Add these two new functions to set up netlink sockets in the global
context structure.

Signed-off-by: Pablo Neira Ayuso <[email protected]>
---
 src/main.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main.c b/src/main.c
index a891832ec5d6..fce9bfeca100 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;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to