summaryrefslogtreecommitdiffstats
path: root/src/expr/fwd.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-12-15 16:30:52 +0100
committerPhil Sutter <phil@nwl.cc>2024-03-06 15:40:37 +0100
commitcdde5a8c5a8734f2d540a0ab52c32d41d4d18127 (patch)
treea1641dedae09aa9b6e069d66b4e3212fe3525972 /src/expr/fwd.c
parent9da7658c6e25b02f7eeef936835469f4174cbfec (diff)
expr: Introduce struct expr_ops::attr_policy
Similar to kernel's nla_policy, enable expressions to inform about restrictions on attribute use. This allows the generic expression code to perform sanity checks before dispatching to expression ops. For now, this holds only the maximum data len which may be passed to nftnl_expr_set(). While one may debate whether accepting e.g. uint32_t for sreg/dreg attributes is correct, it is necessary to not break nftables. Note that this introduces artificial restrictions on name lengths which were caught by the kernel (if nftables didn't). Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src/expr/fwd.c')
-rw-r--r--src/expr/fwd.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/expr/fwd.c b/src/expr/fwd.c
index bd1b1d8..566d6f4 100644
--- a/src/expr/fwd.c
+++ b/src/expr/fwd.c
@@ -148,10 +148,17 @@ static int nftnl_expr_fwd_snprintf(char *buf, size_t remain,
return offset;
}
+static struct attr_policy fwd_attr_policy[__NFTNL_EXPR_FWD_MAX] = {
+ [NFTNL_EXPR_FWD_SREG_DEV] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_FWD_SREG_ADDR] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_FWD_NFPROTO] = { .maxlen = sizeof(uint32_t) },
+};
+
struct expr_ops expr_ops_fwd = {
.name = "fwd",
.alloc_len = sizeof(struct nftnl_expr_fwd),
.nftnl_max_attr = __NFTNL_EXPR_FWD_MAX - 1,
+ .attr_policy = fwd_attr_policy,
.set = nftnl_expr_fwd_set,
.get = nftnl_expr_fwd_get,
.parse = nftnl_expr_fwd_parse,