summaryrefslogtreecommitdiffstats
path: root/src/expr/byteorder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/byteorder.c')
-rw-r--r--src/expr/byteorder.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c
index efdfa2b..383e80d 100644
--- a/src/expr/byteorder.c
+++ b/src/expr/byteorder.c
@@ -37,22 +37,20 @@ nftnl_expr_byteorder_set(struct nftnl_expr *e, uint16_t type,
switch(type) {
case NFTNL_EXPR_BYTEORDER_SREG:
- memcpy(&byteorder->sreg, data, sizeof(byteorder->sreg));
+ memcpy(&byteorder->sreg, data, data_len);
break;
case NFTNL_EXPR_BYTEORDER_DREG:
- memcpy(&byteorder->dreg, data, sizeof(byteorder->dreg));
+ memcpy(&byteorder->dreg, data, data_len);
break;
case NFTNL_EXPR_BYTEORDER_OP:
- memcpy(&byteorder->op, data, sizeof(byteorder->op));
+ memcpy(&byteorder->op, data, data_len);
break;
case NFTNL_EXPR_BYTEORDER_LEN:
- memcpy(&byteorder->len, data, sizeof(byteorder->len));
+ memcpy(&byteorder->len, data, data_len);
break;
case NFTNL_EXPR_BYTEORDER_SIZE:
- memcpy(&byteorder->size, data, sizeof(byteorder->size));
+ memcpy(&byteorder->size, data, data_len);
break;
- default:
- return -1;
}
return 0;
}
@@ -197,11 +195,12 @@ static inline int nftnl_str2ntoh(const char *op)
}
}
-static int nftnl_expr_byteorder_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_byteorder_snprintf(char *buf, size_t remain,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e);
- int remain = size, offset = 0, ret;
+ int offset = 0, ret;
ret = snprintf(buf, remain, "reg %u = %s(reg %u, %u, %u) ",
byteorder->dreg, bo2str(byteorder->op),
@@ -211,28 +210,22 @@ static int nftnl_expr_byteorder_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_byteorder_snprintf_default(buf, size, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
+static struct attr_policy byteorder_attr_policy[__NFTNL_EXPR_BYTEORDER_MAX] = {
+ [NFTNL_EXPR_BYTEORDER_DREG] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_BYTEORDER_SREG] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_BYTEORDER_OP] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_BYTEORDER_LEN] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_BYTEORDER_SIZE] = { .maxlen = sizeof(uint32_t) },
+};
struct expr_ops expr_ops_byteorder = {
.name = "byteorder",
.alloc_len = sizeof(struct nftnl_expr_byteorder),
- .max_attr = NFTA_BYTEORDER_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_BYTEORDER_MAX - 1,
+ .attr_policy = byteorder_attr_policy,
.set = nftnl_expr_byteorder_set,
.get = nftnl_expr_byteorder_get,
.parse = nftnl_expr_byteorder_parse,
.build = nftnl_expr_byteorder_build,
- .snprintf = nftnl_expr_byteorder_snprintf,
+ .output = nftnl_expr_byteorder_snprintf,
};