1*b13321fcSBruce M Simpson /*-
2*b13321fcSBruce M Simpson * Copyright (c) 2007 Bruce M. Simpson
3*b13321fcSBruce M Simpson * All rights reserved.
4*b13321fcSBruce M Simpson *
5*b13321fcSBruce M Simpson * Redistribution and use in source and binary forms, with or without
6*b13321fcSBruce M Simpson * modification, are permitted provided that the following conditions
7*b13321fcSBruce M Simpson * are met:
8*b13321fcSBruce M Simpson * 1. Redistributions of source code must retain the above copyright
9*b13321fcSBruce M Simpson * notice, this list of conditions and the following disclaimer.
10*b13321fcSBruce M Simpson * 2. Redistributions in binary form must reproduce the above copyright
11*b13321fcSBruce M Simpson * notice, this list of conditions and the following disclaimer in the
12*b13321fcSBruce M Simpson * documentation and/or other materials provided with the distribution.
13*b13321fcSBruce M Simpson *
14*b13321fcSBruce M Simpson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*b13321fcSBruce M Simpson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*b13321fcSBruce M Simpson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*b13321fcSBruce M Simpson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*b13321fcSBruce M Simpson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*b13321fcSBruce M Simpson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*b13321fcSBruce M Simpson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*b13321fcSBruce M Simpson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*b13321fcSBruce M Simpson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*b13321fcSBruce M Simpson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*b13321fcSBruce M Simpson * SUCH DAMAGE.
25*b13321fcSBruce M Simpson */
26*b13321fcSBruce M Simpson
27*b13321fcSBruce M Simpson /*
28*b13321fcSBruce M Simpson * Regression test utility for RFC 3678 Advanced Multicast API in FreeBSD.
29*b13321fcSBruce M Simpson *
30*b13321fcSBruce M Simpson * TODO: Test the SSM paths.
31*b13321fcSBruce M Simpson * TODO: Support INET6. The code has been written to facilitate this later.
32*b13321fcSBruce M Simpson * TODO: Merge multicast socket option tests from ipsockopt.
33*b13321fcSBruce M Simpson */
34*b13321fcSBruce M Simpson
35*b13321fcSBruce M Simpson #include <sys/param.h>
36*b13321fcSBruce M Simpson #include <sys/types.h>
37*b13321fcSBruce M Simpson #include <sys/ioctl.h>
38*b13321fcSBruce M Simpson #include <sys/socket.h>
39*b13321fcSBruce M Simpson
40*b13321fcSBruce M Simpson #include <net/if.h>
41*b13321fcSBruce M Simpson #include <net/if_dl.h>
42*b13321fcSBruce M Simpson #include <netinet/in.h>
43*b13321fcSBruce M Simpson #include <arpa/inet.h>
44*b13321fcSBruce M Simpson #include <netdb.h>
45*b13321fcSBruce M Simpson
46*b13321fcSBruce M Simpson #include <assert.h>
47*b13321fcSBruce M Simpson #include <err.h>
48*b13321fcSBruce M Simpson #include <errno.h>
49*b13321fcSBruce M Simpson #include <getopt.h>
50*b13321fcSBruce M Simpson #include <libgen.h>
51*b13321fcSBruce M Simpson #include <pwd.h>
52*b13321fcSBruce M Simpson #include <setjmp.h>
53*b13321fcSBruce M Simpson #include <signal.h>
54*b13321fcSBruce M Simpson #include <stddef.h>
55*b13321fcSBruce M Simpson #include <stdio.h>
56*b13321fcSBruce M Simpson #include <stdlib.h>
57*b13321fcSBruce M Simpson #include <string.h>
58*b13321fcSBruce M Simpson #include <sysexits.h>
59*b13321fcSBruce M Simpson #include <time.h>
60*b13321fcSBruce M Simpson #include <unistd.h>
61*b13321fcSBruce M Simpson
62*b13321fcSBruce M Simpson #ifndef __SOCKUNION_DECLARED
63*b13321fcSBruce M Simpson union sockunion {
64*b13321fcSBruce M Simpson struct sockaddr_storage ss;
65*b13321fcSBruce M Simpson struct sockaddr sa;
66*b13321fcSBruce M Simpson struct sockaddr_dl sdl;
67*b13321fcSBruce M Simpson struct sockaddr_in sin;
68*b13321fcSBruce M Simpson #ifdef INET6
69*b13321fcSBruce M Simpson struct sockaddr_in6 sin6;
70*b13321fcSBruce M Simpson #endif
71*b13321fcSBruce M Simpson };
72*b13321fcSBruce M Simpson typedef union sockunion sockunion_t;
73*b13321fcSBruce M Simpson #define __SOCKUNION_DECLARED
74*b13321fcSBruce M Simpson #endif /* __SOCKUNION_DECLARED */
75*b13321fcSBruce M Simpson
76*b13321fcSBruce M Simpson #define ADDRBUF_LEN 16
77*b13321fcSBruce M Simpson #define DEFAULT_GROUP_STR "238.1.1.0"
78*b13321fcSBruce M Simpson #define DEFAULT_IFNAME "lo0"
79*b13321fcSBruce M Simpson #define DEFAULT_IFADDR_STR "127.0.0.1"
80*b13321fcSBruce M Simpson #define DEFAULT_PORT 6698
81*b13321fcSBruce M Simpson #define DEFAULT_TIMEOUT 0 /* don't wait for traffic */
82*b13321fcSBruce M Simpson #define RXBUFSIZE 2048
83*b13321fcSBruce M Simpson
84*b13321fcSBruce M Simpson static sockunion_t basegroup;
85*b13321fcSBruce M Simpson static const char *basegroup_str = NULL;
86*b13321fcSBruce M Simpson static int dobindaddr = 0;
87*b13321fcSBruce M Simpson static int dodebug = 1;
88*b13321fcSBruce M Simpson static int doipv4 = 0;
89*b13321fcSBruce M Simpson static int domiscopts = 0;
90*b13321fcSBruce M Simpson static int dorandom = 0;
91*b13321fcSBruce M Simpson static int doreuseport = 0;
92*b13321fcSBruce M Simpson static int dossm = 0;
93*b13321fcSBruce M Simpson static int dossf = 0;
94*b13321fcSBruce M Simpson static int doverbose = 0;
95*b13321fcSBruce M Simpson static sockunion_t ifaddr;
96*b13321fcSBruce M Simpson static const char *ifaddr_str = NULL;
97*b13321fcSBruce M Simpson static uint32_t ifindex = 0;
98*b13321fcSBruce M Simpson static const char *ifname = NULL;
99*b13321fcSBruce M Simpson struct in_addr *ipv4_sources = NULL;
100*b13321fcSBruce M Simpson static jmp_buf jmpbuf;
101*b13321fcSBruce M Simpson static size_t nmcastgroups = IP_MAX_MEMBERSHIPS;
102*b13321fcSBruce M Simpson static size_t nmcastsources = 0;
103*b13321fcSBruce M Simpson static uint16_t portno = DEFAULT_PORT;
104*b13321fcSBruce M Simpson static char *progname = NULL;
105*b13321fcSBruce M Simpson struct sockaddr_storage *ss_sources = NULL;
106*b13321fcSBruce M Simpson static uint32_t timeout = 0;
107*b13321fcSBruce M Simpson
108*b13321fcSBruce M Simpson static int do_asm_ipv4(void);
109*b13321fcSBruce M Simpson static int do_asm_pim(void);
110*b13321fcSBruce M Simpson #ifdef notyet
111*b13321fcSBruce M Simpson static int do_misc_opts(void);
112*b13321fcSBruce M Simpson #endif
113*b13321fcSBruce M Simpson static int do_ssf_ipv4(void);
114*b13321fcSBruce M Simpson static int do_ssf_pim(void);
115*b13321fcSBruce M Simpson static int do_ssm_ipv4(void);
116*b13321fcSBruce M Simpson static int do_ssm_pim(void);
117*b13321fcSBruce M Simpson static int open_and_bind_socket(sockunion_t *);
118*b13321fcSBruce M Simpson static int recv_loop_with_match(int, sockunion_t *, sockunion_t *);
119*b13321fcSBruce M Simpson static void signal_handler(int);
120*b13321fcSBruce M Simpson static void usage(void);
121*b13321fcSBruce M Simpson
122*b13321fcSBruce M Simpson /*
123*b13321fcSBruce M Simpson * Test the IPv4 set/getipv4sourcefilter() libc API functions.
124*b13321fcSBruce M Simpson * Build a single socket.
125*b13321fcSBruce M Simpson * Join a source group.
126*b13321fcSBruce M Simpson * Repeatedly change the source filters via setipv4sourcefilter.
127*b13321fcSBruce M Simpson * Read it back with getipv4sourcefilter up to IP_MAX_SOURCES
128*b13321fcSBruce M Simpson * and check for inconsistency.
129*b13321fcSBruce M Simpson */
130*b13321fcSBruce M Simpson static int
do_ssf_ipv4(void)131*b13321fcSBruce M Simpson do_ssf_ipv4(void)
132*b13321fcSBruce M Simpson {
133*b13321fcSBruce M Simpson
134*b13321fcSBruce M Simpson fprintf(stderr, "not yet implemented\n");
135*b13321fcSBruce M Simpson return (0);
136*b13321fcSBruce M Simpson }
137*b13321fcSBruce M Simpson
138*b13321fcSBruce M Simpson /*
139*b13321fcSBruce M Simpson * Test the protocol-independent set/getsourcefilter() functions.
140*b13321fcSBruce M Simpson */
141*b13321fcSBruce M Simpson static int
do_ssf_pim(void)142*b13321fcSBruce M Simpson do_ssf_pim(void)
143*b13321fcSBruce M Simpson {
144*b13321fcSBruce M Simpson
145*b13321fcSBruce M Simpson fprintf(stderr, "not yet implemented\n");
146*b13321fcSBruce M Simpson return (0);
147*b13321fcSBruce M Simpson }
148*b13321fcSBruce M Simpson
149*b13321fcSBruce M Simpson /*
150*b13321fcSBruce M Simpson * Test the IPv4 ASM API.
151*b13321fcSBruce M Simpson * Repeatedly join, block sources, unblock and leave groups.
152*b13321fcSBruce M Simpson */
153*b13321fcSBruce M Simpson static int
do_asm_ipv4(void)154*b13321fcSBruce M Simpson do_asm_ipv4(void)
155*b13321fcSBruce M Simpson {
156*b13321fcSBruce M Simpson int error;
157*b13321fcSBruce M Simpson char gaddrbuf[ADDRBUF_LEN];
158*b13321fcSBruce M Simpson int i;
159*b13321fcSBruce M Simpson sockunion_t laddr;
160*b13321fcSBruce M Simpson struct ip_mreq mreq;
161*b13321fcSBruce M Simpson struct ip_mreq_source mreqs;
162*b13321fcSBruce M Simpson in_addr_t ngroupbase;
163*b13321fcSBruce M Simpson char saddrbuf[ADDRBUF_LEN];
164*b13321fcSBruce M Simpson int sock;
165*b13321fcSBruce M Simpson sockunion_t tmpgroup;
166*b13321fcSBruce M Simpson sockunion_t tmpsource;
167*b13321fcSBruce M Simpson
168*b13321fcSBruce M Simpson memset(&mreq, 0, sizeof(struct ip_mreq));
169*b13321fcSBruce M Simpson memset(&mreqs, 0, sizeof(struct ip_mreq_source));
170*b13321fcSBruce M Simpson memset(&laddr, 0, sizeof(sockunion_t));
171*b13321fcSBruce M Simpson
172*b13321fcSBruce M Simpson if (dobindaddr) {
173*b13321fcSBruce M Simpson laddr = ifaddr;
174*b13321fcSBruce M Simpson } else {
175*b13321fcSBruce M Simpson laddr.sin.sin_family = AF_INET;
176*b13321fcSBruce M Simpson laddr.sin.sin_len = sizeof(struct sockaddr_in);
177*b13321fcSBruce M Simpson laddr.sin.sin_addr.s_addr = INADDR_ANY;
178*b13321fcSBruce M Simpson }
179*b13321fcSBruce M Simpson laddr.sin.sin_port = htons(portno);
180*b13321fcSBruce M Simpson
181*b13321fcSBruce M Simpson tmpgroup = basegroup;
182*b13321fcSBruce M Simpson ngroupbase = ntohl(basegroup.sin.sin_addr.s_addr) + 1; /* XXX */
183*b13321fcSBruce M Simpson tmpgroup.sin.sin_addr.s_addr = htonl(ngroupbase);
184*b13321fcSBruce M Simpson
185*b13321fcSBruce M Simpson sock = open_and_bind_socket(&laddr);
186*b13321fcSBruce M Simpson if (sock == -1)
187*b13321fcSBruce M Simpson return (EX_OSERR);
188*b13321fcSBruce M Simpson
189*b13321fcSBruce M Simpson for (i = 0; i < (signed)nmcastgroups; i++) {
190*b13321fcSBruce M Simpson mreq.imr_multiaddr.s_addr = htonl((ngroupbase + i));
191*b13321fcSBruce M Simpson mreq.imr_interface = ifaddr.sin.sin_addr;
192*b13321fcSBruce M Simpson if (doverbose) {
193*b13321fcSBruce M Simpson inet_ntop(AF_INET, &mreq.imr_multiaddr, gaddrbuf,
194*b13321fcSBruce M Simpson sizeof(gaddrbuf));
195*b13321fcSBruce M Simpson fprintf(stderr, "IP_ADD_MEMBERSHIP %s %s\n",
196*b13321fcSBruce M Simpson gaddrbuf, inet_ntoa(mreq.imr_interface));
197*b13321fcSBruce M Simpson }
198*b13321fcSBruce M Simpson error = setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,
199*b13321fcSBruce M Simpson &mreq, sizeof(struct ip_mreq));
200*b13321fcSBruce M Simpson if (error < 0) {
201*b13321fcSBruce M Simpson warn("setsockopt IP_ADD_MEMBERSHIP");
202*b13321fcSBruce M Simpson close(sock);
203*b13321fcSBruce M Simpson return (EX_OSERR);
204*b13321fcSBruce M Simpson }
205*b13321fcSBruce M Simpson }
206*b13321fcSBruce M Simpson
207*b13321fcSBruce M Simpson /*
208*b13321fcSBruce M Simpson * If no test sources auto-generated or specified on command line,
209*b13321fcSBruce M Simpson * skip source filter portion of ASM test.
210*b13321fcSBruce M Simpson */
211*b13321fcSBruce M Simpson if (nmcastsources == 0)
212*b13321fcSBruce M Simpson goto skipsources;
213*b13321fcSBruce M Simpson
214*b13321fcSBruce M Simpson /*
215*b13321fcSBruce M Simpson * Begin blocking sources on the first group chosen.
216*b13321fcSBruce M Simpson */
217*b13321fcSBruce M Simpson for (i = 0; i < (signed)nmcastsources; i++) {
218*b13321fcSBruce M Simpson mreqs.imr_multiaddr = tmpgroup.sin.sin_addr;
219*b13321fcSBruce M Simpson mreqs.imr_interface = ifaddr.sin.sin_addr;
220*b13321fcSBruce M Simpson mreqs.imr_sourceaddr = ipv4_sources[i];
221*b13321fcSBruce M Simpson if (doverbose) {
222*b13321fcSBruce M Simpson inet_ntop(AF_INET, &mreqs.imr_multiaddr, gaddrbuf,
223*b13321fcSBruce M Simpson sizeof(gaddrbuf));
224*b13321fcSBruce M Simpson inet_ntop(AF_INET, &mreqs.imr_sourceaddr, saddrbuf,
225*b13321fcSBruce M Simpson sizeof(saddrbuf));
226*b13321fcSBruce M Simpson fprintf(stderr, "IP_BLOCK_SOURCE %s %s %s\n",
227*b13321fcSBruce M Simpson gaddrbuf, inet_ntoa(mreqs.imr_interface),
228*b13321fcSBruce M Simpson saddrbuf);
229*b13321fcSBruce M Simpson }
230*b13321fcSBruce M Simpson error = setsockopt(sock, IPPROTO_IP, IP_BLOCK_SOURCE, &mreqs,
231*b13321fcSBruce M Simpson sizeof(struct ip_mreq_source));
232*b13321fcSBruce M Simpson if (error < 0) {
233*b13321fcSBruce M Simpson warn("setsockopt IP_BLOCK_SOURCE");
234*b13321fcSBruce M Simpson close(sock);
235*b13321fcSBruce M Simpson return (EX_OSERR);
236*b13321fcSBruce M Simpson }
237*b13321fcSBruce M Simpson }
238*b13321fcSBruce M Simpson
239*b13321fcSBruce M Simpson /*
240*b13321fcSBruce M Simpson * Choose the first group and source for a match.
241*b13321fcSBruce M Simpson * Enter the I/O loop.
242*b13321fcSBruce M Simpson */
243*b13321fcSBruce M Simpson memset(&tmpsource, 0, sizeof(sockunion_t));
244*b13321fcSBruce M Simpson tmpsource.sin.sin_family = AF_INET;
245*b13321fcSBruce M Simpson tmpsource.sin.sin_len = sizeof(struct sockaddr_in);
246*b13321fcSBruce M Simpson tmpsource.sin.sin_addr = ipv4_sources[0];
247*b13321fcSBruce M Simpson
248*b13321fcSBruce M Simpson error = recv_loop_with_match(sock, &tmpgroup, &tmpsource);
249*b13321fcSBruce M Simpson
250*b13321fcSBruce M Simpson /*
251*b13321fcSBruce M Simpson * Unblock sources.
252*b13321fcSBruce M Simpson */
253*b13321fcSBruce M Simpson for (i = nmcastsources-1; i >= 0; i--) {
254*b13321fcSBruce M Simpson mreqs.imr_multiaddr = tmpgroup.sin.sin_addr;
255*b13321fcSBruce M Simpson mreqs.imr_interface = ifaddr.sin.sin_addr;
256*b13321fcSBruce M Simpson mreqs.imr_sourceaddr = ipv4_sources[i];
257*b13321fcSBruce M Simpson if (doverbose) {
258*b13321fcSBruce M Simpson inet_ntop(AF_INET, &mreqs.imr_multiaddr, gaddrbuf,
259*b13321fcSBruce M Simpson sizeof(gaddrbuf));
260*b13321fcSBruce M Simpson inet_ntop(AF_INET, &mreqs.imr_sourceaddr, saddrbuf,
261*b13321fcSBruce M Simpson sizeof(saddrbuf));
262*b13321fcSBruce M Simpson fprintf(stderr, "IP_UNBLOCK_SOURCE %s %s %s\n",
263*b13321fcSBruce M Simpson gaddrbuf, inet_ntoa(mreqs.imr_interface),
264*b13321fcSBruce M Simpson saddrbuf);
265*b13321fcSBruce M Simpson }
266*b13321fcSBruce M Simpson error = setsockopt(sock, IPPROTO_IP, IP_UNBLOCK_SOURCE, &mreqs,
267*b13321fcSBruce M Simpson sizeof(struct ip_mreq_source));
268*b13321fcSBruce M Simpson if (error < 0) {
269*b13321fcSBruce M Simpson warn("setsockopt IP_UNBLOCK_SOURCE");
270*b13321fcSBruce M Simpson close(sock);
271*b13321fcSBruce M Simpson return (EX_OSERR);
272*b13321fcSBruce M Simpson }
273*b13321fcSBruce M Simpson }
274*b13321fcSBruce M Simpson
275*b13321fcSBruce M Simpson skipsources:
276*b13321fcSBruce M Simpson /*
277*b13321fcSBruce M Simpson * Leave groups.
278*b13321fcSBruce M Simpson */
279*b13321fcSBruce M Simpson for (i = nmcastgroups-1; i >= 0; i--) {
280*b13321fcSBruce M Simpson mreq.imr_multiaddr.s_addr = htonl((ngroupbase + i));
281*b13321fcSBruce M Simpson mreq.imr_interface = ifaddr.sin.sin_addr;
282*b13321fcSBruce M Simpson if (doverbose) {
283*b13321fcSBruce M Simpson inet_ntop(AF_INET, &mreq.imr_multiaddr, gaddrbuf,
284*b13321fcSBruce M Simpson sizeof(gaddrbuf));
285*b13321fcSBruce M Simpson fprintf(stderr, "IP_DROP_MEMBERSHIP %s %s\n",
286*b13321fcSBruce M Simpson gaddrbuf, inet_ntoa(mreq.imr_interface));
287*b13321fcSBruce M Simpson }
288*b13321fcSBruce M Simpson error = setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP,
289*b13321fcSBruce M Simpson &mreq, sizeof(struct ip_mreq));
290*b13321fcSBruce M Simpson if (error < 0) {
291*b13321fcSBruce M Simpson warn("setsockopt IP_DROP_MEMBERSHIP");
292*b13321fcSBruce M Simpson close(sock);
293*b13321fcSBruce M Simpson return (EX_OSERR);
294*b13321fcSBruce M Simpson }
295*b13321fcSBruce M Simpson }
296*b13321fcSBruce M Simpson
297*b13321fcSBruce M Simpson return (0);
298*b13321fcSBruce M Simpson }
299*b13321fcSBruce M Simpson
300*b13321fcSBruce M Simpson static int
do_asm_pim(void)301*b13321fcSBruce M Simpson do_asm_pim(void)
302*b13321fcSBruce M Simpson {
303*b13321fcSBruce M Simpson
304*b13321fcSBruce M Simpson fprintf(stderr, "not yet implemented\n");
305*b13321fcSBruce M Simpson return (0);
306*b13321fcSBruce M Simpson }
307*b13321fcSBruce M Simpson
308*b13321fcSBruce M Simpson #ifdef notyet
309*b13321fcSBruce M Simpson /*
310*b13321fcSBruce M Simpson * Test misceallaneous IPv4 options.
311*b13321fcSBruce M Simpson */
312*b13321fcSBruce M Simpson static int
do_misc_opts(void)313*b13321fcSBruce M Simpson do_misc_opts(void)
314*b13321fcSBruce M Simpson {
315*b13321fcSBruce M Simpson int sock;
316*b13321fcSBruce M Simpson
317*b13321fcSBruce M Simpson sock = open_and_bind_socket(NULL);
318*b13321fcSBruce M Simpson if (sock == -1)
319*b13321fcSBruce M Simpson return (EX_OSERR);
320*b13321fcSBruce M Simpson test_ip_uchar(sock, socktypename, IP_MULTICAST_TTL,
321*b13321fcSBruce M Simpson "IP_MULTICAST_TTL", 1);
322*b13321fcSBruce M Simpson close(sock);
323*b13321fcSBruce M Simpson
324*b13321fcSBruce M Simpson sock = open_and_bind_socket(NULL);
325*b13321fcSBruce M Simpson if (sock == -1)
326*b13321fcSBruce M Simpson return (EX_OSERR);
327*b13321fcSBruce M Simpson test_ip_boolean(sock, socktypename, IP_MULTICAST_LOOP,
328*b13321fcSBruce M Simpson "IP_MULTICAST_LOOP", 1, BOOLEAN_ANYONE);
329*b13321fcSBruce M Simpson close(sock);
330*b13321fcSBruce M Simpson
331*b13321fcSBruce M Simpson return (0);
332*b13321fcSBruce M Simpson }
333*b13321fcSBruce M Simpson #endif
334*b13321fcSBruce M Simpson
335*b13321fcSBruce M Simpson /*
336*b13321fcSBruce M Simpson * Test the IPv4 SSM API.
337*b13321fcSBruce M Simpson */
338*b13321fcSBruce M Simpson static int
do_ssm_ipv4(void)339*b13321fcSBruce M Simpson do_ssm_ipv4(void)
340*b13321fcSBruce M Simpson {
341*b13321fcSBruce M Simpson
342*b13321fcSBruce M Simpson fprintf(stderr, "not yet implemented\n");
343*b13321fcSBruce M Simpson return (0);
344*b13321fcSBruce M Simpson }
345*b13321fcSBruce M Simpson
346*b13321fcSBruce M Simpson /*
347*b13321fcSBruce M Simpson * Test the protocol-independent SSM API with IPv4 addresses.
348*b13321fcSBruce M Simpson */
349*b13321fcSBruce M Simpson static int
do_ssm_pim(void)350*b13321fcSBruce M Simpson do_ssm_pim(void)
351*b13321fcSBruce M Simpson {
352*b13321fcSBruce M Simpson
353*b13321fcSBruce M Simpson fprintf(stderr, "not yet implemented\n");
354*b13321fcSBruce M Simpson return (0);
355*b13321fcSBruce M Simpson }
356*b13321fcSBruce M Simpson
357*b13321fcSBruce M Simpson int
main(int argc,char * argv[])358*b13321fcSBruce M Simpson main(int argc, char *argv[])
359*b13321fcSBruce M Simpson {
360*b13321fcSBruce M Simpson struct addrinfo aih;
361*b13321fcSBruce M Simpson struct addrinfo *aip;
362*b13321fcSBruce M Simpson int ch;
363*b13321fcSBruce M Simpson int error;
364*b13321fcSBruce M Simpson int exitval;
365*b13321fcSBruce M Simpson size_t i;
366*b13321fcSBruce M Simpson struct in_addr *pina;
367*b13321fcSBruce M Simpson struct sockaddr_storage *pbss;
368*b13321fcSBruce M Simpson
369*b13321fcSBruce M Simpson ifname = DEFAULT_IFNAME;
370*b13321fcSBruce M Simpson ifaddr_str = DEFAULT_IFADDR_STR;
371*b13321fcSBruce M Simpson basegroup_str = DEFAULT_GROUP_STR;
372*b13321fcSBruce M Simpson ifname = DEFAULT_IFNAME;
373*b13321fcSBruce M Simpson portno = DEFAULT_PORT;
374*b13321fcSBruce M Simpson basegroup.ss.ss_family = AF_UNSPEC;
375*b13321fcSBruce M Simpson ifaddr.ss.ss_family = AF_UNSPEC;
376*b13321fcSBruce M Simpson
377*b13321fcSBruce M Simpson progname = basename(argv[0]);
378*b13321fcSBruce M Simpson while ((ch = getopt(argc, argv, "4bg:i:I:mM:p:rsS:tT:v")) != -1) {
379*b13321fcSBruce M Simpson switch (ch) {
380*b13321fcSBruce M Simpson case '4':
381*b13321fcSBruce M Simpson doipv4 = 1;
382*b13321fcSBruce M Simpson break;
383*b13321fcSBruce M Simpson case 'b':
384*b13321fcSBruce M Simpson dobindaddr = 1;
385*b13321fcSBruce M Simpson break;
386*b13321fcSBruce M Simpson case 'g':
387*b13321fcSBruce M Simpson basegroup_str = optarg;
388*b13321fcSBruce M Simpson break;
389*b13321fcSBruce M Simpson case 'i':
390*b13321fcSBruce M Simpson ifname = optarg;
391*b13321fcSBruce M Simpson break;
392*b13321fcSBruce M Simpson case 'I':
393*b13321fcSBruce M Simpson ifaddr_str = optarg;
394*b13321fcSBruce M Simpson break;
395*b13321fcSBruce M Simpson case 'm':
396*b13321fcSBruce M Simpson usage(); /* notyet */
397*b13321fcSBruce M Simpson /*NOTREACHED*/
398*b13321fcSBruce M Simpson domiscopts = 1;
399*b13321fcSBruce M Simpson break;
400*b13321fcSBruce M Simpson case 'M':
401*b13321fcSBruce M Simpson nmcastgroups = atoi(optarg);
402*b13321fcSBruce M Simpson break;
403*b13321fcSBruce M Simpson case 'p':
404*b13321fcSBruce M Simpson portno = atoi(optarg);
405*b13321fcSBruce M Simpson break;
406*b13321fcSBruce M Simpson case 'r':
407*b13321fcSBruce M Simpson doreuseport = 1;
408*b13321fcSBruce M Simpson break;
409*b13321fcSBruce M Simpson case 'S':
410*b13321fcSBruce M Simpson nmcastsources = atoi(optarg);
411*b13321fcSBruce M Simpson break;
412*b13321fcSBruce M Simpson case 's':
413*b13321fcSBruce M Simpson dossm = 1;
414*b13321fcSBruce M Simpson break;
415*b13321fcSBruce M Simpson case 't':
416*b13321fcSBruce M Simpson dossf = 1;
417*b13321fcSBruce M Simpson break;
418*b13321fcSBruce M Simpson case 'T':
419*b13321fcSBruce M Simpson timeout = atoi(optarg);
420*b13321fcSBruce M Simpson break;
421*b13321fcSBruce M Simpson case 'v':
422*b13321fcSBruce M Simpson doverbose = 1;
423*b13321fcSBruce M Simpson break;
424*b13321fcSBruce M Simpson default:
425*b13321fcSBruce M Simpson usage();
426*b13321fcSBruce M Simpson break;
427*b13321fcSBruce M Simpson /*NOTREACHED*/
428*b13321fcSBruce M Simpson }
429*b13321fcSBruce M Simpson }
430*b13321fcSBruce M Simpson argc -= optind;
431*b13321fcSBruce M Simpson argv += optind;
432*b13321fcSBruce M Simpson
433*b13321fcSBruce M Simpson memset(&aih, 0, sizeof(struct addrinfo));
434*b13321fcSBruce M Simpson aih.ai_flags = AI_NUMERICHOST | AI_PASSIVE;
435*b13321fcSBruce M Simpson aih.ai_family = PF_INET;
436*b13321fcSBruce M Simpson aih.ai_socktype = SOCK_DGRAM;
437*b13321fcSBruce M Simpson aih.ai_protocol = IPPROTO_UDP;
438*b13321fcSBruce M Simpson
439*b13321fcSBruce M Simpson /*
440*b13321fcSBruce M Simpson * Fill out base group.
441*b13321fcSBruce M Simpson */
442*b13321fcSBruce M Simpson aip = NULL;
443*b13321fcSBruce M Simpson error = getaddrinfo(basegroup_str, NULL, &aih, &aip);
444*b13321fcSBruce M Simpson if (error != 0) {
445*b13321fcSBruce M Simpson fprintf(stderr, "%s: getaddrinfo: %s\n", progname,
446*b13321fcSBruce M Simpson gai_strerror(error));
447*b13321fcSBruce M Simpson exit(EX_USAGE);
448*b13321fcSBruce M Simpson }
449*b13321fcSBruce M Simpson memcpy(&basegroup, aip->ai_addr, aip->ai_addrlen);
450*b13321fcSBruce M Simpson if (dodebug) {
451*b13321fcSBruce M Simpson fprintf(stderr, "debug: gai thinks %s is %s\n",
452*b13321fcSBruce M Simpson basegroup_str, inet_ntoa(basegroup.sin.sin_addr));
453*b13321fcSBruce M Simpson }
454*b13321fcSBruce M Simpson freeaddrinfo(aip);
455*b13321fcSBruce M Simpson
456*b13321fcSBruce M Simpson assert(basegroup.ss.ss_family == AF_INET);
457*b13321fcSBruce M Simpson
458*b13321fcSBruce M Simpson /*
459*b13321fcSBruce M Simpson * If user specified interface as an address, and protocol
460*b13321fcSBruce M Simpson * specific APIs were selected, parse it.
461*b13321fcSBruce M Simpson * Otherwise, parse interface index from name if protocol
462*b13321fcSBruce M Simpson * independent APIs were selected (the default).
463*b13321fcSBruce M Simpson */
464*b13321fcSBruce M Simpson if (doipv4) {
465*b13321fcSBruce M Simpson if (ifaddr_str == NULL) {
466*b13321fcSBruce M Simpson warnx("required argument missing: ifaddr");
467*b13321fcSBruce M Simpson usage();
468*b13321fcSBruce M Simpson /* NOTREACHED */
469*b13321fcSBruce M Simpson }
470*b13321fcSBruce M Simpson aip = NULL;
471*b13321fcSBruce M Simpson error = getaddrinfo(ifaddr_str, NULL, &aih, &aip);
472*b13321fcSBruce M Simpson if (error != 0) {
473*b13321fcSBruce M Simpson fprintf(stderr, "%s: getaddrinfo: %s\n", progname,
474*b13321fcSBruce M Simpson gai_strerror(error));
475*b13321fcSBruce M Simpson exit(EX_USAGE);
476*b13321fcSBruce M Simpson }
477*b13321fcSBruce M Simpson memcpy(&ifaddr, aip->ai_addr, aip->ai_addrlen);
478*b13321fcSBruce M Simpson if (dodebug) {
479*b13321fcSBruce M Simpson fprintf(stderr, "debug: gai thinks %s is %s\n",
480*b13321fcSBruce M Simpson ifaddr_str, inet_ntoa(ifaddr.sin.sin_addr));
481*b13321fcSBruce M Simpson }
482*b13321fcSBruce M Simpson freeaddrinfo(aip);
483*b13321fcSBruce M Simpson }
484*b13321fcSBruce M Simpson
485*b13321fcSBruce M Simpson if (!doipv4) {
486*b13321fcSBruce M Simpson if (ifname == NULL) {
487*b13321fcSBruce M Simpson warnx("required argument missing: ifname");
488*b13321fcSBruce M Simpson usage();
489*b13321fcSBruce M Simpson /* NOTREACHED */
490*b13321fcSBruce M Simpson }
491*b13321fcSBruce M Simpson ifindex = if_nametoindex(ifname);
492*b13321fcSBruce M Simpson if (ifindex == 0)
493*b13321fcSBruce M Simpson err(EX_USAGE, "if_nametoindex");
494*b13321fcSBruce M Simpson }
495*b13321fcSBruce M Simpson
496*b13321fcSBruce M Simpson /*
497*b13321fcSBruce M Simpson * Introduce randomness into group base if specified.
498*b13321fcSBruce M Simpson */
499*b13321fcSBruce M Simpson if (dorandom) {
500*b13321fcSBruce M Simpson in_addr_t ngroupbase;
501*b13321fcSBruce M Simpson
502*b13321fcSBruce M Simpson srandomdev();
503*b13321fcSBruce M Simpson ngroupbase = ntohl(basegroup.sin.sin_addr.s_addr);
504*b13321fcSBruce M Simpson ngroupbase |= ((random() % ((1 << 11) - 1)) << 16);
505*b13321fcSBruce M Simpson basegroup.sin.sin_addr.s_addr = htonl(ngroupbase);
506*b13321fcSBruce M Simpson }
507*b13321fcSBruce M Simpson
508*b13321fcSBruce M Simpson if (argc > 0) {
509*b13321fcSBruce M Simpson nmcastsources = argc;
510*b13321fcSBruce M Simpson if (doipv4) {
511*b13321fcSBruce M Simpson ipv4_sources = calloc(nmcastsources,
512*b13321fcSBruce M Simpson sizeof(struct in_addr));
513*b13321fcSBruce M Simpson if (ipv4_sources == NULL) {
514*b13321fcSBruce M Simpson exitval = EX_OSERR;
515*b13321fcSBruce M Simpson goto out;
516*b13321fcSBruce M Simpson }
517*b13321fcSBruce M Simpson } else {
518*b13321fcSBruce M Simpson ss_sources = calloc(nmcastsources,
519*b13321fcSBruce M Simpson sizeof(struct sockaddr_storage));
520*b13321fcSBruce M Simpson if (ss_sources == NULL) {
521*b13321fcSBruce M Simpson exitval = EX_OSERR;
522*b13321fcSBruce M Simpson goto out;
523*b13321fcSBruce M Simpson }
524*b13321fcSBruce M Simpson }
525*b13321fcSBruce M Simpson }
526*b13321fcSBruce M Simpson
527*b13321fcSBruce M Simpson /*
528*b13321fcSBruce M Simpson * Parse source list, if any were specified on the command line.
529*b13321fcSBruce M Simpson */
530*b13321fcSBruce M Simpson assert(aih.ai_family == PF_INET);
531*b13321fcSBruce M Simpson pbss = ss_sources;
532*b13321fcSBruce M Simpson pina = ipv4_sources;
533*b13321fcSBruce M Simpson for (i = 0; i < (size_t)argc; i++) {
534*b13321fcSBruce M Simpson aip = NULL;
535*b13321fcSBruce M Simpson error = getaddrinfo(argv[i], NULL, &aih, &aip);
536*b13321fcSBruce M Simpson if (error != 0) {
537*b13321fcSBruce M Simpson fprintf(stderr, "getaddrinfo: %s\n",
538*b13321fcSBruce M Simpson gai_strerror(error));
539*b13321fcSBruce M Simpson exitval = EX_USAGE;
540*b13321fcSBruce M Simpson goto out;
541*b13321fcSBruce M Simpson }
542*b13321fcSBruce M Simpson if (doipv4) {
543*b13321fcSBruce M Simpson struct sockaddr_in *sin =
544*b13321fcSBruce M Simpson (struct sockaddr_in *)aip->ai_addr;
545*b13321fcSBruce M Simpson *pina++ = sin->sin_addr;
546*b13321fcSBruce M Simpson } else {
547*b13321fcSBruce M Simpson memcpy(pbss++, aip->ai_addr, aip->ai_addrlen);
548*b13321fcSBruce M Simpson }
549*b13321fcSBruce M Simpson freeaddrinfo(aip);
550*b13321fcSBruce M Simpson }
551*b13321fcSBruce M Simpson
552*b13321fcSBruce M Simpson /*
553*b13321fcSBruce M Simpson * Perform the regression tests which the user requested.
554*b13321fcSBruce M Simpson */
555*b13321fcSBruce M Simpson #ifdef notyet
556*b13321fcSBruce M Simpson if (domiscopts) {
557*b13321fcSBruce M Simpson exitval = do_misc_opts();
558*b13321fcSBruce M Simpson if (exitval)
559*b13321fcSBruce M Simpson goto out;
560*b13321fcSBruce M Simpson }
561*b13321fcSBruce M Simpson #endif
562*b13321fcSBruce M Simpson if (doipv4) {
563*b13321fcSBruce M Simpson /* IPv4 protocol specific API tests */
564*b13321fcSBruce M Simpson if (dossm) {
565*b13321fcSBruce M Simpson /* Source-specific multicast */
566*b13321fcSBruce M Simpson exitval = do_ssm_ipv4();
567*b13321fcSBruce M Simpson if (exitval)
568*b13321fcSBruce M Simpson goto out;
569*b13321fcSBruce M Simpson if (dossf) {
570*b13321fcSBruce M Simpson /* Do setipvsourcefilter() too */
571*b13321fcSBruce M Simpson exitval = do_ssf_ipv4();
572*b13321fcSBruce M Simpson }
573*b13321fcSBruce M Simpson } else {
574*b13321fcSBruce M Simpson /* Any-source multicast */
575*b13321fcSBruce M Simpson exitval = do_asm_ipv4();
576*b13321fcSBruce M Simpson }
577*b13321fcSBruce M Simpson } else {
578*b13321fcSBruce M Simpson /* Protocol independent API tests */
579*b13321fcSBruce M Simpson if (dossm) {
580*b13321fcSBruce M Simpson /* Source-specific multicast */
581*b13321fcSBruce M Simpson exitval = do_ssm_pim();
582*b13321fcSBruce M Simpson if (exitval)
583*b13321fcSBruce M Simpson goto out;
584*b13321fcSBruce M Simpson if (dossf) {
585*b13321fcSBruce M Simpson /* Do setsourcefilter() too */
586*b13321fcSBruce M Simpson exitval = do_ssf_pim();
587*b13321fcSBruce M Simpson }
588*b13321fcSBruce M Simpson } else {
589*b13321fcSBruce M Simpson /* Any-source multicast */
590*b13321fcSBruce M Simpson exitval = do_asm_pim();
591*b13321fcSBruce M Simpson }
592*b13321fcSBruce M Simpson }
593*b13321fcSBruce M Simpson
594*b13321fcSBruce M Simpson out:
595*b13321fcSBruce M Simpson if (ipv4_sources != NULL)
596*b13321fcSBruce M Simpson free(ipv4_sources);
597*b13321fcSBruce M Simpson
598*b13321fcSBruce M Simpson if (ss_sources != NULL)
599*b13321fcSBruce M Simpson free(ss_sources);
600*b13321fcSBruce M Simpson
601*b13321fcSBruce M Simpson exit(exitval);
602*b13321fcSBruce M Simpson }
603*b13321fcSBruce M Simpson
604*b13321fcSBruce M Simpson static int
open_and_bind_socket(sockunion_t * bsu)605*b13321fcSBruce M Simpson open_and_bind_socket(sockunion_t *bsu)
606*b13321fcSBruce M Simpson {
607*b13321fcSBruce M Simpson int error, optval, sock;
608*b13321fcSBruce M Simpson
609*b13321fcSBruce M Simpson sock = -1;
610*b13321fcSBruce M Simpson
611*b13321fcSBruce M Simpson sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
612*b13321fcSBruce M Simpson if (sock == -1) {
613*b13321fcSBruce M Simpson warn("socket");
614*b13321fcSBruce M Simpson return (-1);
615*b13321fcSBruce M Simpson }
616*b13321fcSBruce M Simpson
617*b13321fcSBruce M Simpson if (doreuseport) {
618*b13321fcSBruce M Simpson optval = 1;
619*b13321fcSBruce M Simpson if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &optval,
620*b13321fcSBruce M Simpson sizeof(optval)) < 0) {
621*b13321fcSBruce M Simpson warn("setsockopt SO_REUSEPORT");
622*b13321fcSBruce M Simpson close(sock);
623*b13321fcSBruce M Simpson return (-1);
624*b13321fcSBruce M Simpson }
625*b13321fcSBruce M Simpson }
626*b13321fcSBruce M Simpson
627*b13321fcSBruce M Simpson if (bsu != NULL) {
628*b13321fcSBruce M Simpson error = bind(sock, &bsu->sa, bsu->sa.sa_len);
629*b13321fcSBruce M Simpson if (error == -1) {
630*b13321fcSBruce M Simpson warn("bind");
631*b13321fcSBruce M Simpson close(sock);
632*b13321fcSBruce M Simpson return (-1);
633*b13321fcSBruce M Simpson }
634*b13321fcSBruce M Simpson }
635*b13321fcSBruce M Simpson
636*b13321fcSBruce M Simpson return (sock);
637*b13321fcSBruce M Simpson }
638*b13321fcSBruce M Simpson
639*b13321fcSBruce M Simpson /*
640*b13321fcSBruce M Simpson * Protocol-agnostic multicast I/O loop.
641*b13321fcSBruce M Simpson *
642*b13321fcSBruce M Simpson * Wait for 'timeout' seconds looking for traffic on group, so that manual
643*b13321fcSBruce M Simpson * or automated regression tests (possibly running on another host) have an
644*b13321fcSBruce M Simpson * opportunity to transmit within the group to test source filters.
645*b13321fcSBruce M Simpson *
646*b13321fcSBruce M Simpson * If the filter failed, this loop will report if we received traffic
647*b13321fcSBruce M Simpson * from the source we elected to monitor.
648*b13321fcSBruce M Simpson */
649*b13321fcSBruce M Simpson static int
recv_loop_with_match(int sock,sockunion_t * group,sockunion_t * source)650*b13321fcSBruce M Simpson recv_loop_with_match(int sock, sockunion_t *group, sockunion_t *source)
651*b13321fcSBruce M Simpson {
652*b13321fcSBruce M Simpson int error;
653*b13321fcSBruce M Simpson sockunion_t from;
654*b13321fcSBruce M Simpson char groupname[NI_MAXHOST];
655*b13321fcSBruce M Simpson ssize_t len;
656*b13321fcSBruce M Simpson size_t npackets;
657*b13321fcSBruce M Simpson int jmpretval;
658*b13321fcSBruce M Simpson char rxbuf[RXBUFSIZE];
659*b13321fcSBruce M Simpson char sourcename[NI_MAXHOST];
660*b13321fcSBruce M Simpson
661*b13321fcSBruce M Simpson assert(source->sa.sa_family == AF_INET);
662*b13321fcSBruce M Simpson
663*b13321fcSBruce M Simpson /*
664*b13321fcSBruce M Simpson * Return immediately if we don't need to wait for traffic.
665*b13321fcSBruce M Simpson */
666*b13321fcSBruce M Simpson if (timeout == 0)
667*b13321fcSBruce M Simpson return (0);
668*b13321fcSBruce M Simpson
669*b13321fcSBruce M Simpson error = getnameinfo(&group->sa, group->sa.sa_len, groupname,
670*b13321fcSBruce M Simpson NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
671*b13321fcSBruce M Simpson if (error) {
672*b13321fcSBruce M Simpson fprintf(stderr, "getnameinfo: %s\n", gai_strerror(error));
673*b13321fcSBruce M Simpson return (error);
674*b13321fcSBruce M Simpson }
675*b13321fcSBruce M Simpson
676*b13321fcSBruce M Simpson error = getnameinfo(&source->sa, source->sa.sa_len, sourcename,
677*b13321fcSBruce M Simpson NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
678*b13321fcSBruce M Simpson if (error) {
679*b13321fcSBruce M Simpson fprintf(stderr, "getnameinfo: %s\n", gai_strerror(error));
680*b13321fcSBruce M Simpson return (error);
681*b13321fcSBruce M Simpson }
682*b13321fcSBruce M Simpson
683*b13321fcSBruce M Simpson fprintf(stdout,
684*b13321fcSBruce M Simpson "Waiting %d seconds for inbound traffic on group %s\n"
685*b13321fcSBruce M Simpson "Expecting no traffic from blocked source: %s\n",
686*b13321fcSBruce M Simpson (int)timeout, groupname, sourcename);
687*b13321fcSBruce M Simpson
688*b13321fcSBruce M Simpson signal(SIGINT, signal_handler);
689*b13321fcSBruce M Simpson signal(SIGALRM, signal_handler);
690*b13321fcSBruce M Simpson
691*b13321fcSBruce M Simpson error = 0;
692*b13321fcSBruce M Simpson npackets = 0;
693*b13321fcSBruce M Simpson alarm(timeout);
694*b13321fcSBruce M Simpson while (0 == (jmpretval = setjmp(jmpbuf))) {
695*b13321fcSBruce M Simpson len = recvfrom(sock, rxbuf, RXBUFSIZE, 0, &from.sa,
696*b13321fcSBruce M Simpson (socklen_t *)&from.sa.sa_len);
697*b13321fcSBruce M Simpson if (dodebug) {
698*b13321fcSBruce M Simpson fprintf(stderr, "debug: packet received from %s\n",
699*b13321fcSBruce M Simpson inet_ntoa(from.sin.sin_addr));
700*b13321fcSBruce M Simpson }
701*b13321fcSBruce M Simpson if (source &&
702*b13321fcSBruce M Simpson source->sin.sin_addr.s_addr == from.sin.sin_addr.s_addr)
703*b13321fcSBruce M Simpson break;
704*b13321fcSBruce M Simpson npackets++;
705*b13321fcSBruce M Simpson }
706*b13321fcSBruce M Simpson
707*b13321fcSBruce M Simpson if (doverbose) {
708*b13321fcSBruce M Simpson fprintf(stderr, "Number of datagrams received from "
709*b13321fcSBruce M Simpson "non-blocked sources: %d\n", (int)npackets);
710*b13321fcSBruce M Simpson }
711*b13321fcSBruce M Simpson
712*b13321fcSBruce M Simpson switch (jmpretval) {
713*b13321fcSBruce M Simpson case SIGALRM: /* ok */
714*b13321fcSBruce M Simpson break;
715*b13321fcSBruce M Simpson case SIGINT: /* go bye bye */
716*b13321fcSBruce M Simpson fprintf(stderr, "interrupted\n");
717*b13321fcSBruce M Simpson error = 20;
718*b13321fcSBruce M Simpson break;
719*b13321fcSBruce M Simpson case 0: /* Broke out of loop; saw a bad source. */
720*b13321fcSBruce M Simpson fprintf(stderr, "FAIL: got packet from blocked source\n");
721*b13321fcSBruce M Simpson error = EX_IOERR;
722*b13321fcSBruce M Simpson break;
723*b13321fcSBruce M Simpson default:
724*b13321fcSBruce M Simpson warnx("recvfrom");
725*b13321fcSBruce M Simpson error = EX_OSERR;
726*b13321fcSBruce M Simpson break;
727*b13321fcSBruce M Simpson }
728*b13321fcSBruce M Simpson
729*b13321fcSBruce M Simpson signal(SIGINT, SIG_DFL);
730*b13321fcSBruce M Simpson signal(SIGALRM, SIG_DFL);
731*b13321fcSBruce M Simpson
732*b13321fcSBruce M Simpson return (error);
733*b13321fcSBruce M Simpson }
734*b13321fcSBruce M Simpson
735*b13321fcSBruce M Simpson static void
signal_handler(int signo)736*b13321fcSBruce M Simpson signal_handler(int signo)
737*b13321fcSBruce M Simpson {
738*b13321fcSBruce M Simpson
739*b13321fcSBruce M Simpson longjmp(jmpbuf, signo);
740*b13321fcSBruce M Simpson }
741*b13321fcSBruce M Simpson
742*b13321fcSBruce M Simpson static void
usage(void)743*b13321fcSBruce M Simpson usage(void)
744*b13321fcSBruce M Simpson {
745*b13321fcSBruce M Simpson
746*b13321fcSBruce M Simpson fprintf(stderr, "\nIP multicast regression test utility\n");
747*b13321fcSBruce M Simpson fprintf(stderr,
748*b13321fcSBruce M Simpson "usage: %s [-4] [-b] [-g groupaddr] [-i ifname] [-I ifaddr] [-m]\n"
749*b13321fcSBruce M Simpson " [-M ngroups] [-p portno] [-r] [-R] [-s] [-S nsources] [-t] [-T timeout]\n"
750*b13321fcSBruce M Simpson " [-v] [blockaddr ...]\n\n", progname);
751*b13321fcSBruce M Simpson fprintf(stderr, "-4: Use IPv4 API "
752*b13321fcSBruce M Simpson "(default: Use protocol-independent API)\n");
753*b13321fcSBruce M Simpson fprintf(stderr, "-b: bind listening socket to ifaddr "
754*b13321fcSBruce M Simpson "(default: INADDR_ANY)\n");
755*b13321fcSBruce M Simpson fprintf(stderr, "-g: Base IPv4 multicast group to join (default: %s)\n",
756*b13321fcSBruce M Simpson DEFAULT_GROUP_STR);
757*b13321fcSBruce M Simpson fprintf(stderr, "-i: interface for multicast joins (default: %s)\n",
758*b13321fcSBruce M Simpson DEFAULT_IFNAME);
759*b13321fcSBruce M Simpson fprintf(stderr, "-I: IPv4 address to join groups on, if using IPv4 "
760*b13321fcSBruce M Simpson "API\n (default: %s)\n", DEFAULT_IFADDR_STR);
761*b13321fcSBruce M Simpson #ifdef notyet
762*b13321fcSBruce M Simpson fprintf(stderr, "-m: Test misc IPv4 multicast socket options "
763*b13321fcSBruce M Simpson "(default: off)\n");
764*b13321fcSBruce M Simpson #endif
765*b13321fcSBruce M Simpson fprintf(stderr, "-M: Number of multicast groups to join "
766*b13321fcSBruce M Simpson "(default: %d)\n", (int)nmcastgroups);
767*b13321fcSBruce M Simpson fprintf(stderr, "-p: Set local and remote port (default: %d)\n",
768*b13321fcSBruce M Simpson DEFAULT_PORT);
769*b13321fcSBruce M Simpson fprintf(stderr, "-r: Set SO_REUSEPORT on (default: off)\n");
770*b13321fcSBruce M Simpson fprintf(stderr, "-R: Randomize groups/sources (default: off)\n");
771*b13321fcSBruce M Simpson fprintf(stderr, "-s: Test source-specific API "
772*b13321fcSBruce M Simpson "(default: test any-source API)\n");
773*b13321fcSBruce M Simpson fprintf(stderr, "-S: Number of multicast sources to generate if\n"
774*b13321fcSBruce M Simpson " none specified on command line (default: %d)\n",
775*b13321fcSBruce M Simpson (int)nmcastsources);
776*b13321fcSBruce M Simpson fprintf(stderr, "-t: Test get/setNsourcefilter() (default: off)\n");
777*b13321fcSBruce M Simpson fprintf(stderr, "-T: Timeout to wait for blocked traffic on first "
778*b13321fcSBruce M Simpson "group (default: %d)\n", DEFAULT_TIMEOUT);
779*b13321fcSBruce M Simpson fprintf(stderr, "-v: Be verbose (default: off)\n");
780*b13321fcSBruce M Simpson fprintf(stderr, "\nRemaining arguments are treated as a list of IPv4 "
781*b13321fcSBruce M Simpson "sources to filter.\n\n");
782*b13321fcSBruce M Simpson
783*b13321fcSBruce M Simpson exit(EX_USAGE);
784*b13321fcSBruce M Simpson }
785