]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
proto: add helper function to update protocol context
authorPatrick McHardy <kaber@trash.net>
Wed, 8 Jan 2014 13:02:15 +0000 (13:02 +0000)
committerPatrick McHardy <kaber@trash.net>
Wed, 8 Jan 2014 13:02:15 +0000 (13:02 +0000)
Add a helper function which is to be used to update the protocol update.

Signed-off-by: Patrick McHardy <ksber@trash.net<
include/proto.h
src/meta.c
src/payload.c
src/proto.c

index 037ef09e4022b2752c4a6a0bbe94c69ff8896919..de58d4cc2166488a0e4940202ecfc2f2d83f4384 100644 (file)
@@ -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,
index 9173c306931304c1b9853e124ebb1a49c5b30992..e0ae9502ed8ff5c6fe103d8c7b0542f2040a9dd3 100644 (file)
@@ -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 = {
index 426adc31bce845da6e7c8cba69538749f7a6e21e..0ef3c791acb09abca13127e473f40615a025aaec 100644 (file)
@@ -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 = {
index c6428e4c266bd78e581d0ee7b0995c4cfd30e9a5..f611c97b5ba778702d60a8ce83a77448e25e74fc 100644 (file)
@@ -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,              \