summaryrefslogtreecommitdiffstats
path: root/src/expr/last.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr/last.c')
-rw-r--r--src/expr/last.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/expr/last.c b/src/expr/last.c
index 0020fbc..8e5b88e 100644
--- a/src/expr/last.c
+++ b/src/expr/last.c
@@ -22,6 +22,7 @@
struct nftnl_expr_last {
uint64_t msecs;
+ uint32_t set;
};
static int nftnl_expr_last_set(struct nftnl_expr *e, uint16_t type,
@@ -31,10 +32,11 @@ static int nftnl_expr_last_set(struct nftnl_expr *e, uint16_t type,
switch (type) {
case NFTNL_EXPR_LAST_MSECS:
- memcpy(&last->msecs, data, sizeof(last->msecs));
+ memcpy(&last->msecs, data, data_len);
+ break;
+ case NFTNL_EXPR_LAST_SET:
+ memcpy(&last->set, data, data_len);
break;
- default:
- return -1;
}
return 0;
}
@@ -48,6 +50,9 @@ static const void *nftnl_expr_last_get(const struct nftnl_expr *e,
case NFTNL_EXPR_LAST_MSECS:
*data_len = sizeof(last->msecs);
return &last->msecs;
+ case NFTNL_EXPR_LAST_SET:
+ *data_len = sizeof(last->set);
+ return &last->set;
}
return NULL;
}
@@ -65,6 +70,10 @@ static int nftnl_expr_last_cb(const struct nlattr *attr, void *data)
if (mnl_attr_validate(attr, MNL_TYPE_U64) < 0)
abi_breakage();
break;
+ case NFTA_LAST_SET:
+ if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
+ abi_breakage();
+ break;
}
tb[type] = attr;
@@ -78,6 +87,8 @@ nftnl_expr_last_build(struct nlmsghdr *nlh, const struct nftnl_expr *e)
if (e->flags & (1 << NFTNL_EXPR_LAST_MSECS))
mnl_attr_put_u64(nlh, NFTA_LAST_MSECS, htobe64(last->msecs));
+ if (e->flags & (1 << NFTNL_EXPR_LAST_SET))
+ mnl_attr_put_u32(nlh, NFTA_LAST_SET, htonl(last->set));
}
static int
@@ -93,6 +104,10 @@ nftnl_expr_last_parse(struct nftnl_expr *e, struct nlattr *attr)
last->msecs = be64toh(mnl_attr_get_u64(tb[NFTA_LAST_MSECS]));
e->flags |= (1 << NFTNL_EXPR_LAST_MSECS);
}
+ if (tb[NFTA_LAST_SET]) {
+ last->set = ntohl(mnl_attr_get_u32(tb[NFTA_LAST_SET]));
+ e->flags |= (1 << NFTNL_EXPR_LAST_SET);
+ }
return 0;
}
@@ -103,16 +118,25 @@ static int nftnl_expr_last_snprintf(char *buf, size_t len,
{
struct nftnl_expr_last *last = nftnl_expr_data(e);
- return snprintf(buf, len, "last %"PRIu64" ", last->msecs);
+ if (!last->set)
+ return snprintf(buf, len, "never ");
+
+ return snprintf(buf, len, "%"PRIu64" ", last->msecs);
}
+static struct attr_policy last_attr_policy[__NFTNL_EXPR_LAST_MAX] = {
+ [NFTNL_EXPR_LAST_MSECS] = { .maxlen = sizeof(uint64_t) },
+ [NFTNL_EXPR_LAST_SET] = { .maxlen = sizeof(uint32_t) },
+};
+
struct expr_ops expr_ops_last = {
.name = "last",
.alloc_len = sizeof(struct nftnl_expr_last),
- .max_attr = NFTA_LAST_MAX,
+ .nftnl_max_attr = __NFTNL_EXPR_LAST_MAX - 1,
+ .attr_policy = last_attr_policy,
.set = nftnl_expr_last_set,
.get = nftnl_expr_last_get,
.parse = nftnl_expr_last_parse,
.build = nftnl_expr_last_build,
- .snprintf = nftnl_expr_last_snprintf,
+ .output = nftnl_expr_last_snprintf,
};