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.76 2008/07/08 13:50:52 sephe Exp $
38 #include "opt_atalk.h"
40 #include "opt_inet6.h"
43 #include "opt_netgraph.h"
45 #include "opt_ethernet.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/globaldata.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
53 #include <sys/msgport.h>
54 #include <sys/socket.h>
55 #include <sys/sockio.h>
56 #include <sys/sysctl.h>
57 #include <sys/thread.h>
58 #include <sys/thread2.h>
61 #include <net/netisr.h>
62 #include <net/route.h>
63 #include <net/if_llc.h>
64 #include <net/if_dl.h>
65 #include <net/if_types.h>
66 #include <net/ifq_var.h>
68 #include <net/ethernet.h>
69 #include <net/vlan/if_vlan_ether.h>
70 #include <net/netmsg2.h>
72 #if defined(INET) || defined(INET6)
73 #include <netinet/in.h>
74 #include <netinet/in_var.h>
75 #include <netinet/if_ether.h>
76 #include <net/ipfw/ip_fw.h>
77 #include <net/dummynet/ip_dummynet.h>
80 #include <netinet6/nd6.h>
84 #include <netinet/ip_carp.h>
88 #include <netproto/ipx/ipx.h>
89 #include <netproto/ipx/ipx_if.h>
90 int (*ef_inputp
)(struct ifnet
*, const struct ether_header
*eh
, struct mbuf
*m
);
91 int (*ef_outputp
)(struct ifnet
*ifp
, struct mbuf
**mp
, struct sockaddr
*dst
,
92 short *tp
, int *hlen
);
97 #include <netns/ns_if.h>
99 int ether_outputdebug
= 0;
100 int ether_inputdebug
= 0;
104 #include <netproto/atalk/at.h>
105 #include <netproto/atalk/at_var.h>
106 #include <netproto/atalk/at_extern.h>
108 #define llc_snap_org_code llc_un.type_snap.org_code
109 #define llc_snap_ether_type llc_un.type_snap.ether_type
111 extern u_char at_org_code
[3];
112 extern u_char aarp_org_code
[3];
113 #endif /* NETATALK */
116 #include <netproto/mpls/mpls.h>
119 /* netgraph node hooks for ng_ether(4) */
120 void (*ng_ether_input_p
)(struct ifnet
*ifp
, struct mbuf
**mp
);
121 void (*ng_ether_input_orphan_p
)(struct ifnet
*ifp
,
122 struct mbuf
*m
, const struct ether_header
*eh
);
123 int (*ng_ether_output_p
)(struct ifnet
*ifp
, struct mbuf
**mp
);
124 void (*ng_ether_attach_p
)(struct ifnet
*ifp
);
125 void (*ng_ether_detach_p
)(struct ifnet
*ifp
);
127 int (*vlan_input_p
)(struct mbuf
*, struct mbuf_chain
*);
128 void (*vlan_input2_p
)(struct mbuf
*);
130 static int ether_output(struct ifnet
*, struct mbuf
*, struct sockaddr
*,
132 static void ether_restore_header(struct mbuf
**, const struct ether_header
*,
133 const struct ether_header
*);
134 static void ether_demux_chain(struct ifnet
*, struct mbuf
*,
135 struct mbuf_chain
*);
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
;
162 SYSCTL_DECL(_net_link
);
163 SYSCTL_NODE(_net_link
, IFT_ETHER
, ether
, CTLFLAG_RW
, 0, "Ethernet");
164 SYSCTL_INT(_net_link_ether
, OID_AUTO
, ipfw
, CTLFLAG_RW
,
165 ðer_ipfw
, 0, "Pass ether pkts through firewall");
166 SYSCTL_UINT(_net_link_ether
, OID_AUTO
, restore_hdr
, CTLFLAG_RW
,
167 ðer_restore_hdr
, 0, "# of ether header restoration");
168 SYSCTL_UINT(_net_link_ether
, OID_AUTO
, prepend_hdr
, CTLFLAG_RW
,
169 ðer_prepend_hdr
, 0,
170 "# of ether header restoration which prepends mbuf");
173 * Ethernet output routine.
174 * Encapsulate a packet of type family for the local net.
175 * Use trailer local net encapsulation if enough data in first
176 * packet leaves a multiple of 512 bytes of data in remainder.
177 * Assumes that ifp is actually pointer to arpcom structure.
180 ether_output(struct ifnet
*ifp
, struct mbuf
*m
, struct sockaddr
*dst
,
183 struct ether_header
*eh
, *deh
;
186 int hlen
= ETHER_HDR_LEN
; /* link layer header length */
187 struct arpcom
*ac
= IFP2AC(ifp
);
190 ASSERT_NOT_SERIALIZED(ifp
->if_serializer
);
192 if (ifp
->if_flags
& IFF_MONITOR
)
194 if ((ifp
->if_flags
& (IFF_UP
| IFF_RUNNING
)) != (IFF_UP
| IFF_RUNNING
))
197 M_PREPEND(m
, sizeof(struct ether_header
), MB_DONTWAIT
);
200 eh
= mtod(m
, struct ether_header
*);
201 edst
= eh
->ether_dhost
;
204 * Fill in the destination ethernet address and frame type.
206 switch (dst
->sa_family
) {
209 if (!arpresolve(ifp
, rt
, m
, dst
, edst
))
210 return (0); /* if not yet resolved */
211 eh
->ether_type
= htons(ETHERTYPE_IP
);
216 if (!nd6_storelladdr(&ac
->ac_if
, rt
, m
, dst
, edst
))
217 return (0); /* Something bad happenned. */
218 eh
->ether_type
= htons(ETHERTYPE_IPV6
);
223 if (ef_outputp
!= NULL
) {
224 error
= ef_outputp(ifp
, &m
, dst
, &eh
->ether_type
,
229 eh
->ether_type
= htons(ETHERTYPE_IPX
);
230 bcopy(&(((struct sockaddr_ipx
*)dst
)->sipx_addr
.x_host
),
231 edst
, ETHER_ADDR_LEN
);
237 struct at_ifaddr
*aa
;
239 if ((aa
= at_ifawithnet((struct sockaddr_at
*)dst
)) == NULL
) {
244 * In the phase 2 case, need to prepend an mbuf for
245 * the llc header. Since we must preserve the value
246 * of m, which is passed to us by value, we m_copy()
247 * the first mbuf, and use it for our llc header.
249 if (aa
->aa_flags
& AFA_PHASE2
) {
252 M_PREPEND(m
, sizeof(struct llc
), MB_DONTWAIT
);
253 eh
= mtod(m
, struct ether_header
*);
254 edst
= eh
->ether_dhost
;
255 llc
.llc_dsap
= llc
.llc_ssap
= LLC_SNAP_LSAP
;
256 llc
.llc_control
= LLC_UI
;
257 bcopy(at_org_code
, llc
.llc_snap_org_code
,
259 llc
.llc_snap_ether_type
= htons(ETHERTYPE_AT
);
261 mtod(m
, caddr_t
) + sizeof(struct ether_header
),
263 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
264 hlen
= sizeof(struct llc
) + ETHER_HDR_LEN
;
266 eh
->ether_type
= htons(ETHERTYPE_AT
);
268 if (!aarpresolve(ac
, m
, (struct sockaddr_at
*)dst
, edst
))
277 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
278 eh
->ether_type
= 0x8137;
280 case 0x0: /* Novell 802.3 */
281 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
283 case 0xe0e0: /* Novell 802.2 and Token-Ring */
284 M_PREPEND(m
, 3, MB_DONTWAIT
);
285 eh
= mtod(m
, struct ether_header
*);
286 edst
= eh
->ether_dhost
;
287 eh
->ether_type
= htons(m
->m_pkthdr
.len
);
288 cp
= mtod(m
, u_char
*) + sizeof(struct ether_header
);
294 bcopy(&(((struct sockaddr_ns
*)dst
)->sns_addr
.x_host
), edst
,
297 * XXX if ns_thishost is the same as the node's ethernet
298 * address then just the default code will catch this anyhow.
299 * So I'm not sure if this next clause should be here at all?
302 if (bcmp(edst
, &ns_thishost
, ETHER_ADDR_LEN
) == 0) {
303 m
->m_pkthdr
.rcvif
= ifp
;
304 netisr_dispatch(NETISR_NS
, m
);
307 if (bcmp(edst
, &ns_broadhost
, ETHER_ADDR_LEN
) == 0)
308 m
->m_flags
|= M_BCAST
;
314 struct sockaddr
*sa_gw
;
317 sa_gw
= (struct sockaddr
*)rt
->rt_gateway
;
319 /* We realy need a gateway. */
324 switch (sa_gw
->sa_family
) {
326 if (!arpresolve(ifp
, rt
, m
, sa_gw
, edst
))
330 kprintf("ether_output: address family not supported to forward mpls packets: %d.\n", sa_gw
->sa_family
);
334 eh
->ether_type
= htons(ETHERTYPE_MPLS
); /* XXX how about multicast? */
338 case pseudo_AF_HDRCMPLT
:
340 loop_copy
= -1; /* if this is for us, don't do it */
341 deh
= (struct ether_header
*)dst
->sa_data
;
342 memcpy(edst
, deh
->ether_dhost
, ETHER_ADDR_LEN
);
343 eh
->ether_type
= deh
->ether_type
;
347 if_printf(ifp
, "can't handle af%d\n", dst
->sa_family
);
348 gotoerr(EAFNOSUPPORT
);
351 if (dst
->sa_family
== pseudo_AF_HDRCMPLT
) /* unlikely */
352 memcpy(eh
->ether_shost
,
353 ((struct ether_header
*)dst
->sa_data
)->ether_shost
,
356 memcpy(eh
->ether_shost
, ac
->ac_enaddr
, ETHER_ADDR_LEN
);
359 * Bridges require special output handling.
361 if (ifp
->if_bridge
) {
362 KASSERT(bridge_output_p
!= NULL
,
363 ("%s: if_bridge not loaded!", __func__
));
364 return bridge_output_p(ifp
, m
);
368 * If a simplex interface, and the packet is being sent to our
369 * Ethernet address or a broadcast address, loopback a copy.
370 * XXX To make a simplex device behave exactly like a duplex
371 * device, we should copy in the case of sending to our own
372 * ethernet address (thus letting the original actually appear
373 * on the wire). However, we don't do that here for security
374 * reasons and compatibility with the original behavior.
376 if ((ifp
->if_flags
& IFF_SIMPLEX
) && (loop_copy
!= -1)) {
379 if (m
->m_pkthdr
.csum_flags
& CSUM_IP
)
380 csum_flags
|= (CSUM_IP_CHECKED
| CSUM_IP_VALID
);
381 if (m
->m_pkthdr
.csum_flags
& CSUM_DELAY_DATA
)
382 csum_flags
|= (CSUM_DATA_VALID
| CSUM_PSEUDO_HDR
);
383 if ((m
->m_flags
& M_BCAST
) || (loop_copy
> 0)) {
386 if ((n
= m_copypacket(m
, MB_DONTWAIT
)) != NULL
) {
387 n
->m_pkthdr
.csum_flags
|= csum_flags
;
388 if (csum_flags
& CSUM_DATA_VALID
)
389 n
->m_pkthdr
.csum_data
= 0xffff;
390 if_simloop(ifp
, n
, dst
->sa_family
, hlen
);
393 } else if (bcmp(eh
->ether_dhost
, eh
->ether_shost
,
394 ETHER_ADDR_LEN
) == 0) {
395 m
->m_pkthdr
.csum_flags
|= csum_flags
;
396 if (csum_flags
& CSUM_DATA_VALID
)
397 m
->m_pkthdr
.csum_data
= 0xffff;
398 if_simloop(ifp
, m
, dst
->sa_family
, hlen
);
399 return (0); /* XXX */
404 if (ifp
->if_carp
&& (error
= carp_output(ifp
, m
, dst
, NULL
)))
409 /* Handle ng_ether(4) processing, if any */
410 if (ng_ether_output_p
!= NULL
) {
411 if ((error
= (*ng_ether_output_p
)(ifp
, &m
)) != 0)
417 /* Continue with link-layer output */
418 return ether_output_frame(ifp
, m
);
426 * Ethernet link layer output routine to send a raw frame to the device.
428 * This assumes that the 14 byte Ethernet header is present and contiguous
432 ether_output_frame(struct ifnet
*ifp
, struct mbuf
*m
)
434 struct ip_fw
*rule
= NULL
;
436 struct altq_pktattr pktattr
;
439 ASSERT_NOT_SERIALIZED(ifp
->if_serializer
);
441 /* Extract info from dummynet tag */
442 mtag
= m_tag_find(m
, PACKET_TAG_DUMMYNET
, NULL
);
444 rule
= ((struct dn_pkt
*)m_tag_data(mtag
))->dn_priv
;
446 m_tag_delete(m
, mtag
);
450 if (ifq_is_enabled(&ifp
->if_snd
))
451 altq_etherclassify(&ifp
->if_snd
, m
, &pktattr
);
453 if (IPFW_LOADED
&& ether_ipfw
!= 0) {
454 struct ether_header save_eh
, *eh
;
456 eh
= mtod(m
, struct ether_header
*);
458 m_adj(m
, ETHER_HDR_LEN
);
459 if (!ether_ipfw_chk(&m
, ifp
, &rule
, eh
)) {
463 return ENOBUFS
; /* pkt dropped */
465 return 0; /* consumed e.g. in a pipe */
468 /* packet was ok, restore the ethernet header */
469 ether_restore_header(&m
, eh
, &save_eh
);
478 * Queue message on interface, update output statistics if
479 * successful, and start output if interface not yet active.
481 error
= ifq_dispatch(ifp
, m
, &pktattr
);
486 * ipfw processing for ethernet packets (in and out).
487 * The second parameter is NULL from ether_demux(), and ifp from
488 * ether_output_frame().
491 ether_ipfw_chk(struct mbuf
**m0
, struct ifnet
*dst
, struct ip_fw
**rule
,
492 const struct ether_header
*eh
)
494 struct ether_header save_eh
= *eh
; /* might be a ptr in m */
495 struct ip_fw_args args
;
499 if (*rule
!= NULL
&& fw_one_pass
)
500 return TRUE
; /* dummynet packet, already partially processed */
503 * I need some amount of data to be contiguous.
505 i
= min((*m0
)->m_pkthdr
.len
, max_protohdr
);
506 if ((*m0
)->m_len
< i
) {
507 *m0
= m_pullup(*m0
, i
);
512 args
.m
= *m0
; /* the packet we are looking at */
513 args
.oif
= dst
; /* destination, if any */
514 if ((mtag
= m_tag_find(*m0
, PACKET_TAG_IPFW_DIVERT
, NULL
)) != NULL
)
515 m_tag_delete(*m0
, mtag
);
516 args
.rule
= *rule
; /* matching rule to restart */
517 args
.next_hop
= NULL
; /* we do not support forward yet */
518 args
.eh
= &save_eh
; /* MAC header for bridged/MAC packets */
519 i
= ip_fw_chk_ptr(&args
);
523 if ((i
& IP_FW_PORT_DENY_FLAG
) || *m0
== NULL
) /* drop */
526 if (i
== 0) /* a PASS rule. */
529 if (i
& IP_FW_PORT_DYNT_FLAG
) {
531 * Pass the pkt to dummynet, which consumes it.
535 m
= *m0
; /* pass the original to dummynet */
536 *m0
= NULL
; /* and nothing back to the caller */
538 ether_restore_header(&m
, eh
, &save_eh
);
542 ip_fw_dn_io_ptr(m
, (i
& 0xffff),
543 dst
? DN_TO_ETH_OUT
: DN_TO_ETH_DEMUX
, &args
);
547 * XXX at some point add support for divert/forward actions.
548 * If none of the above matches, we have to drop the pkt.
554 * Process a received Ethernet packet.
556 * The ethernet header is assumed to be in the mbuf so the caller
557 * MUST MAKE SURE that there are at least sizeof(struct ether_header)
558 * bytes in the first mbuf.
560 * This allows us to concentrate in one place a bunch of code which
561 * is replicated in all device drivers. Also, many functions called
562 * from ether_input() try to put the eh back into the mbuf, so we
563 * can later propagate the 'contiguous packet' interface to them.
565 * NOTA BENE: for all drivers "eh" is a pointer into the first mbuf or
566 * cluster, right before m_data. So be very careful when working on m,
567 * as you could destroy *eh !!
569 * First we perform any link layer operations, then continue to the
570 * upper layers with ether_demux().
573 ether_input_chain(struct ifnet
*ifp
, struct mbuf
*m
, struct mbuf_chain
*chain
)
575 struct ether_header
*eh
;
577 ASSERT_SERIALIZED(ifp
->if_serializer
);
580 /* Discard packet if interface is not up */
581 if (!(ifp
->if_flags
& IFF_UP
)) {
586 if (m
->m_len
< sizeof(struct ether_header
)) {
587 /* XXX error in the caller. */
591 eh
= mtod(m
, struct ether_header
*);
593 if (ntohs(eh
->ether_type
) == ETHERTYPE_VLAN
&&
594 (m
->m_flags
& M_VLANTAG
) == 0) {
596 * Extract vlan tag if hardware does not do it for us
598 vlan_ether_decap(&m
);
601 eh
= mtod(m
, struct ether_header
*);
604 m
->m_pkthdr
.rcvif
= ifp
;
606 if (ETHER_IS_MULTICAST(eh
->ether_dhost
)) {
607 if (bcmp(ifp
->if_broadcastaddr
, eh
->ether_dhost
,
608 ifp
->if_addrlen
) == 0)
609 m
->m_flags
|= M_BCAST
;
611 m
->m_flags
|= M_MCAST
;
615 ETHER_BPF_MTAP(ifp
, m
);
617 ifp
->if_ibytes
+= m
->m_pkthdr
.len
;
619 if (ifp
->if_flags
& IFF_MONITOR
) {
621 * Interface marked for monitoring; discard packet.
628 * Tap the packet off here for a bridge. bridge_input()
629 * will return NULL if it has consumed the packet, otherwise
630 * it gets processed as normal. Note that bridge_input()
631 * will always return the original packet if we need to
632 * process it locally.
634 if (ifp
->if_bridge
) {
635 KASSERT(bridge_input_p
!= NULL
,
636 ("%s: if_bridge not loaded!", __func__
));
638 if(m
->m_flags
& M_PROTO1
) {
639 m
->m_flags
&= ~M_PROTO1
;
641 /* clear M_PROMISC, in case the packets comes from a vlan */
642 /* m->m_flags &= ~M_PROMISC; */
643 lwkt_serialize_exit(ifp
->if_serializer
);
644 m
= bridge_input_p(ifp
, m
);
645 lwkt_serialize_enter(ifp
->if_serializer
);
649 KASSERT(ifp
== m
->m_pkthdr
.rcvif
,
650 ("bridge_input_p changed rcvif\n"));
652 /* 'm' may be changed by bridge_input_p() */
653 eh
= mtod(m
, struct ether_header
*);
657 /* Handle ng_ether(4) processing, if any */
658 if (ng_ether_input_p
!= NULL
) {
659 ng_ether_input_p(ifp
, &m
);
663 /* 'm' may be changed by ng_ether_input_p() */
664 eh
= mtod(m
, struct ether_header
*);
667 /* Continue with upper layer processing */
668 ether_demux_chain(ifp
, m
, chain
);
672 ether_input(struct ifnet
*ifp
, struct mbuf
*m
)
674 ether_input_chain(ifp
, m
, NULL
);
678 * Upper layer processing for a received Ethernet packet.
681 ether_demux_chain(struct ifnet
*ifp
, struct mbuf
*m
, struct mbuf_chain
*chain
)
683 struct ether_header save_eh
, *eh
;
686 struct ip_fw
*rule
= NULL
;
693 KASSERT(m
->m_len
>= ETHER_HDR_LEN
,
694 ("ether header is no contiguous!\n"));
696 eh
= mtod(m
, struct ether_header
*);
699 /* XXX old crufty stuff, needs to be removed */
700 m_adj(m
, sizeof(struct ether_header
));
702 /* Extract info from dummynet tag */
703 mtag
= m_tag_find(m
, PACKET_TAG_DUMMYNET
, NULL
);
705 rule
= ((struct dn_pkt
*)m_tag_data(mtag
))->dn_priv
;
706 KKASSERT(ifp
== NULL
);
707 ifp
= m
->m_pkthdr
.rcvif
;
709 m_tag_delete(m
, mtag
);
712 if (rule
) /* packet is passing the second time */
717 * XXX: Okay, we need to call carp_forus() and - if it is for
718 * us jump over code that does the normal check
719 * "ac_enaddr == ether_dhost". The check sequence is a bit
720 * different from OpenBSD, so we jump over as few code as
721 * possible, to catch _all_ sanity checks. This needs
722 * evaluation, to see if the carp ether_dhost values break any
725 if (ifp
->if_carp
&& carp_forus(ifp
->if_carp
, eh
->ether_dhost
))
730 * Discard packet if upper layers shouldn't see it because
731 * it was unicast to a different Ethernet address. If the
732 * driver is working properly, then this situation can only
733 * happen when the interface is in promiscuous mode.
735 if (((ifp
->if_flags
& (IFF_PROMISC
| IFF_PPROMISC
)) == IFF_PROMISC
) &&
736 (eh
->ether_dhost
[0] & 1) == 0 &&
737 bcmp(eh
->ether_dhost
, IFP2AC(ifp
)->ac_enaddr
, ETHER_ADDR_LEN
)) {
743 if (IPFW_LOADED
&& ether_ipfw
!= 0) {
744 if (!ether_ipfw_chk(&m
, NULL
, &rule
, eh
)) {
750 ether_type
= ntohs(save_eh
.ether_type
);
752 if (m
->m_flags
& M_VLANTAG
) {
753 if (ether_type
== ETHERTYPE_VLAN
) {
755 * To prevent possible dangerous recursion,
756 * we don't do vlan-in-vlan
758 m
->m_pkthdr
.rcvif
->if_noproto
++;
763 if (vlan_input_p
!= NULL
) {
764 ether_restore_header(&m
, eh
, &save_eh
);
766 vlan_input_p(m
, chain
);
768 m
->m_pkthdr
.rcvif
->if_noproto
++;
773 KKASSERT(ether_type
!= ETHERTYPE_VLAN
);
775 switch (ether_type
) {
778 if (ipflow_fastforward(m
, ifp
->if_serializer
))
784 if (ifp
->if_flags
& IFF_NOARP
) {
785 /* Discard packet if ARP is disabled on interface */
801 if (ef_inputp
&& ef_inputp(ifp
, &save_eh
, m
) == 0)
808 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
825 case ETHERTYPE_MPLS_MCAST
:
832 if (ef_inputp
&& ef_inputp(ifp
, &save_eh
, m
) == 0)
836 checksum
= mtod(m
, ushort
*);
838 if ((ether_type
<= ETHERMTU
) &&
839 ((*checksum
== 0xffff) || (*checksum
== 0xE0E0))) {
840 if (*checksum
== 0xE0E0) {
841 m
->m_pkthdr
.len
-= 3;
850 if (ether_type
> ETHERMTU
)
852 l
= mtod(m
, struct llc
*);
853 if (l
->llc_dsap
== LLC_SNAP_LSAP
&&
854 l
->llc_ssap
== LLC_SNAP_LSAP
&&
855 l
->llc_control
== LLC_UI
) {
856 if (bcmp(&(l
->llc_snap_org_code
)[0], at_org_code
,
857 sizeof at_org_code
) == 0 &&
858 ntohs(l
->llc_snap_ether_type
) == ETHERTYPE_AT
) {
859 m_adj(m
, sizeof(struct llc
));
863 if (bcmp(&(l
->llc_snap_org_code
)[0], aarp_org_code
,
864 sizeof aarp_org_code
) == 0 &&
865 ntohs(l
->llc_snap_ether_type
) == ETHERTYPE_AARP
) {
866 m_adj(m
, sizeof(struct llc
));
873 if (ng_ether_input_orphan_p
!= NULL
)
874 (*ng_ether_input_orphan_p
)(ifp
, m
, &save_eh
);
880 #ifdef ETHER_INPUT_CHAIN
882 struct mbuf_chain
*c
;
886 port
= netisr_mport(isr
, &m
);
890 m
->m_pkthdr
.header
= port
; /* XXX */
891 cpuid
= port
->mpu_td
->td_gd
->gd_cpuid
;
894 if (c
->mc_head
== NULL
) {
895 c
->mc_head
= c
->mc_tail
= m
;
897 c
->mc_tail
->m_nextpkt
= m
;
902 #endif /* ETHER_INPUT_CHAIN */
903 netisr_dispatch(isr
, m
);
907 ether_demux(struct ifnet
*ifp
, struct mbuf
*m
)
909 ether_demux_chain(ifp
, m
, NULL
);
913 * Perform common duties while attaching to interface list
917 ether_ifattach(struct ifnet
*ifp
, uint8_t *lla
, lwkt_serialize_t serializer
)
919 ether_ifattach_bpf(ifp
, lla
, DLT_EN10MB
, sizeof(struct ether_header
),
924 ether_ifattach_bpf(struct ifnet
*ifp
, uint8_t *lla
, u_int dlt
, u_int hdrlen
,
925 lwkt_serialize_t serializer
)
927 struct sockaddr_dl
*sdl
;
929 ifp
->if_type
= IFT_ETHER
;
930 ifp
->if_addrlen
= ETHER_ADDR_LEN
;
931 ifp
->if_hdrlen
= ETHER_HDR_LEN
;
932 if_attach(ifp
, serializer
);
933 ifp
->if_mtu
= ETHERMTU
;
934 if (ifp
->if_baudrate
== 0)
935 ifp
->if_baudrate
= 10000000;
936 ifp
->if_output
= ether_output
;
937 ifp
->if_input
= ether_input
;
938 ifp
->if_resolvemulti
= ether_resolvemulti
;
939 ifp
->if_broadcastaddr
= etherbroadcastaddr
;
940 sdl
= IF_LLSOCKADDR(ifp
);
941 sdl
->sdl_type
= IFT_ETHER
;
942 sdl
->sdl_alen
= ifp
->if_addrlen
;
943 bcopy(lla
, LLADDR(sdl
), ifp
->if_addrlen
);
945 * XXX Keep the current drivers happy.
946 * XXX Remove once all drivers have been cleaned up
948 if (lla
!= IFP2AC(ifp
)->ac_enaddr
)
949 bcopy(lla
, IFP2AC(ifp
)->ac_enaddr
, ifp
->if_addrlen
);
950 bpfattach(ifp
, dlt
, hdrlen
);
951 if (ng_ether_attach_p
!= NULL
)
952 (*ng_ether_attach_p
)(ifp
);
954 if_printf(ifp
, "MAC address: %6D\n", lla
, ":");
958 * Perform common duties while detaching an Ethernet interface
961 ether_ifdetach(struct ifnet
*ifp
)
965 if (ng_ether_detach_p
!= NULL
)
966 (*ng_ether_detach_p
)(ifp
);
972 ether_ioctl(struct ifnet
*ifp
, int command
, caddr_t data
)
974 struct ifaddr
*ifa
= (struct ifaddr
*) data
;
975 struct ifreq
*ifr
= (struct ifreq
*) data
;
978 #define IF_INIT(ifp) \
980 if (((ifp)->if_flags & IFF_UP) == 0) { \
981 (ifp)->if_flags |= IFF_UP; \
982 (ifp)->if_init((ifp)->if_softc); \
986 ASSERT_SERIALIZED(ifp
->if_serializer
);
990 switch (ifa
->ifa_addr
->sa_family
) {
993 IF_INIT(ifp
); /* before arpwhohas */
994 arp_ifinit(ifp
, ifa
);
999 * XXX - This code is probably wrong
1003 struct ipx_addr
*ina
= &IA_SIPX(ifa
)->sipx_addr
;
1004 struct arpcom
*ac
= IFP2AC(ifp
);
1006 if (ipx_nullhost(*ina
))
1007 ina
->x_host
= *(union ipx_host
*) ac
->ac_enaddr
;
1009 bcopy(ina
->x_host
.c_host
, ac
->ac_enaddr
,
1010 sizeof ac
->ac_enaddr
);
1012 IF_INIT(ifp
); /* Set new address. */
1018 * XXX - This code is probably wrong
1022 struct ns_addr
*ina
= &(IA_SNS(ifa
)->sns_addr
);
1023 struct arpcom
*ac
= IFP2AC(ifp
);
1025 if (ns_nullhost(*ina
))
1026 ina
->x_host
= *(union ns_host
*)(ac
->ac_enaddr
);
1028 bcopy(ina
->x_host
.c_host
, ac
->ac_enaddr
,
1029 sizeof ac
->ac_enaddr
);
1045 bcopy(IFP2AC(ifp
)->ac_enaddr
,
1046 ((struct sockaddr
*)ifr
->ifr_data
)->sa_data
,
1052 * Set the interface MTU.
1054 if (ifr
->ifr_mtu
> ETHERMTU
) {
1057 ifp
->if_mtu
= ifr
->ifr_mtu
;
1072 struct sockaddr
**llsa
,
1073 struct sockaddr
*sa
)
1075 struct sockaddr_dl
*sdl
;
1076 struct sockaddr_in
*sin
;
1078 struct sockaddr_in6
*sin6
;
1082 switch(sa
->sa_family
) {
1085 * No mapping needed. Just check that it's a valid MC address.
1087 sdl
= (struct sockaddr_dl
*)sa
;
1088 e_addr
= LLADDR(sdl
);
1089 if ((e_addr
[0] & 1) != 1)
1090 return EADDRNOTAVAIL
;
1096 sin
= (struct sockaddr_in
*)sa
;
1097 if (!IN_MULTICAST(ntohl(sin
->sin_addr
.s_addr
)))
1098 return EADDRNOTAVAIL
;
1099 MALLOC(sdl
, struct sockaddr_dl
*, sizeof *sdl
, M_IFMADDR
,
1101 sdl
->sdl_len
= sizeof *sdl
;
1102 sdl
->sdl_family
= AF_LINK
;
1103 sdl
->sdl_index
= ifp
->if_index
;
1104 sdl
->sdl_type
= IFT_ETHER
;
1105 sdl
->sdl_alen
= ETHER_ADDR_LEN
;
1106 e_addr
= LLADDR(sdl
);
1107 ETHER_MAP_IP_MULTICAST(&sin
->sin_addr
, e_addr
);
1108 *llsa
= (struct sockaddr
*)sdl
;
1113 sin6
= (struct sockaddr_in6
*)sa
;
1114 if (IN6_IS_ADDR_UNSPECIFIED(&sin6
->sin6_addr
)) {
1116 * An IP6 address of 0 means listen to all
1117 * of the Ethernet multicast address used for IP6.
1118 * (This is used for multicast routers.)
1120 ifp
->if_flags
|= IFF_ALLMULTI
;
1124 if (!IN6_IS_ADDR_MULTICAST(&sin6
->sin6_addr
))
1125 return EADDRNOTAVAIL
;
1126 MALLOC(sdl
, struct sockaddr_dl
*, sizeof *sdl
, M_IFMADDR
,
1128 sdl
->sdl_len
= sizeof *sdl
;
1129 sdl
->sdl_family
= AF_LINK
;
1130 sdl
->sdl_index
= ifp
->if_index
;
1131 sdl
->sdl_type
= IFT_ETHER
;
1132 sdl
->sdl_alen
= ETHER_ADDR_LEN
;
1133 e_addr
= LLADDR(sdl
);
1134 ETHER_MAP_IPV6_MULTICAST(&sin6
->sin6_addr
, e_addr
);
1135 *llsa
= (struct sockaddr
*)sdl
;
1141 * Well, the text isn't quite right, but it's the name
1144 return EAFNOSUPPORT
;
1150 * This is for reference. We have a table-driven version
1151 * of the little-endian crc32 generator, which is faster
1152 * than the double-loop.
1155 ether_crc32_le(const uint8_t *buf
, size_t len
)
1157 uint32_t c
, crc
, carry
;
1160 crc
= 0xffffffffU
; /* initial value */
1162 for (i
= 0; i
< len
; i
++) {
1164 for (j
= 0; j
< 8; j
++) {
1165 carry
= ((crc
& 0x01) ? 1 : 0) ^ (c
& 0x01);
1169 crc
= (crc
^ ETHER_CRC_POLY_LE
);
1177 ether_crc32_le(const uint8_t *buf
, size_t len
)
1179 static const uint32_t crctab
[] = {
1180 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
1181 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
1182 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
1183 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
1188 crc
= 0xffffffffU
; /* initial value */
1190 for (i
= 0; i
< len
; i
++) {
1192 crc
= (crc
>> 4) ^ crctab
[crc
& 0xf];
1193 crc
= (crc
>> 4) ^ crctab
[crc
& 0xf];
1201 ether_crc32_be(const uint8_t *buf
, size_t len
)
1203 uint32_t c
, crc
, carry
;
1206 crc
= 0xffffffffU
; /* initial value */
1208 for (i
= 0; i
< len
; i
++) {
1210 for (j
= 0; j
< 8; j
++) {
1211 carry
= ((crc
& 0x80000000U
) ? 1 : 0) ^ (c
& 0x01);
1215 crc
= (crc
^ ETHER_CRC_POLY_BE
) | carry
;
1223 * find the size of ethernet header, and call classifier
1226 altq_etherclassify(struct ifaltq
*ifq
, struct mbuf
*m
,
1227 struct altq_pktattr
*pktattr
)
1229 struct ether_header
*eh
;
1230 uint16_t ether_type
;
1231 int hlen
, af
, hdrsize
;
1234 hlen
= sizeof(struct ether_header
);
1235 eh
= mtod(m
, struct ether_header
*);
1237 ether_type
= ntohs(eh
->ether_type
);
1238 if (ether_type
< ETHERMTU
) {
1240 struct llc
*llc
= (struct llc
*)(eh
+ 1);
1243 if (m
->m_len
< hlen
||
1244 llc
->llc_dsap
!= LLC_SNAP_LSAP
||
1245 llc
->llc_ssap
!= LLC_SNAP_LSAP
||
1246 llc
->llc_control
!= LLC_UI
)
1247 goto bad
; /* not snap! */
1249 ether_type
= ntohs(llc
->llc_un
.type_snap
.ether_type
);
1252 if (ether_type
== ETHERTYPE_IP
) {
1254 hdrsize
= 20; /* sizeof(struct ip) */
1256 } else if (ether_type
== ETHERTYPE_IPV6
) {
1258 hdrsize
= 40; /* sizeof(struct ip6_hdr) */
1263 while (m
->m_len
<= hlen
) {
1267 hdr
= m
->m_data
+ hlen
;
1268 if (m
->m_len
< hlen
+ hdrsize
) {
1270 * ip header is not in a single mbuf. this should not
1271 * happen in the current code.
1272 * (todo: use m_pulldown in the future)
1278 ifq_classify(ifq
, m
, af
, pktattr
);
1285 pktattr
->pattr_class
= NULL
;
1286 pktattr
->pattr_hdr
= NULL
;
1287 pktattr
->pattr_af
= AF_UNSPEC
;
1291 ether_restore_header(struct mbuf
**m0
, const struct ether_header
*eh
,
1292 const struct ether_header
*save_eh
)
1294 struct mbuf
*m
= *m0
;
1296 ether_restore_hdr
++;
1299 * Prepend the header, optimize for the common case of
1300 * eh pointing into the mbuf.
1302 if ((const void *)(eh
+ 1) == (void *)m
->m_data
) {
1303 m
->m_data
-= ETHER_HDR_LEN
;
1304 m
->m_len
+= ETHER_HDR_LEN
;
1305 m
->m_pkthdr
.len
+= ETHER_HDR_LEN
;
1307 ether_prepend_hdr
++;
1309 M_PREPEND(m
, ETHER_HDR_LEN
, MB_DONTWAIT
);
1311 bcopy(save_eh
, mtod(m
, struct ether_header
*),
1318 #ifdef ETHER_INPUT_CHAIN
1321 ether_input_ipifunc(void *arg
)
1323 struct mbuf
*m
, *next
;
1328 next
= m
->m_nextpkt
;
1329 m
->m_nextpkt
= NULL
;
1331 port
= m
->m_pkthdr
.header
;
1332 m
->m_pkthdr
.header
= NULL
;
1335 &m
->m_hdr
.mh_netmsg
.nm_netmsg
.nm_lmsg
);
1338 } while (m
!= NULL
);
1342 ether_input_dispatch(struct mbuf_chain
*chain
)
1347 for (i
= 0; i
< ncpus
; ++i
) {
1348 if (chain
[i
].mc_head
!= NULL
) {
1349 lwkt_send_ipiq(globaldata_find(i
),
1350 ether_input_ipifunc
, chain
[i
].mc_head
);
1354 if (chain
->mc_head
!= NULL
)
1355 ether_input_ipifunc(chain
->mc_head
);
1360 ether_input_chain_init(struct mbuf_chain
*chain
)
1365 for (i
= 0; i
< ncpus
; ++i
)
1366 chain
[i
].mc_head
= chain
[i
].mc_tail
= NULL
;
1368 chain
->mc_head
= chain
->mc_tail
= NULL
;
1372 #endif /* ETHER_INPUT_CHAIN */
1377 ether_demux_oncpu(struct ifnet
*ifp
, struct mbuf
*m
)
1379 struct ether_header
*eh
;
1380 int isr
, redispatch
;
1382 struct ip_fw
*rule
= NULL
;
1389 KASSERT(m
->m_len
>= ETHER_HDR_LEN
,
1390 ("ether header is no contiguous!\n"));
1392 eh
= mtod(m
, struct ether_header
*);
1394 /* Extract info from dummynet tag */
1395 mtag
= m_tag_find(m
, PACKET_TAG_DUMMYNET
, NULL
);
1397 rule
= ((struct dn_pkt
*)m_tag_data(mtag
))->dn_priv
;
1398 KKASSERT(ifp
== NULL
);
1399 ifp
= m
->m_pkthdr
.rcvif
;
1401 m_tag_delete(m
, mtag
);
1404 if (rule
) /* packet is passing the second time */
1409 * XXX: Okay, we need to call carp_forus() and - if it is for
1410 * us jump over code that does the normal check
1411 * "ac_enaddr == ether_dhost". The check sequence is a bit
1412 * different from OpenBSD, so we jump over as few code as
1413 * possible, to catch _all_ sanity checks. This needs
1414 * evaluation, to see if the carp ether_dhost values break any
1417 if (ifp
->if_carp
&& carp_forus(ifp
->if_carp
, eh
->ether_dhost
))
1422 * Discard packet if upper layers shouldn't see it because
1423 * it was unicast to a different Ethernet address. If the
1424 * driver is working properly, then this situation can only
1425 * happen when the interface is in promiscuous mode.
1427 if (((ifp
->if_flags
& (IFF_PROMISC
| IFF_PPROMISC
)) == IFF_PROMISC
) &&
1428 (eh
->ether_dhost
[0] & 1) == 0 &&
1429 bcmp(eh
->ether_dhost
, IFP2AC(ifp
)->ac_enaddr
, ETHER_ADDR_LEN
)) {
1435 if (IPFW_LOADED
&& ether_ipfw
!= 0) {
1436 struct ether_header save_eh
= *eh
;
1438 /* XXX old crufty stuff, needs to be removed */
1439 m_adj(m
, sizeof(struct ether_header
));
1441 if (!ether_ipfw_chk(&m
, NULL
, &rule
, eh
)) {
1446 ether_restore_header(&m
, eh
, &save_eh
);
1449 eh
= mtod(m
, struct ether_header
*);
1452 ether_type
= ntohs(eh
->ether_type
);
1453 KKASSERT(ether_type
!= ETHERTYPE_VLAN
);
1455 if (m
->m_flags
& M_VLANTAG
) {
1456 if (vlan_input2_p
!= NULL
) {
1459 m
->m_pkthdr
.rcvif
->if_noproto
++;
1465 m_adj(m
, sizeof(struct ether_header
));
1468 switch (ether_type
) {
1472 if (ipflow_fastforward(m
, ifp
->if_serializer
))
1479 if (ifp
->if_flags
& IFF_NOARP
) {
1480 /* Discard packet if ARP is disabled on interface */
1489 case ETHERTYPE_IPV6
:
1496 if (ef_inputp
&& ef_inputp(ifp
, eh
, m
) == 0)
1503 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
1511 isr
= NETISR_ATALK1
;
1513 case ETHERTYPE_AARP
:
1519 case ETHERTYPE_MPLS
:
1520 case ETHERTYPE_MPLS_MCAST
:
1527 * The accurate msgport is not determined before
1528 * we reach here, so redo the dispatching
1532 if (ef_inputp
&& ef_inputp(ifp
, eh
, m
) == 0)
1536 checksum
= mtod(m
, ushort
*);
1538 if ((ether_type
<= ETHERMTU
) &&
1539 ((*checksum
== 0xffff) || (*checksum
== 0xE0E0))) {
1540 if (*checksum
== 0xE0E0) {
1541 m
->m_pkthdr
.len
-= 3;
1550 if (ether_type
> ETHERMTU
)
1552 l
= mtod(m
, struct llc
*);
1553 if (l
->llc_dsap
== LLC_SNAP_LSAP
&&
1554 l
->llc_ssap
== LLC_SNAP_LSAP
&&
1555 l
->llc_control
== LLC_UI
) {
1556 if (bcmp(&(l
->llc_snap_org_code
)[0], at_org_code
,
1557 sizeof at_org_code
) == 0 &&
1558 ntohs(l
->llc_snap_ether_type
) == ETHERTYPE_AT
) {
1559 m_adj(m
, sizeof(struct llc
));
1560 isr
= NETISR_ATALK2
;
1563 if (bcmp(&(l
->llc_snap_org_code
)[0], aarp_org_code
,
1564 sizeof aarp_org_code
) == 0 &&
1565 ntohs(l
->llc_snap_ether_type
) == ETHERTYPE_AARP
) {
1566 m_adj(m
, sizeof(struct llc
));
1573 if (ng_ether_input_orphan_p
!= NULL
)
1574 ng_ether_input_orphan_p(ifp
, m
, eh
);
1583 netisr_dispatch(isr
, m
);
1587 ether_input_oncpu(struct ifnet
*ifp
, struct mbuf
*m
)
1589 if ((ifp
->if_flags
& (IFF_UP
| IFF_MONITOR
)) != IFF_UP
) {
1591 * Receiving interface's flags are changed, when this
1592 * packet is waiting for processing; discard it.
1599 * Tap the packet off here for a bridge. bridge_input()
1600 * will return NULL if it has consumed the packet, otherwise
1601 * it gets processed as normal. Note that bridge_input()
1602 * will always return the original packet if we need to
1603 * process it locally.
1605 if (ifp
->if_bridge
) {
1606 KASSERT(bridge_input_p
!= NULL
,
1607 ("%s: if_bridge not loaded!", __func__
));
1609 if(m
->m_flags
& M_PROTO1
) {
1610 m
->m_flags
&= ~M_PROTO1
;
1612 /* clear M_PROMISC, in case the packets comes from a vlan */
1613 /* m->m_flags &= ~M_PROMISC; */
1614 m
= bridge_input_p(ifp
, m
);
1618 KASSERT(ifp
== m
->m_pkthdr
.rcvif
,
1619 ("bridge_input_p changed rcvif\n"));
1623 /* Handle ng_ether(4) processing, if any */
1624 if (ng_ether_input_p
!= NULL
) {
1625 ng_ether_input_p(ifp
, &m
);
1630 /* Continue with upper layer processing */
1631 ether_demux_oncpu(ifp
, m
);
1635 ether_input_handler(struct netmsg
*nmsg
)
1637 struct netmsg_packet
*nmp
= (struct netmsg_packet
*)nmsg
;
1643 ifp
= m
->m_pkthdr
.rcvif
;
1645 ether_input_oncpu(ifp
, m
);
1648 static __inline
void
1649 ether_init_netpacket(int num
, struct mbuf
*m
)
1651 struct netmsg_packet
*pmsg
;
1653 pmsg
= &m
->m_hdr
.mh_netmsg
;
1654 netmsg_init(&pmsg
->nm_netmsg
, &netisr_apanic_rport
, 0,
1655 ether_input_handler
);
1656 pmsg
->nm_packet
= m
;
1657 pmsg
->nm_netmsg
.nm_lmsg
.u
.ms_result
= num
;
1660 static __inline
struct lwkt_port
*
1661 ether_mport(int num
, struct mbuf
**m0
)
1663 struct lwkt_port
*port
;
1664 struct mbuf
*m
= *m0
;
1666 if (num
== NETISR_MAX
) {
1668 * All packets whose target msgports can't be
1669 * determined here are dispatched to netisr0,
1670 * where further dispatching may happen.
1672 return cpu_portfn(0);
1675 port
= netisr_find_port(num
, &m
);
1684 ether_input_chain2(struct ifnet
*ifp
, struct mbuf
*m
, struct mbuf_chain
*chain
)
1686 struct ether_header
*eh
, *save_eh
, save_eh0
;
1687 struct lwkt_port
*port
;
1688 uint16_t ether_type
;
1691 ASSERT_SERIALIZED(ifp
->if_serializer
);
1694 /* Discard packet if interface is not up */
1695 if (!(ifp
->if_flags
& IFF_UP
)) {
1700 if (m
->m_len
< sizeof(struct ether_header
)) {
1701 /* XXX error in the caller. */
1705 eh
= mtod(m
, struct ether_header
*);
1707 m
->m_pkthdr
.rcvif
= ifp
;
1709 if (ETHER_IS_MULTICAST(eh
->ether_dhost
)) {
1710 if (bcmp(ifp
->if_broadcastaddr
, eh
->ether_dhost
,
1711 ifp
->if_addrlen
) == 0)
1712 m
->m_flags
|= M_BCAST
;
1714 m
->m_flags
|= M_MCAST
;
1718 ETHER_BPF_MTAP(ifp
, m
);
1720 ifp
->if_ibytes
+= m
->m_pkthdr
.len
;
1722 if (ifp
->if_flags
& IFF_MONITOR
) {
1724 * Interface marked for monitoring; discard packet.
1730 if (ntohs(eh
->ether_type
) == ETHERTYPE_VLAN
&&
1731 (m
->m_flags
& M_VLANTAG
) == 0) {
1733 * Extract vlan tag if hardware does not do it for us
1735 vlan_ether_decap(&m
);
1738 eh
= mtod(m
, struct ether_header
*);
1740 ether_type
= ntohs(eh
->ether_type
);
1742 if ((m
->m_flags
& M_VLANTAG
) && ether_type
== ETHERTYPE_VLAN
) {
1744 * To prevent possible dangerous recursion,
1745 * we don't do vlan-in-vlan
1751 KKASSERT(ether_type
!= ETHERTYPE_VLAN
);
1754 * Map ether type to netisr id.
1756 switch (ether_type
) {
1768 case ETHERTYPE_IPV6
:
1780 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
1787 isr
= NETISR_ATALK1
;
1789 case ETHERTYPE_AARP
:
1795 case ETHERTYPE_MPLS
:
1796 case ETHERTYPE_MPLS_MCAST
:
1803 * NETISR_MAX is an invalid value; it is chosen to let
1804 * ether_mport() know that we are not able to decide
1805 * this packet's msgport here.
1812 * If the packet is in contiguous memory, following
1813 * m_adj() could ensure that the hidden ether header
1814 * will not be destroyed, else we will have to save
1815 * the ether header for the later restoration.
1817 if (m
->m_pkthdr
.len
!= m
->m_len
) {
1819 save_eh
= &save_eh0
;
1825 * Temporarily remove ether header; ether_mport()
1826 * expects a packet without ether header.
1828 m_adj(m
, sizeof(struct ether_header
));
1831 * Find the packet's target msgport.
1833 port
= ether_mport(isr
, &m
);
1835 KKASSERT(m
== NULL
);
1840 * Restore ether header.
1842 if (save_eh
!= NULL
) {
1843 ether_restore_header(&m
, eh
, save_eh
);
1847 m
->m_data
-= ETHER_HDR_LEN
;
1848 m
->m_len
+= ETHER_HDR_LEN
;
1849 m
->m_pkthdr
.len
+= ETHER_HDR_LEN
;
1853 * Initialize mbuf's netmsg packet _after_ possible
1854 * ether header restoration, else the initialized
1855 * netmsg packet may be lost during ether header
1858 ether_init_netpacket(isr
, m
);
1860 #ifdef ETHER_INPUT_CHAIN
1861 if (chain
!= NULL
) {
1862 struct mbuf_chain
*c
;
1865 m
->m_pkthdr
.header
= port
; /* XXX */
1866 cpuid
= port
->mpu_td
->td_gd
->gd_cpuid
;
1869 if (c
->mc_head
== NULL
) {
1870 c
->mc_head
= c
->mc_tail
= m
;
1872 c
->mc_tail
->m_nextpkt
= m
;
1875 m
->m_nextpkt
= NULL
;
1877 #endif /* ETHER_INPUT_CHAIN */
1878 lwkt_sendmsg(port
, &m
->m_hdr
.mh_netmsg
.nm_netmsg
.nm_lmsg
);
1881 #endif /* ETHER_INPUT2 */