sctputil.h revision 172157
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 172157 2007-09-13 14:43:54Z rrs $"); 36163953Srrs#ifndef __sctputil_h__ 37163953Srrs#define __sctputil_h__ 38163953Srrs 39163953Srrs 40163953Srrs#if defined(_KERNEL) 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 80163953Srrsuint32_t sctp_select_a_tag(struct sctp_inpcb *); 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 97163953Srrsuint32_t sctp_calculate_sum(struct mbuf *, int32_t *, uint32_t); 98163953Srrs 99163953Srrsvoid 100166023Srrs sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t); 101163953Srrs 102163953Srrsvoid 103163953Srrssctp_add_to_readq(struct sctp_inpcb *inp, 104163953Srrs struct sctp_tcb *stcb, 105163953Srrs struct sctp_queued_to_read *control, 106163953Srrs struct sockbuf *sb, 107172090Srrs int end, 108172090Srrs int so_locked 109172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 110172090Srrs SCTP_UNUSED 111172090Srrs#endif 112172090Srrs); 113163953Srrs 114163953Srrsint 115163953Srrssctp_append_to_readq(struct sctp_inpcb *inp, 116163953Srrs struct sctp_tcb *stcb, 117163953Srrs struct sctp_queued_to_read *control, 118163953Srrs struct mbuf *m, 119163953Srrs int end, 120163953Srrs int new_cumack, 121163953Srrs struct sockbuf *sb); 122163953Srrs 123163953Srrs 124167598Srrsvoid sctp_iterator_worker(void); 125167598Srrs 126163953Srrsint find_next_best_mtu(int); 127163953Srrs 128163953Srrsvoid 129163953Srrs sctp_timeout_handler(void *); 130163953Srrs 131163953Srrsuint32_t 132163953Srrssctp_calculate_rto(struct sctp_tcb *, struct sctp_association *, 133171477Srrs struct sctp_nets *, struct timeval *, int); 134163953Srrs 135163953Srrsuint32_t sctp_calculate_len(struct mbuf *); 136163953Srrs 137163953Srrscaddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *); 138163953Srrs 139163953Srrsstruct sctp_paramhdr * 140163953Srrssctp_get_next_param(struct mbuf *, int, 141163953Srrs struct sctp_paramhdr *, int); 142163953Srrs 143163953Srrsint sctp_add_pad_tombuf(struct mbuf *, int); 144163953Srrs 145163953Srrsint sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *); 146163953Srrs 147172090Srrsvoid 148172090Srrssctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int 149172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 150172090Srrs SCTP_UNUSED 151172090Srrs#endif 152172090Srrs); 153163953Srrs 154163953Srrsvoid 155163953Srrssctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, 156163953Srrs struct sctp_inpcb *new_inp, 157169208Srrs struct sctp_tcb *stcb, int waitflags); 158163953Srrs 159163953Srrs 160163953Srrsvoid sctp_stop_timers_for_shutdown(struct sctp_tcb *); 161163953Srrs 162172090Srrsvoid 163172090Srrssctp_report_all_outbound(struct sctp_tcb *, int, int 164172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 165172090Srrs SCTP_UNUSED 166172090Srrs#endif 167172090Srrs); 168163953Srrs 169170138Srrsint sctp_expand_mapping_array(struct sctp_association *, uint32_t); 170163953Srrs 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 *, 181170181Srrs struct mbuf *, int, struct sctphdr *, struct mbuf *, uint32_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 *, 195170181Srrs struct sctp_inpcb *, struct mbuf *, uint32_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 *); 206163953Srrsuint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 207166675Srrs 208163953Srrsstruct sockaddr_in6 * 209166675Srrs sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 210163953Srrs 211163953Srrs#define sctp_recover_scope_mac(addr, store) do { \ 212166675Srrs if ((addr->sin6_family == AF_INET6) && \ 213166675Srrs (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \ 214166675Srrs *store = *addr; \ 215166675Srrs if (addr->sin6_scope_id == 0) { \ 216166675Srrs if (!sa6_recoverscope(store)) { \ 217166675Srrs addr = store; \ 218166675Srrs } \ 219166675Srrs } else { \ 220166675Srrs in6_clearscope(&addr->sin6_addr); \ 221166675Srrs addr = store; \ 222166675Srrs } \ 223166675Srrs } \ 224166675Srrs} while (0) 225163953Srrs 226163953Srrs 227163953Srrsint sctp_cmpaddr(struct sockaddr *, struct sockaddr *); 228163953Srrs 229163953Srrsvoid sctp_print_address(struct sockaddr *); 230163953Srrsvoid sctp_print_address_pkt(struct ip *, struct sctphdr *); 231163953Srrs 232163953Srrsvoid 233163953Srrssctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, 234168943Srrs uint32_t error, int no_lock, uint32_t strseq); 235163953Srrs 236163953Srrsint 237163953Srrssctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, 238172090Srrs int, struct sctpchunk_listhead *, int 239172090Srrs#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) 240172090Srrs SCTP_UNUSED 241172090Srrs#endif 242172090Srrs); 243163953Srrs 244163953Srrsstruct mbuf *sctp_generate_invmanparam(int); 245163953Srrs 246170606Srrsvoid 247170606Srrssctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp, 248170606Srrs struct sockaddr *sa, sctp_assoc_t assoc_id, 249170606Srrs uint32_t vrf_id, int *error, void *p); 250170606Srrsvoid 251170606Srrssctp_bindx_delete_address(struct socket *so, struct sctp_inpcb *inp, 252170606Srrs struct sockaddr *sa, sctp_assoc_t assoc_id, 253170606Srrs uint32_t vrf_id, int *error); 254163953Srrs 255171572Srrsint sctp_local_addr_count(struct sctp_tcb *stcb); 256171572Srrs 257163953Srrs#ifdef SCTP_MBCNT_LOGGING 258163953Srrsvoid 259163953Srrssctp_free_bufspace(struct sctp_tcb *, struct sctp_association *, 260170744Srrs struct sctp_tmit_chunk *, int); 261163953Srrs 262163953Srrs#else 263163953Srrs#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \ 264163953Srrsdo { \ 265163953Srrs if (tp1->data != NULL) { \ 266169420Srrs atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \ 267163953Srrs if ((asoc)->total_output_queue_size >= tp1->book_size) { \ 268169420Srrs atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \ 269163953Srrs } else { \ 270163953Srrs (asoc)->total_output_queue_size = 0; \ 271163953Srrs } \ 272163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 273163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 274163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \ 275169420Srrs atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \ 276163953Srrs } else { \ 277163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 278163953Srrs } \ 279163953Srrs } \ 280163953Srrs } \ 281163953Srrs} while (0) 282163953Srrs 283163953Srrs#endif 284163953Srrs 285163953Srrs#define sctp_free_spbufspace(stcb, asoc, sp) \ 286163953Srrsdo { \ 287163953Srrs if (sp->data != NULL) { \ 288169420Srrs atomic_subtract_int(&(asoc)->chunks_on_out_queue, 1); \ 289163953Srrs if ((asoc)->total_output_queue_size >= sp->length) { \ 290169420Srrs atomic_subtract_int(&(asoc)->total_output_queue_size, sp->length); \ 291163953Srrs } else { \ 292163953Srrs (asoc)->total_output_queue_size = 0; \ 293163953Srrs } \ 294163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 295163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 296163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \ 297169420Srrs atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \ 298163953Srrs } else { \ 299163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 300163953Srrs } \ 301163953Srrs } \ 302163953Srrs } \ 303163953Srrs} while (0) 304163953Srrs 305163953Srrs#define sctp_snd_sb_alloc(stcb, sz) \ 306163953Srrsdo { \ 307163953Srrs atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \ 308163953Srrs if ((stcb->sctp_socket != NULL) && \ 309163953Srrs ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 310163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 311163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \ 312163953Srrs } \ 313163953Srrs} while (0) 314163953Srrs 315163953Srrs 316163953Srrsint 317163953Srrssctp_soreceive(struct socket *so, struct sockaddr **psa, 318163953Srrs struct uio *uio, 319163953Srrs struct mbuf **mp0, 320163953Srrs struct mbuf **controlp, 321163953Srrs int *flagsp); 322163953Srrs 323163953Srrs 324169352Srrs/* For those not passing mbufs, this does the 325169352Srrs * translations for you. Caller owns memory 326169352Srrs * of size controllen returned in controlp. 327169352Srrs */ 328169352Srrsint 329169352Srrssctp_l_soreceive(struct socket *so, 330169352Srrs struct sockaddr **name, 331169352Srrs struct uio *uio, 332169352Srrs char **controlp, 333169352Srrs int *controllen, 334169352Srrs int *flag); 335169352Srrs 336169352Srrs 337163953Srrsvoid 338163953Srrs sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d); 339163953Srrs 340163953Srrsvoid 341163953Srrssctp_wakeup_log(struct sctp_tcb *stcb, 342163953Srrs uint32_t cumtsn, 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); 368163953Srrsvoid sctp_log_block(uint8_t, struct socket *, 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); 376163953Srrs 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