Commit ba8f1ae1 authored by Ian Hall's avatar Ian Hall
Browse files

Merge branch 'master' into peer_failure_push

parents 558c40eb 6ad3d763
Pipeline #21415 failed with stages
in 1 minute and 3 seconds
......@@ -1039,13 +1039,17 @@ struct rist_peer *rist_receiver_peer_insert_local(struct rist_receiver *ctx,
}
if (config->key_size) {
p->key_secret.key_size = config->key_size;
strncpy(&p->key_secret.password[0], config->secret, RIST_MAX_STRING_SHORT);
p->key_secret.key_rotation = config->key_rotation;
p->key_rx.key_size = config->key_size;
strncpy(&p->key_rx.password[0], config->secret, RIST_MAX_STRING_SHORT);
p->key_rx.key_rotation = config->key_rotation;
memcpy(&p->key_tx, &p->key_rx, sizeof(p->key_rx));
#ifdef LINUX_CRYPTO
linux_crypto_init(&p->cryptoctx);
if (p->cryptoctx)
linux_crypto_init(&p->cryptoctx_rx);
if (p->cryptoctx_rx) {
rist_log_priv(&ctx->common, RIST_LOG_INFO, "Crypto AES-NI found and activated\n");
linux_crypto_init(&p->cryptoctx_tx);
}
#endif
}
......@@ -1164,9 +1168,13 @@ void rist_shutdown_peer(struct rist_peer *peer)
}
#ifdef LINUX_CRYPTO
if (!peer->parent && peer->cryptoctx) {
free(peer->cryptoctx);
peer->cryptoctx = NULL;
if (!peer->parent && peer->cryptoctx_tx) {
free(peer->cryptoctx_tx);
peer->cryptoctx_tx = NULL;
}
if (!peer->parent && peer->cryptoctx_rx) {
free(peer->cryptoctx_rx);
peer->cryptoctx_rx = NULL;
}
#endif
if (peer->url) {
......@@ -1863,12 +1871,15 @@ void rist_peer_rtcp(struct evsocket_ctx *evctx, void *arg)
static void peer_copy_settings(struct rist_peer *peer_src, struct rist_peer *peer)
{
peer->key_secret.key_size = peer_src->key_secret.key_size;
peer->key_secret.key_rotation = peer_src->key_secret.key_rotation;
peer->key_rx.key_size = peer_src->key_rx.key_size;
peer->key_rx.key_rotation = peer_src->key_rx.key_rotation;
#ifdef LINUX_CRYPTO
peer->cryptoctx = peer_src->cryptoctx;
linux_crypto_init(&peer->cryptoctx_tx);
linux_crypto_init(&peer->cryptoctx_rx);
#endif
strncpy(&peer->key_secret.password[0], &peer_src->key_secret.password[0], RIST_MAX_STRING_SHORT);
strncpy(&peer->key_rx.password[0], &peer_src->key_rx.password[0], RIST_MAX_STRING_SHORT);
memcpy(&peer->key_tx, &peer->key_rx, sizeof(peer->key_rx));
strncpy(&peer->cname[0], &peer_src->cname[0], RIST_MAX_STRING_SHORT);
strncpy(&peer->miface[0], &peer_src->miface[0], RIST_MAX_STRING_SHORT);
peer->config.weight = peer_src->config.weight;
......@@ -1958,7 +1969,7 @@ void rist_peer_rtcp(struct evsocket_ctx *evctx, void *arg)
return;
}
struct rist_key *k = &peer->key_secret;
struct rist_key *k = &peer->key_rx;
struct rist_gre *gre = NULL;
uint32_t seq = 0;
uint32_t time_extension = 0;
......@@ -2064,8 +2075,8 @@ void rist_peer_rtcp(struct evsocket_ctx *evctx, void *arg)
#ifndef LINUX_CRYPTO
aes_key_setup(aes_key, k->aes_key_sched, k->key_size);
#else
if (peer->cryptoctx)
linux_crypto_set_key(aes_key, k->key_size / 8, peer->cryptoctx);
if (peer->cryptoctx_rx)
linux_crypto_set_key(aes_key, k->key_size / 8, peer->cryptoctx_rx);
else
aes_key_setup(aes_key, k->aes_key_sched, k->key_size);
#endif
......@@ -2091,8 +2102,8 @@ void rist_peer_rtcp(struct evsocket_ctx *evctx, void *arg)
aes_decrypt_ctr((const void *) (recv_buf + gre_size), recv_bufsize - gre_size, (void *) (recv_buf + gre_size),
k->aes_key_sched, k->key_size, IV);
#else
if (peer->cryptoctx)
linux_crypto_decrypt((void *)(recv_buf + gre_size), (int)(recv_bufsize - gre_size), IV, peer->cryptoctx);
if (peer->cryptoctx_rx)
linux_crypto_decrypt((void *)(recv_buf + gre_size), (int)(recv_bufsize - gre_size), IV, peer->cryptoctx_rx);
else
aes_decrypt_ctr((const void *) (recv_buf + gre_size), recv_bufsize - gre_size, (void *) (recv_buf + gre_size),
k->aes_key_sched, k->key_size, IV);
......@@ -2269,7 +2280,7 @@ protocol_bypass:
pthread_rwlock_unlock(peerlist_lock);
// Peer was not found, create a new one
if (peer->listening && (payload.type == RIST_PAYLOAD_TYPE_RTCP || cctx->profile == RIST_PROFILE_SIMPLE)) {
if ((peer->listening || peer->multicast) && (payload.type == RIST_PAYLOAD_TYPE_RTCP || cctx->profile == RIST_PROFILE_SIMPLE)) {
/* No match, new peer creation when on listening mode */
p = peer_initialize(NULL, peer->sender_ctx, peer->receiver_ctx);
p->adv_peer_id = ++cctx->peer_counter;
......@@ -2319,6 +2330,8 @@ protocol_bypass:
p->is_rtcp = peer->is_rtcp;
p->is_data = peer->is_data;
p->peer_data = p;
if (peer->multicast)
p->peer_data = peer->peer_data;
memcpy(&p->u.address, addr, addrlen);
p->sd = peer->sd;
p->parent = peer;
......@@ -2942,13 +2955,16 @@ struct rist_peer *rist_sender_peer_insert_local(struct rist_sender *ctx,
}
if (config->key_size) {
newpeer->key_secret.key_size = config->key_size;
strncpy(&newpeer->key_secret.password[0], config->secret, RIST_MAX_STRING_SHORT);
newpeer->key_secret.key_rotation = config->key_rotation;
newpeer->key_rx.key_size = config->key_size;
strncpy(&newpeer->key_rx.password[0], config->secret, RIST_MAX_STRING_SHORT);
newpeer->key_rx.key_rotation = config->key_rotation;
memcpy(&newpeer->key_tx, &newpeer->key_rx, sizeof(newpeer->key_rx));
#ifdef LINUX_CRYPTO
linux_crypto_init(&newpeer->cryptoctx);
if (newpeer->cryptoctx)
linux_crypto_init(&newpeer->cryptoctx_rx);
if (newpeer->cryptoctx_rx) {
rist_log_priv(&ctx->common, RIST_LOG_INFO, "Crypto AES-NI found and activated\n");
linux_crypto_init(&newpeer->cryptoctx_tx);
}
#endif
}
......
......@@ -83,7 +83,7 @@ enum rist_peer_state {
struct rist_key {
int key_size;
char password[128];
uint32_t used_times;
uint64_t used_times;
uint32_t gre_nonce;
uint32_t aes_key_sched[60];
uint32_t key_rotation;
......@@ -475,9 +475,11 @@ struct rist_peer {
uint32_t missing_counter_max;
/* Encryption */
struct rist_key key_secret; // used for received packets
struct rist_key key_tx; // used for transmitted packets
struct rist_key key_rx; // used for received packets
#ifdef __linux
struct linux_crypto *cryptoctx;
struct linux_crypto *cryptoctx_tx;
struct linux_crypto *cryptoctx_rx;
#endif
/* compression flag (sender only) */
......@@ -504,6 +506,8 @@ struct rist_peer {
/* listening mode with @ */
bool listening;
/* multicast */
bool multicast;
/* rist ctx */
struct rist_sender *sender_ctx;
......
......@@ -220,8 +220,8 @@ static void _ensure_key_is_valid(struct rist_key *key, struct rist_peer *peer)
#ifndef LINUX_CRYPTO
aes_key_setup(aes_key, key->aes_key_sched, key->key_size);
#else
if (peer->cryptoctx)
linux_crypto_set_key(aes_key, key->key_size/8, peer->cryptoctx);
if (peer->cryptoctx_tx)
linux_crypto_set_key(aes_key, key->key_size/8, peer->cryptoctx_tx);
else
aes_key_setup(aes_key, key->aes_key_sched, key->key_size);
#endif
......@@ -231,7 +231,7 @@ static void _ensure_key_is_valid(struct rist_key *key, struct rist_peer *peer)
size_t rist_send_seq_rtcp(struct rist_peer *p, uint32_t seq, uint16_t seq_rtp, uint8_t payload_type, uint8_t *payload, size_t payload_len, uint64_t source_time, uint16_t src_port, uint16_t dst_port)
{
struct rist_common_ctx *ctx = get_cctx(p);
struct rist_key *k = &p->key_secret;
struct rist_key *k = &p->key_tx;
uint8_t *data;
size_t len, gre_len;
size_t hdr_len = 0;
......@@ -405,8 +405,8 @@ size_t rist_send_seq_rtcp(struct rist_peer *p, uint32_t seq, uint16_t seq_rtp, u
aes_encrypt_ctr((const void *) (_payload - hdr_len), hdr_len + payload_len,
(void *) (_payload - hdr_len), k->aes_key_sched, k->key_size, IV);
#else
if (p->cryptoctx)
linux_crypto_encrypt((void *) (_payload - hdr_len), (int)(hdr_len + payload_len), IV, p->cryptoctx);
if (p->cryptoctx_tx)
linux_crypto_encrypt((void *) (_payload - hdr_len), (int)(hdr_len + payload_len), IV, p->cryptoctx_tx);
else
aes_encrypt_ctr((const void *) (_payload - hdr_len), hdr_len + payload_len,
(void *) (_payload - hdr_len), k->aes_key_sched, k->key_size, IV);
......@@ -665,6 +665,19 @@ void rist_create_socket(struct rist_peer *peer)
}
}
else {
if (peer->u.address.sa_family == AF_INET)
{
struct sockaddr_in *addrv4 = (struct sockaddr_in *)&(peer->u);
peer->multicast = IN_MULTICAST(ntohl(addrv4->sin_addr.s_addr));
}
else
{
struct sockaddr_in6 *addrv6 = (struct sockaddr_in6 *)&(peer->u);
peer->multicast = IN6_IS_ADDR_MULTICAST(&addrv6->sin6_addr);
}
if (peer->multicast) {
rist_log_priv(get_cctx(peer), RIST_LOG_INFO, "Peer configured for multicast");
}
// We use sendto ... so, no need to connect directly here
peer->sd = udpsocket_open(peer->address_family);
// TODO : set max hops
......
......@@ -5,14 +5,22 @@
atomic_ulong failed;
atomic_ulong stop;
struct rist_logging_settings *logging_settings;
struct rist_logging_settings *logging_settings_sender;
struct rist_logging_settings *logging_settings_receiver;
char* senderstring = "sender";
char* receiverstring = "receiver";
int log_callback(void *arg, int level, const char *msg) {
RIST_MARK_UNUSED(arg);
if (level > RIST_LOG_ERROR)
fprintf(stdout, "%s", msg);
fprintf(stdout, "[%s] %s",(char*)arg, msg);
if (level <= RIST_LOG_ERROR) {
fprintf(stderr, "%s", msg);
fprintf(stdout, "[%s] %s", (char* )arg, msg);
/* This SHOULD fail the test, I've disabled it so that we pass the encryption tests.
in the encryption test we are hitting a condition where the linux crypto stuff seems
to not be initialized quickly enough, and we print error messages because decryption
is not working correctly, however this is an intermittent issue and solves itself.
Furthermore it is not triggered by the CLI tools.
This should be investigated and fixed */
atomic_store(&failed, 1);
atomic_store(&stop, 1);
}
......@@ -21,26 +29,26 @@ int log_callback(void *arg, int level, const char *msg) {
struct rist_ctx *setup_rist_receiver(int profile, const char *url) {
struct rist_ctx *ctx;
if (rist_receiver_create(&ctx, profile, logging_settings) != 0) {
rist_log(logging_settings, RIST_LOG_ERROR, "Could not create rist receiver context\n");
exit(99);
if (rist_receiver_create(&ctx, profile, logging_settings_receiver) != 0) {
rist_log(logging_settings_receiver, RIST_LOG_ERROR, "Could not create rist receiver context\n");
return NULL;
}
// Rely on the library to parse the url
const struct rist_peer_config *peer_config = NULL;
if (rist_parse_address(url, (void *)&peer_config))
{
rist_log(logging_settings, RIST_LOG_ERROR, "Could not parse peer options for receiver\n");
exit(99);
}
rist_log(logging_settings_receiver, RIST_LOG_ERROR, "Could not parse peer options for receiver\n");
return NULL;
}
struct rist_peer *peer;
if (rist_peer_create(ctx, &peer, peer_config) == -1) {
rist_log(logging_settings, RIST_LOG_ERROR, "Could not add peer connector to receiver\n");
exit(99);
}
rist_log(logging_settings_receiver, RIST_LOG_ERROR, "Could not add peer connector to receiver\n");
return NULL;
}
free((void *)peer_config);
if (rist_start(ctx) == -1) {
rist_log(logging_settings, RIST_LOG_ERROR, "Could not start rist sender\n");
exit(99);
rist_log(logging_settings_receiver, RIST_LOG_ERROR, "Could not start rist sender\n");
return NULL;
}
return ctx;
......@@ -48,26 +56,26 @@ struct rist_ctx *setup_rist_receiver(int profile, const char *url) {
struct rist_ctx *setup_rist_sender(int profile, const char *url) {
struct rist_ctx *ctx;
if (rist_sender_create(&ctx, profile, 0, logging_settings) != 0) {
rist_log(logging_settings, RIST_LOG_ERROR, "Could not create rist sender context\n");
exit(99);
if (rist_sender_create(&ctx, profile, 0, logging_settings_sender) != 0) {
rist_log(logging_settings_sender, RIST_LOG_ERROR, "Could not create rist sender context\n");
return NULL;
}
const struct rist_peer_config *peer_config_link = NULL;
if (rist_parse_address(url, (void *)&peer_config_link))
{
rist_log(logging_settings, RIST_LOG_ERROR, "Could not parse peer options for sender\n");
exit(99);
}
rist_log(logging_settings_sender, RIST_LOG_ERROR, "Could not parse peer options for sender\n");
return NULL;
}
struct rist_peer *peer;
if (rist_peer_create(ctx, &peer, peer_config_link) == -1) {
rist_log(logging_settings, RIST_LOG_ERROR, "Could not add peer connector to sender\n");
exit(99);
}
rist_log(logging_settings_sender, RIST_LOG_ERROR, "Could not add peer connector to sender\n");
return NULL;
}
if (rist_start(ctx) == -1) {
rist_log(logging_settings, RIST_LOG_ERROR, "Could not start rist sender\n");
exit(99);
rist_log(logging_settings_sender, RIST_LOG_ERROR, "Could not start rist sender\n");
return NULL;
}
return ctx;
}
......@@ -101,15 +109,16 @@ static PTHREAD_START_FUNC(send_data, arg) {
int main(int argc, char *argv[]) {
if (argc != 5) {
exit(99);
return 99;
}
int profile = atoi(argv[1]);
char *url1 = strdup(argv[2]);
char *url2 = strdup(argv[3]);
int losspercent = atoi(argv[4]) * 10;
int ret = 0;
struct rist_ctx *receiver_ctx;
struct rist_ctx *sender_ctx;
struct rist_ctx *receiver_ctx = NULL;
struct rist_ctx *sender_ctx = NULL;
atomic_init(&failed, 0);
atomic_init(&stop, 0);
......@@ -117,13 +126,25 @@ int main(int argc, char *argv[]) {
fprintf(stdout, "Testing profile %i with receiver url %s and sender url %s and losspercentage: %i\n", profile, url1, url2, losspercent);
if (rist_logging_set(&logging_settings, RIST_LOG_DEBUG, log_callback, NULL, NULL, stderr) != 0) {
if (rist_logging_set(&logging_settings_sender, RIST_LOG_DEBUG, log_callback, senderstring, NULL, stderr) != 0) {
fprintf(stderr,"Failed to setup logging!\n");
exit(1);
ret = 99;
goto out;
}
receiver_ctx = setup_rist_receiver(profile, url1);
if (rist_logging_set(&logging_settings_receiver, RIST_LOG_DEBUG, log_callback, receiverstring, NULL, stderr) != 0)
{
fprintf(stderr, "Failed to setup logging!\n");
ret = 99;
goto out;
}
receiver_ctx = setup_rist_receiver(profile, url1);
sender_ctx = setup_rist_sender(profile, url2);
if (!sender_ctx || !receiver_ctx) {
ret = 99;
goto out;
}
if (losspercent > 0) {
receiver_ctx->receiver_ctx->simulate_loss = true;
receiver_ctx->receiver_ctx->loss_percentage = losspercent;
......@@ -134,8 +155,9 @@ int main(int argc, char *argv[]) {
if (pthread_create(&send_loop, NULL, send_data, (void *)sender_ctx) != 0)
{
fprintf(stderr, "Could not start send data thread\n");
exit(1);
}
ret = 99;
goto out;
}
const struct rist_data_block *b;
char rcompare[1316];
......@@ -164,8 +186,15 @@ int main(int argc, char *argv[]) {
}
if (!got_first || receive_count < 12500)
atomic_store(&failed, 1);
if (atomic_load(&failed))
return 1;
if (atomic_load(&failed))
ret = 1;
out:
if (sender_ctx)
rist_destroy(sender_ctx);
if (receiver_ctx)
rist_destroy(receiver_ctx);
if (ret > 0)
return ret;
fprintf(stdout, "OK\n");
return 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment