2 * Copyright (c) 1995, Mike Mitchell
3 * Copyright (c) 1984, 1985, 1986, 1987, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * $FreeBSD: src/sys/netipx/ipx_outputfl.c,v 1.14.2.1 2000/05/01 01:10:24 bp Exp $
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/socket.h>
45 #include <net/route.h>
47 #include <netipx/ipx.h>
48 #include <netipx/ipx_if.h>
49 #include <netipx/ipx_var.h>
52 #include <machine/mtpr.h>
55 static int ipx_copy_output = 0;
58 ipx_outputfl(m0, ro, flags)
63 register struct ipx *ipx = mtod(m0, struct ipx *);
64 register struct ifnet *ifp = NULL;
66 struct sockaddr_ipx *dst;
67 struct route ipxroute;
74 bzero((caddr_t)ro, sizeof(*ro));
76 dst = (struct sockaddr_ipx *)&ro->ro_dst;
77 if (ro->ro_rt == NULL) {
78 dst->sipx_family = AF_IPX;
79 dst->sipx_len = sizeof(*dst);
80 dst->sipx_addr = ipx->ipx_dna;
81 dst->sipx_addr.x_port = 0;
83 * If routing to interface only,
84 * short circuit routing lookup.
86 if (flags & IPX_ROUTETOIF) {
87 struct ipx_ifaddr *ia = ipx_iaonnetof(&ipx->ipx_dna);
90 ipxstat.ipxs_noroute++;
98 } else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
100 * The old route has gone away; try for a new one.
106 if (ro->ro_rt == NULL || (ifp = ro->ro_rt->rt_ifp) == NULL) {
107 ipxstat.ipxs_noroute++;
112 if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
113 dst = (struct sockaddr_ipx *)ro->ro_rt->rt_gateway;
116 * Look for multicast addresses and
117 * and verify user is allowed to send
120 if (dst->sipx_addr.x_host.c_host[0]&1) {
121 if ((ifp->if_flags & (IFF_BROADCAST | IFF_LOOPBACK)) == 0) {
122 error = EADDRNOTAVAIL;
125 if ((flags & IPX_ALLOWBROADCAST) == 0) {
129 m0->m_flags |= M_BCAST;
132 if (htons(ipx->ipx_len) <= ifp->if_mtu) {
133 ipxstat.ipxs_localout++;
134 if (ipx_copy_output) {
135 ipx_watch_output(m0, ifp);
137 error = (*ifp->if_output)(ifp, m0,
138 (struct sockaddr *)dst, ro->ro_rt);
141 ipxstat.ipxs_mtutoosmall++;
145 if (ipx_copy_output) {
146 ipx_watch_output(m0, ifp);
150 if (ro == &ipxroute && (flags & IPX_ROUTETOIF) == 0 &&
159 * This will broadcast the type 20 (Netbios) packet to all the interfaces
160 * that have ipx configured and isn't in the list yet.
166 register struct ipx *ipx;
167 union ipx_net *nbnet;
168 struct ipx_ifaddr *ia, *tia = NULL;
173 struct sockaddr_ipx dst;
176 * We have to get to the 32 bytes after the ipx header also, so
177 * that we can fill in the network address of the receiving
180 if ((m->m_flags & M_EXT || m->m_len < (sizeof(struct ipx) + 32)) &&
181 (m = m_pullup(m, sizeof(struct ipx) + 32)) == NULL) {
182 ipxstat.ipxs_toosmall++;
185 ipx = mtod(m, struct ipx *);
186 nbnet = (union ipx_net *)(ipx + 1);
188 if (ipx->ipx_tc >= 8)
191 * Now see if we have already seen this.
193 for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next)
194 if(ia->ia_ifa.ifa_ifp == m->m_pkthdr.rcvif) {
198 for (i=0;i<ipx->ipx_tc;i++,nbnet++)
199 if(ipx_neteqnn(ia->ia_addr.sipx_addr.x_net,
204 * Don't route the packet if the interface where it come from
205 * does not have an IPX address.
211 * Add our receiving interface to the list.
213 nbnet = (union ipx_net *)(ipx + 1);
214 nbnet += ipx->ipx_tc;
215 *nbnet = tia->ia_addr.sipx_addr.x_net;
218 * Increment the hop count.
221 ipxstat.ipxs_forward++;
224 * Send to all directly connected ifaces not in list and
225 * not to the one it came from.
227 m->m_flags &= ~M_BCAST;
228 bzero(&dst, sizeof(dst));
229 dst.sipx_family = AF_IPX;
231 dst.sipx_addr.x_host = ipx_broadhost;
233 for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next)
234 if(ia->ia_ifa.ifa_ifp != m->m_pkthdr.rcvif) {
235 nbnet = (union ipx_net *)(ipx + 1);
236 for (i=0;i<ipx->ipx_tc;i++,nbnet++)
237 if(ipx_neteqnn(ia->ia_addr.sipx_addr.x_net,
242 * Insert the net address of the dest net and
243 * calculate the new checksum if needed.
245 ifp = ia->ia_ifa.ifa_ifp;
246 dst.sipx_addr.x_net = ia->ia_addr.sipx_addr.x_net;
247 ipx->ipx_dna.x_net = dst.sipx_addr.x_net;
248 if(ipx->ipx_sum != 0xffff)
249 ipx->ipx_sum = ipx_cksum(m, ntohs(ipx->ipx_len));
251 m1 = m_copym(m, 0, M_COPYALL, M_DONTWAIT);
253 error = (*ifp->if_output)(ifp, m1,
254 (struct sockaddr *)&dst, NULL);
255 /* XXX ipxstat.ipxs_localout++; */