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);
|
netconfig_ifaddr_notify(type, data, len, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool netconfig_ifaddr_remove(void *data, void *user_data)
|
static void netconfig_install_address(struct netconfig *netconfig,
|
||||||
{
|
struct netconfig_ifaddr *ifaddr)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
if (netconfig_ifaddr_find(netconfig, ifaddr->family, ifaddr->prefix_len,
|
if (netconfig_ifaddr_find(netconfig, ifaddr->family, ifaddr->prefix_len,
|
||||||
ifaddr->ip))
|
ifaddr->ip))
|
||||||
/* The address is already installed. */
|
return;
|
||||||
goto gateway;
|
|
||||||
|
|
||||||
switch (ifaddr->family) {
|
switch (ifaddr->family) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
if (rtnl_ifaddr_add(rtnl, netconfig->ifindex,
|
if (rtnl_ifaddr_add(rtnl, netconfig->ifindex,
|
||||||
ifaddr->prefix_len, ifaddr->ip,
|
ifaddr->prefix_len, ifaddr->ip,
|
||||||
ifaddr->broadcast,
|
ifaddr->broadcast,
|
||||||
netconfig_ifaddr_cmd_cb, netconfig,
|
netconfig_ifaddr_cmd_cb,
|
||||||
NULL))
|
netconfig, NULL))
|
||||||
break;
|
return;
|
||||||
|
|
||||||
l_error("netconfig: Failed to set IP %s/%u.", ifaddr->ip,
|
l_error("netconfig: Failed to set IP %s/%u.", ifaddr->ip,
|
||||||
ifaddr->prefix_len);
|
ifaddr->prefix_len);
|
||||||
return false;
|
break;
|
||||||
default:
|
default:
|
||||||
l_error("netconfig: Unsupported address family: %u",
|
l_error("netconfig: Unsupported address family: %u",
|
||||||
ifaddr->family);
|
ifaddr->family);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
gateway:
|
|
||||||
/* TODO: Add the routes. */
|
|
||||||
|
|
||||||
resolve_add_dns(netconfig->ifindex, ifaddr->family, dns);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool netconfig_uninstall_addresses(struct netconfig *netconfig,
|
static void netconfig_uninstall_address(struct netconfig *netconfig,
|
||||||
const struct netconfig_ifaddr *ifaddr,
|
struct netconfig_ifaddr *ifaddr)
|
||||||
const char *gateway, char **dns)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!netconfig_ifaddr_find(netconfig, ifaddr->family,
|
if (!netconfig_ifaddr_find(netconfig, ifaddr->family,
|
||||||
ifaddr->prefix_len, ifaddr->ip))
|
ifaddr->prefix_len, ifaddr->ip))
|
||||||
/* The address is already removed. */
|
return;
|
||||||
goto gateway;
|
|
||||||
|
|
||||||
if (!netconfig_ifaddr_remove(netconfig, (void *) ifaddr)) {
|
switch (ifaddr->family) {
|
||||||
l_error("netconfig: Failed to remove IP %s/%u.", ifaddr->ip,
|
case AF_INET:
|
||||||
ifaddr->prefix_len);
|
if (rtnl_ifaddr_delete(rtnl, netconfig->ifindex,
|
||||||
return false;
|
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,
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO Install address */
|
netconfig_install_address(netconfig, ifaddr);
|
||||||
|
|
||||||
netconfig_ifaddr_destroy(ifaddr);
|
netconfig_ifaddr_destroy(ifaddr);
|
||||||
|
|
||||||
@ -435,7 +401,7 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO Uninstall address */
|
netconfig_uninstall_address(netconfig, ifaddr);
|
||||||
|
|
||||||
netconfig_ifaddr_destroy(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);
|
ifaddr = netconfig_ipv4_get_ifaddr(netconfig, RTPROT_STATIC);
|
||||||
if (ifaddr) {
|
if (ifaddr) {
|
||||||
/* TODO Install address */
|
netconfig_install_address(netconfig, ifaddr);
|
||||||
netconfig_ifaddr_destroy(ifaddr);
|
netconfig_ifaddr_destroy(ifaddr);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -511,7 +477,7 @@ static void netconfig_ipv4_select_and_uninstall(struct netconfig *netconfig)
|
|||||||
|
|
||||||
ifaddr = netconfig_ipv4_get_ifaddr(netconfig, RTPROT_STATIC);
|
ifaddr = netconfig_ipv4_get_ifaddr(netconfig, RTPROT_STATIC);
|
||||||
if (ifaddr) {
|
if (ifaddr) {
|
||||||
/* TODO Uninstall address */
|
netconfig_uninstall_address(netconfig, ifaddr);
|
||||||
netconfig_ifaddr_destroy(ifaddr);
|
netconfig_ifaddr_destroy(ifaddr);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -521,7 +487,7 @@ static void netconfig_ipv4_select_and_uninstall(struct netconfig *netconfig)
|
|||||||
if (!ifaddr)
|
if (!ifaddr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* TODO Uninstall address */
|
netconfig_uninstall_address(netconfig, ifaddr);
|
||||||
netconfig_ifaddr_destroy(ifaddr);
|
netconfig_ifaddr_destroy(ifaddr);
|
||||||
|
|
||||||
l_dhcp_client_stop(netconfig->dhcp_client);
|
l_dhcp_client_stop(netconfig->dhcp_client);
|
||||||
|
Loading…
Reference in New Issue
Block a user