sctputil.h revision 235403
1163953Srrs/*- 2169382Srrs * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 3218319Srrs * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved. 4218319Srrs * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved. 5163953Srrs * 6163953Srrs * Redistribution and use in source and binary forms, with or without 7163953Srrs * modification, are permitted provided that the following conditions are met: 8163953Srrs * 9163953Srrs * a) Redistributions of source code must retain the above copyright notice, 10228653Stuexen * this list of conditions and the following disclaimer. 11163953Srrs * 12163953Srrs * b) Redistributions in binary form must reproduce the above copyright 13163953Srrs * notice, this list of conditions and the following disclaimer in 14228653Stuexen * the documentation and/or other materials provided with the distribution. 15163953Srrs * 16163953Srrs * c) Neither the name of Cisco Systems, Inc. nor the names of its 17163953Srrs * contributors may be used to endorse or promote products derived 18163953Srrs * from this software without specific prior written permission. 19163953Srrs * 20163953Srrs * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21163953Srrs * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22163953Srrs * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23163953Srrs * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24163953Srrs * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25163953Srrs * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26163953Srrs * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27163953Srrs * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28163953Srrs * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29163953Srrs * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30163953Srrs * THE POSSIBILITY OF SUCH DAMAGE. 31163953Srrs */ 32163953Srrs 33163953Srrs 34163953Srrs/* $KAME: sctputil.h,v 1.15 2005/03/06 16:04:19 itojun Exp $ */ 35163953Srrs 36163953Srrs#include <sys/cdefs.h> 37163953Srrs__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 235403 2012-05-13 16:56:16Z tuexen $"); 38163953Srrs#ifndef __sctputil_h__ 39163953Srrs#define __sctputil_h__ 40163953Srrs 41163953Srrs 42180387Srrs#if defined(_KERNEL) || defined(__Userspace__) 43163953Srrs 44195918Srrs#define SCTP_READ_LOCK_HELD 1 45195918Srrs#define SCTP_READ_LOCK_NOT_HELD 0 46168755Srrs 47168859Srrs#ifdef SCTP_ASOCLOG_OF_TSNS 48168859Srrsvoid sctp_print_out_track_log(struct sctp_tcb *stcb); 49168859Srrs 50168859Srrs#endif 51168859Srrs 52163953Srrs#ifdef SCTP_MBUF_LOGGING 53163953Srrsstruct mbuf *sctp_m_free(struct mbuf *m); 54163953Srrsvoid sctp_m_freem(struct mbuf *m); 55163953Srrs 56163953Srrs#else 57163953Srrs#define sctp_m_free m_free 58163953Srrs#define sctp_m_freem m_freem 59163953Srrs#endif 60163953Srrs 61171943Srrs#if defined(SCTP_LOCAL_TRACE_BUF) || defined(__APPLE__) 62171943Srrsvoid 63172157Srrs 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); 64163953Srrs 65171943Srrs#endif 66171943Srrs 67163953Srrs#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id) 68163953Srrs 69163953Srrs 70163953Srrs/* 71163953Srrs * Function prototypes 72163953Srrs */ 73167698Srrsuint32_t 74167698Srrssctp_get_ifa_hash_val(struct sockaddr *addr); 75167698Srrs 76167598Srrsstruct sctp_ifa * 77167598Srrs sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock); 78163953Srrs 79167598Srrsstruct sctp_ifa * 80167598Srrs sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock); 81167598Srrs 82163953Srrsuint32_t sctp_select_initial_TSN(struct sctp_pcb *); 83163953Srrs 84185694Srrsuint32_t sctp_select_a_tag(struct sctp_inpcb *, uint16_t lport, uint16_t rport, int); 85163953Srrs 86206137Stuexenint sctp_init_asoc(struct sctp_inpcb *, struct sctp_tcb *, uint32_t, uint32_t); 87163953Srrs 88163953Srrsvoid sctp_fill_random_store(struct sctp_pcb *); 89163953Srrs 90169420Srrsvoid 91233660Srrssctp_notify_stream_reset_add(struct sctp_tcb *stcb, uint16_t numberin, 92233660Srrs uint16_t numberout, int flag); 93233660Srrsvoid 94233660Srrs sctp_notify_stream_reset_tsn(struct sctp_tcb *stcb, uint32_t sending_tsn, uint32_t recv_tsn, int flag); 95233660Srrs 96233660Srrsvoid 97163953Srrssctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *, 98163953Srrs struct sctp_nets *); 99163953Srrs 100169378Srrsvoid 101163953Srrssctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *, 102165220Srrs struct sctp_nets *, uint32_t); 103163953Srrs 104167598Srrsint 105167598Srrs sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id); 106167598Srrs 107163953Srrsvoid 108166023Srrs sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t); 109163953Srrs 110163953Srrsvoid 111163953Srrssctp_add_to_readq(struct sctp_inpcb *inp, 112163953Srrs struct sctp_tcb *stcb, 113163953Srrs struct sctp_queued_to_read *control, 114163953Srrs struct sockbuf *sb, 115172090Srrs int end, 116195918Srrs int inpread_locked, 117172090Srrs int so_locked 118172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 119172090Srrs SCTP_UNUSED 120172090Srrs#endif 121172090Srrs); 122163953Srrs 123163953Srrsint 124163953Srrssctp_append_to_readq(struct sctp_inpcb *inp, 125163953Srrs struct sctp_tcb *stcb, 126163953Srrs struct sctp_queued_to_read *control, 127163953Srrs struct mbuf *m, 128163953Srrs int end, 129163953Srrs int new_cumack, 130163953Srrs struct sockbuf *sb); 131163953Srrs 132163953Srrs 133167598Srrsvoid sctp_iterator_worker(void); 134167598Srrs 135214939Stuexenuint32_t sctp_get_prev_mtu(uint32_t); 136228653Stuexenuint32_t sctp_get_next_mtu(uint32_t); 137163953Srrs 138163953Srrsvoid 139163953Srrs sctp_timeout_handler(void *); 140163953Srrs 141163953Srrsuint32_t 142163953Srrssctp_calculate_rto(struct sctp_tcb *, struct sctp_association *, 143218186Srrs struct sctp_nets *, struct timeval *, int, int); 144163953Srrs 145163953Srrsuint32_t sctp_calculate_len(struct mbuf *); 146163953Srrs 147163953Srrscaddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *); 148163953Srrs 149163953Srrsstruct sctp_paramhdr * 150163953Srrssctp_get_next_param(struct mbuf *, int, 151163953Srrs struct sctp_paramhdr *, int); 152163953Srrs 153163953Srrsint sctp_add_pad_tombuf(struct mbuf *, int); 154163953Srrs 155163953Srrsint sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *); 156163953Srrs 157172090Srrsvoid 158172090Srrssctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int 159172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 160172090Srrs SCTP_UNUSED 161172090Srrs#endif 162172090Srrs); 163163953Srrs 164163953Srrsvoid 165163953Srrssctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, 166163953Srrs struct sctp_inpcb *new_inp, 167169208Srrs struct sctp_tcb *stcb, int waitflags); 168163953Srrs 169163953Srrs 170163953Srrsvoid sctp_stop_timers_for_shutdown(struct sctp_tcb *); 171163953Srrs 172172090Srrsvoid 173172090Srrssctp_report_all_outbound(struct sctp_tcb *, int, int 174172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 175172090Srrs SCTP_UNUSED 176172090Srrs#endif 177172090Srrs); 178163953Srrs 179170138Srrsint sctp_expand_mapping_array(struct sctp_association *, uint32_t); 180163953Srrs 181172090Srrsvoid 182235403Stuexensctp_abort_notification(struct sctp_tcb *, uint8_t, uint16_t, 183235360Stuexen struct sctp_abort_chunk *, int 184172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 185172090Srrs SCTP_UNUSED 186172090Srrs#endif 187172090Srrs); 188163953Srrs 189163953Srrs/* We abort responding to an IP packet for some reason */ 190163953Srrsvoid 191163953Srrssctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, 192179157Srrs struct mbuf *, int, struct sctphdr *, struct mbuf *, uint32_t, uint16_t); 193163953Srrs 194169352Srrs 195163953Srrs/* We choose to abort via user input */ 196163953Srrsvoid 197235360Stuexensctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, 198172090Srrs struct mbuf *, int 199172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 200172090Srrs SCTP_UNUSED 201172090Srrs#endif 202172090Srrs); 203163953Srrs 204169352Srrsvoid 205163953Srrssctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *, 206179157Srrs struct sctp_inpcb *, struct mbuf *, uint32_t, uint16_t); 207163953Srrs 208170056Srrsint 209170056Srrssctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr, 210170056Srrs int totaddr, int *error); 211169352Srrs 212169352Srrsstruct sctp_tcb * 213170056Srrssctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr, 214170056Srrs int *totaddr, int *num_v4, int *num_v6, int *error, int limit, int *bad_addr); 215169352Srrs 216163953Srrsint sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *); 217178251Srrs 218178251Srrs#ifdef INET6 219163953Srrsuint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 220166675Srrs 221163953Srrsstruct sockaddr_in6 * 222166675Srrs sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 223163953Srrs 224163953Srrs#define sctp_recover_scope_mac(addr, store) do { \ 225166675Srrs if ((addr->sin6_family == AF_INET6) && \ 226166675Srrs (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \ 227166675Srrs *store = *addr; \ 228166675Srrs if (addr->sin6_scope_id == 0) { \ 229166675Srrs if (!sa6_recoverscope(store)) { \ 230166675Srrs addr = store; \ 231166675Srrs } \ 232166675Srrs } else { \ 233166675Srrs in6_clearscope(&addr->sin6_addr); \ 234166675Srrs addr = store; \ 235166675Srrs } \ 236166675Srrs } \ 237166675Srrs} while (0) 238178251Srrs#endif 239163953Srrs 240163953Srrsint sctp_cmpaddr(struct sockaddr *, struct sockaddr *); 241163953Srrs 242163953Srrsvoid sctp_print_address(struct sockaddr *); 243163953Srrsvoid sctp_print_address_pkt(struct ip *, struct sctphdr *); 244163953Srrs 245163953Srrsint 246163953Srrssctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, 247189790Srrs int, int 248172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 249172090Srrs SCTP_UNUSED 250172090Srrs#endif 251172090Srrs); 252163953Srrs 253163953Srrsstruct mbuf *sctp_generate_invmanparam(int); 254163953Srrs 255170606Srrsvoid 256170606Srrssctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp, 257170606Srrs struct sockaddr *sa, sctp_assoc_t assoc_id, 258170606Srrs uint32_t vrf_id, int *error, void *p); 259170606Srrsvoid 260228653Stuexensctp_bindx_delete_address(struct sctp_inpcb *inp, 261170606Srrs struct sockaddr *sa, sctp_assoc_t assoc_id, 262170606Srrs uint32_t vrf_id, int *error); 263163953Srrs 264171572Srrsint sctp_local_addr_count(struct sctp_tcb *stcb); 265171572Srrs 266163953Srrs#ifdef SCTP_MBCNT_LOGGING 267163953Srrsvoid 268163953Srrssctp_free_bufspace(struct sctp_tcb *, struct sctp_association *, 269170744Srrs struct sctp_tmit_chunk *, int); 270163953Srrs 271163953Srrs#else 272163953Srrs#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \ 273163953Srrsdo { \ 274163953Srrs if (tp1->data != NULL) { \ 275169420Srrs atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \ 276163953Srrs if ((asoc)->total_output_queue_size >= tp1->book_size) { \ 277169420Srrs atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \ 278163953Srrs } else { \ 279163953Srrs (asoc)->total_output_queue_size = 0; \ 280163953Srrs } \ 281163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 282163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 283163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \ 284169420Srrs atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \ 285163953Srrs } else { \ 286163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 287163953Srrs } \ 288163953Srrs } \ 289163953Srrs } \ 290163953Srrs} while (0) 291163953Srrs 292163953Srrs#endif 293163953Srrs 294163953Srrs#define sctp_free_spbufspace(stcb, asoc, sp) \ 295163953Srrsdo { \ 296163953Srrs if (sp->data != NULL) { \ 297163953Srrs if ((asoc)->total_output_queue_size >= sp->length) { \ 298169420Srrs atomic_subtract_int(&(asoc)->total_output_queue_size, sp->length); \ 299163953Srrs } else { \ 300163953Srrs (asoc)->total_output_queue_size = 0; \ 301163953Srrs } \ 302163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 303163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 304163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \ 305169420Srrs atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \ 306163953Srrs } else { \ 307163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 308163953Srrs } \ 309163953Srrs } \ 310163953Srrs } \ 311163953Srrs} while (0) 312163953Srrs 313163953Srrs#define sctp_snd_sb_alloc(stcb, sz) \ 314163953Srrsdo { \ 315163953Srrs atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \ 316163953Srrs if ((stcb->sctp_socket != NULL) && \ 317163953Srrs ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 318163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 319163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \ 320163953Srrs } \ 321163953Srrs} while (0) 322163953Srrs 323221328Stuexen/* functions to start/stop udp tunneling */ 324221328Stuexen/* XXX: Remove the #ifdef after tunneling over IPv6 works also on FreeBSD. */ 325221328Stuexen#ifdef INET 326179157Srrsvoid sctp_over_udp_stop(void); 327179157Srrsint sctp_over_udp_start(void); 328163953Srrs 329221328Stuexen#endif 330221328Stuexen 331163953Srrsint 332163953Srrssctp_soreceive(struct socket *so, struct sockaddr **psa, 333163953Srrs struct uio *uio, 334163953Srrs struct mbuf **mp0, 335163953Srrs struct mbuf **controlp, 336163953Srrs int *flagsp); 337163953Srrs 338163953Srrsvoid 339163953Srrs sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d); 340163953Srrs 341163953Srrsvoid 342163953Srrssctp_wakeup_log(struct sctp_tcb *stcb, 343163953Srrs uint32_t wake_cnt, int from); 344163953Srrs 345164181Srrsvoid sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int); 346163953Srrs 347163953Srrsvoid sctp_log_nagle_event(struct sctp_tcb *stcb, int action); 348163953Srrs 349163953Srrs 350163953Srrsvoid 351163953Srrs sctp_log_mb(struct mbuf *m, int from); 352163953Srrs 353163953Srrsvoid 354163953Srrssctp_sblog(struct sockbuf *sb, 355163953Srrs struct sctp_tcb *stcb, int from, int incr); 356163953Srrs 357163953Srrsvoid 358163953Srrssctp_log_strm_del(struct sctp_queued_to_read *control, 359163953Srrs struct sctp_queued_to_read *poschk, 360163953Srrs int from); 361163953Srrsvoid sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t); 362163953Srrsvoid rto_logging(struct sctp_nets *net, int from); 363163953Srrs 364163953Srrsvoid sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc); 365163953Srrs 366163953Srrsvoid sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from); 367163953Srrsvoid sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t); 368228653Stuexenvoid sctp_log_block(uint8_t, struct sctp_association *, int); 369163953Srrsvoid sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t); 370163953Srrsvoid sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 371163953Srrsvoid sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 372167598Srrsint sctp_fill_stat_log(void *, size_t *); 373163953Srrsvoid sctp_log_fr(uint32_t, uint32_t, uint32_t, int); 374163953Srrsvoid sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int); 375163953Srrsvoid sctp_log_map(uint32_t, uint32_t, uint32_t, int); 376205502Srrsvoid sctp_print_mapping_array(struct sctp_association *asoc); 377163953Srrsvoid sctp_clr_stat_log(void); 378163953Srrs 379163953Srrs 380163953Srrs#ifdef SCTP_AUDITING_ENABLED 381163953Srrsvoid 382163953Srrssctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *, 383163953Srrs struct sctp_nets *); 384163953Srrsvoid sctp_audit_log(uint8_t, uint8_t); 385163953Srrs 386163953Srrs#endif 387163953Srrs 388163953Srrs 389163953Srrs#endif /* _KERNEL */ 390163953Srrs#endif 391