Use libmnl and libnetfilter_conntrack mnl helpers to flush the conntrack table entries. Signed-off-by: Mikhail Sennikovsky <mikhail.sennikovskii@xxxxxxxxx> --- src/conntrack.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/conntrack.c b/src/conntrack.c index de5c051..3498071 100644 --- a/src/conntrack.c +++ b/src/conntrack.c @@ -2411,6 +2411,17 @@ nfct_mnl_print(struct nfct_mnl_socket *socket, cb, NULL); } +static int +nfct_mnl_flush(struct nfct_mnl_socket *socket, + uint16_t subsys, uint16_t type, uint8_t family) +{ + return nfct_mnl_call(socket, subsys, type, + NLM_F_REQUEST|NLM_F_ACK, + NULL, family, + NULL, + NULL, NULL); +} + #define UNKNOWN_STATS_NUM 4 static int nfct_stats_attr_cb(const struct nlattr *attr, void *data) @@ -3496,11 +3507,15 @@ static int do_command_ct(const char *progname, struct ct_cmd *cmd) break; case CT_FLUSH: - cth = nfct_open(CONNTRACK, 0); - if (!cth) - exit_error(OTHER_PROBLEM, "Can't open handler"); - res = nfct_query(cth, NFCT_Q_FLUSH_FILTER, &cmd->family); - nfct_close(cth); + res = nfct_mnl_socket_open(&sock, 0); + if (res < 0) + exit_error(OTHER_PROBLEM, "Can't open netlink socket"); + + res = nfct_mnl_flush(&sock, + NFNL_SUBSYS_CTNETLINK, + IPCTNL_MSG_CT_DELETE, + cmd->family); + nfct_mnl_socket_close(&sock); fprintf(stderr, "%s v%s (conntrack-tools): ",PROGNAME,VERSION); fprintf(stderr,"connection tracking table has been emptied.\n"); break; -- 2.25.1