@@ -890,17 +890,11 @@ static int nftnl_chain_cmd_snprintf(char *buf, size_t remain,
{
int ret, offset = 0;
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- ret = nftnl_chain_snprintf_default(buf + offset, remain, c);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- break;
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
+ if (type != NFTNL_OUTPUT_DEFAULT)
return -1;
- }
+ ret = nftnl_chain_snprintf_default(buf + offset, remain, c);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}
@@ -630,18 +630,11 @@ static int nftnl_flowtable_cmd_snprintf(char *buf, size_t remain,
{
int ret, offset = 0;
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- ret = nftnl_flowtable_snprintf_default(buf + offset, remain, c);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- break;
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- break;
- default:
+ if (type != NFTNL_OUTPUT_DEFAULT)
return -1;
- }
+ ret = nftnl_flowtable_snprintf_default(buf + offset, remain, c);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}
@@ -162,15 +162,11 @@ static int nftnl_gen_cmd_snprintf(char *buf, size_t remain,
{
int ret, offset = 0;
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- ret = snprintf(buf, remain, "ruleset generation ID %u", gen->id);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- break;
- default:
+ if (type != NFTNL_OUTPUT_DEFAULT)
return -1;
- }
+ ret = snprintf(buf, remain, "ruleset generation ID %u", gen->id);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}
@@ -411,18 +411,11 @@ static int nftnl_obj_cmd_snprintf(char *buf, size_t remain,
{
int ret, offset = 0;
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- ret = nftnl_obj_snprintf_dflt(buf + offset, remain, obj, type,
- flags);
- break;
- case NFTNL_OUTPUT_JSON:
- case NFTNL_OUTPUT_XML:
- default:
+ if (type != NFTNL_OUTPUT_DEFAULT)
return -1;
- }
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+ ret = nftnl_obj_snprintf_dflt(buf + offset, remain, obj, type, flags);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}
@@ -644,18 +644,12 @@ static int nftnl_rule_cmd_snprintf(char *buf, size_t remain,
inner_flags &= ~NFTNL_OF_EVENT_ANY;
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- ret = nftnl_rule_snprintf_default(buf + offset, remain, r, type,
- inner_flags);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- break;
- case NFTNL_OUTPUT_JSON:
- case NFTNL_OUTPUT_XML:
- default:
+ if (type != NFTNL_OUTPUT_DEFAULT)
return -1;
- }
+ ret = nftnl_rule_snprintf_default(buf + offset, remain, r, type,
+ inner_flags);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}
@@ -522,21 +522,6 @@ nftnl_ruleset_do_snprintf(char *buf, size_t remain,
return offset;
}
-static int nftnl_ruleset_cmd_snprintf(char *buf, size_t size,
- const struct nftnl_ruleset *r, uint32_t cmd,
- uint32_t type, uint32_t flags)
-{
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- case NFTNL_OUTPUT_JSON:
- return nftnl_ruleset_do_snprintf(buf, size, r, cmd, type, flags);
- case NFTNL_OUTPUT_XML:
- default:
- errno = EOPNOTSUPP;
- return -1;
- }
-}
-
EXPORT_SYMBOL(nftnl_ruleset_snprintf);
int nftnl_ruleset_snprintf(char *buf, size_t size, const struct nftnl_ruleset *r,
uint32_t type, uint32_t flags)
@@ -544,17 +529,12 @@ int nftnl_ruleset_snprintf(char *buf, size_t size, const struct nftnl_ruleset *r
if (size)
buf[0] = '\0';
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- case NFTNL_OUTPUT_JSON:
- return nftnl_ruleset_cmd_snprintf(buf, size, r,
- nftnl_flag2cmd(flags), type,
- flags);
- case NFTNL_OUTPUT_XML:
- default:
+ if (type != NFTNL_OUTPUT_DEFAULT) {
errno = EOPNOTSUPP;
return -1;
}
+ return nftnl_ruleset_do_snprintf(buf, size, r, nftnl_flag2cmd(flags),
+ type, flags);
}
static int nftnl_ruleset_fprintf_tables(FILE *fp, const struct nftnl_ruleset *rs,
@@ -843,22 +843,15 @@ static int nftnl_set_cmd_snprintf(char *buf, size_t remain,
uint32_t inner_flags = flags;
int ret, offset = 0;
- if (type == NFTNL_OUTPUT_XML)
- return 0;
+ if (type != NFTNL_OUTPUT_DEFAULT)
+ return -1;
/* prevent set_elems to print as events */
inner_flags &= ~NFTNL_OF_EVENT_ANY;
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- ret = nftnl_set_snprintf_default(buf + offset, remain, s, type,
- inner_flags);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- break;
- default:
- return -1;
- }
-
+ ret = nftnl_set_snprintf_default(buf + offset, remain, s, type,
+ inner_flags);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}
@@ -757,19 +757,12 @@ static int nftnl_set_elem_cmd_snprintf(char *buf, size_t remain,
{
int ret, offset = 0;
- switch(type) {
- case NFTNL_OUTPUT_DEFAULT:
- ret = nftnl_set_elem_snprintf_default(buf + offset, remain, e,
- NFT_DATA_VALUE);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- break;
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- break;
- default:
+ if (type != NFTNL_OUTPUT_DEFAULT)
return -1;
- }
+ ret = nftnl_set_elem_snprintf_default(buf + offset, remain, e,
+ NFT_DATA_VALUE);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}
@@ -373,17 +373,11 @@ static int nftnl_table_cmd_snprintf(char *buf, size_t remain,
{
int ret, offset = 0;
- switch (type) {
- case NFTNL_OUTPUT_DEFAULT:
- ret = nftnl_table_snprintf_default(buf + offset, remain, t);
- SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- break;
- case NFTNL_OUTPUT_XML:
- case NFTNL_OUTPUT_JSON:
- default:
+ if (type != NFTNL_OUTPUT_DEFAULT)
return -1;
- }
+ ret = nftnl_table_snprintf_default(buf + offset, remain, t);
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
}
Replace each by a conditional testing the only valid case. There is one odd example, namely src/set.c: When printing a set with type NFTNL_OUTPUT_XML, the relevant function would return 0 instead of -1 like all others. Just drop it assuming nothing depends on that (faulty) behaviour. Cc: Arturo Borrero <arturo.borrero.glez@gmail.com> Signed-off-by: Phil Sutter <phil@nwl.cc> --- src/chain.c | 12 +++--------- src/flowtable.c | 13 +++---------- src/gen.c | 10 +++------- src/object.c | 13 +++---------- src/rule.c | 14 ++++---------- src/ruleset.c | 26 +++----------------------- src/set.c | 17 +++++------------ src/set_elem.c | 15 ++++----------- src/table.c | 12 +++--------- 9 files changed, 31 insertions(+), 101 deletions(-)