X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fnetwork.c;h=c300f3dc7719619aa6092df5b476837ff8177b74;hp=b9b0c5043f58e3131b0789f1948257051d0f5831;hb=5a271400e9b5396cb90258b7582fe7ac6bcc2230;hpb=089d0a6eb769d531129a7cd1061493a1a24b4bef diff --git a/discover/network.c b/discover/network.c index b9b0c50..c300f3d 100644 --- a/discover/network.c +++ b/discover/network.c @@ -14,13 +14,13 @@ #include #include #include -#include #include #include #include "file.h" #include "network.h" #include "sysinfo.h" +#include "platform.h" #include "device-handler.h" #define HWADDR_SIZE 6 @@ -69,7 +69,7 @@ static const struct interface_config *find_config_by_hwaddr( uint8_t *hwaddr) { const struct config *config; - int i; + unsigned int i; config = config_get(); if (!config) @@ -212,20 +212,31 @@ static void udhcpc_process_exit(struct process *process) static void configure_interface_dhcp(struct interface *interface) { + const struct platform *platform; + char pidfile[256], id[10]; struct process *process; - char pidfile[256]; int rc; const char *argv[] = { pb_system_apps.udhcpc, "-R", "-n", + "-O", "pxeconffile", + "-O", "pxepathprefix", "-p", pidfile, "-i", interface->name, + "-x", id, /* [11,12] - dhcp client identifier */ NULL, }; + snprintf(pidfile, sizeof(pidfile), "%s/udhcpc-%s.pid", PIDFILE_BASE, interface->name); + platform = platform_get(); + if (platform && platform->dhcp_arch_id != 0xffff) + snprintf(id, sizeof(id), "0x5d:%04x", platform->dhcp_arch_id); + else + argv[11] = NULL; + process = process_create(interface); process->path = pb_system_apps.udhcpc; @@ -369,6 +380,7 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) info = NLMSG_DATA(nlmsg); have_ifaddr = have_ifname = false; + mtu = 1; attrlen = nlmsg->nlmsg_len - sizeof(*info); @@ -414,14 +426,15 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg) memcpy(interface->hwaddr, ifaddr, sizeof(interface->hwaddr)); strncpy(interface->name, ifname, sizeof(interface->name) - 1); add_interface(network, interface); - - /* tell the sysinfo code about this interface */ - if (strcmp(interface->name, "lo")) - system_info_register_interface( - sizeof(interface->hwaddr), - interface->hwaddr, interface->name); } + /* notify the sysinfo code about changes to this interface */ + if (strcmp(interface->name, "lo")) + system_info_register_interface( + sizeof(interface->hwaddr), + interface->hwaddr, interface->name, + info->ifi_flags & IFF_LOWER_UP); + configure_interface(network, interface, info->ifi_flags & IFF_UP, info->ifi_flags & IFF_LOWER_UP); @@ -483,7 +496,8 @@ retry: static void network_init_dns(struct network *network) { const struct config *config; - int i, rc, len; + unsigned int i; + int rc, len; bool modified; char *buf; @@ -544,8 +558,8 @@ struct network *network_init(struct device_handler *handler, network = talloc(handler, struct network); list_init(&network->interfaces); network->handler = handler; - network->manual_config = false; network->dry_run = dry_run; + network->manual_config = config_get()->network.n_interfaces != 0; network_init_dns(network); @@ -578,8 +592,13 @@ int network_shutdown(struct network *network) if (network->waiter) waiter_remove(network->waiter); - list_for_each_entry(&network->interfaces, interface, list) + list_for_each_entry(&network->interfaces, interface, list) { + if (interface->state == IFSTATE_IGNORED) + continue; + if (!strcmp(interface->name, "lo")) + continue; interface_down(interface); + } close(network->netlink_sd); talloc_free(network);