iptests.c revision 26119
1193323Sed/*
2193323Sed * (C)opyright 1993, 1994, 1995 by Darren Reed.
3193323Sed *
4193323Sed * This code may be freely distributed as long as it retains this notice
5193323Sed * and is not changed in any way.  The author accepts no responsibility
6193323Sed * for the use of this software.  I hate legaleese, don't you ?
7193323Sed */
8193323Sed#if !defined(lint) && defined(LIBC_SCCS)
9193323Sedstatic	char	sccsid[] = "%W% %G% (C)1995 Darren Reed";
10193323Sed#endif
11193323Sed#include <stdio.h>
12193323Sed#include <unistd.h>
13193323Sed#include <stdlib.h>
14234353Sdim#include <string.h>
15193323Sed#include <sys/types.h>
16239462Sdim#include <sys/time.h>
17198090Srdivacky#include <sys/param.h>
18234353Sdim#if !defined(solaris)
19205218Srdivacky# define _KERNEL
20205218Srdivacky# define KERNEL
21234353Sdim# include <sys/file.h>
22218893Sdim# undef  _KERNEL
23234353Sdim# undef  KERNEL
24234353Sdim# include <nlist.h>
25193323Sed# include <sys/user.h>
26234353Sdim# include <sys/proc.h>
27234353Sdim#endif
28198090Srdivacky#include <kvm.h>
29234353Sdim#include <sys/socket.h>
30224145Sdim#if defined(solaris)
31203954Srdivacky# include <sys/stream.h>
32224145Sdim#endif
33203954Srdivacky#include <sys/socketvar.h>
34193323Sed#ifdef sun
35198090Srdivacky#include <sys/systm.h>
36234353Sdim#include <sys/session.h>
37226633Sdim#endif
38193323Sed#if BSD >= 199103
39193323Sed#include <sys/sysctl.h>
40234353Sdim#include <sys/filedesc.h>
41234353Sdim#include <paths.h>
42234353Sdim#endif
43234353Sdim#include <netinet/in_systm.h>
44234353Sdim#include <sys/socket.h>
45234353Sdim#include <net/if.h>
46193323Sed#include <net/route.h>
47208599Srdivacky#include <netinet/in.h>
48208599Srdivacky#include <arpa/inet.h>
49208599Srdivacky#include <netinet/ip.h>
50208599Srdivacky#include <netinet/tcp.h>
51193323Sed#include <netinet/udp.h>
52203954Srdivacky#include <netinet/ip_icmp.h>
53203954Srdivacky#include <netinet/if_ether.h>
54203954Srdivacky#include <netinet/ip_var.h>
55202375Srdivacky#include <netinet/in_pcb.h>
56203954Srdivacky#include <netinet/tcp_timer.h>
57203954Srdivacky#include <netinet/tcp_var.h>
58203954Srdivacky# if defined(__SVR4) || defined(__svr4__)
59203954Srdivacky#include <sys/sysmacros.h>
60203954Srdivacky# endif
61212904Sdim#include "ipsend.h"
62234353Sdim
63203954Srdivacky
64203954Srdivacky#define	PAUSE()	tv.tv_sec = 0; tv.tv_usec = 10000; \
65224145Sdim		  (void) select(0, NULL, NULL, NULL, &tv)
66226633Sdim
67234353Sdim
68234353Sdimvoid	ip_test1(dev, mtu, ip, gwip, ptest)
69234353Sdimchar	*dev;
70234353Sdimint	mtu;
71234353Sdimip_t	*ip;
72224145Sdimstruct	in_addr	gwip;
73226633Sdimint	ptest;
74226633Sdim{
75226633Sdim	struct	timeval	tv;
76226633Sdim	udphdr_t *u;
77226633Sdim	int	nfd, i, len, id = getpid();
78228379Sdim
79228379Sdim	ip->ip_hl = sizeof(*ip) >> 2;
80198090Srdivacky	ip->ip_v = IPVERSION;
81198090Srdivacky	ip->ip_tos = 0;
82234353Sdim	ip->ip_off = 0;
83234353Sdim	ip->ip_ttl = 60;
84234353Sdim	ip->ip_p = IPPROTO_UDP;
85239462Sdim	ip->ip_sum = 0;
86239462Sdim	u = (udphdr_t *)(ip + 1);
87239462Sdim	u->uh_sport = 1;
88234353Sdim	u->uh_dport = 9;
89234353Sdim	u->uh_sum = 0;
90239462Sdim	u->uh_ulen = sizeof(*u) + 4;
91234353Sdim	ip->ip_len = sizeof(*ip) + u->uh_ulen;
92234353Sdim	len = ip->ip_len;
93234353Sdim	nfd = initdevice(dev, u->uh_sport, 1);
94234353Sdim
95234353Sdim	u->uh_sport = htons(u->uh_sport);
96234353Sdim	u->uh_dport = htons(u->uh_dport);
97234353Sdim	u->uh_ulen = htons(u->uh_ulen);
98234353Sdim	if (!ptest || (ptest == 1)) {
99239462Sdim		/*
100234353Sdim		 * Part1: hl < len
101234353Sdim		 */
102234353Sdim		ip->ip_id = 0;
103234353Sdim		printf("1.1. sending packets with ip_hl < ip_len\n");
104234353Sdim		for (i = 0; i < ((sizeof(*ip) + u->uh_ulen) >> 2); i++) {
105234353Sdim			ip->ip_hl = i >> 2;
106234353Sdim			(void) send_ip(nfd, 1500, ip, gwip, 1);
107234353Sdim			printf("%d\r", i);
108234353Sdim			fflush(stdout);
109234353Sdim			PAUSE();
110234353Sdim		}
111234353Sdim		putchar('\n');
112234353Sdim	}
113234353Sdim
114234353Sdim	if (!ptest || (ptest == 2)) {
115234353Sdim		/*
116234353Sdim		 * Part2: hl > len
117234353Sdim		 */
118234353Sdim		ip->ip_id = 0;
119234353Sdim		printf("1.2. sending packets with ip_hl > ip_len\n");
120234353Sdim		for (; i < ((sizeof(*ip) * 2 + u->uh_ulen) >> 2); i++) {
121234353Sdim			ip->ip_hl = i >> 2;
122234353Sdim			(void) send_ip(nfd, 1500, ip, gwip, 1);
123234353Sdim			printf("%d\r", i);
124234353Sdim			fflush(stdout);
125234353Sdim			PAUSE();
126234353Sdim		}
127234353Sdim		putchar('\n');
128234353Sdim	}
129234353Sdim
130234353Sdim	if (!ptest || (ptest == 3)) {
131203954Srdivacky		/*
132203954Srdivacky		 * Part3: v < 4
133203954Srdivacky		 */
134239462Sdim		ip->ip_id = 0;
135239462Sdim		printf("1.3. ip_v < 4\n");
136239462Sdim		ip->ip_hl = sizeof(*ip) >> 2;
137193323Sed		for (i = 0; i < 4; i++) {
138239462Sdim			ip->ip_v = i;
139239462Sdim			(void) send_ip(nfd, 1500, ip, gwip, 1);
140234353Sdim			printf("%d\r", i);
141203954Srdivacky			fflush(stdout);
142193323Sed			PAUSE();
143239462Sdim		}
144239462Sdim		putchar('\n');
145239462Sdim	}
146239462Sdim
147239462Sdim	if (!ptest || (ptest == 4)) {
148239462Sdim		/*
149239462Sdim		 * Part4: v > 4
150239462Sdim		 */
151239462Sdim		ip->ip_id = 0;
152239462Sdim		printf("1.4. ip_v > 4\n");
153221345Sdim		for (i = 5; i < 16; i++) {
154221345Sdim			ip->ip_v = i;
155221345Sdim			(void) send_ip(nfd, 1500, ip, gwip, 1);
156205218Srdivacky			printf("%d\r", i);
157239462Sdim			fflush(stdout);
158226633Sdim			PAUSE();
159203954Srdivacky		}
160203954Srdivacky		putchar('\n');
161193323Sed	}
162203954Srdivacky
163203954Srdivacky	if (!ptest || (ptest == 5)) {
164234353Sdim		/*
165234353Sdim		 * Part5: len < packet
166234353Sdim		 */
167208599Srdivacky		ip->ip_id = 0;
168208599Srdivacky		ip->ip_v = IPVERSION;
169208599Srdivacky		i = ip->ip_len + 1;
170226633Sdim		ip->ip_len = htons(ip->ip_len);
171218893Sdim		ip->ip_off = htons(ip->ip_off);
172224145Sdim		printf("1.5.0 ip_len < packet size (size++, long packets)\n");
173239462Sdim		for (; i < (ntohs(ip->ip_len) * 2); i++) {
174239462Sdim			ip->ip_id = htons(id++);
175241430Sdim			ip->ip_sum = 0;
176218893Sdim			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
177208599Srdivacky			(void) send_ether(nfd, (char *)ip, i, gwip);
178218893Sdim			printf("%d\r", i);
179218893Sdim			fflush(stdout);
180218893Sdim			PAUSE();
181221345Sdim		}
182234353Sdim		putchar('\n');
183218893Sdim		printf("1.5.1 ip_len < packet size (ip_len-, short packets)\n");
184226633Sdim		for (i = len; i > 0; i--) {
185218893Sdim			ip->ip_id = htons(id++);
186218893Sdim			ip->ip_len = htons(i);
187193323Sed			ip->ip_sum = 0;
188193323Sed			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
189203954Srdivacky			(void) send_ether(nfd, (char *)ip, len, gwip);
190203954Srdivacky			printf("%d\r", i);
191203954Srdivacky			fflush(stdout);
192239462Sdim			PAUSE();
193239462Sdim		}
194241430Sdim		putchar('\n');
195226633Sdim	}
196203954Srdivacky
197208599Srdivacky	if (!ptest || (ptest == 6)) {
198226633Sdim		/*
199226633Sdim		 * Part6: len > packet
200226633Sdim		 */
201226633Sdim		ip->ip_id = 0;
202218893Sdim		printf("1.6.0 ip_len > packet size (increase ip_len)\n");
203203954Srdivacky		for (i = len + 1; i < (len * 2); i++) {
204203954Srdivacky			ip->ip_id = htons(id++);
205203954Srdivacky			ip->ip_len = htons(i);
206203954Srdivacky			ip->ip_sum = 0;
207203954Srdivacky			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
208203954Srdivacky			(void) send_ether(nfd, (char *)ip, len, gwip);
209203954Srdivacky			printf("%d\r", i);
210203954Srdivacky			fflush(stdout);
211208599Srdivacky			PAUSE();
212205218Srdivacky		}
213206274Srdivacky		putchar('\n');
214203954Srdivacky		ip->ip_len = htons(len);
215198090Srdivacky		printf("1.6.1 ip_len > packet size (size--, short packets)\n");
216212904Sdim		for (i = len; i > 0; i--) {
217205218Srdivacky			ip->ip_id = htons(id++);
218205218Srdivacky			ip->ip_sum = 0;
219212904Sdim			ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
220203954Srdivacky			(void) send_ether(nfd, (char *)ip, i, gwip);
221212904Sdim			printf("%d\r", i);
222198090Srdivacky			fflush(stdout);
223203954Srdivacky			PAUSE();
224193323Sed		}
225193323Sed		putchar('\n');
226193323Sed	}
227203954Srdivacky
228193323Sed	if (!ptest || (ptest == 7)) {
229193323Sed		/*
230193323Sed		 * Part7: 0 length fragment
231193323Sed		 */
232193323Sed		printf("1.7.0 Zero length fragments (ip_off = 0x2000)\n");
233193323Sed		ip->ip_id = 0;
234204642Srdivacky		ip->ip_len = sizeof(*ip);
235193323Sed		ip->ip_off = htons(IP_MF);
236239462Sdim		(void) send_ip(nfd, mtu, ip, gwip, 1);
237234353Sdim		fflush(stdout);
238193323Sed		PAUSE();
239193323Sed
240234353Sdim		printf("1.7.1 Zero length fragments (ip_off = 0x3000)\n");
241193323Sed		ip->ip_id = 0;
242193323Sed		ip->ip_len = sizeof(*ip);
243193323Sed		ip->ip_off = htons(IP_MF);
244193323Sed		(void) send_ip(nfd, mtu, ip, gwip, 1);
245193323Sed		fflush(stdout);
246212904Sdim		PAUSE();
247212904Sdim
248212904Sdim		printf("1.7.2 Zero length fragments (ip_off = 0xa000)\n");
249212904Sdim		ip->ip_id = 0;
250212904Sdim		ip->ip_len = sizeof(*ip);
251212904Sdim		ip->ip_off = htons(0xa000);
252212904Sdim		(void) send_ip(nfd, mtu, ip, gwip, 1);
253221345Sdim		fflush(stdout);
254212904Sdim		PAUSE();
255212904Sdim
256239462Sdim		printf("1.7.3 Zero length fragments (ip_off = 0x0100)\n");
257234353Sdim		ip->ip_id = 0;
258212904Sdim		ip->ip_len = sizeof(*ip);
259221345Sdim		ip->ip_off = htons(0x0100);
260221345Sdim		(void) send_ip(nfd, mtu, ip, gwip, 1);
261221345Sdim		fflush(stdout);
262221345Sdim		PAUSE();
263221345Sdim	}
264221345Sdim
265239462Sdim	if (!ptest || (ptest == 8)) {
266224145Sdim		struct	timeval	tv;
267239462Sdim
268239462Sdim		gettimeofday(&tv, NULL);
269241430Sdim		srand(tv.tv_sec ^ getpid() ^ tv.tv_usec);
270226633Sdim		/*
271221345Sdim		 * Part8.1: 63k packet + 1k fragment at offset 0x1ffe
272221345Sdim		 * Mark it as being ICMP (so it doesn't get junked), but
273221345Sdim		 * don't bother about the ICMP header, we're not worrying
274226633Sdim		 * about that here.
275226633Sdim		 */
276226633Sdim		ip->ip_p = IPPROTO_ICMP;
277226633Sdim		ip->ip_off = IP_MF;
278221345Sdim		u->uh_dport = htons(9);
279221345Sdim		ip->ip_id = htons(id++);
280221345Sdim		printf("1.8.1 63k packet + 1k fragment at offset 0x1ffe\n");
281221345Sdim		ip->ip_len = 768 + 20 + 8;
282221345Sdim		(void) send_ip(nfd, mtu, ip, gwip, 1);
283221345Sdim		printf("%d\r", i);
284221345Sdim
285221345Sdim		ip->ip_len = MIN(768 + 20, mtu - 68);
286221345Sdim		i = 512;
287221345Sdim		for (; i < (63 * 1024 + 768); i += 768) {
288221345Sdim			ip->ip_off = IP_MF | (i >> 3);
289221345Sdim			(void) send_ip(nfd, mtu, ip, gwip, 1);
290212904Sdim			printf("%d\r", i);
291212904Sdim			fflush(stdout);
292			PAUSE();
293		}
294		ip->ip_len = 896 + 20;
295		ip->ip_off = (i >> 3);
296		(void) send_ip(nfd, mtu, ip, gwip, 1);
297		printf("%d\r", i);
298		putchar('\n');
299		fflush(stdout);
300
301		/*
302		 * Part8.2: 63k packet + 1k fragment at offset 0x1ffe
303		 * Mark it as being ICMP (so it doesn't get junked), but
304		 * don't bother about the ICMP header, we're not worrying
305		 * about that here.  (Lossage here)
306		 */
307		ip->ip_p = IPPROTO_ICMP;
308		ip->ip_off = IP_MF;
309		u->uh_dport = htons(9);
310		ip->ip_id = htons(id++);
311		printf("1.8.2 63k packet + 1k fragment at offset 0x1ffe\n");
312		ip->ip_len = 768 + 20 + 8;
313		if ((rand() & 0x1f) != 0) {
314			(void) send_ip(nfd, mtu, ip, gwip, 1);
315			printf("%d\r", i);
316		} else
317			printf("skip 0\n");
318
319		ip->ip_len = MIN(768 + 20, mtu - 68);
320		i = 512;
321		for (; i < (63 * 1024 + 768); i += 768) {
322			ip->ip_off = IP_MF | (i >> 3);
323			if ((rand() & 0x1f) != 0) {
324				(void) send_ip(nfd, mtu, ip, gwip, 1);
325				printf("%d\r", i);
326			} else
327				printf("skip %d\n", i);
328			fflush(stdout);
329			PAUSE();
330		}
331		ip->ip_len = 896 + 20;
332		ip->ip_off = (i >> 3);
333		if ((rand() & 0x1f) != 0) {
334			(void) send_ip(nfd, mtu, ip, gwip, 1);
335			printf("%d\r", i);
336		} else
337			printf("skip\n");
338		putchar('\n');
339		fflush(stdout);
340
341		/*
342		 * Part8.3: 33k packet - test for not dealing with -ve length
343		 * Mark it as being ICMP (so it doesn't get junked), but
344		 * don't bother about the ICMP header, we're not worrying
345		 * about that here.
346		 */
347		ip->ip_p = IPPROTO_ICMP;
348		ip->ip_off = IP_MF;
349		u->uh_dport = htons(9);
350		ip->ip_id = htons(id++);
351		printf("1.8.3 33k packet\n");
352		ip->ip_len = 768 + 20 + 8;
353		(void) send_ip(nfd, mtu, ip, gwip, 1);
354		printf("%d\r", i);
355
356		ip->ip_len = MIN(768 + 20, mtu - 68);
357		i = 512;
358		for (; i < (32 * 1024 + 768); i += 768) {
359			ip->ip_off = IP_MF | (i >> 3);
360			(void) send_ip(nfd, mtu, ip, gwip, 1);
361			printf("%d\r", i);
362			fflush(stdout);
363			PAUSE();
364		}
365		ip->ip_len = 896 + 20;
366		ip->ip_off = (i >> 3);
367		(void) send_ip(nfd, mtu, ip, gwip, 1);
368		printf("%d\r", i);
369		putchar('\n');
370		fflush(stdout);
371	}
372
373	ip->ip_len = len;
374	ip->ip_off = 0;
375	if (!ptest || (ptest == 9)) {
376		/*
377		 * Part9: off & 0x8000 == 0x8000
378		 */
379		ip->ip_id = 0;
380		ip->ip_off = 0x8000;
381		printf("1.9. ip_off & 0x8000 == 0x8000\n");
382		(void) send_ip(nfd, mtu, ip, gwip, 1);
383		fflush(stdout);
384		PAUSE();
385	}
386
387	ip->ip_off = 0;
388
389	if (!ptest || (ptest == 10)) {
390		/*
391		 * Part10: ttl = 255
392		 */
393		ip->ip_id = 0;
394		ip->ip_ttl = 255;
395		printf("1.10.0 ip_ttl = 255\n");
396		(void) send_ip(nfd, mtu, ip, gwip, 1);
397		fflush(stdout);
398		PAUSE();
399
400		ip->ip_ttl = 128;
401		printf("1.10.1 ip_ttl = 128\n");
402		(void) send_ip(nfd, mtu, ip, gwip, 1);
403		fflush(stdout);
404		PAUSE();
405
406		ip->ip_ttl = 0;
407		printf("1.10.2 ip_ttl = 0\n");
408		(void) send_ip(nfd, mtu, ip, gwip, 1);
409		fflush(stdout);
410		PAUSE();
411	}
412
413	(void) close(nfd);
414}
415
416
417void	ip_test2(dev, mtu, ip, gwip, ptest)
418char	*dev;
419int	mtu;
420ip_t	*ip;
421struct	in_addr	gwip;
422int	ptest;
423{
424	struct	timeval	tv;
425	int	nfd;
426	u_char	*s;
427
428	s = (u_char *)(ip + 1);
429	nfd = initdevice(dev, 1, 1);
430
431	ip->ip_hl = 6;
432	ip->ip_len = ip->ip_hl << 2;
433	s[IPOPT_OPTVAL] = IPOPT_NOP;
434	s++;
435	if (!ptest || (ptest == 1)) {
436		/*
437		 * Test 1: option length > packet length,
438		 *                header length == packet length
439		 */
440		s[IPOPT_OPTVAL] = IPOPT_TS;
441		s[IPOPT_OLEN] = 4;
442		s[IPOPT_OFFSET] = IPOPT_MINOFF;
443		ip->ip_p = IPPROTO_IP;
444		printf("2.1 option length > packet length\n");
445		(void) send_ip(nfd, mtu, ip, gwip, 1);
446		fflush(stdout);
447		PAUSE();
448	}
449
450	ip->ip_hl = 7;
451	ip->ip_len = ip->ip_hl << 2;
452	if (!ptest || (ptest == 1)) {
453		/*
454		 * Test 2: options have length = 0
455		 */
456		printf("2.2.1 option length = 0, RR\n");
457		s[IPOPT_OPTVAL] = IPOPT_RR;
458		s[IPOPT_OLEN] = 0;
459		(void) send_ip(nfd, mtu, ip, gwip, 1);
460		fflush(stdout);
461		PAUSE();
462
463		printf("2.2.2 option length = 0, TS\n");
464		s[IPOPT_OPTVAL] = IPOPT_TS;
465		s[IPOPT_OLEN] = 0;
466		(void) send_ip(nfd, mtu, ip, gwip, 1);
467		fflush(stdout);
468		PAUSE();
469
470		printf("2.2.3 option length = 0, SECURITY\n");
471		s[IPOPT_OPTVAL] = IPOPT_SECURITY;
472		s[IPOPT_OLEN] = 0;
473		(void) send_ip(nfd, mtu, ip, gwip, 1);
474		fflush(stdout);
475		PAUSE();
476
477		printf("2.2.4 option length = 0, LSRR\n");
478		s[IPOPT_OPTVAL] = IPOPT_LSRR;
479		s[IPOPT_OLEN] = 0;
480		(void) send_ip(nfd, mtu, ip, gwip, 1);
481		fflush(stdout);
482		PAUSE();
483
484		printf("2.2.5 option length = 0, SATID\n");
485		s[IPOPT_OPTVAL] = IPOPT_SATID;
486		s[IPOPT_OLEN] = 0;
487		(void) send_ip(nfd, mtu, ip, gwip, 1);
488		fflush(stdout);
489		PAUSE();
490
491		printf("2.2.6 option length = 0, SSRR\n");
492		s[IPOPT_OPTVAL] = IPOPT_SSRR;
493		s[IPOPT_OLEN] = 0;
494		(void) send_ip(nfd, mtu, ip, gwip, 1);
495		fflush(stdout);
496		PAUSE();
497	}
498
499	(void) close(nfd);
500}
501
502
503/*
504 * test 3 (ICMP)
505 */
506void	ip_test3(dev, mtu, ip, gwip, ptest)
507char	*dev;
508int	mtu;
509ip_t	*ip;
510struct	in_addr	gwip;
511int	ptest;
512{
513	static	int	ict1[10] = { 8, 9, 10, 13, 14, 15, 16, 17, 18, 0 };
514	static	int	ict2[8] = { 3, 9, 10, 13, 14, 17, 18, 0 };
515	struct	timeval	tv;
516	struct	icmp	*icp;
517	int	nfd, i;
518
519	ip->ip_hl = sizeof(*ip) >> 2;
520	ip->ip_v = IPVERSION;
521	ip->ip_tos = 0;
522	ip->ip_off = 0;
523	ip->ip_ttl = 60;
524	ip->ip_p = IPPROTO_ICMP;
525	ip->ip_sum = 0;
526	ip->ip_len = sizeof(*ip) + sizeof(*icp);
527	icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
528	nfd = initdevice(dev, 1, 1);
529
530	if (!ptest || (ptest == 1)) {
531		/*
532		 * Type 0 - 31, 255, code = 0
533		 */
534		bzero((char *)icp, sizeof(*icp));
535		for (i = 0; i < 32; i++) {
536			icp->icmp_type = i;
537			(void) send_icmp(nfd, mtu, ip, gwip);
538			PAUSE();
539			printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, i);
540		}
541		icp->icmp_type = 255;
542		(void) send_icmp(nfd, mtu, ip, gwip);
543		PAUSE();
544		printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, 255);
545		putchar('\n');
546	}
547
548	if (!ptest || (ptest == 2)) {
549		/*
550		 * Type 3, code = 0 - 31
551		 */
552		icp->icmp_type = 3;
553		for (i = 0; i < 32; i++) {
554			icp->icmp_code = i;
555			(void) send_icmp(nfd, mtu, ip, gwip);
556			PAUSE();
557			printf("3.2.%d ICMP type 3 code %d (all 0's)\r", i, i);
558		}
559	}
560
561	if (!ptest || (ptest == 3)) {
562		/*
563		 * Type 4, code = 0,127,128,255
564		 */
565		icp->icmp_type = 4;
566		icp->icmp_code = 0;
567		(void) send_icmp(nfd, mtu, ip, gwip);
568		PAUSE();
569		printf("3.3.1 ICMP type 4 code 0 (all 0's)\r");
570		icp->icmp_code = 127;
571		(void) send_icmp(nfd, mtu, ip, gwip);
572		PAUSE();
573		printf("3.3.2 ICMP type 4 code 127 (all 0's)\r");
574		icp->icmp_code = 128;
575		(void) send_icmp(nfd, mtu, ip, gwip);
576		PAUSE();
577		printf("3.3.3 ICMP type 4 code 128 (all 0's)\r");
578		icp->icmp_code = 255;
579		(void) send_icmp(nfd, mtu, ip, gwip);
580		PAUSE();
581		printf("3.3.4 ICMP type 4 code 255 (all 0's)\r");
582	}
583
584	if (!ptest || (ptest == 4)) {
585		/*
586		 * Type 5, code = 0,127,128,255
587		 */
588		icp->icmp_type = 5;
589		icp->icmp_code = 0;
590		(void) send_icmp(nfd, mtu, ip, gwip);
591		PAUSE();
592		printf("3.4.1 ICMP type 5 code 0 (all 0's)\r");
593		icp->icmp_code = 127;
594		(void) send_icmp(nfd, mtu, ip, gwip);
595		PAUSE();
596		printf("3.4.2 ICMP type 5 code 127 (all 0's)\r");
597		icp->icmp_code = 128;
598		(void) send_icmp(nfd, mtu, ip, gwip);
599		PAUSE();
600		printf("3.4.3 ICMP type 5 code 128 (all 0's)\r");
601		icp->icmp_code = 255;
602		(void) send_icmp(nfd, mtu, ip, gwip);
603		PAUSE();
604		printf("3.4.4 ICMP type 5 code 255 (all 0's)\r");
605	}
606
607	if (!ptest || (ptest == 5)) {
608		/*
609		 * Type 8-10;13-18, code - 0,127,128,255
610		 */
611		for (i = 0; ict1[i]; i++) {
612			icp->icmp_type = ict1[i];
613			icp->icmp_code = 0;
614			(void) send_icmp(nfd, mtu, ip, gwip);
615			PAUSE();
616			printf("3.5.%d ICMP type 5 code 0 (all 0's)\r",
617				i * 4);
618			icp->icmp_code = 127;
619			(void) send_icmp(nfd, mtu, ip, gwip);
620			PAUSE();
621			printf("3.5.%d ICMP type 5 code 127 (all 0's)\r",
622				i * 4 + 1);
623			icp->icmp_code = 128;
624			(void) send_icmp(nfd, mtu, ip, gwip);
625			PAUSE();
626			printf("3.5.%d ICMP type 5 code 128 (all 0's)\r",
627				i * 4 + 2);
628			icp->icmp_code = 255;
629			(void) send_icmp(nfd, mtu, ip, gwip);
630			PAUSE();
631			printf("3.5.%d ICMP type 5 code 255 (all 0's)\r",
632				i * 4 + 3);
633		}
634		putchar('\n');
635	}
636
637	if (!ptest || (ptest == 6)) {
638		/*
639		 * Type 12, code - 0,127,128,129,255
640		 */
641		icp->icmp_type = 12;
642		icp->icmp_code = 0;
643		(void) send_icmp(nfd, mtu, ip, gwip);
644		PAUSE();
645		printf("3.6.1 ICMP type 12 code 0 (all 0's)\r");
646		icp->icmp_code = 127;
647		(void) send_icmp(nfd, mtu, ip, gwip);
648		PAUSE();
649		printf("3.6.2 ICMP type 12 code 127 (all 0's)\r");
650		icp->icmp_code = 128;
651		(void) send_icmp(nfd, mtu, ip, gwip);
652		PAUSE();
653		printf("3.6.3 ICMP type 12 code 128 (all 0's)\r");
654		icp->icmp_code = 129;
655		(void) send_icmp(nfd, mtu, ip, gwip);
656		PAUSE();
657		printf("3.6.4 ICMP type 12 code 129 (all 0's)\r");
658		icp->icmp_code = 255;
659		(void) send_icmp(nfd, mtu, ip, gwip);
660		PAUSE();
661		printf("3.6.5 ICMP type 12 code 255 (all 0's)\r");
662		putchar('\n');
663	}
664
665	if (!ptest || (ptest == 7)) {
666		/*
667		 * Type 3;9-10;13-14;17-18 - shorter packets
668		 */
669		ip->ip_len = sizeof(*ip) + sizeof(*icp) / 2;
670		for (i = 0; ict2[i]; i++) {
671			icp->icmp_type = ict1[i];
672			icp->icmp_code = 0;
673			(void) send_icmp(nfd, mtu, ip, gwip);
674			PAUSE();
675			printf("3.5.%d ICMP type %d code 0 (all 0's)\r",
676				i * 4, icp->icmp_type);
677			icp->icmp_code = 127;
678			(void) send_icmp(nfd, mtu, ip, gwip);
679			PAUSE();
680			printf("3.5.%d ICMP type %d code 127 (all 0's)\r",
681				i * 4 + 1, icp->icmp_type);
682			icp->icmp_code = 128;
683			(void) send_icmp(nfd, mtu, ip, gwip);
684			PAUSE();
685			printf("3.5.%d ICMP type %d code 128 (all 0's)\r",
686				i * 4 + 2, icp->icmp_type);
687			icp->icmp_code = 255;
688			(void) send_icmp(nfd, mtu, ip, gwip);
689			PAUSE();
690			printf("3.5.%d ICMP type %d code 127 (all 0's)\r",
691				i * 4 + 3, icp->icmp_type);
692		}
693		putchar('\n');
694	}
695}
696
697
698/* Perform test 4 (UDP) */
699
700void	ip_test4(dev, mtu, ip, gwip, ptest)
701char	*dev;
702int	mtu;
703ip_t	*ip;
704struct	in_addr	gwip;
705int	ptest;
706{
707	struct	timeval	tv;
708	struct	udphdr	*u;
709	int	nfd, i;
710
711
712	ip->ip_hl = sizeof(*ip) >> 2;
713	ip->ip_v = IPVERSION;
714	ip->ip_tos = 0;
715	ip->ip_off = 0;
716	ip->ip_ttl = 60;
717	ip->ip_p = IPPROTO_UDP;
718	ip->ip_sum = 0;
719	u = (udphdr_t *)((char *)ip + (ip->ip_hl << 2));
720	u->uh_sport = 1;
721	u->uh_dport = 1;
722	u->uh_ulen = sizeof(*u) + 4;
723	nfd = initdevice(dev, u->uh_sport, 1);
724
725	if (!ptest || (ptest == 1)) {
726		/*
727		 * Test 1. ulen > packet
728		 */
729		u->uh_ulen = sizeof(*u) + 4;
730		ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen;
731		printf("4.1 UDP uh_ulen > packet size - short packets\n");
732		for (i = u->uh_ulen * 2; i > sizeof(*u) + 4; i--) {
733			u->uh_ulen = i;
734			(void) send_udp(nfd, 1500, ip, gwip);
735			printf("%d\r", i);
736			fflush(stdout);
737			PAUSE();
738		}
739		putchar('\n');
740	}
741
742	if (!ptest || (ptest == 2)) {
743		/*
744		 * Test 2. ulen < packet
745		 */
746		u->uh_ulen = sizeof(*u) + 4;
747		ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen;
748		printf("4.2 UDP uh_ulen < packet size - short packets\n");
749		for (i = u->uh_ulen * 2; i > sizeof(*u) + 4; i--) {
750			ip->ip_len = i;
751			(void) send_udp(nfd, 1500, ip, gwip);
752			printf("%d\r", i);
753			fflush(stdout);
754			PAUSE();
755		}
756		putchar('\n');
757	}
758
759	if (!ptest || (ptest == 3)) {
760		/*
761		 * Test 3: sport = 0, sport = 1, sport = 32767
762		 *         sport = 32768, sport = 65535
763		 */
764		u->uh_ulen = sizeof(*u) + 4;
765		ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen;
766		printf("4.3.1 UDP sport = 0\n");
767		u->uh_sport = 0;
768		(void) send_udp(nfd, 1500, ip, gwip);
769		printf("0\n");
770		fflush(stdout);
771		PAUSE();
772		printf("4.3.2 UDP sport = 1\n");
773		u->uh_sport = 1;
774		(void) send_udp(nfd, 1500, ip, gwip);
775		printf("1\n");
776		fflush(stdout);
777		PAUSE();
778		printf("4.3.3 UDP sport = 32767\n");
779		u->uh_sport = 32767;
780		(void) send_udp(nfd, 1500, ip, gwip);
781		printf("32767\n");
782		fflush(stdout);
783		PAUSE();
784		printf("4.3.4 UDP sport = 32768\n");
785		u->uh_sport = 32768;
786		(void) send_udp(nfd, 1500, ip, gwip);
787		printf("32768\n");
788		putchar('\n');
789		fflush(stdout);
790		PAUSE();
791		printf("4.3.5 UDP sport = 65535\n");
792		u->uh_sport = 65535;
793		(void) send_udp(nfd, 1500, ip, gwip);
794		printf("65535\n");
795		fflush(stdout);
796		PAUSE();
797	}
798
799	if (!ptest || (ptest == 4)) {
800		/*
801		 * Test 4: dport = 0, dport = 1, dport = 32767
802		 *         dport = 32768, dport = 65535
803		 */
804		u->uh_ulen = sizeof(*u) + 4;
805		u->uh_sport = 1;
806		ip->ip_len = (ip->ip_hl << 2) + u->uh_ulen;
807		printf("4.4.1 UDP dport = 0\n");
808		u->uh_dport = 0;
809		(void) send_udp(nfd, 1500, ip, gwip);
810		printf("0\n");
811		fflush(stdout);
812		PAUSE();
813		printf("4.4.2 UDP dport = 1\n");
814		u->uh_dport = 1;
815		(void) send_udp(nfd, 1500, ip, gwip);
816		printf("1\n");
817		fflush(stdout);
818		PAUSE();
819		printf("4.4.3 UDP dport = 32767\n");
820		u->uh_dport = 32767;
821		(void) send_udp(nfd, 1500, ip, gwip);
822		printf("32767\n");
823		fflush(stdout);
824		PAUSE();
825		printf("4.4.4 UDP dport = 32768\n");
826		u->uh_dport = 32768;
827		(void) send_udp(nfd, 1500, ip, gwip);
828		printf("32768\n");
829		fflush(stdout);
830		PAUSE();
831		printf("4.4.5 UDP dport = 65535\n");
832		u->uh_dport = 65535;
833		(void) send_udp(nfd, 1500, ip, gwip);
834		printf("65535\n");
835		fflush(stdout);
836		PAUSE();
837	}
838
839	if (!ptest || (ptest == 4)) {
840		/*
841		 * Test 5: sizeof(struct ip) <= MTU <= sizeof(struct udphdr) +
842		 * sizeof(struct ip)
843		 */
844		printf("4.5 UDP 20 <= MTU <= 32\n");
845		for (i = sizeof(*ip); i <= u->uh_ulen; i++) {
846			(void) send_udp(nfd, i, ip, gwip);
847			printf("%d\r", i);
848			fflush(stdout);
849			PAUSE();
850		}
851		putchar('\n');
852	}
853}
854
855
856/* Perform test 5 (TCP) */
857
858void	ip_test5(dev, mtu, ip, gwip, ptest)
859char	*dev;
860int	mtu;
861ip_t	*ip;
862struct	in_addr	gwip;
863int	ptest;
864{
865	struct	timeval	tv;
866	tcphdr_t *t;
867	int	nfd, i;
868
869	t = (tcphdr_t *)((char *)ip + (ip->ip_hl << 2));
870	t->th_x2 = 0;
871	t->th_off = 0;
872	t->th_sport = 1;
873	t->th_dport = 1;
874	t->th_win = 4096;
875	t->th_urp = 0;
876	t->th_sum = 0;
877	t->th_seq = 1;
878	t->th_ack = 0;
879	nfd = initdevice(dev, t->th_sport, 1);
880
881	if (!ptest || (ptest == 1)) {
882		/*
883		 * Test 1: flags variations, 0 - 3f
884		 */
885		t->th_off = sizeof(*t) >> 2;
886		printf("5.1 Test TCP flag combinations\n");
887		for (i = 0; i <= (TH_URG|TH_ACK|TH_PUSH|TH_RST|TH_SYN|TH_FIN);
888		     i++) {
889			t->th_flags = i;
890			(void) send_tcp(nfd, mtu, ip, gwip);
891			printf("%d\r", i);
892			fflush(stdout);
893			PAUSE();
894		}
895		putchar('\n');
896	}
897
898	if (!ptest || (ptest == 2)) {
899		t->th_flags = TH_SYN;
900		/*
901		 * Test 2: seq = 0, seq = 1, seq = 0x7fffffff, seq=0x80000000,
902		 *         seq = 0xa000000, seq = 0xffffffff
903		 */
904		printf("5.2.1 TCP seq = 0\n");
905		t->th_seq = 0;
906		(void) send_tcp(nfd, mtu, ip, gwip);
907		fflush(stdout);
908		PAUSE();
909
910		printf("5.2.2 TCP seq = 1\n");
911		t->th_seq = 1;
912		(void) send_tcp(nfd, mtu, ip, gwip);
913		fflush(stdout);
914		PAUSE();
915
916		printf("5.2.3 TCP seq = 0x7fffffff\n");
917		t->th_seq = 0x7fffffff;
918		(void) send_tcp(nfd, mtu, ip, gwip);
919		fflush(stdout);
920		PAUSE();
921
922		printf("5.2.4 TCP seq = 0x80000000\n");
923		t->th_seq = 0x80000000;
924		(void) send_tcp(nfd, mtu, ip, gwip);
925		fflush(stdout);
926		PAUSE();
927
928		printf("5.2.5 TCP seq = 0xc0000000\n");
929		t->th_seq = 0xc0000000;
930		(void) send_tcp(nfd, mtu, ip, gwip);
931		fflush(stdout);
932		PAUSE();
933
934		printf("5.2.6 TCP seq = 0xffffffff\n");
935		t->th_seq = 0xffffffff;
936		(void) send_tcp(nfd, mtu, ip, gwip);
937		fflush(stdout);
938		PAUSE();
939	}
940
941	if (!ptest || (ptest == 3)) {
942		t->th_flags = TH_ACK;
943		/*
944		 * Test 3: ack = 0, ack = 1, ack = 0x7fffffff, ack = 0x8000000
945		 *         ack = 0xa000000, ack = 0xffffffff
946		 */
947		printf("5.3.1 TCP ack = 0\n");
948		t->th_ack = 0;
949		(void) send_tcp(nfd, mtu, ip, gwip);
950		fflush(stdout);
951		PAUSE();
952
953		printf("5.3.2 TCP ack = 1\n");
954		t->th_ack = 1;
955		(void) send_tcp(nfd, mtu, ip, gwip);
956		fflush(stdout);
957		PAUSE();
958
959		printf("5.3.3 TCP ack = 0x7fffffff\n");
960		t->th_ack = 0x7fffffff;
961		(void) send_tcp(nfd, mtu, ip, gwip);
962		fflush(stdout);
963		PAUSE();
964
965		printf("5.3.4 TCP ack = 0x80000000\n");
966		t->th_ack = 0x80000000;
967		(void) send_tcp(nfd, mtu, ip, gwip);
968		fflush(stdout);
969		PAUSE();
970
971		printf("5.3.5 TCP ack = 0xc0000000\n");
972		t->th_ack = 0xc0000000;
973		(void) send_tcp(nfd, mtu, ip, gwip);
974		fflush(stdout);
975		PAUSE();
976
977		printf("5.3.6 TCP ack = 0xffffffff\n");
978		t->th_ack = 0xffffffff;
979		(void) send_tcp(nfd, mtu, ip, gwip);
980		fflush(stdout);
981		PAUSE();
982	}
983
984	if (!ptest || (ptest == 4)) {
985		t->th_flags = TH_SYN;
986		/*
987		 * Test 4: win = 0, win = 32768, win = 65535
988		 */
989		printf("5.4.1 TCP win = 0\n");
990		t->th_seq = 0;
991		(void) send_tcp(nfd, mtu, ip, gwip);
992		fflush(stdout);
993		PAUSE();
994
995		printf("5.4.2 TCP win = 32768\n");
996		t->th_seq = 0x7fff;
997		(void) send_tcp(nfd, mtu, ip, gwip);
998		fflush(stdout);
999		PAUSE();
1000
1001		printf("5.4.3 TCP win = 65535\n");
1002		t->th_win = 0xffff;
1003		(void) send_tcp(nfd, mtu, ip, gwip);
1004		fflush(stdout);
1005		PAUSE();
1006	}
1007
1008#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__)
1009	{
1010	struct tcpcb *t, tcb;
1011	struct tcpiphdr ti;
1012	struct sockaddr_in sin;
1013	int fd, slen;
1014
1015	bzero((char *)&sin, sizeof(sin));
1016
1017	for (i = 1; i < 63; i++) {
1018		fd = socket(AF_INET, SOCK_STREAM, 0);
1019		sin.sin_addr.s_addr = ip->ip_dst.s_addr;
1020		sin.sin_port = htons(i);
1021		if (!connect(fd, (struct sockaddr *)&sin, sizeof(sin)))
1022			break;
1023	}
1024
1025	if (i == 63) {
1026		printf("Couldn't open a TCP socket between ports 1 and 63\n");
1027		printf("to host %s for test 5 and 6 - skipping.\n",
1028			inet_ntoa(ip->ip_dst));
1029		goto skip_five_and_six;
1030	}
1031
1032	bcopy((char *)ip, (char *)&ti, sizeof(*ip));
1033	ti.ti_dport = i;
1034	slen = sizeof(sin);
1035	if (!getsockname(fd, (struct sockaddr *)&sin, &slen))
1036		ti.ti_sport = sin.sin_port;
1037	if (!(t = find_tcp(fd, &ti))) {
1038		printf("Can't find PCB\n");
1039		goto skip_five_and_six;
1040	}
1041	KMCPY(&tcb, t, sizeof(tcb));
1042	ti.ti_win = tcb.rcv_adv;
1043	ti.ti_seq = tcb.snd_nxt - 1;
1044	ti.ti_ack = tcb.rcv_nxt;
1045
1046	if (!ptest || (ptest == 5)) {
1047		/*
1048		 * Test 5: urp
1049		 */
1050		printf("5.1 TCP Urgent pointer\n");
1051		ti.ti_urp = 1;
1052		(void) send_tcp(nfd, mtu, ip, gwip);
1053		PAUSE();
1054		ti.ti_urp = 0x7fff;
1055		(void) send_tcp(nfd, mtu, ip, gwip);
1056		PAUSE();
1057		ti.ti_urp = 0x8000;
1058		(void) send_tcp(nfd, mtu, ip, gwip);
1059		PAUSE();
1060		ti.ti_urp = 0xffff;
1061		(void) send_tcp(nfd, mtu, ip, gwip);
1062		PAUSE();
1063	}
1064
1065	if (!ptest || (ptest == 6)) {
1066		/*
1067		 * Test 6: data offset, off = 0, off is inside, off is outside
1068		 */
1069		printf("6.1 TCP off = 0-15, len = 40\n");
1070		for (i = 0; i < 16; i++) {
1071			ti.ti_off = ntohs(i);
1072			(void) send_tcp(nfd, mtu, ip, gwip);
1073			printf("%d\r", i);
1074			fflush(stdout);
1075			PAUSE();
1076		}
1077		putchar('\n');
1078	}
1079
1080	(void) close(fd);
1081	}
1082skip_five_and_six:
1083#endif
1084	t->th_seq = 1;
1085	t->th_ack = 1;
1086
1087	if (!ptest || (ptest == 7)) {
1088		t->th_off = 0;
1089		t->th_flags = TH_SYN;
1090		/*
1091		 * Test 7: sport = 0, sport = 1, sport = 32767
1092		 *         sport = 32768, sport = 65535
1093		 */
1094		printf("5.7.1 TCP sport = 0\n");
1095		t->th_sport = 0;
1096		(void) send_tcp(nfd, mtu, ip, gwip);
1097		fflush(stdout);
1098		PAUSE();
1099
1100		printf("5.7.2 TCP sport = 1\n");
1101		t->th_sport = 1;
1102		(void) send_tcp(nfd, mtu, ip, gwip);
1103		fflush(stdout);
1104		PAUSE();
1105
1106		printf("5.7.3 TCP sport = 32767\n");
1107		t->th_sport = 32767;
1108		(void) send_tcp(nfd, mtu, ip, gwip);
1109		fflush(stdout);
1110		PAUSE();
1111
1112		printf("5.7.4 TCP sport = 32768\n");
1113		t->th_sport = 32768;
1114		(void) send_tcp(nfd, mtu, ip, gwip);
1115		fflush(stdout);
1116		PAUSE();
1117
1118		printf("5.7.5 TCP sport = 65535\n");
1119		t->th_sport = 65535;
1120		(void) send_tcp(nfd, mtu, ip, gwip);
1121		fflush(stdout);
1122		PAUSE();
1123	}
1124
1125	if (!ptest || (ptest == 8)) {
1126		t->th_sport = 1;
1127		/*
1128		 * Test 8: dport = 0, dport = 1, dport = 32767
1129		 *         dport = 32768, dport = 65535
1130		 */
1131		printf("5.8.1 TCP dport = 0\n");
1132		t->th_dport = 0;
1133		(void) send_tcp(nfd, mtu, ip, gwip);
1134		fflush(stdout);
1135		PAUSE();
1136
1137		printf("5.8.2 TCP dport = 1\n");
1138		t->th_dport = 1;
1139		(void) send_tcp(nfd, mtu, ip, gwip);
1140		fflush(stdout);
1141		PAUSE();
1142
1143		printf("5.8.3 TCP dport = 32767\n");
1144		t->th_dport = 32767;
1145		(void) send_tcp(nfd, mtu, ip, gwip);
1146		fflush(stdout);
1147		PAUSE();
1148
1149		printf("5.8.4 TCP dport = 32768\n");
1150		t->th_dport = 32768;
1151		(void) send_tcp(nfd, mtu, ip, gwip);
1152		fflush(stdout);
1153		PAUSE();
1154
1155		printf("5.8.5 TCP dport = 65535\n");
1156		t->th_dport = 65535;
1157		(void) send_tcp(nfd, mtu, ip, gwip);
1158		fflush(stdout);
1159		PAUSE();
1160	}
1161	/* TCP options header checking */
1162	/* 0 length options, etc */
1163}
1164
1165
1166/* Perform test 6 (exhaust mbuf test) */
1167
1168void	ip_test6(dev, mtu, ip, gwip, ptest)
1169char	*dev;
1170int	mtu;
1171ip_t	*ip;
1172struct	in_addr	gwip;
1173int	ptest;
1174{
1175	struct	timeval	tv;
1176	udphdr_t *u;
1177	int	nfd, i, j, k;
1178
1179	ip->ip_v = IPVERSION;
1180	ip->ip_tos = 0;
1181	ip->ip_off = 0;
1182	ip->ip_ttl = 60;
1183	ip->ip_p = IPPROTO_UDP;
1184	ip->ip_sum = 0;
1185	u = (udphdr_t *)(ip + 1);
1186	u->uh_sport = 1;
1187	u->uh_dport = 9;
1188	u->uh_sum = 0;
1189
1190	nfd = initdevice(dev, u->uh_sport, 1);
1191	u->uh_sport = htons(u->uh_sport);
1192	u->uh_dport = htons(u->uh_dport);
1193	u->uh_ulen = 7168;
1194
1195	for (i = 0; i < 128; i++) {
1196		/*
1197		 * First send the entire packet in 768 byte chunks.
1198		 */
1199		ip->ip_len = sizeof(*ip) + 768 + sizeof(*u);
1200		ip->ip_hl = sizeof(*ip) >> 2;
1201		ip->ip_off = IP_MF;
1202		(void) send_ip(nfd, 1500, ip, gwip, 1);
1203		printf("%d %d\r", i, 0);
1204		fflush(stdout);
1205		PAUSE();
1206		/*
1207		 * And again using 128 byte chunks.
1208		 */
1209		ip->ip_len = sizeof(*ip) + 128 + sizeof(*u);
1210		ip->ip_off = IP_MF;
1211		(void) send_ip(nfd, 1500, ip, gwip, 1);
1212		printf("%d %d\r", i, 0);
1213		fflush(stdout);
1214		PAUSE();
1215
1216		for (j = 768; j < 3584; j += 768) {
1217			ip->ip_len = sizeof(*ip) + 768;
1218			ip->ip_off = IP_MF|(j>>3);
1219			(void) send_ip(nfd, 1500, ip, gwip, 1);
1220			printf("%d %d\r", i, j);
1221			fflush(stdout);
1222			PAUSE();
1223
1224			ip->ip_len = sizeof(*ip) + 128;
1225			for (k = j - 768; k < j; k += 128) {
1226				ip->ip_off = IP_MF|(k>>3);
1227				(void) send_ip(nfd, 1500, ip, gwip, 1);
1228				printf("%d %d\r", i, k);
1229				fflush(stdout);
1230				PAUSE();
1231			}
1232		}
1233	}
1234	putchar('\n');
1235}
1236
1237
1238/* Perform test 7 (random packets) */
1239
1240static	u_long	tbuf[64];
1241
1242void	ip_test7(dev, mtu, ip, gwip, ptest)
1243char	*dev;
1244int	mtu;
1245ip_t	*ip;
1246struct	in_addr	gwip;
1247int	ptest;
1248{
1249	ip_t	*pip;
1250	struct	timeval	tv;
1251	int	nfd, i, j;
1252	u_char	*s;
1253
1254	nfd = initdevice(dev, 0, 1);
1255	pip = (ip_t *)tbuf;
1256
1257	srand(time(NULL) ^ (getpid() * getppid()));
1258
1259	printf("7. send 1024 random IP packets.\n");
1260
1261	for (i = 0; i < 512; i++) {
1262		for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++)
1263			*s = (rand() >> 13) & 0xff;
1264		pip->ip_v = IPVERSION;
1265		bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst,
1266		      sizeof(struct in_addr));
1267		pip->ip_sum = 0;
1268		pip->ip_len &= 0xff;
1269		(void) send_ip(nfd, mtu, pip, gwip, 0);
1270		printf("%d\r", i);
1271		fflush(stdout);
1272		PAUSE();
1273	}
1274	putchar('\n');
1275
1276	for (i = 0; i < 512; i++) {
1277		for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++)
1278			*s = (rand() >> 13) & 0xff;
1279		pip->ip_v = IPVERSION;
1280		pip->ip_off &= 0xc000;
1281		bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst,
1282		      sizeof(struct in_addr));
1283		pip->ip_sum = 0;
1284		pip->ip_len &= 0xff;
1285		(void) send_ip(nfd, mtu, pip, gwip, 0);
1286		printf("%d\r", i);
1287		fflush(stdout);
1288		PAUSE();
1289	}
1290	putchar('\n');
1291}
1292