From 4f6e671b462180ba9af12bd30211811b5fca8cb1 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 9 Mar 2021 12:01:19 +0100 Subject: obj: Drop type parameter from snprintf callback Objects don't support any other output type than NFTNL_OUTPUT_DEFAULT, so just drop the parameter. Signed-off-by: Phil Sutter --- src/obj/counter.c | 22 ++-------------------- src/obj/ct_expect.c | 22 +++------------------- src/obj/ct_helper.c | 22 +++------------------- src/obj/ct_timeout.c | 22 +++------------------- src/obj/limit.c | 23 +++-------------------- src/obj/quota.c | 23 +++-------------------- src/obj/secmark.c | 23 +++-------------------- src/obj/synproxy.c | 20 +++----------------- src/obj/tunnel.c | 21 ++------------------- src/object.c | 3 +-- 10 files changed, 26 insertions(+), 175 deletions(-) (limited to 'src') diff --git a/src/obj/counter.c b/src/obj/counter.c index 1baba4e..ef0cd20 100644 --- a/src/obj/counter.c +++ b/src/obj/counter.c @@ -109,8 +109,8 @@ nftnl_obj_counter_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_counter_snprintf_default(char *buf, size_t len, - const struct nftnl_obj *e) +static int nftnl_obj_counter_snprintf(char *buf, size_t len, uint32_t flags, + const struct nftnl_obj *e) { struct nftnl_obj_counter *ctr = nftnl_obj_data(e); @@ -118,24 +118,6 @@ static int nftnl_obj_counter_snprintf_default(char *buf, size_t len, ctr->pkts, ctr->bytes); } -static int nftnl_obj_counter_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, - const struct nftnl_obj *e) -{ - if (len) - buf[0] = '\0'; - - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_counter_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} - struct obj_ops obj_ops_counter = { .name = "counter", .type = NFT_OBJECT_COUNTER, diff --git a/src/obj/ct_expect.c b/src/obj/ct_expect.c index 0b4eb8f..c29f99c 100644 --- a/src/obj/ct_expect.c +++ b/src/obj/ct_expect.c @@ -151,8 +151,9 @@ nftnl_obj_ct_expect_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_ct_expect_snprintf_default(char *buf, size_t len, - const struct nftnl_obj *e) +static int nftnl_obj_ct_expect_snprintf(char *buf, size_t len, + uint32_t flags, + const struct nftnl_obj *e) { int ret = 0; int offset = 0, remain = len; @@ -187,23 +188,6 @@ static int nftnl_obj_ct_expect_snprintf_default(char *buf, size_t len, return offset; } -static int nftnl_obj_ct_expect_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, - const struct nftnl_obj *e) -{ - if (len) - buf[0] = '\0'; - - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_ct_expect_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} - struct obj_ops obj_ops_ct_expect = { .name = "ct_expect", .type = NFT_OBJECT_CT_EXPECT, diff --git a/src/obj/ct_helper.c b/src/obj/ct_helper.c index d91f636..c52032a 100644 --- a/src/obj/ct_helper.c +++ b/src/obj/ct_helper.c @@ -131,8 +131,9 @@ nftnl_obj_ct_helper_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_ct_helper_snprintf_default(char *buf, size_t len, - const struct nftnl_obj *e) +static int nftnl_obj_ct_helper_snprintf(char *buf, size_t len, + uint32_t flags, + const struct nftnl_obj *e) { struct nftnl_obj_ct_helper *helper = nftnl_obj_data(e); @@ -140,23 +141,6 @@ static int nftnl_obj_ct_helper_snprintf_default(char *buf, size_t len, helper->name, helper->l3proto, helper->l4proto); } -static int nftnl_obj_ct_helper_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, - const struct nftnl_obj *e) -{ - if (len) - buf[0] = '\0'; - - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_ct_helper_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} - struct obj_ops obj_ops_ct_helper = { .name = "ct_helper", .type = NFT_OBJECT_CT_HELPER, diff --git a/src/obj/ct_timeout.c b/src/obj/ct_timeout.c index c3f577b..a2e5b4f 100644 --- a/src/obj/ct_timeout.c +++ b/src/obj/ct_timeout.c @@ -257,8 +257,9 @@ nftnl_obj_ct_timeout_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_ct_timeout_snprintf_default(char *buf, size_t len, - const struct nftnl_obj *e) +static int nftnl_obj_ct_timeout_snprintf(char *buf, size_t len, + uint32_t flags, + const struct nftnl_obj *e) { int ret = 0; int offset = 0, remain = len; @@ -307,23 +308,6 @@ static int nftnl_obj_ct_timeout_snprintf_default(char *buf, size_t len, return offset; } -static int nftnl_obj_ct_timeout_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, - const struct nftnl_obj *e) -{ - if (len) - buf[0] = '\0'; - - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_ct_timeout_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} - struct obj_ops obj_ops_ct_timeout = { .name = "ct_timeout", .type = NFT_OBJECT_CT_TIMEOUT, diff --git a/src/obj/limit.c b/src/obj/limit.c index 60b0159..8b40f9d 100644 --- a/src/obj/limit.c +++ b/src/obj/limit.c @@ -148,8 +148,9 @@ static int nftnl_obj_limit_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_limit_snprintf_default(char *buf, size_t len, - const struct nftnl_obj *e) +static int nftnl_obj_limit_snprintf(char *buf, size_t len, + uint32_t flags, + const struct nftnl_obj *e) { struct nftnl_obj_limit *limit = nftnl_obj_data(e); @@ -158,24 +159,6 @@ static int nftnl_obj_limit_snprintf_default(char *buf, size_t len, limit->burst, limit->type, limit->flags); } -static int nftnl_obj_limit_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, - const struct nftnl_obj *e) -{ - if (len) - buf[0] = '\0'; - - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_limit_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} - struct obj_ops obj_ops_limit = { .name = "limit", .type = NFT_OBJECT_LIMIT, diff --git a/src/obj/quota.c b/src/obj/quota.c index 1914037..8ab3300 100644 --- a/src/obj/quota.c +++ b/src/obj/quota.c @@ -125,8 +125,9 @@ nftnl_obj_quota_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_quota_snprintf_default(char *buf, size_t len, - const struct nftnl_obj *e) +static int nftnl_obj_quota_snprintf(char *buf, size_t len, + uint32_t flags, + const struct nftnl_obj *e) { struct nftnl_obj_quota *quota = nftnl_obj_data(e); @@ -134,24 +135,6 @@ static int nftnl_obj_quota_snprintf_default(char *buf, size_t len, quota->bytes, quota->flags); } -static int nftnl_obj_quota_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, - const struct nftnl_obj *e) -{ - if (len) - buf[0] = '\0'; - - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_quota_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} - struct obj_ops obj_ops_quota = { .name = "quota", .type = NFT_OBJECT_QUOTA, diff --git a/src/obj/secmark.c b/src/obj/secmark.c index e27b5fa..2ccc803 100644 --- a/src/obj/secmark.c +++ b/src/obj/secmark.c @@ -98,30 +98,13 @@ nftnl_obj_secmark_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_secmark_snprintf_default(char *buf, size_t len, - const struct nftnl_obj *e) -{ - struct nftnl_obj_secmark *secmark = nftnl_obj_data(e); - - return snprintf(buf, len, "context %s ", secmark->ctx); -} - -static int nftnl_obj_secmark_snprintf(char *buf, size_t len, uint32_t type, +static int nftnl_obj_secmark_snprintf(char *buf, size_t len, uint32_t flags, const struct nftnl_obj *e) { - if (len) - buf[0] = '\0'; + struct nftnl_obj_secmark *secmark = nftnl_obj_data(e); - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_secmark_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; + return snprintf(buf, len, "context %s ", secmark->ctx); } struct obj_ops obj_ops_secmark = { diff --git a/src/obj/synproxy.c b/src/obj/synproxy.c index 56ebc85..e3a991b 100644 --- a/src/obj/synproxy.c +++ b/src/obj/synproxy.c @@ -117,8 +117,9 @@ static int nftnl_obj_synproxy_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_synproxy_snprintf_default(char *buf, size_t size, - const struct nftnl_obj *e) +static int nftnl_obj_synproxy_snprintf(char *buf, size_t size, + uint32_t flags, + const struct nftnl_obj *e) { struct nftnl_obj_synproxy *synproxy = nftnl_obj_data(e); int ret, offset = 0, len = size; @@ -133,21 +134,6 @@ static int nftnl_obj_synproxy_snprintf_default(char *buf, size_t size, return offset; } -static int nftnl_obj_synproxy_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, - const struct nftnl_obj *e) -{ - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_synproxy_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} - struct obj_ops obj_ops_synproxy = { .name = "synproxy", .type = NFT_OBJECT_SYNPROXY, diff --git a/src/obj/tunnel.c b/src/obj/tunnel.c index 100aa09..5ede6bd 100644 --- a/src/obj/tunnel.c +++ b/src/obj/tunnel.c @@ -530,31 +530,14 @@ nftnl_obj_tunnel_parse(struct nftnl_obj *e, struct nlattr *attr) return 0; } -static int nftnl_obj_tunnel_snprintf_default(char *buf, size_t len, - const struct nftnl_obj *e) +static int nftnl_obj_tunnel_snprintf(char *buf, size_t len, + uint32_t flags, const struct nftnl_obj *e) { struct nftnl_obj_tunnel *tun = nftnl_obj_data(e); return snprintf(buf, len, "id %u ", tun->id); } -static int nftnl_obj_tunnel_snprintf(char *buf, size_t len, uint32_t type, - uint32_t flags, const struct nftnl_obj *e) -{ - if (len) - buf[0] = '\0'; - - switch (type) { - case NFTNL_OUTPUT_DEFAULT: - return nftnl_obj_tunnel_snprintf_default(buf, len, e); - case NFTNL_OUTPUT_XML: - case NFTNL_OUTPUT_JSON: - default: - break; - } - return -1; -} - struct obj_ops obj_ops_tunnel = { .name = "tunnel", .type = NFT_OBJECT_TUNNEL, diff --git a/src/object.c b/src/object.c index 46e7916..2d15629 100644 --- a/src/object.c +++ b/src/object.c @@ -396,8 +396,7 @@ static int nftnl_obj_snprintf_dflt(char *buf, size_t size, SNPRINTF_BUFFER_SIZE(ret, remain, offset); if (obj->ops) { - ret = obj->ops->snprintf(buf + offset, remain, type, flags, - obj); + ret = obj->ops->snprintf(buf + offset, remain, flags, obj); SNPRINTF_BUFFER_SIZE(ret, remain, offset); } ret = snprintf(buf + offset, remain, "]"); -- cgit v1.2.3