/*
* 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
*/
/*
* sppptun.c - Solaris STREAMS PPP multiplexing tunnel driver
* installer.
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <stropts.h>
#include <fcntl.h>
#include <locale.h>
#include <netinet/if_ether.h>
#include <libdlpi.h>
/* Data gathered during per-style attach routine. */
struct attach_data {
};
/* Per-protocol plumbing data */
struct protos {
const char *name;
const char *desc;
struct attach_data *adata);
int style;
};
/*
* Print a usage string and terminate. Used for command line argument
* errors. Does not return.
*/
static void
usage(void)
{
"Usage:\n\t%s plumb [-s <sap>] [<protocol> <device>]\n"
"\t%s unplumb <interface-name>\n"
exit(1);
}
/*
* General DLPI function. This is called indirectly through
* the protos structure for the selected lower stream protocol.
*/
/* ARGSUSED */
static int
{
int retv;
if (verbose)
return (-1);
}
if (verbose) {
}
gettext("%s: failed binding on %s: %s\n"),
dlpi_close(dh);
return (-1);
}
dlpi_close(dh);
return (-1);
}
gettext("%s: interface name too long: %s\n"),
dlpi_close(dh);
return (-1);
}
}
PTS_PPPOE },
{ NULL }
};
/*
* Issue a STREAMS I_STR ioctl and fetch the result. Returns -1 on
* error, or length of returned data on success.
*/
static int
{
return (-1);
}
if (olen >= 0) {
return (-1);
}
}
}
/*
* Handle user request to plumb a new lower stream under the sppptun
* driver.
*/
static int
{
/* If no protocol requested, then list known protocols. */
(void) puts("Known tunneling protocols:");
return (0);
}
/* Parse plumbing flags */
switch (opt) {
case 's':
break;
default:
usage();
}
}
/* If missing protocol or device, then abort. */
usage();
/* Look up requested protocol. */
break;
return (1);
}
/* Get interface. */
/* Call per-protocol attach routine to open device */
if (verbose)
return (1);
/* Open sppptun driver */
if (verbose)
return (1);
}
/* Push sppptun module on top of lower driver. */
if (verbose)
linkname);
return (1);
}
/* Convert stream name to protocol-specific name. */
gettext("%s: stream name too long: %s:%s\n"),
return (1);
}
/* Change the lower stream name. */
if (verbose)
return (1);
}
/*
* Send down the local interface address to the lower stream
* so that it can originate packets.
*/
if (verbose)
0, "PPPTUN_LCLADDR") < 0)
return (1);
/*
* And set the SAP value.
*/
if (verbose)
"PPPTUN_SSAP") < 0)
return (1);
/* Link the lower stream under the tunnel device. */
if (verbose)
perror("I_PLINK");
return (1);
}
/*
* Give the tunnel driver the multiplex ID of the new lower
* stream. This allows the unplumb function to find and
* disconnect the lower stream.
*/
if (verbose)
"PPPTUN_SINFO") < 0)
return (1);
if (verbose)
else
return (0);
}
/*
* Handle user request to unplumb an existing lower stream from the
* sppptun driver.
*/
static int
{
char *ifname;
int muxfd;
/*
* Need to have the name of the lower stream on the command
* line.
*/
usage();
/* Open the tunnel driver. */
if (verbose)
return (1);
}
/* Get lower stream information; including multiplex ID. */
if (verbose)
sizeof (pti), "PPPTUN_GINFO") < 0)
return (1);
if (verbose)
/* Unlink lower stream from driver. */
if (verbose)
perror("I_PUNLINK");
return (1);
}
if (verbose)
return (0);
}
/*
* Handle user request to list lower streams plumbed under the sppptun
* driver.
*/
/*ARGSUSED*/
static int
{
int muxfd, i;
/* No other arguments permitted. */
usage();
/* Open the tunnel driver. */
if (verbose)
return (1);
}
/* Read and print names of lower streams. */
for (i = 0; ; i++) {
sizeof (ptn), "PPPTUN_GNNAME") < 0) {
perror("PPPTUN_GNNAME");
break;
}
/* Stop when we index off the end of the list. */
break;
}
return (0);
}
/*
* Invoked by SIGALRM -- timer prevents problems in driver from
* hanging the utility.
*/
/*ARGSUSED*/
static void
{
exit(1);
}
int
{
char *arg;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
/* Parse command line flags */
switch (opt) {
case 'v':
verbose++;
break;
default:
errflag++;
break;
}
usage();
/* Set alarm to avoid stalling on any driver errors. */
(void) alarm(2);
/* Switch out based on user-requested function. */
usage();
return (1);
}