2 * Copyright (c) 1984, 1985, 1986, 1987, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Copyright (c) 1995, Mike Mitchell
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 #include <sys/cdefs.h>
63 __FBSDID("$FreeBSD$");
65 #include <sys/param.h>
66 #include <sys/systm.h>
68 #include <sys/socket.h>
71 #include <net/route.h>
73 #include <netipx/ipx.h>
74 #include <netipx/ipx_if.h>
75 #include <netipx/ipx_var.h>
77 static int ipx_copy_output = 0;
80 ipx_outputfl(struct mbuf *m0, struct route *ro, int flags)
82 struct ipx *ipx = mtod(m0, struct ipx *);
83 struct ifnet *ifp = NULL;
85 struct sockaddr_ipx *dst;
86 struct route ipxroute;
93 bzero((caddr_t)ro, sizeof(*ro));
95 dst = (struct sockaddr_ipx *)&ro->ro_dst;
96 if (ro->ro_rt == NULL) {
97 dst->sipx_family = AF_IPX;
98 dst->sipx_len = sizeof(*dst);
99 dst->sipx_addr = ipx->ipx_dna;
100 dst->sipx_addr.x_port = 0;
102 * If routing to interface only,
103 * short circuit routing lookup.
105 if (flags & IPX_ROUTETOIF) {
106 struct ipx_ifaddr *ia = ipx_iaonnetof(&ipx->ipx_dna);
109 ipxstat.ipxs_noroute++;
117 } else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
119 * The old route has gone away; try for a new one.
125 if (ro->ro_rt == NULL || (ifp = ro->ro_rt->rt_ifp) == NULL) {
126 ipxstat.ipxs_noroute++;
131 if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
132 dst = (struct sockaddr_ipx *)ro->ro_rt->rt_gateway;
135 * Look for multicast addresses and
136 * and verify user is allowed to send
139 if (dst->sipx_addr.x_host.c_host[0]&1) {
140 if ((ifp->if_flags & (IFF_BROADCAST | IFF_LOOPBACK)) == 0) {
141 error = EADDRNOTAVAIL;
144 if ((flags & IPX_ALLOWBROADCAST) == 0) {
148 m0->m_flags |= M_BCAST;
151 if (htons(ipx->ipx_len) <= ifp->if_mtu) {
152 ipxstat.ipxs_localout++;
153 if (ipx_copy_output) {
154 ipx_watch_output(m0, ifp);
156 error = (*ifp->if_output)(ifp, m0,
157 (struct sockaddr *)dst, ro->ro_rt);
160 ipxstat.ipxs_mtutoosmall++;
164 if (ipx_copy_output) {
165 ipx_watch_output(m0, ifp);
169 if (ro == &ipxroute && (flags & IPX_ROUTETOIF) == 0 &&
178 * This will broadcast the type 20 (Netbios) packet to all the interfaces
179 * that have ipx configured and isn't in the list yet.
182 ipx_output_type20(struct mbuf *m)
185 union ipx_net *nbnet;
186 struct ipx_ifaddr *ia, *tia = NULL;
191 struct sockaddr_ipx dst;
194 * We have to get to the 32 bytes after the ipx header also, so
195 * that we can fill in the network address of the receiving
198 if ((m->m_flags & M_EXT || m->m_len < (sizeof(struct ipx) + 32)) &&
199 (m = m_pullup(m, sizeof(struct ipx) + 32)) == NULL) {
200 ipxstat.ipxs_toosmall++;
203 ipx = mtod(m, struct ipx *);
204 nbnet = (union ipx_net *)(ipx + 1);
206 if (ipx->ipx_tc >= 8)
209 * Now see if we have already seen this.
211 for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next)
212 if(ia->ia_ifa.ifa_ifp == m->m_pkthdr.rcvif) {
216 for (i=0;i<ipx->ipx_tc;i++,nbnet++)
217 if(ipx_neteqnn(ia->ia_addr.sipx_addr.x_net,
222 * Don't route the packet if the interface where it come from
223 * does not have an IPX address.
229 * Add our receiving interface to the list.
231 nbnet = (union ipx_net *)(ipx + 1);
232 nbnet += ipx->ipx_tc;
233 *nbnet = tia->ia_addr.sipx_addr.x_net;
236 * Increment the hop count.
239 ipxstat.ipxs_forward++;
242 * Send to all directly connected ifaces not in list and
243 * not to the one it came from.
245 m->m_flags &= ~M_BCAST;
246 bzero(&dst, sizeof(dst));
247 dst.sipx_family = AF_IPX;
249 dst.sipx_addr.x_host = ipx_broadhost;
251 for (ia = ipx_ifaddr; ia != NULL; ia = ia->ia_next)
252 if(ia->ia_ifa.ifa_ifp != m->m_pkthdr.rcvif) {
253 nbnet = (union ipx_net *)(ipx + 1);
254 for (i=0;i<ipx->ipx_tc;i++,nbnet++)
255 if(ipx_neteqnn(ia->ia_addr.sipx_addr.x_net,
260 * Insert the net address of the dest net and
261 * calculate the new checksum if needed.
263 ifp = ia->ia_ifa.ifa_ifp;
264 dst.sipx_addr.x_net = ia->ia_addr.sipx_addr.x_net;
265 ipx->ipx_dna.x_net = dst.sipx_addr.x_net;
266 if(ipx->ipx_sum != 0xffff)
267 ipx->ipx_sum = ipx_cksum(m, ntohs(ipx->ipx_len));
269 m1 = m_copym(m, 0, M_COPYALL, M_DONTWAIT);
271 error = (*ifp->if_output)(ifp, m1,
272 (struct sockaddr *)&dst, NULL);
273 /* XXX ipxstat.ipxs_localout++; */