# 2.11BSD#431 - /usr/src/sys/netns/ns_output.c

##### Functions

    ns_output         X

##### Variables

    ns_copy_output    X
    ns_hold_output    X
    ns_lastout        X
    ns_output_cnt     X

       1: /*
       2:  * Copyright (c) 1984, 1985, 1986, 1987 Regents of the University of California.
       3:  * All rights reserved.
       4:  *
       5:  * Redistribution and use in source and binary forms are permitted
       6:  * provided that this notice is preserved and that due credit is given
       7:  * to the University of California at Berkeley. The name of the University
       8:  * may not be used to endorse or promote products derived from this
       9:  * software without specific prior written permission. This software
      10:  * is provided ``as is'' without express or implied warranty.
      11:  *
      12:  *      @(#)ns_output.c	7.2 (Berkeley) 1/20/88
      13:  */
      14:
      15: #include "param.h"
      16: #ifdef  NS
      17: #include "mbuf.h"
      18: #include "errno.h"
      19: #include "socket.h"
      20: #include "socketvar.h"
      21:
      22: #include "../net/if.h"
      23: #include "../net/route.h"
      24:
      25: #include "ns.h"
      26: #include "ns_if.h"
      27: #include "idp.h"
      28: #include "idp_var.h"
      29:
      30: #ifdef vax
      31: #include "../vax/mtpr.h"
      32: #endif
      33: int ns_hold_output = 0;
      34: int ns_copy_output = 0;
      35: int ns_output_cnt = 0;
      36: struct mbuf *ns_lastout;
      37:
      38: ns_output(m0, ro, flags)
      39:     struct mbuf *m0;
      40:     struct route *ro;
      41:     int flags;
      42: {
      43:     register struct idp *idp = mtod(m0, struct idp *);
      44:     register struct ifnet *ifp = 0;
      45:     int error = 0;
      46:     struct route idproute;
      47:     struct sockaddr_ns *dst;
      48:     extern int idpcksum;
      49:
      50:     if (ns_hold_output) {
      51:         if (ns_lastout) {
      52:             (void)m_free(ns_lastout);
      53:         }
      54:         ns_lastout = m_copy(m0, 0, (int)M_COPYALL);
      55:     }
      56:     /*
      57: 	 * Route packet.
      58: 	 */
      59:     if (ro == 0) {
      60:         ro = &idproute;
      61:         bzero((caddr_t)ro, sizeof (*ro));
      62:     }
      63:     dst = (struct sockaddr_ns *)&ro->ro_dst;
      64:     if (ro->ro_rt == 0) {
      65:         dst->sns_family = AF_NS;
      66:         dst->sns_addr = idp->idp_dna;
      67:         dst->sns_addr.x_port = 0;
      68:         /*
      69: 		 * If routing to interface only,
      70: 		 * short circuit routing lookup.
      71: 		 */
      72:         if (flags & NS_ROUTETOIF) {
      73:             struct ns_ifaddr *ia = ns_iaonnetof(&idp->idp_dna);
      74:
      75:             if (ia == 0) {
      76:                 error = ENETUNREACH;
      77:                 goto bad;
      78:             }
      79:             ifp = ia->ia_ifp;
      80:             goto gotif;
      81:         }
      82:         rtalloc(ro);
      83:     } else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
      84:         /*
      85: 		 * The old route has gone away; try for a new one.
      86: 		 */
      87:         rtfree(ro->ro_rt);
      88:         ro->ro_rt = NULL;
      89:         rtalloc(ro);
      90:     }
      91:     if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
      92:         error = ENETUNREACH;
      93:         goto bad;
      94:     }
      95:     ro->ro_rt->rt_use++;
      96:     if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
      97:         dst = (struct sockaddr_ns *)&ro->ro_rt->rt_gateway;
      98: gotif:
      99:
     100:     /*
     101: 	 * Look for multicast addresses and
     102: 	 * and verify user is allowed to send
     103: 	 * such a packet.
     104: 	 */
     105:     if (dst->sns_addr.x_host.c_host[0]&1) {
     106:         if ((ifp->if_flags & IFF_BROADCAST) == 0) {
     107:             error = EADDRNOTAVAIL;
     108:             goto bad;
     109:         }
     110:         if ((flags & NS_ALLOWBROADCAST) == 0) {
     111:             error = EACCES;
     112:             goto bad;
     113:         }
     114:     }
     115:
     116:     if (htons(idp->idp_len) <= ifp->if_mtu) {
     117:         ns_output_cnt++;
     118:         if (ns_copy_output) {
     119:             ns_watch_output(m0, ifp);
     120:         }
     121:         error = (*ifp->if_output)(ifp, m0, (struct sockaddr *)dst);
     122:         goto done;
     123:     } else error = EMSGSIZE;
     124:
     125:
     126: bad:
     127:     if (ns_copy_output) {
     128:         ns_watch_output(m0, ifp);
     129:     }
     130:     m_freem(m0);
     131: done:
     132:     if (ro == &idproute && (flags & NS_ROUTETOIF) == 0 && ro->ro_rt)
     133:         RTFREE(ro->ro_rt);
     134:     return (error);
     135: }
     136: #endif

#### Defined functions

ns_output defined in line 38; never used

#### Defined variables

ns_copy_output defined in line 34; used 2 times

- in line 118, 127

ns_hold_output defined in line 33; used 1 times

- in line 50

ns_lastout defined in line 36; used 3 times

- in line 51-54(3)

ns_output_cnt defined in line 35; used 1 times

- in line 117

Last modified: 1988-04-29 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 701 |