Skip to contentSkip to conversation

big endian patch against netfilter after PPTP NAT patch

PATCH In review Chris Poon 2 participants 2 messages Jan 31, 2003 – Feb 3, 2003 netfilter

lore
Share & tools
lore

Chris Poon

author
#0 lore raw

PATCH 1/1 big endian patch against netfilter after PPTP NAT patch

This is related to the problems I found with expecting related connections on Sparc64 platform. This is really a patch against the PPTP NAT patch, which changed the unions in ip_conntrack_manip_proto and ip_conntrack_tuple from strictly a 16 bit union to a mixed 16/32 bit and 16/32/64 bit union (the later case in ip_conntrack_tuple.dst.u). The patch will only apply to ip_conntrack_tuple.h after the PPTP patch is installed, and I did the diff right on the file.

Issue stem from the assumption of little endian platform when the PPTP patch changed the unions, and compiler padding basically screw up the actual location of various fields. I have added the #ifdef around the dummy fields so it should be usable by every platform, and my tests show that expectations for related connections will now be found so I am one happy man.... other than the long kernel compile on my Ultra 10 (using an RedHat like kernel RPM build - PLD for those who are interested), it wasn't too hard to track down the problem, and now I wonder how many people are using big-endian machines to run iptables, let alone a sparc64.

Enjoy

include/linux/netfilter_ipv4/ip_conntrack_tuple.h +21 -0
@@ -17,12 +17,21 @@
 	u_int32_t all;
 
 	struct {
+#if defined(__BIG_ENDIAN)
+		u_int16_t dummy;
+#endif
 		u_int16_t port;
 	} tcp;
 	struct {
+#if defined(__BIG_ENDIAN)
+		u_int16_t dummy;
+#endif
 		u_int16_t port;
 	} udp;
 	struct {
+#if defined(__BIG_ENDIAN)
+		u_int16_t dummy;
+#endif
 		u_int16_t id;
 	} icmp;
 	struct {
@@ -50,12 +59,24 @@
 			u_int64_t all;
 
 			struct {
+#if defined(__BIG_ENDIAN)
+				u_int32_t dummy32;
+				u_int16_t dummy16;
+#endif
 				u_int16_t port;
 			} tcp;
 			struct {
+#if defined(__BIG_ENDIAN)
+				u_int32_t dummy32;
+				u_int16_t dummy16;
+#endif
 				u_int16_t port;
 			} udp;
 			struct {
+#if defined(__BIG_ENDIAN)
+				u_int32_t dummy32;
+				u_int16_t dummy16;
+#endif
 				u_int8_t type, code;
 			} icmp;
 			struct {
#1 lore raw
Quoted 7 lines · Chris Poon

This is related to the problems I found with expecting related connections on Sparc64 platform. This is really a patch against the PPTP NAT patch, which changed the unions in ip_conntrack_manip_proto and ip_conntrack_tuple from strictly a 16 bit union to a mixed 16/32 bit and 16/32/64 bit union (the later case in ip_conntrack_tuple.dst.u). The patch will only apply to ip_conntrack_tuple.h after the PPTP patch is installed, and I did the diff right on the file.

first of all, this was a known issue but I didn't yet have the time to fix it.

Quoted 9 lines

Issue stem from the assumption of little endian platform when the PPTP patch changed the unions, and compiler padding basically screw up the actual location of various fields. I have added the #ifdef around the dummy fields so it should be usable by every platform, and my tests show that expectations for related connections will now be found so I am one happy man.... other than the long kernel compile on my Ultra 10 (using an RedHat like kernel RPM build - PLD for those who are interested), it wasn't too hard to track down the problem, and now I wonder how many people are using big-endian machines to run iptables, let alone a sparc64.

I don't like this patch because:

1) there are non-64bit big endian machines, that don't need the padding
2) we should be able to have those structures and the respective functions working in a portable way, with no #ifdef's all over the place. Why is this so difficult? If all empty (padding) space is initialized to zero, and the fields addressed only by the member names, the mask compare should still work. Or am I missing something?

I have now added this whole issue to the bugtracking system, see
https://bugzilla.netfilter.org/cgi-bin/bugzilla/show_bug.cgi?id=41

Quoted 1 line

Enjoy

Signature · 4 lines
- Harald Welte / [email protected]               http://www.gnumonks.org/
============================================================================
"If this were a dictatorship, it'd be a heck of a lot easier, just so long
 as I'm the dictator."  --  George W. Bush Dec 18, 2000