From mboxrd@z Thu Jan 1 00:00:00 1970 From: Patrick McHardy Subject: [PATCH 04/12] proto: add helper function to update protocol context Date: Wed, 8 Jan 2014 13:08:55 +0000 Message-ID: <1389186543-6919-5-git-send-email-kaber@trash.net> References: <1389186543-6919-1-git-send-email-kaber@trash.net> Cc: netfilter-devel@vger.kernel.org To: pablo@netfilter.org Return-path: Received: from stinky.trash.net ([213.144.137.162]:40190 "EHLO stinky.trash.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755739AbaAHNJP (ORCPT ); Wed, 8 Jan 2014 08:09:15 -0500 In-Reply-To: <1389186543-6919-1-git-send-email-kaber@trash.net> Sender: netfilter-devel-owner@vger.kernel.org List-ID: Add a helper function which is to be used to update the protocol update. Signed-off-by: Patrick McHardy 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 426adc3..0ef3c79 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 c6428e4..f611c97 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, \ -- 1.8.4.2