From nobody Tue Mar 08 10:52:35 2022 X-Original-To: dev-commits-src-main@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 7444F19FAC18; Tue, 8 Mar 2022 10:52:35 +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 4KCXGW2sQ9z3CHD; Tue, 8 Mar 2022 10:52:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646736755; 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=KcdIQ5ghw3NE16vq5TG4phIIXmCwTqUV4PYHyQWTak0=; b=lr58WDyfBFuNDE65QoGsO/TvglSBhzjyFgOgW01j+ALD2g73bB5xKbfw7meuNtM5rzx49G rNePvj4xU+OQdCGuJBrZS3wySHhKGMgCwsxk4Gn3v3SFuWqWE64OQ3RSJ9wLltgZN2b0BW sP+FMmC+fkgCJx5IIcaQKTxvBi9mvEEYAVTvPnjRvkiT+bvuv2bOfDbcTc4McqI4W5+dhO CKY0SJW5ZB4jGMsPYcg1igoD8rZ10qG7xi053BndrtTPJbc1m3wYAE6K56RC7KoFZahWNb 6NNwMKf+5SsAphvqvs191i7h7vbXWa1HVFkQ4CLfbXH+Mw7EoIeH1SfENHKFdw== 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 420E41ACF8; Tue, 8 Mar 2022 10:52:35 +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 228AqZka022538; Tue, 8 Mar 2022 10:52:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 228AqZPP022537; Tue, 8 Mar 2022 10:52:35 GMT (envelope-from git) Date: Tue, 8 Mar 2022 10:52:35 GMT Message-Id: <202203081052.228AqZPP022537@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: a20773c81081 - main - pfctl: support recursive printing of nat rules List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a20773c810814dd130ca1f0fbf08d27fea465555 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646736755; 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=KcdIQ5ghw3NE16vq5TG4phIIXmCwTqUV4PYHyQWTak0=; b=Qwm5Y9jTFDZYhsTUaG3kNwV280nhga5m40xM8J1lnBSS8RzH3rpgtma1va2jTzav3vmPAN Io54WHpBZXKnwLlEOg6V/0k4YzZzeOdLD5fqnplxn5jbgt/dqFrRU0QXGQoDLJk/CAnPu7 YDWxjhmHkoff89jVxgS6dgffJsf8zi2XEAfTBe3sJHlpCI6zr2tXIyanthb0cj/0U95g3S GH4Hs1LnZxWj7Hnyd4N8TO/dgmmq5ZHeBOQ4kBiPDn91BL+wspRb3FDdHZYUt+1FJ42o1m +yMqM5ZSxjZW+jjvg1v73OeVoQfW2ShksmSWEKukSz+smgJpLD7yPyW5W+l4zA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646736755; a=rsa-sha256; cv=none; b=kJM0Pj4xHd4DoHk3awBX9OJLigtKFYChBmuS24lMdYqBYJHom4VaSGQhItybS9MtyKJVrQ XaAtOzH79TmCNEMjAsohKgM2kfM/cnrEkOrghEsL8brZo/ZIRiQnt7utpd1T1iFgrfSdlv G74mhsODr1QbV906RryupoQ0vm3BWkf6WUl3SjDK8jGtdI4V2Baia3gsrAEMFr7IPYxxAb obePcza7ig/WLQLxIFQu/43ZR2ObdPfv5GZ0pm72giQGR8kFfbybc/2pFhjUqd1fsvUVSc jiRSScYCxr4SXGJpI+heqJp5pqHYcfL7BE0bK2yQ2DLgvf8MS8C3FEpVA7EkkA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=a20773c810814dd130ca1f0fbf08d27fea465555 commit a20773c810814dd130ca1f0fbf08d27fea465555 Author: Kristof Provost AuthorDate: 2022-03-05 16:55:48 +0000 Commit: Kristof Provost CommitDate: 2022-03-08 09:51:09 +0000 pfctl: support recursive printing of nat rules PR: 252617 MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D34455 --- sbin/pfctl/pfctl.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c index 4ff1bd25e0eb..b1d6c6899716 100644 --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -101,7 +101,7 @@ void pfctl_print_eth_rule_counters(struct pfctl_eth_rule *, int); void pfctl_print_rule_counters(struct pfctl_rule *, int); int pfctl_show_eth_rules(int, char *, int, enum pfctl_show, char *, int); int pfctl_show_rules(int, char *, int, enum pfctl_show, char *, int); -int pfctl_show_nat(int, int, char *); +int pfctl_show_nat(int, char *, int, char *, int); int pfctl_show_src_nodes(int, int); int pfctl_show_states(int, const char *, int); int pfctl_show_status(int, int); @@ -1296,17 +1296,19 @@ pfctl_show_rules(int dev, char *path, int opts, enum pfctl_show format, } int -pfctl_show_nat(int dev, int opts, char *anchorname) +pfctl_show_nat(int dev, char *path, int opts, char *anchorname, int depth) { struct pfioc_rule pr; struct pfctl_rule rule; u_int32_t mnr, nr; static int nattype[3] = { PF_NAT, PF_RDR, PF_BINAT }; int i, dotitle = opts & PF_OPT_SHOWALL; + int brace; + char *p; - memset(&pr, 0, sizeof(pr)); - memcpy(pr.anchor, anchorname, sizeof(pr.anchor)); for (i = 0; i < 3; i++) { + memset(&pr, 0, sizeof(pr)); + memcpy(pr.anchor, anchorname, sizeof(pr.anchor)); pr.rule.action = nattype[i]; if (ioctl(dev, DIOCGETRULES, &pr)) { warn("DIOCGETRULES"); @@ -1314,6 +1316,9 @@ pfctl_show_nat(int dev, int opts, char *anchorname) } mnr = pr.nr; for (nr = 0; nr < mnr; ++nr) { + brace = 0; + INDENT(depth, !(opts & PF_OPT_VERBOSE)); + pr.nr = nr; if (pfctl_get_rule(dev, nr, pr.ticket, anchorname, nattype[i], &rule, pr.anchor_call)) { @@ -1323,15 +1328,37 @@ pfctl_show_nat(int dev, int opts, char *anchorname) if (pfctl_get_pool(dev, &rule.rpool, nr, pr.ticket, nattype[i], anchorname) != 0) return (-1); + + if (pr.anchor_call[0] && + ((((p = strrchr(pr.anchor_call, '_')) != NULL) && + (p == pr.anchor_call || + *(--p) == '/')) || (opts & PF_OPT_RECURSE))) { + brace++; + if ((p = strrchr(pr.anchor_call, '/')) != + NULL) + p++; + else + p = &pr.anchor_call[0]; + } else + p = &pr.anchor_call[0]; + if (dotitle) { pfctl_print_title("TRANSLATION RULES:"); dotitle = 0; } print_rule(&rule, pr.anchor_call, opts & PF_OPT_VERBOSE2, opts & PF_OPT_NUMERIC); - printf("\n"); + if (brace) + printf(" {\n"); + else + printf("\n"); pfctl_print_rule_counters(&rule, opts); pfctl_clear_pool(&rule.rpool); + if (brace) { + pfctl_show_nat(dev, path, opts, p, depth + 1); + INDENT(depth, !(opts & PF_OPT_VERBOSE)); + printf("}\n"); + } } } return (0); @@ -2827,7 +2854,7 @@ main(int argc, char *argv[]) break; case 'n': pfctl_load_fingerprints(dev, opts); - pfctl_show_nat(dev, opts, anchorname); + pfctl_show_nat(dev, path, opts, anchorname, 0); break; case 'q': pfctl_show_altq(dev, ifaceopt, opts, @@ -2860,7 +2887,7 @@ main(int argc, char *argv[]) pfctl_show_eth_rules(dev, path, opts, 0, anchorname, 0); - pfctl_show_nat(dev, opts, anchorname); + pfctl_show_nat(dev, path, opts, anchorname, 0); pfctl_show_rules(dev, path, opts, 0, anchorname, 0); pfctl_show_altq(dev, ifaceopt, opts, 0); pfctl_show_states(dev, ifaceopt, opts);