date and time created 88/07/22 16:08:01 by bostic
[unix-history] / usr / src / sys / netns / ns_output.c
index b43430b..4942aec 100644 (file)
@@ -1,9 +1,20 @@
 /*
 /*
- * 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.
  *
  *
- *     @(#)ns_output.c 6.3 (Berkeley) %G%
+ * 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.
+ *
+ *     @(#)ns_output.c 7.3 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -34,23 +45,18 @@ ns_output(m0, ro, flags)
        int flags;
 {
        register struct idp *idp = mtod(m0, struct idp *);
        int flags;
 {
        register struct idp *idp = mtod(m0, struct idp *);
-       register struct ifnet *ifp;
-       register struct mbuf *m;
-       int len, rlen, off, error = 0;
+       register struct ifnet *ifp = 0;
+       int error = 0;
        struct route idproute;
        struct sockaddr_ns *dst;
        extern int idpcksum;
 
        struct route idproute;
        struct sockaddr_ns *dst;
        extern int idpcksum;
 
-       if(ns_hold_output) {
-               if(ns_lastout) {
-                       m_free(ns_lastout);
+       if (ns_hold_output) {
+               if (ns_lastout) {
+                       (void)m_free(ns_lastout);
                }
                }
-               ns_lastout = m_copy(m0, 0, M_COPYALL);
-       }
-       if(ns_copy_output) {
-               ns_watch_output(m0);
+               ns_lastout = m_copy(m0, 0, (int)M_COPYALL);
        }
        }
-
        /*
         * Route packet.
         */
        /*
         * Route packet.
         */
@@ -62,13 +68,14 @@ ns_output(m0, ro, flags)
        if (ro->ro_rt == 0) {
                dst->sns_family = AF_NS;
                dst->sns_addr = idp->idp_dna;
        if (ro->ro_rt == 0) {
                dst->sns_family = AF_NS;
                dst->sns_addr = idp->idp_dna;
+               dst->sns_addr.x_port = 0;
                /*
                 * If routing to interface only,
                 * short circuit routing lookup.
                 */
                if (flags & NS_ROUTETOIF) {
                /*
                 * If routing to interface only,
                 * short circuit routing lookup.
                 */
                if (flags & NS_ROUTETOIF) {
-                       struct ns_ifaddr *ia;
-                       ia = ns_iaonnetof(idp->idp_dna.x_net);
+                       struct ns_ifaddr *ia = ns_iaonnetof(&idp->idp_dna);
+
                        if (ia == 0) {
                                error = ENETUNREACH;
                                goto bad;
                        if (ia == 0) {
                                error = ENETUNREACH;
                                goto bad;
@@ -82,6 +89,7 @@ ns_output(m0, ro, flags)
                 * The old route has gone away; try for a new one.
                 */
                rtfree(ro->ro_rt);
                 * The old route has gone away; try for a new one.
                 */
                rtfree(ro->ro_rt);
+               ro->ro_rt = NULL;
                rtalloc(ro);
        }
        if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
                rtalloc(ro);
        }
        if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
@@ -111,12 +119,18 @@ gotif:
 
        if (htons(idp->idp_len) <= ifp->if_mtu) {
                ns_output_cnt++;
 
        if (htons(idp->idp_len) <= ifp->if_mtu) {
                ns_output_cnt++;
+               if (ns_copy_output) {
+                       ns_watch_output(m0, ifp);
+               }
                error = (*ifp->if_output)(ifp, m0, (struct sockaddr *)dst);
                goto done;
        } else error = EMSGSIZE;
 
 
 bad:
                error = (*ifp->if_output)(ifp, m0, (struct sockaddr *)dst);
                goto done;
        } else error = EMSGSIZE;
 
 
 bad:
+       if (ns_copy_output) {
+               ns_watch_output(m0, ifp);
+       }
        m_freem(m0);
 done:
        if (ro == &idproute && (flags & NS_ROUTETOIF) == 0 && ro->ro_rt)
        m_freem(m0);
 done:
        if (ro == &idproute && (flags & NS_ROUTETOIF) == 0 && ro->ro_rt)