2 * Copyright (c) 1982, 1989, 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 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93
34 * $FreeBSD: src/sys/net/if_ethersubr.c,v 1.70.2.33 2003/04/28 15:45:53 archie Exp $
35 * $DragonFly: src/sys/net/if_ethersubr.c,v 1.96 2008/11/22 04:00:53 sephe Exp $
38 #include "opt_atalk.h"
40 #include "opt_inet6.h"
43 #include "opt_netgraph.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/globaldata.h>
50 #include <sys/kernel.h>
53 #include <sys/malloc.h>
55 #include <sys/msgport.h>
56 #include <sys/socket.h>
57 #include <sys/sockio.h>
58 #include <sys/sysctl.h>
59 #include <sys/thread.h>
60 #include <sys/thread2.h>
63 #include <net/netisr.h>
64 #include <net/route.h>
65 #include <net/if_llc.h>
66 #include <net/if_dl.h>
67 #include <net/if_types.h>
68 #include <net/ifq_var.h>
70 #include <net/ethernet.h>
71 #include <net/vlan/if_vlan_ether.h>
72 #include <net/netmsg2.h>
74 #if defined(INET) || defined(INET6)
75 #include <netinet/in.h>
76 #include <netinet/ip_var.h>
77 #include <netinet/if_ether.h>
78 #include <netinet/ip_flow.h>
79 #include <net/ipfw/ip_fw.h>
80 #include <net/dummynet/ip_dummynet.h>
83 #include <netinet6/nd6.h>
87 #include <netinet/ip_carp.h>
91 #include <netproto/ipx/ipx.h>
92 #include <netproto/ipx/ipx_if.h>
93 int (*ef_inputp
)(struct ifnet
*, const struct ether_header
*eh
, struct mbuf
*m
);
94 int (*ef_outputp
)(struct ifnet
*ifp
, struct mbuf
**mp
, struct sockaddr
*dst
,
95 short *tp
, int *hlen
);
100 #include <netns/ns_if.h>
102 int ether_outputdebug
= 0;
103 int ether_inputdebug
= 0;
107 #include <netproto/atalk/at.h>
108 #include <netproto/atalk/at_var.h>
109 #include <netproto/atalk/at_extern.h>
111 #define llc_snap_org_code llc_un.type_snap.org_code
112 #define llc_snap_ether_type llc_un.type_snap.ether_type
114 extern u_char at_org_code
[3];
115 extern u_char aarp_org_code
[3];
116 #endif /* NETATALK */
119 #include <netproto/mpls/mpls.h>
122 /* netgraph node hooks for ng_ether(4) */
123 void (*ng_ether_input_p
)(struct ifnet
*ifp
, struct mbuf
**mp
);
124 void (*ng_ether_input_orphan_p
)(struct ifnet
*ifp
,
125 struct mbuf
*m
, const struct ether_header
*eh
);
126 int (*ng_ether_output_p
)(struct ifnet
*ifp
, struct mbuf
**mp
);
127 void (*ng_ether_attach_p
)(struct ifnet
*ifp
);
128 void (*ng_ether_detach_p
)(struct ifnet
*ifp
);
130 void (*vlan_input_p
)(struct mbuf
*);
132 static int ether_output(struct ifnet
*, struct mbuf
*, struct sockaddr
*,
134 static void ether_restore_header(struct mbuf
**, const struct ether_header
*,
135 const struct ether_header
*);
140 struct mbuf
*(*bridge_input_p
)(struct ifnet
*, struct mbuf
*);
141 int (*bridge_output_p
)(struct ifnet
*, struct mbuf
*);
142 void (*bridge_dn_p
)(struct mbuf
*, struct ifnet
*);
144 static int ether_resolvemulti(struct ifnet
*, struct sockaddr
**,
147 const uint8_t etherbroadcastaddr
[ETHER_ADDR_LEN
] = {
148 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
151 #define gotoerr(e) do { error = (e); goto bad; } while (0)
152 #define IFP2AC(ifp) ((struct arpcom *)(ifp))
154 static boolean_t
ether_ipfw_chk(struct mbuf
**m0
, struct ifnet
*dst
,
156 const struct ether_header
*eh
);
158 static int ether_ipfw
;
159 static u_int ether_restore_hdr
;
160 static u_int ether_prepend_hdr
;
163 static u_int ether_pktinfo_try
;
164 static u_int ether_pktinfo_hit
;
165 static u_int ether_rss_nopi
;
166 static u_int ether_rss_nohash
;
169 SYSCTL_DECL(_net_link
);
170 SYSCTL_NODE(_net_link
, IFT_ETHER
, ether
, CTLFLAG_RW
, 0, "Ethernet");
171 SYSCTL_INT(_net_link_ether
, OID_AUTO
, ipfw
, CTLFLAG_RW
,
172 ðer_ipfw
, 0, "Pass ether pkts through firewall");
173 SYSCTL_UINT(_net_link_ether
, OID_AUTO
, restore_hdr
, CTLFLAG_RW
,
174 ðer_restore_hdr
, 0, "# of ether header restoration");
175 SYSCTL_UINT(_net_link_ether
, OID_AUTO
, prepend_hdr
, CTLFLAG_RW
,
176 ðer_prepend_hdr
, 0,
177 "# of ether header restoration which prepends mbuf");
179 SYSCTL_UINT(_net_link_ether
, OID_AUTO
, rss_nopi
, CTLFLAG_RW
,
180 ðer_rss_nopi
, 0, "# of packets do not have pktinfo");
181 SYSCTL_UINT(_net_link_ether
, OID_AUTO
, rss_nohash
, CTLFLAG_RW
,
182 ðer_rss_nohash
, 0, "# of packets do not have hash");
183 SYSCTL_UINT(_net_link_ether
, OID_AUTO
, pktinfo_try
, CTLFLAG_RW
,
184 ðer_pktinfo_try
, 0,
185 "# of tries to find packets' msgport using pktinfo");
186 SYSCTL_UINT(_net_link_ether
, OID_AUTO
, pktinfo_hit
, CTLFLAG_RW
,
187 ðer_pktinfo_hit
, 0,
188 "# of packets whose msgport are found using pktinfo");
191 #define ETHER_KTR_STR "ifp=%p"
192 #define ETHER_KTR_ARG_SIZE (sizeof(void *))
194 #define KTR_ETHERNET KTR_ALL
196 KTR_INFO_MASTER(ether
);
197 KTR_INFO(KTR_ETHERNET
, ether
, chain_beg
, 0, ETHER_KTR_STR
, ETHER_KTR_ARG_SIZE
);
198 KTR_INFO(KTR_ETHERNET
, ether
, chain_end
, 1, ETHER_KTR_STR
, ETHER_KTR_ARG_SIZE
);
199 KTR_INFO(KTR_ETHERNET
, ether
, disp_beg
, 2, ETHER_KTR_STR
, ETHER_KTR_ARG_SIZE
);
200 KTR_INFO(KTR_ETHERNET
, ether
, disp_end
, 3, ETHER_KTR_STR
, ETHER_KTR_ARG_SIZE
);
201 #define logether(name, arg) KTR_LOG(ether_ ## name, arg)
204 * Ethernet output routine.
205 * Encapsulate a packet of type family for the local net.
206 * Use trailer local net encapsulation if enough data in first
207 * packet leaves a multiple of 512 bytes of data in remainder.
208 * Assumes that ifp is actually pointer to arpcom structure.
211 ether_output(struct ifnet
*ifp
, struct mbuf
*m
, struct sockaddr
*dst
,
214 struct ether_header
*eh
, *deh
;
217 int hlen
= ETHER_HDR_LEN
; /* link layer header length */
218 struct arpcom
*ac
= IFP2AC(ifp
);
221 ASSERT_IFNET_NOT_SERIALIZED_ALL(ifp
);
223 if (ifp
->if_flags
& IFF_MONITOR
)
225 if ((ifp
->if_flags
& (IFF_UP
| IFF_RUNNING
)) != (IFF_UP
| IFF_RUNNING
))
228 M_PREPEND(m
, sizeof(struct ether_header
), MB_DONTWAIT
);
231 eh
= mtod(m
, struct ether_header
*);
232 edst
= eh
->ether_dhost
;
235 * Fill in the destination ethernet address and frame type.
237 switch (dst
->sa_family
) {
240 if (!arpresolve(ifp
, rt
, m
, dst
, edst
))
241 return (0); /* if not yet resolved */
243 if (m
->m_flags
& M_MPLSLABELED
)
244 eh
->ether_type
= htons(ETHERTYPE_MPLS
);
247 eh
->ether_type
= htons(ETHERTYPE_IP
);
252 if (!nd6_storelladdr(&ac
->ac_if
, rt
, m
, dst
, edst
))
253 return (0); /* Something bad happenned. */
254 eh
->ether_type
= htons(ETHERTYPE_IPV6
);
259 if (ef_outputp
!= NULL
) {
261 * Hold BGL and recheck ef_outputp
264 if (ef_outputp
!= NULL
) {
265 error
= ef_outputp(ifp
, &m
, dst
,
266 &eh
->ether_type
, &hlen
);
275 eh
->ether_type
= htons(ETHERTYPE_IPX
);
276 bcopy(&(((struct sockaddr_ipx
*)dst
)->sipx_addr
.x_host
),
277 edst
, ETHER_ADDR_LEN
);
282 struct at_ifaddr
*aa
;
289 if ((aa
= at_ifawithnet((struct sockaddr_at
*)dst
)) == NULL
) {
295 * In the phase 2 case, need to prepend an mbuf for
296 * the llc header. Since we must preserve the value
297 * of m, which is passed to us by value, we m_copy()
298 * the first mbuf, and use it for our llc header.
300 if (aa
->aa_flags
& AFA_PHASE2
) {
303 M_PREPEND(m
, sizeof(struct llc
), MB_DONTWAIT
);
304 eh
= mtod(m
, struct ether_header
*);
305 edst
= eh
->ether_dhost
;
306 llc
.llc_dsap
= llc
.llc_ssap
= LLC_SNAP_LSAP
;
307 llc
.llc_control
= LLC_UI
;
308 bcopy(at_org_code
, llc
.llc_snap_org_code
,
310 llc
.llc_snap_ether_type
= htons(ETHERTYPE_AT
);
312 mtod(m
, caddr_t
) + sizeof(struct ether_header
),
314 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
315 hlen
= sizeof(struct llc
) + ETHER_HDR_LEN
;
317 eh
->ether_type
= htons(ETHERTYPE_AT
);
319 if (!aarpresolve(ac
, m
, (struct sockaddr_at
*)dst
, edst
)) {
332 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
333 eh
->ether_type
= 0x8137;
335 case 0x0: /* Novell 802.3 */
336 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
338 case 0xe0e0: /* Novell 802.2 and Token-Ring */
339 M_PREPEND(m
, 3, MB_DONTWAIT
);
340 eh
= mtod(m
, struct ether_header
*);
341 edst
= eh
->ether_dhost
;
342 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
343 cp
= mtod(m
, u_char
*) + sizeof(struct ether_header
);
349 bcopy(&(((struct sockaddr_ns
*)dst
)->sns_addr
.x_host
), edst
,
352 * XXX if ns_thishost is the same as the node's ethernet
353 * address then just the default code will catch this anyhow.
354 * So I'm not sure if this next clause should be here at all?
357 if (bcmp(edst
, &ns_thishost
, ETHER_ADDR_LEN
) == 0) {
358 m
->m_pkthdr
.rcvif
= ifp
;
359 netisr_dispatch(NETISR_NS
, m
);
362 if (bcmp(edst
, &ns_broadhost
, ETHER_ADDR_LEN
) == 0)
363 m
->m_flags
|= M_BCAST
;
366 case pseudo_AF_HDRCMPLT
:
368 loop_copy
= -1; /* if this is for us, don't do it */
369 deh
= (struct ether_header
*)dst
->sa_data
;
370 memcpy(edst
, deh
->ether_dhost
, ETHER_ADDR_LEN
);
371 eh
->ether_type
= deh
->ether_type
;
375 if_printf(ifp
, "can't handle af%d\n", dst
->sa_family
);
376 gotoerr(EAFNOSUPPORT
);
379 if (dst
->sa_family
== pseudo_AF_HDRCMPLT
) /* unlikely */
380 memcpy(eh
->ether_shost
,
381 ((struct ether_header
*)dst
->sa_data
)->ether_shost
,
384 memcpy(eh
->ether_shost
, ac
->ac_enaddr
, ETHER_ADDR_LEN
);
387 * Bridges require special output handling.
389 if (ifp
->if_bridge
) {
390 KASSERT(bridge_output_p
!= NULL
,
391 ("%s: if_bridge not loaded!", __func__
));
392 return bridge_output_p(ifp
, m
);
396 * If a simplex interface, and the packet is being sent to our
397 * Ethernet address or a broadcast address, loopback a copy.
398 * XXX To make a simplex device behave exactly like a duplex
399 * device, we should copy in the case of sending to our own
400 * ethernet address (thus letting the original actually appear
401 * on the wire). However, we don't do that here for security
402 * reasons and compatibility with the original behavior.
404 if ((ifp
->if_flags
& IFF_SIMPLEX
) && (loop_copy
!= -1)) {
407 if (m
->m_pkthdr
.csum_flags
& CSUM_IP
)
408 csum_flags
|= (CSUM_IP_CHECKED
| CSUM_IP_VALID
);
409 if (m
->m_pkthdr
.csum_flags
& CSUM_DELAY_DATA
)
410 csum_flags
|= (CSUM_DATA_VALID
| CSUM_PSEUDO_HDR
);
411 if ((m
->m_flags
& M_BCAST
) || (loop_copy
> 0)) {
414 if ((n
= m_copypacket(m
, MB_DONTWAIT
)) != NULL
) {
415 n
->m_pkthdr
.csum_flags
|= csum_flags
;
416 if (csum_flags
& CSUM_DATA_VALID
)
417 n
->m_pkthdr
.csum_data
= 0xffff;
418 if_simloop(ifp
, n
, dst
->sa_family
, hlen
);
421 } else if (bcmp(eh
->ether_dhost
, eh
->ether_shost
,
422 ETHER_ADDR_LEN
) == 0) {
423 m
->m_pkthdr
.csum_flags
|= csum_flags
;
424 if (csum_flags
& CSUM_DATA_VALID
)
425 m
->m_pkthdr
.csum_data
= 0xffff;
426 if_simloop(ifp
, m
, dst
->sa_family
, hlen
);
427 return (0); /* XXX */
434 * Hold BGL and recheck ifp->if_carp
437 if (ifp
->if_carp
&& (error
= carp_output(ifp
, m
, dst
, NULL
))) {
446 /* Handle ng_ether(4) processing, if any */
447 if (ng_ether_output_p
!= NULL
) {
449 * Hold BGL and recheck ng_ether_output_p
452 if (ng_ether_output_p
!= NULL
) {
453 if ((error
= ng_ether_output_p(ifp
, &m
)) != 0) {
465 /* Continue with link-layer output */
466 return ether_output_frame(ifp
, m
);
474 * Ethernet link layer output routine to send a raw frame to the device.
476 * This assumes that the 14 byte Ethernet header is present and contiguous
480 ether_output_frame(struct ifnet
*ifp
, struct mbuf
*m
)
482 struct ip_fw
*rule
= NULL
;
484 struct altq_pktattr pktattr
;
486 ASSERT_IFNET_NOT_SERIALIZED_ALL(ifp
);
488 if (m
->m_pkthdr
.fw_flags
& DUMMYNET_MBUF_TAGGED
) {
491 /* Extract info from dummynet tag */
492 mtag
= m_tag_find(m
, PACKET_TAG_DUMMYNET
, NULL
);
493 KKASSERT(mtag
!= NULL
);
494 rule
= ((struct dn_pkt
*)m_tag_data(mtag
))->dn_priv
;
495 KKASSERT(rule
!= NULL
);
497 m_tag_delete(m
, mtag
);
498 m
->m_pkthdr
.fw_flags
&= ~DUMMYNET_MBUF_TAGGED
;
501 if (ifq_is_enabled(&ifp
->if_snd
))
502 altq_etherclassify(&ifp
->if_snd
, m
, &pktattr
);
504 if (IPFW_LOADED
&& ether_ipfw
!= 0) {
505 struct ether_header save_eh
, *eh
;
507 eh
= mtod(m
, struct ether_header
*);
509 m_adj(m
, ETHER_HDR_LEN
);
510 if (!ether_ipfw_chk(&m
, ifp
, &rule
, eh
)) {
514 return ENOBUFS
; /* pkt dropped */
516 return 0; /* consumed e.g. in a pipe */
519 /* packet was ok, restore the ethernet header */
520 ether_restore_header(&m
, eh
, &save_eh
);
529 * Queue message on interface, update output statistics if
530 * successful, and start output if interface not yet active.
532 error
= ifq_dispatch(ifp
, m
, &pktattr
);
537 * ipfw processing for ethernet packets (in and out).
538 * The second parameter is NULL from ether_demux(), and ifp from
539 * ether_output_frame().
542 ether_ipfw_chk(struct mbuf
**m0
, struct ifnet
*dst
, struct ip_fw
**rule
,
543 const struct ether_header
*eh
)
545 struct ether_header save_eh
= *eh
; /* might be a ptr in *m0 */
546 struct ip_fw_args args
;
551 if (*rule
!= NULL
&& fw_one_pass
)
552 return TRUE
; /* dummynet packet, already partially processed */
555 * I need some amount of data to be contiguous.
557 i
= min((*m0
)->m_pkthdr
.len
, max_protohdr
);
558 if ((*m0
)->m_len
< i
) {
559 *m0
= m_pullup(*m0
, i
);
567 if ((mtag
= m_tag_find(*m0
, PACKET_TAG_IPFW_DIVERT
, NULL
)) != NULL
)
568 m_tag_delete(*m0
, mtag
);
569 if ((*m0
)->m_pkthdr
.fw_flags
& IPFORWARD_MBUF_TAGGED
) {
570 mtag
= m_tag_find(*m0
, PACKET_TAG_IPFORWARD
, NULL
);
571 KKASSERT(mtag
!= NULL
);
572 m_tag_delete(*m0
, mtag
);
573 (*m0
)->m_pkthdr
.fw_flags
&= ~IPFORWARD_MBUF_TAGGED
;
576 args
.m
= *m0
; /* the packet we are looking at */
577 args
.oif
= dst
; /* destination, if any */
578 args
.rule
= *rule
; /* matching rule to restart */
579 args
.eh
= &save_eh
; /* MAC header for bridged/MAC packets */
580 i
= ip_fw_chk_ptr(&args
);
595 * XXX at some point add support for divert/forward actions.
596 * If none of the above matches, we have to drop the pkt.
602 * Pass the pkt to dummynet, which consumes it.
604 m
= *m0
; /* pass the original to dummynet */
605 *m0
= NULL
; /* and nothing back to the caller */
607 ether_restore_header(&m
, eh
, &save_eh
);
611 ip_fw_dn_io_ptr(m
, args
.cookie
,
612 dst
? DN_TO_ETH_OUT
: DN_TO_ETH_DEMUX
, &args
);
617 panic("unknown ipfw return value: %d\n", i
);
622 ether_input(struct ifnet
*ifp
, struct mbuf
*m
)
624 ether_input_chain(ifp
, m
, NULL
, NULL
);
628 * Perform common duties while attaching to interface list
631 ether_ifattach(struct ifnet
*ifp
, uint8_t *lla
, lwkt_serialize_t serializer
)
633 ether_ifattach_bpf(ifp
, lla
, DLT_EN10MB
, sizeof(struct ether_header
),
638 ether_ifattach_bpf(struct ifnet
*ifp
, uint8_t *lla
, u_int dlt
, u_int hdrlen
,
639 lwkt_serialize_t serializer
)
641 struct sockaddr_dl
*sdl
;
643 ifp
->if_type
= IFT_ETHER
;
644 ifp
->if_addrlen
= ETHER_ADDR_LEN
;
645 ifp
->if_hdrlen
= ETHER_HDR_LEN
;
646 if_attach(ifp
, serializer
);
647 ifp
->if_mtu
= ETHERMTU
;
648 if (ifp
->if_baudrate
== 0)
649 ifp
->if_baudrate
= 10000000;
650 ifp
->if_output
= ether_output
;
651 ifp
->if_input
= ether_input
;
652 ifp
->if_resolvemulti
= ether_resolvemulti
;
653 ifp
->if_broadcastaddr
= etherbroadcastaddr
;
654 sdl
= IF_LLSOCKADDR(ifp
);
655 sdl
->sdl_type
= IFT_ETHER
;
656 sdl
->sdl_alen
= ifp
->if_addrlen
;
657 bcopy(lla
, LLADDR(sdl
), ifp
->if_addrlen
);
659 * XXX Keep the current drivers happy.
660 * XXX Remove once all drivers have been cleaned up
662 if (lla
!= IFP2AC(ifp
)->ac_enaddr
)
663 bcopy(lla
, IFP2AC(ifp
)->ac_enaddr
, ifp
->if_addrlen
);
664 bpfattach(ifp
, dlt
, hdrlen
);
665 if (ng_ether_attach_p
!= NULL
)
666 (*ng_ether_attach_p
)(ifp
);
668 if_printf(ifp
, "MAC address: %6D\n", lla
, ":");
672 * Perform common duties while detaching an Ethernet interface
675 ether_ifdetach(struct ifnet
*ifp
)
679 if (ng_ether_detach_p
!= NULL
)
680 (*ng_ether_detach_p
)(ifp
);
686 ether_ioctl(struct ifnet
*ifp
, int command
, caddr_t data
)
688 struct ifaddr
*ifa
= (struct ifaddr
*) data
;
689 struct ifreq
*ifr
= (struct ifreq
*) data
;
692 #define IF_INIT(ifp) \
694 if (((ifp)->if_flags & IFF_UP) == 0) { \
695 (ifp)->if_flags |= IFF_UP; \
696 (ifp)->if_init((ifp)->if_softc); \
700 ASSERT_IFNET_SERIALIZED_ALL(ifp
);
704 switch (ifa
->ifa_addr
->sa_family
) {
707 IF_INIT(ifp
); /* before arpwhohas */
708 arp_ifinit(ifp
, ifa
);
713 * XXX - This code is probably wrong
717 struct ipx_addr
*ina
= &IA_SIPX(ifa
)->sipx_addr
;
718 struct arpcom
*ac
= IFP2AC(ifp
);
720 if (ipx_nullhost(*ina
))
721 ina
->x_host
= *(union ipx_host
*) ac
->ac_enaddr
;
723 bcopy(ina
->x_host
.c_host
, ac
->ac_enaddr
,
724 sizeof ac
->ac_enaddr
);
726 IF_INIT(ifp
); /* Set new address. */
732 * XXX - This code is probably wrong
736 struct ns_addr
*ina
= &(IA_SNS(ifa
)->sns_addr
);
737 struct arpcom
*ac
= IFP2AC(ifp
);
739 if (ns_nullhost(*ina
))
740 ina
->x_host
= *(union ns_host
*)(ac
->ac_enaddr
);
742 bcopy(ina
->x_host
.c_host
, ac
->ac_enaddr
,
743 sizeof ac
->ac_enaddr
);
759 bcopy(IFP2AC(ifp
)->ac_enaddr
,
760 ((struct sockaddr
*)ifr
->ifr_data
)->sa_data
,
766 * Set the interface MTU.
768 if (ifr
->ifr_mtu
> ETHERMTU
) {
771 ifp
->if_mtu
= ifr
->ifr_mtu
;
786 struct sockaddr
**llsa
,
789 struct sockaddr_dl
*sdl
;
790 struct sockaddr_in
*sin
;
792 struct sockaddr_in6
*sin6
;
796 switch(sa
->sa_family
) {
799 * No mapping needed. Just check that it's a valid MC address.
801 sdl
= (struct sockaddr_dl
*)sa
;
802 e_addr
= LLADDR(sdl
);
803 if ((e_addr
[0] & 1) != 1)
804 return EADDRNOTAVAIL
;
810 sin
= (struct sockaddr_in
*)sa
;
811 if (!IN_MULTICAST(ntohl(sin
->sin_addr
.s_addr
)))
812 return EADDRNOTAVAIL
;
813 MALLOC(sdl
, struct sockaddr_dl
*, sizeof *sdl
, M_IFMADDR
,
815 sdl
->sdl_len
= sizeof *sdl
;
816 sdl
->sdl_family
= AF_LINK
;
817 sdl
->sdl_index
= ifp
->if_index
;
818 sdl
->sdl_type
= IFT_ETHER
;
819 sdl
->sdl_alen
= ETHER_ADDR_LEN
;
820 e_addr
= LLADDR(sdl
);
821 ETHER_MAP_IP_MULTICAST(&sin
->sin_addr
, e_addr
);
822 *llsa
= (struct sockaddr
*)sdl
;
827 sin6
= (struct sockaddr_in6
*)sa
;
828 if (IN6_IS_ADDR_UNSPECIFIED(&sin6
->sin6_addr
)) {
830 * An IP6 address of 0 means listen to all
831 * of the Ethernet multicast address used for IP6.
832 * (This is used for multicast routers.)
834 ifp
->if_flags
|= IFF_ALLMULTI
;
838 if (!IN6_IS_ADDR_MULTICAST(&sin6
->sin6_addr
))
839 return EADDRNOTAVAIL
;
840 MALLOC(sdl
, struct sockaddr_dl
*, sizeof *sdl
, M_IFMADDR
,
842 sdl
->sdl_len
= sizeof *sdl
;
843 sdl
->sdl_family
= AF_LINK
;
844 sdl
->sdl_index
= ifp
->if_index
;
845 sdl
->sdl_type
= IFT_ETHER
;
846 sdl
->sdl_alen
= ETHER_ADDR_LEN
;
847 e_addr
= LLADDR(sdl
);
848 ETHER_MAP_IPV6_MULTICAST(&sin6
->sin6_addr
, e_addr
);
849 *llsa
= (struct sockaddr
*)sdl
;
855 * Well, the text isn't quite right, but it's the name
864 * This is for reference. We have a table-driven version
865 * of the little-endian crc32 generator, which is faster
866 * than the double-loop.
869 ether_crc32_le(const uint8_t *buf
, size_t len
)
871 uint32_t c
, crc
, carry
;
874 crc
= 0xffffffffU
; /* initial value */
876 for (i
= 0; i
< len
; i
++) {
878 for (j
= 0; j
< 8; j
++) {
879 carry
= ((crc
& 0x01) ? 1 : 0) ^ (c
& 0x01);
883 crc
= (crc
^ ETHER_CRC_POLY_LE
);
891 ether_crc32_le(const uint8_t *buf
, size_t len
)
893 static const uint32_t crctab
[] = {
894 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
895 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
896 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
897 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
902 crc
= 0xffffffffU
; /* initial value */
904 for (i
= 0; i
< len
; i
++) {
906 crc
= (crc
>> 4) ^ crctab
[crc
& 0xf];
907 crc
= (crc
>> 4) ^ crctab
[crc
& 0xf];
915 ether_crc32_be(const uint8_t *buf
, size_t len
)
917 uint32_t c
, crc
, carry
;
920 crc
= 0xffffffffU
; /* initial value */
922 for (i
= 0; i
< len
; i
++) {
924 for (j
= 0; j
< 8; j
++) {
925 carry
= ((crc
& 0x80000000U
) ? 1 : 0) ^ (c
& 0x01);
929 crc
= (crc
^ ETHER_CRC_POLY_BE
) | carry
;
937 * find the size of ethernet header, and call classifier
940 altq_etherclassify(struct ifaltq
*ifq
, struct mbuf
*m
,
941 struct altq_pktattr
*pktattr
)
943 struct ether_header
*eh
;
945 int hlen
, af
, hdrsize
;
948 hlen
= sizeof(struct ether_header
);
949 eh
= mtod(m
, struct ether_header
*);
951 ether_type
= ntohs(eh
->ether_type
);
952 if (ether_type
< ETHERMTU
) {
954 struct llc
*llc
= (struct llc
*)(eh
+ 1);
957 if (m
->m_len
< hlen
||
958 llc
->llc_dsap
!= LLC_SNAP_LSAP
||
959 llc
->llc_ssap
!= LLC_SNAP_LSAP
||
960 llc
->llc_control
!= LLC_UI
)
961 goto bad
; /* not snap! */
963 ether_type
= ntohs(llc
->llc_un
.type_snap
.ether_type
);
966 if (ether_type
== ETHERTYPE_IP
) {
968 hdrsize
= 20; /* sizeof(struct ip) */
970 } else if (ether_type
== ETHERTYPE_IPV6
) {
972 hdrsize
= 40; /* sizeof(struct ip6_hdr) */
977 while (m
->m_len
<= hlen
) {
981 hdr
= m
->m_data
+ hlen
;
982 if (m
->m_len
< hlen
+ hdrsize
) {
984 * ip header is not in a single mbuf. this should not
985 * happen in the current code.
986 * (todo: use m_pulldown in the future)
992 ifq_classify(ifq
, m
, af
, pktattr
);
999 pktattr
->pattr_class
= NULL
;
1000 pktattr
->pattr_hdr
= NULL
;
1001 pktattr
->pattr_af
= AF_UNSPEC
;
1005 ether_restore_header(struct mbuf
**m0
, const struct ether_header
*eh
,
1006 const struct ether_header
*save_eh
)
1008 struct mbuf
*m
= *m0
;
1010 ether_restore_hdr
++;
1013 * Prepend the header, optimize for the common case of
1014 * eh pointing into the mbuf.
1016 if ((const void *)(eh
+ 1) == (void *)m
->m_data
) {
1017 m
->m_data
-= ETHER_HDR_LEN
;
1018 m
->m_len
+= ETHER_HDR_LEN
;
1019 m
->m_pkthdr
.len
+= ETHER_HDR_LEN
;
1021 ether_prepend_hdr
++;
1023 M_PREPEND(m
, ETHER_HDR_LEN
, MB_DONTWAIT
);
1025 bcopy(save_eh
, mtod(m
, struct ether_header
*),
1033 ether_input_ipifunc(void *arg
)
1035 struct mbuf
*m
, *next
;
1040 next
= m
->m_nextpkt
;
1041 m
->m_nextpkt
= NULL
;
1043 port
= m
->m_pkthdr
.header
;
1044 m
->m_pkthdr
.header
= NULL
;
1047 &m
->m_hdr
.mh_netmsg
.nm_netmsg
.nm_lmsg
);
1050 } while (m
!= NULL
);
1054 ether_input_dispatch(struct mbuf_chain
*chain
)
1059 logether(disp_beg
, NULL
);
1060 for (i
= 0; i
< ncpus
; ++i
) {
1061 if (chain
[i
].mc_head
!= NULL
) {
1062 lwkt_send_ipiq(globaldata_find(i
),
1063 ether_input_ipifunc
, chain
[i
].mc_head
);
1067 logether(disp_beg
, NULL
);
1068 if (chain
->mc_head
!= NULL
)
1069 ether_input_ipifunc(chain
->mc_head
);
1071 logether(disp_end
, NULL
);
1075 ether_input_chain_init(struct mbuf_chain
*chain
)
1080 for (i
= 0; i
< ncpus
; ++i
)
1081 chain
[i
].mc_head
= chain
[i
].mc_tail
= NULL
;
1083 chain
->mc_head
= chain
->mc_tail
= NULL
;
1088 * Upper layer processing for a received Ethernet packet.
1091 ether_demux_oncpu(struct ifnet
*ifp
, struct mbuf
*m
)
1093 struct ether_header
*eh
;
1094 int isr
, redispatch
, discard
= 0;
1096 struct ip_fw
*rule
= NULL
;
1102 KASSERT(m
->m_len
>= ETHER_HDR_LEN
,
1103 ("ether header is no contiguous!\n"));
1105 eh
= mtod(m
, struct ether_header
*);
1107 if (m
->m_pkthdr
.fw_flags
& DUMMYNET_MBUF_TAGGED
) {
1110 /* Extract info from dummynet tag */
1111 mtag
= m_tag_find(m
, PACKET_TAG_DUMMYNET
, NULL
);
1112 KKASSERT(mtag
!= NULL
);
1113 rule
= ((struct dn_pkt
*)m_tag_data(mtag
))->dn_priv
;
1114 KKASSERT(rule
!= NULL
);
1116 m_tag_delete(m
, mtag
);
1117 m
->m_pkthdr
.fw_flags
&= ~DUMMYNET_MBUF_TAGGED
;
1119 /* packet is passing the second time */
1125 * XXX: Okay, we need to call carp_forus() and - if it is for
1126 * us jump over code that does the normal check
1127 * "ac_enaddr == ether_dhost". The check sequence is a bit
1128 * different from OpenBSD, so we jump over as few code as
1129 * possible, to catch _all_ sanity checks. This needs
1130 * evaluation, to see if the carp ether_dhost values break any
1135 * Hold BGL and recheck ifp->if_carp
1138 if (ifp
->if_carp
&& carp_forus(ifp
->if_carp
, eh
->ether_dhost
)) {
1147 * We got a packet which was unicast to a different Ethernet
1148 * address. If the driver is working properly, then this
1149 * situation can only happen when the interface is in
1150 * promiscuous mode. We defer the packet discarding until the
1151 * vlan processing is done, so that vlan/bridge or vlan/netgraph
1154 if (((ifp
->if_flags
& (IFF_PROMISC
| IFF_PPROMISC
)) == IFF_PROMISC
) &&
1155 !ETHER_IS_MULTICAST(eh
->ether_dhost
) &&
1156 bcmp(eh
->ether_dhost
, IFP2AC(ifp
)->ac_enaddr
, ETHER_ADDR_LEN
))
1160 if (IPFW_LOADED
&& ether_ipfw
!= 0 && !discard
) {
1161 struct ether_header save_eh
= *eh
;
1163 /* XXX old crufty stuff, needs to be removed */
1164 m_adj(m
, sizeof(struct ether_header
));
1166 if (!ether_ipfw_chk(&m
, NULL
, &rule
, eh
)) {
1171 ether_restore_header(&m
, eh
, &save_eh
);
1174 eh
= mtod(m
, struct ether_header
*);
1177 ether_type
= ntohs(eh
->ether_type
);
1178 KKASSERT(ether_type
!= ETHERTYPE_VLAN
);
1180 if (m
->m_flags
& M_VLANTAG
) {
1181 void (*vlan_input_func
)(struct mbuf
*);
1183 vlan_input_func
= vlan_input_p
;
1184 if (vlan_input_func
!= NULL
) {
1187 m
->m_pkthdr
.rcvif
->if_noproto
++;
1194 * If we have been asked to discard this packet
1195 * (e.g. not for us), drop it before entering
1204 * Clear protocol specific flags,
1205 * before entering the upper layer.
1207 m
->m_flags
&= ~M_ETHER_FLAGS
;
1209 /* Strip ethernet header. */
1210 m_adj(m
, sizeof(struct ether_header
));
1213 * By default, we don't need to do the redispatch; for the
1214 * most common packet types, e.g. IPv4, ether_input_chain()
1215 * has already picked up the correct target network msgport.
1219 switch (ether_type
) {
1222 if ((m
->m_flags
& M_LENCHECKED
) == 0) {
1223 if (!ip_lengthcheck(&m
))
1226 if (ipflow_fastforward(m
))
1232 if (ifp
->if_flags
& IFF_NOARP
) {
1233 /* Discard packet if ARP is disabled on interface */
1242 case ETHERTYPE_IPV6
:
1251 * Hold BGL and recheck ef_inputp
1254 if (ef_inputp
&& ef_inputp(ifp
, eh
, m
) == 0) {
1265 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
1273 isr
= NETISR_ATALK1
;
1275 case ETHERTYPE_AARP
:
1281 case ETHERTYPE_MPLS
:
1282 case ETHERTYPE_MPLS_MCAST
:
1283 /* Should have been set by ether_input_chain(). */
1284 KKASSERT(m
->m_flags
& M_MPLSLABELED
);
1291 * The accurate msgport is not determined before
1292 * we reach here, so redo the dispatching
1298 * Hold BGL and recheck ef_inputp
1301 if (ef_inputp
&& ef_inputp(ifp
, eh
, m
) == 0) {
1309 checksum
= mtod(m
, ushort
*);
1311 if ((ether_type
<= ETHERMTU
) &&
1312 ((*checksum
== 0xffff) || (*checksum
== 0xE0E0))) {
1313 if (*checksum
== 0xE0E0) {
1314 m
->m_pkthdr
.len
-= 3;
1323 if (ether_type
> ETHERMTU
)
1325 l
= mtod(m
, struct llc
*);
1326 if (l
->llc_dsap
== LLC_SNAP_LSAP
&&
1327 l
->llc_ssap
== LLC_SNAP_LSAP
&&
1328 l
->llc_control
== LLC_UI
) {
1329 if (bcmp(&(l
->llc_snap_org_code
)[0], at_org_code
,
1330 sizeof at_org_code
) == 0 &&
1331 ntohs(l
->llc_snap_ether_type
) == ETHERTYPE_AT
) {
1332 m_adj(m
, sizeof(struct llc
));
1333 isr
= NETISR_ATALK2
;
1336 if (bcmp(&(l
->llc_snap_org_code
)[0], aarp_org_code
,
1337 sizeof aarp_org_code
) == 0 &&
1338 ntohs(l
->llc_snap_ether_type
) == ETHERTYPE_AARP
) {
1339 m_adj(m
, sizeof(struct llc
));
1346 if (ng_ether_input_orphan_p
!= NULL
) {
1348 * Hold BGL and recheck ng_ether_input_orphan_p
1351 if (ng_ether_input_orphan_p
!= NULL
) {
1352 ng_ether_input_orphan_p(ifp
, m
, eh
);
1365 netisr_dispatch(isr
, m
);
1369 * First we perform any link layer operations, then continue to the
1370 * upper layers with ether_demux_oncpu().
1373 ether_input_oncpu(struct ifnet
*ifp
, struct mbuf
*m
)
1375 if ((ifp
->if_flags
& (IFF_UP
| IFF_MONITOR
)) != IFF_UP
) {
1377 * Receiving interface's flags are changed, when this
1378 * packet is waiting for processing; discard it.
1385 * Tap the packet off here for a bridge. bridge_input()
1386 * will return NULL if it has consumed the packet, otherwise
1387 * it gets processed as normal. Note that bridge_input()
1388 * will always return the original packet if we need to
1389 * process it locally.
1391 if (ifp
->if_bridge
) {
1392 KASSERT(bridge_input_p
!= NULL
,
1393 ("%s: if_bridge not loaded!", __func__
));
1395 if(m
->m_flags
& M_ETHER_BRIDGED
) {
1396 m
->m_flags
&= ~M_ETHER_BRIDGED
;
1398 m
= bridge_input_p(ifp
, m
);
1402 KASSERT(ifp
== m
->m_pkthdr
.rcvif
,
1403 ("bridge_input_p changed rcvif\n"));
1407 /* Handle ng_ether(4) processing, if any */
1408 if (ng_ether_input_p
!= NULL
) {
1410 * Hold BGL and recheck ng_ether_input_p
1413 if (ng_ether_input_p
!= NULL
)
1414 ng_ether_input_p(ifp
, &m
);
1421 /* Continue with upper layer processing */
1422 ether_demux_oncpu(ifp
, m
);
1426 * Perform certain functions of ether_input_chain():
1428 * - Update statistics
1429 * - Run bpf(4) tap if requested
1430 * Then pass the packet to ether_input_oncpu().
1432 * This function should be used by pseudo interface (e.g. vlan(4)),
1433 * when it tries to claim that the packet is received by it.
1436 ether_reinput_oncpu(struct ifnet
*ifp
, struct mbuf
*m
, int run_bpf
)
1438 /* Discard packet if interface is not up */
1439 if (!(ifp
->if_flags
& IFF_UP
)) {
1444 /* Change receiving interface */
1445 m
->m_pkthdr
.rcvif
= ifp
;
1447 /* Update statistics */
1449 ifp
->if_ibytes
+= m
->m_pkthdr
.len
;
1450 if (m
->m_flags
& (M_MCAST
| M_BCAST
))
1456 ether_input_oncpu(ifp
, m
);
1459 static __inline boolean_t
1460 ether_vlancheck(struct mbuf
**m0
)
1462 struct mbuf
*m
= *m0
;
1463 struct ether_header
*eh
;
1464 uint16_t ether_type
;
1466 eh
= mtod(m
, struct ether_header
*);
1467 ether_type
= ntohs(eh
->ether_type
);
1469 if (ether_type
== ETHERTYPE_VLAN
&& (m
->m_flags
& M_VLANTAG
) == 0) {
1471 * Extract vlan tag if hardware does not do it for us
1473 vlan_ether_decap(&m
);
1477 eh
= mtod(m
, struct ether_header
*);
1478 ether_type
= ntohs(eh
->ether_type
);
1481 if (ether_type
== ETHERTYPE_VLAN
&& (m
->m_flags
& M_VLANTAG
)) {
1483 * To prevent possible dangerous recursion,
1484 * we don't do vlan-in-vlan
1486 m
->m_pkthdr
.rcvif
->if_noproto
++;
1489 KKASSERT(ether_type
!= ETHERTYPE_VLAN
);
1491 m
->m_flags
|= M_ETHER_VLANCHECKED
;
1502 ether_input_handler(struct netmsg
*nmsg
)
1504 struct netmsg_packet
*nmp
= (struct netmsg_packet
*)nmsg
;
1505 struct ether_header
*eh
;
1511 ifp
= m
->m_pkthdr
.rcvif
;
1513 eh
= mtod(m
, struct ether_header
*);
1514 if (ETHER_IS_MULTICAST(eh
->ether_dhost
)) {
1515 if (bcmp(ifp
->if_broadcastaddr
, eh
->ether_dhost
,
1516 ifp
->if_addrlen
) == 0)
1517 m
->m_flags
|= M_BCAST
;
1519 m
->m_flags
|= M_MCAST
;
1523 if ((m
->m_flags
& M_ETHER_VLANCHECKED
) == 0) {
1524 if (!ether_vlancheck(&m
)) {
1525 KKASSERT(m
== NULL
);
1530 ether_input_oncpu(ifp
, m
);
1533 static __inline
void
1534 ether_init_netpacket(int num
, struct mbuf
*m
)
1536 struct netmsg_packet
*pmsg
;
1538 pmsg
= &m
->m_hdr
.mh_netmsg
;
1539 netmsg_init(&pmsg
->nm_netmsg
, &netisr_apanic_rport
, MSGF_MPSAFE
,
1540 ether_input_handler
);
1541 pmsg
->nm_packet
= m
;
1542 pmsg
->nm_netmsg
.nm_lmsg
.u
.ms_result
= num
;
1545 static __inline
struct lwkt_port
*
1546 ether_mport(int num
, struct mbuf
**m
)
1548 if (num
== NETISR_MAX
) {
1550 * All packets whose target msgports can't be
1551 * determined here are dispatched to netisr0,
1552 * where further dispatching may happen.
1554 return cpu_portfn(0);
1556 return netisr_find_port(num
, m
);
1560 * Send the packet to the target msgport or
1561 * queue it into 'chain'.
1564 ether_dispatch(int isr
, struct lwkt_port
*port
, struct mbuf
*m
,
1565 struct mbuf_chain
*chain
)
1567 ether_init_netpacket(isr
, m
);
1569 if (chain
!= NULL
) {
1570 struct mbuf_chain
*c
;
1573 m
->m_pkthdr
.header
= port
; /* XXX */
1574 cpuid
= port
->mpu_td
->td_gd
->gd_cpuid
;
1577 if (c
->mc_head
== NULL
) {
1578 c
->mc_head
= c
->mc_tail
= m
;
1580 c
->mc_tail
->m_nextpkt
= m
;
1583 m
->m_nextpkt
= NULL
;
1585 lwkt_sendmsg(port
, &m
->m_hdr
.mh_netmsg
.nm_netmsg
.nm_lmsg
);
1590 * Process a received Ethernet packet.
1592 * The ethernet header is assumed to be in the mbuf so the caller
1593 * MUST MAKE SURE that there are at least sizeof(struct ether_header)
1594 * bytes in the first mbuf.
1596 * We first try to find the target msgport for this ether frame, if
1597 * there is no target msgport for it, this ether frame is discarded,
1598 * else we do following processing according to whether 'chain' is
1600 * - If 'chain' is NULL, this ether frame is sent to the target msgport
1601 * immediately. This situation happens when ether_input_chain is
1602 * accessed through ifnet.if_input.
1603 * - If 'chain' is not NULL, this ether frame is queued to the 'chain'
1604 * bucket indexed by the target msgport's cpuid and the target msgport
1605 * is saved in mbuf's m_pkthdr.m_head. Caller of ether_input_chain
1606 * must initialize 'chain' by calling ether_input_chain_init().
1607 * ether_input_dispatch must be called later to send ether frames
1608 * queued on 'chain' to their target msgport.
1611 ether_input_chain(struct ifnet
*ifp
, struct mbuf
*m
, const struct pktinfo
*pi
,
1612 struct mbuf_chain
*chain
)
1614 struct ether_header
*eh
, *save_eh
, save_eh0
;
1615 struct lwkt_port
*port
;
1616 uint16_t ether_type
;
1621 /* Discard packet if interface is not up */
1622 if (!(ifp
->if_flags
& IFF_UP
)) {
1627 if (m
->m_len
< sizeof(struct ether_header
)) {
1628 /* XXX error in the caller. */
1633 m
->m_pkthdr
.rcvif
= ifp
;
1635 logether(chain_beg
, ifp
);
1637 ETHER_BPF_MTAP(ifp
, m
);
1639 ifp
->if_ibytes
+= m
->m_pkthdr
.len
;
1641 if (ifp
->if_flags
& IFF_MONITOR
) {
1642 eh
= mtod(m
, struct ether_header
*);
1643 if (ETHER_IS_MULTICAST(eh
->ether_dhost
))
1647 * Interface marked for monitoring; discard packet.
1651 logether(chain_end
, ifp
);
1655 if (pi
!= NULL
&& (m
->m_flags
& M_HASH
)) {
1657 ether_pktinfo_try
++;
1659 /* Try finding the port using the packet info */
1660 port
= netisr_find_pktinfo_port(pi
, m
);
1663 ether_pktinfo_hit
++;
1665 ether_dispatch(pi
->pi_netisr
, port
, m
, chain
);
1667 logether(chain_end
, ifp
);
1672 * The packet info does not contain enough
1673 * information, we will have to check the
1678 else if (ifp
->if_capenable
& IFCAP_RSS
) {
1687 * Packet hash will be recalculated by software,
1688 * so clear the M_HASH flag set by the driver;
1689 * the hash value calculated by the hardware may
1690 * not be exactly what we want.
1692 m
->m_flags
&= ~M_HASH
;
1694 if (!ether_vlancheck(&m
)) {
1695 KKASSERT(m
== NULL
);
1696 logether(chain_end
, ifp
);
1699 eh
= mtod(m
, struct ether_header
*);
1700 ether_type
= ntohs(eh
->ether_type
);
1703 * Map ether type to netisr id.
1705 switch (ether_type
) {
1717 case ETHERTYPE_IPV6
:
1729 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
1736 isr
= NETISR_ATALK1
;
1738 case ETHERTYPE_AARP
:
1744 case ETHERTYPE_MPLS
:
1745 case ETHERTYPE_MPLS_MCAST
:
1746 m
->m_flags
|= M_MPLSLABELED
;
1753 * NETISR_MAX is an invalid value; it is chosen to let
1754 * ether_mport() know that we are not able to decide
1755 * this packet's msgport here.
1762 * If the packet is in contiguous memory, following
1763 * m_adj() could ensure that the hidden ether header
1764 * will not be destroyed, else we will have to save
1765 * the ether header for the later restoration.
1767 if (m
->m_pkthdr
.len
!= m
->m_len
) {
1769 save_eh
= &save_eh0
;
1775 * Temporarily remove ether header; ether_mport()
1776 * expects a packet without ether header.
1778 m_adj(m
, sizeof(struct ether_header
));
1781 * Find the packet's target msgport.
1783 port
= ether_mport(isr
, &m
);
1785 KKASSERT(m
== NULL
);
1786 logether(chain_end
, ifp
);
1791 * Restore ether header.
1793 if (save_eh
!= NULL
) {
1794 ether_restore_header(&m
, eh
, save_eh
);
1796 logether(chain_end
, ifp
);
1800 m
->m_data
-= ETHER_HDR_LEN
;
1801 m
->m_len
+= ETHER_HDR_LEN
;
1802 m
->m_pkthdr
.len
+= ETHER_HDR_LEN
;
1805 ether_dispatch(isr
, port
, m
, chain
);
1807 logether(chain_end
, ifp
);