summaryrefslogtreecommitdiff
path: root/sys/netgraph
Commit message (Collapse)AuthorAgeFilesLines
* Merge r196481 from head to stable/8:Robert Watson2009-08-281-2/+2
| | | | | | | | | | | | | | | | | | | Rework global locks for interface list and index management, correcting several critical bugs, including race conditions and lock order issues: Replace the single rwlock, ifnet_lock, with two locks, an rwlock and an sxlock. Either can be held to stablize the lists and indexes, but both are required to write. This allows the list to be held stable in both network interrupt contexts and sleepable user threads across sleeping memory allocations or device driver interactions. As before, writes to the interface list must occur from sleepable contexts. Reviewed by: bz, julian Approved by: re (kib) Notes: svn path=/stable/8/; revision=196626
* Merge the remainder of kern_vimage.c and vimage.h into vnet.c andRobert Watson2009-08-019-9/+7
| | | | | | | | | | | | | 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-237-113/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Reimplement and/or implement vnet list locking by replacing a mostlyRobert Watson2009-07-191-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | unused custom mutex/condvar-based sleep locks with two locks: an rwlock (for non-sleeping use) and sxlock (for sleeping use). Either acquired for read is sufficient to stabilize the vnet list, but both must be acquired for write to modify the list. Replace previous no-op read locking macros, used in various places in the stack, with actual locking to prevent race conditions. Callers must declare when they may perform unbounded sleeps or not when selecting how to lock. Refactor vnet sysinits so that the vnet list and locks are initialized before kernel modules are linked, as the kernel linker will use them for modules loaded by the boot loader. Update various consumers of these KPIs based on whether they may sleep or not. Reviewed by: bz Approved by: re (kib) Notes: svn path=/head/; revision=195760
* Remove unused VNET_SET() and related macros; only VNET_GET() isRobert Watson2009-07-163-5/+5
| | | | | | | | | | | | 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-147-101/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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
* Fix infinite loop in ng_iface, that happens when packet passes out viaAlexander Motin2009-07-011-1/+2
| | | | | | | | | | | | two different ng interfaces sequentially due to tunnelling. PR: kern/134557 Submitted by: Mikolaj Golub Approved by: re (kensmith) MFC after: 3 days Notes: svn path=/head/; revision=195231
* - Turn the third (islocked) argument of the knote call into flags parameter.Stanislav Sedov2009-06-281-1/+1
| | | | | | | | | | | | | | Introduce the new flag KNF_NOKQLOCK to allow event callers to be called without KQ_LOCK mtx held. - Modify VFS knote calls to always use KNF_NOKQLOCK flag. This is required for ZFS as its getattr implementation may sleep. Approved by: re (rwatson) Reviewed by: kib MFC after: 2 weeks Notes: svn path=/head/; revision=195148
* 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
* Update Netgraph nodes to use if_addr_rlock()/if_addr_runlock() insteadRobert Watson2009-06-262-5/+5
| | | | | | | | | of IF_ADDR_LOCK()/IF_ADDR_UNLOCK() when iterating ifp->if_addrhead. MFC after: 6 weeks Notes: svn path=/head/; revision=195024
* Use proper form of gnu designated initalizers. This letsRoman Divacky2009-06-241-1/+1
| | | | | | | | | | clang compile this files. Approved by: ed (mentor) Silence from: harti (maintainer?) Notes: svn path=/head/; revision=194825
* After cleaning up rt_tables from vnet.h and cleaning up opt_route.hBjoern A. Zeeb2009-06-232-2/+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
* Fix a typeo in the frame len function to unbreak the build, make it shorterAndrew Thompson2009-06-231-2/+2
| | | | | | | while I am here. Notes: svn path=/head/; revision=194682
* - Make struct usb_xfer opaque so that drivers can not access the internalsAndrew Thompson2009-06-232-106/+172
| | | | | | | - Reduce the number of headers needed for a usb driver, the common case is just usb.h and usbdi.h Notes: svn path=/head/; revision=194677
* s/usb2_/usb_|usbd_/ on all function names for the USB stack.Andrew Thompson2009-06-152-52/+52
| | | | Notes: svn path=/head/; revision=194228
* Assign ng_eiface nodes a netgraph name on instantiation, in a way whichMarko Zec2009-06-121-6/+4
| | | | | | | | | | is consistent with the current behavior of ng_iface, i.e. borrow the same naming code from ng_iface.c. Approved by: julian (mentor) Notes: svn path=/head/; revision=194051
* Introduce a mechanism for detecting calls from outbound path of theMarko Zec2009-06-116-6/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Close long existed race with net.inet.ip.fw.one_pass = 0:Oleg Bulyzhin2009-06-092-0/+4
| | | | | | | | | | | | | | | | | If packet leaves ipfw to other kernel subsystem (dummynet, netgraph, etc) it carries pointer to matching ipfw rule. If this packet then reinjected back to ipfw, ruleset processing starts from that rule. If rule was deleted meanwhile, due to existed race condition panic was possible (as well as other odd effects like parsing rules in 'reap list'). P.S. this commit changes ABI so userland ipfw related binaries should be recompiled. MFC after: 1 month Tested by: Mikolaj Golub Notes: svn path=/head/; revision=193859
* World now builds without these defines, so eliminate them.Warner Losh2009-06-091-9/+0
| | | | | | | Approved by: julian@ Notes: svn path=/head/; revision=193812
* After r193232 rt_tables in vnet.h are no longer indirectly dependent onBjoern A. Zeeb2009-06-083-6/+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
* Introduce an infrastructure for dismantling vnet instances.Marko Zec2009-06-081-3/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Vnet modules and protocol domains may now register destructor functions to clean up and release per-module state. The destructor mechanisms can be triggered by invoking "vimage -d", or a future equivalent command which will be provided via the new jail framework. While this patch introduces numerous placeholder destructor functions, many of those are currently incomplete, thus leaking memory or (even worse) failing to stop all running timers. Many of such issues are already known and will be incrementaly fixed over the next weeks in smaller incremental commits. Apart from introducing new fields in structs ifnet, domain, protosw and vnet_net, which requires the kernel and modules to be rebuilt, this change should have no impact on nooptions VIMAGE builds, since vnet destructors can only be called in VIMAGE kernels. Moreover, destructor functions should be in general compiled in only in options VIMAGE builds, except for kernel modules which can be safely kldunloaded at run time. Bump __FreeBSD_version to 800097. Reviewed by: bz, julian Approved by: rwatson, kib (re), julian (mentor) Notes: svn path=/head/; revision=193731
* Rework socket upcalls to close some races with setup/teardown of upcalls.John Baldwin2009-06-012-27/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Each socket upcall is now invoked with the appropriate socket buffer locked. It is not permissible to call soisconnected() with this lock held; however, so socket upcalls now return an integer value. The two possible values are SU_OK and SU_ISCONNECTED. If an upcall returns SU_ISCONNECTED, then the soisconnected() will be invoked on the socket after the socket buffer lock is dropped. - A new API is provided for setting and clearing socket upcalls. The API consists of soupcall_set() and soupcall_clear(). - To simplify locking, each socket buffer now has a separate upcall. - When a socket upcall returns SU_ISCONNECTED, the upcall is cleared from the receive socket buffer automatically. Note that a SO_SND upcall should never return SU_ISCONNECTED. - All this means that accept filters should now return SU_ISCONNECTED instead of calling soisconnected() directly. They also no longer need to explicitly clear the upcall on the new socket. - The HTTP accept filter still uses soupcall_set() to manage its internal state machine, but other accept filters no longer have any explicit knowlege of socket upcall internals aside from their return value. - The various RPC client upcalls currently drop the socket buffer lock while invoking soreceive() as a temporary band-aid. The plan for the future is to add a new flag to allow soreceive() to be called with the socket buffer locked. - The AIO callback for socket I/O is now also invoked with the socket buffer locked. Previously sowakeup() would drop the socket buffer lock only to call aio_swake() which immediately re-acquired the socket buffer lock for the duration of the function call. Discussed with: rwatson, rmacklem Notes: svn path=/head/; revision=193272
* s/usb2_/usb_/ on all typedefs for the USB stack.Andrew Thompson2009-05-292-16/+16
| | | | Notes: svn path=/head/; revision=193045
* s/usb2_/usb_/ on all C structs for the USB stack.Andrew Thompson2009-05-283-42/+42
| | | | Notes: svn path=/head/; revision=192984
* Hook ubt and ubtbcmfw back up to the build.Andrew Thompson2009-05-271-2/+1
| | | | Notes: svn path=/head/; revision=192909
* move ng_ubt_var.h back to its original placeAndrew Thompson2009-05-271-0/+131
| | | | Notes: svn path=/head/; revision=192907
* move ng_ubt.c back to its original placeAndrew Thompson2009-05-271-0/+1722
| | | | Notes: svn path=/head/; revision=192906
* move ubtbcmfw.c back to its original placeAndrew Thompson2009-05-271-0/+427
| | | | Notes: svn path=/head/; revision=192905
* Delete the bluetooth drivers for the old usb stack.Andrew Thompson2009-05-274-3091/+0
| | | | Notes: svn path=/head/; revision=192903
* Fix copy-paste bug in NGM_NETFLOW_SETCONFIG argument size verification.Alexander Motin2009-05-131-1/+1
| | | | | | | | | PR: kern/134220 Submitted by: Eugene Mychlo MFC after: 1 week Notes: svn path=/head/; revision=192032
* Unbreak LINT build, caused by a change in struct ng_node layout introducedMarko Zec2009-05-051-0/+1
| | | | | | | | | with r191816, which become uncovered only with NETGRAPH_DEBUG defined. NOT approved by mentor (julian) due to emergency. Notes: svn path=/head/; revision=191827
* Change the curvnet variable from a global const struct vnet *,Marko Zec2009-05-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | previously always pointing to the default vnet context, to a dynamically changing thread-local one. The currvnet context should be set on entry to networking code via CURVNET_SET() macros, and reverted to previous state via CURVNET_RESTORE(). Recursions on curvnet are permitted, though strongly discuouraged. This change should have no functional impact on nooptions VIMAGE kernel builds, where CURVNET_* macros expand to whitespace. The curthread->td_vnet (aka curvnet) variable's purpose is to be an indicator of the vnet context in which the current network-related operation takes place, in case we cannot deduce the current vnet context from any other source, such as by looking at mbuf's m->m_pkthdr.rcvif->if_vnet, sockets's so->so_vnet etc. Moreover, so far curvnet has turned out to be an invaluable consistency checking aid: it helps to catch cases when sockets, ifnets or any other vnet-aware structures may have leaked from one vnet to another. The exact placement of the CURVNET_SET() / CURVNET_RESTORE() macros was a result of an empirical iterative process, whith an aim to reduce recursions on CURVNET_SET() to a minimum, while still reducing the scope of CURVNET_SET() to networking only operations - the alternative would be calling CURVNET_SET() on each system call entry. In general, curvnet has to be set in three typicall cases: when processing socket-related requests from userspace or from within the kernel; when processing inbound traffic flowing from device drivers to upper layers of the networking stack, and when executing timer-driven networking functions. This change also introduces a DDB subcommand to show the list of all vnet instances. Approved by: julian (mentor) Notes: svn path=/head/; revision=191816
* In preparation to make options VIMAGE operational, where needed,Marko Zec2009-04-265-15/+159
| | | | | | | | | | | | | | | | 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
* Lock the interface address list while building replies toRobert Watson2009-04-191-0/+2
| | | | | | | | | NGM_CISCO_COOKIE messages in ng_iface. MFC after: 2 weeks Notes: svn path=/head/; revision=191284
* Lock interface address list when building a reply to NGM_EIFACE_GET_IFADDRSRobert Watson2009-04-191-0/+3
| | | | | | | | | messages in ng_eiface. MFC after: 2 weeks Notes: svn path=/head/; revision=191283
* Switch ubtbcmfw(4) to use si_drv1 instead of storing the unit number.Ed Schouten2009-04-171-39/+21
| | | | | | | | | The unit number is still used to store the type of the device node. Approved by: emax Notes: svn path=/head/; revision=191226
* Change if_output to take a struct route as its fourth argument in orderKip Macy2009-04-162-6/+8
| | | | | | | | | to allow passing a cached struct llentry * down to L2 Reviewed by: rwatson Notes: svn path=/head/; revision=191148
* Make Netgraph compile with Clang.Ed Schouten2009-03-033-14/+12
| | | | | | | | | | | | | | | | | | | Clang disallows structs with variable length arrays to be nested inside other structs, because this is in violation with ISO C99. Even though we can keep bugging the LLVM folks about this issue, we'd better just fix our code to not do this. This code seems to be the only code in the entire source tree that does this. I haven't tested this patch by using the kernel modules in question, but Diane Bruce and I have compared disassembled versions of these kernel modules. We would have expected them to be exactly the same, but due to randomness in the register allocator and reordering of instructions, there were some minor differences. Approved by: julian Notes: svn path=/head/; revision=189315
* Add memmove() to the kernel, making the kernel compile with Clang.Ed Schouten2009-02-282-5/+0
| | | | | | | | | | | | | | | When copying big structures, LLVM generates calls to memmove(), because it may not be able to figure out whether structures overlap. This caused linker errors to occur. memmove() is now implemented using bcopy(). Ideally it would be the other way around, but that can be solved in the future. On ARM we don't do add anything, because it already has memmove(). Discussed on: arch@ Reviewed by: rdivacky Notes: svn path=/head/; revision=189170
* For all files including net/vnet.h directly include opt_route.h andBjoern A. Zeeb2009-02-273-0/+7
| | | | | | | | | | | | | | | | | 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
* Update comment. soalloc() is no longer performing M_WAITOK memory allocations.Maksim Yevmenkin2009-02-101-14/+6
| | | | | | | | Submitted by: ru MFC after: 3 days Notes: svn path=/head/; revision=188452
* Allow unprivileged users to run l2ping(8).Maksim Yevmenkin2009-02-041-5/+0
| | | | | | | MFC after: 1 month Notes: svn path=/head/; revision=188132
* Check for infinite recursion possible on some broken PPTP/L2TP/... VPN setups.Alexander Motin2009-01-202-0/+21
| | | | | | | | | | Mark packets with mbuf_tag on first interface passage and drop on second. PR: ports/129625, ports/125303, MFC after: 2 weeks Notes: svn path=/head/; revision=187495
* Properly return error code to the caller. This should fix the followingMaksim Yevmenkin2009-01-191-20/+26
| | | | | | | | | | | | | panic in ng_l2cap(4). panic: ng_l2cap_l2ca_con_req: ubt0l2cap - could not find connection! While i'm here get rid of few goto's. MFC after: 1 week Notes: svn path=/head/; revision=187454
* If source mbuf chain consists of only one mbuf, use it directly as sourceAlexander Motin2009-01-181-34/+51
| | | | | | | buffer to avoid extra copying. Notes: svn path=/head/; revision=187410
* Use m_unshare()+m_copyback() instead of m_freem()+m_devget() to keepAlexander Motin2009-01-183-49/+80
| | | | | | | | original mbuf chain headers. It can be less efficient in some cases, but it looks better then mess of copying headers into the nonempty chain. Notes: svn path=/head/; revision=187405
* Remove strict limitation on minimal multilink MRRU. RFC claims that MRRUAlexander Motin2009-01-181-5/+6
| | | | | | | | | | of 1500 must be supported, but allows smaller values to be negotiated. Enforce specified MRRU for outgoing frames. MFC after: 2 weeks Notes: svn path=/head/; revision=187387
* Mark ng_vjc node as FORCE_WRITER to protect slcompress state.Alexander Motin2009-01-081-0/+3
| | | | | | | | | | I think it can be the reason of livelock in netgraph reported by some mpd users. MFC after: 3 days Notes: svn path=/head/; revision=186907
* 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