expr: extend support for dynamic register allocation
Pablo Neira Ayuso
maintainerPATCH 1/1 expr: extend support for dynamic register allocation
From: "Jose M. Guisado Gomez" <[email protected]>
Add expression support for:
- ct
- exthdr
- fib
- osf
- rt
- socket
- xfrm
to extend b9e00458b9f3 ("src: add dynamic register allocation infrastructure").
Joint work with Pablo.
Signed-off-by Jose M. Guisado Gomez <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- include/regs.h | 38 ++++++++++++++++++++++ src/expr/ct.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++ src/expr/exthdr.c | 37 +++++++++++++++++++++ src/expr/fib.c | 45 ++++++++++++++++++++++++++ src/expr/osf.c | 32 ++++++++++++++++++ src/expr/rt.c | 46 ++++++++++++++++++++++++++ src/expr/socket.c | 47 +++++++++++++++++++++++++++ src/expr/xfrm.c | 51 +++++++++++++++++++++++++++++ src/regs.c | 16 ++++++++- 9 files changed, 393 insertions(+), 1 deletion(-)
include/regs.h +38 -0
@@ -5,6 +5,13 @@ enum nftnl_expr_type {NFT_EXPR_UNSPEC =0 ,NFT_EXPR_PAYLOAD ,NFT_EXPR_META , +NFT_EXPR_CT , +NFT_EXPR_EXTHDR , +NFT_EXPR_FIB , +NFT_EXPR_OSF , +NFT_EXPR_RT , +NFT_EXPR_XFRM , + NFT_EXPR_SOCKET, }; struct nftnl_reg {
@@ -20,6 +27,37 @@ struct nftnl_reg {enum nft_payload_bases base;uint32_t offset; } payload; +struct { +enum nft_ct_keys key; +uint8_t dir; + } ct; +struct { +uint32_t offset; +uint32_t len; +uint8_t type; +uint32_t op; +uint32_t flags; + } exthdr; +struct { +uint32_t flags; +uint32_t result; + } fib; +struct { +uint8_t ttl; +uint32_t flags; + } osf; +struct { +enum nft_rt_keys key; + } rt; +struct { +enum nft_socket_keys key; +uint32_t level; + } socket; +struct { +enum nft_xfrm_keys key; +uint32_t spnum; +uint8_t dir; + } xfrm; }; };
src/expr/ct.c +82 -0
98 lines not on this page · raw message
src/expr/exthdr.c +37 -0
@@ -194,6 +194,38 @@ nftnl_expr_exthdr_parse(struct nftnl_expr *e, struct nlattr *attr)return 0 ; } +static int +nftnl_expr_exthdr_reg_len (const struct nftnl_expr *e) +{ +const struct nftnl_expr_exthdr *exthdr =nftnl_expr_data (e); + +return exthdr->len; +} + +static bool +nftnl_expr_exthdr_reg_cmp (const struct nftnl_reg *reg, +const struct nftnl_expr *e) +{ +const struct nftnl_expr_exthdr *exthdr =nftnl_expr_data (e); + +return reg->exthdr.offset == exthdr->offset && + reg->exthdr.type == exthdr->type && + reg->exthdr.op == exthdr->op && + reg->exthdr.flags == exthdr->flags; +} + +static void +nftnl_expr_exthdr_reg_update (struct nftnl_reg *reg, +const struct nftnl_expr *e) +{ +const struct nftnl_expr_exthdr *exthdr =nftnl_expr_data (e); + + reg->exthdr.offset = exthdr->offset; + reg->exthdr.type = exthdr->type; + reg->exthdr.op = exthdr->op; + reg->exthdr.flags = exthdr->flags; +} +static const char *op2str (uint8_t op) {switch (op) {
@@ -268,4 +300,9 @@ struct expr_ops expr_ops_exthdr = { .parse = nftnl_expr_exthdr_parse, .build = nftnl_expr_exthdr_build, .snprintf = nftnl_expr_exthdr_snprintf, + .reg = { + .len = nftnl_expr_exthdr_reg_len, + .cmp = nftnl_expr_exthdr_reg_cmp, + .update = nftnl_expr_exthdr_reg_update, + }, };
src/expr/fib.c +45 -0
61 lines not on this page · raw message
src/expr/osf.c +32 -0
@@ -11,6 +11,7 @@#include <libnftnl/rule.h> #define OSF_GENRE_SIZE 32 +#define NFT_OSF_MAXGENRELEN 16struct nftnl_expr_osf {enum nft_registers dreg;
@@ -124,6 +125,32 @@ nftnl_expr_osf_parse(struct nftnl_expr *e, struct nlattr *attr)return 0 ; } +static int +nftnl_expr_osf_reg_len (const struct nftnl_expr *e) +{ +return NFT_OSF_MAXGENRELEN ; +} + +static bool +nftnl_expr_osf_reg_cmp (const struct nftnl_reg *reg, +const struct nftnl_expr *e) +{ +const struct nftnl_expr_osf *osf =nftnl_expr_data (e); + +return reg->osf.ttl == osf->ttl && + reg->osf.flags == osf->flags; +} + +static void +nftnl_expr_osf_reg_update (struct nftnl_reg *reg, +const struct nftnl_expr *e) +{ +const struct nftnl_expr_osf *osf =nftnl_expr_data (e); + + reg->osf.ttl = osf->ttl; + reg->osf.flags = osf->flags; +} +static int nftnl_expr_osf_snprintf (char *buf,size_t len,uint32_t flags,const struct nftnl_expr *e)
@@ -148,4 +175,9 @@ struct expr_ops expr_ops_osf = { .parse = nftnl_expr_osf_parse, .build = nftnl_expr_osf_build, .snprintf = nftnl_expr_osf_snprintf, + .reg = { + .len = nftnl_expr_osf_reg_len, + .cmp = nftnl_expr_osf_reg_cmp, + .update = nftnl_expr_osf_reg_update, + }, };
src/expr/rt.c +46 -0
62 lines not on this page · raw message
src/expr/socket.c +47 -0
63 lines not on this page · raw message
src/expr/xfrm.c +51 -0
67 lines not on this page · raw message
src/regs.c +15 -1
@@ -55,10 +55,24 @@ void nftnl_regs_free(const struct nftnl_regs *regs)static enum nftnl_expr_type nftnl_expr_type (const struct nftnl_expr *expr) { -if (!strcmp (expr->ops->name,"meta" )) +if (!strcmp (expr->ops->name,"ct" )) +return NFT_EXPR_CT ; +else if (!strcmp (expr->ops->name,"exthdr" )) +return NFT_EXPR_EXTHDR ; +else if (!strcmp (expr->ops->name,"fib" )) +return NFT_EXPR_FIB ; +else if (!strcmp (expr->ops->name,"meta" ))return NFT_EXPR_META ; +else if (!strcmp (expr->ops->name,"osf" )) +return NFT_EXPR_OSF ;else if (!strcmp (expr->ops->name,"payload" ))return NFT_EXPR_PAYLOAD ; +else if (!strcmp (expr->ops->name,"rt" )) +return NFT_EXPR_RT ; +else if (!strcmp (expr->ops->name,"socket" )) +return NFT_EXPR_SOCKET ; +else if (!strcmp (expr->ops->name,"xfrm" )) +return NFT_EXPR_XFRM ;assert (0 );return NFT_EXPR_UNSPEC ;
Signature · 1 line
2.30.2