]> git.proxmox.com Git - mirror_kronosnet.git/commitdiff
link: Check address families on a link always match
authorChristine Caulfield <ccaulfie@redhat.com>
Tue, 26 Mar 2019 12:44:25 +0000 (13:44 +0100)
committerFabio M. Di Nitto <fdinitto@redhat.com>
Tue, 26 Mar 2019 12:44:25 +0000 (13:44 +0100)
We can't create a link with a source address of a different
address family than the destination as all sends will fail.

libknet/links.c
libknet/tests/api_knet_link_set_config.c

index c32ae4176d8d242bfc5959e4aecbed015860c8a3..71f74ae8ad1f38b186dddb7348c7479416e11a90 100644 (file)
@@ -119,6 +119,12 @@ int knet_link_set_config(knet_handle_t knet_h, knet_node_id_t host_id, uint8_t l
                return -1;
        }
 
+       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");
+               errno = EINVAL;
+               return -1;
+       }
+
        if (transport >= KNET_MAX_TRANSPORTS) {
                errno = EINVAL;
                return -1;
index 21fbf5d7afaec9b3b7e801fca5691383481a7abc..71482fa228639a49bd860b4e7166b95691f44b72 100644 (file)
@@ -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) {
@@ -227,6 +245,11 @@ static void test(void)
 
        printf("Test knet_link_set_config with static dst_addr\n");
 
+       if (make_local_sockaddr(&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("Unable to configure link: %s\n", strerror(errno));
                knet_host_remove(knet_h, 1);