summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2017-07-19 16:32:57 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2017-07-24 20:23:02 +0200
commite8f4fdb0097769cab0c1f7b56f610d05dbae43bc (patch)
treedafba1fbe74aeddc9e2e05c6e4715f3dca86d1b8
parentabd40b25d2ed413994e19699425964115ef49aa5 (diff)
monitor: Print NEWGEN events
Now that they contain process information, they're actually interesting. For backwards compatibility, print process information only if it was present in the message. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/linux/netfilter/nf_tables.h2
-rw-r--r--src/netlink.c42
2 files changed, 44 insertions, 0 deletions
diff --git a/include/linux/netfilter/nf_tables.h b/include/linux/netfilter/nf_tables.h
index 683f6f88..40096de0 100644
--- a/include/linux/netfilter/nf_tables.h
+++ b/include/linux/netfilter/nf_tables.h
@@ -1221,6 +1221,8 @@ enum nft_objref_attributes {
enum nft_gen_attributes {
NFTA_GEN_UNSPEC,
NFTA_GEN_ID,
+ NFTA_GEN_PROC_ID,
+ NFTA_GEN_PROC_NAME,
__NFTA_GEN_MAX
};
#define NFTA_GEN_MAX (__NFTA_GEN_MAX - 1)
diff --git a/src/netlink.c b/src/netlink.c
index 2c472273..9cef4c48 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -2987,6 +2987,45 @@ static void netlink_events_debug(uint16_t type)
#endif /* DEBUG */
}
+static int netlink_events_newgen_cb(const struct nlmsghdr *nlh, int type,
+ struct netlink_mon_handler *monh)
+{
+ const struct nlattr *attr;
+ char name[256] = "";
+ int genid = -1, pid = -1;
+
+ mnl_attr_for_each(attr, nlh, sizeof(struct nfgenmsg)) {
+ switch (mnl_attr_get_type(attr)) {
+ case NFTA_GEN_ID:
+ if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
+ break;
+ genid = ntohl(mnl_attr_get_u32(attr));
+ break;
+ case NFTA_GEN_PROC_NAME:
+ if (mnl_attr_validate(attr, MNL_TYPE_NUL_STRING) < 0)
+ break;
+ strncpy(name, mnl_attr_get_str(attr), sizeof(name));
+ break;
+ case NFTA_GEN_PROC_ID:
+ if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0)
+ break;
+ pid = ntohl(mnl_attr_get_u32(attr));
+ break;
+ }
+ }
+ if (genid >= 0) {
+ printf("# new generation %d", genid);
+ if (pid >= 0) {
+ printf(" by process %d", pid);
+ if (!monh->ctx->octx->numeric)
+ printf(" (%s)", name);
+ }
+ printf("\n");
+ }
+
+ return MNL_CB_OK;
+}
+
static int netlink_events_cb(const struct nlmsghdr *nlh, void *data)
{
int ret = MNL_CB_OK;
@@ -3027,6 +3066,9 @@ static int netlink_events_cb(const struct nlmsghdr *nlh, void *data)
case NFT_MSG_DELOBJ:
ret = netlink_events_obj_cb(nlh, type, monh);
break;
+ case NFT_MSG_NEWGEN:
+ ret = netlink_events_newgen_cb(nlh, type, monh);
+ break;
}
fflush(stdout);