[PATCH IP6TABLES]: don't allow to specify protocol of IPv6 extension header

Yasuyuki KOZAKAI yasuyuki.kozakai at toshiba.co.jp
Wed Mar 29 08:59:12 CEST 2006


Hi,

Sometimes I hear that people do 'ip6tables -p ah ...' which never matches
any packet. IPv6 extension headers except of ESP are skipped and invalid
as argument of '-p'. Then I propose that ip6tables exits with error in such
case.

-- Yasuyuki Kozakai
-------------- next part --------------
[PATCH] don't allow to specify protocol of IPv6 extension header

---
commit 9bbbc3c90face808eb05da8aae69c9e6f7b508b3
tree 5506d3520a60553607f074ed21969ca0c2fbb8aa
parent 5a2223d5d7d2d81ab036effd7460a9dea45d247e
author Yasuyuki Kozakai <yasuyuki.kozakai at toshiba.co.jp> Wed, 29 Mar 2006 12:50:32 +0900
committer Yasuyuki Kozakai <yasuyuki.kozakai at toshiba.co.jp> Wed, 29 Mar 2006 12:50:32 +0900

 ip6tables.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/ip6tables.c b/ip6tables.c
index dcf7d36..a6471ee 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -849,6 +849,17 @@ parse_protocol(const char *s)
 	return (u_int16_t)proto;
 }
 
+/* proto means upper-layer protocol or ESP ? */
+static int is_exthdr(u_int16_t proto)
+{
+	return (proto == IPPROTO_HOPOPTS ||
+		proto == IPPROTO_ROUTING ||
+		proto == IPPROTO_FRAGMENT ||
+		proto == IPPROTO_ESP ||
+		proto == IPPROTO_AH ||
+		proto == IPPROTO_DSTOPTS);
+}
+
 void parse_interface(const char *arg, char *vianame, unsigned char *mask)
 {
 	int vialen = strlen(arg);
@@ -1926,6 +1937,13 @@ int do_command6(int argc, char *argv[], 
 			    && (fw.ipv6.invflags & IP6T_INV_PROTO))
 				exit_error(PARAMETER_PROBLEM,
 					   "rule would never match protocol");
+			
+			if (fw.ipv6.proto != IPPROTO_ESP &&
+			    is_exthdr(fw.ipv6.proto))
+				exit_error(PARAMETER_PROBLEM,
+					   "invalid protocol: %s. "
+					   "use exension match instead.",
+					   protocol);
 			break;
 
 		case 's':


More information about the netfilter-devel mailing list