summaryrefslogtreecommitdiffstats
path: root/src/cli.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/cli.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/cli.c')
-rw-r--r--src/cli.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/cli.c b/src/cli.c
index 7cd2f45e..c1fdcf6c 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -31,6 +31,8 @@
#include <iface.h>
#include <cli.h>
+#include <libmnl/libmnl.h>
+
#define CMDLINE_HISTFILE ".nft.history"
static const struct input_descriptor indesc_cli = {
@@ -40,6 +42,7 @@ static const struct input_descriptor indesc_cli = {
static struct parser_state *state;
static struct nft_ctx cli_nft;
+static struct mnl_socket *cli_nf_sock;
static void *scanner;
static char histfile[PATH_MAX];
@@ -128,9 +131,9 @@ static void cli_complete(char *line)
xfree(line);
line = s;
- parser_init(state, &msgs);
+ parser_init(cli_nf_sock, state, &msgs);
scanner_push_buffer(scanner, &indesc_cli, line);
- nft_run(&cli_nft, scanner, state, &msgs);
+ nft_run(&cli_nft, cli_nf_sock, scanner, state, &msgs);
erec_print_list(stdout, &msgs);
xfree(line);
cache_release();
@@ -168,10 +171,12 @@ void __fmtstring(1, 0) cli_display(const char *fmt, va_list ap)
rl_forced_update_display();
}
-int cli_init(struct nft_ctx *nft, struct parser_state *_state)
+int cli_init(struct nft_ctx *nft, struct mnl_socket *nf_sock,
+ struct parser_state *_state)
{
const char *home;
+ cli_nf_sock = nf_sock;
cli_nft = *nft;
rl_readline_name = "nft";
rl_instream = stdin;