summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2017-07-08 05:07:23 +0530
committerPablo Neira Ayuso <pablo@netfilter.org>2017-07-17 14:26:30 +0200
commite0146fa254496dc12187053cd0cd6e5d20eb6a43 (patch)
treee41f1d9b9ae20849fe281cf14c97e817c194b68a /src/rule.c
parentf63405f9203ce7a8464d585ad49ea67fb2c0bb3f (diff)
include: Pass nf_sock where needed as parameter
This socket should not be global, it is also hidden in many layers of code. Expose it as function parameters to decouple the netlink socket handling logic from the command parsing, evaluation and bytecode generation. Joint work with Varsha Rao. Signed-off-by: Varsha Rao <rvarsha016@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/rule.c b/src/rule.c
index ee510fe0..b0b64ffe 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -122,7 +122,8 @@ static int cache_init_objects(struct netlink_ctx *ctx, enum cmd_ops cmd)
return 0;
}
-static int cache_init(enum cmd_ops cmd, struct list_head *msgs)
+static int cache_init(struct mnl_socket *nf_sock, enum cmd_ops cmd,
+ struct list_head *msgs)
{
struct handle handle = {
.family = NFPROTO_UNSPEC,
@@ -132,6 +133,7 @@ static int cache_init(enum cmd_ops cmd, struct list_head *msgs)
memset(&ctx, 0, sizeof(ctx));
init_list_head(&ctx.list);
+ ctx.nf_sock = nf_sock;
ctx.msgs = msgs;
ret = cache_init_tables(&ctx, &handle);
@@ -146,19 +148,20 @@ static int cache_init(enum cmd_ops cmd, struct list_head *msgs)
static bool cache_initialized;
-int cache_update(enum cmd_ops cmd, struct list_head *msgs)
+int cache_update(struct mnl_socket *nf_sock, enum cmd_ops cmd,
+ struct list_head *msgs)
{
int ret;
if (cache_initialized)
return 0;
replay:
- netlink_genid_get();
- ret = cache_init(cmd, msgs);
+ netlink_genid_get(nf_sock);
+ ret = cache_init(nf_sock, cmd, msgs);
if (ret < 0) {
cache_release();
if (errno == EINTR) {
- netlink_restart();
+ netlink_restart(nf_sock);
goto replay;
}
return -1;