examples: do not call nftnl_batch_is_supported()
Pablo Neira Ayuso
maintainerPATCH 1/1 examples: do not call nftnl_batch_is_supported()
This is only required by Linux kernel <= 3.16.x, that's too old and at that time nft was very limited in term of features, so let's remove this check from example files.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- examples/nft-chain-add.c | 19 ++++--------------- examples/nft-chain-del.c | 20 +++++--------------- examples/nft-chain-parse-add.c | 19 +++++-------------- examples/nft-flowtable-add.c | 19 ++++--------------- examples/nft-flowtable-del.c | 20 +++++--------------- examples/nft-map-add.c | 20 +++++--------------- examples/nft-rule-add.c | 20 +++++--------------- examples/nft-rule-del.c | 20 +++++--------------- examples/nft-rule-parse-add.c | 20 +++++--------------- examples/nft-ruleset-parse-file.c | 20 +++++--------------- examples/nft-set-add.c | 20 +++++--------------- examples/nft-set-parse-add.c | 19 +++++-------------- examples/nft-table-add.c | 20 +++++--------------- examples/nft-table-del.c | 20 +++++--------------- examples/nft-table-parse-add.c | 19 +++++-------------- examples/nft-table-upd.c | 20 +++++--------------- 16 files changed, 78 insertions(+), 237 deletions(-)
examples/nft-chain-add.c +4 -15
@@ -67,7 +67,6 @@ int main(int argc, char *argv[])int ret, family;struct nftnl_chain *t;struct mnl_nlmsg_batch *batch; -int batching;if (argc !=4 && argc !=6 ) { fprintf(stderr, "Usage: %s <family> <table> <chain> "
@@ -93,19 +92,11 @@ int main(int argc, char *argv[])if (t ==NULL )exit (EXIT_FAILURE ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); chain_seq = seq; nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
@@ -115,10 +106,8 @@ int main(int argc, char *argv[])nftnl_chain_free (t);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-chain-del.c +5 -15
@@ -44,7 +44,7 @@ int main(int argc, char *argv[])struct nlmsghdr *nlh;uint32_t portid, seq, chain_seq;struct nftnl_chain *t; -int ret, family, batching; +int ret, family;if (argc !=4 ) { fprintf(stderr, "Usage: %s <family> <table> <chain>\n",
@@ -69,19 +69,11 @@ int main(int argc, char *argv[])if (t ==NULL )exit (EXIT_FAILURE ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); chain_seq = seq; nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
@@ -91,10 +83,8 @@ int main(int argc, char *argv[])nftnl_chain_free (t);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-chain-parse-add.c +5 -14
@@ -77,8 +77,8 @@ int main(int argc, char *argv[])uint32_t portid, seq, chain_seq;struct nftnl_chain *c;uint16_t family, format, outformat; -int ret, batching;struct mnl_nlmsg_batch *batch; +int ret;if (argc <3 ) {printf ("Usage: %s {json} <file>\n" , argv[0 ]);
@@ -104,18 +104,11 @@ int main(int argc, char *argv[]) family =nftnl_chain_get_u32 (c,NFTNL_CHAIN_FAMILY ); seq =time (NULL ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); chain_seq = seq; nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
@@ -125,10 +118,8 @@ int main(int argc, char *argv[])nftnl_chain_free (c);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-flowtable-add.c +4 -15
@@ -47,7 +47,6 @@ int main(int argc, char *argv[])int ret, family;struct nftnl_flowtable *t;struct mnl_nlmsg_batch *batch; -int batching;if (argc !=6 ) { fprintf(stderr, "Usage: %s <family> <table> <name> <hook> <prio>\n",
@@ -72,19 +71,11 @@ int main(int argc, char *argv[])if (t ==NULL )exit (EXIT_FAILURE ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); flowtable_seq = seq; nlh = nftnl_flowtable_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
@@ -94,10 +85,8 @@ int main(int argc, char *argv[])nftnl_flowtable_free (t);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-flowtable-del.c +5 -15
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])struct nlmsghdr *nlh;uint32_t portid, seq, flowtable_seq;struct nftnl_flowtable *t; -int ret, family, batching; +int ret, family;if (argc !=4 ) { fprintf(stderr, "Usage: %s <family> <table> <flowtable>\n",
@@ -58,19 +58,11 @@ int main(int argc, char *argv[])if (t ==NULL )exit (EXIT_FAILURE ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); flowtable_seq = seq; nlh = nftnl_flowtable_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
@@ -80,10 +72,8 @@ int main(int argc, char *argv[])nftnl_flowtable_free (t);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-map-add.c +5 -15
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])uint8_t family;char buf[MNL_SOCKET_BUFFER_SIZE ];uint32_t seq =time (NULL ); -int ret, batching; +int ret;if (argc !=4 ) {fprintf (stderr,"Usage: %s <family> <table> <setname>\n" , argv[0 ]);
@@ -96,18 +96,10 @@ int main(int argc, char *argv[])exit (EXIT_FAILURE ); } - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +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_NEWSET, family,
@@ -117,10 +109,8 @@ int main(int argc, char *argv[])nftnl_set_free (s);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); ret =mnl_socket_sendto (nl,mnl_nlmsg_batch_head (batch),mnl_nlmsg_batch_size (batch));
examples/nft-rule-add.c +5 -15
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])uint8_t family;char buf[MNL_SOCKET_BUFFER_SIZE ];uint32_t seq =time (NULL ); -int ret, batching; +int ret;if (argc <4 || argc >5 ) {fprintf (stderr,"Usage: %s <family> <table> <chain>\n" , argv[0 ]);
@@ -158,18 +158,10 @@ int main(int argc, char *argv[])exit (EXIT_FAILURE ); } - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), NFT_MSG_NEWRULE,
@@ -180,10 +172,8 @@ int main(int argc, char *argv[])nftnl_rule_free (r);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); ret =mnl_socket_sendto (nl,mnl_nlmsg_batch_head (batch),mnl_nlmsg_batch_size (batch));
examples/nft-rule-del.c +5 -15
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])struct mnl_nlmsg_batch *batch;uint32_t portid, seq;struct nftnl_rule *r =NULL ; -int ret, batching, family; +int ret, family;if (argc <4 || argc >5 ) { fprintf(stderr, "Usage: %s <family> <table> <chain> [<handle>]\n",
@@ -65,18 +65,10 @@ int main(int argc, char *argv[])if (argc ==5 )nftnl_rule_set_u64 (r,NFTNL_RULE_HANDLE ,atoi (argv[4 ])); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), NFT_MSG_DELRULE,
@@ -87,10 +79,8 @@ int main(int argc, char *argv[])nftnl_rule_free (r);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-rule-parse-add.c +5 -15
@@ -80,7 +80,7 @@ int main(int argc, char *argv[])struct nlmsghdr *nlh;uint32_t portid, seq, rule_seq;struct nftnl_rule *r; -int ret, batching; +int ret;uint16_t family, format, outformat;if (argc <3 ) {
@@ -103,19 +103,11 @@ int main(int argc, char *argv[])nftnl_rule_fprintf (stdout, r, outformat,0 );fprintf (stdout,"\n" ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("Cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); rule_seq = seq; family =nftnl_rule_get_u32 (r,NFTNL_RULE_FAMILY );
@@ -127,10 +119,8 @@ int main(int argc, char *argv[])nftnl_rule_free (r);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-ruleset-parse-file.c +5 -15
@@ -379,7 +379,7 @@ int main(int argc, char *argv[])struct nftnl_parse_err *err;const char *filename;FILE *fp; -int ret =-1 , len, batching, portid; +int ret =-1 , len, portid;uint32_t ruleset_seq;char buf[MNL_SOCKET_BUFFER_SIZE ];struct mnl_socket *nl;
@@ -402,19 +402,11 @@ int main(int argc, char *argv[])exit (EXIT_FAILURE ); } - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("Cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); ruleset_seq = seq; filename = argv[1 ];
@@ -435,10 +427,8 @@ int main(int argc, char *argv[])fclose (fp); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-set-add.c +5 -15
@@ -59,7 +59,7 @@ int main(int argc, char *argv[])uint8_t family;char buf[MNL_SOCKET_BUFFER_SIZE ];uint32_t seq =time (NULL ); -int ret, batching; +int ret;if (argc !=4 ) {fprintf (stderr,"Usage: %s <family> <table> <setname>\n" , argv[0 ]);
@@ -92,18 +92,10 @@ int main(int argc, char *argv[])exit (EXIT_FAILURE ); } - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +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_NEWSET, family,
@@ -113,10 +105,8 @@ int main(int argc, char *argv[])nftnl_set_free (s);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); ret =mnl_socket_sendto (nl,mnl_nlmsg_batch_head (batch),mnl_nlmsg_batch_size (batch));
examples/nft-set-parse-add.c +5 -14
@@ -80,9 +80,9 @@ int main(int argc, char *argv[])struct nlmsghdr *nlh;uint32_t portid, seq, set_seq;struct nftnl_set *s; -int ret, batching;uint16_t family, format, outformat;struct mnl_nlmsg_batch *batch; +int ret;if (argc <2 ) {printf ("Usage: %s {json} <file>\n" , argv[0 ]);
@@ -105,18 +105,11 @@ int main(int argc, char *argv[])fprintf (stdout,"\n" ); seq =time (NULL ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); family =nftnl_set_get_u32 (s,NFTNL_SET_FAMILY );
@@ -128,10 +121,8 @@ int main(int argc, char *argv[])nftnl_set_free (s);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-table-add.c +5 -15
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])uint32_t portid, seq, table_seq, family;struct nftnl_table *t;struct mnl_nlmsg_batch *batch; -int ret, batching; +int ret;if (argc !=3 ) {fprintf (stderr,"%s <family> <name>\n" , argv[0 ]);
@@ -69,19 +69,11 @@ int main(int argc, char *argv[])if (t ==NULL )exit (EXIT_FAILURE ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); table_seq = seq; family =nftnl_table_get_u32 (t,NFTNL_TABLE_FAMILY );
@@ -92,10 +84,8 @@ int main(int argc, char *argv[])nftnl_table_free (t);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-table-del.c +5 -15
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])uint32_t portid, seq, table_seq, family;struct nftnl_table *t;struct mnl_nlmsg_batch *batch; -int ret, batching; +int ret;if (argc !=3 ) {fprintf (stderr,"%s <family> <name>\n" , argv[0 ]);
@@ -69,19 +69,11 @@ int main(int argc, char *argv[])if (t ==NULL )exit (EXIT_FAILURE ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); table_seq = seq; family =nftnl_table_get_u32 (t,NFTNL_TABLE_FAMILY );
@@ -92,10 +84,8 @@ int main(int argc, char *argv[])mnl_nlmsg_batch_next (batch);nftnl_table_free (t); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-table-parse-add.c +5 -14
@@ -75,9 +75,9 @@ int main(int argc, char *argv[])struct nlmsghdr *nlh;uint32_t portid, seq, table_seq;struct nftnl_table *t =NULL ; -int ret, batching;uint16_t family, format, outformat;struct mnl_nlmsg_batch *batch; +int ret;if (argc <3 ) {printf ("Usage: %s {json} <file>\n" , argv[0 ]);
@@ -100,18 +100,11 @@ int main(int argc, char *argv[])fprintf (stdout,"\n" ); seq =time (NULL ); - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch); family =nftnl_table_get_u32 (t,NFTNL_TABLE_FAMILY );
@@ -123,10 +116,8 @@ int main(int argc, char *argv[])nftnl_table_free (t);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
examples/nft-table-upd.c +5 -15
@@ -28,7 +28,7 @@ int main(int argc, char *argv[])uint32_t portid, seq, table_seq, family, flags;struct nftnl_table *t =NULL ;struct mnl_nlmsg_batch *batch; -int ret, batching; +int ret;if (argc !=4 ) {fprintf (stderr,"%s <family> <name> <state>\n" , argv[0 ]);
@@ -41,19 +41,11 @@ int main(int argc, char *argv[])exit (EXIT_FAILURE ); } - batching =nftnl_batch_is_supported (); -if (batching <0 ) { -perror ("cannot talk to nfnetlink" ); -exit (EXIT_FAILURE ); - } - seq =time (NULL ); batch =mnl_nlmsg_batch_start (buf,sizeof (buf)); -if (batching) { -nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); -mnl_nlmsg_batch_next (batch); - } +nftnl_batch_begin (mnl_nlmsg_batch_current (batch), seq++); +mnl_nlmsg_batch_next (batch);if (strcmp (argv[1 ],"ip" ) ==0 ) family =NFPROTO_IPV4 ;
@@ -91,10 +83,8 @@ int main(int argc, char *argv[])nftnl_table_free (t);mnl_nlmsg_batch_next (batch); -if (batching) { -nftnl_batch_end (mnl_nlmsg_batch_current (batch), seq++); -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 ) {
Signature · 1 line
2.11.0