summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_ksocket.c
Commit message (Collapse)AuthorAgeFilesLines
* Make ng_ksocket fulfill lower protocol stack layers alignment requirementsmav2010-03-311-1/+13
| | | | | | | on platforms with strict alignment constraints. This fixes kernel panics on arm and probably other architectures. PR: sparc64/80410
* - Turn the third (islocked) argument of the knote call into flags parameter.stas2009-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
* Rework socket upcalls to close some races with setup/teardown of upcalls.jhb2009-06-011-13/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* Retire the MALLOC and FREE macros. They are an abomination unto style(9).des2008-10-231-13/+13
| | | | MFC after: 3 months
* Send only one incoming notification at a time to reduce queuemav2008-03-071-32/+26
| | | | | | | | trashing and improve performance. Remove waitflag argument from ng_ksocket_incoming2(), it means nothing as function call was queued by netgraph. Remove node validity check, as node validity guarantied by netgraph. Update comments.
* In the output path, mask off M_BCAST|M_MCAST so as to prevent incorrectbms2007-02-091-0/+3
| | | | | | | | | | addressing if a packet is later re-encapsulated and sent to a non-broadcast, non-multicast destination after being received on the ng_ksocket input hook. PR: 106999 Submitted by: Kevin Lahey MFC after: 4 weeks
* soreceive_generic(), and sopoll_generic(). Add new functions sosend(),rwatson2006-07-241-4/+3
| | | | | | | | | | | | | | | | soreceive(), and sopoll(), which are wrappers for pru_sosend, pru_soreceive, and pru_sopoll, and are now used univerally by socket consumers rather than either directly invoking the old so*() functions or directly invoking the protocol switch method (about an even split prior to this commit). This completes an architectural change that was begun in 1996 to permit protocols to provide substitute implementations, as now used by UDP. Consumers now uniformly invoke sosend(), soreceive(), and sopoll() to perform these operations on sockets -- in particular, distributed file systems and socket system calls. Architectural head nod: sam, gnn, wollman
* Clear csum_flags after reading data from socket buffer. Otherwise,ru2006-02-211-0/+1
| | | | | | | | if ksocket is connected to an interface-type node somewhere later in the graph (e.g., ng_eiface or ng_iface), the csum_data may be applied to a wrong packet (if we encapsulate Ethernet or IP). MFC after: 3 days
* When we read data from socket buffer using soreceive() the socket layerglebius2005-09-061-4/+13
| | | | | | | | | | | | | | | | | | | | | | | does not clear m_nextpkt for us. The mbufs are sent into netgraph and then, if they contain a TCP packet delivered locally, they will enter socket code again. They can pass the first assert in sbappendstream() because m_nextpkt may be set not in the first mbuf, but deeper in the chain. So the problem will trigger much later, when local program reads the data from socket, and an mbuf with m_nextpkt becomes a first one. This bug was demasked by revision 1.54, when I made upcall queueable. Before revision 1.54 there was a very small probability to have 2 mbufs in GRE socket buffer, because ng_ksocket_incoming2() dequeued the first one immediately. - in ng_ksocket_incoming2() clear m_nextpkt on all mbufs read from socket. - restore rev. 1.54 change in ng_ksocket_incoming(). PR: kern/84952 PR: kern/82413 In collaboration with: rwatson
* Backout revision 1.54, because it exposes a worse problem, thanglebius2005-08-251-3/+1
| | | | | | | | | it fixes. I believe the problem lives somewhere outside ng_ksocket, but until it is found, let the node be working. PR: kern/84952 PR: kern/82413 MFC after: 3 days
* Catch up with new ng_send_fn1() interface.glebius2005-05-161-1/+4
|
* When used as divert socket we need to decouple stack when node is enteredglebius2005-05-131-1/+3
| | | | from socket side. Use ng_queue_fn() instead of ng_send_fn().
* Fix panics with misconfigured routing:glebius2005-04-181-6/+8
| | | | | | | - Backout previous revision, the check is useless. - Turn node to queue mode, since it is edge node. Reported by: sem
* Reimplement recursion protection, checking whether current thread holdsglebius2005-02-191-0/+6
| | | | | | sockbuf mutex. Reviewed by: rwatson
* Remove a recursion protection, which we inherited from splnet() netgraph times.glebius2005-02-161-9/+0
| | | | | | | | Now several threads may write data to ng_ksocket. Locking of socket is done in sosend(). Reviewed by: archie, julian, rwatson MFC after: 2 weeks
* Allocate enough space for new tag.glebius2005-02-121-1/+2
| | | | Pointy hat to: glebius
* When netgraph(4) was converted to use mbuf_tags(9) instead of meta-dataglebius2005-02-121-3/+9
| | | | | | | | | | | | | a definite setup was broken: two ng_ksockets are connected to each other, connect()ed to different remote hosts, and bind()ed to different local interfaces. In this case one ng_ksocket is fooled with tag from the other one. Put node id into tag. In rcvdata method utilize tag only if it has our own id inside or id equals zero. The latter case is added to support packets send by some third, not ng_ksocket node. MFC after: 1 week
* /* -> /*- for license, minor formatting changesimp2005-01-071-2/+3
|
* In FreeBSD 5.x, curthread is always defined, so we don't need to to testrwatson2004-09-021-3/+3
| | | | | | and optionally use &thread0 if it's NULL. Spotted by: julian
* Convert Netgraph to use mbuf tags to pass its meta information around.julian2004-06-251-38/+15
| | | | | | | | Thanks to Sam for importing tags in a way that allowed this to be done. Submitted by: Gleb Smirnoff <glebius@cell.sick.ru> Also allow the sr and ar drivers to create netgraph versions of their modules. Document the change to the ksocket node.
* Merge additional socket buffer locking from rwatson_netperf:rwatson2004-06-171-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | - Lock down low hanging fruit use of sb_flags with socket buffer lock. - Lock down low hanging fruit use of so_state with socket lock. - Lock down low hanging fruit use of so_options. - Lock down low-hanging fruit use of sb_lowwat and sb_hiwat with socket buffer lock. - Annotate situations in which we unlock the socket lock and then grab the receive socket buffer lock, which are currently actually the same lock. Depending on how we want to play our cards, we may want to coallesce these lock uses to reduce overhead. - Convert a if()->panic() into a KASSERT relating to so_state in soaccept(). - Remove a number of splnet()/splx() references. More complex merging of socket and socket buffer locking to follow.
* The socket field so_state is used to hold a variety of socket relatedrwatson2004-06-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | flags relating to several aspects of socket functionality. This change breaks out several bits relating to send and receive operation into a new per-socket buffer field, sb_state, in order to facilitate locking. This is required because, in order to provide more granular locking of sockets, different state fields have different locking properties. The following fields are moved to sb_state: SS_CANTRCVMORE (so_state) SS_CANTSENDMORE (so_state) SS_RCVATMARK (so_state) Rename respectively to: SBS_CANTRCVMORE (so_rcv.sb_state) SBS_CANTSENDMORE (so_snd.sb_state) SBS_RCVATMARK (so_rcv.sb_state) This facilitates locking by isolating fields to be located with other identically locked fields, and permits greater granularity in socket locking by avoiding storing fields with different locking semantics in the same short (avoiding locking conflicts). In the future, we may wish to coallesce sb_state and sb_flags; for the time being I leave them separate and there is no additional memory overhead due to the packing/alignment of shorts in the socket buffer structure.
* Extend coverage of SOCK_LOCK(so) to include so_count, the socketrwatson2004-06-121-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | reference count: - Assert SOCK_LOCK(so) macros that directly manipulate so_count: soref(), sorele(). - Assert SOCK_LOCK(so) in macros/functions that rely on the state of so_count: sofree(), sotryfree(). - Acquire SOCK_LOCK(so) before calling these functions or macros in various contexts in the stack, both at the socket and protocol layers. - In some cases, perform soisdisconnected() before sotryfree(), as this could result in frobbing of a non-present socket if sotryfree() actually frees the socket. - Note that sofree()/sotryfree() will release the socket lock even if they don't free the socket. Submitted by: sam Sponsored by: FreeBSD Foundation Obtained from: BSD/OS
* Integrate accept locking from rwatson_netperf, introducing a newrwatson2004-06-021-7/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | global mutex, accept_mtx, which serializes access to the following fields across all sockets: so_qlen so_incqlen so_qstate so_comp so_incomp so_list so_head While providing only coarse granularity, this approach avoids lock order issues between sockets by avoiding ownership of the fields by a specific socket and its per-socket mutexes. While here, rewrite soclose(), sofree(), soaccept(), and sonewconn() to add assertions, close additional races and address lock order concerns. In particular: - Reorganize the optimistic concurrency behavior in accept1() to always allocate a file descriptor with falloc() so that if we do find a socket, we don't have to encounter the "Oh, there wasn't a socket" race that can occur if falloc() sleeps in the current code, which broke inbound accept() ordering, not to mention requiring backing out socket state changes in a way that raced with the protocol level. We may want to add a lockless read of the queue state if polling of empty queues proves to be important to optimize. - In accept1(), soref() the socket while holding the accept lock so that the socket cannot be free'd in a race with the protocol layer. Likewise in netgraph equivilents of the accept1() code. - In sonewconn(), loop waiting for the queue to be small enough to insert our new socket once we've committed to inserting it, or races can occur that cause the incomplete socket queue to overfill. In the previously implementation, it was sufficient to simply tested once since calling soabort() didn't release synchronization permitting another thread to insert a socket as we discard a previous one. - In soclose()/sofree()/et al, it is the responsibility of the caller to remove a socket from the incomplete connection queue before calling soabort(), which prevents soabort() from having to walk into the accept socket to release the socket from its queue, and avoids races when releasing the accept mutex to enter soabort(), permitting soabort() to avoid lock ordering issues with the caller. - Generally cluster accept queue related operations together throughout these functions in order to facilitate locking. Annotate new locking in socketvar.h.
* The SS_COMP and SS_INCOMP flags in the so_state field indicate whetherrwatson2004-06-011-1/+1
| | | | | | | | the socket is on an accept queue of a listen socket. This change renames the flags to SQ_COMP and SQ_INCOMP, and moves them to a new state field on the socket, so_qstate, as the locking for these flags is substantially different for the locking on the remainder of the flags in so_state.
* 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
* Get rid of the deprecated *LEN constants in favour of the newharti2004-01-261-1/+1
| | | | *SIZ constants that include the trailing \0 byte.
* Replaced two bzero() calls with the M_ZERO flag to malloc().ru2003-12-171-3/+2
| | | | Reviewed by: julian
* Add Protocol Independent Multicast protocol.hsu2003-08-201-0/+1
| | | | Submitted by: Pavlin Radoslavov <pavlin@icir.org>
* Add missing braces.archie2003-04-281-1/+2
| | | | Submitted by: Andrew Lankford <arlankfo@141.com>
* Reference the socket we're accepting.benno2002-09-141-0/+2
|
* Remember who asked for a connect or accept operation so we can actually tellbenno2002-09-111-2/+2
| | | | | | them when it's done. Reviewed by: archie
* Don't use "NULL" when "0" is really meant.archie2002-08-221-3/+3
|
* Fix GCC warnings caused by initializing a zero length array. In the process,archie2002-05-311-8/+7
| | | | | | | simply things a bit by getting rid of 'struct ng_parse_struct_info' which was useless because it only contained one field. MFC after: 2 weeks
* Back out my lats commit of locking down a socket, it conflicts with hsu's work.tanimura2002-05-311-49/+11
| | | | Requested by: hsu
* Lock down a socket, milestone 1.tanimura2002-05-201-11/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | o Add a mutex (sb_mtx) to struct sockbuf. This protects the data in a socket buffer. The mutex in the receive buffer also protects the data in struct socket. o Determine the lock strategy for each members in struct socket. o Lock down the following members: - so_count - so_options - so_linger - so_state o Remove *_locked() socket APIs. Make the following socket APIs touching the members above now require a locked socket: - sodisconnect() - soisconnected() - soisconnecting() - soisdisconnected() - soisdisconnecting() - sofree() - soref() - sorele() - sorwakeup() - sotryfree() - sowakeup() - sowwakeup() Reviewed by: alfred
* Simple p_ucred -> td_ucred changes to start using the per-thread ucredjhb2002-02-271-1/+1
| | | | reference.
* Pre-KSE/M3 commit.julian2002-02-071-3/+3
| | | | | | | | | | this is a low-functionality change that changes the kernel to access the main thread of a process via the linked list of threads rather than assuming that it is embedded in the process. It IS still embeded there but remove all teh code that assumes that in preparation for the next commit which will actually move it out. Reviewed by: peter@freebsd.org, gallatin@cs.duke.edu, benno rice,
* Avoid reentrantly sending on the same socket, which causes a kernel panic.archie2002-01-061-0/+9
|
* o Make the credential used by socreate() an explicit argument torwatson2001-12-311-1/+2
| | | | | | | | | | | | | | socreate(), rather than getting it implicitly from the thread argument. o Make NFS cache the credential provided at mount-time, and use the cached credential (nfsmount->nm_cred) when making calls to socreate() on initially connecting, or reconnecting the socket. This fixes bugs involving NFS over TCP and ipfw uid/gid rules, as well as bugs involving NFS and mandatory access control implementations. Reviewed by: freebsd-arch
* Update to C99, s/__FUNCTION__/__func__/,obrien2001-12-101-2/+2
| | | | also don't use ANSI string concatenation.
* When a socket is not connected, allow the peer "struct sockaddr"archie2001-11-281-13/+74
| | | | | | | | to be included in the meta information that is associated with incoming and outgoing packets. Reviewed by: julian MFC after: 1 week
* Let "raw" mean IPPROTO_RAW instead of IPPROTO_IP.archie2001-10-101-1/+1
| | | | | Noticed by: jdp MFC after: 3 days
* KSE Milestone 2julian2001-09-121-11/+11
| | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha
* First pass at porting John's "accept" changes tojulian2001-09-071-49/+366
| | | | | | | | | | | | allow an in-kernel webserver (or similar) to accept and handle incoming connections using netgraph without ever leaving the kernel. (allows incoming tunnel requests to be handled totally within the kernel for example) Needs work, but shouldn't break existing functionality. Submitted by: John Polstra <jdp@polstra.com> MFC after: 2 weeks
* Fix an erroneous comment and two style(9) bugs.archie2001-02-161-3/+5
|
* Fix some memory leaksjulian2001-01-101-6/+12
| | | | Add memory leak detection assitance.
* Part 2 of the netgraph rewrite.julian2001-01-081-15/+14
| | | | | | This is mostly cosmetic changes, (though I caught a bug or two while makeing them) Reviewed by: archie@freebsd.org
* Rewrite of netgraph to start getting ready for SMP.julian2001-01-061-28/+18
| | | | | | | | This version is functional and is aproaching solid.. notice I said APROACHING. There are many node types I cannot test I have tested: echo hole ppp socket vjc iface tee bpf async tty The rest compile and "Look" right. More changes to follow. DEBUGGING is enabled in this code to help if people have problems.
* Divorce the kernel binary ABI version number from the messagejulian2000-12-181-1/+1
| | | | | | | | | format version number. (userland programs should not need to be recompiled when the netgraph kernel internal ABI is changed. Also fix modules that don;t handle the fact that a caller may not supply a return message pointer. (benign at the moment because the calling code checks, but that will change)
OpenPOWER on IntegriCloud