summaryrefslogtreecommitdiffstats
path: root/src/netlink.c
diff options
context:
space:
mode:
authorVarsha Rao <rvarsha016@gmail.com>2017-07-19 18:04:07 +0530
committerPablo Neira Ayuso <pablo@netfilter.org>2017-07-19 19:24:18 +0200
commit2b261897fa07006e8a46003f8448b69691555314 (patch)
tree0451c11348a48cb299f528f59b46fd965c5021bc /src/netlink.c
parent19cd540390e32f2e1f62e205ddb691d1e6e06152 (diff)
src: netlink: Remove variable nf_mon_sock.
Remove variable nf_mon_sock of type structure mnl_socket to avoid duplicity. Instead variable nf_sock of the same type is passed as argument to netlink_monitor(). Also remove netlink_open_mon_sock() function definition, which is no longer required. Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Varsha Rao <rvarsha016@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/netlink.c')
-rw-r--r--src/netlink.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/netlink.c b/src/netlink.c
index e3c90dac..a3453b96 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -39,8 +39,6 @@
#include <erec.h>
#include <iface.h>
-static struct mnl_socket *nf_mon_sock;
-
const struct input_descriptor indesc_netlink = {
.name = "netlink",
.type = INDESC_NETLINK,
@@ -73,8 +71,6 @@ void netlink_close_sock(struct mnl_socket *nf_sock)
{
if (nf_sock)
mnl_socket_close(nf_sock);
- if (nf_mon_sock)
- mnl_socket_close(nf_mon_sock);
}
void netlink_restart(struct mnl_socket *nf_sock)
@@ -88,11 +84,6 @@ void netlink_genid_get(struct mnl_socket *nf_sock)
mnl_genid_get(nf_sock);
}
-static void netlink_open_mon_sock(void)
-{
- nf_mon_sock = nfsock_open();
-}
-
void __noreturn __netlink_abi_error(const char *file, int line,
const char *reason)
{
@@ -2961,18 +2952,26 @@ static int netlink_events_cb(const struct nlmsghdr *nlh, void *data)
return ret;
}
-int netlink_monitor(struct netlink_mon_handler *monhandler)
+int netlink_monitor(struct netlink_mon_handler *monhandler,
+ struct mnl_socket *nf_sock)
{
- netlink_open_mon_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,
+ "Could not bind to netlink socket %s",
+ strerror(errno));
- if (mnl_socket_bind(nf_mon_sock, (1 << (NFNLGRP_NFTABLES-1)) |
- (1 << (NFNLGRP_NFTRACE-1)),
- MNL_SOCKET_AUTOPID) < 0)
+ group = NFNLGRP_NFTRACE;
+ 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_mon_sock, netlink_events_cb,
+ return mnl_nft_event_listener(nf_sock, netlink_events_cb,
monhandler);
}