Skip to contentSkip to conversation

src: proto: fix byteorder for ip headers.

PATCH In review Yuxuan Shui 3 participants 3 messages Jun 4, 2014 – Jun 5, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src: proto: fix byteorder for ip headers.

Add a new datatype for ip headers which specify the byteorder, this fixes bug 918.

---
 src/proto.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/proto.c +9 -1
index 0a37a65..f1556db 100644
@@ -184,13 +184,21 @@ void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base,
 	proto_ctx_debug(ctx, base);
 }
 
+const struct datatype net_integer = {
+	.type = TYPE_INTEGER,
+	.byteorder = BYTEORDER_BIG_ENDIAN,
+	.name = "net_integer",
+	.desc = "network integer",
+	.basetype = &integer_type,
+};
+
 #define HDR_TEMPLATE(__name, __dtype, __type, __member)			\
 	PROTO_HDR_TEMPLATE(__name, __dtype,				\
 			   offsetof(__type, __member) * 8,		\
 			   field_sizeof(__type, __member) * 8)
 
 #define HDR_FIELD(__name, __struct, __member)				\
-	HDR_TEMPLATE(__name, &integer_type, __struct, __member)
+	HDR_TEMPLATE(__name, &net_integer, __struct, __member)
 #define HDR_BITFIELD(__name, __dtype,  __offset, __len)			\
 	PROTO_HDR_TEMPLATE(__name, __dtype, __offset, __len)
 #define HDR_TYPE(__name, __dtype, __struct, __member)			\
Signature · 1 line
2.0.0
#1 lore raw
Quoted 25 lines · Yuxuan Shui

Add a new datatype for ip headers which specify the byteorder, this fixes bug 918.

---
 src/proto.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/proto.c +8 -0
index 0a37a65..f1556db 100644
@@ -184,13 +184,21 @@ void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base,
 	proto_ctx_debug(ctx, base);
 }
 
+const struct datatype net_integer = {
+	.type = TYPE_INTEGER,
+	.byteorder = BYTEORDER_BIG_ENDIAN,
+	.name = "net_integer",
+	.desc = "network integer",
+	.basetype = &integer_type,
+};
+
 #define HDR_TEMPLATE(__name, __dtype, __type, __member)			\

src/proto.c void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base, · line 204

Quoted 10 lines
src/proto.c +1 -1
 	PROTO_HDR_TEMPLATE(__name, __dtype,				\
 			   offsetof(__type, __member) * 8,		\
 			   field_sizeof(__type, __member) * 8)
 
 #define HDR_FIELD(__name, __struct, __member)				\
-	HDR_TEMPLATE(__name, &integer_type, __struct, __member)
+	HDR_TEMPLATE(__name, &net_integer, __struct, __member)
 #define HDR_BITFIELD(__name, __dtype,  __offset, __len)			\
 	PROTO_HDR_TEMPLATE(__name, __dtype, __offset, __len)
 #define HDR_TYPE(__name, __dtype, __struct, __member)			\

While this does make some sense, I would rather change byteorder_conversion_op() to return immediately for expressions of size <= 8. There is obviously no byteorder in this case, so this seems more like working around incorrect behaviour of that function.

#2 lore raw

Hi Patrick,

Quoted 30 lines · Patrick McHardy
Quoted 29 lines · Yuxuan Shui

Add a new datatype for ip headers which specify the byteorder, this fixes bug 918.

---
 src/proto.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
src/proto.c +8 -0
index 0a37a65..f1556db 100644
@@ -184,13 +184,21 @@ void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base,
 	proto_ctx_debug(ctx, base);
 }
 
+const struct datatype net_integer = {
+	.type = TYPE_INTEGER,
+	.byteorder = BYTEORDER_BIG_ENDIAN,
+	.name = "net_integer",
+	.desc = "network integer",
+	.basetype = &integer_type,
+};
+
 #define HDR_TEMPLATE(__name, __dtype, __type, __member)			\
 	PROTO_HDR_TEMPLATE(__name, __dtype,				\
 			   offsetof(__type, __member) * 8,		\
 			   field_sizeof(__type, __member) * 8)
 
Quoted 11 lines

src/proto.c void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base, · line 204

Quoted 6 lines
src/proto.c +1 -1
 #define HDR_FIELD(__name, __struct, __member)				\
-	HDR_TEMPLATE(__name, &integer_type, __struct, __member)
+	HDR_TEMPLATE(__name, &net_integer, __struct, __member)
 #define HDR_BITFIELD(__name, __dtype,  __offset, __len)			\
 	PROTO_HDR_TEMPLATE(__name, __dtype, __offset, __len)
 #define HDR_TYPE(__name, __dtype, __struct, __member)			\

While this does make some sense, I would rather change byteorder_conversion_op() to return immediately for expressions of size <= 8. There is obviously no byteorder in this case, so this seems more like working around incorrect behaviour of that function.

Indeed, that should calm down that assertion.

But I think this patch also addresses another problem that we have. The integer_type_parse function uses hostbyte order type for values in the network header fields. I think this patch also addresses wrong byteorder when the header field is larger than 8 bits.