Skip to content

Commit

Permalink
selftests: forwarding: lib: Add helpers to build IGMP/MLD leave packets
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Petr Machata authored and David S. Miller committed Feb 6, 2023
1 parent 705d4bc commit 9ae8546
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 9ae8546

Please sign in to comment.