sctputil.h revision 170181
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 170181 2007-06-01 11:19:54Z rrs $"); 36163953Srrs#ifndef __sctputil_h__ 37163953Srrs#define __sctputil_h__ 38163953Srrs 39163953Srrs 40163953Srrs#if defined(_KERNEL) 41163953Srrs 42168755Srrs 43168755Srrs/*- 44168755Srrs * Any new logging added must also define SCTP_STAT_LOGGING if 45168755Srrs * its not already defined. 46168755Srrs */ 47169208Srrs 48170138Srrs#if defined(SCTP_LOG_MAXBURST) || defined(SCTP_LOG_RWND) 49168755Srrs#ifndef SCTP_STAT_LOGGING 50168755Srrs#define SCTP_STAT_LOGGING 1 51168755Srrs#endif 52168755Srrs#endif 53168755Srrs 54168757Srrs#if defined(SCTP_CWND_LOGGING) || defined(SCTP_CWND_MONITOR) || defined(SCTP_BLK_LOGGING) 55168755Srrs#ifndef SCTP_STAT_LOGGING 56168755Srrs#define SCTP_STAT_LOGGING 1 57168755Srrs#endif 58168755Srrs#endif 59168755Srrs 60168757Srrs#if defined(SCTP_STR_LOGGING) || defined(SCTP_FR_LOGGING) || defined(SCTP_MAP_LOGGING) 61168755Srrs#ifndef SCTP_STAT_LOGGING 62168755Srrs#define SCTP_STAT_LOGGING 1 63168755Srrs#endif 64168755Srrs#endif 65168755Srrs 66170138Srrs#if defined(SCTP_SACK_LOGGING) || defined(SCTP_LOCK_LOGGING) 67168755Srrs#ifndef SCTP_STAT_LOGGING 68168755Srrs#define SCTP_STAT_LOGGING 1 69168755Srrs#endif 70168755Srrs#endif 71168755Srrs 72168757Srrs#if defined(SCTP_RTTVAR_LOGGING) || defined(SCTP_SB_LOGGING) || defined(SCTP_EARLYFR_LOGGING) 73168755Srrs#ifndef SCTP_STAT_LOGGING 74168755Srrs#define SCTP_STAT_LOGGING 1 75168755Srrs#endif 76168755Srrs#endif 77168755Srrs 78168757Srrs#if defined(SCTP_NAGLE_LOGGING) || defined(SCTP_WAKE_LOGGING) || defined(SCTP_RECV_RWND_LOGGING) 79168755Srrs#ifndef SCTP_STAT_LOGGING 80168755Srrs#define SCTP_STAT_LOGGING 1 81168755Srrs#endif 82168755Srrs#endif 83168755Srrs 84168757Srrs#if defined(SCTP_SACK_RWND_LOGGING) || defined(SCTP_FLIGHT_LOGGING) || defined(SCTP_MBUF_LOGGING) 85168755Srrs#ifndef SCTP_STAT_LOGGING 86168755Srrs#define SCTP_STAT_LOGGING 1 87168755Srrs#endif 88168755Srrs#endif 89168755Srrs 90169208Srrs#if defined(SCTP_LOG_SACK_ARRIVALS) 91169208Srrs#ifndef SCTP_STAT_LOGGING 92169208Srrs#define SCTP_STAT_LOGGING 1 93169208Srrs#endif 94169208Srrs#endif 95169208Srrs 96169208Srrs 97168859Srrs#ifdef SCTP_ASOCLOG_OF_TSNS 98168859Srrsvoid sctp_print_out_track_log(struct sctp_tcb *stcb); 99168859Srrs 100168859Srrs#endif 101168859Srrs 102163953Srrs#ifdef SCTP_MBUF_LOGGING 103163953Srrsstruct mbuf *sctp_m_free(struct mbuf *m); 104163953Srrsvoid sctp_m_freem(struct mbuf *m); 105163953Srrs 106163953Srrs#else 107163953Srrs#define sctp_m_free m_free 108163953Srrs#define sctp_m_freem m_freem 109163953Srrs#endif 110163953Srrs 111163953Srrs 112163953Srrs#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id) 113163953Srrs 114163953Srrs 115163953Srrs/* 116163953Srrs * Function prototypes 117163953Srrs */ 118167698Srrsuint32_t 119167698Srrssctp_get_ifa_hash_val(struct sockaddr *addr); 120167698Srrs 121167598Srrsstruct sctp_ifa * 122167598Srrs sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock); 123163953Srrs 124167598Srrsstruct sctp_ifa * 125167598Srrs sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock); 126167598Srrs 127163953Srrsuint32_t sctp_select_initial_TSN(struct sctp_pcb *); 128163953Srrs 129163953Srrsuint32_t sctp_select_a_tag(struct sctp_inpcb *); 130163953Srrs 131170138Srrsint sctp_init_asoc(struct sctp_inpcb *, struct sctp_tcb *, int, uint32_t, uint32_t); 132163953Srrs 133163953Srrsvoid sctp_fill_random_store(struct sctp_pcb *); 134163953Srrs 135169420Srrsvoid 136163953Srrssctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *, 137163953Srrs struct sctp_nets *); 138163953Srrs 139169378Srrsvoid 140163953Srrssctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *, 141165220Srrs struct sctp_nets *, uint32_t); 142163953Srrs 143167598Srrsint 144167598Srrs sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id); 145167598Srrs 146163953Srrsuint32_t sctp_calculate_sum(struct mbuf *, int32_t *, uint32_t); 147163953Srrs 148163953Srrsvoid 149166023Srrs sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t); 150163953Srrs 151163953Srrsvoid 152163953Srrssctp_add_to_readq(struct sctp_inpcb *inp, 153163953Srrs struct sctp_tcb *stcb, 154163953Srrs struct sctp_queued_to_read *control, 155163953Srrs struct sockbuf *sb, 156163953Srrs int end); 157163953Srrs 158163953Srrsint 159163953Srrssctp_append_to_readq(struct sctp_inpcb *inp, 160163953Srrs struct sctp_tcb *stcb, 161163953Srrs struct sctp_queued_to_read *control, 162163953Srrs struct mbuf *m, 163163953Srrs int end, 164163953Srrs int new_cumack, 165163953Srrs struct sockbuf *sb); 166163953Srrs 167163953Srrs 168167598Srrsvoid sctp_iterator_worker(void); 169167598Srrs 170163953Srrsint find_next_best_mtu(int); 171163953Srrs 172163953Srrsvoid 173163953Srrs sctp_timeout_handler(void *); 174163953Srrs 175163953Srrsuint32_t 176163953Srrssctp_calculate_rto(struct sctp_tcb *, struct sctp_association *, 177163953Srrs struct sctp_nets *, struct timeval *); 178163953Srrs 179163953Srrsuint32_t sctp_calculate_len(struct mbuf *); 180163953Srrs 181163953Srrscaddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *); 182163953Srrs 183163953Srrsstruct sctp_paramhdr * 184163953Srrssctp_get_next_param(struct mbuf *, int, 185163953Srrs struct sctp_paramhdr *, int); 186163953Srrs 187163953Srrsint sctp_add_pad_tombuf(struct mbuf *, int); 188163953Srrs 189163953Srrsint sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *); 190163953Srrs 191163953Srrsvoid sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *); 192163953Srrs 193163953Srrsvoid 194163953Srrssctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, 195163953Srrs struct sctp_inpcb *new_inp, 196169208Srrs struct sctp_tcb *stcb, int waitflags); 197163953Srrs 198163953Srrs 199163953Srrsvoid sctp_stop_timers_for_shutdown(struct sctp_tcb *); 200163953Srrs 201164205Srrsvoid sctp_report_all_outbound(struct sctp_tcb *, int); 202163953Srrs 203170138Srrsint sctp_expand_mapping_array(struct sctp_association *, uint32_t); 204163953Srrs 205163953Srrsvoid sctp_abort_notification(struct sctp_tcb *, int); 206163953Srrs 207163953Srrs/* We abort responding to an IP packet for some reason */ 208163953Srrsvoid 209163953Srrssctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, 210170181Srrs struct mbuf *, int, struct sctphdr *, struct mbuf *, uint32_t); 211163953Srrs 212169352Srrs 213163953Srrs/* We choose to abort via user input */ 214163953Srrsvoid 215163953Srrssctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, int, 216163953Srrs struct mbuf *); 217163953Srrs 218169352Srrsvoid 219163953Srrssctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *, 220170181Srrs struct sctp_inpcb *, struct mbuf *, uint32_t); 221163953Srrs 222170056Srrsint 223170056Srrssctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr, 224170056Srrs int totaddr, int *error); 225169352Srrs 226169352Srrsstruct sctp_tcb * 227170056Srrssctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr, 228170056Srrs int *totaddr, int *num_v4, int *num_v6, int *error, int limit, int *bad_addr); 229169352Srrs 230163953Srrsint sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *); 231163953Srrsuint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 232166675Srrs 233163953Srrsstruct sockaddr_in6 * 234166675Srrs sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 235163953Srrs 236163953Srrs#define sctp_recover_scope_mac(addr, store) do { \ 237166675Srrs if ((addr->sin6_family == AF_INET6) && \ 238166675Srrs (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \ 239166675Srrs *store = *addr; \ 240166675Srrs if (addr->sin6_scope_id == 0) { \ 241166675Srrs if (!sa6_recoverscope(store)) { \ 242166675Srrs addr = store; \ 243166675Srrs } \ 244166675Srrs } else { \ 245166675Srrs in6_clearscope(&addr->sin6_addr); \ 246166675Srrs addr = store; \ 247166675Srrs } \ 248166675Srrs } \ 249166675Srrs} while (0) 250163953Srrs 251163953Srrs 252163953Srrsint sctp_cmpaddr(struct sockaddr *, struct sockaddr *); 253163953Srrs 254163953Srrsvoid sctp_print_address(struct sockaddr *); 255163953Srrsvoid sctp_print_address_pkt(struct ip *, struct sctphdr *); 256163953Srrs 257163953Srrsvoid 258163953Srrssctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, 259168943Srrs uint32_t error, int no_lock, uint32_t strseq); 260163953Srrs 261163953Srrsint 262163953Srrssctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, 263163953Srrs int, struct sctpchunk_listhead *); 264163953Srrs 265163953Srrsstruct mbuf *sctp_generate_invmanparam(int); 266163953Srrs 267163953Srrs 268163953Srrs#ifdef SCTP_MBCNT_LOGGING 269163953Srrsvoid 270163953Srrssctp_free_bufspace(struct sctp_tcb *, struct sctp_association *, 271163953Srrs struct sctp_tmit_chunk *); 272163953Srrs 273163953Srrs#else 274163953Srrs#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \ 275163953Srrsdo { \ 276163953Srrs if (tp1->data != NULL) { \ 277169420Srrs atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \ 278163953Srrs if ((asoc)->total_output_queue_size >= tp1->book_size) { \ 279169420Srrs atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \ 280163953Srrs } else { \ 281163953Srrs (asoc)->total_output_queue_size = 0; \ 282163953Srrs } \ 283163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 284163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 285163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \ 286169420Srrs atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \ 287163953Srrs } else { \ 288163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 289163953Srrs } \ 290163953Srrs } \ 291163953Srrs } \ 292163953Srrs} while (0) 293163953Srrs 294163953Srrs#endif 295163953Srrs 296163953Srrs#define sctp_free_spbufspace(stcb, asoc, sp) \ 297163953Srrsdo { \ 298163953Srrs if (sp->data != NULL) { \ 299169420Srrs atomic_subtract_int(&(asoc)->chunks_on_out_queue, 1); \ 300163953Srrs if ((asoc)->total_output_queue_size >= sp->length) { \ 301169420Srrs atomic_subtract_int(&(asoc)->total_output_queue_size, sp->length); \ 302163953Srrs } else { \ 303163953Srrs (asoc)->total_output_queue_size = 0; \ 304163953Srrs } \ 305163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 306163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 307163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \ 308169420Srrs atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \ 309163953Srrs } else { \ 310163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 311163953Srrs } \ 312163953Srrs } \ 313163953Srrs } \ 314163953Srrs} while (0) 315163953Srrs 316163953Srrs#define sctp_snd_sb_alloc(stcb, sz) \ 317163953Srrsdo { \ 318163953Srrs atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \ 319163953Srrs if ((stcb->sctp_socket != NULL) && \ 320163953Srrs ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 321163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 322163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \ 323163953Srrs } \ 324163953Srrs} while (0) 325163953Srrs 326163953Srrs 327163953Srrsint 328163953Srrssctp_soreceive(struct socket *so, struct sockaddr **psa, 329163953Srrs struct uio *uio, 330163953Srrs struct mbuf **mp0, 331163953Srrs struct mbuf **controlp, 332163953Srrs int *flagsp); 333163953Srrs 334163953Srrs 335169352Srrs/* For those not passing mbufs, this does the 336169352Srrs * translations for you. Caller owns memory 337169352Srrs * of size controllen returned in controlp. 338169352Srrs */ 339169352Srrsint 340169352Srrssctp_l_soreceive(struct socket *so, 341169352Srrs struct sockaddr **name, 342169352Srrs struct uio *uio, 343169352Srrs char **controlp, 344169352Srrs int *controllen, 345169352Srrs int *flag); 346169352Srrs 347169352Srrs 348163953Srrs#ifdef SCTP_STAT_LOGGING 349163953Srrsvoid 350163953Srrs sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d); 351163953Srrs 352163953Srrsvoid 353163953Srrssctp_wakeup_log(struct sctp_tcb *stcb, 354163953Srrs uint32_t cumtsn, 355163953Srrs uint32_t wake_cnt, int from); 356163953Srrs 357164181Srrsvoid sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int); 358163953Srrs 359163953Srrsvoid sctp_log_nagle_event(struct sctp_tcb *stcb, int action); 360163953Srrs 361163953Srrs 362163953Srrsvoid 363163953Srrs sctp_log_mb(struct mbuf *m, int from); 364163953Srrs 365163953Srrsvoid 366163953Srrssctp_sblog(struct sockbuf *sb, 367163953Srrs struct sctp_tcb *stcb, int from, int incr); 368163953Srrs 369163953Srrsvoid 370163953Srrssctp_log_strm_del(struct sctp_queued_to_read *control, 371163953Srrs struct sctp_queued_to_read *poschk, 372163953Srrs int from); 373163953Srrsvoid sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t); 374163953Srrsvoid rto_logging(struct sctp_nets *net, int from); 375163953Srrs 376163953Srrsvoid sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc); 377163953Srrs 378163953Srrsvoid sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from); 379163953Srrsvoid sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t); 380163953Srrsvoid sctp_log_block(uint8_t, struct socket *, struct sctp_association *, int); 381163953Srrsvoid sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t); 382163953Srrsvoid sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 383163953Srrsvoid sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 384167598Srrsint sctp_fill_stat_log(void *, size_t *); 385163953Srrsvoid sctp_log_fr(uint32_t, uint32_t, uint32_t, int); 386163953Srrsvoid sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int); 387163953Srrsvoid sctp_log_map(uint32_t, uint32_t, uint32_t, int); 388163953Srrs 389163953Srrsvoid sctp_clr_stat_log(void); 390163953Srrs 391163953Srrs#endif 392163953Srrs 393163953Srrs#ifdef SCTP_AUDITING_ENABLED 394163953Srrsvoid 395163953Srrssctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *, 396163953Srrs struct sctp_nets *); 397163953Srrsvoid sctp_audit_log(uint8_t, uint8_t); 398163953Srrs 399163953Srrs#endif 400163953Srrs 401163953Srrs 402163953Srrs#endif /* _KERNEL */ 403163953Srrs#endif 404