diff options
Diffstat (limited to 'src/expr/data_reg.c')
-rw-r--r-- | src/expr/data_reg.c | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c index b375db4..b85d2ef 100644 --- a/src/expr/data_reg.c +++ b/src/expr/data_reg.c @@ -25,28 +25,28 @@ #include "internal.h" #ifdef JSON_PARSING -static int nft_data_reg_verdict_json_parse(union nft_data_reg *reg, json_t *data, - struct nft_parse_err *err) +static int nftnl_data_reg_verdict_json_parse(union nftnl_data_reg *reg, json_t *data, + struct nftnl_parse_err *err) { int verdict; const char *verdict_str; const char *chain; - verdict_str = nft_jansson_parse_str(data, "verdict", err); + verdict_str = nftnl_jansson_parse_str(data, "verdict", err); if (verdict_str == NULL) return DATA_NONE; - if (nft_str2verdict(verdict_str, &verdict) != 0) { + if (nftnl_str2verdict(verdict_str, &verdict) != 0) { err->node_name = "verdict"; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; errno = EINVAL; return -1; } reg->verdict = (uint32_t)verdict; - if (nft_jansson_node_exist(data, "chain")) { - chain = nft_jansson_parse_str(data, "chain", err); + if (nftnl_jansson_node_exist(data, "chain")) { + chain = nftnl_jansson_parse_str(data, "chain", err); if (chain == NULL) return DATA_NONE; @@ -56,71 +56,71 @@ static int nft_data_reg_verdict_json_parse(union nft_data_reg *reg, json_t *data return DATA_VERDICT; } -static int nft_data_reg_value_json_parse(union nft_data_reg *reg, json_t *data, - struct nft_parse_err *err) +static int nftnl_data_reg_value_json_parse(union nftnl_data_reg *reg, json_t *data, + struct nftnl_parse_err *err) { int i; char node_name[6]; - if (nft_jansson_parse_val(data, "len", NFT_TYPE_U8, ®->len, err) < 0) + if (nftnl_jansson_parse_val(data, "len", NFTNL_TYPE_U8, ®->len, err) < 0) return DATA_NONE; for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) { sprintf(node_name, "data%d", i); - if (nft_jansson_str2num(data, node_name, BASE_HEX, - ®->val[i], NFT_TYPE_U32, err) != 0) + if (nftnl_jansson_str2num(data, node_name, BASE_HEX, + ®->val[i], NFTNL_TYPE_U32, err) != 0) return DATA_NONE; } return DATA_VALUE; } -int nft_data_reg_json_parse(union nft_data_reg *reg, json_t *data, - struct nft_parse_err *err) +int nftnl_data_reg_json_parse(union nftnl_data_reg *reg, json_t *data, + struct nftnl_parse_err *err) { const char *type; - type = nft_jansson_parse_str(data, "type", err); + type = nftnl_jansson_parse_str(data, "type", err); if (type == NULL) return -1; /* Select what type of parsing is needed */ if (strcmp(type, "value") == 0) - return nft_data_reg_value_json_parse(reg, data, err); + return nftnl_data_reg_value_json_parse(reg, data, err); else if (strcmp(type, "verdict") == 0) - return nft_data_reg_verdict_json_parse(reg, data, err); + return nftnl_data_reg_verdict_json_parse(reg, data, err); return DATA_NONE; } #endif #ifdef XML_PARSING -static int nft_data_reg_verdict_xml_parse(union nft_data_reg *reg, +static int nftnl_data_reg_verdict_xml_parse(union nftnl_data_reg *reg, mxml_node_t *tree, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { int verdict; const char *verdict_str; const char *chain; - verdict_str = nft_mxml_str_parse(tree, "verdict", MXML_DESCEND_FIRST, - NFT_XML_MAND, err); + verdict_str = nftnl_mxml_str_parse(tree, "verdict", MXML_DESCEND_FIRST, + NFTNL_XML_MAND, err); if (verdict_str == NULL) return DATA_NONE; - if (nft_str2verdict(verdict_str, &verdict) != 0) { + if (nftnl_str2verdict(verdict_str, &verdict) != 0) { err->node_name = "verdict"; - err->error = NFT_PARSE_EBADTYPE; + err->error = NFTNL_PARSE_EBADTYPE; errno = EINVAL; return DATA_NONE; } reg->verdict = (uint32_t)verdict; - chain = nft_mxml_str_parse(tree, "chain", MXML_DESCEND_FIRST, - NFT_XML_OPT, err); + chain = nftnl_mxml_str_parse(tree, "chain", MXML_DESCEND_FIRST, + NFTNL_XML_OPT, err); if (chain != NULL) { if (reg->chain) xfree(reg->chain); @@ -131,31 +131,31 @@ static int nft_data_reg_verdict_xml_parse(union nft_data_reg *reg, return DATA_VERDICT; } -static int nft_data_reg_value_xml_parse(union nft_data_reg *reg, +static int nftnl_data_reg_value_xml_parse(union nftnl_data_reg *reg, mxml_node_t *tree, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { int i; char node_name[6]; - if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, - ®->len, NFT_TYPE_U8, NFT_XML_MAND, err) != 0) + if (nftnl_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, + ®->len, NFTNL_TYPE_U8, NFTNL_XML_MAND, err) != 0) return DATA_NONE; for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) { sprintf(node_name, "data%d", i); - if (nft_mxml_num_parse(tree, node_name, MXML_DESCEND_FIRST, - BASE_HEX, ®->val[i], NFT_TYPE_U32, - NFT_XML_MAND, err) != 0) + if (nftnl_mxml_num_parse(tree, node_name, MXML_DESCEND_FIRST, + BASE_HEX, ®->val[i], NFTNL_TYPE_U32, + NFTNL_XML_MAND, err) != 0) return DATA_NONE; } return DATA_VALUE; } -int nft_data_reg_xml_parse(union nft_data_reg *reg, mxml_node_t *tree, - struct nft_parse_err *err) +int nftnl_data_reg_xml_parse(union nftnl_data_reg *reg, mxml_node_t *tree, + struct nftnl_parse_err *err) { const char *type; mxml_node_t *node; @@ -171,22 +171,22 @@ int nft_data_reg_xml_parse(union nft_data_reg *reg, mxml_node_t *tree, goto err; if (strcmp(type, "value") == 0) - return nft_data_reg_value_xml_parse(reg, node, err); + return nftnl_data_reg_value_xml_parse(reg, node, err); else if (strcmp(type, "verdict") == 0) - return nft_data_reg_verdict_xml_parse(reg, node, err); + return nftnl_data_reg_verdict_xml_parse(reg, node, err); return DATA_NONE; err: errno = EINVAL; err->node_name = "reg"; - err->error = NFT_PARSE_EMISSINGNODE; + err->error = NFTNL_PARSE_EMISSINGNODE; return DATA_NONE; } #endif static int -nft_data_reg_value_snprintf_json(char *buf, size_t size, - union nft_data_reg *reg, +nftnl_data_reg_value_snprintf_json(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret, i, j; @@ -222,8 +222,8 @@ nft_data_reg_value_snprintf_json(char *buf, size_t size, } static -int nft_data_reg_value_snprintf_xml(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +int nftnl_data_reg_value_snprintf_xml(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret, i, j; uint32_t be; @@ -258,8 +258,8 @@ int nft_data_reg_value_snprintf_xml(char *buf, size_t size, } static int -nft_data_reg_value_snprintf_default(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +nftnl_data_reg_value_snprintf_default(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret, i; @@ -272,12 +272,12 @@ nft_data_reg_value_snprintf_default(char *buf, size_t size, } static int -nft_data_reg_verdict_snprintf_def(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +nftnl_data_reg_verdict_snprintf_def(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret = 0; - ret = snprintf(buf, size, "%s ", nft_verdict2str(reg->verdict)); + ret = snprintf(buf, size, "%s ", nftnl_verdict2str(reg->verdict)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (reg->chain != NULL) { @@ -289,13 +289,13 @@ nft_data_reg_verdict_snprintf_def(char *buf, size_t size, } static int -nft_data_reg_verdict_snprintf_xml(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +nftnl_data_reg_verdict_snprintf_xml(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret = 0; ret = snprintf(buf, size, "<reg type=\"verdict\">" - "<verdict>%s</verdict>", nft_verdict2str(reg->verdict)); + "<verdict>%s</verdict>", nftnl_verdict2str(reg->verdict)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (reg->chain != NULL) { @@ -311,13 +311,13 @@ nft_data_reg_verdict_snprintf_xml(char *buf, size_t size, } static int -nft_data_reg_verdict_snprintf_json(char *buf, size_t size, - union nft_data_reg *reg, uint32_t flags) +nftnl_data_reg_verdict_snprintf_json(char *buf, size_t size, + union nftnl_data_reg *reg, uint32_t flags) { int len = size, offset = 0, ret = 0; ret = snprintf(buf, size, "\"reg\":{\"type\":\"verdict\"," - "\"verdict\":\"%s\"", nft_verdict2str(reg->verdict)); + "\"verdict\":\"%s\"", nftnl_verdict2str(reg->verdict)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (reg->chain != NULL) { @@ -332,20 +332,20 @@ nft_data_reg_verdict_snprintf_json(char *buf, size_t size, return offset; } -int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg, +int nftnl_data_reg_snprintf(char *buf, size_t size, union nftnl_data_reg *reg, uint32_t output_format, uint32_t flags, int reg_type) { switch(reg_type) { case DATA_VALUE: switch(output_format) { - case NFT_OUTPUT_DEFAULT: - return nft_data_reg_value_snprintf_default(buf, size, + case NFTNL_OUTPUT_DEFAULT: + return nftnl_data_reg_value_snprintf_default(buf, size, reg, flags); - case NFT_OUTPUT_XML: - return nft_data_reg_value_snprintf_xml(buf, size, + case NFTNL_OUTPUT_XML: + return nftnl_data_reg_value_snprintf_xml(buf, size, reg, flags); - case NFT_OUTPUT_JSON: - return nft_data_reg_value_snprintf_json(buf, size, + case NFTNL_OUTPUT_JSON: + return nftnl_data_reg_value_snprintf_json(buf, size, reg, flags); default: break; @@ -353,14 +353,14 @@ int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg, case DATA_VERDICT: case DATA_CHAIN: switch(output_format) { - case NFT_OUTPUT_DEFAULT: - return nft_data_reg_verdict_snprintf_def(buf, size, + case NFTNL_OUTPUT_DEFAULT: + return nftnl_data_reg_verdict_snprintf_def(buf, size, reg, flags); - case NFT_OUTPUT_XML: - return nft_data_reg_verdict_snprintf_xml(buf, size, + case NFTNL_OUTPUT_XML: + return nftnl_data_reg_verdict_snprintf_xml(buf, size, reg, flags); - case NFT_OUTPUT_JSON: - return nft_data_reg_verdict_snprintf_json(buf, size, + case NFTNL_OUTPUT_JSON: + return nftnl_data_reg_verdict_snprintf_json(buf, size, reg, flags); default: break; @@ -372,7 +372,7 @@ int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg, return -1; } -static int nft_data_parse_cb(const struct nlattr *attr, void *data) +static int nftnl_data_parse_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -394,7 +394,7 @@ static int nft_data_parse_cb(const struct nlattr *attr, void *data) return MNL_CB_OK; } -static int nft_verdict_parse_cb(const struct nlattr *attr, void *data) +static int nftnl_verdict_parse_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -417,11 +417,11 @@ static int nft_verdict_parse_cb(const struct nlattr *attr, void *data) } static int -nft_parse_verdict(union nft_data_reg *data, const struct nlattr *attr, int *type) +nftnl_parse_verdict(union nftnl_data_reg *data, const struct nlattr *attr, int *type) { struct nlattr *tb[NFTA_VERDICT_MAX+1]; - if (mnl_attr_parse_nested(attr, nft_verdict_parse_cb, tb) < 0) { + if (mnl_attr_parse_nested(attr, nftnl_verdict_parse_cb, tb) < 0) { perror("mnl_attr_parse_nested"); return -1; } @@ -459,7 +459,7 @@ nft_parse_verdict(union nft_data_reg *data, const struct nlattr *attr, int *type } static int -__nft_parse_data(union nft_data_reg *data, const struct nlattr *attr) +__nftnl_parse_data(union nftnl_data_reg *data, const struct nlattr *attr) { void *orig = mnl_attr_get_payload(attr); uint32_t data_len = mnl_attr_get_payload_len(attr); @@ -476,12 +476,12 @@ __nft_parse_data(union nft_data_reg *data, const struct nlattr *attr) return 0; } -int nft_parse_data(union nft_data_reg *data, struct nlattr *attr, int *type) +int nftnl_parse_data(union nftnl_data_reg *data, struct nlattr *attr, int *type) { struct nlattr *tb[NFTA_DATA_MAX+1] = {}; int ret = 0; - if (mnl_attr_parse_nested(attr, nft_data_parse_cb, tb) < 0) { + if (mnl_attr_parse_nested(attr, nftnl_data_parse_cb, tb) < 0) { perror("mnl_attr_parse_nested"); return -1; } @@ -489,17 +489,17 @@ int nft_parse_data(union nft_data_reg *data, struct nlattr *attr, int *type) if (type) *type = DATA_VALUE; - ret = __nft_parse_data(data, tb[NFTA_DATA_VALUE]); + ret = __nftnl_parse_data(data, tb[NFTA_DATA_VALUE]); if (ret < 0) return ret; } if (tb[NFTA_DATA_VERDICT]) - ret = nft_parse_verdict(data, tb[NFTA_DATA_VERDICT], type); + ret = nftnl_parse_verdict(data, tb[NFTA_DATA_VERDICT], type); return ret; } -void nft_free_verdict(union nft_data_reg *data) +void nftnl_free_verdict(union nftnl_data_reg *data) { switch(data->verdict) { case NFT_JUMP: |