15 #include <netinet/in.h>
17 #include <linux/netfilter.h>
18 #include <linux/netfilter/nf_tables.h>
20 #include <libmnl/libmnl.h>
21 #include <libnftnl/set.h>
23 int main(
int argc,
char *argv[])
25 struct mnl_socket *nl;
26 char buf[MNL_SOCKET_BUFFER_SIZE];
28 uint32_t portid, seq, family;
29 struct nft_set *t = NULL;
33 fprintf(stderr,
"%s <family> <table> <set>\n", argv[0]);
44 if (strcmp(argv[1],
"ip") == 0)
45 family = NFPROTO_IPV4;
46 else if (strcmp(argv[1],
"ip6") == 0)
47 family = NFPROTO_IPV6;
48 else if (strcmp(argv[1],
"bridge") == 0)
49 family = NFPROTO_BRIDGE;
50 else if (strcmp(argv[1],
"arp") == 0)
53 fprintf(stderr,
"Unknown family: ip, ip6, bridge, arp\n");
57 nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_DELSET, family,
59 nft_set_attr_set(t, NFT_SET_ATTR_TABLE, argv[2]);
60 nft_set_attr_set(t, NFT_SET_ATTR_NAME, argv[3]);
62 nft_set_nlmsg_build_payload(nlh, t);
65 nl = mnl_socket_open(NETLINK_NETFILTER);
67 perror(
"mnl_socket_open");
71 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
72 perror(
"mnl_socket_bind");
75 portid = mnl_socket_get_portid(nl);
77 if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
78 perror(
"mnl_socket_send");
82 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
84 ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
87 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));