Commit Graph

228 Commits

Author SHA1 Message Date
plunky 7f3d4048d7 NULL does not need a cast 2011-08-31 18:31:02 +00:00
joerg 3eb244d801 Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
2011-07-17 20:54:30 +00:00
drochner 813bea3edb catch a case where an ip6 address with scope embedded was compared with
one without -- interestingly this didn't break the connection but just
caused a useless encapsulation
(this code needs to be rearranged to get it clean)
2011-06-09 21:04:37 +00:00
drochner 2cd69bbbad more "const" 2011-06-09 19:54:18 +00:00
dyoung b6aa79a388 Fiddle a bit with const's to make FAST_IPSEC compile. 2011-06-08 16:24:50 +00:00
drochner e4ef78d839 fix tunnel encapsulation in ipsec6_process_packet() -- it is not
completely clean yet, but at least a v6-in-v6 tunnel works now
2011-06-07 15:54:57 +00:00
drochner 7038ebdf09 reindent ipsec6_process_packet() - whitespace changes only 2011-06-07 15:50:42 +00:00
drochner a46f4db6fd remove a limitation that inner and outer IP version must be equal
for an ESP tunnel, and add some fixes which make v4-in-v6 work
(v6 as inner protocol isn't ready, even v6-in-v6 can never have worked)

being here, fix a statistics counter and kill an unused variable
2011-06-06 16:48:35 +00:00
christos 940f19b42b more malloc style. 2011-06-05 01:45:37 +00:00
christos dd8772617a - sprinkle const
- malloc style
2011-06-05 01:40:40 +00:00
drochner 0a8dabda40 pull in AES-GCM/GMAC support from OpenBSD
This is still somewhat experimental. Tested between 2 similar boxes
so far. There is much potential for performance improvement. For now,
I've changed the gmac code to accept any data alignment, as the "char *"
pointer suggests. As the code is practically used, 32-bit alignment
can be assumed, at the cost of data copies. I don't know whether
bytewise access or copies are worse performance-wise. For efficient
implementations using SSE2 instructions on x86, even stricter
alignment requirements might arise.
2011-05-26 21:50:02 +00:00
drochner ebc232a582 copy AES-XCBC-MAC support from KAME IPSEC to FAST_IPSEC
For this to fit, an API change in cryptosoft was adopted from OpenBSD
(addition of a "Setkey" method to hashes) which was done for GCM/GMAC
support there, so it might be useful in the future anyway.
tested against KAME IPSEC
AFAICT, FAST_IPSEC now supports as much as KAME.
2011-05-24 19:10:08 +00:00
drochner fe35ba177e g/c remainders of IV handling in pfkey code -- this is done in
opencrypto now
2011-05-23 15:17:25 +00:00
drochner 22a8d55c40 allow ESP to use AES-CTR
(pfkey and userland tool support is already there because it has been
in KAME IPSEC all the time)
tested against KAME IPSEC
2011-05-23 13:57:52 +00:00
drochner 5fafa9c424 -in the descriptor for encryption xforms, split the "blocksize" field
into "blocksize" and "IV size"
-add an "reinit" function pointer which, if set, means that the xform
 does its IV handling itself and doesn't want the default CBC handling
 by the framework (poor name, but left that way to avoid unecessary
 differences)
This syncs with Open/FreeBSD, purpose is to allow non-CBC transforms.
Refer to ivsize instead of blocksize where appropriate.
(At this point, blocksize and ivsize are identical.)
2011-05-23 13:46:54 +00:00
drochner 582edd8b2a include the SHA2 hashs into the proposal which goes out with
SADB_ACQUIRE -- this doesn't change much because racoon ignores
the proposal from the kernel anyway and applies its own configuration,
but having MD5 and SHA1 in the list but SHA2 not looks strange
2011-05-18 18:56:02 +00:00
drochner 184e1b20e6 use monotonic time rather than wall time for lifetime related timestamps,
to make key expiration robust against time changes
2011-05-18 18:36:15 +00:00
drochner 8ec435e6ba cleanup some error handling to avoid memory leaks and doube frees,
from Wolfgang Stukenbrock per PR kern/44948, and part of kern/44952
2011-05-17 18:57:02 +00:00
drochner d1cd4a3eb4 fix lookup of SAs for outgoing packets in the !prefered_oldsa case,
as done in KAME and FAST_IPSEC after NetBSD imported the code
(The default differs: KAME uses the oldest valid SA while FAST_IPSEC
in NetBSD uses the newest one. I'm not changing this -- there is a lack
of specification and behavior can be changed with the "oldsa" sysctl.)
For incoming packets it shouldn't matter but I made it look similar
just to avoid unnecessary differences.
2011-05-17 18:43:02 +00:00
drochner 1234118091 remove redundant declaration 2011-05-16 10:05:23 +00:00
drochner 7c0f80c6a5 remove a useless m_freem() call where the argument is known to be NULL 2011-05-16 10:04:02 +00:00
drochner 06d326df43 use time_t rather than long for timestamps 2011-05-16 10:02:30 +00:00
drochner 48841b961c cosmetical whitespace changes 2011-05-16 10:00:32 +00:00
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