sctputil.h revision 171477
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 171477 2007-07-17 20:58:26Z 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 57163953Srrs 58163953Srrs#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id) 59163953Srrs 60163953Srrs 61163953Srrs/* 62163953Srrs * Function prototypes 63163953Srrs */ 64167698Srrsuint32_t 65167698Srrssctp_get_ifa_hash_val(struct sockaddr *addr); 66167698Srrs 67167598Srrsstruct sctp_ifa * 68167598Srrs sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock); 69163953Srrs 70167598Srrsstruct sctp_ifa * 71167598Srrs sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock); 72167598Srrs 73163953Srrsuint32_t sctp_select_initial_TSN(struct sctp_pcb *); 74163953Srrs 75163953Srrsuint32_t sctp_select_a_tag(struct sctp_inpcb *); 76163953Srrs 77170138Srrsint sctp_init_asoc(struct sctp_inpcb *, struct sctp_tcb *, int, uint32_t, uint32_t); 78163953Srrs 79163953Srrsvoid sctp_fill_random_store(struct sctp_pcb *); 80163953Srrs 81169420Srrsvoid 82163953Srrssctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *, 83163953Srrs struct sctp_nets *); 84163953Srrs 85169378Srrsvoid 86163953Srrssctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *, 87165220Srrs struct sctp_nets *, uint32_t); 88163953Srrs 89167598Srrsint 90167598Srrs sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id); 91167598Srrs 92163953Srrsuint32_t sctp_calculate_sum(struct mbuf *, int32_t *, uint32_t); 93163953Srrs 94163953Srrsvoid 95166023Srrs sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t); 96163953Srrs 97163953Srrsvoid 98163953Srrssctp_add_to_readq(struct sctp_inpcb *inp, 99163953Srrs struct sctp_tcb *stcb, 100163953Srrs struct sctp_queued_to_read *control, 101163953Srrs struct sockbuf *sb, 102163953Srrs int end); 103163953Srrs 104163953Srrsint 105163953Srrssctp_append_to_readq(struct sctp_inpcb *inp, 106163953Srrs struct sctp_tcb *stcb, 107163953Srrs struct sctp_queued_to_read *control, 108163953Srrs struct mbuf *m, 109163953Srrs int end, 110163953Srrs int new_cumack, 111163953Srrs struct sockbuf *sb); 112163953Srrs 113163953Srrs 114167598Srrsvoid sctp_iterator_worker(void); 115167598Srrs 116163953Srrsint find_next_best_mtu(int); 117163953Srrs 118163953Srrsvoid 119163953Srrs sctp_timeout_handler(void *); 120163953Srrs 121163953Srrsuint32_t 122163953Srrssctp_calculate_rto(struct sctp_tcb *, struct sctp_association *, 123171477Srrs struct sctp_nets *, struct timeval *, int); 124163953Srrs 125163953Srrsuint32_t sctp_calculate_len(struct mbuf *); 126163953Srrs 127163953Srrscaddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *); 128163953Srrs 129163953Srrsstruct sctp_paramhdr * 130163953Srrssctp_get_next_param(struct mbuf *, int, 131163953Srrs struct sctp_paramhdr *, int); 132163953Srrs 133163953Srrsint sctp_add_pad_tombuf(struct mbuf *, int); 134163953Srrs 135163953Srrsint sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *); 136163953Srrs 137163953Srrsvoid sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *); 138163953Srrs 139163953Srrsvoid 140163953Srrssctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, 141163953Srrs struct sctp_inpcb *new_inp, 142169208Srrs struct sctp_tcb *stcb, int waitflags); 143163953Srrs 144163953Srrs 145163953Srrsvoid sctp_stop_timers_for_shutdown(struct sctp_tcb *); 146163953Srrs 147164205Srrsvoid sctp_report_all_outbound(struct sctp_tcb *, int); 148163953Srrs 149170138Srrsint sctp_expand_mapping_array(struct sctp_association *, uint32_t); 150163953Srrs 151163953Srrsvoid sctp_abort_notification(struct sctp_tcb *, int); 152163953Srrs 153163953Srrs/* We abort responding to an IP packet for some reason */ 154163953Srrsvoid 155163953Srrssctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, 156170181Srrs struct mbuf *, int, struct sctphdr *, struct mbuf *, uint32_t); 157163953Srrs 158169352Srrs 159163953Srrs/* We choose to abort via user input */ 160163953Srrsvoid 161163953Srrssctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, int, 162163953Srrs struct mbuf *); 163163953Srrs 164169352Srrsvoid 165163953Srrssctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *, 166170181Srrs struct sctp_inpcb *, struct mbuf *, uint32_t); 167163953Srrs 168170056Srrsint 169170056Srrssctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr, 170170056Srrs int totaddr, int *error); 171169352Srrs 172169352Srrsstruct sctp_tcb * 173170056Srrssctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr, 174170056Srrs int *totaddr, int *num_v4, int *num_v6, int *error, int limit, int *bad_addr); 175169352Srrs 176163953Srrsint sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *); 177163953Srrsuint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 178166675Srrs 179163953Srrsstruct sockaddr_in6 * 180166675Srrs sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 181163953Srrs 182163953Srrs#define sctp_recover_scope_mac(addr, store) do { \ 183166675Srrs if ((addr->sin6_family == AF_INET6) && \ 184166675Srrs (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \ 185166675Srrs *store = *addr; \ 186166675Srrs if (addr->sin6_scope_id == 0) { \ 187166675Srrs if (!sa6_recoverscope(store)) { \ 188166675Srrs addr = store; \ 189166675Srrs } \ 190166675Srrs } else { \ 191166675Srrs in6_clearscope(&addr->sin6_addr); \ 192166675Srrs addr = store; \ 193166675Srrs } \ 194166675Srrs } \ 195166675Srrs} while (0) 196163953Srrs 197163953Srrs 198163953Srrsint sctp_cmpaddr(struct sockaddr *, struct sockaddr *); 199163953Srrs 200163953Srrsvoid sctp_print_address(struct sockaddr *); 201163953Srrsvoid sctp_print_address_pkt(struct ip *, struct sctphdr *); 202163953Srrs 203163953Srrsvoid 204163953Srrssctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, 205168943Srrs uint32_t error, int no_lock, uint32_t strseq); 206163953Srrs 207163953Srrsint 208163953Srrssctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, 209163953Srrs int, struct sctpchunk_listhead *); 210163953Srrs 211163953Srrsstruct mbuf *sctp_generate_invmanparam(int); 212163953Srrs 213170606Srrsvoid 214170606Srrssctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp, 215170606Srrs struct sockaddr *sa, sctp_assoc_t assoc_id, 216170606Srrs uint32_t vrf_id, int *error, void *p); 217170606Srrsvoid 218170606Srrssctp_bindx_delete_address(struct socket *so, struct sctp_inpcb *inp, 219170606Srrs struct sockaddr *sa, sctp_assoc_t assoc_id, 220170606Srrs uint32_t vrf_id, int *error); 221163953Srrs 222163953Srrs#ifdef SCTP_MBCNT_LOGGING 223163953Srrsvoid 224163953Srrssctp_free_bufspace(struct sctp_tcb *, struct sctp_association *, 225170744Srrs struct sctp_tmit_chunk *, int); 226163953Srrs 227163953Srrs#else 228163953Srrs#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \ 229163953Srrsdo { \ 230163953Srrs if (tp1->data != NULL) { \ 231169420Srrs atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \ 232163953Srrs if ((asoc)->total_output_queue_size >= tp1->book_size) { \ 233169420Srrs atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \ 234163953Srrs } else { \ 235163953Srrs (asoc)->total_output_queue_size = 0; \ 236163953Srrs } \ 237163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 238163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 239163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \ 240169420Srrs atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \ 241163953Srrs } else { \ 242163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 243163953Srrs } \ 244163953Srrs } \ 245163953Srrs } \ 246163953Srrs} while (0) 247163953Srrs 248163953Srrs#endif 249163953Srrs 250163953Srrs#define sctp_free_spbufspace(stcb, asoc, sp) \ 251163953Srrsdo { \ 252163953Srrs if (sp->data != NULL) { \ 253169420Srrs atomic_subtract_int(&(asoc)->chunks_on_out_queue, 1); \ 254163953Srrs if ((asoc)->total_output_queue_size >= sp->length) { \ 255169420Srrs atomic_subtract_int(&(asoc)->total_output_queue_size, sp->length); \ 256163953Srrs } else { \ 257163953Srrs (asoc)->total_output_queue_size = 0; \ 258163953Srrs } \ 259163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 260163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 261163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \ 262169420Srrs atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \ 263163953Srrs } else { \ 264163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 265163953Srrs } \ 266163953Srrs } \ 267163953Srrs } \ 268163953Srrs} while (0) 269163953Srrs 270163953Srrs#define sctp_snd_sb_alloc(stcb, sz) \ 271163953Srrsdo { \ 272163953Srrs atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \ 273163953Srrs if ((stcb->sctp_socket != NULL) && \ 274163953Srrs ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 275163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 276163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \ 277163953Srrs } \ 278163953Srrs} while (0) 279163953Srrs 280163953Srrs 281163953Srrsint 282163953Srrssctp_soreceive(struct socket *so, struct sockaddr **psa, 283163953Srrs struct uio *uio, 284163953Srrs struct mbuf **mp0, 285163953Srrs struct mbuf **controlp, 286163953Srrs int *flagsp); 287163953Srrs 288163953Srrs 289169352Srrs/* For those not passing mbufs, this does the 290169352Srrs * translations for you. Caller owns memory 291169352Srrs * of size controllen returned in controlp. 292169352Srrs */ 293169352Srrsint 294169352Srrssctp_l_soreceive(struct socket *so, 295169352Srrs struct sockaddr **name, 296169352Srrs struct uio *uio, 297169352Srrs char **controlp, 298169352Srrs int *controllen, 299169352Srrs int *flag); 300169352Srrs 301169352Srrs 302163953Srrsvoid 303163953Srrs sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d); 304163953Srrs 305163953Srrsvoid 306163953Srrssctp_wakeup_log(struct sctp_tcb *stcb, 307163953Srrs uint32_t cumtsn, 308163953Srrs uint32_t wake_cnt, int from); 309163953Srrs 310164181Srrsvoid sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int); 311163953Srrs 312163953Srrsvoid sctp_log_nagle_event(struct sctp_tcb *stcb, int action); 313163953Srrs 314163953Srrs 315163953Srrsvoid 316163953Srrs sctp_log_mb(struct mbuf *m, int from); 317163953Srrs 318163953Srrsvoid 319163953Srrssctp_sblog(struct sockbuf *sb, 320163953Srrs struct sctp_tcb *stcb, int from, int incr); 321163953Srrs 322163953Srrsvoid 323163953Srrssctp_log_strm_del(struct sctp_queued_to_read *control, 324163953Srrs struct sctp_queued_to_read *poschk, 325163953Srrs int from); 326163953Srrsvoid sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t); 327163953Srrsvoid rto_logging(struct sctp_nets *net, int from); 328163953Srrs 329163953Srrsvoid sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc); 330163953Srrs 331163953Srrsvoid sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from); 332163953Srrsvoid sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t); 333163953Srrsvoid sctp_log_block(uint8_t, struct socket *, struct sctp_association *, int); 334163953Srrsvoid sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t); 335163953Srrsvoid sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 336163953Srrsvoid sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 337167598Srrsint sctp_fill_stat_log(void *, size_t *); 338163953Srrsvoid sctp_log_fr(uint32_t, uint32_t, uint32_t, int); 339163953Srrsvoid sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int); 340163953Srrsvoid sctp_log_map(uint32_t, uint32_t, uint32_t, int); 341163953Srrs 342163953Srrsvoid sctp_clr_stat_log(void); 343163953Srrs 344163953Srrs 345163953Srrs#ifdef SCTP_AUDITING_ENABLED 346163953Srrsvoid 347163953Srrssctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *, 348163953Srrs struct sctp_nets *); 349163953Srrsvoid sctp_audit_log(uint8_t, uint8_t); 350163953Srrs 351163953Srrs#endif 352163953Srrs 353163953Srrs 354163953Srrs#endif /* _KERNEL */ 355163953Srrs#endif 356