summaryrefslogtreecommitdiffstats
path: root/src/expr/match.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/match.c')
-rw-r--r--src/expr/match.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/expr/match.c b/src/expr/match.c
index 4fa74b2..8c1bc74 100644
--- a/src/expr/match.c
+++ b/src/expr/match.c
@@ -46,7 +46,7 @@ nftnl_expr_match_set(struct nftnl_expr *e, uint16_t type,
(const char *)data);
break;
case NFTNL_EXPR_MT_REV:
- memcpy(&mt->rev, data, sizeof(mt->rev));
+ memcpy(&mt->rev, data, data_len);
break;
case NFTNL_EXPR_MT_INFO:
if (e->flags & (1 << NFTNL_EXPR_MT_INFO))
@@ -55,8 +55,6 @@ nftnl_expr_match_set(struct nftnl_expr *e, uint16_t type,
mt->data = data;
mt->data_len = data_len;
break;
- default:
- return -1;
}
return 0;
}
@@ -165,21 +163,12 @@ static int nftnl_expr_match_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type,
+nftnl_expr_match_snprintf(char *buf, size_t len,
uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_match *match = nftnl_expr_data(e);
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return snprintf(buf, len, "name %s rev %u ",
- match->name, match->rev);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
+ return snprintf(buf, len, "name %s rev %u ", match->name, match->rev);
}
static void nftnl_expr_match_free(const struct nftnl_expr *e)
@@ -189,14 +178,21 @@ static void nftnl_expr_match_free(const struct nftnl_expr *e)
xfree(match->data);
}
+static struct attr_policy match_attr_policy[__NFTNL_EXPR_MT_MAX] = {
+ [NFTNL_EXPR_MT_NAME] = { .maxlen = XT_EXTENSION_MAXNAMELEN },
+ [NFTNL_EXPR_MT_REV] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_MT_INFO] = { .maxlen = 0 },
+};
+
struct expr_ops expr_ops_match = {
.name = "match",
.alloc_len = sizeof(struct nftnl_expr_match),
- .max_attr = NFTA_MATCH_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_MT_MAX - 1,
+ .attr_policy = match_attr_policy,
.free = nftnl_expr_match_free,
.set = nftnl_expr_match_set,
.get = nftnl_expr_match_get,
.parse = nftnl_expr_match_parse,
.build = nftnl_expr_match_build,
- .snprintf = nftnl_expr_match_snprintf,
+ .output = nftnl_expr_match_snprintf,
};