diff mbox

[nft] src: netlink: Subscribe nft monitor and nft monitor trace to respective groups.

Message ID 5976d630.c553650a.2e876.31e8@mx.google.com
State Changes Requested
Delegated to: Pablo Neira
Headers show

Commit Message

Varsha Rao July 25, 2017, 5:25 a.m. UTC
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.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
---
 src/netlink.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Comments

Pablo Neira Ayuso July 25, 2017, 4:06 p.m. UTC | #1
Hi Varsha,

On Tue, Jul 25, 2017 at 10:55:00AM +0530, Varsha Rao wrote:
> 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.

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.

>+       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!
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/netlink.c b/src/netlink.c
index 9cef4c4..ccc13eb 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -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,