diff options
Diffstat (limited to 'src/expr')
36 files changed, 1 insertions, 1808 deletions
diff --git a/src/expr/bitwise.c b/src/expr/bitwise.c index a89734b..ebfbcd0 100644 --- a/src/expr/bitwise.c +++ b/src/expr/bitwise.c @@ -174,61 +174,6 @@ nftnl_expr_bitwise_parse(struct nftnl_expr *e, struct nlattr *attr) return ret; } -static int -nftnl_expr_bitwise_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); - uint32_t reg, len; - - if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_BITWISE_SREG, reg); - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_BITWISE_DREG, reg); - - if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &len, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_BITWISE_LEN, len); - - if (nftnl_jansson_data_reg_parse(root, "mask", &bitwise->mask, - err) == DATA_VALUE) - e->flags |= (1 << NFTNL_EXPR_BITWISE_MASK); - - if (nftnl_jansson_data_reg_parse(root, "xor", &bitwise->xor, - err) == DATA_VALUE) - e->flags |= (1 << NFTNL_EXPR_BITWISE_XOR); - - if (bitwise->mask.len != bitwise->xor.len) - return -1; - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_bitwise_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_BITWISE_SREG)) - nftnl_buf_u32(&b, type, bitwise->sreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_BITWISE_DREG)) - nftnl_buf_u32(&b, type, bitwise->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_BITWISE_LEN)) - nftnl_buf_u32(&b, type, bitwise->len, LEN); - if (e->flags & (1 << NFTNL_EXPR_BITWISE_MASK)) - nftnl_buf_reg(&b, type, &bitwise->mask, DATA_VALUE, MASK); - if (e->flags & (1 << NFTNL_EXPR_BITWISE_XOR)) - nftnl_buf_reg(&b, type, &bitwise->xor, DATA_VALUE, XOR); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_bitwise_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) { @@ -260,9 +205,6 @@ nftnl_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type, switch (type) { case NFTNL_OUTPUT_DEFAULT: return nftnl_expr_bitwise_snprintf_default(buf, size, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - return nftnl_expr_bitwise_export(buf, size, e, type); default: break; } @@ -300,5 +242,4 @@ struct expr_ops expr_ops_bitwise = { .parse = nftnl_expr_bitwise_parse, .build = nftnl_expr_bitwise_build, .snprintf = nftnl_expr_bitwise_snprintf, - .json_parse = nftnl_expr_bitwise_json_parse, }; diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c index 47c04cf..4cddd4a 100644 --- a/src/expr/byteorder.c +++ b/src/expr/byteorder.c @@ -197,63 +197,6 @@ static inline int nftnl_str2ntoh(const char *op) } } -static int -nftnl_expr_byteorder_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *op; - uint32_t sreg, dreg, len, size; - int ntoh; - - if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &sreg, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_SREG, sreg); - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &dreg, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_DREG, dreg); - - op = nftnl_jansson_parse_str(root, "op", err); - if (op != NULL) { - ntoh = nftnl_str2ntoh(op); - if (ntoh < 0) - return -1; - - nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_OP, ntoh); - } - - if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &len, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_LEN, len); - - if (nftnl_jansson_parse_val(root, "size", NFTNL_TYPE_U32, &size, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_SIZE, size); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_byteorder_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_SREG)) - nftnl_buf_u32(&b, type, byteorder->sreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_DREG)) - nftnl_buf_u32(&b, type, byteorder->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_OP)) - nftnl_buf_str(&b, type, bo2str(byteorder->op), OP); - if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_LEN)) - nftnl_buf_u32(&b, type, byteorder->len, LEN); - if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_SIZE)) - nftnl_buf_u32(&b, type, byteorder->size, SIZE); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_byteorder_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) { @@ -277,7 +220,6 @@ nftnl_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type, return nftnl_expr_byteorder_snprintf_default(buf, size, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_byteorder_export(buf, size, e, type); default: break; } @@ -315,5 +257,4 @@ struct expr_ops expr_ops_byteorder = { .parse = nftnl_expr_byteorder_parse, .build = nftnl_expr_byteorder_build, .snprintf = nftnl_expr_byteorder_snprintf, - .json_parse = nftnl_expr_byteorder_json_parse, }; diff --git a/src/expr/cmp.c b/src/expr/cmp.c index b26d0eb..86708a4 100644 --- a/src/expr/cmp.c +++ b/src/expr/cmp.c @@ -176,55 +176,6 @@ static inline int nftnl_str2cmp(const char *op) } } -static int nftnl_expr_cmp_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); - const char *op; - uint32_t uval32; - int base; - - if (nftnl_jansson_parse_val(root, "sreg", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_CMP_SREG, uval32); - - op = nftnl_jansson_parse_str(root, "op", err); - if (op != NULL) { - base = nftnl_str2cmp(op); - if (base < 0) - return -1; - - nftnl_expr_set_u32(e, NFTNL_EXPR_CMP_OP, base); - } - - if (nftnl_jansson_data_reg_parse(root, "data", - &cmp->data, err) == DATA_VALUE) - e->flags |= (1 << NFTNL_EXPR_CMP_DATA); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_cmp_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_cmp *cmp = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_CMP_SREG)) - nftnl_buf_u32(&b, type, cmp->sreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_CMP_OP)) - nftnl_buf_str(&b, type, cmp2str(cmp->op), OP); - if (e->flags & (1 << NFTNL_EXPR_CMP_DATA)) - nftnl_buf_reg(&b, type, &cmp->data, DATA_VALUE, DATA); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_cmp_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) { @@ -251,7 +202,6 @@ nftnl_expr_cmp_snprintf(char *buf, size_t size, uint32_t type, return nftnl_expr_cmp_snprintf_default(buf, size, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_cmp_export(buf, size, e, type); default: break; } @@ -285,5 +235,4 @@ struct expr_ops expr_ops_cmp = { .parse = nftnl_expr_cmp_parse, .build = nftnl_expr_cmp_build, .snprintf = nftnl_expr_cmp_snprintf, - .json_parse = nftnl_expr_cmp_json_parse, }; diff --git a/src/expr/connlimit.c b/src/expr/connlimit.c index 60965b5..61fd299 100644 --- a/src/expr/connlimit.c +++ b/src/expr/connlimit.c @@ -117,42 +117,6 @@ nftnl_expr_connlimit_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int -nftnl_expr_connlimit_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t uval32; - - if (nftnl_jansson_parse_val(root, "count", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_CONNLIMIT_COUNT, uval32); - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_CONNLIMIT_FLAGS, uval32); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_connlimit_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_connlimit *connlimit = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_CONNLIMIT_COUNT)) - nftnl_buf_u32(&b, type, connlimit->count, COUNT); - if (e->flags & (1 << NFTNL_EXPR_CONNLIMIT_FLAGS)) - nftnl_buf_u32(&b, type, connlimit->flags, FLAGS); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_connlimit_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -171,7 +135,6 @@ static int nftnl_expr_connlimit_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_connlimit_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_connlimit_export(buf, len, e, type); default: break; } @@ -203,5 +166,4 @@ struct expr_ops expr_ops_connlimit = { .parse = nftnl_expr_connlimit_parse, .build = nftnl_expr_connlimit_build, .snprintf = nftnl_expr_connlimit_snprintf, - .json_parse = nftnl_expr_connlimit_json_parse, }; diff --git a/src/expr/counter.c b/src/expr/counter.c index 21901e8..2036cb0 100644 --- a/src/expr/counter.c +++ b/src/expr/counter.c @@ -115,42 +115,6 @@ nftnl_expr_counter_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int -nftnl_expr_counter_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint64_t uval64; - - if (nftnl_jansson_parse_val(root, "pkts", NFTNL_TYPE_U64, &uval64, - err) == 0) - nftnl_expr_set_u64(e, NFTNL_EXPR_CTR_PACKETS, uval64); - - if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &uval64, - err) == 0) - nftnl_expr_set_u64(e, NFTNL_EXPR_CTR_BYTES, uval64); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_counter_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_counter *ctr = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_CTR_PACKETS)) - nftnl_buf_u64(&b, type, ctr->pkts, PKTS); - if (e->flags & (1 << NFTNL_EXPR_CTR_BYTES)) - nftnl_buf_u64(&b, type, ctr->bytes, BYTES); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_counter_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -169,7 +133,6 @@ static int nftnl_expr_counter_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_counter_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_counter_export(buf, len, e, type); default: break; } @@ -201,5 +164,4 @@ struct expr_ops expr_ops_counter = { .parse = nftnl_expr_counter_parse, .build = nftnl_expr_counter_build, .snprintf = nftnl_expr_counter_snprintf, - .json_parse = nftnl_expr_counter_json_parse, }; diff --git a/src/expr/ct.c b/src/expr/ct.c index 39e9be6..bb7fe8a 100644 --- a/src/expr/ct.c +++ b/src/expr/ct.c @@ -221,70 +221,6 @@ static inline int str2ctdir(const char *str, uint8_t *ctdir) return -1; } -static int nftnl_expr_ct_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *key_str, *dir_str; - uint32_t reg; - uint8_t dir; - int key; - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_CT_DREG, reg); - - if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_CT_SREG, reg); - - key_str = nftnl_jansson_parse_str(root, "key", err); - if (key_str != NULL) { - key = str2ctkey(key_str); - if (key < 0) - return -1; - - nftnl_expr_set_u32(e, NFTNL_EXPR_CT_KEY, key); - } - - dir_str = nftnl_jansson_parse_str(root, "dir", err); - if (dir_str != NULL) { - if (str2ctdir(dir_str, &dir) != 0) { - err->node_name = "dir"; - err->error = NFTNL_PARSE_EBADTYPE; - goto err; - } - nftnl_expr_set_u8(e, NFTNL_EXPR_CT_DIR, dir); - } - - return 0; -err: - errno = EINVAL; - return -1; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - - -static int -nftnl_expr_ct_export(char *buf, size_t size, const struct nftnl_expr *e, - int type) -{ - struct nftnl_expr_ct *ct = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_CT_SREG)) - nftnl_buf_u32(&b, type, ct->sreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_CT_DREG)) - nftnl_buf_u32(&b, type, ct->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_CT_KEY)) - nftnl_buf_str(&b, type, ctkey2str(ct->key), KEY); - if (e->flags & (1 << NFTNL_EXPR_CT_DIR)) - nftnl_buf_str(&b, type, ctdir2str(ct->dir), DIR); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_ct_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) @@ -322,7 +258,6 @@ nftnl_expr_ct_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_ct_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_ct_export(buf, len, e, type); default: break; } @@ -358,5 +293,4 @@ struct expr_ops expr_ops_ct = { .parse = nftnl_expr_ct_parse, .build = nftnl_expr_ct_build, .snprintf = nftnl_expr_ct_snprintf, - .json_parse = nftnl_expr_ct_json_parse, }; diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c index ad7f4cb..48a012b 100644 --- a/src/expr/data_reg.c +++ b/src/expr/data_reg.c @@ -24,116 +24,6 @@ #include <libnftnl/rule.h> #include "internal.h" -#ifdef JSON_PARSING -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 = nftnl_jansson_parse_str(data, "verdict", err); - if (verdict_str == NULL) - return DATA_NONE; - - if (nftnl_str2verdict(verdict_str, &verdict) != 0) { - err->node_name = "verdict"; - err->error = NFTNL_PARSE_EBADTYPE; - errno = EINVAL; - return -1; - } - - reg->verdict = (uint32_t)verdict; - - if (nftnl_jansson_node_exist(data, "chain")) { - chain = nftnl_jansson_parse_str(data, "chain", err); - if (chain == NULL) - return DATA_NONE; - - reg->chain = strdup(chain); - } - - return DATA_VERDICT; -} - -static int nftnl_data_reg_value_json_parse(union nftnl_data_reg *reg, json_t *data, - struct nftnl_parse_err *err) -{ - char node_name[32] = {}; - int ret, remain = sizeof(node_name), offset = 0, i; - - if (nftnl_jansson_parse_val(data, "len", NFTNL_TYPE_U32, ®->len, err) < 0) - return DATA_NONE; - - for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) { - ret = snprintf(node_name, sizeof(node_name), "data%u", i); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - - if (nftnl_jansson_str2num(data, node_name, BASE_HEX, - ®->val[i], NFTNL_TYPE_U32, err) != 0) - return DATA_NONE; - } - - return DATA_VALUE; -} - -int nftnl_data_reg_json_parse(union nftnl_data_reg *reg, json_t *data, - struct nftnl_parse_err *err) -{ - - const char *type; - - 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 nftnl_data_reg_value_json_parse(reg, data, err); - else if (strcmp(type, "verdict") == 0) - return nftnl_data_reg_verdict_json_parse(reg, data, err); - - return DATA_NONE; -} -#endif - -static int -nftnl_data_reg_value_snprintf_json(char *buf, size_t size, - const union nftnl_data_reg *reg, - uint32_t flags) -{ - int remain = size, offset = 0, ret, i, j; - uint32_t utemp; - uint8_t *tmp; - - ret = snprintf(buf, remain, "\"reg\":{\"type\":\"value\","); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - - ret = snprintf(buf + offset, remain, "\"len\":%u,", reg->len); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - - for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) { - ret = snprintf(buf + offset, remain, "\"data%d\":\"0x", i); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - - utemp = htonl(reg->val[i]); - tmp = (uint8_t *)&utemp; - - for (j = 0; j<sizeof(uint32_t); j++) { - ret = snprintf(buf + offset, remain, "%.02x", tmp[j]); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - } - - ret = snprintf(buf + offset, remain, "\","); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - } - offset--; - ret = snprintf(buf + offset, remain, "}"); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - - return offset; -} - static int nftnl_data_reg_value_snprintf_default(char *buf, size_t size, const union nftnl_data_reg *reg, @@ -167,29 +57,6 @@ nftnl_data_reg_verdict_snprintf_def(char *buf, size_t size, return offset; } -static int -nftnl_data_reg_verdict_snprintf_json(char *buf, size_t size, - const union nftnl_data_reg *reg, - uint32_t flags) -{ - int remain = size, offset = 0, ret = 0; - - ret = snprintf(buf, size, "\"reg\":{\"type\":\"verdict\"," - "\"verdict\":\"%s\"", nftnl_verdict2str(reg->verdict)); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - - if (reg->chain != NULL) { - ret = snprintf(buf + offset, remain, ",\"chain\":\"%s\"", - reg->chain); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - } - - ret = snprintf(buf + offset, remain, "}"); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - - return offset; -} - int nftnl_data_reg_snprintf(char *buf, size_t size, const union nftnl_data_reg *reg, uint32_t output_format, uint32_t flags, @@ -202,8 +69,6 @@ int nftnl_data_reg_snprintf(char *buf, size_t size, return nftnl_data_reg_value_snprintf_default(buf, size, reg, flags); case NFTNL_OUTPUT_JSON: - return nftnl_data_reg_value_snprintf_json(buf, size, - reg, flags); case NFTNL_OUTPUT_XML: default: break; @@ -216,8 +81,6 @@ int nftnl_data_reg_snprintf(char *buf, size_t size, return nftnl_data_reg_verdict_snprintf_def(buf, size, reg, flags); case NFTNL_OUTPUT_JSON: - return nftnl_data_reg_verdict_snprintf_json(buf, size, - reg, flags); case NFTNL_OUTPUT_XML: default: break; diff --git a/src/expr/dup.c b/src/expr/dup.c index ed8e620..6fa6598 100644 --- a/src/expr/dup.c +++ b/src/expr/dup.c @@ -112,41 +112,6 @@ static int nftnl_expr_dup_parse(struct nftnl_expr *e, struct nlattr *attr) return ret; } -static int nftnl_expr_dup_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t sreg_addr, sreg_dev; - int ret; - - ret = nftnl_jansson_parse_val(root, "sreg_addr", NFTNL_TYPE_U32, &sreg_addr, err); - if (ret >= 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_DUP_SREG_DEV, sreg_addr); - ret = nftnl_jansson_parse_val(root, "sreg_dev", NFTNL_TYPE_U32, &sreg_dev, err); - if (ret >= 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_DUP_SREG_DEV, sreg_dev); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_dup_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_dup *dup = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_DUP_SREG_ADDR)) - nftnl_buf_u32(&b, type, dup->sreg_addr, "sreg_addr"); - if (e->flags & (1 << NFTNL_EXPR_DUP_SREG_DEV)) - nftnl_buf_u32(&b, type, dup->sreg_addr, "sreg_dev"); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_dup_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e, uint32_t flags) @@ -175,7 +140,6 @@ static int nftnl_expr_dup_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_dup_snprintf_default(buf, len, e, flags); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_dup_export(buf, len, e, type); default: break; } @@ -207,5 +171,4 @@ struct expr_ops expr_ops_dup = { .parse = nftnl_expr_dup_parse, .build = nftnl_expr_dup_build, .snprintf = nftnl_expr_dup_snprintf, - .json_parse = nftnl_expr_dup_json_parse, }; diff --git a/src/expr/dynset.c b/src/expr/dynset.c index 160d0e1..3d24ef8 100644 --- a/src/expr/dynset.c +++ b/src/expr/dynset.c @@ -205,59 +205,6 @@ nftnl_expr_dynset_parse(struct nftnl_expr *e, struct nlattr *attr) return ret; } -static int -nftnl_expr_dynset_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *set_name; - uint32_t uval32; - uint64_t uval64; - - set_name = nftnl_jansson_parse_str(root, "set", err); - if (set_name != NULL) - nftnl_expr_set_str(e, NFTNL_EXPR_DYNSET_SET_NAME, set_name); - - if (nftnl_jansson_parse_reg(root, "sreg_key", - NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_DYNSET_SREG_KEY, uval32); - - if (nftnl_jansson_parse_reg(root, "sreg_data", - NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_DYNSET_SREG_DATA, uval32); - - if (nftnl_jansson_parse_val(root, "op", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_DYNSET_OP, uval32); - - if (nftnl_jansson_parse_val(root, "timeout", NFTNL_TYPE_U64, &uval64, - err) == 0) - nftnl_expr_set_u64(e, NFTNL_EXPR_DYNSET_TIMEOUT, uval64); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int -nftnl_expr_dynset_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_dynset *dynset = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_DYNSET_SET_NAME)) - nftnl_buf_str(&b, type, dynset->set_name, SET_NAME); - if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_KEY)) - nftnl_buf_u32(&b, type, dynset->sreg_key, SREG_KEY); - if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_DATA)) - nftnl_buf_u32(&b, type, dynset->sreg_data, SREG_DATA); - - return nftnl_buf_done(&b); -} - static const char *op2str_array[] = { [NFT_DYNSET_OP_ADD] = "add", [NFT_DYNSET_OP_UPDATE] = "update", @@ -319,7 +266,6 @@ nftnl_expr_dynset_snprintf(char *buf, size_t size, uint32_t type, return nftnl_expr_dynset_snprintf_default(buf, size, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_dynset_export(buf, size, e, type); default: break; } @@ -369,5 +315,4 @@ struct expr_ops expr_ops_dynset = { .parse = nftnl_expr_dynset_parse, .build = nftnl_expr_dynset_build, .snprintf = nftnl_expr_dynset_snprintf, - .json_parse = nftnl_expr_dynset_json_parse, }; diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c index a351835..ec6a855 100644 --- a/src/expr/exthdr.c +++ b/src/expr/exthdr.c @@ -205,24 +205,6 @@ static const char *op2str(uint8_t op) } } -static const char *type2str(uint32_t type) -{ - switch (type) { - case IPPROTO_HOPOPTS: - return "hopopts"; - case IPPROTO_ROUTING: - return "routing"; - case IPPROTO_FRAGMENT: - return "fragment"; - case IPPROTO_DSTOPTS: - return "dstopts"; - case IPPROTO_MH: - return "mh"; - default: - return "unknown"; - } -} - static inline int str2exthdr_op(const char* str) { if (!strcmp(str, "tcpopt")) @@ -248,75 +230,6 @@ static inline int str2exthdr_type(const char *str) return -1; } -static int -nftnl_expr_exthdr_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *exthdr_type; - uint32_t uval32; - int type; - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_DREG, uval32); - - if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_SREG, uval32); - - exthdr_type = nftnl_jansson_parse_str(root, "exthdr_type", err); - if (exthdr_type != NULL) { - type = str2exthdr_type(exthdr_type); - if (type < 0) - return -1; - nftnl_expr_set_u8(e, NFTNL_EXPR_EXTHDR_TYPE, type); - } - - if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_OFFSET, uval32); - - if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_LEN, uval32); - - if (nftnl_jansson_parse_val(root, "op", NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_OP, uval32); - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_FLAGS, uval32); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_exthdr_export(char *buf, size_t len, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, len); - - if (e->flags & (1 << NFTNL_EXPR_EXTHDR_DREG)) - nftnl_buf_u32(&b, type, exthdr->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_EXTHDR_SREG)) - nftnl_buf_u32(&b, type, exthdr->dreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_EXTHDR_TYPE)) - nftnl_buf_str(&b, type, type2str(exthdr->type), EXTHDR_TYPE); - if (e->flags & (1 << NFTNL_EXPR_EXTHDR_OFFSET)) - nftnl_buf_u32(&b, type, exthdr->offset, OFFSET); - if (e->flags & (1 << NFTNL_EXPR_EXTHDR_LEN)) - nftnl_buf_u32(&b, type, exthdr->len, LEN); - if (e->flags & (1 << NFTNL_EXPR_EXTHDR_OP)) - nftnl_buf_u32(&b, type, exthdr->op, OP); - if (e->flags & (1 << NFTNL_EXPR_EXTHDR_FLAGS)) - nftnl_buf_u32(&b, type, exthdr->flags, FLAGS); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_exthdr_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -344,7 +257,6 @@ nftnl_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_exthdr_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_exthdr_export(buf, len, e, type); default: break; } @@ -386,5 +298,4 @@ struct expr_ops expr_ops_exthdr = { .parse = nftnl_expr_exthdr_parse, .build = nftnl_expr_exthdr_build, .snprintf = nftnl_expr_exthdr_snprintf, - .json_parse = nftnl_expr_exthdr_json_parse, }; diff --git a/src/expr/fib.c b/src/expr/fib.c index b922b26..f1eec73 100644 --- a/src/expr/fib.c +++ b/src/expr/fib.c @@ -128,31 +128,6 @@ nftnl_expr_fib_parse(struct nftnl_expr *e, struct nlattr *attr) return ret; } -static int nftnl_expr_fib_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t result, flags, dreg; - - if (nftnl_jansson_parse_reg(root, "result", NFTNL_TYPE_U32, - &result, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_FIB_RESULT, result); - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, - &dreg, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_FIB_DREG, dreg); - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, - &flags, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_FIB_FLAGS, flags); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static const char *fib_type[NFT_FIB_RESULT_MAX + 1] = { [NFT_FIB_RESULT_OIF] = "oif", [NFT_FIB_RESULT_OIFNAME] = "oifname", @@ -215,23 +190,6 @@ nftnl_expr_fib_snprintf_default(char *buf, size_t size, return offset; } -static int nftnl_expr_fib_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_fib *fib = nftnl_expr_data(e); - - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_FIB_RESULT)) - nftnl_buf_u32(&b, type, fib->result, OP); - if (e->flags & (1 << NFTNL_EXPR_FIB_DREG)) - nftnl_buf_u32(&b, type, fib->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_FIB_FLAGS)) - nftnl_buf_u32(&b, type, fib->flags, FLAGS); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -241,7 +199,6 @@ nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_fib_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_fib_export(buf, len, e, type); default: break; } @@ -275,5 +232,4 @@ struct expr_ops expr_ops_fib = { .parse = nftnl_expr_fib_parse, .build = nftnl_expr_fib_build, .snprintf = nftnl_expr_fib_snprintf, - .json_parse = nftnl_expr_fib_json_parse, }; diff --git a/src/expr/flow_offload.c b/src/expr/flow_offload.c index a2001c9..648099a 100644 --- a/src/expr/flow_offload.c +++ b/src/expr/flow_offload.c @@ -92,36 +92,6 @@ static int nftnl_expr_flow_parse(struct nftnl_expr *e, struct nlattr *attr) return ret; } -static int -nftnl_expr_flow_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *table_name; - - table_name = nftnl_jansson_parse_str(root, "flowtable", err); - if (table_name != NULL) - nftnl_expr_set_str(e, NFTNL_EXPR_FLOW_TABLE_NAME, table_name); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_flow_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_flow *l = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_FLOW_TABLE_NAME)) - nftnl_buf_str(&b, type, l->table_name, SET); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_flow_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) { @@ -142,7 +112,6 @@ static int nftnl_expr_flow_snprintf(char *buf, size_t size, uint32_t type, return nftnl_expr_flow_snprintf_default(buf, size, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_flow_export(buf, size, e, type); default: break; } @@ -180,5 +149,4 @@ struct expr_ops expr_ops_flow = { .parse = nftnl_expr_flow_parse, .build = nftnl_expr_flow_build, .snprintf = nftnl_expr_flow_snprintf, - .json_parse = nftnl_expr_flow_json_parse, }; diff --git a/src/expr/fwd.c b/src/expr/fwd.c index 9021606..9890e9a 100644 --- a/src/expr/fwd.c +++ b/src/expr/fwd.c @@ -126,46 +126,6 @@ static int nftnl_expr_fwd_parse(struct nftnl_expr *e, struct nlattr *attr) return ret; } -static int nftnl_expr_fwd_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t u32val; - int ret; - - ret = nftnl_jansson_parse_val(root, "sreg_dev", NFTNL_TYPE_U32, &u32val, err); - if (ret >= 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_FWD_SREG_DEV, u32val); - ret = nftnl_jansson_parse_val(root, "sreg_addr", NFTNL_TYPE_U32, &u32val, err); - if (ret >= 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_FWD_SREG_ADDR, u32val); - ret = nftnl_jansson_parse_val(root, "nfproto", NFTNL_TYPE_U32, &u32val, err); - if (ret >= 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_FWD_NFPROTO, u32val); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_fwd_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_fwd *fwd = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_FWD_SREG_DEV)) - nftnl_buf_u32(&b, type, fwd->sreg_dev, "sreg_dev"); - if (e->flags & (1 << NFTNL_EXPR_FWD_SREG_ADDR)) - nftnl_buf_u32(&b, type, fwd->sreg_dev, "sreg_addr"); - if (e->flags & (1 << NFTNL_EXPR_FWD_NFPROTO)) - nftnl_buf_u32(&b, type, fwd->nfproto, "nfproto"); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_fwd_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e, uint32_t flags) @@ -200,7 +160,6 @@ static int nftnl_expr_fwd_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_fwd_snprintf_default(buf, len, e, flags); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_fwd_export(buf, len, e, type); default: break; } @@ -234,5 +193,4 @@ struct expr_ops expr_ops_fwd = { .parse = nftnl_expr_fwd_parse, .build = nftnl_expr_fwd_build, .snprintf = nftnl_expr_fwd_snprintf, - .json_parse = nftnl_expr_fwd_json_parse, }; diff --git a/src/expr/hash.c b/src/expr/hash.c index 415537e..280ea0c 100644 --- a/src/expr/hash.c +++ b/src/expr/hash.c @@ -220,47 +220,6 @@ nftnl_expr_hash_parse(struct nftnl_expr *e, struct nlattr *attr) return ret; } -static int nftnl_expr_hash_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t sreg, dreg, len, modulus, seed, offset, type; - - if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, - &sreg, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_SREG, sreg); - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, - &dreg, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_DREG, dreg); - - if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, - &len, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_LEN, len); - - if (nftnl_jansson_parse_val(root, "modulus", NFTNL_TYPE_U32, - &modulus, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_MODULUS, modulus); - - if (nftnl_jansson_parse_val(root, "seed", NFTNL_TYPE_U32, - &seed, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_SEED, seed); - - if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32, - &offset, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_OFFSET, offset); - - if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, - &type, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_TYPE, type); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static int nftnl_expr_hash_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) @@ -302,33 +261,6 @@ nftnl_expr_hash_snprintf_default(char *buf, size_t size, return offset; } -static int nftnl_expr_hash_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_hash *hash = nftnl_expr_data(e); - - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_HASH_SREG)) - nftnl_buf_u32(&b, type, hash->sreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_HASH_DREG)) - nftnl_buf_u32(&b, type, hash->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_HASH_LEN)) - nftnl_buf_u32(&b, type, hash->len, LEN); - if (e->flags & (1 << NFTNL_EXPR_HASH_MODULUS)) - nftnl_buf_u32(&b, type, hash->modulus, MODULUS); - if (e->flags & (1 << NFTNL_EXPR_HASH_SEED)) - nftnl_buf_u32(&b, type, hash->seed, SEED); - if (e->flags & (1 << NFTNL_EXPR_HASH_OFFSET)) - nftnl_buf_u32(&b, type, hash->offset, OFFSET); - if (e->flags & (1 << NFTNL_EXPR_HASH_TYPE)) - nftnl_buf_u32(&b, type, hash->type, TYPE); - if (e->flags & (1 << NFTNL_EXPR_HASH_SET_NAME)) - nftnl_buf_str(&b, type, hash->map.name, SET); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -338,7 +270,6 @@ nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_hash_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_hash_export(buf, len, e, type); default: break; } @@ -384,5 +315,4 @@ struct expr_ops expr_ops_hash = { .parse = nftnl_expr_hash_parse, .build = nftnl_expr_hash_build, .snprintf = nftnl_expr_hash_snprintf, - .json_parse = nftnl_expr_hash_json_parse, }; diff --git a/src/expr/immediate.c b/src/expr/immediate.c index b0570bd..22edbc8 100644 --- a/src/expr/immediate.c +++ b/src/expr/immediate.c @@ -174,61 +174,6 @@ nftnl_expr_immediate_parse(struct nftnl_expr *e, struct nlattr *attr) } static int -nftnl_expr_immediate_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - struct nftnl_expr_immediate *imm = nftnl_expr_data(e); - int datareg_type; - uint32_t reg; - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_IMM_DREG, reg); - - datareg_type = nftnl_jansson_data_reg_parse(root, "data", - &imm->data, err); - if (datareg_type >= 0) { - switch (datareg_type) { - case DATA_VALUE: - e->flags |= (1 << NFTNL_EXPR_IMM_DATA); - break; - case DATA_VERDICT: - e->flags |= (1 << NFTNL_EXPR_IMM_VERDICT); - break; - case DATA_CHAIN: - e->flags |= (1 << NFTNL_EXPR_IMM_CHAIN); - break; - default: - return -1; - } - } - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int -nftnl_expr_immediate_export(char *buf, size_t size, const struct nftnl_expr *e, - int type) -{ - struct nftnl_expr_immediate *imm = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_IMM_DREG)) - nftnl_buf_u32(&b, type, imm->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_IMM_DATA)) - nftnl_buf_reg(&b, type, &imm->data, DATA_VALUE, DATA); - if (e->flags & (1 << NFTNL_EXPR_IMM_VERDICT)) - nftnl_buf_reg(&b, type, &imm->data, DATA_VERDICT, DATA); - if (e->flags & (1 << NFTNL_EXPR_IMM_CHAIN)) - nftnl_buf_reg(&b, type, &imm->data, DATA_CHAIN, DATA); - - return nftnl_buf_done(&b); -} - -static int nftnl_expr_immediate_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e, uint32_t flags) @@ -267,7 +212,6 @@ nftnl_expr_immediate_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_immediate_snprintf_default(buf, len, e, flags); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_immediate_export(buf, len, e, type); default: break; } @@ -317,5 +261,4 @@ struct expr_ops expr_ops_immediate = { .parse = nftnl_expr_immediate_parse, .build = nftnl_expr_immediate_build, .snprintf = nftnl_expr_immediate_snprintf, - .json_parse = nftnl_expr_immediate_json_parse, }; diff --git a/src/expr/limit.c b/src/expr/limit.c index 856ab18..4831abd 100644 --- a/src/expr/limit.c +++ b/src/expr/limit.c @@ -160,32 +160,6 @@ nftnl_expr_limit_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int nftnl_expr_limit_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint64_t uval64; - uint32_t uval32; - - if (nftnl_jansson_parse_val(root, "rate", NFTNL_TYPE_U64, &uval64, err) == 0) - nftnl_expr_set_u64(e, NFTNL_EXPR_LIMIT_RATE, uval64); - - if (nftnl_jansson_parse_val(root, "unit", NFTNL_TYPE_U64, &uval64, err) == 0) - nftnl_expr_set_u64(e, NFTNL_EXPR_LIMIT_UNIT, uval64); - if (nftnl_jansson_parse_val(root, "burst", NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LIMIT_BURST, uval32); - if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LIMIT_TYPE, uval32); - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LIMIT_FLAGS, uval32); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static const char *get_unit(uint64_t u) { switch (u) { @@ -198,26 +172,6 @@ static const char *get_unit(uint64_t u) return "error"; } -static int nftnl_expr_limit_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_limit *limit = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_LIMIT_RATE)) - nftnl_buf_u64(&b, type, limit->rate, RATE); - if (e->flags & (1 << NFTNL_EXPR_LIMIT_UNIT)) - nftnl_buf_u64(&b, type, limit->unit, UNIT); - if (e->flags & (1 << NFTNL_EXPR_LIMIT_BURST)) - nftnl_buf_u32(&b, type, limit->burst, BURST); - if (e->flags & (1 << NFTNL_EXPR_LIMIT_TYPE)) - nftnl_buf_u32(&b, type, limit->type, TYPE); - if (e->flags & (1 << NFTNL_EXPR_LIMIT_FLAGS)) - nftnl_buf_u32(&b, type, limit->flags, FLAGS); - - return nftnl_buf_done(&b); -} - static const char *limit_to_type(enum nft_limit_type type) { switch (type) { @@ -248,7 +202,6 @@ nftnl_expr_limit_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_limit_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_limit_export(buf, len, e, type); default: break; } @@ -286,5 +239,4 @@ struct expr_ops expr_ops_limit = { .parse = nftnl_expr_limit_parse, .build = nftnl_expr_limit_build, .snprintf = nftnl_expr_limit_snprintf, - .json_parse = nftnl_expr_limit_json_parse, }; diff --git a/src/expr/log.c b/src/expr/log.c index 86d9651..e4bf051 100644 --- a/src/expr/log.c +++ b/src/expr/log.c @@ -186,45 +186,6 @@ nftnl_expr_log_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int nftnl_expr_log_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *prefix; - uint32_t snaplen, level, flags; - uint16_t group, qthreshold; - - prefix = nftnl_jansson_parse_str(root, "prefix", err); - if (prefix != NULL) - nftnl_expr_set_str(e, NFTNL_EXPR_LOG_PREFIX, prefix); - - if (nftnl_jansson_parse_val(root, "group", NFTNL_TYPE_U16, &group, - err) == 0) - nftnl_expr_set_u16(e, NFTNL_EXPR_LOG_GROUP, group); - - if (nftnl_jansson_parse_val(root, "snaplen", NFTNL_TYPE_U32, &snaplen, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LOG_SNAPLEN, snaplen); - - if (nftnl_jansson_parse_val(root, "qthreshold", NFTNL_TYPE_U16, - &qthreshold, err) == 0) - nftnl_expr_set_u16(e, NFTNL_EXPR_LOG_QTHRESHOLD, qthreshold); - - if (nftnl_jansson_parse_val(root, "level", NFTNL_TYPE_U32, &level, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LOG_LEVEL, level); - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LOG_FLAGS, flags); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static int nftnl_expr_log_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) { @@ -275,28 +236,6 @@ static int nftnl_expr_log_snprintf_default(char *buf, size_t size, return offset; } -static int nftnl_expr_log_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_log *log = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_LOG_PREFIX)) - nftnl_buf_str(&b, type, log->prefix, PREFIX); - if (e->flags & (1 << NFTNL_EXPR_LOG_GROUP)) - nftnl_buf_u32(&b, type, log->group, GROUP); - if (e->flags & (1 << NFTNL_EXPR_LOG_SNAPLEN)) - nftnl_buf_u32(&b, type, log->snaplen, SNAPLEN); - if (e->flags & (1 << NFTNL_EXPR_LOG_QTHRESHOLD)) - nftnl_buf_u32(&b, type, log->qthreshold, QTHRESH); - if (e->flags & (1 << NFTNL_EXPR_LOG_LEVEL)) - nftnl_buf_u32(&b, type, log->level, LEVEL); - if (e->flags & (1 << NFTNL_EXPR_LOG_FLAGS)) - nftnl_buf_u32(&b, type, log->flags, FLAGS); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -306,7 +245,6 @@ nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_log_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_log_export(buf, len, e, type); default: break; } @@ -354,5 +292,4 @@ struct expr_ops expr_ops_log = { .parse = nftnl_expr_log_parse, .build = nftnl_expr_log_build, .snprintf = nftnl_expr_log_snprintf, - .json_parse = nftnl_expr_log_json_parse, }; diff --git a/src/expr/lookup.c b/src/expr/lookup.c index 5fcb81f..132dc4e 100644 --- a/src/expr/lookup.c +++ b/src/expr/lookup.c @@ -168,54 +168,6 @@ nftnl_expr_lookup_parse(struct nftnl_expr *e, struct nlattr *attr) } static int -nftnl_expr_lookup_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *set_name; - uint32_t sreg, dreg, flags; - - set_name = nftnl_jansson_parse_str(root, "set", err); - if (set_name != NULL) - nftnl_expr_set_str(e, NFTNL_EXPR_LOOKUP_SET, set_name); - - if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &sreg, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LOOKUP_SREG, sreg); - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &dreg, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LOOKUP_DREG, dreg); - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, - &flags, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_LOOKUP_FLAGS, flags); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int -nftnl_expr_lookup_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_lookup *l = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET)) - nftnl_buf_str(&b, type, l->set_name, SET); - if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SREG)) - nftnl_buf_u32(&b, type, l->sreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_LOOKUP_DREG)) - nftnl_buf_u32(&b, type, l->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_LOOKUP_FLAGS)) - nftnl_buf_u32(&b, type, l->flags, FLAGS); - - return nftnl_buf_done(&b); -} - -static int nftnl_expr_lookup_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) { @@ -247,7 +199,6 @@ nftnl_expr_lookup_snprintf(char *buf, size_t size, uint32_t type, return nftnl_expr_lookup_snprintf_default(buf, size, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_lookup_export(buf, size, e, type); default: break; } @@ -293,5 +244,4 @@ struct expr_ops expr_ops_lookup = { .parse = nftnl_expr_lookup_parse, .build = nftnl_expr_lookup_build, .snprintf = nftnl_expr_lookup_snprintf, - .json_parse = nftnl_expr_lookup_json_parse, }; diff --git a/src/expr/masq.c b/src/expr/masq.c index 7c235d3..78dd76b 100644 --- a/src/expr/masq.c +++ b/src/expr/masq.c @@ -131,46 +131,6 @@ nftnl_expr_masq_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int -nftnl_expr_masq_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t reg, flags; - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_MASQ_FLAGS, flags); - if (nftnl_jansson_parse_reg(root, "sreg_proto_min", NFTNL_TYPE_U32, - ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_MASQ_REG_PROTO_MIN, reg); - if (nftnl_jansson_parse_reg(root, "sreg_proto_max", NFTNL_TYPE_U32, - ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_MASQ_REG_PROTO_MAX, reg); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_masq_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_masq *masq = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_MASQ_FLAGS)) - nftnl_buf_u32(&b, type, masq->flags, FLAGS); - if (e->flags & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MIN)) - nftnl_buf_u32(&b, type, masq->sreg_proto_min, SREG_PROTO_MIN); - if (e->flags & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MAX)) - nftnl_buf_u32(&b, type, masq->sreg_proto_max, SREG_PROTO_MAX); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_masq_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -195,7 +155,6 @@ static int nftnl_expr_masq_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_masq_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_masq_export(buf, len, e, type); default: break; } @@ -229,5 +188,4 @@ struct expr_ops expr_ops_masq = { .parse = nftnl_expr_masq_parse, .build = nftnl_expr_masq_build, .snprintf = nftnl_expr_masq_snprintf, - .json_parse = nftnl_expr_masq_json_parse, }; diff --git a/src/expr/match.c b/src/expr/match.c index dd09e1e..85dd79c 100644 --- a/src/expr/match.c +++ b/src/expr/match.c @@ -164,36 +164,6 @@ static int nftnl_expr_match_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int nftnl_expr_match_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *name; - - name = nftnl_jansson_parse_str(root, "name", err); - if (name != NULL) - nftnl_expr_set_str(e, NFTNL_EXPR_MT_NAME, name); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - - -static int nftnl_expr_match_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_match *mt = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_MT_NAME)) - nftnl_buf_str(&b, type, mt->name, NAME); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -206,7 +176,6 @@ nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type, match->name, match->rev); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_match_export(buf, len, e, type); default: break; } @@ -250,5 +219,4 @@ struct expr_ops expr_ops_match = { .parse = nftnl_expr_match_parse, .build = nftnl_expr_match_build, .snprintf = nftnl_expr_match_snprintf, - .json_parse = nftnl_expr_match_json_parse, }; diff --git a/src/expr/meta.c b/src/expr/meta.c index de82105..b66b9b7 100644 --- a/src/expr/meta.c +++ b/src/expr/meta.c @@ -182,40 +182,6 @@ static inline int str2meta_key(const char *str) return -1; } -static int nftnl_expr_meta_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *key_str; - uint32_t reg; - int key; - - key_str = nftnl_jansson_parse_str(root, "key", err); - if (key_str != NULL) { - key = str2meta_key(key_str); - if (key >= 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_META_KEY, key); - } - - if (nftnl_jansson_node_exist(root, "dreg")) { - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_META_DREG, reg); - } - - if (nftnl_jansson_node_exist(root, "sreg")) { - if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, ®, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_META_SREG, reg); - } - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static int nftnl_expr_meta_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) @@ -233,22 +199,6 @@ nftnl_expr_meta_snprintf_default(char *buf, size_t len, return 0; } -static int nftnl_expr_meta_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_meta *meta = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_META_DREG)) - nftnl_buf_u32(&b, type, meta->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_META_KEY)) - nftnl_buf_str(&b, type, meta_key2str(meta->key), KEY); - if (e->flags & (1 << NFTNL_EXPR_META_SREG)) - nftnl_buf_u32(&b, type, meta->sreg, SREG); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -258,7 +208,6 @@ nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_meta_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_meta_export(buf, len, e, type); default: break; } @@ -292,5 +241,4 @@ struct expr_ops expr_ops_meta = { .parse = nftnl_expr_meta_parse, .build = nftnl_expr_meta_build, .snprintf = nftnl_expr_meta_snprintf, - .json_parse = nftnl_expr_meta_json_parse, }; diff --git a/src/expr/nat.c b/src/expr/nat.c index 9271303..9be78f3 100644 --- a/src/expr/nat.c +++ b/src/expr/nat.c @@ -220,85 +220,6 @@ static inline int nftnl_str2nat(const char *nat) } } -static int nftnl_expr_nat_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *nat_type, *family_str; - uint32_t reg, flags; - int val32; - - nat_type = nftnl_jansson_parse_str(root, "nat_type", err); - if (nat_type == NULL) - return -1; - - val32 = nftnl_str2nat(nat_type); - if (val32 < 0) - return -1; - - nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_TYPE, val32); - - family_str = nftnl_jansson_parse_str(root, "family", err); - if (family_str == NULL) - return -1; - - val32 = nftnl_str2family(family_str); - if (val32 < 0) - return -1; - - nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_FAMILY, val32); - - if (nftnl_jansson_parse_reg(root, "sreg_addr_min", NFTNL_TYPE_U32, - ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_REG_ADDR_MIN, reg); - - if (nftnl_jansson_parse_reg(root, "sreg_addr_max", NFTNL_TYPE_U32, - ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_REG_ADDR_MAX, reg); - - if (nftnl_jansson_parse_reg(root, "sreg_proto_min", NFTNL_TYPE_U32, - ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_REG_PROTO_MIN, reg); - - if (nftnl_jansson_parse_reg(root, "sreg_proto_max", NFTNL_TYPE_U32, - ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_REG_PROTO_MAX, reg); - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, - &flags, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_FLAGS, flags); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_nat_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_nat *nat = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_NAT_TYPE)) - nftnl_buf_str(&b, type, nat2str(nat->type), NAT_TYPE); - if (e->flags & (1 << NFTNL_EXPR_NAT_FAMILY)) - nftnl_buf_str(&b, type, nftnl_family2str(nat->family), FAMILY); - if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MIN)) - nftnl_buf_u32(&b, type, nat->sreg_addr_min, SREG_ADDR_MIN); - if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MAX)) - nftnl_buf_u32(&b, type, nat->sreg_addr_max, SREG_ADDR_MAX); - if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MIN)) - nftnl_buf_u32(&b, type, nat->sreg_proto_min, SREG_PROTO_MIN); - if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MAX)) - nftnl_buf_u32(&b, type, nat->sreg_proto_max, SREG_PROTO_MAX); - if (e->flags & (1 << NFTNL_EXPR_NAT_FLAGS)) - nftnl_buf_u32(&b, type, nat->flags, FLAGS); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_nat_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) @@ -344,7 +265,6 @@ nftnl_expr_nat_snprintf(char *buf, size_t size, uint32_t type, return nftnl_expr_nat_snprintf_default(buf, size, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_nat_export(buf, size, e, type); default: break; } @@ -385,5 +305,4 @@ struct expr_ops expr_ops_nat = { .parse = nftnl_expr_nat_parse, .build = nftnl_expr_nat_build, .snprintf = nftnl_expr_nat_snprintf, - .json_parse = nftnl_expr_nat_json_parse, }; diff --git a/src/expr/numgen.c b/src/expr/numgen.c index 5336fde..d46cf94 100644 --- a/src/expr/numgen.c +++ b/src/expr/numgen.c @@ -179,35 +179,6 @@ nftnl_expr_ng_parse(struct nftnl_expr *e, struct nlattr *attr) return ret; } -static int nftnl_expr_ng_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t dreg, modulus, type, offset; - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, - &dreg, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NG_DREG, dreg); - - if (nftnl_jansson_parse_val(root, "modulus", NFTNL_TYPE_U32, - &modulus, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NG_MODULUS, modulus); - - if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, - &type, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NG_TYPE, type); - - if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32, - &offset, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_NG_OFFSET, offset); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static int nftnl_expr_ng_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) @@ -244,27 +215,6 @@ nftnl_expr_ng_snprintf_default(char *buf, size_t size, return offset; } -static int nftnl_expr_ng_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_ng *ng = nftnl_expr_data(e); - - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_NG_DREG)) - nftnl_buf_u32(&b, type, ng->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_NG_MODULUS)) - nftnl_buf_u32(&b, type, ng->modulus, MODULUS); - if (e->flags & (1 << NFTNL_EXPR_NG_TYPE)) - nftnl_buf_u32(&b, type, ng->type, TYPE); - if (e->flags & (1 << NFTNL_EXPR_NG_OFFSET)) - nftnl_buf_u32(&b, type, ng->type, OFFSET); - if (e->flags & (1 << NFTNL_EXPR_NG_SET_NAME)) - nftnl_buf_str(&b, type, ng->map.name, SET); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -274,7 +224,6 @@ nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_ng_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_ng_export(buf, len, e, type); default: break; } @@ -314,5 +263,4 @@ struct expr_ops expr_ops_ng = { .parse = nftnl_expr_ng_parse, .build = nftnl_expr_ng_build, .snprintf = nftnl_expr_ng_snprintf, - .json_parse = nftnl_expr_ng_json_parse, }; diff --git a/src/expr/objref.c b/src/expr/objref.c index 64ee863..67fd74b 100644 --- a/src/expr/objref.c +++ b/src/expr/objref.c @@ -174,51 +174,6 @@ static int nftnl_expr_objref_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int -nftnl_expr_objref_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t uval32; - const char *str; - - if (nftnl_jansson_node_exist(root, "name")) { - str = nftnl_jansson_parse_str(root, "name", err); - if (str == NULL) - return -1; - - nftnl_expr_set_str(e, NFTNL_EXPR_OBJREF_IMM_NAME, str); - } - - if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_OBJREF_IMM_TYPE, uval32); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_objref_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_objref *objref = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_OBJREF_IMM_TYPE)) - nftnl_buf_u32(&b, type, objref->imm.type, BYTES); - if (e->flags & (1 << NFTNL_EXPR_OBJREF_IMM_NAME)) - nftnl_buf_str(&b, type, objref->imm.name, NAME); - if (e->flags & (1 << NFTNL_EXPR_OBJREF_SET_SREG)) - nftnl_buf_u32(&b, type, objref->set.sreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_OBJREF_SET_NAME)) - nftnl_buf_str(&b, type, objref->set.name, SET); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_objref_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -241,7 +196,6 @@ static int nftnl_expr_objref_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_objref_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_objref_export(buf, len, e, type); default: break; } @@ -279,5 +233,4 @@ struct expr_ops expr_ops_objref = { .parse = nftnl_expr_objref_parse, .build = nftnl_expr_objref_build, .snprintf = nftnl_expr_objref_snprintf, - .json_parse = nftnl_expr_objref_json_parse, }; diff --git a/src/expr/osf.c b/src/expr/osf.c index 6fd62e5..372ebe1 100644 --- a/src/expr/osf.c +++ b/src/expr/osf.c @@ -102,18 +102,6 @@ static int nftnl_expr_osf_snprintf_default(char *buf, size_t size, return offset; } -static int nftnl_expr_osf_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_osf *osf = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_OSF_DREG)) - nftnl_buf_u32(&b, type, osf->dreg, "dreg"); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_osf_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -123,7 +111,6 @@ nftnl_expr_osf_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_osf_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_osf_export(buf, len, e, type); default: break; } diff --git a/src/expr/payload.c b/src/expr/payload.c index 91e1587..4b2f322 100644 --- a/src/expr/payload.c +++ b/src/expr/payload.c @@ -232,59 +232,6 @@ static inline int nftnl_str2base(const char *base) } static int -nftnl_expr_payload_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *base_str; - uint32_t reg, uval32; - int base; - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_DREG, reg); - - base_str = nftnl_jansson_parse_str(root, "base", err); - if (base_str != NULL) { - base = nftnl_str2base(base_str); - if (base < 0) - return -1; - - nftnl_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_BASE, base); - } - - if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_OFFSET, uval32); - - if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &uval32, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_LEN, uval32); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_payload_export(char *buf, size_t size, uint32_t flags, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_payload *payload = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_DREG)) - nftnl_buf_u32(&b, type, payload->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_OFFSET)) - nftnl_buf_u32(&b, type, payload->offset, OFFSET); - if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_LEN)) - nftnl_buf_u32(&b, type, payload->len, LEN); - if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_BASE)) - nftnl_buf_str(&b, type, base2str(payload->base), BASE); - - return nftnl_buf_done(&b); -} - -static int nftnl_expr_payload_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) { @@ -305,7 +252,6 @@ nftnl_expr_payload_snprintf(char *buf, size_t len, uint32_t type, payload->offset, payload->dreg); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_payload_export(buf, len, flags, e, type); default: break; } @@ -349,5 +295,4 @@ struct expr_ops expr_ops_payload = { .parse = nftnl_expr_payload_parse, .build = nftnl_expr_payload_build, .snprintf = nftnl_expr_payload_snprintf, - .json_parse = nftnl_expr_payload_json_parse, }; diff --git a/src/expr/queue.c b/src/expr/queue.c index a392a27..e71df7d 100644 --- a/src/expr/queue.c +++ b/src/expr/queue.c @@ -143,35 +143,6 @@ nftnl_expr_queue_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int -nftnl_expr_queue_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t sreg_qnum; - uint16_t type; - uint16_t code; - - if (nftnl_jansson_parse_val(root, "num", NFTNL_TYPE_U16, &type, err) == 0) - nftnl_expr_set_u16(e, NFTNL_EXPR_QUEUE_NUM, type); - - if (nftnl_jansson_parse_val(root, "total", NFTNL_TYPE_U16, &code, err) == 0) - nftnl_expr_set_u16(e, NFTNL_EXPR_QUEUE_TOTAL, code); - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U16, &code, err) == 0) - nftnl_expr_set_u16(e, NFTNL_EXPR_QUEUE_FLAGS, code); - - if (nftnl_jansson_parse_val(root, "sreg_qnum", NFTNL_TYPE_U32, &sreg_qnum, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_QUEUE_SREG_QNUM, sreg_qnum); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static int nftnl_expr_queue_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -213,24 +184,6 @@ static int nftnl_expr_queue_snprintf_default(char *buf, size_t len, return offset; } -static int nftnl_expr_queue_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_queue *queue = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_QUEUE_NUM)) - nftnl_buf_u32(&b, type, queue->queuenum, NUM); - if (e->flags & (1 << NFTNL_EXPR_QUEUE_TOTAL)) - nftnl_buf_u32(&b, type, queue->queues_total, TOTAL); - if (e->flags & (1 << NFTNL_EXPR_QUEUE_FLAGS)) - nftnl_buf_u32(&b, type, queue->flags, FLAGS); - if (e->flags & (1 << NFTNL_EXPR_QUEUE_SREG_QNUM)) - nftnl_buf_u32(&b, type, queue->sreg_qnum, SREG_QNUM); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -240,7 +193,6 @@ nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_queue_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_queue_export(buf, len, e, type); default: break; } @@ -276,5 +228,4 @@ struct expr_ops expr_ops_queue = { .parse = nftnl_expr_queue_parse, .build = nftnl_expr_queue_build, .snprintf = nftnl_expr_queue_snprintf, - .json_parse = nftnl_expr_queue_json_parse, }; diff --git a/src/expr/quota.c b/src/expr/quota.c index 667e6e1..b280852 100644 --- a/src/expr/quota.c +++ b/src/expr/quota.c @@ -128,47 +128,6 @@ nftnl_expr_quota_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int -nftnl_expr_quota_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint64_t bytes, consumed; - uint32_t flags; - - if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &bytes, - err) == 0) - nftnl_expr_set_u64(e, NFTNL_EXPR_QUOTA_BYTES, bytes); - if (nftnl_jansson_parse_val(root, "consumed", NFTNL_TYPE_U64, &consumed, - err) == 0) - nftnl_expr_set_u64(e, NFTNL_EXPR_QUOTA_CONSUMED, consumed); - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_QUOTA_FLAGS, flags); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_quota_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_quota *quota = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_QUOTA_BYTES)) - nftnl_buf_u64(&b, type, quota->bytes, BYTES); - if (e->flags & (1 << NFTNL_EXPR_QUOTA_CONSUMED)) - nftnl_buf_u64(&b, type, quota->consumed, CONSUMED); - if (e->flags & (1 << NFTNL_EXPR_QUOTA_FLAGS)) - nftnl_buf_u32(&b, type, quota->flags, FLAGS); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_quota_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -188,7 +147,6 @@ static int nftnl_expr_quota_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_quota_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_quota_export(buf, len, e, type); default: break; } @@ -204,5 +162,4 @@ struct expr_ops expr_ops_quota = { .parse = nftnl_expr_quota_parse, .build = nftnl_expr_quota_build, .snprintf = nftnl_expr_quota_snprintf, - .json_parse = nftnl_expr_quota_json_parse, }; diff --git a/src/expr/range.c b/src/expr/range.c index b2789ff..f5a41ac 100644 --- a/src/expr/range.c +++ b/src/expr/range.c @@ -184,61 +184,6 @@ static inline int nftnl_str2range(const char *op) } } -static int nftnl_expr_range_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - struct nftnl_expr_range *range = nftnl_expr_data(e); - const char *op; - uint32_t uval32; - int base; - - if (nftnl_jansson_parse_val(root, "sreg", NFTNL_TYPE_U32, &uval32, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_RANGE_SREG, uval32); - - op = nftnl_jansson_parse_str(root, "op", err); - if (op != NULL) { - base = nftnl_str2range(op); - if (base < 0) - return -1; - - nftnl_expr_set_u32(e, NFTNL_EXPR_RANGE_OP, base); - } - - if (nftnl_jansson_data_reg_parse(root, "data_from", - &range->data_from, err) == DATA_VALUE) - e->flags |= (1 << NFTNL_EXPR_RANGE_FROM_DATA); - - if (nftnl_jansson_data_reg_parse(root, "data_to", - &range->data_to, err) == DATA_VALUE) - e->flags |= (1 << NFTNL_EXPR_RANGE_TO_DATA); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_range_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_range *range = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_RANGE_SREG)) - nftnl_buf_u32(&b, type, range->sreg, SREG); - if (e->flags & (1 << NFTNL_EXPR_RANGE_OP)) - nftnl_buf_str(&b, type, range2str(range->op), OP); - if (e->flags & (1 << NFTNL_EXPR_RANGE_FROM_DATA)) - nftnl_buf_reg(&b, type, &range->data_from, DATA_VALUE, DATA); - if (e->flags & (1 << NFTNL_EXPR_RANGE_TO_DATA)) - nftnl_buf_reg(&b, type, &range->data_to, DATA_VALUE, DATA); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_range_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) { @@ -246,7 +191,7 @@ static int nftnl_expr_range_snprintf_default(char *buf, size_t size, int remain = size, offset = 0, ret; ret = snprintf(buf, remain, "%s reg %u ", - expr_range_str[range->op], range->sreg); + range2str(range->op), range->sreg); SNPRINTF_BUFFER_SIZE(ret, remain, offset); ret = nftnl_data_reg_snprintf(buf + offset, remain, &range->data_from, @@ -268,7 +213,6 @@ static int nftnl_expr_range_snprintf(char *buf, size_t size, uint32_t type, return nftnl_expr_range_snprintf_default(buf, size, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_range_export(buf, size, e, type); default: break; } @@ -284,5 +228,4 @@ struct expr_ops expr_ops_range = { .parse = nftnl_expr_range_parse, .build = nftnl_expr_range_build, .snprintf = nftnl_expr_range_snprintf, - .json_parse = nftnl_expr_range_json_parse, }; diff --git a/src/expr/redir.c b/src/expr/redir.c index b2aa345..1ed4896 100644 --- a/src/expr/redir.c +++ b/src/expr/redir.c @@ -131,48 +131,6 @@ nftnl_expr_redir_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int -nftnl_expr_redir_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t reg, flags; - - if (nftnl_jansson_parse_reg(root, "sreg_proto_min", NFTNL_TYPE_U32, - ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_REDIR_REG_PROTO_MIN, reg); - - if (nftnl_jansson_parse_reg(root, "sreg_proto_max", NFTNL_TYPE_U32, - ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_REDIR_REG_PROTO_MAX, reg); - - if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_REDIR_FLAGS, flags); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_expr_redir_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_redir *redir = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_REDIR_REG_PROTO_MIN)) - nftnl_buf_u32(&b, type, redir->sreg_proto_min, SREG_PROTO_MIN); - if (e->flags & (1 << NFTNL_EXPR_REDIR_REG_PROTO_MAX)) - nftnl_buf_u32(&b, type, redir->sreg_proto_max, SREG_PROTO_MAX); - if (e->flags & (1 << NFTNL_EXPR_REDIR_FLAGS)) - nftnl_buf_u32(&b, type, redir->flags, FLAGS); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_redir_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -209,7 +167,6 @@ nftnl_expr_redir_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_redir_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_redir_export(buf, len, e, type); default: break; } @@ -243,5 +200,4 @@ struct expr_ops expr_ops_redir = { .parse = nftnl_expr_redir_parse, .build = nftnl_expr_redir_build, .snprintf = nftnl_expr_redir_snprintf, - .json_parse = nftnl_expr_redir_json_parse, }; diff --git a/src/expr/reject.c b/src/expr/reject.c index 11d8b20..b26b0cc 100644 --- a/src/expr/reject.c +++ b/src/expr/reject.c @@ -116,27 +116,6 @@ nftnl_expr_reject_parse(struct nftnl_expr *e, struct nlattr *attr) return 0; } -static int -nftnl_expr_reject_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - uint32_t type; - uint8_t code; - - if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &type, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_REJECT_TYPE, type); - - if (nftnl_jansson_parse_val(root, "code", NFTNL_TYPE_U8, &code, err) == 0) - nftnl_expr_set_u8(e, NFTNL_EXPR_REJECT_CODE, code); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static int nftnl_expr_reject_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) { @@ -146,20 +125,6 @@ static int nftnl_expr_reject_snprintf_default(char *buf, size_t len, reject->type, reject->icmp_code); } -static int nftnl_expr_reject_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_reject *reject = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_REJECT_TYPE)) - nftnl_buf_u32(&b, type, reject->type, TYPE); - if (e->flags & (1 << NFTNL_EXPR_REJECT_CODE)) - nftnl_buf_u32(&b, type, reject->icmp_code, CODE); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -169,7 +134,6 @@ nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_reject_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_reject_export(buf, len, e, type); default: break; } @@ -201,5 +165,4 @@ struct expr_ops expr_ops_reject = { .parse = nftnl_expr_reject_parse, .build = nftnl_expr_reject_build, .snprintf = nftnl_expr_reject_snprintf, - .json_parse = nftnl_expr_reject_json_parse, }; diff --git a/src/expr/rt.c b/src/expr/rt.c index 18c3945..2c0c1cf 100644 --- a/src/expr/rt.c +++ b/src/expr/rt.c @@ -141,34 +141,6 @@ static inline int str2rt_key(const char *str) return -1; } -static int nftnl_expr_rt_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *val_str; - uint32_t reg; - int val32; - - val_str = nftnl_jansson_parse_str(root, "key", err); - if (val_str != NULL) { - val32 = str2rt_key(val_str); - if (val32 >= 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_RT_KEY, val32); - } - - if (nftnl_jansson_node_exist(root, "dreg")) { - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, - err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_RT_DREG, reg); - } - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - static int nftnl_expr_rt_snprintf_default(char *buf, size_t len, const struct nftnl_expr *e) @@ -182,20 +154,6 @@ nftnl_expr_rt_snprintf_default(char *buf, size_t len, return 0; } -static int nftnl_expr_rt_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_rt *rt = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_RT_DREG)) - nftnl_buf_u32(&b, type, rt->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_RT_KEY)) - nftnl_buf_str(&b, type, rt_key2str(rt->key), KEY); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -205,7 +163,6 @@ nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_rt_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_rt_export(buf, len, e, type); default: break; } @@ -237,5 +194,4 @@ struct expr_ops expr_ops_rt = { .parse = nftnl_expr_rt_parse, .build = nftnl_expr_rt_build, .snprintf = nftnl_expr_rt_snprintf, - .json_parse = nftnl_expr_rt_json_parse, }; diff --git a/src/expr/socket.c b/src/expr/socket.c index 5fa2ef2..704b1d9 100644 --- a/src/expr/socket.c +++ b/src/expr/socket.c @@ -151,20 +151,6 @@ nftnl_expr_socket_snprintf_default(char *buf, size_t len, return 0; } -static int nftnl_expr_socket_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_socket *socket = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_SOCKET_DREG)) - nftnl_buf_u32(&b, type, socket->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_SOCKET_KEY)) - nftnl_buf_str(&b, type, socket_key2str(socket->key), KEY); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_socket_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -174,7 +160,6 @@ nftnl_expr_socket_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_socket_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_socket_export(buf, len, e, type); default: break; } diff --git a/src/expr/target.c b/src/expr/target.c index ed4bf7d..6ae6c81 100644 --- a/src/expr/target.c +++ b/src/expr/target.c @@ -165,36 +165,6 @@ static int nftnl_expr_target_parse(struct nftnl_expr *e, struct nlattr *attr) } static int -nftnl_expr_target_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *name; - - name = nftnl_jansson_parse_str(root, "name", err); - if (name != NULL) - nftnl_expr_set_str(e, NFTNL_EXPR_TG_NAME, name); - - return 0; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int nftnl_rule_exp_target_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_target *target = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_TG_NAME)) - nftnl_buf_str(&b, type, target->name, NAME); - - return nftnl_buf_done(&b); -} - -static int nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) { @@ -206,7 +176,6 @@ nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type, target->name, target->rev); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_rule_exp_target_export(buf, len, e, type); default: break; } @@ -250,5 +219,4 @@ struct expr_ops expr_ops_target = { .parse = nftnl_expr_target_parse, .build = nftnl_expr_target_build, .snprintf = nftnl_expr_target_snprintf, - .json_parse = nftnl_expr_target_json_parse, }; diff --git a/src/expr/tunnel.c b/src/expr/tunnel.c index 2067c35..677e968 100644 --- a/src/expr/tunnel.c +++ b/src/expr/tunnel.c @@ -150,20 +150,6 @@ nftnl_expr_tunnel_snprintf_default(char *buf, size_t len, return 0; } -static int nftnl_expr_tunnel_export(char *buf, size_t size, - const struct nftnl_expr *e, int type) -{ - struct nftnl_expr_tunnel *tunnel = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_TUNNEL_DREG)) - nftnl_buf_u32(&b, type, tunnel->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_TUNNEL_KEY)) - nftnl_buf_str(&b, type, tunnel_key2str(tunnel->key), KEY); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_tunnel_snprintf(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e) @@ -173,7 +159,6 @@ nftnl_expr_tunnel_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_tunnel_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_tunnel_export(buf, len, e, type); default: break; } diff --git a/src/expr/xfrm.c b/src/expr/xfrm.c index b159d60..dd3062c 100644 --- a/src/expr/xfrm.c +++ b/src/expr/xfrm.c @@ -199,66 +199,6 @@ static int str2xfmrdir(const char *s) } #endif -static int nftnl_expr_xfrm_json_parse(struct nftnl_expr *e, json_t *root, - struct nftnl_parse_err *err) -{ -#ifdef JSON_PARSING - const char *key_str, *dir_str; - uint32_t reg, key, spnum; - uint8_t dir; - - if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, ®, err) == 0) - nftnl_expr_set_u32(e, NFTNL_EXPR_XFRM_DREG, reg); - - key_str = nftnl_jansson_parse_str(root, "key", err); - if (key_str != NULL) { - key = str2xfrmkey(key_str); - if (key < 0) - return -1; - - nftnl_expr_set_u32(e, NFTNL_EXPR_XFRM_KEY, key); - } - - dir_str = nftnl_jansson_parse_str(root, "dir", err); - if (dir_str != NULL) { - dir = str2xfmrdir(dir_str); - if (dir == -1) { - err->node_name = "dir"; - err->error = NFTNL_PARSE_EBADTYPE; - goto err; - } - nftnl_expr_set_u8(e, NFTNL_EXPR_XFRM_DIR, dir); - } - - return 0; -err: - errno = EINVAL; - return -1; -#else - errno = EOPNOTSUPP; - return -1; -#endif -} - -static int -nftnl_expr_xfrm_export(char *buf, size_t size, const struct nftnl_expr *e, - int type) -{ - struct nftnl_expr_xfrm *x = nftnl_expr_data(e); - NFTNL_BUF_INIT(b, buf, size); - - if (e->flags & (1 << NFTNL_EXPR_XFRM_DREG)) - nftnl_buf_u32(&b, type, x->dreg, DREG); - if (e->flags & (1 << NFTNL_EXPR_XFRM_KEY)) - nftnl_buf_str(&b, type, xfrmkey2str(x->key), KEY); - if (e->flags & (1 << NFTNL_EXPR_XFRM_DIR)) - nftnl_buf_str(&b, type, xfrmdir2str(x->dir), DIR); - if (e->flags & (1 << NFTNL_EXPR_XFRM_SPNUM)) - nftnl_buf_u32(&b, type, x->spnum, NUM); - - return nftnl_buf_done(&b); -} - static int nftnl_expr_xfrm_snprintf_default(char *buf, size_t size, const struct nftnl_expr *e) @@ -285,7 +225,6 @@ nftnl_expr_xfrm_snprintf(char *buf, size_t len, uint32_t type, return nftnl_expr_xfrm_snprintf_default(buf, len, e); case NFTNL_OUTPUT_XML: case NFTNL_OUTPUT_JSON: - return nftnl_expr_xfrm_export(buf, len, e, type); default: break; } @@ -321,5 +260,4 @@ struct expr_ops expr_ops_xfrm = { .parse = nftnl_expr_xfrm_parse, .build = nftnl_expr_xfrm_build, .snprintf = nftnl_expr_xfrm_snprintf, - .json_parse = nftnl_expr_xfrm_json_parse, }; |