Commit Graph

168 Commits

Author SHA1 Message Date
ozaki-r
6f13f59f2e Rename key_alloc* functions (NFC)
We shouldn't use the term "alloc" for functions that just look up
data and actually don't allocate memory.
2017-07-07 01:37:34 +00:00
ozaki-r
7ee151b4c2 Avoid updating sav directly
On SADB_UPDATE a target sav was updated directly, which was unsafe.
Instead allocate another sav, copy variables of the old sav to
the new one and replace the old one with the new one.
2017-07-06 09:48:42 +00:00
ozaki-r
cd0424f8e1 Fix usages of sadb_msg_errno 2017-07-06 09:04:26 +00:00
ozaki-r
c18aa5892a Introduce and use SADB_SASTATE_USABLE_P 2017-07-04 08:11:32 +00:00
ozaki-r
cd7b32deaa Do m_pullup before mtod
It may fix panicks of some tests on anita/sparc and anita/GuruPlug.
2017-06-10 14:21:01 +00:00
ozaki-r
401fa112b3 Tweak header file inclusions 2017-06-02 03:32:51 +00:00
ozaki-r
243e38c0a1 Change the prefix of function names of SADB API handlers to key_api_
By doing so we can easily distinguish them from other utility functions.
And so we can easily know that they are all called from key_parse and
applied assumptions that the arguments are always non-NULL and they
are always called from userland, i.e., never called from interrupt
context (softint). As a result, we can omit some tedious assertions
in the functions.
2017-06-02 01:22:50 +00:00
ozaki-r
ab52e45ac5 Simplify; we can assume the arguments are always non-NULL 2017-06-01 09:50:35 +00:00
ozaki-r
e59c7bb717 Return a return value of key_senderror as usual 2017-06-01 03:51:08 +00:00
ozaki-r
a64ab1c600 Split the timer handler into small functions (NFC) 2017-05-31 09:53:35 +00:00
ozaki-r
43dfc1c49f Introduce key_fill_replymsg to dedup some routines 2017-05-31 09:52:43 +00:00
ozaki-r
0e6cb2d26a Convert some sanity checks to CTASSERT 2017-05-31 09:51:31 +00:00
ozaki-r
61fae7fece Move key_init_spidx_bymsghdr to just before spidx is used (NFC) 2017-05-31 09:50:04 +00:00
ozaki-r
0cf335f02e Use key_getsah more (NFCI) 2017-05-31 05:05:38 +00:00
ozaki-r
4d3ffa7bab Avoid using variable newsp for an existing SP (NFC) 2017-05-31 04:02:44 +00:00
ozaki-r
0a401eb841 Simplify; assignment just works for spidx (NFC) 2017-05-31 04:02:05 +00:00
ozaki-r
fc3d449686 Sanity-check and return on error early
And delay initializing local variables until they're actually used.
2017-05-31 04:01:21 +00:00
ozaki-r
ee8d21398c Hide details of the sadb message format (NFCI)
Especially src0 + 1 and dst0 + 1 shouldn't be exposed.
2017-05-31 01:31:07 +00:00
ozaki-r
06cae45f66 Use key_senderror 2017-05-30 09:39:53 +00:00
ozaki-r
811e34fcaa Send up an error message on error as well as others 2017-05-30 09:39:08 +00:00
ozaki-r
90bba4b225 Make refcnt operations of SA and SP atomic
Using atomic opeartions isn't optimal and should be optimized somehow
in the future though, the change allows a kernel with NET_MPSAFE to
run out a benchmark, which is useful to know performance improvement
and degradation by code changes.
2017-05-30 01:31:07 +00:00
ozaki-r
63d0263345 Don't make isr->sav NULL
We assume it's always non-NULL.
2017-05-29 10:11:10 +00:00
mlelstv
48439a854c release key_mtx on return path. 2017-05-28 14:16:05 +00:00
ozaki-r
cafb33e1cd Replace "cmp" of function names to "match" and make their return value consistent
Function names with cmp are expected to return the order of two comparees
like memcmp and strcmp. The functions in question just answer if matched
or not, so don't use cmp and use match instead.

Consistently return 1 on matched and 0 otherwise.
2017-05-26 08:26:22 +00:00
ozaki-r
956d492de9 Make key_cmpspidx_exactly and key_cmpspidx_withmask static 2017-05-26 08:10:46 +00:00
ozaki-r
b27d2b947a Comment out unused key_freesp_so and key_freeso 2017-05-26 08:09:44 +00:00
ozaki-r
c216b3be17 Simplify; we can assume the arguments are always non-NULL 2017-05-26 08:00:15 +00:00
ozaki-r
7c276de754 Protect acqtree and regtree with a mutex (key_mtx)
The data structures aren't used in any performance-sensitive paths,
so just using a mutex to protect them is good enough.
2017-05-25 03:36:36 +00:00
ozaki-r
8db5286d3d Use __arraycount (NFC) 2017-05-23 09:08:45 +00:00
ozaki-r
18db854e5d Disable secspacq stuffs that are now unused
The stuffs are used only if sp->policy == IPSEC_POLICY_IPSEC
&& sp->req == NULL (see ipsec{4,6}_checkpolicy). However, in the
current implementation, sp->req never be NULL (except for the
moments of SP allocation and deallocation) if sp->policy is
IPSEC_POLICY_IPSEC.

It seems that the facility was partially implemented in the KAME
era and wasn't completed. Make it clear that the facility is
unused for now by #ifdef notyet. Eventually we should complete
the implementation or remove it entirely.
2017-05-23 04:26:08 +00:00
ozaki-r
cc005244cf Prepare to retire __LIST_CHAINED
We shouldn't relpy on the band-aid and instead use a lock or
refcnt to maintain chains properly. Before removing them,
replace conditionals with KASSERTs and see what will happen.
2017-05-23 03:13:52 +00:00
ozaki-r
7a6a3f1f25 KNF
And avoid calling a function, assigning a result to a variable, and
comparing it all together in one condition expression.
2017-05-22 04:40:23 +00:00
ozaki-r
cf5475457a Replace remaining DPRINTF with IPSECLOG 2017-05-22 04:23:55 +00:00
ozaki-r
9b4025812f Remove unnecessary MALLOC_DEFINE(M_SECA) 2017-05-19 06:32:31 +00:00
ozaki-r
fc8b563faf Use IPSECLOG instead of ipseclog 2017-05-19 06:24:03 +00:00
ozaki-r
74521c2a37 Use kmem_intr_free in key_freesaval which can be called in softint 2017-05-19 04:39:25 +00:00
ozaki-r
14fe74100b Replace malloc/free with kmem(9) and kill KMALLOC/KFREE macros 2017-05-17 02:19:09 +00:00
ozaki-r
86d681a1cc Fix memory leaks of allocated data to sav on key_update
key_setsaval NULL-clears member variables of sav at the beginning
of the function regardless of the states of the variables. When
key_setsaval is called by key_update, member variables sav->replay,
sav->key_* and sav->lft_* may have data allocated by malloc. In
that case they will leak. Free them before NULL-clear to avoid
memory leaks.
2017-05-17 02:04:55 +00:00
ozaki-r
6618f5ed62 Replace kmem_alloc + memset with kmem_zalloc
Suggested by kamil@
2017-05-16 10:11:24 +00:00
ozaki-r
db86b5ecbc Fix memory leaks of sah->idents and sah->identd
Originally fixed by the SEIL team of IIJ
2017-05-16 07:43:50 +00:00
ozaki-r
b5d03f6429 Fix diagnostic assertion failure in ipsec_init_policy
panic: kernel diagnostic assertion "!cpu_softintr_p()" failed: file "../../../../netipsec/ipsec.c", line 1277
  cpu7: Begin traceback...
  vpanic() at netbsd:vpanic+0x140
  ch_voltag_convert_in() at netbsd:ch_voltag_convert_in
  ipsec_init_policy() at netbsd:ipsec_init_policy+0x149
  in_pcballoc() at netbsd:in_pcballoc+0x1c5
  tcp_attach_wrapper() at netbsd:tcp_attach_wrapper+0x1e1
  sonewconn() at netbsd:sonewconn+0x1ea
  syn_cache_get() at netbsd:syn_cache_get+0x15f
  tcp_input() at netbsd:tcp_input+0x1689
  ipintr() at netbsd:ipintr+0xa88
  softint_dispatch() at netbsd:softint_dispatch+0xd3
  DDB lost frame for netbsd:Xsoftintr+0x4f, trying 0xfffffe811d337ff0
  Xsoftintr() at netbsd:Xsoftintr+0x4f

Reported by msaitoh@
2017-05-16 07:25:57 +00:00
ozaki-r
2044837295 Use kmem(9) instead of malloc/free
Some of non-sleepable allocations can be replaced with sleepable ones.
To make it clear that the replacements are possible, some assertions
are addded.
2017-05-16 03:05:28 +00:00
ozaki-r
07df88e0cd Run key_timehandler in thread context (workqueue)
The handler involves object deallocations so we want to not run
it in softint.
2017-05-16 02:59:22 +00:00
ozaki-r
21cadb654a Show __func__ instead of __FILE__ in debug log messages
__func__ is shorter and more useful than __FILE__.
2017-05-15 09:55:29 +00:00
ozaki-r
637b428df2 Fix a debug log message 2017-05-15 09:52:05 +00:00
ozaki-r
ed732a8ac2 Kill useless IPSEC_DEBUG2 (NFC) 2017-05-15 09:51:00 +00:00
ozaki-r
6ecd19b1e3 Fix kernel build with IPSEC 2017-05-09 05:38:50 +00:00
ozaki-r
9569f32e68 Add debugging facilities for refcnt of SA/SP 2017-05-09 04:20:11 +00:00
ozaki-r
fa05cc7c46 Provide foreach macros for SA states (NFCI) 2017-05-09 04:18:51 +00:00
ozaki-r
d9a74b87d3 Use LIST_* functions (NFC) 2017-05-09 04:17:13 +00:00