fix route caching (which had been causing packets to go out on the
authorKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Fri, 27 Sep 1985 06:18:02 +0000 (22:18 -0800)
committerKeith Sklower <sklower@ucbvax.Berkeley.EDU>
Fri, 27 Sep 1985 06:18:02 +0000 (22:18 -0800)
wrong interface).

SCCS-vsn: sys/netns/idp_usrreq.c 6.10

usr/src/sys/netns/idp_usrreq.c

index d7556f9..bf23e11 100644 (file)
@@ -3,7 +3,7 @@
  * 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.
  *
- *      @(#)idp_usrreq.c       6.9 (Berkeley) %G%
+ *      @(#)idp_usrreq.c       6.10 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -49,7 +49,7 @@ idp_input(m, nsp, ifp)
         * Stuff source address and datagram in user buffer.
         */
        idp_ns.sns_addr = idp->idp_sna;
         * Stuff source address and datagram in user buffer.
         */
        idp_ns.sns_addr = idp->idp_sna;
-       if (ns_netof(idp->idp_sna)==0) {
+       if (ns_netof(idp->idp_sna)==0 && ifp) {
                register struct ifaddr *ia;
 
                for (ia = ifp->if_addrlist; ia; ia = ia->ifa_next) {
                register struct ifaddr *ia;
 
                for (ia = ifp->if_addrlist; ia; ia = ia->ifa_next) {
@@ -107,6 +107,7 @@ idp_drop(nsp, errno)
        soisdisconnected(so);
 }
 
        soisdisconnected(so);
 }
 
+int noIdpRoute;
 idp_output(nsp, m0)
        struct nspcb *nsp;
        struct mbuf *m0;
 idp_output(nsp, m0)
        struct nspcb *nsp;
        struct mbuf *m0;
@@ -190,19 +191,47 @@ idp_output(nsp, m0)
                    (so->so_options & SO_BROADCAST) | NS_ROUTETOIF));
        /*
         * Use cached route for previous datagram if
                    (so->so_options & SO_BROADCAST) | NS_ROUTETOIF));
        /*
         * Use cached route for previous datagram if
-        * this is also to the same destination. 
+        * possible.  If the previous net was the same
+        * and the interface was a broadcast medium, or
+        * if the previous destination was identical,
+        * then we are ok.
         *
         * NB: We don't handle broadcasts because that
         *     would require 3 subroutine calls.
         */
        ro = &nsp->nsp_route;
         *
         * NB: We don't handle broadcasts because that
         *     would require 3 subroutine calls.
         */
        ro = &nsp->nsp_route;
-       if (ro->ro_rt &&
-               ((*(long *)&nsp->nsp_lastnet)!=ns_netof(idp->idp_dna)) &&
-               !(ns_hosteq(satons_addr(ro->ro_dst), idp->idp_dna))) {
-               RTFREE(ro->ro_rt);
-               ro->ro_rt = (struct rtentry *)0;
-               nsp->nsp_lastnet = idp->idp_dna.x_net;
+#ifdef ancient_history
+       /*
+        * I think that this will all be handled in ns_pcbconnect!
+        */
+       if (ro->ro_rt) {
+               if(ns_neteq(nsp->nsp_lastdst, idp->idp_dna)) {
+                       /*
+                        * This assumes we have no GH type routes
+                        */
+                       if (ro->ro_rt->rt_flags & RTF_HOST) {
+                               if (!ns_hosteq(nsp->nsp_lastdst, idp->idp_dna))
+                                       goto re_route;
+
+                       }
+                       if ((ro->ro_rt->rt_flags & RTF_GATEWAY) == 0) {
+                               register struct ns_addr *dst =
+                                               &satons_addr(ro->ro_dst);
+                               dst->x_host = idp->idp_dna.x_host;
+                       }
+                       /* 
+                        * Otherwise, we go through the same gateway
+                        * and dst is already set up.
+                        */
+               } else {
+               re_route:
+                       RTFREE(ro->ro_rt);
+                       ro->ro_rt = (struct rtentry *)0;
+               }
        }
        }
+       nsp->nsp_lastdst = idp->idp_dna;
+#endif ancient_history
+       if (noIdpRoute) ro = 0;
        return (ns_output(m, ro, so->so_options & SO_BROADCAST));
 }
 /* ARGSUSED */
        return (ns_output(m, ro, so->so_options & SO_BROADCAST));
 }
 /* ARGSUSED */