merge official v8.6.1

This commit is contained in:
luvletter2333 2022-03-13 22:48:25 +08:00
commit fa5b44b51e
No known key found for this signature in database
GPG Key ID: A26A8880836E1978
2447 changed files with 155597 additions and 61357 deletions

View File

@ -3,15 +3,15 @@ import cn.hutool.core.util.RuntimeUtil
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
def verName = "8.5.4"
def verCode = 581
def verName = "8.6.1-preview01"
def verCode = 600
if (System.getenv("DEBUG_BUILD") == "true") {
verName += "-" + RuntimeUtil.execForStr("git log --pretty=format:'%h' -n 1").trim()
}
def officialVer = "8.5.4"
def officialCode = 2566
def officialVer = "8.6.1"
def officialCode = 2594
def serviceAccountCredentialsFile = rootProject.file("service_account_credentials.json")

View File

@ -462,7 +462,7 @@ target_compile_definitions(sqlite PUBLIC
#voip
include(${CMAKE_HOME_DIRECTORY}/voip/CMakeLists.txt)
set(NATIVE_LIB "tmessages.41")
set(NATIVE_LIB "tmessages.42")
#tmessages
add_library(${NATIVE_LIB} SHARED

View File

@ -54,7 +54,7 @@ static TexturedShape powerful_mask, powerful_infinity, powerful_infinity_white;
static Shape private_bg;
static TexturedShape telegram_sphere, telegram_plane;
static TexturedShape telegram_sphere, telegram_plane, telegram_mask;
static Shape cloud_bg;
@ -72,7 +72,7 @@ static mat4x4 ribbons_layer;
static TexturedShape ic_bubble_dot, ic_bubble, ic_cam_lens, ic_cam, ic_pencil, ic_pin, ic_smile_eye, ic_smile, ic_videocam;
static GLuint ic_bubble_dot_texture, ic_bubble_texture, ic_cam_lens_texture, ic_cam_texture, ic_pencil_texture, ic_pin_texture, ic_smile_eye_texture, ic_smile_texture, ic_videocam_texture;
static GLuint telegram_sphere_texture, telegram_plane_texture;
static GLuint telegram_sphere_texture, telegram_plane_texture, telegram_mask_texture;
static GLuint fast_spiral_texture, fast_body_texture, fast_arrow_texture, fast_arrow_shadow_texture;
static GLuint free_knot_up_texture, free_knot_down_texture;
static GLuint powerful_mask_texture, powerful_star_texture, powerful_infinity_texture, powerful_infinity_white_texture;
@ -105,6 +105,7 @@ static float scroll_offset;
static float calculated_speedometer_sin;
float ms0_anim;
int fps_anim;
int last_stars_update_fps;
int count_anim_fps;
static float speedometer_scroll_offset = 0, free_scroll_offset = 0, private_scroll_offset = 0;
float anim_pencil_start_time, anim_pencil_start_all_time, anim_pencil_start_all_end_time;
@ -125,6 +126,8 @@ static int32_t anim_pencil_period;
static mat4x4 private_matrix;
float cloud_scroll_offset;
vec4 background_color = {1, 1, 1, 1};
static inline void vec2_add(vec2 r, vec2 a, vec2 b) {
int32_t i;
for (i = 0; i < 2; ++i) {
@ -1122,6 +1125,8 @@ xyz star_initial_position(int32_t randZ, int32_t forward) {
}
void draw_stars() {
int update = last_stars_update_fps != fps_anim;
last_stars_update_fps = fps_anim;
float k = (float) width / (float) height;
set_y_offset_objects(-100 * k * 0);
@ -1137,7 +1142,9 @@ void draw_stars() {
}
float speed = stars_scroll_offset + transition_speed;
stars[i].position.z += speed;
if (update) {
stars[i].position.z += speed;
}
if (stars[i].position.z > 0 && speed > 0) {
stars[i].position = star_initial_position(0, 1);
@ -1682,8 +1689,24 @@ void draw_safe(int32_t type, float alpha, float screw_alpha) {
draw_textured_shape(&private_screw, private_matrix, NORMAL_ONE);
}
JNIEXPORT void Java_org_telegram_messenger_Intro_onDrawFrame(JNIEnv *env, jclass class) {
time_local += 0.016f;
JNIEXPORT void Java_org_telegram_messenger_Intro_setBackgroundColor(JNIEnv *env, jclass class, jfloat r, jfloat g, jfloat b, jfloat a) {
background_color[0] = r;
background_color[1] = g;
background_color[2] = b;
background_color[3] = a;
cloud_cover = create_rectangle(CSizeMake(240, 100), background_color);
cloud_cover.params.anchor.y = -50;
TexturedShape was_mask = powerful_mask;
powerful_mask = create_textured_rectangle(CSizeMake(200, 200), powerful_mask_texture);
powerful_mask.params = was_mask.params;
telegram_mask = create_textured_rectangle(CSizeMake(200, 150), telegram_mask_texture);
}
JNIEXPORT void Java_org_telegram_messenger_Intro_onDrawFrame(JNIEnv *env, jclass class, jint deltaMs) {
time_local += (float) deltaMs / 1000;
if (current_page != prev_page) {
reset_ic();
@ -1722,7 +1745,8 @@ JNIEXPORT void Java_org_telegram_messenger_Intro_onDrawFrame(JNIEnv *env, jclass
}
}
fps_anim++;
// Normalize if FPS is greater than 60
fps_anim = (int)(time_local / 0.016f);
if (count_anim_fps == 1 && date - ms0_anim >= duration_const) {
count_anim_fps = 0;
}
@ -1735,7 +1759,7 @@ JNIEXPORT void Java_org_telegram_messenger_Intro_onDrawFrame(JNIEnv *env, jclass
float private_back_k = .8;
glClearColor(1, 1, 1, 1);
glClearColor(background_color[0], background_color[1], background_color[2], background_color[3]);
glClear(GL_COLOR_BUFFER_BIT);
@ -2140,15 +2164,16 @@ JNIEXPORT void Java_org_telegram_messenger_Intro_onDrawFrame(JNIEnv *env, jclass
draw_textured_shape(&telegram_sphere, main_matrix, NORMAL);
float tt = MINf(0, (float) (-M_PI * 125.0f / 180.0f + time * M_PI * 2 * 1.5f));
float dx = sinf(tt) * 75;
float dy = -sinf(tt) * 60;
float dx = t(-75, 0, 0, 0.15f, EaseIn);
float dy = t(75, 0, 0, 0.15f, EaseIn);
telegram_plane.params.position = xyzMake(dx, dy, 0);
float scale = (cosf(tt) + 1) * 0.5f;
telegram_plane.params.scale = xyzMake(cosf(tt) * scale, scale, 1);
float scale = t(0.1f, 1, 0.03f, 0.15f, EaseOut);
telegram_plane.params.scale = xyzMake(scale, scale, 1);
if (tt < D2R(125)) {
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
draw_textured_shape(&telegram_plane, main_matrix, NORMAL_ONE);
draw_textured_shape(&telegram_mask, main_matrix, NORMAL);
}
}
} else if (current_page == 1) {
@ -2159,18 +2184,18 @@ JNIEXPORT void Java_org_telegram_messenger_Intro_onDrawFrame(JNIEnv *env, jclass
double tt = time * M_PI * 2 * 1.5f;
float dx = (float) sin(tt) * 75;
float dy = (float) -sin(tt) * 60;
float dx = t(0, 75, 0, 0.15f, EaseOut);
float dy = t(0, -75, 0, 0.15f, EaseOut);
telegram_plane.params.position = xyzMake(dx, dy, 0);
float scale = (float) (cos(tt) + 1) * 0.5f;
telegram_plane.params.scale = xyzMake((float) cos(tt) * scale, scale, 1);
float scale = t(1, 0.1f, 0.03f, 0.15f, EaseOut);
telegram_plane.params.scale = xyzMake(scale, scale, 1);
if (tt < D2R(125)) {
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
draw_textured_shape(&telegram_plane, main_matrix, NORMAL_ONE);
draw_textured_shape(&telegram_mask, main_matrix, NORMAL);
}
}
} else if (current_page == 2) {
@ -2601,9 +2626,10 @@ JNIEXPORT void Java_org_telegram_messenger_Intro_setIcTextures(JNIEnv *env, jcla
ic_videocam_texture = a_ic_videocam;
}
JNIEXPORT void Java_org_telegram_messenger_Intro_setTelegramTextures(JNIEnv *env, jclass class, GLuint a_telegram_sphere, GLuint a_telegram_plane) {
JNIEXPORT void Java_org_telegram_messenger_Intro_setTelegramTextures(JNIEnv *env, jclass class, GLuint a_telegram_sphere, GLuint a_telegram_plane, GLuint a_telegram_mask) {
telegram_sphere_texture = a_telegram_sphere;
telegram_plane_texture = a_telegram_plane;
telegram_mask_texture = a_telegram_mask;
}
JNIEXPORT void Java_org_telegram_messenger_Intro_setFastTextures(JNIEnv *env, jclass class, GLuint a_fast_body, GLuint a_fast_spiral, GLuint a_fast_arrow, GLuint a_fast_arrow_shadow) {
@ -2691,6 +2717,7 @@ JNIEXPORT void Java_org_telegram_messenger_Intro_onSurfaceCreated(JNIEnv *env, j
mask1 = create_rounded_rectangle(CSizeMake(60, 60), 0, 16, black_color);
telegram_sphere = create_textured_rectangle(CSizeMake(150, 150), telegram_sphere_texture);
telegram_mask = create_textured_rectangle(CSizeMake(200, 150), telegram_mask_texture);
telegram_plane = create_textured_rectangle(CSizeMake(82, 74), telegram_plane_texture);
telegram_plane.params.anchor = xyzMake(6, -5, 0);
@ -2794,7 +2821,7 @@ JNIEXPORT void Java_org_telegram_messenger_Intro_onSurfaceCreated(JNIEnv *env, j
cloud_extra_mask3 = create_circle(1, cloud_polygons_count, black_color);
cloud_extra_mask4 = create_circle(1, cloud_polygons_count, black_color);
cloud_cover = create_rectangle(CSizeMake(240, 100), white_color);
cloud_cover = create_rectangle(CSizeMake(240, 100), background_color);
cloud_cover.params.anchor.y = -50;
vec4 cloud_color = {42 / 255.0f, 180 / 255.0f, 247 / 255.0f, 1};

View File

@ -1,289 +1,11 @@
From cdc55ea354ab977ea2f94ea74fad0561b3a8fd93 Mon Sep 17 00:00:00 2001
From: thermatk <thermatk@thermatk.com>
Date: Sat, 26 Jun 2021 16:56:55 +0200
Subject: [PATCH] [PATCH] Compilation magic 2
---
libavcodec/get_bits.h | 221 ++--------------------------------
libavcodec/golomb.h | 269 ------------------------------------------
2 files changed, 13 insertions(+), 477 deletions(-)
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index 66fb877..a0695d3 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -29,13 +29,9 @@
#include <stdint.h>
-#include "libavutil/common.h"
-#include "libavutil/intreadwrite.h"
-#include "libavutil/log.h"
-#include "libavutil/avassert.h"
-#include "avcodec.h"
-#include "mathops.h"
-#include "vlc.h"
+#ifndef NEG_USR32
+# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
+#endif
/*
* Safe bitstream reading:
@@ -313,66 +309,6 @@ static inline void skip_remaining(GetBitContext *s, unsigned n)
}
#endif
-/**
- * Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
- * if MSB not set it is negative
- * @param n length in bits
- */
-static inline int get_xbits(GetBitContext *s, int n)
-{
-#if CACHED_BITSTREAM_READER
- int32_t cache = show_bits(s, 32);
- int sign = ~cache >> 31;
- skip_remaining(s, n);
-
- return ((((uint32_t)(sign ^ cache)) >> (32 - n)) ^ sign) - sign;
-#else
- register int sign;
- register int32_t cache;
- OPEN_READER(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE(re, s);
- cache = GET_CACHE(re, s);
- sign = ~cache >> 31;
- LAST_SKIP_BITS(re, s, n);
- CLOSE_READER(re, s);
- return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
-#endif
-}
-
-#if !CACHED_BITSTREAM_READER
-static inline int get_xbits_le(GetBitContext *s, int n)
-{
- register int sign;
- register int32_t cache;
- OPEN_READER(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE_LE(re, s);
- cache = GET_CACHE(re, s);
- sign = sign_extend(~cache, n) >> 31;
- LAST_SKIP_BITS(re, s, n);
- CLOSE_READER(re, s);
- return (zero_extend(sign ^ cache, n) ^ sign) - sign;
-}
-#endif
-
-static inline int get_sbits(GetBitContext *s, int n)
-{
- register int tmp;
-#if CACHED_BITSTREAM_READER
- av_assert2(n>0 && n<=25);
- tmp = sign_extend(get_bits(s, n), n);
-#else
- OPEN_READER(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE(re, s);
- tmp = SHOW_SBITS(re, s, n);
- LAST_SKIP_BITS(re, s, n);
- CLOSE_READER(re, s);
-#endif
- return tmp;
-}
-
/**
* Read 1-25 bits.
*/
@@ -409,61 +345,6 @@ static inline unsigned int get_bits(GetBitContext *s, int n)
return tmp;
}
-/**
- * Read 0-25 bits.
- */
-static av_always_inline int get_bitsz(GetBitContext *s, int n)
-{
- return n ? get_bits(s, n) : 0;
-}
-
-static inline unsigned int get_bits_le(GetBitContext *s, int n)
-{
-#if CACHED_BITSTREAM_READER
- av_assert2(n>0 && n<=32);
- if (n > s->bits_left) {
- refill_32(s, 1);
- if (s->bits_left < 32)
- s->bits_left = n;
- }
-
- return get_val(s, n, 1);
-#else
- register int tmp;
- OPEN_READER(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE_LE(re, s);
- tmp = SHOW_UBITS_LE(re, s, n);
- LAST_SKIP_BITS(re, s, n);
- CLOSE_READER(re, s);
- return tmp;
-#endif
-}
-
-/**
- * Show 1-25 bits.
- */
-static inline unsigned int show_bits(GetBitContext *s, int n)
-{
- register unsigned int tmp;
-#if CACHED_BITSTREAM_READER
- if (n > s->bits_left)
-#ifdef BITSTREAM_READER_LE
- refill_32(s, 1);
-#else
- refill_32(s, 0);
-#endif
-
- tmp = show_val(s, n);
-#else
- OPEN_READER_NOSIZE(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE(re, s);
- tmp = SHOW_UBITS(re, s, n);
-#endif
- return tmp;
-}
-
static inline void skip_bits(GetBitContext *s, int n)
{
#if CACHED_BITSTREAM_READER
@@ -530,11 +411,6 @@ static inline unsigned int get_bits1(GetBitContext *s)
#endif
}
-static inline unsigned int show_bits1(GetBitContext *s)
-{
- return show_bits(s, 1);
-}
-
static inline void skip_bits1(GetBitContext *s)
{
skip_bits(s, 1);
@@ -584,31 +460,6 @@ static inline uint64_t get_bits64(GetBitContext *s, int n)
}
}
-/**
- * Read 0-32 bits as a signed integer.
- */
-static inline int get_sbits_long(GetBitContext *s, int n)
-{
- // sign_extend(x, 0) is undefined
- if (!n)
- return 0;
-
- return sign_extend(get_bits_long(s, n), n);
-}
-
-/**
- * Show 0-32 bits.
- */
-static inline unsigned int show_bits_long(GetBitContext *s, int n)
-{
- if (n <= MIN_CACHE_BITS) {
- return show_bits(s, n);
- } else {
- GetBitContext gb = *s;
- return get_bits_long(&gb, n);
- }
-}
-
static inline int check_marker(void *logctx, GetBitContext *s, const char *msg)
{
int bit = get_bits1(s);
@@ -772,62 +623,6 @@ static inline const uint8_t *align_get_bits(GetBitContext *s)
SKIP_BITS(name, gb, n); \
} while (0)
-/* Return the LUT element for the given bitstream configuration. */
-static inline int set_idx(GetBitContext *s, int code, int *n, int *nb_bits,
- VLC_TYPE (*table)[2])
-{
- unsigned idx;
-
- *nb_bits = -*n;
- idx = show_bits(s, *nb_bits) + code;
- *n = table[idx][1];
-
- return table[idx][0];
-}
-
-/**
- * Parse a vlc code.
- * @param bits is the number of bits which will be read at once, must be
- * identical to nb_bits in init_vlc()
- * @param max_depth is the number of times bits bits must be read to completely
- * read the longest vlc code
- * = (max_vlc_length + bits - 1) / bits
- * @returns the code parsed or -1 if no vlc matches
- */
-static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
- int bits, int max_depth)
-{
-#if CACHED_BITSTREAM_READER
- int nb_bits;
- unsigned idx = show_bits(s, bits);
- int code = table[idx][0];
- int n = table[idx][1];
-
- if (max_depth > 1 && n < 0) {
- skip_remaining(s, bits);
- code = set_idx(s, code, &n, &nb_bits, table);
- if (max_depth > 2 && n < 0) {
- skip_remaining(s, nb_bits);
- code = set_idx(s, code, &n, &nb_bits, table);
- }
- }
- skip_remaining(s, n);
-
- return code;
-#else
- int code;
-
- OPEN_READER(re, s);
- UPDATE_CACHE(re, s);
-
- GET_VLC(code, re, s, table, bits, max_depth);
-
- CLOSE_READER(re, s);
-
- return code;
-#endif
-}
-
static inline int decode012(GetBitContext *gb)
{
int n;
@@ -865,4 +660,14 @@ static inline int skip_1stop_8data_bits(GetBitContext *gb)
return 0;
}
+static inline unsigned int show_bits_long(GetBitContext *s, int n)
+{
+ if (n <= MIN_CACHE_BITS) {
+ return show_bits(s, n);
+ } else {
+ GetBitContext gb = *s;
+ return get_bits_long(&gb, n);
+ }
+}
+
#endif /* AVCODEC_GET_BITS_H */
Index: libavcodec/golomb.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
index 7fd46a9..637111a 100644
--- a/libavcodec/golomb.h
+++ b/libavcodec/golomb.h
--- a/libavcodec/golomb.h (revision a77521cd5d27e955b16e8097eecefc779ffdcb6d)
+++ b/libavcodec/golomb.h (date 1647179346628)
@@ -33,7 +33,6 @@
#include <stdint.h>
@ -292,7 +14,7 @@ index 7fd46a9..637111a 100644
#define INVALID_VLC 0x80000000
@@ -422,144 +421,6 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit,
@@ -422,144 +421,6 @@
#endif
}
@ -437,7 +159,7 @@ index 7fd46a9..637111a 100644
#ifdef TRACE
static inline int get_ue(GetBitContext *s, const char *file, const char *func,
@@ -614,134 +475,4 @@ static inline int get_te(GetBitContext *s, int r, char *file, const char *func,
@@ -614,134 +475,4 @@
#endif /* TRACE */
@ -572,6 +294,287 @@ index 7fd46a9..637111a 100644
-}
-
#endif /* AVCODEC_GOLOMB_H */
--
2.32.0
Index: libavcodec/get_bits.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
--- a/libavcodec/get_bits.h (revision a77521cd5d27e955b16e8097eecefc779ffdcb6d)
+++ b/libavcodec/get_bits.h (date 1647179363911)
@@ -29,13 +29,9 @@
#include <stdint.h>
-#include "libavutil/common.h"
-#include "libavutil/intreadwrite.h"
-#include "libavutil/log.h"
-#include "libavutil/avassert.h"
-#include "avcodec.h"
-#include "mathops.h"
-#include "vlc.h"
+#ifndef NEG_USR32
+# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
+#endif
/*
* Safe bitstream reading:
@@ -312,73 +308,13 @@
s->bits_left -= n;
}
#endif
-
-/**
- * Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
- * if MSB not set it is negative
- * @param n length in bits
- */
-static inline int get_xbits(GetBitContext *s, int n)
-{
-#if CACHED_BITSTREAM_READER
- int32_t cache = show_bits(s, 32);
- int sign = ~cache >> 31;
- skip_remaining(s, n);
-
- return ((((uint32_t)(sign ^ cache)) >> (32 - n)) ^ sign) - sign;
-#else
- register int sign;
- register int32_t cache;
- OPEN_READER(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE(re, s);
- cache = GET_CACHE(re, s);
- sign = ~cache >> 31;
- LAST_SKIP_BITS(re, s, n);
- CLOSE_READER(re, s);
- return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
-#endif
-}
-
-#if !CACHED_BITSTREAM_READER
-static inline int get_xbits_le(GetBitContext *s, int n)
-{
- register int sign;
- register int32_t cache;
- OPEN_READER(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE_LE(re, s);
- cache = GET_CACHE(re, s);
- sign = sign_extend(~cache, n) >> 31;
- LAST_SKIP_BITS(re, s, n);
- CLOSE_READER(re, s);
- return (zero_extend(sign ^ cache, n) ^ sign) - sign;
-}
-#endif
-
-static inline int get_sbits(GetBitContext *s, int n)
-{
- register int tmp;
-#if CACHED_BITSTREAM_READER
- av_assert2(n>0 && n<=25);
- tmp = sign_extend(get_bits(s, n), n);
-#else
- OPEN_READER(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE(re, s);
- tmp = SHOW_SBITS(re, s, n);
- LAST_SKIP_BITS(re, s, n);
- CLOSE_READER(re, s);
-#endif
- return tmp;
-}
/**
* Read 1-25 bits.
*/
static inline unsigned int get_bits(GetBitContext *s, int n)
{
- register unsigned int tmp;
+ unsigned int tmp;
#if CACHED_BITSTREAM_READER
av_assert2(n>0 && n<=32);
@@ -409,61 +345,6 @@
return tmp;
}
-/**
- * Read 0-25 bits.
- */
-static av_always_inline int get_bitsz(GetBitContext *s, int n)
-{
- return n ? get_bits(s, n) : 0;
-}
-
-static inline unsigned int get_bits_le(GetBitContext *s, int n)
-{
-#if CACHED_BITSTREAM_READER
- av_assert2(n>0 && n<=32);
- if (n > s->bits_left) {
- refill_32(s, 1);
- if (s->bits_left < 32)
- s->bits_left = n;
- }
-
- return get_val(s, n, 1);
-#else
- register int tmp;
- OPEN_READER(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE_LE(re, s);
- tmp = SHOW_UBITS_LE(re, s, n);
- LAST_SKIP_BITS(re, s, n);
- CLOSE_READER(re, s);
- return tmp;
-#endif
-}
-
-/**
- * Show 1-25 bits.
- */
-static inline unsigned int show_bits(GetBitContext *s, int n)
-{
- register unsigned int tmp;
-#if CACHED_BITSTREAM_READER
- if (n > s->bits_left)
-#ifdef BITSTREAM_READER_LE
- refill_32(s, 1);
-#else
- refill_32(s, 0);
-#endif
-
- tmp = show_val(s, n);
-#else
- OPEN_READER_NOSIZE(re, s);
- av_assert2(n>0 && n<=25);
- UPDATE_CACHE(re, s);
- tmp = SHOW_UBITS(re, s, n);
-#endif
- return tmp;
-}
-
static inline void skip_bits(GetBitContext *s, int n)
{
#if CACHED_BITSTREAM_READER
@@ -530,11 +411,6 @@
#endif
}
-static inline unsigned int show_bits1(GetBitContext *s)
-{
- return show_bits(s, 1);
-}
-
static inline void skip_bits1(GetBitContext *s)
{
skip_bits(s, 1);
@@ -584,31 +460,6 @@
}
}
-/**
- * Read 0-32 bits as a signed integer.
- */
-static inline int get_sbits_long(GetBitContext *s, int n)
-{
- // sign_extend(x, 0) is undefined
- if (!n)
- return 0;
-
- return sign_extend(get_bits_long(s, n), n);
-}
-
-/**
- * Show 0-32 bits.
- */
-static inline unsigned int show_bits_long(GetBitContext *s, int n)
-{
- if (n <= MIN_CACHE_BITS) {
- return show_bits(s, n);
- } else {
- GetBitContext gb = *s;
- return get_bits_long(&gb, n);
- }
-}
-
static inline int check_marker(void *logctx, GetBitContext *s, const char *msg)
{
int bit = get_bits1(s);
@@ -772,62 +623,6 @@
SKIP_BITS(name, gb, n); \
} while (0)
-/* Return the LUT element for the given bitstream configuration. */
-static inline int set_idx(GetBitContext *s, int code, int *n, int *nb_bits,
- VLC_TYPE (*table)[2])
-{
- unsigned idx;
-
- *nb_bits = -*n;
- idx = show_bits(s, *nb_bits) + code;
- *n = table[idx][1];
-
- return table[idx][0];
-}
-
-/**
- * Parse a vlc code.
- * @param bits is the number of bits which will be read at once, must be
- * identical to nb_bits in init_vlc()
- * @param max_depth is the number of times bits bits must be read to completely
- * read the longest vlc code
- * = (max_vlc_length + bits - 1) / bits
- * @returns the code parsed or -1 if no vlc matches
- */
-static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
- int bits, int max_depth)
-{
-#if CACHED_BITSTREAM_READER
- int nb_bits;
- unsigned idx = show_bits(s, bits);
- int code = table[idx][0];
- int n = table[idx][1];
-
- if (max_depth > 1 && n < 0) {
- skip_remaining(s, bits);
- code = set_idx(s, code, &n, &nb_bits, table);
- if (max_depth > 2 && n < 0) {
- skip_remaining(s, nb_bits);
- code = set_idx(s, code, &n, &nb_bits, table);
- }
- }
- skip_remaining(s, n);
-
- return code;
-#else
- int code;
-
- OPEN_READER(re, s);
- UPDATE_CACHE(re, s);
-
- GET_VLC(code, re, s, table, bits, max_depth);
-
- CLOSE_READER(re, s);
-
- return code;
-#endif
-}
-
static inline int decode012(GetBitContext *gb)
{
int n;
@@ -865,4 +660,14 @@
return 0;
}
+static inline unsigned int show_bits_long(GetBitContext *s, int n)
+{
+ if (n <= MIN_CACHE_BITS) {
+ return show_bits(s, n);
+ } else {
+ GetBitContext gb = *s;
+ return get_bits_long(&gb, n);
+ }
+}
+
#endif /* AVCODEC_GET_BITS_H */

View File

@ -32,22 +32,20 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp.h 356357 2020-01-04 20:33:12Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp.h 366750 2020-10-16 10:44:48Z tuexen $");
#endif
#ifndef _NETINET_SCTP_H_
#define _NETINET_SCTP_H_
#if (defined(__APPLE__) || defined(__Userspace_os_Linux) || defined(__Userspace_os_Darwin))
#if defined(__APPLE__) || defined(__linux__)
#include <stdint.h>
#endif
#include <sys/types.h>
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#define SCTP_PACKED __attribute__((packed))
#else
#pragma pack (push, 1)
@ -191,7 +189,6 @@ struct sctp_paramhdr {
#define SCTP_STREAM_RESET_INCOMING 0x00000001
#define SCTP_STREAM_RESET_OUTGOING 0x00000002
/* here on down are more implementation specific */
#define SCTP_SET_DEBUG_LEVEL 0x00001005
#define SCTP_CLR_STAT_LOG 0x00001007
@ -213,7 +210,6 @@ struct sctp_paramhdr {
#define SCTP_PCB_STATUS 0x00001104
#define SCTP_GET_NONCE_VALUES 0x00001105
/* Special hook for dynamically setting primary for all assoc's,
* this is a write only option that requires root privilege.
*/
@ -286,11 +282,11 @@ struct sctp_paramhdr {
#define SCTP_PEELOFF 0x0000800a
/* the real worker for sctp_getaddrlen() */
#define SCTP_GET_ADDR_LEN 0x0000800b
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
/* temporary workaround for Apple listen() issue, no args used */
#define SCTP_LISTEN_FIX 0x0000800c
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
/* workaround for Cygwin on Windows: returns the SOCKET handle */
#define SCTP_GET_HANDLE 0x0000800d
#endif
@ -336,7 +332,6 @@ struct sctp_paramhdr {
/* First-come, first-serve */
#define SCTP_SS_FIRST_COME 0x00000005
/* fragment interleave constants
* setting must be one of these or
* EINVAL returned.
@ -607,13 +602,12 @@ struct sctp_error_auth_invalid_hmac {
#define SCTP_MOBILITY_FASTHANDOFF 0x00000002
#define SCTP_MOBILITY_PRIM_DELETED 0x00000004
/* Smallest PMTU allowed when disabling PMTU discovery */
#define SCTP_SMALLEST_PMTU 512
/* Largest PMTU allowed when disabling PMTU discovery */
#define SCTP_LARGEST_PMTU 65536
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#pragma pack(pop)
#endif
#undef SCTP_PACKED
@ -632,9 +626,9 @@ struct sctp_error_auth_invalid_hmac {
*/
#define SCTP_MAX_SACK_DELAY 500 /* per RFC4960 */
#define SCTP_MAX_HB_INTERVAL 14400000 /* 4 hours in ms */
#define SCTP_MIN_COOKIE_LIFE 1000 /* 1 second in ms */
#define SCTP_MAX_COOKIE_LIFE 3600000 /* 1 hour in ms */
/* Types of logging/KTR tracing that can be enabled via the
* sysctl net.inet.sctp.sctp_logging. You must also enable
* SUBSYS tracing.

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.c 357197 2020-01-28 10:09:05Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#include <netinet/sctp_os.h>
@ -53,10 +53,6 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.c 357197 2020-01-28 10:09:05Z t
* SCTP_DEBUG_ASCONF2: detailed info
*/
#if defined(__APPLE__)
#define APPLE_FILE_NO 1
#endif
/*
* RFC 5061
*
@ -588,7 +584,6 @@ sctp_process_asconf_set_primary(struct sockaddr *src,
SCTP_MOBILITY_PRIM_DELETED) &&
(stcb->asoc.primary_destination->dest_state &
SCTP_ADDR_UNCONFIRMED) == 0) {
sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED,
stcb->sctp_ep, stcb, NULL,
SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
@ -602,8 +597,7 @@ sctp_process_asconf_set_primary(struct sockaddr *src,
sctp_move_chunks_from_net(stcb,
stcb->asoc.deleted_primary);
}
sctp_delete_prim_timer(stcb->sctp_ep, stcb,
stcb->asoc.deleted_primary);
sctp_delete_prim_timer(stcb->sctp_ep, stcb);
}
} else {
/* couldn't set the requested primary address! */
@ -743,7 +737,7 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
sctp_m_freem(m_ack);
return;
}
if (param_length <= sizeof(struct sctp_paramhdr)) {
if (param_length < sizeof(struct sctp_asconf_paramhdr)) {
SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
sctp_m_freem(m_ack);
return;
@ -955,12 +949,12 @@ sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
* Cleanup for non-responded/OP ERR'd ASCONF
*/
void
sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net)
sctp_asconf_cleanup(struct sctp_tcb *stcb)
{
/*
* clear out any existing asconfs going out
*/
sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
/* remove the old ASCONF on our outbound queue */
@ -997,8 +991,12 @@ sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
((ifn == NULL) ||
(SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
/* clear any cached route */
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
#endif
}
/* clear any cached source address */
if (net->src_addr_selected) {
@ -1009,7 +1007,6 @@ sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
}
}
void
sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
{
@ -1050,9 +1047,14 @@ sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
(stcb->asoc.sent_queue_cnt > 0)) {
struct sctp_tmit_chunk *chk;
chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
stcb, chk->whoTo);
TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
if (chk->whoTo != NULL) {
break;
}
}
if (chk != NULL) {
sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, chk->whoTo);
}
}
}
return;
@ -1107,10 +1109,14 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
if (addrnum == 1) {
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
/* clear any cached route and source address */
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
if (net->ro.ro_rt) {
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
}
#endif
if (net->src_addr_selected) {
sctp_free_ifa(net->ro._s_addr);
net->ro._s_addr = NULL;
@ -1129,10 +1135,14 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
/* Multiple local addresses exsist in the association. */
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
/* clear any cached route and source address */
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
if (net->ro.ro_rt) {
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
}
#endif
if (net->src_addr_selected) {
sctp_free_ifa(net->ro._s_addr);
net->ro._s_addr = NULL;
@ -1147,7 +1157,11 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
SCTP_RTALLOC((sctp_route_t *)&net->ro,
stcb->sctp_ep->def_vrf_id,
stcb->sctp_ep->fibnum);
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (net->ro.ro_nh == NULL)
#else
if (net->ro.ro_rt == NULL)
#endif
continue;
changed = 0;
@ -1187,7 +1201,7 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
}
}
}
#endif /* __FreeBSD__ __APPLE__ __Userspace__ */
#endif
/*
* process an ADD/DELETE IP ack from peer.
@ -1219,7 +1233,7 @@ sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t
sctp_path_check_and_react(stcb, addr);
return;
}
#endif /* __FreeBSD__ __APPLE__ __Userspace__ */
#endif
/* clear any cached/topologically incorrect source addresses */
sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
}
@ -1353,7 +1367,6 @@ sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
return (0);
}
/*
* add an asconf operation for the given ifa and type.
* type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
@ -1723,10 +1736,9 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
char msg[SCTP_DIAG_INFO_LEN];
SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
snprintf(msg, sizeof(msg), "Never sent serial number %8.8x",
serial_num);
SCTP_SNPRINTF(msg, sizeof(msg), "Never sent serial number %8.8x", serial_num);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED);
*abort_no_unlock = 1;
return;
}
@ -1739,7 +1751,7 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
if (serial_num == asoc->asconf_seq_out - 1) {
/* stop our timer */
sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
}
@ -1765,7 +1777,7 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
sctp_asconf_ack_clear(stcb);
return;
}
if (param_length < sizeof(struct sctp_paramhdr)) {
if (param_length < sizeof(struct sctp_asconf_paramhdr)) {
sctp_asconf_ack_clear(stcb);
return;
}
@ -1813,9 +1825,9 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
} /* switch */
/* update remaining ASCONF-ACK message length to process */
ack_length -= SCTP_SIZE32(param_length);
if (ack_length <= 0) {
/* no more data in the mbuf chain */
if (ack_length > SCTP_SIZE32(param_length)) {
ack_length -= SCTP_SIZE32(param_length);
} else {
break;
}
offset += SCTP_SIZE32(param_length);
@ -1926,7 +1938,7 @@ sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
switch (ifa->address.sa.sa_family) {
#ifdef INET6
case AF_INET6:
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
&ifa->address.sin6.sin6_addr) != 0) {
return;
@ -1936,7 +1948,7 @@ sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
#endif
#ifdef INET
case AF_INET:
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
&ifa->address.sin.sin_addr) != 0) {
return;
@ -2046,7 +2058,6 @@ sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
}
}
int
sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
{
@ -2110,7 +2121,6 @@ sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP
laddr->action = 0;
break;
}
}
} else if (l->action == SCTP_DEL_IP_ADDRESS) {
LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
@ -2165,7 +2175,7 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
/* we skip unspecifed addresses */
continue;
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) {
continue;
@ -2199,7 +2209,7 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
/* we skip unspecifed addresses */
continue;
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) {
continue;
@ -2227,7 +2237,6 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
return;
else
continue;
break;
}
if (type == SCTP_ADD_IP_ADDRESS) {
@ -2236,18 +2245,19 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
} else if (type == SCTP_DEL_IP_ADDRESS) {
struct sctp_nets *net;
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
sctp_rtentry_t *rt;
/* delete this address if cached */
if (net->ro._s_addr == ifa) {
sctp_free_ifa(net->ro._s_addr);
net->ro._s_addr = NULL;
net->src_addr_selected = 0;
rt = net->ro.ro_rt;
if (rt) {
RTFREE(rt);
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
if (net->ro.ro_rt) {
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
}
#endif
/*
* Now we deleted our src address,
* should we not also now reset the
@ -2256,7 +2266,6 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
*/
stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
net->RTO = 0;
}
}
} else if (type == SCTP_SET_PRIM_ADDR) {
@ -2488,7 +2497,7 @@ sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
/* skip unspecifed addresses */
continue;
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) {
continue;
@ -2522,7 +2531,7 @@ sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
/* we skip unspecifed addresses */
continue;
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) {
continue;
@ -2611,14 +2620,14 @@ sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
if (m_asconf_chk == NULL) {
/* no mbuf's */
SCTPDBG(SCTP_DEBUG_ASCONF1,
"compose_asconf: couldn't get chunk mbuf!\n");
"sctp_compose_asconf: couldn't get chunk mbuf!\n");
return (NULL);
}
m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
if (m_asconf == NULL) {
/* no mbuf's */
SCTPDBG(SCTP_DEBUG_ASCONF1,
"compose_asconf: couldn't get mbuf!\n");
"sctp_compose_asconf: couldn't get mbuf!\n");
sctp_m_freem(m_asconf_chk);
return (NULL);
}
@ -2743,10 +2752,12 @@ sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
break;
#endif
default:
p_size = 0;
addr_size = 0;
addr_ptr = NULL;
break;
SCTPDBG(SCTP_DEBUG_ASCONF1,
"sctp_compose_asconf: no usable lookup addr (family = %d)!\n",
found_addr->sa_family);
sctp_m_freem(m_asconf_chk);
sctp_m_freem(m_asconf);
return (NULL);
}
lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
memcpy(lookup->addr, addr_ptr, addr_size);
@ -2754,12 +2765,10 @@ sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
} else {
/* uh oh... don't have any address?? */
SCTPDBG(SCTP_DEBUG_ASCONF1,
"compose_asconf: no lookup addr!\n");
/* XXX for now, we send a IPv4 address of 0.0.0.0 */
lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
memset(lookup->addr, 0, sizeof(struct in_addr));
SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
"sctp_compose_asconf: no lookup addr!\n");
sctp_m_freem(m_asconf_chk);
sctp_m_freem(m_asconf);
return (NULL);
}
}
/* chain it all together */
@ -3055,10 +3064,6 @@ sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
"check_addr_list_ep: laddr->ifa is NULL");
continue;
}
if (laddr->ifa == NULL) {
SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
continue;
}
/* do i have it implicitly? */
if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
continue;
@ -3120,7 +3125,7 @@ sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
#ifdef INET
case AF_INET:
sin = &sctp_ifa->address.sin;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) {
continue;
@ -3136,7 +3141,7 @@ sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
#ifdef INET6
case AF_INET6:
sin6 = &sctp_ifa->address.sin6;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) {
continue;
@ -3205,7 +3210,7 @@ sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
*/
uint32_t
sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap)
uint32_t type, uint32_t vrf_id)
{
struct sctp_ifa *ifa;
struct sctp_laddr *laddr, *nladdr;
@ -3216,9 +3221,7 @@ sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
return (EINVAL);
}
#endif
if (sctp_ifap) {
ifa = sctp_ifap;
} else if (type == SCTP_ADD_IP_ADDRESS) {
if (type == SCTP_ADD_IP_ADDRESS) {
/* For an add the address MUST be on the system */
ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
} else if (type == SCTP_DEL_IP_ADDRESS) {
@ -3305,10 +3308,9 @@ sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
}
void
sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
struct sctp_nets *net)
sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, struct sctp_nets *net)
{
struct sctp_asconf_addr *aa;
struct sctp_asconf_addr *aa_vtag, *aa_add, *aa_del;
struct sctp_ifa *sctp_ifap;
struct sctp_asconf_tag_param *vtag;
#ifdef INET
@ -3317,6 +3319,7 @@ sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
#ifdef INET6
struct sockaddr_in6 *to6;
#endif
if (net == NULL) {
SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
return;
@ -3325,108 +3328,84 @@ sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
return;
}
/* Need to have in the asconf:
* - vtagparam(my_vtag/peer_vtag)
* - add(0.0.0.0)
* - del(0.0.0.0)
* - Any global addresses add(addr)
*/
SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
SCTP_M_ASC_ADDR);
if (aa == NULL) {
/* didn't get memory */
SCTPDBG(SCTP_DEBUG_ASCONF1,
"sctp_asconf_send_nat_state_update: failed to get memory!\n");
/* Need to have in the ASCONF:
* - VTAG(my_vtag/peer_vtag)
* - ADD(wildcard)
* - DEL(wildcard)
* - ADD(Any global addresses)
*/
SCTP_MALLOC(aa_vtag, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
SCTP_MALLOC(aa_add, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
SCTP_MALLOC(aa_del, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
if ((aa_vtag == NULL) || (aa_add == NULL) || (aa_del == NULL)) {
/* Didn't get memory */
SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: failed to get memory!\n");
out:
if (aa_vtag != NULL) {
SCTP_FREE(aa_vtag, SCTP_M_ASC_ADDR);
}
if (aa_add != NULL) {
SCTP_FREE(aa_add, SCTP_M_ASC_ADDR);
}
if (aa_del != NULL) {
SCTP_FREE(aa_del, SCTP_M_ASC_ADDR);
}
return;
}
aa->special_del = 0;
/* fill in asconf address parameter fields */
/* top level elements are "networked" during send */
aa->ifa = NULL;
aa->sent = 0; /* clear sent flag */
vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph;
memset(aa_vtag, 0, sizeof(struct sctp_asconf_addr));
aa_vtag->special_del = 0;
/* Fill in ASCONF address parameter fields. */
/* Top level elements are "networked" during send. */
aa_vtag->ifa = NULL;
aa_vtag->sent = 0; /* clear sent flag */
vtag = (struct sctp_asconf_tag_param *)&aa_vtag->ap.aph;
vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
vtag->local_vtag = htonl(stcb->asoc.my_vtag);
vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
SCTP_M_ASC_ADDR);
if (aa == NULL) {
/* didn't get memory */
SCTPDBG(SCTP_DEBUG_ASCONF1,
"sctp_asconf_send_nat_state_update: failed to get memory!\n");
return;
}
memset(aa, 0, sizeof(struct sctp_asconf_addr));
/* fill in asconf address parameter fields */
/* ADD(0.0.0.0) */
memset(aa_add, 0, sizeof(struct sctp_asconf_addr));
memset(aa_del, 0, sizeof(struct sctp_asconf_addr));
switch (net->ro._l_addr.sa.sa_family) {
#ifdef INET
case AF_INET:
aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
aa->ap.addrp.ph.param_length = sizeof (struct sctp_ipv4addr_param);
/* No need to add an address, we are using 0.0.0.0 */
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
aa_add->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
aa_add->ap.addrp.ph.param_length = sizeof (struct sctp_ipv4addr_param);
/* No need to fill the address, we are using 0.0.0.0 */
aa_del->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
aa_del->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
aa_del->ap.addrp.ph.param_length = sizeof (struct sctp_ipv4addr_param);
/* No need to fill the address, we are using 0.0.0.0 */
break;
#endif
#ifdef INET6
case AF_INET6:
aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
aa->ap.addrp.ph.param_length = sizeof (struct sctp_ipv6addr_param);
/* No need to add an address, we are using 0.0.0.0 */
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
aa_add->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
aa_add->ap.addrp.ph.param_length = sizeof (struct sctp_ipv6addr_param);
/* No need to fill the address, we are using ::0 */
aa_del->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
aa_del->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
aa_del->ap.addrp.ph.param_length = sizeof (struct sctp_ipv6addr_param);
/* No need to fill the address, we are using ::0 */
break;
#endif
default:
SCTPDBG(SCTP_DEBUG_ASCONF1,
"sctp_asconf_send_nat_state_update: unknown address family\n");
SCTP_FREE(aa, SCTP_M_ASC_ADDR);
return;
}
SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
SCTP_M_ASC_ADDR);
if (aa == NULL) {
/* didn't get memory */
SCTPDBG(SCTP_DEBUG_ASCONF1,
"sctp_asconf_send_nat_state_update: failed to get memory!\n");
return;
}
memset(aa, 0, sizeof(struct sctp_asconf_addr));
/* fill in asconf address parameter fields */
/* ADD(0.0.0.0) */
switch (net->ro._l_addr.sa.sa_family) {
#ifdef INET
case AF_INET:
aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
aa->ap.addrp.ph.param_length = sizeof (struct sctp_ipv4addr_param);
/* No need to add an address, we are using 0.0.0.0 */
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
break;
#endif
#ifdef INET6
case AF_INET6:
aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
aa->ap.addrp.ph.param_length = sizeof (struct sctp_ipv6addr_param);
/* No need to add an address, we are using 0.0.0.0 */
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
break;
#endif
default:
SCTPDBG(SCTP_DEBUG_ASCONF1,
"sctp_asconf_send_nat_state_update: unknown address family\n");
SCTP_FREE(aa, SCTP_M_ASC_ADDR);
return;
"sctp_asconf_send_nat_state_update: unknown address family %d\n",
net->ro._l_addr.sa.sa_family);
goto out;
}
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_vtag, next);
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_add, next);
TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_del, next);
/* Now we must hunt the addresses and add all global addresses */
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
struct sctp_vrf *vrf = NULL;
@ -3446,7 +3425,7 @@ sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
#ifdef INET
case AF_INET:
to = &sctp_ifap->address.sin;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
&to->sin_addr) != 0) {
continue;
@ -3463,7 +3442,7 @@ sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
#ifdef INET6
case AF_INET6:
to6 = &sctp_ifap->address.sin6;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
&to6->sin6_addr) != 0) {
continue;

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.h 324056 2017-09-27 13:05:23Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_ASCONF_H_
@ -45,7 +45,7 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.h 324056 2017-09-27 13:05:23Z t
/*
* function prototypes
*/
extern void sctp_asconf_cleanup(struct sctp_tcb *, struct sctp_nets *);
extern void sctp_asconf_cleanup(struct sctp_tcb *);
extern struct mbuf *sctp_compose_asconf(struct sctp_tcb *, int *, int);
@ -58,9 +58,8 @@ sctp_handle_asconf_ack(struct mbuf *, int, struct sctp_asconf_ack_chunk *,
struct sctp_tcb *, struct sctp_nets *, int *);
extern uint32_t
sctp_addr_mgmt_ep_sa(struct sctp_inpcb *, struct sockaddr *,
uint32_t, uint32_t, struct sctp_ifa *);
sctp_addr_mgmt_ep_sa(struct sctp_inpcb *, struct sockaddr *, uint32_t,
uint32_t);
extern int sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr,
uint32_t val);
@ -69,7 +68,6 @@ extern void sctp_asconf_iterator_stcb(struct sctp_inpcb *inp,
void *ptr, uint32_t type);
extern void sctp_asconf_iterator_end(void *ptr, uint32_t val);
extern int32_t
sctp_set_primary_ip_address_sa(struct sctp_tcb *,
struct sockaddr *);

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.c 355931 2019-12-20 15:25:08Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.c 365071 2020-09-01 21:19:14Z mjg $");
#endif
#include <netinet/sctp_os.h>
@ -53,7 +53,6 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.c 355931 2019-12-20 15:25:08Z tue
#define SCTP_AUTH_DEBUG2 (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_AUTH2)
#endif /* SCTP_DEBUG */
void
sctp_clear_chunklist(sctp_auth_chklist_t *chklist)
{
@ -101,7 +100,6 @@ sctp_copy_chunklist(sctp_auth_chklist_t *list)
return (new_list);
}
/*
* add a chunk to the required chunks list
*/
@ -241,7 +239,6 @@ sctp_unpack_auth_chunks(const uint8_t *ptr, uint8_t num_chunks,
return (size);
}
/*
* allocate structure space for a key of length keylen
*/
@ -458,7 +455,6 @@ sctp_compute_hashkey(sctp_key_t *key1, sctp_key_t *key2, sctp_key_t *shared)
return (new_key);
}
sctp_sharedkey_t *
sctp_alloc_sharedkey(void)
{
@ -567,11 +563,7 @@ sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t key_id)
}
void
sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t key_id, int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
)
sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t key_id, int so_locked)
{
sctp_sharedkey_t *skey;
@ -636,7 +628,6 @@ sctp_copy_skeylist(const struct sctp_keyhead *src, struct sctp_keyhead *dest)
return (count);
}
sctp_hmaclist_t *
sctp_alloc_hmaclist(uint16_t num_hmacs)
{
@ -660,7 +651,6 @@ sctp_free_hmaclist(sctp_hmaclist_t *list)
{
if (list != NULL) {
SCTP_FREE(list,SCTP_M_AUTH_HL);
list = NULL;
}
}
@ -831,7 +821,6 @@ sctp_free_authinfo(sctp_authinfo_t *authinfo)
/* SCTP_FREE(authinfo, SCTP_M_AUTH_??); */
}
uint32_t
sctp_get_auth_chunk_len(uint16_t hmac_algo)
{
@ -1171,7 +1160,6 @@ sctp_auth_is_supported_hmac(sctp_hmaclist_t *list, uint16_t id)
return (0);
}
/*-
* clear any cached key(s) if they match the given key id on an association.
* the cached key(s) will be recomputed and re-cached at next use.
@ -1584,7 +1572,6 @@ sctp_fill_hmac_digest_m(struct mbuf *m, uint32_t auth_offset,
m, auth_offset, auth->hmac);
}
static void
sctp_zero_m(struct mbuf *m, uint32_t m_offset, uint32_t size)
{
@ -1650,6 +1637,9 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
"SCTP AUTH Chunk: shared key %u, HMAC id %u\n",
shared_key_id, hmac_id);
#if defined(__Userspace__) && defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
return (0);
#endif
/* is the indicated HMAC supported? */
if (!sctp_auth_is_supported_hmac(stcb->asoc.local_hmacs, hmac_id)) {
struct mbuf *op_err;
@ -1730,11 +1720,6 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
(void)sctp_compute_hmac_m(hmac_id, stcb->asoc.authinfo.recv_key,
m, offset, computed_digest);
#if defined(__Userspace__)
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
return (0);
#endif
#endif
/* compare the computed digest with the one in the AUTH chunk */
if (timingsafe_bcmp(digest, computed_digest, digestlen) != 0) {
SCTP_STAT_INCR(sctps_recvauthfailed);
@ -1750,11 +1735,7 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
*/
void
sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication,
uint16_t keyid, uint16_t alt_keyid, int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
)
uint16_t keyid, uint16_t alt_keyid, int so_locked)
{
struct mbuf *m_notify;
struct sctp_authkey_event *auth;
@ -1809,7 +1790,6 @@ sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication,
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, so_locked);
}
/*-
* validates the AUTHentication related parameters in an INIT/INIT-ACK
* Note: currently only used for INIT as INIT-ACK is handled inline
@ -1924,7 +1904,6 @@ sctp_validate_init_auth_params(struct mbuf *m, int offset, int limit)
saw_asconf = 1;
if (chunks->chunk_types[i] == SCTP_ASCONF_ACK)
saw_asconf_ack = 1;
}
if (num_chunks)
got_chklist = 1;

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.h 338749 2018-09-18 10:53:07Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_AUTH_H_
@ -99,8 +99,6 @@ typedef struct sctp_authinformation {
uint16_t recv_keyid; /* last recv keyid (cached) */
} sctp_authinfo_t;
/*
* Macros
*/
@ -149,7 +147,6 @@ extern void sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t keyid);
extern void sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t keyid,
int so_locked);
/* hmac list handling */
extern sctp_hmaclist_t *sctp_alloc_hmaclist(uint16_t num_hmacs);
extern void sctp_free_hmaclist(sctp_hmaclist_t *list);

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 353480 2019-10-13 18:17:08Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 366426 2020-10-04 15:37:34Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@ -50,12 +50,11 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 353480 2019-10-13 18:17:08Z
#include <netinet/sctp_asconf.h>
#include <netinet/sctp_sysctl.h>
#include <netinet/sctp_indata.h>
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/unistd.h>
#endif
/* Declare all of our malloc named types */
#ifndef __Panda__
MALLOC_DEFINE(SCTP_M_MAP, "sctp_map", "sctp asoc map descriptor");
MALLOC_DEFINE(SCTP_M_STRMI, "sctp_stri", "sctp stream in array");
MALLOC_DEFINE(SCTP_M_STRMO, "sctp_stro", "sctp stream out array");
@ -76,12 +75,11 @@ MALLOC_DEFINE(SCTP_M_MVRF, "sctp_mvrf", "sctp mvrf pcb list");
MALLOC_DEFINE(SCTP_M_ITER, "sctp_iter", "sctp iterator control");
MALLOC_DEFINE(SCTP_M_SOCKOPT, "sctp_socko", "sctp socket option");
MALLOC_DEFINE(SCTP_M_MCORE, "sctp_mcore", "sctp mcore queue");
#endif
/* Global NON-VNET structure that controls the iterator */
struct iterator_control sctp_it_ctl;
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
#if !defined(__FreeBSD__)
static void
sctp_cleanup_itqueue(void)
{
@ -109,7 +107,7 @@ void
sctp_wakeup_iterator(void)
{
#if defined(SCTP_PROCESS_LEVEL_LOCKS)
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
WakeAllConditionVariable(&sctp_it_ctl.iterator_wakeup);
#else
pthread_cond_broadcast(&sctp_it_ctl.iterator_wakeup);
@ -131,7 +129,7 @@ sctp_iterator_thread(void *v SCTP_UNUSED)
#endif
SCTP_IPI_ITERATOR_WQ_LOCK();
/* In FreeBSD this thread never terminates. */
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
for (;;) {
#else
while ((sctp_it_ctl.iterator_flags & SCTP_ITERATOR_MUST_EXIT) == 0) {
@ -140,25 +138,25 @@ sctp_iterator_thread(void *v SCTP_UNUSED)
msleep(&sctp_it_ctl.iterator_running,
#if defined(__FreeBSD__)
&sctp_it_ctl.ipi_iterator_wq_mtx,
#elif defined(__APPLE__) || defined(__Userspace_os_Darwin)
#elif defined(__APPLE__)
sctp_it_ctl.ipi_iterator_wq_mtx,
#endif
0, "waiting_for_work", 0);
#else
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SleepConditionVariableCS(&sctp_it_ctl.iterator_wakeup, &sctp_it_ctl.ipi_iterator_wq_mtx, INFINITE);
#else
pthread_cond_wait(&sctp_it_ctl.iterator_wakeup, &sctp_it_ctl.ipi_iterator_wq_mtx);
#endif
#endif
#if !defined(__FreeBSD__)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
if (sctp_it_ctl.iterator_flags & SCTP_ITERATOR_MUST_EXIT) {
break;
}
#endif
sctp_iterator_worker();
}
#if !defined(__FreeBSD__)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
/* Now this thread needs to be terminated */
sctp_cleanup_itqueue();
sctp_it_ctl.iterator_flags |= SCTP_ITERATOR_EXITED;
@ -187,23 +185,21 @@ sctp_startup_iterator(void)
SCTP_ITERATOR_LOCK_INIT();
SCTP_IPI_ITERATOR_WQ_INIT();
TAILQ_INIT(&sctp_it_ctl.iteratorhead);
#if defined(__FreeBSD__)
#if __FreeBSD_version <= 701000
kthread_create(sctp_iterator_thread,
#else
#if defined(__Userspace__)
if (sctp_userspace_thread_create(&sctp_it_ctl.thread_proc, &sctp_iterator_thread)) {
SCTP_PRINTF("ERROR: Creating sctp_iterator_thread failed.\n");
} else {
SCTP_BASE_VAR(iterator_thread_started) = 1;
}
#elif defined(__FreeBSD__)
kproc_create(sctp_iterator_thread,
#endif
(void *)NULL,
&sctp_it_ctl.thread_proc,
RFPROC,
0,
SCTP_KTHREAD_PAGES,
SCTP_KTRHEAD_NAME);
#elif defined(__APPLE__)
kernel_thread_start((thread_continue_t)sctp_iterator_thread, NULL, &sctp_it_ctl.thread_proc);
#elif defined(__Userspace__)
if (sctp_userspace_thread_create(&sctp_it_ctl.thread_proc, &sctp_iterator_thread)) {
SCTP_PRINTF("ERROR: Creating sctp_iterator_thread failed.\n");
}
#endif
}
@ -248,7 +244,6 @@ sctp_gather_internal_ifa_flags(struct sctp_ifa *ifa)
#endif /* __Userspace__ */
#endif /* INET6 */
#if !defined(__Userspace__)
static uint32_t
sctp_is_desired_interface_type(struct ifnet *ifn)
@ -256,7 +251,7 @@ sctp_is_desired_interface_type(struct ifnet *ifn)
int result;
/* check the interface type to see if it's one we care about */
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
switch(ifnet_type(ifn)) {
#else
switch (ifn->if_type) {
@ -282,7 +277,7 @@ sctp_is_desired_interface_type(struct ifnet *ifn)
case IFT_GIF:
case IFT_L2VLAN:
case IFT_STF:
#if !defined(__APPLE__)
#if !(defined(__APPLE__) && !defined(__Userspace__))
case IFT_IP:
case IFT_IPOVERCDLC:
case IFT_IPOVERCLAW:
@ -298,16 +293,17 @@ sctp_is_desired_interface_type(struct ifnet *ifn)
return (result);
}
#endif
#if defined(__APPLE__) && !defined(__Userspace__)
#if defined(__APPLE__)
int
sctp_is_vmware_interface(struct ifnet *ifn)
{
return (strncmp(ifnet_name(ifn), "vmnet", 5) == 0);
}
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && defined(__Userspace__)
#ifdef MALLOC
#undef MALLOC
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
@ -480,8 +476,7 @@ sctp_init_ifns_for_vrf(int vrfid)
#endif
}
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static void
sctp_init_ifns_for_vrf(int vrfid)
{
@ -540,7 +535,7 @@ sctp_init_ifns_for_vrf(int vrfid)
} else {
ifa_flags = 0;
}
snprintf(name, SCTP_IFNAMSIZ, "%s%d", ifnet_name(ifn), ifnet_unit(ifn));
SCTP_SNPRINTF(name, SCTP_IFNAMSIZ, "%s%d", ifnet_name(ifn), ifnet_unit(ifn));
sctp_ifa = sctp_add_addr_to_vrf(vrfid,
(void *)ifn, /* XXX */
ifnet_index(ifn),
@ -559,8 +554,7 @@ sctp_init_ifns_for_vrf(int vrfid)
ifnet_list_free(ifnetlist);
}
#endif
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
static void
sctp_init_ifns_for_vrf(int vrfid)
{
@ -716,16 +710,15 @@ sctp_addr_change(struct ifaddr *ifa, int cmd)
}
if (cmd == RTM_ADD) {
(void)sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID, (void *)ifa->ifa_ifp,
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
ifnet_index(ifa->ifa_ifp), ifnet_type(ifa->ifa_ifp), ifnet_name(ifa->ifa_ifp),
#else
ifa->ifa_ifp->if_index, ifa->ifa_ifp->if_type, ifa->ifa_ifp->if_xname,
#endif
(void *)ifa, ifa->ifa_addr, ifa_flags, 1);
} else {
sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, ifa->ifa_addr,
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
ifnet_index(ifa->ifa_ifp),
ifnet_name(ifa->ifa_ifp));
#else
@ -740,31 +733,13 @@ sctp_addr_change(struct ifaddr *ifa, int cmd)
#endif
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
void
sctp_addr_change_event_handler(void *arg __unused, struct ifaddr *ifa, int cmd) {
sctp_addr_change(ifa, cmd);
}
void
sctp_add_or_del_interfaces(int (*pred)(struct ifnet *), int add)
{
struct ifnet *ifn;
struct ifaddr *ifa;
IFNET_RLOCK();
CK_STAILQ_FOREACH(ifn, &MODULE_GLOBAL(ifnet), if_link) {
if (!(*pred)(ifn)) {
continue;
}
CK_STAILQ_FOREACH(ifa, &ifn->if_addrhead, ifa_link) {
sctp_addr_change(ifa, add ? RTM_ADD : RTM_DELETE);
}
}
IFNET_RUNLOCK();
}
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
void
sctp_add_or_del_interfaces(int (*pred)(struct ifnet *), int add)
{
@ -797,7 +772,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header,
int how, int allonebuf, int type)
{
struct mbuf *m = NULL;
#if defined(__FreeBSD__) && __FreeBSD_version > 1100052 || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(__Userspace__)
#if defined(__Userspace__)
m = m_getm2(NULL, space_needed, how, type, want_header ? M_PKTHDR : 0, allonebuf);
#else
@ -813,7 +788,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header,
m_freem(m);
return (NULL);
}
KASSERT(SCTP_BUF_NEXT(m) == NULL, ("%s: no chain allowed", __FUNCTION__));
KASSERT(SCTP_BUF_NEXT(m) == NULL, ("%s: no chain allowed", __func__));
}
#endif
#ifdef SCTP_MBUF_LOGGING
@ -867,7 +842,6 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header,
return (m);
}
#ifdef SCTP_PACKET_LOGGING
void
sctp_packet_log(struct mbuf *m)
@ -943,7 +917,6 @@ sctp_packet_log(struct mbuf *m)
SCTP_BASE_VAR(packet_log_end));
SCTP_BASE_VAR(packet_log_end) = 0;
goto no_log;
}
lenat = (int *)&SCTP_BASE_VAR(packet_log_buffer)[thisbegin];
*lenat = total_len;
@ -969,7 +942,6 @@ sctp_packet_log(struct mbuf *m)
atomic_subtract_int(&SCTP_BASE_VAR(packet_log_writers), 1);
}
int
sctp_copy_out_packet_log(uint8_t *target, int length)
{

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.h 353480 2019-10-13 18:17:08Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_BSD_ADDR_H_
@ -49,7 +49,6 @@ void sctp_wakeup_iterator(void);
void sctp_startup_iterator(void);
#ifdef INET6
void sctp_gather_internal_ifa_flags(struct sctp_ifa *ifa);
#endif
@ -61,10 +60,8 @@ int sctp_copy_out_packet_log(uint8_t *target, int length);
#endif
#if !defined(__Panda__)
void sctp_addr_change(struct ifaddr *ifa, int cmd);
#endif
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
void sctp_addr_change_event_handler(void *, struct ifaddr *, int);
#endif

View File

@ -34,12 +34,12 @@
#if defined(__Userspace__)
#include <sys/types.h>
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
#endif
#if defined(__Userspace_os_NaCl)
#if defined(__native_client__)
#include <sys/select.h>
#endif
#include <stdlib.h>
@ -54,6 +54,7 @@
#include <netinet/sctp_callout.h>
#include <netinet/sctp_pcb.h>
#endif
#include <netinet/sctputil.h>
/*
* Callout/Timer routines for OS that doesn't have them
@ -86,17 +87,20 @@ sctp_os_timer_init(sctp_os_timer_t *c)
memset(c, 0, sizeof(*c));
}
void
int
sctp_os_timer_start(sctp_os_timer_t *c, uint32_t to_ticks, void (*ftn) (void *),
void *arg)
{
int ret = 0;
/* paranoia */
if ((c == NULL) || (ftn == NULL))
return;
return (ret);
SCTP_TIMERQ_LOCK();
/* check to see if we're rescheduling a timer */
if (c->c_flags & SCTP_CALLOUT_PENDING) {
ret = 1;
if (c == sctp_os_timer_next) {
sctp_os_timer_next = TAILQ_NEXT(c, tqe);
}
@ -122,6 +126,7 @@ sctp_os_timer_start(sctp_os_timer_t *c, uint32_t to_ticks, void (*ftn) (void *),
c->c_time = ticks + to_ticks;
TAILQ_INSERT_TAIL(&SCTP_BASE_INFO(callqueue), c, tqe);
SCTP_TIMERQ_UNLOCK();
return (ret);
}
int
@ -175,7 +180,7 @@ sctp_handle_tick(uint32_t elapsed_ticks)
SCTP_TIMERQ_UNLOCK();
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
void
sctp_timeout(void *arg SCTP_UNUSED)
{
@ -192,7 +197,7 @@ user_sctp_timer_iterate(void *arg)
{
sctp_userspace_set_threadname("SCTP timer");
for (;;) {
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
Sleep(TIMEOUT_INTERVAL);
#else
struct timespec amount, remaining;
@ -206,13 +211,13 @@ user_sctp_timer_iterate(void *arg)
if (atomic_cmpset_int(&SCTP_BASE_VAR(timer_thread_should_exit), 1, 1)) {
break;
}
sctp_handle_tick(MSEC_TO_TICKS(TIMEOUT_INTERVAL));
sctp_handle_tick(sctp_msecs_to_ticks(TIMEOUT_INTERVAL));
}
return (NULL);
}
void
sctp_start_timer(void)
sctp_start_timer_thread(void)
{
/*
* No need to do SCTP_TIMERQ_LOCK_INIT();
@ -223,7 +228,22 @@ sctp_start_timer(void)
rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(timer_thread), user_sctp_timer_iterate);
if (rc) {
SCTP_PRINTF("ERROR; return code from sctp_thread_create() is %d\n", rc);
} else {
SCTP_BASE_VAR(timer_thread_started) = 1;
}
}
void
sctp_stop_timer_thread(void)
{
atomic_cmpset_int(&SCTP_BASE_VAR(timer_thread_should_exit), 0, 1);
if (SCTP_BASE_VAR(timer_thread_started)) {
#if defined(_WIN32)
WaitForSingleObject(SCTP_BASE_VAR(timer_thread), INFINITE);
CloseHandle(SCTP_BASE_VAR(timer_thread));
#else
pthread_join(SCTP_BASE_VAR(timer_thread), NULL);
#endif
}
}
#endif

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#endif
@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$");
#define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */
#if defined(__Userspace__)
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_UNLOCK() LeaveCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_LOCK_INIT() InitializeCriticalSection(&SCTP_BASE_VAR(timer_mtx))
@ -88,11 +88,18 @@ typedef struct sctp_callout sctp_os_timer_t;
#define SCTP_CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */
void sctp_os_timer_init(sctp_os_timer_t *tmr);
void sctp_os_timer_start(sctp_os_timer_t *, uint32_t, void (*)(void *), void *);
/* Returns 1 if pending timer was rescheduled, 0 otherwise. */
int sctp_os_timer_start(sctp_os_timer_t *, uint32_t, void (*)(void *), void *);
/* Returns 1 if pending timer was stopped, 0 otherwise. */
int sctp_os_timer_stop(sctp_os_timer_t *);
void sctp_handle_tick(uint32_t);
#define SCTP_OS_TIMER_INIT sctp_os_timer_init
/*
* NOTE: The next two shouldn't be called directly outside of sctp_timer_start()
* and sctp_timer_stop(), since they don't handle incrementing/decrementing
* relevant reference counts.
*/
#define SCTP_OS_TIMER_START sctp_os_timer_start
#define SCTP_OS_TIMER_STOP sctp_os_timer_stop
/* MT FIXME: Is the following correct? */
@ -102,9 +109,10 @@ void sctp_handle_tick(uint32_t);
#define SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE)
#if defined(__Userspace__)
void sctp_start_timer(void);
void sctp_start_timer_thread(void);
void sctp_stop_timer_thread(void);
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
void sctp_timeout(void *);
#endif

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 356660 2020-01-12 15:45:27Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#include <netinet/sctp_os.h>
@ -50,7 +50,7 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 356660 2020-01-12 15:45
#include <netinet/sctp_timer.h>
#include <netinet/sctp_auth.h>
#include <netinet/sctp_asconf.h>
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/sctp_kdtrace.h>
#endif
@ -64,7 +64,7 @@ sctp_enforce_cwnd_limit(struct sctp_association *assoc, struct sctp_nets *net)
if ((assoc->max_cwnd > 0) &&
(net->cwnd > assoc->max_cwnd) &&
(net->cwnd > (net->mtu - sizeof(struct sctphdr)))) {
net->cwnd = assoc->max_cwnd ;
net->cwnd = assoc->max_cwnd;
if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
net->cwnd = net->mtu - sizeof(struct sctphdr);
}
@ -101,7 +101,7 @@ sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
}
sctp_enforce_cwnd_limit(assoc, net);
net->ssthresh = assoc->peers_rwnd;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, init,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
0, net->cwnd);
@ -163,7 +163,6 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
(uint64_t)net->mtu *
(uint64_t)net->ssthresh) /
(uint64_t)t_ssthresh);
}
if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) {
uint32_t srtt;
@ -196,7 +195,7 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
}
net->cwnd = net->ssthresh;
sctp_enforce_cwnd_limit(asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, fr,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
old_cwnd, net->cwnd);
@ -251,22 +250,21 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
#define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */
#define SCTP_INST_GAINING 3 /* Gaining, step down possible */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
static int
cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
#else
static int
cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw,
uint64_t rtt_offset, uint8_t inst_ind)
uint64_t rtt_offset, uint8_t inst_ind)
#endif
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32);
#endif
if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
@ -275,7 +273,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
* we don't update bw.. so we don't
* update the rtt either.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 5 */
probepoint |= ((5 << 16) | 1);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -295,7 +293,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
/* Try a step down */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -324,7 +322,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
* we update both the bw and the rtt here to
* lock this in as a good step down.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 6 */
probepoint |= ((6 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -335,7 +333,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -370,7 +368,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
}
/* Ok bw and rtt remained the same .. no update to any
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 7 */
probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -407,22 +405,22 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
return ((int)net->cc_mod.rtcc.ret_from_eq);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
static int
cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
uint64_t vtag, uint8_t inst_ind)
uint64_t vtag, uint8_t inst_ind)
#else
static int
cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
uint8_t inst_ind)
uint8_t inst_ind)
#endif
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint;
#endif
/* Bandwidth decreased.*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32);
#endif
if (net->rtt > net->cc_mod.rtcc.lbw_rtt+rtt_offset) {
@ -431,7 +429,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
(inst_ind != SCTP_INST_LOOSING)) {
/* We caused it maybe.. back off? */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* PROBE POINT 1 */
probepoint |= ((1 << 16) | 1);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -448,7 +446,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
}
return (1);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 2 */
probepoint |= ((2 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -460,7 +458,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
#endif
/* Someone else - fight for more? */
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -488,7 +486,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
goto out_decision;
} else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) {
/* bw & rtt decreased */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 3 */
probepoint |= ((3 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -499,7 +497,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -524,7 +522,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
goto out_decision;
}
/* The bw decreased but rtt stayed the same */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 4 */
probepoint |= ((4 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -535,7 +533,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -568,7 +566,7 @@ out_decision:
}
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
static int
cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
#else
@ -576,7 +574,7 @@ static int
cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw)
#endif
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint;
#endif
@ -586,7 +584,7 @@ cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
* update. Note that we pay no attention to
* the inst_ind since our overall sum is increasing.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* PROBE POINT 0 */
probepoint = (((uint64_t)net->cwnd) << 32);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -597,7 +595,7 @@ cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -627,7 +625,7 @@ static int
cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
{
uint64_t bw_offset, rtt_offset;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t probepoint, rtt, vtag;
#endif
uint64_t bytes_for_this_rtt, inst_bw;
@ -673,7 +671,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
* change within 1/32nd
*/
bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
rtt = stcb->asoc.my_vtag;
vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
probepoint = (((uint64_t)net->cwnd) << 32);
@ -694,12 +692,12 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
inst_ind = SCTP_INST_LOOSING;
else
inst_ind = SCTP_INST_NEUTRAL;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint |= ((0xb << 16) | inst_ind);
#endif
} else {
inst_ind = net->cc_mod.rtcc.last_inst_ind;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt);
/* Can't determine do not change */
probepoint |= ((0xc << 16) | inst_ind);
@ -707,13 +705,13 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
}
} else {
inst_ind = net->cc_mod.rtcc.last_inst_ind;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
inst_bw = bytes_for_this_rtt;
/* Can't determine do not change */
probepoint |= ((0xd << 16) | inst_ind);
#endif
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, rttvar,
vtag,
((nbw << 32) | inst_bw),
@ -727,7 +725,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
}
bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
if (nbw > net->cc_mod.rtcc.lbw + bw_offset) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
ret = cc_bw_increase(stcb, net, nbw, vtag);
#else
ret = cc_bw_increase(stcb, net, nbw);
@ -736,7 +734,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
}
rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
if (nbw < net->cc_mod.rtcc.lbw - bw_offset) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
#else
ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, inst_ind);
@ -747,7 +745,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
* we are in a situation where
* the bw stayed the same.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
#else
ret = cc_bw_same(stcb, net, nbw, rtt_offset, inst_ind);
@ -763,10 +761,10 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
{
struct sctp_nets *net;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int old_cwnd;
#endif
uint32_t t_ssthresh, t_cwnd, incr;
uint32_t t_ssthresh, incr;
uint64_t t_ucwnd_sbw;
uint64_t t_path_mptcp;
uint64_t mptcp_like_alpha;
@ -775,7 +773,6 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
/* MT FIXME: Don't compute this over and over again */
t_ssthresh = 0;
t_cwnd = 0;
t_ucwnd_sbw = 0;
t_path_mptcp = 0;
mptcp_like_alpha = 1;
@ -785,7 +782,6 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
max_path = 0;
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
t_ssthresh += net->ssthresh;
t_cwnd += net->cwnd;
/* lastsa>>3; we don't need to devide ...*/
srtt = net->lastsa;
if (srtt > 0) {
@ -817,7 +813,6 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
/* update cwnd and Early FR */
/******************************/
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
#ifdef JANA_CMT_FAST_RECOVERY
/*
* CMT fast recovery code. Need to debug.
@ -837,7 +832,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
continue;
}
#ifdef JANA_CMT_FAST_RECOVERY
/* CMT fast recovery code
/* CMT fast recovery code
*/
/*
if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) {
@ -879,7 +874,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
continue;
}
} else {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t vtag, probepoint;
probepoint = (((uint64_t)net->cwnd) << 32);
@ -915,7 +910,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
if (net->flight_size + net->net_ack >= net->cwnd) {
uint32_t limit;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
old_cwnd = net->cwnd;
#endif
switch (asoc->sctp_cmt_on_off) {
@ -987,7 +982,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
sctp_log_cwnd(stcb, net, incr,
SCTP_CWND_LOG_FROM_SS);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1008,9 +1003,9 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
net->partial_bytes_acked += net->net_ack;
if ((net->flight_size + net->net_ack >= net->cwnd) &&
(net->partial_bytes_acked >= net->cwnd)) {
(net->partial_bytes_acked >= net->cwnd)) {
net->partial_bytes_acked -= net->cwnd;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
old_cwnd = net->cwnd;
#endif
switch (asoc->sctp_cmt_on_off) {
@ -1051,7 +1046,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
}
net->cwnd += incr;
sctp_enforce_cwnd_limit(asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1078,7 +1073,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
}
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
static void
sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
#else
@ -1086,13 +1081,13 @@ static void
sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net)
#endif
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int old_cwnd;
old_cwnd = net->cwnd;
#endif
net->cwnd = net->mtu;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
old_cwnd, net->cwnd);
@ -1101,7 +1096,6 @@ sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_n
(void *)net, net->cwnd);
}
static void
sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
{
@ -1165,7 +1159,7 @@ sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
}
net->cwnd = net->mtu;
net->partial_bytes_acked = 0;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, to,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1179,7 +1173,7 @@ sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
static void
sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net,
int in_window, int num_pkt_lost, int use_rtcc)
int in_window, int num_pkt_lost, int use_rtcc)
{
int old_cwnd = net->cwnd;
if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) {
@ -1207,10 +1201,9 @@ sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
}
}
SCTP_STAT_INCR(sctps_ecnereducedcwnd);
} else {
} else {
if (in_window == 0) {
SCTP_STAT_INCR(sctps_ecnereducedcwnd);
net->ssthresh = net->cwnd / 2;
@ -1220,7 +1213,7 @@ sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *
net->RTO <<= 1;
}
net->cwnd = net->ssthresh;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ecn,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1341,7 +1334,7 @@ sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
sctp_enforce_cwnd_limit(&stcb->asoc, net);
if (net->cwnd - old_cwnd != 0) {
/* log only changes */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, pd,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1357,7 +1350,7 @@ sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
static void
sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
struct sctp_nets *net, int burst_limit)
struct sctp_nets *net, int burst_limit)
{
int old_cwnd = net->cwnd;
@ -1366,7 +1359,7 @@ sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
if (burst_limit) {
net->cwnd = (net->flight_size + (burst_limit * net->mtu));
sctp_enforce_cwnd_limit(&stcb->asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, bl,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1381,8 +1374,8 @@ sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
static void
sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
struct sctp_association *asoc,
int accum_moved, int reneged_all, int will_exit)
struct sctp_association *asoc,
int accum_moved, int reneged_all, int will_exit)
{
/* Passing a zero argument in last disables the rtcc algorithm */
sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0);
@ -1390,7 +1383,7 @@ sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
static void
sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
int in_window, int num_pkt_lost)
int in_window, int num_pkt_lost)
{
/* Passing a zero argument in last disables the rtcc algorithm */
sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0);
@ -1403,22 +1396,20 @@ sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
*/
static void
sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
int in_window, int num_pkt_lost)
int in_window, int num_pkt_lost)
{
sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1);
}
static
void sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net,
struct sctp_tmit_chunk *tp1)
static void sctp_cwnd_update_rtcc_tsn_acknowledged(struct sctp_nets *net,
struct sctp_tmit_chunk *tp1)
{
net->cc_mod.rtcc.bw_bytes += tp1->send_size;
}
static void
sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED,
struct sctp_nets *net)
struct sctp_nets *net)
{
if (net->cc_mod.rtcc.tls_needs_set > 0) {
/* We had a bw measurment going on */
@ -1431,14 +1422,14 @@ sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED,
static void
sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
struct sctp_nets *net)
struct sctp_nets *net)
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t vtag, probepoint;
#endif
if (net->cc_mod.rtcc.lbw) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Clear the old bw.. we went to 0 in-flight */
vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
(stcb->rport);
@ -1492,15 +1483,15 @@ sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
static void
sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
struct sctp_nets *net)
struct sctp_nets *net)
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t vtag, probepoint;
#endif
sctp_set_initial_cc_param(stcb, net);
stcb->asoc.use_precise_time = 1;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32);
probepoint |= ((9 << 16) | 0);
vtag = (net->rtt << 32) |
@ -1527,15 +1518,14 @@ sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
net->cc_mod.rtcc.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn);
net->cc_mod.rtcc.step_cnt = 0;
net->cc_mod.rtcc.last_step_state = 0;
}
static int
sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget,
struct sctp_cc_option *cc_opt)
struct sctp_cc_option *cc_opt)
{
struct sctp_nets *net;
if (setorget == 1) {
/* a set */
if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) {
@ -1600,8 +1590,8 @@ sctp_cwnd_update_rtcc_packet_transmitted(struct sctp_tcb *stcb SCTP_UNUSED,
static void
sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
struct sctp_association *asoc,
int accum_moved, int reneged_all, int will_exit)
struct sctp_association *asoc,
int accum_moved, int reneged_all, int will_exit)
{
/* Passing a one argument at the last enables the rtcc algorithm */
sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1);
@ -1842,15 +1832,14 @@ sctp_hs_cwnd_update_after_fr(struct sctp_tcb *stcb,
static void
sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
struct sctp_association *asoc,
int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
struct sctp_association *asoc,
int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
{
struct sctp_nets *net;
/******************************/
/* update cwnd and Early FR */
/******************************/
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
#ifdef JANA_CMT_FAST_RECOVERY
/*
* CMT fast recovery code. Need to debug.
@ -1870,7 +1859,7 @@ sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
continue;
}
#ifdef JANA_CMT_FAST_RECOVERY
/* CMT fast recovery code
/* CMT fast recovery code
*/
/*
if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) {
@ -1934,7 +1923,6 @@ sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
}
}
/*
* H-TCP congestion control. The algorithm is detailed in:
* R.N.Shorten, D.J.Leith:
@ -1943,7 +1931,6 @@ sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
* http://www.hamilton.ie/net/htcp3.pdf
*/
static int use_rtt_scaling = 1;
static int use_bandwidth_switch = 1;
@ -2000,7 +1987,7 @@ measure_rtt(struct sctp_nets *net)
if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) {
if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT)
net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT;
if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT+MSEC_TO_TICKS(20))
if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT+sctp_msecs_to_ticks(20))
net->cc_mod.htcp_ca.maxRTT = srtt;
}
}
@ -2060,7 +2047,7 @@ htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
}
}
if (ca->modeswitch && minRTT > (uint32_t)MSEC_TO_TICKS(10) && maxRTT) {
if (ca->modeswitch && minRTT > sctp_msecs_to_ticks(10) && maxRTT) {
ca->beta = (minRTT<<7)/maxRTT;
if (ca->beta < BETA_MIN)
ca->beta = BETA_MIN;
@ -2081,19 +2068,19 @@ htcp_alpha_update(struct htcp *ca)
if (diff > (uint32_t)hz) {
diff -= hz;
factor = 1+ ( 10*diff + ((diff/2)*(diff/2)/hz))/hz;
factor = 1+ (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz;
}
if (use_rtt_scaling && minRTT) {
uint32_t scale = (hz<<3)/(10*minRTT);
scale = min(max(scale, 1U<<2), 10U<<3); /* clamping ratio to interval [0.5,10]<<3 */
factor = (factor<<3)/scale;
if (!factor)
uint32_t scale = (hz << 3) / (10 * minRTT);
scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to interval [0.5,10]<<3 */
factor = (factor << 3) / scale;
if (factor != 0)
factor = 1;
}
ca->alpha = 2*factor*((1<<7)-ca->beta);
if (!ca->alpha)
ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
if (ca->alpha != 0)
ca->alpha = ALPHA_BASE;
}
@ -2131,10 +2118,10 @@ htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
{
/*-
* How to handle these functions?
* if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
* if (!tcp_is_cwnd_limited(sk, in_flight)) RRS - good question.
* return;
*/
if (net->cwnd <= net->ssthresh) {
if (net->cwnd <= net->ssthresh) {
/* We are in slow start */
if (net->flight_size + net->net_ack >= net->cwnd) {
if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) {
@ -2150,7 +2137,6 @@ htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
sctp_log_cwnd(stcb, net, net->net_ack,
SCTP_CWND_LOG_FROM_SS);
}
}
sctp_enforce_cwnd_limit(&stcb->asoc, net);
} else {
@ -2167,7 +2153,7 @@ htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
*/
/* What is snd_cwnd_cnt?? */
if (((net->partial_bytes_acked/net->mtu * net->cc_mod.htcp_ca.alpha) >> 7)*net->mtu >= net->cwnd) {
/*-
/*-
* Does SCTP have a cwnd clamp?
* if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS).
*/
@ -2238,7 +2224,6 @@ sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
/* update cwnd and Early FR */
/******************************/
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
#ifdef JANA_CMT_FAST_RECOVERY
/*
* CMT fast recovery code. Need to debug.
@ -2258,7 +2243,7 @@ sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
continue;
}
#ifdef JANA_CMT_FAST_RECOVERY
/* CMT fast recovery code
/* CMT fast recovery code
*/
/*
if (sctp_cmt_on_off > 0 && net->fast_retran_loss_recovery && net->will_exit_fast_recovery == 0) {
@ -2410,7 +2395,7 @@ sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
const struct sctp_cc_functions sctp_cc_functions[] = {
{
#if defined(__Windows__) || (defined(__Userspace_os_Windows) && !defined(__MINGW32__))
#if defined(_WIN32) && !defined(__MINGW32__)
sctp_set_initial_cc_param,
sctp_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common,
@ -2431,7 +2416,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif
},
{
#if defined(__Windows__) || (defined(__Userspace_os_Windows) && !defined(__MINGW32__))
#if defined(_WIN32) && !defined(__MINGW32__)
sctp_set_initial_cc_param,
sctp_hs_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common,
@ -2452,7 +2437,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif
},
{
#if defined(__Windows__) || (defined(__Userspace_os_Windows) && !defined(__MINGW32__))
#if defined(_WIN32) && !defined(__MINGW32__)
sctp_htcp_set_initial_cc_param,
sctp_htcp_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common,
@ -2473,7 +2458,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif
},
{
#if defined(__Windows__) || (defined(__Userspace_os_Windows) && !defined(__MINGW32__))
#if defined(_WIN32) && !defined(__MINGW32__)
sctp_set_rtcc_initial_cc_param,
sctp_cwnd_update_rtcc_after_sack,
sctp_cwnd_update_exit_pf_common,

View File

@ -32,18 +32,18 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_constants.h 343089 2019-01-16 11:33:47Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#ifndef _NETINET_SCTP_CONSTANTS_H_
#define _NETINET_SCTP_CONSTANTS_H_
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && defined(__Userspace__)
extern void getwintimeofday(struct timeval *tv);
#endif
#endif
/* IANA assigned port number for SCTP over UDP encapsulation */
#define SCTP_OVER_UDP_TUNNELING_PORT 9899
@ -92,13 +92,11 @@ extern void getwintimeofday(struct timeval *tv);
/* #define SCTP_AUDITING_ENABLED 1 used for debug/auditing */
#define SCTP_AUDIT_SIZE 256
#define SCTP_KTRHEAD_NAME "sctp_iterator"
#define SCTP_KTHREAD_PAGES 0
#define SCTP_MCORE_NAME "sctp_core_worker"
/* If you support Multi-VRF how big to
* make the initial array of VRF's to.
*/
@ -268,7 +266,6 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_LOCK_UNKNOWN 2
/* number of associations by default for zone allocation */
#define SCTP_MAX_NUM_OF_ASOC 40000
/* how many addresses per assoc remote and local */
@ -393,7 +390,6 @@ extern void getwintimeofday(struct timeval *tv);
#define IS_SCTP_CONTROL(a) (((a)->chunk_type != SCTP_DATA) && ((a)->chunk_type != SCTP_IDATA))
#define IS_SCTP_DATA(a) (((a)->chunk_type == SCTP_DATA) || ((a)->chunk_type == SCTP_IDATA))
/* SCTP parameter types */
/*************0x0000 series*************/
#define SCTP_HEARTBEAT_INFO 0x0001
@ -458,7 +454,6 @@ extern void getwintimeofday(struct timeval *tv);
/* mask to get sticky */
#define SCTP_STICKY_OPTIONS_MASK 0x0c
/*
* SCTP states for internal state machine
*/
@ -551,24 +546,22 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_TIMER_TYPE_ASCONF 10
#define SCTP_TIMER_TYPE_SHUTDOWNGUARD 11
#define SCTP_TIMER_TYPE_AUTOCLOSE 12
#define SCTP_TIMER_TYPE_EVENTWAKE 13
#define SCTP_TIMER_TYPE_STRRESET 14
#define SCTP_TIMER_TYPE_INPKILL 15
#define SCTP_TIMER_TYPE_ASOCKILL 16
#define SCTP_TIMER_TYPE_ADDR_WQ 17
#define SCTP_TIMER_TYPE_PRIM_DELETED 18
#define SCTP_TIMER_TYPE_STRRESET 13
#define SCTP_TIMER_TYPE_INPKILL 14
#define SCTP_TIMER_TYPE_ASOCKILL 15
#define SCTP_TIMER_TYPE_ADDR_WQ 16
#define SCTP_TIMER_TYPE_PRIM_DELETED 17
/* add new timers here - and increment LAST */
#define SCTP_TIMER_TYPE_LAST 19
#define SCTP_TIMER_TYPE_LAST 18
#define SCTP_IS_TIMER_TYPE_VALID(t) (((t) > SCTP_TIMER_TYPE_NONE) && \
((t) < SCTP_TIMER_TYPE_LAST))
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
/* Number of ticks to run the main timer at in msec */
#define SCTP_MAIN_TIMER_DEFAULT 10
#endif
#endif
/* max number of TSN's dup'd that I will hold */
#define SCTP_MAX_DUP_TSNS 20
@ -587,22 +580,7 @@ extern void getwintimeofday(struct timeval *tv);
* number of clusters as a base. This way high bandwidth environments will
* not get impacted by the lower bandwidth sending a bunch of 1 byte chunks
*/
#ifdef __Panda__
#define SCTP_ASOC_MAX_CHUNKS_ON_QUEUE 10240
#else
#define SCTP_ASOC_MAX_CHUNKS_ON_QUEUE 512
#endif
/* The conversion from time to ticks and vice versa is done by rounding
* upwards. This way we can test in the code the time to be positive and
* know that this corresponds to a positive number of ticks.
*/
#define MSEC_TO_TICKS(x) ((hz == 1000) ? x : ((((x) * hz) + 999) / 1000))
#define TICKS_TO_MSEC(x) ((hz == 1000) ? x : ((((x) * 1000) + (hz - 1)) / hz))
#define SEC_TO_TICKS(x) ((x) * hz)
#define TICKS_TO_SEC(x) (((x) + (hz - 1)) / hz)
/*
* Basically the minimum amount of time before I do a early FR. Making this
@ -632,8 +610,7 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_RTO_UPPER_BOUND (60000) /* 60 sec in ms */
#define SCTP_RTO_LOWER_BOUND (1000) /* 1 sec is ms */
#define SCTP_RTO_INITIAL (3000) /* 3 sec in ms */
#define SCTP_RTO_INITIAL (1000) /* 1 sec in ms */
#define SCTP_INP_KILL_TIMEOUT 20 /* number of ms to retry kill of inpcb */
#define SCTP_ASOC_KILL_TIMEOUT 10 /* number of ms to retry kill of inpcb */
@ -645,7 +622,6 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_DEF_PMTU_RAISE_SEC 600 /* 10 min between raise attempts */
/* How many streams I request initially by default */
#define SCTP_OSTREAM_INITIAL 10
#define SCTP_ISTREAM_INITIAL 2048
@ -728,7 +704,6 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_NUMBER_OF_SECRETS 8 /* or 8 * 4 = 32 octets */
#define SCTP_SECRET_SIZE 32 /* number of octets in a 256 bits */
/*
* SCTP upper layer notifications
*/
@ -759,6 +734,7 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_NOTIFY_NO_PEER_AUTH 25
#define SCTP_NOTIFY_SENDER_DRY 26
#define SCTP_NOTIFY_REMOTE_ERROR 27
#define SCTP_NOTIFY_ASSOC_TIMEDOUT 28
/* This is the value for messages that are NOT completely
* copied down where we will start to split the message.
@ -769,7 +745,11 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_DEFAULT_SPLIT_POINT_MIN 2904
/* Maximum length of diagnostic information in error causes */
#if defined(__Userspace__)
#define SCTP_DIAG_INFO_LEN 256
#else
#define SCTP_DIAG_INFO_LEN 128
#endif
/* ABORT CODES and other tell-tale location
* codes are generated by adding the below
@ -787,9 +767,8 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_FROM_SCTP_ASCONF 0x80000000
#define SCTP_FROM_SCTP_OUTPUT 0x90000000
#define SCTP_FROM_SCTP_PEELOFF 0xa0000000
#define SCTP_FROM_SCTP_PANDA 0xb0000000
#define SCTP_FROM_SCTP_SYSCTL 0xc0000000
#define SCTP_FROM_SCTP_CC_FUNCTIONS 0xd0000000
#define SCTP_FROM_SCTP_SYSCTL 0xb0000000
#define SCTP_FROM_SCTP_CC_FUNCTIONS 0xc0000000
/* Location ID's */
#define SCTP_LOC_1 0x00000001
@ -827,7 +806,8 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_LOC_33 0x00000021
#define SCTP_LOC_34 0x00000022
#define SCTP_LOC_35 0x00000023
#define SCTP_LOC_36 0x00000024
#define SCTP_LOC_37 0x00000025
/* Free assoc codes */
#define SCTP_NORMAL_PROC 0
@ -847,7 +827,6 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_DONOT_SETSCOPE 0
#define SCTP_DO_SETSCOPE 1
/* This value determines the default for when
* we try to add more on the send queue., if
* there is room. This prevents us from cycling
@ -874,7 +853,7 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_CHUNKQUEUE_SCALE 10
#endif
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* clock variance is 1 ms */
#define SCTP_CLOCK_GRANULARITY 1
#else
@ -930,7 +909,6 @@ extern void getwintimeofday(struct timeval *tv);
} \
} while (0)
#define SCTP_RETRAN_DONE -1
#define SCTP_RETRAN_EXIT -2
@ -981,12 +959,11 @@ extern void getwintimeofday(struct timeval *tv);
/*-
* defines for socket lock states.
* Used by __APPLE__ and SCTP_SO_LOCK_TESTING
* Used by __APPLE__
*/
#define SCTP_SO_LOCKED 1
#define SCTP_SO_NOT_LOCKED 0
/*-
* For address locks, do we hold the lock?
*/
@ -1012,7 +989,7 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_SOCKET_OPTION_LIMIT (64 * 1024)
#if defined(__Userspace__)
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SCTP_GETTIME_TIMEVAL(x) getwintimeofday(x)
#define SCTP_GETPTIME_TIMEVAL(x) getwintimeofday(x) /* this doesn't seem to ever be used.. */
#else
@ -1020,7 +997,6 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_GETPTIME_TIMEVAL(x) gettimeofday(x, NULL)
#endif
#endif
#if defined(_KERNEL)
#define SCTP_GETTIME_TIMEVAL(x) (getmicrouptime(x))
#define SCTP_GETPTIME_TIMEVAL(x) (microuptime(x))
@ -1036,11 +1012,11 @@ do { \
} \
} while (0)
#if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
#define sctp_sowwakeup_locked(inp, so) \
do { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \
SOCKBUF_UNLOCK(&((so)->so_snd)); \
SOCKBUF_UNLOCK(&((so)->so_snd)); \
inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEOUTPUT; \
} else { \
sowwakeup_locked(so); \
@ -1050,7 +1026,7 @@ do { \
#define sctp_sowwakeup_locked(inp, so) \
do { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \
SOCKBUF_UNLOCK(&((so)->so_snd)); \
SOCKBUF_UNLOCK(&((so)->so_snd)); \
inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEOUTPUT; \
} else { \
sowwakeup(so); \
@ -1067,12 +1043,12 @@ do { \
} \
} while (0)
#if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
#define sctp_sorwakeup_locked(inp, so) \
do { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \
inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEINPUT; \
SOCKBUF_UNLOCK(&((so)->so_rcv)); \
SOCKBUF_UNLOCK(&((so)->so_rcv)); \
} else { \
sorwakeup_locked(so); \
} \
@ -1083,7 +1059,7 @@ do { \
do { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \
inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEINPUT; \
SOCKBUF_UNLOCK(&((so)->so_rcv)); \
SOCKBUF_UNLOCK(&((so)->so_rcv)); \
} else { \
sorwakeup(so); \
} \

View File

@ -32,26 +32,22 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.c 352361 2019-09-15 18:29:45Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.c 362498 2020-06-22 14:36:14Z tuexen $");
#include "opt_sctp.h"
#if defined(__FreeBSD__)
#include <sys/gsb_crc32.h>
#endif
#ifdef SCTP
#include <netinet/sctp_os.h>
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#include <netinet/sctp_pcb.h>
#else
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/gsb_crc32.h>
#include <sys/mbuf.h>
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#if defined(SCTP) || defined(SCTP_SUPPORT)
#include <netinet/sctp_os.h>
#include <netinet/sctp_pcb.h>
#endif
#else
#include <netinet/sctp_os.h>
@ -60,7 +56,7 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.c 352361 2019-09-15 18:29:45Z tu
#include <netinet/sctp_pcb.h>
#endif
#if !defined(__FreeBSD__)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
/**
*
* Routine Description:
@ -799,8 +795,11 @@ sctp_calculate_cksum(struct mbuf *m, uint32_t offset)
return (base);
}
#if defined(__FreeBSD__)
#ifdef SCTP
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SCTP) || defined(SCTP_SUPPORT)
VNET_DEFINE(struct sctp_base_info, system_base_info);
/*
* Compute and insert the SCTP checksum in network byte order for a given
* mbuf chain m which contains an SCTP packet starting at offset.

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.h 327200 2017-12-26 12:35:02Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.h 362338 2020-06-18 19:32:34Z markj $");
#endif
#ifndef _NETINET_SCTP_CRC32_H_
@ -42,8 +42,8 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.h 327200 2017-12-26 12:35:02Z tu
#if defined(_KERNEL)
uint32_t sctp_calculate_cksum(struct mbuf *, uint32_t);
#if defined(__FreeBSD__)
#ifdef SCTP
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SCTP) || defined(SCTP_SUPPORT)
void sctp_delayed_cksum(struct mbuf *, uint32_t offset);
#endif
#endif

View File

@ -32,24 +32,24 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 309682 2016-12-07 19:30:59Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 366114 2020-09-24 12:26:06Z tuexen $");
#endif
#ifndef _NETINET_SCTP_HEADER_H_
#define _NETINET_SCTP_HEADER_H_
#if defined(__Windows__) && !defined(__Userspace_os_Windows)
#if defined(_WIN32) && !defined(__Userspace__)
#include <packon.h>
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#include <sys/time.h>
#endif
#include <netinet/sctp.h>
#include <netinet/sctp_constants.h>
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#define SCTP_PACKED __attribute__((packed))
#else
#pragma pack (push, 1)
@ -66,7 +66,6 @@ struct sctp_ipv4addr_param {
#define SCTP_V6_ADDR_BYTES 16
struct sctp_ipv6addr_param {
struct sctp_paramhdr ph;/* type=SCTP_IPV6_PARAM_TYPE, len=20 */
uint8_t addr[SCTP_V6_ADDR_BYTES]; /* IPV6 address */
@ -110,14 +109,12 @@ struct sctp_heartbeat_info_param {
char address[SCTP_ADDRMAX];
} SCTP_PACKED;
/* draft-ietf-tsvwg-prsctp */
/* PR-SCTP supported parameter */
struct sctp_prsctp_supported_param {
struct sctp_paramhdr ph;
} SCTP_PACKED;
/* draft-ietf-tsvwg-addip-sctp */
struct sctp_asconf_paramhdr { /* an ASCONF "parameter" */
struct sctp_paramhdr ph;/* a SCTP parameter header */
@ -129,14 +126,12 @@ struct sctp_asconf_addr_param { /* an ASCONF address parameter */
struct sctp_ipv6addr_param addrp; /* max storage size */
} SCTP_PACKED;
struct sctp_asconf_tag_param { /* an ASCONF NAT-Vtag parameter */
struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
uint32_t local_vtag;
uint32_t remote_vtag;
uint32_t local_vtag;
uint32_t remote_vtag;
} SCTP_PACKED;
struct sctp_asconf_addrv4_param { /* an ASCONF address (v4) parameter */
struct sctp_asconf_paramhdr aph; /* asconf "parameter" */
struct sctp_ipv4addr_param addrp; /* max storage size */
@ -149,7 +144,6 @@ struct sctp_supported_chunk_types_param {
uint8_t chunk_types[];
} SCTP_PACKED;
/*
* Structures for DATA chunks
*/
@ -260,7 +254,6 @@ struct sctp_init_msg {
#define sctp_init_ack_chunk sctp_init_chunk
#define sctp_init_ack_msg sctp_init_msg
/* Selective Ack (SACK) */
struct sctp_gap_ack_block {
uint16_t start; /* Gap Ack block start */
@ -297,7 +290,6 @@ struct sctp_nr_sack_chunk {
struct sctp_nr_sack nr_sack;
} SCTP_PACKED;
/* Heartbeat Request (HEARTBEAT) */
struct sctp_heartbeat {
struct sctp_heartbeat_info_param hb_info;
@ -312,7 +304,6 @@ struct sctp_heartbeat_chunk {
#define sctp_heartbeat_ack sctp_heartbeat
#define sctp_heartbeat_ack_chunk sctp_heartbeat_chunk
/* Abort Asssociation (ABORT) */
struct sctp_abort_chunk {
struct sctp_chunkhdr ch;
@ -324,27 +315,23 @@ struct sctp_abort_msg {
struct sctp_abort_chunk msg;
} SCTP_PACKED;
/* Shutdown Association (SHUTDOWN) */
struct sctp_shutdown_chunk {
struct sctp_chunkhdr ch;
uint32_t cumulative_tsn_ack;
} SCTP_PACKED;
/* Shutdown Acknowledgment (SHUTDOWN ACK) */
struct sctp_shutdown_ack_chunk {
struct sctp_chunkhdr ch;
} SCTP_PACKED;
/* Operation Error (ERROR) */
struct sctp_error_chunk {
struct sctp_chunkhdr ch;
/* optional error causes follow */
} SCTP_PACKED;
/* Cookie Echo (COOKIE ECHO) */
struct sctp_cookie_echo_chunk {
struct sctp_chunkhdr ch;
@ -436,7 +423,6 @@ struct sctp_chunk_desc {
uint32_t tsn_ifany;
} SCTP_PACKED;
struct sctp_pktdrop_chunk {
struct sctp_chunkhdr ch;
uint32_t bottle_bw;
@ -487,10 +473,10 @@ struct sctp_stream_reset_response_tsn {
} SCTP_PACKED;
struct sctp_stream_reset_add_strm {
struct sctp_paramhdr ph;
uint32_t request_seq;
uint16_t number_of_streams;
uint16_t reserved;
struct sctp_paramhdr ph;
uint32_t request_seq;
uint16_t number_of_streams;
uint16_t reserved;
} SCTP_PACKED;
#define SCTP_STREAM_RESET_RESULT_NOTHING_TO_DO 0x00000000 /* XXX: unused */
@ -563,48 +549,46 @@ struct sctp_auth_chunk {
#ifndef SCTP_MAX_OVERHEAD
#ifdef INET6
#define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
sizeof(struct sctphdr) + \
sizeof(struct sctp_ecne_chunk) + \
sizeof(struct sctp_sack_chunk) + \
sizeof(struct ip6_hdr))
sizeof(struct sctphdr) + \
sizeof(struct sctp_ecne_chunk) + \
sizeof(struct sctp_sack_chunk) + \
sizeof(struct ip6_hdr))
#define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
sizeof(struct sctphdr) + \
sizeof(struct ip6_hdr))
sizeof(struct sctphdr) + \
sizeof(struct ip6_hdr))
#define SCTP_MIN_OVERHEAD (sizeof(struct ip6_hdr) + \
sizeof(struct sctphdr))
sizeof(struct sctphdr))
#else
#define SCTP_MAX_OVERHEAD (sizeof(struct sctp_data_chunk) + \
sizeof(struct sctphdr) + \
sizeof(struct sctp_ecne_chunk) + \
sizeof(struct sctp_sack_chunk) + \
sizeof(struct ip))
sizeof(struct sctphdr) + \
sizeof(struct sctp_ecne_chunk) + \
sizeof(struct sctp_sack_chunk) + \
sizeof(struct ip))
#define SCTP_MED_OVERHEAD (sizeof(struct sctp_data_chunk) + \
sizeof(struct sctphdr) + \
sizeof(struct ip))
sizeof(struct sctphdr) + \
sizeof(struct ip))
#define SCTP_MIN_OVERHEAD (sizeof(struct ip) + \
sizeof(struct sctphdr))
sizeof(struct sctphdr))
#endif /* INET6 */
#endif /* !SCTP_MAX_OVERHEAD */
#define SCTP_MED_V4_OVERHEAD (sizeof(struct sctp_data_chunk) + \
sizeof(struct sctphdr) + \
sizeof(struct ip))
sizeof(struct sctphdr) + \
sizeof(struct ip))
#define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
sizeof(struct sctphdr))
sizeof(struct sctphdr))
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
#include <packoff.h>
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && defined(__Userspace__)
#pragma pack(pop)
#endif
#undef SCTP_PACKED

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.h 351655 2019-09-01 10:39:16Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_INDATA_H_
@ -44,12 +44,11 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.h 351655 2019-09-01 10:39:16Z t
struct sctp_queued_to_read *
sctp_build_readq_entry(struct sctp_tcb *stcb,
struct sctp_nets *net,
uint32_t tsn, uint32_t ppid,
uint32_t context, uint16_t sid,
uint32_t mid, uint8_t flags,
struct mbuf *dm);
struct sctp_nets *net,
uint32_t tsn, uint32_t ppid,
uint32_t context, uint16_t sid,
uint32_t mid, uint8_t flags,
struct mbuf *dm);
#define sctp_build_readq_entry_mac(_ctl, in_it, context, net, tsn, ppid, sid, flags, dm, tfsn, mid) do { \
if (_ctl) { \
@ -70,14 +69,15 @@ sctp_build_readq_entry(struct sctp_tcb *stcb,
(_ctl)->data = dm; \
(_ctl)->stcb = (in_it); \
(_ctl)->port_from = (in_it)->rport; \
if ((in_it)->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { \
(_ctl)->do_not_ref_stcb = 1; \
}\
} \
} while (0)
struct mbuf *
sctp_build_ctl_nchunk(struct sctp_inpcb *inp,
struct sctp_sndrcvinfo *sinfo);
struct sctp_sndrcvinfo *sinfo);
void sctp_set_rwnd(struct sctp_tcb *, struct sctp_association *);
@ -86,7 +86,7 @@ sctp_calc_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc);
void
sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack,
uint32_t rwnd, int *abort_now, int ecne_seen);
uint32_t rwnd, int *abort_now, int ecne_seen);
void
sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup,
@ -98,7 +98,7 @@ sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup,
/* draft-ietf-tsvwg-usctp */
void
sctp_handle_forward_tsn(struct sctp_tcb *,
struct sctp_forward_tsn_chunk *, int *, struct mbuf *, int);
struct sctp_forward_tsn_chunk *, int *, struct mbuf *, int);
struct sctp_tmit_chunk *
sctp_try_advance_peer_ack_point(struct sctp_tcb *, struct sctp_association *);
@ -110,8 +110,8 @@ sctp_update_acked(struct sctp_tcb *, struct sctp_shutdown_chunk *, int *);
int
sctp_process_data(struct mbuf **, int, int *, int,
struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *, uint32_t *);
struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *, uint32_t *);
void sctp_slide_mapping_arrays(struct sctp_tcb *stcb);

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.h 326672 2017-12-07 22:19:08Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_INPUT_H_
@ -47,7 +47,7 @@ sctp_common_input_processing(struct mbuf **, int, int, int,
struct sctphdr *, struct sctp_chunkhdr *,
uint8_t,
uint8_t,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
@ -56,9 +56,9 @@ struct sctp_stream_reset_request *
sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq,
struct sctp_tmit_chunk **bchk);
void sctp_reset_in_stream(struct sctp_tcb *stcb, uint32_t number_entries,
uint16_t *list);
void
sctp_reset_in_stream(struct sctp_tcb *stcb, uint32_t number_entries,
uint16_t *list);
int sctp_is_there_unsent_data(struct sctp_tcb *stcb, int so_locked);

View File

@ -33,7 +33,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#endif
@ -63,12 +63,15 @@ __FBSDID("$FreeBSD$");
#define SCTP_INP_INFO_TRYLOCK() 1
#define SCTP_INP_INFO_RUNLOCK()
#define SCTP_INP_INFO_WUNLOCK()
#define SCTP_INP_INFO_LOCK_ASSERT()
#define SCTP_INP_INFO_RLOCK_ASSERT()
#define SCTP_INP_INFO_WLOCK_ASSERT()
#define SCTP_WQ_ADDR_INIT()
#define SCTP_WQ_ADDR_DESTROY()
#define SCTP_WQ_ADDR_LOCK()
#define SCTP_WQ_ADDR_UNLOCK()
#define SCTP_WQ_ADDR_LOCK_ASSERT()
#define SCTP_IPI_ADDR_INIT()
#define SCTP_IPI_ADDR_DESTROY()
@ -76,20 +79,19 @@ __FBSDID("$FreeBSD$");
#define SCTP_IPI_ADDR_WLOCK()
#define SCTP_IPI_ADDR_RUNLOCK()
#define SCTP_IPI_ADDR_WUNLOCK()
#define SCTP_IPI_ADDR_LOCK_ASSERT()
#define SCTP_IPI_ADDR_WLOCK_ASSERT()
#define SCTP_IPI_ITERATOR_WQ_INIT()
#define SCTP_IPI_ITERATOR_WQ_DESTROY()
#define SCTP_IPI_ITERATOR_WQ_LOCK()
#define SCTP_IPI_ITERATOR_WQ_UNLOCK()
#define SCTP_IP_PKTLOG_INIT()
#define SCTP_IP_PKTLOG_LOCK()
#define SCTP_IP_PKTLOG_UNLOCK()
#define SCTP_IP_PKTLOG_DESTROY()
#define SCTP_INP_READ_INIT(_inp)
#define SCTP_INP_READ_DESTROY(_inp)
#define SCTP_INP_READ_LOCK(_inp)
@ -100,9 +102,10 @@ __FBSDID("$FreeBSD$");
#define SCTP_INP_LOCK_DESTROY(_inp)
#define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp)
#define SCTP_INP_RLOCK(_inp)
#define SCTP_INP_WLOCK(_inp)
#define SCTP_INP_RLOCK_ASSERT(_inp)
#define SCTP_INP_WLOCK_ASSERT(_inp)
#define SCTP_INP_LOCK_CONTENDED(_inp) (0) /* Don't know if this is possible */
@ -214,14 +217,6 @@ __FBSDID("$FreeBSD$");
} while (0)
/* not sure if __Userspace__ needs these (but copied nonetheless...) */
#if defined(SCTP_SO_LOCK_TESTING)
#define SCTP_INP_SO(sctpinp) (sctpinp)->ip_inp.inp.inp_socket
#define SCTP_SOCKET_LOCK(so, refcnt)
#define SCTP_SOCKET_UNLOCK(so, refcnt)
#endif
/* these were in sctp_lock_empty.h but aren't in sctp_lock_bsd.h ... */
#if 0
#define SCTP_IPI_ADDR_LOCK()

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_os.h 235828 2012-05-23 11:26:28Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_os.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_OS_H_
@ -64,25 +64,18 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_os.h 235828 2012-05-23 11:26:28Z tuexe
* SCTP_ZONE_DESTROY(zone)
*/
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/sctp_os_bsd.h>
#else
#define MODULE_GLOBAL(_B) (_B)
#endif
#if defined(__Userspace__)
#include <netinet/sctp_os_userspace.h>
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#include <netinet/sctp_os_macosx.h>
#endif
#if defined(__Panda__)
#include <ip/sctp/sctp_os_iox.h>
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
#include <netinet/sctp_os_windows.h>
#endif

View File

@ -43,7 +43,7 @@
#include <errno.h>
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
@ -83,28 +83,24 @@ typedef HANDLE userland_thread_t;
#if !defined(_MSC_VER) || (_MSC_VER >= 1600)
#include <stdint.h>
#else
#define uint64_t unsigned __int64
#define uint32_t unsigned __int32
#define int32_t __int32
#define uint16_t unsigned __int16
#define int16_t __int16
#define uint8_t unsigned __int8
#define int8_t __int8
typedef unsigned __int64 uint64_t;
typedef unsigned __int32 uint32_t;
typedef __int32 int32_t;
typedef unsigned __int16 uint16_t;
typedef __int16 int16_t;
typedef unsigned __int8 uint8_t;
typedef __int8 int8_t;
#endif
#ifndef _SIZE_T_DEFINED
#define size_t __int32
#typedef __int32 size_t;
#endif
typedef unsigned __int32 u_int;
typedef unsigned char u_char;
typedef unsigned __int16 u_short;
typedef unsigned __int8 sa_family_t;
#ifndef _SSIZE_T_DEFINED
typedef __int64 ssize_t;
#endif
#define u_long unsigned __int64
#define u_int unsigned __int32
#define u_int32_t unsigned __int32
#define u_int16_t unsigned __int16
#define u_int8_t unsigned __int8
#define u_char unsigned char
#define n_short unsigned __int16
#define u_short unsigned __int16
#define n_time unsigned __int32
#define sa_family_t unsigned __int8
#define ssize_t __int64
#if !defined(__MINGW32__)
#define __func__ __FUNCTION__
#endif
@ -221,9 +217,19 @@ typedef char* caddr_t;
#define bzero(buf, len) memset(buf, 0, len)
#define bcopy(srcKey, dstKey, len) memcpy(dstKey, srcKey, len)
#if defined(_MSC_VER) && (_MSC_VER < 1900) && !defined(__MINGW32__)
#define snprintf(data, size, format, ...) _snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__)
#define SCTP_SNPRINTF(data, size, format, ...) \
if (_snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__) < 0) { \
data[0] = '\0'; \
}
#else
#define SCTP_SNPRINTF(data, ...) \
if (snprintf(data, __VA_ARGS__) < 0 ) { \
data[0] = '\0'; \
}
#endif
#define inline __inline
#define __inline__ __inline
#define MSG_EOR 0x8 /* data completes record */
@ -277,15 +283,19 @@ typedef char* caddr_t;
#else /* !defined(Userspace_os_Windows) */
#include <sys/socket.h>
#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_NaCl) || defined(__Userspace_os_Fuchsia)
#include <pthread.h>
#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__)
#error "Unsupported build configuration."
#endif
#include <pthread.h>
typedef pthread_mutex_t userland_mutex_t;
typedef pthread_cond_t userland_cond_t;
typedef pthread_t userland_thread_t;
#endif
#if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
#if defined(_WIN32) || defined(__native_client__)
#define IFNAMSIZ 64
@ -379,43 +389,9 @@ struct ifkpi {
int ifk_value;
} ifk_data;
};
struct ifreq {
char ifr_name[16];
union {
struct sockaddr ifru_addr;
struct sockaddr ifru_dstaddr;
struct sockaddr ifru_broadaddr;
short ifru_flags;
int ifru_metric;
int ifru_mtu;
int ifru_phys;
int ifru_media;
int ifru_intval;
char* ifru_data;
struct ifdevmtu ifru_devmtu;
struct ifkpi ifru_kpi;
uint32_t ifru_wake_flags;
} ifr_ifru;
#define ifr_addr ifr_ifru.ifru_addr
#define ifr_dstaddr ifr_ifru.ifru_dstaddr
#define ifr_broadaddr ifr_ifru.ifru_broadaddr
#define ifr_flags ifr_ifru.ifru_flags[0]
#define ifr_prevflags ifr_ifru.ifru_flags[1]
#define ifr_metric ifr_ifru.ifru_metric
#define ifr_mtu ifr_ifru.ifru_mtu
#define ifr_phys ifr_ifru.ifru_phys
#define ifr_media ifr_ifru.ifru_media
#define ifr_data ifr_ifru.ifru_data
#define ifr_devmtu ifr_ifru.ifru_devmtu
#define ifr_intval ifr_ifru.ifru_intval
#define ifr_kpi ifr_ifru.ifru_kpi
#define ifr_wake_flags ifr_ifru.ifru_wake_flags
};
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
int Win_getifaddrs(struct ifaddrs**);
#define getifaddrs(interfaces) (int)Win_getifaddrs(interfaces)
int win_if_nametoindex(const char *);
@ -426,9 +402,9 @@ int win_if_nametoindex(const char *);
#define mtx_unlock(arg1)
#define mtx_assert(arg1,arg2)
#define MA_OWNED 7 /* sys/mutex.h typically on FreeBSD */
#if !defined(__Userspace_os_FreeBSD)
#if !defined(__FreeBSD__)
struct mtx {int dummy;};
#if !defined(__Userspace_os_NetBSD)
#if !defined(__NetBSD__)
struct selinfo {int dummy;};
#endif
struct sx {int dummy;};
@ -436,6 +412,7 @@ struct sx {int dummy;};
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
/* #include <sys/param.h> in FreeBSD defines MSIZE */
/* #include <sys/ktr.h> */
/* #include <sys/systm.h> */
@ -458,22 +435,22 @@ struct sx {int dummy;};
#include <user_mbuf.h>
/* #include <sys/uio.h> */
/* #include <sys/lock.h> */
#if defined(__FreeBSD__) && __FreeBSD_version > 602000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/rwlock.h>
#endif
/* #include <sys/kthread.h> */
#if defined(__FreeBSD__) && __FreeBSD_version > 602000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/priv.h>
#endif
/* #include <sys/random.h> */
#include <limits.h>
/* #include <machine/cpu.h> */
#if defined(__Userspace_os_Darwin)
#if defined(__APPLE__)
/* was a 0 byte file. needed for structs if_data(64) and net_event_data */
#include <net/if_var.h>
#endif
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <net/if_types.h>
/* #include <net/if_var.h> was a 0 byte file. causes struct mtx redefinition */
#endif
@ -481,7 +458,7 @@ struct sx {int dummy;};
* userspace as well? */
/* on FreeBSD, this results in a redefintion of struct route */
/* #include <net/route.h> */
#if !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl)
#if !defined(_WIN32) && !defined(__native_client__)
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -497,7 +474,7 @@ struct sx {int dummy;};
/* for getifaddrs */
#include <sys/types.h>
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#if defined(INET) || defined(INET6)
#include <ifaddrs.h>
#endif
@ -507,6 +484,8 @@ struct sx {int dummy;};
/* for close, etc. */
#include <unistd.h>
/* for gettimeofday */
#include <sys/time.h>
#endif
/* lots of errno's used and needed in userspace */
@ -514,7 +493,7 @@ struct sx {int dummy;};
/* for offsetof */
#include <stddef.h>
#if defined(SCTP_PROCESS_LEVEL_LOCKS) && !defined(__Userspace_os_Windows)
#if defined(SCTP_PROCESS_LEVEL_LOCKS) && !defined(_WIN32)
/* for pthread_mutex_lock, pthread_mutex_unlock, etc. */
#include <pthread.h>
#endif
@ -525,21 +504,21 @@ struct sx {int dummy;};
#endif /* IPSEC */
#ifdef INET6
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <sys/domain.h>
#endif
#ifdef IPSEC
#include <netipsec/ipsec6.h>
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#include <netinet/ip6.h>
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_Windows)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(_WIN32) || defined(__EMSCRIPTEN__)
#include "user_ip6_var.h"
#else
#include <netinet6/ip6_var.h>
#endif
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <netinet6/in6_pcb.h>
#include <netinet6/ip6protosw.h>
/* #include <netinet6/nd6.h> was a 0 byte file */
@ -554,7 +533,7 @@ struct sx {int dummy;};
#include "netinet/sctp_sha1.h"
#if __FreeBSD_version >= 700000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/ip_options.h>
#endif
@ -607,12 +586,12 @@ MALLOC_DECLARE(SCTP_M_SOCKOPT);
/*
*
*/
#if !defined(__Userspace_os_Darwin)
#if !defined(__APPLE__)
#define USER_ADDR_NULL (NULL) /* FIX ME: temp */
#endif
#if defined(SCTP_DEBUG)
#include <netinet/sctp_constants.h>
#if defined(SCTP_DEBUG)
#define SCTPDBG(level, ...) \
{ \
do { \
@ -666,7 +645,7 @@ MALLOC_DECLARE(SCTP_M_SOCKOPT);
#define SCTP_VRF_IFN_HASH_SIZE 3
#define SCTP_INIT_VRF_TABLEID(vrf)
#if !defined(__Userspace_os_Windows)
#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) */
@ -800,7 +779,7 @@ sctp_hashfreedestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask);
#define KTR_SUBSYS 1
/* The packed define for 64 bit platforms */
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#define SCTP_PACKED __attribute__((packed))
#define SCTP_UNUSED __attribute__((unused))
#else
@ -829,6 +808,13 @@ sctp_hashfreedestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask);
M_ALIGN(m, len); \
}
#if !defined(_WIN32)
#define SCTP_SNPRINTF(data, ...) \
if (snprintf(data, __VA_ARGS__) < 0) { \
data[0] = '\0'; \
}
#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
@ -887,7 +873,6 @@ static inline void sctp_userspace_rtfree(sctp_rtentry_t *rt)
return;
}
free(rt);
rt = NULL;
}
#define rtfree(arg1) sctp_userspace_rtfree(arg1)
@ -901,17 +886,13 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af);
#define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((rt != NULL) ? rt->rt_rmx.rmx_mtu : 0)
#define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) sctp_userspace_get_mtu_from_ifn(if_nametoindex(((struct ifaddrs *) (sctp_ifn))->ifa_name), AF_INET)
#define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) (sctp_ifn->ifn_mtu)
#define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \
if (rt != NULL) \
rt->rt_rmx.rmx_mtu = mtu; \
} while(0)
/* (de-)register interface event notifications */
#define SCTP_REGISTER_INTERFACE(ifhandle, af)
#define SCTP_DEREGISTER_INTERFACE(ifhandle, af)
/*************************/
/* These are for logging */
@ -961,7 +942,7 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af);
*/
/* get the v6 hop limit */
#define SCTP_GET_HLIM(inp, ro) 128 /* As done for __Windows__ */
#define SCTP_GET_HLIM(inp, ro) 128
#define IPv6_HOP_LIMIT 128
/* is the endpoint v6only? */
@ -1000,7 +981,7 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af);
/* sctp_pcb.h */
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SHUT_RD 1
#define SHUT_WR 2
#define SHUT_RDWR 3
@ -1087,12 +1068,12 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
/* with the current included files, this is defined in Linux but
* in FreeBSD, it is behind a _KERNEL in sys/socket.h ...
*/
#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_NaCl)
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__native_client__)
/* stolen from /usr/include/sys/socket.h */
#define CMSG_ALIGN(n) _ALIGN(n)
#elif defined(__Userspace_os_NetBSD)
#elif defined(__NetBSD__)
#define CMSG_ALIGN(n) (((n) + __ALIGNBYTES) & ~__ALIGNBYTES)
#elif defined(__Userspace_os_Darwin)
#elif defined(__APPLE__)
#if !defined(__DARWIN_ALIGNBYTES)
#define __DARWIN_ALIGNBYTES (sizeof(__darwin_size_t) - 1)
#endif
@ -1127,7 +1108,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
} while (0)
#endif
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#if !defined(TAILQ_FOREACH_SAFE)
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = ((head)->tqh_first); \
@ -1141,12 +1122,12 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
(var) = (tvar))
#endif
#endif
#if defined(__Userspace_os_DragonFly)
#if defined(__DragonFly__)
#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE
#define LIST_FOREACH_SAFE LIST_FOREACH_MUTABLE
#endif
#if defined(__Userspace_os_NaCl)
#if defined(__native_client__)
#define timercmp(tvp, uvp, cmp) \
(((tvp)->tv_sec == (uvp)->tv_sec) ? \
((tvp)->tv_usec cmp (uvp)->tv_usec) : \
@ -1155,7 +1136,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
#define SCTP_IS_LISTENING(inp) ((inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) != 0)
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NaCl) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_Windows) || defined(__Userspace_os_Fuchsia)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__linux__) || defined(__native_client__) || defined(__NetBSD__) || defined(_WIN32) || defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
int
timingsafe_bcmp(const void *, const void *, size_t);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.h 351654 2019-09-01 10:09:53Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.h 366114 2020-09-24 12:26:06Z tuexen $");
#endif
#ifndef _NETINET_SCTP_OUTPUT_H_
@ -44,45 +44,37 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_output.h 351654 2019-09-01 10:09:53Z t
#if defined(_KERNEL) || defined(__Userspace__)
struct mbuf *
sctp_add_addresses_to_i_ia(struct sctp_inpcb *inp,
struct sctp_tcb *stcb,
struct sctp_scoping *scope,
struct mbuf *m_at,
int cnt_inits_to,
uint16_t *padding_len, uint16_t *chunk_len);
struct sctp_scoping *scope,
struct mbuf *m_at,
int cnt_inits_to,
uint16_t *padding_len, uint16_t *chunk_len);
int sctp_is_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
int
sctp_is_address_in_scope(struct sctp_ifa *ifa,
struct sctp_scoping *scope,
int do_update);
int do_update);
int
sctp_is_addr_in_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa);
struct sctp_ifa *
sctp_source_address_selection(struct sctp_inpcb *inp,
struct sctp_tcb *stcb,
sctp_route_t *ro, struct sctp_nets *net,
int non_asoc_addr_ok, uint32_t vrf_id);
struct sctp_tcb *stcb,
sctp_route_t *ro, struct sctp_nets *net,
int non_asoc_addr_ok, uint32_t vrf_id);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Userspace__)
int
sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t *ro);
int
sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro);
int sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t *ro);
int sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro);
#endif
void sctp_send_initiate(struct sctp_inpcb *, struct sctp_tcb *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_send_initiate(struct sctp_inpcb *, struct sctp_tcb *, int);
void
sctp_send_initiate_ack(struct sctp_inpcb *, struct sctp_tcb *,
@ -90,31 +82,30 @@ sctp_send_initiate_ack(struct sctp_inpcb *, struct sctp_tcb *,
int, int,
struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct sctp_init_chunk *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t,
#endif
uint32_t, uint16_t);
struct mbuf *
sctp_arethere_unrecognized_parameters(struct mbuf *, int, int *,
struct sctp_chunkhdr *, int *, int *);
struct sctp_chunkhdr *, int *, int *);
void sctp_queue_op_err(struct sctp_tcb *, struct mbuf *);
int
sctp_send_cookie_echo(struct mbuf *, int, int, struct sctp_tcb *,
struct sctp_nets *);
struct sctp_nets *);
void sctp_send_cookie_ack(struct sctp_tcb *);
void
sctp_send_heartbeat_ack(struct sctp_tcb *, struct mbuf *, int, int,
struct sctp_nets *);
struct sctp_nets *);
void
sctp_remove_from_wheel(struct sctp_tcb *stcb,
struct sctp_association *asoc,
struct sctp_stream_out *strq, int holds_lock);
struct sctp_association *asoc,
struct sctp_stream_out *strq, int holds_lock);
void sctp_send_shutdown(struct sctp_tcb *, struct sctp_nets *);
@ -124,7 +115,7 @@ void sctp_send_shutdown_complete(struct sctp_tcb *, struct sctp_nets *, int);
void sctp_send_shutdown_complete2(struct sockaddr *, struct sockaddr *,
struct sctphdr *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
@ -143,16 +134,15 @@ void sctp_fix_ecn_echo(struct sctp_association *);
void sctp_move_chunks_from_net(struct sctp_tcb *stcb, struct sctp_nets *net);
#define SCTP_DATA_CHUNK_OVERHEAD(stcb) ((stcb)->asoc.idata_supported ? \
sizeof(struct sctp_idata_chunk) : \
sizeof(struct sctp_data_chunk))
sizeof(struct sctp_idata_chunk) : \
sizeof(struct sctp_data_chunk))
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int
sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct thread *, int);
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, PKTHREAD, int);
#else
@ -161,30 +151,15 @@ sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
#endif
int
sctp_output(struct sctp_inpcb *,
#if defined(__Panda__)
pakhandle_type,
#else
struct mbuf *,
#endif
struct sockaddr *,
#if defined(__Panda__)
pakhandle_type,
#else
struct mbuf *,
#endif
struct proc *, int);
#endif
void sctp_chunk_output(struct sctp_inpcb *, struct sctp_tcb *, int, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_send_abort_tcb(struct sctp_tcb *, struct mbuf *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_chunk_output(struct sctp_inpcb *, struct sctp_tcb *, int, int);
void sctp_send_abort_tcb(struct sctp_tcb *, struct mbuf *, int);
void send_forward_tsn(struct sctp_tcb *, struct sctp_association *);
@ -194,23 +169,19 @@ void sctp_send_hb(struct sctp_tcb *, struct sctp_nets *, int);
void sctp_send_ecn_echo(struct sctp_tcb *, struct sctp_nets *, uint32_t);
void
sctp_send_packet_dropped(struct sctp_tcb *, struct sctp_nets *, struct mbuf *,
int, int, int);
void sctp_send_cwr(struct sctp_tcb *, struct sctp_nets *, uint32_t, uint8_t);
void
sctp_add_stream_reset_result(struct sctp_tmit_chunk *, uint32_t, uint32_t);
void
sctp_send_deferred_reset_response(struct sctp_tcb *,
struct sctp_stream_reset_list *,
int);
struct sctp_stream_reset_list *,
int);
void
sctp_add_stream_reset_result_tsn(struct sctp_tmit_chunk *,
@ -225,17 +196,18 @@ sctp_send_str_reset_req(struct sctp_tcb *, uint16_t , uint16_t *,
void
sctp_send_abort(struct mbuf *, int, struct sockaddr *, struct sockaddr *,
struct sctphdr *, uint32_t, struct mbuf *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
void sctp_send_operr_to(struct sockaddr *, struct sockaddr *,
struct sctphdr *, uint32_t, struct mbuf *,
#if defined(__FreeBSD__)
uint8_t, uint32_t, uint16_t,
void
sctp_send_operr_to(struct sockaddr *, struct sockaddr *,
struct sctphdr *, uint32_t, struct mbuf *,
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
uint32_t, uint16_t);
#endif /* _KERNEL || __Userspace__ */
@ -244,20 +216,15 @@ int
sctp_sosend(struct socket *so,
struct sockaddr *addr,
struct uio *uio,
#ifdef __Panda__
pakhandle_type top,
pakhandle_type control,
#else
struct mbuf *top,
struct mbuf *control,
#endif
#if defined(__APPLE__) || defined(__Panda__)
#if defined(__APPLE__) && !defined(__Userspace__)
int flags
#else
int flags,
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct thread *p
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
PKTHREAD p
#else
#if defined(__Userspace__)

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.h 354018 2019-10-24 09:22:23Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#ifndef _NETINET_SCTP_PCB_H_
@ -147,9 +147,8 @@ struct sctp_tagblock {
struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
};
struct sctp_epinfo {
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#ifdef INET
struct socket *udp4_tun_socket;
#endif
@ -189,7 +188,7 @@ struct sctp_epinfo {
struct sctppcbhead listhead;
struct sctpladdr addr_wq;
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
struct inpcbhead inplisthead;
struct inpcbinfo sctbinfo;
#endif
@ -204,18 +203,10 @@ struct sctp_epinfo {
sctp_zone_t ipi_zone_asconf;
sctp_zone_t ipi_zone_asconf_ack;
#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
#if __FreeBSD_version <= 602000
struct mtx ipi_ep_mtx;
#else
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct rwlock ipi_ep_mtx;
#endif
struct mtx ipi_iterator_wq_mtx;
#if __FreeBSD_version <= 602000
struct mtx ipi_addr_mtx;
#else
struct rwlock ipi_addr_mtx;
#endif
struct mtx ipi_pktlog_mtx;
struct mtx wq_addr_mtx;
#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
@ -224,7 +215,7 @@ struct sctp_epinfo {
userland_mutex_t ipi_count_mtx;
userland_mutex_t ipi_pktlog_mtx;
userland_mutex_t wq_addr_mtx;
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
#ifdef _KERN_LOCKS_H_
lck_mtx_t *ipi_addr_mtx;
lck_mtx_t *ipi_count_mtx;
@ -235,13 +226,12 @@ struct sctp_epinfo {
void *ipi_count_mtx;
void *logging_mtx;
#endif /* _KERN_LOCKS_H_ */
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
struct rwlock ipi_ep_lock;
struct rwlock ipi_addr_lock;
struct spinlock ipi_pktlog_mtx;
struct rwlock wq_addr_mtx;
#elif defined(__Userspace__)
/* TODO decide on __Userspace__ locks */
#endif
uint32_t ipi_count_ep;
@ -286,14 +276,17 @@ struct sctp_epinfo {
#endif
};
struct sctp_base_info {
/* All static structures that
* anchor the system must be here.
*/
struct sctp_epinfo sctppcbinfo;
#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
struct sctpstat *sctpstat;
#else
struct sctpstat sctpstat;
#endif
#else
struct sctpstat sctpstat;
#endif
@ -305,17 +298,19 @@ struct sctp_base_info {
int packet_log_end;
uint8_t packet_log_buffer[SCTP_PACKET_LOG_SIZE];
#endif
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
eventhandler_tag eh_tag;
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
int sctp_main_timer_ticks;
#endif
#if defined(__Userspace__)
userland_mutex_t timer_mtx;
userland_thread_t timer_thread;
int timer_thread_should_exit;
#if !defined(__Userspace_os_Windows)
int iterator_thread_started;
int timer_thread_started;
#if !defined(_WIN32)
pthread_mutexattr_t mtx_attr;
#if defined(INET) || defined(INET6)
int userspace_route;
@ -323,7 +318,7 @@ struct sctp_base_info {
#endif
#endif
#ifdef INET
#if defined(__Userspace_os_Windows) && !defined(__MINGW32__)
#if defined(_WIN32) && !defined(__MINGW32__)
SOCKET userspace_rawsctp;
SOCKET userspace_udpsctp;
#else
@ -334,7 +329,7 @@ struct sctp_base_info {
userland_thread_t recvthreadudp;
#endif
#ifdef INET6
#if defined(__Userspace_os_Windows) && !defined(__MINGW32__)
#if defined(_WIN32) && !defined(__MINGW32__)
SOCKET userspace_rawsctp6;
SOCKET userspace_udpsctp6;
#else
@ -361,11 +356,11 @@ struct sctp_pcb {
uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
unsigned int size_of_a_cookie;
unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
unsigned int sctp_minrto;
unsigned int sctp_maxrto;
unsigned int initial_rto;
int initial_init_rto_max;
uint32_t sctp_timeoutticks[SCTP_NUM_TMRS];
uint32_t sctp_minrto;
uint32_t sctp_maxrto;
uint32_t initial_rto;
uint32_t initial_init_rto_max;
unsigned int sctp_sack_freq;
uint32_t sctp_sws_sender;
@ -408,7 +403,7 @@ struct sctp_pcb {
uint32_t def_cookie_life;
/* defaults to 0 */
int auto_close_time;
uint32_t auto_close_time;
uint32_t initial_sequence_debug;
uint32_t adaptation_layer_indicator;
uint8_t adaptation_layer_indicator_provided;
@ -443,7 +438,6 @@ struct sctp_pcbtsn_rlog {
};
#define SCTP_READ_LOG_SIZE 135 /* we choose the number to make a pcb a page */
struct sctp_inpcb {
/*-
* put an inpcb in front of it all, kind of a waste but we need to
@ -454,8 +448,7 @@ struct sctp_inpcb {
char align[(sizeof(struct inpcb) + SCTP_ALIGNM1) &
~SCTP_ALIGNM1];
} ip_inp;
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
/* leave some space in case i386 inpcb is bigger than ppc */
uint8_t padding[128];
#endif
@ -464,7 +457,7 @@ struct sctp_inpcb {
struct sctp_readhead read_queue;
LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */
/* hash of all endpoints for model */
/* hash of all endpoints for model */
LIST_ENTRY(sctp_inpcb) sctp_hash;
/* count of local addresses bound, 0 if bound all */
int laddr_count;
@ -488,7 +481,6 @@ struct sctp_inpcb {
#ifdef SCTP_TRACK_FREED_ASOCS
struct sctpasochead sctp_asoc_free_list;
#endif
struct sctp_iterator *inp_starting_point_for_iterator;
uint32_t sctp_frag_point;
uint32_t partial_delivery_point;
uint32_t sctp_context;
@ -512,26 +504,9 @@ struct sctp_inpcb {
* they are candidates with sctp_sendm for
* de-supporting.
*/
#ifdef __Panda__
pakhandle_type pak_to_read;
pakhandle_type pak_to_read_sendq;
#endif
struct mbuf *pkt, *pkt_last;
struct mbuf *control;
#if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__))
#ifndef INP_IPV6
#define INP_IPV6 0x1
#endif
#ifndef INP_IPV4
#define INP_IPV4 0x2
#endif
uint8_t inp_vflag;
/* TODO __Userspace__ where is our inp_vlag going to be? */
uint8_t inp_ip_ttl;
uint8_t inp_ip_tos; /* defined as macro in user_inpcb.h */
uint8_t inp_ip_resv;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct mtx inp_mtx;
struct mtx inp_create_mtx;
struct mtx inp_rdata_mtx;
@ -541,7 +516,7 @@ struct sctp_inpcb {
userland_mutex_t inp_create_mtx;
userland_mutex_t inp_rdata_mtx;
int32_t refcount;
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
#if defined(SCTP_APPLE_RWLOCK)
lck_rw_t *inp_mtx;
#else
@ -549,16 +524,15 @@ struct sctp_inpcb {
#endif
lck_mtx_t *inp_create_mtx;
lck_mtx_t *inp_rdata_mtx;
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
struct rwlock inp_lock;
struct spinlock inp_create_lock;
struct spinlock inp_rdata_lock;
int32_t refcount;
#elif defined(__Userspace__)
/* TODO decide on __Userspace__ locks */
int32_t refcount;
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
int32_t refcount;
uint32_t lock_caller1;
@ -602,7 +576,7 @@ struct sctp_inpcb {
int (*recv_callback)(struct socket *, union sctp_sockstore, void *, size_t,
struct sctp_rcvinfo, int, void *);
uint32_t send_sb_threshold;
int (*send_callback)(struct socket *, uint32_t);
int (*send_callback)(struct socket *, uint32_t, void *);
#endif
};
@ -610,8 +584,9 @@ struct sctp_inpcb {
int register_recv_cb (struct socket *,
int (*)(struct socket *, union sctp_sockstore, void *, size_t,
struct sctp_rcvinfo, int, void *));
int register_send_cb (struct socket *, uint32_t, int (*)(struct socket *, uint32_t));
int register_send_cb (struct socket *, uint32_t, int (*)(struct socket *, uint32_t, void *));
int register_ulp_info (struct socket *, void *);
int retrieve_ulp_info (struct socket *, void **);
#endif
struct sctp_tcb {
@ -639,34 +614,30 @@ struct sctp_tcb {
int freed_from_where;
uint16_t rport; /* remote port in network format */
uint16_t resv;
#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct mtx tcb_mtx;
struct mtx tcb_send_mtx;
#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
userland_mutex_t tcb_mtx;
userland_mutex_t tcb_send_mtx;
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
lck_mtx_t* tcb_mtx;
lck_mtx_t* tcb_send_mtx;
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
struct spinlock tcb_lock;
struct spinlock tcb_send_lock;
#elif defined(__Userspace__)
/* TODO decide on __Userspace__ locks */
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
uint32_t caller1;
uint32_t caller2;
uint32_t caller3;
#endif
};
#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/sctp_lock_bsd.h>
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
/*
* Apple MacOS X 10.4 "Tiger"
*/
@ -677,7 +648,7 @@ struct sctp_tcb {
#include <netinet/sctp_process_lock.h>
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
#include <netinet/sctp_lock_windows.h>
@ -692,15 +663,14 @@ struct sctp_tcb {
#include <netinet/sctp_lock_empty.h>
#endif
/* TODO where to put non-_KERNEL things for __Userspace__? */
#if defined(_KERNEL) || defined(__Userspace__)
/* Attention Julian, this is the extern that
* goes with the base info. sctp_pcb.c has
* the real definition.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
VNET_DECLARE(struct sctp_base_info, system_base_info) ;
#if defined(__FreeBSD__) && !defined(__Userspace__)
VNET_DECLARE(struct sctp_base_info, system_base_info);
#else
extern struct sctp_base_info system_base_info;
#endif
@ -742,26 +712,35 @@ void sctp_update_ifn_mtu(uint32_t ifn_index, uint32_t mtu);
void sctp_free_ifn(struct sctp_ifn *sctp_ifnp);
void sctp_free_ifa(struct sctp_ifa *sctp_ifap);
void sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr,
uint32_t ifn_index, const char *if_name);
struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t);
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
int sctp_inpcb_bind(struct socket *, struct sockaddr *,
struct sctp_ifa *,struct thread *);
#elif defined(__Windows__)
int sctp_inpcb_bind(struct socket *, struct sockaddr *,
struct sctp_ifa *,PKTHREAD);
#if defined(__FreeBSD__) && !defined(__Userspace__)
int
sctp_inpcb_bind(struct socket *, struct sockaddr *,
struct sctp_ifa *, struct thread *);
int
sctp_inpcb_bind_locked(struct sctp_inpcb *, struct sockaddr *,
struct sctp_ifa *, struct thread *);
#elif defined(_WIN32) && !defined(__Userspace__)
int
sctp_inpcb_bind(struct socket *, struct sockaddr *,
struct sctp_ifa *, PKTHREAD);
int
sctp_inpcb_bind_locked(struct sctp_inpcb *, struct sockaddr *,
struct sctp_ifa *, PKTHREAD);
#else
/* struct proc is a dummy for __Userspace__ */
int sctp_inpcb_bind(struct socket *, struct sockaddr *,
struct sctp_ifa *, struct proc *);
int
sctp_inpcb_bind(struct socket *, struct sockaddr *,
struct sctp_ifa *, struct proc *);
int
sctp_inpcb_bind_locked(struct sctp_inpcb *, struct sockaddr *,
struct sctp_ifa *, struct proc *);
#endif
struct sctp_tcb *
@ -809,33 +788,34 @@ void sctp_inpcb_free(struct sctp_inpcb *, int, int);
#define SCTP_DONT_INITIALIZE_AUTH_PARAMS 0
#define SCTP_INITIALIZE_AUTH_PARAMS 1
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct sctp_tcb *
sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
int *, uint32_t, uint32_t, uint16_t, uint16_t, struct thread *,
int);
#elif defined(__Windows__)
int *, uint32_t, uint32_t, uint32_t, uint16_t, uint16_t,
struct thread *, int);
struct sctp_tcb *
sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
int *, uint32_t, uint32_t, uint16_t, uint16_t, PKTHREAD, int);
sctp_aloc_assoc_connected(struct sctp_inpcb *, struct sockaddr *,
int *, uint32_t, uint32_t, uint32_t, uint16_t, uint16_t,
struct thread *, int);
#elif defined(_WIN32) && !defined(__Userspace__)
struct sctp_tcb *
sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, int *, uint32_t,
uint32_t, uint32_t, uint16_t, uint16_t, PKTHREAD, int);
struct sctp_tcb *
sctp_aloc_assoc_connected(struct sctp_inpcb *, struct sockaddr *, int *, uint32_t,
uint32_t, uint32_t, uint16_t, uint16_t, PKTHREAD, int);
#else
/* proc will be NULL for __Userspace__ */
struct sctp_tcb *
sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
int *, uint32_t, uint32_t, uint16_t, uint16_t, struct proc *,
int);
sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, int *, uint32_t,
uint32_t, uint32_t, uint16_t, uint16_t, struct proc *, int);
struct sctp_tcb *
sctp_aloc_assoc_connected(struct sctp_inpcb *, struct sockaddr *, int *, uint32_t,
uint32_t, uint32_t, uint16_t, uint16_t, struct proc *, int);
#endif
int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
void sctp_delete_from_timewait(uint32_t, uint16_t, uint16_t);
int sctp_is_in_timewait(uint32_t tag, uint16_t lport, uint16_t rport);
void
sctp_add_vtag_to_timewait(uint32_t tag, uint32_t time, uint16_t lport, uint16_t rport);
void sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t);
void sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *);
@ -865,7 +845,8 @@ int
sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
struct sctp_nets *);
int sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *);
bool
sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *);
/* void sctp_drain(void); */
@ -889,10 +870,12 @@ sctp_initiate_iterator(inp_func inpf,
end_func ef,
struct sctp_inpcb *,
uint8_t co_off);
#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SCTP_MCORE_INPUT) && defined(SMP)
void
sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use);
#endif
#endif
#endif /* _KERNEL */

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.c 337708 2018-08-13 13:58:45Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#include <netinet/sctp_os.h>
@ -49,10 +49,6 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.c 337708 2018-08-13 13:58:45Z
#include <netinet/sctputil.h>
#include <netinet/sctp_auth.h>
#if defined(__APPLE__)
#define APPLE_FILE_NO 5
#endif
int
sctp_can_peel_off(struct socket *head, sctp_assoc_t assoc_id)
{
@ -138,7 +134,6 @@ sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
n_inp->sctp_context = inp->sctp_context;
n_inp->max_cwnd = inp->max_cwnd;
n_inp->local_strreset_support = inp->local_strreset_support;
n_inp->inp_starting_point_for_iterator = NULL;
/* copy in the authentication parameters from the original endpoint */
if (n_inp->sctp_ep.local_hmacs)
sctp_free_hmaclist(n_inp->sctp_ep.local_hmacs);
@ -164,7 +159,7 @@ sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb);
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, SBL_WAIT);
#else
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, M_WAITOK);
@ -178,14 +173,6 @@ sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
struct socket *
sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
{
#if defined(__Userspace__)
/* if __Userspace__ chooses to originally not support peeloff, put it here... */
#endif
#if defined(__Panda__)
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EINVAL);
*error = EINVAL;
return (NULL);
#else
struct socket *newso;
struct sctp_inpcb *inp, *n_inp;
struct sctp_tcb *stcb;
@ -205,18 +192,15 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
}
atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb);
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
#if defined(__FreeBSD__) && !defined(__Userspace__)
CURVNET_SET(head->so_vnet);
#endif
newso = sonewconn(head, SS_ISCONNECTED
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
, NULL
#elif defined(__Panda__)
/* place this socket in the assoc's vrf id */
, NULL, stcb->asoc.vrf_id
#endif
);
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
#if defined(__FreeBSD__) && !defined(__Userspace__)
CURVNET_RESTORE();
#endif
if (newso == NULL) {
@ -227,7 +211,7 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
return (NULL);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
else {
SCTP_SOCKET_LOCK(newso, 1);
}
@ -288,7 +272,6 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
SOCK_UNLOCK(newso);
/* We remove it right away */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
#ifdef SCTP_LOCK_LOGGING
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
@ -297,16 +280,6 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
TAILQ_REMOVE(&head->so_comp, newso, so_list);
head->so_qlen--;
SOCK_UNLOCK(head);
#else
newso = TAILQ_FIRST(&head->so_q);
if (soqremque(newso, 1) == 0) {
SCTP_PRINTF("soremque failed, peeloff-fails (invarients would panic)\n");
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, ENOTCONN);
*error = ENOTCONN;
return (NULL);
}
#endif
/*
* Now we must move it from one hash table to another and get the
* stcb in the right place.
@ -318,13 +291,12 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
* And now the final hack. We move data in the pending side i.e.
* head to the new socket buffer. Let the GRUBBING begin :-0
*/
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, SBL_WAIT);
#else
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, M_WAITOK);
#endif
atomic_subtract_int(&stcb->asoc.refcnt, 1);
return (newso);
#endif
}
#endif

View File

@ -32,7 +32,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.h 309607 2016-12-06 10:21:25Z tuexen $");
#endif
@ -42,13 +42,13 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.h 309607 2016-12-06 10:21:25Z
#if defined(HAVE_SCTP_PEELOFF_SOCKOPT)
/* socket option peeloff */
struct sctp_peeloff_opt {
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
int s;
#else
HANDLE s;
#endif
sctp_assoc_t assoc_id;
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
int new_sd;
#else
HANDLE new_sd;

View File

@ -53,13 +53,16 @@
* per socket level locking
*/
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
/* Lock for INFO stuff */
#define SCTP_INP_INFO_LOCK_INIT()
#define SCTP_INP_INFO_RLOCK()
#define SCTP_INP_INFO_RUNLOCK()
#define SCTP_INP_INFO_WLOCK()
#define SCTP_INP_INFO_WUNLOCK()
#define SCTP_INP_INFO_LOCK_ASSERT()
#define SCTP_INP_INFO_RLOCK_ASSERT()
#define SCTP_INP_INFO_WLOCK_ASSERT()
#define SCTP_INP_INFO_LOCK_DESTROY()
#define SCTP_IPI_COUNT_INIT()
#define SCTP_IPI_COUNT_DESTROY()
@ -69,6 +72,9 @@
#define SCTP_INP_INFO_RUNLOCK()
#define SCTP_INP_INFO_WLOCK()
#define SCTP_INP_INFO_WUNLOCK()
#define SCTP_INP_INFO_LOCK_ASSERT()
#define SCTP_INP_INFO_RLOCK_ASSERT()
#define SCTP_INP_INFO_WLOCK_ASSERT()
#define SCTP_INP_INFO_LOCK_DESTROY()
#define SCTP_IPI_COUNT_INIT()
#define SCTP_IPI_COUNT_DESTROY()
@ -86,7 +92,9 @@
#define SCTP_INP_RLOCK(_inp)
#define SCTP_INP_RUNLOCK(_inp)
#define SCTP_INP_WLOCK(_inp)
#define SCTP_INP_WUNLOCK(_inep)
#define SCTP_INP_WUNLOCK(_inp)
#define SCTP_INP_RLOCK_ASSERT(_inp)
#define SCTP_INP_WLOCK_ASSERT(_inp)
#define SCTP_INP_INCR_REF(_inp)
#define SCTP_INP_DECR_REF(_inp)
@ -115,7 +123,7 @@
*/
#define SCTP_IPI_COUNT_INIT()
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SCTP_WQ_ADDR_INIT() \
InitializeCriticalSection(&SCTP_BASE_INFO(wq_addr_mtx))
#define SCTP_WQ_ADDR_DESTROY() \
@ -124,7 +132,7 @@
EnterCriticalSection(&SCTP_BASE_INFO(wq_addr_mtx))
#define SCTP_WQ_ADDR_UNLOCK() \
LeaveCriticalSection(&SCTP_BASE_INFO(wq_addr_mtx))
#define SCTP_WQ_ADDR_LOCK_ASSERT()
#define SCTP_INP_INFO_LOCK_INIT() \
InitializeCriticalSection(&SCTP_BASE_INFO(ipi_ep_mtx))
@ -140,6 +148,9 @@
LeaveCriticalSection(&SCTP_BASE_INFO(ipi_ep_mtx))
#define SCTP_INP_INFO_WUNLOCK() \
LeaveCriticalSection(&SCTP_BASE_INFO(ipi_ep_mtx))
#define SCTP_INP_INFO_LOCK_ASSERT()
#define SCTP_INP_INFO_RLOCK_ASSERT()
#define SCTP_INP_INFO_WLOCK_ASSERT()
#define SCTP_IP_PKTLOG_INIT() \
InitializeCriticalSection(&SCTP_BASE_INFO(ipi_pktlog_mtx))
@ -185,6 +196,8 @@
#define SCTP_INP_WLOCK(_inp) \
EnterCriticalSection(&(_inp)->inp_mtx)
#endif
#define SCTP_INP_RLOCK_ASSERT(_tcb)
#define SCTP_INP_WLOCK_ASSERT(_tcb)
#define SCTP_TCB_SEND_LOCK_INIT(_tcb) \
InitializeCriticalSection(&(_tcb)->tcb_send_mtx)
@ -263,6 +276,8 @@
#define SCTP_WQ_ADDR_UNLOCK() \
(void)pthread_mutex_unlock(&SCTP_BASE_INFO(wq_addr_mtx))
#endif
#define SCTP_WQ_ADDR_LOCK_ASSERT() \
KASSERT(pthread_mutex_trylock(&SCTP_BASE_INFO(wq_addr_mtx)) == EBUSY, ("%s: wq_addr_mtx not locked", __func__))
#define SCTP_INP_INFO_LOCK_INIT() \
(void)pthread_mutex_init(&SCTP_BASE_INFO(ipi_ep_mtx), &SCTP_BASE_VAR(mtx_attr))
@ -287,6 +302,12 @@
#define SCTP_INP_INFO_WUNLOCK() \
(void)pthread_mutex_unlock(&SCTP_BASE_INFO(ipi_ep_mtx))
#endif
#define SCTP_INP_INFO_LOCK_ASSERT() \
KASSERT(pthread_mutex_trylock(&SCTP_BASE_INFO(ipi_ep_mtx)) == EBUSY, ("%s: ipi_ep_mtx not locked", __func__))
#define SCTP_INP_INFO_RLOCK_ASSERT() \
KASSERT(pthread_mutex_trylock(&SCTP_BASE_INFO(ipi_ep_mtx)) == EBUSY, ("%s: ipi_ep_mtx not locked", __func__))
#define SCTP_INP_INFO_WLOCK_ASSERT() \
KASSERT(pthread_mutex_trylock(&SCTP_BASE_INFO(ipi_ep_mtx)) == EBUSY, ("%s: ipi_ep_mtx not locked", __func__))
#define SCTP_INP_INFO_TRYLOCK() \
(!(pthread_mutex_trylock(&SCTP_BASE_INFO(ipi_ep_mtx))))
@ -377,6 +398,10 @@
#define SCTP_INP_WUNLOCK(_inp) \
(void)pthread_mutex_unlock(&(_inp)->inp_mtx)
#endif
#define SCTP_INP_RLOCK_ASSERT(_inp) \
KASSERT(pthread_mutex_trylock(&(_inp)->inp_mtx) == EBUSY, ("%s: inp_mtx not locked", __func__))
#define SCTP_INP_WLOCK_ASSERT(_inp) \
KASSERT(pthread_mutex_trylock(&(_inp)->inp_mtx) == EBUSY, ("%s: inp_mtx not locked", __func__))
#define SCTP_INP_INCR_REF(_inp) atomic_add_int(&((_inp)->refcount), 1)
#define SCTP_INP_DECR_REF(_inp) atomic_add_int(&((_inp)->refcount), -1)
@ -484,7 +509,7 @@
/* socket locks */
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SOCKBUF_LOCK_ASSERT(_so_buf)
#define SOCKBUF_LOCK(_so_buf) \
EnterCriticalSection(&(_so_buf)->sb_mtx)
@ -519,7 +544,7 @@
#define SCTP_STATLOG_UNLOCK()
#define SCTP_STATLOG_DESTROY()
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
/* address list locks */
#define SCTP_IPI_ADDR_INIT() \
InitializeCriticalSection(&SCTP_BASE_INFO(ipi_addr_mtx))
@ -533,6 +558,8 @@
EnterCriticalSection(&SCTP_BASE_INFO(ipi_addr_mtx))
#define SCTP_IPI_ADDR_WUNLOCK() \
LeaveCriticalSection(&SCTP_BASE_INFO(ipi_addr_mtx))
#define SCTP_IPI_ADDR_LOCK_ASSERT()
#define SCTP_IPI_ADDR_WLOCK_ASSERT()
/* iterator locks */
@ -554,7 +581,7 @@
#define SCTP_IPI_ITERATOR_WQ_UNLOCK() \
LeaveCriticalSection(&sctp_it_ctl.ipi_iterator_wq_mtx)
#else /* end of __Userspace_os_Windows */
#else
/* address list locks */
#define SCTP_IPI_ADDR_INIT() \
(void)pthread_mutex_init(&SCTP_BASE_INFO(ipi_addr_mtx), &SCTP_BASE_VAR(mtx_attr))
@ -569,6 +596,10 @@
KASSERT(pthread_mutex_lock(&SCTP_BASE_INFO(ipi_addr_mtx)) == 0, ("%s: ipi_addr_mtx already locked", __func__))
#define SCTP_IPI_ADDR_WUNLOCK() \
KASSERT(pthread_mutex_unlock(&SCTP_BASE_INFO(ipi_addr_mtx)) == 0, ("%s: ipi_addr_mtx not locked", __func__))
#define SCTP_IPI_ADDR_LOCK_ASSERT() \
KASSERT(pthread_mutex_trylock(&SCTP_BASE_INFO(ipi_addr_mtx)) == EBUSY, ("%s: ipi_addr_mtx not locked", __func__))
#define SCTP_IPI_ADDR_WLOCK_ASSERT() \
KASSERT(pthread_mutex_trylock(&SCTP_BASE_INFO(ipi_addr_mtx)) == EBUSY, ("%s: ipi_addr_mtx not locked", __func__))
#else
#define SCTP_IPI_ADDR_RLOCK() \
(void)pthread_mutex_lock(&SCTP_BASE_INFO(ipi_addr_mtx))
@ -578,6 +609,8 @@
(void)pthread_mutex_lock(&SCTP_BASE_INFO(ipi_addr_mtx))
#define SCTP_IPI_ADDR_WUNLOCK() \
(void)pthread_mutex_unlock(&SCTP_BASE_INFO(ipi_addr_mtx))
#define SCTP_IPI_ADDR_LOCK_ASSERT()
#define SCTP_IPI_ADDR_WLOCK_ASSERT()
#endif
/* iterator locks */

View File

@ -80,13 +80,31 @@ sctp_sha1_final(unsigned char *digest, struct sctp_sha1_context *ctx)
{
SHA1_Final(digest, &ctx->sha_ctx);
}
#elif defined(SCTP_USE_MBEDTLS_SHA1)
void
sctp_sha1_init(struct sctp_sha1_context *ctx)
{
mbedtls_sha1_init(&ctx->sha1_ctx);
mbedtls_sha1_starts_ret(&ctx->sha1_ctx);
}
void
sctp_sha1_update(struct sctp_sha1_context *ctx, const unsigned char *ptr, unsigned int siz)
{
mbedtls_sha1_update_ret(&ctx->sha1_ctx, ptr, siz);
}
void
sctp_sha1_final(unsigned char *digest, struct sctp_sha1_context *ctx)
{
mbedtls_sha1_finish_ret(&ctx->sha1_ctx, digest);
}
#else
#include <string.h>
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && defined(__Userspace__)
#include <winsock2.h>
#elif !defined(__Windows__)
#elif !(defined(_WIN32) && !defined(__Userspace__))
#include <arpa/inet.h>
#endif

View File

@ -32,7 +32,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#endif
@ -43,18 +43,11 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#if defined(SCTP_USE_NSS_SHA1)
#if defined(__Userspace_os_Darwin)
/* The NSS sources require __APPLE__ to be defined.
* XXX: Remove this ugly hack once the platform defines have been cleaned up.
*/
#define __APPLE__
#endif
#include <pk11pub.h>
#if defined(__Userspace_os_Darwin)
#undef __APPLE__
#endif
#elif defined(SCTP_USE_OPENSSL_SHA1)
#include <openssl/sha.h>
#elif defined(SCTP_USE_MBEDTLS_SHA1)
#include <mbedtls/sha1.h>
#endif
struct sctp_sha1_context {
@ -62,6 +55,8 @@ struct sctp_sha1_context {
struct PK11Context *pk11_ctx;
#elif defined(SCTP_USE_OPENSSL_SHA1)
SHA_CTX sha_ctx;
#elif defined(SCTP_USE_MBEDTLS_SHA1)
mbedtls_sha1_context sha1_ctx;
#else
unsigned int A;
unsigned int B;
@ -83,7 +78,7 @@ struct sctp_sha1_context {
#endif
};
#if (defined(__APPLE__) && defined(KERNEL))
#if (defined(__APPLE__) && !defined(__Userspace__) && defined(KERNEL))
#ifndef _KERNEL
#define _KERNEL
#endif

View File

@ -28,9 +28,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_ss_functions.c 345505 2019-03-25 16:40:54Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_ss_functions.c 365071 2020-09-01 21:19:14Z mjg $");
#endif
#include <netinet/sctp_pcb.h>
@ -185,7 +185,6 @@ sctp_ss_default_remove(struct sctp_tcb *stcb, struct sctp_association *asoc,
return;
}
static struct sctp_stream_out *
sctp_ss_default_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
struct sctp_association *asoc)
@ -396,7 +395,6 @@ rrp_again:
return;
}
/*
* Priority algorithm.
* Always prefers streams based on their priority id.
@ -418,7 +416,6 @@ sctp_ss_prio_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.prio.next_spoke);
strq->ss_params.prio.next_spoke.tqe_next = NULL;
strq->ss_params.prio.next_spoke.tqe_prev = NULL;
}
asoc->ss_data.last_out_stream = NULL;
if (holds_lock == 0) {
@ -521,6 +518,9 @@ sctp_ss_prio_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
{
struct sctp_stream_out *strq, *strqt, *strqn;
if (asoc->ss_data.locked_on_sending) {
return (asoc->ss_data.locked_on_sending);
}
strqt = asoc->ss_data.last_out_stream;
prio_again:
/* Find the next stream to use */
@ -589,7 +589,7 @@ sctp_ss_prio_set_value(struct sctp_tcb *stcb, struct sctp_association *asoc,
/*
* Fair bandwidth algorithm.
* Maintains an equal troughput per stream.
* Maintains an equal throughput per stream.
*/
static void
sctp_ss_fb_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
@ -697,6 +697,9 @@ sctp_ss_fb_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
{
struct sctp_stream_out *strq = NULL, *strqt;
if (asoc->ss_data.locked_on_sending) {
return (asoc->ss_data.locked_on_sending);
}
if (asoc->ss_data.last_out_stream == NULL ||
TAILQ_FIRST(&asoc->ss_data.out.wheel) == TAILQ_LAST(&asoc->ss_data.out.wheel, sctpwheel_listhead)) {
strqt = TAILQ_FIRST(&asoc->ss_data.out.wheel);
@ -764,8 +767,8 @@ sctp_ss_fb_scheduled(struct sctp_tcb *stcb, struct sctp_nets *net SCTP_UNUSED,
*/
static void
sctp_ss_fcfs_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp,
int holds_lock);
struct sctp_stream_out *strq SCTP_UNUSED,
struct sctp_stream_queue_pending *sp, int holds_lock);
static void
sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc,
@ -897,7 +900,6 @@ sctp_ss_fcfs_remove(struct sctp_tcb *stcb, struct sctp_association *asoc,
return;
}
static struct sctp_stream_out *
sctp_ss_fcfs_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
struct sctp_association *asoc)
@ -905,6 +907,9 @@ sctp_ss_fcfs_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
struct sctp_stream_out *strq;
struct sctp_stream_queue_pending *sp;
if (asoc->ss_data.locked_on_sending) {
return (asoc->ss_data.locked_on_sending);
}
sp = TAILQ_FIRST(&asoc->ss_data.out.list);
default_again:
if (sp != NULL) {
@ -940,7 +945,7 @@ default_again:
const struct sctp_ss_functions sctp_ss_functions[] = {
/* SCTP_SS_DEFAULT */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_default_clear,
sctp_ss_default_init_stream,
@ -970,7 +975,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_ROUND_ROBIN */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_default_clear,
sctp_ss_default_init_stream,
@ -1000,7 +1005,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_ROUND_ROBIN_PACKET */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_default_clear,
sctp_ss_default_init_stream,
@ -1030,7 +1035,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_PRIORITY */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_prio_clear,
sctp_ss_prio_init_stream,
@ -1060,7 +1065,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_FAIR_BANDWITH */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_fb_clear,
sctp_ss_fb_init_stream,
@ -1090,7 +1095,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_FIRST_COME */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_fcfs_init,
sctp_ss_fcfs_clear,
sctp_ss_fcfs_init_stream,

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_structs.h 345467 2019-03-24 12:13:05Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#ifndef _NETINET_SCTP_STRUCTS_H_
@ -55,7 +55,7 @@ struct sctp_timer {
void *ep;
void *tcb;
void *net;
#if defined(__FreeBSD__) && __FreeBSD_version >= 800000
#if defined(__FreeBSD__) && !defined(__Userspace__)
void *vnet;
#endif
@ -65,7 +65,6 @@ struct sctp_timer {
uint32_t stopped_from;
};
struct sctp_foo_stuff {
struct sctp_inpcb *inp;
uint32_t lineno;
@ -73,7 +72,6 @@ struct sctp_foo_stuff {
int updown;
};
/*
* This is the information we track on each interface that we know about from
* the distant end.
@ -113,13 +111,12 @@ typedef void (*asoc_func) (struct sctp_inpcb *, struct sctp_tcb *, void *ptr,
typedef int (*inp_func) (struct sctp_inpcb *, void *ptr, uint32_t val);
typedef void (*end_func) (void *ptr, uint32_t val);
#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SCTP_MCORE_INPUT) && defined(SMP)
/* whats on the mcore control struct */
struct sctp_mcore_queue {
TAILQ_ENTRY(sctp_mcore_queue) next;
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
struct vnet *vn;
#endif
struct mbuf *m;
int off;
int v6;
@ -135,14 +132,12 @@ struct sctp_mcore_ctrl {
int running;
int cpuid;
};
#endif
#endif
struct sctp_iterator {
TAILQ_ENTRY(sctp_iterator) sctp_nxt_itr;
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct vnet *vn;
#endif
struct sctp_timer tmr;
@ -166,7 +161,6 @@ struct sctp_iterator {
#define SCTP_ITERATOR_DO_ALL_INP 0x00000001
#define SCTP_ITERATOR_DO_SINGLE_INP 0x00000002
TAILQ_HEAD(sctpiterators, sctp_iterator);
struct sctp_copy_all {
@ -184,10 +178,10 @@ struct sctp_asconf_iterator {
};
struct iterator_control {
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct mtx ipi_iterator_wq_mtx;
struct mtx it_mtx;
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
lck_mtx_t *ipi_iterator_wq_mtx;
lck_mtx_t *it_mtx;
#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
@ -200,7 +194,7 @@ struct iterator_control {
pthread_mutex_t it_mtx;
pthread_cond_t iterator_wakeup;
#endif
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
struct spinlock it_lock;
struct spinlock ipi_iterator_wq_lock;
KEVENT iterator_wakeup[2];
@ -208,7 +202,7 @@ struct iterator_control {
#else
void *it_mtx;
#endif
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
#if !defined(__Userspace__)
SCTP_PROCESS_STRUCT thread_proc;
#else
@ -220,7 +214,7 @@ struct iterator_control {
uint32_t iterator_running;
uint32_t iterator_flags;
};
#if !defined(__FreeBSD__)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
#define SCTP_ITERATOR_MUST_EXIT 0x00000001
#define SCTP_ITERATOR_EXITED 0x00000002
#endif
@ -228,28 +222,18 @@ struct iterator_control {
#define SCTP_ITERATOR_STOP_CUR_INP 0x00000008
struct sctp_net_route {
sctp_rtentry_t *ro_rt;
#if defined(__FreeBSD__)
#if __FreeBSD_version < 1100093
#if __FreeBSD_version >= 800000
void *ro_lle;
#endif
#if __FreeBSD_version >= 900000
void *ro_ia;
int ro_flags;
#endif
#else
#if __FreeBSD_version >= 1100116
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct nhop_object *ro_nh;
struct llentry *ro_lle;
#endif
char *ro_prepend;
uint16_t ro_plen;
uint16_t ro_flags;
uint16_t ro_mtu;
uint16_t spare;
#else
sctp_rtentry_t *ro_rt;
#endif
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#if !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION) && !defined(APPLE_ELCAPITAN)
struct llentry *ro_lle;
#endif
@ -306,7 +290,6 @@ struct rtcc_cc {
uint8_t last_inst_ind; /* Last saved inst indication */
};
struct sctp_nets {
TAILQ_ENTRY(sctp_nets) sctp_next; /* next link */
@ -334,7 +317,7 @@ struct sctp_nets {
int lastsa;
int lastsv;
uint64_t rtt; /* last measured rtt value in us */
unsigned int RTO;
uint32_t RTO;
/* This is used for SHUTDOWN/SHUTDOWN-ACK/SEND or INIT timers */
struct sctp_timer rxt_timer;
@ -443,13 +426,12 @@ struct sctp_nets {
uint8_t last_hs_used; /* index into the last HS table entry we used */
uint8_t lan_type;
uint8_t rto_needed;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint32_t flowid;
uint8_t flowtype;
#endif
};
struct sctp_data_chunkrec {
uint32_t tsn; /* the TSN of this transmit */
uint32_t mid; /* the message identifier of this transmit */
@ -488,7 +470,6 @@ struct chk_id {
uint8_t can_take_data;
};
struct sctp_tmit_chunk {
union {
struct sctp_data_chunkrec data;
@ -597,6 +578,7 @@ struct sctp_stream_queue_pending {
uint8_t sender_all_done;
uint8_t put_last_out;
uint8_t discard_rest;
uint8_t processing;
};
/*
@ -616,6 +598,19 @@ struct sctp_stream_in {
TAILQ_HEAD(sctpwheel_listhead, sctp_stream_out);
TAILQ_HEAD(sctplist_listhead, sctp_stream_queue_pending);
/*
* This union holds all data necessary for
* different stream schedulers.
*/
struct scheduling_data {
struct sctp_stream_out *locked_on_sending;
/* circular looking for output selection */
struct sctp_stream_out *last_out_stream;
union {
struct sctpwheel_listhead wheel;
struct sctplist_listhead list;
} out;
};
/* Round-robin schedulers */
struct ss_rr {
@ -639,20 +634,6 @@ struct ss_fb {
int32_t rounds;
};
/*
* This union holds all data necessary for
* different stream schedulers.
*/
struct scheduling_data {
struct sctp_stream_out *locked_on_sending;
/* circular looking for output selection */
struct sctp_stream_out *last_out_stream;
union {
struct sctpwheel_listhead wheel;
struct sctplist_listhead list;
} out;
};
/*
* This union holds all parameters per stream
* necessary for different stream schedulers.
@ -670,8 +651,6 @@ union scheduling_parameters {
#define SCTP_STREAM_RESET_PENDING 0x03
#define SCTP_STREAM_RESET_IN_FLIGHT 0x04
#define SCTP_MAX_STREAMS_AT_ONCE_RESET 200
/* This struct is used to track the traffic on outbound streams */
struct sctp_stream_out {
struct sctp_streamhead outqueue;
@ -695,6 +674,8 @@ struct sctp_stream_out {
uint8_t state;
};
#define SCTP_MAX_STREAMS_AT_ONCE_RESET 200
/* used to keep track of the addresses yet to try to add/delete */
TAILQ_HEAD(sctp_asconf_addrhead, sctp_asconf_addr);
struct sctp_asconf_addr {
@ -868,7 +849,6 @@ struct sctp_association {
struct sctp_timer strreset_timer; /* stream reset */
struct sctp_timer shut_guard_timer; /* shutdown guard */
struct sctp_timer autoclose_timer; /* automatic close timer */
struct sctp_timer delayed_event_timer; /* timer for delayed events */
struct sctp_timer delete_prim_timer; /* deleting primary dst */
/* list of restricted local addresses */
@ -934,7 +914,6 @@ struct sctp_association {
/* last place I got a control from */
struct sctp_nets *last_control_chunk_from;
/*
* wait to the point the cum-ack passes req->send_reset_at_tsn for
* any req on the list.
@ -998,7 +977,6 @@ struct sctp_association {
/* Original seq number I used ??questionable to keep?? */
uint32_t init_seq_number;
/* The Advanced Peer Ack Point, as required by the PR-SCTP */
/* (A1 in Section 4.2) */
uint32_t advanced_peer_ack_point;
@ -1122,7 +1100,7 @@ struct sctp_association {
uint32_t heart_beat_delay;
/* autoclose */
unsigned int sctp_autoclose_ticks;
uint32_t sctp_autoclose_ticks;
/* how many preopen streams we have */
unsigned int pre_open_streams;
@ -1131,7 +1109,7 @@ struct sctp_association {
unsigned int max_inbound_streams;
/* the cookie life I award for any cookie, in seconds */
unsigned int cookie_life;
uint32_t cookie_life;
/* time to delay acks for */
unsigned int delayed_ack;
unsigned int old_delayed_ack;
@ -1140,10 +1118,10 @@ struct sctp_association {
unsigned int numduptsns;
int dup_tsns[SCTP_MAX_DUP_TSNS];
unsigned int initial_init_rto_max; /* initial RTO for INIT's */
unsigned int initial_rto; /* initial send RTO */
unsigned int minrto; /* per assoc RTO-MIN */
unsigned int maxrto; /* per assoc RTO-MAX */
uint32_t initial_init_rto_max; /* initial RTO for INIT's */
uint32_t initial_rto; /* initial send RTO */
uint32_t minrto; /* per assoc RTO-MIN */
uint32_t maxrto; /* per assoc RTO-MAX */
/* authentication fields */
sctp_auth_chklist_t *local_auth_chunks;

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 356357 2020-01-04 20:33:12Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 365071 2020-09-01 21:19:14Z mjg $");
#endif
#include <netinet/sctp_os.h>
@ -44,15 +44,15 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 356357 2020-01-04 20:33:12Z t
#include <netinet/sctp_pcb.h>
#include <netinet/sctputil.h>
#include <netinet/sctp_output.h>
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/smp.h>
#include <sys/sysctl.h>
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#include <netinet/sctp_bsd_addr.h>
#endif
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
FEATURE(sctp, "Stream Control Transmission Protocol");
#endif
@ -74,7 +74,7 @@ sctp_init_sysctls()
SCTP_BASE_SYSCTL(sctp_reconfig_enable) = SCTPCTL_RECONFIG_ENABLE_DEFAULT;
SCTP_BASE_SYSCTL(sctp_nrsack_enable) = SCTPCTL_NRSACK_ENABLE_DEFAULT;
SCTP_BASE_SYSCTL(sctp_pktdrop_enable) = SCTPCTL_PKTDROP_ENABLE_DEFAULT;
#if !(defined(__FreeBSD__) && __FreeBSD_version >= 800000)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) = SCTPCTL_LOOPBACK_NOCSUM_DEFAULT;
#endif
SCTP_BASE_SYSCTL(sctp_peer_chunk_oh) = SCTPCTL_PEER_CHKOH_DEFAULT;
@ -152,7 +152,7 @@ sctp_init_sysctls()
SCTP_BASE_SYSCTL(sctp_sendall_limit) = SCTPCTL_SENDALL_LIMIT_DEFAULT;
SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT;
#if defined(SCTP_LOCAL_TRACE_BUF)
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
/* On Windows, the resource for global variables is limited. */
MALLOC(SCTP_BASE_SYSCTL(sctp_log), struct sctp_log *, sizeof(struct sctp_log), M_SYSCTL, M_ZERO);
#else
@ -165,18 +165,18 @@ sctp_init_sysctls()
#if defined(SCTP_DEBUG)
SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT;
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_BASE_SYSCTL(sctp_ignore_vmware_interfaces) = SCTPCTL_IGNORE_VMWARE_INTERFACES_DEFAULT;
SCTP_BASE_SYSCTL(sctp_main_timer) = SCTPCTL_MAIN_TIMER_DEFAULT;
SCTP_BASE_SYSCTL(sctp_addr_watchdog_limit) = SCTPCTL_ADDR_WATCHDOG_LIMIT_DEFAULT;
SCTP_BASE_SYSCTL(sctp_vtag_watchdog_limit) = SCTPCTL_VTAG_WATCHDOG_LIMIT_DEFAULT;
#endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_BASE_SYSCTL(sctp_output_unlocked) = SCTPCTL_OUTPUT_UNLOCKED_DEFAULT;
#endif
}
#if defined(_WIN32) && !defined(__Userspace__)
#if defined(__Windows__)
void
sctp_finish_sysctls()
{
@ -189,7 +189,7 @@ sctp_finish_sysctls()
}
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__Windows__)
#if !defined(__Userspace__)
/* It returns an upper limit. No filtering is done here */
static unsigned int
sctp_sysctl_number_of_addresses(struct sctp_inpcb *inp)
@ -329,7 +329,7 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st
sin = &sctp_ifa->address.sin;
if (sin->sin_addr.s_addr == 0)
continue;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) {
continue;
@ -350,7 +350,7 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st
sin6 = &sctp_ifa->address.sin6;
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
continue;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) {
continue;
@ -428,7 +428,7 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st
/*
* sysctl functions
*/
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_assoclist SYSCTL_HANDLER_ARGS
{
@ -458,7 +458,7 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
number_of_remote_addresses = 0;
SCTP_INP_INFO_RLOCK();
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
if (req->oldptr == USER_ADDR_NULL) {
#else
if (req->oldptr == NULL) {
@ -483,14 +483,14 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
(number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
/* request some more memory than needed */
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
req->oldidx = (n + n / 8);
#else
req->dataidx = (n + n / 8);
#endif
return (0);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
if (req->newptr != USER_ADDR_NULL) {
#else
if (req->newptr != NULL) {
@ -511,16 +511,12 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xinpcb.last = 0;
xinpcb.local_port = ntohs(inp->sctp_lport);
xinpcb.flags = inp->sctp_flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 1000048
xinpcb.features = (uint32_t)inp->sctp_features;
#else
xinpcb.features = inp->sctp_features;
#endif
xinpcb.total_sends = inp->total_sends;
xinpcb.total_recvs = inp->total_recvs;
xinpcb.total_nospaces = inp->total_nospaces;
xinpcb.fragmentation_point = inp->sctp_frag_point;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
xinpcb.socket = (uintptr_t)inp->sctp_socket;
#else
xinpcb.socket = inp->sctp_socket;
@ -532,33 +528,16 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xinpcb.qlen = 0;
xinpcb.maxqlen = 0;
} else {
#if defined(__FreeBSD__) && __FreeBSD_version >= 1200034
#if defined(__FreeBSD__) && !defined(__Userspace__)
xinpcb.qlen = so->sol_qlen;
#else
xinpcb.qlen = so->so_qlen;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
#if __FreeBSD_version >= 1200034
xinpcb.qlen_old = so->sol_qlen > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->sol_qlen;
#else
xinpcb.qlen_old = so->so_qlen > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->so_qlen;
#endif
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 1200034
xinpcb.maxqlen = so->sol_qlimit;
#else
xinpcb.maxqlen = so->so_qlimit;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
#if __FreeBSD_version >= 1200034
xinpcb.maxqlen_old = so->sol_qlimit > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->sol_qlimit;
#else
xinpcb.maxqlen_old = so->so_qlimit > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->so_qlimit;
#endif
xinpcb.qlen = so->so_qlen;
xinpcb.maxqlen = so->so_qlimit;
#endif
}
SCTP_INP_INCR_REF(inp);
@ -587,16 +566,8 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
xstcb.state = (uint32_t)sctp_map_assoc_state(stcb->asoc.state);
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
/* 7.0 does not support these */
xstcb.assoc_id = sctp_get_associd(stcb);
xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
#endif
#else
xstcb.assoc_id = sctp_get_associd(stcb);
xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
#endif
xstcb.in_streams = stcb->asoc.streamincnt;
xstcb.out_streams = stcb->asoc.streamoutcnt;
xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
@ -648,8 +619,6 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xraddr.cwnd = net->cwnd;
xraddr.flight_size = net->flight_size;
xraddr.mtu = net->mtu;
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
xraddr.rtt = net->rtt / 1000;
xraddr.heartbeat_interval = net->heart_beat_delay;
xraddr.ssthresh = net->ssthresh;
@ -661,20 +630,6 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
} else {
xraddr.state = SCTP_INACTIVE;
}
#endif
#else
xraddr.rtt = net->rtt / 1000;
xraddr.heartbeat_interval = net->heart_beat_delay;
xraddr.ssthresh = net->ssthresh;
xraddr.encaps_port = net->port;
if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
xraddr.state = SCTP_UNCONFIRMED;
} else if (net->dest_state & SCTP_ADDR_REACHABLE) {
xraddr.state = SCTP_ACTIVE;
} else {
xraddr.state = SCTP_INACTIVE;
}
#endif
xraddr.start_time.tv_sec = (uint32_t)net->start_time.tv_sec;
xraddr.start_time.tv_usec = (uint32_t)net->start_time.tv_usec;
SCTP_INP_RUNLOCK(inp);
@ -721,7 +676,7 @@ skip:
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_udp_tunneling SYSCTL_HANDLER_ARGS
{
@ -738,22 +693,14 @@ sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
old = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
SCTP_INP_INFO_RUNLOCK();
new = old;
#if defined(__FreeBSD__) && __FreeBSD_version >= 800056 && __FreeBSD_version < 1000100
#ifdef VIMAGE
error = vnet_sysctl_handle_int(oidp, &new, 0, req);
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) &&
#if defined (__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) {
#else
(req->newptr != NULL)) {
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
SCTP_INP_INFO_WLOCK();
sctp_over_udp_restart();
SCTP_INP_INFO_WUNLOCK();
@ -780,8 +727,8 @@ sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
}
return (error);
}
#if defined(__APPLE__) && !defined(__Userspace__)
#if defined(__APPLE__)
int sctp_is_vmware_interface(struct ifnet *);
static int
@ -814,7 +761,7 @@ sctp_sysctl_handle_vmware_interfaces SYSCTL_HANDLER_ARGS
}
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_auth SYSCTL_HANDLER_ARGS
{
@ -828,17 +775,9 @@ sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
uint32_t new;
new = SCTP_BASE_SYSCTL(sctp_auth_enable);
#if defined(__FreeBSD__) && __FreeBSD_version >= 800056 && __FreeBSD_version < 1000100
#ifdef VIMAGE
error = vnet_sysctl_handle_int(oidp, &new, 0, req);
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) &&
#if defined (__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) {
#else
(req->newptr != NULL)) {
@ -859,7 +798,7 @@ sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_asconf SYSCTL_HANDLER_ARGS
{
@ -873,17 +812,9 @@ sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
uint32_t new;
new = SCTP_BASE_SYSCTL(sctp_asconf_enable);
#if defined(__FreeBSD__) && __FreeBSD_version >= 800056 && __FreeBSD_version < 1000100
#ifdef VIMAGE
error = vnet_sysctl_handle_int(oidp, &new, 0, req);
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) &&
#if defined (__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) {
#else
(req->newptr != NULL)) {
@ -904,7 +835,7 @@ sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_stats SYSCTL_HANDLER_ARGS
{
@ -915,7 +846,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
{
#endif
int error;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
struct sctpstat *sarry;
struct sctpstat sb;
@ -924,7 +855,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
struct sctpstat sb_temp;
#endif
#if defined (__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
if ((req->newptr != USER_ADDR_NULL) &&
#else
if ((req->newptr != NULL) &&
@ -932,7 +863,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
(req->newlen != sizeof(struct sctpstat))) {
return (EINVAL);
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
memset(&sb_temp, 0, sizeof(struct sctpstat));
if (req->newptr != NULL) {
@ -1089,7 +1020,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
}
#if defined(SCTP_LOCAL_TRACE_BUF)
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_trace_log SYSCTL_HANDLER_ARGS
{
@ -1101,7 +1032,7 @@ sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
#endif
int error;
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
error = SYSCTL_OUT(req, SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
#else
error = SYSCTL_OUT(req, &SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
@ -1109,7 +1040,7 @@ sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_trace_log_clear SYSCTL_HANDLER_ARGS
{
@ -1120,7 +1051,7 @@ sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
{
#endif
int error = 0;
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
int value = 0;
if (req->new_data == NULL) {
@ -1138,33 +1069,8 @@ sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
}
#endif
#if defined(__APPLE__) || defined(__FreeBSD__)
#if (defined(__APPLE__) || defined(__FreeBSD__)) && !defined(__Userspace__)
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800056 && __FreeBSD_version < 1000100
#ifdef VIMAGE
#define SCTP_UINT_SYSCTL(name, var_name, prefix) \
static int \
sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS) \
{ \
int error; \
uint32_t new; \
\
new = SCTP_BASE_SYSCTL(var_name); \
error = vnet_sysctl_handle_int(oidp, &new, 0, req); \
if ((error == 0) && (req->newptr != NULL)) { \
if ((new < prefix##_MIN) || \
(new > prefix##_MAX)) { \
error = EINVAL; \
} else { \
SCTP_BASE_SYSCTL(var_name) = new; \
} \
} \
return (error); \
} \
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name, \
CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, \
sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
#else
#define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \
static int \
sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS) \
@ -1187,31 +1093,6 @@ sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name, \
CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, \
sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
#endif
#else
#define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \
static int \
sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS) \
{ \
int error; \
uint32_t new; \
\
new = SCTP_BASE_SYSCTL(var_name); \
error = sysctl_handle_int(oidp, &new, 0, req); \
if ((error == 0) && (req->newptr != NULL)) { \
if ((new < prefix##_MIN) || \
(new > prefix##_MAX)) { \
error = EINVAL; \
} else { \
SCTP_BASE_SYSCTL(var_name) = new; \
} \
} \
return (error); \
} \
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name, \
CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, \
sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
#endif
#else
#define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \
static int \
@ -1258,7 +1139,7 @@ SYSCTL_PROC(_net_inet_sctp, OID_AUTO, asconf_enable, CTLFLAG_VNET|CTLTYPE_UINT|C
SCTP_UINT_SYSCTL(reconfig_enable, sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
SCTP_UINT_SYSCTL(pktdrop_enable, sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE)
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_UINT_SYSCTL(loopback_nocsum, sctp_no_csum_on_loopback, SCTPCTL_LOOPBACK_NOCSUM)
#endif
SCTP_UINT_SYSCTL(peer_chkoh, sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH)
@ -1330,14 +1211,14 @@ SCTP_UINT_SYSCTL(diag_info_code, sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE)
#ifdef SCTP_DEBUG
SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG)
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_UINT_SYSCTL(main_timer, sctp_main_timer, SCTPCTL_MAIN_TIMER)
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, ignore_vmware_interfaces, CTLTYPE_UINT|CTLFLAG_RW,
NULL, 0, sctp_sysctl_handle_vmware_interfaces, "IU", SCTPCTL_IGNORE_VMWARE_INTERFACES_DESC);
SCTP_UINT_SYSCTL(addr_watchdog_limit, sctp_addr_watchdog_limit, SCTPCTL_ADDR_WATCHDOG_LIMIT)
SCTP_UINT_SYSCTL(vtag_watchdog_limit, sctp_vtag_watchdog_limit, SCTPCTL_VTAG_WATCHDOG_LIMIT)
#endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_UINT_SYSCTL(output_unlocked, sctp_output_unlocked, SCTPCTL_OUTPUT_UNLOCKED)
#endif
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_VNET|CTLTYPE_STRUCT|CTLFLAG_RW,
@ -1345,7 +1226,7 @@ SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_VNET|CTLTYPE_STRUCT|CTLFLAG
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLFLAG_VNET|CTLTYPE_OPAQUE|CTLFLAG_RD,
NULL, 0, sctp_sysctl_handle_assoclist, "S,xassoc", "List of active SCTP associations");
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
#define RANGECHK(var, min, max) \
if ((var) < (min)) { (var) = (min); } \

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.h 356357 2020-01-04 20:33:12Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.h 366750 2020-10-16 10:44:48Z tuexen $");
#endif
#ifndef _NETINET_SCTP_SYSCTL_H_
@ -56,7 +56,7 @@ struct sctp_sysctl {
uint32_t sctp_nrsack_enable;
uint32_t sctp_pktdrop_enable;
uint32_t sctp_fr_max_burst_default;
#if !(defined(__FreeBSD__) && __FreeBSD_version >= 800000)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
uint32_t sctp_no_csum_on_loopback;
#endif
uint32_t sctp_peer_chunk_oh;
@ -113,7 +113,7 @@ struct sctp_sysctl {
uint32_t sctp_use_dccc_ecn;
uint32_t sctp_diag_info_code;
#if defined(SCTP_LOCAL_TRACE_BUF)
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
struct sctp_log *sctp_log;
#else
struct sctp_log sctp_log;
@ -129,13 +129,13 @@ struct sctp_sysctl {
#if defined(SCTP_DEBUG)
uint32_t sctp_debug_on;
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
uint32_t sctp_ignore_vmware_interfaces;
uint32_t sctp_main_timer;
uint32_t sctp_addr_watchdog_limit;
uint32_t sctp_vtag_watchdog_limit;
#endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#if defined(__APPLE__) && !defined(__Userspace__)
uint32_t sctp_output_unlocked;
#endif
};
@ -241,7 +241,6 @@ struct sctp_sysctl {
#define SCTPCTL_FRMAXBURST_MAX 0xFFFFFFFF
#define SCTPCTL_FRMAXBURST_DEFAULT SCTP_DEF_FRMAX_BURST
/* maxchunks: Default max chunks on queue per asoc */
#define SCTPCTL_MAXCHUNKS_DESC "Default max chunks on queue per asoc"
#define SCTPCTL_MAXCHUNKS_MIN 0
@ -344,10 +343,10 @@ struct sctp_sysctl {
#define SCTPCTL_INIT_RTO_MAX_MAX 0xFFFFFFFF
#define SCTPCTL_INIT_RTO_MAX_DEFAULT SCTP_RTO_UPPER_BOUND
/* valid_cookie_life: Default cookie lifetime in sec */
#define SCTPCTL_VALID_COOKIE_LIFE_DESC "Default cookie lifetime in seconds"
#define SCTPCTL_VALID_COOKIE_LIFE_MIN 0
#define SCTPCTL_VALID_COOKIE_LIFE_MAX 0xFFFFFFFF
/* valid_cookie_life: Default cookie lifetime in ms */
#define SCTPCTL_VALID_COOKIE_LIFE_DESC "Default cookie lifetime in ms"
#define SCTPCTL_VALID_COOKIE_LIFE_MIN SCTP_MIN_COOKIE_LIFE
#define SCTPCTL_VALID_COOKIE_LIFE_MAX SCTP_MAX_COOKIE_LIFE
#define SCTPCTL_VALID_COOKIE_LIFE_DEFAULT SCTP_DEFAULT_COOKIE_LIFE
/* init_rtx_max: Default maximum number of retransmission for INIT chunks */
@ -498,7 +497,7 @@ struct sctp_sysctl {
#define SCTPCTL_UDP_TUNNELING_PORT_DESC "Set the SCTP/UDP tunneling port"
#define SCTPCTL_UDP_TUNNELING_PORT_MIN 0
#define SCTPCTL_UDP_TUNNELING_PORT_MAX 65535
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#define SCTPCTL_UDP_TUNNELING_PORT_DEFAULT 0
#else
#define SCTPCTL_UDP_TUNNELING_PORT_DEFAULT SCTP_OVER_UDP_TUNNELING_PORT
@ -585,7 +584,7 @@ struct sctp_sysctl {
#define SCTPCTL_DEBUG_DEFAULT 0
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#define SCTPCTL_MAIN_TIMER_DESC "Main timer interval in ms"
#define SCTPCTL_MAIN_TIMER_MIN 1
#define SCTPCTL_MAIN_TIMER_MAX 0xFFFFFFFF
@ -595,16 +594,12 @@ struct sctp_sysctl {
#define SCTPCTL_IGNORE_VMWARE_INTERFACES_MIN 0
#define SCTPCTL_IGNORE_VMWARE_INTERFACES_MAX 1
#define SCTPCTL_IGNORE_VMWARE_INTERFACES_DEFAULT SCTPCTL_IGNORE_VMWARE_INTERFACES_MAX
#endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#define SCTPCTL_OUTPUT_UNLOCKED_DESC "Unlock socket when sending packets down to IP"
#define SCTPCTL_OUTPUT_UNLOCKED_MIN 0
#define SCTPCTL_OUTPUT_UNLOCKED_MAX 1
#define SCTPCTL_OUTPUT_UNLOCKED_DEFAULT SCTPCTL_OUTPUT_UNLOCKED_MIN
#endif
#if defined(__APPLE__)
#define SCTPCTL_ADDR_WATCHDOG_LIMIT_DESC "Address watchdog limit"
#define SCTPCTL_ADDR_WATCHDOG_LIMIT_MIN 0
#define SCTPCTL_ADDR_WATCHDOG_LIMIT_MAX 0xFFFFFFFF
@ -614,8 +609,8 @@ struct sctp_sysctl {
#define SCTPCTL_VTAG_WATCHDOG_LIMIT_MIN 0
#define SCTPCTL_VTAG_WATCHDOG_LIMIT_MAX 0xFFFFFFFF
#define SCTPCTL_VTAG_WATCHDOG_LIMIT_DEFAULT SCTPCTL_VTAG_WATCHDOG_LIMIT_MIN
#endif
#endif
#if defined(_KERNEL) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Userspace__)
#if defined(SYSCTL_DECL)
@ -624,7 +619,7 @@ SYSCTL_DECL(_net_inet_sctp);
#endif
void sctp_init_sysctls(void);
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
void sctp_finish_sysctls(void);
#endif

View File

@ -32,16 +32,16 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.c 338134 2018-08-21 13:25:32Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#define _IP_VHL
#include <netinet/sctp_os.h>
#include <netinet/sctp_pcb.h>
#ifdef INET6
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__) && defined(__Userspace__)
#include <netinet6/sctp6_var.h>
#endif
#endif
@ -57,15 +57,11 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.c 338134 2018-08-21 13:25:32Z tu
#include <netinet/sctp.h>
#include <netinet/sctp_uio.h>
#if defined(INET) || defined(INET6)
#if !defined(__Userspace_os_Windows)
#if !(defined(_WIN32) && defined(__Userspace__))
#include <netinet/udp.h>
#endif
#endif
#if defined(__APPLE__)
#define APPLE_FILE_NO 6
#endif
void
sctp_audit_retranmission_queue(struct sctp_association *asoc)
{
@ -168,15 +164,15 @@ sctp_threshold_management(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
"Association error counter exceeded");
inp->last_abort_code = SCTP_FROM_SCTP_TIMER + SCTP_LOC_2;
sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
sctp_abort_an_association(inp, stcb, op_err, true, SCTP_SO_NOT_LOCKED);
return (1);
}
return (0);
}
/*
* sctp_find_alternate_net() returns a non-NULL pointer as long
* the argument net is non-NULL.
* sctp_find_alternate_net() returns a non-NULL pointer as long as there
* exists nets, which are not being deleted.
*/
struct sctp_nets *
sctp_find_alternate_net(struct sctp_tcb *stcb,
@ -185,13 +181,13 @@ sctp_find_alternate_net(struct sctp_tcb *stcb,
{
/* Find and return an alternate network if possible */
struct sctp_nets *alt, *mnet, *min_errors_net = NULL , *max_cwnd_net = NULL;
int once;
bool looped;
/* JRS 5/14/07 - Initialize min_errors to an impossible value. */
int min_errors = -1;
uint32_t max_cwnd = 0;
if (stcb->asoc.numnets == 1) {
/* No others but net */
/* No selection can be made. */
return (TAILQ_FIRST(&stcb->asoc.nets));
}
/*
@ -327,28 +323,29 @@ sctp_find_alternate_net(struct sctp_tcb *stcb,
return (max_cwnd_net);
}
}
mnet = net;
once = 0;
if (mnet == NULL) {
mnet = TAILQ_FIRST(&stcb->asoc.nets);
if (mnet == NULL) {
return (NULL);
}
/* Look for an alternate net, which is active. */
if ((net != NULL) && ((net->dest_state & SCTP_ADDR_BEING_DELETED) == 0)) {
alt = TAILQ_NEXT(net, sctp_next);
} else {
alt = TAILQ_FIRST(&stcb->asoc.nets);
}
looped = false;
for (;;) {
alt = TAILQ_NEXT(mnet, sctp_next);
if (alt == NULL) {
once++;
if (once > 1) {
if (!looped) {
alt = TAILQ_FIRST(&stcb->asoc.nets);
looped = true;
}
/* Definitely out of candidates. */
if (alt == NULL) {
break;
}
alt = TAILQ_FIRST(&stcb->asoc.nets);
if (alt == NULL) {
return (NULL);
}
}
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (alt->ro.ro_nh == NULL) {
#else
if (alt->ro.ro_rt == NULL) {
#endif
if (alt->ro._s_addr) {
sctp_free_ifa(alt->ro._s_addr);
alt->ro._s_addr = NULL;
@ -356,44 +353,61 @@ sctp_find_alternate_net(struct sctp_tcb *stcb,
alt->src_addr_selected = 0;
}
if (((alt->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE) &&
#if defined(__FreeBSD__) && !defined(__Userspace__)
(alt->ro.ro_nh != NULL) &&
#else
(alt->ro.ro_rt != NULL) &&
(!(alt->dest_state & SCTP_ADDR_UNCONFIRMED))) {
/* Found a reachable address */
#endif
(!(alt->dest_state & SCTP_ADDR_UNCONFIRMED)) &&
(alt != net)) {
/* Found an alternate net, which is reachable. */
break;
}
mnet = alt;
alt = TAILQ_NEXT(alt, sctp_next);
}
if (alt == NULL) {
/* Case where NO insv network exists (dormant state) */
/* we rotate destinations */
once = 0;
mnet = net;
/*
* In case no active alternate net has been found, look for
* an alternate net, which is confirmed.
*/
if ((net != NULL) && ((net->dest_state & SCTP_ADDR_BEING_DELETED) == 0)) {
alt = TAILQ_NEXT(net, sctp_next);
} else {
alt = TAILQ_FIRST(&stcb->asoc.nets);
}
looped = false;
for (;;) {
if (mnet == NULL) {
return (TAILQ_FIRST(&stcb->asoc.nets));
}
alt = TAILQ_NEXT(mnet, sctp_next);
if (alt == NULL) {
once++;
if (once > 1) {
break;
if (!looped) {
alt = TAILQ_FIRST(&stcb->asoc.nets);
looped = true;
}
alt = TAILQ_FIRST(&stcb->asoc.nets);
/* Definitely out of candidates. */
if (alt == NULL) {
break;
}
}
if ((!(alt->dest_state & SCTP_ADDR_UNCONFIRMED)) &&
(alt != net)) {
/* Found an alternate address */
/* Found an alternate net, which is confirmed. */
break;
}
mnet = alt;
alt = TAILQ_NEXT(alt, sctp_next);
}
}
if (alt == NULL) {
return (net);
/*
* In case no confirmed alternate net has been found, just
* return net, if it is not being deleted. In the other case
* just return the first net.
*/
if ((net != NULL) && ((net->dest_state & SCTP_ADDR_BEING_DELETED) == 0)) {
alt = net;
}
if (alt == NULL) {
alt = TAILQ_FIRST(&stcb->asoc.nets);
}
}
return (alt);
}
@ -495,7 +509,6 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
uint32_t tsnlast, tsnfirst;
int recovery_cnt = 0;
/* none in flight now */
audit_tf = 0;
fir = 0;
@ -517,7 +530,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
}
tv.tv_sec = cur_rto / 1000000;
tv.tv_usec = cur_rto % 1000000;
#ifndef __FreeBSD__
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
timersub(&now, &tv, &min_wait);
#else
min_wait = now;
@ -533,8 +546,8 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
min_wait.tv_sec = min_wait.tv_usec = 0;
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(cur_rto, now.tv_sec, now.tv_usec, SCTP_FR_T3_MARK_TIME);
sctp_log_fr(0, min_wait.tv_sec, min_wait.tv_usec, SCTP_FR_T3_MARK_TIME);
sctp_log_fr(cur_rto, (uint32_t)now.tv_sec, now.tv_usec, SCTP_FR_T3_MARK_TIME);
sctp_log_fr(0, (uint32_t)min_wait.tv_sec, min_wait.tv_usec, SCTP_FR_T3_MARK_TIME);
}
/*
* Our rwnd will be incorrect here since we are not adding back the
@ -581,7 +594,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
/* validate its been outstanding long enough */
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(chk->rec.data.tsn,
chk->sent_rcv_time.tv_sec,
(uint32_t)chk->sent_rcv_time.tv_sec,
chk->sent_rcv_time.tv_usec,
SCTP_FR_T3_MARK_TIME);
}
@ -593,7 +606,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
*/
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(0,
chk->sent_rcv_time.tv_sec,
(uint32_t)chk->sent_rcv_time.tv_sec,
chk->sent_rcv_time.tv_usec,
SCTP_FR_T3_STOPPED);
}
@ -614,7 +627,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
}
if (stcb->asoc.prsctp_supported && PR_SCTP_TTL_ENABLED(chk->flags)) {
/* Is it expired? */
#ifndef __FreeBSD__
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
if (timercmp(&now, &chk->rec.data.timetodrop, >)) {
#else
if (timevalcmp(&now, &chk->rec.data.timetodrop, >)) {
@ -806,7 +819,6 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
return (0);
}
int
sctp_t3rxt_timer(struct sctp_inpcb *inp,
struct sctp_tcb *stcb,
@ -848,11 +860,11 @@ sctp_t3rxt_timer(struct sctp_inpcb *inp,
if (net != stcb->asoc.primary_destination) {
/* send a immediate HB if our RTO is stale */
struct timeval now;
unsigned int ms_goneby;
uint32_t ms_goneby;
(void)SCTP_GETTIME_TIMEVAL(&now);
if (net->last_sent_time.tv_sec) {
ms_goneby = (now.tv_sec - net->last_sent_time.tv_sec) * 1000;
ms_goneby = (uint32_t)(now.tv_sec - net->last_sent_time.tv_sec) * 1000;
} else {
ms_goneby = 0;
}
@ -942,10 +954,14 @@ sctp_t3rxt_timer(struct sctp_inpcb *inp,
net->src_addr_selected = 0;
/* Force a route allocation too */
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
if (net->ro.ro_rt) {
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
}
#endif
/* Was it our primary? */
if ((stcb->asoc.primary_destination == net) && (alt != net)) {
@ -982,7 +998,12 @@ sctp_t3rxt_timer(struct sctp_inpcb *inp,
/* C3. See if we need to send a Fwd-TSN */
if (SCTP_TSN_GT(stcb->asoc.advanced_peer_ack_point, stcb->asoc.last_acked_seq)) {
send_forward_tsn(stcb, &stcb->asoc);
if (lchk) {
for (; lchk != NULL; lchk = TAILQ_NEXT(lchk, sctp_next)) {
if (lchk->whoTo != NULL) {
break;
}
}
if (lchk != NULL) {
/* Assure a timer is up */
sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, lchk->whoTo);
}
@ -1064,7 +1085,7 @@ sctp_cookie_timer(struct sctp_inpcb *inp,
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
"Cookie timer expired, but no cookie");
inp->last_abort_code = SCTP_FROM_SCTP_TIMER + SCTP_LOC_3;
sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
sctp_abort_an_association(inp, stcb, op_err, false, SCTP_SO_NOT_LOCKED);
} else {
#ifdef INVARIANTS
panic("Cookie timer expires in wrong state?");
@ -1108,10 +1129,9 @@ sctp_cookie_timer(struct sctp_inpcb *inp,
}
int
sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct sctp_nets *net)
sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
{
struct sctp_nets *alt;
struct sctp_nets *alt, *net;
struct sctp_tmit_chunk *strrst = NULL, *chk = NULL;
if (stcb->asoc.stream_reset_outstanding == 0) {
@ -1122,9 +1142,9 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
if (strrst == NULL) {
return (0);
}
net = strrst->whoTo;
/* do threshold management */
if (sctp_threshold_management(inp, stcb, strrst->whoTo,
stcb->asoc.max_send_times)) {
if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) {
/* Assoc is over */
return (1);
}
@ -1132,9 +1152,8 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* Cleared threshold management, now lets backoff the address
* and select an alternate
*/
sctp_backoff_on_timeout(stcb, strrst->whoTo, 1, 0, 0);
alt = sctp_find_alternate_net(stcb, strrst->whoTo, 0);
sctp_free_remote_addr(strrst->whoTo);
sctp_backoff_on_timeout(stcb, net, 1, 0, 0);
alt = sctp_find_alternate_net(stcb, net, 0);
strrst->whoTo = alt;
atomic_add_int(&alt->ref_count, 1);
@ -1159,6 +1178,8 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
*/
sctp_move_chunks_from_net(stcb, net);
}
sctp_free_remote_addr(net);
/* mark the retran info */
if (strrst->sent != SCTP_DATAGRAM_RESEND)
sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
@ -1166,7 +1187,7 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
strrst->flags |= CHUNK_FLAGS_FRAGMENT_OK;
/* restart the timer */
sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, inp, stcb, strrst->whoTo);
sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, inp, stcb, alt);
return (0);
}
@ -1191,8 +1212,9 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
if (asconf == NULL) {
return (0);
}
net = asconf->whoTo;
/* do threshold management */
if (sctp_threshold_management(inp, stcb, asconf->whoTo,
if (sctp_threshold_management(inp, stcb, net,
stcb->asoc.max_send_times)) {
/* Assoc is over */
return (1);
@ -1205,17 +1227,16 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* Mark this peer as ASCONF incapable and cleanup.
*/
SCTPDBG(SCTP_DEBUG_TIMER1, "asconf_timer: Peer has not responded to our repeated ASCONFs\n");
sctp_asconf_cleanup(stcb, net);
sctp_asconf_cleanup(stcb);
return (0);
}
/*
* cleared threshold management, so now backoff the net and
* select an alternate
*/
sctp_backoff_on_timeout(stcb, asconf->whoTo, 1, 0, 0);
alt = sctp_find_alternate_net(stcb, asconf->whoTo, 0);
sctp_backoff_on_timeout(stcb, net, 1, 0, 0);
alt = sctp_find_alternate_net(stcb, net, 0);
if (asconf->whoTo != alt) {
sctp_free_remote_addr(asconf->whoTo);
asconf->whoTo = alt;
atomic_add_int(&alt->ref_count, 1);
}
@ -1252,6 +1273,8 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
*/
sctp_move_chunks_from_net(stcb, net);
}
sctp_free_remote_addr(net);
/* mark the retran info */
if (asconf->sent != SCTP_DATAGRAM_RESEND)
sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
@ -1266,8 +1289,7 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
/* Mobility adaptation */
void
sctp_delete_prim_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct sctp_nets *net SCTP_UNUSED)
sctp_delete_prim_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
{
if (stcb->asoc.deleted_primary == NULL) {
SCTPDBG(SCTP_DEBUG_ASCONF1, "delete_prim_timer: deleted_primary is not stored...\n");
@ -1441,7 +1463,7 @@ sctp_heartbeat_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
if ((net->last_sent_time.tv_sec > 0) ||
(net->last_sent_time.tv_usec > 0)) {
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct timeval diff;
SCTP_GETTIME_TIMEVAL(&diff);
@ -1487,7 +1509,7 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp,
if (net->ro._l_addr.sa.sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
/* KAME hack: embed scopeid */
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD)
(void)in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL);
#else
@ -1520,7 +1542,11 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp,
net->src_addr_selected = 1;
}
if (net->ro._s_addr) {
#if defined(__FreeBSD__) && !defined(__Userspace__)
mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._s_addr.sa, net->ro.ro_nh);
#else
mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._s_addr.sa, net->ro.ro_rt);
#endif
#if defined(INET) || defined(INET6)
if (net->port) {
mtu -= sizeof(struct udphdr);
@ -1538,16 +1564,14 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp,
}
void
sctp_autoclose_timer(struct sctp_inpcb *inp,
struct sctp_tcb *stcb,
struct sctp_nets *net)
sctp_autoclose_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
{
struct timeval tn, *tim_touse;
struct sctp_association *asoc;
int ticks_gone_by;
uint32_t ticks_gone_by;
(void)SCTP_GETTIME_TIMEVAL(&tn);
if (stcb->asoc.sctp_autoclose_ticks &&
if (stcb->asoc.sctp_autoclose_ticks > 0 &&
sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE)) {
/* Auto close is on */
asoc = &stcb->asoc;
@ -1559,9 +1583,8 @@ sctp_autoclose_timer(struct sctp_inpcb *inp,
tim_touse = &asoc->time_last_sent;
}
/* Now has long enough transpired to autoclose? */
ticks_gone_by = SEC_TO_TICKS(tn.tv_sec - tim_touse->tv_sec);
if ((ticks_gone_by > 0) &&
(ticks_gone_by >= (int)asoc->sctp_autoclose_ticks)) {
ticks_gone_by = sctp_secs_to_ticks((uint32_t)(tn.tv_sec - tim_touse->tv_sec));
if (ticks_gone_by >= asoc->sctp_autoclose_ticks) {
/*
* autoclose time has hit, call the output routine,
* which should do nothing just to be SURE we don't
@ -1579,7 +1602,7 @@ sctp_autoclose_timer(struct sctp_inpcb *inp,
*/
if (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) {
/* only send SHUTDOWN 1st time thru */
struct sctp_nets *netp;
struct sctp_nets *net;
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
@ -1588,17 +1611,15 @@ sctp_autoclose_timer(struct sctp_inpcb *inp,
SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
sctp_stop_timers_for_shutdown(stcb);
if (stcb->asoc.alternate) {
netp = stcb->asoc.alternate;
net = stcb->asoc.alternate;
} else {
netp = stcb->asoc.primary_destination;
net = stcb->asoc.primary_destination;
}
sctp_send_shutdown(stcb, netp);
sctp_send_shutdown(stcb, net);
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
stcb->sctp_ep, stcb,
netp);
stcb->sctp_ep, stcb, net);
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
stcb->sctp_ep, stcb,
netp);
stcb->sctp_ep, stcb, NULL);
}
}
} else {
@ -1606,13 +1627,12 @@ sctp_autoclose_timer(struct sctp_inpcb *inp,
* No auto close at this time, reset t-o to check
* later
*/
int tmp;
uint32_t tmp;
/* fool the timer startup to use the time left */
tmp = asoc->sctp_autoclose_ticks;
asoc->sctp_autoclose_ticks -= ticks_gone_by;
sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb,
net);
sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb, NULL);
/* restore the real tick value */
asoc->sctp_autoclose_ticks = tmp;
}

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.h 295709 2016-02-17 18:04:22Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_TIMER_H_
@ -46,18 +46,20 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.h 295709 2016-02-17 18:04:22Z tu
#define SCTP_RTT_VAR_SHIFT 2
struct sctp_nets *
sctp_find_alternate_net(struct sctp_tcb *,
struct sctp_nets *, int mode);
sctp_find_alternate_net(struct sctp_tcb *, struct sctp_nets *, int);
int
sctp_t3rxt_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
int
sctp_t1init_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
int
sctp_shutdown_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
int
sctp_heartbeat_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
@ -74,32 +76,28 @@ int
sctp_shutdownack_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
int
sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct sctp_nets *net);
sctp_strreset_timer(struct sctp_inpcb *, struct sctp_tcb *);
int
sctp_asconf_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
void
sctp_delete_prim_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
sctp_delete_prim_timer(struct sctp_inpcb *, struct sctp_tcb *);
void
sctp_autoclose_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *net);
sctp_autoclose_timer(struct sctp_inpcb *, struct sctp_tcb *);
void sctp_audit_retranmission_queue(struct sctp_association *);
void sctp_iterator_timer(struct sctp_iterator *it);
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
void sctp_slowtimo(void);
#else
void sctp_gc(struct inpcbinfo *);
#endif
#endif
#endif
#endif

View File

@ -32,29 +32,28 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_uio.h 336511 2018-07-19 20:16:33Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_uio.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_UIO_H_
#define _NETINET_SCTP_UIO_H_
#if (defined(__APPLE__) && defined(KERNEL))
#if (defined(__APPLE__) && !defined(__Userspace__) && defined(KERNEL))
#ifndef _KERNEL
#define _KERNEL
#endif
#endif
#if !(defined(__Windows__)) && !defined(__Userspace_os_Windows)
#if ! defined(_KERNEL)
#if !defined(_WIN32)
#if !defined(_KERNEL)
#include <stdint.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
#pragma warning(push)
#pragma warning(disable: 4200)
#if defined(_KERNEL)
@ -110,14 +109,8 @@ struct sctp_event_subscribe {
* ancillary data structures
*/
struct sctp_initmsg {
#if defined(__FreeBSD__) && __FreeBSD_version < 800000
/* This is a bug. Not fixed for ABI compatibility */
uint32_t sinit_num_ostreams;
uint32_t sinit_max_instreams;
#else
uint16_t sinit_num_ostreams;
uint16_t sinit_max_instreams;
#endif
uint16_t sinit_max_attempts;
uint16_t sinit_max_init_timeo;
};
@ -135,7 +128,6 @@ struct sctp_initmsg {
* all sendrcvinfo's need a verfid for SENDING only.
*/
#define SCTP_ALIGN_RESV_PAD 92
#define SCTP_ALIGN_RESV_PAD_SHORT 76
@ -143,9 +135,6 @@ struct sctp_sndrcvinfo {
uint16_t sinfo_stream;
uint16_t sinfo_ssn;
uint16_t sinfo_flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 800000
uint16_t sinfo_pr_policy;
#endif
uint32_t sinfo_ppid;
uint32_t sinfo_context;
uint32_t sinfo_timetolive;
@ -161,9 +150,6 @@ struct sctp_extrcvinfo {
uint16_t sinfo_stream;
uint16_t sinfo_ssn;
uint16_t sinfo_flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 800000
uint16_t sinfo_pr_policy;
#endif
uint32_t sinfo_ppid;
uint32_t sinfo_context;
uint32_t sinfo_timetolive; /* should have been sinfo_pr_value */
@ -453,7 +439,6 @@ struct sctp_setadaption {
uint32_t ssb_adaption_ind;
};
/*
* Partial Delivery API event
*/
@ -470,7 +455,6 @@ struct sctp_pdapi_event {
/* indication values */
#define SCTP_PARTIAL_DELIVERY_ABORTED 0x0001
/*
* authentication key event
*/
@ -490,7 +474,6 @@ struct sctp_authkey_event {
#define SCTP_AUTH_NO_AUTH 0x0002
#define SCTP_AUTH_FREE_KEY 0x0003
struct sctp_sender_dry_event {
uint16_t sender_dry_type;
uint16_t sender_dry_flags;
@ -498,7 +481,6 @@ struct sctp_sender_dry_event {
sctp_assoc_t sender_dry_assoc_id;
};
/*
* Stream reset event - subscribe to SCTP_STREAM_RESET_EVENT
*/
@ -546,7 +528,6 @@ struct sctp_stream_change_event {
#define SCTP_STREAM_CHANGE_DENIED 0x0004
#define SCTP_STREAM_CHANGE_FAILED 0x0008
/* SCTP notification event */
struct sctp_tlv {
uint16_t sn_type;
@ -662,10 +643,18 @@ struct sctp_setpeerprim {
uint8_t sspp_padding[4];
};
union sctp_sockstore {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
#if defined(__Userspace__)
struct sockaddr_conn sconn;
#endif
struct sockaddr sa;
};
struct sctp_getaddresses {
sctp_assoc_t sget_assoc_id;
/* addr is filled in for N * sockaddr_storage */
struct sockaddr addr[1];
union sctp_sockstore addr[];
};
struct sctp_status {
@ -1121,13 +1110,18 @@ struct sctpstat {
#define SCTP_STAT_INCR(_x) SCTP_STAT_INCR_BY(_x,1)
#define SCTP_STAT_DECR(_x) SCTP_STAT_DECR_BY(_x,1)
#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
#define SCTP_STAT_INCR_BY(_x,_d) (SCTP_BASE_STATS[PCPU_GET(cpuid)]._x += _d)
#define SCTP_STAT_DECR_BY(_x,_d) (SCTP_BASE_STATS[PCPU_GET(cpuid)]._x -= _d)
#else
#define SCTP_STAT_INCR_BY(_x,_d) atomic_add_int(&SCTP_BASE_STAT(_x), _d)
#define SCTP_STAT_DECR_BY(_x,_d) atomic_subtract_int(&SCTP_BASE_STAT(_x), _d)
#endif
#else
#define SCTP_STAT_INCR_BY(_x,_d) atomic_add_int(&SCTP_BASE_STAT(_x), _d)
#define SCTP_STAT_DECR_BY(_x,_d) atomic_subtract_int(&SCTP_BASE_STAT(_x), _d)
#endif
/* The following macros are for handling MIB values, */
#define SCTP_STAT_INCR_COUNTER32(_x) SCTP_STAT_INCR(_x)
#define SCTP_STAT_INCR_COUNTER64(_x) SCTP_STAT_INCR(_x)
@ -1136,24 +1130,14 @@ struct sctpstat {
#define SCTP_STAT_DECR_COUNTER64(_x) SCTP_STAT_DECR(_x)
#define SCTP_STAT_DECR_GAUGE32(_x) SCTP_STAT_DECR(_x)
union sctp_sockstore {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
#if defined(__Userspace__)
struct sockaddr_conn sconn;
#endif
struct sockaddr sa;
};
/***********************************/
/* And something for us old timers */
/***********************************/
#ifndef __APPLE__
#ifndef __Userspace__
#if !(defined(__APPLE__) && !defined(__Userspace__))
#if !defined(__Userspace__)
#ifndef ntohll
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
@ -1165,7 +1149,7 @@ union sctp_sockstore {
#endif
#ifndef htonll
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
@ -1179,21 +1163,16 @@ union sctp_sockstore {
#endif
/***********************************/
struct xsctp_inpcb {
uint32_t last;
uint32_t flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 1000048
uint32_t features;
#else
uint64_t features;
#endif
uint32_t total_sends;
uint32_t total_recvs;
uint32_t total_nospaces;
uint32_t fragmentation_point;
uint16_t local_port;
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint16_t qlen_old;
uint16_t maxqlen_old;
#else
@ -1201,22 +1180,16 @@ struct xsctp_inpcb {
uint16_t maxqlen;
#endif
uint16_t __spare16;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
kvaddr_t socket;
#else
void *socket;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint32_t qlen;
uint32_t maxqlen;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 1000048
uint32_t extra_padding[32]; /* future */
#elif defined(__FreeBSD__) && (__FreeBSD_version < 1001517)
uint32_t extra_padding[31]; /* future */
#else
uint32_t extra_padding[26]; /* future */
#endif
};
struct xsctp_tcb {
@ -1245,18 +1218,9 @@ struct xsctp_tcb {
uint16_t remote_port; /* sctpAssocEntry 4 */
struct sctp_timeval start_time; /* sctpAssocEntry 16 */
struct sctp_timeval discontinuity_time; /* sctpAssocEntry 17 */
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
uint32_t peers_rwnd;
sctp_assoc_t assoc_id; /* sctpAssocEntry 1 */
uint32_t extra_padding[32]; /* future */
#else
#endif
#else
uint32_t peers_rwnd;
sctp_assoc_t assoc_id; /* sctpAssocEntry 1 */
uint32_t extra_padding[32]; /* future */
#endif
};
struct xsctp_laddr {
@ -1281,23 +1245,12 @@ struct xsctp_raddr {
uint8_t heartbeat_enabled; /* sctpAssocLocalRemEntry 4 */
uint8_t potentially_failed;
struct sctp_timeval start_time; /* sctpAssocLocalRemEntry 8 */
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
uint32_t rtt;
uint32_t heartbeat_interval;
uint32_t ssthresh;
uint16_t encaps_port;
uint16_t state;
uint32_t extra_padding[29]; /* future */
#endif
#else
uint32_t rtt;
uint32_t heartbeat_interval;
uint32_t ssthresh;
uint16_t encaps_port;
uint16_t state;
uint32_t extra_padding[29]; /* future */
#endif
};
#define SCTP_MAX_LOGGING_SIZE 30000
@ -1324,19 +1277,14 @@ int
sctp_lower_sosend(struct socket *so,
struct sockaddr *addr,
struct uio *uio,
#if defined(__Panda__)
pakhandle_type i_pak,
pakhandle_type i_control,
#else
struct mbuf *i_pak,
struct mbuf *control,
#endif
int flags,
struct sctp_sndrcvinfo *srcv
#if !(defined(__Panda__) || defined(__Userspace__))
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if !defined(__Userspace__)
#if defined(__FreeBSD__)
,struct thread *p
#elif defined(__Windows__)
#elif defined(_WIN32)
, PKTHREAD p
#else
,struct proc *p
@ -1347,11 +1295,7 @@ sctp_lower_sosend(struct socket *so,
int
sctp_sorecvmsg(struct socket *so,
struct uio *uio,
#if defined(__Panda__)
particletype **mp,
#else
struct mbuf **mp,
#endif
struct sockaddr *from,
int fromlen,
int *msg_flags,
@ -1365,45 +1309,6 @@ sctp_sorecvmsg(struct socket *so,
#if !(defined(_KERNEL)) && !(defined(__Userspace__))
__BEGIN_DECLS
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
int sctp_peeloff __P((int, sctp_assoc_t));
int sctp_bindx __P((int, struct sockaddr *, int, int));
int sctp_connectx __P((int, const struct sockaddr *, int, sctp_assoc_t *));
int sctp_getaddrlen __P((sa_family_t));
int sctp_getpaddrs __P((int, sctp_assoc_t, struct sockaddr **));
void sctp_freepaddrs __P((struct sockaddr *));
int sctp_getladdrs __P((int, sctp_assoc_t, struct sockaddr **));
void sctp_freeladdrs __P((struct sockaddr *));
int sctp_opt_info __P((int, sctp_assoc_t, int, void *, socklen_t *));
/* deprecated */
ssize_t sctp_sendmsg __P((int, const void *, size_t, const struct sockaddr *,
socklen_t, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t));
/* deprecated */
ssize_t sctp_send __P((int, const void *, size_t,
const struct sctp_sndrcvinfo *, int));
/* deprecated */
ssize_t sctp_sendx __P((int, const void *, size_t, struct sockaddr *,
int, struct sctp_sndrcvinfo *, int));
/* deprecated */
ssize_t sctp_sendmsgx __P((int sd, const void *, size_t, struct sockaddr *,
int, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t));
sctp_assoc_t sctp_getassocid __P((int, struct sockaddr *));
/* deprecated */
ssize_t sctp_recvmsg __P((int, void *, size_t, struct sockaddr *, socklen_t *,
struct sctp_sndrcvinfo *, int *));
ssize_t sctp_sendv __P((int, const struct iovec *, int, struct sockaddr *,
int, void *, socklen_t, unsigned int, int));
ssize_t sctp_recvv __P((int, const struct iovec *, int, struct sockaddr *,
socklen_t *, void *, socklen_t *, unsigned int *, int *));
#else
int sctp_peeloff(int, sctp_assoc_t);
int sctp_bindx(int, struct sockaddr *, int, int);
int sctp_connectx(int, const struct sockaddr *, int, sctp_assoc_t *);
@ -1441,7 +1346,6 @@ ssize_t sctp_sendv(int, const struct iovec *, int, struct sockaddr *,
ssize_t sctp_recvv(int, const struct iovec *, int, struct sockaddr *,
socklen_t *, void *, socklen_t *, unsigned int *, int *);
#endif
__END_DECLS
#endif /* !_KERNEL */

View File

@ -32,24 +32,24 @@
#include <sys/timeb.h>
#include <iphlpapi.h>
#if !defined(__MINGW32__)
#pragma comment(lib, "IPHLPAPI.lib")
#pragma comment(lib, "iphlpapi.lib")
#endif
#endif
#include <netinet/sctp_os_userspace.h>
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <pthread_np.h>
#endif
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#include <sys/prctl.h>
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
/* Adapter to translate Unix thread start routines to Windows thread start
* routines.
*/
#if defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
static DWORD WINAPI
@ -83,42 +83,61 @@ sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_ro
void
sctp_userspace_set_threadname(const char *name)
{
#if defined(__Userspace_os_Darwin)
#if defined(__APPLE__)
pthread_setname_np(name);
#endif
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
prctl(PR_SET_NAME, name);
#endif
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
pthread_set_name_np(pthread_self(), name);
#endif
}
#if !defined(_WIN32) && !defined(__Userspace_os_NaCl)
#if !defined(_WIN32) && !defined(__native_client__)
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{
#if defined(INET) || defined(INET6)
struct ifreq ifr;
int fd;
#endif
int mtu;
memset(&ifr, 0, sizeof(struct ifreq));
if (if_indextoname(if_index, ifr.ifr_name) != NULL) {
/* TODO can I use the raw socket here and not have to open a new one with each query? */
if ((fd = socket(af, SOCK_DGRAM, 0)) < 0)
return (0);
if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
switch (af) {
#if defined(INET)
case AF_INET:
#endif
#if defined(INET6)
case AF_INET6:
#endif
#if defined(INET) || defined(INET6)
memset(&ifr, 0, sizeof(struct ifreq));
mtu = 0;
if (if_indextoname(if_index, ifr.ifr_name) != NULL) {
/* TODO can I use the raw socket here and not have to open a new one with each query? */
if ((fd = socket(af, SOCK_DGRAM, 0)) < 0) {
break;
}
if (ioctl(fd, SIOCGIFMTU, &ifr) >= 0) {
mtu = ifr.ifr_mtu;
}
close(fd);
return (0);
}
close(fd);
return ifr.ifr_mtu;
} else {
return (0);
break;
#endif
case AF_CONN:
mtu = 1280;
break;
default:
mtu = 0;
break;
}
return (mtu);
}
#endif
#if defined(__Userspace_os_NaCl)
#if defined(__native_client__)
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{
@ -126,7 +145,7 @@ sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
}
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NaCl) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_Windows) || defined(__Userspace_os_Fuchsia)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__linux__) || defined(__native_client__) || defined(__NetBSD__) || defined(_WIN32) || defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
int
timingsafe_bcmp(const void *b1, const void *b2, size_t n)
{
@ -143,51 +162,88 @@ timingsafe_bcmp(const void *b1, const void *b2, size_t n)
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{
#if defined(INET) || defined(INET6)
PIP_ADAPTER_ADDRESSES pAdapterAddrs, pAdapt;
DWORD AdapterAddrsSize, Err;
int ret;
#endif
int mtu;
ret = 0;
AdapterAddrsSize = 0;
pAdapterAddrs = NULL;
if ((Err = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &AdapterAddrsSize)) != 0) {
if ((Err != ERROR_BUFFER_OVERFLOW) && (Err != ERROR_INSUFFICIENT_BUFFER)) {
SCTPDBG(SCTP_DEBUG_USR, "GetAdaptersAddresses() sizing failed with error code %d, AdapterAddrsSize = %d\n", Err, AdapterAddrsSize);
ret = -1;
switch (af) {
#if defined(INET)
case AF_INET:
#endif
#if defined(INET6)
case AF_INET6:
#endif
#if defined(INET) || defined(INET6)
mtu = 0;
AdapterAddrsSize = 0;
pAdapterAddrs = NULL;
if ((Err = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &AdapterAddrsSize)) != 0) {
if ((Err != ERROR_BUFFER_OVERFLOW) && (Err != ERROR_INSUFFICIENT_BUFFER)) {
SCTPDBG(SCTP_DEBUG_USR, "GetAdaptersAddresses() sizing failed with error code %d, AdapterAddrsSize = %d\n", Err, AdapterAddrsSize);
mtu = -1;
goto cleanup;
}
}
if ((pAdapterAddrs = (PIP_ADAPTER_ADDRESSES) GlobalAlloc(GPTR, AdapterAddrsSize)) == NULL) {
SCTPDBG(SCTP_DEBUG_USR, "Memory allocation error!\n");
mtu = -1;
goto cleanup;
}
}
if ((pAdapterAddrs = (PIP_ADAPTER_ADDRESSES) GlobalAlloc(GPTR, AdapterAddrsSize)) == NULL) {
SCTPDBG(SCTP_DEBUG_USR, "Memory allocation error!\n");
ret = -1;
goto cleanup;
}
if ((Err = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAdapterAddrs, &AdapterAddrsSize)) != ERROR_SUCCESS) {
SCTPDBG(SCTP_DEBUG_USR, "GetAdaptersAddresses() failed with error code %d\n", Err);
ret = -1;
goto cleanup;
}
for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) {
if (pAdapt->IfIndex == if_index) {
ret = pAdapt->Mtu;
break;
if ((Err = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAdapterAddrs, &AdapterAddrsSize)) != ERROR_SUCCESS) {
SCTPDBG(SCTP_DEBUG_USR, "GetAdaptersAddresses() failed with error code %d\n", Err);
mtu = -1;
goto cleanup;
}
for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) {
if (pAdapt->IfIndex == if_index) {
mtu = pAdapt->Mtu;
break;
}
}
cleanup:
if (pAdapterAddrs != NULL) {
GlobalFree(pAdapterAddrs);
}
break;
#endif
case AF_CONN:
mtu = 1280;
break;
default:
mtu = 0;
break;
}
cleanup:
if (pAdapterAddrs != NULL) {
GlobalFree(pAdapterAddrs);
}
return (ret);
return (mtu);
}
void
getwintimeofday(struct timeval *tv)
{
struct timeb tb;
FILETIME filetime;
ULARGE_INTEGER ularge;
ftime(&tb);
tv->tv_sec = (long)tb.time;
tv->tv_usec = (long)(tb.millitm) * 1000L;
GetSystemTimeAsFileTime(&filetime);
ularge.LowPart = filetime.dwLowDateTime;
ularge.HighPart = filetime.dwHighDateTime;
/* Change base from Jan 1 1601 00:00:00 to Jan 1 1970 00:00:00 */
#if defined(__MINGW32__)
ularge.QuadPart -= 116444736000000000ULL;
#else
ularge.QuadPart -= 116444736000000000UI64;
#endif
/*
* ularge.QuadPart is now the number of 100-nanosecond intervals
* since Jan 1 1970 00:00:00.
*/
#if defined(__MINGW32__)
tv->tv_sec = (long)(ularge.QuadPart / 10000000ULL);
tv->tv_usec = (long)((ularge.QuadPart % 10000000ULL) / 10ULL);
#else
tv->tv_sec = (long)(ularge.QuadPart / 10000000UI64);
tv->tv_usec = (long)((ularge.QuadPart % 10000000UI64) / 10UI64);
#endif
}
int

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 317457 2017-04-26 19:26:40Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 365071 2020-09-01 21:19:14Z mjg $");
#endif
#ifndef _NETINET_SCTP_VAR_H_
@ -44,11 +44,10 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 317457 2017-04-26 19:26:40Z tuex
#if defined(_KERNEL) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
extern struct pr_usrreqs sctp_usrreqs;
#endif
#define sctp_feature_on(inp, feature) (inp->sctp_features |= feature)
#define sctp_feature_off(inp, feature) (inp->sctp_features &= ~feature)
#define sctp_is_feature_on(inp, feature) ((inp->sctp_features & feature) == feature)
@ -186,18 +185,11 @@ extern struct pr_usrreqs sctp_usrreqs;
} \
}
#if defined(__FreeBSD__) && __FreeBSD_version > 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#define sctp_free_remote_addr(__net) { \
if ((__net)) { \
if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \
(void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \
(void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \
(void)SCTP_OS_TIMER_STOP(&(__net)->hb_timer.timer); \
if ((__net)->ro.ro_rt) { \
RTFREE((__net)->ro.ro_rt); \
(__net)->ro.ro_rt = NULL; \
} \
RO_NHFREE(&(__net)->ro); \
if ((__net)->src_addr_selected) { \
sctp_free_ifa((__net)->ro._s_addr); \
(__net)->ro._s_addr = NULL; \
@ -233,15 +225,10 @@ extern struct pr_usrreqs sctp_usrreqs;
SCTP_BUF_TYPE(m) != MT_OOBDATA) \
atomic_add_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
}
#else /* FreeBSD Version <= 500000 or non-FreeBSD */
#define sctp_free_remote_addr(__net) { \
if ((__net)) { \
if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \
(void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \
(void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \
(void)SCTP_OS_TIMER_STOP(&(__net)->hb_timer.timer); \
if ((__net)->ro.ro_rt) { \
RTFREE((__net)->ro.ro_rt); \
(__net)->ro.ro_rt = NULL; \
@ -258,31 +245,6 @@ extern struct pr_usrreqs sctp_usrreqs;
} \
}
#if defined(__Panda__)
#define sctp_sbfree(ctl, stcb, sb, m) { \
if ((sb)->sb_cc >= (uint32_t)SCTP_BUF_LEN((m))) { \
atomic_subtract_int(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
} else { \
(sb)->sb_cc = 0; \
} \
if (((ctl)->do_not_ref_stcb == 0) && stcb) { \
if ((stcb)->asoc.sb_cc >= (uint32_t)SCTP_BUF_LEN((m))) { \
atomic_subtract_int(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
} else { \
(stcb)->asoc.sb_cc = 0; \
} \
} \
}
#define sctp_sballoc(stcb, sb, m) { \
atomic_add_int(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
if (stcb) { \
atomic_add_int(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
} \
}
#else
#define sctp_sbfree(ctl, stcb, sb, m) { \
SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_mbcnt, MSIZE); \
@ -301,7 +263,6 @@ extern struct pr_usrreqs sctp_usrreqs;
} \
}
#endif
#endif
#define sctp_ucount_incr(val) { \
val++; \
@ -402,23 +363,13 @@ struct sctp_inpcb;
struct sctp_tcb;
struct sctphdr;
#if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
void sctp_close(struct socket *so);
#else
int sctp_detach(struct socket *so);
#endif
int sctp_disconnect(struct socket *so);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
void sctp_ctlinput __P((int, struct sockaddr *, void *));
int sctp_ctloutput __P((struct socket *, struct sockopt *));
#ifdef INET
void sctp_input_with_port __P((struct mbuf *, int, uint16_t));
void sctp_input __P((struct mbuf *, int));
#endif
void sctp_pathmtu_adjustment __P((struct sctp_tcb *, uint16_t));
#else
#if !defined(__Userspace__)
#if defined(__APPLE__) && !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION) && !defined(APPLE_ELCAPITAN)
void sctp_ctlinput(int, struct sockaddr *, void *, struct ifnet * SCTP_UNUSED);
#else
@ -427,18 +378,15 @@ void sctp_ctlinput(int, struct sockaddr *, void *);
int sctp_ctloutput(struct socket *, struct sockopt *);
#ifdef INET
void sctp_input_with_port(struct mbuf *, int, uint16_t);
#if defined(__FreeBSD__) && __FreeBSD_version >= 1100020
#if defined(__FreeBSD__) && !defined(__Userspace__)
int sctp_input(struct mbuf **, int *, int);
#else
void sctp_input(struct mbuf *, int);
#endif
#endif
void sctp_pathmtu_adjustment(struct sctp_tcb *, uint16_t);
#endif
#else
#if defined(__Panda__)
void sctp_input(pakhandle_type i_pak);
#elif defined(__Userspace__)
#if defined(__Userspace__)
void sctp_pathmtu_adjustment(struct sctp_tcb *, uint16_t);
#else
void sctp_input(struct mbuf *,...);
@ -446,17 +394,11 @@ void sctp_input(struct mbuf *,...);
void *sctp_ctlinput(int, struct sockaddr *, void *);
int sctp_ctloutput(int, struct socket *, int, int, struct mbuf **);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
void sctp_drain __P((void));
#else
void sctp_drain(void);
#endif
#if defined(__Userspace__)
void sctp_init(uint16_t,
int (*)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
void (*)(const char *, ...), int start_threads);
#elif defined(__FreeBSD__) && __FreeBSD_version < 902000
void sctp_init __P((void));
#elif defined(__APPLE__) && (!defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) &&!defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION))
void sctp_init(struct protosw *pp, struct domain *dp);
#else
@ -464,55 +406,37 @@ void sctp_init(void);
void sctp_notify(struct sctp_inpcb *, struct sctp_tcb *, struct sctp_nets *,
uint8_t, uint8_t, uint16_t, uint32_t);
#endif
#if !defined(__FreeBSD__)
#if !defined(__FreeBSD__) && !defined(__Userspace__)
void sctp_finish(void);
#endif
#if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
int sctp_flush(struct socket *, int);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
int sctp_shutdown __P((struct socket *));
#else
int sctp_shutdown(struct socket *);
#endif
int sctp_bindx(struct socket *, int, struct sockaddr_storage *,
int, int, struct proc *);
/* can't use sctp_assoc_t here */
int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
int sctp_ingetaddr(struct socket *, struct sockaddr **);
#elif defined(__Panda__)
int sctp_ingetaddr(struct socket *, struct sockaddr *);
#else
int sctp_ingetaddr(struct socket *, struct mbuf *);
#endif
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
int sctp_peeraddr(struct socket *, struct sockaddr **);
#elif defined(__Panda__)
int sctp_peeraddr(struct socket *, struct sockaddr *);
#else
int sctp_peeraddr(struct socket *, struct mbuf *);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if __FreeBSD_version >= 700000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int sctp_listen(struct socket *, int, struct thread *);
#else
int sctp_listen(struct socket *, struct thread *);
#endif
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
int sctp_listen(struct socket *, int, PKTHREAD);
#elif defined(__Userspace__)
int sctp_listen(struct socket *, int, struct proc *);
#else
int sctp_listen(struct socket *, struct proc *);
#endif
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
int sctp_accept(struct socket *, struct sockaddr **);
#elif defined(__Panda__)
int sctp_accept(struct socket *, struct sockaddr *, int *, void *, int *);
#else
int sctp_accept(struct socket *, struct mbuf *);
#endif
#endif /* _KERNEL */

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 352592 2019-09-22 10:40:15Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#ifndef _NETINET_SCTP_UTIL_H_
@ -57,14 +57,13 @@ void sctp_m_freem(struct mbuf *m);
#define sctp_m_freem m_freem
#endif
#if defined(SCTP_LOCAL_TRACE_BUF) || defined(__APPLE__)
#if defined(SCTP_LOCAL_TRACE_BUF)
void
sctp_log_trace(uint32_t fr, const char *str SCTP_UNUSED, uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, uint32_t f);
#endif
#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id)
/*
* Function prototypes
*/
@ -84,7 +83,7 @@ uint32_t sctp_select_initial_TSN(struct sctp_pcb *);
uint32_t sctp_select_a_tag(struct sctp_inpcb *, uint16_t lport, uint16_t rport, int);
int sctp_init_asoc(struct sctp_inpcb *, struct sctp_tcb *, uint32_t, uint32_t, uint16_t);
int sctp_init_asoc(struct sctp_inpcb *, struct sctp_tcb *, uint32_t, uint32_t, uint32_t, uint16_t);
void sctp_fill_random_store(struct sctp_pcb *);
@ -94,6 +93,14 @@ sctp_notify_stream_reset_add(struct sctp_tcb *stcb, uint16_t numberin,
void
sctp_notify_stream_reset_tsn(struct sctp_tcb *stcb, uint32_t sending_tsn, uint32_t recv_tsn, int flag);
/*
* NOTE: sctp_timer_start() will increment the reference count of any relevant
* structure the timer is referencing, in order to prevent a race condition
* between the timer executing and the structure being freed.
*
* When the timer fires or sctp_timer_stop() is called, these references are
* removed.
*/
void
sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
@ -111,7 +118,7 @@ sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t);
void
sctp_wakeup_the_read_socket(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
#if !(defined(__APPLE__) && !defined(__Userspace__))
SCTP_UNUSED
#endif
);
@ -130,11 +137,7 @@ sctp_add_to_readq(struct sctp_inpcb *inp,
struct sockbuf *sb,
int end,
int inpread_locked,
int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
int so_locked);
void sctp_iterator_worker(void);
@ -162,60 +165,45 @@ sctp_add_pad_tombuf(struct mbuf *, int);
struct mbuf *
sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *);
void sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int);
void
sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
struct sctp_inpcb *new_inp,
struct sctp_tcb *stcb, int waitflags);
void sctp_stop_timers_for_shutdown(struct sctp_tcb *);
void sctp_report_all_outbound(struct sctp_tcb *, uint16_t, int, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
/* Stop all timers for association and remote addresses. */
void sctp_stop_association_timers(struct sctp_tcb *, bool);
void sctp_report_all_outbound(struct sctp_tcb *, uint16_t, int);
int sctp_expand_mapping_array(struct sctp_association *, uint32_t);
void sctp_abort_notification(struct sctp_tcb *, uint8_t, uint16_t,
struct sctp_abort_chunk *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_abort_notification(struct sctp_tcb *, bool, bool, uint16_t,
struct sctp_abort_chunk *, int);
/* We abort responding to an IP packet for some reason */
void
sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, struct mbuf *,
int, struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct mbuf *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t,
#endif
uint32_t, uint16_t);
/* We choose to abort via user input */
void
sctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *,
struct mbuf *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
struct mbuf *, bool, int);
void sctp_handle_ootb(struct mbuf *, int, int,
struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct sctp_inpcb *,
struct mbuf *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
@ -276,21 +264,16 @@ void sctp_print_address(struct sockaddr *);
int
sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *,
uint8_t, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
uint8_t, int);
struct mbuf *sctp_generate_cause(uint16_t, char *);
struct mbuf *sctp_generate_no_user_data_cause(uint32_t);
void sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp,
struct sockaddr *sa, sctp_assoc_t assoc_id,
uint32_t vrf_id, int *error, void *p);
void sctp_bindx_delete_address(struct sctp_inpcb *inp,
struct sockaddr *sa, sctp_assoc_t assoc_id,
uint32_t vrf_id, int *error);
struct sockaddr *sa, uint32_t vrf_id, int *error,
void *p);
void sctp_bindx_delete_address(struct sctp_inpcb *inp, struct sockaddr *sa,
uint32_t vrf_id, int *error);
int sctp_local_addr_count(struct sctp_tcb *stcb);
@ -352,11 +335,11 @@ do { \
} while (0)
/* functions to start/stop udp tunneling */
#if defined(__APPLE__) || defined(__FreeBSD__)
#if (defined(__APPLE__) || defined(__FreeBSD__)) && !defined(__Userspace__)
void sctp_over_udp_stop(void);
int sctp_over_udp_start(void);
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
void sctp_over_udp_restart(void);
#endif
@ -378,7 +361,6 @@ void sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t,
void sctp_log_nagle_event(struct sctp_tcb *stcb, int action);
#ifdef SCTP_MBUF_LOGGING
void
sctp_log_mb(struct mbuf *m, int from);
@ -412,7 +394,6 @@ void sctp_log_map(uint32_t, uint32_t, uint32_t, int);
void sctp_print_mapping_array(struct sctp_association *asoc);
void sctp_clr_stat_log(void);
#ifdef SCTP_AUDITING_ENABLED
void
sctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *,
@ -421,11 +402,16 @@ void sctp_audit_log(uint8_t, uint8_t);
#endif
uint32_t sctp_min_mtu(uint32_t, uint32_t, uint32_t);
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
void sctp_hc_set_mtu(union sctp_sockstore *, uint16_t, uint32_t);
uint32_t sctp_hc_get_mtu(union sctp_sockstore *, uint16_t);
#endif
void sctp_set_state(struct sctp_tcb *, int);
void sctp_add_substate(struct sctp_tcb *, int);
uint32_t sctp_ticks_to_msecs(uint32_t);
uint32_t sctp_msecs_to_ticks(uint32_t);
uint32_t sctp_ticks_to_secs(uint32_t);
uint32_t sctp_secs_to_ticks(uint32_t);
#endif /* _KERNEL */
#endif

View File

@ -32,14 +32,14 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet6/sctp6_usrreq.c 355264 2019-12-01 16:14:44Z tuexen $");
__FBSDID("$FreeBSD$");
#endif
#include <netinet/sctp_os.h>
#ifdef INET6
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/proc.h>
#endif
#include <netinet/sctp_pcb.h>
@ -58,14 +58,11 @@ __FBSDID("$FreeBSD: head/sys/netinet6/sctp6_usrreq.c 355264 2019-12-01 16:14:44Z
#include <netinet/sctp_output.h>
#include <netinet/sctp_bsd_addr.h>
#include <netinet/sctp_crc32.h>
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#include <netinet/icmp6.h>
#include <netinet/udp.h>
#endif
#if defined(__APPLE__)
#define APPLE_FILE_NO 9
#endif
#if defined(__Panda__) || defined(__Userspace__)
#if defined(__Userspace__)
int ip6_v6only=0;
#endif
#if defined(__Userspace__)
@ -73,7 +70,7 @@ int ip6_v6only=0;
void
in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6)
{
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
uint32_t temp;
#endif
memset(sin, 0, sizeof(*sin));
@ -82,7 +79,7 @@ in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6)
#endif
sin->sin_family = AF_INET;
sin->sin_port = sin6->sin6_port;
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
temp = sin6->sin6_addr.s6_addr16[7];
temp = temp << 16;
temp = temp | sin6->sin6_addr.s6_addr16[6];
@ -108,20 +105,20 @@ void
in6_sin_2_v4mapsin6(const struct sockaddr_in *sin, struct sockaddr_in6 *sin6)
{
memset(sin6, 0, sizeof(struct sockaddr_in6));
sin6->sin6_family = AF_INET6;
sin6->sin6_family = AF_INET6;
#ifdef HAVE_SIN6_LEN
sin6->sin6_len = sizeof(struct sockaddr_in6);
#endif
sin6->sin6_port = sin->sin_port;
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
((uint32_t *)&sin6->sin6_addr)[0] = 0;
((uint32_t *)&sin6->sin6_addr)[1] = 0;
((uint32_t *)&sin6->sin6_addr)[2] = htonl(0xffff);
((uint32_t *)&sin6->sin6_addr)[3] = sin->sin_addr.s_addr;
#else
sin6->sin6_addr.s6_addr32[0] = 0;
sin6->sin6_addr.s6_addr32[0] = 0;
sin6->sin6_addr.s6_addr32[1] = 0;
sin6->sin6_addr.s6_addr32[2] = htonl(0xffff);
sin6->sin6_addr.s6_addr32[2] = htonl(0xffff);
sin6->sin6_addr.s6_addr32[3] = sin->sin_addr.s_addr;
#endif
}
@ -132,8 +129,6 @@ in6_sin_2_v4mapsin6(const struct sockaddr_in *sin, struct sockaddr_in6 *sin6)
int
#if defined(__APPLE__) || defined(__FreeBSD__)
sctp6_input_with_port(struct mbuf **i_pak, int *offp, uint16_t port)
#elif defined( __Panda__)
sctp6_input(pakhandle_type *i_pak)
#else
sctp6_input(struct mbuf **i_pak, int *offp, int proto)
#endif
@ -153,25 +148,16 @@ sctp6_input(struct mbuf **i_pak, int *offp, int proto)
uint8_t mflowtype;
uint16_t fibnum;
#endif
#if !(defined(__APPLE__) || defined (__FreeBSD__))
#if !(defined(__APPLE__) || defined(__FreeBSD__))
uint16_t port = 0;
#endif
#if defined(__Panda__)
/* This is Evil, but its the only way to make panda work right. */
iphlen = sizeof(struct ip6_hdr);
#else
iphlen = *offp;
#endif
if (SCTP_GET_PKT_VRFID(*i_pak, vrf_id)) {
SCTP_RELEASE_PKT(*i_pak);
return (IPPROTO_DONE);
}
m = SCTP_HEADER_TO_CHAIN(*i_pak);
#ifdef __Panda__
SCTP_DETACH_HEADER_FROM_CHAIN(*i_pak);
(void)SCTP_RELEASE_HEADER(*i_pak);
#endif
#ifdef SCTP_MBUF_LOGGING
/* Log in any input mbufs */
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) {
@ -184,25 +170,11 @@ sctp6_input(struct mbuf **i_pak, int *offp, int proto)
}
#endif
#if defined(__FreeBSD__)
#if __FreeBSD_version > 1000049
SCTPDBG(SCTP_DEBUG_CRCOFFLOAD,
"sctp6_input(): Packet of length %d received on %s with csum_flags 0x%b.\n",
m->m_pkthdr.len,
if_name(m->m_pkthdr.rcvif),
(int)m->m_pkthdr.csum_flags, CSUM_BITS);
#elif __FreeBSD_version >= 800000
SCTPDBG(SCTP_DEBUG_CRCOFFLOAD,
"sctp6_input(): Packet of length %d received on %s with csum_flags 0x%x.\n",
m->m_pkthdr.len,
if_name(m->m_pkthdr.rcvif),
m->m_pkthdr.csum_flags);
#else
SCTPDBG(SCTP_DEBUG_CRCOFFLOAD,
"sctp6_input(): Packet of length %d received on %s with csum_flags 0x%x.\n",
m->m_pkthdr.len,
m->m_pkthdr.rcvif->if_xname,
m->m_pkthdr.csum_flags);
#endif
#endif
#if defined(__APPLE__)
SCTPDBG(SCTP_DEBUG_CRCOFFLOAD,
@ -212,7 +184,7 @@ sctp6_input(struct mbuf **i_pak, int *offp, int proto)
m->m_pkthdr.rcvif->if_unit,
m->m_pkthdr.csum_flags);
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
SCTPDBG(SCTP_DEBUG_CRCOFFLOAD,
"sctp6_input(): Packet of length %d received on %s with csum_flags 0x%x.\n",
m->m_pkthdr.len,
@ -287,13 +259,14 @@ sctp6_input(struct mbuf **i_pak, int *offp, int proto)
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
goto out;
}
ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
#if defined(__FreeBSD__) && __FreeBSD_version >= 800000
#if defined(__FreeBSD__)
ecn_bits = IPV6_TRAFFIC_CLASS(ip6);
if (m->m_pkthdr.csum_flags & CSUM_SCTP_VALID) {
SCTP_STAT_INCR(sctps_recvhwcrc);
compute_crc = 0;
} else {
#else
ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
(IN6_ARE_ADDR_EQUAL(&src.sin6_addr, &dst.sin6_addr))) {
SCTP_STAT_INCR(sctps_recvhwcrc);
@ -327,7 +300,6 @@ sctp6_input(struct mbuf **i_pak, int *offp)
return (sctp6_input_with_port(i_pak, offp, 0));
}
#endif
#if defined(__FreeBSD__)
int
sctp6_input(struct mbuf **i_pak, int *offp, int proto SCTP_UNUSED)
@ -344,7 +316,7 @@ sctp6_notify(struct sctp_inpcb *inp,
uint8_t icmp6_code,
uint32_t next_mtu)
{
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#if defined(__APPLE__)
struct socket *so;
#endif
int timer_stopped;
@ -369,8 +341,8 @@ sctp6_notify(struct sctp_inpcb *inp,
case ICMP6_PARAM_PROB:
/* Treat it like an ABORT. */
if (icmp6_code == ICMP6_PARAMPROB_NEXTHEADER) {
sctp_abort_notification(stcb, 1, 0, NULL, SCTP_SO_NOT_LOCKED);
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
sctp_abort_notification(stcb, true, false, 0, NULL, SCTP_SO_NOT_LOCKED);
#if defined(__APPLE__)
so = SCTP_INP_SO(inp);
atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb);
@ -380,7 +352,7 @@ sctp6_notify(struct sctp_inpcb *inp,
#endif
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2);
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#if defined(__APPLE__)
SCTP_SOCKET_UNLOCK(so, 1);
#endif
} else {
@ -595,11 +567,6 @@ sctp6_ctlinput(int cmd, struct sockaddr *pktdst, void *d)
}
#endif
} else {
#if defined(__FreeBSD__) && __FreeBSD_version < 500000
if (PRC_IS_REDIRECT(cmd) && (inp != NULL)) {
in6_rtchange(inp, inet6ctlerrmap[cmd]);
}
#endif
if ((stcb == NULL) && (inp != NULL)) {
/* reduce inp's ref-count */
SCTP_INP_WLOCK(inp);
@ -618,7 +585,7 @@ sctp6_ctlinput(int cmd, struct sockaddr *pktdst, void *d)
* this routine can probably be collasped into the one in sctp_userreq.c
* since they do the same thing and now we lookup with a sockaddr
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
static int
sctp6_getcred(SYSCTL_HANDLER_ARGS)
{
@ -630,16 +597,10 @@ sctp6_getcred(SYSCTL_HANDLER_ARGS)
int error;
uint32_t vrf_id;
#if defined(__FreeBSD__) || defined(__APPLE__)
vrf_id = SCTP_DEFAULT_VRFID;
#else
vrf_id = panda_get_vrf_from_call(); /* from connectx call? */
#endif
#if defined(__FreeBSD__) && __FreeBSD_version > 602000
#if defined(__FreeBSD__) && !defined(__Userspace__)
error = priv_check(req->td, PRIV_NETINET_GETCRED);
#elif defined(__FreeBSD__) && __FreeBSD_version >= 500000
error = suser(req->td);
#else
error = suser(req->p);
#endif
@ -694,34 +655,40 @@ out:
return (error);
}
SYSCTL_PROC(_net_inet6_sctp6, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW,
0, 0,
sctp6_getcred, "S,ucred", "Get the ucred of a SCTP6 connection");
SYSCTL_PROC(_net_inet6_sctp6, OID_AUTO, getcred,
CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
0, 0, sctp6_getcred, "S,ucred",
"Get the ucred of a SCTP6 connection");
#endif
/* This is the same as the sctp_abort() could be made common */
#if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__)
static void
#elif defined(__Panda__) || defined(__Userspace__)
#if defined(__Userspace__)
int
#elif defined(__FreeBSD__) || defined(_WIN32)
static void
#else
static int
#endif
sctp6_abort(struct socket *so)
{
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct epoch_tracker et;
#endif
struct sctp_inpcb *inp;
uint32_t flags;
inp = (struct sctp_inpcb *)so->so_pcb;
if (inp == NULL) {
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
#if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__)
#if (defined(__FreeBSD__) || defined(_WIN32)) && !defined(__Userspace__)
return;
#else
return (EINVAL);
#endif
}
#if defined(__FreeBSD__) && !defined(__Userspace__)
NET_EPOCH_ENTER(et);
#endif
sctp_must_try_again:
flags = inp->sctp_flags;
#ifdef SCTP_LOG_CLOSING
@ -740,7 +707,7 @@ sctp6_abort(struct socket *so)
* here for the accounting/select.
*/
SCTP_SB_CLEAR(so->so_rcv);
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
so->so_usecount--;
#else
/* Now null out the reference, we are completely detached. */
@ -753,20 +720,21 @@ sctp6_abort(struct socket *so)
goto sctp_must_try_again;
}
}
#if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
NET_EPOCH_EXIT(et);
return;
#else
return (0);
#endif
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
static int
sctp6_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
#elif defined(__Panda__) || defined(__Userspace__)
#if defined(__Userspace__)
int
sctp6_attach(struct socket *so, int proto SCTP_UNUSED, uint32_t vrf_id)
#elif defined(__Windows__)
#elif defined(__FreeBSD__)
static int
sctp6_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED)
#elif defined(_WIN32)
static int
sctp6_attach(struct socket *so, int proto SCTP_UNUSED, PKTHREAD p SCTP_UNUSED)
#else
@ -776,7 +744,7 @@ sctp6_attach(struct socket *so, int proto SCTP_UNUSED, struct proc *p SCTP_UNUSE
{
int error;
struct sctp_inpcb *inp;
#if !defined(__Panda__) && !defined(__Userspace__)
#if !defined(__Userspace__)
uint32_t vrf_id = SCTP_DEFAULT_VRFID;
#endif
@ -798,15 +766,9 @@ sctp6_attach(struct socket *so, int proto SCTP_UNUSED, struct proc *p SCTP_UNUSE
SCTP_INP_WLOCK(inp);
inp->sctp_flags |= SCTP_PCB_FLAGS_BOUND_V6; /* I'm v6! */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
inp->ip_inp.inp.inp_vflag |= INP_IPV6;
#else
inp->inp_vflag |= INP_IPV6;
#endif
#if !defined(__Panda__)
inp->ip_inp.inp.in6p_hops = -1; /* use kernel default */
inp->ip_inp.inp.in6p_cksum = -1; /* just to be sure */
#endif
#ifdef INET
/*
* XXX: ugly!! IPv4 TTL initialization is necessary for an IPv6
@ -819,19 +781,19 @@ sctp6_attach(struct socket *so, int proto SCTP_UNUSED, struct proc *p SCTP_UNUSE
return (0);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
static int
sctp6_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
{
#elif defined(__FreeBSD__) || defined(__APPLE__)
static int
sctp6_bind(struct socket *so, struct sockaddr *addr, struct proc *p)
{
#elif defined(__Panda__) || defined(__Userspace__)
#if defined(__Userspace__)
int
sctp6_bind(struct socket *so, struct sockaddr *addr, void * p)
{
#elif defined(__Windows__)
#elif defined(__FreeBSD__)
static int
sctp6_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
{
#elif defined(__APPLE__)
static int
sctp6_bind(struct socket *so, struct sockaddr *addr, struct proc *p)
{
#elif defined(_WIN32)
static int
sctp6_bind(struct socket *so, struct sockaddr *addr, PKTHREAD p)
{
@ -852,7 +814,7 @@ sctp6_bind(struct socket *so, struct mbuf *nam, struct proc *p)
return (EINVAL);
}
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
if (addr) {
switch (addr->sa_family) {
#ifdef INET
@ -881,27 +843,16 @@ sctp6_bind(struct socket *so, struct mbuf *nam, struct proc *p)
}
}
#endif
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
vflagsav = inp->ip_inp.inp.inp_vflag;
inp->ip_inp.inp.inp_vflag &= ~INP_IPV4;
inp->ip_inp.inp.inp_vflag |= INP_IPV6;
#else
vflagsav = inp->inp_vflag;
inp->inp_vflag &= ~INP_IPV4;
inp->inp_vflag |= INP_IPV6;
#endif
if ((addr != NULL) && (SCTP_IPV6_V6ONLY(inp) == 0)) {
switch (addr->sa_family) {
#ifdef INET
case AF_INET:
/* binding v4 addr to v6 socket, so reset flags */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
inp->ip_inp.inp.inp_vflag |= INP_IPV4;
inp->ip_inp.inp.inp_vflag &= ~INP_IPV6;
#else
inp->inp_vflag |= INP_IPV4;
inp->inp_vflag &= ~INP_IPV6;
#endif
break;
#endif
#ifdef INET6
@ -912,24 +863,15 @@ sctp6_bind(struct socket *so, struct mbuf *nam, struct proc *p)
sin6_p = (struct sockaddr_in6 *)addr;
if (IN6_IS_ADDR_UNSPECIFIED(&sin6_p->sin6_addr)) {
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
inp->ip_inp.inp.inp_vflag |= INP_IPV4;
#else
inp->inp_vflag |= INP_IPV4;
#endif
}
#ifdef INET
if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
struct sockaddr_in sin;
in6_sin6_2_sin(&sin, sin6_p);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
inp->ip_inp.inp.inp_vflag |= INP_IPV4;
inp->ip_inp.inp.inp_vflag &= ~INP_IPV6;
#else
inp->inp_vflag |= INP_IPV4;
inp->inp_vflag &= ~INP_IPV6;
#endif
error = sctp_inpcb_bind(so, (struct sockaddr *)&sin, NULL, p);
goto out;
}
@ -965,16 +907,11 @@ sctp6_bind(struct socket *so, struct mbuf *nam, struct proc *p)
error = sctp_inpcb_bind(so, addr, NULL, p);
out:
if (error != 0)
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
inp->ip_inp.inp.inp_vflag = vflagsav;
#else
inp->inp_vflag = vflagsav;
#endif
return (error);
}
#if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
#if !defined(__Userspace__)
static void
#else
@ -988,9 +925,7 @@ sctp6_close(struct socket *so)
/* This could be made common with sctp_detach() since they are identical */
#else
#if !defined(__Panda__)
static
#endif
int
sctp6_detach(struct socket *so)
{
@ -1004,7 +939,7 @@ sctp6_detach(struct socket *so)
#endif
#if !defined(__Panda__) && !defined(__Userspace__)
#if !defined(__Userspace__)
static
#endif
int
@ -1013,25 +948,22 @@ sctp6_disconnect(struct socket *so)
return (sctp_disconnect(so));
}
int
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
struct mbuf *control, struct thread *p);
#else
sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
struct mbuf *control, struct proc *p);
#endif
#if !defined(__Panda__) && !defined(__Windows__) && !defined(__Userspace__)
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if !defined(_WIN32) && !defined(__Userspace__)
#if defined(__FreeBSD__)
static int
sctp6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
struct mbuf *control, struct thread *p)
{
#elif defined(__FreeBSD__) || defined(__APPLE__)
#elif defined(__APPLE__)
static int
sctp6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
struct mbuf *control, struct proc *p)
@ -1077,6 +1009,46 @@ sctp6_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam,
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EDESTADDRREQ);
return (EDESTADDRREQ);
}
switch (addr->sa_family) {
#ifdef INET
case AF_INET:
#if defined(HAVE_SA_LEN)
if (addr->sa_len != sizeof(struct sockaddr_in)) {
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
#endif
break;
#endif
#ifdef INET6
case AF_INET6:
#if defined(HAVE_SA_LEN)
if (addr->sa_len != sizeof(struct sockaddr_in6)) {
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
#endif
break;
#endif
default:
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
#ifdef INET
sin6 = (struct sockaddr_in6 *)addr;
if (SCTP_IPV6_V6ONLY(inp)) {
@ -1085,15 +1057,26 @@ sctp6_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam,
* v4 addr or v4-mapped addr
*/
if (addr->sa_family == AF_INET) {
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
}
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
if ((addr->sa_family == AF_INET6) &&
IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
struct sockaddr_in sin;
/* convert v4-mapped into v4 addr and send */
@ -1119,7 +1102,7 @@ connected_type:
inp->pkt_last = inp->pkt = m;
}
if (
#if defined(__FreeBSD__) || defined(__APPLE__)
#if (defined(__FreeBSD__) || defined(__APPLE__)) && !defined(__Userspace__)
/* FreeBSD and MacOSX uses a flag passed */
((flags & PRUS_MORETOCOME) == 0)
#else
@ -1134,9 +1117,18 @@ connected_type:
* optionaly switch back to this code (by changing back the
* defininitions but this is not advisable.
*/
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct epoch_tracker et;
#endif
int ret;
#if defined(__FreeBSD__) && !defined(__Userspace__)
NET_EPOCH_ENTER(et);
#endif
ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags);
#if defined(__FreeBSD__) && !defined(__Userspace__)
NET_EPOCH_EXIT(et);
#endif
inp->pkt = NULL;
inp->control = NULL;
return (ret);
@ -1146,32 +1138,31 @@ connected_type:
}
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
static int
sctp6_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
{
#elif defined(__FreeBSD__) || defined(__APPLE__)
static int
sctp6_connect(struct socket *so, struct sockaddr *addr, struct proc *p)
{
#elif defined(__Panda__)
int
sctp6_connect(struct socket *so, struct sockaddr *addr, void *p)
{
#elif defined(__Windows__)
static int
sctp6_connect(struct socket *so, struct sockaddr *addr, PKTHREAD p)
{
#elif defined(__Userspace__)
#if defined(__Userspace__)
int
sctp6_connect(struct socket *so, struct sockaddr *addr)
{
void *p = NULL;
#elif defined(__FreeBSD__)
static int
sctp6_connect(struct socket *so, struct sockaddr *addr, struct thread *p)
{
#elif defined(__APPLE__)
static int
sctp6_connect(struct socket *so, struct sockaddr *addr, struct proc *p)
{
#elif defined(_WIN32)
static int
sctp6_connect(struct socket *so, struct sockaddr *addr, PKTHREAD p)
{
#else
static int
sctp6_connect(struct socket *so, struct mbuf *nam, struct proc *p)
{
struct sockaddr *addr = mtod(nam, struct sockaddr *);
#endif
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct epoch_tracker et;
#endif
uint32_t vrf_id;
int error = 0;
@ -1192,7 +1183,7 @@ sctp6_connect(struct socket *so, struct mbuf *nam, struct proc *p)
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
switch (addr->sa_family) {
#ifdef INET
case AF_INET:
@ -1263,7 +1254,8 @@ sctp6_connect(struct socket *so, struct mbuf *nam, struct proc *p)
return (EINVAL);
}
}
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
if ((addr->sa_family == AF_INET6) &&
IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
/* convert v4-mapped into v4 addr */
in6_sin6_2_sin(&store.sin, sin6);
addr = &store.sa;
@ -1297,36 +1289,33 @@ sctp6_connect(struct socket *so, struct mbuf *nam, struct proc *p)
return (EALREADY);
}
/* We are GOOD to go */
stcb = sctp_aloc_assoc(inp, addr, &error, 0, vrf_id,
inp->sctp_ep.pre_open_stream_count,
inp->sctp_ep.port, p,
SCTP_INITIALIZE_AUTH_PARAMS);
stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id,
inp->sctp_ep.pre_open_stream_count,
inp->sctp_ep.port, p,
SCTP_INITIALIZE_AUTH_PARAMS);
SCTP_ASOC_CREATE_UNLOCK(inp);
if (stcb == NULL) {
/* Gak! no memory */
return (error);
}
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) {
stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED;
/* Set the connected flag so we can queue data */
soisconnecting(so);
}
SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT);
(void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
#if defined(__FreeBSD__) && !defined(__Userspace__)
NET_EPOCH_ENTER(et);
#endif
sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED);
SCTP_TCB_UNLOCK(stcb);
#if defined(__FreeBSD__) && !defined(__Userspace__)
NET_EPOCH_EXIT(et);
#endif
return (error);
}
static int
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
sctp6_getaddr(struct socket *so, struct sockaddr **addr)
{
struct sockaddr_in6 *sin6;
#elif defined(__Panda__)
sctp6_getaddr(struct socket *so, struct sockaddr *addr)
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
#else
sctp6_getaddr(struct socket *so, struct mbuf *nam)
{
@ -1336,19 +1325,17 @@ sctp6_getaddr(struct socket *so, struct mbuf *nam)
uint32_t vrf_id;
struct sctp_ifa *sctp_ifa;
#ifdef SCTP_KAME
#if defined(SCTP_KAME) && defined(SCTP_EMBEDDED_V6_SCOPE)
int error;
#endif /* SCTP_KAME */
#endif
/*
* Do the malloc first in case it blocks.
*/
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof(*sin6));
if (sin6 == NULL)
return (ENOMEM);
#elif defined(__Panda__)
memset(sin6, 0, sizeof(*sin6));
#else
SCTP_BUF_LEN(nam) = sizeof(*sin6);
memset(sin6, 0, sizeof(*sin6));
@ -1360,7 +1347,7 @@ sctp6_getaddr(struct socket *so, struct mbuf *nam)
inp = (struct sctp_inpcb *)so->so_pcb;
if (inp == NULL) {
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_FREE_SONAME(sin6);
#endif
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ECONNRESET);
@ -1378,7 +1365,7 @@ sctp6_getaddr(struct socket *so, struct mbuf *nam)
stcb = LIST_FIRST(&inp->sctp_asoc_list);
if (stcb == NULL) {
SCTP_INP_RUNLOCK(inp);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_FREE_SONAME(sin6);
#endif
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
@ -1400,7 +1387,7 @@ sctp6_getaddr(struct socket *so, struct mbuf *nam)
if ((!fnd) || (sin_a6 == NULL)) {
/* punt */
SCTP_INP_RUNLOCK(inp);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_FREE_SONAME(sin6);
#endif
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
@ -1431,7 +1418,7 @@ sctp6_getaddr(struct socket *so, struct mbuf *nam)
}
}
if (!fnd) {
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_FREE_SONAME(sin6);
#endif
SCTP_INP_RUNLOCK(inp);
@ -1455,21 +1442,17 @@ sctp6_getaddr(struct socket *so, struct mbuf *nam)
sin6->sin6_scope_id = 0; /* XXX */
#endif /* SCTP_KAME */
#endif /* SCTP_EMBEDDED_V6_SCOPE */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
(*addr) = (struct sockaddr *)sin6;
#endif
return (0);
}
static int
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
sctp6_peeraddr(struct socket *so, struct sockaddr **addr)
{
struct sockaddr_in6 *sin6;
#elif defined(__Panda__)
sctp6_peeraddr(struct socket *so, struct sockaddr *addr)
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
#else
sctp6_peeraddr(struct socket *so, struct mbuf *nam)
{
@ -1485,12 +1468,10 @@ sctp6_peeraddr(struct socket *so, struct mbuf *nam)
#endif
/* Do the malloc first in case it blocks. */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
if (sin6 == NULL)
return (ENOMEM);
#elif defined(__Panda__)
memset(sin6, 0, sizeof(*sin6));
#else
SCTP_BUF_LEN(nam) = sizeof(*sin6);
memset(sin6, 0, sizeof(*sin6));
@ -1504,7 +1485,7 @@ sctp6_peeraddr(struct socket *so, struct mbuf *nam)
if ((inp == NULL) ||
((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) {
/* UDP type and listeners will drop out here */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_FREE_SONAME(sin6);
#endif
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOTCONN);
@ -1517,7 +1498,7 @@ sctp6_peeraddr(struct socket *so, struct mbuf *nam)
}
SCTP_INP_RUNLOCK(inp);
if (stcb == NULL) {
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_FREE_SONAME(sin6);
#endif
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ECONNRESET);
@ -1536,7 +1517,7 @@ sctp6_peeraddr(struct socket *so, struct mbuf *nam)
SCTP_TCB_UNLOCK(stcb);
if (!fnd) {
/* No IPv4 address */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_FREE_SONAME(sin6);
#endif
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, ENOENT);
@ -1545,7 +1526,7 @@ sctp6_peeraddr(struct socket *so, struct mbuf *nam)
#ifdef SCTP_EMBEDDED_V6_SCOPE
#ifdef SCTP_KAME
if ((error = sa6_recoverscope(sin6)) != 0) {
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_FREE_SONAME(sin6);
#endif
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, error);
@ -1555,21 +1536,16 @@ sctp6_peeraddr(struct socket *so, struct mbuf *nam)
in6_recoverscope(sin6, &sin6->sin6_addr, NULL);
#endif /* SCTP_KAME */
#endif /* SCTP_EMBEDDED_V6_SCOPE */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
*addr = (struct sockaddr *)sin6;
#endif
return (0);
}
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
static int
sctp6_in6getaddr(struct socket *so, struct sockaddr **nam)
{
#elif defined(__Panda__)
int
sctp6_in6getaddr(struct socket *so, struct sockaddr *nam, uint32_t *namelen)
{
struct sockaddr *addr = nam;
#elif defined(__Userspace__)
int
sctp6_in6getaddr(struct socket *so, struct mbuf *nam)
@ -1597,7 +1573,7 @@ sctp6_in6getaddr(struct socket *so, struct mbuf *nam)
error = sctp6_getaddr(so, nam);
#ifdef INET
if (error) {
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
struct sockaddr_in6 *sin6;
#else
struct sockaddr_in6 sin6;
@ -1608,7 +1584,7 @@ sctp6_in6getaddr(struct socket *so, struct mbuf *nam)
if (error) {
return (error);
}
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
if (sin6 == NULL) {
SCTP_FREE_SONAME(*nam);
@ -1623,23 +1599,14 @@ sctp6_in6getaddr(struct socket *so, struct mbuf *nam)
memcpy(addr, &sin6, sizeof(struct sockaddr_in6));
#endif
}
#endif
#if defined(__Panda__)
*namelen = nam->sa_len;
#endif
return (error);
}
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
static int
sctp6_getpeeraddr(struct socket *so, struct sockaddr **nam)
{
#elif defined(__Panda__)
int
sctp6_getpeeraddr(struct socket *so, struct sockaddr *nam, uint32_t *namelen)
{
struct sockaddr *addr = (struct sockaddr *)nam;
#elif defined(__Userspace__)
int
sctp6_getpeeraddr(struct socket *so, struct mbuf *nam)
@ -1669,7 +1636,7 @@ sctp6_getpeeraddr(struct socket *so, struct mbuf *nam)
error = sctp6_peeraddr(so, nam);
#ifdef INET
if (error) {
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
struct sockaddr_in6 *sin6;
#else
struct sockaddr_in6 sin6;
@ -1680,7 +1647,7 @@ sctp6_getpeeraddr(struct socket *so, struct mbuf *nam)
if (error) {
return (error);
}
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6);
if (sin6 == NULL) {
SCTP_FREE_SONAME(*nam);
@ -1695,14 +1662,11 @@ sctp6_getpeeraddr(struct socket *so, struct mbuf *nam)
memcpy(addr, &sin6, sizeof(struct sockaddr_in6));
#endif
}
#endif
#if defined(__Panda__)
*namelen = nam->sa_len;
#endif
return (error);
}
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
struct pr_usrreqs sctp6_usrreqs = {
#if defined(__FreeBSD__)
.pru_abort = sctp6_abort,
@ -1711,15 +1675,10 @@ struct pr_usrreqs sctp6_usrreqs = {
.pru_bind = sctp6_bind,
.pru_connect = sctp6_connect,
.pru_control = in6_control,
#if __FreeBSD_version >= 690000
.pru_close = sctp6_close,
.pru_detach = sctp6_close,
.pru_sopoll = sopoll_generic,
.pru_flush = sctp_flush,
#else
.pru_detach = sctp6_detach,
.pru_sopoll = sopoll,
#endif
.pru_disconnect = sctp6_disconnect,
.pru_listen = sctp_listen,
.pru_peeraddr = sctp6_getpeeraddr,
@ -1728,7 +1687,7 @@ struct pr_usrreqs sctp6_usrreqs = {
.pru_sockaddr = sctp6_in6getaddr,
.pru_sosend = sctp_sosend,
.pru_soreceive = sctp_soreceive
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
.pru_abort = sctp6_abort,
.pru_accept = sctp_accept,
.pru_attach = sctp6_attach,
@ -1749,7 +1708,7 @@ struct pr_usrreqs sctp6_usrreqs = {
.pru_sosend = sctp_sosend,
.pru_soreceive = sctp_soreceive,
.pru_sopoll = sopoll
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
sctp6_abort,
sctp_accept,
sctp6_attach,
@ -1776,7 +1735,7 @@ struct pr_usrreqs sctp6_usrreqs = {
#endif
};
#elif !defined(__Panda__) && !defined(__Userspace__)
#elif !defined(__Userspace__)
int
sctp6_usrreq(so, req, m, nam, control, p)
struct socket *so;
@ -1784,22 +1743,22 @@ sctp6_usrreq(so, req, m, nam, control, p)
struct mbuf *m, *nam, *control;
struct proc *p;
{
int s;
int error = 0;
int error;
int family;
uint32_t vrf_id;
family = so->so_proto->pr_domain->dom_family;
if (req == PRU_CONTROL) {
switch (family) {
case PF_INET:
error = in_control(so, (long)m, (caddr_t)nam,
(struct ifnet *)control
);
(struct ifnet *)control);
break;
#ifdef INET6
case PF_INET6:
error = in6_control(so, (long)m, (caddr_t)nam,
(struct ifnet *)control, p);
break;
#endif
default:
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EAFNOSUPPORT);
@ -1883,6 +1842,7 @@ sctp6_usrreq(so, req, m, nam, control, p)
error = 0;
break;
default:
error = 0;
break;
}
return (error);

View File

@ -32,7 +32,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet6/sctp6_var.h 317457 2017-04-26 19:26:40Z tuexen $");
#endif
@ -49,40 +49,28 @@ extern void in6_sin_2_v4mapsin6(const struct sockaddr_in *, struct sockaddr_in6
#endif
#if defined(_KERNEL)
#if defined(__FreeBSD__) || (__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SYSCTL_DECL(_net_inet6_sctp6);
extern struct pr_usrreqs sctp6_usrreqs;
#else
int sctp6_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *);
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
int sctp6_input(struct mbuf **, int *);
int sctp6_input_with_port(struct mbuf **, int *, uint16_t);
#elif defined(__Panda__)
int sctp6_input (pakhandle_type *);
#elif defined(__FreeBSD__) && __FreeBSD_version < 902000
int sctp6_input __P((struct mbuf **, int *, int));
int sctp6_input_with_port __P((struct mbuf **, int *, uint16_t));
#else
int sctp6_input(struct mbuf **, int *, int);
int sctp6_input_with_port(struct mbuf **, int *, uint16_t);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
int sctp6_output
__P((struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct proc *));
void sctp6_ctlinput __P((int, struct sockaddr *, void *));
#else
int sctp6_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct proc *);
#if defined(__APPLE__) && !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION) && !defined(APPLE_ELCAPITAN)
#if defined(__APPLE__) && !defined(__Userspace__) && !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION) && !defined(APPLE_ELCAPITAN)
void sctp6_ctlinput(int, struct sockaddr *, void *, struct ifnet * SCTP_UNUSED);
#else
void sctp6_ctlinput(int, struct sockaddr *, void *);
#endif
#endif
#if !(defined(__FreeBSD__) || defined(__APPLE__))
#if !((defined(__FreeBSD__) || defined(__APPLE__)) && !defined(__Userspace__))
extern void in6_sin_2_v4mapsin6(struct sockaddr_in *, struct sockaddr_in6 *);
extern void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *);
extern void in6_sin6_2_sin_in_sock(struct sockaddr *);

View File

@ -42,8 +42,8 @@
#include <stdio.h>
#include <sys/types.h>
#if defined(__Userspace_os_Darwin) || defined (__Userspace_os_Windows)
#if defined (__Userspace_os_Windows)
#if defined(__APPLE__) || defined(_WIN32)
#if defined(_WIN32)
#define atomic_add_int(addr, val) InterlockedExchangeAdd((LPLONG)addr, (LONG)val)
#define atomic_fetchadd_int(addr, val) InterlockedExchangeAdd((LPLONG)addr, (LONG)val)
#define atomic_subtract_int(addr, val) InterlockedExchangeAdd((LPLONG)addr,-((LONG)val))
@ -77,7 +77,7 @@
} \
}
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
static void atomic_init(void) {} /* empty when we are not using atomic_mtx */
#else
static inline void atomic_init(void) {} /* empty when we are not using atomic_mtx */
@ -173,7 +173,7 @@ static inline void atomic_init() {} /* empty when we are not using atomic_mtx */
extern userland_mutex_t atomic_mtx;
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
static inline void atomic_init() {
InitializeCriticalSection(&atomic_mtx);
}

View File

@ -30,18 +30,23 @@
/* __Userspace__ */
#include <stdlib.h>
#if !defined (__Userspace_os_Windows)
#if defined(_WIN32)
#if !defined(_CRT_RAND_S) && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
#define _CRT_RAND_S
#endif
#else
#include <stdint.h>
#include <netinet/sctp_os_userspace.h>
#endif
#ifdef INVARIANTS
#include <netinet/sctp_pcb.h>
#endif
#include <user_environment.h>
#include <sys/types.h>
/* #include <sys/param.h> defines MIN */
#if !defined(MIN)
#define MIN(arg1,arg2) ((arg1) < (arg2) ? (arg1) : (arg2))
#endif
#include <string.h>
#define uHZ 1000
@ -64,50 +69,316 @@ userland_mutex_t atomic_mtx;
* provide _some_ kind of randomness. This should only be used
* inside other RNG's, like arc4random(9).
*/
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
static int
read_random_phony(void *buf, int count)
#if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
#include <string.h>
void
init_random(void)
{
memset(buf, 'A', count);
return (count);
return;
}
#else
#if defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Darwin)
static int
read_random_phony(void *buf, int count)
void
read_random(void *buf, size_t size)
{
if (count >= 0) {
arc4random_buf(buf, count);
memset(buf, 'A', size);
return;
}
void
finish_random(void)
{
return;
}
/* This define can be used to optionally use OpenSSL's random number utility,
* which is capable of bypassing the chromium sandbox which normally would
* prevent opening files, including /dev/urandom.
*/
#elif defined(SCTP_USE_OPENSSL_RAND)
#include <openssl/rand.h>
/* Requiring BoringSSL because it guarantees that RAND_bytes will succeed. */
#ifndef OPENSSL_IS_BORINGSSL
#error Only BoringSSL is supported with SCTP_USE_OPENSSL_RAND.
#endif
void
init_random(void)
{
return;
}
void
read_random(void *buf, size_t size)
{
RAND_bytes((uint8_t *)buf, size);
return;
}
void
finish_random(void)
{
return;
}
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(__Bitrig__)
#include <stdlib.h>
void
init_random(void)
{
return;
}
void
read_random(void *buf, size_t size)
{
arc4random_buf(buf, size);
return;
}
void
finish_random(void)
{
return;
}
#elif defined(_WIN32)
#include <stdlib.h>
void
init_random(void)
{
return;
}
void
read_random(void *buf, size_t size)
{
unsigned int randval;
size_t position, remaining;
position = 0;
while (position < size) {
if (rand_s(&randval) == 0) {
remaining = MIN(size - position, sizeof(unsigned int));
memcpy((char *)buf + position, &randval, remaining);
position += sizeof(unsigned int);
}
}
return (count);
return;
}
#else
static int
read_random_phony(void *buf, int count)
void
finish_random(void)
{
uint32_t randval;
int size, i;
/* srandom() is called in kern/init_main.c:proc0_post() */
/* Fill buf[] with random(9) output */
for (i = 0; i < count; i+= (int)sizeof(uint32_t)) {
randval = random();
size = MIN(count - i, (int)sizeof(uint32_t));
memcpy(&((char *)buf)[i], &randval, (size_t)size);
}
return (count);
return;
}
#elif (defined(__ANDROID__) && (__ANDROID_API__ < 28)) || defined(__EMSCRIPTEN__)
#include <fcntl.h>
static int fd = -1;
void
init_random(void)
{
fd = open("/dev/urandom", O_RDONLY);
return;
}
void
read_random(void *buf, size_t size)
{
size_t position;
ssize_t n;
position = 0;
while (position < size) {
n = read(fd, (char *)buf + position, size - position);
if (n > 0) {
position += n;
}
}
return;
}
void
finish_random(void)
{
close(fd);
return;
}
#elif defined(__ANDROID__) && (__ANDROID_API__ >= 28)
#include <sys/random.h>
void
init_random(void)
{
return;
}
void
read_random(void *buf, size_t size)
{
size_t position;
ssize_t n;
position = 0;
while (position < size) {
n = getrandom((char *)buf + position, size - position, 0);
if (n > 0) {
position += n;
}
}
return;
}
void
finish_random(void)
{
return;
}
#elif defined(__linux__)
#include <fcntl.h>
#include <unistd.h>
#include <sys/syscall.h>
#if defined(__has_feature)
#if __has_feature(memory_sanitizer)
void __msan_unpoison(void *, size_t);
#endif
#endif
static int (*read_func)(void *, int) = read_random_phony;
#ifdef __NR_getrandom
#if !defined(GRND_NONBLOCK)
#define GRND_NONBLOCK 1
#endif
static int getrandom_available = 0;
#endif
static int fd = -1;
/* Userland-visible version of read_random */
int
read_random(void *buf, int count)
void
init_random(void)
{
return ((*read_func)(buf, count));
#ifdef __NR_getrandom
char dummy;
ssize_t n = syscall(__NR_getrandom, &dummy, sizeof(dummy), GRND_NONBLOCK);
if (n > 0 || errno == EINTR || errno == EAGAIN) {
/* Either getrandom succeeded, was interrupted or is waiting for entropy;
* all of which mean the syscall is available.
*/
getrandom_available = 1;
} else {
#ifdef INVARIANTS
if (errno != ENOSYS) {
panic("getrandom syscall returned unexpected error: %d", errno);
}
#endif
/* If the syscall isn't available, fall back to /dev/urandom. */
#endif
fd = open("/dev/urandom", O_RDONLY);
#ifdef __NR_getrandom
}
#endif
return;
}
void
read_random(void *buf, size_t size)
{
size_t position;
ssize_t n;
position = 0;
while (position < size) {
#ifdef __NR_getrandom
if (getrandom_available) {
/* Using syscall directly because getrandom isn't present in glibc < 2.25.
*/
n = syscall(__NR_getrandom, (char *)buf + position, size - position, 0);
if (n > 0) {
#if defined(__has_feature)
#if __has_feature(memory_sanitizer)
/* Need to do this because MSan doesn't realize that syscall has
* initialized the output buffer.
*/
__msan_unpoison(buf + position, n);
#endif
#endif
position += n;
} else if (errno != EINTR && errno != EAGAIN) {
#ifdef INVARIANTS
panic("getrandom syscall returned unexpected error: %d", errno);
#endif
}
} else
#endif /* __NR_getrandom */
{
n = read(fd, (char *)buf + position, size - position);
if (n > 0) {
position += n;
}
}
}
return;
}
void
finish_random(void)
{
if (fd != -1) {
close(fd);
}
return;
}
#elif defined(__Fuchsia__)
#include <zircon/syscalls.h>
void
init_random(void)
{
return;
}
void
read_random(void *buf, size_t size)
{
zx_cprng_draw(buf, size);
return;
}
void
finish_random(void)
{
return;
}
#elif defined(__native_client__)
#include <nacl/nacl_random.h>
void
init_random(void)
{
return;
}
void
read_random(void *buf, size_t size)
{
size_t position;
size_t n;
position = 0;
while (position < size) {
if (nacl_secure_random((char *)buf + position, size - position, &n) == 0)
position += n;
}
}
return;
}
void
finish_random(void)
{
return;
}
#else
#error "Unknown platform. Please provide platform specific RNG."
#endif

View File

@ -33,12 +33,12 @@
/* __Userspace__ */
#include <sys/types.h>
#ifdef __Userspace_os_FreeBSD
#ifdef __FreeBSD__
#ifndef _SYS_MUTEX_H_
#include <sys/mutex.h>
#endif
#endif
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
#include "netinet/sctp_os_userspace.h"
#endif
@ -63,11 +63,13 @@ extern int ipport_firstauto, ipport_lastauto;
extern int nmbclusters;
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#endif
extern int read_random(void *buf, int count);
void init_random(void);
void read_random(void *, size_t);
void finish_random(void);
/* errno's may differ per OS. errno.h now included in sctp_os_userspace.h */
/* Source: /usr/src/sys/sys/errno.h */
@ -82,14 +84,18 @@ extern int read_random(void *buf, int count);
/* Source ip_output.c. extern'd in ip_var.h */
extern u_short ip_id;
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#define IPV6_VERSION 0x60
#endif
#if defined(INVARIANTS)
#include <stdlib.h>
static inline void
#if defined(_WIN32)
static inline void __declspec(noreturn)
#else
static inline void __attribute__((__noreturn__))
#endif
terminate_non_graceful(void) {
abort();
}

View File

@ -10,7 +10,7 @@
* 2. 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.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -54,7 +54,7 @@ LIST_HEAD(inpcbporthead, inpcbport);
* the following structure.
*/
struct in_addr_4in6 {
u_int32_t ia46_pad32[3];
uint32_t ia46_pad32[3];
struct in_addr ia46_addr4;
};
@ -63,8 +63,8 @@ struct in_addr_4in6 {
* some extra padding to accomplish this.
*/
struct in_endpoints {
u_int16_t ie_fport; /* foreign port */
u_int16_t ie_lport; /* local port */
uint16_t ie_fport; /* foreign port */
uint16_t ie_lport; /* local port */
/* protocol dependent part, local and foreign addr */
union {
/* foreign host table entry */
@ -87,9 +87,9 @@ struct in_endpoints {
* references.
*/
struct in_conninfo {
u_int8_t inc_flags;
u_int8_t inc_len;
u_int16_t inc_pad; /* XXX alignment for in_endpoints */
uint8_t inc_flags;
uint8_t inc_len;
uint16_t inc_pad; /* XXX alignment for in_endpoints */
/* protocol dependent part */
struct in_endpoints inc_ie;
};
@ -110,7 +110,7 @@ struct inpcb {
struct inpcbinfo *inp_pcbinfo; /* PCB list info */
struct socket *inp_socket; /* back pointer to socket */
u_int32_t inp_flow;
uint32_t inp_flow;
int inp_flags; /* generic IP/datagram flags */
u_char inp_vflag; /* IP version flag (v4/v6) */
@ -329,7 +329,6 @@ struct inpcbinfo {
#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
/* #ifdef _KERNEL */
extern int ipport_reservedhigh;
extern int ipport_reservedlow;
extern int ipport_lowfirstauto;
@ -370,6 +369,5 @@ void ipport_tick(void *xtp);
*/
void db_print_inpcb(struct inpcb *inp, const char *name, int indent);
/* #endif _KERNEL */
#endif /* !_NETINET_IN_PCB_H_ */

View File

@ -39,7 +39,7 @@
* 2. 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.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -60,16 +60,16 @@
#ifndef _USER_IP6_VAR_H_
#define _USER_IP6_VAR_H_
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
struct ip6_hdr {
union {
struct ip6_hdrctl {
u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */
u_int16_t ip6_un1_plen; /* payload length */
u_int8_t ip6_un1_nxt; /* next header */
u_int8_t ip6_un1_hlim; /* hop limit */
uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
uint16_t ip6_un1_plen; /* payload length */
uint8_t ip6_un1_nxt; /* next header */
uint8_t ip6_un1_hlim; /* hop limit */
} ip6_un1;
u_int8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
} ip6_ctlun;
struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */
@ -84,18 +84,16 @@ struct ip6_hdr {
#define IPV6_VERSION 0x60
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define s6_addr16 u.Word
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(__Userspace_os_Linux)
#if !defined(_WIN32) && !defined(__linux__) && !defined(__EMSCRIPTEN__)
#define s6_addr8 __u6_addr.__u6_addr8
#define s6_addr16 __u6_addr.__u6_addr16
#define s6_addr32 __u6_addr.__u6_addr32
#endif
#endif
#if !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_OpenBSD) && !defined(__Userspace_os_DragonFly)
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
struct route_in6 {
struct rtentry *ro_rt;
struct llentry *ro_lle;

View File

@ -10,7 +10,7 @@
* 2. 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.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -40,8 +40,8 @@
* Internal of an ICMP Router Advertisement
*/
struct icmp_ra_addr {
u_int32_t ira_addr;
u_int32_t ira_preference;
uint32_t ira_addr;
uint32_t ira_preference;
};
/*
@ -53,16 +53,16 @@ struct icmphdr {
u_short icmp_cksum; /* ones complement cksum of struct */
};
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#pragma pack (push, 1)
struct icmp6_hdr {
u_int8_t icmp6_type;
u_int8_t icmp6_code;
u_int16_t icmp6_cksum;
uint8_t icmp6_type;
uint8_t icmp6_code;
uint16_t icmp6_cksum;
union {
u_int32_t icmp6_un_data32[1];
u_int16_t icmp6_un_data16[2];
u_int8_t icmp6_un_data8[4];
uint32_t icmp6_un_data32[1];
uint16_t icmp6_un_data16[2];
uint8_t icmp6_un_data8[4];
} icmp6_dataun;
};
#pragma pack(pop)
@ -98,7 +98,7 @@ struct icmp {
struct ih_rtradv {
u_char irt_num_addrs;
u_char irt_wpa;
u_int16_t irt_lifetime;
uint16_t irt_lifetime;
} ih_rtradv;
} icmp_hun;
#define icmp_pptr icmp_hun.ih_pptr
@ -126,7 +126,7 @@ struct icmp {
/* options and then 64 bits of data */
} id_ip;
struct icmp_ra_addr id_radv;
u_int32_t id_mask;
uint32_t id_mask;
char id_data[1];
} icmp_dun;
#define icmp_otime icmp_dun.id_ts.its_otime

View File

@ -12,7 +12,7 @@
* 2. 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.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -37,7 +37,7 @@
/*__Userspace__*/
#include <stdlib.h>
#include <sys/types.h>
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
#include <strings.h>
#include <stdint.h>
#else
@ -200,67 +200,4 @@ Start copy: Copied code for __Userspace__ */
} \
} while (0);
/* End copy: Copied code for __Userspace__ */
#if 0
#ifdef _KERNEL
#define MALLOC_DEFINE(type, shortdesc, longdesc) \
struct malloc_type type[1] = { \
{ NULL, 0, 0, 0, 0, 0, M_MAGIC, shortdesc, NULL, NULL, \
NULL, 0, NULL, NULL, 0, 0 } \
}; \
SYSINIT(type##_init, SI_SUB_KMEM, SI_ORDER_SECOND, malloc_init, \
type); \
SYSUNINIT(type##_uninit, SI_SUB_KMEM, SI_ORDER_ANY, \
malloc_uninit, type)
#define MALLOC_DECLARE(type) \
extern struct malloc_type type[1]
MALLOC_DECLARE(M_CACHE);
MALLOC_DECLARE(M_DEVBUF);
MALLOC_DECLARE(M_TEMP);
MALLOC_DECLARE(M_IP6OPT); /* for INET6 */
MALLOC_DECLARE(M_IP6NDP); /* for INET6 */
/*
* Deprecated macro versions of not-quite-malloc() and free().
*/
#define MALLOC(space, cast, size, type, flags) \
((space) = (cast)malloc((u_long)(size), (type), (flags)))
#define FREE(addr, type) free((addr), (type))
/*
* XXX this should be declared in <sys/uio.h>, but that tends to fail
* because <sys/uio.h> is included in a header before the source file
* has a chance to include <sys/malloc.h> to get MALLOC_DECLARE() defined.
*/
MALLOC_DECLARE(M_IOV);
extern struct mtx malloc_mtx;
/* XXX struct malloc_type is unused for contig*(). */
void contigfree(void *addr, unsigned long size, struct malloc_type *type);
void *contigmalloc(unsigned long size, struct malloc_type *type, int flags,
vm_paddr_t low, vm_paddr_t high, unsigned long alignment,
unsigned long boundary);
void free(void *addr, struct malloc_type *type);
void *malloc(unsigned long size, struct malloc_type *type, int flags);
void malloc_init(void *);
int malloc_last_fail(void);
void malloc_type_allocated(struct malloc_type *type, unsigned long size);
void malloc_type_freed(struct malloc_type *type, unsigned long size);
void malloc_uninit(void *);
void *realloc(void *addr, unsigned long size, struct malloc_type *type,
int flags);
void *reallocf(void *addr, unsigned long size, struct malloc_type *type,
int flags);
#endif /* _KERNEL */
#endif
#endif /* !_SYS_MALLOC_H_ */

View File

@ -46,7 +46,6 @@
#include "user_atomic.h"
#include "netinet/sctp_pcb.h"
struct mbstat mbstat;
#define KIPC_MAX_LINKHDR 4 /* int: max length of link header (see sys/sysclt.h) */
#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header (see sys/sysclt.h)*/
int max_linkhdr = KIPC_MAX_LINKHDR;
@ -81,8 +80,6 @@ static void mb_dtor_clust(void *, void *);
static int mbuf_constructor_dup(struct mbuf *m, int pkthdr, short type)
{
int flags = pkthdr;
if (type == MT_NOINIT)
return (0);
m->m_next = NULL;
m->m_nextpkt = NULL;
@ -272,9 +269,9 @@ m_clget(struct mbuf *m, int how)
mclust_ret = SCTP_ZONE_GET(zone_clust, char);
#endif
/*mclust_ret = umem_cache_alloc(zone_clust, UMEM_DEFAULT);*/
if (NULL == mclust_ret) {
SCTPDBG(SCTP_DEBUG_USR, "Memory allocation failure in %s\n", __func__);
}
/* if (NULL == mclust_ret) { */
SCTPDBG(SCTP_DEBUG_USR, "Memory allocation failure in %s\n", __func__);
/* } */
}
#if USING_MBUF_CONSTRUCTOR
@ -290,7 +287,7 @@ struct mbuf *
m_getm2(struct mbuf *m, int len, int how, short type, int flags, int allonebuf)
{
struct mbuf *mb, *nm = NULL, *mtail = NULL;
int size = 0, mbuf_threshold, space_needed = len;
int size, mbuf_threshold, space_needed = len;
KASSERT(len >= 0, ("%s: len is < 0", __func__));
@ -473,7 +470,7 @@ m_tag_free(struct m_tag *t)
* XXX probably should be called m_tag_init, but that was already taken.
*/
static __inline void
m_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len)
m_tag_setup(struct m_tag *t, uint32_t cookie, int type, int len)
{
t->m_tag_id = type;
@ -507,7 +504,7 @@ mbuf_initialize(void *dummy)
#else
zone_mbuf = umem_cache_create(MBUF_MEM_NAME, MSIZE, 0,
mb_ctor_mbuf, mb_dtor_mbuf, NULL,
NUULL,
NULL,
NULL, 0);
#endif
/*zone_ext_refcnt = umem_cache_create(MBUF_EXTREFCNT_MEM_NAME, sizeof(u_int), 0,
@ -536,26 +533,6 @@ mbuf_initialize(void *dummy)
*
*/
/*
* [Re]set counters and local statistics knobs.
*
*/
mbstat.m_mbufs = 0;
mbstat.m_mclusts = 0;
mbstat.m_drain = 0;
mbstat.m_msize = MSIZE;
mbstat.m_mclbytes = MCLBYTES;
mbstat.m_minclsize = MINCLSIZE;
mbstat.m_mlen = MLEN;
mbstat.m_mhlen = MHLEN;
mbstat.m_numtypes = MT_NTYPES;
mbstat.m_mcfail = mbstat.m_mpfail = 0;
mbstat.sf_iocnt = 0;
mbstat.sf_allocwait = mbstat.sf_allocfail = 0;
}
@ -598,13 +575,6 @@ mb_ctor_mbuf(void *mem, void *arg, int flgs)
flags = args->flags;
type = args->type;
/*
* The mbuf is initialized later.
*
*/
if (type == MT_NOINIT)
return (0);
m->m_next = NULL;
m->m_nextpkt = NULL;
m->m_len = 0;
@ -909,7 +879,6 @@ m_pullup(struct mbuf *n, int len)
return (m);
bad:
m_freem(n);
mbstat.m_mpfail++; /* XXX: No consistency. */
return (NULL);
}
@ -1045,16 +1014,14 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
* easy cases first.
* we need to use m_copydata() to get data from <n->m_next, 0>.
*/
if ((off == 0 || offp) && M_TRAILINGSPACE(n) >= tlen
&& writable) {
if ((off == 0 || offp) && (M_TRAILINGSPACE(n) >= tlen) && writable) {
m_copydata(n->m_next, 0, tlen, mtod(n, caddr_t) + n->m_len);
n->m_len += tlen;
m_adj(n->m_next, tlen);
goto ok;
}
if ((off == 0 || offp) && M_LEADINGSPACE(n->m_next) >= hlen
&& writable) {
if ((off == 0 || offp) && (M_LEADINGSPACE(n->m_next) >= hlen) && writable) {
n->m_next->m_data -= hlen;
n->m_next->m_len += hlen;
memcpy( mtod(n->m_next, caddr_t), mtod(n, caddr_t) + off,hlen);
@ -1198,13 +1165,10 @@ m_copym(struct mbuf *m, int off0, int len, int wait)
m = m->m_next;
np = &n->m_next;
}
if (top == NULL)
mbstat.m_mcfail++; /* XXX: No consistency. */
return (top);
nospace:
m_freem(top);
mbstat.m_mcfail++; /* XXX: No consistency. */
return (NULL);
}
@ -1266,7 +1230,7 @@ m_tag_copy(struct m_tag *t, int how)
/* Get a packet tag structure along with specified data following. */
struct m_tag *
m_tag_alloc(u_int32_t cookie, int type, int len, int wait)
m_tag_alloc(uint32_t cookie, int type, int len, int wait)
{
struct m_tag *t;

View File

@ -110,7 +110,7 @@ void m_cat(struct mbuf *m, struct mbuf *n);
void m_adj(struct mbuf *, int);
void mb_free_ext(struct mbuf *);
void m_freem(struct mbuf *);
struct m_tag *m_tag_alloc(u_int32_t, int, int, int);
struct m_tag *m_tag_alloc(uint32_t, int, int, int);
struct mbuf *m_copym(struct mbuf *, int, int, int);
void m_copyback(struct mbuf *, int, int, caddr_t);
struct mbuf *m_pullup(struct mbuf *, int);
@ -125,38 +125,6 @@ void m_copydata(const struct mbuf *, int, int, caddr_t);
#define MBUF_CLUSTER_MEM_NAME "mbuf_cluster"
#define MBUF_EXTREFCNT_MEM_NAME "mbuf_ext_refcnt"
#define MT_NOINIT 255 /* Not a type but a flag to allocate
a non-initialized mbuf */
/*
* General mbuf allocator statistics structure.
* __Userspace__ mbstat may be useful for gathering statistics.
* In the kernel many of these statistics are no longer used as
* they track allocator statistics through kernel UMA's built in statistics mechanism.
*/
struct mbstat {
u_long m_mbufs; /* XXX */
u_long m_mclusts; /* XXX */
u_long m_drain; /* times drained protocols for space */
u_long m_mcfail; /* XXX: times m_copym failed */
u_long m_mpfail; /* XXX: times m_pullup failed */
u_long m_msize; /* length of an mbuf */
u_long m_mclbytes; /* length of an mbuf cluster */
u_long m_minclsize; /* min length of data to allocate a cluster */
u_long m_mlen; /* length of data in an mbuf */
u_long m_mhlen; /* length of data in a header mbuf */
/* Number of mbtypes (gives # elems in mbtypes[] array: */
short m_numtypes;
/* XXX: Sendfile stats should eventually move to their own struct */
u_long sf_iocnt; /* times sendfile had to do disk I/O */
u_long sf_allocfail; /* times sfbuf allocation failed */
u_long sf_allocwait; /* times sfbuf allocation had to wait */
};
/*
* Mbufs are of a single size, MSIZE (sys/param.h), which includes overhead.
* An mbuf may add a single "mbuf cluster" of size MCLBYTES (also in
@ -190,9 +158,9 @@ struct m_hdr {
*/
struct m_tag {
SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
u_int16_t m_tag_id; /* Tag ID */
u_int16_t m_tag_len; /* Length of data */
u_int32_t m_tag_cookie; /* ABI/Module ID */
uint16_t m_tag_id; /* Tag ID */
uint16_t m_tag_len; /* Length of data */
uint32_t m_tag_cookie; /* ABI/Module ID */
void (*m_tag_free)(struct m_tag *);
};
@ -207,8 +175,8 @@ struct pkthdr {
/* variables for hardware checksum */
int csum_flags; /* flags regarding checksum */
int csum_data; /* data field used by csum routines */
u_int16_t tso_segsz; /* TSO segment size */
u_int16_t ether_vtag; /* Ethernet 802.1p+q vlan tag */
uint16_t tso_segsz; /* TSO segment size */
uint16_t ether_vtag; /* Ethernet 802.1p+q vlan tag */
SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */
};
@ -322,9 +290,6 @@ struct mbuf {
#define MT_OOBDATA 15 /* expedited data */
#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */
#define MT_NOINIT 255 /* Not a type but a flag to allocate
a non-initialized mbuf */
/*
* __Userspace__ flags like M_NOWAIT are defined in malloc.h
* Flags like these are used in functions like uma_zalloc()
@ -352,9 +317,6 @@ void m_tag_free_default(struct m_tag *);
extern int max_linkhdr; /* Largest link-level header */
extern int max_protohdr; /* Size of largest protocol layer header. See user_mbuf.c */
extern struct mbstat mbstat; /* General mbuf stats/infos */
/*
* Evaluate TRUE if it's safe to write to the mbuf m's data region (this can
* be both the local data payload, or an external buffer area, depending on
@ -373,9 +335,9 @@ extern struct mbstat mbstat; /* General mbuf stats/infos */
* of checking writability of the mbuf data area rests solely with the caller.
*/
#define M_LEADINGSPACE(m) \
((m)->m_flags & M_EXT ? \
(((m)->m_flags & M_EXT) ? \
(M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \
(m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
((m)->m_flags & M_PKTHDR)? (m)->m_data - (m)->m_pktdat : \
(m)->m_data - (m)->m_dat)
/*
@ -385,7 +347,7 @@ extern struct mbstat mbstat; /* General mbuf stats/infos */
* of checking writability of the mbuf data area rests solely with the caller.
*/
#define M_TRAILINGSPACE(m) \
((m)->m_flags & M_EXT ? \
(((m)->m_flags & M_EXT) ? \
(M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \
- ((m)->m_data + (m)->m_len) : 0) : \
&(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
@ -437,4 +399,9 @@ extern struct mbstat mbstat; /* General mbuf stats/infos */
(m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \
} while (0)
#define M_SIZE(m) \
(((m)->m_flags & M_EXT) ? (m)->m_ext.ext_size : \
((m)->m_flags & M_PKTHDR) ? MHLEN : \
MLEN)
#endif

View File

@ -10,7 +10,7 @@
* 2. 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.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -144,8 +144,8 @@ struct name { \
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#if defined (__Userspace_os_Windows)
#if defined (SLIST_ENTRY)
#if defined(_WIN32)
#if defined(SLIST_ENTRY)
#undef SLIST_ENTRY
#endif
#endif

View File

@ -30,12 +30,12 @@
#if defined(INET) || defined(INET6)
#include <sys/types.h>
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <pthread.h>
#if !defined(__Userspace_os_DragonFly) && !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD)
#if !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
#include <sys/uio.h>
#else
#include <user_ip6_var.h>
@ -46,7 +46,7 @@
#include <netinet/sctp_pcb.h>
#include <netinet/sctp_input.h>
#if 0
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#include <linux/netlink.h>
#ifdef HAVE_LINUX_IF_ADDR_H
#include <linux/if_addr.h>
@ -56,23 +56,32 @@
#endif
#endif
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#include <net/route.h>
#if defined(HAVE_NET_ROUTE_H)
# include <net/route.h>
#elif defined(__APPLE__)
/* Apple SDKs for iOS, tvOS, watchOS, etc. don't ship this header */
# define RTM_NEWADDR 0xc
# define RTM_DELADDR 0xd
# define RTAX_IFA 5
# define RTAX_MAX 8
#endif
/* local macros and datatypes used to get IP addresses system independently */
#if !defined(IP_PKTINFO ) && ! defined(IP_RECVDSTADDR)
#if !defined(IP_PKTINFO) && !defined(IP_RECVDSTADDR)
# error "Can't determine socket option to use to get UDP IP"
#endif
void recv_thread_destroy(void);
#define MAXLEN_MBUF_CHAIN 32 /* What should this value be? */
#define MAXLEN_MBUF_CHAIN 128
#define ROUNDUP(a, size) (((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
#define NEXT_SA(ap) ap = (struct sockaddr *) \
((caddr_t) ap + (ap->sa_len ? ROUNDUP(ap->sa_len, sizeof (uint32_t)) : sizeof(uint32_t)))
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
static void
sctp_get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
{
@ -270,7 +279,8 @@ recv_function_raw(void *arg)
int compute_crc = 1;
struct sctp_chunkhdr *ch;
struct sockaddr_in src, dst;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
ssize_t res;
unsigned int ncounter;
struct msghdr msg;
struct iovec recv_iovec[MAXLEN_MBUF_CHAIN];
@ -305,7 +315,7 @@ recv_function_raw(void *arg)
Have tried both sending and receiving
*/
recvmbuf[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA);
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
recv_iovec[i].iov_base = (caddr_t)recvmbuf[i]->m_data;
recv_iovec[i].iov_len = iovlen;
#else
@ -314,7 +324,7 @@ recv_function_raw(void *arg)
#endif
}
to_fill = 0;
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
flags = 0;
ncounter = 0;
fromlen = sizeof(struct sockaddr_in);
@ -337,14 +347,16 @@ recv_function_raw(void *arg)
msg.msg_iovlen = MAXLEN_MBUF_CHAIN;
msg.msg_control = NULL;
msg.msg_controllen = 0;
ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_rawsctp), &msg, 0);
if (n < 0) {
res = recvmsg(SCTP_BASE_VAR(userspace_rawsctp), &msg, 0);
if (res < 0) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
}
}
ncounter = (unsigned int)res;
n = (int)res;
#endif
SCTP_HEADER_LEN(recvmbuf[0]) = n; /* length of total packet */
SCTP_STAT_INCR(sctps_recvpackets);
@ -368,13 +380,20 @@ recv_function_raw(void *arg)
} while (ncounter > 0);
}
offset = sizeof(struct ip) + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);
if (SCTP_BUF_LEN(recvmbuf[0]) < offset) {
if ((recvmbuf[0] = m_pullup(recvmbuf[0], offset)) == NULL) {
SCTP_STAT_INCR(sctps_hdrops);
continue;
}
}
iphdr = mtod(recvmbuf[0], struct ip *);
sh = (struct sctphdr *)((caddr_t)iphdr + sizeof(struct ip));
ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
offset = sizeof(struct ip) + sizeof(struct sctphdr);
offset -= sizeof(struct sctp_chunkhdr);
if (iphdr->ip_tos != 0) {
ecn = iphdr->ip_tos & 0x02;
ecn = iphdr->ip_tos & 0x03;
}
dst.sin_family = AF_INET;
@ -430,7 +449,7 @@ recv_function_raw(void *arg)
}
/* free the array itself */
free(recvmbuf);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP4 rcv", __func__);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP4 rcv\n", __func__);
return (NULL);
}
#endif
@ -440,8 +459,9 @@ static void *
recv_function_raw6(void *arg)
{
struct mbuf **recvmbuf6;
#if !defined(__Userspace_os_Windows)
unsigned int ncounter = 0;
#if !defined(_WIN32)
ssize_t res;
unsigned int ncounter;
struct iovec recv_iovec[MAXLEN_MBUF_CHAIN];
struct msghdr msg;
struct cmsghdr *cmsgptr;
@ -482,7 +502,7 @@ recv_function_raw6(void *arg)
Have tried both sending and receiving
*/
recvmbuf6[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA);
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
recv_iovec[i].iov_base = (caddr_t)recvmbuf6[i]->m_data;
recv_iovec[i].iov_len = iovlen;
#else
@ -491,7 +511,7 @@ recv_function_raw6(void *arg)
#endif
}
to_fill = 0;
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
ncounter = 0;
memset(&from, 0, sizeof(struct sockaddr_in6));
nResult = WSAIoctl(SCTP_BASE_VAR(userspace_rawsctp6), SIO_GET_EXTENSION_FUNCTION_POINTER,
@ -528,15 +548,16 @@ recv_function_raw6(void *arg)
msg.msg_control = (void *)cmsgbuf;
msg.msg_controllen = (socklen_t)CMSG_SPACE(sizeof (struct in6_pktinfo));
msg.msg_flags = 0;
ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg, 0);
if (n < 0) {
res = recvmsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg, 0);
if (res < 0) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
}
}
ncounter = (unsigned int)res;
n = (int)res;
#endif
SCTP_HEADER_LEN(recvmbuf6[0]) = n; /* length of total packet */
SCTP_STAT_INCR(sctps_recvpackets);
@ -576,9 +597,16 @@ recv_function_raw6(void *arg)
continue;
}
offset = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);
if (SCTP_BUF_LEN(recvmbuf6[0]) < offset) {
if ((recvmbuf6[0] = m_pullup(recvmbuf6[0], offset)) == NULL) {
SCTP_STAT_INCR(sctps_hdrops);
continue;
}
}
sh = mtod(recvmbuf6[0], struct sctphdr *);
ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
offset = sizeof(struct sctphdr);
offset -= sizeof(struct sctp_chunkhdr);
dst.sin6_family = AF_INET6;
#ifdef HAVE_SIN6_LEN
@ -591,7 +619,8 @@ recv_function_raw6(void *arg)
src.sin6_len = sizeof(struct sockaddr_in6);
#endif
src.sin6_port = sh->src_port;
if (memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0) {
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
(memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0)) {
compute_crc = 0;
SCTP_STAT_INCR(sctps_recvhwcrc);
} else {
@ -615,7 +644,7 @@ recv_function_raw6(void *arg)
}
/* free the array itself */
free(recvmbuf6);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP6 rcv", __func__);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP6 rcv\n", __func__);
return (NULL);
}
#endif
@ -643,7 +672,8 @@ recv_function_udp(void *arg)
char cmsgbuf[CMSG_SPACE(sizeof(struct in_addr))];
#endif
int compute_crc = 1;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
ssize_t res;
unsigned int ncounter;
struct iovec iov[MAXLEN_MBUF_CHAIN];
struct msghdr msg;
@ -670,7 +700,7 @@ recv_function_udp(void *arg)
Have tried both sending and receiving
*/
udprecvmbuf[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA);
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
iov[i].iov_base = (caddr_t)udprecvmbuf[i]->m_data;
iov[i].iov_len = iovlen;
#else
@ -679,7 +709,7 @@ recv_function_udp(void *arg)
#endif
}
to_fill = 0;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
memset(&msg, 0, sizeof(struct msghdr));
#else
memset(&msg, 0, sizeof(WSAMSG));
@ -688,7 +718,7 @@ recv_function_udp(void *arg)
memset(&dst, 0, sizeof(struct sockaddr_in));
memset(cmsgbuf, 0, sizeof(cmsgbuf));
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
msg.msg_name = (void *)&src;
msg.msg_namelen = sizeof(struct sockaddr_in);
msg.msg_iov = iov;
@ -697,14 +727,16 @@ recv_function_udp(void *arg)
msg.msg_controllen = sizeof(cmsgbuf);
msg.msg_flags = 0;
ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_udpsctp), &msg, 0);
if (n < 0) {
res = recvmsg(SCTP_BASE_VAR(userspace_udpsctp), &msg, 0);
if (res < 0) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
}
}
ncounter = (unsigned int)res;
n = (int)res;
#else
nResult = WSAIoctl(SCTP_BASE_VAR(userspace_udpsctp), SIO_GET_EXTENSION_FUNCTION_POINTER,
&WSARecvMsg_GUID, sizeof WSARecvMsg_GUID,
@ -789,14 +821,22 @@ recv_function_udp(void *arg)
continue;
}
/*offset = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);*/
offset = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);
if (SCTP_BUF_LEN(udprecvmbuf[0]) < offset) {
if ((udprecvmbuf[0] = m_pullup(udprecvmbuf[0], offset)) == NULL) {
SCTP_STAT_INCR(sctps_hdrops);
continue;
}
}
sh = mtod(udprecvmbuf[0], struct sctphdr *);
ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
offset = sizeof(struct sctphdr);
offset -= sizeof(struct sctp_chunkhdr);
port = src.sin_port;
src.sin_port = sh->src_port;
dst.sin_port = sh->dest_port;
if (src.sin_addr.s_addr == dst.sin_addr.s_addr) {
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
(src.sin_addr.s_addr == dst.sin_addr.s_addr)) {
compute_crc = 0;
SCTP_STAT_INCR(sctps_recvhwcrc);
} else {
@ -820,7 +860,7 @@ recv_function_udp(void *arg)
}
/* free the array itself */
free(udprecvmbuf);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP4 rcv", __func__);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP4 rcv\n", __func__);
return (NULL);
}
#endif
@ -844,10 +884,11 @@ recv_function_udp6(void *arg)
struct sctp_chunkhdr *ch;
char cmsgbuf[CMSG_SPACE(sizeof (struct in6_pktinfo))];
int compute_crc = 1;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
struct iovec iov[MAXLEN_MBUF_CHAIN];
struct msghdr msg;
struct cmsghdr *cmsgptr;
ssize_t res;
unsigned int ncounter;
#else
GUID WSARecvMsg_GUID = WSAID_WSARECVMSG;
@ -870,7 +911,7 @@ recv_function_udp6(void *arg)
Have tried both sending and receiving
*/
udprecvmbuf6[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA);
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
iov[i].iov_base = (caddr_t)udprecvmbuf6[i]->m_data;
iov[i].iov_len = iovlen;
#else
@ -880,7 +921,7 @@ recv_function_udp6(void *arg)
}
to_fill = 0;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
memset(&msg, 0, sizeof(struct msghdr));
#else
memset(&msg, 0, sizeof(WSAMSG));
@ -889,7 +930,7 @@ recv_function_udp6(void *arg)
memset(&dst, 0, sizeof(struct sockaddr_in6));
memset(cmsgbuf, 0, CMSG_SPACE(sizeof (struct in6_pktinfo)));
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
msg.msg_name = (void *)&src;
msg.msg_namelen = sizeof(struct sockaddr_in6);
msg.msg_iov = iov;
@ -898,14 +939,16 @@ recv_function_udp6(void *arg)
msg.msg_controllen = (socklen_t)CMSG_SPACE(sizeof (struct in6_pktinfo));
msg.msg_flags = 0;
ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg, 0);
if (n < 0) {
res = recvmsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg, 0);
if (res < 0) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
}
}
ncounter = (unsigned int)res;
n = (int)res;
#else
nResult = WSAIoctl(SCTP_BASE_VAR(userspace_udpsctp6), SIO_GET_EXTENSION_FUNCTION_POINTER,
&WSARecvMsg_GUID, sizeof WSARecvMsg_GUID,
@ -976,14 +1019,22 @@ recv_function_udp6(void *arg)
continue;
}
offset = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);
if (SCTP_BUF_LEN(udprecvmbuf6[0]) < offset) {
if ((udprecvmbuf6[0] = m_pullup(udprecvmbuf6[0], offset)) == NULL) {
SCTP_STAT_INCR(sctps_hdrops);
continue;
}
}
sh = mtod(udprecvmbuf6[0], struct sctphdr *);
ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
offset = sizeof(struct sctphdr);
offset -= sizeof(struct sctp_chunkhdr);
port = src.sin6_port;
src.sin6_port = sh->src_port;
dst.sin6_port = sh->dest_port;
if ((memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0)) {
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
(memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0)) {
compute_crc = 0;
SCTP_STAT_INCR(sctps_recvhwcrc);
} else {
@ -1007,12 +1058,12 @@ recv_function_udp6(void *arg)
}
/* free the array itself */
free(udprecvmbuf6);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP6 rcv", __func__);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP6 rcv\n", __func__);
return (NULL);
}
#endif
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
static void
setReceiveBufferSize(SOCKET sfd, int new_size)
#else
@ -1023,7 +1074,7 @@ setReceiveBufferSize(int sfd, int new_size)
int ch = new_size;
if (setsockopt (sfd, SOL_SOCKET, SO_RCVBUF, (void*)&ch, sizeof(ch)) < 0) {
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set recv-buffers size (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't set recv-buffers size (errno = %d).\n", errno);
@ -1032,7 +1083,7 @@ setReceiveBufferSize(int sfd, int new_size)
return;
}
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
static void
setSendBufferSize(SOCKET sfd, int new_size)
#else
@ -1043,7 +1094,7 @@ setSendBufferSize(int sfd, int new_size)
int ch = new_size;
if (setsockopt (sfd, SOL_SOCKET, SO_SNDBUF, (void*)&ch, sizeof(ch)) < 0) {
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set send-buffers size (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't set send-buffers size (errno = %d).\n", errno);
@ -1066,7 +1117,7 @@ recv_thread_init(void)
#if defined(INET) || defined(INET6)
const int on = 1;
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
struct timeval timeout;
memset(&timeout, 0, sizeof(struct timeval));
@ -1075,7 +1126,7 @@ recv_thread_init(void)
#else
unsigned int timeout = SOCKET_TIMEOUT; /* Timeout in milliseconds */
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
if (SCTP_BASE_VAR(userspace_route) == -1) {
if ((SCTP_BASE_VAR(userspace_route) = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) {
SCTPDBG(SCTP_DEBUG_USR, "Can't create routing socket (errno = %d).\n", errno);
@ -1104,7 +1155,7 @@ recv_thread_init(void)
if (SCTP_BASE_VAR(userspace_route) != -1) {
if (setsockopt(SCTP_BASE_VAR(userspace_route), SOL_SOCKET, SO_RCVTIMEO,(const void*)&timeout, sizeof(struct timeval)) < 0) {
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on routing socket (errno = %d).\n", errno);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_route));
#else
close(SCTP_BASE_VAR(userspace_route));
@ -1117,7 +1168,7 @@ recv_thread_init(void)
#if defined(INET)
if (SCTP_BASE_VAR(userspace_rawsctp) == -1) {
if ((SCTP_BASE_VAR(userspace_rawsctp) = socket(AF_INET, SOCK_RAW, IPPROTO_SCTP)) == -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't create raw socket for IPv4 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't create raw socket for IPv4 (errno = %d).\n", errno);
@ -1125,7 +1176,7 @@ recv_thread_init(void)
} else {
/* complete setting up the raw SCTP socket */
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp), IPPROTO_IP, IP_HDRINCL,(const void*)&hdrincl, sizeof(int)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_HDRINCL (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
#else
@ -1134,7 +1185,7 @@ recv_thread_init(void)
#endif
SCTP_BASE_VAR(userspace_rawsctp) = -1;
} else if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/IPv4 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
#else
@ -1151,7 +1202,7 @@ recv_thread_init(void)
addr_ipv4.sin_port = htons(0);
addr_ipv4.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(SCTP_BASE_VAR(userspace_rawsctp), (const struct sockaddr *)&addr_ipv4, sizeof(struct sockaddr_in)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/IPv4 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
#else
@ -1166,9 +1217,9 @@ recv_thread_init(void)
}
}
}
if (SCTP_BASE_VAR(userspace_udpsctp) == -1) {
if ((SCTP_BASE_VAR(userspace_udpsctp) == -1) && (SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) != 0)) {
if ((SCTP_BASE_VAR(userspace_udpsctp) = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv4 (errno = %d).\n", errno);
@ -1179,7 +1230,7 @@ recv_thread_init(void)
#else
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp), IPPROTO_IP, IP_RECVDSTADDR, (const void *)&on, (int)sizeof(int)) < 0) {
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#if defined(IP_PKTINFO)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_PKTINFO on socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError());
#else
@ -1196,7 +1247,7 @@ recv_thread_init(void)
#endif
SCTP_BASE_VAR(userspace_udpsctp) = -1;
} else if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp));
#else
@ -1213,7 +1264,7 @@ recv_thread_init(void)
addr_ipv4.sin_port = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port));
addr_ipv4.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(SCTP_BASE_VAR(userspace_udpsctp), (const struct sockaddr *)&addr_ipv4, sizeof(struct sockaddr_in)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp));
#else
@ -1232,7 +1283,7 @@ recv_thread_init(void)
#if defined(INET6)
if (SCTP_BASE_VAR(userspace_rawsctp6) == -1) {
if ((SCTP_BASE_VAR(userspace_rawsctp6) = socket(AF_INET6, SOCK_RAW, IPPROTO_SCTP)) == -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/IPv6 (errno = %d).\n", errno);
@ -1241,7 +1292,7 @@ recv_thread_init(void)
/* complete setting up the raw SCTP socket */
#if defined(IPV6_RECVPKTINFO)
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_RECVPKTINFO, (const void *)&on, sizeof(on)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_RECVPKTINFO on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
@ -1252,7 +1303,7 @@ recv_thread_init(void)
} else {
#else
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_PKTINFO,(const void*)&on, sizeof(on)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_PKTINFO on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
@ -1263,14 +1314,14 @@ recv_thread_init(void)
} else {
#endif
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_V6ONLY, (const void*)&on, (socklen_t)sizeof(on)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/IPv6 (errno = %d).\n", errno);
#endif
}
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
@ -1287,7 +1338,7 @@ recv_thread_init(void)
addr_ipv6.sin6_port = htons(0);
addr_ipv6.sin6_addr = in6addr_any;
if (bind(SCTP_BASE_VAR(userspace_rawsctp6), (const struct sockaddr *)&addr_ipv6, sizeof(struct sockaddr_in6)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
@ -1303,9 +1354,9 @@ recv_thread_init(void)
}
}
}
if (SCTP_BASE_VAR(userspace_udpsctp6) == -1) {
if ((SCTP_BASE_VAR(userspace_udpsctp6) == -1) && (SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) != 0)) {
if ((SCTP_BASE_VAR(userspace_udpsctp6) = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv6 (errno = %d).\n", errno);
@ -1313,7 +1364,7 @@ recv_thread_init(void)
}
#if defined(IPV6_RECVPKTINFO)
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_RECVPKTINFO, (const void *)&on, (int)sizeof(int)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_RECVPKTINFO on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
@ -1324,7 +1375,7 @@ recv_thread_init(void)
} else {
#else
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_PKTINFO, (const void *)&on, (int)sizeof(int)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_PKTINFO on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
@ -1335,14 +1386,14 @@ recv_thread_init(void)
} else {
#endif
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, (socklen_t)sizeof(on)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/UDP/IPv6 (errno = %d).\n", errno);
#endif
}
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
@ -1359,7 +1410,7 @@ recv_thread_init(void)
addr_ipv6.sin6_port = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port));
addr_ipv6.sin6_addr = in6addr_any;
if (bind(SCTP_BASE_VAR(userspace_udpsctp6), (const struct sockaddr *)&addr_ipv6, sizeof(struct sockaddr_in6)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
@ -1375,7 +1426,7 @@ recv_thread_init(void)
}
}
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
#if defined(INET) || defined(INET6)
if (SCTP_BASE_VAR(userspace_route) != -1) {
int rc;
@ -1394,7 +1445,7 @@ recv_thread_init(void)
if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadraw), &recv_function_raw))) {
SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/IPv4 recv thread (%d).\n", rc);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
#else
close(SCTP_BASE_VAR(userspace_rawsctp));
@ -1407,7 +1458,7 @@ recv_thread_init(void)
if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadudp), &recv_function_udp))) {
SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/UDP/IPv4 recv thread (%d).\n", rc);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_udpsctp));
#else
close(SCTP_BASE_VAR(userspace_udpsctp));
@ -1422,7 +1473,7 @@ recv_thread_init(void)
if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadraw6), &recv_function_raw6))) {
SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/IPv6 recv thread (%d).\n", rc);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
close(SCTP_BASE_VAR(userspace_rawsctp6));
@ -1435,7 +1486,7 @@ recv_thread_init(void)
if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadudp6), &recv_function_udp6))) {
SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/UDP/IPv6 recv thread (%d).\n", rc);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
close(SCTP_BASE_VAR(userspace_udpsctp6));
@ -1449,42 +1500,63 @@ recv_thread_init(void)
void
recv_thread_destroy(void)
{
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
#if defined(INET) || defined(INET6)
if (SCTP_BASE_VAR(userspace_route) != -1) {
close(SCTP_BASE_VAR(userspace_route));
pthread_join(SCTP_BASE_VAR(recvthreadroute), NULL);
}
#endif
#endif
#if defined(INET)
if (SCTP_BASE_VAR(userspace_rawsctp) != -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
SCTP_BASE_VAR(userspace_rawsctp) = -1;
WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw), INFINITE);
CloseHandle(SCTP_BASE_VAR(recvthreadraw));
#else
close(SCTP_BASE_VAR(userspace_rawsctp));
SCTP_BASE_VAR(userspace_rawsctp) = -1;
pthread_join(SCTP_BASE_VAR(recvthreadraw), NULL);
#endif
}
if (SCTP_BASE_VAR(userspace_udpsctp) != -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_udpsctp));
SCTP_BASE_VAR(userspace_udpsctp) = -1;
WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp), INFINITE);
CloseHandle(SCTP_BASE_VAR(recvthreadudp));
#else
close(SCTP_BASE_VAR(userspace_udpsctp));
SCTP_BASE_VAR(userspace_udpsctp) = -1;
pthread_join(SCTP_BASE_VAR(recvthreadudp), NULL);
#endif
}
#endif
#if defined(INET6)
if (SCTP_BASE_VAR(userspace_rawsctp6) != -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
SCTP_BASE_VAR(userspace_rawsctp6) = -1;
WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw6), INFINITE);
CloseHandle(SCTP_BASE_VAR(recvthreadraw6));
#else
close(SCTP_BASE_VAR(userspace_rawsctp6));
SCTP_BASE_VAR(userspace_rawsctp6) = -1;
pthread_join(SCTP_BASE_VAR(recvthreadraw6), NULL);
#endif
}
if (SCTP_BASE_VAR(userspace_udpsctp6) != -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTP_BASE_VAR(userspace_udpsctp6) = -1;
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp6), INFINITE);
CloseHandle(SCTP_BASE_VAR(recvthreadudp6));
#else
close(SCTP_BASE_VAR(userspace_udpsctp6));
SCTP_BASE_VAR(userspace_udpsctp6) = -1;
pthread_join(SCTP_BASE_VAR(recvthreadudp6), NULL);
#endif
}
#endif

View File

@ -10,7 +10,7 @@
* 2. 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.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*

View File

@ -44,13 +44,13 @@
#ifdef INET6
#include <netinet6/sctp6_var.h>
#endif
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <sys/param.h>
#endif
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#define __FAVOR_BSD /* (on Ubuntu at least) enables UDP header field names like BSD in RFC 768 */
#endif
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
#if defined INET || defined INET6
#include <netinet/udp.h>
#endif
@ -79,7 +79,7 @@ extern int sctp_attach(struct socket *so, int proto, uint32_t vrf_id);
extern int sctpconn_attach(struct socket *so, int proto, uint32_t vrf_id);
static void init_sync(void) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#if defined(INET) || defined(INET6)
WSADATA wsaData;
@ -115,8 +115,8 @@ usrsctp_init(uint16_t port,
void
usrsctp_init_nothreads(uint16_t port,
int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
void (*debug_printf)(const char *format, ...))
int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
void (*debug_printf)(const char *format, ...))
{
init_sync();
sctp_init(port, conn_output, debug_printf, 0);
@ -169,28 +169,17 @@ socantsendmore(struct socket *so)
int
sbwait(struct sockbuf *sb)
{
#if defined(__Userspace__) /* __Userspace__ */
SOCKBUF_LOCK_ASSERT(sb);
sb->sb_flags |= SB_WAIT;
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
if (SleepConditionVariableCS(&(sb->sb_cond), &(sb->sb_mtx), INFINITE))
return 0;
return (0);
else
return -1;
return (-1);
#else
return (pthread_cond_wait(&(sb->sb_cond), &(sb->sb_mtx)));
#endif
#else
SOCKBUF_LOCK_ASSERT(sb);
sb->sb_flags |= SB_WAIT;
return (msleep(&sb->sb_cc, &sb->sb_mtx,
(sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK | PCATCH, "sbwait",
sb->sb_timeo));
#endif
}
@ -394,7 +383,7 @@ void
wakeup(void *ident, struct socket *so)
{
SOCK_LOCK(so);
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
WakeAllConditionVariable(&(so)->timeo_cond);
#else
pthread_cond_broadcast(&(so)->timeo_cond);
@ -420,7 +409,7 @@ wakeup_one(void *ident)
subsidiary sockets.
*/
ACCEPT_LOCK();
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
WakeAllConditionVariable(&accept_cond);
#else
pthread_cond_broadcast(&accept_cond);
@ -568,28 +557,6 @@ sonewconn(struct socket *head, int connstatus)
}
/* From /src/sys/sys/sysproto.h */
struct sctp_generic_sendmsg_args {
int sd;
caddr_t msg;
int mlen;
caddr_t to;
socklen_t tolen; /* was __socklen_t */
struct sctp_sndrcvinfo * sinfo;
int flags;
};
struct sctp_generic_recvmsg_args {
int sd;
struct iovec *iov;
int iovlen;
struct sockaddr *from;
socklen_t *fromlenaddr; /* was __socklen_t */
struct sctp_sndrcvinfo *sinfo;
int *msg_flags;
};
/*
Source: /src/sys/gnu/fs/xfs/FreeBSD/xfs_ioctl.c
*/
@ -774,11 +741,11 @@ userspace_sctp_sendmsg(struct socket *so,
size_t len,
struct sockaddr *to,
socklen_t tolen,
u_int32_t ppid,
u_int32_t flags,
u_int16_t stream_no,
u_int32_t timetolive,
u_int32_t context)
uint32_t ppid,
uint32_t flags,
uint16_t stream_no,
uint32_t timetolive,
uint32_t context)
{
struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo;
struct uio auio;
@ -958,11 +925,11 @@ userspace_sctp_sendmbuf(struct socket *so,
size_t len,
struct sockaddr *to,
socklen_t tolen,
u_int32_t ppid,
u_int32_t flags,
u_int16_t stream_no,
u_int32_t timetolive,
u_int32_t context)
uint32_t ppid,
uint32_t flags,
uint16_t stream_no,
uint32_t timetolive,
uint32_t context)
{
struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo;
@ -1068,7 +1035,7 @@ userspace_sctp_recvmsg(struct socket *so,
if (error) {
if ((auio.uio_resid != ulen) &&
(error == EINTR ||
#if !defined(__Userspace_os_NetBSD)
#if !defined(__NetBSD__)
error == ERESTART ||
#endif
error == EWOULDBLOCK)) {
@ -1161,7 +1128,7 @@ usrsctp_recvv(struct socket *so,
if (errno) {
if ((auio.uio_resid != ulen) &&
(errno == EINTR ||
#if !defined(__Userspace_os_NetBSD)
#if !defined(__NetBSD__)
errno == ERESTART ||
#endif
errno == EWOULDBLOCK)) {
@ -1260,7 +1227,6 @@ out:
#if defined(__Userspace__)
/* Taken from /src/sys/kern/uipc_socket.c
* and modified for __Userspace__
* socreate returns a socket. The socket should be
@ -1331,74 +1297,6 @@ socreate(int dom, struct socket **aso, int type, int proto)
*aso = so;
return (0);
}
#else
/* The kernel version for reference is below. The #else
should be removed once the __Userspace__
version is tested.
* socreate returns a socket with a ref count of 1. The socket should be
* closed with soclose().
*/
int
socreate(int dom, struct socket **aso, int type, int proto,
struct ucred *cred, struct thread *td)
{
struct protosw *prp;
struct socket *so;
int error;
if (proto)
prp = pffindproto(dom, proto, type);
else
prp = pffindtype(dom, type);
if (prp == NULL || prp->pr_usrreqs->pru_attach == NULL ||
prp->pr_usrreqs->pru_attach == pru_attach_notsupp)
return (EPROTONOSUPPORT);
if (jailed(cred) && jail_socket_unixiproute_only &&
prp->pr_domain->dom_family != PF_LOCAL &&
prp->pr_domain->dom_family != PF_INET &&
prp->pr_domain->dom_family != PF_ROUTE) {
return (EPROTONOSUPPORT);
}
if (prp->pr_type != type)
return (EPROTOTYPE);
so = soalloc();
if (so == NULL)
return (ENOBUFS);
TAILQ_INIT(&so->so_incomp);
TAILQ_INIT(&so->so_comp);
so->so_type = type;
so->so_cred = crhold(cred);
so->so_proto = prp;
#ifdef MAC
mac_create_socket(cred, so);
#endif
knlist_init(&so->so_rcv.sb_sel.si_note, SOCKBUF_MTX(&so->so_rcv),
NULL, NULL, NULL);
knlist_init(&so->so_snd.sb_sel.si_note, SOCKBUF_MTX(&so->so_snd),
NULL, NULL, NULL);
so->so_count = 1;
/*
* Auto-sizing of socket buffers is managed by the protocols and
* the appropriate flags must be set in the pru_attach function.
*/
error = (*prp->pr_usrreqs->pru_attach)(so, proto, td);
if (error) {
KASSERT(so->so_count == 1, ("socreate: so_count %d",
so->so_count));
so->so_count = 0;
sodealloc(so);
return (error);
}
*aso = so;
return (0);
}
#endif
/* Taken from /src/sys/kern/uipc_syscalls.c
@ -1426,11 +1324,11 @@ struct socket *
usrsctp_socket(int domain, int type, int protocol,
int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data,
size_t datalen, struct sctp_rcvinfo, int flags, void *ulp_info),
int (*send_cb)(struct socket *sock, uint32_t sb_free),
int (*send_cb)(struct socket *sock, uint32_t sb_free, void *ulp_info),
uint32_t sb_threshold,
void *ulp_info)
{
struct socket *so;
struct socket *so = NULL;
if ((protocol == IPPROTO_SCTP) && (SCTP_BASE_VAR(sctp_pcb_initialized) == 0)) {
errno = EPROTONOSUPPORT;
@ -1493,7 +1391,6 @@ sbreserve(struct sockbuf *sb, u_long cc, struct socket *so)
return (error);
}
#if defined(__Userspace__)
int
soreserve(struct socket *so, u_long sndcc, u_long rcvcc)
{
@ -1523,45 +1420,12 @@ soreserve(struct socket *so, u_long sndcc, u_long rcvcc)
SOCKBUF_UNLOCK(&so->so_snd);
return (ENOBUFS);
}
#else /* kernel version for reference */
int
soreserve(struct socket *so, u_long sndcc, u_long rcvcc)
{
struct thread *td = curthread;
SOCKBUF_LOCK(&so->so_snd);
SOCKBUF_LOCK(&so->so_rcv);
if (sbreserve_locked(&so->so_snd, sndcc, so, td) == 0)
goto bad;
if (sbreserve_locked(&so->so_rcv, rcvcc, so, td) == 0)
goto bad2;
if (so->so_rcv.sb_lowat == 0)
so->so_rcv.sb_lowat = 1;
if (so->so_snd.sb_lowat == 0)
so->so_snd.sb_lowat = MCLBYTES;
if (so->so_snd.sb_lowat > so->so_snd.sb_hiwat)
so->so_snd.sb_lowat = so->so_snd.sb_hiwat;
SOCKBUF_UNLOCK(&so->so_rcv);
SOCKBUF_UNLOCK(&so->so_snd);
return (0);
bad2:
sbrelease_locked(&so->so_snd, so);
bad:
SOCKBUF_UNLOCK(&so->so_rcv);
SOCKBUF_UNLOCK(&so->so_snd);
return (ENOBUFS);
}
#endif
/* Taken from /src/sys/kern/uipc_sockbuf.c
* and modified for __Userspace__
*/
#if defined(__Userspace__)
void
sowakeup(struct socket *so, struct sockbuf *sb)
{
@ -1571,7 +1435,7 @@ sowakeup(struct socket *so, struct sockbuf *sb)
sb->sb_flags &= ~SB_SEL;
if (sb->sb_flags & SB_WAIT) {
sb->sb_flags &= ~SB_WAIT;
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
WakeAllConditionVariable(&(sb)->sb_cond);
#else
pthread_cond_broadcast(&(sb)->sb_cond);
@ -1579,43 +1443,6 @@ sowakeup(struct socket *so, struct sockbuf *sb)
}
SOCKBUF_UNLOCK(sb);
}
#else /* kernel version for reference */
/*
* Wakeup processes waiting on a socket buffer. Do asynchronous notification
* via SIGIO if the socket has the SS_ASYNC flag set.
*
* Called with the socket buffer lock held; will release the lock by the end
* of the function. This allows the caller to acquire the socket buffer lock
* while testing for the need for various sorts of wakeup and hold it through
* to the point where it's no longer required. We currently hold the lock
* through calls out to other subsystems (with the exception of kqueue), and
* then release it to avoid lock order issues. It's not clear that's
* correct.
*/
void
sowakeup(struct socket *so, struct sockbuf *sb)
{
SOCKBUF_LOCK_ASSERT(sb);
selwakeuppri(&sb->sb_sel, PSOCK);
sb->sb_flags &= ~SB_SEL;
if (sb->sb_flags & SB_WAIT) {
sb->sb_flags &= ~SB_WAIT;
wakeup(&sb->sb_cc);
}
KNOTE_LOCKED(&sb->sb_sel.si_note, 0);
SOCKBUF_UNLOCK(sb);
if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL)
pgsigio(&so->so_sigio, SIGIO, 0);
if (sb->sb_flags & SB_UPCALL)
(*so->so_upcall)(so, so->so_upcallarg, M_NOWAIT);
if (sb->sb_flags & SB_AIO)
aio_swake(so, sb);
mtx_assert(SOCKBUF_MTX(sb), MA_NOTOWNED);
}
#endif
/* Taken from /src/sys/kern/uipc_socket.c
@ -1787,7 +1614,7 @@ user_accept(struct socket *head, struct sockaddr **name, socklen_t *namelen, st
head->so_error = ECONNABORTED;
break;
}
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
if (SleepConditionVariableCS(&accept_cond, &accept_mtx, INFINITE))
error = 0;
else
@ -2051,7 +1878,7 @@ soconnect(struct socket *so, struct sockaddr *nam)
* Otherwise, if connected, try to disconnect first. This allows
* user to disconnect by connecting to, e.g., a null address.
*/
if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) && (error = sodisconnect(so))) {
if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) && (sodisconnect(so) != 0)) {
error = EISCONN;
} else {
/*
@ -2108,7 +1935,7 @@ int user_connect(struct socket *so, struct sockaddr *sa)
SOCK_LOCK(so);
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
if (SleepConditionVariableCS(SOCK_COND(so), SOCK_MTX(so), INFINITE))
error = 0;
else
@ -2117,7 +1944,7 @@ int user_connect(struct socket *so, struct sockaddr *sa)
error = pthread_cond_wait(SOCK_COND(so), SOCK_MTX(so));
#endif
if (error) {
#if defined(__Userspace_os_NetBSD)
#if defined(__NetBSD__)
if (error == EINTR) {
#else
if (error == EINTR || error == ERESTART) {
@ -2137,7 +1964,7 @@ bad:
if (!interrupted) {
so->so_state &= ~SS_ISCONNECTING;
}
#if !defined(__Userspace_os_NetBSD)
#if !defined(__NetBSD__)
if (error == ERESTART) {
error = EINTR;
}
@ -2247,7 +2074,7 @@ usrsctp_finish(void)
return (-1);
}
sctp_finish();
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
DeleteConditionVariable(&accept_cond);
DeleteCriticalSection(&accept_mtx);
#if defined(INET) || defined(INET6)
@ -2383,7 +2210,7 @@ usrsctp_getsockopt(struct socket *so, int level, int option_name,
int *buf_size;
buf_size = (int *)option_value;
*buf_size = so->so_rcv.sb_hiwat;;
*buf_size = so->so_rcv.sb_hiwat;
*option_len = (socklen_t)sizeof(int);
return (0);
}
@ -2583,10 +2410,16 @@ usrsctp_set_ulpinfo(struct socket *so, void *ulp_info)
return (register_ulp_info(so, ulp_info));
}
int
usrsctp_get_ulpinfo(struct socket *so, void **pulp_info)
{
return (retrieve_ulp_info(so, pulp_info));
}
int
usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
{
struct sctp_getaddresses *gaddrs;
struct sockaddr *sa;
#ifdef INET
struct sockaddr_in *sin;
@ -2595,9 +2428,9 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
struct sockaddr_in6 *sin6;
#endif
int i;
size_t argsz;
#if defined(INET) || defined(INET6)
uint16_t sport = 0;
uint16_t sport;
bool fix_port;
#endif
/* validate the flags */
@ -2611,6 +2444,10 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
errno = EINVAL;
return (-1);
}
#if defined(INET) || defined(INET6)
sport = 0;
fix_port = false;
#endif
/* First pre-screen the addresses */
sa = addrs;
for (i = 0; i < addrcnt; i++) {
@ -2635,6 +2472,7 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
} else {
/* save off the port */
sport = sin->sin_port;
fix_port = (i > 0);
}
}
#ifndef HAVE_SA_LEN
@ -2662,6 +2500,7 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
} else {
/* save off the port */
sport = sin6->sin6_port;
fix_port = (i > 0);
}
}
#ifndef HAVE_SA_LEN
@ -2678,41 +2517,30 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
#endif
}
argsz = sizeof(struct sctp_getaddresses) +
sizeof(struct sockaddr_storage);
if ((gaddrs = (struct sctp_getaddresses *)malloc(argsz)) == NULL) {
errno = ENOMEM;
return (-1);
}
sa = addrs;
for (i = 0; i < addrcnt; i++) {
#ifndef HAVE_SA_LEN
size_t sa_len;
#endif
memset(gaddrs, 0, argsz);
gaddrs->sget_assoc_id = 0;
#ifdef HAVE_SA_LEN
memcpy(gaddrs->addr, sa, sa->sa_len);
#if defined(INET) || defined(INET6)
if ((i == 0) && (sport != 0)) {
switch (gaddrs->addr->sa_family) {
if (fix_port) {
switch (sa->sa_family) {
#ifdef INET
case AF_INET:
sin = (struct sockaddr_in *)gaddrs->addr;
sin->sin_port = sport;
((struct sockaddr_in *)sa)->sin_port = sport;
break;
#endif
#ifdef INET6
case AF_INET6:
sin6 = (struct sockaddr_in6 *)gaddrs->addr;
sin6->sin6_port = sport;
((struct sockaddr_in6 *)sa)->sin6_port = sport;
break;
#endif
}
}
#endif
if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, gaddrs, (socklen_t)argsz) != 0) {
free(gaddrs);
if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, sa, sa->sa_len) != 0) {
return (-1);
}
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
@ -2732,38 +2560,33 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
sa_len = 0;
break;
}
memcpy(gaddrs->addr, sa, sa_len);
/*
* Now, if there was a port mentioned, assure that the
* first address has that port to make sure it fails or
* succeeds correctly.
*/
#if defined(INET) || defined(INET6)
if ((i == 0) && (sport != 0)) {
switch (gaddrs->addr->sa_family) {
if (fix_port) {
switch (sa->sa_family) {
#ifdef INET
case AF_INET:
sin = (struct sockaddr_in *)gaddrs->addr;
sin->sin_port = sport;
((struct sockaddr_in *)sa)->sin_port = sport;
break;
#endif
#ifdef INET6
case AF_INET6:
sin6 = (struct sockaddr_in6 *)gaddrs->addr;
sin6->sin6_port = sport;
((struct sockaddr_in6 *)sa)->sin6_port = sport;
break;
#endif
}
}
#endif
if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, gaddrs, (socklen_t)argsz) != 0) {
free(gaddrs);
if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, sa, (socklen_t)sa_len) != 0) {
return (-1);
}
sa = (struct sockaddr *)((caddr_t)sa + sa_len);
#endif
}
free(gaddrs);
return (0);
}
@ -2899,9 +2722,9 @@ usrsctp_getpaddrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs)
free(addrs);
return (-1);
}
*raddrs = (struct sockaddr *)&addrs->addr[0];
*raddrs = &addrs->addr[0].sa;
cnt = 0;
sa = (struct sockaddr *)&addrs->addr[0];
sa = &addrs->addr[0].sa;
lim = (caddr_t)addrs + opt_len;
#ifdef HAVE_SA_LEN
while (((caddr_t)sa < lim) && (sa->sa_len > 0)) {
@ -2938,7 +2761,7 @@ usrsctp_freepaddrs(struct sockaddr *addrs)
/* Take away the hidden association id */
void *fr_addr;
fr_addr = (void *)((caddr_t)addrs - sizeof(sctp_assoc_t));
fr_addr = (void *)((caddr_t)addrs - offsetof(struct sctp_getaddresses, addr));
/* Now free it */
free(fr_addr);
}
@ -2967,9 +2790,7 @@ usrsctp_getladdrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs)
errno = ENOTCONN;
return (-1);
}
opt_len = (socklen_t)(size_of_addresses +
sizeof(struct sockaddr_storage) +
sizeof(struct sctp_getaddresses));
opt_len = (socklen_t)(size_of_addresses + sizeof(struct sctp_getaddresses));
addrs = calloc(1, (size_t)opt_len);
if (addrs == NULL) {
errno = ENOMEM;
@ -2982,9 +2803,9 @@ usrsctp_getladdrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs)
errno = ENOMEM;
return (-1);
}
*raddrs = (struct sockaddr *)&addrs->addr[0];
*raddrs = &addrs->addr[0].sa;
cnt = 0;
sa = (struct sockaddr *)&addrs->addr[0];
sa = &addrs->addr[0].sa;
lim = (caddr_t)addrs + opt_len;
#ifdef HAVE_SA_LEN
while (((caddr_t)sa < lim) && (sa->sa_len > 0)) {
@ -3021,7 +2842,7 @@ usrsctp_freeladdrs(struct sockaddr *addrs)
/* Take away the hidden association id */
void *fr_addr;
fr_addr = (void *)((caddr_t)addrs - sizeof(sctp_assoc_t));
fr_addr = (void *)((caddr_t)addrs - offsetof(struct sctp_getaddresses, addr));
/* Now free it */
free(fr_addr);
}
@ -3035,16 +2856,11 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
struct mbuf *m;
struct mbuf *m_orig;
int iovcnt;
int send_len;
int len;
int send_count;
struct ip *ip;
struct udphdr *udp;
#if !defined (__Userspace_os_Windows)
int res;
#endif
struct sockaddr_in dst;
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
WSAMSG win_msg_hdr;
DWORD win_sent_len;
WSABUF send_iovec[MAXLEN_MBUF_CHAIN];
@ -3090,7 +2906,7 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
SCTP_PRINTF("Why did the SCTP implementation did not choose a source address?\n");
}
/* TODO need to worry about ro->ro_dst as in ip_output? */
#if defined(__Userspace_os_Linux) || defined (__Userspace_os_Windows) || (defined(__Userspace_os_FreeBSD) && (__FreeBSD_version >= 1100030))
#if defined(__linux__) || defined(_WIN32) || (defined(__FreeBSD__) && (__FreeBSD_version >= 1100030))
/* need to put certain fields into network order for Linux */
ip->ip_len = htons(ip->ip_len);
#endif
@ -3113,17 +2929,13 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
m_adj(m, sizeof(struct ip) + sizeof(struct udphdr));
}
send_len = SCTP_HEADER_LEN(m); /* length of entire packet */
send_count = 0;
for (iovcnt = 0; m != NULL && iovcnt < MAXLEN_MBUF_CHAIN; m = m->m_next, iovcnt++) {
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
send_iovec[iovcnt].iov_base = (caddr_t)m->m_data;
send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m);
send_count += send_iovec[iovcnt].iov_len;
#else
send_iovec[iovcnt].buf = (caddr_t)m->m_data;
send_iovec[iovcnt].len = SCTP_BUF_LEN(m);
send_count += send_iovec[iovcnt].len;
#endif
}
@ -3132,7 +2944,7 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
goto free_mbuf;
}
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
msg_hdr.msg_name = (struct sockaddr *) &dst;
msg_hdr.msg_namelen = sizeof(struct sockaddr_in);
msg_hdr.msg_iov = send_iovec;
@ -3142,12 +2954,12 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
msg_hdr.msg_flags = 0;
if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) {
if ((res = sendmsg(SCTP_BASE_VAR(userspace_rawsctp), &msg_hdr, MSG_DONTWAIT)) != send_len) {
if (sendmsg(SCTP_BASE_VAR(userspace_rawsctp), &msg_hdr, MSG_DONTWAIT) < 0) {
*result = errno;
}
}
if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) {
if ((res = sendmsg(SCTP_BASE_VAR(userspace_udpsctp), &msg_hdr, MSG_DONTWAIT)) != send_len) {
if (sendmsg(SCTP_BASE_VAR(userspace_udpsctp), &msg_hdr, MSG_DONTWAIT) < 0) {
*result = errno;
}
}
@ -3164,15 +2976,11 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) {
if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) {
*result = WSAGetLastError();
} else if ((int)win_sent_len != send_len) {
*result = WSAGetLastError();
}
}
if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) {
if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) {
*result = WSAGetLastError();
} else if ((int)win_sent_len != send_len) {
*result = WSAGetLastError();
}
}
#endif
@ -3181,7 +2989,7 @@ free_mbuf:
}
#endif
#if defined (INET6)
#if defined(INET6)
void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
struct route_in6 *ro, void *stcb,
uint32_t vrf_id)
@ -3189,16 +2997,11 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
struct mbuf *m;
struct mbuf *m_orig;
int iovcnt;
int send_len;
int len;
int send_count;
struct ip6_hdr *ip6;
struct udphdr *udp;
#if !defined (__Userspace_os_Windows)
int res;
#endif
struct sockaddr_in6 dst;
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
WSAMSG win_msg_hdr;
DWORD win_sent_len;
WSABUF send_iovec[MAXLEN_MBUF_CHAIN];
@ -3265,20 +3068,16 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
if (use_udp_tunneling) {
m_adj(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr));
} else {
m_adj(m, sizeof(struct ip6_hdr));
m_adj(m, sizeof(struct ip6_hdr));
}
send_len = SCTP_HEADER_LEN(m); /* length of entire packet */
send_count = 0;
for (iovcnt = 0; m != NULL && iovcnt < MAXLEN_MBUF_CHAIN; m = m->m_next, iovcnt++) {
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
send_iovec[iovcnt].iov_base = (caddr_t)m->m_data;
send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m);
send_count += send_iovec[iovcnt].iov_len;
#else
send_iovec[iovcnt].buf = (caddr_t)m->m_data;
send_iovec[iovcnt].len = SCTP_BUF_LEN(m);
send_count += send_iovec[iovcnt].len;
#endif
}
if (m != NULL) {
@ -3286,7 +3085,7 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
goto free_mbuf;
}
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
msg_hdr.msg_name = (struct sockaddr *) &dst;
msg_hdr.msg_namelen = sizeof(struct sockaddr_in6);
msg_hdr.msg_iov = send_iovec;
@ -3296,12 +3095,12 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
msg_hdr.msg_flags = 0;
if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) {
if ((res = sendmsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg_hdr, MSG_DONTWAIT)) != send_len) {
if (sendmsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg_hdr, MSG_DONTWAIT)< 0) {
*result = errno;
}
}
if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) {
if ((res = sendmsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg_hdr, MSG_DONTWAIT)) != send_len) {
if (sendmsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg_hdr, MSG_DONTWAIT) < 0) {
*result = errno;
}
}
@ -3318,15 +3117,11 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) {
if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) {
*result = WSAGetLastError();
} else if ((int)win_sent_len != send_len) {
*result = WSAGetLastError();
}
}
if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) {
if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) {
*result = WSAGetLastError();
} else if ((int)win_sent_len != send_len) {
*result = WSAGetLastError();
}
}
#endif
@ -3405,21 +3200,30 @@ usrsctp_dumppacket(const void *buf, size_t len, int outbound)
ftime(&tb);
localtime_s(&t, &tb.time);
#if defined(__MINGW32__)
snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT,
outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm));
if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT,
outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) {
free(dump_buf);
return (NULL);
}
#else
_snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT,
outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm));
if (_snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT,
outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) {
free(dump_buf);
return (NULL);
}
#endif
#else
gettimeofday(&tv, NULL);
sec = (time_t)tv.tv_sec;
localtime_r((const time_t *)&sec, &t);
snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT,
outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)tv.tv_usec);
if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT,
outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)tv.tv_usec) < 0) {
free(dump_buf);
return (NULL);
}
#endif
pos += PREAMBLE_LENGTH;
#if defined(_WIN32) && !defined(__MINGW32__)
@ -3482,9 +3286,10 @@ void
usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bits)
{
struct sockaddr_conn src, dst;
struct mbuf *m;
struct mbuf *m, *mm;
struct sctphdr *sh;
struct sctp_chunkhdr *ch;
int remaining, offset;
SCTP_STAT_INCR(sctps_recvpackets);
SCTP_STAT_INCR_COUNTER64(sctps_inpackets);
@ -3503,18 +3308,30 @@ usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bit
if ((m = sctp_get_mbuf_for_msg((unsigned int)length, 1, M_NOWAIT, 0, MT_DATA)) == NULL) {
return;
}
/* Set the lengths fields of the mbuf chain.
* This is expected by m_copyback().
*/
remaining = (int)length;
for (mm = m; mm != NULL; mm = mm->m_next) {
mm->m_len = min((int)M_SIZE(mm), remaining);
m->m_pkthdr.len += mm->m_len;
remaining -= mm->m_len;
}
KASSERT(remaining == 0, ("usrsctp_conninput: %zu bytes left", remaining));
m_copyback(m, 0, (int)length, (caddr_t)buffer);
if (SCTP_BUF_LEN(m) < (int)(sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr))) {
if ((m = m_pullup(m, sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr))) == NULL) {
offset = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);
if (SCTP_BUF_LEN(m) < offset) {
if ((m = m_pullup(m, offset)) == NULL) {
SCTP_STAT_INCR(sctps_hdrops);
return;
}
}
sh = mtod(m, struct sctphdr *);;
sh = mtod(m, struct sctphdr *);
ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
offset -= sizeof(struct sctp_chunkhdr);
src.sconn_port = sh->src_port;
dst.sconn_port = sh->dest_port;
sctp_common_input_processing(&m, 0, sizeof(struct sctphdr), (int)length,
sctp_common_input_processing(&m, 0, offset, (int)length,
(struct sockaddr *)&src,
(struct sockaddr *)&dst,
sh, ch,
@ -3527,9 +3344,9 @@ usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bit
return;
}
void usrsctp_handle_timers(uint32_t delta)
void usrsctp_handle_timers(uint32_t elapsed_milliseconds)
{
sctp_handle_tick(delta);
sctp_handle_tick(sctp_msecs_to_ticks(elapsed_milliseconds));
}
int

View File

@ -10,7 +10,7 @@
* 2. 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.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -33,7 +33,7 @@
#ifndef _USER_SOCKETVAR_H_
#define _USER_SOCKETVAR_H_
#if defined(__Userspace_os_Darwin)
#if defined(__APPLE__)
#include <sys/types.h>
#include <unistd.h>
#endif
@ -42,7 +42,7 @@
/* #include <sys/_lock.h> was 0 byte file */
/* #include <sys/_mutex.h> was 0 byte file */
/* #include <sys/_sx.h> */ /*__Userspace__ alternative?*/
#if !defined(__Userspace_os_DragonFly) && !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl)
#if !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(_WIN32) && !defined(__native_client__)
#include <sys/uio.h>
#endif
#define SOCK_MAXADDRLEN 255
@ -54,16 +54,16 @@
#define SS_CANTRCVMORE 0x020
#define SS_CANTSENDMORE 0x010
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined (__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(_WIN32) || defined(__native_client__)
#define UIO_MAXIOV 1024
#define ERESTART (-1)
#endif
#if !defined(__Userspace_os_Darwin) && !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_OpenBSD)
#if !defined(__APPLE__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
enum uio_rw { UIO_READ, UIO_WRITE };
#endif
#if !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_OpenBSD)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
/* Segment flag values. */
enum uio_seg {
UIO_USERSPACE, /* from user data space */
@ -100,7 +100,7 @@ struct uio {
* handle on protocol and pointer to protocol
* private data and error information.
*/
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
#define AF_ROUTE 17
#if !defined(__MINGW32__)
typedef __int32 pid_t;
@ -237,7 +237,7 @@ struct socket {
* avoid defining a lock order between listen and accept sockets
* until such time as it proves to be a good idea.
*/
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
extern userland_mutex_t accept_mtx;
extern userland_cond_t accept_cond;
#define ACCEPT_LOCK_ASSERT()
@ -272,7 +272,7 @@ extern userland_cond_t accept_cond;
* buffer.
*/
#define SOCKBUF_MTX(_sb) (&(_sb)->sb_mtx)
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
#define SOCKBUF_LOCK_INIT(_sb, _name) \
InitializeCriticalSection(SOCKBUF_MTX(_sb))
#define SOCKBUF_LOCK_DESTROY(_sb) DeleteCriticalSection(SOCKBUF_MTX(_sb))
@ -373,340 +373,6 @@ extern userland_cond_t accept_cond;
#define SCTP_EVENT_WRITE 0x0002 /* socket is writeable */
#define SCTP_EVENT_ERROR 0x0004 /* socket has an error state */
/*
* Externalized form of struct socket used by the sysctl(3) interface.
*/
struct xsocket {
size_t xso_len; /* length of this structure */
struct socket *xso_so; /* makes a convenient handle sometimes */
short so_type;
short so_options;
short so_linger;
short so_state;
caddr_t so_pcb; /* another convenient handle */
int xso_protocol;
int xso_family;
u_short so_qlen;
u_short so_incqlen;
u_short so_qlimit;
short so_timeo;
u_short so_error;
pid_t so_pgid;
u_long so_oobmark;
struct xsockbuf {
u_int sb_cc;
u_int sb_hiwat;
u_int sb_mbcnt;
u_int sb_mbmax;
int sb_lowat;
int sb_timeo;
short sb_flags;
} so_rcv, so_snd;
uid_t so_uid; /* XXX */
};
#if defined(_KERNEL)
/*
* Macros for sockets and socket buffering.
*/
/*
* Do we need to notify the other side when I/O is possible?
*/
#define sb_notify(sb) (((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \
SB_UPCALL | SB_AIO | SB_KNOTE)) != 0)
/*
* How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
* This is problematical if the fields are unsigned, as the space might
* still be negative (cc > hiwat or mbcnt > mbmax). Should detect
* overflow and return 0. Should use "lmin" but it doesn't exist now.
*/
#define sbspace(sb) \
((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
(int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
/* do we have to send all at once on a socket? */
#define sosendallatonce(so) \
((so)->so_proto->pr_flags & PR_ATOMIC)
/* can we read something from so? */
#define soreadable(so) \
((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
((so)->so_rcv.sb_state & SBS_CANTRCVMORE) || \
!TAILQ_EMPTY(&(so)->so_comp) || (so)->so_error)
/* can we write something to so? */
#define sowriteable(so) \
((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
(((so)->so_state&SS_ISCONNECTED) || \
((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
((so)->so_snd.sb_state & SBS_CANTSENDMORE) || \
(so)->so_error)
/* adjust counters in sb reflecting allocation of m */
#define sballoc(sb, m) { \
(sb)->sb_cc += (m)->m_len; \
if ((m)->m_type != MT_DATA && (m)->m_type != MT_OOBDATA) \
(sb)->sb_ctl += (m)->m_len; \
(sb)->sb_mbcnt += MSIZE; \
if ((m)->m_flags & M_EXT) \
(sb)->sb_mbcnt += (m)->m_ext.ext_size; \
}
/* adjust counters in sb reflecting freeing of m */
#define sbfree(sb, m) { \
(sb)->sb_cc -= (m)->m_len; \
if ((m)->m_type != MT_DATA && (m)->m_type != MT_OOBDATA) \
(sb)->sb_ctl -= (m)->m_len; \
(sb)->sb_mbcnt -= MSIZE; \
if ((m)->m_flags & M_EXT) \
(sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
if ((sb)->sb_sndptr == (m)) { \
(sb)->sb_sndptr = NULL; \
(sb)->sb_sndptroff = 0; \
} \
if ((sb)->sb_sndptroff != 0) \
(sb)->sb_sndptroff -= (m)->m_len; \
}
/*
* soref()/sorele() ref-count the socket structure. Note that you must
* still explicitly close the socket, but the last ref count will free
* the structure.
*/
#define soref(so) do { \
SOCK_LOCK_ASSERT(so); \
++(so)->so_count; \
} while (0)
#define sorele(so) do { \
ACCEPT_LOCK_ASSERT(); \
SOCK_LOCK_ASSERT(so); \
KASSERT((so)->so_count > 0, ("sorele")); \
if (--(so)->so_count == 0) \
sofree(so); \
else { \
SOCK_UNLOCK(so); \
ACCEPT_UNLOCK(); \
} \
} while (0)
#define sotryfree(so) do { \
ACCEPT_LOCK_ASSERT(); \
SOCK_LOCK_ASSERT(so); \
if ((so)->so_count == 0) \
sofree(so); \
else { \
SOCK_UNLOCK(so); \
ACCEPT_UNLOCK(); \
} \
} while(0)
/*
* In sorwakeup() and sowwakeup(), acquire the socket buffer lock to
* avoid a non-atomic test-and-wakeup. However, sowakeup is
* responsible for releasing the lock if it is called. We unlock only
* if we don't call into sowakeup. If any code is introduced that
* directly invokes the underlying sowakeup() primitives, it must
* maintain the same semantics.
*/
#define sorwakeup_locked(so) do { \
SOCKBUF_LOCK_ASSERT(&(so)->so_rcv); \
if (sb_notify(&(so)->so_rcv)) \
sowakeup((so), &(so)->so_rcv); \
else \
SOCKBUF_UNLOCK(&(so)->so_rcv); \
} while (0)
#define sorwakeup(so) do { \
SOCKBUF_LOCK(&(so)->so_rcv); \
sorwakeup_locked(so); \
} while (0)
#define sowwakeup_locked(so) do { \
SOCKBUF_LOCK_ASSERT(&(so)->so_snd); \
if (sb_notify(&(so)->so_snd)) \
sowakeup((so), &(so)->so_snd); \
else \
SOCKBUF_UNLOCK(&(so)->so_snd); \
} while (0)
#define sowwakeup(so) do { \
SOCKBUF_LOCK(&(so)->so_snd); \
sowwakeup_locked(so); \
} while (0)
/*
* Argument structure for sosetopt et seq. This is in the KERNEL
* section because it will never be visible to user code.
*/
enum sopt_dir { SOPT_GET, SOPT_SET };
struct sockopt {
enum sopt_dir sopt_dir; /* is this a get or a set? */
int sopt_level; /* second arg of [gs]etsockopt */
int sopt_name; /* third arg of [gs]etsockopt */
void *sopt_val; /* fourth arg of [gs]etsockopt */
size_t sopt_valsize; /* (almost) fifth arg of [gs]etsockopt */
struct thread *sopt_td; /* calling thread or null if kernel */
};
struct accept_filter {
char accf_name[16];
void (*accf_callback)
(struct socket *so, void *arg, int waitflag);
void * (*accf_create)
(struct socket *so, char *arg);
void (*accf_destroy)
(struct socket *so);
SLIST_ENTRY(accept_filter) accf_next;
};
extern int maxsockets;
extern u_long sb_max;
extern struct uma_zone *socket_zone;
extern so_gen_t so_gencnt;
struct mbuf;
struct sockaddr;
struct ucred;
struct uio;
/*
* From uipc_socket and friends
*/
int do_getopt_accept_filter(struct socket *so, struct sockopt *sopt);
int do_setopt_accept_filter(struct socket *so, struct sockopt *sopt);
int so_setsockopt(struct socket *so, int level, int optname,
void *optval, size_t optlen);
int sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type);
int getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len);
void sbappend(struct sockbuf *sb, struct mbuf *m);
void sbappend_locked(struct sockbuf *sb, struct mbuf *m);
void sbappendstream(struct sockbuf *sb, struct mbuf *m);
void sbappendstream_locked(struct sockbuf *sb, struct mbuf *m);
int sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa,
struct mbuf *m0, struct mbuf *control);
int sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa,
struct mbuf *m0, struct mbuf *control);
int sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
struct mbuf *control);
int sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0,
struct mbuf *control);
void sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
void sbappendrecord_locked(struct sockbuf *sb, struct mbuf *m0);
void sbcheck(struct sockbuf *sb);
void sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
struct mbuf *
sbcreatecontrol(caddr_t p, int size, int type, int level);
void sbdestroy(struct sockbuf *sb, struct socket *so);
void sbdrop(struct sockbuf *sb, int len);
void sbdrop_locked(struct sockbuf *sb, int len);
void sbdroprecord(struct sockbuf *sb);
void sbdroprecord_locked(struct sockbuf *sb);
void sbflush(struct sockbuf *sb);
void sbflush_locked(struct sockbuf *sb);
void sbrelease(struct sockbuf *sb, struct socket *so);
void sbrelease_locked(struct sockbuf *sb, struct socket *so);
int sbreserve(struct sockbuf *sb, u_long cc, struct socket *so,
struct thread *td);
int sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so,
struct thread *td);
struct mbuf *
sbsndptr(struct sockbuf *sb, u_int off, u_int len, u_int *moff);
void sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb);
int sbwait(struct sockbuf *sb);
int sblock(struct sockbuf *sb, int flags);
void sbunlock(struct sockbuf *sb);
void soabort(struct socket *so);
int soaccept(struct socket *so, struct sockaddr **nam);
int socheckuid(struct socket *so, uid_t uid);
int sobind(struct socket *so, struct sockaddr *nam, struct thread *td);
void socantrcvmore(struct socket *so);
void socantrcvmore_locked(struct socket *so);
void socantsendmore(struct socket *so);
void socantsendmore_locked(struct socket *so);
int soclose(struct socket *so);
int soconnect(struct socket *so, struct sockaddr *nam, struct thread *td);
int soconnect2(struct socket *so1, struct socket *so2);
int socow_setup(struct mbuf *m0, struct uio *uio);
int socreate(int dom, struct socket **aso, int type, int proto,
struct ucred *cred, struct thread *td);
int sodisconnect(struct socket *so);
struct sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
void sofree(struct socket *so);
int sogetopt(struct socket *so, struct sockopt *sopt);
void sohasoutofband(struct socket *so);
void soisconnected(struct socket *so);
void soisconnecting(struct socket *so);
void soisdisconnected(struct socket *so);
void soisdisconnecting(struct socket *so);
int solisten(struct socket *so, int backlog, struct thread *td);
void solisten_proto(struct socket *so, int backlog);
int solisten_proto_check(struct socket *so);
struct socket *
sonewconn(struct socket *head, int connstatus);
int sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen);
int sooptcopyout(struct sockopt *sopt, const void *buf, size_t len);
/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
int soopt_getm(struct sockopt *sopt, struct mbuf **mp);
int soopt_mcopyin(struct sockopt *sopt, struct mbuf *m);
int soopt_mcopyout(struct sockopt *sopt, struct mbuf *m);
int sopoll(struct socket *so, int events, struct ucred *active_cred,
struct thread *td);
int sopoll_generic(struct socket *so, int events,
struct ucred *active_cred, struct thread *td);
int soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio,
struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
int soreceive_generic(struct socket *so, struct sockaddr **paddr,
struct uio *uio, struct mbuf **mp0, struct mbuf **controlp,
int *flagsp);
int soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
void sorflush(struct socket *so);
int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
struct mbuf *top, struct mbuf *control, int flags,
struct thread *td);
int sosend_dgram(struct socket *so, struct sockaddr *addr,
struct uio *uio, struct mbuf *top, struct mbuf *control,
int flags, struct thread *td);
int sosend_generic(struct socket *so, struct sockaddr *addr,
struct uio *uio, struct mbuf *top, struct mbuf *control,
int flags, struct thread *td);
int sosetopt(struct socket *so, struct sockopt *sopt);
int soshutdown(struct socket *so, int how);
void sotoxsocket(struct socket *so, struct xsocket *xso);
void sowakeup(struct socket *so, struct sockbuf *sb);
#ifdef SOCKBUF_DEBUG
void sblastrecordchk(struct sockbuf *, const char *, int);
#define SBLASTRECORDCHK(sb) sblastrecordchk((sb), __FILE__, __LINE__)
void sblastmbufchk(struct sockbuf *, const char *, int);
#define SBLASTMBUFCHK(sb) sblastmbufchk((sb), __FILE__, __LINE__)
#else
#define SBLASTRECORDCHK(sb) /* nothing */
#define SBLASTMBUFCHK(sb) /* nothing */
#endif /* SOCKBUF_DEBUG */
/*
* Accept filter functions (duh).
*/
int accept_filt_add(struct accept_filter *filt);
int accept_filt_del(char *name);
struct accept_filter *accept_filt_get(char *name);
#ifdef ACCEPT_FILTER_MOD
#ifdef SYSCTL_DECL
SYSCTL_DECL(_net_inet_accf);
#endif
int accept_filt_generic_mod_event(module_t mod, int event, void *data);
#endif
#endif /* _KERNEL */
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
@ -717,7 +383,6 @@ int accept_filt_generic_mod_event(module_t mod, int event, void *data);
* above into, avoiding having to port the entire thing at once...
* For function prototypes, the full bodies are in user_socket.c .
*/
#if defined(__Userspace__)
/* ---------------------------------------------------------- */
/* --- function prototypes (implemented in user_socket.c) --- */
@ -792,9 +457,7 @@ extern int sctp_listen(struct socket *so, int backlog, struct proc *p);
extern void socantrcvmore_locked(struct socket *so);
extern int sctp_bind(struct socket *so, struct sockaddr *addr);
extern int sctp6_bind(struct socket *so, struct sockaddr *addr, void *proc);
#if defined(__Userspace__)
extern int sctpconn_bind(struct socket *so, struct sockaddr *addr);
#endif
extern int sctp_accept(struct socket *so, struct sockaddr **addr);
extern int sctp_attach(struct socket *so, int proto, uint32_t vrf_id);
extern int sctp6_attach(struct socket *so, int proto, uint32_t vrf_id);
@ -813,9 +476,7 @@ extern int soconnect(struct socket *so, struct sockaddr *nam);
extern int sctp_disconnect(struct socket *so);
extern int sctp_connect(struct socket *so, struct sockaddr *addr);
extern int sctp6_connect(struct socket *so, struct sockaddr *addr);
#if defined(__Userspace__)
extern int sctpconn_connect(struct socket *so, struct sockaddr *addr);
#endif
extern void sctp_finish(void);
/* ------------------------------------------------ */
@ -863,8 +524,4 @@ extern void sctp_finish(void);
sowwakeup_locked(so); \
} while (0)
#endif /* __Userspace__ */
#endif /* !_SYS_SOCKETVAR_H_ */

View File

@ -83,14 +83,14 @@ struct uma_zone {
/* Prototype */
uma_zone_t
uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
uma_init uminit, uma_fini fini, int align, u_int32_t flags);
uma_init uminit, uma_fini fini, int align, uint32_t flags);
#define uma_zone_set_max(zone, number) /* stub TODO __Userspace__ */
uma_zone_t
uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
uma_init uminit, uma_fini fini, int align, u_int32_t flags) {
uma_init uminit, uma_fini fini, int align, uint32_t flags) {
return NULL; /* stub TODO __Userspace__. Also place implementation in a separate .c file */
}
#endif

View File

@ -64,19 +64,19 @@ extern "C" {
#elif defined(SCTP_STDINT_INCLUDE)
#include SCTP_STDINT_INCLUDE
#else
#define uint8_t unsigned __int8
#define uint16_t unsigned __int16
#define uint32_t unsigned __int32
#define uint64_t unsigned __int64
#define int16_t __int16
#define int32_t __int32
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
#endif
#ifndef ssize_t
#ifdef _WIN64
#define ssize_t __int64
typedef __int64 ssize_t;
#elif defined _WIN32
#define ssize_t int
typedef int ssize_t;
#else
#error "Unknown platform!"
#endif
@ -281,12 +281,13 @@ struct sctp_assoc_change {
#define SCTP_CANT_STR_ASSOC 0x0005
/* sac_info values */
#define SCTP_ASSOC_SUPPORTS_PR 0x01
#define SCTP_ASSOC_SUPPORTS_AUTH 0x02
#define SCTP_ASSOC_SUPPORTS_ASCONF 0x03
#define SCTP_ASSOC_SUPPORTS_MULTIBUF 0x04
#define SCTP_ASSOC_SUPPORTS_RE_CONFIG 0x05
#define SCTP_ASSOC_SUPPORTS_MAX 0x05
#define SCTP_ASSOC_SUPPORTS_PR 0x01
#define SCTP_ASSOC_SUPPORTS_AUTH 0x02
#define SCTP_ASSOC_SUPPORTS_ASCONF 0x03
#define SCTP_ASSOC_SUPPORTS_MULTIBUF 0x04
#define SCTP_ASSOC_SUPPORTS_RE_CONFIG 0x05
#define SCTP_ASSOC_SUPPORTS_INTERLEAVING 0x06
#define SCTP_ASSOC_SUPPORTS_MAX 0x06
/* Address event */
struct sctp_paddr_change {
@ -903,7 +904,7 @@ struct socket *
usrsctp_socket(int domain, int type, int protocol,
int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data,
size_t datalen, struct sctp_rcvinfo, int flags, void *ulp_info),
int (*send_cb)(struct socket *sock, uint32_t sb_free),
int (*send_cb)(struct socket *sock, uint32_t sb_free, void *ulp_info),
uint32_t sb_threshold,
void *ulp_info);
@ -1032,6 +1033,9 @@ usrsctp_deregister_address(void *);
int
usrsctp_set_ulpinfo(struct socket *, void *);
int
usrsctp_get_ulpinfo(struct socket *, void **);
int
usrsctp_set_upcall(struct socket *so,
void (*upcall)(struct socket *, void *, int),
@ -1042,7 +1046,7 @@ usrsctp_get_events(struct socket *so);
void
usrsctp_handle_timers(uint32_t delta);
usrsctp_handle_timers(uint32_t elapsed_milliseconds);
#define SCTP_DUMP_OUTBOUND 1
#define SCTP_DUMP_INBOUND 0

View File

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.6.0)
set(CMAKE_CXX_FLAGS "-std=c++17 -DANDROID -g")
#tgvoip
add_library(tgvoip STATIC
@ -289,9 +290,7 @@ add_library(tgcalls_tp STATIC
third_party/usrsctplib/user_mbuf.c
third_party/usrsctplib/user_recv_thread.c
third_party/usrsctplib/user_socket.c
voip/webrtc/absl/base/dynamic_annotations.cc
voip/webrtc/absl/base/internal/cycleclock.cc
voip/webrtc/absl/base/internal/exception_safety_testing.cc
voip/webrtc/absl/base/internal/exponential_biased.cc
voip/webrtc/absl/base/internal/low_level_alloc.cc
voip/webrtc/absl/base/internal/periodic_sampler.cc
@ -326,8 +325,6 @@ add_library(tgcalls_tp STATIC
voip/webrtc/absl/flags/internal/commandlineflag.cc
voip/webrtc/absl/flags/internal/flag.cc
voip/webrtc/absl/flags/internal/program_name.cc
voip/webrtc/absl/flags/internal/registry.cc
voip/webrtc/absl/flags/internal/type_erased.cc
voip/webrtc/absl/flags/internal/usage.cc
voip/webrtc/absl/flags/marshalling.cc
voip/webrtc/absl/flags/parse.cc
@ -447,16 +444,17 @@ add_library(tgcalls STATIC
voip/tgcalls/AudioDeviceHelper.cpp
voip/tgcalls/SctpDataChannelProviderInterfaceImpl.cpp
voip/tgcalls/TurnCustomizerImpl.cpp
voip/tgcalls/reference/InstanceImplReference.cpp
voip/tgcalls/legacy/InstanceImplLegacy.cpp
voip/tgcalls/group/GroupNetworkManager.cpp
voip/tgcalls/group/GroupInstanceCustomImpl.cpp
voip/tgcalls/group/GroupJoinPayloadInternal.cpp
voip/tgcalls/group/AudioStreamingPart.cpp
voip/tgcalls/group/VideoStreamingPart.cpp
voip/tgcalls/group/AudioStreamingPartInternal.cpp
voip/tgcalls/group/AudioStreamingPartPersistentDecoder.cpp
voip/tgcalls/group/AVIOContextImpl.cpp
voip/tgcalls/group/StreamingMediaContext.cpp
voip/tgcalls/third-party/json11.cpp
voip/tgcalls/group/VideoStreamingPart.cpp
voip/webrtc/rtc_base/bitstream_reader.cc
voip/webrtc/rtc_base/async_invoker.cc
voip/webrtc/rtc_base/system_time.cc
voip/webrtc/rtc_base/async_resolver.cc
@ -479,6 +477,7 @@ add_library(tgcalls STATIC
voip/webrtc/rtc_base/boringssl_identity.cc
voip/webrtc/rtc_base/experiments/alr_experiment.cc
voip/webrtc/rtc_base/experiments/balanced_degradation_settings.cc
voip/webrtc/rtc_base/experiments/bandwidth_quality_scaler_settings.cc
voip/webrtc/rtc_base/experiments/cpu_speed_experiment.cc
voip/webrtc/rtc_base/experiments/encoder_info_settings.cc
voip/webrtc/rtc_base/experiments/field_trial_list.cc
@ -491,10 +490,12 @@ add_library(tgcalls STATIC
voip/webrtc/rtc_base/experiments/quality_rampup_experiment.cc
voip/webrtc/rtc_base/experiments/quality_scaler_settings.cc
voip/webrtc/rtc_base/experiments/quality_scaling_experiment.cc
voip/webrtc/rtc_base/experiments/quality_rampup_experiment.cc
voip/webrtc/rtc_base/experiments/rate_control_settings.cc
voip/webrtc/rtc_base/experiments/rtt_mult_experiment.cc
voip/webrtc/rtc_base/experiments/stable_target_rate_experiment.cc
voip/webrtc/rtc_base/experiments/struct_parameters_parser.cc
voip/webrtc/rtc_base/experiments/bandwidth_quality_scaler_settings.cc
voip/webrtc/rtc_base/file_rotating_stream.cc
voip/webrtc/rtc_base/helpers.cc
voip/webrtc/rtc_base/http_common.cc
@ -584,6 +585,7 @@ add_library(tgcalls STATIC
voip/webrtc/rtc_base/callback_list.cc
voip/webrtc/rtc_base/deprecated/recursive_critical_section.cc
voip/webrtc/rtc_base/internal/default_socket_server.cc
voip/webrtc/api/adaptation/resource.cc
voip/webrtc/api/audio/audio_frame.cc
voip/webrtc/api/audio/channel_layout.cc
voip/webrtc/api/audio/echo_canceller3_config.cc
@ -630,8 +632,8 @@ add_library(tgcalls STATIC
voip/webrtc/api/neteq/default_neteq_controller_factory.cc
voip/webrtc/api/neteq/neteq.cc
voip/webrtc/api/neteq/tick_timer.cc
voip/webrtc/api/numerics/samples_stats_counter.cc
voip/webrtc/api/peer_connection_interface.cc
voip/webrtc/api/proxy.cc
voip/webrtc/api/rtc_error.cc
voip/webrtc/api/rtc_event_log/rtc_event.cc
voip/webrtc/api/rtc_event_log/rtc_event_log.cc
@ -656,7 +658,9 @@ add_library(tgcalls STATIC
voip/webrtc/api/video/video_adaptation_counters.cc
voip/webrtc/api/video/video_frame_metadata.cc
voip/webrtc/api/voip/voip_engine_factory.cc
voip/webrtc/api/video/rtp_video_frame_assembler.cc
voip/webrtc/api/numerics/samples_stats_counter.cc
voip/webrtc/api/wrapping_async_dns_resolver.cc
voip/webrtc/call/adaptation/adaptation_constraint.cc
voip/webrtc/call/adaptation/broadcast_resource_listener.cc
voip/webrtc/call/adaptation/degradation_preference_provider.cc
@ -722,6 +726,7 @@ add_library(tgcalls STATIC
voip/webrtc/pc/jsep_ice_candidate.cc
voip/webrtc/pc/jsep_session_description.cc
voip/webrtc/pc/jsep_transport.cc
voip/webrtc/pc/jsep_transport_collection.cc
voip/webrtc/pc/jsep_transport_controller.cc
voip/webrtc/pc/local_audio_source.cc
voip/webrtc/pc/media_protocol_names.cc
@ -758,6 +763,7 @@ add_library(tgcalls STATIC
voip/webrtc/pc/video_rtp_track_source.cc
voip/webrtc/pc/video_track.cc
voip/webrtc/pc/video_track_source.cc
voip/webrtc/pc/video_track_source_proxy.cc
voip/webrtc/pc/webrtc_sdp.cc
voip/webrtc/pc/webrtc_session_description_factory.cc
voip/webrtc/pc/connection_context.cc
@ -769,7 +775,6 @@ add_library(tgcalls STATIC
voip/webrtc/sdk/android/src/jni/pc/add_ice_candidate_observer.cc
voip/webrtc/media/base/adapted_video_track_source.cc
voip/webrtc/media/base/codec.cc
voip/webrtc/media/base/h264_profile_level_id.cc
voip/webrtc/media/base/media_channel.cc
voip/webrtc/media/base/media_constants.cc
voip/webrtc/media/base/media_engine.cc
@ -805,6 +810,7 @@ add_library(tgcalls STATIC
voip/webrtc/system_wrappers/source/metrics.cc
voip/webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc
voip/webrtc/system_wrappers/source/sleep.cc
voip/webrtc/system_wrappers/source/denormal_disabler.cc
voip/webrtc/modules/audio_coding/acm2/acm_receiver.cc
voip/webrtc/modules/audio_coding/acm2/acm_remixing.cc
voip/webrtc/modules/audio_coding/acm2/acm_resampler.cc
@ -1008,6 +1014,9 @@ add_library(tgcalls STATIC
voip/webrtc/modules/audio_coding/neteq/sync_buffer.cc
voip/webrtc/modules/audio_coding/neteq/time_stretch.cc
voip/webrtc/modules/audio_coding/neteq/timestamp_scaler.cc
voip/webrtc/modules/audio_coding/neteq/reorder_optimizer.cc
voip/webrtc/modules/audio_coding/neteq/underrun_optimizer.cc
voip/webrtc/modules/audio_coding/neteq/relative_arrival_delay_tracker.cc
voip/webrtc/modules/audio_device/audio_device_buffer.cc
voip/webrtc/modules/audio_device/audio_device_data_observer.cc
voip/webrtc/modules/audio_device/audio_device_generic.cc
@ -1089,24 +1098,25 @@ add_library(tgcalls STATIC
voip/webrtc/modules/audio_processing/agc/legacy/digital_agc.cc
voip/webrtc/modules/audio_processing/agc/loudness_histogram.cc
voip/webrtc/modules/audio_processing/agc/utility.cc
voip/webrtc/modules/audio_processing/agc2/adaptive_agc.cc
voip/webrtc/modules/audio_processing/agc/clipping_predictor.cc
voip/webrtc/modules/audio_processing/agc/clipping_predictor_evaluator.cc
voip/webrtc/modules/audio_processing/agc/clipping_predictor_level_buffer.cc
voip/webrtc/modules/audio_processing/agc/analog_gain_stats_reporter.cc
voip/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_controller.cc
voip/webrtc/modules/audio_processing/agc2/vad_wrapper.cc
voip/webrtc/modules/audio_processing/agc2/cpu_features.cc
voip/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_applier.cc
voip/webrtc/modules/audio_processing/agc2/adaptive_mode_level_estimator.cc
voip/webrtc/modules/audio_processing/agc2/agc2_testing_common.cc
voip/webrtc/modules/audio_processing/agc2/biquad_filter.cc
voip/webrtc/modules/audio_processing/agc2/compute_interpolated_gain_curve.cc
voip/webrtc/modules/audio_processing/agc2/down_sampler.cc
voip/webrtc/modules/audio_processing/agc2/fixed_digital_level_estimator.cc
voip/webrtc/modules/audio_processing/agc2/gain_applier.cc
voip/webrtc/modules/audio_processing/agc2/interpolated_gain_curve.cc
voip/webrtc/modules/audio_processing/agc2/limiter.cc
voip/webrtc/modules/audio_processing/agc2/limiter_db_gain_curve.cc
voip/webrtc/modules/audio_processing/agc2/noise_level_estimator.cc
voip/webrtc/modules/audio_processing/agc2/noise_spectrum_estimator.cc
voip/webrtc/modules/audio_processing/agc2/saturation_protector.cc
voip/webrtc/modules/audio_processing/agc2/signal_classifier.cc
voip/webrtc/modules/audio_processing/agc2/vad_with_level.cc
voip/webrtc/modules/audio_processing/agc2/vector_float_frame.cc
voip/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.cc
voip/webrtc/modules/audio_processing/agc2/rnn_vad/auto_correlation.cc
@ -1134,8 +1144,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/audio_processing/include/audio_frame_proxies.cc
voip/webrtc/modules/audio_processing/include/audio_processing.cc
voip/webrtc/modules/audio_processing/include/audio_processing_statistics.cc
voip/webrtc/modules/audio_processing/include/config.cc
voip/webrtc/modules/audio_processing/level_estimator.cc
voip/webrtc/modules/audio_processing/logging/apm_data_dumper.cc
voip/webrtc/modules/audio_processing/ns/fast_math.cc
voip/webrtc/modules/audio_processing/ns/histograms.cc
@ -1203,6 +1211,8 @@ add_library(tgcalls STATIC
voip/webrtc/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc
voip/webrtc/modules/congestion_controller/goog_cc/trendline_estimator.cc
voip/webrtc/modules/congestion_controller/goog_cc/inter_arrival_delta.cc
voip/webrtc/modules/congestion_controller/goog_cc/loss_based_bandwidth_estimation.cc
voip/webrtc/modules/congestion_controller/goog_cc/loss_based_bwe_v2.cc
voip/webrtc/modules/pacing/bitrate_prober.cc
voip/webrtc/modules/pacing/interval_budget.cc
voip/webrtc/modules/pacing/paced_sender.cc
@ -1215,7 +1225,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/rtp_rtcp/source/absolute_capture_time_interpolator.cc
voip/webrtc/modules/rtp_rtcp/source/capture_clock_offset_updater.cc
voip/webrtc/modules/rtp_rtcp/source/active_decode_targets_helper.cc
voip/webrtc/modules/rtp_rtcp/source/absolute_capture_time_receiver.cc
voip/webrtc/modules/rtp_rtcp/source/absolute_capture_time_sender.cc
voip/webrtc/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc
voip/webrtc/modules/rtp_rtcp/source/dtmf_queue.cc
@ -1289,7 +1298,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc
voip/webrtc/modules/rtp_rtcp/source/rtp_sender_video_frame_transformer_delegate.cc
voip/webrtc/modules/rtp_rtcp/source/rtp_sequence_number_map.cc
voip/webrtc/modules/rtp_rtcp/source/rtp_utility.cc
voip/webrtc/modules/rtp_rtcp/source/rtp_video_header.cc
voip/webrtc/modules/rtp_rtcp/source/source_tracker.cc
voip/webrtc/modules/rtp_rtcp/source/time_util.cc
@ -1309,6 +1317,7 @@ add_library(tgcalls STATIC
voip/webrtc/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc
voip/webrtc/modules/rtp_rtcp/source/rtp_video_layers_allocation_extension.cc
voip/webrtc/modules/rtp_rtcp/source/packet_sequencer.cc
voip/webrtc/modules/rtp_rtcp/source/rtp_util.cc
voip/webrtc/modules/utility/source/helpers_android.cc
voip/webrtc/modules/utility/source/jvm_android.cc
voip/webrtc/modules/utility/source/process_thread_impl.cc
@ -1361,7 +1370,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/video_coding/utility/decoded_frames_history.cc
voip/webrtc/modules/video_coding/utility/qp_parser.cc
voip/webrtc/modules/video_coding/utility/frame_dropper.cc
voip/webrtc/modules/video_coding/utility/framerate_controller.cc
voip/webrtc/modules/video_coding/utility/ivf_file_reader.cc
voip/webrtc/modules/video_coding/utility/ivf_file_writer.cc
voip/webrtc/modules/video_coding/utility/quality_scaler.cc
@ -1369,6 +1377,8 @@ add_library(tgcalls STATIC
voip/webrtc/modules/video_coding/utility/simulcast_utility.cc
voip/webrtc/modules/video_coding/utility/vp8_header_parser.cc
voip/webrtc/modules/video_coding/utility/vp9_uncompressed_header_parser.cc
voip/webrtc/modules/video_coding/utility/bandwidth_quality_scaler.cc
voip/webrtc/modules/video_coding/utility/framerate_controller_deprecated.cc
voip/webrtc/modules/video_coding/video_codec_initializer.cc
voip/webrtc/modules/video_coding/video_coding_defines.cc
voip/webrtc/modules/video_coding/video_coding_impl.cc
@ -1398,6 +1408,9 @@ add_library(tgcalls STATIC
voip/webrtc/modules/video_coding/rtp_vp9_ref_finder.cc
voip/webrtc/modules/video_coding/rtp_generic_ref_finder.cc
voip/webrtc/modules/video_coding/codecs/av1/av1_svc_config.cc
voip/webrtc/modules/video_coding/nack_requester.cc
voip/webrtc/modules/video_coding/frame_buffer3.cc
voip/webrtc/modules/video_coding/h264_packet_buffer.cc
voip/webrtc/modules/video_processing/util/denoiser_filter.cc
voip/webrtc/modules/video_processing/util/denoiser_filter_c.cc
voip/webrtc/modules/video_processing/util/noise_estimation.cc
@ -1497,6 +1510,7 @@ add_library(tgcalls STATIC
voip/webrtc/common_video/h264/sps_vui_rewriter.cc
voip/webrtc/common_video/h265/h265_bitstream_parser.cc
voip/webrtc/common_video/h265/h265_common.cc
voip/webrtc/common_video/h265/legacy_bit_buffer.cc
voip/webrtc/common_video/h265/h265_pps_parser.cc
voip/webrtc/common_video/h265/h265_sps_parser.cc
voip/webrtc/common_video/h265/h265_vps_parser.cc
@ -1505,6 +1519,7 @@ add_library(tgcalls STATIC
voip/webrtc/common_video/video_frame_buffer.cc
voip/webrtc/common_video/video_render_frames.cc
voip/webrtc/common_video/video_frame_buffer_pool.cc
voip/webrtc/common_video/framerate_controller.cc
voip/webrtc/p2p/base/async_stun_tcp_socket.cc
voip/webrtc/p2p/base/basic_async_resolver_factory.cc
voip/webrtc/p2p/base/basic_ice_controller.cc
@ -1537,9 +1552,7 @@ add_library(tgcalls STATIC
voip/webrtc/p2p/client/basic_port_allocator.cc
voip/webrtc/p2p/client/turn_port_factory.cc
voip/webrtc/p2p/stunprober/stun_prober.cc
voip/webrtc/video/adaptation/quality_rampup_experiment_helper.cc
voip/webrtc/modules/video_coding/deprecated/nack_module.cc
voip/webrtc/modules/video_coding/nack_module2.cc
voip/webrtc/modules/async_audio_processing/async_audio_processing.cc
voip/webrtc/logging/rtc_event_log/encoder/blob_encoding.cc
voip/webrtc/logging/rtc_event_log/encoder/delta_encoding.cc
@ -1569,6 +1582,10 @@ add_library(tgcalls STATIC
voip/webrtc/logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.cc
voip/webrtc/logging/rtc_event_log/events/rtc_event_video_receive_stream_config.cc
voip/webrtc/logging/rtc_event_log/events/rtc_event_video_send_stream_config.cc
voip/webrtc/logging/rtc_event_log/events/fixed_length_encoding_parameters_v3.cc
voip/webrtc/logging/rtc_event_log/events/rtc_event_field_encoding.cc
voip/webrtc/logging/rtc_event_log/events/rtc_event_field_encoding_parser.cc
voip/webrtc/logging/rtc_event_log/events/rtc_event_field_extraction.cc
voip/webrtc/logging/rtc_event_log/fake_rtc_event_log.cc
voip/webrtc/logging/rtc_event_log/fake_rtc_event_log_factory.cc
voip/webrtc/logging/rtc_event_log/ice_logger.cc
@ -1582,6 +1599,8 @@ add_library(tgcalls STATIC
voip/webrtc/video/adaptation/balanced_constraint.cc
voip/webrtc/video/adaptation/bitrate_constraint.cc
voip/webrtc/video/adaptation/pixel_limit_resource.cc
voip/webrtc/video/adaptation/quality_rampup_experiment_helper.cc
voip/webrtc/video/adaptation/bandwidth_quality_scaler_resource.cc
voip/webrtc/video/buffered_frame_decryptor.cc
voip/webrtc/video/call_stats.cc
voip/webrtc/video/encoder_bitrate_adjuster.cc
@ -1602,7 +1621,6 @@ add_library(tgcalls STATIC
voip/webrtc/video/stream_synchronization.cc
voip/webrtc/video/transport_adapter.cc
voip/webrtc/video/video_quality_observer.cc
voip/webrtc/video/video_receive_stream.cc
voip/webrtc/video/video_send_stream.cc
voip/webrtc/video/video_send_stream_impl.cc
voip/webrtc/video/video_source_sink_controller.cc
@ -1617,6 +1635,7 @@ add_library(tgcalls STATIC
voip/webrtc/video/receive_statistics_proxy2.cc
voip/webrtc/video/call_stats2.cc
voip/webrtc/video/alignment_adjuster.cc
voip/webrtc/video/frame_cadence_adapter.cc
voip/webrtc/audio/audio_level.cc
voip/webrtc/audio/audio_receive_stream.cc
voip/webrtc/audio/audio_send_stream.cc

View File

@ -27,9 +27,7 @@ EchoCanceller::EchoCanceller(bool enableAEC, bool enableNS, bool enableAGC){
this->enableNS=enableNS;
isOn=true;
webrtc::Config extraConfig;
apm=webrtc::AudioProcessingBuilder().Create(extraConfig);
apm=webrtc::AudioProcessingBuilder().Create();
webrtc::AudioProcessing::Config config;
config.echo_canceller.enabled = enableAEC;
@ -70,7 +68,6 @@ EchoCanceller::EchoCanceller(bool enableAEC, bool enableNS, bool enableAGC){
config.gain_controller1.enable_limiter = ServerConfig::GetSharedInstance()->GetBoolean("webrtc_agc_enable_limiter", true);
config.gain_controller1.compression_gain_db = ServerConfig::GetSharedInstance()->GetInt("webrtc_agc_compression_gain", 20);
}
config.voice_detection.enabled = true;
apm->ApplyConfig(config);
@ -126,10 +123,8 @@ void EchoCanceller::RunBufferFarendThread() {
frame.sample_rate_hz_ = 48000;
frame.samples_per_channel_ = 480;
webrtc::StreamConfig input_config(frame.sample_rate_hz_, frame.num_channels_,
/*has_keyboard=*/false);
webrtc::StreamConfig output_config(frame.sample_rate_hz_, frame.num_channels_,
/*has_keyboard=*/false);
webrtc::StreamConfig input_config(frame.sample_rate_hz_, frame.num_channels_);
webrtc::StreamConfig output_config(frame.sample_rate_hz_, frame.num_channels_);
while (running) {
int16_t *samplesIn = farendQueue->GetBlocking();
@ -159,10 +154,8 @@ void EchoCanceller::ProcessInput(int16_t* inOut, size_t numSamples, bool& hasVoi
int delay = audio::AudioInput::GetEstimatedDelay() + audio::AudioOutput::GetEstimatedDelay();
assert(numSamples == 960);
webrtc::StreamConfig input_config(audioFrame->sample_rate_hz_, audioFrame->num_channels_,
/*has_keyboard=*/false);
webrtc::StreamConfig output_config(audioFrame->sample_rate_hz_, audioFrame->num_channels_,
/*has_keyboard=*/false);
webrtc::StreamConfig input_config(audioFrame->sample_rate_hz_, audioFrame->num_channels_);
webrtc::StreamConfig output_config(audioFrame->sample_rate_hz_, audioFrame->num_channels_);
memcpy(audioFrame->mutable_data(), inOut, 480 * 2);
if (enableAEC)
@ -201,7 +194,7 @@ void EchoCanceller::SetVoiceDetectionEnabled(bool enabled) {
enableVAD = enabled;
#ifndef TGVOIP_NO_DSP
auto config = apm->GetConfig();
config.voice_detection.enabled = enabled;
// config.voice_detection.enabled = enabled;
apm->ApplyConfig(config);
#endif
}

View File

@ -19,7 +19,6 @@
#include "pc/video_track.h"
#include "legacy/InstanceImplLegacy.h"
#include "InstanceImpl.h"
#include "reference/InstanceImplReference.h"
#include "libtgvoip/os/android/AudioOutputOpenSLES.h"
#include "libtgvoip/os/android/AudioInputOpenSLES.h"
#include "libtgvoip/os/android/JNIUtilities.h"
@ -29,7 +28,6 @@ using namespace tgcalls;
const auto RegisterTag = Register<InstanceImpl>();
const auto RegisterTagLegacy = Register<InstanceImplLegacy>();
const auto RegisterTagReference = tgcalls::Register<InstanceImplReference>();
jclass TrafficStatsClass;
jclass FingerprintClass;
@ -137,6 +135,19 @@ private:
VideoChannelDescription::Quality _quality;
};
class RequestCurrentTimeTaskJava : public BroadcastPartTask {
public:
RequestCurrentTimeTaskJava(std::function<void(int64_t)> callback) :
_callback(std::move(callback)) {
}
std::function<void(int64_t)> _callback;
private:
void cancel() override {
}
};
class JavaObject {
private:
JNIEnv *env;
@ -198,6 +209,7 @@ struct InstanceHolder {
std::unique_ptr<GroupInstanceCustomImpl> groupNativeInstance;
std::shared_ptr<tgcalls::VideoCaptureInterface> _videoCapture;
std::shared_ptr<tgcalls::VideoCaptureInterface> _screenVideoCapture;
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _sink;
std::shared_ptr<PlatformContext> _platformContext;
std::map<std::string, SetVideoSink> remoteGroupSinks;
bool useScreencast = false;
@ -466,6 +478,14 @@ JNIEXPORT jlong JNICALL Java_org_telegram_messenger_voip_NativeInstance_makeGrou
});
return task;
};
descriptor.requestCurrentTime = [platformContext](std::function<void(int64_t)> callback) -> std::shared_ptr<BroadcastPartTask> {
std::shared_ptr<RequestCurrentTimeTaskJava> task = std::make_shared<RequestCurrentTimeTaskJava>(callback);
tgvoip::jni::DoWithJNI([platformContext, task](JNIEnv *env) {
jobject globalRef = ((AndroidContext *) platformContext.get())->getJavaInstance();
env->CallVoidMethod(globalRef, env->GetMethodID(NativeInstanceClass, "requestCurrentTime", "(J)V"), (jlong) task.get());
});
return task;
};
}
auto *holder = new InstanceHolder;
@ -481,17 +501,18 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_setJoinRe
if (instance->groupNativeInstance == nullptr) {
return;
}
instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeRtc, true);
instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeRtc, true, true);
instance->groupNativeInstance->setJoinResponsePayload(tgvoip::jni::JavaStringToStdString(env, payload));
}
extern "C"
JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_prepareForStream(JNIEnv *env, jobject obj) {
JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_prepareForStream(JNIEnv *env, jobject obj, jboolean isRtmpStream) {
InstanceHolder *instance = getInstanceHolder(env, obj);
if (instance->groupNativeInstance == nullptr) {
return;
}
instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeBroadcast, true);
instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeBroadcast, true,
isRtmpStream);
}
void onEmitJoinPayload(const std::shared_ptr<PlatformContext>& platformContext, const GroupJoinPayload& payload) {
@ -507,7 +528,7 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_resetGrou
return;
}
if (set) {
instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeNone, !disconnect);
instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeNone, !disconnect, true);
}
std::shared_ptr<PlatformContext> platformContext = instance->_platformContext;
instance->groupNativeInstance->emitJoinPayload([platformContext](const GroupJoinPayload& payload) {
@ -735,7 +756,8 @@ JNIEXPORT jlong JNICALL Java_org_telegram_messenger_voip_NativeInstance_makeNati
holder->nativeInstance = tgcalls::Meta::Create(v, std::move(descriptor));
holder->_videoCapture = videoCapture;
holder->_platformContext = platformContext;
holder->nativeInstance->setIncomingVideoOutput(webrtc::JavaToNativeVideoSink(env, remoteSink));
holder->_sink = webrtc::JavaToNativeVideoSink(env, remoteSink);
holder->nativeInstance->setIncomingVideoOutput(holder->_sink);
holder->nativeInstance->setNetworkType(parseNetworkType(networkType));
holder->nativeInstance->setRequestedVideoAspect(aspectRatio);
return reinterpret_cast<jlong>(holder);
@ -1067,4 +1089,14 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_onSignali
env->ReleaseByteArrayElements(value, (jbyte *) valueBytes, JNI_ABORT);
}
extern "C"
JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_onRequestTimeComplete(JNIEnv *env, jobject obj, jlong taskPtr, jlong currentTime) {
InstanceHolder *instance = getInstanceHolder(env, obj);
if (instance->groupNativeInstance == nullptr) {
return;
}
auto task = reinterpret_cast<RequestCurrentTimeTaskJava *>(taskPtr);
task->_callback(currentTime);
}
}

View File

@ -106,11 +106,7 @@ std::vector<VideoFormat>::const_iterator FindEqualFormat(
const std::vector<VideoFormat> &list,
const VideoFormat &format) {
return std::find_if(list.begin(), list.end(), [&](const VideoFormat &other) {
return cricket::IsSameCodec(
format.name,
format.parameters,
other.name,
other.parameters);
return format.IsSameCodec(other);
});
}

View File

@ -63,7 +63,7 @@ bool ConstTimeIsDifferent(const void *a, const void *b, size_t size) {
auto cb = reinterpret_cast<const char*>(b);
volatile auto different = false;
for (const auto ce = ca + size; ca != ce; ++ca, ++cb) {
different |= (*ca != *cb);
different = different | (*ca != *cb);
}
return different;
}

View File

@ -121,13 +121,13 @@ class FakeVideoSource : public rtc::VideoSourceInterface<webrtc::VideoFrame> {
}
using VideoFrameT = webrtc::VideoFrame;
void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrameT> *sink, const rtc::VideoSinkWants &wants) override {
RTC_LOG(WARNING) << "ADD";
RTC_LOG(LS_WARNING) << "ADD";
data_->broadcaster_.AddOrUpdateSink(sink, wants);
}
// RemoveSink must guarantee that at the time the method returns,
// there is no current and no future calls to VideoSinkInterface::OnFrame.
void RemoveSink(rtc::VideoSinkInterface<VideoFrameT> *sink) {
RTC_LOG(WARNING) << "REMOVE";
RTC_LOG(LS_WARNING) << "REMOVE";
data_->broadcaster_.RemoveSink(sink);
}

View File

@ -62,7 +62,7 @@ void dumpStatsLog(const FilePath &path, const CallStats &stats) {
} // namespace
bool Manager::ResolvedNetworkStatus::operator==(const ResolvedNetworkStatus &rhs) {
bool Manager::ResolvedNetworkStatus::operator==(const ResolvedNetworkStatus &rhs) const {
if (rhs.isLowCost != isLowCost) {
return false;
}
@ -72,7 +72,7 @@ bool Manager::ResolvedNetworkStatus::operator==(const ResolvedNetworkStatus &rhs
return true;
}
bool Manager::ResolvedNetworkStatus::operator!=(const ResolvedNetworkStatus &rhs) {
bool Manager::ResolvedNetworkStatus::operator!=(const ResolvedNetworkStatus &rhs) const {
return !(*this == rhs);
}
@ -334,7 +334,7 @@ void Manager::setMuteOutgoingAudio(bool mute) {
});
}
void Manager::setIncomingVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
void Manager::setIncomingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
_mediaManager->perform(RTC_FROM_HERE, [sink](MediaManager *mediaManager) {
mediaManager->setIncomingVideoOutput(sink);
});

View File

@ -16,8 +16,8 @@ private:
bool isLowCost = false;
bool isLowDataRequested = false;
bool operator==(const ResolvedNetworkStatus &rhs);
bool operator!=(const ResolvedNetworkStatus &rhs);
bool operator==(const ResolvedNetworkStatus &rhs) const;
bool operator!=(const ResolvedNetworkStatus &rhs) const;
};
public:
@ -32,7 +32,7 @@ public:
void sendVideoDeviceUpdated();
void setRequestedVideoAspect(float aspect);
void setMuteOutgoingAudio(bool mute);
void setIncomingVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
void setIncomingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
void setIsLowBatteryLevel(bool isLowBatteryLevel);
void setIsLocalNetworkLowCost(bool isLocalNetworkLowCost);
void getNetworkStats(std::function<void(TrafficStats, CallStats)> completion);

View File

@ -18,11 +18,13 @@
#include "system_wrappers/include/field_trial.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "call/call.h"
#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "modules/rtp_rtcp/source/rtp_util.h"
#include "api/call/audio_sink.h"
#include "modules/audio_processing/audio_buffer.h"
#include "modules/audio_device/include/audio_device_factory.h"
#ifdef WEBRTC_IOS
#include "platform/darwin/iOS/tgcalls_audio_device_module_ios.h"
#endif
namespace tgcalls {
namespace {
@ -163,30 +165,30 @@ public:
}
virtual void OnFrame(const webrtc::VideoFrame& frame) override {
if (_impl) {
if (const auto strong = _impl.lock()) {
if (_rewriteRotation) {
webrtc::VideoFrame updatedFrame = frame;
//updatedFrame.set_rotation(webrtc::VideoRotation::kVideoRotation_90);
_impl->OnFrame(updatedFrame);
strong->OnFrame(updatedFrame);
} else {
_impl->OnFrame(frame);
strong->OnFrame(frame);
}
}
}
virtual void OnDiscardedFrame() override {
if (_impl) {
_impl->OnDiscardedFrame();
if (const auto strong = _impl.lock()) {
strong->OnDiscardedFrame();
}
}
void setSink(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> impl) {
void setSink(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> impl) {
_impl = impl;
}
private:
bool _rewriteRotation = false;
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _impl;
std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _impl;
};
@ -405,9 +407,13 @@ _platformContext(platformContext) {
rtc::scoped_refptr<webrtc::AudioDeviceModule> MediaManager::createAudioDeviceModule() {
const auto create = [&](webrtc::AudioDeviceModule::AudioLayer layer) {
#ifdef WEBRTC_IOS
return rtc::make_ref_counted<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS>(false, false);
#else
return webrtc::AudioDeviceModule::Create(
layer,
_taskQueueFactory.get());
#endif
};
const auto check = [&](const rtc::scoped_refptr<webrtc::AudioDeviceModule> &result) {
return (result && result->Init() == 0) ? result : nullptr;
@ -908,28 +914,31 @@ void MediaManager::setOutgoingVideoState(VideoState state) {
sendOutgoingMediaStateMessage();
}
void MediaManager::setIncomingVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
void MediaManager::setIncomingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
_incomingVideoSinkProxy->setSink(sink);
}
static bool IsRtcp(const uint8_t* packet, size_t length) {
webrtc::RtpUtility::RtpHeaderParser rtp_parser(packet, length);
return rtp_parser.RTCP();
}
void MediaManager::receiveMessage(DecryptedMessage &&message) {
const auto data = &message.message.data;
if (const auto formats = absl::get_if<VideoFormatsMessage>(data)) {
setPeerVideoFormats(std::move(*formats));
} else if (const auto audio = absl::get_if<AudioDataMessage>(data)) {
if (IsRtcp(audio->data.data(), audio->data.size())) {
if (webrtc::IsRtcpPacket(audio->data)) {
RTC_LOG(LS_VERBOSE) << "Deliver audio RTCP";
}
_call->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, audio->data, -1);
if (webrtc::IsRtcpPacket(audio->data)) {
_call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, audio->data, -1);
} else {
_call->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, audio->data, -1);
}
} else if (const auto video = absl::get_if<VideoDataMessage>(data)) {
if (_videoChannel) {
if (_readyToReceiveVideo) {
_call->Receiver()->DeliverPacket(webrtc::MediaType::VIDEO, video->data, -1);
if (webrtc::IsRtcpPacket(video->data)) {
_call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, video->data, -1);
} else {
_call->Receiver()->DeliverPacket(webrtc::MediaType::VIDEO, video->data, -1);
}
} else {
// maybe we need to queue packets for some time?
}

View File

@ -61,7 +61,7 @@ public:
void sendVideoDeviceUpdated();
void setRequestedVideoAspect(float aspect);
void setMuteOutgoingAudio(bool mute);
void setIncomingVideoOutput(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
void setIncomingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
void receiveMessage(DecryptedMessage &&message);
void remoteVideoStateUpdated(VideoState videoState);
void setNetworkParameters(bool isLowCost, bool isDataSavingActive);

View File

@ -107,7 +107,7 @@ NetworkManager::~NetworkManager() {
}
void NetworkManager::start() {
_socketFactory.reset(new rtc::BasicPacketSocketFactory(_thread));
_socketFactory.reset(new rtc::BasicPacketSocketFactory(_thread->socketserver()));
_networkManager = std::make_unique<rtc::BasicNetworkManager>(_networkMonitorFactory.get());

View File

@ -103,7 +103,7 @@ void SctpDataChannelProviderInterfaceImpl::sctpReadyToSendData() {
_dataChannel->OnTransportReady(true);
}
void SctpDataChannelProviderInterfaceImpl::sctpClosedAbruptly() {
void SctpDataChannelProviderInterfaceImpl::sctpClosedAbruptly(webrtc::RTCError error) {
assert(_threads->getNetworkThread()->IsCurrent());
if (_onTerminated) {
@ -117,10 +117,15 @@ void SctpDataChannelProviderInterfaceImpl::sctpDataReceived(const cricket::Recei
_dataChannel->OnDataReceived(params, buffer);
}
bool SctpDataChannelProviderInterfaceImpl::SendData(int sid, const webrtc::SendDataParams& params, const rtc::CopyOnWriteBuffer& payload, cricket::SendDataResult* result) {
bool SctpDataChannelProviderInterfaceImpl::SendData(
int sid,
const webrtc::SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result
) {
assert(_threads->getNetworkThread()->IsCurrent());
return _sctpTransport->SendData(sid, params, payload);
return _sctpTransport->SendData(sid, params, payload, result);
}
bool SctpDataChannelProviderInterfaceImpl::ConnectDataChannel(webrtc::SctpDataChannel *data_channel) {

View File

@ -5,6 +5,7 @@
#include "api/turn_customizer.h"
#include "api/data_channel_interface.h"
#include "pc/sctp_data_channel.h"
#include "media/sctp/sctp_transport_factory.h"
#include "pc/sctp_transport.h"
#include "StaticThreads.h"
@ -32,7 +33,11 @@ public:
virtual void OnStateChange() override;
virtual void OnMessage(const webrtc::DataBuffer& buffer) override;
virtual bool SendData(int sid, const webrtc::SendDataParams& params, const rtc::CopyOnWriteBuffer& payload, cricket::SendDataResult* result = nullptr) override;
virtual bool SendData(
int sid,
const webrtc::SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result) override;
virtual bool ConnectDataChannel(webrtc::SctpDataChannel *data_channel) override;
virtual void DisconnectDataChannel(webrtc::SctpDataChannel* data_channel) override;
virtual void AddSctpDataStream(int sid) override;
@ -41,7 +46,7 @@ public:
private:
void sctpReadyToSendData();
void sctpClosedAbruptly();
void sctpClosedAbruptly(webrtc::RTCError error);
void sctpDataReceived(const cricket::ReceiveDataParams& params, const rtc::CopyOnWriteBuffer& buffer);
private:

View File

@ -60,16 +60,17 @@ class ThreadsImpl : public Threads {
public:
explicit ThreadsImpl(size_t i) {
auto suffix = i == 0 ? "" : "#" + std::to_string(i);
network_ = create_network("tgc-net" + suffix);
network_->DisallowAllInvokes();
media_ = create("tgc-media" + suffix);
worker_ = create("tgc-work" + suffix);
worker_->DisallowAllInvokes();
worker_->AllowInvokesToThread(network_.get());
//worker_ = create("tgc-work" + suffix);
worker_ = create_network("tgc-work" + suffix);
//network_ = create_network("tgc-net" + suffix);
//network_->DisallowAllInvokes();
//worker_->DisallowAllInvokes();
//worker_->AllowInvokesToThread(network_.get());
}
rtc::Thread *getNetworkThread() override {
return network_.get();
return worker_.get();
}
rtc::Thread *getMediaThread() override {
return media_.get();
@ -89,7 +90,7 @@ public:
}
private:
Thread network_;
//Thread network_;
Thread media_;
Thread worker_;
rtc::scoped_refptr<webrtc::SharedModuleThread> shared_module_thread_;

View File

@ -0,0 +1,64 @@
#include "AVIOContextImpl.h"
#include "rtc_base/logging.h"
#include "rtc_base/third_party/base64/base64.h"
#include "api/video/i420_buffer.h"
#include <string>
#include <set>
#include <map>
namespace tgcalls {
namespace {
int AVIOContextImplRead(void *opaque, unsigned char *buffer, int bufferSize) {
AVIOContextImpl *instance = static_cast<AVIOContextImpl *>(opaque);
int bytesToRead = std::min(bufferSize, ((int)instance->_fileData.size()) - instance->_fileReadPosition);
if (bytesToRead < 0) {
bytesToRead = 0;
}
if (bytesToRead > 0) {
memcpy(buffer, instance->_fileData.data() + instance->_fileReadPosition, bytesToRead);
instance->_fileReadPosition += bytesToRead;
return bytesToRead;
} else {
return AVERROR_EOF;
}
}
int64_t AVIOContextImplSeek(void *opaque, int64_t offset, int whence) {
AVIOContextImpl *instance = static_cast<AVIOContextImpl *>(opaque);
if (whence == 0x10000) {
return (int64_t)instance->_fileData.size();
} else {
int64_t seekOffset = std::min(offset, (int64_t)instance->_fileData.size());
if (seekOffset < 0) {
seekOffset = 0;
}
instance->_fileReadPosition = (int)seekOffset;
return seekOffset;
}
}
}
AVIOContextImpl::AVIOContextImpl(std::vector<uint8_t> &&fileData) :
_fileData(std::move(fileData)) {
_buffer.resize(4 * 1024);
_context = avio_alloc_context(_buffer.data(), (int)_buffer.size(), 0, this, &AVIOContextImplRead, NULL, &AVIOContextImplSeek);
}
AVIOContextImpl::~AVIOContextImpl() {
av_free(_context);
}
AVIOContext *AVIOContextImpl::getContext() const {
return _context;
};
}

View File

@ -0,0 +1,40 @@
#ifndef TGCALLS_AVIOCONTEXTIMPL_H
#define TGCALLS_AVIOCONTEXTIMPL_H
#include "absl/types/optional.h"
#include <vector>
#include <stdint.h>
#include "api/video/video_frame.h"
#include "absl/types/optional.h"
// Fix build on Windows - this should appear before FFmpeg timestamp include.
#define _USE_MATH_DEFINES
#include <math.h>
extern "C" {
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
namespace tgcalls {
class AVIOContextImpl {
public:
AVIOContextImpl(std::vector<uint8_t> &&fileData);
~AVIOContextImpl();
AVIOContext *getContext() const;
public:
std::vector<uint8_t> _fileData;
int _fileReadPosition = 0;
std::vector<uint8_t> _buffer;
AVIOContext *_context = nullptr;
};
}
#endif

View File

@ -1,14 +1,10 @@
#include "AudioStreamingPart.h"
#include "AudioStreamingPartInternal.h"
#include "rtc_base/logging.h"
#include "rtc_base/third_party/base64/base64.h"
extern "C" {
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
#include <string>
#include <bitset>
#include <set>
@ -162,307 +158,6 @@ struct ReadPcmResult {
int numChannels = 0;
};
class AudioStreamingPartInternal {
public:
AudioStreamingPartInternal(std::vector<uint8_t> &&fileData) :
_avIoContext(std::move(fileData)) {
int ret = 0;
_frame = av_frame_alloc();
AVInputFormat *inputFormat = av_find_input_format("ogg");
if (!inputFormat) {
_didReadToEnd = true;
return;
}
_inputFormatContext = avformat_alloc_context();
if (!_inputFormatContext) {
_didReadToEnd = true;
return;
}
_inputFormatContext->pb = _avIoContext.getContext();
if ((ret = avformat_open_input(&_inputFormatContext, "", inputFormat, nullptr)) < 0) {
_didReadToEnd = true;
return;
}
if ((ret = avformat_find_stream_info(_inputFormatContext, nullptr)) < 0) {
_didReadToEnd = true;
avformat_close_input(&_inputFormatContext);
_inputFormatContext = nullptr;
return;
}
AVCodecParameters *audioCodecParameters = nullptr;
AVStream *audioStream = nullptr;
for (int i = 0; i < _inputFormatContext->nb_streams; i++) {
AVStream *inStream = _inputFormatContext->streams[i];
AVCodecParameters *inCodecpar = inStream->codecpar;
if (inCodecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
continue;
}
audioCodecParameters = inCodecpar;
audioStream = inStream;
_durationInMilliseconds = (int)((inStream->duration + inStream->first_dts) * 1000 / 48000);
if (inStream->metadata) {
AVDictionaryEntry *entry = av_dict_get(inStream->metadata, "TG_META", nullptr, 0);
if (entry && entry->value) {
std::string result;
size_t data_used = 0;
std::string sourceBase64 = (const char *)entry->value;
rtc::Base64::Decode(sourceBase64, rtc::Base64::DO_LAX, &result, &data_used);
if (result.size() != 0) {
int offset = 0;
_channelUpdates = parseChannelUpdates(result, offset);
}
}
uint32_t videoChannelMask = 0;
entry = av_dict_get(inStream->metadata, "ACTIVE_MASK", nullptr, 0);
if (entry && entry->value) {
std::string sourceString = (const char *)entry->value;
videoChannelMask = stringToUInt32(sourceString);
}
std::vector<std::string> endpointList;
entry = av_dict_get(inStream->metadata, "ENDPOINTS", nullptr, 0);
if (entry && entry->value) {
std::string sourceString = (const char *)entry->value;
endpointList = splitString(sourceString, ' ');
}
std::bitset<32> videoChannels(videoChannelMask);
size_t endpointIndex = 0;
if (videoChannels.count() == endpointList.size()) {
for (size_t i = 0; i < videoChannels.size(); i++) {
if (videoChannels[i]) {
_endpointMapping.insert(std::make_pair(endpointList[endpointIndex], i));
endpointIndex++;
}
}
}
}
break;
}
if (audioCodecParameters && audioStream) {
AVCodec *codec = avcodec_find_decoder(audioCodecParameters->codec_id);
if (codec) {
_codecContext = avcodec_alloc_context3(codec);
ret = avcodec_parameters_to_context(_codecContext, audioCodecParameters);
if (ret < 0) {
_didReadToEnd = true;
avcodec_free_context(&_codecContext);
_codecContext = nullptr;
} else {
_codecContext->pkt_timebase = audioStream->time_base;
_channelCount = _codecContext->channels;
ret = avcodec_open2(_codecContext, codec, nullptr);
if (ret < 0) {
_didReadToEnd = true;
avcodec_free_context(&_codecContext);
_codecContext = nullptr;
}
}
}
}
}
~AudioStreamingPartInternal() {
if (_frame) {
av_frame_unref(_frame);
}
if (_codecContext) {
avcodec_close(_codecContext);
avcodec_free_context(&_codecContext);
}
if (_inputFormatContext) {
avformat_close_input(&_inputFormatContext);
}
}
ReadPcmResult readPcm(std::vector<int16_t> &outPcm) {
int outPcmSampleOffset = 0;
ReadPcmResult result;
if (_channelCount == 0) {
RTC_LOG(LS_WARNING) << "ReadPcmResult readPcm: _channelCount == 0, returned.";
return result;
}
int readSamples = (int)outPcm.size() / _channelCount;
result.numChannels = _channelCount;
while (outPcmSampleOffset < readSamples) {
if (_pcmBufferSampleOffset >= _pcmBufferSampleSize) {
fillPcmBuffer();
if (_pcmBufferSampleOffset >= _pcmBufferSampleSize) {
break;
}
}
int readFromPcmBufferSamples = std::min(_pcmBufferSampleSize - _pcmBufferSampleOffset, readSamples - outPcmSampleOffset);
if (readFromPcmBufferSamples != 0) {
std::copy(_pcmBuffer.begin() + _pcmBufferSampleOffset * _channelCount, _pcmBuffer.begin() + _pcmBufferSampleOffset * _channelCount + readFromPcmBufferSamples * _channelCount, outPcm.begin() + outPcmSampleOffset * _channelCount);
_pcmBufferSampleOffset += readFromPcmBufferSamples;
outPcmSampleOffset += readFromPcmBufferSamples;
result.numSamples += readFromPcmBufferSamples;
}
}
return result;
}
int getDurationInMilliseconds() {
return _durationInMilliseconds;
}
int getChannelCount() {
return _channelCount;
}
std::vector<ChannelUpdate> const &getChannelUpdates() const {
return _channelUpdates;
}
std::map<std::string, int32_t> getEndpointMapping() const {
return _endpointMapping;
}
private:
static int16_t sampleFloatToInt16(float sample) {
return av_clip_int16 (static_cast<int32_t>(lrint(sample*32767)));
}
void fillPcmBuffer() {
_pcmBufferSampleSize = 0;
_pcmBufferSampleOffset = 0;
if (_didReadToEnd) {
return;
}
if (!_inputFormatContext) {
_didReadToEnd = true;
return;
}
if (!_codecContext) {
_didReadToEnd = true;
return;
}
int ret = 0;
do {
ret = av_read_frame(_inputFormatContext, &_packet);
if (ret < 0) {
_didReadToEnd = true;
return;
}
ret = avcodec_send_packet(_codecContext, &_packet);
if (ret < 0) {
_didReadToEnd = true;
return;
}
int bytesPerSample = av_get_bytes_per_sample(_codecContext->sample_fmt);
if (bytesPerSample != 2 && bytesPerSample != 4) {
_didReadToEnd = true;
return;
}
ret = avcodec_receive_frame(_codecContext, _frame);
} while (ret == AVERROR(EAGAIN));
if (ret != 0) {
_didReadToEnd = true;
return;
}
if (_frame->channels != _channelCount || _frame->channels > 8) {
_didReadToEnd = true;
return;
}
if (_pcmBuffer.size() < _frame->nb_samples * _frame->channels) {
_pcmBuffer.resize(_frame->nb_samples * _frame->channels);
}
switch (_codecContext->sample_fmt) {
case AV_SAMPLE_FMT_S16: {
memcpy(_pcmBuffer.data(), _frame->data[0], _frame->nb_samples * 2 * _frame->channels);
} break;
case AV_SAMPLE_FMT_S16P: {
int16_t *to = _pcmBuffer.data();
for (int sample = 0; sample < _frame->nb_samples; ++sample) {
for (int channel = 0; channel < _frame->channels; ++channel) {
int16_t *shortChannel = (int16_t*)_frame->data[channel];
*to++ = shortChannel[sample];
}
}
} break;
case AV_SAMPLE_FMT_FLT: {
float *floatData = (float *)&_frame->data[0];
for (int i = 0; i < _frame->nb_samples * _frame->channels; i++) {
_pcmBuffer[i] = sampleFloatToInt16(floatData[i]);
}
} break;
case AV_SAMPLE_FMT_FLTP: {
int16_t *to = _pcmBuffer.data();
for (int sample = 0; sample < _frame->nb_samples; ++sample) {
for (int channel = 0; channel < _frame->channels; ++channel) {
float *floatChannel = (float*)_frame->data[channel];
*to++ = sampleFloatToInt16(floatChannel[sample]);
}
}
} break;
default: {
//RTC_FATAL() << "Unexpected sample_fmt";
} break;
}
_pcmBufferSampleSize = _frame->nb_samples;
_pcmBufferSampleOffset = 0;
}
private:
AVIOContextImpl _avIoContext;
AVFormatContext *_inputFormatContext = nullptr;
AVPacket _packet;
AVCodecContext *_codecContext = nullptr;
AVFrame *_frame = nullptr;
bool _didReadToEnd = false;
int _durationInMilliseconds = 0;
int _channelCount = 0;
std::vector<ChannelUpdate> _channelUpdates;
std::map<std::string, int32_t> _endpointMapping;
std::vector<int16_t> _pcmBuffer;
int _pcmBufferSampleOffset = 0;
int _pcmBufferSampleSize = 0;
};
class AudioStreamingPartState {
struct ChannelMapping {
uint32_t ssrc = 0;
@ -474,15 +169,15 @@ class AudioStreamingPartState {
};
public:
AudioStreamingPartState(std::vector<uint8_t> &&data) :
_parsedPart(std::move(data)) {
if (_parsedPart.getChannelUpdates().size() == 0) {
AudioStreamingPartState(std::vector<uint8_t> &&data, std::string const &container, bool isSingleChannel) :
_isSingleChannel(isSingleChannel),
_parsedPart(std::move(data), container) {
if (_parsedPart.getChannelUpdates().size() == 0 && !isSingleChannel) {
_didReadToEnd = true;
return;
}
_remainingMilliseconds = _parsedPart.getDurationInMilliseconds();
_pcm10ms.resize(480 * _parsedPart.getChannelCount());
for (const auto &it : _parsedPart.getChannelUpdates()) {
_allSsrcs.insert(it.ssrc);
@ -500,7 +195,7 @@ public:
return _remainingMilliseconds;
}
std::vector<AudioStreamingPart::StreamingPartChannel> get10msPerChannel() {
std::vector<AudioStreamingPart::StreamingPartChannel> get10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder) {
if (_didReadToEnd) {
return {};
}
@ -511,30 +206,50 @@ public:
}
}
auto readResult = _parsedPart.readPcm(_pcm10ms);
auto readResult = _parsedPart.readPcm(persistentDecoder, _pcm10ms);
if (readResult.numSamples <= 0) {
_didReadToEnd = true;
return {};
}
std::vector<AudioStreamingPart::StreamingPartChannel> resultChannels;
for (const auto ssrc : _allSsrcs) {
AudioStreamingPart::StreamingPartChannel emptyPart;
emptyPart.ssrc = ssrc;
resultChannels.push_back(emptyPart);
}
for (auto &channel : resultChannels) {
auto mappedChannelIndex = getCurrentMappedChannelIndex(channel.ssrc);
if (_isSingleChannel) {
for (int i = 0; i < readResult.numChannels; i++) {
AudioStreamingPart::StreamingPartChannel emptyPart;
emptyPart.ssrc = i + 1;
resultChannels.push_back(emptyPart);
}
if (mappedChannelIndex) {
int sourceChannelIndex = mappedChannelIndex.value();
for (int i = 0; i < readResult.numChannels; i++) {
auto channel = resultChannels.begin() + i;
int sourceChannelIndex = i;
for (int j = 0; j < readResult.numSamples; j++) {
channel.pcmData.push_back(_pcm10ms[sourceChannelIndex + j * readResult.numChannels]);
channel->pcmData.push_back(_pcm10ms[sourceChannelIndex + j * readResult.numChannels]);
}
} else {
for (int j = 0; j < readResult.numSamples; j++) {
channel.pcmData.push_back(0);
channel->numSamples += readResult.numSamples;
}
} else {
for (const auto ssrc : _allSsrcs) {
AudioStreamingPart::StreamingPartChannel emptyPart;
emptyPart.ssrc = ssrc;
resultChannels.push_back(emptyPart);
}
for (auto &channel : resultChannels) {
auto mappedChannelIndex = getCurrentMappedChannelIndex(channel.ssrc);
if (mappedChannelIndex) {
int sourceChannelIndex = mappedChannelIndex.value();
for (int j = 0; j < readResult.numSamples; j++) {
channel.pcmData.push_back(_pcm10ms[sourceChannelIndex + j * readResult.numChannels]);
}
channel.numSamples += readResult.numSamples;
} else {
for (int j = 0; j < readResult.numSamples; j++) {
channel.pcmData.push_back(0);
}
channel.numSamples += readResult.numSamples;
}
}
}
@ -571,6 +286,7 @@ private:
}
private:
bool _isSingleChannel = false;
AudioStreamingPartInternal _parsedPart;
std::set<uint32_t> _allSsrcs;
@ -582,9 +298,9 @@ private:
bool _didReadToEnd = false;
};
AudioStreamingPart::AudioStreamingPart(std::vector<uint8_t> &&data) {
AudioStreamingPart::AudioStreamingPart(std::vector<uint8_t> &&data, std::string const &container, bool isSingleChannel) {
if (!data.empty()) {
_state = new AudioStreamingPartState(std::move(data));
_state = new AudioStreamingPartState(std::move(data), container, isSingleChannel);
}
}
@ -602,9 +318,9 @@ int AudioStreamingPart::getRemainingMilliseconds() const {
return _state ? _state->getRemainingMilliseconds() : 0;
}
std::vector<AudioStreamingPart::StreamingPartChannel> AudioStreamingPart::get10msPerChannel() {
std::vector<AudioStreamingPart::StreamingPartChannel> AudioStreamingPart::get10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder) {
return _state
? _state->get10msPerChannel()
? _state->get10msPerChannel(persistentDecoder)
: std::vector<AudioStreamingPart::StreamingPartChannel>();
}

View File

@ -3,9 +3,12 @@
#include "absl/types/optional.h"
#include <vector>
#include <string>
#include <map>
#include <stdint.h>
#include "AudioStreamingPartPersistentDecoder.h"
namespace tgcalls {
class AudioStreamingPartState;
@ -15,11 +18,12 @@ public:
struct StreamingPartChannel {
uint32_t ssrc = 0;
std::vector<int16_t> pcmData;
int numSamples = 0;
};
explicit AudioStreamingPart(std::vector<uint8_t> &&data);
explicit AudioStreamingPart(std::vector<uint8_t> &&data, std::string const &container, bool isSingleChannel);
~AudioStreamingPart();
AudioStreamingPart(const AudioStreamingPart&) = delete;
AudioStreamingPart(AudioStreamingPart&& other) {
_state = other._state;
@ -30,8 +34,8 @@ public:
std::map<std::string, int32_t> getEndpointMapping() const;
int getRemainingMilliseconds() const;
std::vector<StreamingPartChannel> get10msPerChannel();
std::vector<StreamingPartChannel> get10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder);
private:
AudioStreamingPartState *_state = nullptr;
};

View File

@ -0,0 +1,367 @@
#include "AudioStreamingPartInternal.h"
#include "rtc_base/logging.h"
#include "rtc_base/third_party/base64/base64.h"
extern "C" {
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
#include <string>
#include <bitset>
#include <set>
#include <map>
namespace tgcalls {
namespace {
int16_t sampleFloatToInt16(float sample) {
return av_clip_int16 (static_cast<int32_t>(lrint(sample*32767)));
}
uint32_t stringToUInt32(std::string const &string) {
std::stringstream stringStream(string);
uint32_t value = 0;
stringStream >> value;
return value;
}
template <typename Out>
void splitString(const std::string &s, char delim, Out result) {
std::istringstream iss(s);
std::string item;
while (std::getline(iss, item, delim)) {
*result++ = item;
}
}
std::vector<std::string> splitString(const std::string &s, char delim) {
std::vector<std::string> elems;
splitString(s, delim, std::back_inserter(elems));
return elems;
}
static absl::optional<uint32_t> readInt32(std::string const &data, int &offset) {
if (offset + 4 > data.length()) {
return absl::nullopt;
}
int32_t value = 0;
memcpy(&value, data.data() + offset, 4);
offset += 4;
return value;
}
std::vector<AudioStreamingPartInternal::ChannelUpdate> parseChannelUpdates(std::string const &data, int &offset) {
std::vector<AudioStreamingPartInternal::ChannelUpdate> result;
auto channels = readInt32(data, offset);
if (!channels) {
return {};
}
auto count = readInt32(data, offset);
if (!count) {
return {};
}
for (int i = 0; i < count.value(); i++) {
auto frameIndex = readInt32(data, offset);
if (!frameIndex) {
return {};
}
auto channelId = readInt32(data, offset);
if (!channelId) {
return {};
}
auto ssrc = readInt32(data, offset);
if (!ssrc) {
return {};
}
AudioStreamingPartInternal::ChannelUpdate update;
update.frameIndex = frameIndex.value();
update.id = channelId.value();
update.ssrc = ssrc.value();
result.push_back(update);
}
return result;
}
}
AudioStreamingPartInternal::AudioStreamingPartInternal(std::vector<uint8_t> &&fileData, std::string const &container) :
_avIoContext(std::move(fileData)) {
int ret = 0;
_frame = av_frame_alloc();
AVInputFormat *inputFormat = av_find_input_format(container.c_str());
if (!inputFormat) {
_didReadToEnd = true;
return;
}
_inputFormatContext = avformat_alloc_context();
if (!_inputFormatContext) {
_didReadToEnd = true;
return;
}
_inputFormatContext->pb = _avIoContext.getContext();
if ((ret = avformat_open_input(&_inputFormatContext, "", inputFormat, nullptr)) < 0) {
_didReadToEnd = true;
return;
}
if ((ret = avformat_find_stream_info(_inputFormatContext, nullptr)) < 0) {
_didReadToEnd = true;
avformat_close_input(&_inputFormatContext);
_inputFormatContext = nullptr;
return;
}
for (int i = 0; i < _inputFormatContext->nb_streams; i++) {
AVStream *inStream = _inputFormatContext->streams[i];
AVCodecParameters *inCodecpar = inStream->codecpar;
if (inCodecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
continue;
}
_audioCodecParameters = avcodec_parameters_alloc();
avcodec_parameters_copy(_audioCodecParameters, inCodecpar);
_streamId = i;
_durationInMilliseconds = (int)((inStream->duration + inStream->first_dts) * 1000 / 48000);
if (inStream->metadata) {
AVDictionaryEntry *entry = av_dict_get(inStream->metadata, "TG_META", nullptr, 0);
if (entry && entry->value) {
std::string result;
size_t data_used = 0;
std::string sourceBase64 = (const char *)entry->value;
rtc::Base64::Decode(sourceBase64, rtc::Base64::DO_LAX, &result, &data_used);
if (result.size() != 0) {
int offset = 0;
_channelUpdates = parseChannelUpdates(result, offset);
}
}
uint32_t videoChannelMask = 0;
entry = av_dict_get(inStream->metadata, "ACTIVE_MASK", nullptr, 0);
if (entry && entry->value) {
std::string sourceString = (const char *)entry->value;
videoChannelMask = stringToUInt32(sourceString);
}
std::vector<std::string> endpointList;
entry = av_dict_get(inStream->metadata, "ENDPOINTS", nullptr, 0);
if (entry && entry->value) {
std::string sourceString = (const char *)entry->value;
endpointList = splitString(sourceString, ' ');
}
std::bitset<32> videoChannels(videoChannelMask);
size_t endpointIndex = 0;
if (videoChannels.count() == endpointList.size()) {
for (size_t i = 0; i < videoChannels.size(); i++) {
if (videoChannels[i]) {
_endpointMapping.insert(std::make_pair(endpointList[endpointIndex], i));
endpointIndex++;
}
}
}
}
break;
}
if (_streamId == -1) {
_didReadToEnd = true;
}
}
AudioStreamingPartInternal::~AudioStreamingPartInternal() {
if (_frame) {
av_frame_unref(_frame);
}
if (_inputFormatContext) {
avformat_close_input(&_inputFormatContext);
}
if (_audioCodecParameters) {
avcodec_parameters_free(&_audioCodecParameters);
}
}
AudioStreamingPartInternal::ReadPcmResult AudioStreamingPartInternal::readPcm(AudioStreamingPartPersistentDecoder &persistentDecoder, std::vector<int16_t> &outPcm) {
if (_didReadToEnd) {
return AudioStreamingPartInternal::ReadPcmResult();
}
int outPcmSampleOffset = 0;
ReadPcmResult result;
if (_pcmBufferSampleOffset >= _pcmBufferSampleSize) {
fillPcmBuffer(persistentDecoder);
}
if (outPcm.size() != 480 * _channelCount) {
outPcm.resize(480 * _channelCount);
}
int readSamples = 0;
if (_channelCount != 0) {
readSamples = (int)outPcm.size() / _channelCount;
}
while (outPcmSampleOffset < readSamples) {
if (_pcmBufferSampleOffset >= _pcmBufferSampleSize) {
fillPcmBuffer(persistentDecoder);
if (_pcmBufferSampleOffset >= _pcmBufferSampleSize) {
break;
}
}
int readFromPcmBufferSamples = std::min(_pcmBufferSampleSize - _pcmBufferSampleOffset, readSamples - outPcmSampleOffset);
if (readFromPcmBufferSamples != 0) {
std::copy(_pcmBuffer.begin() + _pcmBufferSampleOffset * _channelCount, _pcmBuffer.begin() + _pcmBufferSampleOffset * _channelCount + readFromPcmBufferSamples * _channelCount, outPcm.begin() + outPcmSampleOffset * _channelCount);
_pcmBufferSampleOffset += readFromPcmBufferSamples;
outPcmSampleOffset += readFromPcmBufferSamples;
result.numSamples += readFromPcmBufferSamples;
_readSampleCount += readFromPcmBufferSamples;
}
}
result.numChannels = _channelCount;
// Uncomment for debugging incomplete frames
/*if (result.numSamples != 480 && result.numSamples != 0) {
RTC_LOG(LS_INFO) << "result.numSamples = " << result.numSamples << ", _readSampleCount = " << _readSampleCount << ", duration = " << _inputFormatContext->streams[_streamId]->duration;
}*/
return result;
}
int AudioStreamingPartInternal::getDurationInMilliseconds() const {
return _durationInMilliseconds;
}
std::vector<AudioStreamingPartInternal::ChannelUpdate> const &AudioStreamingPartInternal::getChannelUpdates() const {
return _channelUpdates;
}
std::map<std::string, int32_t> AudioStreamingPartInternal::getEndpointMapping() const {
return _endpointMapping;
}
void AudioStreamingPartInternal::fillPcmBuffer(AudioStreamingPartPersistentDecoder &persistentDecoder) {
_pcmBufferSampleSize = 0;
_pcmBufferSampleOffset = 0;
if (_didReadToEnd) {
return;
}
if (!_inputFormatContext) {
_didReadToEnd = true;
return;
}
int ret = 0;
while (true) {
ret = av_read_frame(_inputFormatContext, &_packet);
if (ret < 0) {
_didReadToEnd = true;
return;
}
if (_packet.stream_index != _streamId) {
continue;
}
ret = persistentDecoder.decode(_audioCodecParameters, _inputFormatContext->streams[_streamId]->time_base, _packet, _frame);
if (ret == AVERROR(EAGAIN)) {
continue;
}
break;
}
if (ret != 0) {
_didReadToEnd = true;
return;
}
if (_channelCount == 0) {
_channelCount = _frame->channels;
}
if (_channelCount == 0) {
_didReadToEnd = true;
return;
}
if (_frame->channels != _channelCount || _frame->channels > 8) {
_didReadToEnd = true;
return;
}
if (_pcmBuffer.size() < _frame->nb_samples * _frame->channels) {
_pcmBuffer.resize(_frame->nb_samples * _frame->channels);
}
switch (_frame->format) {
case AV_SAMPLE_FMT_S16: {
memcpy(_pcmBuffer.data(), _frame->data[0], _frame->nb_samples * 2 * _frame->channels);
} break;
case AV_SAMPLE_FMT_S16P: {
int16_t *to = _pcmBuffer.data();
for (int sample = 0; sample < _frame->nb_samples; ++sample) {
for (int channel = 0; channel < _frame->channels; ++channel) {
int16_t *shortChannel = (int16_t*)_frame->data[channel];
*to++ = shortChannel[sample];
}
}
} break;
case AV_SAMPLE_FMT_FLT: {
float *floatData = (float *)&_frame->data[0];
for (int i = 0; i < _frame->nb_samples * _frame->channels; i++) {
_pcmBuffer[i] = sampleFloatToInt16(floatData[i]);
}
} break;
case AV_SAMPLE_FMT_FLTP: {
int16_t *to = _pcmBuffer.data();
for (int sample = 0; sample < _frame->nb_samples; ++sample) {
for (int channel = 0; channel < _frame->channels; ++channel) {
float *floatChannel = (float*)_frame->data[channel];
*to++ = sampleFloatToInt16(floatChannel[sample]);
}
}
} break;
default: {
RTC_FATAL() << "Unexpected sample_fmt";
} break;
}
_pcmBufferSampleSize = _frame->nb_samples;
_pcmBufferSampleOffset = 0;
}
}

View File

@ -0,0 +1,65 @@
#ifndef TGCALLS_AUDIO_STREAMING_PART_INTERNAL_H
#define TGCALLS_AUDIO_STREAMING_PART_INTERNAL_H
#include "absl/types/optional.h"
#include <vector>
#include <string>
#include <map>
#include <stdint.h>
#include "AVIOContextImpl.h"
#include "AudioStreamingPartPersistentDecoder.h"
namespace tgcalls {
class AudioStreamingPartInternal {
public:
struct ReadPcmResult {
int numSamples = 0;
int numChannels = 0;
};
struct ChannelUpdate {
int frameIndex = 0;
int id = 0;
uint32_t ssrc = 0;
};
public:
AudioStreamingPartInternal(std::vector<uint8_t> &&fileData, std::string const &container);
~AudioStreamingPartInternal();
ReadPcmResult readPcm(AudioStreamingPartPersistentDecoder &persistentDecoder, std::vector<int16_t> &outPcm);
int getDurationInMilliseconds() const;
std::vector<ChannelUpdate> const &getChannelUpdates() const;
std::map<std::string, int32_t> getEndpointMapping() const;
private:
void fillPcmBuffer(AudioStreamingPartPersistentDecoder &persistentDecoder);
private:
AVIOContextImpl _avIoContext;
AVFormatContext *_inputFormatContext = nullptr;
AVPacket _packet;
AVFrame *_frame = nullptr;
AVCodecParameters *_audioCodecParameters = nullptr;
bool _didReadToEnd = false;
int _durationInMilliseconds = 0;
int _streamId = -1;
int _channelCount = 0;
std::vector<ChannelUpdate> _channelUpdates;
std::map<std::string, int32_t> _endpointMapping;
std::vector<int16_t> _pcmBuffer;
int _pcmBufferSampleOffset = 0;
int _pcmBufferSampleSize = 0;
int _readSampleCount = 0;
};
}
#endif

View File

@ -0,0 +1,122 @@
#include "AudioStreamingPartPersistentDecoder.h"
#include "rtc_base/logging.h"
#include "rtc_base/third_party/base64/base64.h"
namespace tgcalls {
WrappedCodecParameters::WrappedCodecParameters(AVCodecParameters const *codecParameters) {
_value = avcodec_parameters_alloc();
avcodec_parameters_copy(_value, codecParameters);
}
WrappedCodecParameters::~WrappedCodecParameters() {
avcodec_parameters_free(&_value);
}
bool WrappedCodecParameters::isEqual(AVCodecParameters const *other) {
if (_value->codec_id != other->codec_id) {
return false;
}
if (_value->format != other->format) {
return false;
}
if (_value->channels != other->channels) {
return false;
}
return true;
}
class AudioStreamingPartPersistentDecoderState {
public:
AudioStreamingPartPersistentDecoderState(AVCodecParameters const *codecParameters, AVRational timeBase) :
_codecParameters(codecParameters),
_timeBase(timeBase) {
AVCodec *codec = avcodec_find_decoder(codecParameters->codec_id);
if (codec) {
_codecContext = avcodec_alloc_context3(codec);
int ret = avcodec_parameters_to_context(_codecContext, codecParameters);
if (ret < 0) {
avcodec_free_context(&_codecContext);
_codecContext = nullptr;
} else {
_codecContext->pkt_timebase = timeBase;
_channelCount = _codecContext->channels;
ret = avcodec_open2(_codecContext, codec, nullptr);
if (ret < 0) {
avcodec_free_context(&_codecContext);
_codecContext = nullptr;
}
}
}
}
~AudioStreamingPartPersistentDecoderState() {
if (_codecContext) {
avcodec_free_context(&_codecContext);
}
}
int decode(AVPacket &packet, AVFrame *frame) {
int ret = avcodec_send_packet(_codecContext, &packet);
if (ret < 0) {
return ret;
}
int bytesPerSample = av_get_bytes_per_sample(_codecContext->sample_fmt);
if (bytesPerSample != 2 && bytesPerSample != 4) {
return -1;
}
ret = avcodec_receive_frame(_codecContext, frame);
return ret;
}
public:
WrappedCodecParameters _codecParameters;
AVRational _timeBase;
AVCodecContext *_codecContext = nullptr;
int _channelCount = 0;
};
AudioStreamingPartPersistentDecoder::AudioStreamingPartPersistentDecoder() {
}
AudioStreamingPartPersistentDecoder::~AudioStreamingPartPersistentDecoder() {
}
void AudioStreamingPartPersistentDecoder::maybeReset(AVCodecParameters const *codecParameters, AVRational timeBase) {
if (_state) {
bool isUpdated = false;
if (!_state->_codecParameters.isEqual(codecParameters)) {
isUpdated = true;
}
if (_state->_timeBase.num != timeBase.num || _state->_timeBase.den != timeBase.den) {
isUpdated = true;
}
if (!isUpdated) {
return;
}
}
if (_state) {
delete _state;
_state = nullptr;
}
_state = new AudioStreamingPartPersistentDecoderState(codecParameters, timeBase);
}
int AudioStreamingPartPersistentDecoder::decode(AVCodecParameters const *codecParameters, AVRational timeBase, AVPacket &packet, AVFrame *frame) {
maybeReset(codecParameters, timeBase);
if (!_state) {
return -1;
}
return _state->decode(packet, frame);
}
}

View File

@ -0,0 +1,51 @@
#ifndef TGCALLS_AUDIO_STREAMING_PART_PERSISTENT_DECODER_H
#define TGCALLS_AUDIO_STREAMING_PART_PERSISTENT_DECODER_H
#include "absl/types/optional.h"
#include <vector>
#include <string>
#include <map>
#include <stdint.h>
// Fix build on Windows - this should appear before FFmpeg timestamp include.
#define _USE_MATH_DEFINES
#include <math.h>
extern "C" {
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
namespace tgcalls {
class AudioStreamingPartPersistentDecoderState;
class WrappedCodecParameters {
public:
WrappedCodecParameters(AVCodecParameters const *codecParameters);
~WrappedCodecParameters();
bool isEqual(AVCodecParameters const *other);
private:
AVCodecParameters *_value = nullptr;
};
class AudioStreamingPartPersistentDecoder {
public:
AudioStreamingPartPersistentDecoder();
~AudioStreamingPartPersistentDecoder();
int decode(AVCodecParameters const *codecParameters, AVRational timeBase, AVPacket &packet, AVFrame *frame);
private:
void maybeReset(AVCodecParameters const *codecParameters, AVRational timeBase);
private:
AudioStreamingPartPersistentDecoderState *_state = nullptr;
};
}
#endif

View File

@ -24,18 +24,20 @@
#include "system_wrappers/include/field_trial.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "call/call.h"
#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "media/base/rtp_utils.h"
#include "api/call/audio_sink.h"
#include "modules/audio_processing/audio_buffer.h"
#include "absl/strings/match.h"
#include "modules/audio_processing/agc2/vad_with_level.h"
#include "modules/audio_processing/agc2/cpu_features.h"
#include "modules/audio_processing/agc2/vad_wrapper.h"
#include "pc/channel_manager.h"
#include "audio/audio_state.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/include/audio_coding_module.h"
#include "common_audio/include/audio_util.h"
#include "modules/audio_device/include/audio_device_data_observer.h"
#include "common_audio/resampler/include/resampler.h"
#include "modules/rtp_rtcp/source/rtp_util.h"
#include "AudioFrame.h"
#include "ThreadLocalObject.h"
@ -50,7 +52,9 @@
#include "AudioDeviceHelper.h"
#include "FakeAudioDeviceModule.h"
#include "StreamingMediaContext.h"
#ifdef WEBRTC_IOS
#include "platform/darwin/iOS/tgcalls_audio_device_module_ios.h"
#endif
#include <mutex>
#include <random>
#include <sstream>
@ -273,7 +277,7 @@ static std::vector<webrtc::SdpVideoFormat> filterSupportedVideoFormats(std::vect
return lhsLevelAssymetryAllowedPriority < rhsLevelAssymetryAllowedPriority;
}
return true;
return false;
});
filteredFormats.push_back(h264Formats[0]);
@ -467,15 +471,14 @@ public:
class CombinedVad {
private:
std::unique_ptr<webrtc::VadLevelAnalyzer> _vadWithLevel;
webrtc::VoiceActivityDetectorWrapper _vadWithLevel;
VadHistory _history;
bool _countFrames;
std::atomic<int32_t> _waitingFramesToProcess{0};
public:
CombinedVad(bool count = false){
_vadWithLevel = std::make_unique<webrtc::VadLevelAnalyzer>(500, webrtc::GetAvailableCpuFeatures());
_countFrames = count;
CombinedVad() :
_vadWithLevel(500, webrtc::GetAvailableCpuFeatures(), webrtc::AudioProcessing::kSampleRate48kHz) {
}
~CombinedVad() = default;
@ -489,25 +492,25 @@ public:
}
bool update(webrtc::AudioBuffer *buffer) {
if (buffer) {
if (_countFrames) {
_waitingFramesToProcess--;
}
if (buffer->num_channels() <= 0) {
return _history.update(0.0f);
}
webrtc::AudioFrameView<float> frameView(buffer->channels(), buffer->num_channels(), buffer->num_frames());
float peak = 0.0f;
for (const auto &x : frameView.channel(0)) {
peak = std::max(std::fabs(x), peak);
}
if (peak <= 0.01f) {
return _history.update(false);
}
auto result = _vadWithLevel->AnalyzeFrame(frameView);
return _history.update(result.speech_probability);
if (buffer->num_channels() <= 0) {
return _history.update(0.0f);
}
return _history.update(-1);
webrtc::AudioFrameView<float> frameView(buffer->channels(), (int)(buffer->num_channels()), (int)(buffer->num_frames()));
float peak = 0.0f;
for (const auto &x : frameView.channel(0)) {
peak = std::max(std::fabs(x), peak);
}
if (peak <= 0.01f) {
return _history.update(false);
}
auto result = _vadWithLevel.Analyze(frameView);
return _history.update(result);
}
bool update() {
return _history.update(0.0f);
}
};
@ -553,7 +556,7 @@ public:
AudioSinkImpl(std::function<void(Update)> update,
ChannelId channel_id, std::function<void(uint32_t, const AudioFrame &)> onAudioFrame) :
_update(update), _channel_id(channel_id), _onAudioFrame(std::move(onAudioFrame)) {
_vad = std::make_shared<CombinedVad>(true);
//_vad = std::make_shared<CombinedVad>(true);
}
virtual ~AudioSinkImpl() {
@ -620,7 +623,7 @@ public:
virtual void OnFrame(const webrtc::VideoFrame& frame) override {
std::unique_lock<std::mutex> lock{ _mutex };
/*int64_t timestamp = rtc::TimeMillis();
int64_t timestamp = rtc::TimeMillis();
if (_lastFrame) {
if (_lastFrame->video_frame_buffer()->width() != frame.video_frame_buffer()->width()) {
int64_t deltaTime = std::abs(_lastFrameSizeChangeTimestamp - timestamp);
@ -635,7 +638,7 @@ public:
_lastFrameSizeChangeHeight = 0;
_lastFrameSizeChangeTimestamp = timestamp;
}
_lastFrame = frame;*/
_lastFrame = frame;
for (int i = (int)(_sinks.size()) - 1; i >= 0; i--) {
auto strong = _sinks[i].lock();
if (!strong) {
@ -659,11 +662,10 @@ public:
}
void addSink(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> impl) {
std::unique_lock<std::mutex> lock{ _mutex };
_sinks.push_back(impl);
if (_lastFrame) {
auto strong = impl.lock();
if (strong) {
if (const auto strong = impl.lock()) {
std::unique_lock<std::mutex> lock{ _mutex };
_sinks.push_back(impl);
if (_lastFrame) {
strong->OnFrame(_lastFrame.value());
}
}
@ -1256,29 +1258,40 @@ public:
}
void mixAudio(int16_t *audio_samples, const size_t num_samples, const size_t num_channels, const uint32_t samples_per_sec) {
const auto numSamplesOut = num_samples * num_channels;
const auto numBytesOut = sizeof(int16_t) * numSamplesOut;
if (samples_per_sec != 48000) {
return;
}
if (_buffer.size() < numSamplesOut) {
_buffer.resize(numSamplesOut);
}
_mutex.Lock();
const auto context = _streamingContext;
_mutex.Unlock();
if (context) {
context->getAudio(_buffer.data(), num_samples, num_channels, samples_per_sec);
memcpy(audio_samples, _buffer.data(), numBytesOut);
if (_samplesToResample.size() < 480 * num_channels) {
_samplesToResample.resize(480 * num_channels);
}
memset(_samplesToResample.data(), 0, _samplesToResample.size() * sizeof(int16_t));
context->getAudio(_samplesToResample.data(), 480, num_channels, 48000);
if (_resamplerFrequency != samples_per_sec || _resamplerNumChannels != num_channels) {
_resamplerFrequency = samples_per_sec;
_resamplerNumChannels = num_channels;
_resampler = std::make_unique<webrtc::Resampler>();
if (_resampler->Reset(48000, samples_per_sec, num_channels) == -1) {
_resampler = nullptr;
}
}
if (_resampler) {
size_t outLen = 0;
_resampler->Push(_samplesToResample.data(), _samplesToResample.size(), (int16_t *)audio_samples, num_samples * num_channels, outLen);
}
}
}
private:
webrtc::Mutex _mutex;
std::vector<int16_t> _buffer;
std::unique_ptr<webrtc::Resampler> _resampler;
uint32_t _resamplerFrequency = 0;
size_t _resamplerNumChannels = 0;
std::vector<int16_t> _samplesToResample;
std::shared_ptr<StreamingMediaContext> _streamingContext;
};
@ -1303,12 +1316,16 @@ public:
const size_t bytes_per_sample,
const size_t num_channels,
const uint32_t samples_per_sec) override {
if (samples_per_sec != 48000) {
return;
}
if (bytes_per_sample != num_channels * 2) {
return;
}
if (samples_per_sec % 100 != 0) {
return;
}
if (num_samples != samples_per_sec / 100) {
return;
}
if (_shared) {
_shared->mixAudio((int16_t *)audio_samples, num_samples, num_channels, samples_per_sec);
}
@ -1318,6 +1335,48 @@ private:
std::shared_ptr<AudioDeviceDataObserverShared> _shared;
};
class CustomNetEqFactory: public webrtc::NetEqFactory {
public:
virtual ~CustomNetEqFactory() = default;
std::unique_ptr<webrtc::NetEq> CreateNetEq(
const webrtc::NetEq::Config& config,
const rtc::scoped_refptr<webrtc::AudioDecoderFactory>& decoder_factory, webrtc::Clock* clock
) const override {
webrtc::NetEq::Config updatedConfig = config;
updatedConfig.sample_rate_hz = 48000;
return webrtc::DefaultNetEqFactory().CreateNetEq(updatedConfig, decoder_factory, clock);
}
};
std::unique_ptr<webrtc::NetEqFactory> createNetEqFactory() {
return std::make_unique<CustomNetEqFactory>();
}
class CustomEchoDetector : public webrtc::EchoDetector {
public:
// (Re-)Initializes the submodule.
virtual void Initialize(int capture_sample_rate_hz,
int num_capture_channels,
int render_sample_rate_hz,
int num_render_channels) override {
}
// Analysis (not changing) of the render signal.
virtual void AnalyzeRenderAudio(rtc::ArrayView<const float> render_audio) override {
}
// Analysis (not changing) of the capture signal.
virtual void AnalyzeCaptureAudio(
rtc::ArrayView<const float> capture_audio) override {
}
// Collect current metrics from the echo detector.
virtual Metrics GetMetrics() const override {
return webrtc::EchoDetector::Metrics();
}
};
} // namespace
int GroupInstanceCustomImpl::customAudioBitrate = 0;
@ -1340,11 +1399,15 @@ public:
_useDummyChannel(descriptor.useDummyChannel),
_outgoingAudioBitrateKbit(descriptor.outgoingAudioBitrateKbit),
_disableOutgoingAudioProcessing(descriptor.disableOutgoingAudioProcessing),
#ifdef WEBRTC_IOS
_disableAudioInput(descriptor.disableAudioInput),
#endif
_minOutgoingVideoBitrateKbit(descriptor.minOutgoingVideoBitrateKbit),
_videoContentType(descriptor.videoContentType),
_videoCodecPreferences(std::move(descriptor.videoCodecPreferences)),
_eventLog(std::make_unique<webrtc::RtcEventLogNull>()),
_taskQueueFactory(webrtc::CreateDefaultTaskQueueFactory()),
_netEqFactory(createNetEqFactory()),
_createAudioDeviceModule(descriptor.createAudioDeviceModule),
_initialInputDeviceId(std::move(descriptor.initialInputDeviceId)),
_initialOutputDeviceId(std::move(descriptor.initialOutputDeviceId)),
@ -1407,7 +1470,8 @@ public:
<< "WebRTC-Audio-OpusMinPacketLossRate/Enabled-1/"
<< "WebRTC-TaskQueuePacer/Enabled/"
<< "WebRTC-VP8ConferenceTemporalLayers/1/"
<< "WebRTC-Audio-MinimizeResamplingOnMobile/Enabled/";
<< "WebRTC-Audio-MinimizeResamplingOnMobile/Enabled/"
<< "WebRTC-BweLossExperiment/Enabled/";
// << "WebRTC-MutedStateKillSwitch/Enabled/"
// << "WebRTC-VP8IosMaxNumberOfThread/max_thread:1/"
@ -1487,7 +1551,7 @@ public:
mediaDeps.audio_encoder_factory = webrtc::CreateAudioEncoderFactory<webrtc::AudioEncoderOpus, webrtc::AudioEncoderL16>();
mediaDeps.audio_decoder_factory = webrtc::CreateAudioDecoderFactory<webrtc::AudioDecoderOpus, webrtc::AudioDecoderL16>();
mediaDeps.video_encoder_factory = PlatformInterface::SharedInstance()->makeVideoEncoderFactory(_platformContext);
mediaDeps.video_encoder_factory = PlatformInterface::SharedInstance()->makeVideoEncoderFactory(_platformContext, false, _videoContentType == VideoContentType::Screencast);
mediaDeps.video_decoder_factory = PlatformInterface::SharedInstance()->makeVideoDecoderFactory(_platformContext);
#if USE_RNNOISE
@ -1495,6 +1559,8 @@ public:
webrtc::AudioProcessingBuilder builder;
builder.SetCapturePostProcessing(std::move(audioProcessor));
builder.SetEchoDetector(rtc::make_ref_counted<CustomEchoDetector>());
mediaDeps.audio_processing = builder.Create();
}
#endif
@ -1524,10 +1590,11 @@ public:
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this]() {
webrtc::Call::Config callConfig(_eventLog.get(), _threads->getNetworkThread());
callConfig.neteq_factory = _netEqFactory.get();
callConfig.task_queue_factory = _taskQueueFactory.get();
callConfig.trials = &_fieldTrials;
callConfig.audio_state = _channelManager->media_engine()->voice().GetAudioState();
_call.reset(webrtc::Call::Create(callConfig, _threads->getSharedModuleThread()));
_call.reset(webrtc::Call::Create(callConfig, webrtc::Clock::GetRealTimeClock(), _threads->getSharedModuleThread(), webrtc::ProcessThread::Create("PacerThread")));
});
_uniqueRandomIdGenerator.reset(new rtc::UniqueRandomIdGenerator());
@ -1656,11 +1723,11 @@ public:
incomingVideoDescription->set_codecs({ _selectedPayloadType->videoCodec, _selectedPayloadType->rtxCodec });
incomingVideoDescription->set_bandwidth(1300000);
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this, incomingVideoDescription, outgoingVideoDescription]() {
_outgoingVideoChannel->SetRemoteContent(incomingVideoDescription.get(), webrtc::SdpType::kAnswer, nullptr);
_outgoingVideoChannel->SetLocalContent(outgoingVideoDescription.get(), webrtc::SdpType::kOffer, nullptr);
_outgoingVideoChannel->SetPayloadTypeDemuxingEnabled(false);
});
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [&]() {
_outgoingVideoChannel->SetRemoteContent(incomingVideoDescription.get(), webrtc::SdpType::kAnswer, nullptr);
_outgoingVideoChannel->SetLocalContent(outgoingVideoDescription.get(), webrtc::SdpType::kOffer, nullptr);
_outgoingVideoChannel->SetPayloadTypeDemuxingEnabled(false);
});
adjustVideoSendParams();
updateVideoSend();
@ -1842,7 +1909,7 @@ public:
incomingAudioDescription->set_codecs({ opusCodec });
incomingAudioDescription->set_bandwidth(1300000);
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this, outgoingAudioDescription, incomingAudioDescription]() mutable {
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [&]() {
_outgoingAudioChannel->SetLocalContent(outgoingAudioDescription.get(), webrtc::SdpType::kOffer, nullptr);
_outgoingAudioChannel->SetRemoteContent(incomingAudioDescription.get(), webrtc::SdpType::kAnswer, nullptr);
_outgoingAudioChannel->SetPayloadTypeDemuxingEnabled(false);
@ -2148,11 +2215,9 @@ public:
void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer *buffer, int64_t packet_time_us) {
rtc::CopyOnWriteBuffer packet = *buffer;
_threads->getWorkerThread()->PostTask(ToQueuedTask(_workerThreadSafery, [this, packet, packet_time_us] {
if (_call) {
_call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, packet_time_us);
}
}));
if (_call) {
_call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, packet_time_us);
}
}
void adjustBitratePreferences(bool resetStartBitrate) {
@ -2264,39 +2329,29 @@ public:
}
}
webrtc::RtpUtility::RtpHeaderParser rtpParser(packet.data(), packet.size());
webrtc::RTPHeader header;
if (rtpParser.RTCP()) {
if (!rtpParser.ParseRtcp(&header)) {
RTC_LOG(LS_INFO) << "Could not parse rtcp header";
return;
}
if (webrtc::IsRtcpPacket(packet)) {
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this, packet]() {
_call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, -1);
});
} else {
if (!rtpParser.Parse(&header)) {
// Probably a data channel message
uint32_t ssrc = webrtc::ParseRtpSsrc(packet);
int payloadType = webrtc::ParseRtpPayloadType(packet);
if (ssrc == _outgoingAudioSsrc) {
return;
}
if (header.ssrc == _outgoingAudioSsrc) {
return;
}
auto ssrcInfo = _channelBySsrc.find(header.ssrc);
auto ssrcInfo = _channelBySsrc.find(ssrc);
if (ssrcInfo == _channelBySsrc.end()) {
// opus
if (header.payloadType == 111) {
maybeRequestUnknownSsrc(header.ssrc);
_missingPacketBuffer.add(header.ssrc, packet);
if (payloadType == 111) {
maybeRequestUnknownSsrc(ssrc);
_missingPacketBuffer.add(ssrc, packet);
}
} else {
switch (ssrcInfo->second.type) {
case ChannelSsrcInfo::Type::Audio: {
const auto it = _incomingAudioChannels.find(ChannelId(header.ssrc));
const auto it = _incomingAudioChannels.find(ChannelId(ssrc));
if (it != _incomingAudioChannels.end()) {
it->second->updateActivity();
}
@ -2566,10 +2621,11 @@ public:
});
}
void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) {
void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled, bool isUnifiedBroadcast) {
if (_connectionMode != connectionMode || connectionMode == GroupConnectionMode::GroupConnectionModeNone) {
GroupConnectionMode previousMode = _connectionMode;
_connectionMode = connectionMode;
_isUnifiedBroadcast = isUnifiedBroadcast;
onConnectionModeUpdated(previousMode, keepBroadcastIfWasEnabled);
}
}
@ -2623,6 +2679,7 @@ public:
const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this());
arguments.threads = _threads;
arguments.platformContext = _platformContext;
arguments.isUnifiedBroadcast = _isUnifiedBroadcast;
arguments.requestCurrentTime = _requestCurrentTime;
arguments.requestAudioBroadcastPart = _requestAudioBroadcastPart;
arguments.requestVideoBroadcastPart = _requestVideoBroadcastPart;
@ -2664,7 +2721,7 @@ public:
break;
}
default: {
//RTC_FATAL() << "Unknown connectionMode";
RTC_FATAL() << "Unknown connectionMode";
break;
}
}
@ -2931,6 +2988,14 @@ public:
_noiseSuppressionConfiguration->isEnabled = isNoiseSuppressionEnabled;
}
void addOutgoingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
_videoCaptureSink->addSink(sink);
if (_videoCapture) {
_videoCapture->setOutput(_videoCaptureSink);
}
}
void addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
if (_sharedVideoInformation && endpointId == _sharedVideoInformation->endpointId) {
if (_videoCapture) {
@ -2956,7 +3021,7 @@ public:
return;
}
if (_incomingAudioChannels.size() > 5) {
if (_incomingAudioChannels.size() > 10) {
auto timestamp = rtc::TimeMillis();
int64_t minActivity = INT64_MAX;
@ -2977,7 +3042,7 @@ public:
removeIncomingAudioChannel(minActivityChannelId);
}
if (_incomingAudioChannels.size() > 5) {
if (_incomingAudioChannels.size() > 10) {
// Wait until there is a channel that hasn't been active in 1 second
return;
}
@ -3240,10 +3305,17 @@ public:
private:
rtc::scoped_refptr<WrappedAudioDeviceModule> createAudioDeviceModule() {
auto audioDeviceDataObserverShared = _audioDeviceDataObserverShared;
#ifdef WEBRTC_IOS
bool disableRecording = _disableAudioInput;
#endif
const auto create = [&](webrtc::AudioDeviceModule::AudioLayer layer) {
#ifdef WEBRTC_IOS
return rtc::make_ref_counted<webrtc::tgcalls_ios_adm::AudioDeviceModuleIOS>(false, disableRecording);
#else
return webrtc::AudioDeviceModule::Create(
layer,
_taskQueueFactory.get());
#endif
};
const auto check = [&](const rtc::scoped_refptr<webrtc::AudioDeviceModule> &result) -> rtc::scoped_refptr<WrappedAudioDeviceModule> {
if (!result) {
@ -3278,6 +3350,7 @@ private:
private:
std::shared_ptr<Threads> _threads;
GroupConnectionMode _connectionMode = GroupConnectionMode::GroupConnectionModeNone;
bool _isUnifiedBroadcast = false;
std::function<void(GroupNetworkState)> _networkStateUpdated;
std::function<void(GroupLevelsUpdate const &)> _audioLevelsUpdated;
@ -3293,6 +3366,9 @@ private:
bool _useDummyChannel{true};
int _outgoingAudioBitrateKbit{32};
bool _disableOutgoingAudioProcessing{false};
#ifdef WEBRTC_IOS
bool _disableAudioInput{false};
#endif
int _minOutgoingVideoBitrateKbit{100};
VideoContentType _videoContentType{VideoContentType::None};
std::vector<VideoCodecName> _videoCodecPreferences;
@ -3304,6 +3380,7 @@ private:
std::unique_ptr<webrtc::RtcEventLogNull> _eventLog;
std::unique_ptr<webrtc::TaskQueueFactory> _taskQueueFactory;
std::unique_ptr<webrtc::NetEqFactory> _netEqFactory;
std::unique_ptr<cricket::MediaEngineInterface> _mediaEngine;
std::unique_ptr<webrtc::Call> _call;
webrtc::FieldTrialBasedConfig _fieldTrials;
@ -3412,9 +3489,9 @@ void GroupInstanceCustomImpl::stop() {
});
}
void GroupInstanceCustomImpl::setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) {
_internal->perform(RTC_FROM_HERE, [connectionMode, keepBroadcastIfWasEnabled](GroupInstanceCustomInternal *internal) {
internal->setConnectionMode(connectionMode, keepBroadcastIfWasEnabled);
void GroupInstanceCustomImpl::setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled, bool isUnifiedBroadcast) {
_internal->perform(RTC_FROM_HERE, [connectionMode, keepBroadcastIfWasEnabled, isUnifiedBroadcast](GroupInstanceCustomInternal *internal) {
internal->setConnectionMode(connectionMode, keepBroadcastIfWasEnabled, isUnifiedBroadcast);
});
}
@ -3484,6 +3561,12 @@ void GroupInstanceCustomImpl::addExternalAudioSamples(std::vector<uint8_t> &&sam
});
}
void GroupInstanceCustomImpl::addOutgoingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
_internal->perform(RTC_FROM_HERE, [sink](GroupInstanceCustomInternal *internal) mutable {
internal->addOutgoingVideoOutput(sink);
});
}
void GroupInstanceCustomImpl::addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
_internal->perform(RTC_FROM_HERE, [endpointId, sink](GroupInstanceCustomInternal *internal) mutable {
internal->addIncomingVideoOutput(endpointId, sink);

View File

@ -24,7 +24,7 @@ public:
void stop();
void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled);
void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled, bool isUnifiedBroadcast);
void emitJoinPayload(std::function<void(GroupJoinPayload const &)> completion);
void setJoinResponsePayload(std::string const &payload);
@ -39,6 +39,7 @@ public:
void setAudioInputDevice(std::string id);
void addExternalAudioSamples(std::vector<uint8_t> &&samples);
void addOutgoingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
void addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
void setVolume(uint32_t ssrc, double volume);

View File

@ -158,6 +158,7 @@ struct GroupInstanceDescriptor {
std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, int32_t, VideoChannelDescription::Quality, std::function<void(BroadcastPart &&)>)> requestVideoBroadcastPart;
int outgoingAudioBitrateKbit{32};
bool disableOutgoingAudioProcessing{false};
bool disableAudioInput{false};
VideoContentType videoContentType{VideoContentType::None};
bool initialEnableNoiseSuppression{false};
std::vector<VideoCodecName> videoCodecPreferences;
@ -179,7 +180,7 @@ public:
virtual void stop() = 0;
virtual void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) = 0;
virtual void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled, bool isUnifiedBroadcast) = 0;
virtual void emitJoinPayload(std::function<void(GroupJoinPayload const &)> completion) = 0;
virtual void setJoinResponsePayload(std::string const &payload) = 0;
@ -194,6 +195,7 @@ public:
virtual void setAudioInputDevice(std::string id) = 0;
virtual void addExternalAudioSamples(std::vector<uint8_t> &&samples) = 0;
virtual void addOutgoingVideoOutput(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0;
virtual void addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0;
virtual void setVolume(uint32_t ssrc, double volume) = 0;

View File

@ -13,8 +13,8 @@
#include "p2p/base/dtls_transport_factory.h"
#include "pc/dtls_srtp_transport.h"
#include "pc/dtls_transport.h"
#include "modules/rtp_rtcp/source/rtp_util.h"
#include "media/sctp/sctp_transport_factory.h"
#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "modules/rtp_rtcp/source/byte_io.h"
#include "platform/PlatformInterface.h"
#include "TurnCustomizerImpl.h"
@ -324,7 +324,7 @@ _audioActivityUpdated(audioActivityUpdated) {
_networkMonitorFactory = PlatformInterface::SharedInstance()->createNetworkMonitorFactory();
_socketFactory.reset(new rtc::BasicPacketSocketFactory(_threads->getNetworkThread()));
_socketFactory.reset(new rtc::BasicPacketSocketFactory(_threads->getNetworkThread()->socketserver()));
_networkManager = std::make_unique<rtc::BasicNetworkManager>(_networkMonitorFactory.get());
_asyncResolverFactory = std::make_unique<webrtc::BasicAsyncResolverFactory>();
@ -362,9 +362,9 @@ void GroupNetworkManager::resetDtlsSrtpTransport() {
_transportChannel.reset(new cricket::P2PTransportChannel("transport", 0, _portAllocator.get(), _asyncResolverFactory.get(), nullptr));
cricket::IceConfig iceConfig;
iceConfig.continual_gathering_policy = cricket::GATHER_ONCE;
iceConfig.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
iceConfig.prioritize_most_likely_candidate_pairs = true;
iceConfig.regather_on_failed_networks_interval = 8000;
iceConfig.regather_on_failed_networks_interval = 2000;
_transportChannel->SetIceConfig(iceConfig);
cricket::IceParameters localIceParameters(

View File

@ -11,6 +11,7 @@
#include "rtc_base/network_monitor_factory.h"
#include "api/candidate.h"
#include "media/base/media_channel.h"
#include "pc/sctp_transport.h"
#include "rtc_base/ssl_fingerprint.h"
#include "pc/sctp_data_channel.h"

View File

@ -11,7 +11,7 @@
#include "rtc_base/synchronization/mutex.h"
#include "common_audio/ring_buffer.h"
#include "modules/audio_mixer/frame_combiner.h"
#include "modules/audio_processing/agc2/vad_with_level.h"
#include "modules/audio_processing/agc2/vad_wrapper.h"
#include "modules/audio_processing/audio_buffer.h"
#include "api/video/video_sink_interface.h"
#include "audio/utility/audio_frame_operations.h"
@ -23,6 +23,9 @@ namespace {
struct PendingAudioSegmentData {
};
struct PendingUnifiedSegmentData {
};
struct PendingVideoSegmentData {
int32_t channelId = 0;
VideoChannelDescription::Quality quality = VideoChannelDescription::Quality::Thumbnail;
@ -42,7 +45,7 @@ struct PendingMediaSegmentPartResult {
};
struct PendingMediaSegmentPart {
absl::variant<PendingAudioSegmentData, PendingVideoSegmentData> typeData;
absl::variant<PendingAudioSegmentData, PendingVideoSegmentData, PendingUnifiedSegmentData> typeData;
int64_t minRequestTimestamp = 0;
@ -64,11 +67,21 @@ struct VideoSegment {
std::shared_ptr<PendingMediaSegmentPart> pendingVideoQualityUpdatePart;
};
struct UnifiedSegment {
std::shared_ptr<VideoStreamingPart> videoPart;
double lastFramePts = -1.0;
int _displayedFrames = 0;
bool isPlaying = false;
};
struct MediaSegment {
int64_t timestamp = 0;
int64_t duration = 0;
std::shared_ptr<AudioStreamingPart> audio;
AudioStreamingPartPersistentDecoder audioDecoder;
std::shared_ptr<VideoStreamingPart> unifiedAudio;
std::vector<std::shared_ptr<VideoSegment>> video;
std::vector<std::shared_ptr<UnifiedSegment>> unified;
};
class SampleRingBuffer {
@ -138,12 +151,12 @@ public:
class CombinedVad {
private:
std::unique_ptr<webrtc::VadLevelAnalyzer> _vadWithLevel;
webrtc::VoiceActivityDetectorWrapper _vadWithLevel;
VadHistory _history;
public:
CombinedVad() {
_vadWithLevel = std::make_unique<webrtc::VadLevelAnalyzer>(500, webrtc::GetAvailableCpuFeatures());
CombinedVad() :
_vadWithLevel(500, webrtc::GetAvailableCpuFeatures(), webrtc::AudioProcessing::kSampleRate48kHz) {
}
~CombinedVad() {
@ -153,7 +166,7 @@ public:
if (buffer->num_channels() <= 0) {
return _history.update(0.0f);
}
webrtc::AudioFrameView<float> frameView(buffer->channels(), buffer->num_channels(), buffer->num_frames());
webrtc::AudioFrameView<float> frameView(buffer->channels(), (int)(buffer->num_channels()), (int)(buffer->num_frames()));
float peak = 0.0f;
for (const auto &x : frameView.channel(0)) {
peak = std::max(std::fabs(x), peak);
@ -162,9 +175,9 @@ public:
return _history.update(false);
}
auto result = _vadWithLevel->AnalyzeFrame(frameView);
auto result = _vadWithLevel.Analyze(frameView);
return _history.update(result.speech_probability);
return _history.update(result);
}
bool update() {
@ -226,6 +239,7 @@ class StreamingMediaContextPrivate : public std::enable_shared_from_this<Streami
public:
StreamingMediaContextPrivate(StreamingMediaContext::StreamingMediaContextArguments &&arguments) :
_threads(arguments.threads),
_isUnifiedBroadcast(arguments.isUnifiedBroadcast),
_requestCurrentTime(arguments.requestCurrentTime),
_requestAudioBroadcastPart(arguments.requestAudioBroadcastPart),
_requestVideoBroadcastPart(arguments.requestVideoBroadcastPart),
@ -308,16 +322,38 @@ public:
}
}
for (auto &videoSegment : segment->unified) {
videoSegment->isPlaying = true;
auto frame = videoSegment->videoPart->getFrameAtRelativeTimestamp(relativeTimestamp);
if (frame) {
if (videoSegment->lastFramePts != frame->pts) {
videoSegment->lastFramePts = frame->pts;
videoSegment->_displayedFrames += 1;
auto sinkList = _videoSinks.find("unified");
if (sinkList != _videoSinks.end()) {
for (const auto &weakSink : sinkList->second) {
auto sink = weakSink.lock();
if (sink) {
sink->OnFrame(frame->frame);
}
}
}
}
}
}
if (segment->audio) {
const auto available = [&] {
_audioDataMutex.Lock();
const auto result = (_audioRingBuffer.availableForWriting() >= 480);
const auto result = (_audioRingBuffer.availableForWriting() >= 480 * _audioRingBufferNumChannels);
_audioDataMutex.Unlock();
return result;
};
while (available()) {
auto audioChannels = segment->audio->get10msPerChannel();
auto audioChannels = segment->audio->get10msPerChannel(segment->audioDecoder);
if (audioChannels.empty()) {
break;
}
@ -348,7 +384,90 @@ public:
}
_audioDataMutex.Lock();
_audioRingBuffer.write(frameOut.data(), frameOut.samples_per_channel());
if (frameOut.num_channels() == _audioRingBufferNumChannels) {
_audioRingBuffer.write(frameOut.data(), frameOut.samples_per_channel() * frameOut.num_channels());
} else {
if (_stereoShuffleBuffer.size() < frameOut.samples_per_channel() * _audioRingBufferNumChannels) {
_stereoShuffleBuffer.resize(frameOut.samples_per_channel() * _audioRingBufferNumChannels);
}
for (int i = 0; i < frameOut.samples_per_channel(); i++) {
for (int j = 0; j < _audioRingBufferNumChannels; j++) {
_stereoShuffleBuffer[i * _audioRingBufferNumChannels + j] = frameOut.data()[i];
}
}
_audioRingBuffer.write(_stereoShuffleBuffer.data(), frameOut.samples_per_channel() * _audioRingBufferNumChannels);
}
_audioDataMutex.Unlock();
}
} else if (segment->unifiedAudio) {
const auto available = [&] {
_audioDataMutex.Lock();
const auto result = (_audioRingBuffer.availableForWriting() >= 480);
_audioDataMutex.Unlock();
return result;
};
while (available()) {
auto audioChannels = segment->unifiedAudio->getAudio10msPerChannel(_persistentAudioDecoder);
if (audioChannels.empty()) {
break;
}
if (audioChannels[0].numSamples < 480) {
RTC_LOG(LS_INFO) << "render: got less than 10ms of audio data (" << audioChannels[0].numSamples << " samples)";
}
int numChannels = std::min(2, (int)audioChannels.size());
webrtc::AudioFrame frameOut;
if (numChannels == 1) {
frameOut.UpdateFrame(0, audioChannels[0].pcmData.data(), audioChannels[0].pcmData.size(), 48000, webrtc::AudioFrame::SpeechType::kNormalSpeech, webrtc::AudioFrame::VADActivity::kVadActive, numChannels);
} else {
bool skipFrame = false;
int numSamples = (int)audioChannels[0].pcmData.size();
for (int i = 1; i < numChannels; i++) {
if (audioChannels[i].pcmData.size() != numSamples) {
skipFrame = true;
break;
}
}
if (skipFrame) {
break;
}
if (_stereoShuffleBuffer.size() < numChannels * numSamples) {
_stereoShuffleBuffer.resize(numChannels * numSamples);
}
for (int i = 0; i < numSamples; i++) {
for (int j = 0; j < numChannels; j++) {
_stereoShuffleBuffer[i * numChannels + j] = audioChannels[0].pcmData[i];
}
}
frameOut.UpdateFrame(0, _stereoShuffleBuffer.data(), numSamples, 48000, webrtc::AudioFrame::SpeechType::kNormalSpeech, webrtc::AudioFrame::VADActivity::kVadActive, numChannels);
}
auto volumeIt = _volumeBySsrc.find(1);
if (volumeIt != _volumeBySsrc.end()) {
double outputGain = volumeIt->second;
if (outputGain < 0.99f || outputGain > 1.01f) {
webrtc::AudioFrameOperations::ScaleWithSat(outputGain, &frameOut);
}
}
_audioDataMutex.Lock();
if (frameOut.num_channels() == _audioRingBufferNumChannels) {
_audioRingBuffer.write(frameOut.data(), frameOut.samples_per_channel() * frameOut.num_channels());
} else {
if (_stereoShuffleBuffer.size() < frameOut.samples_per_channel() * _audioRingBufferNumChannels) {
_stereoShuffleBuffer.resize(frameOut.samples_per_channel() * _audioRingBufferNumChannels);
}
for (int i = 0; i < frameOut.samples_per_channel(); i++) {
for (int j = 0; j < _audioRingBufferNumChannels; j++) {
_stereoShuffleBuffer[i * _audioRingBufferNumChannels + j] = frameOut.data()[i];
}
}
_audioRingBuffer.write(_stereoShuffleBuffer.data(), frameOut.samples_per_channel() * _audioRingBufferNumChannels);
}
_audioDataMutex.Unlock();
}
}
@ -397,31 +516,31 @@ public:
_updateAudioLevel(ssrc, vadResult.first, vadResult.second);
}
void getAudio(int16_t *audio_samples, const size_t num_samples, const size_t num_channels, const uint32_t samples_per_sec) {
void getAudio(int16_t *audio_samples, size_t num_samples, size_t num_channels, uint32_t samples_per_sec) {
int16_t *buffer = nullptr;
if (num_channels == 1) {
if (num_channels == _audioRingBufferNumChannels) {
buffer = audio_samples;
} else {
if (_tempAudioBuffer.size() < num_samples) {
_tempAudioBuffer.resize(num_samples);
if (_tempAudioBuffer.size() < num_samples * _audioRingBufferNumChannels) {
_tempAudioBuffer.resize(num_samples * _audioRingBufferNumChannels);
}
buffer = _tempAudioBuffer.data();
}
_audioDataMutex.Lock();
size_t readSamples = _audioRingBuffer.read(buffer, num_samples);
size_t readSamples = _audioRingBuffer.read(buffer, num_samples * _audioRingBufferNumChannels);
_audioDataMutex.Unlock();
if (num_channels != 1) {
for (size_t sampleIndex = 0; sampleIndex < readSamples; sampleIndex++) {
if (num_channels != _audioRingBufferNumChannels) {
for (size_t sampleIndex = 0; sampleIndex < readSamples / _audioRingBufferNumChannels; sampleIndex++) {
for (size_t channelIndex = 0; channelIndex < num_channels; channelIndex++) {
audio_samples[sampleIndex * num_channels + channelIndex] = _tempAudioBuffer[sampleIndex];
audio_samples[sampleIndex * num_channels + channelIndex] = _tempAudioBuffer[sampleIndex * _audioRingBufferNumChannels + 0];
}
}
}
if (readSamples < num_samples) {
memset(audio_samples + readSamples * num_channels, 0, (num_samples - readSamples) * num_channels * sizeof(int16_t));
if (readSamples < num_samples * num_channels) {
memset(audio_samples + readSamples, 0, (num_samples * num_channels - readSamples) * sizeof(int16_t));
}
}
@ -449,10 +568,49 @@ public:
void requestSegmentsIfNeeded() {
while (true) {
if (_nextSegmentTimestamp == 0) {
if (_pendingSegments.size() >= 1) {
break;
if (_nextSegmentTimestamp == -1) {
if (!_pendingRequestTimeTask && _pendingRequestTimeDelayTaskId == 0) {
const auto weak = std::weak_ptr<StreamingMediaContextPrivate>(shared_from_this());
_pendingRequestTimeTask = _requestCurrentTime([weak, threads = _threads](int64_t timestamp) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, timestamp]() {
auto strong = weak.lock();
if (!strong) {
return;
}
strong->_pendingRequestTimeTask.reset();
int64_t adjustedTimestamp = 0;
if (timestamp > 0) {
adjustedTimestamp = (int64_t)((timestamp / strong->_segmentDuration * strong->_segmentDuration) - strong->_segmentBufferDuration);
}
if (adjustedTimestamp <= 0) {
int taskId = strong->_nextPendingRequestTimeDelayTaskId;
strong->_pendingRequestTimeDelayTaskId = taskId;
strong->_nextPendingRequestTimeDelayTaskId++;
strong->_threads->getMediaThread()->PostDelayedTask(RTC_FROM_HERE, [weak, taskId]() {
auto strong = weak.lock();
if (!strong) {
return;
}
if (strong->_pendingRequestTimeDelayTaskId != taskId) {
return;
}
strong->_pendingRequestTimeDelayTaskId = 0;
strong->requestSegmentsIfNeeded();
}, 1000);
} else {
strong->_nextSegmentTimestamp = adjustedTimestamp;
strong->requestSegmentsIfNeeded();
}
});
});
}
break;
} else {
int64_t availableAndRequestedSegmentsDuration = 0;
availableAndRequestedSegmentsDuration += getAvailableBufferDuration();
@ -466,12 +624,16 @@ public:
auto pendingSegment = std::make_shared<PendingMediaSegment>();
pendingSegment->timestamp = _nextSegmentTimestamp;
if (_nextSegmentTimestamp != 0) {
if (_nextSegmentTimestamp != -1) {
_nextSegmentTimestamp += _segmentDuration;
}
auto audio = std::make_shared<PendingMediaSegmentPart>();
audio->typeData = PendingAudioSegmentData();
if (_isUnifiedBroadcast) {
audio->typeData = PendingUnifiedSegmentData();
} else {
audio->typeData = PendingAudioSegmentData();
}
audio->minRequestTimestamp = 0;
pendingSegment->parts.push_back(audio);
@ -491,7 +653,7 @@ public:
_pendingSegments.push_back(pendingSegment);
if (_nextSegmentTimestamp == 0) {
if (_nextSegmentTimestamp == -1) {
break;
}
}
@ -556,7 +718,7 @@ public:
auto result = strongSegment->pendingVideoQualityUpdatePart->result;
if (result) {
strongSegment->part = std::make_shared<VideoStreamingPart>(std::move(result->data));
strongSegment->part = std::make_shared<VideoStreamingPart>(std::move(result->data), VideoStreamingPart::ContentType::Video);
}
strongSegment->pendingVideoQualityUpdatePart.reset();
@ -597,9 +759,6 @@ public:
if (!part->result && !part->task) {
if (part->minRequestTimestamp != 0) {
if (i != 0) {
continue;
}
if (part->minRequestTimestamp > absoluteTimestamp) {
minDelayedRequestTimeout = std::min(minDelayedRequestTimeout, part->minRequestTimestamp - absoluteTimestamp);
@ -631,14 +790,14 @@ public:
switch (part.status) {
case BroadcastPart::Status::Success: {
pendingPart->result = std::make_shared<PendingMediaSegmentPartResult>(std::move(part.data));
if (strong->_nextSegmentTimestamp == 0) {
if (strong->_nextSegmentTimestamp == -1) {
strong->_nextSegmentTimestamp = part.timestampMilliseconds + strong->_segmentDuration;
}
strong->checkPendingSegments();
break;
}
case BroadcastPart::Status::NotReady: {
if (segmentTimestamp == 0) {
if (segmentTimestamp == 0 && !strong->_isUnifiedBroadcast) {
int64_t responseTimestampMilliseconds = (int64_t)(part.responseTimestamp * 1000.0);
int64_t responseTimestampBoundary = (responseTimestampMilliseconds / strong->_segmentDuration) * strong->_segmentDuration;
@ -653,10 +812,15 @@ public:
break;
}
case BroadcastPart::Status::ResyncNeeded: {
int64_t responseTimestampMilliseconds = (int64_t)(part.responseTimestamp * 1000.0);
int64_t responseTimestampBoundary = (responseTimestampMilliseconds / strong->_segmentDuration) * strong->_segmentDuration;
if (strong->_isUnifiedBroadcast) {
strong->_nextSegmentTimestamp = -1;
} else {
int64_t responseTimestampMilliseconds = (int64_t)(part.responseTimestamp * 1000.0);
int64_t responseTimestampBoundary = (responseTimestampMilliseconds / strong->_segmentDuration) * strong->_segmentDuration;
strong->_nextSegmentTimestamp = responseTimestampBoundary;
}
strong->_nextSegmentTimestamp = responseTimestampBoundary;
strong->discardAllPendingSegments();
strong->requestSegmentsIfNeeded();
strong->checkPendingSegments();
@ -676,6 +840,8 @@ public:
part->task = _requestAudioBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, handleResult);
} else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) {
part->task = _requestVideoBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, videoData->channelId, videoData->quality, handleResult);
} else if (const auto unifiedData = absl::get_if<PendingUnifiedSegmentData>(typeData)) {
part->task = _requestVideoBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, 1, VideoChannelDescription::Quality::Full, handleResult);
}
}
}
@ -687,7 +853,7 @@ public:
for (auto &part : pendingSegment->parts) {
const auto typeData = &part->typeData;
if (const auto audioData = absl::get_if<PendingAudioSegmentData>(typeData)) {
segment->audio = std::make_shared<AudioStreamingPart>(std::move(part->result->data));
segment->audio = std::make_shared<AudioStreamingPart>(std::move(part->result->data), "ogg", false);
_currentEndpointMapping = segment->audio->getEndpointMapping();
} else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) {
auto videoSegment = std::make_shared<VideoSegment>();
@ -695,8 +861,17 @@ public:
if (part->result->data.empty()) {
RTC_LOG(LS_INFO) << "Video part " << segment->timestamp << " is empty";
}
videoSegment->part = std::make_shared<VideoStreamingPart>(std::move(part->result->data));
videoSegment->part = std::make_shared<VideoStreamingPart>(std::move(part->result->data), VideoStreamingPart::ContentType::Video);
segment->video.push_back(videoSegment);
} else if (const auto videoData = absl::get_if<PendingUnifiedSegmentData>(typeData)) {
auto unifiedSegment = std::make_shared<UnifiedSegment>();
if (part->result->data.empty()) {
RTC_LOG(LS_INFO) << "Unified part " << segment->timestamp << " is empty";
}
std::vector<uint8_t> dataCopy = part->result->data;
unifiedSegment->videoPart = std::make_shared<VideoStreamingPart>(std::move(part->result->data), VideoStreamingPart::ContentType::Video);
segment->unified.push_back(unifiedSegment);
segment->unifiedAudio = std::make_shared<VideoStreamingPart>(std::move(dataCopy), VideoStreamingPart::ContentType::Audio);
}
}
_availableSegments.push_back(segment);
@ -768,6 +943,8 @@ public:
part->task = _requestAudioBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, handleResult);
} else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) {
part->task = _requestVideoBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, videoData->channelId, videoData->quality, handleResult);
} else if (const auto unifiedData = absl::get_if<PendingUnifiedSegmentData>(typeData)) {
part->task = _requestVideoBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, 1, VideoChannelDescription::Quality::Full, handleResult);
}
}
@ -776,15 +953,10 @@ public:
}
void setActiveVideoChannels(std::vector<StreamingMediaContext::VideoChannel> const &videoChannels) {
_activeVideoChannels = videoChannels;
/*#if DEBUG
for (auto &updatedVideoChannel : _activeVideoChannels) {
if (updatedVideoChannel.quality == VideoChannelDescription::Quality::Medium) {
updatedVideoChannel.quality = VideoChannelDescription::Quality::Thumbnail;
}
if (_isUnifiedBroadcast) {
return;
}
#endif*/
_activeVideoChannels = videoChannels;
for (const auto &updatedVideoChannel : _activeVideoChannels) {
for (const auto &segment : _availableSegments) {
@ -809,6 +981,7 @@ public:
private:
std::shared_ptr<Threads> _threads;
bool _isUnifiedBroadcast = false;
std::function<std::shared_ptr<BroadcastPartTask>(std::function<void(int64_t)>)> _requestCurrentTime;
std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, std::function<void(BroadcastPart &&)>)> _requestAudioBroadcastPart;
std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, int32_t, VideoChannelDescription::Quality, std::function<void(BroadcastPart &&)>)> _requestVideoBroadcastPart;
@ -817,19 +990,26 @@ private:
const int _segmentDuration = 1000;
const int _segmentBufferDuration = 2000;
int64_t _nextSegmentTimestamp = 0;
int64_t _nextSegmentTimestamp = -1;
absl::optional<int> _waitForBufferredMillisecondsBeforeRendering;
std::vector<std::shared_ptr<MediaSegment>> _availableSegments;
AudioStreamingPartPersistentDecoder _persistentAudioDecoder;
std::shared_ptr<BroadcastPartTask> _pendingRequestTimeTask;
int _pendingRequestTimeDelayTaskId = 0;
int _nextPendingRequestTimeDelayTaskId = 0;
std::vector<std::shared_ptr<PendingMediaSegment>> _pendingSegments;
int64_t _playbackReferenceTimestamp = 0;
const size_t _audioDataRingBufferMaxSize = 4800;
const int _audioRingBufferNumChannels = 2;
const size_t _audioDataRingBufferMaxSize = 4800 * 2;
webrtc::Mutex _audioDataMutex;
SampleRingBuffer _audioRingBuffer;
std::vector<int16_t> _tempAudioBuffer;
std::vector<int16_t> _stereoShuffleBuffer;
webrtc::FrameCombiner _audioFrameCombiner;
std::map<uint32_t, std::unique_ptr<SparseVad>> _audioVadMap;
@ -838,7 +1018,7 @@ private:
std::map<std::string, std::vector<std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>>>> _videoSinks;
std::map<std::string, int32_t> _currentEndpointMapping;
std::shared_ptr<PlatformContext> _platformContext;
};

View File

@ -24,6 +24,7 @@ public:
public:
struct StreamingMediaContextArguments {
std::shared_ptr<Threads> threads;
bool isUnifiedBroadcast = false;
std::function<std::shared_ptr<BroadcastPartTask>(std::function<void(int64_t)>)> requestCurrentTime;
std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, std::function<void(BroadcastPart &&)>)> requestAudioBroadcastPart;
std::function<std::shared_ptr<BroadcastPartTask>(std::shared_ptr<PlatformContext>, int64_t, int64_t, int32_t, VideoChannelDescription::Quality, std::function<void(BroadcastPart &&)>)> requestVideoBroadcastPart;

View File

@ -4,11 +4,7 @@
#include "rtc_base/third_party/base64/base64.h"
#include "api/video/i420_buffer.h"
extern "C" {
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
#include "AVIOContextImpl.h"
#include <string>
#include <set>
@ -18,63 +14,6 @@ namespace tgcalls {
namespace {
class AVIOContextImpl {
public:
AVIOContextImpl(std::vector<uint8_t> &&fileData) :
_fileData(std::move(fileData)) {
_buffer.resize(4 * 1024);
_context = avio_alloc_context(_buffer.data(), (int)_buffer.size(), 0, this, &AVIOContextImpl::read, NULL, &AVIOContextImpl::seek);
}
~AVIOContextImpl() {
av_free(_context);
}
static int read(void *opaque, unsigned char *buffer, int bufferSize) {
AVIOContextImpl *instance = static_cast<AVIOContextImpl *>(opaque);
int bytesToRead = std::min(bufferSize, ((int)instance->_fileData.size()) - instance->_fileReadPosition);
if (bytesToRead < 0) {
bytesToRead = 0;
}
if (bytesToRead > 0) {
memcpy(buffer, instance->_fileData.data() + instance->_fileReadPosition, bytesToRead);
instance->_fileReadPosition += bytesToRead;
return bytesToRead;
} else {
return AVERROR_EOF;
}
}
static int64_t seek(void *opaque, int64_t offset, int whence) {
AVIOContextImpl *instance = static_cast<AVIOContextImpl *>(opaque);
if (whence == 0x10000) {
return (int64_t)instance->_fileData.size();
} else {
int64_t seekOffset = std::min(offset, (int64_t)instance->_fileData.size());
if (seekOffset < 0) {
seekOffset = 0;
}
instance->_fileReadPosition = (int)seekOffset;
return seekOffset;
}
}
AVIOContext *getContext() {
return _context;
}
private:
std::vector<uint8_t> _fileData;
int _fileReadPosition = 0;
std::vector<uint8_t> _buffer;
AVIOContext *_context = nullptr;
};
class MediaDataPacket {
public:
MediaDataPacket() : _packet(av_packet_alloc()) {
@ -312,8 +251,12 @@ absl::optional<VideoStreamInfo> consumeVideoStreamInfo(std::vector<uint8_t> &dat
}
if (const auto eventCount = readInt32(data, offset)) {
if (const auto event = readVideoStreamEvent(data, offset)) {
info.events.push_back(event.value());
if (eventCount > 0) {
if (const auto event = readVideoStreamEvent(data, offset)) {
info.events.push_back(event.value());
} else {
return absl::nullopt;
}
} else {
return absl::nullopt;
}
@ -499,7 +442,7 @@ public:
_frameIndex++;
return convertedFrame;
}
} else if (status == -35) {
} else if (status == AVERROR(EAGAIN)) {
// more data needed
} else {
_didReadToEnd = true;
@ -552,14 +495,29 @@ private:
class VideoStreamingPartState {
public:
VideoStreamingPartState(std::vector<uint8_t> &&data) {
VideoStreamingPartState(std::vector<uint8_t> &&data, VideoStreamingPart::ContentType contentType) {
_videoStreamInfo = consumeVideoStreamInfo(data);
if (!_videoStreamInfo) {
return;
}
for (size_t i = 0; i < _videoStreamInfo->events.size(); i++) {
std::vector<uint8_t> dataSlice(data.begin() + _videoStreamInfo->events[i].offset, i == (_videoStreamInfo->events.size() - 1) ? data.end() : (data.begin() + _videoStreamInfo->events[i + 1].offset));
if (_videoStreamInfo->events[i].offset < 0) {
continue;
}
size_t endOffset = 0;
if (i == _videoStreamInfo->events.size() - 1) {
endOffset = data.size();
} else {
endOffset = _videoStreamInfo->events[i + 1].offset;
}
if (endOffset <= _videoStreamInfo->events[i].offset) {
continue;
}
if (endOffset > data.size()) {
continue;
}
std::vector<uint8_t> dataSlice(data.begin() + _videoStreamInfo->events[i].offset, data.begin() + endOffset);
webrtc::VideoRotation rotation = webrtc::VideoRotation::kVideoRotation_0;
switch (_videoStreamInfo->events[i].rotation) {
case 0: {
@ -582,8 +540,24 @@ public:
break;
}
}
auto part = std::make_unique<VideoStreamingPartInternal>(_videoStreamInfo->events[i].endpointId, rotation, std::move(dataSlice), _videoStreamInfo->container);
_parsedParts.push_back(std::move(part));
switch (contentType) {
case VideoStreamingPart::ContentType::Audio: {
auto part = std::make_unique<AudioStreamingPart>(std::move(dataSlice), _videoStreamInfo->container, true);
_parsedAudioParts.push_back(std::move(part));
break;
}
case VideoStreamingPart::ContentType::Video: {
auto part = std::make_unique<VideoStreamingPartInternal>(_videoStreamInfo->events[i].endpointId, rotation, std::move(dataSlice), _videoStreamInfo->container);
_parsedVideoParts.push_back(std::move(part));
break;
}
default: {
break;
}
}
}
}
@ -593,13 +567,13 @@ public:
absl::optional<VideoStreamingPartFrame> getFrameAtRelativeTimestamp(double timestamp) {
while (true) {
if (!_currentFrame) {
if (!_parsedParts.empty()) {
auto result = _parsedParts[0]->getNextFrame();
if (!_parsedVideoParts.empty()) {
auto result = _parsedVideoParts[0]->getNextFrame();
if (result) {
_currentFrame = result;
_relativeTimestamp += result->duration;
} else {
_parsedParts.erase(_parsedParts.begin());
_parsedVideoParts.erase(_parsedVideoParts.begin());
continue;
}
}
@ -618,23 +592,49 @@ public:
}
absl::optional<std::string> getActiveEndpointId() const {
if (!_parsedParts.empty()) {
return _parsedParts[0]->endpointId();
if (!_parsedVideoParts.empty()) {
return _parsedVideoParts[0]->endpointId();
} else {
return absl::nullopt;
}
}
int getAudioRemainingMilliseconds() {
while (!_parsedAudioParts.empty()) {
auto firstPartResult = _parsedAudioParts[0]->getRemainingMilliseconds();
if (firstPartResult <= 0) {
_parsedAudioParts.erase(_parsedAudioParts.begin());
} else {
return firstPartResult;
}
}
return 0;
}
std::vector<AudioStreamingPart::StreamingPartChannel> getAudio10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder) {
while (!_parsedAudioParts.empty()) {
auto firstPartResult = _parsedAudioParts[0]->get10msPerChannel(persistentDecoder);
if (firstPartResult.empty()) {
_parsedAudioParts.erase(_parsedAudioParts.begin());
} else {
return firstPartResult;
}
}
return {};
}
private:
absl::optional<VideoStreamInfo> _videoStreamInfo;
std::vector<std::unique_ptr<VideoStreamingPartInternal>> _parsedParts;
std::vector<std::unique_ptr<VideoStreamingPartInternal>> _parsedVideoParts;
absl::optional<VideoStreamingPartFrame> _currentFrame;
double _relativeTimestamp = 0.0;
std::vector<std::unique_ptr<AudioStreamingPart>> _parsedAudioParts;
};
VideoStreamingPart::VideoStreamingPart(std::vector<uint8_t> &&data) {
VideoStreamingPart::VideoStreamingPart(std::vector<uint8_t> &&data, VideoStreamingPart::ContentType contentType) {
if (!data.empty()) {
_state = new VideoStreamingPartState(std::move(data));
_state = new VideoStreamingPartState(std::move(data), contentType);
}
}
@ -656,4 +656,15 @@ absl::optional<std::string> VideoStreamingPart::getActiveEndpointId() const {
: absl::nullopt;
}
int VideoStreamingPart::getAudioRemainingMilliseconds() {
return _state
? _state->getAudioRemainingMilliseconds()
: 0;
}
std::vector<AudioStreamingPart::StreamingPartChannel> VideoStreamingPart::getAudio10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder) {
return _state
? _state->getAudio10msPerChannel(persistentDecoder)
: std::vector<AudioStreamingPart::StreamingPartChannel>();
}
}

View File

@ -8,6 +8,9 @@
#include "api/video/video_frame.h"
#include "absl/types/optional.h"
#include "AudioStreamingPart.h"
#include "AudioStreamingPartInternal.h"
namespace tgcalls {
class VideoStreamingPartState;
@ -30,7 +33,13 @@ struct VideoStreamingPartFrame {
class VideoStreamingPart {
public:
explicit VideoStreamingPart(std::vector<uint8_t> &&data);
enum class ContentType {
Audio,
Video
};
public:
explicit VideoStreamingPart(std::vector<uint8_t> &&data, VideoStreamingPart::ContentType contentType);
~VideoStreamingPart();
VideoStreamingPart(const VideoStreamingPart&) = delete;
@ -44,6 +53,9 @@ public:
absl::optional<VideoStreamingPartFrame> getFrameAtRelativeTimestamp(double timestamp);
absl::optional<std::string> getActiveEndpointId() const;
int getAudioRemainingMilliseconds();
std::vector<AudioStreamingPart::StreamingPartChannel> getAudio10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder);
private:
VideoStreamingPartState *_state = nullptr;
};

View File

@ -303,8 +303,8 @@ public:
virtual std::unique_ptr<rtc::NetworkMonitorFactory> createNetworkMonitorFactory() {
return nullptr;
}
virtual std::unique_ptr<webrtc::VideoEncoderFactory> makeVideoEncoderFactory(std::shared_ptr<PlatformContext> platformContext) = 0;
virtual std::unique_ptr<webrtc::VideoEncoderFactory> makeVideoEncoderFactory(std::shared_ptr<PlatformContext> platformContext, bool preferHardwareEncoding = false, bool isScreencast = false) = 0;
virtual std::unique_ptr<webrtc::VideoDecoderFactory> makeVideoDecoderFactory(std::shared_ptr<PlatformContext> platformContext) = 0;
virtual bool supportsEncoding(const std::string &codecName, std::shared_ptr<PlatformContext> platformContext) = 0;
virtual rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> makeVideoSource(rtc::Thread *signalingThread, rtc::Thread *workerThread, bool screencapture) = 0;
@ -314,6 +314,8 @@ public:
return new rtc::RefCountedObject<DefaultWrappedAudioDeviceModule>(module);
}
public:
bool preferX264 = false;
};
std::unique_ptr<PlatformInterface> CreatePlatformInterface();

View File

@ -17,7 +17,7 @@
#include "sdk/android/native_api/video/video_source.h"
#include "api/video_codecs/builtin_video_encoder_factory.h"
#include "api/video_codecs/builtin_video_decoder_factory.h"
#include "api/video_track_source_proxy.h"
#include "api/video_track_source_proxy_factory.h"
#include "AndroidContext.h"
@ -27,7 +27,7 @@ void AndroidInterface::configurePlatformAudio() {
}
std::unique_ptr<webrtc::VideoEncoderFactory> AndroidInterface::makeVideoEncoderFactory(std::shared_ptr<PlatformContext> platformContext) {
std::unique_ptr<webrtc::VideoEncoderFactory> AndroidInterface::makeVideoEncoderFactory(std::shared_ptr<PlatformContext> platformContext, bool preferHardwareEncoding, bool isScreencast) {
JNIEnv *env = webrtc::AttachCurrentThreadIfNeeded();
AndroidContext *context = (AndroidContext *) platformContext.get();
@ -60,7 +60,7 @@ void AndroidInterface::adaptVideoSource(rtc::scoped_refptr<webrtc::VideoTrackSou
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> AndroidInterface::makeVideoSource(rtc::Thread *signalingThread, rtc::Thread *workerThread, bool screencapture) {
JNIEnv *env = webrtc::AttachCurrentThreadIfNeeded();
_source[screencapture ? 1 : 0] = webrtc::CreateJavaVideoSource(env, signalingThread, false, false);
return webrtc::VideoTrackSourceProxy::Create(signalingThread, workerThread, _source[screencapture ? 1 : 0]);
return webrtc::CreateVideoTrackSourceProxy(signalingThread, workerThread, _source[screencapture ? 1 : 0]);
}
bool AndroidInterface::supportsEncoding(const std::string &codecName, std::shared_ptr<PlatformContext> platformContext) {

View File

@ -10,7 +10,7 @@ namespace tgcalls {
class AndroidInterface : public PlatformInterface {
public:
void configurePlatformAudio() override;
std::unique_ptr<webrtc::VideoEncoderFactory> makeVideoEncoderFactory(std::shared_ptr<PlatformContext> platformContext) override;
std::unique_ptr<webrtc::VideoEncoderFactory> makeVideoEncoderFactory(std::shared_ptr<PlatformContext> platformContext, bool preferHardwareEncoding = false, bool isScreencast = false) override;
std::unique_ptr<webrtc::VideoDecoderFactory> makeVideoDecoderFactory(std::shared_ptr<PlatformContext> platformContext) override;
bool supportsEncoding(const std::string &codecName, std::shared_ptr<PlatformContext> platformContext) override;
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> makeVideoSource(rtc::Thread *signalingThread, rtc::Thread *workerThread, bool screencapture) override;

View File

@ -2,11 +2,11 @@
#include "api/video_codecs/builtin_video_encoder_factory.h"
#include "api/video_codecs/builtin_video_decoder_factory.h"
#include "api/video_track_source_proxy.h"
//#include "api/video_track_source_proxy.h"
namespace tgcalls {
std::unique_ptr<webrtc::VideoEncoderFactory> FakeInterface::makeVideoEncoderFactory() {
std::unique_ptr<webrtc::VideoEncoderFactory> FakeInterface::makeVideoEncoderFactory(bool preferHardwareEncoding, bool isScreencast) {
return webrtc::CreateBuiltinVideoEncoderFactory();
}

View File

@ -7,7 +7,7 @@ namespace tgcalls {
class FakeInterface : public PlatformInterface {
public:
std::unique_ptr<webrtc::VideoEncoderFactory> makeVideoEncoderFactory() override;
std::unique_ptr<webrtc::VideoEncoderFactory> makeVideoEncoderFactory(bool preferHardwareEncoding, bool isScreencast) override;
std::unique_ptr<webrtc::VideoDecoderFactory> makeVideoDecoderFactory() override;
bool supportsEncoding(const std::string &codecName) override;
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> makeVideoSource(rtc::Thread *signalingThread,

Some files were not shown because too many files have changed in this diff Show More