- int error = 0;
- struct in_addr iaddr = { 0 };
- struct ifreq ifr;
- struct ifnet * ifp;
- struct in_addr netmask = { 0 };
- proc_t procp = current_proc();
- struct in_addr router = { 0 };
- struct socket * so = NULL;
- unsigned int try;
-
- bzero(&ifr, sizeof(ifr));
-
- /* find the interface */
- ifp = find_interface();
- if (ifp == NULL) {
- printf("netboot: no suitable interface\n");
- error = ENXIO;
- goto failed;
- }
- 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 */
- if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0)) != 0) {
- printf("netboot: socreate, error=%d\n", error);
- goto failed;
- }
- ifr.ifr_flags = ifp->if_flags | IFF_UP;
- error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)&ifr, procp);
- if (error) {
- printf("netboot: SIFFLAGS, error=%d\n", error);
- goto failed;
- }
-
- /* grab information from the registry */
- if (get_ip_parameters(&iaddr, &netmask, &router) == FALSE) {
- printf("netboot: can't retrieve IP parameters\n");
- goto failed;
- }
- printf("netboot: IP address " IP_FORMAT, IP_LIST(&iaddr));
- if (netmask.s_addr) {
- printf(" netmask " IP_FORMAT, IP_LIST(&netmask));
- }
- if (router.s_addr) {
- printf(" router " IP_FORMAT, IP_LIST(&router));
- }
- printf("\n");
- error = inet_aifaddr(so, ifr.ifr_name, &iaddr, &netmask, NULL);
- if (error) {
- printf("netboot: inet_aifaddr failed, %d\n", error);
- goto failed;
- }
- if (router.s_addr == 0) {
- /* enable proxy arp if we don't have a router */
- router.s_addr = iaddr.s_addr;
- }
- printf("netboot: adding default route " IP_FORMAT "\n",
- IP_LIST(&router));
- error = default_route_add(router, router.s_addr == iaddr.s_addr);
- if (error) {
- printf("netboot: default_route_add failed %d\n", error);
- }
-
- soclose(so);
-
- S_netboot_info_p = netboot_info_init(iaddr);
- switch (S_netboot_info_p->image_type) {
- default:
- case kNetBootImageTypeNFS:
- for (try = 1; TRUE; try++) {
- error = nfs_mountroot();
- if (error == 0) {
- break;
- }
- printf("netboot: nfs_mountroot() attempt %u failed; "
- "clearing ARP entry and trying again\n", try);
- /*
- * error is either EHOSTDOWN or EHOSTUNREACH, which likely means
- * that the port we're plugged into has spanning tree enabled,
- * and either the router or the server can't answer our ARP
- * requests. Clear the incomplete ARP entry by removing the
- * appropriate route, depending on the error code:
- * EHOSTDOWN NFS server's route
- * EHOSTUNREACH router's route
- */
- switch (error) {
- default:
- /* NOT REACHED */
- case EHOSTDOWN:
- /* remove the server's arp entry */
- error = host_route_delete(S_netboot_info_p->server_ip,
- ifp->if_index);
- if (error) {
- printf("netboot: host_route_delete(" IP_FORMAT
- ") failed %d\n",
- IP_LIST(&S_netboot_info_p->server_ip), error);
+ int error = 0;
+ struct in_addr iaddr = { 0 };
+ struct ifreq ifr;
+ struct ifnet * ifp;
+ struct in_addr netmask = { 0 };
+ proc_t procp = current_proc();
+ struct in_addr router = { 0 };
+ struct socket * so = NULL;
+ unsigned int try;
+
+ bzero(&ifr, sizeof(ifr));
+
+ /* find the interface */
+ ifp = find_interface();
+ if (ifp == NULL) {
+ printf("netboot: no suitable interface\n");
+ error = ENXIO;
+ goto failed;
+ }
+ 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 */
+ if ((error = socreate(AF_INET, &so, SOCK_DGRAM, 0)) != 0) {
+ printf("netboot: socreate, error=%d\n", error);
+ goto failed;
+ }
+ ifr.ifr_flags = ifp->if_flags | IFF_UP;
+ error = ifioctl(so, SIOCSIFFLAGS, (caddr_t)&ifr, procp);
+ if (error) {
+ printf("netboot: SIFFLAGS, error=%d\n", error);
+ goto failed;
+ }
+
+ /* grab information from the registry */
+ if (get_ip_parameters(&iaddr, &netmask, &router) == FALSE) {
+ printf("netboot: can't retrieve IP parameters\n");
+ goto failed;
+ }
+ printf("netboot: IP address " IP_FORMAT, IP_LIST(&iaddr));
+ if (netmask.s_addr) {
+ printf(" netmask " IP_FORMAT, IP_LIST(&netmask));
+ }
+ if (router.s_addr) {
+ printf(" router " IP_FORMAT, IP_LIST(&router));
+ }
+ printf("\n");
+ error = inet_aifaddr(so, ifr.ifr_name, &iaddr, &netmask, NULL);
+ if (error) {
+ printf("netboot: inet_aifaddr failed, %d\n", error);
+ goto failed;
+ }
+ if (router.s_addr == 0) {
+ /* enable proxy arp if we don't have a router */
+ router.s_addr = iaddr.s_addr;
+ }
+ printf("netboot: adding default route " IP_FORMAT "\n",
+ IP_LIST(&router));
+ error = default_route_add(router, router.s_addr == iaddr.s_addr);
+ if (error) {
+ printf("netboot: default_route_add failed %d\n", error);
+ }
+
+ soclose(so);
+
+ S_netboot_info_p = netboot_info_init(iaddr);
+ switch (S_netboot_info_p->image_type) {
+ default:
+ case kNetBootImageTypeNFS:
+ for (try = 1; TRUE; try++) {
+ error = nfs_mountroot();
+ if (error == 0) {
+ break;
+ }
+ printf("netboot: nfs_mountroot() attempt %u failed; "
+ "clearing ARP entry and trying again\n", try);
+ /*
+ * error is either EHOSTDOWN or EHOSTUNREACH, which likely means
+ * that the port we're plugged into has spanning tree enabled,
+ * and either the router or the server can't answer our ARP
+ * requests. Clear the incomplete ARP entry by removing the
+ * appropriate route, depending on the error code:
+ * EHOSTDOWN NFS server's route
+ * EHOSTUNREACH router's route
+ */
+ switch (error) {
+ default:
+ /* NOT REACHED */
+ case EHOSTDOWN:
+ /* remove the server's arp entry */
+ error = host_route_delete(S_netboot_info_p->server_ip,
+ ifp->if_index);
+ if (error) {
+ printf("netboot: host_route_delete(" IP_FORMAT
+ ") failed %d\n",
+ IP_LIST(&S_netboot_info_p->server_ip), error);
+ }
+ break;
+ case EHOSTUNREACH:
+ error = host_route_delete(router, ifp->if_index);
+ if (error) {
+ printf("netboot: host_route_delete(" IP_FORMAT
+ ") failed %d\n", IP_LIST(&router), error);
+ }
+ break;
+ }