Wireless Daemon for Linux
 help / color / mirror / Atom feed
* [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper
@ 2019-10-02 20:39 Tim Kourt
  2019-10-02 20:39 ` [PATCH 2/4] netconfig: Remove IPv6 default route Tim Kourt
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tim Kourt @ 2019-10-02 20:39 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2403 bytes --]

---
 src/rtnlutil.c | 31 +++++++++++++++++++++++++++++--
 src/rtnlutil.h |  7 +++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/rtnlutil.c b/src/rtnlutil.c
index 4090d311..f90e9dcf 100644
--- a/src/rtnlutil.c
+++ b/src/rtnlutil.c
@@ -533,7 +533,8 @@ uint32_t rtnl_ifaddr_ipv6_delete(struct l_netlink *rtnl, int ifindex,
 						ip, cb, user_data, destroy);
 }
 
-uint32_t rtnl_route_ipv6_add_gateway(struct l_netlink *rtnl, int ifindex,
+static uint32_t rtnl_route_ipv6_change(struct l_netlink *rtnl,
+					uint16_t nlmsg_type, int ifindex,
 					const char *gateway,
 					uint32_t priority_offset,
 					uint8_t proto,
@@ -581,7 +582,33 @@ uint32_t rtnl_route_ipv6_add_gateway(struct l_netlink *rtnl, int ifindex,
 						sizeof(struct in6_addr));
 	}
 
-	return l_netlink_send(rtnl, RTM_NEWROUTE, flags, rtmmsg,
+	return l_netlink_send(rtnl, nlmsg_type, flags, rtmmsg,
 				rta_buf - (void *) rtmmsg, cb, user_data,
 								destroy);
 }
+
+uint32_t rtnl_route_ipv6_add_gateway(struct l_netlink *rtnl, int ifindex,
+					const char *gateway,
+					uint32_t priority_offset,
+					uint8_t proto,
+					l_netlink_command_func_t cb,
+					void *user_data,
+					l_netlink_destroy_func_t destroy)
+{
+	return rtnl_route_ipv6_change(rtnl, RTM_NEWROUTE, ifindex, gateway,
+					priority_offset, proto, cb,
+					user_data, destroy);
+}
+
+uint32_t rtnl_route_ipv6_delete_gateway(struct l_netlink *rtnl, int ifindex,
+					const char *gateway,
+					uint32_t priority_offset,
+					uint8_t proto,
+					l_netlink_command_func_t cb,
+					void *user_data,
+					l_netlink_destroy_func_t destroy)
+{
+	return rtnl_route_ipv6_change(rtnl, RTM_DELROUTE, ifindex, gateway,
+					priority_offset, proto, cb,
+					user_data, destroy);
+}
diff --git a/src/rtnlutil.h b/src/rtnlutil.h
index 6689e16e..383d562f 100644
--- a/src/rtnlutil.h
+++ b/src/rtnlutil.h
@@ -90,3 +90,10 @@ uint32_t rtnl_route_ipv6_add_gateway(struct l_netlink *rtnl, int ifindex,
 					l_netlink_command_func_t cb,
 					void *user_data,
 					l_netlink_destroy_func_t destroy);
+uint32_t rtnl_route_ipv6_delete_gateway(struct l_netlink *rtnl, int ifindex,
+					const char *gateway,
+					uint32_t priority_offset,
+					uint8_t proto,
+					l_netlink_command_func_t cb,
+					void *user_data,
+					l_netlink_destroy_func_t destroy);
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] netconfig: Remove IPv6 default route
  2019-10-02 20:39 [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper Tim Kourt
@ 2019-10-02 20:39 ` Tim Kourt
  2019-10-02 20:39 ` [PATCH 3/4] netconfig: Optimize IPv4 address deletion Tim Kourt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Tim Kourt @ 2019-10-02 20:39 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1332 bytes --]

The IPv6 default route needs to be explicitly revoked. Unlike in IPv4,
there is no SRC address associated with the route and it will not be
removed on address removal.
---
 src/netconfig.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/netconfig.c b/src/netconfig.c
index 90cd6bc2..cf951245 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -958,6 +958,7 @@ static void netconfig_ipv6_select_and_install(struct netconfig *netconfig)
 static void netconfig_ipv6_select_and_uninstall(struct netconfig *netconfig)
 {
 	struct netconfig_ifaddr *ifaddr;
+	char *gateway;
 
 	ifaddr = netconfig_ipv6_get_ifaddr(netconfig,
 						netconfig->rtm_v6_protocol);
@@ -970,6 +971,20 @@ static void netconfig_ipv6_select_and_uninstall(struct netconfig *netconfig)
 	 * TODO
 	 * l_dhcp_v6_client_stop(netconfig->l_dhcp_v6_client);
 	 */
+
+	gateway = netconfig_ipv6_get_gateway(netconfig);
+	if (!gateway)
+		return;
+
+	if (!rtnl_route_ipv6_delete_gateway(rtnl, netconfig->ifindex,
+			gateway, ROUTE_PRIORITY_OFFSET,
+			netconfig->rtm_v6_protocol,
+			netconfig_route_cmd_cb, NULL, NULL)) {
+		l_error("netconfig: Failed to delete route for: %s gateway.",
+								gateway);
+	}
+
+	l_free(gateway);
 }
 
 bool netconfig_configure(struct netconfig *netconfig,
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] netconfig: Optimize IPv4 address deletion
  2019-10-02 20:39 [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper Tim Kourt
  2019-10-02 20:39 ` [PATCH 2/4] netconfig: Remove IPv6 default route Tim Kourt
@ 2019-10-02 20:39 ` Tim Kourt
  2019-10-02 20:39 ` [PATCH 4/4] netconfig: Fix return type for module init Tim Kourt
  2019-10-03 15:56 ` [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Tim Kourt @ 2019-10-02 20:39 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 1096 bytes --]

Decrease the queue traversals to a single pass
---
 src/netconfig.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/netconfig.c b/src/netconfig.c
index cf951245..2175d9be 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -427,22 +427,22 @@ static void netconfig_ifaddr_deleted(struct netconfig *netconfig,
 					uint32_t len)
 {
 	struct netconfig_ifaddr *ifaddr;
-	char *ip;
+	struct netconfig_ifaddr query;
 
-	rtnl_ifaddr_extract(ifa, len, NULL, &ip, NULL);
+	rtnl_ifaddr_extract(ifa, len, NULL, &query.ip, NULL);
 
-	ifaddr = netconfig_ifaddr_find(netconfig, ifa->ifa_family,
-							ifa->ifa_prefixlen, ip);
+	query.family = ifa->ifa_family;
+	query.prefix_len = ifa->ifa_prefixlen;
 
-	l_free(ip);
+	ifaddr = l_queue_remove_if(netconfig->ifaddr_list,
+						netconfig_ifaddr_match, &query);
+	l_free(query.ip);
 
 	if (!ifaddr)
 		return;
 
 	l_debug("ifaddr %s/%u", ifaddr->ip, ifaddr->prefix_len);
 
-	l_queue_remove(netconfig->ifaddr_list, ifaddr);
-
 	netconfig_ifaddr_destroy(ifaddr);
 }
 
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] netconfig: Fix return type for module init
  2019-10-02 20:39 [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper Tim Kourt
  2019-10-02 20:39 ` [PATCH 2/4] netconfig: Remove IPv6 default route Tim Kourt
  2019-10-02 20:39 ` [PATCH 3/4] netconfig: Optimize IPv4 address deletion Tim Kourt
@ 2019-10-02 20:39 ` Tim Kourt
  2019-10-03 15:56 ` [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Tim Kourt @ 2019-10-02 20:39 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]

---
 src/netconfig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/netconfig.c b/src/netconfig.c
index 2175d9be..285d5fef 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -1087,7 +1087,7 @@ static int netconfig_init(void)
 								!enabled) {
 		l_warn("netconfig: Network configuration with the IP addresses "
 								"is disabled.");
-		return false;
+		return 0;
 	}
 
 	rtnl = l_netlink_new(NETLINK_ROUTE);
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper
  2019-10-02 20:39 [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper Tim Kourt
                   ` (2 preceding siblings ...)
  2019-10-02 20:39 ` [PATCH 4/4] netconfig: Fix return type for module init Tim Kourt
@ 2019-10-03 15:56 ` Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2019-10-03 15:56 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 249 bytes --]

Hi Tim,

On 10/2/19 3:39 PM, Tim Kourt wrote:
> ---
>   src/rtnlutil.c | 31 +++++++++++++++++++++++++++++--
>   src/rtnlutil.h |  7 +++++++
>   2 files changed, 36 insertions(+), 2 deletions(-)
> 

All applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-03 15:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-02 20:39 [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper Tim Kourt
2019-10-02 20:39 ` [PATCH 2/4] netconfig: Remove IPv6 default route Tim Kourt
2019-10-02 20:39 ` [PATCH 3/4] netconfig: Optimize IPv4 address deletion Tim Kourt
2019-10-02 20:39 ` [PATCH 4/4] netconfig: Fix return type for module init Tim Kourt
2019-10-03 15:56 ` [PATCH 1/4] rtnlutil: Add IPv6 route deletion helper Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox