2 * Copyright (c) 2001-2007, 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__
39 #include <netinet/sctp_os.h>
40 #include <netinet/sctp.h>
41 #include <netinet/sctp_constants.h>
43 LIST_HEAD(sctppcbhead, sctp_inpcb);
44 LIST_HEAD(sctpasochead, sctp_tcb);
45 LIST_HEAD(sctpladdr, sctp_laddr);
46 LIST_HEAD(sctpvtaghead, sctp_tagblock);
47 LIST_HEAD(sctp_vrflist, sctp_vrf);
48 LIST_HEAD(sctp_ifnlist, sctp_ifn);
49 LIST_HEAD(sctp_ifalist, sctp_ifa);
50 TAILQ_HEAD(sctp_readhead, sctp_queued_to_read);
51 TAILQ_HEAD(sctp_streamhead, sctp_stream_queue_pending);
53 #include <netinet/sctp_structs.h>
54 #include <netinet/sctp_uio.h>
55 #include <netinet/sctp_auth.h>
57 #define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask)
58 #define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask)
61 LIST_ENTRY(sctp_vrf) next_vrf;
62 struct sctp_ifalist *vrf_addr_hash;
63 struct sctp_ifnlist ifnlist;
65 uint32_t total_ifa_count;
70 struct sctp_ifalist ifalist;
72 LIST_ENTRY(sctp_ifn) next_ifn;
73 void *ifn_p; /* never access without appropriate lock */
75 uint32_t ifn_index; /* shorthand way to look at ifn for reference */
76 uint32_t refcount; /* number of reference held should be >=
78 uint32_t ifa_count; /* IFA's we hold (in our list - ifalist) */
79 char ifn_name[SCTP_IFNAMSIZ];
82 /* SCTP local IFA flags */
83 #define SCTP_ADDR_VALID 0x00000001 /* its up and active */
84 #define SCTP_BEING_DELETED 0x00000002 /* being deleted, when
85 * refcount = 0. Note that it
86 * is pulled from the ifn list
87 * and ifa_p is nulled right
88 * away but it cannot be freed
90 * pointing to it is deleted. */
91 #define SCTP_ADDR_DEFER_USE 0x00000004 /* Hold off using this one */
92 #define SCTP_ADDR_IFA_UNUSEABLE 0x00000008
95 LIST_ENTRY(sctp_ifa) next_ifa;
96 LIST_ENTRY(sctp_ifa) next_bucket;
97 struct sctp_ifn *ifn_p; /* back pointer to parent ifn */
98 void *ifa; /* pointer to ifa, needed for flag update for
99 * that we MUST lock appropriate locks. This
101 union sctp_sockstore address;
102 uint32_t refcount; /* number of folks refering to this */
104 uint32_t localifa_flags;
112 LIST_ENTRY(sctp_laddr) sctp_nxt_addr; /* next in list */
113 struct sctp_ifa *ifa;
114 uint32_t action; /* Used during asconf and adding if no-zero
115 * src-addr selection will not consider this
119 struct sctp_block_entry {
123 struct sctp_timewait {
124 uint32_t tv_sec_at_expire; /* the seconds from boot to expire */
125 uint32_t v_tag; /* the vtag that can not be reused */
128 struct sctp_tagblock {
129 LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock;
130 struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
134 struct sctpasochead *sctp_asochash;
137 struct sctppcbhead *sctp_ephash;
140 struct sctpasochead *sctp_restarthash;
141 u_long hashrestartmark;
143 * The TCP model represents a substantial overhead in that we get an
144 * additional hash table to keep explicit connections in. The
145 * listening TCP endpoint will exist in the usual ephash above and
146 * accept only INIT's. It will be incapable of sending off an INIT.
147 * When a dg arrives we must look in the normal ephash. If we find a
148 * TCP endpoint that will tell us to go to the specific endpoint
149 * hash and re-hash to find the right assoc/socket. If we find a UDP
150 * model socket we then must complete the lookup. If this fails,
151 * i.e. no association can be found then we must continue to see if
152 * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket
153 * acts like a TCP model connected socket).
155 struct sctppcbhead *sctp_tcpephash;
157 uint32_t hashtblsize;
159 struct sctp_vrflist *sctp_vrfhash;
162 struct sctppcbhead listhead;
163 struct sctpladdr addr_wq;
165 struct sctpiterators iteratorhead;
168 sctp_zone_t ipi_zone_ep;
169 sctp_zone_t ipi_zone_asoc;
170 sctp_zone_t ipi_zone_laddr;
171 sctp_zone_t ipi_zone_net;
172 sctp_zone_t ipi_zone_chunk;
173 sctp_zone_t ipi_zone_readq;
174 sctp_zone_t ipi_zone_strmoq;
176 struct mtx ipi_ep_mtx;
178 struct mtx ipi_iterator_wq_mtx;
179 struct mtx ipi_addr_mtx;
180 uint32_t ipi_count_ep;
182 /* assoc/tcb zone info */
183 uint32_t ipi_count_asoc;
185 /* local addrlist zone info */
186 uint32_t ipi_count_laddr;
188 /* remote addrlist zone info */
189 uint32_t ipi_count_raddr;
191 /* chunk structure list for output */
192 uint32_t ipi_count_chunk;
194 /* socket queue zone info */
195 uint32_t ipi_count_readq;
197 /* socket queue zone info */
198 uint32_t ipi_count_strmoq;
200 /* system wide number of free chunks hanging around */
201 uint32_t ipi_free_chunks;
202 uint32_t ipi_free_strmoq;
204 struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
206 /* address work queue handling */
207 #if defined(SCTP_USE_THREAD_BASED_ITERATOR)
208 uint32_t iterator_running;
209 SCTP_PROCESS_STRUCT thread_proc;
211 struct sctp_timer addr_wq_timer;
216 * Here we have all the relevant information for each SCTP entity created. We
217 * will need to modify this as approprate. We also need to figure out how to
218 * access /dev/random.
221 unsigned int time_of_secret_change; /* number of seconds from
223 uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
224 unsigned int size_of_a_cookie;
226 unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
227 unsigned int sctp_minrto;
228 unsigned int sctp_maxrto;
229 unsigned int initial_rto;
230 int initial_init_rto_max;
232 unsigned int sctp_sack_freq;
233 uint32_t sctp_sws_sender;
234 uint32_t sctp_sws_receiver;
236 /* authentication related fields */
237 struct sctp_keyhead shared_keys;
238 sctp_auth_chklist_t *local_auth_chunks;
239 sctp_hmaclist_t *local_hmacs;
240 uint16_t default_keyid;
242 /* various thresholds */
243 /* Max times I will init at a guy */
244 uint16_t max_init_times;
246 /* Max times I will send before we consider someone dead */
247 uint16_t max_send_times;
249 uint16_t def_net_failure;
251 /* number of streams to pre-open on a association */
252 uint16_t pre_open_stream_count;
253 uint16_t max_open_streams_intome;
255 /* random number generator */
256 uint32_t random_counter;
257 uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
258 uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
261 * This timer is kept running per endpoint. When it fires it will
262 * change the secret key. The default is once a hour
264 struct sctp_timer signature_change;
268 uint32_t initial_sequence_debug;
269 uint32_t adaptation_layer_indicator;
272 char current_secret_number;
273 char last_secret_number;
276 #ifndef SCTP_ALIGNMENT
277 #define SCTP_ALIGNMENT 32
281 #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
284 #define sctp_lport ip_inp.inp.inp_lport
288 * put an inpcb in front of it all, kind of a waste but we need to
289 * for compatability with all the other stuff.
293 char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) &
298 /* Socket buffer lock protects read_queue and of course sb_cc */
299 struct sctp_readhead read_queue;
301 LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */
302 /* hash of all endpoints for model */
303 LIST_ENTRY(sctp_inpcb) sctp_hash;
304 /* count of local addresses bound, 0 if bound all */
307 /* list of addrs in use by the EP, NULL if bound-all */
308 struct sctpladdr sctp_addr_list;
310 * used for source address selection rotation when we are subset
313 struct sctp_laddr *next_addr_touse;
315 /* back pointer to our socket */
316 struct socket *sctp_socket;
317 uint32_t sctp_flags; /* INP state flag set */
318 uint32_t sctp_features; /* Feature flags */
319 struct sctp_pcb sctp_ep;/* SCTP ep data */
320 /* head of the hash of all associations */
321 struct sctpasochead *sctp_tcbhash;
322 u_long sctp_hashmark;
323 /* head of the list of all associations */
324 struct sctpasochead sctp_asoc_list;
325 #ifdef SCTP_TRACK_FREED_ASOCS
326 struct sctpasochead sctp_asoc_free_list;
328 struct sctp_iterator *inp_starting_point_for_iterator;
329 uint32_t sctp_frag_point;
330 uint32_t partial_delivery_point;
331 uint32_t sctp_context;
332 struct sctp_sndrcvinfo def_send;
334 * These three are here for the sosend_dgram
335 * (pkt, pkt_last and control).
336 * routine. However, I don't think anyone in
337 * the current FreeBSD kernel calls this. So
338 * they are candidates with sctp_sendm for
341 struct mbuf *pkt, *pkt_last;
342 struct mbuf *control;
344 struct mtx inp_create_mtx;
345 struct mtx inp_rdata_mtx;
348 uint32_t total_sends;
349 uint32_t total_recvs;
350 uint32_t last_abort_code;
351 uint32_t total_nospaces;
355 struct socket *sctp_socket; /* back pointer to socket */
356 struct sctp_inpcb *sctp_ep; /* back pointer to ep */
357 LIST_ENTRY(sctp_tcb) sctp_tcbhash; /* next link in hash
359 LIST_ENTRY(sctp_tcb) sctp_tcblist; /* list of all of the
361 LIST_ENTRY(sctp_tcb) sctp_tcbrestarhash; /* next link in restart
363 LIST_ENTRY(sctp_tcb) sctp_asocs; /* vtag hash list */
364 struct sctp_block_entry *block_entry; /* pointer locked by socket
366 struct sctp_association asoc;
368 * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the
369 * tcb_lock. Its special in this way to help avoid extra mutex calls
370 * in the reading of data.
372 uint32_t freed_by_sorcv_sincelast;
373 uint32_t total_sends;
374 uint32_t total_recvs;
375 int freed_from_where;
376 uint16_t rport; /* remote port in network format */
379 struct mtx tcb_send_mtx;
384 #include <netinet/sctp_lock_bsd.h>
389 extern struct sctp_epinfo sctppcbinfo;
391 int SCTP6_ARE_ADDR_EQUAL(struct in6_addr *a, struct in6_addr *b);
393 void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
396 sctp_find_ifn(struct sctp_vrf *vrf, void *ifn, uint32_t ifn_index);
398 struct sctp_vrf *sctp_allocate_vrf(int vrfid);
400 struct sctp_vrf *sctp_find_vrf(uint32_t vrfid);
403 sctp_add_addr_to_vrf(uint32_t vrfid,
404 void *ifn, uint32_t ifn_index, uint32_t ifn_type,
406 void *ifa, struct sockaddr *addr, uint32_t ifa_flags, int dynamic_add);
408 void sctp_free_ifa(struct sctp_ifa *sctp_ifap);
411 sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr,
417 struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
419 struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t);
421 int sctp_inpcb_bind(struct socket *, struct sockaddr *, struct thread *);
425 sctp_findassociation_addr(struct mbuf *, int, int,
426 struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
427 struct sctp_nets **, uint32_t vrf_id);
430 sctp_findassociation_addr_sa(struct sockaddr *,
431 struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int, uint32_t);
434 sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
438 * For this call ep_addr, the to is the destination endpoint address of the
439 * peer (relative to outbound). The from field is only used if the TCP model
440 * is enabled and helps distingush amongst the subset bound (non-boundall).
441 * The TCP model MAY change the actual ep field, this is why it is passed.
444 sctp_findassociation_ep_addr(struct sctp_inpcb **,
445 struct sockaddr *, struct sctp_nets **, struct sockaddr *,
449 sctp_findassociation_ep_asocid(struct sctp_inpcb *,
453 sctp_findassociation_ep_asconf(struct mbuf *, int, int,
454 struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **);
456 int sctp_inpcb_alloc(struct socket *);
458 int sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id);
460 void sctp_inpcb_free(struct sctp_inpcb *, int, int);
463 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
464 int, int *, uint32_t, uint32_t);
466 int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
469 sctp_add_vtag_to_timewait(struct sctp_inpcb *, uint32_t, uint32_t);
471 int sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t);
473 int sctp_insert_laddr(struct sctpladdr *, struct sctp_ifa *, uint32_t);
475 void sctp_remove_laddr(struct sctp_laddr *);
477 int sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *);
479 void sctp_set_initial_cc_param(struct sctp_tcb *, struct sctp_nets *net);
482 int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, int, int);
484 void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
486 int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
488 void sctp_pcb_init(void);
490 int sctp_add_local_addr_assoc(struct sctp_tcb *, struct sctp_ifa *, int);
492 int sctp_del_local_addr_assoc(struct sctp_tcb *, struct sctp_ifa *);
495 sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
496 int, struct sctphdr *, struct sockaddr *);
499 sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
502 int sctp_is_vtag_good(struct sctp_inpcb *, uint32_t, struct timeval *);
504 /* void sctp_drain(void); */
506 int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *);
509 * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg
510 * indicates run on ONLY assoc's of the specified endpoint.
513 sctp_initiate_iterator(inp_func inpf,
524 #endif /* !__sctp_pcb_h__ */