rtnl: Track expiry times instead of lifetimes
Andrew Zaborowski
PATCH 1/6 rtnl: Track expiry times instead of lifetimes
Internally within rtnl.c store expiry times of addresses and routes instead of their lifetime periods so that at any time the current lifetime left can be returned. This is an incompatible API change to the lifetime getters and setters as they now take a reference_time parameter, which in the setter case should normally be the timestamp of when the address or route was received from DHCP. These setters and getters don't seem to have been used outside of ell.
--- ell/dhcp.c | 3 ++- ell/dhcp6.c | 3 ++- ell/rtnl.c | 71 ++++++++++++++++++++++++++++++++++------------------- ell/rtnl.h | 15 +++++++---- 4 files changed, 60 insertions(+), 32 deletions(-)
ell/dhcp.c +2 -1
@@ -680,6 +680,7 @@ static int dhcp_client_receive_ack(struct l_dhcp_client *client,struct dhcp_message_iter iter;struct l_dhcp_lease *lease;int r; +uint64_t now =l_time_now ();CLIENT_DEBUG ("" );
@@ -734,7 +735,7 @@ static int dhcp_client_receive_ack(struct l_dhcp_client *client, a =l_rtnl_address_new (ip, prefix_len);l_rtnl_address_set_noprefixroute (a, true); -l_rtnl_address_set_lifetimes (a, l, l); +l_rtnl_address_set_lifetimes (a, l, l, now);l_rtnl_address_set_broadcast (a, broadcast); client->rtnl_add_cmdid =
ell/dhcp6.c +2 -1
@@ -967,6 +967,7 @@ static void dhcp6_client_setup_lease(struct l_dhcp6_client *client)uint32_t t1 =_dhcp6_lease_get_t1 (client->lease);uint32_t t2 =_dhcp6_lease_get_t2 (client->lease);enum l_dhcp6_client_event event; +uint64_t now =l_time_now (); client->lease_start_t =l_time_now ();
@@ -1007,7 +1008,7 @@ static void dhcp6_client_setup_lease(struct l_dhcp6_client *client) a =l_rtnl_address_new (ip, prefix_len);l_rtnl_address_set_noprefixroute (a, true); -l_rtnl_address_set_lifetimes (a, p, v); +l_rtnl_address_set_lifetimes (a, p, v, now); client->rtnl_add_cmdid = l_rtnl_ifaddr_add(client->rtnl, client->ifindex, a,
ell/rtnl.c +46 -25
175 lines not on this page · raw message
ell/rtnl.h +10 -5
@@ -54,12 +54,15 @@ const char *l_rtnl_address_get_label(const struct l_rtnl_address *addr);bool l_rtnl_address_set_label (struct l_rtnl_address *addr,const char *label);bool l_rtnl_address_set_noprefixroute (struct l_rtnl_address *addr,bool noprefixroute); -uint32_t l_rtnl_address_get_valid_lifetime (const struct l_rtnl_address *addr); +uint32_t l_rtnl_address_get_valid_lifetime (const struct l_rtnl_address *addr, +uint64_t reference_time);uint32_t l_rtnl_address_get_preferred_lifetime ( -const struct l_rtnl_address *addr); +const struct l_rtnl_address *addr, +uint64_t reference_time);bool l_rtnl_address_set_lifetimes (struct l_rtnl_address *addr,uint32_t preferred_lifetime, -uint32_t valid_lifetime); +uint32_t valid_lifetime, +uint64_t reference_time);bool l_rtnl_address_set_scope (struct l_rtnl_address *addr,uint8_t scope);struct l_rtnl_route *l_rtnl_route_new_gateway (const char *gw);
@@ -69,8 +72,10 @@ void l_rtnl_route_free(struct l_rtnl_route *rt);DEFINE_CLEANUP_FUNC (l_rtnl_route_free);uint8_t l_rtnl_route_get_family (const struct l_rtnl_route *rt);bool l_rtnl_route_get_gateway (const struct l_rtnl_route *rt,char *out_buf); -uint32_t l_rtnl_route_get_lifetime (const struct l_rtnl_route *rt); -bool l_rtnl_route_set_lifetime (struct l_rtnl_route *rt,uint32_t lt); +uint32_t l_rtnl_route_get_lifetime (const struct l_rtnl_route *rt, +uint64_t reference_time); +bool l_rtnl_route_set_lifetime (struct l_rtnl_route *rt,uint32_t lt, +uint64_t reference_time);uint32_t l_rtnl_route_get_mtu (const struct l_rtnl_route *rt);bool l_rtnl_route_set_mtu (struct l_rtnl_route *rt,uint32_t mtu);uint8_t l_rtnl_route_get_preference (const struct l_rtnl_route *rt);
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 2/6 rtnl: Add l_rtnl_route_get_dst
--- ell/ell.sym | 1 + ell/rtnl.c | 14 ++++++++++++++ ell/rtnl.h | 2 ++ 3 files changed, 17 insertions(+)
ell/ell.sym +1 -0
@@ -634,6 +634,7 @@ global: l_rtnl_route_free; l_rtnl_route_get_family; l_rtnl_route_get_gateway; + l_rtnl_route_get_dst; l_rtnl_route_get_lifetime; l_rtnl_route_set_lifetime; l_rtnl_route_get_mtu;
ell/rtnl.c +14 -0
@@ -410,6 +410,20 @@ LIB_EXPORT bool l_rtnl_route_get_gateway(const struct l_rtnl_route *rt, out_buf); } +LIB_EXPORT bool l_rtnl_route_get_dst(const struct l_rtnl_route *rt, char *out_buf, +uint8_t *out_prefix_len) +{ +if (unlikely (!rt)) +return false; + +if (address_to_string (rt->family, &rt->dst.in_addr, &rt->dst.in6_addr, + out_buf) !=0 ) +return false; + + *out_prefix_len = rt->dst_prefix_len; +return true; +} + LIB_EXPORT uint32_t l_rtnl_route_get_lifetime(const struct l_rtnl_route *rt,uint64_t reference_time) {
ell/rtnl.h +2 -0
@@ -72,6 +72,8 @@ void l_rtnl_route_free(struct l_rtnl_route *rt);DEFINE_CLEANUP_FUNC (l_rtnl_route_free);uint8_t l_rtnl_route_get_family (const struct l_rtnl_route *rt);bool l_rtnl_route_get_gateway (const struct l_rtnl_route *rt,char *out_buf); +bool l_rtnl_route_get_dst (const struct l_rtnl_route *rt,char *out_buf, +uint8_t *out_prefix_len);uint32_t l_rtnl_route_get_lifetime (const struct l_rtnl_route *rt,uint64_t reference_time); bool l_rtnl_route_set_lifetime(struct l_rtnl_route *rt, uint32_t lt,
Signature · 1 line
2.32.0
Denis Kenzior
Re: [PATCH 2/6] rtnl: Add l_rtnl_route_get_dst
Hi Andrew,
Quoted 5 lines · Andrew Zaborowski
--- ell/ell.sym | 1 + ell/rtnl.c | 14 ++++++++++++++ ell/rtnl.h | 2 ++ 3 files changed, 17 insertions(+)
I went ahead and applied this patch after some formatting changes. Also patch 3.
Regards,
-Denis
Andrew Zaborowski
PATCH 3/6 rtnl: Fix a return line in address_to_string
In reply to Andrew Zaborowski--- ell/rtnl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ell/rtnl.c +1 -1
@@ -71,7 +71,7 @@ static inline int address_to_string(int family, const struct in_addr *v4,return -errno;break ;default : -return false; +return -EAFNOSUPPORT ; }return 0 ;
Signature · 1 line
2.32.0
Andrew Zaborowski
PATCH 4/6 netconfig: Add netconfig API
In reply to Andrew ZaborowskiThis adds the netconfig class that will encapsulate static IP configuration, DHCP, DHCP6, ICMP6, SLAAC logic and free the user of manually handling DHCP/DHCP6 events to implement netconfig policies. The user will still need to handle committing received DNS and mdns information.
In this patch only IPv4 DHCP is implemented and no configurable settings are added.
When events are emitted for address and/or route changes, the changes are split into "added", "updated" and "removed" lists so that the user can decide apply those changes without first removing all addresses and routes from the interface and the re-adding the complete new list. They can also decide to let another entity apply the changes.
--- Makefile.am | 6 +- ell/ell.h | 1 + ell/ell.sym | 8 ++ ell/netconfig.c | 375 ++++++++++++++++++++++++++++++++++++++++++++++++ ell/netconfig.h | 73 ++++++++++ 5 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 ell/netconfig.c create mode 100644 ell/netconfig.h
Makefile.am +4 -2
@@ -60,7 +60,8 @@ pkginclude_HEADERS = ell/ell.h \ ell/icmp6.h \ ell/acd.h \ ell/tester.h \ - ell/cleanup.h + ell/cleanup.h \ + ell/netconfig.h lib_LTLIBRARIES = ell/libell.la
@@ -146,7 +147,8 @@ ell_libell_la_SOURCES = $(linux_headers) \ ell/icmp6.c \ ell/icmp6-private.h \ ell/acd.c \ - ell/tester.c + ell/tester.c \ + ell/netconfig.c ell_libell_la_LDFLAGS = -Wl,--no-undefined \ -Wl,--version-script=$(top_srcdir)/ell/ell.sym \
ell/ell.h +1 -0
@@ -65,3 +65,4 @@#include <ell/path.h> #include <ell/acd.h> #include <ell/tester.h> +#include <ell/netconfig.h>
ell/ell.sym +8 -0
@@ -720,6 +720,14 @@ global: l_tester_post_teardown_complete; l_tester_post_teardown_failed; l_tester_wait; + /* netconfig */ + l_netconfig_new; + l_netconfig_destroy; + l_netconfig_set_route_priority; + l_netconfig_start; + l_netconfig_stop; + l_netconfig_get_dhcp_client; + l_netconfig_set_event_handler; local: *; };
ell/netconfig.c new file +375 -0
375 lines not on this page · raw message
ell/netconfig.h new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.32.0
Denis Kenzior
Re: [PATCH 4/6] netconfig: Add netconfig API
Hi Andrew,
Quoted 21 lines · Andrew Zaborowski
This adds the netconfig class that will encapsulate static IP configuration, DHCP, DHCP6, ICMP6, SLAAC logic and free the user of manually handling DHCP/DHCP6 events to implement netconfig policies. The user will still need to handle committing received DNS and mdns information.
In this patch only IPv4 DHCP is implemented and no configurable settings are added.
When events are emitted for address and/or route changes, the changes are split into "added", "updated" and "removed" lists so that the user can decide apply those changes without first removing all addresses and routes from the interface and the re-adding the complete new list. They can also decide to let another entity apply the changes.
--- Makefile.am | 6 +- ell/ell.h | 1 + ell/ell.sym | 8 ++ ell/netconfig.c | 375 ++++++++++++++++++++++++++++++++++++++++++++++++ ell/netconfig.h | 73 ++++++++++ 5 files changed, 461 insertions(+), 2 deletions(-)
Quoted 3 lines
create mode 100644
ell/netconfig.c
create mode 100644ell/netconfig.h
I have no real comments here. This seems like the right approach.
Regards,
-Denis
Andrew Zaborowski
PATCH 5/6 netconfig: Add l_netconfig_apply_rtnl
In reply to Andrew ZaborowskiAdd l_netconfig_apply_rtnl and the getters for current lists of routes and addresses for the netconfig user to be able to commit address and route changes.
--- ell/ell.sym | 3 ++ ell/netconfig.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ ell/netconfig.h | 11 ++++++++ 3 files changed, 87 insertions(+)
ell/ell.sym +3 -0
@@ -728,6 +728,9 @@ global: l_netconfig_stop; l_netconfig_get_dhcp_client; l_netconfig_set_event_handler; + l_netconfig_apply_rtnl; + l_netconfig_get_addresses; + l_netconfig_get_routes; local: *; };
ell/netconfig.c +73 -0
76 lines not on this page · raw message
ell/netconfig.h +11 -0
@@ -66,6 +66,17 @@ void l_netconfig_set_event_handler(struct l_netconfig *netconfig,void *user_data, l_netconfig_destroy_cb_t destroy); +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); + #ifdef __cplusplus }#endif
Signature · 1 line
2.32.0
Denis Kenzior
Re: [PATCH 5/6] netconfig: Add l_netconfig_apply_rtnl
Hi Andrew,
Quoted 9 lines · Andrew Zaborowski
Add
l_netconfig_apply_rtnland the getters for current lists of routes and addresses for the netconfig user to be able to commit address and route changes.--- ell/ell.sym | 3 ++ ell/netconfig.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ ell/netconfig.h | 11 ++++++++ 3 files changed, 87 insertions(+)
<snip>
ell/netconfig.h void l_netconfig_set_event_handler(struct l_netconfig *netconfig, · line 79
Quoted 12 lines
ell/netconfig.h +11
-0+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); +
I wonder if we can use const l_queue_entry * instead. Or maybe some sort of iterator concept? Returning a pointer to the internal data structure is something we should only do as a last resort.
Regards,
-Denis
Andrew Zaborowski
Re: [PATCH 5/6] netconfig: Add l_netconfig_apply_rtnl
Quoted 14 lines · Denis Kenzior
Quoted 9 lines · Andrew Zaborowski
Add
l_netconfig_apply_rtnland the getters for current lists of routes and addresses for the netconfig user to be able to commit address and route changes.--- ell/ell.sym | 3 ++ ell/netconfig.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ ell/netconfig.h | 11 ++++++++ 3 files changed, 87 insertions(+)<snip>
Quoted 1 line
Quoted 15 lines
ell/netconfig.h void l_netconfig_set_event_handler(struct l_netconfig *netconfig, · line 79
Quoted 11 lines
ell/netconfig.h +11
-0+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); +I wonder if we can use const
l_queue_entry* instead. Or maybe some sort of iterator concept? Returning a pointer to the internal data structure is something we should only do as a last resort.
"const l_queue_entry *" would work. We can also just transfer the ownership of those three lists to the caller and drop our references to those three lists when we return them. They're actually temporary, I just used l_queue_clear instead of destroying and recreating them.
Best regards
Andrew Zaborowski
Re: [PATCH 5/6] netconfig: Add l_netconfig_apply_rtnl
Quoted 31 lines · Andrew Zaborowski
Quoted 14 lines · Denis Kenzior
Quoted 9 lines · Andrew Zaborowski
Add
l_netconfig_apply_rtnland the getters for current lists of routes and addresses for the netconfig user to be able to commit address and route changes.--- ell/ell.sym | 3 ++ ell/netconfig.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ ell/netconfig.h | 11 ++++++++ 3 files changed, 87 insertions(+)<snip>
Quoted 1 line
Quoted 15 lines
ell/netconfig.h void l_netconfig_set_event_handler(struct l_netconfig *netconfig, · line 79
Quoted 11 lines
ell/netconfig.h +11
-0+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); +I wonder if we can use const
l_queue_entry* instead. Or maybe some sort of iterator concept? Returning a pointer to the internal data structure is something we should only do as a last resort.
Quoted 4 lines
"const
l_queue_entry*" would work. We can also just transfer the ownership of those three lists to the caller and drop our references to those three lists when we return them. They're actually temporary, I just usedl_queue_clearinstead of destroying and recreating them.
(This doesn't apply to the complete list of addresses/routes that we also return, you're right that we'd need to return an iterator. struct l_queue_entry is pretty much an iterator except that the .next/.data members are public)
Best regards
Denis Kenzior
Re: [PATCH 5/6] netconfig: Add l_netconfig_apply_rtnl
Hi Andrew,
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
I wonder if we can use const
l_queue_entry* instead. Or maybe some sort of iterator concept? Returning a pointer to the internal data structure is something we should only do as a last resort."const
l_queue_entry*" would work. We can also just transfer the ownership of those three lists to the caller and drop our references to those three lists when we return them. They're actually temporary, I just usedl_queue_clearinstead of destroying and recreating them.
Quoted 5 lines
(This doesn't apply to the complete list of addresses/routes that we also return, you're right that we'd need to return an iterator. struct
l_queue_entryis pretty much an iterator except that the .next/.data members are public)
Okay. See what you can come up with. If l_queue_entry works, that would likely be the easiest approach.
Regards,
-Denis
Andrew Zaborowski
PATCH 6/6 examples: Add a netconfig API example/test utility
In reply to Andrew ZaborowskiA test utility that simply starts netconfig on a given interface and prints events that occur. DNS/mdns changes aren't committed to the system.
--- Makefile.am | 4 +- examples/netconfig-test.c | 210 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 examples/netconfig-test.c
Makefile.am +3 -1
@@ -347,7 +347,8 @@ unit_test_data_files = unit/settings.test unit/dbus.conf examples = examples/dbus-service examples/https-client-test \ examples/https-server-test examples/dbus-client \ examples/dhcp-client examples/dhcp6-client \ - examples/dhcp-server examples/acd-client + examples/dhcp-server examples/acd-client \ + examples/netconfig-test if GLIB examples += examples/glib-eventloop
@@ -367,6 +368,7 @@ examples_dhcp_client_LDADD = ell/libell-private.la examples_dhcp6_client_LDADD = ell/libell-private.la examples_dhcp_server_LDADD = ell/libell-private.la examples_acd_client_LDADD = ell/libell-private.la +examples_netconfig_test_LDADD = ell/libell-private.la noinst_PROGRAMS += tools/certchain-verify tools/genl-discover \ tools/genl-watch tools/genl-request tools/gpio
examples/netconfig-test.c new file +210 -0
210 lines not on this page · raw message
Signature · 1 line
2.32.0
Denis Kenzior
Hi Andrew,
Quoted 2 lines · Andrew Zaborowski
Internally within
rtnl.cstore expiry times of addresses and routes instead of their lifetime periods so that at any time the current
I'm not too sure about this. l_rtnl_route/address reflect the information obtained from RTNL. They are going to be used not just for l_netconfig. Why do we need the expiry time anyway? Can't l_netconfig just set the lifetime based on its own expiry time book-keeping?
Quoted 5 lines
lifetime left can be returned. This is an incompatible API change to the lifetime getters and setters as they now take a
reference_timeparameter, which in the setter case should normally be the timestamp of when the address or route was received from DHCP. These setters and getters don't seem to have been used outside of ell.
Quoted 7 lines
--- ell/dhcp.c | 3 ++- ell/dhcp6.c | 3 ++- ell/rtnl.c | 71 ++++++++++++++++++++++++++++++++++------------------- ell/rtnl.h | 15 +++++++---- 4 files changed, 60 insertions(+), 32 deletions(-)
Regards,
-Denis
Andrew Zaborowski
Hi Denis,
Quoted 8 lines · Denis Kenzior
Quoted 2 lines · Andrew Zaborowski
Internally within
rtnl.cstore expiry times of addresses and routes instead of their lifetime periods so that at any time the currentI'm not too sure about this. l_rtnl_route/address reflect the information obtained from RTNL. They are going to be used not just for
l_netconfig. Why do we need the expiry time anyway? Can'tl_netconfigjust set the lifetime based on its own expiry time book-keeping?
It can but it complicates things a little.
So the lifetime stored in an l_rtnl_{route,address} without a reference time is useless once any time has passed from the lease receival or RA. That's going to be the case for both l_netconfig internally and also the API user (caller of l_netconfig_get_addresses).
So internally I could wrap l_rtnl_{route,address} in a new private structre, but since it's also an issue for the public API I'd rather create new public classes, and they'd be very similar to l_rtnl_{route,address}.
New APIs outside of l_netconfig may end up having that problem too, the user can't tell if an addresses is still valid.
Remember we're basing l_netconfig on the idea that we don't set timeouts for addresses or routes. Without timers I'll probably be purging expired addresses from the lists when l_netconfig_get_addresses() is called and at other entry points.
Note we already use l_rtnl_address in places where most of its contents are irrelevant. I.e. we may only need 32 bits for each IPv4 address (prefix length is common to the subnet) but we chose to use l_rtnl_address with the space overhead that it implies. I thought the slight extra size of the timestamp shouldn't be an issue.
Best regards
Denis Kenzior
Hi Andrew,
Quoted 5 lines
So the lifetime stored in an l_rtnl_{route,address} without a reference time is useless once any time has passed from the lease receival or RA. That's going to be the case for both
l_netconfiginternally and also the API user (caller ofl_netconfig_get_addresses).
Right, but where does the caller get the reference time? Calling l_time_now() possibly. But lets say you got l_rtnl_route object by querying the kernel over rtnl. The reference time is actually the timestamp of the rtnetlink message (which we probably should obtain as well). So reference_time parameter use is just wrong in this context since the caller can't do the right thing.
I would remove this completely and either track the reference time internally in l_rtnl_{route|address}, or inside l_netconfig.
Quoted 6 lines
So internally I could wrap l_rtnl_{route,address} in a new private structre, but since it's also an issue for the public API I'd rather create new public classes, and they'd be very similar to l_rtnl_{route,address}.
I'm not following? Why isn't validity time enough?
Quoted 7 lines
New APIs outside of
l_netconfigmay end up having that problem too, the user can't tell if an addresses is still valid.Remember we're basing
l_netconfigon the idea that we don't set timeouts for addresses or routes. Without timers I'll probably be purging expired addresses from the lists whenl_netconfig_get_addresses()is called and at other entry points.
It isn't really a blanket ban on timers. It is more to optimize the case of a repeated RAs being received and having to blast all the info into the kernel each time. We can still set a timer for DHCP lease for example. Also, we can hook into the main loop to be woken up every time an event fires and update whatever expiry times we have, and optionally take action if needed.
Quoted 6 lines
Note we already use
l_rtnl_addressin places where most of its contents are irrelevant. I.e. we may only need 32 bits for each IPv4 address (prefix length is common to the subnet) but we chose to usel_rtnl_addresswith the space overhead that it implies. I thought the slight extra size of the timestamp shouldn't be an issue.
I'm mostly concerned about API use. The 'reference' time is confusing to a pure rtnetlink user.
Regards,
-Denis
Andrew Zaborowski
Quoted 11 lines · Denis Kenzior
Quoted 5 lines
So the lifetime stored in an l_rtnl_{route,address} without a reference time is useless once any time has passed from the lease receival or RA. That's going to be the case for both
l_netconfiginternally and also the API user (caller ofl_netconfig_get_addresses).Right, but where does the caller get the reference time? Calling
l_time_now()possibly. But lets say you gotl_rtnl_routeobject by querying the kernel over rtnl. The reference time is actually the timestamp of the rtnetlink message (which we probably should obtain as well). Soreference_timeparameter use is just wrong in this context since the caller can't do the right thing.
Ok, yes, I kind of included that parameter for people who will need to call l_rtnl_route_get_lifetime() for a whole list of routes, and want to optimize and call l_time_now() just once.
Quoted 2 lines
I would remove this completely and either track the reference time internally in l_rtnl_{route|address}, or inside
l_netconfig.
How about l_rtnl_{get,set}_expiry? But I'm ok also making it internal and moving the structs to rtnl-private.h, that would help optimize a lot of these string conversions. However IWD will need to read the lifetimes in some form.
Quoted 9 lines
Quoted 7 lines
So internally I could wrap l_rtnl_{route,address} in a new private structre, but since it's also an issue for the public API I'd rather create new public classes, and they'd be very similar to l_rtnl_{route,address}.
I'm not following? Why isn't validity time enough?
I mean it's not enough in the current code where you call l_rtnl_route_get_lifetime but you have no idea how much time has already passed. Any form that references a specific timestamp would work.
Quoted 4 lines
Quoted 4 lines
New APIs outside of
l_netconfigmay end up having that problem too, the user can't tell if an addresses is still valid.
Quoted 8 lines
Quoted 4 lines
Remember we're basing
l_netconfigon the idea that we don't set timeouts for addresses or routes. Without timers I'll probably be purging expired addresses from the lists whenl_netconfig_get_addresses()is called and at other entry points.It isn't really a blanket ban on timers. It is more to optimize the case of a repeated RAs being received and having to blast all the info into the kernel each time.
And IIRC avoid maintaining a timer FD per route/address.
Quoted 3 lines
We can still set a timer for DHCP lease for example. Also, we can
hook into the main loop to be woken up every time an event fires and update whatever expiry times we have, and optionally take action if needed.
It should be enough to do this on entry points into netconfig.c.
Quoted 10 lines
Quoted 7 lines
Note we already use
l_rtnl_addressin places where most of its contents are irrelevant. I.e. we may only need 32 bits for each IPv4 address (prefix length is common to the subnet) but we chose to usel_rtnl_addresswith the space overhead that it implies. I thought the slight extra size of the timestamp shouldn't be an issue.I'm mostly concerned about API use. The 'reference' time is confusing to a pure rtnetlink user.
True, 'lifetime' is the term used by the kernel but if it's not updated it's wrong. So either we should be returning an updated lifetime or use a term like expiry.
Best regards