summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2014-01-08 13:02:15 +0000
committerPatrick McHardy <kaber@trash.net>2014-01-08 13:02:15 +0000
commitdccc746af16bdc3e85610e067eebc951b75b73f1 (patch)
tree2bfd3b0180667989d00c79955d1883889db8f27f
parent77ef4d83c8d030b183ff763605b2c3026545fc9c (diff)
proto: add helper function to update protocol context
Add a helper function which is to be used to update the protocol update. Signed-off-by: Patrick McHardy <ksber@trash.net<
-rw-r--r--include/proto.h3
-rw-r--r--src/meta.c3
-rw-r--r--src/payload.c3
-rw-r--r--src/proto.c16
4 files changed, 21 insertions, 4 deletions
diff --git a/include/proto.h b/include/proto.h
index 037ef09e..de58d4cc 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -122,6 +122,9 @@ struct proto_ctx {
};
extern void proto_ctx_init(struct proto_ctx *ctx, unsigned int family);
+extern void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base,
+ const struct location *loc,
+ const struct proto_desc *desc);
extern const struct proto_desc *proto_find_upper(const struct proto_desc *base,
unsigned int num);
extern int proto_find_num(const struct proto_desc *base,
diff --git a/src/meta.c b/src/meta.c
index 9173c306..e0ae9502 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -367,8 +367,7 @@ static void meta_expr_pctx_update(struct proto_ctx *ctx,
if (desc == NULL)
desc = &proto_unknown;
- ctx->protocol[PROTO_BASE_LL_HDR].location = expr->location;
- ctx->protocol[PROTO_BASE_LL_HDR].desc = desc;
+ proto_ctx_update(ctx, PROTO_BASE_LL_HDR, &expr->location, desc);
}
static const struct expr_ops meta_expr_ops = {
diff --git a/src/payload.c b/src/payload.c
index 426adc31..0ef3c791 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -69,8 +69,7 @@ static void payload_expr_pctx_update(struct proto_ctx *ctx,
base = ctx->protocol[left->payload.base].desc;
desc = proto_find_upper(base, mpz_get_uint32(right->value));
- ctx->protocol[left->payload.base + 1].location = expr->location;
- ctx->protocol[left->payload.base + 1].desc = desc;
+ proto_ctx_update(ctx, left->payload.base + 1, &expr->location, desc);
}
static const struct expr_ops payload_expr_ops = {
diff --git a/src/proto.c b/src/proto.c
index c6428e4c..f611c97b 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -143,6 +143,22 @@ void proto_ctx_init(struct proto_ctx *ctx, unsigned int family)
ctx->protocol[h->base].desc = h->desc;
}
+/**
+ * proto_ctx_update: update protocol context for given protocol base
+ *
+ * @ctx: protocol context
+ * @base: protocol base
+ * @loc: location of the relational expression definiting the context
+ * @desc: protocol description for the given layer
+ */
+void proto_ctx_update(struct proto_ctx *ctx, enum proto_bases base,
+ const struct location *loc,
+ const struct proto_desc *desc)
+{
+ ctx->protocol[base].location = *loc;
+ ctx->protocol[base].desc = desc;
+}
+
#define HDR_TEMPLATE(__name, __dtype, __type, __member) \
PROTO_HDR_TEMPLATE(__name, __dtype, \
offsetof(__type, __member) * 8, \