provision bandaids for new sockaddrs
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Tue, 22 Aug 1989 03:34:16 +0000 (19:34 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Tue, 22 Aug 1989 03:34:16 +0000 (19:34 -0800)
SCCS-vsn: sbin/routed/output.c 5.13
SCCS-vsn: sbin/routed/tables.c 5.16
SCCS-vsn: sbin/routed/input.c 5.21
SCCS-vsn: sbin/routed/table.h 5.7
SCCS-vsn: sbin/routed/af.c 5.9

usr/src/sbin/routed/af.c
usr/src/sbin/routed/input.c
usr/src/sbin/routed/output.c
usr/src/sbin/routed/table.h
usr/src/sbin/routed/tables.c

index ed21864..e0f7d6c 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)af.c       5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)af.c       5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -45,7 +45,11 @@ struct afswitch afswitch[AF_MAX] = {
 
 int af_max = sizeof(afswitch) / sizeof(afswitch[0]);
 
 
 int af_max = sizeof(afswitch) / sizeof(afswitch[0]);
 
-struct sockaddr_in inet_default = { AF_INET, INADDR_ANY };
+struct sockaddr_in inet_default = {
+#ifdef RTM_ADD
+       sizeof (inet_default),
+#endif
+       AF_INET, INADDR_ANY };
 
 inet_hash(sin, hp)
        register struct sockaddr_in *sin;
 
 inet_hash(sin, hp)
        register struct sockaddr_in *sin;
@@ -103,6 +107,8 @@ inet_output(s, flags, sin, size)
        sin = &dst;
        if (sin->sin_port == 0)
                sin->sin_port = sp->s_port;
        sin = &dst;
        if (sin->sin_port == 0)
                sin->sin_port = sp->s_port;
+       if (sin->sin_len == 0)
+               sin->sin_len = sizeof (*sin);
        if (sendto(s, packet, size, flags, sin, sizeof (*sin)) < 0)
                perror("sendto");
 }
        if (sendto(s, packet, size, flags, sin, sizeof (*sin)) < 0)
                perror("sendto");
 }
@@ -135,6 +141,7 @@ inet_canon(sin)
 {
 
        sin->sin_port = 0;
 {
 
        sin->sin_port = 0;
+       sin->sin_len = sizeof(*sin);
 }
 
 char *
 }
 
 char *
index fb34398..0e9501e 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)input.c    5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)input.c    5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -69,9 +69,13 @@ rip_input(from, rip, size)
                        count -= sizeof (struct netinfo);
 
 #if BSD < 198810
                        count -= sizeof (struct netinfo);
 
 #if BSD < 198810
-                       if (sizeof(n->rip_dst.sa_family) > 1)/* XXX */
-                               n->rip_dst.sa_family =
-                                       ntohs(n->rip_dst.sa_family);
+                       if (sizeof(n->rip_dst.sa_family) > 1)   /* XXX */
+                           n->rip_dst.sa_family = ntohs(n->rip_dst.sa_family);
+#else
+#define osa(x) ((struct osockaddr *)(&(x)))
+                           n->rip_dst.sa_family =
+                                       ntohs(osa(n->rip_dst)->sa_family);
+                           n->rip_dst.sa_len = sizeof(n->rip_dst);
 #endif
                        n->rip_metric = ntohl(n->rip_metric);
                        /* 
 #endif
                        n->rip_metric = ntohl(n->rip_metric);
                        /* 
@@ -92,11 +96,15 @@ rip_input(from, rip, size)
                                rt = rtlookup(&n->rip_dst);
                        else
                                rt = 0;
                                rt = rtlookup(&n->rip_dst);
                        else
                                rt = 0;
+#define min(a, b) (a < b ? a : b)
                        n->rip_metric = rt == 0 ? HOPCNT_INFINITY :
                                min(rt->rt_metric + 1, HOPCNT_INFINITY);
 #if BSD < 198810
                        if (sizeof(n->rip_dst.sa_family) > 1)   /* XXX */
                            n->rip_dst.sa_family = htons(n->rip_dst.sa_family);
                        n->rip_metric = rt == 0 ? HOPCNT_INFINITY :
                                min(rt->rt_metric + 1, HOPCNT_INFINITY);
 #if BSD < 198810
                        if (sizeof(n->rip_dst.sa_family) > 1)   /* XXX */
                            n->rip_dst.sa_family = htons(n->rip_dst.sa_family);
+#else
+                           osa(n->rip_dst)->sa_family =
+                                               htons(n->rip_dst.sa_family);
 #endif
                        n->rip_metric = htonl(n->rip_metric);
                }
 #endif
                        n->rip_metric = htonl(n->rip_metric);
                }
@@ -184,6 +192,10 @@ rip_input(from, rip, size)
                        if (sizeof(n->rip_dst.sa_family) > 1)   /* XXX */
                                n->rip_dst.sa_family =
                                        ntohs(n->rip_dst.sa_family);
                        if (sizeof(n->rip_dst.sa_family) > 1)   /* XXX */
                                n->rip_dst.sa_family =
                                        ntohs(n->rip_dst.sa_family);
+#else
+                           n->rip_dst.sa_family =
+                                       ntohs(osa(n->rip_dst)->sa_family);
+                           n->rip_dst.sa_len = sizeof(n->rip_dst);
 #endif
                        n->rip_metric = ntohl(n->rip_metric);
                        if (n->rip_dst.sa_family >= af_max ||
 #endif
                        n->rip_metric = ntohl(n->rip_metric);
                        if (n->rip_dst.sa_family >= af_max ||
index a42b243..cdaaac9 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)output.c   5.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)output.c   5.13 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -136,6 +136,9 @@ again:
 #if BSD < 198810
                if (sizeof(n->rip_dst.sa_family) > 1)   /* XXX */
                n->rip_dst.sa_family = htons(n->rip_dst.sa_family);
 #if BSD < 198810
                if (sizeof(n->rip_dst.sa_family) > 1)   /* XXX */
                n->rip_dst.sa_family = htons(n->rip_dst.sa_family);
+#else
+#define osa(x) ((struct osockaddr *)(&(x)))
+               osa(n->rip_dst)->sa_family = htons(n->rip_dst.sa_family);
 #endif
                n->rip_metric = htonl(rt->rt_metric);
                n++;
 #endif
                n->rip_metric = htonl(rt->rt_metric);
                n++;
index 5959c59..d6dd9ec 100644 (file)
@@ -14,7 +14,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)table.h     5.6 (Berkeley) %G%
+ *     @(#)table.h     5.7 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -31,6 +31,9 @@ struct rthash {
        struct  rt_entry *rt_forw;
        struct  rt_entry *rt_back;
 };
        struct  rt_entry *rt_forw;
        struct  rt_entry *rt_back;
 };
+#ifdef RTM_ADD
+#define rtentry ortentry
+#endif
 
 struct rt_entry {
        struct  rt_entry *rt_forw;
 
 struct rt_entry {
        struct  rt_entry *rt_forw;
index aace380..4b79d50 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tables.c   5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)tables.c   5.16 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -31,6 +31,12 @@ static char sccsid[] = "@(#)tables.c 5.15 (Berkeley) %G%";
 #define        DEBUG   0
 #endif
 
 #define        DEBUG   0
 #endif
 
+#ifdef RTM_ADD
+#define FIXLEN(s) {if ((s)->sa_len == 0) (s)->sa_len = sizeof *(s);}
+#else
+#define FIXLEN(s) { }
+#endif
+
 int    install = !DEBUG;               /* if 1 call kernel */
 
 /*
 int    install = !DEBUG;               /* if 1 call kernel */
 
 /*
@@ -138,6 +144,8 @@ rtadd(dst, gate, metric, state)
        /*
         * Subnet flag isn't visible to kernel, move to state.  XXX
         */
        /*
         * Subnet flag isn't visible to kernel, move to state.  XXX
         */
+       FIXLEN(dst);
+       FIXLEN(gate);
        if (flags & RTF_SUBNET) {
                state |= RTS_SUBNET;
                flags &= ~RTF_SUBNET;
        if (flags & RTF_SUBNET) {
                state |= RTS_SUBNET;
                flags &= ~RTF_SUBNET;
@@ -158,7 +166,7 @@ rtadd(dst, gate, metric, state)
        rt->rt_timer = 0;
        rt->rt_flags = RTF_UP | flags;
        rt->rt_state = state | RTS_CHANGED;
        rt->rt_timer = 0;
        rt->rt_flags = RTF_UP | flags;
        rt->rt_state = state | RTS_CHANGED;
-       rt->rt_ifp = if_ifwithdstaddr(&rt->rt_router);
+       rt->rt_ifp = if_ifwithdstaddr(&rt->rt_dst);
        if (rt->rt_ifp == 0)
                rt->rt_ifp = if_ifwithnet(&rt->rt_router);
        if ((state & RTS_INTERFACE) == 0)
        if (rt->rt_ifp == 0)
                rt->rt_ifp = if_ifwithnet(&rt->rt_router);
        if ((state & RTS_INTERFACE) == 0)
@@ -195,6 +203,9 @@ rtchange(rt, gate, metric)
        int add = 0, delete = 0, newgateway = 0;
        struct rtentry oldroute;
 
        int add = 0, delete = 0, newgateway = 0;
        struct rtentry oldroute;
 
+       FIXLEN(gate);
+       FIXLEN(&(rt->rt_router));
+       FIXLEN(&(rt->rt_dst));
        if (!equal(&rt->rt_router, gate)) {
                newgateway++;
                TRACE_ACTION("CHANGE FROM ", rt);
        if (!equal(&rt->rt_router, gate)) {
                newgateway++;
                TRACE_ACTION("CHANGE FROM ", rt);
@@ -237,12 +248,22 @@ rtchange(rt, gate, metric)
        rt->rt_state |= RTS_CHANGED;
        if (newgateway)
                TRACE_ACTION("CHANGE TO   ", rt);
        rt->rt_state |= RTS_CHANGED;
        if (newgateway)
                TRACE_ACTION("CHANGE TO   ", rt);
+#ifndef RTM_ADD
        if (add && install)
                if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
                        perror("SIOCADDRT");
        if (delete && install)
                if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
                        perror("SIOCDELRT");
        if (add && install)
                if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
                        perror("SIOCADDRT");
        if (delete && install)
                if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
                        perror("SIOCDELRT");
+#else
+       if (delete && install)
+               if (ioctl(s, SIOCDELRT, (char *)&oldroute) < 0)
+                       perror("SIOCDELRT");
+       if (add && install) {
+               if (ioctl(s, SIOCADDRT, (char *)&rt->rt_rt) < 0)
+                       perror("SIOCADDRT");
+       }
+#endif
 }
 
 rtdelete(rt)
 }
 
 rtdelete(rt)
@@ -250,6 +271,8 @@ rtdelete(rt)
 {
 
        TRACE_ACTION("DELETE", rt);
 {
 
        TRACE_ACTION("DELETE", rt);
+       FIXLEN(&(rt->rt_router));
+       FIXLEN(&(rt->rt_dst));
        if (rt->rt_metric < HOPCNT_INFINITY) {
            if ((rt->rt_state & (RTS_INTERFACE|RTS_INTERNAL)) == RTS_INTERFACE)
                syslog(LOG_ERR,
        if (rt->rt_metric < HOPCNT_INFINITY) {
            if ((rt->rt_state & (RTS_INTERFACE|RTS_INTERNAL)) == RTS_INTERFACE)
                syslog(LOG_ERR,