Skip to content

Commit fe79bd6

Browse files
isilencedavem330
authored andcommitted
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 <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4b159f5 commit fe79bd6

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

net/ipv6/tcp_ipv6.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,8 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(const struct sock *sk,
9393
* This avoids a dereference and allow compiler optimizations.
9494
* It is a specialized version of inet6_sk_generic().
9595
*/
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)
10298

10399
static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104100
{
@@ -533,7 +529,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
533529
struct sk_buff *syn_skb)
534530
{
535531
struct inet_request_sock *ireq = inet_rsk(req);
536-
struct ipv6_pinfo *np = tcp_inet6_sk(sk);
532+
const struct ipv6_pinfo *np = tcp_inet6_sk(sk);
537533
struct ipv6_txoptions *opt;
538534
struct flowi6 *fl6 = &fl->u.ip6;
539535
struct sk_buff *skb;

0 commit comments

Comments
 (0)