projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
don't rely on AF_MAX (comes from kernel include): check for nil explicitly,
[unix-history]
/
usr
/
src
/
sbin
/
routed
/
main.c
diff --git
a/usr/src/sbin/routed/main.c
b/usr/src/sbin/routed/main.c
index
a68a3a0
..
9c766eb
100644
(file)
--- a/
usr/src/sbin/routed/main.c
+++ b/
usr/src/sbin/routed/main.c
@@
-1,6
+1,18
@@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
#ifndef lint
#ifndef lint
-static char sccsid[] = "@(#)main.c 4.11 (Berkeley) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1983 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)main.c 5.6 (Berkeley) %G%";
+#endif not lint
/*
* Routing Table Management Daemon
/*
* Routing Table Management Daemon
@@
-14,9
+26,10
@@
static char sccsid[] = "@(#)main.c 4.11 (Berkeley) %G%";
#include <errno.h>
#include <nlist.h>
#include <signal.h>
#include <errno.h>
#include <nlist.h>
#include <signal.h>
+#include <syslog.h>
int supplier = -1; /* process should supply updates */
int supplier = -1; /* process should supply updates */
-extern int gateway;
+int gateway = 0; /* 1 if we are a gateway to parts beyond */
struct rip *msg = (struct rip *)packet;
int hup();
struct rip *msg = (struct rip *)packet;
int hup();
@@
-28,11
+41,10
@@
main(argc, argv)
int cc;
struct sockaddr from;
u_char retry;
int cc;
struct sockaddr from;
u_char retry;
-#ifdef COMPAT
- int snoroute;
-#endif
argv0 = argv;
argv0 = argv;
+ openlog("routed", LOG_PID | LOG_ODELAY, LOG_DAEMON);
+ setlogmask(LOG_UPTO(LOG_WARNING));
sp = getservbyname("router", "udp");
if (sp == NULL) {
fprintf(stderr, "routed: router/udp: unknown service\n");
sp = getservbyname("router", "udp");
if (sp == NULL) {
fprintf(stderr, "routed: router/udp: unknown service\n");
@@
-43,14
+55,6
@@
main(argc, argv)
s = getsocket(AF_INET, SOCK_DGRAM, &addr);
if (s < 0)
exit(1);
s = getsocket(AF_INET, SOCK_DGRAM, &addr);
if (s < 0)
exit(1);
-#ifdef COMPAT
- bzero(&addr, sizeof (addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(ntohs(sp->s_port) + 1);
- snoroute = getsocket(AF_INET, SOCK_DGRAM, &addr);
- if (snoroute < 0)
- exit(1);
-#endif
argv++, argc--;
while (argc > 0 && **argv == '-') {
if (strcmp(*argv, "-s") == 0) {
argv++, argc--;
while (argc > 0 && **argv == '-') {
if (strcmp(*argv, "-s") == 0) {
@@
-65,21
+69,22
@@
main(argc, argv)
}
if (strcmp(*argv, "-t") == 0) {
tracepackets++;
}
if (strcmp(*argv, "-t") == 0) {
tracepackets++;
+ setlogmask(LOG_UPTO(LOG_DEBUG));
argv++, argc--;
continue;
}
argv++, argc--;
continue;
}
- if (strcmp(*argv, "-
g
") == 0) {
-
gateway = 1
;
+ if (strcmp(*argv, "-
d
") == 0) {
+
setlogmask(LOG_UPTO(LOG_DEBUG))
;
argv++, argc--;
continue;
}
argv++, argc--;
continue;
}
- if (strcmp(*argv, "-
l
") == 0) {
- gateway =
-
1;
+ if (strcmp(*argv, "-
g
") == 0) {
+ gateway = 1;
argv++, argc--;
continue;
}
fprintf(stderr,
argv++, argc--;
continue;
}
fprintf(stderr,
- "usage: routed [ -s ] [ -q ] [ -t ] [ -g ]
[ -l ]
\n");
+ "usage: routed [ -s ] [ -q ] [ -t ] [ -g ]\n");
exit(1);
}
#ifndef DEBUG
exit(1);
}
#ifndef DEBUG
@@
-90,10
+95,7
@@
main(argc, argv)
exit(0);
for (t = 0; t < 20; t++)
if (t != s)
exit(0);
for (t = 0; t < 20; t++)
if (t != s)
-#ifdef COMPAT
- if (t != snoroute)
-#endif
- (void) close(cc);
+ (void) close(t);
(void) open("/", 0);
(void) dup2(0, 1);
(void) dup2(0, 2);
(void) open("/", 0);
(void) dup2(0, 1);
(void) dup2(0, 2);
@@
-112,7
+114,7
@@
main(argc, argv)
traceon(*argv);
/*
* Collect an initial view of the world by
traceon(*argv);
/*
* Collect an initial view of the world by
- *
snooping in the kernel
and the gateway kludge
+ *
checking the interface configuration
and the gateway kludge
* file. Then, send a request packet on all
* directly connected networks to find out what
* everyone else thinks.
* file. Then, send a request packet on all
* directly connected networks to find out what
* everyone else thinks.
@@
-120,6
+122,8
@@
main(argc, argv)
rtinit();
gwkludge();
ifinit();
rtinit();
gwkludge();
ifinit();
+ if (gateway > 0)
+ rtdefault();
if (supplier < 0)
supplier = 0;
msg->rip_cmd = RIPCMD_REQUEST;
if (supplier < 0)
supplier = 0;
msg->rip_cmd = RIPCMD_REQUEST;
@@
-131,6
+135,7
@@
main(argc, argv)
toall(sendmsg);
signal(SIGALRM, timer);
signal(SIGHUP, hup);
toall(sendmsg);
signal(SIGALRM, timer);
signal(SIGHUP, hup);
+ signal(SIGTERM, hup);
timer();
for (;;) {
timer();
for (;;) {
@@
-138,18
+143,11
@@
main(argc, argv)
register int n;
ibits = 1 << s;
register int n;
ibits = 1 << s;
-#ifdef COMPAT
- ibits |= 1 << snoroute;
-#endif
n = select(20, &ibits, 0, 0, 0);
if (n < 0)
continue;
if (ibits & (1 << s))
process(s);
n = select(20, &ibits, 0, 0, 0);
if (n < 0)
continue;
if (ibits & (1 << s))
process(s);
-#ifdef COMPAT
- if (ibits & (1 << snoroute))
- process(snoroute);
-#endif
/* handle ICMP redirects */
}
}
/* handle ICMP redirects */
}
}
@@
-168,8
+166,7
@@
process(fd)
}
if (fromlen != sizeof (struct sockaddr_in))
return;
}
if (fromlen != sizeof (struct sockaddr_in))
return;
-#define mask(s) (1<<((s)-1))
- omask = sigblock(mask(SIGALRM));
+ omask = sigblock(sigmask(SIGALRM));
rip_input(&from, cc);
sigsetmask(omask);
}
rip_input(&from, cc);
sigsetmask(omask);
}
@@
-178,22
+175,23
@@
getsocket(domain, type, sin)
int domain, type;
struct sockaddr_in *sin;
{
int domain, type;
struct sockaddr_in *sin;
{
- int
retry, s
;
+ int
s, on = 1
;
- retry = 1;
- while ((s = socket(domain, type, 0, 0)) < 0 && retry) {
+ if ((s = socket(domain, type, 0)) < 0) {
perror("socket");
perror("socket");
- s
leep(5 * retry
);
- ret
ry <<= 1
;
+ s
yslog(LOG_ERR, "socket: %m"
);
+ ret
urn (-1)
;
}
}
- if (retry == 0)
+ if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) {
+ syslog(LOG_ERR, "setsockopt SO_BROADCAST: %m");
+ close(s);
return (-1);
return (-1);
- while (bind(s, sin, sizeof (*sin), 0) < 0 && retry) {
- perror("bind");
- sleep(5 * retry);
- retry <<= 1;
}
}
- if (retry == 0)
+ if (bind(s, sin, sizeof (*sin), 0) < 0) {
+ perror("bind");
+ syslog(LOG_ERR, "bind: %m");
+ close(s);
return (-1);
return (-1);
+ }
return (s);
}
return (s);
}