Skip to contentSkip to conversation

u32 extension

DISCUSSION Applied Jan Engelhardt 2 participants 5 messages Sep 10, 2007 – Sep 19, 2007 1 message not in the archive netfilter

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 5 lines · Patrick McHardy

Hi Jan,

I just noticed the u32 extension is missing from iptables. Could you send me your latest version please.

Adds u32 to iptables.

---

symlink extensions/libip6t_u32.man -> extensions/libipt_u32.man

 extensions/Makefile              |    2 
 extensions/libipt_u32.man        |  129 ++++++++++++++++
 extensions/libxt_u32.c           |  307 +++++++++++++++++++++++++++++++++++++++
 include/linux/netfilter/xt_u32.h |   40 +++++
 4 files changed, 477 insertions(+), 1 deletion(-)
extensions/Makefile +1 -1
Index: iptables/extensions/Makefile
===================================================================
@@ -7,7 +7,7 @@
 #
 PF_EXT_SLIB:=ah addrtype conntrack ecn icmp iprange owner policy realm recent tos ttl unclean CLUSTERIP DNAT ECN LOG MASQUERADE MIRROR NETMAP REDIRECT REJECT SAME SNAT TOS TTL ULOG
 PF6_EXT_SLIB:=ah dst eui64 frag hbh hl icmp6 ipv6header mh owner policy rt HL LOG REJECT
-PFX_EXT_SLIB:=connbytes connmark connlimit comment dccp dscp esp hashlimit helper length limit mac mark multiport physdev pkttype quota sctp state statistic standard string tcp tcpmss udp CLASSIFY CONNMARK DSCP MARK NFLOG NFQUEUE NOTRACK TCPMSS TRACE
+PFX_EXT_SLIB:=connbytes connmark connlimit comment dccp dscp esp hashlimit helper length limit mac mark multiport physdev pkttype quota sctp state statistic standard string tcp tcpmss u32 udp CLASSIFY CONNMARK DSCP MARK NFLOG NFQUEUE NOTRACK TCPMSS TRACE
 
 PF_EXT_SELINUX_SLIB:=
 PF6_EXT_SELINUX_SLIB:=
extensions/libipt_u32.man new file +129 -0

129 lines not on this page · raw message

extensions/libxt_u32.c new file +307 -0

307 lines not on this page · raw message

include/linux/netfilter/xt_u32.h new file +40 -0
Index: iptables/include/linux/netfilter/xt_u32.h
===================================================================
@@ -0,0 +1,40 @@
+#ifndef _XT_U32_H
+#define _XT_U32_H 1
+
+enum xt_u32_ops {
+	XT_U32_AND,
+	XT_U32_LEFTSH,
+	XT_U32_RIGHTSH,
+	XT_U32_AT,
+};
+
+struct xt_u32_location_element {
+	u_int32_t number;
+	u_int8_t nextop;
+};
+
+struct xt_u32_value_element {
+	u_int32_t min;
+	u_int32_t max;
+};
+
+/*
+ * Any way to allow for an arbitrary number of elements?
+ * For now, I settle with a limit of 10 each.
+ */
+#define XT_U32_MAXSIZE 10
+
+struct xt_u32_test {
+	struct xt_u32_location_element location[XT_U32_MAXSIZE+1];
+	struct xt_u32_value_element value[XT_U32_MAXSIZE+1];
+	u_int8_t nnums;
+	u_int8_t nvalues;
+};
+
+struct xt_u32 {
+	struct xt_u32_test tests[XT_U32_MAXSIZE+1];
+	u_int8_t ntests;
+	u_int8_t invert;
+};
+
+#endif /* _XT_U32_H */
#2 lore raw
Quoted 11 lines · Jan Engelhardt
Quoted 5 lines · Patrick McHardy

Hi Jan,

I just noticed the u32 extension is missing from iptables. Could you send me your latest version please.

Adds u32 to iptables.

Applied, thanks Jan.

Quoted 1 line

symlink extensions/libip6t_u32.man -> extensions/libipt_u32.man

I copied it and fixed a bunch of warnings on 64 bit:

extensions/libxt_u32.c: In function 'u32_parse':
extensions/libxt_u32.c:146: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:160: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:173: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:178: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:184: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:193: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:204: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:207: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:214: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:224: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int' extensions/libxt_u32.c:244: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int'

#3 lore raw
Quoted 10 lines · Patrick McHardy
Quoted 6 lines · Jan Engelhardt
Quoted 3 lines · Patrick McHardy

I just noticed the u32 extension is missing from iptables. Could you send me your latest version please.

Adds u32 to iptables.

Applied, thanks Jan.

Quoted 7 lines
Quoted 1 line

symlink extensions/libip6t_u32.man -> extensions/libipt_u32.man

I copied it and fixed a bunch of warnings on 64 bit:

extensions/libxt_u32.c: In function 'u32_parse':
extensions/libxt_u32.c:146: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int'

argument 3 is actually of type ptrdiff_t, but whatever :) Yeah should be %lu.

Jan

#4 lore raw
Quoted 13 lines · Jan Engelhardt
Quoted 12 lines · Patrick McHardy
Quoted 6 lines · Jan Engelhardt
Quoted 3 lines · Patrick McHardy

I just noticed the u32 extension is missing from iptables. Could you send me your latest version please.

Adds u32 to iptables.

Applied, thanks Jan.

Quoted 1 line

symlink extensions/libip6t_u32.man -> extensions/libipt_u32.man

Quoted 8 lines
Quoted 5 lines

I copied it and fixed a bunch of warnings on 64 bit:

extensions/libxt_u32.c: In function 'u32_parse':
extensions/libxt_u32.c:146: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long int'

argument 3 is actually of type ptrdiff_t, but whatever :) Yeah should be %lu.

Ha, not! On i586 (iptables-svn7047) I now get:

warning: format '%ld' expects type 'long int', but argument 3 has type 'int'.

Oh well, oh well. Patch below.
===

With %u alone, you would get "but arg-start is long" warnings on x64. With %lu, you would get "but arg-start is int" on x86.
Fix it up by explicitly deciding for one (%u and cast to unsigned int) and using that.

---
 extensions/libxt_u32.c |   26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
extensions/libxt_u32.c +13 -13
Index: iptables/extensions/libxt_u32.c
===================================================================
@@ -142,8 +142,8 @@ static int u32_parse(int c, char **argv,
 
 			if (testind > XT_U32_MAXSIZE)
 				exit_error(PARAMETER_PROBLEM,
-				           "u32: at char %ld: too many \"&&\"s",
-				           arg - start);
+				           "u32: at char %u: too many \"&&\"s",
+				           (unsigned int)(arg - start));
 			return 1;
 		}
 
@@ -155,9 +155,9 @@ static int u32_parse(int c, char **argv,
 			if (*arg == '=') {
 				if (locind == 0) {
 					exit_error(PARAMETER_PROBLEM,
-					           "u32: at char %ld: "
+					           "u32: at char %u: "
 					           "location spec missing",
-					           arg - start);
+					           (unsigned int)(arg - start));
 				} else {
 					++arg;
 					state = 1;
@@ -170,18 +170,18 @@ static int u32_parse(int c, char **argv,
 					} else if (*arg == '<') {
 						if (*++arg != '<')
 							exit_error(PARAMETER_PROBLEM,
-								   "u32: at char %ld: a second < expected", arg - start);
+								   "u32: at char %u: a second '<' was expected", (unsigned int)(arg - start));
 						ct->location[locind].nextop = XT_U32_LEFTSH;
 					} else if (*arg == '>') {
 						if (*++arg != '>')
 							exit_error(PARAMETER_PROBLEM,
-								   "u32: at char %ld: a second > expected", arg - start);
+								   "u32: at char %u: a second '>' was expected", (unsigned int)(arg - start));
 						ct->location[locind].nextop = XT_U32_RIGHTSH;
 					} else if (*arg == '@') {
 						ct->location[locind].nextop = XT_U32_AT;
 					} else {
 						exit_error(PARAMETER_PROBLEM,
-							"u32: at char %ld: operator expected", arg - start);
+							"u32: at char %u: operator expected", (unsigned int)(arg - start));
 					}
 					++arg;
 				}
@@ -190,7 +190,7 @@ static int u32_parse(int c, char **argv,
 					parse_number(&arg, arg - start);
 				if (++locind > XT_U32_MAXSIZE)
 					exit_error(PARAMETER_PROBLEM,
-						   "u32: at char %ld: too many operators", arg - start);
+						   "u32: at char %u: too many operators", (unsigned int)(arg - start));
 			}
 		} else {
 			/*
@@ -201,17 +201,17 @@ static int u32_parse(int c, char **argv,
 			if (*arg == '&') {
 				if (*++arg != '&')
 					exit_error(PARAMETER_PROBLEM,
-						   "u32: at char %ld: a second & was expected", arg - start);
+						   "u32: at char %u: a second '&' was expected", (unsigned int)(arg - start));
 				if (valind == 0) {
 					exit_error(PARAMETER_PROBLEM,
-						   "u32: at char %ld: value spec missing", arg - start);
+						   "u32: at char %u: value spec missing", (unsigned int)(arg - start));
 				} else {
 					ct->nnums   = locind;
 					ct->nvalues = valind;
 					ct = &data->tests[++testind];
 					if (testind > XT_U32_MAXSIZE)
 						exit_error(PARAMETER_PROBLEM,
-							   "u32: at char %ld: too many \"&&\"s", arg - start);
+							   "u32: at char %u: too many \"&&\"s", (unsigned int)(arg - start));
 					++arg;
 					state  = 0;
 					locind = 0;
@@ -221,7 +221,7 @@ static int u32_parse(int c, char **argv,
 				if (valind > 0) { /* need , before number */
 					if (*arg != ',')
 						exit_error(PARAMETER_PROBLEM,
-							   "u32: at char %ld: expected , or &&", arg - start);
+							   "u32: at char %u: expected \",\" or \"&&\"", (unsigned int)(arg - start));
 					++arg;
 				}
 				ct->value[valind].min =
@@ -241,7 +241,7 @@ static int u32_parse(int c, char **argv,
 
 				if (++valind > XT_U32_MAXSIZE)
 					exit_error(PARAMETER_PROBLEM,
-						   "u32: at char %ld: too many \",\"s", arg - start);
+						   "u32: at char %u: too many \",\"s", (unsigned int)(arg - start));
 			}
 		}
 	}
#5 lore raw
Quoted 10 lines · Jan Engelhardt

warning: format '%ld' expects type 'long int', but argument 3 has type 'int'.

Oh well, oh well. Patch below.
===

With %u alone, you would get "but arg-start is long" warnings on x64. With %lu, you would get "but arg-start is int" on x86.
Fix it up by explicitly deciding for one (%u and cast to unsigned int) and using that.

Applied, thanks Jan.