Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

inet: preserve const qualifier in inet_csk()

We can change inet_csk() to propagate its argument const qualifier,
thanks to container_of_const().

We have to fix few places that had mistakes, like tcp_bound_rto().

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://lore.kernel.org/r/20240329144931.295800-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
58169ec9 513bebc4

+8 -11
+1 -1
include/net/espintcp.h
··· 32 32 33 33 static inline struct espintcp_ctx *espintcp_getctx(const struct sock *sk) 34 34 { 35 - struct inet_connection_sock *icsk = inet_csk(sk); 35 + const struct inet_connection_sock *icsk = inet_csk(sk); 36 36 37 37 /* RCU is only needed for diag */ 38 38 return (__force void *)icsk->icsk_ulp_data;
+1 -4
include/net/inet_connection_sock.h
··· 147 147 #define ICSK_TIME_LOSS_PROBE 5 /* Tail loss probe timer */ 148 148 #define ICSK_TIME_REO_TIMEOUT 6 /* Reordering timer */ 149 149 150 - static inline struct inet_connection_sock *inet_csk(const struct sock *sk) 151 - { 152 - return (struct inet_connection_sock *)sk; 153 - } 150 + #define inet_csk(ptr) container_of_const(ptr, struct inet_connection_sock, icsk_inet.sk) 154 151 155 152 static inline void *inet_csk_ca(const struct sock *sk) 156 153 {
+1 -1
include/net/tcp.h
··· 742 742 int tcp_mss_to_mtu(struct sock *sk, int mss); 743 743 void tcp_mtup_init(struct sock *sk); 744 744 745 - static inline void tcp_bound_rto(const struct sock *sk) 745 + static inline void tcp_bound_rto(struct sock *sk) 746 746 { 747 747 if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX) 748 748 inet_csk(sk)->icsk_rto = TCP_RTO_MAX;
+1 -1
include/net/tls.h
··· 361 361 362 362 static inline struct tls_context *tls_get_ctx(const struct sock *sk) 363 363 { 364 - struct inet_connection_sock *icsk = inet_csk(sk); 364 + const struct inet_connection_sock *icsk = inet_csk(sk); 365 365 366 366 /* Use RCU on icsk_ulp_data only for sock diag code, 367 367 * TLS data path doesn't need rcu_dereference().
+1 -1
net/ipv4/tcp_input.c
··· 6999 6999 /* 7000 7000 * Return true if a syncookie should be sent 7001 7001 */ 7002 - static bool tcp_syn_flood_action(const struct sock *sk, const char *proto) 7002 + static bool tcp_syn_flood_action(struct sock *sk, const char *proto) 7003 7003 { 7004 7004 struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue; 7005 7005 const char *msg = "Dropping request";
+2 -2
net/ipv4/tcp_timer.c
··· 25 25 26 26 static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk) 27 27 { 28 - struct inet_connection_sock *icsk = inet_csk(sk); 28 + const struct inet_connection_sock *icsk = inet_csk(sk); 29 29 const struct tcp_sock *tp = tcp_sk(sk); 30 30 u32 elapsed, user_timeout; 31 31 s32 remaining; ··· 47 47 48 48 u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when) 49 49 { 50 - struct inet_connection_sock *icsk = inet_csk(sk); 50 + const struct inet_connection_sock *icsk = inet_csk(sk); 51 51 u32 remaining, user_timeout; 52 52 s32 elapsed; 53 53
+1 -1
net/mptcp/protocol.h
··· 558 558 static inline struct mptcp_subflow_context * 559 559 mptcp_subflow_ctx(const struct sock *sk) 560 560 { 561 - struct inet_connection_sock *icsk = inet_csk(sk); 561 + const struct inet_connection_sock *icsk = inet_csk(sk); 562 562 563 563 /* Use RCU on icsk_ulp_data only for sock diag code */ 564 564 return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data;