blob: e6b5e76a962a683401388207a69689378a337cb4 [file] [log] [blame]
Thomas Gleixnerc9422992019-05-29 07:12:43 -07001// SPDX-License-Identifier: GPL-2.0-only
Pravin B Shelaraa310702013-06-17 17:50:33 -07002/*
Pravin B Shelar8c8b1b82014-09-15 19:28:44 -07003 * Copyright (c) 2007-2014 Nicira, Inc.
Pravin B Shelaraa310702013-06-17 17:50:33 -07004 */
5
Pravin B Shelaraa310702013-06-17 17:50:33 -07006#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 Shelaraa310702013-06-17 17:50:33 -070014#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 Graf62b9c8d2014-10-22 17:29:06 +020019#include <linux/module.h>
Pravin B Shelaraa310702013-06-17 17:50:33 -070020#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 Shelarb2acd1d2015-08-07 23:51:47 -070035#include "vport-netdev.h"
Pravin B Shelaraa310702013-06-17 17:50:33 -070036
Thomas Graf62b9c8d2014-10-22 17:29:06 +020037static struct vport_ops ovs_gre_vport_ops;
38
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070039static struct vport *gre_tnl_create(const struct vport_parms *parms)
Pravin B Shelaraa310702013-06-17 17:50:33 -070040{
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070041 struct net *net = ovs_dp_get_net(parms->dp);
42 struct net_device *dev;
Wei Zhange0bb8c42014-06-28 12:34:53 -070043 struct vport *vport;
Martynas Pumputis4b5b9ba2016-08-09 16:24:50 +010044 int err;
Wei Zhange0bb8c42014-06-28 12:34:53 -070045
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070046 vport = ovs_vport_alloc(0, &ovs_gre_vport_ops, parms);
47 if (IS_ERR(vport))
48 return vport;
Wei Zhange0bb8c42014-06-28 12:34:53 -070049
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070050 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 Shelaraa310702013-06-17 17:50:33 -070056 }
57
Petr Machata567c5e12018-12-06 17:05:42 +000058 err = dev_change_flags(dev, dev->flags | IFF_UP, NULL);
Martynas Pumputis4b5b9ba2016-08-09 16:24:50 +010059 if (err < 0) {
60 rtnl_delete_link(dev);
61 rtnl_unlock();
62 ovs_vport_free(vport);
63 return ERR_PTR(err);
64 }
Pravin B Shelaraa310702013-06-17 17:50:33 -070065
Martynas Pumputis4b5b9ba2016-08-09 16:24:50 +010066 rtnl_unlock();
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070067 return vport;
Pravin B Shelaraa310702013-06-17 17:50:33 -070068}
69
70static struct vport *gre_create(const struct vport_parms *parms)
71{
Pravin B Shelaraa310702013-06-17 17:50:33 -070072 struct vport *vport;
Pravin B Shelaraa310702013-06-17 17:50:33 -070073
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070074 vport = gre_tnl_create(parms);
Pravin B Shelaraa310702013-06-17 17:50:33 -070075 if (IS_ERR(vport))
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070076 return vport;
Pravin B Shelaraa310702013-06-17 17:50:33 -070077
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070078 return ovs_netdev_link(vport, parms->name);
Pravin B Shelaraa310702013-06-17 17:50:33 -070079}
80
Thomas Graf62b9c8d2014-10-22 17:29:06 +020081static struct vport_ops ovs_gre_vport_ops = {
Pravin B Shelaraa310702013-06-17 17:50:33 -070082 .type = OVS_VPORT_TYPE_GRE,
83 .create = gre_create,
Pravin B Shelaraec15922015-10-20 23:00:10 -070084 .send = dev_queue_xmit,
Pravin B Shelarb2acd1d2015-08-07 23:51:47 -070085 .destroy = ovs_netdev_tunnel_destroy,
Pravin B Shelaraa310702013-06-17 17:50:33 -070086};
Thomas Graf62b9c8d2014-10-22 17:29:06 +020087
88static int __init ovs_gre_tnl_init(void)
89{
90 return ovs_vport_ops_register(&ovs_gre_vport_ops);
91}
92
93static void __exit ovs_gre_tnl_exit(void)
94{
95 ovs_vport_ops_unregister(&ovs_gre_vport_ops);
96}
97
98module_init(ovs_gre_tnl_init);
99module_exit(ovs_gre_tnl_exit);
100
101MODULE_DESCRIPTION("OVS: GRE switching port");
102MODULE_LICENSE("GPL");
103MODULE_ALIAS("vport-type-3");