1/* 2 * Copyright (c) 1995, 1996 3 * Matt Thomas <matt@3am-software.com>. All rights reserved. 4 * Copyright (c) 1982, 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp
| 1/* 2 * Copyright (c) 1995, 1996 3 * Matt Thomas <matt@3am-software.com>. All rights reserved. 4 * Copyright (c) 1982, 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp
|
37 */ 38 39#include "opt_atalk.h" 40#include "opt_inet.h" 41#include "opt_inet6.h" 42#include "opt_ipx.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/kernel.h> 47#include <sys/malloc.h> 48#include <sys/mbuf.h> 49#include <sys/module.h> 50#include <sys/socket.h> 51#include <sys/sockio.h> 52 53#include <net/if.h> 54#include <net/if_llc.h> 55#include <net/if_dl.h> 56#include <net/if_types.h> 57#include <net/netisr.h> 58#include <net/route.h> 59#include <net/bpf.h> 60#include <net/fddi.h> 61 62#if defined(INET) || defined(INET6) 63#include <netinet/in.h> 64#include <netinet/in_var.h> 65#include <netinet/if_ether.h> 66#endif 67#ifdef INET6 68#include <netinet6/nd6.h> 69#endif 70 71#ifdef IPX 72#include <netipx/ipx.h> 73#include <netipx/ipx_if.h> 74#endif 75 76#ifdef NS 77#include <netns/ns.h> 78#include <netns/ns_if.h> 79#endif 80 81#ifdef DECNET 82#include <netdnet/dn.h> 83#endif 84 85#ifdef NETATALK 86#include <netatalk/at.h> 87#include <netatalk/at_var.h> 88#include <netatalk/at_extern.h> 89 90extern u_char at_org_code[ 3 ]; 91extern u_char aarp_org_code[ 3 ]; 92#endif /* NETATALK */ 93 94static int fddi_resolvemulti(struct ifnet *, struct sockaddr **, 95 struct sockaddr *); 96 97#define IFP2AC(IFP) ((struct arpcom *)IFP) 98#define senderr(e) { error = (e); goto bad; } 99 100/* 101 * FDDI output routine. 102 * Encapsulate a packet of type family for the local net. 103 * Use trailer local net encapsulation if enough data in first 104 * packet leaves a multiple of 512 bytes of data in remainder. 105 * Assumes that ifp is actually pointer to arpcom structure. 106 */ 107int 108fddi_output(ifp, m, dst, rt0) 109 struct ifnet *ifp; 110 struct mbuf *m; 111 struct sockaddr *dst; 112 struct rtentry *rt0; 113{ 114 u_int16_t type; 115 int loop_copy = 0, error = 0, hdrcmplt = 0; 116 u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN]; 117 struct rtentry *rt; 118 struct fddi_header *fh; 119 struct arpcom *ac = IFP2AC(ifp); 120 121 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 122 senderr(ENETDOWN); 123 getmicrotime(&ifp->if_lastchange); 124 if ((rt = rt0) != NULL) { 125 if ((rt->rt_flags & RTF_UP) == 0) { 126 if ((rt0 = rt = rtalloc1(dst, 1, 0UL)) != NULL) 127 rt->rt_refcnt--; 128 else 129 senderr(EHOSTUNREACH); 130 } 131 if (rt->rt_flags & RTF_GATEWAY) { 132 if (rt->rt_gwroute == 0) 133 goto lookup; 134 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 135 rtfree(rt); rt = rt0; 136 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL); 137 if ((rt = rt->rt_gwroute) == 0) 138 senderr(EHOSTUNREACH); 139 } 140 } 141 if (rt->rt_flags & RTF_REJECT) 142 if (rt->rt_rmx.rmx_expire == 0 || 143 time_second < rt->rt_rmx.rmx_expire) 144 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 145 } 146 switch (dst->sa_family) { 147 148#ifdef INET 149 case AF_INET: { 150 if (!arpresolve(ifp, rt, m, dst, edst, rt0)) 151 return (0); /* if not yet resolved */ 152 type = htons(ETHERTYPE_IP); 153 break; 154 } 155#endif 156#ifdef INET6 157 case AF_INET6: 158 if (!nd6_storelladdr(ifp, rt, m, dst, (u_char *)edst)) { 159 /* Something bad happened */ 160 return (0); 161 } 162 type = htons(ETHERTYPE_IPV6); 163 break; 164#endif 165#ifdef IPX 166 case AF_IPX: 167 type = htons(ETHERTYPE_IPX); 168 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 169 (caddr_t)edst, FDDI_ADDR_LEN); 170 break; 171#endif 172#ifdef NETATALK 173 case AF_APPLETALK: { 174 struct at_ifaddr *aa; 175 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) 176 return (0); 177 /* 178 * ifaddr is the first thing in at_ifaddr 179 */ 180 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0) 181 goto bad; 182 183 /* 184 * In the phase 2 case, we need to prepend an mbuf for the llc header. 185 * Since we must preserve the value of m, which is passed to us by 186 * value, we m_copy() the first mbuf, and use it for our llc header. 187 */ 188 if (aa->aa_flags & AFA_PHASE2) { 189 struct llc llc; 190 191 M_PREPEND(m, LLC_SNAPFRAMELEN, M_TRYWAIT); 192 if (m == 0) 193 senderr(ENOBUFS); 194 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 195 llc.llc_control = LLC_UI; 196 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code)); 197 llc.llc_snap.ether_type = htons(ETHERTYPE_AT); 198 bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN); 199 type = 0; 200 } else { 201 type = htons(ETHERTYPE_AT); 202 } 203 break; 204 } 205#endif /* NETATALK */ 206#ifdef NS 207 case AF_NS: 208 type = htons(ETHERTYPE_NS); 209 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 210 (caddr_t)edst, FDDI_ADDR_LEN); 211 break; 212#endif 213 214 case pseudo_AF_HDRCMPLT: 215 {
| 37 */ 38 39#include "opt_atalk.h" 40#include "opt_inet.h" 41#include "opt_inet6.h" 42#include "opt_ipx.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/kernel.h> 47#include <sys/malloc.h> 48#include <sys/mbuf.h> 49#include <sys/module.h> 50#include <sys/socket.h> 51#include <sys/sockio.h> 52 53#include <net/if.h> 54#include <net/if_llc.h> 55#include <net/if_dl.h> 56#include <net/if_types.h> 57#include <net/netisr.h> 58#include <net/route.h> 59#include <net/bpf.h> 60#include <net/fddi.h> 61 62#if defined(INET) || defined(INET6) 63#include <netinet/in.h> 64#include <netinet/in_var.h> 65#include <netinet/if_ether.h> 66#endif 67#ifdef INET6 68#include <netinet6/nd6.h> 69#endif 70 71#ifdef IPX 72#include <netipx/ipx.h> 73#include <netipx/ipx_if.h> 74#endif 75 76#ifdef NS 77#include <netns/ns.h> 78#include <netns/ns_if.h> 79#endif 80 81#ifdef DECNET 82#include <netdnet/dn.h> 83#endif 84 85#ifdef NETATALK 86#include <netatalk/at.h> 87#include <netatalk/at_var.h> 88#include <netatalk/at_extern.h> 89 90extern u_char at_org_code[ 3 ]; 91extern u_char aarp_org_code[ 3 ]; 92#endif /* NETATALK */ 93 94static int fddi_resolvemulti(struct ifnet *, struct sockaddr **, 95 struct sockaddr *); 96 97#define IFP2AC(IFP) ((struct arpcom *)IFP) 98#define senderr(e) { error = (e); goto bad; } 99 100/* 101 * FDDI output routine. 102 * Encapsulate a packet of type family for the local net. 103 * Use trailer local net encapsulation if enough data in first 104 * packet leaves a multiple of 512 bytes of data in remainder. 105 * Assumes that ifp is actually pointer to arpcom structure. 106 */ 107int 108fddi_output(ifp, m, dst, rt0) 109 struct ifnet *ifp; 110 struct mbuf *m; 111 struct sockaddr *dst; 112 struct rtentry *rt0; 113{ 114 u_int16_t type; 115 int loop_copy = 0, error = 0, hdrcmplt = 0; 116 u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN]; 117 struct rtentry *rt; 118 struct fddi_header *fh; 119 struct arpcom *ac = IFP2AC(ifp); 120 121 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 122 senderr(ENETDOWN); 123 getmicrotime(&ifp->if_lastchange); 124 if ((rt = rt0) != NULL) { 125 if ((rt->rt_flags & RTF_UP) == 0) { 126 if ((rt0 = rt = rtalloc1(dst, 1, 0UL)) != NULL) 127 rt->rt_refcnt--; 128 else 129 senderr(EHOSTUNREACH); 130 } 131 if (rt->rt_flags & RTF_GATEWAY) { 132 if (rt->rt_gwroute == 0) 133 goto lookup; 134 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 135 rtfree(rt); rt = rt0; 136 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL); 137 if ((rt = rt->rt_gwroute) == 0) 138 senderr(EHOSTUNREACH); 139 } 140 } 141 if (rt->rt_flags & RTF_REJECT) 142 if (rt->rt_rmx.rmx_expire == 0 || 143 time_second < rt->rt_rmx.rmx_expire) 144 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 145 } 146 switch (dst->sa_family) { 147 148#ifdef INET 149 case AF_INET: { 150 if (!arpresolve(ifp, rt, m, dst, edst, rt0)) 151 return (0); /* if not yet resolved */ 152 type = htons(ETHERTYPE_IP); 153 break; 154 } 155#endif 156#ifdef INET6 157 case AF_INET6: 158 if (!nd6_storelladdr(ifp, rt, m, dst, (u_char *)edst)) { 159 /* Something bad happened */ 160 return (0); 161 } 162 type = htons(ETHERTYPE_IPV6); 163 break; 164#endif 165#ifdef IPX 166 case AF_IPX: 167 type = htons(ETHERTYPE_IPX); 168 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 169 (caddr_t)edst, FDDI_ADDR_LEN); 170 break; 171#endif 172#ifdef NETATALK 173 case AF_APPLETALK: { 174 struct at_ifaddr *aa; 175 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) 176 return (0); 177 /* 178 * ifaddr is the first thing in at_ifaddr 179 */ 180 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0) 181 goto bad; 182 183 /* 184 * In the phase 2 case, we need to prepend an mbuf for the llc header. 185 * Since we must preserve the value of m, which is passed to us by 186 * value, we m_copy() the first mbuf, and use it for our llc header. 187 */ 188 if (aa->aa_flags & AFA_PHASE2) { 189 struct llc llc; 190 191 M_PREPEND(m, LLC_SNAPFRAMELEN, M_TRYWAIT); 192 if (m == 0) 193 senderr(ENOBUFS); 194 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 195 llc.llc_control = LLC_UI; 196 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code)); 197 llc.llc_snap.ether_type = htons(ETHERTYPE_AT); 198 bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN); 199 type = 0; 200 } else { 201 type = htons(ETHERTYPE_AT); 202 } 203 break; 204 } 205#endif /* NETATALK */ 206#ifdef NS 207 case AF_NS: 208 type = htons(ETHERTYPE_NS); 209 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 210 (caddr_t)edst, FDDI_ADDR_LEN); 211 break; 212#endif 213 214 case pseudo_AF_HDRCMPLT: 215 {
|
220 /* FALLTHROUGH */ 221 } 222 223 case AF_UNSPEC: 224 { 225 struct ether_header *eh; 226 loop_copy = -1; 227 eh = (struct ether_header *)dst->sa_data; 228 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, FDDI_ADDR_LEN); 229 if (*edst & 1) 230 m->m_flags |= (M_BCAST|M_MCAST); 231 type = eh->ether_type; 232 break; 233 } 234 235 case AF_IMPLINK: 236 { 237 fh = mtod(m, struct fddi_header *); 238 error = EPROTONOSUPPORT; 239 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) { 240 case FDDIFC_LLC_ASYNC: { 241 /* legal priorities are 0 through 7 */ 242 if ((fh->fddi_fc & FDDIFC_Z) > 7) 243 goto bad; 244 break; 245 } 246 case FDDIFC_LLC_SYNC: { 247 /* FDDIFC_Z bits reserved, must be zero */ 248 if (fh->fddi_fc & FDDIFC_Z) 249 goto bad; 250 break; 251 } 252 case FDDIFC_SMT: { 253 /* FDDIFC_Z bits must be non zero */ 254 if ((fh->fddi_fc & FDDIFC_Z) == 0) 255 goto bad; 256 break; 257 } 258 default: { 259 /* anything else is too dangerous */ 260 goto bad; 261 } 262 } 263 error = 0; 264 if (fh->fddi_dhost[0] & 1) 265 m->m_flags |= (M_BCAST|M_MCAST); 266 goto queue_it; 267 } 268 default: 269 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 270 dst->sa_family); 271 senderr(EAFNOSUPPORT); 272 } 273 274 if (type != 0) { 275 struct llc *l; 276 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT); 277 if (m == 0) 278 senderr(ENOBUFS); 279 l = mtod(m, struct llc *); 280 l->llc_control = LLC_UI; 281 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; 282 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0; 283 bcopy((caddr_t)&type, (caddr_t)&l->llc_snap.ether_type, 284 sizeof(u_int16_t)); 285 } 286 287 /* 288 * Add local net header. If no space in first mbuf, 289 * allocate another. 290 */ 291 M_PREPEND(m, FDDI_HDR_LEN, M_DONTWAIT); 292 if (m == 0) 293 senderr(ENOBUFS); 294 fh = mtod(m, struct fddi_header *); 295 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4; 296 bcopy((caddr_t)edst, (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN); 297 queue_it: 298 if (hdrcmplt) 299 bcopy((caddr_t)esrc, (caddr_t)fh->fddi_shost, FDDI_ADDR_LEN); 300 else 301 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)fh->fddi_shost, 302 FDDI_ADDR_LEN); 303 /* 304 * If a simplex interface, and the packet is being sent to our 305 * Ethernet address or a broadcast address, loopback a copy. 306 * XXX To make a simplex device behave exactly like a duplex 307 * device, we should copy in the case of sending to our own 308 * ethernet address (thus letting the original actually appear 309 * on the wire). However, we don't do that here for security 310 * reasons and compatibility with the original behavior. 311 */ 312 if ((ifp->if_flags & IFF_SIMPLEX) && 313 (loop_copy != -1)) { 314 if ((m->m_flags & M_BCAST) || loop_copy) { 315 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); 316 317 (void) if_simloop(ifp, 318 n, dst->sa_family, FDDI_HDR_LEN); 319 } else if (bcmp(fh->fddi_dhost, 320 fh->fddi_shost, FDDI_ADDR_LEN) == 0) { 321 (void) if_simloop(ifp, 322 m, dst->sa_family, FDDI_HDR_LEN); 323 return (0); /* XXX */ 324 } 325 } 326 327 if (! IF_HANDOFF(&ifp->if_snd, m, ifp)) 328 senderr(ENOBUFS); 329 return (error); 330 331bad: 332 if (m) 333 m_freem(m); 334 return (error); 335} 336 337/* 338 * Process a received FDDI packet; 339 * the packet is in the mbuf chain m without 340 * the fddi header, which is provided separately. 341 */ 342void 343fddi_input(ifp, fh, m) 344 struct ifnet *ifp; 345 struct fddi_header *fh; 346 struct mbuf *m; 347{ 348 struct ifqueue *inq; 349 struct llc *l; 350 351 if ((ifp->if_flags & IFF_UP) == 0) { 352 m_freem(m); 353 return; 354 } 355 getmicrotime(&ifp->if_lastchange); 356 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh); 357 if (fh->fddi_dhost[0] & 1) { 358 if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost, 359 FDDI_ADDR_LEN) == 0) 360 m->m_flags |= M_BCAST; 361 else 362 m->m_flags |= M_MCAST; 363 ifp->if_imcasts++; 364 } else if ((ifp->if_flags & IFF_PROMISC) 365 && bcmp(IFP2AC(ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost, 366 FDDI_ADDR_LEN) != 0) { 367 m_freem(m); 368 return; 369 } 370 371#ifdef M_LINK0 372 /* 373 * If this has a LLC priority of 0, then mark it so upper 374 * layers have a hint that it really came via a FDDI/Ethernet 375 * bridge. 376 */ 377 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0) 378 m->m_flags |= M_LINK0; 379#endif 380 381 l = mtod(m, struct llc *); 382 switch (l->llc_dsap) { 383#if defined(INET) || defined(INET6) || defined(NS) || defined(DECNET) || defined(IPX) || defined(NETATALK) 384 case LLC_SNAP_LSAP: 385 { 386 u_int16_t type; 387 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP) 388 goto dropanyway; 389#ifdef NETATALK 390 if (Bcmp(&(l->llc_snap.org_code)[0], at_org_code, 391 sizeof(at_org_code)) == 0 && 392 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) { 393 inq = &atintrq2; 394 m_adj(m, LLC_SNAPFRAMELEN); 395 schednetisr(NETISR_ATALK); 396 break; 397 } 398 399 if (Bcmp(&(l->llc_snap.org_code)[0], aarp_org_code, 400 sizeof(aarp_org_code)) == 0 && 401 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) { 402 m_adj(m, LLC_SNAPFRAMELEN); 403 aarpinput(IFP2AC(ifp), m); /* XXX */ 404 return; 405 } 406#endif /* NETATALK */ 407 if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0) 408 goto dropanyway; 409 type = ntohs(l->llc_snap.ether_type); 410 m_adj(m, 8); 411 switch (type) { 412#ifdef INET 413 case ETHERTYPE_IP: 414 if (ipflow_fastforward(m)) 415 return; 416 schednetisr(NETISR_IP); 417 inq = &ipintrq; 418 break; 419 420 case ETHERTYPE_ARP: 421 if (ifp->if_flags & IFF_NOARP) 422 goto dropanyway; 423 schednetisr(NETISR_ARP); 424 inq = &arpintrq; 425 break; 426#endif 427#ifdef INET6 428 case ETHERTYPE_IPV6: 429 schednetisr(NETISR_IPV6); 430 inq = &ip6intrq; 431 break; 432#endif 433#ifdef IPX 434 case ETHERTYPE_IPX: 435 schednetisr(NETISR_IPX); 436 inq = &ipxintrq; 437 break; 438#endif 439#ifdef NS 440 case ETHERTYPE_NS: 441 schednetisr(NETISR_NS); 442 inq = &nsintrq; 443 break; 444#endif 445#ifdef DECNET 446 case ETHERTYPE_DECNET: 447 schednetisr(NETISR_DECNET); 448 inq = &decnetintrq; 449 break; 450#endif 451#ifdef NETATALK 452 case ETHERTYPE_AT: 453 schednetisr(NETISR_ATALK); 454 inq = &atintrq1; 455 break; 456 case ETHERTYPE_AARP: 457 /* probably this should be done with a NETISR as well */ 458 aarpinput(IFP2AC(ifp), m); /* XXX */ 459 return; 460#endif /* NETATALK */ 461 default: 462 /* printf("fddi_input: unknown protocol 0x%x\n", type); */ 463 ifp->if_noproto++; 464 goto dropanyway; 465 } 466 break; 467 } 468#endif /* INET || NS */ 469 470 default: 471 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */ 472 ifp->if_noproto++; 473 dropanyway: 474 m_freem(m); 475 return; 476 } 477 478 (void) IF_HANDOFF(inq, m, NULL); 479} 480/* 481 * Perform common duties while attaching to interface list 482 */ 483 484void 485fddi_ifattach(ifp) 486 struct ifnet *ifp; 487{ 488 struct ifaddr *ifa; 489 struct sockaddr_dl *sdl; 490 491 ifp->if_type = IFT_FDDI; 492 ifp->if_addrlen = FDDI_ADDR_LEN; 493 ifp->if_hdrlen = 21; 494 ifp->if_mtu = FDDIMTU; 495 ifp->if_resolvemulti = fddi_resolvemulti; 496 ifp->if_baudrate = 100000000; 497#ifdef IFF_NOTRAILERS 498 ifp->if_flags |= IFF_NOTRAILERS; 499#endif 500 ifp->if_broadcastaddr = fddibroadcastaddr; 501 ifa = ifaddr_byindex(ifp->if_index); 502 sdl = (struct sockaddr_dl *)ifa->ifa_addr; 503 sdl->sdl_type = IFT_FDDI; 504 sdl->sdl_alen = ifp->if_addrlen; 505 bcopy(IFP2AC(ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen); 506} 507 508static int 509fddi_resolvemulti(ifp, llsa, sa) 510 struct ifnet *ifp; 511 struct sockaddr **llsa; 512 struct sockaddr *sa; 513{ 514 struct sockaddr_dl *sdl; 515 struct sockaddr_in *sin; 516#ifdef INET6 517 struct sockaddr_in6 *sin6; 518#endif 519 u_char *e_addr; 520 521 switch(sa->sa_family) { 522 case AF_LINK: 523 /* 524 * No mapping needed. Just check that it's a valid MC address. 525 */ 526 sdl = (struct sockaddr_dl *)sa; 527 e_addr = LLADDR(sdl); 528 if ((e_addr[0] & 1) != 1) 529 return (EADDRNOTAVAIL); 530 *llsa = 0; 531 return (0); 532 533#ifdef INET 534 case AF_INET: 535 sin = (struct sockaddr_in *)sa; 536 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) 537 return (EADDRNOTAVAIL); 538 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 539 M_WAITOK); 540 sdl->sdl_len = sizeof *sdl; 541 sdl->sdl_family = AF_LINK; 542 sdl->sdl_index = ifp->if_index; 543 sdl->sdl_type = IFT_FDDI; 544 sdl->sdl_nlen = 0; 545 sdl->sdl_alen = FDDI_ADDR_LEN; 546 sdl->sdl_slen = 0; 547 e_addr = LLADDR(sdl); 548 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr); 549 *llsa = (struct sockaddr *)sdl; 550 return (0); 551#endif 552#ifdef INET6 553 case AF_INET6: 554 sin6 = (struct sockaddr_in6 *)sa; 555 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 556 /* 557 * An IP6 address of 0 means listen to all 558 * of the Ethernet multicast address used for IP6. 559 * (This is used for multicast routers.) 560 */ 561 ifp->if_flags |= IFF_ALLMULTI; 562 *llsa = 0; 563 return (0); 564 } 565 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) 566 return (EADDRNOTAVAIL); 567 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 568 M_WAITOK); 569 sdl->sdl_len = sizeof *sdl; 570 sdl->sdl_family = AF_LINK; 571 sdl->sdl_index = ifp->if_index; 572 sdl->sdl_type = IFT_FDDI; 573 sdl->sdl_nlen = 0; 574 sdl->sdl_alen = FDDI_ADDR_LEN; 575 sdl->sdl_slen = 0; 576 e_addr = LLADDR(sdl); 577 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr); 578 *llsa = (struct sockaddr *)sdl; 579 return (0); 580#endif 581 582 default: 583 /* 584 * Well, the text isn't quite right, but it's the name 585 * that counts... 586 */ 587 return (EAFNOSUPPORT); 588 } 589 590 return (0); 591} 592 593static moduledata_t fddi_mod = { 594 "fddi", /* module name */ 595 NULL, /* event handler */ 596 0 /* extra data */ 597}; 598 599DECLARE_MODULE(fddi, fddi_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 600MODULE_VERSION(fddi, 1);
| 220 /* FALLTHROUGH */ 221 } 222 223 case AF_UNSPEC: 224 { 225 struct ether_header *eh; 226 loop_copy = -1; 227 eh = (struct ether_header *)dst->sa_data; 228 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, FDDI_ADDR_LEN); 229 if (*edst & 1) 230 m->m_flags |= (M_BCAST|M_MCAST); 231 type = eh->ether_type; 232 break; 233 } 234 235 case AF_IMPLINK: 236 { 237 fh = mtod(m, struct fddi_header *); 238 error = EPROTONOSUPPORT; 239 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) { 240 case FDDIFC_LLC_ASYNC: { 241 /* legal priorities are 0 through 7 */ 242 if ((fh->fddi_fc & FDDIFC_Z) > 7) 243 goto bad; 244 break; 245 } 246 case FDDIFC_LLC_SYNC: { 247 /* FDDIFC_Z bits reserved, must be zero */ 248 if (fh->fddi_fc & FDDIFC_Z) 249 goto bad; 250 break; 251 } 252 case FDDIFC_SMT: { 253 /* FDDIFC_Z bits must be non zero */ 254 if ((fh->fddi_fc & FDDIFC_Z) == 0) 255 goto bad; 256 break; 257 } 258 default: { 259 /* anything else is too dangerous */ 260 goto bad; 261 } 262 } 263 error = 0; 264 if (fh->fddi_dhost[0] & 1) 265 m->m_flags |= (M_BCAST|M_MCAST); 266 goto queue_it; 267 } 268 default: 269 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 270 dst->sa_family); 271 senderr(EAFNOSUPPORT); 272 } 273 274 if (type != 0) { 275 struct llc *l; 276 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT); 277 if (m == 0) 278 senderr(ENOBUFS); 279 l = mtod(m, struct llc *); 280 l->llc_control = LLC_UI; 281 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; 282 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0; 283 bcopy((caddr_t)&type, (caddr_t)&l->llc_snap.ether_type, 284 sizeof(u_int16_t)); 285 } 286 287 /* 288 * Add local net header. If no space in first mbuf, 289 * allocate another. 290 */ 291 M_PREPEND(m, FDDI_HDR_LEN, M_DONTWAIT); 292 if (m == 0) 293 senderr(ENOBUFS); 294 fh = mtod(m, struct fddi_header *); 295 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4; 296 bcopy((caddr_t)edst, (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN); 297 queue_it: 298 if (hdrcmplt) 299 bcopy((caddr_t)esrc, (caddr_t)fh->fddi_shost, FDDI_ADDR_LEN); 300 else 301 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)fh->fddi_shost, 302 FDDI_ADDR_LEN); 303 /* 304 * If a simplex interface, and the packet is being sent to our 305 * Ethernet address or a broadcast address, loopback a copy. 306 * XXX To make a simplex device behave exactly like a duplex 307 * device, we should copy in the case of sending to our own 308 * ethernet address (thus letting the original actually appear 309 * on the wire). However, we don't do that here for security 310 * reasons and compatibility with the original behavior. 311 */ 312 if ((ifp->if_flags & IFF_SIMPLEX) && 313 (loop_copy != -1)) { 314 if ((m->m_flags & M_BCAST) || loop_copy) { 315 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); 316 317 (void) if_simloop(ifp, 318 n, dst->sa_family, FDDI_HDR_LEN); 319 } else if (bcmp(fh->fddi_dhost, 320 fh->fddi_shost, FDDI_ADDR_LEN) == 0) { 321 (void) if_simloop(ifp, 322 m, dst->sa_family, FDDI_HDR_LEN); 323 return (0); /* XXX */ 324 } 325 } 326 327 if (! IF_HANDOFF(&ifp->if_snd, m, ifp)) 328 senderr(ENOBUFS); 329 return (error); 330 331bad: 332 if (m) 333 m_freem(m); 334 return (error); 335} 336 337/* 338 * Process a received FDDI packet; 339 * the packet is in the mbuf chain m without 340 * the fddi header, which is provided separately. 341 */ 342void 343fddi_input(ifp, fh, m) 344 struct ifnet *ifp; 345 struct fddi_header *fh; 346 struct mbuf *m; 347{ 348 struct ifqueue *inq; 349 struct llc *l; 350 351 if ((ifp->if_flags & IFF_UP) == 0) { 352 m_freem(m); 353 return; 354 } 355 getmicrotime(&ifp->if_lastchange); 356 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh); 357 if (fh->fddi_dhost[0] & 1) { 358 if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost, 359 FDDI_ADDR_LEN) == 0) 360 m->m_flags |= M_BCAST; 361 else 362 m->m_flags |= M_MCAST; 363 ifp->if_imcasts++; 364 } else if ((ifp->if_flags & IFF_PROMISC) 365 && bcmp(IFP2AC(ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost, 366 FDDI_ADDR_LEN) != 0) { 367 m_freem(m); 368 return; 369 } 370 371#ifdef M_LINK0 372 /* 373 * If this has a LLC priority of 0, then mark it so upper 374 * layers have a hint that it really came via a FDDI/Ethernet 375 * bridge. 376 */ 377 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0) 378 m->m_flags |= M_LINK0; 379#endif 380 381 l = mtod(m, struct llc *); 382 switch (l->llc_dsap) { 383#if defined(INET) || defined(INET6) || defined(NS) || defined(DECNET) || defined(IPX) || defined(NETATALK) 384 case LLC_SNAP_LSAP: 385 { 386 u_int16_t type; 387 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP) 388 goto dropanyway; 389#ifdef NETATALK 390 if (Bcmp(&(l->llc_snap.org_code)[0], at_org_code, 391 sizeof(at_org_code)) == 0 && 392 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) { 393 inq = &atintrq2; 394 m_adj(m, LLC_SNAPFRAMELEN); 395 schednetisr(NETISR_ATALK); 396 break; 397 } 398 399 if (Bcmp(&(l->llc_snap.org_code)[0], aarp_org_code, 400 sizeof(aarp_org_code)) == 0 && 401 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) { 402 m_adj(m, LLC_SNAPFRAMELEN); 403 aarpinput(IFP2AC(ifp), m); /* XXX */ 404 return; 405 } 406#endif /* NETATALK */ 407 if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0) 408 goto dropanyway; 409 type = ntohs(l->llc_snap.ether_type); 410 m_adj(m, 8); 411 switch (type) { 412#ifdef INET 413 case ETHERTYPE_IP: 414 if (ipflow_fastforward(m)) 415 return; 416 schednetisr(NETISR_IP); 417 inq = &ipintrq; 418 break; 419 420 case ETHERTYPE_ARP: 421 if (ifp->if_flags & IFF_NOARP) 422 goto dropanyway; 423 schednetisr(NETISR_ARP); 424 inq = &arpintrq; 425 break; 426#endif 427#ifdef INET6 428 case ETHERTYPE_IPV6: 429 schednetisr(NETISR_IPV6); 430 inq = &ip6intrq; 431 break; 432#endif 433#ifdef IPX 434 case ETHERTYPE_IPX: 435 schednetisr(NETISR_IPX); 436 inq = &ipxintrq; 437 break; 438#endif 439#ifdef NS 440 case ETHERTYPE_NS: 441 schednetisr(NETISR_NS); 442 inq = &nsintrq; 443 break; 444#endif 445#ifdef DECNET 446 case ETHERTYPE_DECNET: 447 schednetisr(NETISR_DECNET); 448 inq = &decnetintrq; 449 break; 450#endif 451#ifdef NETATALK 452 case ETHERTYPE_AT: 453 schednetisr(NETISR_ATALK); 454 inq = &atintrq1; 455 break; 456 case ETHERTYPE_AARP: 457 /* probably this should be done with a NETISR as well */ 458 aarpinput(IFP2AC(ifp), m); /* XXX */ 459 return; 460#endif /* NETATALK */ 461 default: 462 /* printf("fddi_input: unknown protocol 0x%x\n", type); */ 463 ifp->if_noproto++; 464 goto dropanyway; 465 } 466 break; 467 } 468#endif /* INET || NS */ 469 470 default: 471 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */ 472 ifp->if_noproto++; 473 dropanyway: 474 m_freem(m); 475 return; 476 } 477 478 (void) IF_HANDOFF(inq, m, NULL); 479} 480/* 481 * Perform common duties while attaching to interface list 482 */ 483 484void 485fddi_ifattach(ifp) 486 struct ifnet *ifp; 487{ 488 struct ifaddr *ifa; 489 struct sockaddr_dl *sdl; 490 491 ifp->if_type = IFT_FDDI; 492 ifp->if_addrlen = FDDI_ADDR_LEN; 493 ifp->if_hdrlen = 21; 494 ifp->if_mtu = FDDIMTU; 495 ifp->if_resolvemulti = fddi_resolvemulti; 496 ifp->if_baudrate = 100000000; 497#ifdef IFF_NOTRAILERS 498 ifp->if_flags |= IFF_NOTRAILERS; 499#endif 500 ifp->if_broadcastaddr = fddibroadcastaddr; 501 ifa = ifaddr_byindex(ifp->if_index); 502 sdl = (struct sockaddr_dl *)ifa->ifa_addr; 503 sdl->sdl_type = IFT_FDDI; 504 sdl->sdl_alen = ifp->if_addrlen; 505 bcopy(IFP2AC(ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen); 506} 507 508static int 509fddi_resolvemulti(ifp, llsa, sa) 510 struct ifnet *ifp; 511 struct sockaddr **llsa; 512 struct sockaddr *sa; 513{ 514 struct sockaddr_dl *sdl; 515 struct sockaddr_in *sin; 516#ifdef INET6 517 struct sockaddr_in6 *sin6; 518#endif 519 u_char *e_addr; 520 521 switch(sa->sa_family) { 522 case AF_LINK: 523 /* 524 * No mapping needed. Just check that it's a valid MC address. 525 */ 526 sdl = (struct sockaddr_dl *)sa; 527 e_addr = LLADDR(sdl); 528 if ((e_addr[0] & 1) != 1) 529 return (EADDRNOTAVAIL); 530 *llsa = 0; 531 return (0); 532 533#ifdef INET 534 case AF_INET: 535 sin = (struct sockaddr_in *)sa; 536 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) 537 return (EADDRNOTAVAIL); 538 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 539 M_WAITOK); 540 sdl->sdl_len = sizeof *sdl; 541 sdl->sdl_family = AF_LINK; 542 sdl->sdl_index = ifp->if_index; 543 sdl->sdl_type = IFT_FDDI; 544 sdl->sdl_nlen = 0; 545 sdl->sdl_alen = FDDI_ADDR_LEN; 546 sdl->sdl_slen = 0; 547 e_addr = LLADDR(sdl); 548 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr); 549 *llsa = (struct sockaddr *)sdl; 550 return (0); 551#endif 552#ifdef INET6 553 case AF_INET6: 554 sin6 = (struct sockaddr_in6 *)sa; 555 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 556 /* 557 * An IP6 address of 0 means listen to all 558 * of the Ethernet multicast address used for IP6. 559 * (This is used for multicast routers.) 560 */ 561 ifp->if_flags |= IFF_ALLMULTI; 562 *llsa = 0; 563 return (0); 564 } 565 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) 566 return (EADDRNOTAVAIL); 567 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 568 M_WAITOK); 569 sdl->sdl_len = sizeof *sdl; 570 sdl->sdl_family = AF_LINK; 571 sdl->sdl_index = ifp->if_index; 572 sdl->sdl_type = IFT_FDDI; 573 sdl->sdl_nlen = 0; 574 sdl->sdl_alen = FDDI_ADDR_LEN; 575 sdl->sdl_slen = 0; 576 e_addr = LLADDR(sdl); 577 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr); 578 *llsa = (struct sockaddr *)sdl; 579 return (0); 580#endif 581 582 default: 583 /* 584 * Well, the text isn't quite right, but it's the name 585 * that counts... 586 */ 587 return (EAFNOSUPPORT); 588 } 589 590 return (0); 591} 592 593static moduledata_t fddi_mod = { 594 "fddi", /* module name */ 595 NULL, /* event handler */ 596 0 /* extra data */ 597}; 598 599DECLARE_MODULE(fddi, fddi_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 600MODULE_VERSION(fddi, 1);
|