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/snprintf_xml.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/conntrack/snprintf_xml.c') diff --git a/src/conntrack/snprintf_xml.c b/src/conntrack/snprintf_xml.c index ad53075..37f51b4 100644 --- a/src/conntrack/snprintf_xml.c +++ b/src/conntrack/snprintf_xml.c @@ -348,11 +348,35 @@ static int __snprintf_tuple_xml(char *buf, return size; } +static int +__snprintf_clabels_xml(char *buf, unsigned int len, + const struct nf_conntrack *ct, struct nfct_labelmap *map) +{ + const struct nfct_bitmask *b = nfct_get_attr(ct, ATTR_CONNLABELS); + int ret, size = 0, offset = 0; + + if (!b) + return 0; + + ret = snprintf(buf, len, ""); + BUFFER_SIZE(ret, size, len, offset); + + ret = __snprintf_connlabels(buf + offset, len, map, b, ""); + + BUFFER_SIZE(ret, size, len, offset); + + ret = snprintf(buf + offset, len, ""); + BUFFER_SIZE(ret, size, len, offset); + + return size; +} + int __snprintf_conntrack_xml(char *buf, unsigned int len, const struct nf_conntrack *ct, const unsigned int msg_type, - const unsigned int flags) + const unsigned int flags, + struct nfct_labelmap *map) { int ret = 0; unsigned int size = 0, offset = 0; @@ -390,6 +414,7 @@ int __snprintf_conntrack_xml(char *buf, test_bit(ATTR_USE, ct->head.set) || test_bit(ATTR_STATUS, ct->head.set) || test_bit(ATTR_ID, ct->head.set) || + test_bit(ATTR_CONNLABELS, ct->head.set) || test_bit(ATTR_TIMESTAMP_START, ct->head.set) || test_bit(ATTR_TIMESTAMP_STOP, ct->head.set)) { ret = snprintf(buf+offset, len, @@ -432,6 +457,11 @@ int __snprintf_conntrack_xml(char *buf, BUFFER_SIZE(ret, size, len, offset); } + if (map && test_bit(ATTR_CONNLABELS, ct->head.set)) { + ret = __snprintf_clabels_xml(buf+offset, len, ct, map); + BUFFER_SIZE(ret, size, len, offset); + } + if (test_bit(ATTR_SECMARK, ct->head.set)) { ret = snprintf(buf+offset, len, "%u", ct->secmark); @@ -510,6 +540,7 @@ int __snprintf_conntrack_xml(char *buf, test_bit(ATTR_USE, ct->head.set) || test_bit(ATTR_STATUS, ct->head.set) || test_bit(ATTR_ID, ct->head.set) || + test_bit(ATTR_CONNLABELS, ct->head.set) || test_bit(ATTR_TIMESTAMP_START, ct->head.set) || test_bit(ATTR_TIMESTAMP_STOP, ct->head.set)) { ret = snprintf(buf+offset, len, ""); -- cgit v1.2.3