kernel: Fix -Wundef in a number of places.
[dragonfly.git] / sys / netinet / sctputil.h
1 /*      $KAME: sctputil.h,v 1.14 2004/08/17 04:06:21 itojun Exp $       */
2
3 #ifndef _NETINET_SCTPUTIL_H_
4 #define _NETINET_SCTPUTIL_H_
5
6 /*
7  * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc,
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the project nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34
35 #ifndef _SYS_TYPES_H_
36 #include <sys/types.h>
37 #endif
38 #ifndef _SYS_SOCKET_H_
39 #include <sys/socket.h>
40 #endif
41
42 #if defined(_KERNEL) || (defined(__APPLE__) && defined(KERNEL))
43
44 #ifdef SCTP_MBUF_DEBUG
45 #define sctp_m_freem(m) do { \
46     kprintf("m_freem(%p) m->nxtpkt:%p at %s[%d]\n", \
47            (m), (m)->m_next, __FILE__, __LINE__); \
48     m_freem(m); \
49 } while (0);
50 #else
51 #define sctp_m_freem m_freem
52 #endif
53
54 #ifdef __APPLE__
55 struct mbuf *sctp_m_copym(struct mbuf *m, int off, int len, int wait);
56 #else
57 #define sctp_m_copym    m_copym
58 #endif /* __APPLE__ */
59
60 /*
61  * Zone(pool) allocation routines: MUST be defined for each OS
62  * zone = zone/pool pointer
63  * name = string name of the zone/pool
64  * size = size of each zone/pool element
65  * number = number of elements in zone/pool
66  */
67 #if defined(__FreeBSD__) || defined(__DragonFly__)
68 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
69 #include <vm/uma.h>
70 #endif
71 #elif defined(__NetBSD__) || defined(__OpenBSD__)
72 #include <sys/pool.h>
73 #endif
74
75 /* SCTP_ZONE_INIT: initialize the zone */
76 #if defined(__FreeBSD__) || defined(__DragonFly__)
77 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
78 #define UMA_ZFLAG_FULL  0x0020
79 #define SCTP_ZONE_INIT(zone, name, size, number) { \
80         zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\
81                 UMA_ZFLAG_FULL); \
82         uma_zone_set_max(zone, number); \
83 }
84 #else
85 #define SCTP_ZONE_INIT(zone, name, size, number)        \
86         do {                                            \
87                 zone.ks_shortdesc = name;               \
88                 zone.ks_size = size;                    \
89                 zone.ks_magic = M_MAGIC;                \
90                 malloc_init(&zone);                     \
91         } while(0)
92 #endif
93 #elif defined(__APPLE__)
94 #define SCTP_ZONE_INIT(zone, name, size, number) \
95         zone = (void *)zinit(size, number * size, number, name);
96 #elif defined(__OpenBSD__) || defined(__NetBSD__)
97 #define SCTP_ZONE_INIT(zone, name, size, number) \
98         pool_init(&(zone), size, 0, 0, 0, name, NULL);
99 #else
100         /* don't know this OS! */
101         force_comile_error;
102 #endif
103
104 /* SCTP_ZONE_GET: allocate element from the zone */
105 #if defined(__FreeBSD__)
106 #if __FreeBSD_version >= 500000
107 #define SCTP_ZONE_GET(zone) \
108         uma_zalloc(zone, M_NOWAIT);
109 #else
110 #define SCTP_ZONE_GET(zone) \
111         zalloci(zone);
112 #endif
113 #elif defined(__DragonFly__)
114 #define SCTP_ZONE_GET(zone) \
115         kmalloc(zone.ks_size, &zone, M_WAITOK|M_ZERO)
116 #elif defined(__APPLE__)
117 #define SCTP_ZONE_GET(zone) \
118         zalloc(zone);
119 #elif defined(__NetBSD__) || defined(__OpenBSD__)
120 #define SCTP_ZONE_GET(zone) \
121         pool_get(&zone, PR_NOWAIT);
122 #else
123         /* don't know this OS! */
124         force_comile_error;
125 #endif
126
127 /* SCTP_ZONE_FREE: free element from the zone */
128 #if defined(__FreeBSD__)
129 #if __FreeBSD_version >= 500000
130 #define SCTP_ZONE_FREE(zone, element) \
131         uma_zfree(zone, element);
132 #else
133 #define SCTP_ZONE_FREE(zone, element) \
134         zfreei(zone, element);
135 #endif
136 #elif defined(__DragonFly__)
137 #define SCTP_ZONE_FREE(zone, element) \
138         kfree(element, &zone)
139 #elif defined(__APPLE__)
140 #define SCTP_ZONE_FREE(zone, element) \
141         zfree(zone, element);
142 #elif defined(__NetBSD__) || defined(__OpenBSD__)
143 #define SCTP_ZONE_FREE(zone, element) \
144         pool_put(&zone, element);
145 #else
146         /* don't know this OS! */
147         force_comile_error;
148 #endif
149
150 #define sctp_get_associd(stcb) ((sctp_assoc_t)(uintptr_t)stcb->asoc.my_vtag)
151
152 /*
153  * Function prototypes
154  */
155
156 struct mbuf;
157 struct ip;
158 struct sockbuf;
159 struct socket;
160 struct sockaddr_in6;
161 struct sctp_pcb;
162 struct sctp_tcb;
163 struct sctp_tmit_chunk;
164 struct sctpchunk_listhead;
165 struct sctphdr;
166 struct sctp_inpcb;
167 struct sctp_association;
168 struct sctp_nets;
169
170 struct ifaddr *sctp_find_ifa_by_addr(struct sockaddr *sa);
171
172 u_int32_t sctp_select_initial_TSN(struct sctp_pcb *);
173
174 u_int32_t sctp_select_a_tag(struct sctp_inpcb *);
175
176 int sctp_init_asoc(struct sctp_inpcb *, struct sctp_association *, int, uint32_t);
177
178 void sctp_fill_random_store(struct sctp_pcb *);
179
180 int sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *,
181         struct sctp_nets *);
182
183 int sctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *,
184         struct sctp_nets *);
185
186 u_int32_t sctp_calculate_sum(struct mbuf *, int32_t *, u_int32_t);
187
188 void sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *,
189         u_long);
190
191 int find_next_best_mtu(int);
192
193 u_int32_t sctp_calculate_rto(struct sctp_tcb *, struct sctp_association *,
194         struct sctp_nets *, struct timeval *);
195
196 u_int32_t sctp_calculate_len(struct mbuf *);
197
198 caddr_t sctp_m_getptr(struct mbuf *, int, int, u_int8_t *);
199
200 struct sctp_paramhdr *sctp_get_next_param(struct mbuf *, int,
201         struct sctp_paramhdr *, int);
202
203 int sctp_add_pad_tombuf(struct mbuf *, int);
204
205 int sctp_pad_lastmbuf(struct mbuf *, int);
206
207 void sctp_ulp_notify(u_int32_t, struct sctp_tcb *, u_int32_t, void *);
208
209 void sctp_report_all_outbound(struct sctp_tcb *);
210
211 int sctp_expand_mapping_array(struct sctp_association *);
212
213 void sctp_abort_notification(struct sctp_tcb *, int);
214
215 /* We abort responding to an IP packet for some reason */
216 void sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *,
217     struct mbuf *, int, struct sctphdr *, struct mbuf *);
218
219 /* We choose to abort via user input */
220 void sctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, int,
221         struct mbuf *);
222
223 void sctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *,
224     struct sctp_inpcb *, struct mbuf *);
225
226 int sctp_is_there_an_abort_here(struct mbuf *, int, int *);
227 uint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *);
228 struct sockaddr_in6 *sctp_recover_scope(struct sockaddr_in6 *,
229         struct sockaddr_in6 *);
230
231 int sctp_cmpaddr(struct sockaddr *, struct sockaddr *);
232
233 void sctp_print_address(struct sockaddr *);
234 void sctp_print_address_pkt(struct ip *, struct sctphdr *);
235
236 int sctp_sbappendaddr_nocheck(struct signalsockbuf *, struct sockaddr *,
237         struct mbuf *, struct mbuf *, u_int32_t, struct sctp_inpcb *);
238
239
240 int sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *,
241         int, struct sctpchunk_listhead *);
242
243 struct mbuf *sctp_generate_invmanparam(int);
244
245 /*
246  * this is an evil layer violation that I think is a hack.. but I stand
247  * alone on the tsvwg in this thought... everyone else considers it part
248  * of the sockets layer (along with all of the peeloff code :<)
249  */
250 u_int32_t sctp_get_first_vtag_from_sb(struct socket *);
251
252
253 void sctp_grub_through_socket_buffer(struct sctp_inpcb *, struct socket *,
254                                      struct socket *, struct sctp_tcb *);
255
256 void sctp_free_bufspace(struct sctp_tcb *, struct sctp_association *,
257         struct sctp_tmit_chunk *);
258
259 #ifdef SCTP_STAT_LOGGING
260 void sctp_log_strm_del_alt(u_int32_t, u_int16_t, int);
261
262 void sctp_log_strm_del(struct sctp_tmit_chunk *, struct sctp_tmit_chunk *, int);
263 void sctp_log_cwnd(struct sctp_nets *, int, uint8_t);
264 void sctp_log_maxburst(struct sctp_nets *, int, int, uint8_t);
265 void sctp_log_block(uint8_t, struct socket *, struct sctp_association *);
266 void sctp_log_rwnd(uint8_t, u_int32_t, u_int32_t, u_int32_t );
267 void sctp_log_mbcnt(uint8_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t);
268 void sctp_log_rwnd_set(uint8_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t);
269 int sctp_fill_stat_log(struct mbuf *);
270 void sctp_log_fr(uint32_t, uint32_t, uint32_t, int);
271 void sctp_log_map(uint32_t, uint32_t, uint32_t, int);
272
273 void sctp_clr_stat_log(void);
274
275 #endif
276
277 #ifdef SCTP_AUDITING_ENABLED
278 void sctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *,
279         struct sctp_nets *);
280 void sctp_audit_log(u_int8_t, u_int8_t);
281
282 #endif
283
284 #if defined(SCTP_BASE_FREEBSD) || defined(__DragonFly__)
285 /* Note: these are in <sys/time.h>, but not in kernel space */
286 #define timerclear(tvp)         (tvp)->tv_sec = (tvp)->tv_usec = 0
287 #define timerisset(tvp)         ((tvp)->tv_sec || (tvp)->tv_usec)
288 #define timercmp(tvp, uvp, cmp)                                         \
289         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
290             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
291             ((tvp)->tv_sec cmp (uvp)->tv_sec))
292 #define timeradd(tvp, uvp, vvp)                                         \
293         do {                                                            \
294                 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;          \
295                 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;       \
296                 if ((vvp)->tv_usec >= 1000000) {                        \
297                         (vvp)->tv_sec++;                                \
298                         (vvp)->tv_usec -= 1000000;                      \
299                 }                                                       \
300         } while (/* CONSTCOND */ 0)
301 #define timersub(tvp, uvp, vvp)                                         \
302         do {                                                            \
303                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
304                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
305                 if ((vvp)->tv_usec < 0) {                               \
306                         (vvp)->tv_sec--;                                \
307                         (vvp)->tv_usec += 1000000;                      \
308                 }                                                       \
309         } while (/* CONSTCOND */ 0)
310 #endif /* SCTP_BASE_FREEBSD */
311
312 #endif /* _KERNEL */
313 #endif