From 6883b28c1a2d26625b712710e3e4c4d46d17bc70 Mon Sep 17 00:00:00 2001 From: Ana Rey Date: Thu, 26 Jun 2014 19:08:39 +0200 Subject: table: Add set, unset and parse implementation for the use attribute Add some parts of the implemention of 'use' vualue in table that miss it. These changes are neeeded for a correct import/export of xml/json file Signed-off-by: Ana Rey Signed-off-by: Pablo Neira Ayuso --- src/table.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/table.c') diff --git a/src/table.c b/src/table.c index de4a64d..5a0135f 100644 --- a/src/table.c +++ b/src/table.c @@ -72,8 +72,7 @@ void nft_table_attr_unset(struct nft_table *t, uint16_t attr) case NFT_TABLE_ATTR_FAMILY: break; case NFT_TABLE_ATTR_USE: - /* Cannot be unset, ignoring it */ - return; + break; } t->flags &= ~(1 << attr); } @@ -106,8 +105,8 @@ void nft_table_attr_set_data(struct nft_table *t, uint16_t attr, t->family = *((uint32_t *)data); break; case NFT_TABLE_ATTR_USE: - /* Cannot be set, ignoring it */ - return; + t->use = *((uint32_t *)data); + break; } t->flags |= (1 << attr); } @@ -263,7 +262,7 @@ int nft_mxml_table_parse(mxml_node_t *tree, struct nft_table *t, { const char *name; int family; - uint32_t flags; + uint32_t flags, use; name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST, NFT_XML_MAND, err); @@ -282,6 +281,10 @@ int nft_mxml_table_parse(mxml_node_t *tree, struct nft_table *t, return -1; nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FLAGS, flags); + if (nft_mxml_num_parse(tree, "use", MXML_DESCEND, BASE_DEC, + &use, NFT_TYPE_U32, NFT_XML_MAND, err) == 0) + nft_table_attr_set_u32(t, NFT_TABLE_ATTR_USE, use); + return 0; } #endif @@ -310,7 +313,7 @@ int nft_jansson_parse_table(struct nft_table *t, json_t *tree, struct nft_parse_err *err) { json_t *root; - uint32_t flags; + uint32_t flags, use; const char *str; int family; @@ -334,6 +337,9 @@ int nft_jansson_parse_table(struct nft_table *t, json_t *tree, nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FLAGS, flags); + if (nft_jansson_parse_val(root, "use", NFT_TYPE_U32, &use, err) == 0) + nft_table_attr_set_u32(t, NFT_TABLE_ATTR_USE, use); + return 0; } #endif -- cgit v1.2.3