| 512 | |
| 513 | #endif |
| 514 | void |
| 515 | sctp_close(struct socket *so) |
| 516 | { |
| 517 | struct epoch_tracker et; |
| 518 | struct sctp_inpcb *inp; |
| 519 | uint32_t flags; |
| 520 | |
| 521 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 522 | if (inp == NULL) |
| 523 | return; |
| 524 | |
| 525 | /* |
| 526 | * Inform all the lower layer assoc that we are done. |
| 527 | */ |
| 528 | NET_EPOCH_ENTER(et); |
| 529 | sctp_must_try_again: |
| 530 | flags = inp->sctp_flags; |
| 531 | #ifdef SCTP_LOG_CLOSING |
| 532 | sctp_log_closing(inp, NULL, 17); |
| 533 | #endif |
| 534 | if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && |
| 535 | (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) { |
| 536 | if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || |
| 537 | (so->so_rcv.sb_cc > 0)) { |
| 538 | #ifdef SCTP_LOG_CLOSING |
| 539 | sctp_log_closing(inp, NULL, 13); |
| 540 | #endif |
| 541 | sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT, |
| 542 | SCTP_CALLED_AFTER_CMPSET_OFCLOSE); |
| 543 | } else { |
| 544 | #ifdef SCTP_LOG_CLOSING |
| 545 | sctp_log_closing(inp, NULL, 14); |
| 546 | #endif |
| 547 | sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE, |
| 548 | SCTP_CALLED_AFTER_CMPSET_OFCLOSE); |
| 549 | } |
| 550 | /* |
| 551 | * The socket is now detached, no matter what the state of |
| 552 | * the SCTP association. |
| 553 | */ |
| 554 | SOCK_LOCK(so); |
| 555 | SCTP_SB_CLEAR(so->so_snd); |
| 556 | /* |
| 557 | * same for the rcv ones, they are only here for the |
| 558 | * accounting/select. |
| 559 | */ |
| 560 | SCTP_SB_CLEAR(so->so_rcv); |
| 561 | |
| 562 | /* Now null out the reference, we are completely detached. */ |
| 563 | so->so_pcb = NULL; |
| 564 | SOCK_UNLOCK(so); |
| 565 | } else { |
| 566 | flags = inp->sctp_flags; |
| 567 | if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { |
| 568 | goto sctp_must_try_again; |
| 569 | } |
| 570 | } |
| 571 | NET_EPOCH_EXIT(et); |
no test coverage detected