sctputil.h revision 167698
1/*- 2 * Copyright (c) 2001-2007, Cisco Systems, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * a) Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * 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. 13 * 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. 17 * 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. 29 */ 30 31 32/* $KAME: sctputil.h,v 1.15 2005/03/06 16:04:19 itojun Exp $ */ 33 34#include <sys/cdefs.h> 35__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 167698 2007-03-19 11:11:16Z rrs $"); 36#ifndef __sctputil_h__ 37#define __sctputil_h__ 38 39 40#if defined(_KERNEL) 41 42#ifdef SCTP_MBUF_LOGGING 43 44struct mbuf *sctp_m_free(struct mbuf *m); 45void sctp_m_freem(struct mbuf *m); 46 47#else 48#define sctp_m_free m_free 49#define sctp_m_freem m_freem 50#endif 51 52 53#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id) 54 55 56/* 57 * Function prototypes 58 */ 59uint32_t 60sctp_get_ifa_hash_val(struct sockaddr *addr); 61 62struct sctp_ifa * 63 sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock); 64struct sctp_ifa * 65sctp_find_ifa_in_ifn(struct sctp_ifn *sctp_ifnp, struct sockaddr *addr, 66 int holds_lock); 67 68struct sctp_ifa * 69 sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock); 70 71uint32_t sctp_select_initial_TSN(struct sctp_pcb *); 72 73uint32_t sctp_select_a_tag(struct sctp_inpcb *); 74 75int sctp_init_asoc(struct sctp_inpcb *, struct sctp_association *, int, uint32_t, uint32_t); 76 77void sctp_fill_random_store(struct sctp_pcb *); 78 79int 80sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *, 81 struct sctp_nets *); 82 83int 84sctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *, 85 struct sctp_nets *, uint32_t); 86 87int 88 sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id); 89 90uint32_t sctp_calculate_sum(struct mbuf *, int32_t *, uint32_t); 91 92void 93 sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t); 94 95void 96sctp_add_to_readq(struct sctp_inpcb *inp, 97 struct sctp_tcb *stcb, 98 struct sctp_queued_to_read *control, 99 struct sockbuf *sb, 100 int end); 101 102int 103sctp_append_to_readq(struct sctp_inpcb *inp, 104 struct sctp_tcb *stcb, 105 struct sctp_queued_to_read *control, 106 struct mbuf *m, 107 int end, 108 int new_cumack, 109 struct sockbuf *sb); 110 111 112void sctp_iterator_worker(void); 113 114int find_next_best_mtu(int); 115 116void 117 sctp_timeout_handler(void *); 118 119uint32_t 120sctp_calculate_rto(struct sctp_tcb *, struct sctp_association *, 121 struct sctp_nets *, struct timeval *); 122 123uint32_t sctp_calculate_len(struct mbuf *); 124 125caddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *); 126 127struct sctp_paramhdr * 128sctp_get_next_param(struct mbuf *, int, 129 struct sctp_paramhdr *, int); 130 131int sctp_add_pad_tombuf(struct mbuf *, int); 132 133int sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *); 134 135void sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *); 136 137void 138sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, 139 struct sctp_inpcb *new_inp, 140 struct sctp_tcb *stcb); 141 142 143void sctp_stop_timers_for_shutdown(struct sctp_tcb *); 144 145void sctp_report_all_outbound(struct sctp_tcb *, int); 146 147int sctp_expand_mapping_array(struct sctp_association *); 148 149void sctp_abort_notification(struct sctp_tcb *, int); 150 151/* We abort responding to an IP packet for some reason */ 152void 153sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, 154 struct mbuf *, int, struct sctphdr *, struct mbuf *); 155 156/* We choose to abort via user input */ 157void 158sctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, int, 159 struct mbuf *); 160 161void 162sctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *, 163 struct sctp_inpcb *, struct mbuf *); 164 165int sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *); 166uint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 167 168struct sockaddr_in6 * 169 sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 170 171#define sctp_recover_scope_mac(addr, store) do { \ 172 if ((addr->sin6_family == AF_INET6) && \ 173 (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \ 174 *store = *addr; \ 175 if (addr->sin6_scope_id == 0) { \ 176 if (!sa6_recoverscope(store)) { \ 177 addr = store; \ 178 } \ 179 } else { \ 180 in6_clearscope(&addr->sin6_addr); \ 181 addr = store; \ 182 } \ 183 } \ 184} while (0) 185 186 187int sctp_cmpaddr(struct sockaddr *, struct sockaddr *); 188 189void sctp_print_address(struct sockaddr *); 190void sctp_print_address_pkt(struct ip *, struct sctphdr *); 191 192void 193sctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, 194 uint32_t error, int no_lock); 195 196int 197sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, 198 int, struct sctpchunk_listhead *); 199 200struct mbuf *sctp_generate_invmanparam(int); 201 202 203#ifdef SCTP_MBCNT_LOGGING 204void 205sctp_free_bufspace(struct sctp_tcb *, struct sctp_association *, 206 struct sctp_tmit_chunk *); 207 208#else 209#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \ 210do { \ 211 if (tp1->data != NULL) { \ 212 atomic_add_int(&((asoc)->chunks_on_out_queue), -chk_cnt); \ 213 if ((asoc)->total_output_queue_size >= tp1->book_size) { \ 214 atomic_add_int(&((asoc)->total_output_queue_size), -tp1->book_size); \ 215 } else { \ 216 (asoc)->total_output_queue_size = 0; \ 217 } \ 218 if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 219 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 220 if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \ 221 atomic_add_int(&((stcb)->sctp_socket->so_snd.sb_cc), -tp1->book_size); \ 222 } else { \ 223 stcb->sctp_socket->so_snd.sb_cc = 0; \ 224 } \ 225 } \ 226 } \ 227} while (0) 228 229#endif 230 231#define sctp_free_spbufspace(stcb, asoc, sp) \ 232do { \ 233 if (sp->data != NULL) { \ 234 atomic_add_int(&(asoc)->chunks_on_out_queue, -1); \ 235 if ((asoc)->total_output_queue_size >= sp->length) { \ 236 atomic_add_int(&(asoc)->total_output_queue_size,sp->length); \ 237 } else { \ 238 (asoc)->total_output_queue_size = 0; \ 239 } \ 240 if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 241 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 242 if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \ 243 atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \ 244 } else { \ 245 stcb->sctp_socket->so_snd.sb_cc = 0; \ 246 } \ 247 } \ 248 } \ 249} while (0) 250 251#define sctp_snd_sb_alloc(stcb, sz) \ 252do { \ 253 atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \ 254 if ((stcb->sctp_socket != NULL) && \ 255 ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 256 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 257 atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \ 258 } \ 259} while (0) 260 261 262int 263sctp_soreceive(struct socket *so, struct sockaddr **psa, 264 struct uio *uio, 265 struct mbuf **mp0, 266 struct mbuf **controlp, 267 int *flagsp); 268 269 270#ifdef SCTP_STAT_LOGGING 271void 272 sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d); 273 274void 275sctp_wakeup_log(struct sctp_tcb *stcb, 276 uint32_t cumtsn, 277 uint32_t wake_cnt, int from); 278 279void sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int); 280 281void sctp_log_nagle_event(struct sctp_tcb *stcb, int action); 282 283 284void 285 sctp_log_mb(struct mbuf *m, int from); 286 287void 288sctp_sblog(struct sockbuf *sb, 289 struct sctp_tcb *stcb, int from, int incr); 290 291void 292sctp_log_strm_del(struct sctp_queued_to_read *control, 293 struct sctp_queued_to_read *poschk, 294 int from); 295void sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t); 296void rto_logging(struct sctp_nets *net, int from); 297 298void sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc); 299 300void sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from); 301void sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t); 302void sctp_log_block(uint8_t, struct socket *, struct sctp_association *, int); 303void sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t); 304void sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 305void sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 306int sctp_fill_stat_log(void *, size_t *); 307void sctp_log_fr(uint32_t, uint32_t, uint32_t, int); 308void sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int); 309void sctp_log_map(uint32_t, uint32_t, uint32_t, int); 310 311void sctp_clr_stat_log(void); 312 313#endif 314 315#ifdef SCTP_AUDITING_ENABLED 316void 317sctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *, 318 struct sctp_nets *); 319void sctp_audit_log(uint8_t, uint8_t); 320 321#endif 322 323 324#endif /* _KERNEL */ 325#endif 326