Skip to content

Commit dcc38c0

Browse files
tgrafdavem330
authored andcommitted
openvswitch: Re-add CONFIG_OPENVSWITCH_VXLAN
This readds the config option CONFIG_OPENVSWITCH_VXLAN to avoid a hard dependency of OVS on VXLAN. It moves the VXLAN config compat code to vport-vxlan.c and allows compliation as a module. Fixes: 614732e ("openvswitch: Use regular VXLAN net_device device") Fixes: 2661371 ("openvswitch: fix compilation when vxlan is a module") Cc: Pravin B Shelar <[email protected]> Cc: Nicolas Dichtel <[email protected]> Signed-off-by: Thomas Graf <[email protected]> Acked-by: Pravin B Shelar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1ce4b2f commit dcc38c0

File tree

5 files changed

+235
-200
lines changed

5 files changed

+235
-200
lines changed

net/openvswitch/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
config OPENVSWITCH
66
tristate "Open vSwitch"
77
depends on INET
8-
depends on VXLAN
98
select LIBCRC32C
109
select MPLS
1110
select NET_MPLS_GSO
@@ -45,6 +44,18 @@ config OPENVSWITCH_GRE
4544

4645
If unsure, say Y.
4746

47+
config OPENVSWITCH_VXLAN
48+
tristate "Open vSwitch VXLAN tunneling support"
49+
depends on OPENVSWITCH
50+
depends on VXLAN
51+
default OPENVSWITCH
52+
---help---
53+
If you say Y here, then the Open vSwitch will be able create vxlan vport.
54+
55+
Say N to exclude this support and reduce the binary size.
56+
57+
If unsure, say Y.
58+
4859
config OPENVSWITCH_GENEVE
4960
tristate "Open vSwitch Geneve tunneling support"
5061
depends on OPENVSWITCH

net/openvswitch/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ openvswitch-y := \
1515
vport-internal_dev.o \
1616
vport-netdev.o
1717

18+
obj-$(CONFIG_OPENVSWITCH_VXLAN)+= vport-vxlan.o
1819
obj-$(CONFIG_OPENVSWITCH_GENEVE)+= vport-geneve.o
1920
obj-$(CONFIG_OPENVSWITCH_GRE) += vport-gre.o

net/openvswitch/vport-netdev.c

Lines changed: 12 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626
#include <linux/rtnetlink.h>
2727
#include <linux/skbuff.h>
2828
#include <linux/openvswitch.h>
29+
#include <linux/export.h>
2930

30-
#include <net/udp.h>
3131
#include <net/ip_tunnels.h>
3232
#include <net/rtnetlink.h>
33-
#include <net/vxlan.h>
3433

3534
#include "datapath.h"
3635
#include "vport.h"
@@ -90,7 +89,7 @@ static struct net_device *get_dpdev(const struct datapath *dp)
9089
return local->dev;
9190
}
9291

93-
static struct vport *netdev_link(struct vport *vport, const char *name)
92+
struct vport *ovs_netdev_link(struct vport *vport, const char *name)
9493
{
9594
int err;
9695

@@ -135,6 +134,7 @@ static struct vport *netdev_link(struct vport *vport, const char *name)
135134
ovs_vport_free(vport);
136135
return ERR_PTR(err);
137136
}
137+
EXPORT_SYMBOL_GPL(ovs_netdev_link);
138138

139139
static struct vport *netdev_create(const struct vport_parms *parms)
140140
{
@@ -144,17 +144,18 @@ static struct vport *netdev_create(const struct vport_parms *parms)
144144
if (IS_ERR(vport))
145145
return vport;
146146

147-
return netdev_link(vport, parms->name);
147+
return ovs_netdev_link(vport, parms->name);
148148
}
149149

150-
static void free_port_rcu(struct rcu_head *rcu)
150+
void ovs_vport_free_rcu(struct rcu_head *rcu)
151151
{
152152
struct vport *vport = container_of(rcu, struct vport, rcu);
153153

154154
if (vport->dev)
155155
dev_put(vport->dev);
156156
ovs_vport_free(vport);
157157
}
158+
EXPORT_SYMBOL_GPL(ovs_vport_free_rcu);
158159

159160
void ovs_netdev_detach_dev(struct vport *vport)
160161
{
@@ -165,6 +166,7 @@ void ovs_netdev_detach_dev(struct vport *vport)
165166
netdev_master_upper_dev_get(vport->dev));
166167
dev_set_promiscuity(vport->dev, -1);
167168
}
169+
EXPORT_SYMBOL_GPL(ovs_netdev_detach_dev);
168170

169171
static void netdev_destroy(struct vport *vport)
170172
{
@@ -173,7 +175,7 @@ static void netdev_destroy(struct vport *vport)
173175
ovs_netdev_detach_dev(vport);
174176
rtnl_unlock();
175177

176-
call_rcu(&vport->rcu, free_port_rcu);
178+
call_rcu(&vport->rcu, ovs_vport_free_rcu);
177179
}
178180

179181
static unsigned int packet_length(const struct sk_buff *skb)
@@ -186,7 +188,7 @@ static unsigned int packet_length(const struct sk_buff *skb)
186188
return length;
187189
}
188190

189-
static int netdev_send(struct vport *vport, struct sk_buff *skb)
191+
int ovs_netdev_send(struct vport *vport, struct sk_buff *skb)
190192
{
191193
int mtu = vport->dev->mtu;
192194
int len;
@@ -208,6 +210,7 @@ static int netdev_send(struct vport *vport, struct sk_buff *skb)
208210
kfree_skb(skb);
209211
return 0;
210212
}
213+
EXPORT_SYMBOL_GPL(ovs_netdev_send);
211214

212215
/* Returns null if this device is not attached to a datapath. */
213216
struct vport *ovs_netdev_get_vport(struct net_device *dev)
@@ -223,205 +226,15 @@ static struct vport_ops ovs_netdev_vport_ops = {
223226
.type = OVS_VPORT_TYPE_NETDEV,
224227
.create = netdev_create,
225228
.destroy = netdev_destroy,
226-
.send = netdev_send,
229+
.send = ovs_netdev_send,
227230
};
228231

229-
/* Compat code for old userspace. */
230-
#if IS_ENABLED(CONFIG_VXLAN)
231-
static struct vport_ops ovs_vxlan_netdev_vport_ops;
232-
233-
static int vxlan_get_options(const struct vport *vport, struct sk_buff *skb)
234-
{
235-
struct vxlan_dev *vxlan = netdev_priv(vport->dev);
236-
__be16 dst_port = vxlan->cfg.dst_port;
237-
238-
if (nla_put_u16(skb, OVS_TUNNEL_ATTR_DST_PORT, ntohs(dst_port)))
239-
return -EMSGSIZE;
240-
241-
if (vxlan->flags & VXLAN_F_GBP) {
242-
struct nlattr *exts;
243-
244-
exts = nla_nest_start(skb, OVS_TUNNEL_ATTR_EXTENSION);
245-
if (!exts)
246-
return -EMSGSIZE;
247-
248-
if (vxlan->flags & VXLAN_F_GBP &&
249-
nla_put_flag(skb, OVS_VXLAN_EXT_GBP))
250-
return -EMSGSIZE;
251-
252-
nla_nest_end(skb, exts);
253-
}
254-
255-
return 0;
256-
}
257-
258-
static const struct nla_policy exts_policy[OVS_VXLAN_EXT_MAX + 1] = {
259-
[OVS_VXLAN_EXT_GBP] = { .type = NLA_FLAG, },
260-
};
261-
262-
static int vxlan_configure_exts(struct vport *vport, struct nlattr *attr,
263-
struct vxlan_config *conf)
264-
{
265-
struct nlattr *exts[OVS_VXLAN_EXT_MAX + 1];
266-
int err;
267-
268-
if (nla_len(attr) < sizeof(struct nlattr))
269-
return -EINVAL;
270-
271-
err = nla_parse_nested(exts, OVS_VXLAN_EXT_MAX, attr, exts_policy);
272-
if (err < 0)
273-
return err;
274-
275-
if (exts[OVS_VXLAN_EXT_GBP])
276-
conf->flags |= VXLAN_F_GBP;
277-
278-
return 0;
279-
}
280-
281-
static struct vport *vxlan_tnl_create(const struct vport_parms *parms)
282-
{
283-
struct net *net = ovs_dp_get_net(parms->dp);
284-
struct nlattr *options = parms->options;
285-
struct net_device *dev;
286-
struct vport *vport;
287-
struct nlattr *a;
288-
int err;
289-
struct vxlan_config conf = {
290-
.no_share = true,
291-
.flags = VXLAN_F_FLOW_BASED | VXLAN_F_COLLECT_METADATA,
292-
};
293-
294-
if (!options) {
295-
err = -EINVAL;
296-
goto error;
297-
}
298-
299-
a = nla_find_nested(options, OVS_TUNNEL_ATTR_DST_PORT);
300-
if (a && nla_len(a) == sizeof(u16)) {
301-
conf.dst_port = htons(nla_get_u16(a));
302-
} else {
303-
/* Require destination port from userspace. */
304-
err = -EINVAL;
305-
goto error;
306-
}
307-
308-
vport = ovs_vport_alloc(0, &ovs_vxlan_netdev_vport_ops, parms);
309-
if (IS_ERR(vport))
310-
return vport;
311-
312-
a = nla_find_nested(options, OVS_TUNNEL_ATTR_EXTENSION);
313-
if (a) {
314-
err = vxlan_configure_exts(vport, a, &conf);
315-
if (err) {
316-
ovs_vport_free(vport);
317-
goto error;
318-
}
319-
}
320-
321-
rtnl_lock();
322-
dev = vxlan_dev_create(net, parms->name, NET_NAME_USER, &conf);
323-
if (IS_ERR(dev)) {
324-
rtnl_unlock();
325-
ovs_vport_free(vport);
326-
return ERR_CAST(dev);
327-
}
328-
329-
dev_change_flags(dev, dev->flags | IFF_UP);
330-
rtnl_unlock();
331-
return vport;
332-
error:
333-
return ERR_PTR(err);
334-
}
335-
336-
static struct vport *vxlan_create(const struct vport_parms *parms)
337-
{
338-
struct vport *vport;
339-
340-
vport = vxlan_tnl_create(parms);
341-
if (IS_ERR(vport))
342-
return vport;
343-
344-
return netdev_link(vport, parms->name);
345-
}
346-
347-
static void vxlan_destroy(struct vport *vport)
348-
{
349-
rtnl_lock();
350-
if (vport->dev->priv_flags & IFF_OVS_DATAPATH)
351-
ovs_netdev_detach_dev(vport);
352-
353-
/* Early release so we can unregister the device */
354-
dev_put(vport->dev);
355-
rtnl_delete_link(vport->dev);
356-
vport->dev = NULL;
357-
rtnl_unlock();
358-
359-
call_rcu(&vport->rcu, free_port_rcu);
360-
}
361-
362-
static int vxlan_get_egress_tun_info(struct vport *vport, struct sk_buff *skb,
363-
struct ip_tunnel_info *egress_tun_info)
364-
{
365-
struct vxlan_dev *vxlan = netdev_priv(vport->dev);
366-
struct net *net = ovs_dp_get_net(vport->dp);
367-
__be16 dst_port = vxlan_dev_dst_port(vxlan);
368-
__be16 src_port;
369-
int port_min;
370-
int port_max;
371-
372-
inet_get_local_port_range(net, &port_min, &port_max);
373-
src_port = udp_flow_src_port(net, skb, 0, 0, true);
374-
375-
return ovs_tunnel_get_egress_info(egress_tun_info, net,
376-
OVS_CB(skb)->egress_tun_info,
377-
IPPROTO_UDP, skb->mark,
378-
src_port, dst_port);
379-
}
380-
381-
static struct vport_ops ovs_vxlan_netdev_vport_ops = {
382-
.type = OVS_VPORT_TYPE_VXLAN,
383-
.create = vxlan_create,
384-
.destroy = vxlan_destroy,
385-
.get_options = vxlan_get_options,
386-
.send = netdev_send,
387-
.get_egress_tun_info = vxlan_get_egress_tun_info,
388-
};
389-
390-
static int vxlan_compat_init(void)
391-
{
392-
return ovs_vport_ops_register(&ovs_vxlan_netdev_vport_ops);
393-
}
394-
395-
static void vxlan_compat_exit(void)
396-
{
397-
ovs_vport_ops_unregister(&ovs_vxlan_netdev_vport_ops);
398-
}
399-
#else
400-
static int vxlan_compat_init(void)
401-
{
402-
return 0;
403-
}
404-
405-
static void vxlan_compat_exit(void)
406-
{
407-
}
408-
#endif
409-
410232
int __init ovs_netdev_init(void)
411233
{
412-
int err;
413-
414-
err = ovs_vport_ops_register(&ovs_netdev_vport_ops);
415-
if (err)
416-
return err;
417-
err = vxlan_compat_init();
418-
if (err)
419-
vxlan_compat_exit();
420-
return err;
234+
return ovs_vport_ops_register(&ovs_netdev_vport_ops);
421235
}
422236

423237
void ovs_netdev_exit(void)
424238
{
425239
ovs_vport_ops_unregister(&ovs_netdev_vport_ops);
426-
vxlan_compat_exit();
427240
}

net/openvswitch/vport-netdev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626

2727
struct vport *ovs_netdev_get_vport(struct net_device *dev);
2828

29+
struct vport *ovs_netdev_link(struct vport *vport, const char *name);
30+
int ovs_netdev_send(struct vport *vport, struct sk_buff *skb);
2931
void ovs_netdev_detach_dev(struct vport *);
32+
void ovs_vport_free_rcu(struct rcu_head *);
3033

3134
int __init ovs_netdev_init(void);
3235
void ovs_netdev_exit(void);

0 commit comments

Comments
 (0)