multilink.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* multilink.c - support routines for multilink.
*
* Copyright (c) 2000-2001 by Sun Microsystems, Inc.
* All rights reserved.
*
* Copyright (c) 2000 Paul Mackerras.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms. The name of the author may not be
* used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define RCSID "$Id: $"
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <netdb.h>
#include <errno.h>
#include <signal.h>
#include "pppd.h"
#include "fsm.h"
#include "lcp.h"
#ifdef HAVE_MULTILINK
#include "tdb.h"
#endif
#endif
)
#ifdef HAVE_MULTILINK
bool endpoint_specified; /* user gave explicit endpoint discriminator */
char *bundle_id; /* identifier for our bundle */
void
{
if (!multilink)
return;
/* if we're doing multilink, we have to negotiate MRRU */
/* mrru not specified, default to mru */
}
/* get a default endpoint value */
if (wo->neg_endpoint)
dbglog("using default endpoint %s",
}
}
/*
* Make a new bundle or join us to an existing bundle
* if we are doing multilink.
*/
int
{
int l;
char *p;
/* not doing multilink */
notice("oops, multilink negotiated only for receive");
multilink = 0;
if (demand) {
/* already have a bundle */
cfg_bundle(0, 0, 0, 0);
return 0;
}
make_new_bundle(0, 0, 0, 0);
set_ifunit(1);
return 0;
}
/*
* Find the appropriate bundle or join a new one.
* First we make up a name for the bundle.
* The length estimate is worst-case assuming every
* character has to be quoted.
*
* Note - RFC 1990 requires that an unnegotiated endpoint
* discriminator value be equivalent to negotiating with class
* zero. Do not test ho->neg_endpoint here.
*/
if (bundle_name)
novm("bundle identifier");
p = bundle_id;
*p++ = '/';
if (bundle_name)
/*
* For demand mode, we only need to configure the bundle
* and attach the link.
*/
if (demand) {
return 0;
}
/*
* Check if the bundle ID is already in the database.
*/
unit = -1;
/* bundle ID exists, see if the pppd record exists */
/* it does, parse the interface number */
/* check the pid value */
|| !process_exists(pppd_pid)
unit = -1;
}
}
if (unit >= 0) {
/* attach to existing unit */
if (bundle_attach(unit)) {
set_ifunit(0);
return 1;
}
/* attach failed because bundle doesn't exist */
}
/* we have to make a new bundle */
set_ifunit(1);
return 0;
}
static int
char *str;
const char *key;
int *valp;
{
char *p, *endp;
int i;
if (p != 0) {
*valp = i;
return 1;
}
}
return 0;
}
/*
* Check whether the pppd identified by `key' still owns ppp unit `unit'.
*/
static int
int unit;
{
char ifkey[32];
int ret = 0;
}
return ret;
}
static int
{
return 1;
}
/* see if our hostname corresponds to a reasonable IP address */
if (!bad_ip_adrs(addr)) {
if (!LOCAL_IP_ADDR(addr)) {
return 1;
}
}
}
return 0;
}
#endif /* HAVE_MULTILINK */
/*
* epdisc_to_str - make a printable string from an endpoint discriminator.
*/
static char *endp_class_names[] = {
"null", "local", "IP", "MAC", "magic", "phone"
};
char *
{
int i, mask = 0;
char *q, c, c2;
return "null";
return str;
}
c = ':';
c2 = '.';
c2 = ':';
mask = 3;
q = str;
else
c = ':';
if ((i & mask) == 0) {
*q++ = c;
c = c2;
}
}
return str;
}
static int hexc_val(int c)
{
if (c >= 'a')
return c - 'a' + 10;
if (c >= 'A')
return c - 'A' + 10;
return c - '0';
}
int
char *str;
{
int i, l;
char *p, *endp;
for (i = EPD_NULL; i <= EPD_PHONENUM; ++i) {
break;
}
}
if (i > EPD_PHONENUM) {
/* not a class name, try a decimal class number */
option_error("cannot parse endpoint class in \"%s\"",
str);
return 0; /* can't parse class number */
}
}
if (*str == 0) {
return 1;
}
return 0;
}
++str;
if (i == EPD_IP) {
if (i == 0 || str[i] != 0)
return 0;
return 1;
}
if (i == EPD_MAC &&
return 1;
}
p = str;
for (l = 0; l < MAX_ENDP_LEN; ++l) {
if (*str == 0)
break;
if (p <= str)
;
i = p - str;
if (i == 0) {
return 0;
}
if ((i & 1) == 0)
++str;
}
if (*str != 0) {
option_error("too many bytes in value; max is %d",
return 0;
}
option_error("bad endpoint; MAC address must have 6 bytes");
return 0;
}
return 1;
}