From nobody Tue Mar 15 15:20:11 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 4A1191A192D4; Tue, 15 Mar 2022 15:20:12 +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 4KHxt36CYCz4Zp0; Tue, 15 Mar 2022 15:20:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647357612; 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=OEDs5H2oHH5C+syyb6TMZAHTR0+n7xPr67NM2lQU2YY=; b=Hw7w7v+2rbVUTPZqDtrZ8T5kTgUf2wiysohP/tODybhcS9NSlETyOI4ljzhoMGnwYVCe2N GsVqTcIG/TkIu62wjG9B0PVbjHYSxuR08O+k/m0EjWSYoNi86FGKAsTrM9CxvJxEFoYuuV cs7X8ZIzIZt2A3Bhl6qhIUlxqH1JZqbrP1STtfar2xsuboJT+6okZoPivcnwHdtoqzve87 6JK11uAc74xZL/f1yGHvE4dNCcD6b9HE5FN6EkRShmcT2oCJw521wtwE6N13U66ctKNQW1 6b0EDCi5JcEffC4VwN6nbWptchBeypa+qH9SBXK/mdovX+2CLmCqb3hD74xktg== 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 96C6324145; Tue, 15 Mar 2022 15:20:11 +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 22FFKBrj033930; Tue, 15 Mar 2022 15:20:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22FFKBn8033924; Tue, 15 Mar 2022 15:20:11 GMT (envelope-from git) Date: Tue, 15 Mar 2022 15:20:11 GMT Message-Id: <202203151520.22FFKBn8033924@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 4da31fbe58a4 - stable/13 - pfctl: support recursive printing of nat rules 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4da31fbe58a43cfbd15350fc36c1e8357123b334 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647357612; 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=OEDs5H2oHH5C+syyb6TMZAHTR0+n7xPr67NM2lQU2YY=; b=QEmjwhquFLWGjwYPB+2CJtHyV7TijXiT4K58j8/z+kC8S3HUqwYwBot72yMBp/JUjJc6DU N/fO3x3yKqWYBvw0aWyDgY2Xvcr0YRVsgjy6fVu/+eBC5k6OAtrS0Jw1sjwPQyOmzilc8H aZMiyyGe3uRn71FuTAEVenYXaSuALrU0vw+GqDPWUVZH6hENshWVxUK+wIG3oeczixKkMx w05SrmMPvPngquC3zmxSOClvFRX0DNrAxodLDxZJdG/VgX4QHNWKixgmOkSLJ0gwlqr6oK F+PatSqJbE7ip21tl7PU5RQi7x6GZmHK+0f4LZ/oGNoe49XND7BxFjgRdnUrZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647357612; a=rsa-sha256; cv=none; b=BRvW2PhiKkUwKzCroMblFmJvG7axX97DlADSs1w93fPFT0UJrYJCK4BkURhwKDLHM0DMgF eW56TBsWVryrfniUqv6DARjuAdLVFMnHHpLan/VTpzn1wUeLDrWqe83nRL4qn7jNkl4iym owqZHkmcxM7i9XewX+j24Jrk3t2j5lDb8NPgeHNovqYpL/pUEvJ856ueBWwi9SErUMora1 lk3qzoo8oeSOgimUiBGSCMc6ghM7xlcfkvAkWzVubME37MMt4m7ZxOGW8424jCU8kWe7tE qtPhlCt8fGUZmBphN8ck0fW8xASyb+QgsaYzVNwAuqAuP99motjMEarV61Gp0w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=4da31fbe58a43cfbd15350fc36c1e8357123b334 commit 4da31fbe58a43cfbd15350fc36c1e8357123b334 Author: Kristof Provost AuthorDate: 2022-03-05 16:55:48 +0000 Commit: Kristof Provost CommitDate: 2022-03-15 02:52:18 +0000 pfctl: support recursive printing of nat rules PR: 252617 MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D34455 (cherry picked from commit a20773c810814dd130ca1f0fbf08d27fea465555) --- 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 a0eec1b09289..342f355a0116 100644 --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -98,7 +98,7 @@ int pfctl_get_pool(int, struct pfctl_pool *, u_int32_t, u_int32_t, int, char *); void pfctl_print_rule_counters(struct pfctl_rule *, 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); @@ -1191,17 +1191,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"); @@ -1209,6 +1211,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)) { @@ -1218,15 +1223,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); @@ -2537,7 +2564,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, @@ -2565,7 +2592,7 @@ main(int argc, char *argv[]) opts |= PF_OPT_SHOWALL; pfctl_load_fingerprints(dev, opts); - 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);