/*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 2006-2007, by Cisco Systems, Inc. All rights reserved. * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved. * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved. * Copyright (c) 2008-2011, by Brad Penoff. 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.
*/
#ifndef __sctp_os_userspace_h__ #define __sctp_os_userspace_h__ /* * Userspace includes * All the opt_xxx.h files are placed in the kernel build directory. * We will place them in userspace stack build directory.
*/
#defineinline __inline #define __inline__ __inline #define MSG_EOR 0x8 /* data completes record */ #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
#ifdef CMSG_DATA #undef CMSG_DATA #endif /* * The following definitions should apply iff WINVER < 0x0600 * but that check doesn't work in all cases. So be more pedantic...
*/ #define CMSG_DATA(x) WSA_CMSG_DATA(x) #define CMSG_ALIGN(x) WSA_CMSGDATA_ALIGN(x) #ifndef CMSG_FIRSTHDR #define CMSG_FIRSTHDR(x) WSA_CMSG_FIRSTHDR(x) #endif #ifndef CMSG_NXTHDR #define CMSG_NXTHDR(x, y) WSA_CMSG_NXTHDR(x, y) #endif #ifndef CMSG_SPACE #define CMSG_SPACE(x) WSA_CMSG_SPACE(x) #endif #ifndef CMSG_LEN #define CMSG_LEN(x) WSA_CMSG_LEN(x) #endif
/* * Access to IFN's to help with src-addr-selection
*/ /* This could return VOID if the index works but for BSD we provide both. */ #define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) \
((ro)->ro_rt != NULL ? (ro)->ro_rt->rt_ifp : NULL) #define SCTP_ROUTE_HAS_VALID_IFN(ro) \
((ro)->ro_rt && (ro)->ro_rt->rt_ifp) /******************************************/
#define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) 1 /* compiles... TODO use routing socket to determine */
#ifdefined(__APPLE__) /* was a 0 byte file. needed for structs if_data(64) and net_event_data */ #include <net/if_var.h> #endif #ifdefined(__FreeBSD__) #include <net/if_types.h> /* #include <net/if_var.h> was a 0 byte file. causes struct mtx redefinition */ #endif /* OOTB only - dummy route used at the moment. should we port route to
* userspace as well? */ /* on FreeBSD, this results in a redefintion of struct route */ /* #include <net/route.h> */ #if !defined(_WIN32) && !defined(__native_client__) #include <net/if.h> #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #endif #ifdefined(HAVE_NETINET_IP_ICMP_H) #include <netinet/ip_icmp.h> #else #include <user_ip_icmp.h> #endif /* #include <netinet/in_pcb.h> ported to userspace */ #include <user_inpcb.h>
/* * Local address and interface list handling
*/ #define SCTP_MAX_VRF_ID 0 #define SCTP_SIZE_OF_VRF_HASH 3 #define SCTP_IFNAMSIZ IFNAMSIZ #define SCTP_DEFAULT_VRFID 0 #define SCTP_VRF_ADDR_HASH_SIZE 16 #define SCTP_VRF_IFN_HASH_SIZE 3 #define SCTP_INIT_VRF_TABLEID(vrf)
#if !defined(_WIN32) #define SCTP_IFN_IS_IFT_LOOP(ifn) (strncmp((ifn)->ifn_name, "lo", 2) == 0) /* BSD definition */ /* #define SCTP_ROUTE_IS_REAL_LOOP(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifa && (ro)->ro_rt->rt_ifa->ifa_ifp && (ro)->ro_rt->rt_ifa->ifa_ifp->if_type == IFT_LOOP) */ /* only used in IPv6 scenario, which isn't supported yet */ #define SCTP_ROUTE_IS_REAL_LOOP(ro) 0
/* * Access to IFN's to help with src-addr-selection
*/ /* This could return VOID if the index works but for BSD we provide both. */ #define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) (void *)ro->ro_rt->rt_ifp #define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) 1 /* compiles... TODO use routing socket to determine */ #define SCTP_ROUTE_HAS_VALID_IFN(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifp) #endif
/* * general memory allocation
*/ #define SCTP_MALLOC(var, type, size, name) \ do { \
MALLOC(var, type, size, name, M_NOWAIT); \
} while (0)
#define SCTP_FREE(var, type) FREE(var, type)
#define SCTP_MALLOC_SONAME(var, type, size) \ do { \
MALLOC(var, type, size, M_SONAME, (M_WAITOK | M_ZERO)); \
} while (0)
/* __Userspace__ SCTP_ZONE_GET: allocate element from the zone */ #define SCTP_ZONE_GET(zone, type) \
(type *)malloc(zone);
/* __Userspace__ SCTP_ZONE_FREE: free element from the zone */ #define SCTP_ZONE_FREE(zone, element) { \
free(element); \
}
#define SCTP_ZONE_DESTROY(zone) #else /*__Userspace__ Compiling & linking notes: Needs libumem, which has been placed in ./user_lib All userspace header files are in ./user_include. Makefile will need the following. CFLAGS = -I./ -Wall LDFLAGS = -L./user_lib -R./user_lib -lumem
*/ #include"user_include/umem.h"
/* __Userspace__ SCTP_ZONE_INIT: initialize the zone */ /* __Userspace__ No equivalent function to uma_zone_set_max added yet. (See SCTP_ZONE_INIT in sctp_os_bsd.h for reference). It may not be required as mentioned in http://nixdoc.net/man-pages/FreeBSD/uma_zalloc.9.html that max limits may not enforced on systems with more than one CPU.
*/ #define SCTP_ZONE_INIT(zone, name, size, number) { \
zone = umem_cache_create(name, size, 0, NULL, NULL, NULL, NULL, NULL, 0); \
}
/* __Userspace__ SCTP_ZONE_GET: allocate element from the zone */ #define SCTP_ZONE_GET(zone, type) \
(type *)umem_cache_alloc(zone, UMEM_DEFAULT);
/* __Userspace__ SCTP_ZONE_FREE: free element from the zone */ #define SCTP_ZONE_FREE(zone, element) \
umem_cache_free(zone, element);
/* __Userspace__ SCTP_ZONE_DESTROY: destroy the zone */ #define SCTP_ZONE_DESTROY(zone) \
umem_cache_destroy(zone); #endif
/* * __Userspace__ Defining sctp_hashinit_flags() and sctp_hashdestroy() for userland.
*/ void *sctp_hashinit_flags(int elements, struct malloc_type *type,
u_long *hashmask, int flags); void
sctp_hashdestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask);
/* * timers
*/ /* __Userspace__ * user_sctp_callout.h has typedef struct sctp_callout sctp_os_timer_t; * which is used in the timer related functions such as * SCTP_OS_TIMER_INIT etc.
*/ #include <netinet/sctp_callout.h>
/* __Userspace__ Creating a receive thread */ #include <user_recv_thread.h>
/*__Userspace__ defining KTR_SUBSYS 1 as done in sctp_os_macosx.h */ #define KTR_SUBSYS 1
/* The packed define for 64 bit platforms */ #if !defined(_WIN32) #define SCTP_PACKED __attribute__((packed)) #define SCTP_UNUSED __attribute__((unused)) #else #define SCTP_PACKED #define SCTP_UNUSED #endif
/* We make it so if you have up to 4 threads * writting based on the default size of * the packet log 65 k, that would be * 4 16k packets before we would hit * a problem.
*/ #define SCTP_PKTLOG_WRITERS_NEED_LOCK 3
/* set MTU */ /* TODO set this based on the ro->ro_dst, looking up MTU with routing socket */ #if 0 if (userspace_rawroute == -1) {
userspace_rawroute = socket(AF_ROUTE, SOCK_RAW, 0); if (userspace_rawroute == -1) return;
} #endif
ro->ro_rt->rt_rmx.rmx_mtu = 1500; /* FIXME temporary solution */
/* TODO enable the ability to obtain interface index of route for * SCTP_GET_IF_INDEX_FROM_ROUTE macro.
*/
} #define SCTP_RTALLOC(ro, vrf_id, fibnum) sctp_userspace_rtalloc((sctp_route_t *)ro)
/* dummy rtfree needed once user_route.h is included */ staticinlinevoid sctp_userspace_rtfree(sctp_rtentry_t *rt)
{ if(rt == NULL) { return;
} if(--rt->rt_refcnt > 0) { return;
}
free(rt);
} #define rtfree(arg1) sctp_userspace_rtfree(arg1)
/*************************/ /* MTU */ /*************************/ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index);
#define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \ if (rt != NULL) \
rt->rt_rmx.rmx_mtu = mtu; \
} while(0)
/*************************/ /* 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_DETACH_HEADER_FROM_CHAIN(m) #define SCTP_HEADER_LEN(m) ((m)->m_pkthdr.len) #define SCTP_GET_HEADER_FOR_OUTPUT(o_pak) 0 #define SCTP_RELEASE_HEADER(m) #define SCTP_RELEASE_PKT(m) sctp_m_freem(m)
/* Attach the chain of data into the sendable packet. */ #define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \
pak = m; \
pak->m_pkthdr.len = packet_length; \
} while(0)
/* Other m_pkthdr type things */ /* FIXME need real definitions */ #define SCTP_IS_IT_BROADCAST(dst, m) 0 /* OOTB only #define SCTP_IS_IT_BROADCAST(dst, m) ((m->m_flags & M_PKTHDR) ? in_broadcast(dst, m->m_pkthdr.rcvif) : 0) BSD def */ #define SCTP_IS_IT_LOOPBACK(m) 0 /* OOTB ONLY #define SCTP_IS_IT_LOOPBACK(m) ((m->m_flags & M_PKTHDR) && ((m->m_pkthdr.rcvif == NULL) || (m->m_pkthdr.rcvif->if_type == IFT_LOOP))) BSD def */
/* This converts any input packet header * into the chain of data holders, for BSD * its a NOP.
*/
/* get the v6 hop limit */ #define SCTP_GET_HLIM(inp, ro) 128 #define IPv6_HOP_LIMIT 128
/* is the endpoint v6only? */ #define SCTP_IPV6_V6ONLY(sctp_inpcb) ((sctp_inpcb)->ip_inp.inp.inp_flags & IN6P_IPV6_V6ONLY) /* is the socket non-blocking? */ #define SCTP_SO_IS_NBIO(so) ((so)->so_state & SS_NBIO) #define SCTP_SET_SO_NBIO(so) ((so)->so_state |= SS_NBIO) #define SCTP_CLEAR_SO_NBIO(so) ((so)->so_state &= ~SS_NBIO) /* get the socket type */ #define SCTP_SO_TYPE(so) ((so)->so_type)
/* reserve sb space for a socket */ #define SCTP_SORESERVE(so, send, recv) soreserve(so, send, recv)
/* Defining SCTP_IP_ID macro. In netinet/ip_output.c, we have u_short ip_id; In netinet/ip_var.h, we have extern u_short ip_id; (enclosed within _KERNEL_) See static __inline uint16_t ip_newid(void) in netinet/ip_var.h
*/ #define SCTP_IP_ID(inp) (ip_id)
/* need sctphdr to get port in SCTP_IP_OUTPUT. sctphdr defined in sctp.h */ #include <netinet/sctp.h> externvoid sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
sctp_route_t *ro, void *stcb,
uint32_t vrf_id);
struct mbuf *
sctp_get_mbuf_for_msg(unsignedint space_needed, int want_header, int how, int allonebuf, int type);
/* with the current included files, this is defined in Linux but * in FreeBSD, it is behind a _KERNEL in sys/socket.h ...
*/ #ifdefined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__native_client__) /* stolen from /usr/include/sys/socket.h */ #define CMSG_ALIGN(n) _ALIGN(n) #elifdefined(__NetBSD__) #define CMSG_ALIGN(n) (((n) + __ALIGNBYTES) & ~__ALIGNBYTES) #elifdefined(__APPLE__) #if !defined(__DARWIN_ALIGNBYTES) #define __DARWIN_ALIGNBYTES (sizeof(__darwin_size_t) - 1) #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.