Skip to contentSkip to conversation

icmpv6 match --icmpv6-type confusion

PATCH In review Phil Oester 3 participants 6 messages Jun 30, 2006 – Jul 4, 2006 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 icmpv6 match --icmpv6-type confusion

Adding a rule such as this:

-A INPUT -p ipv6-icmp -m icmpv6

ends up creating a rule with "ipv6-icmp type 0", instead of "ipv6-icmp type any" which is what was expected. Granted, the match is redundant anyway, but it should not assume a specific type when one is not specified.

Below patches (to both kernel and userspace) fix this, and resolve bug #461. In keeping with icmpv4, 0xFF is used to designate "any". And since I was looking at it, I fixed up a 255 -> any in icmpv4 printing.

Phil

net/ipv6/netfilter/ip6_tables.c +1 -1
@@ -1308,7 +1308,7 @@
 		     u_int8_t type, u_int8_t code,
 		     int invert)
 {
-	return (type == test_type && code >= min_code && code <= max_code)
+	return ((test_type == 0xFF) || (type == test_type && code >= min_code && code <= max_code))
 		^ invert;
 }
 
extensions/libip6t_icmp6.c +13 -2
diff -ru ipt-orig/extensions/libip6t_icmp6.c ipt-new/extensions/libip6t_icmp6.c
@@ -149,6 +149,7 @@
 {
 	struct ip6t_icmp *icmpv6info = (struct ip6t_icmp *)m->data;
 
+	icmpv6info->type = 0xFF;
 	icmpv6info->code[1] = 0xFF;
 }
 
@@ -206,7 +207,12 @@
 	if (invert)
 		printf("!");
 
-	printf("type %u", type);
+	/* special hack for 'any' case */
+	if (type == 0xFF)
+		printf("type any ");
+	else
+		printf("type %u", type);
+
 	if (code_min == 0 && code_max == 0xFF)
 		printf(" ");
 	else if (code_min == code_max)
@@ -241,7 +247,12 @@
 	if (icmpv6->invflags & IP6T_ICMP_INV)
 		printf("! ");
 
-	printf("--icmpv6-type %u", icmpv6->type);
+	/* special hack for 'any' case */
+	if (icmpv6->type == 0xFF)
+		printf("--icmpv6-type any ");
+	else
+		printf("--icmpv6-type %u", icmpv6->type);
+
 	if (icmpv6->code[0] != 0 || icmpv6->code[1] != 0xFF)
 		printf("/%u", icmpv6->code[0]);
 	printf(" ");
extensions/libipt_icmp.c +6 -1
diff -ru ipt-orig/extensions/libipt_icmp.c ipt-new/extensions/libipt_icmp.c
@@ -231,7 +231,12 @@
 	if (invert)
 		printf("!");
 
-	printf("type %u", type);
+	/* special hack for 'any' case */
+	if (type == 0xFF)
+		printf("type any ");
+	else
+		printf("type %u", type);
+
 	if (code_min == 0 && code_max == 0xFF)
 		printf(" ");
 	else if (code_min == code_max)
#1 lore raw
Quoted 11 lines · Phil Oester

Adding a rule such as this:

-A INPUT -p ipv6-icmp -m icmpv6

ends up creating a rule with "ipv6-icmp type 0", instead of "ipv6-icmp type any" which is what was expected. Granted, the match is redundant anyway, but it should not assume a specific type when one is not specified.

Below patches (to both kernel and userspace) fix this, and resolve bug #461. In keeping with icmpv4, 0xFF is used to designate "any". And since I was looking at it, I fixed up a 255 -> any in icmpv4 printing.

Thanks Phil. I have to admit that I never liked the ugly 255 hack, its a perfectly valid value for the type field to use, even though its currently not defined for IPv4 or IPv6. For IPv6 I even have some concerns that it will stay unused for all times, the stategy for choosing new values seems to be different from IPv4. I guess an alternative would be to introduce a new revision.

Yasuyuki, do you have an opinion on this?

#2 lore raw

From: Patrick McHardy <[email protected]>
Subject: Re: [PATCH] icmpv6 match --icmpv6-type confusion
Date: Mon, 03 Jul 2006 19:52:23 +0200

Quoted 13 lines
Quoted 11 lines · Phil Oester

Adding a rule such as this:

-A INPUT -p ipv6-icmp -m icmpv6

ends up creating a rule with "ipv6-icmp type 0", instead of "ipv6-icmp type any" which is what was expected. Granted, the match is redundant anyway, but it should not assume a specific type when one is not specified.

Below patches (to both kernel and userspace) fix this, and resolve bug #461. In keeping with icmpv4, 0xFF is used to designate "any". And since I was looking at it, I fixed up a 255 -> any in icmpv4 printing.

Quoted 8 lines

Thanks Phil. I have to admit that I never liked the ugly 255 hack, its a perfectly valid value for the type field to use, even though its currently not defined for IPv4 or IPv6. For IPv6 I even have some concerns that it will stay unused for all times, the stategy for choosing new values seems to be different from IPv4. I guess an alternative would be to introduce a new revision.

Yasuyuki, do you have an opinion on this?

It sounds good to me to introduce a new revision and a new value to support "icmpv6-type any". But can we really break behavior compatibility of "-p ipv6-icmp -m icmpv6" ?

-- Yasuyuki Kozakai

#4 lore raw
In reply to a message not in the archive
Quoted 24 lines · Yasuyuki KOZAKAI

From: Patrick McHardy <[email protected]>
Subject: Re: [PATCH] icmpv6 match --icmpv6-type confusion
Date: Mon, 03 Jul 2006 19:52:23 +0200

Quoted 21 lines
Quoted 11 lines · Phil Oester

Adding a rule such as this:

-A INPUT -p ipv6-icmp -m icmpv6

ends up creating a rule with "ipv6-icmp type 0", instead of "ipv6-icmp type any" which is what was expected. Granted, the match is redundant anyway, but it should not assume a specific type when one is not specified.

Below patches (to both kernel and userspace) fix this, and resolve bug #461. In keeping with icmpv4, 0xFF is used to designate "any". And since I was looking at it, I fixed up a 255 -> any in icmpv4 printing.

Thanks Phil. I have to admit that I never liked the ugly 255 hack, its a perfectly valid value for the type field to use, even though its currently not defined for IPv4 or IPv6. For IPv6 I even have some concerns that it will stay unused for all times, the stategy for choosing new values seems to be different from IPv4. I guess an alternative would be to introduce a new revision.

Quoted 6 lines
Quoted 1 line

Yasuyuki, do you have an opinion on this?

It sounds good to me to introduce a new revision and a new value to support "icmpv6-type any". But can we really break behavior compatibility of "-p ipv6-icmp -m icmpv6" ?

I tend to agree with Phil's interpretation that this is actually unexpected behaviour, so I don't think anyone is doing this intentional. I would expect either a parser error or type any.

#5 lore raw

From: Patrick McHardy <[email protected]>
Date: Tue, 04 Jul 2006 02:46:41 +0200

Quoted 28 lines
Quoted 27 lines · Yasuyuki KOZAKAI

From: Patrick McHardy <[email protected]>
Subject: Re: [PATCH] icmpv6 match --icmpv6-type confusion
Date: Mon, 03 Jul 2006 19:52:23 +0200

Quoted 22 lines
Quoted 11 lines · Phil Oester

Adding a rule such as this:

-A INPUT -p ipv6-icmp -m icmpv6

ends up creating a rule with "ipv6-icmp type 0", instead of "ipv6-icmp type any" which is what was expected. Granted, the match is redundant anyway, but it should not assume a specific type when one is not specified.

Below patches (to both kernel and userspace) fix this, and resolve bug #461. In keeping with icmpv4, 0xFF is used to designate "any". And since I was looking at it, I fixed up a 255 -> any in icmpv4 printing.

Thanks Phil. I have to admit that I never liked the ugly 255 hack, its a perfectly valid value for the type field to use, even though its currently not defined for IPv4 or IPv6. For IPv6 I even have some concerns that it will stay unused for all times, the stategy for choosing new values seems to be different from IPv4. I guess an alternative would be to introduce a new revision.

Yasuyuki, do you have an opinion on this?

Quoted 8 lines
Quoted 3 lines

It sounds good to me to introduce a new revision and a new value to support "icmpv6-type any". But can we really break behavior compatibility of "-p ipv6-icmp -m icmpv6" ?

I tend to agree with Phil's interpretation that this is actually unexpected behaviour, so I don't think anyone is doing this intentional. I would expect either a parser error or type any.

parser error is good idea. It's not neccesary for icmpv6 match to support "--icmpv6-type any" because people can get same behavior with only "-p ipv6-icmp".

How about the attached patch ? That also fixes allowing double --icmp-type/--icmpv6-type.

-- Yasuyuki Kozakai

extensions/libip6t_icmp6.c +7 -1
index a29bb38..6940d0e 100644
@@ -164,11 +164,15 @@ parse(int c, char **argv, int invert, un
 
 	switch (c) {
 	case '1':
+		if (*flags == 1)
+			exit_error(PARAMETER_PROBLEM,
+				   "icmpv6 match: only use --icmpv6-type once!");
 		check_inverse(optarg, &invert, &optind, 0);
 		parse_icmpv6(argv[optind-1], &icmpv6info->type, 
 			     icmpv6info->code);
 		if (invert)
 			icmpv6info->invflags |= IP6T_ICMP_INV;
+		*flags = 1;
 		break;
 
 	default:
@@ -247,9 +251,11 @@ static void save(const struct ip6t_ip6 *
 	printf(" ");
 }
 
-/* Final check; we don't care. */
 static void final_check(unsigned int flags)
 {
+	if (!flags)
+		exit_error(PARAMETER_PROBLEM,
+			   "icmpv6 match: You must specify `--icmpv6-type'");
 }
 
 static struct ip6tables_match icmpv6 = {
extensions/libipt_icmp.c +4 -0
index 9d45c8c..8f22d05 100644
@@ -189,11 +189,15 @@ parse(int c, char **argv, int invert, un
 
 	switch (c) {
 	case '1':
+		if (*flags == 1)
+			exit_error(PARAMETER_PROBLEM,
+				   "icmp match: only use --icmp-type once!");
 		check_inverse(optarg, &invert, &optind, 0);
 		parse_icmp(argv[optind-1], &icmpinfo->type, 
 			   icmpinfo->code);
 		if (invert)
 			icmpinfo->invflags |= IPT_ICMP_INV;
+		*flags = 1;
 		break;
 
 	default:
#7 lore raw
In reply to a message not in the archive
Quoted 11 lines · Yasuyuki KOZAKAI

From: Patrick McHardy <[email protected]>
Date: Tue, 04 Jul 2006 02:46:41 +0200

Quoted 3 lines

I tend to agree with Phil's interpretation that this is actually unexpected behaviour, so I don't think anyone is doing this intentional. I would expect either a parser error or type any.

parser error is good idea. It's not neccesary for icmpv6 match to support "--icmpv6-type any" because people can get same behavior with only "-p ipv6-icmp".

Agreed. Too bad we already have this hack in the kernel for IPv4.

Quoted 2 lines

How about the attached patch ? That also fixes allowing double --icmp-type/--icmpv6-type.

Looks good to me.