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 *
6f4b3ec61Sdh155122 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
77c478bd9Sstevel@tonic-gate * Use is subject to license terms.
8*94bdecd9SRob Gulewich *
9*94bdecd9SRob Gulewich * Copyright (c) 2014, Joyent, Inc. All rights reserved.
107c478bd9Sstevel@tonic-gate */
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>
36f4b3ec61Sdh155122 #include <nlist.h>
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate #include "ipf.h"
39f4b3ec61Sdh155122 #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"
44*94bdecd9SRob Gulewich #include "ipfzone.h"
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate extern int ippool_yyparse __P((void));
477c478bd9Sstevel@tonic-gate extern int ippool_yydebug;
487c478bd9Sstevel@tonic-gate extern FILE *ippool_yyin;
497c478bd9Sstevel@tonic-gate extern char *optarg;
507c478bd9Sstevel@tonic-gate extern int lineNum;
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate void showpools __P((ip_pool_stat_t *));
537c478bd9Sstevel@tonic-gate void usage __P((char *));
547c478bd9Sstevel@tonic-gate int main __P((int, char **));
557c478bd9Sstevel@tonic-gate int poolcommand __P((int, int, char *[]));
567c478bd9Sstevel@tonic-gate int poolnodecommand __P((int, int, char *[]));
577c478bd9Sstevel@tonic-gate int loadpoolfile __P((int, char *[], char *));
587c478bd9Sstevel@tonic-gate int poollist __P((int, char *[]));
597c478bd9Sstevel@tonic-gate int poolflush __P((int, char *[]));
607c478bd9Sstevel@tonic-gate int poolstats __P((int, char *[]));
617c478bd9Sstevel@tonic-gate int gettype __P((char *, u_int *));
627c478bd9Sstevel@tonic-gate int getrole __P((char *));
63f4b3ec61Sdh155122 void poollist_dead __P((int, char *, int, char *, char *));
64f4b3ec61Sdh155122 void showpools_live(int, int, ip_pool_stat_t *, char *, int);
65f4b3ec61Sdh155122 void showhashs_live(int, int, iphtstat_t *, char *, int);
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate int opts = 0;
687c478bd9Sstevel@tonic-gate int fd = -1;
697c478bd9Sstevel@tonic-gate int use_inet6 = 0;
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate
usage(prog)727c478bd9Sstevel@tonic-gate void usage(prog)
737c478bd9Sstevel@tonic-gate char *prog;
747c478bd9Sstevel@tonic-gate {
75*94bdecd9SRob Gulewich const char *zoneopt = "[-G|-z zonename] ";
767c478bd9Sstevel@tonic-gate fprintf(stderr, "Usage:\t%s\n", prog);
77*94bdecd9SRob Gulewich fprintf(stderr, "\t\t\t-a [-dnv] %s[-m <name>] [-o <role>] -i <ipaddr>[/netmask]\n",
78*94bdecd9SRob Gulewich zoneopt);
79*94bdecd9SRob Gulewich fprintf(stderr, "\t\t\t-A [-dnv] %s[-m <name>] [-o <role>] [-S <seed>] [-t <type>]\n",
80*94bdecd9SRob Gulewich zoneopt);
81*94bdecd9SRob Gulewich fprintf(stderr, "\t\t\t-f <file> %s[-dnuv]\n", zoneopt);
82*94bdecd9SRob Gulewich fprintf(stderr, "\t\t\t-F [-dv] %s[-o <role>] [-t <type>]\n", zoneopt);
83*94bdecd9SRob Gulewich fprintf(stderr, "\t\t\t-l [-dv] %s[-m <name>] [-t <type>]\n", zoneopt);
84*94bdecd9SRob Gulewich fprintf(stderr, "\t\t\t-r [-dnv] %s[-m <name>] [-o <role>] -i <ipaddr>[/netmask]\n",
85*94bdecd9SRob Gulewich zoneopt);
86*94bdecd9SRob Gulewich fprintf(stderr, "\t\t\t-R [-dnv] %s[-m <name>] [-o <role>] [-t <type>]\n",
87*94bdecd9SRob Gulewich zoneopt);
88*94bdecd9SRob Gulewich fprintf(stderr, "\t\t\t-s [-dtv] %s[-M <core>] [-N <namelist>]\n",
89*94bdecd9SRob Gulewich zoneopt);
907c478bd9Sstevel@tonic-gate exit(1);
917c478bd9Sstevel@tonic-gate }
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate
main(argc,argv)947c478bd9Sstevel@tonic-gate int main(argc, argv)
957c478bd9Sstevel@tonic-gate int argc;
967c478bd9Sstevel@tonic-gate char *argv[];
977c478bd9Sstevel@tonic-gate {
987c478bd9Sstevel@tonic-gate int err;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate if (argc < 2)
1017c478bd9Sstevel@tonic-gate usage(argv[0]);
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate switch (getopt(argc, argv, "aAf:FlrRs"))
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate case 'a' :
1067c478bd9Sstevel@tonic-gate err = poolnodecommand(0, argc, argv);
1077c478bd9Sstevel@tonic-gate break;
1087c478bd9Sstevel@tonic-gate case 'A' :
1097c478bd9Sstevel@tonic-gate err = poolcommand(0, argc, argv);
1107c478bd9Sstevel@tonic-gate break;
1117c478bd9Sstevel@tonic-gate case 'f' :
1127c478bd9Sstevel@tonic-gate err = loadpoolfile(argc, argv, optarg);
1137c478bd9Sstevel@tonic-gate break;
1147c478bd9Sstevel@tonic-gate case 'F' :
1157c478bd9Sstevel@tonic-gate err = poolflush(argc, argv);
1167c478bd9Sstevel@tonic-gate break;
1177c478bd9Sstevel@tonic-gate case 'l' :
1187c478bd9Sstevel@tonic-gate err = poollist(argc, argv);
1197c478bd9Sstevel@tonic-gate break;
1207c478bd9Sstevel@tonic-gate case 'r' :
1217c478bd9Sstevel@tonic-gate err = poolnodecommand(1, argc, argv);
1227c478bd9Sstevel@tonic-gate break;
1237c478bd9Sstevel@tonic-gate case 'R' :
1247c478bd9Sstevel@tonic-gate err = poolcommand(1, argc, argv);
1257c478bd9Sstevel@tonic-gate break;
1267c478bd9Sstevel@tonic-gate case 's' :
1277c478bd9Sstevel@tonic-gate err = poolstats(argc, argv);
1287c478bd9Sstevel@tonic-gate break;
1297c478bd9Sstevel@tonic-gate default :
1307c478bd9Sstevel@tonic-gate exit(1);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate return err;
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate
poolnodecommand(remove,argc,argv)1377c478bd9Sstevel@tonic-gate int poolnodecommand(remove, argc, argv)
1387c478bd9Sstevel@tonic-gate int remove, argc;
1397c478bd9Sstevel@tonic-gate char *argv[];
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate char *poolname = NULL, *s;
1427c478bd9Sstevel@tonic-gate int err, c, ipset, role;
1437c478bd9Sstevel@tonic-gate ip_pool_node_t node;
1447c478bd9Sstevel@tonic-gate struct in_addr mask;
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate ipset = 0;
1477c478bd9Sstevel@tonic-gate role = IPL_LOGIPF;
1487c478bd9Sstevel@tonic-gate bzero((char *)&node, sizeof(node));
1497c478bd9Sstevel@tonic-gate
150*94bdecd9SRob Gulewich while ((c = getopt(argc, argv, "di:G:m:no:Rvz:")) != -1)
1517c478bd9Sstevel@tonic-gate switch (c)
1527c478bd9Sstevel@tonic-gate {
1537c478bd9Sstevel@tonic-gate case 'd' :
1547c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG;
1557c478bd9Sstevel@tonic-gate ippool_yydebug++;
1567c478bd9Sstevel@tonic-gate break;
157*94bdecd9SRob Gulewich case 'G' :
158*94bdecd9SRob Gulewich setzonename_global(optarg);
159*94bdecd9SRob Gulewich break;
1607c478bd9Sstevel@tonic-gate case 'i' :
1617c478bd9Sstevel@tonic-gate s = strchr(optarg, '/');
1627c478bd9Sstevel@tonic-gate if (s == NULL)
1637c478bd9Sstevel@tonic-gate mask.s_addr = 0xffffffff;
1647c478bd9Sstevel@tonic-gate else if (strchr(s, '.') == NULL) {
1657c478bd9Sstevel@tonic-gate if (ntomask(4, atoi(s + 1), &mask.s_addr) != 0)
1667c478bd9Sstevel@tonic-gate return -1;
1677c478bd9Sstevel@tonic-gate } else {
1687c478bd9Sstevel@tonic-gate mask.s_addr = inet_addr(s + 1);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate if (s != NULL)
1717c478bd9Sstevel@tonic-gate *s = '\0';
1727c478bd9Sstevel@tonic-gate ipset = 1;
173ab25eeb5Syz155240 node.ipn_addr.adf_len = sizeof(node.ipn_addr);
1747c478bd9Sstevel@tonic-gate node.ipn_addr.adf_addr.in4.s_addr = inet_addr(optarg);
175ab25eeb5Syz155240 node.ipn_mask.adf_len = sizeof(node.ipn_mask);
1767c478bd9Sstevel@tonic-gate node.ipn_mask.adf_addr.in4.s_addr = mask.s_addr;
1777c478bd9Sstevel@tonic-gate break;
1787c478bd9Sstevel@tonic-gate case 'm' :
1797c478bd9Sstevel@tonic-gate poolname = optarg;
1807c478bd9Sstevel@tonic-gate break;
1817c478bd9Sstevel@tonic-gate case 'n' :
1827c478bd9Sstevel@tonic-gate opts |= OPT_DONOTHING;
1837c478bd9Sstevel@tonic-gate break;
1847c478bd9Sstevel@tonic-gate case 'o' :
1857c478bd9Sstevel@tonic-gate role = getrole(optarg);
1867c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE)
1877c478bd9Sstevel@tonic-gate return -1;
1887c478bd9Sstevel@tonic-gate break;
189ab25eeb5Syz155240 case 'R' :
190ab25eeb5Syz155240 opts |= OPT_NORESOLVE;
191ab25eeb5Syz155240 break;
1927c478bd9Sstevel@tonic-gate case 'v' :
1937c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE;
1947c478bd9Sstevel@tonic-gate break;
195*94bdecd9SRob Gulewich case 'z' :
196*94bdecd9SRob Gulewich setzonename(optarg);
197*94bdecd9SRob Gulewich break;
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
200ab25eeb5Syz155240 if (opts & OPT_DEBUG)
201ab25eeb5Syz155240 fprintf(stderr, "poolnodecommand: opts = %#x\n", opts);
202ab25eeb5Syz155240
2037c478bd9Sstevel@tonic-gate if (ipset == 0)
2047c478bd9Sstevel@tonic-gate return -1;
2057c478bd9Sstevel@tonic-gate if (poolname == NULL) {
2067c478bd9Sstevel@tonic-gate fprintf(stderr, "poolname not given with add/remove node\n");
2077c478bd9Sstevel@tonic-gate return -1;
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate if (remove == 0)
2117c478bd9Sstevel@tonic-gate err = load_poolnode(0, poolname, &node, ioctl);
2127c478bd9Sstevel@tonic-gate else
2137c478bd9Sstevel@tonic-gate err = remove_poolnode(0, poolname, &node, ioctl);
2147c478bd9Sstevel@tonic-gate return err;
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate
poolcommand(remove,argc,argv)2187c478bd9Sstevel@tonic-gate int poolcommand(remove, argc, argv)
2197c478bd9Sstevel@tonic-gate int remove, argc;
2207c478bd9Sstevel@tonic-gate char *argv[];
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate int type, role, c, err;
2237c478bd9Sstevel@tonic-gate char *poolname;
2247c478bd9Sstevel@tonic-gate iphtable_t iph;
2257c478bd9Sstevel@tonic-gate ip_pool_t pool;
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate err = 1;
2287c478bd9Sstevel@tonic-gate role = 0;
2297c478bd9Sstevel@tonic-gate type = 0;
2307c478bd9Sstevel@tonic-gate poolname = NULL;
2317c478bd9Sstevel@tonic-gate role = IPL_LOGIPF;
2327c478bd9Sstevel@tonic-gate bzero((char *)&iph, sizeof(iph));
2337c478bd9Sstevel@tonic-gate bzero((char *)&pool, sizeof(pool));
2347c478bd9Sstevel@tonic-gate
235*94bdecd9SRob Gulewich while ((c = getopt(argc, argv, "dG:m:no:RS:t:vz:")) != -1)
2367c478bd9Sstevel@tonic-gate switch (c)
2377c478bd9Sstevel@tonic-gate {
2387c478bd9Sstevel@tonic-gate case 'd' :
2397c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG;
2407c478bd9Sstevel@tonic-gate ippool_yydebug++;
2417c478bd9Sstevel@tonic-gate break;
242*94bdecd9SRob Gulewich case 'G' :
243*94bdecd9SRob Gulewich setzonename_global(optarg);
244*94bdecd9SRob Gulewich break;
2457c478bd9Sstevel@tonic-gate case 'm' :
2467c478bd9Sstevel@tonic-gate poolname = optarg;
2477c478bd9Sstevel@tonic-gate break;
2487c478bd9Sstevel@tonic-gate case 'n' :
2497c478bd9Sstevel@tonic-gate opts |= OPT_DONOTHING;
2507c478bd9Sstevel@tonic-gate break;
2517c478bd9Sstevel@tonic-gate case 'o' :
2527c478bd9Sstevel@tonic-gate role = getrole(optarg);
2537c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) {
2547c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown role '%s'\n", optarg);
2557c478bd9Sstevel@tonic-gate return -1;
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate break;
258ab25eeb5Syz155240 case 'R' :
259ab25eeb5Syz155240 opts |= OPT_NORESOLVE;
260ab25eeb5Syz155240 break;
2617c478bd9Sstevel@tonic-gate case 'S' :
2627c478bd9Sstevel@tonic-gate iph.iph_seed = atoi(optarg);
2637c478bd9Sstevel@tonic-gate break;
2647c478bd9Sstevel@tonic-gate case 't' :
2657c478bd9Sstevel@tonic-gate type = gettype(optarg, &iph.iph_type);
2667c478bd9Sstevel@tonic-gate if (type == IPLT_NONE) {
2677c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown type '%s'\n", optarg);
2687c478bd9Sstevel@tonic-gate return -1;
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate break;
2717c478bd9Sstevel@tonic-gate case 'v' :
2727c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE;
2737c478bd9Sstevel@tonic-gate break;
274*94bdecd9SRob Gulewich case 'z' :
275*94bdecd9SRob Gulewich setzonename(optarg);
276*94bdecd9SRob Gulewich break;
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate
279ab25eeb5Syz155240 if (opts & OPT_DEBUG)
280ab25eeb5Syz155240 fprintf(stderr, "poolcommand: opts = %#x\n", opts);
281ab25eeb5Syz155240
2827c478bd9Sstevel@tonic-gate if (poolname == NULL) {
2837c478bd9Sstevel@tonic-gate fprintf(stderr, "poolname not given with add/remove pool\n");
2847c478bd9Sstevel@tonic-gate return -1;
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate if (type == IPLT_HASH) {
2887c478bd9Sstevel@tonic-gate strncpy(iph.iph_name, poolname, sizeof(iph.iph_name));
2897c478bd9Sstevel@tonic-gate iph.iph_name[sizeof(iph.iph_name) - 1] = '\0';
2907c478bd9Sstevel@tonic-gate iph.iph_unit = role;
2917c478bd9Sstevel@tonic-gate } else if (type == IPLT_POOL) {
2927c478bd9Sstevel@tonic-gate strncpy(pool.ipo_name, poolname, sizeof(pool.ipo_name));
2937c478bd9Sstevel@tonic-gate pool.ipo_name[sizeof(pool.ipo_name) - 1] = '\0';
2947c478bd9Sstevel@tonic-gate pool.ipo_unit = role;
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate if (remove == 0) {
2987c478bd9Sstevel@tonic-gate switch (type)
2997c478bd9Sstevel@tonic-gate {
3007c478bd9Sstevel@tonic-gate case IPLT_HASH :
3017c478bd9Sstevel@tonic-gate err = load_hash(&iph, NULL, ioctl);
3027c478bd9Sstevel@tonic-gate break;
3037c478bd9Sstevel@tonic-gate case IPLT_POOL :
3047c478bd9Sstevel@tonic-gate err = load_pool(&pool, ioctl);
3057c478bd9Sstevel@tonic-gate break;
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate } else {
3087c478bd9Sstevel@tonic-gate switch (type)
3097c478bd9Sstevel@tonic-gate {
3107c478bd9Sstevel@tonic-gate case IPLT_HASH :
3117c478bd9Sstevel@tonic-gate err = remove_hash(&iph, ioctl);
3127c478bd9Sstevel@tonic-gate break;
3137c478bd9Sstevel@tonic-gate case IPLT_POOL :
3147c478bd9Sstevel@tonic-gate err = remove_pool(&pool, ioctl);
3157c478bd9Sstevel@tonic-gate break;
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate return err;
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate
loadpoolfile(argc,argv,infile)3227c478bd9Sstevel@tonic-gate int loadpoolfile(argc, argv, infile)
3237c478bd9Sstevel@tonic-gate int argc;
3247c478bd9Sstevel@tonic-gate char *argv[], *infile;
3257c478bd9Sstevel@tonic-gate {
3267c478bd9Sstevel@tonic-gate int c;
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate infile = optarg;
3297c478bd9Sstevel@tonic-gate
330*94bdecd9SRob Gulewich while ((c = getopt(argc, argv, "dG:nRuvz:")) != -1)
3317c478bd9Sstevel@tonic-gate switch (c)
3327c478bd9Sstevel@tonic-gate {
3337c478bd9Sstevel@tonic-gate case 'd' :
3347c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG;
3357c478bd9Sstevel@tonic-gate ippool_yydebug++;
3367c478bd9Sstevel@tonic-gate break;
337*94bdecd9SRob Gulewich case 'G' :
338*94bdecd9SRob Gulewich setzonename_global(optarg);
339*94bdecd9SRob Gulewich break;
3407c478bd9Sstevel@tonic-gate case 'n' :
3417c478bd9Sstevel@tonic-gate opts |= OPT_DONOTHING;
3427c478bd9Sstevel@tonic-gate break;
343ab25eeb5Syz155240 case 'R' :
344ab25eeb5Syz155240 opts |= OPT_NORESOLVE;
345ab25eeb5Syz155240 break;
346ab25eeb5Syz155240 case 'u' :
3477c478bd9Sstevel@tonic-gate opts |= OPT_REMOVE;
3487c478bd9Sstevel@tonic-gate break;
3497c478bd9Sstevel@tonic-gate case 'v' :
3507c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE;
3517c478bd9Sstevel@tonic-gate break;
352*94bdecd9SRob Gulewich case 'z' :
353*94bdecd9SRob Gulewich setzonename(optarg);
354*94bdecd9SRob Gulewich break;
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate
357ab25eeb5Syz155240 if (opts & OPT_DEBUG)
358ab25eeb5Syz155240 fprintf(stderr, "loadpoolfile: opts = %#x\n", opts);
359ab25eeb5Syz155240
3607c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING) && (fd == -1)) {
3617c478bd9Sstevel@tonic-gate fd = open(IPLOOKUP_NAME, O_RDWR);
3627c478bd9Sstevel@tonic-gate if (fd == -1) {
3637c478bd9Sstevel@tonic-gate perror("open(IPLOOKUP_NAME)");
3647c478bd9Sstevel@tonic-gate exit(1);
3657c478bd9Sstevel@tonic-gate }
366*94bdecd9SRob Gulewich
367*94bdecd9SRob Gulewich if (setzone(fd) != 0) {
368*94bdecd9SRob Gulewich close(fd);
369*94bdecd9SRob Gulewich exit(1);
370*94bdecd9SRob Gulewich }
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate if (ippool_parsefile(fd, infile, ioctl) != 0)
3747c478bd9Sstevel@tonic-gate return -1;
3757c478bd9Sstevel@tonic-gate return 0;
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate
poollist(argc,argv)3797c478bd9Sstevel@tonic-gate int poollist(argc, argv)
3807c478bd9Sstevel@tonic-gate int argc;
3817c478bd9Sstevel@tonic-gate char *argv[];
3827c478bd9Sstevel@tonic-gate {
3837c478bd9Sstevel@tonic-gate char *kernel, *core, *poolname;
3847c478bd9Sstevel@tonic-gate int c, role, type, live_kernel;
3857c478bd9Sstevel@tonic-gate ip_pool_stat_t *plstp, plstat;
3867663b816Sml37995 iphtstat_t *htstp, htstat;
3877663b816Sml37995 iphtable_t *hptr;
3887c478bd9Sstevel@tonic-gate iplookupop_t op;
3897c478bd9Sstevel@tonic-gate ip_pool_t *ptr;
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate core = NULL;
3927c478bd9Sstevel@tonic-gate kernel = NULL;
3937c478bd9Sstevel@tonic-gate live_kernel = 1;
3947c478bd9Sstevel@tonic-gate type = IPLT_ALL;
3957c478bd9Sstevel@tonic-gate poolname = NULL;
3967c478bd9Sstevel@tonic-gate role = IPL_LOGALL;
3977c478bd9Sstevel@tonic-gate
398*94bdecd9SRob Gulewich while ((c = getopt(argc, argv, "dG:m:M:N:o:Rt:vz:")) != -1)
3997c478bd9Sstevel@tonic-gate switch (c)
4007c478bd9Sstevel@tonic-gate {
4017c478bd9Sstevel@tonic-gate case 'd' :
4027c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG;
4037c478bd9Sstevel@tonic-gate break;
404*94bdecd9SRob Gulewich case 'G' :
405*94bdecd9SRob Gulewich setzonename_global(optarg);
406*94bdecd9SRob Gulewich break;
4077c478bd9Sstevel@tonic-gate case 'm' :
4087c478bd9Sstevel@tonic-gate poolname = optarg;
4097c478bd9Sstevel@tonic-gate break;
4107c478bd9Sstevel@tonic-gate case 'M' :
4117c478bd9Sstevel@tonic-gate live_kernel = 0;
4127c478bd9Sstevel@tonic-gate core = optarg;
4137c478bd9Sstevel@tonic-gate break;
4147c478bd9Sstevel@tonic-gate case 'N' :
4157c478bd9Sstevel@tonic-gate live_kernel = 0;
4167c478bd9Sstevel@tonic-gate kernel = optarg;
4177c478bd9Sstevel@tonic-gate break;
4187c478bd9Sstevel@tonic-gate case 'o' :
4197c478bd9Sstevel@tonic-gate role = getrole(optarg);
4207c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) {
4217c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown role '%s'\n", optarg);
4227c478bd9Sstevel@tonic-gate return -1;
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate break;
425ab25eeb5Syz155240 case 'R' :
426ab25eeb5Syz155240 opts |= OPT_NORESOLVE;
427ab25eeb5Syz155240 break;
4287c478bd9Sstevel@tonic-gate case 't' :
4297c478bd9Sstevel@tonic-gate type = gettype(optarg, NULL);
4307c478bd9Sstevel@tonic-gate if (type == IPLT_NONE) {
4317c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown type '%s'\n", optarg);
4327c478bd9Sstevel@tonic-gate return -1;
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate break;
4357c478bd9Sstevel@tonic-gate case 'v' :
4367c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE;
4377c478bd9Sstevel@tonic-gate break;
438*94bdecd9SRob Gulewich case 'z' :
439*94bdecd9SRob Gulewich setzonename(optarg);
440*94bdecd9SRob Gulewich break;
4417c478bd9Sstevel@tonic-gate }
4427c478bd9Sstevel@tonic-gate
4437663b816Sml37995 if (opts & OPT_DEBUG)
4447663b816Sml37995 fprintf(stderr, "poollist: opts = %#x\n", opts);
4457663b816Sml37995
4467c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING) && (fd == -1)) {
4477c478bd9Sstevel@tonic-gate fd = open(IPLOOKUP_NAME, O_RDWR);
4487c478bd9Sstevel@tonic-gate if (fd == -1) {
4497c478bd9Sstevel@tonic-gate perror("open(IPLOOKUP_NAME)");
4507c478bd9Sstevel@tonic-gate exit(1);
4517c478bd9Sstevel@tonic-gate }
452*94bdecd9SRob Gulewich
453*94bdecd9SRob Gulewich if (setzone(fd) != 0) {
454*94bdecd9SRob Gulewich close(fd);
455*94bdecd9SRob Gulewich exit(1);
456*94bdecd9SRob Gulewich }
4577c478bd9Sstevel@tonic-gate }
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate bzero((char *)&op, sizeof(op));
4607c478bd9Sstevel@tonic-gate if (poolname != NULL) {
4617c478bd9Sstevel@tonic-gate strncpy(op.iplo_name, poolname, sizeof(op.iplo_name));
4627c478bd9Sstevel@tonic-gate op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate op.iplo_unit = role;
4657663b816Sml37995
466f4b3ec61Sdh155122 if (live_kernel == 0) {
467f4b3ec61Sdh155122 poollist_dead(role, poolname, type, kernel, core);
468f4b3ec61Sdh155122 return (0);
469f4b3ec61Sdh155122 }
4707663b816Sml37995
4717663b816Sml37995 if (type == IPLT_ALL || type == IPLT_POOL) {
4727663b816Sml37995 plstp = &plstat;
4737663b816Sml37995 op.iplo_type = IPLT_POOL;
4747c478bd9Sstevel@tonic-gate op.iplo_size = sizeof(plstat);
4757c478bd9Sstevel@tonic-gate op.iplo_struct = &plstat;
476f4b3ec61Sdh155122 op.iplo_name[0] = '\0';
477f4b3ec61Sdh155122 op.iplo_arg = 0;
478f4b3ec61Sdh155122
479f4b3ec61Sdh155122 if (role != IPL_LOGALL) {
480f4b3ec61Sdh155122 op.iplo_unit = role;
481f4b3ec61Sdh155122
4827c478bd9Sstevel@tonic-gate c = ioctl(fd, SIOCLOOKUPSTAT, &op);
4837c478bd9Sstevel@tonic-gate if (c == -1) {
4847c478bd9Sstevel@tonic-gate perror("ioctl(SIOCLOOKUPSTAT)");
4857c478bd9Sstevel@tonic-gate return -1;
4867c478bd9Sstevel@tonic-gate }
4877c478bd9Sstevel@tonic-gate
488f4b3ec61Sdh155122 showpools_live(fd, role, &plstat, poolname, opts);
489f4b3ec61Sdh155122 } else {
490f4b3ec61Sdh155122 for (role = 0; role <= IPL_LOGMAX; role++) {
491f4b3ec61Sdh155122 op.iplo_unit = role;
492f4b3ec61Sdh155122
493f4b3ec61Sdh155122 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
494f4b3ec61Sdh155122 if (c == -1) {
495f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPSTAT)");
496f4b3ec61Sdh155122 return -1;
497f4b3ec61Sdh155122 }
498f4b3ec61Sdh155122
499f4b3ec61Sdh155122 showpools_live(fd, role, &plstat, poolname, opts);
500f4b3ec61Sdh155122 }
501f4b3ec61Sdh155122
502f4b3ec61Sdh155122 role = IPL_LOGALL;
503f4b3ec61Sdh155122 }
504f4b3ec61Sdh155122 }
505f4b3ec61Sdh155122 if (type == IPLT_ALL || type == IPLT_HASH) {
506f4b3ec61Sdh155122 htstp = &htstat;
507f4b3ec61Sdh155122 op.iplo_type = IPLT_HASH;
508f4b3ec61Sdh155122 op.iplo_size = sizeof(htstat);
509f4b3ec61Sdh155122 op.iplo_struct = &htstat;
510f4b3ec61Sdh155122 op.iplo_name[0] = '\0';
511f4b3ec61Sdh155122 op.iplo_arg = 0;
512f4b3ec61Sdh155122
5137c478bd9Sstevel@tonic-gate if (role != IPL_LOGALL) {
514f4b3ec61Sdh155122 op.iplo_unit = role;
515f4b3ec61Sdh155122
516f4b3ec61Sdh155122 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
517f4b3ec61Sdh155122 if (c == -1) {
518f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPSTAT)");
519f4b3ec61Sdh155122 return -1;
520f4b3ec61Sdh155122 }
521f4b3ec61Sdh155122 showhashs_live(fd, role, &htstat, poolname, opts);
522f4b3ec61Sdh155122 } else {
523f4b3ec61Sdh155122 for (role = 0; role <= IPL_LOGMAX; role++) {
524f4b3ec61Sdh155122
525f4b3ec61Sdh155122 op.iplo_unit = role;
526f4b3ec61Sdh155122 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
527f4b3ec61Sdh155122 if (c == -1) {
528f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPSTAT)");
529f4b3ec61Sdh155122 return -1;
530f4b3ec61Sdh155122 }
531f4b3ec61Sdh155122
532f4b3ec61Sdh155122 showhashs_live(fd, role, &htstat, poolname, opts);
533f4b3ec61Sdh155122 }
534f4b3ec61Sdh155122 }
535f4b3ec61Sdh155122 }
536f4b3ec61Sdh155122 return 0;
537f4b3ec61Sdh155122 }
538f4b3ec61Sdh155122
poollist_dead(role,poolname,type,kernel,core)539f4b3ec61Sdh155122 void poollist_dead(role, poolname, type, kernel, core)
540f4b3ec61Sdh155122 int role, type;
541f4b3ec61Sdh155122 char *poolname, *kernel, *core;
542f4b3ec61Sdh155122 {
543f4b3ec61Sdh155122 iphtable_t *hptr;
544f4b3ec61Sdh155122 ip_pool_t *ptr;
545f4b3ec61Sdh155122
546f4b3ec61Sdh155122 if (openkmem(kernel, core) == -1)
547f4b3ec61Sdh155122 exit(-1);
548f4b3ec61Sdh155122
549f4b3ec61Sdh155122 if (type == IPLT_ALL || type == IPLT_POOL) {
550f4b3ec61Sdh155122 ip_pool_t *pools[IPL_LOGSIZE];
551f4b3ec61Sdh155122 struct nlist names[2] = { { "ip_pool_list" } , { "" } };
552f4b3ec61Sdh155122
553f4b3ec61Sdh155122 if (nlist(kernel, names) != 1)
554f4b3ec61Sdh155122 return;
555f4b3ec61Sdh155122
556f4b3ec61Sdh155122 bzero(&pools, sizeof(pools));
557f4b3ec61Sdh155122 if (kmemcpy((char *)&pools, names[0].n_value, sizeof(pools)))
558f4b3ec61Sdh155122 return;
559f4b3ec61Sdh155122
560f4b3ec61Sdh155122 if (role != IPL_LOGALL) {
561f4b3ec61Sdh155122 ptr = pools[role];
5627c478bd9Sstevel@tonic-gate while (ptr != NULL) {
563f4b3ec61Sdh155122 ptr = printpool(ptr, kmemcpywrap,
564f4b3ec61Sdh155122 poolname, opts);
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate } else {
5677c478bd9Sstevel@tonic-gate for (role = 0; role <= IPL_LOGMAX; role++) {
568f4b3ec61Sdh155122 ptr = pools[role];
5697c478bd9Sstevel@tonic-gate while (ptr != NULL) {
5707663b816Sml37995 ptr = printpool(ptr, kmemcpywrap,
571ab25eeb5Syz155240 poolname, opts);
5727663b816Sml37995 }
5737663b816Sml37995 }
5747663b816Sml37995 role = IPL_LOGALL;
5757663b816Sml37995 }
5767663b816Sml37995 }
5777663b816Sml37995 if (type == IPLT_ALL || type == IPLT_HASH) {
578f4b3ec61Sdh155122 iphtable_t *tables[IPL_LOGSIZE];
579f4b3ec61Sdh155122 struct nlist names[2] = { { "ipf_htables" } , { "" } };
580f4b3ec61Sdh155122
581f4b3ec61Sdh155122 if (nlist(kernel, names) != 1)
582f4b3ec61Sdh155122 return;
583f4b3ec61Sdh155122
584f4b3ec61Sdh155122 bzero(&tables, sizeof(tables));
585f4b3ec61Sdh155122 if (kmemcpy((char *)&tables, names[0].n_value, sizeof(tables)))
586f4b3ec61Sdh155122 return;
5877663b816Sml37995
5887663b816Sml37995 if (role != IPL_LOGALL) {
589f4b3ec61Sdh155122 hptr = tables[role];
5907663b816Sml37995 while (hptr != NULL) {
591ab25eeb5Syz155240 hptr = printhash(hptr, kmemcpywrap,
592ab25eeb5Syz155240 poolname, opts);
5937663b816Sml37995 }
5947663b816Sml37995 } else {
5957663b816Sml37995 for (role = 0; role <= IPL_LOGMAX; role++) {
596f4b3ec61Sdh155122 hptr = tables[role];
5977663b816Sml37995 while (hptr != NULL) {
5987663b816Sml37995 hptr = printhash(hptr, kmemcpywrap,
599ab25eeb5Syz155240 poolname, opts);
6007663b816Sml37995 }
6017663b816Sml37995 }
6027c478bd9Sstevel@tonic-gate }
6037c478bd9Sstevel@tonic-gate }
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate
6067c478bd9Sstevel@tonic-gate
607f4b3ec61Sdh155122 void
showpools_live(fd,role,plstp,poolname,opts)608f4b3ec61Sdh155122 showpools_live(fd, role, plstp, poolname, opts)
609f4b3ec61Sdh155122 int fd, role;
610f4b3ec61Sdh155122 ip_pool_stat_t *plstp;
611f4b3ec61Sdh155122 char *poolname;
612f4b3ec61Sdh155122 int opts;
613f4b3ec61Sdh155122 {
614f4b3ec61Sdh155122 ipflookupiter_t iter;
615f4b3ec61Sdh155122 ip_pool_t pool;
616f4b3ec61Sdh155122 ipfobj_t obj;
617f4b3ec61Sdh155122
618f4b3ec61Sdh155122 obj.ipfo_rev = IPFILTER_VERSION;
619f4b3ec61Sdh155122 obj.ipfo_type = IPFOBJ_LOOKUPITER;
620f4b3ec61Sdh155122 obj.ipfo_size = sizeof(iter);
621f4b3ec61Sdh155122 obj.ipfo_ptr = &iter;
622f4b3ec61Sdh155122
623f4b3ec61Sdh155122 iter.ili_type = IPLT_POOL;
624f4b3ec61Sdh155122 iter.ili_otype = IPFLOOKUPITER_LIST;
625f4b3ec61Sdh155122 iter.ili_ival = IPFGENITER_LOOKUP;
626f4b3ec61Sdh155122 iter.ili_data = &pool;
627f4b3ec61Sdh155122 iter.ili_unit = role;
628f4b3ec61Sdh155122 *iter.ili_name = '\0';
629f4b3ec61Sdh155122
630f4b3ec61Sdh155122 while (plstp->ipls_list[role] != NULL) {
631f4b3ec61Sdh155122 if (ioctl(fd, SIOCLOOKUPITER, &obj)) {
632f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPITER)");
633f4b3ec61Sdh155122 break;
634f4b3ec61Sdh155122 }
635f4b3ec61Sdh155122 (void) printpool_live(&pool, fd, poolname, opts);
636f4b3ec61Sdh155122
637f4b3ec61Sdh155122 plstp->ipls_list[role] = pool.ipo_next;
638f4b3ec61Sdh155122 }
639f4b3ec61Sdh155122 }
640f4b3ec61Sdh155122
poolstats(argc,argv)6417c478bd9Sstevel@tonic-gate int poolstats(argc, argv)
6427c478bd9Sstevel@tonic-gate int argc;
6437c478bd9Sstevel@tonic-gate char *argv[];
6447c478bd9Sstevel@tonic-gate {
6457c478bd9Sstevel@tonic-gate int c, type, role, live_kernel;
6467c478bd9Sstevel@tonic-gate ip_pool_stat_t plstat;
6477c478bd9Sstevel@tonic-gate char *kernel, *core;
6487663b816Sml37995 iphtstat_t htstat;
6497c478bd9Sstevel@tonic-gate iplookupop_t op;
6507c478bd9Sstevel@tonic-gate
6517c478bd9Sstevel@tonic-gate core = NULL;
6527c478bd9Sstevel@tonic-gate kernel = NULL;
6537c478bd9Sstevel@tonic-gate live_kernel = 1;
6547c478bd9Sstevel@tonic-gate type = IPLT_ALL;
6557c478bd9Sstevel@tonic-gate role = IPL_LOGALL;
6567c478bd9Sstevel@tonic-gate
6577c478bd9Sstevel@tonic-gate bzero((char *)&op, sizeof(op));
6587c478bd9Sstevel@tonic-gate
659*94bdecd9SRob Gulewich while ((c = getopt(argc, argv, "dG:M:N:o:t:vz:")) != -1)
6607c478bd9Sstevel@tonic-gate switch (c)
6617c478bd9Sstevel@tonic-gate {
6627c478bd9Sstevel@tonic-gate case 'd' :
6637c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG;
6647c478bd9Sstevel@tonic-gate break;
665*94bdecd9SRob Gulewich case 'G' :
666*94bdecd9SRob Gulewich setzonename_global(optarg);
667*94bdecd9SRob Gulewich break;
6687c478bd9Sstevel@tonic-gate case 'M' :
6697c478bd9Sstevel@tonic-gate live_kernel = 0;
6707c478bd9Sstevel@tonic-gate core = optarg;
6717c478bd9Sstevel@tonic-gate break;
6727c478bd9Sstevel@tonic-gate case 'N' :
6737c478bd9Sstevel@tonic-gate live_kernel = 0;
6747c478bd9Sstevel@tonic-gate kernel = optarg;
6757c478bd9Sstevel@tonic-gate break;
6767c478bd9Sstevel@tonic-gate case 'o' :
6777c478bd9Sstevel@tonic-gate role = getrole(optarg);
6787c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) {
6797c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown role '%s'\n", optarg);
6807c478bd9Sstevel@tonic-gate return -1;
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate break;
6837c478bd9Sstevel@tonic-gate case 't' :
6847c478bd9Sstevel@tonic-gate type = gettype(optarg, NULL);
6857c478bd9Sstevel@tonic-gate if (type != IPLT_POOL) {
6867c478bd9Sstevel@tonic-gate fprintf(stderr,
6877c478bd9Sstevel@tonic-gate "-s not supported for this type yet\n");
6887c478bd9Sstevel@tonic-gate return -1;
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate break;
6917c478bd9Sstevel@tonic-gate case 'v' :
6927c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE;
6937c478bd9Sstevel@tonic-gate break;
694*94bdecd9SRob Gulewich case 'z' :
695*94bdecd9SRob Gulewich setzonename(optarg);
696*94bdecd9SRob Gulewich break;
6977c478bd9Sstevel@tonic-gate }
6987c478bd9Sstevel@tonic-gate
6997663b816Sml37995 if (opts & OPT_DEBUG)
7007663b816Sml37995 fprintf(stderr, "poolstats: opts = %#x\n", opts);
7017663b816Sml37995
7027c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING) && (fd == -1)) {
7037c478bd9Sstevel@tonic-gate fd = open(IPLOOKUP_NAME, O_RDWR);
7047c478bd9Sstevel@tonic-gate if (fd == -1) {
7057c478bd9Sstevel@tonic-gate perror("open(IPLOOKUP_NAME)");
7067c478bd9Sstevel@tonic-gate exit(1);
7077c478bd9Sstevel@tonic-gate }
708*94bdecd9SRob Gulewich
709*94bdecd9SRob Gulewich if (setzone(fd) != 0) {
710*94bdecd9SRob Gulewich close(fd);
711*94bdecd9SRob Gulewich exit(1);
712*94bdecd9SRob Gulewich }
7137c478bd9Sstevel@tonic-gate }
7147c478bd9Sstevel@tonic-gate
7157663b816Sml37995 if (type == IPLT_ALL || type == IPLT_POOL) {
7167663b816Sml37995 op.iplo_type = IPLT_POOL;
7177663b816Sml37995 op.iplo_struct = &plstat;
7187663b816Sml37995 op.iplo_size = sizeof(plstat);
7197c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING)) {
7207c478bd9Sstevel@tonic-gate c = ioctl(fd, SIOCLOOKUPSTAT, &op);
7217c478bd9Sstevel@tonic-gate if (c == -1) {
7227c478bd9Sstevel@tonic-gate perror("ioctl(SIOCLOOKUPSTAT)");
7237c478bd9Sstevel@tonic-gate return -1;
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate printf("Pools:\t%lu\n", plstat.ipls_pools);
7267c478bd9Sstevel@tonic-gate printf("Nodes:\t%lu\n", plstat.ipls_nodes);
7277c478bd9Sstevel@tonic-gate }
7287663b816Sml37995 }
7297663b816Sml37995
7307663b816Sml37995 if (type == IPLT_ALL || type == IPLT_HASH) {
7317663b816Sml37995 op.iplo_type = IPLT_HASH;
7327663b816Sml37995 op.iplo_struct = &htstat;
7337663b816Sml37995 op.iplo_size = sizeof(htstat);
7347663b816Sml37995 if (!(opts & OPT_DONOTHING)) {
7357663b816Sml37995 c = ioctl(fd, SIOCLOOKUPSTAT, &op);
7367663b816Sml37995 if (c == -1) {
7377663b816Sml37995 perror("ioctl(SIOCLOOKUPSTAT)");
7387663b816Sml37995 return -1;
7397663b816Sml37995 }
7407663b816Sml37995 printf("Hash Tables:\t%lu\n", htstat.iphs_numtables);
7417663b816Sml37995 printf("Nodes:\t%lu\n", htstat.iphs_numnodes);
7427663b816Sml37995 printf("Out of Memory:\t%lu\n", htstat.iphs_nomem);
7437663b816Sml37995 }
7447663b816Sml37995 }
7457c478bd9Sstevel@tonic-gate return 0;
7467c478bd9Sstevel@tonic-gate }
7477c478bd9Sstevel@tonic-gate
7487c478bd9Sstevel@tonic-gate
poolflush(argc,argv)7497c478bd9Sstevel@tonic-gate int poolflush(argc, argv)
7507c478bd9Sstevel@tonic-gate int argc;
7517c478bd9Sstevel@tonic-gate char *argv[];
7527c478bd9Sstevel@tonic-gate {
7537c478bd9Sstevel@tonic-gate int c, role, type, arg;
7547c478bd9Sstevel@tonic-gate iplookupflush_t flush;
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate arg = IPLT_ALL;
7577c478bd9Sstevel@tonic-gate type = IPLT_ALL;
7587c478bd9Sstevel@tonic-gate role = IPL_LOGALL;
7597c478bd9Sstevel@tonic-gate
760*94bdecd9SRob Gulewich while ((c = getopt(argc, argv, "do:t:vz:")) != -1)
7617c478bd9Sstevel@tonic-gate switch (c)
7627c478bd9Sstevel@tonic-gate {
7637c478bd9Sstevel@tonic-gate case 'd' :
7647c478bd9Sstevel@tonic-gate opts |= OPT_DEBUG;
7657c478bd9Sstevel@tonic-gate break;
7667c478bd9Sstevel@tonic-gate case 'o' :
7677c478bd9Sstevel@tonic-gate role = getrole(optarg);
7687c478bd9Sstevel@tonic-gate if (role == IPL_LOGNONE) {
7697c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown role '%s'\n", optarg);
7707c478bd9Sstevel@tonic-gate return -1;
7717c478bd9Sstevel@tonic-gate }
7727c478bd9Sstevel@tonic-gate break;
7737c478bd9Sstevel@tonic-gate case 't' :
7747c478bd9Sstevel@tonic-gate type = gettype(optarg, NULL);
7757c478bd9Sstevel@tonic-gate if (type == IPLT_NONE) {
7767c478bd9Sstevel@tonic-gate fprintf(stderr, "unknown type '%s'\n", optarg);
7777c478bd9Sstevel@tonic-gate return -1;
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate break;
7807c478bd9Sstevel@tonic-gate case 'v' :
7817c478bd9Sstevel@tonic-gate opts |= OPT_VERBOSE;
7827c478bd9Sstevel@tonic-gate break;
783*94bdecd9SRob Gulewich case 'z' :
784*94bdecd9SRob Gulewich setzonename(optarg);
785*94bdecd9SRob Gulewich break;
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate
788ab25eeb5Syz155240 if (opts & OPT_DEBUG)
789ab25eeb5Syz155240 fprintf(stderr, "poolflush: opts = %#x\n", opts);
790ab25eeb5Syz155240
7917c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING) && (fd == -1)) {
7927c478bd9Sstevel@tonic-gate fd = open(IPLOOKUP_NAME, O_RDWR);
7937c478bd9Sstevel@tonic-gate if (fd == -1) {
7947c478bd9Sstevel@tonic-gate perror("open(IPLOOKUP_NAME)");
7957c478bd9Sstevel@tonic-gate exit(1);
7967c478bd9Sstevel@tonic-gate }
797*94bdecd9SRob Gulewich
798*94bdecd9SRob Gulewich if (setzone(fd) != 0) {
799*94bdecd9SRob Gulewich close(fd);
800*94bdecd9SRob Gulewich exit(1);
801*94bdecd9SRob Gulewich }
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate bzero((char *)&flush, sizeof(flush));
8057c478bd9Sstevel@tonic-gate flush.iplf_type = type;
8067c478bd9Sstevel@tonic-gate flush.iplf_unit = role;
8077c478bd9Sstevel@tonic-gate flush.iplf_arg = arg;
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate if (!(opts & OPT_DONOTHING)) {
8107c478bd9Sstevel@tonic-gate if (ioctl(fd, SIOCLOOKUPFLUSH, &flush) == -1) {
8117c478bd9Sstevel@tonic-gate perror("ioctl(SIOCLOOKUPFLUSH)");
8127c478bd9Sstevel@tonic-gate exit(1);
8137c478bd9Sstevel@tonic-gate }
8147c478bd9Sstevel@tonic-gate
8157c478bd9Sstevel@tonic-gate }
8167c478bd9Sstevel@tonic-gate printf("%u object%s flushed\n", flush.iplf_count,
8177c478bd9Sstevel@tonic-gate (flush.iplf_count == 1) ? "" : "s");
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate return 0;
8207c478bd9Sstevel@tonic-gate }
8217c478bd9Sstevel@tonic-gate
8227c478bd9Sstevel@tonic-gate
getrole(rolename)8237c478bd9Sstevel@tonic-gate int getrole(rolename)
8247c478bd9Sstevel@tonic-gate char *rolename;
8257c478bd9Sstevel@tonic-gate {
8267c478bd9Sstevel@tonic-gate int role;
8277c478bd9Sstevel@tonic-gate
8287c478bd9Sstevel@tonic-gate if (!strcasecmp(rolename, "ipf")) {
8297c478bd9Sstevel@tonic-gate role = IPL_LOGIPF;
8307c478bd9Sstevel@tonic-gate #if 0
8317c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "nat")) {
8327c478bd9Sstevel@tonic-gate role = IPL_LOGNAT;
8337c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "state")) {
8347c478bd9Sstevel@tonic-gate role = IPL_LOGSTATE;
8357c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "auth")) {
8367c478bd9Sstevel@tonic-gate role = IPL_LOGAUTH;
8377c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "sync")) {
8387c478bd9Sstevel@tonic-gate role = IPL_LOGSYNC;
8397c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "scan")) {
8407c478bd9Sstevel@tonic-gate role = IPL_LOGSCAN;
8417c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "pool")) {
8427c478bd9Sstevel@tonic-gate role = IPL_LOGLOOKUP;
8437c478bd9Sstevel@tonic-gate } else if (!strcasecmp(rolename, "count")) {
8447c478bd9Sstevel@tonic-gate role = IPL_LOGCOUNT;
8457c478bd9Sstevel@tonic-gate #endif
8467c478bd9Sstevel@tonic-gate } else {
8477c478bd9Sstevel@tonic-gate role = IPL_LOGNONE;
8487c478bd9Sstevel@tonic-gate }
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate return role;
8517c478bd9Sstevel@tonic-gate }
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate
gettype(typename,minor)8547c478bd9Sstevel@tonic-gate int gettype(typename, minor)
8557c478bd9Sstevel@tonic-gate char *typename;
8567c478bd9Sstevel@tonic-gate u_int *minor;
8577c478bd9Sstevel@tonic-gate {
8587c478bd9Sstevel@tonic-gate int type;
8597c478bd9Sstevel@tonic-gate
860ab25eeb5Syz155240 if (!strcasecmp(optarg, "tree")) {
8617c478bd9Sstevel@tonic-gate type = IPLT_POOL;
8627c478bd9Sstevel@tonic-gate } else if (!strcasecmp(optarg, "hash")) {
8637c478bd9Sstevel@tonic-gate type = IPLT_HASH;
8647c478bd9Sstevel@tonic-gate if (minor != NULL)
8657c478bd9Sstevel@tonic-gate *minor = IPHASH_LOOKUP;
8667c478bd9Sstevel@tonic-gate } else if (!strcasecmp(optarg, "group-map")) {
8677c478bd9Sstevel@tonic-gate type = IPLT_HASH;
8687c478bd9Sstevel@tonic-gate if (minor != NULL)
8697c478bd9Sstevel@tonic-gate *minor = IPHASH_GROUPMAP;
8707c478bd9Sstevel@tonic-gate } else {
8717c478bd9Sstevel@tonic-gate type = IPLT_NONE;
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate return type;
8747c478bd9Sstevel@tonic-gate }
875f4b3ec61Sdh155122
showhashs_live(fd,role,htstp,poolname,opts)876f4b3ec61Sdh155122 void showhashs_live(fd, role, htstp, poolname, opts)
877f4b3ec61Sdh155122 int fd, role;
878f4b3ec61Sdh155122 iphtstat_t *htstp;
879f4b3ec61Sdh155122 char *poolname;
880f4b3ec61Sdh155122 int opts;
881f4b3ec61Sdh155122 {
882f4b3ec61Sdh155122 ipflookupiter_t iter;
883f4b3ec61Sdh155122 iphtable_t table;
884f4b3ec61Sdh155122 ipfobj_t obj;
885f4b3ec61Sdh155122
886f4b3ec61Sdh155122 obj.ipfo_rev = IPFILTER_VERSION;
887f4b3ec61Sdh155122 obj.ipfo_type = IPFOBJ_LOOKUPITER;
888f4b3ec61Sdh155122 obj.ipfo_size = sizeof(iter);
889f4b3ec61Sdh155122 obj.ipfo_ptr = &iter;
890f4b3ec61Sdh155122
891f4b3ec61Sdh155122 iter.ili_type = IPLT_HASH;
892f4b3ec61Sdh155122 iter.ili_otype = IPFLOOKUPITER_LIST;
893f4b3ec61Sdh155122 iter.ili_ival = IPFGENITER_LOOKUP;
894f4b3ec61Sdh155122 iter.ili_data = &table;
895f4b3ec61Sdh155122 iter.ili_unit = role;
896f4b3ec61Sdh155122 *iter.ili_name = '\0';
897f4b3ec61Sdh155122
898f4b3ec61Sdh155122 while (htstp->iphs_tables != NULL) {
899f4b3ec61Sdh155122 if (ioctl(fd, SIOCLOOKUPITER, &obj)) {
900f4b3ec61Sdh155122 perror("ioctl(SIOCLOOKUPITER)");
901f4b3ec61Sdh155122 break;
902f4b3ec61Sdh155122 }
903f4b3ec61Sdh155122
904f4b3ec61Sdh155122 printhash_live(&table, fd, poolname, opts);
905f4b3ec61Sdh155122
906f4b3ec61Sdh155122 htstp->iphs_tables = table.iph_next;
907f4b3ec61Sdh155122 }
908f4b3ec61Sdh155122 }
909