summaryrefslogtreecommitdiffstats
path: root/src/obj/ct_expect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/obj/ct_expect.c')
-rw-r--r--src/obj/ct_expect.c63
1 files changed, 29 insertions, 34 deletions
diff --git a/src/obj/ct_expect.c b/src/obj/ct_expect.c
index c0bb5ba..b4d6faa 100644
--- a/src/obj/ct_expect.c
+++ b/src/obj/ct_expect.c
@@ -21,22 +21,20 @@ static int nftnl_obj_ct_expect_set(struct nftnl_obj *e, uint16_t type,
switch (type) {
case NFTNL_OBJ_CT_EXPECT_L3PROTO:
- memcpy(&exp->l3proto, data, sizeof(exp->l3proto));
+ memcpy(&exp->l3proto, data, data_len);
break;
case NFTNL_OBJ_CT_EXPECT_L4PROTO:
- memcpy(&exp->l4proto, data, sizeof(exp->l4proto));
+ memcpy(&exp->l4proto, data, data_len);
break;
case NFTNL_OBJ_CT_EXPECT_DPORT:
- memcpy(&exp->dport, data, sizeof(exp->dport));
+ memcpy(&exp->dport, data, data_len);
break;
case NFTNL_OBJ_CT_EXPECT_TIMEOUT:
- memcpy(&exp->timeout, data, sizeof(exp->timeout));
+ memcpy(&exp->timeout, data, data_len);
break;
case NFTNL_OBJ_CT_EXPECT_SIZE:
- memcpy(&exp->size, data, sizeof(exp->size));
+ memcpy(&exp->size, data, data_len);
break;
- default:
- return -1;
}
return 0;
}
@@ -151,31 +149,35 @@ nftnl_obj_ct_expect_parse(struct nftnl_obj *e, struct nlattr *attr)
return 0;
}
-static int nftnl_obj_ct_expect_snprintf_default(char *buf, size_t len,
- const struct nftnl_obj *e)
+static int nftnl_obj_ct_expect_snprintf(char *buf, size_t remain,
+ uint32_t flags,
+ const struct nftnl_obj *e)
{
- int ret = 0;
- int offset = 0, remain = len;
struct nftnl_obj_ct_expect *exp = nftnl_obj_data(e);
+ int ret = 0, offset = 0;
if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_L3PROTO)) {
- ret = snprintf(buf + offset, len, "family %d ", exp->l3proto);
+ ret = snprintf(buf + offset, remain,
+ "family %d ", exp->l3proto);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_L4PROTO)) {
- ret = snprintf(buf + offset, len, "protocol %d ", exp->l4proto);
+ ret = snprintf(buf + offset, remain,
+ "protocol %d ", exp->l4proto);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_DPORT)) {
- ret = snprintf(buf + offset, len, "dport %d ", exp->dport);
+ ret = snprintf(buf + offset, remain,
+ "dport %d ", exp->dport);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_TIMEOUT)) {
- ret = snprintf(buf + offset, len, "timeout %d ", exp->timeout);
+ ret = snprintf(buf + offset, remain,
+ "timeout %d ", exp->timeout);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_SIZE)) {
- ret = snprintf(buf + offset, len, "size %d ", exp->size);
+ ret = snprintf(buf + offset, remain, "size %d ", exp->size);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
@@ -183,31 +185,24 @@ static int nftnl_obj_ct_expect_snprintf_default(char *buf, size_t len,
return offset;
}
-static int nftnl_obj_ct_expect_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags,
- const struct nftnl_obj *e)
-{
- if (len)
- buf[0] = '\0';
-
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_obj_ct_expect_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
+static struct attr_policy
+obj_ct_expect_attr_policy[__NFTNL_OBJ_CT_EXPECT_MAX] = {
+ [NFTNL_OBJ_CT_EXPECT_L3PROTO] = { .maxlen = sizeof(uint16_t) },
+ [NFTNL_OBJ_CT_EXPECT_L4PROTO] = { .maxlen = sizeof(uint8_t) },
+ [NFTNL_OBJ_CT_EXPECT_DPORT] = { .maxlen = sizeof(uint16_t) },
+ [NFTNL_OBJ_CT_EXPECT_TIMEOUT] = { .maxlen = sizeof(uint32_t) },
+ [NFTNL_OBJ_CT_EXPECT_SIZE] = { .maxlen = sizeof(uint8_t) },
+};
struct obj_ops obj_ops_ct_expect = {
.name = "ct_expect",
.type = NFT_OBJECT_CT_EXPECT,
.alloc_len = sizeof(struct nftnl_obj_ct_expect),
- .max_attr = NFTA_CT_EXPECT_MAX,
+ .nftnl_max_attr = __NFTNL_OBJ_CT_EXPECT_MAX - 1,
+ .attr_policy = obj_ct_expect_attr_policy,
.set = nftnl_obj_ct_expect_set,
.get = nftnl_obj_ct_expect_get,
.parse = nftnl_obj_ct_expect_parse,
.build = nftnl_obj_ct_expect_build,
- .snprintf = nftnl_obj_ct_expect_snprintf,
+ .output = nftnl_obj_ct_expect_snprintf,
};