bool dry_run;
};
-static const struct network_config *find_config_by_hwaddr(
+static const struct interface_config *find_config_by_hwaddr(
uint8_t *hwaddr)
{
const struct config *config;
if (!config)
return NULL;
- for (i = 0; i < config->n_network_configs; i++) {
- struct network_config *netconf = config->network_configs[i];
+ for (i = 0; i < config->network.n_interfaces; i++) {
+ struct interface_config *ifconf = config->network.interfaces[i];
- if (!memcmp(netconf->hwaddr, hwaddr, HWADDR_SIZE))
- return netconf;
+ if (!memcmp(ifconf->hwaddr, hwaddr, HWADDR_SIZE))
+ return ifconf;
}
return NULL;
return 0;
}
-static int interface_up(struct network *network, struct interface *interface)
+static int interface_change(struct network *network,
+ struct interface *interface,
+ bool up)
{
int rc;
+ const char *statestr = up ? "up" : "down";
const char *argv[] = {
pb_system_apps.ip,
"link",
"set",
interface->name,
- "up",
+ statestr,
NULL,
};
rc = pb_run_cmd(argv, 1, network->dry_run);
if (rc) {
- pb_log("failed to bring interface %s up\n", interface->name);
+ pb_log("failed to bring interface %s %s\n", interface->name,
+ statestr);
return -1;
}
return 0;
}
+static int interface_up(struct network *network,
+ struct interface *interface)
+{
+ return interface_change(network, interface, true);
+}
+
+static int interface_down(struct network *network,
+ struct interface *interface)
+{
+ return interface_change(network, interface, false);
+}
+
static void configure_interface_dhcp(struct network *network,
struct interface *interface)
{
static void configure_interface_static(struct network *network,
struct interface *interface,
- const struct network_config *config)
+ const struct interface_config *config)
{
const char *addr_argv[] = {
pb_system_apps.ip,
static void configure_interface(struct network *network,
struct interface *interface, bool up, bool link)
{
- const struct network_config *config = NULL;
+ const struct interface_config *config = NULL;
if (interface->state == IFSTATE_IGNORED)
return;
int network_shutdown(struct network *network)
{
+ struct interface *interface;
+
if (network->waiter)
waiter_remove(network->waiter);
+ list_for_each_entry(&network->interfaces, interface, list)
+ interface_down(network, interface);
+
close(network->netlink_sd);
talloc_free(network);
return 0;