All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/9] netconfig: Move FILS override checks to common functions
@ 2021-11-08 11:28 Andrew Zaborowski
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Zaborowski @ 2021-11-08 11:28 UTC (permalink / raw)
  To: iwd

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

---
 src/netconfig.c | 56 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 19 deletions(-)

diff --git a/src/netconfig.c b/src/netconfig.c
index ea77e818..885e34a8 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -189,6 +189,36 @@ static inline char *netconfig_ipv6_to_string(const uint8_t *addr)
 	return addr_str;
 }
 
+static bool netconfig_use_fils_addr(struct netconfig *netconfig, int af)
+{
+	if ((af == AF_INET ? netconfig->rtm_protocol :
+				netconfig->rtm_v6_protocol) != RTPROT_DHCP)
+		return false;
+
+	if (!netconfig->fils_override)
+		return false;
+
+	if (af == AF_INET)
+		return !!netconfig->fils_override->ipv4_addr;
+
+	return !l_memeqzero(netconfig->fils_override->ipv6_addr, 16);
+}
+
+static bool netconfig_use_fils_gateway(struct netconfig *netconfig, int af)
+{
+	if ((af == AF_INET ? netconfig->rtm_protocol :
+				netconfig->rtm_v6_protocol) != RTPROT_DHCP)
+		return false;
+
+	if (!netconfig->fils_override)
+		return false;
+
+	if (af == AF_INET)
+		return !!netconfig->fils_override->ipv4_gateway;
+
+	return !l_memeqzero(netconfig->fils_override->ipv6_gateway, 16);
+}
+
 static char **netconfig_get_dns_list(struct netconfig *netconfig, int af,
 					const uint8_t **out_dns_mac)
 {
@@ -472,7 +502,7 @@ static char *netconfig_ipv4_get_gateway(struct netconfig *netconfig,
 		return gateway;
 
 	case RTPROT_DHCP:
-		if (fils && fils->ipv4_gateway) {
+		if (netconfig_use_fils_gateway(netconfig, AF_INET)) {
 			gateway = netconfig_ipv4_to_string(fils->ipv4_gateway);
 
 			if (gateway && out_mac &&
@@ -540,10 +570,7 @@ static struct l_rtnl_route *netconfig_get_static6_gateway(
 
 	gateway = l_settings_get_string(netconfig->active_settings,
 						"IPv6", "Gateway");
-	if (!gateway && netconfig->rtm_v6_protocol == RTPROT_DHCP &&
-			netconfig->fils_override &&
-			!l_memeqzero(netconfig->fils_override->ipv6_gateway,
-					16)) {
+	if (!gateway && netconfig_use_fils_gateway(netconfig, AF_INET6)) {
 		gateway = netconfig_ipv6_to_string(
 					netconfig->fils_override->ipv6_gateway);
 
@@ -711,8 +738,7 @@ static void netconfig_ifaddr_ipv6_added(struct netconfig *netconfig,
 			ip, ifa->ifa_prefixlen);
 
 	if (netconfig->rtm_v6_protocol != RTPROT_DHCP ||
-			(netconfig->fils_override &&
-			 !l_memeqzero(netconfig->fils_override->ipv6_addr, 16)))
+			netconfig_use_fils_addr(netconfig, AF_INET6))
 		return;
 
 	inet_pton(AF_INET6, ip, &in6);
@@ -1089,9 +1115,7 @@ static void netconfig_set(struct netconfig *netconfig, uint8_t af,
 		 * static and FILS-provided cases here.
 		 */
 	} else if (netconfig->rtm_v6_protocol == RTPROT_STATIC ||
-			(netconfig->fils_override &&
-			 !l_memeqzero(netconfig->fils_override->ipv6_addr,
-					16))) {
+			netconfig_use_fils_addr(netconfig, AF_INET6)) {
 		if (!netconfig->v6_address)
 			return;
 
@@ -1137,9 +1161,7 @@ static void netconfig_set(struct netconfig *netconfig, uint8_t af,
 			netconfig->notify = NULL;
 		}
 	} else if (netconfig->rtm_v6_protocol == RTPROT_STATIC ||
-			(netconfig->fils_override &&
-			 !l_memeqzero(netconfig->fils_override->ipv6_gateway,
-					16))) {
+			netconfig_use_fils_gateway(netconfig, AF_INET6)) {
 		if (changed & (NETCONFIG_CHANGED_GATEWAY))
 			if (netconfig_ipv6_static_gateway_route_install(
 								netconfig))
@@ -1450,9 +1472,7 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig)
 	struct netdev *netdev = netdev_find(netconfig->ifindex);
 	bool set_address = (netconfig->rtm_protocol == RTPROT_STATIC);
 
-	if (netconfig->rtm_protocol == RTPROT_DHCP &&
-			netconfig->fils_override &&
-			netconfig->fils_override->ipv4_addr) {
+	if (netconfig_use_fils_addr(netconfig, AF_INET)) {
 		L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv4_to_string(
 					netconfig->fils_override->ipv4_addr);
 		uint8_t prefix_len = netconfig->fils_override->ipv4_prefix_len;
@@ -1538,9 +1558,7 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig)
 
 	sysfs_write_ipv6_setting(netdev_get_name(netdev), "disable_ipv6", "0");
 
-	if (netconfig->rtm_v6_protocol == RTPROT_DHCP &&
-			netconfig->fils_override &&
-			!l_memeqzero(netconfig->fils_override->ipv6_addr, 16)) {
+	if (netconfig_use_fils_addr(netconfig, AF_INET6)) {
 		uint8_t prefix_len = netconfig->fils_override->ipv6_prefix_len;
 		L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv6_to_string(
 					netconfig->fils_override->ipv6_addr);
-- 
2.32.0

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

* Re: [PATCH 2/9] netconfig: Move FILS override checks to common functions
@ 2021-11-10 18:03 Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2021-11-10 18:03 UTC (permalink / raw)
  To: iwd

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

Hi Andrew,

On 11/8/21 5:28 AM, Andrew Zaborowski wrote:
> ---
>   src/netconfig.c | 56 ++++++++++++++++++++++++++++++++-----------------
>   1 file changed, 37 insertions(+), 19 deletions(-)
> 

Applied (without the chunks in netconfig_set).

Regards,
-Denis

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

end of thread, other threads:[~2021-11-10 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-08 11:28 [PATCH 2/9] netconfig: Move FILS override checks to common functions Andrew Zaborowski
2021-11-10 18:03 Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.