commit d80d1d5f1ac95140e5137b9c04ea4a4a59d8a9ad
parent 6aabd80051d66b5546b714c36f85ab0b6e9dd7cb
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date: Tue, 25 Jun 2019 15:20:59 -0700
netconfig: Implement address installation and removal
Diffstat:
| M | src/netconfig.c | | | 69 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- |
1 file changed, 66 insertions(+), 3 deletions(-)
diff --git a/src/netconfig.c b/src/netconfig.c
@@ -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)
{
- 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,
const struct netconfig_ifaddr *ifaddr,
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,
const struct netconfig_ifaddr *ifaddr,
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 {