From: Ana Rey <anarey@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Ana Rey <anarey@gmail.com>
Subject: [libnftnl PATCH] expr: queue: Use snprintf and SNPRINTF_BUFFER_SIZE in snprintf_default functions.
Date: Mon, 16 Jun 2014 11:06:37 +0200 [thread overview]
Message-ID: <1402909598-24943-1-git-send-email-anarey@gmail.com> (raw)
Code refactoring to use snprintf and SNPRINTF_BUFFER_SIZE in
snprintf_default functions. Also, It adapts to the next syntax in queue
(Added in
http://git.netfilter.org/nftables/commit/?id=27619ffbe503ed4d9e59a02e81db9a7ac49d37af)
Here, some examples:
ip test input 31
[ queue num 3-5 bypass fanout]
ip test input 32 31
[ queue num 0]
ip test input 33 32
[ queue num 4]
ip test input 34 33
[ queue num 2-6 bypass]
table ip test {
chain input {
type filter hook input priority 0;
queue num 3-5 bypass fanout
queue num 0
queue num 4
queue num 2-6 bypass
}
}
Signed-off-by: Ana Rey <anarey@gmail.com>
---
src/expr/queue.c | 38 ++++++++++++++++++++++----------------
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/expr/queue.c b/src/expr/queue.c
index 78540b6..282dc8b 100644
--- a/src/expr/queue.c
+++ b/src/expr/queue.c
@@ -187,24 +187,31 @@ static int nft_rule_expr_queue_snprintf_default(char *buf, size_t len,
struct nft_rule_expr *e)
{
struct nft_expr_queue *queue = nft_expr_data(e);
- int ret;
- int one = 0;
-
- ret = snprintf(buf, len, "num %u total %u", queue->queuenum,
- queue->queues_total);
- if (queue->flags) {
- ret += snprintf(buf + ret, len - ret, " options ");
- if (queue->flags & NFT_QUEUE_FLAG_BYPASS) {
- ret += snprintf(buf + ret, len - ret, "bypass");
- one = 1;
+ int ret, size = len, offset = 0;
+ uint16_t total_queues;
+
+ total_queues = queue->queuenum + queue->queues_total -1;
+
+ ret = snprintf(buf + offset, len, "num %u", queue->queuenum);
+
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+
+ if (queue->queues_total && total_queues != queue->queuenum) {
+ ret = snprintf(buf + offset, len, "-%u", total_queues);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ }
+
+ if (e->flags & (1 << NFT_EXPR_QUEUE_FLAGS)) {
+ if (queue->flags & (NFT_QUEUE_FLAG_BYPASS)) {
+ ret = snprintf(buf + offset, len, " bypass");
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
- if (queue->flags & NFT_QUEUE_FLAG_CPU_FANOUT) {
- if (one)
- ret += snprintf(buf + ret, len - ret, ",");
- ret += snprintf(buf + ret, len - ret, "fanout");
+ if (queue->flags & (NFT_QUEUE_FLAG_CPU_FANOUT)) {
+ ret = snprintf(buf + offset, len, " fanout");
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
}
- return ret;
+ return offset;
}
static int nft_rule_expr_queue_snprintf_xml(char *buf, size_t len,
@@ -213,7 +220,6 @@ static int nft_rule_expr_queue_snprintf_xml(char *buf, size_t len,
int ret, size = len, offset = 0;
struct nft_expr_queue *queue = nft_expr_data(e);
-
if (e->flags & (1 << NFT_EXPR_QUEUE_NUM)) {
ret = snprintf(buf + offset, len, "<num>%u</num>",
queue->queuenum);
--
2.0.0
next reply other threads:[~2014-06-16 9:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-16 9:06 Ana Rey [this message]
2014-06-16 9:06 ` [libnftnl PATCH] tests: Add json and xml test file for queue Ana Rey
2014-06-16 10:17 ` Pablo Neira Ayuso
2014-06-16 10:15 ` [libnftnl PATCH] expr: queue: Use snprintf and SNPRINTF_BUFFER_SIZE in snprintf_default functions Pablo Neira Ayuso
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=1402909598-24943-1-git-send-email-anarey@gmail.com \
--to=anarey@gmail.com \
--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).