common.c revision 32529ec11ac8e93a62985721612a18ee6bb8659a
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
*/
/*
* PPPoE common utilities and data.
*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <netdb.h>
#include <assert.h>
#include <stropts.h>
#include "common.h"
/* Not all functions are used by all applications. Let lint know this. */
/*LINTLIBRARY*/
/* Common I/O buffers */
/*
* Wrapper for standard strerror() function -- the standard allows
* that routine to return NULL, and that's inconvenient to handle.
* This function never returns NULL.
*/
const char *
mystrerror(int err)
{
const char *estr;
static char ebuf[64];
return (estr);
return (ebuf);
}
/*
* Wrapper for standard perror() function -- the standard definition
* of perror doesn't include the program name in the output and is
* thus inconvenient to use.
*/
void
{
mystrerror(errno));
}
/*
* Wrapper for standard getmsg() function. Completely discards any
* fragmented messages because we don't expect ever to see these from
* a properly functioning tunnel driver. Returns flags
* (MORECTL|MOREDATA) as seen by interface.
*/
int
{
int retv;
int hadflags;
return (hadflags);
do {
*flags = 0;
/*
* What remains at this point is the tail end of the
* truncated message. Toss it.
*/
}
/*
* Common wrapper function for STREAMS I_STR ioctl. Returns -1 on
* failure, 0 for success.
*/
int
{
return (-1);
}
return (-1);
}
return (0);
}
/*
* Format a PPPoE header in the user's buffer. The returned pointer
* is either identical to the first argument, or is NULL if it's not
* usable. On entry, dptr should point to the first byte after the
* Ethertype field, codeval should be one of the POECODE_* values, and
* sessionid should be the assigned session ID number or one of the
* special POESESS_* values.
*/
poep_t *
{
/* Discard obvious junk. */
/* Initialize the header */
return (poep);
}
/*
* Validate that a given tag is intact. This is intended to be used
* in tag-parsing loops before attempting to access the tag data.
*/
{
int plen;
return (B_FALSE);
return (B_FALSE);
/*
* Note careful dereference of tptr; it might be near the end
* already, so we have to range check it before dereferencing
* to get the actual tag length. Yes, it looks like we have
* duplicate array end checks. No, they're not duplicates.
*/
return (B_FALSE);
return (B_TRUE);
}
static int
{
int plen;
dlen = 0;
return (-1);
if (dlen > 0)
return (0);
}
/*
* Add a tag with text string data to a PPPoE packet being
* constructed. Returns -1 if it doesn't fit, or 0 for success.
*/
int
{
}
/*
* Add a tag with 32-bit integer data to a PPPoE packet being
* constructed. Returns -1 if it doesn't fit, or 0 for success.
*/
int
{
}
/*
* Add a tag with two 32-bit integers to a PPPoE packet being
* constructed. Returns -1 if it doesn't fit, or 0 for success.
*/
int
{
}
/*
* Copy a single tag and its data from one PPPoE packet to a PPPoE
* packet being constructed. Returns -1 if it doesn't fit, or 0 for
* success.
*/
int
{
int tlen;
int plen;
return (-1);
return (0);
}
struct tag_list {
int tl_type;
const char *tl_name;
};
/* List of PPPoE data tag types. */
{ POETT_END, "End-Of-List" },
{ POETT_SERVICE, "Service-Name" },
{ POETT_ACCESS, "AC-Name" },
{ POETT_UNIQ, "Host-Uniq" },
{ POETT_COOKIE, "AC-Cookie" },
{ POETT_VENDOR, "Vendor-Specific" },
{ POETT_RELAY, "Relay-Session-Id" },
{ POETT_NAMERR, "Service-Name-Error" },
{ POETT_SYSERR, "AC-System-Error" },
{ POETT_GENERR, "Generic-Error" },
{ POETT_MULTI, "Multicast-Capable" },
{ POETT_HURL, "Host-URL" },
{ POETT_MOTM, "Message-Of-The-Minute" },
{ POETT_RTEADD, "IP-Route-Add" },
{ 0, NULL }
};
/* List of PPPoE message code numbers. */
{ POECODE_DATA, "Data" },
{ POECODE_PADO, "Active Discovery Offer" },
{ POECODE_PADI, "Active Discovery Initiation" },
{ POECODE_PADR, "Active Discovery Request" },
{ POECODE_PADS, "Active Discovery Session-confirmation" },
{ POECODE_PADT, "Active Discovery Terminate" },
{ POECODE_PADM, "Active Discovery Message" },
{ POECODE_PADN, "Active Discovery Network" },
{ 0, NULL }
};
/*
* Given a tag type number, return a pointer to a string describing
* the tag.
*/
const char *
{
static char tname[32];
return (tname);
}
/*
* Given a PPPoE message code number, return a pointer to a string
* describing the message.
*/
const char *
{
static char tname[32];
return (tname);
}
/*
* Given a tunnel driver address structure, return a pointer to a
* string naming that Ethernet host.
*/
const char *
{
return ("NULL");
return (hbuf);
return (ether_ntoa(ea));
}
const char *
{
}
/*
* Given an Internet address (in network byte order), return a pointer
* to a string naming the host.
*/
const char *
{
struct sockaddr_in sin;
}
int
{
return ((int)(chr - '0'));
}