revarp.c revision 0689f76c08c5e553ff25ac43a852b56c430bb61e
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include "defs.h"
#include "ifconfig.h"
#include <libdlpi.h>
#include <sys/sysmacros.h>
#include <deflt.h>
#define RARPRETRIES 5
/*
* The following value (8) is determined to work reliably in switched 10/100MB
* ethernet environments. Use caution if you plan on decreasing it.
*/
#define RARPTIMEOUT 8
static char defaultfile[] = "/etc/inet/rarp";
static char retries_var[] = "RARP_RETRIES=";
static int rarp_timeout = RARPTIMEOUT;
static int rarp_retries = RARPRETRIES;
int
{
int s, retval;
int tries_left;
if (linkname[0] == '\0') {
exit(1);
}
if (debug)
Perror0_exit("socket");
(void) close(s);
Perror0_exit("SIOCGLIFFLAGS");
}
/* don't try to revarp if we know it won't work */
(void) close(s);
return (0);
}
/* open rarp interface */
(void) close(s);
return (0);
}
/*
* with 6 byte addresses currently.
*/
if (physaddrlen != ETHERADDRL) {
dlpi_close(dh);
(void) close(s);
return (0);
}
/* look for adjustments to rarp_retries in the RARP defaults file */
if (defopen(defaultfile) == 0) {
char *cp;
int ntries;
if (ntries > 0)
}
}
/* allocate request and response buffers */
dlpi_close(dh);
(void) close(s);
return (0);
}
/* create rarp request */
/* send the request */
if (retval != DLPI_SUCCESS) {
Perrdlpi("doifrevarp: cannot send rarp request",
break;
}
if (debug)
(void) printf("rarp sent\n");
rarp_timeout * MILLISEC);
if (retval != DLPI_ETIMEDOUT)
break;
if (debug)
(void) printf("rarp retry\n");
}
if (retval == DLPI_SUCCESS) {
sizeof (answer));
if (debug) {
}
} else if (debug) {
Perrdlpi("doifrevarp: could not receive rarp reply",
}
dlpi_close(dh);
(void) close(s);
return (retval == DLPI_SUCCESS);
}
/*
* Open the datalink provider device and bind to the REVARP type.
* Return the resulting DLPI handle.
*/
static dlpi_handle_t
{
int retval;
if (debug)
return (NULL);
}
goto failed;
}
goto failed;
}
if (dlinfo.di_bcastaddrlen == 0) {
"not supported\n", linkname);
goto failed;
}
/* we assume the following are equal and fill in 'alen' */
if (debug) {
(void) printf("device %s: broadcast address %s, mac "
}
(void) printf("rarp_open: addr length = %d\n",
}
return (dh);
dlpi_close(dh);
return (NULL);
}
/*
* Read reply for RARP request. If a reply is received within waitms,
* validate the reply. If it is a correct RARP reply return DLPI_SUCCESS,
* otherwise return DLPI_ETIMEDOUT. If there is an error while reading retrun
* the error code.
*/
static int
{
int retval;
char *cause;
if (retval == DLPI_SUCCESS) {
cause = "short packet";
cause = "hardware type not Ethernet";
cause = "protocol type not IP";
cause = "unexpected hardware address length";
cause = "unexpected protocol address length";
"but discarded (%s)\n", cause);
continue;
}
case REVARP_REQUEST:
if (debug)
(void) printf("Got a rarp request.\n");
break;
case REVARP_REPLY:
return (DLPI_SUCCESS);
default:
break;
}
} else if (retval != DLPI_ETIMEDOUT) {
Perrdlpi("doifrevarp: dlpi_recv failed",
return (retval);
}
}
return (DLPI_ETIMEDOUT);
}
void
dlpi_print_address(const char *linkname)
{
char *str;
int retv;
/* Do not report an error */
return;
}
if (retv != DLPI_SUCCESS) {
dlpi_close(dh);
return;
}
if (retv != DLPI_SUCCESS) {
dlpi_close(dh);
return;
}
dlpi_close(dh);
switch (dlinfo.di_mactype) {
case DL_IB:
break;
default:
break;
}
}
}