xref: /openbmc/linux/net/openvswitch/vport-netdev.c (revision 614732eaa12dd462c0ab274700bed14f36afea5e)
1ccb1352eSJesse Gross /*
2caf2ee14SRaju Subramanian  * Copyright (c) 2007-2012 Nicira, Inc.
3ccb1352eSJesse Gross  *
4ccb1352eSJesse Gross  * This program is free software; you can redistribute it and/or
5ccb1352eSJesse Gross  * modify it under the terms of version 2 of the GNU General Public
6ccb1352eSJesse Gross  * License as published by the Free Software Foundation.
7ccb1352eSJesse Gross  *
8ccb1352eSJesse Gross  * This program is distributed in the hope that it will be useful, but
9ccb1352eSJesse Gross  * WITHOUT ANY WARRANTY; without even the implied warranty of
10ccb1352eSJesse Gross  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11ccb1352eSJesse Gross  * General Public License for more details.
12ccb1352eSJesse Gross  *
13ccb1352eSJesse Gross  * You should have received a copy of the GNU General Public License
14ccb1352eSJesse Gross  * along with this program; if not, write to the Free Software
15ccb1352eSJesse Gross  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16ccb1352eSJesse Gross  * 02110-1301, USA
17ccb1352eSJesse Gross  */
18ccb1352eSJesse Gross 
19ccb1352eSJesse Gross #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20ccb1352eSJesse Gross 
21ccb1352eSJesse Gross #include <linux/if_arp.h>
22ccb1352eSJesse Gross #include <linux/if_bridge.h>
23ccb1352eSJesse Gross #include <linux/if_vlan.h>
24ccb1352eSJesse Gross #include <linux/kernel.h>
25ccb1352eSJesse Gross #include <linux/llc.h>
26ccb1352eSJesse Gross #include <linux/rtnetlink.h>
27ccb1352eSJesse Gross #include <linux/skbuff.h>
282537b4ddSJiri Pirko #include <linux/openvswitch.h>
29ccb1352eSJesse Gross 
30*614732eaSThomas Graf #include <net/udp.h>
31*614732eaSThomas Graf #include <net/ip_tunnels.h>
32*614732eaSThomas Graf #include <net/rtnetlink.h>
33*614732eaSThomas Graf #include <net/vxlan.h>
34ccb1352eSJesse Gross 
35ccb1352eSJesse Gross #include "datapath.h"
36*614732eaSThomas Graf #include "vport.h"
37ccb1352eSJesse Gross #include "vport-internal_dev.h"
38ccb1352eSJesse Gross #include "vport-netdev.h"
39ccb1352eSJesse Gross 
4062b9c8d0SThomas Graf static struct vport_ops ovs_netdev_vport_ops;
4162b9c8d0SThomas Graf 
42ccb1352eSJesse Gross /* Must be called with rcu_read_lock. */
43ccb1352eSJesse Gross static void netdev_port_receive(struct vport *vport, struct sk_buff *skb)
44ccb1352eSJesse Gross {
45d9d59089SJesse Gross 	if (unlikely(!vport))
46d9d59089SJesse Gross 		goto error;
47d9d59089SJesse Gross 
48d9d59089SJesse Gross 	if (unlikely(skb_warn_if_lro(skb)))
49d9d59089SJesse Gross 		goto error;
50ccb1352eSJesse Gross 
51ccb1352eSJesse Gross 	/* Make our own copy of the packet.  Otherwise we will mangle the
52ccb1352eSJesse Gross 	 * packet for anyone who came before us (e.g. tcpdump via AF_PACKET).
53d176ca2aSCong Wang 	 */
54ccb1352eSJesse Gross 	skb = skb_share_check(skb, GFP_ATOMIC);
55ccb1352eSJesse Gross 	if (unlikely(!skb))
56ccb1352eSJesse Gross 		return;
57ccb1352eSJesse Gross 
58ccb1352eSJesse Gross 	skb_push(skb, ETH_HLEN);
59b34df5e8SPravin B Shelar 	ovs_skb_postpush_rcsum(skb, skb->data, ETH_HLEN);
60b34df5e8SPravin B Shelar 
617d5437c7SPravin B Shelar 	ovs_vport_receive(vport, skb, NULL);
62d9d59089SJesse Gross 	return;
63d9d59089SJesse Gross 
64d9d59089SJesse Gross error:
65d9d59089SJesse Gross 	kfree_skb(skb);
66ccb1352eSJesse Gross }
67ccb1352eSJesse Gross 
68ccb1352eSJesse Gross /* Called with rcu_read_lock and bottom-halves disabled. */
69ccb1352eSJesse Gross static rx_handler_result_t netdev_frame_hook(struct sk_buff **pskb)
70ccb1352eSJesse Gross {
71ccb1352eSJesse Gross 	struct sk_buff *skb = *pskb;
72ccb1352eSJesse Gross 	struct vport *vport;
73ccb1352eSJesse Gross 
74ccb1352eSJesse Gross 	if (unlikely(skb->pkt_type == PACKET_LOOPBACK))
75ccb1352eSJesse Gross 		return RX_HANDLER_PASS;
76ccb1352eSJesse Gross 
77ccb1352eSJesse Gross 	vport = ovs_netdev_get_vport(skb->dev);
78ccb1352eSJesse Gross 
79ccb1352eSJesse Gross 	netdev_port_receive(vport, skb);
80ccb1352eSJesse Gross 
81ccb1352eSJesse Gross 	return RX_HANDLER_CONSUMED;
82ccb1352eSJesse Gross }
83ccb1352eSJesse Gross 
8412eb18f7SThomas Graf static struct net_device *get_dpdev(const struct datapath *dp)
852537b4ddSJiri Pirko {
862537b4ddSJiri Pirko 	struct vport *local;
872537b4ddSJiri Pirko 
882537b4ddSJiri Pirko 	local = ovs_vport_ovsl(dp, OVSP_LOCAL);
892537b4ddSJiri Pirko 	BUG_ON(!local);
90be4ace6eSThomas Graf 	return local->dev;
912537b4ddSJiri Pirko }
922537b4ddSJiri Pirko 
93be4ace6eSThomas Graf static struct vport *netdev_link(struct vport *vport, const char *name)
94ccb1352eSJesse Gross {
95ccb1352eSJesse Gross 	int err;
96ccb1352eSJesse Gross 
97be4ace6eSThomas Graf 	vport->dev = dev_get_by_name(ovs_dp_get_net(vport->dp), name);
98be4ace6eSThomas Graf 	if (!vport->dev) {
99ccb1352eSJesse Gross 		err = -ENODEV;
100ccb1352eSJesse Gross 		goto error_free_vport;
101ccb1352eSJesse Gross 	}
102ccb1352eSJesse Gross 
103be4ace6eSThomas Graf 	if (vport->dev->flags & IFF_LOOPBACK ||
104be4ace6eSThomas Graf 	    vport->dev->type != ARPHRD_ETHER ||
105be4ace6eSThomas Graf 	    ovs_is_internal_dev(vport->dev)) {
106ccb1352eSJesse Gross 		err = -EINVAL;
107ccb1352eSJesse Gross 		goto error_put;
108ccb1352eSJesse Gross 	}
109ccb1352eSJesse Gross 
1108e4e1713SPravin B Shelar 	rtnl_lock();
111be4ace6eSThomas Graf 	err = netdev_master_upper_dev_link(vport->dev,
1122537b4ddSJiri Pirko 					   get_dpdev(vport->dp));
1132537b4ddSJiri Pirko 	if (err)
1142537b4ddSJiri Pirko 		goto error_unlock;
1152537b4ddSJiri Pirko 
116be4ace6eSThomas Graf 	err = netdev_rx_handler_register(vport->dev, netdev_frame_hook,
117ccb1352eSJesse Gross 					 vport);
118ccb1352eSJesse Gross 	if (err)
1192537b4ddSJiri Pirko 		goto error_master_upper_dev_unlink;
120ccb1352eSJesse Gross 
121be4ace6eSThomas Graf 	dev_disable_lro(vport->dev);
122be4ace6eSThomas Graf 	dev_set_promiscuity(vport->dev, 1);
123be4ace6eSThomas Graf 	vport->dev->priv_flags |= IFF_OVS_DATAPATH;
1248e4e1713SPravin B Shelar 	rtnl_unlock();
125ccb1352eSJesse Gross 
126ccb1352eSJesse Gross 	return vport;
127ccb1352eSJesse Gross 
1282537b4ddSJiri Pirko error_master_upper_dev_unlink:
129be4ace6eSThomas Graf 	netdev_upper_dev_unlink(vport->dev, get_dpdev(vport->dp));
1308e4e1713SPravin B Shelar error_unlock:
1318e4e1713SPravin B Shelar 	rtnl_unlock();
132ccb1352eSJesse Gross error_put:
133be4ace6eSThomas Graf 	dev_put(vport->dev);
134ccb1352eSJesse Gross error_free_vport:
135ccb1352eSJesse Gross 	ovs_vport_free(vport);
136ccb1352eSJesse Gross 	return ERR_PTR(err);
137ccb1352eSJesse Gross }
138ccb1352eSJesse Gross 
139be4ace6eSThomas Graf static struct vport *netdev_create(const struct vport_parms *parms)
140be4ace6eSThomas Graf {
141be4ace6eSThomas Graf 	struct vport *vport;
142be4ace6eSThomas Graf 
143be4ace6eSThomas Graf 	vport = ovs_vport_alloc(0, &ovs_netdev_vport_ops, parms);
144be4ace6eSThomas Graf 	if (IS_ERR(vport))
145be4ace6eSThomas Graf 		return vport;
146be4ace6eSThomas Graf 
147be4ace6eSThomas Graf 	return netdev_link(vport, parms->name);
148be4ace6eSThomas Graf }
149be4ace6eSThomas Graf 
15092eb1d47SJesse Gross static void free_port_rcu(struct rcu_head *rcu)
15192eb1d47SJesse Gross {
152be4ace6eSThomas Graf 	struct vport *vport = container_of(rcu, struct vport, rcu);
15392eb1d47SJesse Gross 
154*614732eaSThomas Graf 	if (vport->dev)
155be4ace6eSThomas Graf 		dev_put(vport->dev);
156be4ace6eSThomas Graf 	ovs_vport_free(vport);
15792eb1d47SJesse Gross }
15892eb1d47SJesse Gross 
159b07c2651SAlexei Starovoitov void ovs_netdev_detach_dev(struct vport *vport)
160b07c2651SAlexei Starovoitov {
161b07c2651SAlexei Starovoitov 	ASSERT_RTNL();
162be4ace6eSThomas Graf 	vport->dev->priv_flags &= ~IFF_OVS_DATAPATH;
163be4ace6eSThomas Graf 	netdev_rx_handler_unregister(vport->dev);
164be4ace6eSThomas Graf 	netdev_upper_dev_unlink(vport->dev,
165be4ace6eSThomas Graf 				netdev_master_upper_dev_get(vport->dev));
166be4ace6eSThomas Graf 	dev_set_promiscuity(vport->dev, -1);
167b07c2651SAlexei Starovoitov }
168b07c2651SAlexei Starovoitov 
169ccb1352eSJesse Gross static void netdev_destroy(struct vport *vport)
170ccb1352eSJesse Gross {
1718e4e1713SPravin B Shelar 	rtnl_lock();
172be4ace6eSThomas Graf 	if (vport->dev->priv_flags & IFF_OVS_DATAPATH)
173b07c2651SAlexei Starovoitov 		ovs_netdev_detach_dev(vport);
1748e4e1713SPravin B Shelar 	rtnl_unlock();
175ccb1352eSJesse Gross 
176be4ace6eSThomas Graf 	call_rcu(&vport->rcu, free_port_rcu);
177ccb1352eSJesse Gross }
178ccb1352eSJesse Gross 
17995c96174SEric Dumazet static unsigned int packet_length(const struct sk_buff *skb)
180ccb1352eSJesse Gross {
18195c96174SEric Dumazet 	unsigned int length = skb->len - ETH_HLEN;
182ccb1352eSJesse Gross 
183ccb1352eSJesse Gross 	if (skb->protocol == htons(ETH_P_8021Q))
184ccb1352eSJesse Gross 		length -= VLAN_HLEN;
185ccb1352eSJesse Gross 
186ccb1352eSJesse Gross 	return length;
187ccb1352eSJesse Gross }
188ccb1352eSJesse Gross 
189ccb1352eSJesse Gross static int netdev_send(struct vport *vport, struct sk_buff *skb)
190ccb1352eSJesse Gross {
191be4ace6eSThomas Graf 	int mtu = vport->dev->mtu;
192ccb1352eSJesse Gross 	int len;
193ccb1352eSJesse Gross 
194ccb1352eSJesse Gross 	if (unlikely(packet_length(skb) > mtu && !skb_is_gso(skb))) {
195e87cc472SJoe Perches 		net_warn_ratelimited("%s: dropped over-mtu packet: %d > %d\n",
196be4ace6eSThomas Graf 				     vport->dev->name,
197e87cc472SJoe Perches 				     packet_length(skb), mtu);
19891b7514cSPravin B Shelar 		goto drop;
199ccb1352eSJesse Gross 	}
200ccb1352eSJesse Gross 
201be4ace6eSThomas Graf 	skb->dev = vport->dev;
202ccb1352eSJesse Gross 	len = skb->len;
203ccb1352eSJesse Gross 	dev_queue_xmit(skb);
204ccb1352eSJesse Gross 
205ccb1352eSJesse Gross 	return len;
206ccb1352eSJesse Gross 
20791b7514cSPravin B Shelar drop:
208ccb1352eSJesse Gross 	kfree_skb(skb);
209ccb1352eSJesse Gross 	return 0;
210ccb1352eSJesse Gross }
211ccb1352eSJesse Gross 
212ccb1352eSJesse Gross /* Returns null if this device is not attached to a datapath. */
213ccb1352eSJesse Gross struct vport *ovs_netdev_get_vport(struct net_device *dev)
214ccb1352eSJesse Gross {
215ccb1352eSJesse Gross 	if (likely(dev->priv_flags & IFF_OVS_DATAPATH))
216ccb1352eSJesse Gross 		return (struct vport *)
217ccb1352eSJesse Gross 			rcu_dereference_rtnl(dev->rx_handler_data);
218ccb1352eSJesse Gross 	else
219ccb1352eSJesse Gross 		return NULL;
220ccb1352eSJesse Gross }
221ccb1352eSJesse Gross 
22262b9c8d0SThomas Graf static struct vport_ops ovs_netdev_vport_ops = {
223ccb1352eSJesse Gross 	.type		= OVS_VPORT_TYPE_NETDEV,
224ccb1352eSJesse Gross 	.create		= netdev_create,
225ccb1352eSJesse Gross 	.destroy	= netdev_destroy,
226ccb1352eSJesse Gross 	.send		= netdev_send,
227ccb1352eSJesse Gross };
22862b9c8d0SThomas Graf 
229*614732eaSThomas Graf /* Compat code for old userspace. */
230*614732eaSThomas Graf #if IS_ENABLED(CONFIG_VXLAN)
231*614732eaSThomas Graf static struct vport_ops ovs_vxlan_netdev_vport_ops;
232*614732eaSThomas Graf 
233*614732eaSThomas Graf static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)
234*614732eaSThomas Graf {
235*614732eaSThomas Graf 	struct vxlan_dev *vxlan = netdev_priv(vport->dev);
236*614732eaSThomas Graf 	__be16 dst_port = vxlan->cfg.dst_port;
237*614732eaSThomas Graf 
238*614732eaSThomas Graf 	if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, ntohs(dst_port)))
239*614732eaSThomas Graf 		return -EMSGSIZE;
240*614732eaSThomas Graf 
241*614732eaSThomas Graf 	if (vxlan->flags & VXLAN_F_GBP) {
242*614732eaSThomas Graf 		struct nlattr *exts;
243*614732eaSThomas Graf 
244*614732eaSThomas Graf 		exts = nla_nest_start(skb, OVS_TUNNEL_ATTR_EXTENSION);
245*614732eaSThomas Graf 		if (!exts)
246*614732eaSThomas Graf 			return -EMSGSIZE;
247*614732eaSThomas Graf 
248*614732eaSThomas Graf 		if (vxlan->flags & VXLAN_F_GBP &&
249*614732eaSThomas Graf 		    nla_put_flag(skb, OVS_VXLAN_EXT_GBP))
250*614732eaSThomas Graf 			return -EMSGSIZE;
251*614732eaSThomas Graf 
252*614732eaSThomas Graf 		nla_nest_end(skb, exts);
253*614732eaSThomas Graf 	}
254*614732eaSThomas Graf 
255*614732eaSThomas Graf 	return 0;
256*614732eaSThomas Graf }
257*614732eaSThomas Graf 
258*614732eaSThomas Graf static const struct nla_policy exts_policy[OVS_VXLAN_EXT_MAX + 1] = {
259*614732eaSThomas Graf 	[OVS_VXLAN_EXT_GBP]	= { .type = NLA_FLAG, },
260*614732eaSThomas Graf };
261*614732eaSThomas Graf 
262*614732eaSThomas Graf static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,
263*614732eaSThomas Graf 				struct vxlan_config *conf)
264*614732eaSThomas Graf {
265*614732eaSThomas Graf 	struct nlattr *exts[OVS_VXLAN_EXT_MAX + 1];
266*614732eaSThomas Graf 	int err;
267*614732eaSThomas Graf 
268*614732eaSThomas Graf 	if (nla_len(attr) < sizeof(struct nlattr))
269*614732eaSThomas Graf 		return -EINVAL;
270*614732eaSThomas Graf 
271*614732eaSThomas Graf 	err = nla_parse_nested(exts, OVS_VXLAN_EXT_MAX, attr, exts_policy);
272*614732eaSThomas Graf 	if (err < 0)
273*614732eaSThomas Graf 		return err;
274*614732eaSThomas Graf 
275*614732eaSThomas Graf 	if (exts[OVS_VXLAN_EXT_GBP])
276*614732eaSThomas Graf 		conf->flags |= VXLAN_F_GBP;
277*614732eaSThomas Graf 
278*614732eaSThomas Graf 	return 0;
279*614732eaSThomas Graf }
280*614732eaSThomas Graf 
281*614732eaSThomas Graf static struct vport *vxlan_tnl_create(const struct vport_parms *parms)
282*614732eaSThomas Graf {
283*614732eaSThomas Graf 	struct net *net = ovs_dp_get_net(parms->dp);
284*614732eaSThomas Graf 	struct nlattr *options = parms->options;
285*614732eaSThomas Graf 	struct net_device *dev;
286*614732eaSThomas Graf 	struct vport *vport;
287*614732eaSThomas Graf 	struct nlattr *a;
288*614732eaSThomas Graf 	int err;
289*614732eaSThomas Graf 	struct vxlan_config conf = {
290*614732eaSThomas Graf 		.no_share = true,
291*614732eaSThomas Graf 		.flags = VXLAN_F_FLOW_BASED | VXLAN_F_COLLECT_METADATA,
292*614732eaSThomas Graf 	};
293*614732eaSThomas Graf 
294*614732eaSThomas Graf 	if (!options) {
295*614732eaSThomas Graf 		err = -EINVAL;
296*614732eaSThomas Graf 		goto error;
297*614732eaSThomas Graf 	}
298*614732eaSThomas Graf 
299*614732eaSThomas Graf 	a = nla_find_nested(options, OVS_TUNNEL_ATTR_DST_PORT);
300*614732eaSThomas Graf 	if (a && nla_len(a) == sizeof(u16)) {
301*614732eaSThomas Graf 		conf.dst_port = htons(nla_get_u16(a));
302*614732eaSThomas Graf 	} else {
303*614732eaSThomas Graf 		/* Require destination port from userspace. */
304*614732eaSThomas Graf 		err = -EINVAL;
305*614732eaSThomas Graf 		goto error;
306*614732eaSThomas Graf 	}
307*614732eaSThomas Graf 
308*614732eaSThomas Graf 	vport = ovs_vport_alloc(0, &ovs_vxlan_netdev_vport_ops, parms);
309*614732eaSThomas Graf 	if (IS_ERR(vport))
310*614732eaSThomas Graf 		return vport;
311*614732eaSThomas Graf 
312*614732eaSThomas Graf 	a = nla_find_nested(options, OVS_TUNNEL_ATTR_EXTENSION);
313*614732eaSThomas Graf 	if (a) {
314*614732eaSThomas Graf 		err = vxlan_configure_exts(vport, a, &conf);
315*614732eaSThomas Graf 		if (err) {
316*614732eaSThomas Graf 			ovs_vport_free(vport);
317*614732eaSThomas Graf 			goto error;
318*614732eaSThomas Graf 		}
319*614732eaSThomas Graf 	}
320*614732eaSThomas Graf 
321*614732eaSThomas Graf 	rtnl_lock();
322*614732eaSThomas Graf 	dev = vxlan_dev_create(net, parms->name, NET_NAME_USER, &conf);
323*614732eaSThomas Graf 	if (IS_ERR(dev)) {
324*614732eaSThomas Graf 		rtnl_unlock();
325*614732eaSThomas Graf 		ovs_vport_free(vport);
326*614732eaSThomas Graf 		return ERR_CAST(dev);
327*614732eaSThomas Graf 	}
328*614732eaSThomas Graf 
329*614732eaSThomas Graf 	dev_change_flags(dev, dev->flags | IFF_UP);
330*614732eaSThomas Graf 	rtnl_unlock();
331*614732eaSThomas Graf 	return vport;
332*614732eaSThomas Graf error:
333*614732eaSThomas Graf 	return ERR_PTR(err);
334*614732eaSThomas Graf }
335*614732eaSThomas Graf 
336*614732eaSThomas Graf static struct vport *vxlan_create(const struct vport_parms *parms)
337*614732eaSThomas Graf {
338*614732eaSThomas Graf 	struct vport *vport;
339*614732eaSThomas Graf 
340*614732eaSThomas Graf 	vport = vxlan_tnl_create(parms);
341*614732eaSThomas Graf 	if (IS_ERR(vport))
342*614732eaSThomas Graf 		return vport;
343*614732eaSThomas Graf 
344*614732eaSThomas Graf 	return netdev_link(vport, parms->name);
345*614732eaSThomas Graf }
346*614732eaSThomas Graf 
347*614732eaSThomas Graf static void vxlan_destroy(struct vport *vport)
348*614732eaSThomas Graf {
349*614732eaSThomas Graf 	rtnl_lock();
350*614732eaSThomas Graf 	if (vport->dev->priv_flags & IFF_OVS_DATAPATH)
351*614732eaSThomas Graf 		ovs_netdev_detach_dev(vport);
352*614732eaSThomas Graf 
353*614732eaSThomas Graf 	/* Early release so we can unregister the device */
354*614732eaSThomas Graf 	dev_put(vport->dev);
355*614732eaSThomas Graf 	rtnl_delete_link(vport->dev);
356*614732eaSThomas Graf 	vport->dev = NULL;
357*614732eaSThomas Graf 	rtnl_unlock();
358*614732eaSThomas Graf 
359*614732eaSThomas Graf 	call_rcu(&vport->rcu, free_port_rcu);
360*614732eaSThomas Graf }
361*614732eaSThomas Graf 
362*614732eaSThomas Graf static int vxlan_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
363*614732eaSThomas Graf 				     struct ip_tunnel_info *egress_tun_info)
364*614732eaSThomas Graf {
365*614732eaSThomas Graf 	struct vxlan_dev *vxlan = netdev_priv(vport->dev);
366*614732eaSThomas Graf 	struct net *net = ovs_dp_get_net(vport->dp);
367*614732eaSThomas Graf 	__be16 dst_port = vxlan_dev_dst_port(vxlan);
368*614732eaSThomas Graf 	__be16 src_port;
369*614732eaSThomas Graf 	int port_min;
370*614732eaSThomas Graf 	int port_max;
371*614732eaSThomas Graf 
372*614732eaSThomas Graf 	inet_get_local_port_range(net, &port_min, &port_max);
373*614732eaSThomas Graf 	src_port = udp_flow_src_port(net, skb, 0, 0, true);
374*614732eaSThomas Graf 
375*614732eaSThomas Graf 	return ovs_tunnel_get_egress_info(egress_tun_info, net,
376*614732eaSThomas Graf 					  OVS_CB(skb)->egress_tun_info,
377*614732eaSThomas Graf 					  IPPROTO_UDP, skb->mark,
378*614732eaSThomas Graf 					  src_port, dst_port);
379*614732eaSThomas Graf }
380*614732eaSThomas Graf 
381*614732eaSThomas Graf static struct vport_ops ovs_vxlan_netdev_vport_ops = {
382*614732eaSThomas Graf 	.type		= OVS_VPORT_TYPE_VXLAN,
383*614732eaSThomas Graf 	.create		= vxlan_create,
384*614732eaSThomas Graf 	.destroy	= vxlan_destroy,
385*614732eaSThomas Graf 	.get_options	= vxlan_get_options,
386*614732eaSThomas Graf 	.send		= netdev_send,
387*614732eaSThomas Graf 	.get_egress_tun_info	= vxlan_get_egress_tun_info,
388*614732eaSThomas Graf };
389*614732eaSThomas Graf 
390*614732eaSThomas Graf static int vxlan_compat_init(void)
391*614732eaSThomas Graf {
392*614732eaSThomas Graf 	return ovs_vport_ops_register(&ovs_vxlan_netdev_vport_ops);
393*614732eaSThomas Graf }
394*614732eaSThomas Graf 
395*614732eaSThomas Graf static void vxlan_compat_exit(void)
396*614732eaSThomas Graf {
397*614732eaSThomas Graf 	ovs_vport_ops_unregister(&ovs_vxlan_netdev_vport_ops);
398*614732eaSThomas Graf }
399*614732eaSThomas Graf #else
400*614732eaSThomas Graf static int vxlan_compat_init(void)
401*614732eaSThomas Graf {
402*614732eaSThomas Graf 	return 0;
403*614732eaSThomas Graf }
404*614732eaSThomas Graf 
405*614732eaSThomas Graf static void vxlan_compat_exit(void)
406*614732eaSThomas Graf {
407*614732eaSThomas Graf }
408*614732eaSThomas Graf #endif
409*614732eaSThomas Graf 
41062b9c8d0SThomas Graf int __init ovs_netdev_init(void)
41162b9c8d0SThomas Graf {
412*614732eaSThomas Graf 	int err;
413*614732eaSThomas Graf 
414*614732eaSThomas Graf 	err = ovs_vport_ops_register(&ovs_netdev_vport_ops);
415*614732eaSThomas Graf 	if (err)
416*614732eaSThomas Graf 		return err;
417*614732eaSThomas Graf 	err = vxlan_compat_init();
418*614732eaSThomas Graf 	if (err)
419*614732eaSThomas Graf 		vxlan_compat_exit();
420*614732eaSThomas Graf 	return err;
42162b9c8d0SThomas Graf }
42262b9c8d0SThomas Graf 
42362b9c8d0SThomas Graf void ovs_netdev_exit(void)
42462b9c8d0SThomas Graf {
42562b9c8d0SThomas Graf 	ovs_vport_ops_unregister(&ovs_netdev_vport_ops);
426*614732eaSThomas Graf 	vxlan_compat_exit();
42762b9c8d0SThomas Graf }
428