blob: 0e72d95b0e8f1fcd2e6d1446fc0944b519c0500e [file] [log] [blame]
Pravin B Shelaraa310702013-06-17 17:50:33 -07001/*
Pravin B Shelar8c8b1b82014-09-15 19:28:44 -07002 * Copyright (c) 2007-2014 Nicira, Inc.
Pravin B Shelaraa310702013-06-17 17:50:33 -07003 *
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 Shelaraa310702013-06-17 17:50:33 -070019#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 Shelaraa310702013-06-17 17:50:33 -070027#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 Graf62b9c8d2014-10-22 17:29:06 +020032#include <linux/module.h>
Pravin B Shelaraa310702013-06-17 17:50:33 -070033#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 Shelarb2acd1d2015-08-07 23:51:47 -070048#include "vport-netdev.h"
Pravin B Shelaraa310702013-06-17 17:50:33 -070049
Thomas Graf62b9c8d2014-10-22 17:29:06 +020050static struct vport_ops ovs_gre_vport_ops;
51
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070052static struct vport *gre_tnl_create(const struct vport_parms *parms)
Pravin B Shelaraa310702013-06-17 17:50:33 -070053{
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070054 struct net *net = ovs_dp_get_net(parms->dp);
55 struct net_device *dev;
Wei Zhange0bb8c42014-06-28 12:34:53 -070056 struct vport *vport;
Martynas Pumputis4b5b9ba2016-08-09 16:24:50 +010057 int err;
Wei Zhange0bb8c42014-06-28 12:34:53 -070058
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070059 vport = ovs_vport_alloc(0, &ovs_gre_vport_ops, parms);
60 if (IS_ERR(vport))
61 return vport;
Wei Zhange0bb8c42014-06-28 12:34:53 -070062
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070063 rtnl_lock();
64 dev = gretap_fb_dev_create(net, parms->name, NET_NAME_USER);
65 if (IS_ERR(dev)) {
66 rtnl_unlock();
67 ovs_vport_free(vport);
68 return ERR_CAST(dev);
Pravin B Shelaraa310702013-06-17 17:50:33 -070069 }
70
Martynas Pumputis4b5b9ba2016-08-09 16:24:50 +010071 err = dev_change_flags(dev, dev->flags | IFF_UP);
72 if (err < 0) {
73 rtnl_delete_link(dev);
74 rtnl_unlock();
75 ovs_vport_free(vport);
76 return ERR_PTR(err);
77 }
Pravin B Shelaraa310702013-06-17 17:50:33 -070078
Martynas Pumputis4b5b9ba2016-08-09 16:24:50 +010079 rtnl_unlock();
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070080 return vport;
Pravin B Shelaraa310702013-06-17 17:50:33 -070081}
82
83static struct vport *gre_create(const struct vport_parms *parms)
84{
Pravin B Shelaraa310702013-06-17 17:50:33 -070085 struct vport *vport;
Pravin B Shelaraa310702013-06-17 17:50:33 -070086
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070087 vport = gre_tnl_create(parms);
Pravin B Shelaraa310702013-06-17 17:50:33 -070088 if (IS_ERR(vport))
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070089 return vport;
Pravin B Shelaraa310702013-06-17 17:50:33 -070090
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070091 return ovs_netdev_link(vport, parms->name);
Pravin B Shelaraa310702013-06-17 17:50:33 -070092}
93
Thomas Graf62b9c8d2014-10-22 17:29:06 +020094static struct vport_ops ovs_gre_vport_ops = {
Pravin B Shelaraa310702013-06-17 17:50:33 -070095 .type = OVS_VPORT_TYPE_GRE,
96 .create = gre_create,
Pravin B Shelaraec15922015-10-20 23:00:10 -070097 .send = dev_queue_xmit,
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070098 .destroy = ovs_netdev_tunnel_destroy,
Pravin B Shelaraa310702013-06-17 17:50:33 -070099};
Thomas Graf62b9c8d2014-10-22 17:29:06 +0200100
101static int __init ovs_gre_tnl_init(void)
102{
103 return ovs_vport_ops_register(&ovs_gre_vport_ops);
104}
105
106static void __exit ovs_gre_tnl_exit(void)
107{
108 ovs_vport_ops_unregister(&ovs_gre_vport_ops);
109}
110
111module_init(ovs_gre_tnl_init);
112module_exit(ovs_gre_tnl_exit);
113
114MODULE_DESCRIPTION("OVS: GRE switching port");
115MODULE_LICENSE("GPL");
116MODULE_ALIAS("vport-type-3");