aboutsummaryrefslogtreecommitdiff
path: root/sys/netgraph/ng_base.c
Commit message (Collapse)AuthorAgeFilesLines
* netgraph: Fix ng_ether's shutdown handingMark Johnston2020-12-231-3/+1
| | | | | | | | | | | | | | | | | | | | | | | 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
* net: clean up empty lines in .c and .h filesMateusz Guzik2020-09-011-3/+2
| | | | Notes: svn path=/head/; revision=365071
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)Pawel Biernacki2020-02-261-3/+6
| | | | | | | | | | | | | | | | | | | r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are still not MPSAFE (or already are but aren’t properly marked). Use it in preparation for a general review of all nodes. This is non-functional change that adds annotations to SYSCTL_NODE and SYSCTL_PROC nodes using one of the soon-to-be-required flags. Mark all obvious cases as MPSAFE. All entries that haven't been marked as MPSAFE before are by default marked as NEEDGIANT Approved by: kib (mentor, blanket) Commented by: kib, gallatin, melifaro Differential Revision: https://reviews.freebsd.org/D23718 Notes: svn path=/head/; revision=358333
* netgraph(4) callouts need to be executed in the network epoch.Gleb Smirnoff2020-02-051-0/+3
| | | | Notes: svn path=/head/; revision=357557
* Netgraph queue processing thread must process all its itemsGleb Smirnoff2020-01-151-0/+4
| | | | | | | | | in the network epoch. Reported by: Michael Zhilin <mizhka@ > Notes: svn path=/head/; revision=356749
* Remove the deprecated timeout(9) interface.John Baldwin2019-12-131-1/+1
| | | | | | | | | | All in-tree consumers have been converted to callout(9). Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D22602 Notes: svn path=/head/; revision=355732
* Remove extra M_ZERO from NG_MKRESPONSE() argument.Alexander Motin2018-08-201-1/+1
| | | | | | | | | | NG_MKRESPONSE() sets M_ZERO by itself. Submitted by: Dmitry Luhtionov <dmitryluhtionov@gmail.com> MFC after: 1 week Notes: svn path=/head/; revision=338105
* Use the new VNET_DEFINE_STATIC macro when we are defining static VNETAndrew Turner2018-07-241-7/+7
| | | | | | | | | | | variables. Reviewed by: bz Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D16147 Notes: svn path=/head/; revision=336676
* Fix return value from ng_uncallout().Hans Petter Selasky2016-12-021-1/+5
| | | | | | | | | | | | | callout_stop() recently started returning -1 when the callout is already stopped, which is not handled by the netgraph code. Properly filter the return value. Netgraph callers only want to know if the callout was cancelled and not draining or already stopped. Discussed with: julian, glebius MFC after: 2 weeks Notes: svn path=/head/; revision=309404
* Fix improper use of "its".Bryan Drewery2016-11-081-3/+3
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=308457
* Avoid panic from ng_uncallout when unpluggin ethernet cable with activeSean Bruno2016-08-081-1/+1
| | | | | | | | | | | | PPTP VPN connection. Submitted by: Michael Zhilin <mizhka@gmail.com> Reviewed by: ngie MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D7209 Notes: svn path=/head/; revision=303848
* sys/netgraph: spelling fixes in comments.Pedro F. Giffuni2016-04-291-2/+2
| | | | | | | No functional change. Notes: svn path=/head/; revision=298813
* Cleanup unnecessary semicolons from the kernel.Pedro F. Giffuni2016-04-101-1/+1
| | | | | | | Found with devel/coccinelle. Notes: svn path=/head/; revision=297793
* These files were getting sys/malloc.h and vm/uma.h with header pollutionGleb Smirnoff2016-02-011-0/+1
| | | | | | | via sys/mbuf.h Notes: svn path=/head/; revision=295126
* Revise default limit for maximum of netgraph data items.Gleb Smirnoff2015-02-121-1/+1
| | | | | | | | With modern internet speeds the limit can be reached even on a single L2TP link. Notes: svn path=/head/; revision=278640
* Fix multiple incorrect SYSCTL arguments in the kernel:Hans Petter Selasky2014-10-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Wrong integer type was specified. - Wrong or missing "access" specifier. The "access" specifier sometimes included the SYSCTL type, which it should not, except for procedural SYSCTL nodes. - Logical OR where binary OR was expected. - Properly assert the "access" argument passed to all SYSCTL macros, using the CTASSERT macro. This applies to both static- and dynamically created SYSCTLs. - Properly assert the the data type for both static and dynamic SYSCTLs. In the case of static SYSCTLs we only assert that the data pointed to by the SYSCTL data pointer has the correct size, hence there is no easy way to assert types in the C language outside a C-function. - Rewrote some code which doesn't pass a constant "access" specifier when creating dynamic SYSCTL nodes, which is now a requirement. - Updated "EXAMPLES" section in SYSCTL manual page. MFC after: 3 days Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=273377
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-3/+0
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-0/+3
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985
* Extend the meaning of the CTLFLAG_TUN flag to automatically check ifHans Petter Selasky2014-06-271-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | there is an environment variable which shall initialize the SYSCTL during early boot. This works for all SYSCTL types both statically and dynamically created ones, except for the SYSCTL NODE type and SYSCTLs which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to be used in the case a tunable sysctl has a custom initialisation function allowing the sysctl to still be marked as a tunable. The kernel SYSCTL API is mostly the same, with a few exceptions for some special operations like iterating childrens of a static/extern SYSCTL node. This operation should probably be made into a factored out common macro, hence some device drivers use this. The reason for changing the SYSCTL API was the need for a SYSCTL parent OID pointer and not only the SYSCTL parent OID list pointer in order to quickly generate the sysctl path. The motivation behind this patch is to avoid parameter loading cludges inside the OFED driver subsystem. Instead of adding special code to the OFED driver subsystem to post-load tunables into dynamically created sysctls, we generalize this in the kernel. Other changes: - Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask" to "hw.pcic.intr_mask". - Removed redundant TUNABLE statements throughout the kernel. - Some minor code rewrites in connection to removing not needed TUNABLE statements. - Added a missing SYSCTL_DECL(). - Wrapped two very long lines. - Avoid malloc()/free() inside sysctl string handling, in case it is called to initialize a sysctl from a tunable, hence malloc()/free() is not ready when sysctls from the sysctl dataset are registered. - Bumped FreeBSD version to indicate SYSCTL API change. MFC after: 2 weeks Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=267961
* Fix the parse type for NGM_LISTTYPES.Gleb Smirnoff2013-12-291-2/+2
| | | | | | | | | | | | Actually, text versions of generic commands are not used, since ngctl(8) uses binary messages for them. And to request a text command one needs a working ngctl(8). That's why the bug was never discovered. I'm pondering on removing the text support for generic commands. Found by: dim with clang 3.4 Notes: svn path=/head/; revision=260046
* Improve locking model used to protect netgraph topology:Alexander V. Chernikov2013-10-151-22/+26
| | | | | | | | | | | | use rwlocks instead of mutexes on node traversal. Reviewed by: glebius Tested by: Eugene Grosbein <egrosbein@rdtc.ru> MFC after: 2 weeks Sponsored by: Yandex LLC Notes: svn path=/head/; revision=256550
* PR: 168520 170096Craig Rodrigues2013-07-151-0/+3
| | | | | | | | | | | | | | | | | | | | | | | Submitted by: adrian, zec Fix multiple kernel panics when VIMAGE is enabled in the kernel. These fixes are based on patches submitted by Adrian Chadd and Marko Zec. (1) Set curthread->td_vnet to vnet0 in device_probe_and_attach() just before calling device_attach(). This fixes multiple VIMAGE related kernel panics when trying to attach Bluetooth or USB Ethernet devices because curthread->td_vnet is NULL. (2) Set curthread->td_vnet in if_detach(). This fixes kernel panics when detaching networking interfaces, especially USB Ethernet devices. (3) Use VNET_DOMAIN_SET() in ng_btsocket.c (4) In ng_unref_node() set curthread->td_vnet. This fixes kernel panics when detaching Netgraph nodes. Notes: svn path=/head/; revision=253346
* - Correct mispellings of the word necessaryGabor Kovesdan2013-04-171-1/+1
| | | | | | | Submitted by: Christoph Mallon <christoph.mallon@gmx.de> (via private mail) Notes: svn path=/head/; revision=249583
* Ensure that all cases that enqueue a netgraph item for delivery by aRyan Stone2012-09-271-1/+1
| | | | | | | | | | | | | | | | ngthread properly set the item's depth to 1. In particular, prior to this change if ng_snd_item failed to acquire a lock on a node, the item's depth would not be set at all. This fix ensures that the error code from rcvmsg/ rcvdata is properly passed back to the apply callback. For example, this fixes a bug where an error from rcvmsg/rcvdata would not previously propagate back to a libnetgraph consumer when the message was queued. Reviewed by: mav MFC after: 1 month Sponsored by: Sandvine Incorporated Notes: svn path=/head/; revision=241009
* Revert r231829, that was my braino.Gleb Smirnoff2012-02-221-2/+2
| | | | Notes: svn path=/head/; revision=231997
* Refactor the name hash and the ID hash, that are used to address nodes:Gleb Smirnoff2012-02-161-66/+177
| | | | | | | | | | | | | | | | | | | | | - Make hash sizes growable, to satisfy users running large mpd installations, having thousands of nodes. - NG_NAMEHASH() proved to give a very bad distribution in real life name sets, while generic hash32_str(name, HASHINIT) proved to give an even one, so you the latter for name hash. - Do not store unnamed nodes in slot 0 of name hash, no reason for that. - Use the ID hash in cases when we need to run through all nodes: the NGM_LISTNODES command and in the vnet_netgraph_uninit(). - Implement NGM_LISTNODES and NGM_LISTNAMES as separate code, the former iterates through the ID hash, and the latter through the name hash. - Keep count of all nodes and of named nodes, so that we don't need to count nodes in NGM_LISTNODES and NGM_LISTNAMES. The counters are also used to estimate whether we need to grow hashes. - Close a race between two threads running ng_name_node() assigning same name to different nodes. Notes: svn path=/head/; revision=231831
* Specify correct loading order for core of netgraph(4).Gleb Smirnoff2012-02-161-2/+2
| | | | Notes: svn path=/head/; revision=231830
* Supply correct "how" argument to the uma_zcreate().Gleb Smirnoff2012-02-161-2/+2
| | | | Notes: svn path=/head/; revision=231829
* Fix includes list.Gleb Smirnoff2012-02-151-2/+1
| | | | | | | Submitted by: bde Notes: svn path=/head/; revision=231766
* Trim double empty lines.Gleb Smirnoff2012-02-151-8/+0
| | | | Notes: svn path=/head/; revision=231765
* Remove testing stuff, reducing kernel memory footprint by 1 Kb.Gleb Smirnoff2012-02-151-29/+0
| | | | | | | | Anyway, when we are building a LINT kernel, all these macros are tested via nodes. Notes: svn path=/head/; revision=231764
* In ng_bypass() add more protection against potential raceGleb Smirnoff2012-02-151-0/+4
| | | | | | | with ng_rmnode() and its followers. Notes: svn path=/head/; revision=231761
* style(9): sort includes.Gleb Smirnoff2012-02-151-6/+6
| | | | Notes: svn path=/head/; revision=231760
* Convert locks that protect name hash, ID hash and typelist fromGleb Smirnoff2012-01-231-60/+61
| | | | | | | | | | | mutex(9) to rwlock(9) based locks. While here remove dropping lock when processing NGM_LISTNODES, and NGM_LISTTYPES generic commands. We don't need to drop it since memory allocation is done with M_NOWAIT. Notes: svn path=/head/; revision=230480
* style(9), whitespace and spelling nits.Gleb Smirnoff2011-12-301-104/+78
| | | | Notes: svn path=/head/; revision=229003
* Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs.Ed Schouten2011-11-071-3/+6
| | | | | | | This means that their use is restricted to a single C file. Notes: svn path=/head/; revision=227293
* Constify "address" argument of ng_address_path().Max Khon2011-11-061-1/+1
| | | | Notes: svn path=/head/; revision=227130
* - If KDB & NETGRAPH_DEBUG are on, print traces on discovered failedGleb Smirnoff2011-10-271-0/+6
| | | | | | | | invariants. - Reduce tautology in NETGRAPH_DEBUG output. Notes: svn path=/head/; revision=226829
* - Use refcount(9) API to manage node and hook refcounting.Gleb Smirnoff2011-07-041-15/+6
| | | | | | | | | | | - Make ng_unref_node() void, since caller shouldn't be interested in whether node is valid after call or not, since it can't be guaranteed to be valid. [1] Ok from: julian [1] Notes: svn path=/head/; revision=223754
* Fix error where error variable was assigned result of comparison,Gleb Smirnoff2011-04-171-1/+1
| | | | | | | | | | instead of function return value. Submitted by: Przemyslaw Frasunek <przemyslaw frasunek.com> MFC after: 4 days Notes: svn path=/head/; revision=220745
* Improve locking of creating and dropping links in the graph, acquiringGleb Smirnoff2011-03-211-51/+46
| | | | | | | | | | | | | | | | the topology mutex in the following functions, that manipulate pointers to peer nodes: - ng_bypass() - ng_path2noderef() when switching to the next node in sequence. Rewrite the function a bit. - ng_address_hook() - ng_address_path() This patch improves stability of large mpd5 installations. Notes: svn path=/head/; revision=219827
* After some off-list discussion, revert a number of changes to theDimitry Andric2010-11-221-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | DPCPU_DEFINE and VNET_DEFINE macros, as these cause problems for various people working on the affected files. A better long-term solution is still being considered. This reversal may give some modules empty set_pcpu or set_vnet sections, but these are harmless. Changes reverted: ------------------------------------------------------------------------ r215318 | dim | 2010-11-14 21:40:55 +0100 (Sun, 14 Nov 2010) | 4 lines Instead of unconditionally emitting .globl's for the __start_set_xxx and __stop_set_xxx symbols, only emit them when the set_vnet or set_pcpu sections are actually defined. ------------------------------------------------------------------------ r215317 | dim | 2010-11-14 21:38:11 +0100 (Sun, 14 Nov 2010) | 3 lines Apply the STATIC_VNET_DEFINE and STATIC_DPCPU_DEFINE macros throughout the tree. ------------------------------------------------------------------------ r215316 | dim | 2010-11-14 21:23:02 +0100 (Sun, 14 Nov 2010) | 2 lines Add macros to define static instances of VNET_DEFINE and DPCPU_DEFINE. Notes: svn path=/head/; revision=215701
* Apply the STATIC_VNET_DEFINE and STATIC_DPCPU_DEFINE macros throughoutDimitry Andric2010-11-141-3/+3
| | | | | | | the tree. Notes: svn path=/head/; revision=215317
* Increase the target buffer for performing NGM_ASCII2BINARY conversionMarko Zec2010-05-131-1/+1
| | | | | | | | | | | | | | from 2000 bytes to 20 Kbytes, which now matches the buffer size used for NGM_BINARY2ASCII conversions. The aim of this change is to allow for bigger binary structures to be managed via netgraph ASCII messages, until we come up with an API improvement which would get rid of such arbitrary hardcoded limits. MFC after: 3 days Notes: svn path=/head/; revision=208036
* When destroying a vnet, shut down all netgraph nodes tied to that vnetMarko Zec2010-05-031-18/+32
| | | | | | | | | | | | before proceeding with dismantling other protocol domains. This change only affects options VIMAGE builds. Reviewed by: julian, bz MFC after: 3 days Notes: svn path=/head/; revision=207572
* (S)LIST_HEAD_INITIALIZER takes a (S)LIST_HEAD as an argument.Antoine Brodin2009-12-281-1/+1
| | | | | | | | | | | | Fix some wrong usages. Note: this does not affect generated binaries as this argument is not used. PR: 137213 Submitted by: Eygene Ryabinkin (initial version) MFC after: 1 month Notes: svn path=/head/; revision=201145
* Merge the remainder of kern_vimage.c and vimage.h into vnet.c andRobert Watson2009-08-011-1/+0
| | | | | | | | | | | | | 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-20/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove unused VNET_SET() and related macros; only VNET_GET() isRobert Watson2009-07-161-3/+3
| | | | | | | | | | | | ever actually used. Rename VNET_GET() to VNET() to shorten variable references. Discussed with: bz, julian Reviewed by: bz Approved by: re (kensmith, kib) Notes: svn path=/head/; revision=195727
* Build on Jeff Roberson's linker-set based dynamic per-CPU allocatorRobert Watson2009-07-141-42/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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