netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH conntrack-tools 2/2] conntrack: update CT_GET to use libmnl
Date: Mon, 13 Jun 2022 19:27:59 +0200	[thread overview]
Message-ID: <20220613172759.232211-2-pablo@netfilter.org> (raw)
In-Reply-To: <20220613172759.232211-1-pablo@netfilter.org>

Use nfct_mnl_request() to build and send the netlink command. Remove
dump_cb() since this is a copy of the new libmnl's mnl_nfct_dump_cb()
callback function.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/conntrack.c | 51 +++----------------------------------------------
 1 file changed, 3 insertions(+), 48 deletions(-)

diff --git a/src/conntrack.c b/src/conntrack.c
index 615aa01ed6be..82534ec9fb02 100644
--- a/src/conntrack.c
+++ b/src/conntrack.c
@@ -1996,47 +1996,6 @@ out:
 	return MNL_CB_OK;
 }
 
-static int dump_cb(enum nf_conntrack_msg_type type,
-		   struct nf_conntrack *ct,
-		   void *data)
-{
-	unsigned int op_type = NFCT_O_DEFAULT;
-	unsigned int op_flags = 0;
-	struct ct_cmd *cmd = data;
-	char buf[1024];
-
-	if (nfct_filter(cmd, ct, cur_tmpl))
-		return NFCT_CB_CONTINUE;
-
-	if (output_mask & _O_SAVE) {
-		ct_save_snprintf(buf, sizeof(buf), ct, labelmap, NFCT_T_NEW);
-		goto done;
-	}
-
-	if (output_mask & _O_XML) {
-		op_type = NFCT_O_XML;
-		if (dump_xml_header_done) {
-			dump_xml_header_done = 0;
-			printf("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
-			       "<conntrack>\n");
-		}
-	}
-	if (output_mask & _O_EXT)
-		op_flags = NFCT_OF_SHOW_LAYER3;
-	if (output_mask & _O_KTMS)
-		op_flags |= NFCT_OF_TIMESTAMP;
-	if (output_mask & _O_ID)
-		op_flags |= NFCT_OF_ID;
-
-	nfct_snprintf_labels(buf, sizeof(buf), ct, NFCT_T_UNKNOWN, op_type, op_flags, labelmap);
-done:
-	printf("%s\n", buf);
-
-	counter++;
-
-	return NFCT_CB_CONTINUE;
-}
-
 static int nfct_mnl_request(struct nfct_mnl_socket *sock, uint16_t subsys,
 			    int family, uint16_t type, uint16_t flags,
 			    mnl_cb_t cb, const struct nf_conntrack *ct,
@@ -3451,13 +3410,9 @@ static int do_command_ct(const char *progname, struct ct_cmd *cmd,
 		break;
 
 	case CT_GET:
-		cth = nfct_open(CONNTRACK, 0);
-		if (!cth)
-			exit_error(OTHER_PROBLEM, "Can't open handler");
-
-		nfct_callback_register(cth, NFCT_T_ALL, dump_cb, cmd);
-		res = nfct_query(cth, NFCT_Q_GET, cmd->tmpl.ct);
-		nfct_close(cth);
+		res = nfct_mnl_request(sock, NFNL_SUBSYS_CTNETLINK, cmd->family,
+				       IPCTNL_MSG_CT_GET, NLM_F_ACK,
+				       mnl_nfct_dump_cb, cmd->tmpl.ct, cmd);
 		break;
 
 	case EXP_GET:
-- 
2.30.2


      reply	other threads:[~2022-06-13 19:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13 17:27 [PATCH conntrack-tools 1/2] conntrack: pass command object to nfct_mnl_request() Pablo Neira Ayuso
2022-06-13 17:27 ` Pablo Neira Ayuso [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220613172759.232211-2-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).