|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) 1984, 1985, 1986, 1987, 1993
27: * The Regents of the University of California. All rights reserved.
28: *
29: * Redistribution and use in source and binary forms, with or without
30: * modification, are permitted provided that the following conditions
31: * are met:
32: * 1. Redistributions of source code must retain the above copyright
33: * notice, this list of conditions and the following disclaimer.
34: * 2. Redistributions in binary form must reproduce the above copyright
35: * notice, this list of conditions and the following disclaimer in the
36: * documentation and/or other materials provided with the distribution.
37: * 3. All advertising materials mentioning features or use of this software
38: * must display the following acknowledgement:
39: * This product includes software developed by the University of
40: * California, Berkeley and its contributors.
41: * 4. Neither the name of the University nor the names of its contributors
42: * may be used to endorse or promote products derived from this software
43: * without specific prior written permission.
44: *
45: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
46: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
49: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55: * SUCH DAMAGE.
56: *
57: * @(#)ns_output.c 8.1 (Berkeley) 6/10/93
58: */
59:
60: #include <sys/param.h>
61: #include <sys/malloc.h>
62: #include <sys/mbuf.h>
63: #include <sys/errno.h>
64: #include <sys/socket.h>
65: #include <sys/socketvar.h>
66:
67: #include <net/if.h>
68: #include <net/route.h>
69:
70: #include <netns/ns.h>
71: #include <netns/ns_if.h>
72: #include <netns/idp.h>
73: #include <netns/idp_var.h>
74:
75: #ifdef vax
76: #include <machine/mtpr.h>
77: #endif
78: int ns_hold_output = 0;
79: int ns_copy_output = 0;
80: int ns_output_cnt = 0;
81: struct mbuf *ns_lastout;
82:
83: ns_output(m0, ro, flags)
84: struct mbuf *m0;
85: struct route *ro;
86: int flags;
87: {
88: register struct idp *idp = mtod(m0, struct idp *);
89: register struct ifnet *ifp = 0;
90: int error = 0;
91: struct route idproute;
92: struct sockaddr_ns *dst;
93: extern int idpcksum;
94:
95: if (ns_hold_output) {
96: if (ns_lastout) {
97: (void)m_free(ns_lastout);
98: }
99: ns_lastout = m_copy(m0, 0, (int)M_COPYALL);
100: }
101: /*
102: * Route packet.
103: */
104: if (ro == 0) {
105: ro = &idproute;
106: bzero((caddr_t)ro, sizeof (*ro));
107: }
108: dst = (struct sockaddr_ns *)&ro->ro_dst;
109: if (ro->ro_rt == 0) {
110: dst->sns_family = AF_NS;
111: dst->sns_len = sizeof (*dst);
112: dst->sns_addr = idp->idp_dna;
113: dst->sns_addr.x_port = 0;
114: /*
115: * If routing to interface only,
116: * short circuit routing lookup.
117: */
118: if (flags & NS_ROUTETOIF) {
119: struct ns_ifaddr *ia = ns_iaonnetof(&idp->idp_dna);
120:
121: if (ia == 0) {
122: error = ENETUNREACH;
123: goto bad;
124: }
125: ifp = ia->ia_ifp;
126: goto gotif;
127: }
128: rtalloc(ro);
129: } else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
130: /*
131: * The old route has gone away; try for a new one.
132: */
133: rtfree(ro->ro_rt);
134: ro->ro_rt = NULL;
135: rtalloc(ro);
136: }
137: if (ro->ro_rt == 0 || (ifp = ro->ro_rt->rt_ifp) == 0) {
138: error = ENETUNREACH;
139: goto bad;
140: }
141: ro->ro_rt->rt_use++;
142: if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
143: dst = (struct sockaddr_ns *)ro->ro_rt->rt_gateway;
144: gotif:
145:
146: /*
147: * Look for multicast addresses and
148: * and verify user is allowed to send
149: * such a packet.
150: */
151: if (dst->sns_addr.x_host.c_host[0]&1) {
152: if ((ifp->if_flags & IFF_BROADCAST) == 0) {
153: error = EADDRNOTAVAIL;
154: goto bad;
155: }
156: if ((flags & NS_ALLOWBROADCAST) == 0) {
157: error = EACCES;
158: goto bad;
159: }
160: }
161:
162: if (htons(idp->idp_len) <= ifp->if_mtu) {
163: ns_output_cnt++;
164: if (ns_copy_output) {
165: ns_watch_output(m0, ifp);
166: }
167: error = (*ifp->if_output)(ifp, m0,
168: (struct sockaddr *)dst, ro->ro_rt);
169: goto done;
170: } else error = EMSGSIZE;
171:
172:
173: bad:
174: if (ns_copy_output) {
175: ns_watch_output(m0, ifp);
176: }
177: m_freem(m0);
178: done:
179: if (ro == &idproute && (flags & NS_ROUTETOIF) == 0 && ro->ro_rt) {
180: RTFREE(ro->ro_rt);
181: ro->ro_rt = 0;
182: }
183: return (error);
184: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.