mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-02-22 22:00:38 +01:00
netconfig: Implement address installation and removal
This commit is contained in:
parent
6aabd80051
commit
d80d1d5f1a
@ -222,21 +222,84 @@ static void netconfig_ifaddr_cmd_cb(int error, uint16_t type,
|
|||||||
|
|
||||||
static bool netconfig_ifaddr_remove(void *data, void *user_data)
|
static bool netconfig_ifaddr_remove(void *data, void *user_data)
|
||||||
{
|
{
|
||||||
return false;
|
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,
|
static bool netconfig_install_addresses(struct netconfig *netconfig,
|
||||||
const struct netconfig_ifaddr *ifaddr,
|
const struct netconfig_ifaddr *ifaddr,
|
||||||
const char *gateway, char **dns)
|
const char *gateway, char **dns)
|
||||||
{
|
{
|
||||||
return false;
|
if (netconfig_ifaddr_find(netconfig, ifaddr->family, ifaddr->prefix_len,
|
||||||
|
ifaddr->ip))
|
||||||
|
/* The address is already installed. */
|
||||||
|
goto gateway;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
l_error("netconfig: Failed to set IP %s/%u.", ifaddr->ip,
|
||||||
|
ifaddr->prefix_len);
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
l_error("netconfig: Unsupported address family: %u",
|
||||||
|
ifaddr->family);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
gateway:
|
||||||
|
/* TODO: Add the routes and domain name servers. */
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool netconfig_uninstall_addresses(struct netconfig *netconfig,
|
static bool netconfig_uninstall_addresses(struct netconfig *netconfig,
|
||||||
const struct netconfig_ifaddr *ifaddr,
|
const struct netconfig_ifaddr *ifaddr,
|
||||||
const char *gateway, char **dns)
|
const char *gateway, char **dns)
|
||||||
{
|
{
|
||||||
return false;
|
|
||||||
|
if (!netconfig_ifaddr_find(netconfig, ifaddr->family,
|
||||||
|
ifaddr->prefix_len, ifaddr->ip))
|
||||||
|
/* The address is already removed. */
|
||||||
|
goto gateway;
|
||||||
|
|
||||||
|
if (!netconfig_ifaddr_remove(netconfig, (void *) ifaddr)) {
|
||||||
|
l_error("netconfig: Failed to remove IP %s/%u.", ifaddr->ip,
|
||||||
|
ifaddr->prefix_len);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
gateway:
|
||||||
|
/* TODO: Remove the routes and domain name servers. */
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum lease_action {
|
enum lease_action {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user