2006-11-03 15:23:16 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006, Cisco Systems, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* a) Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* b) Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* c) Neither the name of Cisco Systems, Inc. nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2006-11-03 17:21:53 +00:00
|
|
|
#include <sys/cdefs.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
#ifndef __sctp_os_bsd_h__
|
|
|
|
#define __sctp_os_bsd_h__
|
|
|
|
|
|
|
|
/*
|
|
|
|
* includes
|
|
|
|
*/
|
|
|
|
#include <sys/random.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
typedef struct mbuf *sctp_mbuf_t;
|
|
|
|
|
2006-12-14 17:02:55 +00:00
|
|
|
#define USER_ADDR_NULL (NULL) /* FIX ME: temp */
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* general memory allocation
|
|
|
|
*/
|
|
|
|
#define SCTP_MALLOC(var, type, size, name) \
|
|
|
|
do { \
|
|
|
|
MALLOC(var, type, size, M_PCB, M_NOWAIT); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define SCTP_FREE(var) FREE(var, M_PCB)
|
|
|
|
|
|
|
|
#define SCTP_MALLOC_SONAME(var, type, size) \
|
|
|
|
do { \
|
|
|
|
MALLOC(var, type, size, M_SONAME, M_WAITOK | M_ZERO); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define SCTP_FREE_SONAME(var) FREE(var, M_SONAME)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zone allocation functions
|
|
|
|
*/
|
|
|
|
#include <vm/uma.h>
|
|
|
|
/* SCTP_ZONE_INIT: initialize the zone */
|
|
|
|
typedef struct uma_zone *sctp_zone_t;
|
|
|
|
|
|
|
|
#define UMA_ZFLAG_FULL 0x0020
|
|
|
|
#define SCTP_ZONE_INIT(zone, name, size, number) { \
|
|
|
|
zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\
|
|
|
|
UMA_ZFLAG_FULL); \
|
|
|
|
uma_zone_set_max(zone, number); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* SCTP_ZONE_GET: allocate element from the zone */
|
|
|
|
#define SCTP_ZONE_GET(zone) \
|
|
|
|
uma_zalloc(zone, M_NOWAIT);
|
|
|
|
|
|
|
|
/* SCTP_ZONE_FREE: free element from the zone */
|
|
|
|
#define SCTP_ZONE_FREE(zone, element) \
|
|
|
|
uma_zfree(zone, element);
|
2007-01-15 15:12:10 +00:00
|
|
|
#define SCTP_HASH_INIT(size, hashmark) hashinit_flags(size, M_PCB, hashmark, HASH_NOWAIT)
|
|
|
|
#define SCTP_HASH_FREE(table, hashmark) hashdestroy(table, M_PCB, hashmark)
|
|
|
|
|
|
|
|
#define SCTP_M_COPYM m_copym
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
/*
|
|
|
|
* timers
|
|
|
|
*/
|
|
|
|
#include <sys/callout.h>
|
|
|
|
typedef struct callout sctp_os_timer_t;
|
|
|
|
|
|
|
|
#define SCTP_OS_TIMER_INIT(tmr) callout_init(tmr, 1)
|
|
|
|
#define SCTP_OS_TIMER_START callout_reset
|
|
|
|
#define SCTP_OS_TIMER_STOP callout_stop
|
2007-01-15 15:12:10 +00:00
|
|
|
#define SCTP_OS_TIMER_STOP_DRAIN callout_drain
|
2006-12-29 20:21:42 +00:00
|
|
|
#define SCTP_OS_TIMER_PENDING callout_pending
|
|
|
|
#define SCTP_OS_TIMER_ACTIVE callout_active
|
|
|
|
#define SCTP_OS_TIMER_DEACTIVATE callout_deactivate
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Functions
|
|
|
|
*/
|
2006-12-29 20:21:42 +00:00
|
|
|
#define SCTP_READ_RANDOM(buf, len) read_random(buf, len)
|
|
|
|
|
|
|
|
/* Mbuf manipulation and access macros */
|
|
|
|
#define SCTP_BUF_LEN(m) (m->m_len)
|
|
|
|
#define SCTP_BUF_NEXT(m) (m->m_next)
|
|
|
|
#define SCTP_BUF_NEXT_PKT(m) (m->m_nextpkt)
|
|
|
|
#define SCTP_BUF_RESV_UF(m, size) m->m_data += size
|
|
|
|
#define SCTP_BUF_AT(m, size) m->m_data + size
|
|
|
|
#define SCTP_BUF_IS_EXTENDED(m) (m->m_flags & M_EXT)
|
|
|
|
#define SCTP_BUF_EXTEND_SIZE(m) (m->m_ext.ext_size)
|
|
|
|
#define SCTP_BUF_TYPE(m) (m->m_type)
|
|
|
|
#define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif)
|
|
|
|
#define SCTP_BUF_PREPEND M_PREPEND
|
|
|
|
/*************************/
|
|
|
|
/* These are for logging */
|
|
|
|
/*************************/
|
|
|
|
/* return the base ext data pointer */
|
|
|
|
#define SCTP_BUF_EXTEND_BASE(m) (m->m_ext.ext_buf)
|
|
|
|
/* return the refcnt of the data pointer */
|
|
|
|
#define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ref_cnt)
|
|
|
|
/* return any buffer related flags, this is
|
|
|
|
* used beyond logging for apple only.
|
|
|
|
*/
|
|
|
|
#define SCTP_BUF_GET_FLAGS(m) (m->m_flags)
|
|
|
|
|
|
|
|
/* For BSD this just accesses the M_PKTHDR length
|
|
|
|
* so it operates on an mbuf with hdr flag. Other
|
|
|
|
* O/S's may have seperate packet header and mbuf
|
|
|
|
* chain pointers.. thus the macro.
|
|
|
|
*/
|
|
|
|
#define SCTP_HEADER_TO_CHAIN(m) (m)
|
|
|
|
#define SCTP_HEADER_LEN(m) (m->m_pkthdr.len)
|
|
|
|
#define SCTP_GET_HEADER_FOR_OUTPUT(len) sctp_get_mbuf_for_msg(len, 1, M_DONTWAIT, 1, MT_DATA)
|
|
|
|
|
|
|
|
/* Attach the chain of data into the sendable packet. */
|
|
|
|
#define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \
|
|
|
|
pak->m_next = m; \
|
|
|
|
pak->m_pkthdr.len = packet_length; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/* Other m_pkthdr type things */
|
|
|
|
#define SCTP_IS_IT_BROADCAST(dst, m) in_broadcast(dst, m->m_pkthdr.rcvif)
|
|
|
|
#define SCTP_IS_IT_LOOPBACK(m) ((m->m_pkthdr.rcvif == NULL) ||(m->m_pkthdr.rcvif->if_type == IFT_LOOP))
|
|
|
|
|
|
|
|
|
|
|
|
/* This converts any input packet header
|
|
|
|
* into the chain of data holders, for BSD
|
|
|
|
* its a NOP.
|
|
|
|
*/
|
|
|
|
#define SCTP_PAK_TO_BUF(i_pak) (i_pak)
|
|
|
|
|
|
|
|
/* Macro's for getting length from V6/V4 header */
|
|
|
|
#define SCTP_GET_IPV4_LENGTH(iph) (iph->ip_len)
|
|
|
|
#define SCTP_GET_IPV6_LENGTH(ip6) (ntohs(ip6->ip6_plen))
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-01-15 15:12:10 +00:00
|
|
|
/* is the endpoint v6only? */
|
|
|
|
#define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
|
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif
|