1 // SPDX-License-Identifier: GPL-2.0-only << 2 /* 1 /* 3 * Copyright (c) 2007-2014 Nicira, Inc. 2 * Copyright (c) 2007-2014 Nicira, Inc. >> 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 4 */ 17 */ 5 18 6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7 20 8 #include <linux/if.h> 21 #include <linux/if.h> 9 #include <linux/skbuff.h> 22 #include <linux/skbuff.h> 10 #include <linux/ip.h> 23 #include <linux/ip.h> 11 #include <linux/if_tunnel.h> 24 #include <linux/if_tunnel.h> 12 #include <linux/if_vlan.h> 25 #include <linux/if_vlan.h> 13 #include <linux/in.h> 26 #include <linux/in.h> 14 #include <linux/in_route.h> 27 #include <linux/in_route.h> 15 #include <linux/inetdevice.h> 28 #include <linux/inetdevice.h> 16 #include <linux/jhash.h> 29 #include <linux/jhash.h> 17 #include <linux/list.h> 30 #include <linux/list.h> 18 #include <linux/kernel.h> 31 #include <linux/kernel.h> 19 #include <linux/module.h> 32 #include <linux/module.h> 20 #include <linux/workqueue.h> 33 #include <linux/workqueue.h> 21 #include <linux/rculist.h> 34 #include <linux/rculist.h> 22 #include <net/route.h> 35 #include <net/route.h> 23 #include <net/xfrm.h> 36 #include <net/xfrm.h> 24 37 25 #include <net/icmp.h> 38 #include <net/icmp.h> 26 #include <net/ip.h> 39 #include <net/ip.h> 27 #include <net/ip_tunnels.h> 40 #include <net/ip_tunnels.h> 28 #include <net/gre.h> 41 #include <net/gre.h> 29 #include <net/net_namespace.h> 42 #include <net/net_namespace.h> 30 #include <net/netns/generic.h> 43 #include <net/netns/generic.h> 31 #include <net/protocol.h> 44 #include <net/protocol.h> 32 45 33 #include "datapath.h" 46 #include "datapath.h" 34 #include "vport.h" 47 #include "vport.h" 35 #include "vport-netdev.h" 48 #include "vport-netdev.h" 36 49 37 static struct vport_ops ovs_gre_vport_ops; 50 static struct vport_ops ovs_gre_vport_ops; 38 51 39 static struct vport *gre_tnl_create(const stru 52 static struct vport *gre_tnl_create(const struct vport_parms *parms) 40 { 53 { 41 struct net *net = ovs_dp_get_net(parms 54 struct net *net = ovs_dp_get_net(parms->dp); 42 struct net_device *dev; 55 struct net_device *dev; 43 struct vport *vport; 56 struct vport *vport; 44 int err; 57 int err; 45 58 46 vport = ovs_vport_alloc(0, &ovs_gre_vp 59 vport = ovs_vport_alloc(0, &ovs_gre_vport_ops, parms); 47 if (IS_ERR(vport)) 60 if (IS_ERR(vport)) 48 return vport; 61 return vport; 49 62 50 rtnl_lock(); 63 rtnl_lock(); 51 dev = gretap_fb_dev_create(net, parms- 64 dev = gretap_fb_dev_create(net, parms->name, NET_NAME_USER); 52 if (IS_ERR(dev)) { 65 if (IS_ERR(dev)) { 53 rtnl_unlock(); 66 rtnl_unlock(); 54 ovs_vport_free(vport); 67 ovs_vport_free(vport); 55 return ERR_CAST(dev); 68 return ERR_CAST(dev); 56 } 69 } 57 70 58 err = dev_change_flags(dev, dev->flags !! 71 err = dev_change_flags(dev, dev->flags | IFF_UP); 59 if (err < 0) { 72 if (err < 0) { 60 rtnl_delete_link(dev, 0, NULL) !! 73 rtnl_delete_link(dev); 61 rtnl_unlock(); 74 rtnl_unlock(); 62 ovs_vport_free(vport); 75 ovs_vport_free(vport); 63 return ERR_PTR(err); 76 return ERR_PTR(err); 64 } 77 } 65 78 66 rtnl_unlock(); 79 rtnl_unlock(); 67 return vport; 80 return vport; 68 } 81 } 69 82 70 static struct vport *gre_create(const struct v 83 static struct vport *gre_create(const struct vport_parms *parms) 71 { 84 { 72 struct vport *vport; 85 struct vport *vport; 73 86 74 vport = gre_tnl_create(parms); 87 vport = gre_tnl_create(parms); 75 if (IS_ERR(vport)) 88 if (IS_ERR(vport)) 76 return vport; 89 return vport; 77 90 78 return ovs_netdev_link(vport, parms->n 91 return ovs_netdev_link(vport, parms->name); 79 } 92 } 80 93 81 static struct vport_ops ovs_gre_vport_ops = { 94 static struct vport_ops ovs_gre_vport_ops = { 82 .type = OVS_VPORT_TYPE_GRE, 95 .type = OVS_VPORT_TYPE_GRE, 83 .create = gre_create, 96 .create = gre_create, 84 .send = dev_queue_xmit, 97 .send = dev_queue_xmit, 85 .destroy = ovs_netdev_tunnel_de 98 .destroy = ovs_netdev_tunnel_destroy, 86 }; 99 }; 87 100 88 static int __init ovs_gre_tnl_init(void) 101 static int __init ovs_gre_tnl_init(void) 89 { 102 { 90 return ovs_vport_ops_register(&ovs_gre 103 return ovs_vport_ops_register(&ovs_gre_vport_ops); 91 } 104 } 92 105 93 static void __exit ovs_gre_tnl_exit(void) 106 static void __exit ovs_gre_tnl_exit(void) 94 { 107 { 95 ovs_vport_ops_unregister(&ovs_gre_vpor 108 ovs_vport_ops_unregister(&ovs_gre_vport_ops); 96 } 109 } 97 110 98 module_init(ovs_gre_tnl_init); 111 module_init(ovs_gre_tnl_init); 99 module_exit(ovs_gre_tnl_exit); 112 module_exit(ovs_gre_tnl_exit); 100 113 101 MODULE_DESCRIPTION("OVS: GRE switching port"); 114 MODULE_DESCRIPTION("OVS: GRE switching port"); 102 MODULE_LICENSE("GPL"); 115 MODULE_LICENSE("GPL"); 103 MODULE_ALIAS("vport-type-3"); 116 MODULE_ALIAS("vport-type-3"); 104 117
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.