diff options
author | Phil Sutter <phil@nwl.cc> | 2018-09-19 15:17:00 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2018-09-24 11:24:17 +0200 |
commit | 80aae9b3b784ffdea3624117c548d500c56f24d9 (patch) | |
tree | f1f3ae0a9f8ed001f0f49ad8a0bce4f1cec6ff3e /iptables/xshared.c | |
parent | 8da04ffdca1931402a6bc22c43c1a2fa1c6f1e14 (diff) |
iptables: Use print_ifaces() from xtables
Move the function to xshared.c for common use between legacy and xtables
sources. While being at it, silence a covscan warning triggered by that
function as it couldn't verify input buffers won't exceed IFNAMSIZ.
Therefore use snprintf() when writing to the local buffer.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'iptables/xshared.c')
-rw-r--r-- | iptables/xshared.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/iptables/xshared.c b/iptables/xshared.c index d30e7232..a10e425c 100644 --- a/iptables/xshared.c +++ b/iptables/xshared.c @@ -568,3 +568,28 @@ void print_ipv6_addresses(const struct ip6t_entry *fw6, unsigned int format) ipv6_addr_to_string(&fw6->ipv6.dst, &fw6->ipv6.dmsk, format)); } + +/* Luckily, IPT_INV_VIA_IN and IPT_INV_VIA_OUT + * have the same values as IP6T_INV_VIA_IN and IP6T_INV_VIA_OUT + * so this function serves for both iptables and ip6tables */ +void print_ifaces(const char *iniface, const char *outiface, uint8_t invflags, + unsigned int format) +{ + const char *anyname = format & FMT_NUMERIC ? "*" : "any"; + char iface[IFNAMSIZ + 2]; + + if (!(format & FMT_VIA)) + return; + + snprintf(iface, IFNAMSIZ + 2, "%s%s", + invflags & IPT_INV_VIA_IN ? "!" : "", + iniface[0] != '\0' ? iniface : anyname); + + printf(FMT(" %-6s ", "in %s "), iface); + + snprintf(iface, IFNAMSIZ + 2, "%s%s", + invflags & IPT_INV_VIA_OUT ? "!" : "", + outiface[0] != '\0' ? outiface : anyname); + + printf(FMT("%-6s ", "out %s "), iface); +} |