@@ -384,8 +384,7 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
384
384
{
385
385
struct bpf_link * link = NULL ;
386
386
struct bpf_link * link2 = NULL ;
387
- int veth , bond ;
388
- int err ;
387
+ int veth , bond , err ;
389
388
390
389
if (!ASSERT_OK (system ("ip link add veth type veth" ), "add veth" ))
391
390
goto out ;
@@ -399,22 +398,18 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
399
398
if (!ASSERT_GE (bond , 0 , "if_nametoindex bond" ))
400
399
goto out ;
401
400
402
- /* enslaving with a XDP program loaded fails */
401
+ /* enslaving with a XDP program loaded is allowed */
403
402
link = bpf_program__attach_xdp (skeletons -> xdp_dummy -> progs .xdp_dummy_prog , veth );
404
403
if (!ASSERT_OK_PTR (link , "attach program to veth" ))
405
404
goto out ;
406
405
407
406
err = system ("ip link set veth master bond" );
408
- if (!ASSERT_NEQ (err , 0 , "attaching slave with xdp program expected to fail " ))
407
+ if (!ASSERT_OK (err , "set veth master " ))
409
408
goto out ;
410
409
411
410
bpf_link__destroy (link );
412
411
link = NULL ;
413
412
414
- err = system ("ip link set veth master bond" );
415
- if (!ASSERT_OK (err , "set veth master" ))
416
- goto out ;
417
-
418
413
/* attaching to slave when master has no program is allowed */
419
414
link = bpf_program__attach_xdp (skeletons -> xdp_dummy -> progs .xdp_dummy_prog , veth );
420
415
if (!ASSERT_OK_PTR (link , "attach program to slave when enslaved" ))
@@ -434,15 +429,71 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
434
429
goto out ;
435
430
436
431
/* attaching to slave not allowed when master has program loaded */
437
- link2 = bpf_program__attach_xdp (skeletons -> xdp_dummy -> progs .xdp_dummy_prog , bond );
438
- ASSERT_ERR_PTR (link2 , "attach program to slave when master has program" );
432
+ link2 = bpf_program__attach_xdp (skeletons -> xdp_dummy -> progs .xdp_dummy_prog , veth );
433
+ if (!ASSERT_ERR_PTR (link2 , "attach program to slave when master has program" ))
434
+ goto out ;
435
+
436
+ bpf_link__destroy (link );
437
+ link = NULL ;
438
+
439
+ /* test program unwinding with a non-XDP slave */
440
+ if (!ASSERT_OK (system ("ip link add vxlan type vxlan id 1 remote 1.2.3.4 dstport 0 dev lo" ),
441
+ "add vxlan" ))
442
+ goto out ;
443
+
444
+ err = system ("ip link set vxlan master bond" );
445
+ if (!ASSERT_OK (err , "set vxlan master" ))
446
+ goto out ;
447
+
448
+ /* attaching not allowed when one slave does not support XDP */
449
+ link = bpf_program__attach_xdp (skeletons -> xdp_dummy -> progs .xdp_dummy_prog , bond );
450
+ if (!ASSERT_ERR_PTR (link , "attach program to master when slave does not support XDP" ))
451
+ goto out ;
439
452
440
453
out :
441
454
bpf_link__destroy (link );
442
455
bpf_link__destroy (link2 );
443
456
444
457
system ("ip link del veth" );
445
458
system ("ip link del bond" );
459
+ system ("ip link del vxlan" );
460
+ }
461
+
462
+ /* Test with nested bonding devices to catch issue with negative jump label count */
463
+ static void test_xdp_bonding_nested (struct skeletons * skeletons )
464
+ {
465
+ struct bpf_link * link = NULL ;
466
+ int bond , err ;
467
+
468
+ if (!ASSERT_OK (system ("ip link add bond type bond" ), "add bond" ))
469
+ goto out ;
470
+
471
+ bond = if_nametoindex ("bond" );
472
+ if (!ASSERT_GE (bond , 0 , "if_nametoindex bond" ))
473
+ goto out ;
474
+
475
+ if (!ASSERT_OK (system ("ip link add bond_nest1 type bond" ), "add bond_nest1" ))
476
+ goto out ;
477
+
478
+ err = system ("ip link set bond_nest1 master bond" );
479
+ if (!ASSERT_OK (err , "set bond_nest1 master" ))
480
+ goto out ;
481
+
482
+ if (!ASSERT_OK (system ("ip link add bond_nest2 type bond" ), "add bond_nest1" ))
483
+ goto out ;
484
+
485
+ err = system ("ip link set bond_nest2 master bond_nest1" );
486
+ if (!ASSERT_OK (err , "set bond_nest2 master" ))
487
+ goto out ;
488
+
489
+ link = bpf_program__attach_xdp (skeletons -> xdp_dummy -> progs .xdp_dummy_prog , bond );
490
+ ASSERT_OK_PTR (link , "attach program to master" );
491
+
492
+ out :
493
+ bpf_link__destroy (link );
494
+ system ("ip link del bond" );
495
+ system ("ip link del bond_nest1" );
496
+ system ("ip link del bond_nest2" );
446
497
}
447
498
448
499
static int libbpf_debug_print (enum libbpf_print_level level ,
@@ -496,6 +547,9 @@ void test_xdp_bonding(void)
496
547
if (test__start_subtest ("xdp_bonding_attach" ))
497
548
test_xdp_bonding_attach (& skeletons );
498
549
550
+ if (test__start_subtest ("xdp_bonding_nested" ))
551
+ test_xdp_bonding_nested (& skeletons );
552
+
499
553
for (i = 0 ; i < ARRAY_SIZE (bond_test_cases ); i ++ ) {
500
554
struct bond_test_case * test_case = & bond_test_cases [i ];
501
555
0 commit comments