summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_socket.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r263710, r273377, r273378, r273423 and r273455:hselasky2014-10-271-3/+3
| | | | | | | - De-vnet hash sizes and hash masks. - Fix multiple issues related to arguments passed to SYSCTL macros. Sponsored by: Mellanox Technologies
* In ng_getsockaddr() allocate memory prior to obtaining lock.glebius2012-02-161-11/+8
| | | | Reported & tested by: Mykola Dzham <i levsha.me>
* No need to optimise for a node with no hooks, my braino.glebius2012-02-131-5/+2
|
* Provide a findhook method for ng_socket(4). The node stores aglebius2012-01-231-2/+101
| | | | | | | | | | | | | | | | | hash with names of its hooks. It starts with size of 16, and grows when number of hooks reaches twice the current size. A failure to grow (memory is allocated with M_NOWAIT) isn't fatal, however. I used standard hash(9) function for the hash. With 25000 hooks named in the mpd (ports/net/mpd5) manner of "b%u", the distributions is the following: 72.1% entries consist of one element, 22.1% consist of two, 5.2% consist of three and 0.6% of four. Speedup in a synthetic test that creates 25000 hooks and then runs through a long cyclce dereferencing them in a random order is over 25 times.
* In ng_socket(4) expose less kernel internals to userland. This commitglebius2012-01-231-3/+16
| | | | breaks ABI, but makes probability of ABI breakage in future less.
* Remove some disabled NOTYET code. Probability of enabling it is low,glebius2012-01-161-78/+0
| | | | if anyone wants, he/she can take it from svn.
* Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.ed2011-11-071-2/+2
| | | | | | The SYSCTL_NODE macro defines a list that stores all child-elements of that node. If there's no SYSCTL_DECL macro anywhere else, there's no reason why it shouldn't be static.
* Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs.ed2011-11-071-2/+2
| | | | This means that their use is restricted to a single C file.
* Second-to-last commit implementing Capsicum capabilities in the FreeBSDrwatson2011-08-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | kernel for FreeBSD 9.0: Add a new capability mask argument to fget(9) and friends, allowing system call code to declare what capabilities are required when an integer file descriptor is converted into an in-kernel struct file *. With options CAPABILITIES compiled into the kernel, this enforces capability protection; without, this change is effectively a no-op. Some cases require special handling, such as mmap(2), which must preserve information about the maximum rights at the time of mapping in the memory map so that they can later be enforced in mprotect(2) -- this is done by narrowing the rights in the existing max_protection field used for similar purposes with file permissions. In namei(9), we assert that the code is not reached from within capability mode, as we're not yet ready to enforce namespace capabilities there. This will follow in a later commit. Update two capability names: CAP_EVENT and CAP_KEVENT become CAP_POST_KEVENT and CAP_POLL_KEVENT to more accurately indicate what they represent. Approved by: re (bz) Submitted by: jonathan Sponsored by: Google Inc
* In ng_attach_cntl() first allocate things that may fail, and thenglebius2011-07-141-16/+15
| | | | | | | do the rest of initialization. This simplifies code and fixes a double free in failure scenario. Reviewed by: bz
* sysctl(9) cleanup checkpoint: amd64 GENERIC builds cleanly.mdf2011-01-121-2/+2
| | | | Commit the netgraph piece.
* When calling panic(), always pass a format string.rpaulo2010-10-131-1/+1
|
* Fix a race between ngs_rcvmsg() and soclose() which closes the controlattilio2010-05-191-6/+26
| | | | | | | | | | | | | socket while it is still in use. priv->ctlsock is checked at the top of the function but without any lock held, which means the control socket state may certainly change. Add a similar protection to ngs_shutdown() even if a race is unlikely to be experienced there. Sponsored by: Sandvine Incorporated Obtained from: Nima Misaghian @ Sandvine Incorporated <nmisaghian at sandvine dot com> MFC after: 10 days
* Now fix functionality of 'netstat -f netgraph' that hasn't workedglebius2010-03-121-0/+3
| | | | | | | | | | | | starting from netgraph import in 1999. netstat(8) used pointer to node as node address, oops. That didn't work, we need the node ID in brackets to successfully address a node. We can't look into ng_node, due to inability to include netgraph/netgraph.h in userland code. So let the node make a hint for a userland, storing the node ID in its private data. MFC after: 2 weeks
* Fix 'netstat -f netgraph', which I had broken in r163463 ling timeglebius2010-03-121-0/+18
| | | | | | | ago in 2006. This linked list is actually needed for userland. PR: kern/140446 Submitted by: Adrian Steinmann <ast marabu.ch>
* Introduce and use a sysinit-based initialization scheme for virtualrwatson2009-07-231-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* Remove unused variable.mav2008-11-221-3/+2
| | | | | Found with: Coverity Prevent(tm) CID: 3682
* Improve apply callback error reporting:mav2008-03-111-1/+1
| | | | | | | | | | | Before this patch callback returned result of the last finished call chain. Now it returns last nonzero result from all call chain results in this request. As soon as this improvement gives reliable error reporting, it is now possible to remove dirty workaround in ng_socket, made to return ENOBUFS error statuses of request-response operations. That workaround was responsible for returning ENOBUFS errors to completely unrelated requests working at the same time on socket.
* Remove explicit locking of struct file.jeff2007-12-301-1/+1
| | | | | | | | | | | | | - Introduce a finit() which is used to initailize the fields of struct file in such a way that the ops vector is only valid after the data, type, and flags are valid. - Protect f_flag and f_count with atomic operations. - Remove the global list of all files and associated accounting. - Rewrite the unp garbage collection such that it no longer requires the global list of all files and instead uses a list of all unp sockets. - Mark sockets in the accept queue so we don't incorrectly gc them. Tested by: kris, pho
* Implement new apply callback mechanism to handle item forwarding.mav2007-10-191-12/+13
| | | | | | | | When item forwarded refence counter is incremented, when item processed, counter decremented. When counter reaches zero, apply handler is getting called. Now it allows to report right connect() call status from user-level at the right time.
* Reduce network stack oddness: implement .pru_sockaddr and .pru_peeraddrrwatson2007-05-111-3/+3
| | | | | | | | protocol entry points using functions named proto_getsockaddr and proto_getpeeraddr rather than proto_setsockaddr and proto_setpeeraddr. While it's true that sockaddrs are allocated and set, the net effect is to retrieve (get) the socket address or peer address from a socket, not set it, so align names to that intent.
* Sweep kernel replacing suser(9) calls with priv(9) calls, assigningrwatson2006-11-061-2/+5
| | | | | | | | | | | | | specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net>
* Check pointer before dereferencing.glebius2006-10-181-1/+2
| | | | | Reported by: Coverity CID: 1556
* Some clenaup of ngs_rcvmsg():glebius2006-10-171-60/+46
| | | | | | | - Inline ship_msg() into ngs_rcvmsg(). - Plug memory leak in case if no control socket present. - Remove malloc() and allocate the sockaddr on stack. - style(9).
* Some cleanup and small changes:glebius2006-10-171-121/+74
| | | | | | | | | | - Use malloc() and free() instead of MALLOC() and FREE() macros. - Do not check malloc results if M_WAITOK was used. - Remove linked list of all netgraph sockets. It isn't needed. - Use ng_findhook() instead of searching the list ourselves. - Use NG_WAITOK in syscalls. - Remove unneeded includes. - style(9)
* Change semantics of socket close and detach. Add a new protocol switchrwatson2006-07-211-0/+4
| | | | | | | | | | | | | | | | | | | function, pru_close, to notify protocols that the file descriptor or other consumer of a socket is closing the socket. pru_abort is now a notification of close also, and no longer detaches. pru_detach is no longer used to notify of close, and will be called during socket tear-down by sofree() when all references to a socket evaporate after an earlier call to abort or close the socket. This means detach is now an unconditional teardown of a socket, whereas previously sockets could persist after detach of the protocol retained a reference. This faciliates sharing mutexes between layers of the network stack as the mutex is required during the checking and removal of references at the head of sofree(). With this change, pru_detach can now assume that the mutex will no longer be required by the socket layer after completion, whereas before this was not necessarily true. Reviewed by: gnn
* Use kern_kldload() and kern_kldunload() to load and unload modules whenjhb2006-06-131-6/+5
| | | | | | | | we intend for the user to be able to unload them later via kldunload(2) instead of calling linker_load_module() and then directly adjusting the ref count on the linker file structure. This makes the resulting consumer code simpler and cleaner and better hides the linker internals making it possible to sanely lock the linker.
* Remove unneeded check.glebius2006-05-161-4/+0
| | | | Coverity ID: 445
* Do not leak kernel memory in case if userland has been compiledglebius2006-05-161-0/+1
| | | | | | against older NG_VERSION. Coverity ID: 1131
* Correct assertion in ng_detach().rwatson2006-04-061-1/+1
| | | | | Submitted by: tegge MFC after: 3 months
* Chance protocol switch method pru_detach() so that it returns voidrwatson2006-04-011-8/+4
| | | | | | | | | | | | | | | | | | | | | | | | | rather than an error. Detaches do not "fail", they other occur or the protocol flags SS_PROTOREF to take ownership of the socket. soclose() no longer looks at so_pcb to see if it's NULL, relying entirely on the protocol to decide whether it's time to free the socket or not using SS_PROTOREF. so_pcb is now entirely owned and managed by the protocol code. Likewise, no longer test so_pcb in other socket functions, such as soreceive(), which have no business digging into protocol internals. Protocol detach routines no longer try to free the socket on detach, this is performed in the socket code if the protocol permits it. In rts_detach(), no longer test for rp != NULL in detach, and likewise in other protocols that don't permit a NULL so_pcb, reduce the incidence of testing for it during detach. netinet and netinet6 are not fully updated to this change, which will be in an upcoming commit. In their current state they may leak memory or panic. MFC after: 3 months
* Use sparse initializers for "struct domain" and "struct protosw",ru2005-11-091-33/+18
| | | | so they are easier to follow for the human being.
* Fix several races between socket closure and node/hookglebius2005-11-021-77/+97
| | | | | | | | | | | | | destruction: - Backout 1.62, since it doesn't fix all possible problems. - Upon node creation, put an additional reference on node. - Add a mutex and refcounter to struct ngsock. Netgraph node, control socket and data socket all count as references. - Introduce ng_socket_free_priv() which removes one reference from ngsock, and frees it when all references has gone. - No direct pointers between pcbs and node, all pointing is done via struct ngsock and protected with mutex.
* When message can't fit into socket receive buffer return ENOBUFSglebius2005-09-121-2/+3
| | | | | | to userland program instead of letting it wait until end of days. PR: kern/85907
* Fix missing '=' in structure initialization.obrien2005-07-231-1/+1
|
* In the splnet times, netgraph was functional and synchronous. Nowadays,glebius2005-07-051-1/+44
| | | | | | | | | | | | | | | | | | | | | | an item may be queued and processed later. While this is OK for mbufs, this is a problem for control messages. In the framework: - Add optional callback function pointer to an item. When item gets applied the callback is executed from ng_apply_item(). - Add new flag NG_PROGRESS. If this flag is supplied, then return EINPROGRESS instead of 0 in case if item failed to deliver synchronously and was queued. - Honor NG_PROGRESS in ng_snd_item(). In ng_socket: - When userland sends control message add callback to the item. - If ng_snd_item() returns EINPROGRESS, then sleep. This change fixes possible races in ngctl(8) scripts. Reviewed by: julian Approved by: re (scottl)
* Fix use of uninitialized variable len in ngd_send.bz2005-05-281-3/+7
| | | | | | | | | Note: len gets intialized to 0 for sap == NULL case only to make compiler on amd64 happy. This has nothing todo with the former uninitialized use of len in sap != NULL case. Reviewed by: glebius Approved by: pjd (mentor)
* Remove local error variable, which leads to hiding error from returnglebius2005-05-231-1/+0
| | | | | | | | value. PR: kern/81371 Submitted by: Wojciech A. Koszek MFC after: 1 week
* - Unwind NG_SEND_MSG_PATH() macro and merge it with already unwindedglebius2005-05-171-28/+26
| | | | | version under TRACE_MESSAGES. - Pass NG_WAITOK flag to ng_package_data() in unwinded macro.
* - Fix build with TRACE_MESSAGES on.glebius2005-05-161-41/+42
| | | | | | - Reformat code under TRACE_MESSAGES to make it more readable. - Move linker hackery out of #ifdef. - Break long lines in linker hackery block.
* Close race between node being shutdown and socket being detached. Toglebius2005-05-161-7/+27
| | | | | | | do this, obtain netgraph locking in detach method via ng_send_fn1(). Reviewed by: julian MFC after: 2 weeks
* Catch up with new ng_package_data(). Use NG_WAITOK on userlandglebius2005-05-161-1/+1
| | | | path.
* Create a per-module mutex on MOD_LOAD, and destroy it on MOD_UNLOAD.ru2005-02-051-1/+2
| | | | | | (This fixes witness_destroy() panic after module unload.) OK'ed by: rwatson, julian
* Do check that version of a message from userland matches ours.glebius2005-02-041-0/+5
| | | | MFC after: 3 days
* - Fix build with TRACE_MESSAGES definedglebius2005-02-041-2/+2
| | | | - Remove extra parenthesis
* /* -> /*- for license, minor formatting changesimp2005-01-071-1/+3
|
* Move ng_socket and ng_btsocket initialization to SI_SUB_PROTO_DOMAIN as theymlaier2004-11-301-1/+1
| | | | | | | | | | | | | | | call net_add_domain(). Calling this function too early (or late) breaks assertations about the global domains list. Actually it should be forbidden to call net_add_domain() outside of SI_SUB_PROTO_DOMAIN completely as there are many places where we traverse the domains list unprotected, but for now we allow late calls (mostly to support netgraph). In order to really fix this we have to lock the domains list in all places or find another way to ensure that we can safely walk the list while another thread might be adding a new domain. Spotted by: se Reviewed by: julian, glebius PR: kern/73321 (partly)
* Initialize struct pr_userreqs in new/sparse style and fill in commonphk2004-11-081-42/+20
| | | | | | default elements in net_init_domain(). This makes it possible to grep these structures and see any bogosities.
* Acquire Giant arounds calls into the linker from Netgraph sockets.rwatson2004-08-301-0/+2
| | | | | | | | We now no longer hold Giant in send(), so it isn't inheritted by the linker, which calls into VFS. Reported by: glebius Discussed with: glebius, bz
* Fix a stupid error in my previous commit, which broke operationglebius2004-07-311-1/+2
| | | | | | of many nodes. Pointy hat to: glebius
OpenPOWER on IntegriCloud