[PATCH nft 3/3] src: add nft_ctx_netlink_init()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
---
 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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux