17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright (C) 2003 by Darren Reed. 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing. 57c478bd9Sstevel@tonic-gate * 6*f4b3ec61Sdh155122 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 77c478bd9Sstevel@tonic-gate * Use is subject to license terms. 87c478bd9Sstevel@tonic-gate */ 97c478bd9Sstevel@tonic-gate 107c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 117c478bd9Sstevel@tonic-gate 127c478bd9Sstevel@tonic-gate #include <sys/types.h> 137c478bd9Sstevel@tonic-gate #include <sys/time.h> 147c478bd9Sstevel@tonic-gate #include <sys/param.h> 157c478bd9Sstevel@tonic-gate #include <sys/socket.h> 167c478bd9Sstevel@tonic-gate #if defined(BSD) && (BSD >= 199306) 177c478bd9Sstevel@tonic-gate # include <sys/cdefs.h> 187c478bd9Sstevel@tonic-gate #endif 197c478bd9Sstevel@tonic-gate #include <sys/ioctl.h> 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate #include <net/if.h> 227c478bd9Sstevel@tonic-gate #if __FreeBSD_version >= 300000 237c478bd9Sstevel@tonic-gate # include <net/if_var.h> 247c478bd9Sstevel@tonic-gate #endif 257c478bd9Sstevel@tonic-gate #include <netinet/in.h> 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <fcntl.h> 317c478bd9Sstevel@tonic-gate #include <stdlib.h> 327c478bd9Sstevel@tonic-gate #include <string.h> 337c478bd9Sstevel@tonic-gate #include <netdb.h> 347c478bd9Sstevel@tonic-gate #include <ctype.h> 357c478bd9Sstevel@tonic-gate #include <unistd.h> 36*f4b3ec61Sdh155122 #include <nlist.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include "ipf.h" 39*f4b3ec61Sdh155122 #include "netinet/ipl.h" 407c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h" 417c478bd9Sstevel@tonic-gate #include "netinet/ip_pool.h" 427c478bd9Sstevel@tonic-gate #include "netinet/ip_htable.h" 437c478bd9Sstevel@tonic-gate #include "kmem.h" 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate extern int ippool_yyparse __P((void)); 467c478bd9Sstevel@tonic-gate extern int ippool_yydebug; 477c478bd9Sstevel@tonic-gate extern FILE *ippool_yyin; 487c478bd9Sstevel@tonic-gate extern char *optarg; 497c478bd9Sstevel@tonic-gate extern int lineNum; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate void showpools __P((ip_pool_stat_t *)); 527c478bd9Sstevel@tonic-gate void usage __P((char *)); 537c478bd9Sstevel@tonic-gate int main __P((int, char **)); 547c478bd9Sstevel@tonic-gate int poolcommand __P((int, int, char *[])); 557c478bd9Sstevel@tonic-gate int poolnodecommand __P((int, int, char *[])); 567c478bd9Sstevel@tonic-gate int loadpoolfile __P((int, char *[], char *)); 577c478bd9Sstevel@tonic-gate int poollist __P((int, char *[])); 587c478bd9Sstevel@tonic-gate int poolflush __P((int, char *[])); 597c478bd9Sstevel@tonic-gate int poolstats __P((int, char *[])); 607c478bd9Sstevel@tonic-gate int gettype __P((char *, u_int *)); 617c478bd9Sstevel@tonic-gate int getrole __P((char *)); 62*f4b3ec61Sdh155122 void poollist_dead __P((int, char *, int, char *, char *)); 63*f4b3ec61Sdh155122 void showpools_live(int, int, ip_pool_stat_t *, char *, int); 64*f4b3ec61Sdh155122 void showhashs_live(int, int, iphtstat_t *, char *, int); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate int opts = 0; 677c478bd9Sstevel@tonic-gate int fd = -1; 687c478bd9Sstevel@tonic-gate int use_inet6 = 0; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate void usage(prog) 727c478bd9Sstevel@tonic-gate char *prog; 737c478bd9Sstevel@tonic-gate { 747c478bd9Sstevel@tonic-gate fprintf(stderr, "Usage:\t%s\n", prog); 757c478bd9Sstevel@tonic-gate fprintf(stderr, "\t\t\t-a [-dnv] [-m <name>] [-o <role>] -i <ipaddr>[/netmask]\n"); 767c478bd9Sstevel@tonic-gate fprintf(stderr, "\t\t\t-A [-dnv] [-m <name>] [-o <role>] [-S <seed>] [-t <type>]\n"); 777c478bd9Sstevel@tonic-gate fprintf(stderr, "\t\t\t-f <file> [-dnuv]\n"); 787c478bd9Sstevel@tonic-gate fprintf(stderr, "\t\t\t-F [-dv] [-o <role>] [-t <type>]\n"); 797c478bd9Sstevel@tonic-gate fprintf(stderr, "\t\t\t-l [-dv] [-m <name>] [-t <type>]\n"); 807c478bd9Sstevel@tonic-gate fprintf(stderr, "\t\t\t-r [-dnv] [-m <name>] [-o <role>] -i <ipaddr>[/netmask]\n"); 817c478bd9Sstevel@tonic-gate fprintf(stderr, "\t\t\t-R [-dnv] [-m <name>] [-o <role>] [-t <type>]\n"); 827c478bd9Sstevel@tonic-gate fprintf(stderr, "\t\t\t-s [-dtv] [-M <core>] [-N <namelist>]\n"); 837c478bd9Sstevel@tonic-gate exit(1); 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate int main(argc, argv) 887c478bd9Sstevel@tonic-gate int argc; 897c478bd9Sstevel@tonic-gate char *argv[]; 907c478bd9Sstevel@tonic-gate { 917c478bd9Sstevel@tonic-gate int err; 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate if (argc < 2) 947c478bd9Sstevel@tonic-gate usage(argv[0]); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate switch (getopt(argc, argv, "aAf:FlrRs")) 977c478bd9Sstevel@tonic-gate { 987c478bd9Sstevel@tonic-gate case 'a' : 997c478bd9Sstevel@tonic-gate err = poolnodecommand(0, argc, argv); 1007c478bd9Sstevel@tonic-gate break; 1017c478bd9Sstevel@tonic-gate case 'A' : 1027c478bd9Sstevel@tonic-gate err = poolcommand(0, argc, argv); 1037c478bd9Sstevel@tonic-gate break; 1047c478bd9Sstevel@tonic-gate case 'f' : 1057c478bd9Sstevel@tonic-gate err = loadpoolfile(argc, argv, optarg); 1067c478bd9Sstevel@tonic-gate break; 1077c478bd9Sstevel@tonic-gate case 'F' : 1087c478bd9Sstevel@tonic-gate err = poolflush(argc, argv); 1097c478bd9Sstevel@tonic-gate break; 1107c478bd9Sstevel@tonic-gate case 'l' : 1117c478bd9Sstevel@tonic-gate err = poollist(argc, argv); 1127c478bd9Sstevel@tonic-gate break; 1137c478bd9Sstevel@tonic-gate case 'r' : 1147c478bd9Sstevel@tonic-gate err = poolnodecommand(1, argc, argv); 1157c478bd9Sstevel@tonic-gate break; 1167c478bd9Sstevel@tonic-gate case 'R' : 1177c478bd9Sstevel@tonic-gate err = poolcommand(1, argc, argv); 1187c478bd9Sstevel@tonic-gate break; 1197c478bd9Sstevel@tonic-gate case 's' : 1207c478bd9Sstevel@tonic-gate err = poolstats(argc, argv); 1217c478bd9Sstevel@tonic-gate break; 1227c478bd9Sstevel@tonic-gate default : 1237c478bd9Sstevel@tonic-gate exit(1); 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate return err; 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate int poolnodecommand(remove, argc, argv) 1317c478bd9Sstevel@tonic-gate int remove, argc; 1327c478bd9Sstevel@tonic-gate char *argv[]; 1337c478bd9Sstevel@tonic-gate { 1347c478bd9Sstevel@tonic-gate char *poolname = NULL, *s; 1357c478bd9Sstevel@tonic-gate int err, c, ipset, role; 1367c478bd9Sstevel@tonic-gate ip_pool_node_t node; 1377c478bd9Sstevel@tonic-gate struct in_addr mask; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate ipset = 0; 1407c478bd9Sstevel@tonic-gate role = IPL_LOGIPF; 1417c478bd9Sstevel@tonic-gate bzero((char *)&node, sizeof(node)); 1427c478bd9Sstevel@tonic-gate 143ab25eeb5Syz155240 while ((c = getopt(argc, argv, "di:m:no:Rv")) != -1) 1447c478bd9Sstevel@tonic-gate switch (c) 1457c478bd9Sstevel@tonic-gate { 1467c478bd9Sstevel@tonic-gate case 'd' : 1477c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG; 1487c478bd9Sstevel@tonic-gate ippool_yydebug++; 1497c478bd9Sstevel@tonic-gate break; 1507c478bd9Sstevel@tonic-gate case 'i' : 1517c478bd9Sstevel@tonic-gate s = strchr(optarg, '/'); 1527c478bd9Sstevel@tonic-gate if (s == NULL) 1537c478bd9Sstevel@tonic-gate mask.s_addr = 0xffffffff; 1547c478bd9Sstevel@tonic-gate else if (strchr(s, '.') == NULL) { 1557c478bd9Sstevel@tonic-gate if (ntomask(4, atoi(s + 1), &mask.s_addr) != 0) 1567c478bd9Sstevel@tonic-gate return -1; 1577c478bd9Sstevel@tonic-gate } else { 1587c478bd9Sstevel@tonic-gate mask.s_addr = inet_addr(s + 1); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate if (s != NULL) 1617c478bd9Sstevel@tonic-gate *s = '\0'; 1627c478bd9Sstevel@tonic-gate ipset = 1; 163ab25eeb5Syz155240 node.ipn_addr.adf_len = sizeof(node.ipn_addr); 1647c478bd9Sstevel@tonic-gate node.ipn_addr.adf_addr.in4.s_addr = inet_addr(optarg); 165ab25eeb5Syz155240 node.ipn_mask.adf_len = sizeof(node.ipn_mask); 1667c478bd9Sstevel@tonic-gate node.ipn_mask.adf_addr.in4.s_addr = mask.s_addr; 1677c478bd9Sstevel@tonic-gate break; 1687c478bd9Sstevel@tonic-gate case 'm' : 1697c478bd9Sstevel@tonic-gate poolname = optarg; 1707c478bd9Sstevel@tonic-gate break; 1717c478bd9Sstevel@tonic-gate case 'n' : 1727c478bd9Sstevel@tonic-gate opts |= OPT_DONOTHING; 1737c478bd9Sstevel@tonic-gate break; 1747c478bd9Sstevel@tonic-gate case 'o' : 1757c478bd9Sstevel@tonic-gate role = getrole(optarg); 1767c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) 1777c478bd9Sstevel@tonic-gate return -1; 1787c478bd9Sstevel@tonic-gate break; 179ab25eeb5Syz155240 case 'R' : 180ab25eeb5Syz155240 opts |= OPT_NORESOLVE; 181ab25eeb5Syz155240 break; 1827c478bd9Sstevel@tonic-gate case 'v' : 1837c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE; 1847c478bd9Sstevel@tonic-gate break; 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate 187ab25eeb5Syz155240 if (opts & OPT_DEBUG) 188ab25eeb5Syz155240 fprintf(stderr, "poolnodecommand: opts = %#x\n", opts); 189ab25eeb5Syz155240 1907c478bd9Sstevel@tonic-gate if (ipset == 0) 1917c478bd9Sstevel@tonic-gate return -1; 1927c478bd9Sstevel@tonic-gate if (poolname == NULL) { 1937c478bd9Sstevel@tonic-gate fprintf(stderr, "poolname not given with add/remove node\n"); 1947c478bd9Sstevel@tonic-gate return -1; 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate if (remove == 0) 1987c478bd9Sstevel@tonic-gate err = load_poolnode(0, poolname, &node, ioctl); 1997c478bd9Sstevel@tonic-gate else 2007c478bd9Sstevel@tonic-gate err = remove_poolnode(0, poolname, &node, ioctl); 2017c478bd9Sstevel@tonic-gate return err; 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate int poolcommand(remove, argc, argv) 2067c478bd9Sstevel@tonic-gate int remove, argc; 2077c478bd9Sstevel@tonic-gate char *argv[]; 2087c478bd9Sstevel@tonic-gate { 2097c478bd9Sstevel@tonic-gate int type, role, c, err; 2107c478bd9Sstevel@tonic-gate char *poolname; 2117c478bd9Sstevel@tonic-gate iphtable_t iph; 2127c478bd9Sstevel@tonic-gate ip_pool_t pool; 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate err = 1; 2157c478bd9Sstevel@tonic-gate role = 0; 2167c478bd9Sstevel@tonic-gate type = 0; 2177c478bd9Sstevel@tonic-gate poolname = NULL; 2187c478bd9Sstevel@tonic-gate role = IPL_LOGIPF; 2197c478bd9Sstevel@tonic-gate bzero((char *)&iph, sizeof(iph)); 2207c478bd9Sstevel@tonic-gate bzero((char *)&pool, sizeof(pool)); 2217c478bd9Sstevel@tonic-gate 22234ef97d0Sjojemann while ((c = getopt(argc, argv, "dm:no:RS:t:v")) != -1) 2237c478bd9Sstevel@tonic-gate switch (c) 2247c478bd9Sstevel@tonic-gate { 2257c478bd9Sstevel@tonic-gate case 'd' : 2267c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG; 2277c478bd9Sstevel@tonic-gate ippool_yydebug++; 2287c478bd9Sstevel@tonic-gate break; 2297c478bd9Sstevel@tonic-gate case 'm' : 2307c478bd9Sstevel@tonic-gate poolname = optarg; 2317c478bd9Sstevel@tonic-gate break; 2327c478bd9Sstevel@tonic-gate case 'n' : 2337c478bd9Sstevel@tonic-gate opts |= OPT_DONOTHING; 2347c478bd9Sstevel@tonic-gate break; 2357c478bd9Sstevel@tonic-gate case 'o' : 2367c478bd9Sstevel@tonic-gate role = getrole(optarg); 2377c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) { 2387c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown role '%s'\n", optarg); 2397c478bd9Sstevel@tonic-gate return -1; 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate break; 242ab25eeb5Syz155240 case 'R' : 243ab25eeb5Syz155240 opts |= OPT_NORESOLVE; 244ab25eeb5Syz155240 break; 2457c478bd9Sstevel@tonic-gate case 'S' : 2467c478bd9Sstevel@tonic-gate iph.iph_seed = atoi(optarg); 2477c478bd9Sstevel@tonic-gate break; 2487c478bd9Sstevel@tonic-gate case 't' : 2497c478bd9Sstevel@tonic-gate type = gettype(optarg, &iph.iph_type); 2507c478bd9Sstevel@tonic-gate if (type == IPLT_NONE) { 2517c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown type '%s'\n", optarg); 2527c478bd9Sstevel@tonic-gate return -1; 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate break; 2557c478bd9Sstevel@tonic-gate case 'v' : 2567c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE; 2577c478bd9Sstevel@tonic-gate break; 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 260ab25eeb5Syz155240 if (opts & OPT_DEBUG) 261ab25eeb5Syz155240 fprintf(stderr, "poolcommand: opts = %#x\n", opts); 262ab25eeb5Syz155240 2637c478bd9Sstevel@tonic-gate if (poolname == NULL) { 2647c478bd9Sstevel@tonic-gate fprintf(stderr, "poolname not given with add/remove pool\n"); 2657c478bd9Sstevel@tonic-gate return -1; 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate if (type == IPLT_HASH) { 2697c478bd9Sstevel@tonic-gate strncpy(iph.iph_name, poolname, sizeof(iph.iph_name)); 2707c478bd9Sstevel@tonic-gate iph.iph_name[sizeof(iph.iph_name) - 1] = '\0'; 2717c478bd9Sstevel@tonic-gate iph.iph_unit = role; 2727c478bd9Sstevel@tonic-gate } else if (type == IPLT_POOL) { 2737c478bd9Sstevel@tonic-gate strncpy(pool.ipo_name, poolname, sizeof(pool.ipo_name)); 2747c478bd9Sstevel@tonic-gate pool.ipo_name[sizeof(pool.ipo_name) - 1] = '\0'; 2757c478bd9Sstevel@tonic-gate pool.ipo_unit = role; 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate if (remove == 0) { 2797c478bd9Sstevel@tonic-gate switch (type) 2807c478bd9Sstevel@tonic-gate { 2817c478bd9Sstevel@tonic-gate case IPLT_HASH : 2827c478bd9Sstevel@tonic-gate err = load_hash(&iph, NULL, ioctl); 2837c478bd9Sstevel@tonic-gate break; 2847c478bd9Sstevel@tonic-gate case IPLT_POOL : 2857c478bd9Sstevel@tonic-gate err = load_pool(&pool, ioctl); 2867c478bd9Sstevel@tonic-gate break; 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate } else { 2897c478bd9Sstevel@tonic-gate switch (type) 2907c478bd9Sstevel@tonic-gate { 2917c478bd9Sstevel@tonic-gate case IPLT_HASH : 2927c478bd9Sstevel@tonic-gate err = remove_hash(&iph, ioctl); 2937c478bd9Sstevel@tonic-gate break; 2947c478bd9Sstevel@tonic-gate case IPLT_POOL : 2957c478bd9Sstevel@tonic-gate err = remove_pool(&pool, ioctl); 2967c478bd9Sstevel@tonic-gate break; 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate } 2997c478bd9Sstevel@tonic-gate return err; 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate int loadpoolfile(argc, argv, infile) 3047c478bd9Sstevel@tonic-gate int argc; 3057c478bd9Sstevel@tonic-gate char *argv[], *infile; 3067c478bd9Sstevel@tonic-gate { 3077c478bd9Sstevel@tonic-gate int c; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate infile = optarg; 3107c478bd9Sstevel@tonic-gate 311ab25eeb5Syz155240 while ((c = getopt(argc, argv, "dnRuv")) != -1) 3127c478bd9Sstevel@tonic-gate switch (c) 3137c478bd9Sstevel@tonic-gate { 3147c478bd9Sstevel@tonic-gate case 'd' : 3157c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG; 3167c478bd9Sstevel@tonic-gate ippool_yydebug++; 3177c478bd9Sstevel@tonic-gate break; 3187c478bd9Sstevel@tonic-gate case 'n' : 3197c478bd9Sstevel@tonic-gate opts |= OPT_DONOTHING; 3207c478bd9Sstevel@tonic-gate break; 321ab25eeb5Syz155240 case 'R' : 322ab25eeb5Syz155240 opts |= OPT_NORESOLVE; 323ab25eeb5Syz155240 break; 324ab25eeb5Syz155240 case 'u' : 3257c478bd9Sstevel@tonic-gate opts |= OPT_REMOVE; 3267c478bd9Sstevel@tonic-gate break; 3277c478bd9Sstevel@tonic-gate case 'v' : 3287c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE; 3297c478bd9Sstevel@tonic-gate break; 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate 332ab25eeb5Syz155240 if (opts & OPT_DEBUG) 333ab25eeb5Syz155240 fprintf(stderr, "loadpoolfile: opts = %#x\n", opts); 334ab25eeb5Syz155240 3357c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING) && (fd == -1)) { 3367c478bd9Sstevel@tonic-gate fd = open(IPLOOKUP_NAME, O_RDWR); 3377c478bd9Sstevel@tonic-gate if (fd == -1) { 3387c478bd9Sstevel@tonic-gate perror("open(IPLOOKUP_NAME)"); 3397c478bd9Sstevel@tonic-gate exit(1); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate if (ippool_parsefile(fd, infile, ioctl) != 0) 3447c478bd9Sstevel@tonic-gate return -1; 3457c478bd9Sstevel@tonic-gate return 0; 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate int poollist(argc, argv) 3507c478bd9Sstevel@tonic-gate int argc; 3517c478bd9Sstevel@tonic-gate char *argv[]; 3527c478bd9Sstevel@tonic-gate { 3537c478bd9Sstevel@tonic-gate char *kernel, *core, *poolname; 3547c478bd9Sstevel@tonic-gate int c, role, type, live_kernel; 3557c478bd9Sstevel@tonic-gate ip_pool_stat_t *plstp, plstat; 3567663b816Sml37995 iphtstat_t *htstp, htstat; 3577663b816Sml37995 iphtable_t *hptr; 3587c478bd9Sstevel@tonic-gate iplookupop_t op; 3597c478bd9Sstevel@tonic-gate ip_pool_t *ptr; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate core = NULL; 3627c478bd9Sstevel@tonic-gate kernel = NULL; 3637c478bd9Sstevel@tonic-gate live_kernel = 1; 3647c478bd9Sstevel@tonic-gate type = IPLT_ALL; 3657c478bd9Sstevel@tonic-gate poolname = NULL; 3667c478bd9Sstevel@tonic-gate role = IPL_LOGALL; 3677c478bd9Sstevel@tonic-gate 368ab25eeb5Syz155240 while ((c = getopt(argc, argv, "dm:M:N:o:Rt:v")) != -1) 3697c478bd9Sstevel@tonic-gate switch (c) 3707c478bd9Sstevel@tonic-gate { 3717c478bd9Sstevel@tonic-gate case 'd' : 3727c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG; 3737c478bd9Sstevel@tonic-gate break; 3747c478bd9Sstevel@tonic-gate case 'm' : 3757c478bd9Sstevel@tonic-gate poolname = optarg; 3767c478bd9Sstevel@tonic-gate break; 3777c478bd9Sstevel@tonic-gate case 'M' : 3787c478bd9Sstevel@tonic-gate live_kernel = 0; 3797c478bd9Sstevel@tonic-gate core = optarg; 3807c478bd9Sstevel@tonic-gate break; 3817c478bd9Sstevel@tonic-gate case 'N' : 3827c478bd9Sstevel@tonic-gate live_kernel = 0; 3837c478bd9Sstevel@tonic-gate kernel = optarg; 3847c478bd9Sstevel@tonic-gate break; 3857c478bd9Sstevel@tonic-gate case 'o' : 3867c478bd9Sstevel@tonic-gate role = getrole(optarg); 3877c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) { 3887c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown role '%s'\n", optarg); 3897c478bd9Sstevel@tonic-gate return -1; 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate break; 392ab25eeb5Syz155240 case 'R' : 393ab25eeb5Syz155240 opts |= OPT_NORESOLVE; 394ab25eeb5Syz155240 break; 3957c478bd9Sstevel@tonic-gate case 't' : 3967c478bd9Sstevel@tonic-gate type = gettype(optarg, NULL); 3977c478bd9Sstevel@tonic-gate if (type == IPLT_NONE) { 3987c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown type '%s'\n", optarg); 3997c478bd9Sstevel@tonic-gate return -1; 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate break; 4027c478bd9Sstevel@tonic-gate case 'v' : 4037c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE; 4047c478bd9Sstevel@tonic-gate break; 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate 4077663b816Sml37995 if (opts & OPT_DEBUG) 4087663b816Sml37995 fprintf(stderr, "poollist: opts = %#x\n", opts); 4097663b816Sml37995 4107c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING) && (fd == -1)) { 4117c478bd9Sstevel@tonic-gate fd = open(IPLOOKUP_NAME, O_RDWR); 4127c478bd9Sstevel@tonic-gate if (fd == -1) { 4137c478bd9Sstevel@tonic-gate perror("open(IPLOOKUP_NAME)"); 4147c478bd9Sstevel@tonic-gate exit(1); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate } 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate bzero((char *)&op, sizeof(op)); 4197c478bd9Sstevel@tonic-gate if (poolname != NULL) { 4207c478bd9Sstevel@tonic-gate strncpy(op.iplo_name, poolname, sizeof(op.iplo_name)); 4217c478bd9Sstevel@tonic-gate op.iplo_name[sizeof(op.iplo_name) - 1] = '\0'; 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate op.iplo_unit = role; 4247663b816Sml37995 425*f4b3ec61Sdh155122 if (live_kernel == 0) { 426*f4b3ec61Sdh155122 poollist_dead(role, poolname, type, kernel, core); 427*f4b3ec61Sdh155122 return (0); 428*f4b3ec61Sdh155122 } 4297663b816Sml37995 4307663b816Sml37995 if (type == IPLT_ALL || type == IPLT_POOL) { 4317663b816Sml37995 plstp = &plstat; 4327663b816Sml37995 op.iplo_type = IPLT_POOL; 4337c478bd9Sstevel@tonic-gate op.iplo_size = sizeof(plstat); 4347c478bd9Sstevel@tonic-gate op.iplo_struct = &plstat; 435*f4b3ec61Sdh155122 op.iplo_name[0] = '\0'; 436*f4b3ec61Sdh155122 op.iplo_arg = 0; 437*f4b3ec61Sdh155122 438*f4b3ec61Sdh155122 if (role != IPL_LOGALL) { 439*f4b3ec61Sdh155122 op.iplo_unit = role; 440*f4b3ec61Sdh155122 4417c478bd9Sstevel@tonic-gate c = ioctl(fd, SIOCLOOKUPSTAT, &op); 4427c478bd9Sstevel@tonic-gate if (c == -1) { 4437c478bd9Sstevel@tonic-gate perror("ioctl(SIOCLOOKUPSTAT)"); 4447c478bd9Sstevel@tonic-gate return -1; 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate 447*f4b3ec61Sdh155122 showpools_live(fd, role, &plstat, poolname, opts); 448*f4b3ec61Sdh155122 } else { 449*f4b3ec61Sdh155122 for (role = 0; role <= IPL_LOGMAX; role++) { 450*f4b3ec61Sdh155122 op.iplo_unit = role; 451*f4b3ec61Sdh155122 452*f4b3ec61Sdh155122 c = ioctl(fd, SIOCLOOKUPSTAT, &op); 453*f4b3ec61Sdh155122 if (c == -1) { 454*f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPSTAT)"); 455*f4b3ec61Sdh155122 return -1; 456*f4b3ec61Sdh155122 } 457*f4b3ec61Sdh155122 458*f4b3ec61Sdh155122 showpools_live(fd, role, &plstat, poolname, opts); 459*f4b3ec61Sdh155122 } 460*f4b3ec61Sdh155122 461*f4b3ec61Sdh155122 role = IPL_LOGALL; 462*f4b3ec61Sdh155122 } 463*f4b3ec61Sdh155122 } 464*f4b3ec61Sdh155122 if (type == IPLT_ALL || type == IPLT_HASH) { 465*f4b3ec61Sdh155122 htstp = &htstat; 466*f4b3ec61Sdh155122 op.iplo_type = IPLT_HASH; 467*f4b3ec61Sdh155122 op.iplo_size = sizeof(htstat); 468*f4b3ec61Sdh155122 op.iplo_struct = &htstat; 469*f4b3ec61Sdh155122 op.iplo_name[0] = '\0'; 470*f4b3ec61Sdh155122 op.iplo_arg = 0; 471*f4b3ec61Sdh155122 4727c478bd9Sstevel@tonic-gate if (role != IPL_LOGALL) { 473*f4b3ec61Sdh155122 op.iplo_unit = role; 474*f4b3ec61Sdh155122 475*f4b3ec61Sdh155122 c = ioctl(fd, SIOCLOOKUPSTAT, &op); 476*f4b3ec61Sdh155122 if (c == -1) { 477*f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPSTAT)"); 478*f4b3ec61Sdh155122 return -1; 479*f4b3ec61Sdh155122 } 480*f4b3ec61Sdh155122 showhashs_live(fd, role, &htstat, poolname, opts); 481*f4b3ec61Sdh155122 } else { 482*f4b3ec61Sdh155122 for (role = 0; role <= IPL_LOGMAX; role++) { 483*f4b3ec61Sdh155122 484*f4b3ec61Sdh155122 op.iplo_unit = role; 485*f4b3ec61Sdh155122 c = ioctl(fd, SIOCLOOKUPSTAT, &op); 486*f4b3ec61Sdh155122 if (c == -1) { 487*f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPSTAT)"); 488*f4b3ec61Sdh155122 return -1; 489*f4b3ec61Sdh155122 } 490*f4b3ec61Sdh155122 491*f4b3ec61Sdh155122 showhashs_live(fd, role, &htstat, poolname, opts); 492*f4b3ec61Sdh155122 } 493*f4b3ec61Sdh155122 } 494*f4b3ec61Sdh155122 } 495*f4b3ec61Sdh155122 return 0; 496*f4b3ec61Sdh155122 } 497*f4b3ec61Sdh155122 498*f4b3ec61Sdh155122 void poollist_dead(role, poolname, type, kernel, core) 499*f4b3ec61Sdh155122 int role, type; 500*f4b3ec61Sdh155122 char *poolname, *kernel, *core; 501*f4b3ec61Sdh155122 { 502*f4b3ec61Sdh155122 iphtable_t *hptr; 503*f4b3ec61Sdh155122 ip_pool_t *ptr; 504*f4b3ec61Sdh155122 505*f4b3ec61Sdh155122 if (openkmem(kernel, core) == -1) 506*f4b3ec61Sdh155122 exit(-1); 507*f4b3ec61Sdh155122 508*f4b3ec61Sdh155122 if (type == IPLT_ALL || type == IPLT_POOL) { 509*f4b3ec61Sdh155122 ip_pool_t *pools[IPL_LOGSIZE]; 510*f4b3ec61Sdh155122 struct nlist names[2] = { { "ip_pool_list" } , { "" } }; 511*f4b3ec61Sdh155122 512*f4b3ec61Sdh155122 if (nlist(kernel, names) != 1) 513*f4b3ec61Sdh155122 return; 514*f4b3ec61Sdh155122 515*f4b3ec61Sdh155122 bzero(&pools, sizeof(pools)); 516*f4b3ec61Sdh155122 if (kmemcpy((char *)&pools, names[0].n_value, sizeof(pools))) 517*f4b3ec61Sdh155122 return; 518*f4b3ec61Sdh155122 519*f4b3ec61Sdh155122 if (role != IPL_LOGALL) { 520*f4b3ec61Sdh155122 ptr = pools[role]; 5217c478bd9Sstevel@tonic-gate while (ptr != NULL) { 522*f4b3ec61Sdh155122 ptr = printpool(ptr, kmemcpywrap, 523*f4b3ec61Sdh155122 poolname, opts); 5247c478bd9Sstevel@tonic-gate } 5257c478bd9Sstevel@tonic-gate } else { 5267c478bd9Sstevel@tonic-gate for (role = 0; role <= IPL_LOGMAX; role++) { 527*f4b3ec61Sdh155122 ptr = pools[role]; 5287c478bd9Sstevel@tonic-gate while (ptr != NULL) { 5297663b816Sml37995 ptr = printpool(ptr, kmemcpywrap, 530ab25eeb5Syz155240 poolname, opts); 5317663b816Sml37995 } 5327663b816Sml37995 } 5337663b816Sml37995 role = IPL_LOGALL; 5347663b816Sml37995 } 5357663b816Sml37995 } 5367663b816Sml37995 if (type == IPLT_ALL || type == IPLT_HASH) { 537*f4b3ec61Sdh155122 iphtable_t *tables[IPL_LOGSIZE]; 538*f4b3ec61Sdh155122 struct nlist names[2] = { { "ipf_htables" } , { "" } }; 539*f4b3ec61Sdh155122 540*f4b3ec61Sdh155122 if (nlist(kernel, names) != 1) 541*f4b3ec61Sdh155122 return; 542*f4b3ec61Sdh155122 543*f4b3ec61Sdh155122 bzero(&tables, sizeof(tables)); 544*f4b3ec61Sdh155122 if (kmemcpy((char *)&tables, names[0].n_value, sizeof(tables))) 545*f4b3ec61Sdh155122 return; 5467663b816Sml37995 5477663b816Sml37995 if (role != IPL_LOGALL) { 548*f4b3ec61Sdh155122 hptr = tables[role]; 5497663b816Sml37995 while (hptr != NULL) { 550ab25eeb5Syz155240 hptr = printhash(hptr, kmemcpywrap, 551ab25eeb5Syz155240 poolname, opts); 5527663b816Sml37995 } 5537663b816Sml37995 } else { 5547663b816Sml37995 for (role = 0; role <= IPL_LOGMAX; role++) { 555*f4b3ec61Sdh155122 hptr = tables[role]; 5567663b816Sml37995 while (hptr != NULL) { 5577663b816Sml37995 hptr = printhash(hptr, kmemcpywrap, 558ab25eeb5Syz155240 poolname, opts); 5597663b816Sml37995 } 5607663b816Sml37995 } 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate } 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate 566*f4b3ec61Sdh155122 void 567*f4b3ec61Sdh155122 showpools_live(fd, role, plstp, poolname, opts) 568*f4b3ec61Sdh155122 int fd, role; 569*f4b3ec61Sdh155122 ip_pool_stat_t *plstp; 570*f4b3ec61Sdh155122 char *poolname; 571*f4b3ec61Sdh155122 int opts; 572*f4b3ec61Sdh155122 { 573*f4b3ec61Sdh155122 ipflookupiter_t iter; 574*f4b3ec61Sdh155122 ip_pool_t pool; 575*f4b3ec61Sdh155122 ipfobj_t obj; 576*f4b3ec61Sdh155122 577*f4b3ec61Sdh155122 obj.ipfo_rev = IPFILTER_VERSION; 578*f4b3ec61Sdh155122 obj.ipfo_type = IPFOBJ_LOOKUPITER; 579*f4b3ec61Sdh155122 obj.ipfo_size = sizeof(iter); 580*f4b3ec61Sdh155122 obj.ipfo_ptr = &iter; 581*f4b3ec61Sdh155122 582*f4b3ec61Sdh155122 iter.ili_type = IPLT_POOL; 583*f4b3ec61Sdh155122 iter.ili_otype = IPFLOOKUPITER_LIST; 584*f4b3ec61Sdh155122 iter.ili_ival = IPFGENITER_LOOKUP; 585*f4b3ec61Sdh155122 iter.ili_data = &pool; 586*f4b3ec61Sdh155122 iter.ili_unit = role; 587*f4b3ec61Sdh155122 *iter.ili_name = '\0'; 588*f4b3ec61Sdh155122 589*f4b3ec61Sdh155122 while (plstp->ipls_list[role] != NULL) { 590*f4b3ec61Sdh155122 if (ioctl(fd, SIOCLOOKUPITER, &obj)) { 591*f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPITER)"); 592*f4b3ec61Sdh155122 break; 593*f4b3ec61Sdh155122 } 594*f4b3ec61Sdh155122 (void) printpool_live(&pool, fd, poolname, opts); 595*f4b3ec61Sdh155122 596*f4b3ec61Sdh155122 plstp->ipls_list[role] = pool.ipo_next; 597*f4b3ec61Sdh155122 } 598*f4b3ec61Sdh155122 } 599*f4b3ec61Sdh155122 6007c478bd9Sstevel@tonic-gate int poolstats(argc, argv) 6017c478bd9Sstevel@tonic-gate int argc; 6027c478bd9Sstevel@tonic-gate char *argv[]; 6037c478bd9Sstevel@tonic-gate { 6047c478bd9Sstevel@tonic-gate int c, type, role, live_kernel; 6057c478bd9Sstevel@tonic-gate ip_pool_stat_t plstat; 6067c478bd9Sstevel@tonic-gate char *kernel, *core; 6077663b816Sml37995 iphtstat_t htstat; 6087c478bd9Sstevel@tonic-gate iplookupop_t op; 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate core = NULL; 6117c478bd9Sstevel@tonic-gate kernel = NULL; 6127c478bd9Sstevel@tonic-gate live_kernel = 1; 6137c478bd9Sstevel@tonic-gate type = IPLT_ALL; 6147c478bd9Sstevel@tonic-gate role = IPL_LOGALL; 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate bzero((char *)&op, sizeof(op)); 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "dM:N:o:t:v")) != -1) 6197c478bd9Sstevel@tonic-gate switch (c) 6207c478bd9Sstevel@tonic-gate { 6217c478bd9Sstevel@tonic-gate case 'd' : 6227c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG; 6237c478bd9Sstevel@tonic-gate break; 6247c478bd9Sstevel@tonic-gate case 'M' : 6257c478bd9Sstevel@tonic-gate live_kernel = 0; 6267c478bd9Sstevel@tonic-gate core = optarg; 6277c478bd9Sstevel@tonic-gate break; 6287c478bd9Sstevel@tonic-gate case 'N' : 6297c478bd9Sstevel@tonic-gate live_kernel = 0; 6307c478bd9Sstevel@tonic-gate kernel = optarg; 6317c478bd9Sstevel@tonic-gate break; 6327c478bd9Sstevel@tonic-gate case 'o' : 6337c478bd9Sstevel@tonic-gate role = getrole(optarg); 6347c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) { 6357c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown role '%s'\n", optarg); 6367c478bd9Sstevel@tonic-gate return -1; 6377c478bd9Sstevel@tonic-gate } 6387c478bd9Sstevel@tonic-gate break; 6397c478bd9Sstevel@tonic-gate case 't' : 6407c478bd9Sstevel@tonic-gate type = gettype(optarg, NULL); 6417c478bd9Sstevel@tonic-gate if (type != IPLT_POOL) { 6427c478bd9Sstevel@tonic-gate fprintf(stderr, 6437c478bd9Sstevel@tonic-gate "-s not supported for this type yet\n"); 6447c478bd9Sstevel@tonic-gate return -1; 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate break; 6477c478bd9Sstevel@tonic-gate case 'v' : 6487c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE; 6497c478bd9Sstevel@tonic-gate break; 6507c478bd9Sstevel@tonic-gate } 6517c478bd9Sstevel@tonic-gate 6527663b816Sml37995 if (opts & OPT_DEBUG) 6537663b816Sml37995 fprintf(stderr, "poolstats: opts = %#x\n", opts); 6547663b816Sml37995 6557c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING) && (fd == -1)) { 6567c478bd9Sstevel@tonic-gate fd = open(IPLOOKUP_NAME, O_RDWR); 6577c478bd9Sstevel@tonic-gate if (fd == -1) { 6587c478bd9Sstevel@tonic-gate perror("open(IPLOOKUP_NAME)"); 6597c478bd9Sstevel@tonic-gate exit(1); 6607c478bd9Sstevel@tonic-gate } 6617c478bd9Sstevel@tonic-gate } 6627c478bd9Sstevel@tonic-gate 6637663b816Sml37995 if (type == IPLT_ALL || type == IPLT_POOL) { 6647663b816Sml37995 op.iplo_type = IPLT_POOL; 6657663b816Sml37995 op.iplo_struct = &plstat; 6667663b816Sml37995 op.iplo_size = sizeof(plstat); 6677c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING)) { 6687c478bd9Sstevel@tonic-gate c = ioctl(fd, SIOCLOOKUPSTAT, &op); 6697c478bd9Sstevel@tonic-gate if (c == -1) { 6707c478bd9Sstevel@tonic-gate perror("ioctl(SIOCLOOKUPSTAT)"); 6717c478bd9Sstevel@tonic-gate return -1; 6727c478bd9Sstevel@tonic-gate } 6737c478bd9Sstevel@tonic-gate printf("Pools:\t%lu\n", plstat.ipls_pools); 6747c478bd9Sstevel@tonic-gate printf("Nodes:\t%lu\n", plstat.ipls_nodes); 6757c478bd9Sstevel@tonic-gate } 6767663b816Sml37995 } 6777663b816Sml37995 6787663b816Sml37995 if (type == IPLT_ALL || type == IPLT_HASH) { 6797663b816Sml37995 op.iplo_type = IPLT_HASH; 6807663b816Sml37995 op.iplo_struct = &htstat; 6817663b816Sml37995 op.iplo_size = sizeof(htstat); 6827663b816Sml37995 if (!(opts & OPT_DONOTHING)) { 6837663b816Sml37995 c = ioctl(fd, SIOCLOOKUPSTAT, &op); 6847663b816Sml37995 if (c == -1) { 6857663b816Sml37995 perror("ioctl(SIOCLOOKUPSTAT)"); 6867663b816Sml37995 return -1; 6877663b816Sml37995 } 6887663b816Sml37995 printf("Hash Tables:\t%lu\n", htstat.iphs_numtables); 6897663b816Sml37995 printf("Nodes:\t%lu\n", htstat.iphs_numnodes); 6907663b816Sml37995 printf("Out of Memory:\t%lu\n", htstat.iphs_nomem); 6917663b816Sml37995 } 6927663b816Sml37995 } 6937c478bd9Sstevel@tonic-gate return 0; 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate int poolflush(argc, argv) 6987c478bd9Sstevel@tonic-gate int argc; 6997c478bd9Sstevel@tonic-gate char *argv[]; 7007c478bd9Sstevel@tonic-gate { 7017c478bd9Sstevel@tonic-gate int c, role, type, arg; 7027c478bd9Sstevel@tonic-gate iplookupflush_t flush; 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate arg = IPLT_ALL; 7057c478bd9Sstevel@tonic-gate type = IPLT_ALL; 7067c478bd9Sstevel@tonic-gate role = IPL_LOGALL; 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "do:t:v")) != -1) 7097c478bd9Sstevel@tonic-gate switch (c) 7107c478bd9Sstevel@tonic-gate { 7117c478bd9Sstevel@tonic-gate case 'd' : 7127c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG; 7137c478bd9Sstevel@tonic-gate break; 7147c478bd9Sstevel@tonic-gate case 'o' : 7157c478bd9Sstevel@tonic-gate role = getrole(optarg); 7167c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) { 7177c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown role '%s'\n", optarg); 7187c478bd9Sstevel@tonic-gate return -1; 7197c478bd9Sstevel@tonic-gate } 7207c478bd9Sstevel@tonic-gate break; 7217c478bd9Sstevel@tonic-gate case 't' : 7227c478bd9Sstevel@tonic-gate type = gettype(optarg, NULL); 7237c478bd9Sstevel@tonic-gate if (type == IPLT_NONE) { 7247c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown type '%s'\n", optarg); 7257c478bd9Sstevel@tonic-gate return -1; 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate break; 7287c478bd9Sstevel@tonic-gate case 'v' : 7297c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE; 7307c478bd9Sstevel@tonic-gate break; 7317c478bd9Sstevel@tonic-gate } 7327c478bd9Sstevel@tonic-gate 733ab25eeb5Syz155240 if (opts & OPT_DEBUG) 734ab25eeb5Syz155240 fprintf(stderr, "poolflush: opts = %#x\n", opts); 735ab25eeb5Syz155240 7367c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING) && (fd == -1)) { 7377c478bd9Sstevel@tonic-gate fd = open(IPLOOKUP_NAME, O_RDWR); 7387c478bd9Sstevel@tonic-gate if (fd == -1) { 7397c478bd9Sstevel@tonic-gate perror("open(IPLOOKUP_NAME)"); 7407c478bd9Sstevel@tonic-gate exit(1); 7417c478bd9Sstevel@tonic-gate } 7427c478bd9Sstevel@tonic-gate } 7437c478bd9Sstevel@tonic-gate 7447c478bd9Sstevel@tonic-gate bzero((char *)&flush, sizeof(flush)); 7457c478bd9Sstevel@tonic-gate flush.iplf_type = type; 7467c478bd9Sstevel@tonic-gate flush.iplf_unit = role; 7477c478bd9Sstevel@tonic-gate flush.iplf_arg = arg; 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING)) { 7507c478bd9Sstevel@tonic-gate if (ioctl(fd, SIOCLOOKUPFLUSH, &flush) == -1) { 7517c478bd9Sstevel@tonic-gate perror("ioctl(SIOCLOOKUPFLUSH)"); 7527c478bd9Sstevel@tonic-gate exit(1); 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate } 7567c478bd9Sstevel@tonic-gate printf("%u object%s flushed\n", flush.iplf_count, 7577c478bd9Sstevel@tonic-gate (flush.iplf_count == 1) ? "" : "s"); 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate return 0; 7607c478bd9Sstevel@tonic-gate } 7617c478bd9Sstevel@tonic-gate 7627c478bd9Sstevel@tonic-gate 7637c478bd9Sstevel@tonic-gate int getrole(rolename) 7647c478bd9Sstevel@tonic-gate char *rolename; 7657c478bd9Sstevel@tonic-gate { 7667c478bd9Sstevel@tonic-gate int role; 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate if (!strcasecmp(rolename, "ipf")) { 7697c478bd9Sstevel@tonic-gate role = IPL_LOGIPF; 7707c478bd9Sstevel@tonic-gate #if 0 7717c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "nat")) { 7727c478bd9Sstevel@tonic-gate role = IPL_LOGNAT; 7737c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "state")) { 7747c478bd9Sstevel@tonic-gate role = IPL_LOGSTATE; 7757c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "auth")) { 7767c478bd9Sstevel@tonic-gate role = IPL_LOGAUTH; 7777c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "sync")) { 7787c478bd9Sstevel@tonic-gate role = IPL_LOGSYNC; 7797c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "scan")) { 7807c478bd9Sstevel@tonic-gate role = IPL_LOGSCAN; 7817c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "pool")) { 7827c478bd9Sstevel@tonic-gate role = IPL_LOGLOOKUP; 7837c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "count")) { 7847c478bd9Sstevel@tonic-gate role = IPL_LOGCOUNT; 7857c478bd9Sstevel@tonic-gate #endif 7867c478bd9Sstevel@tonic-gate } else { 7877c478bd9Sstevel@tonic-gate role = IPL_LOGNONE; 7887c478bd9Sstevel@tonic-gate } 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate return role; 7917c478bd9Sstevel@tonic-gate } 7927c478bd9Sstevel@tonic-gate 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate int gettype(typename, minor) 7957c478bd9Sstevel@tonic-gate char *typename; 7967c478bd9Sstevel@tonic-gate u_int *minor; 7977c478bd9Sstevel@tonic-gate { 7987c478bd9Sstevel@tonic-gate int type; 7997c478bd9Sstevel@tonic-gate 800ab25eeb5Syz155240 if (!strcasecmp(optarg, "tree")) { 8017c478bd9Sstevel@tonic-gate type = IPLT_POOL; 8027c478bd9Sstevel@tonic-gate } else if (!strcasecmp(optarg, "hash")) { 8037c478bd9Sstevel@tonic-gate type = IPLT_HASH; 8047c478bd9Sstevel@tonic-gate if (minor != NULL) 8057c478bd9Sstevel@tonic-gate *minor = IPHASH_LOOKUP; 8067c478bd9Sstevel@tonic-gate } else if (!strcasecmp(optarg, "group-map")) { 8077c478bd9Sstevel@tonic-gate type = IPLT_HASH; 8087c478bd9Sstevel@tonic-gate if (minor != NULL) 8097c478bd9Sstevel@tonic-gate *minor = IPHASH_GROUPMAP; 8107c478bd9Sstevel@tonic-gate } else { 8117c478bd9Sstevel@tonic-gate type = IPLT_NONE; 8127c478bd9Sstevel@tonic-gate } 8137c478bd9Sstevel@tonic-gate return type; 8147c478bd9Sstevel@tonic-gate } 815*f4b3ec61Sdh155122 816*f4b3ec61Sdh155122 void showhashs_live(fd, role, htstp, poolname, opts) 817*f4b3ec61Sdh155122 int fd, role; 818*f4b3ec61Sdh155122 iphtstat_t *htstp; 819*f4b3ec61Sdh155122 char *poolname; 820*f4b3ec61Sdh155122 int opts; 821*f4b3ec61Sdh155122 { 822*f4b3ec61Sdh155122 ipflookupiter_t iter; 823*f4b3ec61Sdh155122 iphtable_t table; 824*f4b3ec61Sdh155122 ipfobj_t obj; 825*f4b3ec61Sdh155122 826*f4b3ec61Sdh155122 obj.ipfo_rev = IPFILTER_VERSION; 827*f4b3ec61Sdh155122 obj.ipfo_type = IPFOBJ_LOOKUPITER; 828*f4b3ec61Sdh155122 obj.ipfo_size = sizeof(iter); 829*f4b3ec61Sdh155122 obj.ipfo_ptr = &iter; 830*f4b3ec61Sdh155122 831*f4b3ec61Sdh155122 iter.ili_type = IPLT_HASH; 832*f4b3ec61Sdh155122 iter.ili_otype = IPFLOOKUPITER_LIST; 833*f4b3ec61Sdh155122 iter.ili_ival = IPFGENITER_LOOKUP; 834*f4b3ec61Sdh155122 iter.ili_data = &table; 835*f4b3ec61Sdh155122 iter.ili_unit = role; 836*f4b3ec61Sdh155122 *iter.ili_name = '\0'; 837*f4b3ec61Sdh155122 838*f4b3ec61Sdh155122 while (htstp->iphs_tables != NULL) { 839*f4b3ec61Sdh155122 if (ioctl(fd, SIOCLOOKUPITER, &obj)) { 840*f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPITER)"); 841*f4b3ec61Sdh155122 break; 842*f4b3ec61Sdh155122 } 843*f4b3ec61Sdh155122 844*f4b3ec61Sdh155122 printhash_live(&table, fd, poolname, opts); 845*f4b3ec61Sdh155122 846*f4b3ec61Sdh155122 htstp->iphs_tables = table.iph_next; 847*f4b3ec61Sdh155122 } 848*f4b3ec61Sdh155122 } 849