The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/netinet/sctp_peeloff.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
    3  * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
    4  * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions are met:
    8  *
    9  * a) Redistributions of source code must retain the above copyright notice,
   10  *    this list of conditions and the following disclaimer.
   11  *
   12  * b) Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in
   14  *    the documentation and/or other materials provided with the distribution.
   15  *
   16  * c) Neither the name of Cisco Systems, Inc. nor the names of its
   17  *    contributors may be used to endorse or promote products derived
   18  *    from this software without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
   22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
   24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
   30  * THE POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 #include <sys/cdefs.h>
   34 __FBSDID("$FreeBSD$");
   35 
   36 #include <netinet/sctp_os.h>
   37 #include <netinet/sctp_pcb.h>
   38 #include <netinet/sctputil.h>
   39 #include <netinet/sctp_var.h>
   40 #include <netinet/sctp_var.h>
   41 #include <netinet/sctp_sysctl.h>
   42 #include <netinet/sctp.h>
   43 #include <netinet/sctp_uio.h>
   44 #include <netinet/sctp_peeloff.h>
   45 #include <netinet/sctputil.h>
   46 #include <netinet/sctp_auth.h>
   47 
   48 
   49 int
   50 sctp_can_peel_off(struct socket *head, sctp_assoc_t assoc_id)
   51 {
   52         struct sctp_inpcb *inp;
   53         struct sctp_tcb *stcb;
   54         uint32_t state;
   55 
   56         if (head == NULL) {
   57                 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EBADF);
   58                 return (EBADF);
   59         }
   60         inp = (struct sctp_inpcb *)head->so_pcb;
   61         if (inp == NULL) {
   62                 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EFAULT);
   63                 return (EFAULT);
   64         }
   65         if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
   66             (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
   67                 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EOPNOTSUPP);
   68                 return (EOPNOTSUPP);
   69         }
   70         stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1);
   71         if (stcb == NULL) {
   72                 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_PEELOFF, ENOENT);
   73                 return (ENOENT);
   74         }
   75         state = SCTP_GET_STATE(stcb);
   76         if ((state == SCTP_STATE_EMPTY) ||
   77             (state == SCTP_STATE_INUSE)) {
   78                 SCTP_TCB_UNLOCK(stcb);
   79                 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_PEELOFF, ENOTCONN);
   80                 return (ENOTCONN);
   81         }
   82         SCTP_TCB_UNLOCK(stcb);
   83         /* We are clear to peel this one off */
   84         return (0);
   85 }
   86 
   87 int
   88 sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
   89 {
   90         struct sctp_inpcb *inp, *n_inp;
   91         struct sctp_tcb *stcb;
   92         uint32_t state;
   93 
   94         inp = (struct sctp_inpcb *)head->so_pcb;
   95         if (inp == NULL) {
   96                 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EFAULT);
   97                 return (EFAULT);
   98         }
   99         stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1);
  100         if (stcb == NULL) {
  101                 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, ENOTCONN);
  102                 return (ENOTCONN);
  103         }
  104 
  105         state = SCTP_GET_STATE(stcb);
  106         if ((state == SCTP_STATE_EMPTY) ||
  107             (state == SCTP_STATE_INUSE)) {
  108                 SCTP_TCB_UNLOCK(stcb);
  109                 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, ENOTCONN);
  110                 return (ENOTCONN);
  111         }
  112 
  113         n_inp = (struct sctp_inpcb *)so->so_pcb;
  114         n_inp->sctp_flags = (SCTP_PCB_FLAGS_UDPTYPE |
  115             SCTP_PCB_FLAGS_CONNECTED |
  116             SCTP_PCB_FLAGS_IN_TCPPOOL | /* Turn on Blocking IO */
  117             (SCTP_PCB_COPY_FLAGS & inp->sctp_flags));
  118         n_inp->sctp_socket = so;
  119         n_inp->sctp_features = inp->sctp_features;
  120         n_inp->sctp_mobility_features = inp->sctp_mobility_features;
  121         n_inp->sctp_frag_point = inp->sctp_frag_point;
  122         n_inp->sctp_cmt_on_off = inp->sctp_cmt_on_off;
  123         n_inp->ecn_supported = inp->ecn_supported;
  124         n_inp->prsctp_supported = inp->prsctp_supported;
  125         n_inp->auth_supported = inp->auth_supported;
  126         n_inp->asconf_supported = inp->asconf_supported;
  127         n_inp->reconfig_supported = inp->reconfig_supported;
  128         n_inp->nrsack_supported = inp->nrsack_supported;
  129         n_inp->pktdrop_supported = inp->pktdrop_supported;
  130         n_inp->partial_delivery_point = inp->partial_delivery_point;
  131         n_inp->sctp_context = inp->sctp_context;
  132         n_inp->max_cwnd = inp->max_cwnd;
  133         n_inp->local_strreset_support = inp->local_strreset_support;
  134         n_inp->inp_starting_point_for_iterator = NULL;
  135         /* copy in the authentication parameters from the original endpoint */
  136         if (n_inp->sctp_ep.local_hmacs)
  137                 sctp_free_hmaclist(n_inp->sctp_ep.local_hmacs);
  138         n_inp->sctp_ep.local_hmacs =
  139             sctp_copy_hmaclist(inp->sctp_ep.local_hmacs);
  140         if (n_inp->sctp_ep.local_auth_chunks)
  141                 sctp_free_chunklist(n_inp->sctp_ep.local_auth_chunks);
  142         n_inp->sctp_ep.local_auth_chunks =
  143             sctp_copy_chunklist(inp->sctp_ep.local_auth_chunks);
  144         (void)sctp_copy_skeylist(&inp->sctp_ep.shared_keys,
  145             &n_inp->sctp_ep.shared_keys);
  146         /*
  147          * Now we must move it from one hash table to another and get the
  148          * stcb in the right place.
  149          */
  150         sctp_move_pcb_and_assoc(inp, n_inp, stcb);
  151         atomic_add_int(&stcb->asoc.refcnt, 1);
  152         SCTP_TCB_UNLOCK(stcb);
  153 
  154         sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, SBL_WAIT);
  155         atomic_subtract_int(&stcb->asoc.refcnt, 1);
  156 
  157         return (0);
  158 }

Cache object: 1bd9ca346b6014c28f383da089ee0f1e


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.