[PATCH 2/6] conntrack: use libmnl for conntrack entry creation

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

 



Use libmnl and libnetfilter_conntrack mnl helpers to create the conntrack
table entries.

Signed-off-by: Mikhail Sennikovsky <mikhail.sennikovskii@xxxxxxxxx>
---
 src/conntrack.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/conntrack.c b/src/conntrack.c
index d37f130..f042d9d 100644
--- a/src/conntrack.c
+++ b/src/conntrack.c
@@ -2504,6 +2504,16 @@ nfct_mnl_get(uint16_t subsys, uint16_t type, mnl_cb_t cb, uint8_t family)
 		      cb, NULL);
 }
 
+static int
+nfct_mnl_create(uint16_t subsys, uint16_t type, const struct nf_conntrack *ct)
+{
+	return nfct_mnl_call(subsys, type,
+		      NLM_F_REQUEST|NLM_F_CREATE|NLM_F_ACK|NLM_F_EXCL,
+		      ct, 0,
+		      NULL,
+		      NULL, NULL);
+}
+
 #define UNKNOWN_STATS_NUM 4
 
 static int nfct_stats_attr_cb(const struct nlattr *attr, void *data)
@@ -3321,14 +3331,17 @@ static int do_command_ct(const char *progname, struct ct_cmd *cmd)
 			nfct_set_attr(cmd->tmpl.ct, ATTR_CONNLABELS,
 					xnfct_bitmask_clone(cmd->tmpl.label_modify));
 
-		cth = nfct_open(CONNTRACK, 0);
-		if (!cth)
-			exit_error(OTHER_PROBLEM, "Can't open handler");
+		res = nfct_mnl_socket_open(0);
+		if (res < 0)
+			exit_error(OTHER_PROBLEM, "Can't open netlink socket");
 
-		res = nfct_query(cth, NFCT_Q_CREATE, cmd->tmpl.ct);
-		if (res != -1)
+		res = nfct_mnl_create(NFNL_SUBSYS_CTNETLINK,
+							IPCTNL_MSG_CT_NEW,
+							cmd->tmpl.ct);
+		if (res >= 0)
 			counter++;
-		nfct_close(cth);
+
+		nfct_mnl_socket_close();
 		break;
 
 	case EXP_CREATE:
-- 
2.25.1




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux