summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_socket.c
Commit message (Collapse)AuthorAgeFilesLines
* 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
* When making a peer of unknown type framework tries to load moduleglebius2004-07-271-0/+34
| | | | | | | | | | | | | | using linker_load_module(). This works OK if NGM_MKPEER message came from userland and we have process associated with thread. But when NGM_MKPEER was queued because target node was busy, linker_load_module() is called from netisr thread leading to panic. To workaround that we do not load modules by framework, instead ng_socket loads module (if this is required) before sending NGM_MKPEER. However, the race condition between return from NgSendMsg() and actual creation of node still exist and needs to be solved. PR: kern/62789 Approved by: julian
* Introduce a global mtx 'ngsocketlist_mtx' to protect the globalrwatson2004-07-121-0/+8
| | | | ng_socket list during insert/delete.
* Update for the KDB framework:marcel2004-07-101-2/+2
| | | | | o Call kdb_enter() instead of Debugger(). o Change comments accordingly.
* Switch to using C99 sparse initialisers for the type methods array.julian2004-05-291-12/+10
| | | | | | | | Should make no binary difference. Submitted by: Gleb Smirnoff <glebius@cell.sick.ru> Reviewed by: Harti Brandt <harti@freebsd.org> MFC after: 1 week
* Correct the description of the net.graph.recvspace sysctl.ru2004-01-271-1/+1
|
* Get rid of the deprecated *LEN constants in favour of the newharti2004-01-261-5/+5
| | | | *SIZ constants that include the trailing \0 byte.
* Allow the socket buffer sizes to be controlled via sysctl(8).ru2004-01-231-0/+4
| | | | MFC after: 3 days
* Introduce a MAC label reference in 'struct inpcb', which cachesrwatson2003-11-181-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | the MAC label referenced from 'struct socket' in the IPv4 and IPv6-based protocols. This permits MAC labels to be checked during network delivery operations without dereferencing inp->inp_socket to get to so->so_label, which will eventually avoid our having to grab the socket lock during delivery at the network layer. This change introduces 'struct inpcb' as a labeled object to the MAC Framework, along with the normal circus of entry points: initialization, creation from socket, destruction, as well as a delivery access control check. For most policies, the inpcb label will simply be a cache of the socket label, so a new protocol switch method is introduced, pr_sosetlabel() to notify protocols that the socket layer label has been updated so that the cache can be updated while holding appropriate locks. Most protocols implement this using pru_sosetlabel_null(), but IPv4/IPv6 protocols using inpcbs use the the worker function in_pcbsosetlabel(), which calls into the MAC Framework to perform a cache update. Biba, LOMAC, and MLS implement these entry points, as do the stub policy, and test policy. Reviewed by: sam, bms Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories
* Back out M_* changes, per decision of the TRB.imp2003-02-191-5/+5
| | | | Approved by: trb
* Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.alfred2003-01-211-5/+5
| | | | Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.
* Bow to the whining masses and change a union back into void *. Retaindillon2003-01-131-1/+1
| | | | | removal of unnecessary casts and throw in some minor cleanups to see if anyone complains, just for the hell of it.
* Change struct file f_data to un_data, a union of the correct structdillon2003-01-121-1/+1
| | | | | | | | | | pointer types, and remove a huge number of casts from code using it. Change struct xfile xf_data to xun_data (ABI is still compatible). If we need to add a #define for f_data and xf_data we can, but I don't think it will be necessary. There are no operational changes in this commit.
* Correct typos, mostly s/ a / an / where appropriate. Some whitespace cleanup,schweikh2003-01-011-2/+2
| | | | especially in troff files.
* Don't use "NULL" when "0" is really meant.archie2002-08-221-2/+2
|
* Const'ify variables to make it clear we're not writing to the mbuf data.archie2002-06-051-1/+1
| | | | | Reviewed by: julian, brian MFC after: 1 week
* Back out my lats commit of locking down a socket, it conflicts with hsu's work.tanimura2002-05-311-16/+0
| | | | Requested by: hsu
OpenPOWER on IntegriCloud