summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2017-09-01 12:00:21 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2017-09-01 12:08:42 +0200
commit4b8cfe020c9adc71dad857106b915aae01348df4 (patch)
tree3b182517300c0b8a42d43b60c5d6ae08dcc2afbe
parent5e22cfb19a60f09d7e9825f6e68ac7036769aa56 (diff)
src: add nft_ctx_netlink_init()
Add these two new functions to set up netlink sockets in the global context structure. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/main.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index a891832e..fce9bfec 100644
--- a/src/main.c
+++ b/src/main.c
@@ -298,12 +298,20 @@ static struct nft_ctx *nft_ctx_new(void)
static void nft_ctx_free(const struct nft_ctx *ctx)
{
+ if (ctx->nf_sock)
+ netlink_close_sock(ctx->nf_sock);
+
iface_cache_release();
cache_release(&nft->cache);
xfree(ctx);
nft_exit();
}
+static void nft_ctx_netlink_init(struct nft_ctx *ctx)
+{
+ ctx->nf_sock = netlink_open_sock();
+}
+
static int nft_run_cmd_from_buffer(struct nft_ctx *nft,
char *buf, size_t buflen)
{
@@ -361,7 +369,8 @@ int main(int argc, char * const *argv)
nft = nft_ctx_new();
- nft->nf_sock = netlink_open_sock();
+ nft_ctx_netlink_init(nft);
+
while (1) {
val = getopt_long(argc, argv, OPTSTRING, options, NULL);
if (val == -1)
@@ -472,7 +481,6 @@ int main(int argc, char * const *argv)
}
xfree(buf);
- netlink_close_sock(nft->nf_sock);
nft_ctx_free(nft);
return rc;