summaryrefslogtreecommitdiffstats
path: root/src/expr/osf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/osf.c')
-rw-r--r--src/expr/osf.c48
1 files changed, 21 insertions, 27 deletions
diff --git a/src/expr/osf.c b/src/expr/osf.c
index 98d0df9..35a31cf 100644
--- a/src/expr/osf.c
+++ b/src/expr/osf.c
@@ -18,20 +18,21 @@ struct nftnl_expr_osf {
uint32_t flags;
};
-static int nftnl_expr_osf_set(struct nftnl_expr *e, uint16_t type,
- const void *data, uint32_t data_len)
+static int
+nftnl_expr_osf_set(struct nftnl_expr *e, uint16_t type,
+ const void *data, uint32_t data_len, uint32_t byteorder)
{
struct nftnl_expr_osf *osf = nftnl_expr_data(e);
switch(type) {
case NFTNL_EXPR_OSF_DREG:
- memcpy(&osf->dreg, data, sizeof(osf->dreg));
+ memcpy(&osf->dreg, data, data_len);
break;
case NFTNL_EXPR_OSF_TTL:
- memcpy(&osf->ttl, data, sizeof(osf->ttl));
+ memcpy(&osf->ttl, data, data_len);
break;
case NFTNL_EXPR_OSF_FLAGS:
- memcpy(&osf->flags, data, sizeof(osf->flags));
+ memcpy(&osf->flags, data, data_len);
break;
}
return 0;
@@ -89,12 +90,12 @@ nftnl_expr_osf_build(struct nlmsghdr *nlh, const struct nftnl_expr *e)
struct nftnl_expr_osf *osf = nftnl_expr_data(e);
if (e->flags & (1 << NFTNL_EXPR_OSF_DREG))
- mnl_attr_put_u32(nlh, NFTNL_EXPR_OSF_DREG, htonl(osf->dreg));
+ mnl_attr_put_u32(nlh, NFTA_OSF_DREG, htonl(osf->dreg));
if (e->flags & (1 << NFTNL_EXPR_OSF_TTL))
- mnl_attr_put_u8(nlh, NFTNL_EXPR_OSF_TTL, osf->ttl);
+ mnl_attr_put_u8(nlh, NFTA_OSF_TTL, osf->ttl);
if (e->flags & (1 << NFTNL_EXPR_OSF_FLAGS))
if (osf->flags)
- mnl_attr_put_u32(nlh, NFTNL_EXPR_OSF_FLAGS, htonl(osf->flags));
+ mnl_attr_put_u32(nlh, NFTA_OSF_FLAGS, htonl(osf->flags));
}
static int
@@ -124,11 +125,12 @@ nftnl_expr_osf_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_osf_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_osf_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_osf *osf = nftnl_expr_data(e);
- int ret, offset = 0, len = size;
+ int ret, offset = 0;
if (e->flags & (1 << NFTNL_EXPR_OSF_DREG)) {
ret = snprintf(buf, len, "dreg %u ", osf->dreg);
@@ -138,28 +140,20 @@ static int nftnl_expr_osf_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_osf_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_osf_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
+static struct attr_policy osf_attr_policy[__NFTNL_EXPR_OSF_MAX] = {
+ [NFTNL_EXPR_OSF_DREG] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_EXPR_OSF_TTL] = { .maxlen = sizeof(uint8_t) },
+ [NFTNL_EXPR_OSF_FLAGS] = { .maxlen = sizeof(uint32_t) },
+};
struct expr_ops expr_ops_osf = {
.name = "osf",
.alloc_len = sizeof(struct nftnl_expr_osf),
- .max_attr = NFTA_OSF_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_OSF_MAX - 1,
+ .attr_policy = osf_attr_policy,
.set = nftnl_expr_osf_set,
.get = nftnl_expr_osf_get,
.parse = nftnl_expr_osf_parse,
.build = nftnl_expr_osf_build,
- .snprintf = nftnl_expr_osf_snprintf,
+ .output = nftnl_expr_osf_snprintf,
};