diff options
author | Arturo Borrero Gonzalez <arturo@netfilter.org> | 2017-07-12 13:29:49 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2017-07-17 17:20:34 +0200 |
commit | 8069b60a331141f00924f9fc9fad478badff6687 (patch) | |
tree | 7332aa9614911375e8c8ad84ddbddae845586a52 /src/netlink.c | |
parent | 30821c4d81ee3bd430030f69e9a838b8b4e8244d (diff) |
monitor: add debug messages
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>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/netlink.c')
-rw-r--r-- | src/netlink.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/netlink.c b/src/netlink.c index 8bf90b20..7355036b 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -2879,12 +2879,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))) |