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