From 033ec6be245261cd5e53e5a01435afea71ef6230 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Wed, 3 Jul 2013 13:06:22 +0200 Subject: conntrack: api: add nfct_snprintf_labels nfct_snprintf doesn't print connlabels, as they're system specific and can easily generate lots of output. This adds a new helper function, nfct_snprintf_labels. It behaves like nfct_snprintf, except that the label names in the labelmap whose bits are contained in connlabel attribute bitset are added to the buffer. output looks like this: output looks like this: ... mark=0 use=1 labels=eth0-in,eth1-in or Signed-off-by: Florian Westphal --- src/conntrack/api.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/conntrack/api.c') diff --git a/src/conntrack/api.c b/src/conntrack/api.c index b6c453f..cad860e 100644 --- a/src/conntrack/api.c +++ b/src/conntrack/api.c @@ -1071,13 +1071,38 @@ int nfct_snprintf(char *buf, const struct nf_conntrack *ct, unsigned int msg_type, unsigned int out_type, - unsigned int flags) + unsigned int flags) { assert(buf != NULL); assert(size > 0); assert(ct != NULL); - return __snprintf_conntrack(buf, size, ct, msg_type, out_type, flags); + return __snprintf_conntrack(buf, size, ct, msg_type, out_type, flags, NULL); +} + +/** + * nfct_snprintf_labels - print a bitmask object to a buffer including labels + * \param buf buffer used to build the printable conntrack + * \param size size of the buffer + * \param ct pointer to a valid conntrack object + * \param message_type print message type (NFCT_T_UNKNOWN, NFCT_T_NEW,...) + * \param output_type print type (NFCT_O_DEFAULT, NFCT_O_XML, ...) + * \param flags extra flags for the output type (NFCT_OF_LAYER3) + * \param map nfct_labelmap describing the connlabel translation, or NULL. + * + * When map is NULL, the function is equal to nfct_snprintf(). + * Otherwise, if the conntrack object has a connlabel attribute, the active + * labels are translated using the label map and added to the buffer. + */ +int nfct_snprintf_labels(char *buf, + unsigned int size, + const struct nf_conntrack *ct, + unsigned int msg_type, + unsigned int out_type, + unsigned int flags, + struct nfct_labelmap *map) +{ + return __snprintf_conntrack(buf, size, ct, msg_type, out_type, flags, map); } /** -- cgit v1.2.3