summaryrefslogtreecommitdiffstats
path: root/extensions/libip6t_icmp6.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2018-04-18 00:09:04 +0200
committerFlorian Westphal <fw@strlen.de>2018-04-19 10:18:10 +0200
commit71a6e372f82b6c50c14c8034a974f3ad5983314d (patch)
tree7cc9d9491ac1035f668d11cca7ec186822c51a55 /extensions/libip6t_icmp6.c
parente67c08880961f64984b396d6e8ad6bad04546253 (diff)
icmp: split icmp type printing to header file
libebt_ip will get icmp support soon, unify icmp name mapping a bit so we can re-use this code from libebt_ip.c. It doesn't seem to be too useful to move to libxtables (as its icmp specific), so add a hedaer file for this to reduce copy & paste needs. Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'extensions/libip6t_icmp6.c')
-rw-r--r--extensions/libip6t_icmp6.c34
1 files changed, 5 insertions, 29 deletions
diff --git a/extensions/libip6t_icmp6.c b/extensions/libip6t_icmp6.c
index 37c2bcb8..45a71875 100644
--- a/extensions/libip6t_icmp6.c
+++ b/extensions/libip6t_icmp6.c
@@ -6,17 +6,13 @@
#include <linux/netfilter_ipv6/ip6_tables.h>
#include <netinet/icmp6.h>
+#include "libxt_icmp.h"
+
enum {
O_ICMPV6_TYPE = 0,
};
-struct icmpv6_names {
- const char *name;
- uint8_t type;
- uint8_t code_min, code_max;
-};
-
-static const struct icmpv6_names icmpv6_codes[] = {
+static const struct xt_icmp_names icmpv6_codes[] = {
{ "destination-unreachable", 1, 0, 0xFF },
{ "no-route", 1, 0, 0 },
{ "communication-prohibited", 1, 1, 1 },
@@ -58,34 +54,14 @@ static const struct icmpv6_names icmpv6_codes[] = {
};
-static void
-print_icmpv6types(void)
-{
- unsigned int i;
- printf("Valid ICMPv6 Types:");
-
- for (i = 0; i < ARRAY_SIZE(icmpv6_codes); ++i) {
- if (i && icmpv6_codes[i].type == icmpv6_codes[i-1].type) {
- if (icmpv6_codes[i].code_min == icmpv6_codes[i-1].code_min
- && (icmpv6_codes[i].code_max
- == icmpv6_codes[i-1].code_max))
- printf(" (%s)", icmpv6_codes[i].name);
- else
- printf("\n %s", icmpv6_codes[i].name);
- }
- else
- printf("\n%s", icmpv6_codes[i].name);
- }
- printf("\n");
-}
-
static void icmp6_help(void)
{
printf(
"icmpv6 match options:\n"
"[!] --icmpv6-type typename match icmpv6 type\n"
" (or numeric type or type/code)\n");
- print_icmpv6types();
+ printf("Valid ICMPv6 Types:");
+ xt_print_icmp_types(icmpv6_codes, ARRAY_SIZE(icmpv6_codes));
}
static const struct xt_option_entry icmp6_opts[] = {