X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fnetwork.c;h=5a3b0b436334fb8efb6ba0b4d5dc700406a03e30;hp=e2cae912182265eef225c86b130afc4fffafaea2;hb=99a1f905f585480cca2c9a43ab18ed8e37365192;hpb=58db060fbb1548a0acdfc475fa41fe86fb32dd11 diff --git a/discover/network.c b/discover/network.c index e2cae91..5a3b0b4 100644 --- a/discover/network.c +++ b/discover/network.c @@ -331,6 +331,7 @@ static void configure_interface_dhcp(struct network *network, "-f", "-O", "pxeconffile", "-O", "pxepathprefix", + "-O", "reboottime", "-p", pidfile, "-i", interface->name, "-x", id, /* [11,12] - dhcp client identifier */ @@ -417,6 +418,8 @@ static void configure_interface_static(struct network *network, interface->hwaddr, sizeof(interface->hwaddr)), config->static_config.address); + device_handler_start_requery_timeout(network->handler, + interface->dev, -1); } return; @@ -498,6 +501,49 @@ static void configure_interface(struct network *network, interface->state = IFSTATE_CONFIGURED; } +void network_requery_device(struct network *network, + struct discover_device *dev) +{ + const struct interface_config *config; + struct interface *interface; + + interface = find_interface_by_uuid(network, dev->uuid); + if (!interface) + return; + + if (interface->udhcpc_process) { + interface->udhcpc_process->exit_cb = NULL; + interface->udhcpc_process->data = NULL; + process_stop_async(interface->udhcpc_process); + process_release(interface->udhcpc_process); + } + + config = find_config_by_hwaddr(interface->hwaddr); + + if (config && config->ignore) + return; + + if (!config || config->method == CONFIG_METHOD_DHCP) { + /* Restart DHCP. Once we acquire a lease, we'll re-start + * the requery timeout (based on any reboottime DHCP option) + */ + configure_interface_dhcp(network, interface); + + } else if (config->method == CONFIG_METHOD_STATIC && + config->static_config.url) { + /* Redownload statically-provided URL, and manually restart + * requery timeout */ + device_handler_process_url(network->handler, + config->static_config.url, + mac_bytes_to_string(interface->dev, + interface->hwaddr, + sizeof(interface->hwaddr)), + config->static_config.address); + device_handler_start_requery_timeout(network->handler, + dev, -1); + } +} + static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) { bool have_ifaddr, have_ifname; @@ -506,7 +552,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) struct rtattr *attr; unsigned int mtu; uint8_t ifaddr[6]; - char ifname[IFNAMSIZ+1]; + char ifname[IFNAMSIZ]; int attrlen, type; @@ -534,6 +580,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) case IFLA_IFNAME: strncpy(ifname, data, IFNAMSIZ); + ifname[IFNAMSIZ - 1] = '\0'; have_ifname = true; break; @@ -565,7 +612,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) interface->ifindex = info->ifi_index; interface->state = IFSTATE_NEW; memcpy(interface->hwaddr, ifaddr, sizeof(interface->hwaddr)); - strncpy(interface->name, ifname, sizeof(interface->name) - 1); + strncpy(interface->name, ifname, sizeof(interface->name)); list_for_each_entry(&network->interfaces, tmp, list) if (memcmp(interface->hwaddr, tmp->hwaddr, @@ -583,7 +630,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) /* A repeated RTM_NEWLINK can represent an interface name change */ if (strncmp(interface->name, ifname, IFNAMSIZ)) { pb_debug("ifname update: %s -> %s\n", interface->name, ifname); - strncpy(interface->name, ifname, sizeof(interface->name) - 1); + strncpy(interface->name, ifname, sizeof(interface->name)); talloc_free(interface->dev->device->id); interface->dev->device->id = talloc_strdup(interface->dev->device, ifname);