Module Name: src
Committed By: joerg
Date: Tue Aug 30 21:26:11 UTC 2011
Modified Files:
src/usr.sbin/route6d: route6d.c
Log Message:
static + __dead + G/C
To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.sbin/route6d/route6d.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/route6d/route6d.c
diff -u src/usr.sbin/route6d/route6d.c:1.63 src/usr.sbin/route6d/route6d.c:1.64
--- src/usr.sbin/route6d/route6d.c:1.63 Fri Apr 23 15:30:30 2010
+++ src/usr.sbin/route6d/route6d.c Tue Aug 30 21:26:11 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: route6d.c,v 1.63 2010/04/23 15:30:30 plunky Exp $ */
+/* $NetBSD: route6d.c,v 1.64 2011/08/30 21:26:11 joerg Exp $ */
/* $KAME: route6d.c,v 1.94 2002/10/26 20:08:55 itojun Exp $ */
/*
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: route6d.c,v 1.63 2010/04/23 15:30:30 plunky Exp $");
+__RCSID("$NetBSD: route6d.c,v 1.64 2011/08/30 21:26:11 joerg Exp $");
#endif
#include <stdbool.h>
@@ -129,16 +129,16 @@
struct iff *iff_next;
};
-struct ifc *ifc;
-int nifc; /* number of valid ifc's */
-struct ifc **index2ifc;
-int nindex2ifc;
-struct ifc *loopifcp = NULL; /* pointing to loopback */
-struct pollfd set[2];
-int rtsock; /* the routing socket */
-int ripsock; /* socket to send/receive RIP datagram */
+static struct ifc *ifc;
+static int nifc; /* number of valid ifc's */
+static struct ifc **index2ifc;
+static int nindex2ifc;
+static struct ifc *loopifcp = NULL; /* pointing to loopback */
+static struct pollfd set[2];
+static int rtsock; /* the routing socket */
+static int ripsock; /* socket to send/receive RIP datagram */
-struct rip6 *ripbuf; /* packet buffer for sending */
+static struct rip6 *ripbuf; /* packet buffer for sending */
/*
* Maintain the routes in a linked list. When the number of the routes
@@ -163,41 +163,38 @@
int rrt_index; /* ifindex from which this route got */
};
-struct riprt *riprt = 0;
+static struct riprt *riprt = 0;
-int dflag = 0; /* debug flag */
-int qflag = 0; /* quiet flag */
-int nflag = 0; /* don't update kernel routing table */
-int aflag = 0; /* age out even the statically defined routes */
-int hflag = 0; /* don't split horizon */
-int lflag = 0; /* exchange site local routes */
-int sflag = 0; /* announce static routes w/ split horizon */
-int Sflag = 0; /* announce static routes to every interface */
-unsigned long routetag = 0; /* route tag attached on originating case */
+static int dflag = 0; /* debug flag */
+static int qflag = 0; /* quiet flag */
+static int nflag = 0; /* don't update kernel routing table */
+static int aflag = 0; /* age out even the statically defined routes */
+static int hflag = 0; /* don't split horizon */
+static int lflag = 0; /* exchange site local routes */
+static int sflag = 0; /* announce static routes w/ split horizon */
+static int Sflag = 0; /* announce static routes to every interface */
+static unsigned long routetag = 0; /* route tag attached on originating case */
-char *filter[MAXFILTER];
-int filtertype[MAXFILTER];
-int nfilter = 0;
+static char *filter[MAXFILTER];
+static int filtertype[MAXFILTER];
+static int nfilter = 0;
-pid_t pid;
+static pid_t pid;
-struct sockaddr_storage ripsin;
+static struct sockaddr_storage ripsin;
-struct rtentry rtentry;
+static int interval = 1;
+static time_t nextalarm = 0;
-int interval = 1;
-time_t nextalarm = 0;
-time_t sup_trig_update = 0;
+static FILE *rtlog = NULL;
-FILE *rtlog = NULL;
-
-int logopened = 0;
+static int logopened = 0;
static int seq = 0;
-volatile sig_atomic_t seenalrm;
-volatile sig_atomic_t seenquit;
-volatile sig_atomic_t seenusr1;
+static volatile sig_atomic_t seenalrm;
+static volatile sig_atomic_t seenquit;
+static volatile sig_atomic_t seenusr1;
#define RRTF_AGGREGATE 0x08000000
#define RRTF_NOADVERTISE 0x10000000
@@ -205,77 +202,66 @@
#define RRTF_SENDANYWAY 0x40000000
#define RRTF_CHANGED 0x80000000
-int main(int, char **);
-void sighandler(int);
-void ripalarm(void);
-void riprecv(void);
-void ripsend(struct ifc *, struct sockaddr_in6 *, int);
-int out_filter(struct riprt *, struct ifc *);
-void init(void);
-void sockopt(struct ifc *);
-void ifconfig(void);
-void ifconfig1(const char *, const struct sockaddr *, struct ifc *, int);
-void rtrecv(void);
-int rt_del(const struct sockaddr_in6 *, const struct sockaddr_in6 *,
+static void sighandler(int);
+static void ripalarm(void);
+static void riprecv(void);
+static void ripsend(struct ifc *, struct sockaddr_in6 *, int);
+static int out_filter(struct riprt *, struct ifc *);
+static void init(void);
+static void ifconfig(void);
+static void ifconfig1(const char *, const struct sockaddr *, struct ifc *, int);
+static void rtrecv(void);
+static int rt_del(const struct sockaddr_in6 *, const struct sockaddr_in6 *,
const struct sockaddr_in6 *);
-int rt_deladdr(struct ifc *, const struct sockaddr_in6 *,
+static int rt_deladdr(struct ifc *, const struct sockaddr_in6 *,
const struct sockaddr_in6 *);
-void filterconfig(void);
-int getifmtu(int);
-const char *
+static void filterconfig(void);
+static int getifmtu(int);
+static const char *
rttypes(struct rt_msghdr *);
-const char *
+static const char *
rtflags(struct rt_msghdr *);
-const char *
+static const char *
ifflags(int);
-int ifrt(struct ifc *, int);
-void ifrt_p2p(struct ifc *, int);
-void applymask(struct in6_addr *, struct in6_addr *);
-void applyplen(struct in6_addr *, int);
-void ifrtdump(int);
-void ifdump(int);
-void ifdump0(FILE *, const struct ifc *);
-void rtdump(int);
-void rt_entry(struct rt_msghdr *, int);
-void rtdexit(void);
-void riprequest(struct ifc *, struct netinfo6 *, int,
+static int ifrt(struct ifc *, int);
+static void ifrt_p2p(struct ifc *, int);
+static void applyplen(struct in6_addr *, int);
+static void ifrtdump(int);
+static void ifdump(int);
+static void ifdump0(FILE *, const struct ifc *);
+static void rtdump(int);
+static void rt_entry(struct rt_msghdr *, int);
+static void rtdexit(void) __dead;
+static void riprequest(struct ifc *, struct netinfo6 *, int,
struct sockaddr_in6 *);
-void ripflush(struct ifc *, struct sockaddr_in6 *);
-void sendrequest(struct ifc *);
-int sin6mask2len(const struct sockaddr_in6 *);
-int mask2len(const struct in6_addr *, int);
-int sendpacket(struct sockaddr_in6 *, int);
-int addroute(struct riprt *, const struct in6_addr *, struct ifc *);
-int delroute(struct netinfo6 *, struct in6_addr *);
-struct in6_addr *
- getroute(struct netinfo6 *, struct in6_addr *);
-void krtread(int);
-int tobeadv(struct riprt *, struct ifc *);
-char * allocopy(char *);
-char * hms(void);
-const char *
+static void ripflush(struct ifc *, struct sockaddr_in6 *);
+static void sendrequest(struct ifc *);
+static int sin6mask2len(const struct sockaddr_in6 *);
+static int mask2len(const struct in6_addr *, int);
+static int sendpacket(struct sockaddr_in6 *, int);
+static int addroute(struct riprt *, const struct in6_addr *, struct ifc *);
+static int delroute(struct netinfo6 *, struct in6_addr *);
+static void krtread(int);
+static int tobeadv(struct riprt *, struct ifc *);
+static char * allocopy(char *);
+static char * hms(void);
+static const char *
inet6_n2p(const struct in6_addr *);
-struct ifac *
+static struct ifac *
ifa_match(const struct ifc *, const struct in6_addr *, int);
-struct in6_addr *
+static struct in6_addr *
plen2mask(int);
-struct riprt *
+static struct riprt *
rtsearch(struct netinfo6 *, struct riprt **);
-int ripinterval(int);
-time_t ripsuptrig(void);
-void fatal(const char *, ...)
- __attribute__((__format__(__printf__, 1, 2)));
-void trace(int, const char *, ...)
- __attribute__((__format__(__printf__, 2, 3)));
-void tracet(int, const char *, ...)
- __attribute__((__format__(__printf__, 2, 3)));
-unsigned int
- if_maxindex(void);
-struct ifc *
+static int ripinterval(int);
+static void fatal(const char *, ...) __printflike(1, 2) __dead;
+static void trace(int, const char *, ...) __printflike(2, 3);
+static void tracet(int, const char *, ...) __printflike(2, 3);
+static struct ifc *
ifc_find(char *);
-struct iff *
+static struct iff *
iff_find(struct ifc *, int);
-void setindex2ifc(int, struct ifc *);
+static void setindex2ifc(int, struct ifc *);
#define MALLOC(type) ((type *)malloc(sizeof(type)))
@@ -475,7 +461,7 @@
}
}
-void
+static void
sighandler(int signo)
{
@@ -499,7 +485,7 @@
* gracefully exits after resetting sockopts.
*/
/* ARGSUSED */
-void
+static void
rtdexit(void)
{
struct riprt *rrt;
@@ -526,7 +512,7 @@
* routes more precisely.
*/
/* ARGSUSED */
-void
+static void
ripalarm(void)
{
struct ifc *ifcp;
@@ -566,7 +552,7 @@
alarm(ripinterval(SUPPLY_INTERVAL6));
}
-void
+static void
init(void)
{
int i, error;
@@ -672,7 +658,7 @@
static int nrt;
static struct netinfo6 *nip;
-void
+static void
ripflush(struct ifc *ifcp, struct sockaddr_in6 *sin6)
{
int i;
@@ -721,7 +707,7 @@
/*
* Generate RIP6_RESPONSE packets and send them.
*/
-void
+static void
ripsend(struct ifc *ifcp, struct sockaddr_in6 *sin6, int flag)
{
struct riprt *rrt;
@@ -847,7 +833,7 @@
/*
* outbound filter logic, per-route/interface.
*/
-int
+static int
out_filter(struct riprt *rrt, struct ifc *ifcp)
{
struct iff *iffp;
@@ -918,7 +904,7 @@
* Determine if the route is to be advertised on the specified interface.
* It checks options specified in the arguments and the split horizon rule.
*/
-int
+static int
tobeadv(struct riprt *rrt, struct ifc *ifcp)
{
@@ -943,7 +929,7 @@
/*
* Send a rip packet actually.
*/
-int
+static int
sendpacket(struct sockaddr_in6 *sin6, int len)
{
struct msghdr m;
@@ -1002,7 +988,7 @@
* Receive and process RIP packets. Update the routes/kernel forwarding
* table if necessary.
*/
-void
+static void
riprecv(void)
{
struct ifc *ifcp, *ic;
@@ -1291,7 +1277,7 @@
/*
* Send all routes request packet to the specified interface.
*/
-void
+static void
sendrequest(struct ifc *ifcp)
{
struct netinfo6 *np;
@@ -1319,7 +1305,7 @@
/*
* Process a RIP6_REQUEST packet.
*/
-void
+static void
riprequest(struct ifc *ifcp, struct netinfo6 *np, int nn,
struct sockaddr_in6 *sin6)
{
@@ -1348,7 +1334,7 @@
/*
* Get information of each interface.
*/
-void
+static void
ifconfig(void)
{
struct ifaddrs *ifap, *ifa;
@@ -1420,7 +1406,7 @@
freeifaddrs(ifap);
}
-void
+static void
ifconfig1(const char *name, const struct sockaddr *sa, struct ifc *ifcp, int s)
{
struct in6_ifreq ifr;
@@ -1497,7 +1483,7 @@
* Receive and process routing messages.
* Update interface information as necessary.
*/
-void
+static void
rtrecv(void)
{
char buf[BUFSIZ];
@@ -1730,7 +1716,7 @@
/*
* remove specified route from the internal routing table.
*/
-int
+static int
rt_del(const struct sockaddr_in6 *sdst, const struct sockaddr_in6 *sgw,
const struct sockaddr_in6 *smask)
{
@@ -1827,7 +1813,7 @@
/*
* remove specified address from internal interface/routing table.
*/
-int
+static int
rt_deladdr(struct ifc *ifcp, const struct sockaddr_in6 *sifa,
const struct sockaddr_in6 *smask)
{
@@ -1937,7 +1923,7 @@
* Get each interface address and put those interface routes to the route
* list.
*/
-int
+static int
ifrt(struct ifc *ifcp, int again)
{
struct ifac *ifa;
@@ -2055,7 +2041,7 @@
* you pick one. it looks that gated behavior fits best with BSDs,
* since BSD kernels do not look at prefix length on p2p interfaces.
*/
-void
+static void
ifrt_p2p(struct ifc *ifcp, int again)
{
struct ifac *ifa;
@@ -2224,7 +2210,7 @@
#undef P2PADVERT_MAX
}
-int
+static int
getifmtu(int ifindex)
{
int mib[6];
@@ -2263,7 +2249,7 @@
return mtu;
}
-const char *
+static const char *
rttypes(struct rt_msghdr *rtm)
{
#define RTTYPE(s, f) \
@@ -2307,7 +2293,7 @@
return NULL;
}
-const char *
+static const char *
rtflags(struct rt_msghdr *rtm)
{
static char buf[BUFSIZ];
@@ -2372,7 +2358,7 @@
return buf;
}
-const char *
+static const char *
ifflags(int flags)
{
static char buf[BUFSIZ];
@@ -2411,7 +2397,7 @@
return buf;
}
-void
+static void
krtread(int again)
{
int mib[6];
@@ -2464,7 +2450,7 @@
free(buf);
}
-void
+static void
rt_entry(struct rt_msghdr *rtm, int again)
{
struct sockaddr_in6 *sin6_dst, *sin6_gw, *sin6_mask;
@@ -2624,7 +2610,7 @@
}
}
-int
+static int
addroute(struct riprt *rrt, const struct in6_addr *gw, struct ifc *ifcp)
{
struct netinfo6 *np;
@@ -2694,7 +2680,7 @@
return -1;
}
-int
+static int
delroute(struct netinfo6 *np, struct in6_addr *gw)
{
u_char buf[BUFSIZ], buf2[BUFSIZ];
@@ -2759,54 +2745,7 @@
return -1;
}
-struct in6_addr *
-getroute(struct netinfo6 *np, struct in6_addr *gw)
-{
- u_char buf[BUFSIZ];
- int myseq;
- int len;
- struct rt_msghdr *rtm;
- struct sockaddr_in6 *sin6;
-
- rtm = (struct rt_msghdr *)buf;
- len = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in6);
- memset(rtm, 0, len);
- rtm->rtm_type = RTM_GET;
- rtm->rtm_version = RTM_VERSION;
- myseq = ++seq;
- rtm->rtm_seq = myseq;
- rtm->rtm_addrs = RTA_DST;
- rtm->rtm_msglen = len;
- sin6 = (struct sockaddr_in6 *)&buf[sizeof(struct rt_msghdr)];
- sin6->sin6_len = sizeof(struct sockaddr_in6);
- sin6->sin6_family = AF_INET6;
- sin6->sin6_addr = np->rip6_dest;
- if (write(rtsock, buf, len) < 0) {
- if (errno == ESRCH) /* No such route found */
- return NULL;
- perror("write to rtsock");
- exit(1);
- }
- do {
- if ((len = read(rtsock, buf, sizeof(buf))) < 0) {
- perror("read from rtsock");
- exit(1);
- }
- rtm = (struct rt_msghdr *)buf;
- } while (rtm->rtm_seq != myseq || rtm->rtm_pid != pid);
- sin6 = (struct sockaddr_in6 *)&buf[sizeof(struct rt_msghdr)];
- if (rtm->rtm_addrs & RTA_DST) {
- sin6 = (struct sockaddr_in6 *)
- ((char *)sin6 + ROUNDUP(sin6->sin6_len));
- }
- if (rtm->rtm_addrs & RTA_GATEWAY) {
- *gw = sin6->sin6_addr;
- return gw;
- }
- return NULL;
-}
-
-const char *
+static const char *
inet6_n2p(const struct in6_addr *p)
{
static char buf[BUFSIZ];
@@ -2814,7 +2753,7 @@
return inet_ntop(AF_INET6, (const void *)p, buf, sizeof(buf));
}
-void
+static void
ifrtdump(int sig)
{
@@ -2822,7 +2761,7 @@
rtdump(sig);
}
-void
+static void
ifdump(int sig)
{
struct ifc *ifcp;
@@ -2857,7 +2796,7 @@
fclose(dump);
}
-void
+static void
ifdump0(FILE *dump, const struct ifc *ifcp)
{
struct ifac *ifa;
@@ -2914,7 +2853,7 @@
}
}
-void
+static void
rtdump(int sig)
{
struct riprt *rrt;
@@ -2963,7 +2902,7 @@
* syntax: -A 5f09:c400::/32,ef0,ef1 (aggregate)
* -O 5f09:c400::/32,ef0,ef1 (only when match)
*/
-void
+static void
filterconfig(void)
{
int i;
@@ -3094,7 +3033,7 @@
* Returns a pointer to ifac whose address and prefix length matches
* with the address and prefix length specified in the arguments.
*/
-struct ifac *
+static struct ifac *
ifa_match(const struct ifc *ifcp, const struct in6_addr *ia, int plen)
{
struct ifac *ifa;
@@ -3112,7 +3051,7 @@
* matches with the address and prefix length found in the argument.
* Note: This is not a rtalloc(). Therefore exact match is necessary.
*/
-struct riprt *
+static struct riprt *
rtsearch(struct netinfo6 *np, struct riprt **prev_rrt)
{
struct riprt *rrt;
@@ -3132,7 +3071,7 @@
return 0;
}
-int
+static int
sin6mask2len(const struct sockaddr_in6 *sin6)
{
@@ -3140,7 +3079,7 @@
sin6->sin6_len - offsetof(struct sockaddr_in6, sin6_addr));
}
-int
+static int
mask2len(const struct in6_addr *addr, int lenlim)
{
int i = 0, j;
@@ -3167,22 +3106,11 @@
return i;
}
-void
-applymask(struct in6_addr *addr, struct in6_addr *mask)
-{
- int i;
- u_long *p, *q;
-
- p = (u_long *)addr; q = (u_long *)mask;
- for (i = 0; i < 4; i++)
- *p++ &= *q++;
-}
-
static const u_char plent[8] = {
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe
};
-void
+static void
applyplen(struct in6_addr *ia, int plen)
{
u_char *p;
@@ -3198,11 +3126,11 @@
}
}
-static const int pl2m[9] = {
+static static const int pl2m[9] = {
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
};
-struct in6_addr *
+static struct in6_addr *
plen2mask(int n)
{
static struct in6_addr ia;
@@ -3222,7 +3150,7 @@
return &ia;
}
-char *
+static char *
allocopy(char *p)
{
int len = strlen(p) + 1;
@@ -3237,7 +3165,7 @@
return q;
}
-char *
+static char *
hms(void)
{
static char buf[BUFSIZ];
@@ -3256,7 +3184,7 @@
#define RIPRANDDEV 1.0 /* 30 +- 15, max - min = 30 */
-int
+static int
ripinterval(int timer)
{
double r = rand();
@@ -3266,19 +3194,7 @@
return interval;
}
-time_t
-ripsuptrig(void)
-{
- time_t t;
-
- double r = rand();
- t = (int)(RIP_TRIG_INT6_MIN +
- (RIP_TRIG_INT6_MAX - RIP_TRIG_INT6_MIN) * (r / RAND_MAX));
- sup_trig_update = time(NULL) + t;
- return t;
-}
-
-void
+static void
fatal(const char *fmt, ...)
{
va_list ap;
@@ -3295,7 +3211,7 @@
rtdexit();
}
-void
+static void
tracet(int level, const char *fmt, ...)
{
va_list ap;
@@ -3316,7 +3232,7 @@
}
}
-void
+static void
trace(int level, const char *fmt, ...)
{
va_list ap;
@@ -3336,22 +3252,7 @@
}
}
-unsigned int
-if_maxindex(void)
-{
- struct if_nameindex *p, *p0;
- unsigned int max = 0;
-
- p0 = if_nameindex();
- for (p = p0; p && p->if_index && p->if_name; p++) {
- if (max < p->if_index)
- max = p->if_index;
- }
- if_freenameindex(p0);
- return max;
-}
-
-struct ifc *
+static struct ifc *
ifc_find(char *name)
{
struct ifc *ifcp;
@@ -3363,7 +3264,7 @@
return (struct ifc *)NULL;
}
-struct iff *
+static struct iff *
iff_find(struct ifc *ifcp, int type)
{
struct iff *iffp;
@@ -3375,7 +3276,7 @@
return NULL;
}
-void
+static void
setindex2ifc(int idx, struct ifc *ifcp)
{
int n, nsize;