diff options
author | Andrey V. Elsukov <ae@FreeBSD.org> | 2025-02-11 09:48:17 +0000 |
---|---|---|
committer | Andrey V. Elsukov <ae@FreeBSD.org> | 2025-02-11 09:48:17 +0000 |
commit | 706a03f61bbb6e0cf10e6c3727966495b30d763e (patch) | |
tree | e1c4262bfe17e84c01653bdc4cc35393353263e3 /sbin | |
parent | 03704b89e78560823cac4e447885412cb395a527 (diff) |
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
MFC after: 1 week
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ipfw/ipfw2.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c index 51eae7e8e246..cc0970207749 100644 --- a/sbin/ipfw/ipfw2.c +++ b/sbin/ipfw/ipfw2.c @@ -2380,6 +2380,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; } |