[libnftnl PATCH 1/5] expr: queue: Add nft_rule_expr_queue_snprinf_* functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Code refactoring in nft_rule_expr_queue_snprinf functions. This process
adds three new functions:

* nft_rule_expr_queue_snprinf_default
* nft_rule_expr_queue_snprinf_xml
* nft_rule_expr_queue_snprinf_json

Also, It is delete an unnecesary whitespace as the CodingStyle recommends.

Signed-off-by: Ana Rey <anarey@xxxxxxxxx>
---
 src/expr/queue.c | 82 +++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 51 insertions(+), 31 deletions(-)

diff --git a/src/expr/queue.c b/src/expr/queue.c
index 9f269e7..5dad84a 100644
--- a/src/expr/queue.c
+++ b/src/expr/queue.c
@@ -194,46 +194,66 @@ nft_rule_expr_queue_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree,
 #endif
 }
 
-static int
-nft_rule_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
-			      uint32_t flags, struct nft_rule_expr *e)
+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;
+		}
+		if (queue->flags & NFT_QUEUE_FLAG_CPU_FANOUT) {
+			if (one)
+				ret += snprintf(buf + ret, len - ret, ",");
+			ret += snprintf(buf + ret, len - ret, "fanout");
+		}
+	}
+	return ret;
+}
+
+static int nft_rule_expr_queue_snprintf_xml(char *buf, size_t len,
+					    struct nft_rule_expr *e)
+{
+	struct nft_expr_queue *queue = nft_expr_data(e);
+
+	return snprintf(buf, len, "<num>%u</num>"
+				  "<total>%u</total>"
+				  "<flags>%u</flags>",
+			queue->queuenum, queue->queues_total,
+			queue->flags);
+}
+
+static int nft_rule_expr_queue_snprintf_json(char *buf, size_t len,
+					     struct nft_rule_expr *e)
+{
+	struct nft_expr_queue *queue = nft_expr_data(e);
+
+	return snprintf(buf, len, "\"num\":%u,"
+				  "\"total\":%u,"
+				  "\"flags\":%u,",
+			queue->queuenum, queue->queues_total,
+			queue->flags);
+}
+
+static int
+nft_rule_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
+			      uint32_t flags, struct nft_rule_expr *e)
+{
+
 	switch(type) {
 	case NFT_OUTPUT_DEFAULT:
-		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;
-			}
-			if (queue->flags & NFT_QUEUE_FLAG_CPU_FANOUT) {
-				if (one)
-					ret += snprintf(buf + ret ,
-							len - ret, ",");
-				ret += snprintf(buf + ret ,
-						len - ret, "fanout");
-			}
-		}
-		return ret;
+		return nft_rule_expr_queue_snprintf_default(buf, len, e);
 	case NFT_OUTPUT_XML:
-		return snprintf(buf, len, "<num>%u</num>"
-					  "<total>%u</total>"
-					  "<flags>%u</flags>",
-				queue->queuenum, queue->queues_total,
-				queue->flags);
+		return nft_rule_expr_queue_snprintf_xml(buf, len, e);
 	case NFT_OUTPUT_JSON:
-		return snprintf(buf, len, "\"num\":%u,"
-					  "\"total\":%u,"
-					  "\"flags\":%u,",
-				queue->queuenum, queue->queues_total,
-				queue->flags);
+		return nft_rule_expr_queue_snprintf_json(buf, len, e);
 	default:
 		break;
 	}
-- 
2.0.0

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux