summaryrefslogtreecommitdiffstats
path: root/src/netlink.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2017-08-14 17:47:21 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2017-08-15 14:03:41 +0200
commit0d9d04c31481c7c73b4ba64f0ad746b84c4250c5 (patch)
tree60713cea11ad785cfba3ceff19983e5394b97d2a /src/netlink.c
parent2caecefe812e4d614687926d259ade3106935c56 (diff)
src: make netlink sequence number non-static
Place sequence number that is allocated per-command on the struct netlink_ctx structure. This is allocated from nft_run() to correlate commands with netlink messages for error reporting. Batch support probing also shares this sequence numbers with commands. There is an inpendent cache sequence number though, this routine is called from a different path, usually from the evaluation phase. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/netlink.c')
-rw-r--r--src/netlink.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/netlink.c b/src/netlink.c
index 68f33625..7311149f 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -79,9 +79,9 @@ void netlink_restart(struct mnl_socket *nf_sock)
nf_sock = netlink_open_sock();
}
-void netlink_genid_get(struct mnl_socket *nf_sock)
+void netlink_genid_get(struct mnl_socket *nf_sock, uint32_t seqnum)
{
- mnl_genid_get(nf_sock);
+ mnl_genid_get(nf_sock, seqnum);
}
void __noreturn __netlink_abi_error(const char *file, int line,
@@ -570,7 +570,7 @@ static int netlink_list_rules(struct netlink_ctx *ctx, const struct handle *h,
{
struct nftnl_rule_list *rule_cache;
- rule_cache = mnl_nft_rule_dump(ctx->nf_sock, h->family);
+ rule_cache = mnl_nft_rule_dump(ctx->nf_sock, h->family, ctx->seqnum);
if (rule_cache == NULL) {
if (errno == EINTR)
return -1;
@@ -627,7 +627,7 @@ static int netlink_add_chain_compat(struct netlink_ctx *ctx,
}
netlink_dump_chain(nlc);
- err = mnl_nft_chain_add(ctx->nf_sock, nlc, flags);
+ err = mnl_nft_chain_add(ctx->nf_sock, nlc, flags, ctx->seqnum);
nftnl_chain_free(nlc);
if (err < 0)
@@ -693,7 +693,7 @@ static int netlink_rename_chain_compat(struct netlink_ctx *ctx,
nlc = alloc_nftnl_chain(h);
nftnl_chain_set_str(nlc, NFTNL_CHAIN_NAME, name);
netlink_dump_chain(nlc);
- err = mnl_nft_chain_add(ctx->nf_sock, nlc, 0);
+ err = mnl_nft_chain_add(ctx->nf_sock, nlc, 0, ctx->seqnum);
nftnl_chain_free(nlc);
if (err < 0)
@@ -740,7 +740,7 @@ static int netlink_del_chain_compat(struct netlink_ctx *ctx,
nlc = alloc_nftnl_chain(h);
netlink_dump_chain(nlc);
- err = mnl_nft_chain_delete(ctx->nf_sock, nlc, 0);
+ err = mnl_nft_chain_delete(ctx->nf_sock, nlc, 0, ctx->seqnum);
nftnl_chain_free(nlc);
if (err < 0)
@@ -843,7 +843,7 @@ int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h,
struct nftnl_chain_list *chain_cache;
struct chain *chain;
- chain_cache = mnl_nft_chain_dump(ctx->nf_sock, h->family);
+ chain_cache = mnl_nft_chain_dump(ctx->nf_sock, h->family, ctx->seqnum);
if (chain_cache == NULL) {
if (errno == EINTR)
return -1;
@@ -879,7 +879,7 @@ int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h,
int err;
nlc = alloc_nftnl_chain(h);
- err = mnl_nft_chain_get(ctx->nf_sock, nlc, 0);
+ err = mnl_nft_chain_get(ctx->nf_sock, nlc, 0, ctx->seqnum);
if (err < 0) {
netlink_io_error(ctx, loc,
"Could not receive chain from kernel: %s",
@@ -915,7 +915,7 @@ static int netlink_add_table_compat(struct netlink_ctx *ctx,
int err;
nlt = alloc_nftnl_table(h);
- err = mnl_nft_table_add(ctx->nf_sock, nlt, flags);
+ err = mnl_nft_table_add(ctx->nf_sock, nlt, flags, ctx->seqnum);
nftnl_table_free(nlt);
if (err < 0)
@@ -965,7 +965,7 @@ static int netlink_del_table_compat(struct netlink_ctx *ctx,
int err;
nlt = alloc_nftnl_table(h);
- err = mnl_nft_table_delete(ctx->nf_sock, nlt, 0);
+ err = mnl_nft_table_delete(ctx->nf_sock, nlt, 0, ctx->seqnum);
nftnl_table_free(nlt);
if (err < 0)
@@ -1042,7 +1042,7 @@ int netlink_list_tables(struct netlink_ctx *ctx, const struct handle *h,
{
struct nftnl_table_list *table_cache;
- table_cache = mnl_nft_table_dump(ctx->nf_sock, h->family);
+ table_cache = mnl_nft_table_dump(ctx->nf_sock, h->family, ctx->seqnum);
if (table_cache == NULL) {
if (errno == EINTR)
return -1;
@@ -1063,7 +1063,7 @@ int netlink_get_table(struct netlink_ctx *ctx, const struct handle *h,
int err;
nlt = alloc_nftnl_table(h);
- err = mnl_nft_table_get(ctx->nf_sock, nlt, 0);
+ err = mnl_nft_table_get(ctx->nf_sock, nlt, 0, ctx->seqnum);
if (err < 0) {
netlink_io_error(ctx, loc,
"Could not receive table from kernel: %s",
@@ -1254,7 +1254,8 @@ static int netlink_add_set_compat(struct netlink_ctx *ctx,
}
netlink_dump_set(nls);
- err = mnl_nft_set_add(ctx->nf_sock, nls, NLM_F_ECHO | flags);
+ err = mnl_nft_set_add(ctx->nf_sock, nls, NLM_F_ECHO | flags,
+ ctx->seqnum);
if (err < 0)
netlink_io_error(ctx, &set->location, "Could not add set: %s",
strerror(errno));
@@ -1350,7 +1351,7 @@ static int netlink_del_set_compat(struct netlink_ctx *ctx,
int err;
nls = alloc_nftnl_set(h);
- err = mnl_nft_set_delete(ctx->nf_sock, nls, 0);
+ err = mnl_nft_set_delete(ctx->nf_sock, nls, 0, ctx->seqnum);
nftnl_set_free(nls);
if (err < 0)
@@ -1403,7 +1404,8 @@ int netlink_list_sets(struct netlink_ctx *ctx, const struct handle *h,
struct nftnl_set_list *set_cache;
int err;
- set_cache = mnl_nft_set_dump(ctx->nf_sock, h->family, h->table);
+ set_cache = mnl_nft_set_dump(ctx->nf_sock, h->family, h->table,
+ ctx->seqnum);
if (set_cache == NULL) {
if (errno == EINTR)
return -1;
@@ -1424,7 +1426,7 @@ int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h,
int err;
nls = alloc_nftnl_set(h);
- err = mnl_nft_set_get(ctx->nf_sock, nls);
+ err = mnl_nft_set_get(ctx->nf_sock, nls, ctx->seqnum);
if (err < 0) {
nftnl_set_free(nls);
return netlink_io_error(ctx, loc,
@@ -1483,7 +1485,7 @@ static int netlink_add_setelems_compat(struct netlink_ctx *ctx,
alloc_setelem_cache(expr, nls);
netlink_dump_set(nls);
- err = mnl_nft_setelem_add(ctx->nf_sock, nls, flags);
+ err = mnl_nft_setelem_add(ctx->nf_sock, nls, flags, ctx->seqnum);
nftnl_set_free(nls);
if (err < 0)
netlink_io_error(ctx, &expr->location,
@@ -1533,7 +1535,7 @@ static int netlink_del_setelems_compat(struct netlink_ctx *ctx,
alloc_setelem_cache(expr, nls);
netlink_dump_set(nls);
- err = mnl_nft_setelem_delete(ctx->nf_sock, nls, 0);
+ err = mnl_nft_setelem_delete(ctx->nf_sock, nls, 0, ctx->seqnum);
nftnl_set_free(nls);
if (err < 0)
netlink_io_error(ctx, &expr->location,
@@ -1733,7 +1735,7 @@ int netlink_get_setelems(struct netlink_ctx *ctx, const struct handle *h,
nls = alloc_nftnl_set(h);
- err = mnl_nft_setelem_get(ctx->nf_sock, nls);
+ err = mnl_nft_setelem_get(ctx->nf_sock, nls, ctx->seqnum);
if (err < 0) {
nftnl_set_free(nls);
if (errno == EINTR)
@@ -1869,8 +1871,8 @@ int netlink_list_objs(struct netlink_ctx *ctx, const struct handle *h,
struct nftnl_obj_list *obj_cache;
int err;
- obj_cache = mnl_nft_obj_dump(ctx->nf_sock, h->family, h->table, NULL,
- 0, true, false);
+ obj_cache = mnl_nft_obj_dump(ctx->nf_sock, h->family, ctx->seqnum,
+ h->table, NULL, 0, true, false);
if (obj_cache == NULL) {
if (errno == EINTR)
return -1;
@@ -1889,8 +1891,8 @@ int netlink_reset_objs(struct netlink_ctx *ctx, const struct handle *h,
struct nftnl_obj_list *obj_cache;
int err;
- obj_cache = mnl_nft_obj_dump(ctx->nf_sock, h->family, h->table, h->obj,
- type, dump, true);
+ obj_cache = mnl_nft_obj_dump(ctx->nf_sock, h->family, ctx->seqnum,
+ h->table, h->obj, type, dump, true);
if (obj_cache == NULL) {
if (errno == EINTR)
return -1;
@@ -1935,7 +1937,7 @@ struct nftnl_ruleset *netlink_dump_ruleset(struct netlink_ctx *ctx,
{
struct nftnl_ruleset *rs;
- rs = mnl_nft_ruleset_dump(ctx->nf_sock, h->family);
+ rs = mnl_nft_ruleset_dump(ctx->nf_sock, h->family, ctx->seqnum);
if (rs == NULL) {
if (errno == EINTR)
return NULL;
@@ -3127,7 +3129,7 @@ int netlink_monitor(struct netlink_mon_handler *monhandler,
return mnl_nft_event_listener(nf_sock, netlink_events_cb, monhandler);
}
-bool netlink_batch_supported(struct mnl_socket *nf_sock)
+bool netlink_batch_supported(struct mnl_socket *nf_sock, uint32_t *seqnum)
{
- return mnl_batch_supported(nf_sock);
+ return mnl_batch_supported(nf_sock, seqnum);
}