sctp_input.c revision 1.7.4.2 1 1.7.4.2 jdolecek /* $KAME: sctp_input.c,v 1.28 2005/04/21 18:36:21 nishida Exp $ */
2 1.7.4.2 jdolecek /* $NetBSD: sctp_input.c,v 1.7.4.2 2017/12/03 11:39:04 jdolecek Exp $ */
3 1.7.4.2 jdolecek
4 1.7.4.2 jdolecek /*
5 1.7.4.2 jdolecek * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc,
6 1.7.4.2 jdolecek * All rights reserved.
7 1.7.4.2 jdolecek *
8 1.7.4.2 jdolecek * Redistribution and use in source and binary forms, with or without
9 1.7.4.2 jdolecek * modification, are permitted provided that the following conditions
10 1.7.4.2 jdolecek * are met:
11 1.7.4.2 jdolecek * 1. Redistributions of source code must retain the above copyright
12 1.7.4.2 jdolecek * notice, this list of conditions and the following disclaimer.
13 1.7.4.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
14 1.7.4.2 jdolecek * notice, this list of conditions and the following disclaimer in the
15 1.7.4.2 jdolecek * documentation and/or other materials provided with the distribution.
16 1.7.4.2 jdolecek * 3. Neither the name of the project nor the names of its contributors
17 1.7.4.2 jdolecek * may be used to endorse or promote products derived from this software
18 1.7.4.2 jdolecek * without specific prior written permission.
19 1.7.4.2 jdolecek *
20 1.7.4.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 1.7.4.2 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.7.4.2 jdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.7.4.2 jdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 1.7.4.2 jdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.7.4.2 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.7.4.2 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.7.4.2 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.7.4.2 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.7.4.2 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.7.4.2 jdolecek * SUCH DAMAGE.
31 1.7.4.2 jdolecek */
32 1.7.4.2 jdolecek
33 1.7.4.2 jdolecek #include <sys/cdefs.h>
34 1.7.4.2 jdolecek __KERNEL_RCSID(0, "$NetBSD: sctp_input.c,v 1.7.4.2 2017/12/03 11:39:04 jdolecek Exp $");
35 1.7.4.2 jdolecek
36 1.7.4.2 jdolecek #ifdef _KERNEL_OPT
37 1.7.4.2 jdolecek #include "opt_ipsec.h"
38 1.7.4.2 jdolecek #include "opt_inet.h"
39 1.7.4.2 jdolecek #include "opt_sctp.h"
40 1.7.4.2 jdolecek #endif /* _KERNEL_OPT */
41 1.7.4.2 jdolecek
42 1.7.4.2 jdolecek #include <sys/param.h>
43 1.7.4.2 jdolecek #include <sys/systm.h>
44 1.7.4.2 jdolecek #include <sys/malloc.h>
45 1.7.4.2 jdolecek #include <sys/mbuf.h>
46 1.7.4.2 jdolecek #include <sys/socket.h>
47 1.7.4.2 jdolecek #include <sys/socketvar.h>
48 1.7.4.2 jdolecek #include <sys/sysctl.h>
49 1.7.4.2 jdolecek #include <sys/domain.h>
50 1.7.4.2 jdolecek #include <sys/protosw.h>
51 1.7.4.2 jdolecek #include <sys/kernel.h>
52 1.7.4.2 jdolecek #include <sys/errno.h>
53 1.7.4.2 jdolecek #include <sys/syslog.h>
54 1.7.4.2 jdolecek
55 1.7.4.2 jdolecek #include <machine/limits.h>
56 1.7.4.2 jdolecek #include <machine/cpu.h>
57 1.7.4.2 jdolecek
58 1.7.4.2 jdolecek #include <net/if.h>
59 1.7.4.2 jdolecek #include <net/route.h>
60 1.7.4.2 jdolecek #include <net/if_types.h>
61 1.7.4.2 jdolecek
62 1.7.4.2 jdolecek #include <netinet/in.h>
63 1.7.4.2 jdolecek #include <netinet/in_systm.h>
64 1.7.4.2 jdolecek #include <netinet/ip.h>
65 1.7.4.2 jdolecek #include <netinet/in_pcb.h>
66 1.7.4.2 jdolecek #include <netinet/in_var.h>
67 1.7.4.2 jdolecek #include <netinet/ip_var.h>
68 1.7.4.2 jdolecek
69 1.7.4.2 jdolecek #ifdef INET6
70 1.7.4.2 jdolecek #include <netinet/ip6.h>
71 1.7.4.2 jdolecek #include <netinet6/ip6_var.h>
72 1.7.4.2 jdolecek #endif /* INET6 */
73 1.7.4.2 jdolecek
74 1.7.4.2 jdolecek #include <netinet/ip_icmp.h>
75 1.7.4.2 jdolecek #include <netinet/icmp_var.h>
76 1.7.4.2 jdolecek #include <netinet/sctp_var.h>
77 1.7.4.2 jdolecek #include <netinet/sctp_pcb.h>
78 1.7.4.2 jdolecek #include <netinet/sctp_header.h>
79 1.7.4.2 jdolecek #include <netinet/sctputil.h>
80 1.7.4.2 jdolecek #include <netinet/sctp_output.h>
81 1.7.4.2 jdolecek #include <netinet/sctp_input.h>
82 1.7.4.2 jdolecek #include <netinet/sctp_hashdriver.h>
83 1.7.4.2 jdolecek #include <netinet/sctp_indata.h>
84 1.7.4.2 jdolecek #include <netinet/sctp_asconf.h>
85 1.7.4.2 jdolecek
86 1.7.4.2 jdolecek #ifdef IPSEC
87 1.7.4.2 jdolecek #include <netipsec/ipsec.h>
88 1.7.4.2 jdolecek #include <netipsec/key.h>
89 1.7.4.2 jdolecek #endif /*IPSEC*/
90 1.7.4.2 jdolecek
91 1.7.4.2 jdolecek #include <net/net_osdep.h>
92 1.7.4.2 jdolecek
93 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
94 1.7.4.2 jdolecek extern u_int32_t sctp_debug_on;
95 1.7.4.2 jdolecek #endif
96 1.7.4.2 jdolecek
97 1.7.4.2 jdolecek /* INIT handler */
98 1.7.4.2 jdolecek static void
99 1.7.4.2 jdolecek sctp_handle_init(struct mbuf *m, int iphlen, int offset,
100 1.7.4.2 jdolecek struct sctphdr *sh, struct sctp_init_chunk *cp, struct sctp_inpcb *inp,
101 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net)
102 1.7.4.2 jdolecek {
103 1.7.4.2 jdolecek struct sctp_init *init;
104 1.7.4.2 jdolecek struct mbuf *op_err;
105 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
106 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
107 1.7.4.2 jdolecek printf("sctp_handle_init: handling INIT tcb:%p\n", stcb);
108 1.7.4.2 jdolecek }
109 1.7.4.2 jdolecek #endif
110 1.7.4.2 jdolecek op_err = NULL;
111 1.7.4.2 jdolecek init = &cp->init;
112 1.7.4.2 jdolecek /* First are we accepting? */
113 1.7.4.2 jdolecek if (((inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) == 0) ||
114 1.7.4.2 jdolecek (inp->sctp_socket->so_qlimit == 0)) {
115 1.7.4.2 jdolecek sctp_abort_association(inp, stcb, m, iphlen, sh, op_err);
116 1.7.4.2 jdolecek return;
117 1.7.4.2 jdolecek }
118 1.7.4.2 jdolecek if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_init_chunk)) {
119 1.7.4.2 jdolecek /* Invalid length */
120 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
121 1.7.4.2 jdolecek sctp_abort_association(inp, stcb, m, iphlen, sh, op_err);
122 1.7.4.2 jdolecek return;
123 1.7.4.2 jdolecek }
124 1.7.4.2 jdolecek /* validate parameters */
125 1.7.4.2 jdolecek if (init->initiate_tag == 0) {
126 1.7.4.2 jdolecek /* protocol error... send abort */
127 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
128 1.7.4.2 jdolecek sctp_abort_association(inp, stcb, m, iphlen, sh, op_err);
129 1.7.4.2 jdolecek return;
130 1.7.4.2 jdolecek }
131 1.7.4.2 jdolecek if (ntohl(init->a_rwnd) < SCTP_MIN_RWND) {
132 1.7.4.2 jdolecek /* invalid parameter... send abort */
133 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
134 1.7.4.2 jdolecek sctp_abort_association(inp, stcb, m, iphlen, sh, op_err);
135 1.7.4.2 jdolecek return;
136 1.7.4.2 jdolecek }
137 1.7.4.2 jdolecek if (init->num_inbound_streams == 0) {
138 1.7.4.2 jdolecek /* protocol error... send abort */
139 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
140 1.7.4.2 jdolecek sctp_abort_association(inp, stcb, m, iphlen, sh, op_err);
141 1.7.4.2 jdolecek return;
142 1.7.4.2 jdolecek }
143 1.7.4.2 jdolecek if (init->num_outbound_streams == 0) {
144 1.7.4.2 jdolecek /* protocol error... send abort */
145 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
146 1.7.4.2 jdolecek sctp_abort_association(inp, stcb, m, iphlen, sh, op_err);
147 1.7.4.2 jdolecek return;
148 1.7.4.2 jdolecek }
149 1.7.4.2 jdolecek
150 1.7.4.2 jdolecek /* send an INIT-ACK w/cookie */
151 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
152 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
153 1.7.4.2 jdolecek printf("sctp_handle_init: sending INIT-ACK\n");
154 1.7.4.2 jdolecek }
155 1.7.4.2 jdolecek #endif
156 1.7.4.2 jdolecek
157 1.7.4.2 jdolecek sctp_send_initiate_ack(inp, stcb, m, iphlen, offset, sh, cp);
158 1.7.4.2 jdolecek }
159 1.7.4.2 jdolecek
160 1.7.4.2 jdolecek /*
161 1.7.4.2 jdolecek * process peer "INIT/INIT-ACK" chunk
162 1.7.4.2 jdolecek * returns value < 0 on error
163 1.7.4.2 jdolecek */
164 1.7.4.2 jdolecek
165 1.7.4.2 jdolecek static int
166 1.7.4.2 jdolecek sctp_process_init(struct sctp_init_chunk *cp, struct sctp_tcb *stcb,
167 1.7.4.2 jdolecek struct sctp_nets *net)
168 1.7.4.2 jdolecek {
169 1.7.4.2 jdolecek struct sctp_init *init;
170 1.7.4.2 jdolecek struct sctp_association *asoc;
171 1.7.4.2 jdolecek struct sctp_nets *lnet;
172 1.7.4.2 jdolecek unsigned int i;
173 1.7.4.2 jdolecek
174 1.7.4.2 jdolecek init = &cp->init;
175 1.7.4.2 jdolecek asoc = &stcb->asoc;
176 1.7.4.2 jdolecek /* save off parameters */
177 1.7.4.2 jdolecek asoc->peer_vtag = ntohl(init->initiate_tag);
178 1.7.4.2 jdolecek asoc->peers_rwnd = ntohl(init->a_rwnd);
179 1.7.4.2 jdolecek
180 1.7.4.2 jdolecek if (TAILQ_FIRST(&asoc->nets)) {
181 1.7.4.2 jdolecek /* update any ssthresh's that may have a default */
182 1.7.4.2 jdolecek TAILQ_FOREACH(lnet, &asoc->nets, sctp_next) {
183 1.7.4.2 jdolecek lnet->ssthresh = asoc->peers_rwnd;
184 1.7.4.2 jdolecek }
185 1.7.4.2 jdolecek }
186 1.7.4.2 jdolecek if (asoc->pre_open_streams > ntohs(init->num_inbound_streams)) {
187 1.7.4.2 jdolecek unsigned int newcnt;
188 1.7.4.2 jdolecek struct sctp_stream_out *outs;
189 1.7.4.2 jdolecek struct sctp_tmit_chunk *chk;
190 1.7.4.2 jdolecek
191 1.7.4.2 jdolecek /* cut back on number of streams */
192 1.7.4.2 jdolecek newcnt = ntohs(init->num_inbound_streams);
193 1.7.4.2 jdolecek /* This if is probably not needed but I am cautious */
194 1.7.4.2 jdolecek if (asoc->strmout) {
195 1.7.4.2 jdolecek /* First make sure no data chunks are trapped */
196 1.7.4.2 jdolecek for (i=newcnt; i < asoc->pre_open_streams; i++) {
197 1.7.4.2 jdolecek outs = &asoc->strmout[i];
198 1.7.4.2 jdolecek chk = TAILQ_FIRST(&outs->outqueue);
199 1.7.4.2 jdolecek while (chk) {
200 1.7.4.2 jdolecek TAILQ_REMOVE(&outs->outqueue, chk,
201 1.7.4.2 jdolecek sctp_next);
202 1.7.4.2 jdolecek asoc->stream_queue_cnt--;
203 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_DG_FAIL,
204 1.7.4.2 jdolecek stcb, SCTP_NOTIFY_DATAGRAM_UNSENT,
205 1.7.4.2 jdolecek chk);
206 1.7.4.2 jdolecek if (chk->data) {
207 1.7.4.2 jdolecek sctp_m_freem(chk->data);
208 1.7.4.2 jdolecek chk->data = NULL;
209 1.7.4.2 jdolecek }
210 1.7.4.2 jdolecek sctp_free_remote_addr(chk->whoTo);
211 1.7.4.2 jdolecek chk->whoTo = NULL;
212 1.7.4.2 jdolecek chk->asoc = NULL;
213 1.7.4.2 jdolecek /* Free the chunk */
214 1.7.4.2 jdolecek SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
215 1.7.4.2 jdolecek sctppcbinfo.ipi_count_chunk--;
216 1.7.4.2 jdolecek if ((int)sctppcbinfo.ipi_count_chunk < 0) {
217 1.7.4.2 jdolecek panic("Chunk count is negative");
218 1.7.4.2 jdolecek }
219 1.7.4.2 jdolecek sctppcbinfo.ipi_gencnt_chunk++;
220 1.7.4.2 jdolecek chk = TAILQ_FIRST(&outs->outqueue);
221 1.7.4.2 jdolecek }
222 1.7.4.2 jdolecek }
223 1.7.4.2 jdolecek }
224 1.7.4.2 jdolecek /* cut back the count and abandon the upper streams */
225 1.7.4.2 jdolecek asoc->pre_open_streams = newcnt;
226 1.7.4.2 jdolecek }
227 1.7.4.2 jdolecek asoc->streamincnt = ntohs(init->num_outbound_streams);
228 1.7.4.2 jdolecek if (asoc->streamincnt > MAX_SCTP_STREAMS) {
229 1.7.4.2 jdolecek asoc->streamincnt = MAX_SCTP_STREAMS;
230 1.7.4.2 jdolecek }
231 1.7.4.2 jdolecek
232 1.7.4.2 jdolecek asoc->streamoutcnt = asoc->pre_open_streams;
233 1.7.4.2 jdolecek /* init tsn's */
234 1.7.4.2 jdolecek asoc->highest_tsn_inside_map = asoc->asconf_seq_in = ntohl(init->initial_tsn) - 1;
235 1.7.4.2 jdolecek #ifdef SCTP_MAP_LOGGING
236 1.7.4.2 jdolecek sctp_log_map(0, 5, asoc->highest_tsn_inside_map, SCTP_MAP_SLIDE_RESULT);
237 1.7.4.2 jdolecek #endif
238 1.7.4.2 jdolecek /* This is the next one we expect */
239 1.7.4.2 jdolecek asoc->str_reset_seq_in = asoc->asconf_seq_in + 1;
240 1.7.4.2 jdolecek
241 1.7.4.2 jdolecek asoc->mapping_array_base_tsn = ntohl(init->initial_tsn);
242 1.7.4.2 jdolecek asoc->cumulative_tsn = asoc->asconf_seq_in;
243 1.7.4.2 jdolecek asoc->last_echo_tsn = asoc->asconf_seq_in;
244 1.7.4.2 jdolecek asoc->advanced_peer_ack_point = asoc->last_acked_seq;
245 1.7.4.2 jdolecek /* open the requested streams */
246 1.7.4.2 jdolecek if (asoc->strmin != NULL) {
247 1.7.4.2 jdolecek /* Free the old ones */
248 1.7.4.2 jdolecek free(asoc->strmin, M_PCB);
249 1.7.4.2 jdolecek }
250 1.7.4.2 jdolecek asoc->strmin = malloc(asoc->streamincnt * sizeof(struct sctp_stream_in),
251 1.7.4.2 jdolecek M_PCB, M_NOWAIT);
252 1.7.4.2 jdolecek if (asoc->strmin == NULL) {
253 1.7.4.2 jdolecek /* we didn't get memory for the streams! */
254 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
255 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
256 1.7.4.2 jdolecek printf("process_init: couldn't get memory for the streams!\n");
257 1.7.4.2 jdolecek }
258 1.7.4.2 jdolecek #endif
259 1.7.4.2 jdolecek return (-1);
260 1.7.4.2 jdolecek }
261 1.7.4.2 jdolecek for (i = 0; i < asoc->streamincnt; i++) {
262 1.7.4.2 jdolecek asoc->strmin[i].stream_no = i;
263 1.7.4.2 jdolecek asoc->strmin[i].last_sequence_delivered = 0xffff;
264 1.7.4.2 jdolecek /*
265 1.7.4.2 jdolecek * U-stream ranges will be set when the cookie
266 1.7.4.2 jdolecek * is unpacked. Or for the INIT sender they
267 1.7.4.2 jdolecek * are un set (if pr-sctp not supported) when the
268 1.7.4.2 jdolecek * INIT-ACK arrives.
269 1.7.4.2 jdolecek */
270 1.7.4.2 jdolecek TAILQ_INIT(&asoc->strmin[i].inqueue);
271 1.7.4.2 jdolecek /*
272 1.7.4.2 jdolecek * we are not on any wheel, pr-sctp streams
273 1.7.4.2 jdolecek * will go on the wheel when they have data waiting
274 1.7.4.2 jdolecek * for reorder.
275 1.7.4.2 jdolecek */
276 1.7.4.2 jdolecek asoc->strmin[i].next_spoke.tqe_next = 0;
277 1.7.4.2 jdolecek asoc->strmin[i].next_spoke.tqe_prev = 0;
278 1.7.4.2 jdolecek }
279 1.7.4.2 jdolecek
280 1.7.4.2 jdolecek /*
281 1.7.4.2 jdolecek * load_address_from_init will put the addresses into the
282 1.7.4.2 jdolecek * association when the COOKIE is processed or the INIT-ACK
283 1.7.4.2 jdolecek * is processed. Both types of COOKIE's existing and new
284 1.7.4.2 jdolecek * call this routine. It will remove addresses that
285 1.7.4.2 jdolecek * are no longer in the association (for the restarting
286 1.7.4.2 jdolecek * case where addresses are removed). Up front when the
287 1.7.4.2 jdolecek * INIT arrives we will discard it if it is a restart
288 1.7.4.2 jdolecek * and new addresses have been added.
289 1.7.4.2 jdolecek */
290 1.7.4.2 jdolecek return (0);
291 1.7.4.2 jdolecek }
292 1.7.4.2 jdolecek
293 1.7.4.2 jdolecek /*
294 1.7.4.2 jdolecek * INIT-ACK message processing/consumption
295 1.7.4.2 jdolecek * returns value < 0 on error
296 1.7.4.2 jdolecek */
297 1.7.4.2 jdolecek static int
298 1.7.4.2 jdolecek sctp_process_init_ack(struct mbuf *m, int iphlen, int offset,
299 1.7.4.2 jdolecek struct sctphdr *sh, struct sctp_init_ack_chunk *cp, struct sctp_tcb *stcb,
300 1.7.4.2 jdolecek struct sctp_nets *net)
301 1.7.4.2 jdolecek {
302 1.7.4.2 jdolecek struct sctp_association *asoc;
303 1.7.4.2 jdolecek struct mbuf *op_err;
304 1.7.4.2 jdolecek int retval, abort_flag;
305 1.7.4.2 jdolecek uint32_t initack_limit;
306 1.7.4.2 jdolecek /* First verify that we have no illegal param's */
307 1.7.4.2 jdolecek abort_flag = 0;
308 1.7.4.2 jdolecek op_err = NULL;
309 1.7.4.2 jdolecek
310 1.7.4.2 jdolecek op_err = sctp_arethere_unrecognized_parameters(m,
311 1.7.4.2 jdolecek (offset+sizeof(struct sctp_init_chunk)) ,
312 1.7.4.2 jdolecek &abort_flag, (struct sctp_chunkhdr *)cp);
313 1.7.4.2 jdolecek if (abort_flag) {
314 1.7.4.2 jdolecek /* Send an abort and notify peer */
315 1.7.4.2 jdolecek if (op_err != NULL) {
316 1.7.4.2 jdolecek sctp_send_operr_to(m, iphlen, op_err, cp->init.initiate_tag);
317 1.7.4.2 jdolecek } else {
318 1.7.4.2 jdolecek /*
319 1.7.4.2 jdolecek * Just notify (abort_assoc does this if
320 1.7.4.2 jdolecek * we send an abort).
321 1.7.4.2 jdolecek */
322 1.7.4.2 jdolecek sctp_abort_notification(stcb, 0);
323 1.7.4.2 jdolecek /*
324 1.7.4.2 jdolecek * No sense in further INIT's since
325 1.7.4.2 jdolecek * we will get the same param back
326 1.7.4.2 jdolecek */
327 1.7.4.2 jdolecek sctp_free_assoc(stcb->sctp_ep, stcb);
328 1.7.4.2 jdolecek }
329 1.7.4.2 jdolecek return (-1);
330 1.7.4.2 jdolecek }
331 1.7.4.2 jdolecek asoc = &stcb->asoc;
332 1.7.4.2 jdolecek /* process the peer's parameters in the INIT-ACK */
333 1.7.4.2 jdolecek retval = sctp_process_init((struct sctp_init_chunk *)cp, stcb, net);
334 1.7.4.2 jdolecek if (retval < 0) {
335 1.7.4.2 jdolecek return (retval);
336 1.7.4.2 jdolecek }
337 1.7.4.2 jdolecek
338 1.7.4.2 jdolecek initack_limit = offset + ntohs(cp->ch.chunk_length);
339 1.7.4.2 jdolecek /* load all addresses */
340 1.7.4.2 jdolecek if (sctp_load_addresses_from_init(stcb, m, iphlen,
341 1.7.4.2 jdolecek (offset + sizeof(struct sctp_init_chunk)), initack_limit, sh,
342 1.7.4.2 jdolecek NULL)) {
343 1.7.4.2 jdolecek /* Huh, we should abort */
344 1.7.4.2 jdolecek sctp_abort_notification(stcb, 0);
345 1.7.4.2 jdolecek sctp_free_assoc(stcb->sctp_ep, stcb);
346 1.7.4.2 jdolecek return (-1);
347 1.7.4.2 jdolecek }
348 1.7.4.2 jdolecek if (op_err) {
349 1.7.4.2 jdolecek sctp_queue_op_err(stcb, op_err);
350 1.7.4.2 jdolecek /* queuing will steal away the mbuf chain to the out queue */
351 1.7.4.2 jdolecek op_err = NULL;
352 1.7.4.2 jdolecek }
353 1.7.4.2 jdolecek /* extract the cookie and queue it to "echo" it back... */
354 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
355 1.7.4.2 jdolecek net->error_count = 0;
356 1.7.4.2 jdolecek retval = sctp_send_cookie_echo(m, offset, stcb, net);
357 1.7.4.2 jdolecek if (retval < 0) {
358 1.7.4.2 jdolecek /*
359 1.7.4.2 jdolecek * No cookie, we probably should send a op error.
360 1.7.4.2 jdolecek * But in any case if there is no cookie in the INIT-ACK,
361 1.7.4.2 jdolecek * we can abandon the peer, its broke.
362 1.7.4.2 jdolecek */
363 1.7.4.2 jdolecek if (retval == -3) {
364 1.7.4.2 jdolecek /* We abort with an error of missing mandatory param */
365 1.7.4.2 jdolecek op_err =
366 1.7.4.2 jdolecek sctp_generate_invmanparam(SCTP_CAUSE_MISS_PARAM);
367 1.7.4.2 jdolecek if (op_err) {
368 1.7.4.2 jdolecek /*
369 1.7.4.2 jdolecek * Expand beyond to include the mandatory
370 1.7.4.2 jdolecek * param cookie
371 1.7.4.2 jdolecek */
372 1.7.4.2 jdolecek struct sctp_inv_mandatory_param *mp;
373 1.7.4.2 jdolecek op_err->m_len =
374 1.7.4.2 jdolecek sizeof(struct sctp_inv_mandatory_param);
375 1.7.4.2 jdolecek mp = mtod(op_err,
376 1.7.4.2 jdolecek struct sctp_inv_mandatory_param *);
377 1.7.4.2 jdolecek /* Subtract the reserved param */
378 1.7.4.2 jdolecek mp->length =
379 1.7.4.2 jdolecek htons(sizeof(struct sctp_inv_mandatory_param) - 2);
380 1.7.4.2 jdolecek mp->num_param = htonl(1);
381 1.7.4.2 jdolecek mp->param = htons(SCTP_STATE_COOKIE);
382 1.7.4.2 jdolecek mp->resv = 0;
383 1.7.4.2 jdolecek }
384 1.7.4.2 jdolecek sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
385 1.7.4.2 jdolecek sh, op_err);
386 1.7.4.2 jdolecek }
387 1.7.4.2 jdolecek return (retval);
388 1.7.4.2 jdolecek }
389 1.7.4.2 jdolecek
390 1.7.4.2 jdolecek /*
391 1.7.4.2 jdolecek * Cancel the INIT timer, We do this first before queueing
392 1.7.4.2 jdolecek * the cookie. We always cancel at the primary to assue that
393 1.7.4.2 jdolecek * we are canceling the timer started by the INIT which always
394 1.7.4.2 jdolecek * goes to the primary.
395 1.7.4.2 jdolecek */
396 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_INIT, stcb->sctp_ep, stcb,
397 1.7.4.2 jdolecek asoc->primary_destination);
398 1.7.4.2 jdolecek
399 1.7.4.2 jdolecek /* calculate the RTO */
400 1.7.4.2 jdolecek net->RTO = sctp_calculate_rto(stcb, asoc, net, &asoc->time_entered);
401 1.7.4.2 jdolecek
402 1.7.4.2 jdolecek return (0);
403 1.7.4.2 jdolecek }
404 1.7.4.2 jdolecek
405 1.7.4.2 jdolecek static void
406 1.7.4.2 jdolecek sctp_handle_heartbeat_ack(struct sctp_heartbeat_chunk *cp,
407 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net)
408 1.7.4.2 jdolecek {
409 1.7.4.2 jdolecek struct sockaddr_storage store;
410 1.7.4.2 jdolecek struct sockaddr_in *sin;
411 1.7.4.2 jdolecek struct sockaddr_in6 *sin6;
412 1.7.4.2 jdolecek struct sctp_nets *r_net;
413 1.7.4.2 jdolecek struct timeval tv;
414 1.7.4.2 jdolecek
415 1.7.4.2 jdolecek if (ntohs(cp->ch.chunk_length) != sizeof(struct sctp_heartbeat_chunk)) {
416 1.7.4.2 jdolecek /* Invalid length */
417 1.7.4.2 jdolecek return;
418 1.7.4.2 jdolecek }
419 1.7.4.2 jdolecek
420 1.7.4.2 jdolecek sin = (struct sockaddr_in *)&store;
421 1.7.4.2 jdolecek sin6 = (struct sockaddr_in6 *)&store;
422 1.7.4.2 jdolecek
423 1.7.4.2 jdolecek memset(&store, 0, sizeof(store));
424 1.7.4.2 jdolecek if (cp->heartbeat.hb_info.addr_family == AF_INET &&
425 1.7.4.2 jdolecek cp->heartbeat.hb_info.addr_len == sizeof(struct sockaddr_in)) {
426 1.7.4.2 jdolecek sin->sin_family = cp->heartbeat.hb_info.addr_family;
427 1.7.4.2 jdolecek sin->sin_len = cp->heartbeat.hb_info.addr_len;
428 1.7.4.2 jdolecek sin->sin_port = stcb->rport;
429 1.7.4.2 jdolecek memcpy(&sin->sin_addr, cp->heartbeat.hb_info.address,
430 1.7.4.2 jdolecek sizeof(sin->sin_addr));
431 1.7.4.2 jdolecek } else if (cp->heartbeat.hb_info.addr_family == AF_INET6 &&
432 1.7.4.2 jdolecek cp->heartbeat.hb_info.addr_len == sizeof(struct sockaddr_in6)) {
433 1.7.4.2 jdolecek sin6->sin6_family = cp->heartbeat.hb_info.addr_family;
434 1.7.4.2 jdolecek sin6->sin6_len = cp->heartbeat.hb_info.addr_len;
435 1.7.4.2 jdolecek sin6->sin6_port = stcb->rport;
436 1.7.4.2 jdolecek memcpy(&sin6->sin6_addr, cp->heartbeat.hb_info.address,
437 1.7.4.2 jdolecek sizeof(sin6->sin6_addr));
438 1.7.4.2 jdolecek } else {
439 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
440 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
441 1.7.4.2 jdolecek printf("unsupported address family");
442 1.7.4.2 jdolecek }
443 1.7.4.2 jdolecek #endif
444 1.7.4.2 jdolecek return;
445 1.7.4.2 jdolecek }
446 1.7.4.2 jdolecek r_net = sctp_findnet(stcb, (struct sockaddr *)sin);
447 1.7.4.2 jdolecek if (r_net == NULL) {
448 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
449 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
450 1.7.4.2 jdolecek printf("Huh? I can't find the address I sent it to, discard\n");
451 1.7.4.2 jdolecek }
452 1.7.4.2 jdolecek #endif
453 1.7.4.2 jdolecek return;
454 1.7.4.2 jdolecek }
455 1.7.4.2 jdolecek if ((r_net && (r_net->dest_state & SCTP_ADDR_UNCONFIRMED)) &&
456 1.7.4.2 jdolecek (r_net->heartbeat_random1 == cp->heartbeat.hb_info.random_value1) &&
457 1.7.4.2 jdolecek (r_net->heartbeat_random2 == cp->heartbeat.hb_info.random_value2)) {
458 1.7.4.2 jdolecek /*
459 1.7.4.2 jdolecek * If the its a HB and it's random value is correct when
460 1.7.4.2 jdolecek * can confirm the destination.
461 1.7.4.2 jdolecek */
462 1.7.4.2 jdolecek r_net->dest_state &= ~SCTP_ADDR_UNCONFIRMED;
463 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_CONFIRMED,
464 1.7.4.2 jdolecek stcb, 0, (void *)r_net);
465 1.7.4.2 jdolecek }
466 1.7.4.2 jdolecek r_net->error_count = 0;
467 1.7.4.2 jdolecek r_net->hb_responded = 1;
468 1.7.4.2 jdolecek tv.tv_sec = cp->heartbeat.hb_info.time_value_1;
469 1.7.4.2 jdolecek tv.tv_usec = cp->heartbeat.hb_info.time_value_2;
470 1.7.4.2 jdolecek if (r_net->dest_state & SCTP_ADDR_NOT_REACHABLE) {
471 1.7.4.2 jdolecek r_net->dest_state = SCTP_ADDR_REACHABLE;
472 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb,
473 1.7.4.2 jdolecek SCTP_HEARTBEAT_SUCCESS, (void *)r_net);
474 1.7.4.2 jdolecek
475 1.7.4.2 jdolecek /* now was it the primary? if so restore */
476 1.7.4.2 jdolecek if (r_net->dest_state & SCTP_ADDR_WAS_PRIMARY) {
477 1.7.4.2 jdolecek sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, r_net);
478 1.7.4.2 jdolecek }
479 1.7.4.2 jdolecek }
480 1.7.4.2 jdolecek /* Now lets do a RTO with this */
481 1.7.4.2 jdolecek r_net->RTO = sctp_calculate_rto(stcb, &stcb->asoc, r_net, &tv);
482 1.7.4.2 jdolecek }
483 1.7.4.2 jdolecek
484 1.7.4.2 jdolecek static void
485 1.7.4.2 jdolecek sctp_handle_abort(struct sctp_abort_chunk *cp,
486 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net)
487 1.7.4.2 jdolecek {
488 1.7.4.2 jdolecek
489 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
490 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
491 1.7.4.2 jdolecek printf("sctp_handle_abort: handling ABORT\n");
492 1.7.4.2 jdolecek }
493 1.7.4.2 jdolecek #endif
494 1.7.4.2 jdolecek if (stcb == NULL)
495 1.7.4.2 jdolecek return;
496 1.7.4.2 jdolecek /* verify that the destination addr is in the association */
497 1.7.4.2 jdolecek /* ignore abort for addresses being deleted */
498 1.7.4.2 jdolecek
499 1.7.4.2 jdolecek /* stop any receive timers */
500 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep, stcb, net);
501 1.7.4.2 jdolecek /* notify user of the abort and clean up... */
502 1.7.4.2 jdolecek sctp_abort_notification(stcb, 0);
503 1.7.4.2 jdolecek /* free the tcb */
504 1.7.4.2 jdolecek sctp_free_assoc(stcb->sctp_ep, stcb);
505 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
506 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
507 1.7.4.2 jdolecek printf("sctp_handle_abort: finished\n");
508 1.7.4.2 jdolecek }
509 1.7.4.2 jdolecek #endif
510 1.7.4.2 jdolecek }
511 1.7.4.2 jdolecek
512 1.7.4.2 jdolecek static void
513 1.7.4.2 jdolecek sctp_handle_shutdown(struct sctp_shutdown_chunk *cp,
514 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net, int *abort_flag)
515 1.7.4.2 jdolecek {
516 1.7.4.2 jdolecek struct sctp_association *asoc;
517 1.7.4.2 jdolecek int some_on_streamwheel;
518 1.7.4.2 jdolecek
519 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
520 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
521 1.7.4.2 jdolecek printf("sctp_handle_shutdown: handling SHUTDOWN\n");
522 1.7.4.2 jdolecek }
523 1.7.4.2 jdolecek #endif
524 1.7.4.2 jdolecek if (stcb == NULL)
525 1.7.4.2 jdolecek return;
526 1.7.4.2 jdolecek
527 1.7.4.2 jdolecek if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_WAIT) ||
528 1.7.4.2 jdolecek (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_ECHOED)) {
529 1.7.4.2 jdolecek return;
530 1.7.4.2 jdolecek }
531 1.7.4.2 jdolecek
532 1.7.4.2 jdolecek if (ntohs(cp->ch.chunk_length) != sizeof(struct sctp_shutdown_chunk)) {
533 1.7.4.2 jdolecek /* update current data status */
534 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
535 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
536 1.7.4.2 jdolecek printf("Warning Shutdown NOT the expected size.. skipping (%d:%d)\n",
537 1.7.4.2 jdolecek ntohs(cp->ch.chunk_length),
538 1.7.4.2 jdolecek (int)sizeof(struct sctp_shutdown_chunk));
539 1.7.4.2 jdolecek }
540 1.7.4.2 jdolecek #endif
541 1.7.4.2 jdolecek return;
542 1.7.4.2 jdolecek } else {
543 1.7.4.2 jdolecek sctp_update_acked(stcb, cp, net, abort_flag);
544 1.7.4.2 jdolecek }
545 1.7.4.2 jdolecek asoc = &stcb->asoc;
546 1.7.4.2 jdolecek /* goto SHUTDOWN_RECEIVED state to block new requests */
547 1.7.4.2 jdolecek if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_RECEIVED) &&
548 1.7.4.2 jdolecek (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT)) {
549 1.7.4.2 jdolecek asoc->state = SCTP_STATE_SHUTDOWN_RECEIVED;
550 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
551 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
552 1.7.4.2 jdolecek printf("Moving to SHUTDOWN-RECEIVED state\n");
553 1.7.4.2 jdolecek }
554 1.7.4.2 jdolecek #endif
555 1.7.4.2 jdolecek /* notify upper layer that peer has initiated a shutdown */
556 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_PEER_SHUTDOWN, stcb, 0, NULL);
557 1.7.4.2 jdolecek
558 1.7.4.2 jdolecek if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
559 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
560 1.7.4.2 jdolecek
561 1.7.4.2 jdolecek /* Set the flag so we cannot send more, we
562 1.7.4.2 jdolecek * would call the function but we don't want to
563 1.7.4.2 jdolecek * wake up the ulp necessarily.
564 1.7.4.2 jdolecek */
565 1.7.4.2 jdolecek #if defined(__FreeBSD__) && __FreeBSD_version >= 502115
566 1.7.4.2 jdolecek stcb->sctp_ep->sctp_socket->so_rcv.sb_state |= SBS_CANTSENDMORE;
567 1.7.4.2 jdolecek #else
568 1.7.4.2 jdolecek stcb->sctp_ep->sctp_socket->so_state |= SS_CANTSENDMORE;
569 1.7.4.2 jdolecek #endif
570 1.7.4.2 jdolecek }
571 1.7.4.2 jdolecek /* reset time */
572 1.7.4.2 jdolecek SCTP_GETTIME_TIMEVAL(&asoc->time_entered);
573 1.7.4.2 jdolecek }
574 1.7.4.2 jdolecek if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) {
575 1.7.4.2 jdolecek /*
576 1.7.4.2 jdolecek * stop the shutdown timer, since we WILL move
577 1.7.4.2 jdolecek * to SHUTDOWN-ACK-SENT.
578 1.7.4.2 jdolecek */
579 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb, net);
580 1.7.4.2 jdolecek }
581 1.7.4.2 jdolecek /* Now are we there yet? */
582 1.7.4.2 jdolecek some_on_streamwheel = 0;
583 1.7.4.2 jdolecek if (!TAILQ_EMPTY(&asoc->out_wheel)) {
584 1.7.4.2 jdolecek /* Check to see if some data queued */
585 1.7.4.2 jdolecek struct sctp_stream_out *outs;
586 1.7.4.2 jdolecek TAILQ_FOREACH(outs, &asoc->out_wheel, next_spoke) {
587 1.7.4.2 jdolecek if (!TAILQ_EMPTY(&outs->outqueue)) {
588 1.7.4.2 jdolecek some_on_streamwheel = 1;
589 1.7.4.2 jdolecek break;
590 1.7.4.2 jdolecek }
591 1.7.4.2 jdolecek }
592 1.7.4.2 jdolecek }
593 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
594 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
595 1.7.4.2 jdolecek printf("some_on_streamwheel:%d send_q_empty:%d sent_q_empty:%d\n",
596 1.7.4.2 jdolecek some_on_streamwheel,
597 1.7.4.2 jdolecek !TAILQ_EMPTY(&asoc->send_queue),
598 1.7.4.2 jdolecek !TAILQ_EMPTY(&asoc->sent_queue));
599 1.7.4.2 jdolecek }
600 1.7.4.2 jdolecek #endif
601 1.7.4.2 jdolecek if (!TAILQ_EMPTY(&asoc->send_queue) ||
602 1.7.4.2 jdolecek !TAILQ_EMPTY(&asoc->sent_queue) ||
603 1.7.4.2 jdolecek some_on_streamwheel) {
604 1.7.4.2 jdolecek /* By returning we will push more data out */
605 1.7.4.2 jdolecek return;
606 1.7.4.2 jdolecek } else {
607 1.7.4.2 jdolecek /* no outstanding data to send, so move on... */
608 1.7.4.2 jdolecek /* send SHUTDOWN-ACK */
609 1.7.4.2 jdolecek sctp_send_shutdown_ack(stcb, stcb->asoc.primary_destination);
610 1.7.4.2 jdolecek /* move to SHUTDOWN-ACK-SENT state */
611 1.7.4.2 jdolecek asoc->state = SCTP_STATE_SHUTDOWN_ACK_SENT;
612 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
613 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
614 1.7.4.2 jdolecek printf("moving to SHUTDOWN_ACK state\n");
615 1.7.4.2 jdolecek }
616 1.7.4.2 jdolecek #endif
617 1.7.4.2 jdolecek /* start SHUTDOWN timer */
618 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNACK, stcb->sctp_ep,
619 1.7.4.2 jdolecek stcb, net);
620 1.7.4.2 jdolecek }
621 1.7.4.2 jdolecek }
622 1.7.4.2 jdolecek
623 1.7.4.2 jdolecek static void
624 1.7.4.2 jdolecek sctp_handle_shutdown_ack(struct sctp_shutdown_ack_chunk *cp,
625 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net)
626 1.7.4.2 jdolecek {
627 1.7.4.2 jdolecek struct sctp_association *asoc;
628 1.7.4.2 jdolecek
629 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
630 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
631 1.7.4.2 jdolecek printf("sctp_handle_shutdown_ack: handling SHUTDOWN ACK\n");
632 1.7.4.2 jdolecek }
633 1.7.4.2 jdolecek #endif
634 1.7.4.2 jdolecek if (stcb == NULL)
635 1.7.4.2 jdolecek return;
636 1.7.4.2 jdolecek
637 1.7.4.2 jdolecek asoc = &stcb->asoc;
638 1.7.4.2 jdolecek /* process according to association state */
639 1.7.4.2 jdolecek if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
640 1.7.4.2 jdolecek (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
641 1.7.4.2 jdolecek /* unexpected SHUTDOWN-ACK... so ignore... */
642 1.7.4.2 jdolecek return;
643 1.7.4.2 jdolecek }
644 1.7.4.2 jdolecek /* are the queues empty? */
645 1.7.4.2 jdolecek if (!TAILQ_EMPTY(&asoc->send_queue) ||
646 1.7.4.2 jdolecek !TAILQ_EMPTY(&asoc->sent_queue) ||
647 1.7.4.2 jdolecek !TAILQ_EMPTY(&asoc->out_wheel)) {
648 1.7.4.2 jdolecek sctp_report_all_outbound(stcb);
649 1.7.4.2 jdolecek }
650 1.7.4.2 jdolecek /* stop the timer */
651 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb, net);
652 1.7.4.2 jdolecek /* send SHUTDOWN-COMPLETE */
653 1.7.4.2 jdolecek sctp_send_shutdown_complete(stcb, net);
654 1.7.4.2 jdolecek /* notify upper layer protocol */
655 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_ASSOC_DOWN, stcb, 0, NULL);
656 1.7.4.2 jdolecek if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
657 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
658 1.7.4.2 jdolecek stcb->sctp_ep->sctp_flags &= ~SCTP_PCB_FLAGS_CONNECTED;
659 1.7.4.2 jdolecek /* Set the connected flag to disconnected */
660 1.7.4.2 jdolecek stcb->sctp_ep->sctp_socket->so_snd.sb_cc = 0;
661 1.7.4.2 jdolecek stcb->sctp_ep->sctp_socket->so_snd.sb_mbcnt = 0;
662 1.7.4.2 jdolecek soisdisconnected(stcb->sctp_ep->sctp_socket);
663 1.7.4.2 jdolecek }
664 1.7.4.2 jdolecek /* free the TCB but first save off the ep */
665 1.7.4.2 jdolecek sctp_free_assoc(stcb->sctp_ep, stcb);
666 1.7.4.2 jdolecek }
667 1.7.4.2 jdolecek
668 1.7.4.2 jdolecek /*
669 1.7.4.2 jdolecek * Skip past the param header and then we will find the chunk that
670 1.7.4.2 jdolecek * caused the problem. There are two possiblities ASCONF or FWD-TSN
671 1.7.4.2 jdolecek * other than that and our peer must be broken.
672 1.7.4.2 jdolecek */
673 1.7.4.2 jdolecek static void
674 1.7.4.2 jdolecek sctp_process_unrecog_chunk(struct sctp_tcb *stcb, struct sctp_paramhdr *phdr,
675 1.7.4.2 jdolecek struct sctp_nets *net)
676 1.7.4.2 jdolecek {
677 1.7.4.2 jdolecek struct sctp_chunkhdr *chk;
678 1.7.4.2 jdolecek
679 1.7.4.2 jdolecek chk = (struct sctp_chunkhdr *)((vaddr_t)phdr + sizeof(*phdr));
680 1.7.4.2 jdolecek switch (chk->chunk_type) {
681 1.7.4.2 jdolecek case SCTP_ASCONF_ACK:
682 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
683 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
684 1.7.4.2 jdolecek printf("Strange peer, snds ASCONF but does not recongnize asconf-ack?\n");
685 1.7.4.2 jdolecek }
686 1.7.4.2 jdolecek #endif
687 1.7.4.2 jdolecek case SCTP_ASCONF:
688 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
689 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
690 1.7.4.2 jdolecek printf("Peer does not support ASCONF/ASCONF-ACK chunks\n");
691 1.7.4.2 jdolecek }
692 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
693 1.7.4.2 jdolecek sctp_asconf_cleanup(stcb, net);
694 1.7.4.2 jdolecek break;
695 1.7.4.2 jdolecek case SCTP_FORWARD_CUM_TSN:
696 1.7.4.2 jdolecek stcb->asoc.peer_supports_prsctp = 0;
697 1.7.4.2 jdolecek break;
698 1.7.4.2 jdolecek default:
699 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
700 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
701 1.7.4.2 jdolecek printf("Peer does not support chunk type %d(%x)??\n",
702 1.7.4.2 jdolecek chk->chunk_type, (u_int)chk->chunk_type);
703 1.7.4.2 jdolecek }
704 1.7.4.2 jdolecek #endif
705 1.7.4.2 jdolecek break;
706 1.7.4.2 jdolecek }
707 1.7.4.2 jdolecek }
708 1.7.4.2 jdolecek
709 1.7.4.2 jdolecek /*
710 1.7.4.2 jdolecek * Skip past the param header and then we will find the param that
711 1.7.4.2 jdolecek * caused the problem. There are a number of param's in a ASCONF
712 1.7.4.2 jdolecek * OR the prsctp param these will turn of specific features.
713 1.7.4.2 jdolecek */
714 1.7.4.2 jdolecek static void
715 1.7.4.2 jdolecek sctp_process_unrecog_param(struct sctp_tcb *stcb, struct sctp_paramhdr *phdr)
716 1.7.4.2 jdolecek {
717 1.7.4.2 jdolecek struct sctp_paramhdr *pbad;
718 1.7.4.2 jdolecek
719 1.7.4.2 jdolecek pbad = phdr + 1;
720 1.7.4.2 jdolecek switch (ntohs(pbad->param_type)) {
721 1.7.4.2 jdolecek /* pr-sctp draft */
722 1.7.4.2 jdolecek case SCTP_PRSCTP_SUPPORTED:
723 1.7.4.2 jdolecek stcb->asoc.peer_supports_prsctp = 0;
724 1.7.4.2 jdolecek break;
725 1.7.4.2 jdolecek case SCTP_SUPPORTED_CHUNK_EXT:
726 1.7.4.2 jdolecek break;
727 1.7.4.2 jdolecek /* draft-ietf-tsvwg-addip-sctp */
728 1.7.4.2 jdolecek case SCTP_ECN_NONCE_SUPPORTED:
729 1.7.4.2 jdolecek stcb->asoc.peer_supports_ecn_nonce = 0;
730 1.7.4.2 jdolecek stcb->asoc.ecn_nonce_allowed = 0;
731 1.7.4.2 jdolecek stcb->asoc.ecn_allowed = 0;
732 1.7.4.2 jdolecek break;
733 1.7.4.2 jdolecek case SCTP_ADD_IP_ADDRESS:
734 1.7.4.2 jdolecek case SCTP_DEL_IP_ADDRESS:
735 1.7.4.2 jdolecek stcb->asoc.peer_supports_asconf = 0;
736 1.7.4.2 jdolecek break;
737 1.7.4.2 jdolecek case SCTP_SET_PRIM_ADDR:
738 1.7.4.2 jdolecek stcb->asoc.peer_supports_asconf_setprim = 0;
739 1.7.4.2 jdolecek break;
740 1.7.4.2 jdolecek case SCTP_SUCCESS_REPORT:
741 1.7.4.2 jdolecek case SCTP_ERROR_CAUSE_IND:
742 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
743 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
744 1.7.4.2 jdolecek printf("Huh, the peer does not support success? or error cause?\n");
745 1.7.4.2 jdolecek printf("Turning off ASCONF to this strange peer\n");
746 1.7.4.2 jdolecek }
747 1.7.4.2 jdolecek #endif
748 1.7.4.2 jdolecek stcb->asoc.peer_supports_asconf = 0;
749 1.7.4.2 jdolecek stcb->asoc.peer_supports_asconf_setprim = 0;
750 1.7.4.2 jdolecek break;
751 1.7.4.2 jdolecek default:
752 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
753 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
754 1.7.4.2 jdolecek printf("Peer does not support base param type %d(%x)??\n",
755 1.7.4.2 jdolecek pbad->param_type, (u_int)pbad->param_type);
756 1.7.4.2 jdolecek }
757 1.7.4.2 jdolecek #endif
758 1.7.4.2 jdolecek break;
759 1.7.4.2 jdolecek }
760 1.7.4.2 jdolecek }
761 1.7.4.2 jdolecek
762 1.7.4.2 jdolecek static int
763 1.7.4.2 jdolecek sctp_handle_error(struct sctp_chunkhdr *ch,
764 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net)
765 1.7.4.2 jdolecek {
766 1.7.4.2 jdolecek int chklen;
767 1.7.4.2 jdolecek struct sctp_paramhdr *phdr;
768 1.7.4.2 jdolecek uint16_t error_type;
769 1.7.4.2 jdolecek uint16_t error_len;
770 1.7.4.2 jdolecek struct sctp_association *asoc;
771 1.7.4.2 jdolecek
772 1.7.4.2 jdolecek int adjust;
773 1.7.4.2 jdolecek /* parse through all of the errors and process */
774 1.7.4.2 jdolecek asoc = &stcb->asoc;
775 1.7.4.2 jdolecek phdr = (struct sctp_paramhdr *)((vaddr_t)ch +
776 1.7.4.2 jdolecek sizeof(struct sctp_chunkhdr));
777 1.7.4.2 jdolecek chklen = ntohs(ch->chunk_length) - sizeof(struct sctp_chunkhdr);
778 1.7.4.2 jdolecek while ((size_t)chklen >= sizeof(struct sctp_paramhdr)) {
779 1.7.4.2 jdolecek /* Process an Error Cause */
780 1.7.4.2 jdolecek error_type = ntohs(phdr->param_type);
781 1.7.4.2 jdolecek error_len = ntohs(phdr->param_length);
782 1.7.4.2 jdolecek if ((error_len > chklen) || (error_len == 0)) {
783 1.7.4.2 jdolecek /* invalid param length for this param */
784 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
785 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
786 1.7.4.2 jdolecek printf("Bogus length in error param- chunk left:%d errorlen:%d\n",
787 1.7.4.2 jdolecek chklen, error_len);
788 1.7.4.2 jdolecek }
789 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
790 1.7.4.2 jdolecek return (0);
791 1.7.4.2 jdolecek }
792 1.7.4.2 jdolecek switch (error_type) {
793 1.7.4.2 jdolecek case SCTP_CAUSE_INV_STRM:
794 1.7.4.2 jdolecek case SCTP_CAUSE_MISS_PARAM:
795 1.7.4.2 jdolecek case SCTP_CAUSE_INVALID_PARAM:
796 1.7.4.2 jdolecek case SCTP_CAUSE_NOUSER_DATA:
797 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
798 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
799 1.7.4.2 jdolecek printf("Software error we got a %d back? We have a bug :/ (or do they?)\n",
800 1.7.4.2 jdolecek error_type);
801 1.7.4.2 jdolecek }
802 1.7.4.2 jdolecek #endif
803 1.7.4.2 jdolecek break;
804 1.7.4.2 jdolecek case SCTP_CAUSE_STALE_COOKIE:
805 1.7.4.2 jdolecek /* We only act if we have echoed a cookie and are waiting. */
806 1.7.4.2 jdolecek if (SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_ECHOED) {
807 1.7.4.2 jdolecek int *p;
808 1.7.4.2 jdolecek p = (int *)((vaddr_t)phdr + sizeof(*phdr));
809 1.7.4.2 jdolecek /* Save the time doubled */
810 1.7.4.2 jdolecek asoc->cookie_preserve_req = ntohl(*p) << 1;
811 1.7.4.2 jdolecek asoc->stale_cookie_count++;
812 1.7.4.2 jdolecek if (asoc->stale_cookie_count >
813 1.7.4.2 jdolecek asoc->max_init_times) {
814 1.7.4.2 jdolecek sctp_abort_notification(stcb, 0);
815 1.7.4.2 jdolecek /* now free the asoc */
816 1.7.4.2 jdolecek sctp_free_assoc(stcb->sctp_ep, stcb);
817 1.7.4.2 jdolecek return (-1);
818 1.7.4.2 jdolecek }
819 1.7.4.2 jdolecek /* blast back to INIT state */
820 1.7.4.2 jdolecek asoc->state &= ~SCTP_STATE_COOKIE_ECHOED;
821 1.7.4.2 jdolecek asoc->state |= SCTP_STATE_COOKIE_WAIT;
822 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_COOKIE,
823 1.7.4.2 jdolecek stcb->sctp_ep, stcb, net);
824 1.7.4.2 jdolecek sctp_send_initiate(stcb->sctp_ep, stcb);
825 1.7.4.2 jdolecek }
826 1.7.4.2 jdolecek break;
827 1.7.4.2 jdolecek case SCTP_CAUSE_UNRESOLV_ADDR:
828 1.7.4.2 jdolecek /*
829 1.7.4.2 jdolecek * Nothing we can do here, we don't do hostname
830 1.7.4.2 jdolecek * addresses so if the peer does not like my IPv6 (or
831 1.7.4.2 jdolecek * IPv4 for that matter) it does not matter. If they
832 1.7.4.2 jdolecek * don't support that type of address, they can NOT
833 1.7.4.2 jdolecek * possibly get that packet type... i.e. with no IPv6
834 1.7.4.2 jdolecek * you can't recieve a IPv6 packet. so we can safely
835 1.7.4.2 jdolecek * ignore this one. If we ever added support for
836 1.7.4.2 jdolecek * HOSTNAME Addresses, then we would need to do
837 1.7.4.2 jdolecek * something here.
838 1.7.4.2 jdolecek */
839 1.7.4.2 jdolecek break;
840 1.7.4.2 jdolecek case SCTP_CAUSE_UNRECOG_CHUNK:
841 1.7.4.2 jdolecek sctp_process_unrecog_chunk(stcb, phdr, net);
842 1.7.4.2 jdolecek break;
843 1.7.4.2 jdolecek case SCTP_CAUSE_UNRECOG_PARAM:
844 1.7.4.2 jdolecek sctp_process_unrecog_param(stcb, phdr);
845 1.7.4.2 jdolecek break;
846 1.7.4.2 jdolecek case SCTP_CAUSE_COOKIE_IN_SHUTDOWN:
847 1.7.4.2 jdolecek /*
848 1.7.4.2 jdolecek * We ignore this since the timer will drive out a new
849 1.7.4.2 jdolecek * cookie anyway and there timer will drive us to send
850 1.7.4.2 jdolecek * a SHUTDOWN_COMPLETE. We can't send one here since
851 1.7.4.2 jdolecek * we don't have their tag.
852 1.7.4.2 jdolecek */
853 1.7.4.2 jdolecek break;
854 1.7.4.2 jdolecek case SCTP_CAUSE_DELETEING_LAST_ADDR:
855 1.7.4.2 jdolecek case SCTP_CAUSE_OPERATION_REFUSED:
856 1.7.4.2 jdolecek case SCTP_CAUSE_DELETING_SRC_ADDR:
857 1.7.4.2 jdolecek /* We should NOT get these here, but in a ASCONF-ACK. */
858 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
859 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
860 1.7.4.2 jdolecek printf("Peer sends ASCONF errors in a Operational Error?<%d>?\n",
861 1.7.4.2 jdolecek error_type);
862 1.7.4.2 jdolecek }
863 1.7.4.2 jdolecek #endif
864 1.7.4.2 jdolecek break;
865 1.7.4.2 jdolecek case SCTP_CAUSE_OUT_OF_RESC:
866 1.7.4.2 jdolecek /*
867 1.7.4.2 jdolecek * And what, pray tell do we do with the fact
868 1.7.4.2 jdolecek * that the peer is out of resources? Not
869 1.7.4.2 jdolecek * really sure we could do anything but abort.
870 1.7.4.2 jdolecek * I suspect this should have came WITH an
871 1.7.4.2 jdolecek * abort instead of in a OP-ERROR.
872 1.7.4.2 jdolecek */
873 1.7.4.2 jdolecek break;
874 1.7.4.2 jdolecek default:
875 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
876 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
877 1.7.4.2 jdolecek /* don't know what this error cause is... */
878 1.7.4.2 jdolecek printf("sctp_handle_error: unknown error type = 0x%xh\n",
879 1.7.4.2 jdolecek error_type);
880 1.7.4.2 jdolecek }
881 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
882 1.7.4.2 jdolecek break;
883 1.7.4.2 jdolecek }
884 1.7.4.2 jdolecek adjust = SCTP_SIZE32(error_len);
885 1.7.4.2 jdolecek chklen -= adjust;
886 1.7.4.2 jdolecek phdr = (struct sctp_paramhdr *)((vaddr_t)phdr + adjust);
887 1.7.4.2 jdolecek }
888 1.7.4.2 jdolecek return (0);
889 1.7.4.2 jdolecek }
890 1.7.4.2 jdolecek
891 1.7.4.2 jdolecek static int
892 1.7.4.2 jdolecek sctp_handle_init_ack(struct mbuf *m, int iphlen, int offset, struct sctphdr *sh,
893 1.7.4.2 jdolecek struct sctp_init_ack_chunk *cp, struct sctp_tcb *stcb,
894 1.7.4.2 jdolecek struct sctp_nets *net)
895 1.7.4.2 jdolecek {
896 1.7.4.2 jdolecek struct sctp_init_ack *init_ack;
897 1.7.4.2 jdolecek int *state;
898 1.7.4.2 jdolecek struct mbuf *op_err;
899 1.7.4.2 jdolecek
900 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
901 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
902 1.7.4.2 jdolecek printf("sctp_handle_init_ack: handling INIT-ACK\n");
903 1.7.4.2 jdolecek }
904 1.7.4.2 jdolecek #endif
905 1.7.4.2 jdolecek if (stcb == NULL) {
906 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
907 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
908 1.7.4.2 jdolecek printf("sctp_handle_init_ack: TCB is null\n");
909 1.7.4.2 jdolecek }
910 1.7.4.2 jdolecek #endif
911 1.7.4.2 jdolecek return (-1);
912 1.7.4.2 jdolecek }
913 1.7.4.2 jdolecek if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_init_ack_chunk)) {
914 1.7.4.2 jdolecek /* Invalid length */
915 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
916 1.7.4.2 jdolecek sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen, sh,
917 1.7.4.2 jdolecek op_err);
918 1.7.4.2 jdolecek return (-1);
919 1.7.4.2 jdolecek }
920 1.7.4.2 jdolecek init_ack = &cp->init;
921 1.7.4.2 jdolecek /* validate parameters */
922 1.7.4.2 jdolecek if (init_ack->initiate_tag == 0) {
923 1.7.4.2 jdolecek /* protocol error... send an abort */
924 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
925 1.7.4.2 jdolecek sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen, sh,
926 1.7.4.2 jdolecek op_err);
927 1.7.4.2 jdolecek return (-1);
928 1.7.4.2 jdolecek }
929 1.7.4.2 jdolecek if (ntohl(init_ack->a_rwnd) < SCTP_MIN_RWND) {
930 1.7.4.2 jdolecek /* protocol error... send an abort */
931 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
932 1.7.4.2 jdolecek sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen, sh,
933 1.7.4.2 jdolecek op_err);
934 1.7.4.2 jdolecek return (-1);
935 1.7.4.2 jdolecek }
936 1.7.4.2 jdolecek if (init_ack->num_inbound_streams == 0) {
937 1.7.4.2 jdolecek /* protocol error... send an abort */
938 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
939 1.7.4.2 jdolecek sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen, sh,
940 1.7.4.2 jdolecek op_err);
941 1.7.4.2 jdolecek return (-1);
942 1.7.4.2 jdolecek }
943 1.7.4.2 jdolecek if (init_ack->num_outbound_streams == 0) {
944 1.7.4.2 jdolecek /* protocol error... send an abort */
945 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_INVALID_PARAM);
946 1.7.4.2 jdolecek sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen, sh,
947 1.7.4.2 jdolecek op_err);
948 1.7.4.2 jdolecek return (-1);
949 1.7.4.2 jdolecek }
950 1.7.4.2 jdolecek
951 1.7.4.2 jdolecek /* process according to association state... */
952 1.7.4.2 jdolecek state = &stcb->asoc.state;
953 1.7.4.2 jdolecek switch (*state & SCTP_STATE_MASK) {
954 1.7.4.2 jdolecek case SCTP_STATE_COOKIE_WAIT:
955 1.7.4.2 jdolecek /* this is the expected state for this chunk */
956 1.7.4.2 jdolecek /* process the INIT-ACK parameters */
957 1.7.4.2 jdolecek if (stcb->asoc.primary_destination->dest_state &
958 1.7.4.2 jdolecek SCTP_ADDR_UNCONFIRMED) {
959 1.7.4.2 jdolecek /*
960 1.7.4.2 jdolecek * The primary is where we sent the INIT, we can
961 1.7.4.2 jdolecek * always consider it confirmed when the INIT-ACK
962 1.7.4.2 jdolecek * is returned. Do this before we load addresses
963 1.7.4.2 jdolecek * though.
964 1.7.4.2 jdolecek */
965 1.7.4.2 jdolecek stcb->asoc.primary_destination->dest_state &=
966 1.7.4.2 jdolecek ~SCTP_ADDR_UNCONFIRMED;
967 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_CONFIRMED,
968 1.7.4.2 jdolecek stcb, 0, (void *)stcb->asoc.primary_destination);
969 1.7.4.2 jdolecek }
970 1.7.4.2 jdolecek if (sctp_process_init_ack(m, iphlen, offset, sh, cp, stcb, net
971 1.7.4.2 jdolecek ) < 0) {
972 1.7.4.2 jdolecek /* error in parsing parameters */
973 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
974 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
975 1.7.4.2 jdolecek printf("sctp_process_init_ack: error in msg, discarding\n");
976 1.7.4.2 jdolecek }
977 1.7.4.2 jdolecek #endif
978 1.7.4.2 jdolecek return (-1);
979 1.7.4.2 jdolecek }
980 1.7.4.2 jdolecek /* update our state */
981 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
982 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
983 1.7.4.2 jdolecek printf("moving to COOKIE-ECHOED state\n");
984 1.7.4.2 jdolecek }
985 1.7.4.2 jdolecek #endif
986 1.7.4.2 jdolecek if (*state & SCTP_STATE_SHUTDOWN_PENDING) {
987 1.7.4.2 jdolecek *state = SCTP_STATE_COOKIE_ECHOED |
988 1.7.4.2 jdolecek SCTP_STATE_SHUTDOWN_PENDING;
989 1.7.4.2 jdolecek } else {
990 1.7.4.2 jdolecek *state = SCTP_STATE_COOKIE_ECHOED;
991 1.7.4.2 jdolecek }
992 1.7.4.2 jdolecek
993 1.7.4.2 jdolecek /* reset the RTO calc */
994 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
995 1.7.4.2 jdolecek SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
996 1.7.4.2 jdolecek /*
997 1.7.4.2 jdolecek * collapse the init timer back in case of a exponential backoff
998 1.7.4.2 jdolecek */
999 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_COOKIE, stcb->sctp_ep,
1000 1.7.4.2 jdolecek stcb, net);
1001 1.7.4.2 jdolecek /*
1002 1.7.4.2 jdolecek * the send at the end of the inbound data processing will
1003 1.7.4.2 jdolecek * cause the cookie to be sent
1004 1.7.4.2 jdolecek */
1005 1.7.4.2 jdolecek break;
1006 1.7.4.2 jdolecek case SCTP_STATE_SHUTDOWN_SENT:
1007 1.7.4.2 jdolecek /* incorrect state... discard */
1008 1.7.4.2 jdolecek break;
1009 1.7.4.2 jdolecek case SCTP_STATE_COOKIE_ECHOED:
1010 1.7.4.2 jdolecek /* incorrect state... discard */
1011 1.7.4.2 jdolecek break;
1012 1.7.4.2 jdolecek case SCTP_STATE_OPEN:
1013 1.7.4.2 jdolecek /* incorrect state... discard */
1014 1.7.4.2 jdolecek break;
1015 1.7.4.2 jdolecek case SCTP_STATE_EMPTY:
1016 1.7.4.2 jdolecek case SCTP_STATE_INUSE:
1017 1.7.4.2 jdolecek default:
1018 1.7.4.2 jdolecek /* incorrect state... discard */
1019 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1020 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1021 1.7.4.2 jdolecek printf("Leaving handle-init-ack default\n");
1022 1.7.4.2 jdolecek }
1023 1.7.4.2 jdolecek #endif
1024 1.7.4.2 jdolecek return (-1);
1025 1.7.4.2 jdolecek break;
1026 1.7.4.2 jdolecek } /* end switch asoc state */
1027 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1028 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1029 1.7.4.2 jdolecek printf("Leaving handle-init-ack end\n");
1030 1.7.4.2 jdolecek }
1031 1.7.4.2 jdolecek #endif
1032 1.7.4.2 jdolecek return (0);
1033 1.7.4.2 jdolecek }
1034 1.7.4.2 jdolecek
1035 1.7.4.2 jdolecek
1036 1.7.4.2 jdolecek /*
1037 1.7.4.2 jdolecek * handle a state cookie for an existing association
1038 1.7.4.2 jdolecek * m: input packet mbuf chain-- assumes a pullup on IP/SCTP/COOKIE-ECHO chunk
1039 1.7.4.2 jdolecek * note: this is a "split" mbuf and the cookie signature does not exist
1040 1.7.4.2 jdolecek * offset: offset into mbuf to the cookie-echo chunk
1041 1.7.4.2 jdolecek */
1042 1.7.4.2 jdolecek static struct sctp_tcb *
1043 1.7.4.2 jdolecek sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
1044 1.7.4.2 jdolecek struct sctphdr *sh, struct sctp_state_cookie *cookie, int cookie_len,
1045 1.7.4.2 jdolecek struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sctp_nets *net,
1046 1.7.4.2 jdolecek struct sockaddr *init_src, int *notification)
1047 1.7.4.2 jdolecek {
1048 1.7.4.2 jdolecek struct sctp_association *asoc;
1049 1.7.4.2 jdolecek struct sctp_init_chunk *init_cp, init_buf;
1050 1.7.4.2 jdolecek struct sctp_init_ack_chunk *initack_cp, initack_buf;
1051 1.7.4.2 jdolecek int chk_length;
1052 1.7.4.2 jdolecek int init_offset, initack_offset;
1053 1.7.4.2 jdolecek int retval;
1054 1.7.4.2 jdolecek
1055 1.7.4.2 jdolecek /* I know that the TCB is non-NULL from the caller */
1056 1.7.4.2 jdolecek asoc = &stcb->asoc;
1057 1.7.4.2 jdolecek
1058 1.7.4.2 jdolecek if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_ACK_SENT) {
1059 1.7.4.2 jdolecek /* SHUTDOWN came in after sending INIT-ACK */
1060 1.7.4.2 jdolecek struct mbuf *op_err;
1061 1.7.4.2 jdolecek struct sctp_paramhdr *ph;
1062 1.7.4.2 jdolecek
1063 1.7.4.2 jdolecek sctp_send_shutdown_ack(stcb, stcb->asoc.primary_destination);
1064 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1065 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1066 1.7.4.2 jdolecek printf("sctp_handle_cookie: got a cookie, while shutting down!\n");
1067 1.7.4.2 jdolecek }
1068 1.7.4.2 jdolecek #endif
1069 1.7.4.2 jdolecek MGETHDR(op_err, M_DONTWAIT, MT_HEADER);
1070 1.7.4.2 jdolecek if (op_err == NULL) {
1071 1.7.4.2 jdolecek /* FOOBAR */
1072 1.7.4.2 jdolecek return (NULL);
1073 1.7.4.2 jdolecek }
1074 1.7.4.2 jdolecek /* pre-reserve some space */
1075 1.7.4.2 jdolecek op_err->m_data += sizeof(struct ip6_hdr);
1076 1.7.4.2 jdolecek op_err->m_data += sizeof(struct sctphdr);
1077 1.7.4.2 jdolecek op_err->m_data += sizeof(struct sctp_chunkhdr);
1078 1.7.4.2 jdolecek /* Set the len */
1079 1.7.4.2 jdolecek op_err->m_len = op_err->m_pkthdr.len = sizeof(struct sctp_paramhdr);
1080 1.7.4.2 jdolecek ph = mtod(op_err, struct sctp_paramhdr *);
1081 1.7.4.2 jdolecek ph->param_type = htons(SCTP_CAUSE_COOKIE_IN_SHUTDOWN);
1082 1.7.4.2 jdolecek ph->param_length = htons(sizeof(struct sctp_paramhdr));
1083 1.7.4.2 jdolecek sctp_send_operr_to(m, iphlen, op_err, cookie->peers_vtag);
1084 1.7.4.2 jdolecek return (NULL);
1085 1.7.4.2 jdolecek }
1086 1.7.4.2 jdolecek /*
1087 1.7.4.2 jdolecek * find and validate the INIT chunk in the cookie (peer's info)
1088 1.7.4.2 jdolecek * the INIT should start after the cookie-echo header struct
1089 1.7.4.2 jdolecek * (chunk header, state cookie header struct)
1090 1.7.4.2 jdolecek */
1091 1.7.4.2 jdolecek init_offset = offset += sizeof(struct sctp_cookie_echo_chunk);
1092 1.7.4.2 jdolecek
1093 1.7.4.2 jdolecek init_cp = (struct sctp_init_chunk *)
1094 1.7.4.2 jdolecek sctp_m_getptr(m, init_offset, sizeof(struct sctp_init_chunk),
1095 1.7.4.2 jdolecek (u_int8_t *)&init_buf);
1096 1.7.4.2 jdolecek if (init_cp == NULL) {
1097 1.7.4.2 jdolecek /* could not pull a INIT chunk in cookie */
1098 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1099 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1100 1.7.4.2 jdolecek printf("process_cookie_existing: could not pull INIT chunk hdr\n");
1101 1.7.4.2 jdolecek }
1102 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1103 1.7.4.2 jdolecek return (NULL);
1104 1.7.4.2 jdolecek }
1105 1.7.4.2 jdolecek chk_length = ntohs(init_cp->ch.chunk_length);
1106 1.7.4.2 jdolecek if (init_cp->ch.chunk_type != SCTP_INITIATION) {
1107 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1108 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1109 1.7.4.2 jdolecek printf("process_cookie_existing: could not find INIT chunk!\n");
1110 1.7.4.2 jdolecek }
1111 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1112 1.7.4.2 jdolecek return (NULL);
1113 1.7.4.2 jdolecek }
1114 1.7.4.2 jdolecek
1115 1.7.4.2 jdolecek /*
1116 1.7.4.2 jdolecek * find and validate the INIT-ACK chunk in the cookie (my info)
1117 1.7.4.2 jdolecek * the INIT-ACK follows the INIT chunk
1118 1.7.4.2 jdolecek */
1119 1.7.4.2 jdolecek initack_offset = init_offset + SCTP_SIZE32(chk_length);
1120 1.7.4.2 jdolecek initack_cp = (struct sctp_init_ack_chunk *)
1121 1.7.4.2 jdolecek sctp_m_getptr(m, initack_offset, sizeof(struct sctp_init_ack_chunk),
1122 1.7.4.2 jdolecek (u_int8_t *)&initack_buf);
1123 1.7.4.2 jdolecek if (initack_cp == NULL) {
1124 1.7.4.2 jdolecek /* could not pull INIT-ACK chunk in cookie */
1125 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1126 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1127 1.7.4.2 jdolecek printf("process_cookie_existing: could not pull INIT-ACK chunk hdr\n");
1128 1.7.4.2 jdolecek }
1129 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1130 1.7.4.2 jdolecek return (NULL);
1131 1.7.4.2 jdolecek }
1132 1.7.4.2 jdolecek chk_length = ntohs(initack_cp->ch.chunk_length);
1133 1.7.4.2 jdolecek if (initack_cp->ch.chunk_type != SCTP_INITIATION_ACK) {
1134 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1135 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1136 1.7.4.2 jdolecek printf("process_cookie_existing: could not find INIT-ACK chunk!\n");
1137 1.7.4.2 jdolecek }
1138 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1139 1.7.4.2 jdolecek return (NULL);
1140 1.7.4.2 jdolecek }
1141 1.7.4.2 jdolecek if ((ntohl(initack_cp->init.initiate_tag) == asoc->my_vtag) &&
1142 1.7.4.2 jdolecek (ntohl(init_cp->init.initiate_tag) == asoc->peer_vtag)) {
1143 1.7.4.2 jdolecek /*
1144 1.7.4.2 jdolecek * case D in Section 5.2.4 Table 2: MMAA
1145 1.7.4.2 jdolecek * process accordingly to get into the OPEN state
1146 1.7.4.2 jdolecek */
1147 1.7.4.2 jdolecek switch SCTP_GET_STATE(asoc) {
1148 1.7.4.2 jdolecek case SCTP_STATE_COOKIE_WAIT:
1149 1.7.4.2 jdolecek /*
1150 1.7.4.2 jdolecek * INIT was sent, but got got a COOKIE_ECHO with
1151 1.7.4.2 jdolecek * the correct tags... just accept it...
1152 1.7.4.2 jdolecek */
1153 1.7.4.2 jdolecek /* First we must process the INIT !! */
1154 1.7.4.2 jdolecek retval = sctp_process_init(init_cp, stcb, net);
1155 1.7.4.2 jdolecek if (retval < 0) {
1156 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1157 1.7.4.2 jdolecek printf("process_cookie_existing: INIT processing failed\n");
1158 1.7.4.2 jdolecek #endif
1159 1.7.4.2 jdolecek return (NULL);
1160 1.7.4.2 jdolecek }
1161 1.7.4.2 jdolecek /* intentional fall through to below... */
1162 1.7.4.2 jdolecek
1163 1.7.4.2 jdolecek case SCTP_STATE_COOKIE_ECHOED:
1164 1.7.4.2 jdolecek /* Duplicate INIT case */
1165 1.7.4.2 jdolecek /* we have already processed the INIT so no problem */
1166 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb,
1167 1.7.4.2 jdolecek net);
1168 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, net);
1169 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_COOKIE, inp, stcb,
1170 1.7.4.2 jdolecek net);
1171 1.7.4.2 jdolecek /* update current state */
1172 1.7.4.2 jdolecek if (asoc->state & SCTP_STATE_SHUTDOWN_PENDING) {
1173 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN |
1174 1.7.4.2 jdolecek SCTP_STATE_SHUTDOWN_PENDING;
1175 1.7.4.2 jdolecek } else if ((asoc->state & SCTP_STATE_SHUTDOWN_SENT) == 0) {
1176 1.7.4.2 jdolecek /* if ok, move to OPEN state */
1177 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN;
1178 1.7.4.2 jdolecek }
1179 1.7.4.2 jdolecek if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1180 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) &&
1181 1.7.4.2 jdolecek (!(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING))) {
1182 1.7.4.2 jdolecek /*
1183 1.7.4.2 jdolecek * Here is where collision would go if we did a
1184 1.7.4.2 jdolecek * connect() and instead got a
1185 1.7.4.2 jdolecek * init/init-ack/cookie done before the
1186 1.7.4.2 jdolecek * init-ack came back..
1187 1.7.4.2 jdolecek */
1188 1.7.4.2 jdolecek stcb->sctp_ep->sctp_flags |=
1189 1.7.4.2 jdolecek SCTP_PCB_FLAGS_CONNECTED;
1190 1.7.4.2 jdolecek soisconnected(stcb->sctp_ep->sctp_socket);
1191 1.7.4.2 jdolecek }
1192 1.7.4.2 jdolecek /* notify upper layer */
1193 1.7.4.2 jdolecek *notification = SCTP_NOTIFY_ASSOC_UP;
1194 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb,
1195 1.7.4.2 jdolecek net);
1196 1.7.4.2 jdolecek /*
1197 1.7.4.2 jdolecek * since we did not send a HB make sure we don't double
1198 1.7.4.2 jdolecek * things
1199 1.7.4.2 jdolecek */
1200 1.7.4.2 jdolecek net->hb_responded = 1;
1201 1.7.4.2 jdolecek
1202 1.7.4.2 jdolecek if (stcb->asoc.sctp_autoclose_ticks &&
1203 1.7.4.2 jdolecek (inp->sctp_flags & SCTP_PCB_FLAGS_AUTOCLOSE)) {
1204 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE,
1205 1.7.4.2 jdolecek inp, stcb, NULL);
1206 1.7.4.2 jdolecek }
1207 1.7.4.2 jdolecek break;
1208 1.7.4.2 jdolecek default:
1209 1.7.4.2 jdolecek /*
1210 1.7.4.2 jdolecek * we're in the OPEN state (or beyond), so peer
1211 1.7.4.2 jdolecek * must have simply lost the COOKIE-ACK
1212 1.7.4.2 jdolecek */
1213 1.7.4.2 jdolecek break;
1214 1.7.4.2 jdolecek } /* end switch */
1215 1.7.4.2 jdolecek
1216 1.7.4.2 jdolecek /*
1217 1.7.4.2 jdolecek * We ignore the return code here.. not sure if we should
1218 1.7.4.2 jdolecek * somehow abort.. but we do have an existing asoc. This
1219 1.7.4.2 jdolecek * really should not fail.
1220 1.7.4.2 jdolecek */
1221 1.7.4.2 jdolecek if (sctp_load_addresses_from_init(stcb, m, iphlen,
1222 1.7.4.2 jdolecek init_offset + sizeof(struct sctp_init_chunk),
1223 1.7.4.2 jdolecek initack_offset, sh, init_src)) {
1224 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1225 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1226 1.7.4.2 jdolecek printf("Weird cookie load_address failure on cookie existing - 1\n");
1227 1.7.4.2 jdolecek }
1228 1.7.4.2 jdolecek #endif
1229 1.7.4.2 jdolecek return (NULL);
1230 1.7.4.2 jdolecek }
1231 1.7.4.2 jdolecek
1232 1.7.4.2 jdolecek /* respond with a COOKIE-ACK */
1233 1.7.4.2 jdolecek sctp_send_cookie_ack(stcb);
1234 1.7.4.2 jdolecek return (stcb);
1235 1.7.4.2 jdolecek } /* end if */
1236 1.7.4.2 jdolecek if (ntohl(initack_cp->init.initiate_tag) != asoc->my_vtag &&
1237 1.7.4.2 jdolecek ntohl(init_cp->init.initiate_tag) == asoc->peer_vtag &&
1238 1.7.4.2 jdolecek cookie->tie_tag_my_vtag == 0 &&
1239 1.7.4.2 jdolecek cookie->tie_tag_peer_vtag == 0) {
1240 1.7.4.2 jdolecek /*
1241 1.7.4.2 jdolecek * case C in Section 5.2.4 Table 2: XMOO
1242 1.7.4.2 jdolecek * silently discard
1243 1.7.4.2 jdolecek */
1244 1.7.4.2 jdolecek return (NULL);
1245 1.7.4.2 jdolecek }
1246 1.7.4.2 jdolecek if (ntohl(initack_cp->init.initiate_tag) == asoc->my_vtag &&
1247 1.7.4.2 jdolecek (ntohl(init_cp->init.initiate_tag) != asoc->peer_vtag ||
1248 1.7.4.2 jdolecek init_cp->init.initiate_tag == 0)) {
1249 1.7.4.2 jdolecek /*
1250 1.7.4.2 jdolecek * case B in Section 5.2.4 Table 2: MXAA or MOAA
1251 1.7.4.2 jdolecek * my info should be ok, re-accept peer info
1252 1.7.4.2 jdolecek */
1253 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
1254 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, net);
1255 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_COOKIE, inp, stcb, net);
1256 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
1257 1.7.4.2 jdolecek /*
1258 1.7.4.2 jdolecek * since we did not send a HB make sure we don't double things
1259 1.7.4.2 jdolecek */
1260 1.7.4.2 jdolecek net->hb_responded = 1;
1261 1.7.4.2 jdolecek if (stcb->asoc.sctp_autoclose_ticks &&
1262 1.7.4.2 jdolecek (inp->sctp_flags & SCTP_PCB_FLAGS_AUTOCLOSE)) {
1263 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb,
1264 1.7.4.2 jdolecek NULL);
1265 1.7.4.2 jdolecek }
1266 1.7.4.2 jdolecek asoc->my_rwnd = ntohl(initack_cp->init.a_rwnd);
1267 1.7.4.2 jdolecek asoc->pre_open_streams =
1268 1.7.4.2 jdolecek ntohs(initack_cp->init.num_outbound_streams);
1269 1.7.4.2 jdolecek asoc->init_seq_number = ntohl(initack_cp->init.initial_tsn);
1270 1.7.4.2 jdolecek asoc->sending_seq = asoc->asconf_seq_out = asoc->str_reset_seq_out =
1271 1.7.4.2 jdolecek asoc->init_seq_number;
1272 1.7.4.2 jdolecek asoc->t3timeout_highest_marked = asoc->asconf_seq_out;
1273 1.7.4.2 jdolecek asoc->last_cwr_tsn = asoc->init_seq_number - 1;
1274 1.7.4.2 jdolecek asoc->asconf_seq_in = asoc->last_acked_seq = asoc->init_seq_number - 1;
1275 1.7.4.2 jdolecek asoc->str_reset_seq_in = asoc->init_seq_number;
1276 1.7.4.2 jdolecek asoc->advanced_peer_ack_point = asoc->last_acked_seq;
1277 1.7.4.2 jdolecek
1278 1.7.4.2 jdolecek /* process the INIT info (peer's info) */
1279 1.7.4.2 jdolecek retval = sctp_process_init(init_cp, stcb, net);
1280 1.7.4.2 jdolecek if (retval < 0) {
1281 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1282 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1283 1.7.4.2 jdolecek printf("process_cookie_existing: INIT processing failed\n");
1284 1.7.4.2 jdolecek }
1285 1.7.4.2 jdolecek #endif
1286 1.7.4.2 jdolecek return (NULL);
1287 1.7.4.2 jdolecek }
1288 1.7.4.2 jdolecek if (sctp_load_addresses_from_init(stcb, m, iphlen,
1289 1.7.4.2 jdolecek init_offset + sizeof(struct sctp_init_chunk),
1290 1.7.4.2 jdolecek initack_offset, sh, init_src)) {
1291 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1292 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1293 1.7.4.2 jdolecek printf("Weird cookie load_address failure on cookie existing - 2\n");
1294 1.7.4.2 jdolecek }
1295 1.7.4.2 jdolecek #endif
1296 1.7.4.2 jdolecek return (NULL);
1297 1.7.4.2 jdolecek }
1298 1.7.4.2 jdolecek
1299 1.7.4.2 jdolecek if ((asoc->state & SCTP_STATE_COOKIE_WAIT) ||
1300 1.7.4.2 jdolecek (asoc->state & SCTP_STATE_COOKIE_ECHOED)) {
1301 1.7.4.2 jdolecek *notification = SCTP_NOTIFY_ASSOC_UP;
1302 1.7.4.2 jdolecek
1303 1.7.4.2 jdolecek if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1304 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) &&
1305 1.7.4.2 jdolecek !(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING)) {
1306 1.7.4.2 jdolecek stcb->sctp_ep->sctp_flags |=
1307 1.7.4.2 jdolecek SCTP_PCB_FLAGS_CONNECTED;
1308 1.7.4.2 jdolecek soisconnected(stcb->sctp_ep->sctp_socket);
1309 1.7.4.2 jdolecek }
1310 1.7.4.2 jdolecek }
1311 1.7.4.2 jdolecek if (asoc->state & SCTP_STATE_SHUTDOWN_PENDING) {
1312 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN |
1313 1.7.4.2 jdolecek SCTP_STATE_SHUTDOWN_PENDING;
1314 1.7.4.2 jdolecek } else {
1315 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN;
1316 1.7.4.2 jdolecek }
1317 1.7.4.2 jdolecek sctp_send_cookie_ack(stcb);
1318 1.7.4.2 jdolecek return (stcb);
1319 1.7.4.2 jdolecek }
1320 1.7.4.2 jdolecek
1321 1.7.4.2 jdolecek if ((ntohl(initack_cp->init.initiate_tag) != asoc->my_vtag &&
1322 1.7.4.2 jdolecek ntohl(init_cp->init.initiate_tag) != asoc->peer_vtag) &&
1323 1.7.4.2 jdolecek cookie->tie_tag_my_vtag == asoc->my_vtag_nonce &&
1324 1.7.4.2 jdolecek cookie->tie_tag_peer_vtag == asoc->peer_vtag_nonce &&
1325 1.7.4.2 jdolecek cookie->tie_tag_peer_vtag != 0) {
1326 1.7.4.2 jdolecek /*
1327 1.7.4.2 jdolecek * case A in Section 5.2.4 Table 2: XXMM (peer restarted)
1328 1.7.4.2 jdolecek */
1329 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, net);
1330 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_COOKIE, inp, stcb, net);
1331 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
1332 1.7.4.2 jdolecek
1333 1.7.4.2 jdolecek /* notify upper layer */
1334 1.7.4.2 jdolecek *notification = SCTP_NOTIFY_ASSOC_RESTART;
1335 1.7.4.2 jdolecek
1336 1.7.4.2 jdolecek /* send up all the data */
1337 1.7.4.2 jdolecek sctp_report_all_outbound(stcb);
1338 1.7.4.2 jdolecek
1339 1.7.4.2 jdolecek /* process the INIT-ACK info (my info) */
1340 1.7.4.2 jdolecek asoc->my_vtag = ntohl(initack_cp->init.initiate_tag);
1341 1.7.4.2 jdolecek asoc->my_rwnd = ntohl(initack_cp->init.a_rwnd);
1342 1.7.4.2 jdolecek asoc->pre_open_streams =
1343 1.7.4.2 jdolecek ntohs(initack_cp->init.num_outbound_streams);
1344 1.7.4.2 jdolecek asoc->init_seq_number = ntohl(initack_cp->init.initial_tsn);
1345 1.7.4.2 jdolecek asoc->sending_seq = asoc->asconf_seq_out = asoc->str_reset_seq_out =
1346 1.7.4.2 jdolecek asoc->init_seq_number;
1347 1.7.4.2 jdolecek asoc->t3timeout_highest_marked = asoc->asconf_seq_out;
1348 1.7.4.2 jdolecek asoc->last_cwr_tsn = asoc->init_seq_number - 1;
1349 1.7.4.2 jdolecek asoc->asconf_seq_in = asoc->last_acked_seq = asoc->init_seq_number - 1;
1350 1.7.4.2 jdolecek asoc->str_reset_seq_in = asoc->init_seq_number;
1351 1.7.4.2 jdolecek
1352 1.7.4.2 jdolecek asoc->advanced_peer_ack_point = asoc->last_acked_seq;
1353 1.7.4.2 jdolecek if (asoc->mapping_array)
1354 1.7.4.2 jdolecek memset(asoc->mapping_array, 0,
1355 1.7.4.2 jdolecek asoc->mapping_array_size);
1356 1.7.4.2 jdolecek /* process the INIT info (peer's info) */
1357 1.7.4.2 jdolecek retval = sctp_process_init(init_cp, stcb, net);
1358 1.7.4.2 jdolecek if (retval < 0) {
1359 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1360 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1361 1.7.4.2 jdolecek printf("process_cookie_existing: INIT processing failed\n");
1362 1.7.4.2 jdolecek }
1363 1.7.4.2 jdolecek #endif
1364 1.7.4.2 jdolecek return (NULL);
1365 1.7.4.2 jdolecek }
1366 1.7.4.2 jdolecek
1367 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
1368 1.7.4.2 jdolecek /*
1369 1.7.4.2 jdolecek * since we did not send a HB make sure we don't double things
1370 1.7.4.2 jdolecek */
1371 1.7.4.2 jdolecek net->hb_responded = 1;
1372 1.7.4.2 jdolecek
1373 1.7.4.2 jdolecek if (sctp_load_addresses_from_init(stcb, m, iphlen,
1374 1.7.4.2 jdolecek init_offset + sizeof(struct sctp_init_chunk),
1375 1.7.4.2 jdolecek initack_offset, sh, init_src)) {
1376 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1377 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1378 1.7.4.2 jdolecek printf("Weird cookie load_address failure on cookie existing - 3\n");
1379 1.7.4.2 jdolecek }
1380 1.7.4.2 jdolecek #endif
1381 1.7.4.2 jdolecek return (NULL);
1382 1.7.4.2 jdolecek }
1383 1.7.4.2 jdolecek
1384 1.7.4.2 jdolecek if (asoc->state & SCTP_STATE_SHUTDOWN_PENDING) {
1385 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN |
1386 1.7.4.2 jdolecek SCTP_STATE_SHUTDOWN_PENDING;
1387 1.7.4.2 jdolecek } else if (!(asoc->state & SCTP_STATE_SHUTDOWN_SENT)) {
1388 1.7.4.2 jdolecek /* move to OPEN state, if not in SHUTDOWN_SENT */
1389 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN;
1390 1.7.4.2 jdolecek }
1391 1.7.4.2 jdolecek /* respond with a COOKIE-ACK */
1392 1.7.4.2 jdolecek sctp_send_cookie_ack(stcb);
1393 1.7.4.2 jdolecek
1394 1.7.4.2 jdolecek return (stcb);
1395 1.7.4.2 jdolecek }
1396 1.7.4.2 jdolecek /* all other cases... */
1397 1.7.4.2 jdolecek return (NULL);
1398 1.7.4.2 jdolecek }
1399 1.7.4.2 jdolecek
1400 1.7.4.2 jdolecek /*
1401 1.7.4.2 jdolecek * handle a state cookie for a new association
1402 1.7.4.2 jdolecek * m: input packet mbuf chain-- assumes a pullup on IP/SCTP/COOKIE-ECHO chunk
1403 1.7.4.2 jdolecek * note: this is a "split" mbuf and the cookie signature does not exist
1404 1.7.4.2 jdolecek * offset: offset into mbuf to the cookie-echo chunk
1405 1.7.4.2 jdolecek * length: length of the cookie chunk
1406 1.7.4.2 jdolecek * to: where the init was from
1407 1.7.4.2 jdolecek * returns a new TCB
1408 1.7.4.2 jdolecek */
1409 1.7.4.2 jdolecek static struct sctp_tcb *
1410 1.7.4.2 jdolecek sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
1411 1.7.4.2 jdolecek struct sctphdr *sh, struct sctp_state_cookie *cookie, int cookie_len,
1412 1.7.4.2 jdolecek struct sctp_inpcb *inp, struct sctp_nets **netp,
1413 1.7.4.2 jdolecek struct sockaddr *init_src, int *notification)
1414 1.7.4.2 jdolecek {
1415 1.7.4.2 jdolecek struct sctp_tcb *stcb;
1416 1.7.4.2 jdolecek struct sctp_init_chunk *init_cp, init_buf;
1417 1.7.4.2 jdolecek struct sctp_init_ack_chunk *initack_cp, initack_buf;
1418 1.7.4.2 jdolecek struct sockaddr_storage sa_store;
1419 1.7.4.2 jdolecek struct sockaddr *initack_src = (struct sockaddr *)&sa_store;
1420 1.7.4.2 jdolecek struct sockaddr_in *sin;
1421 1.7.4.2 jdolecek struct sockaddr_in6 *sin6;
1422 1.7.4.2 jdolecek struct sctp_association *asoc;
1423 1.7.4.2 jdolecek int chk_length;
1424 1.7.4.2 jdolecek int init_offset, initack_offset, initack_limit;
1425 1.7.4.2 jdolecek int retval;
1426 1.7.4.2 jdolecek int error = 0;
1427 1.7.4.2 jdolecek /*
1428 1.7.4.2 jdolecek * find and validate the INIT chunk in the cookie (peer's info)
1429 1.7.4.2 jdolecek * the INIT should start after the cookie-echo header struct
1430 1.7.4.2 jdolecek * (chunk header, state cookie header struct)
1431 1.7.4.2 jdolecek */
1432 1.7.4.2 jdolecek init_offset = offset + sizeof(struct sctp_cookie_echo_chunk);
1433 1.7.4.2 jdolecek init_cp = (struct sctp_init_chunk *)
1434 1.7.4.2 jdolecek sctp_m_getptr(m, init_offset, sizeof(struct sctp_init_chunk),
1435 1.7.4.2 jdolecek (u_int8_t *)&init_buf);
1436 1.7.4.2 jdolecek if (init_cp == NULL) {
1437 1.7.4.2 jdolecek /* could not pull a INIT chunk in cookie */
1438 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1439 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1440 1.7.4.2 jdolecek printf("process_cookie_new: could not pull INIT chunk hdr\n");
1441 1.7.4.2 jdolecek }
1442 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1443 1.7.4.2 jdolecek return (NULL);
1444 1.7.4.2 jdolecek }
1445 1.7.4.2 jdolecek chk_length = ntohs(init_cp->ch.chunk_length);
1446 1.7.4.2 jdolecek if (init_cp->ch.chunk_type != SCTP_INITIATION) {
1447 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1448 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1449 1.7.4.2 jdolecek printf("HUH? process_cookie_new: could not find INIT chunk!\n");
1450 1.7.4.2 jdolecek }
1451 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1452 1.7.4.2 jdolecek return (NULL);
1453 1.7.4.2 jdolecek }
1454 1.7.4.2 jdolecek
1455 1.7.4.2 jdolecek initack_offset = init_offset + SCTP_SIZE32(chk_length);
1456 1.7.4.2 jdolecek /*
1457 1.7.4.2 jdolecek * find and validate the INIT-ACK chunk in the cookie (my info)
1458 1.7.4.2 jdolecek * the INIT-ACK follows the INIT chunk
1459 1.7.4.2 jdolecek */
1460 1.7.4.2 jdolecek initack_cp = (struct sctp_init_ack_chunk *)
1461 1.7.4.2 jdolecek sctp_m_getptr(m, initack_offset, sizeof(struct sctp_init_ack_chunk),
1462 1.7.4.2 jdolecek (u_int8_t *)&initack_buf);
1463 1.7.4.2 jdolecek if (initack_cp == NULL) {
1464 1.7.4.2 jdolecek /* could not pull INIT-ACK chunk in cookie */
1465 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1466 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1467 1.7.4.2 jdolecek printf("process_cookie_new: could not pull INIT-ACK chunk hdr\n");
1468 1.7.4.2 jdolecek }
1469 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1470 1.7.4.2 jdolecek return (NULL);
1471 1.7.4.2 jdolecek }
1472 1.7.4.2 jdolecek chk_length = ntohs(initack_cp->ch.chunk_length);
1473 1.7.4.2 jdolecek if (initack_cp->ch.chunk_type != SCTP_INITIATION_ACK) {
1474 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1475 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1476 1.7.4.2 jdolecek u_int8_t *pp;
1477 1.7.4.2 jdolecek pp = (u_int8_t *)initack_cp;
1478 1.7.4.2 jdolecek printf("process_cookie_new: could not find INIT-ACK chunk!\n");
1479 1.7.4.2 jdolecek printf("Found bytes %x %x %x %x at postion %d\n",
1480 1.7.4.2 jdolecek (u_int)pp[0], (u_int)pp[1], (u_int)pp[2],
1481 1.7.4.2 jdolecek (u_int)pp[3], initack_offset);
1482 1.7.4.2 jdolecek }
1483 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1484 1.7.4.2 jdolecek return (NULL);
1485 1.7.4.2 jdolecek }
1486 1.7.4.2 jdolecek initack_limit = initack_offset + SCTP_SIZE32(chk_length);
1487 1.7.4.2 jdolecek
1488 1.7.4.2 jdolecek /*
1489 1.7.4.2 jdolecek * now that we know the INIT/INIT-ACK are in place,
1490 1.7.4.2 jdolecek * create a new TCB and popluate
1491 1.7.4.2 jdolecek */
1492 1.7.4.2 jdolecek stcb = sctp_aloc_assoc(inp, init_src, 0, &error, ntohl(initack_cp->init.initiate_tag));
1493 1.7.4.2 jdolecek if (stcb == NULL) {
1494 1.7.4.2 jdolecek struct mbuf *op_err;
1495 1.7.4.2 jdolecek /* memory problem? */
1496 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1497 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1498 1.7.4.2 jdolecek printf("process_cookie_new: no room for another TCB!\n");
1499 1.7.4.2 jdolecek }
1500 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1501 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC);
1502 1.7.4.2 jdolecek sctp_abort_association(inp, (struct sctp_tcb *)NULL, m, iphlen,
1503 1.7.4.2 jdolecek sh, op_err);
1504 1.7.4.2 jdolecek return (NULL);
1505 1.7.4.2 jdolecek }
1506 1.7.4.2 jdolecek
1507 1.7.4.2 jdolecek /* get the correct sctp_nets */
1508 1.7.4.2 jdolecek *netp = sctp_findnet(stcb, init_src);
1509 1.7.4.2 jdolecek asoc = &stcb->asoc;
1510 1.7.4.2 jdolecek /* get scope variables out of cookie */
1511 1.7.4.2 jdolecek asoc->ipv4_local_scope = cookie->ipv4_scope;
1512 1.7.4.2 jdolecek asoc->site_scope = cookie->site_scope;
1513 1.7.4.2 jdolecek asoc->local_scope = cookie->local_scope;
1514 1.7.4.2 jdolecek asoc->loopback_scope = cookie->loopback_scope;
1515 1.7.4.2 jdolecek
1516 1.7.4.2 jdolecek if ((asoc->ipv4_addr_legal != cookie->ipv4_addr_legal) ||
1517 1.7.4.2 jdolecek (asoc->ipv6_addr_legal != cookie->ipv6_addr_legal)) {
1518 1.7.4.2 jdolecek struct mbuf *op_err;
1519 1.7.4.2 jdolecek /*
1520 1.7.4.2 jdolecek * Houston we have a problem. The EP changed while the cookie
1521 1.7.4.2 jdolecek * was in flight. Only recourse is to abort the association.
1522 1.7.4.2 jdolecek */
1523 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC);
1524 1.7.4.2 jdolecek sctp_abort_association(inp, (struct sctp_tcb *)NULL, m, iphlen,
1525 1.7.4.2 jdolecek sh, op_err);
1526 1.7.4.2 jdolecek return (NULL);
1527 1.7.4.2 jdolecek }
1528 1.7.4.2 jdolecek
1529 1.7.4.2 jdolecek /* process the INIT-ACK info (my info) */
1530 1.7.4.2 jdolecek asoc->my_vtag = ntohl(initack_cp->init.initiate_tag);
1531 1.7.4.2 jdolecek asoc->my_rwnd = ntohl(initack_cp->init.a_rwnd);
1532 1.7.4.2 jdolecek asoc->pre_open_streams = ntohs(initack_cp->init.num_outbound_streams);
1533 1.7.4.2 jdolecek asoc->init_seq_number = ntohl(initack_cp->init.initial_tsn);
1534 1.7.4.2 jdolecek asoc->sending_seq = asoc->asconf_seq_out = asoc->str_reset_seq_out = asoc->init_seq_number;
1535 1.7.4.2 jdolecek asoc->t3timeout_highest_marked = asoc->asconf_seq_out;
1536 1.7.4.2 jdolecek asoc->last_cwr_tsn = asoc->init_seq_number - 1;
1537 1.7.4.2 jdolecek asoc->asconf_seq_in = asoc->last_acked_seq = asoc->init_seq_number - 1;
1538 1.7.4.2 jdolecek asoc->str_reset_seq_in = asoc->init_seq_number;
1539 1.7.4.2 jdolecek
1540 1.7.4.2 jdolecek asoc->advanced_peer_ack_point = asoc->last_acked_seq;
1541 1.7.4.2 jdolecek
1542 1.7.4.2 jdolecek /* process the INIT info (peer's info) */
1543 1.7.4.2 jdolecek retval = sctp_process_init(init_cp, stcb, *netp);
1544 1.7.4.2 jdolecek if (retval < 0) {
1545 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1546 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1547 1.7.4.2 jdolecek printf("process_cookie_new: INIT processing failed\n");
1548 1.7.4.2 jdolecek }
1549 1.7.4.2 jdolecek #endif
1550 1.7.4.2 jdolecek sctp_free_assoc(inp, stcb);
1551 1.7.4.2 jdolecek return (NULL);
1552 1.7.4.2 jdolecek }
1553 1.7.4.2 jdolecek /* load all addresses */
1554 1.7.4.2 jdolecek if (sctp_load_addresses_from_init(stcb, m, iphlen,
1555 1.7.4.2 jdolecek init_offset + sizeof(struct sctp_init_chunk), initack_offset, sh,
1556 1.7.4.2 jdolecek init_src)) {
1557 1.7.4.2 jdolecek sctp_free_assoc(inp, stcb);
1558 1.7.4.2 jdolecek return (NULL);
1559 1.7.4.2 jdolecek }
1560 1.7.4.2 jdolecek
1561 1.7.4.2 jdolecek /* update current state */
1562 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1563 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1564 1.7.4.2 jdolecek printf("moving to OPEN state\n");
1565 1.7.4.2 jdolecek }
1566 1.7.4.2 jdolecek #endif
1567 1.7.4.2 jdolecek if (asoc->state & SCTP_STATE_SHUTDOWN_PENDING) {
1568 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN | SCTP_STATE_SHUTDOWN_PENDING;
1569 1.7.4.2 jdolecek } else {
1570 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN;
1571 1.7.4.2 jdolecek }
1572 1.7.4.2 jdolecek /* calculate the RTT */
1573 1.7.4.2 jdolecek (*netp)->RTO = sctp_calculate_rto(stcb, asoc, *netp,
1574 1.7.4.2 jdolecek &cookie->time_entered);
1575 1.7.4.2 jdolecek
1576 1.7.4.2 jdolecek /*
1577 1.7.4.2 jdolecek * if we're doing ASCONFs, check to see if we have any new
1578 1.7.4.2 jdolecek * local addresses that need to get added to the peer (eg.
1579 1.7.4.2 jdolecek * addresses changed while cookie echo in flight). This needs
1580 1.7.4.2 jdolecek * to be done after we go to the OPEN state to do the correct
1581 1.7.4.2 jdolecek * asconf processing.
1582 1.7.4.2 jdolecek * else, make sure we have the correct addresses in our lists
1583 1.7.4.2 jdolecek */
1584 1.7.4.2 jdolecek
1585 1.7.4.2 jdolecek /* warning, we re-use sin, sin6, sa_store here! */
1586 1.7.4.2 jdolecek /* pull in local_address (our "from" address) */
1587 1.7.4.2 jdolecek if (cookie->laddr_type == SCTP_IPV4_ADDRESS) {
1588 1.7.4.2 jdolecek /* source addr is IPv4 */
1589 1.7.4.2 jdolecek sin = (struct sockaddr_in *)initack_src;
1590 1.7.4.2 jdolecek memset(sin, 0, sizeof(*sin));
1591 1.7.4.2 jdolecek sin->sin_family = AF_INET;
1592 1.7.4.2 jdolecek sin->sin_len = sizeof(struct sockaddr_in);
1593 1.7.4.2 jdolecek sin->sin_addr.s_addr = cookie->laddress[0];
1594 1.7.4.2 jdolecek } else if (cookie->laddr_type == SCTP_IPV6_ADDRESS) {
1595 1.7.4.2 jdolecek /* source addr is IPv6 */
1596 1.7.4.2 jdolecek sin6 = (struct sockaddr_in6 *)initack_src;
1597 1.7.4.2 jdolecek memset(sin6, 0, sizeof(*sin6));
1598 1.7.4.2 jdolecek sin6->sin6_family = AF_INET6;
1599 1.7.4.2 jdolecek sin6->sin6_len = sizeof(struct sockaddr_in6);
1600 1.7.4.2 jdolecek sin6->sin6_scope_id = cookie->scope_id;
1601 1.7.4.2 jdolecek memcpy(&sin6->sin6_addr, cookie->laddress,
1602 1.7.4.2 jdolecek sizeof(sin6->sin6_addr));
1603 1.7.4.2 jdolecek } else {
1604 1.7.4.2 jdolecek sctp_free_assoc(inp, stcb);
1605 1.7.4.2 jdolecek return (NULL);
1606 1.7.4.2 jdolecek }
1607 1.7.4.2 jdolecek
1608 1.7.4.2 jdolecek sctp_check_address_list(stcb, m, initack_offset +
1609 1.7.4.2 jdolecek sizeof(struct sctp_init_ack_chunk), initack_limit,
1610 1.7.4.2 jdolecek initack_src, cookie->local_scope, cookie->site_scope,
1611 1.7.4.2 jdolecek cookie->ipv4_scope, cookie->loopback_scope);
1612 1.7.4.2 jdolecek
1613 1.7.4.2 jdolecek
1614 1.7.4.2 jdolecek /* set up to notify upper layer */
1615 1.7.4.2 jdolecek *notification = SCTP_NOTIFY_ASSOC_UP;
1616 1.7.4.2 jdolecek if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
1617 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) &&
1618 1.7.4.2 jdolecek !(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING)) {
1619 1.7.4.2 jdolecek /*
1620 1.7.4.2 jdolecek * This is an endpoint that called connect()
1621 1.7.4.2 jdolecek * how it got a cookie that is NEW is a bit of
1622 1.7.4.2 jdolecek * a mystery. It must be that the INIT was sent, but
1623 1.7.4.2 jdolecek * before it got there.. a complete INIT/INIT-ACK/COOKIE
1624 1.7.4.2 jdolecek * arrived. But of course then it should have went to
1625 1.7.4.2 jdolecek * the other code.. not here.. oh well.. a bit of protection
1626 1.7.4.2 jdolecek * is worth having..
1627 1.7.4.2 jdolecek */
1628 1.7.4.2 jdolecek stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
1629 1.7.4.2 jdolecek soisconnected(stcb->sctp_ep->sctp_socket);
1630 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, *netp);
1631 1.7.4.2 jdolecek } else if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
1632 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING)) {
1633 1.7.4.2 jdolecek /*
1634 1.7.4.2 jdolecek * We don't want to do anything with this
1635 1.7.4.2 jdolecek * one. Since it is the listening guy. The timer will
1636 1.7.4.2 jdolecek * get started for accepted connections in the caller.
1637 1.7.4.2 jdolecek */
1638 1.7.4.2 jdolecek ;
1639 1.7.4.2 jdolecek } else {
1640 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, *netp);
1641 1.7.4.2 jdolecek }
1642 1.7.4.2 jdolecek /* since we did not send a HB make sure we don't double things */
1643 1.7.4.2 jdolecek (*netp)->hb_responded = 1;
1644 1.7.4.2 jdolecek
1645 1.7.4.2 jdolecek if (stcb->asoc.sctp_autoclose_ticks &&
1646 1.7.4.2 jdolecek (inp->sctp_flags & SCTP_PCB_FLAGS_AUTOCLOSE)) {
1647 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb, NULL);
1648 1.7.4.2 jdolecek }
1649 1.7.4.2 jdolecek
1650 1.7.4.2 jdolecek /* respond with a COOKIE-ACK */
1651 1.7.4.2 jdolecek sctp_send_cookie_ack(stcb);
1652 1.7.4.2 jdolecek
1653 1.7.4.2 jdolecek return (stcb);
1654 1.7.4.2 jdolecek }
1655 1.7.4.2 jdolecek
1656 1.7.4.2 jdolecek
1657 1.7.4.2 jdolecek /*
1658 1.7.4.2 jdolecek * handles a COOKIE-ECHO message
1659 1.7.4.2 jdolecek * stcb: modified to either a new or left as existing (non-NULL) TCB
1660 1.7.4.2 jdolecek */
1661 1.7.4.2 jdolecek static struct mbuf *
1662 1.7.4.2 jdolecek sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
1663 1.7.4.2 jdolecek struct sctphdr *sh, struct sctp_cookie_echo_chunk *cp,
1664 1.7.4.2 jdolecek struct sctp_inpcb **inp_p, struct sctp_tcb **stcb, struct sctp_nets **netp)
1665 1.7.4.2 jdolecek {
1666 1.7.4.2 jdolecek struct sctp_state_cookie *cookie;
1667 1.7.4.2 jdolecek struct sockaddr_in6 sin6;
1668 1.7.4.2 jdolecek struct sockaddr_in sin;
1669 1.7.4.2 jdolecek struct sctp_tcb *l_stcb=*stcb;
1670 1.7.4.2 jdolecek struct sctp_inpcb *l_inp;
1671 1.7.4.2 jdolecek struct sockaddr *to;
1672 1.7.4.2 jdolecek struct sctp_pcb *ep;
1673 1.7.4.2 jdolecek struct mbuf *m_sig;
1674 1.7.4.2 jdolecek uint8_t calc_sig[SCTP_SIGNATURE_SIZE], tmp_sig[SCTP_SIGNATURE_SIZE];
1675 1.7.4.2 jdolecek uint8_t *sig;
1676 1.7.4.2 jdolecek uint8_t cookie_ok = 0;
1677 1.7.4.2 jdolecek unsigned int size_of_pkt, sig_offset, cookie_offset;
1678 1.7.4.2 jdolecek unsigned int cookie_len;
1679 1.7.4.2 jdolecek struct timeval now;
1680 1.7.4.2 jdolecek struct timeval time_expires;
1681 1.7.4.2 jdolecek struct sockaddr_storage dest_store;
1682 1.7.4.2 jdolecek struct sockaddr *localep_sa = (struct sockaddr *)&dest_store;
1683 1.7.4.2 jdolecek struct ip *iph;
1684 1.7.4.2 jdolecek int notification = 0;
1685 1.7.4.2 jdolecek struct sctp_nets *netl;
1686 1.7.4.2 jdolecek int had_a_existing_tcb = 0;
1687 1.7.4.2 jdolecek
1688 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1689 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1690 1.7.4.2 jdolecek printf("sctp_handle_cookie: handling COOKIE-ECHO\n");
1691 1.7.4.2 jdolecek }
1692 1.7.4.2 jdolecek #endif
1693 1.7.4.2 jdolecek
1694 1.7.4.2 jdolecek if (inp_p == NULL) {
1695 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1696 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1697 1.7.4.2 jdolecek printf("sctp_handle_cookie: null inp_p!\n");
1698 1.7.4.2 jdolecek }
1699 1.7.4.2 jdolecek #endif
1700 1.7.4.2 jdolecek return (NULL);
1701 1.7.4.2 jdolecek }
1702 1.7.4.2 jdolecek /* First get the destination address setup too. */
1703 1.7.4.2 jdolecek iph = mtod(m, struct ip *);
1704 1.7.4.2 jdolecek if (iph->ip_v == IPVERSION) {
1705 1.7.4.2 jdolecek /* its IPv4 */
1706 1.7.4.2 jdolecek struct sockaddr_in *sin_d;
1707 1.7.4.2 jdolecek sin_d = (struct sockaddr_in *)(localep_sa);
1708 1.7.4.2 jdolecek memset(sin_d, 0, sizeof(*sin_d));
1709 1.7.4.2 jdolecek sin_d->sin_family = AF_INET;
1710 1.7.4.2 jdolecek sin_d->sin_len = sizeof(*sin_d);
1711 1.7.4.2 jdolecek sin_d->sin_port = sh->dest_port;
1712 1.7.4.2 jdolecek sin_d->sin_addr.s_addr = iph->ip_dst.s_addr ;
1713 1.7.4.2 jdolecek } else if (iph->ip_v == (IPV6_VERSION >> 4)) {
1714 1.7.4.2 jdolecek /* its IPv6 */
1715 1.7.4.2 jdolecek struct ip6_hdr *ip6;
1716 1.7.4.2 jdolecek struct sockaddr_in6 *sin6_d;
1717 1.7.4.2 jdolecek sin6_d = (struct sockaddr_in6 *)(localep_sa);
1718 1.7.4.2 jdolecek memset(sin6_d, 0, sizeof(*sin6_d));
1719 1.7.4.2 jdolecek sin6_d->sin6_family = AF_INET6;
1720 1.7.4.2 jdolecek sin6_d->sin6_len = sizeof(struct sockaddr_in6);
1721 1.7.4.2 jdolecek ip6 = mtod(m, struct ip6_hdr *);
1722 1.7.4.2 jdolecek sin6_d->sin6_port = sh->dest_port;
1723 1.7.4.2 jdolecek sin6_d->sin6_addr = ip6->ip6_dst;
1724 1.7.4.2 jdolecek } else {
1725 1.7.4.2 jdolecek return (NULL);
1726 1.7.4.2 jdolecek }
1727 1.7.4.2 jdolecek
1728 1.7.4.2 jdolecek cookie = &cp->cookie;
1729 1.7.4.2 jdolecek cookie_offset = offset + sizeof(struct sctp_chunkhdr);
1730 1.7.4.2 jdolecek cookie_len = ntohs(cp->ch.chunk_length);
1731 1.7.4.2 jdolecek
1732 1.7.4.2 jdolecek /* compute size of packet */
1733 1.7.4.2 jdolecek if (m->m_flags & M_PKTHDR) {
1734 1.7.4.2 jdolecek size_of_pkt = m->m_pkthdr.len;
1735 1.7.4.2 jdolecek } else {
1736 1.7.4.2 jdolecek /* Should have a pkt hdr really */
1737 1.7.4.2 jdolecek struct mbuf *mat;
1738 1.7.4.2 jdolecek mat = m;
1739 1.7.4.2 jdolecek size_of_pkt = 0;
1740 1.7.4.2 jdolecek while (mat != NULL) {
1741 1.7.4.2 jdolecek size_of_pkt += mat->m_len;
1742 1.7.4.2 jdolecek mat = mat->m_next;
1743 1.7.4.2 jdolecek }
1744 1.7.4.2 jdolecek }
1745 1.7.4.2 jdolecek if (cookie_len > size_of_pkt ||
1746 1.7.4.2 jdolecek cookie_len < sizeof(struct sctp_cookie_echo_chunk) +
1747 1.7.4.2 jdolecek sizeof(struct sctp_init_chunk) +
1748 1.7.4.2 jdolecek sizeof(struct sctp_init_ack_chunk) + SCTP_SIGNATURE_SIZE) {
1749 1.7.4.2 jdolecek /* cookie too long! or too small */
1750 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1751 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1752 1.7.4.2 jdolecek printf("sctp_handle_cookie: cookie_len=%u, pkt size=%u\n", cookie_len, size_of_pkt);
1753 1.7.4.2 jdolecek }
1754 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
1755 1.7.4.2 jdolecek return (NULL);
1756 1.7.4.2 jdolecek }
1757 1.7.4.2 jdolecek
1758 1.7.4.2 jdolecek if ((cookie->peerport != sh->src_port) &&
1759 1.7.4.2 jdolecek (cookie->myport != sh->dest_port) &&
1760 1.7.4.2 jdolecek (cookie->my_vtag != sh->v_tag)) {
1761 1.7.4.2 jdolecek /*
1762 1.7.4.2 jdolecek * invalid ports or bad tag. Note that we always leave
1763 1.7.4.2 jdolecek * the v_tag in the header in network order and when we
1764 1.7.4.2 jdolecek * stored it in the my_vtag slot we also left it in network
1765 1.7.4.2 jdolecek * order. This maintians the match even though it may be in
1766 1.7.4.2 jdolecek * the opposite byte order of the machine :->
1767 1.7.4.2 jdolecek */
1768 1.7.4.2 jdolecek return (NULL);
1769 1.7.4.2 jdolecek }
1770 1.7.4.2 jdolecek
1771 1.7.4.2 jdolecek /*
1772 1.7.4.2 jdolecek * split off the signature into its own mbuf (since it
1773 1.7.4.2 jdolecek * should not be calculated in the sctp_hash_digest_m() call).
1774 1.7.4.2 jdolecek */
1775 1.7.4.2 jdolecek sig_offset = offset + cookie_len - SCTP_SIGNATURE_SIZE;
1776 1.7.4.2 jdolecek if (sig_offset > size_of_pkt) {
1777 1.7.4.2 jdolecek /* packet not correct size! */
1778 1.7.4.2 jdolecek /* XXX this may already be accounted for earlier... */
1779 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1780 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1781 1.7.4.2 jdolecek printf("sctp_handle_cookie: sig offset=%u, pkt size=%u\n", sig_offset, size_of_pkt);
1782 1.7.4.2 jdolecek }
1783 1.7.4.2 jdolecek #endif
1784 1.7.4.2 jdolecek return (NULL);
1785 1.7.4.2 jdolecek }
1786 1.7.4.2 jdolecek
1787 1.7.4.2 jdolecek m_sig = m_split(m, sig_offset, M_DONTWAIT);
1788 1.7.4.2 jdolecek if (m_sig == NULL) {
1789 1.7.4.2 jdolecek /* out of memory or ?? */
1790 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1791 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1792 1.7.4.2 jdolecek printf("sctp_handle_cookie: couldn't m_split the signature\n");
1793 1.7.4.2 jdolecek }
1794 1.7.4.2 jdolecek #endif
1795 1.7.4.2 jdolecek return (NULL);
1796 1.7.4.2 jdolecek }
1797 1.7.4.2 jdolecek /*
1798 1.7.4.2 jdolecek * compute the signature/digest for the cookie
1799 1.7.4.2 jdolecek */
1800 1.7.4.2 jdolecek ep = &(*inp_p)->sctp_ep;
1801 1.7.4.2 jdolecek l_inp = *inp_p;
1802 1.7.4.2 jdolecek if (l_stcb) {
1803 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(l_stcb);
1804 1.7.4.2 jdolecek }
1805 1.7.4.2 jdolecek SCTP_INP_RLOCK(l_inp);
1806 1.7.4.2 jdolecek if (l_stcb) {
1807 1.7.4.2 jdolecek SCTP_TCB_LOCK(l_stcb);
1808 1.7.4.2 jdolecek }
1809 1.7.4.2 jdolecek /* which cookie is it? */
1810 1.7.4.2 jdolecek if ((cookie->time_entered.tv_sec < (long)ep->time_of_secret_change) &&
1811 1.7.4.2 jdolecek (ep->current_secret_number != ep->last_secret_number)) {
1812 1.7.4.2 jdolecek /* it's the old cookie */
1813 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1814 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1815 1.7.4.2 jdolecek printf("sctp_handle_cookie: old cookie sig\n");
1816 1.7.4.2 jdolecek }
1817 1.7.4.2 jdolecek #endif
1818 1.7.4.2 jdolecek sctp_hash_digest_m((char *)ep->secret_key[(int)ep->last_secret_number],
1819 1.7.4.2 jdolecek SCTP_SECRET_SIZE, m, cookie_offset, calc_sig);
1820 1.7.4.2 jdolecek } else {
1821 1.7.4.2 jdolecek /* it's the current cookie */
1822 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1823 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1824 1.7.4.2 jdolecek printf("sctp_handle_cookie: current cookie sig\n");
1825 1.7.4.2 jdolecek }
1826 1.7.4.2 jdolecek #endif
1827 1.7.4.2 jdolecek sctp_hash_digest_m((char *)ep->secret_key[(int)ep->current_secret_number],
1828 1.7.4.2 jdolecek SCTP_SECRET_SIZE, m, cookie_offset, calc_sig);
1829 1.7.4.2 jdolecek }
1830 1.7.4.2 jdolecek /* get the signature */
1831 1.7.4.2 jdolecek SCTP_INP_RUNLOCK(l_inp);
1832 1.7.4.2 jdolecek sig = (u_int8_t *)sctp_m_getptr(m_sig, 0, SCTP_SIGNATURE_SIZE, (u_int8_t *)&tmp_sig);
1833 1.7.4.2 jdolecek if (sig == NULL) {
1834 1.7.4.2 jdolecek /* couldn't find signature */
1835 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1836 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
1837 1.7.4.2 jdolecek printf("sctp_handle_cookie: couldn't pull the signature\n");
1838 1.7.4.2 jdolecek }
1839 1.7.4.2 jdolecek #endif
1840 1.7.4.2 jdolecek return (NULL);
1841 1.7.4.2 jdolecek }
1842 1.7.4.2 jdolecek /* compare the received digest with the computed digest */
1843 1.7.4.2 jdolecek if (memcmp(calc_sig, sig, SCTP_SIGNATURE_SIZE) != 0) {
1844 1.7.4.2 jdolecek /* try the old cookie? */
1845 1.7.4.2 jdolecek if ((cookie->time_entered.tv_sec == (long)ep->time_of_secret_change) &&
1846 1.7.4.2 jdolecek (ep->current_secret_number != ep->last_secret_number)) {
1847 1.7.4.2 jdolecek /* compute digest with old */
1848 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1849 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1850 1.7.4.2 jdolecek printf("sctp_handle_cookie: old cookie sig\n");
1851 1.7.4.2 jdolecek }
1852 1.7.4.2 jdolecek #endif
1853 1.7.4.2 jdolecek sctp_hash_digest_m((char *)ep->secret_key[(int)ep->last_secret_number],
1854 1.7.4.2 jdolecek SCTP_SECRET_SIZE, m, cookie_offset, calc_sig);
1855 1.7.4.2 jdolecek /* compare */
1856 1.7.4.2 jdolecek if (memcmp(calc_sig, sig, SCTP_SIGNATURE_SIZE) == 0)
1857 1.7.4.2 jdolecek cookie_ok = 1;
1858 1.7.4.2 jdolecek }
1859 1.7.4.2 jdolecek } else {
1860 1.7.4.2 jdolecek cookie_ok = 1;
1861 1.7.4.2 jdolecek }
1862 1.7.4.2 jdolecek
1863 1.7.4.2 jdolecek /*
1864 1.7.4.2 jdolecek * Now before we continue we must reconstruct our mbuf so
1865 1.7.4.2 jdolecek * that normal processing of any other chunks will work.
1866 1.7.4.2 jdolecek */
1867 1.7.4.2 jdolecek {
1868 1.7.4.2 jdolecek struct mbuf *m_at;
1869 1.7.4.2 jdolecek m_at = m;
1870 1.7.4.2 jdolecek while (m_at->m_next != NULL) {
1871 1.7.4.2 jdolecek m_at = m_at->m_next;
1872 1.7.4.2 jdolecek }
1873 1.7.4.2 jdolecek m_at->m_next = m_sig;
1874 1.7.4.2 jdolecek if (m->m_flags & M_PKTHDR) {
1875 1.7.4.2 jdolecek /*
1876 1.7.4.2 jdolecek * We should only do this if and only if the front
1877 1.7.4.2 jdolecek * mbuf has a m_pkthdr... it should in theory.
1878 1.7.4.2 jdolecek */
1879 1.7.4.2 jdolecek if (m_sig->m_flags & M_PKTHDR) {
1880 1.7.4.2 jdolecek /* Add back to the pkt hdr of main m chain */
1881 1.7.4.2 jdolecek m->m_pkthdr.len += m_sig->m_len;
1882 1.7.4.2 jdolecek } else {
1883 1.7.4.2 jdolecek /*
1884 1.7.4.2 jdolecek * Got a problem, no pkthdr in split chain.
1885 1.7.4.2 jdolecek * TSNH but we will handle it just in case
1886 1.7.4.2 jdolecek */
1887 1.7.4.2 jdolecek int mmlen = 0;
1888 1.7.4.2 jdolecek struct mbuf *lat;
1889 1.7.4.2 jdolecek printf("Warning: Hitting m_split join TSNH code - fixed\n");
1890 1.7.4.2 jdolecek lat = m_sig;
1891 1.7.4.2 jdolecek while (lat) {
1892 1.7.4.2 jdolecek mmlen += lat->m_len;
1893 1.7.4.2 jdolecek lat = lat->m_next;
1894 1.7.4.2 jdolecek }
1895 1.7.4.2 jdolecek m->m_pkthdr.len += mmlen;
1896 1.7.4.2 jdolecek }
1897 1.7.4.2 jdolecek }
1898 1.7.4.2 jdolecek }
1899 1.7.4.2 jdolecek
1900 1.7.4.2 jdolecek if (cookie_ok == 0) {
1901 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1902 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1903 1.7.4.2 jdolecek printf("handle_cookie_echo: cookie signature validation failed!\n");
1904 1.7.4.2 jdolecek printf("offset = %u, cookie_offset = %u, sig_offset = %u\n",
1905 1.7.4.2 jdolecek (u_int32_t)offset, cookie_offset, sig_offset);
1906 1.7.4.2 jdolecek }
1907 1.7.4.2 jdolecek #endif
1908 1.7.4.2 jdolecek return (NULL);
1909 1.7.4.2 jdolecek }
1910 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1911 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
1912 1.7.4.2 jdolecek printf("handle_cookie_echo: cookie signature validation passed\n");
1913 1.7.4.2 jdolecek }
1914 1.7.4.2 jdolecek #endif
1915 1.7.4.2 jdolecek
1916 1.7.4.2 jdolecek /*
1917 1.7.4.2 jdolecek * check the cookie timestamps to be sure it's not stale
1918 1.7.4.2 jdolecek */
1919 1.7.4.2 jdolecek SCTP_GETTIME_TIMEVAL(&now);
1920 1.7.4.2 jdolecek /* Expire time is in Ticks, so we convert to seconds */
1921 1.7.4.2 jdolecek time_expires.tv_sec = cookie->time_entered.tv_sec + cookie->cookie_life;
1922 1.7.4.2 jdolecek time_expires.tv_usec = cookie->time_entered.tv_usec;
1923 1.7.4.2 jdolecek #ifndef __FreeBSD__
1924 1.7.4.2 jdolecek if (timercmp(&now, &time_expires, >))
1925 1.7.4.2 jdolecek #else
1926 1.7.4.2 jdolecek if (timevalcmp(&now, &time_expires, >))
1927 1.7.4.2 jdolecek #endif
1928 1.7.4.2 jdolecek {
1929 1.7.4.2 jdolecek /* cookie is stale! */
1930 1.7.4.2 jdolecek struct mbuf *op_err;
1931 1.7.4.2 jdolecek struct sctp_stale_cookie_msg *scm;
1932 1.7.4.2 jdolecek u_int32_t tim;
1933 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
1934 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
1935 1.7.4.2 jdolecek printf("sctp_handle_cookie: got a STALE cookie!\n");
1936 1.7.4.2 jdolecek }
1937 1.7.4.2 jdolecek #endif
1938 1.7.4.2 jdolecek MGETHDR(op_err, M_DONTWAIT, MT_HEADER);
1939 1.7.4.2 jdolecek if (op_err == NULL) {
1940 1.7.4.2 jdolecek /* FOOBAR */
1941 1.7.4.2 jdolecek return (NULL);
1942 1.7.4.2 jdolecek }
1943 1.7.4.2 jdolecek /* pre-reserve some space */
1944 1.7.4.2 jdolecek op_err->m_data += sizeof(struct ip6_hdr);
1945 1.7.4.2 jdolecek op_err->m_data += sizeof(struct sctphdr);
1946 1.7.4.2 jdolecek op_err->m_data += sizeof(struct sctp_chunkhdr);
1947 1.7.4.2 jdolecek
1948 1.7.4.2 jdolecek /* Set the len */
1949 1.7.4.2 jdolecek op_err->m_len = op_err->m_pkthdr.len = sizeof(struct sctp_stale_cookie_msg);
1950 1.7.4.2 jdolecek scm = mtod(op_err, struct sctp_stale_cookie_msg *);
1951 1.7.4.2 jdolecek scm->ph.param_type = htons(SCTP_CAUSE_STALE_COOKIE);
1952 1.7.4.2 jdolecek scm->ph.param_length = htons((sizeof(struct sctp_paramhdr) +
1953 1.7.4.2 jdolecek (sizeof(u_int32_t))));
1954 1.7.4.2 jdolecek /* seconds to usec */
1955 1.7.4.2 jdolecek tim = (now.tv_sec - time_expires.tv_sec) * 1000000;
1956 1.7.4.2 jdolecek /* add in usec */
1957 1.7.4.2 jdolecek if (tim == 0)
1958 1.7.4.2 jdolecek tim = now.tv_usec - cookie->time_entered.tv_usec;
1959 1.7.4.2 jdolecek scm->time_usec = htonl(tim);
1960 1.7.4.2 jdolecek sctp_send_operr_to(m, iphlen, op_err, cookie->peers_vtag);
1961 1.7.4.2 jdolecek return (NULL);
1962 1.7.4.2 jdolecek }
1963 1.7.4.2 jdolecek /*
1964 1.7.4.2 jdolecek * Now we must see with the lookup address if we have an existing
1965 1.7.4.2 jdolecek * asoc. This will only happen if we were in the COOKIE-WAIT state
1966 1.7.4.2 jdolecek * and a INIT collided with us and somewhere the peer sent the
1967 1.7.4.2 jdolecek * cookie on another address besides the single address our assoc
1968 1.7.4.2 jdolecek * had for him. In this case we will have one of the tie-tags set
1969 1.7.4.2 jdolecek * at least AND the address field in the cookie can be used to
1970 1.7.4.2 jdolecek * look it up.
1971 1.7.4.2 jdolecek */
1972 1.7.4.2 jdolecek to = NULL;
1973 1.7.4.2 jdolecek if (cookie->addr_type == SCTP_IPV6_ADDRESS) {
1974 1.7.4.2 jdolecek memset(&sin6, 0, sizeof(sin6));
1975 1.7.4.2 jdolecek sin6.sin6_family = AF_INET6;
1976 1.7.4.2 jdolecek sin6.sin6_len = sizeof(sin6);
1977 1.7.4.2 jdolecek sin6.sin6_port = sh->src_port;
1978 1.7.4.2 jdolecek sin6.sin6_scope_id = cookie->scope_id;
1979 1.7.4.2 jdolecek memcpy(&sin6.sin6_addr.s6_addr, cookie->address,
1980 1.7.4.2 jdolecek sizeof(sin6.sin6_addr.s6_addr));
1981 1.7.4.2 jdolecek to = (struct sockaddr *)&sin6;
1982 1.7.4.2 jdolecek } else if (cookie->addr_type == SCTP_IPV4_ADDRESS) {
1983 1.7.4.2 jdolecek memset(&sin, 0, sizeof(sin));
1984 1.7.4.2 jdolecek sin.sin_family = AF_INET;
1985 1.7.4.2 jdolecek sin.sin_len = sizeof(sin);
1986 1.7.4.2 jdolecek sin.sin_port = sh->src_port;
1987 1.7.4.2 jdolecek sin.sin_addr.s_addr = cookie->address[0];
1988 1.7.4.2 jdolecek to = (struct sockaddr *)&sin;
1989 1.7.4.2 jdolecek }
1990 1.7.4.2 jdolecek
1991 1.7.4.2 jdolecek if ((*stcb == NULL) && to) {
1992 1.7.4.2 jdolecek /* Yep, lets check */
1993 1.7.4.2 jdolecek *stcb = sctp_findassociation_ep_addr(inp_p, to, netp, localep_sa, NULL);
1994 1.7.4.2 jdolecek if (*stcb == NULL) {
1995 1.7.4.2 jdolecek /* We should have only got back the same inp. If we
1996 1.7.4.2 jdolecek * got back a different ep we have a problem. The original
1997 1.7.4.2 jdolecek * findep got back l_inp and now
1998 1.7.4.2 jdolecek */
1999 1.7.4.2 jdolecek if (l_inp != *inp_p) {
2000 1.7.4.2 jdolecek printf("Bad problem find_ep got a diff inp then special_locate?\n");
2001 1.7.4.2 jdolecek }
2002 1.7.4.2 jdolecek }
2003 1.7.4.2 jdolecek }
2004 1.7.4.2 jdolecek
2005 1.7.4.2 jdolecek cookie_len -= SCTP_SIGNATURE_SIZE;
2006 1.7.4.2 jdolecek if (*stcb == NULL) {
2007 1.7.4.2 jdolecek /* this is the "normal" case... get a new TCB */
2008 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2009 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
2010 1.7.4.2 jdolecek printf("sctp_handle_cookie: processing NEW cookie\n");
2011 1.7.4.2 jdolecek }
2012 1.7.4.2 jdolecek #endif
2013 1.7.4.2 jdolecek *stcb = sctp_process_cookie_new(m, iphlen, offset, sh, cookie,
2014 1.7.4.2 jdolecek cookie_len, *inp_p, netp, to, ¬ification);
2015 1.7.4.2 jdolecek /* now always decrement, since this is the normal
2016 1.7.4.2 jdolecek * case.. we had no tcb when we entered.
2017 1.7.4.2 jdolecek */
2018 1.7.4.2 jdolecek } else {
2019 1.7.4.2 jdolecek /* this is abnormal... cookie-echo on existing TCB */
2020 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2021 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
2022 1.7.4.2 jdolecek printf("sctp_handle_cookie: processing EXISTING cookie\n");
2023 1.7.4.2 jdolecek }
2024 1.7.4.2 jdolecek #endif
2025 1.7.4.2 jdolecek had_a_existing_tcb = 1;
2026 1.7.4.2 jdolecek *stcb = sctp_process_cookie_existing(m, iphlen, offset, sh,
2027 1.7.4.2 jdolecek cookie, cookie_len, *inp_p, *stcb, *netp, to, ¬ification);
2028 1.7.4.2 jdolecek }
2029 1.7.4.2 jdolecek
2030 1.7.4.2 jdolecek if (*stcb == NULL) {
2031 1.7.4.2 jdolecek /* still no TCB... must be bad cookie-echo */
2032 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2033 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
2034 1.7.4.2 jdolecek printf("handle_cookie_echo: ACK! don't have a TCB!\n");
2035 1.7.4.2 jdolecek }
2036 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
2037 1.7.4.2 jdolecek return (NULL);
2038 1.7.4.2 jdolecek }
2039 1.7.4.2 jdolecek
2040 1.7.4.2 jdolecek /*
2041 1.7.4.2 jdolecek * Ok, we built an association so confirm the address
2042 1.7.4.2 jdolecek * we sent the INIT-ACK to.
2043 1.7.4.2 jdolecek */
2044 1.7.4.2 jdolecek netl = sctp_findnet(*stcb, to);
2045 1.7.4.2 jdolecek /* This code should in theory NOT run but
2046 1.7.4.2 jdolecek */
2047 1.7.4.2 jdolecek if (netl == NULL) {
2048 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2049 1.7.4.2 jdolecek printf("TSNH! Huh, why do I need to add this address here?\n");
2050 1.7.4.2 jdolecek #endif
2051 1.7.4.2 jdolecek sctp_add_remote_addr(*stcb, to, 0, 100);
2052 1.7.4.2 jdolecek netl = sctp_findnet(*stcb, to);
2053 1.7.4.2 jdolecek }
2054 1.7.4.2 jdolecek if (netl) {
2055 1.7.4.2 jdolecek if (netl->dest_state & SCTP_ADDR_UNCONFIRMED) {
2056 1.7.4.2 jdolecek netl->dest_state &= ~SCTP_ADDR_UNCONFIRMED;
2057 1.7.4.2 jdolecek sctp_set_primary_addr((*stcb), (struct sockaddr *)NULL,
2058 1.7.4.2 jdolecek netl);
2059 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_CONFIRMED,
2060 1.7.4.2 jdolecek (*stcb), 0, (void *)netl);
2061 1.7.4.2 jdolecek }
2062 1.7.4.2 jdolecek }
2063 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2064 1.7.4.2 jdolecek else {
2065 1.7.4.2 jdolecek printf("Could not add source address for some reason\n");
2066 1.7.4.2 jdolecek }
2067 1.7.4.2 jdolecek #endif
2068 1.7.4.2 jdolecek
2069 1.7.4.2 jdolecek if ((*inp_p)->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
2070 1.7.4.2 jdolecek if (!had_a_existing_tcb ||
2071 1.7.4.2 jdolecek (((*inp_p)->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
2072 1.7.4.2 jdolecek /*
2073 1.7.4.2 jdolecek * If we have a NEW cookie or the connect never reached
2074 1.7.4.2 jdolecek * the connected state during collision we must do the
2075 1.7.4.2 jdolecek * TCP accept thing.
2076 1.7.4.2 jdolecek */
2077 1.7.4.2 jdolecek struct socket *so, *oso;
2078 1.7.4.2 jdolecek struct sctp_inpcb *inp;
2079 1.7.4.2 jdolecek if (notification == SCTP_NOTIFY_ASSOC_RESTART) {
2080 1.7.4.2 jdolecek /*
2081 1.7.4.2 jdolecek * For a restart we will keep the same socket,
2082 1.7.4.2 jdolecek * no need to do anything. I THINK!!
2083 1.7.4.2 jdolecek */
2084 1.7.4.2 jdolecek sctp_ulp_notify(notification, *stcb, 0, NULL);
2085 1.7.4.2 jdolecek return (m);
2086 1.7.4.2 jdolecek }
2087 1.7.4.2 jdolecek oso = (*inp_p)->sctp_socket;
2088 1.7.4.2 jdolecek SCTP_TCB_UNLOCK((*stcb));
2089 1.7.4.2 jdolecek so = sonewconn(oso, SS_ISCONNECTED);
2090 1.7.4.2 jdolecek SCTP_INP_WLOCK((*stcb)->sctp_ep);
2091 1.7.4.2 jdolecek SCTP_TCB_LOCK((*stcb));
2092 1.7.4.2 jdolecek SCTP_INP_WUNLOCK((*stcb)->sctp_ep);
2093 1.7.4.2 jdolecek if (so == NULL) {
2094 1.7.4.2 jdolecek struct mbuf *op_err;
2095 1.7.4.2 jdolecek /* Too many sockets */
2096 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2097 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
2098 1.7.4.2 jdolecek printf("process_cookie_new: no room for another socket!\n");
2099 1.7.4.2 jdolecek }
2100 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
2101 1.7.4.2 jdolecek op_err = sctp_generate_invmanparam(SCTP_CAUSE_OUT_OF_RESC);
2102 1.7.4.2 jdolecek sctp_abort_association(*inp_p, NULL, m, iphlen,
2103 1.7.4.2 jdolecek sh, op_err);
2104 1.7.4.2 jdolecek sctp_free_assoc(*inp_p, *stcb);
2105 1.7.4.2 jdolecek return (NULL);
2106 1.7.4.2 jdolecek }
2107 1.7.4.2 jdolecek inp = (struct sctp_inpcb *)so->so_pcb;
2108 1.7.4.2 jdolecek inp->sctp_flags = (SCTP_PCB_FLAGS_TCPTYPE |
2109 1.7.4.2 jdolecek SCTP_PCB_FLAGS_CONNECTED |
2110 1.7.4.2 jdolecek SCTP_PCB_FLAGS_IN_TCPPOOL |
2111 1.7.4.2 jdolecek (SCTP_PCB_COPY_FLAGS & (*inp_p)->sctp_flags) |
2112 1.7.4.2 jdolecek SCTP_PCB_FLAGS_DONT_WAKE);
2113 1.7.4.2 jdolecek inp->sctp_socket = so;
2114 1.7.4.2 jdolecek
2115 1.7.4.2 jdolecek /*
2116 1.7.4.2 jdolecek * Now we must move it from one hash table to another
2117 1.7.4.2 jdolecek * and get the tcb in the right place.
2118 1.7.4.2 jdolecek */
2119 1.7.4.2 jdolecek sctp_move_pcb_and_assoc(*inp_p, inp, *stcb);
2120 1.7.4.2 jdolecek
2121 1.7.4.2 jdolecek /* Switch over to the new guy */
2122 1.7.4.2 jdolecek *inp_p = inp;
2123 1.7.4.2 jdolecek
2124 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp,
2125 1.7.4.2 jdolecek *stcb, *netp);
2126 1.7.4.2 jdolecek
2127 1.7.4.2 jdolecek sctp_ulp_notify(notification, *stcb, 0, NULL);
2128 1.7.4.2 jdolecek return (m);
2129 1.7.4.2 jdolecek }
2130 1.7.4.2 jdolecek }
2131 1.7.4.2 jdolecek if ((notification) && ((*inp_p)->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
2132 1.7.4.2 jdolecek sctp_ulp_notify(notification, *stcb, 0, NULL);
2133 1.7.4.2 jdolecek }
2134 1.7.4.2 jdolecek return (m);
2135 1.7.4.2 jdolecek }
2136 1.7.4.2 jdolecek
2137 1.7.4.2 jdolecek static void
2138 1.7.4.2 jdolecek sctp_handle_cookie_ack(struct sctp_cookie_ack_chunk *cp,
2139 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net)
2140 1.7.4.2 jdolecek {
2141 1.7.4.2 jdolecek /* cp must not be used, others call this without a c-ack :-) */
2142 1.7.4.2 jdolecek struct sctp_association *asoc;
2143 1.7.4.2 jdolecek
2144 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2145 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
2146 1.7.4.2 jdolecek printf("sctp_handle_cookie_ack: handling COOKIE-ACK\n");
2147 1.7.4.2 jdolecek }
2148 1.7.4.2 jdolecek #endif
2149 1.7.4.2 jdolecek if (stcb == NULL)
2150 1.7.4.2 jdolecek return;
2151 1.7.4.2 jdolecek
2152 1.7.4.2 jdolecek asoc = &stcb->asoc;
2153 1.7.4.2 jdolecek
2154 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_COOKIE, stcb->sctp_ep, stcb, net);
2155 1.7.4.2 jdolecek
2156 1.7.4.2 jdolecek /* process according to association state */
2157 1.7.4.2 jdolecek if (SCTP_GET_STATE(asoc) == SCTP_STATE_COOKIE_ECHOED) {
2158 1.7.4.2 jdolecek /* state change only needed when I am in right state */
2159 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2160 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
2161 1.7.4.2 jdolecek printf("moving to OPEN state\n");
2162 1.7.4.2 jdolecek }
2163 1.7.4.2 jdolecek #endif
2164 1.7.4.2 jdolecek if (asoc->state & SCTP_STATE_SHUTDOWN_PENDING) {
2165 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN | SCTP_STATE_SHUTDOWN_PENDING;
2166 1.7.4.2 jdolecek } else {
2167 1.7.4.2 jdolecek asoc->state = SCTP_STATE_OPEN;
2168 1.7.4.2 jdolecek }
2169 1.7.4.2 jdolecek
2170 1.7.4.2 jdolecek /* update RTO */
2171 1.7.4.2 jdolecek if (asoc->overall_error_count == 0) {
2172 1.7.4.2 jdolecek net->RTO = sctp_calculate_rto(stcb, asoc, net,
2173 1.7.4.2 jdolecek &asoc->time_entered);
2174 1.7.4.2 jdolecek }
2175 1.7.4.2 jdolecek SCTP_GETTIME_TIMEVAL(&asoc->time_entered);
2176 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_ASSOC_UP, stcb, 0, NULL);
2177 1.7.4.2 jdolecek if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2178 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
2179 1.7.4.2 jdolecek stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
2180 1.7.4.2 jdolecek soisconnected(stcb->sctp_ep->sctp_socket);
2181 1.7.4.2 jdolecek }
2182 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
2183 1.7.4.2 jdolecek stcb, net);
2184 1.7.4.2 jdolecek /* since we did not send a HB make sure we don't double things */
2185 1.7.4.2 jdolecek net->hb_responded = 1;
2186 1.7.4.2 jdolecek
2187 1.7.4.2 jdolecek if (stcb->asoc.sctp_autoclose_ticks &&
2188 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_AUTOCLOSE)) {
2189 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE,
2190 1.7.4.2 jdolecek stcb->sctp_ep, stcb, NULL);
2191 1.7.4.2 jdolecek }
2192 1.7.4.2 jdolecek
2193 1.7.4.2 jdolecek /*
2194 1.7.4.2 jdolecek * set ASCONF timer if ASCONFs are pending and allowed
2195 1.7.4.2 jdolecek * (eg. addresses changed when init/cookie echo in flight)
2196 1.7.4.2 jdolecek */
2197 1.7.4.2 jdolecek if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) &&
2198 1.7.4.2 jdolecek (stcb->asoc.peer_supports_asconf) &&
2199 1.7.4.2 jdolecek (!TAILQ_EMPTY(&stcb->asoc.asconf_queue))) {
2200 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2201 1.7.4.2 jdolecek stcb->sctp_ep, stcb,
2202 1.7.4.2 jdolecek stcb->asoc.primary_destination);
2203 1.7.4.2 jdolecek }
2204 1.7.4.2 jdolecek
2205 1.7.4.2 jdolecek }
2206 1.7.4.2 jdolecek /* Toss the cookie if I can */
2207 1.7.4.2 jdolecek sctp_toss_old_cookies(asoc);
2208 1.7.4.2 jdolecek if (!TAILQ_EMPTY(&asoc->sent_queue)) {
2209 1.7.4.2 jdolecek /* Restart the timer if we have pending data */
2210 1.7.4.2 jdolecek struct sctp_tmit_chunk *chk;
2211 1.7.4.2 jdolecek chk = TAILQ_FIRST(&asoc->sent_queue);
2212 1.7.4.2 jdolecek if (chk) {
2213 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
2214 1.7.4.2 jdolecek stcb, chk->whoTo);
2215 1.7.4.2 jdolecek }
2216 1.7.4.2 jdolecek }
2217 1.7.4.2 jdolecek
2218 1.7.4.2 jdolecek }
2219 1.7.4.2 jdolecek
2220 1.7.4.2 jdolecek static void
2221 1.7.4.2 jdolecek sctp_handle_ecn_echo(struct sctp_ecne_chunk *cp,
2222 1.7.4.2 jdolecek struct sctp_tcb *stcb)
2223 1.7.4.2 jdolecek {
2224 1.7.4.2 jdolecek struct sctp_nets *net;
2225 1.7.4.2 jdolecek struct sctp_tmit_chunk *lchk;
2226 1.7.4.2 jdolecek u_int32_t tsn;
2227 1.7.4.2 jdolecek if (ntohs(cp->ch.chunk_length) != sizeof(struct sctp_ecne_chunk)) {
2228 1.7.4.2 jdolecek return;
2229 1.7.4.2 jdolecek }
2230 1.7.4.2 jdolecek sctp_pegs[SCTP_ECNE_RCVD]++;
2231 1.7.4.2 jdolecek tsn = ntohl(cp->tsn);
2232 1.7.4.2 jdolecek /* ECN Nonce stuff: need a resync and disable the nonce sum check */
2233 1.7.4.2 jdolecek /* Also we make sure we disable the nonce_wait */
2234 1.7.4.2 jdolecek lchk = TAILQ_FIRST(&stcb->asoc.send_queue);
2235 1.7.4.2 jdolecek if (lchk == NULL) {
2236 1.7.4.2 jdolecek stcb->asoc.nonce_resync_tsn = stcb->asoc.sending_seq;
2237 1.7.4.2 jdolecek } else {
2238 1.7.4.2 jdolecek stcb->asoc.nonce_resync_tsn = lchk->rec.data.TSN_seq;
2239 1.7.4.2 jdolecek }
2240 1.7.4.2 jdolecek stcb->asoc.nonce_wait_for_ecne = 0;
2241 1.7.4.2 jdolecek stcb->asoc.nonce_sum_check = 0;
2242 1.7.4.2 jdolecek
2243 1.7.4.2 jdolecek /* Find where it was sent, if possible */
2244 1.7.4.2 jdolecek net = NULL;
2245 1.7.4.2 jdolecek lchk = TAILQ_FIRST(&stcb->asoc.sent_queue);
2246 1.7.4.2 jdolecek while (lchk) {
2247 1.7.4.2 jdolecek if (lchk->rec.data.TSN_seq == tsn) {
2248 1.7.4.2 jdolecek net = lchk->whoTo;
2249 1.7.4.2 jdolecek break;
2250 1.7.4.2 jdolecek }
2251 1.7.4.2 jdolecek if (compare_with_wrap(lchk->rec.data.TSN_seq, tsn, MAX_SEQ))
2252 1.7.4.2 jdolecek break;
2253 1.7.4.2 jdolecek lchk = TAILQ_NEXT(lchk, sctp_next);
2254 1.7.4.2 jdolecek }
2255 1.7.4.2 jdolecek if (net == NULL)
2256 1.7.4.2 jdolecek /* default is we use the primary */
2257 1.7.4.2 jdolecek net = stcb->asoc.primary_destination;
2258 1.7.4.2 jdolecek
2259 1.7.4.2 jdolecek if (compare_with_wrap(tsn, stcb->asoc.last_cwr_tsn, MAX_TSN)) {
2260 1.7.4.2 jdolecek #ifdef SCTP_CWND_LOGGING
2261 1.7.4.2 jdolecek int old_cwnd;
2262 1.7.4.2 jdolecek #endif
2263 1.7.4.2 jdolecek #ifdef SCTP_CWND_LOGGING
2264 1.7.4.2 jdolecek old_cwnd = net->cwnd;
2265 1.7.4.2 jdolecek #endif
2266 1.7.4.2 jdolecek sctp_pegs[SCTP_CWR_PERFO]++;
2267 1.7.4.2 jdolecek net->ssthresh = net->cwnd / 2;
2268 1.7.4.2 jdolecek if (net->ssthresh < net->mtu) {
2269 1.7.4.2 jdolecek net->ssthresh = net->mtu;
2270 1.7.4.2 jdolecek /* here back off the timer as well, to slow us down */
2271 1.7.4.2 jdolecek net->RTO <<= 2;
2272 1.7.4.2 jdolecek }
2273 1.7.4.2 jdolecek net->cwnd = net->ssthresh;
2274 1.7.4.2 jdolecek #ifdef SCTP_CWND_LOGGING
2275 1.7.4.2 jdolecek sctp_log_cwnd(net, (net->cwnd-old_cwnd), SCTP_CWND_LOG_FROM_SAT);
2276 1.7.4.2 jdolecek #endif
2277 1.7.4.2 jdolecek /* we reduce once every RTT. So we will only lower
2278 1.7.4.2 jdolecek * cwnd at the next sending seq i.e. the resync_tsn.
2279 1.7.4.2 jdolecek */
2280 1.7.4.2 jdolecek stcb->asoc.last_cwr_tsn = stcb->asoc.nonce_resync_tsn;
2281 1.7.4.2 jdolecek }
2282 1.7.4.2 jdolecek /*
2283 1.7.4.2 jdolecek * We always send a CWR this way if our previous one was lost
2284 1.7.4.2 jdolecek * our peer will get an update, or if it is not time again
2285 1.7.4.2 jdolecek * to reduce we still get the cwr to the peer.
2286 1.7.4.2 jdolecek */
2287 1.7.4.2 jdolecek sctp_send_cwr(stcb, net, tsn);
2288 1.7.4.2 jdolecek }
2289 1.7.4.2 jdolecek
2290 1.7.4.2 jdolecek static void
2291 1.7.4.2 jdolecek sctp_handle_ecn_cwr(struct sctp_cwr_chunk *cp, struct sctp_tcb *stcb)
2292 1.7.4.2 jdolecek {
2293 1.7.4.2 jdolecek /* Here we get a CWR from the peer. We must look in
2294 1.7.4.2 jdolecek * the outqueue and make sure that we have a covered
2295 1.7.4.2 jdolecek * ECNE in teh control chunk part. If so remove it.
2296 1.7.4.2 jdolecek */
2297 1.7.4.2 jdolecek struct sctp_tmit_chunk *chk;
2298 1.7.4.2 jdolecek struct sctp_ecne_chunk *ecne;
2299 1.7.4.2 jdolecek
2300 1.7.4.2 jdolecek TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) {
2301 1.7.4.2 jdolecek if (chk->rec.chunk_id != SCTP_ECN_ECHO) {
2302 1.7.4.2 jdolecek continue;
2303 1.7.4.2 jdolecek }
2304 1.7.4.2 jdolecek /* Look for and remove if it is the right TSN. Since
2305 1.7.4.2 jdolecek * there is only ONE ECNE on the control queue at
2306 1.7.4.2 jdolecek * any one time we don't need to worry about more than
2307 1.7.4.2 jdolecek * one!
2308 1.7.4.2 jdolecek */
2309 1.7.4.2 jdolecek ecne = mtod(chk->data, struct sctp_ecne_chunk *);
2310 1.7.4.2 jdolecek if (compare_with_wrap(ntohl(cp->tsn), ntohl(ecne->tsn),
2311 1.7.4.2 jdolecek MAX_TSN) || (cp->tsn == ecne->tsn)) {
2312 1.7.4.2 jdolecek /* this covers this ECNE, we can remove it */
2313 1.7.4.2 jdolecek TAILQ_REMOVE(&stcb->asoc.control_send_queue, chk,
2314 1.7.4.2 jdolecek sctp_next);
2315 1.7.4.2 jdolecek if (chk->data) {
2316 1.7.4.2 jdolecek sctp_m_freem(chk->data);
2317 1.7.4.2 jdolecek chk->data = NULL;
2318 1.7.4.2 jdolecek }
2319 1.7.4.2 jdolecek stcb->asoc.ctrl_queue_cnt--;
2320 1.7.4.2 jdolecek sctp_free_remote_addr(chk->whoTo);
2321 1.7.4.2 jdolecek SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
2322 1.7.4.2 jdolecek sctppcbinfo.ipi_count_chunk--;
2323 1.7.4.2 jdolecek if ((int)sctppcbinfo.ipi_count_chunk < 0) {
2324 1.7.4.2 jdolecek panic("Chunk count is negative");
2325 1.7.4.2 jdolecek }
2326 1.7.4.2 jdolecek sctppcbinfo.ipi_gencnt_chunk++;
2327 1.7.4.2 jdolecek break;
2328 1.7.4.2 jdolecek }
2329 1.7.4.2 jdolecek }
2330 1.7.4.2 jdolecek }
2331 1.7.4.2 jdolecek
2332 1.7.4.2 jdolecek static void
2333 1.7.4.2 jdolecek sctp_handle_shutdown_complete(struct sctp_shutdown_complete_chunk *cp,
2334 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net)
2335 1.7.4.2 jdolecek {
2336 1.7.4.2 jdolecek struct sctp_association *asoc;
2337 1.7.4.2 jdolecek
2338 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2339 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
2340 1.7.4.2 jdolecek printf("sctp_handle_shutdown_complete: handling SHUTDOWN-COMPLETE\n");
2341 1.7.4.2 jdolecek }
2342 1.7.4.2 jdolecek #endif
2343 1.7.4.2 jdolecek if (stcb == NULL)
2344 1.7.4.2 jdolecek return;
2345 1.7.4.2 jdolecek
2346 1.7.4.2 jdolecek asoc = &stcb->asoc;
2347 1.7.4.2 jdolecek /* process according to association state */
2348 1.7.4.2 jdolecek if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT) {
2349 1.7.4.2 jdolecek /* unexpected SHUTDOWN-COMPLETE... so ignore... */
2350 1.7.4.2 jdolecek return;
2351 1.7.4.2 jdolecek }
2352 1.7.4.2 jdolecek /* notify upper layer protocol */
2353 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_ASSOC_DOWN, stcb, 0, NULL);
2354 1.7.4.2 jdolecek if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
2355 1.7.4.2 jdolecek (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
2356 1.7.4.2 jdolecek stcb->sctp_ep->sctp_flags &= ~SCTP_PCB_FLAGS_CONNECTED;
2357 1.7.4.2 jdolecek stcb->sctp_ep->sctp_socket->so_snd.sb_cc = 0;
2358 1.7.4.2 jdolecek stcb->sctp_ep->sctp_socket->so_snd.sb_mbcnt = 0;
2359 1.7.4.2 jdolecek soisdisconnected(stcb->sctp_ep->sctp_socket);
2360 1.7.4.2 jdolecek }
2361 1.7.4.2 jdolecek /* are the queues empty? they should be */
2362 1.7.4.2 jdolecek if (!TAILQ_EMPTY(&asoc->send_queue) ||
2363 1.7.4.2 jdolecek !TAILQ_EMPTY(&asoc->sent_queue) ||
2364 1.7.4.2 jdolecek !TAILQ_EMPTY(&asoc->out_wheel)) {
2365 1.7.4.2 jdolecek sctp_report_all_outbound(stcb);
2366 1.7.4.2 jdolecek }
2367 1.7.4.2 jdolecek /* stop the timer */
2368 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb, net);
2369 1.7.4.2 jdolecek /* free the TCB */
2370 1.7.4.2 jdolecek sctp_free_assoc(stcb->sctp_ep, stcb);
2371 1.7.4.2 jdolecek return;
2372 1.7.4.2 jdolecek }
2373 1.7.4.2 jdolecek
2374 1.7.4.2 jdolecek static int
2375 1.7.4.2 jdolecek process_chunk_drop(struct sctp_tcb *stcb, struct sctp_chunk_desc *desc,
2376 1.7.4.2 jdolecek struct sctp_nets *net, u_int8_t flg)
2377 1.7.4.2 jdolecek {
2378 1.7.4.2 jdolecek switch (desc->chunk_type) {
2379 1.7.4.2 jdolecek case SCTP_DATA:
2380 1.7.4.2 jdolecek /* find the tsn to resend (possibly */
2381 1.7.4.2 jdolecek {
2382 1.7.4.2 jdolecek u_int32_t tsn;
2383 1.7.4.2 jdolecek struct sctp_tmit_chunk *tp1;
2384 1.7.4.2 jdolecek tsn = ntohl(desc->tsn_ifany);
2385 1.7.4.2 jdolecek tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue);
2386 1.7.4.2 jdolecek while (tp1) {
2387 1.7.4.2 jdolecek if (tp1->rec.data.TSN_seq == tsn) {
2388 1.7.4.2 jdolecek /* found it */
2389 1.7.4.2 jdolecek break;
2390 1.7.4.2 jdolecek }
2391 1.7.4.2 jdolecek if (compare_with_wrap(tp1->rec.data.TSN_seq, tsn,
2392 1.7.4.2 jdolecek MAX_TSN)) {
2393 1.7.4.2 jdolecek /* not found */
2394 1.7.4.2 jdolecek tp1 = NULL;
2395 1.7.4.2 jdolecek break;
2396 1.7.4.2 jdolecek }
2397 1.7.4.2 jdolecek tp1 = TAILQ_NEXT(tp1, sctp_next);
2398 1.7.4.2 jdolecek }
2399 1.7.4.2 jdolecek if (tp1 == NULL) {
2400 1.7.4.2 jdolecek /* Do it the other way */
2401 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_DNFND]++;
2402 1.7.4.2 jdolecek tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue);
2403 1.7.4.2 jdolecek while (tp1) {
2404 1.7.4.2 jdolecek if (tp1->rec.data.TSN_seq == tsn) {
2405 1.7.4.2 jdolecek /* found it */
2406 1.7.4.2 jdolecek break;
2407 1.7.4.2 jdolecek }
2408 1.7.4.2 jdolecek tp1 = TAILQ_NEXT(tp1, sctp_next);
2409 1.7.4.2 jdolecek }
2410 1.7.4.2 jdolecek }
2411 1.7.4.2 jdolecek if (tp1 == NULL) {
2412 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_TSNNF]++;
2413 1.7.4.2 jdolecek }
2414 1.7.4.2 jdolecek if ((tp1) && (tp1->sent < SCTP_DATAGRAM_ACKED)) {
2415 1.7.4.2 jdolecek u_int8_t *ddp;
2416 1.7.4.2 jdolecek if (((tp1->rec.data.state_flags & SCTP_WINDOW_PROBE) == SCTP_WINDOW_PROBE) &&
2417 1.7.4.2 jdolecek ((flg & SCTP_FROM_MIDDLE_BOX) == 0)) {
2418 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_DIWNP]++;
2419 1.7.4.2 jdolecek return (0);
2420 1.7.4.2 jdolecek }
2421 1.7.4.2 jdolecek if (stcb->asoc.peers_rwnd == 0 &&
2422 1.7.4.2 jdolecek (flg & SCTP_FROM_MIDDLE_BOX)) {
2423 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_DIZRW]++;
2424 1.7.4.2 jdolecek return (0);
2425 1.7.4.2 jdolecek }
2426 1.7.4.2 jdolecek ddp = (u_int8_t *)(mtod(tp1->data, vaddr_t) +
2427 1.7.4.2 jdolecek sizeof(struct sctp_data_chunk));
2428 1.7.4.2 jdolecek {
2429 1.7.4.2 jdolecek unsigned int iii;
2430 1.7.4.2 jdolecek for (iii = 0; iii < sizeof(desc->data_bytes);
2431 1.7.4.2 jdolecek iii++) {
2432 1.7.4.2 jdolecek if (ddp[iii] != desc->data_bytes[iii]) {
2433 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_BADD]++;
2434 1.7.4.2 jdolecek return (-1);
2435 1.7.4.2 jdolecek }
2436 1.7.4.2 jdolecek }
2437 1.7.4.2 jdolecek }
2438 1.7.4.2 jdolecek if (tp1->sent != SCTP_DATAGRAM_RESEND) {
2439 1.7.4.2 jdolecek stcb->asoc.sent_queue_retran_cnt++;
2440 1.7.4.2 jdolecek }
2441 1.7.4.2 jdolecek /* We zero out the nonce so resync not needed */
2442 1.7.4.2 jdolecek tp1->rec.data.ect_nonce = 0;
2443 1.7.4.2 jdolecek
2444 1.7.4.2 jdolecek if (tp1->do_rtt) {
2445 1.7.4.2 jdolecek /*
2446 1.7.4.2 jdolecek * this guy had a RTO calculation pending on it,
2447 1.7.4.2 jdolecek * cancel it
2448 1.7.4.2 jdolecek */
2449 1.7.4.2 jdolecek tp1->whoTo->rto_pending = 0;
2450 1.7.4.2 jdolecek tp1->do_rtt = 0;
2451 1.7.4.2 jdolecek }
2452 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_MARK]++;
2453 1.7.4.2 jdolecek tp1->sent = SCTP_DATAGRAM_RESEND;
2454 1.7.4.2 jdolecek /*
2455 1.7.4.2 jdolecek * mark it as if we were doing a FR, since we
2456 1.7.4.2 jdolecek * will be getting gap ack reports behind the
2457 1.7.4.2 jdolecek * info from the router.
2458 1.7.4.2 jdolecek */
2459 1.7.4.2 jdolecek tp1->rec.data.doing_fast_retransmit = 1;
2460 1.7.4.2 jdolecek /*
2461 1.7.4.2 jdolecek * mark the tsn with what sequences can cause a new FR.
2462 1.7.4.2 jdolecek */
2463 1.7.4.2 jdolecek if (TAILQ_EMPTY(&stcb->asoc.send_queue) ) {
2464 1.7.4.2 jdolecek tp1->rec.data.fast_retran_tsn = stcb->asoc.sending_seq;
2465 1.7.4.2 jdolecek } else {
2466 1.7.4.2 jdolecek tp1->rec.data.fast_retran_tsn = (TAILQ_FIRST(&stcb->asoc.send_queue))->rec.data.TSN_seq;
2467 1.7.4.2 jdolecek }
2468 1.7.4.2 jdolecek
2469 1.7.4.2 jdolecek /* restart the timer */
2470 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
2471 1.7.4.2 jdolecek stcb, tp1->whoTo);
2472 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
2473 1.7.4.2 jdolecek stcb, tp1->whoTo);
2474 1.7.4.2 jdolecek
2475 1.7.4.2 jdolecek /* fix counts and things */
2476 1.7.4.2 jdolecek sctp_flight_size_decrease(tp1);
2477 1.7.4.2 jdolecek sctp_total_flight_decrease(stcb, tp1);
2478 1.7.4.2 jdolecek tp1->snd_count--;
2479 1.7.4.2 jdolecek }
2480 1.7.4.2 jdolecek {
2481 1.7.4.2 jdolecek /* audit code */
2482 1.7.4.2 jdolecek unsigned int audit;
2483 1.7.4.2 jdolecek audit = 0;
2484 1.7.4.2 jdolecek TAILQ_FOREACH(tp1, &stcb->asoc.sent_queue, sctp_next) {
2485 1.7.4.2 jdolecek if (tp1->sent == SCTP_DATAGRAM_RESEND)
2486 1.7.4.2 jdolecek audit++;
2487 1.7.4.2 jdolecek }
2488 1.7.4.2 jdolecek TAILQ_FOREACH(tp1, &stcb->asoc.control_send_queue,
2489 1.7.4.2 jdolecek sctp_next) {
2490 1.7.4.2 jdolecek if (tp1->sent == SCTP_DATAGRAM_RESEND)
2491 1.7.4.2 jdolecek audit++;
2492 1.7.4.2 jdolecek }
2493 1.7.4.2 jdolecek if (audit != stcb->asoc.sent_queue_retran_cnt) {
2494 1.7.4.2 jdolecek printf("**Local Audit finds cnt:%d asoc cnt:%d\n",
2495 1.7.4.2 jdolecek audit, stcb->asoc.sent_queue_retran_cnt);
2496 1.7.4.2 jdolecek #ifndef SCTP_AUDITING_ENABLED
2497 1.7.4.2 jdolecek stcb->asoc.sent_queue_retran_cnt = audit;
2498 1.7.4.2 jdolecek #endif
2499 1.7.4.2 jdolecek }
2500 1.7.4.2 jdolecek }
2501 1.7.4.2 jdolecek }
2502 1.7.4.2 jdolecek break;
2503 1.7.4.2 jdolecek case SCTP_ASCONF:
2504 1.7.4.2 jdolecek {
2505 1.7.4.2 jdolecek struct sctp_tmit_chunk *asconf;
2506 1.7.4.2 jdolecek TAILQ_FOREACH(asconf, &stcb->asoc.control_send_queue,
2507 1.7.4.2 jdolecek sctp_next) {
2508 1.7.4.2 jdolecek if (asconf->rec.chunk_id == SCTP_ASCONF) {
2509 1.7.4.2 jdolecek break;
2510 1.7.4.2 jdolecek }
2511 1.7.4.2 jdolecek }
2512 1.7.4.2 jdolecek if (asconf) {
2513 1.7.4.2 jdolecek if (asconf->sent != SCTP_DATAGRAM_RESEND)
2514 1.7.4.2 jdolecek stcb->asoc.sent_queue_retran_cnt++;
2515 1.7.4.2 jdolecek asconf->sent = SCTP_DATAGRAM_RESEND;
2516 1.7.4.2 jdolecek asconf->snd_count--;
2517 1.7.4.2 jdolecek }
2518 1.7.4.2 jdolecek }
2519 1.7.4.2 jdolecek break;
2520 1.7.4.2 jdolecek case SCTP_INITIATION:
2521 1.7.4.2 jdolecek /* resend the INIT */
2522 1.7.4.2 jdolecek stcb->asoc.dropped_special_cnt++;
2523 1.7.4.2 jdolecek if (stcb->asoc.dropped_special_cnt < SCTP_RETRY_DROPPED_THRESH) {
2524 1.7.4.2 jdolecek /*
2525 1.7.4.2 jdolecek * If we can get it in, in a few attempts we do this,
2526 1.7.4.2 jdolecek * otherwise we let the timer fire.
2527 1.7.4.2 jdolecek */
2528 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_INIT, stcb->sctp_ep,
2529 1.7.4.2 jdolecek stcb, net);
2530 1.7.4.2 jdolecek sctp_send_initiate(stcb->sctp_ep, stcb);
2531 1.7.4.2 jdolecek }
2532 1.7.4.2 jdolecek break;
2533 1.7.4.2 jdolecek case SCTP_SELECTIVE_ACK:
2534 1.7.4.2 jdolecek /* resend the sack */
2535 1.7.4.2 jdolecek sctp_send_sack(stcb);
2536 1.7.4.2 jdolecek break;
2537 1.7.4.2 jdolecek case SCTP_HEARTBEAT_REQUEST:
2538 1.7.4.2 jdolecek /* resend a demand HB */
2539 1.7.4.2 jdolecek sctp_send_hb(stcb, 1, net);
2540 1.7.4.2 jdolecek break;
2541 1.7.4.2 jdolecek case SCTP_SHUTDOWN:
2542 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2543 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_OUTPUT4) {
2544 1.7.4.2 jdolecek printf("%s:%d sends a shutdown\n",
2545 1.7.4.2 jdolecek __FILE__,
2546 1.7.4.2 jdolecek __LINE__
2547 1.7.4.2 jdolecek );
2548 1.7.4.2 jdolecek }
2549 1.7.4.2 jdolecek #endif
2550 1.7.4.2 jdolecek sctp_send_shutdown(stcb, net);
2551 1.7.4.2 jdolecek break;
2552 1.7.4.2 jdolecek case SCTP_SHUTDOWN_ACK:
2553 1.7.4.2 jdolecek sctp_send_shutdown_ack(stcb, net);
2554 1.7.4.2 jdolecek break;
2555 1.7.4.2 jdolecek case SCTP_COOKIE_ECHO:
2556 1.7.4.2 jdolecek {
2557 1.7.4.2 jdolecek struct sctp_tmit_chunk *cookie;
2558 1.7.4.2 jdolecek cookie = NULL;
2559 1.7.4.2 jdolecek TAILQ_FOREACH(cookie, &stcb->asoc.control_send_queue,
2560 1.7.4.2 jdolecek sctp_next) {
2561 1.7.4.2 jdolecek if (cookie->rec.chunk_id == SCTP_COOKIE_ECHO) {
2562 1.7.4.2 jdolecek break;
2563 1.7.4.2 jdolecek }
2564 1.7.4.2 jdolecek }
2565 1.7.4.2 jdolecek if (cookie) {
2566 1.7.4.2 jdolecek if (cookie->sent != SCTP_DATAGRAM_RESEND)
2567 1.7.4.2 jdolecek stcb->asoc.sent_queue_retran_cnt++;
2568 1.7.4.2 jdolecek cookie->sent = SCTP_DATAGRAM_RESEND;
2569 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_COOKIE, stcb->sctp_ep, stcb, net);
2570 1.7.4.2 jdolecek }
2571 1.7.4.2 jdolecek }
2572 1.7.4.2 jdolecek break;
2573 1.7.4.2 jdolecek case SCTP_COOKIE_ACK:
2574 1.7.4.2 jdolecek sctp_send_cookie_ack(stcb);
2575 1.7.4.2 jdolecek break;
2576 1.7.4.2 jdolecek case SCTP_ASCONF_ACK:
2577 1.7.4.2 jdolecek /* resend last asconf ack */
2578 1.7.4.2 jdolecek sctp_send_asconf_ack(stcb, 1);
2579 1.7.4.2 jdolecek break;
2580 1.7.4.2 jdolecek case SCTP_FORWARD_CUM_TSN:
2581 1.7.4.2 jdolecek send_forward_tsn(stcb, &stcb->asoc);
2582 1.7.4.2 jdolecek break;
2583 1.7.4.2 jdolecek /* can't do anything with these */
2584 1.7.4.2 jdolecek case SCTP_PACKET_DROPPED:
2585 1.7.4.2 jdolecek case SCTP_INITIATION_ACK: /* this should not happen */
2586 1.7.4.2 jdolecek case SCTP_HEARTBEAT_ACK:
2587 1.7.4.2 jdolecek case SCTP_ABORT_ASSOCIATION:
2588 1.7.4.2 jdolecek case SCTP_OPERATION_ERROR:
2589 1.7.4.2 jdolecek case SCTP_SHUTDOWN_COMPLETE:
2590 1.7.4.2 jdolecek case SCTP_ECN_ECHO:
2591 1.7.4.2 jdolecek case SCTP_ECN_CWR:
2592 1.7.4.2 jdolecek default:
2593 1.7.4.2 jdolecek break;
2594 1.7.4.2 jdolecek }
2595 1.7.4.2 jdolecek return (0);
2596 1.7.4.2 jdolecek }
2597 1.7.4.2 jdolecek
2598 1.7.4.2 jdolecek static void
2599 1.7.4.2 jdolecek sctp_reset_in_stream(struct sctp_tcb *stcb,
2600 1.7.4.2 jdolecek struct sctp_stream_reset_response *resp, int number_entries)
2601 1.7.4.2 jdolecek {
2602 1.7.4.2 jdolecek int i;
2603 1.7.4.2 jdolecek uint16_t *list, temp;
2604 1.7.4.2 jdolecek
2605 1.7.4.2 jdolecek /* We set things to 0xffff since this is the last delivered
2606 1.7.4.2 jdolecek * sequence and we will be sending in 0 after the reset.
2607 1.7.4.2 jdolecek */
2608 1.7.4.2 jdolecek
2609 1.7.4.2 jdolecek if (resp->reset_flags & SCTP_RESET_PERFORMED) {
2610 1.7.4.2 jdolecek if (number_entries) {
2611 1.7.4.2 jdolecek list = resp->list_of_streams;
2612 1.7.4.2 jdolecek for (i = 0; i < number_entries; i++) {
2613 1.7.4.2 jdolecek temp = ntohs(list[i]);
2614 1.7.4.2 jdolecek list[i] = temp;
2615 1.7.4.2 jdolecek if (list[i] >= stcb->asoc.streamincnt) {
2616 1.7.4.2 jdolecek printf("Invalid stream in-stream reset %d\n", list[i]);
2617 1.7.4.2 jdolecek continue;
2618 1.7.4.2 jdolecek }
2619 1.7.4.2 jdolecek stcb->asoc.strmin[(list[i])].last_sequence_delivered = 0xffff;
2620 1.7.4.2 jdolecek }
2621 1.7.4.2 jdolecek } else {
2622 1.7.4.2 jdolecek list = NULL;
2623 1.7.4.2 jdolecek for (i = 0; i < stcb->asoc.streamincnt; i++) {
2624 1.7.4.2 jdolecek stcb->asoc.strmin[i].last_sequence_delivered = 0xffff;
2625 1.7.4.2 jdolecek }
2626 1.7.4.2 jdolecek }
2627 1.7.4.2 jdolecek sctp_ulp_notify(SCTP_NOTIFY_STR_RESET_RECV, stcb, number_entries, (void *)list);
2628 1.7.4.2 jdolecek }
2629 1.7.4.2 jdolecek }
2630 1.7.4.2 jdolecek
2631 1.7.4.2 jdolecek static void
2632 1.7.4.2 jdolecek sctp_clean_up_stream_reset(struct sctp_tcb *stcb)
2633 1.7.4.2 jdolecek {
2634 1.7.4.2 jdolecek struct sctp_tmit_chunk *chk, *nchk;
2635 1.7.4.2 jdolecek struct sctp_association *asoc;
2636 1.7.4.2 jdolecek
2637 1.7.4.2 jdolecek asoc = &stcb->asoc;
2638 1.7.4.2 jdolecek
2639 1.7.4.2 jdolecek for (chk = TAILQ_FIRST(&asoc->control_send_queue);
2640 1.7.4.2 jdolecek chk; chk = nchk) {
2641 1.7.4.2 jdolecek nchk = TAILQ_NEXT(chk, sctp_next);
2642 1.7.4.2 jdolecek if (chk->rec.chunk_id == SCTP_STREAM_RESET) {
2643 1.7.4.2 jdolecek struct sctp_stream_reset_req *strreq;
2644 1.7.4.2 jdolecek strreq = mtod(chk->data, struct sctp_stream_reset_req *);
2645 1.7.4.2 jdolecek if (strreq->sr_req.ph.param_type == ntohs(SCTP_STR_RESET_RESPONSE)) {
2646 1.7.4.2 jdolecek /* we only clean up the request */
2647 1.7.4.2 jdolecek continue;
2648 1.7.4.2 jdolecek } else if (strreq->sr_req.ph.param_type != ntohs(SCTP_STR_RESET_REQUEST)) {
2649 1.7.4.2 jdolecek printf("TSNH, an unknown stream reset request is in queue %x\n",
2650 1.7.4.2 jdolecek (u_int)ntohs(strreq->sr_req.ph.param_type));
2651 1.7.4.2 jdolecek continue;
2652 1.7.4.2 jdolecek }
2653 1.7.4.2 jdolecek sctp_timer_stop(SCTP_TIMER_TYPE_STRRESET, stcb->sctp_ep, stcb, chk->whoTo);
2654 1.7.4.2 jdolecek TAILQ_REMOVE(&asoc->control_send_queue,
2655 1.7.4.2 jdolecek chk,
2656 1.7.4.2 jdolecek sctp_next);
2657 1.7.4.2 jdolecek if (chk->data) {
2658 1.7.4.2 jdolecek sctp_m_freem(chk->data);
2659 1.7.4.2 jdolecek chk->data = NULL;
2660 1.7.4.2 jdolecek }
2661 1.7.4.2 jdolecek asoc->ctrl_queue_cnt--;
2662 1.7.4.2 jdolecek sctp_free_remote_addr(chk->whoTo);
2663 1.7.4.2 jdolecek SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, chk);
2664 1.7.4.2 jdolecek sctppcbinfo.ipi_count_chunk--;
2665 1.7.4.2 jdolecek if ((int)sctppcbinfo.ipi_count_chunk < 0) {
2666 1.7.4.2 jdolecek panic("Chunk count is negative");
2667 1.7.4.2 jdolecek }
2668 1.7.4.2 jdolecek sctppcbinfo.ipi_gencnt_chunk++;
2669 1.7.4.2 jdolecek /* we can only have one of these so we break */
2670 1.7.4.2 jdolecek break;
2671 1.7.4.2 jdolecek }
2672 1.7.4.2 jdolecek }
2673 1.7.4.2 jdolecek }
2674 1.7.4.2 jdolecek
2675 1.7.4.2 jdolecek
2676 1.7.4.2 jdolecek void
2677 1.7.4.2 jdolecek sctp_handle_stream_reset_response(struct sctp_tcb *stcb,
2678 1.7.4.2 jdolecek struct sctp_stream_reset_response *resp)
2679 1.7.4.2 jdolecek {
2680 1.7.4.2 jdolecek uint32_t seq, tsn;
2681 1.7.4.2 jdolecek int number_entries, param_length;
2682 1.7.4.2 jdolecek
2683 1.7.4.2 jdolecek param_length = ntohs(resp->ph.param_length);
2684 1.7.4.2 jdolecek seq = ntohl(resp->reset_req_seq_resp);
2685 1.7.4.2 jdolecek if (seq == stcb->asoc.str_reset_seq_out) {
2686 1.7.4.2 jdolecek sctp_clean_up_stream_reset(stcb);
2687 1.7.4.2 jdolecek stcb->asoc.str_reset_seq_out++;
2688 1.7.4.2 jdolecek stcb->asoc.stream_reset_outstanding = 0;
2689 1.7.4.2 jdolecek tsn = ntohl(resp->reset_at_tsn);
2690 1.7.4.2 jdolecek number_entries = (param_length - sizeof(struct sctp_stream_reset_response))/sizeof(uint16_t);
2691 1.7.4.2 jdolecek tsn--;
2692 1.7.4.2 jdolecek if ((tsn == stcb->asoc.cumulative_tsn) ||
2693 1.7.4.2 jdolecek (compare_with_wrap(stcb->asoc.cumulative_tsn, tsn, MAX_TSN))) {
2694 1.7.4.2 jdolecek /* no problem we are good to go */
2695 1.7.4.2 jdolecek sctp_reset_in_stream(stcb, resp, number_entries);
2696 1.7.4.2 jdolecek } else {
2697 1.7.4.2 jdolecek /* So, we have a stream reset but there
2698 1.7.4.2 jdolecek * is pending data. We need to copy
2699 1.7.4.2 jdolecek * out the stream_reset and then queue
2700 1.7.4.2 jdolecek * any data = or > resp->reset_at_tsn
2701 1.7.4.2 jdolecek */
2702 1.7.4.2 jdolecek if (stcb->asoc.pending_reply != NULL) {
2703 1.7.4.2 jdolecek /* FIX ME FIX ME
2704 1.7.4.2 jdolecek * This IS WRONG. We need
2705 1.7.4.2 jdolecek * to queue each of these up
2706 1.7.4.2 jdolecek * and only release the chunks
2707 1.7.4.2 jdolecek * for each reset that the cum-ack
2708 1.7.4.2 jdolecek * goes by. This is a short cut.
2709 1.7.4.2 jdolecek */
2710 1.7.4.2 jdolecek free(stcb->asoc.pending_reply, M_PCB);
2711 1.7.4.2 jdolecek }
2712 1.7.4.2 jdolecek stcb->asoc.pending_reply = malloc(param_length,
2713 1.7.4.2 jdolecek M_PCB, M_NOWAIT);
2714 1.7.4.2 jdolecek memcpy(stcb->asoc.pending_reply, resp, param_length);
2715 1.7.4.2 jdolecek }
2716 1.7.4.2 jdolecek
2717 1.7.4.2 jdolecek } else {
2718 1.7.4.2 jdolecek /* duplicate */
2719 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
2720 1.7.4.2 jdolecek printf("Duplicate old stream reset resp next:%x this one:%x\n",
2721 1.7.4.2 jdolecek stcb->asoc.str_reset_seq_out, seq);
2722 1.7.4.2 jdolecek #endif
2723 1.7.4.2 jdolecek }
2724 1.7.4.2 jdolecek }
2725 1.7.4.2 jdolecek
2726 1.7.4.2 jdolecek
2727 1.7.4.2 jdolecek static void
2728 1.7.4.2 jdolecek sctp_handle_stream_reset(struct sctp_tcb *stcb, struct sctp_stream_reset_req *sr_req)
2729 1.7.4.2 jdolecek {
2730 1.7.4.2 jdolecek int chk_length, param_len;
2731 1.7.4.2 jdolecek struct sctp_paramhdr *ph;
2732 1.7.4.2 jdolecek /* now it may be a reset or a reset-response */
2733 1.7.4.2 jdolecek struct sctp_stream_reset_request *req;
2734 1.7.4.2 jdolecek struct sctp_stream_reset_response *resp;
2735 1.7.4.2 jdolecek chk_length = ntohs(sr_req->ch.chunk_length);
2736 1.7.4.2 jdolecek
2737 1.7.4.2 jdolecek ph = (struct sctp_paramhdr *)&sr_req->sr_req;
2738 1.7.4.2 jdolecek while ((size_t)chk_length >= sizeof(struct sctp_stream_reset_request)) {
2739 1.7.4.2 jdolecek param_len = ntohs(ph->param_length);
2740 1.7.4.2 jdolecek if (ntohs(ph->param_type) == SCTP_STR_RESET_REQUEST) {
2741 1.7.4.2 jdolecek /* this will send the ACK and do the reset if needed */
2742 1.7.4.2 jdolecek req = (struct sctp_stream_reset_request *)ph;
2743 1.7.4.2 jdolecek sctp_send_str_reset_ack(stcb, req);
2744 1.7.4.2 jdolecek } else if (ntohs(ph->param_type) == SCTP_STR_RESET_RESPONSE) {
2745 1.7.4.2 jdolecek /* Now here is a tricky one. We reset our receive side
2746 1.7.4.2 jdolecek * of the streams. But what happens if the peers
2747 1.7.4.2 jdolecek * next sending TSN is NOT equal to 1 minus our cumack?
2748 1.7.4.2 jdolecek * And if his cumack is not equal to our next one out - 1
2749 1.7.4.2 jdolecek * we have another problem if this is receprical.
2750 1.7.4.2 jdolecek */
2751 1.7.4.2 jdolecek resp = (struct sctp_stream_reset_response *)ph;
2752 1.7.4.2 jdolecek sctp_handle_stream_reset_response(stcb, resp);
2753 1.7.4.2 jdolecek }
2754 1.7.4.2 jdolecek ph = (struct sctp_paramhdr *)((vaddr_t)ph + SCTP_SIZE32(param_len));
2755 1.7.4.2 jdolecek chk_length -= SCTP_SIZE32(param_len);
2756 1.7.4.2 jdolecek }
2757 1.7.4.2 jdolecek }
2758 1.7.4.2 jdolecek
2759 1.7.4.2 jdolecek /*
2760 1.7.4.2 jdolecek * Handle a router or endpoints report of a packet loss, there
2761 1.7.4.2 jdolecek * are two ways to handle this, either we get the whole packet
2762 1.7.4.2 jdolecek * and must disect it ourselves (possibly with truncation and
2763 1.7.4.2 jdolecek * or corruption) or it is a summary from a middle box that did
2764 1.7.4.2 jdolecek * the disectting for us.
2765 1.7.4.2 jdolecek */
2766 1.7.4.2 jdolecek static void
2767 1.7.4.2 jdolecek sctp_handle_packet_dropped(struct sctp_pktdrop_chunk *cp,
2768 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets *net)
2769 1.7.4.2 jdolecek {
2770 1.7.4.2 jdolecek u_int32_t bottle_bw, on_queue;
2771 1.7.4.2 jdolecek u_int16_t trunc_len;
2772 1.7.4.2 jdolecek unsigned int chlen;
2773 1.7.4.2 jdolecek unsigned int at;
2774 1.7.4.2 jdolecek struct sctp_chunk_desc desc;
2775 1.7.4.2 jdolecek struct sctp_chunkhdr *ch;
2776 1.7.4.2 jdolecek
2777 1.7.4.2 jdolecek chlen = ntohs(cp->ch.chunk_length);
2778 1.7.4.2 jdolecek chlen -= sizeof(struct sctp_pktdrop_chunk);
2779 1.7.4.2 jdolecek /* XXX possible chlen underflow */
2780 1.7.4.2 jdolecek if (chlen == 0) {
2781 1.7.4.2 jdolecek ch = NULL;
2782 1.7.4.2 jdolecek if (cp->ch.chunk_flags & SCTP_FROM_MIDDLE_BOX)
2783 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_BWRPT]++;
2784 1.7.4.2 jdolecek } else {
2785 1.7.4.2 jdolecek ch = (struct sctp_chunkhdr *)(cp->data + sizeof(struct sctphdr));
2786 1.7.4.2 jdolecek chlen -= sizeof(struct sctphdr);
2787 1.7.4.2 jdolecek /* XXX possible chlen underflow */
2788 1.7.4.2 jdolecek memset(&desc, 0, sizeof(desc));
2789 1.7.4.2 jdolecek }
2790 1.7.4.2 jdolecek
2791 1.7.4.2 jdolecek /* first update a rwnd possibly */
2792 1.7.4.2 jdolecek if ((cp->ch.chunk_flags & SCTP_FROM_MIDDLE_BOX) == 0) {
2793 1.7.4.2 jdolecek /* From a peer, we get a rwnd report */
2794 1.7.4.2 jdolecek u_int32_t a_rwnd;
2795 1.7.4.2 jdolecek
2796 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_FEHOS]++;
2797 1.7.4.2 jdolecek
2798 1.7.4.2 jdolecek bottle_bw = ntohl(cp->bottle_bw);
2799 1.7.4.2 jdolecek on_queue = ntohl(cp->current_onq);
2800 1.7.4.2 jdolecek if (bottle_bw && on_queue) {
2801 1.7.4.2 jdolecek /* a rwnd report is in here */
2802 1.7.4.2 jdolecek if (bottle_bw > on_queue)
2803 1.7.4.2 jdolecek a_rwnd = bottle_bw - on_queue;
2804 1.7.4.2 jdolecek else
2805 1.7.4.2 jdolecek a_rwnd = 0;
2806 1.7.4.2 jdolecek
2807 1.7.4.2 jdolecek if (a_rwnd <= 0)
2808 1.7.4.2 jdolecek stcb->asoc.peers_rwnd = 0;
2809 1.7.4.2 jdolecek else {
2810 1.7.4.2 jdolecek if (a_rwnd > stcb->asoc.total_flight) {
2811 1.7.4.2 jdolecek stcb->asoc.peers_rwnd =
2812 1.7.4.2 jdolecek a_rwnd - stcb->asoc.total_flight;
2813 1.7.4.2 jdolecek } else {
2814 1.7.4.2 jdolecek stcb->asoc.peers_rwnd = 0;
2815 1.7.4.2 jdolecek }
2816 1.7.4.2 jdolecek if (stcb->asoc.peers_rwnd <
2817 1.7.4.2 jdolecek stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
2818 1.7.4.2 jdolecek /* SWS sender side engages */
2819 1.7.4.2 jdolecek stcb->asoc.peers_rwnd = 0;
2820 1.7.4.2 jdolecek }
2821 1.7.4.2 jdolecek }
2822 1.7.4.2 jdolecek }
2823 1.7.4.2 jdolecek } else {
2824 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_FMBOX]++;
2825 1.7.4.2 jdolecek }
2826 1.7.4.2 jdolecek trunc_len = (u_int16_t)ntohs(cp->trunc_len);
2827 1.7.4.2 jdolecek /* now the chunks themselves */
2828 1.7.4.2 jdolecek while ((ch != NULL) && (chlen >= sizeof(struct sctp_chunkhdr))) {
2829 1.7.4.2 jdolecek desc.chunk_type = ch->chunk_type;
2830 1.7.4.2 jdolecek /* get amount we need to move */
2831 1.7.4.2 jdolecek at = ntohs(ch->chunk_length);
2832 1.7.4.2 jdolecek if (at < sizeof(struct sctp_chunkhdr)) {
2833 1.7.4.2 jdolecek /* corrupt chunk, maybe at the end? */
2834 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_CRUPT]++;
2835 1.7.4.2 jdolecek break;
2836 1.7.4.2 jdolecek }
2837 1.7.4.2 jdolecek if (trunc_len == 0) {
2838 1.7.4.2 jdolecek /* we are supposed to have all of it */
2839 1.7.4.2 jdolecek if (at > chlen) {
2840 1.7.4.2 jdolecek /* corrupt skip it */
2841 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_CRUPT]++;
2842 1.7.4.2 jdolecek break;
2843 1.7.4.2 jdolecek }
2844 1.7.4.2 jdolecek } else {
2845 1.7.4.2 jdolecek /* is there enough of it left ? */
2846 1.7.4.2 jdolecek if (desc.chunk_type == SCTP_DATA) {
2847 1.7.4.2 jdolecek if (chlen < (sizeof(struct sctp_data_chunk) +
2848 1.7.4.2 jdolecek sizeof(desc.data_bytes))) {
2849 1.7.4.2 jdolecek break;
2850 1.7.4.2 jdolecek }
2851 1.7.4.2 jdolecek } else {
2852 1.7.4.2 jdolecek if (chlen < sizeof(struct sctp_chunkhdr)) {
2853 1.7.4.2 jdolecek break;
2854 1.7.4.2 jdolecek }
2855 1.7.4.2 jdolecek }
2856 1.7.4.2 jdolecek }
2857 1.7.4.2 jdolecek if (desc.chunk_type == SCTP_DATA) {
2858 1.7.4.2 jdolecek /* can we get out the tsn? */
2859 1.7.4.2 jdolecek if ((cp->ch.chunk_flags & SCTP_FROM_MIDDLE_BOX))
2860 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_MB_DA]++;
2861 1.7.4.2 jdolecek
2862 1.7.4.2 jdolecek if (chlen >= (sizeof(struct sctp_data_chunk) + sizeof(u_int32_t)) ) {
2863 1.7.4.2 jdolecek /* yep */
2864 1.7.4.2 jdolecek struct sctp_data_chunk *dcp;
2865 1.7.4.2 jdolecek u_int8_t *ddp;
2866 1.7.4.2 jdolecek unsigned int iii;
2867 1.7.4.2 jdolecek dcp = (struct sctp_data_chunk *)ch;
2868 1.7.4.2 jdolecek ddp = (u_int8_t *)(dcp + 1);
2869 1.7.4.2 jdolecek for (iii = 0; iii < sizeof(desc.data_bytes); iii++) {
2870 1.7.4.2 jdolecek desc.data_bytes[iii] = ddp[iii];
2871 1.7.4.2 jdolecek }
2872 1.7.4.2 jdolecek desc.tsn_ifany = dcp->dp.tsn;
2873 1.7.4.2 jdolecek } else {
2874 1.7.4.2 jdolecek /* nope we are done. */
2875 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_NEDAT]++;
2876 1.7.4.2 jdolecek break;
2877 1.7.4.2 jdolecek }
2878 1.7.4.2 jdolecek } else {
2879 1.7.4.2 jdolecek if ((cp->ch.chunk_flags & SCTP_FROM_MIDDLE_BOX))
2880 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_MB_CT]++;
2881 1.7.4.2 jdolecek }
2882 1.7.4.2 jdolecek
2883 1.7.4.2 jdolecek if (process_chunk_drop(stcb, &desc, net, cp->ch.chunk_flags)) {
2884 1.7.4.2 jdolecek sctp_pegs[SCTP_PDRP_PDBRK]++;
2885 1.7.4.2 jdolecek break;
2886 1.7.4.2 jdolecek }
2887 1.7.4.2 jdolecek if (SCTP_SIZE32(at) > chlen) {
2888 1.7.4.2 jdolecek break;
2889 1.7.4.2 jdolecek }
2890 1.7.4.2 jdolecek chlen -= SCTP_SIZE32(at);
2891 1.7.4.2 jdolecek if (chlen < sizeof(struct sctp_chunkhdr)) {
2892 1.7.4.2 jdolecek /* done, none left */
2893 1.7.4.2 jdolecek break;
2894 1.7.4.2 jdolecek }
2895 1.7.4.2 jdolecek ch = (struct sctp_chunkhdr *)((vaddr_t)ch + SCTP_SIZE32(at));
2896 1.7.4.2 jdolecek }
2897 1.7.4.2 jdolecek
2898 1.7.4.2 jdolecek /* now middle boxes in sat networks get a cwnd bump */
2899 1.7.4.2 jdolecek if ((cp->ch.chunk_flags & SCTP_FROM_MIDDLE_BOX) &&
2900 1.7.4.2 jdolecek (stcb->asoc.sat_t3_loss_recovery == 0) &&
2901 1.7.4.2 jdolecek (stcb->asoc.sat_network)) {
2902 1.7.4.2 jdolecek /*
2903 1.7.4.2 jdolecek * This is debateable but for sat networks it makes sense
2904 1.7.4.2 jdolecek * Note if a T3 timer has went off, we will prohibit any
2905 1.7.4.2 jdolecek * changes to cwnd until we exit the t3 loss recovery.
2906 1.7.4.2 jdolecek */
2907 1.7.4.2 jdolecek u_int32_t bw_avail;
2908 1.7.4.2 jdolecek int rtt, incr;
2909 1.7.4.2 jdolecek #ifdef SCTP_CWND_LOGGING
2910 1.7.4.2 jdolecek int old_cwnd=net->cwnd;
2911 1.7.4.2 jdolecek #endif
2912 1.7.4.2 jdolecek /* need real RTT for this calc */
2913 1.7.4.2 jdolecek rtt = ((net->lastsa >> 2) + net->lastsv) >> 1;
2914 1.7.4.2 jdolecek /* get bottle neck bw */
2915 1.7.4.2 jdolecek bottle_bw = ntohl(cp->bottle_bw);
2916 1.7.4.2 jdolecek /* and whats on queue */
2917 1.7.4.2 jdolecek on_queue = ntohl(cp->current_onq);
2918 1.7.4.2 jdolecek /*
2919 1.7.4.2 jdolecek * adjust the on-queue if our flight is more it could be
2920 1.7.4.2 jdolecek * that the router has not yet gotten data "in-flight" to it
2921 1.7.4.2 jdolecek */
2922 1.7.4.2 jdolecek if (on_queue < net->flight_size)
2923 1.7.4.2 jdolecek on_queue = net->flight_size;
2924 1.7.4.2 jdolecek
2925 1.7.4.2 jdolecek /* calculate the available space */
2926 1.7.4.2 jdolecek bw_avail = (bottle_bw*rtt)/1000;
2927 1.7.4.2 jdolecek if (bw_avail > bottle_bw) {
2928 1.7.4.2 jdolecek /*
2929 1.7.4.2 jdolecek * Cap the growth to no more than the bottle neck.
2930 1.7.4.2 jdolecek * This can happen as RTT slides up due to queues.
2931 1.7.4.2 jdolecek * It also means if you have more than a 1 second
2932 1.7.4.2 jdolecek * RTT with a empty queue you will be limited to
2933 1.7.4.2 jdolecek * the bottle_bw per second no matter if
2934 1.7.4.2 jdolecek * other points have 1/2 the RTT and you could
2935 1.7.4.2 jdolecek * get more out...
2936 1.7.4.2 jdolecek */
2937 1.7.4.2 jdolecek bw_avail = bottle_bw;
2938 1.7.4.2 jdolecek }
2939 1.7.4.2 jdolecek
2940 1.7.4.2 jdolecek if (on_queue > bw_avail) {
2941 1.7.4.2 jdolecek /*
2942 1.7.4.2 jdolecek * No room for anything else don't allow anything
2943 1.7.4.2 jdolecek * else to be "added to the fire".
2944 1.7.4.2 jdolecek */
2945 1.7.4.2 jdolecek int seg_inflight, seg_onqueue, my_portion;
2946 1.7.4.2 jdolecek net->partial_bytes_acked = 0;
2947 1.7.4.2 jdolecek
2948 1.7.4.2 jdolecek /* how much are we over queue size? */
2949 1.7.4.2 jdolecek incr = on_queue - bw_avail;
2950 1.7.4.2 jdolecek if (stcb->asoc.seen_a_sack_this_pkt) {
2951 1.7.4.2 jdolecek /* undo any cwnd adjustment that
2952 1.7.4.2 jdolecek * the sack might have made
2953 1.7.4.2 jdolecek */
2954 1.7.4.2 jdolecek net->cwnd = net->prev_cwnd;
2955 1.7.4.2 jdolecek }
2956 1.7.4.2 jdolecek
2957 1.7.4.2 jdolecek /* Now how much of that is mine? */
2958 1.7.4.2 jdolecek seg_inflight = net->flight_size / net->mtu;
2959 1.7.4.2 jdolecek seg_onqueue = on_queue / net->mtu;
2960 1.7.4.2 jdolecek my_portion = (incr * seg_inflight)/seg_onqueue;
2961 1.7.4.2 jdolecek
2962 1.7.4.2 jdolecek /* Have I made an adjustment already */
2963 1.7.4.2 jdolecek if (net->cwnd > net->flight_size) {
2964 1.7.4.2 jdolecek /* for this flight I made an adjustment
2965 1.7.4.2 jdolecek * we need to decrease the portion by a share
2966 1.7.4.2 jdolecek * our previous adjustment.
2967 1.7.4.2 jdolecek */
2968 1.7.4.2 jdolecek int diff_adj;
2969 1.7.4.2 jdolecek diff_adj = net->cwnd - net->flight_size;
2970 1.7.4.2 jdolecek if (diff_adj > my_portion)
2971 1.7.4.2 jdolecek my_portion = 0;
2972 1.7.4.2 jdolecek else
2973 1.7.4.2 jdolecek my_portion -= diff_adj;
2974 1.7.4.2 jdolecek }
2975 1.7.4.2 jdolecek
2976 1.7.4.2 jdolecek /* back down to the previous cwnd (assume
2977 1.7.4.2 jdolecek * we have had a sack before this packet). minus
2978 1.7.4.2 jdolecek * what ever portion of the overage is my fault.
2979 1.7.4.2 jdolecek */
2980 1.7.4.2 jdolecek net->cwnd -= my_portion;
2981 1.7.4.2 jdolecek
2982 1.7.4.2 jdolecek /* we will NOT back down more than 1 MTU */
2983 1.7.4.2 jdolecek if (net->cwnd <= net->mtu) {
2984 1.7.4.2 jdolecek net->cwnd = net->mtu;
2985 1.7.4.2 jdolecek }
2986 1.7.4.2 jdolecek /* force into CA */
2987 1.7.4.2 jdolecek net->ssthresh = net->cwnd - 1;
2988 1.7.4.2 jdolecek } else {
2989 1.7.4.2 jdolecek /*
2990 1.7.4.2 jdolecek * Take 1/4 of the space left or
2991 1.7.4.2 jdolecek * max burst up .. whichever is less.
2992 1.7.4.2 jdolecek */
2993 1.7.4.2 jdolecek incr = min((bw_avail - on_queue) >> 2,
2994 1.7.4.2 jdolecek (int)stcb->asoc.max_burst * (int)net->mtu);
2995 1.7.4.2 jdolecek net->cwnd += incr;
2996 1.7.4.2 jdolecek }
2997 1.7.4.2 jdolecek if (net->cwnd > bw_avail) {
2998 1.7.4.2 jdolecek /* We can't exceed the pipe size */
2999 1.7.4.2 jdolecek net->cwnd = bw_avail;
3000 1.7.4.2 jdolecek }
3001 1.7.4.2 jdolecek if (net->cwnd < net->mtu) {
3002 1.7.4.2 jdolecek /* We always have 1 MTU */
3003 1.7.4.2 jdolecek net->cwnd = net->mtu;
3004 1.7.4.2 jdolecek }
3005 1.7.4.2 jdolecek #ifdef SCTP_CWND_LOGGING
3006 1.7.4.2 jdolecek if (net->cwnd - old_cwnd != 0) {
3007 1.7.4.2 jdolecek /* log only changes */
3008 1.7.4.2 jdolecek sctp_log_cwnd(net, (net->cwnd - old_cwnd),
3009 1.7.4.2 jdolecek SCTP_CWND_LOG_FROM_SAT);
3010 1.7.4.2 jdolecek }
3011 1.7.4.2 jdolecek #endif
3012 1.7.4.2 jdolecek }
3013 1.7.4.2 jdolecek }
3014 1.7.4.2 jdolecek
3015 1.7.4.2 jdolecek extern int sctp_strict_init;
3016 1.7.4.2 jdolecek
3017 1.7.4.2 jdolecek /*
3018 1.7.4.2 jdolecek * handles all control chunks in a packet
3019 1.7.4.2 jdolecek * inputs:
3020 1.7.4.2 jdolecek * - m: mbuf chain, assumed to still contain IP/SCTP header
3021 1.7.4.2 jdolecek * - stcb: is the tcb found for this packet
3022 1.7.4.2 jdolecek * - offset: offset into the mbuf chain to first chunkhdr
3023 1.7.4.2 jdolecek * - length: is the length of the complete packet
3024 1.7.4.2 jdolecek * outputs:
3025 1.7.4.2 jdolecek * - length: modified to remaining length after control processing
3026 1.7.4.2 jdolecek * - netp: modified to new sctp_nets after cookie-echo processing
3027 1.7.4.2 jdolecek * - return NULL to discard the packet (ie. no asoc, bad packet,...)
3028 1.7.4.2 jdolecek * otherwise return the tcb for this packet
3029 1.7.4.2 jdolecek */
3030 1.7.4.2 jdolecek static struct sctp_tcb *
3031 1.7.4.2 jdolecek sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
3032 1.7.4.2 jdolecek struct sctphdr *sh, struct sctp_chunkhdr *ch, struct sctp_inpcb *inp,
3033 1.7.4.2 jdolecek struct sctp_tcb *stcb, struct sctp_nets **netp, int *fwd_tsn_seen)
3034 1.7.4.2 jdolecek {
3035 1.7.4.2 jdolecek struct sctp_association *asoc;
3036 1.7.4.2 jdolecek u_int32_t vtag_in;
3037 1.7.4.2 jdolecek int num_chunks = 0; /* number of control chunks processed */
3038 1.7.4.2 jdolecek int chk_length;
3039 1.7.4.2 jdolecek int ret;
3040 1.7.4.2 jdolecek
3041 1.7.4.2 jdolecek /*
3042 1.7.4.2 jdolecek * How big should this be, and should it be alloc'd?
3043 1.7.4.2 jdolecek * Lets try the d-mtu-ceiling for now (2k) and that should
3044 1.7.4.2 jdolecek * hopefully work ... until we get into jumbo grams and such..
3045 1.7.4.2 jdolecek */
3046 1.7.4.2 jdolecek u_int8_t chunk_buf[DEFAULT_CHUNK_BUFFER];
3047 1.7.4.2 jdolecek struct sctp_tcb *locked_tcb = stcb;
3048 1.7.4.2 jdolecek
3049 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3050 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
3051 1.7.4.2 jdolecek printf("sctp_process_control: iphlen=%u, offset=%u, length=%u stcb:%p\n",
3052 1.7.4.2 jdolecek iphlen, *offset, length, stcb);
3053 1.7.4.2 jdolecek }
3054 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3055 1.7.4.2 jdolecek
3056 1.7.4.2 jdolecek /* validate chunk header length... */
3057 1.7.4.2 jdolecek if (ntohs(ch->chunk_length) < sizeof(*ch)) {
3058 1.7.4.2 jdolecek return (NULL);
3059 1.7.4.2 jdolecek }
3060 1.7.4.2 jdolecek
3061 1.7.4.2 jdolecek /*
3062 1.7.4.2 jdolecek * validate the verification tag
3063 1.7.4.2 jdolecek */
3064 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3065 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3066 1.7.4.2 jdolecek printf("sctp_process_control: validating vtags\n");
3067 1.7.4.2 jdolecek }
3068 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3069 1.7.4.2 jdolecek vtag_in = ntohl(sh->v_tag);
3070 1.7.4.2 jdolecek if (ch->chunk_type == SCTP_INITIATION) {
3071 1.7.4.2 jdolecek if (vtag_in != 0) {
3072 1.7.4.2 jdolecek /* protocol error- silently discard... */
3073 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3074 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3075 1.7.4.2 jdolecek printf("sctp_process_control: INIT with vtag != 0\n");
3076 1.7.4.2 jdolecek }
3077 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3078 1.7.4.2 jdolecek sctp_pegs[SCTP_BAD_VTAGS]++;
3079 1.7.4.2 jdolecek if (locked_tcb) {
3080 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3081 1.7.4.2 jdolecek }
3082 1.7.4.2 jdolecek return (NULL);
3083 1.7.4.2 jdolecek }
3084 1.7.4.2 jdolecek } else if (ch->chunk_type != SCTP_COOKIE_ECHO) {
3085 1.7.4.2 jdolecek /*
3086 1.7.4.2 jdolecek * first check if it's an ASCONF with an unknown src addr
3087 1.7.4.2 jdolecek * we need to look inside to find the association
3088 1.7.4.2 jdolecek */
3089 1.7.4.2 jdolecek if (ch->chunk_type == SCTP_ASCONF && stcb == NULL) {
3090 1.7.4.2 jdolecek stcb = sctp_findassociation_ep_asconf(m, iphlen,
3091 1.7.4.2 jdolecek *offset, sh, &inp, netp);
3092 1.7.4.2 jdolecek }
3093 1.7.4.2 jdolecek if (stcb == NULL) {
3094 1.7.4.2 jdolecek /* no association, so it's out of the blue... */
3095 1.7.4.2 jdolecek sctp_handle_ootb(m, iphlen, *offset, sh, inp, NULL);
3096 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3097 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3098 1.7.4.2 jdolecek printf("sctp_process_control: handling OOTB packet, chunk type=%xh\n",
3099 1.7.4.2 jdolecek ch->chunk_type);
3100 1.7.4.2 jdolecek }
3101 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3102 1.7.4.2 jdolecek *offset = length;
3103 1.7.4.2 jdolecek if (locked_tcb) {
3104 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3105 1.7.4.2 jdolecek }
3106 1.7.4.2 jdolecek return (NULL);
3107 1.7.4.2 jdolecek }
3108 1.7.4.2 jdolecek asoc = &stcb->asoc;
3109 1.7.4.2 jdolecek /* ABORT and SHUTDOWN can use either v_tag... */
3110 1.7.4.2 jdolecek if ((ch->chunk_type == SCTP_ABORT_ASSOCIATION) ||
3111 1.7.4.2 jdolecek (ch->chunk_type == SCTP_SHUTDOWN_COMPLETE) ||
3112 1.7.4.2 jdolecek (ch->chunk_type == SCTP_PACKET_DROPPED)) {
3113 1.7.4.2 jdolecek if ((vtag_in == asoc->my_vtag) ||
3114 1.7.4.2 jdolecek ((ch->chunk_flags & SCTP_HAD_NO_TCB) &&
3115 1.7.4.2 jdolecek (vtag_in == asoc->peer_vtag))) {
3116 1.7.4.2 jdolecek /* this is valid */
3117 1.7.4.2 jdolecek } else {
3118 1.7.4.2 jdolecek /* drop this packet... */
3119 1.7.4.2 jdolecek sctp_pegs[SCTP_BAD_VTAGS]++;
3120 1.7.4.2 jdolecek if (locked_tcb) {
3121 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3122 1.7.4.2 jdolecek }
3123 1.7.4.2 jdolecek return (NULL);
3124 1.7.4.2 jdolecek }
3125 1.7.4.2 jdolecek } else if (ch->chunk_type == SCTP_SHUTDOWN_ACK) {
3126 1.7.4.2 jdolecek if (vtag_in != asoc->my_vtag) {
3127 1.7.4.2 jdolecek /*
3128 1.7.4.2 jdolecek * this could be a stale SHUTDOWN-ACK or the
3129 1.7.4.2 jdolecek * peer never got the SHUTDOWN-COMPLETE and
3130 1.7.4.2 jdolecek * is still hung; we have started a new asoc
3131 1.7.4.2 jdolecek * but it won't complete until the shutdown is
3132 1.7.4.2 jdolecek * completed
3133 1.7.4.2 jdolecek */
3134 1.7.4.2 jdolecek if (locked_tcb) {
3135 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3136 1.7.4.2 jdolecek }
3137 1.7.4.2 jdolecek sctp_handle_ootb(m, iphlen, *offset, sh, inp,
3138 1.7.4.2 jdolecek NULL);
3139 1.7.4.2 jdolecek return (NULL);
3140 1.7.4.2 jdolecek }
3141 1.7.4.2 jdolecek } else {
3142 1.7.4.2 jdolecek /* for all other chunks, vtag must match */
3143 1.7.4.2 jdolecek
3144 1.7.4.2 jdolecek if (vtag_in != asoc->my_vtag) {
3145 1.7.4.2 jdolecek /* invalid vtag... */
3146 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3147 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3148 1.7.4.2 jdolecek printf("invalid vtag: %xh, expect %xh\n", vtag_in, asoc->my_vtag);
3149 1.7.4.2 jdolecek }
3150 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3151 1.7.4.2 jdolecek sctp_pegs[SCTP_BAD_VTAGS]++;
3152 1.7.4.2 jdolecek if (locked_tcb) {
3153 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3154 1.7.4.2 jdolecek }
3155 1.7.4.2 jdolecek *offset = length;
3156 1.7.4.2 jdolecek return (NULL);
3157 1.7.4.2 jdolecek }
3158 1.7.4.2 jdolecek }
3159 1.7.4.2 jdolecek } /* end if !SCTP_COOKIE_ECHO */
3160 1.7.4.2 jdolecek
3161 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3162 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3163 1.7.4.2 jdolecek printf("sctp_process_control: vtags ok, processing ctrl chunks\n");
3164 1.7.4.2 jdolecek }
3165 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3166 1.7.4.2 jdolecek
3167 1.7.4.2 jdolecek /*
3168 1.7.4.2 jdolecek * process all control chunks...
3169 1.7.4.2 jdolecek */
3170 1.7.4.2 jdolecek if (((ch->chunk_type == SCTP_SELECTIVE_ACK) ||
3171 1.7.4.2 jdolecek (ch->chunk_type == SCTP_HEARTBEAT_REQUEST)) &&
3172 1.7.4.2 jdolecek (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_ECHOED)) {
3173 1.7.4.2 jdolecek /* implied cookie-ack.. we must have lost the ack */
3174 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3175 1.7.4.2 jdolecek sctp_handle_cookie_ack((struct sctp_cookie_ack_chunk *)ch, stcb, *netp);
3176 1.7.4.2 jdolecek }
3177 1.7.4.2 jdolecek
3178 1.7.4.2 jdolecek while (IS_SCTP_CONTROL(ch)) {
3179 1.7.4.2 jdolecek /* validate chunk length */
3180 1.7.4.2 jdolecek chk_length = ntohs(ch->chunk_length);
3181 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3182 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT2) {
3183 1.7.4.2 jdolecek printf("sctp_process_control: processing a chunk type=%u, len=%u\n", ch->chunk_type, chk_length);
3184 1.7.4.2 jdolecek }
3185 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3186 1.7.4.2 jdolecek if ((size_t)chk_length < sizeof(*ch) ||
3187 1.7.4.2 jdolecek (*offset + chk_length) > length) {
3188 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3189 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3190 1.7.4.2 jdolecek printf("sctp_process_control: chunk length invalid! *offset:%u, chk_length:%u > length:%u\n",
3191 1.7.4.2 jdolecek *offset, chk_length, length);
3192 1.7.4.2 jdolecek }
3193 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3194 1.7.4.2 jdolecek *offset = length;
3195 1.7.4.2 jdolecek if (locked_tcb) {
3196 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3197 1.7.4.2 jdolecek }
3198 1.7.4.2 jdolecek return (NULL);
3199 1.7.4.2 jdolecek }
3200 1.7.4.2 jdolecek
3201 1.7.4.2 jdolecek /*
3202 1.7.4.2 jdolecek * INIT-ACK only gets the init ack "header" portion only
3203 1.7.4.2 jdolecek * because we don't have to process the peer's COOKIE.
3204 1.7.4.2 jdolecek * All others get a complete chunk.
3205 1.7.4.2 jdolecek */
3206 1.7.4.2 jdolecek if (ch->chunk_type == SCTP_INITIATION_ACK) {
3207 1.7.4.2 jdolecek /* get an init-ack chunk */
3208 1.7.4.2 jdolecek ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
3209 1.7.4.2 jdolecek sizeof(struct sctp_init_ack), chunk_buf);
3210 1.7.4.2 jdolecek if (ch == NULL) {
3211 1.7.4.2 jdolecek *offset = length;
3212 1.7.4.2 jdolecek if (locked_tcb) {
3213 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3214 1.7.4.2 jdolecek }
3215 1.7.4.2 jdolecek return (NULL);
3216 1.7.4.2 jdolecek }
3217 1.7.4.2 jdolecek } else {
3218 1.7.4.2 jdolecek /* get a complete chunk... */
3219 1.7.4.2 jdolecek if ((size_t)chk_length > sizeof(chunk_buf)) {
3220 1.7.4.2 jdolecek struct mbuf *oper;
3221 1.7.4.2 jdolecek struct sctp_paramhdr *phdr;
3222 1.7.4.2 jdolecek oper = NULL;
3223 1.7.4.2 jdolecek MGETHDR(oper, M_DONTWAIT, MT_HEADER);
3224 1.7.4.2 jdolecek if (oper) {
3225 1.7.4.2 jdolecek /* pre-reserve some space */
3226 1.7.4.2 jdolecek oper->m_data +=
3227 1.7.4.2 jdolecek sizeof(struct sctp_chunkhdr);
3228 1.7.4.2 jdolecek phdr =
3229 1.7.4.2 jdolecek mtod(oper, struct sctp_paramhdr *);
3230 1.7.4.2 jdolecek phdr->param_type =
3231 1.7.4.2 jdolecek htons(SCTP_CAUSE_OUT_OF_RESC);
3232 1.7.4.2 jdolecek phdr->param_length =
3233 1.7.4.2 jdolecek htons(sizeof(struct sctp_paramhdr));
3234 1.7.4.2 jdolecek sctp_queue_op_err(stcb, oper);
3235 1.7.4.2 jdolecek }
3236 1.7.4.2 jdolecek if (locked_tcb) {
3237 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3238 1.7.4.2 jdolecek }
3239 1.7.4.2 jdolecek return (NULL);
3240 1.7.4.2 jdolecek }
3241 1.7.4.2 jdolecek ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
3242 1.7.4.2 jdolecek chk_length, chunk_buf);
3243 1.7.4.2 jdolecek if (ch == NULL) {
3244 1.7.4.2 jdolecek printf("sctp_process_control: Can't get the all data....\n");
3245 1.7.4.2 jdolecek *offset = length;
3246 1.7.4.2 jdolecek if (locked_tcb) {
3247 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3248 1.7.4.2 jdolecek }
3249 1.7.4.2 jdolecek return (NULL);
3250 1.7.4.2 jdolecek }
3251 1.7.4.2 jdolecek
3252 1.7.4.2 jdolecek }
3253 1.7.4.2 jdolecek num_chunks++;
3254 1.7.4.2 jdolecek /* Save off the last place we got a control from */
3255 1.7.4.2 jdolecek if ((*netp) && stcb) {
3256 1.7.4.2 jdolecek stcb->asoc.last_control_chunk_from = *netp;
3257 1.7.4.2 jdolecek }
3258 1.7.4.2 jdolecek #ifdef SCTP_AUDITING_ENABLED
3259 1.7.4.2 jdolecek sctp_audit_log(0xB0, ch->chunk_type);
3260 1.7.4.2 jdolecek #endif
3261 1.7.4.2 jdolecek switch (ch->chunk_type) {
3262 1.7.4.2 jdolecek case SCTP_INITIATION:
3263 1.7.4.2 jdolecek /* must be first and only chunk */
3264 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3265 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3266 1.7.4.2 jdolecek printf("SCTP_INIT\n");
3267 1.7.4.2 jdolecek }
3268 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3269 1.7.4.2 jdolecek if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
3270 1.7.4.2 jdolecek /* We are not interested anymore */
3271 1.7.4.2 jdolecek if (locked_tcb) {
3272 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3273 1.7.4.2 jdolecek }
3274 1.7.4.2 jdolecek if (LIST_FIRST(&inp->sctp_asoc_list) == NULL) {
3275 1.7.4.2 jdolecek /* finish the job now */
3276 1.7.4.2 jdolecek sctp_inpcb_free(inp, 1);
3277 1.7.4.2 jdolecek }
3278 1.7.4.2 jdolecek *offset = length;
3279 1.7.4.2 jdolecek return (NULL);
3280 1.7.4.2 jdolecek }
3281 1.7.4.2 jdolecek if ((num_chunks > 1) ||
3282 1.7.4.2 jdolecek (sctp_strict_init && (length - *offset > SCTP_SIZE32(chk_length)))) {
3283 1.7.4.2 jdolecek *offset = length;
3284 1.7.4.2 jdolecek if (locked_tcb) {
3285 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3286 1.7.4.2 jdolecek }
3287 1.7.4.2 jdolecek return (NULL);
3288 1.7.4.2 jdolecek }
3289 1.7.4.2 jdolecek if ((stcb != NULL) &&
3290 1.7.4.2 jdolecek (SCTP_GET_STATE(&stcb->asoc) ==
3291 1.7.4.2 jdolecek SCTP_STATE_SHUTDOWN_ACK_SENT)) {
3292 1.7.4.2 jdolecek sctp_send_shutdown_ack(stcb,
3293 1.7.4.2 jdolecek stcb->asoc.primary_destination);
3294 1.7.4.2 jdolecek *offset = length;
3295 1.7.4.2 jdolecek if (locked_tcb) {
3296 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3297 1.7.4.2 jdolecek }
3298 1.7.4.2 jdolecek return (NULL);
3299 1.7.4.2 jdolecek }
3300 1.7.4.2 jdolecek sctp_handle_init(m, iphlen, *offset, sh,
3301 1.7.4.2 jdolecek (struct sctp_init_chunk *)ch, inp, stcb, *netp);
3302 1.7.4.2 jdolecek *offset = length;
3303 1.7.4.2 jdolecek if (locked_tcb) {
3304 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3305 1.7.4.2 jdolecek }
3306 1.7.4.2 jdolecek return (NULL);
3307 1.7.4.2 jdolecek break;
3308 1.7.4.2 jdolecek case SCTP_INITIATION_ACK:
3309 1.7.4.2 jdolecek /* must be first and only chunk */
3310 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3311 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3312 1.7.4.2 jdolecek printf("SCTP_INIT-ACK\n");
3313 1.7.4.2 jdolecek }
3314 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3315 1.7.4.2 jdolecek if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
3316 1.7.4.2 jdolecek /* We are not interested anymore */
3317 1.7.4.2 jdolecek if (locked_tcb) {
3318 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3319 1.7.4.2 jdolecek }
3320 1.7.4.2 jdolecek *offset = length;
3321 1.7.4.2 jdolecek if (stcb) {
3322 1.7.4.2 jdolecek sctp_free_assoc(inp, stcb);
3323 1.7.4.2 jdolecek } else {
3324 1.7.4.2 jdolecek if (LIST_FIRST(&inp->sctp_asoc_list) == NULL) {
3325 1.7.4.2 jdolecek /* finish the job now */
3326 1.7.4.2 jdolecek sctp_inpcb_free(inp, 1);
3327 1.7.4.2 jdolecek }
3328 1.7.4.2 jdolecek }
3329 1.7.4.2 jdolecek return (NULL);
3330 1.7.4.2 jdolecek }
3331 1.7.4.2 jdolecek if ((num_chunks > 1) ||
3332 1.7.4.2 jdolecek (sctp_strict_init && (length - *offset > SCTP_SIZE32(chk_length)))) {
3333 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3334 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3335 1.7.4.2 jdolecek printf("Length is %d rounded chk_length:%d .. dropping\n",
3336 1.7.4.2 jdolecek length - *offset,
3337 1.7.4.2 jdolecek SCTP_SIZE32(chk_length));
3338 1.7.4.2 jdolecek }
3339 1.7.4.2 jdolecek #endif
3340 1.7.4.2 jdolecek *offset = length;
3341 1.7.4.2 jdolecek if (locked_tcb) {
3342 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3343 1.7.4.2 jdolecek }
3344 1.7.4.2 jdolecek return (NULL);
3345 1.7.4.2 jdolecek }
3346 1.7.4.2 jdolecek ret = sctp_handle_init_ack(m, iphlen, *offset, sh,
3347 1.7.4.2 jdolecek (struct sctp_init_ack_chunk *)ch, stcb, *netp);
3348 1.7.4.2 jdolecek /*
3349 1.7.4.2 jdolecek * Special case, I must call the output routine
3350 1.7.4.2 jdolecek * to get the cookie echoed
3351 1.7.4.2 jdolecek */
3352 1.7.4.2 jdolecek if ((stcb) && ret == 0)
3353 1.7.4.2 jdolecek sctp_chunk_output(stcb->sctp_ep, stcb, 2);
3354 1.7.4.2 jdolecek *offset = length;
3355 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3356 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3357 1.7.4.2 jdolecek printf("All done INIT-ACK processing\n");
3358 1.7.4.2 jdolecek }
3359 1.7.4.2 jdolecek #endif
3360 1.7.4.2 jdolecek if (locked_tcb) {
3361 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3362 1.7.4.2 jdolecek }
3363 1.7.4.2 jdolecek return (NULL);
3364 1.7.4.2 jdolecek break;
3365 1.7.4.2 jdolecek case SCTP_SELECTIVE_ACK:
3366 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3367 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3368 1.7.4.2 jdolecek printf("SCTP_SACK\n");
3369 1.7.4.2 jdolecek }
3370 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3371 1.7.4.2 jdolecek sctp_pegs[SCTP_PEG_SACKS_SEEN]++;
3372 1.7.4.2 jdolecek {
3373 1.7.4.2 jdolecek int abort_now = 0;
3374 1.7.4.2 jdolecek stcb->asoc.seen_a_sack_this_pkt = 1;
3375 1.7.4.2 jdolecek sctp_handle_sack((struct sctp_sack_chunk *)ch,
3376 1.7.4.2 jdolecek stcb, *netp, &abort_now);
3377 1.7.4.2 jdolecek if (abort_now) {
3378 1.7.4.2 jdolecek /* ABORT signal from sack processing */
3379 1.7.4.2 jdolecek *offset = length;
3380 1.7.4.2 jdolecek return (NULL);
3381 1.7.4.2 jdolecek }
3382 1.7.4.2 jdolecek }
3383 1.7.4.2 jdolecek break;
3384 1.7.4.2 jdolecek case SCTP_HEARTBEAT_REQUEST:
3385 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3386 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3387 1.7.4.2 jdolecek printf("SCTP_HEARTBEAT\n");
3388 1.7.4.2 jdolecek }
3389 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3390 1.7.4.2 jdolecek sctp_pegs[SCTP_HB_RECV]++;
3391 1.7.4.2 jdolecek sctp_send_heartbeat_ack(stcb, m, *offset, chk_length,
3392 1.7.4.2 jdolecek *netp);
3393 1.7.4.2 jdolecek
3394 1.7.4.2 jdolecek /* He's alive so give him credit */
3395 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3396 1.7.4.2 jdolecek break;
3397 1.7.4.2 jdolecek case SCTP_HEARTBEAT_ACK:
3398 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3399 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3400 1.7.4.2 jdolecek printf("SCTP_HEARTBEAT-ACK\n");
3401 1.7.4.2 jdolecek }
3402 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3403 1.7.4.2 jdolecek
3404 1.7.4.2 jdolecek /* He's alive so give him credit */
3405 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3406 1.7.4.2 jdolecek
3407 1.7.4.2 jdolecek sctp_pegs[SCTP_HB_ACK_RECV]++;
3408 1.7.4.2 jdolecek sctp_handle_heartbeat_ack((struct sctp_heartbeat_chunk *)ch,
3409 1.7.4.2 jdolecek stcb, *netp);
3410 1.7.4.2 jdolecek break;
3411 1.7.4.2 jdolecek case SCTP_ABORT_ASSOCIATION:
3412 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3413 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3414 1.7.4.2 jdolecek printf("SCTP_ABORT\n");
3415 1.7.4.2 jdolecek }
3416 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3417 1.7.4.2 jdolecek sctp_handle_abort((struct sctp_abort_chunk *)ch,
3418 1.7.4.2 jdolecek stcb, *netp);
3419 1.7.4.2 jdolecek *offset = length;
3420 1.7.4.2 jdolecek return (NULL);
3421 1.7.4.2 jdolecek break;
3422 1.7.4.2 jdolecek case SCTP_SHUTDOWN:
3423 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3424 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3425 1.7.4.2 jdolecek printf("SCTP_SHUTDOWN\n");
3426 1.7.4.2 jdolecek }
3427 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3428 1.7.4.2 jdolecek {
3429 1.7.4.2 jdolecek int abort_flag = 0;
3430 1.7.4.2 jdolecek sctp_handle_shutdown((struct sctp_shutdown_chunk *)ch,
3431 1.7.4.2 jdolecek stcb, *netp, &abort_flag);
3432 1.7.4.2 jdolecek if (abort_flag) {
3433 1.7.4.2 jdolecek *offset = length;
3434 1.7.4.2 jdolecek return (NULL);
3435 1.7.4.2 jdolecek }
3436 1.7.4.2 jdolecek }
3437 1.7.4.2 jdolecek break;
3438 1.7.4.2 jdolecek case SCTP_SHUTDOWN_ACK:
3439 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3440 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3441 1.7.4.2 jdolecek printf("SCTP_SHUTDOWN-ACK\n");
3442 1.7.4.2 jdolecek }
3443 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3444 1.7.4.2 jdolecek sctp_handle_shutdown_ack((struct sctp_shutdown_ack_chunk *)ch, stcb, *netp);
3445 1.7.4.2 jdolecek *offset = length;
3446 1.7.4.2 jdolecek return (NULL);
3447 1.7.4.2 jdolecek break;
3448 1.7.4.2 jdolecek case SCTP_OPERATION_ERROR:
3449 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3450 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3451 1.7.4.2 jdolecek printf("SCTP_OP-ERR\n");
3452 1.7.4.2 jdolecek }
3453 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3454 1.7.4.2 jdolecek if (sctp_handle_error(ch, stcb, *netp) < 0) {
3455 1.7.4.2 jdolecek *offset = length;
3456 1.7.4.2 jdolecek return (NULL);
3457 1.7.4.2 jdolecek }
3458 1.7.4.2 jdolecek break;
3459 1.7.4.2 jdolecek case SCTP_COOKIE_ECHO:
3460 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3461 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3462 1.7.4.2 jdolecek printf("SCTP_COOKIE-ECHO stcb is %p\n", stcb);
3463 1.7.4.2 jdolecek }
3464 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3465 1.7.4.2 jdolecek if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
3466 1.7.4.2 jdolecek /* We are not interested anymore */
3467 1.7.4.2 jdolecek *offset = length;
3468 1.7.4.2 jdolecek if (stcb) {
3469 1.7.4.2 jdolecek sctp_free_assoc(inp, stcb);
3470 1.7.4.2 jdolecek } else {
3471 1.7.4.2 jdolecek if (LIST_FIRST(&inp->sctp_asoc_list) == NULL) {
3472 1.7.4.2 jdolecek /* finish the job now */
3473 1.7.4.2 jdolecek sctp_inpcb_free(inp, 1);
3474 1.7.4.2 jdolecek }
3475 1.7.4.2 jdolecek }
3476 1.7.4.2 jdolecek return (NULL);
3477 1.7.4.2 jdolecek }
3478 1.7.4.2 jdolecek /*
3479 1.7.4.2 jdolecek * First are we accepting?
3480 1.7.4.2 jdolecek * We do this again here since it is possible
3481 1.7.4.2 jdolecek * that a previous endpoint WAS listening responded to
3482 1.7.4.2 jdolecek * a INIT-ACK and then closed. We opened and bound..
3483 1.7.4.2 jdolecek * and are now no longer listening.
3484 1.7.4.2 jdolecek */
3485 1.7.4.2 jdolecek if (((inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) == 0) ||
3486 1.7.4.2 jdolecek (inp->sctp_socket->so_qlimit == 0)) {
3487 1.7.4.2 jdolecek sctp_abort_association(inp, stcb, m, iphlen, sh,
3488 1.7.4.2 jdolecek NULL);
3489 1.7.4.2 jdolecek *offset = length;
3490 1.7.4.2 jdolecek return (NULL);
3491 1.7.4.2 jdolecek } else if (inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) {
3492 1.7.4.2 jdolecek /* we are accepting so check limits like TCP */
3493 1.7.4.2 jdolecek if (inp->sctp_socket->so_qlen >
3494 1.7.4.2 jdolecek inp->sctp_socket->so_qlimit) {
3495 1.7.4.2 jdolecek /* no space */
3496 1.7.4.2 jdolecek struct mbuf *oper;
3497 1.7.4.2 jdolecek struct sctp_paramhdr *phdr;
3498 1.7.4.2 jdolecek oper = NULL;
3499 1.7.4.2 jdolecek MGETHDR(oper, M_DONTWAIT, MT_HEADER);
3500 1.7.4.2 jdolecek if (oper) {
3501 1.7.4.2 jdolecek oper->m_len =
3502 1.7.4.2 jdolecek oper->m_pkthdr.len =
3503 1.7.4.2 jdolecek sizeof(struct sctp_paramhdr);
3504 1.7.4.2 jdolecek phdr = mtod(oper,
3505 1.7.4.2 jdolecek struct sctp_paramhdr *);
3506 1.7.4.2 jdolecek phdr->param_type =
3507 1.7.4.2 jdolecek htons(SCTP_CAUSE_OUT_OF_RESC);
3508 1.7.4.2 jdolecek phdr->param_length =
3509 1.7.4.2 jdolecek htons(sizeof(struct sctp_paramhdr));
3510 1.7.4.2 jdolecek }
3511 1.7.4.2 jdolecek sctp_abort_association(inp, stcb, m,
3512 1.7.4.2 jdolecek iphlen, sh, oper);
3513 1.7.4.2 jdolecek *offset = length;
3514 1.7.4.2 jdolecek return (NULL);
3515 1.7.4.2 jdolecek }
3516 1.7.4.2 jdolecek }
3517 1.7.4.2 jdolecek {
3518 1.7.4.2 jdolecek struct mbuf *ret_buf;
3519 1.7.4.2 jdolecek ret_buf = sctp_handle_cookie_echo(m, iphlen,
3520 1.7.4.2 jdolecek *offset, sh,
3521 1.7.4.2 jdolecek (struct sctp_cookie_echo_chunk *)ch, &inp,
3522 1.7.4.2 jdolecek &stcb, netp);
3523 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3524 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3525 1.7.4.2 jdolecek printf("ret_buf:%p length:%d off:%d\n",
3526 1.7.4.2 jdolecek ret_buf, length, *offset);
3527 1.7.4.2 jdolecek }
3528 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3529 1.7.4.2 jdolecek
3530 1.7.4.2 jdolecek if (ret_buf == NULL) {
3531 1.7.4.2 jdolecek if (locked_tcb) {
3532 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3533 1.7.4.2 jdolecek }
3534 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3535 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3536 1.7.4.2 jdolecek printf("GAK, null buffer\n");
3537 1.7.4.2 jdolecek }
3538 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3539 1.7.4.2 jdolecek *offset = length;
3540 1.7.4.2 jdolecek return (NULL);
3541 1.7.4.2 jdolecek }
3542 1.7.4.2 jdolecek if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
3543 1.7.4.2 jdolecek /*
3544 1.7.4.2 jdolecek * Restart the timer if we have pending
3545 1.7.4.2 jdolecek * data
3546 1.7.4.2 jdolecek */
3547 1.7.4.2 jdolecek struct sctp_tmit_chunk *chk;
3548 1.7.4.2 jdolecek chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
3549 1.7.4.2 jdolecek if (chk) {
3550 1.7.4.2 jdolecek sctp_timer_start(SCTP_TIMER_TYPE_SEND,
3551 1.7.4.2 jdolecek stcb->sctp_ep, stcb,
3552 1.7.4.2 jdolecek chk->whoTo);
3553 1.7.4.2 jdolecek }
3554 1.7.4.2 jdolecek }
3555 1.7.4.2 jdolecek }
3556 1.7.4.2 jdolecek break;
3557 1.7.4.2 jdolecek case SCTP_COOKIE_ACK:
3558 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3559 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3560 1.7.4.2 jdolecek printf("SCTP_COOKIE-ACK\n");
3561 1.7.4.2 jdolecek }
3562 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3563 1.7.4.2 jdolecek
3564 1.7.4.2 jdolecek if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
3565 1.7.4.2 jdolecek /* We are not interested anymore */
3566 1.7.4.2 jdolecek sctp_free_assoc(inp, stcb);
3567 1.7.4.2 jdolecek *offset = length;
3568 1.7.4.2 jdolecek return (NULL);
3569 1.7.4.2 jdolecek }
3570 1.7.4.2 jdolecek /* He's alive so give him credit */
3571 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3572 1.7.4.2 jdolecek sctp_handle_cookie_ack((struct sctp_cookie_ack_chunk *)ch,
3573 1.7.4.2 jdolecek stcb, *netp);
3574 1.7.4.2 jdolecek break;
3575 1.7.4.2 jdolecek case SCTP_ECN_ECHO:
3576 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3577 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3578 1.7.4.2 jdolecek printf("SCTP_ECN-ECHO\n");
3579 1.7.4.2 jdolecek }
3580 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3581 1.7.4.2 jdolecek /* He's alive so give him credit */
3582 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3583 1.7.4.2 jdolecek sctp_handle_ecn_echo((struct sctp_ecne_chunk *)ch,
3584 1.7.4.2 jdolecek stcb);
3585 1.7.4.2 jdolecek break;
3586 1.7.4.2 jdolecek case SCTP_ECN_CWR:
3587 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3588 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3589 1.7.4.2 jdolecek printf("SCTP_ECN-CWR\n");
3590 1.7.4.2 jdolecek }
3591 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3592 1.7.4.2 jdolecek /* He's alive so give him credit */
3593 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3594 1.7.4.2 jdolecek
3595 1.7.4.2 jdolecek sctp_handle_ecn_cwr((struct sctp_cwr_chunk *)ch, stcb);
3596 1.7.4.2 jdolecek break;
3597 1.7.4.2 jdolecek case SCTP_SHUTDOWN_COMPLETE:
3598 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3599 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3600 1.7.4.2 jdolecek printf("SCTP_SHUTDOWN-COMPLETE\n");
3601 1.7.4.2 jdolecek }
3602 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3603 1.7.4.2 jdolecek /* must be first and only chunk */
3604 1.7.4.2 jdolecek if ((num_chunks > 1) ||
3605 1.7.4.2 jdolecek (length - *offset > SCTP_SIZE32(chk_length))) {
3606 1.7.4.2 jdolecek *offset = length;
3607 1.7.4.2 jdolecek if (locked_tcb) {
3608 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3609 1.7.4.2 jdolecek }
3610 1.7.4.2 jdolecek return (NULL);
3611 1.7.4.2 jdolecek }
3612 1.7.4.2 jdolecek sctp_handle_shutdown_complete((struct sctp_shutdown_complete_chunk *)ch,
3613 1.7.4.2 jdolecek stcb, *netp);
3614 1.7.4.2 jdolecek *offset = length;
3615 1.7.4.2 jdolecek return (NULL);
3616 1.7.4.2 jdolecek break;
3617 1.7.4.2 jdolecek case SCTP_ASCONF:
3618 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3619 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3620 1.7.4.2 jdolecek printf("SCTP_ASCONF\n");
3621 1.7.4.2 jdolecek }
3622 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3623 1.7.4.2 jdolecek /* He's alive so give him credit */
3624 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3625 1.7.4.2 jdolecek
3626 1.7.4.2 jdolecek sctp_handle_asconf(m, *offset,
3627 1.7.4.2 jdolecek (struct sctp_asconf_chunk *)ch, stcb, *netp);
3628 1.7.4.2 jdolecek break;
3629 1.7.4.2 jdolecek case SCTP_ASCONF_ACK:
3630 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3631 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3632 1.7.4.2 jdolecek printf("SCTP_ASCONF-ACK\n");
3633 1.7.4.2 jdolecek }
3634 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3635 1.7.4.2 jdolecek /* He's alive so give him credit */
3636 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3637 1.7.4.2 jdolecek
3638 1.7.4.2 jdolecek sctp_handle_asconf_ack(m, *offset,
3639 1.7.4.2 jdolecek (struct sctp_asconf_ack_chunk *)ch, stcb, *netp);
3640 1.7.4.2 jdolecek break;
3641 1.7.4.2 jdolecek case SCTP_FORWARD_CUM_TSN:
3642 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3643 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3644 1.7.4.2 jdolecek printf("SCTP_FWD-TSN\n");
3645 1.7.4.2 jdolecek }
3646 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3647 1.7.4.2 jdolecek /* He's alive so give him credit */
3648 1.7.4.2 jdolecek {
3649 1.7.4.2 jdolecek int abort_flag = 0;
3650 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3651 1.7.4.2 jdolecek *fwd_tsn_seen = 1;
3652 1.7.4.2 jdolecek sctp_handle_forward_tsn(stcb,
3653 1.7.4.2 jdolecek (struct sctp_forward_tsn_chunk *)ch, &abort_flag);
3654 1.7.4.2 jdolecek if (abort_flag) {
3655 1.7.4.2 jdolecek *offset = length;
3656 1.7.4.2 jdolecek return (NULL);
3657 1.7.4.2 jdolecek } else {
3658 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3659 1.7.4.2 jdolecek }
3660 1.7.4.2 jdolecek
3661 1.7.4.2 jdolecek }
3662 1.7.4.2 jdolecek break;
3663 1.7.4.2 jdolecek case SCTP_STREAM_RESET:
3664 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3665 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3666 1.7.4.2 jdolecek printf("SCTP_STREAM_RESET\n");
3667 1.7.4.2 jdolecek }
3668 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3669 1.7.4.2 jdolecek ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
3670 1.7.4.2 jdolecek chk_length, chunk_buf);
3671 1.7.4.2 jdolecek if (stcb->asoc.peer_supports_strreset == 0) {
3672 1.7.4.2 jdolecek /* hmm, peer should have annonced this, but
3673 1.7.4.2 jdolecek * we will turn it on since he is sending us
3674 1.7.4.2 jdolecek * a stream reset.
3675 1.7.4.2 jdolecek */
3676 1.7.4.2 jdolecek stcb->asoc.peer_supports_strreset = 1;
3677 1.7.4.2 jdolecek }
3678 1.7.4.2 jdolecek sctp_handle_stream_reset(stcb, (struct sctp_stream_reset_req *)ch);
3679 1.7.4.2 jdolecek break;
3680 1.7.4.2 jdolecek case SCTP_PACKET_DROPPED:
3681 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3682 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3683 1.7.4.2 jdolecek printf("SCTP_PACKET_DROPPED\n");
3684 1.7.4.2 jdolecek }
3685 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3686 1.7.4.2 jdolecek /* re-get it all please */
3687 1.7.4.2 jdolecek ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
3688 1.7.4.2 jdolecek chk_length, chunk_buf);
3689 1.7.4.2 jdolecek
3690 1.7.4.2 jdolecek sctp_handle_packet_dropped((struct sctp_pktdrop_chunk *)ch,
3691 1.7.4.2 jdolecek stcb, *netp);
3692 1.7.4.2 jdolecek
3693 1.7.4.2 jdolecek
3694 1.7.4.2 jdolecek break;
3695 1.7.4.2 jdolecek default:
3696 1.7.4.2 jdolecek /* it's an unknown chunk! */
3697 1.7.4.2 jdolecek if ((ch->chunk_type & 0x40) && (stcb != NULL)) {
3698 1.7.4.2 jdolecek struct mbuf *mm;
3699 1.7.4.2 jdolecek struct sctp_paramhdr *phd;
3700 1.7.4.2 jdolecek MGETHDR(mm, M_DONTWAIT, MT_HEADER);
3701 1.7.4.2 jdolecek if (mm) {
3702 1.7.4.2 jdolecek phd = mtod(mm, struct sctp_paramhdr *);
3703 1.7.4.2 jdolecek /* We cheat and use param type since we
3704 1.7.4.2 jdolecek * did not bother to define a error
3705 1.7.4.2 jdolecek * cause struct.
3706 1.7.4.2 jdolecek * They are the same basic format with
3707 1.7.4.2 jdolecek * different names.
3708 1.7.4.2 jdolecek */
3709 1.7.4.2 jdolecek phd->param_type =
3710 1.7.4.2 jdolecek htons(SCTP_CAUSE_UNRECOG_CHUNK);
3711 1.7.4.2 jdolecek phd->param_length =
3712 1.7.4.2 jdolecek htons(chk_length + sizeof(*phd));
3713 1.7.4.2 jdolecek mm->m_len = sizeof(*phd);
3714 1.7.4.2 jdolecek mm->m_next = sctp_m_copym(m, *offset,
3715 1.7.4.2 jdolecek SCTP_SIZE32(chk_length),
3716 1.7.4.2 jdolecek M_DONTWAIT);
3717 1.7.4.2 jdolecek if (mm->m_next) {
3718 1.7.4.2 jdolecek mm->m_pkthdr.len =
3719 1.7.4.2 jdolecek SCTP_SIZE32(chk_length) +
3720 1.7.4.2 jdolecek sizeof(*phd);
3721 1.7.4.2 jdolecek sctp_queue_op_err(stcb, mm);
3722 1.7.4.2 jdolecek } else {
3723 1.7.4.2 jdolecek sctp_m_freem(mm);
3724 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3725 1.7.4.2 jdolecek if (sctp_debug_on &
3726 1.7.4.2 jdolecek SCTP_DEBUG_INPUT1) {
3727 1.7.4.2 jdolecek printf("Gak can't copy the chunk into operr %d bytes\n",
3728 1.7.4.2 jdolecek chk_length);
3729 1.7.4.2 jdolecek }
3730 1.7.4.2 jdolecek #endif
3731 1.7.4.2 jdolecek }
3732 1.7.4.2 jdolecek }
3733 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3734 1.7.4.2 jdolecek else {
3735 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
3736 1.7.4.2 jdolecek printf("Gak can't mgethdr for op-err of unrec chunk\n");
3737 1.7.4.2 jdolecek }
3738 1.7.4.2 jdolecek }
3739 1.7.4.2 jdolecek #endif
3740 1.7.4.2 jdolecek }
3741 1.7.4.2 jdolecek if ((ch->chunk_type & 0x80) == 0) {
3742 1.7.4.2 jdolecek /* discard this packet */
3743 1.7.4.2 jdolecek *offset = length;
3744 1.7.4.2 jdolecek return (stcb);
3745 1.7.4.2 jdolecek } /* else skip this bad chunk and continue... */
3746 1.7.4.2 jdolecek break;
3747 1.7.4.2 jdolecek } /* switch (ch->chunk_type) */
3748 1.7.4.2 jdolecek /* get the next chunk */
3749 1.7.4.2 jdolecek *offset += SCTP_SIZE32(chk_length);
3750 1.7.4.2 jdolecek if (*offset >= length) {
3751 1.7.4.2 jdolecek /* no more data left in the mbuf chain */
3752 1.7.4.2 jdolecek break;
3753 1.7.4.2 jdolecek }
3754 1.7.4.2 jdolecek ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
3755 1.7.4.2 jdolecek sizeof(struct sctp_chunkhdr), chunk_buf);
3756 1.7.4.2 jdolecek if (ch == NULL) {
3757 1.7.4.2 jdolecek if (locked_tcb) {
3758 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(locked_tcb);
3759 1.7.4.2 jdolecek }
3760 1.7.4.2 jdolecek *offset = length;
3761 1.7.4.2 jdolecek return (NULL);
3762 1.7.4.2 jdolecek }
3763 1.7.4.2 jdolecek } /* while */
3764 1.7.4.2 jdolecek return (stcb);
3765 1.7.4.2 jdolecek }
3766 1.7.4.2 jdolecek
3767 1.7.4.2 jdolecek
3768 1.7.4.2 jdolecek /*
3769 1.7.4.2 jdolecek * Process the ECN bits we have something set so
3770 1.7.4.2 jdolecek * we must look to see if it is ECN(0) or ECN(1) or CE
3771 1.7.4.2 jdolecek */
3772 1.7.4.2 jdolecek static void
3773 1.7.4.2 jdolecek sctp_process_ecn_marked_a(struct sctp_tcb *stcb, struct sctp_nets *net,
3774 1.7.4.2 jdolecek u_int8_t ecn_bits)
3775 1.7.4.2 jdolecek {
3776 1.7.4.2 jdolecek if ((ecn_bits & SCTP_CE_BITS) == SCTP_CE_BITS) {
3777 1.7.4.2 jdolecek ;
3778 1.7.4.2 jdolecek } else if ((ecn_bits & SCTP_ECT1_BIT) == SCTP_ECT1_BIT) {
3779 1.7.4.2 jdolecek /*
3780 1.7.4.2 jdolecek * we only add to the nonce sum for ECT1, ECT0
3781 1.7.4.2 jdolecek * does not change the NS bit (that we have
3782 1.7.4.2 jdolecek * yet to find a way to send it yet).
3783 1.7.4.2 jdolecek */
3784 1.7.4.2 jdolecek
3785 1.7.4.2 jdolecek /* ECN Nonce stuff */
3786 1.7.4.2 jdolecek stcb->asoc.receiver_nonce_sum++;
3787 1.7.4.2 jdolecek stcb->asoc.receiver_nonce_sum &= SCTP_SACK_NONCE_SUM;
3788 1.7.4.2 jdolecek
3789 1.7.4.2 jdolecek /*
3790 1.7.4.2 jdolecek * Drag up the last_echo point if cumack is larger since we
3791 1.7.4.2 jdolecek * don't want the point falling way behind by more than 2^^31
3792 1.7.4.2 jdolecek * and then having it be incorrect.
3793 1.7.4.2 jdolecek */
3794 1.7.4.2 jdolecek if (compare_with_wrap(stcb->asoc.cumulative_tsn,
3795 1.7.4.2 jdolecek stcb->asoc.last_echo_tsn, MAX_TSN)) {
3796 1.7.4.2 jdolecek stcb->asoc.last_echo_tsn = stcb->asoc.cumulative_tsn;
3797 1.7.4.2 jdolecek }
3798 1.7.4.2 jdolecek } else if ((ecn_bits & SCTP_ECT0_BIT) == SCTP_ECT0_BIT) {
3799 1.7.4.2 jdolecek /*
3800 1.7.4.2 jdolecek * Drag up the last_echo point if cumack is larger since we
3801 1.7.4.2 jdolecek * don't want the point falling way behind by more than 2^^31
3802 1.7.4.2 jdolecek * and then having it be incorrect.
3803 1.7.4.2 jdolecek */
3804 1.7.4.2 jdolecek if (compare_with_wrap(stcb->asoc.cumulative_tsn,
3805 1.7.4.2 jdolecek stcb->asoc.last_echo_tsn, MAX_TSN)) {
3806 1.7.4.2 jdolecek stcb->asoc.last_echo_tsn = stcb->asoc.cumulative_tsn;
3807 1.7.4.2 jdolecek }
3808 1.7.4.2 jdolecek }
3809 1.7.4.2 jdolecek }
3810 1.7.4.2 jdolecek
3811 1.7.4.2 jdolecek static void
3812 1.7.4.2 jdolecek sctp_process_ecn_marked_b(struct sctp_tcb *stcb, struct sctp_nets *net,
3813 1.7.4.2 jdolecek u_int32_t high_tsn, u_int8_t ecn_bits)
3814 1.7.4.2 jdolecek {
3815 1.7.4.2 jdolecek if ((ecn_bits & SCTP_CE_BITS) == SCTP_CE_BITS) {
3816 1.7.4.2 jdolecek /*
3817 1.7.4.2 jdolecek * we possibly must notify the sender that a congestion
3818 1.7.4.2 jdolecek * window reduction is in order. We do this
3819 1.7.4.2 jdolecek * by adding a ECNE chunk to the output chunk
3820 1.7.4.2 jdolecek * queue. The incoming CWR will remove this chunk.
3821 1.7.4.2 jdolecek */
3822 1.7.4.2 jdolecek if (compare_with_wrap(high_tsn, stcb->asoc.last_echo_tsn,
3823 1.7.4.2 jdolecek MAX_TSN)) {
3824 1.7.4.2 jdolecek /* Yep, we need to add a ECNE */
3825 1.7.4.2 jdolecek sctp_send_ecn_echo(stcb, net, high_tsn);
3826 1.7.4.2 jdolecek stcb->asoc.last_echo_tsn = high_tsn;
3827 1.7.4.2 jdolecek }
3828 1.7.4.2 jdolecek }
3829 1.7.4.2 jdolecek }
3830 1.7.4.2 jdolecek
3831 1.7.4.2 jdolecek /*
3832 1.7.4.2 jdolecek * common input chunk processing (v4 and v6)
3833 1.7.4.2 jdolecek */
3834 1.7.4.2 jdolecek int
3835 1.7.4.2 jdolecek sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset,
3836 1.7.4.2 jdolecek int length, struct sctphdr *sh, struct sctp_chunkhdr *ch,
3837 1.7.4.2 jdolecek struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sctp_nets *net,
3838 1.7.4.2 jdolecek u_int8_t ecn_bits)
3839 1.7.4.2 jdolecek {
3840 1.7.4.2 jdolecek /*
3841 1.7.4.2 jdolecek * Control chunk processing
3842 1.7.4.2 jdolecek */
3843 1.7.4.2 jdolecek u_int32_t high_tsn;
3844 1.7.4.2 jdolecek int fwd_tsn_seen = 0, data_processed = 0;
3845 1.7.4.2 jdolecek struct mbuf *m = *mm;
3846 1.7.4.2 jdolecek int abort_flag = 0;
3847 1.7.4.2 jdolecek
3848 1.7.4.2 jdolecek sctp_pegs[SCTP_DATAGRAMS_RCVD]++;
3849 1.7.4.2 jdolecek #ifdef SCTP_AUDITING_ENABLED
3850 1.7.4.2 jdolecek sctp_audit_log(0xE0, 1);
3851 1.7.4.2 jdolecek sctp_auditing(0, inp, stcb, net);
3852 1.7.4.2 jdolecek #endif
3853 1.7.4.2 jdolecek
3854 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3855 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
3856 1.7.4.2 jdolecek printf("Ok, Common input processing called, m:%p iphlen:%d offset:%d length:%d\n",
3857 1.7.4.2 jdolecek m, iphlen, offset, length);
3858 1.7.4.2 jdolecek }
3859 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3860 1.7.4.2 jdolecek if (IS_SCTP_CONTROL(ch)) {
3861 1.7.4.2 jdolecek /* process the control portion of the SCTP packet */
3862 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3863 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
3864 1.7.4.2 jdolecek printf("Processing control\n");
3865 1.7.4.2 jdolecek }
3866 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3867 1.7.4.2 jdolecek
3868 1.7.4.2 jdolecek stcb = sctp_process_control(m, iphlen, &offset, length, sh, ch,
3869 1.7.4.2 jdolecek inp, stcb, &net, &fwd_tsn_seen);
3870 1.7.4.2 jdolecek } else {
3871 1.7.4.2 jdolecek /*
3872 1.7.4.2 jdolecek * no control chunks, so pre-process DATA chunks
3873 1.7.4.2 jdolecek * (these checks are taken care of by control processing)
3874 1.7.4.2 jdolecek */
3875 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3876 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
3877 1.7.4.2 jdolecek printf("No control present\n");
3878 1.7.4.2 jdolecek }
3879 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3880 1.7.4.2 jdolecek
3881 1.7.4.2 jdolecek if (stcb == NULL) {
3882 1.7.4.2 jdolecek /* out of the blue DATA chunk */
3883 1.7.4.2 jdolecek sctp_handle_ootb(m, iphlen, offset, sh, inp, NULL);
3884 1.7.4.2 jdolecek return (1);
3885 1.7.4.2 jdolecek }
3886 1.7.4.2 jdolecek if (stcb->asoc.my_vtag != ntohl(sh->v_tag)) {
3887 1.7.4.2 jdolecek /* v_tag mismatch! */
3888 1.7.4.2 jdolecek sctp_pegs[SCTP_BAD_VTAGS]++;
3889 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(stcb);
3890 1.7.4.2 jdolecek return (1);
3891 1.7.4.2 jdolecek }
3892 1.7.4.2 jdolecek }
3893 1.7.4.2 jdolecek if (stcb == NULL) {
3894 1.7.4.2 jdolecek /*
3895 1.7.4.2 jdolecek * no valid TCB for this packet,
3896 1.7.4.2 jdolecek * or we found it's a bad packet while processing control,
3897 1.7.4.2 jdolecek * or we're done with this packet (done or skip rest of data),
3898 1.7.4.2 jdolecek * so we drop it...
3899 1.7.4.2 jdolecek */
3900 1.7.4.2 jdolecek return (1);
3901 1.7.4.2 jdolecek }
3902 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3903 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
3904 1.7.4.2 jdolecek printf("Ok, control finished time to look for data (%d) offset:%d\n",
3905 1.7.4.2 jdolecek length, offset);
3906 1.7.4.2 jdolecek }
3907 1.7.4.2 jdolecek #endif /* SCTP_DEBUG */
3908 1.7.4.2 jdolecek /*
3909 1.7.4.2 jdolecek * DATA chunk processing
3910 1.7.4.2 jdolecek */
3911 1.7.4.2 jdolecek /* plow through the data chunks while length > offset */
3912 1.7.4.2 jdolecek stcb->asoc.seen_a_sack_this_pkt = 0;
3913 1.7.4.2 jdolecek
3914 1.7.4.2 jdolecek if (length > offset) {
3915 1.7.4.2 jdolecek int retval;
3916 1.7.4.2 jdolecek /*
3917 1.7.4.2 jdolecek * First check to make sure our state is correct.
3918 1.7.4.2 jdolecek * We would not get here unless we really did have a
3919 1.7.4.2 jdolecek * tag, so we don't abort if this happens, just
3920 1.7.4.2 jdolecek * dump the chunk silently.
3921 1.7.4.2 jdolecek */
3922 1.7.4.2 jdolecek switch (SCTP_GET_STATE(&stcb->asoc)) {
3923 1.7.4.2 jdolecek case SCTP_STATE_COOKIE_ECHOED:
3924 1.7.4.2 jdolecek /*
3925 1.7.4.2 jdolecek * we consider data with valid tags in
3926 1.7.4.2 jdolecek * this state shows us the cookie-ack was lost.
3927 1.7.4.2 jdolecek * Imply it was there.
3928 1.7.4.2 jdolecek */
3929 1.7.4.2 jdolecek stcb->asoc.overall_error_count = 0;
3930 1.7.4.2 jdolecek sctp_handle_cookie_ack(
3931 1.7.4.2 jdolecek (struct sctp_cookie_ack_chunk *)ch, stcb, net);
3932 1.7.4.2 jdolecek break;
3933 1.7.4.2 jdolecek case SCTP_STATE_COOKIE_WAIT:
3934 1.7.4.2 jdolecek /*
3935 1.7.4.2 jdolecek * We consider OOTB any data sent during asoc setup.
3936 1.7.4.2 jdolecek */
3937 1.7.4.2 jdolecek sctp_handle_ootb(m, iphlen, offset, sh, inp, NULL);
3938 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(stcb);
3939 1.7.4.2 jdolecek return (1);
3940 1.7.4.2 jdolecek break;
3941 1.7.4.2 jdolecek case SCTP_STATE_EMPTY: /* should not happen */
3942 1.7.4.2 jdolecek case SCTP_STATE_INUSE: /* should not happen */
3943 1.7.4.2 jdolecek case SCTP_STATE_SHUTDOWN_RECEIVED: /* This is a peer error */
3944 1.7.4.2 jdolecek case SCTP_STATE_SHUTDOWN_ACK_SENT:
3945 1.7.4.2 jdolecek default:
3946 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
3947 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
3948 1.7.4.2 jdolecek printf("Got data in invalid state %d.. dropping\n", stcb->asoc.state);
3949 1.7.4.2 jdolecek }
3950 1.7.4.2 jdolecek #endif
3951 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(stcb);
3952 1.7.4.2 jdolecek return (1);
3953 1.7.4.2 jdolecek break;
3954 1.7.4.2 jdolecek case SCTP_STATE_OPEN:
3955 1.7.4.2 jdolecek case SCTP_STATE_SHUTDOWN_SENT:
3956 1.7.4.2 jdolecek break;
3957 1.7.4.2 jdolecek }
3958 1.7.4.2 jdolecek /* take care of ECN, part 1. */
3959 1.7.4.2 jdolecek if (stcb->asoc.ecn_allowed &&
3960 1.7.4.2 jdolecek (ecn_bits & (SCTP_ECT0_BIT|SCTP_ECT1_BIT)) ) {
3961 1.7.4.2 jdolecek sctp_process_ecn_marked_a(stcb, net, ecn_bits);
3962 1.7.4.2 jdolecek }
3963 1.7.4.2 jdolecek /* plow through the data chunks while length > offset */
3964 1.7.4.2 jdolecek retval = sctp_process_data(mm, iphlen, &offset, length, sh,
3965 1.7.4.2 jdolecek inp, stcb, net, &high_tsn);
3966 1.7.4.2 jdolecek if (retval == 2) {
3967 1.7.4.2 jdolecek /* The association aborted, NO UNLOCK needed
3968 1.7.4.2 jdolecek * since the association is destroyed.
3969 1.7.4.2 jdolecek */
3970 1.7.4.2 jdolecek return (0);
3971 1.7.4.2 jdolecek }
3972 1.7.4.2 jdolecek
3973 1.7.4.2 jdolecek data_processed = 1;
3974 1.7.4.2 jdolecek if (retval == 0) {
3975 1.7.4.2 jdolecek /* take care of ecn part 2. */
3976 1.7.4.2 jdolecek if (stcb->asoc.ecn_allowed && (ecn_bits & (SCTP_ECT0_BIT|SCTP_ECT1_BIT)) ) {
3977 1.7.4.2 jdolecek sctp_process_ecn_marked_b(stcb, net, high_tsn, ecn_bits);
3978 1.7.4.2 jdolecek
3979 1.7.4.2 jdolecek }
3980 1.7.4.2 jdolecek }
3981 1.7.4.2 jdolecek
3982 1.7.4.2 jdolecek /*
3983 1.7.4.2 jdolecek * Anything important needs to have been m_copy'ed in
3984 1.7.4.2 jdolecek * process_data
3985 1.7.4.2 jdolecek */
3986 1.7.4.2 jdolecek }
3987 1.7.4.2 jdolecek if ((data_processed == 0) && (fwd_tsn_seen)) {
3988 1.7.4.2 jdolecek int was_a_gap = 0;
3989 1.7.4.2 jdolecek if (compare_with_wrap(stcb->asoc.highest_tsn_inside_map,
3990 1.7.4.2 jdolecek stcb->asoc.cumulative_tsn, MAX_TSN)) {
3991 1.7.4.2 jdolecek /* there was a gap before this data was processed */
3992 1.7.4.2 jdolecek was_a_gap = 1;
3993 1.7.4.2 jdolecek }
3994 1.7.4.2 jdolecek sctp_sack_check(stcb, 1, was_a_gap, &abort_flag);
3995 1.7.4.2 jdolecek if (abort_flag) {
3996 1.7.4.2 jdolecek /* Again, we aborted so NO UNLOCK needed */
3997 1.7.4.2 jdolecek return (0);
3998 1.7.4.2 jdolecek }
3999 1.7.4.2 jdolecek }
4000 1.7.4.2 jdolecek /* trigger send of any chunks in queue... */
4001 1.7.4.2 jdolecek #ifdef SCTP_AUDITING_ENABLED
4002 1.7.4.2 jdolecek sctp_audit_log(0xE0, 2);
4003 1.7.4.2 jdolecek sctp_auditing(1, inp, stcb, net);
4004 1.7.4.2 jdolecek #endif
4005 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
4006 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
4007 1.7.4.2 jdolecek printf("Check for chunk output prw:%d tqe:%d tf=%d\n",
4008 1.7.4.2 jdolecek stcb->asoc.peers_rwnd,
4009 1.7.4.2 jdolecek TAILQ_EMPTY(&stcb->asoc.control_send_queue),
4010 1.7.4.2 jdolecek stcb->asoc.total_flight);
4011 1.7.4.2 jdolecek }
4012 1.7.4.2 jdolecek #endif
4013 1.7.4.2 jdolecek if (stcb->asoc.peers_rwnd > 0 ||
4014 1.7.4.2 jdolecek !TAILQ_EMPTY(&stcb->asoc.control_send_queue) ||
4015 1.7.4.2 jdolecek (stcb->asoc.peers_rwnd <= 0 && stcb->asoc.total_flight == 0)) {
4016 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
4017 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
4018 1.7.4.2 jdolecek printf("Calling chunk OUTPUT\n");
4019 1.7.4.2 jdolecek }
4020 1.7.4.2 jdolecek #endif
4021 1.7.4.2 jdolecek sctp_chunk_output(inp, stcb, 3);
4022 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
4023 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT3) {
4024 1.7.4.2 jdolecek printf("chunk OUTPUT returns\n");
4025 1.7.4.2 jdolecek }
4026 1.7.4.2 jdolecek #endif
4027 1.7.4.2 jdolecek }
4028 1.7.4.2 jdolecek
4029 1.7.4.2 jdolecek #ifdef SCTP_AUDITING_ENABLED
4030 1.7.4.2 jdolecek sctp_audit_log(0xE0, 3);
4031 1.7.4.2 jdolecek sctp_auditing(2, inp, stcb, net);
4032 1.7.4.2 jdolecek #endif
4033 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(stcb);
4034 1.7.4.2 jdolecek return (0);
4035 1.7.4.2 jdolecek }
4036 1.7.4.2 jdolecek
4037 1.7.4.2 jdolecek #if defined(__OpenBSD__)
4038 1.7.4.2 jdolecek static void
4039 1.7.4.2 jdolecek sctp_saveopt(struct sctp_inpcb *inp, struct mbuf **mp, struct ip *ip,
4040 1.7.4.2 jdolecek struct mbuf *m)
4041 1.7.4.2 jdolecek {
4042 1.7.4.2 jdolecek if (inp->ip_inp.inp.inp_flags & INP_RECVDSTADDR) {
4043 1.7.4.2 jdolecek *mp = sbcreatecontrol((vaddr_t) &ip->ip_dst,
4044 1.7.4.2 jdolecek sizeof(struct in_addr), IP_RECVDSTADDR, IPPROTO_IP);
4045 1.7.4.2 jdolecek if (*mp)
4046 1.7.4.2 jdolecek mp = &(*mp)->m_next;
4047 1.7.4.2 jdolecek }
4048 1.7.4.2 jdolecek }
4049 1.7.4.2 jdolecek #endif
4050 1.7.4.2 jdolecek
4051 1.7.4.2 jdolecek extern int sctp_no_csum_on_loopback;
4052 1.7.4.2 jdolecek
4053 1.7.4.2 jdolecek void
4054 1.7.4.2 jdolecek sctp_input(struct mbuf *m, ...)
4055 1.7.4.2 jdolecek {
4056 1.7.4.2 jdolecek int iphlen;
4057 1.7.4.2 jdolecek u_int8_t ecn_bits;
4058 1.7.4.2 jdolecek struct ip *ip;
4059 1.7.4.2 jdolecek struct sctphdr *sh;
4060 1.7.4.2 jdolecek struct sctp_inpcb *inp = NULL;
4061 1.7.4.2 jdolecek struct mbuf *opts = 0;
4062 1.7.4.2 jdolecek /*#ifdef INET6*/
4063 1.7.4.2 jdolecek /* Don't think this is needed */
4064 1.7.4.2 jdolecek /* struct ip6_recvpktopts opts6;*/
4065 1.7.4.2 jdolecek /*#endif INET6 */
4066 1.7.4.2 jdolecek
4067 1.7.4.2 jdolecek u_int32_t check, calc_check;
4068 1.7.4.2 jdolecek struct sctp_nets *net;
4069 1.7.4.2 jdolecek struct sctp_tcb *stcb = NULL;
4070 1.7.4.2 jdolecek struct sctp_chunkhdr *ch;
4071 1.7.4.2 jdolecek int refcount_up = 0;
4072 1.7.4.2 jdolecek int length, mlen, offset;
4073 1.7.4.2 jdolecek
4074 1.7.4.2 jdolecek int off;
4075 1.7.4.2 jdolecek va_list ap;
4076 1.7.4.2 jdolecek
4077 1.7.4.2 jdolecek va_start(ap, m);
4078 1.7.4.2 jdolecek iphlen = off = va_arg(ap, int);
4079 1.7.4.2 jdolecek va_end(ap);
4080 1.7.4.2 jdolecek
4081 1.7.4.2 jdolecek net = NULL;
4082 1.7.4.2 jdolecek sctp_pegs[SCTP_INPKTS]++;
4083 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
4084 1.7.4.2 jdolecek /*if (sctp_debug_on & SCTP_DEBUG_INPUT1) {*/
4085 1.7.4.2 jdolecek printf("V4 input gets a packet iphlen:%d pktlen:%d\n", iphlen, m->m_pkthdr.len);
4086 1.7.4.2 jdolecek /*}*/
4087 1.7.4.2 jdolecek #endif
4088 1.7.4.2 jdolecek /*#ifdef INET6*/
4089 1.7.4.2 jdolecek /* Don't think this is needed */
4090 1.7.4.2 jdolecek /* bzero(&opts6, sizeof(opts6));*/
4091 1.7.4.2 jdolecek /*#endif INET6 */
4092 1.7.4.2 jdolecek
4093 1.7.4.2 jdolecek /*
4094 1.7.4.2 jdolecek * Strip IP options, we don't allow any in or out.
4095 1.7.4.2 jdolecek */
4096 1.7.4.2 jdolecek if ((size_t)iphlen > sizeof(struct ip)) {
4097 1.7.4.2 jdolecek printf("sctp_input: got options\n");
4098 1.7.4.2 jdolecek #if 0 /* XXX */
4099 1.7.4.2 jdolecek ip_stripoptions(m, (struct mbuf *)0);
4100 1.7.4.2 jdolecek #endif
4101 1.7.4.2 jdolecek iphlen = sizeof(struct ip);
4102 1.7.4.2 jdolecek }
4103 1.7.4.2 jdolecek
4104 1.7.4.2 jdolecek /*
4105 1.7.4.2 jdolecek * Get IP, SCTP, and first chunk header together in first mbuf.
4106 1.7.4.2 jdolecek */
4107 1.7.4.2 jdolecek ip = mtod(m, struct ip *);
4108 1.7.4.2 jdolecek offset = iphlen + sizeof(*sh) + sizeof(*ch);
4109 1.7.4.2 jdolecek if (m->m_len < offset) {
4110 1.7.4.2 jdolecek if ((m = m_pullup(m, offset)) == 0) {
4111 1.7.4.2 jdolecek sctp_pegs[SCTP_HDR_DROPS]++;
4112 1.7.4.2 jdolecek return;
4113 1.7.4.2 jdolecek }
4114 1.7.4.2 jdolecek ip = mtod(m, struct ip *);
4115 1.7.4.2 jdolecek }
4116 1.7.4.2 jdolecek sh = (struct sctphdr *)((vaddr_t)ip + iphlen);
4117 1.7.4.2 jdolecek ch = (struct sctp_chunkhdr *)((vaddr_t)sh + sizeof(*sh));
4118 1.7.4.2 jdolecek
4119 1.7.4.2 jdolecek /* SCTP does not allow broadcasts or multicasts */
4120 1.7.4.2 jdolecek if (IN_MULTICAST(ip->ip_dst.s_addr))
4121 1.7.4.2 jdolecek {
4122 1.7.4.2 jdolecek sctp_pegs[SCTP_IN_MCAST]++;
4123 1.7.4.2 jdolecek goto bad;
4124 1.7.4.2 jdolecek }
4125 1.7.4.2 jdolecek if (in_broadcast(ip->ip_dst, m_get_rcvif_NOMPSAFE(m))) {
4126 1.7.4.2 jdolecek sctp_pegs[SCTP_IN_MCAST]++;
4127 1.7.4.2 jdolecek goto bad;
4128 1.7.4.2 jdolecek }
4129 1.7.4.2 jdolecek
4130 1.7.4.2 jdolecek /* destination port of 0 is illegal, based on RFC2960. */
4131 1.7.4.2 jdolecek if (sh->dest_port == 0) {
4132 1.7.4.2 jdolecek sctp_pegs[SCTP_HDR_DROPS]++;
4133 1.7.4.2 jdolecek goto bad;
4134 1.7.4.2 jdolecek }
4135 1.7.4.2 jdolecek
4136 1.7.4.2 jdolecek /* validate SCTP checksum */
4137 1.7.4.2 jdolecek if ((sctp_no_csum_on_loopback == 0) ||
4138 1.7.4.2 jdolecek (m_get_rcvif_NOMPSAFE(m) == NULL) ||
4139 1.7.4.2 jdolecek (m_get_rcvif_NOMPSAFE(m)->if_type != IFT_LOOP)) {
4140 1.7.4.2 jdolecek /* we do NOT validate things from the loopback if the
4141 1.7.4.2 jdolecek * sysctl is set to 1.
4142 1.7.4.2 jdolecek */
4143 1.7.4.2 jdolecek check = sh->checksum; /* save incoming checksum */
4144 1.7.4.2 jdolecek if ((check == 0) && (sctp_no_csum_on_loopback)) {
4145 1.7.4.2 jdolecek /* special hook for where we got a local address
4146 1.7.4.2 jdolecek * somehow routed across a non IFT_LOOP type interface
4147 1.7.4.2 jdolecek */
4148 1.7.4.2 jdolecek if (ip->ip_src.s_addr == ip->ip_dst.s_addr)
4149 1.7.4.2 jdolecek goto sctp_skip_csum_4;
4150 1.7.4.2 jdolecek }
4151 1.7.4.2 jdolecek sh->checksum = 0; /* prepare for calc */
4152 1.7.4.2 jdolecek calc_check = sctp_calculate_sum(m, &mlen, iphlen);
4153 1.7.4.2 jdolecek if (calc_check != check) {
4154 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
4155 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
4156 1.7.4.2 jdolecek printf("Bad CSUM on SCTP packet calc_check:%x check:%x m:%p mlen:%d iphlen:%d\n",
4157 1.7.4.2 jdolecek calc_check, check, m, mlen, iphlen);
4158 1.7.4.2 jdolecek }
4159 1.7.4.2 jdolecek #endif
4160 1.7.4.2 jdolecek
4161 1.7.4.2 jdolecek stcb = sctp_findassociation_addr(m, iphlen,
4162 1.7.4.2 jdolecek offset - sizeof(*ch),
4163 1.7.4.2 jdolecek sh, ch, &inp, &net);
4164 1.7.4.2 jdolecek if ((inp) && (stcb)) {
4165 1.7.4.2 jdolecek sctp_send_packet_dropped(stcb, net, m, iphlen,
4166 1.7.4.2 jdolecek 1);
4167 1.7.4.2 jdolecek sctp_chunk_output(inp, stcb, 2);
4168 1.7.4.2 jdolecek } else if ((inp != NULL) && (stcb == NULL)) {
4169 1.7.4.2 jdolecek refcount_up = 1;
4170 1.7.4.2 jdolecek }
4171 1.7.4.2 jdolecek sctp_pegs[SCTP_BAD_CSUM]++;
4172 1.7.4.2 jdolecek goto bad;
4173 1.7.4.2 jdolecek }
4174 1.7.4.2 jdolecek sh->checksum = calc_check;
4175 1.7.4.2 jdolecek } else {
4176 1.7.4.2 jdolecek sctp_skip_csum_4:
4177 1.7.4.2 jdolecek mlen = m->m_pkthdr.len;
4178 1.7.4.2 jdolecek }
4179 1.7.4.2 jdolecek /* validate mbuf chain length with IP payload length */
4180 1.7.4.2 jdolecek #if defined(__NetBSD__) || defined(__OpenBSD__)
4181 1.7.4.2 jdolecek /* Open BSD gives us the len in network order, fix it */
4182 1.7.4.2 jdolecek NTOHS(ip->ip_len);
4183 1.7.4.2 jdolecek #endif
4184 1.7.4.2 jdolecek if (mlen < (ip->ip_len - iphlen)) {
4185 1.7.4.2 jdolecek sctp_pegs[SCTP_HDR_DROPS]++;
4186 1.7.4.2 jdolecek goto bad;
4187 1.7.4.2 jdolecek }
4188 1.7.4.2 jdolecek
4189 1.7.4.2 jdolecek /*
4190 1.7.4.2 jdolecek * Locate pcb and tcb for datagram
4191 1.7.4.2 jdolecek * sctp_findassociation_addr() wants IP/SCTP/first chunk header...
4192 1.7.4.2 jdolecek */
4193 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
4194 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
4195 1.7.4.2 jdolecek printf("V4 find association\n");
4196 1.7.4.2 jdolecek }
4197 1.7.4.2 jdolecek #endif
4198 1.7.4.2 jdolecek
4199 1.7.4.2 jdolecek stcb = sctp_findassociation_addr(m, iphlen, offset - sizeof(*ch),
4200 1.7.4.2 jdolecek sh, ch, &inp, &net);
4201 1.7.4.2 jdolecek /* inp's ref-count increased && stcb locked */
4202 1.7.4.2 jdolecek if (inp == NULL) {
4203 1.7.4.2 jdolecek struct sctp_init_chunk *init_chk, chunk_buf;
4204 1.7.4.2 jdolecek
4205 1.7.4.2 jdolecek sctp_pegs[SCTP_NOPORTS]++;
4206 1.7.4.2 jdolecek #ifdef ICMP_BANDLIM
4207 1.7.4.2 jdolecek /*
4208 1.7.4.2 jdolecek * we use the bandwidth limiting to protect against
4209 1.7.4.2 jdolecek * sending too many ABORTS all at once. In this case
4210 1.7.4.2 jdolecek * these count the same as an ICMP message.
4211 1.7.4.2 jdolecek */
4212 1.7.4.2 jdolecek if (badport_bandlim(0) < 0)
4213 1.7.4.2 jdolecek goto bad;
4214 1.7.4.2 jdolecek #endif /* ICMP_BANDLIM */
4215 1.7.4.2 jdolecek #ifdef SCTP_DEBUG
4216 1.7.4.2 jdolecek if (sctp_debug_on & SCTP_DEBUG_INPUT1) {
4217 1.7.4.2 jdolecek printf("Sending a ABORT from packet entry!\n");
4218 1.7.4.2 jdolecek }
4219 1.7.4.2 jdolecek #endif
4220 1.7.4.2 jdolecek if (ch->chunk_type == SCTP_INITIATION) {
4221 1.7.4.2 jdolecek /* we do a trick here to get the INIT tag,
4222 1.7.4.2 jdolecek * dig in and get the tag from the INIT and
4223 1.7.4.2 jdolecek * put it in the common header.
4224 1.7.4.2 jdolecek */
4225 1.7.4.2 jdolecek init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m,
4226 1.7.4.2 jdolecek iphlen + sizeof(*sh), sizeof(*init_chk),
4227 1.7.4.2 jdolecek (u_int8_t *)&chunk_buf);
4228 1.7.4.2 jdolecek if (init_chk != NULL)
4229 1.7.4.2 jdolecek sh->v_tag = init_chk->init.initiate_tag;
4230 1.7.4.2 jdolecek }
4231 1.7.4.2 jdolecek sctp_send_abort(m, iphlen, sh, 0, NULL);
4232 1.7.4.2 jdolecek goto bad;
4233 1.7.4.2 jdolecek } else if (stcb == NULL) {
4234 1.7.4.2 jdolecek refcount_up = 1;
4235 1.7.4.2 jdolecek }
4236 1.7.4.2 jdolecek #ifdef IPSEC
4237 1.7.4.2 jdolecek /*
4238 1.7.4.2 jdolecek * I very much doubt any of the IPSEC stuff will work but I have
4239 1.7.4.2 jdolecek * no idea, so I will leave it in place.
4240 1.7.4.2 jdolecek */
4241 1.7.4.2 jdolecek if (ipsec_used && ipsec4_in_reject(m, (struct inpcb *)inp)) {
4242 1.7.4.2 jdolecek #if 0
4243 1.7.4.2 jdolecek ipsecstat.in_polvio++;
4244 1.7.4.2 jdolecek #endif
4245 1.7.4.2 jdolecek sctp_pegs[SCTP_HDR_DROPS]++;
4246 1.7.4.2 jdolecek goto bad;
4247 1.7.4.2 jdolecek }
4248 1.7.4.2 jdolecek #endif /* IPSEC */
4249 1.7.4.2 jdolecek
4250 1.7.4.2 jdolecek /*
4251 1.7.4.2 jdolecek * Construct sockaddr format source address.
4252 1.7.4.2 jdolecek * Stuff source address and datagram in user buffer.
4253 1.7.4.2 jdolecek */
4254 1.7.4.2 jdolecek if ((inp->ip_inp.inp.inp_flags & INP_CONTROLOPTS)
4255 1.7.4.2 jdolecek || (inp->sctp_socket->so_options & SO_TIMESTAMP)
4256 1.7.4.2 jdolecek ) {
4257 1.7.4.2 jdolecek ip_savecontrol((struct inpcb *)inp, &opts, ip, m);
4258 1.7.4.2 jdolecek }
4259 1.7.4.2 jdolecek
4260 1.7.4.2 jdolecek /*
4261 1.7.4.2 jdolecek * common chunk processing
4262 1.7.4.2 jdolecek */
4263 1.7.4.2 jdolecek length = ip->ip_len - (ip->ip_hl << 2) + iphlen;
4264 1.7.4.2 jdolecek offset -= sizeof(struct sctp_chunkhdr);
4265 1.7.4.2 jdolecek
4266 1.7.4.2 jdolecek ecn_bits = ip->ip_tos;
4267 1.7.4.2 jdolecek sctp_common_input_processing(&m, iphlen, offset, length, sh, ch,
4268 1.7.4.2 jdolecek inp, stcb, net, ecn_bits);
4269 1.7.4.2 jdolecek /* inp's ref-count reduced && stcb unlocked */
4270 1.7.4.2 jdolecek if (m) {
4271 1.7.4.2 jdolecek sctp_m_freem(m);
4272 1.7.4.2 jdolecek }
4273 1.7.4.2 jdolecek if (opts)
4274 1.7.4.2 jdolecek sctp_m_freem(opts);
4275 1.7.4.2 jdolecek
4276 1.7.4.2 jdolecek if ((inp) && (refcount_up)) {
4277 1.7.4.2 jdolecek /* reduce ref-count */
4278 1.7.4.2 jdolecek SCTP_INP_WLOCK(inp);
4279 1.7.4.2 jdolecek SCTP_INP_DECR_REF(inp);
4280 1.7.4.2 jdolecek SCTP_INP_WUNLOCK(inp);
4281 1.7.4.2 jdolecek }
4282 1.7.4.2 jdolecek
4283 1.7.4.2 jdolecek return;
4284 1.7.4.2 jdolecek bad:
4285 1.7.4.2 jdolecek if (stcb) {
4286 1.7.4.2 jdolecek SCTP_TCB_UNLOCK(stcb);
4287 1.7.4.2 jdolecek }
4288 1.7.4.2 jdolecek
4289 1.7.4.2 jdolecek if ((inp) && (refcount_up)) {
4290 1.7.4.2 jdolecek /* reduce ref-count */
4291 1.7.4.2 jdolecek SCTP_INP_WLOCK(inp);
4292 1.7.4.2 jdolecek SCTP_INP_DECR_REF(inp);
4293 1.7.4.2 jdolecek SCTP_INP_WUNLOCK(inp);
4294 1.7.4.2 jdolecek }
4295 1.7.4.2 jdolecek
4296 1.7.4.2 jdolecek if (m) {
4297 1.7.4.2 jdolecek sctp_m_freem(m);
4298 1.7.4.2 jdolecek }
4299 1.7.4.2 jdolecek if (opts)
4300 1.7.4.2 jdolecek sctp_m_freem(opts);
4301 1.7.4.2 jdolecek return;
4302 1.7.4.2 jdolecek }
4303