3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00

netconfig: Move FILS override checks to common functions

This commit is contained in:
Andrew Zaborowski 2021-11-08 12:28:31 +01:00 committed by Denis Kenzior
parent 5e7949c144
commit 6ac062d151

View File

@ -176,6 +176,36 @@ static inline char *netconfig_ipv6_to_string(const uint8_t *addr)
return addr_str; 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, static char **netconfig_get_dns_list(struct netconfig *netconfig, int af,
const uint8_t **out_dns_mac) const uint8_t **out_dns_mac)
{ {
@ -459,7 +489,7 @@ static char *netconfig_ipv4_get_gateway(struct netconfig *netconfig,
return gateway; return gateway;
case RTPROT_DHCP: case RTPROT_DHCP:
if (fils && fils->ipv4_gateway) { if (netconfig_use_fils_gateway(netconfig, AF_INET)) {
gateway = netconfig_ipv4_to_string(fils->ipv4_gateway); gateway = netconfig_ipv4_to_string(fils->ipv4_gateway);
if (gateway && out_mac && if (gateway && out_mac &&
@ -527,10 +557,7 @@ static struct l_rtnl_route *netconfig_get_static6_gateway(
gateway = l_settings_get_string(netconfig->active_settings, gateway = l_settings_get_string(netconfig->active_settings,
"IPv6", "Gateway"); "IPv6", "Gateway");
if (!gateway && netconfig->rtm_v6_protocol == RTPROT_DHCP && if (!gateway && netconfig_use_fils_gateway(netconfig, AF_INET6)) {
netconfig->fils_override &&
!l_memeqzero(netconfig->fils_override->ipv6_gateway,
16)) {
gateway = netconfig_ipv6_to_string( gateway = netconfig_ipv6_to_string(
netconfig->fils_override->ipv6_gateway); netconfig->fils_override->ipv6_gateway);
@ -698,8 +725,7 @@ static void netconfig_ifaddr_ipv6_added(struct netconfig *netconfig,
ip, ifa->ifa_prefixlen); ip, ifa->ifa_prefixlen);
if (netconfig->rtm_v6_protocol != RTPROT_DHCP || if (netconfig->rtm_v6_protocol != RTPROT_DHCP ||
(netconfig->fils_override && netconfig_use_fils_addr(netconfig, AF_INET6))
!l_memeqzero(netconfig->fils_override->ipv6_addr, 16)))
return; return;
inet_pton(AF_INET6, ip, &in6); inet_pton(AF_INET6, ip, &in6);
@ -1191,9 +1217,7 @@ static bool netconfig_ipv4_select_and_install(struct netconfig *netconfig)
struct netdev *netdev = netdev_find(netconfig->ifindex); struct netdev *netdev = netdev_find(netconfig->ifindex);
bool set_address = (netconfig->rtm_protocol == RTPROT_STATIC); bool set_address = (netconfig->rtm_protocol == RTPROT_STATIC);
if (netconfig->rtm_protocol == RTPROT_DHCP && if (netconfig_use_fils_addr(netconfig, AF_INET)) {
netconfig->fils_override &&
netconfig->fils_override->ipv4_addr) {
L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv4_to_string( L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv4_to_string(
netconfig->fils_override->ipv4_addr); netconfig->fils_override->ipv4_addr);
uint8_t prefix_len = netconfig->fils_override->ipv4_prefix_len; uint8_t prefix_len = netconfig->fils_override->ipv4_prefix_len;
@ -1274,9 +1298,7 @@ static bool netconfig_ipv6_select_and_install(struct netconfig *netconfig)
sysfs_write_ipv6_setting(netdev_get_name(netdev), "disable_ipv6", "0"); sysfs_write_ipv6_setting(netdev_get_name(netdev), "disable_ipv6", "0");
if (netconfig->rtm_v6_protocol == RTPROT_DHCP && if (netconfig_use_fils_addr(netconfig, AF_INET6)) {
netconfig->fils_override &&
!l_memeqzero(netconfig->fils_override->ipv6_addr, 16)) {
uint8_t prefix_len = netconfig->fils_override->ipv6_prefix_len; uint8_t prefix_len = netconfig->fils_override->ipv6_prefix_len;
L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv6_to_string( L_AUTO_FREE_VAR(char *, addr_str) = netconfig_ipv6_to_string(
netconfig->fils_override->ipv6_addr); netconfig->fils_override->ipv6_addr);