parms.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgment:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "defs.h"
#include "pathnames.h"
#include <ctype.h>
#define PARMS_MAXLINELEN 500
/* use configured parameters */
void
{
int i, num_passwds = 0;
return;
/* get all relevant parameters */
/*
* This group of parameters is relevant,
* so get its settings
*/
for (i = 0; i < MAX_AUTH_KEYS; i++) {
break;
}
if (parmp->parm_rdisc_pref != 0)
if (parmp->parm_rdisc_int != 0)
if (parmp->parm_d_metric != 0)
if (parmp->parm_ripout_addr != 0)
}
}
/*
* Set general defaults.
*
* Default poor-man's router discovery to a metric that will
* be heard by old versions of `routed`. They ignored received
* routes with metric 15.
*/
if (ifp->int_rdisc_int == 0)
/*
* By default, point-to-point links should be passive
* about router-discovery for the sake of demand-dialing.
*/
}
" will be accepted without authentication",
}
if (!warned_auth_out) {
" will be sent without authentication",
}
}
/*
* If not overriden by the rip_neighbor option, set the
* default address to which RIP packets will be sent on
* this interface.
*/
if (ifp->int_ripout_addr == 0) {
/*
* By definition we always send RIP packets to
* the address assigned to a remote interface.
*/
/*
* If the interface is being used for RIPv2
* and it supports multicast, and if the user
* has not explicitely turned off multicast
* RIP output, send to the all RIP routers
* multicast address.
*/
/*
* For point-to-point interfaces which don't
* fall into the two categories above, just
* send to the destination address of the
* interface.
*/
} else {
/* Otherwise, use the broadcast address. */
}
}
}
/*
*
* This file contains a list of "remote" gateways. That is usually
* a gateway which we cannot immediately determine if it is present or
* not as we can do for those provided by directly connected hardware.
*
* If a gateway is marked "passive" in the file, then we assume it
* does not understand RIP and assume it is always present. Those
* not marked passive are treated as if they were directly connected
* and assumed to be broken if they do not send us advertisements.
* All remote interfaces are added to our list, and those not marked
* passive are sent routing updates.
*
* A passive interface can also be local, hardware interface exempt
* from RIP.
*/
void
gwkludge(void)
{
#define STR2(x) #x
#define NETHOST_LEN 4
#define DNAME_LEN MAXHOSTNAMELEN
#define GNAME_LEN MAXHOSTNAMELEN
#define QUAL_LEN 8
char *p, *lptr;
const char *cp;
int n;
return;
return;
}
break;
/* Eliminate the /n character at the end of the lbuf */
/* Move lptr to the first non-space character */
;
continue;
/* Move p to the end of the line */
/* Skip all trailing spaces except escaped space */
p--;
/* truncate the line to remove trailing spaces */
*++p = '\0';
/* notice newfangled parameter lines */
if (cp != 0)
continue;
}
/*
* Processes lines of the follwoing format:
* net|host <name>[/mask] gateway <Gname> metric <value>
* passive|active|extern
*/
qual[0] = '\0';
if (n != 4 && n != 5) {
lptr, n);
continue;
}
if (metric >= HOPCNT_INFINITY) {
lptr);
continue;
}
continue;
}
continue;
}
} else {
continue;
}
continue;
}
/*
* Passive entries are not placed in our tables,
* only the kernel's, so we don't copy all of the
* external routing information within a net.
* Internal machines should use the default
* route to a suitable gateway (like us).
*/
if (metric == 0)
metric = 1;
/*
* External entries are handled by other means
* such as EGP, and are placed only in the daemon
* tables to prevent overriding them with something
* else.
*/
if (metric == 0)
metric = 1;
qual[0] == '\0') {
if (default_dst) {
" entry \"%s\"-- cannot be default",
continue;
}
if (metric != 0) {
/*
* Entries that are neither "passive" nor
* "external" are "remote" and must behave
* like physical interfaces. If they are not
* heard from regularly, they are deleted.
*/
} else {
/*
* "remote" entries with a metric of 0
* are aliases for our own interfaces
*/
}
} else {
continue;
}
state |= IS_NO_RDISC;
if (state & IS_PASSIVE)
if (default_dst) {
continue;
}
continue;
}
else
if (!(state & IS_EXTERNAL) &&
"remote(%s)", gname);
}
/*
* After all of the parameter lines have been read,
* apply them to any remote interfaces.
*/
}
}
/* Parse password timestamp */
static char *
char **valp,
char *val0,
char *delimp,
char *buf,
{
return (buf);
}
return (buf);
}
/* assume small years are in the 3rd millenium */
return (buf);
}
return (NULL);
}
/*
* Get a password, key ID, and expiration date in the format
* returns NULL or error message
*/
static const char *
get_passwd(char *tgt,
char *val,
{
static char buf[80];
int i;
ulong_t l;
if (!safe)
return ("ignore unsafe password");
i++, ap++) {
if (i >= MAX_AUTH_KEYS)
return ("too many passwords");
}
(void) memset(&k, 0, sizeof (k));
return (tgt);
if (delim != '|') {
if (type == RIP_AUTH_MD5)
return ("missing Keyid");
} else {
sizeof (buf)) ||
p == buf || *p != '\0') {
"bad KeyID \"%.20s\"", val0);
return (buf);
}
"duplicate KeyID \"%.20s\"",
val0);
return (buf);
}
}
k.keyid = (int)l;
if (delim == '|') {
return (p);
if (delim != '|')
return ("missing second timestamp");
return (p);
"out of order timestamp %.30s", val0);
return (buf);
}
}
}
if (delim != '\0')
return (tgt);
return (NULL);
}
static const char *
{
return (buf);
}
/*
* Parse a set of parameters for an interface.
* returns NULL or error message
*/
const char *
parse_parms(char *line,
{
/*
* This macro checks for conflicting configurations options
* For eg one can set either the IS_NO_SOL_OUT flag bit or the IS_SOL_OUT flag
* bit, but not both.
*/
parm.parm_int_state |= (b); }
const char *msg;
int i;
"parse_parms subnet");
if (delim == ',') {
val+1 == p ||
}
}
&intnetp->intnet_mask) ||
}
return (NULL);
}
/*
*/
delim == '\0')
*p != '\0')
}
return (NULL);
}
/*
* Support of the following for Solaris backward compatibility
* norip <ifname>
* noripin <ifname>
* noripout <ifname>
*/
int n;
if (n != 2) {
/* Not enough parameters */
}
/*
* Get the interface name and turn on the appropriate
* interface flags
*/
} else {
/* Bad command */
}
/*
* Look for duplication, and if new,
* link to the rest of the parm entries.
*/
return (insert_parm(&parm));
}
for (;;) {
break;
if (delim == '=') {
}
if (delim != '\0') {
for (;;) {
*line = '\0';
if (delim == '#')
break;
++line;
break;
}
}
if (PARSEQ("if")) {
} else if (PARSEQ("addr")) {
/*
* This is a bad idea, because the address based
* sets of parameters cannot be checked for
* consistency with the interface name parameters.
* The parm_net stuff is needed to allow several
* -F settings.
*/
} else if (PARSEQ("passwd")) {
/*
* since cleartext passwords are so weak allow
* them anywhere
*/
if (msg) {
*val0 = '\0';
}
} else if (PARSEQ("md5_passwd")) {
if (msg) {
*val0 = '\0';
}
} else if (PARS("no_ag")) {
} else if (PARS("no_host")) {
} else if (PARS("no_super_ag")) {
} else if (PARS("no_ripv1_in")) {
} else if (PARS("no_ripv2_in")) {
} else if (PARS("ripv2_out")) {
} else if (PARS("ripv2")) {
| IS_NO_RIPV1_OUT);
} else if (PARS("no_rip")) {
} else if (PARS("no_rip_mcast")) {
} else if (PARS("no_rdisc")) {
} else if (PARS("no_solicit")) {
} else if (PARS("send_solicit")) {
} else if (PARS("no_rdisc_adv")) {
} else if (PARS("rdisc_adv")) {
} else if (PARS("bcast_rdisc")) {
} else if (PARS("passive")) {
} else if (PARSEQ("rdisc_pref")) {
if (parm.parm_rdisc_pref != 0 ||
*p != '\0') || (buf == p))
} else if (PARS("pm_rdisc")) {
} else if (PARSEQ("rdisc_interval")) {
if (parm.parm_rdisc_int != 0 ||
*p != '\0') || (buf == p) ||
} else if (PARSEQ("fake_default")) {
if (parm.parm_d_metric != 0 ||
*p != '\0') || (buf == p) ||
} else if (PARSEQ("trust_gateway")) {
p = buf;
"parse_parms trust_gateway");
i = 0;
/* The default is to trust all routes. */
while (delim == '|') {
p++;
if (i >= MAX_TGATE_NETS ||
sizeof (buf2)) ||
}
i++;
}
} else if (PARS("redirect_ok")) {
} else if (PARSEQ("rip_neighbor")) {
} else {
}
}
return (insert_parm(&parm));
}
/*
* Insert parameter specifications into the parms list. Returns NULL if
* successful, or an error message otherwise.
*/
const char *
{
int i, num_passwds;
/* set implicit values */
for (i = num_passwds = 0; i < MAX_AUTH_KEYS; i++) {
num_passwds++;
}
/* compare with existing sets of parameters */
continue;
continue;
for (i = 0; i < MAX_AUTH_KEYS; i++) {
num_passwds++;
}
if (num_passwds > MAX_AUTH_KEYS)
return ("too many conflicting passwords");
GROUP_IS_SOL_OUT)) ||
GROUP_IS_ADV_OUT)) ||
(new->parm_rdisc_pref != 0 &&
parmp->parm_rdisc_pref != 0 &&
(new->parm_rdisc_int != 0 &&
parmp->parm_rdisc_int != 0 &&
return ("conflicting, duplicate router discovery"
" parameters");
}
return ("conflicting, duplicate poor man's router"
" discovery or fake default metric");
}
}
/*
* link new entry on the list so that when the entries are scanned,
* they affect the result in the order the operator specified.
*/
return (NULL);
}
int /* 0=bad */
{
/*
* Try for a number first. This avoids hitting the name
* server which might be sick because routing is.
*/
/*
* get a good number, but check that it makes some
* sense.
*/
return (0);
return (1);
}
return (1);
}
return (0);
}
static void
{
naddr_ntoa(gate));
return;
}
/* Get the ifp of the physical interface */
}