Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Feb 2025 11:19:54 GMT
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 63422982e074 - stable/13 - ipfw: make 'ipfw show' output compatible with 'ipfw add' command
Message-ID:  <202502211119.51LBJst4016774@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by ae:

URL: https://cgit.FreeBSD.org/src/commit/?id=63422982e074a144cfb420408be06e6dc154f9fe

commit 63422982e074a144cfb420408be06e6dc154f9fe
Author:     Andrey V. Elsukov <ae@FreeBSD.org>
AuthorDate: 2025-02-11 09:48:17 +0000
Commit:     Andrey V. Elsukov <ae@FreeBSD.org>
CommitDate: 2025-02-21 11:18:44 +0000

    ipfw: make 'ipfw show' output compatible with 'ipfw add' command
    
    If rule was added in compact form and rule body is empty, print
    'proto ip' opcode to be compatible with ipfw(8) syntax parser.
    
      Before:
      $ ipfw add allow proto ip
      000700 allow
      After:
      $ ipfw add allow proto ip
      000700 allow proto ip
    
    (cherry picked from commit 706a03f61bbb6e0cf10e6c3727966495b30d763e)
---
 sbin/ipfw/ipfw2.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
index 46c51081ded4..7a084249c4eb 100644
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -2276,6 +2276,13 @@ show_static_rule(struct cmdline_opts *co, struct format_opts *fo,
 
 	if (rule->flags & IPFW_RULE_JUSTOPTS) {
 		state.flags |= HAVE_PROTO | HAVE_SRCIP | HAVE_DSTIP;
+		/*
+		 * Print `proto ip` if all opcodes has been already printed.
+		 */
+		if (memchr(state.printed, 0, rule->act_ofs) == NULL) {
+			bprintf(bp, " proto ip");
+			goto end;
+		}
 		goto justopts;
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502211119.51LBJst4016774>