sctputil.h revision 189790
1163953Srrs/*- 2169382Srrs * Copyright (c) 2001-2007, by 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 189790 2009-03-14 13:42:13Z rrs $"); 36163953Srrs#ifndef __sctputil_h__ 37163953Srrs#define __sctputil_h__ 38163953Srrs 39163953Srrs 40180387Srrs#if defined(_KERNEL) || defined(__Userspace__) 41163953Srrs 42168755Srrs 43168859Srrs#ifdef SCTP_ASOCLOG_OF_TSNS 44168859Srrsvoid sctp_print_out_track_log(struct sctp_tcb *stcb); 45168859Srrs 46168859Srrs#endif 47168859Srrs 48163953Srrs#ifdef SCTP_MBUF_LOGGING 49163953Srrsstruct mbuf *sctp_m_free(struct mbuf *m); 50163953Srrsvoid sctp_m_freem(struct mbuf *m); 51163953Srrs 52163953Srrs#else 53163953Srrs#define sctp_m_free m_free 54163953Srrs#define sctp_m_freem m_freem 55163953Srrs#endif 56163953Srrs 57171943Srrs#if defined(SCTP_LOCAL_TRACE_BUF) || defined(__APPLE__) 58171943Srrsvoid 59172157Srrs 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); 60163953Srrs 61171943Srrs#endif 62171943Srrs 63163953Srrs#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id) 64163953Srrs 65163953Srrs 66163953Srrs/* 67163953Srrs * Function prototypes 68163953Srrs */ 69167698Srrsuint32_t 70167698Srrssctp_get_ifa_hash_val(struct sockaddr *addr); 71167698Srrs 72167598Srrsstruct sctp_ifa * 73167598Srrs sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock); 74163953Srrs 75167598Srrsstruct sctp_ifa * 76167598Srrs sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock); 77167598Srrs 78163953Srrsuint32_t sctp_select_initial_TSN(struct sctp_pcb *); 79163953Srrs 80185694Srrsuint32_t sctp_select_a_tag(struct sctp_inpcb *, uint16_t lport, uint16_t rport, int); 81163953Srrs 82170138Srrsint sctp_init_asoc(struct sctp_inpcb *, struct sctp_tcb *, int, uint32_t, uint32_t); 83163953Srrs 84163953Srrsvoid sctp_fill_random_store(struct sctp_pcb *); 85163953Srrs 86169420Srrsvoid 87163953Srrssctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *, 88163953Srrs struct sctp_nets *); 89163953Srrs 90169378Srrsvoid 91163953Srrssctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *, 92165220Srrs struct sctp_nets *, uint32_t); 93163953Srrs 94167598Srrsint 95167598Srrs sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id); 96167598Srrs 97163953Srrsvoid 98166023Srrs sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t); 99163953Srrs 100163953Srrsvoid 101163953Srrssctp_add_to_readq(struct sctp_inpcb *inp, 102163953Srrs struct sctp_tcb *stcb, 103163953Srrs struct sctp_queued_to_read *control, 104163953Srrs struct sockbuf *sb, 105172090Srrs int end, 106172090Srrs int so_locked 107172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 108172090Srrs SCTP_UNUSED 109172090Srrs#endif 110172090Srrs); 111163953Srrs 112163953Srrsint 113163953Srrssctp_append_to_readq(struct sctp_inpcb *inp, 114163953Srrs struct sctp_tcb *stcb, 115163953Srrs struct sctp_queued_to_read *control, 116163953Srrs struct mbuf *m, 117163953Srrs int end, 118163953Srrs int new_cumack, 119163953Srrs struct sockbuf *sb); 120163953Srrs 121163953Srrs 122167598Srrsvoid sctp_iterator_worker(void); 123167598Srrs 124163953Srrsint find_next_best_mtu(int); 125163953Srrs 126163953Srrsvoid 127163953Srrs sctp_timeout_handler(void *); 128163953Srrs 129163953Srrsuint32_t 130163953Srrssctp_calculate_rto(struct sctp_tcb *, struct sctp_association *, 131171477Srrs struct sctp_nets *, struct timeval *, int); 132163953Srrs 133163953Srrsuint32_t sctp_calculate_len(struct mbuf *); 134163953Srrs 135163953Srrscaddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *); 136163953Srrs 137163953Srrsstruct sctp_paramhdr * 138163953Srrssctp_get_next_param(struct mbuf *, int, 139163953Srrs struct sctp_paramhdr *, int); 140163953Srrs 141163953Srrsint sctp_add_pad_tombuf(struct mbuf *, int); 142163953Srrs 143163953Srrsint sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *); 144163953Srrs 145172090Srrsvoid 146172090Srrssctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int 147172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 148172090Srrs SCTP_UNUSED 149172090Srrs#endif 150172090Srrs); 151163953Srrs 152163953Srrsvoid 153163953Srrssctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, 154163953Srrs struct sctp_inpcb *new_inp, 155169208Srrs struct sctp_tcb *stcb, int waitflags); 156163953Srrs 157163953Srrs 158163953Srrsvoid sctp_stop_timers_for_shutdown(struct sctp_tcb *); 159163953Srrs 160172090Srrsvoid 161172090Srrssctp_report_all_outbound(struct sctp_tcb *, int, int 162172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 163172090Srrs SCTP_UNUSED 164172090Srrs#endif 165172090Srrs); 166163953Srrs 167170138Srrsint sctp_expand_mapping_array(struct sctp_association *, uint32_t); 168163953Srrs 169185694Srrs/* EY nr_sack version of the above method, expands nr_mapping_array */ 170185694Srrsint sctp_expand_nr_mapping_array(struct sctp_association *, uint32_t); 171172090Srrsvoid 172172090Srrssctp_abort_notification(struct sctp_tcb *, int, int 173172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 174172090Srrs SCTP_UNUSED 175172090Srrs#endif 176172090Srrs); 177163953Srrs 178163953Srrs/* We abort responding to an IP packet for some reason */ 179163953Srrsvoid 180163953Srrssctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, 181179157Srrs struct mbuf *, int, struct sctphdr *, struct mbuf *, uint32_t, uint16_t); 182163953Srrs 183169352Srrs 184163953Srrs/* We choose to abort via user input */ 185163953Srrsvoid 186163953Srrssctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, int, 187172090Srrs struct mbuf *, int 188172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 189172090Srrs SCTP_UNUSED 190172090Srrs#endif 191172090Srrs); 192163953Srrs 193169352Srrsvoid 194163953Srrssctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *, 195179157Srrs struct sctp_inpcb *, struct mbuf *, uint32_t, uint16_t); 196163953Srrs 197170056Srrsint 198170056Srrssctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr, 199170056Srrs int totaddr, int *error); 200169352Srrs 201169352Srrsstruct sctp_tcb * 202170056Srrssctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr, 203170056Srrs int *totaddr, int *num_v4, int *num_v6, int *error, int limit, int *bad_addr); 204169352Srrs 205163953Srrsint sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *); 206178251Srrs 207178251Srrs#ifdef INET6 208163953Srrsuint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 209166675Srrs 210163953Srrsstruct sockaddr_in6 * 211166675Srrs sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 212163953Srrs 213163953Srrs#define sctp_recover_scope_mac(addr, store) do { \ 214166675Srrs if ((addr->sin6_family == AF_INET6) && \ 215166675Srrs (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \ 216166675Srrs *store = *addr; \ 217166675Srrs if (addr->sin6_scope_id == 0) { \ 218166675Srrs if (!sa6_recoverscope(store)) { \ 219166675Srrs addr = store; \ 220166675Srrs } \ 221166675Srrs } else { \ 222166675Srrs in6_clearscope(&addr->sin6_addr); \ 223166675Srrs addr = store; \ 224166675Srrs } \ 225166675Srrs } \ 226166675Srrs} while (0) 227178251Srrs#endif 228163953Srrs 229163953Srrsint sctp_cmpaddr(struct sockaddr *, struct sockaddr *); 230163953Srrs 231163953Srrsvoid sctp_print_address(struct sockaddr *); 232163953Srrsvoid sctp_print_address_pkt(struct ip *, struct sctphdr *); 233163953Srrs 234163953Srrsvoid 235163953Srrssctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, 236168943Srrs uint32_t error, int no_lock, uint32_t strseq); 237163953Srrs 238163953Srrsint 239163953Srrssctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, 240189790Srrs int, int 241172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 242172090Srrs SCTP_UNUSED 243172090Srrs#endif 244172090Srrs); 245163953Srrs 246163953Srrsstruct mbuf *sctp_generate_invmanparam(int); 247163953Srrs 248170606Srrsvoid 249170606Srrssctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp, 250170606Srrs struct sockaddr *sa, sctp_assoc_t assoc_id, 251170606Srrs uint32_t vrf_id, int *error, void *p); 252170606Srrsvoid 253170606Srrssctp_bindx_delete_address(struct socket *so, struct sctp_inpcb *inp, 254170606Srrs struct sockaddr *sa, sctp_assoc_t assoc_id, 255170606Srrs uint32_t vrf_id, int *error); 256163953Srrs 257171572Srrsint sctp_local_addr_count(struct sctp_tcb *stcb); 258171572Srrs 259163953Srrs#ifdef SCTP_MBCNT_LOGGING 260163953Srrsvoid 261163953Srrssctp_free_bufspace(struct sctp_tcb *, struct sctp_association *, 262170744Srrs struct sctp_tmit_chunk *, int); 263163953Srrs 264163953Srrs#else 265163953Srrs#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \ 266163953Srrsdo { \ 267163953Srrs if (tp1->data != NULL) { \ 268169420Srrs atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \ 269163953Srrs if ((asoc)->total_output_queue_size >= tp1->book_size) { \ 270169420Srrs atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \ 271163953Srrs } else { \ 272163953Srrs (asoc)->total_output_queue_size = 0; \ 273163953Srrs } \ 274163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 275163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 276163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \ 277169420Srrs atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \ 278163953Srrs } else { \ 279163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 280163953Srrs } \ 281163953Srrs } \ 282163953Srrs } \ 283163953Srrs} while (0) 284163953Srrs 285163953Srrs#endif 286163953Srrs 287163953Srrs#define sctp_free_spbufspace(stcb, asoc, sp) \ 288163953Srrsdo { \ 289163953Srrs if (sp->data != NULL) { \ 290163953Srrs if ((asoc)->total_output_queue_size >= sp->length) { \ 291169420Srrs atomic_subtract_int(&(asoc)->total_output_queue_size, sp->length); \ 292163953Srrs } else { \ 293163953Srrs (asoc)->total_output_queue_size = 0; \ 294163953Srrs } \ 295163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 296163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 297163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \ 298169420Srrs atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \ 299163953Srrs } else { \ 300163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 301163953Srrs } \ 302163953Srrs } \ 303163953Srrs } \ 304163953Srrs} while (0) 305163953Srrs 306163953Srrs#define sctp_snd_sb_alloc(stcb, sz) \ 307163953Srrsdo { \ 308163953Srrs atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \ 309163953Srrs if ((stcb->sctp_socket != NULL) && \ 310163953Srrs ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 311163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 312163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \ 313163953Srrs } \ 314163953Srrs} while (0) 315163953Srrs 316179157Srrs/* new functions to start/stop udp tunneling */ 317179157Srrsvoid sctp_over_udp_stop(void); 318179157Srrsint sctp_over_udp_start(void); 319163953Srrs 320163953Srrsint 321163953Srrssctp_soreceive(struct socket *so, struct sockaddr **psa, 322163953Srrs struct uio *uio, 323163953Srrs struct mbuf **mp0, 324163953Srrs struct mbuf **controlp, 325163953Srrs int *flagsp); 326163953Srrs 327163953Srrs 328169352Srrs/* For those not passing mbufs, this does the 329169352Srrs * translations for you. Caller owns memory 330169352Srrs * of size controllen returned in controlp. 331169352Srrs */ 332169352Srrsint 333169352Srrssctp_l_soreceive(struct socket *so, 334169352Srrs struct sockaddr **name, 335169352Srrs struct uio *uio, 336169352Srrs char **controlp, 337169352Srrs int *controllen, 338169352Srrs int *flag); 339169352Srrs 340169352Srrs 341163953Srrsvoid 342163953Srrs sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d); 343163953Srrs 344163953Srrsvoid 345163953Srrssctp_wakeup_log(struct sctp_tcb *stcb, 346163953Srrs uint32_t cumtsn, 347163953Srrs uint32_t wake_cnt, int from); 348163953Srrs 349164181Srrsvoid sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int); 350163953Srrs 351163953Srrsvoid sctp_log_nagle_event(struct sctp_tcb *stcb, int action); 352163953Srrs 353163953Srrs 354163953Srrsvoid 355163953Srrs sctp_log_mb(struct mbuf *m, int from); 356163953Srrs 357163953Srrsvoid 358163953Srrssctp_sblog(struct sockbuf *sb, 359163953Srrs struct sctp_tcb *stcb, int from, int incr); 360163953Srrs 361163953Srrsvoid 362163953Srrssctp_log_strm_del(struct sctp_queued_to_read *control, 363163953Srrs struct sctp_queued_to_read *poschk, 364163953Srrs int from); 365163953Srrsvoid sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t); 366163953Srrsvoid rto_logging(struct sctp_nets *net, int from); 367163953Srrs 368163953Srrsvoid sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc); 369163953Srrs 370163953Srrsvoid sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from); 371163953Srrsvoid sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t); 372163953Srrsvoid sctp_log_block(uint8_t, struct socket *, struct sctp_association *, int); 373163953Srrsvoid sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t); 374163953Srrsvoid sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 375163953Srrsvoid sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 376167598Srrsint sctp_fill_stat_log(void *, size_t *); 377163953Srrsvoid sctp_log_fr(uint32_t, uint32_t, uint32_t, int); 378163953Srrsvoid sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int); 379163953Srrsvoid sctp_log_map(uint32_t, uint32_t, uint32_t, int); 380163953Srrs 381163953Srrsvoid sctp_clr_stat_log(void); 382163953Srrs 383163953Srrs 384163953Srrs#ifdef SCTP_AUDITING_ENABLED 385163953Srrsvoid 386163953Srrssctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *, 387163953Srrs struct sctp_nets *); 388163953Srrsvoid sctp_audit_log(uint8_t, uint8_t); 389163953Srrs 390163953Srrs#endif 391163953Srrs 392163953Srrs 393163953Srrs#endif /* _KERNEL */ 394163953Srrs#endif 395