netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nft PATCH] monitor: add debug messages
@ 2017-07-12 11:29 Arturo Borrero Gonzalez
  2017-07-17 15:24 ` Pablo Neira Ayuso
  2017-07-17 15:26 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Arturo Borrero Gonzalez @ 2017-07-12 11:29 UTC (permalink / raw)
  To: netfilter-devel

Add some debug messages in the monitor/trace code paths to ease development
and debugging in case of errors.

After this patch, running 'nft monitor --debug=mnl,netlink' is more verbose.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
---
 src/mnl.c     |    7 +++++++
 src/netlink.c |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/mnl.c b/src/mnl.c
index da7c090..cf060a4 100644
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -1139,6 +1139,13 @@ int mnl_nft_event_listener(struct mnl_socket *nf_sock,
 			fprintf(stdout, "# ERROR: %s\n", strerror(errno));
 			break;
 		}
+
+#ifdef DEBUG
+		if (debug_level & DEBUG_MNL) {
+			mnl_nlmsg_fprintf(stdout, buf, sizeof(buf),
+					  sizeof(struct nfgenmsg));
+		}
+#endif /* DEBUG */
 		ret = mnl_cb_run(buf, ret, 0, 0, cb, cb_data);
 		if (ret <= 0)
 			break;
diff --git a/src/netlink.c b/src/netlink.c
index 880502c..50ed25f 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -2877,12 +2877,51 @@ static int netlink_events_trace_cb(const struct nlmsghdr *nlh, int type,
 	return MNL_CB_OK;
 }
 
+#ifdef DEBUG
+/* only those which could be useful listening to events */
+static const char *const nftnl_msg_types[NFT_MSG_MAX] = {
+	[NFT_MSG_NEWTABLE]	= "NFT_MSG_NEWTABLE",
+	[NFT_MSG_DELTABLE]	= "NFT_MSG_DELTABLE",
+	[NFT_MSG_NEWCHAIN]	= "NFT_MSG_NEWCHAIN",
+	[NFT_MSG_DELCHAIN]	= "NFT_MSG_DELCHAIN",
+	[NFT_MSG_NEWSET]	= "NFT_MSG_NEWSET",
+	[NFT_MSG_DELSET]	= "NFT_MSG_DELSET",
+	[NFT_MSG_NEWSETELEM]	= "NFT_MSG_NEWSETELEM",
+	[NFT_MSG_DELSETELEM]	= "NFT_MSG_DELSETELEM",
+	[NFT_MSG_NEWRULE]	= "NFT_MSG_NEWRULE",
+	[NFT_MSG_DELRULE]	= "NFT_MSG_DELRULE",
+	[NFT_MSG_TRACE]		= "NFT_MSG_TRACE",
+	[NFT_MSG_NEWGEN]	= "NFT_MSG_NEWGEN",
+	[NFT_MSG_NEWOBJ]	= "NFT_MSG_NEWOBJ",
+	[NFT_MSG_DELOBJ]	= "NFT_MSG_DELOBJ",
+};
+
+static const char *nftnl_msgtype2str(uint16_t type)
+{
+	if (type >= NFT_MSG_MAX || !nftnl_msg_types[type])
+		return "unknown";
+
+	return nftnl_msg_types[type];
+}
+#endif /* DEBUG */
+
+static void netlink_events_debug(uint16_t type)
+{
+#ifdef DEBUG
+	if (!(debug_level & DEBUG_NETLINK))
+		return;
+
+	printf("netlink event: %s\n", nftnl_msgtype2str(type));
+#endif /* DEBUG */
+}
+
 static int netlink_events_cb(const struct nlmsghdr *nlh, void *data)
 {
 	int ret = MNL_CB_OK;
 	uint16_t type = NFNL_MSG_TYPE(nlh->nlmsg_type);
 	struct netlink_mon_handler *monh = (struct netlink_mon_handler *)data;
 
+	netlink_events_debug(type);
 	netlink_events_cache_update(monh, nlh, type);
 
 	if (!(monh->monitor_flags & (1 << type)))


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [nft PATCH] monitor: add debug messages
  2017-07-12 11:29 [nft PATCH] monitor: add debug messages Arturo Borrero Gonzalez
@ 2017-07-17 15:24 ` Pablo Neira Ayuso
  2017-07-17 15:26 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-07-17 15:24 UTC (permalink / raw)
  To: Arturo Borrero Gonzalez; +Cc: netfilter-devel

On Wed, Jul 12, 2017 at 01:29:49PM +0200, Arturo Borrero Gonzalez wrote:
> Add some debug messages in the monitor/trace code paths to ease development
> and debugging in case of errors.
> 
> After this patch, running 'nft monitor --debug=mnl,netlink' is more verbose.

Applied, thanks Arturo.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [nft PATCH] monitor: add debug messages
  2017-07-12 11:29 [nft PATCH] monitor: add debug messages Arturo Borrero Gonzalez
  2017-07-17 15:24 ` Pablo Neira Ayuso
@ 2017-07-17 15:26 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-07-17 15:26 UTC (permalink / raw)
  To: Arturo Borrero Gonzalez; +Cc: netfilter-devel

On Wed, Jul 12, 2017 at 01:29:49PM +0200, Arturo Borrero Gonzalez wrote:
> Add some debug messages in the monitor/trace code paths to ease development
> and debugging in case of errors.
> 
> After this patch, running 'nft monitor --debug=mnl,netlink' is more verbose.

Applied, thanks Arturo.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-17 15:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-12 11:29 [nft PATCH] monitor: add debug messages Arturo Borrero Gonzalez
2017-07-17 15:24 ` Pablo Neira Ayuso
2017-07-17 15:26 ` 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).