1 /* $FreeBSD$ */ 2 3 /* 4 * Copyright (C) 2012 by Darren Reed. 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 */ 9 #if !defined(lint) 10 static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; 11 static const char rcsid[] = "@(#)$Id$"; 12 #endif 13 #include <sys/param.h> 14 #include <sys/types.h> 15 #if defined(__NetBSD__) && defined(__vax__) 16 /* 17 * XXX need to declare boolean_t for _KERNEL <sys/files.h> 18 * which ends up including <sys/device.h> for vax. See PR#32907 19 * for further details. 20 */ 21 typedef int boolean_t; 22 #endif 23 #include <sys/time.h> 24 # ifdef __NetBSD__ 25 # include <machine/lock.h> 26 # include <machine/mutex.h> 27 # endif 28 # define _KERNEL 29 # define KERNEL 30 # if !defined(solaris) 31 # include <sys/file.h> 32 # else 33 # ifdef solaris 34 # include <sys/dditypes.h> 35 # endif 36 # endif 37 # undef _KERNEL 38 # undef KERNEL 39 #if !defined(solaris) 40 # include <nlist.h> 41 # include <sys/user.h> 42 # include <sys/proc.h> 43 #endif 44 # include <kvm.h> 45 # include <sys/socket.h> 46 #if defined(solaris) 47 # include <sys/stream.h> 48 #else 49 # include <sys/socketvar.h> 50 #endif 51 #ifdef sun 52 #include <sys/systm.h> 53 #include <sys/session.h> 54 #endif 55 # include <sys/sysctl.h> 56 # include <sys/filedesc.h> 57 # include <paths.h> 58 #include <netinet/in_systm.h> 59 #include <sys/socket.h> 60 #include <net/if.h> 61 # if defined(__FreeBSD__) 62 # include "radix_ipf.h" 63 # endif 64 # if !defined(solaris) 65 # include <net/route.h> 66 # endif 67 #include <netinet/in.h> 68 #include <arpa/inet.h> 69 #include <netinet/ip.h> 70 #if defined(__SVR4) || defined(__svr4__) 71 # include <sys/sysmacros.h> 72 #endif 73 #include <stdio.h> 74 #include <unistd.h> 75 #include <stdlib.h> 76 #include <string.h> 77 # include <netinet/ip_var.h> 78 # if !defined(solaris) 79 # include <netinet/in_pcb.h> 80 # endif 81 #include "ipsend.h" 82 # include <netinet/tcp_timer.h> 83 # include <netinet/tcp_var.h> 84 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106000000) 85 # define USE_NANOSLEEP 86 #endif 87 88 89 #ifdef USE_NANOSLEEP 90 # define PAUSE() ts.tv_sec = 0; ts.tv_nsec = 10000000; \ 91 (void) nanosleep(&ts, NULL) 92 #else 93 # define PAUSE() tv.tv_sec = 0; tv.tv_usec = 10000; \ 94 (void) select(0, NULL, NULL, NULL, &tv) 95 #endif 96 97 98 void ip_test1(dev, mtu, ip, gwip, ptest) 99 char *dev; 100 int mtu; 101 ip_t *ip; 102 struct in_addr gwip; 103 int ptest; 104 { 105 #ifdef USE_NANOSLEEP 106 struct timespec ts; 107 #else 108 struct timeval tv; 109 #endif 110 udphdr_t *u; 111 int nfd, i = 0, len, id = getpid(); 112 113 IP_HL_A(ip, sizeof(*ip) >> 2); 114 IP_V_A(ip, IPVERSION); 115 ip->ip_tos = 0; 116 ip->ip_off = 0; 117 ip->ip_ttl = 60; 118 ip->ip_p = IPPROTO_UDP; 119 ip->ip_sum = 0; 120 u = (udphdr_t *)(ip + 1); 121 u->uh_sport = htons(1); 122 u->uh_dport = htons(9); 123 u->uh_sum = 0; 124 u->uh_ulen = htons(sizeof(*u) + 4); 125 ip->ip_len = sizeof(*ip) + ntohs(u->uh_ulen); 126 len = ip->ip_len; 127 128 nfd = initdevice(dev, 1); 129 if (nfd == -1) 130 return; 131 132 if (!ptest || (ptest == 1)) { 133 /* 134 * Part1: hl < len 135 */ 136 ip->ip_id = 0; 137 printf("1.1. sending packets with ip_hl < ip_len\n"); 138 for (i = 0; i < ((sizeof(*ip) + ntohs(u->uh_ulen)) >> 2); i++) { 139 IP_HL_A(ip, i >> 2); 140 (void) send_ip(nfd, 1500, ip, gwip, 1); 141 printf("%d\r", i); 142 fflush(stdout); 143 PAUSE(); 144 } 145 putchar('\n'); 146 } 147 148 if (!ptest || (ptest == 2)) { 149 /* 150 * Part2: hl > len 151 */ 152 ip->ip_id = 0; 153 printf("1.2. sending packets with ip_hl > ip_len\n"); 154 for (; i < ((sizeof(*ip) * 2 + ntohs(u->uh_ulen)) >> 2); i++) { 155 IP_HL_A(ip, i >> 2); 156 (void) send_ip(nfd, 1500, ip, gwip, 1); 157 printf("%d\r", i); 158 fflush(stdout); 159 PAUSE(); 160 } 161 putchar('\n'); 162 } 163 164 if (!ptest || (ptest == 3)) { 165 /* 166 * Part3: v < 4 167 */ 168 ip->ip_id = 0; 169 printf("1.3. ip_v < 4\n"); 170 IP_HL_A(ip, sizeof(*ip) >> 2); 171 for (i = 0; i < 4; i++) { 172 IP_V_A(ip, i); 173 (void) send_ip(nfd, 1500, ip, gwip, 1); 174 printf("%d\r", i); 175 fflush(stdout); 176 PAUSE(); 177 } 178 putchar('\n'); 179 } 180 181 if (!ptest || (ptest == 4)) { 182 /* 183 * Part4: v > 4 184 */ 185 ip->ip_id = 0; 186 printf("1.4. ip_v > 4\n"); 187 for (i = 5; i < 16; i++) { 188 IP_V_A(ip, i); 189 (void) send_ip(nfd, 1500, ip, gwip, 1); 190 printf("%d\r", i); 191 fflush(stdout); 192 PAUSE(); 193 } 194 putchar('\n'); 195 } 196 197 if (!ptest || (ptest == 5)) { 198 /* 199 * Part5: len < packet 200 */ 201 ip->ip_id = 0; 202 IP_V_A(ip, IPVERSION); 203 i = ip->ip_len + 1; 204 printf("1.5.0 ip_len < packet size (size++, long packets)\n"); 205 for (; i < (ip->ip_len * 2); i++) { 206 ip->ip_id = htons(id++); 207 ip->ip_sum = 0; 208 ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); 209 (void) send_ether(nfd, (char *)ip, i, gwip); 210 printf("%d\r", i); 211 fflush(stdout); 212 PAUSE(); 213 } 214 putchar('\n'); 215 printf("1.5.1 ip_len < packet size (ip_len-, short packets)\n"); 216 for (i = len; i > 0; i--) { 217 ip->ip_id = htons(id++); 218 ip->ip_len = i; 219 ip->ip_sum = 0; 220 ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); 221 (void) send_ether(nfd, (char *)ip, len, gwip); 222 printf("%d\r", i); 223 fflush(stdout); 224 PAUSE(); 225 } 226 putchar('\n'); 227 } 228 229 if (!ptest || (ptest == 6)) { 230 /* 231 * Part6: len > packet 232 */ 233 ip->ip_id = 0; 234 printf("1.6.0 ip_len > packet size (increase ip_len)\n"); 235 for (i = len + 1; i < (len * 2); i++) { 236 ip->ip_id = htons(id++); 237 ip->ip_len = i; 238 ip->ip_sum = 0; 239 ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); 240 (void) send_ether(nfd, (char *)ip, len, gwip); 241 printf("%d\r", i); 242 fflush(stdout); 243 PAUSE(); 244 } 245 putchar('\n'); 246 ip->ip_len = len; 247 printf("1.6.1 ip_len > packet size (size--, short packets)\n"); 248 for (i = len; i > 0; i--) { 249 ip->ip_id = htons(id++); 250 ip->ip_sum = 0; 251 ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); 252 (void) send_ether(nfd, (char *)ip, i, gwip); 253 printf("%d\r", i); 254 fflush(stdout); 255 PAUSE(); 256 } 257 putchar('\n'); 258 } 259 260 if (!ptest || (ptest == 7)) { 261 /* 262 * Part7: 0 length fragment 263 */ 264 printf("1.7.0 Zero length fragments (ip_off = 0x2000)\n"); 265 ip->ip_id = 0; 266 ip->ip_len = sizeof(*ip); 267 ip->ip_off = htons(IP_MF); 268 (void) send_ip(nfd, mtu, ip, gwip, 1); 269 fflush(stdout); 270 PAUSE(); 271 272 printf("1.7.1 Zero length fragments (ip_off = 0x3000)\n"); 273 ip->ip_id = 0; 274 ip->ip_len = sizeof(*ip); 275 ip->ip_off = htons(IP_MF); 276 (void) send_ip(nfd, mtu, ip, gwip, 1); 277 fflush(stdout); 278 PAUSE(); 279 280 printf("1.7.2 Zero length fragments (ip_off = 0xa000)\n"); 281 ip->ip_id = 0; 282 ip->ip_len = sizeof(*ip); 283 ip->ip_off = htons(0xa000); 284 (void) send_ip(nfd, mtu, ip, gwip, 1); 285 fflush(stdout); 286 PAUSE(); 287 288 printf("1.7.3 Zero length fragments (ip_off = 0x0100)\n"); 289 ip->ip_id = 0; 290 ip->ip_len = sizeof(*ip); 291 ip->ip_off = htons(0x0100); 292 (void) send_ip(nfd, mtu, ip, gwip, 1); 293 fflush(stdout); 294 PAUSE(); 295 } 296 297 if (!ptest || (ptest == 8)) { 298 struct timeval tv; 299 300 gettimeofday(&tv, NULL); 301 srand(tv.tv_sec ^ getpid() ^ tv.tv_usec); 302 /* 303 * Part8.1: 63k packet + 1k fragment at offset 0x1ffe 304 * Mark it as being ICMP (so it doesn't get junked), but 305 * don't bother about the ICMP header, we're not worrying 306 * about that here. 307 */ 308 ip->ip_p = IPPROTO_ICMP; 309 ip->ip_off = htons(IP_MF); 310 u->uh_dport = htons(9); 311 ip->ip_id = htons(id++); 312 printf("1.8.1 63k packet + 1k fragment at offset 0x1ffe\n"); 313 ip->ip_len = 768 + 20 + 8; 314 (void) send_ip(nfd, mtu, ip, gwip, 1); 315 printf("%d\r", i); 316 317 ip->ip_len = MIN(768 + 20, mtu - 68); 318 i = 512; 319 for (; i < (63 * 1024 + 768); i += 768) { 320 ip->ip_off = htons(IP_MF | (i >> 3)); 321 (void) send_ip(nfd, mtu, ip, gwip, 1); 322 printf("%d\r", i); 323 fflush(stdout); 324 PAUSE(); 325 } 326 ip->ip_len = 896 + 20; 327 ip->ip_off = htons(i >> 3); 328 (void) send_ip(nfd, mtu, ip, gwip, 1); 329 printf("%d\r", i); 330 putchar('\n'); 331 fflush(stdout); 332 333 /* 334 * Part8.2: 63k packet + 1k fragment at offset 0x1ffe 335 * Mark it as being ICMP (so it doesn't get junked), but 336 * don't bother about the ICMP header, we're not worrying 337 * about that here. (Lossage here) 338 */ 339 ip->ip_p = IPPROTO_ICMP; 340 ip->ip_off = htons(IP_MF); 341 u->uh_dport = htons(9); 342 ip->ip_id = htons(id++); 343 printf("1.8.2 63k packet + 1k fragment at offset 0x1ffe\n"); 344 ip->ip_len = 768 + 20 + 8; 345 if ((rand() & 0x1f) != 0) { 346 (void) send_ip(nfd, mtu, ip, gwip, 1); 347 printf("%d\r", i); 348 } else 349 printf("skip 0\n"); 350 351 ip->ip_len = MIN(768 + 20, mtu - 68); 352 i = 512; 353 for (; i < (63 * 1024 + 768); i += 768) { 354 ip->ip_off = htons(IP_MF | (i >> 3)); 355 if ((rand() & 0x1f) != 0) { 356 (void) send_ip(nfd, mtu, ip, gwip, 1); 357 printf("%d\r", i); 358 } else 359 printf("skip %d\n", i); 360 fflush(stdout); 361 PAUSE(); 362 } 363 ip->ip_len = 896 + 20; 364 ip->ip_off = htons(i >> 3); 365 if ((rand() & 0x1f) != 0) { 366 (void) send_ip(nfd, mtu, ip, gwip, 1); 367 printf("%d\r", i); 368 } else 369 printf("skip\n"); 370 putchar('\n'); 371 fflush(stdout); 372 373 /* 374 * Part8.3: 33k packet - test for not dealing with -ve length 375 * Mark it as being ICMP (so it doesn't get junked), but 376 * don't bother about the ICMP header, we're not worrying 377 * about that here. 378 */ 379 ip->ip_p = IPPROTO_ICMP; 380 ip->ip_off = htons(IP_MF); 381 u->uh_dport = htons(9); 382 ip->ip_id = htons(id++); 383 printf("1.8.3 33k packet\n"); 384 ip->ip_len = 768 + 20 + 8; 385 (void) send_ip(nfd, mtu, ip, gwip, 1); 386 printf("%d\r", i); 387 388 ip->ip_len = MIN(768 + 20, mtu - 68); 389 i = 512; 390 for (; i < (32 * 1024 + 768); i += 768) { 391 ip->ip_off = htons(IP_MF | (i >> 3)); 392 (void) send_ip(nfd, mtu, ip, gwip, 1); 393 printf("%d\r", i); 394 fflush(stdout); 395 PAUSE(); 396 } 397 ip->ip_len = 896 + 20; 398 ip->ip_off = htons(i >> 3); 399 (void) send_ip(nfd, mtu, ip, gwip, 1); 400 printf("%d\r", i); 401 putchar('\n'); 402 fflush(stdout); 403 } 404 405 ip->ip_len = len; 406 ip->ip_off = 0; 407 if (!ptest || (ptest == 9)) { 408 /* 409 * Part9: off & 0x8000 == 0x8000 410 */ 411 ip->ip_id = 0; 412 ip->ip_off = htons(0x8000); 413 printf("1.9. ip_off & 0x8000 == 0x8000\n"); 414 (void) send_ip(nfd, mtu, ip, gwip, 1); 415 fflush(stdout); 416 PAUSE(); 417 } 418 419 ip->ip_off = 0; 420 421 if (!ptest || (ptest == 10)) { 422 /* 423 * Part10: ttl = 255 424 */ 425 ip->ip_id = 0; 426 ip->ip_ttl = 255; 427 printf("1.10.0 ip_ttl = 255\n"); 428 (void) send_ip(nfd, mtu, ip, gwip, 1); 429 fflush(stdout); 430 PAUSE(); 431 432 ip->ip_ttl = 128; 433 printf("1.10.1 ip_ttl = 128\n"); 434 (void) send_ip(nfd, mtu, ip, gwip, 1); 435 fflush(stdout); 436 PAUSE(); 437 438 ip->ip_ttl = 0; 439 printf("1.10.2 ip_ttl = 0\n"); 440 (void) send_ip(nfd, mtu, ip, gwip, 1); 441 fflush(stdout); 442 PAUSE(); 443 } 444 445 (void) close(nfd); 446 } 447 448 449 void ip_test2(dev, mtu, ip, gwip, ptest) 450 char *dev; 451 int mtu; 452 ip_t *ip; 453 struct in_addr gwip; 454 int ptest; 455 { 456 #ifdef USE_NANOSLEEP 457 struct timespec ts; 458 #else 459 struct timeval tv; 460 #endif 461 int nfd; 462 u_char *s; 463 464 465 nfd = initdevice(dev, 1); 466 if (nfd == -1) 467 return; 468 469 IP_HL_A(ip, 6); 470 ip->ip_len = IP_HL(ip) << 2; 471 s = (u_char *)(ip + 1); 472 s[IPOPT_OPTVAL] = IPOPT_NOP; 473 s++; 474 if (!ptest || (ptest == 1)) { 475 /* 476 * Test 1: option length > packet length, 477 * header length == packet length 478 */ 479 s[IPOPT_OPTVAL] = IPOPT_TS; 480 s[IPOPT_OLEN] = 4; 481 s[IPOPT_OFFSET] = IPOPT_MINOFF; 482 ip->ip_p = IPPROTO_IP; 483 printf("2.1 option length > packet length\n"); 484 (void) send_ip(nfd, mtu, ip, gwip, 1); 485 fflush(stdout); 486 PAUSE(); 487 } 488 489 IP_HL_A(ip, 7); 490 ip->ip_len = IP_HL(ip) << 2; 491 if (!ptest || (ptest == 1)) { 492 /* 493 * Test 2: options have length = 0 494 */ 495 printf("2.2.1 option length = 0, RR\n"); 496 s[IPOPT_OPTVAL] = IPOPT_RR; 497 s[IPOPT_OLEN] = 0; 498 (void) send_ip(nfd, mtu, ip, gwip, 1); 499 fflush(stdout); 500 PAUSE(); 501 502 printf("2.2.2 option length = 0, TS\n"); 503 s[IPOPT_OPTVAL] = IPOPT_TS; 504 s[IPOPT_OLEN] = 0; 505 (void) send_ip(nfd, mtu, ip, gwip, 1); 506 fflush(stdout); 507 PAUSE(); 508 509 printf("2.2.3 option length = 0, SECURITY\n"); 510 s[IPOPT_OPTVAL] = IPOPT_SECURITY; 511 s[IPOPT_OLEN] = 0; 512 (void) send_ip(nfd, mtu, ip, gwip, 1); 513 fflush(stdout); 514 PAUSE(); 515 516 printf("2.2.4 option length = 0, LSRR\n"); 517 s[IPOPT_OPTVAL] = IPOPT_LSRR; 518 s[IPOPT_OLEN] = 0; 519 (void) send_ip(nfd, mtu, ip, gwip, 1); 520 fflush(stdout); 521 PAUSE(); 522 523 printf("2.2.5 option length = 0, SATID\n"); 524 s[IPOPT_OPTVAL] = IPOPT_SATID; 525 s[IPOPT_OLEN] = 0; 526 (void) send_ip(nfd, mtu, ip, gwip, 1); 527 fflush(stdout); 528 PAUSE(); 529 530 printf("2.2.6 option length = 0, SSRR\n"); 531 s[IPOPT_OPTVAL] = IPOPT_SSRR; 532 s[IPOPT_OLEN] = 0; 533 (void) send_ip(nfd, mtu, ip, gwip, 1); 534 fflush(stdout); 535 PAUSE(); 536 } 537 538 (void) close(nfd); 539 } 540 541 542 /* 543 * test 3 (ICMP) 544 */ 545 void ip_test3(dev, mtu, ip, gwip, ptest) 546 char *dev; 547 int mtu; 548 ip_t *ip; 549 struct in_addr gwip; 550 int ptest; 551 { 552 static int ict1[10] = { 8, 9, 10, 13, 14, 15, 16, 17, 18, 0 }; 553 static int ict2[8] = { 3, 9, 10, 13, 14, 17, 18, 0 }; 554 #ifdef USE_NANOSLEEP 555 struct timespec ts; 556 #else 557 struct timeval tv; 558 #endif 559 struct icmp *icp; 560 int nfd, i; 561 562 IP_HL_A(ip, sizeof(*ip) >> 2); 563 IP_V_A(ip, IPVERSION); 564 ip->ip_tos = 0; 565 ip->ip_off = 0; 566 ip->ip_ttl = 60; 567 ip->ip_p = IPPROTO_ICMP; 568 ip->ip_sum = 0; 569 ip->ip_len = sizeof(*ip) + sizeof(*icp); 570 icp = (struct icmp *)((char *)ip + (IP_HL(ip) << 2)); 571 572 nfd = initdevice(dev, 1); 573 if (nfd == -1) 574 return; 575 576 if (!ptest || (ptest == 1)) { 577 /* 578 * Type 0 - 31, 255, code = 0 579 */ 580 bzero((char *)icp, sizeof(*icp)); 581 for (i = 0; i < 32; i++) { 582 icp->icmp_type = i; 583 (void) send_icmp(nfd, mtu, ip, gwip); 584 PAUSE(); 585 printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, i); 586 } 587 icp->icmp_type = 255; 588 (void) send_icmp(nfd, mtu, ip, gwip); 589 PAUSE(); 590 printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, 255); 591 putchar('\n'); 592 } 593 594 if (!ptest || (ptest == 2)) { 595 /* 596 * Type 3, code = 0 - 31 597 */ 598 icp->icmp_type = 3; 599 for (i = 0; i < 32; i++) { 600 icp->icmp_code = i; 601 (void) send_icmp(nfd, mtu, ip, gwip); 602 PAUSE(); 603 printf("3.2.%d ICMP type 3 code %d (all 0's)\r", i, i); 604 } 605 } 606 607 if (!ptest || (ptest == 3)) { 608 /* 609 * Type 4, code = 0,127,128,255 610 */ 611 icp->icmp_type = 4; 612 icp->icmp_code = 0; 613 (void) send_icmp(nfd, mtu, ip, gwip); 614 PAUSE(); 615 printf("3.3.1 ICMP type 4 code 0 (all 0's)\r"); 616 icp->icmp_code = 127; 617 (void) send_icmp(nfd, mtu, ip, gwip); 618 PAUSE(); 619 printf("3.3.2 ICMP type 4 code 127 (all 0's)\r"); 620 icp->icmp_code = 128; 621 (void) send_icmp(nfd, mtu, ip, gwip); 622 PAUSE(); 623 printf("3.3.3 ICMP type 4 code 128 (all 0's)\r"); 624 icp->icmp_code = 255; 625 (void) send_icmp(nfd, mtu, ip, gwip); 626 PAUSE(); 627 printf("3.3.4 ICMP type 4 code 255 (all 0's)\r"); 628 } 629 630 if (!ptest || (ptest == 4)) { 631 /* 632 * Type 5, code = 0,127,128,255 633 */ 634 icp->icmp_type = 5; 635 icp->icmp_code = 0; 636 (void) send_icmp(nfd, mtu, ip, gwip); 637 PAUSE(); 638 printf("3.4.1 ICMP type 5 code 0 (all 0's)\r"); 639 icp->icmp_code = 127; 640 (void) send_icmp(nfd, mtu, ip, gwip); 641 PAUSE(); 642 printf("3.4.2 ICMP type 5 code 127 (all 0's)\r"); 643 icp->icmp_code = 128; 644 (void) send_icmp(nfd, mtu, ip, gwip); 645 PAUSE(); 646 printf("3.4.3 ICMP type 5 code 128 (all 0's)\r"); 647 icp->icmp_code = 255; 648 (void) send_icmp(nfd, mtu, ip, gwip); 649 PAUSE(); 650 printf("3.4.4 ICMP type 5 code 255 (all 0's)\r"); 651 } 652 653 if (!ptest || (ptest == 5)) { 654 /* 655 * Type 8-10;13-18, code - 0,127,128,255 656 */ 657 for (i = 0; ict1[i]; i++) { 658 icp->icmp_type = ict1[i]; 659 icp->icmp_code = 0; 660 (void) send_icmp(nfd, mtu, ip, gwip); 661 PAUSE(); 662 printf("3.5.%d ICMP type 5 code 0 (all 0's)\r", 663 i * 4); 664 icp->icmp_code = 127; 665 (void) send_icmp(nfd, mtu, ip, gwip); 666 PAUSE(); 667 printf("3.5.%d ICMP type 5 code 127 (all 0's)\r", 668 i * 4 + 1); 669 icp->icmp_code = 128; 670 (void) send_icmp(nfd, mtu, ip, gwip); 671 PAUSE(); 672 printf("3.5.%d ICMP type 5 code 128 (all 0's)\r", 673 i * 4 + 2); 674 icp->icmp_code = 255; 675 (void) send_icmp(nfd, mtu, ip, gwip); 676 PAUSE(); 677 printf("3.5.%d ICMP type 5 code 255 (all 0's)\r", 678 i * 4 + 3); 679 } 680 putchar('\n'); 681 } 682 683 if (!ptest || (ptest == 6)) { 684 /* 685 * Type 12, code - 0,127,128,129,255 686 */ 687 icp->icmp_type = 12; 688 icp->icmp_code = 0; 689 (void) send_icmp(nfd, mtu, ip, gwip); 690 PAUSE(); 691 printf("3.6.1 ICMP type 12 code 0 (all 0's)\r"); 692 icp->icmp_code = 127; 693 (void) send_icmp(nfd, mtu, ip, gwip); 694 PAUSE(); 695 printf("3.6.2 ICMP type 12 code 127 (all 0's)\r"); 696 icp->icmp_code = 128; 697 (void) send_icmp(nfd, mtu, ip, gwip); 698 PAUSE(); 699 printf("3.6.3 ICMP type 12 code 128 (all 0's)\r"); 700 icp->icmp_code = 129; 701 (void) send_icmp(nfd, mtu, ip, gwip); 702 PAUSE(); 703 printf("3.6.4 ICMP type 12 code 129 (all 0's)\r"); 704 icp->icmp_code = 255; 705 (void) send_icmp(nfd, mtu, ip, gwip); 706 PAUSE(); 707 printf("3.6.5 ICMP type 12 code 255 (all 0's)\r"); 708 putchar('\n'); 709 } 710 711 if (!ptest || (ptest == 7)) { 712 /* 713 * Type 3;9-10;13-14;17-18 - shorter packets 714 */ 715 ip->ip_len = sizeof(*ip) + sizeof(*icp) / 2; 716 for (i = 0; ict2[i]; i++) { 717 icp->icmp_type = ict1[i]; 718 icp->icmp_code = 0; 719 (void) send_icmp(nfd, mtu, ip, gwip); 720 PAUSE(); 721 printf("3.5.%d ICMP type %d code 0 (all 0's)\r", 722 i * 4, icp->icmp_type); 723 icp->icmp_code = 127; 724 (void) send_icmp(nfd, mtu, ip, gwip); 725 PAUSE(); 726 printf("3.5.%d ICMP type %d code 127 (all 0's)\r", 727 i * 4 + 1, icp->icmp_type); 728 icp->icmp_code = 128; 729 (void) send_icmp(nfd, mtu, ip, gwip); 730 PAUSE(); 731 printf("3.5.%d ICMP type %d code 128 (all 0's)\r", 732 i * 4 + 2, icp->icmp_type); 733 icp->icmp_code = 255; 734 (void) send_icmp(nfd, mtu, ip, gwip); 735 PAUSE(); 736 printf("3.5.%d ICMP type %d code 127 (all 0's)\r", 737 i * 4 + 3, icp->icmp_type); 738 } 739 putchar('\n'); 740 } 741 } 742 743 744 /* Perform test 4 (UDP) */ 745 746 void ip_test4(dev, mtu, ip, gwip, ptest) 747 char *dev; 748 int mtu; 749 ip_t *ip; 750 struct in_addr gwip; 751 int ptest; 752 { 753 #ifdef USE_NANOSLEEP 754 struct timespec ts; 755 #else 756 struct timeval tv; 757 #endif 758 udphdr_t *u; 759 int nfd, i; 760 761 762 IP_HL_A(ip, sizeof(*ip) >> 2); 763 IP_V_A(ip, IPVERSION); 764 ip->ip_tos = 0; 765 ip->ip_off = 0; 766 ip->ip_ttl = 60; 767 ip->ip_p = IPPROTO_UDP; 768 ip->ip_sum = 0; 769 u = (udphdr_t *)((char *)ip + (IP_HL(ip) << 2)); 770 u->uh_sport = htons(1); 771 u->uh_dport = htons(1); 772 u->uh_ulen = htons(sizeof(*u) + 4); 773 774 nfd = initdevice(dev, 1); 775 if (nfd == -1) 776 return; 777 778 if (!ptest || (ptest == 1)) { 779 /* 780 * Test 1. ulen > packet 781 */ 782 u->uh_ulen = htons(sizeof(*u) + 4); 783 ip->ip_len = (IP_HL(ip) << 2) + ntohs(u->uh_ulen); 784 printf("4.1 UDP uh_ulen > packet size - short packets\n"); 785 for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) { 786 u->uh_ulen = htons(i); 787 (void) send_udp(nfd, 1500, ip, gwip); 788 printf("%d\r", i); 789 fflush(stdout); 790 PAUSE(); 791 } 792 putchar('\n'); 793 } 794 795 if (!ptest || (ptest == 2)) { 796 /* 797 * Test 2. ulen < packet 798 */ 799 u->uh_ulen = htons(sizeof(*u) + 4); 800 ip->ip_len = (IP_HL(ip) << 2) + ntohs(u->uh_ulen); 801 printf("4.2 UDP uh_ulen < packet size - short packets\n"); 802 for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) { 803 ip->ip_len = i; 804 (void) send_udp(nfd, 1500, ip, gwip); 805 printf("%d\r", i); 806 fflush(stdout); 807 PAUSE(); 808 } 809 putchar('\n'); 810 } 811 812 if (!ptest || (ptest == 3)) { 813 /* 814 * Test 3: sport = 0, sport = 1, sport = 32767 815 * sport = 32768, sport = 65535 816 */ 817 u->uh_ulen = sizeof(*u) + 4; 818 ip->ip_len = (IP_HL(ip) << 2) + ntohs(u->uh_ulen); 819 printf("4.3.1 UDP sport = 0\n"); 820 u->uh_sport = 0; 821 (void) send_udp(nfd, 1500, ip, gwip); 822 printf("0\n"); 823 fflush(stdout); 824 PAUSE(); 825 printf("4.3.2 UDP sport = 1\n"); 826 u->uh_sport = htons(1); 827 (void) send_udp(nfd, 1500, ip, gwip); 828 printf("1\n"); 829 fflush(stdout); 830 PAUSE(); 831 printf("4.3.3 UDP sport = 32767\n"); 832 u->uh_sport = htons(32767); 833 (void) send_udp(nfd, 1500, ip, gwip); 834 printf("32767\n"); 835 fflush(stdout); 836 PAUSE(); 837 printf("4.3.4 UDP sport = 32768\n"); 838 u->uh_sport = htons(32768); 839 (void) send_udp(nfd, 1500, ip, gwip); 840 printf("32768\n"); 841 putchar('\n'); 842 fflush(stdout); 843 PAUSE(); 844 printf("4.3.5 UDP sport = 65535\n"); 845 u->uh_sport = htons(65535); 846 (void) send_udp(nfd, 1500, ip, gwip); 847 printf("65535\n"); 848 fflush(stdout); 849 PAUSE(); 850 } 851 852 if (!ptest || (ptest == 4)) { 853 /* 854 * Test 4: dport = 0, dport = 1, dport = 32767 855 * dport = 32768, dport = 65535 856 */ 857 u->uh_ulen = ntohs(sizeof(*u) + 4); 858 u->uh_sport = htons(1); 859 ip->ip_len = (IP_HL(ip) << 2) + ntohs(u->uh_ulen); 860 printf("4.4.1 UDP dport = 0\n"); 861 u->uh_dport = 0; 862 (void) send_udp(nfd, 1500, ip, gwip); 863 printf("0\n"); 864 fflush(stdout); 865 PAUSE(); 866 printf("4.4.2 UDP dport = 1\n"); 867 u->uh_dport = htons(1); 868 (void) send_udp(nfd, 1500, ip, gwip); 869 printf("1\n"); 870 fflush(stdout); 871 PAUSE(); 872 printf("4.4.3 UDP dport = 32767\n"); 873 u->uh_dport = htons(32767); 874 (void) send_udp(nfd, 1500, ip, gwip); 875 printf("32767\n"); 876 fflush(stdout); 877 PAUSE(); 878 printf("4.4.4 UDP dport = 32768\n"); 879 u->uh_dport = htons(32768); 880 (void) send_udp(nfd, 1500, ip, gwip); 881 printf("32768\n"); 882 fflush(stdout); 883 PAUSE(); 884 printf("4.4.5 UDP dport = 65535\n"); 885 u->uh_dport = htons(65535); 886 (void) send_udp(nfd, 1500, ip, gwip); 887 printf("65535\n"); 888 fflush(stdout); 889 PAUSE(); 890 } 891 892 if (!ptest || (ptest == 5)) { 893 /* 894 * Test 5: sizeof(ip_t) <= MTU <= sizeof(udphdr_t) + 895 * sizeof(ip_t) 896 */ 897 printf("4.5 UDP 20 <= MTU <= 32\n"); 898 for (i = sizeof(*ip); i <= ntohs(u->uh_ulen); i++) { 899 (void) send_udp(nfd, i, ip, gwip); 900 printf("%d\r", i); 901 fflush(stdout); 902 PAUSE(); 903 } 904 putchar('\n'); 905 } 906 } 907 908 909 /* Perform test 5 (TCP) */ 910 911 void ip_test5(dev, mtu, ip, gwip, ptest) 912 char *dev; 913 int mtu; 914 ip_t *ip; 915 struct in_addr gwip; 916 int ptest; 917 { 918 #ifdef USE_NANOSLEEP 919 struct timespec ts; 920 #else 921 struct timeval tv; 922 #endif 923 tcphdr_t *t; 924 int nfd, i; 925 926 t = (tcphdr_t *)((char *)ip + (IP_HL(ip) << 2)); 927 t->th_x2 = 0; 928 TCP_OFF_A(t, 0); 929 t->th_sport = htons(1); 930 t->th_dport = htons(1); 931 t->th_win = htons(4096); 932 t->th_urp = 0; 933 t->th_sum = 0; 934 t->th_seq = htonl(1); 935 t->th_ack = 0; 936 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); 937 938 nfd = initdevice(dev, 1); 939 if (nfd == -1) 940 return; 941 942 if (!ptest || (ptest == 1)) { 943 /* 944 * Test 1: flags variations, 0 - 3f 945 */ 946 TCP_OFF_A(t, sizeof(*t) >> 2); 947 printf("5.1 Test TCP flag combinations\n"); 948 for (i = 0; i <= (TH_URG|TH_ACK|TH_PUSH|TH_RST|TH_SYN|TH_FIN); 949 i++) { 950 t->th_flags = i; 951 (void) send_tcp(nfd, mtu, ip, gwip); 952 printf("%d\r", i); 953 fflush(stdout); 954 PAUSE(); 955 } 956 putchar('\n'); 957 } 958 959 if (!ptest || (ptest == 2)) { 960 t->th_flags = TH_SYN; 961 /* 962 * Test 2: seq = 0, seq = 1, seq = 0x7fffffff, seq=0x80000000, 963 * seq = 0xa000000, seq = 0xffffffff 964 */ 965 printf("5.2.1 TCP seq = 0\n"); 966 t->th_seq = htonl(0); 967 (void) send_tcp(nfd, mtu, ip, gwip); 968 fflush(stdout); 969 PAUSE(); 970 971 printf("5.2.2 TCP seq = 1\n"); 972 t->th_seq = htonl(1); 973 (void) send_tcp(nfd, mtu, ip, gwip); 974 fflush(stdout); 975 PAUSE(); 976 977 printf("5.2.3 TCP seq = 0x7fffffff\n"); 978 t->th_seq = htonl(0x7fffffff); 979 (void) send_tcp(nfd, mtu, ip, gwip); 980 fflush(stdout); 981 PAUSE(); 982 983 printf("5.2.4 TCP seq = 0x80000000\n"); 984 t->th_seq = htonl(0x80000000); 985 (void) send_tcp(nfd, mtu, ip, gwip); 986 fflush(stdout); 987 PAUSE(); 988 989 printf("5.2.5 TCP seq = 0xc0000000\n"); 990 t->th_seq = htonl(0xc0000000); 991 (void) send_tcp(nfd, mtu, ip, gwip); 992 fflush(stdout); 993 PAUSE(); 994 995 printf("5.2.6 TCP seq = 0xffffffff\n"); 996 t->th_seq = htonl(0xffffffff); 997 (void) send_tcp(nfd, mtu, ip, gwip); 998 fflush(stdout); 999 PAUSE(); 1000 } 1001 1002 if (!ptest || (ptest == 3)) { 1003 t->th_flags = TH_ACK; 1004 /* 1005 * Test 3: ack = 0, ack = 1, ack = 0x7fffffff, ack = 0x8000000 1006 * ack = 0xa000000, ack = 0xffffffff 1007 */ 1008 printf("5.3.1 TCP ack = 0\n"); 1009 t->th_ack = 0; 1010 (void) send_tcp(nfd, mtu, ip, gwip); 1011 fflush(stdout); 1012 PAUSE(); 1013 1014 printf("5.3.2 TCP ack = 1\n"); 1015 t->th_ack = htonl(1); 1016 (void) send_tcp(nfd, mtu, ip, gwip); 1017 fflush(stdout); 1018 PAUSE(); 1019 1020 printf("5.3.3 TCP ack = 0x7fffffff\n"); 1021 t->th_ack = htonl(0x7fffffff); 1022 (void) send_tcp(nfd, mtu, ip, gwip); 1023 fflush(stdout); 1024 PAUSE(); 1025 1026 printf("5.3.4 TCP ack = 0x80000000\n"); 1027 t->th_ack = htonl(0x80000000); 1028 (void) send_tcp(nfd, mtu, ip, gwip); 1029 fflush(stdout); 1030 PAUSE(); 1031 1032 printf("5.3.5 TCP ack = 0xc0000000\n"); 1033 t->th_ack = htonl(0xc0000000); 1034 (void) send_tcp(nfd, mtu, ip, gwip); 1035 fflush(stdout); 1036 PAUSE(); 1037 1038 printf("5.3.6 TCP ack = 0xffffffff\n"); 1039 t->th_ack = htonl(0xffffffff); 1040 (void) send_tcp(nfd, mtu, ip, gwip); 1041 fflush(stdout); 1042 PAUSE(); 1043 } 1044 1045 if (!ptest || (ptest == 4)) { 1046 t->th_flags = TH_SYN; 1047 /* 1048 * Test 4: win = 0, win = 32768, win = 65535 1049 */ 1050 printf("5.4.1 TCP win = 0\n"); 1051 t->th_seq = htonl(0); 1052 (void) send_tcp(nfd, mtu, ip, gwip); 1053 fflush(stdout); 1054 PAUSE(); 1055 1056 printf("5.4.2 TCP win = 32768\n"); 1057 t->th_seq = htonl(0x7fff); 1058 (void) send_tcp(nfd, mtu, ip, gwip); 1059 fflush(stdout); 1060 PAUSE(); 1061 1062 printf("5.4.3 TCP win = 65535\n"); 1063 t->th_win = htons(0xffff); 1064 (void) send_tcp(nfd, mtu, ip, gwip); 1065 fflush(stdout); 1066 PAUSE(); 1067 } 1068 1069 #if !defined(linux) && !defined(__SVR4) && !defined(__svr4__) && \ 1070 !defined(__sgi) && !defined(__hpux) && !defined(__osf__) 1071 { 1072 struct tcpcb *tcbp, tcb; 1073 struct tcpiphdr ti; 1074 struct sockaddr_in sin; 1075 int fd; 1076 socklen_t slen; 1077 1078 bzero((char *)&sin, sizeof(sin)); 1079 1080 for (i = 1; i < 63; i++) { 1081 fd = socket(AF_INET, SOCK_STREAM, 0); 1082 bzero((char *)&sin, sizeof(sin)); 1083 sin.sin_addr.s_addr = ip->ip_dst.s_addr; 1084 sin.sin_port = htons(i); 1085 sin.sin_family = AF_INET; 1086 if (!connect(fd, (struct sockaddr *)&sin, sizeof(sin))) 1087 break; 1088 close(fd); 1089 } 1090 1091 if (i == 63) { 1092 printf("Couldn't open a TCP socket between ports 1 and 63\n"); 1093 printf("to host %s for test 5 and 6 - skipping.\n", 1094 inet_ntoa(ip->ip_dst)); 1095 goto skip_five_and_six; 1096 } 1097 1098 bcopy((char *)ip, (char *)&ti, sizeof(*ip)); 1099 t->th_dport = htons(i); 1100 slen = sizeof(sin); 1101 if (!getsockname(fd, (struct sockaddr *)&sin, &slen)) 1102 t->th_sport = sin.sin_port; 1103 if (!(tcbp = find_tcp(fd, &ti))) { 1104 printf("Can't find PCB\n"); 1105 goto skip_five_and_six; 1106 } 1107 KMCPY(&tcb, tcbp, sizeof(tcb)); 1108 ti.ti_win = tcb.rcv_adv; 1109 ti.ti_seq = htonl(tcb.snd_nxt - 1); 1110 ti.ti_ack = tcb.rcv_nxt; 1111 1112 if (!ptest || (ptest == 5)) { 1113 /* 1114 * Test 5: urp 1115 */ 1116 t->th_flags = TH_ACK|TH_URG; 1117 printf("5.5.1 TCP Urgent pointer, sport %hu dport %hu\n", 1118 ntohs(t->th_sport), ntohs(t->th_dport)); 1119 t->th_urp = htons(1); 1120 (void) send_tcp(nfd, mtu, ip, gwip); 1121 PAUSE(); 1122 1123 t->th_seq = htonl(tcb.snd_nxt); 1124 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t) + 1; 1125 t->th_urp = htons(0x7fff); 1126 (void) send_tcp(nfd, mtu, ip, gwip); 1127 PAUSE(); 1128 t->th_urp = htons(0x8000); 1129 (void) send_tcp(nfd, mtu, ip, gwip); 1130 PAUSE(); 1131 t->th_urp = htons(0xffff); 1132 (void) send_tcp(nfd, mtu, ip, gwip); 1133 PAUSE(); 1134 t->th_urp = 0; 1135 t->th_flags &= ~TH_URG; 1136 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); 1137 } 1138 1139 if (!ptest || (ptest == 6)) { 1140 /* 1141 * Test 6: data offset, off = 0, off is inside, off is outside 1142 */ 1143 t->th_flags = TH_ACK; 1144 printf("5.6.1 TCP off = 1-15, len = 40\n"); 1145 for (i = 1; i < 16; i++) { 1146 TCP_OFF_A(t, ntohs(i)); 1147 (void) send_tcp(nfd, mtu, ip, gwip); 1148 printf("%d\r", i); 1149 fflush(stdout); 1150 PAUSE(); 1151 } 1152 putchar('\n'); 1153 ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); 1154 } 1155 1156 (void) close(fd); 1157 } 1158 skip_five_and_six: 1159 #endif 1160 t->th_seq = htonl(1); 1161 t->th_ack = htonl(1); 1162 TCP_OFF_A(t, 0); 1163 1164 if (!ptest || (ptest == 7)) { 1165 t->th_flags = TH_SYN; 1166 /* 1167 * Test 7: sport = 0, sport = 1, sport = 32767 1168 * sport = 32768, sport = 65535 1169 */ 1170 printf("5.7.1 TCP sport = 0\n"); 1171 t->th_sport = 0; 1172 (void) send_tcp(nfd, mtu, ip, gwip); 1173 fflush(stdout); 1174 PAUSE(); 1175 1176 printf("5.7.2 TCP sport = 1\n"); 1177 t->th_sport = htons(1); 1178 (void) send_tcp(nfd, mtu, ip, gwip); 1179 fflush(stdout); 1180 PAUSE(); 1181 1182 printf("5.7.3 TCP sport = 32767\n"); 1183 t->th_sport = htons(32767); 1184 (void) send_tcp(nfd, mtu, ip, gwip); 1185 fflush(stdout); 1186 PAUSE(); 1187 1188 printf("5.7.4 TCP sport = 32768\n"); 1189 t->th_sport = htons(32768); 1190 (void) send_tcp(nfd, mtu, ip, gwip); 1191 fflush(stdout); 1192 PAUSE(); 1193 1194 printf("5.7.5 TCP sport = 65535\n"); 1195 t->th_sport = htons(65535); 1196 (void) send_tcp(nfd, mtu, ip, gwip); 1197 fflush(stdout); 1198 PAUSE(); 1199 } 1200 1201 if (!ptest || (ptest == 8)) { 1202 t->th_sport = htons(1); 1203 t->th_flags = TH_SYN; 1204 /* 1205 * Test 8: dport = 0, dport = 1, dport = 32767 1206 * dport = 32768, dport = 65535 1207 */ 1208 printf("5.8.1 TCP dport = 0\n"); 1209 t->th_dport = 0; 1210 (void) send_tcp(nfd, mtu, ip, gwip); 1211 fflush(stdout); 1212 PAUSE(); 1213 1214 printf("5.8.2 TCP dport = 1\n"); 1215 t->th_dport = htons(1); 1216 (void) send_tcp(nfd, mtu, ip, gwip); 1217 fflush(stdout); 1218 PAUSE(); 1219 1220 printf("5.8.3 TCP dport = 32767\n"); 1221 t->th_dport = htons(32767); 1222 (void) send_tcp(nfd, mtu, ip, gwip); 1223 fflush(stdout); 1224 PAUSE(); 1225 1226 printf("5.8.4 TCP dport = 32768\n"); 1227 t->th_dport = htons(32768); 1228 (void) send_tcp(nfd, mtu, ip, gwip); 1229 fflush(stdout); 1230 PAUSE(); 1231 1232 printf("5.8.5 TCP dport = 65535\n"); 1233 t->th_dport = htons(65535); 1234 (void) send_tcp(nfd, mtu, ip, gwip); 1235 fflush(stdout); 1236 PAUSE(); 1237 } 1238 1239 /* LAND attack - self connect, so make src & dst ip/port the same */ 1240 if (!ptest || (ptest == 9)) { 1241 printf("5.9 TCP LAND attack. sport = 25, dport = 25\n"); 1242 /* chose SMTP port 25 */ 1243 t->th_sport = htons(25); 1244 t->th_dport = htons(25); 1245 t->th_flags = TH_SYN; 1246 ip->ip_src = ip->ip_dst; 1247 (void) send_tcp(nfd, mtu, ip, gwip); 1248 fflush(stdout); 1249 PAUSE(); 1250 } 1251 1252 /* TCP options header checking */ 1253 /* 0 length options, etc */ 1254 } 1255 1256 1257 /* Perform test 6 (exhaust mbuf test) */ 1258 1259 void ip_test6(dev, mtu, ip, gwip, ptest) 1260 char *dev; 1261 int mtu; 1262 ip_t *ip; 1263 struct in_addr gwip; 1264 int ptest; 1265 { 1266 #ifdef USE_NANOSLEEP 1267 struct timespec ts; 1268 #else 1269 struct timeval tv; 1270 #endif 1271 udphdr_t *u; 1272 int nfd, i, j, k; 1273 1274 IP_V_A(ip, IPVERSION); 1275 ip->ip_tos = 0; 1276 ip->ip_off = 0; 1277 ip->ip_ttl = 60; 1278 ip->ip_p = IPPROTO_UDP; 1279 ip->ip_sum = 0; 1280 u = (udphdr_t *)(ip + 1); 1281 u->uh_sport = htons(1); 1282 u->uh_dport = htons(9); 1283 u->uh_sum = 0; 1284 1285 nfd = initdevice(dev, 1); 1286 if (nfd == -1) 1287 return; 1288 1289 u->uh_ulen = htons(7168); 1290 1291 printf("6. Exhaustive mbuf test.\n"); 1292 printf(" Send 7k packet in 768 & 128 byte fragments, 128 times.\n"); 1293 printf(" Total of around 8,900 packets\n"); 1294 for (i = 0; i < 128; i++) { 1295 /* 1296 * First send the entire packet in 768 byte chunks. 1297 */ 1298 ip->ip_len = sizeof(*ip) + 768 + sizeof(*u); 1299 IP_HL_A(ip, sizeof(*ip) >> 2); 1300 ip->ip_off = htons(IP_MF); 1301 (void) send_ip(nfd, 1500, ip, gwip, 1); 1302 printf("%d %d\r", i, 0); 1303 fflush(stdout); 1304 PAUSE(); 1305 /* 1306 * And again using 128 byte chunks. 1307 */ 1308 ip->ip_len = sizeof(*ip) + 128 + sizeof(*u); 1309 ip->ip_off = htons(IP_MF); 1310 (void) send_ip(nfd, 1500, ip, gwip, 1); 1311 printf("%d %d\r", i, 0); 1312 fflush(stdout); 1313 PAUSE(); 1314 1315 for (j = 768; j < 3584; j += 768) { 1316 ip->ip_len = sizeof(*ip) + 768; 1317 ip->ip_off = htons(IP_MF|(j>>3)); 1318 (void) send_ip(nfd, 1500, ip, gwip, 1); 1319 printf("%d %d\r", i, j); 1320 fflush(stdout); 1321 PAUSE(); 1322 1323 ip->ip_len = sizeof(*ip) + 128; 1324 for (k = j - 768; k < j; k += 128) { 1325 ip->ip_off = htons(IP_MF|(k>>3)); 1326 (void) send_ip(nfd, 1500, ip, gwip, 1); 1327 printf("%d %d\r", i, k); 1328 fflush(stdout); 1329 PAUSE(); 1330 } 1331 } 1332 } 1333 putchar('\n'); 1334 } 1335 1336 1337 /* Perform test 7 (random packets) */ 1338 1339 static u_long tbuf[64]; 1340 1341 void ip_test7(dev, mtu, ip, gwip, ptest) 1342 char *dev; 1343 int mtu; 1344 ip_t *ip; 1345 struct in_addr gwip; 1346 int ptest; 1347 { 1348 ip_t *pip; 1349 #ifdef USE_NANOSLEEP 1350 struct timespec ts; 1351 #else 1352 struct timeval tv; 1353 #endif 1354 int nfd, i, j; 1355 u_char *s; 1356 1357 nfd = initdevice(dev, 1); 1358 if (nfd == -1) 1359 return; 1360 1361 pip = (ip_t *)tbuf; 1362 1363 srand(time(NULL) ^ (getpid() * getppid())); 1364 1365 printf("7. send 1024 random IP packets.\n"); 1366 1367 for (i = 0; i < 512; i++) { 1368 for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++) 1369 *s = (rand() >> 13) & 0xff; 1370 IP_V_A(pip, IPVERSION); 1371 bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst, 1372 sizeof(struct in_addr)); 1373 pip->ip_sum = 0; 1374 pip->ip_len &= 0xff; 1375 (void) send_ip(nfd, mtu, pip, gwip, 0); 1376 printf("%d\r", i); 1377 fflush(stdout); 1378 PAUSE(); 1379 } 1380 putchar('\n'); 1381 1382 for (i = 0; i < 512; i++) { 1383 for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++) 1384 *s = (rand() >> 13) & 0xff; 1385 IP_V_A(pip, IPVERSION); 1386 pip->ip_off &= htons(0xc000); 1387 bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst, 1388 sizeof(struct in_addr)); 1389 pip->ip_sum = 0; 1390 pip->ip_len &= 0xff; 1391 (void) send_ip(nfd, mtu, pip, gwip, 0); 1392 printf("%d\r", i); 1393 fflush(stdout); 1394 PAUSE(); 1395 } 1396 putchar('\n'); 1397 } 1398