diff options
author | Álvaro Neira Ayuso <alvaroneay@gmail.com> | 2013-08-09 13:13:31 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-08-09 13:28:23 +0200 |
commit | 3c4559021754012a3155f092ac9787e33db50c38 (patch) | |
tree | 66f4fa2e52ea5ac317b5aae02c232073ad35c078 | |
parent | add2bc2068992daf520082c2765261227afd8f09 (diff) |
expr: bytecode: add nft_str2ntoh function
Add function that will be use in the JSON parser.
Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | src/expr/byteorder.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c index 79ba439..e2d442c 100644 --- a/src/expr/byteorder.c +++ b/src/expr/byteorder.c @@ -181,13 +181,25 @@ static char *expr_byteorder_str[] = { [NFT_BYTEORDER_NTOH] = "ntoh", }; +static inline int nft_str2ntoh(const char *op) +{ + if (strcmp(op, "ntoh") == 0) + return NFT_BYTEORDER_NTOH; + else if (strcmp(op, "hton") == 0) + return NFT_BYTEORDER_HTON; + else { + errno = EINVAL; + return -1; + } +} + static int nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree) { #ifdef XML_PARSING struct nft_expr_byteorder *byteorder = nft_expr_data(e); const char *op; - int32_t reg; + int32_t reg, ntoh; reg = nft_mxml_reg_parse(tree, "sreg", MXML_DESCEND_FIRST); if (reg < 0) @@ -207,15 +219,11 @@ nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree) if (op == NULL) return -1; - if (strcmp(op, "ntoh") == 0) - byteorder->op = NFT_BYTEORDER_NTOH; - else if (strcmp(op, "hton") == 0) - byteorder->op = NFT_BYTEORDER_HTON; - else { - errno = EINVAL; + ntoh = nft_str2ntoh(op); + if (ntoh < 0) return -1; - } + byteorder->op = ntoh; e->flags |= (1 << NFT_EXPR_BYTEORDER_OP); if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC, |