diff options
author | ume <ume@FreeBSD.org> | 2003-08-08 16:56:01 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2003-08-08 16:56:01 +0000 |
commit | 958362f6a8e61ad6b4a95057c871838e4d4de29a (patch) | |
tree | 178f6af642cf6aacbd3415e4286f66d0b9bd3bba /usr.sbin/rtsold/rtsold.c | |
parent | 0820e437dc59b5da388bb504e58d1f00bd256862 (diff) | |
download | FreeBSD-src-958362f6a8e61ad6b4a95057c871838e4d4de29a.zip FreeBSD-src-958362f6a8e61ad6b4a95057c871838e4d4de29a.tar.gz |
KNF, correct typos and cleanup spaces.
Obtained from: KAME
MFC after: 1 week
Diffstat (limited to 'usr.sbin/rtsold/rtsold.c')
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 130 |
1 files changed, 63 insertions, 67 deletions
diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index ca2044a..cc300ac 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -51,23 +51,29 @@ #include <err.h> #include <stdarg.h> #include <ifaddrs.h> + #include "rtsold.h" struct ifinfo *iflist; struct timeval tm_max = {0x7fffffff, 0x7fffffff}; +static int log_upto = 999; +static int fflag = 0; + int aflag = 0; int dflag = 0; + char *otherconf_script; -static int log_upto = 999; -static int fflag = 0; /* protocol constatns */ #define MAX_RTR_SOLICITATION_DELAY 1 /* second */ #define RTR_SOLICITATION_INTERVAL 4 /* seconds */ #define MAX_RTR_SOLICITATIONS 3 /* times */ -/* implementation dependent constants */ -#define PROBE_INTERVAL 60 /* secondes XXX: should be configurable */ +/* + * implementation dependent constants in secondes + * XXX: should be configurable + */ +#define PROBE_INTERVAL 60 /* utility macros */ /* a < b */ @@ -78,12 +84,12 @@ static int fflag = 0; /* a <= b */ #define TIMEVAL_LEQ(a, b) (((a).tv_sec < (b).tv_sec) ||\ (((a).tv_sec == (b).tv_sec) &&\ - ((a).tv_usec <= (b).tv_usec))) + ((a).tv_usec <= (b).tv_usec))) /* a == b */ #define TIMEVAL_EQ(a, b) (((a).tv_sec==(b).tv_sec) && ((a).tv_usec==(b).tv_usec)) -int main __P((int argc, char *argv[])); +int main __P((int, char **)); /* static variables and functions */ static int mobile_node = 0; @@ -91,32 +97,31 @@ static int do_dump; static char *dumpfilename = "/var/run/rtsold.dump"; /* XXX: should be configurable */ static char *pidfilename = "/var/run/rtsold.pid"; /* should be configurable */ -static int ifconfig __P((char *ifname)); +static int ifconfig __P((char *)); #if 0 -static int ifreconfig __P((char *ifname)); +static int ifreconfig __P((char *)); #endif -static int make_packet __P((struct ifinfo *ifinfo)); +static int make_packet __P((struct ifinfo *)); static struct timeval *rtsol_check_timer __P((void)); -static void TIMEVAL_ADD __P((struct timeval *a, struct timeval *b, - struct timeval *result)); -static void TIMEVAL_SUB __P((struct timeval *a, struct timeval *b, - struct timeval *result)); +static void TIMEVAL_ADD __P((struct timeval *, struct timeval *, + struct timeval *)); +static void TIMEVAL_SUB __P((struct timeval *, struct timeval *, + struct timeval *)); static void rtsold_set_dump_file __P((void)); -static void usage __P((char *progname)); +static void usage __P((char *)); static char **autoifprobe __P((void)); int main(argc, argv) int argc; - char *argv[]; + char **argv; { int s, rtsock, maxfd, ch; int once = 0; struct timeval *timeout; struct fd_set fdset; - char *argv0; - char *opts; + char *argv0, *opts; /* * Initialization @@ -190,6 +195,7 @@ main(argc, argv) log_upto = LOG_NOTICE; if (!fflag) { char *ident; + ident = strrchr(argv0, '/'); if (!ident) ident = argv0; @@ -206,7 +212,7 @@ main(argc, argv) } #ifndef HAVE_ARC4RANDOM - /* random value initilization */ + /* random value initialization */ srandom((u_long)time(NULL)); #endif @@ -269,8 +275,8 @@ main(argc, argv) if ((fp = fopen(pidfilename, "w")) == NULL) warnmsg(LOG_ERR, __func__, - "failed to open a log file(%s): %s", - pidfilename, strerror(errno)); + "failed to open a pid log file(%s): %s", + pidfilename, strerror(errno)); else { fprintf(fp, "%d\n", pid); fclose(fp); @@ -288,7 +294,7 @@ main(argc, argv) do_dump = 0; rtsold_dump_file(dumpfilename); } - + timeout = rtsol_check_timer(); if (once) { @@ -310,7 +316,7 @@ main(argc, argv) if (e < 1) { if (e < 0 && errno != EINTR) { warnmsg(LOG_ERR, __func__, "select: %s", - strerror(errno)); + strerror(errno)); } continue; } @@ -335,12 +341,12 @@ ifconfig(char *ifname) if ((sdl = if_nametosdl(ifname)) == NULL) { warnmsg(LOG_ERR, __func__, - "failed to get link layer information for %s", ifname); + "failed to get link layer information for %s", ifname); return(-1); } if (find_ifinfo(sdl->sdl_index)) { warnmsg(LOG_ERR, __func__, - "interface %s was already configured", ifname); + "interface %s was already configured", ifname); free(sdl); return(-1); } @@ -391,7 +397,7 @@ ifconfig(char *ifname) return(0); - bad: +bad: free(ifinfo->sdl); free(ifinfo); return(-1); @@ -419,7 +425,6 @@ ifreconfig(char *ifname) free(ifi->rs_data); free(ifi->sdl); free(ifi); - return rv; } #endif @@ -432,21 +437,20 @@ find_ifinfo(int ifindex) for (ifi = iflist; ifi; ifi = ifi->next) if (ifi->sdl->sdl_index == ifindex) return(ifi); - return(NULL); } static int make_packet(struct ifinfo *ifinfo) { - char *buf; - struct nd_router_solicit *rs; size_t packlen = sizeof(struct nd_router_solicit), lladdroptlen = 0; + struct nd_router_solicit *rs; + char *buf; if ((lladdroptlen = lladdropt_length(ifinfo->sdl)) == 0) { warnmsg(LOG_INFO, __func__, - "link-layer address option has null length" - " on %s. Treat as not included.", ifinfo->ifname); + "link-layer address option has null length" + " on %s. Treat as not included.", ifinfo->ifname); } packlen += lladdroptlen; ifinfo->rs_datalen = packlen; @@ -454,7 +458,7 @@ make_packet(struct ifinfo *ifinfo) /* allocate buffer */ if ((buf = malloc(packlen)) == NULL) { warnmsg(LOG_ERR, __func__, - "memory allocation failed for %s", ifinfo->ifname); + "memory allocation failed for %s", ifinfo->ifname); return(-1); } ifinfo->rs_data = buf; @@ -490,9 +494,9 @@ rtsol_check_timer() if (TIMEVAL_LEQ(ifinfo->expire, now)) { if (dflag > 1) warnmsg(LOG_DEBUG, __func__, - "timer expiration on %s, " - "state = %d", ifinfo->ifname, - ifinfo->state); + "timer expiration on %s, " + "state = %d", ifinfo->ifname, + ifinfo->state); switch (ifinfo->state) { case IFS_DOWN: @@ -511,24 +515,22 @@ rtsol_check_timer() int oldstatus = ifinfo->active; int probe = 0; - ifinfo->active = - interface_status(ifinfo); + ifinfo->active = interface_status(ifinfo); if (oldstatus != ifinfo->active) { warnmsg(LOG_DEBUG, __func__, - "%s status is changed" - " from %d to %d", - ifinfo->ifname, - oldstatus, ifinfo->active); + "%s status is changed" + " from %d to %d", + ifinfo->ifname, + oldstatus, ifinfo->active); probe = 1; ifinfo->state = IFS_DELAY; - } - else if (ifinfo->probeinterval && - (ifinfo->probetimer -= - ifinfo->timer.tv_sec) <= 0) { + } else if (ifinfo->probeinterval && + (ifinfo->probetimer -= + ifinfo->timer.tv_sec) <= 0) { /* probe timer expired */ ifinfo->probetimer = - ifinfo->probeinterval; + ifinfo->probeinterval; probe = 1; ifinfo->state = IFS_PROBE; } @@ -553,9 +555,8 @@ rtsol_check_timer() sendpacket(ifinfo); else { warnmsg(LOG_INFO, __func__, - "No answer " - "after sending %d RSs", - ifinfo->probes); + "No answer after sending %d RSs", + ifinfo->probes); ifinfo->probes = 0; ifinfo->state = IFS_IDLE; } @@ -571,8 +572,7 @@ rtsol_check_timer() if (TIMEVAL_EQ(rtsol_timer, tm_max)) { warnmsg(LOG_DEBUG, __func__, "there is no timer"); return(NULL); - } - else if (TIMEVAL_LT(rtsol_timer, now)) + } else if (TIMEVAL_LT(rtsol_timer, now)) /* this may occur when the interval is too small */ returnval.tv_sec = returnval.tv_usec = 0; else @@ -580,7 +580,7 @@ rtsol_check_timer() if (dflag > 1) warnmsg(LOG_DEBUG, __func__, "New timer is %ld:%08ld", - (long)returnval.tv_sec, (long)returnval.tv_usec); + (long)returnval.tv_sec, (long)returnval.tv_usec); return(&returnval); } @@ -601,13 +601,12 @@ rtsol_timer_update(struct ifinfo *ifinfo) if (++ifinfo->dadcount > DADRETRY) { ifinfo->dadcount = 0; ifinfo->timer.tv_sec = PROBE_INTERVAL; - } - else + } else ifinfo->timer.tv_sec = 1; break; case IFS_IDLE: if (mobile_node) { - /* XXX should be configurable */ + /* XXX should be configurable */ ifinfo->timer.tv_sec = 3; } else @@ -638,8 +637,8 @@ rtsol_timer_update(struct ifinfo *ifinfo) break; default: warnmsg(LOG_ERR, __func__, - "illegal interface state(%d) on %s", - ifinfo->state, ifinfo->ifname); + "illegal interface state(%d) on %s", + ifinfo->state, ifinfo->ifname); return; } @@ -647,17 +646,16 @@ rtsol_timer_update(struct ifinfo *ifinfo) if (TIMEVAL_EQ(ifinfo->timer, tm_max)) { ifinfo->expire = tm_max; warnmsg(LOG_DEBUG, __func__, - "stop timer for %s", ifinfo->ifname); - } - else { + "stop timer for %s", ifinfo->ifname); + } else { gettimeofday(&now, NULL); TIMEVAL_ADD(&now, &ifinfo->timer, &ifinfo->expire); if (dflag > 1) warnmsg(LOG_DEBUG, __func__, - "set timer for %s to %d:%d", ifinfo->ifname, - (int)ifinfo->timer.tv_sec, - (int)ifinfo->timer.tv_usec); + "set timer for %s to %d:%d", ifinfo->ifname, + (int)ifinfo->timer.tv_sec, + (int)ifinfo->timer.tv_usec); } #undef MILLION @@ -675,8 +673,7 @@ TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result) if ((l = a->tv_usec + b->tv_usec) < MILLION) { result->tv_usec = l; result->tv_sec = a->tv_sec + b->tv_sec; - } - else { + } else { result->tv_usec = l - MILLION; result->tv_sec = a->tv_sec + b->tv_sec + 1; } @@ -694,8 +691,7 @@ TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result) if ((l = a->tv_usec - b->tv_usec) >= 0) { result->tv_usec = l; result->tv_sec = a->tv_sec - b->tv_sec; - } - else { + } else { result->tv_usec = MILLION + l; result->tv_sec = a->tv_sec - b->tv_sec - 1; } |