From: Varsha Rao <rvarsha016@gmail.com>
To: pablo@netfilter.org, netfilter-devel@vger.kernel.org
Subject: [PATCH nft v2] src: netlink: Subscribe nft monitor and nft monitor trace to respective groups.
Date: Fri, 28 Jul 2017 10:55:21 +0530 [thread overview]
Message-ID: <597acac5.1dc8620a.5a708.5f17@mx.google.com> (raw)
Subscribe nft monitor to both NFNLGRP_NFTABLES and NFNLGRP_NFTRACE.
nft monitor trace subscribes only to NFNLGRP_NFTRACE. Other event
reporting options to only NFNLGRP_NFTABLES.
Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
---
Changes in v1:
- Subscribe nft monitor to only _NFTABLES.
- Subsribe nft monitor trace to only _NFTRACE.
Changes in v2:
- Subsribe nft monitor to both _NFTABLES and _NFTRACE.
- Subscribe other events to _NFTABLES.
- Modified commit message.
src/netlink.c | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/src/netlink.c b/src/netlink.c
index 9cef4c4..f7069fd 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -3078,21 +3078,34 @@ static int netlink_events_cb(const struct nlmsghdr *nlh, void *data)
int netlink_monitor(struct netlink_mon_handler *monhandler,
struct mnl_socket *nf_sock)
{
- 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,
+ int group = NFNLGRP_NFTRACE, val;
+
+ val = monhandler->monitor_flags | NFNLGRP_NFTABLES;
+ if (val == 131439) {
+ 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));
-
- group = NFNLGRP_NFTRACE;
- if (mnl_socket_setsockopt(nf_sock, NETLINK_ADD_MEMBERSHIP, &group,
- sizeof(int)) < 0)
- return netlink_io_error(monhandler->ctx, monhandler->loc,
+ } else {
+ if (val < 0) {
+ 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));
+ }
+ 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));
+ }
return mnl_nft_event_listener(nf_sock, netlink_events_cb,
monhandler);
--
2.9.4
next reply other threads:[~2017-07-28 5:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-28 5:25 Varsha Rao [this message]
2017-07-28 15:36 ` [PATCH nft v2] src: netlink: Subscribe nft monitor and nft monitor trace to respective groups Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=597acac5.1dc8620a.5a708.5f17@mx.google.com \
--to=rvarsha016@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).