xref: /titanic_51/usr/src/cmd/ipf/tools/ippool.c (revision ab25eeb551a4be927a4b6ae2cf8aff7ed17decb4)
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*ab25eeb5Syz155240  * Copyright 2006 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>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include "ipf.h"
387c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
397c478bd9Sstevel@tonic-gate #include "netinet/ip_pool.h"
407c478bd9Sstevel@tonic-gate #include "netinet/ip_htable.h"
417c478bd9Sstevel@tonic-gate #include "kmem.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate extern	int	ippool_yyparse __P((void));
457c478bd9Sstevel@tonic-gate extern	int	ippool_yydebug;
467c478bd9Sstevel@tonic-gate extern	FILE	*ippool_yyin;
477c478bd9Sstevel@tonic-gate extern	char	*optarg;
487c478bd9Sstevel@tonic-gate extern	int	lineNum;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate void	showpools __P((ip_pool_stat_t *));
517c478bd9Sstevel@tonic-gate void	usage __P((char *));
527c478bd9Sstevel@tonic-gate int	main __P((int, char **));
537c478bd9Sstevel@tonic-gate int	poolcommand __P((int, int, char *[]));
547c478bd9Sstevel@tonic-gate int	poolnodecommand __P((int, int, char *[]));
557c478bd9Sstevel@tonic-gate int	loadpoolfile __P((int, char *[], char *));
567c478bd9Sstevel@tonic-gate int	poollist __P((int, char *[]));
577c478bd9Sstevel@tonic-gate int	poolflush __P((int, char *[]));
587c478bd9Sstevel@tonic-gate int	poolstats __P((int, char *[]));
597c478bd9Sstevel@tonic-gate int	gettype __P((char *, u_int *));
607c478bd9Sstevel@tonic-gate int	getrole __P((char *));
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate int	opts = 0;
637c478bd9Sstevel@tonic-gate int	fd = -1;
647c478bd9Sstevel@tonic-gate int	use_inet6 = 0;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate void usage(prog)
687c478bd9Sstevel@tonic-gate char *prog;
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	fprintf(stderr, "Usage:\t%s\n", prog);
717c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t\t\t-a [-dnv] [-m <name>] [-o <role>] -i <ipaddr>[/netmask]\n");
727c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t\t\t-A [-dnv] [-m <name>] [-o <role>] [-S <seed>] [-t <type>]\n");
737c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t\t\t-f <file> [-dnuv]\n");
747c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t\t\t-F [-dv] [-o <role>] [-t <type>]\n");
757c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t\t\t-l [-dv] [-m <name>] [-t <type>]\n");
767c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t\t\t-r [-dnv] [-m <name>] [-o <role>] -i <ipaddr>[/netmask]\n");
777c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t\t\t-R [-dnv] [-m <name>] [-o <role>] [-t <type>]\n");
787c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t\t\t-s [-dtv] [-M <core>] [-N <namelist>]\n");
797c478bd9Sstevel@tonic-gate 	exit(1);
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate int main(argc, argv)
847c478bd9Sstevel@tonic-gate int argc;
857c478bd9Sstevel@tonic-gate char *argv[];
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate 	int err;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	if (argc < 2)
907c478bd9Sstevel@tonic-gate 		usage(argv[0]);
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	switch (getopt(argc, argv, "aAf:FlrRs"))
937c478bd9Sstevel@tonic-gate 	{
947c478bd9Sstevel@tonic-gate 	case 'a' :
957c478bd9Sstevel@tonic-gate 		err = poolnodecommand(0, argc, argv);
967c478bd9Sstevel@tonic-gate 		break;
977c478bd9Sstevel@tonic-gate 	case 'A' :
987c478bd9Sstevel@tonic-gate 		err = poolcommand(0, argc, argv);
997c478bd9Sstevel@tonic-gate 		break;
1007c478bd9Sstevel@tonic-gate 	case 'f' :
1017c478bd9Sstevel@tonic-gate 		err = loadpoolfile(argc, argv, optarg);
1027c478bd9Sstevel@tonic-gate 		break;
1037c478bd9Sstevel@tonic-gate 	case 'F' :
1047c478bd9Sstevel@tonic-gate 		err = poolflush(argc, argv);
1057c478bd9Sstevel@tonic-gate 		break;
1067c478bd9Sstevel@tonic-gate 	case 'l' :
1077c478bd9Sstevel@tonic-gate 		err = poollist(argc, argv);
1087c478bd9Sstevel@tonic-gate 		break;
1097c478bd9Sstevel@tonic-gate 	case 'r' :
1107c478bd9Sstevel@tonic-gate 		err = poolnodecommand(1, argc, argv);
1117c478bd9Sstevel@tonic-gate 		break;
1127c478bd9Sstevel@tonic-gate 	case 'R' :
1137c478bd9Sstevel@tonic-gate 		err = poolcommand(1, argc, argv);
1147c478bd9Sstevel@tonic-gate 		break;
1157c478bd9Sstevel@tonic-gate 	case 's' :
1167c478bd9Sstevel@tonic-gate 		err = poolstats(argc, argv);
1177c478bd9Sstevel@tonic-gate 		break;
1187c478bd9Sstevel@tonic-gate 	default :
1197c478bd9Sstevel@tonic-gate 		exit(1);
1207c478bd9Sstevel@tonic-gate 	}
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	return err;
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate int poolnodecommand(remove, argc, argv)
1277c478bd9Sstevel@tonic-gate int remove, argc;
1287c478bd9Sstevel@tonic-gate char *argv[];
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate 	char *poolname = NULL, *s;
1317c478bd9Sstevel@tonic-gate 	int err, c, ipset, role;
1327c478bd9Sstevel@tonic-gate 	ip_pool_node_t node;
1337c478bd9Sstevel@tonic-gate 	struct in_addr mask;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	ipset = 0;
1367c478bd9Sstevel@tonic-gate 	role = IPL_LOGIPF;
1377c478bd9Sstevel@tonic-gate 	bzero((char *)&node, sizeof(node));
1387c478bd9Sstevel@tonic-gate 
139*ab25eeb5Syz155240 	while ((c = getopt(argc, argv, "di:m:no:Rv")) != -1)
1407c478bd9Sstevel@tonic-gate 		switch (c)
1417c478bd9Sstevel@tonic-gate 		{
1427c478bd9Sstevel@tonic-gate 		case 'd' :
1437c478bd9Sstevel@tonic-gate 			opts |= OPT_DEBUG;
1447c478bd9Sstevel@tonic-gate 			ippool_yydebug++;
1457c478bd9Sstevel@tonic-gate 			break;
1467c478bd9Sstevel@tonic-gate 		case 'i' :
1477c478bd9Sstevel@tonic-gate 			s = strchr(optarg, '/');
1487c478bd9Sstevel@tonic-gate 			if (s == NULL)
1497c478bd9Sstevel@tonic-gate 				mask.s_addr = 0xffffffff;
1507c478bd9Sstevel@tonic-gate 			else if (strchr(s, '.') == NULL) {
1517c478bd9Sstevel@tonic-gate 				if (ntomask(4, atoi(s + 1), &mask.s_addr) != 0)
1527c478bd9Sstevel@tonic-gate 					return -1;
1537c478bd9Sstevel@tonic-gate 			} else {
1547c478bd9Sstevel@tonic-gate 				mask.s_addr = inet_addr(s + 1);
1557c478bd9Sstevel@tonic-gate 			}
1567c478bd9Sstevel@tonic-gate 			if (s != NULL)
1577c478bd9Sstevel@tonic-gate 				*s = '\0';
1587c478bd9Sstevel@tonic-gate 			ipset = 1;
159*ab25eeb5Syz155240 			node.ipn_addr.adf_len = sizeof(node.ipn_addr);
1607c478bd9Sstevel@tonic-gate 			node.ipn_addr.adf_addr.in4.s_addr = inet_addr(optarg);
161*ab25eeb5Syz155240 			node.ipn_mask.adf_len = sizeof(node.ipn_mask);
1627c478bd9Sstevel@tonic-gate 			node.ipn_mask.adf_addr.in4.s_addr = mask.s_addr;
1637c478bd9Sstevel@tonic-gate 			break;
1647c478bd9Sstevel@tonic-gate 		case 'm' :
1657c478bd9Sstevel@tonic-gate 			poolname = optarg;
1667c478bd9Sstevel@tonic-gate 			break;
1677c478bd9Sstevel@tonic-gate 		case 'n' :
1687c478bd9Sstevel@tonic-gate 			opts |= OPT_DONOTHING;
1697c478bd9Sstevel@tonic-gate 			break;
1707c478bd9Sstevel@tonic-gate 		case 'o' :
1717c478bd9Sstevel@tonic-gate 			role = getrole(optarg);
1727c478bd9Sstevel@tonic-gate 			if (role == IPL_LOGNONE)
1737c478bd9Sstevel@tonic-gate 				return -1;
1747c478bd9Sstevel@tonic-gate 			break;
175*ab25eeb5Syz155240 		case 'R' :
176*ab25eeb5Syz155240 			opts |= OPT_NORESOLVE;
177*ab25eeb5Syz155240 			break;
1787c478bd9Sstevel@tonic-gate 		case 'v' :
1797c478bd9Sstevel@tonic-gate 			opts |= OPT_VERBOSE;
1807c478bd9Sstevel@tonic-gate 			break;
1817c478bd9Sstevel@tonic-gate 		}
1827c478bd9Sstevel@tonic-gate 
183*ab25eeb5Syz155240 	if (opts & OPT_DEBUG)
184*ab25eeb5Syz155240 		fprintf(stderr, "poolnodecommand: opts = %#x\n", opts);
185*ab25eeb5Syz155240 
1867c478bd9Sstevel@tonic-gate 	if (ipset == 0)
1877c478bd9Sstevel@tonic-gate 		return -1;
1887c478bd9Sstevel@tonic-gate 	if (poolname == NULL) {
1897c478bd9Sstevel@tonic-gate 		fprintf(stderr, "poolname not given with add/remove node\n");
1907c478bd9Sstevel@tonic-gate 		return -1;
1917c478bd9Sstevel@tonic-gate 	}
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	if (remove == 0)
1947c478bd9Sstevel@tonic-gate 		err = load_poolnode(0, poolname, &node, ioctl);
1957c478bd9Sstevel@tonic-gate 	else
1967c478bd9Sstevel@tonic-gate 		err = remove_poolnode(0, poolname, &node, ioctl);
1977c478bd9Sstevel@tonic-gate 	return err;
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate int poolcommand(remove, argc, argv)
2027c478bd9Sstevel@tonic-gate int remove, argc;
2037c478bd9Sstevel@tonic-gate char *argv[];
2047c478bd9Sstevel@tonic-gate {
2057c478bd9Sstevel@tonic-gate 	int type, role, c, err;
2067c478bd9Sstevel@tonic-gate 	char *poolname;
2077c478bd9Sstevel@tonic-gate 	iphtable_t iph;
2087c478bd9Sstevel@tonic-gate 	ip_pool_t pool;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	err = 1;
2117c478bd9Sstevel@tonic-gate 	role = 0;
2127c478bd9Sstevel@tonic-gate 	type = 0;
2137c478bd9Sstevel@tonic-gate 	poolname = NULL;
2147c478bd9Sstevel@tonic-gate 	role = IPL_LOGIPF;
2157c478bd9Sstevel@tonic-gate 	bzero((char *)&iph, sizeof(iph));
2167c478bd9Sstevel@tonic-gate 	bzero((char *)&pool, sizeof(pool));
2177c478bd9Sstevel@tonic-gate 
218*ab25eeb5Syz155240 	while ((c = getopt(argc, argv, "dm:no:RSt:v")) != -1)
2197c478bd9Sstevel@tonic-gate 		switch (c)
2207c478bd9Sstevel@tonic-gate 		{
2217c478bd9Sstevel@tonic-gate 		case 'd' :
2227c478bd9Sstevel@tonic-gate 			opts |= OPT_DEBUG;
2237c478bd9Sstevel@tonic-gate 			ippool_yydebug++;
2247c478bd9Sstevel@tonic-gate 			break;
2257c478bd9Sstevel@tonic-gate 		case 'm' :
2267c478bd9Sstevel@tonic-gate 			poolname = optarg;
2277c478bd9Sstevel@tonic-gate 			break;
2287c478bd9Sstevel@tonic-gate 		case 'n' :
2297c478bd9Sstevel@tonic-gate 			opts |= OPT_DONOTHING;
2307c478bd9Sstevel@tonic-gate 			break;
2317c478bd9Sstevel@tonic-gate 		case 'o' :
2327c478bd9Sstevel@tonic-gate 			role = getrole(optarg);
2337c478bd9Sstevel@tonic-gate 			if (role == IPL_LOGNONE) {
2347c478bd9Sstevel@tonic-gate 				fprintf(stderr, "unknown role '%s'\n", optarg);
2357c478bd9Sstevel@tonic-gate 				return -1;
2367c478bd9Sstevel@tonic-gate 			}
2377c478bd9Sstevel@tonic-gate 			break;
238*ab25eeb5Syz155240 		case 'R' :
239*ab25eeb5Syz155240 			opts |= OPT_NORESOLVE;
240*ab25eeb5Syz155240 			break;
2417c478bd9Sstevel@tonic-gate 		case 'S' :
2427c478bd9Sstevel@tonic-gate 			iph.iph_seed = atoi(optarg);
2437c478bd9Sstevel@tonic-gate 			break;
2447c478bd9Sstevel@tonic-gate 		case 't' :
2457c478bd9Sstevel@tonic-gate 			type = gettype(optarg, &iph.iph_type);
2467c478bd9Sstevel@tonic-gate 			if (type == IPLT_NONE) {
2477c478bd9Sstevel@tonic-gate 				fprintf(stderr, "unknown type '%s'\n", optarg);
2487c478bd9Sstevel@tonic-gate 				return -1;
2497c478bd9Sstevel@tonic-gate 			}
2507c478bd9Sstevel@tonic-gate 			break;
2517c478bd9Sstevel@tonic-gate 		case 'v' :
2527c478bd9Sstevel@tonic-gate 			opts |= OPT_VERBOSE;
2537c478bd9Sstevel@tonic-gate 			break;
2547c478bd9Sstevel@tonic-gate 		}
2557c478bd9Sstevel@tonic-gate 
256*ab25eeb5Syz155240 	if (opts & OPT_DEBUG)
257*ab25eeb5Syz155240 		fprintf(stderr, "poolcommand: opts = %#x\n", opts);
258*ab25eeb5Syz155240 
2597c478bd9Sstevel@tonic-gate 	if (poolname == NULL) {
2607c478bd9Sstevel@tonic-gate 		fprintf(stderr, "poolname not given with add/remove pool\n");
2617c478bd9Sstevel@tonic-gate 		return -1;
2627c478bd9Sstevel@tonic-gate 	}
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	if (type == IPLT_HASH) {
2657c478bd9Sstevel@tonic-gate 		strncpy(iph.iph_name, poolname, sizeof(iph.iph_name));
2667c478bd9Sstevel@tonic-gate 		iph.iph_name[sizeof(iph.iph_name) - 1] = '\0';
2677c478bd9Sstevel@tonic-gate 		iph.iph_unit = role;
2687c478bd9Sstevel@tonic-gate 	} else if (type == IPLT_POOL) {
2697c478bd9Sstevel@tonic-gate 		strncpy(pool.ipo_name, poolname, sizeof(pool.ipo_name));
2707c478bd9Sstevel@tonic-gate 		pool.ipo_name[sizeof(pool.ipo_name) - 1] = '\0';
2717c478bd9Sstevel@tonic-gate 		pool.ipo_unit = role;
2727c478bd9Sstevel@tonic-gate 	}
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	if (remove == 0) {
2757c478bd9Sstevel@tonic-gate 		switch (type)
2767c478bd9Sstevel@tonic-gate 		{
2777c478bd9Sstevel@tonic-gate 		case IPLT_HASH :
2787c478bd9Sstevel@tonic-gate 			err = load_hash(&iph, NULL, ioctl);
2797c478bd9Sstevel@tonic-gate 			break;
2807c478bd9Sstevel@tonic-gate 		case IPLT_POOL :
2817c478bd9Sstevel@tonic-gate 			err = load_pool(&pool, ioctl);
2827c478bd9Sstevel@tonic-gate 			break;
2837c478bd9Sstevel@tonic-gate 		}
2847c478bd9Sstevel@tonic-gate 	} else {
2857c478bd9Sstevel@tonic-gate 		switch (type)
2867c478bd9Sstevel@tonic-gate 		{
2877c478bd9Sstevel@tonic-gate 		case IPLT_HASH :
2887c478bd9Sstevel@tonic-gate 			err = remove_hash(&iph, ioctl);
2897c478bd9Sstevel@tonic-gate 			break;
2907c478bd9Sstevel@tonic-gate 		case IPLT_POOL :
2917c478bd9Sstevel@tonic-gate 			err = remove_pool(&pool, ioctl);
2927c478bd9Sstevel@tonic-gate 			break;
2937c478bd9Sstevel@tonic-gate 		}
2947c478bd9Sstevel@tonic-gate 	}
2957c478bd9Sstevel@tonic-gate 	return err;
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate int loadpoolfile(argc, argv, infile)
3007c478bd9Sstevel@tonic-gate int argc;
3017c478bd9Sstevel@tonic-gate char *argv[], *infile;
3027c478bd9Sstevel@tonic-gate {
3037c478bd9Sstevel@tonic-gate 	int c;
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	infile = optarg;
3067c478bd9Sstevel@tonic-gate 
307*ab25eeb5Syz155240 	while ((c = getopt(argc, argv, "dnRuv")) != -1)
3087c478bd9Sstevel@tonic-gate 		switch (c)
3097c478bd9Sstevel@tonic-gate 		{
3107c478bd9Sstevel@tonic-gate 		case 'd' :
3117c478bd9Sstevel@tonic-gate 			opts |= OPT_DEBUG;
3127c478bd9Sstevel@tonic-gate 			ippool_yydebug++;
3137c478bd9Sstevel@tonic-gate 			break;
3147c478bd9Sstevel@tonic-gate 		case 'n' :
3157c478bd9Sstevel@tonic-gate 			opts |= OPT_DONOTHING;
3167c478bd9Sstevel@tonic-gate 			break;
317*ab25eeb5Syz155240 		case 'R' :
318*ab25eeb5Syz155240 			opts |= OPT_NORESOLVE;
319*ab25eeb5Syz155240 			break;
320*ab25eeb5Syz155240 		case 'u' :
3217c478bd9Sstevel@tonic-gate 			opts |= OPT_REMOVE;
3227c478bd9Sstevel@tonic-gate 			break;
3237c478bd9Sstevel@tonic-gate 		case 'v' :
3247c478bd9Sstevel@tonic-gate 			opts |= OPT_VERBOSE;
3257c478bd9Sstevel@tonic-gate 			break;
3267c478bd9Sstevel@tonic-gate 		}
3277c478bd9Sstevel@tonic-gate 
328*ab25eeb5Syz155240 	if (opts & OPT_DEBUG)
329*ab25eeb5Syz155240 		fprintf(stderr, "loadpoolfile: opts = %#x\n", opts);
330*ab25eeb5Syz155240 
3317c478bd9Sstevel@tonic-gate 	if (!(opts & OPT_DONOTHING) && (fd == -1)) {
3327c478bd9Sstevel@tonic-gate 		fd = open(IPLOOKUP_NAME, O_RDWR);
3337c478bd9Sstevel@tonic-gate 		if (fd == -1) {
3347c478bd9Sstevel@tonic-gate 			perror("open(IPLOOKUP_NAME)");
3357c478bd9Sstevel@tonic-gate 			exit(1);
3367c478bd9Sstevel@tonic-gate 		}
3377c478bd9Sstevel@tonic-gate 	}
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	if (ippool_parsefile(fd, infile, ioctl) != 0)
3407c478bd9Sstevel@tonic-gate 		return -1;
3417c478bd9Sstevel@tonic-gate 	return 0;
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate int poollist(argc, argv)
3467c478bd9Sstevel@tonic-gate int argc;
3477c478bd9Sstevel@tonic-gate char *argv[];
3487c478bd9Sstevel@tonic-gate {
3497c478bd9Sstevel@tonic-gate 	char *kernel, *core, *poolname;
3507c478bd9Sstevel@tonic-gate 	int c, role, type, live_kernel;
3517c478bd9Sstevel@tonic-gate 	ip_pool_stat_t *plstp, plstat;
3527663b816Sml37995 	iphtstat_t *htstp, htstat;
3537663b816Sml37995 	iphtable_t *hptr;
3547c478bd9Sstevel@tonic-gate 	iplookupop_t op;
3557c478bd9Sstevel@tonic-gate 	ip_pool_t *ptr;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	core = NULL;
3587c478bd9Sstevel@tonic-gate 	kernel = NULL;
3597c478bd9Sstevel@tonic-gate 	live_kernel = 1;
3607c478bd9Sstevel@tonic-gate 	type = IPLT_ALL;
3617c478bd9Sstevel@tonic-gate 	poolname = NULL;
3627c478bd9Sstevel@tonic-gate 	role = IPL_LOGALL;
3637c478bd9Sstevel@tonic-gate 
364*ab25eeb5Syz155240 	while ((c = getopt(argc, argv, "dm:M:N:o:Rt:v")) != -1)
3657c478bd9Sstevel@tonic-gate 		switch (c)
3667c478bd9Sstevel@tonic-gate 		{
3677c478bd9Sstevel@tonic-gate 		case 'd' :
3687c478bd9Sstevel@tonic-gate 			opts |= OPT_DEBUG;
3697c478bd9Sstevel@tonic-gate 			break;
3707c478bd9Sstevel@tonic-gate 		case 'm' :
3717c478bd9Sstevel@tonic-gate 			poolname = optarg;
3727c478bd9Sstevel@tonic-gate 			break;
3737c478bd9Sstevel@tonic-gate 		case 'M' :
3747c478bd9Sstevel@tonic-gate 			live_kernel = 0;
3757c478bd9Sstevel@tonic-gate 			core = optarg;
3767c478bd9Sstevel@tonic-gate 			break;
3777c478bd9Sstevel@tonic-gate 		case 'N' :
3787c478bd9Sstevel@tonic-gate 			live_kernel = 0;
3797c478bd9Sstevel@tonic-gate 			kernel = optarg;
3807c478bd9Sstevel@tonic-gate 			break;
3817c478bd9Sstevel@tonic-gate 		case 'o' :
3827c478bd9Sstevel@tonic-gate 			role = getrole(optarg);
3837c478bd9Sstevel@tonic-gate 			if (role == IPL_LOGNONE) {
3847c478bd9Sstevel@tonic-gate 				fprintf(stderr, "unknown role '%s'\n", optarg);
3857c478bd9Sstevel@tonic-gate 				return -1;
3867c478bd9Sstevel@tonic-gate 			}
3877c478bd9Sstevel@tonic-gate 			break;
388*ab25eeb5Syz155240 		case 'R' :
389*ab25eeb5Syz155240 			opts |= OPT_NORESOLVE;
390*ab25eeb5Syz155240 			break;
3917c478bd9Sstevel@tonic-gate 		case 't' :
3927c478bd9Sstevel@tonic-gate 			type = gettype(optarg, NULL);
3937c478bd9Sstevel@tonic-gate 			if (type == IPLT_NONE) {
3947c478bd9Sstevel@tonic-gate 				fprintf(stderr, "unknown type '%s'\n", optarg);
3957c478bd9Sstevel@tonic-gate 				return -1;
3967c478bd9Sstevel@tonic-gate 			}
3977c478bd9Sstevel@tonic-gate 			break;
3987c478bd9Sstevel@tonic-gate 		case 'v' :
3997c478bd9Sstevel@tonic-gate 			opts |= OPT_VERBOSE;
4007c478bd9Sstevel@tonic-gate 			break;
4017c478bd9Sstevel@tonic-gate 		}
4027c478bd9Sstevel@tonic-gate 
4037663b816Sml37995 	if (opts & OPT_DEBUG)
4047663b816Sml37995 		fprintf(stderr, "poollist: opts = %#x\n", opts);
4057663b816Sml37995 
4067c478bd9Sstevel@tonic-gate 	if (!(opts & OPT_DONOTHING) && (fd == -1)) {
4077c478bd9Sstevel@tonic-gate 		fd = open(IPLOOKUP_NAME, O_RDWR);
4087c478bd9Sstevel@tonic-gate 		if (fd == -1) {
4097c478bd9Sstevel@tonic-gate 			perror("open(IPLOOKUP_NAME)");
4107c478bd9Sstevel@tonic-gate 			exit(1);
4117c478bd9Sstevel@tonic-gate 		}
4127c478bd9Sstevel@tonic-gate 	}
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	bzero((char *)&op, sizeof(op));
4157c478bd9Sstevel@tonic-gate 	if (poolname != NULL) {
4167c478bd9Sstevel@tonic-gate 		strncpy(op.iplo_name, poolname, sizeof(op.iplo_name));
4177c478bd9Sstevel@tonic-gate 		op.iplo_name[sizeof(op.iplo_name) - 1] = '\0';
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 	op.iplo_unit = role;
4207663b816Sml37995 
4217663b816Sml37995 	if (openkmem(kernel, core) == -1)
4227663b816Sml37995 		exit(-1);
4237663b816Sml37995 
4247663b816Sml37995 	if (type == IPLT_ALL || type == IPLT_POOL) {
4257663b816Sml37995 		plstp = &plstat;
4267663b816Sml37995 		op.iplo_type = IPLT_POOL;
4277c478bd9Sstevel@tonic-gate 		op.iplo_size = sizeof(plstat);
4287c478bd9Sstevel@tonic-gate 		op.iplo_struct = &plstat;
4297c478bd9Sstevel@tonic-gate 		c = ioctl(fd, SIOCLOOKUPSTAT, &op);
4307c478bd9Sstevel@tonic-gate 		if (c == -1) {
4317c478bd9Sstevel@tonic-gate 			perror("ioctl(SIOCLOOKUPSTAT)");
4327c478bd9Sstevel@tonic-gate 			return -1;
4337c478bd9Sstevel@tonic-gate 		}
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 		if (role != IPL_LOGALL) {
4367c478bd9Sstevel@tonic-gate 			ptr = plstp->ipls_list[role];
4377c478bd9Sstevel@tonic-gate 			while (ptr != NULL) {
438*ab25eeb5Syz155240 				ptr = printpool(ptr, kmemcpywrap, poolname,
439*ab25eeb5Syz155240 						opts);
4407c478bd9Sstevel@tonic-gate 			}
4417c478bd9Sstevel@tonic-gate 		} else {
4427c478bd9Sstevel@tonic-gate 			for (role = 0; role <= IPL_LOGMAX; role++) {
4437c478bd9Sstevel@tonic-gate 				ptr = plstp->ipls_list[role];
4447c478bd9Sstevel@tonic-gate 				while (ptr != NULL) {
4457663b816Sml37995 					ptr = printpool(ptr, kmemcpywrap,
446*ab25eeb5Syz155240 							poolname, opts);
4477663b816Sml37995 				}
4487663b816Sml37995 			}
4497663b816Sml37995 			role = IPL_LOGALL;
4507663b816Sml37995 		}
4517663b816Sml37995 	}
4527663b816Sml37995 	if (type == IPLT_ALL || type == IPLT_HASH) {
4537663b816Sml37995 		htstp = &htstat;
4547663b816Sml37995 		op.iplo_type = IPLT_HASH;
4557663b816Sml37995 		op.iplo_size = sizeof(htstat);
4567663b816Sml37995 		op.iplo_struct = &htstat;
4577663b816Sml37995 		c = ioctl(fd, SIOCLOOKUPSTAT, &op);
4587663b816Sml37995 		if (c == -1) {
4597663b816Sml37995 			perror("ioctl(SIOCLOOKUPSTAT)");
4607663b816Sml37995 			return -1;
4617663b816Sml37995 		}
4627663b816Sml37995 
4637663b816Sml37995 		if (role != IPL_LOGALL) {
4647663b816Sml37995 			hptr = htstp->iphs_tables;
4657663b816Sml37995 			while (hptr != NULL) {
466*ab25eeb5Syz155240 				hptr = printhash(hptr, kmemcpywrap,
467*ab25eeb5Syz155240 						 poolname, opts);
4687663b816Sml37995 			}
4697663b816Sml37995 		} else {
4707663b816Sml37995 			for (role = 0; role <= IPL_LOGMAX; role++) {
4717663b816Sml37995 				hptr = htstp->iphs_tables;
4727663b816Sml37995 				while (hptr != NULL) {
4737663b816Sml37995 					hptr = printhash(hptr, kmemcpywrap,
474*ab25eeb5Syz155240 							 poolname, opts);
4757663b816Sml37995 				}
4767663b816Sml37995 
4777663b816Sml37995 				op.iplo_unit = role;
4787663b816Sml37995 				c = ioctl(fd, SIOCLOOKUPSTAT, &op);
4797663b816Sml37995 				if (c == -1) {
4807663b816Sml37995 					perror("ioctl(SIOCLOOKUPSTAT)");
4817663b816Sml37995 					return -1;
4827663b816Sml37995 				}
4837c478bd9Sstevel@tonic-gate 			}
4847c478bd9Sstevel@tonic-gate 		}
4857c478bd9Sstevel@tonic-gate 	}
4867c478bd9Sstevel@tonic-gate 	return 0;
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate int poolstats(argc, argv)
4917c478bd9Sstevel@tonic-gate int argc;
4927c478bd9Sstevel@tonic-gate char *argv[];
4937c478bd9Sstevel@tonic-gate {
4947c478bd9Sstevel@tonic-gate 	int c, type, role, live_kernel;
4957c478bd9Sstevel@tonic-gate 	ip_pool_stat_t plstat;
4967c478bd9Sstevel@tonic-gate 	char *kernel, *core;
4977663b816Sml37995 	iphtstat_t htstat;
4987c478bd9Sstevel@tonic-gate 	iplookupop_t op;
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 	core = NULL;
5017c478bd9Sstevel@tonic-gate 	kernel = NULL;
5027c478bd9Sstevel@tonic-gate 	live_kernel = 1;
5037c478bd9Sstevel@tonic-gate 	type = IPLT_ALL;
5047c478bd9Sstevel@tonic-gate 	role = IPL_LOGALL;
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate 	bzero((char *)&op, sizeof(op));
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "dM:N:o:t:v")) != -1)
5097c478bd9Sstevel@tonic-gate 		switch (c)
5107c478bd9Sstevel@tonic-gate 		{
5117c478bd9Sstevel@tonic-gate 		case 'd' :
5127c478bd9Sstevel@tonic-gate 			opts |= OPT_DEBUG;
5137c478bd9Sstevel@tonic-gate 			break;
5147c478bd9Sstevel@tonic-gate 		case 'M' :
5157c478bd9Sstevel@tonic-gate 			live_kernel = 0;
5167c478bd9Sstevel@tonic-gate 			core = optarg;
5177c478bd9Sstevel@tonic-gate 			break;
5187c478bd9Sstevel@tonic-gate 		case 'N' :
5197c478bd9Sstevel@tonic-gate 			live_kernel = 0;
5207c478bd9Sstevel@tonic-gate 			kernel = optarg;
5217c478bd9Sstevel@tonic-gate 			break;
5227c478bd9Sstevel@tonic-gate 		case 'o' :
5237c478bd9Sstevel@tonic-gate 			role = getrole(optarg);
5247c478bd9Sstevel@tonic-gate 			if (role == IPL_LOGNONE) {
5257c478bd9Sstevel@tonic-gate 				fprintf(stderr, "unknown role '%s'\n", optarg);
5267c478bd9Sstevel@tonic-gate 				return -1;
5277c478bd9Sstevel@tonic-gate 			}
5287c478bd9Sstevel@tonic-gate 			break;
5297c478bd9Sstevel@tonic-gate 		case 't' :
5307c478bd9Sstevel@tonic-gate 			type = gettype(optarg, NULL);
5317c478bd9Sstevel@tonic-gate 			if (type != IPLT_POOL) {
5327c478bd9Sstevel@tonic-gate 				fprintf(stderr,
5337c478bd9Sstevel@tonic-gate 					"-s not supported for this type yet\n");
5347c478bd9Sstevel@tonic-gate 				return -1;
5357c478bd9Sstevel@tonic-gate 			}
5367c478bd9Sstevel@tonic-gate 			break;
5377c478bd9Sstevel@tonic-gate 		case 'v' :
5387c478bd9Sstevel@tonic-gate 			opts |= OPT_VERBOSE;
5397c478bd9Sstevel@tonic-gate 			break;
5407c478bd9Sstevel@tonic-gate 		}
5417c478bd9Sstevel@tonic-gate 
5427663b816Sml37995 	if (opts & OPT_DEBUG)
5437663b816Sml37995 		fprintf(stderr, "poolstats: opts = %#x\n", opts);
5447663b816Sml37995 
5457c478bd9Sstevel@tonic-gate 	if (!(opts & OPT_DONOTHING) && (fd == -1)) {
5467c478bd9Sstevel@tonic-gate 		fd = open(IPLOOKUP_NAME, O_RDWR);
5477c478bd9Sstevel@tonic-gate 		if (fd == -1) {
5487c478bd9Sstevel@tonic-gate 			perror("open(IPLOOKUP_NAME)");
5497c478bd9Sstevel@tonic-gate 			exit(1);
5507c478bd9Sstevel@tonic-gate 		}
5517c478bd9Sstevel@tonic-gate 	}
5527c478bd9Sstevel@tonic-gate 
5537663b816Sml37995 	if (type == IPLT_ALL || type == IPLT_POOL) {
5547663b816Sml37995 		op.iplo_type = IPLT_POOL;
5557663b816Sml37995 		op.iplo_struct = &plstat;
5567663b816Sml37995 		op.iplo_size = sizeof(plstat);
5577c478bd9Sstevel@tonic-gate 		if (!(opts & OPT_DONOTHING)) {
5587c478bd9Sstevel@tonic-gate 			c = ioctl(fd, SIOCLOOKUPSTAT, &op);
5597c478bd9Sstevel@tonic-gate 			if (c == -1) {
5607c478bd9Sstevel@tonic-gate 				perror("ioctl(SIOCLOOKUPSTAT)");
5617c478bd9Sstevel@tonic-gate 				return -1;
5627c478bd9Sstevel@tonic-gate 			}
5637c478bd9Sstevel@tonic-gate 			printf("Pools:\t%lu\n", plstat.ipls_pools);
5647c478bd9Sstevel@tonic-gate 			printf("Nodes:\t%lu\n", plstat.ipls_nodes);
5657c478bd9Sstevel@tonic-gate 		}
5667663b816Sml37995 	}
5677663b816Sml37995 
5687663b816Sml37995 	if (type == IPLT_ALL || type == IPLT_HASH) {
5697663b816Sml37995 		op.iplo_type = IPLT_HASH;
5707663b816Sml37995 		op.iplo_struct = &htstat;
5717663b816Sml37995 		op.iplo_size = sizeof(htstat);
5727663b816Sml37995 		if (!(opts & OPT_DONOTHING)) {
5737663b816Sml37995 			c = ioctl(fd, SIOCLOOKUPSTAT, &op);
5747663b816Sml37995 			if (c == -1) {
5757663b816Sml37995 				perror("ioctl(SIOCLOOKUPSTAT)");
5767663b816Sml37995 				return -1;
5777663b816Sml37995 			}
5787663b816Sml37995 			printf("Hash Tables:\t%lu\n", htstat.iphs_numtables);
5797663b816Sml37995 			printf("Nodes:\t%lu\n", htstat.iphs_numnodes);
5807663b816Sml37995 			printf("Out of Memory:\t%lu\n", htstat.iphs_nomem);
5817663b816Sml37995 		}
5827663b816Sml37995 	}
5837c478bd9Sstevel@tonic-gate 	return 0;
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate int poolflush(argc, argv)
5887c478bd9Sstevel@tonic-gate int argc;
5897c478bd9Sstevel@tonic-gate char *argv[];
5907c478bd9Sstevel@tonic-gate {
5917c478bd9Sstevel@tonic-gate 	int c, role, type, arg;
5927c478bd9Sstevel@tonic-gate 	iplookupflush_t flush;
5937c478bd9Sstevel@tonic-gate 
5947c478bd9Sstevel@tonic-gate 	arg = IPLT_ALL;
5957c478bd9Sstevel@tonic-gate 	type = IPLT_ALL;
5967c478bd9Sstevel@tonic-gate 	role = IPL_LOGALL;
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "do:t:v")) != -1)
5997c478bd9Sstevel@tonic-gate 		switch (c)
6007c478bd9Sstevel@tonic-gate 		{
6017c478bd9Sstevel@tonic-gate 		case 'd' :
6027c478bd9Sstevel@tonic-gate 			opts |= OPT_DEBUG;
6037c478bd9Sstevel@tonic-gate 			break;
6047c478bd9Sstevel@tonic-gate 		case 'o' :
6057c478bd9Sstevel@tonic-gate 			role = getrole(optarg);
6067c478bd9Sstevel@tonic-gate 			if (role == IPL_LOGNONE) {
6077c478bd9Sstevel@tonic-gate 				fprintf(stderr, "unknown role '%s'\n", optarg);
6087c478bd9Sstevel@tonic-gate 				return -1;
6097c478bd9Sstevel@tonic-gate 			}
6107c478bd9Sstevel@tonic-gate 			break;
6117c478bd9Sstevel@tonic-gate 		case 't' :
6127c478bd9Sstevel@tonic-gate 			type = gettype(optarg, NULL);
6137c478bd9Sstevel@tonic-gate 			if (type == IPLT_NONE) {
6147c478bd9Sstevel@tonic-gate 				fprintf(stderr, "unknown type '%s'\n", optarg);
6157c478bd9Sstevel@tonic-gate 				return -1;
6167c478bd9Sstevel@tonic-gate 			}
6177c478bd9Sstevel@tonic-gate 			break;
6187c478bd9Sstevel@tonic-gate 		case 'v' :
6197c478bd9Sstevel@tonic-gate 			opts |= OPT_VERBOSE;
6207c478bd9Sstevel@tonic-gate 			break;
6217c478bd9Sstevel@tonic-gate 		}
6227c478bd9Sstevel@tonic-gate 
623*ab25eeb5Syz155240 	if (opts & OPT_DEBUG)
624*ab25eeb5Syz155240 		fprintf(stderr, "poolflush: opts = %#x\n", opts);
625*ab25eeb5Syz155240 
6267c478bd9Sstevel@tonic-gate 	if (!(opts & OPT_DONOTHING) && (fd == -1)) {
6277c478bd9Sstevel@tonic-gate 		fd = open(IPLOOKUP_NAME, O_RDWR);
6287c478bd9Sstevel@tonic-gate 		if (fd == -1) {
6297c478bd9Sstevel@tonic-gate 			perror("open(IPLOOKUP_NAME)");
6307c478bd9Sstevel@tonic-gate 			exit(1);
6317c478bd9Sstevel@tonic-gate 		}
6327c478bd9Sstevel@tonic-gate 	}
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate 	bzero((char *)&flush, sizeof(flush));
6357c478bd9Sstevel@tonic-gate 	flush.iplf_type = type;
6367c478bd9Sstevel@tonic-gate 	flush.iplf_unit = role;
6377c478bd9Sstevel@tonic-gate 	flush.iplf_arg = arg;
6387c478bd9Sstevel@tonic-gate 
6397c478bd9Sstevel@tonic-gate 	if (!(opts & OPT_DONOTHING)) {
6407c478bd9Sstevel@tonic-gate 		if (ioctl(fd, SIOCLOOKUPFLUSH, &flush) == -1) {
6417c478bd9Sstevel@tonic-gate 			perror("ioctl(SIOCLOOKUPFLUSH)");
6427c478bd9Sstevel@tonic-gate 			exit(1);
6437c478bd9Sstevel@tonic-gate 		}
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 	}
6467c478bd9Sstevel@tonic-gate 	printf("%u object%s flushed\n", flush.iplf_count,
6477c478bd9Sstevel@tonic-gate 	       (flush.iplf_count == 1) ? "" : "s");
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 	return 0;
6507c478bd9Sstevel@tonic-gate }
6517c478bd9Sstevel@tonic-gate 
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate int getrole(rolename)
6547c478bd9Sstevel@tonic-gate char *rolename;
6557c478bd9Sstevel@tonic-gate {
6567c478bd9Sstevel@tonic-gate 	int role;
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	if (!strcasecmp(rolename, "ipf")) {
6597c478bd9Sstevel@tonic-gate 		role = IPL_LOGIPF;
6607c478bd9Sstevel@tonic-gate #if 0
6617c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(rolename, "nat")) {
6627c478bd9Sstevel@tonic-gate 		role = IPL_LOGNAT;
6637c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(rolename, "state")) {
6647c478bd9Sstevel@tonic-gate 		role = IPL_LOGSTATE;
6657c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(rolename, "auth")) {
6667c478bd9Sstevel@tonic-gate 		role = IPL_LOGAUTH;
6677c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(rolename, "sync")) {
6687c478bd9Sstevel@tonic-gate 		role = IPL_LOGSYNC;
6697c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(rolename, "scan")) {
6707c478bd9Sstevel@tonic-gate 		role = IPL_LOGSCAN;
6717c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(rolename, "pool")) {
6727c478bd9Sstevel@tonic-gate 		role = IPL_LOGLOOKUP;
6737c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(rolename, "count")) {
6747c478bd9Sstevel@tonic-gate 		role = IPL_LOGCOUNT;
6757c478bd9Sstevel@tonic-gate #endif
6767c478bd9Sstevel@tonic-gate 	} else {
6777c478bd9Sstevel@tonic-gate 		role = IPL_LOGNONE;
6787c478bd9Sstevel@tonic-gate 	}
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 	return role;
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate int gettype(typename, minor)
6857c478bd9Sstevel@tonic-gate char *typename;
6867c478bd9Sstevel@tonic-gate u_int *minor;
6877c478bd9Sstevel@tonic-gate {
6887c478bd9Sstevel@tonic-gate 	int type;
6897c478bd9Sstevel@tonic-gate 
690*ab25eeb5Syz155240 	if (!strcasecmp(optarg, "tree")) {
6917c478bd9Sstevel@tonic-gate 		type = IPLT_POOL;
6927c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(optarg, "hash")) {
6937c478bd9Sstevel@tonic-gate 		type = IPLT_HASH;
6947c478bd9Sstevel@tonic-gate 		if (minor != NULL)
6957c478bd9Sstevel@tonic-gate 			*minor = IPHASH_LOOKUP;
6967c478bd9Sstevel@tonic-gate 	} else if (!strcasecmp(optarg, "group-map")) {
6977c478bd9Sstevel@tonic-gate 		type = IPLT_HASH;
6987c478bd9Sstevel@tonic-gate 		if (minor != NULL)
6997c478bd9Sstevel@tonic-gate 			*minor = IPHASH_GROUPMAP;
7007c478bd9Sstevel@tonic-gate 	} else {
7017c478bd9Sstevel@tonic-gate 		type = IPLT_NONE;
7027c478bd9Sstevel@tonic-gate 	}
7037c478bd9Sstevel@tonic-gate 	return type;
7047c478bd9Sstevel@tonic-gate }
705