From nobody Thu Sep 22 22:39:25 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MYVZj6mPFz4cVCV; Thu, 22 Sep 2022 22:39:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MYVZj6CBbz3ypk; Thu, 22 Sep 2022 22:39:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663886365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ddpDRx8lbHddgqFa2JwMYmSjQpqhw4RZBtEd/fMvOC4=; b=DsZ7owYddIJzboC04CbFE0g0kXEZ/WQfDR+qFcybEj50Nnw3noS2j+FFXUC/j87Nr89Lyz eQRfTxfVPxeBTTx0GWohNN5Fej0ERPVlHr2F4QHuoKLAjaXt7yO4jrT7hZYVEnwtcsJBY9 /4gjN4wETIglDH4uOLI59VG8cKO3OFkPt010107FLeum5GI6IJJP1H03pPmTXK00LBoGY/ xvPEVdBtSKcF8QkddcIKbg0Y8gYZhEdm8WtCe5srorETyA+C5ZW9RV/xUUonx87v+ih8AC 3Lh7Vd5pWZcXVRxJtLcH3dEb2+t7FRrMEDYB2JoZ+LGikxRd4/uEjFLQCSVjbA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MYVZj5Cs8zYQP; Thu, 22 Sep 2022 22:39:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 28MMdPJG021704; Thu, 22 Sep 2022 22:39:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28MMdPcx021702; Thu, 22 Sep 2022 22:39:25 GMT (envelope-from git) Date: Thu, 22 Sep 2022 22:39:25 GMT Message-Id: <202209222239.28MMdPcx021702@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Cy Schubert Subject: git: 7531c434a593 - main - ipfilter/ippool: Dump a copy of ippool in ippool.conf format List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cy X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7531c434a593b2f369d69c85551e7ad1ebb7499a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663886365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ddpDRx8lbHddgqFa2JwMYmSjQpqhw4RZBtEd/fMvOC4=; b=rF1zY3F9EoqKRKsac3midNmYIs7xiCWwTcsUrkxvQ/xXVMfJ935x22YurMSbOEAWoEEHoq B4tRkWwZxKPoHHkAsPdRM5IV7rviO86IVtD89ZFo2lrX+hKz0B7JvGRqRp+EzqrNyiB0GT Q7PqeLWJ3h0+qT7i5rahc7GBen01uekupanxJNARFxAa2pcD6I9nGi8kDi0DQTErXKiecA OvzK5WKm+z1ijjD3jaG3cOsh9aRdUjJ/+fc4oNi4D2gUr0FXkgv7+D7XGIolAQGxC0GpC6 cyKxPeOXKoY1tPJQSxos/5agfuw9D/o3Rv3bvp5Oiq0ia96Kfg3yk409AoIEWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663886365; a=rsa-sha256; cv=none; b=vJtxq3ikTOOwzYpbTv9crVFQt6DmgKBi2AGpCDnhvg0LCceuLdoreGuDMXDgdvPqy+L/7R /2BZyGY3DxiPKxqCk/vQIMSeStRC2sBjys/HyGLSuVEhDH4dcVWS5V0yMG4hFBJpQH5cLW vcMf3DbmF5eEwuz1u8t5SeDzK0BHtnvPSCqMR9S5XLJO6r8Xs5ljjlHqh1iCC2ez02V+w3 mOWBzircKQXuA03HkckjXdWdJsSDp4YJ9w1dwmWW5ke3Ns+L6agLgC+i7CWe9jWUGk7kHX 7YSFKJQqxjHUb7efD96xDoGtJfeCUV4Nrx4gP6XuCmQ/UUGUChiLDMmRh9WPQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by cy: URL: https://cgit.FreeBSD.org/src/commit/?id=7531c434a593b2f369d69c85551e7ad1ebb7499a commit 7531c434a593b2f369d69c85551e7ad1ebb7499a Author: Cy Schubert AuthorDate: 2022-09-21 15:33:11 +0000 Commit: Cy Schubert CommitDate: 2022-09-22 22:38:11 +0000 ipfilter/ippool: Dump a copy of ippool in ippool.conf format Add an ippool(8) option to dump a copy of the inm-memory ippool tables in an ippool(5) format so that it can be reloaded using ippool -f. MFC after: 2 weeks --- sbin/ipf/ippool/ippool.8 | 6 +++++- sbin/ipf/ippool/ippool.c | 5 ++++- sbin/ipf/libipf/printpool_live.c | 12 ++++++++++-- sbin/ipf/libipf/printpooldata.c | 10 ++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/sbin/ipf/ippool/ippool.8 b/sbin/ipf/ippool/ippool.8 index bcc8f3cbd71d..358ece5a26ff 100644 --- a/sbin/ipf/ippool/ippool.8 +++ b/sbin/ipf/ippool/ippool.8 @@ -18,7 +18,7 @@ ippool \- user interface to the IPFilter pools -F [-dv] [-o ] [-t ] .br .B ippool --l [-dv] [-m ] [-t ] [-o ] [-M ] [-N ] +-l [-dDv] [-m ] [-t ] [-o ] [-M ] [-N ] .br .B ippool -r [-dnv] [-m ] [-o ] [-t ] -i [/] @@ -121,6 +121,10 @@ as a number of seconds. When parsing a configuration file, rather than load new pool data into the kernel, unload it. .TP +.B -D +When used in conjuction with -l, dump the ippool configuration to stdout in +a format that can be subsequently used as input into ippool -f. +.TP .SH FILES .br /dev/iplookup diff --git a/sbin/ipf/ippool/ippool.c b/sbin/ipf/ippool/ippool.c index 3e8918e1fcfa..384146d729c9 100644 --- a/sbin/ipf/ippool/ippool.c +++ b/sbin/ipf/ippool/ippool.c @@ -670,12 +670,15 @@ poollist(int argc, char *argv[]) poolname = NULL; role = IPL_LOGALL; - while ((c = getopt(argc, argv, "dm:M:N:o:t:v")) != -1) + while ((c = getopt(argc, argv, "dDm:M:N:o:t:v")) != -1) switch (c) { case 'd' : opts |= OPT_DEBUG; break; + case 'D' : + opts |= OPT_SAVEOUT; + break; case 'm' : poolname = optarg; break; diff --git a/sbin/ipf/libipf/printpool_live.c b/sbin/ipf/libipf/printpool_live.c index 324deb629d0b..c1d770b4ef77 100644 --- a/sbin/ipf/libipf/printpool_live.c +++ b/sbin/ipf/libipf/printpool_live.c @@ -26,7 +26,9 @@ printpool_live(ip_pool_t *pool, int fd, char *name, int opts, if ((pool->ipo_flags & IPOOL_DELETE) != 0) PRINTF("# "); - if ((opts & OPT_DEBUG) == 0) + if (opts & OPT_SAVEOUT) + PRINTF("{\n"); + else if ((opts & OPT_DEBUG) == 0) PRINTF("\t{"); obj.ipfo_rev = IPFILTER_VERSION; @@ -48,9 +50,13 @@ printpool_live(ip_pool_t *pool, int fd, char *name, int opts, while (!last && (ioctl(fd, SIOCLOOKUPITER, &obj) == 0)) { if (entry.ipn_next == NULL) last = 1; + if (opts & OPT_SAVEOUT) + PRINTF("\t"); (void) printpoolnode(&entry, opts, fields); if ((opts & OPT_DEBUG) == 0) putchar(';'); + if (opts & OPT_SAVEOUT) + PRINTF("\n"); printed++; } } @@ -58,7 +64,9 @@ printpool_live(ip_pool_t *pool, int fd, char *name, int opts, if (printed == 0) putchar(';'); - if ((opts & OPT_DEBUG) == 0) + if (opts & OPT_SAVEOUT) + PRINTF("};\n"); + else if ((opts & OPT_DEBUG) == 0) PRINTF(" };\n"); (void) ioctl(fd,SIOCIPFDELTOK, &iter.ili_key); diff --git a/sbin/ipf/libipf/printpooldata.c b/sbin/ipf/libipf/printpooldata.c index ce754f9a89bb..bd5af316eb19 100644 --- a/sbin/ipf/libipf/printpooldata.c +++ b/sbin/ipf/libipf/printpooldata.c @@ -12,7 +12,9 @@ void printpooldata(ip_pool_t *pool, int opts) { - if ((opts & OPT_DEBUG) == 0) { + if (opts & OPT_SAVEOUT) { + PRINTF("pool "); + } else if ((opts & OPT_DEBUG) == 0) { if ((pool->ipo_flags & IPOOL_ANON) != 0) PRINTF("# 'anonymous' tree %s\n", pool->ipo_name); if ((pool->ipo_flags & IPOOL_DELETE) != 0) @@ -32,7 +34,11 @@ printpooldata(ip_pool_t *pool, int opts) printunit(pool->ipo_unit); - if ((opts & OPT_DEBUG) == 0) { + if ((opts & OPT_SAVEOUT)) { + PRINTF("/tree (%s \"\%s\";)\n", + (!*pool->ipo_name || ISDIGIT(*pool->ipo_name)) ? \ + "number" : "name", pool->ipo_name); + } else if ((opts & OPT_DEBUG) == 0) { PRINTF(" type=tree %s=%s\n", (!*pool->ipo_name || ISDIGIT(*pool->ipo_name)) ? \ "number" : "name", pool->ipo_name);