| 1 | /* $NetBSD: if_fddisubr.c,v 1.102 2016/10/03 11:06:06 ozaki-r Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
| 5 | * 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. Neither the name of the project nor the names of its contributors |
| 16 | * may be used to endorse or promote products derived from this software |
| 17 | * without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
| 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | * SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | /* |
| 33 | * Copyright (c) 1982, 1989, 1993 |
| 34 | * The Regents of the University of California. All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * 1. Redistributions of source code must retain the above copyright |
| 40 | * notice, this list of conditions and the following disclaimer. |
| 41 | * 2. Redistributions in binary form must reproduce the above copyright |
| 42 | * notice, this list of conditions and the following disclaimer in the |
| 43 | * documentation and/or other materials provided with the distribution. |
| 44 | * 3. Neither the name of the University nor the names of its contributors |
| 45 | * may be used to endorse or promote products derived from this software |
| 46 | * without specific prior written permission. |
| 47 | * |
| 48 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 49 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 55 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 58 | * SUCH DAMAGE. |
| 59 | * |
| 60 | * @(#)if_fddisubr.c 8.1 (Berkeley) 6/10/93 |
| 61 | * |
| 62 | * Id: if_fddisubr.c,v 1.15 1997/03/21 22:35:50 thomas Exp |
| 63 | */ |
| 64 | |
| 65 | /* |
| 66 | * Copyright (c) 1995, 1996 |
| 67 | * Matt Thomas <matt@3am-software.com>. All rights reserved. |
| 68 | * |
| 69 | * Redistribution and use in source and binary forms, with or without |
| 70 | * modification, are permitted provided that the following conditions |
| 71 | * are met: |
| 72 | * 1. Redistributions of source code must retain the above copyright |
| 73 | * notice, this list of conditions and the following disclaimer. |
| 74 | * 2. Redistributions in binary form must reproduce the above copyright |
| 75 | * notice, this list of conditions and the following disclaimer in the |
| 76 | * documentation and/or other materials provided with the distribution. |
| 77 | * 3. The name of its contributor may not be used to endorse or promote |
| 78 | * products derived from this software without specific prior written |
| 79 | * permission. |
| 80 | * |
| 81 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 82 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 83 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 84 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 85 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 86 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 87 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 88 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 89 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 90 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 91 | * SUCH DAMAGE. |
| 92 | * |
| 93 | * @(#)if_fddisubr.c 8.1 (Berkeley) 6/10/93 |
| 94 | * |
| 95 | * Id: if_fddisubr.c,v 1.15 1997/03/21 22:35:50 thomas Exp |
| 96 | */ |
| 97 | |
| 98 | #include <sys/cdefs.h> |
| 99 | __KERNEL_RCSID(0, "$NetBSD: if_fddisubr.c,v 1.102 2016/10/03 11:06:06 ozaki-r Exp $" ); |
| 100 | |
| 101 | #ifdef _KERNEL_OPT |
| 102 | #include "opt_gateway.h" |
| 103 | #include "opt_inet.h" |
| 104 | #include "opt_atalk.h" |
| 105 | #include "opt_mbuftrace.h" |
| 106 | #endif |
| 107 | |
| 108 | |
| 109 | #include <sys/param.h> |
| 110 | #include <sys/systm.h> |
| 111 | #include <sys/kernel.h> |
| 112 | #include <sys/malloc.h> |
| 113 | #include <sys/mbuf.h> |
| 114 | #include <sys/protosw.h> |
| 115 | #include <sys/socket.h> |
| 116 | #include <sys/ioctl.h> |
| 117 | #include <sys/errno.h> |
| 118 | #include <sys/syslog.h> |
| 119 | |
| 120 | #include <sys/cpu.h> |
| 121 | |
| 122 | #include <net/if.h> |
| 123 | #include <net/netisr.h> |
| 124 | #include <net/route.h> |
| 125 | #include <net/if_llc.h> |
| 126 | #include <net/if_dl.h> |
| 127 | #include <net/if_types.h> |
| 128 | |
| 129 | #include <net/bpf.h> |
| 130 | |
| 131 | #ifdef INET |
| 132 | #include <netinet/in.h> |
| 133 | #include <netinet/in_var.h> |
| 134 | #include <netinet/if_inarp.h> |
| 135 | #endif |
| 136 | #include <net/if_fddi.h> |
| 137 | |
| 138 | #ifdef INET6 |
| 139 | #ifndef INET |
| 140 | #include <netinet/in.h> |
| 141 | #include <netinet/in_var.h> |
| 142 | #endif |
| 143 | #include <netinet6/nd6.h> |
| 144 | #endif |
| 145 | |
| 146 | |
| 147 | #include "carp.h" |
| 148 | #if NCARP > 0 |
| 149 | #include <netinet/ip_carp.h> |
| 150 | #endif |
| 151 | |
| 152 | #ifdef NETATALK |
| 153 | #include <netatalk/at.h> |
| 154 | #include <netatalk/at_var.h> |
| 155 | #include <netatalk/at_extern.h> |
| 156 | |
| 157 | #define llc_snap_org_code llc_un.type_snap.org_code |
| 158 | #define llc_snap_ether_type llc_un.type_snap.ether_type |
| 159 | |
| 160 | extern u_char at_org_code[ 3 ]; |
| 161 | extern u_char aarp_org_code[ 3 ]; |
| 162 | #endif /* NETATALK */ |
| 163 | |
| 164 | |
| 165 | |
| 166 | #define senderr(e) { error = (e); goto bad;} |
| 167 | |
| 168 | /* |
| 169 | * This really should be defined in if_llc.h but in case it isn't. |
| 170 | */ |
| 171 | #ifndef llc_snap |
| 172 | #define llc_snap llc_un.type_snap |
| 173 | #endif |
| 174 | |
| 175 | #define FDDIADDR(ifp) LLADDR((ifp)->if_sadl) |
| 176 | #define CFDDIADDR(ifp) CLLADDR((ifp)->if_sadl) |
| 177 | |
| 178 | static int fddi_output(struct ifnet *, struct mbuf *, |
| 179 | const struct sockaddr *, const struct rtentry *); |
| 180 | static void fddi_input(struct ifnet *, struct mbuf *); |
| 181 | |
| 182 | /* |
| 183 | * FDDI output routine. |
| 184 | * Encapsulate a packet of type family for the local net. |
| 185 | * Assumes that ifp is actually pointer to ethercom structure. |
| 186 | */ |
| 187 | static int |
| 188 | fddi_output(struct ifnet *ifp0, struct mbuf *m0, const struct sockaddr *dst, |
| 189 | const struct rtentry *rt) |
| 190 | { |
| 191 | uint16_t etype; |
| 192 | int error = 0, hdrcmplt = 0; |
| 193 | uint8_t esrc[6], edst[6]; |
| 194 | struct mbuf *m = m0; |
| 195 | struct fddi_header *fh; |
| 196 | struct mbuf *mcopy = NULL; |
| 197 | struct ifnet *ifp = ifp0; |
| 198 | |
| 199 | MCLAIM(m, ifp->if_mowner); |
| 200 | |
| 201 | #if NCARP > 0 |
| 202 | if (ifp->if_type == IFT_CARP) { |
| 203 | struct ifaddr *ifa; |
| 204 | |
| 205 | /* loop back if this is going to the carp interface */ |
| 206 | if (dst != NULL && ifp0->if_link_state == LINK_STATE_UP) { |
| 207 | int s = pserialize_read_enter(); |
| 208 | ifa = ifa_ifwithaddr(dst); |
| 209 | if (ifa != NULL && |
| 210 | ifa->ifa_ifp == ifp0) { |
| 211 | pserialize_read_exit(s); |
| 212 | return (looutput(ifp0, m, dst, rt)); |
| 213 | } |
| 214 | pserialize_read_exit(s); |
| 215 | } |
| 216 | |
| 217 | ifp = ifp->if_carpdev; |
| 218 | /* ac = (struct arpcom *)ifp; */ |
| 219 | |
| 220 | if ((ifp0->if_flags & (IFF_UP|IFF_RUNNING)) != |
| 221 | (IFF_UP|IFF_RUNNING)) |
| 222 | senderr(ENETDOWN); |
| 223 | } |
| 224 | #endif /* NCARP > 0 */ |
| 225 | if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) |
| 226 | senderr(ENETDOWN); |
| 227 | |
| 228 | /* |
| 229 | * If the queueing discipline needs packet classification, |
| 230 | * do it before prepending link headers. |
| 231 | */ |
| 232 | IFQ_CLASSIFY(&ifp->if_snd, m, dst->sa_family); |
| 233 | |
| 234 | switch (dst->sa_family) { |
| 235 | |
| 236 | #ifdef INET |
| 237 | case AF_INET: { |
| 238 | if (m->m_flags & M_BCAST) |
| 239 | memcpy(edst, fddibroadcastaddr, sizeof(edst)); |
| 240 | else if (m->m_flags & M_MCAST) { |
| 241 | ETHER_MAP_IP_MULTICAST(&satocsin(dst)->sin_addr, |
| 242 | (char *)edst); |
| 243 | } else if ((error = arpresolve(ifp, rt, m, dst, edst, |
| 244 | sizeof(edst))) != 0) |
| 245 | return error == EWOULDBLOCK ? 0 : error; |
| 246 | /* If broadcasting on a simplex interface, loopback a copy */ |
| 247 | if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) |
| 248 | mcopy = m_copy(m, 0, (int)M_COPYALL); |
| 249 | etype = htons(ETHERTYPE_IP); |
| 250 | break; |
| 251 | } |
| 252 | #endif |
| 253 | #ifdef INET6 |
| 254 | case AF_INET6: |
| 255 | if (!nd6_storelladdr(ifp, rt, m, dst, edst, sizeof(edst))){ |
| 256 | /* something bad happened */ |
| 257 | return (0); |
| 258 | } |
| 259 | etype = htons(ETHERTYPE_IPV6); |
| 260 | break; |
| 261 | #endif |
| 262 | #ifdef AF_ARP |
| 263 | case AF_ARP: { |
| 264 | struct arphdr *ah = mtod(m, struct arphdr *); |
| 265 | if (m->m_flags & M_BCAST) |
| 266 | memcpy(edst, etherbroadcastaddr, sizeof(edst)); |
| 267 | else { |
| 268 | void *tha = ar_tha(ah); |
| 269 | if (tha == NULL) |
| 270 | return 0; |
| 271 | memcpy(edst, tha, sizeof(edst)); |
| 272 | } |
| 273 | |
| 274 | ah->ar_hrd = htons(ARPHRD_ETHER); |
| 275 | |
| 276 | switch (ntohs(ah->ar_op)) { |
| 277 | case ARPOP_REVREQUEST: |
| 278 | case ARPOP_REVREPLY: |
| 279 | etype = htons(ETHERTYPE_REVARP); |
| 280 | break; |
| 281 | |
| 282 | case ARPOP_REQUEST: |
| 283 | case ARPOP_REPLY: |
| 284 | default: |
| 285 | etype = htons(ETHERTYPE_ARP); |
| 286 | } |
| 287 | |
| 288 | break; |
| 289 | } |
| 290 | #endif /* AF_ARP */ |
| 291 | #ifdef NETATALK |
| 292 | case AF_APPLETALK: { |
| 293 | struct at_ifaddr *aa; |
| 294 | struct ifaddr *ifa; |
| 295 | int s; |
| 296 | |
| 297 | if (!aarpresolve(ifp, m, (const struct sockaddr_at *)dst, edst)) { |
| 298 | #ifdef NETATALKDEBUG |
| 299 | printf("aarpresolv: failed\n" ); |
| 300 | #endif |
| 301 | return (0); |
| 302 | } |
| 303 | /* |
| 304 | * ifaddr is the first thing in at_ifaddr |
| 305 | */ |
| 306 | s = pserialize_read_enter(); |
| 307 | ifa = at_ifawithnet((const struct sockaddr_at *)dst, ifp); |
| 308 | if (ifa == NULL) { |
| 309 | pserialize_read_exit(s); |
| 310 | goto bad; |
| 311 | } |
| 312 | aa = (struct at_ifaddr *)ifa; |
| 313 | |
| 314 | /* |
| 315 | * In the phase 2 case, we need to prepend an mbuf for the llc |
| 316 | * header. Since we must preserve the value of m, which is |
| 317 | * passed to us by value, we m_copy() the first mbuf, and use |
| 318 | * it for our llc header. |
| 319 | */ |
| 320 | if (aa->aa_flags & AFA_PHASE2) { |
| 321 | struct llc llc; |
| 322 | |
| 323 | M_PREPEND(m, sizeof(struct llc), M_NOWAIT); |
| 324 | if (m == 0) |
| 325 | senderr(ENOBUFS); |
| 326 | llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; |
| 327 | llc.llc_control = LLC_UI; |
| 328 | memcpy(llc.llc_snap_org_code, at_org_code, |
| 329 | sizeof(at_org_code)); |
| 330 | llc.llc_snap_ether_type = htons(ETHERTYPE_ATALK); |
| 331 | memcpy(mtod(m, void *), &llc, sizeof(struct llc)); |
| 332 | etype = 0; |
| 333 | } else { |
| 334 | etype = htons(ETHERTYPE_ATALK); |
| 335 | } |
| 336 | pserialize_read_exit(s); |
| 337 | break; |
| 338 | } |
| 339 | #endif /* NETATALK */ |
| 340 | |
| 341 | case pseudo_AF_HDRCMPLT: |
| 342 | { |
| 343 | const struct fddi_header *fh1 = |
| 344 | (const struct fddi_header *)dst->sa_data; |
| 345 | hdrcmplt = 1; |
| 346 | memcpy(esrc, fh1->fddi_shost, sizeof (esrc)); |
| 347 | /*FALLTHROUGH*/ |
| 348 | } |
| 349 | |
| 350 | case AF_LINK: |
| 351 | { |
| 352 | const struct fddi_header *fh1 = |
| 353 | (const struct fddi_header *)dst->sa_data; |
| 354 | memcpy(edst, fh1->fddi_dhost, sizeof (edst)); |
| 355 | if (*edst & 1) |
| 356 | m->m_flags |= (M_BCAST|M_MCAST); |
| 357 | etype = 0; |
| 358 | break; |
| 359 | } |
| 360 | |
| 361 | case AF_UNSPEC: |
| 362 | { |
| 363 | const struct ether_header *eh; |
| 364 | eh = (const struct ether_header *)dst->sa_data; |
| 365 | memcpy(edst, eh->ether_dhost, sizeof(edst)); |
| 366 | if (*edst & 1) |
| 367 | m->m_flags |= (M_BCAST|M_MCAST); |
| 368 | etype = eh->ether_type; |
| 369 | break; |
| 370 | } |
| 371 | |
| 372 | default: |
| 373 | printf("%s: can't handle af%d\n" , ifp->if_xname, |
| 374 | dst->sa_family); |
| 375 | senderr(EAFNOSUPPORT); |
| 376 | } |
| 377 | |
| 378 | |
| 379 | if (mcopy) |
| 380 | (void) looutput(ifp, mcopy, dst, rt); |
| 381 | if (etype != 0) { |
| 382 | struct llc *l; |
| 383 | M_PREPEND(m, sizeof (struct llc), M_DONTWAIT); |
| 384 | if (m == 0) |
| 385 | senderr(ENOBUFS); |
| 386 | l = mtod(m, struct llc *); |
| 387 | l->llc_control = LLC_UI; |
| 388 | l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; |
| 389 | l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0; |
| 390 | memcpy(&l->llc_snap.ether_type, &etype, sizeof(uint16_t)); |
| 391 | } |
| 392 | /* |
| 393 | * Add local net header. If no space in first mbuf, |
| 394 | * allocate another. |
| 395 | */ |
| 396 | M_PREPEND(m, sizeof (struct fddi_header), M_DONTWAIT); |
| 397 | if (m == 0) |
| 398 | senderr(ENOBUFS); |
| 399 | fh = mtod(m, struct fddi_header *); |
| 400 | fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4; |
| 401 | memcpy(fh->fddi_dhost, edst, sizeof (edst)); |
| 402 | if (hdrcmplt) |
| 403 | memcpy(fh->fddi_shost, esrc, sizeof(fh->fddi_shost)); |
| 404 | else |
| 405 | memcpy(fh->fddi_shost, CFDDIADDR(ifp), sizeof(fh->fddi_shost)); |
| 406 | |
| 407 | #if NCARP > 0 |
| 408 | if (ifp0 != ifp && ifp0->if_type == IFT_CARP) { |
| 409 | if_set_sadl(ifp0, fh->fddi_shost, sizeof(fh->fddi_shost), |
| 410 | false); |
| 411 | } |
| 412 | |
| 413 | if (ifp != ifp0) |
| 414 | ifp0->if_obytes += m->m_pkthdr.len; |
| 415 | #endif /* NCARP > 0 */ |
| 416 | return ifq_enqueue(ifp, m); |
| 417 | |
| 418 | bad: |
| 419 | if (m) |
| 420 | m_freem(m); |
| 421 | return (error); |
| 422 | } |
| 423 | |
| 424 | /* |
| 425 | * Process a received FDDI packet; |
| 426 | * the packet is in the mbuf chain m with |
| 427 | * the fddi header. |
| 428 | */ |
| 429 | static void |
| 430 | fddi_input(struct ifnet *ifp, struct mbuf *m) |
| 431 | { |
| 432 | #if defined(INET) || defined(INET6) |
| 433 | pktqueue_t *pktq = NULL; |
| 434 | #endif |
| 435 | #if defined(NETATALK) |
| 436 | struct ifqueue *inq = NULL; |
| 437 | int isr = 0; |
| 438 | #endif |
| 439 | |
| 440 | struct llc *l; |
| 441 | struct fddi_header *fh; |
| 442 | |
| 443 | MCLAIM(m, &((struct ethercom *)ifp)->ec_rx_mowner); |
| 444 | if ((ifp->if_flags & IFF_UP) == 0) { |
| 445 | m_freem(m); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | fh = mtod(m, struct fddi_header *); |
| 450 | |
| 451 | ifp->if_ibytes += m->m_pkthdr.len; |
| 452 | if (fh->fddi_dhost[0] & 1) { |
| 453 | if (memcmp(fddibroadcastaddr, fh->fddi_dhost, |
| 454 | sizeof(fddibroadcastaddr)) == 0) |
| 455 | m->m_flags |= M_BCAST; |
| 456 | else |
| 457 | m->m_flags |= M_MCAST; |
| 458 | ifp->if_imcasts++; |
| 459 | } else if ((ifp->if_flags & IFF_PROMISC) |
| 460 | && memcmp(CFDDIADDR(ifp), (void *)fh->fddi_dhost, |
| 461 | sizeof(fh->fddi_dhost)) != 0) { |
| 462 | m_freem(m); |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | #ifdef M_LINK0 |
| 467 | /* |
| 468 | * If this has a LLC priority of 0, then mark it so upper |
| 469 | * layers have a hint that it really came via a FDDI/Ethernet |
| 470 | * bridge. |
| 471 | */ |
| 472 | if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0) |
| 473 | m->m_flags |= M_LINK0; |
| 474 | #endif |
| 475 | |
| 476 | l = (struct llc *)(fh+1); |
| 477 | switch (l->llc_dsap) { |
| 478 | #if defined(INET) || defined(INET6) || defined(NETATALK) |
| 479 | case LLC_SNAP_LSAP: |
| 480 | { |
| 481 | uint16_t etype; |
| 482 | if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP) |
| 483 | goto dropanyway; |
| 484 | |
| 485 | /* Strip off the FDDI header. */ |
| 486 | m_adj(m, sizeof(struct fddi_header)); |
| 487 | |
| 488 | #ifdef NETATALK |
| 489 | if (memcmp(&(l->llc_snap_org_code)[0], at_org_code, |
| 490 | sizeof(at_org_code)) == 0 && |
| 491 | ntohs(l->llc_snap_ether_type) == ETHERTYPE_ATALK) { |
| 492 | inq = &atintrq2; |
| 493 | m_adj( m, sizeof( struct llc )); |
| 494 | isr = NETISR_ATALK; |
| 495 | break; |
| 496 | } |
| 497 | |
| 498 | if (memcmp(&(l->llc_snap_org_code)[0], aarp_org_code, |
| 499 | sizeof(aarp_org_code)) == 0 && |
| 500 | ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) { |
| 501 | m_adj( m, sizeof( struct llc )); |
| 502 | aarpinput(ifp, m); /* XXX */ |
| 503 | return; |
| 504 | } |
| 505 | #endif /* NETATALK */ |
| 506 | if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0) |
| 507 | goto dropanyway; |
| 508 | etype = ntohs(l->llc_snap.ether_type); |
| 509 | m_adj(m, 8); |
| 510 | #if NCARP > 0 |
| 511 | if (ifp->if_carp && ifp->if_type != IFT_CARP && |
| 512 | (carp_input(m, (uint8_t *)&fh->fddi_shost, |
| 513 | (uint8_t *)&fh->fddi_dhost, l->llc_snap.ether_type) == 0)) |
| 514 | return; |
| 515 | #endif |
| 516 | |
| 517 | switch (etype) { |
| 518 | #ifdef INET |
| 519 | case ETHERTYPE_IP: |
| 520 | #ifdef GATEWAY |
| 521 | if (ipflow_fastforward(m)) |
| 522 | return; |
| 523 | #endif |
| 524 | pktq = ip_pktq; |
| 525 | break; |
| 526 | |
| 527 | case ETHERTYPE_ARP: |
| 528 | #if !defined(__bsdi__) || _BSDI_VERSION >= 199401 |
| 529 | #if defined(NETATALK) |
| 530 | isr = NETISR_ARP; |
| 531 | inq = &arpintrq; |
| 532 | #endif |
| 533 | break; |
| 534 | #else |
| 535 | arpinput(ifp, m); |
| 536 | return; |
| 537 | #endif |
| 538 | #endif |
| 539 | #ifdef INET6 |
| 540 | case ETHERTYPE_IPV6: |
| 541 | #ifdef GATEWAY |
| 542 | if (ip6flow_fastforward(&m)) |
| 543 | return; |
| 544 | #endif |
| 545 | pktq = ip6_pktq; |
| 546 | break; |
| 547 | |
| 548 | #endif |
| 549 | #ifdef NETATALK |
| 550 | case ETHERTYPE_ATALK: |
| 551 | isr = NETISR_ATALK; |
| 552 | inq = &atintrq1; |
| 553 | break; |
| 554 | case ETHERTYPE_AARP: |
| 555 | /* probably this should be done with a NETISR as well */ |
| 556 | aarpinput(ifp, m); /* XXX */ |
| 557 | return; |
| 558 | #endif /* NETATALK */ |
| 559 | default: |
| 560 | ifp->if_noproto++; |
| 561 | goto dropanyway; |
| 562 | } |
| 563 | break; |
| 564 | } |
| 565 | #endif /* INET || NS */ |
| 566 | |
| 567 | default: |
| 568 | ifp->if_noproto++; |
| 569 | #if defined(INET) || defined(INET6) || defined(NETATALK) |
| 570 | dropanyway: |
| 571 | #endif |
| 572 | m_freem(m); |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | #if defined(INET) || defined(INET6) |
| 577 | if (__predict_true(pktq)) { |
| 578 | if (__predict_false(!pktq_enqueue(pktq, m, 0))) { |
| 579 | m_freem(m); |
| 580 | } |
| 581 | return; |
| 582 | } |
| 583 | #endif |
| 584 | #if defined(NETATALK) |
| 585 | if (inq == NULL) { |
| 586 | m_freem(m); |
| 587 | return; |
| 588 | } |
| 589 | IFQ_LOCK(inq); |
| 590 | if (IF_QFULL(inq)) { |
| 591 | IF_DROP(inq); |
| 592 | IFQ_UNLOCK(inq); |
| 593 | m_freem(m); |
| 594 | } else { |
| 595 | IF_ENQUEUE(inq, m); |
| 596 | IFQ_UNLOCK(inq); |
| 597 | schednetisr(isr); |
| 598 | } |
| 599 | #endif |
| 600 | } |
| 601 | |
| 602 | /* |
| 603 | * Perform common duties while attaching to interface list |
| 604 | */ |
| 605 | void |
| 606 | fddi_ifattach(struct ifnet *ifp, void *lla) |
| 607 | { |
| 608 | struct ethercom *ec = (struct ethercom *)ifp; |
| 609 | |
| 610 | ifp->if_type = IFT_FDDI; |
| 611 | ifp->if_hdrlen = 21; |
| 612 | ifp->if_dlt = DLT_FDDI; |
| 613 | ifp->if_mtu = FDDIMTU; |
| 614 | ifp->if_output = fddi_output; |
| 615 | ifp->_if_input = fddi_input; |
| 616 | ifp->if_baudrate = IF_Mbps(100); |
| 617 | #ifdef IFF_NOTRAILERS |
| 618 | ifp->if_flags |= IFF_NOTRAILERS; |
| 619 | #endif |
| 620 | |
| 621 | /* |
| 622 | * Update the max_linkhdr |
| 623 | */ |
| 624 | if (ALIGN(ifp->if_hdrlen) > max_linkhdr) |
| 625 | max_linkhdr = ALIGN(ifp->if_hdrlen); |
| 626 | |
| 627 | LIST_INIT(&ec->ec_multiaddrs); |
| 628 | if_set_sadl(ifp, lla, 6, true); |
| 629 | |
| 630 | ifp->if_broadcastaddr = fddibroadcastaddr; |
| 631 | bpf_attach(ifp, DLT_FDDI, sizeof(struct fddi_header)); |
| 632 | #ifdef MBUFTRACE |
| 633 | strlcpy(ec->ec_tx_mowner.mo_name, ifp->if_xname, |
| 634 | sizeof(ec->ec_tx_mowner.mo_name)); |
| 635 | strlcpy(ec->ec_tx_mowner.mo_descr, "tx" , |
| 636 | sizeof(ec->ec_tx_mowner.mo_descr)); |
| 637 | strlcpy(ec->ec_rx_mowner.mo_name, ifp->if_xname, |
| 638 | sizeof(ec->ec_rx_mowner.mo_name)); |
| 639 | strlcpy(ec->ec_rx_mowner.mo_descr, "rx" , |
| 640 | sizeof(ec->ec_rx_mowner.mo_descr)); |
| 641 | MOWNER_ATTACH(&ec->ec_tx_mowner); |
| 642 | MOWNER_ATTACH(&ec->ec_rx_mowner); |
| 643 | ifp->if_mowner = &ec->ec_tx_mowner; |
| 644 | #endif |
| 645 | } |
| 646 | |