[libnftnl PATCH 3/3] expr: immediate: Do not print unset values in xml file

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

 



It changes the parse functions to omit unset values.

Signed-off-by: Ana Rey <anarey@xxxxxxxxx>
---
 src/expr/immediate.c | 44 +++++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/src/expr/immediate.c b/src/expr/immediate.c
index b52bd23..af3324b 100644
--- a/src/expr/immediate.c
+++ b/src/expr/immediate.c
@@ -223,24 +223,25 @@ nft_rule_expr_immediate_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree,
 	uint32_t reg;
 
 	if (nft_mxml_reg_parse(tree, "dreg", &reg, MXML_DESCEND_FIRST,
-			       NFT_XML_MAND, err) != 0)
-		return -1;
-	nft_rule_expr_set_u32(e, NFT_EXPR_IMM_DREG, reg);
+			       NFT_XML_MAND, err) == 0)
+		nft_rule_expr_set_u32(e, NFT_EXPR_IMM_DREG, reg);
 
 	datareg_type = nft_mxml_data_reg_parse(tree, "immediatedata",
 					       &imm->data, NFT_XML_MAND, err);
-	switch (datareg_type) {
-	case DATA_VALUE:
-		e->flags |= (1 << NFT_EXPR_IMM_DATA);
-		break;
-	case DATA_VERDICT:
-		e->flags |= (1 << NFT_EXPR_IMM_VERDICT);
-		break;
-	case DATA_CHAIN:
-		e->flags |= (1 << NFT_EXPR_IMM_CHAIN);
-		break;
-	default:
-		return -1;
+	if (datareg_type >= 0) {
+		switch (datareg_type) {
+		case DATA_VALUE:
+			e->flags |= (1 << NFT_EXPR_IMM_DATA);
+			break;
+		case DATA_VERDICT:
+			e->flags |= (1 << NFT_EXPR_IMM_VERDICT);
+			break;
+		case DATA_CHAIN:
+			e->flags |= (1 << NFT_EXPR_IMM_CHAIN);
+			break;
+		default:
+			return -1;
+		}
 	}
 
 	return 0;
@@ -288,22 +289,23 @@ nft_rule_expr_immediate_snprintf_xml(char *buf, size_t len,
 	int size = len, offset = 0, ret;
 	struct nft_expr_immediate *imm = nft_expr_data(e);
 
-	ret = snprintf(buf, len, "<dreg>%u</dreg>", imm->dreg);
-	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
-
+	if (e->flags & (1 << NFT_EXPR_IMM_DREG)) {
+		ret = snprintf(buf, len, "<dreg>%u</dreg>", imm->dreg);
+		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+	}
 
 	if (e->flags & (1 << NFT_EXPR_IMM_DATA)) {
-		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
+		ret = nft_data_reg_snprintf(buf + offset, len, &imm->data,
 					    NFT_OUTPUT_XML, flags, DATA_VALUE);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	} else if (e->flags & (1 << NFT_EXPR_IMM_VERDICT)) {
-		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
+		ret = nft_data_reg_snprintf(buf + offset, len, &imm->data,
 					  NFT_OUTPUT_XML, flags, DATA_VERDICT);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	} else if (e->flags & (1 << NFT_EXPR_IMM_CHAIN)) {
-		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
+		ret = nft_data_reg_snprintf(buf + offset, len, &imm->data,
 					    NFT_OUTPUT_XML, flags, DATA_CHAIN);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 	}
-- 
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