use our own idea of table size. Use syslog to (optionally) log bad packets.
Don't respond to routing inquiries from a router unless we are suppliers
(really want to respondto everything but broadcasts, but haven't got
the "to" address.)
SCCS-vsn: sbin/routed/af.c 5.3
SCCS-vsn: sbin/routed/af.h 5.2
SCCS-vsn: sbin/routed/if.c 5.2
SCCS-vsn: sbin/routed/input.c 5.2
SCCS-vsn: sbin/routed/main.c 5.6
SCCS-vsn: sbin/routed/tables.c 5.2
-static char sccsid[] = "@(#)af.c 5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)af.c 5.3 (Berkeley) %G%";
#endif not lint
#include "defs.h"
#endif not lint
#include "defs.h"
/*
* Address family support routines
*/
/*
* Address family support routines
*/
-int null_hash(), null_netmatch(), null_output(),
- null_portmatch(), null_portcheck(),
- null_checkhost(), null_ishost(), null_canon();
int inet_hash(), inet_netmatch(), inet_output(),
inet_portmatch(), inet_portcheck(),
inet_checkhost(), inet_ishost(), inet_canon();
int inet_hash(), inet_netmatch(), inet_output(),
inet_portmatch(), inet_portcheck(),
inet_checkhost(), inet_ishost(), inet_canon();
-#define NIL \
- { null_hash, null_netmatch, null_output, \
- null_portmatch, null_portcheck, null_checkhost, \
- null_ishost, null_canon }
+char *inet_format();
+#define NIL { 0 }
#define INET \
{ inet_hash, inet_netmatch, inet_output, \
inet_portmatch, inet_portcheck, inet_checkhost, \
#define INET \
{ inet_hash, inet_netmatch, inet_output, \
inet_portmatch, inet_portcheck, inet_checkhost, \
- inet_ishost, inet_canon }
+ inet_ishost, inet_canon, inet_format }
struct afswitch afswitch[AF_MAX] =
struct afswitch afswitch[AF_MAX] =
- { NIL, NIL, INET, INET, NIL, NIL, NIL, NIL, NIL, NIL, NIL };
+ { NIL, NIL, INET, };
+
+int af_max = sizeof(afswitch) / sizeof(afswitch[0]);
struct sockaddr_in inet_default = { AF_INET, INADDR_ANY };
struct sockaddr_in inet_default = { AF_INET, INADDR_ANY };
-/*ARGSUSED*/
-null_hash(addr, hp)
- struct sockaddr *addr;
- struct afhash *hp;
-{
-
- hp->afh_nethash = hp->afh_hosthash = 0;
-}
-
-/*ARGSUSED*/
-null_netmatch(a1, a2)
- struct sockaddr *a1, *a2;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_output(s, f, a1, n)
- int s, f;
- struct sockaddr *a1;
- int n;
-{
-
- ;
-}
-
-/*ARGSUSED*/
-null_portmatch(a1)
- struct sockaddr *a1;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_portcheck(a1)
- struct sockaddr *a1;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_ishost(a1)
- struct sockaddr *a1;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_checkhost(a1)
- struct sockaddr *a1;
-{
-
- return (0);
-}
-
-/*ARGSUSED*/
-null_canon(a1)
- struct sockaddr *a1;
+char *
+inet_format(sin)
+ struct sockaddr_in *sin;
+ return (inet_ntoa(sin->sin_addr));
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
- * @(#)af.h 5.1 (Berkeley) %G%
+ * @(#)af.h 5.2 (Berkeley) %G%
int (*af_checkhost)(); /* tells if address for host or net */
int (*af_ishost)(); /* tells if address is valid */
int (*af_canon)(); /* canonicalize address for compares */
int (*af_checkhost)(); /* tells if address for host or net */
int (*af_ishost)(); /* tells if address is valid */
int (*af_canon)(); /* canonicalize address for compares */
+ char *(*af_format)(); /* convert address to string */
u_int afh_nethash; /* network based hash */
};
u_int afh_nethash; /* network based hash */
};
-struct afswitch afswitch[AF_MAX]; /* table proper */
+struct afswitch afswitch[]; /* table proper */
+int af_max; /* number of entries in table */
-static char sccsid[] = "@(#)if.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)if.c 5.2 (Berkeley) %G%";
register int af = addr->sa_family;
register int (*netmatch)();
register int af = addr->sa_family;
register int (*netmatch)();
return (0);
netmatch = afswitch[af].af_netmatch;
for (ifp = ifnet; ifp; ifp = ifp->int_next) {
return (0);
netmatch = afswitch[af].af_netmatch;
for (ifp = ifnet; ifp; ifp = ifp->int_next) {
register int af = addr->sa_family;
register int (*netmatch)();
register int af = addr->sa_family;
register int (*netmatch)();
return (0);
maybe = 0;
netmatch = afswitch[af].af_netmatch;
return (0);
maybe = 0;
netmatch = afswitch[af].af_netmatch;
-static char sccsid[] = "@(#)input.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)input.c 5.2 (Berkeley) %G%";
#endif not lint
/*
* Routing Table Management Daemon
*/
#include "defs.h"
#endif not lint
/*
* Routing Table Management Daemon
*/
#include "defs.h"
/*
* Process a newly received packet.
/*
* Process a newly received packet.
ifp = 0;
TRACE_INPUT(ifp, from, size);
ifp = 0;
TRACE_INPUT(ifp, from, size);
- if (from->sa_family >= AF_MAX)
+ if (from->sa_family >= af_max ||
+ (afp = &afswitch[from->sa_family])->af_hash == (int (*)())0) {
+ syslog(LOG_INFO,
+ "\"from\" address in unsupported address family (%d), cmd %d\n",
+ from->sa_family, msg->rip_cmd);
- afp = &afswitch[from->sa_family];
switch (msg->rip_cmd) {
case RIPCMD_REQUEST:
switch (msg->rip_cmd) {
case RIPCMD_REQUEST:
/*
* A single entry with sa_family == AF_UNSPEC and
* metric ``infinity'' means ``all routes''.
/*
* A single entry with sa_family == AF_UNSPEC and
* metric ``infinity'' means ``all routes''.
+ * We respond to routers only if we are acting
+ * as a supplier, or to anyone other than a router
+ * (eg, query).
*/
if (n->rip_dst.sa_family == AF_UNSPEC &&
*/
if (n->rip_dst.sa_family == AF_UNSPEC &&
- n->rip_metric == HOPCNT_INFINITY && size == 0) {
+ n->rip_metric == HOPCNT_INFINITY && size == 0 &&
+ (supplier || (*afp->af_portcheck)(from) == 0)) {
supply(from, 0, ifp);
return;
}
supply(from, 0, ifp);
return;
}
}
if ((unsigned) n->rip_metric > HOPCNT_INFINITY)
continue;
}
if ((unsigned) n->rip_metric > HOPCNT_INFINITY)
continue;
- if (n->rip_dst.sa_family >= AF_MAX)
+ if (n->rip_dst.sa_family >= af_max ||
+ (afp = &afswitch[n->rip_dst.sa_family])->af_hash ==
+ (int (*)())0) {
+ syslog(LOG_INFO,
+ "route in unsupported address family (%d), from %s (af %d)\n",
+ n->rip_dst.sa_family,
+ (*afswitch[from->sa_family].af_format)(from),
+ from->sa_family);
- afp = &afswitch[n->rip_dst.sa_family];
- if (((*afp->af_checkhost)(&n->rip_dst)) == 0)
+ }
+ if (((*afp->af_checkhost)(&n->rip_dst)) == 0) {
+ syslog(LOG_DEBUG,
+ "bad host in route from %s (af %d)\n",
+ (*afswitch[from->sa_family].af_format)(from),
+ from->sa_family);
rt = rtlookup(&n->rip_dst);
if (rt == 0) {
if (n->rip_metric < HOPCNT_INFINITY)
rt = rtlookup(&n->rip_dst);
if (rt == 0) {
if (n->rip_metric < HOPCNT_INFINITY)
#endif not lint
#ifndef lint
#endif not lint
#ifndef lint
-static char sccsid[] = "@(#)main.c 5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c 5.6 (Berkeley) %G%";
argv0 = argv;
openlog("routed", LOG_PID | LOG_ODELAY, LOG_DAEMON);
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");
}
if (strcmp(*argv, "-t") == 0) {
tracepackets++;
}
if (strcmp(*argv, "-t") == 0) {
tracepackets++;
+ setlogmask(LOG_UPTO(LOG_DEBUG));
+ argv++, argc--;
+ continue;
+ }
+ if (strcmp(*argv, "-d") == 0) {
+ setlogmask(LOG_UPTO(LOG_DEBUG));
argv++, argc--;
continue;
}
argv++, argc--;
continue;
}
-static char sccsid[] = "@(#)tables.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)tables.c 5.2 (Berkeley) %G%";
struct afhash h;
int doinghost = 1;
struct afhash h;
int doinghost = 1;
- if (dst->sa_family >= AF_MAX)
+ if (dst->sa_family >= af_max)
return (0);
(*afswitch[dst->sa_family].af_hash)(dst, &h);
hash = h.afh_hosthash;
return (0);
(*afswitch[dst->sa_family].af_hash)(dst, &h);
hash = h.afh_hosthash;
int af = dst->sa_family;
int doinghost = 1, (*match)();
int af = dst->sa_family;
int doinghost = 1, (*match)();
return (0);
(*afswitch[af].af_hash)(dst, &h);
hash = h.afh_hosthash;
return (0);
(*afswitch[af].af_hash)(dst, &h);
hash = h.afh_hosthash;
int af = dst->sa_family, flags;
u_int hash;
int af = dst->sa_family, flags;
u_int hash;
return;
(*afswitch[af].af_hash)(dst, &h);
flags = (*afswitch[af].af_ishost)(dst) ? RTF_HOST : 0;
return;
(*afswitch[af].af_hash)(dst, &h);
flags = (*afswitch[af].af_ishost)(dst) ? RTF_HOST : 0;