/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
*/
/*
* This program does the following:
*
* a) Returns:
* 0 - if the program successfully determined the net strategy.
* !0 - if an error occurred.
*
* b) If the program is successful, it prints three tokens to
* stdout: <root fs type> <interface name> <net config strategy>.
* where:
* <root fs type> - "nfs", "ufs" or "zfs"
* <interface name> - "hme0" or "none"
* <net config strategy> - "dhcp", "rarp", "bootprops"
* or "none"
*
* Eg:
* # /sbin/netstrategy
* ufs hme0 dhcp
*
* <root fs type> identifies the system's root file system type.
*
* <interface name> is the 16 char name of the root interface, and is only
*
* <net config strategy> can be either "rarp", "dhcp", "bootprops", or
* "none" depending on which strategy was used to configure the
* interface. Is "none" if no interface was configured using a
* net-based strategy.
*
* CAVEATS: what about autoclient systems? XXX
*
* in particular that code (which implements diskless boot) imposes an
* ordering on possible ways of configuring network interfaces.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <alloca.h>
#include <sys/systeminfo.h>
#include <libdevinfo.h>
static char *program;
static boolean_t
open_sockets(void)
{
return (B_FALSE);
}
return (B_FALSE);
}
return (B_TRUE);
}
static void
close_sockets(void)
{
}
static char *
{
/* root location */
return ("none");
} else {
return (vfs.f_basetype);
}
}
/*
* The following boot properties can be used to configure a network
* interface in the case of a diskless boot.
* host-ip, subnet-mask, server-path, server-name, server-ip.
*
* XXX non-diskless case requires "network-interface"?
*/
static boolean_t
{
/* XXX should use sys/bootprops.h, but it's not delivered */
const char *required_properties[] = {
"host-ip",
"subnet-mask",
"server-path",
"server-name",
"server-ip",
NULL,
};
char *prop_value;
return (B_FALSE);
}
return (B_FALSE);
}
prop++;
}
return (B_TRUE);
}
static char *
{
ifnum.lifn_flags = 0;
ifnum.lifn_count = 0;
return (NULL);
}
ifconf.lifc_flags = 0;
return (NULL);
}
continue; /* skip logical interfaces */
continue;
}
continue;
/*
* For the "nfs rarp" and "nfs bootprops"
* cases, we assume that the first non-virtual
* IFF_UP interface with a non-zero address is
* the one used.
*
* For the non-zero address check, we only check
* v4 interfaces, as it's not possible to set the
* the first logical interface (the only ones we
* look at here) to ::0; that interface must have
* a link-local address.
*
* If we don't find an IFF_UP interface with a
* non-zero address, we'll return the last IFF_UP
* interface seen.
*
* Since the order of the interfaces retrieved
* via SIOCGLIFCONF is not deterministic, this
* is largely silliness, but (a) "it's always
* been this way", and (b) no one consumes the
* interface name in the RARP case anyway.
*/
/* keep looking for a non-zero address */
continue;
}
return (interface);
}
}
/* ARGSUSED */
int
{
long len;
root = get_root_fstype();
if (!open_sockets()) {
"%s: cannot get interface information\n", program);
return (2);
}
/*
* If diskless, perhaps boot properties were used to configure
* the interface.
*/
strategy = "bootprops";
"%s: cannot identify root interface.\n", program);
return (2);
}
return (0);
}
/*
* Handle the simple case where diskless dhcp tells us everything
* we need to know.
*/
/* interface is first thing in cache. */
strategy = "dhcp";
return (0);
}
/*
* We're not "nfs dhcp", "nfs none" is impossible, and we don't handle
* "ufs rarp" (consumers are coded to deal with this reality), so
* there are three possible situations:
*
* 1. We're either "ufs dhcp" or "zfs dhcp" if there are any
* interfaces which have obtained their addresses through DHCP.
* That is, if there are any IFF_UP and non-IFF_VIRTUAL
* interfaces also have IFF_DHCPRUNNING set.
*
* 2. We're either "ufs none" or "zfs none" if our filesystem
* is local and there are no interfaces which have obtained
* their addresses through DHCP.
*
* 3. We're "nfs rarp" if our filesystem is remote and there's
* at least IFF_UP non-IFF_VIRTUAL interface (which there
* *must* be, since we're running over NFS somehow), then
* it must be RARP since SI_DHCP_CACHE call above failed.
* It's too bad there isn't an IFF_RARPRUNNING flag.
*/
if (dhcp_running)
strategy = "dhcp";
"%s: cannot identify root interface.\n", program);
return (2);
}
} else {
}
return (0);
}