summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/expr/last.c22
-rw-r--r--src/expr/payload.c5
-rw-r--r--src/libnftnl.map4
-rw-r--r--src/set.c2
-rw-r--r--src/set_elem.c22
5 files changed, 41 insertions, 14 deletions
diff --git a/src/expr/last.c b/src/expr/last.c
index 0020fbc..e2a60c4 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,
@@ -33,6 +34,9 @@ static int nftnl_expr_last_set(struct nftnl_expr *e, uint16_t type,
case NFTNL_EXPR_LAST_MSECS:
memcpy(&last->msecs, data, sizeof(last->msecs));
break;
+ case NFTNL_EXPR_LAST_SET:
+ memcpy(&last->set, data, sizeof(last->set));
+ break;
default:
return -1;
}
@@ -48,6 +52,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 +72,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 +89,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 +106,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,7 +120,10 @@ 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);
}
struct expr_ops expr_ops_last = {
diff --git a/src/expr/payload.c b/src/expr/payload.c
index 9ccb78e..82747ec 100644
--- a/src/expr/payload.c
+++ b/src/expr/payload.c
@@ -203,15 +203,16 @@ nftnl_expr_payload_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static const char *base2str_array[NFT_PAYLOAD_TRANSPORT_HEADER+1] = {
+static const char *base2str_array[NFT_PAYLOAD_INNER_HEADER + 1] = {
[NFT_PAYLOAD_LL_HEADER] = "link",
[NFT_PAYLOAD_NETWORK_HEADER] = "network",
[NFT_PAYLOAD_TRANSPORT_HEADER] = "transport",
+ [NFT_PAYLOAD_INNER_HEADER] = "inner",
};
static const char *base2str(enum nft_payload_bases base)
{
- if (base > NFT_PAYLOAD_TRANSPORT_HEADER)
+ if (base > NFT_PAYLOAD_INNER_HEADER)
return "unknown";
return base2str_array[base];
diff --git a/src/libnftnl.map b/src/libnftnl.map
index e707b89..ad8f2af 100644
--- a/src/libnftnl.map
+++ b/src/libnftnl.map
@@ -383,3 +383,7 @@ LIBNFTNL_16 {
nftnl_expr_add_expr;
nftnl_expr_expr_foreach;
} LIBNFTNL_15;
+
+LIBNFTNL_17 {
+ nftnl_set_elem_nlmsg_build;
+} LIBNFTNL_16;
diff --git a/src/set.c b/src/set.c
index 1c29dd2..c46f827 100644
--- a/src/set.c
+++ b/src/set.c
@@ -829,7 +829,7 @@ static int nftnl_set_snprintf_default(char *buf, size_t remain,
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
ret = nftnl_set_elem_snprintf_default(buf + offset, remain,
- elem, s->data_type);
+ elem);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
diff --git a/src/set_elem.c b/src/set_elem.c
index 90632a2..12eadce 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -388,8 +388,9 @@ static void nftnl_set_elem_nlmsg_build_def(struct nlmsghdr *nlh,
mnl_attr_put_strz(nlh, NFTA_SET_ELEM_LIST_TABLE, s->table);
}
-static struct nlattr *nftnl_set_elem_build(struct nlmsghdr *nlh,
- struct nftnl_set_elem *elem, int i)
+EXPORT_SYMBOL(nftnl_set_elem_nlmsg_build);
+struct nlattr *nftnl_set_elem_nlmsg_build(struct nlmsghdr *nlh,
+ struct nftnl_set_elem *elem, int i)
{
struct nlattr *nest2;
@@ -414,7 +415,7 @@ void nftnl_set_elems_nlmsg_build_payload(struct nlmsghdr *nlh, struct nftnl_set
nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_LIST_ELEMENTS);
list_for_each_entry(elem, &s->element_list, head)
- nftnl_set_elem_build(nlh, elem, ++i);
+ nftnl_set_elem_nlmsg_build(nlh, elem, ++i);
mnl_attr_nest_end(nlh, nest1);
}
@@ -699,11 +700,9 @@ int nftnl_set_elem_parse_file(struct nftnl_set_elem *e, enum nftnl_parse_type ty
}
int nftnl_set_elem_snprintf_default(char *buf, size_t remain,
- const struct nftnl_set_elem *e,
- enum nft_data_types dtype)
+ const struct nftnl_set_elem *e)
{
- int dregtype = (dtype == NFT_DATA_VERDICT) ? DATA_VERDICT : DATA_VALUE;
- int ret, offset = 0, i;
+ int ret, dregtype = DATA_VALUE, offset = 0, i;
ret = snprintf(buf, remain, "element ");
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
@@ -724,6 +723,9 @@ int nftnl_set_elem_snprintf_default(char *buf, size_t remain,
ret = snprintf(buf + offset, remain, " : ");
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+ if (e->flags & (1 << NFTNL_SET_ELEM_VERDICT))
+ dregtype = DATA_VERDICT;
+
ret = nftnl_data_reg_snprintf(buf + offset, remain, &e->data,
DATA_F_NOPFX, dregtype);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
@@ -760,9 +762,9 @@ static int nftnl_set_elem_cmd_snprintf(char *buf, size_t remain,
if (type != NFTNL_OUTPUT_DEFAULT)
return -1;
- ret = nftnl_set_elem_snprintf_default(buf + offset, remain, e,
- NFT_DATA_VALUE);
+ ret = nftnl_set_elem_snprintf_default(buf + offset, remain, e);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+
return offset;
}
@@ -898,7 +900,7 @@ int nftnl_set_elems_nlmsg_build_payload_iter(struct nlmsghdr *nlh,
nest1 = mnl_attr_nest_start(nlh, NFTA_SET_ELEM_LIST_ELEMENTS);
elem = nftnl_set_elems_iter_next(iter);
while (elem != NULL) {
- nest2 = nftnl_set_elem_build(nlh, elem, ++i);
+ nest2 = nftnl_set_elem_nlmsg_build(nlh, elem, ++i);
if (nftnl_attr_nest_overflow(nlh, nest1, nest2)) {
/* Go back to previous not to miss this element */
iter->cur = list_entry(iter->cur->head.prev,