OLD | NEW |
(Empty) | |
| 1 /*- |
| 2 * Copyright (c) 2006-2007, by Cisco Systems, Inc. All rights reserved. |
| 3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved. |
| 4 * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved. |
| 5 * Copyright (c) 2008-2011, by Brad Penoff. All rights reserved. |
| 6 * |
| 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions are met: |
| 9 * |
| 10 * a) Redistributions of source code must retain the above copyright notice, |
| 11 * this list of conditions and the following disclaimer. |
| 12 * |
| 13 * b) Redistributions in binary form must reproduce the above copyright |
| 14 * notice, this list of conditions and the following disclaimer in |
| 15 * the documentation and/or other materials provided with the distribution. |
| 16 * |
| 17 * c) Neither the name of Cisco Systems, Inc. nor the names of its |
| 18 * contributors may be used to endorse or promote products derived |
| 19 * from this software without specific prior written permission. |
| 20 * |
| 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOS
E |
| 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 31 * THE POSSIBILITY OF SUCH DAMAGE. |
| 32 */ |
| 33 |
| 34 #ifndef __sctp_os_userspace_h__ |
| 35 #define __sctp_os_userspace_h__ |
| 36 /* |
| 37 * Userspace includes |
| 38 * All the opt_xxx.h files are placed in the kernel build directory. |
| 39 * We will place them in userspace stack build directory. |
| 40 */ |
| 41 |
| 42 #include <errno.h> |
| 43 |
| 44 #if defined(__Userspace_os_Windows) |
| 45 #include <winsock2.h> |
| 46 #include <ws2tcpip.h> |
| 47 #include <ws2ipdef.h> |
| 48 #include <ws2def.h> |
| 49 #include <iphlpapi.h> |
| 50 #include <Mswsock.h> |
| 51 #include <Windows.h> |
| 52 #include "user_environment.h" |
| 53 typedef CRITICAL_SECTION userland_mutex_t; |
| 54 #if WINVER < 0x0600 |
| 55 enum { |
| 56 C_SIGNAL = 0, |
| 57 C_BROADCAST = 1, |
| 58 C_MAX_EVENTS = 2 |
| 59 }; |
| 60 typedef struct |
| 61 { |
| 62 u_int waiters_count; |
| 63 CRITICAL_SECTION waiters_count_lock; |
| 64 HANDLE events_[C_MAX_EVENTS]; |
| 65 } userland_cond_t; |
| 66 #define InitializeConditionVariable(cond) InitializeXPConditionVariable(cond) |
| 67 #define DeleteConditionVariable(cond) DeleteXPConditionVariable(cond) |
| 68 #define SleepConditionVariableCS(cond, mtx, time) SleepXPConditionVariable(cond,
mtx) |
| 69 #define WakeAllConditionVariable(cond) WakeAllXPConditionVariable(cond) |
| 70 #else |
| 71 #define DeleteConditionVariable(cond) |
| 72 typedef CONDITION_VARIABLE userland_cond_t; |
| 73 #endif |
| 74 typedef HANDLE userland_thread_t; |
| 75 #define ADDRESS_FAMILY unsigned __int8 |
| 76 #define IPVERSION 4 |
| 77 #define MAXTTL 255 |
| 78 #define uint64_t unsigned __int64 |
| 79 #define u_long unsigned __int64 |
| 80 #define u_int unsigned __int32 |
| 81 #define uint32_t unsigned __int32 |
| 82 #define u_int32_t unsigned __int32 |
| 83 #define int32_t __int32 |
| 84 #define int16_t __int16 |
| 85 #define uint16_t unsigned __int16 |
| 86 #define u_int16_t unsigned __int16 |
| 87 #define uint8_t unsigned __int8 |
| 88 #define u_int8_t unsigned __int8 |
| 89 #define int8_t __int8 |
| 90 #define u_char unsigned char |
| 91 #define n_short unsigned __int16 |
| 92 #define u_short unsigned __int16 |
| 93 #define ssize_t __int64 |
| 94 #define size_t __int32 |
| 95 #define in_addr_t unsigned __int32 |
| 96 #define in_port_t unsigned __int16 |
| 97 #define n_time unsigned __int32 |
| 98 #define sa_family_t unsigned __int8 |
| 99 #define IFNAMSIZ 64 |
| 100 #define __func__ __FUNCTION__ |
| 101 |
| 102 #ifndef EWOULDBLOCK |
| 103 #define EWOULDBLOCK WSAEWOULDBLOCK |
| 104 #endif |
| 105 #ifndef EINPROGRESS |
| 106 #define EINPROGRESS WSAEINPROGRESS |
| 107 #endif |
| 108 #ifndef EALREADY |
| 109 #define EALREADY WSAEALREADY |
| 110 #endif |
| 111 #ifndef ENOTSOCK |
| 112 #define ENOTSOCK WSAENOTSOCK |
| 113 #endif |
| 114 #ifndef EDESTADDRREQ |
| 115 #define EDESTADDRREQ WSAEDESTADDRREQ |
| 116 #endif |
| 117 #ifndef EMSGSIZE |
| 118 #define EMSGSIZE WSAEMSGSIZE |
| 119 #endif |
| 120 #ifndef EPROTOTYPE |
| 121 #define EPROTOTYPE WSAEPROTOTYPE |
| 122 #endif |
| 123 #ifndef ENOPROTOOPT |
| 124 #define ENOPROTOOPT WSAENOPROTOOPT |
| 125 #endif |
| 126 #ifndef EPROTONOSUPPORT |
| 127 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT |
| 128 #endif |
| 129 #ifndef ESOCKTNOSUPPORT |
| 130 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT |
| 131 #endif |
| 132 #ifndef EOPNOTSUPP |
| 133 #define EOPNOTSUPP WSAEOPNOTSUPP |
| 134 #endif |
| 135 #ifndef ENOTSUP |
| 136 #define ENOTSUP WSAEOPNOTSUPP |
| 137 #endif |
| 138 #ifndef EPFNOSUPPORT |
| 139 #define EPFNOSUPPORT WSAEPFNOSUPPORT |
| 140 #endif |
| 141 #ifndef EAFNOSUPPORT |
| 142 #define EAFNOSUPPORT WSAEAFNOSUPPORT |
| 143 #endif |
| 144 #ifndef EADDRINUSE |
| 145 #define EADDRINUSE WSAEADDRINUSE |
| 146 #endif |
| 147 #ifndef EADDRNOTAVAIL |
| 148 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL |
| 149 #endif |
| 150 #ifndef ENETDOWN |
| 151 #define ENETDOWN WSAENETDOWN |
| 152 #endif |
| 153 #ifndef ENETUNREACH |
| 154 #define ENETUNREACH WSAENETUNREACH |
| 155 #endif |
| 156 #ifndef ENETRESET |
| 157 #define ENETRESET WSAENETRESET |
| 158 #endif |
| 159 #ifndef ECONNABORTED |
| 160 #define ECONNABORTED WSAECONNABORTED |
| 161 #endif |
| 162 #ifndef ECONNRESET |
| 163 #define ECONNRESET WSAECONNRESET |
| 164 #endif |
| 165 #ifndef ENOBUFS |
| 166 #define ENOBUFS WSAENOBUFS |
| 167 #endif |
| 168 #ifndef EISCONN |
| 169 #define EISCONN WSAEISCONN |
| 170 #endif |
| 171 #ifndef ENOTCONN |
| 172 #define ENOTCONN WSAENOTCONN |
| 173 #endif |
| 174 #ifndef ESHUTDOWN |
| 175 #define ESHUTDOWN WSAESHUTDOWN |
| 176 #endif |
| 177 #ifndef ETOOMANYREFS |
| 178 #define ETOOMANYREFS WSAETOOMANYREFS |
| 179 #endif |
| 180 #ifndef ETIMEDOUT |
| 181 #define ETIMEDOUT WSAETIMEDOUT |
| 182 #endif |
| 183 #ifndef ECONNREFUSED |
| 184 #define ECONNREFUSED WSAECONNREFUSED |
| 185 #endif |
| 186 #ifndef ELOOP |
| 187 #define ELOOP WSAELOOP |
| 188 #endif |
| 189 #ifndef EHOSTDOWN |
| 190 #define EHOSTDOWN WSAEHOSTDOWN |
| 191 #endif |
| 192 #ifndef EHOSTUNREACH |
| 193 #define EHOSTUNREACH WSAEHOSTUNREACH |
| 194 #endif |
| 195 #ifndef EPROCLIM |
| 196 #define EPROCLIM WSAEPROCLIM |
| 197 #endif |
| 198 #ifndef EUSERS |
| 199 #define EUSERS WSAEUSERS |
| 200 #endif |
| 201 #ifndef EDQUOT |
| 202 #define EDQUOT WSAEDQUOT |
| 203 #endif |
| 204 #ifndef ESTALE |
| 205 #define ESTALE WSAESTALE |
| 206 #endif |
| 207 #ifndef EREMOTE |
| 208 #define EREMOTE WSAEREMOTE |
| 209 #endif |
| 210 |
| 211 typedef char* caddr_t; |
| 212 |
| 213 #define getifaddrs(interfaces) (int)Win_getifaddrs(interfaces) |
| 214 #define if_nametoindex(x) (int)win_if_nametoindex(x) |
| 215 |
| 216 #define bzero(buf, len) memset(buf, 0, len) |
| 217 #define bcopy(srcKey, dstKey, len) memcpy(dstKey, srcKey, len) |
| 218 #define snprintf(data, size, format, name) _snprintf_s(data, size, _TRUNCATE, fo
rmat, name) |
| 219 #define inline __inline |
| 220 #define __inline__ __inline |
| 221 #define random() rand() |
| 222 #define srandom(s) srand(s) |
| 223 #define MSG_EOR 0x8 /* data completes record */ |
| 224 #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ |
| 225 |
| 226 #ifdef CMSG_DATA |
| 227 #undef CMSG_DATA |
| 228 #endif |
| 229 #define CMSG_DATA(x) WSA_CMSG_DATA(x) |
| 230 #define CMSG_ALIGN(x) WSA_CMSGDATA_ALIGN(x) |
| 231 #if WINVER < 0x0600 |
| 232 #define CMSG_FIRSTHDR(x) WSA_CMSG_FIRSTHDR(x) |
| 233 #define CMSG_NXTHDR(x, y) WSA_CMSG_NXTHDR(x, y) |
| 234 #define CMSG_SPACE(x) WSA_CMSG_SPACE(x) |
| 235 #define CMSG_LEN(x) WSA_CMSG_LEN(x) |
| 236 #endif |
| 237 |
| 238 /**** from sctp_os_windows.h ***************/ |
| 239 #define SCTP_IFN_IS_IFT_LOOP(ifn) ((ifn)->ifn_type == IFT_LOOP) |
| 240 #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) |
| 241 |
| 242 /* |
| 243 * Access to IFN's to help with src-addr-selection |
| 244 */ |
| 245 /* This could return VOID if the index works but for BSD we provide both. */ |
| 246 #define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) \ |
| 247 ((ro)->ro_rt != NULL ? (ro)->ro_rt->rt_ifp : NULL) |
| 248 #define SCTP_ROUTE_HAS_VALID_IFN(ro) \ |
| 249 ((ro)->ro_rt && (ro)->ro_rt->rt_ifp) |
| 250 /******************************************/ |
| 251 |
| 252 #define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) 1 /* compiles... TODO use routing sock
et to determine */ |
| 253 |
| 254 #define timeradd(tvp, uvp, vvp) \ |
| 255 do { \ |
| 256 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ |
| 257 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ |
| 258 if ((vvp)->tv_usec >= 1000000) { \ |
| 259 (vvp)->tv_sec++; \ |
| 260 (vvp)->tv_usec -= 1000000; \ |
| 261 } \ |
| 262 } while (0) |
| 263 |
| 264 #define timersub(tvp, uvp, vvp) \ |
| 265 do { \ |
| 266 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ |
| 267 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ |
| 268 if ((vvp)->tv_usec < 0) { \ |
| 269 (vvp)->tv_sec--; \ |
| 270 (vvp)->tv_usec += 1000000; \ |
| 271 } \ |
| 272 } while (0) |
| 273 |
| 274 #define BIG_ENDIAN 1 |
| 275 #define LITTLE_ENDIAN 0 |
| 276 #ifdef WORDS_BIGENDIAN |
| 277 #define BYTE_ORDER BIG_ENDIAN |
| 278 #else |
| 279 #define BYTE_ORDER LITTLE_ENDIAN |
| 280 #endif |
| 281 |
| 282 struct iovec { |
| 283 ULONG len; |
| 284 CHAR FAR *buf; |
| 285 }; |
| 286 |
| 287 #define iov_base buf |
| 288 #define iov_len len |
| 289 |
| 290 struct ifa_msghdr { |
| 291 unsigned __int16 ifam_msglen; |
| 292 unsigned char ifam_version; |
| 293 unsigned char ifam_type; |
| 294 __int32 ifam_addrs; |
| 295 __int32 ifam_flags; |
| 296 unsigned __int16 ifam_index; |
| 297 __int32 ifam_metric; |
| 298 }; |
| 299 |
| 300 struct ifdevmtu { |
| 301 int ifdm_current; |
| 302 int ifdm_min; |
| 303 int ifdm_max; |
| 304 }; |
| 305 |
| 306 struct ifkpi { |
| 307 unsigned int ifk_module_id; |
| 308 unsigned int ifk_type; |
| 309 union { |
| 310 void *ifk_ptr; |
| 311 int ifk_value; |
| 312 } ifk_data; |
| 313 }; |
| 314 |
| 315 struct ifreq { |
| 316 char ifr_name[16]; |
| 317 union { |
| 318 struct sockaddr ifru_addr; |
| 319 struct sockaddr ifru_dstaddr; |
| 320 struct sockaddr ifru_broadaddr; |
| 321 short ifru_flags; |
| 322 int ifru_metric; |
| 323 int ifru_mtu; |
| 324 int ifru_phys; |
| 325 int ifru_media; |
| 326 int ifru_intval; |
| 327 char* ifru_data; |
| 328 struct ifdevmtu ifru_devmtu; |
| 329 struct ifkpi ifru_kpi; |
| 330 unsigned __int32 ifru_wake_flags; |
| 331 } ifr_ifru; |
| 332 #define ifr_addr ifr_ifru.ifru_addr |
| 333 #define ifr_dstaddr ifr_ifru.ifru_dstaddr |
| 334 #define ifr_broadaddr ifr_ifru.ifru_broadaddr |
| 335 #define ifr_flags ifr_ifru.ifru_flags[0] |
| 336 #define ifr_prevflags ifr_ifru.ifru_flags[1] |
| 337 #define ifr_metric ifr_ifru.ifru_metric |
| 338 #define ifr_mtu ifr_ifru.ifru_mtu |
| 339 #define ifr_phys ifr_ifru.ifru_phys |
| 340 #define ifr_media ifr_ifru.ifru_media |
| 341 #define ifr_data ifr_ifru.ifru_data |
| 342 #define ifr_devmtu ifr_ifru.ifru_devmtu |
| 343 #define ifr_intval ifr_ifru.ifru_intval |
| 344 #define ifr_kpi ifr_ifru.ifru_kpi |
| 345 #define ifr_wake_flags ifr_ifru.ifru_wake_flags |
| 346 }; |
| 347 |
| 348 /*#include <packon.h> |
| 349 #pragma pack(push, 1)*/ |
| 350 struct ip { |
| 351 u_char ip_hl:4, ip_v:4; |
| 352 u_char ip_tos; |
| 353 u_short ip_len; |
| 354 u_short ip_id; |
| 355 u_short ip_off; |
| 356 #define IP_RP 0x8000 |
| 357 #define IP_DF 0x4000 |
| 358 #define IP_MF 0x2000 |
| 359 #define IP_OFFMASK 0x1fff |
| 360 u_char ip_ttl; |
| 361 u_char ip_p; |
| 362 u_short ip_sum; |
| 363 struct in_addr ip_src, ip_dst; |
| 364 }; |
| 365 |
| 366 struct ifaddrs { |
| 367 struct ifaddrs *ifa_next; |
| 368 char *ifa_name; |
| 369 unsigned int ifa_flags; |
| 370 struct sockaddr *ifa_addr; |
| 371 struct sockaddr *ifa_netmask; |
| 372 struct sockaddr *ifa_dstaddr; |
| 373 void *ifa_data; |
| 374 }; |
| 375 |
| 376 struct udphdr { |
| 377 unsigned __int16 uh_sport; |
| 378 unsigned __int16 uh_dport; |
| 379 unsigned __int16 uh_ulen; |
| 380 unsigned __int16 uh_sum; |
| 381 }; |
| 382 |
| 383 #else /* !defined(Userspace_os_Windows) */ |
| 384 #include <sys/cdefs.h> /* needed? added from old __FreeBSD__ */ |
| 385 #include <sys/socket.h> |
| 386 #if defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) |
| 387 #include <pthread.h> |
| 388 #endif |
| 389 typedef pthread_mutex_t userland_mutex_t; |
| 390 typedef pthread_cond_t userland_cond_t; |
| 391 typedef pthread_t userland_thread_t; |
| 392 #endif |
| 393 |
| 394 #define mtx_lock(arg1) |
| 395 #define mtx_unlock(arg1) |
| 396 #define mtx_assert(arg1,arg2) |
| 397 #define MA_OWNED 7 /* sys/mutex.h typically on FreeBSD */ |
| 398 #if !defined(__Userspace_os_FreeBSD) |
| 399 struct mtx {int dummy;}; |
| 400 struct selinfo {int dummy;}; |
| 401 struct sx {int dummy;}; |
| 402 #endif |
| 403 |
| 404 #include <stdio.h> |
| 405 #include <string.h> |
| 406 /* #include <sys/param.h> in FreeBSD defines MSIZE */ |
| 407 /* #include <sys/ktr.h> */ |
| 408 /* #include <sys/systm.h> */ |
| 409 #if defined(__Userspace_os_Windows) |
| 410 #include <user_queue.h> |
| 411 #else |
| 412 #include <sys/queue.h> |
| 413 #endif |
| 414 /* #include <sys/kernel.h> */ |
| 415 /* #include <sys/sysctl.h> */ |
| 416 /* #include <sys/protosw.h> */ |
| 417 /* on FreeBSD, this results in a redefintion of SOCK(BUF)_(UN)LOCK and |
| 418 * uknown type of struct mtx for sb_mtx in struct sockbuf */ |
| 419 /* #include <sys/jail.h> */ |
| 420 /* #include <sys/sysctl.h> */ |
| 421 #include <user_atomic.h> |
| 422 #include <user_environment.h> |
| 423 #include <user_malloc.h> |
| 424 #include <user_mbuf.h> |
| 425 #include "user_socketvar.h" /* MALLOC_DECLARE's M_PCB. Replacement for sys/socke
tvar.h */ |
| 426 /* #include <sys/uio.h> */ |
| 427 /* #include <sys/lock.h> */ |
| 428 #if defined(__FreeBSD__) && __FreeBSD_version > 602000 |
| 429 #include <sys/rwlock.h> |
| 430 #endif |
| 431 /* #include <sys/kthread.h> */ |
| 432 #if defined(__FreeBSD__) && __FreeBSD_version > 602000 |
| 433 #include <sys/priv.h> |
| 434 #endif |
| 435 /* #include <sys/random.h> */ |
| 436 /* #include <sys/limits.h> */ |
| 437 /* #include <machine/cpu.h> */ |
| 438 |
| 439 #if defined(__Userspace_os_Darwin) |
| 440 /* was a 0 byte file. needed for structs if_data(64) and net_event_data */ |
| 441 #include <net/if_var.h> |
| 442 #endif |
| 443 #if defined(__Userspace_os_FreeBSD) |
| 444 #include <net/if_types.h> |
| 445 /* #include <net/if_var.h> was a 0 byte file. causes struct mtx redefinition */ |
| 446 #endif |
| 447 /* OOTB only - dummy route used at the moment. should we port route to |
| 448 * userspace as well? */ |
| 449 /* on FreeBSD, this results in a redefintion of struct route */ |
| 450 /* #include <net/route.h> */ |
| 451 #if !defined(__Userspace_os_Windows) |
| 452 #include <net/if.h> |
| 453 #include <netinet/in.h> |
| 454 #include <netinet/in_systm.h> |
| 455 #include <netinet/ip.h> |
| 456 #include <netinet/ip_icmp.h> |
| 457 #else |
| 458 #include <user_ip_icmp.h> |
| 459 #endif |
| 460 /* #include <netinet/in_pcb.h> ported to userspace */ |
| 461 #include <user_inpcb.h> |
| 462 |
| 463 /* for getifaddrs */ |
| 464 #include <sys/types.h> |
| 465 #if !defined(__Userspace_os_Windows) |
| 466 #include <ifaddrs.h> |
| 467 |
| 468 /* for ioctl */ |
| 469 #include <sys/ioctl.h> |
| 470 |
| 471 /* for close, etc. */ |
| 472 #include <unistd.h> |
| 473 #endif |
| 474 |
| 475 /* lots of errno's used and needed in userspace */ |
| 476 |
| 477 /* for offsetof */ |
| 478 #include <stddef.h> |
| 479 |
| 480 #if defined(SCTP_PROCESS_LEVEL_LOCKS) && !defined(__Userspace_os_Windows) |
| 481 /* for pthread_mutex_lock, pthread_mutex_unlock, etc. */ |
| 482 #include <pthread.h> |
| 483 #endif |
| 484 |
| 485 #ifdef IPSEC |
| 486 #include <netipsec/ipsec.h> |
| 487 #include <netipsec/key.h> |
| 488 #endif /* IPSEC */ |
| 489 |
| 490 #ifdef INET6 |
| 491 #if defined(__Userspace_os_FreeBSD) |
| 492 #include <sys/domain.h> |
| 493 #endif |
| 494 #ifdef IPSEC |
| 495 #include <netipsec/ipsec6.h> |
| 496 #endif |
| 497 #if !defined(__Userspace_os_Windows) |
| 498 #include <netinet/ip6.h> |
| 499 #include <netinet/icmp6.h> |
| 500 #endif |
| 501 #if defined(__Userspace_os_Linux) || defined(__Userspace_os_Darwin) || defined(_
_Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) ||defined(__Userspace_
os_Windows) |
| 502 #include "user_ip6_var.h" |
| 503 #else |
| 504 #include <netinet6/ip6_var.h> |
| 505 #endif |
| 506 #if defined(__Userspace_os_FreeBSD) |
| 507 #include <netinet6/in6_pcb.h> |
| 508 #include <netinet6/ip6protosw.h> |
| 509 /* #include <netinet6/nd6.h> was a 0 byte file */ |
| 510 #include <netinet6/scope6_var.h> |
| 511 #endif |
| 512 #endif /* INET6 */ |
| 513 |
| 514 #if defined(HAVE_SCTP_PEELOFF_SOCKOPT) |
| 515 #include <sys/file.h> |
| 516 #include <sys/filedesc.h> |
| 517 #endif |
| 518 |
| 519 #if __FreeBSD_version >= 700000 |
| 520 #include <netinet/ip_options.h> |
| 521 #endif |
| 522 |
| 523 #define SCTP_PRINTF(...) \ |
| 524 if (SCTP_BASE_VAR(debug_printf)) { \ |
| 525 SCTP_BASE_VAR(debug_printf)(__VA_ARGS__); \ |
| 526 } |
| 527 |
| 528 #if defined(__FreeBSD__) |
| 529 #ifndef in6pcb |
| 530 #define in6pcb inpcb |
| 531 #endif |
| 532 #endif |
| 533 /* Declare all the malloc names for all the various mallocs */ |
| 534 MALLOC_DECLARE(SCTP_M_MAP); |
| 535 MALLOC_DECLARE(SCTP_M_STRMI); |
| 536 MALLOC_DECLARE(SCTP_M_STRMO); |
| 537 MALLOC_DECLARE(SCTP_M_ASC_ADDR); |
| 538 MALLOC_DECLARE(SCTP_M_ASC_IT); |
| 539 MALLOC_DECLARE(SCTP_M_AUTH_CL); |
| 540 MALLOC_DECLARE(SCTP_M_AUTH_KY); |
| 541 MALLOC_DECLARE(SCTP_M_AUTH_HL); |
| 542 MALLOC_DECLARE(SCTP_M_AUTH_IF); |
| 543 MALLOC_DECLARE(SCTP_M_STRESET); |
| 544 MALLOC_DECLARE(SCTP_M_CMSG); |
| 545 MALLOC_DECLARE(SCTP_M_COPYAL); |
| 546 MALLOC_DECLARE(SCTP_M_VRF); |
| 547 MALLOC_DECLARE(SCTP_M_IFA); |
| 548 MALLOC_DECLARE(SCTP_M_IFN); |
| 549 MALLOC_DECLARE(SCTP_M_TIMW); |
| 550 MALLOC_DECLARE(SCTP_M_MVRF); |
| 551 MALLOC_DECLARE(SCTP_M_ITER); |
| 552 MALLOC_DECLARE(SCTP_M_SOCKOPT); |
| 553 |
| 554 #if defined(SCTP_LOCAL_TRACE_BUF) |
| 555 |
| 556 #define SCTP_GET_CYCLECOUNT get_cyclecount() |
| 557 #define SCTP_CTR6 sctp_log_trace |
| 558 |
| 559 #else |
| 560 #define SCTP_CTR6 CTR6 |
| 561 #endif |
| 562 |
| 563 /* Empty ktr statement for _Userspace__ (similar to what is done for mac) */ |
| 564 #define CTR6(m, d, p1, p2, p3, p4, p5, p6) |
| 565 |
| 566 |
| 567 |
| 568 #define SCTP_BASE_INFO(__m) system_base_info.sctppcbinfo.__m |
| 569 #define SCTP_BASE_STATS system_base_info.sctpstat |
| 570 #define SCTP_BASE_STAT(__m) system_base_info.sctpstat.__m |
| 571 #define SCTP_BASE_SYSCTL(__m) system_base_info.sctpsysctl.__m |
| 572 #define SCTP_BASE_VAR(__m) system_base_info.__m |
| 573 |
| 574 /* |
| 575 * |
| 576 */ |
| 577 #if !defined(__Userspace_os_Darwin) |
| 578 #define USER_ADDR_NULL (NULL) /* FIX ME: temp */ |
| 579 #endif |
| 580 |
| 581 #if defined(SCTP_DEBUG) |
| 582 #include <netinet/sctp_constants.h> |
| 583 #define SCTPDBG(level, ...) \ |
| 584 { \ |
| 585 do { \ |
| 586 if (SCTP_BASE_SYSCTL(sctp_debug_on) & level) { \ |
| 587 SCTP_PRINTF(__VA_ARGS__); \ |
| 588 } \ |
| 589 } while (0); \ |
| 590 } |
| 591 #define SCTPDBG_ADDR(level, addr) \ |
| 592 { \ |
| 593 do { \ |
| 594 if (SCTP_BASE_SYSCTL(sctp_debug_on) & level ) {
\ |
| 595 sctp_print_address(addr); \ |
| 596 } \ |
| 597 } while (0); \ |
| 598 } |
| 599 #else |
| 600 #define SCTPDBG(level, ...) |
| 601 #define SCTPDBG_ADDR(level, addr) |
| 602 #endif |
| 603 |
| 604 #ifdef SCTP_LTRACE_CHUNKS |
| 605 #define SCTP_LTRACE_CHK(a, b, c, d) if(sctp_logging_level & SCTP_LTRACE_CHUNK_EN
ABLE) CTR6(KTR_SUBSYS, "SCTP:%d[%d]:%x-%x-%x-%x", SCTP_LOG_CHUNK_PROC, 0, a, b,
c, d) |
| 606 #else |
| 607 #define SCTP_LTRACE_CHK(a, b, c, d) |
| 608 #endif |
| 609 |
| 610 #ifdef SCTP_LTRACE_ERRORS |
| 611 #define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err) \ |
| 612 if (sctp_logging_level & SCTP_LTRACE_ERROR_ENABLE) \ |
| 613 SCTP_PRINTF("mbuf:%p inp:%p stcb:%p net:%p file:%x line:%d error
:%d\n", \ |
| 614 (void *)m, (void *)inp, (void *)stcb, (void *)net, f
ile, __LINE__, err); |
| 615 #define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err) \ |
| 616 if (sctp_logging_level & SCTP_LTRACE_ERROR_ENABLE) \ |
| 617 SCTP_PRINTF("inp:%p stcb:%p net:%p file:%x line:%d error:%d\n",
\ |
| 618 (void *)inp, (void *)stcb, (void *)net, file, __LINE
__, err); |
| 619 #else |
| 620 #define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err) |
| 621 #define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err) |
| 622 #endif |
| 623 |
| 624 |
| 625 /* |
| 626 * Local address and interface list handling |
| 627 */ |
| 628 #define SCTP_MAX_VRF_ID 0 |
| 629 #define SCTP_SIZE_OF_VRF_HASH 3 |
| 630 #define SCTP_IFNAMSIZ IFNAMSIZ |
| 631 #define SCTP_DEFAULT_VRFID 0 |
| 632 #define SCTP_VRF_ADDR_HASH_SIZE 16 |
| 633 #define SCTP_VRF_IFN_HASH_SIZE 3 |
| 634 #define SCTP_INIT_VRF_TABLEID(vrf) |
| 635 |
| 636 #if !defined(__Userspace_os_Windows) |
| 637 #define SCTP_IFN_IS_IFT_LOOP(ifn) (strncmp((ifn)->ifn_name, "lo", 2) == 0) |
| 638 /* BSD definition */ |
| 639 /* #define SCTP_ROUTE_IS_REAL_LOOP(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifa && (r
o)->ro_rt->rt_ifa->ifa_ifp && (ro)->ro_rt->rt_ifa->ifa_ifp->if_type == IFT_LOOP)
*/ |
| 640 /* only used in IPv6 scenario, which isn't supported yet */ |
| 641 #define SCTP_ROUTE_IS_REAL_LOOP(ro) 0 |
| 642 |
| 643 /* |
| 644 * Access to IFN's to help with src-addr-selection |
| 645 */ |
| 646 /* This could return VOID if the index works but for BSD we provide both. */ |
| 647 #define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) (void *)ro->ro_rt->rt_ifp |
| 648 #define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) 1 /* compiles... TODO use routing sock
et to determine */ |
| 649 #define SCTP_ROUTE_HAS_VALID_IFN(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifp) |
| 650 #endif |
| 651 |
| 652 /* |
| 653 * general memory allocation |
| 654 */ |
| 655 #define SCTP_MALLOC(var, type, size, name) \ |
| 656 do { \ |
| 657 MALLOC(var, type, size, name, M_NOWAIT); \ |
| 658 } while (0) |
| 659 |
| 660 #define SCTP_FREE(var, type) FREE(var, type) |
| 661 |
| 662 #define SCTP_MALLOC_SONAME(var, type, size) \ |
| 663 do { \ |
| 664 MALLOC(var, type, size, M_SONAME, (M_WAITOK | M_ZERO)); \ |
| 665 } while (0) |
| 666 |
| 667 #define SCTP_FREE_SONAME(var) FREE(var, M_SONAME) |
| 668 |
| 669 #define SCTP_PROCESS_STRUCT struct proc * |
| 670 |
| 671 /* |
| 672 * zone allocation functions |
| 673 */ |
| 674 |
| 675 |
| 676 #if defined(SCTP_SIMPLE_ALLOCATOR) |
| 677 /*typedef size_t sctp_zone_t;*/ |
| 678 #define SCTP_ZONE_INIT(zone, name, size, number) { \ |
| 679 zone = size; \ |
| 680 } |
| 681 |
| 682 /* __Userspace__ SCTP_ZONE_GET: allocate element from the zone */ |
| 683 #define SCTP_ZONE_GET(zone, type) \ |
| 684 (type *)malloc(zone); |
| 685 |
| 686 |
| 687 /* __Userspace__ SCTP_ZONE_FREE: free element from the zone */ |
| 688 #define SCTP_ZONE_FREE(zone, element) { \ |
| 689 free(element); \ |
| 690 } |
| 691 |
| 692 #define SCTP_ZONE_DESTROY(zone) |
| 693 #else |
| 694 /*__Userspace__ |
| 695 Compiling & linking notes: Needs libumem, which has been placed in ./user_lib |
| 696 All userspace header files are in ./user_include. Makefile will need the |
| 697 following. |
| 698 CFLAGS = -I./ -Wall |
| 699 LDFLAGS = -L./user_lib -R./user_lib -lumem |
| 700 */ |
| 701 #include "user_include/umem.h" |
| 702 |
| 703 /* __Userspace__ SCTP_ZONE_INIT: initialize the zone */ |
| 704 /* |
| 705 __Userspace__ |
| 706 No equivalent function to uma_zone_set_max added yet. (See SCTP_ZONE_INIT in s
ctp_os_bsd.h |
| 707 for reference). It may not be required as mentioned in |
| 708 http://nixdoc.net/man-pages/FreeBSD/uma_zalloc.9.html that |
| 709 max limits may not enforced on systems with more than one CPU. |
| 710 */ |
| 711 #define SCTP_ZONE_INIT(zone, name, size, number) { \ |
| 712 zone = umem_cache_create(name, size, 0, NULL, NULL, NULL, NULL, NULL, 0)
; \ |
| 713 } |
| 714 |
| 715 /* __Userspace__ SCTP_ZONE_GET: allocate element from the zone */ |
| 716 #define SCTP_ZONE_GET(zone, type) \ |
| 717 (type *)umem_cache_alloc(zone, UMEM_DEFAULT); |
| 718 |
| 719 |
| 720 /* __Userspace__ SCTP_ZONE_FREE: free element from the zone */ |
| 721 #define SCTP_ZONE_FREE(zone, element) \ |
| 722 umem_cache_free(zone, element); |
| 723 |
| 724 |
| 725 /* __Userspace__ SCTP_ZONE_DESTROY: destroy the zone */ |
| 726 #define SCTP_ZONE_DESTROY(zone) \ |
| 727 umem_cache_destroy(zone); |
| 728 #endif |
| 729 |
| 730 /* global struct ifaddrs used in sctp_init_ifns_for_vrf getifaddrs call |
| 731 * but references to fields are needed to persist as the vrf is queried. |
| 732 * getifaddrs allocates memory that needs to be freed with a freeifaddrs |
| 733 * call; this global is used to call freeifaddrs upon in sctp_pcb_finish |
| 734 */ |
| 735 extern struct ifaddrs *g_interfaces; |
| 736 |
| 737 |
| 738 /* |
| 739 * __Userspace__ Defining sctp_hashinit_flags() and sctp_hashdestroy() for userl
and. |
| 740 */ |
| 741 void *sctp_hashinit_flags(int elements, struct malloc_type *type, |
| 742 u_long *hashmask, int flags); |
| 743 void |
| 744 sctp_hashdestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask); |
| 745 |
| 746 void |
| 747 sctp_hashfreedestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask); |
| 748 |
| 749 |
| 750 #define HASH_NOWAIT 0x00000001 |
| 751 #define HASH_WAITOK 0x00000002 |
| 752 |
| 753 /* M_PCB is MALLOC_DECLARE'd in sys/socketvar.h */ |
| 754 #define SCTP_HASH_INIT(size, hashmark) sctp_hashinit_flags(size, M_PCB, hashmark
, HASH_NOWAIT) |
| 755 |
| 756 #define SCTP_HASH_FREE(table, hashmark) sctp_hashdestroy(table, M_PCB, hashmark) |
| 757 |
| 758 #define SCTP_HASH_FREE_DESTROY(table, hashmark) sctp_hashfreedestroy(table, M_P
CB, hashmark) |
| 759 #define SCTP_M_COPYM m_copym |
| 760 |
| 761 /* |
| 762 * timers |
| 763 */ |
| 764 /* __Userspace__ |
| 765 * user_sctp_callout.h has typedef struct sctp_callout sctp_os_timer_t; |
| 766 * which is used in the timer related functions such as |
| 767 * SCTP_OS_TIMER_INIT etc. |
| 768 */ |
| 769 #include <netinet/sctp_callout.h> |
| 770 |
| 771 /* __Userspace__ Creating a receive thread */ |
| 772 #include <user_recv_thread.h> |
| 773 |
| 774 /*__Userspace__ defining KTR_SUBSYS 1 as done in sctp_os_macosx.h */ |
| 775 #define KTR_SUBSYS 1 |
| 776 |
| 777 #define sctp_get_tick_count() (ticks) |
| 778 |
| 779 /* The packed define for 64 bit platforms */ |
| 780 #if !defined(__Userspace_os_Windows) |
| 781 #define SCTP_PACKED __attribute__((packed)) |
| 782 #define SCTP_UNUSED __attribute__((unused)) |
| 783 #else |
| 784 #define SCTP_PACKED |
| 785 #define SCTP_UNUSED |
| 786 #endif |
| 787 |
| 788 /* |
| 789 * Functions |
| 790 */ |
| 791 /* Mbuf manipulation and access macros */ |
| 792 #define SCTP_BUF_LEN(m) (m->m_len) |
| 793 #define SCTP_BUF_NEXT(m) (m->m_next) |
| 794 #define SCTP_BUF_NEXT_PKT(m) (m->m_nextpkt) |
| 795 #define SCTP_BUF_RESV_UF(m, size) m->m_data += size |
| 796 #define SCTP_BUF_AT(m, size) m->m_data + size |
| 797 #define SCTP_BUF_IS_EXTENDED(m) (m->m_flags & M_EXT) |
| 798 #define SCTP_BUF_EXTEND_SIZE(m) (m->m_ext.ext_size) |
| 799 #define SCTP_BUF_TYPE(m) (m->m_type) |
| 800 #define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif) |
| 801 #define SCTP_BUF_PREPEND M_PREPEND |
| 802 |
| 803 #define SCTP_ALIGN_TO_END(m, len) if(m->m_flags & M_PKTHDR) { \ |
| 804 MH_ALIGN(m, len); \ |
| 805 } else if ((m->m_flags & M_EXT) == 0) { \ |
| 806 M_ALIGN(m, len); \ |
| 807 } |
| 808 |
| 809 /* We make it so if you have up to 4 threads |
| 810 * writting based on the default size of |
| 811 * the packet log 65 k, that would be |
| 812 * 4 16k packets before we would hit |
| 813 * a problem. |
| 814 */ |
| 815 #define SCTP_PKTLOG_WRITERS_NEED_LOCK 3 |
| 816 |
| 817 |
| 818 /* |
| 819 * routes, output, etc. |
| 820 */ |
| 821 |
| 822 typedef struct sctp_route sctp_route_t; |
| 823 typedef struct sctp_rtentry sctp_rtentry_t; |
| 824 |
| 825 static inline void sctp_userspace_rtalloc(sctp_route_t *ro) |
| 826 { |
| 827 if (ro->ro_rt != NULL) { |
| 828 ro->ro_rt->rt_refcnt++; |
| 829 return; |
| 830 } |
| 831 |
| 832 ro->ro_rt = (sctp_rtentry_t *) malloc(sizeof(sctp_rtentry_t)); |
| 833 if (ro->ro_rt == NULL) |
| 834 return; |
| 835 |
| 836 /* initialize */ |
| 837 memset(ro->ro_rt, 0, sizeof(sctp_rtentry_t)); |
| 838 ro->ro_rt->rt_refcnt = 1; |
| 839 |
| 840 /* set MTU */ |
| 841 /* TODO set this based on the ro->ro_dst, looking up MTU with routing so
cket */ |
| 842 #if 0 |
| 843 if (userspace_rawroute == -1) { |
| 844 userspace_rawroute = socket(AF_ROUTE, SOCK_RAW, 0); |
| 845 if (userspace_rawroute == -1) |
| 846 return; |
| 847 } |
| 848 #endif |
| 849 ro->ro_rt->rt_rmx.rmx_mtu = 1500; /* FIXME temporary solution */ |
| 850 |
| 851 /* TODO enable the ability to obtain interface index of route for |
| 852 * SCTP_GET_IF_INDEX_FROM_ROUTE macro. |
| 853 */ |
| 854 } |
| 855 #define SCTP_RTALLOC(ro, vrf_id) sctp_userspace_rtalloc((sctp_route_t *)ro) |
| 856 |
| 857 /* dummy rtfree needed once user_route.h is included */ |
| 858 static inline void sctp_userspace_rtfree(sctp_rtentry_t *rt) |
| 859 { |
| 860 if(rt == NULL) { |
| 861 return; |
| 862 } |
| 863 if(--rt->rt_refcnt > 0) { |
| 864 return; |
| 865 } |
| 866 free(rt); |
| 867 rt = NULL; |
| 868 } |
| 869 #define rtfree(arg1) sctp_userspace_rtfree(arg1) |
| 870 |
| 871 |
| 872 /*************************/ |
| 873 /* MTU */ |
| 874 /*************************/ |
| 875 int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af); |
| 876 |
| 877 #define SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index, af) sctp_userspace_get_mtu
_from_ifn(ifn_index, af) |
| 878 |
| 879 #define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((rt != NULL) ? rt->rt_rmx.
rmx_mtu : 0) |
| 880 |
| 881 #define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) sctp_userspace_get_mtu_from_ifn(if
_nametoindex(((struct ifaddrs *) (sctp_ifn))->ifa_name), AF_INET) |
| 882 |
| 883 #define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \ |
| 884 if (rt != NULL) \ |
| 885 rt->rt_rmx.rmx_mtu = mtu; \ |
| 886 } while(0) |
| 887 |
| 888 /* (de-)register interface event notifications */ |
| 889 #define SCTP_REGISTER_INTERFACE(ifhandle, af) |
| 890 #define SCTP_DEREGISTER_INTERFACE(ifhandle, af) |
| 891 |
| 892 |
| 893 /*************************/ |
| 894 /* These are for logging */ |
| 895 /*************************/ |
| 896 /* return the base ext data pointer */ |
| 897 #define SCTP_BUF_EXTEND_BASE(m) (m->m_ext.ext_buf) |
| 898 /* return the refcnt of the data pointer */ |
| 899 #define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ref_cnt) |
| 900 /* return any buffer related flags, this is |
| 901 * used beyond logging for apple only. |
| 902 */ |
| 903 #define SCTP_BUF_GET_FLAGS(m) (m->m_flags) |
| 904 |
| 905 /* For BSD this just accesses the M_PKTHDR length |
| 906 * so it operates on an mbuf with hdr flag. Other |
| 907 * O/S's may have seperate packet header and mbuf |
| 908 * chain pointers.. thus the macro. |
| 909 */ |
| 910 #define SCTP_HEADER_TO_CHAIN(m) (m) |
| 911 #define SCTP_DETACH_HEADER_FROM_CHAIN(m) |
| 912 #define SCTP_HEADER_LEN(m) ((m)->m_pkthdr.len) |
| 913 #define SCTP_GET_HEADER_FOR_OUTPUT(o_pak) 0 |
| 914 #define SCTP_RELEASE_HEADER(m) |
| 915 #define SCTP_RELEASE_PKT(m) sctp_m_freem(m) |
| 916 /* UDP __Userspace__ - dummy definition */ |
| 917 #define SCTP_ENABLE_UDP_CSUM(m) m=m |
| 918 /* BSD definition */ |
| 919 /* #define SCTP_ENABLE_UDP_CSUM(m) do { \ */ |
| 920 /* m->m_pkthdr.csum_flags = CSUM_UDP; \
*/ |
| 921 /* m->m_pkthdr.csum_data = offsetof(stru
ct udphdr, uh_sum); \ */ |
| 922 /* } while (0) */ |
| 923 |
| 924 #define SCTP_GET_PKT_VRFID(m, vrf_id) ((vrf_id = SCTP_DEFAULT_VRFID) != SCTP_DE
FAULT_VRFID) |
| 925 |
| 926 |
| 927 |
| 928 /* Attach the chain of data into the sendable packet. */ |
| 929 #define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \ |
| 930 pak = m; \ |
| 931 pak->m_pkthdr.len = packet_len
gth; \ |
| 932 } while(0) |
| 933 |
| 934 /* Other m_pkthdr type things */ |
| 935 /* FIXME need real definitions */ |
| 936 #define SCTP_IS_IT_BROADCAST(dst, m) 0 |
| 937 /* OOTB only #define SCTP_IS_IT_BROADCAST(dst, m) ((m->m_flags & M_PKTHDR) ? in_
broadcast(dst, m->m_pkthdr.rcvif) : 0) BSD def */ |
| 938 #define SCTP_IS_IT_LOOPBACK(m) 0 |
| 939 /* OOTB ONLY #define SCTP_IS_IT_LOOPBACK(m) ((m->m_flags & M_PKTHDR) && ((m->m_p
kthdr.rcvif == NULL) || (m->m_pkthdr.rcvif->if_type == IFT_LOOP))) BSD def */ |
| 940 |
| 941 |
| 942 /* This converts any input packet header |
| 943 * into the chain of data holders, for BSD |
| 944 * its a NOP. |
| 945 */ |
| 946 |
| 947 /* get the v6 hop limit */ |
| 948 #define SCTP_GET_HLIM(inp, ro) 128 /* As done for __Windows__ */ |
| 949 #define IPv6_HOP_LIMIT 128 |
| 950 |
| 951 /* is the endpoint v6only? */ |
| 952 #define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6
ONLY) |
| 953 /* is the socket non-blocking? */ |
| 954 #define SCTP_SO_IS_NBIO(so) ((so)->so_state & SS_NBIO) |
| 955 #define SCTP_SET_SO_NBIO(so) ((so)->so_state |= SS_NBIO) |
| 956 #define SCTP_CLEAR_SO_NBIO(so) ((so)->so_state &= ~SS_NBIO) |
| 957 /* get the socket type */ |
| 958 #define SCTP_SO_TYPE(so) ((so)->so_type) |
| 959 |
| 960 /* reserve sb space for a socket */ |
| 961 #define SCTP_SORESERVE(so, send, recv) soreserve(so, send, recv) |
| 962 |
| 963 /* wakeup a socket */ |
| 964 #define SCTP_SOWAKEUP(so) wakeup(&(so)->so_timeo, so) |
| 965 /* clear the socket buffer state */ |
| 966 #define SCTP_SB_CLEAR(sb) \ |
| 967 (sb).sb_cc = 0; \ |
| 968 (sb).sb_mb = NULL; \ |
| 969 (sb).sb_mbcnt = 0; |
| 970 |
| 971 #define SCTP_SB_LIMIT_RCV(so) so->so_rcv.sb_hiwat |
| 972 #define SCTP_SB_LIMIT_SND(so) so->so_snd.sb_hiwat |
| 973 |
| 974 /* Future zero copy wakeup/send function */ |
| 975 #define SCTP_ZERO_COPY_EVENT(inp, so) |
| 976 /* This is re-pulse ourselves for sendbuf */ |
| 977 #define SCTP_ZERO_COPY_SENDQ_EVENT(inp, so) |
| 978 |
| 979 |
| 980 /* |
| 981 * SCTP AUTH |
| 982 */ |
| 983 /* USE_SCTP_SHA1 is defined if you need sctp_sha1.[ch]. SHA1_* functions are de
fined |
| 984 * there. On Linux, they are also defined in libcrypto.a once you install |
| 985 * the libssl-dev package (on Ubuntu, at least). |
| 986 */ |
| 987 /* #define USE_SCTP_SHA1 */ |
| 988 |
| 989 /* #define HAVE_SHA2 sha2.h exists on Linux? */ |
| 990 |
| 991 |
| 992 #define SCTP_READ_RANDOM(buf, len) read_random(buf, len) |
| 993 |
| 994 |
| 995 #include <netinet/sctp_sha1.h> |
| 996 #if 0 /*this was old _KERNEL code... */ |
| 997 #include <crypto/sha1.h> |
| 998 /* map standard crypto API names */ |
| 999 #define SHA1_Init SHA1Init |
| 1000 #define SHA1_Update SHA1Update |
| 1001 #define SHA1_Final(x,y) SHA1Final((caddr_t)x, y) |
| 1002 #endif |
| 1003 |
| 1004 #if defined(HAVE_SHA2) |
| 1005 #include <crypto/sha2/sha2.h> |
| 1006 #endif |
| 1007 #if 0 |
| 1008 /* going to have to port so generic across OS's... */ |
| 1009 #if 1 /* openssl header files on FreeBSD 6.3 on Emulab and libssl-dev for Ubuntu
*/ |
| 1010 #include <openssl/md5.h> |
| 1011 #include <openssl/sha.h> |
| 1012 /* libssl-dev calls this SHA_CTX, but it's refered to as SHA1_CTX within the |
| 1013 * SCTP stack code so here we typedef (or macro?) to equate the two. |
| 1014 */ |
| 1015 typedef SHA_CTX SHA1_CTX; |
| 1016 |
| 1017 #else /* only _KERNEL? */ |
| 1018 |
| 1019 #include <sys/md5.h> |
| 1020 /* map standard crypto API names */ |
| 1021 #define MD5_Init MD5Init |
| 1022 #define MD5_Update MD5Update |
| 1023 #define MD5_Final MD5Final |
| 1024 #endif |
| 1025 #endif |
| 1026 |
| 1027 |
| 1028 /* start OOTB only stuff */ |
| 1029 |
| 1030 |
| 1031 /* TODO IFT_LOOP is in net/if_types.h on Linux */ |
| 1032 #define IFT_LOOP 0x18 |
| 1033 |
| 1034 /* sctp_pcb.h */ |
| 1035 /* typedef int SHA1_CTX; */ |
| 1036 /* typedef int MD5_CTX; */ |
| 1037 #ifdef HAVE_SHA2 |
| 1038 typedef int SHA256_CTX; |
| 1039 typedef int SHA384_CTX; |
| 1040 typedef int SHA512_CTX; |
| 1041 #endif |
| 1042 |
| 1043 #if defined(__Userspace_os_Windows) |
| 1044 #define SHUT_RD 1 |
| 1045 #define SHUT_WR 2 |
| 1046 #define SHUT_RDWR 3 |
| 1047 #endif |
| 1048 #define PRU_FLUSH_RD SHUT_RD |
| 1049 #define PRU_FLUSH_WR SHUT_WR |
| 1050 #define PRU_FLUSH_RDWR SHUT_RDWR |
| 1051 |
| 1052 /* netinet/ip_var.h defintions are behind an if defined for _KERNEL on FreeBSD *
/ |
| 1053 #define IP_RAWOUTPUT 0x2 |
| 1054 |
| 1055 |
| 1056 /* end OOTB only stuff */ |
| 1057 |
| 1058 #define AF_CONN 123 |
| 1059 struct sockaddr_conn { |
| 1060 #ifdef HAVE_SCONN_LEN |
| 1061 uint8_t sconn_len; |
| 1062 #endif |
| 1063 uint8_t sconn_family; |
| 1064 uint16_t sconn_port; |
| 1065 void *sconn_addr; |
| 1066 }; |
| 1067 |
| 1068 /* |
| 1069 * IP output routines |
| 1070 */ |
| 1071 |
| 1072 /* Defining SCTP_IP_ID macro. |
| 1073 In netinet/ip_output.c, we have u_short ip_id; |
| 1074 In netinet/ip_var.h, we have extern u_short ip_id; (enclosed within _KERNEL_
) |
| 1075 See static __inline uint16_t ip_newid(void) in netinet/ip_var.h |
| 1076 */ |
| 1077 #define SCTP_IP_ID(inp) (ip_id) |
| 1078 |
| 1079 /* need sctphdr to get port in SCTP_IP_OUTPUT. sctphdr defined in sctp.h */ |
| 1080 #include <netinet/sctp.h> |
| 1081 extern void sctp_userspace_ip_output(int *result, struct mbuf *o_pak, |
| 1082 sctp_route_t *ro, void *stcb, |
| 1083 uint32_t vrf_id); |
| 1084 |
| 1085 #define SCTP_IP_OUTPUT(result, o_pak, ro, stcb, vrf_id) sctp_userspace_ip_output
(&result, o_pak, ro, stcb, vrf_id); |
| 1086 |
| 1087 #if defined(INET6) |
| 1088 extern void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak, |
| 1089 struct route_in6 *ro, void *stcb, |
| 1090 uint32_t vrf_id); |
| 1091 #define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) sctp_userspace_ip6
_output(&result, o_pak, ro, stcb, vrf_id); |
| 1092 #endif |
| 1093 |
| 1094 |
| 1095 |
| 1096 #if 0 |
| 1097 #define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \ |
| 1098 { \ |
| 1099 if (stcb && stcb->sctp_ep) \ |
| 1100 result = ip6_output(o_pak, \ |
| 1101 ((struct in6pcb *)(stcb->sctp_ep))->in6p_out
putopts, \ |
| 1102 (ro), 0, 0, ifp, NULL); \ |
| 1103 else \ |
| 1104 result = ip6_output(o_pak, NULL, (ro), 0, 0, ifp, NULL); \ |
| 1105 } |
| 1106 #endif |
| 1107 |
| 1108 struct mbuf * |
| 1109 sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
llonebuf, int type); |
| 1110 |
| 1111 |
| 1112 /* with the current included files, this is defined in Linux but |
| 1113 * in FreeBSD, it is behind a _KERNEL in sys/socket.h ... |
| 1114 */ |
| 1115 #if defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) |
| 1116 /* stolen from /usr/include/sys/socket.h */ |
| 1117 #define CMSG_ALIGN(n) _ALIGN(n) |
| 1118 #elif defined(__Userspace_os_Darwin) |
| 1119 #if !defined(__DARWIN_ALIGNBYTES) |
| 1120 #define __DARWIN_ALIGNBYTES (sizeof(__darwin_size_t) - 1) |
| 1121 #endif |
| 1122 |
| 1123 #if !defined(__DARWIN_ALIGN) |
| 1124 #define __DARWIN_ALIGN(p) ((__darwin_size_t)((char *)(uintptr_t)(p) + __DA
RWIN_ALIGNBYTES) &~ __DARWIN_ALIGNBYTES) |
| 1125 #endif |
| 1126 |
| 1127 #if !defined(__DARWIN_ALIGNBYTES32) |
| 1128 #define __DARWIN_ALIGNBYTES32 (sizeof(__uint32_t) - 1) |
| 1129 #endif |
| 1130 |
| 1131 #if !defined(__DARWIN_ALIGN32) |
| 1132 #define __DARWIN_ALIGN32(p) ((__darwin_size_t)((char *)(uintptr_t)(p) + __
DARWIN_ALIGNBYTES32) &~ __DARWIN_ALIGNBYTES32) |
| 1133 #endif |
| 1134 #define CMSG_ALIGN(n) __DARWIN_ALIGN32(n) |
| 1135 #endif |
| 1136 #define I_AM_HERE \ |
| 1137 do { \ |
| 1138 SCTP_PRINTF("%s:%d at %s\n", __FILE__, __LINE__ , __FUNC
TION__); \ |
| 1139 } while (0) |
| 1140 |
| 1141 #ifndef timevalsub |
| 1142 #define timevalsub(tp1, tp2) \ |
| 1143 do { \ |
| 1144 (tp1)->tv_sec -= (tp2)->tv_sec; \ |
| 1145 (tp1)->tv_usec -= (tp2)->tv_usec; \ |
| 1146 if ((tp1)->tv_usec < 0) { \ |
| 1147 (tp1)->tv_sec--; \ |
| 1148 (tp1)->tv_usec += 1000000; \ |
| 1149 } \ |
| 1150 } while (0) |
| 1151 #endif |
| 1152 |
| 1153 #if defined(__Userspace_os_Linux) |
| 1154 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ |
| 1155 for ((var) = ((head)->tqh_first); \ |
| 1156 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ |
| 1157 (var) = (tvar)) |
| 1158 |
| 1159 #define LIST_FOREACH_SAFE(var, head, field, tvar) \ |
| 1160 for ((var) = ((head)->lh_first); \ |
| 1161 (var) && ((tvar) = LIST_NEXT((var), field), 1); \ |
| 1162 (var) = (tvar)) |
| 1163 #endif |
| 1164 #endif |
OLD | NEW |