Skip to contentSkip to conversation

libxt_length: update to revision 1

PATCH Superseded Changli Gao 3 participants 8 messages Jul 24, 2010 – Jul 26, 2010 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxt_length: update to revision 1

update libxt_length to revision 1 to support ipv6 jumbo frames.

----

 extensions/libxt_length.c           |    1 +
 include/linux/netfilter/xt_length.h |    2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
extensions/libxt_length.c +1 -0
index 96e8b6c..5d0f5e9 100644
@@ -125,6 +125,7 @@ static struct xtables_match length_match = {
 	.print		= length_print,
 	.save		= length_save,
 	.extra_opts	= length_opts,
+	.revision	= 1,
 };
 
 void _init(void)
include/linux/netfilter/xt_length.h +1 -1
index b82ed7c..a12785c 100644
@@ -4,7 +4,7 @@
 #include <linux/types.h>
 
 struct xt_length_info {
-    __u16	min, max;
+    __u32	min, max;
     __u8	invert;
 };
 
#1 lore raw
Quoted 12 lines · Changli Gao

update libxt_length to revision 1 to support ipv6 jumbo frames.

----

 extensions/libxt_length.c           |    1 +
 include/linux/netfilter/xt_length.h |    2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
extensions/libxt_length.c +0 -0
index 96e8b6c..5d0f5e9 100644

extensions/libxt_length.c static struct xtables_match length_match = { · line 131

Quoted 7 lines
extensions/libxt_length.c +1 -0
@@ -125,6 +125,7 @@ static struct xtables_match length_match = {
 	.print		= length_print,
 	.save		= length_save,
 	.extra_opts	= length_opts,
+	.revision	= 1,
 };
 
 void _init(void)

Hmm... I think you missed at line 50 :

        info->max = cp[0] ? parse_length(cp) : 0xFFFF;

Or document the thing...

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 19 lines · Eric Dumazet
Quoted 18 lines · Changli Gao

update libxt_length to revision 1 to support ipv6 jumbo frames.

----
 extensions/libxt_length.c           |    1 +
 include/linux/netfilter/xt_length.h |    2 +-

 2 files changed, 2 insertions(+), 1 deletion(-)
extensions/libxt_length.c +1 -0
index 96e8b6c..5d0f5e9 100644
@@ -125,6 +125,7 @@ static struct xtables_match length_match = {
       .print          = length_print,
       .save           = length_save,
       .extra_opts     = length_opts,
+     .revision       = 1,
  };
 
Quoted 9 lines

extensions/libxt_length.c static struct xtables_match length_match = { · line 131

Quoted 1 line
extensions/libxt_length.c +0 -0
  void _init(void)

Hmm... I think you missed at line 50 :

       info->max = cp[0] ? parse_length(cp) : 0xFFFF;

Or document the thing...

Oh, thanks. I think we can change 0xFFFF to 0xFFFFFFFF, and I also need to update the return value of parse_length() to u_int32_t.

Signature · 6 lines
Regards,
Changli Gao([email protected])
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to Changli Gao
Quoted 1 line · Changli Gao

update libxt_length to revision 1 to support ipv6 jumbo frames.

You can't just go and change these things, would break xt_length v0.

Quoted 35 lines

----

extensions/libxt_length.c           |    1 +
include/linux/netfilter/xt_length.h |    2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
extensions/libxt_length.c +1 -0
index 96e8b6c..5d0f5e9 100644
@@ -125,6 +125,7 @@ static struct xtables_match length_match = {
 	.print		= length_print,
 	.save		= length_save,
 	.extra_opts	= length_opts,
+	.revision	= 1,
 };
 
 void _init(void)
include/linux/netfilter/xt_length.h +1 -2
index b82ed7c..a12785c 100644
@@ -4,7 +4,7 @@
 #include <linux/types.h>
 
 struct xt_length_info {
-    __u16	min, max;
+    __u32	min, max;
    __u8	invert;
 };
 
--

To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 6 lines · Jan Engelhardt
Quoted 1 line · Changli Gao

update libxt_length to revision 1 to support ipv6 jumbo frames.

You can't just go and change these things, would break xt_length v0.

Hmm. I have updated the patch(attached), but the v0 handlers are not called. Is there anything I missed? Or Is there a bug in iptables?

Signature · 2 lines
Regards,
Changli Gao([email protected])
extensions/libxt_length.c +100 -29
index 96e8b6c..774a80e 100644
@@ -8,6 +8,11 @@
 #include <xtables.h>
 #include <linux/netfilter/xt_length.h>
 
+struct xt_length_info_v0 {
+    __u32	min, max;
+    __u8	invert;
+};
+
 static void length_help(void)
 {
 	printf(
@@ -21,8 +26,7 @@ static const struct option length_opts[] = {
 	{ .name = NULL }
 };
 
-static u_int16_t
-parse_length(const char *s)
+static u_int32_t parse_length(const char *s)
 {
 	unsigned int len;
 	
@@ -33,8 +37,7 @@ parse_length(const char *s)
 }
 
 /* If a single value is provided, min and max are both set to the value */
-static void
-parse_lengths(const char *s, struct xt_length_info *info)
+static void parse_lengths(const char *s, struct xt_length_info *info)
 {
 	char *buffer;
 	char *cp;
@@ -47,7 +50,7 @@ parse_lengths(const char *s, struct xt_length_info *info)
 		cp++;
 
 		info->min = buffer[0] ? parse_length(buffer) : 0;
-		info->max = cp[0] ? parse_length(cp) : 0xFFFF;
+		info->max = cp[0] ? parse_length(cp) : 0xFFFFFFFF;
 	}
 	free(buffer);
 	
@@ -58,12 +61,9 @@ parse_lengths(const char *s, struct xt_length_info *info)
 	
 }
 
-static int
-length_parse(int c, char **argv, int invert, unsigned int *flags,
-             const void *entry, struct xt_entry_match **match)
+static int __length_parse(int c, char **argv, int invert, unsigned int *flags,
+			  const void *entry, struct xt_length_info *info)
 {
-	struct xt_length_info *info = (struct xt_length_info *)(*match)->data;
-
 	switch (c) {
 		case '1':
 			if (*flags)
@@ -83,6 +83,31 @@ length_parse(int c, char **argv, int invert, unsigned int *flags,
 	return 1;
 }
 
+static int length_parse(int c, char **argv, int invert, unsigned int *flags,
+			const void *entry, struct xt_entry_match **match)
+{
+	return __length_parse(c, argv, invert, flags, entry,
+			      (struct xt_length_info *)(*match)->data);
+}
+
+static int length_parse_v0(int c, char **argv, int invert, unsigned int *flags,
+			   const void *entry, struct xt_entry_match **match)
+{
+	struct xt_length_info info;
+
+	if (__length_parse(c, argv, invert, flags, entry, &info)) {
+		struct xt_length_info_v0 *info_v0;
+
+		info_v0 = (void *)(*match)->data;
+		info_v0->min = info.min;
+		info_v0->max = info.max;
+		info_v0->invert = info.invert;
+		return 1;
+	}
+
+	return 0;
+}
+
 static void length_check(unsigned int flags)
 {
 	if (!flags)
@@ -90,11 +115,8 @@ static void length_check(unsigned int flags)
 			   "length: You must specify `--length'");
 }
 
-static void
-length_print(const void *ip, const struct xt_entry_match *match, int numeric)
+static void __length_print(const struct xt_length_info *info)
 {
-	const struct xt_length_info *info = (void *)match->data;
-
 	printf("length %s", info->invert ? "!" : "");
 	if (info->min == info->max)
 		printf("%u ", info->min);
@@ -102,10 +124,26 @@ length_print(const void *ip, const struct xt_entry_match *match, int numeric)
 		printf("%u:%u ", info->min, info->max);
 }
 
-static void length_save(const void *ip, const struct xt_entry_match *match)
+static void length_print(const void *ip, const struct xt_entry_match *match,
+			 int numeric)
 {
-	const struct xt_length_info *info = (void *)match->data;
+	__length_print((void *)match->data);
+}
+
+static void length_print_v0(const void *ip, const struct xt_entry_match *match,
+			    int numeric)
+{
+	const struct xt_length_info_v0 *info_v0 = (void *)match->data;
+	struct xt_length_info info;
 
+	info.min = info_v0->min;
+	info.max = info_v0->max;
+	info.invert = info_v0->invert;
+	__length_print(&info);
+}
+
+static void __length_save(const struct xt_length_info *info)
+{
 	printf("%s--length ", info->invert ? "! " : "");
 	if (info->min == info->max)
 		printf("%u ", info->min);
@@ -113,21 +151,54 @@ static void length_save(const void *ip, const struct xt_entry_match *match)
 		printf("%u:%u ", info->min, info->max);
 }
 
-static struct xtables_match length_match = {
-	.family		= NFPROTO_UNSPEC,
-	.name		= "length",
-	.version	= XTABLES_VERSION,
-	.size		= XT_ALIGN(sizeof(struct xt_length_info)),
-	.userspacesize	= XT_ALIGN(sizeof(struct xt_length_info)),
-	.help		= length_help,
-	.parse		= length_parse,
-	.final_check	= length_check,
-	.print		= length_print,
-	.save		= length_save,
-	.extra_opts	= length_opts,
+static void length_save(const void *ip, const struct xt_entry_match *match)
+{
+	__length_save((void *)match->data);
+}
+
+static void length_save_v0(const void *ip, const struct xt_entry_match *match)
+{
+	const struct xt_length_info_v0 *info_v0 = (void *)match->data;
+	struct xt_length_info info;
+
+	info.min = info_v0->min;
+	info.max = info_v0->max;
+	info.invert = info_v0->invert;
+	__length_save(&info);
+}
+
+static struct xtables_match length_mt_reg[] = {
+	{
+		.family		= NFPROTO_UNSPEC,
+		.name		= "length",
+		.version	= XTABLES_VERSION,
+		.size		= XT_ALIGN(sizeof(struct xt_length_info_v0)),
+		.userspacesize	= XT_ALIGN(sizeof(struct xt_length_info_v0)),
+		.help		= length_help,
+		.parse		= length_parse_v0,
+		.final_check	= length_check,
+		.print		= length_print_v0,
+		.save		= length_save_v0,
+		.extra_opts	= length_opts,
+		.revision	= 0,
+	},
+	{
+		.family		= NFPROTO_UNSPEC,
+		.name		= "length",
+		.version	= XTABLES_VERSION,
+		.size		= XT_ALIGN(sizeof(struct xt_length_info)),
+		.userspacesize	= XT_ALIGN(sizeof(struct xt_length_info)),
+		.help		= length_help,
+		.parse		= length_parse,
+		.final_check	= length_check,
+		.print		= length_print,
+		.save		= length_save,
+		.extra_opts	= length_opts,
+		.revision	= 1,
+	},
 };
 
 void _init(void)
 {
-	xtables_register_match(&length_match);
+	xtables_register_matches(length_mt_reg, ARRAY_SIZE(length_mt_reg));
 }
include/linux/netfilter/xt_length.h +1 -1
index b82ed7c..a12785c 100644
@@ -4,7 +4,7 @@
 #include <linux/types.h>
 
 struct xt_length_info {
-    __u16	min, max;
+    __u32	min, max;
     __u8	invert;
 };
 
#5 lore raw
Quoted 10 lines · Changli Gao
Quoted 6 lines · Jan Engelhardt
Quoted 1 line · Changli Gao

update libxt_length to revision 1 to support ipv6 jumbo frames.

You can't just go and change these things, would break xt_length v0.

Hmm. I have updated the patch(attached), but the v0 handlers are not called. Is there anything I missed? Or Is there a bug in iptables?

Probably because you are still breaking the compatibility by editing struct xt_length_info. I'd say let's concentrate on rev 2 that I submitted.

#6 lore raw
Quoted 7 lines · Jan Engelhardt
Quoted 5 lines · Changli Gao
Quoted 4 lines · Jan Engelhardt
Quoted 1 line · Changli Gao

update libxt_length to revision 1 to support ipv6 jumbo frames.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

You can't just go and change these things, would break xt_length v0.

Hmm. I have updated the patch(attached), but the v0 handlers are not called. Is there anything I missed? Or Is there a bug in iptables?

Probably because you are still breaking the compatibility by editing struct xt_length_info.

I am sure it isn't the problem. The kernel module can work with the old iptables binary. However after I committed the rules with the revision 1, I can't get the correct output with the command 'iptables-save' or 'iptables -nvL'. I checked the code of iptables, and found it doesn't check the revision when founding matches and targets, and even the kernel seems doesn't transfer the revision info to user space.

Quoted 3 lines

I'd say let's concentrate on rev 2 that I
submitted.

I have seen it. Thanks.

Signature · 2 lines
Regards,
Changli Gao([email protected])
#7 lore raw
Quoted 14 lines · Changli Gao
Quoted 13 lines · Jan Engelhardt
Quoted 10 lines · Changli Gao
Quoted 6 lines · Jan Engelhardt
Quoted 1 line · Changli Gao

update libxt_length to revision 1 to support ipv6 jumbo frames.

You can't just go and change these things, would break xt_length v0.

Hmm. I have updated the patch(attached), but the v0 handlers are not called. Is there anything I missed? Or Is there a bug in iptables?

Quoted 7 lines
Quoted 2 lines

Probably because you are still breaking the compatibility by editing struct xt_length_info.

I am sure it isn't the problem. The kernel module can work with the old iptables binary. However after I committed the rules with the revision 1, I can't get the correct output with the command 'iptables-save' or 'iptables -nvL'.

Sorry. I made a mistake. I committed the rules(revision 0) with the old iptables, but I could not get the correct output with the new iptables or iptables-save.

Quoted 15 lines

I checked the code of iptables,
and found it doesn't check the revision when founding matches and targets, and even the kernel seems doesn't transfer the revision info to user space.

Quoted 3 lines

I'd say let's concentrate on rev 2 that I
submitted.

I have seen it. Thanks.

--
Regards,
Changli Gao([email protected])

Signature · 2 lines
Regards,
Changli Gao([email protected])