tcp_ipv6.c (4ad19de8774e2a7b075b3e8ea48db85adcf33fa6) | tcp_ipv6.c (63159f29be1df7f93563a8a0f78c5e65fc844ed6) |
---|---|
1/* 2 * TCP over IPv6 3 * Linux INET6 implementation 4 * 5 * Authors: 6 * Pedro Roque <roque@di.fc.ul.pt> 7 * 8 * Based on: --- 90 unchanged lines hidden (view full) --- 99 dst_hold(dst); 100 sk->sk_rx_dst = dst; 101 inet_sk(sk)->rx_dst_ifindex = skb->skb_iif; 102 if (rt->rt6i_node) 103 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum; 104 } 105} 106 | 1/* 2 * TCP over IPv6 3 * Linux INET6 implementation 4 * 5 * Authors: 6 * Pedro Roque <roque@di.fc.ul.pt> 7 * 8 * Based on: --- 90 unchanged lines hidden (view full) --- 99 dst_hold(dst); 100 sk->sk_rx_dst = dst; 101 inet_sk(sk)->rx_dst_ifindex = skb->skb_iif; 102 if (rt->rt6i_node) 103 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum; 104 } 105} 106 |
107static void tcp_v6_hash(struct sock *sk) 108{ 109 if (sk->sk_state != TCP_CLOSE) { 110 if (inet_csk(sk)->icsk_af_ops == &ipv6_mapped) { 111 tcp_prot.hash(sk); 112 return; 113 } 114 local_bh_disable(); 115 __inet6_hash(sk, NULL); 116 local_bh_enable(); 117 } 118} 119 | |
120static __u32 tcp_v6_init_sequence(const struct sk_buff *skb) 121{ 122 return secure_tcpv6_sequence_number(ipv6_hdr(skb)->daddr.s6_addr32, 123 ipv6_hdr(skb)->saddr.s6_addr32, 124 tcp_hdr(skb)->dest, 125 tcp_hdr(skb)->source); 126} 127 --- 21 unchanged lines hidden (view full) --- 149 memset(&fl6, 0, sizeof(fl6)); 150 151 if (np->sndflow) { 152 fl6.flowlabel = usin->sin6_flowinfo&IPV6_FLOWINFO_MASK; 153 IP6_ECN_flow_init(fl6.flowlabel); 154 if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) { 155 struct ip6_flowlabel *flowlabel; 156 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); | 107static __u32 tcp_v6_init_sequence(const struct sk_buff *skb) 108{ 109 return secure_tcpv6_sequence_number(ipv6_hdr(skb)->daddr.s6_addr32, 110 ipv6_hdr(skb)->saddr.s6_addr32, 111 tcp_hdr(skb)->dest, 112 tcp_hdr(skb)->source); 113} 114 --- 21 unchanged lines hidden (view full) --- 136 memset(&fl6, 0, sizeof(fl6)); 137 138 if (np->sndflow) { 139 fl6.flowlabel = usin->sin6_flowinfo&IPV6_FLOWINFO_MASK; 140 IP6_ECN_flow_init(fl6.flowlabel); 141 if (fl6.flowlabel&IPV6_FLOWLABEL_MASK) { 142 struct ip6_flowlabel *flowlabel; 143 flowlabel = fl6_sock_lookup(sk, fl6.flowlabel); |
157 if (flowlabel == NULL) | 144 if (!flowlabel) |
158 return -EINVAL; 159 fl6_sock_release(flowlabel); 160 } 161 } 162 163 /* 164 * connect() to INADDR_ANY means loopback (BSD'ism). 165 */ --- 62 unchanged lines hidden (view full) --- 228 if (err) { 229 icsk->icsk_ext_hdr_len = exthdrlen; 230 icsk->icsk_af_ops = &ipv6_specific; 231 sk->sk_backlog_rcv = tcp_v6_do_rcv; 232#ifdef CONFIG_TCP_MD5SIG 233 tp->af_specific = &tcp_sock_ipv6_specific; 234#endif 235 goto failure; | 145 return -EINVAL; 146 fl6_sock_release(flowlabel); 147 } 148 } 149 150 /* 151 * connect() to INADDR_ANY means loopback (BSD'ism). 152 */ --- 62 unchanged lines hidden (view full) --- 215 if (err) { 216 icsk->icsk_ext_hdr_len = exthdrlen; 217 icsk->icsk_af_ops = &ipv6_specific; 218 sk->sk_backlog_rcv = tcp_v6_do_rcv; 219#ifdef CONFIG_TCP_MD5SIG 220 tp->af_specific = &tcp_sock_ipv6_specific; 221#endif 222 goto failure; |
236 } else { 237 ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr); 238 ipv6_addr_set_v4mapped(inet->inet_rcv_saddr, 239 &sk->sk_v6_rcv_saddr); | |
240 } | 223 } |
224 np->saddr = sk->sk_v6_rcv_saddr; |
|
241 242 return err; 243 } 244 245 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) 246 saddr = &sk->sk_v6_rcv_saddr; 247 248 fl6.flowi6_proto = IPPROTO_TCP; --- 9 unchanged lines hidden (view full) --- 258 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 259 260 dst = ip6_dst_lookup_flow(sk, &fl6, final_p); 261 if (IS_ERR(dst)) { 262 err = PTR_ERR(dst); 263 goto failure; 264 } 265 | 225 226 return err; 227 } 228 229 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) 230 saddr = &sk->sk_v6_rcv_saddr; 231 232 fl6.flowi6_proto = IPPROTO_TCP; --- 9 unchanged lines hidden (view full) --- 242 security_sk_classify_flow(sk, flowi6_to_flowi(&fl6)); 243 244 dst = ip6_dst_lookup_flow(sk, &fl6, final_p); 245 if (IS_ERR(dst)) { 246 err = PTR_ERR(dst); 247 goto failure; 248 } 249 |
266 if (saddr == NULL) { | 250 if (!saddr) { |
267 saddr = &fl6.saddr; 268 sk->sk_v6_rcv_saddr = *saddr; 269 } 270 271 /* set the source address */ 272 np->saddr = *saddr; 273 inet->inet_rcv_saddr = LOOPBACK4_IPV6; 274 --- 60 unchanged lines hidden (view full) --- 335 } 336} 337 338static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 339 u8 type, u8 code, int offset, __be32 info) 340{ 341 const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data; 342 const struct tcphdr *th = (struct tcphdr *)(skb->data+offset); | 251 saddr = &fl6.saddr; 252 sk->sk_v6_rcv_saddr = *saddr; 253 } 254 255 /* set the source address */ 256 np->saddr = *saddr; 257 inet->inet_rcv_saddr = LOOPBACK4_IPV6; 258 --- 60 unchanged lines hidden (view full) --- 319 } 320} 321 322static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 323 u8 type, u8 code, int offset, __be32 info) 324{ 325 const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data; 326 const struct tcphdr *th = (struct tcphdr *)(skb->data+offset); |
327 struct net *net = dev_net(skb->dev); 328 struct request_sock *fastopen; |
|
343 struct ipv6_pinfo *np; | 329 struct ipv6_pinfo *np; |
344 struct sock *sk; 345 int err; | |
346 struct tcp_sock *tp; | 330 struct tcp_sock *tp; |
347 struct request_sock *fastopen; | |
348 __u32 seq, snd_una; | 331 __u32 seq, snd_una; |
349 struct net *net = dev_net(skb->dev); | 332 struct sock *sk; 333 int err; |
350 | 334 |
351 sk = inet6_lookup(net, &tcp_hashinfo, &hdr->daddr, 352 th->dest, &hdr->saddr, th->source, skb->dev->ifindex); | 335 sk = __inet6_lookup_established(net, &tcp_hashinfo, 336 &hdr->daddr, th->dest, 337 &hdr->saddr, ntohs(th->source), 338 skb->dev->ifindex); |
353 | 339 |
354 if (sk == NULL) { | 340 if (!sk) { |
355 ICMP6_INC_STATS_BH(net, __in6_dev_get(skb->dev), 356 ICMP6_MIB_INERRORS); 357 return; 358 } 359 360 if (sk->sk_state == TCP_TIME_WAIT) { 361 inet_twsk_put(inet_twsk(sk)); 362 return; 363 } | 341 ICMP6_INC_STATS_BH(net, __in6_dev_get(skb->dev), 342 ICMP6_MIB_INERRORS); 343 return; 344 } 345 346 if (sk->sk_state == TCP_TIME_WAIT) { 347 inet_twsk_put(inet_twsk(sk)); 348 return; 349 } |
350 seq = ntohl(th->seq); 351 if (sk->sk_state == TCP_NEW_SYN_RECV) 352 return tcp_req_err(sk, seq); |
|
364 365 bh_lock_sock(sk); 366 if (sock_owned_by_user(sk) && type != ICMPV6_PKT_TOOBIG) 367 NET_INC_STATS_BH(net, LINUX_MIB_LOCKDROPPEDICMPS); 368 369 if (sk->sk_state == TCP_CLOSE) 370 goto out; 371 372 if (ipv6_hdr(skb)->hop_limit < inet6_sk(sk)->min_hopcount) { 373 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP); 374 goto out; 375 } 376 377 tp = tcp_sk(sk); | 353 354 bh_lock_sock(sk); 355 if (sock_owned_by_user(sk) && type != ICMPV6_PKT_TOOBIG) 356 NET_INC_STATS_BH(net, LINUX_MIB_LOCKDROPPEDICMPS); 357 358 if (sk->sk_state == TCP_CLOSE) 359 goto out; 360 361 if (ipv6_hdr(skb)->hop_limit < inet6_sk(sk)->min_hopcount) { 362 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP); 363 goto out; 364 } 365 366 tp = tcp_sk(sk); |
378 seq = ntohl(th->seq); | |
379 /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */ 380 fastopen = tp->fastopen_rsk; 381 snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una; 382 if (sk->sk_state != TCP_LISTEN && 383 !between(seq, snd_una, tp->snd_nxt)) { 384 NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS); 385 goto out; 386 } --- 27 unchanged lines hidden (view full) --- 414 sock_hold(sk); 415 goto out; 416 } 417 418 icmpv6_err_convert(type, code, &err); 419 420 /* Might be for an request_sock */ 421 switch (sk->sk_state) { | 367 /* XXX (TFO) - tp->snd_una should be ISN (tcp_create_openreq_child() */ 368 fastopen = tp->fastopen_rsk; 369 snd_una = fastopen ? tcp_rsk(fastopen)->snt_isn : tp->snd_una; 370 if (sk->sk_state != TCP_LISTEN && 371 !between(seq, snd_una, tp->snd_nxt)) { 372 NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS); 373 goto out; 374 } --- 27 unchanged lines hidden (view full) --- 402 sock_hold(sk); 403 goto out; 404 } 405 406 icmpv6_err_convert(type, code, &err); 407 408 /* Might be for an request_sock */ 409 switch (sk->sk_state) { |
422 struct request_sock *req, **prev; 423 case TCP_LISTEN: 424 if (sock_owned_by_user(sk)) 425 goto out; 426 427 /* Note : We use inet6_iif() here, not tcp_v6_iif() */ 428 req = inet6_csk_search_req(sk, &prev, th->dest, &hdr->daddr, 429 &hdr->saddr, inet6_iif(skb)); 430 if (!req) 431 goto out; 432 433 /* ICMPs are not backlogged, hence we cannot get 434 * an established socket here. 435 */ 436 WARN_ON(req->sk != NULL); 437 438 if (seq != tcp_rsk(req)->snt_isn) { 439 NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS); 440 goto out; 441 } 442 443 inet_csk_reqsk_queue_drop(sk, req, prev); 444 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_LISTENDROPS); 445 goto out; 446 | |
447 case TCP_SYN_SENT: 448 case TCP_SYN_RECV: 449 /* Only in fast or simultaneous open. If a fast open socket is 450 * is already accepted it is treated as a connected one below. 451 */ | 410 case TCP_SYN_SENT: 411 case TCP_SYN_RECV: 412 /* Only in fast or simultaneous open. If a fast open socket is 413 * is already accepted it is treated as a connected one below. 414 */ |
452 if (fastopen && fastopen->sk == NULL) | 415 if (fastopen && !fastopen->sk) |
453 break; 454 455 if (!sock_owned_by_user(sk)) { 456 sk->sk_err = err; 457 sk->sk_error_report(sk); /* Wake people up to see the error (see connect in sock.c) */ 458 459 tcp_done(sk); 460 } else --- 57 unchanged lines hidden (view full) --- 518#ifdef CONFIG_TCP_MD5SIG 519static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk, 520 const struct in6_addr *addr) 521{ 522 return tcp_md5_do_lookup(sk, (union tcp_md5_addr *)addr, AF_INET6); 523} 524 525static struct tcp_md5sig_key *tcp_v6_md5_lookup(struct sock *sk, | 416 break; 417 418 if (!sock_owned_by_user(sk)) { 419 sk->sk_err = err; 420 sk->sk_error_report(sk); /* Wake people up to see the error (see connect in sock.c) */ 421 422 tcp_done(sk); 423 } else --- 57 unchanged lines hidden (view full) --- 481#ifdef CONFIG_TCP_MD5SIG 482static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk, 483 const struct in6_addr *addr) 484{ 485 return tcp_md5_do_lookup(sk, (union tcp_md5_addr *)addr, AF_INET6); 486} 487 488static struct tcp_md5sig_key *tcp_v6_md5_lookup(struct sock *sk, |
526 struct sock *addr_sk) | 489 const struct sock *addr_sk) |
527{ 528 return tcp_v6_md5_do_lookup(sk, &addr_sk->sk_v6_daddr); 529} 530 | 490{ 491 return tcp_v6_md5_do_lookup(sk, &addr_sk->sk_v6_daddr); 492} 493 |
531static struct tcp_md5sig_key *tcp_v6_reqsk_md5_lookup(struct sock *sk, 532 struct request_sock *req) 533{ 534 return tcp_v6_md5_do_lookup(sk, &inet_rsk(req)->ir_v6_rmt_addr); 535} 536 | |
537static int tcp_v6_parse_md5_keys(struct sock *sk, char __user *optval, 538 int optlen) 539{ 540 struct tcp_md5sig cmd; 541 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&cmd.tcpm_addr; 542 543 if (optlen < sizeof(cmd)) 544 return -EINVAL; --- 69 unchanged lines hidden (view full) --- 614 615clear_hash: 616 tcp_put_md5sig_pool(); 617clear_hash_noput: 618 memset(md5_hash, 0, 16); 619 return 1; 620} 621 | 494static int tcp_v6_parse_md5_keys(struct sock *sk, char __user *optval, 495 int optlen) 496{ 497 struct tcp_md5sig cmd; 498 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&cmd.tcpm_addr; 499 500 if (optlen < sizeof(cmd)) 501 return -EINVAL; --- 69 unchanged lines hidden (view full) --- 571 572clear_hash: 573 tcp_put_md5sig_pool(); 574clear_hash_noput: 575 memset(md5_hash, 0, 16); 576 return 1; 577} 578 |
622static int tcp_v6_md5_hash_skb(char *md5_hash, struct tcp_md5sig_key *key, | 579static int tcp_v6_md5_hash_skb(char *md5_hash, 580 const struct tcp_md5sig_key *key, |
623 const struct sock *sk, | 581 const struct sock *sk, |
624 const struct request_sock *req, | |
625 const struct sk_buff *skb) 626{ 627 const struct in6_addr *saddr, *daddr; 628 struct tcp_md5sig_pool *hp; 629 struct hash_desc *desc; 630 const struct tcphdr *th = tcp_hdr(skb); 631 | 582 const struct sk_buff *skb) 583{ 584 const struct in6_addr *saddr, *daddr; 585 struct tcp_md5sig_pool *hp; 586 struct hash_desc *desc; 587 const struct tcphdr *th = tcp_hdr(skb); 588 |
632 if (sk) { 633 saddr = &inet6_sk(sk)->saddr; | 589 if (sk) { /* valid for establish/request sockets */ 590 saddr = &sk->sk_v6_rcv_saddr; |
634 daddr = &sk->sk_v6_daddr; | 591 daddr = &sk->sk_v6_daddr; |
635 } else if (req) { 636 saddr = &inet_rsk(req)->ir_v6_loc_addr; 637 daddr = &inet_rsk(req)->ir_v6_rmt_addr; | |
638 } else { 639 const struct ipv6hdr *ip6h = ipv6_hdr(skb); 640 saddr = &ip6h->saddr; 641 daddr = &ip6h->daddr; 642 } 643 644 hp = tcp_get_md5sig_pool(); 645 if (!hp) --- 19 unchanged lines hidden (view full) --- 665 666clear_hash: 667 tcp_put_md5sig_pool(); 668clear_hash_noput: 669 memset(md5_hash, 0, 16); 670 return 1; 671} 672 | 592 } else { 593 const struct ipv6hdr *ip6h = ipv6_hdr(skb); 594 saddr = &ip6h->saddr; 595 daddr = &ip6h->daddr; 596 } 597 598 hp = tcp_get_md5sig_pool(); 599 if (!hp) --- 19 unchanged lines hidden (view full) --- 619 620clear_hash: 621 tcp_put_md5sig_pool(); 622clear_hash_noput: 623 memset(md5_hash, 0, 16); 624 return 1; 625} 626 |
673static int __tcp_v6_inbound_md5_hash(struct sock *sk, 674 const struct sk_buff *skb) | 627static bool tcp_v6_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb) |
675{ 676 const __u8 *hash_location = NULL; 677 struct tcp_md5sig_key *hash_expected; 678 const struct ipv6hdr *ip6h = ipv6_hdr(skb); 679 const struct tcphdr *th = tcp_hdr(skb); 680 int genhash; 681 u8 newhash[16]; 682 683 hash_expected = tcp_v6_md5_do_lookup(sk, &ip6h->saddr); 684 hash_location = tcp_parse_md5sig_option(th); 685 686 /* We've parsed the options - do we have a hash? */ 687 if (!hash_expected && !hash_location) | 628{ 629 const __u8 *hash_location = NULL; 630 struct tcp_md5sig_key *hash_expected; 631 const struct ipv6hdr *ip6h = ipv6_hdr(skb); 632 const struct tcphdr *th = tcp_hdr(skb); 633 int genhash; 634 u8 newhash[16]; 635 636 hash_expected = tcp_v6_md5_do_lookup(sk, &ip6h->saddr); 637 hash_location = tcp_parse_md5sig_option(th); 638 639 /* We've parsed the options - do we have a hash? */ 640 if (!hash_expected && !hash_location) |
688 return 0; | 641 return false; |
689 690 if (hash_expected && !hash_location) { 691 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND); | 642 643 if (hash_expected && !hash_location) { 644 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND); |
692 return 1; | 645 return true; |
693 } 694 695 if (!hash_expected && hash_location) { 696 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED); | 646 } 647 648 if (!hash_expected && hash_location) { 649 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED); |
697 return 1; | 650 return true; |
698 } 699 700 /* check the signature */ 701 genhash = tcp_v6_md5_hash_skb(newhash, 702 hash_expected, | 651 } 652 653 /* check the signature */ 654 genhash = tcp_v6_md5_hash_skb(newhash, 655 hash_expected, |
703 NULL, NULL, skb); | 656 NULL, skb); |
704 705 if (genhash || memcmp(hash_location, newhash, 16) != 0) { 706 net_info_ratelimited("MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u\n", 707 genhash ? "failed" : "mismatch", 708 &ip6h->saddr, ntohs(th->source), 709 &ip6h->daddr, ntohs(th->dest)); | 657 658 if (genhash || memcmp(hash_location, newhash, 16) != 0) { 659 net_info_ratelimited("MD5 Hash %s for [%pI6c]:%u->[%pI6c]:%u\n", 660 genhash ? "failed" : "mismatch", 661 &ip6h->saddr, ntohs(th->source), 662 &ip6h->daddr, ntohs(th->dest)); |
710 return 1; | 663 return true; |
711 } | 664 } |
712 return 0; | 665 return false; |
713} | 666} |
714 715static int tcp_v6_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb) 716{ 717 int ret; 718 719 rcu_read_lock(); 720 ret = __tcp_v6_inbound_md5_hash(sk, skb); 721 rcu_read_unlock(); 722 723 return ret; 724} 725 | |
726#endif 727 728static void tcp_v6_init_req(struct request_sock *req, struct sock *sk, 729 struct sk_buff *skb) 730{ 731 struct inet_request_sock *ireq = inet_rsk(req); 732 struct ipv6_pinfo *np = inet6_sk(sk); 733 734 ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr; 735 ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr; 736 | 667#endif 668 669static void tcp_v6_init_req(struct request_sock *req, struct sock *sk, 670 struct sk_buff *skb) 671{ 672 struct inet_request_sock *ireq = inet_rsk(req); 673 struct ipv6_pinfo *np = inet6_sk(sk); 674 675 ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr; 676 ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr; 677 |
737 ireq->ir_iif = sk->sk_bound_dev_if; 738 | |
739 /* So that link locals have meaning */ 740 if (!sk->sk_bound_dev_if && 741 ipv6_addr_type(&ireq->ir_v6_rmt_addr) & IPV6_ADDR_LINKLOCAL) 742 ireq->ir_iif = tcp_v6_iif(skb); 743 744 if (!TCP_SKB_CB(skb)->tcp_tw_isn && 745 (ipv6_opt_accepted(sk, skb, &TCP_SKB_CB(skb)->header.h6) || 746 np->rxopt.bits.rxinfo || --- 22 unchanged lines hidden (view full) --- 769 .send_reset = tcp_v6_send_reset, 770 .syn_ack_timeout = tcp_syn_ack_timeout, 771}; 772 773static const struct tcp_request_sock_ops tcp_request_sock_ipv6_ops = { 774 .mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - 775 sizeof(struct ipv6hdr), 776#ifdef CONFIG_TCP_MD5SIG | 678 /* So that link locals have meaning */ 679 if (!sk->sk_bound_dev_if && 680 ipv6_addr_type(&ireq->ir_v6_rmt_addr) & IPV6_ADDR_LINKLOCAL) 681 ireq->ir_iif = tcp_v6_iif(skb); 682 683 if (!TCP_SKB_CB(skb)->tcp_tw_isn && 684 (ipv6_opt_accepted(sk, skb, &TCP_SKB_CB(skb)->header.h6) || 685 np->rxopt.bits.rxinfo || --- 22 unchanged lines hidden (view full) --- 708 .send_reset = tcp_v6_send_reset, 709 .syn_ack_timeout = tcp_syn_ack_timeout, 710}; 711 712static const struct tcp_request_sock_ops tcp_request_sock_ipv6_ops = { 713 .mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - 714 sizeof(struct ipv6hdr), 715#ifdef CONFIG_TCP_MD5SIG |
777 .md5_lookup = tcp_v6_reqsk_md5_lookup, | 716 .req_md5_lookup = tcp_v6_md5_lookup, |
778 .calc_md5_hash = tcp_v6_md5_hash_skb, 779#endif 780 .init_req = tcp_v6_init_req, 781#ifdef CONFIG_SYN_COOKIES 782 .cookie_init_seq = cookie_v6_init_sequence, 783#endif 784 .route_req = tcp_v6_route_req, 785 .init_seq = tcp_v6_init_sequence, --- 20 unchanged lines hidden (view full) --- 806 tot_len += TCPOLEN_TSTAMP_ALIGNED; 807#ifdef CONFIG_TCP_MD5SIG 808 if (key) 809 tot_len += TCPOLEN_MD5SIG_ALIGNED; 810#endif 811 812 buff = alloc_skb(MAX_HEADER + sizeof(struct ipv6hdr) + tot_len, 813 GFP_ATOMIC); | 717 .calc_md5_hash = tcp_v6_md5_hash_skb, 718#endif 719 .init_req = tcp_v6_init_req, 720#ifdef CONFIG_SYN_COOKIES 721 .cookie_init_seq = cookie_v6_init_sequence, 722#endif 723 .route_req = tcp_v6_route_req, 724 .init_seq = tcp_v6_init_sequence, --- 20 unchanged lines hidden (view full) --- 745 tot_len += TCPOLEN_TSTAMP_ALIGNED; 746#ifdef CONFIG_TCP_MD5SIG 747 if (key) 748 tot_len += TCPOLEN_MD5SIG_ALIGNED; 749#endif 750 751 buff = alloc_skb(MAX_HEADER + sizeof(struct ipv6hdr) + tot_len, 752 GFP_ATOMIC); |
814 if (buff == NULL) | 753 if (!buff) |
815 return; 816 817 skb_reserve(buff, MAX_HEADER + sizeof(struct ipv6hdr) + tot_len); 818 819 t1 = (struct tcphdr *) skb_push(buff, tot_len); 820 skb_reset_transport_header(buff); 821 822 /* Swap the send and the receive. */ --- 103 unchanged lines hidden (view full) --- 926 if (!sk1) 927 return; 928 929 rcu_read_lock(); 930 key = tcp_v6_md5_do_lookup(sk1, &ipv6h->saddr); 931 if (!key) 932 goto release_sk1; 933 | 754 return; 755 756 skb_reserve(buff, MAX_HEADER + sizeof(struct ipv6hdr) + tot_len); 757 758 t1 = (struct tcphdr *) skb_push(buff, tot_len); 759 skb_reset_transport_header(buff); 760 761 /* Swap the send and the receive. */ --- 103 unchanged lines hidden (view full) --- 865 if (!sk1) 866 return; 867 868 rcu_read_lock(); 869 key = tcp_v6_md5_do_lookup(sk1, &ipv6h->saddr); 870 if (!key) 871 goto release_sk1; 872 |
934 genhash = tcp_v6_md5_hash_skb(newhash, key, NULL, NULL, skb); | 873 genhash = tcp_v6_md5_hash_skb(newhash, key, NULL, skb); |
935 if (genhash || memcmp(hash_location, newhash, 16) != 0) 936 goto release_sk1; 937 } else { 938 key = sk ? tcp_v6_md5_do_lookup(sk, &ipv6h->saddr) : NULL; 939 } 940#endif 941 942 if (th->ack) --- 49 unchanged lines hidden (view full) --- 992 tcp_time_stamp, req->ts_recent, sk->sk_bound_dev_if, 993 tcp_v6_md5_do_lookup(sk, &ipv6_hdr(skb)->daddr), 994 0, 0); 995} 996 997 998static struct sock *tcp_v6_hnd_req(struct sock *sk, struct sk_buff *skb) 999{ | 874 if (genhash || memcmp(hash_location, newhash, 16) != 0) 875 goto release_sk1; 876 } else { 877 key = sk ? tcp_v6_md5_do_lookup(sk, &ipv6h->saddr) : NULL; 878 } 879#endif 880 881 if (th->ack) --- 49 unchanged lines hidden (view full) --- 931 tcp_time_stamp, req->ts_recent, sk->sk_bound_dev_if, 932 tcp_v6_md5_do_lookup(sk, &ipv6_hdr(skb)->daddr), 933 0, 0); 934} 935 936 937static struct sock *tcp_v6_hnd_req(struct sock *sk, struct sk_buff *skb) 938{ |
1000 struct request_sock *req, **prev; | |
1001 const struct tcphdr *th = tcp_hdr(skb); | 939 const struct tcphdr *th = tcp_hdr(skb); |
940 struct request_sock *req; |
|
1002 struct sock *nsk; 1003 1004 /* Find possible connection requests. */ | 941 struct sock *nsk; 942 943 /* Find possible connection requests. */ |
1005 req = inet6_csk_search_req(sk, &prev, th->source, | 944 req = inet6_csk_search_req(sk, th->source, |
1006 &ipv6_hdr(skb)->saddr, 1007 &ipv6_hdr(skb)->daddr, tcp_v6_iif(skb)); | 945 &ipv6_hdr(skb)->saddr, 946 &ipv6_hdr(skb)->daddr, tcp_v6_iif(skb)); |
1008 if (req) 1009 return tcp_check_req(sk, skb, req, prev, false); 1010 | 947 if (req) { 948 nsk = tcp_check_req(sk, skb, req, false); 949 reqsk_put(req); 950 return nsk; 951 } |
1011 nsk = __inet6_lookup_established(sock_net(sk), &tcp_hashinfo, 1012 &ipv6_hdr(skb)->saddr, th->source, 1013 &ipv6_hdr(skb)->daddr, ntohs(th->dest), 1014 tcp_v6_iif(skb)); 1015 1016 if (nsk) { 1017 if (nsk->sk_state != TCP_TIME_WAIT) { 1018 bh_lock_sock(nsk); --- 43 unchanged lines hidden (view full) --- 1062 1063 if (skb->protocol == htons(ETH_P_IP)) { 1064 /* 1065 * v6 mapped 1066 */ 1067 1068 newsk = tcp_v4_syn_recv_sock(sk, skb, req, dst); 1069 | 952 nsk = __inet6_lookup_established(sock_net(sk), &tcp_hashinfo, 953 &ipv6_hdr(skb)->saddr, th->source, 954 &ipv6_hdr(skb)->daddr, ntohs(th->dest), 955 tcp_v6_iif(skb)); 956 957 if (nsk) { 958 if (nsk->sk_state != TCP_TIME_WAIT) { 959 bh_lock_sock(nsk); --- 43 unchanged lines hidden (view full) --- 1003 1004 if (skb->protocol == htons(ETH_P_IP)) { 1005 /* 1006 * v6 mapped 1007 */ 1008 1009 newsk = tcp_v4_syn_recv_sock(sk, skb, req, dst); 1010 |
1070 if (newsk == NULL) | 1011 if (!newsk) |
1071 return NULL; 1072 1073 newtcp6sk = (struct tcp6_sock *)newsk; 1074 inet_sk(newsk)->pinet6 = &newtcp6sk->inet6; 1075 1076 newinet = inet_sk(newsk); 1077 newnp = inet6_sk(newsk); 1078 newtp = tcp_sk(newsk); 1079 1080 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1081 | 1012 return NULL; 1013 1014 newtcp6sk = (struct tcp6_sock *)newsk; 1015 inet_sk(newsk)->pinet6 = &newtcp6sk->inet6; 1016 1017 newinet = inet_sk(newsk); 1018 newnp = inet6_sk(newsk); 1019 newtp = tcp_sk(newsk); 1020 1021 memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 1022 |
1082 ipv6_addr_set_v4mapped(newinet->inet_daddr, &newsk->sk_v6_daddr); | 1023 newnp->saddr = newsk->sk_v6_rcv_saddr; |
1083 | 1024 |
1084 ipv6_addr_set_v4mapped(newinet->inet_saddr, &newnp->saddr); 1085 1086 newsk->sk_v6_rcv_saddr = newnp->saddr; 1087 | |
1088 inet_csk(newsk)->icsk_af_ops = &ipv6_mapped; 1089 newsk->sk_backlog_rcv = tcp_v4_do_rcv; 1090#ifdef CONFIG_TCP_MD5SIG 1091 newtp->af_specific = &tcp_sock_ipv6_mapped_specific; 1092#endif 1093 1094 newnp->ipv6_ac_list = NULL; 1095 newnp->ipv6_fl_list = NULL; --- 27 unchanged lines hidden (view full) --- 1123 1124 if (!dst) { 1125 dst = inet6_csk_route_req(sk, &fl6, req); 1126 if (!dst) 1127 goto out; 1128 } 1129 1130 newsk = tcp_create_openreq_child(sk, req, skb); | 1025 inet_csk(newsk)->icsk_af_ops = &ipv6_mapped; 1026 newsk->sk_backlog_rcv = tcp_v4_do_rcv; 1027#ifdef CONFIG_TCP_MD5SIG 1028 newtp->af_specific = &tcp_sock_ipv6_mapped_specific; 1029#endif 1030 1031 newnp->ipv6_ac_list = NULL; 1032 newnp->ipv6_fl_list = NULL; --- 27 unchanged lines hidden (view full) --- 1060 1061 if (!dst) { 1062 dst = inet6_csk_route_req(sk, &fl6, req); 1063 if (!dst) 1064 goto out; 1065 } 1066 1067 newsk = tcp_create_openreq_child(sk, req, skb); |
1131 if (newsk == NULL) | 1068 if (!newsk) |
1132 goto out_nonewsk; 1133 1134 /* 1135 * No need to charge this sock to the relevant IPv6 refcnt debug socks 1136 * count here, tcp_create_openreq_child now does this for us, see the 1137 * comment in that function for the gory details. -acme 1138 */ 1139 --- 87 unchanged lines hidden (view full) --- 1227 } 1228#endif 1229 1230 if (__inet_inherit_port(sk, newsk) < 0) { 1231 inet_csk_prepare_forced_close(newsk); 1232 tcp_done(newsk); 1233 goto out; 1234 } | 1069 goto out_nonewsk; 1070 1071 /* 1072 * No need to charge this sock to the relevant IPv6 refcnt debug socks 1073 * count here, tcp_create_openreq_child now does this for us, see the 1074 * comment in that function for the gory details. -acme 1075 */ 1076 --- 87 unchanged lines hidden (view full) --- 1164 } 1165#endif 1166 1167 if (__inet_inherit_port(sk, newsk) < 0) { 1168 inet_csk_prepare_forced_close(newsk); 1169 tcp_done(newsk); 1170 goto out; 1171 } |
1235 __inet6_hash(newsk, NULL); | 1172 __inet_hash(newsk, NULL); |
1236 1237 return newsk; 1238 1239out_overflow: 1240 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS); 1241out_nonewsk: 1242 dst_release(dst); 1243out: --- 162 unchanged lines hidden (view full) --- 1406 skb->len - th->doff*4); 1407 TCP_SKB_CB(skb)->ack_seq = ntohl(th->ack_seq); 1408 TCP_SKB_CB(skb)->tcp_flags = tcp_flag_byte(th); 1409 TCP_SKB_CB(skb)->tcp_tw_isn = 0; 1410 TCP_SKB_CB(skb)->ip_dsfield = ipv6_get_dsfield(hdr); 1411 TCP_SKB_CB(skb)->sacked = 0; 1412} 1413 | 1173 1174 return newsk; 1175 1176out_overflow: 1177 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_LISTENOVERFLOWS); 1178out_nonewsk: 1179 dst_release(dst); 1180out: --- 162 unchanged lines hidden (view full) --- 1343 skb->len - th->doff*4); 1344 TCP_SKB_CB(skb)->ack_seq = ntohl(th->ack_seq); 1345 TCP_SKB_CB(skb)->tcp_flags = tcp_flag_byte(th); 1346 TCP_SKB_CB(skb)->tcp_tw_isn = 0; 1347 TCP_SKB_CB(skb)->ip_dsfield = ipv6_get_dsfield(hdr); 1348 TCP_SKB_CB(skb)->sacked = 0; 1349} 1350 |
1414static void tcp_v6_restore_cb(struct sk_buff *skb) 1415{ 1416 /* We need to move header back to the beginning if xfrm6_policy_check() 1417 * and tcp_v6_fill_cb() are going to be called again. 1418 */ 1419 memmove(IP6CB(skb), &TCP_SKB_CB(skb)->header.h6, 1420 sizeof(struct inet6_skb_parm)); 1421} 1422 | |
1423static int tcp_v6_rcv(struct sk_buff *skb) 1424{ 1425 const struct tcphdr *th; 1426 const struct ipv6hdr *hdr; 1427 struct sock *sk; 1428 int ret; 1429 struct net *net = dev_net(skb->dev); 1430 --- 116 unchanged lines hidden (view full) --- 1547 &ipv6_hdr(skb)->saddr, th->source, 1548 &ipv6_hdr(skb)->daddr, 1549 ntohs(th->dest), tcp_v6_iif(skb)); 1550 if (sk2 != NULL) { 1551 struct inet_timewait_sock *tw = inet_twsk(sk); 1552 inet_twsk_deschedule(tw, &tcp_death_row); 1553 inet_twsk_put(tw); 1554 sk = sk2; | 1351static int tcp_v6_rcv(struct sk_buff *skb) 1352{ 1353 const struct tcphdr *th; 1354 const struct ipv6hdr *hdr; 1355 struct sock *sk; 1356 int ret; 1357 struct net *net = dev_net(skb->dev); 1358 --- 116 unchanged lines hidden (view full) --- 1475 &ipv6_hdr(skb)->saddr, th->source, 1476 &ipv6_hdr(skb)->daddr, 1477 ntohs(th->dest), tcp_v6_iif(skb)); 1478 if (sk2 != NULL) { 1479 struct inet_timewait_sock *tw = inet_twsk(sk); 1480 inet_twsk_deschedule(tw, &tcp_death_row); 1481 inet_twsk_put(tw); 1482 sk = sk2; |
1555 tcp_v6_restore_cb(skb); | |
1556 goto process; 1557 } 1558 /* Fall through to ACK */ 1559 } 1560 case TCP_TW_ACK: 1561 tcp_v6_timewait_ack(sk, skb); 1562 break; 1563 case TCP_TW_RST: | 1483 goto process; 1484 } 1485 /* Fall through to ACK */ 1486 } 1487 case TCP_TW_ACK: 1488 tcp_v6_timewait_ack(sk, skb); 1489 break; 1490 case TCP_TW_RST: |
1564 tcp_v6_restore_cb(skb); | |
1565 goto no_tcp_socket; 1566 case TCP_TW_SUCCESS: 1567 ; 1568 } 1569 goto discard_it; 1570} 1571 1572static void tcp_v6_early_demux(struct sk_buff *skb) --- 17 unchanged lines hidden (view full) --- 1590 /* Note : We use inet6_iif() here, not tcp_v6_iif() */ 1591 sk = __inet6_lookup_established(dev_net(skb->dev), &tcp_hashinfo, 1592 &hdr->saddr, th->source, 1593 &hdr->daddr, ntohs(th->dest), 1594 inet6_iif(skb)); 1595 if (sk) { 1596 skb->sk = sk; 1597 skb->destructor = sock_edemux; | 1491 goto no_tcp_socket; 1492 case TCP_TW_SUCCESS: 1493 ; 1494 } 1495 goto discard_it; 1496} 1497 1498static void tcp_v6_early_demux(struct sk_buff *skb) --- 17 unchanged lines hidden (view full) --- 1516 /* Note : We use inet6_iif() here, not tcp_v6_iif() */ 1517 sk = __inet6_lookup_established(dev_net(skb->dev), &tcp_hashinfo, 1518 &hdr->saddr, th->source, 1519 &hdr->daddr, ntohs(th->dest), 1520 inet6_iif(skb)); 1521 if (sk) { 1522 skb->sk = sk; 1523 skb->destructor = sock_edemux; |
1598 if (sk->sk_state != TCP_TIME_WAIT) { 1599 struct dst_entry *dst = READ_ONCE(sk->sk_rx_dst); | 1524 if (sk_fullsock(sk)) { 1525 struct dst_entry *dst = sk->sk_rx_dst; |
1600 1601 if (dst) 1602 dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie); 1603 if (dst && 1604 inet_sk(sk)->rx_dst_ifindex == skb->skb_iif) 1605 skb_dst_set_noref(skb, dst); 1606 } 1607 } --- 87 unchanged lines hidden (view full) --- 1695{ 1696 tcp_v4_destroy_sock(sk); 1697 inet6_destroy_sock(sk); 1698} 1699 1700#ifdef CONFIG_PROC_FS 1701/* Proc filesystem TCPv6 sock list dumping. */ 1702static void get_openreq6(struct seq_file *seq, | 1526 1527 if (dst) 1528 dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie); 1529 if (dst && 1530 inet_sk(sk)->rx_dst_ifindex == skb->skb_iif) 1531 skb_dst_set_noref(skb, dst); 1532 } 1533 } --- 87 unchanged lines hidden (view full) --- 1621{ 1622 tcp_v4_destroy_sock(sk); 1623 inet6_destroy_sock(sk); 1624} 1625 1626#ifdef CONFIG_PROC_FS 1627/* Proc filesystem TCPv6 sock list dumping. */ 1628static void get_openreq6(struct seq_file *seq, |
1703 const struct sock *sk, struct request_sock *req, int i, kuid_t uid) | 1629 struct request_sock *req, int i, kuid_t uid) |
1704{ | 1630{ |
1705 int ttd = req->expires - jiffies; | 1631 long ttd = req->rsk_timer.expires - jiffies; |
1706 const struct in6_addr *src = &inet_rsk(req)->ir_v6_loc_addr; 1707 const struct in6_addr *dest = &inet_rsk(req)->ir_v6_rmt_addr; 1708 1709 if (ttd < 0) 1710 ttd = 0; 1711 1712 seq_printf(seq, 1713 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " --- 119 unchanged lines hidden (view full) --- 1833 case TCP_SEQ_STATE_LISTENING: 1834 case TCP_SEQ_STATE_ESTABLISHED: 1835 if (sk->sk_state == TCP_TIME_WAIT) 1836 get_timewait6_sock(seq, v, st->num); 1837 else 1838 get_tcp6_sock(seq, v, st->num); 1839 break; 1840 case TCP_SEQ_STATE_OPENREQ: | 1632 const struct in6_addr *src = &inet_rsk(req)->ir_v6_loc_addr; 1633 const struct in6_addr *dest = &inet_rsk(req)->ir_v6_rmt_addr; 1634 1635 if (ttd < 0) 1636 ttd = 0; 1637 1638 seq_printf(seq, 1639 "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " --- 119 unchanged lines hidden (view full) --- 1759 case TCP_SEQ_STATE_LISTENING: 1760 case TCP_SEQ_STATE_ESTABLISHED: 1761 if (sk->sk_state == TCP_TIME_WAIT) 1762 get_timewait6_sock(seq, v, st->num); 1763 else 1764 get_tcp6_sock(seq, v, st->num); 1765 break; 1766 case TCP_SEQ_STATE_OPENREQ: |
1841 get_openreq6(seq, st->syn_wait_sk, v, st->num, st->uid); | 1767 get_openreq6(seq, v, st->num, st->uid); |
1842 break; 1843 } 1844out: 1845 return 0; 1846} 1847 1848static const struct file_operations tcp6_afinfo_seq_fops = { 1849 .owner = THIS_MODULE, --- 47 unchanged lines hidden (view full) --- 1897 .shutdown = tcp_shutdown, 1898 .setsockopt = tcp_setsockopt, 1899 .getsockopt = tcp_getsockopt, 1900 .recvmsg = tcp_recvmsg, 1901 .sendmsg = tcp_sendmsg, 1902 .sendpage = tcp_sendpage, 1903 .backlog_rcv = tcp_v6_do_rcv, 1904 .release_cb = tcp_release_cb, | 1768 break; 1769 } 1770out: 1771 return 0; 1772} 1773 1774static const struct file_operations tcp6_afinfo_seq_fops = { 1775 .owner = THIS_MODULE, --- 47 unchanged lines hidden (view full) --- 1823 .shutdown = tcp_shutdown, 1824 .setsockopt = tcp_setsockopt, 1825 .getsockopt = tcp_getsockopt, 1826 .recvmsg = tcp_recvmsg, 1827 .sendmsg = tcp_sendmsg, 1828 .sendpage = tcp_sendpage, 1829 .backlog_rcv = tcp_v6_do_rcv, 1830 .release_cb = tcp_release_cb, |
1905 .hash = tcp_v6_hash, | 1831 .hash = inet_hash, |
1906 .unhash = inet_unhash, 1907 .get_port = inet_csk_get_port, 1908 .enter_memory_pressure = tcp_enter_memory_pressure, 1909 .stream_memory_free = tcp_stream_memory_free, 1910 .sockets_allocated = &tcp_sockets_allocated, 1911 .memory_allocated = &tcp_memory_allocated, 1912 .memory_pressure = &tcp_memory_pressure, 1913 .orphan_count = &tcp_orphan_count, --- 90 unchanged lines hidden --- | 1832 .unhash = inet_unhash, 1833 .get_port = inet_csk_get_port, 1834 .enter_memory_pressure = tcp_enter_memory_pressure, 1835 .stream_memory_free = tcp_stream_memory_free, 1836 .sockets_allocated = &tcp_sockets_allocated, 1837 .memory_allocated = &tcp_memory_allocated, 1838 .memory_pressure = &tcp_memory_pressure, 1839 .orphan_count = &tcp_orphan_count, --- 90 unchanged lines hidden --- |