summaryrefslogtreecommitdiffstats
path: root/src/expr/rt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/rt.c')
-rw-r--r--src/expr/rt.c62
1 files changed, 10 insertions, 52 deletions
diff --git a/src/expr/rt.c b/src/expr/rt.c
index 16a1aff..ff4fd03 100644
--- a/src/expr/rt.c
+++ b/src/expr/rt.c
@@ -12,7 +12,6 @@
#include <string.h>
#include <arpa/inet.h>
#include <errno.h>
-#include <assert.h>
#include <linux/netfilter/nf_tables.h>
#include "internal.h"
@@ -33,13 +32,11 @@ nftnl_expr_rt_set(struct nftnl_expr *e, uint16_t type,
switch (type) {
case NFTNL_EXPR_RT_KEY:
- memcpy(&rt->key, data, sizeof(rt->key));
+ memcpy(&rt->key, data, data_len);
break;
case NFTNL_EXPR_RT_DREG:
- memcpy(&rt->dreg, data, sizeof(rt->dreg));
+ memcpy(&rt->dreg, data, data_len);
break;
- default:
- return -1;
}
return 0;
}
@@ -113,46 +110,6 @@ 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",
@@ -195,18 +152,19 @@ nftnl_expr_rt_snprintf(char *buf, size_t len,
return 0;
}
+static struct attr_policy rt_attr_policy[__NFTNL_EXPR_RT_MAX] = {
+ [NFTNL_EXPR_RT_KEY] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_RT_DREG] = { .maxlen = sizeof(uint32_t) },
+};
+
struct expr_ops expr_ops_rt = {
.name = "rt",
.alloc_len = sizeof(struct nftnl_expr_rt),
- .max_attr = NFTA_RT_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_RT_MAX - 1,
+ .attr_policy = rt_attr_policy,
.set = nftnl_expr_rt_set,
.get = nftnl_expr_rt_get,
.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,
- },
+ .output = nftnl_expr_rt_snprintf,
};