sctputil.h revision 166086
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 166086 2007-01-18 09:58:43Z rrs $"); 36163953Srrs#ifndef __sctputil_h__ 37163953Srrs#define __sctputil_h__ 38163953Srrs 39163953Srrs 40163953Srrs#if defined(_KERNEL) 41163953Srrs 42163953Srrs#ifdef SCTP_MBUF_LOGGING 43163953Srrs 44163953Srrsstruct mbuf *sctp_m_free(struct mbuf *m); 45163953Srrsvoid sctp_m_freem(struct mbuf *m); 46163953Srrs 47163953Srrs#else 48163953Srrs#define sctp_m_free m_free 49163953Srrs#define sctp_m_freem m_freem 50163953Srrs#endif 51163953Srrs 52163953Srrs 53163953Srrs#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id) 54163953Srrs 55163953Srrs 56163953Srrs/* 57163953Srrs * Function prototypes 58163953Srrs */ 59163953Srrsstruct ifaddr *sctp_find_ifa_by_addr(struct sockaddr *sa); 60163953Srrs 61163953Srrsuint32_t sctp_select_initial_TSN(struct sctp_pcb *); 62163953Srrs 63163953Srrsuint32_t sctp_select_a_tag(struct sctp_inpcb *); 64163953Srrs 65163953Srrsint sctp_init_asoc(struct sctp_inpcb *, struct sctp_association *, int, uint32_t); 66163953Srrs 67163953Srrsvoid sctp_fill_random_store(struct sctp_pcb *); 68163953Srrs 69163953Srrsint 70163953Srrssctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *, 71163953Srrs struct sctp_nets *); 72163953Srrs 73163953Srrsint 74163953Srrssctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *, 75165220Srrs struct sctp_nets *, uint32_t); 76163953Srrs 77163953Srrsuint32_t sctp_calculate_sum(struct mbuf *, int32_t *, uint32_t); 78163953Srrs 79163953Srrsvoid 80166023Srrs sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t); 81163953Srrs 82163953Srrsvoid 83163953Srrssctp_add_to_readq(struct sctp_inpcb *inp, 84163953Srrs struct sctp_tcb *stcb, 85163953Srrs struct sctp_queued_to_read *control, 86163953Srrs struct sockbuf *sb, 87163953Srrs int end); 88163953Srrs 89163953Srrsint 90163953Srrssctp_append_to_readq(struct sctp_inpcb *inp, 91163953Srrs struct sctp_tcb *stcb, 92163953Srrs struct sctp_queued_to_read *control, 93163953Srrs struct mbuf *m, 94163953Srrs int end, 95163953Srrs int new_cumack, 96163953Srrs struct sockbuf *sb); 97163953Srrs 98163953Srrs 99163953Srrsint find_next_best_mtu(int); 100163953Srrs 101163953Srrsvoid 102163953Srrs sctp_timeout_handler(void *); 103163953Srrs 104163953Srrsuint32_t 105163953Srrssctp_calculate_rto(struct sctp_tcb *, struct sctp_association *, 106163953Srrs struct sctp_nets *, struct timeval *); 107163953Srrs 108163953Srrsuint32_t sctp_calculate_len(struct mbuf *); 109163953Srrs 110163953Srrscaddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *); 111163953Srrs 112163953Srrsstruct sctp_paramhdr * 113163953Srrssctp_get_next_param(struct mbuf *, int, 114163953Srrs struct sctp_paramhdr *, int); 115163953Srrs 116163953Srrsint sctp_add_pad_tombuf(struct mbuf *, int); 117163953Srrs 118163953Srrsint sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *); 119163953Srrs 120163953Srrsvoid sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *); 121163953Srrs 122163953Srrsvoid 123163953Srrssctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, 124163953Srrs struct sctp_inpcb *new_inp, 125163953Srrs struct sctp_tcb *stcb); 126163953Srrs 127163953Srrs 128163953Srrsvoid sctp_stop_timers_for_shutdown(struct sctp_tcb *); 129163953Srrs 130164205Srrsvoid sctp_report_all_outbound(struct sctp_tcb *, int); 131163953Srrs 132163953Srrsint sctp_expand_mapping_array(struct sctp_association *); 133163953Srrs 134163953Srrsvoid sctp_abort_notification(struct sctp_tcb *, int); 135163953Srrs 136163953Srrs/* We abort responding to an IP packet for some reason */ 137163953Srrsvoid 138163953Srrssctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, 139163953Srrs struct mbuf *, int, struct sctphdr *, struct mbuf *); 140163953Srrs 141163953Srrs/* We choose to abort via user input */ 142163953Srrsvoid 143163953Srrssctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, int, 144163953Srrs struct mbuf *); 145163953Srrs 146163953Srrsvoid 147163953Srrssctp_handle_ootb(struct mbuf *, int, int, struct sctphdr *, 148163953Srrs struct sctp_inpcb *, struct mbuf *); 149163953Srrs 150163953Srrsint sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *); 151163953Srrsuint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *); 152163953Srrsstruct sockaddr_in6 * 153163953Srrssctp_recover_scope(struct sockaddr_in6 *, 154163953Srrs struct sockaddr_in6 *); 155163953Srrs 156163953Srrs 157163953Srrs 158163953Srrs 159163953Srrs#define sctp_recover_scope_mac(addr, store) do { \ 160163953Srrs if ((addr->sin6_family == AF_INET6) && \ 161163953Srrs (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr)) && \ 162163953Srrs (addr->sin6_scope_id == 0)) { \ 163163953Srrs *store = *addr; \ 164163953Srrs if (!sa6_recoverscope(store)) { \ 165163953Srrs addr = store; \ 166163953Srrs } \ 167163953Srrs } \ 168163953Srrs } while (0) 169163953Srrs 170163953Srrs 171163953Srrs 172163953Srrsint sctp_cmpaddr(struct sockaddr *, struct sockaddr *); 173163953Srrs 174163953Srrsvoid sctp_print_address(struct sockaddr *); 175163953Srrsvoid sctp_print_address_pkt(struct ip *, struct sctphdr *); 176163953Srrs 177163953Srrsvoid 178163953Srrssctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, 179163953Srrs uint32_t error, int no_lock); 180163953Srrs 181163953Srrsint 182163953Srrssctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, 183163953Srrs int, struct sctpchunk_listhead *); 184163953Srrs 185163953Srrsstruct mbuf *sctp_generate_invmanparam(int); 186163953Srrs 187163953Srrs 188163953Srrs#ifdef SCTP_MBCNT_LOGGING 189163953Srrsvoid 190163953Srrssctp_free_bufspace(struct sctp_tcb *, struct sctp_association *, 191163953Srrs struct sctp_tmit_chunk *); 192163953Srrs 193163953Srrs#else 194163953Srrs#define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \ 195163953Srrsdo { \ 196163953Srrs if (tp1->data != NULL) { \ 197163996Srrs atomic_add_int(&((asoc)->chunks_on_out_queue), -chk_cnt); \ 198163953Srrs if ((asoc)->total_output_queue_size >= tp1->book_size) { \ 199163953Srrs atomic_add_int(&((asoc)->total_output_queue_size), -tp1->book_size); \ 200163953Srrs } else { \ 201163953Srrs (asoc)->total_output_queue_size = 0; \ 202163953Srrs } \ 203163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 204163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 205163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \ 206163953Srrs atomic_add_int(&((stcb)->sctp_socket->so_snd.sb_cc), -tp1->book_size); \ 207163953Srrs } else { \ 208163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 209163953Srrs } \ 210163953Srrs } \ 211163953Srrs } \ 212163953Srrs} while (0) 213163953Srrs 214163953Srrs#endif 215163953Srrs 216163953Srrs#define sctp_free_spbufspace(stcb, asoc, sp) \ 217163953Srrsdo { \ 218163953Srrs if (sp->data != NULL) { \ 219163996Srrs atomic_add_int(&(asoc)->chunks_on_out_queue, -1); \ 220163953Srrs if ((asoc)->total_output_queue_size >= sp->length) { \ 221163953Srrs atomic_add_int(&(asoc)->total_output_queue_size,sp->length); \ 222163953Srrs } else { \ 223163953Srrs (asoc)->total_output_queue_size = 0; \ 224163953Srrs } \ 225163953Srrs if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 226163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 227163953Srrs if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \ 228163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \ 229163953Srrs } else { \ 230163953Srrs stcb->sctp_socket->so_snd.sb_cc = 0; \ 231163953Srrs } \ 232163953Srrs } \ 233163953Srrs } \ 234163953Srrs} while (0) 235163953Srrs 236163953Srrs#define sctp_snd_sb_alloc(stcb, sz) \ 237163953Srrsdo { \ 238163953Srrs atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \ 239163953Srrs if ((stcb->sctp_socket != NULL) && \ 240163953Srrs ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \ 241163953Srrs (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \ 242163953Srrs atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \ 243163953Srrs } \ 244163953Srrs} while (0) 245163953Srrs 246163953Srrs 247163953Srrsint 248163953Srrssctp_soreceive(struct socket *so, struct sockaddr **psa, 249163953Srrs struct uio *uio, 250163953Srrs struct mbuf **mp0, 251163953Srrs struct mbuf **controlp, 252163953Srrs int *flagsp); 253163953Srrs 254163953Srrs 255163953Srrs#ifdef SCTP_STAT_LOGGING 256163953Srrsvoid 257163953Srrs sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d); 258163953Srrs 259163953Srrsvoid 260163953Srrssctp_wakeup_log(struct sctp_tcb *stcb, 261163953Srrs uint32_t cumtsn, 262163953Srrs uint32_t wake_cnt, int from); 263163953Srrs 264164181Srrsvoid sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int); 265163953Srrs 266163953Srrsvoid sctp_log_nagle_event(struct sctp_tcb *stcb, int action); 267163953Srrs 268163953Srrs 269163953Srrsvoid 270163953Srrs sctp_log_mb(struct mbuf *m, int from); 271163953Srrs 272163953Srrsvoid 273163953Srrssctp_sblog(struct sockbuf *sb, 274163953Srrs struct sctp_tcb *stcb, int from, int incr); 275163953Srrs 276163953Srrsvoid 277163953Srrssctp_log_strm_del(struct sctp_queued_to_read *control, 278163953Srrs struct sctp_queued_to_read *poschk, 279163953Srrs int from); 280163953Srrsvoid sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t); 281163953Srrsvoid rto_logging(struct sctp_nets *net, int from); 282163953Srrs 283163953Srrsvoid sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc); 284163953Srrs 285163953Srrsvoid sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from); 286163953Srrsvoid sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t); 287163953Srrsvoid sctp_log_block(uint8_t, struct socket *, struct sctp_association *, int); 288163953Srrsvoid sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t); 289163953Srrsvoid sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 290163953Srrsvoid sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t); 291163953Srrsint sctp_fill_stat_log(struct mbuf *); 292163953Srrsvoid sctp_log_fr(uint32_t, uint32_t, uint32_t, int); 293163953Srrsvoid sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int); 294163953Srrsvoid sctp_log_map(uint32_t, uint32_t, uint32_t, int); 295163953Srrs 296163953Srrsvoid sctp_clr_stat_log(void); 297163953Srrs 298163953Srrs#endif 299163953Srrs 300163953Srrs#ifdef SCTP_AUDITING_ENABLED 301163953Srrsvoid 302163953Srrssctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *, 303163953Srrs struct sctp_nets *); 304163953Srrsvoid sctp_audit_log(uint8_t, uint8_t); 305163953Srrs 306163953Srrs#endif 307163953Srrs 308163953Srrs 309163953Srrs#endif /* _KERNEL */ 310163953Srrs#endif 311