netwerk/sctp/src/netinet/sctputil.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/sctp/src/netinet/sctputil.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,406 @@
     1.4 +/*-
     1.5 + * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
     1.6 + * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
     1.7 + * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions are met:
    1.11 + *
    1.12 + * a) Redistributions of source code must retain the above copyright notice,
    1.13 + *    this list of conditions and the following disclaimer.
    1.14 + *
    1.15 + * b) Redistributions in binary form must reproduce the above copyright
    1.16 + *    notice, this list of conditions and the following disclaimer in
    1.17 + *    the documentation and/or other materials provided with the distribution.
    1.18 + *
    1.19 + * c) Neither the name of Cisco Systems, Inc. nor the names of its
    1.20 + *    contributors may be used to endorse or promote products derived
    1.21 + *    from this software without specific prior written permission.
    1.22 + *
    1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    1.25 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.26 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    1.27 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.28 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.29 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.30 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.31 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.32 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
    1.33 + * THE POSSIBILITY OF SUCH DAMAGE.
    1.34 + */
    1.35 +
    1.36 +#ifdef __FreeBSD__
    1.37 +#include <sys/cdefs.h>
    1.38 +__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 243186 2012-11-17 20:04:04Z tuexen $");
    1.39 +#endif
    1.40 +
    1.41 +#ifndef _NETINET_SCTP_UTIL_H_
    1.42 +#define _NETINET_SCTP_UTIL_H_
    1.43 +
    1.44 +#if defined(_KERNEL) || defined(__Userspace__)
    1.45 +
    1.46 +#define SCTP_READ_LOCK_HELD 1
    1.47 +#define SCTP_READ_LOCK_NOT_HELD 0
    1.48 +
    1.49 +#ifdef SCTP_ASOCLOG_OF_TSNS
    1.50 +void sctp_print_out_track_log(struct sctp_tcb *stcb);
    1.51 +#endif
    1.52 +
    1.53 +#ifdef SCTP_MBUF_LOGGING
    1.54 +struct mbuf *sctp_m_free(struct mbuf *m);
    1.55 +void sctp_m_freem(struct mbuf *m);
    1.56 +#else
    1.57 +#define sctp_m_free m_free
    1.58 +#define sctp_m_freem m_freem
    1.59 +#endif
    1.60 +
    1.61 +#if defined(SCTP_LOCAL_TRACE_BUF) || defined(__APPLE__)
    1.62 +void
    1.63 +sctp_log_trace(uint32_t fr, const char *str SCTP_UNUSED, uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, uint32_t f);
    1.64 +#endif
    1.65 +
    1.66 +#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id)
    1.67 +
    1.68 +
    1.69 +/*
    1.70 + * Function prototypes
    1.71 + */
    1.72 +uint32_t
    1.73 +sctp_get_ifa_hash_val(struct sockaddr *addr);
    1.74 +
    1.75 +struct sctp_ifa *
    1.76 +sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock);
    1.77 +
    1.78 +struct sctp_ifa *
    1.79 +sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock);
    1.80 +
    1.81 +uint32_t sctp_select_initial_TSN(struct sctp_pcb *);
    1.82 +
    1.83 +uint32_t sctp_select_a_tag(struct sctp_inpcb *, uint16_t lport, uint16_t rport, int);
    1.84 +
    1.85 +int sctp_init_asoc(struct sctp_inpcb *, struct sctp_tcb *, uint32_t, uint32_t);
    1.86 +
    1.87 +void sctp_fill_random_store(struct sctp_pcb *);
    1.88 +
    1.89 +void
    1.90 +sctp_notify_stream_reset_add(struct sctp_tcb *stcb, uint16_t numberin,
    1.91 +			     uint16_t numberout, int flag);
    1.92 +void
    1.93 +sctp_notify_stream_reset_tsn(struct sctp_tcb *stcb, uint32_t sending_tsn, uint32_t recv_tsn, int flag);
    1.94 +
    1.95 +void
    1.96 +sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *,
    1.97 +    struct sctp_nets *);
    1.98 +
    1.99 +void
   1.100 +sctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *,
   1.101 +    struct sctp_nets *, uint32_t);
   1.102 +
   1.103 +int
   1.104 +sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id);
   1.105 +
   1.106 +void
   1.107 +sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t);
   1.108 +
   1.109 +void
   1.110 +sctp_add_to_readq(struct sctp_inpcb *inp,
   1.111 +    struct sctp_tcb *stcb,
   1.112 +    struct sctp_queued_to_read *control,
   1.113 +    struct sockbuf *sb,
   1.114 +    int end,
   1.115 +    int inpread_locked,
   1.116 +    int so_locked
   1.117 +#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
   1.118 +    SCTP_UNUSED
   1.119 +#endif
   1.120 +    );
   1.121 +
   1.122 +int
   1.123 +sctp_append_to_readq(struct sctp_inpcb *inp,
   1.124 +    struct sctp_tcb *stcb,
   1.125 +    struct sctp_queued_to_read *control,
   1.126 +    struct mbuf *m,
   1.127 +    int end,
   1.128 +    int new_cumack,
   1.129 +    struct sockbuf *sb);
   1.130 +
   1.131 +
   1.132 +void sctp_iterator_worker(void);
   1.133 +
   1.134 +uint32_t sctp_get_prev_mtu(uint32_t);
   1.135 +uint32_t sctp_get_next_mtu(uint32_t);
   1.136 +
   1.137 +void
   1.138 +sctp_timeout_handler(void *);
   1.139 +
   1.140 +uint32_t
   1.141 +sctp_calculate_rto(struct sctp_tcb *, struct sctp_association *,
   1.142 +    struct sctp_nets *, struct timeval *, int, int);
   1.143 +
   1.144 +uint32_t sctp_calculate_len(struct mbuf *);
   1.145 +
   1.146 +caddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *);
   1.147 +
   1.148 +struct sctp_paramhdr *
   1.149 +sctp_get_next_param(struct mbuf *, int,
   1.150 +    struct sctp_paramhdr *, int);
   1.151 +
   1.152 +int sctp_add_pad_tombuf(struct mbuf *, int);
   1.153 +
   1.154 +int sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *);
   1.155 +
   1.156 +void sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int
   1.157 +#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
   1.158 +    SCTP_UNUSED
   1.159 +#endif
   1.160 +    );
   1.161 +
   1.162 +void
   1.163 +sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
   1.164 +    struct sctp_inpcb *new_inp,
   1.165 +    struct sctp_tcb *stcb, int waitflags);
   1.166 +
   1.167 +
   1.168 +void sctp_stop_timers_for_shutdown(struct sctp_tcb *);
   1.169 +
   1.170 +void sctp_report_all_outbound(struct sctp_tcb *, uint16_t, int, int
   1.171 +#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
   1.172 +    SCTP_UNUSED
   1.173 +#endif
   1.174 +    );
   1.175 +
   1.176 +int sctp_expand_mapping_array(struct sctp_association *, uint32_t);
   1.177 +
   1.178 +void sctp_abort_notification(struct sctp_tcb *, uint8_t, uint16_t,
   1.179 +			     struct sctp_abort_chunk *, int
   1.180 +#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
   1.181 +    SCTP_UNUSED
   1.182 +#endif
   1.183 +    );
   1.184 +
   1.185 +/* We abort responding to an IP packet for some reason */
   1.186 +void
   1.187 +sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, struct mbuf *,
   1.188 +                       int, struct sockaddr *, struct sockaddr *,
   1.189 +                       struct sctphdr *, struct mbuf *,
   1.190 +#if defined(__FreeBSD__)
   1.191 +                       uint8_t, uint32_t,
   1.192 +#endif
   1.193 +                       uint32_t, uint16_t);
   1.194 +
   1.195 +
   1.196 +/* We choose to abort via user input */
   1.197 +void
   1.198 +sctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *,
   1.199 +    struct mbuf *, int
   1.200 +#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
   1.201 +    SCTP_UNUSED
   1.202 +#endif
   1.203 +);
   1.204 +
   1.205 +void sctp_handle_ootb(struct mbuf *, int, int,
   1.206 +                      struct sockaddr *, struct sockaddr *,
   1.207 +                      struct sctphdr *, struct sctp_inpcb *,
   1.208 +#if defined(__FreeBSD__)
   1.209 +                      uint8_t, uint32_t,
   1.210 +#endif
   1.211 +                      uint32_t, uint16_t);
   1.212 +
   1.213 +int sctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr,
   1.214 +    int totaddr, int *error);
   1.215 +
   1.216 +struct sctp_tcb *
   1.217 +sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr,
   1.218 +    int *totaddr, int *num_v4, int *num_v6, int *error, int limit, int *bad_addr);
   1.219 +
   1.220 +int sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *);
   1.221 +#ifdef INET6
   1.222 +uint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *);
   1.223 +
   1.224 +#if defined(SCTP_EMBEDDED_V6_SCOPE)
   1.225 +struct sockaddr_in6 *
   1.226 +sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *);
   1.227 +
   1.228 +#ifdef SCTP_KAME
   1.229 +#define sctp_recover_scope_mac(addr, store) do { \
   1.230 +	 if ((addr->sin6_family == AF_INET6) && \
   1.231 +	     (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \
   1.232 +		*store = *addr; \
   1.233 +		if (addr->sin6_scope_id == 0) { \
   1.234 +			if (!sa6_recoverscope(store)) { \
   1.235 +				addr = store; \
   1.236 +			} \
   1.237 +		} else { \
   1.238 +			in6_clearscope(&addr->sin6_addr); \
   1.239 +			addr = store; \
   1.240 +		} \
   1.241 +	 } \
   1.242 +} while (0)
   1.243 +#else
   1.244 +#define sctp_recover_scope_mac(addr, store) do { \
   1.245 +	 if ((addr->sin6_family == AF_INET6) && \
   1.246 +	     (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \
   1.247 +		*store = *addr; \
   1.248 +	 	if (addr->sin6_scope_id == 0) { \
   1.249 +			if (!in6_recoverscope(store, &store->sin6_addr, \
   1.250 +					      NULL)) { \
   1.251 +				addr = store; \
   1.252 +			} \
   1.253 +		} else { \
   1.254 +			in6_clearscope(&addr->sin6_addr); \
   1.255 +			addr = store; \
   1.256 +		} \
   1.257 +	 } \
   1.258 +} while (0)
   1.259 +#endif
   1.260 +#endif
   1.261 +#endif
   1.262 +
   1.263 +int sctp_cmpaddr(struct sockaddr *, struct sockaddr *);
   1.264 +
   1.265 +void sctp_print_address(struct sockaddr *);
   1.266 +
   1.267 +int
   1.268 +sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *,
   1.269 +    uint8_t, int
   1.270 +#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
   1.271 +    SCTP_UNUSED
   1.272 +#endif
   1.273 +);
   1.274 +
   1.275 +struct mbuf *sctp_generate_invmanparam(int);
   1.276 +
   1.277 +void sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp,
   1.278 +			    struct sockaddr *sa, sctp_assoc_t assoc_id,
   1.279 +			    uint32_t vrf_id, int *error, void *p);
   1.280 +void sctp_bindx_delete_address(struct sctp_inpcb *inp,
   1.281 +			       struct sockaddr *sa, sctp_assoc_t assoc_id,
   1.282 +			       uint32_t vrf_id, int *error);
   1.283 +
   1.284 +int sctp_local_addr_count(struct sctp_tcb *stcb);
   1.285 +
   1.286 +#ifdef SCTP_MBCNT_LOGGING
   1.287 +void
   1.288 +sctp_free_bufspace(struct sctp_tcb *, struct sctp_association *,
   1.289 +    struct sctp_tmit_chunk *, int);
   1.290 +
   1.291 +#else
   1.292 +#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt)  \
   1.293 +do { \
   1.294 +	if (tp1->data != NULL) { \
   1.295 +                atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \
   1.296 +		if ((asoc)->total_output_queue_size >= tp1->book_size) { \
   1.297 +			atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \
   1.298 +		} else { \
   1.299 +			(asoc)->total_output_queue_size = 0; \
   1.300 +		} \
   1.301 +   	        if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
   1.302 +	            (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
   1.303 +			if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \
   1.304 +				atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \
   1.305 +			} else { \
   1.306 +				stcb->sctp_socket->so_snd.sb_cc = 0; \
   1.307 +			} \
   1.308 +		} \
   1.309 +        } \
   1.310 +} while (0)
   1.311 +
   1.312 +#endif
   1.313 +
   1.314 +#define sctp_free_spbufspace(stcb, asoc, sp)  \
   1.315 +do { \
   1.316 + 	if (sp->data != NULL) { \
   1.317 +		if ((asoc)->total_output_queue_size >= sp->length) { \
   1.318 +			atomic_subtract_int(&(asoc)->total_output_queue_size, sp->length); \
   1.319 +		} else { \
   1.320 +			(asoc)->total_output_queue_size = 0; \
   1.321 +		} \
   1.322 +   	        if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
   1.323 +	            (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
   1.324 +			if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \
   1.325 +				atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \
   1.326 +			} else { \
   1.327 +				stcb->sctp_socket->so_snd.sb_cc = 0; \
   1.328 +			} \
   1.329 +		} \
   1.330 +        } \
   1.331 +} while (0)
   1.332 +
   1.333 +#define sctp_snd_sb_alloc(stcb, sz)  \
   1.334 +do { \
   1.335 +	atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \
   1.336 +	if ((stcb->sctp_socket != NULL) && \
   1.337 +	    ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
   1.338 +	     (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
   1.339 +		atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \
   1.340 +	} \
   1.341 +} while (0)
   1.342 +
   1.343 +/* functions to start/stop udp tunneling */
   1.344 +#if defined(__APPLE__) || defined(__FreeBSD__)
   1.345 +void sctp_over_udp_stop(void);
   1.346 +int sctp_over_udp_start(void);
   1.347 +#endif
   1.348 +#if defined(__Windows__)
   1.349 +void sctp_over_udp_restart(void);
   1.350 +#endif
   1.351 +
   1.352 +int
   1.353 +sctp_soreceive(struct socket *so, struct sockaddr **psa,
   1.354 +    struct uio *uio,
   1.355 +    struct mbuf **mp0,
   1.356 +    struct mbuf **controlp,
   1.357 +    int *flagsp);
   1.358 +
   1.359 +void
   1.360 +sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d);
   1.361 +
   1.362 +void
   1.363 +sctp_wakeup_log(struct sctp_tcb *stcb,
   1.364 +    uint32_t wake_cnt, int from);
   1.365 +
   1.366 +void sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int);
   1.367 +
   1.368 +void sctp_log_nagle_event(struct sctp_tcb *stcb, int action);
   1.369 +
   1.370 +
   1.371 +void
   1.372 +sctp_log_mb(struct mbuf *m, int from);
   1.373 +
   1.374 +void
   1.375 +sctp_sblog(struct sockbuf *sb,
   1.376 +    struct sctp_tcb *stcb, int from, int incr);
   1.377 +
   1.378 +void
   1.379 +sctp_log_strm_del(struct sctp_queued_to_read *control,
   1.380 +    struct sctp_queued_to_read *poschk,
   1.381 +    int from);
   1.382 +void sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t);
   1.383 +void rto_logging(struct sctp_nets *net, int from);
   1.384 +
   1.385 +void sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc);
   1.386 +
   1.387 +void sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from);
   1.388 +void sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t);
   1.389 +void sctp_log_block(uint8_t, struct sctp_association *, int);
   1.390 +void sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t);
   1.391 +void sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t);
   1.392 +void sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t);
   1.393 +int sctp_fill_stat_log(void *, size_t *);
   1.394 +void sctp_log_fr(uint32_t, uint32_t, uint32_t, int);
   1.395 +void sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int);
   1.396 +void sctp_log_map(uint32_t, uint32_t, uint32_t, int);
   1.397 +void sctp_print_mapping_array(struct sctp_association *asoc);
   1.398 +void sctp_clr_stat_log(void);
   1.399 +
   1.400 +
   1.401 +#ifdef SCTP_AUDITING_ENABLED
   1.402 +void
   1.403 +sctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *,
   1.404 +    struct sctp_nets *);
   1.405 +void sctp_audit_log(uint8_t, uint8_t);
   1.406 +
   1.407 +#endif
   1.408 +#endif				/* _KERNEL */
   1.409 +#endif

mercurial