mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 10:32:33 +01:00
netconfig: Refactor Install/Uninstall for IPv4 addresses
This commit is contained in:
parent
72e6598c6e
commit
372240fe8c
@ -316,90 +316,56 @@ static void netconfig_ifaddr_cmd_cb(int error, uint16_t type,
|
||||
netconfig_ifaddr_notify(type, data, len, user_data);
|
||||
}
|
||||
|
||||
static bool netconfig_ifaddr_remove(void *data, void *user_data)
|
||||
{
|
||||
struct netconfig *netconfig = user_data;
|
||||
struct netconfig_ifaddr *ifaddr = data;
|
||||
|
||||
switch (ifaddr->family) {
|
||||
case AF_INET:
|
||||
if (rtnl_ifaddr_delete(rtnl, netconfig->ifindex,
|
||||
ifaddr->prefix_len, ifaddr->ip,
|
||||
ifaddr->broadcast,
|
||||
netconfig_ifaddr_cmd_cb, NULL, NULL))
|
||||
break;
|
||||
|
||||
l_error("netconfig: Failed to remove ifaddr %s from "
|
||||
"interface %u", ifaddr->ip, netconfig->ifindex);
|
||||
break;
|
||||
default:
|
||||
l_error("netconfig: Unsupported address family: %u",
|
||||
ifaddr->family);
|
||||
break;
|
||||
}
|
||||
|
||||
netconfig_ifaddr_destroy(ifaddr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool netconfig_install_addresses(struct netconfig *netconfig,
|
||||
const struct netconfig_ifaddr *ifaddr,
|
||||
const char *gateway, char **dns)
|
||||
static void netconfig_install_address(struct netconfig *netconfig,
|
||||
struct netconfig_ifaddr *ifaddr)
|
||||
{
|
||||
if (netconfig_ifaddr_find(netconfig, ifaddr->family, ifaddr->prefix_len,
|
||||
ifaddr->ip))
|
||||
/* The address is already installed. */
|
||||
goto gateway;
|
||||
return;
|
||||
|
||||
switch (ifaddr->family) {
|
||||
case AF_INET:
|
||||
if (rtnl_ifaddr_add(rtnl, netconfig->ifindex,
|
||||
ifaddr->prefix_len, ifaddr->ip,
|
||||
ifaddr->broadcast,
|
||||
netconfig_ifaddr_cmd_cb, netconfig,
|
||||
NULL))
|
||||
break;
|
||||
netconfig_ifaddr_cmd_cb,
|
||||
netconfig, NULL))
|
||||
return;
|
||||
|
||||
l_error("netconfig: Failed to set IP %s/%u.", ifaddr->ip,
|
||||
ifaddr->prefix_len);
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
l_error("netconfig: Unsupported address family: %u",
|
||||
ifaddr->family);
|
||||
break;
|
||||
}
|
||||
|
||||
gateway:
|
||||
/* TODO: Add the routes. */
|
||||
|
||||
resolve_add_dns(netconfig->ifindex, ifaddr->family, dns);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool netconfig_uninstall_addresses(struct netconfig *netconfig,
|
||||
const struct netconfig_ifaddr *ifaddr,
|
||||
const char *gateway, char **dns)
|
||||
static void netconfig_uninstall_address(struct netconfig *netconfig,
|
||||
struct netconfig_ifaddr *ifaddr)
|
||||
{
|
||||
|
||||
if (!netconfig_ifaddr_find(netconfig, ifaddr->family,
|
||||
ifaddr->prefix_len, ifaddr->ip))
|
||||
/* The address is already removed. */
|
||||
goto gateway;
|
||||
return;
|
||||
|
||||
if (!netconfig_ifaddr_remove(netconfig, (void *) ifaddr)) {
|
||||
l_error("netconfig: Failed to remove IP %s/%u.", ifaddr->ip,
|
||||
ifaddr->prefix_len);
|
||||
return false;
|
||||
switch (ifaddr->family) {
|
||||
case AF_INET:
|
||||
if (rtnl_ifaddr_delete(rtnl, netconfig->ifindex,
|
||||
ifaddr->prefix_len, ifaddr->ip,
|
||||
ifaddr->broadcast,
|
||||
netconfig_ifaddr_cmd_cb, netconfig,
|
||||
NULL))
|
||||
return;
|
||||
|
||||
l_error("netconfig: Failed to delete IP %s/%u.",
|
||||
ifaddr->ip, ifaddr->prefix_len);
|
||||
break;
|
||||
default:
|
||||
l_error("netconfig: Unsupported address family: %u",
|
||||
ifaddr->family);
|
||||
break;
|
||||
}
|
||||
|
||||
gateway:
|
||||
/* TODO: Remove the routes. */
|
||||
|
||||
resolve_remove(netconfig->ifindex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,
|
||||
@ -422,7 +388,7 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO Install address */
|
||||
netconfig_install_address(netconfig, ifaddr);
|
||||
|
||||
netconfig_ifaddr_destroy(ifaddr);
|
||||
|
||||
@ -435,7 +401,7 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,
|
||||
return;
|
||||
}
|
||||
|
||||
/* TODO Uninstall address */
|
||||
netconfig_uninstall_address(netconfig, ifaddr);
|
||||
|
||||
netconfig_ifaddr_destroy(ifaddr);
|
||||
|
||||
@ -483,7 +449,7 @@ static void netconfig_ipv4_select_and_install(struct netconfig *netconfig)
|
||||
|
||||
ifaddr = netconfig_ipv4_get_ifaddr(netconfig, RTPROT_STATIC);
|
||||
if (ifaddr) {
|
||||
/* TODO Install address */
|
||||
netconfig_install_address(netconfig, ifaddr);
|
||||
netconfig_ifaddr_destroy(ifaddr);
|
||||
|
||||
return;
|
||||
@ -511,7 +477,7 @@ static void netconfig_ipv4_select_and_uninstall(struct netconfig *netconfig)
|
||||
|
||||
ifaddr = netconfig_ipv4_get_ifaddr(netconfig, RTPROT_STATIC);
|
||||
if (ifaddr) {
|
||||
/* TODO Uninstall address */
|
||||
netconfig_uninstall_address(netconfig, ifaddr);
|
||||
netconfig_ifaddr_destroy(ifaddr);
|
||||
|
||||
return;
|
||||
@ -521,7 +487,7 @@ static void netconfig_ipv4_select_and_uninstall(struct netconfig *netconfig)
|
||||
if (!ifaddr)
|
||||
return;
|
||||
|
||||
/* TODO Uninstall address */
|
||||
netconfig_uninstall_address(netconfig, ifaddr);
|
||||
netconfig_ifaddr_destroy(ifaddr);
|
||||
|
||||
l_dhcp_client_stop(netconfig->dhcp_client);
|
||||
|
Loading…
Reference in New Issue
Block a user