aboutsummaryrefslogtreecommitdiff
path: root/sys/netgraph/ng_ether.c
Commit message (Collapse)AuthorAgeFilesLines
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-231-2/+0
| | | | | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/ Similar commit in current: (cherry picked from commit 95ee2897e98f)
* ng_ether: Create netgraph nodes for bridge interfaces.Yoshihiro Takahashi2021-10-021-3/+6
| | | | | | | | Create netgraph nodes for bridge interfaces when the ng_ether module is loaded. If a bridge interface is created after loading the ng_ether module, a netgraph node is created via ether_ifattach(). (cherry picked from commit d653b188e89b5e44b2708342c7d3b789398f9cde)
* netgraph: Fix ng_ether's shutdown handingMark Johnston2020-12-231-7/+6
| | | | | | | | | | | | | | | | | | | | | | | When tearing down a VNET, netgraph sends shutdown messages to all of the nodes before detaching interfaces (SI_SUB_NETGRAPH comes before SI_SUB_INIT_IF in teardown order). ng_ether nodes handle this by destroying themselves without detaching from the parent ifnet. Then, when ifnets go away they detach their ng_ether nodes again, triggering a use-after-free. Handle this by modifying ng_ether_shutdown() to detach from the ifnet. If the shutdown was triggered by an ifnet being destroyed, we will clear priv->ifp in the ng_ether detach callback, so priv->ifp may be NULL. Also get rid of the printf in vnet_netgraph_uninit(). It can be triggered trivially by ng_ether since ng_ether_shutdown() persists the node unless NG_REALLY_DIE is set. PR: 233622 Reviewed by: afedorov, kp, Lutz Donnerhacke MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D27662
* ng_ether: Enter NET_EPOCH where requiredKristof Provost2020-09-021-3/+0
| | | | | | | | | | | | | | | | | We must enter NET_EPOCH before calling ether_output_frame(). Several of the functions it calls (pfil_run_hooks, if_transmit) expect to be running in the NET_EPOCH. While here remove an unneeded EPOCH entry (which wasn't wide enough to cover BRIDGE_INPUT). PR: 248958 Reviewed by: glebius, bz (previous version), melifaro (previous version) Tested by: manu Differential Revision: https://reviews.freebsd.org/D26226 Notes: svn path=/head/; revision=365246
* net: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-1/+0
| | | | Notes: svn path=/head/; revision=365071
* Don't use if_maddr_rlock() in ng_ether(4), use epoch(9) directly instead.Gleb Smirnoff2019-10-101-2/+3
| | | | Notes: svn path=/head/; revision=353421
* Widen NET_EPOCH coverage.Gleb Smirnoff2019-10-071-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When epoch(9) was introduced to network stack, it was basically dropped in place of existing locking, which was mutexes and rwlocks. For the sake of performance mutex covered areas were as small as possible, so became epoch covered areas. However, epoch doesn't introduce any contention, it just delays memory reclaim. So, there is no point to minimise epoch covered areas in sense of performance. Meanwhile entering/exiting epoch also has non-zero CPU usage, so doing this less often is a win. Not the least is also code maintainability. In the new paradigm we can assume that at any stage of processing a packet, we are inside network epoch. This makes coding both input and output path way easier. On output path we already enter epoch quite early - in the ip_output(), in the ip6_output(). This patch does the same for the input path. All ISR processing, network related callouts, other ways of packet injection to the network stack shall be performed in net_epoch. Any leaf function that walks network configuration now asserts epoch. Tricky part is configuration code paths - ioctls, sysctls. They also call into leaf functions, so some need to be changed. This patch would introduce more epoch recursions (see EPOCH_TRACE) than we had before. They will be cleaned up separately, as several of them aren't trivial. Note, that unlike a lock recursion the epoch recursion is safe and just wastes a bit of resources. Reviewed by: gallatin, hselasky, cy, adrian, kristof Differential Revision: https://reviews.freebsd.org/D19111 Notes: svn path=/head/; revision=353292
* The interface name must be sanitized before the search to match the existingLuiz Otavio O Souza2018-08-151-2/+2
| | | | | | | | | | | | netgraph node. Fixes the search (and use) of VLANs with dot notation. Obtained from: pfSense Sponsored by: Rubicon Communications, LLC (Netgate) Notes: svn path=/head/; revision=337844
* Catch up two more places to the V_ifnet change to a CK_STAILQ.John Baldwin2018-05-241-1/+1
| | | | Notes: svn path=/head/; revision=334123
* sys/netgraph: spelling fixes in comments.Pedro F. Giffuni2016-04-291-1/+1
| | | | | | | No functional change. Notes: svn path=/head/; revision=298813
* Move iflladdr_event eventhandler invocation to if_setlladdr.Alexander V. Chernikov2015-11-141-2/+0
| | | | | | | Suggested by: glebius Notes: svn path=/head/; revision=290819
* Use lladdr_event to propagate gratiotus arp.Alexander V. Chernikov2015-11-091-1/+2
| | | | | | | Differential Revision: https://reviews.freebsd.org/D4019 Notes: svn path=/head/; revision=290603
* Remove struct arpcom. It is unused by most interface types, that allocateGleb Smirnoff2014-11-071-1/+1
| | | | | | | | | | | it, except Ethernet, where it carried ng_ether(4) pointer. For now carry the pointer in if_l2com directly. Sponsored by: Netflix Sponsored by: Nginx, Inc. Notes: svn path=/head/; revision=274231
* Include necessary headers that now are available due to pollutionGleb Smirnoff2013-10-281-0/+1
| | | | | | | | | | via if_var.h. Sponsored by: Netflix Sponsored by: Nginx, Inc. Notes: svn path=/head/; revision=257241
* ng_ether_ifnet_arrival_event: check interface type before using IFP2NGAndriy Gapon2013-02-041-1/+7
| | | | | | | | | | | | | | The check is copied from vnet_ng_ether_init. Not sure if it covers all the types that we want to support with ng_ether. Reported by: markj Discussed with: zec MFC after: 10 days X-MFC with: r246245 Notes: svn path=/head/; revision=246324
* ng_ether: track interface renamingAndriy Gapon2013-02-021-4/+56
| | | | | | | | | | | | | | Also sanitize interface names that can potentially contain characters that are prohibited in netgraph names. PR: kern/154850 (sanitizing of names) Discussed with: eri, melifaro Submitted by: Nikolay Denev <ndenev@gmail.com> (sanitizing code) Reviewed by: eri, glebius MFC after: 17 days Notes: svn path=/head/; revision=246245
* Mechanically remove the last stray remains of spl* calls from net*/*.Andre Oppermann2012-10-181-7/+0
| | | | | | | They have been Noop's for a long time now. Notes: svn path=/head/; revision=241686
* Add version so others can depend on this moduleEd Maste2012-07-271-0/+2
| | | | Notes: svn path=/head/; revision=238844
* remove RESTARTABLE_PANICS optionAndriy Gapon2011-07-251-3/+0
| | | | | | | | | | | | | | | | | | | This is done per request/suggestion from John Baldwin who introduced the option. Trying to resume normal system operation after a panic is very unpredictable and dangerous. It will become even more dangerous when we allow a thread in panic(9) to penetrate all lock contexts. I understand that the only purpose of this option was for testing scenarios potentially resulting in panic. Suggested by: jhb Reviewed by: attilio, jhb X-MFC-After: never Approved by: re (kib) Notes: svn path=/head/; revision=224307
* Clear pending ifnet events, in an attempt at preventingMarko Zec2011-07-161-0/+2
| | | | | | | | | | ng_ether_link_state() from being dispatched after we have cleared our IFP2NG(ifp). MFC after: 3 days Notes: svn path=/head/; revision=224107
* Be consistent with r160968: keep autoSrcAddr flag untouched whenGleb Smirnoff2011-06-231-1/+0
| | | | | | | | | node receives NGM_SHUTDOWN. Submitted by: pluknet Notes: svn path=/head/; revision=223469
* Declare a new EVENTHANDLER called iflladdr_event which signals that the L2Andrew Thompson2010-01-181-0/+1
| | | | | | | | | | | | | | | | address on an interface has changed. This lets stacked interfaces such as vlan(4) detect that their lower interface has changed and adjust things in order to keep working. Previously this situation broke at least vlan(4) and lagg(4) configurations. The EVENTHANDLER_INVOKE call was not placed within if_setlladdr() due to the risk of a loop. PR: kern/142927 Submitted by: Nikolay Denev Notes: svn path=/head/; revision=202588
* Send link state change control messages to "orphans" hook as well.Max Khon2010-01-091-6/+10
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=201924
* Merge the remainder of kern_vimage.c and vimage.h into vnet.c andRobert Watson2009-08-011-1/+1
| | | | | | | | | | | | | vnet.h, we now use jails (rather than vimages) as the abstraction for virtualization management, and what remained was specific to virtual network stacks. Minor cleanups are done in the process, and comments updated to reflect these changes. Reviewed by: bz Approved by: re (vimage blanket) Notes: svn path=/head/; revision=196019
* Introduce and use a sysinit-based initialization scheme for virtualRobert Watson2009-07-231-23/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | network stacks, VNET_SYSINIT: - Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will occur each time a network stack is instantiated and destroyed. In the !VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT. For the VIMAGE case, we instead use SYSINIT's to track their order and properties on registration, using them for each vnet when created/ destroyed, or immediately on module load for already-started vnets. - Remove vnet_modinfo mechanism that existed to serve this purpose previously, as well as its dependency scheme: we now just use the SYSINIT ordering scheme. - Implement VNET_DOMAIN_SET() to allow protocol domains to declare that they want init functions to be called for each virtual network stack rather than just once at boot, compiling down to DOMAIN_SET() in the non-VIMAGE case. - Walk all virtualized kernel subsystems and make use of these instead of modinfo or DOMAIN_SET() for init/uninit events. In some cases, convert modular components from using modevent to using sysinit (where appropriate). In some cases, do minor rejuggling of SYSINIT ordering to make room for or better manage events. Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup) Discussed with: jhb, bz, julian, zec Reviewed by: bz Approved by: re (VIMAGE blanket) Notes: svn path=/head/; revision=195837
* Build on Jeff Roberson's linker-set based dynamic per-CPU allocatorRobert Watson2009-07-141-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (DPCPU), as suggested by Peter Wemm, and implement a new per-virtual network stack memory allocator. Modify vnet to use the allocator instead of monolithic global container structures (vinet, ...). This change solves many binary compatibility problems associated with VIMAGE, and restores ELF symbols for virtualized global variables. Each virtualized global variable exists as a "reference copy", and also once per virtual network stack. Virtualized global variables are tagged at compile-time, placing the in a special linker set, which is loaded into a contiguous region of kernel memory. Virtualized global variables in the base kernel are linked as normal, but those in modules are copied and relocated to a reserved portion of the kernel's vnet region with the help of a the kernel linker. Virtualized global variables exist in per-vnet memory set up when the network stack instance is created, and are initialized statically from the reference copy. Run-time access occurs via an accessor macro, which converts from the current vnet and requested symbol to a per-vnet address. When "options VIMAGE" is not compiled into the kernel, normal global ELF symbols will be used instead and indirection is avoided. This change restores static initialization for network stack global variables, restores support for non-global symbols and types, eliminates the need for many subsystem constructors, eliminates large per-subsystem structures that caused many binary compatibility issues both for monitoring applications (netstat) and kernel modules, removes the per-function INIT_VNET_*() macros throughout the stack, eliminates the need for vnet_symmap ksym(2) munging, and eliminates duplicate definitions of virtualized globals under VIMAGE_GLOBALS. Bump __FreeBSD_version and update UPDATING. Portions submitted by: bz Reviewed by: bz, zec Discussed with: gnn, jamie, jeff, jhb, julian, sam Suggested by: peter Approved by: re (kensmith) Notes: svn path=/head/; revision=195699
* Use if_maddr_rlock()/if_maddr_runlock() rather than IF_ADDR_LOCK()/Robert Watson2009-06-261-2/+2
| | | | | | | | | | | | | | | | IF_ADDR_UNLOCK() across network device drivers when accessing the per-interface multicast address list, if_multiaddrs. This will allow us to change the locking strategy without affecting our driver programming interface or binary interface. For two wireless drivers, remove unnecessary locking, since they don't actually access the multicast address list. Approved by: re (kib) MFC after: 6 weeks Notes: svn path=/head/; revision=195049
* After cleaning up rt_tables from vnet.h and cleaning up opt_route.hBjoern A. Zeeb2009-06-231-1/+0
| | | | | | | | a lot of files no longer need route.h either. Garbage collect them. While here remove now unneeded vnet.h #includes as well. Notes: svn path=/head/; revision=194739
* Mark ng_ether node hooks as HI_STACK. It is usually the last point whenAlexander Motin2009-06-231-1/+1
| | | | | | | | netgraph may unroll the call stack, and I have found that in some cases 2K guarantied there for i386 may be not enough for NIC driver and BPF. Notes: svn path=/head/; revision=194699
* Introduce a mechanism for detecting calls from outbound path of theMarko Zec2009-06-111-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | network stack when reentering the inbound path from netgraph, and force queueing of mbufs at the outbound netgraph node. The mechanism relies on two components. First, in netgraph nodes where outbound path of the network stack calls into netgraph, the current thread has to be appropriately marked using the new NG_OUTBOUND_THREAD_REF() macro before proceeding to call further into the netgraph topology, and unmarked using the NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller. Second, netgraph nodes which can potentially reenter the network stack in the inbound path have to mark their inbound hooks using NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then detect when there is a danger of a call graph looping back from outbound to inbound path via netgraph, and defer handing off the mbufs to the "inbound" node to a worker thread with a clean stack. In this first pass only the most obvious netgraph nodes have been updated to ensure no outbound to inbound calls can occur. Nodes such as ng_ipfw, ng_gif etc. should be further examined whether a potential for outbound to inbound call looping exists. This commit changes the layout of struct thread, but due to __FreeBSD_version number shortage a version bump has been omitted at this time, nevertheless kernel and modules have to be rebuilt. Reviewed by: julian, rwatson, bz Approved by: julian (mentor) Notes: svn path=/head/; revision=194012
* After r193232 rt_tables in vnet.h are no longer indirectly dependent onBjoern A. Zeeb2009-06-081-2/+0
| | | | | | | | | | | | the ROUTETABLES kernel option thus there is no need to include opt_route.h anymore in all consumers of vnet.h and no longer depend on it for module builds. Remove the hidden include in flowtable.h as well and leave the two explicit #includes in ip_input.c and ip_output.c. Notes: svn path=/head/; revision=193744
* In preparation to make options VIMAGE operational, where needed,Marko Zec2009-04-261-9/+48
| | | | | | | | | | | | | | | | initialize / release netgraph related state in iattach() / idetach() functions called via the vnet module registration / initialization framework, instead of initialization / cleanups being done in mod_event handlers. While here, introduce a crude hack aimed at preventing ng_ether to autoattach to ng_eiface ifnets, which are also netgraph nodes already. Reviewed by: bz Approved by: julian (mentor) Notes: svn path=/head/; revision=191510
* For all files including net/vnet.h directly include opt_route.h andBjoern A. Zeeb2009-02-271-0/+3
| | | | | | | | | | | | | | | | | net/route.h. Remove the hidden include of opt_route.h and net/route.h from net/vnet.h. We need to make sure that both opt_route.h and net/route.h are included before net/vnet.h because of the way MRT figures out the number of FIBs from the kernel option. If we do not, we end up with the default number of 1 when including net/vnet.h and array sizes are wrong. This does not change the list of files which depend on opt_route.h but we can identify them now more easily. Notes: svn path=/head/; revision=189106
* shave about 7% off the overhead of ng_ether by using per-hookJulian Elischer2008-12-251-17/+23
| | | | | | | receive data methods. Notes: svn path=/head/; revision=186488
* Rather than using hidden includes (with cicular dependencies),Bjoern A. Zeeb2008-12-021-0/+1
| | | | | | | | | | | | | | directly include only the header files needed. This reduces the unneeded spamming of various headers into lots of files. For now, this leaves us with very few modules including vnet.h and thus needing to depend on opt_route.h. Reviewed by: brooks, gnn, des, zec, imp Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=185571
* Retire the MALLOC and FREE macros. They are an abomination unto style(9).Dag-Erling Smørgrav2008-10-231-2/+2
| | | | | | | MFC after: 3 months Notes: svn path=/head/; revision=184205
* Commit step 1 of the vimage project, (network stack)Bjoern A. Zeeb2008-08-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | virtualization work done by Marko Zec (zec@). This is the first in a series of commits over the course of the next few weeks. Mark all uses of global variables to be virtualized with a V_ prefix. Use macros to map them back to their global names for now, so this is a NOP change only. We hope to have caught at least 85-90% of what is needed so we do not invalidate a lot of outstanding patches again. Obtained from: //depot/projects/vimage-commit2/... Reviewed by: brooks, des, ed, mav, julian, jamie, kris, rwatson, zec, ... (various people I forgot, different versions) md5 (with a bit of help) Sponsored by: NLnet Foundation, The FreeBSD Foundation X-MFC after: never V_Commit_Message_Reviewed_By: more people than the patch Notes: svn path=/head/; revision=181803
* Implement reference counting for ifmultiaddr, in_multi, and in6_multiBruce M Simpson2007-03-201-3/+18
| | | | | | | | | | | | | | | | | | | | | | structures. Detect when ifnet instances are detached from the network stack and perform appropriate cleanup to prevent memory leaks. This has been implemented in such a way as to be backwards ABI compatible. Kernel consumers are changed to use if_delmulti_ifma(); in_delmulti() is unable to detect interface removal by design, as it performs searches on structures which are removed with the interface. With this architectural change, the panics FreeBSD users have experienced with carp and pfsync should be resolved. Obtained from: p4 branch bms_netdev Reviewed by: andre Sponsored by: Garance A Drosehn Idea from: NetBSD MFC after: 1 month Notes: svn path=/head/; revision=167729
* Turn off by default "feature" that overwrites MAC addressGleb Smirnoff2006-08-041-1/+0
| | | | | | | | | | | on output frames. Many people were confused with not working CARP, ng_bridge(4) and other subsystems, because ng_ether(4) overwritten source MAC address. Notes: svn path=/head/; revision=160968
* Remove the dependency of bridgestp.h on if_bridgevar.h by moving a couple ofAndrew Thompson2006-07-271-1/+0
| | | | | | | private structures to if_bridge.c. Notes: svn path=/head/; revision=160769
* Fixing compilation bustage: net/if_bridgevar.h depends on net/bridgestp.h.Tai-hwa Liang2006-07-271-0/+1
| | | | Notes: svn path=/head/; revision=160739
* Do not force queueing on peer hooks. This was important only forGleb Smirnoff2006-01-121-14/+0
| | | | | | | | | | 5.0-CURRENT. And it looks like this didn't work before Julian's revamp of netgraph queue code. Reviewed by: julian Notes: svn path=/head/; revision=154272
* - Store pointer to the link-level address right in "struct ifnet"Ruslan Ermilov2005-11-111-2/+2
| | | | | | | | | | | | | rather than in ifindex_table[]; all (except one) accesses are through ifp anyway. IF_LLADDR() works faster, and all (except one) ifaddr_byindex() users were converted to use ifp->if_addr. - Stop storing a (pointer to) Ethernet address in "struct arpcom", and drop the IFP2ENADDR() macro; all users have been converted to use IF_LLADDR() instead. Notes: svn path=/head/; revision=152315
* Make IFP2NG() usable as an lvalue.Ruslan Ermilov2005-11-091-4/+3
| | | | Notes: svn path=/head/; revision=152243
* Restore part of the code dropped in rev. 1.25 that makes sure ether_demux()Ruslan Ermilov2005-11-031-0/+9
| | | | | | | | will receive an mbuf chain with Ethernet header in the data portion of the first mbuf. Notes: svn path=/head/; revision=152001
* Further clean up the bridge hooks in if_ethersubr.c and ng_ether.cAndrew Thompson2005-10-141-17/+4
| | | | | | | | | - move the function pointer definitions to if_bridgevar.h - move most of the logic to the new BRIDGE_INPUT and BRIDGE_OUTPUT macros - remove unneeded functions from if_bridgevar.h and sort a little. Notes: svn path=/head/; revision=151305
* Clean up the if_bridge hooks a bit in if_ethersubr.c and ng_ether.c, moveAndrew Thompson2005-10-131-19/+0
| | | | | | | | | the broadcast/multicast test to bridge_input(). Requested by: glebius Notes: svn path=/head/; revision=151282
* A deja vu of:Gleb Smirnoff2005-10-071-2/+41
| | | | | | | | | | | | | | | | | http://lists.freebsd.org/pipermail/cvs-src/2004-October/033496.html The same problem applies to if_bridge(4), too. - Copy-and-paste the if_bridge(4) related block from if_ethersubr.c to ng_ether.c - Add XXXs, so that copy-and-paste would be noticed by any future editors of this code. - Also add XXXs near if_bridge(4) declarations. Silence from: thompsa Notes: svn path=/head/; revision=151063
* Remove bridge(4) from the tree. if_bridge(4) is a full functionalMax Laier2005-09-271-4/+1
| | | | | | | | | | | replacement and has additional features which make it superior. Discussed on: -arch Reviewed by: thompsa X-MFC-after: never (RELENG_6 as transition period) Notes: svn path=/head/; revision=150636
* Propagate rename of IFF_OACTIVE and IFF_RUNNING to IFF_DRV_OACTIVE andRobert Watson2005-08-091-1/+2
| | | | | | | | | | | | | | | | | IFF_DRV_RUNNING, as well as the move from ifnet.if_flags to ifnet.if_drv_flags. Device drivers are now responsible for synchronizing access to these flags, as they are in if_drv_flags. This helps prevent races between the network stack and device driver in maintaining the interface flags field. Many __FreeBSD__ and __FreeBSD_version checks maintained and continued; some less so. Reviewed by: pjd, bz MFC after: 7 days Notes: svn path=/head/; revision=148887