Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 1 | /* |
Pravin B Shelar | 8c8b1b8 | 2014-09-15 19:28:44 -0700 | [diff] [blame] | 2 | * Copyright (c) 2007-2014 Nicira, Inc. |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of version 2 of the GNU General Public |
| 6 | * License as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 16 | * 02110-1301, USA |
| 17 | */ |
| 18 | |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
| 21 | #include <linux/if.h> |
| 22 | #include <linux/skbuff.h> |
| 23 | #include <linux/ip.h> |
| 24 | #include <linux/if_tunnel.h> |
| 25 | #include <linux/if_vlan.h> |
| 26 | #include <linux/in.h> |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 27 | #include <linux/in_route.h> |
| 28 | #include <linux/inetdevice.h> |
| 29 | #include <linux/jhash.h> |
| 30 | #include <linux/list.h> |
| 31 | #include <linux/kernel.h> |
Thomas Graf | 62b9c8d | 2014-10-22 17:29:06 +0200 | [diff] [blame] | 32 | #include <linux/module.h> |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 33 | #include <linux/workqueue.h> |
| 34 | #include <linux/rculist.h> |
| 35 | #include <net/route.h> |
| 36 | #include <net/xfrm.h> |
| 37 | |
| 38 | #include <net/icmp.h> |
| 39 | #include <net/ip.h> |
| 40 | #include <net/ip_tunnels.h> |
| 41 | #include <net/gre.h> |
| 42 | #include <net/net_namespace.h> |
| 43 | #include <net/netns/generic.h> |
| 44 | #include <net/protocol.h> |
| 45 | |
| 46 | #include "datapath.h" |
| 47 | #include "vport.h" |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 48 | #include "vport-netdev.h" |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 49 | |
Thomas Graf | 62b9c8d | 2014-10-22 17:29:06 +0200 | [diff] [blame] | 50 | static struct vport_ops ovs_gre_vport_ops; |
| 51 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 52 | static struct vport *gre_tnl_create(const struct vport_parms *parms) |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 53 | { |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 54 | struct net *net = ovs_dp_get_net(parms->dp); |
| 55 | struct net_device *dev; |
Wei Zhang | e0bb8c4 | 2014-06-28 12:34:53 -0700 | [diff] [blame] | 56 | struct vport *vport; |
| 57 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 58 | vport = ovs_vport_alloc(0, &ovs_gre_vport_ops, parms); |
| 59 | if (IS_ERR(vport)) |
| 60 | return vport; |
Wei Zhang | e0bb8c4 | 2014-06-28 12:34:53 -0700 | [diff] [blame] | 61 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 62 | rtnl_lock(); |
| 63 | dev = gretap_fb_dev_create(net, parms->name, NET_NAME_USER); |
| 64 | if (IS_ERR(dev)) { |
| 65 | rtnl_unlock(); |
| 66 | ovs_vport_free(vport); |
| 67 | return ERR_CAST(dev); |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 70 | dev_change_flags(dev, dev->flags | IFF_UP); |
| 71 | rtnl_unlock(); |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 72 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 73 | return vport; |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static struct vport *gre_create(const struct vport_parms *parms) |
| 77 | { |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 78 | struct vport *vport; |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 79 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 80 | vport = gre_tnl_create(parms); |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 81 | if (IS_ERR(vport)) |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 82 | return vport; |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 83 | |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 84 | return ovs_netdev_link(vport, parms->name); |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Thomas Graf | 62b9c8d | 2014-10-22 17:29:06 +0200 | [diff] [blame] | 87 | static struct vport_ops ovs_gre_vport_ops = { |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 88 | .type = OVS_VPORT_TYPE_GRE, |
| 89 | .create = gre_create, |
Pravin B Shelar | aec1592 | 2015-10-20 23:00:10 -0700 | [diff] [blame] | 90 | .send = dev_queue_xmit, |
Pravin B Shelar | b2acd1d | 2015-08-07 23:51:47 -0700 | [diff] [blame] | 91 | .destroy = ovs_netdev_tunnel_destroy, |
Pravin B Shelar | aa31070 | 2013-06-17 17:50:33 -0700 | [diff] [blame] | 92 | }; |
Thomas Graf | 62b9c8d | 2014-10-22 17:29:06 +0200 | [diff] [blame] | 93 | |
| 94 | static int __init ovs_gre_tnl_init(void) |
| 95 | { |
| 96 | return ovs_vport_ops_register(&ovs_gre_vport_ops); |
| 97 | } |
| 98 | |
| 99 | static void __exit ovs_gre_tnl_exit(void) |
| 100 | { |
| 101 | ovs_vport_ops_unregister(&ovs_gre_vport_ops); |
| 102 | } |
| 103 | |
| 104 | module_init(ovs_gre_tnl_init); |
| 105 | module_exit(ovs_gre_tnl_exit); |
| 106 | |
| 107 | MODULE_DESCRIPTION("OVS: GRE switching port"); |
| 108 | MODULE_LICENSE("GPL"); |
| 109 | MODULE_ALIAS("vport-type-3"); |