Commit Graph

107 Commits

Author SHA1 Message Date
riastradh d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
msaitoh 3cd62456f9 Implement the BPF direction filter (BIOC[GS]DIRECTION). It provides backward
compatibility with BIOC[GS]SEESENT ioctl. The userland interface is the same
as FreeBSD.

 This change also fixes a bug that the direction is misunderstand on some
environment by passing the direction to bpf_mtap*() instead of checking
m->m_pkthdr.rcvif.
2018-06-26 06:47:57 +00:00
ozaki-r 436bca6c47 Don't set IFEF_MPSAFE unless NET_MPSAFE at this point
Because recent investigations show that interfaces with IFEF_MPSAFE need to
follow additional restrictions to work with the flag safely. We should enable it
on an interface by default only if the interface surely satisfies the
restrictions, which are described in if.h.

Note that enabling IFEF_MPSAFE solely gains a few benefit on performance because
the network stack is still serialized by the big kernel locks by default.
2017-12-19 03:32:35 +00:00
christos ea05286d92 add fo_name so we can identify the fileops in a simple way. 2017-11-30 20:25:54 +00:00
jmcneill 7165875eea set IFEF_MPSAFE 2017-11-29 19:27:52 +00:00
jmcneill 8413866399 Make tap(4) MP-safe. 2017-11-29 19:21:44 +00:00
ozaki-r 7010c5b04d Set IFEF_NO_LINK_STATE_CHANGE flag to pseudo devices that don't use if_link_state_change 2017-10-30 16:01:19 +00:00
msaitoh 2223ce7058 - If if_initialize() failed in the attach function, free resources and return.
- KNF
2017-10-23 09:32:33 +00:00
skrll 4c9468e5b1 Whitespace 2017-02-12 09:47:31 +00:00
skrll 18a70850e5 Convert to kmem(9) 2017-02-12 08:51:45 +00:00
skrll 3cc4428ad4 Typo in comment 2017-02-12 08:47:12 +00:00
skrll a7ecd2081f KNF (sort #include <sys/...>) and remove a duplicate 2017-02-12 08:40:19 +00:00
skrll 3a6718d674 KNF and trailing whitespace. No functional change. 2017-02-07 11:17:50 +00:00
ozaki-r dd8638eea5 Move bpf_mtap and if_ipackets++ on Rx of each driver to percpuq if_input
The benefits of the change are:
- We can reduce codes
- We can provide the same behavior between drivers
  - Where/When if_ipackets is counted up
  - Note that some drivers still update packet statistics in their own
    way (periodical update)
- Moved bpf_mtap run in softint
  - This makes it easy to MP-ify bpf

Proposed on tech-kern and tech-net
2016-12-15 09:28:02 +00:00
christos 9c7db92f68 MFREE -> m_free 2016-10-02 14:16:02 +00:00
christos bbc7b97ded remove MODULAR/COMPAT_40 ifdef. 2016-08-15 05:10:33 +00:00
christos a74f222e94 fix rump tests. 2016-08-14 11:03:21 +00:00
kre 73176b8121 create++, destroy-- 2016-08-08 16:40:39 +00:00
pgoyette 822a1852a7 Typo (missing ampersand) 2016-08-08 09:51:39 +00:00
pgoyette 2bdbc91cbc Final part of fixing if_tap. The module needs to attach its cdevsw (and
detach it later).
2016-08-08 09:42:33 +00:00
pgoyette 1a2474cc13 Add the devsw_attach stuff, since the tap device can be accessed via
/dev/tap

This is a partial fix for the build.  The rump tap component will be
fixed shortly.
2016-08-08 09:23:13 +00:00
pgoyette b70b5f48f4 Partial fix - restore creation of our sysctl subtree for _MODULE
builds (it's already handled for built-in builds via registration
in a link-set).

XXX The build is still broken in rump...
2016-08-08 07:35:12 +00:00
christos 1d8e08d4c8 modularize some more drivers and merge the module glue 2016-08-07 17:38:33 +00:00
ozaki-r d938d837b3 Introduce m_set_rcvif and m_reset_rcvif
The API is used to set (or reset) a received interface of a mbuf.
They are counterpart of m_get_rcvif, which will come in another
commit, hide internal of rcvif operation, and reduce the diff of
the upcoming change.

No functional change.
2016-06-10 13:27:10 +00:00
ozaki-r 9c4cd06355 Introduce softint-based if_input
This change intends to run the whole network stack in softint context
(or normal LWP), not hardware interrupt context. Note that the work is
still incomplete by this change; to that end, we also have to softint-ify
if_link_state_change (and bpf) which can still run in hardware interrupt.

This change softint-ifies at ifp->if_input that is called from
each device driver (and ieee80211_input) to ensure Layer 2 runs
in softint (e.g., ether_input and bridge_input). To this end,
we provide a framework (called percpuq) that utlizes softint(9)
and percpu ifqueues. With this patch, rxintr of most drivers just
queues received packets and schedules a softint, and the softint
dequeues packets and does rest packet processing.

To minimize changes to each driver, percpuq is allocated in struct
ifnet for now and that is initialized by default (in if_attach).
We probably have to move percpuq to softc of each driver, but it's
future work. At this point, only wm(4) has percpuq in its softc
as a reference implementation.

Additional information including performance numbers can be found
in the thread at tech-kern@ and tech-net@:
http://mail-index.netbsd.org/tech-kern/2016/01/14/msg019997.html

Acknowledgment: riastradh@ greatly helped this work.
Thank you very much!
2016-02-09 08:32:07 +00:00
christos e7ae23fd9e include "ioconf.h" to get the 'void <driver>attach(int count);' prototype. 2015-08-20 14:40:16 +00:00
ozaki-r ae4ecace09 Replace if_attach of if_tap with if_initialize and if_register 2014-12-17 09:41:30 +00:00
ozaki-r 16af22f197 Complete the initialization of tap_softc before if_attach
Basically we should complete the initializaiton of softc before if_attach
because once if_attach is called if_detach can be called for the softc
before returning from if_attach. In case of tap, mutex_destroy can be
called before mutex_init that comes after if_attach.
2014-11-07 09:26:08 +00:00
skrll 7123045127 Remove unneeded #include 2014-10-03 06:46:02 +00:00
matt 45b1ec740d Try not to use f_data, use f_{vnode,socket,pipe,mqueue,kqueue,ksem} to get
a correctly typed pointer.
2014-09-05 09:20:59 +00:00
dholland f9228f4225 Add d_discard to all struct cdevsw instances I could find.
All have been set to "nodiscard"; some should get a real implementation.
2014-07-25 08:10:31 +00:00
cube 1d53b5b172 Prevent a race between tap_dev_poll() and tap_start() by making sure the
call to selrecord() happens at splnet().  Fixes kern/47506 and kern/46199.
2014-05-07 22:53:34 +00:00
aymeric 0a70cfa1fe Call mutex_destroy() on sc_kqlock in tap_detach(). Found by LOCKDEBUG. 2014-04-20 22:39:51 +00:00
skrll 8f2cde0556 Mechanically replace simplelock with kmutex_t. 2014-03-20 06:48:54 +00:00
dholland a68f9396b6 Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
2014-03-16 05:20:22 +00:00
pooka 4f6fb3bf35 Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
2014-02-25 18:30:08 +00:00
yamt 44ef5a4f25 - deal with softint_establish failure
- establish softint only when necessary
2013-08-20 12:28:12 +00:00
yamt aad8ef3224 use cprng_fast instead of getmicrouptime to generate "random" mac address
because the latter often produces the same addresses for subsequent tap
instances.
2013-01-28 15:05:03 +00:00
yamt cc345863dc whitespace 2013-01-28 15:01:13 +00:00
chs cbab9cadce split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
2012-10-27 17:17:22 +00:00
dsl e21a34c25e Add some pre-processor magic to verify that the type of the data item
passed to sysctl_createv() actually matches the declared type for
  the item itself.
In the places where the caller specifies a function and a structure
  address (typically the 'softc') an explicit (void *) cast is now needed.
Fixes bugs in sys/dev/acpi/asus_acpi.c sys/dev/bluetooth/bcsp.c
  sys/kern/vfs_bio.c sys/miscfs/syncfs/sync_subr.c and setting
  AcpiGbl_EnableAmlDebugObject.
(mostly passing the address of a uint64_t when typed as CTLTYPE_INT).
I've test built quite a few kernels, but there may be some unfixed MD
  fallout. Most likely passing &char[] to char *.
Also add CTLFLAG_UNSIGNED for unsiged decimals - not set yet.
2012-06-02 21:36:41 +00:00
christos 420ea92013 PR/44131: Matthew Mondor: if_tap.c tap_dev_ioctl() not propagating error,
always returns 0.
2010-11-22 21:31:51 +00:00
christos 5cbb2aa881 Replace ether_nonstatic_aton with a
- better named one
- not suffering from buffer oveflow
- simpler
- handling different separators
- returning error codes for errors

Some ideas from one posted on tech-net by Jonathan A. Kollasch
2010-05-19 20:41:59 +00:00
joerg 58e867556f Push the bpf_ops usage back into bpf.h. Push the common ifp->if_bpf
check into the inline functions as well the fourth argument for
bpf_attach.
2010-04-05 07:19:28 +00:00
pooka 10fe49d72c Redefine bpf linkage through an always present op vector, i.e.
#if NBPFILTER is no longer required in the client.  This change
doesn't yet add support for loading bpf as a module, since drivers
can register before bpf is attached.  However, callers of bpf can
now be modularized.

Dynamically loadable bpf could probably be done fairly easily with
coordination from the stub driver and the real driver by registering
attachments in the stub before the real driver is loaded and doing
a handoff.  ... and I'm not going to ponder the depths of unload
here.

Tested with i386/MONOLITHIC, modified MONOLITHIC without bpf and rump.
2010-01-19 22:06:18 +00:00
dsl 2a54322c7b If a multithreaded app closes an fd while another thread is blocked in
read/write/accept, then the expectation is that the blocked thread will
exit and the close complete.
Since only one fd is affected, but many fd can refer to the same file,
the close code can only request the fs code unblock with ERESTART.
Fixed for pipes and sockets, ERESTART will only be generated after such
a close - so there should be no change for other programs.
Also rename fo_abort() to fo_restart() (this used to be fo_drain()).
Fixes PR/26567
2009-12-20 09:36:05 +00:00
dsl 7a42c833db Rename fo_drain() to fo_abort(), 'drain' is used to mean 'wait for output
do drain' in many places, whereas fo_drain() was called in order to force
blocking read()/write() etc calls to return to userspace so that a close()
call from a different thread can complete.
In the sockets code comment out the broken code in the inner function,
it was being called from compat code.
2009-12-09 21:32:58 +00:00
plunky 7f5b5a7b01 fix a potential leak on tap device close, purging the send queue
did not actually release the dequeued mbufs.

pointed out by Paul Forgey on tech-net
2009-11-29 10:44:23 +00:00
drochner d70cb77245 fix undefined result of stat(), found by clang static analyzer 2009-09-15 19:38:15 +00:00
plunky 076d7e3e4e Avoid a kernel assertion failure upstream by using FSTATE_NOTFOUND
rather than FSTATE_FOUND when setting the unit number directly.

config_attach_pseudo() will convert it to FSTATE_FOUND just after the
assertion.
2009-07-23 17:53:17 +00:00