diff options
Diffstat (limited to 'hicn-light/src/hicn/socket')
-rw-r--r-- | hicn-light/src/hicn/socket/CMakeLists.txt | 8 | ||||
-rw-r--r-- | hicn-light/src/hicn/socket/api.c | 81 | ||||
-rw-r--r-- | hicn-light/src/hicn/socket/api.h | 9 | ||||
-rw-r--r-- | hicn-light/src/hicn/socket/ops.h | 18 | ||||
-rw-r--r-- | hicn-light/src/hicn/socket/ops_linux.c | 131 |
5 files changed, 129 insertions, 118 deletions
diff --git a/hicn-light/src/hicn/socket/CMakeLists.txt b/hicn-light/src/hicn/socket/CMakeLists.txt index 8c8a757fb..41dbd2342 100644 --- a/hicn-light/src/hicn/socket/CMakeLists.txt +++ b/hicn-light/src/hicn/socket/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2019 Cisco and/or its affiliates. +# Copyright (c) 2021-2022 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -25,11 +25,5 @@ if (UNIX AND NOT APPLE) ) endif() -set(TO_INSTALL_HEADER_FILES - ${TO_INSTALL_HEADER_FILES} - ${HEADER_FILES} - PARENT_SCOPE -) - set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE) set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) diff --git a/hicn-light/src/hicn/socket/api.c b/hicn-light/src/hicn/socket/api.c index 34c0aae54..db377aecd 100644 --- a/hicn-light/src/hicn/socket/api.c +++ b/hicn-light/src/hicn/socket/api.c @@ -10,8 +10,12 @@ #include <unistd.h> // close #include "api.h" -#include "error.h" #include "ops.h" +#include <hicn/util/sstrncpy.h> + +#if __linux__ +#include "error.h" +#endif #define INET_MAX_ADDRSTRLEN INET6_ADDRSTRLEN @@ -39,7 +43,7 @@ static hicn_conf_t hicn_default_conf = { struct ip_rule_state_ { char tun_name[IF_NAMESIZE]; - ip_prefix_t prefix; + hicn_ip_prefix_t prefix; uint32_t table_id; uint8_t priority; uint8_t address_family; @@ -72,8 +76,7 @@ hicn_socket_helper_t *hicn_create() { } hicn->conf = malloc(sizeof(hicn_conf_t)); - if (hicn->conf < 0) - goto ERR_CONF; + if (hicn->conf < 0) goto ERR_CONF; memcpy(hicn->conf, &hicn_default_conf, sizeof(hicn_conf_t)); /* Initialize socket tree to empty */ @@ -133,20 +136,16 @@ void hicn_destroy() { /* Restore default rules */ printf("Restoring default configuration.\n"); rc = ops.del_lo_prio_rule(NULL, AF_INET6, LOCAL_PRIORITY); - if (rc < 0) - ret = -1; + if (rc < 0) ret = -1; rc = ops.del_lo_prio_rule(NULL, AF_INET, LOCAL_PRIORITY); - if (rc < 0) - ret = -1; + if (rc < 0) ret = -1; rc = ops.add_lo_prio_rule(NULL, AF_INET6, 0); - if (rc < 0) - ret = -1; + if (rc < 0) ret = -1; rc = ops.add_lo_prio_rule(NULL, AF_INET, 0); - if (rc < 0) - ret = -1; + if (rc < 0) ret = -1; for (i = 0; i < rules_counter; i++) { if (strcmp(rules_to_remove[i].tun_name, "NONE") != 0) { @@ -158,20 +157,17 @@ void hicn_destroy() { &rules_to_remove[i].prefix, rules_to_remove[i].address_family, rules_to_remove[i].priority, rules_to_remove[i].table_id); } - if (rc < 0) - ret = -1; + if (rc < 0) ret = -1; } for (i = 0; i < routes_counter; i++) { rc = ops.del_out_route(routes_to_remove[i].remote_ip_address, routes_to_remove[i].address_family, routes_to_remove[i].table_id); - if (rc < 0) - ret = -1; + if (rc < 0) ret = -1; } - if (ret < 0) - printf("Unexpected exit. Some state may not be deleted.\n"); + if (ret < 0) printf("Unexpected exit. Some state may not be deleted.\n"); } void hicn_free(hicn_socket_helper_t *hicn) { @@ -197,7 +193,7 @@ int hicn_socket_cmp(hicn_socket_t *a, hicn_socket_t *b) { return b->fd - a->fd; } -ip_prefix_t *hicn_socket_get_src_ip(hicn_socket_t *socket) { +hicn_ip_prefix_t *hicn_socket_get_src_ip(hicn_socket_t *socket) { if (socket->type != HS_CONNECTION) { return NULL; } @@ -245,7 +241,8 @@ int hicn_set_local_endpoint(hicn_socket_t *socket, const char *local_ip_address, */ /* Copy the local IP address inside the connection */ - rc = ip_prefix_pton(local_ip_address, &socket->connection.tun_ip_address); + rc = + hicn_ip_prefix_pton(local_ip_address, &socket->connection.tun_ip_address); if (rc < 0) { rc = HICN_SOCKET_ERROR_SOCKET_LOCAL_REPR; goto end; @@ -255,14 +252,14 @@ end: return rc; } -int hicn_get_local_address(const ip_prefix_t *remote_address, - ip_prefix_t *local_address) { +int hicn_get_local_address(const hicn_ip_prefix_t *remote_address, + hicn_ip_prefix_t *local_address) { int rc = 0; uint32_t interface_id; - char remote_address_str[INET_MAX_ADDRSTRLEN + 4 ]; + char remote_address_str[INET_MAX_ADDRSTRLEN + 4]; - rc = ip_prefix_ntop_short(remote_address, remote_address_str, - sizeof(remote_address_str)); + rc = hicn_ip_prefix_ntop_short(remote_address, remote_address_str, + sizeof(remote_address_str)); if (rc < 0) { rc = HICN_SOCKET_ERROR_BIND_REMOTE_REPR; goto ERR; @@ -293,7 +290,7 @@ ERR: int hicn_set_remote_endpoint(hicn_socket_t *socket, const char *remote_ip_address) { int af, rc = HICN_SOCKET_ERROR_NONE; - ip_prefix_t addr; + hicn_ip_prefix_t addr; af = get_addr_family(remote_ip_address); if ((af != AF_INET6) && (af != AF_INET)) { @@ -301,7 +298,7 @@ int hicn_set_remote_endpoint(hicn_socket_t *socket, } /* Bind local endpoint if not done yet */ - if (ip_prefix_empty(&socket->connection.tun_ip_address)) { + if (hicn_ip_prefix_empty(&socket->connection.tun_ip_address)) { char local_ip_address[INET_MAX_ADDRSTRLEN + 4]; /* Local interface id */ @@ -331,7 +328,8 @@ int hicn_set_remote_endpoint(hicn_socket_t *socket, ///// /* Convert to representation format */ - rc = ip_prefix_ntop_short(&addr, local_ip_address, sizeof(local_ip_address)); + rc = hicn_ip_prefix_ntop_short(&addr, local_ip_address, + sizeof(local_ip_address)); if (rc < 0) { rc = HICN_SOCKET_ERROR_BIND_REMOTE_REPR; goto ERR; @@ -448,8 +446,8 @@ int hicn_listen(hicn_socket_helper_t *hicn, int fd, const char *prefix) { return rc; } - ip_prefix_t ip_prefix; - rc = ip_prefix_pton(prefix, &ip_prefix); + hicn_ip_prefix_t hicn_ip_prefix; + rc = hicn_ip_prefix_pton(prefix, &hicn_ip_prefix); if (rc < 0) { return rc; } @@ -460,16 +458,18 @@ int hicn_listen(hicn_socket_helper_t *hicn, int fd, const char *prefix) { if (punting_table_id == -1) punting_table_id = socket->connection.table_id; - rc = ops.add_prio_rule(&ip_prefix, ip_prefix.family, 0, + rc = ops.add_prio_rule(&hicn_ip_prefix, hicn_ip_prefix.family, 0, socket->connection.table_id); if (rc < 0) { return rc; } - strcpy(rules_to_remove[rules_counter].tun_name, "NONE"); + rc = strcpy_s(rules_to_remove[rules_counter].tun_name, + sizeof(rules_to_remove[rules_counter].tun_name), "NONE"); + if (rc != EOK) return -1; - rules_to_remove[rules_counter].prefix = ip_prefix; - rules_to_remove[rules_counter].address_family = ip_prefix.family; + rules_to_remove[rules_counter].prefix = hicn_ip_prefix; + rules_to_remove[rules_counter].address_family = hicn_ip_prefix.family; rules_to_remove[rules_counter].table_id = socket->connection.table_id; rules_to_remove[rules_counter].priority = 0; ++rules_counter; @@ -533,7 +533,10 @@ int hicn_bind(hicn_socket_helper_t *hicn, int fd, goto ERR; } - strcpy(rules_to_remove[rules_counter].tun_name, socket->tun_name); + rc = strcpy_s(rules_to_remove[rules_counter].tun_name, + sizeof(rules_to_remove[rules_counter].tun_name), + socket->tun_name); + if (rc != EOK) return -1; rules_to_remove[rules_counter].address_family = addr_family; rules_to_remove[rules_counter].table_id = socket->connection.table_id; ++rules_counter; @@ -563,7 +566,13 @@ int hicn_bind(hicn_socket_helper_t *hicn, int fd, goto ERR; } - strcpy(routes_to_remove[routes_counter].remote_ip_address, remote_ip_address); + rc = strcpy_s(routes_to_remove[routes_counter].remote_ip_address, + sizeof(rules_to_remove[rules_counter].tun_name), + remote_ip_address); + if (rc != EOK) { + rc = HICN_SOCKET_ERROR_UNSPEC; + goto ERR; + } routes_to_remove[routes_counter].table_id = socket->connection.table_id; routes_to_remove[routes_counter].address_family = (uint8_t)addr_family; ++routes_counter; diff --git a/hicn-light/src/hicn/socket/api.h b/hicn-light/src/hicn/socket/api.h index 1a7f5c700..3caf9ef1e 100644 --- a/hicn-light/src/hicn/socket/api.h +++ b/hicn-light/src/hicn/socket/api.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ #include <stdlib.h> #include <hicn/hicn.h> -#include "error.h" #define BUFSIZE 4096 #define MAX_CONNECTIONS \ @@ -84,7 +83,7 @@ typedef struct hicn_socket_s { union { struct { - ip_prefix_t tun_ip_address; + hicn_ip_prefix_t tun_ip_address; uint32_t interface_id; /* ID of the corresponding table : avoid default values of 0, 32766 and @@ -163,8 +162,8 @@ void hicn_free(hicn_socket_helper_t *hicn); * * @return 0 in case of success, -1 otherwise. */ -int hicn_get_local_address(const ip_prefix_t *remote_address, - ip_prefix_t *local_address); +int hicn_get_local_address(const hicn_ip_prefix_t *remote_address, + hicn_ip_prefix_t *local_address); /* hICN socket */ diff --git a/hicn-light/src/hicn/socket/ops.h b/hicn-light/src/hicn/socket/ops.h index 1bee7c6f6..854b0c461 100644 --- a/hicn-light/src/hicn/socket/ops.h +++ b/hicn-light/src/hicn/socket/ops.h @@ -17,10 +17,10 @@ typedef struct { int (*get_output_ifid)(const char *ip_address, uint8_t address_family, uint32_t *interface_id); int (*get_ip_addr)(uint32_t interface_id, uint8_t address_family, - ip_prefix_t *ip_address); - int (*set_ip_addr)(uint32_t interface_id, ip_prefix_t *ip_address); + hicn_ip_prefix_t *ip_address); + int (*set_ip_addr)(uint32_t interface_id, hicn_ip_prefix_t *ip_address); int (*up_if)(uint32_t interface_id); - int (*add_in_route_table)(const ip_prefix_t *prefix, + int (*add_in_route_table)(const hicn_ip_prefix_t *prefix, const uint32_t interface_id, const uint8_t table_id); int (*add_in_route_table_s)(const char *prefix, const uint32_t interface_id, @@ -30,23 +30,23 @@ typedef struct { const uint8_t table_id, int default_route); int (*del_out_route)(const char *gateway, const uint8_t address_family, const uint8_t table_id); - int (*del_lo_route)(const ip_prefix_t *ip_address); + int (*del_lo_route)(const hicn_ip_prefix_t *ip_address); int (*add_rule)(const char *interface_name, const uint8_t address_family, const uint8_t table_id); int (*del_rule)(const char *interface_name, const uint8_t address_family, const uint8_t table_id); - int (*add_neigh_proxy)(const ip_prefix_t *ip_address, + int (*add_neigh_proxy)(const hicn_ip_prefix_t *ip_address, const uint32_t interface_id); - int (*add_prio_rule)(const ip_prefix_t *ip_address, + int (*add_prio_rule)(const hicn_ip_prefix_t *ip_address, const uint8_t address_family, const uint32_t priority, const uint8_t table_id); - int (*add_lo_prio_rule)(const ip_prefix_t *ip_address, + int (*add_lo_prio_rule)(const hicn_ip_prefix_t *ip_address, const uint8_t address_family, const uint32_t priority); - int (*del_prio_rule)(const ip_prefix_t *ip_address, + int (*del_prio_rule)(const hicn_ip_prefix_t *ip_address, const uint8_t address_family, const uint32_t priority, const uint8_t table_id); - int (*del_lo_prio_rule)(const ip_prefix_t *ip_address, + int (*del_lo_prio_rule)(const hicn_ip_prefix_t *ip_address, const uint8_t address_family, const uint32_t priority); } hicn_socket_ops_t; diff --git a/hicn-light/src/hicn/socket/ops_linux.c b/hicn-light/src/hicn/socket/ops_linux.c index 8bfc438f3..a3675e929 100644 --- a/hicn-light/src/hicn/socket/ops_linux.c +++ b/hicn-light/src/hicn/socket/ops_linux.c @@ -24,6 +24,8 @@ #include <stdint.h> #include <stdlib.h> +#include <hicn/ctrl/api.h> +#include <hicn/util/sstrncpy.h> /* Public interface */ @@ -60,13 +62,13 @@ int _nl_get_output_ifid(const char *ip_address, uint8_t address_family, * @see getifaddrs */ int _nl_get_ip_addr(uint32_t interface_id, uint8_t address_family, - ip_prefix_t *ip_address); + hicn_ip_prefix_t *ip_address); -int _nl_set_ip_addr(uint32_t interface_id, ip_prefix_t *ip_address); +int _nl_set_ip_addr(uint32_t interface_id, hicn_ip_prefix_t *ip_address); int _nl_up_if(uint32_t interface_id); -int _nl_add_in_route_table(const ip_prefix_t *prefix, +int _nl_add_in_route_table(const hicn_ip_prefix_t *prefix, const uint32_t interface_id, const uint8_t table_id); int _nl_add_in_route_table_s(const char *prefix, const uint32_t interface_id, const uint8_t table_id); @@ -77,25 +79,25 @@ int _nl_add_out_route(const char *gateway, const uint8_t address_family, int _nl_del_out_route(const char *gateway, const uint8_t address_family, const uint8_t table_id); -int _nl_del_lo_route(const ip_prefix_t *ip_address); +int _nl_del_lo_route(const hicn_ip_prefix_t *ip_address); int _nl_add_rule(const char *interface_name, const uint8_t address_family, const uint8_t table_id); int _nl_del_rule(const char *interface_name, const uint8_t address_family, const uint8_t table_id); -int _nl_add_neigh_proxy(const ip_prefix_t *ip_address, +int _nl_add_neigh_proxy(const hicn_ip_prefix_t *ip_address, const uint32_t interface_id); -int _nl_add_prio_rule(const ip_prefix_t *ip_address, +int _nl_add_prio_rule(const hicn_ip_prefix_t *ip_address, const uint8_t address_family, const uint32_t priority, const uint8_t table_id); -int _nl_add_lo_prio_rule(const ip_prefix_t *ip_address, +int _nl_add_lo_prio_rule(const hicn_ip_prefix_t *ip_address, const uint8_t address_family, const uint32_t priority); -int _nl_del_prio_rule(const ip_prefix_t *ip_address, +int _nl_del_prio_rule(const hicn_ip_prefix_t *ip_address, const uint8_t address_family, const uint32_t priority, const uint8_t table_id); -int _nl_del_lo_prio_rule(const ip_prefix_t *ip_address, +int _nl_del_lo_prio_rule(const hicn_ip_prefix_t *ip_address, const uint8_t address_family, const uint32_t priority); #endif /* HICN_NETLINK_H */ @@ -338,7 +340,8 @@ uint32_t _nl_get_ifid(const char *interface_name) { struct nlmsghdr *hdr = (struct nlmsghdr *)buffer; size_t n; int fd; - size_t len = interface_name ? strlen(interface_name) + 1 : 0; + size_t len = + interface_name ? strnlen_s(interface_name, INTERFACE_LEN) + 1 : 0; uint8_t padding[RTA_ALIGNTO] = {0, 0, 0, 0}; if (len == 0) { @@ -353,8 +356,8 @@ uint32_t _nl_get_ifid(const char *interface_name) { .hdr.nlmsg_flags = FLAGS_GET, .payload.ifi_family = AF_UNSPEC, .payload.ifi_index = 0}; - struct rtattr a_ifname = {RTA_LENGTH(strlen(interface_name) + 1), - IFLA_IFNAME}; + struct rtattr a_ifname = { + RTA_LENGTH(strnlen_s(interface_name, INTERFACE_LEN) + 1), IFLA_IFNAME}; struct iovec iov[] = {{&msg, sizeof(msg)}, {&a_ifname, sizeof(a_ifname)}, @@ -530,7 +533,7 @@ ERR: } int _nl_get_ip_addr(uint32_t interface_id, uint8_t address_family, - ip_prefix_t *prefix) { + hicn_ip_prefix_t *prefix) { char buffer[BUFSIZE]; struct nlmsghdr *hdr = (struct nlmsghdr *)buffer; size_t n; @@ -599,7 +602,7 @@ ERR_SOCKET: return HICN_SOCKET_ERROR_UNSPEC; } -int _nl_set_ip_addr(uint32_t interface_id, ip_prefix_t *prefix) { +int _nl_set_ip_addr(uint32_t interface_id, hicn_ip_prefix_t *prefix) { char buffer[BUFSIZE]; struct nlmsghdr *hdr = (struct nlmsghdr *)buffer; size_t n; @@ -619,15 +622,15 @@ int _nl_set_ip_addr(uint32_t interface_id, ip_prefix_t *prefix) { .payload.ifa_index = interface_id}; /* Set attributes = length/type/value */ - struct rtattr ifa_address = {RTA_LENGTH(ip_address_len(prefix->family)), + struct rtattr ifa_address = {RTA_LENGTH(hicn_ip_address_len(prefix->family)), IFA_ADDRESS}; - const void * address = ip_address_get_buffer(&prefix->address, prefix->family); - if (!address) - goto ERR_ADDRESS; + const void *address = + hicn_ip_address_get_buffer(&prefix->address, prefix->family); + if (!address) goto ERR_ADDRESS; const struct iovec iov[] = { {&msg, sizeof(msg)}, {&ifa_address, sizeof(ifa_address)}, - {(void*)address, ip_address_len(prefix->family)}, + {(void *)address, hicn_ip_address_len(prefix->family)}, }; msg.hdr.nlmsg_len = iov_length(iov, ARRAY_SIZE(iov)); @@ -965,7 +968,7 @@ ERR_SOCKET: * ip route del 1:2::2 dev lo table local * */ -int _nl_del_lo_route(const ip_prefix_t *prefix) { +int _nl_del_lo_route(const hicn_ip_prefix_t *prefix) { char buffer[BUFSIZE]; struct nlmsghdr *hdr = (struct nlmsghdr *)buffer; size_t n; @@ -991,16 +994,17 @@ int _nl_del_lo_route(const ip_prefix_t *prefix) { /* Set attribute = length/type/value */ uint32_t one = 1; - struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), RTA_DST}; + struct rtattr a_dst = {RTA_LENGTH(hicn_ip_address_len(prefix->family)), + RTA_DST}; struct rtattr a_ifid_lo = {RTA_LENGTH(sizeof(uint32_t)), RTA_OIF}; - const void * address = ip_address_get_buffer(&prefix->address, prefix->family); - if (!address) - goto ERR; + const void *address = + hicn_ip_address_get_buffer(&prefix->address, prefix->family); + if (!address) goto ERR; const struct iovec iov[] = { {&msg, sizeof(msg)}, /* Ip address */ {&a_dst, sizeof(a_dst)}, - {(void*)address, ip_address_len(prefix->family)}, + {(void *)address, hicn_ip_address_len(prefix->family)}, /* Interface id */ {&a_ifid_lo, sizeof(a_ifid_lo)}, {&one, sizeof(one)}}; @@ -1048,7 +1052,7 @@ int _nl_add_rule(const char *interface_name, uint8_t address_family, _nl_payload_rule(table_id, address_family, (uint8_t *)buffer, BUFSIZE); addAttr(hdr, BUFSIZE, FRA_IIFNAME, (void *)interface_name, - strlen(interface_name)); + strnlen_s(interface_name, INTERFACE_LEN)); fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); if (fd < 0) { @@ -1094,7 +1098,7 @@ int _nl_del_rule(const char *interface_name, uint8_t address_family, _nl_payload_rule(table_id, address_family, (uint8_t *)buffer, BUFSIZE); addAttr(hdr, BUFSIZE, FRA_IIFNAME, (void *)interface_name, - strlen(interface_name)); + strnlen_s(interface_name, INTERFACE_LEN)); fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); if (fd < 0) { @@ -1131,7 +1135,7 @@ ERR_SOCKET: * ip -6 neigh add proxy 1:2::2 dev hicnc-cons-eth0 2>&1 | grep nei * */ -int _nl_add_neigh_proxy(const ip_prefix_t *prefix, +int _nl_add_neigh_proxy(const hicn_ip_prefix_t *prefix, const uint32_t interface_id) { /* Buffer for holding the response, with appropriate casting on the header */ char buffer[BUFSIZE]; @@ -1156,18 +1160,19 @@ int _nl_add_neigh_proxy(const ip_prefix_t *prefix, }; /* Message attributes = length/type/value */ - struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), NDA_DST}; + struct rtattr a_dst = {RTA_LENGTH(hicn_ip_address_len(prefix->family)), + NDA_DST}; - const void * address = ip_address_get_buffer(&prefix->address, prefix->family); - if (!address) - goto ERR; + const void *address = + hicn_ip_address_get_buffer(&prefix->address, prefix->family); + if (!address) goto ERR; /* Iovec describing the packets */ const struct iovec iov[] = { {&msg, sizeof(msg)}, /* Ip address */ {&a_dst, sizeof(a_dst)}, - {(void*)address, ip_address_len(prefix->family)}, + {(void *)address, hicn_ip_address_len(prefix->family)}, }; msg.hdr.nlmsg_len = iov_length(iov, ARRAY_SIZE(iov)); @@ -1205,7 +1210,7 @@ ERR: /* ip -6 route add 0:1::/64 dev hicn-if0 table 100 */ /* ip -6 route add 0:2::/64 dev hicn-if1 table 100 */ -int _nl_add_in_route_table(const ip_prefix_t *prefix, +int _nl_add_in_route_table(const hicn_ip_prefix_t *prefix, const uint32_t interface_id, const uint8_t table_id) { /* Buffer for holding the response, with appropriate casting on the header */ @@ -1237,19 +1242,20 @@ int _nl_add_in_route_table(const ip_prefix_t *prefix, }; /* Message attributes = length/type/value */ - struct rtattr a_dst = {RTA_LENGTH(ip_address_len(prefix->family)), RTA_DST}; + struct rtattr a_dst = {RTA_LENGTH(hicn_ip_address_len(prefix->family)), + RTA_DST}; struct rtattr a_oif = {RTA_LENGTH(sizeof(uint32_t)), RTA_OIF}; - const void * address = ip_address_get_buffer(&prefix->address, prefix->family); - if (!address) - goto ERR; + const void *address = + hicn_ip_address_get_buffer(&prefix->address, prefix->family); + if (!address) goto ERR; /* Iovec describing the packets */ const struct iovec iov[] = { {&msg, sizeof(msg)}, /* Destination prefix / ip address */ {&a_dst, sizeof(a_dst)}, - {(void*)address, ip_address_len(prefix->family)}, + {(void *)address, hicn_ip_address_len(prefix->family)}, /* Output interface */ {&a_oif, sizeof(a_oif)}, {(void *)&interface_id, sizeof(uint32_t)}, @@ -1293,9 +1299,9 @@ ERR: int _nl_add_in_route_table_s(const char *prefix, const uint32_t interface_id, const uint8_t table_id) { int rc; - ip_prefix_t ip_address; + hicn_ip_prefix_t ip_address; - rc = ip_prefix_pton(prefix, &ip_address); + rc = hicn_ip_prefix_pton(prefix, &ip_address); if (rc < 0) { return rc; } @@ -1308,7 +1314,7 @@ int _nl_add_in_route_s(const char *prefix, const uint32_t interface_id) { } /* ip -6 rule add from b001::/16 prio 0 table 100 */ -int _nl_add_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, +int _nl_add_prio_rule(const hicn_ip_prefix_t *prefix, uint8_t address_family, const uint32_t priority, const uint8_t table_id) { /* Buffer for holding the response, with appropriate casting on the header */ char buffer[BUFSIZE]; @@ -1343,18 +1349,19 @@ int _nl_add_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, if (prefix) { /* Message attributes = length/type/value */ - struct rtattr a_src = {RTA_LENGTH(ip_address_len(prefix->family)), FRA_SRC}; + struct rtattr a_src = {RTA_LENGTH(hicn_ip_address_len(prefix->family)), + FRA_SRC}; struct rtattr a_prio = {RTA_LENGTH(sizeof(uint32_t)), FRA_PRIORITY}; - const void * address = ip_address_get_buffer(&prefix->address, prefix->family); - if (!address) - goto ERR; + const void *address = + hicn_ip_address_get_buffer(&prefix->address, prefix->family); + if (!address) goto ERR; /* Iovec describing the packets */ const struct iovec iov[] = { {&msg, sizeof(msg)}, /* Source prefix / prefix */ {&a_src, sizeof(a_src)}, - {(void*)address, ip_address_len(prefix->family)}, + {(void *)address, hicn_ip_address_len(prefix->family)}, /* Priority */ {&a_prio, sizeof(a_prio)}, {(void *)&priority, sizeof(uint32_t)}, @@ -1405,14 +1412,13 @@ ERR: return HICN_SOCKET_ERROR_UNSPEC; } -int _nl_add_lo_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, +int _nl_add_lo_prio_rule(const hicn_ip_prefix_t *prefix, uint8_t address_family, const uint32_t priority) { - return _nl_add_prio_rule(prefix, address_family, priority, - RT_TABLE_LOCAL); + return _nl_add_prio_rule(prefix, address_family, priority, RT_TABLE_LOCAL); } /* ip -6 rule del from all prio 0 table local */ -int _nl_del_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, +int _nl_del_prio_rule(const hicn_ip_prefix_t *prefix, uint8_t address_family, const uint32_t priority, const uint8_t table_id) { /* Buffer for holding the response, with appropriate casting on the header */ char buffer[BUFSIZE]; @@ -1447,19 +1453,20 @@ int _nl_del_prio_rule(const ip_prefix_t *prefix, uint8_t address_family, /* Message attributes = length/type/value */ if (prefix) { - struct rtattr a_src = {RTA_LENGTH(ip_address_len(prefix->family)), FRA_SRC}; + struct rtattr a_src = {RTA_LENGTH(hicn_ip_address_len(prefix->family)), + FRA_SRC}; struct rtattr a_prio = {RTA_LENGTH(sizeof(uint32_t)), FRA_PRIORITY}; - const void * address = ip_address_get_buffer(&prefix->address, prefix->family); - if (!address) - goto ERR; + const void *address = + hicn_ip_address_get_buffer(&prefix->address, prefix->family); + if (!address) goto ERR; /* Iovec describing the packets */ const struct iovec iov[] = { {&msg, sizeof(msg)}, /* Source prefix / prefix */ {&a_src, sizeof(a_src)}, - {(void*)address, ip_address_len(prefix->family)}, + {(void *)address, hicn_ip_address_len(prefix->family)}, /* Priority */ {&a_prio, sizeof(a_prio)}, {(void *)&priority, sizeof(uint32_t)}, @@ -1512,8 +1519,8 @@ ERR: return HICN_SOCKET_ERROR_UNSPEC; } -int _nl_del_lo_prio_rule(const ip_prefix_t *ip_address, uint8_t address_family, - const uint32_t priority) { +int _nl_del_lo_prio_rule(const hicn_ip_prefix_t *ip_address, + uint8_t address_family, const uint32_t priority) { return _nl_del_prio_rule(ip_address, address_family, priority, RT_TABLE_LOCAL); } @@ -1539,7 +1546,7 @@ int _nl_del_lo_prio_rule(const ip_prefix_t *ip_address, uint8_t address_family, int tun_alloc(char *dev, int flags) { struct ifreq ifr; - int fd, err; + int fd, err, rc; char *clonedev = "/dev/net/tun"; /* Arguments taken by the function: @@ -1563,7 +1570,8 @@ int tun_alloc(char *dev, int flags) { /* if a device name was specified, put it in the structure; otherwise, * the kernel will try to allocate the "next" device of the * specified type */ - strncpy(ifr.ifr_name, dev, IF_NAMESIZE - 1); + rc = strcpy_s(ifr.ifr_name, IF_NAMESIZE - 1, dev); + if (rc != EOK) return -1; } /* try to create the device */ @@ -1576,7 +1584,8 @@ int tun_alloc(char *dev, int flags) { * interface to the variable "dev", so the caller can know * it. Note that the caller MUST reserve space in *dev (see calling * code below) */ - strcpy(dev, ifr.ifr_name); + rc = strcpy_s(dev, IF_NAMESIZE, ifr.ifr_name); + if (rc != EOK) return -1; /* this is the special file descriptor that the caller will use to talk * with the virtual interface */ |