]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: avoid IPPROTO_MAX for array definitions
authorFlorian Westphal <fw@strlen.de>
Tue, 20 Jun 2023 19:52:13 +0000 (21:52 +0200)
committerFlorian Westphal <fw@strlen.de>
Wed, 21 Jun 2023 15:27:43 +0000 (17:27 +0200)
ip header can only accomodate 8but value, but IPPROTO_MAX has been bumped
due to uapi reasons to support MPTCP (262, which is used to toggle on
multipath support in tcp).

This results in:
exthdr.c:349:11: warning: result of comparison of constant 263 with expression of type 'uint8_t' (aka 'unsigned char') is always true [-Wtautological-constant-out-of-range-compare]
if (type < array_size(exthdr_protocols))
            ~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

redude array sizes back to what can be used on-wire.

Signed-off-by: Florian Westphal <fw@strlen.de>
include/rule.h
src/exthdr.c
src/rule.c

index b360e2614c78320b043223833e94f71e1aeab1c0..5cb549c2e14e1409a1e055de5e90dea409e310d4 100644 (file)
@@ -786,7 +786,7 @@ struct timeout_protocol {
        uint32_t *dflt_timeout;
 };
 
-extern struct timeout_protocol timeout_protocol[IPPROTO_MAX];
+extern struct timeout_protocol timeout_protocol[UINT8_MAX + 1];
 extern int timeout_str2num(uint16_t l4proto, struct timeout_state *ts);
 
 #endif /* NFTABLES_RULE_H */
index d0274bea6ca075e983e7d8fa076958c1a3b05613..f5527ddb4a3f333732b2ea8b62d0c46a2c6aa284 100644 (file)
@@ -289,7 +289,7 @@ struct stmt *exthdr_stmt_alloc(const struct location *loc,
        return stmt;
 }
 
-static const struct exthdr_desc *exthdr_protocols[IPPROTO_MAX] = {
+static const struct exthdr_desc *exthdr_protocols[UINT8_MAX + 1] = {
        [IPPROTO_HOPOPTS]       = &exthdr_hbh,
        [IPPROTO_ROUTING]       = &exthdr_rt,
        [IPPROTO_FRAGMENT]      = &exthdr_frag,
@@ -346,8 +346,7 @@ void exthdr_init_raw(struct expr *expr, uint8_t type,
        expr->exthdr.offset = offset;
        expr->exthdr.desc = NULL;
 
-       if (type < array_size(exthdr_protocols))
-               expr->exthdr.desc = exthdr_protocols[type];
+       expr->exthdr.desc = exthdr_protocols[type];
 
        if (expr->exthdr.desc == NULL)
                goto out;
index 3704600a87be4b00d7fe2abff3cff3eaca7442dc..19d681bb74b3a1b984894a7fee2a8f3128c5a546 100644 (file)
@@ -76,7 +76,7 @@ static uint32_t udp_dflt_timeout[] = {
        [NFTNL_CTTIMEOUT_UDP_REPLIED]           = 120,
 };
 
-struct timeout_protocol timeout_protocol[IPPROTO_MAX] = {
+struct timeout_protocol timeout_protocol[UINT8_MAX + 1] = {
        [IPPROTO_TCP]   = {
                .array_size     = NFTNL_CTTIMEOUT_TCP_MAX,
                .state_to_name  = tcp_state_to_name,