strplumb.c revision a08fa175a5f2205c2ca6df8da5595b44b965265b
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/bootconf.h>
#include <sys/bootprops.h>
#include <sys/ethernet.h>
#include <sys/ddi_implfuncs.h>
/*
* Debug Macros
*/
int strplumbdebug = 0;
if (strplumbdebug != 0) \
if (strplumbdebug != 0) \
if (strplumbdebug != 0) \
if (strplumbdebug != 0) \
/*
* Module linkage information for the kernel.
*/
#define STRPLUMB_IDENT "STREAMS Plumbing Module"
};
static struct modlinkage modlinkage = {
&modlmisc,
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
{
}
#define ARP "arp"
#define TCP "tcp"
#define TCP6 "tcp6"
#define UDP "udp"
#define UDP6 "udp6"
#define SCTP "sctp"
#define SCTP6 "sctp6"
#define ICMP "icmp"
#define ICMP6 "icmp6"
#define IP "ip"
#define IP6 "ip6"
#define TIMOD "timod"
typedef struct strplumb_modspec {
char *sm_type;
char *sm_name;
static strplumb_modspec_t strplumb_modlist[] = {
{ "drv", DLD_DRIVER_NAME },
{ "drv", IP },
{ "drv", IP6 },
{ "drv", TCP },
{ "drv", TCP6 },
{ "drv", UDP },
{ "drv", UDP6 },
{ "drv", SCTP },
{ "drv", SCTP6 },
{ "drv", ICMP },
{ "drv", ICMP6 },
{ "drv", ARP },
{ "strmod", TIMOD }
};
/*
* Called from swapgeneric.c:loadrootmodules() in the network boot case.
*/
int
strplumb_load(void)
{
uint_t i;
DBG0("loading modules\n");
for (i = 0, p = strplumb_modlist;
i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]);
i++, p++) {
printf("strplumb: failed to load %s/%s\n",
return (EFAULT);
}
}
return (0);
}
static int
strplumb_init(void)
{
uint_t i;
int err;
DBG0("initializing modules\n");
for (i = 0, p = strplumb_modlist;
i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]);
i++, p++) {
0 : EFAULT;
else
EFAULT : 0;
if (err != 0) {
printf("strplumb: failed to initialize %s/%s\n",
return (err);
}
}
return (0);
}
static int
strplumb_autopush(void)
{
char *mods[5];
int err;
/*
* ARP
*/
DBG0("setting up arp autopush\n");
mods)) != 0) {
return (err);
}
return (0);
}
static int
{
int err;
int rval;
DBG0("configuring SCTP default queue\n");
li)) != 0) {
return (err);
}
printf("strplumb: failed to set SCTP default queue: %d\n",
err);
return (err);
}
return (0);
}
static int
{
int err;
int rval;
DBG0("configuring TCP default queue\n");
/*
* We open IP6DEV here because we need to have it open to in
* order to open TCP6DEV successfully.
*/
li)) != 0) {
return (err);
}
/*
* We set the tcp default queue to IPv6 because IPv4 falls back to
* IPv6 when it can't find a client, but IPv6 does not fall back to
* IPv4.
*/
li)) != 0) {
goto done;
}
printf("strplumb: failed to set TCP default queue: %d\n",
err);
goto done;
}
done:
return (err);
}
/*
*/
char *ndev_name = 0;
int ndev_unit = 0;
/*
* If we booted diskless then strplumb() will have been called from
* swapgeneric.c:rootconf(). All we can do in that case is plumb the
* network device that we booted from.
*
* If we booted from a local disk, we will have been called from main(),
*/
static int
resolve_boot_path(void)
{
char *devpath;
const char *driver;
int instance;
#ifdef _OBP
char stripped_path[OBP_MAXPATHLEN];
#endif
else
#ifdef _OBP
/*
* OBP passes options e.g, "net:dhcp"
* remove them here
*/
#endif
/*
* Hold the devi since this is the root device.
*/
printf("strplumb: unable to hold root device: %s\n",
devpath);
return (ENXIO);
}
} else {
return (ENODEV);
printf("strplumb: cannot load ndev_name '%s'\n",
return (ENXIO);
}
}
return (0);
}
static int
{
int rval;
}
static int
{
int rval;
}
static int
{
int err;
int rval;
/*
* Now set up the links. Ultimately, we should have two streams
* permanently linked underneath UDP (which is actually IP with UDP
* autopushed). One stream consists of the ARP-[ifname] combination,
* while the other consists of ARP-IP-[ifname]. The second combination
* seems a little weird, but is linked underneath UDP just to keep it
* around.
*
* We pin underneath UDP here to match what is done in ifconfig(1m);
* otherwise, ifconfig will be unable to unplumb the stream (the major
* number and mux id must both match for a successful I_PUNLINK).
*
* There are subtleties in the plumbing which make it essential to
* follow the logic used in ifconfig(1m) very closely.
*/
/*
* Plumb UDP-ARP-IP-<dev>
*/
err);
goto done;
}
&rval)) != 0) {
goto done;
}
goto done;
&rval)) != 0) {
goto done;
}
goto done;
/* Get the flags and check if ARP is needed */
printf("strplumb: getifflags %s IP failed, error %d\n",
goto done;
}
/* Pop out ARP if not needed */
&rval);
if (err != 0) {
goto done;
}
}
li)) != 0) {
goto done;
}
&(ifr.ifr_ip_muxid))) != 0) {
printf("strplumb: plink UDP-ARP-IP-%s failed: %d\n",
goto done;
}
/*
* Plumb UDP-ARP-<dev>
*/
err);
goto done;
}
&rval)) != 0) {
goto done;
}
goto done;
&(ifr.ifr_arp_muxid))) != 0) {
printf("strplumb: plink UDP-ARP-%s failed: %d\n",
goto done;
}
/*
* Cache the mux ids.
*/
goto done;
}
done:
return (err);
}
/*
* Do streams plumbing for internet protocols.
*/
int
strplumb(void)
{
int err;
if ((err = strplumb_init()) != 0)
return (err);
if ((err = strplumb_autopush()) != 0)
return (err);
return (err);
/*
* Setup the TCP and SCTP default queues for the global stack.
* tcp/sctp_stack_init will do this for additional stack instances.
*/
goto done;
goto done;
if ((err = resolve_boot_path()) != 0)
goto done;
goto done;
done:
return (err);
}
/* multiboot: diskless boot interface discovery */
#ifndef _OBP
static int boot_maclen;
#endif /* !_OBP */
char *
strplumb_get_netdev_path(void)
{
#ifdef _OBP
char fstype[OBP_MAXPROPNAME];
return (NULL);
return (prom_bootpath());
else
return (NULL);
#else
/*
* hard coded ether mac len for booting floppy on
* machines with old cards
*/
if (boot_maclen != 6) {
"malformed boot_mac property, %d bytes",
}
== DDI_SUCCESS) {
/*
* These offsets are defined by dhcp standard
* Should use structure offsets
*/
} else
return (NULL);
return (devpath);
#endif /* _OBP */
}
#ifndef _OBP
/*
* Get boot path from the boot_mac address
*/
/*ARGSUSED*/
static int
{
char *model_str;
int maclen;
/* XXX Should use "device-type" per IEEE 1275 */
return (DDI_WALK_CONTINUE);
return (DDI_WALK_CONTINUE);
}
/* We have a network device now */
return (DDI_WALK_CONTINUE);
}
ASSERT(boot_maclen != 0);
return (DDI_WALK_CONTINUE);
if (maclen != boot_maclen ||
return (DDI_WALK_CONTINUE);
}
/* found hardware with the mac address */
/* fill in dhcifname */
if (dhcack) {
}
return (DDI_WALK_TERMINATE);
}
static uchar_t *
{
char ifname[16];
return (NULL);
}
*maclenp = sizeof (struct ether_addr);
return (macaddr);
}
static uchar_t *
{
char *clonepath;
/* a simpler way to get mac address for GLDv3 drivers */
maclenp));
}
"getmacaddr: ldi_ident_from_mod failed: %d\n", rc);
return (NULL);
}
if (rc) {
"getmacaddr: ldi_open_by_name(%s) failed: %d\n",
return (NULL);
}
return (NULL);
}
*maclenp = sizeof (struct ether_addr);
*maclenp = 0;
"getmacaddr: dl_macaddr(%s%d) failed: %d\n",
}
return (macaddr);
}
#endif /* !_OBP */
int
{
union DL_primitives *dl_prim;
int error;
return (ENOSR);
}
return (error);
}
switch (dl_prim->dl_primitive) {
case DL_OK_ACK:
"!dl_attach: DL_OK_ACK protocol error");
break;
}
break;
}
return (0);
case DL_ERROR_ACK:
"!dl_attach: DL_ERROR_ACK protocol error");
break;
}
break;
default:
break;
}
/*
* Error return only.
*/
return (-1);
}
int
{
union DL_primitives *dl_prim;
int error;
return (ENOSR);
}
bind_req->dl_xidtest_flg = 0;
return (error);
}
switch (dl_prim->dl_primitive) {
case DL_BIND_ACK:
"!dl_bind: DL_BIND_ACK protocol error");
break;
}
break;
}
return (0);
case DL_ERROR_ACK:
"!dl_bind: DL_ERROR_ACK protocol error");
break;
}
break;
default:
break;
}
/*
* Error return only.
*/
return (-1);
}
int
{
union DL_primitives *dl_prim;
int error;
return (ENOSR);
}
/*
* In case some provider doesn't implement or nack the
* request just wait for 15 seconds.
*/
return (-1);
} else if (error != 0) {
return (error);
}
switch (dl_prim->dl_primitive) {
case DL_PHYS_ADDR_ACK:
"DL_PHYS_ADDR_ACK protocol error");
break;
}
"!dl_phys_addr: DL_PHYS_ADDR_ACK bad len %u",
break;
}
if (phys_addr_ack->dl_addr_length +
"!dl_phys_addr: DL_PHYS_ADDR_ACK bad len %u",
break;
}
return (0);
case DL_ERROR_ACK:
"!dl_phys_addr: DL_ERROR_ACK protocol error");
break;
}
break;
default:
break;
}
/*
* Error return only.
*/
return (-1);
}