selftests: forwarding: lib: Add helpers to build IGMP/MLD leave packets
authorPetr Machata <petrm@nvidia.com>
Thu, 2 Feb 2023 17:59:33 +0000 (18:59 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 6 Feb 2023 08:48:27 +0000 (08:48 +0000)
The testsuite that checks for mcast_max_groups functionality will need to
wipe the added groups as well. Add helpers to build an IGMP or MLD packets
announcing that host is leaving a given group.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/forwarding/lib.sh

index df6b3208e236440581e60929082d4e243a0d0c91..cc7c4f89a097881ffe08b48fe7f471a8e68f25d4 100755 (executable)
@@ -1794,6 +1794,21 @@ igmpv3_is_in_get()
        payload_template_expand_checksum "$igmpv3" $checksum
 }
 
+igmpv2_leave_get()
+{
+       local GRP=$1; shift
+
+       local payload=$(:
+               )"17:"$(                        : Type - Leave Group
+               )"00:"$(                        : Max Resp Time - not meaningful
+               )"CHECKSUM:"$(                  : Checksum
+               )"$(ipv4_to_bytes $GRP)"$(      : Group Address
+               )
+       local checksum=$(payload_template_calc_checksum "$payload")
+
+       payload_template_expand_checksum "$payload" $checksum
+}
+
 mldv2_is_in_get()
 {
        local SIP=$1; shift
@@ -1837,3 +1852,38 @@ mldv2_is_in_get()
 
        payload_template_expand_checksum "$hbh$icmpv6" $checksum
 }
+
+mldv1_done_get()
+{
+       local SIP=$1; shift
+       local GRP=$1; shift
+
+       local hbh
+       local icmpv6
+
+       hbh=$(:
+               )"3a:"$(                        : Next Header - ICMPv6
+               )"00:"$(                        : Hdr Ext Len
+               )"00:00:00:00:00:00:"$(         : Options and Padding
+               )
+
+       icmpv6=$(:
+               )"84:"$(                        : Type - MLDv1 Done
+               )"00:"$(                        : Code
+               )"CHECKSUM:"$(                  : Checksum
+               )"00:00:"$(                     : Max Resp Delay - not meaningful
+               )"00:00:"$(                     : Reserved
+               )"$(ipv6_to_bytes $GRP):"$(     : Multicast address
+               )
+
+       local len=$(u16_to_bytes $(payload_template_nbytes $icmpv6))
+       local sudohdr=$(:
+               )"$(ipv6_to_bytes $SIP):"$(     : SIP
+               )"$(ipv6_to_bytes $GRP):"$(     : DIP is multicast address
+               )"${len}:"$(                    : Upper-layer length
+               )"00:3a:"$(                     : Zero and next-header
+               )
+       local checksum=$(payload_template_calc_checksum ${sudohdr}${icmpv6})
+
+       payload_template_expand_checksum "$hbh$icmpv6" $checksum
+}