1 /*
2 * Copyright (C) 2003 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 *
6 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
7 * Use is subject to license terms.
8 *
9 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
10 */
11
12 #include <sys/types.h>
13 #include <sys/time.h>
14 #include <sys/param.h>
15 #include <sys/socket.h>
16 #if defined(BSD) && (BSD >= 199306)
17 # include <sys/cdefs.h>
18 #endif
19 #include <sys/ioctl.h>
20
21 #include <net/if.h>
22 #if __FreeBSD_version >= 300000
23 # include <net/if_var.h>
24 #endif
25 #include <netinet/in.h>
26
27 #include <arpa/inet.h>
28
29 #include <stdio.h>
365 }
366
367 if (setzone(fd) != 0) {
368 close(fd);
369 exit(1);
370 }
371 }
372
373 if (ippool_parsefile(fd, infile, ioctl) != 0)
374 return -1;
375 return 0;
376 }
377
378
379 int poollist(argc, argv)
380 int argc;
381 char *argv[];
382 {
383 char *kernel, *core, *poolname;
384 int c, role, type, live_kernel;
385 ip_pool_stat_t *plstp, plstat;
386 iphtstat_t *htstp, htstat;
387 iphtable_t *hptr;
388 iplookupop_t op;
389 ip_pool_t *ptr;
390
391 core = NULL;
392 kernel = NULL;
393 live_kernel = 1;
394 type = IPLT_ALL;
395 poolname = NULL;
396 role = IPL_LOGALL;
397
398 while ((c = getopt(argc, argv, "dG:m:M:N:o:Rt:vz:")) != -1)
399 switch (c)
400 {
401 case 'd' :
402 opts |= OPT_DEBUG;
403 break;
404 case 'G' :
405 setzonename_global(optarg);
406 break;
452
453 if (setzone(fd) != 0) {
454 close(fd);
455 exit(1);
456 }
457 }
458
459 bzero((char *)&op, sizeof(op));
460 if (poolname != NULL) {
461 strncpy(op.iplo_name, poolname, sizeof(op.iplo_name));
462 op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
463 }
464 op.iplo_unit = role;
465
466 if (live_kernel == 0) {
467 poollist_dead(role, poolname, type, kernel, core);
468 return (0);
469 }
470
471 if (type == IPLT_ALL || type == IPLT_POOL) {
472 plstp = &plstat;
473 op.iplo_type = IPLT_POOL;
474 op.iplo_size = sizeof(plstat);
475 op.iplo_struct = &plstat;
476 op.iplo_name[0] = '\0';
477 op.iplo_arg = 0;
478
479 if (role != IPL_LOGALL) {
480 op.iplo_unit = role;
481
482 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
483 if (c == -1) {
484 perror("ioctl(SIOCLOOKUPSTAT)");
485 return -1;
486 }
487
488 showpools_live(fd, role, &plstat, poolname, opts);
489 } else {
490 for (role = 0; role <= IPL_LOGMAX; role++) {
491 op.iplo_unit = role;
492
493 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
494 if (c == -1) {
495 perror("ioctl(SIOCLOOKUPSTAT)");
496 return -1;
497 }
498
499 showpools_live(fd, role, &plstat, poolname, opts);
500 }
501
502 role = IPL_LOGALL;
503 }
504 }
505 if (type == IPLT_ALL || type == IPLT_HASH) {
506 htstp = &htstat;
507 op.iplo_type = IPLT_HASH;
508 op.iplo_size = sizeof(htstat);
509 op.iplo_struct = &htstat;
510 op.iplo_name[0] = '\0';
511 op.iplo_arg = 0;
512
513 if (role != IPL_LOGALL) {
514 op.iplo_unit = role;
515
516 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
517 if (c == -1) {
518 perror("ioctl(SIOCLOOKUPSTAT)");
519 return -1;
520 }
521 showhashs_live(fd, role, &htstat, poolname, opts);
522 } else {
523 for (role = 0; role <= IPL_LOGMAX; role++) {
524
525 op.iplo_unit = role;
526 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
625 iter.ili_ival = IPFGENITER_LOOKUP;
626 iter.ili_data = &pool;
627 iter.ili_unit = role;
628 *iter.ili_name = '\0';
629
630 while (plstp->ipls_list[role] != NULL) {
631 if (ioctl(fd, SIOCLOOKUPITER, &obj)) {
632 perror("ioctl(SIOCLOOKUPITER)");
633 break;
634 }
635 (void) printpool_live(&pool, fd, poolname, opts);
636
637 plstp->ipls_list[role] = pool.ipo_next;
638 }
639 }
640
641 int poolstats(argc, argv)
642 int argc;
643 char *argv[];
644 {
645 int c, type, role, live_kernel;
646 ip_pool_stat_t plstat;
647 char *kernel, *core;
648 iphtstat_t htstat;
649 iplookupop_t op;
650
651 core = NULL;
652 kernel = NULL;
653 live_kernel = 1;
654 type = IPLT_ALL;
655 role = IPL_LOGALL;
656
657 bzero((char *)&op, sizeof(op));
658
659 while ((c = getopt(argc, argv, "dG:M:N:o:t:vz:")) != -1)
660 switch (c)
661 {
662 case 'd' :
663 opts |= OPT_DEBUG;
664 break;
665 case 'G' :
666 setzonename_global(optarg);
667 break;
668 case 'M' :
669 live_kernel = 0;
670 core = optarg;
671 break;
672 case 'N' :
673 live_kernel = 0;
674 kernel = optarg;
675 break;
676 case 'o' :
677 role = getrole(optarg);
678 if (role == IPL_LOGNONE) {
679 fprintf(stderr, "unknown role '%s'\n", optarg);
680 return -1;
681 }
682 break;
683 case 't' :
684 type = gettype(optarg, NULL);
685 if (type != IPLT_POOL) {
686 fprintf(stderr,
687 "-s not supported for this type yet\n");
688 return -1;
689 }
690 break;
691 case 'v' :
692 opts |= OPT_VERBOSE;
693 break;
694 case 'z' :
|
1 /*
2 * Copyright (C) 2003 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 *
6 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
7 * Use is subject to license terms.
8 *
9 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
10 * Copyright 2017 Gary Mills
11 */
12
13 #include <sys/types.h>
14 #include <sys/time.h>
15 #include <sys/param.h>
16 #include <sys/socket.h>
17 #if defined(BSD) && (BSD >= 199306)
18 # include <sys/cdefs.h>
19 #endif
20 #include <sys/ioctl.h>
21
22 #include <net/if.h>
23 #if __FreeBSD_version >= 300000
24 # include <net/if_var.h>
25 #endif
26 #include <netinet/in.h>
27
28 #include <arpa/inet.h>
29
30 #include <stdio.h>
366 }
367
368 if (setzone(fd) != 0) {
369 close(fd);
370 exit(1);
371 }
372 }
373
374 if (ippool_parsefile(fd, infile, ioctl) != 0)
375 return -1;
376 return 0;
377 }
378
379
380 int poollist(argc, argv)
381 int argc;
382 char *argv[];
383 {
384 char *kernel, *core, *poolname;
385 int c, role, type, live_kernel;
386 ip_pool_stat_t *plstp;
387 ip_pool_stat_t plstat;
388 iphtstat_t htstat;
389 iphtable_t *hptr;
390 iplookupop_t op;
391 ip_pool_t *ptr;
392
393 core = NULL;
394 kernel = NULL;
395 live_kernel = 1;
396 type = IPLT_ALL;
397 poolname = NULL;
398 role = IPL_LOGALL;
399
400 while ((c = getopt(argc, argv, "dG:m:M:N:o:Rt:vz:")) != -1)
401 switch (c)
402 {
403 case 'd' :
404 opts |= OPT_DEBUG;
405 break;
406 case 'G' :
407 setzonename_global(optarg);
408 break;
454
455 if (setzone(fd) != 0) {
456 close(fd);
457 exit(1);
458 }
459 }
460
461 bzero((char *)&op, sizeof(op));
462 if (poolname != NULL) {
463 strncpy(op.iplo_name, poolname, sizeof(op.iplo_name));
464 op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
465 }
466 op.iplo_unit = role;
467
468 if (live_kernel == 0) {
469 poollist_dead(role, poolname, type, kernel, core);
470 return (0);
471 }
472
473 if (type == IPLT_ALL || type == IPLT_POOL) {
474 op.iplo_type = IPLT_POOL;
475 op.iplo_size = sizeof(plstat);
476 op.iplo_struct = &plstat;
477 op.iplo_name[0] = '\0';
478 op.iplo_arg = 0;
479
480 if (role != IPL_LOGALL) {
481 op.iplo_unit = role;
482
483 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
484 if (c == -1) {
485 perror("ioctl(SIOCLOOKUPSTAT)");
486 return -1;
487 }
488
489 showpools_live(fd, role, &plstat, poolname, opts);
490 } else {
491 for (role = 0; role <= IPL_LOGMAX; role++) {
492 op.iplo_unit = role;
493
494 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
495 if (c == -1) {
496 perror("ioctl(SIOCLOOKUPSTAT)");
497 return -1;
498 }
499
500 showpools_live(fd, role, &plstat, poolname, opts);
501 }
502
503 role = IPL_LOGALL;
504 }
505 }
506 if (type == IPLT_ALL || type == IPLT_HASH) {
507 op.iplo_type = IPLT_HASH;
508 op.iplo_size = sizeof(htstat);
509 op.iplo_struct = &htstat;
510 op.iplo_name[0] = '\0';
511 op.iplo_arg = 0;
512
513 if (role != IPL_LOGALL) {
514 op.iplo_unit = role;
515
516 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
517 if (c == -1) {
518 perror("ioctl(SIOCLOOKUPSTAT)");
519 return -1;
520 }
521 showhashs_live(fd, role, &htstat, poolname, opts);
522 } else {
523 for (role = 0; role <= IPL_LOGMAX; role++) {
524
525 op.iplo_unit = role;
526 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
625 iter.ili_ival = IPFGENITER_LOOKUP;
626 iter.ili_data = &pool;
627 iter.ili_unit = role;
628 *iter.ili_name = '\0';
629
630 while (plstp->ipls_list[role] != NULL) {
631 if (ioctl(fd, SIOCLOOKUPITER, &obj)) {
632 perror("ioctl(SIOCLOOKUPITER)");
633 break;
634 }
635 (void) printpool_live(&pool, fd, poolname, opts);
636
637 plstp->ipls_list[role] = pool.ipo_next;
638 }
639 }
640
641 int poolstats(argc, argv)
642 int argc;
643 char *argv[];
644 {
645 int c, type, role;
646 ip_pool_stat_t plstat;
647 iphtstat_t htstat;
648 iplookupop_t op;
649
650 type = IPLT_ALL;
651 role = IPL_LOGALL;
652
653 bzero((char *)&op, sizeof(op));
654
655 while ((c = getopt(argc, argv, "dG:M:N:o:t:vz:")) != -1)
656 switch (c)
657 {
658 case 'd' :
659 opts |= OPT_DEBUG;
660 break;
661 case 'G' :
662 setzonename_global(optarg);
663 break;
664 case 'M' :
665 break;
666 case 'N' :
667 break;
668 case 'o' :
669 role = getrole(optarg);
670 if (role == IPL_LOGNONE) {
671 fprintf(stderr, "unknown role '%s'\n", optarg);
672 return -1;
673 }
674 break;
675 case 't' :
676 type = gettype(optarg, NULL);
677 if (type != IPLT_POOL) {
678 fprintf(stderr,
679 "-s not supported for this type yet\n");
680 return -1;
681 }
682 break;
683 case 'v' :
684 opts |= OPT_VERBOSE;
685 break;
686 case 'z' :
|