src: netlink: Subscribe nft monitor and nft monitor trace to respective groups.
PATCH 1/1 src: netlink: Subscribe nft monitor and nft monitor trace to respective groups.
Subscribe nft monitor only to NFNLGRP_NFTABLES and nft monitor trace only to NFNLGRP_NFTRACE. In netlink_monitor() depending on the command call setsockopt() once.
--- src/netlink.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
src/netlink.c +4 -7
@@ -3080,14 +3080,11 @@ int netlink_monitor(struct netlink_mon_handler *monhandler, {int group; - group =NFNLGRP_NFTABLES ; -if (mnl_socket_setsockopt (nf_sock,NETLINK_ADD_MEMBERSHIP , &group, -sizeof (int )) <0 ) -return netlink_io_error (monhandler->ctx, monhandler->loc, -"Could not bind to netlink socket %s" , -strerror (errno)); +if (monhandler->monitor_flags == (unsigned int )-1 ) + group =NFNLGRP_NFTABLES ; +else + group =NFNLGRP_NFTRACE ; - group =NFNLGRP_NFTRACE ;if (mnl_socket_setsockopt (nf_sock,NETLINK_ADD_MEMBERSHIP , &group,sizeof (int )) <0 ) return netlink_io_error(monhandler->ctx, monhandler->loc,
Signature · 1 line
2.9.4
Pablo Neira Ayuso
maintainerHi Varsha,
Quoted 3 lines · Varsha Rao
Subscribe nft monitor only to
NFNLGRP_NFTABLESand nft monitor trace only toNFNLGRP_NFTRACE. Innetlink_monitor()depending on the command callsetsockopt()once.
Could you enhance this patch in a way that things work like the following:
#1 nft monitor
This prints all events, both nftrace and nftables.
#2 nft monitor trace
This prints only trace events.
#3 nft monitor ruleset
This prints only ruleset events.
for #3, you have to extend the bison parser I think, it should be not too complicated.
Quoted 1 line
+ if (
monhandler->monitor_flags== (unsigned int)-1)
I think there must be a way to make this more readable, as well as make it work in the way I propose above.
Thanks!