Date: Fri, 27 Sep 2019 00:29:13 +0000 (UTC) From: Cy Schubert <cy@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r352786 - in head/contrib/ipfilter: man tools Message-ID: <201909270029.x8R0TDrn074535@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: cy Date: Fri Sep 27 00:29:12 2019 New Revision: 352786 URL: https://svnweb.freebsd.org/changeset/base/352786 Log: Implement the dynamic add (-A) and removal (-R) of ippool pools from the command line. Prior to this the functionality was mostly there however since the pool type (-t) was not recognized by the -A and -R command options -- not recognized by getopt(). Additionally the code to implement the dynamic add and removal of pools didn't work. When dynamically adding (-A) a pool a type (-t) to specify if the pool is a tree or hash pool must be specified. When dynamically removing (-R) a pool, omitting -t will cause a search-and-destroy which will remove both types of pools matching the name given (-m). PR: 218433 MFC after: 1 week Modified: head/contrib/ipfilter/man/ippool.8 head/contrib/ipfilter/tools/ippool.c Modified: head/contrib/ipfilter/man/ippool.8 ============================================================================== --- head/contrib/ipfilter/man/ippool.8 Fri Sep 27 00:29:09 2019 (r352785) +++ head/contrib/ipfilter/man/ippool.8 Fri Sep 27 00:29:12 2019 (r352786) @@ -9,7 +9,7 @@ ippool \- user interface to the IPFilter pools -a [-dnv] [-m <name>] [-o <role>] [-t <type>] [-T ttl] -i <ipaddr>[/<netmask>] .br .B ippool --A [-dnv] [-m <name>] [-o <role>] [-S <seed>] [-t <type>] +-A [-dnv] [-m <name>] [-o <role>] [-S <seed>] -t <type> .br .B ippool -f <file> [-dnuv] Modified: head/contrib/ipfilter/tools/ippool.c ============================================================================== --- head/contrib/ipfilter/tools/ippool.c Fri Sep 27 00:29:09 2019 (r352785) +++ head/contrib/ipfilter/tools/ippool.c Fri Sep 27 00:29:12 2019 (r352786) @@ -257,7 +257,7 @@ poolcommand(remove, argc, argv) char *argv[]; { int type, role, c, err; - char *poolname; + char *poolname, *typearg = NULL; iphtable_t iph; ip_pool_t pool; @@ -269,7 +269,7 @@ poolcommand(remove, argc, argv) bzero((char *)&iph, sizeof(iph)); bzero((char *)&pool, sizeof(pool)); - while ((c = getopt(argc, argv, "dm:no:S:v")) != -1) + while ((c = getopt(argc, argv, "dm:no:S:vt:")) != -1) switch (c) { case 'd' : @@ -295,6 +295,10 @@ poolcommand(remove, argc, argv) else usage(argv[0]); break; + case 't' : + type = gettype(optarg, &iph.iph_type); + typearg = optarg; + break; case 'v' : opts |= OPT_VERBOSE; break; @@ -314,17 +318,22 @@ poolcommand(remove, argc, argv) return -1; } - type = gettype(argv[optind], &iph.iph_type); - if (type == IPLT_NONE) { - fprintf(stderr, "unknown type '%s'\n", argv[optind]); + if (type == IPLT_NONE && remove == 0) { + if (typearg == NULL) { + fprintf(stderr, "type must be specified\n"); + usage(argv[0]); + } else { + fprintf(stderr, "unknown type '%s'\n", typearg); + } return -1; } - if (type == IPLT_HASH) { + if (type == IPLT_HASH || (type == IPLT_NONE && remove == 1)) { strncpy(iph.iph_name, poolname, sizeof(iph.iph_name)); iph.iph_name[sizeof(iph.iph_name) - 1] = '\0'; iph.iph_unit = role; - } else if (type == IPLT_POOL) { + } + if (type == IPLT_POOL || (type == IPLT_NONE && remove == 1)) { strncpy(pool.ipo_name, poolname, sizeof(pool.ipo_name)); pool.ipo_name[sizeof(pool.ipo_name) - 1] = '\0'; pool.ipo_unit = role; @@ -348,6 +357,16 @@ poolcommand(remove, argc, argv) break; case IPLT_POOL : err = remove_pool(&pool, ioctl); + break; + case IPLT_NONE : + err = 1; + { + int err_h, err_p; + err_h = remove_hash(&iph, ioctl); + err_p = remove_pool(&pool, ioctl); + if (err_h == 0 || err_p == 0) + err = 0; + } break; } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909270029.x8R0TDrn074535>