aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/tcp_ipv6.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv6/tcp_ipv6.c')
-rw-r--r--net/ipv6/tcp_ipv6.c146
1 files changed, 105 insertions, 41 deletions
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 21d100b68b19..febfd595a40d 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -96,7 +96,7 @@ static void tcp_v6_hash(struct sock *sk)
96 return; 96 return;
97 } 97 }
98 local_bh_disable(); 98 local_bh_disable();
99 __inet6_hash(sk); 99 __inet6_hash(sk, NULL);
100 local_bh_enable(); 100 local_bh_enable();
101 } 101 }
102} 102}
@@ -226,10 +226,9 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
226#endif 226#endif
227 goto failure; 227 goto failure;
228 } else { 228 } else {
229 ipv6_addr_set(&np->saddr, 0, 0, htonl(0x0000FFFF), 229 ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
230 inet->saddr); 230 ipv6_addr_set_v4mapped(inet->inet_rcv_saddr,
231 ipv6_addr_set(&np->rcv_saddr, 0, 0, htonl(0x0000FFFF), 231 &np->rcv_saddr);
232 inet->rcv_saddr);
233 } 232 }
234 233
235 return err; 234 return err;
@@ -243,8 +242,9 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
243 ipv6_addr_copy(&fl.fl6_src, 242 ipv6_addr_copy(&fl.fl6_src,
244 (saddr ? saddr : &np->saddr)); 243 (saddr ? saddr : &np->saddr));
245 fl.oif = sk->sk_bound_dev_if; 244 fl.oif = sk->sk_bound_dev_if;
245 fl.mark = sk->sk_mark;
246 fl.fl_ip_dport = usin->sin6_port; 246 fl.fl_ip_dport = usin->sin6_port;
247 fl.fl_ip_sport = inet->sport; 247 fl.fl_ip_sport = inet->inet_sport;
248 248
249 if (np->opt && np->opt->srcrt) { 249 if (np->opt && np->opt->srcrt) {
250 struct rt0_hdr *rt0 = (struct rt0_hdr *)np->opt->srcrt; 250 struct rt0_hdr *rt0 = (struct rt0_hdr *)np->opt->srcrt;
@@ -276,7 +276,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
276 276
277 /* set the source address */ 277 /* set the source address */
278 ipv6_addr_copy(&np->saddr, saddr); 278 ipv6_addr_copy(&np->saddr, saddr);
279 inet->rcv_saddr = LOOPBACK4_IPV6; 279 inet->inet_rcv_saddr = LOOPBACK4_IPV6;
280 280
281 sk->sk_gso_type = SKB_GSO_TCPV6; 281 sk->sk_gso_type = SKB_GSO_TCPV6;
282 __ip6_dst_store(sk, dst, NULL, NULL); 282 __ip6_dst_store(sk, dst, NULL, NULL);
@@ -288,7 +288,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
288 288
289 tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr); 289 tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr);
290 290
291 inet->dport = usin->sin6_port; 291 inet->inet_dport = usin->sin6_port;
292 292
293 tcp_set_state(sk, TCP_SYN_SENT); 293 tcp_set_state(sk, TCP_SYN_SENT);
294 err = inet6_hash_connect(&tcp_death_row, sk); 294 err = inet6_hash_connect(&tcp_death_row, sk);
@@ -298,8 +298,8 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
298 if (!tp->write_seq) 298 if (!tp->write_seq)
299 tp->write_seq = secure_tcpv6_sequence_number(np->saddr.s6_addr32, 299 tp->write_seq = secure_tcpv6_sequence_number(np->saddr.s6_addr32,
300 np->daddr.s6_addr32, 300 np->daddr.s6_addr32,
301 inet->sport, 301 inet->inet_sport,
302 inet->dport); 302 inet->inet_dport);
303 303
304 err = tcp_connect(sk); 304 err = tcp_connect(sk);
305 if (err) 305 if (err)
@@ -311,7 +311,7 @@ late_failure:
311 tcp_set_state(sk, TCP_CLOSE); 311 tcp_set_state(sk, TCP_CLOSE);
312 __sk_dst_reset(sk); 312 __sk_dst_reset(sk);
313failure: 313failure:
314 inet->dport = 0; 314 inet->inet_dport = 0;
315 sk->sk_route_caps = 0; 315 sk->sk_route_caps = 0;
316 return err; 316 return err;
317} 317}
@@ -383,8 +383,9 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
383 ipv6_addr_copy(&fl.fl6_dst, &np->daddr); 383 ipv6_addr_copy(&fl.fl6_dst, &np->daddr);
384 ipv6_addr_copy(&fl.fl6_src, &np->saddr); 384 ipv6_addr_copy(&fl.fl6_src, &np->saddr);
385 fl.oif = sk->sk_bound_dev_if; 385 fl.oif = sk->sk_bound_dev_if;
386 fl.fl_ip_dport = inet->dport; 386 fl.mark = sk->sk_mark;
387 fl.fl_ip_sport = inet->sport; 387 fl.fl_ip_dport = inet->inet_dport;
388 fl.fl_ip_sport = inet->inet_sport;
388 security_skb_classify_flow(skb, &fl); 389 security_skb_classify_flow(skb, &fl);
389 390
390 if ((err = ip6_dst_lookup(sk, &dst, &fl))) { 391 if ((err = ip6_dst_lookup(sk, &dst, &fl))) {
@@ -460,7 +461,8 @@ out:
460} 461}
461 462
462 463
463static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req) 464static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req,
465 struct request_values *rvp)
464{ 466{
465 struct inet6_request_sock *treq = inet6_rsk(req); 467 struct inet6_request_sock *treq = inet6_rsk(req);
466 struct ipv6_pinfo *np = inet6_sk(sk); 468 struct ipv6_pinfo *np = inet6_sk(sk);
@@ -477,6 +479,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req)
477 ipv6_addr_copy(&fl.fl6_src, &treq->loc_addr); 479 ipv6_addr_copy(&fl.fl6_src, &treq->loc_addr);
478 fl.fl6_flowlabel = 0; 480 fl.fl6_flowlabel = 0;
479 fl.oif = treq->iif; 481 fl.oif = treq->iif;
482 fl.mark = sk->sk_mark;
480 fl.fl_ip_dport = inet_rsk(req)->rmt_port; 483 fl.fl_ip_dport = inet_rsk(req)->rmt_port;
481 fl.fl_ip_sport = inet_rsk(req)->loc_port; 484 fl.fl_ip_sport = inet_rsk(req)->loc_port;
482 security_req_classify_flow(req, &fl); 485 security_req_classify_flow(req, &fl);
@@ -497,7 +500,7 @@ static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req)
497 if ((err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0) 500 if ((err = xfrm_lookup(sock_net(sk), &dst, &fl, sk, 0)) < 0)
498 goto done; 501 goto done;
499 502
500 skb = tcp_make_synack(sk, dst, req); 503 skb = tcp_make_synack(sk, dst, req, rvp);
501 if (skb) { 504 if (skb) {
502 struct tcphdr *th = tcp_hdr(skb); 505 struct tcphdr *th = tcp_hdr(skb);
503 506
@@ -1159,11 +1162,13 @@ static struct sock *tcp_v6_hnd_req(struct sock *sk,struct sk_buff *skb)
1159 */ 1162 */
1160static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) 1163static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
1161{ 1164{
1165 struct tcp_extend_values tmp_ext;
1166 struct tcp_options_received tmp_opt;
1167 u8 *hash_location;
1168 struct request_sock *req;
1162 struct inet6_request_sock *treq; 1169 struct inet6_request_sock *treq;
1163 struct ipv6_pinfo *np = inet6_sk(sk); 1170 struct ipv6_pinfo *np = inet6_sk(sk);
1164 struct tcp_options_received tmp_opt;
1165 struct tcp_sock *tp = tcp_sk(sk); 1171 struct tcp_sock *tp = tcp_sk(sk);
1166 struct request_sock *req = NULL;
1167 __u32 isn = TCP_SKB_CB(skb)->when; 1172 __u32 isn = TCP_SKB_CB(skb)->when;
1168#ifdef CONFIG_SYN_COOKIES 1173#ifdef CONFIG_SYN_COOKIES
1169 int want_cookie = 0; 1174 int want_cookie = 0;
@@ -1202,8 +1207,52 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
1202 tcp_clear_options(&tmp_opt); 1207 tcp_clear_options(&tmp_opt);
1203 tmp_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr); 1208 tmp_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr);
1204 tmp_opt.user_mss = tp->rx_opt.user_mss; 1209 tmp_opt.user_mss = tp->rx_opt.user_mss;
1210 tcp_parse_options(skb, &tmp_opt, &hash_location, 0);
1211
1212 if (tmp_opt.cookie_plus > 0 &&
1213 tmp_opt.saw_tstamp &&
1214 !tp->rx_opt.cookie_out_never &&
1215 (sysctl_tcp_cookie_size > 0 ||
1216 (tp->cookie_values != NULL &&
1217 tp->cookie_values->cookie_desired > 0))) {
1218 u8 *c;
1219 u32 *d;
1220 u32 *mess = &tmp_ext.cookie_bakery[COOKIE_DIGEST_WORDS];
1221 int l = tmp_opt.cookie_plus - TCPOLEN_COOKIE_BASE;
1222
1223 if (tcp_cookie_generator(&tmp_ext.cookie_bakery[0]) != 0)
1224 goto drop_and_free;
1225
1226 /* Secret recipe starts with IP addresses */
1227 d = &ipv6_hdr(skb)->daddr.s6_addr32[0];
1228 *mess++ ^= *d++;
1229 *mess++ ^= *d++;
1230 *mess++ ^= *d++;
1231 *mess++ ^= *d++;
1232 d = &ipv6_hdr(skb)->saddr.s6_addr32[0];
1233 *mess++ ^= *d++;
1234 *mess++ ^= *d++;
1235 *mess++ ^= *d++;
1236 *mess++ ^= *d++;
1237
1238 /* plus variable length Initiator Cookie */
1239 c = (u8 *)mess;
1240 while (l-- > 0)
1241 *c++ ^= *hash_location++;
1205 1242
1206 tcp_parse_options(skb, &tmp_opt, 0); 1243#ifdef CONFIG_SYN_COOKIES
1244 want_cookie = 0; /* not our kind of cookie */
1245#endif
1246 tmp_ext.cookie_out_never = 0; /* false */
1247 tmp_ext.cookie_plus = tmp_opt.cookie_plus;
1248 } else if (!tp->rx_opt.cookie_in_always) {
1249 /* redundant indications, but ensure initialization. */
1250 tmp_ext.cookie_out_never = 1; /* true */
1251 tmp_ext.cookie_plus = 0;
1252 } else {
1253 goto drop_and_free;
1254 }
1255 tmp_ext.cookie_in_always = tp->rx_opt.cookie_in_always;
1207 1256
1208 if (want_cookie && !tmp_opt.saw_tstamp) 1257 if (want_cookie && !tmp_opt.saw_tstamp)
1209 tcp_clear_options(&tmp_opt); 1258 tcp_clear_options(&tmp_opt);
@@ -1236,23 +1285,21 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
1236 1285
1237 isn = tcp_v6_init_sequence(skb); 1286 isn = tcp_v6_init_sequence(skb);
1238 } 1287 }
1239
1240 tcp_rsk(req)->snt_isn = isn; 1288 tcp_rsk(req)->snt_isn = isn;
1241 1289
1242 security_inet_conn_request(sk, skb, req); 1290 security_inet_conn_request(sk, skb, req);
1243 1291
1244 if (tcp_v6_send_synack(sk, req)) 1292 if (tcp_v6_send_synack(sk, req,
1245 goto drop; 1293 (struct request_values *)&tmp_ext) ||
1294 want_cookie)
1295 goto drop_and_free;
1246 1296
1247 if (!want_cookie) { 1297 inet6_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
1248 inet6_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT); 1298 return 0;
1249 return 0;
1250 }
1251 1299
1300drop_and_free:
1301 reqsk_free(req);
1252drop: 1302drop:
1253 if (req)
1254 reqsk_free(req);
1255
1256 return 0; /* don't send reset */ 1303 return 0; /* don't send reset */
1257} 1304}
1258 1305
@@ -1290,11 +1337,9 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1290 1337
1291 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1338 memcpy(newnp, np, sizeof(struct ipv6_pinfo));
1292 1339
1293 ipv6_addr_set(&newnp->daddr, 0, 0, htonl(0x0000FFFF), 1340 ipv6_addr_set_v4mapped(newinet->inet_daddr, &newnp->daddr);
1294 newinet->daddr);
1295 1341
1296 ipv6_addr_set(&newnp->saddr, 0, 0, htonl(0x0000FFFF), 1342 ipv6_addr_set_v4mapped(newinet->inet_saddr, &newnp->saddr);
1297 newinet->saddr);
1298 1343
1299 ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr); 1344 ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr);
1300 1345
@@ -1345,6 +1390,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1345 } 1390 }
1346 ipv6_addr_copy(&fl.fl6_src, &treq->loc_addr); 1391 ipv6_addr_copy(&fl.fl6_src, &treq->loc_addr);
1347 fl.oif = sk->sk_bound_dev_if; 1392 fl.oif = sk->sk_bound_dev_if;
1393 fl.mark = sk->sk_mark;
1348 fl.fl_ip_dport = inet_rsk(req)->rmt_port; 1394 fl.fl_ip_dport = inet_rsk(req)->rmt_port;
1349 fl.fl_ip_sport = inet_rsk(req)->loc_port; 1395 fl.fl_ip_sport = inet_rsk(req)->loc_port;
1350 security_req_classify_flow(req, &fl); 1396 security_req_classify_flow(req, &fl);
@@ -1431,7 +1477,8 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1431 newtp->advmss = dst_metric(dst, RTAX_ADVMSS); 1477 newtp->advmss = dst_metric(dst, RTAX_ADVMSS);
1432 tcp_initialize_rcv_mss(newsk); 1478 tcp_initialize_rcv_mss(newsk);
1433 1479
1434 newinet->daddr = newinet->saddr = newinet->rcv_saddr = LOOPBACK4_IPV6; 1480 newinet->inet_daddr = newinet->inet_saddr = LOOPBACK4_IPV6;
1481 newinet->inet_rcv_saddr = LOOPBACK4_IPV6;
1435 1482
1436#ifdef CONFIG_TCP_MD5SIG 1483#ifdef CONFIG_TCP_MD5SIG
1437 /* Copy over the MD5 key from the original socket */ 1484 /* Copy over the MD5 key from the original socket */
@@ -1448,7 +1495,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb,
1448 } 1495 }
1449#endif 1496#endif
1450 1497
1451 __inet6_hash(newsk); 1498 __inet6_hash(newsk, NULL);
1452 __inet_inherit_port(sk, newsk); 1499 __inet_inherit_port(sk, newsk);
1453 1500
1454 return newsk; 1501 return newsk;
@@ -1848,7 +1895,7 @@ static int tcp_v6_init_sock(struct sock *sk)
1848 */ 1895 */
1849 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH; 1896 tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
1850 tp->snd_cwnd_clamp = ~0; 1897 tp->snd_cwnd_clamp = ~0;
1851 tp->mss_cache = 536; 1898 tp->mss_cache = TCP_MSS_DEFAULT;
1852 1899
1853 tp->reordering = sysctl_tcp_reordering; 1900 tp->reordering = sysctl_tcp_reordering;
1854 1901
@@ -1864,6 +1911,19 @@ static int tcp_v6_init_sock(struct sock *sk)
1864 tp->af_specific = &tcp_sock_ipv6_specific; 1911 tp->af_specific = &tcp_sock_ipv6_specific;
1865#endif 1912#endif
1866 1913
1914 /* TCP Cookie Transactions */
1915 if (sysctl_tcp_cookie_size > 0) {
1916 /* Default, cookies without s_data_payload. */
1917 tp->cookie_values =
1918 kzalloc(sizeof(*tp->cookie_values),
1919 sk->sk_allocation);
1920 if (tp->cookie_values != NULL)
1921 kref_init(&tp->cookie_values->kref);
1922 }
1923 /* Presumed zeroed, in order of appearance:
1924 * cookie_in_always, cookie_out_never,
1925 * s_data_constant, s_data_in, s_data_out
1926 */
1867 sk->sk_sndbuf = sysctl_tcp_wmem[1]; 1927 sk->sk_sndbuf = sysctl_tcp_wmem[1];
1868 sk->sk_rcvbuf = sysctl_tcp_rmem[1]; 1928 sk->sk_rcvbuf = sysctl_tcp_rmem[1];
1869 1929
@@ -1931,8 +1991,8 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
1931 1991
1932 dest = &np->daddr; 1992 dest = &np->daddr;
1933 src = &np->rcv_saddr; 1993 src = &np->rcv_saddr;
1934 destp = ntohs(inet->dport); 1994 destp = ntohs(inet->inet_dport);
1935 srcp = ntohs(inet->sport); 1995 srcp = ntohs(inet->inet_sport);
1936 1996
1937 if (icsk->icsk_pending == ICSK_TIME_RETRANS) { 1997 if (icsk->icsk_pending == ICSK_TIME_RETRANS) {
1938 timer_active = 1; 1998 timer_active = 1;
@@ -2109,7 +2169,6 @@ static struct inet_protosw tcpv6_protosw = {
2109 .protocol = IPPROTO_TCP, 2169 .protocol = IPPROTO_TCP,
2110 .prot = &tcpv6_prot, 2170 .prot = &tcpv6_prot,
2111 .ops = &inet6_stream_ops, 2171 .ops = &inet6_stream_ops,
2112 .capability = -1,
2113 .no_check = 0, 2172 .no_check = 0,
2114 .flags = INET_PROTOSW_PERMANENT | 2173 .flags = INET_PROTOSW_PERMANENT |
2115 INET_PROTOSW_ICSK, 2174 INET_PROTOSW_ICSK,
@@ -2124,12 +2183,17 @@ static int tcpv6_net_init(struct net *net)
2124static void tcpv6_net_exit(struct net *net) 2183static void tcpv6_net_exit(struct net *net)
2125{ 2184{
2126 inet_ctl_sock_destroy(net->ipv6.tcp_sk); 2185 inet_ctl_sock_destroy(net->ipv6.tcp_sk);
2127 inet_twsk_purge(net, &tcp_hashinfo, &tcp_death_row, AF_INET6); 2186}
2187
2188static void tcpv6_net_exit_batch(struct list_head *net_exit_list)
2189{
2190 inet_twsk_purge(&tcp_hashinfo, &tcp_death_row, AF_INET6);
2128} 2191}
2129 2192
2130static struct pernet_operations tcpv6_net_ops = { 2193static struct pernet_operations tcpv6_net_ops = {
2131 .init = tcpv6_net_init, 2194 .init = tcpv6_net_init,
2132 .exit = tcpv6_net_exit, 2195 .exit = tcpv6_net_exit,
2196 .exit_batch = tcpv6_net_exit_batch,
2133}; 2197};
2134 2198
2135int __init tcpv6_init(void) 2199int __init tcpv6_init(void)