Coverage Report

Created: 2026-01-10 06:57

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