@@ -629,6 +629,66 @@ ipv6_fcnal()
629
629
log_test $? 0 " Nexthops removed on admin down"
630
630
}
631
631
632
+ ipv6_grp_refs ()
633
+ {
634
+ if [ ! -x " $( command -v mausezahn) " ]; then
635
+ echo " SKIP: Could not run test; need mausezahn tool"
636
+ return
637
+ fi
638
+
639
+ run_cmd " $IP link set dev veth1 up"
640
+ run_cmd " $IP link add veth1.10 link veth1 up type vlan id 10"
641
+ run_cmd " $IP link add veth1.20 link veth1 up type vlan id 20"
642
+ run_cmd " $IP -6 addr add 2001:db8:91::1/64 dev veth1.10"
643
+ run_cmd " $IP -6 addr add 2001:db8:92::1/64 dev veth1.20"
644
+ run_cmd " $IP -6 neigh add 2001:db8:91::2 lladdr 00:11:22:33:44:55 dev veth1.10"
645
+ run_cmd " $IP -6 neigh add 2001:db8:92::2 lladdr 00:11:22:33:44:55 dev veth1.20"
646
+ run_cmd " $IP nexthop add id 100 via 2001:db8:91::2 dev veth1.10"
647
+ run_cmd " $IP nexthop add id 101 via 2001:db8:92::2 dev veth1.20"
648
+ run_cmd " $IP nexthop add id 102 group 100"
649
+ run_cmd " $IP route add 2001:db8:101::1/128 nhid 102"
650
+
651
+ # create per-cpu dsts through nh 100
652
+ run_cmd " ip netns exec me mausezahn -6 veth1.10 -B 2001:db8:101::1 -A 2001:db8:91::1 -c 5 -t tcp " dp=1-1023, flags=syn" >/dev/null 2>&1"
653
+
654
+ # remove nh 100 from the group to delete the route potentially leaving
655
+ # a stale per-cpu dst which holds a reference to the nexthop's net
656
+ # device and to the IPv6 route
657
+ run_cmd " $IP nexthop replace id 102 group 101"
658
+ run_cmd " $IP route del 2001:db8:101::1/128"
659
+
660
+ # add both nexthops to the group so a reference is taken on them
661
+ run_cmd " $IP nexthop replace id 102 group 100/101"
662
+
663
+ # if the bug described in commit "net: nexthop: release IPv6 per-cpu
664
+ # dsts when replacing a nexthop group" exists at this point we have
665
+ # an unlinked IPv6 route (but not freed due to stale dst) with a
666
+ # reference over the group so we delete the group which will again
667
+ # only unlink it due to the route reference
668
+ run_cmd " $IP nexthop del id 102"
669
+
670
+ # delete the nexthop with stale dst, since we have an unlinked
671
+ # group with a ref to it and an unlinked IPv6 route with ref to the
672
+ # group, the nh will only be unlinked and not freed so the stale dst
673
+ # remains forever and we get a net device refcount imbalance
674
+ run_cmd " $IP nexthop del id 100"
675
+
676
+ # if a reference was lost this command will hang because the net device
677
+ # cannot be removed
678
+ timeout -s KILL 5 ip netns exec me ip link del veth1.10 > /dev/null 2>&1
679
+
680
+ # we can't cleanup if the command is hung trying to delete the netdev
681
+ if [ $? -eq 137 ]; then
682
+ return 1
683
+ fi
684
+
685
+ # cleanup
686
+ run_cmd " $IP link del veth1.20"
687
+ run_cmd " $IP nexthop flush"
688
+
689
+ return 0
690
+ }
691
+
632
692
ipv6_grp_fcnal ()
633
693
{
634
694
local rc
@@ -734,6 +794,9 @@ ipv6_grp_fcnal()
734
794
735
795
run_cmd " $IP nexthop add id 108 group 31/24"
736
796
log_test $? 2 " Nexthop group can not have a blackhole and another nexthop"
797
+
798
+ ipv6_grp_refs
799
+ log_test $? 0 " Nexthop group replace refcounts"
737
800
}
738
801
739
802
ipv6_res_grp_fcnal ()
0 commit comments