X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/6d2010ae8f7a6078e10b361c6962983bab233e0f..527f99514973766e9c0382a4d8550dfb00f54939:/bsd/kern/netboot.c diff --git a/bsd/kern/netboot.c b/bsd/kern/netboot.c index 664f03ef7..e8bdddb34 100644 --- a/bsd/kern/netboot.c +++ b/bsd/kern/netboot.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2010 Apple Inc. All rights reserved. + * Copyright (c) 2001-2013 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -53,7 +53,6 @@ #include #include #include -#include #include #include @@ -86,9 +85,6 @@ IOBSDRegistryEntryGetData(void * entry, const char * property_name, #define BSDP_RESPONSE "bsdp-response" #define DHCP_RESPONSE "dhcp-response" -/* forward declarations */ -int inet_aton(char * cp, struct in_addr * pin); - #define IP_FORMAT "%d.%d.%d.%d" #define IP_CH(ip) ((u_char *)ip) #define IP_LIST(ip) IP_CH(ip)[0],IP_CH(ip)[1],IP_CH(ip)[2],IP_CH(ip)[3] @@ -591,6 +587,7 @@ find_interface(void) { struct ifnet * ifp = NULL; + dlil_if_lock(); if (rootdevice[0]) { ifp = ifunit((char *)rootdevice); } @@ -601,9 +598,44 @@ find_interface(void) break; ifnet_head_done(); } + dlil_if_unlock(); return (ifp); } +static const struct sockaddr_in blank_sin = { + sizeof(struct sockaddr_in), + AF_INET, + 0, + { 0 }, + { 0, 0, 0, 0, 0, 0, 0, 0 } +}; + +static int +inet_aifaddr(struct socket * so, const char * name, + const struct in_addr * addr, + const struct in_addr * mask, + const struct in_addr * broadcast) +{ + struct ifaliasreq ifra; + + bzero(&ifra, sizeof(ifra)); + strlcpy(ifra.ifra_name, name, sizeof(ifra.ifra_name)); + if (addr) { + *((struct sockaddr_in *)(void *)&ifra.ifra_addr) = blank_sin; + ((struct sockaddr_in *)(void *)&ifra.ifra_addr)->sin_addr = *addr; + } + if (mask) { + *((struct sockaddr_in *)(void *)&ifra.ifra_mask) = blank_sin; + ((struct sockaddr_in *)(void *)&ifra.ifra_mask)->sin_addr = *mask; + } + if (broadcast) { + *((struct sockaddr_in *)(void *)&ifra.ifra_broadaddr) = blank_sin; + ((struct sockaddr_in *)(void *)&ifra.ifra_broadaddr)->sin_addr = *broadcast; + } + return (ifioctl(so, SIOCAIFADDR, (caddr_t)&ifra, current_proc())); +} + + int netboot_mountroot(void) { @@ -626,8 +658,7 @@ netboot_mountroot(void) error = ENXIO; goto failed; } - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s%d", ifp->if_name, - ifp->if_unit); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", if_name(ifp)); printf("netboot: using network interface '%s'\n", ifr.ifr_name); /* bring it up */ @@ -644,12 +675,8 @@ netboot_mountroot(void) /* grab information from the registry */ if (get_ip_parameters(&iaddr, &netmask, &router) == FALSE) { - /* use DHCP to retrieve IP address, netmask and router */ - error = dhcp(ifp, &iaddr, 64, &netmask, &router, procp); - if (error) { - printf("netboot: DHCP failed %d\n", error); - goto failed; - } + printf("netboot: can't retrieve IP parameters\n"); + goto failed; } printf("netboot: IP address " IP_FORMAT, IP_LIST(&iaddr)); if (netmask.s_addr) {