summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2021-12-24 16:25:24 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2021-12-24 16:25:24 +0100
commit11219c63f4db1a803b5da4a2d308d3a5364d271f (patch)
treef56dc3f34a3f9a529cf5b1355ca923b1ca3cdbb0
parent1c3149ff21d44460a8a506abb22cad6d6c158cd3 (diff)
conntrack: use libmnl to create entry
Use libmnl to create entries through the new nfct_mnl_create() helper function. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/conntrack.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/conntrack.c b/src/conntrack.c
index 3f74fa1..fe604ff 100644
--- a/src/conntrack.c
+++ b/src/conntrack.c
@@ -2505,6 +2505,24 @@ nfct_mnl_get(uint16_t subsys, uint16_t type, mnl_cb_t cb, uint8_t family)
return nfct_mnl_talk(nlh, cb);
}
+static int
+nfct_mnl_create(uint16_t subsys, uint16_t type, const struct nf_conntrack *ct)
+{
+ char buf[MNL_SOCKET_BUFFER_SIZE];
+ struct nlmsghdr *nlh;
+ int err;
+
+ nlh = nfct_mnl_nlmsghdr_put(buf, subsys, type,
+ NLM_F_CREATE | NLM_F_ACK | NLM_F_EXCL,
+ nfct_get_attr_u8(ct, ATTR_ORIG_L3PROTO));
+
+ err = nfct_nlmsg_build(nlh, ct);
+ if (err < 0)
+ return err;
+
+ return nfct_mnl_talk(nlh, NULL, NULL);
+}
+
#define UNKNOWN_STATS_NUM 4
static int nfct_stats_attr_cb(const struct nlattr *attr, void *data)
@@ -3322,14 +3340,16 @@ 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: