Skip to content

Commit

Permalink
link: Check address families on a link always match
Browse files Browse the repository at this point in the history
We can't create a link with a source address of a different
address family than the destination as all sends will fail.
  • Loading branch information
chrissie-c committed Mar 26, 2019
1 parent 4818cfa commit 45d5225
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libknet/links.c
Expand Up @@ -146,6 +146,13 @@ int knet_link_set_config(knet_handle_t knet_h, knet_node_id_t host_id, uint8_t l
goto exit_unlock;
}

if (dst_addr && (src_addr->ss_family != dst_addr->ss_family)) {
log_err(knet_h, KNET_SUB_LINK, "Source address family does not match destination address family");
err = -1;
savederrno = EINVAL;
goto exit_unlock;
}

host = knet_h->host_index[host_id];
if (!host) {
err = -1;
Expand Down
18 changes: 18 additions & 0 deletions libknet/tests/api_knet_link_set_config.c
Expand Up @@ -113,6 +113,24 @@ static void test(void)

flush_logs(logfds[0], stdout);

printf("Test knet_link_set_config with conflicting address families\n");

if (make_local_sockaddr6(&dst, 1) < 0) {
printf("Unable to convert dst to sockaddr: %s\n", strerror(errno));
exit(FAIL);
}

if (knet_link_set_config(knet_h, 1, 0, KNET_TRANSPORT_UDP, &src, &dst, 0) == 0) {
printf("knet_link_set_config accepted invalid address families: %s\n", strerror(errno));
knet_host_remove(knet_h, 1);
knet_handle_free(knet_h);
flush_logs(logfds[0], stdout);
close_logpipes(logfds);
exit(FAIL);
}

flush_logs(logfds[0], stdout);

printf("Test knet_link_set_config with dynamic dst_addr\n");

if (knet_link_set_config(knet_h, 1, 0, KNET_TRANSPORT_UDP, &src, NULL, 0) < 0) {
Expand Down

0 comments on commit 45d5225

Please sign in to comment.