summaryrefslogtreecommitdiffstats
path: root/src/payload.c
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2014-08-19 00:21:59 +0100
committerPatrick McHardy <kaber@trash.net>2014-08-19 00:21:59 +0100
commit69ade79302b9bc7d88fa58db9d30555e54ef7887 (patch)
treed6da7ef1b11e5330778dd1894342cb97f9db52f4 /src/payload.c
parent6ef2c71e9772a8bd1be7ddf376e1be26c3334110 (diff)
payload: take endianess into account when updating the payload context
payload_expr_pctx_update() uses the numeric protocol value in host byte order to find the upper layer protocol. This obviously doesn't work for protocol expressions in other byte orders, such as the ethernet protocol on little endian. Export the protocol value in the correct byte order and use that value to look up the upper layer protocol. Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src/payload.c')
-rw-r--r--src/payload.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/payload.c b/src/payload.c
index a1785a59..47861ed2 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -69,13 +69,20 @@ static void payload_expr_pctx_update(struct proto_ctx *ctx,
{
const struct expr *left = expr->left, *right = expr->right;
const struct proto_desc *base, *desc;
+ unsigned int proto = 0;
if (!(left->flags & EXPR_F_PROTOCOL))
return;
assert(expr->op == OP_EQ);
+
+ /* Export the data in the correct byte order */
+ assert(right->len / BITS_PER_BYTE <= sizeof(proto));
+ mpz_export_data(&proto, right->value, right->byteorder,
+ right->len / BITS_PER_BYTE);
+
base = ctx->protocol[left->payload.base].desc;
- desc = proto_find_upper(base, mpz_get_uint32(right->value));
+ desc = proto_find_upper(base, proto);
proto_ctx_update(ctx, left->payload.base + 1, &expr->location, desc);
}