From d4e06f5bb9511c6a3a00191f74a99ba0c58093a6 Mon Sep 17 00:00:00 2001 From: Alvaro Neira Ayuso Date: Wed, 17 Sep 2014 09:20:28 +0200 Subject: src: add specific byteorder to the struct proto_hdr_template If we try to add a rule like: nft add rule filter input udp length {55-9999} nftable shows: BUG: invalid byte order conversion 0 => 2 nft: src/evaluate.c:153: byteorder_conversion_op: Assertion `0' failed. Some of the existing payload fields rely on BYTEORDER_INVALID. Therefore, if we try to convert it in evaluation step, we hit this bug. This patch allows to add a specific byteorder to the struct proto_hdr_template. If we create a expression with a invalid byteorder, we will use the byteorder added to the proto_hdr_template structure. Signed-off-by: Alvaro Neira Ayuso Signed-off-by: Patrick McHardy --- src/proto.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/proto.c') diff --git a/src/proto.c b/src/proto.c index 15a456a7..6eb4bb24 100644 --- a/src/proto.c +++ b/src/proto.c @@ -38,7 +38,7 @@ const char *proto_base_tokens[] = { }; const struct proto_hdr_template proto_unknown_template = - PROTO_HDR_TEMPLATE("unknown", &invalid_type, 0, 0); + PROTO_HDR_TEMPLATE("unknown", &invalid_type, BYTEORDER_INVALID, 0, 0); const struct proto_desc proto_unknown = { .name = "unknown", @@ -186,13 +186,15 @@ void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base, #define HDR_TEMPLATE(__name, __dtype, __type, __member) \ PROTO_HDR_TEMPLATE(__name, __dtype, \ + BYTEORDER_BIG_ENDIAN, \ offsetof(__type, __member) * 8, \ field_sizeof(__type, __member) * 8) #define HDR_FIELD(__name, __struct, __member) \ HDR_TEMPLATE(__name, &integer_type, __struct, __member) #define HDR_BITFIELD(__name, __dtype, __offset, __len) \ - PROTO_HDR_TEMPLATE(__name, __dtype, __offset, __len) + PROTO_HDR_TEMPLATE(__name, __dtype, BYTEORDER_BIG_ENDIAN, \ + __offset, __len) #define HDR_TYPE(__name, __dtype, __struct, __member) \ HDR_TEMPLATE(__name, __dtype, __struct, __member) @@ -785,7 +787,10 @@ const struct datatype ethertype_type = { #define ETHHDR_TYPE(__name, __member) \ ETHHDR_TEMPLATE(__name, ðertype_type, __member) #define ETHHDR_ADDR(__name, __member) \ - ETHHDR_TEMPLATE(__name, ðeraddr_type, __member) + PROTO_HDR_TEMPLATE(__name, ðeraddr_type, \ + BYTEORDER_HOST_ENDIAN, \ + offsetof(struct ether_header, __member) * 8, \ + field_sizeof(struct ether_header, __member) * 8) const struct proto_desc proto_eth = { .name = "ether", -- cgit v1.2.3