diff options
Diffstat (limited to 'src/expr/rt.c')
-rw-r--r-- | src/expr/rt.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/expr/rt.c b/src/expr/rt.c index 1ad9b2a..16a1aff 100644 --- a/src/expr/rt.c +++ b/src/expr/rt.c @@ -12,6 +12,7 @@ #include <string.h> #include <arpa/inet.h> #include <errno.h> +#include <assert.h> #include <linux/netfilter/nf_tables.h> #include "internal.h" @@ -112,6 +113,46 @@ nftnl_expr_rt_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } +static int nftnl_expr_rt_reg_len(const struct nftnl_expr *e) +{ + const struct nftnl_expr_rt *rt = nftnl_expr_data(e); + + switch (rt->key) { + case NFT_RT_CLASSID: + case NFT_RT_NEXTHOP4: + return sizeof(uint32_t); + case NFT_RT_NEXTHOP6: + return sizeof(uint32_t) * 4; + case NFT_RT_TCPMSS: + return sizeof(uint16_t); + case NFT_RT_XFRM: + return sizeof(uint8_t); + default: + assert(0); + break; + } + + return sizeof(uint32_t); +} + +static bool +nftnl_expr_rt_reg_cmp(const struct nftnl_reg *reg, + const struct nftnl_expr *e) +{ + const struct nftnl_expr_rt *rt = nftnl_expr_data(e); + + return reg->rt.key == rt->key; +} + +static void +nftnl_expr_rt_reg_update(struct nftnl_reg *reg, + const struct nftnl_expr *e) +{ + const struct nftnl_expr_rt *rt = nftnl_expr_data(e); + + reg->rt.key = rt->key; +} + static const char *rt_key2str_array[NFT_RT_MAX + 1] = { [NFT_RT_CLASSID] = "classid", [NFT_RT_NEXTHOP4] = "nexthop4", @@ -163,4 +204,9 @@ struct expr_ops expr_ops_rt = { .parse = nftnl_expr_rt_parse, .build = nftnl_expr_rt_build, .snprintf = nftnl_expr_rt_snprintf, + .reg = { + .len = nftnl_expr_rt_reg_len, + .cmp = nftnl_expr_rt_reg_cmp, + .update = nftnl_expr_rt_reg_update, + }, }; |