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. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $FreeBSD: src/sys/netipx/ipx_outputfl.c,v 1.14.2.1 2000/05/01 01:10:24 bp Exp $
33 * $DragonFly: src/sys/netproto/ipx/ipx_outputfl.c,v 1.9 2008/05/14 11:59:24 sephe Exp $
36 #include <sys/param.h>
37 #include <sys/systm.h>
39 #include <sys/socket.h>
42 #include <net/route.h>
48 static int ipx_copy_output = 0;
51 ipx_outputfl(struct mbuf *m0, struct route *ro, int flags)
53 struct ipx *ipx = mtod(m0, struct ipx *);
54 struct ifnet *ifp = NULL;
56 struct sockaddr_ipx *dst;
57 struct route ipxroute;
64 bzero((caddr_t)ro, sizeof(*ro));
66 dst = (struct sockaddr_ipx *)&ro->ro_dst;
67 if (ro->ro_rt == NULL) {
68 dst->sipx_family = AF_IPX;
69 dst->sipx_len = sizeof(*dst);
70 dst->sipx_addr = ipx->ipx_dna;
71 dst->sipx_addr.x_port = 0;
73 * If routing to interface only,
74 * short circuit routing lookup.
76 if (flags & IPX_ROUTETOIF) {
77 struct ipx_ifaddr *ia = ipx_iaonnetof(&ipx->ipx_dna);
80 ipxstat.ipxs_noroute++;
88 } else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
90 * The old route has gone away; try for a new one.
96 if (ro->ro_rt == NULL || (ifp = ro->ro_rt->rt_ifp) == NULL) {
97 ipxstat.ipxs_noroute++;
102 if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
103 dst = (struct sockaddr_ipx *)ro->ro_rt->rt_gateway;
106 * Look for multicast addresses and
107 * and verify user is allowed to send
110 if (dst->sipx_addr.x_host.c_host[0]&1) {
111 if ((ifp->if_flags & (IFF_BROADCAST | IFF_LOOPBACK)) == 0) {
112 error = EADDRNOTAVAIL;
115 if ((flags & IPX_ALLOWBROADCAST) == 0) {
119 m0->m_flags |= M_BCAST;
122 if (htons(ipx->ipx_len) <= ifp->if_mtu) {
123 ipxstat.ipxs_localout++;
124 if (ipx_copy_output) {
125 ipx_watch_output(m0, ifp);
127 error = ifp->if_output(ifp, m0, (struct sockaddr *)dst,
131 ipxstat.ipxs_mtutoosmall++;
135 if (ipx_copy_output) {
136 ipx_watch_output(m0, ifp);
140 if (ro == &ipxroute && (flags & IPX_ROUTETOIF) == 0 &&
149 * This will broadcast the type 20 (Netbios) packet to all the interfaces
150 * that have ipx configured and isn't in the list yet.
153 ipx_output_type20(struct mbuf *m)
156 union ipx_net *nbnet;
157 struct ipx_ifaddr *ia, *tia = NULL;
162 struct sockaddr_ipx dst;
165 * We have to get to the 32 bytes after the ipx header also, so
166 * that we can fill in the network address of the receiving
169 if ((m->m_flags & M_EXT || m->m_len < (sizeof(struct ipx) + 32)) &&
170 (m = m_pullup(m, sizeof(struct ipx) + 32)) == NULL) {
171 ipxstat.ipxs_toosmall++;
174 ipx = mtod(m, struct ipx *);
175 nbnet = (union ipx_net *)(ipx + 1);
177 if (ipx->ipx_tc >= 8)
180 * Now see if we have already seen this.
182 for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next)
183 if(ia->ia_ifa.ifa_ifp == m->m_pkthdr.rcvif) {
187 for (i=0;i<ipx->ipx_tc;i++,nbnet++)
188 if(ipx_neteqnn(ia->ia_addr.sipx_addr.x_net,
193 * Don't route the packet if the interface where it come from
194 * does not have an IPX address.
200 * Add our receiving interface to the list.
202 nbnet = (union ipx_net *)(ipx + 1);
203 nbnet += ipx->ipx_tc;
204 *nbnet = tia->ia_addr.sipx_addr.x_net;
207 * Increment the hop count.
210 ipxstat.ipxs_forward++;
213 * Send to all directly connected ifaces not in list and
214 * not to the one it came from.
216 m->m_flags &= ~M_BCAST;
217 bzero(&dst, sizeof(dst));
218 dst.sipx_family = AF_IPX;
220 dst.sipx_addr.x_host = ipx_broadhost;
222 for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next)
223 if(ia->ia_ifa.ifa_ifp != m->m_pkthdr.rcvif) {
224 nbnet = (union ipx_net *)(ipx + 1);
225 for (i=0;i<ipx->ipx_tc;i++,nbnet++)
226 if(ipx_neteqnn(ia->ia_addr.sipx_addr.x_net,
231 * Insert the net address of the dest net and
232 * calculate the new checksum if needed.
234 ifp = ia->ia_ifa.ifa_ifp;
235 dst.sipx_addr.x_net = ia->ia_addr.sipx_addr.x_net;
236 ipx->ipx_dna.x_net = dst.sipx_addr.x_net;
237 if(ipx->ipx_sum != 0xffff)
238 ipx->ipx_sum = ipx_cksum(m, ntohs(ipx->ipx_len));
240 m1 = m_copym(m, 0, M_COPYALL, MB_DONTWAIT);
242 error = ifp->if_output(ifp, m1,
243 (struct sockaddr *)&dst, NULL);
244 /* XXX ipxstat.ipxs_localout++; */