Update to 8.6.0

This commit is contained in:
xaxtix 2022-03-11 19:49:54 +03:00
parent 3708e9847a
commit d30f796d8c
2625 changed files with 166215 additions and 59265 deletions

View File

@ -300,7 +300,7 @@ android {
} }
} }
defaultConfig.versionCode = 2566 defaultConfig.versionCode = 2587
applicationVariants.all { variant -> applicationVariants.all { variant ->
variant.outputs.all { output -> variant.outputs.all { output ->
@ -319,7 +319,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 30 targetSdkVersion 30
versionName "8.5.4" versionName "8.6.0"
vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi'] vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi']

View File

@ -314,7 +314,7 @@ static inline void skip_remaining(GetBitContext *s, unsigned n)
*/ */
static inline unsigned int get_bits(GetBitContext *s, int n) static inline unsigned int get_bits(GetBitContext *s, int n)
{ {
register unsigned int tmp; unsigned int tmp;
#if CACHED_BITSTREAM_READER #if CACHED_BITSTREAM_READER
av_assert2(n>0 && n<=32); av_assert2(n>0 && n<=32);

View File

@ -54,7 +54,7 @@ static TexturedShape powerful_mask, powerful_infinity, powerful_infinity_white;
static Shape private_bg; static Shape private_bg;
static TexturedShape telegram_sphere, telegram_plane; static TexturedShape telegram_sphere, telegram_plane, telegram_mask;
static Shape cloud_bg; 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 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 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 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 free_knot_up_texture, free_knot_down_texture;
static GLuint powerful_mask_texture, powerful_star_texture, powerful_infinity_texture, powerful_infinity_white_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; static float calculated_speedometer_sin;
float ms0_anim; float ms0_anim;
int fps_anim; int fps_anim;
int last_stars_update_fps;
int count_anim_fps; int count_anim_fps;
static float speedometer_scroll_offset = 0, free_scroll_offset = 0, private_scroll_offset = 0; 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; 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; static mat4x4 private_matrix;
float cloud_scroll_offset; float cloud_scroll_offset;
vec4 background_color = {1, 1, 1, 1};
static inline void vec2_add(vec2 r, vec2 a, vec2 b) { static inline void vec2_add(vec2 r, vec2 a, vec2 b) {
int32_t i; int32_t i;
for (i = 0; i < 2; ++i) { for (i = 0; i < 2; ++i) {
@ -1122,6 +1125,8 @@ xyz star_initial_position(int32_t randZ, int32_t forward) {
} }
void draw_stars() { void draw_stars() {
int update = last_stars_update_fps != fps_anim;
last_stars_update_fps = fps_anim;
float k = (float) width / (float) height; float k = (float) width / (float) height;
set_y_offset_objects(-100 * k * 0); set_y_offset_objects(-100 * k * 0);
@ -1137,7 +1142,9 @@ void draw_stars() {
} }
float speed = stars_scroll_offset + transition_speed; 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) { if (stars[i].position.z > 0 && speed > 0) {
stars[i].position = star_initial_position(0, 1); 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); draw_textured_shape(&private_screw, private_matrix, NORMAL_ONE);
} }
JNIEXPORT void Java_org_telegram_messenger_Intro_onDrawFrame(JNIEnv *env, jclass class) { JNIEXPORT void Java_org_telegram_messenger_Intro_setBackgroundColor(JNIEnv *env, jclass class, jfloat r, jfloat g, jfloat b, jfloat a) {
time_local += 0.016f; 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) { if (current_page != prev_page) {
reset_ic(); 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) { if (count_anim_fps == 1 && date - ms0_anim >= duration_const) {
count_anim_fps = 0; count_anim_fps = 0;
} }
@ -1735,7 +1759,7 @@ JNIEXPORT void Java_org_telegram_messenger_Intro_onDrawFrame(JNIEnv *env, jclass
float private_back_k = .8; 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); 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); 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 tt = MINf(0, (float) (-M_PI * 125.0f / 180.0f + time * M_PI * 2 * 1.5f));
float dx = sinf(tt) * 75; float dx = t(-75, 0, 0, 0.15f, EaseIn);
float dy = -sinf(tt) * 60; float dy = t(75, 0, 0, 0.15f, EaseIn);
telegram_plane.params.position = xyzMake(dx, dy, 0); telegram_plane.params.position = xyzMake(dx, dy, 0);
float scale = (cosf(tt) + 1) * 0.5f; float scale = t(0.1f, 1, 0.03f, 0.15f, EaseOut);
telegram_plane.params.scale = xyzMake(cosf(tt) * scale, scale, 1); telegram_plane.params.scale = xyzMake(scale, scale, 1);
if (tt < D2R(125)) { if (tt < D2R(125)) {
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
draw_textured_shape(&telegram_plane, main_matrix, NORMAL_ONE); draw_textured_shape(&telegram_plane, main_matrix, NORMAL_ONE);
draw_textured_shape(&telegram_mask, main_matrix, NORMAL);
} }
} }
} else if (current_page == 1) { } 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; double tt = time * M_PI * 2 * 1.5f;
float dx = (float) sin(tt) * 75; float dx = t(0, 75, 0, 0.15f, EaseOut);
float dy = (float) -sin(tt) * 60; float dy = t(0, -75, 0, 0.15f, EaseOut);
telegram_plane.params.position = xyzMake(dx, dy, 0); telegram_plane.params.position = xyzMake(dx, dy, 0);
float scale = (float) (cos(tt) + 1) * 0.5f; float scale = t(1, 0.1f, 0.03f, 0.15f, EaseOut);
telegram_plane.params.scale = xyzMake(scale, scale, 1);
telegram_plane.params.scale = xyzMake((float) cos(tt) * scale, scale, 1);
if (tt < D2R(125)) { if (tt < D2R(125)) {
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
draw_textured_shape(&telegram_plane, main_matrix, NORMAL_ONE); draw_textured_shape(&telegram_plane, main_matrix, NORMAL_ONE);
draw_textured_shape(&telegram_mask, main_matrix, NORMAL);
} }
} }
} else if (current_page == 2) { } 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; 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_sphere_texture = a_telegram_sphere;
telegram_plane_texture = a_telegram_plane; 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) { 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); mask1 = create_rounded_rectangle(CSizeMake(60, 60), 0, 16, black_color);
telegram_sphere = create_textured_rectangle(CSizeMake(150, 150), telegram_sphere_texture); 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 = create_textured_rectangle(CSizeMake(82, 74), telegram_plane_texture);
telegram_plane.params.anchor = xyzMake(6, -5, 0); 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_mask3 = create_circle(1, cloud_polygons_count, black_color);
cloud_extra_mask4 = 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; cloud_cover.params.anchor.y = -50;
vec4 cloud_color = {42 / 255.0f, 180 / 255.0f, 247 / 255.0f, 1}; vec4 cloud_color = {42 / 255.0f, 180 / 255.0f, 247 / 255.0f, 1};

View File

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

View File

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

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_ASCONF_H_ #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 * 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); 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 *); struct sctp_tcb *, struct sctp_nets *, int *);
extern uint32_t extern uint32_t
sctp_addr_mgmt_ep_sa(struct sctp_inpcb *, struct sockaddr *, sctp_addr_mgmt_ep_sa(struct sctp_inpcb *, struct sockaddr *, uint32_t,
uint32_t, uint32_t, struct sctp_ifa *); uint32_t);
extern int sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, extern int sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr,
uint32_t val); uint32_t val);
@ -69,7 +68,6 @@ extern void sctp_asconf_iterator_stcb(struct sctp_inpcb *inp,
void *ptr, uint32_t type); void *ptr, uint32_t type);
extern void sctp_asconf_iterator_end(void *ptr, uint32_t val); extern void sctp_asconf_iterator_end(void *ptr, uint32_t val);
extern int32_t extern int32_t
sctp_set_primary_ip_address_sa(struct sctp_tcb *, sctp_set_primary_ip_address_sa(struct sctp_tcb *,
struct sockaddr *); struct sockaddr *);

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#include <netinet/sctp_os.h> #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) #define SCTP_AUTH_DEBUG2 (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_AUTH2)
#endif /* SCTP_DEBUG */ #endif /* SCTP_DEBUG */
void void
sctp_clear_chunklist(sctp_auth_chklist_t *chklist) sctp_clear_chunklist(sctp_auth_chklist_t *chklist)
{ {
@ -101,7 +100,6 @@ sctp_copy_chunklist(sctp_auth_chklist_t *list)
return (new_list); return (new_list);
} }
/* /*
* add a chunk to the required chunks 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); return (size);
} }
/* /*
* allocate structure space for a key of length keylen * 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); return (new_key);
} }
sctp_sharedkey_t * sctp_sharedkey_t *
sctp_alloc_sharedkey(void) sctp_alloc_sharedkey(void)
{ {
@ -567,11 +563,7 @@ sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t key_id)
} }
void void
sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t key_id, int so_locked 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_sharedkey_t *skey; sctp_sharedkey_t *skey;
@ -636,7 +628,6 @@ sctp_copy_skeylist(const struct sctp_keyhead *src, struct sctp_keyhead *dest)
return (count); return (count);
} }
sctp_hmaclist_t * sctp_hmaclist_t *
sctp_alloc_hmaclist(uint16_t num_hmacs) sctp_alloc_hmaclist(uint16_t num_hmacs)
{ {
@ -660,7 +651,6 @@ sctp_free_hmaclist(sctp_hmaclist_t *list)
{ {
if (list != NULL) { if (list != NULL) {
SCTP_FREE(list,SCTP_M_AUTH_HL); 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_??); */ /* SCTP_FREE(authinfo, SCTP_M_AUTH_??); */
} }
uint32_t uint32_t
sctp_get_auth_chunk_len(uint16_t hmac_algo) 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); return (0);
} }
/*- /*-
* clear any cached key(s) if they match the given key id on an association. * 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. * 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); m, auth_offset, auth->hmac);
} }
static void static void
sctp_zero_m(struct mbuf *m, uint32_t m_offset, uint32_t size) 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", "SCTP AUTH Chunk: shared key %u, HMAC id %u\n",
shared_key_id, hmac_id); shared_key_id, hmac_id);
#if defined(__Userspace__) && defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
return (0);
#endif
/* is the indicated HMAC supported? */ /* is the indicated HMAC supported? */
if (!sctp_auth_is_supported_hmac(stcb->asoc.local_hmacs, hmac_id)) { if (!sctp_auth_is_supported_hmac(stcb->asoc.local_hmacs, hmac_id)) {
struct mbuf *op_err; 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, (void)sctp_compute_hmac_m(hmac_id, stcb->asoc.authinfo.recv_key,
m, offset, computed_digest); 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 */ /* compare the computed digest with the one in the AUTH chunk */
if (timingsafe_bcmp(digest, computed_digest, digestlen) != 0) { if (timingsafe_bcmp(digest, computed_digest, digestlen) != 0) {
SCTP_STAT_INCR(sctps_recvauthfailed); SCTP_STAT_INCR(sctps_recvauthfailed);
@ -1750,11 +1735,7 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
*/ */
void void
sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication, sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication,
uint16_t keyid, uint16_t alt_keyid, int so_locked uint16_t keyid, uint16_t alt_keyid, int so_locked)
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
)
{ {
struct mbuf *m_notify; struct mbuf *m_notify;
struct sctp_authkey_event *auth; 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); &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, so_locked);
} }
/*- /*-
* validates the AUTHentication related parameters in an INIT/INIT-ACK * validates the AUTHentication related parameters in an INIT/INIT-ACK
* Note: currently only used for INIT as INIT-ACK is handled inline * 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; saw_asconf = 1;
if (chunks->chunk_types[i] == SCTP_ASCONF_ACK) if (chunks->chunk_types[i] == SCTP_ASCONF_ACK)
saw_asconf_ack = 1; saw_asconf_ack = 1;
} }
if (num_chunks) if (num_chunks)
got_chklist = 1; got_chklist = 1;

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_AUTH_H_ #ifndef _NETINET_SCTP_AUTH_H_
@ -99,8 +99,6 @@ typedef struct sctp_authinformation {
uint16_t recv_keyid; /* last recv keyid (cached) */ uint16_t recv_keyid; /* last recv keyid (cached) */
} sctp_authinfo_t; } sctp_authinfo_t;
/* /*
* Macros * 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, extern void sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t keyid,
int so_locked); int so_locked);
/* hmac list handling */ /* hmac list handling */
extern sctp_hmaclist_t *sctp_alloc_hmaclist(uint16_t num_hmacs); extern sctp_hmaclist_t *sctp_alloc_hmaclist(uint16_t num_hmacs);
extern void sctp_free_hmaclist(sctp_hmaclist_t *list); extern void sctp_free_hmaclist(sctp_hmaclist_t *list);

View File

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

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_BSD_ADDR_H_ #ifndef _NETINET_SCTP_BSD_ADDR_H_
@ -49,7 +49,6 @@ void sctp_wakeup_iterator(void);
void sctp_startup_iterator(void); void sctp_startup_iterator(void);
#ifdef INET6 #ifdef INET6
void sctp_gather_internal_ifa_flags(struct sctp_ifa *ifa); void sctp_gather_internal_ifa_flags(struct sctp_ifa *ifa);
#endif #endif
@ -61,10 +60,8 @@ int sctp_copy_out_packet_log(uint8_t *target, int length);
#endif #endif
#if !defined(__Panda__)
void sctp_addr_change(struct ifaddr *ifa, int cmd); void sctp_addr_change(struct ifaddr *ifa, int cmd);
#endif #if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(__FreeBSD__)
void sctp_addr_change_event_handler(void *, struct ifaddr *, int); void sctp_addr_change_event_handler(void *, struct ifaddr *, int);
#endif #endif

View File

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

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD$"); __FBSDID("$FreeBSD$");
#endif #endif
@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$");
#define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */ #define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */
#if defined(__Userspace__) #if defined(__Userspace__)
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
#define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx)) #define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_UNLOCK() LeaveCriticalSection(&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)) #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 */ #define SCTP_CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */
void sctp_os_timer_init(sctp_os_timer_t *tmr); 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 *); int sctp_os_timer_stop(sctp_os_timer_t *);
void sctp_handle_tick(uint32_t); void sctp_handle_tick(uint32_t);
#define SCTP_OS_TIMER_INIT sctp_os_timer_init #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_START sctp_os_timer_start
#define SCTP_OS_TIMER_STOP sctp_os_timer_stop #define SCTP_OS_TIMER_STOP sctp_os_timer_stop
/* MT FIXME: Is the following correct? */ /* 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) #define SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE)
#if defined(__Userspace__) #if defined(__Userspace__)
void sctp_start_timer(void); void sctp_start_timer_thread(void);
void sctp_stop_timer_thread(void);
#endif #endif
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
void sctp_timeout(void *); void sctp_timeout(void *);
#endif #endif

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 356660 2020-01-12 15:45:27Z tuexen $"); __FBSDID("$FreeBSD$");
#endif #endif
#include <netinet/sctp_os.h> #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_timer.h>
#include <netinet/sctp_auth.h> #include <netinet/sctp_auth.h>
#include <netinet/sctp_asconf.h> #include <netinet/sctp_asconf.h>
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/sctp_kdtrace.h> #include <netinet/sctp_kdtrace.h>
#endif #endif
@ -64,7 +64,7 @@ sctp_enforce_cwnd_limit(struct sctp_association *assoc, struct sctp_nets *net)
if ((assoc->max_cwnd > 0) && if ((assoc->max_cwnd > 0) &&
(net->cwnd > assoc->max_cwnd) && (net->cwnd > assoc->max_cwnd) &&
(net->cwnd > (net->mtu - sizeof(struct sctphdr)))) { (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))) { if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
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); sctp_enforce_cwnd_limit(assoc, net);
net->ssthresh = assoc->peers_rwnd; net->ssthresh = assoc->peers_rwnd;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, init, SDT_PROBE5(sctp, cwnd, net, init,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
0, net->cwnd); 0, net->cwnd);
@ -163,7 +163,6 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
(uint64_t)net->mtu * (uint64_t)net->mtu *
(uint64_t)net->ssthresh) / (uint64_t)net->ssthresh) /
(uint64_t)t_ssthresh); (uint64_t)t_ssthresh);
} }
if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) { if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) {
uint32_t srtt; uint32_t srtt;
@ -196,7 +195,7 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
} }
net->cwnd = net->ssthresh; net->cwnd = net->ssthresh;
sctp_enforce_cwnd_limit(asoc, net); sctp_enforce_cwnd_limit(asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, fr, SDT_PROBE5(sctp, cwnd, net, fr,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
old_cwnd, net->cwnd); 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_NEUTRAL 2 /* Neutral, no indication */
#define SCTP_INST_GAINING 3 /* Gaining, step down possible */ #define SCTP_INST_GAINING 3 /* Gaining, step down possible */
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
static int static int
cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, 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 #else
static int static int
cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, 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 #endif
{ {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint; uint64_t oth, probepoint;
#endif #endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32); probepoint = (((uint64_t)net->cwnd) << 32);
#endif #endif
if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) { 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 * we don't update bw.. so we don't
* update the rtt either. * update the rtt either.
*/ */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 5 */ /* Probe point 5 */
probepoint |= ((5 << 16) | 1); probepoint |= ((5 << 16) | 1);
SDT_PROBE5(sctp, cwnd, net, rttvar, 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) &&
((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) { ((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
/* Try a step down */ /* Try a step down */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce; oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16; oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt; 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 * we update both the bw and the rtt here to
* lock this in as a good step down. * lock this in as a good step down.
*/ */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 6 */ /* Probe point 6 */
probepoint |= ((6 << 16) | 0); probepoint |= ((6 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar, 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); probepoint);
#endif #endif
if (net->cc_mod.rtcc.steady_step) { 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 = net->cc_mod.rtcc.vol_reduce;
oth <<= 16; oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt; 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 /* 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 */ /* Probe point 7 */
probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq); probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
SDT_PROBE5(sctp, cwnd, net, rttvar, 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); return ((int)net->cc_mod.rtcc.ret_from_eq);
} }
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
static int static int
cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset, 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 #else
static int static int
cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset, 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 #endif
{ {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint; uint64_t oth, probepoint;
#endif #endif
/* Bandwidth decreased.*/ /* Bandwidth decreased.*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32); probepoint = (((uint64_t)net->cwnd) << 32);
#endif #endif
if (net->rtt > net->cc_mod.rtcc.lbw_rtt+rtt_offset) { 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) && if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
(inst_ind != SCTP_INST_LOOSING)) { (inst_ind != SCTP_INST_LOOSING)) {
/* We caused it maybe.. back off? */ /* We caused it maybe.. back off? */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
/* PROBE POINT 1 */ /* PROBE POINT 1 */
probepoint |= ((1 << 16) | 1); probepoint |= ((1 << 16) | 1);
SDT_PROBE5(sctp, cwnd, net, rttvar, 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); return (1);
} }
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 2 */ /* Probe point 2 */
probepoint |= ((2 << 16) | 0); probepoint |= ((2 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar, 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 #endif
/* Someone else - fight for more? */ /* Someone else - fight for more? */
if (net->cc_mod.rtcc.steady_step) { 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 = net->cc_mod.rtcc.vol_reduce;
oth <<= 16; oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt; 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; goto out_decision;
} else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) { } else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) {
/* bw & rtt decreased */ /* bw & rtt decreased */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 3 */ /* Probe point 3 */
probepoint |= ((3 << 16) | 0); probepoint |= ((3 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar, 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); probepoint);
#endif #endif
if (net->cc_mod.rtcc.steady_step) { 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 = net->cc_mod.rtcc.vol_reduce;
oth <<= 16; oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt; 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; goto out_decision;
} }
/* The bw decreased but rtt stayed the same */ /* The bw decreased but rtt stayed the same */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 4 */ /* Probe point 4 */
probepoint |= ((4 << 16) | 0); probepoint |= ((4 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar, 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); probepoint);
#endif #endif
if (net->cc_mod.rtcc.steady_step) { 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 = net->cc_mod.rtcc.vol_reduce;
oth <<= 16; oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt; 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 static int
cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag) cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
#else #else
@ -576,7 +574,7 @@ static int
cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw) cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw)
#endif #endif
{ {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint; uint64_t oth, probepoint;
#endif #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 * update. Note that we pay no attention to
* the inst_ind since our overall sum is increasing. * the inst_ind since our overall sum is increasing.
*/ */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
/* PROBE POINT 0 */ /* PROBE POINT 0 */
probepoint = (((uint64_t)net->cwnd) << 32); probepoint = (((uint64_t)net->cwnd) << 32);
SDT_PROBE5(sctp, cwnd, net, rttvar, 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); probepoint);
#endif #endif
if (net->cc_mod.rtcc.steady_step) { 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 = net->cc_mod.rtcc.vol_reduce;
oth <<= 16; oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt; 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) cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
{ {
uint64_t bw_offset, rtt_offset; uint64_t bw_offset, rtt_offset;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t probepoint, rtt, vtag; uint64_t probepoint, rtt, vtag;
#endif #endif
uint64_t bytes_for_this_rtt, inst_bw; 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 * change within 1/32nd
*/ */
bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw); bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
rtt = stcb->asoc.my_vtag; rtt = stcb->asoc.my_vtag;
vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
probepoint = (((uint64_t)net->cwnd) << 32); 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; inst_ind = SCTP_INST_LOOSING;
else else
inst_ind = SCTP_INST_NEUTRAL; inst_ind = SCTP_INST_NEUTRAL;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint |= ((0xb << 16) | inst_ind); probepoint |= ((0xb << 16) | inst_ind);
#endif #endif
} else { } else {
inst_ind = net->cc_mod.rtcc.last_inst_ind; 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); inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt);
/* Can't determine do not change */ /* Can't determine do not change */
probepoint |= ((0xc << 16) | inst_ind); probepoint |= ((0xc << 16) | inst_ind);
@ -707,13 +705,13 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
} }
} else { } else {
inst_ind = net->cc_mod.rtcc.last_inst_ind; 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; inst_bw = bytes_for_this_rtt;
/* Can't determine do not change */ /* Can't determine do not change */
probepoint |= ((0xd << 16) | inst_ind); probepoint |= ((0xd << 16) | inst_ind);
#endif #endif
} }
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, rttvar, SDT_PROBE5(sctp, cwnd, net, rttvar,
vtag, vtag,
((nbw << 32) | inst_bw), ((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; bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
if (nbw > net->cc_mod.rtcc.lbw + bw_offset) { 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); ret = cc_bw_increase(stcb, net, nbw, vtag);
#else #else
ret = cc_bw_increase(stcb, net, nbw); 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); rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
if (nbw < net->cc_mod.rtcc.lbw - bw_offset) { 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); ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
#else #else
ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, inst_ind); 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 * we are in a situation where
* the bw stayed the same. * 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); ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
#else #else
ret = cc_bw_same(stcb, net, nbw, rtt_offset, inst_ind); 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) int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
{ {
struct sctp_nets *net; struct sctp_nets *net;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
int old_cwnd; int old_cwnd;
#endif #endif
uint32_t t_ssthresh, t_cwnd, incr; uint32_t t_ssthresh, incr;
uint64_t t_ucwnd_sbw; uint64_t t_ucwnd_sbw;
uint64_t t_path_mptcp; uint64_t t_path_mptcp;
uint64_t mptcp_like_alpha; 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 */ /* MT FIXME: Don't compute this over and over again */
t_ssthresh = 0; t_ssthresh = 0;
t_cwnd = 0;
t_ucwnd_sbw = 0; t_ucwnd_sbw = 0;
t_path_mptcp = 0; t_path_mptcp = 0;
mptcp_like_alpha = 1; mptcp_like_alpha = 1;
@ -785,7 +782,6 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
max_path = 0; max_path = 0;
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
t_ssthresh += net->ssthresh; t_ssthresh += net->ssthresh;
t_cwnd += net->cwnd;
/* lastsa>>3; we don't need to devide ...*/ /* lastsa>>3; we don't need to devide ...*/
srtt = net->lastsa; srtt = net->lastsa;
if (srtt > 0) { if (srtt > 0) {
@ -817,7 +813,6 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
/* update cwnd and Early FR */ /* update cwnd and Early FR */
/******************************/ /******************************/
TAILQ_FOREACH(net, &asoc->nets, sctp_next) { TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
#ifdef JANA_CMT_FAST_RECOVERY #ifdef JANA_CMT_FAST_RECOVERY
/* /*
* CMT fast recovery code. Need to debug. * CMT fast recovery code. Need to debug.
@ -837,7 +832,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
continue; continue;
} }
#ifdef JANA_CMT_FAST_RECOVERY #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) { 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; continue;
} }
} else { } else {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t vtag, probepoint; uint64_t vtag, probepoint;
probepoint = (((uint64_t)net->cwnd) << 32); 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) { if (net->flight_size + net->net_ack >= net->cwnd) {
uint32_t limit; uint32_t limit;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
old_cwnd = net->cwnd; old_cwnd = net->cwnd;
#endif #endif
switch (asoc->sctp_cmt_on_off) { 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_log_cwnd(stcb, net, incr,
SCTP_CWND_LOG_FROM_SS); SCTP_CWND_LOG_FROM_SS);
} }
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack, SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag, stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), ((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; net->partial_bytes_acked += net->net_ack;
if ((net->flight_size + net->net_ack >= net->cwnd) && 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; net->partial_bytes_acked -= net->cwnd;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
old_cwnd = net->cwnd; old_cwnd = net->cwnd;
#endif #endif
switch (asoc->sctp_cmt_on_off) { switch (asoc->sctp_cmt_on_off) {
@ -1051,7 +1046,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
} }
net->cwnd += incr; net->cwnd += incr;
sctp_enforce_cwnd_limit(asoc, net); sctp_enforce_cwnd_limit(asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack, SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag, stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), ((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 static void
sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net) sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
#else #else
@ -1086,13 +1081,13 @@ static void
sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net) sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net)
#endif #endif
{ {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
int old_cwnd; int old_cwnd;
old_cwnd = net->cwnd; old_cwnd = net->cwnd;
#endif #endif
net->cwnd = net->mtu; net->cwnd = net->mtu;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack, SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net, stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
old_cwnd, net->cwnd); 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); (void *)net, net->cwnd);
} }
static void static void
sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net) 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->cwnd = net->mtu;
net->partial_bytes_acked = 0; net->partial_bytes_acked = 0;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, to, SDT_PROBE5(sctp, cwnd, net, to,
stcb->asoc.my_vtag, stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), ((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 static void
sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *net, 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; int old_cwnd = net->cwnd;
if ((use_rtcc) && (net->lan_type == SCTP_LAN_LOCAL) && (net->cc_mod.rtcc.use_dccc_ecn)) { 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) { 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_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
} }
} }
SCTP_STAT_INCR(sctps_ecnereducedcwnd); SCTP_STAT_INCR(sctps_ecnereducedcwnd);
} else { } else {
if (in_window == 0) { if (in_window == 0) {
SCTP_STAT_INCR(sctps_ecnereducedcwnd); SCTP_STAT_INCR(sctps_ecnereducedcwnd);
net->ssthresh = net->cwnd / 2; 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->RTO <<= 1;
} }
net->cwnd = net->ssthresh; net->cwnd = net->ssthresh;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ecn, SDT_PROBE5(sctp, cwnd, net, ecn,
stcb->asoc.my_vtag, stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), ((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); sctp_enforce_cwnd_limit(&stcb->asoc, net);
if (net->cwnd - old_cwnd != 0) { if (net->cwnd - old_cwnd != 0) {
/* log only changes */ /* log only changes */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, pd, SDT_PROBE5(sctp, cwnd, net, pd,
stcb->asoc.my_vtag, stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1357,7 +1350,7 @@ sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
static void static void
sctp_cwnd_update_after_output(struct sctp_tcb *stcb, 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; int old_cwnd = net->cwnd;
@ -1366,7 +1359,7 @@ sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
if (burst_limit) { if (burst_limit) {
net->cwnd = (net->flight_size + (burst_limit * net->mtu)); net->cwnd = (net->flight_size + (burst_limit * net->mtu));
sctp_enforce_cwnd_limit(&stcb->asoc, net); sctp_enforce_cwnd_limit(&stcb->asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, bl, SDT_PROBE5(sctp, cwnd, net, bl,
stcb->asoc.my_vtag, stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1381,8 +1374,8 @@ sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
static void static void
sctp_cwnd_update_after_sack(struct sctp_tcb *stcb, sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
struct sctp_association *asoc, struct sctp_association *asoc,
int accum_moved, int reneged_all, int will_exit) int accum_moved, int reneged_all, int will_exit)
{ {
/* Passing a zero argument in last disables the rtcc algorithm */ /* 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); 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 static void
sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, 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 */ /* 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); 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 static void
sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net, 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); 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,
static struct sctp_tmit_chunk *tp1)
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; net->cc_mod.rtcc.bw_bytes += tp1->send_size;
} }
static void static void
sctp_cwnd_prepare_rtcc_net_for_sack(struct sctp_tcb *stcb SCTP_UNUSED, 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) { if (net->cc_mod.rtcc.tls_needs_set > 0) {
/* We had a bw measurment going on */ /* 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 static void
sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb, 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; uint64_t vtag, probepoint;
#endif #endif
if (net->cc_mod.rtcc.lbw) { 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 */ /* Clear the old bw.. we went to 0 in-flight */
vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
(stcb->rport); (stcb->rport);
@ -1492,15 +1483,15 @@ sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
static void static void
sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb, 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; uint64_t vtag, probepoint;
#endif #endif
sctp_set_initial_cc_param(stcb, net); sctp_set_initial_cc_param(stcb, net);
stcb->asoc.use_precise_time = 1; stcb->asoc.use_precise_time = 1;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000 #if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32); probepoint = (((uint64_t)net->cwnd) << 32);
probepoint |= ((9 << 16) | 0); probepoint |= ((9 << 16) | 0);
vtag = (net->rtt << 32) | 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.use_dccc_ecn = SCTP_BASE_SYSCTL(sctp_use_dccc_ecn);
net->cc_mod.rtcc.step_cnt = 0; net->cc_mod.rtcc.step_cnt = 0;
net->cc_mod.rtcc.last_step_state = 0; net->cc_mod.rtcc.last_step_state = 0;
} }
static int static int
sctp_cwnd_rtcc_socket_option(struct sctp_tcb *stcb, int setorget, 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; struct sctp_nets *net;
if (setorget == 1) { if (setorget == 1) {
/* a set */ /* a set */
if (cc_opt->option == SCTP_CC_OPT_RTCC_SETMODE) { 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 static void
sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb, sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
struct sctp_association *asoc, struct sctp_association *asoc,
int accum_moved, int reneged_all, int will_exit) int accum_moved, int reneged_all, int will_exit)
{ {
/* Passing a one argument at the last enables the rtcc algorithm */ /* 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); 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 static void
sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb, sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
struct sctp_association *asoc, struct sctp_association *asoc,
int accum_moved, int reneged_all SCTP_UNUSED, int will_exit) int accum_moved, int reneged_all SCTP_UNUSED, int will_exit)
{ {
struct sctp_nets *net; struct sctp_nets *net;
/******************************/ /******************************/
/* update cwnd and Early FR */ /* update cwnd and Early FR */
/******************************/ /******************************/
TAILQ_FOREACH(net, &asoc->nets, sctp_next) { TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
#ifdef JANA_CMT_FAST_RECOVERY #ifdef JANA_CMT_FAST_RECOVERY
/* /*
* CMT fast recovery code. Need to debug. * CMT fast recovery code. Need to debug.
@ -1870,7 +1859,7 @@ sctp_hs_cwnd_update_after_sack(struct sctp_tcb *stcb,
continue; continue;
} }
#ifdef JANA_CMT_FAST_RECOVERY #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) { 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: * H-TCP congestion control. The algorithm is detailed in:
* R.N.Shorten, D.J.Leith: * 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 * http://www.hamilton.ie/net/htcp3.pdf
*/ */
static int use_rtt_scaling = 1; static int use_rtt_scaling = 1;
static int use_bandwidth_switch = 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->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) 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; 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; 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; ca->beta = (minRTT<<7)/maxRTT;
if (ca->beta < BETA_MIN) if (ca->beta < BETA_MIN)
ca->beta = BETA_MIN; ca->beta = BETA_MIN;
@ -2081,19 +2068,19 @@ htcp_alpha_update(struct htcp *ca)
if (diff > (uint32_t)hz) { if (diff > (uint32_t)hz) {
diff -= 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) { if (use_rtt_scaling && minRTT) {
uint32_t scale = (hz<<3)/(10*minRTT); uint32_t scale = (hz << 3) / (10 * minRTT);
scale = min(max(scale, 1U<<2), 10U<<3); /* clamping ratio to interval [0.5,10]<<3 */ scale = min(max(scale, 1U << 2), 10U << 3); /* clamping ratio to interval [0.5,10]<<3 */
factor = (factor<<3)/scale; factor = (factor << 3) / scale;
if (!factor) if (factor != 0)
factor = 1; factor = 1;
} }
ca->alpha = 2*factor*((1<<7)-ca->beta); ca->alpha = 2 * factor * ((1 << 7) - ca->beta);
if (!ca->alpha) if (ca->alpha != 0)
ca->alpha = ALPHA_BASE; ca->alpha = ALPHA_BASE;
} }
@ -2131,10 +2118,10 @@ htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
{ {
/*- /*-
* How to handle these functions? * 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; * return;
*/ */
if (net->cwnd <= net->ssthresh) { if (net->cwnd <= net->ssthresh) {
/* We are in slow start */ /* We are in slow start */
if (net->flight_size + net->net_ack >= net->cwnd) { if (net->flight_size + net->net_ack >= net->cwnd) {
if (net->net_ack > (net->mtu * SCTP_BASE_SYSCTL(sctp_L2_abc_variable))) { 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_log_cwnd(stcb, net, net->net_ack,
SCTP_CWND_LOG_FROM_SS); SCTP_CWND_LOG_FROM_SS);
} }
} }
sctp_enforce_cwnd_limit(&stcb->asoc, net); sctp_enforce_cwnd_limit(&stcb->asoc, net);
} else { } else {
@ -2167,7 +2153,7 @@ htcp_cong_avoid(struct sctp_tcb *stcb, struct sctp_nets *net)
*/ */
/* What is snd_cwnd_cnt?? */ /* What is snd_cwnd_cnt?? */
if (((net->partial_bytes_acked/net->mtu * net->cc_mod.htcp_ca.alpha) >> 7)*net->mtu >= net->cwnd) { if (((net->partial_bytes_acked/net->mtu * net->cc_mod.htcp_ca.alpha) >> 7)*net->mtu >= net->cwnd) {
/*- /*-
* Does SCTP have a cwnd clamp? * Does SCTP have a cwnd clamp?
* if (net->snd_cwnd < net->snd_cwnd_clamp) - Nope (RRS). * 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 */ /* update cwnd and Early FR */
/******************************/ /******************************/
TAILQ_FOREACH(net, &asoc->nets, sctp_next) { TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
#ifdef JANA_CMT_FAST_RECOVERY #ifdef JANA_CMT_FAST_RECOVERY
/* /*
* CMT fast recovery code. Need to debug. * CMT fast recovery code. Need to debug.
@ -2258,7 +2243,7 @@ sctp_htcp_cwnd_update_after_sack(struct sctp_tcb *stcb,
continue; continue;
} }
#ifdef JANA_CMT_FAST_RECOVERY #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) { 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[] = { 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_set_initial_cc_param,
sctp_cwnd_update_after_sack, sctp_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common, sctp_cwnd_update_exit_pf_common,
@ -2431,7 +2416,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif #endif
}, },
{ {
#if defined(__Windows__) || (defined(__Userspace_os_Windows) && !defined(__MINGW32__)) #if defined(_WIN32) && !defined(__MINGW32__)
sctp_set_initial_cc_param, sctp_set_initial_cc_param,
sctp_hs_cwnd_update_after_sack, sctp_hs_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common, sctp_cwnd_update_exit_pf_common,
@ -2452,7 +2437,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif #endif
}, },
{ {
#if defined(__Windows__) || (defined(__Userspace_os_Windows) && !defined(__MINGW32__)) #if defined(_WIN32) && !defined(__MINGW32__)
sctp_htcp_set_initial_cc_param, sctp_htcp_set_initial_cc_param,
sctp_htcp_cwnd_update_after_sack, sctp_htcp_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common, sctp_cwnd_update_exit_pf_common,
@ -2473,7 +2458,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif #endif
}, },
{ {
#if defined(__Windows__) || (defined(__Userspace_os_Windows) && !defined(__MINGW32__)) #if defined(_WIN32) && !defined(__MINGW32__)
sctp_set_rtcc_initial_cc_param, sctp_set_rtcc_initial_cc_param,
sctp_cwnd_update_rtcc_after_sack, sctp_cwnd_update_rtcc_after_sack,
sctp_cwnd_update_exit_pf_common, sctp_cwnd_update_exit_pf_common,

View File

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

View File

@ -32,26 +32,22 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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" #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/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/gsb_crc32.h>
#include <sys/mbuf.h> #include <sys/mbuf.h>
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h> #include <netinet/sctp_crc32.h>
#if defined(SCTP) || defined(SCTP_SUPPORT)
#include <netinet/sctp_os.h>
#include <netinet/sctp_pcb.h>
#endif #endif
#else #else
#include <netinet/sctp_os.h> #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> #include <netinet/sctp_pcb.h>
#endif #endif
#if !defined(__FreeBSD__) #if !(defined(__FreeBSD__) && !defined(__Userspace__))
/** /**
* *
* Routine Description: * Routine Description:
@ -799,8 +795,11 @@ sctp_calculate_cksum(struct mbuf *m, uint32_t offset)
return (base); return (base);
} }
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
#ifdef SCTP #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 * Compute and insert the SCTP checksum in network byte order for a given
* mbuf chain m which contains an SCTP packet starting at offset. * mbuf chain m which contains an SCTP packet starting at offset.

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_CRC32_H_ #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) #if defined(_KERNEL)
uint32_t sctp_calculate_cksum(struct mbuf *, uint32_t); uint32_t sctp_calculate_cksum(struct mbuf *, uint32_t);
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
#ifdef SCTP #if defined(SCTP) || defined(SCTP_SUPPORT)
void sctp_delayed_cksum(struct mbuf *, uint32_t offset); void sctp_delayed_cksum(struct mbuf *, uint32_t offset);
#endif #endif
#endif #endif

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_INDATA_H_ #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 * struct sctp_queued_to_read *
sctp_build_readq_entry(struct sctp_tcb *stcb, sctp_build_readq_entry(struct sctp_tcb *stcb,
struct sctp_nets *net, struct sctp_nets *net,
uint32_t tsn, uint32_t ppid, uint32_t tsn, uint32_t ppid,
uint32_t context, uint16_t sid, uint32_t context, uint16_t sid,
uint32_t mid, uint8_t flags, uint32_t mid, uint8_t flags,
struct mbuf *dm); struct mbuf *dm);
#define sctp_build_readq_entry_mac(_ctl, in_it, context, net, tsn, ppid, sid, flags, dm, tfsn, mid) do { \ #define sctp_build_readq_entry_mac(_ctl, in_it, context, net, tsn, ppid, sid, flags, dm, tfsn, mid) do { \
if (_ctl) { \ if (_ctl) { \
@ -70,14 +69,15 @@ sctp_build_readq_entry(struct sctp_tcb *stcb,
(_ctl)->data = dm; \ (_ctl)->data = dm; \
(_ctl)->stcb = (in_it); \ (_ctl)->stcb = (in_it); \
(_ctl)->port_from = (in_it)->rport; \ (_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) } while (0)
struct mbuf * struct mbuf *
sctp_build_ctl_nchunk(struct sctp_inpcb *inp, 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 *); 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 void
sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, 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 void
sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup, 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 */ /* draft-ietf-tsvwg-usctp */
void void
sctp_handle_forward_tsn(struct sctp_tcb *, 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 * struct sctp_tmit_chunk *
sctp_try_advance_peer_ack_point(struct sctp_tcb *, struct sctp_association *); 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 int
sctp_process_data(struct mbuf **, int, int *, int, sctp_process_data(struct mbuf **, int, int *, int,
struct sctp_inpcb *, struct sctp_tcb *, struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *, uint32_t *); struct sctp_nets *, uint32_t *);
void sctp_slide_mapping_arrays(struct sctp_tcb *stcb); 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. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_INPUT_H_ #ifndef _NETINET_SCTP_INPUT_H_
@ -47,7 +47,7 @@ sctp_common_input_processing(struct mbuf **, int, int, int,
struct sctphdr *, struct sctp_chunkhdr *, struct sctphdr *, struct sctp_chunkhdr *,
uint8_t, uint8_t,
uint8_t, uint8_t,
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t, uint8_t, uint32_t, uint16_t,
#endif #endif
uint32_t, uint16_t); uint32_t, uint16_t);
@ -56,9 +56,9 @@ struct sctp_stream_reset_request *
sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq, sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq,
struct sctp_tmit_chunk **bchk); struct sctp_tmit_chunk **bchk);
void sctp_reset_in_stream(struct sctp_tcb *stcb, uint32_t number_entries, void
uint16_t *list); 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); int sctp_is_there_unsent_data(struct sctp_tcb *stcb, int so_locked);

View File

@ -33,7 +33,7 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD$"); __FBSDID("$FreeBSD$");
#endif #endif
@ -63,12 +63,15 @@ __FBSDID("$FreeBSD$");
#define SCTP_INP_INFO_TRYLOCK() 1 #define SCTP_INP_INFO_TRYLOCK() 1
#define SCTP_INP_INFO_RUNLOCK() #define SCTP_INP_INFO_RUNLOCK()
#define SCTP_INP_INFO_WUNLOCK() #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_INIT()
#define SCTP_WQ_ADDR_DESTROY() #define SCTP_WQ_ADDR_DESTROY()
#define SCTP_WQ_ADDR_LOCK() #define SCTP_WQ_ADDR_LOCK()
#define SCTP_WQ_ADDR_UNLOCK() #define SCTP_WQ_ADDR_UNLOCK()
#define SCTP_WQ_ADDR_LOCK_ASSERT()
#define SCTP_IPI_ADDR_INIT() #define SCTP_IPI_ADDR_INIT()
#define SCTP_IPI_ADDR_DESTROY() #define SCTP_IPI_ADDR_DESTROY()
@ -76,20 +79,19 @@ __FBSDID("$FreeBSD$");
#define SCTP_IPI_ADDR_WLOCK() #define SCTP_IPI_ADDR_WLOCK()
#define SCTP_IPI_ADDR_RUNLOCK() #define SCTP_IPI_ADDR_RUNLOCK()
#define SCTP_IPI_ADDR_WUNLOCK() #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_INIT()
#define SCTP_IPI_ITERATOR_WQ_DESTROY() #define SCTP_IPI_ITERATOR_WQ_DESTROY()
#define SCTP_IPI_ITERATOR_WQ_LOCK() #define SCTP_IPI_ITERATOR_WQ_LOCK()
#define SCTP_IPI_ITERATOR_WQ_UNLOCK() #define SCTP_IPI_ITERATOR_WQ_UNLOCK()
#define SCTP_IP_PKTLOG_INIT() #define SCTP_IP_PKTLOG_INIT()
#define SCTP_IP_PKTLOG_LOCK() #define SCTP_IP_PKTLOG_LOCK()
#define SCTP_IP_PKTLOG_UNLOCK() #define SCTP_IP_PKTLOG_UNLOCK()
#define SCTP_IP_PKTLOG_DESTROY() #define SCTP_IP_PKTLOG_DESTROY()
#define SCTP_INP_READ_INIT(_inp) #define SCTP_INP_READ_INIT(_inp)
#define SCTP_INP_READ_DESTROY(_inp) #define SCTP_INP_READ_DESTROY(_inp)
#define SCTP_INP_READ_LOCK(_inp) #define SCTP_INP_READ_LOCK(_inp)
@ -100,9 +102,10 @@ __FBSDID("$FreeBSD$");
#define SCTP_INP_LOCK_DESTROY(_inp) #define SCTP_INP_LOCK_DESTROY(_inp)
#define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp) #define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp)
#define SCTP_INP_RLOCK(_inp) #define SCTP_INP_RLOCK(_inp)
#define SCTP_INP_WLOCK(_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 */ #define SCTP_INP_LOCK_CONTENDED(_inp) (0) /* Don't know if this is possible */
@ -214,14 +217,6 @@ __FBSDID("$FreeBSD$");
} while (0) } 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 ... */ /* these were in sctp_lock_empty.h but aren't in sctp_lock_bsd.h ... */
#if 0 #if 0
#define SCTP_IPI_ADDR_LOCK() #define SCTP_IPI_ADDR_LOCK()

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_OS_H_ #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) * SCTP_ZONE_DESTROY(zone)
*/ */
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/sctp_os_bsd.h> #include <netinet/sctp_os_bsd.h>
#else #else
#define MODULE_GLOBAL(_B) (_B) #define MODULE_GLOBAL(_B) (_B)
#endif #endif
#if defined(__Userspace__) #if defined(__Userspace__)
#include <netinet/sctp_os_userspace.h> #include <netinet/sctp_os_userspace.h>
#endif #endif
#if defined(__APPLE__) && !defined(__Userspace__)
#if defined(__APPLE__)
#include <netinet/sctp_os_macosx.h> #include <netinet/sctp_os_macosx.h>
#endif #endif
#if defined(_WIN32) && !defined(__Userspace__)
#if defined(__Panda__)
#include <ip/sctp/sctp_os_iox.h>
#endif
#if defined(__Windows__)
#include <netinet/sctp_os_windows.h> #include <netinet/sctp_os_windows.h>
#endif #endif

View File

@ -43,7 +43,7 @@
#include <errno.h> #include <errno.h>
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <iphlpapi.h> #include <iphlpapi.h>
@ -83,28 +83,24 @@ typedef HANDLE userland_thread_t;
#if !defined(_MSC_VER) || (_MSC_VER >= 1600) #if !defined(_MSC_VER) || (_MSC_VER >= 1600)
#include <stdint.h> #include <stdint.h>
#else #else
#define uint64_t unsigned __int64 typedef unsigned __int64 uint64_t;
#define uint32_t unsigned __int32 typedef unsigned __int32 uint32_t;
#define int32_t __int32 typedef __int32 int32_t;
#define uint16_t unsigned __int16 typedef unsigned __int16 uint16_t;
#define int16_t __int16 typedef __int16 int16_t;
#define uint8_t unsigned __int8 typedef unsigned __int8 uint8_t;
#define int8_t __int8 typedef __int8 int8_t;
#endif #endif
#ifndef _SIZE_T_DEFINED #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 #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__) #if !defined(__MINGW32__)
#define __func__ __FUNCTION__ #define __func__ __FUNCTION__
#endif #endif
@ -221,9 +217,19 @@ typedef char* caddr_t;
#define bzero(buf, len) memset(buf, 0, len) #define bzero(buf, len) memset(buf, 0, len)
#define bcopy(srcKey, dstKey, len) memcpy(dstKey, srcKey, len) #define bcopy(srcKey, dstKey, len) memcpy(dstKey, srcKey, len)
#if defined(_MSC_VER) && (_MSC_VER < 1900) && !defined(__MINGW32__) #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 #endif
#define inline __inline #define inline __inline
#define __inline__ __inline #define __inline__ __inline
#define MSG_EOR 0x8 /* data completes record */ #define MSG_EOR 0x8 /* data completes record */
@ -277,15 +283,19 @@ typedef char* caddr_t;
#else /* !defined(Userspace_os_Windows) */ #else /* !defined(Userspace_os_Windows) */
#include <sys/socket.h> #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 #endif
#include <pthread.h>
typedef pthread_mutex_t userland_mutex_t; typedef pthread_mutex_t userland_mutex_t;
typedef pthread_cond_t userland_cond_t; typedef pthread_cond_t userland_cond_t;
typedef pthread_t userland_thread_t; typedef pthread_t userland_thread_t;
#endif #endif
#if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl) #if defined(_WIN32) || defined(__native_client__)
#define IFNAMSIZ 64 #define IFNAMSIZ 64
@ -379,43 +389,9 @@ struct ifkpi {
int ifk_value; int ifk_value;
} ifk_data; } 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 #endif
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
int Win_getifaddrs(struct ifaddrs**); int Win_getifaddrs(struct ifaddrs**);
#define getifaddrs(interfaces) (int)Win_getifaddrs(interfaces) #define getifaddrs(interfaces) (int)Win_getifaddrs(interfaces)
int win_if_nametoindex(const char *); int win_if_nametoindex(const char *);
@ -426,9 +402,9 @@ int win_if_nametoindex(const char *);
#define mtx_unlock(arg1) #define mtx_unlock(arg1)
#define mtx_assert(arg1,arg2) #define mtx_assert(arg1,arg2)
#define MA_OWNED 7 /* sys/mutex.h typically on FreeBSD */ #define MA_OWNED 7 /* sys/mutex.h typically on FreeBSD */
#if !defined(__Userspace_os_FreeBSD) #if !defined(__FreeBSD__)
struct mtx {int dummy;}; struct mtx {int dummy;};
#if !defined(__Userspace_os_NetBSD) #if !defined(__NetBSD__)
struct selinfo {int dummy;}; struct selinfo {int dummy;};
#endif #endif
struct sx {int dummy;}; struct sx {int dummy;};
@ -436,6 +412,7 @@ struct sx {int dummy;};
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdbool.h>
/* #include <sys/param.h> in FreeBSD defines MSIZE */ /* #include <sys/param.h> in FreeBSD defines MSIZE */
/* #include <sys/ktr.h> */ /* #include <sys/ktr.h> */
/* #include <sys/systm.h> */ /* #include <sys/systm.h> */
@ -458,22 +435,22 @@ struct sx {int dummy;};
#include <user_mbuf.h> #include <user_mbuf.h>
/* #include <sys/uio.h> */ /* #include <sys/uio.h> */
/* #include <sys/lock.h> */ /* #include <sys/lock.h> */
#if defined(__FreeBSD__) && __FreeBSD_version > 602000 #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/rwlock.h> #include <sys/rwlock.h>
#endif #endif
/* #include <sys/kthread.h> */ /* #include <sys/kthread.h> */
#if defined(__FreeBSD__) && __FreeBSD_version > 602000 #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/priv.h> #include <sys/priv.h>
#endif #endif
/* #include <sys/random.h> */ /* #include <sys/random.h> */
#include <limits.h> #include <limits.h>
/* #include <machine/cpu.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 */ /* was a 0 byte file. needed for structs if_data(64) and net_event_data */
#include <net/if_var.h> #include <net/if_var.h>
#endif #endif
#if defined(__Userspace_os_FreeBSD) #if defined(__FreeBSD__)
#include <net/if_types.h> #include <net/if_types.h>
/* #include <net/if_var.h> was a 0 byte file. causes struct mtx redefinition */ /* #include <net/if_var.h> was a 0 byte file. causes struct mtx redefinition */
#endif #endif
@ -481,7 +458,7 @@ struct sx {int dummy;};
* userspace as well? */ * userspace as well? */
/* on FreeBSD, this results in a redefintion of struct route */ /* on FreeBSD, this results in a redefintion of struct route */
/* #include <net/route.h> */ /* #include <net/route.h> */
#if !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl) #if !defined(_WIN32) && !defined(__native_client__)
#include <net/if.h> #include <net/if.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/in_systm.h> #include <netinet/in_systm.h>
@ -497,7 +474,7 @@ struct sx {int dummy;};
/* for getifaddrs */ /* for getifaddrs */
#include <sys/types.h> #include <sys/types.h>
#if !defined(__Userspace_os_Windows) #if !defined(_WIN32)
#if defined(INET) || defined(INET6) #if defined(INET) || defined(INET6)
#include <ifaddrs.h> #include <ifaddrs.h>
#endif #endif
@ -507,6 +484,8 @@ struct sx {int dummy;};
/* for close, etc. */ /* for close, etc. */
#include <unistd.h> #include <unistd.h>
/* for gettimeofday */
#include <sys/time.h>
#endif #endif
/* lots of errno's used and needed in userspace */ /* lots of errno's used and needed in userspace */
@ -514,7 +493,7 @@ struct sx {int dummy;};
/* for offsetof */ /* for offsetof */
#include <stddef.h> #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. */ /* for pthread_mutex_lock, pthread_mutex_unlock, etc. */
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -525,21 +504,21 @@ struct sx {int dummy;};
#endif /* IPSEC */ #endif /* IPSEC */
#ifdef INET6 #ifdef INET6
#if defined(__Userspace_os_FreeBSD) #if defined(__FreeBSD__)
#include <sys/domain.h> #include <sys/domain.h>
#endif #endif
#ifdef IPSEC #ifdef IPSEC
#include <netipsec/ipsec6.h> #include <netipsec/ipsec6.h>
#endif #endif
#if !defined(__Userspace_os_Windows) #if !defined(_WIN32)
#include <netinet/ip6.h> #include <netinet/ip6.h>
#endif #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" #include "user_ip6_var.h"
#else #else
#include <netinet6/ip6_var.h> #include <netinet6/ip6_var.h>
#endif #endif
#if defined(__Userspace_os_FreeBSD) #if defined(__FreeBSD__)
#include <netinet6/in6_pcb.h> #include <netinet6/in6_pcb.h>
#include <netinet6/ip6protosw.h> #include <netinet6/ip6protosw.h>
/* #include <netinet6/nd6.h> was a 0 byte file */ /* #include <netinet6/nd6.h> was a 0 byte file */
@ -554,7 +533,7 @@ struct sx {int dummy;};
#include "netinet/sctp_sha1.h" #include "netinet/sctp_sha1.h"
#if __FreeBSD_version >= 700000 #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/ip_options.h> #include <netinet/ip_options.h>
#endif #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 */ #define USER_ADDR_NULL (NULL) /* FIX ME: temp */
#endif #endif
#if defined(SCTP_DEBUG)
#include <netinet/sctp_constants.h> #include <netinet/sctp_constants.h>
#if defined(SCTP_DEBUG)
#define SCTPDBG(level, ...) \ #define SCTPDBG(level, ...) \
{ \ { \
do { \ do { \
@ -666,7 +645,7 @@ MALLOC_DECLARE(SCTP_M_SOCKOPT);
#define SCTP_VRF_IFN_HASH_SIZE 3 #define SCTP_VRF_IFN_HASH_SIZE 3
#define SCTP_INIT_VRF_TABLEID(vrf) #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) #define SCTP_IFN_IS_IFT_LOOP(ifn) (strncmp((ifn)->ifn_name, "lo", 2) == 0)
/* BSD definition */ /* 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) */ /* #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 #define KTR_SUBSYS 1
/* The packed define for 64 bit platforms */ /* The packed define for 64 bit platforms */
#if !defined(__Userspace_os_Windows) #if !defined(_WIN32)
#define SCTP_PACKED __attribute__((packed)) #define SCTP_PACKED __attribute__((packed))
#define SCTP_UNUSED __attribute__((unused)) #define SCTP_UNUSED __attribute__((unused))
#else #else
@ -829,6 +808,13 @@ sctp_hashfreedestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask);
M_ALIGN(m, len); \ 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 /* We make it so if you have up to 4 threads
* writting based on the default size of * writting based on the default size of
* the packet log 65 k, that would be * the packet log 65 k, that would be
@ -887,7 +873,6 @@ static inline void sctp_userspace_rtfree(sctp_rtentry_t *rt)
return; return;
} }
free(rt); free(rt);
rt = NULL;
} }
#define rtfree(arg1) sctp_userspace_rtfree(arg1) #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_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 { \ #define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \
if (rt != NULL) \ if (rt != NULL) \
rt->rt_rmx.rmx_mtu = mtu; \ rt->rt_rmx.rmx_mtu = mtu; \
} while(0) } while(0)
/* (de-)register interface event notifications */
#define SCTP_REGISTER_INTERFACE(ifhandle, af)
#define SCTP_DEREGISTER_INTERFACE(ifhandle, af)
/*************************/ /*************************/
/* These are for logging */ /* 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 */ /* 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 #define IPv6_HOP_LIMIT 128
/* is the endpoint v6only? */ /* is the endpoint v6only? */
@ -1000,7 +981,7 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af);
/* sctp_pcb.h */ /* sctp_pcb.h */
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
#define SHUT_RD 1 #define SHUT_RD 1
#define SHUT_WR 2 #define SHUT_WR 2
#define SHUT_RDWR 3 #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 /* with the current included files, this is defined in Linux but
* in FreeBSD, it is behind a _KERNEL in sys/socket.h ... * 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 */ /* stolen from /usr/include/sys/socket.h */
#define CMSG_ALIGN(n) _ALIGN(n) #define CMSG_ALIGN(n) _ALIGN(n)
#elif defined(__Userspace_os_NetBSD) #elif defined(__NetBSD__)
#define CMSG_ALIGN(n) (((n) + __ALIGNBYTES) & ~__ALIGNBYTES) #define CMSG_ALIGN(n) (((n) + __ALIGNBYTES) & ~__ALIGNBYTES)
#elif defined(__Userspace_os_Darwin) #elif defined(__APPLE__)
#if !defined(__DARWIN_ALIGNBYTES) #if !defined(__DARWIN_ALIGNBYTES)
#define __DARWIN_ALIGNBYTES (sizeof(__darwin_size_t) - 1) #define __DARWIN_ALIGNBYTES (sizeof(__darwin_size_t) - 1)
#endif #endif
@ -1127,7 +1108,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
} while (0) } while (0)
#endif #endif
#if defined(__Userspace_os_Linux) #if defined(__linux__)
#if !defined(TAILQ_FOREACH_SAFE) #if !defined(TAILQ_FOREACH_SAFE)
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = ((head)->tqh_first); \ 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)) (var) = (tvar))
#endif #endif
#endif #endif
#if defined(__Userspace_os_DragonFly) #if defined(__DragonFly__)
#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE #define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE
#define LIST_FOREACH_SAFE LIST_FOREACH_MUTABLE #define LIST_FOREACH_SAFE LIST_FOREACH_MUTABLE
#endif #endif
#if defined(__Userspace_os_NaCl) #if defined(__native_client__)
#define timercmp(tvp, uvp, cmp) \ #define timercmp(tvp, uvp, cmp) \
(((tvp)->tv_sec == (uvp)->tv_sec) ? \ (((tvp)->tv_sec == (uvp)->tv_sec) ? \
((tvp)->tv_usec cmp (uvp)->tv_usec) : \ ((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) #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 int
timingsafe_bcmp(const void *, const void *, size_t); timingsafe_bcmp(const void *, const void *, size_t);
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_OUTPUT_H_ #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__) #if defined(_KERNEL) || defined(__Userspace__)
struct mbuf * struct mbuf *
sctp_add_addresses_to_i_ia(struct sctp_inpcb *inp, sctp_add_addresses_to_i_ia(struct sctp_inpcb *inp,
struct sctp_tcb *stcb, struct sctp_tcb *stcb,
struct sctp_scoping *scope, struct sctp_scoping *scope,
struct mbuf *m_at, struct mbuf *m_at,
int cnt_inits_to, int cnt_inits_to,
uint16_t *padding_len, uint16_t *chunk_len); uint16_t *padding_len, uint16_t *chunk_len);
int sctp_is_addr_restricted(struct sctp_tcb *, struct sctp_ifa *); int sctp_is_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
int int
sctp_is_address_in_scope(struct sctp_ifa *ifa, sctp_is_address_in_scope(struct sctp_ifa *ifa,
struct sctp_scoping *scope, struct sctp_scoping *scope,
int do_update); int do_update);
int int
sctp_is_addr_in_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa); sctp_is_addr_in_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa);
struct sctp_ifa * struct sctp_ifa *
sctp_source_address_selection(struct sctp_inpcb *inp, sctp_source_address_selection(struct sctp_inpcb *inp,
struct sctp_tcb *stcb, struct sctp_tcb *stcb,
sctp_route_t *ro, struct sctp_nets *net, sctp_route_t *ro, struct sctp_nets *net,
int non_asoc_addr_ok, uint32_t vrf_id); int non_asoc_addr_ok, uint32_t vrf_id);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Userspace__) #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Userspace__)
int int sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t *ro);
sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t *ro);
int int sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro);
sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro);
#endif #endif
void sctp_send_initiate(struct sctp_inpcb *, struct sctp_tcb *, int void sctp_send_initiate(struct sctp_inpcb *, struct sctp_tcb *, int);
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void void
sctp_send_initiate_ack(struct sctp_inpcb *, struct sctp_tcb *, 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, int, int,
struct sockaddr *, struct sockaddr *, struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct sctp_init_chunk *, struct sctphdr *, struct sctp_init_chunk *,
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint8_t, uint32_t,
#endif #endif
uint32_t, uint16_t); uint32_t, uint16_t);
struct mbuf * struct mbuf *
sctp_arethere_unrecognized_parameters(struct mbuf *, int, int *, 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 *); void sctp_queue_op_err(struct sctp_tcb *, struct mbuf *);
int int
sctp_send_cookie_echo(struct mbuf *, int, int, struct sctp_tcb *, 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_cookie_ack(struct sctp_tcb *);
void void
sctp_send_heartbeat_ack(struct sctp_tcb *, struct mbuf *, int, int, sctp_send_heartbeat_ack(struct sctp_tcb *, struct mbuf *, int, int,
struct sctp_nets *); struct sctp_nets *);
void void
sctp_remove_from_wheel(struct sctp_tcb *stcb, sctp_remove_from_wheel(struct sctp_tcb *stcb,
struct sctp_association *asoc, struct sctp_association *asoc,
struct sctp_stream_out *strq, int holds_lock); struct sctp_stream_out *strq, int holds_lock);
void sctp_send_shutdown(struct sctp_tcb *, struct sctp_nets *); 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 *, void sctp_send_shutdown_complete2(struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct sctphdr *,
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t, uint8_t, uint32_t, uint16_t,
#endif #endif
uint32_t, uint16_t); 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); void sctp_move_chunks_from_net(struct sctp_tcb *stcb, struct sctp_nets *net);
#define SCTP_DATA_CHUNK_OVERHEAD(stcb) ((stcb)->asoc.idata_supported ? \ #define SCTP_DATA_CHUNK_OVERHEAD(stcb) ((stcb)->asoc.idata_supported ? \
sizeof(struct sctp_idata_chunk) : \ sizeof(struct sctp_idata_chunk) : \
sizeof(struct sctp_data_chunk)) sizeof(struct sctp_data_chunk))
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 #if defined(__FreeBSD__) && !defined(__Userspace__)
int int
sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *, sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct thread *, int); struct mbuf *, struct thread *, int);
#elif defined(__Windows__) #elif defined(_WIN32) && !defined(__Userspace__)
sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *, sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, PKTHREAD, int); struct mbuf *, PKTHREAD, int);
#else #else
@ -161,30 +151,15 @@ sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
#endif #endif
int int
sctp_output(struct sctp_inpcb *, sctp_output(struct sctp_inpcb *,
#if defined(__Panda__)
pakhandle_type,
#else
struct mbuf *, struct mbuf *,
#endif
struct sockaddr *, struct sockaddr *,
#if defined(__Panda__)
pakhandle_type,
#else
struct mbuf *, struct mbuf *,
#endif
struct proc *, int); struct proc *, int);
#endif #endif
void sctp_chunk_output(struct sctp_inpcb *, struct sctp_tcb *, int, int void sctp_chunk_output(struct sctp_inpcb *, struct sctp_tcb *, int, int);
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED void sctp_send_abort_tcb(struct sctp_tcb *, struct mbuf *, int);
#endif
);
void sctp_send_abort_tcb(struct sctp_tcb *, struct mbuf *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void send_forward_tsn(struct sctp_tcb *, struct sctp_association *); 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_ecn_echo(struct sctp_tcb *, struct sctp_nets *, uint32_t);
void void
sctp_send_packet_dropped(struct sctp_tcb *, struct sctp_nets *, struct mbuf *, sctp_send_packet_dropped(struct sctp_tcb *, struct sctp_nets *, struct mbuf *,
int, int, int); int, int, int);
void sctp_send_cwr(struct sctp_tcb *, struct sctp_nets *, uint32_t, uint8_t); void sctp_send_cwr(struct sctp_tcb *, struct sctp_nets *, uint32_t, uint8_t);
void void
sctp_add_stream_reset_result(struct sctp_tmit_chunk *, uint32_t, uint32_t); sctp_add_stream_reset_result(struct sctp_tmit_chunk *, uint32_t, uint32_t);
void void
sctp_send_deferred_reset_response(struct sctp_tcb *, sctp_send_deferred_reset_response(struct sctp_tcb *,
struct sctp_stream_reset_list *, struct sctp_stream_reset_list *,
int); int);
void void
sctp_add_stream_reset_result_tsn(struct sctp_tmit_chunk *, 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 void
sctp_send_abort(struct mbuf *, int, struct sockaddr *, struct sockaddr *, sctp_send_abort(struct mbuf *, int, struct sockaddr *, struct sockaddr *,
struct sctphdr *, uint32_t, struct mbuf *, struct sctphdr *, uint32_t, struct mbuf *,
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t, uint8_t, uint32_t, uint16_t,
#endif #endif
uint32_t, uint16_t); uint32_t, uint16_t);
void sctp_send_operr_to(struct sockaddr *, struct sockaddr *, void
struct sctphdr *, uint32_t, struct mbuf *, sctp_send_operr_to(struct sockaddr *, struct sockaddr *,
#if defined(__FreeBSD__) struct sctphdr *, uint32_t, struct mbuf *,
uint8_t, uint32_t, uint16_t, #if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif #endif
uint32_t, uint16_t); uint32_t, uint16_t);
#endif /* _KERNEL || __Userspace__ */ #endif /* _KERNEL || __Userspace__ */
@ -244,20 +216,15 @@ int
sctp_sosend(struct socket *so, sctp_sosend(struct socket *so,
struct sockaddr *addr, struct sockaddr *addr,
struct uio *uio, struct uio *uio,
#ifdef __Panda__
pakhandle_type top,
pakhandle_type control,
#else
struct mbuf *top, struct mbuf *top,
struct mbuf *control, struct mbuf *control,
#endif #if defined(__APPLE__) && !defined(__Userspace__)
#if defined(__APPLE__) || defined(__Panda__)
int flags int flags
#else #else
int flags, int flags,
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 #if defined(__FreeBSD__) && !defined(__Userspace__)
struct thread *p struct thread *p
#elif defined(__Windows__) #elif defined(_WIN32) && !defined(__Userspace__)
PKTHREAD p PKTHREAD p
#else #else
#if defined(__Userspace__) #if defined(__Userspace__)

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.c 337708 2018-08-13 13:58:45Z tuexen $"); __FBSDID("$FreeBSD$");
#endif #endif
#include <netinet/sctp_os.h> #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/sctputil.h>
#include <netinet/sctp_auth.h> #include <netinet/sctp_auth.h>
#if defined(__APPLE__)
#define APPLE_FILE_NO 5
#endif
int int
sctp_can_peel_off(struct socket *head, sctp_assoc_t assoc_id) 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->sctp_context = inp->sctp_context;
n_inp->max_cwnd = inp->max_cwnd; n_inp->max_cwnd = inp->max_cwnd;
n_inp->local_strreset_support = inp->local_strreset_support; 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 */ /* copy in the authentication parameters from the original endpoint */
if (n_inp->sctp_ep.local_hmacs) if (n_inp->sctp_ep.local_hmacs)
sctp_free_hmaclist(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); atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb); 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); sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, SBL_WAIT);
#else #else
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, M_WAITOK); 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 * struct socket *
sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error) 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 socket *newso;
struct sctp_inpcb *inp, *n_inp; struct sctp_inpcb *inp, *n_inp;
struct sctp_tcb *stcb; 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); atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb); SCTP_TCB_UNLOCK(stcb);
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000 #if defined(__FreeBSD__) && !defined(__Userspace__)
CURVNET_SET(head->so_vnet); CURVNET_SET(head->so_vnet);
#endif #endif
newso = sonewconn(head, SS_ISCONNECTED newso = sonewconn(head, SS_ISCONNECTED
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
, NULL , NULL
#elif defined(__Panda__)
/* place this socket in the assoc's vrf id */
, NULL, stcb->asoc.vrf_id
#endif #endif
); );
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000 #if defined(__FreeBSD__) && !defined(__Userspace__)
CURVNET_RESTORE(); CURVNET_RESTORE();
#endif #endif
if (newso == NULL) { if (newso == NULL) {
@ -227,7 +211,7 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
return (NULL); return (NULL);
} }
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
else { else {
SCTP_SOCKET_LOCK(newso, 1); 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); SOCK_UNLOCK(newso);
/* We remove it right away */ /* We remove it right away */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
#ifdef SCTP_LOCK_LOGGING #ifdef SCTP_LOCK_LOGGING
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) { if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK); 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); TAILQ_REMOVE(&head->so_comp, newso, so_list);
head->so_qlen--; head->so_qlen--;
SOCK_UNLOCK(head); 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 * Now we must move it from one hash table to another and get the
* stcb in the right place. * 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. * 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 * 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); sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, SBL_WAIT);
#else #else
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, M_WAITOK); sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, M_WAITOK);
#endif #endif
atomic_subtract_int(&stcb->asoc.refcnt, 1); atomic_subtract_int(&stcb->asoc.refcnt, 1);
return (newso); return (newso);
#endif
} }
#endif #endif

View File

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

View File

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

View File

@ -32,7 +32,7 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD$"); __FBSDID("$FreeBSD$");
#endif #endif
@ -43,18 +43,11 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h> #include <sys/types.h>
#if defined(SCTP_USE_NSS_SHA1) #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> #include <pk11pub.h>
#if defined(__Userspace_os_Darwin)
#undef __APPLE__
#endif
#elif defined(SCTP_USE_OPENSSL_SHA1) #elif defined(SCTP_USE_OPENSSL_SHA1)
#include <openssl/sha.h> #include <openssl/sha.h>
#elif defined(SCTP_USE_MBEDTLS_SHA1)
#include <mbedtls/sha1.h>
#endif #endif
struct sctp_sha1_context { struct sctp_sha1_context {
@ -62,6 +55,8 @@ struct sctp_sha1_context {
struct PK11Context *pk11_ctx; struct PK11Context *pk11_ctx;
#elif defined(SCTP_USE_OPENSSL_SHA1) #elif defined(SCTP_USE_OPENSSL_SHA1)
SHA_CTX sha_ctx; SHA_CTX sha_ctx;
#elif defined(SCTP_USE_MBEDTLS_SHA1)
mbedtls_sha1_context sha1_ctx;
#else #else
unsigned int A; unsigned int A;
unsigned int B; unsigned int B;
@ -83,7 +78,7 @@ struct sctp_sha1_context {
#endif #endif
}; };
#if (defined(__APPLE__) && defined(KERNEL)) #if (defined(__APPLE__) && !defined(__Userspace__) && defined(KERNEL))
#ifndef _KERNEL #ifndef _KERNEL
#define _KERNEL #define _KERNEL
#endif #endif

View File

@ -28,9 +28,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#include <netinet/sctp_pcb.h> #include <netinet/sctp_pcb.h>
@ -185,7 +185,6 @@ sctp_ss_default_remove(struct sctp_tcb *stcb, struct sctp_association *asoc,
return; return;
} }
static struct sctp_stream_out * static struct sctp_stream_out *
sctp_ss_default_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, sctp_ss_default_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
struct sctp_association *asoc) struct sctp_association *asoc)
@ -396,7 +395,6 @@ rrp_again:
return; return;
} }
/* /*
* Priority algorithm. * Priority algorithm.
* Always prefers streams based on their priority id. * 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); 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_next = NULL;
strq->ss_params.prio.next_spoke.tqe_prev = NULL; strq->ss_params.prio.next_spoke.tqe_prev = NULL;
} }
asoc->ss_data.last_out_stream = NULL; asoc->ss_data.last_out_stream = NULL;
if (holds_lock == 0) { 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; 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; strqt = asoc->ss_data.last_out_stream;
prio_again: prio_again:
/* Find the next stream to use */ /* 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. * Fair bandwidth algorithm.
* Maintains an equal troughput per stream. * Maintains an equal throughput per stream.
*/ */
static void static void
sctp_ss_fb_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, 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; 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 || if (asoc->ss_data.last_out_stream == NULL ||
TAILQ_FIRST(&asoc->ss_data.out.wheel) == TAILQ_LAST(&asoc->ss_data.out.wheel, sctpwheel_listhead)) { TAILQ_FIRST(&asoc->ss_data.out.wheel) == TAILQ_LAST(&asoc->ss_data.out.wheel, sctpwheel_listhead)) {
strqt = TAILQ_FIRST(&asoc->ss_data.out.wheel); 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 static void
sctp_ss_fcfs_add(struct sctp_tcb *stcb, struct sctp_association *asoc, sctp_ss_fcfs_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp, struct sctp_stream_out *strq SCTP_UNUSED,
int holds_lock); struct sctp_stream_queue_pending *sp, int holds_lock);
static void static void
sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc, 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; return;
} }
static struct sctp_stream_out * static struct sctp_stream_out *
sctp_ss_fcfs_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, sctp_ss_fcfs_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
struct sctp_association *asoc) 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_out *strq;
struct sctp_stream_queue_pending *sp; 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); sp = TAILQ_FIRST(&asoc->ss_data.out.list);
default_again: default_again:
if (sp != NULL) { if (sp != NULL) {
@ -940,7 +945,7 @@ default_again:
const struct sctp_ss_functions sctp_ss_functions[] = { const struct sctp_ss_functions sctp_ss_functions[] = {
/* SCTP_SS_DEFAULT */ /* SCTP_SS_DEFAULT */
{ {
#if defined(__Windows__) || defined(__Userspace_os_Windows) #if defined(_WIN32)
sctp_ss_default_init, sctp_ss_default_init,
sctp_ss_default_clear, sctp_ss_default_clear,
sctp_ss_default_init_stream, sctp_ss_default_init_stream,
@ -970,7 +975,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
}, },
/* SCTP_SS_ROUND_ROBIN */ /* SCTP_SS_ROUND_ROBIN */
{ {
#if defined(__Windows__) || defined(__Userspace_os_Windows) #if defined(_WIN32)
sctp_ss_default_init, sctp_ss_default_init,
sctp_ss_default_clear, sctp_ss_default_clear,
sctp_ss_default_init_stream, sctp_ss_default_init_stream,
@ -1000,7 +1005,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
}, },
/* SCTP_SS_ROUND_ROBIN_PACKET */ /* SCTP_SS_ROUND_ROBIN_PACKET */
{ {
#if defined(__Windows__) || defined(__Userspace_os_Windows) #if defined(_WIN32)
sctp_ss_default_init, sctp_ss_default_init,
sctp_ss_default_clear, sctp_ss_default_clear,
sctp_ss_default_init_stream, sctp_ss_default_init_stream,
@ -1030,7 +1035,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
}, },
/* SCTP_SS_PRIORITY */ /* SCTP_SS_PRIORITY */
{ {
#if defined(__Windows__) || defined(__Userspace_os_Windows) #if defined(_WIN32)
sctp_ss_default_init, sctp_ss_default_init,
sctp_ss_prio_clear, sctp_ss_prio_clear,
sctp_ss_prio_init_stream, sctp_ss_prio_init_stream,
@ -1060,7 +1065,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
}, },
/* SCTP_SS_FAIR_BANDWITH */ /* SCTP_SS_FAIR_BANDWITH */
{ {
#if defined(__Windows__) || defined(__Userspace_os_Windows) #if defined(_WIN32)
sctp_ss_default_init, sctp_ss_default_init,
sctp_ss_fb_clear, sctp_ss_fb_clear,
sctp_ss_fb_init_stream, sctp_ss_fb_init_stream,
@ -1090,7 +1095,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
}, },
/* SCTP_SS_FIRST_COME */ /* SCTP_SS_FIRST_COME */
{ {
#if defined(__Windows__) || defined(__Userspace_os_Windows) #if defined(_WIN32)
sctp_ss_fcfs_init, sctp_ss_fcfs_init,
sctp_ss_fcfs_clear, sctp_ss_fcfs_clear,
sctp_ss_fcfs_init_stream, sctp_ss_fcfs_init_stream,

View File

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

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#include <netinet/sctp_os.h> #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/sctp_pcb.h>
#include <netinet/sctputil.h> #include <netinet/sctputil.h>
#include <netinet/sctp_output.h> #include <netinet/sctp_output.h>
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/smp.h> #include <sys/smp.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
#include <netinet/sctp_bsd_addr.h> #include <netinet/sctp_bsd_addr.h>
#endif #endif
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
FEATURE(sctp, "Stream Control Transmission Protocol"); FEATURE(sctp, "Stream Control Transmission Protocol");
#endif #endif
@ -74,7 +74,7 @@ sctp_init_sysctls()
SCTP_BASE_SYSCTL(sctp_reconfig_enable) = SCTPCTL_RECONFIG_ENABLE_DEFAULT; SCTP_BASE_SYSCTL(sctp_reconfig_enable) = SCTPCTL_RECONFIG_ENABLE_DEFAULT;
SCTP_BASE_SYSCTL(sctp_nrsack_enable) = SCTPCTL_NRSACK_ENABLE_DEFAULT; SCTP_BASE_SYSCTL(sctp_nrsack_enable) = SCTPCTL_NRSACK_ENABLE_DEFAULT;
SCTP_BASE_SYSCTL(sctp_pktdrop_enable) = SCTPCTL_PKTDROP_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; SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) = SCTPCTL_LOOPBACK_NOCSUM_DEFAULT;
#endif #endif
SCTP_BASE_SYSCTL(sctp_peer_chunk_oh) = SCTPCTL_PEER_CHKOH_DEFAULT; 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_sendall_limit) = SCTPCTL_SENDALL_LIMIT_DEFAULT;
SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT; SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT;
#if defined(SCTP_LOCAL_TRACE_BUF) #if defined(SCTP_LOCAL_TRACE_BUF)
#if defined(__Windows__) #if defined(_WIN32) && !defined(__Userspace__)
/* On Windows, the resource for global variables is limited. */ /* 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); MALLOC(SCTP_BASE_SYSCTL(sctp_log), struct sctp_log *, sizeof(struct sctp_log), M_SYSCTL, M_ZERO);
#else #else
@ -165,18 +165,18 @@ sctp_init_sysctls()
#if defined(SCTP_DEBUG) #if defined(SCTP_DEBUG)
SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT; SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT;
#endif #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_ignore_vmware_interfaces) = SCTPCTL_IGNORE_VMWARE_INTERFACES_DEFAULT;
SCTP_BASE_SYSCTL(sctp_main_timer) = SCTPCTL_MAIN_TIMER_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_addr_watchdog_limit) = SCTPCTL_ADDR_WATCHDOG_LIMIT_DEFAULT;
SCTP_BASE_SYSCTL(sctp_vtag_watchdog_limit) = SCTPCTL_VTAG_WATCHDOG_LIMIT_DEFAULT; SCTP_BASE_SYSCTL(sctp_vtag_watchdog_limit) = SCTPCTL_VTAG_WATCHDOG_LIMIT_DEFAULT;
#endif #endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) #if defined(__APPLE__) && !defined(__Userspace__)
SCTP_BASE_SYSCTL(sctp_output_unlocked) = SCTPCTL_OUTPUT_UNLOCKED_DEFAULT; SCTP_BASE_SYSCTL(sctp_output_unlocked) = SCTPCTL_OUTPUT_UNLOCKED_DEFAULT;
#endif #endif
} }
#if defined(_WIN32) && !defined(__Userspace__)
#if defined(__Windows__)
void void
sctp_finish_sysctls() sctp_finish_sysctls()
{ {
@ -189,7 +189,7 @@ sctp_finish_sysctls()
} }
#endif #endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__Windows__) #if !defined(__Userspace__)
/* It returns an upper limit. No filtering is done here */ /* It returns an upper limit. No filtering is done here */
static unsigned int static unsigned int
sctp_sysctl_number_of_addresses(struct sctp_inpcb *inp) 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; sin = &sctp_ifa->address.sin;
if (sin->sin_addr.s_addr == 0) if (sin->sin_addr.s_addr == 0)
continue; continue;
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(inp->ip_inp.inp.inp_cred, if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) { &sin->sin_addr) != 0) {
continue; continue;
@ -350,7 +350,7 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st
sin6 = &sctp_ifa->address.sin6; sin6 = &sctp_ifa->address.sin6;
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
continue; continue;
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(inp->ip_inp.inp.inp_cred, if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) { &sin6->sin6_addr) != 0) {
continue; continue;
@ -428,7 +428,7 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st
/* /*
* sysctl functions * sysctl functions
*/ */
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
static int static int
sctp_sysctl_handle_assoclist SYSCTL_HANDLER_ARGS sctp_sysctl_handle_assoclist SYSCTL_HANDLER_ARGS
{ {
@ -458,7 +458,7 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
number_of_remote_addresses = 0; number_of_remote_addresses = 0;
SCTP_INP_INFO_RLOCK(); SCTP_INP_INFO_RLOCK();
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
if (req->oldptr == USER_ADDR_NULL) { if (req->oldptr == USER_ADDR_NULL) {
#else #else
if (req->oldptr == NULL) { 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); (number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
/* request some more memory than needed */ /* request some more memory than needed */
#if !defined(__Windows__) #if !(defined(_WIN32) && !defined(__Userspace__))
req->oldidx = (n + n / 8); req->oldidx = (n + n / 8);
#else #else
req->dataidx = (n + n / 8); req->dataidx = (n + n / 8);
#endif #endif
return (0); return (0);
} }
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
if (req->newptr != USER_ADDR_NULL) { if (req->newptr != USER_ADDR_NULL) {
#else #else
if (req->newptr != NULL) { if (req->newptr != NULL) {
@ -511,16 +511,12 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xinpcb.last = 0; xinpcb.last = 0;
xinpcb.local_port = ntohs(inp->sctp_lport); xinpcb.local_port = ntohs(inp->sctp_lport);
xinpcb.flags = inp->sctp_flags; xinpcb.flags = inp->sctp_flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 1000048
xinpcb.features = (uint32_t)inp->sctp_features;
#else
xinpcb.features = inp->sctp_features; xinpcb.features = inp->sctp_features;
#endif
xinpcb.total_sends = inp->total_sends; xinpcb.total_sends = inp->total_sends;
xinpcb.total_recvs = inp->total_recvs; xinpcb.total_recvs = inp->total_recvs;
xinpcb.total_nospaces = inp->total_nospaces; xinpcb.total_nospaces = inp->total_nospaces;
xinpcb.fragmentation_point = inp->sctp_frag_point; xinpcb.fragmentation_point = inp->sctp_frag_point;
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
xinpcb.socket = (uintptr_t)inp->sctp_socket; xinpcb.socket = (uintptr_t)inp->sctp_socket;
#else #else
xinpcb.socket = inp->sctp_socket; xinpcb.socket = inp->sctp_socket;
@ -532,33 +528,16 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xinpcb.qlen = 0; xinpcb.qlen = 0;
xinpcb.maxqlen = 0; xinpcb.maxqlen = 0;
} else { } else {
#if defined(__FreeBSD__) && __FreeBSD_version >= 1200034 #if defined(__FreeBSD__) && !defined(__Userspace__)
xinpcb.qlen = so->sol_qlen; 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 ? xinpcb.qlen_old = so->sol_qlen > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->sol_qlen; 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; 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 ? xinpcb.maxqlen_old = so->sol_qlimit > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->sol_qlimit; USHRT_MAX : (uint16_t) so->sol_qlimit;
#else #else
xinpcb.maxqlen_old = so->so_qlimit > USHRT_MAX ? xinpcb.qlen = so->so_qlen;
USHRT_MAX : (uint16_t) so->so_qlimit; xinpcb.maxqlen = so->so_qlimit;
#endif
#endif #endif
} }
SCTP_INP_INCR_REF(inp); 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.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay; xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
xstcb.state = (uint32_t)sctp_map_assoc_state(stcb->asoc.state); 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.assoc_id = sctp_get_associd(stcb);
xstcb.peers_rwnd = stcb->asoc.peers_rwnd; 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.in_streams = stcb->asoc.streamincnt;
xstcb.out_streams = stcb->asoc.streamoutcnt; xstcb.out_streams = stcb->asoc.streamoutcnt;
xstcb.max_nr_retrans = stcb->asoc.overall_error_count; 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.cwnd = net->cwnd;
xraddr.flight_size = net->flight_size; xraddr.flight_size = net->flight_size;
xraddr.mtu = net->mtu; xraddr.mtu = net->mtu;
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
xraddr.rtt = net->rtt / 1000; xraddr.rtt = net->rtt / 1000;
xraddr.heartbeat_interval = net->heart_beat_delay; xraddr.heartbeat_interval = net->heart_beat_delay;
xraddr.ssthresh = net->ssthresh; xraddr.ssthresh = net->ssthresh;
@ -661,20 +630,6 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
} else { } else {
xraddr.state = SCTP_INACTIVE; 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_sec = (uint32_t)net->start_time.tv_sec;
xraddr.start_time.tv_usec = (uint32_t)net->start_time.tv_usec; xraddr.start_time.tv_usec = (uint32_t)net->start_time.tv_usec;
SCTP_INP_RUNLOCK(inp); SCTP_INP_RUNLOCK(inp);
@ -721,7 +676,7 @@ skip:
return (error); return (error);
} }
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
static int static int
sctp_sysctl_handle_udp_tunneling SYSCTL_HANDLER_ARGS 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); old = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
SCTP_INP_INFO_RUNLOCK(); SCTP_INP_INFO_RUNLOCK();
new = old; 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); error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) && if ((error == 0) &&
#if defined (__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) { (req->newptr != USER_ADDR_NULL)) {
#else #else
(req->newptr != NULL)) { (req->newptr != NULL)) {
#endif #endif
#if defined(__Windows__) #if defined(_WIN32) && !defined(__Userspace__)
SCTP_INP_INFO_WLOCK(); SCTP_INP_INFO_WLOCK();
sctp_over_udp_restart(); sctp_over_udp_restart();
SCTP_INP_INFO_WUNLOCK(); SCTP_INP_INFO_WUNLOCK();
@ -780,8 +727,8 @@ sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
} }
return (error); return (error);
} }
#if defined(__APPLE__) && !defined(__Userspace__)
#if defined(__APPLE__)
int sctp_is_vmware_interface(struct ifnet *); int sctp_is_vmware_interface(struct ifnet *);
static int static int
@ -814,7 +761,7 @@ sctp_sysctl_handle_vmware_interfaces SYSCTL_HANDLER_ARGS
} }
#endif #endif
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
static int static int
sctp_sysctl_handle_auth SYSCTL_HANDLER_ARGS sctp_sysctl_handle_auth SYSCTL_HANDLER_ARGS
{ {
@ -828,17 +775,9 @@ sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
uint32_t new; uint32_t new;
new = SCTP_BASE_SYSCTL(sctp_auth_enable); 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); error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) && if ((error == 0) &&
#if defined (__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) { (req->newptr != USER_ADDR_NULL)) {
#else #else
(req->newptr != NULL)) { (req->newptr != NULL)) {
@ -859,7 +798,7 @@ sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
return (error); return (error);
} }
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
static int static int
sctp_sysctl_handle_asconf SYSCTL_HANDLER_ARGS sctp_sysctl_handle_asconf SYSCTL_HANDLER_ARGS
{ {
@ -873,17 +812,9 @@ sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
uint32_t new; uint32_t new;
new = SCTP_BASE_SYSCTL(sctp_asconf_enable); 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); error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) && if ((error == 0) &&
#if defined (__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) { (req->newptr != USER_ADDR_NULL)) {
#else #else
(req->newptr != NULL)) { (req->newptr != NULL)) {
@ -904,7 +835,7 @@ sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
return (error); return (error);
} }
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
static int static int
sctp_sysctl_handle_stats SYSCTL_HANDLER_ARGS sctp_sysctl_handle_stats SYSCTL_HANDLER_ARGS
{ {
@ -915,7 +846,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
{ {
#endif #endif
int error; int error;
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT) #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
struct sctpstat *sarry; struct sctpstat *sarry;
struct sctpstat sb; struct sctpstat sb;
@ -924,7 +855,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
struct sctpstat sb_temp; struct sctpstat sb_temp;
#endif #endif
#if defined (__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
if ((req->newptr != USER_ADDR_NULL) && if ((req->newptr != USER_ADDR_NULL) &&
#else #else
if ((req->newptr != NULL) && if ((req->newptr != NULL) &&
@ -932,7 +863,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
(req->newlen != sizeof(struct sctpstat))) { (req->newlen != sizeof(struct sctpstat))) {
return (EINVAL); return (EINVAL);
} }
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
memset(&sb_temp, 0, sizeof(struct sctpstat)); memset(&sb_temp, 0, sizeof(struct sctpstat));
if (req->newptr != NULL) { if (req->newptr != NULL) {
@ -1089,7 +1020,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
} }
#if defined(SCTP_LOCAL_TRACE_BUF) #if defined(SCTP_LOCAL_TRACE_BUF)
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
static int static int
sctp_sysctl_handle_trace_log SYSCTL_HANDLER_ARGS sctp_sysctl_handle_trace_log SYSCTL_HANDLER_ARGS
{ {
@ -1101,7 +1032,7 @@ sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
#endif #endif
int error; int error;
#if defined(__Windows__) #if defined(_WIN32) && !defined(__Userspace__)
error = SYSCTL_OUT(req, SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log)); error = SYSCTL_OUT(req, SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
#else #else
error = SYSCTL_OUT(req, &SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log)); 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); return (error);
} }
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
static int static int
sctp_sysctl_handle_trace_log_clear SYSCTL_HANDLER_ARGS sctp_sysctl_handle_trace_log_clear SYSCTL_HANDLER_ARGS
{ {
@ -1120,7 +1051,7 @@ sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
{ {
#endif #endif
int error = 0; int error = 0;
#if defined(__Windows__) #if defined(_WIN32) && !defined(__Userspace__)
int value = 0; int value = 0;
if (req->new_data == NULL) { if (req->new_data == NULL) {
@ -1138,33 +1069,8 @@ sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
} }
#endif #endif
#if defined(__APPLE__) || defined(__FreeBSD__) #if (defined(__APPLE__) || defined(__FreeBSD__)) && !defined(__Userspace__)
#if defined(__FreeBSD__) #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) \ #define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \
static int \ static int \
sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS) \ 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, \ SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name, \
CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, \ CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, \
sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC); 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 #else
#define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \ #define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \
static int \ 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(reconfig_enable, sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE) SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
SCTP_UINT_SYSCTL(pktdrop_enable, sctp_pktdrop_enable, SCTPCTL_PKTDROP_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) SCTP_UINT_SYSCTL(loopback_nocsum, sctp_no_csum_on_loopback, SCTPCTL_LOOPBACK_NOCSUM)
#endif #endif
SCTP_UINT_SYSCTL(peer_chkoh, sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH) 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 #ifdef SCTP_DEBUG
SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG) SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG)
#endif #endif
#if defined(__APPLE__) #if defined(__APPLE__) && !defined(__Userspace__)
SCTP_UINT_SYSCTL(main_timer, sctp_main_timer, SCTPCTL_MAIN_TIMER) 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, 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); 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(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) SCTP_UINT_SYSCTL(vtag_watchdog_limit, sctp_vtag_watchdog_limit, SCTPCTL_VTAG_WATCHDOG_LIMIT)
#endif #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) SCTP_UINT_SYSCTL(output_unlocked, sctp_output_unlocked, SCTPCTL_OUTPUT_UNLOCKED)
#endif #endif
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_VNET|CTLTYPE_STRUCT|CTLFLAG_RW, 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, 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"); 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) \ #define RANGECHK(var, min, max) \
if ((var) < (min)) { (var) = (min); } \ if ((var) < (min)) { (var) = (min); } \

View File

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

View File

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

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #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 #endif
#ifndef _NETINET_SCTP_TIMER_H_ #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 #define SCTP_RTT_VAR_SHIFT 2
struct sctp_nets * struct sctp_nets *
sctp_find_alternate_net(struct sctp_tcb *, sctp_find_alternate_net(struct sctp_tcb *, struct sctp_nets *, int);
struct sctp_nets *, int mode);
int int
sctp_t3rxt_timer(struct sctp_inpcb *, struct sctp_tcb *, sctp_t3rxt_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *); struct sctp_nets *);
int int
sctp_t1init_timer(struct sctp_inpcb *, struct sctp_tcb *, sctp_t1init_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *); struct sctp_nets *);
int int
sctp_shutdown_timer(struct sctp_inpcb *, struct sctp_tcb *, sctp_shutdown_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *); struct sctp_nets *);
int int
sctp_heartbeat_timer(struct sctp_inpcb *, struct sctp_tcb *, sctp_heartbeat_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *); struct sctp_nets *);
@ -74,32 +76,28 @@ int
sctp_shutdownack_timer(struct sctp_inpcb *, struct sctp_tcb *, sctp_shutdownack_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *); struct sctp_nets *);
int int
sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, sctp_strreset_timer(struct sctp_inpcb *, struct sctp_tcb *);
struct sctp_nets *net);
int int
sctp_asconf_timer(struct sctp_inpcb *, struct sctp_tcb *, sctp_asconf_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *); struct sctp_nets *);
void void
sctp_delete_prim_timer(struct sctp_inpcb *, struct sctp_tcb *, sctp_delete_prim_timer(struct sctp_inpcb *, struct sctp_tcb *);
struct sctp_nets *);
void void
sctp_autoclose_timer(struct sctp_inpcb *, struct sctp_tcb *, sctp_autoclose_timer(struct sctp_inpcb *, struct sctp_tcb *);
struct sctp_nets *net);
void sctp_audit_retranmission_queue(struct sctp_association *); void sctp_audit_retranmission_queue(struct sctp_association *);
void sctp_iterator_timer(struct sctp_iterator *it); 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) #if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
void sctp_slowtimo(void); void sctp_slowtimo(void);
#else #else
void sctp_gc(struct inpcbinfo *); void sctp_gc(struct inpcbinfo *);
#endif #endif
#endif #endif
#endif #endif
#endif #endif

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __FreeBSD__ #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 352592 2019-09-22 10:40:15Z tuexen $"); __FBSDID("$FreeBSD$");
#endif #endif
#ifndef _NETINET_SCTP_UTIL_H_ #ifndef _NETINET_SCTP_UTIL_H_
@ -57,14 +57,13 @@ void sctp_m_freem(struct mbuf *m);
#define sctp_m_freem m_freem #define sctp_m_freem m_freem
#endif #endif
#if defined(SCTP_LOCAL_TRACE_BUF) || defined(__APPLE__) #if defined(SCTP_LOCAL_TRACE_BUF)
void 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); 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 #endif
#define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id) #define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id)
/* /*
* Function prototypes * 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); 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 *); 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 void
sctp_notify_stream_reset_tsn(struct sctp_tcb *stcb, uint32_t sending_tsn, uint32_t recv_tsn, int flag); 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 void
sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *, sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *); struct sctp_nets *);
@ -111,7 +118,7 @@ sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t);
void void
sctp_wakeup_the_read_socket(struct sctp_inpcb *inp, struct sctp_tcb *stcb, sctp_wakeup_the_read_socket(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
int so_locked int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) #if !(defined(__APPLE__) && !defined(__Userspace__))
SCTP_UNUSED SCTP_UNUSED
#endif #endif
); );
@ -130,11 +137,7 @@ sctp_add_to_readq(struct sctp_inpcb *inp,
struct sockbuf *sb, struct sockbuf *sb,
int end, int end,
int inpread_locked, int inpread_locked,
int so_locked int so_locked);
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_iterator_worker(void); void sctp_iterator_worker(void);
@ -162,60 +165,45 @@ sctp_add_pad_tombuf(struct mbuf *, int);
struct mbuf * struct mbuf *
sctp_pad_lastmbuf(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 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 void
sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp, sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
struct sctp_inpcb *new_inp, struct sctp_inpcb *new_inp,
struct sctp_tcb *stcb, int waitflags); struct sctp_tcb *stcb, int waitflags);
void sctp_stop_timers_for_shutdown(struct sctp_tcb *); void sctp_stop_timers_for_shutdown(struct sctp_tcb *);
void sctp_report_all_outbound(struct sctp_tcb *, uint16_t, int, int /* Stop all timers for association and remote addresses. */
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING) void sctp_stop_association_timers(struct sctp_tcb *, bool);
SCTP_UNUSED
#endif void sctp_report_all_outbound(struct sctp_tcb *, uint16_t, int);
);
int sctp_expand_mapping_array(struct sctp_association *, uint32_t); int sctp_expand_mapping_array(struct sctp_association *, uint32_t);
void sctp_abort_notification(struct sctp_tcb *, uint8_t, uint16_t, void sctp_abort_notification(struct sctp_tcb *, bool, bool, uint16_t,
struct sctp_abort_chunk *, int struct sctp_abort_chunk *, int);
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
/* We abort responding to an IP packet for some reason */ /* We abort responding to an IP packet for some reason */
void void
sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, struct mbuf *, sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, struct mbuf *,
int, struct sockaddr *, struct sockaddr *, int, struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct mbuf *, struct sctphdr *, struct mbuf *,
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint8_t, uint32_t,
#endif #endif
uint32_t, uint16_t); uint32_t, uint16_t);
/* We choose to abort via user input */ /* We choose to abort via user input */
void void
sctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *, sctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *,
struct mbuf *, int struct mbuf *, bool, int);
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_handle_ootb(struct mbuf *, int, int, void sctp_handle_ootb(struct mbuf *, int, int,
struct sockaddr *, struct sockaddr *, struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct sctp_inpcb *, struct sctphdr *, struct sctp_inpcb *,
struct mbuf *, struct mbuf *,
#if defined(__FreeBSD__) #if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t, uint8_t, uint32_t, uint16_t,
#endif #endif
uint32_t, uint16_t); uint32_t, uint16_t);
@ -276,21 +264,16 @@ void sctp_print_address(struct sockaddr *);
int int
sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *, sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *,
uint8_t, int uint8_t, int);
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
struct mbuf *sctp_generate_cause(uint16_t, char *); struct mbuf *sctp_generate_cause(uint16_t, char *);
struct mbuf *sctp_generate_no_user_data_cause(uint32_t); struct mbuf *sctp_generate_no_user_data_cause(uint32_t);
void sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp, void sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp,
struct sockaddr *sa, sctp_assoc_t assoc_id, struct sockaddr *sa, uint32_t vrf_id, int *error,
uint32_t vrf_id, int *error, void *p); void *p);
void sctp_bindx_delete_address(struct sctp_inpcb *inp, void sctp_bindx_delete_address(struct sctp_inpcb *inp, struct sockaddr *sa,
struct sockaddr *sa, sctp_assoc_t assoc_id, uint32_t vrf_id, int *error);
uint32_t vrf_id, int *error);
int sctp_local_addr_count(struct sctp_tcb *stcb); int sctp_local_addr_count(struct sctp_tcb *stcb);
@ -352,11 +335,11 @@ do { \
} while (0) } while (0)
/* functions to start/stop udp tunneling */ /* functions to start/stop udp tunneling */
#if defined(__APPLE__) || defined(__FreeBSD__) #if (defined(__APPLE__) || defined(__FreeBSD__)) && !defined(__Userspace__)
void sctp_over_udp_stop(void); void sctp_over_udp_stop(void);
int sctp_over_udp_start(void); int sctp_over_udp_start(void);
#endif #endif
#if defined(__Windows__) #if defined(_WIN32) && !defined(__Userspace__)
void sctp_over_udp_restart(void); void sctp_over_udp_restart(void);
#endif #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); void sctp_log_nagle_event(struct sctp_tcb *stcb, int action);
#ifdef SCTP_MBUF_LOGGING #ifdef SCTP_MBUF_LOGGING
void void
sctp_log_mb(struct mbuf *m, int from); 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_print_mapping_array(struct sctp_association *asoc);
void sctp_clr_stat_log(void); void sctp_clr_stat_log(void);
#ifdef SCTP_AUDITING_ENABLED #ifdef SCTP_AUDITING_ENABLED
void void
sctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *, sctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *,
@ -421,11 +402,16 @@ void sctp_audit_log(uint8_t, uint8_t);
#endif #endif
uint32_t sctp_min_mtu(uint32_t, uint32_t, uint32_t); 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); void sctp_hc_set_mtu(union sctp_sockstore *, uint16_t, uint32_t);
uint32_t sctp_hc_get_mtu(union sctp_sockstore *, uint16_t); uint32_t sctp_hc_get_mtu(union sctp_sockstore *, uint16_t);
#endif #endif
void sctp_set_state(struct sctp_tcb *, int); void sctp_set_state(struct sctp_tcb *, int);
void sctp_add_substate(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 /* _KERNEL */
#endif #endif

View File

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

View File

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

View File

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

View File

@ -30,18 +30,23 @@
/* __Userspace__ */ /* __Userspace__ */
#include <stdlib.h> #if defined(_WIN32)
#if !defined (__Userspace_os_Windows) #if !defined(_CRT_RAND_S) && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
#define _CRT_RAND_S
#endif
#else
#include <stdint.h> #include <stdint.h>
#include <netinet/sctp_os_userspace.h> #include <netinet/sctp_os_userspace.h>
#endif #endif
#ifdef INVARIANTS
#include <netinet/sctp_pcb.h>
#endif
#include <user_environment.h> #include <user_environment.h>
#include <sys/types.h> #include <sys/types.h>
/* #include <sys/param.h> defines MIN */ /* #include <sys/param.h> defines MIN */
#if !defined(MIN) #if !defined(MIN)
#define MIN(arg1,arg2) ((arg1) < (arg2) ? (arg1) : (arg2)) #define MIN(arg1,arg2) ((arg1) < (arg2) ? (arg1) : (arg2))
#endif #endif
#include <string.h>
#define uHZ 1000 #define uHZ 1000
@ -64,50 +69,316 @@ userland_mutex_t atomic_mtx;
* provide _some_ kind of randomness. This should only be used * provide _some_ kind of randomness. This should only be used
* inside other RNG's, like arc4random(9). * inside other RNG's, like arc4random(9).
*/ */
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION #if defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
static int #include <string.h>
read_random_phony(void *buf, int count)
void
init_random(void)
{ {
memset(buf, 'A', count); return;
return (count);
} }
#else
#if defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Darwin) void
static int read_random(void *buf, size_t size)
read_random_phony(void *buf, int count)
{ {
if (count >= 0) { memset(buf, 'A', size);
arc4random_buf(buf, count); 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 void
read_random_phony(void *buf, int count) finish_random(void)
{ {
uint32_t randval; return;
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);
} }
#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
#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 */ void
int init_random(void)
read_random(void *buf, int count)
{ {
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__ */ /* __Userspace__ */
#include <sys/types.h> #include <sys/types.h>
#ifdef __Userspace_os_FreeBSD #ifdef __FreeBSD__
#ifndef _SYS_MUTEX_H_ #ifndef _SYS_MUTEX_H_
#include <sys/mutex.h> #include <sys/mutex.h>
#endif #endif
#endif #endif
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
#include "netinet/sctp_os_userspace.h" #include "netinet/sctp_os_userspace.h"
#endif #endif
@ -63,11 +63,13 @@ extern int ipport_firstauto, ipport_lastauto;
extern int nmbclusters; extern int nmbclusters;
#if !defined(_MSC_VER) && !defined(__MINGW32__) #if !defined(_MSC_VER) && !defined(__MINGW32__)
#define min(a,b) ((a)>(b)?(b):(a)) #define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b)) #define max(a,b) (((a)>(b))?(a):(b))
#endif #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 */ /* errno's may differ per OS. errno.h now included in sctp_os_userspace.h */
/* Source: /usr/src/sys/sys/errno.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 */ /* Source ip_output.c. extern'd in ip_var.h */
extern u_short ip_id; extern u_short ip_id;
#if defined(__Userspace_os_Linux) #if defined(__linux__)
#define IPV6_VERSION 0x60 #define IPV6_VERSION 0x60
#endif #endif
#if defined(INVARIANTS) #if defined(INVARIANTS)
#include <stdlib.h> #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) { terminate_non_graceful(void) {
abort(); abort();
} }

View File

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

View File

@ -39,7 +39,7 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@ -60,16 +60,16 @@
#ifndef _USER_IP6_VAR_H_ #ifndef _USER_IP6_VAR_H_
#define _USER_IP6_VAR_H_ #define _USER_IP6_VAR_H_
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
struct ip6_hdr { struct ip6_hdr {
union { union {
struct ip6_hdrctl { struct ip6_hdrctl {
u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */ uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
u_int16_t ip6_un1_plen; /* payload length */ uint16_t ip6_un1_plen; /* payload length */
u_int8_t ip6_un1_nxt; /* next header */ uint8_t ip6_un1_nxt; /* next header */
u_int8_t ip6_un1_hlim; /* hop limit */ uint8_t ip6_un1_hlim; /* hop limit */
} ip6_un1; } 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; } ip6_ctlun;
struct in6_addr ip6_src; /* source address */ struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */ struct in6_addr ip6_dst; /* destination address */
@ -84,18 +84,16 @@ struct ip6_hdr {
#define IPV6_VERSION 0x60 #define IPV6_VERSION 0x60
#endif #endif
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
#define s6_addr16 u.Word #define s6_addr16 u.Word
#endif #endif
#if !defined(__Userspace_os_Windows) #if !defined(_WIN32) && !defined(__linux__) && !defined(__EMSCRIPTEN__)
#if !defined(__Userspace_os_Linux)
#define s6_addr8 __u6_addr.__u6_addr8 #define s6_addr8 __u6_addr.__u6_addr8
#define s6_addr16 __u6_addr.__u6_addr16 #define s6_addr16 __u6_addr.__u6_addr16
#define s6_addr32 __u6_addr.__u6_addr32 #define s6_addr32 __u6_addr.__u6_addr32
#endif #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 route_in6 {
struct rtentry *ro_rt; struct rtentry *ro_rt;
struct llentry *ro_lle; struct llentry *ro_lle;

View File

@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@ -40,8 +40,8 @@
* Internal of an ICMP Router Advertisement * Internal of an ICMP Router Advertisement
*/ */
struct icmp_ra_addr { struct icmp_ra_addr {
u_int32_t ira_addr; uint32_t ira_addr;
u_int32_t ira_preference; uint32_t ira_preference;
}; };
/* /*
@ -53,16 +53,16 @@ struct icmphdr {
u_short icmp_cksum; /* ones complement cksum of struct */ u_short icmp_cksum; /* ones complement cksum of struct */
}; };
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
#pragma pack (push, 1) #pragma pack (push, 1)
struct icmp6_hdr { struct icmp6_hdr {
u_int8_t icmp6_type; uint8_t icmp6_type;
u_int8_t icmp6_code; uint8_t icmp6_code;
u_int16_t icmp6_cksum; uint16_t icmp6_cksum;
union { union {
u_int32_t icmp6_un_data32[1]; uint32_t icmp6_un_data32[1];
u_int16_t icmp6_un_data16[2]; uint16_t icmp6_un_data16[2];
u_int8_t icmp6_un_data8[4]; uint8_t icmp6_un_data8[4];
} icmp6_dataun; } icmp6_dataun;
}; };
#pragma pack(pop) #pragma pack(pop)
@ -98,7 +98,7 @@ struct icmp {
struct ih_rtradv { struct ih_rtradv {
u_char irt_num_addrs; u_char irt_num_addrs;
u_char irt_wpa; u_char irt_wpa;
u_int16_t irt_lifetime; uint16_t irt_lifetime;
} ih_rtradv; } ih_rtradv;
} icmp_hun; } icmp_hun;
#define icmp_pptr icmp_hun.ih_pptr #define icmp_pptr icmp_hun.ih_pptr
@ -126,7 +126,7 @@ struct icmp {
/* options and then 64 bits of data */ /* options and then 64 bits of data */
} id_ip; } id_ip;
struct icmp_ra_addr id_radv; struct icmp_ra_addr id_radv;
u_int32_t id_mask; uint32_t id_mask;
char id_data[1]; char id_data[1];
} icmp_dun; } icmp_dun;
#define icmp_otime icmp_dun.id_ts.its_otime #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 * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@ -37,7 +37,7 @@
/*__Userspace__*/ /*__Userspace__*/
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#if !defined (__Userspace_os_Windows) #if !defined(_WIN32)
#include <strings.h> #include <strings.h>
#include <stdint.h> #include <stdint.h>
#else #else
@ -200,67 +200,4 @@ Start copy: Copied code for __Userspace__ */
} \ } \
} while (0); } 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_ */ #endif /* !_SYS_MALLOC_H_ */

View File

@ -46,7 +46,6 @@
#include "user_atomic.h" #include "user_atomic.h"
#include "netinet/sctp_pcb.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_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)*/ #define KIPC_MAX_PROTOHDR 5 /* int: max length of network header (see sys/sysclt.h)*/
int max_linkhdr = KIPC_MAX_LINKHDR; 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) static int mbuf_constructor_dup(struct mbuf *m, int pkthdr, short type)
{ {
int flags = pkthdr; int flags = pkthdr;
if (type == MT_NOINIT)
return (0);
m->m_next = NULL; m->m_next = NULL;
m->m_nextpkt = NULL; m->m_nextpkt = NULL;
@ -272,9 +269,9 @@ m_clget(struct mbuf *m, int how)
mclust_ret = SCTP_ZONE_GET(zone_clust, char); mclust_ret = SCTP_ZONE_GET(zone_clust, char);
#endif #endif
/*mclust_ret = umem_cache_alloc(zone_clust, UMEM_DEFAULT);*/ /*mclust_ret = umem_cache_alloc(zone_clust, UMEM_DEFAULT);*/
if (NULL == mclust_ret) { /* if (NULL == mclust_ret) { */
SCTPDBG(SCTP_DEBUG_USR, "Memory allocation failure in %s\n", __func__); SCTPDBG(SCTP_DEBUG_USR, "Memory allocation failure in %s\n", __func__);
} /* } */
} }
#if USING_MBUF_CONSTRUCTOR #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) m_getm2(struct mbuf *m, int len, int how, short type, int flags, int allonebuf)
{ {
struct mbuf *mb, *nm = NULL, *mtail = NULL; 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__)); 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. * XXX probably should be called m_tag_init, but that was already taken.
*/ */
static __inline void 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; t->m_tag_id = type;
@ -507,7 +504,7 @@ mbuf_initialize(void *dummy)
#else #else
zone_mbuf = umem_cache_create(MBUF_MEM_NAME, MSIZE, 0, zone_mbuf = umem_cache_create(MBUF_MEM_NAME, MSIZE, 0,
mb_ctor_mbuf, mb_dtor_mbuf, NULL, mb_ctor_mbuf, mb_dtor_mbuf, NULL,
NUULL, NULL,
NULL, 0); NULL, 0);
#endif #endif
/*zone_ext_refcnt = umem_cache_create(MBUF_EXTREFCNT_MEM_NAME, sizeof(u_int), 0, /*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; flags = args->flags;
type = args->type; type = args->type;
/*
* The mbuf is initialized later.
*
*/
if (type == MT_NOINIT)
return (0);
m->m_next = NULL; m->m_next = NULL;
m->m_nextpkt = NULL; m->m_nextpkt = NULL;
m->m_len = 0; m->m_len = 0;
@ -909,7 +879,6 @@ m_pullup(struct mbuf *n, int len)
return (m); return (m);
bad: bad:
m_freem(n); m_freem(n);
mbstat.m_mpfail++; /* XXX: No consistency. */
return (NULL); return (NULL);
} }
@ -1045,16 +1014,14 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
* easy cases first. * easy cases first.
* we need to use m_copydata() to get data from <n->m_next, 0>. * we need to use m_copydata() to get data from <n->m_next, 0>.
*/ */
if ((off == 0 || offp) && M_TRAILINGSPACE(n) >= tlen if ((off == 0 || offp) && (M_TRAILINGSPACE(n) >= tlen) && writable) {
&& writable) {
m_copydata(n->m_next, 0, tlen, mtod(n, caddr_t) + n->m_len); m_copydata(n->m_next, 0, tlen, mtod(n, caddr_t) + n->m_len);
n->m_len += tlen; n->m_len += tlen;
m_adj(n->m_next, tlen); m_adj(n->m_next, tlen);
goto ok; goto ok;
} }
if ((off == 0 || offp) && M_LEADINGSPACE(n->m_next) >= hlen if ((off == 0 || offp) && (M_LEADINGSPACE(n->m_next) >= hlen) && writable) {
&& writable) {
n->m_next->m_data -= hlen; n->m_next->m_data -= hlen;
n->m_next->m_len += hlen; n->m_next->m_len += hlen;
memcpy( mtod(n->m_next, caddr_t), mtod(n, caddr_t) + off,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; m = m->m_next;
np = &n->m_next; np = &n->m_next;
} }
if (top == NULL)
mbstat.m_mcfail++; /* XXX: No consistency. */
return (top); return (top);
nospace: nospace:
m_freem(top); m_freem(top);
mbstat.m_mcfail++; /* XXX: No consistency. */
return (NULL); 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. */ /* Get a packet tag structure along with specified data following. */
struct m_tag * 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; 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 m_adj(struct mbuf *, int);
void mb_free_ext(struct mbuf *); void mb_free_ext(struct mbuf *);
void m_freem(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); struct mbuf *m_copym(struct mbuf *, int, int, int);
void m_copyback(struct mbuf *, int, int, caddr_t); void m_copyback(struct mbuf *, int, int, caddr_t);
struct mbuf *m_pullup(struct mbuf *, int); 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_CLUSTER_MEM_NAME "mbuf_cluster"
#define MBUF_EXTREFCNT_MEM_NAME "mbuf_ext_refcnt" #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. * 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 * An mbuf may add a single "mbuf cluster" of size MCLBYTES (also in
@ -190,9 +158,9 @@ struct m_hdr {
*/ */
struct m_tag { struct m_tag {
SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */ SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
u_int16_t m_tag_id; /* Tag ID */ uint16_t m_tag_id; /* Tag ID */
u_int16_t m_tag_len; /* Length of data */ uint16_t m_tag_len; /* Length of data */
u_int32_t m_tag_cookie; /* ABI/Module ID */ uint32_t m_tag_cookie; /* ABI/Module ID */
void (*m_tag_free)(struct m_tag *); void (*m_tag_free)(struct m_tag *);
}; };
@ -207,8 +175,8 @@ struct pkthdr {
/* variables for hardware checksum */ /* variables for hardware checksum */
int csum_flags; /* flags regarding checksum */ int csum_flags; /* flags regarding checksum */
int csum_data; /* data field used by csum routines */ int csum_data; /* data field used by csum routines */
u_int16_t tso_segsz; /* TSO segment size */ uint16_t tso_segsz; /* TSO segment size */
u_int16_t ether_vtag; /* Ethernet 802.1p+q vlan tag */ uint16_t ether_vtag; /* Ethernet 802.1p+q vlan tag */
SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */ 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_OOBDATA 15 /* expedited data */
#define MT_NTYPES 16 /* number of mbuf types for mbtypes[] */ #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 * __Userspace__ flags like M_NOWAIT are defined in malloc.h
* Flags like these are used in functions like uma_zalloc() * 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_linkhdr; /* Largest link-level header */
extern int max_protohdr; /* Size of largest protocol layer header. See user_mbuf.c */ 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 * 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 * 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. * of checking writability of the mbuf data area rests solely with the caller.
*/ */
#define M_LEADINGSPACE(m) \ #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_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) (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. * of checking writability of the mbuf data area rests solely with the caller.
*/ */
#define M_TRAILINGSPACE(m) \ #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_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \
- ((m)->m_data + (m)->m_len) : 0) : \ - ((m)->m_data + (m)->m_len) : 0) : \
&(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len)) &(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); \ (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \
} while (0) } while (0)
#define M_SIZE(m) \
(((m)->m_flags & M_EXT) ? (m)->m_ext.ext_size : \
((m)->m_flags & M_PKTHDR) ? MHLEN : \
MLEN)
#endif #endif

View File

@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@ -144,8 +144,8 @@ struct name { \
#define SLIST_HEAD_INITIALIZER(head) \ #define SLIST_HEAD_INITIALIZER(head) \
{ NULL } { NULL }
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
#if defined (SLIST_ENTRY) #if defined(SLIST_ENTRY)
#undef SLIST_ENTRY #undef SLIST_ENTRY
#endif #endif
#endif #endif

View File

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

View File

@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *

View File

@ -44,13 +44,13 @@
#ifdef INET6 #ifdef INET6
#include <netinet6/sctp6_var.h> #include <netinet6/sctp6_var.h>
#endif #endif
#if defined(__Userspace_os_FreeBSD) #if defined(__FreeBSD__)
#include <sys/param.h> #include <sys/param.h>
#endif #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 */ #define __FAVOR_BSD /* (on Ubuntu at least) enables UDP header field names like BSD in RFC 768 */
#endif #endif
#if !defined (__Userspace_os_Windows) #if !defined(_WIN32)
#if defined INET || defined INET6 #if defined INET || defined INET6
#include <netinet/udp.h> #include <netinet/udp.h>
#endif #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); extern int sctpconn_attach(struct socket *so, int proto, uint32_t vrf_id);
static void init_sync(void) { static void init_sync(void) {
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
#if defined(INET) || defined(INET6) #if defined(INET) || defined(INET6)
WSADATA wsaData; WSADATA wsaData;
@ -115,8 +115,8 @@ usrsctp_init(uint16_t port,
void void
usrsctp_init_nothreads(uint16_t port, usrsctp_init_nothreads(uint16_t port,
int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df), int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
void (*debug_printf)(const char *format, ...)) void (*debug_printf)(const char *format, ...))
{ {
init_sync(); init_sync();
sctp_init(port, conn_output, debug_printf, 0); sctp_init(port, conn_output, debug_printf, 0);
@ -169,28 +169,17 @@ socantsendmore(struct socket *so)
int int
sbwait(struct sockbuf *sb) sbwait(struct sockbuf *sb)
{ {
#if defined(__Userspace__) /* __Userspace__ */
SOCKBUF_LOCK_ASSERT(sb); SOCKBUF_LOCK_ASSERT(sb);
sb->sb_flags |= SB_WAIT; sb->sb_flags |= SB_WAIT;
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
if (SleepConditionVariableCS(&(sb->sb_cond), &(sb->sb_mtx), INFINITE)) if (SleepConditionVariableCS(&(sb->sb_cond), &(sb->sb_mtx), INFINITE))
return 0; return (0);
else else
return -1; return (-1);
#else #else
return (pthread_cond_wait(&(sb->sb_cond), &(sb->sb_mtx))); return (pthread_cond_wait(&(sb->sb_cond), &(sb->sb_mtx)));
#endif #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) wakeup(void *ident, struct socket *so)
{ {
SOCK_LOCK(so); SOCK_LOCK(so);
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
WakeAllConditionVariable(&(so)->timeo_cond); WakeAllConditionVariable(&(so)->timeo_cond);
#else #else
pthread_cond_broadcast(&(so)->timeo_cond); pthread_cond_broadcast(&(so)->timeo_cond);
@ -420,7 +409,7 @@ wakeup_one(void *ident)
subsidiary sockets. subsidiary sockets.
*/ */
ACCEPT_LOCK(); ACCEPT_LOCK();
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
WakeAllConditionVariable(&accept_cond); WakeAllConditionVariable(&accept_cond);
#else #else
pthread_cond_broadcast(&accept_cond); 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 Source: /src/sys/gnu/fs/xfs/FreeBSD/xfs_ioctl.c
*/ */
@ -774,11 +741,11 @@ userspace_sctp_sendmsg(struct socket *so,
size_t len, size_t len,
struct sockaddr *to, struct sockaddr *to,
socklen_t tolen, socklen_t tolen,
u_int32_t ppid, uint32_t ppid,
u_int32_t flags, uint32_t flags,
u_int16_t stream_no, uint16_t stream_no,
u_int32_t timetolive, uint32_t timetolive,
u_int32_t context) uint32_t context)
{ {
struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo; struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo;
struct uio auio; struct uio auio;
@ -958,11 +925,11 @@ userspace_sctp_sendmbuf(struct socket *so,
size_t len, size_t len,
struct sockaddr *to, struct sockaddr *to,
socklen_t tolen, socklen_t tolen,
u_int32_t ppid, uint32_t ppid,
u_int32_t flags, uint32_t flags,
u_int16_t stream_no, uint16_t stream_no,
u_int32_t timetolive, uint32_t timetolive,
u_int32_t context) uint32_t context)
{ {
struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo; struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo;
@ -1068,7 +1035,7 @@ userspace_sctp_recvmsg(struct socket *so,
if (error) { if (error) {
if ((auio.uio_resid != ulen) && if ((auio.uio_resid != ulen) &&
(error == EINTR || (error == EINTR ||
#if !defined(__Userspace_os_NetBSD) #if !defined(__NetBSD__)
error == ERESTART || error == ERESTART ||
#endif #endif
error == EWOULDBLOCK)) { error == EWOULDBLOCK)) {
@ -1161,7 +1128,7 @@ usrsctp_recvv(struct socket *so,
if (errno) { if (errno) {
if ((auio.uio_resid != ulen) && if ((auio.uio_resid != ulen) &&
(errno == EINTR || (errno == EINTR ||
#if !defined(__Userspace_os_NetBSD) #if !defined(__NetBSD__)
errno == ERESTART || errno == ERESTART ||
#endif #endif
errno == EWOULDBLOCK)) { errno == EWOULDBLOCK)) {
@ -1260,7 +1227,6 @@ out:
#if defined(__Userspace__)
/* Taken from /src/sys/kern/uipc_socket.c /* Taken from /src/sys/kern/uipc_socket.c
* and modified for __Userspace__ * and modified for __Userspace__
* socreate returns a socket. The socket should be * socreate returns a socket. The socket should be
@ -1331,74 +1297,6 @@ socreate(int dom, struct socket **aso, int type, int proto)
*aso = so; *aso = so;
return (0); 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 /* Taken from /src/sys/kern/uipc_syscalls.c
@ -1426,11 +1324,11 @@ struct socket *
usrsctp_socket(int domain, int type, int protocol, usrsctp_socket(int domain, int type, int protocol,
int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data, int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data,
size_t datalen, struct sctp_rcvinfo, int flags, void *ulp_info), 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, uint32_t sb_threshold,
void *ulp_info) void *ulp_info)
{ {
struct socket *so; struct socket *so = NULL;
if ((protocol == IPPROTO_SCTP) && (SCTP_BASE_VAR(sctp_pcb_initialized) == 0)) { if ((protocol == IPPROTO_SCTP) && (SCTP_BASE_VAR(sctp_pcb_initialized) == 0)) {
errno = EPROTONOSUPPORT; errno = EPROTONOSUPPORT;
@ -1493,7 +1391,6 @@ sbreserve(struct sockbuf *sb, u_long cc, struct socket *so)
return (error); return (error);
} }
#if defined(__Userspace__)
int int
soreserve(struct socket *so, u_long sndcc, u_long rcvcc) 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); SOCKBUF_UNLOCK(&so->so_snd);
return (ENOBUFS); 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 /* Taken from /src/sys/kern/uipc_sockbuf.c
* and modified for __Userspace__ * and modified for __Userspace__
*/ */
#if defined(__Userspace__)
void void
sowakeup(struct socket *so, struct sockbuf *sb) sowakeup(struct socket *so, struct sockbuf *sb)
{ {
@ -1571,7 +1435,7 @@ sowakeup(struct socket *so, struct sockbuf *sb)
sb->sb_flags &= ~SB_SEL; sb->sb_flags &= ~SB_SEL;
if (sb->sb_flags & SB_WAIT) { if (sb->sb_flags & SB_WAIT) {
sb->sb_flags &= ~SB_WAIT; sb->sb_flags &= ~SB_WAIT;
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
WakeAllConditionVariable(&(sb)->sb_cond); WakeAllConditionVariable(&(sb)->sb_cond);
#else #else
pthread_cond_broadcast(&(sb)->sb_cond); pthread_cond_broadcast(&(sb)->sb_cond);
@ -1579,43 +1443,6 @@ sowakeup(struct socket *so, struct sockbuf *sb)
} }
SOCKBUF_UNLOCK(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 /* 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; head->so_error = ECONNABORTED;
break; break;
} }
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
if (SleepConditionVariableCS(&accept_cond, &accept_mtx, INFINITE)) if (SleepConditionVariableCS(&accept_cond, &accept_mtx, INFINITE))
error = 0; error = 0;
else else
@ -2051,7 +1878,7 @@ soconnect(struct socket *so, struct sockaddr *nam)
* Otherwise, if connected, try to disconnect first. This allows * Otherwise, if connected, try to disconnect first. This allows
* user to disconnect by connecting to, e.g., a null address. * 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; error = EISCONN;
} else { } else {
/* /*
@ -2108,7 +1935,7 @@ int user_connect(struct socket *so, struct sockaddr *sa)
SOCK_LOCK(so); SOCK_LOCK(so);
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) { 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)) if (SleepConditionVariableCS(SOCK_COND(so), SOCK_MTX(so), INFINITE))
error = 0; error = 0;
else else
@ -2117,7 +1944,7 @@ int user_connect(struct socket *so, struct sockaddr *sa)
error = pthread_cond_wait(SOCK_COND(so), SOCK_MTX(so)); error = pthread_cond_wait(SOCK_COND(so), SOCK_MTX(so));
#endif #endif
if (error) { if (error) {
#if defined(__Userspace_os_NetBSD) #if defined(__NetBSD__)
if (error == EINTR) { if (error == EINTR) {
#else #else
if (error == EINTR || error == ERESTART) { if (error == EINTR || error == ERESTART) {
@ -2137,7 +1964,7 @@ bad:
if (!interrupted) { if (!interrupted) {
so->so_state &= ~SS_ISCONNECTING; so->so_state &= ~SS_ISCONNECTING;
} }
#if !defined(__Userspace_os_NetBSD) #if !defined(__NetBSD__)
if (error == ERESTART) { if (error == ERESTART) {
error = EINTR; error = EINTR;
} }
@ -2247,7 +2074,7 @@ usrsctp_finish(void)
return (-1); return (-1);
} }
sctp_finish(); sctp_finish();
#if defined(__Userspace_os_Windows) #if defined(_WIN32)
DeleteConditionVariable(&accept_cond); DeleteConditionVariable(&accept_cond);
DeleteCriticalSection(&accept_mtx); DeleteCriticalSection(&accept_mtx);
#if defined(INET) || defined(INET6) #if defined(INET) || defined(INET6)
@ -2383,7 +2210,7 @@ usrsctp_getsockopt(struct socket *so, int level, int option_name,
int *buf_size; int *buf_size;
buf_size = (int *)option_value; 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); *option_len = (socklen_t)sizeof(int);
return (0); return (0);
} }
@ -2583,10 +2410,16 @@ usrsctp_set_ulpinfo(struct socket *so, void *ulp_info)
return (register_ulp_info(so, 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 int
usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags) usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
{ {
struct sctp_getaddresses *gaddrs;
struct sockaddr *sa; struct sockaddr *sa;
#ifdef INET #ifdef INET
struct sockaddr_in *sin; struct sockaddr_in *sin;
@ -2595,9 +2428,9 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
struct sockaddr_in6 *sin6; struct sockaddr_in6 *sin6;
#endif #endif
int i; int i;
size_t argsz;
#if defined(INET) || defined(INET6) #if defined(INET) || defined(INET6)
uint16_t sport = 0; uint16_t sport;
bool fix_port;
#endif #endif
/* validate the flags */ /* validate the flags */
@ -2611,6 +2444,10 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
} }
#if defined(INET) || defined(INET6)
sport = 0;
fix_port = false;
#endif
/* First pre-screen the addresses */ /* First pre-screen the addresses */
sa = addrs; sa = addrs;
for (i = 0; i < addrcnt; i++) { for (i = 0; i < addrcnt; i++) {
@ -2635,6 +2472,7 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
} else { } else {
/* save off the port */ /* save off the port */
sport = sin->sin_port; sport = sin->sin_port;
fix_port = (i > 0);
} }
} }
#ifndef HAVE_SA_LEN #ifndef HAVE_SA_LEN
@ -2662,6 +2500,7 @@ usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags)
} else { } else {
/* save off the port */ /* save off the port */
sport = sin6->sin6_port; sport = sin6->sin6_port;
fix_port = (i > 0);
} }
} }
#ifndef HAVE_SA_LEN #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); sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len);
#endif #endif
} }
argsz = sizeof(struct sctp_getaddresses) +
sizeof(struct sockaddr_storage);
if ((gaddrs = (struct sctp_getaddresses *)malloc(argsz)) == NULL) {
errno = ENOMEM;
return (-1);
}
sa = addrs; sa = addrs;
for (i = 0; i < addrcnt; i++) { for (i = 0; i < addrcnt; i++) {
#ifndef HAVE_SA_LEN #ifndef HAVE_SA_LEN
size_t sa_len; size_t sa_len;
#endif #endif
memset(gaddrs, 0, argsz);
gaddrs->sget_assoc_id = 0;
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
memcpy(gaddrs->addr, sa, sa->sa_len);
#if defined(INET) || defined(INET6) #if defined(INET) || defined(INET6)
if ((i == 0) && (sport != 0)) { if (fix_port) {
switch (gaddrs->addr->sa_family) { switch (sa->sa_family) {
#ifdef INET #ifdef INET
case AF_INET: case AF_INET:
sin = (struct sockaddr_in *)gaddrs->addr; ((struct sockaddr_in *)sa)->sin_port = sport;
sin->sin_port = sport;
break; break;
#endif #endif
#ifdef INET6 #ifdef INET6
case AF_INET6: case AF_INET6:
sin6 = (struct sockaddr_in6 *)gaddrs->addr; ((struct sockaddr_in6 *)sa)->sin6_port = sport;
sin6->sin6_port = sport;
break; break;
#endif #endif
} }
} }
#endif #endif
if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, gaddrs, (socklen_t)argsz) != 0) { if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, sa, sa->sa_len) != 0) {
free(gaddrs);
return (-1); return (-1);
} }
sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); 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; sa_len = 0;
break; break;
} }
memcpy(gaddrs->addr, sa, sa_len);
/* /*
* Now, if there was a port mentioned, assure that the * Now, if there was a port mentioned, assure that the
* first address has that port to make sure it fails or * first address has that port to make sure it fails or
* succeeds correctly. * succeeds correctly.
*/ */
#if defined(INET) || defined(INET6) #if defined(INET) || defined(INET6)
if ((i == 0) && (sport != 0)) { if (fix_port) {
switch (gaddrs->addr->sa_family) { switch (sa->sa_family) {
#ifdef INET #ifdef INET
case AF_INET: case AF_INET:
sin = (struct sockaddr_in *)gaddrs->addr; ((struct sockaddr_in *)sa)->sin_port = sport;
sin->sin_port = sport;
break; break;
#endif #endif
#ifdef INET6 #ifdef INET6
case AF_INET6: case AF_INET6:
sin6 = (struct sockaddr_in6 *)gaddrs->addr; ((struct sockaddr_in6 *)sa)->sin6_port = sport;
sin6->sin6_port = sport;
break; break;
#endif #endif
} }
} }
#endif #endif
if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, gaddrs, (socklen_t)argsz) != 0) { if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, sa, (socklen_t)sa_len) != 0) {
free(gaddrs);
return (-1); return (-1);
} }
sa = (struct sockaddr *)((caddr_t)sa + sa_len); sa = (struct sockaddr *)((caddr_t)sa + sa_len);
#endif #endif
} }
free(gaddrs);
return (0); return (0);
} }
@ -2899,9 +2722,9 @@ usrsctp_getpaddrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs)
free(addrs); free(addrs);
return (-1); return (-1);
} }
*raddrs = (struct sockaddr *)&addrs->addr[0]; *raddrs = &addrs->addr[0].sa;
cnt = 0; cnt = 0;
sa = (struct sockaddr *)&addrs->addr[0]; sa = &addrs->addr[0].sa;
lim = (caddr_t)addrs + opt_len; lim = (caddr_t)addrs + opt_len;
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
while (((caddr_t)sa < lim) && (sa->sa_len > 0)) { while (((caddr_t)sa < lim) && (sa->sa_len > 0)) {
@ -2938,7 +2761,7 @@ usrsctp_freepaddrs(struct sockaddr *addrs)
/* Take away the hidden association id */ /* Take away the hidden association id */
void *fr_addr; 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 */ /* Now free it */
free(fr_addr); free(fr_addr);
} }
@ -2967,9 +2790,7 @@ usrsctp_getladdrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs)
errno = ENOTCONN; errno = ENOTCONN;
return (-1); return (-1);
} }
opt_len = (socklen_t)(size_of_addresses + opt_len = (socklen_t)(size_of_addresses + sizeof(struct sctp_getaddresses));
sizeof(struct sockaddr_storage) +
sizeof(struct sctp_getaddresses));
addrs = calloc(1, (size_t)opt_len); addrs = calloc(1, (size_t)opt_len);
if (addrs == NULL) { if (addrs == NULL) {
errno = ENOMEM; errno = ENOMEM;
@ -2982,9 +2803,9 @@ usrsctp_getladdrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs)
errno = ENOMEM; errno = ENOMEM;
return (-1); return (-1);
} }
*raddrs = (struct sockaddr *)&addrs->addr[0]; *raddrs = &addrs->addr[0].sa;
cnt = 0; cnt = 0;
sa = (struct sockaddr *)&addrs->addr[0]; sa = &addrs->addr[0].sa;
lim = (caddr_t)addrs + opt_len; lim = (caddr_t)addrs + opt_len;
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
while (((caddr_t)sa < lim) && (sa->sa_len > 0)) { while (((caddr_t)sa < lim) && (sa->sa_len > 0)) {
@ -3021,7 +2842,7 @@ usrsctp_freeladdrs(struct sockaddr *addrs)
/* Take away the hidden association id */ /* Take away the hidden association id */
void *fr_addr; 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 */ /* Now free it */
free(fr_addr); free(fr_addr);
} }
@ -3035,16 +2856,11 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
struct mbuf *m; struct mbuf *m;
struct mbuf *m_orig; struct mbuf *m_orig;
int iovcnt; int iovcnt;
int send_len;
int len; int len;
int send_count;
struct ip *ip; struct ip *ip;
struct udphdr *udp; struct udphdr *udp;
#if !defined (__Userspace_os_Windows)
int res;
#endif
struct sockaddr_in dst; struct sockaddr_in dst;
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
WSAMSG win_msg_hdr; WSAMSG win_msg_hdr;
DWORD win_sent_len; DWORD win_sent_len;
WSABUF send_iovec[MAXLEN_MBUF_CHAIN]; 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"); 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? */ /* 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 */ /* need to put certain fields into network order for Linux */
ip->ip_len = htons(ip->ip_len); ip->ip_len = htons(ip->ip_len);
#endif #endif
@ -3113,17 +2929,13 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
m_adj(m, sizeof(struct ip) + sizeof(struct udphdr)); 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++) { 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_base = (caddr_t)m->m_data;
send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m); send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m);
send_count += send_iovec[iovcnt].iov_len;
#else #else
send_iovec[iovcnt].buf = (caddr_t)m->m_data; send_iovec[iovcnt].buf = (caddr_t)m->m_data;
send_iovec[iovcnt].len = SCTP_BUF_LEN(m); send_iovec[iovcnt].len = SCTP_BUF_LEN(m);
send_count += send_iovec[iovcnt].len;
#endif #endif
} }
@ -3132,7 +2944,7 @@ sctp_userspace_ip_output(int *result, struct mbuf *o_pak,
goto free_mbuf; goto free_mbuf;
} }
#if !defined (__Userspace_os_Windows) #if !defined(_WIN32)
msg_hdr.msg_name = (struct sockaddr *) &dst; msg_hdr.msg_name = (struct sockaddr *) &dst;
msg_hdr.msg_namelen = sizeof(struct sockaddr_in); msg_hdr.msg_namelen = sizeof(struct sockaddr_in);
msg_hdr.msg_iov = send_iovec; 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; msg_hdr.msg_flags = 0;
if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) { 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; *result = errno;
} }
} }
if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) { 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; *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 ((!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) { 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(); *result = WSAGetLastError();
} else if ((int)win_sent_len != send_len) {
*result = WSAGetLastError();
} }
} }
if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) { 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) { 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(); *result = WSAGetLastError();
} else if ((int)win_sent_len != send_len) {
*result = WSAGetLastError();
} }
} }
#endif #endif
@ -3181,7 +2989,7 @@ free_mbuf:
} }
#endif #endif
#if defined (INET6) #if defined(INET6)
void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak, void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
struct route_in6 *ro, void *stcb, struct route_in6 *ro, void *stcb,
uint32_t vrf_id) 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;
struct mbuf *m_orig; struct mbuf *m_orig;
int iovcnt; int iovcnt;
int send_len;
int len; int len;
int send_count;
struct ip6_hdr *ip6; struct ip6_hdr *ip6;
struct udphdr *udp; struct udphdr *udp;
#if !defined (__Userspace_os_Windows)
int res;
#endif
struct sockaddr_in6 dst; struct sockaddr_in6 dst;
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
WSAMSG win_msg_hdr; WSAMSG win_msg_hdr;
DWORD win_sent_len; DWORD win_sent_len;
WSABUF send_iovec[MAXLEN_MBUF_CHAIN]; 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) { if (use_udp_tunneling) {
m_adj(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr)); m_adj(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr));
} else { } 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++) { 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_base = (caddr_t)m->m_data;
send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m); send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m);
send_count += send_iovec[iovcnt].iov_len;
#else #else
send_iovec[iovcnt].buf = (caddr_t)m->m_data; send_iovec[iovcnt].buf = (caddr_t)m->m_data;
send_iovec[iovcnt].len = SCTP_BUF_LEN(m); send_iovec[iovcnt].len = SCTP_BUF_LEN(m);
send_count += send_iovec[iovcnt].len;
#endif #endif
} }
if (m != NULL) { if (m != NULL) {
@ -3286,7 +3085,7 @@ void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
goto free_mbuf; goto free_mbuf;
} }
#if !defined (__Userspace_os_Windows) #if !defined(_WIN32)
msg_hdr.msg_name = (struct sockaddr *) &dst; msg_hdr.msg_name = (struct sockaddr *) &dst;
msg_hdr.msg_namelen = sizeof(struct sockaddr_in6); msg_hdr.msg_namelen = sizeof(struct sockaddr_in6);
msg_hdr.msg_iov = send_iovec; 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; msg_hdr.msg_flags = 0;
if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) { 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; *result = errno;
} }
} }
if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) { 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; *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 ((!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) { 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(); *result = WSAGetLastError();
} else if ((int)win_sent_len != send_len) {
*result = WSAGetLastError();
} }
} }
if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) { 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) { 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(); *result = WSAGetLastError();
} else if ((int)win_sent_len != send_len) {
*result = WSAGetLastError();
} }
} }
#endif #endif
@ -3405,21 +3200,30 @@ usrsctp_dumppacket(const void *buf, size_t len, int outbound)
ftime(&tb); ftime(&tb);
localtime_s(&t, &tb.time); localtime_s(&t, &tb.time);
#if defined(__MINGW32__) #if defined(__MINGW32__)
snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT,
outbound ? 'O' : 'I', outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)); t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) {
free(dump_buf);
return (NULL);
}
#else #else
_snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT, if (_snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT,
outbound ? 'O' : 'I', outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)); t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) {
free(dump_buf);
return (NULL);
}
#endif #endif
#else #else
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
sec = (time_t)tv.tv_sec; sec = (time_t)tv.tv_sec;
localtime_r((const time_t *)&sec, &t); localtime_r((const time_t *)&sec, &t);
snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT,
outbound ? 'O' : 'I', outbound ? 'O' : 'I',
t.tm_hour, t.tm_min, t.tm_sec, (long)tv.tv_usec); t.tm_hour, t.tm_min, t.tm_sec, (long)tv.tv_usec) < 0) {
free(dump_buf);
return (NULL);
}
#endif #endif
pos += PREAMBLE_LENGTH; pos += PREAMBLE_LENGTH;
#if defined(_WIN32) && !defined(__MINGW32__) #if defined(_WIN32) && !defined(__MINGW32__)
@ -3482,9 +3286,10 @@ void
usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bits) usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bits)
{ {
struct sockaddr_conn src, dst; struct sockaddr_conn src, dst;
struct mbuf *m; struct mbuf *m, *mm;
struct sctphdr *sh; struct sctphdr *sh;
struct sctp_chunkhdr *ch; struct sctp_chunkhdr *ch;
int remaining, offset;
SCTP_STAT_INCR(sctps_recvpackets); SCTP_STAT_INCR(sctps_recvpackets);
SCTP_STAT_INCR_COUNTER64(sctps_inpackets); 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) { if ((m = sctp_get_mbuf_for_msg((unsigned int)length, 1, M_NOWAIT, 0, MT_DATA)) == NULL) {
return; 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); m_copyback(m, 0, (int)length, (caddr_t)buffer);
if (SCTP_BUF_LEN(m) < (int)(sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr))) { offset = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);
if ((m = m_pullup(m, sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr))) == NULL) { if (SCTP_BUF_LEN(m) < offset) {
if ((m = m_pullup(m, offset)) == NULL) {
SCTP_STAT_INCR(sctps_hdrops); SCTP_STAT_INCR(sctps_hdrops);
return; return;
} }
} }
sh = mtod(m, struct sctphdr *);; sh = mtod(m, struct sctphdr *);
ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr)); ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr));
offset -= sizeof(struct sctp_chunkhdr);
src.sconn_port = sh->src_port; src.sconn_port = sh->src_port;
dst.sconn_port = sh->dest_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 *)&src,
(struct sockaddr *)&dst, (struct sockaddr *)&dst,
sh, ch, sh, ch,
@ -3527,9 +3344,9 @@ usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bit
return; 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 int

View File

@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
@ -33,7 +33,7 @@
#ifndef _USER_SOCKETVAR_H_ #ifndef _USER_SOCKETVAR_H_
#define _USER_SOCKETVAR_H_ #define _USER_SOCKETVAR_H_
#if defined(__Userspace_os_Darwin) #if defined(__APPLE__)
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -42,7 +42,7 @@
/* #include <sys/_lock.h> was 0 byte file */ /* #include <sys/_lock.h> was 0 byte file */
/* #include <sys/_mutex.h> was 0 byte file */ /* #include <sys/_mutex.h> was 0 byte file */
/* #include <sys/_sx.h> */ /*__Userspace__ alternative?*/ /* #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> #include <sys/uio.h>
#endif #endif
#define SOCK_MAXADDRLEN 255 #define SOCK_MAXADDRLEN 255
@ -54,16 +54,16 @@
#define SS_CANTRCVMORE 0x020 #define SS_CANTRCVMORE 0x020
#define SS_CANTSENDMORE 0x010 #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 UIO_MAXIOV 1024
#define ERESTART (-1) #define ERESTART (-1)
#endif #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 }; enum uio_rw { UIO_READ, UIO_WRITE };
#endif #endif
#if !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_OpenBSD) #if !defined(__NetBSD__) && !defined(__OpenBSD__)
/* Segment flag values. */ /* Segment flag values. */
enum uio_seg { enum uio_seg {
UIO_USERSPACE, /* from user data space */ UIO_USERSPACE, /* from user data space */
@ -100,7 +100,7 @@ struct uio {
* handle on protocol and pointer to protocol * handle on protocol and pointer to protocol
* private data and error information. * private data and error information.
*/ */
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
#define AF_ROUTE 17 #define AF_ROUTE 17
#if !defined(__MINGW32__) #if !defined(__MINGW32__)
typedef __int32 pid_t; typedef __int32 pid_t;
@ -237,7 +237,7 @@ struct socket {
* avoid defining a lock order between listen and accept sockets * avoid defining a lock order between listen and accept sockets
* until such time as it proves to be a good idea. * 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_mutex_t accept_mtx;
extern userland_cond_t accept_cond; extern userland_cond_t accept_cond;
#define ACCEPT_LOCK_ASSERT() #define ACCEPT_LOCK_ASSERT()
@ -272,7 +272,7 @@ extern userland_cond_t accept_cond;
* buffer. * buffer.
*/ */
#define SOCKBUF_MTX(_sb) (&(_sb)->sb_mtx) #define SOCKBUF_MTX(_sb) (&(_sb)->sb_mtx)
#if defined (__Userspace_os_Windows) #if defined(_WIN32)
#define SOCKBUF_LOCK_INIT(_sb, _name) \ #define SOCKBUF_LOCK_INIT(_sb, _name) \
InitializeCriticalSection(SOCKBUF_MTX(_sb)) InitializeCriticalSection(SOCKBUF_MTX(_sb))
#define SOCKBUF_LOCK_DESTROY(_sb) DeleteCriticalSection(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_WRITE 0x0002 /* socket is writeable */
#define SCTP_EVENT_ERROR 0x0004 /* socket has an error state */ #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... * above into, avoiding having to port the entire thing at once...
* For function prototypes, the full bodies are in user_socket.c . * For function prototypes, the full bodies are in user_socket.c .
*/ */
#if defined(__Userspace__)
/* ---------------------------------------------------------- */ /* ---------------------------------------------------------- */
/* --- function prototypes (implemented in user_socket.c) --- */ /* --- 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 void socantrcvmore_locked(struct socket *so);
extern int sctp_bind(struct socket *so, struct sockaddr *addr); extern int sctp_bind(struct socket *so, struct sockaddr *addr);
extern int sctp6_bind(struct socket *so, struct sockaddr *addr, void *proc); 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); extern int sctpconn_bind(struct socket *so, struct sockaddr *addr);
#endif
extern int sctp_accept(struct socket *so, struct sockaddr **addr); 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 sctp_attach(struct socket *so, int proto, uint32_t vrf_id);
extern int sctp6_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_disconnect(struct socket *so);
extern int sctp_connect(struct socket *so, struct sockaddr *addr); extern int sctp_connect(struct socket *so, struct sockaddr *addr);
extern int sctp6_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); extern int sctpconn_connect(struct socket *so, struct sockaddr *addr);
#endif
extern void sctp_finish(void); extern void sctp_finish(void);
/* ------------------------------------------------ */ /* ------------------------------------------------ */
@ -863,8 +524,4 @@ extern void sctp_finish(void);
sowwakeup_locked(so); \ sowwakeup_locked(so); \
} while (0) } while (0)
#endif /* __Userspace__ */
#endif /* !_SYS_SOCKETVAR_H_ */ #endif /* !_SYS_SOCKETVAR_H_ */

View File

@ -83,14 +83,14 @@ struct uma_zone {
/* Prototype */ /* Prototype */
uma_zone_t uma_zone_t
uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor, 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__ */ #define uma_zone_set_max(zone, number) /* stub TODO __Userspace__ */
uma_zone_t uma_zone_t
uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor, 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 */ return NULL; /* stub TODO __Userspace__. Also place implementation in a separate .c file */
} }
#endif #endif

View File

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

View File

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.6.0) cmake_minimum_required(VERSION 3.6.0)
set(CMAKE_CXX_FLAGS "-std=c++17 -DANDROID -g")
#tgvoip #tgvoip
add_library(tgvoip STATIC add_library(tgvoip STATIC
@ -289,9 +290,7 @@ add_library(tgcalls_tp STATIC
third_party/usrsctplib/user_mbuf.c third_party/usrsctplib/user_mbuf.c
third_party/usrsctplib/user_recv_thread.c third_party/usrsctplib/user_recv_thread.c
third_party/usrsctplib/user_socket.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/cycleclock.cc
voip/webrtc/absl/base/internal/exception_safety_testing.cc
voip/webrtc/absl/base/internal/exponential_biased.cc voip/webrtc/absl/base/internal/exponential_biased.cc
voip/webrtc/absl/base/internal/low_level_alloc.cc voip/webrtc/absl/base/internal/low_level_alloc.cc
voip/webrtc/absl/base/internal/periodic_sampler.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/commandlineflag.cc
voip/webrtc/absl/flags/internal/flag.cc voip/webrtc/absl/flags/internal/flag.cc
voip/webrtc/absl/flags/internal/program_name.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/internal/usage.cc
voip/webrtc/absl/flags/marshalling.cc voip/webrtc/absl/flags/marshalling.cc
voip/webrtc/absl/flags/parse.cc voip/webrtc/absl/flags/parse.cc
@ -446,16 +443,17 @@ add_library(tgcalls STATIC
voip/tgcalls/AudioDeviceHelper.cpp voip/tgcalls/AudioDeviceHelper.cpp
voip/tgcalls/SctpDataChannelProviderInterfaceImpl.cpp voip/tgcalls/SctpDataChannelProviderInterfaceImpl.cpp
voip/tgcalls/TurnCustomizerImpl.cpp voip/tgcalls/TurnCustomizerImpl.cpp
voip/tgcalls/reference/InstanceImplReference.cpp
voip/tgcalls/legacy/InstanceImplLegacy.cpp voip/tgcalls/legacy/InstanceImplLegacy.cpp
voip/tgcalls/group/GroupNetworkManager.cpp voip/tgcalls/group/GroupNetworkManager.cpp
voip/tgcalls/group/GroupInstanceCustomImpl.cpp voip/tgcalls/group/GroupInstanceCustomImpl.cpp
voip/tgcalls/group/GroupJoinPayloadInternal.cpp voip/tgcalls/group/GroupJoinPayloadInternal.cpp
voip/tgcalls/group/AudioStreamingPart.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/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/async_invoker.cc
voip/webrtc/rtc_base/system_time.cc voip/webrtc/rtc_base/system_time.cc
voip/webrtc/rtc_base/async_resolver.cc voip/webrtc/rtc_base/async_resolver.cc
@ -478,6 +476,7 @@ add_library(tgcalls STATIC
voip/webrtc/rtc_base/boringssl_identity.cc voip/webrtc/rtc_base/boringssl_identity.cc
voip/webrtc/rtc_base/experiments/alr_experiment.cc voip/webrtc/rtc_base/experiments/alr_experiment.cc
voip/webrtc/rtc_base/experiments/balanced_degradation_settings.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/cpu_speed_experiment.cc
voip/webrtc/rtc_base/experiments/encoder_info_settings.cc voip/webrtc/rtc_base/experiments/encoder_info_settings.cc
voip/webrtc/rtc_base/experiments/field_trial_list.cc voip/webrtc/rtc_base/experiments/field_trial_list.cc
@ -490,10 +489,12 @@ add_library(tgcalls STATIC
voip/webrtc/rtc_base/experiments/quality_rampup_experiment.cc voip/webrtc/rtc_base/experiments/quality_rampup_experiment.cc
voip/webrtc/rtc_base/experiments/quality_scaler_settings.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_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/rate_control_settings.cc
voip/webrtc/rtc_base/experiments/rtt_mult_experiment.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/stable_target_rate_experiment.cc
voip/webrtc/rtc_base/experiments/struct_parameters_parser.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/file_rotating_stream.cc
voip/webrtc/rtc_base/helpers.cc voip/webrtc/rtc_base/helpers.cc
voip/webrtc/rtc_base/http_common.cc voip/webrtc/rtc_base/http_common.cc
@ -583,6 +584,7 @@ add_library(tgcalls STATIC
voip/webrtc/rtc_base/callback_list.cc voip/webrtc/rtc_base/callback_list.cc
voip/webrtc/rtc_base/deprecated/recursive_critical_section.cc voip/webrtc/rtc_base/deprecated/recursive_critical_section.cc
voip/webrtc/rtc_base/internal/default_socket_server.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/audio_frame.cc
voip/webrtc/api/audio/channel_layout.cc voip/webrtc/api/audio/channel_layout.cc
voip/webrtc/api/audio/echo_canceller3_config.cc voip/webrtc/api/audio/echo_canceller3_config.cc
@ -629,8 +631,8 @@ add_library(tgcalls STATIC
voip/webrtc/api/neteq/default_neteq_controller_factory.cc voip/webrtc/api/neteq/default_neteq_controller_factory.cc
voip/webrtc/api/neteq/neteq.cc voip/webrtc/api/neteq/neteq.cc
voip/webrtc/api/neteq/tick_timer.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/peer_connection_interface.cc
voip/webrtc/api/proxy.cc
voip/webrtc/api/rtc_error.cc voip/webrtc/api/rtc_error.cc
voip/webrtc/api/rtc_event_log/rtc_event.cc voip/webrtc/api/rtc_event_log/rtc_event.cc
voip/webrtc/api/rtc_event_log/rtc_event_log.cc voip/webrtc/api/rtc_event_log/rtc_event_log.cc
@ -655,7 +657,10 @@ add_library(tgcalls STATIC
voip/webrtc/api/video/video_adaptation_counters.cc voip/webrtc/api/video/video_adaptation_counters.cc
voip/webrtc/api/video/video_frame_metadata.cc voip/webrtc/api/video/video_frame_metadata.cc
voip/webrtc/api/voip/voip_engine_factory.cc voip/webrtc/api/voip/voip_engine_factory.cc
voip/webrtc/api/video/i444_buffer.cc
voip/webrtc/api/video/rtp_video_frame_assembler.cc
voip/webrtc/api/numerics/samples_stats_counter.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/adaptation_constraint.cc
voip/webrtc/call/adaptation/broadcast_resource_listener.cc voip/webrtc/call/adaptation/broadcast_resource_listener.cc
voip/webrtc/call/adaptation/degradation_preference_provider.cc voip/webrtc/call/adaptation/degradation_preference_provider.cc
@ -721,6 +726,7 @@ add_library(tgcalls STATIC
voip/webrtc/pc/jsep_ice_candidate.cc voip/webrtc/pc/jsep_ice_candidate.cc
voip/webrtc/pc/jsep_session_description.cc voip/webrtc/pc/jsep_session_description.cc
voip/webrtc/pc/jsep_transport.cc voip/webrtc/pc/jsep_transport.cc
voip/webrtc/pc/jsep_transport_collection.cc
voip/webrtc/pc/jsep_transport_controller.cc voip/webrtc/pc/jsep_transport_controller.cc
voip/webrtc/pc/local_audio_source.cc voip/webrtc/pc/local_audio_source.cc
voip/webrtc/pc/media_protocol_names.cc voip/webrtc/pc/media_protocol_names.cc
@ -757,6 +763,7 @@ add_library(tgcalls STATIC
voip/webrtc/pc/video_rtp_track_source.cc voip/webrtc/pc/video_rtp_track_source.cc
voip/webrtc/pc/video_track.cc voip/webrtc/pc/video_track.cc
voip/webrtc/pc/video_track_source.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_sdp.cc
voip/webrtc/pc/webrtc_session_description_factory.cc voip/webrtc/pc/webrtc_session_description_factory.cc
voip/webrtc/pc/connection_context.cc voip/webrtc/pc/connection_context.cc
@ -768,7 +775,6 @@ add_library(tgcalls STATIC
voip/webrtc/sdk/android/src/jni/pc/add_ice_candidate_observer.cc 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/adapted_video_track_source.cc
voip/webrtc/media/base/codec.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_channel.cc
voip/webrtc/media/base/media_constants.cc voip/webrtc/media/base/media_constants.cc
voip/webrtc/media/base/media_engine.cc voip/webrtc/media/base/media_engine.cc
@ -804,6 +810,7 @@ add_library(tgcalls STATIC
voip/webrtc/system_wrappers/source/metrics.cc voip/webrtc/system_wrappers/source/metrics.cc
voip/webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc voip/webrtc/system_wrappers/source/rtp_to_ntp_estimator.cc
voip/webrtc/system_wrappers/source/sleep.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_receiver.cc
voip/webrtc/modules/audio_coding/acm2/acm_remixing.cc voip/webrtc/modules/audio_coding/acm2/acm_remixing.cc
voip/webrtc/modules/audio_coding/acm2/acm_resampler.cc voip/webrtc/modules/audio_coding/acm2/acm_resampler.cc
@ -1007,6 +1014,9 @@ add_library(tgcalls STATIC
voip/webrtc/modules/audio_coding/neteq/sync_buffer.cc voip/webrtc/modules/audio_coding/neteq/sync_buffer.cc
voip/webrtc/modules/audio_coding/neteq/time_stretch.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/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_buffer.cc
voip/webrtc/modules/audio_device/audio_device_data_observer.cc voip/webrtc/modules/audio_device/audio_device_data_observer.cc
voip/webrtc/modules/audio_device/audio_device_generic.cc voip/webrtc/modules/audio_device/audio_device_generic.cc
@ -1088,24 +1098,25 @@ add_library(tgcalls STATIC
voip/webrtc/modules/audio_processing/agc/legacy/digital_agc.cc 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/loudness_histogram.cc
voip/webrtc/modules/audio_processing/agc/utility.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/cpu_features.cc
voip/webrtc/modules/audio_processing/agc2/adaptive_digital_gain_applier.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/adaptive_mode_level_estimator.cc
voip/webrtc/modules/audio_processing/agc2/agc2_testing_common.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/biquad_filter.cc
voip/webrtc/modules/audio_processing/agc2/compute_interpolated_gain_curve.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/fixed_digital_level_estimator.cc
voip/webrtc/modules/audio_processing/agc2/gain_applier.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/interpolated_gain_curve.cc
voip/webrtc/modules/audio_processing/agc2/limiter.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/limiter_db_gain_curve.cc
voip/webrtc/modules/audio_processing/agc2/noise_level_estimator.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/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/vector_float_frame.cc
voip/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.cc voip/webrtc/modules/audio_processing/agc2/saturation_protector_buffer.cc
voip/webrtc/modules/audio_processing/agc2/rnn_vad/auto_correlation.cc voip/webrtc/modules/audio_processing/agc2/rnn_vad/auto_correlation.cc
@ -1133,8 +1144,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/audio_processing/include/audio_frame_proxies.cc 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.cc
voip/webrtc/modules/audio_processing/include/audio_processing_statistics.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/logging/apm_data_dumper.cc
voip/webrtc/modules/audio_processing/ns/fast_math.cc voip/webrtc/modules/audio_processing/ns/fast_math.cc
voip/webrtc/modules/audio_processing/ns/histograms.cc voip/webrtc/modules/audio_processing/ns/histograms.cc
@ -1172,7 +1181,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/audio_processing/vad/vad_audio_proc.cc voip/webrtc/modules/audio_processing/vad/vad_audio_proc.cc
voip/webrtc/modules/audio_processing/vad/vad_circular_buffer.cc voip/webrtc/modules/audio_processing/vad/vad_circular_buffer.cc
voip/webrtc/modules/audio_processing/vad/voice_activity_detector.cc voip/webrtc/modules/audio_processing/vad/voice_activity_detector.cc
voip/webrtc/modules/audio_processing/voice_detection.cc
voip/webrtc/modules/audio_processing/optionally_built_submodule_creators.cc voip/webrtc/modules/audio_processing/optionally_built_submodule_creators.cc
voip/webrtc/modules/audio_processing/capture_levels_adjuster/capture_levels_adjuster.cc voip/webrtc/modules/audio_processing/capture_levels_adjuster/capture_levels_adjuster.cc
voip/webrtc/modules/audio_processing/capture_levels_adjuster/audio_samples_scaler.cc voip/webrtc/modules/audio_processing/capture_levels_adjuster/audio_samples_scaler.cc
@ -1202,6 +1210,8 @@ add_library(tgcalls STATIC
voip/webrtc/modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.cc 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/trendline_estimator.cc
voip/webrtc/modules/congestion_controller/goog_cc/inter_arrival_delta.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/bitrate_prober.cc
voip/webrtc/modules/pacing/interval_budget.cc voip/webrtc/modules/pacing/interval_budget.cc
voip/webrtc/modules/pacing/paced_sender.cc voip/webrtc/modules/pacing/paced_sender.cc
@ -1214,7 +1224,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/rtp_rtcp/source/absolute_capture_time_interpolator.cc 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/capture_clock_offset_updater.cc
voip/webrtc/modules/rtp_rtcp/source/active_decode_targets_helper.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/absolute_capture_time_sender.cc
voip/webrtc/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc voip/webrtc/modules/rtp_rtcp/source/create_video_rtp_depacketizer.cc
voip/webrtc/modules/rtp_rtcp/source/dtmf_queue.cc voip/webrtc/modules/rtp_rtcp/source/dtmf_queue.cc
@ -1288,7 +1297,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/rtp_rtcp/source/rtp_sender_video.cc 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_sender_video_frame_transformer_delegate.cc
voip/webrtc/modules/rtp_rtcp/source/rtp_sequence_number_map.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/rtp_video_header.cc
voip/webrtc/modules/rtp_rtcp/source/source_tracker.cc voip/webrtc/modules/rtp_rtcp/source/source_tracker.cc
voip/webrtc/modules/rtp_rtcp/source/time_util.cc voip/webrtc/modules/rtp_rtcp/source/time_util.cc
@ -1308,6 +1316,7 @@ add_library(tgcalls STATIC
voip/webrtc/modules/rtp_rtcp/source/deprecated/deprecated_rtp_sender_egress.cc 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/rtp_video_layers_allocation_extension.cc
voip/webrtc/modules/rtp_rtcp/source/packet_sequencer.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/helpers_android.cc
voip/webrtc/modules/utility/source/jvm_android.cc voip/webrtc/modules/utility/source/jvm_android.cc
voip/webrtc/modules/utility/source/process_thread_impl.cc voip/webrtc/modules/utility/source/process_thread_impl.cc
@ -1318,7 +1327,7 @@ add_library(tgcalls STATIC
voip/webrtc/modules/video_capture/video_capture_impl.cc voip/webrtc/modules/video_capture/video_capture_impl.cc
voip/webrtc/modules/video_coding/codec_timer.cc voip/webrtc/modules/video_coding/codec_timer.cc
voip/webrtc/modules/video_coding/codecs/av1/libaom_av1_decoder_absent.cc voip/webrtc/modules/video_coding/codecs/av1/libaom_av1_decoder_absent.cc
voip/webrtc/modules/video_coding/codecs/av1/libaom_av1_encoder_absent.cc voip/webrtc/modules/video_coding/codecs/av1/libaom_av1_encoder_supported.cc
voip/webrtc/modules/video_coding/codecs/h264/h264.cc voip/webrtc/modules/video_coding/codecs/h264/h264.cc
voip/webrtc/modules/video_coding/codecs/h264/h264_color_space.cc voip/webrtc/modules/video_coding/codecs/h264/h264_color_space.cc
voip/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc voip/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc
@ -1360,7 +1369,6 @@ add_library(tgcalls STATIC
voip/webrtc/modules/video_coding/utility/decoded_frames_history.cc 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/qp_parser.cc
voip/webrtc/modules/video_coding/utility/frame_dropper.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_reader.cc
voip/webrtc/modules/video_coding/utility/ivf_file_writer.cc voip/webrtc/modules/video_coding/utility/ivf_file_writer.cc
voip/webrtc/modules/video_coding/utility/quality_scaler.cc voip/webrtc/modules/video_coding/utility/quality_scaler.cc
@ -1368,6 +1376,8 @@ add_library(tgcalls STATIC
voip/webrtc/modules/video_coding/utility/simulcast_utility.cc 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/vp8_header_parser.cc
voip/webrtc/modules/video_coding/utility/vp9_uncompressed_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_codec_initializer.cc
voip/webrtc/modules/video_coding/video_coding_defines.cc voip/webrtc/modules/video_coding/video_coding_defines.cc
voip/webrtc/modules/video_coding/video_coding_impl.cc voip/webrtc/modules/video_coding/video_coding_impl.cc
@ -1397,6 +1407,10 @@ add_library(tgcalls STATIC
voip/webrtc/modules/video_coding/rtp_vp9_ref_finder.cc 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/rtp_generic_ref_finder.cc
voip/webrtc/modules/video_coding/codecs/av1/av1_svc_config.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/frame_helpers.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.cc
voip/webrtc/modules/video_processing/util/denoiser_filter_c.cc voip/webrtc/modules/video_processing/util/denoiser_filter_c.cc
voip/webrtc/modules/video_processing/util/noise_estimation.cc voip/webrtc/modules/video_processing/util/noise_estimation.cc
@ -1496,6 +1510,7 @@ add_library(tgcalls STATIC
voip/webrtc/common_video/h264/sps_vui_rewriter.cc voip/webrtc/common_video/h264/sps_vui_rewriter.cc
voip/webrtc/common_video/h265/h265_bitstream_parser.cc voip/webrtc/common_video/h265/h265_bitstream_parser.cc
voip/webrtc/common_video/h265/h265_common.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_pps_parser.cc
voip/webrtc/common_video/h265/h265_sps_parser.cc voip/webrtc/common_video/h265/h265_sps_parser.cc
voip/webrtc/common_video/h265/h265_vps_parser.cc voip/webrtc/common_video/h265/h265_vps_parser.cc
@ -1504,6 +1519,7 @@ add_library(tgcalls STATIC
voip/webrtc/common_video/video_frame_buffer.cc voip/webrtc/common_video/video_frame_buffer.cc
voip/webrtc/common_video/video_render_frames.cc voip/webrtc/common_video/video_render_frames.cc
voip/webrtc/common_video/video_frame_buffer_pool.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/async_stun_tcp_socket.cc
voip/webrtc/p2p/base/basic_async_resolver_factory.cc voip/webrtc/p2p/base/basic_async_resolver_factory.cc
voip/webrtc/p2p/base/basic_ice_controller.cc voip/webrtc/p2p/base/basic_ice_controller.cc
@ -1536,9 +1552,7 @@ add_library(tgcalls STATIC
voip/webrtc/p2p/client/basic_port_allocator.cc voip/webrtc/p2p/client/basic_port_allocator.cc
voip/webrtc/p2p/client/turn_port_factory.cc voip/webrtc/p2p/client/turn_port_factory.cc
voip/webrtc/p2p/stunprober/stun_prober.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/deprecated/nack_module.cc
voip/webrtc/modules/video_coding/nack_module2.cc
voip/webrtc/modules/async_audio_processing/async_audio_processing.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/blob_encoding.cc
voip/webrtc/logging/rtc_event_log/encoder/delta_encoding.cc voip/webrtc/logging/rtc_event_log/encoder/delta_encoding.cc
@ -1568,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_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_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/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.cc
voip/webrtc/logging/rtc_event_log/fake_rtc_event_log_factory.cc voip/webrtc/logging/rtc_event_log/fake_rtc_event_log_factory.cc
voip/webrtc/logging/rtc_event_log/ice_logger.cc voip/webrtc/logging/rtc_event_log/ice_logger.cc
@ -1581,6 +1599,8 @@ add_library(tgcalls STATIC
voip/webrtc/video/adaptation/balanced_constraint.cc voip/webrtc/video/adaptation/balanced_constraint.cc
voip/webrtc/video/adaptation/bitrate_constraint.cc voip/webrtc/video/adaptation/bitrate_constraint.cc
voip/webrtc/video/adaptation/pixel_limit_resource.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/buffered_frame_decryptor.cc
voip/webrtc/video/call_stats.cc voip/webrtc/video/call_stats.cc
voip/webrtc/video/encoder_bitrate_adjuster.cc voip/webrtc/video/encoder_bitrate_adjuster.cc
@ -1601,7 +1621,6 @@ add_library(tgcalls STATIC
voip/webrtc/video/stream_synchronization.cc voip/webrtc/video/stream_synchronization.cc
voip/webrtc/video/transport_adapter.cc voip/webrtc/video/transport_adapter.cc
voip/webrtc/video/video_quality_observer.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.cc
voip/webrtc/video/video_send_stream_impl.cc voip/webrtc/video/video_send_stream_impl.cc
voip/webrtc/video/video_source_sink_controller.cc voip/webrtc/video/video_source_sink_controller.cc
@ -1616,6 +1635,12 @@ add_library(tgcalls STATIC
voip/webrtc/video/receive_statistics_proxy2.cc voip/webrtc/video/receive_statistics_proxy2.cc
voip/webrtc/video/call_stats2.cc voip/webrtc/video/call_stats2.cc
voip/webrtc/video/alignment_adjuster.cc voip/webrtc/video/alignment_adjuster.cc
voip/webrtc/video/frame_buffer_proxy.cc
voip/webrtc/video/decode_synchronizer.cc
voip/webrtc/video/frame_cadence_adapter.cc
voip/webrtc/video/frame_decode_timing.cc
voip/webrtc/video/task_queue_frame_decode_scheduler.cc
voip/webrtc/video/video_receive_stream_timeout_tracker.cc
voip/webrtc/audio/audio_level.cc voip/webrtc/audio/audio_level.cc
voip/webrtc/audio/audio_receive_stream.cc voip/webrtc/audio/audio_receive_stream.cc
voip/webrtc/audio/audio_send_stream.cc voip/webrtc/audio/audio_send_stream.cc
@ -1761,7 +1786,7 @@ add_library(voipandroid STATIC
voip/webrtc/sdk/android/native_api/video/wrapper.cc voip/webrtc/sdk/android/native_api/video/wrapper.cc
voip/webrtc/sdk/android/native_api/network_monitor/network_monitor.cc voip/webrtc/sdk/android/native_api/network_monitor/network_monitor.cc
voip/webrtc/sdk/android/src/jni/android_histogram.cc voip/webrtc/sdk/android/src/jni/android_histogram.cc
voip/webrtc/sdk/android/src/jni/av1_codec.cc voip/webrtc/sdk/android/src/jni/libaom_av1_codec.cc
voip/webrtc/sdk/android/src/jni/egl_base_10_impl.cc voip/webrtc/sdk/android/src/jni/egl_base_10_impl.cc
voip/webrtc/sdk/android/src/jni/android_metrics.cc voip/webrtc/sdk/android/src/jni/android_metrics.cc
voip/webrtc/sdk/android/src/jni/android_network_monitor.cc voip/webrtc/sdk/android/src/jni/android_network_monitor.cc

View File

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

View File

@ -19,7 +19,6 @@
#include "pc/video_track.h" #include "pc/video_track.h"
#include "legacy/InstanceImplLegacy.h" #include "legacy/InstanceImplLegacy.h"
#include "InstanceImpl.h" #include "InstanceImpl.h"
#include "reference/InstanceImplReference.h"
#include "libtgvoip/os/android/AudioOutputOpenSLES.h" #include "libtgvoip/os/android/AudioOutputOpenSLES.h"
#include "libtgvoip/os/android/AudioInputOpenSLES.h" #include "libtgvoip/os/android/AudioInputOpenSLES.h"
#include "libtgvoip/os/android/JNIUtilities.h" #include "libtgvoip/os/android/JNIUtilities.h"
@ -29,7 +28,6 @@ using namespace tgcalls;
const auto RegisterTag = Register<InstanceImpl>(); const auto RegisterTag = Register<InstanceImpl>();
const auto RegisterTagLegacy = Register<InstanceImplLegacy>(); const auto RegisterTagLegacy = Register<InstanceImplLegacy>();
const auto RegisterTagReference = tgcalls::Register<InstanceImplReference>();
jclass TrafficStatsClass; jclass TrafficStatsClass;
jclass FingerprintClass; jclass FingerprintClass;
@ -137,6 +135,19 @@ private:
VideoChannelDescription::Quality _quality; 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 { class JavaObject {
private: private:
JNIEnv *env; JNIEnv *env;
@ -465,6 +476,14 @@ JNIEXPORT jlong JNICALL Java_org_telegram_messenger_voip_NativeInstance_makeGrou
}); });
return task; 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; auto *holder = new InstanceHolder;
@ -480,17 +499,18 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_setJoinRe
if (instance->groupNativeInstance == nullptr) { if (instance->groupNativeInstance == nullptr) {
return; return;
} }
instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeRtc, true); instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeRtc, true, true);
instance->groupNativeInstance->setJoinResponsePayload(tgvoip::jni::JavaStringToStdString(env, payload)); instance->groupNativeInstance->setJoinResponsePayload(tgvoip::jni::JavaStringToStdString(env, payload));
} }
extern "C" 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); InstanceHolder *instance = getInstanceHolder(env, obj);
if (instance->groupNativeInstance == nullptr) { if (instance->groupNativeInstance == nullptr) {
return; 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) { void onEmitJoinPayload(const std::shared_ptr<PlatformContext>& platformContext, const GroupJoinPayload& payload) {
@ -506,7 +526,7 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_resetGrou
return; return;
} }
if (set) { if (set) {
instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeNone, !disconnect); instance->groupNativeInstance->setConnectionMode(GroupConnectionMode::GroupConnectionModeNone, !disconnect, true);
} }
std::shared_ptr<PlatformContext> platformContext = instance->_platformContext; std::shared_ptr<PlatformContext> platformContext = instance->_platformContext;
instance->groupNativeInstance->emitJoinPayload([platformContext](const GroupJoinPayload& payload) { instance->groupNativeInstance->emitJoinPayload([platformContext](const GroupJoinPayload& payload) {
@ -1066,4 +1086,14 @@ JNIEXPORT void JNICALL Java_org_telegram_messenger_voip_NativeInstance_onSignali
env->ReleaseByteArrayElements(value, (jbyte *) valueBytes, JNI_ABORT); 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 std::vector<VideoFormat> &list,
const VideoFormat &format) { const VideoFormat &format) {
return std::find_if(list.begin(), list.end(), [&](const VideoFormat &other) { return std::find_if(list.begin(), list.end(), [&](const VideoFormat &other) {
return cricket::IsSameCodec( return format.IsSameCodec(other);
format.name,
format.parameters,
other.name,
other.parameters);
}); });
} }

View File

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

View File

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

View File

@ -62,7 +62,7 @@ void dumpStatsLog(const FilePath &path, const CallStats &stats) {
} // namespace } // namespace
bool Manager::ResolvedNetworkStatus::operator==(const ResolvedNetworkStatus &rhs) { bool Manager::ResolvedNetworkStatus::operator==(const ResolvedNetworkStatus &rhs) const {
if (rhs.isLowCost != isLowCost) { if (rhs.isLowCost != isLowCost) {
return false; return false;
} }
@ -72,7 +72,7 @@ bool Manager::ResolvedNetworkStatus::operator==(const ResolvedNetworkStatus &rhs
return true; return true;
} }
bool Manager::ResolvedNetworkStatus::operator!=(const ResolvedNetworkStatus &rhs) { bool Manager::ResolvedNetworkStatus::operator!=(const ResolvedNetworkStatus &rhs) const {
return !(*this == rhs); return !(*this == rhs);
} }
@ -139,9 +139,9 @@ void Manager::sendSignalingAsync(int delayMs, int cause) {
} }
}; };
if (delayMs) { if (delayMs) {
_thread->PostDelayedTask(RTC_FROM_HERE, std::move(task), delayMs); _thread->PostDelayedTask(std::move(task), delayMs);
} else { } else {
_thread->PostTask(RTC_FROM_HERE, std::move(task)); _thread->PostTask(std::move(task));
} }
} }
@ -149,7 +149,7 @@ void Manager::start() {
const auto weak = std::weak_ptr<Manager>(shared_from_this()); const auto weak = std::weak_ptr<Manager>(shared_from_this());
const auto thread = _thread; const auto thread = _thread;
const auto sendSignalingMessage = [=](Message &&message) { const auto sendSignalingMessage = [=](Message &&message) {
thread->PostTask(RTC_FROM_HERE, [=, message = std::move(message)]() mutable { thread->PostTask([=, message = std::move(message)]() mutable {
const auto strong = weak.lock(); const auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -167,7 +167,7 @@ void Manager::start() {
rtcServers, rtcServers,
std::move(proxy), std::move(proxy),
[=](const NetworkManager::State &state) { [=](const NetworkManager::State &state) {
thread->PostTask(RTC_FROM_HERE, [=] { thread->PostTask([=] {
const auto strong = weak.lock(); const auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -200,7 +200,7 @@ void Manager::start() {
}); });
}, },
[=](DecryptedMessage &&message) { [=](DecryptedMessage &&message) {
thread->PostTask(RTC_FROM_HERE, [=, message = std::move(message)]() mutable { thread->PostTask([=, message = std::move(message)]() mutable {
if (const auto strong = weak.lock()) { if (const auto strong = weak.lock()) {
strong->receiveMessage(std::move(message)); strong->receiveMessage(std::move(message));
} }
@ -216,9 +216,9 @@ void Manager::start() {
} }
}; };
if (delayMs) { if (delayMs) {
thread->PostDelayedTask(RTC_FROM_HERE, task, delayMs); thread->PostDelayedTask(task, delayMs);
} else { } else {
thread->PostTask(RTC_FROM_HERE, task); thread->PostTask(task);
} }
}); });
})); }));
@ -232,7 +232,7 @@ void Manager::start() {
videoCapture, videoCapture,
sendSignalingMessage, sendSignalingMessage,
[=](Message &&message) { [=](Message &&message) {
thread->PostTask(RTC_FROM_HERE, [=, message = std::move(message)]() mutable { thread->PostTask([=, message = std::move(message)]() mutable {
const auto strong = weak.lock(); const auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -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->perform(RTC_FROM_HERE, [sink](MediaManager *mediaManager) {
mediaManager->setIncomingVideoOutput(sink); mediaManager->setIncomingVideoOutput(sink);
}); });
@ -362,7 +362,7 @@ void Manager::getNetworkStats(std::function<void (TrafficStats, CallStats)> comp
CallStats callStats; CallStats callStats;
networkManager->fillCallStats(callStats); networkManager->fillCallStats(callStats);
thread->PostTask(RTC_FROM_HERE, [weak, networkStats, completion = std::move(completion), callStats = std::move(callStats), statsLogPath = statsLogPath] { thread->PostTask([weak, networkStats, completion = std::move(completion), callStats = std::move(callStats), statsLogPath = statsLogPath] {
const auto strong = weak.lock(); const auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;

View File

@ -16,8 +16,8 @@ private:
bool isLowCost = false; bool isLowCost = false;
bool isLowDataRequested = false; bool isLowDataRequested = false;
bool operator==(const ResolvedNetworkStatus &rhs); bool operator==(const ResolvedNetworkStatus &rhs) const;
bool operator!=(const ResolvedNetworkStatus &rhs); bool operator!=(const ResolvedNetworkStatus &rhs) const;
}; };
public: public:
@ -32,7 +32,7 @@ public:
void sendVideoDeviceUpdated(); void sendVideoDeviceUpdated();
void setRequestedVideoAspect(float aspect); void setRequestedVideoAspect(float aspect);
void setMuteOutgoingAudio(bool mute); 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 setIsLowBatteryLevel(bool isLowBatteryLevel);
void setIsLocalNetworkLowCost(bool isLocalNetworkLowCost); void setIsLocalNetworkLowCost(bool isLocalNetworkLowCost);
void getNetworkStats(std::function<void(TrafficStats, CallStats)> completion); void getNetworkStats(std::function<void(TrafficStats, CallStats)> completion);

View File

@ -18,11 +18,13 @@
#include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/field_trial.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h" #include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "call/call.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 "api/call/audio_sink.h"
#include "modules/audio_processing/audio_buffer.h" #include "modules/audio_processing/audio_buffer.h"
#include "modules/audio_device/include/audio_device_factory.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 tgcalls {
namespace { namespace {
@ -163,30 +165,30 @@ public:
} }
virtual void OnFrame(const webrtc::VideoFrame& frame) override { virtual void OnFrame(const webrtc::VideoFrame& frame) override {
if (_impl) { if (const auto strong = _impl.lock()) {
if (_rewriteRotation) { if (_rewriteRotation) {
webrtc::VideoFrame updatedFrame = frame; webrtc::VideoFrame updatedFrame = frame;
//updatedFrame.set_rotation(webrtc::VideoRotation::kVideoRotation_90); //updatedFrame.set_rotation(webrtc::VideoRotation::kVideoRotation_90);
_impl->OnFrame(updatedFrame); strong->OnFrame(updatedFrame);
} else { } else {
_impl->OnFrame(frame); strong->OnFrame(frame);
} }
} }
} }
virtual void OnDiscardedFrame() override { virtual void OnDiscardedFrame() override {
if (_impl) { if (const auto strong = _impl.lock()) {
_impl->OnDiscardedFrame(); strong->OnDiscardedFrame();
} }
} }
void setSink(std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> impl) { void setSink(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> impl) {
_impl = impl; _impl = impl;
} }
private: private:
bool _rewriteRotation = false; bool _rewriteRotation = false;
std::shared_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _impl; std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> _impl;
}; };
@ -312,7 +314,7 @@ _platformContext(platformContext) {
webrtc::AudioProcessingBuilder builder; webrtc::AudioProcessingBuilder builder;
std::unique_ptr<AudioCapturePostProcessor> audioProcessor = std::make_unique<AudioCapturePostProcessor>([this](float level) { std::unique_ptr<AudioCapturePostProcessor> audioProcessor = std::make_unique<AudioCapturePostProcessor>([this](float level) {
this->_thread->PostTask(RTC_FROM_HERE, [this, level](){ this->_thread->PostTask([this, level](){
auto strong = this; auto strong = this;
strong->_currentMyAudioLevel = level; strong->_currentMyAudioLevel = level;
}); });
@ -405,9 +407,13 @@ _platformContext(platformContext) {
rtc::scoped_refptr<webrtc::AudioDeviceModule> MediaManager::createAudioDeviceModule() { rtc::scoped_refptr<webrtc::AudioDeviceModule> MediaManager::createAudioDeviceModule() {
const auto create = [&](webrtc::AudioDeviceModule::AudioLayer layer) { 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( return webrtc::AudioDeviceModule::Create(
layer, layer,
_taskQueueFactory.get()); _taskQueueFactory.get());
#endif
}; };
const auto check = [&](const rtc::scoped_refptr<webrtc::AudioDeviceModule> &result) { const auto check = [&](const rtc::scoped_refptr<webrtc::AudioDeviceModule> &result) {
return (result && result->Init() == 0) ? result : nullptr; return (result && result->Init() == 0) ? result : nullptr;
@ -430,7 +436,7 @@ void MediaManager::start() {
// Here we hope that thread outlives the sink // Here we hope that thread outlives the sink
rtc::Thread *thread = _thread; rtc::Thread *thread = _thread;
std::unique_ptr<AudioTrackSinkInterfaceImpl> incomingSink(new AudioTrackSinkInterfaceImpl([weak, thread](float level) { std::unique_ptr<AudioTrackSinkInterfaceImpl> incomingSink(new AudioTrackSinkInterfaceImpl([weak, thread](float level) {
thread->PostTask(RTC_FROM_HERE, [weak, level] { thread->PostTask([weak, level] {
if (const auto strong = weak.lock()) { if (const auto strong = weak.lock()) {
strong->_currentAudioLevel = level; strong->_currentAudioLevel = level;
} }
@ -539,7 +545,7 @@ void MediaManager::sendOutgoingMediaStateMessage() {
void MediaManager::beginStatsTimer(int timeoutMs) { void MediaManager::beginStatsTimer(int timeoutMs) {
const auto weak = std::weak_ptr<MediaManager>(shared_from_this()); const auto weak = std::weak_ptr<MediaManager>(shared_from_this());
_thread->PostDelayedTask(RTC_FROM_HERE, [weak]() { _thread->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -550,7 +556,7 @@ void MediaManager::beginStatsTimer(int timeoutMs) {
void MediaManager::beginLevelsTimer(int timeoutMs) { void MediaManager::beginLevelsTimer(int timeoutMs) {
const auto weak = std::weak_ptr<MediaManager>(shared_from_this()); const auto weak = std::weak_ptr<MediaManager>(shared_from_this());
_thread->PostDelayedTask(RTC_FROM_HERE, [weak]() { _thread->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -647,7 +653,7 @@ void MediaManager::setSendVideo(std::shared_ptr<VideoCaptureInterface> videoCapt
const auto object = GetVideoCaptureAssumingSameThread(_videoCapture.get()); const auto object = GetVideoCaptureAssumingSameThread(_videoCapture.get());
_isScreenCapture = object->isScreenCapture(); _isScreenCapture = object->isScreenCapture();
object->setStateUpdated([=](VideoState state) { object->setStateUpdated([=](VideoState state) {
thread->PostTask(RTC_FROM_HERE, [=] { thread->PostTask([=] {
if (const auto strong = weak.lock()) { if (const auto strong = weak.lock()) {
strong->setOutgoingVideoState(state); strong->setOutgoingVideoState(state);
} }
@ -908,28 +914,31 @@ void MediaManager::setOutgoingVideoState(VideoState state) {
sendOutgoingMediaStateMessage(); 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); _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) { void MediaManager::receiveMessage(DecryptedMessage &&message) {
const auto data = &message.message.data; const auto data = &message.message.data;
if (const auto formats = absl::get_if<VideoFormatsMessage>(data)) { if (const auto formats = absl::get_if<VideoFormatsMessage>(data)) {
setPeerVideoFormats(std::move(*formats)); setPeerVideoFormats(std::move(*formats));
} else if (const auto audio = absl::get_if<AudioDataMessage>(data)) { } 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"; 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)) { } else if (const auto video = absl::get_if<VideoDataMessage>(data)) {
if (_videoChannel) { if (_videoChannel) {
if (_readyToReceiveVideo) { 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 { } else {
// maybe we need to queue packets for some time? // maybe we need to queue packets for some time?
} }

View File

@ -61,7 +61,7 @@ public:
void sendVideoDeviceUpdated(); void sendVideoDeviceUpdated();
void setRequestedVideoAspect(float aspect); void setRequestedVideoAspect(float aspect);
void setMuteOutgoingAudio(bool mute); 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 receiveMessage(DecryptedMessage &&message);
void remoteVideoStateUpdated(VideoState videoState); void remoteVideoStateUpdated(VideoState videoState);
void setNetworkParameters(bool isLowCost, bool isDataSavingActive); void setNetworkParameters(bool isLowCost, bool isDataSavingActive);

View File

@ -107,7 +107,7 @@ NetworkManager::~NetworkManager() {
} }
void NetworkManager::start() { void NetworkManager::start() {
_socketFactory.reset(new rtc::BasicPacketSocketFactory(_thread)); _socketFactory.reset(new rtc::BasicPacketSocketFactory(_thread->socketserver()));
_networkManager = std::make_unique<rtc::BasicNetworkManager>(_networkMonitorFactory.get()); _networkManager = std::make_unique<rtc::BasicNetworkManager>(_networkMonitorFactory.get());
@ -274,7 +274,7 @@ void NetworkManager::logCurrentNetworkState() {
void NetworkManager::checkConnectionTimeout() { void NetworkManager::checkConnectionTimeout() {
const auto weak = std::weak_ptr<NetworkManager>(shared_from_this()); const auto weak = std::weak_ptr<NetworkManager>(shared_from_this());
_thread->PostDelayedTask(RTC_FROM_HERE, [weak]() { _thread->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;

View File

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

View File

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

View File

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

View File

@ -19,20 +19,20 @@ public:
_thread(thread), _thread(thread),
_valueHolder(std::make_unique<ValueHolder>()) { _valueHolder(std::make_unique<ValueHolder>()) {
assert(_thread != nullptr); assert(_thread != nullptr);
_thread->PostTask(RTC_FROM_HERE, [valueHolder = _valueHolder.get(), generator = std::forward<Generator>(generator)]() mutable { _thread->PostTask([valueHolder = _valueHolder.get(), generator = std::forward<Generator>(generator)]() mutable {
valueHolder->_value.reset(generator()); valueHolder->_value.reset(generator());
}); });
} }
~ThreadLocalObject() { ~ThreadLocalObject() {
_thread->PostTask(RTC_FROM_HERE, [valueHolder = std::move(_valueHolder)](){ _thread->PostTask([valueHolder = std::move(_valueHolder)](){
valueHolder->_value.reset(); valueHolder->_value.reset();
}); });
} }
template <typename FunctorT> template <typename FunctorT>
void perform(const rtc::Location& posted_from, FunctorT &&functor) { void perform(const rtc::Location& posted_from, FunctorT &&functor) {
_thread->PostTask(posted_from, [valueHolder = _valueHolder.get(), f = std::forward<FunctorT>(functor)]() mutable { _thread->PostTask([valueHolder = _valueHolder.get(), f = std::forward<FunctorT>(functor)]() mutable {
assert(valueHolder->_value != nullptr); assert(valueHolder->_value != nullptr);
f(valueHolder->_value.get()); f(valueHolder->_value.get());
}); });

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 "AudioStreamingPart.h"
#include "AudioStreamingPartInternal.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/third_party/base64/base64.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 <string>
#include <bitset> #include <bitset>
#include <set> #include <set>
@ -162,302 +158,6 @@ struct ReadPcmResult {
int numChannels = 0; 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;
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 { class AudioStreamingPartState {
struct ChannelMapping { struct ChannelMapping {
uint32_t ssrc = 0; uint32_t ssrc = 0;
@ -469,15 +169,15 @@ class AudioStreamingPartState {
}; };
public: public:
AudioStreamingPartState(std::vector<uint8_t> &&data) : AudioStreamingPartState(std::vector<uint8_t> &&data, std::string const &container, bool isSingleChannel) :
_parsedPart(std::move(data)) { _isSingleChannel(isSingleChannel),
if (_parsedPart.getChannelUpdates().size() == 0) { _parsedPart(std::move(data), container) {
if (_parsedPart.getChannelUpdates().size() == 0 && !isSingleChannel) {
_didReadToEnd = true; _didReadToEnd = true;
return; return;
} }
_remainingMilliseconds = _parsedPart.getDurationInMilliseconds(); _remainingMilliseconds = _parsedPart.getDurationInMilliseconds();
_pcm10ms.resize(480 * _parsedPart.getChannelCount());
for (const auto &it : _parsedPart.getChannelUpdates()) { for (const auto &it : _parsedPart.getChannelUpdates()) {
_allSsrcs.insert(it.ssrc); _allSsrcs.insert(it.ssrc);
@ -495,7 +195,7 @@ public:
return _remainingMilliseconds; return _remainingMilliseconds;
} }
std::vector<AudioStreamingPart::StreamingPartChannel> get10msPerChannel() { std::vector<AudioStreamingPart::StreamingPartChannel> get10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder) {
if (_didReadToEnd) { if (_didReadToEnd) {
return {}; return {};
} }
@ -506,30 +206,50 @@ public:
} }
} }
auto readResult = _parsedPart.readPcm(_pcm10ms); auto readResult = _parsedPart.readPcm(persistentDecoder, _pcm10ms);
if (readResult.numSamples <= 0) { if (readResult.numSamples <= 0) {
_didReadToEnd = true; _didReadToEnd = true;
return {}; return {};
} }
std::vector<AudioStreamingPart::StreamingPartChannel> resultChannels; std::vector<AudioStreamingPart::StreamingPartChannel> resultChannels;
for (const auto ssrc : _allSsrcs) {
AudioStreamingPart::StreamingPartChannel emptyPart;
emptyPart.ssrc = ssrc;
resultChannels.push_back(emptyPart);
}
for (auto &channel : resultChannels) { if (_isSingleChannel) {
auto mappedChannelIndex = getCurrentMappedChannelIndex(channel.ssrc); for (int i = 0; i < readResult.numChannels; i++) {
AudioStreamingPart::StreamingPartChannel emptyPart;
emptyPart.ssrc = i + 1;
resultChannels.push_back(emptyPart);
}
if (mappedChannelIndex) { for (int i = 0; i < readResult.numChannels; i++) {
int sourceChannelIndex = mappedChannelIndex.value(); auto channel = resultChannels.begin() + i;
int sourceChannelIndex = i;
for (int j = 0; j < readResult.numSamples; j++) { 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 { channel->numSamples += readResult.numSamples;
for (int j = 0; j < readResult.numSamples; j++) { }
channel.pcmData.push_back(0); } 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;
} }
} }
} }
@ -566,6 +286,7 @@ private:
} }
private: private:
bool _isSingleChannel = false;
AudioStreamingPartInternal _parsedPart; AudioStreamingPartInternal _parsedPart;
std::set<uint32_t> _allSsrcs; std::set<uint32_t> _allSsrcs;
@ -577,9 +298,9 @@ private:
bool _didReadToEnd = false; 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()) { if (!data.empty()) {
_state = new AudioStreamingPartState(std::move(data)); _state = new AudioStreamingPartState(std::move(data), container, isSingleChannel);
} }
} }
@ -597,9 +318,9 @@ int AudioStreamingPart::getRemainingMilliseconds() const {
return _state ? _state->getRemainingMilliseconds() : 0; return _state ? _state->getRemainingMilliseconds() : 0;
} }
std::vector<AudioStreamingPart::StreamingPartChannel> AudioStreamingPart::get10msPerChannel() { std::vector<AudioStreamingPart::StreamingPartChannel> AudioStreamingPart::get10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder) {
return _state return _state
? _state->get10msPerChannel() ? _state->get10msPerChannel(persistentDecoder)
: std::vector<AudioStreamingPart::StreamingPartChannel>(); : std::vector<AudioStreamingPart::StreamingPartChannel>();
} }

View File

@ -3,9 +3,12 @@
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include <vector> #include <vector>
#include <string>
#include <map> #include <map>
#include <stdint.h> #include <stdint.h>
#include "AudioStreamingPartPersistentDecoder.h"
namespace tgcalls { namespace tgcalls {
class AudioStreamingPartState; class AudioStreamingPartState;
@ -15,11 +18,12 @@ public:
struct StreamingPartChannel { struct StreamingPartChannel {
uint32_t ssrc = 0; uint32_t ssrc = 0;
std::vector<int16_t> pcmData; 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();
AudioStreamingPart(const AudioStreamingPart&) = delete; AudioStreamingPart(const AudioStreamingPart&) = delete;
AudioStreamingPart(AudioStreamingPart&& other) { AudioStreamingPart(AudioStreamingPart&& other) {
_state = other._state; _state = other._state;
@ -30,8 +34,8 @@ public:
std::map<std::string, int32_t> getEndpointMapping() const; std::map<std::string, int32_t> getEndpointMapping() const;
int getRemainingMilliseconds() const; int getRemainingMilliseconds() const;
std::vector<StreamingPartChannel> get10msPerChannel(); std::vector<StreamingPartChannel> get10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder);
private: private:
AudioStreamingPartState *_state = nullptr; 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 "system_wrappers/include/field_trial.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h" #include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "call/call.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 "api/call/audio_sink.h"
#include "modules/audio_processing/audio_buffer.h" #include "modules/audio_processing/audio_buffer.h"
#include "absl/strings/match.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/cpu_features.h"
#include "modules/audio_processing/agc2/vad_wrapper.h"
#include "pc/channel_manager.h" #include "pc/channel_manager.h"
#include "audio/audio_state.h" #include "audio/audio_state.h"
#include "modules/audio_coding/neteq/default_neteq_factory.h" #include "modules/audio_coding/neteq/default_neteq_factory.h"
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "common_audio/include/audio_util.h" #include "common_audio/include/audio_util.h"
#include "modules/audio_device/include/audio_device_data_observer.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 "AudioFrame.h"
#include "ThreadLocalObject.h" #include "ThreadLocalObject.h"
@ -50,7 +52,9 @@
#include "AudioDeviceHelper.h" #include "AudioDeviceHelper.h"
#include "FakeAudioDeviceModule.h" #include "FakeAudioDeviceModule.h"
#include "StreamingMediaContext.h" #include "StreamingMediaContext.h"
#ifdef WEBRTC_IOS
#include "platform/darwin/iOS/tgcalls_audio_device_module_ios.h"
#endif
#include <mutex> #include <mutex>
#include <random> #include <random>
#include <sstream> #include <sstream>
@ -273,7 +277,7 @@ static std::vector<webrtc::SdpVideoFormat> filterSupportedVideoFormats(std::vect
return lhsLevelAssymetryAllowedPriority < rhsLevelAssymetryAllowedPriority; return lhsLevelAssymetryAllowedPriority < rhsLevelAssymetryAllowedPriority;
} }
return true; return false;
}); });
filteredFormats.push_back(h264Formats[0]); filteredFormats.push_back(h264Formats[0]);
@ -467,15 +471,14 @@ public:
class CombinedVad { class CombinedVad {
private: private:
std::unique_ptr<webrtc::VadLevelAnalyzer> _vadWithLevel; webrtc::VoiceActivityDetectorWrapper _vadWithLevel;
VadHistory _history; VadHistory _history;
bool _countFrames; bool _countFrames;
std::atomic<int32_t> _waitingFramesToProcess{0}; std::atomic<int32_t> _waitingFramesToProcess{0};
public: public:
CombinedVad(bool count = false){ CombinedVad() :
_vadWithLevel = std::make_unique<webrtc::VadLevelAnalyzer>(500, webrtc::GetAvailableCpuFeatures()); _vadWithLevel(500, webrtc::GetAvailableCpuFeatures(), webrtc::AudioProcessing::kSampleRate48kHz) {
_countFrames = count;
} }
~CombinedVad() = default; ~CombinedVad() = default;
@ -489,25 +492,25 @@ public:
} }
bool update(webrtc::AudioBuffer *buffer) { bool update(webrtc::AudioBuffer *buffer) {
if (buffer) { if (buffer->num_channels() <= 0) {
if (_countFrames) { return _history.update(0.0f);
_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);
} }
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, AudioSinkImpl(std::function<void(Update)> update,
ChannelId channel_id, std::function<void(uint32_t, const AudioFrame &)> onAudioFrame) : ChannelId channel_id, std::function<void(uint32_t, const AudioFrame &)> onAudioFrame) :
_update(update), _channel_id(channel_id), _onAudioFrame(std::move(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() { virtual ~AudioSinkImpl() {
@ -620,7 +623,7 @@ public:
virtual void OnFrame(const webrtc::VideoFrame& frame) override { virtual void OnFrame(const webrtc::VideoFrame& frame) override {
std::unique_lock<std::mutex> lock{ _mutex }; std::unique_lock<std::mutex> lock{ _mutex };
/*int64_t timestamp = rtc::TimeMillis(); int64_t timestamp = rtc::TimeMillis();
if (_lastFrame) { if (_lastFrame) {
if (_lastFrame->video_frame_buffer()->width() != frame.video_frame_buffer()->width()) { if (_lastFrame->video_frame_buffer()->width() != frame.video_frame_buffer()->width()) {
int64_t deltaTime = std::abs(_lastFrameSizeChangeTimestamp - timestamp); int64_t deltaTime = std::abs(_lastFrameSizeChangeTimestamp - timestamp);
@ -635,7 +638,7 @@ public:
_lastFrameSizeChangeHeight = 0; _lastFrameSizeChangeHeight = 0;
_lastFrameSizeChangeTimestamp = timestamp; _lastFrameSizeChangeTimestamp = timestamp;
} }
_lastFrame = frame;*/ _lastFrame = frame;
for (int i = (int)(_sinks.size()) - 1; i >= 0; i--) { for (int i = (int)(_sinks.size()) - 1; i >= 0; i--) {
auto strong = _sinks[i].lock(); auto strong = _sinks[i].lock();
if (!strong) { if (!strong) {
@ -659,11 +662,10 @@ public:
} }
void addSink(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> impl) { void addSink(std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> impl) {
std::unique_lock<std::mutex> lock{ _mutex }; if (const auto strong = impl.lock()) {
_sinks.push_back(impl); std::unique_lock<std::mutex> lock{ _mutex };
if (_lastFrame) { _sinks.push_back(impl);
auto strong = impl.lock(); if (_lastFrame) {
if (strong) {
strong->OnFrame(_lastFrame.value()); strong->OnFrame(_lastFrame.value());
} }
} }
@ -927,7 +929,8 @@ public:
std::string streamId = std::string("stream") + ssrc.name(); std::string streamId = std::string("stream") + ssrc.name();
_audioChannel = _channelManager->CreateVoiceChannel(_call, cricket::MediaConfig(), rtpTransport, _threads->getWorkerThread(), std::string("audio") + uint32ToString(ssrc.networkSsrc), false, GroupNetworkManager::getDefaulCryptoOptions(), randomIdGenerator, audioOptions); _audioChannel = _channelManager->CreateVoiceChannel(_call, cricket::MediaConfig(), std::string("audio") + uint32ToString(ssrc.networkSsrc), false, GroupNetworkManager::getDefaulCryptoOptions(), audioOptions);
_audioChannel->SetRtpTransport(rtpTransport);
const uint8_t opusPTimeMs = 120; const uint8_t opusPTimeMs = 120;
@ -964,8 +967,9 @@ public:
streamParams.set_stream_ids({ streamId }); streamParams.set_stream_ids({ streamId });
incomingAudioDescription->AddStream(streamParams); incomingAudioDescription->AddStream(streamParams);
_audioChannel->SetLocalContent(outgoingAudioDescription.get(), webrtc::SdpType::kOffer, nullptr); std::string error_desc;
_audioChannel->SetRemoteContent(incomingAudioDescription.get(), webrtc::SdpType::kAnswer, nullptr); _audioChannel->SetLocalContent(outgoingAudioDescription.get(), webrtc::SdpType::kOffer, error_desc);
_audioChannel->SetRemoteContent(incomingAudioDescription.get(), webrtc::SdpType::kAnswer, error_desc);
_audioChannel->SetPayloadTypeDemuxingEnabled(false); _audioChannel->SetPayloadTypeDemuxingEnabled(false);
outgoingAudioDescription.reset(); outgoingAudioDescription.reset();
@ -1100,10 +1104,11 @@ public:
incomingVideoDescription->AddStream(videoRecvStreamParams); incomingVideoDescription->AddStream(videoRecvStreamParams);
_videoChannel = _channelManager->CreateVideoChannel(_call, cricket::MediaConfig(), rtpTransport, _threads->getWorkerThread(), std::string("video") + uint32ToString(mid), false, GroupNetworkManager::getDefaulCryptoOptions(), randomIdGenerator, cricket::VideoOptions(), _videoBitrateAllocatorFactory.get()); _videoChannel = _channelManager->CreateVideoChannel(_call, cricket::MediaConfig(), std::string("video") + uint32ToString(mid), false, GroupNetworkManager::getDefaulCryptoOptions(), cricket::VideoOptions(), _videoBitrateAllocatorFactory.get());
_videoChannel->SetRtpTransport(rtpTransport);
_videoChannel->SetLocalContent(outgoingVideoDescription.get(), webrtc::SdpType::kOffer, nullptr); std::string error_desc;
_videoChannel->SetRemoteContent(incomingVideoDescription.get(), webrtc::SdpType::kAnswer, nullptr); _videoChannel->SetLocalContent(outgoingVideoDescription.get(), webrtc::SdpType::kOffer, error_desc);
_videoChannel->SetRemoteContent(incomingVideoDescription.get(), webrtc::SdpType::kAnswer, error_desc);
_videoChannel->SetPayloadTypeDemuxingEnabled(false); _videoChannel->SetPayloadTypeDemuxingEnabled(false);
_videoChannel->media_channel()->SetSink(_mainVideoSsrc, _videoSink.get()); _videoChannel->media_channel()->SetSink(_mainVideoSsrc, _videoSink.get());
@ -1256,29 +1261,40 @@ public:
} }
void mixAudio(int16_t *audio_samples, const size_t num_samples, const size_t num_channels, const uint32_t samples_per_sec) { 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(); _mutex.Lock();
const auto context = _streamingContext; const auto context = _streamingContext;
_mutex.Unlock(); _mutex.Unlock();
if (context) { if (context) {
context->getAudio(_buffer.data(), num_samples, num_channels, samples_per_sec); if (_samplesToResample.size() < 480 * num_channels) {
memcpy(audio_samples, _buffer.data(), numBytesOut); _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: private:
webrtc::Mutex _mutex; 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; std::shared_ptr<StreamingMediaContext> _streamingContext;
}; };
@ -1303,12 +1319,16 @@ public:
const size_t bytes_per_sample, const size_t bytes_per_sample,
const size_t num_channels, const size_t num_channels,
const uint32_t samples_per_sec) override { const uint32_t samples_per_sec) override {
if (samples_per_sec != 48000) {
return;
}
if (bytes_per_sample != num_channels * 2) { if (bytes_per_sample != num_channels * 2) {
return; return;
} }
if (samples_per_sec % 100 != 0) {
return;
}
if (num_samples != samples_per_sec / 100) {
return;
}
if (_shared) { if (_shared) {
_shared->mixAudio((int16_t *)audio_samples, num_samples, num_channels, samples_per_sec); _shared->mixAudio((int16_t *)audio_samples, num_samples, num_channels, samples_per_sec);
} }
@ -1318,6 +1338,48 @@ private:
std::shared_ptr<AudioDeviceDataObserverShared> _shared; 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 } // namespace
class GroupInstanceCustomInternal : public sigslot::has_slots<>, public std::enable_shared_from_this<GroupInstanceCustomInternal> { class GroupInstanceCustomInternal : public sigslot::has_slots<>, public std::enable_shared_from_this<GroupInstanceCustomInternal> {
@ -1338,11 +1400,15 @@ public:
_useDummyChannel(descriptor.useDummyChannel), _useDummyChannel(descriptor.useDummyChannel),
_outgoingAudioBitrateKbit(descriptor.outgoingAudioBitrateKbit), _outgoingAudioBitrateKbit(descriptor.outgoingAudioBitrateKbit),
_disableOutgoingAudioProcessing(descriptor.disableOutgoingAudioProcessing), _disableOutgoingAudioProcessing(descriptor.disableOutgoingAudioProcessing),
#ifdef WEBRTC_IOS
_disableAudioInput(descriptor.disableAudioInput),
#endif
_minOutgoingVideoBitrateKbit(descriptor.minOutgoingVideoBitrateKbit), _minOutgoingVideoBitrateKbit(descriptor.minOutgoingVideoBitrateKbit),
_videoContentType(descriptor.videoContentType), _videoContentType(descriptor.videoContentType),
_videoCodecPreferences(std::move(descriptor.videoCodecPreferences)), _videoCodecPreferences(std::move(descriptor.videoCodecPreferences)),
_eventLog(std::make_unique<webrtc::RtcEventLogNull>()), _eventLog(std::make_unique<webrtc::RtcEventLogNull>()),
_taskQueueFactory(webrtc::CreateDefaultTaskQueueFactory()), _taskQueueFactory(webrtc::CreateDefaultTaskQueueFactory()),
_netEqFactory(createNetEqFactory()),
_createAudioDeviceModule(descriptor.createAudioDeviceModule), _createAudioDeviceModule(descriptor.createAudioDeviceModule),
_initialInputDeviceId(std::move(descriptor.initialInputDeviceId)), _initialInputDeviceId(std::move(descriptor.initialInputDeviceId)),
_initialOutputDeviceId(std::move(descriptor.initialOutputDeviceId)), _initialOutputDeviceId(std::move(descriptor.initialOutputDeviceId)),
@ -1400,14 +1466,13 @@ public:
"WebRTC-TaskQueuePacer/Enabled/" "WebRTC-TaskQueuePacer/Enabled/"
"WebRTC-VP8ConferenceTemporalLayers/1/" "WebRTC-VP8ConferenceTemporalLayers/1/"
"WebRTC-Audio-MinimizeResamplingOnMobile/Enabled/" "WebRTC-Audio-MinimizeResamplingOnMobile/Enabled/"
//"WebRTC-MutedStateKillSwitch/Enabled/" "WebRTC-BweLossExperiment/Enabled/"
//"WebRTC-VP8IosMaxNumberOfThread/max_thread:1/"
); );
_networkManager.reset(new ThreadLocalObject<GroupNetworkManager>(_threads->getNetworkThread(), [weak, threads = _threads] () mutable { _networkManager.reset(new ThreadLocalObject<GroupNetworkManager>(_threads->getNetworkThread(), [weak, threads = _threads] () mutable {
return new GroupNetworkManager( return new GroupNetworkManager(
[=](const GroupNetworkManager::State &state) { [=](const GroupNetworkManager::State &state) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [=] { threads->getMediaThread()->PostTask([=] {
const auto strong = weak.lock(); const auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -1419,28 +1484,28 @@ public:
if (!isUnresolved) { if (!isUnresolved) {
return; return;
} }
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, message, isUnresolved]() mutable { threads->getMediaThread()->PostTask([weak, message, isUnresolved]() mutable {
if (const auto strong = weak.lock()) { if (const auto strong = weak.lock()) {
strong->receivePacket(message, isUnresolved); strong->receivePacket(message, isUnresolved);
} }
}); });
}, },
[=](bool isDataChannelOpen) { [=](bool isDataChannelOpen) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, isDataChannelOpen]() mutable { threads->getMediaThread()->PostTask([weak, isDataChannelOpen]() mutable {
if (const auto strong = weak.lock()) { if (const auto strong = weak.lock()) {
strong->updateIsDataChannelOpen(isDataChannelOpen); strong->updateIsDataChannelOpen(isDataChannelOpen);
} }
}); });
}, },
[=](std::string const &message) { [=](std::string const &message) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, message]() { threads->getMediaThread()->PostTask([weak, message]() {
if (const auto strong = weak.lock()) { if (const auto strong = weak.lock()) {
strong->receiveDataChannelMessage(message); strong->receiveDataChannelMessage(message);
} }
}); });
}, },
[=](uint32_t ssrc, uint8_t audioLevel, bool isSpeech) { [=](uint32_t ssrc, uint8_t audioLevel, bool isSpeech) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, ssrc, audioLevel, isSpeech]() { threads->getMediaThread()->PostTask([weak, ssrc, audioLevel, isSpeech]() {
if (const auto strong = weak.lock()) { if (const auto strong = weak.lock()) {
strong->updateSsrcAudioLevel(ssrc, audioLevel, isSpeech); strong->updateSsrcAudioLevel(ssrc, audioLevel, isSpeech);
} }
@ -1456,7 +1521,7 @@ public:
#if USE_RNNOISE #if USE_RNNOISE
audioProcessor = std::make_unique<AudioCapturePostProcessor>([weak, threads = _threads](GroupLevelValue const &level) { audioProcessor = std::make_unique<AudioCapturePostProcessor>([weak, threads = _threads](GroupLevelValue const &level) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, level](){ threads->getMediaThread()->PostTask([weak, level](){
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -1477,7 +1542,7 @@ public:
mediaDeps.audio_encoder_factory = webrtc::CreateAudioEncoderFactory<webrtc::AudioEncoderOpus, webrtc::AudioEncoderL16>(); mediaDeps.audio_encoder_factory = webrtc::CreateAudioEncoderFactory<webrtc::AudioEncoderOpus, webrtc::AudioEncoderL16>();
mediaDeps.audio_decoder_factory = webrtc::CreateAudioDecoderFactory<webrtc::AudioDecoderOpus, webrtc::AudioDecoderL16>(); 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); mediaDeps.video_decoder_factory = PlatformInterface::SharedInstance()->makeVideoDecoderFactory(_platformContext);
#if USE_RNNOISE #if USE_RNNOISE
@ -1485,6 +1550,8 @@ public:
webrtc::AudioProcessingBuilder builder; webrtc::AudioProcessingBuilder builder;
builder.SetCapturePostProcessing(std::move(audioProcessor)); builder.SetCapturePostProcessing(std::move(audioProcessor));
builder.SetEchoDetector(rtc::make_ref_counted<CustomEchoDetector>());
mediaDeps.audio_processing = builder.Create(); mediaDeps.audio_processing = builder.Create();
} }
#endif #endif
@ -1514,10 +1581,11 @@ public:
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this]() { _threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this]() {
webrtc::Call::Config callConfig(_eventLog.get(), _threads->getNetworkThread()); webrtc::Call::Config callConfig(_eventLog.get(), _threads->getNetworkThread());
callConfig.neteq_factory = _netEqFactory.get();
callConfig.task_queue_factory = _taskQueueFactory.get(); callConfig.task_queue_factory = _taskQueueFactory.get();
callConfig.trials = &_fieldTrials; callConfig.trials = &_fieldTrials;
callConfig.audio_state = _channelManager->media_engine()->voice().GetAudioState(); 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()); _uniqueRandomIdGenerator.reset(new rtc::UniqueRandomIdGenerator());
@ -1586,8 +1654,8 @@ public:
if (_videoContentType == VideoContentType::Screencast) { if (_videoContentType == VideoContentType::Screencast) {
videoOptions.is_screencast = true; videoOptions.is_screencast = true;
} }
_outgoingVideoChannel = _channelManager->CreateVideoChannel(_call.get(), cricket::MediaConfig(), _rtpTransport, _threads->getWorkerThread(), "1", false, GroupNetworkManager::getDefaulCryptoOptions(), _uniqueRandomIdGenerator.get(), videoOptions, _videoBitrateAllocatorFactory.get()); _outgoingVideoChannel = _channelManager->CreateVideoChannel(_call.get(), cricket::MediaConfig(), "1", false, GroupNetworkManager::getDefaulCryptoOptions(), videoOptions, _videoBitrateAllocatorFactory.get());
_outgoingVideoChannel->SetRtpTransport(_rtpTransport);
if (!_outgoingVideoChannel) { if (!_outgoingVideoChannel) {
RTC_LOG(LS_ERROR) << "Could not create outgoing video channel."; RTC_LOG(LS_ERROR) << "Could not create outgoing video channel.";
return; return;
@ -1646,11 +1714,12 @@ public:
incomingVideoDescription->set_codecs({ _selectedPayloadType->videoCodec, _selectedPayloadType->rtxCodec }); incomingVideoDescription->set_codecs({ _selectedPayloadType->videoCodec, _selectedPayloadType->rtxCodec });
incomingVideoDescription->set_bandwidth(1300000); incomingVideoDescription->set_bandwidth(1300000);
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this, incomingVideoDescription, outgoingVideoDescription]() { _threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [&]() {
_outgoingVideoChannel->SetRemoteContent(incomingVideoDescription.get(), webrtc::SdpType::kAnswer, nullptr); std::string error_desc;
_outgoingVideoChannel->SetLocalContent(outgoingVideoDescription.get(), webrtc::SdpType::kOffer, nullptr); _outgoingVideoChannel->SetRemoteContent(incomingVideoDescription.get(), webrtc::SdpType::kAnswer, error_desc);
_outgoingVideoChannel->SetPayloadTypeDemuxingEnabled(false); _outgoingVideoChannel->SetLocalContent(outgoingVideoDescription.get(), webrtc::SdpType::kOffer, error_desc);
}); _outgoingVideoChannel->SetPayloadTypeDemuxingEnabled(false);
});
adjustVideoSendParams(); adjustVideoSendParams();
updateVideoSend(); updateVideoSend();
@ -1782,21 +1851,21 @@ public:
audioOptions.auto_gain_control = false; audioOptions.auto_gain_control = false;
audioOptions.highpass_filter = false; audioOptions.highpass_filter = false;
audioOptions.typing_detection = false; audioOptions.typing_detection = false;
audioOptions.experimental_agc = false; // audioOptions.experimental_agc = false;
audioOptions.experimental_ns = false; // audioOptions.experimental_ns = false;
audioOptions.residual_echo_detector = false; audioOptions.residual_echo_detector = false;
} else { } else {
audioOptions.echo_cancellation = true; audioOptions.echo_cancellation = true;
audioOptions.noise_suppression = true; audioOptions.noise_suppression = true;
audioOptions.experimental_ns = true; // audioOptions.experimental_ns = true;
audioOptions.residual_echo_detector = true; audioOptions.residual_echo_detector = true;
} }
std::vector<std::string> streamIds; std::vector<std::string> streamIds;
streamIds.push_back("1"); streamIds.push_back("1");
_outgoingAudioChannel = _channelManager->CreateVoiceChannel(_call.get(), cricket::MediaConfig(), _rtpTransport, _threads->getWorkerThread(), "0", false, GroupNetworkManager::getDefaulCryptoOptions(), _uniqueRandomIdGenerator.get(), audioOptions); _outgoingAudioChannel = _channelManager->CreateVoiceChannel(_call.get(), cricket::MediaConfig(), "0", false, GroupNetworkManager::getDefaulCryptoOptions(), audioOptions);
_outgoingAudioChannel->SetRtpTransport(_rtpTransport);
const uint8_t opusMinBitrateKbps = _outgoingAudioBitrateKbit; const uint8_t opusMinBitrateKbps = _outgoingAudioBitrateKbit;
const uint8_t opusMaxBitrateKbps = _outgoingAudioBitrateKbit; const uint8_t opusMaxBitrateKbps = _outgoingAudioBitrateKbit;
const uint8_t opusStartBitrateKbps = _outgoingAudioBitrateKbit; const uint8_t opusStartBitrateKbps = _outgoingAudioBitrateKbit;
@ -1831,9 +1900,10 @@ public:
incomingAudioDescription->set_codecs({ opusCodec }); incomingAudioDescription->set_codecs({ opusCodec });
incomingAudioDescription->set_bandwidth(1300000); 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); std::string error_desc;
_outgoingAudioChannel->SetRemoteContent(incomingAudioDescription.get(), webrtc::SdpType::kAnswer, nullptr); _outgoingAudioChannel->SetLocalContent(outgoingAudioDescription.get(), webrtc::SdpType::kOffer, error_desc);
_outgoingAudioChannel->SetRemoteContent(incomingAudioDescription.get(), webrtc::SdpType::kAnswer, error_desc);
_outgoingAudioChannel->SetPayloadTypeDemuxingEnabled(false); _outgoingAudioChannel->SetPayloadTypeDemuxingEnabled(false);
_outgoingAudioChannel->Enable(true); _outgoingAudioChannel->Enable(true);
}); });
@ -1879,7 +1949,7 @@ public:
void beginLevelsTimer(int timeoutMs) { void beginLevelsTimer(int timeoutMs) {
const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this()); const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this());
_threads->getMediaThread()->PostDelayedTask(RTC_FROM_HERE, [weak]() { _threads->getMediaThread()->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -1940,7 +2010,7 @@ public:
void beginAudioChannelCleanupTimer(int delayMs) { void beginAudioChannelCleanupTimer(int delayMs) {
const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this()); const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this());
_threads->getMediaThread()->PostDelayedTask(RTC_FROM_HERE, [weak]() { _threads->getMediaThread()->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -1969,7 +2039,7 @@ public:
void beginRemoteConstraintsUpdateTimer(int delayMs) { void beginRemoteConstraintsUpdateTimer(int delayMs) {
const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this()); const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this());
_threads->getMediaThread()->PostDelayedTask(RTC_FROM_HERE, [weak]() { _threads->getMediaThread()->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -1983,7 +2053,7 @@ public:
void beginNetworkStatusTimer(int delayMs) { void beginNetworkStatusTimer(int delayMs) {
const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this()); const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this());
_threads->getMediaThread()->PostDelayedTask(RTC_FROM_HERE, [weak]() { _threads->getMediaThread()->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -2137,11 +2207,9 @@ public:
void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer *buffer, int64_t packet_time_us) { void OnRtcpPacketReceived_n(rtc::CopyOnWriteBuffer *buffer, int64_t packet_time_us) {
rtc::CopyOnWriteBuffer packet = *buffer; rtc::CopyOnWriteBuffer packet = *buffer;
_threads->getWorkerThread()->PostTask(ToQueuedTask(_workerThreadSafery, [this, packet, packet_time_us] { if (_call) {
if (_call) { _call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, packet_time_us);
_call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, packet_time_us); }
}
}));
} }
void adjustBitratePreferences(bool resetStartBitrate) { void adjustBitratePreferences(bool resetStartBitrate) {
@ -2253,39 +2321,29 @@ public:
} }
} }
webrtc::RtpUtility::RtpHeaderParser rtpParser(packet.data(), packet.size()); if (webrtc::IsRtcpPacket(packet)) {
webrtc::RTPHeader header;
if (rtpParser.RTCP()) {
if (!rtpParser.ParseRtcp(&header)) {
RTC_LOG(LS_INFO) << "Could not parse rtcp header";
return;
}
_threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this, packet]() { _threads->getWorkerThread()->Invoke<void>(RTC_FROM_HERE, [this, packet]() {
_call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, -1); _call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, -1);
}); });
} else { } else {
if (!rtpParser.Parse(&header)) { uint32_t ssrc = webrtc::ParseRtpSsrc(packet);
// Probably a data channel message int payloadType = webrtc::ParseRtpPayloadType(packet);
if (ssrc == _outgoingAudioSsrc) {
return; return;
} }
if (header.ssrc == _outgoingAudioSsrc) { auto ssrcInfo = _channelBySsrc.find(ssrc);
return;
}
auto ssrcInfo = _channelBySsrc.find(header.ssrc);
if (ssrcInfo == _channelBySsrc.end()) { if (ssrcInfo == _channelBySsrc.end()) {
// opus // opus
if (header.payloadType == 111) { if (payloadType == 111) {
maybeRequestUnknownSsrc(header.ssrc); maybeRequestUnknownSsrc(ssrc);
_missingPacketBuffer.add(header.ssrc, packet); _missingPacketBuffer.add(ssrc, packet);
} }
} else { } else {
switch (ssrcInfo->second.type) { switch (ssrcInfo->second.type) {
case ChannelSsrcInfo::Type::Audio: { case ChannelSsrcInfo::Type::Audio: {
const auto it = _incomingAudioChannels.find(ChannelId(header.ssrc)); const auto it = _incomingAudioChannels.find(ChannelId(ssrc));
if (it != _incomingAudioChannels.end()) { if (it != _incomingAudioChannels.end()) {
it->second->updateActivity(); it->second->updateActivity();
} }
@ -2304,7 +2362,7 @@ public:
} }
void receiveRtcpPacket(rtc::CopyOnWriteBuffer const &packet, int64_t timestamp) { void receiveRtcpPacket(rtc::CopyOnWriteBuffer const &packet, int64_t timestamp) {
_threads->getWorkerThread()->PostTask(RTC_FROM_HERE, [this, packet, timestamp]() { _threads->getWorkerThread()->PostTask([this, packet, timestamp]() {
_call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, timestamp); _call->Receiver()->DeliverPacket(webrtc::MediaType::ANY, packet, timestamp);
}); });
} }
@ -2335,7 +2393,7 @@ public:
_pendingOutgoingVideoConstraintRequestId += 1; _pendingOutgoingVideoConstraintRequestId += 1;
const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this()); const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this());
_threads->getMediaThread()->PostDelayedTask(RTC_FROM_HERE, [weak, requestId]() { _threads->getMediaThread()->PostDelayedTask([weak, requestId]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -2435,7 +2493,7 @@ public:
const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this()); const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this());
auto task = _requestMediaChannelDescriptions(requestSsrcs, [weak, threads = _threads, requestId](std::vector<MediaChannelDescription> &&descriptions) { auto task = _requestMediaChannelDescriptions(requestSsrcs, [weak, threads = _threads, requestId](std::vector<MediaChannelDescription> &&descriptions) {
threads->getWorkerThread()->PostTask(RTC_FROM_HERE, [weak, requestId, descriptions = std::move(descriptions)]() mutable { threads->getWorkerThread()->PostTask([weak, requestId, descriptions = std::move(descriptions)]() mutable {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -2555,10 +2613,11 @@ public:
}); });
} }
void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) { void setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled, bool isUnifiedBroadcast) {
if (_connectionMode != connectionMode || connectionMode == GroupConnectionMode::GroupConnectionModeNone) { if (_connectionMode != connectionMode || connectionMode == GroupConnectionMode::GroupConnectionModeNone) {
GroupConnectionMode previousMode = _connectionMode; GroupConnectionMode previousMode = _connectionMode;
_connectionMode = connectionMode; _connectionMode = connectionMode;
_isUnifiedBroadcast = isUnifiedBroadcast;
onConnectionModeUpdated(previousMode, keepBroadcastIfWasEnabled); onConnectionModeUpdated(previousMode, keepBroadcastIfWasEnabled);
} }
} }
@ -2612,6 +2671,7 @@ public:
const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this()); const auto weak = std::weak_ptr<GroupInstanceCustomInternal>(shared_from_this());
arguments.threads = _threads; arguments.threads = _threads;
arguments.platformContext = _platformContext; arguments.platformContext = _platformContext;
arguments.isUnifiedBroadcast = _isUnifiedBroadcast;
arguments.requestCurrentTime = _requestCurrentTime; arguments.requestCurrentTime = _requestCurrentTime;
arguments.requestAudioBroadcastPart = _requestAudioBroadcastPart; arguments.requestAudioBroadcastPart = _requestAudioBroadcastPart;
arguments.requestVideoBroadcastPart = _requestVideoBroadcastPart; arguments.requestVideoBroadcastPart = _requestVideoBroadcastPart;
@ -2653,7 +2713,7 @@ public:
break; break;
} }
default: { default: {
//RTC_FATAL() << "Unknown connectionMode"; RTC_FATAL() << "Unknown connectionMode";
break; break;
} }
} }
@ -2920,6 +2980,14 @@ public:
_noiseSuppressionConfiguration->isEnabled = isNoiseSuppressionEnabled; _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) { void addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) {
if (_sharedVideoInformation && endpointId == _sharedVideoInformation->endpointId) { if (_sharedVideoInformation && endpointId == _sharedVideoInformation->endpointId) {
if (_videoCapture) { if (_videoCapture) {
@ -2945,7 +3013,7 @@ public:
return; return;
} }
if (_incomingAudioChannels.size() > 5) { if (_incomingAudioChannels.size() > 10) {
auto timestamp = rtc::TimeMillis(); auto timestamp = rtc::TimeMillis();
int64_t minActivity = INT64_MAX; int64_t minActivity = INT64_MAX;
@ -2966,7 +3034,7 @@ public:
removeIncomingAudioChannel(minActivityChannelId); removeIncomingAudioChannel(minActivityChannelId);
} }
if (_incomingAudioChannels.size() > 5) { if (_incomingAudioChannels.size() > 10) {
// Wait until there is a channel that hasn't been active in 1 second // Wait until there is a channel that hasn't been active in 1 second
return; return;
} }
@ -2978,7 +3046,7 @@ public:
if (ssrc.actualSsrc != ssrc.networkSsrc) { if (ssrc.actualSsrc != ssrc.networkSsrc) {
if (_audioLevelsUpdated) { if (_audioLevelsUpdated) {
onAudioSinkUpdate = [weak, ssrc = ssrc, threads = _threads](AudioSinkImpl::Update update) { onAudioSinkUpdate = [weak, ssrc = ssrc, threads = _threads](AudioSinkImpl::Update update) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, ssrc, update]() { threads->getMediaThread()->PostTask([weak, ssrc, update]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -3229,10 +3297,17 @@ public:
private: private:
rtc::scoped_refptr<WrappedAudioDeviceModule> createAudioDeviceModule() { rtc::scoped_refptr<WrappedAudioDeviceModule> createAudioDeviceModule() {
auto audioDeviceDataObserverShared = _audioDeviceDataObserverShared; auto audioDeviceDataObserverShared = _audioDeviceDataObserverShared;
#ifdef WEBRTC_IOS
bool disableRecording = _disableAudioInput;
#endif
const auto create = [&](webrtc::AudioDeviceModule::AudioLayer layer) { 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( return webrtc::AudioDeviceModule::Create(
layer, layer,
_taskQueueFactory.get()); _taskQueueFactory.get());
#endif
}; };
const auto check = [&](const rtc::scoped_refptr<webrtc::AudioDeviceModule> &result) -> rtc::scoped_refptr<WrappedAudioDeviceModule> { const auto check = [&](const rtc::scoped_refptr<webrtc::AudioDeviceModule> &result) -> rtc::scoped_refptr<WrappedAudioDeviceModule> {
if (!result) { if (!result) {
@ -3267,6 +3342,7 @@ private:
private: private:
std::shared_ptr<Threads> _threads; std::shared_ptr<Threads> _threads;
GroupConnectionMode _connectionMode = GroupConnectionMode::GroupConnectionModeNone; GroupConnectionMode _connectionMode = GroupConnectionMode::GroupConnectionModeNone;
bool _isUnifiedBroadcast = false;
std::function<void(GroupNetworkState)> _networkStateUpdated; std::function<void(GroupNetworkState)> _networkStateUpdated;
std::function<void(GroupLevelsUpdate const &)> _audioLevelsUpdated; std::function<void(GroupLevelsUpdate const &)> _audioLevelsUpdated;
@ -3282,6 +3358,9 @@ private:
bool _useDummyChannel{true}; bool _useDummyChannel{true};
int _outgoingAudioBitrateKbit{32}; int _outgoingAudioBitrateKbit{32};
bool _disableOutgoingAudioProcessing{false}; bool _disableOutgoingAudioProcessing{false};
#ifdef WEBRTC_IOS
bool _disableAudioInput{false};
#endif
int _minOutgoingVideoBitrateKbit{100}; int _minOutgoingVideoBitrateKbit{100};
VideoContentType _videoContentType{VideoContentType::None}; VideoContentType _videoContentType{VideoContentType::None};
std::vector<VideoCodecName> _videoCodecPreferences; std::vector<VideoCodecName> _videoCodecPreferences;
@ -3293,6 +3372,7 @@ private:
std::unique_ptr<webrtc::RtcEventLogNull> _eventLog; std::unique_ptr<webrtc::RtcEventLogNull> _eventLog;
std::unique_ptr<webrtc::TaskQueueFactory> _taskQueueFactory; std::unique_ptr<webrtc::TaskQueueFactory> _taskQueueFactory;
std::unique_ptr<webrtc::NetEqFactory> _netEqFactory;
std::unique_ptr<cricket::MediaEngineInterface> _mediaEngine; std::unique_ptr<cricket::MediaEngineInterface> _mediaEngine;
std::unique_ptr<webrtc::Call> _call; std::unique_ptr<webrtc::Call> _call;
webrtc::FieldTrialBasedConfig _fieldTrials; webrtc::FieldTrialBasedConfig _fieldTrials;
@ -3401,9 +3481,9 @@ void GroupInstanceCustomImpl::stop() {
}); });
} }
void GroupInstanceCustomImpl::setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled) { void GroupInstanceCustomImpl::setConnectionMode(GroupConnectionMode connectionMode, bool keepBroadcastIfWasEnabled, bool isUnifiedBroadcast) {
_internal->perform(RTC_FROM_HERE, [connectionMode, keepBroadcastIfWasEnabled](GroupInstanceCustomInternal *internal) { _internal->perform(RTC_FROM_HERE, [connectionMode, keepBroadcastIfWasEnabled, isUnifiedBroadcast](GroupInstanceCustomInternal *internal) {
internal->setConnectionMode(connectionMode, keepBroadcastIfWasEnabled); internal->setConnectionMode(connectionMode, keepBroadcastIfWasEnabled, isUnifiedBroadcast);
}); });
} }
@ -3473,6 +3553,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) { 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->perform(RTC_FROM_HERE, [endpointId, sink](GroupInstanceCustomInternal *internal) mutable {
internal->addIncomingVideoOutput(endpointId, sink); internal->addIncomingVideoOutput(endpointId, sink);

View File

@ -23,7 +23,7 @@ public:
void stop(); 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 emitJoinPayload(std::function<void(GroupJoinPayload const &)> completion);
void setJoinResponsePayload(std::string const &payload); void setJoinResponsePayload(std::string const &payload);
@ -38,6 +38,7 @@ public:
void setAudioInputDevice(std::string id); void setAudioInputDevice(std::string id);
void addExternalAudioSamples(std::vector<uint8_t> &&samples); 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 addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink);
void setVolume(uint32_t ssrc, double volume); 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; 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}; int outgoingAudioBitrateKbit{32};
bool disableOutgoingAudioProcessing{false}; bool disableOutgoingAudioProcessing{false};
bool disableAudioInput{false};
VideoContentType videoContentType{VideoContentType::None}; VideoContentType videoContentType{VideoContentType::None};
bool initialEnableNoiseSuppression{false}; bool initialEnableNoiseSuppression{false};
std::vector<VideoCodecName> videoCodecPreferences; std::vector<VideoCodecName> videoCodecPreferences;
@ -179,7 +180,7 @@ public:
virtual void stop() = 0; 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 emitJoinPayload(std::function<void(GroupJoinPayload const &)> completion) = 0;
virtual void setJoinResponsePayload(std::string const &payload) = 0; virtual void setJoinResponsePayload(std::string const &payload) = 0;
@ -194,6 +195,7 @@ public:
virtual void setAudioInputDevice(std::string id) = 0; virtual void setAudioInputDevice(std::string id) = 0;
virtual void addExternalAudioSamples(std::vector<uint8_t> &&samples) = 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 addIncomingVideoOutput(std::string const &endpointId, std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>> sink) = 0;
virtual void setVolume(uint32_t ssrc, double volume) = 0; virtual void setVolume(uint32_t ssrc, double volume) = 0;

View File

@ -13,8 +13,8 @@
#include "p2p/base/dtls_transport_factory.h" #include "p2p/base/dtls_transport_factory.h"
#include "pc/dtls_srtp_transport.h" #include "pc/dtls_srtp_transport.h"
#include "pc/dtls_transport.h" #include "pc/dtls_transport.h"
#include "modules/rtp_rtcp/source/rtp_util.h"
#include "media/sctp/sctp_transport_factory.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 "modules/rtp_rtcp/source/byte_io.h"
#include "platform/PlatformInterface.h" #include "platform/PlatformInterface.h"
#include "TurnCustomizerImpl.h" #include "TurnCustomizerImpl.h"
@ -324,7 +324,7 @@ _audioActivityUpdated(audioActivityUpdated) {
_networkMonitorFactory = PlatformInterface::SharedInstance()->createNetworkMonitorFactory(); _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()); _networkManager = std::make_unique<rtc::BasicNetworkManager>(_networkMonitorFactory.get());
_asyncResolverFactory = std::make_unique<webrtc::BasicAsyncResolverFactory>(); _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)); _transportChannel.reset(new cricket::P2PTransportChannel("transport", 0, _portAllocator.get(), _asyncResolverFactory.get(), nullptr));
cricket::IceConfig iceConfig; 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.prioritize_most_likely_candidate_pairs = true;
iceConfig.regather_on_failed_networks_interval = 8000; iceConfig.regather_on_failed_networks_interval = 2000;
_transportChannel->SetIceConfig(iceConfig); _transportChannel->SetIceConfig(iceConfig);
cricket::IceParameters localIceParameters( cricket::IceParameters localIceParameters(
@ -509,7 +509,7 @@ webrtc::RtpTransport *GroupNetworkManager::getRtpTransport() {
void GroupNetworkManager::checkConnectionTimeout() { void GroupNetworkManager::checkConnectionTimeout() {
const auto weak = std::weak_ptr<GroupNetworkManager>(shared_from_this()); const auto weak = std::weak_ptr<GroupNetworkManager>(shared_from_this());
_threads->getNetworkThread()->PostDelayedTask(RTC_FROM_HERE, [weak]() { _threads->getNetworkThread()->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -553,7 +553,7 @@ void GroupNetworkManager::DtlsReadyToSend(bool isReadyToSend) {
if (isReadyToSend) { if (isReadyToSend) {
const auto weak = std::weak_ptr<GroupNetworkManager>(shared_from_this()); const auto weak = std::weak_ptr<GroupNetworkManager>(shared_from_this());
_threads->getNetworkThread()->PostTask(RTC_FROM_HERE, [weak]() { _threads->getNetworkThread()->PostTask([weak]() {
const auto strong = weak.lock(); const auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;

View File

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

View File

@ -11,7 +11,7 @@
#include "rtc_base/synchronization/mutex.h" #include "rtc_base/synchronization/mutex.h"
#include "common_audio/ring_buffer.h" #include "common_audio/ring_buffer.h"
#include "modules/audio_mixer/frame_combiner.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 "modules/audio_processing/audio_buffer.h"
#include "api/video/video_sink_interface.h" #include "api/video/video_sink_interface.h"
#include "audio/utility/audio_frame_operations.h" #include "audio/utility/audio_frame_operations.h"
@ -23,6 +23,9 @@ namespace {
struct PendingAudioSegmentData { struct PendingAudioSegmentData {
}; };
struct PendingUnifiedSegmentData {
};
struct PendingVideoSegmentData { struct PendingVideoSegmentData {
int32_t channelId = 0; int32_t channelId = 0;
VideoChannelDescription::Quality quality = VideoChannelDescription::Quality::Thumbnail; VideoChannelDescription::Quality quality = VideoChannelDescription::Quality::Thumbnail;
@ -42,7 +45,7 @@ struct PendingMediaSegmentPartResult {
}; };
struct PendingMediaSegmentPart { struct PendingMediaSegmentPart {
absl::variant<PendingAudioSegmentData, PendingVideoSegmentData> typeData; absl::variant<PendingAudioSegmentData, PendingVideoSegmentData, PendingUnifiedSegmentData> typeData;
int64_t minRequestTimestamp = 0; int64_t minRequestTimestamp = 0;
@ -64,11 +67,21 @@ struct VideoSegment {
std::shared_ptr<PendingMediaSegmentPart> pendingVideoQualityUpdatePart; std::shared_ptr<PendingMediaSegmentPart> pendingVideoQualityUpdatePart;
}; };
struct UnifiedSegment {
std::shared_ptr<VideoStreamingPart> videoPart;
double lastFramePts = -1.0;
int _displayedFrames = 0;
bool isPlaying = false;
};
struct MediaSegment { struct MediaSegment {
int64_t timestamp = 0; int64_t timestamp = 0;
int64_t duration = 0; int64_t duration = 0;
std::shared_ptr<AudioStreamingPart> audio; std::shared_ptr<AudioStreamingPart> audio;
AudioStreamingPartPersistentDecoder audioDecoder;
std::shared_ptr<VideoStreamingPart> unifiedAudio;
std::vector<std::shared_ptr<VideoSegment>> video; std::vector<std::shared_ptr<VideoSegment>> video;
std::vector<std::shared_ptr<UnifiedSegment>> unified;
}; };
class SampleRingBuffer { class SampleRingBuffer {
@ -138,12 +151,12 @@ public:
class CombinedVad { class CombinedVad {
private: private:
std::unique_ptr<webrtc::VadLevelAnalyzer> _vadWithLevel; webrtc::VoiceActivityDetectorWrapper _vadWithLevel;
VadHistory _history; VadHistory _history;
public: public:
CombinedVad() { CombinedVad() :
_vadWithLevel = std::make_unique<webrtc::VadLevelAnalyzer>(500, webrtc::GetAvailableCpuFeatures()); _vadWithLevel(500, webrtc::GetAvailableCpuFeatures(), webrtc::AudioProcessing::kSampleRate48kHz) {
} }
~CombinedVad() { ~CombinedVad() {
@ -153,7 +166,7 @@ public:
if (buffer->num_channels() <= 0) { if (buffer->num_channels() <= 0) {
return _history.update(0.0f); 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; float peak = 0.0f;
for (const auto &x : frameView.channel(0)) { for (const auto &x : frameView.channel(0)) {
peak = std::max(std::fabs(x), peak); peak = std::max(std::fabs(x), peak);
@ -162,9 +175,9 @@ public:
return _history.update(false); 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() { bool update() {
@ -226,6 +239,7 @@ class StreamingMediaContextPrivate : public std::enable_shared_from_this<Streami
public: public:
StreamingMediaContextPrivate(StreamingMediaContext::StreamingMediaContextArguments &&arguments) : StreamingMediaContextPrivate(StreamingMediaContext::StreamingMediaContextArguments &&arguments) :
_threads(arguments.threads), _threads(arguments.threads),
_isUnifiedBroadcast(arguments.isUnifiedBroadcast),
_requestCurrentTime(arguments.requestCurrentTime), _requestCurrentTime(arguments.requestCurrentTime),
_requestAudioBroadcastPart(arguments.requestAudioBroadcastPart), _requestAudioBroadcastPart(arguments.requestAudioBroadcastPart),
_requestVideoBroadcastPart(arguments.requestVideoBroadcastPart), _requestVideoBroadcastPart(arguments.requestVideoBroadcastPart),
@ -244,7 +258,7 @@ public:
void beginRenderTimer(int timeoutMs) { void beginRenderTimer(int timeoutMs) {
const auto weak = std::weak_ptr<StreamingMediaContextPrivate>(shared_from_this()); const auto weak = std::weak_ptr<StreamingMediaContextPrivate>(shared_from_this());
_threads->getMediaThread()->PostDelayedTask(RTC_FROM_HERE, [weak]() { _threads->getMediaThread()->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -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) { if (segment->audio) {
const auto available = [&] { const auto available = [&] {
_audioDataMutex.Lock(); _audioDataMutex.Lock();
const auto result = (_audioRingBuffer.availableForWriting() >= 480); const auto result = (_audioRingBuffer.availableForWriting() >= 480 * _audioRingBufferNumChannels);
_audioDataMutex.Unlock(); _audioDataMutex.Unlock();
return result; return result;
}; };
while (available()) { while (available()) {
auto audioChannels = segment->audio->get10msPerChannel(); auto audioChannels = segment->audio->get10msPerChannel(segment->audioDecoder);
if (audioChannels.empty()) { if (audioChannels.empty()) {
break; break;
} }
@ -348,7 +384,90 @@ public:
} }
_audioDataMutex.Lock(); _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(); _audioDataMutex.Unlock();
} }
} }
@ -397,31 +516,31 @@ public:
_updateAudioLevel(ssrc, vadResult.first, vadResult.second); _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; int16_t *buffer = nullptr;
if (num_channels == 1) { if (num_channels == _audioRingBufferNumChannels) {
buffer = audio_samples; buffer = audio_samples;
} else { } else {
if (_tempAudioBuffer.size() < num_samples) { if (_tempAudioBuffer.size() < num_samples * _audioRingBufferNumChannels) {
_tempAudioBuffer.resize(num_samples); _tempAudioBuffer.resize(num_samples * _audioRingBufferNumChannels);
} }
buffer = _tempAudioBuffer.data(); buffer = _tempAudioBuffer.data();
} }
_audioDataMutex.Lock(); _audioDataMutex.Lock();
size_t readSamples = _audioRingBuffer.read(buffer, num_samples); size_t readSamples = _audioRingBuffer.read(buffer, num_samples * _audioRingBufferNumChannels);
_audioDataMutex.Unlock(); _audioDataMutex.Unlock();
if (num_channels != 1) { if (num_channels != _audioRingBufferNumChannels) {
for (size_t sampleIndex = 0; sampleIndex < readSamples; sampleIndex++) { for (size_t sampleIndex = 0; sampleIndex < readSamples / _audioRingBufferNumChannels; sampleIndex++) {
for (size_t channelIndex = 0; channelIndex < num_channels; channelIndex++) { 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) { if (readSamples < num_samples * num_channels) {
memset(audio_samples + readSamples * num_channels, 0, (num_samples - readSamples) * num_channels * sizeof(int16_t)); memset(audio_samples + readSamples, 0, (num_samples * num_channels - readSamples) * sizeof(int16_t));
} }
} }
@ -449,10 +568,49 @@ public:
void requestSegmentsIfNeeded() { void requestSegmentsIfNeeded() {
while (true) { while (true) {
if (_nextSegmentTimestamp == 0) { if (_nextSegmentTimestamp == -1) {
if (_pendingSegments.size() >= 1) { if (!_pendingRequestTimeTask && _pendingRequestTimeDelayTaskId == 0) {
break; const auto weak = std::weak_ptr<StreamingMediaContextPrivate>(shared_from_this());
_pendingRequestTimeTask = _requestCurrentTime([weak, threads = _threads](int64_t timestamp) {
threads->getMediaThread()->PostTask([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([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 { } else {
int64_t availableAndRequestedSegmentsDuration = 0; int64_t availableAndRequestedSegmentsDuration = 0;
availableAndRequestedSegmentsDuration += getAvailableBufferDuration(); availableAndRequestedSegmentsDuration += getAvailableBufferDuration();
@ -466,12 +624,16 @@ public:
auto pendingSegment = std::make_shared<PendingMediaSegment>(); auto pendingSegment = std::make_shared<PendingMediaSegment>();
pendingSegment->timestamp = _nextSegmentTimestamp; pendingSegment->timestamp = _nextSegmentTimestamp;
if (_nextSegmentTimestamp != 0) { if (_nextSegmentTimestamp != -1) {
_nextSegmentTimestamp += _segmentDuration; _nextSegmentTimestamp += _segmentDuration;
} }
auto audio = std::make_shared<PendingMediaSegmentPart>(); auto audio = std::make_shared<PendingMediaSegmentPart>();
audio->typeData = PendingAudioSegmentData(); if (_isUnifiedBroadcast) {
audio->typeData = PendingUnifiedSegmentData();
} else {
audio->typeData = PendingAudioSegmentData();
}
audio->minRequestTimestamp = 0; audio->minRequestTimestamp = 0;
pendingSegment->parts.push_back(audio); pendingSegment->parts.push_back(audio);
@ -491,7 +653,7 @@ public:
_pendingSegments.push_back(pendingSegment); _pendingSegments.push_back(pendingSegment);
if (_nextSegmentTimestamp == 0) { if (_nextSegmentTimestamp == -1) {
break; break;
} }
} }
@ -556,7 +718,7 @@ public:
auto result = strongSegment->pendingVideoQualityUpdatePart->result; auto result = strongSegment->pendingVideoQualityUpdatePart->result;
if (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(); strongSegment->pendingVideoQualityUpdatePart.reset();
@ -597,9 +759,6 @@ public:
if (!part->result && !part->task) { if (!part->result && !part->task) {
if (part->minRequestTimestamp != 0) { if (part->minRequestTimestamp != 0) {
if (i != 0) {
continue;
}
if (part->minRequestTimestamp > absoluteTimestamp) { if (part->minRequestTimestamp > absoluteTimestamp) {
minDelayedRequestTimeout = std::min(minDelayedRequestTimeout, part->minRequestTimestamp - absoluteTimestamp); minDelayedRequestTimeout = std::min(minDelayedRequestTimeout, part->minRequestTimestamp - absoluteTimestamp);
@ -611,7 +770,7 @@ public:
const auto weakPart = std::weak_ptr<PendingMediaSegmentPart>(part); const auto weakPart = std::weak_ptr<PendingMediaSegmentPart>(part);
std::function<void(BroadcastPart &&)> handleResult = [weak, weakSegment, weakPart, threads = _threads, segmentTimestamp](BroadcastPart &&part) { std::function<void(BroadcastPart &&)> handleResult = [weak, weakSegment, weakPart, threads = _threads, segmentTimestamp](BroadcastPart &&part) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, weakSegment, weakPart, part = std::move(part), segmentTimestamp]() mutable { threads->getMediaThread()->PostTask([weak, weakSegment, weakPart, part = std::move(part), segmentTimestamp]() mutable {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -631,14 +790,14 @@ public:
switch (part.status) { switch (part.status) {
case BroadcastPart::Status::Success: { case BroadcastPart::Status::Success: {
pendingPart->result = std::make_shared<PendingMediaSegmentPartResult>(std::move(part.data)); 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->_nextSegmentTimestamp = part.timestampMilliseconds + strong->_segmentDuration;
} }
strong->checkPendingSegments(); strong->checkPendingSegments();
break; break;
} }
case BroadcastPart::Status::NotReady: { case BroadcastPart::Status::NotReady: {
if (segmentTimestamp == 0) { if (segmentTimestamp == 0 && !strong->_isUnifiedBroadcast) {
int64_t responseTimestampMilliseconds = (int64_t)(part.responseTimestamp * 1000.0); int64_t responseTimestampMilliseconds = (int64_t)(part.responseTimestamp * 1000.0);
int64_t responseTimestampBoundary = (responseTimestampMilliseconds / strong->_segmentDuration) * strong->_segmentDuration; int64_t responseTimestampBoundary = (responseTimestampMilliseconds / strong->_segmentDuration) * strong->_segmentDuration;
@ -653,10 +812,15 @@ public:
break; break;
} }
case BroadcastPart::Status::ResyncNeeded: { case BroadcastPart::Status::ResyncNeeded: {
int64_t responseTimestampMilliseconds = (int64_t)(part.responseTimestamp * 1000.0); if (strong->_isUnifiedBroadcast) {
int64_t responseTimestampBoundary = (responseTimestampMilliseconds / strong->_segmentDuration) * strong->_segmentDuration; 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->discardAllPendingSegments();
strong->requestSegmentsIfNeeded(); strong->requestSegmentsIfNeeded();
strong->checkPendingSegments(); strong->checkPendingSegments();
@ -676,6 +840,8 @@ public:
part->task = _requestAudioBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, handleResult); part->task = _requestAudioBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, handleResult);
} else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) { } else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) {
part->task = _requestVideoBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, videoData->channelId, videoData->quality, handleResult); 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) { for (auto &part : pendingSegment->parts) {
const auto typeData = &part->typeData; const auto typeData = &part->typeData;
if (const auto audioData = absl::get_if<PendingAudioSegmentData>(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(); _currentEndpointMapping = segment->audio->getEndpointMapping();
} else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) { } else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) {
auto videoSegment = std::make_shared<VideoSegment>(); auto videoSegment = std::make_shared<VideoSegment>();
@ -695,8 +861,17 @@ public:
if (part->result->data.empty()) { if (part->result->data.empty()) {
RTC_LOG(LS_INFO) << "Video part " << segment->timestamp << " is 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); 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); _availableSegments.push_back(segment);
@ -710,7 +885,7 @@ public:
if (minDelayedRequestTimeout < INT32_MAX) { if (minDelayedRequestTimeout < INT32_MAX) {
const auto weak = std::weak_ptr<StreamingMediaContextPrivate>(shared_from_this()); const auto weak = std::weak_ptr<StreamingMediaContextPrivate>(shared_from_this());
_threads->getMediaThread()->PostDelayedTask(RTC_FROM_HERE, [weak]() { _threads->getMediaThread()->PostDelayedTask([weak]() {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -729,7 +904,7 @@ public:
const auto weakPart = std::weak_ptr<PendingMediaSegmentPart>(part); const auto weakPart = std::weak_ptr<PendingMediaSegmentPart>(part);
std::function<void(BroadcastPart &&)> handleResult = [weak, weakPart, threads = _threads, completion](BroadcastPart &&part) { std::function<void(BroadcastPart &&)> handleResult = [weak, weakPart, threads = _threads, completion](BroadcastPart &&part) {
threads->getMediaThread()->PostTask(RTC_FROM_HERE, [weak, weakPart, part = std::move(part), completion]() mutable { threads->getMediaThread()->PostTask([weak, weakPart, part = std::move(part), completion]() mutable {
auto strong = weak.lock(); auto strong = weak.lock();
if (!strong) { if (!strong) {
return; return;
@ -768,6 +943,8 @@ public:
part->task = _requestAudioBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, handleResult); part->task = _requestAudioBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, handleResult);
} else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) { } else if (const auto videoData = absl::get_if<PendingVideoSegmentData>(typeData)) {
part->task = _requestVideoBroadcastPart(_platformContext, segmentTimestamp, _segmentDuration, videoData->channelId, videoData->quality, handleResult); 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) { void setActiveVideoChannels(std::vector<StreamingMediaContext::VideoChannel> const &videoChannels) {
_activeVideoChannels = videoChannels; if (_isUnifiedBroadcast) {
return;
/*#if DEBUG
for (auto &updatedVideoChannel : _activeVideoChannels) {
if (updatedVideoChannel.quality == VideoChannelDescription::Quality::Medium) {
updatedVideoChannel.quality = VideoChannelDescription::Quality::Thumbnail;
}
} }
#endif*/ _activeVideoChannels = videoChannels;
for (const auto &updatedVideoChannel : _activeVideoChannels) { for (const auto &updatedVideoChannel : _activeVideoChannels) {
for (const auto &segment : _availableSegments) { for (const auto &segment : _availableSegments) {
@ -809,6 +981,7 @@ public:
private: private:
std::shared_ptr<Threads> _threads; 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::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, 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; 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 _segmentDuration = 1000;
const int _segmentBufferDuration = 2000; const int _segmentBufferDuration = 2000;
int64_t _nextSegmentTimestamp = 0; int64_t _nextSegmentTimestamp = -1;
absl::optional<int> _waitForBufferredMillisecondsBeforeRendering; absl::optional<int> _waitForBufferredMillisecondsBeforeRendering;
std::vector<std::shared_ptr<MediaSegment>> _availableSegments; 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; std::vector<std::shared_ptr<PendingMediaSegment>> _pendingSegments;
int64_t _playbackReferenceTimestamp = 0; int64_t _playbackReferenceTimestamp = 0;
const size_t _audioDataRingBufferMaxSize = 4800; const int _audioRingBufferNumChannels = 2;
const size_t _audioDataRingBufferMaxSize = 4800 * 2;
webrtc::Mutex _audioDataMutex; webrtc::Mutex _audioDataMutex;
SampleRingBuffer _audioRingBuffer; SampleRingBuffer _audioRingBuffer;
std::vector<int16_t> _tempAudioBuffer; std::vector<int16_t> _tempAudioBuffer;
std::vector<int16_t> _stereoShuffleBuffer;
webrtc::FrameCombiner _audioFrameCombiner; webrtc::FrameCombiner _audioFrameCombiner;
std::map<uint32_t, std::unique_ptr<SparseVad>> _audioVadMap; 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, std::vector<std::weak_ptr<rtc::VideoSinkInterface<webrtc::VideoFrame>>>> _videoSinks;
std::map<std::string, int32_t> _currentEndpointMapping; std::map<std::string, int32_t> _currentEndpointMapping;
std::shared_ptr<PlatformContext> _platformContext; std::shared_ptr<PlatformContext> _platformContext;
}; };

View File

@ -24,6 +24,7 @@ public:
public: public:
struct StreamingMediaContextArguments { struct StreamingMediaContextArguments {
std::shared_ptr<Threads> threads; 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::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, 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; 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 "rtc_base/third_party/base64/base64.h"
#include "api/video/i420_buffer.h" #include "api/video/i420_buffer.h"
extern "C" { #include "AVIOContextImpl.h"
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
}
#include <string> #include <string>
#include <set> #include <set>
@ -18,63 +14,6 @@ namespace tgcalls {
namespace { 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 { class MediaDataPacket {
public: public:
MediaDataPacket() : _packet(av_packet_alloc()) { 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 eventCount = readInt32(data, offset)) {
if (const auto event = readVideoStreamEvent(data, offset)) { if (eventCount > 0) {
info.events.push_back(event.value()); if (const auto event = readVideoStreamEvent(data, offset)) {
info.events.push_back(event.value());
} else {
return absl::nullopt;
}
} else { } else {
return absl::nullopt; return absl::nullopt;
} }
@ -499,7 +442,7 @@ public:
_frameIndex++; _frameIndex++;
return convertedFrame; return convertedFrame;
} }
} else if (status == -35) { } else if (status == AVERROR(EAGAIN)) {
// more data needed // more data needed
} else { } else {
_didReadToEnd = true; _didReadToEnd = true;
@ -552,14 +495,29 @@ private:
class VideoStreamingPartState { class VideoStreamingPartState {
public: public:
VideoStreamingPartState(std::vector<uint8_t> &&data) { VideoStreamingPartState(std::vector<uint8_t> &&data, VideoStreamingPart::ContentType contentType) {
_videoStreamInfo = consumeVideoStreamInfo(data); _videoStreamInfo = consumeVideoStreamInfo(data);
if (!_videoStreamInfo) { if (!_videoStreamInfo) {
return; return;
} }
for (size_t i = 0; i < _videoStreamInfo->events.size(); i++) { 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; webrtc::VideoRotation rotation = webrtc::VideoRotation::kVideoRotation_0;
switch (_videoStreamInfo->events[i].rotation) { switch (_videoStreamInfo->events[i].rotation) {
case 0: { case 0: {
@ -582,8 +540,24 @@ public:
break; 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) { absl::optional<VideoStreamingPartFrame> getFrameAtRelativeTimestamp(double timestamp) {
while (true) { while (true) {
if (!_currentFrame) { if (!_currentFrame) {
if (!_parsedParts.empty()) { if (!_parsedVideoParts.empty()) {
auto result = _parsedParts[0]->getNextFrame(); auto result = _parsedVideoParts[0]->getNextFrame();
if (result) { if (result) {
_currentFrame = result; _currentFrame = result;
_relativeTimestamp += result->duration; _relativeTimestamp += result->duration;
} else { } else {
_parsedParts.erase(_parsedParts.begin()); _parsedVideoParts.erase(_parsedVideoParts.begin());
continue; continue;
} }
} }
@ -618,23 +592,49 @@ public:
} }
absl::optional<std::string> getActiveEndpointId() const { absl::optional<std::string> getActiveEndpointId() const {
if (!_parsedParts.empty()) { if (!_parsedVideoParts.empty()) {
return _parsedParts[0]->endpointId(); return _parsedVideoParts[0]->endpointId();
} else { } else {
return absl::nullopt; 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: private:
absl::optional<VideoStreamInfo> _videoStreamInfo; absl::optional<VideoStreamInfo> _videoStreamInfo;
std::vector<std::unique_ptr<VideoStreamingPartInternal>> _parsedParts; std::vector<std::unique_ptr<VideoStreamingPartInternal>> _parsedVideoParts;
absl::optional<VideoStreamingPartFrame> _currentFrame; absl::optional<VideoStreamingPartFrame> _currentFrame;
double _relativeTimestamp = 0.0; 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()) { 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; : 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 "api/video/video_frame.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "AudioStreamingPart.h"
#include "AudioStreamingPartInternal.h"
namespace tgcalls { namespace tgcalls {
class VideoStreamingPartState; class VideoStreamingPartState;
@ -30,7 +33,13 @@ struct VideoStreamingPartFrame {
class VideoStreamingPart { class VideoStreamingPart {
public: 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();
VideoStreamingPart(const VideoStreamingPart&) = delete; VideoStreamingPart(const VideoStreamingPart&) = delete;
@ -44,6 +53,9 @@ public:
absl::optional<VideoStreamingPartFrame> getFrameAtRelativeTimestamp(double timestamp); absl::optional<VideoStreamingPartFrame> getFrameAtRelativeTimestamp(double timestamp);
absl::optional<std::string> getActiveEndpointId() const; absl::optional<std::string> getActiveEndpointId() const;
int getAudioRemainingMilliseconds();
std::vector<AudioStreamingPart::StreamingPartChannel> getAudio10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder);
private: private:
VideoStreamingPartState *_state = nullptr; VideoStreamingPartState *_state = nullptr;
}; };

View File

@ -303,8 +303,8 @@ public:
virtual std::unique_ptr<rtc::NetworkMonitorFactory> createNetworkMonitorFactory() { virtual std::unique_ptr<rtc::NetworkMonitorFactory> createNetworkMonitorFactory() {
return nullptr; 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 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 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; 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); return new rtc::RefCountedObject<DefaultWrappedAudioDeviceModule>(module);
} }
public:
bool preferX264 = false;
}; };
std::unique_ptr<PlatformInterface> CreatePlatformInterface(); std::unique_ptr<PlatformInterface> CreatePlatformInterface();

View File

@ -17,7 +17,7 @@
#include "sdk/android/native_api/video/video_source.h" #include "sdk/android/native_api/video/video_source.h"
#include "api/video_codecs/builtin_video_encoder_factory.h" #include "api/video_codecs/builtin_video_encoder_factory.h"
#include "api/video_codecs/builtin_video_decoder_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" #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(); JNIEnv *env = webrtc::AttachCurrentThreadIfNeeded();
AndroidContext *context = (AndroidContext *) platformContext.get(); 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) { rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> AndroidInterface::makeVideoSource(rtc::Thread *signalingThread, rtc::Thread *workerThread, bool screencapture) {
JNIEnv *env = webrtc::AttachCurrentThreadIfNeeded(); JNIEnv *env = webrtc::AttachCurrentThreadIfNeeded();
_source[screencapture ? 1 : 0] = webrtc::CreateJavaVideoSource(env, signalingThread, false, false); _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) { bool AndroidInterface::supportsEncoding(const std::string &codecName, std::shared_ptr<PlatformContext> platformContext) {

View File

@ -10,7 +10,7 @@ namespace tgcalls {
class AndroidInterface : public PlatformInterface { class AndroidInterface : public PlatformInterface {
public: public:
void configurePlatformAudio() override; 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; std::unique_ptr<webrtc::VideoDecoderFactory> makeVideoDecoderFactory(std::shared_ptr<PlatformContext> platformContext) override;
bool supportsEncoding(const std::string &codecName, 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; 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_encoder_factory.h"
#include "api/video_codecs/builtin_video_decoder_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 { namespace tgcalls {
std::unique_ptr<webrtc::VideoEncoderFactory> FakeInterface::makeVideoEncoderFactory() { std::unique_ptr<webrtc::VideoEncoderFactory> FakeInterface::makeVideoEncoderFactory(bool preferHardwareEncoding, bool isScreencast) {
return webrtc::CreateBuiltinVideoEncoderFactory(); return webrtc::CreateBuiltinVideoEncoderFactory();
} }

View File

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