Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/netinet/multicast.sh
39483 views
1
#
2
# SPDX-License-Identifier: BSD-2-Clause
3
#
4
# Copyright (c) 2025 Gleb Smirnoff <[email protected]>
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions
8
# are met:
9
# 1. Redistributions of source code must retain the above copyright
10
# notice, this list of conditions and the following disclaimer.
11
# 2. Redistributions in binary form must reproduce the above copyright
12
# notice, this list of conditions and the following disclaimer in the
13
# documentation and/or other materials provided with the distribution.
14
#
15
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
# SUCH DAMAGE.
26
27
. $(atf_get_srcdir)/../common/vnet.subr
28
29
# Set up two jails, mjail1 and mjail2, connected with two interface pairs
30
multicast_vnet_init()
31
{
32
33
vnet_init
34
epair1=$(vnet_mkepair)
35
epair2=$(vnet_mkepair)
36
vnet_mkjail mjail1 ${epair1}a ${epair2}a
37
jexec mjail1 ifconfig ${epair1}a up
38
jexec mjail1 ifconfig ${epair1}a 192.0.2.1/24
39
jexec mjail1 ifconfig ${epair2}a up
40
jexec mjail1 ifconfig ${epair2}a 192.0.3.1/24
41
vnet_mkjail mjail2 ${epair1}b ${epair2}b
42
jexec mjail2 ifconfig ${epair1}b up
43
jexec mjail2 ifconfig ${epair1}b 192.0.2.2/24
44
jexec mjail2 ifconfig ${epair2}b up
45
jexec mjail2 ifconfig ${epair2}b 192.0.3.2/24
46
}
47
48
atf_test_case "IP_ADD_MEMBERSHIP_ip_mreq" "cleanup"
49
IP_ADD_MEMBERSHIP_ip_mreq_head()
50
{
51
atf_set descr 'IP_ADD_MEMBERSHIP / IP_MULTICAST_IF with ip_mreq'
52
atf_set require.user root
53
}
54
IP_ADD_MEMBERSHIP_ip_mreq_body()
55
{
56
multicast_vnet_init
57
58
# join group on interface with IP address 192.0.2.2
59
jexec mjail2 $(atf_get_srcdir)/multicast-receive \
60
ip_mreq 233.252.0.1 6676 192.0.2.2 > out & pid=$!
61
atf_check -s exit:0 -o empty \
62
jexec mjail1 $(atf_get_srcdir)/multicast-send \
63
0.0.0.0 6676 233.252.0.1 6676 192.0.2.1 hello
64
atf_check -s exit:0 sh -c "wait $pid; exit $?"
65
atf_check -s exit:0 -o inline:"192.0.2.1:6676 hello\n" cat out
66
67
# join group on interface with IP address 192.0.3.2
68
jexec mjail2 $(atf_get_srcdir)/multicast-receive \
69
ip_mreq 233.252.0.1 6676 192.0.3.2 > out & pid=$!
70
atf_check -s exit:0 -o empty \
71
jexec mjail1 $(atf_get_srcdir)/multicast-send \
72
0.0.0.0 6676 233.252.0.1 6676 192.0.3.1 hello
73
atf_check -s exit:0 sh -c "wait $pid; exit $?"
74
atf_check -s exit:0 -o inline:"192.0.3.1:6676 hello\n" cat out
75
}
76
IP_ADD_MEMBERSHIP_ip_mreq_cleanup()
77
{
78
rm out
79
vnet_cleanup
80
}
81
82
atf_test_case "IP_ADD_MEMBERSHIP_ip_mreqn" "cleanup"
83
IP_ADD_MEMBERSHIP_ip_mreqn_head()
84
{
85
atf_set descr 'IP_ADD_MEMBERSHIP / IP_MULTICAST_IF with ip_mreqn'
86
atf_set require.user root
87
}
88
IP_ADD_MEMBERSHIP_ip_mreqn_body()
89
{
90
multicast_vnet_init
91
92
# join group on interface epair2
93
jexec mjail2 $(atf_get_srcdir)/multicast-receive \
94
ip_mreqn 233.252.0.1 6676 ${epair1}b > out & pid=$!
95
atf_check -s exit:0 -o empty \
96
jexec mjail1 $(atf_get_srcdir)/multicast-send \
97
0.0.0.0 6676 233.252.0.1 6676 ${epair1}a hello
98
atf_check -s exit:0 sh -c "wait $pid; exit $?"
99
atf_check -s exit:0 -o inline:"192.0.2.1:6676 hello\n" cat out
100
101
# join group on interface epair2
102
jexec mjail2 $(atf_get_srcdir)/multicast-receive \
103
ip_mreqn 233.252.0.1 6676 ${epair2}b > out & pid=$!
104
atf_check -s exit:0 -o empty \
105
jexec mjail1 $(atf_get_srcdir)/multicast-send \
106
0.0.0.0 6676 233.252.0.1 6676 ${epair2}a hello
107
atf_check -s exit:0 sh -c "wait $pid; exit $?"
108
atf_check -s exit:0 -o inline:"192.0.3.1:6676 hello\n" cat out
109
}
110
IP_ADD_MEMBERSHIP_ip_mreqn_cleanup()
111
{
112
rm out
113
vnet_cleanup
114
}
115
116
atf_test_case "MCAST_JOIN_GROUP" "cleanup"
117
MCAST_JOIN_GROUP_head()
118
{
119
atf_set descr 'MCAST_JOIN_GROUP'
120
atf_set require.user root
121
}
122
MCAST_JOIN_GROUP_body()
123
{
124
multicast_vnet_init
125
126
# join group on interface epair2
127
jexec mjail2 $(atf_get_srcdir)/multicast-receive \
128
group_req 233.252.0.1 6676 ${epair1}b > out & pid=$!
129
atf_check -s exit:0 -o empty \
130
jexec mjail1 $(atf_get_srcdir)/multicast-send \
131
0.0.0.0 6676 233.252.0.1 6676 ${epair1}a hello
132
atf_check -s exit:0 sh -c "wait $pid; exit $?"
133
atf_check -s exit:0 -o inline:"192.0.2.1:6676 hello\n" cat out
134
135
# join group on interface epair2
136
jexec mjail2 $(atf_get_srcdir)/multicast-receive \
137
group_req 233.252.0.1 6676 ${epair2}b > out & pid=$!
138
atf_check -s exit:0 -o empty \
139
jexec mjail1 $(atf_get_srcdir)/multicast-send \
140
0.0.0.0 6676 233.252.0.1 6676 ${epair2}a hello
141
atf_check -s exit:0 sh -c "wait $pid; exit $?"
142
atf_check -s exit:0 -o inline:"192.0.3.1:6676 hello\n" cat out
143
}
144
MCAST_JOIN_GROUP_cleanup()
145
{
146
rm out
147
vnet_cleanup
148
}
149
150
atf_init_test_cases()
151
{
152
atf_add_test_case "IP_ADD_MEMBERSHIP_ip_mreq"
153
atf_add_test_case "IP_ADD_MEMBERSHIP_ip_mreqn"
154
atf_add_test_case "MCAST_JOIN_GROUP"
155
}
156
157