diff options
Diffstat (limited to 'src/expr/limit.c')
-rw-r--r-- | src/expr/limit.c | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/src/expr/limit.c b/src/expr/limit.c index 3ad246e..b323c5c 100644 --- a/src/expr/limit.c +++ b/src/expr/limit.c @@ -22,22 +22,22 @@ #include <libnftnl/expr.h> #include <libnftnl/rule.h> -struct nft_expr_limit { +struct nftnl_expr_limit { uint64_t rate; uint64_t unit; }; static int -nft_rule_expr_limit_set(struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_limit_set(struct nftnl_rule_expr *e, uint16_t type, const void *data, uint32_t data_len) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_LIMIT_RATE: + case NFTNL_EXPR_LIMIT_RATE: limit->rate = *((uint64_t *)data); break; - case NFT_EXPR_LIMIT_UNIT: + case NFTNL_EXPR_LIMIT_UNIT: limit->unit = *((uint64_t *)data); break; default: @@ -47,23 +47,23 @@ nft_rule_expr_limit_set(struct nft_rule_expr *e, uint16_t type, } static const void * -nft_rule_expr_limit_get(const struct nft_rule_expr *e, uint16_t type, +nftnl_rule_expr_limit_get(const struct nftnl_rule_expr *e, uint16_t type, uint32_t *data_len) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); switch(type) { - case NFT_EXPR_LIMIT_RATE: + case NFTNL_EXPR_LIMIT_RATE: *data_len = sizeof(uint64_t); return &limit->rate; - case NFT_EXPR_LIMIT_UNIT: + case NFTNL_EXPR_LIMIT_UNIT: *data_len = sizeof(uint64_t); return &limit->unit; } return NULL; } -static int nft_rule_expr_limit_cb(const struct nlattr *attr, void *data) +static int nftnl_rule_expr_limit_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; int type = mnl_attr_get_type(attr); @@ -84,48 +84,48 @@ static int nft_rule_expr_limit_cb(const struct nlattr *attr, void *data) } static void -nft_rule_expr_limit_build(struct nlmsghdr *nlh, struct nft_rule_expr *e) +nftnl_rule_expr_limit_build(struct nlmsghdr *nlh, struct nftnl_rule_expr *e) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); - if (e->flags & (1 << NFT_EXPR_LIMIT_RATE)) + if (e->flags & (1 << NFTNL_EXPR_LIMIT_RATE)) mnl_attr_put_u64(nlh, NFTA_LIMIT_RATE, htobe64(limit->rate)); - if (e->flags & (1 << NFT_EXPR_LIMIT_UNIT)) + if (e->flags & (1 << NFTNL_EXPR_LIMIT_UNIT)) mnl_attr_put_u64(nlh, NFTA_LIMIT_UNIT, htobe64(limit->unit)); } static int -nft_rule_expr_limit_parse(struct nft_rule_expr *e, struct nlattr *attr) +nftnl_rule_expr_limit_parse(struct nftnl_rule_expr *e, struct nlattr *attr) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); struct nlattr *tb[NFTA_LIMIT_MAX+1] = {}; - if (mnl_attr_parse_nested(attr, nft_rule_expr_limit_cb, tb) < 0) + if (mnl_attr_parse_nested(attr, nftnl_rule_expr_limit_cb, tb) < 0) return -1; if (tb[NFTA_LIMIT_RATE]) { limit->rate = be64toh(mnl_attr_get_u64(tb[NFTA_LIMIT_RATE])); - e->flags |= (1 << NFT_EXPR_LIMIT_RATE); + e->flags |= (1 << NFTNL_EXPR_LIMIT_RATE); } if (tb[NFTA_LIMIT_UNIT]) { limit->unit = be64toh(mnl_attr_get_u64(tb[NFTA_LIMIT_UNIT])); - e->flags |= (1 << NFT_EXPR_LIMIT_UNIT); + e->flags |= (1 << NFTNL_EXPR_LIMIT_UNIT); } return 0; } -static int nft_rule_expr_limit_json_parse(struct nft_rule_expr *e, json_t *root, - struct nft_parse_err *err) +static int nftnl_rule_expr_limit_json_parse(struct nftnl_rule_expr *e, json_t *root, + struct nftnl_parse_err *err) { #ifdef JSON_PARSING uint64_t uval64; - if (nft_jansson_parse_val(root, "rate", NFT_TYPE_U64, &uval64, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_RATE, uval64); + if (nftnl_jansson_parse_val(root, "rate", NFTNL_TYPE_U64, &uval64, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_LIMIT_RATE, uval64); - if (nft_jansson_parse_val(root, "unit", NFT_TYPE_U64, &uval64, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_UNIT, uval64); + if (nftnl_jansson_parse_val(root, "unit", NFTNL_TYPE_U64, &uval64, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_LIMIT_UNIT, uval64); return 0; #else @@ -134,20 +134,20 @@ static int nft_rule_expr_limit_json_parse(struct nft_rule_expr *e, json_t *root, #endif } -static int nft_rule_expr_limit_xml_parse(struct nft_rule_expr *e, +static int nftnl_rule_expr_limit_xml_parse(struct nftnl_rule_expr *e, mxml_node_t *tree, - struct nft_parse_err *err) + struct nftnl_parse_err *err) { #ifdef XML_PARSING uint64_t rate, unit; - if (nft_mxml_num_parse(tree, "rate", MXML_DESCEND_FIRST, BASE_DEC, - &rate, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_RATE, rate); + if (nftnl_mxml_num_parse(tree, "rate", MXML_DESCEND_FIRST, BASE_DEC, + &rate, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_LIMIT_RATE, rate); - if (nft_mxml_num_parse(tree, "unit", MXML_DESCEND_FIRST, BASE_DEC, - &unit, NFT_TYPE_U64, NFT_XML_MAND, err) == 0) - nft_rule_expr_set_u64(e, NFT_EXPR_LIMIT_UNIT, unit); + if (nftnl_mxml_num_parse(tree, "unit", MXML_DESCEND_FIRST, BASE_DEC, + &unit, NFTNL_TYPE_U64, NFTNL_XML_MAND, err) == 0) + nftnl_rule_expr_set_u64(e, NFTNL_EXPR_LIMIT_UNIT, unit); return 0; #else @@ -168,40 +168,40 @@ static const char *get_unit(uint64_t u) return "error"; } -static int nft_rule_expr_limit_export(char *buf, size_t size, - struct nft_rule_expr *e, int type) +static int nftnl_rule_expr_limit_export(char *buf, size_t size, + struct nftnl_rule_expr *e, int type) { - struct nft_expr_limit *limit = nft_expr_data(e); - NFT_BUF_INIT(b, buf, size); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); + NFTNL_BUF_INIT(b, buf, size); - if (e->flags & (1 << NFT_EXPR_LIMIT_RATE)) - nft_buf_u64(&b, type, limit->rate, RATE); - if (e->flags & (1 << NFT_EXPR_LIMIT_UNIT)) - nft_buf_u64(&b, type, limit->unit, UNIT); + 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); - return nft_buf_done(&b); + return nftnl_buf_done(&b); } -static int nft_rule_expr_limit_snprintf_default(char *buf, size_t len, - struct nft_rule_expr *e) +static int nftnl_rule_expr_limit_snprintf_default(char *buf, size_t len, + struct nftnl_rule_expr *e) { - struct nft_expr_limit *limit = nft_expr_data(e); + struct nftnl_expr_limit *limit = nftnl_expr_data(e); return snprintf(buf, len, "rate %"PRIu64"/%s ", limit->rate, get_unit(limit->unit)); } static int -nft_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, struct nft_rule_expr *e) +nftnl_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, struct nftnl_rule_expr *e) { switch(type) { - case NFT_OUTPUT_DEFAULT: - return nft_rule_expr_limit_snprintf_default(buf, len, e); - case NFT_OUTPUT_XML: - case NFT_OUTPUT_JSON: - return nft_rule_expr_limit_export(buf, len, e, type); + case NFTNL_OUTPUT_DEFAULT: + return nftnl_rule_expr_limit_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + return nftnl_rule_expr_limit_export(buf, len, e, type); default: break; } @@ -210,13 +210,13 @@ nft_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type, struct expr_ops expr_ops_limit = { .name = "limit", - .alloc_len = sizeof(struct nft_expr_limit), + .alloc_len = sizeof(struct nftnl_expr_limit), .max_attr = NFTA_LIMIT_MAX, - .set = nft_rule_expr_limit_set, - .get = nft_rule_expr_limit_get, - .parse = nft_rule_expr_limit_parse, - .build = nft_rule_expr_limit_build, - .snprintf = nft_rule_expr_limit_snprintf, - .xml_parse = nft_rule_expr_limit_xml_parse, - .json_parse = nft_rule_expr_limit_json_parse, + .set = nftnl_rule_expr_limit_set, + .get = nftnl_rule_expr_limit_get, + .parse = nftnl_rule_expr_limit_parse, + .build = nftnl_rule_expr_limit_build, + .snprintf = nftnl_rule_expr_limit_snprintf, + .xml_parse = nftnl_rule_expr_limit_xml_parse, + .json_parse = nftnl_rule_expr_limit_json_parse, }; |