@@ -90,6 +90,17 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(const struct sock *sk,
90
90
}
91
91
#endif
92
92
93
+ /* Helper returning the inet6 address from a given tcp socket.
94
+ * It can be used in TCP stack instead of inet6_sk(sk).
95
+ * This avoids a dereference and allow compiler optimizations.
96
+ */
97
+ static struct ipv6_pinfo * tcp_inet6_sk (const struct sock * sk )
98
+ {
99
+ struct tcp6_sock * tcp6 = container_of (tcp_sk (sk ), struct tcp6_sock , tcp );
100
+
101
+ return & tcp6 -> inet6 ;
102
+ }
103
+
93
104
static void inet6_sk_rx_dst_set (struct sock * sk , const struct sk_buff * skb )
94
105
{
95
106
struct dst_entry * dst = skb_dst (skb );
@@ -99,7 +110,7 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99
110
100
111
sk -> sk_rx_dst = dst ;
101
112
inet_sk (sk )-> rx_dst_ifindex = skb -> skb_iif ;
102
- inet6_sk (sk )-> rx_dst_cookie = rt6_get_cookie (rt );
113
+ tcp_inet6_sk (sk )-> rx_dst_cookie = rt6_get_cookie (rt );
103
114
}
104
115
}
105
116
@@ -138,7 +149,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
138
149
struct sockaddr_in6 * usin = (struct sockaddr_in6 * ) uaddr ;
139
150
struct inet_sock * inet = inet_sk (sk );
140
151
struct inet_connection_sock * icsk = inet_csk (sk );
141
- struct ipv6_pinfo * np = inet6_sk (sk );
152
+ struct ipv6_pinfo * np = tcp_inet6_sk (sk );
142
153
struct tcp_sock * tp = tcp_sk (sk );
143
154
struct in6_addr * saddr = NULL , * final_p , final ;
144
155
struct ipv6_txoptions * opt ;
@@ -390,7 +401,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
390
401
if (sk -> sk_state == TCP_CLOSE )
391
402
goto out ;
392
403
393
- if (ipv6_hdr (skb )-> hop_limit < inet6_sk (sk )-> min_hopcount ) {
404
+ if (ipv6_hdr (skb )-> hop_limit < tcp_inet6_sk (sk )-> min_hopcount ) {
394
405
__NET_INC_STATS (net , LINUX_MIB_TCPMINTTLDROP );
395
406
goto out ;
396
407
}
@@ -405,7 +416,7 @@ static int tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
405
416
goto out ;
406
417
}
407
418
408
- np = inet6_sk (sk );
419
+ np = tcp_inet6_sk (sk );
409
420
410
421
if (type == NDISC_REDIRECT ) {
411
422
if (!sock_owned_by_user (sk )) {
@@ -478,7 +489,7 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
478
489
enum tcp_synack_type synack_type )
479
490
{
480
491
struct inet_request_sock * ireq = inet_rsk (req );
481
- struct ipv6_pinfo * np = inet6_sk (sk );
492
+ struct ipv6_pinfo * np = tcp_inet6_sk (sk );
482
493
struct ipv6_txoptions * opt ;
483
494
struct flowi6 * fl6 = & fl -> u .ip6 ;
484
495
struct sk_buff * skb ;
@@ -737,7 +748,7 @@ static void tcp_v6_init_req(struct request_sock *req,
737
748
{
738
749
bool l3_slave = ipv6_l3mdev_skb (TCP_SKB_CB (skb )-> header .h6 .flags );
739
750
struct inet_request_sock * ireq = inet_rsk (req );
740
- const struct ipv6_pinfo * np = inet6_sk (sk_listener );
751
+ const struct ipv6_pinfo * np = tcp_inet6_sk (sk_listener );
741
752
742
753
ireq -> ir_v6_rmt_addr = ipv6_hdr (skb )-> saddr ;
743
754
ireq -> ir_v6_loc_addr = ipv6_hdr (skb )-> daddr ;
@@ -1066,9 +1077,8 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
1066
1077
{
1067
1078
struct inet_request_sock * ireq ;
1068
1079
struct ipv6_pinfo * newnp ;
1069
- const struct ipv6_pinfo * np = inet6_sk (sk );
1080
+ const struct ipv6_pinfo * np = tcp_inet6_sk (sk );
1070
1081
struct ipv6_txoptions * opt ;
1071
- struct tcp6_sock * newtcp6sk ;
1072
1082
struct inet_sock * newinet ;
1073
1083
struct tcp_sock * newtp ;
1074
1084
struct sock * newsk ;
@@ -1088,11 +1098,10 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
1088
1098
if (!newsk )
1089
1099
return NULL ;
1090
1100
1091
- newtcp6sk = (struct tcp6_sock * )newsk ;
1092
- inet_sk (newsk )-> pinet6 = & newtcp6sk -> inet6 ;
1101
+ inet_sk (newsk )-> pinet6 = tcp_inet6_sk (newsk );
1093
1102
1094
1103
newinet = inet_sk (newsk );
1095
- newnp = inet6_sk (newsk );
1104
+ newnp = tcp_inet6_sk (newsk );
1096
1105
newtp = tcp_sk (newsk );
1097
1106
1098
1107
memcpy (newnp , np , sizeof (struct ipv6_pinfo ));
@@ -1156,12 +1165,11 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
1156
1165
ip6_dst_store (newsk , dst , NULL , NULL );
1157
1166
inet6_sk_rx_dst_set (newsk , skb );
1158
1167
1159
- newtcp6sk = (struct tcp6_sock * )newsk ;
1160
- inet_sk (newsk )-> pinet6 = & newtcp6sk -> inet6 ;
1168
+ inet_sk (newsk )-> pinet6 = tcp_inet6_sk (newsk );
1161
1169
1162
1170
newtp = tcp_sk (newsk );
1163
1171
newinet = inet_sk (newsk );
1164
- newnp = inet6_sk (newsk );
1172
+ newnp = tcp_inet6_sk (newsk );
1165
1173
1166
1174
memcpy (newnp , np , sizeof (struct ipv6_pinfo ));
1167
1175
@@ -1276,9 +1284,9 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
1276
1284
*/
1277
1285
static int tcp_v6_do_rcv (struct sock * sk , struct sk_buff * skb )
1278
1286
{
1279
- struct ipv6_pinfo * np = inet6_sk (sk );
1280
- struct tcp_sock * tp ;
1287
+ struct ipv6_pinfo * np = tcp_inet6_sk (sk );
1281
1288
struct sk_buff * opt_skb = NULL ;
1289
+ struct tcp_sock * tp ;
1282
1290
1283
1291
/* Imagine: socket is IPv6. IPv4 packet arrives,
1284
1292
goes to IPv4 receive handler and backlogged.
@@ -1524,7 +1532,7 @@ static int tcp_v6_rcv(struct sk_buff *skb)
1524
1532
return 0 ;
1525
1533
}
1526
1534
}
1527
- if (hdr -> hop_limit < inet6_sk (sk )-> min_hopcount ) {
1535
+ if (hdr -> hop_limit < tcp_inet6_sk (sk )-> min_hopcount ) {
1528
1536
__NET_INC_STATS (net , LINUX_MIB_TCPMINTTLDROP );
1529
1537
goto discard_and_relse ;
1530
1538
}
@@ -1669,7 +1677,7 @@ static void tcp_v6_early_demux(struct sk_buff *skb)
1669
1677
struct dst_entry * dst = READ_ONCE (sk -> sk_rx_dst );
1670
1678
1671
1679
if (dst )
1672
- dst = dst_check (dst , inet6_sk (sk )-> rx_dst_cookie );
1680
+ dst = dst_check (dst , tcp_inet6_sk (sk )-> rx_dst_cookie );
1673
1681
if (dst &&
1674
1682
inet_sk (sk )-> rx_dst_ifindex == skb -> skb_iif )
1675
1683
skb_dst_set_noref (skb , dst );
0 commit comments