2302 Commits

Author SHA1 Message Date
rmind
f7fec0d2a4 Multiple NPF fixes, add better error reporting from kernel side, add some
asserts, bump the version.
2012-02-05 00:37:13 +00:00
christos
86cd0e8b2d PR/45764, PR/45914
Part 2:
Arrange so that the pointers that we free (ifp->if_afdata, dom->dom_ifqueues[i])
are set to NULL.
While I am here, add a continue.
2012-02-03 03:35:30 +00:00
matt
4b50cb788d Use proper ANSI prototypes for foo() -> foo(void)
Caught when compiling with -Wold-style-definition
2012-01-30 23:31:27 +00:00
christos
80398b9c60 - don't copy past the end of sockaddr if we are rounding, zero it out instead,
from mlelstv@
- put a comment explaining the 6 nuls.
2012-01-30 20:02:55 +00:00
christos
92b963447b Count length from the beginning of the structure not the sa_data portion.
From skrll@
2012-01-30 20:01:08 +00:00
rmind
833816ab75 Replace tun_lock with mutex(9). XXX: too far from being MP-safe yet. 2012-01-28 01:02:27 +00:00
rmind
4b85474b41 - Expire all sessions on flush.
- Enable checking for zero mask in IP{4,6}MATCH after npfctl changes.
- Make locking symmetric for npf_ruleset_inspect().
- Sync function prototypes in npf(3) man page with reality.
- Rename NPF_TABLE_RBTREE to NPF_TABLE_TREE.
2012-01-15 00:49:47 +00:00
christos
42c420856f - fix offsetof usage, and redundant defines
- kill pointer casts to 0
2011-12-31 20:41:58 +00:00
alnsn
c55c73b80d Apply same bounds checks for BPF_LD|BPF_B|BPF_IND as for
BPF_LD|BPF_H|BPF_IND and BPF_LD|BPF_W|BPF_IND.

From FreeBSD r48548, the original r45574 had a typo.
2011-12-29 23:47:21 +00:00
christos
b0874ea247 PR/45751: Alexander Nasonov: No overflow check in BPF_LD|BPF_ABS 2011-12-29 20:50:06 +00:00
dyoung
b604e06e51 Fix ifpromisc() regression: if ifpromisc(ifp, 1) is called, do set
IFF_PROMISC whether ifp is IFF_UP or not, but do not call ifp->if_ioctl
unless ifp is IFF_UP.
2011-12-28 02:14:57 +00:00
christos
64f7c0e218 PR/45730: David Holland: Avoid having 2 copies of bpf.h in /usr/include.
This adds the missing entries from libpcap to make libpcap compile with
our bpf.h.
2011-12-21 19:04:18 +00:00
tls
6e1dd068e9 Separate /dev/random pseudodevice implemenation from kernel entropy pool
implementation.  Rewrite pseudodevice code to use cprng_strong(9).

The new pseudodevice is cloning, so each caller gets bits from a stream
generated with its own key.  Users of /dev/urandom get their generators
keyed on a "best effort" basis -- the kernel will rekey generators
whenever the entropy pool hits the high water mark -- while users of
/dev/random get their generators rekeyed every time key-length bits
are output.

The underlying cprng_strong API can use AES-256 or AES-128, but we use
AES-128 because of concerns about related-key attacks on AES-256.  This
improves performance (and reduces entropy pool depletion) significantly
for users of /dev/urandom but does cause users of /dev/random to rekey
twice as often.

Also fixes various bugs (including some missing locking and a reseed-counter
overflow in the CTR_DRBG code) found while testing this.

For long reads, this generator is approximately 20 times as fast as the
old generator (dd with bs=64K yields 53MB/sec on 2Ghz Core2 instead of
2.5MB/sec) and also uses a separate mutex per instance so concurrency
is greatly improved.  For reads of typical key sizes for modern
cryptosystems (16-32 bytes) performance is about the same as the old
code: a little better for 32 bytes, a little worse for 16 bytes.
2011-12-17 20:05:38 +00:00
christos
4bdfaa0aa3 make comment reflect reality 2011-12-16 03:05:23 +00:00
christos
811ac7bb4f don't leak mbufs. 2011-12-15 22:20:26 +00:00
roy
46df35d87e When adding or scrubbing a prefix, always notify userland even if the
prefix does not have IFA_ROUTE.
Don't scrub the interface in SIOCAIFADDR if the new address does't
have IFA_ROUTE. If more functions are added to in_ifscrub then this logic
might need to be revisited.

Fixes PR/26450.
2011-12-12 00:06:39 +00:00
rmind
215a4b5f51 - Explain the magic in npf_tcpfl2case().
- Use __unused instead of (void)cast; fix comment.
2011-12-08 23:36:57 +00:00
rmind
f2701a6f1c - Add npf_tcpfl2case() and make TCP state table more compact.
- Adjust the state for FIN case on sim-SYN and SYN-RECEIVED.
2011-12-05 00:34:25 +00:00
rmind
fad8b2d7a1 - Rework and improve TCP state tracking.
- Fix regressions after IPv6 patch merge.

Note: npfctl(8) rework will come soon.
2011-11-29 20:05:30 +00:00
drochner
2467eee7c7 sys/pcq.h isn't installed to userland, so only include it ifdef _KERNEL,
fixes glitch in kdump build
2011-11-29 17:28:45 +00:00
jakllsch
3a65f68183 We need a cv_destroy() here too. Fixes LOCKDEBUG panic on interface detachment. 2011-11-27 14:55:57 +00:00
kiyohara
6c04b3bca9 Fix build failed. Include if_inarp.h. 2011-11-20 12:15:38 +00:00
tls
3afd44cf08 First step of random number subsystem rework described in
<20111022023242.BA26F14A158@mail.netbsd.org>.  This change includes
the following:

	An initial cleanup and minor reorganization of the entropy pool
	code in sys/dev/rnd.c and sys/dev/rndpool.c.  Several bugs are
	fixed.  Some effort is made to accumulate entropy more quickly at
	boot time.

	A generic interface, "rndsink", is added, for stream generators to
	request that they be re-keyed with good quality entropy from the pool
	as soon as it is available.

	The arc4random()/arc4randbytes() implementation in libkern is
	adjusted to use the rndsink interface for rekeying, which helps
	address the problem of low-quality keys at boot time.

	An implementation of the FIPS 140-2 statistical tests for random
	number generator quality is provided (libkern/rngtest.c).  This
	is based on Greg Rose's implementation from Qualcomm.

	A new random stream generator, nist_ctr_drbg, is provided.  It is
	based on an implementation of the NIST SP800-90 CTR_DRBG by
	Henric Jungheim.  This generator users AES in a modified counter
	mode to generate a backtracking-resistant random stream.

	An abstraction layer, "cprng", is provided for in-kernel consumers
	of randomness.  The arc4random/arc4randbytes API is deprecated for
	in-kernel use.  It is replaced by "cprng_strong".  The current
	cprng_fast implementation wraps the existing arc4random
	implementation.  The current cprng_strong implementation wraps the
	new CTR_DRBG implementation.  Both interfaces are rekeyed from
	the entropy pool automatically at intervals justifiable from best
	current cryptographic practice.

	In some quick tests, cprng_fast() is about the same speed as
	the old arc4randbytes(), and cprng_strong() is about 20% faster
	than rnd_extract_data().  Performance is expected to improve.

	The AES code in src/crypto/rijndael is no longer an optional
	kernel component, as it is required by cprng_strong, which is
	not an optional kernel component.

	The entropy pool output is subjected to the rngtest tests at
	startup time; if it fails, the system will reboot.  There is
	approximately a 3/10000 chance of a false positive from these
	tests.  Entropy pool _input_ from hardware random numbers is
	subjected to the rngtest tests at attach time, as well as the
	FIPS continuous-output test, to detect bad or stuck hardware
	RNGs; if any are detected, they are detached, but the system
	continues to run.

	A problem with rndctl(8) is fixed -- datastructures with
	pointers in arrays are no longer passed to userspace (this
	was not a security problem, but rather a major issue for
	compat32).  A new kernel will require a new rndctl.

	The sysctl kern.arandom() and kern.urandom() nodes are hooked
	up to the new generators, but the /dev/*random pseudodevices
	are not, yet.

	Manual pages for the new kernel interfaces are forthcoming.
2011-11-19 22:51:18 +00:00
dyoung
d74f0a643d Before freeing an ifnet_lock, destroy its mutex. Should help with
kern/43294.
2011-11-16 06:09:37 +00:00
jakllsch
dacb12f218 Make a comment consistent with the code. 2011-11-12 14:51:41 +00:00
gdt
c9bfbf1142 Move RTF_ANNOUNCE flag so that it no longer conflicts with RTF_PROTO2.
RTF_ANNOUNCE was defined as RTF_PROTO2.  The flag is used to indicated
that host should act as a proxy for a link level arp or ndp request.
(If RTF_PROTO2 is used as an experimental flag (as advertised),
various problems can occur.)

This commit provides a first-class definition with its own bit for
RTF_ANNOUNCE, removes the old aliasing definitions, and adds support
for the new RTF_ANNOUNCE flag to netstat(8) and route(8).,

Also, remove unused RTF_ flags that collide with RTF_PROTO1:
  netinet/icmp6.h defined RTF_PROBEMTU as RTF_PROTO1
  netinet/if_inarp.h defined RTF_USETRAILERS as RTF_PROTO1
  (Neither of these flags are used anywhere.  Both have been removed
  to reduce chances of collision with RTF_PROTO1.)

Figuring this out and the diff are the work of Beverly Schwartz of
BBN.

(Passed release build, boot in VM, with no apparently related atf
failures.)

Approved for Public Release, Distribution Unlimited
This material is based upon work supported by the Defense Advanced
Research Projects Agency and Space and Naval Warfare Systems Center,
Pacific, under Contract No. N66001-09-C-2073.
2011-11-11 15:09:32 +00:00
christos
60b08a4dfb cosmetic, no functional change:
- sizeof(*var) instead of sizeof(type)
- sort the event counters in the discard the same as alloc for readability
2011-11-09 19:43:22 +00:00
tron
2a04f59494 Change module class to driver as npf(4) is a pseudo device. 2011-11-06 13:08:04 +00:00
rmind
09cdfd6a19 Few fixes, KNF/style, bump the NPF version. 2011-11-06 02:49:03 +00:00
zoltan
7d78d5aecf When building the kernel without IPv6 support, compilation failed.
Fix that.
2011-11-05 10:23:26 +00:00
jakllsch
380d04da8a Use uint8_t instead of npf_netmask_t, as npf_netmask_t is a uint_fast8_t,
which is in many places is actually a uint32_t and thus incompatible with
prop_dictionary_get_uint8().  The correct type is noted in a comment.
2011-11-04 02:57:28 +00:00
zoltan
5a5d868dc5 Add IPv6 support for NPF. 2011-11-04 01:00:27 +00:00
dyoung
89986fc527 For simplicity's sake, use pcq(9) instead of my own circular-queue
implementation.  Saves 45 lines of code.
2011-11-02 01:17:59 +00:00
yamt
02a75580d4 remove an unnecessary cast 2011-10-31 12:50:50 +00:00
dyoung
53c8737e53 For these interfaces, the implementation of SIOCSIFDSTADDR is identical
to SIOCINITIFADDR, and SIOCSIFDSTADDR callers always fall back to
SIOCINITIFADDR, so just get rid of the SIOCSIFDSTADDR case.
2011-10-28 22:08:14 +00:00
dyoung
60d9d0608c Don't kauth-orize SIOCSIFMTU in pppsioctl() and stf_ioctl(), ifioctl()
has already done that for us.
2011-10-28 20:13:32 +00:00
dyoung
7609a81937 Userland may not change the IFF_CANTCHANGE flags, however, the kernel
may, so make sure if_flags_set() takes care of them.  Fixes a regression
in ifpromisc().
2011-10-28 20:11:58 +00:00
dyoung
bca1ae2608 Don't kauth-orize SIOCDIFPHYADDR, SIOCSIFFLAGS, SIOCSIFMTU, or
SIOCSLIFPHYADDR, in gif_ioctl() or in gre_ioctl(), because those
operations are ordinarily kauth-orized already in ifioctl().

Kauth-orizing SIOCSIFFLAGS in gre_ioctl() caused a panic ("panic:
bpf_detachd: ifpromisc failed: 1") when tcpdump(8) was interrupted.
Somehow bpf(4) enables promiscuous mode using different credentials than
it uses to disable promiscuous mode, hence the ifpromisc failure.  This
may have something to do with privilege-separation in tcpdump(8).  I.e.,
an LWP with SIOCSIFFLAGS privilege opens /dev/bpf, but an LWP without
SIOCSIFFLAGS privilege closes it.
2011-10-28 16:42:52 +00:00
dyoung
f7b2ead301 kauth isn't used in here, so don't #include <sys/kauth.h>. 2011-10-28 16:10:12 +00:00
dyoung
0275d524f1 Fix gif(4)/gre(4) operation over interfaces such as wm(4) that do IPv4
checksum-offload.  Note well: it really is necessary to clear the
csum_data.

While I'm here, remove the do-nothing case for SIOCSIFDSTADDR and let
ifioctl_common() or the protocol handle it.
2011-10-27 20:04:57 +00:00
dyoung
b9e1bc4e41 Document the ifioctl locking in comments.
Add a missing percpu_free(9) call.
2011-10-25 22:26:18 +00:00
dyoung
3dbb17c433 Use if_flags_set() and if_mcast_op(). 2011-10-19 22:07:09 +00:00
dyoung
d2e7867bc1 Get rid of gre's deadlock-prone, one-off ifioctl locking. The standard
ifioctl locking will do.
2011-10-19 21:59:38 +00:00
dyoung
ea1b432e78 Fix userland compilation: pull the ifioctl lock-related data members
into a struct ifnet_lock that the ifnet has a pointer to.  In a
non-_KERNEL environment, don't #include <sys/percpu.h> et cetera, and
don't define the struct ifnet_lock but *do* declare it.
2011-10-19 21:29:51 +00:00
dyoung
82f65cfc5a Use if_flags_set() and if_addr_init() instead of ifp->if_ioctl(). 2011-10-19 01:49:50 +00:00
dyoung
96ddefeaea Use if_mcast_op() and if_flags_set() instead of calling ifp->if_ioctl(). 2011-10-19 01:48:30 +00:00
dyoung
9454d9b3cd Extract subroutines ifioctl_enter() and ifioctl_exit(). 2011-10-19 01:46:43 +00:00
dyoung
ab5a4db2a3 Start to untangle the ifnet ioctls mess.
Add ifnet functions, if_mcast_op(), if_flags_set(), and if_addr_init()
for adding/deleting multicast addresses, modifying the if_flags,
and initializing local/remote addresses.  Make ifpromisc() use
if_flags_set().  Protocols and network drivers should use these
instead of ifp->if_ioctl() calls.  Subsequent commits will
replace ifp->if_ioctl(SIOCADDMULTI| SIOCDELMULTI| SIOCSIFDSTADDR|
SIOCINITIFADDR| SIOCSIFFLAGS) calls with calls to the new functions.

Use a mutex(9) to synchronize ifp->if_ioctl() calls originating in
userland.  Also synchronize ifp->if_ioctl() calls with ifnet detachment
and reclamation.
2011-10-19 01:34:37 +00:00
dyoung
0f201a09eb Cosmetic: remove whitespace at the end of line. 2011-10-07 16:34:31 +00:00
christos
04f8076084 Change obsolete CBSIZE constant (48), to a power of two constant (64) that
is close enough to match the original assumptions.
2011-09-23 15:29:08 +00:00