From e0146fa254496dc12187053cd0cd6e5d20eb6a43 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sat, 8 Jul 2017 05:07:23 +0530 Subject: 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 Signed-off-by: Pablo Neira Ayuso --- src/cli.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/cli.c') 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 #include +#include + #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; -- cgit v1.2.3