defs.h revision e704a8f24a369484ba8f4a1cf49d4db00dd91166
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Copyright (c) 1983, 1988, 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.
*
* @(#)defs.h 8.1 (Berkeley) 6/5/93
*
*/
#ifndef _DEFS_H
#define _DEFS_H
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Definitions for RIPv2 routing process.
*
* This code is based on the 4.4BSD `routed` daemon, with extensions to
* support:
* RIPv2, including variable length subnet masks.
* Router Discovery
* aggregate routes in the kernel tables.
* aggregate advertised routes.
* maintain spare routes for faster selection of another gateway
* when the current gateway dies.
* timers on routes with second granularity so that selection
* of a new route does not wait 30-60 seconds.
* tolerance of static routes.
* tell the kernel hop counts.
* use of per-interface ip_forwarding state.
*
* The vestigial support for other protocols has been removed. There
* is no likelihood that IETF RIPv1 or RIPv2 will ever be used with
* other protocols. The result is far smaller, faster, cleaner, and
* perhaps understandable.
*
* The accumulation of special flags and kludges added over the many
* years have been simplified and integrated.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <netdb.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdarg.h>
#include <syslog.h>
#include <time.h>
#include <md5.h>
#include <libintl.h>
#include <locale.h>
#include "radix.h"
#include <sys/sysmacros.h>
#define RIPVERSION RIPv2
/*
* Scan the kernel regularly to see if any interfaces have appeared or been
* turned off.
*/
/*
* Limit the seconds in the timeval structure "s" to "l" seconds, but only
* if l is less than the current seconds in s. This is used to shorten
* certain timers to ensure that scheduled events occur sooner than
* originally scheduled.
*/
/*
* Metric used for fake default routes. It ought to be 15, but when
* processing advertised routes, previous versions of `routed` added
* to the received metric and discarded the route if the total was 16
* or larger.
*/
/* Router Discovery parameters */
#define MAX_MAXADVERTISEINTERVAL 1800
#define MIN_MAXADVERTISEINTERVAL 4
#define DEF_MAXADVERTISEINTERVAL 600
#define DEF_PREFERENCELEVEL 0
#define MIN_PREFERENCELEVEL 0x80000000
#define MAX_INITIAL_ADVERT_INTERVAL 16
#define MAX_INITIAL_ADVERTS 3
#define MAX_RESPONSE_DELAY 2
#define MAX_SOLICITATION_DELAY 1
#define SOLICITATION_INTERVAL 3
#define MAX_SOLICITATIONS 3
/*
* convert between signed, balanced around zero,
* and unsigned zero-based preferences
*/
#define SIGN_PREF(p) ((p) ^ MIN_PREFERENCELEVEL)
#define UNSIGN_PREF(p) SIGN_PREF(p)
/*
* Bloated packet size for systems that simply add authentication to
* full-sized packets
*/
/* typical packet buffers */
union pkt_buf {
};
/*
* IF_NAME_LEN is the maximum size of interface names represented within
* in.routed. Regular Solaris interfaces have names of at most LIFNAMESIZ
* characters, but in.routed has remote interfaces represented internally
* as "remote(<gatewayname>)", where <gatewayname> is a hostname or IP
* address. IF_NAME_LEN needs to be large enough to also hold such
* interface names as well.
*/
/*
* No more routes than this, to protect ourself in case something goes
* whacko and starts broadcasting zillions of bogus routes.
*/
enum origin {
RO_NONE, /* empty slot */
RO_RIP, /* learnt from RIP */
RO_RDISC, /* learnt from RDISC */
RO_STATIC, /* learnt from kernel */
RO_LOOPBCK, /* loopback route */
RO_PTOPT, /* point-to-point route */
RO_NET_SYN, /* fake net route for subnet */
RO_IF, /* interface route */
};
/*
* Main, daemon routing table structure
*/
struct rt_spare {
enum origin rts_origin;
};
#define SPARE_INC 2
struct rt_entry {
struct sockaddr_in rt_dst_sock;
};
#define HOST_MASK 0xffffffffU
/*
* Determine if a route should be aged. Age all routes that are:
* Not from -g, -m, nor static routes from the kernel
* not unbroken interface routes but not broken interfaces
* nor non-passive, remote interfaces that are not aliases
* (i.e. remote & metric=0)
*/
(rts_origin != RO_RDISC) && \
(rts_origin != RO_FILE)) && \
/*
* true if A is better than B
* Better if
* - A is not a poisoned route
* - and A is not stale
* - and either:
* - A has a shorter path
* - or the router is speaking for itself
* - or B has the same metric and isn't stale
* - or A is a host route advertised by a system for itself
*/
((A)->rts_metric < (B)->rts_metric || \
((A)->rts_gate == (A)->rts_router && \
(B)->rts_gate != (B)->rts_router) || \
((A)->rts_metric == (B)->rts_metric && \
(A)->rts_metric == (B)->rts_metric)))
struct hlinkage {
void *hl_next;
void **hl_prev;
};
/*
* A "physical_interface" represents the actual hardware. It is also
* a container for a list of the interfaces that have the same ifIndex
* number. This will consist of zero or one "main" interface plus
* zero or more IS_ALIAS interfaces.
*/
struct physical_interface {
struct interface *phyi_interface;
struct phyi_data {
} phyi_data;
};
/*
* An "interface" is similar to a kernel ifnet structure, except it also
* handles "logical" or "IS_REMOTE" interfaces (remote gateways).
*/
struct interface {
/*
* We keep interfaces in a variety of data structures to
* optimize for different types of searches.
*/
#define MAX_AUTH_KEYS 5
struct auth { /* authentication info */
/*
* Although the following key is just an array of bytes,
* in.routed is currently limited to ascii characters
* because of its configuration syntax and parsing.
*/
/* router discovery parameters */
int int_rdisc_pref; /* signed preference to advertise */
struct timeval int_rdisc_timer;
};
/* bits in int_state */
/*
* passive interfaces are added through gwkludge
*/
#define IS_PASSIVE_IFP(ifp) \
/*
* Is an IP interface up? Because of the way IPMP uses deprecated
* interfaces, we need to check more than the IFF_UP and IFF_RUNNING
* interface flags here. Basically, we do not want to use IFF_DEPRECATED
* interfaces unless they are also IFF_STANDBY and not IFF_INACTIVE.
*/
#define IS_IFF_UP(f) \
(IFF_GOOD|IFF_STANDBY)))
/*
* This defines interfaces that we should not use for advertising or
* soliciting routes by way of RIP and rdisc. Interfaces marked this
* way do not count for purposes of determining how many interfaces
* this router has.
*/
/*
* This defines interfaces that we can use for advertising routes by way of
* RIP and rdisc.
*/
#define IS_IFF_ROUTING(f) \
/* Information for aggregating routes */
#define NUM_AG_SLOTS 32
struct ag_info {
#define AGS_REDUN1 0x008
== (AGS_REDUN0 | AGS_REDUN1))
/* this has the finer netmask */
/* has the coarser netmasks */
/* some bits are set if they are set on either route */
};
struct khash {
short k_metric;
};
#define KS_NEW 0x0001
#define KS_CHECK 0x0400
/* default router structure */
struct dr { /* accumulated advertisements */
};
/* parameters for interfaces */
struct parm {
};
/* authority for internal networks */
extern struct intnet {
struct intnet *intnet_next;
} *intnets;
/*
* Defined RIPv1 netmasks. These come from ripv1_mask entries in
*
* ripv1_mask=<net>/<match>,<mask>
*
* The intended use of these structures is to give RIPv1 destinations which
* are in <net>/<match> a netmask of <mask>, where <mask> > <match>.
*/
extern struct r1net {
struct r1net *r1net_next;
} *r1nets;
/* trusted routers */
extern struct tgate {
struct tgate *tgate_next;
#define MAX_TGATE_NETS 32
struct tgate_net {
} *tgates;
/* common output buffers */
extern struct ws_buf {
struct netinfo *n;
enum output_type type;
} v12buf;
extern int stopint; /* !=0 to stop in.routed */
extern int rip_sock; /* RIP socket */
extern int rt_sock; /* routing socket */
extern int rdisc_sock; /* router-discovery raw socket */
extern int rdisc_mib_sock; /* AF_UNIX mib info socket */
extern time_t now_expire;
extern time_t now_garbage;
extern int tracelevel, new_tracelevel;
#define MAX_TRACELEVEL 5
#define TRACEACTIONS (tracelevel != 0)
extern struct radix_node_head *rhead;
extern void fix_sock(int, const char *);
extern void fix_select(void);
extern void rip_off(void);
extern void bufinit(void);
extern void rip_query(void);
extern void rip_bcast(int);
enum output_type, int, int, boolean_t);
extern void msglog(const char *, ...);
extern void writelog(int, const char *, ...);
struct msg_limit {
struct msg_sub {
#define MSG_SUBJECT_N 8
} subs[MSG_SUBJECT_N];
};
#ifdef DEBUG
#else
#endif
extern char *naddr_ntoa(in_addr_t);
extern const char *saddr_ntoa(struct sockaddr_storage *);
extern const char *rip_strerror(int errnum);
extern void gwkludge(void);
extern const char *parse_parms(char *, boolean_t);
extern const char *insert_parm(struct parm *);
extern void lastlog(void);
extern void trace_close(int);
extern void set_tracefile(const char *, const char *, int);
extern void tracelevel_msg(const char *, int);
extern void trace_off(const char *, ...);
extern void set_tracelevel(void);
extern void trace_flush(void);
extern void trace_misc(const char *, ...);
extern void trace_act(const char *, ...);
extern void trace_pkt(const char *, ...);
extern void trace_add_del(const char *, struct rt_entry *);
const char *);
extern void trace_khash(const struct khash *);
struct rt_spare *);
extern void trace_rip(const char *, const char *, struct sockaddr_in *,
extern void set_rdisc_mg(struct interface *, int);
extern void set_supplier(void);
extern void if_bad_rdisc(struct interface *);
extern void if_ok_rdisc(struct interface *);
extern int read_rip(void);
extern void read_rt(void);
extern void read_d(void);
extern void process_d_mib_sock(void);
extern void rdisc_sol(void);
extern void *find_ancillary(struct msghdr *, int);
extern void rdisc_dump(void);
extern void rdisc_suppress(struct interface *);
extern void rdisc_restore(struct interface *);
extern void age_peer_info(void);
extern void sigtrace_more(int);
extern void sigtrace_less(int);
extern void sigtrace_dump(int);
extern void sync_kern(void);
extern void kern_dump(void);
extern void kern_flush_ifp(struct interface *);
void (*)(struct ag_info *));
struct interface *, int);
extern void rtinit(void);
char *);
struct rewire_data {
int metric_delta;
};
extern int parse_quote(char **, const char *, char *, char *, int);
extern void iftbl_alloc(void);
extern void ifscan(void);
extern int walk_bad(struct radix_node *, void *);
extern int walk_rewire(struct radix_node *, void *);
extern struct interface *ifwithname(const char *);
extern void rip_mcast_on(struct interface *);
extern void rip_mcast_off(struct interface *);
extern void trace_dump();
uint_t);
#ifdef __cplusplus
}
#endif
#endif /* _DEFS_H */