summaryrefslogtreecommitdiffstats
path: root/sys/net
Commit message (Collapse)AuthorAgeFilesLines
* Move if_handoff() from an inline in if_var.h to a function to if.crwatson2004-10-302-24/+27
| | | | | | | | | in orden to harden the ABI for 5.x; this will permit us to modify the locking in the ifnet packet dispatch without requiring drivers to be recompiled. MFC after: 3 days Discussed at: EuroBSDCon Developer's Summit
* Add additional "spare" fields to 'struct ifnet' in order to improverwatson2004-10-301-0/+5
| | | | | | | | the resistance of the network driver ABI to changes that will be required as we optimize locking. MFC after: 3 days Discussed at: Developer Summit
* use NULL instead of 0 when casting/comparing w/ a pointer...jmg2004-10-251-2/+2
|
* Define IFF_LOCKGIANT() and IFF_UNLOCKGIANT() macros, which conditionallyrwatson2004-10-192-2/+40
| | | | | | | | | acquire Giant if the passed interface has IFF_NEEDSGIANT set on it. Modify calls into (ifp)->if_ioctl() in if.c to use these macros in order to ensure that Giant is held. MFC after: 3 days Bumped into by: jmg
* Push acquisition of the accept mutex out of sofree() into the callerrwatson2004-10-182-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (sorele()/sotryfree()): - This permits the caller to acquire the accept mutex before the socket mutex, avoiding sofree() having to drop the socket mutex and re-order, which could lead to races permitting more than one thread to enter sofree() after a socket is ready to be free'd. - This also covers clearing of the so_pcb weak socket reference from the protocol to the socket, preventing races in clearing and evaluation of the reference such that sofree() might be called more than once on the same socket. This appears to close a race I was able to easily trigger by repeatedly opening and resetting TCP connections to a host, in which the tcp_close() code called as a result of the RST raced with the close() of the accepted socket in the user process resulting in simultaneous attempts to de-allocate the same socket. The new locking increases the overhead for operations that may potentially free the socket, so we will want to revise the synchronization strategy here as we normalize the reference counting model for sockets. The use of the accept mutex in freeing of sockets that are not listen sockets is primarily motivated by the potential need to remove the socket from the incomplete connection queue on its parent (listen) socket, so cleaning up the reference model here may allow us to substantially weaken the synchronization requirements. RELENG_5_3 candidate. MFC after: 3 days Reviewed by: dwhite Discussed with: gnn, dwhite, green Reported by: Marc UBM Bocklet <ubm at u-boot-man dot de> Reported by: Vlad <marchenko at gmail dot com>
* Fix packet flow when both ng_ether(4) and bridge(4) are in use:glebius2004-10-123-51/+32
| | | | | | | | | | | | | | | - push all bridge logic from if_ethersubr.c into bridge.c make bridge_in() return mbuf pointer (or NULL). - call only bridge_in() from ether_input(), after ng_ether_input() was optinally called. - call bridge_in() from ng_ether_rcv_upper(). Long description: http://lists.freebsd.org/mailman/htdig/freebsd-net/2004-May/003881.html Reported by: Jian-Wei Wang <jwwang at FreeBSD.csie.NCTU.edu.tw> Tested by: myself, Sergey Lyubka Reviewed by: sam Approved by: julian (mentor) MFC after: 2 months
* Correctly unregister a netisr by clearing the ni->ni_queue field to NULL asandre2004-10-111-0/+1
| | | | | | | | | well. This field is actually used by various netisr functions to determine the availablility of the specified netisr. This uncomplete unregister leads directly to a crash when the KLD unregistering the netisr is unloaded. Submitted by: Sam <sah@softcardsystems.com> MFC after: 3 days
* When harvesting entropy from an ethernet mbuf, do so before freeing therwatson2004-10-111-1/+1
| | | | | | mbuf. RELENG_5 candidate.
* Assign pointer NULL, not 0.glebius2004-10-111-1/+1
| | | | Approved by: julian (mentor)
* Change pfil starvation prevention from fail-open to fail-close.mlaier2004-10-081-2/+10
| | | | | | | | | We return ENOBUF to indicate the problem, which is an errno that should be handled well everywhere. Requested & Submitted by: green Silently okay'ed by: The rest of the firewall gang MFC after: 3 days
* Since net/net_osdep.c contained only one function that could bebrooks2004-10-082-59/+1
| | | | | trivially implemented as a macro, do that and remove it. NetBSD did this quite a while ago.
* Don't recurse the BPF descriptor lock during the BIOCSDLT operationgreen2004-10-061-1/+1
| | | | | | | | | (and panic). To try to finish making BPF safe, at the very least, the BPF descriptor lock really needs to change into a reader/writer lock that controls access to "settings," and a mutex that controls access to the selinfo/knote/callout. Also, use of callout_drain() instead of callout_stop() (which is really a much more widespread issue).
* Add 802.11-specific events that are dispatched through the routing socket.sam2004-10-052-13/+68
| | | | | | | This really doesn't belong here but is preferred (for the moment) over adding yet another mechanism for sending msgs from the kernel to user apps. Reviewed by: imp
* add ETHERTYPE_PAE for EAPOL/802.1xsam2004-10-051-0/+1
|
* Add an additional struct inpcb * argument to pfil(9) in order to enablemlaier2004-09-293-11/+12
| | | | | | | | | | | | | | | | | | | passing along socket information. This is required to work around a LOR with the socket code which results in an easy reproducible hard lockup with debug.mpsafenet=1. This commit does *not* fix the LOR, but enables us to do so later. The missing piece is to turn the filter locking into a leaf lock and will follow in a seperate (later) commit. This will hopefully be MT5'ed in order to fix the problem for RELENG_5 in forseeable future. Suggested by: rwatson A lot of work by: csjp (he'd be even more helpful w/o mentor-reviews ;) Reviewed by: rwatson, csjp Tested by: -pf, -ipfw, LINT, csjp and myself MFC after: 3 days LOR IDs: 14 - 17 (not fixed yet)
* Switch order for mtx_unlock and cv_signal as (condvar(9)) sez:mlaier2004-09-221-2/+2
| | | | | | | | | | | | A thread must hold mp while calling cv_signal(), cv_broadcast(), or cv_broadcastpri() even though it isn't passed as an argument. and is right with this claim. While here remove a "\" from the macro -> __inline conversion. Found by: csjp MFC after: 4 days
* Prefer C99's __func__ over GCC's __FUNCTION__.stefanf2004-09-221-1/+1
|
* Call sbuf_finish() before sbuf_data() so as to not panic the system.green2004-09-221-0/+1
|
* Fix a LOR where ifconf() used copyout while holding a mutex. This LORbrooks2004-09-221-41/+51
| | | | | | | | was seen when configuring addresses on interfaces using ifconfig. This patch has been verified to work with over eight thousand addresses assigned to an interface. LOR id: 031
* Log the renaming of an interface. This should make it easier to followbrooks2004-09-181-0/+3
| | | | kernel log files.
* Destroy global tapmtx when the if_tap module is unloaded.rwatson2004-09-171-0/+2
| | | | RELENG_5 candidated.
* Fix a LOR where copyout was called while holding a lock.brooks2004-09-151-10/+27
| | | | Reported by: rwatson
* Reformulate bpf_dettachd() to acquire the BIF_LOCK() as well asrwatson2004-09-091-11/+20
| | | | | | | | | | | | | BPFD_LOCK() when removing a descriptor from an interface descriptor list. Hold both over the operation, and do a better job at maintaining the invariant that you can't find partially connected descriptors on an active interface descriptor list. This appears to close a race that resulted in the kernel performing a NULL pointer dereference when BPF sessions are detached during heavy network activity on SMP systems. RELENG_5 candidate.
* Reformulate use of linked lists in 'struct bpf_d' and 'struct bpf_if'rwatson2004-09-092-38/+24
| | | | | | | | | | | | to use queue(3) list macros rather than hand-crafted lists. While here, move to doubly linked lists to eliminate iterating lists in order to remove entries. This change simplifies and clarifies the list logic in the BPF descriptor code as a first step towards revising the locking strategy. RELENG_5 candidate. Reviewed by: fenner
* Compare/set pointers using NULL not 0.rwatson2004-09-091-3/+3
|
* Re-add ifi_epoch, to struct if_data, this time replacing ifi_unusedbrooks2004-09-082-1/+5
| | | | | | | | | | | | to avoid ABI changes. It is set to the last time the interface counters were zeroed, currently the time if_attach() was called. It is intentended to be a valid value for RFC2233's ifCounterDiscontinuityTime and to make it easier for applications to verify that the interface they find at a given index is the one that was there last time they looked. Due to space constraints ifi_epoch is a time_t rather then a struct timeval. SNMP would prefer higher precision, but this unlikely to be useful in practice.
* don't call f_detach if the filter has alread removed the knote.. Thisjmg2004-09-061-3/+0
| | | | | | | | happens when a proc exits, but needs to inform the user that this has happened.. This also means we can remove the check for detached from proc and sig f_detach functions as this is doing in kqueue now... MFC after: 5 days
* Correct a comment typo: s/Note/Not/.rwatson2004-09-031-1/+1
| | | | Pointed out by: kensmith
* Back out ifi_epoch. The ABI breakage is too disruptive this close tobrooks2004-09-022-2/+0
| | | | | 5-STABLE. ifi_epoch will shortly be reintroduced with less precistion using the space currently allocated to ifi_unused.
* Fix an assertion when if_down()ing a ALTQ managed interface. The lock shouldmlaier2004-09-011-0/+2
| | | | | | | | | have been in place all the time the mtx_assert in the ALTQ code just discovered the shortcoming. PR: i386/71195 Tested by: Bettan (PR originator), myself MFC after: 5 days
* Use a spare byte in struct if_data to store the structure size withoutbrooks2004-09-012-0/+2
| | | | | | | | | increasing it. Add code to ifconfig to use this size to find the sockaddr_dl after the struct if_data in the routing message. This allows struct if_data to grow (up to 255 bytes) without breaking ifconfig. Submitted by: peter
* Add a new variable, ifi_epoch, to struct if_data. It is set to the lastbrooks2004-08-302-0/+2
| | | | | | | | | | | | | time the interface counters were zeroed, currently the time if_attach() was called. It is indentended to be a valid value for RFC2233's ifCounterDiscontinuityTime and to make it easier for applications to verify that the interface they find at a given index is the one that was there last time they looked. An if_epoch "compatability" macro has not been created as ifi_epoch has never been a member of struct ifnet. Approved by: andre, bms, wollman
* Use an ANSI-style definition for slstart()yar2004-08-301-2/+1
| | | | in accord with the rest of the file.
* Grant the poor old SLIP driver with an if_start handleryar2004-08-301-7/+18
| | | | | | | | | so that it becomes happy and no longer panics the system upon getting the very first packet to transmit. Reported and tested by: Igor Timkin <ivt@gamma.ru> Reviewed by: rwatson MFC after: 5 days
* Correct typo in printf() warning.rwatson2004-08-281-1/+1
| | | | Submitted by: Pawel Worach <pawel.worach at telia.com>
* Change the default disposition of debug.mpsafenet from 0 to 1, whichrwatson2004-08-281-3/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | will cause the network stack to operate without the Giant lock by default. This change has the potential to improve performance by increasing parallelism and decreasing latency in network processing. Due to the potential exposure of existing or new bugs, the following compatibility functionality is maintained: - It is still possible to disable Giant-free operation by setting debug.mpsafenet to 0 in loader.conf. - Add "options NET_WITH_GIANT", which will restore the default value of debug.mpsafenet to 0, and is intended for use on systems compiled with known unsafe components, or where a more conservative configuration is desired. - Add a new declaration, NET_NEEDS_GIANT("componentname"), which permits kernel components to declare dependence on Giant over the network stack. If the declaration is made by a preloaded module or a compiled in component, the disposition of debug.mpsafenet will be set to 0 and a warning concerning performance degraded operation printed to the console. If it is declared by a loadable kernel module after boot, a warning is displayed but the disposition cannot be changed. This is implemented by defining a new SYSINIT() value, SI_SUB_SETTINGS, which is intended for the processing of configuration choices after tunables are read in and the console is available to generate errors, but before much else gets going. This compatibility behavior will go away when we've finished the last of the locking work and are confident that operation is correct.
* When detaching an interface, don't leave an obsolete pointer to thebrooks2004-08-271-0/+1
| | | | | | | soon to be deleted struct ifnet around. PR: kern/52260 MFC After: 3 days
* Apply error and success logic consistently to the function netisr_queue() andandre2004-08-276-9/+11
| | | | | | | | | | | | | | | | | | its users. netisr_queue() now returns (0) on success and ERRNO on failure. At the moment ENXIO (netisr queue not functional) and ENOBUFS (netisr queue full) are supported. Previously it would return (1) on success but the return value of IF_HANDOFF() was interpreted wrongly and (0) was actually returned on success. Due to this schednetisr() was never called to kick the scheduling of the isr. However this was masked by other normal packets coming through netisr_dispatch() causing the dequeueing of waiting packets. PR: kern/70988 Found by: MOROHOSHI Akihiko <moro@remus.dti.ne.jp> MFC after: 3 days
* Always compile PFIL_HOOKS into the kernel and remove the associated kernelandre2004-08-271-9/+1
| | | | | | | | | | | compile option. All FreeBSD packet filters now use the PFIL_HOOKS API and thus it becomes a standard part of the network stack. If no hooks are connected the entire packet filter hooks section and related activities are jumped over. This removes any performance impact if no hooks are active. Both OpenBSD and DragonFlyBSD have integrated PFIL_HOOKS permanently as well.
* Revert previous revision, 1.7, as removal of GIANT_REQUIRED was maderwatson2004-08-241-0/+2
| | | | in the wrong branch (and hence to the wrong function).
* MT4 if_fwsubr.c:1.6:rwatson2004-08-241-2/+0
| | | | | | | | date: 2004/08/22 14:48:55; author: rwatson; state: Exp; lines: +0 -2 Don't need to assert Giant in fw_output(), only in the firewire start routine. Approved by: re (scottl)
* Fix a typo (attacked -> attached).roam2004-08-241-1/+1
| | | | Approved by: sam
* Style update: use newer style function prototypes in if_sl.c inrwatson2004-08-221-38/+15
| | | | prep for merging locking.
* Don't need to assert Giant in fw_output(), only in the firewire startrwatson2004-08-221-2/+0
| | | | routine.
* If a tunable for the routing socket netisr queue max is defined, allow itrwatson2004-08-211-1/+3
| | | | | to override the default value, rather than the default value overriding the tunable.
* Allow the size of the routing socket netisr queue to be configured usingrwatson2004-08-211-1/+6
| | | | | | | | | | the tunable or sysctl 'net.route.netisr_maxqlen'. Default the maximum depth to 256 rather than IFQ_MAXLEN due to the downsides of dropping routing messages. MT5 candidate. Discussed with: mdodd, mlaier, Vincent Jardin <jardin at 6wind.com>
* When a prison is given the ability to create raw sockets (when thecsjp2004-08-211-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | security.jail.allow_raw_sockets sysctl MIB is set to 1) where privileged access to jails is given out, it is possible for prison root to manipulate various network parameters which effect the host environment. This commit plugs a number of security holes associated with the use of raw sockets and prisons. This commit makes the following changes: - Add a comment to rtioctl warning developers that if they add any ioctl commands, they should use super-user checks where necessary, as it is possible for PRISON root to make it this far in execution. - Add super-user checks for the execution of the SIOCGETVIFCNT and SIOCGETSGCNT IP multicast ioctl commands. - Add a super-user check to rip_ctloutput(). If the calling cred is PRISON root, make sure the socket option name is IP_HDRINCL, otherwise deny the request. Although this patch corrects a number of security problems associated with raw sockets and prisons, the warning in jail(8) should still apply, and by default we should keep the default value of security.jail.allow_raw_sockets MIB to 0 (or disabled) until we are certain that we have tracked down all the problems. Looking forward, we will probably want to eliminate the references to curthread. This may be a MFC candidate for RELENG_5. Reviewed by: rwatson Approved by: bmilekic (mentor)
* Convert ipfw to use PFIL_HOOKS. This is change is transparent to userlandandre2004-08-171-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and preserves the ipfw ABI. The ipfw core packet inspection and filtering functions have not been changed, only how ipfw is invoked is different. However there are many changes how ipfw is and its add-on's are handled: In general ipfw is now called through the PFIL_HOOKS and most associated magic, that was in ip_input() or ip_output() previously, is now done in ipfw_check_[in|out]() in the ipfw PFIL handler. IPDIVERT is entirely handled within the ipfw PFIL handlers. A packet to be diverted is checked if it is fragmented, if yes, ip_reass() gets in for reassembly. If not, or all fragments arrived and the packet is complete, divert_packet is called directly. For 'tee' no reassembly attempt is made and a copy of the packet is sent to the divert socket unmodified. The original packet continues its way through ip_input/output(). ipfw 'forward' is done via m_tag's. The ipfw PFIL handlers tag the packet with the new destination sockaddr_in. A check if the new destination is a local IP address is made and the m_flags are set appropriately. ip_input() and ip_output() have some more work to do here. For ip_input() the m_flags are checked and a packet for us is directly sent to the 'ours' section for further processing. Destination changes on the input path are only tagged and the 'srcrt' flag to ip_forward() is set to disable destination checks and ICMP replies at this stage. The tag is going to be handled on output. ip_output() again checks for m_flags and the 'ours' tag. If found, the packet will be dropped back to the IP netisr where it is going to be picked up by ip_input() again and the directly sent to the 'ours' section. When only the destination changes, the route's 'dst' is overwritten with the new destination from the forward m_tag. Then it jumps back at the route lookup again and skips the firewall check because it has been marked with M_SKIP_FIREWALL. ipfw 'forward' has to be compiled into the kernel with 'option IPFIREWALL_FORWARD' to enable it. DUMMYNET is entirely handled within the ipfw PFIL handlers. A packet for a dummynet pipe or queue is directly sent to dummynet_io(). Dummynet will then inject it back into ip_input/ip_output() after it has served its time. Dummynet packets are tagged and will continue from the next rule when they hit the ipfw PFIL handlers again after re-injection. BRIDGING and IPFW_ETHER are not changed yet and use ipfw_chk() directly as they did before. Later this will be changed to dedicated ETHER PFIL_HOOKS. More detailed changes to the code: conf/files Add netinet/ip_fw_pfil.c. conf/options Add IPFIREWALL_FORWARD option. modules/ipfw/Makefile Add ip_fw_pfil.c. net/bridge.c Disable PFIL_HOOKS if ipfw for bridging is active. Bridging ipfw is still directly invoked to handle layer2 headers and packets would get a double ipfw when run through PFIL_HOOKS as well. netinet/ip_divert.c Removed divert_clone() function. It is no longer used. netinet/ip_dummynet.[ch] Neither the route 'ro' nor the destination 'dst' need to be stored while in dummynet transit. Structure members and associated macros are removed. netinet/ip_fastfwd.c Removed all direct ipfw handling code and replace it with the new 'ipfw forward' handling code. netinet/ip_fw.h Removed 'ro' and 'dst' from struct ip_fw_args. netinet/ip_fw2.c (Re)moved some global variables and the module handling. netinet/ip_fw_pfil.c New file containing the ipfw PFIL handlers and module initialization. netinet/ip_input.c Removed all direct ipfw handling code and replace it with the new 'ipfw forward' handling code. ip_forward() does not longer require the 'next_hop' struct sockaddr_in argument. Disable early checks if 'srcrt' is set. netinet/ip_output.c Removed all direct ipfw handling code and replace it with the new 'ipfw forward' handling code. netinet/ip_var.h Add ip_reass() as general function. (Used from ipfw PFIL handlers for IPDIVERT.) netinet/raw_ip.c Directly check if ipfw and dummynet control pointers are active. netinet/tcp_input.c Rework the 'ipfw forward' to local code to work with the new way of forward tags. netinet/tcp_sack.c Remove include 'opt_ipfw.h' which is not needed here. sys/mbuf.h Remove m_claim_next() macro which was exclusively for ipfw 'forward' and is no longer needed. Approved by: re (scottl)
* Add locking to the kqueue subsystem. This also makes the kqueue subsystemjmg2004-08-154-28/+30
| | | | | | | | | | | | | a more complete subsystem, and removes the knowlege of how things are implemented from the drivers. Include locking around filter ops, so a module like aio will know when not to be unloaded if there are outstanding knotes using it's filter ops. Currently, it uses the MTX_DUPOK even though it is not always safe to aquire duplicate locks. Witness currently doesn't support the ability to discover if a dup lock is ok (in some cases). Reviewed by: green, rwatson (both earlier versions)
* Use IFQ_SET_MAXLEN() to set the maximum queue depth of the routingrwatson2004-08-131-1/+1
| | | | | | socket netisr queue. Pointed out by: winter
OpenPOWER on IntegriCloud