netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [iptables PATCH 1/3] extensions: libipt_icmp: Fix confusion between 255/255 and any
@ 2023-08-02  2:05 Phil Sutter
  2023-08-02  2:05 ` [iptables PATCH 2/3] extensions: libipt_icmp: --icmp-type is not mandatory Phil Sutter
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Phil Sutter @ 2023-08-02  2:05 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Amelia Downs

Per definition, ICMP type "any" is type 255 and the full range of codes
(0-255). Save callback though ignored the actual code values, printing
"any" for every type 255 match. This at least confuses users as they
can't find their rule added as '--icmp-type 255/255' anymore.

It is not entirely clear what the fixed commit was trying to establish,
but the save output is certainly not correct (especially since print
callback gets things right).

Reported-by: Amelia Downs <adowns@vmware.com>
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1600
Fixes: fc9237da4e845 ("Fix '-p icmp -m icmp' issue (Closes: #37)")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 extensions/libipt_icmp.c | 3 ++-
 extensions/libipt_icmp.t | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/extensions/libipt_icmp.c b/extensions/libipt_icmp.c
index b0318aebc2c57..171b3b3949e54 100644
--- a/extensions/libipt_icmp.c
+++ b/extensions/libipt_icmp.c
@@ -108,7 +108,8 @@ static void icmp_save(const void *ip, const struct xt_entry_match *match)
 		printf(" !");
 
 	/* special hack for 'any' case */
-	if (icmp->type == 0xFF) {
+	if (icmp->type == 0xFF &&
+	    icmp->code[0] == 0 && icmp->code[1] == 0xFF) {
 		printf(" --icmp-type any");
 	} else {
 		printf(" --icmp-type %u", icmp->type);
diff --git a/extensions/libipt_icmp.t b/extensions/libipt_icmp.t
index f4ba65c27f032..ce4a33f9633b5 100644
--- a/extensions/libipt_icmp.t
+++ b/extensions/libipt_icmp.t
@@ -13,3 +13,5 @@
 # we accept "iptables -I INPUT -p tcp -m tcp", why not this below?
 # ERROR: cannot load: iptables -A INPUT -p icmp -m icmp
 # -p icmp -m icmp;=;OK
+-p icmp -m icmp --icmp-type 255/255;=;OK
+-p icmp -m icmp --icmp-type 255/0:255;-p icmp -m icmp --icmp-type any;OK
-- 
2.40.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-04 13:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-02  2:05 [iptables PATCH 1/3] extensions: libipt_icmp: Fix confusion between 255/255 and any Phil Sutter
2023-08-02  2:05 ` [iptables PATCH 2/3] extensions: libipt_icmp: --icmp-type is not mandatory Phil Sutter
2023-08-02  2:05 ` [iptables PATCH 3/3] tests: libipt_icmp.t: Enable tests with numeric output Phil Sutter
2023-08-02  8:31 ` [iptables PATCH 1/3] extensions: libipt_icmp: Fix confusion between 255/255 and any Jan Engelhardt
2023-08-03 12:57   ` Phil Sutter
2023-08-03 19:38     ` Jan Engelhardt
2023-08-04 13:56       ` Phil Sutter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).