aboutsummaryrefslogtreecommitdiff
path: root/sys/net/ethernet.h
Commit message (Collapse)AuthorAgeFilesLines
* ethernet: Move the assertion of ether header sizes back into ethernet.hZhenlei Huang2025-07-151-0/+6
| | | | | | | | | | | | | | | | | | | | | | There're lots of consumers, Ethernet drivers, libraries and applications. It is more promising to assert the sizes in every compilation units rather than in if_ethersubr.c only. Those assertions were in the header file but were moved to if_ethersubr.c due to possible conflict of the implementation of CTASSERT [1]. Now that the default C standard is now gnu17 [2] [3] which supports _Static_assert natively, use _Static_assert instead of CTASSERT to avoid possible conflicts. While here, add an extra assertion for the size of struct ether_vlan_header. [1] d54d93ac7f0f Move CTASSERT of ether header sizes out of the header file and into ... [2] ca4eddea97c5 src: Use gnu17 as the default C standard for userland instead of gnu99 [3] 3a98d5701c7f sys: Use gnu17 as the default C standard for the kernel PR: 287761 (exp-run) Reviewed by: glebius Differential Revision: https://reviews.freebsd.org/D50947
* sys/net: move DOT1Q_VID_* constants to ethernet.hLexi Winter2025-07-041-0/+17
| | | | | | | | | | | | These are generally useful to anything dealing with 802.1q and aren't specific to if_vlan, so move them to <net/ethernet.h> and remove the _KERNEL gate. While here, document what they actually mean. Reviewed by: kp, des Approved by: des (mentor) Differential Revision: https://reviews.freebsd.org/D50570
* sys/net: add a new ether_vlanid_t typeLexi Winter2025-04-151-0/+5
| | | | | | | | | | ether_vlanid_t is a type to represent a VLAN ID, for example inside a .1q tag. since this is specific to Ethernet, put it in net/ethernet.h. change bridge to use the new type instead of uint{16,32}_t. Reviewed by: adrian, kp Differential Revision: https://reviews.freebsd.org/D49836
* ethernet: Retire M_HASFCSZhenlei Huang2024-07-041-1/+0
| | | | | | | | | | | | | | | | | | | The mbuf flag M_HASFCS was introduced for drivers to indicate the net stack that packets include FCS (Frame Check Sequence). In principle, to be efficient, FCS should always be processed by hardware, firmware, or at last sort the driver. Well, Ethernet specifies that damaged frames should be discarded, thus only good ones will be passed up to the net stack, then it makes no senses for the net stack to see FCS just to trim it. The last consumer of the flag M_HASFCS has been removed since change [1]. It is time to retire it. 1. 105a4f7b3cb6 ng_atmllc: remove Reviewed by: kp MFC after: never Differential Revision: https://reviews.freebsd.org/D42391
* Teach if_smsc to get MAC from bootargs.Ronald Klop2023-12-071-0/+1
| | | | | | | | | | | | | | | Some Raspberry Pi pass smsc95xx.macaddr=XX:XX:XX:XX:XX:XX as bootargs. Use this if no ethernet address is found in an EEPROM. As last resort fall back to ether_gen_addr() instead of random MAC. PR: 274092 Reported by: Patrick M. Hausen (via ML) Reviewed by: imp, karels, zlei Tested by: Patrick M. Hausen Approved by: karels MFC after: 1 month Relnotes: yes Differential Revision: https://reviews.freebsd.org/D42463
* net: Do not overwrite if_vlan's PCPZhenlei Huang2023-08-231-1/+1
| | | | | | | | | | | | | | | | | | | | | In commit c7cffd65c5d8 the function ether_8021q_frame() was slightly refactored to use pointer of struct ether_8021q_tag as parameter qtag to include the new option proto. It is wrong to write to qtag->pcp as it will effectively change the memory that qtag points to. Unfortunately the transmit routine of if_vlan parses pointer of the member ifv_qtag of its softc which stores vlan interface's PCP internally, when transmitting mbufs that contains PCP the vlan interface's PCP will get overwritten. Fix by operating on a local copy of qtag->pcp. Also mark 'struct ether_8021q_tag' as const so that compilers can pick up such kind of bug. PR: 273304 Reviewed by: kp Fixes: c7cffd65c5d85 Add support for stacked VLANs (IEEE 802.1ad, AKA Q-in-Q) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D39505
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-161-2/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* bridge: Add support for emulated netmap modeMark Johnston2023-04-101-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | if_bridge receives packets via a special interface, if_bridge_input, rather than by if_input. Thus, netmap's usual hooking of ifnet routines does not work as expected. Instead, modify bridge_input() to pass packets directly to netmap when it is enabled. This applies to both locally delivered packets and forwarded packets. When a netmap application transmits a packet by writing it to the host TX ring, the mbuf chain is passed to if_input, which ordinarily points to ether_input(). However, when transmitting via if_bridge, bridge_input() needs to see the packet again in order to decide whether to deliver or forward. Thus, introduce a new protocol flag, M_BRIDGE_INJECT, which 1) causes the packet to be passed to bridge_input() again after Ethernet processing, and 2) avoids passing the packet back to netmap. The source MAC address of the packet is used to determine the original "receiving" interface. Reviewed by: vmaffione MFC after: 2 months Sponsored by: Zenarmor Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38066
* bpf: Add "_if" tap APIsJustin Hibbits2023-01-311-10/+5
| | | | | | | | | | Summary: Hide more netstack by making the BPF_TAP macros real functions in the netstack. "struct ifnet" is used in the header instead of "if_t" to keep header pollution down. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D38103
* net(3): Fix a typo in a source code commentGordon Bergling2022-04-021-1/+1
| | | | | | - s/verion/version/ MFC after: 3 days
* net: make ethernet.h self-containedKristof Provost2021-12-171-0/+2
| | | | | | Reviewed by: imp Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D33501
* ifconfig: Minor documentation fixJose Luis Duran2021-05-031-2/+2
| | | | | | | | | | | | | Fix what appears to have been a small copy/paste typo in ifconfig(8)'s documentation (man page and header file). Not that it matters anymore. Reference: Table I-2 in IEEE Std 802.1Q-2014. PR: 255557 Submitted by: Jose Luis Duran <jlduran@gmail.com> MFC after: 1 week
* bridge: Remove members when assigned to a new vnetKristof Provost2021-02-231-0/+4
| | | | | | | | | | | | When the bridge is moved to a different vnet we must remove all of its member interfaces (and span interfaces), because we don't know if those will be moved along with it. We don't want to hold references to interfaces not in our vnet. Reviewed by: donner@ MFC after: 1 week Sponsored by: Orange Business Services Differential Revision: https://reviews.freebsd.org/D28859
* net: add ETHER_IS_IPV6_MULTICASTMitchell Horne2020-10-301-0/+2
| | | | | | | | | | | | | | | This can be used to detect if an ethernet address is specifically an IPv6 multicast address, defined in accordance to RFC 2464. ETHER_IS_MULTICAST is still preferred in the general case. Reviewed by: ae Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D26611 Notes: svn path=/head/; revision=367163
* Add support for stacked VLANs (IEEE 802.1ad, AKA Q-in-Q).Alexander V. Chernikov2020-10-211-3/+10
| | | | | | | | | | | | | | | | | | | | | 802.1ad interfaces are created with ifconfig using the "vlanproto" parameter. Eg., the following creates a 802.1Q VLAN (id #42) over a 802.1ad S-VLAN (id #5) over a physical Ethernet interface (em0). ifconfig vlan5 create vlandev em0 vlan 5 vlanproto 802.1ad up ifconfig vlan42 create vlandev vlan5 vlan 42 inet 10.5.42.1/24 VLAN_MTU, VLAN_HWCSUM and VLAN_TSO capabilities should be properly supported. VLAN_HWTAGGING is only partially supported, as there is currently no IFCAP_VLAN_* denoting the possibility to set the VLAN EtherType to anything else than 0x8100 (802.1ad uses 0x88A8). Submitted by: Olivier Piras Sponsored by: RG Nets Differential Revision: https://reviews.freebsd.org/D26436 Notes: svn path=/head/; revision=366917
* typo: stray spaces.Pedro F. Giffuni2020-02-071-1/+1
| | | | | | | No functional change Notes: svn path=/head/; revision=357655
* ethernet: Add a couple more Ethertypes.Pedro F. Giffuni2020-02-051-0/+2
| | | | | | | | Powerlink and Sercos III are used in automation. Both have been standardized and In the case of Ethernet Powerlink there is a BSD-licensed stack. Notes: svn path=/head/; revision=357587
* typo: Registration.Pedro F. Giffuni2020-02-031-1/+1
| | | | | | | Pointed by: Dikshie Fauzie Notes: svn path=/head/; revision=357424
* ethernet: Minor cleanup.Pedro F. Giffuni2020-02-031-5/+5
| | | | | | | Consistently use uppercase for ethertype hex numbers. Notes: svn path=/head/; revision=357423
* style(9): Fix spaces after #define.Pedro F. Giffuni2020-02-021-4/+4
| | | | | | | No functional change. Notes: svn path=/head/; revision=357417
* ethernet: add some more Ethertypes.Pedro F. Giffuni2020-02-021-1/+1
| | | | | | | Sort ETHERTYPE_FCOE, from r357414. Notes: svn path=/head/; revision=357415
* ethernet: add some more Ethertypes.Pedro F. Giffuni2020-02-021-0/+12
| | | | | | | | | | | | | Add some types based on other BSDs and also add EtherCat and PROFINET, which are IEC standards. There is a public list (CSV format) at: https://standards.ieee.org/products-services/regauth/ MFC after: 2 weeks Notes: svn path=/head/; revision=357414
* net: add ETHER_IS_ZERO macro similar to ETHER_IS_BROADCASTEric Joyner2019-11-051-0/+3
| | | | | | | | | | | | | | | | | | | Some places in network code may need to verify that an ethernet address is not the 'zero' address. Provide a standard macro ETHER_IS_ZERO for this purpose, similar to the ETHER_IS_BROADCAST macro already available. This patch also removes previous ETHER_IS_ZERO definitions in several USB ethernet drivers, in favor of this centrally-located macro. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Submitted by: Jacob Keller <jacob.e.keller@intel.com> Reviewed by: erj@ Sponsored by: Intel Corporation Differential Revision: https://reviews.freebsd.org/D21240 Notes: svn path=/head/; revision=354345
* ether: add older ethertype definitions for QinQPhilip Paeps2019-10-171-0/+3
| | | | | | | | | | | Older network equipment used the ethertypes 0x9100, 0x9200, and 0x9300 for outer VLANs, before standardisation introduced 0x88a8. Submitted by: Lutz Donnerhacke <lutz_donnerhacke.de> Differential Revision: https://reviews.freebsd.org/D21846 Notes: svn path=/head/; revision=353674
* Extract eventfilter declarations to sys/_eventfilter.hConrad Meyer2019-05-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h" in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header pollution substantially. EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c files into appropriate headers (e.g., sys/proc.h, powernv/opal.h). As a side effect of reduced header pollution, many .c files and headers no longer contain needed definitions. The remainder of the patch addresses adding appropriate includes to fix those files. LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by sys/mutex.h since r326106 (but silently protected by header pollution prior to this change). No functional change (intended). Of course, any out of tree modules that relied on header pollution for sys/eventhandler.h, sys/lock.h, or sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped. Notes: svn path=/head/; revision=347984
* net: adjust randomized address bitsKyle Evans2019-04-171-1/+1
| | | | | | | | | | | | | Give devices that need a MAC a 16-bit allocation out of the FreeBSD Foundation OUI range. Change the name ether_fakeaddr to ether_gen_addr now that we're dealing real MAC addresses with a real OUI rather than random locally-administered addresses. Reviewed by: bz, rgrimes Differential Revision: https://reviews.freebsd.org/D19587 Notes: svn path=/head/; revision=346324
* ether: centralize fake hwaddr generationKyle Evans2019-03-141-0/+1
| | | | | | | | | | | | We currently have two places with identical fake hwaddr generation -- if_vxlan and if_bridge. Lift it into if_ethersubr for reuse in other interfaces that may also need a fake addr. Reviewed by: bryanv, kp, philip Differential Revision: https://reviews.freebsd.org/D19573 Notes: svn path=/head/; revision=345139
* Allow to specify PCP on packets not belonging to any VLAN.Konstantin Belousov2018-03-271-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | According to 802.1Q-2014, VLAN tagged packets with VLAN id 0 should be considered as untagged, and only PCP and DEI values from the VLAN tag are meaningful. See for instance https://www.cisco.com/c/en/us/td/docs/switches/connectedgrid/cg-switch-sw-master/software/configuration/guide/vlan0/b_vlan_0.html. Make it possible to specify PCP value for outgoing packets on an ethernet interface. When PCP is supplied, the tag is appended, VLAN id set to 0, and PCP is filled by the supplied value. The code to do VLAN tag encapsulation is refactored from the if_vlan.c and moved into if_ethersubr.c. Drivers might have issues with filtering VID 0 packets on receive. This bug should be fixed for each driver. Reviewed by: ae (previous version), hselasky, melifaro Sponsored by: Mellanox Technologies MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D14702 Notes: svn path=/head/; revision=331622
* Define ethernet type 0x88A8 as ETHERTYPE_QINQ.Andrey V. Elsukov2018-03-061-0/+1
| | | | | | | | | | Reviewed by: kp Obtained from: OpenBSD MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D14593 Notes: svn path=/head/; revision=330536
* ethernet: Add ethernet interface attached event and devctl notification.Sepherosa Ziehau2017-07-241-0/+6
| | | | | | | | | | | | | ifnet_arrival_event may not be adequate under certain situation; e.g. when the LLADDR is needed. So the ethernet ifattach event is announced after all necessary bits are setup. MFC after: 3 days Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D11617 Notes: svn path=/head/; revision=321406
* net/vlan: Revert 305177Sepherosa Ziehau2017-05-191-1/+1
| | | | | | | | | | | | Miss read the parentheses. Reported by: oleg@ Reviewed by: hps@ MFC after: 3 days Sponsored by: Microsoft Notes: svn path=/head/; revision=318512
* net/vlan: Shift for pri is 13 (pri mask 0xe000) not 1.Sepherosa Ziehau2016-09-011-1/+1
| | | | | | | | | | Reviewed by: araujo, hps MFC after: 1 week Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7710 Notes: svn path=/head/; revision=305177
* Extract out the various local definitions of ETHER_IS_BROADCAST() andAdrian Chadd2016-08-071-0/+3
| | | | | | | | | | | | turn them into a shared definition. Set M_MCAST/M_BCAST appropriately upon packet reception in net80211, just before they are delivered up to the ethernet stack. Submitted by: rstone Notes: svn path=/head/; revision=303811
* Add ethertype reserved for network testingGeorge V. Neville-Neil2016-03-281-0/+1
| | | | | | | MFC after: 2 weeks Notes: svn path=/head/; revision=297358
* Move struct ether_vlan_header to ethernet.h, out of if_vlan_var.h,Gleb Smirnoff2014-11-111-0/+19
| | | | | | | since this structure is protocol definition, not part of implementation. Notes: svn path=/head/; revision=274374
* Add const qualifier to the dst parameter of the ifnet if_output method.Gleb Smirnoff2013-04-261-2/+2
| | | | Notes: svn path=/head/; revision=249925
* Change if_output to take a struct route as its fourth argument in orderKip Macy2009-04-161-2/+2
| | | | | | | | | to allow passing a cached struct llentry * down to L2 Reviewed by: rwatson Notes: svn path=/head/; revision=191148
* Move CTASSERT of ether header sizes out of the header file and intoEd Maste2008-08-271-5/+0
| | | | | | | | | | | | | if_ethersubr.c. CTASSERT is implemented using a dummy typedef, which if used in a header file may conflict with another CTASSERT in a source file using that header. I'll make a note of this in CTASSERT's man page. Approved by: imp Notes: svn path=/head/; revision=182285
* Spelling and capitalization fixes.Sean Farley2008-05-161-4/+4
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=179036
* Use a uint16_t type for the vlan tag rather an int.Andrew Thompson2007-10-181-1/+1
| | | | Notes: svn path=/head/; revision=172777
* The bridging output function puts the mbuf directly on the interfaces sendAndrew Thompson2007-10-181-0/+1
| | | | | | | | | | | | | | | | | | | queue so the output network card must support the same tagging mechanism as how the frame was input (prepended Ethernet header tag or stripped HW mflag). Now the vlan Ethernet header is _always_ stripped in ether_input and the mbuf flagged, only only network cards with VLAN_HWTAGGING enabled would properly re-tag any outgoing vlan frames. If the outgoing interface does not support hardware tagging then readd the vlan header to the front of the frame. Move the common vlan encapsulation in to ether_vlanencap(). Reported by: Erik Osterholm, Jon Otterholm MFC after: 1 week Notes: svn path=/head/; revision=172770
* Sync ether_ioctl() with ioctl(2) and ifnet.if_ioctlYaroslav Tykhiy2007-05-291-1/+1
| | | | | | | | | | | | | | as to the type of the command argument: int -> u_long. These types have different widths in the 64-bit world. Add a note to UPDATING because the change breaks KBI on 64-bit platforms. Discussed on: -net, -current Reviewed by: bms, ru Notes: svn path=/head/; revision=170097
* Add prototypes for ether_aton_r() and ether_ntoa_r() missed in previousRobert Watson2007-05-131-0/+2
| | | | | | | commit. Notes: svn path=/head/; revision=169529
* Add Ethertype for 802.3ad LACP.Bruce M Simpson2007-03-071-0/+1
| | | | Notes: svn path=/head/; revision=167290
* style(9) nit. Prefer struct[space]name[space]{ to make grep searches moreChristian S.J. Peron2007-01-011-2/+2
| | | | | | | in line with that we find in the rest of the tree. Notes: svn path=/head/; revision=165724
* Use CTASSERT to make sure:Warner Losh2006-12-011-1/+6
| | | | | | | | | | | | | | | sizeof ether_header is 2 * ETHER_ADDR_LEN + 2 (14) bytes long sizeof ether_addr is ETHER_ADDR_LEN bytes long On arm, this shows that struct ether_addr needs to be __packed. The first condition muts be true for the bridging code to not dump core. The second one appears to be implicitly relied upon by wi (but many of the rids it sends down likely need __packed too to be safe) and maybe others. It appears to not hurt anything. Notes: svn path=/head/; revision=164785
* Fix typo in commentChristian S.J. Peron2006-11-181-1/+1
| | | | | | | Pointed out by: ru Notes: svn path=/head/; revision=164398
* Currently, drivers that support hardware offload of VLAN tagChristian S.J. Peron2006-11-181-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | processing are forced to toggle this functionality when the card is put in and out of promiscuous mode. The main reason for this is because the hardware strips the VLAN tag, making it impossible for the tag information to show up in network diagnostic tools like tcpdump(1). This change introduces ether_vlan_mtap(), which is called if the mbuf has M_VLANTAG set. VLAN information is extracted from the mbuf and inserted into a stack allocated ether vlan header which is then inserted through the bpf machinery via bpf_mtap2(). The original mbuf's data pointer and lengths are temporarily adjusted to eliminate the original Ethernet header for the duration of the tap operation. This should have no long term effects on the mbuf. Also, define a new macro, ETHER_BPF_MTAP which should be used by drivers which support hardware offload of VLAN tag processing. The fixes for the relevant drivers will follow shortly. Discussed with: rwatson, andre, jhb (and others) Much feedback from: sam, ru MFC after: 1 month [1] [1] The version that is eventually MFCed will be somewhat different then this, as there has been significant work done to the VLAN code in HEAD. Notes: svn path=/head/; revision=164396
* mark struct ether_header packed so gcc honors alignmentSam Leffler2006-11-181-1/+1
| | | | | | | | | | | constratins on arm; this fixes bridging when packets are rx'd so ip headers are 32-bit aligned Reviewed by: imp (and discussed elsewhere) MFC after: 2 weeks Notes: svn path=/head/; revision=164381
* add ETHERTYPE_PAE for EAPOL/802.1xSam Leffler2004-10-051-0/+1
| | | | Notes: svn path=/head/; revision=136154