Skip to content

Commit 7425627

Browse files
nathanchancedavem330
authored andcommitted
tcp: Fix -Wc23-extensions in tcp_options_write()
Clang warns (or errors with CONFIG_WERROR=y) when CONFIG_TCP_AO is set: net/ipv4/tcp_output.c:663:2: error: label at end of compound statement is a C23 extension [-Werror,-Wc23-extensions] 663 | } | ^ 1 error generated. On earlier releases (such as clang-11, the current minimum supported version for building the kernel) that do not support C23, this was a hard error unconditionally: net/ipv4/tcp_output.c:663:2: error: expected statement } ^ 1 error generated. While adding a semicolon after the label would resolve this, it is more in line with the kernel as a whole to refactor this block into a standalone function, which means the goto a label construct can just be replaced with a return statement. Do so to resolve the warning. Closes: ClangBuiltLinux#1953 Fixes: 1e03d32 ("net/tcp: Add TCP-AO sign to outgoing packets") Signed-off-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Dmitry Safonov <dima@arista.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c542b39 commit 7425627

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

net/ipv4/tcp_output.c

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,44 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
601601
}
602602
#endif
603603

604+
static __be32 *process_tcp_ao_options(struct tcp_sock *tp,
605+
const struct tcp_request_sock *tcprsk,
606+
struct tcp_out_options *opts,
607+
struct tcp_key *key, __be32 *ptr)
608+
{
609+
#ifdef CONFIG_TCP_AO
610+
u8 maclen = tcp_ao_maclen(key->ao_key);
611+
612+
if (tcprsk) {
613+
u8 aolen = maclen + sizeof(struct tcp_ao_hdr);
614+
615+
*ptr++ = htonl((TCPOPT_AO << 24) | (aolen << 16) |
616+
(tcprsk->ao_keyid << 8) |
617+
(tcprsk->ao_rcv_next));
618+
} else {
619+
struct tcp_ao_key *rnext_key;
620+
struct tcp_ao_info *ao_info;
621+
622+
ao_info = rcu_dereference_check(tp->ao_info,
623+
lockdep_sock_is_held(&tp->inet_conn.icsk_inet.sk));
624+
rnext_key = READ_ONCE(ao_info->rnext_key);
625+
if (WARN_ON_ONCE(!rnext_key))
626+
return ptr;
627+
*ptr++ = htonl((TCPOPT_AO << 24) |
628+
(tcp_ao_len(key->ao_key) << 16) |
629+
(key->ao_key->sndid << 8) |
630+
(rnext_key->rcvid));
631+
}
632+
opts->hash_location = (__u8 *)ptr;
633+
ptr += maclen / sizeof(*ptr);
634+
if (unlikely(maclen % sizeof(*ptr))) {
635+
memset(ptr, TCPOPT_NOP, sizeof(*ptr));
636+
ptr++;
637+
}
638+
#endif
639+
return ptr;
640+
}
641+
604642
/* Write previously computed TCP options to the packet.
605643
*
606644
* Beware: Something in the Internet is very sensitive to the ordering of
@@ -629,37 +667,7 @@ static void tcp_options_write(struct tcphdr *th, struct tcp_sock *tp,
629667
opts->hash_location = (__u8 *)ptr;
630668
ptr += 4;
631669
} else if (tcp_key_is_ao(key)) {
632-
#ifdef CONFIG_TCP_AO
633-
u8 maclen = tcp_ao_maclen(key->ao_key);
634-
635-
if (tcprsk) {
636-
u8 aolen = maclen + sizeof(struct tcp_ao_hdr);
637-
638-
*ptr++ = htonl((TCPOPT_AO << 24) | (aolen << 16) |
639-
(tcprsk->ao_keyid << 8) |
640-
(tcprsk->ao_rcv_next));
641-
} else {
642-
struct tcp_ao_key *rnext_key;
643-
struct tcp_ao_info *ao_info;
644-
645-
ao_info = rcu_dereference_check(tp->ao_info,
646-
lockdep_sock_is_held(&tp->inet_conn.icsk_inet.sk));
647-
rnext_key = READ_ONCE(ao_info->rnext_key);
648-
if (WARN_ON_ONCE(!rnext_key))
649-
goto out_ao;
650-
*ptr++ = htonl((TCPOPT_AO << 24) |
651-
(tcp_ao_len(key->ao_key) << 16) |
652-
(key->ao_key->sndid << 8) |
653-
(rnext_key->rcvid));
654-
}
655-
opts->hash_location = (__u8 *)ptr;
656-
ptr += maclen / sizeof(*ptr);
657-
if (unlikely(maclen % sizeof(*ptr))) {
658-
memset(ptr, TCPOPT_NOP, sizeof(*ptr));
659-
ptr++;
660-
}
661-
out_ao:
662-
#endif
670+
ptr = process_tcp_ao_options(tp, tcprsk, opts, key, ptr);
663671
}
664672
if (unlikely(opts->mss)) {
665673
*ptr++ = htonl((TCPOPT_MSS << 24) |

0 commit comments

Comments
 (0)