aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/tcp_ipv6.c
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2013-10-03 18:42:29 -0400
committerDavid S. Miller <davem@davemloft.net>2013-10-09 00:01:25 -0400
commitefe4208f47f907b86f528788da711e8ab9dea44d (patch)
tree8246b487be087877ba26d166f629d8c53d553ec1 /net/ipv6/tcp_ipv6.c
parent05dbc7b59481ca891bbcfe6799a562d48159fbf7 (diff)
ipv6: make lookups simpler and faster
TCP listener refactoring, part 4 : To speed up inet lookups, we moved IPv4 addresses from inet to struct sock_common Now is time to do the same for IPv6, because it permits us to have fast lookups for all kind of sockets, including upcoming SYN_RECV. Getting IPv6 addresses in TCP lookups currently requires two extra cache lines, plus a dereference (and memory stall). inet6_sk(sk) does the dereference of inet_sk(__sk)->pinet6 This patch is way bigger than its IPv4 counter part, because for IPv4, we could add aliases (inet_daddr, inet_rcv_saddr), while on IPv6, it's not doable easily. inet6_sk(sk)->daddr becomes sk->sk_v6_daddr inet6_sk(sk)->rcv_saddr becomes sk->sk_v6_rcv_saddr And timewait socket also have tw->tw_v6_daddr & tw->tw_v6_rcv_saddr at the same offset. We get rid of INET6_TW_MATCH() as INET6_MATCH() is now the generic macro. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/tcp_ipv6.c')
-rw-r--r--net/ipv6/tcp_ipv6.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 528e61afaf5e..541dfc40c7b3 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -192,13 +192,13 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
192 } 192 }
193 193
194 if (tp->rx_opt.ts_recent_stamp && 194 if (tp->rx_opt.ts_recent_stamp &&
195 !ipv6_addr_equal(&np->daddr, &usin->sin6_addr)) { 195 !ipv6_addr_equal(&sk->sk_v6_daddr, &usin->sin6_addr)) {
196 tp->rx_opt.ts_recent = 0; 196 tp->rx_opt.ts_recent = 0;
197 tp->rx_opt.ts_recent_stamp = 0; 197 tp->rx_opt.ts_recent_stamp = 0;
198 tp->write_seq = 0; 198 tp->write_seq = 0;
199 } 199 }
200 200
201 np->daddr = usin->sin6_addr; 201 sk->sk_v6_daddr = usin->sin6_addr;
202 np->flow_label = fl6.flowlabel; 202 np->flow_label = fl6.flowlabel;
203 203
204 /* 204 /*
@@ -237,17 +237,17 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
237 } else { 237 } else {
238 ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr); 238 ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
239 ipv6_addr_set_v4mapped(inet->inet_rcv_saddr, 239 ipv6_addr_set_v4mapped(inet->inet_rcv_saddr,
240 &np->rcv_saddr); 240 &sk->sk_v6_rcv_saddr);
241 } 241 }
242 242
243 return err; 243 return err;
244 } 244 }
245 245
246 if (!ipv6_addr_any(&np->rcv_saddr)) 246 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr))
247 saddr = &np->rcv_saddr; 247 saddr = &sk->sk_v6_rcv_saddr;
248 248
249 fl6.flowi6_proto = IPPROTO_TCP; 249 fl6.flowi6_proto = IPPROTO_TCP;
250 fl6.daddr = np->daddr; 250 fl6.daddr = sk->sk_v6_daddr;
251 fl6.saddr = saddr ? *saddr : np->saddr; 251 fl6.saddr = saddr ? *saddr : np->saddr;
252 fl6.flowi6_oif = sk->sk_bound_dev_if; 252 fl6.flowi6_oif = sk->sk_bound_dev_if;
253 fl6.flowi6_mark = sk->sk_mark; 253 fl6.flowi6_mark = sk->sk_mark;
@@ -266,7 +266,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
266 266
267 if (saddr == NULL) { 267 if (saddr == NULL) {
268 saddr = &fl6.saddr; 268 saddr = &fl6.saddr;
269 np->rcv_saddr = *saddr; 269 sk->sk_v6_rcv_saddr = *saddr;
270 } 270 }
271 271
272 /* set the source address */ 272 /* set the source address */
@@ -279,7 +279,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
279 rt = (struct rt6_info *) dst; 279 rt = (struct rt6_info *) dst;
280 if (tcp_death_row.sysctl_tw_recycle && 280 if (tcp_death_row.sysctl_tw_recycle &&
281 !tp->rx_opt.ts_recent_stamp && 281 !tp->rx_opt.ts_recent_stamp &&
282 ipv6_addr_equal(&rt->rt6i_dst.addr, &np->daddr)) 282 ipv6_addr_equal(&rt->rt6i_dst.addr, &sk->sk_v6_daddr))
283 tcp_fetch_timewait_stamp(sk, dst); 283 tcp_fetch_timewait_stamp(sk, dst);
284 284
285 icsk->icsk_ext_hdr_len = 0; 285 icsk->icsk_ext_hdr_len = 0;
@@ -298,7 +298,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
298 298
299 if (!tp->write_seq && likely(!tp->repair)) 299 if (!tp->write_seq && likely(!tp->repair))
300 tp->write_seq = secure_tcpv6_sequence_number(np->saddr.s6_addr32, 300 tp->write_seq = secure_tcpv6_sequence_number(np->saddr.s6_addr32,
301 np->daddr.s6_addr32, 301 sk->sk_v6_daddr.s6_addr32,
302 inet->inet_sport, 302 inet->inet_sport,
303 inet->inet_dport); 303 inet->inet_dport);
304 304
@@ -515,7 +515,7 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
515static struct tcp_md5sig_key *tcp_v6_md5_lookup(struct sock *sk, 515static struct tcp_md5sig_key *tcp_v6_md5_lookup(struct sock *sk,
516 struct sock *addr_sk) 516 struct sock *addr_sk)
517{ 517{
518 return tcp_v6_md5_do_lookup(sk, &inet6_sk(addr_sk)->daddr); 518 return tcp_v6_md5_do_lookup(sk, &addr_sk->sk_v6_daddr);
519} 519}
520 520
521static struct tcp_md5sig_key *tcp_v6_reqsk_md5_lookup(struct sock *sk, 521static struct tcp_md5sig_key *tcp_v6_reqsk_md5_lookup(struct sock *sk,
@@ -621,7 +621,7 @@ static int tcp_v6_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key,
621 621
622 if (sk) { 622 if (sk) {
623 saddr = &inet6_sk(sk)->saddr; 623 saddr = &inet6_sk(sk)->saddr;
624 daddr = &inet6_sk(sk)->daddr; 624 daddr = &sk->sk_v6_daddr;
625 } else if (req) { 625 } else if (req) {
626 saddr = &inet6_rsk(req)->loc_addr; 626 saddr = &inet6_rsk(req)->loc_addr;
627 daddr = &inet6_rsk(req)->rmt_addr; 627 daddr = &inet6_rsk(req)->rmt_addr;
@@ -1116,11 +1116,11 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1116 1116
1117 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1117 memcpy(newnp, np, sizeof(struct ipv6_pinfo));
1118 1118
1119 ipv6_addr_set_v4mapped(newinet->inet_daddr, &newnp->daddr); 1119 ipv6_addr_set_v4mapped(newinet->inet_daddr, &newsk->sk_v6_daddr);
1120 1120
1121 ipv6_addr_set_v4mapped(newinet->inet_saddr, &newnp->saddr); 1121 ipv6_addr_set_v4mapped(newinet->inet_saddr, &newnp->saddr);
1122 1122
1123 newnp->rcv_saddr = newnp->saddr; 1123 newsk->sk_v6_rcv_saddr = newnp->saddr;
1124 1124
1125 inet_csk(newsk)->icsk_af_ops = &ipv6_mapped; 1125 inet_csk(newsk)->icsk_af_ops = &ipv6_mapped;
1126 newsk->sk_backlog_rcv = tcp_v4_do_rcv; 1126 newsk->sk_backlog_rcv = tcp_v4_do_rcv;
@@ -1185,9 +1185,9 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1185 1185
1186 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1186 memcpy(newnp, np, sizeof(struct ipv6_pinfo));
1187 1187
1188 newnp->daddr = treq->rmt_addr; 1188 newsk->sk_v6_daddr = treq->rmt_addr;
1189 newnp->saddr = treq->loc_addr; 1189 newnp->saddr = treq->loc_addr;
1190 newnp->rcv_saddr = treq->loc_addr; 1190 newsk->sk_v6_rcv_saddr = treq->loc_addr;
1191 newsk->sk_bound_dev_if = treq->iif; 1191 newsk->sk_bound_dev_if = treq->iif;
1192 1192
1193 /* Now IPv6 options... 1193 /* Now IPv6 options...
@@ -1244,13 +1244,13 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1244 1244
1245#ifdef CONFIG_TCP_MD5SIG 1245#ifdef CONFIG_TCP_MD5SIG
1246 /* Copy over the MD5 key from the original socket */ 1246 /* Copy over the MD5 key from the original socket */
1247 if ((key = tcp_v6_md5_do_lookup(sk, &newnp->daddr)) != NULL) { 1247 if ((key = tcp_v6_md5_do_lookup(sk, &newsk->sk_v6_daddr)) != NULL) {
1248 /* We're using one, so create a matching key 1248 /* We're using one, so create a matching key
1249 * on the newsk structure. If we fail to get 1249 * on the newsk structure. If we fail to get
1250 * memory, then we end up not copying the key 1250 * memory, then we end up not copying the key
1251 * across. Shucks. 1251 * across. Shucks.
1252 */ 1252 */
1253 tcp_md5_do_add(newsk, (union tcp_md5_addr *)&newnp->daddr, 1253 tcp_md5_do_add(newsk, (union tcp_md5_addr *)&newsk->sk_v6_daddr,
1254 AF_INET6, key->key, key->keylen, 1254 AF_INET6, key->key, key->keylen,
1255 sk_gfp_atomic(sk, GFP_ATOMIC)); 1255 sk_gfp_atomic(sk, GFP_ATOMIC));
1256 } 1256 }
@@ -1758,10 +1758,9 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
1758 const struct inet_sock *inet = inet_sk(sp); 1758 const struct inet_sock *inet = inet_sk(sp);
1759 const struct tcp_sock *tp = tcp_sk(sp); 1759 const struct tcp_sock *tp = tcp_sk(sp);
1760 const struct inet_connection_sock *icsk = inet_csk(sp); 1760 const struct inet_connection_sock *icsk = inet_csk(sp);
1761 const struct ipv6_pinfo *np = inet6_sk(sp);
1762 1761
1763 dest = &np->daddr; 1762 dest = &sp->sk_v6_daddr;
1764 src = &np->rcv_saddr; 1763 src = &sp->sk_v6_rcv_saddr;
1765 destp = ntohs(inet->inet_dport); 1764 destp = ntohs(inet->inet_dport);
1766 srcp = ntohs(inet->inet_sport); 1765 srcp = ntohs(inet->inet_sport);
1767 1766
@@ -1810,11 +1809,10 @@ static void get_timewait6_sock(struct seq_file *seq,
1810{ 1809{
1811 const struct in6_addr *dest, *src; 1810 const struct in6_addr *dest, *src;
1812 __u16 destp, srcp; 1811 __u16 destp, srcp;
1813 const struct inet6_timewait_sock *tw6 = inet6_twsk((struct sock *)tw);
1814 s32 delta = tw->tw_ttd - inet_tw_time_stamp(); 1812 s32 delta = tw->tw_ttd - inet_tw_time_stamp();
1815 1813
1816 dest = &tw6->tw_v6_daddr; 1814 dest = &tw->tw_v6_daddr;
1817 src = &tw6->tw_v6_rcv_saddr; 1815 src = &tw->tw_v6_rcv_saddr;
1818 destp = ntohs(tw->tw_dport); 1816 destp = ntohs(tw->tw_dport);
1819 srcp = ntohs(tw->tw_sport); 1817 srcp = ntohs(tw->tw_sport);
1820 1818