]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: Collate ICMP types/codes in libxt_icmp.h
authorPhil Sutter <phil@nwl.cc>
Tue, 11 Oct 2022 15:07:33 +0000 (17:07 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 15 Nov 2022 15:58:16 +0000 (16:58 +0100)
Put the most extensive version of icmp_codes, icmpv6_codes and
igmp_codes into the header. Have to rename the function
xt_print_icmp_types's parameter to avoid a compiler warning.

Signed-off-by: Phil Sutter <phil@nwl.cc>
extensions/libebt_ip.c
extensions/libebt_ip6.c
extensions/libip6t_icmp6.c
extensions/libipt_icmp.c
extensions/libxt_icmp.h

index d13e83c06895da56e777c3c4217aeb1123f470de..27ae84e9470d8a94614a2dddd5885aaafc745de0 100644 (file)
@@ -50,68 +50,6 @@ static const struct option brip_opts[] = {
        XT_GETOPT_TABLEEND,
 };
 
-static const struct xt_icmp_names icmp_codes[] = {
-       { "echo-reply", 0, 0, 0xFF },
-       /* Alias */ { "pong", 0, 0, 0xFF },
-
-       { "destination-unreachable", 3, 0, 0xFF },
-       {   "network-unreachable", 3, 0, 0 },
-       {   "host-unreachable", 3, 1, 1 },
-       {   "protocol-unreachable", 3, 2, 2 },
-       {   "port-unreachable", 3, 3, 3 },
-       {   "fragmentation-needed", 3, 4, 4 },
-       {   "source-route-failed", 3, 5, 5 },
-       {   "network-unknown", 3, 6, 6 },
-       {   "host-unknown", 3, 7, 7 },
-       {   "network-prohibited", 3, 9, 9 },
-       {   "host-prohibited", 3, 10, 10 },
-       {   "TOS-network-unreachable", 3, 11, 11 },
-       {   "TOS-host-unreachable", 3, 12, 12 },
-       {   "communication-prohibited", 3, 13, 13 },
-       {   "host-precedence-violation", 3, 14, 14 },
-       {   "precedence-cutoff", 3, 15, 15 },
-
-       { "source-quench", 4, 0, 0xFF },
-
-       { "redirect", 5, 0, 0xFF },
-       {   "network-redirect", 5, 0, 0 },
-       {   "host-redirect", 5, 1, 1 },
-       {   "TOS-network-redirect", 5, 2, 2 },
-       {   "TOS-host-redirect", 5, 3, 3 },
-
-       { "echo-request", 8, 0, 0xFF },
-       /* Alias */ { "ping", 8, 0, 0xFF },
-
-       { "router-advertisement", 9, 0, 0xFF },
-
-       { "router-solicitation", 10, 0, 0xFF },
-
-       { "time-exceeded", 11, 0, 0xFF },
-       /* Alias */ { "ttl-exceeded", 11, 0, 0xFF },
-       {   "ttl-zero-during-transit", 11, 0, 0 },
-       {   "ttl-zero-during-reassembly", 11, 1, 1 },
-
-       { "parameter-problem", 12, 0, 0xFF },
-       {   "ip-header-bad", 12, 0, 0 },
-       {   "required-option-missing", 12, 1, 1 },
-
-       { "timestamp-request", 13, 0, 0xFF },
-
-       { "timestamp-reply", 14, 0, 0xFF },
-
-       { "address-mask-request", 17, 0, 0xFF },
-
-       { "address-mask-reply", 18, 0, 0xFF }
-};
-
-static const struct xt_icmp_names igmp_types[] = {
-       { "membership-query", 0x11 },
-       { "membership-report-v1", 0x12 },
-       { "membership-report-v2", 0x16 },
-       { "leave-group", 0x17 },
-       { "membership-report-v3", 0x22 },
-};
-
 static void brip_print_help(void)
 {
        printf(
index a686a285c3cb811dc47a600283f34a5c2c12b077..ac20666af5ba328dd9a67fe1e13951fde566208c 100644 (file)
@@ -49,44 +49,6 @@ static const struct option brip6_opts[] = {
        XT_GETOPT_TABLEEND,
 };
 
-static const struct xt_icmp_names icmpv6_codes[] = {
-       { "destination-unreachable", 1, 0, 0xFF },
-       { "no-route", 1, 0, 0 },
-       { "communication-prohibited", 1, 1, 1 },
-       { "address-unreachable", 1, 3, 3 },
-       { "port-unreachable", 1, 4, 4 },
-
-       { "packet-too-big", 2, 0, 0xFF },
-
-       { "time-exceeded", 3, 0, 0xFF },
-       /* Alias */ { "ttl-exceeded", 3, 0, 0xFF },
-       { "ttl-zero-during-transit", 3, 0, 0 },
-       { "ttl-zero-during-reassembly", 3, 1, 1 },
-
-       { "parameter-problem", 4, 0, 0xFF },
-       { "bad-header", 4, 0, 0 },
-       { "unknown-header-type", 4, 1, 1 },
-       { "unknown-option", 4, 2, 2 },
-
-       { "echo-request", 128, 0, 0xFF },
-       /* Alias */ { "ping", 128, 0, 0xFF },
-
-       { "echo-reply", 129, 0, 0xFF },
-       /* Alias */ { "pong", 129, 0, 0xFF },
-
-       { "router-solicitation", 133, 0, 0xFF },
-
-       { "router-advertisement", 134, 0, 0xFF },
-
-       { "neighbour-solicitation", 135, 0, 0xFF },
-       /* Alias */ { "neighbor-solicitation", 135, 0, 0xFF },
-
-       { "neighbour-advertisement", 136, 0, 0xFF },
-       /* Alias */ { "neighbor-advertisement", 136, 0, 0xFF },
-
-       { "redirect", 137, 0, 0xFF },
-};
-
 static void
 parse_port_range(const char *protocol, const char *portstring, uint16_t *ports)
 {
index cc7bfaeb72fd7a355acfcfa311cecf855211e3ec..44f71095281663128f666352a8d542e3ac5e3a5d 100644 (file)
@@ -12,48 +12,6 @@ enum {
        O_ICMPV6_TYPE = 0,
 };
 
-static const struct xt_icmp_names icmpv6_codes[] = {
-       { "destination-unreachable", 1, 0, 0xFF },
-       {   "no-route", 1, 0, 0 },
-       {   "communication-prohibited", 1, 1, 1 },
-       {   "beyond-scope", 1, 2, 2 },
-       {   "address-unreachable", 1, 3, 3 },
-       {   "port-unreachable", 1, 4, 4 },
-       {   "failed-policy", 1, 5, 5 },
-       {   "reject-route", 1, 6, 6 },
-
-       { "packet-too-big", 2, 0, 0xFF },
-
-       { "time-exceeded", 3, 0, 0xFF },
-       /* Alias */ { "ttl-exceeded", 3, 0, 0xFF },
-       {   "ttl-zero-during-transit", 3, 0, 0 },
-       {   "ttl-zero-during-reassembly", 3, 1, 1 },
-
-       { "parameter-problem", 4, 0, 0xFF },
-       {   "bad-header", 4, 0, 0 },
-       {   "unknown-header-type", 4, 1, 1 },
-       {   "unknown-option", 4, 2, 2 },
-
-       { "echo-request", 128, 0, 0xFF },
-       /* Alias */ { "ping", 128, 0, 0xFF },
-
-       { "echo-reply", 129, 0, 0xFF },
-       /* Alias */ { "pong", 129, 0, 0xFF },
-
-       { "router-solicitation", 133, 0, 0xFF },
-
-       { "router-advertisement", 134, 0, 0xFF },
-
-       { "neighbour-solicitation", 135, 0, 0xFF },
-       /* Alias */ { "neighbor-solicitation", 135, 0, 0xFF },
-
-       { "neighbour-advertisement", 136, 0, 0xFF },
-       /* Alias */ { "neighbor-advertisement", 136, 0, 0xFF },
-
-       { "redirect", 137, 0, 0xFF },
-
-};
-
 static void icmp6_help(void)
 {
        printf(
index e5e236613f39f51ed39fa2d80f886589bc95c301..f0e838874286bd17ac71313645bcbc080beaa43e 100644 (file)
@@ -19,61 +19,6 @@ enum {
        O_ICMP_TYPE = 0,
 };
 
-static const struct xt_icmp_names icmp_codes[] = {
-       { "any", 0xFF, 0, 0xFF },
-       { "echo-reply", 0, 0, 0xFF },
-       /* Alias */ { "pong", 0, 0, 0xFF },
-
-       { "destination-unreachable", 3, 0, 0xFF },
-       {   "network-unreachable", 3, 0, 0 },
-       {   "host-unreachable", 3, 1, 1 },
-       {   "protocol-unreachable", 3, 2, 2 },
-       {   "port-unreachable", 3, 3, 3 },
-       {   "fragmentation-needed", 3, 4, 4 },
-       {   "source-route-failed", 3, 5, 5 },
-       {   "network-unknown", 3, 6, 6 },
-       {   "host-unknown", 3, 7, 7 },
-       {   "network-prohibited", 3, 9, 9 },
-       {   "host-prohibited", 3, 10, 10 },
-       {   "TOS-network-unreachable", 3, 11, 11 },
-       {   "TOS-host-unreachable", 3, 12, 12 },
-       {   "communication-prohibited", 3, 13, 13 },
-       {   "host-precedence-violation", 3, 14, 14 },
-       {   "precedence-cutoff", 3, 15, 15 },
-
-       { "source-quench", 4, 0, 0xFF },
-
-       { "redirect", 5, 0, 0xFF },
-       {   "network-redirect", 5, 0, 0 },
-       {   "host-redirect", 5, 1, 1 },
-       {   "TOS-network-redirect", 5, 2, 2 },
-       {   "TOS-host-redirect", 5, 3, 3 },
-
-       { "echo-request", 8, 0, 0xFF },
-       /* Alias */ { "ping", 8, 0, 0xFF },
-
-       { "router-advertisement", 9, 0, 0xFF },
-
-       { "router-solicitation", 10, 0, 0xFF },
-
-       { "time-exceeded", 11, 0, 0xFF },
-       /* Alias */ { "ttl-exceeded", 11, 0, 0xFF },
-       {   "ttl-zero-during-transit", 11, 0, 0 },
-       {   "ttl-zero-during-reassembly", 11, 1, 1 },
-
-       { "parameter-problem", 12, 0, 0xFF },
-       {   "ip-header-bad", 12, 0, 0 },
-       {   "required-option-missing", 12, 1, 1 },
-
-       { "timestamp-request", 13, 0, 0xFF },
-
-       { "timestamp-reply", 14, 0, 0xFF },
-
-       { "address-mask-request", 17, 0, 0xFF },
-
-       { "address-mask-reply", 18, 0, 0xFF }
-};
-
 static void icmp_help(void)
 {
        printf(
index 5820206ef469ed4c027104a63315c58dc2dadbc7..d6d9f9b6ffc98f4f4aaac43cb93e2f0ef963ed9f 100644 (file)
-struct xt_icmp_names {
+static const struct xt_icmp_names {
        const char *name;
        uint8_t type;
        uint8_t code_min, code_max;
+} icmp_codes[] = {
+       { "any", 0xFF, 0, 0xFF },
+       { "echo-reply", 0, 0, 0xFF },
+       /* Alias */ { "pong", 0, 0, 0xFF },
+
+       { "destination-unreachable", 3, 0, 0xFF },
+       {   "network-unreachable", 3, 0, 0 },
+       {   "host-unreachable", 3, 1, 1 },
+       {   "protocol-unreachable", 3, 2, 2 },
+       {   "port-unreachable", 3, 3, 3 },
+       {   "fragmentation-needed", 3, 4, 4 },
+       {   "source-route-failed", 3, 5, 5 },
+       {   "network-unknown", 3, 6, 6 },
+       {   "host-unknown", 3, 7, 7 },
+       {   "network-prohibited", 3, 9, 9 },
+       {   "host-prohibited", 3, 10, 10 },
+       {   "TOS-network-unreachable", 3, 11, 11 },
+       {   "TOS-host-unreachable", 3, 12, 12 },
+       {   "communication-prohibited", 3, 13, 13 },
+       {   "host-precedence-violation", 3, 14, 14 },
+       {   "precedence-cutoff", 3, 15, 15 },
+
+       { "source-quench", 4, 0, 0xFF },
+
+       { "redirect", 5, 0, 0xFF },
+       {   "network-redirect", 5, 0, 0 },
+       {   "host-redirect", 5, 1, 1 },
+       {   "TOS-network-redirect", 5, 2, 2 },
+       {   "TOS-host-redirect", 5, 3, 3 },
+
+       { "echo-request", 8, 0, 0xFF },
+       /* Alias */ { "ping", 8, 0, 0xFF },
+
+       { "router-advertisement", 9, 0, 0xFF },
+
+       { "router-solicitation", 10, 0, 0xFF },
+
+       { "time-exceeded", 11, 0, 0xFF },
+       /* Alias */ { "ttl-exceeded", 11, 0, 0xFF },
+       {   "ttl-zero-during-transit", 11, 0, 0 },
+       {   "ttl-zero-during-reassembly", 11, 1, 1 },
+
+       { "parameter-problem", 12, 0, 0xFF },
+       {   "ip-header-bad", 12, 0, 0 },
+       {   "required-option-missing", 12, 1, 1 },
+
+       { "timestamp-request", 13, 0, 0xFF },
+
+       { "timestamp-reply", 14, 0, 0xFF },
+
+       { "address-mask-request", 17, 0, 0xFF },
+
+       { "address-mask-reply", 18, 0, 0xFF }
+}, icmpv6_codes[] = {
+       { "destination-unreachable", 1, 0, 0xFF },
+       {   "no-route", 1, 0, 0 },
+       {   "communication-prohibited", 1, 1, 1 },
+       {   "beyond-scope", 1, 2, 2 },
+       {   "address-unreachable", 1, 3, 3 },
+       {   "port-unreachable", 1, 4, 4 },
+       {   "failed-policy", 1, 5, 5 },
+       {   "reject-route", 1, 6, 6 },
+
+       { "packet-too-big", 2, 0, 0xFF },
+
+       { "time-exceeded", 3, 0, 0xFF },
+       /* Alias */ { "ttl-exceeded", 3, 0, 0xFF },
+       {   "ttl-zero-during-transit", 3, 0, 0 },
+       {   "ttl-zero-during-reassembly", 3, 1, 1 },
+
+       { "parameter-problem", 4, 0, 0xFF },
+       {   "bad-header", 4, 0, 0 },
+       {   "unknown-header-type", 4, 1, 1 },
+       {   "unknown-option", 4, 2, 2 },
+
+       { "echo-request", 128, 0, 0xFF },
+       /* Alias */ { "ping", 128, 0, 0xFF },
+
+       { "echo-reply", 129, 0, 0xFF },
+       /* Alias */ { "pong", 129, 0, 0xFF },
+
+       { "router-solicitation", 133, 0, 0xFF },
+
+       { "router-advertisement", 134, 0, 0xFF },
+
+       { "neighbour-solicitation", 135, 0, 0xFF },
+       /* Alias */ { "neighbor-solicitation", 135, 0, 0xFF },
+
+       { "neighbour-advertisement", 136, 0, 0xFF },
+       /* Alias */ { "neighbor-advertisement", 136, 0, 0xFF },
+
+       { "redirect", 137, 0, 0xFF },
+}, igmp_types[] = {
+       { "membership-query", 0x11 },
+       { "membership-report-v1", 0x12 },
+       { "membership-report-v2", 0x16 },
+       { "leave-group", 0x17 },
+       { "membership-report-v3", 0x22 },
 };
 
-static void xt_print_icmp_types(const struct xt_icmp_names *icmp_codes,
+static void xt_print_icmp_types(const struct xt_icmp_names *_icmp_codes,
                                unsigned int n_codes)
 {
        unsigned int i;
 
        for (i = 0; i < n_codes; ++i) {
-               if (i && icmp_codes[i].type == icmp_codes[i-1].type) {
-                       if (icmp_codes[i].code_min == icmp_codes[i-1].code_min
-                           && (icmp_codes[i].code_max
-                               == icmp_codes[i-1].code_max))
-                               printf(" (%s)", icmp_codes[i].name);
+               if (i && _icmp_codes[i].type == _icmp_codes[i-1].type) {
+                       if (_icmp_codes[i].code_min == _icmp_codes[i-1].code_min
+                           && (_icmp_codes[i].code_max
+                               == _icmp_codes[i-1].code_max))
+                               printf(" (%s)", _icmp_codes[i].name);
                        else
-                               printf("\n   %s", icmp_codes[i].name);
+                               printf("\n   %s", _icmp_codes[i].name);
                }
                else
-                       printf("\n%s", icmp_codes[i].name);
+                       printf("\n%s", _icmp_codes[i].name);
        }
        printf("\n");
 }