input.c (a432c771e2d9bc059ffe3028faf040c08b6a9f98) | input.c (0c5dc070ff3d6246d22ddd931f23a6266249e3db) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* SCTP kernel implementation 3 * Copyright (c) 1999-2000 Cisco, Inc. 4 * Copyright (c) 1999-2001 Motorola, Inc. 5 * Copyright (c) 2001-2003 International Business Machines, Corp. 6 * Copyright (c) 2001 Intel Corp. 7 * Copyright (c) 2001 Nokia, Inc. 8 * Copyright (c) 2001 La Monte H.P. Yarroll --- 371 unchanged lines hidden (view full) --- 380 return ret; 381 382} 383 384/* Handle icmp frag needed error. */ 385void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc, 386 struct sctp_transport *t, __u32 pmtu) 387{ | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* SCTP kernel implementation 3 * Copyright (c) 1999-2000 Cisco, Inc. 4 * Copyright (c) 1999-2001 Motorola, Inc. 5 * Copyright (c) 2001-2003 International Business Machines, Corp. 6 * Copyright (c) 2001 Intel Corp. 7 * Copyright (c) 2001 Nokia, Inc. 8 * Copyright (c) 2001 La Monte H.P. Yarroll --- 371 unchanged lines hidden (view full) --- 380 return ret; 381 382} 383 384/* Handle icmp frag needed error. */ 385void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc, 386 struct sctp_transport *t, __u32 pmtu) 387{ |
388 if (!t || 389 (t->pathmtu <= pmtu && 390 t->pl.probe_size + sctp_transport_pl_hlen(t) <= pmtu)) | 388 if (!t || (t->pathmtu <= pmtu)) |
391 return; 392 393 if (sock_owned_by_user(sk)) { 394 atomic_set(&t->mtu_info, pmtu); 395 asoc->pmtu_pending = 1; 396 t->pmtu_pending = 1; 397 return; 398 } --- 152 unchanged lines hidden (view full) --- 551/* Common cleanup code for icmp/icmpv6 error handler. */ 552void sctp_err_finish(struct sock *sk, struct sctp_transport *t) 553 __releases(&((__sk)->sk_lock.slock)) 554{ 555 bh_unlock_sock(sk); 556 sctp_transport_put(t); 557} 558 | 389 return; 390 391 if (sock_owned_by_user(sk)) { 392 atomic_set(&t->mtu_info, pmtu); 393 asoc->pmtu_pending = 1; 394 t->pmtu_pending = 1; 395 return; 396 } --- 152 unchanged lines hidden (view full) --- 549/* Common cleanup code for icmp/icmpv6 error handler. */ 550void sctp_err_finish(struct sock *sk, struct sctp_transport *t) 551 __releases(&((__sk)->sk_lock.slock)) 552{ 553 bh_unlock_sock(sk); 554 sctp_transport_put(t); 555} 556 |
559static void sctp_v4_err_handle(struct sctp_transport *t, struct sk_buff *skb, 560 __u8 type, __u8 code, __u32 info) 561{ 562 struct sctp_association *asoc = t->asoc; 563 struct sock *sk = asoc->base.sk; 564 int err = 0; 565 566 switch (type) { 567 case ICMP_PARAMETERPROB: 568 err = EPROTO; 569 break; 570 case ICMP_DEST_UNREACH: 571 if (code > NR_ICMP_UNREACH) 572 return; 573 if (code == ICMP_FRAG_NEEDED) { 574 sctp_icmp_frag_needed(sk, asoc, t, SCTP_TRUNC4(info)); 575 return; 576 } 577 if (code == ICMP_PROT_UNREACH) { 578 sctp_icmp_proto_unreachable(sk, asoc, t); 579 return; 580 } 581 err = icmp_err_convert[code].errno; 582 break; 583 case ICMP_TIME_EXCEEDED: 584 if (code == ICMP_EXC_FRAGTIME) 585 return; 586 587 err = EHOSTUNREACH; 588 break; 589 case ICMP_REDIRECT: 590 sctp_icmp_redirect(sk, t, skb); 591 default: 592 return; 593 } 594 if (!sock_owned_by_user(sk) && inet_sk(sk)->recverr) { 595 sk->sk_err = err; 596 sk->sk_error_report(sk); 597 } else { /* Only an error on timeout */ 598 sk->sk_err_soft = err; 599 } 600} 601 | |
602/* 603 * This routine is called by the ICMP module when it gets some 604 * sort of error condition. If err < 0 then the socket should 605 * be closed and the error returned to the user. If err > 0 606 * it's just the icmp type << 8 | icmp code. After adjustment 607 * header points to the first 8 bytes of the sctp header. We need 608 * to find the appropriate port. 609 * 610 * The locking strategy used here is very "optimistic". When 611 * someone else accesses the socket the ICMP is just dropped 612 * and for some paths there is no check at all. 613 * A more general error queue to queue errors for later handling 614 * is probably better. 615 * 616 */ 617int sctp_v4_err(struct sk_buff *skb, __u32 info) 618{ 619 const struct iphdr *iph = (const struct iphdr *)skb->data; | 557/* 558 * This routine is called by the ICMP module when it gets some 559 * sort of error condition. If err < 0 then the socket should 560 * be closed and the error returned to the user. If err > 0 561 * it's just the icmp type << 8 | icmp code. After adjustment 562 * header points to the first 8 bytes of the sctp header. We need 563 * to find the appropriate port. 564 * 565 * The locking strategy used here is very "optimistic". When 566 * someone else accesses the socket the ICMP is just dropped 567 * and for some paths there is no check at all. 568 * A more general error queue to queue errors for later handling 569 * is probably better. 570 * 571 */ 572int sctp_v4_err(struct sk_buff *skb, __u32 info) 573{ 574 const struct iphdr *iph = (const struct iphdr *)skb->data; |
575 const int ihlen = iph->ihl * 4; |
|
620 const int type = icmp_hdr(skb)->type; 621 const int code = icmp_hdr(skb)->code; | 576 const int type = icmp_hdr(skb)->type; 577 const int code = icmp_hdr(skb)->code; |
622 struct net *net = dev_net(skb->dev); | 578 struct sock *sk; 579 struct sctp_association *asoc = NULL; |
623 struct sctp_transport *transport; | 580 struct sctp_transport *transport; |
624 struct sctp_association *asoc; | 581 struct inet_sock *inet; |
625 __u16 saveip, savesctp; | 582 __u16 saveip, savesctp; |
626 struct sock *sk; | 583 int err; 584 struct net *net = dev_net(skb->dev); |
627 628 /* Fix up skb to look at the embedded net header. */ 629 saveip = skb->network_header; 630 savesctp = skb->transport_header; 631 skb_reset_network_header(skb); | 585 586 /* Fix up skb to look at the embedded net header. */ 587 saveip = skb->network_header; 588 savesctp = skb->transport_header; 589 skb_reset_network_header(skb); |
632 skb_set_transport_header(skb, iph->ihl * 4); | 590 skb_set_transport_header(skb, ihlen); |
633 sk = sctp_err_lookup(net, AF_INET, skb, sctp_hdr(skb), &asoc, &transport); 634 /* Put back, the original values. */ 635 skb->network_header = saveip; 636 skb->transport_header = savesctp; 637 if (!sk) { 638 __ICMP_INC_STATS(net, ICMP_MIB_INERRORS); 639 return -ENOENT; 640 } | 591 sk = sctp_err_lookup(net, AF_INET, skb, sctp_hdr(skb), &asoc, &transport); 592 /* Put back, the original values. */ 593 skb->network_header = saveip; 594 skb->transport_header = savesctp; 595 if (!sk) { 596 __ICMP_INC_STATS(net, ICMP_MIB_INERRORS); 597 return -ENOENT; 598 } |
599 /* Warning: The sock lock is held. Remember to call 600 * sctp_err_finish! 601 */ |
|
641 | 602 |
642 sctp_v4_err_handle(transport, skb, type, code, info); 643 sctp_err_finish(sk, transport); | 603 switch (type) { 604 case ICMP_PARAMETERPROB: 605 err = EPROTO; 606 break; 607 case ICMP_DEST_UNREACH: 608 if (code > NR_ICMP_UNREACH) 609 goto out_unlock; |
644 | 610 |
645 return 0; 646} | 611 /* PMTU discovery (RFC1191) */ 612 if (ICMP_FRAG_NEEDED == code) { 613 sctp_icmp_frag_needed(sk, asoc, transport, 614 SCTP_TRUNC4(info)); 615 goto out_unlock; 616 } else { 617 if (ICMP_PROT_UNREACH == code) { 618 sctp_icmp_proto_unreachable(sk, asoc, 619 transport); 620 goto out_unlock; 621 } 622 } 623 err = icmp_err_convert[code].errno; 624 break; 625 case ICMP_TIME_EXCEEDED: 626 /* Ignore any time exceeded errors due to fragment reassembly 627 * timeouts. 628 */ 629 if (ICMP_EXC_FRAGTIME == code) 630 goto out_unlock; |
647 | 631 |
648int sctp_udp_v4_err(struct sock *sk, struct sk_buff *skb) 649{ 650 struct net *net = dev_net(skb->dev); 651 struct sctp_association *asoc; 652 struct sctp_transport *t; 653 struct icmphdr *hdr; 654 __u32 info = 0; 655 656 skb->transport_header += sizeof(struct udphdr); 657 sk = sctp_err_lookup(net, AF_INET, skb, sctp_hdr(skb), &asoc, &t); 658 if (!sk) { 659 __ICMP_INC_STATS(net, ICMP_MIB_INERRORS); 660 return -ENOENT; | 632 err = EHOSTUNREACH; 633 break; 634 case ICMP_REDIRECT: 635 sctp_icmp_redirect(sk, transport, skb); 636 /* Fall through to out_unlock. */ 637 default: 638 goto out_unlock; |
661 } 662 | 639 } 640 |
663 skb->transport_header -= sizeof(struct udphdr); 664 hdr = (struct icmphdr *)(skb_network_header(skb) - sizeof(struct icmphdr)); 665 if (hdr->type == ICMP_REDIRECT) { 666 /* can't be handled without outer iphdr known, leave it to udp_err */ 667 sctp_err_finish(sk, t); 668 return 0; | 641 inet = inet_sk(sk); 642 if (!sock_owned_by_user(sk) && inet->recverr) { 643 sk->sk_err = err; 644 sk->sk_error_report(sk); 645 } else { /* Only an error on timeout */ 646 sk->sk_err_soft = err; |
669 } | 647 } |
670 if (hdr->type == ICMP_DEST_UNREACH && hdr->code == ICMP_FRAG_NEEDED) 671 info = ntohs(hdr->un.frag.mtu); 672 sctp_v4_err_handle(t, skb, hdr->type, hdr->code, info); | |
673 | 648 |
674 sctp_err_finish(sk, t); 675 return 1; | 649out_unlock: 650 sctp_err_finish(sk, transport); 651 return 0; |
676} 677 678/* 679 * RFC 2960, 8.4 - Handle "Out of the blue" Packets. 680 * 681 * This function scans all the chunks in the OOTB packet to determine if 682 * the packet should be discarded right away. If a response might be needed 683 * for this packet, or, if further processing is possible, the packet will --- 466 unchanged lines hidden (view full) --- 1150 /* Walk the parameters looking for embedded addresses. */ 1151 sctp_walk_params(params, init, init_hdr.params) { 1152 1153 /* Note: Ignoring hostname addresses. */ 1154 af = sctp_get_af_specific(param_type2af(params.p->type)); 1155 if (!af) 1156 continue; 1157 | 652} 653 654/* 655 * RFC 2960, 8.4 - Handle "Out of the blue" Packets. 656 * 657 * This function scans all the chunks in the OOTB packet to determine if 658 * the packet should be discarded right away. If a response might be needed 659 * for this packet, or, if further processing is possible, the packet will --- 466 unchanged lines hidden (view full) --- 1126 /* Walk the parameters looking for embedded addresses. */ 1127 sctp_walk_params(params, init, init_hdr.params) { 1128 1129 /* Note: Ignoring hostname addresses. */ 1130 af = sctp_get_af_specific(param_type2af(params.p->type)); 1131 if (!af) 1132 continue; 1133 |
1158 af->from_addr_param(paddr, params.addr, sh->source, 0); | 1134 if (!af->from_addr_param(paddr, params.addr, sh->source, 0)) 1135 continue; |
1159 1160 asoc = __sctp_lookup_association(net, laddr, paddr, transportp); 1161 if (asoc) 1162 return asoc; 1163 } 1164 1165 return NULL; 1166} --- 26 unchanged lines hidden (view full) --- 1193 1194 /* Skip over the ADDIP header and find the Address parameter */ 1195 param = (union sctp_addr_param *)(asconf + 1); 1196 1197 af = sctp_get_af_specific(param_type2af(param->p.type)); 1198 if (unlikely(!af)) 1199 return NULL; 1200 | 1136 1137 asoc = __sctp_lookup_association(net, laddr, paddr, transportp); 1138 if (asoc) 1139 return asoc; 1140 } 1141 1142 return NULL; 1143} --- 26 unchanged lines hidden (view full) --- 1170 1171 /* Skip over the ADDIP header and find the Address parameter */ 1172 param = (union sctp_addr_param *)(asconf + 1); 1173 1174 af = sctp_get_af_specific(param_type2af(param->p.type)); 1175 if (unlikely(!af)) 1176 return NULL; 1177 |
1201 af->from_addr_param(&paddr, param, peer_port, 0); | 1178 if (af->from_addr_param(&paddr, param, peer_port, 0)) 1179 return NULL; |
1202 1203 return __sctp_lookup_association(net, laddr, &paddr, transportp); 1204} 1205 1206 1207/* SCTP-AUTH, Section 6.3: 1208* If the receiver does not find a STCB for a packet containing an AUTH 1209* chunk as the first chunk and not a COOKIE-ECHO chunk as the second --- 138 unchanged lines hidden --- | 1180 1181 return __sctp_lookup_association(net, laddr, &paddr, transportp); 1182} 1183 1184 1185/* SCTP-AUTH, Section 6.3: 1186* If the receiver does not find a STCB for a packet containing an AUTH 1187* chunk as the first chunk and not a COOKIE-ECHO chunk as the second --- 138 unchanged lines hidden --- |