2 * Copyright (c) 2001-2006, Cisco Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 /* $KAME: sctp_pcb.h,v 1.21 2005/07/16 01:18:47 suz Exp $ */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #ifndef __sctp_pcb_h__
37 #define __sctp_pcb_h__
42 * We must have V6 so the size of the proto can be calculated. Otherwise we
43 * would not allocate enough for Net/Open BSD :-<
50 #include <sys/socket.h>
51 #include <sys/socketvar.h>
53 #include <net/if_types.h>
54 #include <net/if_var.h>
55 #include <net/route.h>
56 #include <netinet/in.h>
57 #include <netinet/ip6.h>
58 #include <netinet6/ip6_var.h>
59 #include <netinet6/ip6protosw.h>
60 #include <netinet6/in6_var.h>
61 #include <netinet6/in6_pcb.h>
67 #include <netinet/sctp.h>
68 #include <netinet/sctp_os.h>
69 #include <netinet/sctp_constants.h>
71 LIST_HEAD(sctppcbhead, sctp_inpcb);
72 LIST_HEAD(sctpasochead, sctp_tcb);
73 LIST_HEAD(sctpladdr, sctp_laddr);
74 LIST_HEAD(sctpvtaghead, sctp_tagblock);
75 TAILQ_HEAD(sctp_readhead, sctp_queued_to_read);
76 TAILQ_HEAD(sctp_streamhead, sctp_stream_queue_pending);
78 #include <netinet/sctp_structs.h>
79 #include <netinet/sctp_uio.h>
80 #include <netinet/sctp_auth.h>
83 * PCB flags (in sctp_flags bitmask)
85 #define SCTP_PCB_FLAGS_UDPTYPE 0x00000001
86 #define SCTP_PCB_FLAGS_TCPTYPE 0x00000002
87 #define SCTP_PCB_FLAGS_BOUNDALL 0x00000004
88 #define SCTP_PCB_FLAGS_ACCEPTING 0x00000008
89 #define SCTP_PCB_FLAGS_UNBOUND 0x00000010
90 #define SCTP_PCB_FLAGS_CLOSE_IP 0x00040000
91 #define SCTP_PCB_FLAGS_WAS_CONNECTED 0x00080000
92 #define SCTP_PCB_FLAGS_WAS_ABORTED 0x00100000
93 /* TCP model support */
95 #define SCTP_PCB_FLAGS_CONNECTED 0x00200000
96 #define SCTP_PCB_FLAGS_IN_TCPPOOL 0x00400000
97 #define SCTP_PCB_FLAGS_DONT_WAKE 0x00800000
98 #define SCTP_PCB_FLAGS_WAKEOUTPUT 0x01000000
99 #define SCTP_PCB_FLAGS_WAKEINPUT 0x02000000
100 #define SCTP_PCB_FLAGS_BOUND_V6 0x04000000
101 #define SCTP_PCB_FLAGS_NEEDS_MAPPED_V4 0x08000000
102 #define SCTP_PCB_FLAGS_BLOCKING_IO 0x10000000
103 #define SCTP_PCB_FLAGS_SOCKET_GONE 0x20000000
104 #define SCTP_PCB_FLAGS_SOCKET_ALLGONE 0x40000000
105 /* flags to copy to new PCB */
106 #define SCTP_PCB_COPY_FLAGS 0x0e000004
110 * PCB Features (in sctp_features bitmask)
112 #define SCTP_PCB_FLAGS_EXT_RCVINFO 0x00000004
113 #define SCTP_PCB_FLAGS_DONOT_HEARTBEAT 0x00000008
114 #define SCTP_PCB_FLAGS_FRAG_INTERLEAVE 0x00000010
115 #define SCTP_PCB_FLAGS_DO_ASCONF 0x00000020
116 #define SCTP_PCB_FLAGS_AUTO_ASCONF 0x00000040
118 #define SCTP_PCB_FLAGS_NODELAY 0x00000100
119 #define SCTP_PCB_FLAGS_AUTOCLOSE 0x00000200
120 #define SCTP_PCB_FLAGS_RECVDATAIOEVNT 0x00000400
121 #define SCTP_PCB_FLAGS_RECVASSOCEVNT 0x00000800
122 #define SCTP_PCB_FLAGS_RECVPADDREVNT 0x00001000
123 #define SCTP_PCB_FLAGS_RECVPEERERR 0x00002000
124 #define SCTP_PCB_FLAGS_RECVSENDFAILEVNT 0x00004000
125 #define SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT 0x00008000
126 #define SCTP_PCB_FLAGS_ADAPTATIONEVNT 0x00010000
127 #define SCTP_PCB_FLAGS_PDAPIEVNT 0x00020000
128 #define SCTP_PCB_FLAGS_AUTHEVNT 0x00040000
129 #define SCTP_PCB_FLAGS_STREAM_RESETEVNT 0x00080000
130 #define SCTP_PCB_FLAGS_NO_FRAGMENT 0x00100000
131 #define SCTP_PCB_FLAGS_EXPLICIT_EOR 0x00200000
134 #define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask)
135 #define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask)
138 LIST_ENTRY(sctp_laddr) sctp_nxt_addr; /* next in list */
140 int action; /* Only used in delayed asconf stuff */
143 struct sctp_block_entry {
147 struct sctp_timewait {
148 uint32_t tv_sec_at_expire; /* the seconds from boot to expire */
149 uint32_t v_tag; /* the vtag that can not be reused */
152 struct sctp_tagblock {
153 LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock;
154 struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
159 struct sctpasochead *sctp_asochash;
162 struct sctppcbhead *sctp_ephash;
165 struct sctpasochead *sctp_restarthash;
166 u_long hashrestartmark;
168 * The TCP model represents a substantial overhead in that we get an
169 * additional hash table to keep explicit connections in. The
170 * listening TCP endpoint will exist in the usual ephash above and
171 * accept only INIT's. It will be incapable of sending off an INIT.
172 * When a dg arrives we must look in the normal ephash. If we find a
173 * TCP endpoint that will tell us to go to the specific endpoint
174 * hash and re-hash to find the right assoc/socket. If we find a UDP
175 * model socket we then must complete the lookup. If this fails,
176 * i.e. no association can be found then we must continue to see if
177 * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket
178 * acts like a TCP model connected socket).
180 struct sctppcbhead *sctp_tcpephash;
182 uint32_t hashtblsize;
184 struct sctppcbhead listhead;
185 struct sctpladdr addr_wq;
187 struct sctpiterators iteratorhead;
190 sctp_zone_t ipi_zone_ep;
191 sctp_zone_t ipi_zone_asoc;
192 sctp_zone_t ipi_zone_laddr;
193 sctp_zone_t ipi_zone_net;
194 sctp_zone_t ipi_zone_chunk;
195 sctp_zone_t ipi_zone_readq;
196 sctp_zone_t ipi_zone_strmoq;
198 struct mtx ipi_ep_mtx;
200 struct mtx ipi_addr_mtx;
201 struct mtx timer_mtx;
202 uint32_t ipi_count_ep;
204 /* assoc/tcb zone info */
205 uint32_t ipi_count_asoc;
207 /* local addrlist zone info */
208 uint32_t ipi_count_laddr;
210 /* remote addrlist zone info */
211 uint32_t ipi_count_raddr;
213 /* chunk structure list for output */
214 uint32_t ipi_count_chunk;
216 /* socket queue zone info */
217 uint32_t ipi_count_readq;
219 /* socket queue zone info */
220 uint32_t ipi_count_strmoq;
222 /* system wide number of free chunks hanging around */
223 uint32_t ipi_free_chunks;
224 uint32_t ipi_free_strmoq;
226 struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
229 struct sctp_timer addr_wq_timer;
231 /* for port allocations */
238 extern struct sctpstat sctpstat;
241 * Here we have all the relevant information for each SCTP entity created. We
242 * will need to modify this as approprate. We also need to figure out how to
243 * access /dev/random.
246 unsigned int time_of_secret_change; /* number of seconds from
248 uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
249 unsigned int size_of_a_cookie;
251 unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
252 unsigned int sctp_minrto;
253 unsigned int sctp_maxrto;
254 unsigned int initial_rto;
256 int initial_init_rto_max;
258 uint32_t sctp_sws_sender;
259 uint32_t sctp_sws_receiver;
261 /* authentication related fields */
262 struct sctp_keyhead shared_keys;
263 sctp_auth_chklist_t *local_auth_chunks;
264 sctp_hmaclist_t *local_hmacs;
265 uint16_t default_keyid;
267 /* various thresholds */
268 /* Max times I will init at a guy */
269 uint16_t max_init_times;
271 /* Max times I will send before we consider someone dead */
272 uint16_t max_send_times;
274 uint16_t def_net_failure;
276 /* number of streams to pre-open on a association */
277 uint16_t pre_open_stream_count;
278 uint16_t max_open_streams_intome;
280 /* random number generator */
281 uint32_t random_counter;
282 uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
283 uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
286 * This timer is kept running per endpoint. When it fires it will
287 * change the secret key. The default is once a hour
289 struct sctp_timer signature_change;
293 uint32_t initial_sequence_debug;
294 uint32_t adaptation_layer_indicator;
297 char current_secret_number;
298 char last_secret_number;
301 #ifndef SCTP_ALIGNMENT
302 #define SCTP_ALIGNMENT 32
306 #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
309 #define sctp_lport ip_inp.inp.inp_lport
313 * put an inpcb in front of it all, kind of a waste but we need to
314 * for compatability with all the other stuff.
318 char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) &
323 /* Socket buffer lock protects read_queue and of course sb_cc */
324 struct sctp_readhead read_queue;
326 LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */
327 /* hash of all endpoints for model */
328 LIST_ENTRY(sctp_inpcb) sctp_hash;
329 /* count of local addresses bound, 0 if bound all */
331 /* list of addrs in use by the EP */
332 struct sctpladdr sctp_addr_list;
333 /* used for source address selection rotation */
334 struct sctp_laddr *next_addr_touse;
335 struct ifnet *next_ifn_touse;
336 /* back pointer to our socket */
337 struct socket *sctp_socket;
338 uint32_t sctp_flags; /* INP state flag set */
339 uint32_t sctp_features; /* Feature flags */
340 struct sctp_pcb sctp_ep;/* SCTP ep data */
341 /* head of the hash of all associations */
342 struct sctpasochead *sctp_tcbhash;
343 u_long sctp_hashmark;
344 /* head of the list of all associations */
345 struct sctpasochead sctp_asoc_list;
346 #ifdef SCTP_TRACK_FREED_ASOCS
347 struct sctpasochead sctp_asoc_free_list;
349 struct sctp_iterator *inp_starting_point_for_iterator;
350 uint32_t sctp_frag_point;
351 uint32_t partial_delivery_point;
352 uint32_t sctp_context;
353 struct sctp_sndrcvinfo def_send;
355 * These three are here for the sosend_dgram (pkt, pkt_last and
356 * control). routine. However, I don't think anyone in the current
357 * FreeBSD kernel calls this. So they are candidates with sctp_sendm
360 struct mbuf *pkt, *pkt_last;
361 struct mbuf *control;
363 struct mtx inp_create_mtx;
364 struct mtx inp_rdata_mtx;
366 uint32_t total_sends;
367 uint32_t total_recvs;
368 uint32_t last_abort_code;
369 uint32_t total_nospaces;
373 struct socket *sctp_socket; /* back pointer to socket */
374 struct sctp_inpcb *sctp_ep; /* back pointer to ep */
375 LIST_ENTRY(sctp_tcb) sctp_tcbhash; /* next link in hash
377 LIST_ENTRY(sctp_tcb) sctp_tcblist; /* list of all of the
379 LIST_ENTRY(sctp_tcb) sctp_tcbrestarhash; /* next link in restart
381 LIST_ENTRY(sctp_tcb) sctp_asocs; /* vtag hash list */
382 struct sctp_block_entry *block_entry; /* pointer locked by socket
384 struct sctp_association asoc;
386 * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the
387 * tcb_lock. Its special in this way to help avoid extra mutex calls
388 * in the reading of data.
390 uint32_t freed_by_sorcv_sincelast;
391 uint32_t total_sends;
392 uint32_t total_recvs;
393 int freed_from_where;
394 uint16_t rport; /* remote port in network format */
397 struct mtx tcb_send_mtx;
402 #include <netinet/sctp_lock_bsd.h>
408 extern struct sctp_epinfo sctppcbinfo;
409 extern int sctp_auto_asconf;
411 int SCTP6_ARE_ADDR_EQUAL(struct in6_addr *a, struct in6_addr *b);
413 void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
415 struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
417 struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int);
419 int sctp_inpcb_bind(struct socket *, struct sockaddr *, struct thread *);
423 sctp_findassociation_addr(struct mbuf *, int, int,
424 struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
425 struct sctp_nets **);
428 sctp_findassociation_addr_sa(struct sockaddr *,
429 struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int);
432 sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
436 * For this call ep_addr, the to is the destination endpoint address of the
437 * peer (relative to outbound). The from field is only used if the TCP model
438 * is enabled and helps distingush amongst the subset bound (non-boundall).
439 * The TCP model MAY change the actual ep field, this is why it is passed.
442 sctp_findassociation_ep_addr(struct sctp_inpcb **,
443 struct sockaddr *, struct sctp_nets **, struct sockaddr *,
447 sctp_findassociation_ep_asocid(struct sctp_inpcb *,
451 sctp_findassociation_ep_asconf(struct mbuf *, int, int,
452 struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **);
454 int sctp_inpcb_alloc(struct socket *);
456 int sctp_is_address_on_local_host(struct sockaddr *addr);
458 void sctp_inpcb_free(struct sctp_inpcb *, int, int);
461 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
462 int, int *, uint32_t);
464 int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
466 int sctp_add_local_addr_ep(struct sctp_inpcb *, struct ifaddr *);
468 int sctp_insert_laddr(struct sctpladdr *, struct ifaddr *);
470 void sctp_remove_laddr(struct sctp_laddr *);
472 int sctp_del_local_addr_ep(struct sctp_inpcb *, struct ifaddr *);
474 int sctp_del_local_addr_ep_sa(struct sctp_inpcb *, struct sockaddr *);
476 int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, int, int);
478 void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
480 int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
482 void sctp_pcb_init(void);
484 int sctp_add_local_addr_assoc(struct sctp_tcb *, struct ifaddr *);
486 int sctp_del_local_addr_assoc(struct sctp_tcb *, struct ifaddr *);
488 int sctp_del_local_addr_assoc_sa(struct sctp_tcb *, struct sockaddr *);
491 sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
492 int, struct sctphdr *, struct sockaddr *);
495 sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
498 int sctp_is_vtag_good(struct sctp_inpcb *, uint32_t, struct timeval *);
500 /* void sctp_drain(void); */
502 int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *);
505 * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg
506 * indicates run on ONLY assoc's of the specified endpoint.
509 sctp_initiate_iterator(inp_func inpf, asoc_func af, uint32_t, uint32_t,
510 uint32_t, void *, uint32_t, end_func ef, struct sctp_inpcb *, uint8_t co_off);
514 #endif /* !__sctp_pcb_h__ */