summary |
tags |
clone url |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
971be2e)
SCCS-vsn: sbin/routed/defs.h 4.3
SCCS-vsn: sbin/routed/routed.c 4.7
-/* defs.h 4.2 82/05/25 */
+/* defs.h 4.3 82/05/26 */
/*
* Internal data structure definitions for
/*
* Internal data structure definitions for
#include <net/route.h>
/*
#include <net/route.h>
/*
- * Internal routing table structure.
- * Differs a bit from kernel tables.
+ * Routing table structure; differs a bit from kernel tables.
+ *
+ * Note: the union below must agree in the first 4 members
+ * so the ioctl's will work.
*/
struct rthash {
struct rt_entry *rt_forw;
*/
struct rthash {
struct rt_entry *rt_forw;
struct sockaddr rtu_gateway;
short rtu_flags;
short rtu_retry;
struct sockaddr rtu_gateway;
short rtu_flags;
short rtu_retry;
+ short rtu_timer;
+ short rtu_state;
int rtu_metric;
struct ifnet *rtu_ifp;
} rtu_entry;
int rtu_metric;
struct ifnet *rtu_ifp;
} rtu_entry;
#define rt_hash rt_rtu.rtu_entry.rtu_hash /* for net or host */
#define rt_dst rt_rtu.rtu_entry.rtu_dst /* match value */
#define rt_gateway rt_rtu.rtu_entry.rtu_gateway /* who to forward to */
#define rt_hash rt_rtu.rtu_entry.rtu_hash /* for net or host */
#define rt_dst rt_rtu.rtu_entry.rtu_dst /* match value */
#define rt_gateway rt_rtu.rtu_entry.rtu_gateway /* who to forward to */
-#define rt_flags rt_rtu.rtu_entry.rtu_flags /* see below */
+#define rt_flags rt_rtu.rtu_entry.rtu_flags /* kernel flags */
#define rt_retry rt_rtu.rtu_entry.rtu_retry /* retries of ioctl */
#define rt_timer rt_rtu.rtu_entry.rtu_timer /* for invalidation */
#define rt_retry rt_rtu.rtu_entry.rtu_retry /* retries of ioctl */
#define rt_timer rt_rtu.rtu_entry.rtu_timer /* for invalidation */
+#define rt_state rt_rtu.rtu_entry.rtu_state /* see below */
#define rt_metric rt_rtu.rtu_entry.rtu_metric /* cost of route */
#define rt_ifp rt_rtu.rtu_entry.rtu_ifp /* interface to take */
#define ROUTEHASHSIZ 19
/*
#define rt_metric rt_rtu.rtu_entry.rtu_metric /* cost of route */
#define rt_ifp rt_rtu.rtu_entry.rtu_ifp /* interface to take */
#define ROUTEHASHSIZ 19
/*
- * Flags used by routing process are not
- * interpreted by kernel.
+ * "State" of routing table entry.
-#define RTF_DELRT 0x8 /* delete pending */
-#define RTF_CHGRT 0x10 /* change command pending */
-#define RTF_ADDRT 0x20 /* add command pending */
-#define RTF_SILENT 0x40 /* don't send to router */
+#define RTS_DELRT 0x1 /* delete pending */
+#define RTS_CHGRT 0x2 /* change command pending */
+#define RTS_ADDRT 0x4 /* add command pending */
+#define RTS_SILENT 0x8 /* don't send to router */
struct rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
struct rt_entry *rtlookup();
/*
struct rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
struct rt_entry *rtlookup();
/*
- * Per address family routines. Hash returns hash key based
- * on address; netmatch verifies net # matching, output interprets
- * an address in preparation for sending; portmatch interprets
- * an address in verifying incoming packets were sent from the
- * appropriate port; checkhost is used to decide whether an
- * address is for a host, or for a network (e.g. broadcast);
- * canon purges any extraneous stuff from a sender's address
- * before pattern matching is performed (e.g. Internet ports).
+ * Per address family routines.
- int (*af_hash)();
- int (*af_netmatch)();
- int (*af_output)();
- int (*af_portmatch)();
- int (*af_checkhost)();
- int (*af_canon)();
+ int (*af_hash)(); /* returns keys based on address */
+ int (*af_netmatch)(); /* verifies net # matching */
+ int (*af_output)(); /* interprets address for sending */
+ int (*af_portmatch)(); /* interprets address on receipt */
+ int (*af_checkhost)(); /* tells if address for host or net */
+ int (*af_canon)(); /* purges extraneous part of address */
+/*
+ * Structure returned by af_hash routines.
+ */
- u_int afh_hosthash;
- u_int afh_nethash;
+ u_int afh_hosthash; /* host based hash */
+ u_int afh_nethash; /* network based hash */
-struct afswitch afswitch[AF_MAX];
+struct afswitch afswitch[AF_MAX]; /* table proper */
-static char sccsid[] = "@(#)routed.c 4.6 %G%";
+static char sccsid[] = "@(#)routed.c 4.7 %G%";
(void) dup2(fileno(stdout), 2);
setbuf(stdout, NULL);
}
(void) dup2(fileno(stdout), 2);
setbuf(stdout, NULL);
}
myaddr.sin_port = htons(myaddr.sin_port);
#endif
again:
myaddr.sin_port = htons(myaddr.sin_port);
#endif
again:
rtadd((struct sockaddr *)&dst, (struct sockaddr *)&gate, 1);
rt = rtlookup((struct sockaddr *)&dst);
if (rt)
rtadd((struct sockaddr *)&dst, (struct sockaddr *)&gate, 1);
rt = rtlookup((struct sockaddr *)&dst);
if (rt)
- rt->rt_flags |= RTF_SILENT;
+ rt->rt_state |= RTS_SILENT;
* from the initialization file),
* don't time out it's entry.
*/
* from the initialization file),
* don't time out it's entry.
*/
- if ((rt->rt_flags & RTF_SILENT) == 0)
+ if ((rt->rt_state & RTS_SILENT) == 0)
rt->rt_timer += TIMER_RATE;
log("", rt);
rt->rt_timer += TIMER_RATE;
log("", rt);
* attempt to do so and reclaim space.
*/
if (rt->rt_timer >= GARBAGE_TIME ||
* attempt to do so and reclaim space.
*/
if (rt->rt_timer >= GARBAGE_TIME ||
- (rt->rt_flags & RTF_DELRT)) {
- rt = rt->rt_forw;
- rtdelete(rt->rt_back);
+ (rt->rt_state & RTS_DELRT)) {
*/
if (rt->rt_timer >= EXPIRE_TIME)
rt->rt_metric = HOPCNT_INFINITY;
*/
if (rt->rt_timer >= EXPIRE_TIME)
rt->rt_metric = HOPCNT_INFINITY;
- if (rt->rt_flags & RTF_CHGRT)
+ if (rt->rt_state & RTS_CHGRT)
if (!ioctl(s, SIOCCHGRT,(char *)&rt->rt_rt) ||
--rt->rt_retry == 0)
if (!ioctl(s, SIOCCHGRT,(char *)&rt->rt_rt) ||
--rt->rt_retry == 0)
- rt->rt_flags &= ~RTF_CHGRT;
+ rt->rt_state &= ~RTS_CHGRT;
/*
* Try to add the route to the kernel tables.
/*
* Try to add the route to the kernel tables.
* fails otherwise (likely because the entry is
* in use), retry the operation a few more times.
*/
* fails otherwise (likely because the entry is
* in use), retry the operation a few more times.
*/
- if (rt->rt_flags & RTF_ADDRT) {
+ if (rt->rt_state & RTS_ADDRT) {
if (!ioctl(s, SIOCADDRT,(char *)&rt->rt_rt)) {
if (errno == EEXIST) {
if (!ioctl(s, SIOCADDRT,(char *)&rt->rt_rt)) {
if (errno == EEXIST) {
- rt->rt_flags &= ~RTF_ADDRT;
- rt->rt_flags |= RTF_CHGRT;
+ rt->rt_state &= ~RTS_ADDRT;
+ rt->rt_state |= RTS_CHGRT;
rt->rt_retry =
(EXPIRE_TIME/TIMER_RATE);
continue;
rt->rt_retry =
(EXPIRE_TIME/TIMER_RATE);
continue;
if (--rt->rt_retry)
continue;
}
if (--rt->rt_retry)
continue;
}
- rt->rt_flags &= ~RTF_ADDRT;
+ rt->rt_state &= ~RTS_ADDRT;
again:
for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
again:
for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- if ((rt->rt_flags & RTF_SILENT) || rt->rt_metric > 0)
+ if ((rt->rt_state & RTS_SILENT) || rt->rt_metric > 0)
continue;
if (rt->rt_ifp && (rt->rt_ifp->if_flags & IFF_BROADCAST))
dst = &rt->rt_ifp->if_broadaddr;
continue;
if (rt->rt_ifp && (rt->rt_ifp->if_flags & IFF_BROADCAST))
dst = &rt->rt_ifp->if_broadaddr;
again:
for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
again:
for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)
for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
- if ((rt->rt_flags & RTF_SILENT) || rt->rt_metric > 0)
+ if ((rt->rt_state & RTS_SILENT) || rt->rt_metric > 0)
continue;
if (rt->rt_ifp && (rt->rt_ifp->if_flags & IFF_BROADCAST))
dst = &rt->rt_ifp->if_broadaddr;
continue;
if (rt->rt_ifp && (rt->rt_ifp->if_flags & IFF_BROADCAST))
dst = &rt->rt_ifp->if_broadaddr;
struct rt_entry *rt;
struct netinfo *n;
struct rt_entry *rt;
struct netinfo *n;
- if (msg->rip_cmd != RIPCMD_RESPONSE &&
- msg->rip_cmd != RIPCMD_REQUEST)
- return;
+ switch (msg->rip_cmd) {
- if (msg->rip_cmd == RIPCMD_RESPONSE &&
- (*afswitch[from->sa_family].af_portmatch)(from) == 0)
- if (msg->rip_cmd == RIPCMD_REQUEST) {
rip_respond(from, size);
return;
rip_respond(from, size);
return;
+
+ case RIPCMD_RESPONSE:
+ /* verify message came from a priviledged port */
+ if ((*afswitch[from->sa_family].af_portmatch)(from) == 0)
+ return;
+ break;
rt->rt_metric = metric;
rt->rt_timer = 0;
rt->rt_flags = RTF_UP | flags;
rt->rt_metric = metric;
rt->rt_timer = 0;
rt->rt_flags = RTF_UP | flags;
rt->rt_ifp = if_ifwithnet(&rt->rt_gateway);
if (metric == 0)
rt->rt_flags |= RTF_DIRECT;
rt->rt_ifp = if_ifwithnet(&rt->rt_gateway);
if (metric == 0)
rt->rt_flags |= RTF_DIRECT;
if (supplier)
broadcast(rt);
if (install) {
if (supplier)
broadcast(rt);
if (install) {
- rt->rt_flags |= RTF_ADDRT;
+ rt->rt_state |= RTS_ADDRT;
rt->rt_retry = EXPIRE_TIME/TIMER_RATE;
}
}
rt->rt_retry = EXPIRE_TIME/TIMER_RATE;
}
}
broadcast(rt);
log("change", rt);
if (install) {
broadcast(rt);
log("change", rt);
if (install) {
- rt->rt_flags |= RTF_CHGRT;
+ rt->rt_state |= RTS_CHGRT;
rt->rt_retry = EXPIRE_TIME/TIMER_RATE;
}
}
rt->rt_retry = EXPIRE_TIME/TIMER_RATE;
}
}
if (install)
if (ioctl(s, SIOCDELRT, (char *)&rt->rt_rt) &&
errno == EBUSY)
if (install)
if (ioctl(s, SIOCDELRT, (char *)&rt->rt_rt) &&
errno == EBUSY)
- rt->rt_flags |= RTF_DELRT;
+ rt->rt_state |= RTS_DELRT;
remque(rt);
free((char *)rt);
}
remque(rt);
free((char *)rt);
}
{
time_t t = time(0);
struct sockaddr_in *dst, *gate;
{
time_t t = time(0);
struct sockaddr_in *dst, *gate;
- static struct flagbits {
int t_bits;
char *t_name;
int t_bits;
char *t_name;
{ RTF_UP, "UP" },
{ RTF_DIRECT, "DIRECT" },
{ RTF_HOST, "HOST" },
{ RTF_UP, "UP" },
{ RTF_DIRECT, "DIRECT" },
{ RTF_HOST, "HOST" },
- { RTF_DELRT, "DELETE" },
- { RTF_CHGRT, "CHANGE" },
- { RTF_SILENT, "SILENT" },
+ { 0 }
+ }, statebits[] = {
+ { RTS_DELRT, "DELETE" },
+ { RTS_CHGRT, "CHANGE" },
+ { RTS_SILENT, "SILENT" },
- register struct flagbits *p;
+ register struct bits *p;
register int first;
char *cp;
register int first;
char *cp;
printf("%s ", operation);
dst = (struct sockaddr_in *)&rt->rt_dst;
gate = (struct sockaddr_in *)&rt->rt_gateway;
printf("%s ", operation);
dst = (struct sockaddr_in *)&rt->rt_dst;
gate = (struct sockaddr_in *)&rt->rt_gateway;
- printf("dst %x, router %x, metric %d, flags ",
+ printf("dst %x, router %x, metric %d, flags",
dst->sin_addr, gate->sin_addr, rt->rt_metric);
dst->sin_addr, gate->sin_addr, rt->rt_metric);
- cp = "%s";
- for (first = 1, p = bits; p->t_bits > 0; p++) {
+ cp = " %s";
+ for (first = 1, p = flagbits; p->t_bits > 0; p++) {
if ((rt->rt_flags & p->t_bits) == 0)
continue;
printf(cp, p->t_name);
if ((rt->rt_flags & p->t_bits) == 0)
continue;
printf(cp, p->t_name);
+ printf(" state");
+ cp = " %s";
+ for (first = 1, p = statebits; p->t_bits > 0; p++) {
+ if ((rt->rt_state & p->t_bits) == 0)
+ continue;
+ printf(cp, p->t_name);
+ if (first) {
+ cp = "|%s";
+ first = 0;
+ }
+ }