sctputil.h revision 168757
1163953Srrs/*-
2166086Srrs * Copyright (c) 2001-2007, Cisco Systems, Inc. All rights reserved.
3163953Srrs *
4163953Srrs * Redistribution and use in source and binary forms, with or without
5163953Srrs * modification, are permitted provided that the following conditions are met:
6163953Srrs *
7163953Srrs * a) Redistributions of source code must retain the above copyright notice,
8163953Srrs *   this list of conditions and the following disclaimer.
9163953Srrs *
10163953Srrs * b) Redistributions in binary form must reproduce the above copyright
11163953Srrs *    notice, this list of conditions and the following disclaimer in
12163953Srrs *   the documentation and/or other materials provided with the distribution.
13163953Srrs *
14163953Srrs * c) Neither the name of Cisco Systems, Inc. nor the names of its
15163953Srrs *    contributors may be used to endorse or promote products derived
16163953Srrs *    from this software without specific prior written permission.
17163953Srrs *
18163953Srrs * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19163953Srrs * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20163953Srrs * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21163953Srrs * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22163953Srrs * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23163953Srrs * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24163953Srrs * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25163953Srrs * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26163953Srrs * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27163953Srrs * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28163953Srrs * THE POSSIBILITY OF SUCH DAMAGE.
29163953Srrs */
30163953Srrs
31163953Srrs
32163953Srrs/* $KAME: sctputil.h,v 1.15 2005/03/06 16:04:19 itojun Exp $	 */
33163953Srrs
34163953Srrs#include <sys/cdefs.h>
35163953Srrs__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 168757 2007-04-15 13:03:14Z rrs $");
36163953Srrs#ifndef __sctputil_h__
37163953Srrs#define __sctputil_h__
38163953Srrs
39163953Srrs
40163953Srrs#if defined(_KERNEL)
41163953Srrs
42168755Srrs
43168755Srrs/*-
44168755Srrs * Any new logging added must also define SCTP_STAT_LOGGING if
45168755Srrs * its not already defined.
46168755Srrs */
47168757Srrs#if defined(SCTP_LOG_MAXBURST) || defined(SCTP_LOG_RWND) || defined(SCTP_LOG_RWND)
48168755Srrs#ifndef SCTP_STAT_LOGGING
49168755Srrs#define SCTP_STAT_LOGGING 1
50168755Srrs#endif
51168755Srrs#endif
52168755Srrs
53168757Srrs#if defined(SCTP_CWND_LOGGING) || defined(SCTP_CWND_MONITOR) || defined(SCTP_BLK_LOGGING)
54168755Srrs#ifndef SCTP_STAT_LOGGING
55168755Srrs#define SCTP_STAT_LOGGING 1
56168755Srrs#endif
57168755Srrs#endif
58168755Srrs
59168757Srrs#if defined(SCTP_STR_LOGGING) || defined(SCTP_FR_LOGGING) || defined(SCTP_MAP_LOGGING)
60168755Srrs#ifndef SCTP_STAT_LOGGING
61168755Srrs#define SCTP_STAT_LOGGING 1
62168755Srrs#endif
63168755Srrs#endif
64168755Srrs
65168757Srrs#if defined(SCTP_SACK_LOGGING) || defined(SCTP_LOCK_LOGGING) || defined(SCTP_STAT_LOGGING)
66168755Srrs#ifndef SCTP_STAT_LOGGING
67168755Srrs#define SCTP_STAT_LOGGING 1
68168755Srrs#endif
69168755Srrs#endif
70168755Srrs
71168757Srrs#if defined(SCTP_RTTVAR_LOGGING) || defined(SCTP_SB_LOGGING) || defined(SCTP_EARLYFR_LOGGING)
72168755Srrs#ifndef SCTP_STAT_LOGGING
73168755Srrs#define SCTP_STAT_LOGGING 1
74168755Srrs#endif
75168755Srrs#endif
76168755Srrs
77168757Srrs#if defined(SCTP_NAGLE_LOGGING) || defined(SCTP_WAKE_LOGGING) || defined(SCTP_RECV_RWND_LOGGING)
78168755Srrs#ifndef SCTP_STAT_LOGGING
79168755Srrs#define SCTP_STAT_LOGGING 1
80168755Srrs#endif
81168755Srrs#endif
82168755Srrs
83168757Srrs#if defined(SCTP_SACK_RWND_LOGGING) || defined(SCTP_FLIGHT_LOGGING) || defined(SCTP_MBUF_LOGGING)
84168755Srrs#ifndef SCTP_STAT_LOGGING
85168755Srrs#define SCTP_STAT_LOGGING 1
86168755Srrs#endif
87168755Srrs#endif
88168755Srrs
89163953Srrs#ifdef SCTP_MBUF_LOGGING
90163953Srrsstruct mbuf *sctp_m_free(struct mbuf *m);
91163953Srrsvoid sctp_m_freem(struct mbuf *m);
92163953Srrs
93163953Srrs#else
94163953Srrs#define sctp_m_free m_free
95163953Srrs#define sctp_m_freem m_freem
96163953Srrs#endif
97163953Srrs
98163953Srrs
99163953Srrs#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id)
100163953Srrs
101163953Srrs
102163953Srrs/*
103163953Srrs * Function prototypes
104163953Srrs */
105167698Srrsuint32_t
106167698Srrssctp_get_ifa_hash_val(struct sockaddr *addr);
107167698Srrs
108167598Srrsstruct sctp_ifa *
109167598Srrs         sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock);
110167598Srrsstruct sctp_ifa *
111167598Srrssctp_find_ifa_in_ifn(struct sctp_ifn *sctp_ifnp, struct sockaddr *addr,
112167598Srrs    int holds_lock);
113163953Srrs
114167598Srrsstruct sctp_ifa *
115167598Srrs         sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock);
116167598Srrs
117163953Srrsuint32_t sctp_select_initial_TSN(struct sctp_pcb *);
118163953Srrs
119163953Srrsuint32_t sctp_select_a_tag(struct sctp_inpcb *);
120163953Srrs
121167598Srrsint sctp_init_asoc(struct sctp_inpcb *, struct sctp_association *, int, uint32_t, uint32_t);
122163953Srrs
123163953Srrsvoid sctp_fill_random_store(struct sctp_pcb *);
124163953Srrs
125163953Srrsint
126163953Srrssctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *,
127163953Srrs    struct sctp_nets *);
128163953Srrs
129163953Srrsint
130163953Srrssctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *,
131165220Srrs    struct sctp_nets *, uint32_t);
132163953Srrs
133167598Srrsint
134167598Srrs    sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id);
135167598Srrs
136163953Srrsuint32_t sctp_calculate_sum(struct mbuf *, int32_t *, uint32_t);
137163953Srrs
138163953Srrsvoid
139166023Srrs     sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t);
140163953Srrs
141163953Srrsvoid
142163953Srrssctp_add_to_readq(struct sctp_inpcb *inp,
143163953Srrs    struct sctp_tcb *stcb,
144163953Srrs    struct sctp_queued_to_read *control,
145163953Srrs    struct sockbuf *sb,
146163953Srrs    int end);
147163953Srrs
148163953Srrsint
149163953Srrssctp_append_to_readq(struct sctp_inpcb *inp,
150163953Srrs    struct sctp_tcb *stcb,
151163953Srrs    struct sctp_queued_to_read *control,
152163953Srrs    struct mbuf *m,
153163953Srrs    int end,
154163953Srrs    int new_cumack,
155163953Srrs    struct sockbuf *sb);
156163953Srrs
157163953Srrs
158167598Srrsvoid sctp_iterator_worker(void);
159167598Srrs
160163953Srrsint find_next_best_mtu(int);
161163953Srrs
162163953Srrsvoid
163163953Srrs     sctp_timeout_handler(void *);
164163953Srrs
165163953Srrsuint32_t
166163953Srrssctp_calculate_rto(struct sctp_tcb *, struct sctp_association *,
167163953Srrs    struct sctp_nets *, struct timeval *);
168163953Srrs
169163953Srrsuint32_t sctp_calculate_len(struct mbuf *);
170163953Srrs
171163953Srrscaddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *);
172163953Srrs
173163953Srrsstruct sctp_paramhdr *
174163953Srrssctp_get_next_param(struct mbuf *, int,
175163953Srrs    struct sctp_paramhdr *, int);
176163953Srrs
177163953Srrsint sctp_add_pad_tombuf(struct mbuf *, int);
178163953Srrs
179163953Srrsint sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *);
180163953Srrs
181163953Srrsvoid sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *);
182163953Srrs
183163953Srrsvoid
184163953Srrssctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
185163953Srrs    struct sctp_inpcb *new_inp,
186163953Srrs    struct sctp_tcb *stcb);
187163953Srrs
188163953Srrs
189163953Srrsvoid sctp_stop_timers_for_shutdown(struct sctp_tcb *);
190163953Srrs
191164205Srrsvoid sctp_report_all_outbound(struct sctp_tcb *, int);
192163953Srrs
193163953Srrsint sctp_expand_mapping_array(struct sctp_association *);
194163953Srrs
195163953Srrsvoid sctp_abort_notification(struct sctp_tcb *, int);
196163953Srrs
197163953Srrs/* We abort responding to an IP packet for some reason */
198163953Srrsvoid
199163953Srrssctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *,
200163953Srrs    struct mbuf *, int, struct sctphdr *, struct mbuf *);
201163953Srrs
202163953Srrs/* We choose to abort via user input */
203163953Srrsvoid
204163953Srrssctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, int,
205163953Srrs    struct mbuf *);
206163953Srrs
207163953Srrsvoid
208163953Srrssctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *,
209163953Srrs    struct sctp_inpcb *, struct mbuf *);
210163953Srrs
211163953Srrsint sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *);
212163953Srrsuint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *);
213166675Srrs
214163953Srrsstruct sockaddr_in6 *
215166675Srrs             sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *);
216163953Srrs
217163953Srrs#define sctp_recover_scope_mac(addr, store) do { \
218166675Srrs	 if ((addr->sin6_family == AF_INET6) && \
219166675Srrs	     (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \
220166675Srrs		*store = *addr; \
221166675Srrs		if (addr->sin6_scope_id == 0) { \
222166675Srrs			if (!sa6_recoverscope(store)) { \
223166675Srrs				addr = store; \
224166675Srrs			} \
225166675Srrs		} else { \
226166675Srrs			in6_clearscope(&addr->sin6_addr); \
227166675Srrs			addr = store; \
228166675Srrs		} \
229166675Srrs	 } \
230166675Srrs} while (0)
231163953Srrs
232163953Srrs
233163953Srrsint sctp_cmpaddr(struct sockaddr *, struct sockaddr *);
234163953Srrs
235163953Srrsvoid sctp_print_address(struct sockaddr *);
236163953Srrsvoid sctp_print_address_pkt(struct ip *, struct sctphdr *);
237163953Srrs
238163953Srrsvoid
239163953Srrssctp_notify_partial_delivery_indication(struct sctp_tcb *stcb,
240163953Srrs    uint32_t error, int no_lock);
241163953Srrs
242163953Srrsint
243163953Srrssctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *,
244163953Srrs    int, struct sctpchunk_listhead *);
245163953Srrs
246163953Srrsstruct mbuf *sctp_generate_invmanparam(int);
247163953Srrs
248163953Srrs
249163953Srrs#ifdef SCTP_MBCNT_LOGGING
250163953Srrsvoid
251163953Srrssctp_free_bufspace(struct sctp_tcb *, struct sctp_association *,
252163953Srrs    struct sctp_tmit_chunk *);
253163953Srrs
254163953Srrs#else
255163953Srrs#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt)  \
256163953Srrsdo { \
257163953Srrs	if (tp1->data != NULL) { \
258163996Srrs                atomic_add_int(&((asoc)->chunks_on_out_queue), -chk_cnt); \
259163953Srrs		if ((asoc)->total_output_queue_size >= tp1->book_size) { \
260163953Srrs			atomic_add_int(&((asoc)->total_output_queue_size), -tp1->book_size); \
261163953Srrs		} else { \
262163953Srrs			(asoc)->total_output_queue_size = 0; \
263163953Srrs		} \
264163953Srrs   	        if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
265163953Srrs	            (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
266163953Srrs			if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \
267163953Srrs				atomic_add_int(&((stcb)->sctp_socket->so_snd.sb_cc), -tp1->book_size); \
268163953Srrs			} else { \
269163953Srrs				stcb->sctp_socket->so_snd.sb_cc = 0; \
270163953Srrs			} \
271163953Srrs		} \
272163953Srrs        } \
273163953Srrs} while (0)
274163953Srrs
275163953Srrs#endif
276163953Srrs
277163953Srrs#define sctp_free_spbufspace(stcb, asoc, sp)  \
278163953Srrsdo { \
279163953Srrs 	if (sp->data != NULL) { \
280163996Srrs                atomic_add_int(&(asoc)->chunks_on_out_queue, -1); \
281163953Srrs		if ((asoc)->total_output_queue_size >= sp->length) { \
282163953Srrs			atomic_add_int(&(asoc)->total_output_queue_size,sp->length); \
283163953Srrs		} else { \
284163953Srrs			(asoc)->total_output_queue_size = 0; \
285163953Srrs		} \
286163953Srrs   	        if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
287163953Srrs	            (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
288163953Srrs			if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \
289163953Srrs				atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \
290163953Srrs			} else { \
291163953Srrs				stcb->sctp_socket->so_snd.sb_cc = 0; \
292163953Srrs			} \
293163953Srrs		} \
294163953Srrs        } \
295163953Srrs} while (0)
296163953Srrs
297163953Srrs#define sctp_snd_sb_alloc(stcb, sz)  \
298163953Srrsdo { \
299163953Srrs	atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \
300163953Srrs	if ((stcb->sctp_socket != NULL) && \
301163953Srrs	    ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
302163953Srrs	     (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
303163953Srrs		atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \
304163953Srrs	} \
305163953Srrs} while (0)
306163953Srrs
307163953Srrs
308163953Srrsint
309163953Srrssctp_soreceive(struct socket *so, struct sockaddr **psa,
310163953Srrs    struct uio *uio,
311163953Srrs    struct mbuf **mp0,
312163953Srrs    struct mbuf **controlp,
313163953Srrs    int *flagsp);
314163953Srrs
315163953Srrs
316163953Srrs#ifdef SCTP_STAT_LOGGING
317163953Srrsvoid
318163953Srrs     sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d);
319163953Srrs
320163953Srrsvoid
321163953Srrssctp_wakeup_log(struct sctp_tcb *stcb,
322163953Srrs    uint32_t cumtsn,
323163953Srrs    uint32_t wake_cnt, int from);
324163953Srrs
325164181Srrsvoid sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int);
326163953Srrs
327163953Srrsvoid sctp_log_nagle_event(struct sctp_tcb *stcb, int action);
328163953Srrs
329163953Srrs
330163953Srrsvoid
331163953Srrs     sctp_log_mb(struct mbuf *m, int from);
332163953Srrs
333163953Srrsvoid
334163953Srrssctp_sblog(struct sockbuf *sb,
335163953Srrs    struct sctp_tcb *stcb, int from, int incr);
336163953Srrs
337163953Srrsvoid
338163953Srrssctp_log_strm_del(struct sctp_queued_to_read *control,
339163953Srrs    struct sctp_queued_to_read *poschk,
340163953Srrs    int from);
341163953Srrsvoid sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t);
342163953Srrsvoid rto_logging(struct sctp_nets *net, int from);
343163953Srrs
344163953Srrsvoid sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc);
345163953Srrs
346163953Srrsvoid sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from);
347163953Srrsvoid sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t);
348163953Srrsvoid sctp_log_block(uint8_t, struct socket *, struct sctp_association *, int);
349163953Srrsvoid sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t);
350163953Srrsvoid sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t);
351163953Srrsvoid sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t);
352167598Srrsint sctp_fill_stat_log(void *, size_t *);
353163953Srrsvoid sctp_log_fr(uint32_t, uint32_t, uint32_t, int);
354163953Srrsvoid sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int);
355163953Srrsvoid sctp_log_map(uint32_t, uint32_t, uint32_t, int);
356163953Srrs
357163953Srrsvoid sctp_clr_stat_log(void);
358163953Srrs
359163953Srrs#endif
360163953Srrs
361163953Srrs#ifdef SCTP_AUDITING_ENABLED
362163953Srrsvoid
363163953Srrssctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *,
364163953Srrs    struct sctp_nets *);
365163953Srrsvoid sctp_audit_log(uint8_t, uint8_t);
366163953Srrs
367163953Srrs#endif
368163953Srrs
369163953Srrs
370163953Srrs#endif				/* _KERNEL */
371163953Srrs#endif
372