net: Rename l_net_subnet_matches to l_net_prefix_matches
Andrew Zaborowski
PATCH 1/13 net: Rename l_net_subnet_matches to l_net_prefix_matches
--- ell/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ell/net.h +1 -1
@@ -41,7 +41,7 @@ bool l_net_hostname_is_localhost(const char *hostname);bool l_net_get_address (int ifindex,struct in_addr *out);bool l_net_get_link_local_address (int ifindex,struct in6_addr *out); -static inline bool l_net_subnet_matches (const void *a,const void *b, +static inline bool l_net_prefix_matches (const void *a,const void *b,uint8_t prefix_len) {uint8_t bytes = prefix_len /8 ;
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 2/13 icmp6: Parse extra options
Parse Route Information and New Advertisement Interval options. Route Information options (RIOs) are supported by radvd and a few clients that I checked.
--- ell/icmp6-private.h | 6 ++- ell/icmp6.c | 118 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 110 insertions(+), 14 deletions(-)
ell/icmp6-private.h +4 -2
@@ -22,6 +22,7 @@struct route_info {uint8_t address[16 ]; +bool onlink :1 ;uint8_t prefix_len;uint8_t preference;uint32_t preferred_lifetime;
@@ -36,8 +37,9 @@ struct l_icmp6_router {uint64_t start_time;uint16_t lifetime;uint32_t mtu; -uint32_t n_prefixes; -struct route_info *prefixes; +uint32_t max_rtr_adv_interval_ms; +uint32_t n_routes; +struct route_info *routes; };struct l_icmp6_router *_icmp6_router_new ();
ell/icmp6.c +106 -12
181 lines not on this page · raw message
Signature · 1 line
2.32.0
Denis Kenzior
AppliedRe: [PATCH 02/13] icmp6: Parse extra options
Hi Andrew,
Quoted 8 lines · Andrew Zaborowski
Parse Route Information and New Advertisement Interval options. Route Information options (RIOs) are supported by radvd and a few clients that I checked.
--- ell/icmp6-private.h | 6 ++- ell/icmp6.c | 118 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 110 insertions(+), 14 deletions(-)
Applied, thanks.
Regards,
-Denis
Andrew Zaborowski
PATCH 3/13 netconfig: Add DHCP override and static IP API
In reply to Andrew ZaborowskiAdd API to override things like DNS, domain names, etc. received from DHCP or disable DHCP completely by setting a static address.
--- ell/ell.sym | 8 ++ ell/netconfig.c | 322 +++++++++++++++++++++++++++++++++++++++++++++++- ell/netconfig.h | 16 +++ 3 files changed, 341 insertions(+), 5 deletions(-)
ell/ell.sym +8 -0
@@ -738,6 +738,14 @@ global: /* netconfig */ l_netconfig_new; l_netconfig_destroy; + l_netconfig_set_family_enabled; + l_netconfig_set_hostname; + l_netconfig_set_route_priority; + l_netconfig_set_static_addr; + l_netconfig_set_gateway_override; + l_netconfig_set_dns_override; + l_netconfig_set_domain_names_override; + l_netconfig_check_config; l_netconfig_start; l_netconfig_stop; l_netconfig_get_dhcp_client;
ell/netconfig.c +317 -5
368 lines not on this page · raw message
ell/netconfig.h +16 -0
@@ -53,6 +53,22 @@ typedef void (*l_netconfig_destroy_cb_t)(void *user_data);struct l_netconfig *l_netconfig_new (uint32_t ifindex);void l_netconfig_destroy (struct l_netconfig *netconfig); +bool l_netconfig_set_family_enabled (struct l_netconfig *netconfig, +uint8_t family,bool enabled); +bool l_netconfig_set_hostname (struct l_netconfig *netconfig, +const char *hostname); +bool l_netconfig_set_route_priority (struct l_netconfig *netconfig, +uint32_t priority); +bool l_netconfig_set_static_addr (struct l_netconfig *netconfig,uint8_t family, +const struct l_rtnl_address *addr); +bool l_netconfig_set_gateway_override (struct l_netconfig *netconfig, +uint8_t family, +const char *gateway_str); +bool l_netconfig_set_dns_override (struct l_netconfig *netconfig,uint8_t family, +char **dns_list); +bool l_netconfig_set_domain_names_override (struct l_netconfig *netconfig, +uint8_t family,char **names); +bool l_netconfig_check_config (struct l_netconfig *netconfig);bool l_netconfig_start (struct l_netconfig *netconfig);void l_netconfig_stop (struct l_netconfig *netconfig);
Signature · 1 line
2.32.0
Denis Kenzior
AppliedRe: [PATCH 03/13] netconfig: Add DHCP override and static IP API
Hi Andrew,
Quoted 8 lines · Andrew Zaborowski
Add API to override things like DNS, domain names, etc. received from DHCP or disable DHCP completely by setting a static address.
--- ell/ell.sym | 8 ++ ell/netconfig.c | 322 +++++++++++++++++++++++++++++++++++++++++++++++- ell/netconfig.h | 16 +++ 3 files changed, 341 insertions(+), 5 deletions(-)
Applied, thanks.
Regards,
-Denis
Andrew Zaborowski
PATCH 4/13 netconfig: Support IPv6 static configurations
In reply to Andrew Zaborowski--- ell/netconfig.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 143 insertions(+), 5 deletions(-)
ell/netconfig.c +143 -5
@@ -62,11 +62,13 @@ struct l_netconfig {struct l_idle *do_static_work;bool v4_configured;struct l_dhcp_client *dhcp_client; +bool v6_configured;/* These objects, if not NULL, are owned by @addresses and @routes */ struct l_rtnl_address *v4_address;struct l_rtnl_route *v4_subnet_route;struct l_rtnl_route *v4_default_route; +struct l_rtnl_address *v6_address;struct {struct l_queue *current;
@@ -159,6 +161,50 @@ static void netconfig_add_v4_routes(struct l_netconfig *nc, const char *ip,l_queue_push_tail (nc->routes.added, nc->v4_default_route); } +static void netconfig_add_v6_static_routes (struct l_netconfig *nc, +const char *ip, +uint8_t prefix_len) +{ +struct in6_addr in6_addr; +char network[INET6_ADDRSTRLEN ]; +struct l_rtnl_route *v6_subnet_route; +struct l_rtnl_route *v6_default_route; + +/* Subnet route */ + +if (L_WARN_ON (inet_pton (AF_INET6 , ip, &in6_addr) !=1 )) +return ; + +/* Zero out host address bits to produce network address */ +if (prefix_len &7 ) + in6_addr.s6_addr[prefix_len /8 ] &=0xff00 >> (prefix_len &7 ); + +if (prefix_len <=120 ) +memset (in6_addr.s6_addr + (prefix_len +7 ) /8 ,0 , +16 - (prefix_len +7 ) /8 ); + +if (L_WARN_ON (!inet_ntop (AF_INET6 , &in6_addr, network, +INET6_ADDRSTRLEN ))) +return ; + + v6_subnet_route =l_rtnl_route_new_prefix (network, prefix_len); +l_rtnl_route_set_protocol (v6_subnet_route,RTPROT_STATIC ); +l_rtnl_route_set_priority (v6_subnet_route, nc->route_priority); +l_queue_push_tail (nc->routes.current, v6_subnet_route); +l_queue_push_tail (nc->routes.added, v6_subnet_route); + +/* Gateway route */ + +if (!nc->v6_gateway_override) +return ; + + v6_default_route =l_rtnl_route_new_gateway (nc->v6_gateway_override); +l_rtnl_route_set_protocol (v6_default_route,RTPROT_STATIC ); +L_WARN_ON (!l_rtnl_route_set_prefsrc (v6_default_route, ip)); +l_queue_push_tail (nc->routes.current, v6_default_route); +l_queue_push_tail (nc->routes.added, v6_default_route); +} +static void netconfig_add_dhcp_address_routes (struct l_netconfig *nc) { const struct l_dhcp_lease *lease =
@@ -388,6 +434,9 @@ LIB_EXPORT bool l_netconfig_set_family_enabled(struct l_netconfig *netconfig,case AF_INET : netconfig->v4_enabled = enabled;return true; +case AF_INET6 : + netconfig->v6_enabled = enabled; +return true; }return false;
@@ -580,11 +629,56 @@ static bool netconfig_check_v4_config(struct l_netconfig *netconfig)return true; } +static bool netconfig_check_v6_config (struct l_netconfig *netconfig) +{ +struct in6_addr local; +struct in6_addr gateway; +uint8_t prefix_len =0 ; +unsigned int dns_num =0 ; + _auto_(l_free) struct in6_addr *dns_list = NULL; + +if (!netconfig->v6_enabled) +return true; + +if (netconfig->v6_static_addr) { +char str[INET6_ADDRSTRLEN ]; + + prefix_len =l_rtnl_address_get_prefix_length ( + netconfig->v6_static_addr); +if (unlikely (prefix_len >126 )) +return false; + +l_rtnl_address_get_address (netconfig->v6_static_addr, str); +inet_pton (AF_INET6 , str, &local); + } + +if (netconfig->v6_gateway_override) { +if (unlikely (inet_pton (AF_INET6 , netconfig->v6_gateway_override, + &gateway) !=1 )) +return false; + } + +if (netconfig->v6_dns_override && + (dns_num =l_strv_length (netconfig->v6_dns_override))) { +unsigned int i; + + dns_list = l_new(struct in6_addr, dns_num); + +for (i =0 ; i < dns_num; i++) +if (inet_pton (AF_INET6 , netconfig->v6_dns_override[i], + &dns_list[i]) !=1 ) +return false; + } + +return true; +} +static bool netconfig_check_config (struct l_netconfig *netconfig) {/* TODO: error reporting through a debug log handler or otherwise */ -return netconfig_check_v4_config (netconfig); +return netconfig_check_v4_config (netconfig) && +netconfig_check_v6_config (netconfig); } LIB_EXPORT bool l_netconfig_check_config(struct l_netconfig *netconfig)
@@ -595,7 +689,7 @@ LIB_EXPORT bool l_netconfig_check_config(struct l_netconfig *netconfig)return netconfig_check_config (netconfig); } -static void netconfig_add_static_address_routes (struct l_netconfig *nc) +static void netconfig_add_v4_static_address_routes (struct l_netconfig *nc) {char ip[INET_ADDRSTRLEN ];uint32_t prefix_len;
@@ -609,6 +703,29 @@ static void netconfig_add_static_address_routes(struct l_netconfig *nc)netconfig_add_v4_routes (nc, ip, prefix_len,NULL ,RTPROT_STATIC ); } +/* +* Just mirror the IPv4 behaviour with static IPv6 configuration. It would +* be more logical to let the user choose between static IPv6 address and +* DHCPv6, and, completely independently, choose between static routes +* (if a static prefix length and/or gateway address is set) and ICMPv6. +* Yet a mechanism identical with IPv4 is easier to understand for a typical +* user so providing a static address just disables all automatic +* configuration. +*/ +static void netconfig_add_v6_static_address_routes (struct l_netconfig *nc) +{ +char ip[INET6_ADDRSTRLEN ]; +uint32_t prefix_len; + + nc->v6_address =l_rtnl_address_clone (nc->v6_static_addr); +l_queue_push_tail (nc->addresses.current, nc->v6_address); +l_queue_push_tail (nc->addresses.added, nc->v6_address); + +l_rtnl_address_get_address (nc->v6_static_addr, ip); + prefix_len =l_rtnl_address_get_prefix_length (nc->v6_static_addr); +netconfig_add_v6_static_routes (nc, ip, prefix_len); +} +static void netconfig_do_static_config (struct l_idle *idle,void *user_data) {struct l_netconfig *nc = user_data;
@@ -616,10 +733,16 @@ static void netconfig_do_static_config(struct l_idle *idle, void *user_data)l_idle_remove (l_steal_ptr (nc->do_static_work));if (nc->v4_static_addr && !nc->v4_configured) { -netconfig_add_static_address_routes (nc); +netconfig_add_v4_static_address_routes (nc); nc->v4_configured = true;netconfig_emit_event (nc,AF_INET ,L_NETCONFIG_EVENT_CONFIGURE ); } + +if (nc->v6_static_addr && !nc->v6_configured) { +netconfig_add_v6_static_address_routes (nc); + nc->v6_configured = true; +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_CONFIGURE ); + } } LIB_EXPORT bool l_netconfig_start(struct l_netconfig *netconfig)
@@ -631,7 +754,7 @@ LIB_EXPORT bool l_netconfig_start(struct l_netconfig *netconfig)return false;if (!netconfig->v4_enabled) - goto done; + goto configure_ipv6;if (netconfig->v4_static_addr) {/*
@@ -641,12 +764,26 @@ LIB_EXPORT bool l_netconfig_start(struct l_netconfig *netconfig) netconfig->do_static_work =l_idle_create ( netconfig_do_static_config, netconfig,NULL ); - goto done; + goto configure_ipv6; }if (!l_dhcp_client_start (netconfig->dhcp_client))return false; +configure_ipv6: +if (!netconfig->v6_enabled) + goto done; + +if (netconfig->v6_static_addr && !netconfig->do_static_work) { +/* +* We're basically ready to configure the interface +* but do this in an idle callback. +*/ + netconfig->do_static_work =l_idle_create ( + netconfig_do_static_config, + netconfig,NULL ); + } + done: netconfig->started = true;return true;
@@ -670,6 +807,7 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig) netconfig->v4_address =NULL ; netconfig->v4_subnet_route =NULL ; netconfig->v4_default_route =NULL ; + netconfig->v6_address =NULL ;l_dhcp_client_stop (netconfig->dhcp_client); }
Signature · 1 line
2.32.0
Denis Kenzior
Re: [PATCH 04/13] netconfig: Support IPv6 static configurations
Hi Andrew,
Quoted 4 lines · Andrew Zaborowski
--- ell/netconfig.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 143 insertions(+), 5 deletions(-)
So I was going to apply this, but let me ask you this first...
<snip>
Quoted 11 lines
ell/netconfig.c +7
-0@@ -159,6 +161,50 @@ static void netconfig_add_v4_routes(struct l_netconfig *nc, const char *ip,l_queue_push_tail (nc->routes.added, nc->v4_default_route); } +static void netconfig_add_v6_static_routes (struct l_netconfig *nc, +const char *ip, +uint8_t prefix_len) +{ +struct in6_addr in6_addr; +char network[INET6_ADDRSTRLEN ]; +struct l_rtnl_route *v6_subnet_route;
ell/netconfig.c static void netconfig_add_v4_routes(struct l_netconfig *nc, const char *ip, · line 180
Quoted 10 lines
ell/netconfig.c +10
-0+struct l_rtnl_route *v6_default_route; + +/* Subnet route */ + +if (L_WARN_ON (inet_pton (AF_INET6 , ip, &in6_addr) !=1 )) +return ; + +/* Zero out host address bits to produce network address */ +if (prefix_len &7 ) + in6_addr.s6_addr[prefix_len /8 ] &=0xff00 >> (prefix_len &7 );
Can we make this a bit cleaner? Something like
last_byte = prefix_len / 8;
if (prefix_len & 7) {
/* zero out lsb bits */
last_byte += 1;
}memset(in6_addr + last_byte, 0, 16 - last_byte);
However, the more general question here is why do we want to store and compute the prefix route separately? Is the assumption here that all addresses use the noprefixroute flag? Wouldn't it be simpler to just have the kernel handle this?
Quoted 30 lines
ell/netconfig.c +27
-0+ +if (prefix_len <=120 ) +memset (in6_addr.s6_addr + (prefix_len +7 ) /8 ,0 , +16 - (prefix_len +7 ) /8 ); + +if (L_WARN_ON (!inet_ntop (AF_INET6 , &in6_addr, network, +INET6_ADDRSTRLEN ))) +return ; + + v6_subnet_route =l_rtnl_route_new_prefix (network, prefix_len); +l_rtnl_route_set_protocol (v6_subnet_route,RTPROT_STATIC ); +l_rtnl_route_set_priority (v6_subnet_route, nc->route_priority); +l_queue_push_tail (nc->routes.current, v6_subnet_route); +l_queue_push_tail (nc->routes.added, v6_subnet_route); + +/* Gateway route */ + +if (!nc->v6_gateway_override) +return ; + + v6_default_route =l_rtnl_route_new_gateway (nc->v6_gateway_override); +l_rtnl_route_set_protocol (v6_default_route,RTPROT_STATIC ); +L_WARN_ON (!l_rtnl_route_set_prefsrc (v6_default_route, ip)); +l_queue_push_tail (nc->routes.current, v6_default_route); +l_queue_push_tail (nc->routes.added, v6_default_route); +} +static void netconfig_add_dhcp_address_routes (struct l_netconfig *nc) { const struct l_dhcp_lease *lease =
<snip>
Quoted 35 lines
ell/netconfig.c +31
-0@@ -580,11 +629,56 @@ static bool netconfig_check_v4_config(struct l_netconfig *netconfig)return true; } +static bool netconfig_check_v6_config (struct l_netconfig *netconfig) +{ +struct in6_addr local; +struct in6_addr gateway; +uint8_t prefix_len =0 ; +unsigned int dns_num =0 ; + _auto_(l_free) struct in6_addr *dns_list = NULL; + +if (!netconfig->v6_enabled) +return true; + +if (netconfig->v6_static_addr) { +char str[INET6_ADDRSTRLEN ]; + + prefix_len =l_rtnl_address_get_prefix_length ( + netconfig->v6_static_addr); +if (unlikely (prefix_len >126 )) +return false; + +l_rtnl_address_get_address (netconfig->v6_static_addr, str); +inet_pton (AF_INET6 , str, &local); + } + +if (netconfig->v6_gateway_override) { +if (unlikely (inet_pton (AF_INET6 , netconfig->v6_gateway_override, + &gateway) !=1 )) +return false; + } + +if (netconfig->v6_dns_override && + (dns_num =l_strv_length (netconfig->v6_dns_override))) {
ell/netconfig.c static bool netconfig_check_v4_config(struct l_netconfig *netconfig) · line 672
Quoted 10 lines
ell/netconfig.c +10
-0+unsigned int i; + + dns_list = l_new(struct in6_addr, dns_num); + +for (i =0 ; i < dns_num; i++) +if (inet_pton (AF_INET6 , netconfig->v6_dns_override[i], + &dns_list[i]) !=1 ) +return false; + } +
All this checking is pure copy-paste of the v4 version. Can they be combined?
ell/netconfig.c static bool netconfig_check_v4_config(struct l_netconfig *netconfig) · line 684
Quoted 13 lines
ell/netconfig.c +5
-1+return true; +} +static bool netconfig_check_config (struct l_netconfig *netconfig) {/* TODO: error reporting through a debug log handler or otherwise */ -return netconfig_check_v4_config (netconfig); +return netconfig_check_v4_config (netconfig) && +netconfig_check_v6_config (netconfig); } LIB_EXPORT bool l_netconfig_check_config(struct l_netconfig *netconfig)
Regards,
-Denis
Andrew Zaborowski
Re: [PATCH 04/13] netconfig: Support IPv6 static configurations
Quoted 7 lines · Denis Kenzior
ell/netconfig.c static void netconfig_add_v4_routes(struct l_netconfig *nc, const char *ip, · line 180
Quoted 3 lines · Andrew Zaborowski
ell/netconfig.c +3
-0+/* Zero out host address bits to produce network address */ +if (prefix_len &7 ) + in6_addr.s6_addr[prefix_len /8 ] &=0xff00 >> (prefix_len &7 );Can we make this a bit cleaner? Something like
Quoted 8 lines
last_byte=prefix_len/ 8;if (prefix_len & 7) { /* zero out lsb bits */ last_byte += 1; }
memset(in6_addr + last_byte, 0, 16 - last_byte);
Ok.
Quoted 4 lines
However, the more general question here is why do we want to store and compute the prefix route separately? Is the assumption here that all addresses use the noprefixroute flag? Wouldn't it be simpler to just have the kernel handle this?
So I think we can do that if we're committing the addresses to the kernel ourselves. If we have to delegate it to NM we still need this code. In the end I think it's easier to have just one branch here.
Having the kernel handle the subnet routes is even more obvious for IPv4 because it works for static as well as DHCP. For some reason the IWD code always sets this flag for both IPv4 and IPv6.
Quoted 39 lines
Quoted 39 lines
ell/netconfig.c +35
-0@@ -580,11 +629,56 @@ static bool netconfig_check_v4_config(struct l_netconfig *netconfig)return true; } +static bool netconfig_check_v6_config (struct l_netconfig *netconfig) +{ +struct in6_addr local; +struct in6_addr gateway; +uint8_t prefix_len =0 ; +unsigned int dns_num =0 ; + _auto_(l_free) struct in6_addr *dns_list = NULL; + +if (!netconfig->v6_enabled) +return true; + +if (netconfig->v6_static_addr) { +char str[INET6_ADDRSTRLEN ]; + + prefix_len =l_rtnl_address_get_prefix_length ( + netconfig->v6_static_addr); +if (unlikely (prefix_len >126 )) +return false; + +l_rtnl_address_get_address (netconfig->v6_static_addr, str); +inet_pton (AF_INET6 , str, &local); + } + +if (netconfig->v6_gateway_override) { +if (unlikely (inet_pton (AF_INET6 , netconfig->v6_gateway_override, + &gateway) !=1 )) +return false; + } + +if (netconfig->v6_dns_override && + (dns_num =l_strv_length (netconfig->v6_dns_override))) { +unsigned int i; + + dns_list = l_new(struct in6_addr, dns_num); +
Quoted 8 lines
ell/netconfig.c static bool netconfig_check_v4_config(struct l_netconfig *netconfig) · line 672
Quoted 6 lines
ell/netconfig.c +6
-0+for (i =0 ; i < dns_num; i++) +if (inet_pton (AF_INET6 , netconfig->v6_dns_override[i], + &dns_list[i]) !=1 ) +return false; + } +All this checking is pure copy-paste of the v4 version. Can they be combined?
Ok, let me do it that way.
Best regards
Denis Kenzior
Re: [PATCH 04/13] netconfig: Support IPv6 static configurations
Hi Andrew,
Quoted 7 lines
Quoted 3 lines
However, the more general question here is why do we want to store and compute the prefix route separately? Is the assumption here that all addresses use the noprefixroute flag? Wouldn't it be simpler to just have the kernel handle this?
So I think we can do that if we're committing the addresses to the kernel ourselves. If we have to delegate it to NM we still need this code. In the end I think it's easier to have just one branch here.
Explain? NM doesn't understand the noprefixroute flag? Just curious. I think we do indeed need to do it as you propose. See below.
Quoted 5 lines
Having the kernel handle the subnet routes is even more obvious for IPv4 because it works for static as well as DHCP. For some reason the IWD code always sets this flag for both IPv4 and IPv6.
I don't recall exactly why we originally added the connected route separately. I'm pretty sure this resulted in two prefix routes in the routing table until I introduced the noprefixroute flag to ell.
But I *think* the reason we add a separate connected route, in icmp6 at least, is to make sure the metric is applied properly. If noprefixroute flag isn't set, the kernel will automagically create a new connected route when the address is installed. But the metric used for this route is the default.
I don't think we found a way to affect the connected route's metric without resorting to the noprefixroute flag and adding the route separately. Maybe it is possible? Would save us a round trip.
Regards,
-Denis
Andrew Zaborowski
Re: [PATCH 04/13] netconfig: Support IPv6 static configurations
Quoted 10 lines · Denis Kenzior
Quoted 7 lines
Quoted 3 lines
However, the more general question here is why do we want to store and compute the prefix route separately? Is the assumption here that all addresses use the noprefixroute flag? Wouldn't it be simpler to just have the kernel handle this?
So I think we can do that if we're committing the addresses to the kernel ourselves. If we have to delegate it to NM we still need this code. In the end I think it's easier to have just one branch here.
Explain? NM doesn't understand the noprefixroute flag? Just curious. I think we do indeed need to do it as you propose. See below.
After some digging my understanding is that NM internally stores the address flags bitmap and the IWD backend could set it or clear IFA_F_NOPREFIXROUTE on the addresses received from IWD. But the core code doesn't often look at whether IFA_F_NOPREFIXROUTE is set because there's a policy in their netconfig code that basically it should be always set. The logic is quite involved but basically NM will set the flag when talking to the kernel, and then will autogenerate the subnet routes for IPv4 (statically or dynamically assigned) and for IPv6 static configs. That means that IWD doesn't need to give NM those subnet routes, same as if IFA_F_NOPREFIXROUTE was cleared.
On the other hand my thinking is that 1. we might want to not shape the ell API based on current NM behaviour and might want to add the subnet routes at the risk of NM ignoring them or adding duplicates. These routes can also be dropped (or added) at the IWD-backend or IWD level.
2. We may want to avoid adding too many address parameters and flags in the D-Bus API, or the ell C API.
Here are some interesting comments in NM code:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/libnm-platform/nm-platform.c#L5388-5404
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/libnm-platform/nm-platform.h#L411-425
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/core/nm-l3-config-data.c#L2418-2430
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/core/nm-l3-config-data.c#L2457-2465
Quoted 7 lines
Quoted 6 lines
Having the kernel handle the subnet routes is even more obvious for IPv4 because it works for static as well as DHCP. For some reason the IWD code always sets this flag for both IPv4 and IPv6.
Quoted 8 lines
I don't recall exactly why we originally added the connected route separately. I'm pretty sure this resulted in two prefix routes in the routing table until I introduced the noprefixroute flag to ell.
But I *think* the reason we add a separate connected route, in icmp6 at least, is to make sure the metric is applied properly. If noprefixroute flag isn't set, the kernel will automagically create a new connected route when the address is installed. But the metric used for this route is the default.
Ok I didn't know that, and it matches what NM comments say too. I guess this matters because the local subnet needs a higher metric than other routes?
Quoted 4 lines
I don't think we found a way to affect the connected route's metric without resorting to the noprefixroute flag and adding the route separately. Maybe it is possible? Would save us a round trip.
Best regards
Denis Kenzior
Re: [PATCH 04/13] netconfig: Support IPv6 static configurations
Hi Andrew,
Quoted 12 lines · Andrew Zaborowski
Quoted 10 lines · Denis Kenzior
Quoted 7 lines
Quoted 3 lines
However, the more general question here is why do we want to store and compute the prefix route separately? Is the assumption here that all addresses use the noprefixroute flag? Wouldn't it be simpler to just have the kernel handle this?
So I think we can do that if we're committing the addresses to the kernel ourselves. If we have to delegate it to NM we still need this code. In the end I think it's easier to have just one branch here.
Explain? NM doesn't understand the noprefixroute flag? Just curious. I think we do indeed need to do it as you propose. See below.
Quoted 10 lines
After some digging my understanding is that NM internally stores the address flags bitmap and the IWD backend could set it or clear
IFA_F_NOPREFIXROUTEon the addresses received from IWD. But the core code doesn't often look at whetherIFA_F_NOPREFIXROUTEis set because there's a policy in their netconfig code that basically it should be always set. The logic is quite involved but basically NM will set the flag when talking to the kernel, and then will autogenerate the subnet routes for IPv4 (statically or dynamically assigned) and for IPv6 static configs. That means that IWD doesn't need to give NM those subnet routes, same as ifIFA_F_NOPREFIXROUTEwas cleared.
Thanks, that was helpful.
Quoted 4 lines
On the other hand my thinking is that 1. we might want to not shape the ell API based on current NM behaviour and might want to add the subnet routes at the risk of NM ignoring them or adding duplicates.
I really have no strong feelings one way or the other. I suspect that unless we can add a metric info directly to the address, we are stuck using noprefixroute flag in all cases.
<snip>
Quoted 7 lines
Here are some interesting comments in NM code:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/libnm-platform/nm-platform.c#L5388-5404
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/libnm-platform/nm-platform.h#L411-425
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/core/nm-l3-config-data.c#L2418-2430
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/main/src/core/nm-l3-config-data.c#L2457-2465
So they actually try and work around kernels with no 'noprefixroute' flag support. We don't need to worry about this since iwd only works with kernels where this is standard.
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Having the kernel handle the subnet routes is even more obvious for IPv4 because it works for static as well as DHCP. For some reason the IWD code always sets this flag for both IPv4 and IPv6.
I don't recall exactly why we originally added the connected route separately. I'm pretty sure this resulted in two prefix routes in the routing table until I introduced the noprefixroute flag to ell.
Quoted 8 lines
Quoted 4 lines
But I *think* the reason we add a separate connected route, in icmp6 at least, is to make sure the metric is applied properly. If noprefixroute flag isn't set, the kernel will automagically create a new connected route when the address is installed. But the metric used for this route is the default.
Ok I didn't know that, and it matches what NM comments say too. I guess this matters because the local subnet needs a higher metric than other routes?
It is mostly to deal with multiple interfaces connected to the same subnet. For example, you may have wifi + ethernet connected to the same access point. You would want the packets to the local subnet to be routed over ethernet (with a lower metric) than over WiFi.
Regards,
-Denis
Andrew Zaborowski
PATCH 5/13 netconfig: Create routes from Router Advertisements
In reply to Andrew ZaborowskiIf IPv6 is enabled, create the ICMP6 client and handle Router Advertisements received by creating, updating and removing routes per the data in the Router Advertisements. Timeouts aren't handled yet.
--- ell/netconfig.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 206 insertions(+), 2 deletions(-)
ell/netconfig.c +206 -2
@@ -27,12 +27,16 @@#include <linux/types.h> #include <netinet/ip.h> #include <arpa/inet.h> +#include <netinet/icmp6.h> #include "private.h" #include "useful.h" #include "log.h" #include "dhcp.h" #include "dhcp-private.h" +#include "icmp6.h" +#include "icmp6-private.h" +#include "dhcp6.h" #include "netlink.h" #include "rtnl.h" #include "queue.h"
@@ -63,6 +67,8 @@ struct l_netconfig {bool v4_configured;struct l_dhcp_client *dhcp_client;bool v6_configured; +struct l_icmp6_client *icmp6_client; +struct l_dhcp6_client *dhcp6_client;/* These objects, if not NULL, are owned by @addresses and @routes */ struct l_rtnl_address *v4_address;
@@ -351,6 +357,189 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client, } } +static struct l_rtnl_route *netconfig_find_icmp6_route ( +struct l_netconfig *nc, +const uint8_t *gateway, +const struct route_info *dst) +{ +const struct l_queue_entry *entry; + +for (entry =l_queue_get_entries (nc->routes.current); entry; + entry = entry->next) { +struct l_rtnl_route *route = entry->data; +const uint8_t *route_gateway; +const uint8_t *route_dst; +uint8_t route_prefix_len =0 ; + +if (l_rtnl_route_get_family (route) !=AF_INET6 || +l_rtnl_route_get_protocol (route) !=RTPROT_RA ) +continue ; + + route_gateway =l_rtnl_route_get_gateway_in_addr (route); +if ((gateway || route_gateway) && + (!gateway || !route_gateway || +memcmp (gateway, route_gateway,16 ))) +continue ; + + route_dst =l_rtnl_route_get_dst_in_addr (route, + &route_prefix_len); +if ((dst || route_prefix_len) && + (!dst || !route_prefix_len || + dst->prefix_len != route_prefix_len || +memcmp (dst->address, route_dst, + (dst->prefix_len +7 ) /8 ))) +continue ; + +return route; + } + +return NULL ; +} + +static struct l_rtnl_route *netconfig_add_icmp6_route (struct l_netconfig *nc, +const uint8_t *gateway, +const struct route_info *dst, +uint8_t preference) +{ +struct l_rtnl_route *rt; +char buf1[INET6_ADDRSTRLEN ]; +char buf2[INET6_ADDRSTRLEN ]; + +if (gateway && !dst) + rt =l_rtnl_route_new_gateway (inet_ntop (AF_INET6 , gateway, + buf1,sizeof (buf1))); +else if (dst && !gateway) + rt =l_rtnl_route_new_prefix (inet_ntop (AF_INET6 , dst->address, + buf2,sizeof (buf2)), + dst->prefix_len); +else + rt =l_rtnl_route_new_static (inet_ntop (AF_INET6 , gateway, + buf1,sizeof (buf1)), +inet_ntop (AF_INET6 , + dst->address, + buf2,sizeof (buf2)), + dst->prefix_len); + +if (L_WARN_ON (!rt)) +return NULL ; + +l_rtnl_route_set_preference (rt, preference); +l_rtnl_route_set_protocol (rt,RTPROT_RA ); +l_rtnl_route_set_priority (rt, nc->route_priority); +l_queue_push_tail (nc->routes.current, rt); +l_queue_push_tail (nc->routes.added, rt); +return rt; +} + +static void netconfig_set_icmp6_route_data (struct l_netconfig *nc, +struct l_rtnl_route *rt, +uint64_t start_time, +uint32_t preferred_lifetime, +uint32_t valid_lifetime, +uint32_t mtu,bool updated) +{ +uint64_t expiry = start_time + valid_lifetime *L_USEC_PER_SEC ; + +l_rtnl_route_set_mtu (rt, mtu); +l_rtnl_route_set_lifetime (rt, valid_lifetime); +l_rtnl_route_set_expiry (rt, expiry); + +if (updated) +l_queue_push_tail (nc->routes.updated, rt); +} + +static void netconfig_remove_icmp6_route (struct l_netconfig *nc, +struct l_rtnl_route *route) +{ +l_queue_remove (nc->routes.current, route); +l_queue_push_tail (nc->routes.removed, route); +} + +static void netconfig_icmp6_event_handler (struct l_icmp6_client *client, +enum l_icmp6_client_event event, +void *event_data, +void *user_data) +{ +struct l_netconfig *nc = user_data; +const struct l_icmp6_router *r; +struct l_rtnl_route *default_route; +unsigned int i; + +if (event !=L_ICMP6_CLIENT_EVENT_ROUTER_FOUND ) +return ; + + r = event_data; + +/* +* Note: If this is the first RA received, the l_dhcp6_client +* will have received the event before us and will be acting +* on it by now. +*/ + +if (nc->v4_gateway_override) +return ; + +/* Process the default gateway information */ + default_route =netconfig_find_icmp6_route (nc, r->address,NULL ); + +if (!default_route && r->lifetime) { + default_route =netconfig_add_icmp6_route (nc, r->address,NULL , + r->pref); +if (unlikely (!default_route)) +return ; + +netconfig_set_icmp6_route_data (nc, default_route, r->start_time, + r->lifetime, r->lifetime, + r->mtu, false); + }else if (default_route && r->lifetime) +netconfig_set_icmp6_route_data (nc, default_route, r->start_time, + r->lifetime, r->lifetime, + r->mtu, true); +else if (default_route && !r->lifetime) +netconfig_remove_icmp6_route (nc, default_route); + +/* +* Process the onlink and offlink routes, from the Router +* Advertisement's Prefix Information options and Route +* Information options respectively. +*/ +for (i =0 ; i < r->n_routes; i++) { +const struct route_info *info = &r->routes[i]; +const uint8_t *gateway = info->onlink ?NULL : r->address; +struct l_rtnl_route *route = +netconfig_find_icmp6_route (nc, gateway, info); + +if (!route && info->valid_lifetime) { + route =netconfig_add_icmp6_route (nc, gateway, info, + info->preference); +if (unlikely (!route)) +continue ; + +netconfig_set_icmp6_route_data (nc, route, r->start_time, + info->preferred_lifetime, + info->valid_lifetime, + gateway ? r->mtu :0 , false); + }else if (route && info->valid_lifetime) +netconfig_set_icmp6_route_data (nc, route, r->start_time, + info->preferred_lifetime, + info->valid_lifetime, + gateway ? r->mtu :0 , true); +else if (route && !info->valid_lifetime) +netconfig_remove_icmp6_route (nc, route); + } + +/* +* Note: we may be emitting this before L_NETCONFIG_EVENT_CONFIGURE. +* We should probably instead save the affected routes in separate +* lists and add them to the _CONFIGURE event, suppressing any _UPDATE +* events while nc->v6_configured is false. +*/ +if (!l_queue_isempty (nc->routes.added) || + !l_queue_isempty (nc->routes.updated) || + !l_queue_isempty (nc->routes.removed)) +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE ); +} + LIB_EXPORT struct l_netconfig *l_netconfig_new(uint32_t ifindex) {struct l_netconfig *nc;
@@ -373,6 +562,13 @@ LIB_EXPORT struct l_netconfig *l_netconfig_new(uint32_t ifindex) netconfig_dhcp_event_handler, nc, NULL); + nc->dhcp6_client =l_dhcp6_client_new (ifindex); + + nc->icmp6_client =l_dhcp6_client_get_icmp6 (nc->dhcp6_client); +l_icmp6_client_add_event_handler (nc->icmp6_client, + netconfig_icmp6_event_handler, + nc,NULL ); +return nc; }
@@ -393,6 +589,7 @@ LIB_EXPORT void l_netconfig_destroy(struct l_netconfig *netconfig)l_netconfig_set_domain_names_override (netconfig,AF_INET6 ,NULL );l_dhcp_client_destroy (netconfig->dhcp_client); +l_dhcp6_client_destroy (netconfig->dhcp6_client);l_netconfig_set_event_handler (netconfig,NULL ,NULL ,NULL );l_queue_destroy (netconfig->addresses.current,NULL );l_queue_destroy (netconfig->addresses.added,NULL );
@@ -774,16 +971,22 @@ configure_ipv6:if (!netconfig->v6_enabled) goto done; -if (netconfig->v6_static_addr && !netconfig->do_static_work) { +if (netconfig->v6_static_addr) {/* * We're basically ready to configure the interface * but do this in an idle callback. */ - netconfig->do_static_work =l_idle_create ( +if (!netconfig->do_static_work) + netconfig->do_static_work =l_idle_create ( netconfig_do_static_config, netconfig,NULL ); + + goto done; } +if (!l_dhcp6_client_start (netconfig->dhcp6_client)) +return false; + done: netconfig->started = true;return true;
@@ -810,6 +1013,7 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig) netconfig->v6_address =NULL ;l_dhcp_client_stop (netconfig->dhcp_client); +l_dhcp6_client_stop (netconfig->dhcp6_client); } LIB_EXPORT struct l_dhcp_client *l_netconfig_get_dhcp_client(
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 6/13 netconfig: Add l_netconfig_get_{dhcp6,icmp6}_client
In reply to Andrew Zaborowski--- ell/ell.sym | 2 ++ ell/netconfig.c | 18 ++++++++++++++++++ ell/netconfig.h | 4 ++++ 3 files changed, 24 insertions(+)
ell/ell.sym +2 -0
@@ -749,6 +749,8 @@ global: l_netconfig_start; l_netconfig_stop; l_netconfig_get_dhcp_client; + l_netconfig_get_dhcp6_client; + l_netconfig_get_icmp6_client; l_netconfig_set_event_handler; l_netconfig_apply_rtnl; l_netconfig_get_addresses;
ell/netconfig.c +18 -0
@@ -1025,6 +1025,24 @@ LIB_EXPORT struct l_dhcp_client *l_netconfig_get_dhcp_client(return netconfig->dhcp_client; } +LIB_EXPORT struct l_dhcp6_client *l_netconfig_get_dhcp6_client( +struct l_netconfig *netconfig) +{ +if (unlikely (!netconfig)) +return NULL ; + +return netconfig->dhcp6_client; +} + +LIB_EXPORT struct l_icmp6_client *l_netconfig_get_icmp6_client( +struct l_netconfig *netconfig) +{ +if (unlikely (!netconfig)) +return NULL ; + +return netconfig->icmp6_client; +} + LIB_EXPORT void l_netconfig_set_event_handler(struct l_netconfig *netconfig, l_netconfig_event_cb_t handler, void *user_data,
ell/netconfig.h +4 -0
@@ -75,6 +75,10 @@ void l_netconfig_stop(struct l_netconfig *netconfig);struct l_dhcp_client *l_netconfig_get_dhcp_client (struct l_netconfig *netconfig); +struct l_dhcp6_client *l_netconfig_get_dhcp6_client ( +struct l_netconfig *netconfig); +struct l_icmp6_client *l_netconfig_get_icmp6_client ( +struct l_netconfig *netconfig); void l_netconfig_set_event_handler(struct l_netconfig *netconfig, l_netconfig_event_cb_t handler,
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 7/13 netconfig: Avoid returning internal l_queues
In reply to Andrew ZaborowskiReturn const struct l_queue_entry pointers instead.
--- ell/netconfig.c | 35 ++++++++++++++++++----------------- ell/netconfig.h | 20 +++++++++++--------- 2 files changed, 29 insertions(+), 26 deletions(-)
ell/netconfig.c +18 -17
@@ -1097,37 +1097,38 @@ LIB_EXPORT void l_netconfig_apply_rtnl(struct l_netconfig *netconfig, NULL, NULL, NULL); } -LIB_EXPORT struct l_queue *l_netconfig_get_addresses( -struct l_netconfig *netconfig, -struct l_queue **out_added, -struct l_queue **out_updated, -struct l_queue **out_removed) +LIB_EXPORT const struct l_queue_entry *l_netconfig_get_addresses( +struct l_netconfig *netconfig, +const struct l_queue_entry **out_added, +const struct l_queue_entry **out_updated, +const struct l_queue_entry **out_removed) {if (out_added) - *out_added = netconfig->addresses.added; + *out_added =l_queue_get_entries (netconfig->addresses.added);if (out_updated) - *out_updated = netconfig->addresses.updated; + *out_updated =l_queue_get_entries (netconfig->addresses.updated);if (out_removed) - *out_removed = netconfig->addresses.removed; + *out_removed =l_queue_get_entries (netconfig->addresses.removed); -return netconfig->addresses.current; +return l_queue_get_entries (netconfig->addresses.current); } -LIB_EXPORT struct l_queue *l_netconfig_get_routes(struct l_netconfig *netconfig, -struct l_queue **out_added, -struct l_queue **out_updated, -struct l_queue **out_removed) +LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes( +struct l_netconfig *netconfig, +const struct l_queue_entry **out_added, +const struct l_queue_entry **out_updated, +const struct l_queue_entry **out_removed) {if (out_added) - *out_added = netconfig->routes.added; + *out_added =l_queue_get_entries (netconfig->routes.added);if (out_updated) - *out_updated = netconfig->routes.updated; + *out_updated =l_queue_get_entries (netconfig->routes.updated);if (out_removed) - *out_removed = netconfig->routes.removed; + *out_removed =l_queue_get_entries (netconfig->routes.removed); -return netconfig->routes.current; +return l_queue_get_entries (netconfig->routes.current); }
ell/netconfig.h +11 -9
@@ -33,7 +33,7 @@ struct l_dhcp_client;struct l_dhcp6_client ;struct l_icmp6_client ;struct l_netlink ; -struct l_queue ; +struct l_queue_entry ;struct l_netconfig ;struct l_rtnl_address ;struct l_rtnl_route ;
@@ -87,14 +87,16 @@ void l_netconfig_set_event_handler(struct l_netconfig *netconfig,void l_netconfig_apply_rtnl (struct l_netconfig *netconfig,struct l_netlink *rtnl); -struct l_queue *l_netconfig_get_addresses (struct l_netconfig *netconfig, -struct l_queue **out_added, -struct l_queue **out_updated, -struct l_queue **out_removed); -struct l_queue *l_netconfig_get_routes (struct l_netconfig *netconfig, -struct l_queue **out_added, -struct l_queue **out_updated, -struct l_queue **out_removed); +const struct l_queue_entry *l_netconfig_get_addresses ( +struct l_netconfig *netconfig, +const struct l_queue_entry **out_added, +const struct l_queue_entry **out_updated, +const struct l_queue_entry **out_removed); +const struct l_queue_entry *l_netconfig_get_routes ( +struct l_netconfig *netconfig, +const struct l_queue_entry **out_added, +const struct l_queue_entry **out_updated, +const struct l_queue_entry **out_removed); #ifdef __cplusplus }
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 8/13 netconfig: Handle DHCPv6 events
In reply to Andrew ZaborowskiUse l_dhcp6_client to support IPv6 address assignment through DHCPv6.
--- ell/netconfig.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+)
ell/netconfig.c +132 -0
@@ -357,6 +357,135 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client, } } +static void netconfig_add_dhcp6_address (struct l_netconfig *nc) +{ +const struct l_dhcp6_lease *lease = +l_dhcp6_client_get_lease (nc->dhcp6_client); + _auto_(l_free) char *ip = NULL; +uint32_t prefix_len; + +if (L_WARN_ON (!lease)) +return ; + + ip =l_dhcp6_lease_get_address (lease); + prefix_len =l_dhcp6_lease_get_prefix_length (lease); + nc->v6_address =l_rtnl_address_new (ip, prefix_len); + +if (L_WARN_ON (!nc->v6_address)) +return ; + +/* +* Assume we already have a route from a Router Advertisement +* covering the address from DHCPv6 + prefix length from DHCPv6. +* We might want to emit a warning of some sort or +* L_NETCONFIG_EVENT_FAILED if we don't since this would +* basically be fatal for IPv6 connectivity. +*/ +l_rtnl_address_set_noprefixroute (nc->v6_address, true); + +l_queue_push_tail (nc->addresses.current, nc->v6_address); +l_queue_push_tail (nc->addresses.added, nc->v6_address); +} + +static void netconfig_set_dhcp6_address_lifetimes (struct l_netconfig *nc, +bool updated) +{ +const struct l_dhcp6_lease *lease = +l_dhcp6_client_get_lease (nc->dhcp6_client); +uint32_t p, v; +uint64_t start_time; + +if (L_WARN_ON (!lease)) +return ; + + p =l_dhcp6_lease_get_preferred_lifetime (lease); + v =l_dhcp6_lease_get_valid_lifetime (lease); + start_time =l_dhcp6_lease_get_start_time (lease); + +l_rtnl_address_set_lifetimes (nc->v6_address, p, v); +l_rtnl_address_set_expiry (nc->v6_address, + start_time + p *L_USEC_PER_SEC , + start_time + v *L_USEC_PER_SEC ); + +if (updated) +l_queue_push_tail (nc->addresses.updated, nc->v6_address); +} + +static void netconfig_remove_dhcp6_address (struct l_netconfig *nc) +{ +l_queue_remove (nc->addresses.current, nc->v6_address); +l_queue_push_tail (nc->addresses.removed, nc->v6_address); + nc->v6_address =NULL ; +} + +static void netconfig_dhcp6_event_handler (struct l_dhcp6_client *client, +enum l_dhcp6_client_event event, +void *user_data) +{ +struct l_netconfig *nc = user_data; + +switch (event) { +case L_DHCP6_CLIENT_EVENT_LEASE_OBTAINED : +if (L_WARN_ON (nc->v6_configured)) +break ; + +netconfig_add_dhcp6_address (nc); +netconfig_set_dhcp6_address_lifetimes (nc, false); + nc->v6_configured = true; +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_CONFIGURE ); +break ; +case L_DHCP6_CLIENT_EVENT_IP_CHANGED : +if (L_WARN_ON (!nc->v6_configured)) +break ; + +netconfig_remove_dhcp6_address (nc); +netconfig_add_dhcp6_address (nc); +netconfig_set_dhcp6_address_lifetimes (nc, false); +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE ); +break ; +case L_DHCP6_CLIENT_EVENT_LEASE_EXPIRED : +if (L_WARN_ON (!nc->v6_configured)) +break ; + +netconfig_remove_dhcp6_address (nc); + nc->v6_configured = false; + +if (l_dhcp6_client_start (nc->dhcp6_client)) +/* TODO: also start a new timeout */ +netconfig_emit_event (nc,AF_INET6 , +L_NETCONFIG_EVENT_UNCONFIGURE ); +else +netconfig_emit_event (nc,AF_INET6 , +L_NETCONFIG_EVENT_FAILED ); + +break ; +case L_DHCP6_CLIENT_EVENT_LEASE_RENEWED : +if (L_WARN_ON (!nc->v6_configured)) +break ; + +netconfig_set_dhcp6_address_lifetimes (nc, true); +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE ); +break ; +case L_DHCP6_CLIENT_EVENT_NO_LEASE : +if (L_WARN_ON (nc->v6_configured)) +break ; + +/* +* The requested address is no longer available, try to restart +* the client. +* +* TODO: this may need to be delayed so we don't flood the +* network with SOLICITs and DECLINEs. Also add a retry limit +* or better yet a configurable timeout. +*/ +if (!l_dhcp6_client_start (nc->dhcp6_client)) +netconfig_emit_event (nc,AF_INET6 , +L_NETCONFIG_EVENT_FAILED ); + +break ; + } +} + static struct l_rtnl_route *netconfig_find_icmp6_route( struct l_netconfig *nc, const uint8_t *gateway,
@@ -563,6 +692,9 @@ LIB_EXPORT struct l_netconfig *l_netconfig_new(uint32_t ifindex) nc, NULL); nc->dhcp6_client =l_dhcp6_client_new (ifindex); +l_dhcp6_client_set_event_handler (nc->dhcp6_client, + netconfig_dhcp6_event_handler, + nc,NULL ); nc->icmp6_client =l_dhcp6_client_get_icmp6 (nc->dhcp6_client); l_icmp6_client_add_event_handler(nc->icmp6_client,
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 9/13 netconfig: Add getters for DNS addresses and domain names
In reply to Andrew Zaborowski--- ell/ell.sym | 2 ++ ell/netconfig.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ ell/netconfig.h | 2 ++ 3 files changed, 68 insertions(+)
ell/ell.sym +2 -0
@@ -755,6 +755,8 @@ global: l_netconfig_apply_rtnl; l_netconfig_get_addresses; l_netconfig_get_routes; + l_netconfig_get_dns_list; + l_netconfig_get_domain_names; local: *; };
ell/netconfig.c +64 -0
67 lines not on this page · raw message
ell/netconfig.h +2 -0
@@ -97,6 +97,8 @@ const struct l_queue_entry *l_netconfig_get_routes(const struct l_queue_entry **out_added, const struct l_queue_entry **out_updated, const struct l_queue_entry **out_removed); +char **l_netconfig_get_dns_list (struct l_netconfig *netconfig); +char **l_netconfig_get_domain_names (struct l_netconfig *netconfig); #ifdef __cplusplus }
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 10/13 netconfig: Expire addresses and routes
In reply to Andrew ZaborowskiStart differentiating between routes/addresses being removed and those expiring. Generally if we're committing the routes through RTNL, the lifetimes are submitted to the kernel and the kernel should expire them for us on the kernel side. In that case there's no need to send an RTM_DELROUTE/RTM_DELADDR. That should apply to routes received in Router Advertisements as well as addresses and routes from expiring DHCP leases and DHCPv6 leases.
For routes/addresses being removed because a router is going offline and signals that by setting the lifetime to 0 in an RA, or as a result of L_DHCP_CLIENT_EVENT_IP_CHANGED and similar, us or the user do need to send RTM_DELROUTE/RTM_DELADDR. To differentiate between the two cases (removal and expiry) pass two separate lists to the user.
Add checks for expired IPv6 routes in the ICMPv6 event handler to avoid using timers for that. We have no bound on the number of routes (yet) so we avoid keeping potentially many timers or keeping one timer tracking multiple expiry times which would add a little complexity (but might be acceptable.)
--- ell/netconfig.c | 160 ++++++++++++++++++++++++++++++++++++++++++------ ell/netconfig.h | 6 +- 2 files changed, 145 insertions(+), 21 deletions(-)
ell/netconfig.c +141 -19
@@ -69,6 +69,7 @@ struct l_netconfig {bool v6_configured;struct l_icmp6_client *icmp6_client;struct l_dhcp6_client *dhcp6_client; +struct l_idle *signal_expired_work;/* These objects, if not NULL, are owned by @addresses and @routes */ struct l_rtnl_address *v4_address;
@@ -89,10 +90,14 @@ struct l_netconfig {* for example those that only have their lifetime updated. * * Any entries in @added and @updated are owned by @current. +* Entries in @removed need to be removed with an +* RTM_DELADD/RTM_DELROUTE while those in @expired are only +* informative as the kernel will have removed them already. */ struct l_queue *added;struct l_queue *updated;struct l_queue *removed; +struct l_queue *expired; } addresses, routes;struct {
@@ -108,10 +113,14 @@ static void netconfig_update_cleanup(struct l_netconfig *nc)l_queue_clear (nc->addresses.updated,NULL );l_queue_clear (nc->addresses.removed, (l_queue_destroy_func_t ) l_rtnl_address_free); +l_queue_clear (nc->addresses.expired, + (l_queue_destroy_func_t ) l_rtnl_address_free);l_queue_clear (nc->routes.added,NULL );l_queue_clear (nc->routes.updated,NULL );l_queue_clear (nc->routes.removed, (l_queue_destroy_func_t ) l_rtnl_route_free); +l_queue_clear (nc->routes.expired, + (l_queue_destroy_func_t ) l_rtnl_route_free); } static void netconfig_emit_event(struct l_netconfig *nc, uint8_t family,
@@ -128,6 +137,24 @@ static void netconfig_emit_event(struct l_netconfig *nc, uint8_t family,netconfig_update_cleanup (nc); } +static void netconfig_signal_expired (struct l_idle *idle,void *user_data) +{ +struct l_netconfig *nc = user_data; + +l_idle_remove (l_steal_ptr (nc->signal_expired_work)); + +/* +* If the idle work was scheduled from within l_netconfig_get_routes +* or netconfig_icmp6_event_handler, the user is likely to have +* already received an event and had a chance to process the expired +* routes list. In that case there's no need to emit a new event, +* and the list will have been emptied in netconfig_update_cleanup() +* anyway. +*/ +if (!l_queue_isempty (nc->routes.expired)) +netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE ); +} +static void netconfig_add_v4_routes (struct l_netconfig *nc,const char *ip,uint8_t prefix_len,const char *gateway,uint8_t rtm_protocol)
@@ -211,6 +238,11 @@ static void netconfig_add_v6_static_routes(struct l_netconfig *nc,l_queue_push_tail (nc->routes.added, v6_default_route); } +static bool netconfig_match_ptr (const void *a,const void *b) +{ +return a == b; +} +static void netconfig_add_dhcp_address_routes (struct l_netconfig *nc) { const struct l_dhcp_lease *lease =
@@ -254,13 +286,15 @@ static void netconfig_set_dhcp_lifetimes(struct l_netconfig *nc, bool updated)l_rtnl_address_set_lifetimes (nc->v4_address,0 , lifetime);l_rtnl_address_set_expiry (nc->v4_address,0 , expiry); -if (updated) +if (updated && !l_queue_find (nc->addresses.added, netconfig_match_ptr, + nc->v4_address))l_queue_push_tail (nc->addresses.updated, nc->v4_address);l_rtnl_route_set_lifetime (nc->v4_subnet_route, lifetime);l_rtnl_route_set_expiry (nc->v4_subnet_route, expiry); -if (updated) +if (updated && !l_queue_find (nc->routes.added, netconfig_match_ptr, + nc->v4_subnet_route))l_queue_push_tail (nc->routes.updated, nc->v4_subnet_route);if (!nc->v4_default_route)
@@ -269,23 +303,42 @@ static void netconfig_set_dhcp_lifetimes(struct l_netconfig *nc, bool updated)l_rtnl_route_set_lifetime (nc->v4_default_route, lifetime);l_rtnl_route_set_expiry (nc->v4_default_route, expiry); -if (updated) +if (updated && !l_queue_find (nc->routes.added, netconfig_match_ptr, + nc->v4_default_route))l_queue_push_tail (nc->routes.updated, nc->v4_default_route); } -static void netconfig_remove_dhcp_address_routes (struct l_netconfig *nc) +static void netconfig_remove_dhcp_address_routes (struct l_netconfig *nc, +bool expired) { +struct l_queue *routes = + expired ? nc->routes.expired : nc->routes.removed; +l_queue_remove (nc->addresses.current, nc->v4_address); -l_queue_push_tail (nc->addresses.removed, nc->v4_address); +l_queue_remove (nc->addresses.updated, nc->v4_address); + +if (!l_queue_remove (nc->addresses.added, nc->v4_address)) +l_queue_push_tail ( + expired ? nc->addresses.expired : nc->addresses.removed, + nc->v4_address); + nc->v4_address =NULL ;l_queue_remove (nc->routes.current, nc->v4_subnet_route); -l_queue_push_tail (nc->routes.removed, nc->v4_subnet_route); +l_queue_remove (nc->routes.updated, nc->v4_subnet_route); + +if (!l_queue_remove (nc->routes.added, nc->v4_subnet_route)) +l_queue_push_tail (routes, nc->v4_subnet_route); + nc->v4_subnet_route =NULL ;if (nc->v4_default_route) {l_queue_remove (nc->routes.current, nc->v4_default_route); -l_queue_push_tail (nc->routes.removed, nc->v4_default_route); +l_queue_remove (nc->routes.updated, nc->v4_default_route); + +if (!l_queue_remove (nc->routes.added, nc->v4_default_route)) +l_queue_push_tail (routes, nc->v4_default_route); + nc->v4_default_route =NULL ; } }
@@ -301,7 +354,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,if (L_WARN_ON (!nc->v4_configured))break ; -netconfig_remove_dhcp_address_routes (nc); +netconfig_remove_dhcp_address_routes (nc, false);netconfig_add_dhcp_address_routes (nc);netconfig_set_dhcp_lifetimes (nc, false);netconfig_emit_event (nc,AF_INET ,L_NETCONFIG_EVENT_UPDATE );
@@ -326,7 +379,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,if (L_WARN_ON (!nc->v4_configured))break ; -netconfig_remove_dhcp_address_routes (nc); +netconfig_remove_dhcp_address_routes (nc, true); nc->v4_configured = false;if (l_dhcp_client_start (nc->dhcp_client))
@@ -407,14 +460,21 @@ static void netconfig_set_dhcp6_address_lifetimes(struct l_netconfig *nc, start_time + p *L_USEC_PER_SEC , start_time + v * L_USEC_PER_SEC); -if (updated) +if (updated && !l_queue_find (nc->addresses.added, netconfig_match_ptr, + nc->v6_address))l_queue_push_tail (nc->addresses.updated, nc->v6_address); } -static void netconfig_remove_dhcp6_address (struct l_netconfig *nc) +static void netconfig_remove_dhcp6_address (struct l_netconfig *nc,bool expired) {l_queue_remove (nc->addresses.current, nc->v6_address); -l_queue_push_tail (nc->addresses.removed, nc->v6_address); +l_queue_remove (nc->addresses.updated, nc->v6_address); + +if (!l_queue_remove (nc->addresses.added, nc->v6_address)) +l_queue_push_tail ( + expired ? nc->addresses.expired : nc->addresses.removed, + nc->v6_address); + nc->v6_address =NULL ; }
@@ -438,7 +498,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,if (L_WARN_ON (!nc->v6_configured))break ; -netconfig_remove_dhcp6_address (nc); +netconfig_remove_dhcp6_address (nc, false);netconfig_add_dhcp6_address (nc);netconfig_set_dhcp6_address_lifetimes (nc, false);netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE );
@@ -447,7 +507,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,if (L_WARN_ON (!nc->v6_configured))break ; -netconfig_remove_dhcp6_address (nc); +netconfig_remove_dhcp6_address (nc, true); nc->v6_configured = false;if (l_dhcp6_client_start (nc->dhcp6_client))
@@ -486,6 +546,49 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client, } } +static uint64_t now; + +static bool netconfig_check_route_expired (void *data,void *user_data) +{ +struct l_netconfig *nc = user_data; +struct l_rtnl_route *route = data; +uint64_t expiry_time =l_rtnl_route_get_expiry (route); + +if (!expiry_time || now < expiry_time) +return false; + +/* +* Since we set lifetimes on the routes we submit to the kernel with +* RTM_NEWROUTE, we count on them being deleted automatically so no +* need to send an RTM_DELROUTE. We signal the fact that the route +* expired to the user by having it on the expired list but there's +* nothing that the user needs to do with the routes on that list +* like they do with the added, updated and removed lists. +* +* If for some reason the route is still on the added list, drop it +* from there and there's nothing to notify the user of. +*/ +if (!l_queue_remove (nc->routes.added, route)) +l_queue_push_tail (nc->routes.expired, route); + +l_queue_remove (nc->routes.updated, route); +l_queue_remove (nc->routes.removed, route); +return true; +} + +static void netconfig_expire_routes (struct l_netconfig *nc) +{ + now =l_time_now (); + +if (l_queue_foreach_remove (nc->routes.current, + netconfig_check_route_expired, nc) && + !l_queue_isempty (nc->routes.expired) && + !nc->signal_expired_work) + nc->signal_expired_work =l_idle_create ( + netconfig_signal_expired, + nc,NULL ); +} + static struct l_rtnl_route *netconfig_find_icmp6_route( struct l_netconfig *nc, const uint8_t *gateway,
@@ -573,7 +676,7 @@ static void netconfig_set_icmp6_route_data(struct l_netconfig *nc,l_rtnl_route_set_lifetime (rt, valid_lifetime);l_rtnl_route_set_expiry (rt, expiry); -if (updated) +if (updated && !l_queue_find (nc->routes.added, netconfig_match_ptr, rt))l_queue_push_tail (nc->routes.updated, rt); }
@@ -581,7 +684,10 @@ static void netconfig_remove_icmp6_route(struct l_netconfig *nc, struct l_rtnl_route *route) {l_queue_remove (nc->routes.current, route); -l_queue_push_tail (nc->routes.removed, route); +l_queue_remove (nc->routes.updated, route); + +if (!l_queue_remove (nc->routes.added, route)) +l_queue_push_tail (nc->routes.removed, route); } static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
@@ -608,6 +714,8 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,if (nc->v4_gateway_override)return ; +netconfig_expire_routes (nc); +/* Process the default gateway information */ default_route =netconfig_find_icmp6_route (nc, r->address,NULL );
@@ -665,7 +773,8 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,*/ if (!l_queue_isempty (nc->routes.added) || !l_queue_isempty (nc->routes.updated) || - !l_queue_isempty (nc->routes.removed)) + !l_queue_isempty (nc->routes.removed) || + !l_queue_isempty (nc->routes.expired))netconfig_emit_event (nc,AF_INET6 ,L_NETCONFIG_EVENT_UPDATE ); }
@@ -1134,6 +1243,9 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig)if (netconfig->do_static_work)l_idle_remove (l_steal_ptr (netconfig->do_static_work)); +if (netconfig->signal_expired_work) +l_idle_remove (l_steal_ptr (netconfig->signal_expired_work)); +netconfig_update_cleanup (netconfig);l_queue_clear (netconfig->routes.current, (l_queue_destroy_func_t ) l_rtnl_route_free);
@@ -1233,7 +1345,8 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_addresses(struct l_netconfig *netconfig, const struct l_queue_entry **out_added, const struct l_queue_entry **out_updated, - const struct l_queue_entry **out_removed) + const struct l_queue_entry **out_removed, + const struct l_queue_entry **out_expired) { if (out_added) *out_added =l_queue_get_entries (netconfig->addresses.added);
@@ -1244,6 +1357,9 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_addresses(if (out_removed) *out_removed =l_queue_get_entries (netconfig->addresses.removed); +if (out_expired) + *out_expired =l_queue_get_entries (netconfig->addresses.expired); +return l_queue_get_entries (netconfig->addresses.current); }
@@ -1251,8 +1367,11 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(struct l_netconfig *netconfig, const struct l_queue_entry **out_added, const struct l_queue_entry **out_updated, - const struct l_queue_entry **out_removed) + const struct l_queue_entry **out_removed, + const struct l_queue_entry **out_expired) { +netconfig_expire_routes (netconfig ); +if (out_added) *out_added =l_queue_get_entries (netconfig->routes.added);
@@ -1262,6 +1381,9 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(if (out_removed) *out_removed =l_queue_get_entries (netconfig->routes.removed); +if (out_expired) + *out_expired =l_queue_get_entries (netconfig->routes.expired); +return l_queue_get_entries (netconfig->routes.current); }
ell/netconfig.h +4 -2
@@ -91,12 +91,14 @@ const struct l_queue_entry *l_netconfig_get_addresses(struct l_netconfig *netconfig, const struct l_queue_entry **out_added, const struct l_queue_entry **out_updated, - const struct l_queue_entry **out_removed); + const struct l_queue_entry **out_removed, + const struct l_queue_entry **out_expired);const struct l_queue_entry *l_netconfig_get_routes (struct l_netconfig *netconfig,const struct l_queue_entry **out_added,const struct l_queue_entry **out_updated, -const struct l_queue_entry **out_removed); +const struct l_queue_entry **out_removed, +const struct l_queue_entry **out_expired);char **l_netconfig_get_dns_list (struct l_netconfig *netconfig);char **l_netconfig_get_domain_names (struct l_netconfig *netconfig);
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 11/13 examples: Update l_netconfig_get_{addresses, routes} calls
In reply to Andrew Zaborowski--- examples/netconfig-test.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
examples/netconfig-test.c +19 -17
@@ -61,16 +61,14 @@ static void signal_handler(uint32_t signo, void *user_data) }static void log_addresses (const char *af_str,const char *action, -struct l_queue *list) +const struct l_queue_entry *entry) { -const struct l_queue_entry *entry; - -if (l_queue_isempty (list)) +if (!entry)return ;l_info ("[netconfig%s] Addresses %s:" , af_str, action); -for (entry =l_queue_get_entries (list); entry; entry = entry->next) { +for (; entry; entry = entry->next) {struct l_rtnl_address *addr = entry->data;char ip_str[INET6_ADDRSTRLEN ];
@@ -83,25 +81,26 @@ static void log_addresses(const char *af_str, const char *action, }static void log_routes (const char *af_str,const char *action, -struct l_queue *list) +const struct l_queue_entry *entry) { -const struct l_queue_entry *entry; - -if (l_queue_isempty (list)) +if (!entry)return ;l_info ("[netconfig%s] Routes %s:" , af_str, action); -for (entry =l_queue_get_entries (list); entry; entry = entry->next) { +for (; entry; entry = entry->next) {struct l_rtnl_route *rt = entry->data; -char subnet_str[INET6_ADDRSTRLEN ]; +char subnet_str[INET6_ADDRSTRLEN ] ="unknown" ;char gateway_str[INET6_ADDRSTRLEN ];uint8_t prefix_len; +bool onlink;l_rtnl_route_get_dst (rt, subnet_str, &prefix_len); -l_rtnl_route_get_gateway (rt, gateway_str); -l_info ("[netconfig%s] \t%s/%i, gateway %s, orig lifetime %i s" , - af_str, subnet_str, prefix_len, gateway_str, + onlink = !l_rtnl_route_get_gateway (rt, gateway_str); +l_info ("[netconfig%s] \t%s/%i, %s%s, orig lifetime %i s" , + af_str, subnet_str, prefix_len, + onlink ?"onlink" :"next-hop " , + onlink ?"" : gateway_str,l_rtnl_route_get_lifetime (rt)); } }
@@ -110,7 +109,7 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family, enum l_netconfig_event event, void *user_data) { const char *af_str = family == AF_INET ? "v4" : "v6"; -struct l_queue *added, *updated, *removed; +const struct l_queue_entry *added, *updated, *removed, *expired;switch (event) {case L_NETCONFIG_EVENT_CONFIGURE :
@@ -128,15 +127,18 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,return ; } -l_netconfig_get_addresses (netconfig, &added, &updated, &removed); +l_netconfig_get_addresses (netconfig, &added, &updated, + &removed, &expired);log_addresses (af_str,"added" , added);log_addresses (af_str,"updated" , updated);log_addresses (af_str,"removed" , removed); +log_addresses (af_str,"expired" , expired); -l_netconfig_get_routes (netconfig, &added, &updated, &removed); +l_netconfig_get_routes (netconfig, &added, &updated, &removed, &expired);log_routes (af_str,"added" , added);log_routes (af_str,"updated" , updated);log_routes (af_str,"removed" , removed); +log_routes (af_str,"expired" , expired);if (apply)l_netconfig_apply_rtnl (netconfig, rtnl);
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 12/13 rtnl: Fix l_rtnl_route_get_protocol
In reply to Andrew Zaborowski--- ell/rtnl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ell/rtnl.c +1 -1
@@ -651,7 +651,7 @@ LIB_EXPORT uint8_t l_rtnl_route_get_protocol(const struct l_rtnl_route *rt)if (unlikely (!rt))return RTPROT_UNSPEC ; -return rt->scope; +return rt->protocol; } LIB_EXPORT bool l_rtnl_route_set_protocol(struct l_rtnl_route *rt,
Signature · 1 line
2.32.0
Denis Kenzior
AppliedRe: [PATCH 12/13] rtnl: Fix l_rtnl_route_get_protocol
Hi Andrew,
Quoted 4 lines · Andrew Zaborowski
--- ell/rtnl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks.
Regards,
-Denis
Andrew Zaborowski
PATCH 13/13 icmp6, dhcp6, dhcp: Ensure buffer space for SCM_TIMESTAMP
In reply to Andrew ZaborowskiApparently the kernel will include message ancillary elements like SCM_TIMESTAMP even if there isn't enough space for the entire element. Reserve enough buffer space and check we received the whole SCM_TIMESTAMP element.
--- ell/dhcp-transport.c | 6 ++++-- ell/dhcp6-transport.c | 8 +++++--- ell/icmp6.c | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-)
ell/dhcp-transport.c +4 -2
@@ -117,7 +117,7 @@ static bool _dhcp_default_transport_read_handler(struct l_io *io,struct cmsghdr *cmsg;struct iovec iov = { .iov_base = buf, .iov_len =sizeof (buf) };struct msghdr msg = {}; -unsigned char control[32 ]; +unsigned char control[32 +CMSG_SPACE (sizeof (struct timeval ))]; msg.msg_name = &saddr; msg.msg_namelen =sizeof (saddr);
@@ -165,7 +165,9 @@ static bool _dhcp_default_transport_read_handler(struct l_io *io,for (cmsg =CMSG_FIRSTHDR (&msg); cmsg !=NULL ; cmsg =CMSG_NXTHDR (&msg, cmsg)) {if (cmsg->cmsg_level ==SOL_SOCKET && - cmsg->cmsg_type ==SCM_TIMESTAMP ) { + cmsg->cmsg_type ==SCM_TIMESTAMP && + cmsg->cmsg_len == +CMSG_LEN (sizeof (struct timeval ))) {const struct timeval *tv = (void *)CMSG_DATA (cmsg); timestamp = tv->tv_sec *L_USEC_PER_SEC + tv->tv_usec;
ell/dhcp6-transport.c +5 -3
@@ -61,7 +61,7 @@ static bool _dhcp6_default_transport_read_handler(struct l_io *io,struct cmsghdr *cmsg;struct iovec iov = { .iov_base = buf, .iov_len =sizeof (buf) };struct msghdr msg = {}; -unsigned char control[32 ]; +unsigned char control[32 +CMSG_SPACE (sizeof (struct timeval ))]; msg.msg_iov = &iov; msg.msg_iovlen =1 ;
@@ -78,8 +78,10 @@ static bool _dhcp6_default_transport_read_handler(struct l_io *io,for (cmsg =CMSG_FIRSTHDR (&msg); cmsg !=NULL ; cmsg =CMSG_NXTHDR (&msg, cmsg)) {if (cmsg->cmsg_level ==SOL_SOCKET && - cmsg->cmsg_type ==SCM_TIMESTAMP ) { -const struct timeval *tv = (void *)CMSG_DATA (cmsg); + cmsg->cmsg_type ==SCM_TIMESTAMP && + cmsg->cmsg_len == +CMSG_LEN (sizeof (struct timeval ))) { +const struct timeval *tv = (void *)CMSG_DATA (cmsg); timestamp = tv->tv_sec *L_USEC_PER_SEC + tv->tv_usec; }
ell/icmp6.c +5 -2
@@ -203,7 +203,8 @@ static int icmp6_send_router_solicitation(int s, const uint8_t mac[static 6])static int icmp6_receive (int s,void *buf,size_t buf_len,struct in6_addr *src,uint64_t *out_timestamp) { -char c_msg_buf[CMSG_SPACE (sizeof (int ))]; +char c_msg_buf[CMSG_SPACE (sizeof (int )) + +CMSG_SPACE (sizeof (struct timeval ))];struct iovec iov = { .iov_base = buf, .iov_len = buf_len,
@@ -242,7 +243,9 @@ static int icmp6_receive(int s, void *buf, size_t buf_len, struct in6_addr *src,if (hops !=255 )return -EMULTIHOP ; }else if (cmsg->cmsg_level ==SOL_SOCKET && - cmsg->cmsg_type ==SCM_TIMESTAMP ) { + cmsg->cmsg_type ==SCM_TIMESTAMP && + cmsg->cmsg_len == +CMSG_LEN (sizeof (struct timeval ))) {const struct timeval *tv = (void *)CMSG_DATA (cmsg); timestamp = tv->tv_sec *L_USEC_PER_SEC + tv->tv_usec;
Signature · 1 line
2.32.0
Denis Kenzior
AppliedRe: [PATCH 13/13] icmp6,dhcp6,dhcp: Ensure buffer space for SCM_TIMESTAMP
Hi Andrew,
Quoted 5 lines · Andrew Zaborowski
Apparently the kernel will include message ancillary elements like
SCM_TIMESTAMPeven if there isn't enough space for the entire element. Reserve enough buffer space and check we received the wholeSCM_TIMESTAMPelement.
Quoted 9 lines
Fixes adf18f2bae67 ("icmp6: Use SO_TIMESTAMP")Fixes cd678415a75c ("dhcp6: Set lease expiry based on frame reception times")Fixes c78ad1bb6d7e ("dhcp: Set lease expiry based on frame reception times")--- ell/dhcp-transport.c | 6 ++++-- ell/dhcp6-transport.c | 8 +++++--- ell/icmp6.c | 7 +++++-- 3 files changed, 14 insertions(+), 7 deletions(-)
Applied, thanks.
Regards,
-Denis
Denis Kenzior
AppliedHi Andrew,
Quoted 4 lines · Andrew Zaborowski
--- ell/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks.
Regards,
-Denis