Thomas Gleixner | c942299 | 2019-05-29 07:12:43 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 2 | /* |
Pravin B Shelar | 8c8b1b8 | 2014-09-15 19:28:44 -0700 | [diff] [blame] | 3 | * Copyright (c) 2007-2014 Nicira, Inc. |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 6 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 7 | |
| 8 | #include <linux/if.h> |
| 9 | #include <linux/skbuff.h> |
| 10 | #include <linux/ip.h> |
| 11 | #include <linux/if_tunnel.h> |
| 12 | #include <linux/if_vlan.h> |
| 13 | #include <linux/in.h> |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 14 | #include <linux/in_route.h> |
| 15 | #include <linux/inetdevice.h> |
| 16 | #include <linux/jhash.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/kernel.h> |
Thomas Graf | 62b9c8d | 2014-10-22 17:29:06 +0200 | [diff] [blame] | 19 | #include <linux/module.h> |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 20 | #include <linux/workqueue.h> |
| 21 | #include <linux/rculist.h> |
| 22 | #include <net/route.h> |
| 23 | #include <net/xfrm.h> |
| 24 | |
| 25 | #include <net/icmp.h> |
| 26 | #include <net/ip.h> |
| 27 | #include <net/ip_tunnels.h> |
| 28 | #include <net/gre.h> |
| 29 | #include <net/net_namespace.h> |
| 30 | #include <net/netns/generic.h> |
| 31 | #include <net/protocol.h> |
| 32 | |
| 33 | #include "datapath.h" |
| 34 | #include "vport.h" |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 35 | #include "vport-netdev.h" |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 36 | |
Thomas Graf | 62b9c8d | 2014-10-22 17:29:06 +0200 | [diff] [blame] | 37 | static struct vport_ops ovs_gre_vport_ops; |
| 38 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 39 | static struct vport *gre_tnl_create(const struct vport_parms *parms) |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 40 | { |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 41 | struct net *net = ovs_dp_get_net(parms->dp); |
| 42 | struct net_device *dev; |
Wei Zhang | e0bb8c4 | 2014-06-28 12:34:53 -0700 | [diff] [blame] | 43 | struct vport *vport; |
Martynas Pumputis | 4b5b9ba | 2016-08-09 16:24:50 +0100 | [diff] [blame] | 44 | int err; |
Wei Zhang | e0bb8c4 | 2014-06-28 12:34:53 -0700 | [diff] [blame] | 45 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 46 | vport = ovs_vport_alloc(0, &ovs_gre_vport_ops, parms); |
| 47 | if (IS_ERR(vport)) |
| 48 | return vport; |
Wei Zhang | e0bb8c4 | 2014-06-28 12:34:53 -0700 | [diff] [blame] | 49 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 50 | rtnl_lock(); |
| 51 | dev = gretap_fb_dev_create(net, parms->name, NET_NAME_USER); |
| 52 | if (IS_ERR(dev)) { |
| 53 | rtnl_unlock(); |
| 54 | ovs_vport_free(vport); |
| 55 | return ERR_CAST(dev); |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Petr Machata | 567c5e1 | 2018-12-06 17:05:42 +0000 | [diff] [blame] | 58 | err = dev_change_flags(dev, dev->flags | IFF_UP, NULL); |
Martynas Pumputis | 4b5b9ba | 2016-08-09 16:24:50 +0100 | [diff] [blame] | 59 | if (err < 0) { |
| 60 | rtnl_delete_link(dev); |
| 61 | rtnl_unlock(); |
| 62 | ovs_vport_free(vport); |
| 63 | return ERR_PTR(err); |
| 64 | } |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 65 | |
Martynas Pumputis | 4b5b9ba | 2016-08-09 16:24:50 +0100 | [diff] [blame] | 66 | rtnl_unlock(); |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 67 | return vport; |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static struct vport *gre_create(const struct vport_parms *parms) |
| 71 | { |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 72 | struct vport *vport; |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 73 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 74 | vport = gre_tnl_create(parms); |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 75 | if (IS_ERR(vport)) |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 76 | return vport; |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 77 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 78 | return ovs_netdev_link(vport, parms->name); |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Thomas Graf | 62b9c8d | 2014-10-22 17:29:06 +0200 | [diff] [blame] | 81 | static struct vport_ops ovs_gre_vport_ops = { |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 82 | .type = OVS_VPORT_TYPE_GRE, |
| 83 | .create = gre_create, |
Pravin B Shelar | aec1592 | 2015-10-20 23:00:10 -0700 | [diff] [blame] | 84 | .send = dev_queue_xmit, |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 85 | .destroy = ovs_netdev_tunnel_destroy, |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 86 | }; |
Thomas Graf | 62b9c8d | 2014-10-22 17:29:06 +0200 | [diff] [blame] | 87 | |
| 88 | static int __init ovs_gre_tnl_init(void) |
| 89 | { |
| 90 | return ovs_vport_ops_register(&ovs_gre_vport_ops); |
| 91 | } |
| 92 | |
| 93 | static void __exit ovs_gre_tnl_exit(void) |
| 94 | { |
| 95 | ovs_vport_ops_unregister(&ovs_gre_vport_ops); |
| 96 | } |
| 97 | |
| 98 | module_init(ovs_gre_tnl_init); |
| 99 | module_exit(ovs_gre_tnl_exit); |
| 100 | |
| 101 | MODULE_DESCRIPTION("OVS: GRE switching port"); |
| 102 | MODULE_LICENSE("GPL"); |
| 103 | MODULE_ALIAS("vport-type-3"); |