* [PATCH libnftnl] examples: nft-set-del: fix set deletion
@ 2018-02-14 19:04 Pablo Neira Ayuso
0 siblings, 0 replies; only message in thread
From: Pablo Neira Ayuso @ 2018-02-14 19:04 UTC (permalink / raw)
To: netfilter-devel
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
examples/nft-set-del.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/examples/nft-set-del.c b/examples/nft-set-del.c
index 5e1fad30d341..8c216df861d7 100644
--- a/examples/nft-set-del.c
+++ b/examples/nft-set-del.c
@@ -25,6 +25,7 @@ int main(int argc, char *argv[])
struct mnl_socket *nl;
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
+ struct mnl_nlmsg_batch *batch;
uint32_t portid, seq, family;
struct nftnl_set *t = NULL;
int ret;
@@ -54,13 +55,23 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_DELSET, family,
+ batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
+
+ nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
+ mnl_nlmsg_batch_next(batch);
+
+ nlh = nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
+ NFT_MSG_DELSET, family,
NLM_F_ACK, seq);
nftnl_set_set(t, NFTNL_SET_TABLE, argv[2]);
nftnl_set_set(t, NFTNL_SET_NAME, argv[3]);
nftnl_set_nlmsg_build_payload(nlh, t);
nftnl_set_free(t);
+ mnl_nlmsg_batch_next(batch);
+
+ nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
+ mnl_nlmsg_batch_next(batch);
nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
@@ -74,20 +85,24 @@ int main(int argc, char *argv[])
}
portid = mnl_socket_get_portid(nl);
- if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
+ ret = mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch),
+ mnl_nlmsg_batch_size(batch));
+ if (ret < 0) {
perror("mnl_socket_send");
exit(EXIT_FAILURE);
}
+ mnl_nlmsg_batch_stop(batch);
+
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
- while (ret > 0) {
- ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
- if (ret <= 0)
- break;
- ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
+ while (ret < 0) {
+ perror("mnl_socket_recvfrom");
+ exit(EXIT_FAILURE);
}
- if (ret == -1) {
- perror("error");
+
+ ret = mnl_cb_run(buf, ret, 0, portid, NULL, NULL);
+ if (ret < 0) {
+ perror("mnl_cb_run");
exit(EXIT_FAILURE);
}
mnl_socket_close(nl);
--
2.11.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2018-02-14 19:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-14 19:04 [PATCH libnftnl] examples: nft-set-del: fix set deletion Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).