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 uint32_t ipi_count_ep;
203 /* assoc/tcb zone info */
204 uint32_t ipi_count_asoc;
206 /* local addrlist zone info */
207 uint32_t ipi_count_laddr;
209 /* remote addrlist zone info */
210 uint32_t ipi_count_raddr;
212 /* chunk structure list for output */
213 uint32_t ipi_count_chunk;
215 /* socket queue zone info */
216 uint32_t ipi_count_readq;
218 /* socket queue zone info */
219 uint32_t ipi_count_strmoq;
221 /* system wide number of free chunks hanging around */
222 uint32_t ipi_free_chunks;
223 uint32_t ipi_free_strmoq;
225 struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
228 struct sctp_timer addr_wq_timer;
230 /* for port allocations */
237 extern struct sctpstat sctpstat;
240 * Here we have all the relevant information for each SCTP entity created. We
241 * will need to modify this as approprate. We also need to figure out how to
242 * access /dev/random.
245 unsigned int time_of_secret_change; /* number of seconds from
247 uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
248 unsigned int size_of_a_cookie;
250 unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
251 unsigned int sctp_minrto;
252 unsigned int sctp_maxrto;
253 unsigned int initial_rto;
255 int initial_init_rto_max;
257 uint32_t sctp_sws_sender;
258 uint32_t sctp_sws_receiver;
260 /* authentication related fields */
261 struct sctp_keyhead shared_keys;
262 sctp_auth_chklist_t *local_auth_chunks;
263 sctp_hmaclist_t *local_hmacs;
264 uint16_t default_keyid;
266 /* various thresholds */
267 /* Max times I will init at a guy */
268 uint16_t max_init_times;
270 /* Max times I will send before we consider someone dead */
271 uint16_t max_send_times;
273 uint16_t def_net_failure;
275 /* number of streams to pre-open on a association */
276 uint16_t pre_open_stream_count;
277 uint16_t max_open_streams_intome;
279 /* random number generator */
280 uint32_t random_counter;
281 uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
282 uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
285 * This timer is kept running per endpoint. When it fires it will
286 * change the secret key. The default is once a hour
288 struct sctp_timer signature_change;
292 uint32_t initial_sequence_debug;
293 uint32_t adaptation_layer_indicator;
296 char current_secret_number;
297 char last_secret_number;
300 #ifndef SCTP_ALIGNMENT
301 #define SCTP_ALIGNMENT 32
305 #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
308 #define sctp_lport ip_inp.inp.inp_lport
312 * put an inpcb in front of it all, kind of a waste but we need to
313 * for compatability with all the other stuff.
317 char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) &
322 /* Socket buffer lock protects read_queue and of course sb_cc */
323 struct sctp_readhead read_queue;
325 LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */
326 /* hash of all endpoints for model */
327 LIST_ENTRY(sctp_inpcb) sctp_hash;
328 /* count of local addresses bound, 0 if bound all */
330 /* list of addrs in use by the EP */
331 struct sctpladdr sctp_addr_list;
332 /* used for source address selection rotation */
333 struct sctp_laddr *next_addr_touse;
334 struct ifnet *next_ifn_touse;
335 /* back pointer to our socket */
336 struct socket *sctp_socket;
337 uint32_t sctp_flags; /* INP state flag set */
338 uint32_t sctp_features; /* Feature flags */
339 struct sctp_pcb sctp_ep;/* SCTP ep data */
340 /* head of the hash of all associations */
341 struct sctpasochead *sctp_tcbhash;
342 u_long sctp_hashmark;
343 /* head of the list of all associations */
344 struct sctpasochead sctp_asoc_list;
345 struct sctp_iterator *inp_starting_point_for_iterator;
346 uint32_t sctp_frag_point;
347 uint32_t partial_delivery_point;
348 uint32_t sctp_context;
349 struct sctp_sndrcvinfo def_send;
351 * These three are here for the sosend_dgram (pkt, pkt_last and
352 * control). routine. However, I don't think anyone in the current
353 * FreeBSD kernel calls this. So they are candidates with sctp_sendm
356 struct mbuf *pkt, *pkt_last;
357 struct mbuf *control;
359 struct mtx inp_create_mtx;
360 struct mtx inp_rdata_mtx;
365 struct socket *sctp_socket; /* back pointer to socket */
366 struct sctp_inpcb *sctp_ep; /* back pointer to ep */
367 LIST_ENTRY(sctp_tcb) sctp_tcbhash; /* next link in hash
369 LIST_ENTRY(sctp_tcb) sctp_tcblist; /* list of all of the
371 LIST_ENTRY(sctp_tcb) sctp_tcbrestarhash; /* next link in restart
373 LIST_ENTRY(sctp_tcb) sctp_asocs; /* vtag hash list */
374 struct sctp_block_entry *block_entry; /* pointer locked by socket
376 struct sctp_association asoc;
378 * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the
379 * tcb_lock. Its special in this way to help avoid extra mutex calls
380 * in the reading of data.
382 uint32_t freed_by_sorcv_sincelast;
383 uint16_t rport; /* remote port in network format */
386 struct mtx tcb_send_mtx;
391 #include <netinet/sctp_lock_bsd.h>
397 extern struct sctp_epinfo sctppcbinfo;
398 extern int sctp_auto_asconf;
400 int SCTP6_ARE_ADDR_EQUAL(struct in6_addr *a, struct in6_addr *b);
402 void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
404 struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
406 struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int);
408 int sctp_inpcb_bind(struct socket *, struct sockaddr *, struct thread *);
412 sctp_findassociation_addr(struct mbuf *, int, int,
413 struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
414 struct sctp_nets **);
417 sctp_findassociation_addr_sa(struct sockaddr *,
418 struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int);
421 sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
425 * For this call ep_addr, the to is the destination endpoint address of the
426 * peer (relative to outbound). The from field is only used if the TCP model
427 * is enabled and helps distingush amongst the subset bound (non-boundall).
428 * The TCP model MAY change the actual ep field, this is why it is passed.
431 sctp_findassociation_ep_addr(struct sctp_inpcb **,
432 struct sockaddr *, struct sctp_nets **, struct sockaddr *,
436 sctp_findassociation_ep_asocid(struct sctp_inpcb *,
440 sctp_findassociation_ep_asconf(struct mbuf *, int, int,
441 struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **);
443 int sctp_inpcb_alloc(struct socket *);
445 int sctp_is_address_on_local_host(struct sockaddr *addr);
447 void sctp_inpcb_free(struct sctp_inpcb *, int, int);
450 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
451 int, int *, uint32_t);
453 int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int);
455 int sctp_add_local_addr_ep(struct sctp_inpcb *, struct ifaddr *);
457 int sctp_insert_laddr(struct sctpladdr *, struct ifaddr *);
459 void sctp_remove_laddr(struct sctp_laddr *);
461 int sctp_del_local_addr_ep(struct sctp_inpcb *, struct ifaddr *);
463 int sctp_del_local_addr_ep_sa(struct sctp_inpcb *, struct sockaddr *);
465 int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, int, int);
467 void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
469 int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
471 void sctp_pcb_init(void);
473 int sctp_add_local_addr_assoc(struct sctp_tcb *, struct ifaddr *);
475 int sctp_del_local_addr_assoc(struct sctp_tcb *, struct ifaddr *);
477 int sctp_del_local_addr_assoc_sa(struct sctp_tcb *, struct sockaddr *);
480 sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
481 int, struct sctphdr *, struct sockaddr *);
484 sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
487 int sctp_is_vtag_good(struct sctp_inpcb *, uint32_t, struct timeval *);
489 /* void sctp_drain(void); */
491 int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *);
494 * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg
495 * indicates run on ONLY assoc's of the specified endpoint.
498 sctp_initiate_iterator(inp_func inpf, asoc_func af, uint32_t, uint32_t,
499 uint32_t, void *, uint32_t, end_func ef, struct sctp_inpcb *, uint8_t co_off);
504 #endif /* !__sctp_pcb_h__ */