]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
exthdr: prepare for tcp support
authorManuel Messner <mm@skelett.io>
Tue, 7 Feb 2017 02:14:10 +0000 (03:14 +0100)
committerFlorian Westphal <fw@strlen.de>
Sun, 12 Feb 2017 14:34:47 +0000 (15:34 +0100)
right now exthdr only deals with ipv6 extension headers, followup
patch will enable tcp option matching.

This adds the 'op' arg to exthdr_init.

Signed-off-by: Manuel Messner <mm@skelett.io>
Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
include/exthdr.h
src/exthdr.c
src/netlink_delinearize.c
src/netlink_linearize.c

index d17841bc46159da1c10505caa8322834e5396ada..93a53f307f553184d880f4e35169ab58d84bb0a8 100644 (file)
@@ -21,7 +21,8 @@ extern struct expr *exthdr_expr_alloc(const struct location *loc,
                                      uint8_t type);
 
 extern void exthdr_init_raw(struct expr *expr, uint8_t type,
-                           unsigned int offset, unsigned int len);
+                           unsigned int offset, unsigned int len,
+                           enum nft_exthdr_op op);
 
 extern bool exthdr_find_template(struct expr *expr, const struct expr *mask,
                                 unsigned int *shift);
index c641d4a398ad235c3a37ab3d6e569b6bf13d0a3b..45b1b690766480358c2ee06bf7c793609f8a068d 100644 (file)
@@ -79,7 +79,8 @@ static const struct exthdr_desc *exthdr_protocols[IPPROTO_MAX] = {
 };
 
 void exthdr_init_raw(struct expr *expr, uint8_t type,
-                    unsigned int offset, unsigned int len)
+                    unsigned int offset, unsigned int len,
+                    enum nft_exthdr_op op)
 {
        const struct proto_hdr_template *tmpl;
        unsigned int i;
@@ -123,7 +124,7 @@ bool exthdr_find_template(struct expr *expr, const struct expr *mask, unsigned i
        off += round_up(mask->len, BITS_PER_BYTE) - mask_len;
 
        exthdr_init_raw(expr, expr->exthdr.desc->type,
-                       off, mask_len - mask_offset);
+                       off, mask_len - mask_offset, NFT_EXTHDR_OP_IPV6);
 
        /* still failed to find a template... Bug. */
        if (expr->exthdr.tmpl == &exthdr_unknown_template)
index 48968442d9bcc04b4fdc1fc4acbc66d13ddcd9e8..f21d2d56ef284ecdf5a1e2d8ba6201b3ff24dbd8 100644 (file)
@@ -499,6 +499,7 @@ static void netlink_parse_exthdr(struct netlink_parse_ctx *ctx,
                                 const struct nftnl_expr *nle)
 {
        enum nft_registers dreg;
+       enum nft_exthdr_op op;
        uint32_t offset, len;
        uint8_t type;
        struct expr *expr;
@@ -506,9 +507,10 @@ static void netlink_parse_exthdr(struct netlink_parse_ctx *ctx,
        type   = nftnl_expr_get_u8(nle, NFTNL_EXPR_EXTHDR_TYPE);
        offset = nftnl_expr_get_u32(nle, NFTNL_EXPR_EXTHDR_OFFSET) * BITS_PER_BYTE;
        len    = nftnl_expr_get_u32(nle, NFTNL_EXPR_EXTHDR_LEN) * BITS_PER_BYTE;
+       op     = NFT_EXTHDR_OP_IPV6;
 
        expr = exthdr_expr_alloc(loc, NULL, 0);
-       exthdr_init_raw(expr, type, offset, len);
+       exthdr_init_raw(expr, type, offset, len, op);
 
        dreg = netlink_parse_register(nle, NFTNL_EXPR_EXTHDR_DREG);
        netlink_set_register(ctx, dreg, expr);
index 5030135cd5d5806bd2fbf092c9c5cae5e6adcf54..056f11317298682b3508cce969e58f9979090f38 100644 (file)
@@ -162,14 +162,14 @@ static void netlink_gen_exthdr(struct netlink_linearize_ctx *ctx,
                               const struct expr *expr,
                               enum nft_registers dreg)
 {
+       unsigned int offset = expr->exthdr.tmpl->offset;
        struct nftnl_expr *nle;
 
        nle = alloc_nft_expr("exthdr");
        netlink_put_register(nle, NFTNL_EXPR_EXTHDR_DREG, dreg);
        nftnl_expr_set_u8(nle, NFTNL_EXPR_EXTHDR_TYPE,
                          expr->exthdr.desc->type);
-       nftnl_expr_set_u32(nle, NFTNL_EXPR_EXTHDR_OFFSET,
-                          expr->exthdr.tmpl->offset / BITS_PER_BYTE);
+       nftnl_expr_set_u32(nle, NFTNL_EXPR_EXTHDR_OFFSET, offset / BITS_PER_BYTE);
        nftnl_expr_set_u32(nle, NFTNL_EXPR_EXTHDR_LEN,
                           div_round_up(expr->len, BITS_PER_BYTE));
        nftnl_rule_add_expr(ctx->nlr, nle);