diff options
author | Patrick McHardy <kaber@trash.net> | 2014-01-08 13:02:15 +0000 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2014-01-08 13:02:15 +0000 |
commit | 8f86606efe82489945db1706bd1d1a4d524afcad (patch) | |
tree | 5a7b5febee4c8190a067b3d1af38fcd5f9172c74 /src/meta.c | |
parent | bc3656ad1e5b5812f916e9c9356785c06ce90936 (diff) |
nftables: generic procotol contexts
Currently the context of higher layer protocols is specific to payload
expressions with some special cases for meta IIFTYPE expressions. This
approach has a few shortcomings, concretely there are more expression
types which define upper layer protocols like the ct expression and two
upcoming new types for the meta expression.
Replace the payload context by a generic protocol context to deal with
this. This patch just splits off the requires parts from the payload
expression without any functional changes, the following patches will
add further functionality for other expressions.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src/meta.c')
-rw-r--r-- | src/meta.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -341,6 +341,35 @@ static void meta_expr_clone(struct expr *new, const struct expr *expr) new->meta.key = expr->meta.key; } +/** + * meta_expr_pctx_update - update protocol context based on meta match + * + * @ctx: protocol context + * @expr: relational meta expression + * + * Update LL protocol context based on IIFTYPE meta match in non-LL hooks. + */ +void meta_expr_pctx_update(struct proto_ctx *ctx, const struct expr *expr) +{ + const struct hook_proto_desc *h = &hook_proto_desc[ctx->family]; + const struct expr *left = expr->left, *right = expr->right; + const struct proto_desc *desc; + + if (left->meta.key != NFT_META_IIFTYPE) + return; + + assert(expr->op == OP_EQ); + if (h->base < PROTO_BASE_NETWORK_HDR) + return; + + desc = proto_dev_desc(mpz_get_uint16(right->value)); + if (desc == NULL) + desc = &proto_unknown; + + ctx->protocol[PROTO_BASE_LL_HDR].location = expr->location; + ctx->protocol[PROTO_BASE_LL_HDR].desc = desc; +} + static const struct expr_ops meta_expr_ops = { .type = EXPR_META, .name = "meta", |