Code refactoring in nft_rule_expr_limit_snprinf functions. This process adds three new functions: * nft_rule_expr_limit_snprinf_default * nft_rule_expr_limit_snprinf_xml * nft_rule_expr_limit_snprinf_json Signed-off-by: Ana Rey <anarey@xxxxxxxxx> --- src/expr/limit.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/expr/limit.c b/src/expr/limit.c index 7d10340..b7cd32d 100644 --- a/src/expr/limit.c +++ b/src/expr/limit.c @@ -181,24 +181,44 @@ static const char *get_unit(uint64_t u) return "error"; } +static int nft_rule_expr_limit_snprintf_xml(char *buf, size_t len, + struct nft_rule_expr *e) { + struct nft_expr_limit *limit = nft_expr_data(e); + + return snprintf(buf, len, "<rate>%"PRIu64"</rate>" + "<unit>%"PRIu64"</unit>", + limit->rate, limit->unit); +} + +static int nft_rule_expr_limit_snprintf_json(char *buf, size_t len, + struct nft_rule_expr *e) { + struct nft_expr_limit *limit = nft_expr_data(e); + + return snprintf(buf, len, "\"rate\":%"PRIu64"," + "\"unit\":%"PRIu64"", + limit->rate, limit->unit); +} + +static int nft_rule_expr_limit_snprintf_default(char *buf, size_t len, + struct nft_rule_expr *e) { + struct nft_expr_limit *limit = nft_expr_data(e); + + return snprintf(buf, len, "rate %"PRIu64"/%s ", + limit->rate, get_unit(limit->unit)); +} + static int nft_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, struct nft_rule_expr *e) { - struct nft_expr_limit *limit = nft_expr_data(e); switch(type) { case NFT_OUTPUT_DEFAULT: - return snprintf(buf, len, "rate %"PRIu64"/%s ", - limit->rate, get_unit(limit->unit)); + return nft_rule_expr_limit_snprintf_default(buf, len, e); case NFT_OUTPUT_XML: - return snprintf(buf, len, "<rate>%"PRIu64"</rate>" - "<unit>%"PRIu64"</unit>", - limit->rate, limit->unit); + return nft_rule_expr_limit_snprintf_xml(buf, len, e); case NFT_OUTPUT_JSON: - return snprintf(buf, len, "\"rate\":%"PRIu64"," - "\"unit\":%"PRIu64"", - limit->rate, limit->unit); + return nft_rule_expr_limit_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