FreeBSD kernel IPv4 code
sctp_peeloff.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
17 *
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD$");
37
38#include <netinet/sctp_os.h>
39#include <netinet/sctp_pcb.h>
40#include <netinet/sctputil.h>
41#include <netinet/sctp_var.h>
42#include <netinet/sctp_var.h>
43#include <netinet/sctp_sysctl.h>
44#include <netinet/sctp.h>
45#include <netinet/sctp_uio.h>
47#include <netinet/sctputil.h>
48#include <netinet/sctp_auth.h>
49
50int
51sctp_can_peel_off(struct socket *head, sctp_assoc_t assoc_id)
52{
53 struct sctp_inpcb *inp;
54 struct sctp_tcb *stcb;
56
57 if (head == NULL) {
58 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EBADF);
59 return (EBADF);
60 }
61 inp = (struct sctp_inpcb *)head->so_pcb;
62 if (inp == NULL) {
63 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EFAULT);
64 return (EFAULT);
65 }
66 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
67 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
68 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EOPNOTSUPP);
69 return (EOPNOTSUPP);
70 }
71 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1);
72 if (stcb == NULL) {
74 return (ENOENT);
75 }
76 state = SCTP_GET_STATE(stcb);
77 if ((state == SCTP_STATE_EMPTY) ||
79 SCTP_TCB_UNLOCK(stcb);
80 SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_PEELOFF, ENOTCONN);
81 return (ENOTCONN);
82 }
83 SCTP_TCB_UNLOCK(stcb);
84 /* We are clear to peel this one off */
85 return (0);
86}
87
88int
89sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
90{
91 struct sctp_inpcb *inp, *n_inp;
92 struct sctp_tcb *stcb;
94
95 inp = (struct sctp_inpcb *)head->so_pcb;
96 if (inp == NULL) {
98 return (EFAULT);
99 }
100 stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1);
101 if (stcb == NULL) {
102 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, ENOTCONN);
103 return (ENOTCONN);
104 }
105
106 state = SCTP_GET_STATE(stcb);
107 if ((state == SCTP_STATE_EMPTY) ||
108 (state == SCTP_STATE_INUSE)) {
109 SCTP_TCB_UNLOCK(stcb);
110 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, ENOTCONN);
111 return (ENOTCONN);
112 }
113
114 n_inp = (struct sctp_inpcb *)so->so_pcb;
117 SCTP_PCB_FLAGS_IN_TCPPOOL | /* Turn on Blocking IO */
118 (SCTP_PCB_COPY_FLAGS & inp->sctp_flags));
119 n_inp->sctp_socket = so;
120 n_inp->sctp_features = inp->sctp_features;
121 n_inp->sctp_mobility_features = inp->sctp_mobility_features;
122 n_inp->sctp_frag_point = inp->sctp_frag_point;
123 n_inp->sctp_cmt_on_off = inp->sctp_cmt_on_off;
124 n_inp->ecn_supported = inp->ecn_supported;
125 n_inp->prsctp_supported = inp->prsctp_supported;
126 n_inp->auth_supported = inp->auth_supported;
127 n_inp->asconf_supported = inp->asconf_supported;
128 n_inp->reconfig_supported = inp->reconfig_supported;
129 n_inp->nrsack_supported = inp->nrsack_supported;
130 n_inp->pktdrop_supported = inp->pktdrop_supported;
131 n_inp->partial_delivery_point = inp->partial_delivery_point;
132 n_inp->sctp_context = inp->sctp_context;
133 n_inp->max_cwnd = inp->max_cwnd;
134 n_inp->local_strreset_support = inp->local_strreset_support;
135 /* copy in the authentication parameters from the original endpoint */
136 if (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)
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}
__uint32_t uint32_t
Definition: in.h:62
u_int32_t state
Definition: ip_fw.h:10
#define SCTP_PCB_FLAGS_TCPTYPE
Definition: sctp.h:504
#define SCTP_PCB_FLAGS_UDPTYPE
Definition: sctp.h:503
#define SCTP_PCB_FLAGS_IN_TCPPOOL
Definition: sctp.h:515
#define SCTP_PCB_FLAGS_CONNECTED
Definition: sctp.h:514
#define SCTP_PCB_COPY_FLAGS
Definition: sctp.h:526
sctp_auth_chklist_t * sctp_copy_chunklist(sctp_auth_chklist_t *list)
Definition: sctp_auth.c:84
void sctp_free_chunklist(sctp_auth_chklist_t *list)
Definition: sctp_auth.c:77
void sctp_free_hmaclist(sctp_hmaclist_t *list)
Definition: sctp_auth.c:648
sctp_hmaclist_t * sctp_copy_hmaclist(sctp_hmaclist_t *list)
Definition: sctp_auth.c:684
int sctp_copy_skeylist(const struct sctp_keyhead *src, struct sctp_keyhead *dest)
Definition: sctp_auth.c:609
#define SCTP_STATE_INUSE
#define SCTP_GET_STATE(_stcb)
#define SCTP_FROM_SCTP_PEELOFF
#define SCTP_STATE_EMPTY
#define SCTP_TCB_UNLOCK(_tcb)
#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err)
Definition: sctp_os_bsd.h:191
struct sctp_tcb * sctp_findassociation_ep_asocid(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock)
Definition: sctp_pcb.c:1583
void sctp_move_pcb_and_assoc(struct sctp_inpcb *old_inp, struct sctp_inpcb *new_inp, struct sctp_tcb *stcb)
Definition: sctp_pcb.c:2610
int sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
Definition: sctp_peeloff.c:89
__FBSDID("$FreeBSD$")
int sctp_can_peel_off(struct socket *head, sctp_assoc_t assoc_id)
Definition: sctp_peeloff.c:51
uint32_t sctp_assoc_t
Definition: sctp_uio.h:48
void sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, struct sctp_inpcb *new_inp, struct sctp_tcb *stcb, int waitflags)
Definition: sctputil.c:4758
uint8_t auth_supported
Definition: sctp_pcb.h:400
struct inpcb inp
Definition: sctp_pcb.h:356
uint8_t prsctp_supported
Definition: sctp_pcb.h:399
uint32_t max_cwnd
Definition: sctp_pcb.h:395
uint32_t partial_delivery_point
Definition: sctp_pcb.h:393
uint32_t sctp_flags
Definition: sctp_pcb.h:381
uint8_t ecn_supported
Definition: sctp_pcb.h:398
uint8_t asconf_supported
Definition: sctp_pcb.h:402
struct socket * sctp_socket
Definition: sctp_pcb.h:379
uint32_t sctp_frag_point
Definition: sctp_pcb.h:392
uint8_t nrsack_supported
Definition: sctp_pcb.h:404
uint8_t reconfig_supported
Definition: sctp_pcb.h:403
uint64_t sctp_features
Definition: sctp_pcb.h:380
uint32_t sctp_mobility_features
Definition: sctp_pcb.h:382
uint32_t sctp_context
Definition: sctp_pcb.h:394
uint8_t pktdrop_supported
Definition: sctp_pcb.h:405
struct sctp_pcb sctp_ep
Definition: sctp_pcb.h:383
uint8_t local_strreset_support
Definition: sctp_pcb.h:396
uint32_t sctp_cmt_on_off
Definition: sctp_pcb.h:397
struct sctp_keyhead shared_keys
Definition: sctp_pcb.h:281
sctp_auth_chklist_t * local_auth_chunks
Definition: sctp_pcb.h:282
sctp_hmaclist_t * local_hmacs
Definition: sctp_pcb.h:283
struct sctp_association asoc
Definition: sctp_pcb.h:449