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>
78 ipx_outputfl(struct mbuf *m0, struct route *ro, int flags)
80 struct ipx *ipx = mtod(m0, struct ipx *);
81 struct ifnet *ifp = NULL;
83 struct sockaddr_ipx *dst;
84 struct route ipxroute;
91 bzero((caddr_t)ro, sizeof(*ro));
93 dst = (struct sockaddr_ipx *)&ro->ro_dst;
94 if (ro->ro_rt == NULL) {
95 dst->sipx_family = AF_IPX;
96 dst->sipx_len = sizeof(*dst);
97 dst->sipx_addr = ipx->ipx_dna;
98 dst->sipx_addr.x_port = 0;
100 * If routing to interface only,
101 * short circuit routing lookup.
103 if (flags & IPX_ROUTETOIF) {
104 struct ipx_ifaddr *ia;
107 ia = ipx_iaonnetof(&ipx->ipx_dna);
109 IPX_IFADDR_RUNLOCK();
110 ipxstat.ipxs_noroute++;
115 IPX_IFADDR_RUNLOCK();
119 } else if ((ro->ro_rt->rt_flags & RTF_UP) == 0) {
121 * The old route has gone away; try for a new one.
127 if (ro->ro_rt == NULL || (ifp = ro->ro_rt->rt_ifp) == NULL) {
128 ipxstat.ipxs_noroute++;
132 counter_u64_add(ro->ro_rt->rt_pksent, 1);
133 if (ro->ro_rt->rt_flags & (RTF_GATEWAY|RTF_HOST))
134 dst = (struct sockaddr_ipx *)ro->ro_rt->rt_gateway;
137 * Look for multicast addresses and
138 * and verify user is allowed to send
141 if (dst->sipx_addr.x_host.c_host[0]&1) {
142 if ((ifp->if_flags & (IFF_BROADCAST | IFF_LOOPBACK)) == 0) {
143 error = EADDRNOTAVAIL;
146 if ((flags & IPX_ALLOWBROADCAST) == 0) {
150 m0->m_flags |= M_BCAST;
153 if (htons(ipx->ipx_len) <= ifp->if_mtu) {
154 ipxstat.ipxs_localout++;
155 error = (*ifp->if_output)(ifp, m0,
156 (struct sockaddr *)dst, ro);
159 ipxstat.ipxs_mtutoosmall++;
165 if (ro == &ipxroute && (flags & IPX_ROUTETOIF) == 0 &&
174 * This will broadcast the type 20 (Netbios) packet to all the interfaces
175 * that have ipx configured and isn't in the list yet.
178 ipx_output_type20(struct mbuf *m)
181 union ipx_net *nbnet;
182 struct ipx_ifaddr *ia, *tia;
187 struct sockaddr_ipx dst;
190 * We have to get to the 32 bytes after the ipx header also, so
191 * that we can fill in the network address of the receiving
194 if ((m->m_flags & M_EXT || m->m_len < (sizeof(struct ipx) + 32)) &&
195 (m = m_pullup(m, sizeof(struct ipx) + 32)) == NULL) {
196 ipxstat.ipxs_toosmall++;
199 ipx = mtod(m, struct ipx *);
200 nbnet = (union ipx_net *)(ipx + 1);
202 if (ipx->ipx_tc >= 8)
205 * Now see if we have already seen this.
209 TAILQ_FOREACH(ia, &ipx_ifaddrhead, ia_link) {
210 if (ia->ia_ifa.ifa_ifp == m->m_pkthdr.rcvif) {
213 for (i=0; i < ipx->ipx_tc; i++, nbnet++) {
214 if (ipx_neteqnn(ia->ia_addr.sipx_addr.x_net,
216 IPX_IFADDR_RUNLOCK();
224 * Don't route the packet if the interface where it come from
225 * does not have an IPX address.
228 IPX_IFADDR_RUNLOCK();
233 * Add our receiving interface to the list.
235 nbnet = (union ipx_net *)(ipx + 1);
236 nbnet += ipx->ipx_tc;
237 *nbnet = tia->ia_addr.sipx_addr.x_net;
240 * Increment the hop count.
243 ipxstat.ipxs_forward++;
246 * Send to all directly connected ifaces not in list and
247 * not to the one it came from.
249 m->m_flags &= ~M_BCAST;
250 bzero(&dst, sizeof(dst));
251 dst.sipx_family = AF_IPX;
253 dst.sipx_addr.x_host = ipx_broadhost;
255 TAILQ_FOREACH(ia, &ipx_ifaddrhead, ia_link) {
256 if (ia->ia_ifa.ifa_ifp != m->m_pkthdr.rcvif) {
257 nbnet = (union ipx_net *)(ipx + 1);
258 for (i=0; i < ipx->ipx_tc; i++, nbnet++)
259 if (ipx_neteqnn(ia->ia_addr.sipx_addr.x_net,
264 * Insert the net address of the dest net and
265 * calculate the new checksum if needed.
267 ifp = ia->ia_ifa.ifa_ifp;
268 dst.sipx_addr.x_net = ia->ia_addr.sipx_addr.x_net;
269 ipx->ipx_dna.x_net = dst.sipx_addr.x_net;
270 if(ipx->ipx_sum != 0xffff)
271 ipx->ipx_sum = ipx_cksum(m, ntohs(ipx->ipx_len));
273 m1 = m_copym(m, 0, M_COPYALL, M_NOWAIT);
275 error = (*ifp->if_output)(ifp, m1,
276 (struct sockaddr *)&dst, NULL);
277 /* XXX ipxstat.ipxs_localout++; */
282 IPX_IFADDR_RUNLOCK();