BSD 4_4 release
[unix-history] / usr / src / sbin / routed / input.c
index 16d94c7..fb0ee79 100644 (file)
@@ -1,22 +1,38 @@
 /*
 /*
- * Copyright (c) 1983, 1988 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1983, 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)input.c    5.19 (Berkeley) %G%";
+static char sccsid[] = "@(#)input.c    8.1 (Berkeley) 6/5/93";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -28,8 +44,9 @@ static char sccsid[] = "@(#)input.c   5.19 (Berkeley) %G%";
 /*
  * Process a newly received packet.
  */
 /*
  * Process a newly received packet.
  */
-rip_input(from, size)
+rip_input(from, rip, size)
        struct sockaddr *from;
        struct sockaddr *from;
+       register struct rip *rip;
        int size;
 {
        register struct rt_entry *rt;
        int size;
 {
        register struct rt_entry *rt;
@@ -41,25 +58,25 @@ rip_input(from, size)
        static struct sockaddr badfrom, badfrom2;
 
        ifp = 0;
        static struct sockaddr badfrom, badfrom2;
 
        ifp = 0;
-       TRACE_INPUT(ifp, from, size);
+       TRACE_INPUT(ifp, from, (char *)rip, size);
        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",
        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);
+                   from->sa_family, rip->rip_cmd);
                return;
        }
                return;
        }
-       if (msg->rip_vers == 0) {
+       if (rip->rip_vers == 0) {
                syslog(LOG_ERR,
                    "RIP version 0 packet received from %s! (cmd %d)",
                syslog(LOG_ERR,
                    "RIP version 0 packet received from %s! (cmd %d)",
-                   (*afswitch[from->sa_family].af_format)(from), msg->rip_cmd);
+                   (*afswitch[from->sa_family].af_format)(from), rip->rip_cmd);
                return;
        }
                return;
        }
-       switch (msg->rip_cmd) {
+       switch (rip->rip_cmd) {
 
        case RIPCMD_REQUEST:
 
        case RIPCMD_REQUEST:
-               n = msg->rip_nets;
-               count = size - ((char *)n - (char *)msg);
+               n = rip->rip_nets;
+               count = size - ((char *)n - (char *)rip);
                if (count < sizeof (struct netinfo))
                        return;
                for (; count > 0; n++) {
                if (count < sizeof (struct netinfo))
                        return;
                for (; count > 0; n++) {
@@ -68,9 +85,13 @@ rip_input(from, 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);
                        /* 
@@ -91,15 +112,20 @@ rip_input(from, 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);
                }
-               msg->rip_cmd = RIPCMD_RESPONSE;
+               rip->rip_cmd = RIPCMD_RESPONSE;
+               bcopy((char *)rip, packet, size);
                (*afp->af_output)(s, 0, from, size);
                return;
 
                (*afp->af_output)(s, 0, from, size);
                return;
 
@@ -115,9 +141,9 @@ rip_input(from, size)
                            (*afswitch[from->sa_family].af_format)(from));
                        return;
                }
                            (*afswitch[from->sa_family].af_format)(from));
                        return;
                }
-               packet[size] = '\0';
-               if (msg->rip_cmd == RIPCMD_TRACEON)
-                       traceon(msg->rip_tracefile);
+               ((char *)rip)[size] = '\0';
+               if (rip->rip_cmd == RIPCMD_TRACEON)
+                       traceon(rip->rip_tracefile);
                else
                        traceoff();
                return;
                else
                        traceoff();
                return;
@@ -174,7 +200,7 @@ rip_input(from, size)
                        return;
                }
                size -= 4 * sizeof (char);
                        return;
                }
                size -= 4 * sizeof (char);
-               n = msg->rip_nets;
+               n = rip->rip_nets;
                for (; size > 0; size -= sizeof (struct netinfo), n++) {
                        if (size < sizeof (struct netinfo))
                                break;
                for (; size > 0; size -= sizeof (struct netinfo), n++) {
                        if (size < sizeof (struct netinfo))
                                break;
@@ -182,6 +208,10 @@ rip_input(from, 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 ||