From 71a6e372f82b6c50c14c8034a974f3ad5983314d Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Wed, 18 Apr 2018 00:09:04 +0200 Subject: 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 --- extensions/libip6t_icmp6.c | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) (limited to 'extensions/libip6t_icmp6.c') 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 #include +#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[] = { -- cgit v1.2.3