From patchwork Fri Dec 15 00:10:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13493834 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB4BE36A for ; Fri, 15 Dec 2023 00:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 28071730F9 for ; Thu, 14 Dec 2023 19:10:34 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:839:244f:d841:d551]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id DECBF7311A for ; Thu, 14 Dec 2023 19:10:33 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 1/8] inet: Relocate 'rtnl_route_cmd2string'. Date: Thu, 14 Dec 2023 16:10:24 -0800 Message-ID: <20231215001032.2127527-2-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215001032.2127527-1-gerickson@nuovations.com> References: <20231215001032.2127527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This relocates the 'rtnl_route_cmd2string' function earlier in the file to accommodate incorporation by other functions later in the file without the need for a forward declration. --- src/inet.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/inet.c b/src/inet.c index e957212f11e8..ad2bca7a5e04 100644 --- a/src/inet.c +++ b/src/inet.c @@ -584,6 +584,18 @@ int connman_inet_clear_address(int index, struct connman_ipaddress *ipaddress) return 0; } +static const char *rtnl_route_cmd2string(int cmd) +{ + switch (cmd) { + case RTM_NEWROUTE: + return "add"; + case RTM_DELROUTE: + return "del"; + } + + return ""; +} + int connman_inet_add_host_route(int index, const char *host, const char *gateway) { @@ -3255,18 +3267,6 @@ int __connman_inet_del_fwmark_rule(uint32_t table_id, int family, uint32_t fwmar return iprule_modify(RTM_DELRULE, family, table_id, fwmark); } -static const char *rtnl_route_cmd2string(int cmd) -{ - switch (cmd) { - case RTM_NEWROUTE: - return "add"; - case RTM_DELROUTE: - return "del"; - } - - return ""; -} - /** * @brief * Add or remove a gateway default route. From patchwork Fri Dec 15 00:10:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13493831 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB468361 for ; Fri, 15 Dec 2023 00:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 8610973100 for ; Thu, 14 Dec 2023 19:10:34 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:839:244f:d841:d551]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 47F0B73122 for ; Thu, 14 Dec 2023 19:10:34 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 2/8] inet: Reorder IPv6 host and network route function declarations. Date: Thu, 14 Dec 2023 16:10:25 -0800 Message-ID: <20231215001032.2127527-3-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215001032.2127527-1-gerickson@nuovations.com> References: <20231215001032.2127527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This reorders the IPv6 host and network route function declarations to match that of their IPv4 couterparts. --- include/inet.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/inet.h b/include/inet.h index 9245eef8bf52..1b2be1e23d8f 100644 --- a/include/inet.h +++ b/include/inet.h @@ -56,13 +56,14 @@ int connman_inet_set_ipv6_address(int index, struct connman_ipaddress *ipaddress); int connman_inet_clear_ipv6_address(int index, struct connman_ipaddress *ipaddress); -int connman_inet_add_ipv6_network_route(int index, const char *host, - const char *gateway, unsigned char prefix_len); int connman_inet_add_ipv6_host_route(int index, const char *host, const char *gateway); +int connman_inet_del_ipv6_host_route(int index, const char *host); +int connman_inet_add_ipv6_network_route(int index, const char *host, + const char *gateway, + unsigned char prefix_len); int connman_inet_del_ipv6_network_route(int index, const char *host, unsigned char prefix_len); -int connman_inet_del_ipv6_host_route(int index, const char *host); int connman_inet_clear_ipv6_gateway_address(int index, const char *gateway); int connman_inet_set_ipv6_gateway_interface(int index); int connman_inet_clear_ipv6_gateway_interface(int index); From patchwork Fri Dec 15 00:10:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13493832 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB48C363 for ; Fri, 15 Dec 2023 00:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id E77AF73118 for ; Thu, 14 Dec 2023 19:10:34 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:839:244f:d841:d551]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id A61E773128 for ; Thu, 14 Dec 2023 19:10:34 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 3/8] inet: Add IPv{4,6} host/network route functions with metric/priority. Date: Thu, 14 Dec 2023 16:10:26 -0800 Message-ID: <20231215001032.2127527-4-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215001032.2127527-1-gerickson@nuovations.com> References: <20231215001032.2127527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds 'connman_inet_{add,del}_{,ipv6_}{host,network}_route_with_metric' functions that provide the ability to add/delete an IPv4 or IPv6 host or network route with an explicit metric / priority. As a convenience, the 'connman_inet_{add,del}_{,ipv6_}network_route_with_metric' functions allow the caller to provide the IPv4 or IPv6 network address in masked (that is, 169.254.0.0/16) or unmasked (169.254.75.191/16) form. The function will mask the address, based on the provided prefix length, before modifying the route with it. --- include/inet.h | 36 ++++ src/inet.c | 475 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 479 insertions(+), 32 deletions(-) diff --git a/include/inet.h b/include/inet.h index 1b2be1e23d8f..c7488165720c 100644 --- a/include/inet.h +++ b/include/inet.h @@ -42,8 +42,26 @@ bool connman_inet_is_ifup(int index); int connman_inet_set_address(int index, struct connman_ipaddress *ipaddress); int connman_inet_clear_address(int index, struct connman_ipaddress *ipaddress); +int connman_inet_add_host_route_with_metric(int index, + const char *host, + const char *gateway, + uint32_t metric); +int connman_inet_del_host_route_with_metric(int index, + const char *host, + const char *gateway, + uint32_t metric); int connman_inet_add_host_route(int index, const char *host, const char *gateway); int connman_inet_del_host_route(int index, const char *host); +int connman_inet_add_network_route_with_metric(int index, + const char *host, + const char *gateway, + uint8_t prefix_len, + uint32_t metric); +int connman_inet_del_network_route_with_metric(int index, + const char *host, + const char *gateway, + uint8_t prefix_len, + uint32_t metric); int connman_inet_add_network_route(int index, const char *host, const char *gateway, const char *netmask); int connman_inet_del_network_route(int index, const char *host); @@ -56,9 +74,27 @@ int connman_inet_set_ipv6_address(int index, struct connman_ipaddress *ipaddress); int connman_inet_clear_ipv6_address(int index, struct connman_ipaddress *ipaddress); +int connman_inet_add_ipv6_host_route_with_metric(int index, + const char *host, + const char *gateway, + uint32_t metric); +int connman_inet_del_ipv6_host_route_with_metric(int index, + const char *host, + const char *gateway, + uint32_t metric); int connman_inet_add_ipv6_host_route(int index, const char *host, const char *gateway); int connman_inet_del_ipv6_host_route(int index, const char *host); +int connman_inet_del_ipv6_network_route_with_metric(int index, + const char *host, + const char *gateway, + uint8_t prefix_len, + uint32_t metric); +int connman_inet_add_ipv6_network_route_with_metric(int index, + const char *host, + const char *gateway, + uint8_t prefix_len, + uint32_t metric); int connman_inet_add_ipv6_network_route(int index, const char *host, const char *gateway, unsigned char prefix_len); diff --git a/src/inet.c b/src/inet.c index ad2bca7a5e04..cb2fa4f111e2 100644 --- a/src/inet.c +++ b/src/inet.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -596,6 +597,348 @@ static const char *rtnl_route_cmd2string(int cmd) return ""; } +static int inet_get_addr_data(int family, + const char *addr_string, + void *addr_data) +{ + int status = 0; + + if (!addr_string || !addr_data) + return -EINVAL; + + status = inet_pton(family, addr_string, addr_data); + switch (status) { + case -1: + return -errno; + default: + case 0: + return -EINVAL; + case 1: + break; + } + + return 0; +} + +static int inet_mask_addr_data(size_t addr_len, + void *addr_data, + uint8_t prefixlen) +{ + uint8_t *const addr_bytes = addr_data; + const size_t total_prefix_bytes = howmany(prefixlen, NBBY); + const size_t full_prefix_bytes = prefixlen / NBBY; + const size_t full_clear_bytes = addr_len - total_prefix_bytes; + const uint8_t remaining_bits = prefixlen % NBBY; + + if (!addr_len || !addr_data || full_prefix_bytes > addr_len) + return -EINVAL; + + /* Clear whole non-prefix bytes */ + + memset(&addr_bytes[addr_len - full_clear_bytes], + 0x00, + full_clear_bytes); + + /* Mask remaining bits in the last partial prefix byte */ + + if (remaining_bits) + addr_bytes[full_prefix_bytes] &= ~(0xFF >> remaining_bits); + + return 0; +} + +static int inet_modify_host_or_network_route(int cmd, + int family, + int index, + const char *host_or_network, + const char *gateway, + uint8_t prefixlen, + uint32_t table_id, + uint32_t metric) +{ + g_autofree char *interface = NULL; + struct __connman_inet_rtnl_handle rth; + unsigned char host_or_network_buf[sizeof(struct in6_addr)]; + unsigned char gateway_buf[sizeof(struct in6_addr)]; + int ret; + size_t addr_len; + + if (!host_or_network || index < 0) + return -EINVAL; + + interface = connman_inet_ifname(index); + + DBG("cmd %d (%s) family %d index %d (%s) destination %s/%u gateway %s " + "table %u <%s> metric %u", + cmd, rtnl_route_cmd2string(cmd), + family, + index, interface, + host_or_network, prefixlen, + gateway, + table_id, __connman_inet_table2string(table_id), + metric); + + switch (family) { + case AF_INET: + addr_len = 4; + break; + case AF_INET6: + addr_len = 16; + break; + default: + return -EINVAL; + } + + /* Convert the host or network address from text to binary form */ + + ret = inet_get_addr_data(family, host_or_network, host_or_network_buf); + if (ret < 0) + return ret; + + /* Apply the prefix length to the address data */ + + ret = inet_mask_addr_data(addr_len, host_or_network_buf, prefixlen); + if (ret < 0) + return ret; + + /* If present, convert the gateway address from text to binary form */ + + if (gateway) { + ret = inet_get_addr_data(family, gateway, gateway_buf); + if (ret < 0) + return ret; + } + + memset(&rth, 0, sizeof(rth)); + + rth.req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); + rth.req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; + rth.req.n.nlmsg_type = cmd; + + rth.req.u.r.rt.rtm_family = family; + rth.req.u.r.rt.rtm_table = table_id; + rth.req.u.r.rt.rtm_protocol = RTPROT_BOOT; + rth.req.u.r.rt.rtm_scope = gateway ? + RT_SCOPE_UNIVERSE : + RT_SCOPE_LINK; + rth.req.u.r.rt.rtm_type = RTN_UNICAST; + rth.req.u.r.rt.rtm_dst_len = prefixlen; + + __connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req), + RTA_DST, host_or_network_buf, addr_len); + + if (gateway) { + __connman_inet_rtnl_addattr_l(&rth.req.n, sizeof(rth.req), + RTA_GATEWAY, gateway_buf, addr_len); + } + + __connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req), + RTA_TABLE, table_id); + + __connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req), + RTA_OIF, index); + + __connman_inet_rtnl_addattr32(&rth.req.n, sizeof(rth.req), + RTA_PRIORITY, metric); + + ret = __connman_inet_rtnl_open(&rth); + if (ret < 0) + goto done; + + ret = __connman_inet_rtnl_send(&rth, &rth.req.n); + if (ret < 0) + goto done; + + ret = __connman_inet_rtnl_recv(&rth, NULL); + if (ret < 0) + goto done; + +done: + __connman_inet_rtnl_close(&rth); + + return ret; +} + +static int inet_modify_host_route(int cmd, + int family, + int index, + const char *host, + const char *gateway, + uint8_t prefixlen, + uint32_t metric) +{ + static const uint32_t table_id = RT_TABLE_MAIN; + + return inet_modify_host_or_network_route(cmd, + family, + index, + host, + gateway, + prefixlen, + table_id, + metric); +} + +static int inet_modify_network_route(int cmd, + int family, + int index, + const char *network, + const char *gateway, + uint8_t prefixlen, + uint32_t metric) +{ + static const uint32_t table_id = RT_TABLE_MAIN; + + return inet_modify_host_or_network_route(cmd, + family, + index, + network, + gateway, + prefixlen, + table_id, + metric); +} + +static int inet_modify_ipv4_network_route(int cmd, + int index, + const char *network, + const char *gateway, + uint8_t prefixlen, + uint32_t metric) +{ + static const int family = AF_INET; + + return inet_modify_network_route(cmd, + family, + index, + network, + gateway, + prefixlen, + metric); +} + +static int inet_modify_ipv6_network_route(int cmd, + int index, + const char *network, + const char *gateway, + uint8_t prefixlen, + uint32_t metric) +{ + static const int family = AF_INET6; + + return inet_modify_network_route(cmd, + family, + index, + network, + gateway, + prefixlen, + metric); +} + +static int inet_modify_ipv4_host_route(int cmd, + int index, + const char *host, + const char *gateway, + uint32_t metric) +{ + static const int family = AF_INET; + static const uint8_t prefixlen = 32; + + return inet_modify_host_route(cmd, + family, + index, + host, + gateway, + prefixlen, + metric); +} + +static int inet_modify_ipv6_host_route(int cmd, + int index, + const char *host, + const char *gateway, + uint32_t metric) +{ + static const int family = AF_INET6; + static const uint8_t prefixlen = 128; + + return inet_modify_host_route(cmd, + family, + index, + host, + gateway, + prefixlen, + metric); +} + +int connman_inet_add_host_route_with_metric(int index, + const char *host, + const char *gateway, + uint32_t metric) +{ + static const int cmd = RTM_NEWROUTE; + + DBG(""); + + return inet_modify_ipv4_host_route(cmd, + index, + host, + gateway, + metric); +} + +int connman_inet_del_host_route_with_metric(int index, + const char *host, + const char *gateway, + uint32_t metric) +{ + static const int cmd = RTM_DELROUTE; + + DBG(""); + + return inet_modify_ipv4_host_route(cmd, + index, + host, + gateway, + metric); +} + +int connman_inet_add_network_route_with_metric(int index, + const char *network, + const char *gateway, + uint8_t prefixlen, + uint32_t metric) +{ + static const int cmd = RTM_NEWROUTE; + + DBG(""); + + return inet_modify_ipv4_network_route(cmd, + index, + network, + gateway, + prefixlen, + metric); +} + +int connman_inet_del_network_route_with_metric(int index, + const char *network, + const char *gateway, + uint8_t prefixlen, + uint32_t metric) +{ + static const int cmd = RTM_DELROUTE; + + DBG(""); + + return inet_modify_ipv4_network_route(cmd, + index, + network, + gateway, + prefixlen, + metric); +} + int connman_inet_add_host_route(int index, const char *host, const char *gateway) { @@ -749,48 +1092,78 @@ out: return err; } -int connman_inet_del_ipv6_network_route(int index, const char *host, - unsigned char prefix_len) +int connman_inet_add_ipv6_host_route_with_metric(int index, + const char *host, + const char *gateway, + uint32_t metric) { - struct in6_rtmsg rt; - int sk, err = 0; + static const int cmd = RTM_NEWROUTE; - DBG("index %d host %s", index, host); + DBG(""); - if (!host) - return -EINVAL; + return inet_modify_ipv6_host_route(cmd, + index, + host, + gateway, + metric); +} - memset(&rt, 0, sizeof(rt)); +int connman_inet_del_ipv6_host_route_with_metric(int index, + const char *host, + const char *gateway, + uint32_t metric) +{ + static const int cmd = RTM_DELROUTE; - rt.rtmsg_dst_len = prefix_len; + DBG(""); - if (inet_pton(AF_INET6, host, &rt.rtmsg_dst) != 1) { - err = -errno; - goto out; - } + return inet_modify_ipv6_host_route(cmd, + index, + host, + gateway, + metric); +} - rt.rtmsg_flags = RTF_UP | RTF_HOST; +int connman_inet_add_ipv6_network_route_with_metric(int index, + const char *network, + const char *gateway, + uint8_t prefixlen, + uint32_t metric) +{ + static const int cmd = RTM_NEWROUTE; - rt.rtmsg_metric = 1; - rt.rtmsg_ifindex = index; + DBG(""); - sk = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0); - if (sk < 0) { - err = -errno; - goto out; - } + return inet_modify_ipv6_network_route(cmd, + index, + network, + gateway, + prefixlen, + metric); +} - if (ioctl(sk, SIOCDELRT, &rt) < 0 && errno != ESRCH) - err = -errno; +int connman_inet_del_ipv6_network_route_with_metric(int index, + const char *network, + const char *gateway, + uint8_t prefixlen, + uint32_t metric) +{ + static const int cmd = RTM_DELROUTE; - close(sk); + DBG(""); -out: - if (err < 0) - connman_error("Del IPv6 host route error (%s)", - strerror(-err)); + return inet_modify_ipv6_network_route(cmd, + index, + network, + gateway, + prefixlen, + metric); +} - return err; +int connman_inet_add_ipv6_host_route(int index, const char *host, + const char *gateway) +{ + return connman_inet_add_ipv6_network_route(index, host, gateway, 128); } int connman_inet_del_ipv6_host_route(int index, const char *host) @@ -869,10 +1242,48 @@ out: return err; } -int connman_inet_add_ipv6_host_route(int index, const char *host, - const char *gateway) +int connman_inet_del_ipv6_network_route(int index, const char *host, + unsigned char prefix_len) { - return connman_inet_add_ipv6_network_route(index, host, gateway, 128); + struct in6_rtmsg rt; + int sk, err = 0; + + DBG("index %d host %s", index, host); + + if (!host) + return -EINVAL; + + memset(&rt, 0, sizeof(rt)); + + rt.rtmsg_dst_len = prefix_len; + + if (inet_pton(AF_INET6, host, &rt.rtmsg_dst) != 1) { + err = -errno; + goto out; + } + + rt.rtmsg_flags = RTF_UP | RTF_HOST; + + rt.rtmsg_metric = 1; + rt.rtmsg_ifindex = index; + + sk = socket(AF_INET6, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (sk < 0) { + err = -errno; + goto out; + } + + if (ioctl(sk, SIOCDELRT, &rt) < 0 && errno != ESRCH) + err = -errno; + + close(sk); + +out: + if (err < 0) + connman_error("Del IPv6 host route error (%s)", + strerror(-err)); + + return err; } int connman_inet_clear_ipv6_gateway_address(int index, const char *gateway) From patchwork Fri Dec 15 00:10:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13493835 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB432360 for ; Fri, 15 Dec 2023 00:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 52D5073123 for ; Thu, 14 Dec 2023 19:10:35 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:839:244f:d841:d551]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 161A973144 for ; Thu, 14 Dec 2023 19:10:35 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 4/8] connection: Document 'inet_get_addr_data'. Date: Thu, 14 Dec 2023 16:10:27 -0800 Message-ID: <20231215001032.2127527-5-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215001032.2127527-1-gerickson@nuovations.com> References: <20231215001032.2127527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'inet_get_addr_data' function. --- src/inet.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/inet.c b/src/inet.c index cb2fa4f111e2..cc450355bf7e 100644 --- a/src/inet.c +++ b/src/inet.c @@ -597,6 +597,37 @@ static const char *rtnl_route_cmd2string(int cmd) return ""; } +/** + * @brief + * Convert the specified address from text to binary form. + * + * This attempts to converts the specified address in text form into + * binary form in network (that is, big endian) byte order, according + * to the specified address family. + * + * @param[in] family The address family describing the + * address pointed to by @a addr_string. + * @param[in] addr_string A pointer to an immutable null- + * terminated C string containing the + * address, in text form, to convert to + * binary form. + * @param[in,out] addr_data A pointer to storage sufficiently + * large to hold @a addr_string + * converted into binary form. This will + * point to the converted binary address + * data on success. + * + * @retval 0 If successful. + * @retval -EINVAL If @a addr_string or @a addr_data are + * null or @a addr_string does not contain a + * character string representing a valid + * network address in @a family. + * @retval -EAFNOSUPPORT If @ family does not contain a valid + * address family. + * + * @sa inet_pton + * + */ static int inet_get_addr_data(int family, const char *addr_string, void *addr_data) From patchwork Fri Dec 15 00:10:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13493836 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B083C361 for ; Fri, 15 Dec 2023 00:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id B03E47311A for ; Thu, 14 Dec 2023 19:10:35 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:839:244f:d841:d551]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 72FA873145 for ; Thu, 14 Dec 2023 19:10:35 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 5/8] connection: Document 'inet_mask_addr_data'. Date: Thu, 14 Dec 2023 16:10:28 -0800 Message-ID: <20231215001032.2127527-6-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215001032.2127527-1-gerickson@nuovations.com> References: <20231215001032.2127527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'inet_mask_addr_data' function. --- src/inet.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/inet.c b/src/inet.c index cc450355bf7e..ca999fa31633 100644 --- a/src/inet.c +++ b/src/inet.c @@ -651,6 +651,31 @@ static int inet_get_addr_data(int family, return 0; } +/** + * @brief + * Apply the specified prefix length to the specified binary + * address data. + * + * This attempts to apply the specified prefix length as a network / + * prefix mask to the specified address data, in network (that is, + * big endian) byte order, to generate a network address / prefix. + * + * @param[in] addr_len The length, in bytes of the address + * pointed to by @a addr_data. + * @param[in,out] addr_data A pointer to the mutable address data + * in binary form in network (that is, + * big endian) byte order to mask with @a + * prefixlen. + * @param[in] prefixlen The prefix length to apply to @a + * addr_data as a mask to generate a + * network address / prefix. + * + * @retval 0 If successful. + * @retval -EINVAL If @a addr_len or @a addr_data are null + * or if the specified prefix length exceeds + * the address length. + * + */ static int inet_mask_addr_data(size_t addr_len, void *addr_data, uint8_t prefixlen) From patchwork Fri Dec 15 00:10:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13493837 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B086B363 for ; Fri, 15 Dec 2023 00:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 1AB877310B for ; Thu, 14 Dec 2023 19:10:36 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:839:244f:d841:d551]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id CFFFA7312C for ; Thu, 14 Dec 2023 19:10:35 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 6/8] connection: Document 'inet_modify_host_or_network_route'. Date: Thu, 14 Dec 2023 16:10:29 -0800 Message-ID: <20231215001032.2127527-7-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215001032.2127527-1-gerickson@nuovations.com> References: <20231215001032.2127527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'inet_modify_host_or_network_route' function. --- src/inet.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/inet.c b/src/inet.c index ca999fa31633..873da5f73396 100644 --- a/src/inet.c +++ b/src/inet.c @@ -703,6 +703,67 @@ static int inet_mask_addr_data(size_t addr_len, return 0; } +/** + * @brief + * Add or remove a host or network route. + * + * This attempts to add or remove a host or network route to or from + * the kernel using a Linux Route Netlink (rtnl) socket and protocol + * with the specified attributes. + * + * @note + * The caller may provide the IPv4 or IPv6 @a host_or_network + * address in masked (that is, 169.254.0.0/16) or unmasked + * (169.254.75.191/16) form. The function will mask the address, + * based on the prefix length, before modifying the route with it. + * + * @param[in] cmd The Linux Route Netlink command to + * send. This is expected to be either + * RTM_NEWROUTE (add new route) or + * RTM_DELROUTE (delete existing route). + * @param[in] family The address family associated with @a + * host_or_network and @a gateway, if + * present. + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host_or_network A pointer to an immutable null- + * terminated C string containing the + * IPv4 or IPv6 address, in text form, + * of the route host or network + * destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 or IPv6 address, in text + * form, of the route next hop gateway + * address. + * @param[in] prefixlen The destination prefix length of the + * route. + * @param[in] table_id The table to add/delete this route + * to/from. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host_or_network is null; if @a index is + * invalid; if the address family of @a family was + * not AF_INET (IPv4) or AF_INET6 (IPv6); if @a + * host_or_network or @a gateway, if present, do + * not contain a character string representing a + * valid network address in either the AF_INET or + * AF_INET6 family; or if the routing information + * to be added or deleted was invalid. + * @retval -EFAULT If the address to the routing information to be + * added or deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add or delete + * routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + */ static int inet_modify_host_or_network_route(int cmd, int family, int index, From patchwork Fri Dec 15 00:10:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13493838 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16411379 for ; Fri, 15 Dec 2023 00:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id 7696373128 for ; Thu, 14 Dec 2023 19:10:36 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:839:244f:d841:d551]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 395F27314B for ; Thu, 14 Dec 2023 19:10:36 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 7/8] connection: Document 'inet_modify_{,ipv4_,ipv6_}{host,network}_route'. Date: Thu, 14 Dec 2023 16:10:30 -0800 Message-ID: <20231215001032.2127527-8-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215001032.2127527-1-gerickson@nuovations.com> References: <20231215001032.2127527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'inet_modify_{,ipv4_,ipv6_}{host,network}_route' functions. --- src/inet.c | 321 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) diff --git a/src/inet.c b/src/inet.c index 873da5f73396..863d733078f6 100644 --- a/src/inet.c +++ b/src/inet.c @@ -876,6 +876,68 @@ done: return ret; } +/** + * @brief + * Add or remove a host route. + * + * This attempts to add or remove a host route to or from the kernel + * using a Linux Route Netlink (rtnl) socket and protocol with the + * specified attributes. + * + * @note + * The caller may provide the IPv4 or IPv6 @a host address in + * masked (that is, 169.254.0.0/16) or unmasked (169.254.75.191/16) + * form. The function will mask the address, based on the prefix + * length, before modifying the route with it. + * + * @param[in] cmd The Linux Route Netlink command to + * send. This is expected to be either + * RTM_NEWROUTE (add new route) or + * RTM_DELROUTE (delete existing route). + * @param[in] family The address family associated with @a + * host and @a gateway, if present. + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv4 or IPv6 address, in text form, + * of the route host destination + * address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 or IPv6 address, in text + * form, of the route next hop gateway + * address. + * @param[in] prefixlen The destination prefix length of the + * route. + * @param[in] table_id The table to add/delete this route + * to/from. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * the address family of @a family was not AF_INET + * (IPv4) or AF_INET6 (IPv6); if @a host or @a + * gateway, if present, do not contain a character + * string representing a valid network address in + * either the AF_INET or AF_INET6 family; or if the + * routing information to be added or deleted was + * invalid. + * @retval -EFAULT If the address to the routing information to be + * added or deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add or delete + * routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_host_or_network_route + * + */ static int inet_modify_host_route(int cmd, int family, int index, @@ -896,6 +958,68 @@ static int inet_modify_host_route(int cmd, metric); } +/** + * @brief + * Add or remove a network route. + * + * This attempts to add or remove a network route to or from the + * kernel using a Linux Route Netlink (rtnl) socket and protocol with + * the specified attributes. + * + * @note + * The caller may provide the IPv4 or IPv6 @a network address in + * masked (that is, 169.254.0.0/16) or unmasked (169.254.75.191/16) + * form. The function will mask the address, based on the prefix + * length, before modifying the route with it. + * + * @param[in] cmd The Linux Route Netlink command to + * send. This is expected to be either + * RTM_NEWROUTE (add new route) or + * RTM_DELROUTE (delete existing route). + * @param[in] family The address family associated with @a + * network and @a gateway, if present. + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] network A pointer to an immutable null- + * terminated C string containing the + * IPv4 or IPv6 address, in text form, + * of the route network destination + * address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 or IPv6 address, in text + * form, of the route next hop gateway + * address. + * @param[in] prefixlen The destination prefix length of the + * route. + * @param[in] table_id The table to add/delete this route + * to/from. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a network is null; if @a index is invalid; + * if the address family of @a family was not + * AF_INET (IPv4) or AF_INET6 (IPv6); if @a network + * or @a gateway, if present, do not contain a + * character string representing a valid network + * address in either the AF_INET or AF_INET6 + * family; or if the routing information to be + * added or deleted was invalid. + * @retval -EFAULT If the address to the routing information to be + * added or deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add or delete + * routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_host_or_network_route + * + */ static int inet_modify_network_route(int cmd, int family, int index, @@ -916,6 +1040,58 @@ static int inet_modify_network_route(int cmd, metric); } +/** + * @brief + * Add or remove an IPv4 network route. + * + * This attempts to add or remove an IPv4 network route to or from + * the kernel using a Linux Route Netlink (rtnl) socket and protocol + * with the specified attributes. + * + * @note + * The caller may provide the IPv4 @a network address in masked + * (that is, 169.254.0.0/16) or unmasked (169.254.75.191/16) + * form. The function will mask the address, based on the prefix + * length, before modifying the route with it. + * + * @param[in] cmd The Linux Route Netlink command to + * send. This is expected to be either + * RTM_NEWROUTE (add new route) or + * RTM_DELROUTE (delete existing route). + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] network A pointer to an immutable null- + * terminated C string containing the + * IPv4 address, in text form, of the + * route network destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 address, in text form, of + * the route next hop gateway address. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a network is null; if @a index is invalid; + * if @a network or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added or deleted was + * invalid. + * @retval -EFAULT If the address to the routing information to be + * added or deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add or delete + * routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_network_route + * + */ static int inet_modify_ipv4_network_route(int cmd, int index, const char *network, @@ -934,6 +1110,59 @@ static int inet_modify_ipv4_network_route(int cmd, metric); } +/** + * @brief + * Add or remove an IPv6 network route. + * + * This attempts to add or remove an IPv6 network route to or from + * the kernel using a Linux Route Netlink (rtnl) socket and protocol + * with the specified attributes. + * + * @note + * The caller may provide the IPv6 @a network address in masked + * (that is, 2601:647:5a00:1500::/56) or unmasked + * (2601:647:5a00:15c1:230d:b2c9:c388:f96b/56) form. The function + * will mask the address, based on the prefix length, before + * modifying the route with it. + * + * @param[in] cmd The Linux Route Netlink command to + * send. This is expected to be either + * RTM_NEWROUTE (add new route) or + * RTM_DELROUTE (delete existing route). + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] network A pointer to an immutable null- + * terminated C string containing the + * IPv6 address, in text form, of the + * route network destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv6 address, in text form, of + * the route next hop gateway address. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a network is null; if @a index is invalid; + * if @a network or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added or deleted was + * invalid. + * @retval -EFAULT If the address to the routing information to be + * added or deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add or delete + * routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_network_route + * + */ static int inet_modify_ipv6_network_route(int cmd, int index, const char *network, @@ -952,6 +1181,52 @@ static int inet_modify_ipv6_network_route(int cmd, metric); } +/** + * @brief + * Add or remove an IPv4 host route. + * + * This attempts to add or remove an IPv4 host route to or from the + * kernel using a Linux Route Netlink (rtnl) socket and protocol with + * the specified attributes. + * + * @param[in] cmd The Linux Route Netlink command to + * send. This is expected to be either + * RTM_NEWROUTE (add new route) or + * RTM_DELROUTE (delete existing route). + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv4 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 address, in text form, of + * the route next hop gateway address. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added or deleted was + * invalid. + * @retval -EFAULT If the address to the routing information to be + * added or deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add or delete + * routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_host_route + * + */ static int inet_modify_ipv4_host_route(int cmd, int index, const char *host, @@ -970,6 +1245,52 @@ static int inet_modify_ipv4_host_route(int cmd, metric); } +/** + * @brief + * Add or remove an IPv6 host route. + * + * This attempts to add or remove an IPv6 host route to or from the + * kernel using a Linux Route Netlink (rtnl) socket and protocol with + * the specified attributes. + * + * @param[in] cmd The Linux Route Netlink command to + * send. This is expected to be either + * RTM_NEWROUTE (add new route) or + * RTM_DELROUTE (delete existing route). + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv6 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv6 address, in text form, of + * the route next hop gateway address. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET6 family; or if + * the routing information to be added or deleted + * was invalid. + * @retval -EFAULT If the address to the routing information to be + * added or deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add or delete + * routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_host_route + * + */ static int inet_modify_ipv6_host_route(int cmd, int index, const char *host, From patchwork Fri Dec 15 00:10:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Erickson X-Patchwork-Id: 13493839 Received: from mohas.pair.com (mohas.pair.com [209.68.5.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 163DC36A for ; Fri, 15 Dec 2023 00:10:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nuovations.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nuovations.com Received: from mohas.pair.com (localhost [127.0.0.1]) by mohas.pair.com (Postfix) with ESMTP id D4E657312B for ; Thu, 14 Dec 2023 19:10:36 -0500 (EST) Received: from localhost.localdomain (unknown [IPv6:2601:647:5a00:15c1:839:244f:d841:d551]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mohas.pair.com (Postfix) with ESMTPSA id 97BA973147 for ; Thu, 14 Dec 2023 19:10:36 -0500 (EST) From: Grant Erickson To: connman@lists.linux.dev Subject: [PATCH 8/8] inet: Document IPv{4,6} host/network route functions with metric/priority. Date: Thu, 14 Dec 2023 16:10:31 -0800 Message-ID: <20231215001032.2127527-9-gerickson@nuovations.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231215001032.2127527-1-gerickson@nuovations.com> References: <20231215001032.2127527-1-gerickson@nuovations.com> Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.112 This adds documentation to the 'connman_inet_{add,del}_{,ipv6_}{host,network}_route_with_metric' functions. --- src/inet.c | 338 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 338 insertions(+) diff --git a/src/inet.c b/src/inet.c index 863d733078f6..2abd55ef75e9 100644 --- a/src/inet.c +++ b/src/inet.c @@ -1309,6 +1309,44 @@ static int inet_modify_ipv6_host_route(int cmd, metric); } +/** + * @brief + * Add an IPv4 host route with a route metric/priority. + * + * This attempts to add an IPv4 host route to the kernel using a + * Linux Route Netlink (rtnl) socket and protocol with the specified + * attributes and route metric/priority. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv4 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 address, in text form, of + * the route next hop gateway address. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added was invalid. + * @retval -EFAULT If the address to the routing information to be + * added was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * + * @sa inet_modify_ipv4_host_route + * + */ int connman_inet_add_host_route_with_metric(int index, const char *host, const char *gateway, @@ -1325,6 +1363,44 @@ int connman_inet_add_host_route_with_metric(int index, metric); } +/** + * @brief + * Remove an IPv4 host route with a route metric/priority. + * + * This attempts to remove an IPv4 host route from the kernel using a + * Linux Route Netlink (rtnl) socket and protocol with the specified + * attributes and route metric/priority. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv4 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 address, in text form, of + * the route next hop gateway address. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be deleted was invalid. + * @retval -EFAULT If the address to the routing information to be + * deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to delete routes. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_ipv4_host_route + * + */ int connman_inet_del_host_route_with_metric(int index, const char *host, const char *gateway, @@ -1341,6 +1417,52 @@ int connman_inet_del_host_route_with_metric(int index, metric); } +/** + * @brief + * Add an IPv4 network route with a route metric/priority. + * + * This attempts to add an IPv4 network route to the kernel using a + * Linux Route Netlink (rtnl) socket and protocol with the specified + * attributes and route metric/priority. + * + * @note + * The caller may provide the IPv4 @a network address in masked + * (that is, 169.254.0.0/16) or unmasked (169.254.75.191/16) + * form. The function will mask the address, based on the prefix + * length, before modifying the route with it. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] network A pointer to an immutable null- + * terminated C string containing the + * IPv4 address, in text form, of the + * route network destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 address, in text form, of + * the route next hop gateway address. + * @param[in] prefixlen The destination prefix length of the + * route. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a network is null; if @a index is invalid; + * if @a network or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added was invalid. + * @retval -EFAULT If the address to the routing information to be + * added was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * + * @sa inet_modify_ipv4_network_route + * + */ int connman_inet_add_network_route_with_metric(int index, const char *network, const char *gateway, @@ -1359,6 +1481,52 @@ int connman_inet_add_network_route_with_metric(int index, metric); } +/** + * @brief + * Remove an IPv4 network route with a route metric/priority. + * + * This attempts to add an IPv4 network route from the kernel using a + * Linux Route Netlink (rtnl) socket and protocol with the specified + * attributes and route metric/priority. + * + * @note + * The caller may provide the IPv4 @a network address in masked + * (that is, 169.254.0.0/16) or unmasked (169.254.75.191/16) + * form. The function will mask the address, based on the prefix + * length, before modifying the route with it. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] network A pointer to an immutable null- + * terminated C string containing the + * IPv4 address, in text form, of the + * route network destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv4 address, in text form, of + * the route next hop gateway address. + * @param[in] prefixlen The destination prefix length of the + * route. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a network is null; if @a index is invalid; + * if @a network or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be deleted was invalid. + * @retval -EFAULT If the address to the routing information to be + * deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add routes. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_ipv4_network_route + * + */ int connman_inet_del_network_route_with_metric(int index, const char *network, const char *gateway, @@ -1530,6 +1698,44 @@ out: return err; } +/** + * @brief + * Add an IPv6 host route with a route metric/priority. + * + * This attempts to add an IPv6 host route to the kernel using a + * Linux Route Netlink (rtnl) socket and protocol with the specified + * attributes and route metric/priority. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv6 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv6 address, in text form, of + * the route next hop gateway address. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added was invalid. + * @retval -EFAULT If the address to the routing information to be + * added was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * + * @sa inet_modify_ipv6_host_route + * + */ int connman_inet_add_ipv6_host_route_with_metric(int index, const char *host, const char *gateway, @@ -1546,6 +1752,44 @@ int connman_inet_add_ipv6_host_route_with_metric(int index, metric); } +/** + * @brief + * Remove an IPv6 host route with a route metric/priority. + * + * This attempts to remove an IPv6 host route from the kernel using a + * Linux Route Netlink (rtnl) socket and protocol with the specified + * attributes and route metric/priority. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] host A pointer to an immutable null- + * terminated C string containing the + * IPv6 address, in text form, of the + * route host destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv6 address, in text form, of + * the route next hop gateway address. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a host is null; if @a index is invalid; if + * @a host or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be deleted was invalid. + * @retval -EFAULT If the address to the routing information to be + * deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to delete routes. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_ipv6_host_route + * + */ int connman_inet_del_ipv6_host_route_with_metric(int index, const char *host, const char *gateway, @@ -1562,6 +1806,53 @@ int connman_inet_del_ipv6_host_route_with_metric(int index, metric); } +/** + * @brief + * Add an IPv6 network route with a route metric/priority. + * + * This attempts to add an IPv6 network route to the kernel using a + * Linux Route Netlink (rtnl) socket and protocol with the specified + * attributes and route metric/priority. + * + * @note + * The caller may provide the IPv6 @a network address in masked + * (that is, 2601:647:5a00:1500::/56) or unmasked + * (2601:647:5a00:15c1:230d:b2c9:c388:f96b/56) form. The function + * will mask the address, based on the prefix length, before + * modifying the route with it. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] network A pointer to an immutable null- + * terminated C string containing the + * IPv6 address, in text form, of the + * route network destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv6 address, in text form, of + * the route next hop gateway address. + * @param[in] prefixlen The destination prefix length of the + * route. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a network is null; if @a index is invalid; + * if @a network or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be added was invalid. + * @retval -EFAULT If the address to the routing information to be + * added was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add routes. + * @retval -EEXIST A request was made to add an existing routing + * entry. + * + * @sa inet_modify_ipv6_network_route + * + */ int connman_inet_add_ipv6_network_route_with_metric(int index, const char *network, const char *gateway, @@ -1580,6 +1871,53 @@ int connman_inet_add_ipv6_network_route_with_metric(int index, metric); } +/** + * @brief + * Remove an IPv6 network route with a route metric/priority. + * + * This attempts to add an IPv6 network route from the kernel using a + * Linux Route Netlink (rtnl) socket and protocol with the specified + * attributes and route metric/priority. + * + * @note + * The caller may provide the IPv6 @a network address in masked + * (that is, 2601:647:5a00:1500::/56) or unmasked + * (2601:647:5a00:15c1:230d:b2c9:c388:f96b/56) form. The function + * will mask the address, based on the prefix length, before + * modifying the route with it. + * + * @param[in] index The network interface index associated + * with the output network device for + * the route. + * @param[in] network A pointer to an immutable null- + * terminated C string containing the + * IPv6 address, in text form, of the + * route network destination address. + * @param[in] gateway An optional pointer to an immutable + * null-terminated C string containing + * the IPv6 address, in text form, of + * the route next hop gateway address. + * @param[in] prefixlen The destination prefix length of the + * route. + * @param[in] metric The routing priority metric for the + * route. + * + * @retval 0 If successful. + * @retval -EINVAL If @a network is null; if @a index is invalid; + * if @a network or @a gateway, if present, do not + * contain a character string representing a valid + * network address in the AF_INET family; or if the + * routing information to be deleted was invalid. + * @retval -EFAULT If the address to the routing information to be + * deleted was invalid. + * @retval -EPERM If the current process does not have the + * credentials or capabilities to add routes. + * @retval -ESRCH A request was made to delete a non-existing + * routing entry. + * + * @sa inet_modify_ipv4_network_route + * + */ int connman_inet_del_ipv6_network_route_with_metric(int index, const char *network, const char *gateway,