| 664 | } |
| 665 | |
| 666 | int |
| 667 | sctp_disconnect(struct socket *so) |
| 668 | { |
| 669 | struct sctp_inpcb *inp; |
| 670 | |
| 671 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 672 | if (inp == NULL) { |
| 673 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); |
| 674 | return (ENOTCONN); |
| 675 | } |
| 676 | SCTP_INP_RLOCK(inp); |
| 677 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 678 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { |
| 679 | if (LIST_EMPTY(&inp->sctp_asoc_list)) { |
| 680 | /* No connection */ |
| 681 | SCTP_INP_RUNLOCK(inp); |
| 682 | return (0); |
| 683 | } else { |
| 684 | struct epoch_tracker et; |
| 685 | struct sctp_association *asoc; |
| 686 | struct sctp_tcb *stcb; |
| 687 | |
| 688 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 689 | if (stcb == NULL) { |
| 690 | SCTP_INP_RUNLOCK(inp); |
| 691 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 692 | return (EINVAL); |
| 693 | } |
| 694 | SCTP_TCB_LOCK(stcb); |
| 695 | asoc = &stcb->asoc; |
| 696 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
| 697 | /* We are about to be freed, out of here */ |
| 698 | SCTP_TCB_UNLOCK(stcb); |
| 699 | SCTP_INP_RUNLOCK(inp); |
| 700 | return (0); |
| 701 | } |
| 702 | NET_EPOCH_ENTER(et); |
| 703 | if (((so->so_options & SO_LINGER) && |
| 704 | (so->so_linger == 0)) || |
| 705 | (so->so_rcv.sb_cc > 0)) { |
| 706 | if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) { |
| 707 | /* Left with Data unread */ |
| 708 | struct mbuf *op_err; |
| 709 | |
| 710 | op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, ""); |
| 711 | sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED); |
| 712 | SCTP_STAT_INCR_COUNTER32(sctps_aborted); |
| 713 | } |
| 714 | SCTP_INP_RUNLOCK(inp); |
| 715 | if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || |
| 716 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) { |
| 717 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
| 718 | } |
| 719 | (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, |
| 720 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3); |
| 721 | /* No unlock tcb assoc is gone */ |
| 722 | NET_EPOCH_EXIT(et); |
| 723 | return (0); |
no test coverage detected