Commit Graph

255 Commits

Author SHA1 Message Date
drochner
d26dda3d0d As a first step towards more fine-grained locking, don't require
crypto_{new.free}session() to be called with the "crypto_mtx"
spinlock held.
This doesn't change much for now because these functions acquire
the said mutex first on entry now, but at least it keeps the nasty
locks local to the opencrypto core.
2011-05-06 21:48:46 +00:00
drochner
41fde2494b fix C&P botch in diagnostic printfs 2011-05-05 20:15:14 +00:00
drochner
08355b198c support camellia-cbc as ESP cipher 2011-05-05 17:48:29 +00:00
spz
749619c9e1 mitigation for CVE-2011-1547 2011-04-01 08:29:29 +00:00
spz
2fbfb83e1b fix compiling with IPSEC_DEBUG:
it's authsize not authlen in struct auth_hash
2011-03-27 21:56:57 +00:00
drochner
b4da53f1e6 make the use of SHA2-HMAC by FAST_IPSEC compliant to current standards:
-RFC2104 says that the block size of the hash algorithm must be used
 for key/ipad/opad calculations. While formerly all ciphers used a block
 length of 64, SHA384 and SHA512 use 128 bytes. So we can't use the
 HMAC_BLOCK_LEN constant anymore. Add a new field to "struct auth_hash"
 for the per-cipher blocksize.
-Due to this, there can't be a single "CRYPTO_SHA2_HMAC" external name
 anymore. Replace this by 3 for the 3 different keysizes.
 This was done by Open/FreeBSD before.
-Also fix the number of authenticator bits used tor ESP and AH to
 conform to RFC4868, and remove uses of AH_HMAC_HASHLEN which did
 assume a fixed authenticator size of 12 bytes.

FAST_IPSEC will not interoperate with KAME IPSEC anymore if sha2 is used,
because the latter doesn't implement these standards. It should
interoperate with at least modern Free/OpenBSD now.
(I've only tested with NetBSD-current/FAST_IPSEC on both ends.)
2011-02-25 20:13:10 +00:00
drochner
1caa9a52b2 small modifications in dealing with the unknown result size of compression/
decompression:
-seperate the IPCOMP specific rule that compression must not grow the
 data from general compression semantics: Introduce a special name
 CRYPTO_DEFLATE_COMP_NOGROW/comp_algo_deflate_nogrow to describe
 the IPCOMP semantics and use it there. (being here, fix the check
 so that equal size is considered failure as well as required by
 RFC2393)
 Customers of CRYPTO_DEFLATE_COMP/comp_algo_deflate now always get
 deflated data back, even if they are not smaller than the original.
-allow to pass a "size hint" to the DEFLATE decompression function
 which is used for the initial buffer allocation. Due to the changes
 done there, additional allocations and extra copies are avoided if the
 initial allocation is sufficient. Set the size hint to MCLBYTES (=2k)
 in IPCOMP which should be good for many use cases.
2011-02-24 20:03:41 +00:00
drochner
4b552d0b1b adopt a fix from OpenBSD: when scanning the IPv6 header chain, take
into account that the extension header type is not in the extension
header itself but in the previous one -- this makes a difference
because (a) the length field is different for AH than for all others
and (b) the offset of the "next type" field isn't the same in primary
and extension headers.
(I didn't manage to trigger the bug in my tests, no extension headers
besides AH made it to that point. Didn't try hard enough -- the fix
is still valid.)
2011-02-21 22:54:45 +00:00
drochner
bc5ee3cb6d treat "struct secpolicyindex" and "struct secasindex" as "const" once
they are initialized -- during lifetime, no changes are expected
plus some constification of input to comparision functions etc
mostly required by the former
2011-02-21 22:28:18 +00:00
drochner
7a1d44a2ce declare input to kdebug_*() functions which dump structures
to stdout in human readable form as "const"
2011-02-21 22:21:40 +00:00
degroote
de55cbd2df Fix a missing const in FAST_IPSEC && IPSEC_DEBUG 2011-02-19 18:26:50 +00:00
drochner
909a8e8346 more "const" 2011-02-18 19:56:01 +00:00
drochner
bbd82ed172 sprinkle some "const", documenting that the SA is not supposed to
change during an xform operation
2011-02-18 19:06:45 +00:00
drochner
e790ebf12c do proper statistics counting for outbound packets, fixes PR kern/30182
by Gilles Roy
2011-02-18 16:12:26 +00:00
drochner
a301ba8826 deal with IPv6 address scope, so that SA lookup for
link-local addresses works
(PR kern/43071 is related, but refers to KAME IPSEC)
2011-02-18 16:10:11 +00:00
drochner
cd9bf26d13 handle some unlikely IPv6 error case like everywhere else:
free mbuf, inc statcounter. from OpenBSD
being here, fix a diagnostic output
2011-02-17 20:20:18 +00:00
drochner
443d341d0f remove some unnecessary pointer typecasts
(one was wrong on BE systems, but was harmless here because the
result is effectively unused)
2011-02-16 18:39:33 +00:00
drochner
6ed51462a6 one more botched statistics counter (could increment semi-random locations) 2011-02-14 18:49:31 +00:00
drochner
254b02f7fb fix output bytecount statcounter 2011-02-14 16:34:43 +00:00
drochner
72fa9245cb change locking order, to make sure the cpu is at splsoftnet()
before the softnet_lock (adaptive) mutex is acquired, from
Wolfgang Stukenbrock, should fix a recursive lock panic
2011-02-14 13:43:45 +00:00
drochner
7d0822f82d invalidate the secpolicy cache bin the PCB before destroying, so that
the refcount in the (global) policies gets decremented
(This apparently was missed when the policy cache code was copied
over from KAME IPSEC.)
From Wolfgang Stukenbrock per PR kern/44410, just fixed differently
to avoid unecessary differences to KAME.
2011-02-11 17:53:35 +00:00
drochner
67244067f4 in rev.1.192 of ip_output.c the semantics of ip_output() was changed:
Before, setting the IP_RAWOUTPUT flag did imply that the ip_id
(the fragmentation thing) was used as-is.
Now, a new ID is diced unless the new IP_NOIPNEWID flag is set.
The ip_id is part of the data which are used to calculate the hash
for AH, so set the IP_NOIPNEWID flag to make sure the IP header
is not modified behind AH's back. Otherwise, the recipient will detect
a checksum mismatch and discard the packet.
2011-02-10 20:42:30 +00:00
drochner
6c21d3ecdd -in opencrypto callbacks (which run in a kernel thread), pull softnet_lock
everywhere splsoftnet() was used before, to fix MP concurrency problems
-pull KERNEL_LOCK where ip(6)_output() is called, as this is what
 the network stack (unfortunately) expects, in particular to avoid
 races for packets in the interface send queues
From Wolfgang Stukenbrock per PR kern/44418, with the application
of KERNEL_LOCK to what I think are the essential points, tested
on a dual-core i386.
2011-02-10 20:24:27 +00:00
degroote
cd96000382 Fix ipcomp input counter
Reported Wolfgang Stukenbrock in pr/43250.
2010-09-21 13:41:18 +00:00
spz
445e6acd20 fix two bugs in the PFKEY interface:
1) RFC2367 says in 2.3.3 Address Extension: "All non-address
   information in the sockaddrs, such as sin_zero for AF_INET sockaddrs,
   and sin6_flowinfo for AF_INET6 sockaddrs, MUST be zeroed out."
   the IPSEC_NAT_T code was expecting the port information it needs
   to be conveyed in the sockaddr instead of exclusively by
   SADB_X_EXT_NAT_T_SPORT and SADB_X_EXT_NAT_T_DPORT,
   and was not zeroing out the port information in the non-nat-traversal
   case.
   Since it was expecting the port information to reside in the sockaddr
   it could get away with (re)setting the ports after starting to use them.
   -> Set the natt ports before setting the SA mature.

2) RFC3947 has two Original Address fields, initiator and responder,
   so we need SADB_X_EXT_NAT_T_OAI and SADB_X_EXT_NAT_T_OAR and not just
   SADB_X_EXT_NAT_T_OA

The change has been created using vanhu's patch for FreeBSD as reference.

Note that establishing actual nat-t sessions has not yet been tested.

Likely fixes the following:
PR bin/41757
PR net/42592
PR net/42606
2010-09-05 06:52:53 +00:00
spz
d4446651db trivial comment typo 2010-08-28 07:16:51 +00:00
jakllsch
e7bf96a4c3 Further silence ipsec_attach().
"initializing IPsec..."" done" is of somewhat limited value.
(I normally wouldn't care; but on my box the (root) uhub(4)s attach
between the first and last portion of the line.)
2010-07-21 20:41:31 +00:00
joerg
d621e29eca Remove separate mb_map. The nmbclusters is computed at boot time based
on the amount of physical memory and limited by NMBCLUSTERS if present.
Architectures without direct mapping also limit it based on the kmem_map
size, which is used as backing store. On i386 and ARM, the maximum KVA
used for mbuf clusters is limited to 64MB by default.

The old default limits and limits based on GATEWAY have been removed.
key_registered_sb_max is hard-wired to a value derived from 2048
clusters.
2010-02-08 19:02:25 +00:00
hubertf
af120bb199 Replace more printfs with aprint_normal / aprint_verbose
Makes "boot -z" go mostly silent for me.
2010-01-31 00:43:37 +00:00
dyoung
7e597f6140 Cosmetic: fix indentation, change some spaces to tabs. 2009-12-01 01:01:34 +00:00
jakllsch
7d100c1859 As explained in kern/41701 there's a missing splx() here. 2009-07-30 14:41:59 +00:00
christos
1e42098381 Only print debugging messages about policy on error. 2009-06-25 17:39:51 +00:00
elad
efeb620e44 Adapt FAST_IPSEC to recent KPI changes.
Pointed out by dyoung@ on tech-kern@, thanks!
2009-05-10 02:13:07 +00:00
tsutsui
d779b85d3e Remove extra whitespace added by a stupid tool.
XXX: more in src/sys/arch
2009-04-18 14:58:02 +00:00
cegger
4f9cf8aa30 Correct bungled bcopy() -> memcpy() conversion 2009-03-20 05:26:37 +00:00
cegger
e2cb85904d bcopy -> memcpy 2009-03-18 17:06:41 +00:00
cegger
c363a9cb62 bzero -> memset 2009-03-18 16:00:08 +00:00
cegger
35fb64746b bcmp -> memcmp 2009-03-18 15:14:29 +00:00
cegger
df7f595ecd Ansify function definitions w/o arguments. Generated with sed. 2009-03-18 10:22:21 +00:00
dsl
02cdf4d2c8 Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
2009-03-14 14:45:51 +00:00
christos
f794ad1e52 remove 2038 comment. 2009-02-14 20:53:58 +00:00
skd
8d41ac5617 Back out my previous change. The problem I'm chasgin is with the
initialization of ports in saidx's when IPSEC_NAT_T is defined but the
association connection is not using nat traversal.  Stay tuned.
2009-02-09 15:06:37 +00:00
skd
744626ac10 These comparison functions return 0 on match. Fix sense of test. 2009-01-28 19:06:03 +00:00
cegger
9b87d582bd kill MALLOC and FREE macros. 2008-12-17 20:51:31 +00:00
ad
0efea177e3 Remove LKMs and switch to the module framework, pass 1.
Proposed on tech-kern@.
2008-11-12 12:35:50 +00:00
dsl
a8f5b9cfc2 Comment out the 'do' and 'while (0)' from KEY_CHKSASTATE().
The expansion contains a 'continue' which is expected to continue
a loop in the callling code, not just abort the #define.
2008-07-25 20:55:43 +00:00
mlelstv
be6f2a4b87 Ignore freed rtcache entries. 2008-07-01 20:18:45 +00:00
degroote
ba4ebf7e6b Kill caddr_t introduced in the previous revision
Fix build with FAST_IPSEC
2008-06-27 17:28:24 +00:00
mlelstv
fa014c6383 Verify icmp type and code in IPSEC rules.
Fixes PR kern/39018
2008-06-27 05:18:58 +00:00
thorpej
b129a80c20 Simplify the interface to netstat_sysctl() and allocate space for
the collated counters using kmem_alloc().

PR kern/38577
2008-05-04 07:22:14 +00:00
degroote
b6a04a1973 In key_do_allocsa_policy, fix a bad usage of key_setsadbmsg. The third argument
is an SADB_SATYPE_*, not an IPPROTO_* .

Fix PR/38405. Thanks for the report
2008-05-03 21:53:23 +00:00
martin
ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
degroote
bb588cd930 Fix a stupid typo. In ipsec6_process_packet, reinject the packet in AF_INET6,
nor in AF_INET.
2008-04-28 17:40:11 +00:00
degroote
e7dc156f58 Fix some fallout from socket locking patch :
- {ah6,esp6}_ctlinput must return void*
 - use correct wrapper for rip_usrreq
2008-04-27 12:58:48 +00:00
ad
15e29e981b Merge the socket locking patch:
- Socket layer becomes MP safe.
- Unix protocols become MP safe.
- Allows protocol processing interrupts to safely block on locks.
- Fixes a number of race conditions.

With much feedback from matt@ and plunky@.
2008-04-24 11:38:36 +00:00
thorpej
02f63fe1bf PF_KEY stats for IPSEC and FAST_IPSEC are now per-CPU. 2008-04-23 07:29:47 +00:00
thorpej
caf49ea572 Make IPSEC and FAST_IPSEC stats per-cpu. Use <net/net_stats.h> and
netstat_sysctl().
2008-04-23 06:09:04 +00:00
thorpej
680fd6866d Make ip6 and icmp6 stats per-cpu. 2008-04-15 04:43:53 +00:00
thorpej
3f466bce48 Change IPv6 stats from a structure to an array of uint64_t's.
Note: This is ABI-compatible with the old ip6stat structure; old netstat
binaries will continue to work properly.
2008-04-08 23:37:43 +00:00
degroote
f3f9c5b3a1 Fix build of FAST_IPSEC after the change of ip_newid prototype 2008-02-10 21:42:20 +00:00
tls
e5bd2a127e Rework opencrypto to use a spin mutex (crypto_mtx) instead of "splcrypto"
(actually splnet) and condvars instead of tsleep/wakeup.  Fix a few
miscellaneous problems and add some debugging printfs while there.

Restore set of CRYPTO_F_DONE in crypto_done() which was lost at some
point after this code came from FreeBSD -- it made it impossible to wait
properly for a condition.

Add flags analogous to the "crp" flags to the key operation's krp struct.
Add a new flag, CRYPTO_F_ONRETQ which tells us a request finished before
the kthread had a chance to dequeue it and call its callback -- this was
letting requests stick on the queues before even though done and copied
out.

Callers of crypto_newsession() or crypto_freesession() must now take the
mutex.  Change netipsec to do so.  Dispatch takes the mutex itself as
needed.

This was tested fairly extensively with the cryptosoft backend and lightly
with a new hardware driver.  It has not been tested with FAST_IPSEC; I am
unable to ascertain whether FAST_IPSEC currently works at all in our tree.

pjd@FreeBSD.ORG, ad@NetBSD.ORG, and darran@snark.us pointed me in the
right direction several times in the course of this.  Remaining bugs
are mine alone.
2008-02-04 00:35:34 +00:00
joerg
3615cf7715 Now that __HAVE_TIMECOUNTER and __HAVE_GENERIC_TODR are invariants,
remove the conditionals and the code associated with the undef case.
2008-01-20 18:09:03 +00:00
degroote
55718e804e Fix the ipsec processing in case of USE rules with no SA installed.
In case where there is no more isr to process, just tag the packet and reinject
in the ip{,6} stack.

Fix pr/34843
2007-12-29 16:43:17 +00:00
degroote
bd4ac64c48 Add some statistics for case where compression is not useful
(when len(compressed packet) > len(initial packet))
2007-12-29 14:56:35 +00:00
degroote
61e79ba32a Simplify the FAST_IPSEC output path
Only record an IPSEC_OUT_DONE tag when we have finished the processing
In ip{,6}_output, check this tag to know if we have already processed this
packet.
Remove some dead code (IPSEC_PENDING_TDB is not used in NetBSD)

Fix pr/36870
2007-12-29 14:53:24 +00:00
seanb
82a49e7352 - Remove remain <= MHLEN restriction in m_makespace()
PR:30124
2007-12-14 20:55:22 +00:00
lukem
9d8f493213 use __KERNEL_RCSID() 2007-12-11 12:40:10 +00:00
degroote
939a0dbd0a Kill _IP_VHL ifdef (from netinet/ip.h history, it has never been used in NetBSD so ...) 2007-12-09 18:27:39 +00:00
elad
3668e580ae Use struct initializers. No functional change. 2007-12-07 19:46:18 +00:00
elad
5a24b726ae Let this code compile.
Hi, liamjfoy@. :)
2007-12-07 19:44:38 +00:00
dyoung
5bbde3d775 Use IFNET_FOREACH() and IFADDR_FOREACH(). 2007-12-04 10:27:33 +00:00
christos
62edf45793 defflag IPSEC_DEBUG 2007-11-16 21:15:20 +00:00
adrianp
aaf8e048ae The function ipsec4_get_ulp assumes that ip_off is in host order. This results
in IPsec processing that is dependent on protocol and/or port can be bypassed.

Bug report, analysis and initial fix from Karl Knutsson.
Final patch and ok from degroote@
2007-10-28 15:48:23 +00:00
ad
a2a3828545 machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h 2007-10-19 11:59:34 +00:00
degroote
cdb020058a Fix my previous stupid caddr_t fix. 2007-09-22 23:33:18 +00:00
ad
88ab7da936 Merge some of the less invasive changes from the vmlocking branch:
- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
2007-07-09 20:51:58 +00:00
degroote
a382db0aa9 Ansify
Remove useless extern
bzero -> memset, bcopy -> memcpy

No functionnal changes
2007-07-07 18:38:22 +00:00
degroote
4ddfe916ff Add support for options IPSEC_NAT_T (RFC 3947 and 3948) for fast_ipsec(4).
No objection on tech-net@
2007-06-27 20:38:32 +00:00
degroote
5f72dadbd4 Always compute the sp index even if we don't have any sp in spd. It will
let us to choose the right default policy (based on the adress family
requested).

While here, fix an error message
2007-05-08 14:07:42 +00:00
degroote
8ebbd6c4f6 Increase the refcount for the default ipv6 policy so nobody can reclaim it 2007-05-08 14:03:05 +00:00
degroote
6997fa5f35 Choose the good default policy, depending of the adress family of the
desired policy
2007-04-15 14:17:12 +00:00
degroote
20341ba8ef Add sysctl tree to modify the fast_ipsec options related to ipv6. Similar
to the sysctl kame interface.
2007-04-11 22:21:41 +00:00
degroote
68c3173bb4 When we construct an answer for SADB_X_SPDGET, don't use an hardcoded 0 for seq but
the seq used by the request. It will improve consistency with the answer of SADB_GET
request and helps some applications which relies both on seq and pid.

Reported by  Karl Knutsson by pr/36119.
2007-04-11 21:33:40 +00:00
degroote
2a2cd74d79 In spddelete2, if we can't find the sp by this id, return after sending an error message,
don't process the following code with the NULL sp.

Spotted by Matthew Grooms on freebsd-net ML
2007-04-11 21:19:35 +00:00
degroote
0c3809d098 Fix a memleak in key_spdget.
Problem was reported by Karl Knutsson by pr/36119.
2007-04-09 21:07:03 +00:00
degroote
0138b12722 Honor the ip4_ah_offsetmask bits (clear or not the ip->ip_off field for ah
processing).
2007-03-25 22:11:18 +00:00
degroote
46c420f11a Use ip4_ah_cleartos instead of ah_cleartos for consistency 2007-03-25 22:06:33 +00:00
degroote
40cf3d18fa Make an exact match when we are looking for a cached sp for an unconnected
socket. If we don't make an exact match, we may use a cached rule which
has lower priority than a rule that would otherwise have matched the
packet.

Code submitted by Karl Knutsson in PR/36051
2007-03-25 12:46:42 +00:00
degroote
507fd51bd3 Call key_checkspidup with spi in network bit order in order to make correct
comparaison with spi stored into the sadb.

Reported by Karl Knutsson in kern/36038 .
2007-03-21 22:38:34 +00:00
liamjfoy
142de6f17b Allow to build without INET6
Submitted by: Jukka Salmi
2007-03-09 00:40:39 +00:00
liamjfoy
9763fa0590 Add IPv6 Fast Forward:
Add call to ip6flow_invalidate_all()

ok christos, matt, dyoung and joerg
2007-03-07 22:21:45 +00:00
degroote
dd86ba7231 Remove useless cast
Use NULL instead of (void*) 0
2007-03-04 21:17:54 +00:00
degroote
c252f603d0 Fix fallout from caddr_t changes 2007-03-04 19:54:48 +00:00
christos
53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
degroote
f76a162cb7 Oops, I forgot to commit some bits last time
fast_ipsec and ipcomp works better now.
2007-02-23 19:35:25 +00:00
degroote
9e2b4bf469 Always free the sav, not only in the mature case 2007-02-18 18:58:17 +00:00
degroote
5bf3692f91 Fix the {ah,esp}4_ctlinput code 2007-02-18 14:28:25 +00:00
degroote
b7fbb86788 Forgot to remove two useless extern 2007-02-18 14:13:52 +00:00
degroote
b0339b36b0 Constify the code following the dyoung change ( the "bug" was hidden by the
extern declaration ).
While here, remove a Kame ifdef which is useless in netipsec code
2007-02-18 13:55:25 +00:00
degroote
0a648e9c8b Remove __P
Remove useless extern
Use ansi declaration
2007-02-18 13:27:31 +00:00