26
26
#include <linux/rtnetlink.h>
27
27
#include <linux/skbuff.h>
28
28
#include <linux/openvswitch.h>
29
+ #include <linux/export.h>
29
30
30
- #include <net/udp.h>
31
31
#include <net/ip_tunnels.h>
32
32
#include <net/rtnetlink.h>
33
- #include <net/vxlan.h>
34
33
35
34
#include "datapath.h"
36
35
#include "vport.h"
@@ -90,7 +89,7 @@ static struct net_device *get_dpdev(const struct datapath *dp)
90
89
return local -> dev ;
91
90
}
92
91
93
- static struct vport * netdev_link (struct vport * vport , const char * name )
92
+ struct vport * ovs_netdev_link (struct vport * vport , const char * name )
94
93
{
95
94
int err ;
96
95
@@ -135,6 +134,7 @@ static struct vport *netdev_link(struct vport *vport, const char *name)
135
134
ovs_vport_free (vport );
136
135
return ERR_PTR (err );
137
136
}
137
+ EXPORT_SYMBOL_GPL (ovs_netdev_link );
138
138
139
139
static struct vport * netdev_create (const struct vport_parms * parms )
140
140
{
@@ -144,17 +144,18 @@ static struct vport *netdev_create(const struct vport_parms *parms)
144
144
if (IS_ERR (vport ))
145
145
return vport ;
146
146
147
- return netdev_link (vport , parms -> name );
147
+ return ovs_netdev_link (vport , parms -> name );
148
148
}
149
149
150
- static void free_port_rcu (struct rcu_head * rcu )
150
+ void ovs_vport_free_rcu (struct rcu_head * rcu )
151
151
{
152
152
struct vport * vport = container_of (rcu , struct vport , rcu );
153
153
154
154
if (vport -> dev )
155
155
dev_put (vport -> dev );
156
156
ovs_vport_free (vport );
157
157
}
158
+ EXPORT_SYMBOL_GPL (ovs_vport_free_rcu );
158
159
159
160
void ovs_netdev_detach_dev (struct vport * vport )
160
161
{
@@ -165,6 +166,7 @@ void ovs_netdev_detach_dev(struct vport *vport)
165
166
netdev_master_upper_dev_get (vport -> dev ));
166
167
dev_set_promiscuity (vport -> dev , -1 );
167
168
}
169
+ EXPORT_SYMBOL_GPL (ovs_netdev_detach_dev );
168
170
169
171
static void netdev_destroy (struct vport * vport )
170
172
{
@@ -173,7 +175,7 @@ static void netdev_destroy(struct vport *vport)
173
175
ovs_netdev_detach_dev (vport );
174
176
rtnl_unlock ();
175
177
176
- call_rcu (& vport -> rcu , free_port_rcu );
178
+ call_rcu (& vport -> rcu , ovs_vport_free_rcu );
177
179
}
178
180
179
181
static unsigned int packet_length (const struct sk_buff * skb )
@@ -186,7 +188,7 @@ static unsigned int packet_length(const struct sk_buff *skb)
186
188
return length ;
187
189
}
188
190
189
- static int netdev_send (struct vport * vport , struct sk_buff * skb )
191
+ int ovs_netdev_send (struct vport * vport , struct sk_buff * skb )
190
192
{
191
193
int mtu = vport -> dev -> mtu ;
192
194
int len ;
@@ -208,6 +210,7 @@ static int netdev_send(struct vport *vport, struct sk_buff *skb)
208
210
kfree_skb (skb );
209
211
return 0 ;
210
212
}
213
+ EXPORT_SYMBOL_GPL (ovs_netdev_send );
211
214
212
215
/* Returns null if this device is not attached to a datapath. */
213
216
struct vport * ovs_netdev_get_vport (struct net_device * dev )
@@ -223,205 +226,15 @@ static struct vport_ops ovs_netdev_vport_ops = {
223
226
.type = OVS_VPORT_TYPE_NETDEV ,
224
227
.create = netdev_create ,
225
228
.destroy = netdev_destroy ,
226
- .send = netdev_send ,
229
+ .send = ovs_netdev_send ,
227
230
};
228
231
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
-
410
232
int __init ovs_netdev_init (void )
411
233
{
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 );
421
235
}
422
236
423
237
void ovs_netdev_exit (void )
424
238
{
425
239
ovs_vport_ops_unregister (& ovs_netdev_vport_ops );
426
- vxlan_compat_exit ();
427
240
}
0 commit comments