bring up to revision 7 for tahoe release
[unix-history] / usr / src / sys / netns / idp_usrreq.c
index d7556f9..8cbb8f2 100644 (file)
@@ -1,9 +1,15 @@
 /*
 /*
- * Copyright (c) 1982 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
+ * All rights reserved.
  *
  *
- *      @(#)idp_usrreq.c       6.9 (Berkeley) %G%
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of California at 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'' without express or implied warranty.
+ *
+ *      @(#)idp_usrreq.c       7.2 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -49,7 +55,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_neteqnn(idp->idp_sna.x_net, ns_zeronet) && 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 +113,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;
@@ -161,7 +168,9 @@ idp_output(nsp, m0)
                        m_freem(m0);
                        return (ENOBUFS);
                }
                        m_freem(m0);
                        return (ENOBUFS);
                }
-               m->m_off = MMAXOFF - sizeof (struct idp);
+               m->m_off = MMAXOFF - sizeof (struct idp) - 2;
+                               /* adjust to start on longword bdry
+                                  for NSIP on gould */
                m->m_len = sizeof (struct idp);
                m->m_next = m0;
                idp = mtod(m, struct idp *);
                m->m_len = sizeof (struct idp);
                m->m_next = m0;
                idp = mtod(m, struct idp *);
@@ -190,19 +199,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 */
@@ -264,6 +301,10 @@ idp_ctloutput(req, so, level, name, value)
                        m->m_len = sizeof(long);
                        m->m_off = MMAXOFF - sizeof(long);
                        *mtod(m, long *) = ns_pexseq++;
                        m->m_len = sizeof(long);
                        m->m_off = MMAXOFF - sizeof(long);
                        *mtod(m, long *) = ns_pexseq++;
+                       break;
+
+               default:
+                       error = EINVAL;
                }
                *value = m;
                break;
                }
                *value = m;
                break;
@@ -298,12 +339,15 @@ idp_ctloutput(req, so, level, name, value)
                                    = mtod(*value, struct idp *);
                                nsp->nsp_dpt = idp->idp_pt;
                        }
                                    = mtod(*value, struct idp *);
                                nsp->nsp_dpt = idp->idp_pt;
                        }
-#ifdef NSIP
                        break;
                        break;
+#ifdef NSIP
 
                case SO_NSIP_ROUTE:
                        error = nsip_route(*value);
 
                case SO_NSIP_ROUTE:
                        error = nsip_route(*value);
+                       break;
 #endif NSIP
 #endif NSIP
+               default:
+                       error = EINVAL;
                }
                if (value && *value)
                        m_freem(*value);
                }
                if (value && *value)
                        m_freem(*value);