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

net/tcp: refactor tcp_inet6_sk()

Don't keep hand coded offset caluclations and replace it with
container_of(). It should be type safer and a bit less confusing.

It also makes it with a macro instead of inline function to preserve
constness, which was previously casted out like in case of
tcp_v6_send_synack().

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Pavel Begunkov and committed by
David S. Miller
fe79bd65 4b159f50

+3 -7
+3 -7
net/ipv6/tcp_ipv6.c
··· 93 93 * This avoids a dereference and allow compiler optimizations. 94 94 * It is a specialized version of inet6_sk_generic(). 95 95 */ 96 - static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk) 97 - { 98 - unsigned int offset = sizeof(struct tcp6_sock) - sizeof(struct ipv6_pinfo); 99 - 100 - return (struct ipv6_pinfo *)(((u8 *)sk) + offset); 101 - } 96 + #define tcp_inet6_sk(sk) (&container_of_const(tcp_sk(sk), \ 97 + struct tcp6_sock, tcp)->inet6) 102 98 103 99 static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb) 104 100 { ··· 529 533 struct sk_buff *syn_skb) 530 534 { 531 535 struct inet_request_sock *ireq = inet_rsk(req); 532 - struct ipv6_pinfo *np = tcp_inet6_sk(sk); 536 + const struct ipv6_pinfo *np = tcp_inet6_sk(sk); 533 537 struct ipv6_txoptions *opt; 534 538 struct flowi6 *fl6 = &fl->u.ip6; 535 539 struct sk_buff *skb;