@@ -18,7 +18,7 @@ struct expr_ops {
const void *(*get)(const struct nftnl_expr *e, uint16_t type, uint32_t *data_len);
int (*parse)(struct nftnl_expr *e, struct nlattr *attr);
void (*build)(struct nlmsghdr *nlh, const struct nftnl_expr *e);
- int (*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e);
+ int (*snprintf)(char *buf, size_t len, uint32_t flags, const struct nftnl_expr *e);
};
struct expr_ops *nftnl_expr_ops_lookup(const char *name);
@@ -279,10 +279,10 @@ int nftnl_expr_snprintf(char *buf, size_t size, const struct nftnl_expr *expr,
if (size)
buf[0] = '\0';
- if (!expr->ops->snprintf)
+ if (!expr->ops->snprintf || type != NFTNL_OUTPUT_DEFAULT)
return 0;
- ret = expr->ops->snprintf(buf + offset, remain, type, flags, expr);
+ ret = expr->ops->snprintf(buf + offset, remain, flags, expr);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
@@ -252,8 +252,9 @@ nftnl_expr_bitwise_snprintf_shift(char *buf, size_t size, const char *op,
return offset;
}
-static int nftnl_expr_bitwise_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_bitwise_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e);
int err = -1;
@@ -273,19 +274,6 @@ static int nftnl_expr_bitwise_snprintf_default(char *buf, size_t size,
return err;
}
-static int
-nftnl_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_bitwise_snprintf_default(buf, size, e);
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_bitwise = {
.name = "bitwise",
.alloc_len = sizeof(struct nftnl_expr_bitwise),
@@ -197,8 +197,9 @@ static inline int nftnl_str2ntoh(const char *op)
}
}
-static int nftnl_expr_byteorder_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_byteorder_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e);
int remain = size, offset = 0, ret;
@@ -211,21 +212,6 @@ static int nftnl_expr_byteorder_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_byteorder_snprintf_default(buf, size, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_byteorder = {
.name = "byteorder",
.alloc_len = sizeof(struct nftnl_expr_byteorder),
@@ -176,8 +176,9 @@ static inline int nftnl_str2cmp(const char *op)
}
}
-static int nftnl_expr_cmp_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_cmp_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_cmp *cmp = nftnl_expr_data(e);
int remain = size, offset = 0, ret;
@@ -193,21 +194,6 @@ static int nftnl_expr_cmp_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_cmp_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_cmp_snprintf_default(buf, size, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_cmp = {
.name = "cmp",
.alloc_len = sizeof(struct nftnl_expr_cmp),
@@ -117,8 +117,9 @@ nftnl_expr_connlimit_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_connlimit_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int nftnl_expr_connlimit_snprintf(char *buf, size_t len,
+ uint32_t flags,
+ const struct nftnl_expr *e)
{
struct nftnl_expr_connlimit *connlimit = nftnl_expr_data(e);
@@ -126,21 +127,6 @@ static int nftnl_expr_connlimit_snprintf_default(char *buf, size_t len,
connlimit->count, connlimit->flags);
}
-static int nftnl_expr_connlimit_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags,
- const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_connlimit_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_connlimit = {
.name = "connlimit",
.alloc_len = sizeof(struct nftnl_expr_connlimit),
@@ -115,8 +115,9 @@ nftnl_expr_counter_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_counter_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int nftnl_expr_counter_snprintf(char *buf, size_t len,
+ uint32_t flags,
+ const struct nftnl_expr *e)
{
struct nftnl_expr_counter *ctr = nftnl_expr_data(e);
@@ -124,21 +125,6 @@ static int nftnl_expr_counter_snprintf_default(char *buf, size_t len,
ctr->pkts, ctr->bytes);
}
-static int nftnl_expr_counter_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags,
- const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_counter_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_counter = {
.name = "counter",
.alloc_len = sizeof(struct nftnl_expr_counter),
@@ -223,8 +223,8 @@ static inline int str2ctdir(const char *str, uint8_t *ctdir)
}
static int
-nftnl_expr_ct_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_ct_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
int ret, remain = size, offset = 0;
struct nftnl_expr_ct *ct = nftnl_expr_data(e);
@@ -250,21 +250,6 @@ nftnl_expr_ct_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_ct_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_ct = {
.name = "ct",
.alloc_len = sizeof(struct nftnl_expr_ct),
@@ -111,9 +111,8 @@ static int nftnl_expr_dup_parse(struct nftnl_expr *e, struct nlattr *attr)
return ret;
}
-static int nftnl_expr_dup_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e,
- uint32_t flags)
+static int nftnl_expr_dup_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
int remain = len, offset = 0, ret;
struct nftnl_expr_dup *dup = nftnl_expr_data(e);
@@ -131,20 +130,6 @@ static int nftnl_expr_dup_snprintf_default(char *buf, size_t len,
return offset;
}
-static int nftnl_expr_dup_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_dup_snprintf_default(buf, len, e, flags);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_dup = {
.name = "dup",
.alloc_len = sizeof(struct nftnl_expr_dup),
@@ -308,8 +308,8 @@ static const char *op2str(enum nft_dynset_ops op)
}
static int
-nftnl_expr_dynset_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_dynset_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_dynset *dynset = nftnl_expr_data(e);
struct nftnl_expr *expr;
@@ -346,21 +346,6 @@ nftnl_expr_dynset_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_dynset_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_dynset_snprintf_default(buf, size, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
static void nftnl_expr_dynset_init(const struct nftnl_expr *e)
{
struct nftnl_expr_dynset *dynset = nftnl_expr_data(e);
@@ -235,8 +235,9 @@ static inline int str2exthdr_type(const char *str)
return -1;
}
-static int nftnl_expr_exthdr_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_exthdr_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e);
@@ -253,21 +254,6 @@ static int nftnl_expr_exthdr_snprintf_default(char *buf, size_t len,
}
-static int
-nftnl_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_exthdr_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_exthdr = {
.name = "exthdr",
.alloc_len = sizeof(struct nftnl_expr_exthdr),
@@ -143,8 +143,8 @@ static const char *fib_type_str(enum nft_fib_result r)
}
static int
-nftnl_expr_fib_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_fib_snprintf(char *buf, size_t size,
+ uint32_t printflags, const struct nftnl_expr *e)
{
struct nftnl_expr_fib *fib = nftnl_expr_data(e);
int remain = size, offset = 0, ret, i;
@@ -190,21 +190,6 @@ nftnl_expr_fib_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_fib_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_fib = {
.name = "fib",
.alloc_len = sizeof(struct nftnl_expr_fib),
@@ -92,8 +92,8 @@ static int nftnl_expr_flow_parse(struct nftnl_expr *e, struct nlattr *attr)
return ret;
}
-static int nftnl_expr_flow_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int nftnl_expr_flow_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
int remain = size, offset = 0, ret;
struct nftnl_expr_flow *l = nftnl_expr_data(e);
@@ -104,20 +104,6 @@ static int nftnl_expr_flow_snprintf_default(char *buf, size_t size,
return offset;
}
-static int nftnl_expr_flow_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_flow_snprintf_default(buf, size, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
static void nftnl_expr_flow_free(const struct nftnl_expr *e)
{
struct nftnl_expr_flow *flow = nftnl_expr_data(e);
@@ -125,9 +125,8 @@ static int nftnl_expr_fwd_parse(struct nftnl_expr *e, struct nlattr *attr)
return ret;
}
-static int nftnl_expr_fwd_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e,
- uint32_t flags)
+static int nftnl_expr_fwd_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
int remain = len, offset = 0, ret;
struct nftnl_expr_fwd *fwd = nftnl_expr_data(e);
@@ -151,20 +150,6 @@ static int nftnl_expr_fwd_snprintf_default(char *buf, size_t len,
return offset;
}
-static int nftnl_expr_fwd_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_fwd_snprintf_default(buf, len, e, flags);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_fwd = {
.name = "fwd",
.alloc_len = sizeof(struct nftnl_expr_fwd),
@@ -184,8 +184,8 @@ nftnl_expr_hash_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_hash_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_hash_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_hash *hash = nftnl_expr_data(e);
int remain = size, offset = 0, ret;
@@ -218,21 +218,6 @@ nftnl_expr_hash_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_hash_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_hash = {
.name = "hash",
.alloc_len = sizeof(struct nftnl_expr_hash),
@@ -184,9 +184,8 @@ nftnl_expr_immediate_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_immediate_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e,
- uint32_t flags)
+nftnl_expr_immediate_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
int remain = len, offset = 0, ret;
struct nftnl_expr_immediate *imm = nftnl_expr_data(e);
@@ -213,21 +212,6 @@ nftnl_expr_immediate_snprintf_default(char *buf, size_t len,
return offset;
}
-static int
-nftnl_expr_immediate_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_immediate_snprintf_default(buf, len, e, flags);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
static void nftnl_expr_immediate_free(const struct nftnl_expr *e)
{
struct nftnl_expr_immediate *imm = nftnl_expr_data(e);
@@ -183,8 +183,9 @@ static const char *limit_to_type(enum nft_limit_type type)
}
}
-static int nftnl_expr_limit_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_limit_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_limit *limit = nftnl_expr_data(e);
@@ -193,21 +194,6 @@ static int nftnl_expr_limit_snprintf_default(char *buf, size_t len,
limit_to_type(limit->type), limit->flags);
}
-static int
-nftnl_expr_limit_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_limit_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_limit = {
.name = "limit",
.alloc_len = sizeof(struct nftnl_expr_limit),
@@ -186,8 +186,9 @@ nftnl_expr_log_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_log_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_log_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_log *log = nftnl_expr_data(e);
int ret, offset = 0, remain = size;
@@ -236,21 +237,6 @@ static int nftnl_expr_log_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_log_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
static void nftnl_expr_log_free(const struct nftnl_expr *e)
{
struct nftnl_expr_log *log = nftnl_expr_data(e);
@@ -168,8 +168,8 @@ nftnl_expr_lookup_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_lookup_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_lookup_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
int remain = size, offset = 0, ret;
struct nftnl_expr_lookup *l = nftnl_expr_data(e);
@@ -190,21 +190,6 @@ nftnl_expr_lookup_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_lookup_snprintf_default(buf, size, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
static void nftnl_expr_lookup_free(const struct nftnl_expr *e)
{
struct nftnl_expr_lookup *lookup = nftnl_expr_data(e);
@@ -131,8 +131,8 @@ nftnl_expr_masq_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_masq_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int nftnl_expr_masq_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_masq *masq = nftnl_expr_data(e);
int remain = len, offset = 0, ret = 0;
@@ -155,20 +155,6 @@ static int nftnl_expr_masq_snprintf_default(char *buf, size_t len,
return offset;
}
-static int nftnl_expr_masq_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_masq_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_masq = {
.name = "masq",
.alloc_len = sizeof(struct nftnl_expr_masq),
@@ -165,21 +165,12 @@ static int nftnl_expr_match_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type,
+nftnl_expr_match_snprintf(char *buf, size_t len,
uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_match *match = nftnl_expr_data(e);
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return snprintf(buf, len, "name %s rev %u ",
- match->name, match->rev);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
+ return snprintf(buf, len, "name %s rev %u ", match->name, match->rev);
}
static void nftnl_expr_match_free(const struct nftnl_expr *e)
@@ -192,8 +192,8 @@ static inline int str2meta_key(const char *str)
}
static int
-nftnl_expr_meta_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+nftnl_expr_meta_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_meta *meta = nftnl_expr_data(e);
@@ -208,21 +208,6 @@ nftnl_expr_meta_snprintf_default(char *buf, size_t len,
return 0;
}
-static int
-nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_meta_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_meta = {
.name = "meta",
.alloc_len = sizeof(struct nftnl_expr_meta),
@@ -221,8 +221,8 @@ static inline int nftnl_str2nat(const char *nat)
}
static int
-nftnl_expr_nat_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_nat_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_nat *nat = nftnl_expr_data(e);
int remain = size, offset = 0, ret = 0;
@@ -266,21 +266,6 @@ nftnl_expr_nat_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_nat_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_nat_snprintf_default(buf, size, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_nat = {
.name = "nat",
.alloc_len = sizeof(struct nftnl_expr_nat),
@@ -143,8 +143,8 @@ nftnl_expr_ng_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_ng_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_ng_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_ng *ng = nftnl_expr_data(e);
int remain = size, offset = 0, ret;
@@ -172,21 +172,6 @@ nftnl_expr_ng_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_ng_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_ng = {
.name = "numgen",
.alloc_len = sizeof(struct nftnl_expr_ng),
@@ -174,8 +174,9 @@ static int nftnl_expr_objref_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_objref_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int nftnl_expr_objref_snprintf(char *buf, size_t len,
+ uint32_t flags,
+ const struct nftnl_expr *e)
{
struct nftnl_expr_objref *objref = nftnl_expr_data(e);
@@ -195,21 +196,6 @@ static void nftnl_expr_objref_free(const struct nftnl_expr *e)
xfree(objref->set.name);
}
-static int nftnl_expr_objref_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags,
- const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_objref_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_objref = {
.name = "objref",
.alloc_len = sizeof(struct nftnl_expr_objref),
@@ -124,8 +124,9 @@ nftnl_expr_osf_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_osf_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_osf_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_osf *osf = nftnl_expr_data(e);
int ret, offset = 0, len = size;
@@ -138,21 +139,6 @@ static int nftnl_expr_osf_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_osf_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_osf_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_osf = {
.name = "osf",
.alloc_len = sizeof(struct nftnl_expr_osf),
@@ -232,30 +232,22 @@ static inline int nftnl_str2base(const char *base)
}
static int
-nftnl_expr_payload_snprintf(char *buf, size_t len, uint32_t type,
+nftnl_expr_payload_snprintf(char *buf, size_t len,
uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_payload *payload = nftnl_expr_data(e);
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- if (payload->sreg)
- return snprintf(buf, len, "write reg %u => %ub @ %s header + %u csum_type %u csum_off %u csum_flags 0x%x ",
- payload->sreg,
- payload->len, base2str(payload->base),
- payload->offset, payload->csum_type,
- payload->csum_offset,
- payload->csum_flags);
- else
- return snprintf(buf, len, "load %ub @ %s header + %u => reg %u ",
- payload->len, base2str(payload->base),
- payload->offset, payload->dreg);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
+ if (payload->sreg)
+ return snprintf(buf, len, "write reg %u => %ub @ %s header + %u csum_type %u csum_off %u csum_flags 0x%x ",
+ payload->sreg,
+ payload->len, base2str(payload->base),
+ payload->offset, payload->csum_type,
+ payload->csum_offset,
+ payload->csum_flags);
+ else
+ return snprintf(buf, len, "load %ub @ %s header + %u => reg %u ",
+ payload->len, base2str(payload->base),
+ payload->offset, payload->dreg);
}
struct expr_ops expr_ops_payload = {
@@ -143,8 +143,9 @@ nftnl_expr_queue_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_queue_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_queue_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_queue *queue = nftnl_expr_data(e);
int ret, remain = len, offset = 0;
@@ -184,21 +185,6 @@ static int nftnl_expr_queue_snprintf_default(char *buf, size_t len,
return offset;
}
-static int
-nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_queue_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_queue = {
.name = "queue",
.alloc_len = sizeof(struct nftnl_expr_queue),
@@ -128,8 +128,9 @@ nftnl_expr_quota_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_quota_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int nftnl_expr_quota_snprintf(char *buf, size_t len,
+ uint32_t flags,
+ const struct nftnl_expr *e)
{
struct nftnl_expr_quota *quota = nftnl_expr_data(e);
@@ -138,21 +139,6 @@ static int nftnl_expr_quota_snprintf_default(char *buf, size_t len,
quota->bytes, quota->consumed, quota->flags);
}
-static int nftnl_expr_quota_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags,
- const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_quota_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_quota = {
.name = "quota",
.alloc_len = sizeof(struct nftnl_expr_quota),
@@ -184,8 +184,8 @@ static inline int nftnl_str2range(const char *op)
}
}
-static int nftnl_expr_range_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int nftnl_expr_range_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_range *range = nftnl_expr_data(e);
int remain = size, offset = 0, ret;
@@ -205,20 +205,6 @@ static int nftnl_expr_range_snprintf_default(char *buf, size_t size,
return offset;
}
-static int nftnl_expr_range_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_range_snprintf_default(buf, size, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_range = {
.name = "range",
.alloc_len = sizeof(struct nftnl_expr_range),
@@ -131,8 +131,9 @@ nftnl_expr_redir_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_redir_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_redir_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
int ret, remain = len, offset = 0;
struct nftnl_expr_redir *redir = nftnl_expr_data(e);
@@ -158,21 +159,6 @@ static int nftnl_expr_redir_snprintf_default(char *buf, size_t len,
return offset;
}
-static int
-nftnl_expr_redir_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_redir_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_redir = {
.name = "redir",
.alloc_len = sizeof(struct nftnl_expr_redir),
@@ -116,8 +116,9 @@ nftnl_expr_reject_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_reject_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_reject_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_reject *reject = nftnl_expr_data(e);
@@ -125,21 +126,6 @@ static int nftnl_expr_reject_snprintf_default(char *buf, size_t len,
reject->type, reject->icmp_code);
}
-static int
-nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_reject_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_reject = {
.name = "reject",
.alloc_len = sizeof(struct nftnl_expr_reject),
@@ -142,8 +142,8 @@ static inline int str2rt_key(const char *str)
}
static int
-nftnl_expr_rt_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+nftnl_expr_rt_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_rt *rt = nftnl_expr_data(e);
@@ -154,21 +154,6 @@ nftnl_expr_rt_snprintf_default(char *buf, size_t len,
return 0;
}
-static int
-nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_rt_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_rt = {
.name = "rt",
.alloc_len = sizeof(struct nftnl_expr_rt),
@@ -127,8 +127,8 @@ static const char *socket_key2str(uint8_t key)
}
static int
-nftnl_expr_socket_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+nftnl_expr_socket_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_socket *socket = nftnl_expr_data(e);
@@ -139,21 +139,6 @@ nftnl_expr_socket_snprintf_default(char *buf, size_t len,
return 0;
}
-static int
-nftnl_expr_socket_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_socket_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_socket = {
.name = "socket",
.alloc_len = sizeof(struct nftnl_expr_socket),
@@ -127,8 +127,9 @@ nftnl_expr_synproxy_parse(struct nftnl_expr *e, struct nlattr *attr)
return 0;
}
-static int nftnl_expr_synproxy_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+static int
+nftnl_expr_synproxy_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_synproxy *synproxy = nftnl_expr_data(e);
int ret, offset = 0, len = size;
@@ -143,21 +144,6 @@ static int nftnl_expr_synproxy_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_synproxy_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_synproxy_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_synproxy = {
.name = "synproxy",
.alloc_len = sizeof(struct nftnl_expr_synproxy),
@@ -165,21 +165,12 @@ static int nftnl_expr_target_parse(struct nftnl_expr *e, struct nlattr *attr)
}
static int
-nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type,
+nftnl_expr_target_snprintf(char *buf, size_t len,
uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_target *target = nftnl_expr_data(e);
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return snprintf(buf, len, "name %s rev %u ",
- target->name, target->rev);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
+ return snprintf(buf, len, "name %s rev %u ", target->name, target->rev);
}
static void nftnl_expr_target_free(const struct nftnl_expr *e)
@@ -135,8 +135,8 @@ nftnl_expr_tproxy_build(struct nlmsghdr *nlh, const struct nftnl_expr *e)
}
static int
-nftnl_expr_tproxy_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_tproxy_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_tproxy *tproxy = nftnl_expr_data(e);
int remain = size, offset = 0, ret = 0;
@@ -162,19 +162,6 @@ nftnl_expr_tproxy_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_tproxy_snprintf(char *buf, size_t size, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_tproxy_snprintf_default(buf, size, e);
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_tproxy = {
.name = "tproxy",
.alloc_len = sizeof(struct nftnl_expr_tproxy),
@@ -125,8 +125,8 @@ static const char *tunnel_key2str(uint8_t key)
}
static int
-nftnl_expr_tunnel_snprintf_default(char *buf, size_t len,
- const struct nftnl_expr *e)
+nftnl_expr_tunnel_snprintf(char *buf, size_t len,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_tunnel *tunnel = nftnl_expr_data(e);
@@ -137,21 +137,6 @@ nftnl_expr_tunnel_snprintf_default(char *buf, size_t len,
return 0;
}
-static int
-nftnl_expr_tunnel_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_tunnel_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_tunnel = {
.name = "tunnel",
.alloc_len = sizeof(struct nftnl_expr_tunnel),
@@ -172,8 +172,8 @@ static const char *xfrmdir2str(uint8_t dir)
}
static int
-nftnl_expr_xfrm_snprintf_default(char *buf, size_t size,
- const struct nftnl_expr *e)
+nftnl_expr_xfrm_snprintf(char *buf, size_t size,
+ uint32_t flags, const struct nftnl_expr *e)
{
struct nftnl_expr_xfrm *x = nftnl_expr_data(e);
int ret, remain = size, offset = 0;
@@ -188,21 +188,6 @@ nftnl_expr_xfrm_snprintf_default(char *buf, size_t size,
return offset;
}
-static int
-nftnl_expr_xfrm_snprintf(char *buf, size_t len, uint32_t type,
- uint32_t flags, const struct nftnl_expr *e)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- return nftnl_expr_xfrm_snprintf_default(buf, len, e);
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
- break;
- }
- return -1;
-}
-
struct expr_ops expr_ops_xfrm = {
.name = "xfrm",
.alloc_len = sizeof(struct nftnl_expr_xfrm),
There is but a single supported output type left, so check it in expr.c and drop all the single option switch statements in individual expressions. Since the parameter is now unused (and to ensure code correctness), drop 'type' parameter from struct expr_ops' snprintf callback. Signed-off-by: Phil Sutter <phil@nwl.cc> --- include/expr_ops.h | 2 +- src/expr.c | 4 ++-- src/expr/bitwise.c | 18 +++--------------- src/expr/byteorder.c | 20 +++----------------- src/expr/cmp.c | 20 +++----------------- src/expr/connlimit.c | 20 +++----------------- src/expr/counter.c | 20 +++----------------- src/expr/ct.c | 19 ++----------------- src/expr/dup.c | 19 ++----------------- src/expr/dynset.c | 19 ++----------------- src/expr/exthdr.c | 20 +++----------------- src/expr/fib.c | 19 ++----------------- src/expr/flow_offload.c | 18 ++---------------- src/expr/fwd.c | 19 ++----------------- src/expr/hash.c | 19 ++----------------- src/expr/immediate.c | 20 ++------------------ src/expr/limit.c | 20 +++----------------- src/expr/log.c | 20 +++----------------- src/expr/lookup.c | 19 ++----------------- src/expr/masq.c | 18 ++---------------- src/expr/match.c | 13 ++----------- src/expr/meta.c | 19 ++----------------- src/expr/nat.c | 19 ++----------------- src/expr/numgen.c | 19 ++----------------- src/expr/objref.c | 20 +++----------------- src/expr/osf.c | 20 +++----------------- src/expr/payload.c | 32 ++++++++++++-------------------- src/expr/queue.c | 20 +++----------------- src/expr/quota.c | 20 +++----------------- src/expr/range.c | 18 ++---------------- src/expr/redir.c | 20 +++----------------- src/expr/reject.c | 20 +++----------------- src/expr/rt.c | 19 ++----------------- src/expr/socket.c | 19 ++----------------- src/expr/synproxy.c | 20 +++----------------- src/expr/target.c | 13 ++----------- src/expr/tproxy.c | 17 ++--------------- src/expr/tunnel.c | 19 ++----------------- src/expr/xfrm.c | 19 ++----------------- 39 files changed, 102 insertions(+), 617 deletions(-)