inet: Add IPv{4,6} Host/Network Route Add/Delete with Metric / Priority Functions
cover inet: Add IPv{4,6} Host/Network Route Add/Delete with Metric / Priority Functions
This adds and documents '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' network route functions allow the caller to provide the IPv4 or IPv6 network address in masked (for example, 169.254.0.0/16) or unmasked (for example, 169.254.75.191/16) form. The function will mask the address, based on the provided prefix length, before modifying the route with it.
Grant Erickson (8):
inet: Relocate 'rtnl_route_cmd2string'.
inet: Reorder IPv6 host and network route function declarations.
inet: Add IPv{4,6} host/network route functions with metric/priority.
connection: Document 'inet_get_addr_data'.
connection: Document 'inet_mask_addr_data'.
connection: Document 'inet_modify_host_or_network_route'.
connection: Document 'inet_modify_{,ipv4_,ipv6_}{host,network}_route'.
inet: Document IPv{4,6} host/network route functions with
metric/priority.
include/inet.h | 43 +- src/inet.c | 1275 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 1271 insertions(+), 47 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/8 inet: Relocate 'rtnl_route_cmd2string'.
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(-)
src/inet.c +12 -12
@@ -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 fwmarreturn 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.
Signature · 1 line
2.42.0
PATCH 2/8 inet: Reorder IPv6 host and network route function declarations.
In reply to Grant EricksonThis 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(-)
include/inet.h +4 -3
@@ -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);
Signature · 1 line
2.42.0
PATCH 3/8 inet: Add IPv{4,6} host/network route functions with metric/priority.
In reply to Grant EricksonThis 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(-)
include/inet.h +36 -0
@@ -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);
src/inet.c +443 -32
513 lines not on this page · raw message
Signature · 1 line
2.42.0
PATCH 4/8 connection: Document 'inet_get_addr_data'.
In reply to Grant EricksonThis adds documentation to the 'inet_get_addr_data' function.
--- src/inet.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
src/inet.c +31 -0
@@ -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)
Signature · 1 line
2.42.0
PATCH 5/8 connection: Document 'inet_mask_addr_data'.
In reply to Grant EricksonThis adds documentation to the 'inet_mask_addr_data' function.
--- src/inet.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
src/inet.c +25 -0
@@ -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)
Signature · 1 line
2.42.0
PATCH 6/8 connection: Document 'inet_modify_host_or_network_route'.
In reply to Grant EricksonThis adds documentation to the 'inet_modify_host_or_network_route' function.
--- src/inet.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
src/inet.c +61 -0
@@ -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,
Signature · 1 line
2.42.0
PATCH 7/8 connection: Document 'inet_modify_{,ipv4_,ipv6_}{host,network}_route'.
In reply to Grant EricksonThis adds documentation to the 'inet_modify_{,ipv4_,ipv6_}{host,network}_route' functions.
--- src/inet.c | 321 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+)
src/inet.c +321 -0
@@ -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,
Signature · 1 line
2.42.0
PATCH 8/8 inet: Document IPv{4,6} host/network route functions with metric/priority.
In reply to Grant EricksonThis adds documentation to the 'connman_inet_{add,del}_{,ipv6_}{host,network}_route_with_metric' functions.
--- src/inet.c | 338 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 338 insertions(+)
src/inet.c +338 -0
@@ -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,
Signature · 1 line
2.42.0
Hi Grant,
Quoted 24 lines
This adds and documents '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' network route functions allow the caller to provide the IPv4 or IPv6 network address in masked (for example, 169.254.0.0/16) or unmasked (for example, 169.254.75.191/16) form. The function will mask the address, based on the provided prefix length, before modifying the route with it.
Grant Erickson (8):
inet: Relocate 'rtnl_route_cmd2string'.
inet: Reorder IPv6 host and network route function declarations.
inet: Add IPv{4,6} host/network route functions with metric/priority.
connection: Document 'inet_get_addr_data'.
connection: Document 'inet_mask_addr_data'.
connection: Document 'inet_modify_host_or_network_route'.
connection: Document 'inet_modify_{,ipv4_,ipv6_}{host,network}_route'.
inet: Document IPv{4,6} host/network route functions with
metric/priority.
Quoted 3 lines
include/inet.h| 43 +-src/inet.c| 1275 ++++++++++++++++++++++++++++++++++++++++++++++--2 files changed, 1271 insertions(+), 47 deletions(-)
all 8 patches have been applied.
Regards
Marcel