provide correct exit values
[unix-history] / usr / src / sbin / routed / input.c
index 5f6bf31..013fd15 100644 (file)
@@ -1,12 +1,23 @@
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1983, 1988 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.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)input.c    5.14 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)input.c    5.18 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Routing Table Management Daemon
 
 /*
  * Routing Table Management Daemon
@@ -27,7 +38,7 @@ rip_input(from, size)
        struct interface *if_ifwithdstaddr();
        int newsize;
        register struct afswitch *afp;
        struct interface *if_ifwithdstaddr();
        int newsize;
        register struct afswitch *afp;
-       static struct sockaddr badfrom;
+       static struct sockaddr badfrom, badfrom2;
 
        ifp = 0;
        TRACE_INPUT(ifp, from, size);
 
        ifp = 0;
        TRACE_INPUT(ifp, from, size);
@@ -115,6 +126,12 @@ rip_input(from, size)
                /* are we talking to ourselves? */
                ifp = if_ifwithaddr(from);
                if (ifp) {
                /* are we talking to ourselves? */
                ifp = if_ifwithaddr(from);
                if (ifp) {
+                       if (ifp->int_flags & IFF_PASSIVE) {
+                               syslog(LOG_ERR,
+                                 "bogus input (from passive interface, %s)",
+                                 (*afswitch[from->sa_family].af_format)(from));
+                               return;
+                       }
                        rt = rtfind(from);
                        if (rt == 0 || ((rt->rt_state & RTS_INTERFACE) == 0) &&
                            rt->rt_metric >= ifp->int_metric) 
                        rt = rtfind(from);
                        if (rt == 0 || ((rt->rt_state & RTS_INTERFACE) == 0) &&
                            rt->rt_metric >= ifp->int_metric) 
@@ -179,6 +196,18 @@ rip_input(from, size)
                                   from->sa_family);
                                continue;
                        }
                                   from->sa_family);
                                continue;
                        }
+                       if (n->rip_metric == 0 ||
+                           (unsigned) n->rip_metric > HOPCNT_INFINITY) {
+                               if (bcmp((char *)from, (char *)&badfrom2,
+                                   sizeof(badfrom2)) != 0) {
+                                       syslog(LOG_ERR,
+                                           "bad metric (%d) from %s\n",
+                                           n->rip_metric,
+                                 (*afswitch[from->sa_family].af_format)(from));
+                                       badfrom2 = *from;
+                               }
+                               continue;
+                       }
                        /*
                         * Adjust metric according to incoming interface.
                         */
                        /*
                         * Adjust metric according to incoming interface.
                         */
@@ -198,33 +227,37 @@ rip_input(from, size)
                                if (rt && rt->rt_state & RTS_SUBNET &&
                                    (*afp->af_sendroute)(rt, from))
                                        continue;
                                if (rt && rt->rt_state & RTS_SUBNET &&
                                    (*afp->af_sendroute)(rt, from))
                                        continue;
-                               /*
-                                * Look for an equivalent route that includes
-                                * this one before adding this route.
-                                */
-                               rt = rtfind(&n->rip_dst);
-                               if (rt && equal(from, &rt->rt_router))
-                                       continue;
-                               if (n->rip_metric < HOPCNT_INFINITY)
+                               if ((unsigned)n->rip_metric < HOPCNT_INFINITY) {
+                                   /*
+                                    * Look for an equivalent route that
+                                    * includes this one before adding
+                                    * this route.
+                                    */
+                                   rt = rtfind(&n->rip_dst);
+                                   if (rt && equal(from, &rt->rt_router))
+                                           continue;
                                    rtadd(&n->rip_dst, from, n->rip_metric, 0);
                                    rtadd(&n->rip_dst, from, n->rip_metric, 0);
+                               }
                                continue;
                        }
 
                        /*
                         * Update if from gateway and different,
                                continue;
                        }
 
                        /*
                         * Update if from gateway and different,
-                        * shorter, or getting stale and equivalent.
+                        * shorter, or equivalent but old route
+                        * is getting stale.
                         */
                        if (equal(from, &rt->rt_router)) {
                                if (n->rip_metric != rt->rt_metric) {
                                        rtchange(rt, from, n->rip_metric);
                         */
                        if (equal(from, &rt->rt_router)) {
                                if (n->rip_metric != rt->rt_metric) {
                                        rtchange(rt, from, n->rip_metric);
+                                       rt->rt_timer = 0;
                                        if (rt->rt_metric >= HOPCNT_INFINITY)
                                                rt->rt_timer =
                                                    GARBAGE_TIME - EXPIRE_TIME;
                                } else if (rt->rt_metric < HOPCNT_INFINITY)
                                        rt->rt_timer = 0;
                        } else if ((unsigned) n->rip_metric < rt->rt_metric ||
                                        if (rt->rt_metric >= HOPCNT_INFINITY)
                                                rt->rt_timer =
                                                    GARBAGE_TIME - EXPIRE_TIME;
                                } else if (rt->rt_metric < HOPCNT_INFINITY)
                                        rt->rt_timer = 0;
                        } else if ((unsigned) n->rip_metric < rt->rt_metric ||
-                           (rt->rt_timer > (EXPIRE_TIME/2) &&
-                           rt->rt_metric == n->rip_metric &&
+                           (rt->rt_metric == n->rip_metric &&
+                           rt->rt_timer > (EXPIRE_TIME/2) &&
                            (unsigned) n->rip_metric < HOPCNT_INFINITY)) {
                                rtchange(rt, from, n->rip_metric);
                                rt->rt_timer = 0;
                            (unsigned) n->rip_metric < HOPCNT_INFINITY)) {
                                rtchange(rt, from, n->rip_metric);
                                rt->rt_timer = 0;