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 #ifdef FIX_SERIALIZE_ASSERT
222 ASSERT_NOT_SERIALIZED(ifp
->if_serializer
);
225 if (ifp
->if_flags
& IFF_MONITOR
)
227 if ((ifp
->if_flags
& (IFF_UP
| IFF_RUNNING
)) != (IFF_UP
| IFF_RUNNING
))
230 M_PREPEND(m
, sizeof(struct ether_header
), MB_DONTWAIT
);
233 eh
= mtod(m
, struct ether_header
*);
234 edst
= eh
->ether_dhost
;
237 * Fill in the destination ethernet address and frame type.
239 switch (dst
->sa_family
) {
242 if (!arpresolve(ifp
, rt
, m
, dst
, edst
))
243 return (0); /* if not yet resolved */
245 if (m
->m_flags
& M_MPLSLABELED
)
246 eh
->ether_type
= htons(ETHERTYPE_MPLS
);
249 eh
->ether_type
= htons(ETHERTYPE_IP
);
254 if (!nd6_storelladdr(&ac
->ac_if
, rt
, m
, dst
, edst
))
255 return (0); /* Something bad happenned. */
256 eh
->ether_type
= htons(ETHERTYPE_IPV6
);
261 if (ef_outputp
!= NULL
) {
263 * Hold BGL and recheck ef_outputp
266 if (ef_outputp
!= NULL
) {
267 error
= ef_outputp(ifp
, &m
, dst
,
268 &eh
->ether_type
, &hlen
);
277 eh
->ether_type
= htons(ETHERTYPE_IPX
);
278 bcopy(&(((struct sockaddr_ipx
*)dst
)->sipx_addr
.x_host
),
279 edst
, ETHER_ADDR_LEN
);
284 struct at_ifaddr
*aa
;
291 if ((aa
= at_ifawithnet((struct sockaddr_at
*)dst
)) == NULL
) {
297 * In the phase 2 case, need to prepend an mbuf for
298 * the llc header. Since we must preserve the value
299 * of m, which is passed to us by value, we m_copy()
300 * the first mbuf, and use it for our llc header.
302 if (aa
->aa_flags
& AFA_PHASE2
) {
305 M_PREPEND(m
, sizeof(struct llc
), MB_DONTWAIT
);
306 eh
= mtod(m
, struct ether_header
*);
307 edst
= eh
->ether_dhost
;
308 llc
.llc_dsap
= llc
.llc_ssap
= LLC_SNAP_LSAP
;
309 llc
.llc_control
= LLC_UI
;
310 bcopy(at_org_code
, llc
.llc_snap_org_code
,
312 llc
.llc_snap_ether_type
= htons(ETHERTYPE_AT
);
314 mtod(m
, caddr_t
) + sizeof(struct ether_header
),
316 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
317 hlen
= sizeof(struct llc
) + ETHER_HDR_LEN
;
319 eh
->ether_type
= htons(ETHERTYPE_AT
);
321 if (!aarpresolve(ac
, m
, (struct sockaddr_at
*)dst
, edst
)) {
334 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
335 eh
->ether_type
= 0x8137;
337 case 0x0: /* Novell 802.3 */
338 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
340 case 0xe0e0: /* Novell 802.2 and Token-Ring */
341 M_PREPEND(m
, 3, MB_DONTWAIT
);
342 eh
= mtod(m
, struct ether_header
*);
343 edst
= eh
->ether_dhost
;
344 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
345 cp
= mtod(m
, u_char
*) + sizeof(struct ether_header
);
351 bcopy(&(((struct sockaddr_ns
*)dst
)->sns_addr
.x_host
), edst
,
354 * XXX if ns_thishost is the same as the node's ethernet
355 * address then just the default code will catch this anyhow.
356 * So I'm not sure if this next clause should be here at all?
359 if (bcmp(edst
, &ns_thishost
, ETHER_ADDR_LEN
) == 0) {
360 m
->m_pkthdr
.rcvif
= ifp
;
361 netisr_dispatch(NETISR_NS
, m
);
364 if (bcmp(edst
, &ns_broadhost
, ETHER_ADDR_LEN
) == 0)
365 m
->m_flags
|= M_BCAST
;
368 case pseudo_AF_HDRCMPLT
:
370 loop_copy
= -1; /* if this is for us, don't do it */
371 deh
= (struct ether_header
*)dst
->sa_data
;
372 memcpy(edst
, deh
->ether_dhost
, ETHER_ADDR_LEN
);
373 eh
->ether_type
= deh
->ether_type
;
377 if_printf(ifp
, "can't handle af%d\n", dst
->sa_family
);
378 gotoerr(EAFNOSUPPORT
);
381 if (dst
->sa_family
== pseudo_AF_HDRCMPLT
) /* unlikely */
382 memcpy(eh
->ether_shost
,
383 ((struct ether_header
*)dst
->sa_data
)->ether_shost
,
386 memcpy(eh
->ether_shost
, ac
->ac_enaddr
, ETHER_ADDR_LEN
);
389 * Bridges require special output handling.
391 if (ifp
->if_bridge
) {
392 KASSERT(bridge_output_p
!= NULL
,
393 ("%s: if_bridge not loaded!", __func__
));
394 return bridge_output_p(ifp
, m
);
398 * If a simplex interface, and the packet is being sent to our
399 * Ethernet address or a broadcast address, loopback a copy.
400 * XXX To make a simplex device behave exactly like a duplex
401 * device, we should copy in the case of sending to our own
402 * ethernet address (thus letting the original actually appear
403 * on the wire). However, we don't do that here for security
404 * reasons and compatibility with the original behavior.
406 if ((ifp
->if_flags
& IFF_SIMPLEX
) && (loop_copy
!= -1)) {
409 if (m
->m_pkthdr
.csum_flags
& CSUM_IP
)
410 csum_flags
|= (CSUM_IP_CHECKED
| CSUM_IP_VALID
);
411 if (m
->m_pkthdr
.csum_flags
& CSUM_DELAY_DATA
)
412 csum_flags
|= (CSUM_DATA_VALID
| CSUM_PSEUDO_HDR
);
413 if ((m
->m_flags
& M_BCAST
) || (loop_copy
> 0)) {
416 if ((n
= m_copypacket(m
, MB_DONTWAIT
)) != NULL
) {
417 n
->m_pkthdr
.csum_flags
|= csum_flags
;
418 if (csum_flags
& CSUM_DATA_VALID
)
419 n
->m_pkthdr
.csum_data
= 0xffff;
420 if_simloop(ifp
, n
, dst
->sa_family
, hlen
);
423 } else if (bcmp(eh
->ether_dhost
, eh
->ether_shost
,
424 ETHER_ADDR_LEN
) == 0) {
425 m
->m_pkthdr
.csum_flags
|= csum_flags
;
426 if (csum_flags
& CSUM_DATA_VALID
)
427 m
->m_pkthdr
.csum_data
= 0xffff;
428 if_simloop(ifp
, m
, dst
->sa_family
, hlen
);
429 return (0); /* XXX */
436 * Hold BGL and recheck ifp->if_carp
439 if (ifp
->if_carp
&& (error
= carp_output(ifp
, m
, dst
, NULL
))) {
448 /* Handle ng_ether(4) processing, if any */
449 if (ng_ether_output_p
!= NULL
) {
451 * Hold BGL and recheck ng_ether_output_p
454 if (ng_ether_output_p
!= NULL
) {
455 if ((error
= ng_ether_output_p(ifp
, &m
)) != 0) {
467 /* Continue with link-layer output */
468 return ether_output_frame(ifp
, m
);
476 * Ethernet link layer output routine to send a raw frame to the device.
478 * This assumes that the 14 byte Ethernet header is present and contiguous
482 ether_output_frame(struct ifnet
*ifp
, struct mbuf
*m
)
484 struct ip_fw
*rule
= NULL
;
486 struct altq_pktattr pktattr
;
488 #ifdef FIX_SERIALIZE_ASSERT
489 ASSERT_NOT_SERIALIZED(ifp
->if_serializer
);
492 if (m
->m_pkthdr
.fw_flags
& DUMMYNET_MBUF_TAGGED
) {
495 /* Extract info from dummynet tag */
496 mtag
= m_tag_find(m
, PACKET_TAG_DUMMYNET
, NULL
);
497 KKASSERT(mtag
!= NULL
);
498 rule
= ((struct dn_pkt
*)m_tag_data(mtag
))->dn_priv
;
499 KKASSERT(rule
!= NULL
);
501 m_tag_delete(m
, mtag
);
502 m
->m_pkthdr
.fw_flags
&= ~DUMMYNET_MBUF_TAGGED
;
505 if (ifq_is_enabled(&ifp
->if_snd
))
506 altq_etherclassify(&ifp
->if_snd
, m
, &pktattr
);
508 if (IPFW_LOADED
&& ether_ipfw
!= 0) {
509 struct ether_header save_eh
, *eh
;
511 eh
= mtod(m
, struct ether_header
*);
513 m_adj(m
, ETHER_HDR_LEN
);
514 if (!ether_ipfw_chk(&m
, ifp
, &rule
, eh
)) {
518 return ENOBUFS
; /* pkt dropped */
520 return 0; /* consumed e.g. in a pipe */
523 /* packet was ok, restore the ethernet header */
524 ether_restore_header(&m
, eh
, &save_eh
);
533 * Queue message on interface, update output statistics if
534 * successful, and start output if interface not yet active.
536 error
= ifq_dispatch(ifp
, m
, &pktattr
);
541 * ipfw processing for ethernet packets (in and out).
542 * The second parameter is NULL from ether_demux(), and ifp from
543 * ether_output_frame().
546 ether_ipfw_chk(struct mbuf
**m0
, struct ifnet
*dst
, struct ip_fw
**rule
,
547 const struct ether_header
*eh
)
549 struct ether_header save_eh
= *eh
; /* might be a ptr in *m0 */
550 struct ip_fw_args args
;
555 if (*rule
!= NULL
&& fw_one_pass
)
556 return TRUE
; /* dummynet packet, already partially processed */
559 * I need some amount of data to be contiguous.
561 i
= min((*m0
)->m_pkthdr
.len
, max_protohdr
);
562 if ((*m0
)->m_len
< i
) {
563 *m0
= m_pullup(*m0
, i
);
571 if ((mtag
= m_tag_find(*m0
, PACKET_TAG_IPFW_DIVERT
, NULL
)) != NULL
)
572 m_tag_delete(*m0
, mtag
);
573 if ((*m0
)->m_pkthdr
.fw_flags
& IPFORWARD_MBUF_TAGGED
) {
574 mtag
= m_tag_find(*m0
, PACKET_TAG_IPFORWARD
, NULL
);
575 KKASSERT(mtag
!= NULL
);
576 m_tag_delete(*m0
, mtag
);
577 (*m0
)->m_pkthdr
.fw_flags
&= ~IPFORWARD_MBUF_TAGGED
;
580 args
.m
= *m0
; /* the packet we are looking at */
581 args
.oif
= dst
; /* destination, if any */
582 args
.rule
= *rule
; /* matching rule to restart */
583 args
.eh
= &save_eh
; /* MAC header for bridged/MAC packets */
584 i
= ip_fw_chk_ptr(&args
);
599 * XXX at some point add support for divert/forward actions.
600 * If none of the above matches, we have to drop the pkt.
606 * Pass the pkt to dummynet, which consumes it.
608 m
= *m0
; /* pass the original to dummynet */
609 *m0
= NULL
; /* and nothing back to the caller */
611 ether_restore_header(&m
, eh
, &save_eh
);
615 ip_fw_dn_io_ptr(m
, args
.cookie
,
616 dst
? DN_TO_ETH_OUT
: DN_TO_ETH_DEMUX
, &args
);
621 panic("unknown ipfw return value: %d\n", i
);
626 ether_input(struct ifnet
*ifp
, struct mbuf
*m
)
628 ether_input_chain(ifp
, m
, NULL
, NULL
);
632 * Perform common duties while attaching to interface list
635 ether_ifattach(struct ifnet
*ifp
, uint8_t *lla
, lwkt_serialize_t serializer
)
637 ether_ifattach_bpf(ifp
, lla
, DLT_EN10MB
, sizeof(struct ether_header
),
642 ether_ifattach_bpf(struct ifnet
*ifp
, uint8_t *lla
, u_int dlt
, u_int hdrlen
,
643 lwkt_serialize_t serializer
)
645 struct sockaddr_dl
*sdl
;
647 ifp
->if_type
= IFT_ETHER
;
648 ifp
->if_addrlen
= ETHER_ADDR_LEN
;
649 ifp
->if_hdrlen
= ETHER_HDR_LEN
;
650 if_attach(ifp
, serializer
);
651 ifp
->if_mtu
= ETHERMTU
;
652 if (ifp
->if_baudrate
== 0)
653 ifp
->if_baudrate
= 10000000;
654 ifp
->if_output
= ether_output
;
655 ifp
->if_input
= ether_input
;
656 ifp
->if_resolvemulti
= ether_resolvemulti
;
657 ifp
->if_broadcastaddr
= etherbroadcastaddr
;
658 sdl
= IF_LLSOCKADDR(ifp
);
659 sdl
->sdl_type
= IFT_ETHER
;
660 sdl
->sdl_alen
= ifp
->if_addrlen
;
661 bcopy(lla
, LLADDR(sdl
), ifp
->if_addrlen
);
663 * XXX Keep the current drivers happy.
664 * XXX Remove once all drivers have been cleaned up
666 if (lla
!= IFP2AC(ifp
)->ac_enaddr
)
667 bcopy(lla
, IFP2AC(ifp
)->ac_enaddr
, ifp
->if_addrlen
);
668 bpfattach(ifp
, dlt
, hdrlen
);
669 if (ng_ether_attach_p
!= NULL
)
670 (*ng_ether_attach_p
)(ifp
);
672 if_printf(ifp
, "MAC address: %6D\n", lla
, ":");
676 * Perform common duties while detaching an Ethernet interface
679 ether_ifdetach(struct ifnet
*ifp
)
683 if (ng_ether_detach_p
!= NULL
)
684 (*ng_ether_detach_p
)(ifp
);
690 ether_ioctl(struct ifnet
*ifp
, int command
, caddr_t data
)
692 struct ifaddr
*ifa
= (struct ifaddr
*) data
;
693 struct ifreq
*ifr
= (struct ifreq
*) data
;
696 #define IF_INIT(ifp) \
698 if (((ifp)->if_flags & IFF_UP) == 0) { \
699 (ifp)->if_flags |= IFF_UP; \
700 (ifp)->if_init((ifp)->if_softc); \
704 #ifdef FIX_SERIALIZE_ASSERT
705 ASSERT_SERIALIZED(ifp
->if_serializer
);
710 switch (ifa
->ifa_addr
->sa_family
) {
713 IF_INIT(ifp
); /* before arpwhohas */
714 arp_ifinit(ifp
, ifa
);
719 * XXX - This code is probably wrong
723 struct ipx_addr
*ina
= &IA_SIPX(ifa
)->sipx_addr
;
724 struct arpcom
*ac
= IFP2AC(ifp
);
726 if (ipx_nullhost(*ina
))
727 ina
->x_host
= *(union ipx_host
*) ac
->ac_enaddr
;
729 bcopy(ina
->x_host
.c_host
, ac
->ac_enaddr
,
730 sizeof ac
->ac_enaddr
);
732 IF_INIT(ifp
); /* Set new address. */
738 * XXX - This code is probably wrong
742 struct ns_addr
*ina
= &(IA_SNS(ifa
)->sns_addr
);
743 struct arpcom
*ac
= IFP2AC(ifp
);
745 if (ns_nullhost(*ina
))
746 ina
->x_host
= *(union ns_host
*)(ac
->ac_enaddr
);
748 bcopy(ina
->x_host
.c_host
, ac
->ac_enaddr
,
749 sizeof ac
->ac_enaddr
);
765 bcopy(IFP2AC(ifp
)->ac_enaddr
,
766 ((struct sockaddr
*)ifr
->ifr_data
)->sa_data
,
772 * Set the interface MTU.
774 if (ifr
->ifr_mtu
> ETHERMTU
) {
777 ifp
->if_mtu
= ifr
->ifr_mtu
;
792 struct sockaddr
**llsa
,
795 struct sockaddr_dl
*sdl
;
796 struct sockaddr_in
*sin
;
798 struct sockaddr_in6
*sin6
;
802 switch(sa
->sa_family
) {
805 * No mapping needed. Just check that it's a valid MC address.
807 sdl
= (struct sockaddr_dl
*)sa
;
808 e_addr
= LLADDR(sdl
);
809 if ((e_addr
[0] & 1) != 1)
810 return EADDRNOTAVAIL
;
816 sin
= (struct sockaddr_in
*)sa
;
817 if (!IN_MULTICAST(ntohl(sin
->sin_addr
.s_addr
)))
818 return EADDRNOTAVAIL
;
819 MALLOC(sdl
, struct sockaddr_dl
*, sizeof *sdl
, M_IFMADDR
,
821 sdl
->sdl_len
= sizeof *sdl
;
822 sdl
->sdl_family
= AF_LINK
;
823 sdl
->sdl_index
= ifp
->if_index
;
824 sdl
->sdl_type
= IFT_ETHER
;
825 sdl
->sdl_alen
= ETHER_ADDR_LEN
;
826 e_addr
= LLADDR(sdl
);
827 ETHER_MAP_IP_MULTICAST(&sin
->sin_addr
, e_addr
);
828 *llsa
= (struct sockaddr
*)sdl
;
833 sin6
= (struct sockaddr_in6
*)sa
;
834 if (IN6_IS_ADDR_UNSPECIFIED(&sin6
->sin6_addr
)) {
836 * An IP6 address of 0 means listen to all
837 * of the Ethernet multicast address used for IP6.
838 * (This is used for multicast routers.)
840 ifp
->if_flags
|= IFF_ALLMULTI
;
844 if (!IN6_IS_ADDR_MULTICAST(&sin6
->sin6_addr
))
845 return EADDRNOTAVAIL
;
846 MALLOC(sdl
, struct sockaddr_dl
*, sizeof *sdl
, M_IFMADDR
,
848 sdl
->sdl_len
= sizeof *sdl
;
849 sdl
->sdl_family
= AF_LINK
;
850 sdl
->sdl_index
= ifp
->if_index
;
851 sdl
->sdl_type
= IFT_ETHER
;
852 sdl
->sdl_alen
= ETHER_ADDR_LEN
;
853 e_addr
= LLADDR(sdl
);
854 ETHER_MAP_IPV6_MULTICAST(&sin6
->sin6_addr
, e_addr
);
855 *llsa
= (struct sockaddr
*)sdl
;
861 * Well, the text isn't quite right, but it's the name
870 * This is for reference. We have a table-driven version
871 * of the little-endian crc32 generator, which is faster
872 * than the double-loop.
875 ether_crc32_le(const uint8_t *buf
, size_t len
)
877 uint32_t c
, crc
, carry
;
880 crc
= 0xffffffffU
; /* initial value */
882 for (i
= 0; i
< len
; i
++) {
884 for (j
= 0; j
< 8; j
++) {
885 carry
= ((crc
& 0x01) ? 1 : 0) ^ (c
& 0x01);
889 crc
= (crc
^ ETHER_CRC_POLY_LE
);
897 ether_crc32_le(const uint8_t *buf
, size_t len
)
899 static const uint32_t crctab
[] = {
900 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
901 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
902 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
903 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
908 crc
= 0xffffffffU
; /* initial value */
910 for (i
= 0; i
< len
; i
++) {
912 crc
= (crc
>> 4) ^ crctab
[crc
& 0xf];
913 crc
= (crc
>> 4) ^ crctab
[crc
& 0xf];
921 ether_crc32_be(const uint8_t *buf
, size_t len
)
923 uint32_t c
, crc
, carry
;
926 crc
= 0xffffffffU
; /* initial value */
928 for (i
= 0; i
< len
; i
++) {
930 for (j
= 0; j
< 8; j
++) {
931 carry
= ((crc
& 0x80000000U
) ? 1 : 0) ^ (c
& 0x01);
935 crc
= (crc
^ ETHER_CRC_POLY_BE
) | carry
;
943 * find the size of ethernet header, and call classifier
946 altq_etherclassify(struct ifaltq
*ifq
, struct mbuf
*m
,
947 struct altq_pktattr
*pktattr
)
949 struct ether_header
*eh
;
951 int hlen
, af
, hdrsize
;
954 hlen
= sizeof(struct ether_header
);
955 eh
= mtod(m
, struct ether_header
*);
957 ether_type
= ntohs(eh
->ether_type
);
958 if (ether_type
< ETHERMTU
) {
960 struct llc
*llc
= (struct llc
*)(eh
+ 1);
963 if (m
->m_len
< hlen
||
964 llc
->llc_dsap
!= LLC_SNAP_LSAP
||
965 llc
->llc_ssap
!= LLC_SNAP_LSAP
||
966 llc
->llc_control
!= LLC_UI
)
967 goto bad
; /* not snap! */
969 ether_type
= ntohs(llc
->llc_un
.type_snap
.ether_type
);
972 if (ether_type
== ETHERTYPE_IP
) {
974 hdrsize
= 20; /* sizeof(struct ip) */
976 } else if (ether_type
== ETHERTYPE_IPV6
) {
978 hdrsize
= 40; /* sizeof(struct ip6_hdr) */
983 while (m
->m_len
<= hlen
) {
987 hdr
= m
->m_data
+ hlen
;
988 if (m
->m_len
< hlen
+ hdrsize
) {
990 * ip header is not in a single mbuf. this should not
991 * happen in the current code.
992 * (todo: use m_pulldown in the future)
998 ifq_classify(ifq
, m
, af
, pktattr
);
1005 pktattr
->pattr_class
= NULL
;
1006 pktattr
->pattr_hdr
= NULL
;
1007 pktattr
->pattr_af
= AF_UNSPEC
;
1011 ether_restore_header(struct mbuf
**m0
, const struct ether_header
*eh
,
1012 const struct ether_header
*save_eh
)
1014 struct mbuf
*m
= *m0
;
1016 ether_restore_hdr
++;
1019 * Prepend the header, optimize for the common case of
1020 * eh pointing into the mbuf.
1022 if ((const void *)(eh
+ 1) == (void *)m
->m_data
) {
1023 m
->m_data
-= ETHER_HDR_LEN
;
1024 m
->m_len
+= ETHER_HDR_LEN
;
1025 m
->m_pkthdr
.len
+= ETHER_HDR_LEN
;
1027 ether_prepend_hdr
++;
1029 M_PREPEND(m
, ETHER_HDR_LEN
, MB_DONTWAIT
);
1031 bcopy(save_eh
, mtod(m
, struct ether_header
*),
1039 ether_input_ipifunc(void *arg
)
1041 struct mbuf
*m
, *next
;
1046 next
= m
->m_nextpkt
;
1047 m
->m_nextpkt
= NULL
;
1049 port
= m
->m_pkthdr
.header
;
1050 m
->m_pkthdr
.header
= NULL
;
1053 &m
->m_hdr
.mh_netmsg
.nm_netmsg
.nm_lmsg
);
1056 } while (m
!= NULL
);
1060 ether_input_dispatch(struct mbuf_chain
*chain
)
1065 logether(disp_beg
, NULL
);
1066 for (i
= 0; i
< ncpus
; ++i
) {
1067 if (chain
[i
].mc_head
!= NULL
) {
1068 lwkt_send_ipiq(globaldata_find(i
),
1069 ether_input_ipifunc
, chain
[i
].mc_head
);
1073 logether(disp_beg
, NULL
);
1074 if (chain
->mc_head
!= NULL
)
1075 ether_input_ipifunc(chain
->mc_head
);
1077 logether(disp_end
, NULL
);
1081 ether_input_chain_init(struct mbuf_chain
*chain
)
1086 for (i
= 0; i
< ncpus
; ++i
)
1087 chain
[i
].mc_head
= chain
[i
].mc_tail
= NULL
;
1089 chain
->mc_head
= chain
->mc_tail
= NULL
;
1094 * Upper layer processing for a received Ethernet packet.
1097 ether_demux_oncpu(struct ifnet
*ifp
, struct mbuf
*m
)
1099 struct ether_header
*eh
;
1100 int isr
, redispatch
, discard
= 0;
1102 struct ip_fw
*rule
= NULL
;
1108 KASSERT(m
->m_len
>= ETHER_HDR_LEN
,
1109 ("ether header is no contiguous!\n"));
1111 eh
= mtod(m
, struct ether_header
*);
1113 if (m
->m_pkthdr
.fw_flags
& DUMMYNET_MBUF_TAGGED
) {
1116 /* Extract info from dummynet tag */
1117 mtag
= m_tag_find(m
, PACKET_TAG_DUMMYNET
, NULL
);
1118 KKASSERT(mtag
!= NULL
);
1119 rule
= ((struct dn_pkt
*)m_tag_data(mtag
))->dn_priv
;
1120 KKASSERT(rule
!= NULL
);
1122 m_tag_delete(m
, mtag
);
1123 m
->m_pkthdr
.fw_flags
&= ~DUMMYNET_MBUF_TAGGED
;
1125 /* packet is passing the second time */
1131 * XXX: Okay, we need to call carp_forus() and - if it is for
1132 * us jump over code that does the normal check
1133 * "ac_enaddr == ether_dhost". The check sequence is a bit
1134 * different from OpenBSD, so we jump over as few code as
1135 * possible, to catch _all_ sanity checks. This needs
1136 * evaluation, to see if the carp ether_dhost values break any
1141 * Hold BGL and recheck ifp->if_carp
1144 if (ifp
->if_carp
&& carp_forus(ifp
->if_carp
, eh
->ether_dhost
)) {
1153 * We got a packet which was unicast to a different Ethernet
1154 * address. If the driver is working properly, then this
1155 * situation can only happen when the interface is in
1156 * promiscuous mode. We defer the packet discarding until the
1157 * vlan processing is done, so that vlan/bridge or vlan/netgraph
1160 if (((ifp
->if_flags
& (IFF_PROMISC
| IFF_PPROMISC
)) == IFF_PROMISC
) &&
1161 !ETHER_IS_MULTICAST(eh
->ether_dhost
) &&
1162 bcmp(eh
->ether_dhost
, IFP2AC(ifp
)->ac_enaddr
, ETHER_ADDR_LEN
))
1166 if (IPFW_LOADED
&& ether_ipfw
!= 0 && !discard
) {
1167 struct ether_header save_eh
= *eh
;
1169 /* XXX old crufty stuff, needs to be removed */
1170 m_adj(m
, sizeof(struct ether_header
));
1172 if (!ether_ipfw_chk(&m
, NULL
, &rule
, eh
)) {
1177 ether_restore_header(&m
, eh
, &save_eh
);
1180 eh
= mtod(m
, struct ether_header
*);
1183 ether_type
= ntohs(eh
->ether_type
);
1184 KKASSERT(ether_type
!= ETHERTYPE_VLAN
);
1186 if (m
->m_flags
& M_VLANTAG
) {
1187 void (*vlan_input_func
)(struct mbuf
*);
1189 vlan_input_func
= vlan_input_p
;
1190 if (vlan_input_func
!= NULL
) {
1193 m
->m_pkthdr
.rcvif
->if_noproto
++;
1200 * If we have been asked to discard this packet
1201 * (e.g. not for us), drop it before entering
1210 * Clear protocol specific flags,
1211 * before entering the upper layer.
1213 m
->m_flags
&= ~M_ETHER_FLAGS
;
1215 /* Strip ethernet header. */
1216 m_adj(m
, sizeof(struct ether_header
));
1219 * By default, we don't need to do the redispatch; for the
1220 * most common packet types, e.g. IPv4, ether_input_chain()
1221 * has already picked up the correct target network msgport.
1225 switch (ether_type
) {
1228 if ((m
->m_flags
& M_LENCHECKED
) == 0) {
1229 if (!ip_lengthcheck(&m
))
1232 if (ipflow_fastforward(m
))
1238 if (ifp
->if_flags
& IFF_NOARP
) {
1239 /* Discard packet if ARP is disabled on interface */
1248 case ETHERTYPE_IPV6
:
1257 * Hold BGL and recheck ef_inputp
1260 if (ef_inputp
&& ef_inputp(ifp
, eh
, m
) == 0) {
1271 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
1279 isr
= NETISR_ATALK1
;
1281 case ETHERTYPE_AARP
:
1287 case ETHERTYPE_MPLS
:
1288 case ETHERTYPE_MPLS_MCAST
:
1289 /* Should have been set by ether_input_chain(). */
1290 KKASSERT(m
->m_flags
& M_MPLSLABELED
);
1297 * The accurate msgport is not determined before
1298 * we reach here, so redo the dispatching
1304 * Hold BGL and recheck ef_inputp
1307 if (ef_inputp
&& ef_inputp(ifp
, eh
, m
) == 0) {
1315 checksum
= mtod(m
, ushort
*);
1317 if ((ether_type
<= ETHERMTU
) &&
1318 ((*checksum
== 0xffff) || (*checksum
== 0xE0E0))) {
1319 if (*checksum
== 0xE0E0) {
1320 m
->m_pkthdr
.len
-= 3;
1329 if (ether_type
> ETHERMTU
)
1331 l
= mtod(m
, struct llc
*);
1332 if (l
->llc_dsap
== LLC_SNAP_LSAP
&&
1333 l
->llc_ssap
== LLC_SNAP_LSAP
&&
1334 l
->llc_control
== LLC_UI
) {
1335 if (bcmp(&(l
->llc_snap_org_code
)[0], at_org_code
,
1336 sizeof at_org_code
) == 0 &&
1337 ntohs(l
->llc_snap_ether_type
) == ETHERTYPE_AT
) {
1338 m_adj(m
, sizeof(struct llc
));
1339 isr
= NETISR_ATALK2
;
1342 if (bcmp(&(l
->llc_snap_org_code
)[0], aarp_org_code
,
1343 sizeof aarp_org_code
) == 0 &&
1344 ntohs(l
->llc_snap_ether_type
) == ETHERTYPE_AARP
) {
1345 m_adj(m
, sizeof(struct llc
));
1352 if (ng_ether_input_orphan_p
!= NULL
) {
1354 * Hold BGL and recheck ng_ether_input_orphan_p
1357 if (ng_ether_input_orphan_p
!= NULL
) {
1358 ng_ether_input_orphan_p(ifp
, m
, eh
);
1371 netisr_dispatch(isr
, m
);
1375 * First we perform any link layer operations, then continue to the
1376 * upper layers with ether_demux_oncpu().
1379 ether_input_oncpu(struct ifnet
*ifp
, struct mbuf
*m
)
1381 if ((ifp
->if_flags
& (IFF_UP
| IFF_MONITOR
)) != IFF_UP
) {
1383 * Receiving interface's flags are changed, when this
1384 * packet is waiting for processing; discard it.
1391 * Tap the packet off here for a bridge. bridge_input()
1392 * will return NULL if it has consumed the packet, otherwise
1393 * it gets processed as normal. Note that bridge_input()
1394 * will always return the original packet if we need to
1395 * process it locally.
1397 if (ifp
->if_bridge
) {
1398 KASSERT(bridge_input_p
!= NULL
,
1399 ("%s: if_bridge not loaded!", __func__
));
1401 if(m
->m_flags
& M_ETHER_BRIDGED
) {
1402 m
->m_flags
&= ~M_ETHER_BRIDGED
;
1404 m
= bridge_input_p(ifp
, m
);
1408 KASSERT(ifp
== m
->m_pkthdr
.rcvif
,
1409 ("bridge_input_p changed rcvif\n"));
1413 /* Handle ng_ether(4) processing, if any */
1414 if (ng_ether_input_p
!= NULL
) {
1416 * Hold BGL and recheck ng_ether_input_p
1419 if (ng_ether_input_p
!= NULL
)
1420 ng_ether_input_p(ifp
, &m
);
1427 /* Continue with upper layer processing */
1428 ether_demux_oncpu(ifp
, m
);
1432 * Perform certain functions of ether_input_chain():
1434 * - Update statistics
1435 * - Run bpf(4) tap if requested
1436 * Then pass the packet to ether_input_oncpu().
1438 * This function should be used by pseudo interface (e.g. vlan(4)),
1439 * when it tries to claim that the packet is received by it.
1442 ether_reinput_oncpu(struct ifnet
*ifp
, struct mbuf
*m
, int run_bpf
)
1444 /* Discard packet if interface is not up */
1445 if (!(ifp
->if_flags
& IFF_UP
)) {
1450 /* Change receiving interface */
1451 m
->m_pkthdr
.rcvif
= ifp
;
1453 /* Update statistics */
1455 ifp
->if_ibytes
+= m
->m_pkthdr
.len
;
1456 if (m
->m_flags
& (M_MCAST
| M_BCAST
))
1462 ether_input_oncpu(ifp
, m
);
1465 static __inline boolean_t
1466 ether_vlancheck(struct mbuf
**m0
)
1468 struct mbuf
*m
= *m0
;
1469 struct ether_header
*eh
;
1470 uint16_t ether_type
;
1472 eh
= mtod(m
, struct ether_header
*);
1473 ether_type
= ntohs(eh
->ether_type
);
1475 if (ether_type
== ETHERTYPE_VLAN
&& (m
->m_flags
& M_VLANTAG
) == 0) {
1477 * Extract vlan tag if hardware does not do it for us
1479 vlan_ether_decap(&m
);
1483 eh
= mtod(m
, struct ether_header
*);
1484 ether_type
= ntohs(eh
->ether_type
);
1487 if (ether_type
== ETHERTYPE_VLAN
&& (m
->m_flags
& M_VLANTAG
)) {
1489 * To prevent possible dangerous recursion,
1490 * we don't do vlan-in-vlan
1492 m
->m_pkthdr
.rcvif
->if_noproto
++;
1495 KKASSERT(ether_type
!= ETHERTYPE_VLAN
);
1497 m
->m_flags
|= M_ETHER_VLANCHECKED
;
1508 ether_input_handler(struct netmsg
*nmsg
)
1510 struct netmsg_packet
*nmp
= (struct netmsg_packet
*)nmsg
;
1511 struct ether_header
*eh
;
1517 ifp
= m
->m_pkthdr
.rcvif
;
1519 eh
= mtod(m
, struct ether_header
*);
1520 if (ETHER_IS_MULTICAST(eh
->ether_dhost
)) {
1521 if (bcmp(ifp
->if_broadcastaddr
, eh
->ether_dhost
,
1522 ifp
->if_addrlen
) == 0)
1523 m
->m_flags
|= M_BCAST
;
1525 m
->m_flags
|= M_MCAST
;
1529 if ((m
->m_flags
& M_ETHER_VLANCHECKED
) == 0) {
1530 if (!ether_vlancheck(&m
)) {
1531 KKASSERT(m
== NULL
);
1536 ether_input_oncpu(ifp
, m
);
1539 static __inline
void
1540 ether_init_netpacket(int num
, struct mbuf
*m
)
1542 struct netmsg_packet
*pmsg
;
1544 pmsg
= &m
->m_hdr
.mh_netmsg
;
1545 netmsg_init(&pmsg
->nm_netmsg
, &netisr_apanic_rport
, MSGF_MPSAFE
,
1546 ether_input_handler
);
1547 pmsg
->nm_packet
= m
;
1548 pmsg
->nm_netmsg
.nm_lmsg
.u
.ms_result
= num
;
1551 static __inline
struct lwkt_port
*
1552 ether_mport(int num
, struct mbuf
**m
)
1554 if (num
== NETISR_MAX
) {
1556 * All packets whose target msgports can't be
1557 * determined here are dispatched to netisr0,
1558 * where further dispatching may happen.
1560 return cpu_portfn(0);
1562 return netisr_find_port(num
, m
);
1566 * Send the packet to the target msgport or
1567 * queue it into 'chain'.
1570 ether_dispatch(int isr
, struct lwkt_port
*port
, struct mbuf
*m
,
1571 struct mbuf_chain
*chain
)
1573 ether_init_netpacket(isr
, m
);
1575 if (chain
!= NULL
) {
1576 struct mbuf_chain
*c
;
1579 m
->m_pkthdr
.header
= port
; /* XXX */
1580 cpuid
= port
->mpu_td
->td_gd
->gd_cpuid
;
1583 if (c
->mc_head
== NULL
) {
1584 c
->mc_head
= c
->mc_tail
= m
;
1586 c
->mc_tail
->m_nextpkt
= m
;
1589 m
->m_nextpkt
= NULL
;
1591 lwkt_sendmsg(port
, &m
->m_hdr
.mh_netmsg
.nm_netmsg
.nm_lmsg
);
1596 * Process a received Ethernet packet.
1598 * The ethernet header is assumed to be in the mbuf so the caller
1599 * MUST MAKE SURE that there are at least sizeof(struct ether_header)
1600 * bytes in the first mbuf.
1602 * We first try to find the target msgport for this ether frame, if
1603 * there is no target msgport for it, this ether frame is discarded,
1604 * else we do following processing according to whether 'chain' is
1606 * - If 'chain' is NULL, this ether frame is sent to the target msgport
1607 * immediately. This situation happens when ether_input_chain is
1608 * accessed through ifnet.if_input.
1609 * - If 'chain' is not NULL, this ether frame is queued to the 'chain'
1610 * bucket indexed by the target msgport's cpuid and the target msgport
1611 * is saved in mbuf's m_pkthdr.m_head. Caller of ether_input_chain
1612 * must initialize 'chain' by calling ether_input_chain_init().
1613 * ether_input_dispatch must be called later to send ether frames
1614 * queued on 'chain' to their target msgport.
1617 ether_input_chain(struct ifnet
*ifp
, struct mbuf
*m
, const struct pktinfo
*pi
,
1618 struct mbuf_chain
*chain
)
1620 struct ether_header
*eh
, *save_eh
, save_eh0
;
1621 struct lwkt_port
*port
;
1622 uint16_t ether_type
;
1625 #ifdef FIX_SERIALIZE_ASSERT
1626 ASSERT_SERIALIZED(ifp
->if_serializer
);
1630 /* Discard packet if interface is not up */
1631 if (!(ifp
->if_flags
& IFF_UP
)) {
1636 if (m
->m_len
< sizeof(struct ether_header
)) {
1637 /* XXX error in the caller. */
1642 m
->m_pkthdr
.rcvif
= ifp
;
1644 logether(chain_beg
, ifp
);
1646 ETHER_BPF_MTAP(ifp
, m
);
1648 ifp
->if_ibytes
+= m
->m_pkthdr
.len
;
1650 if (ifp
->if_flags
& IFF_MONITOR
) {
1651 eh
= mtod(m
, struct ether_header
*);
1652 if (ETHER_IS_MULTICAST(eh
->ether_dhost
))
1656 * Interface marked for monitoring; discard packet.
1660 logether(chain_end
, ifp
);
1664 if (pi
!= NULL
&& (m
->m_flags
& M_HASH
)) {
1666 ether_pktinfo_try
++;
1668 /* Try finding the port using the packet info */
1669 port
= netisr_find_pktinfo_port(pi
, m
);
1672 ether_pktinfo_hit
++;
1674 ether_dispatch(pi
->pi_netisr
, port
, m
, chain
);
1676 logether(chain_end
, ifp
);
1681 * The packet info does not contain enough
1682 * information, we will have to check the
1687 else if (ifp
->if_capenable
& IFCAP_RSS
) {
1696 * Packet hash will be recalculated by software,
1697 * so clear the M_HASH flag set by the driver;
1698 * the hash value calculated by the hardware may
1699 * not be exactly what we want.
1701 m
->m_flags
&= ~M_HASH
;
1703 if (!ether_vlancheck(&m
)) {
1704 KKASSERT(m
== NULL
);
1705 logether(chain_end
, ifp
);
1708 eh
= mtod(m
, struct ether_header
*);
1709 ether_type
= ntohs(eh
->ether_type
);
1712 * Map ether type to netisr id.
1714 switch (ether_type
) {
1726 case ETHERTYPE_IPV6
:
1738 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
1745 isr
= NETISR_ATALK1
;
1747 case ETHERTYPE_AARP
:
1753 case ETHERTYPE_MPLS
:
1754 case ETHERTYPE_MPLS_MCAST
:
1755 m
->m_flags
|= M_MPLSLABELED
;
1762 * NETISR_MAX is an invalid value; it is chosen to let
1763 * ether_mport() know that we are not able to decide
1764 * this packet's msgport here.
1771 * If the packet is in contiguous memory, following
1772 * m_adj() could ensure that the hidden ether header
1773 * will not be destroyed, else we will have to save
1774 * the ether header for the later restoration.
1776 if (m
->m_pkthdr
.len
!= m
->m_len
) {
1778 save_eh
= &save_eh0
;
1784 * Temporarily remove ether header; ether_mport()
1785 * expects a packet without ether header.
1787 m_adj(m
, sizeof(struct ether_header
));
1790 * Find the packet's target msgport.
1792 port
= ether_mport(isr
, &m
);
1794 KKASSERT(m
== NULL
);
1795 logether(chain_end
, ifp
);
1800 * Restore ether header.
1802 if (save_eh
!= NULL
) {
1803 ether_restore_header(&m
, eh
, save_eh
);
1805 logether(chain_end
, ifp
);
1809 m
->m_data
-= ETHER_HDR_LEN
;
1810 m
->m_len
+= ETHER_HDR_LEN
;
1811 m
->m_pkthdr
.len
+= ETHER_HDR_LEN
;
1814 ether_dispatch(isr
, port
, m
, chain
);
1816 logether(chain_end
, ifp
);