sctputil.h revision 168943
1163953Srrs/*- 2166086Srrs * Copyright (c) 2001-2007, 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 168943 2007-04-22 11:06:27Z 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 */ 47168757Srrs#if defined(SCTP_LOG_MAXBURST) || defined(SCTP_LOG_RWND) || defined(SCTP_LOG_RWND) 48168755Srrs#ifndef SCTP_STAT_LOGGING 49168755Srrs#define SCTP_STAT_LOGGING 1 50168755Srrs#endif 51168755Srrs#endif 52168755Srrs 53168757Srrs#if defined(SCTP_CWND_LOGGING) || defined(SCTP_CWND_MONITOR) || defined(SCTP_BLK_LOGGING) 54168755Srrs#ifndef SCTP_STAT_LOGGING 55168755Srrs#define SCTP_STAT_LOGGING 1 56168755Srrs#endif 57168755Srrs#endif 58168755Srrs 59168757Srrs#if defined(SCTP_STR_LOGGING) || defined(SCTP_FR_LOGGING) || defined(SCTP_MAP_LOGGING) 60168755Srrs#ifndef SCTP_STAT_LOGGING 61168755Srrs#define SCTP_STAT_LOGGING 1 62168755Srrs#endif 63168755Srrs#endif 64168755Srrs 65168757Srrs#if defined(SCTP_SACK_LOGGING) || defined(SCTP_LOCK_LOGGING) || defined(SCTP_STAT_LOGGING) 66168755Srrs#ifndef SCTP_STAT_LOGGING 67168755Srrs#define SCTP_STAT_LOGGING 1 68168755Srrs#endif 69168755Srrs#endif 70168755Srrs 71168757Srrs#if defined(SCTP_RTTVAR_LOGGING) || defined(SCTP_SB_LOGGING) || defined(SCTP_EARLYFR_LOGGING) 72168755Srrs#ifndef SCTP_STAT_LOGGING 73168755Srrs#define SCTP_STAT_LOGGING 1 74168755Srrs#endif 75168755Srrs#endif 76168755Srrs 77168757Srrs#if defined(SCTP_NAGLE_LOGGING) || defined(SCTP_WAKE_LOGGING) || defined(SCTP_RECV_RWND_LOGGING) 78168755Srrs#ifndef SCTP_STAT_LOGGING 79168755Srrs#define SCTP_STAT_LOGGING 1 80168755Srrs#endif 81168755Srrs#endif 82168755Srrs 83168757Srrs#if defined(SCTP_SACK_RWND_LOGGING) || defined(SCTP_FLIGHT_LOGGING) || defined(SCTP_MBUF_LOGGING) 84168755Srrs#ifndef SCTP_STAT_LOGGING 85168755Srrs#define SCTP_STAT_LOGGING 1 86168755Srrs#endif 87168755Srrs#endif 88168755Srrs 89168859Srrs#ifdef SCTP_ASOCLOG_OF_TSNS 90168859Srrsvoid sctp_print_out_track_log(struct sctp_tcb *stcb); 91168859Srrs 92168859Srrs#endif 93168859Srrs 94163953Srrs#ifdef SCTP_MBUF_LOGGING 95163953Srrsstruct mbuf *sctp_m_free(struct mbuf *m); 96163953Srrsvoid sctp_m_freem(struct mbuf *m); 97163953Srrs 98163953Srrs#else 99163953Srrs#define sctp_m_free m_free 100163953Srrs#define sctp_m_freem m_freem 101163953Srrs#endif 102163953Srrs 103163953Srrs 104163953Srrs#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id) 105163953Srrs 106163953Srrs 107163953Srrs/* 108163953Srrs * Function prototypes 109163953Srrs */ 110167698Srrsuint32_t 111167698Srrssctp_get_ifa_hash_val(struct sockaddr *addr); 112167698Srrs 113167598Srrsstruct sctp_ifa * 114167598Srrs sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock); 115167598Srrsstruct sctp_ifa * 116167598Srrssctp_find_ifa_in_ifn(struct sctp_ifn *sctp_ifnp, struct sockaddr *addr, 117167598Srrs int holds_lock); 118163953Srrs 119167598Srrsstruct sctp_ifa * 120167598Srrs sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock); 121167598Srrs 122163953Srrsuint32_t sctp_select_initial_TSN(struct sctp_pcb *); 123163953Srrs 124163953Srrsuint32_t sctp_select_a_tag(struct sctp_inpcb *); 125163953Srrs 126167598Srrsint sctp_init_asoc(struct sctp_inpcb *, struct sctp_association *, int, uint32_t, uint32_t); 127163953Srrs 128163953Srrsvoid sctp_fill_random_store(struct sctp_pcb *); 129163953Srrs 130163953Srrsint 131163953Srrssctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *, 132163953Srrs struct sctp_nets *); 133163953Srrs 134163953Srrsint 135163953Srrssctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *, 136165220Srrs struct sctp_nets *, uint32_t); 137163953Srrs 138167598Srrsint 139167598Srrs sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id); 140167598Srrs 141163953Srrsuint32_t sctp_calculate_sum(struct mbuf *, int32_t *, uint32_t); 142163953Srrs 143163953Srrsvoid 144166023Srrs sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t); 145163953Srrs 146163953Srrsvoid 147163953Srrssctp_add_to_readq(struct sctp_inpcb *inp, 148163953Srrs struct sctp_tcb *stcb, 149163953Srrs struct sctp_queued_to_read *control, 150163953Srrs struct sockbuf *sb, 151163953Srrs int end); 152163953Srrs 153163953Srrsint 154163953Srrssctp_append_to_readq(struct sctp_inpcb *inp, 155163953Srrs struct sctp_tcb *stcb, 156163953Srrs struct sctp_queued_to_read *control, 157163953Srrs struct mbuf *m, 158163953Srrs int end, 159163953Srrs int new_cumack, 160163953Srrs struct sockbuf *sb); 161163953Srrs 162163953Srrs 163167598Srrsvoid sctp_iterator_worker(void); 164167598Srrs 165163953Srrsint find_next_best_mtu(int); 166163953Srrs 167163953Srrsvoid 168163953Srrs sctp_timeout_handler(void *); 169163953Srrs 170163953Srrsuint32_t 171163953Srrssctp_calculate_rto(struct sctp_tcb *, struct sctp_association *, 172163953Srrs struct sctp_nets *, struct timeval *); 173163953Srrs 174163953Srrsuint32_t sctp_calculate_len(struct mbuf *); 175163953Srrs 176163953Srrscaddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *); 177163953Srrs 178163953Srrsstruct sctp_paramhdr * 179163953Srrssctp_get_next_param(struct mbuf *, int, 180163953Srrs struct sctp_paramhdr *, int); 181163953Srrs 182163953Srrsint sctp_add_pad_tombuf(struct mbuf *, int); 183163953Srrs 184163953Srrsint sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *); 185163953Srrs 186163953Srrsvoid sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *); 187163953Srrs 188163953Srrsvoid 189163953Srrssctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, 190163953Srrs struct sctp_inpcb *new_inp, 191163953Srrs struct sctp_tcb *stcb); 192163953Srrs 193163953Srrs 194163953Srrsvoid sctp_stop_timers_for_shutdown(struct sctp_tcb *); 195163953Srrs 196164205Srrsvoid sctp_report_all_outbound(struct sctp_tcb *, int); 197163953Srrs 198163953Srrsint sctp_expand_mapping_array(struct sctp_association *); 199163953Srrs 200163953Srrsvoid sctp_abort_notification(struct sctp_tcb *, int); 201163953Srrs 202163953Srrs/* We abort responding to an IP packet for some reason */ 203163953Srrsvoid 204163953Srrssctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, 205163953Srrs struct mbuf *, int, struct sctphdr *, struct mbuf *); 206163953Srrs 207163953Srrs/* We choose to abort via user input */ 208163953Srrsvoid 209163953Srrssctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, int, 210163953Srrs struct mbuf *); 211163953Srrs 212163953Srrsvoid 213163953Srrssctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *, 214163953Srrs struct sctp_inpcb *, struct mbuf *); 215163953Srrs 216163953Srrsint sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *); 217163953Srrsuint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 218166675Srrs 219163953Srrsstruct sockaddr_in6 * 220166675Srrs sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 221163953Srrs 222163953Srrs#define sctp_recover_scope_mac(addr, store) do { \ 223166675Srrs if ((addr->sin6_family == AF_INET6) && \ 224166675Srrs (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \ 225166675Srrs *store = *addr; \ 226166675Srrs if (addr->sin6_scope_id == 0) { \ 227166675Srrs if (!sa6_recoverscope(store)) { \ 228166675Srrs addr = store; \ 229166675Srrs } \ 230166675Srrs } else { \ 231166675Srrs in6_clearscope(&addr->sin6_addr); \ 232166675Srrs addr = store; \ 233166675Srrs } \ 234166675Srrs } \ 235166675Srrs} while (0) 236163953Srrs 237163953Srrs 238163953Srrsint sctp_cmpaddr(struct sockaddr *, struct sockaddr *); 239163953Srrs 240163953Srrsvoid sctp_print_address(struct sockaddr *); 241163953Srrsvoid sctp_print_address_pkt(struct ip *, struct sctphdr *); 242163953Srrs 243163953Srrsvoid 244163953Srrssctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, 245168943Srrs uint32_t error, int no_lock, uint32_t strseq); 246163953Srrs 247163953Srrsint 248163953Srrssctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, 249163953Srrs int, struct sctpchunk_listhead *); 250163953Srrs 251163953Srrsstruct mbuf *sctp_generate_invmanparam(int); 252163953Srrs 253163953Srrs 254163953Srrs#ifdef SCTP_MBCNT_LOGGING 255163953Srrsvoid 256163953Srrssctp_free_bufspace(struct sctp_tcb *, struct sctp_association *, 257163953Srrs struct sctp_tmit_chunk *); 258163953Srrs 259163953Srrs#else 260163953Srrs#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \ 261163953Srrsdo { \ 262163953Srrs if (tp1->data != NULL) { \ 263163996Srrs atomic_add_int(&((asoc)->chunks_on_out_queue), -chk_cnt); \ 264163953Srrs if ((asoc)->total_output_queue_size >= tp1->book_size) { \ 265163953Srrs atomic_add_int(&((asoc)->total_output_queue_size), -tp1->book_size); \ 266163953Srrs } else { \ 267163953Srrs (asoc)->total_output_queue_size = 0; \ 268163953Srrs } \ 269163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 270163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 271163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \ 272163953Srrs atomic_add_int(&((stcb)->sctp_socket->so_snd.sb_cc), -tp1->book_size); \ 273163953Srrs } else { \ 274163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 275163953Srrs } \ 276163953Srrs } \ 277163953Srrs } \ 278163953Srrs} while (0) 279163953Srrs 280163953Srrs#endif 281163953Srrs 282163953Srrs#define sctp_free_spbufspace(stcb, asoc, sp) \ 283163953Srrsdo { \ 284163953Srrs if (sp->data != NULL) { \ 285163996Srrs atomic_add_int(&(asoc)->chunks_on_out_queue, -1); \ 286163953Srrs if ((asoc)->total_output_queue_size >= sp->length) { \ 287163953Srrs atomic_add_int(&(asoc)->total_output_queue_size,sp->length); \ 288163953Srrs } else { \ 289163953Srrs (asoc)->total_output_queue_size = 0; \ 290163953Srrs } \ 291163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 292163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 293163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \ 294163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \ 295163953Srrs } else { \ 296163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 297163953Srrs } \ 298163953Srrs } \ 299163953Srrs } \ 300163953Srrs} while (0) 301163953Srrs 302163953Srrs#define sctp_snd_sb_alloc(stcb, sz) \ 303163953Srrsdo { \ 304163953Srrs atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \ 305163953Srrs if ((stcb->sctp_socket != NULL) && \ 306163953Srrs ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 307163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 308163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \ 309163953Srrs } \ 310163953Srrs} while (0) 311163953Srrs 312163953Srrs 313163953Srrsint 314163953Srrssctp_soreceive(struct socket *so, struct sockaddr **psa, 315163953Srrs struct uio *uio, 316163953Srrs struct mbuf **mp0, 317163953Srrs struct mbuf **controlp, 318163953Srrs int *flagsp); 319163953Srrs 320163953Srrs 321163953Srrs#ifdef SCTP_STAT_LOGGING 322163953Srrsvoid 323163953Srrs sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d); 324163953Srrs 325163953Srrsvoid 326163953Srrssctp_wakeup_log(struct sctp_tcb *stcb, 327163953Srrs uint32_t cumtsn, 328163953Srrs uint32_t wake_cnt, int from); 329163953Srrs 330164181Srrsvoid sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int); 331163953Srrs 332163953Srrsvoid sctp_log_nagle_event(struct sctp_tcb *stcb, int action); 333163953Srrs 334163953Srrs 335163953Srrsvoid 336163953Srrs sctp_log_mb(struct mbuf *m, int from); 337163953Srrs 338163953Srrsvoid 339163953Srrssctp_sblog(struct sockbuf *sb, 340163953Srrs struct sctp_tcb *stcb, int from, int incr); 341163953Srrs 342163953Srrsvoid 343163953Srrssctp_log_strm_del(struct sctp_queued_to_read *control, 344163953Srrs struct sctp_queued_to_read *poschk, 345163953Srrs int from); 346163953Srrsvoid sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t); 347163953Srrsvoid rto_logging(struct sctp_nets *net, int from); 348163953Srrs 349163953Srrsvoid sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc); 350163953Srrs 351163953Srrsvoid sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from); 352163953Srrsvoid sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t); 353163953Srrsvoid sctp_log_block(uint8_t, struct socket *, struct sctp_association *, int); 354163953Srrsvoid sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t); 355163953Srrsvoid sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 356163953Srrsvoid sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 357167598Srrsint sctp_fill_stat_log(void *, size_t *); 358163953Srrsvoid sctp_log_fr(uint32_t, uint32_t, uint32_t, int); 359163953Srrsvoid sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int); 360163953Srrsvoid sctp_log_map(uint32_t, uint32_t, uint32_t, int); 361163953Srrs 362163953Srrsvoid sctp_clr_stat_log(void); 363163953Srrs 364163953Srrs#endif 365163953Srrs 366163953Srrs#ifdef SCTP_AUDITING_ENABLED 367163953Srrsvoid 368163953Srrssctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *, 369163953Srrs struct sctp_nets *); 370163953Srrsvoid sctp_audit_log(uint8_t, uint8_t); 371163953Srrs 372163953Srrs#endif 373163953Srrs 374163953Srrs 375163953Srrs#endif /* _KERNEL */ 376163953Srrs#endif 377