Commit Graph

642 Commits

Author SHA1 Message Date
maxv
2f7eef4b1d Remove dead code.
ok ozaki-r@
2018-04-16 17:32:34 +00:00
yamaguchi
c149db4f9c Added a lookup table to find an sav quickly
key_sad.sahlists doesn't work well for inbound packets because
its key includes source address. For the reason, the
look-up-table for the inbound packets is newly added.
The table has all sav whose state is MATURE or DYING and uses a
key calculated by destination address, protocol, and spi instead
of saidx.

reviewd ozaki-r@n.o, thanks.
2018-04-16 08:56:08 +00:00
yamaguchi
9e7eb12d9d Introduced a hash table to sahlist
An saidx of sah included in the list is unique so that
the search can use a hash list whose hash is calculated by
the saidx to find an sah quickly.
The hash list of the sahlits is used in FreeBSD, too.

reviewed by ozaki-r@n.o, thanks.
2018-04-16 08:52:09 +00:00
maxv
f75d3c0566 Introduce a m_verify_packet function, that verifies the mbuf chain of a
packet to ensure it is not malformed. Call this function in "points of
interest", that are the IPv4/IPv6/IPsec entry points. There could be more.

We use M_VERIFY_PACKET(m), declared under DIAGNOSTIC only.

This function should not be called everywhere, especially not in places
that temporarily manipulate (and clobber) the mbuf structure; once they're
done they put the mbuf back in a correct format.
2018-04-15 07:35:49 +00:00
maxv
10581564f8 Remove duplicate, to better show that this place doesn't make a lot of
sense. The code should probably be removed, it's a leftover from when we
had #ifdef __FreeBSD__.
2018-04-13 09:34:20 +00:00
yamaguchi
18cffba26c Removed the unnecessary order check of key_lookup_sa
key_prefered_oldsa flag can change the sa to use if an sah
has multiple sav. However the multiple saves whose protocol
is ah, esp, or tcp cannot exist because their duplications
are checked by the spi value. Although the multiple saves
can exist in the case of ipcomp, the values using in the
post processing are same between the saves.

For those reasons, it is no need to select an sav by its
lifetime.
In addition, FreeBSD has already remove this.

reviewed by ozaki-r@n.o, thanks.
2018-04-09 06:26:05 +00:00
knakahara
d83c566ff6 Fix unexpected failure when ipsecif(4) over IPv6 is changed port number only.
Here is an example of the operation which causes this problem.
    # ifconfig ipsec0 create link0
    # ifconfig ipsec0 tunnel fc00:1001::2,4500 fc00:1001::1,4501
    # ifconfig ipsec0 tunnel fc00:1001::2,4500 fc00:1001::1,4502
2018-04-06 10:38:53 +00:00
knakahara
7c378391ba Add IPv4 ID when the ipsecif(4) packet can be fragmented. Implemented by hsuenaga@IIJ and ohishi@IIJ, thanks.
This modification reduces packet loss of fragmented packets on a
network where reordering occurs.

Alghough this modification has been applied, IPv4 ID is not set for
the packet smaller then IP_MINFRAGSIZE. According to RFC 6864, that
must not cause problems.

XXX pullup-8
2018-04-06 10:31:35 +00:00
maxv
d40270d9c9 Remove ipsec_copy_policy and ipsec_copy_pcbpolicy. No functional change,
since we used only ipsec_copy_pcbpolicy, and it was a no-op.

Originally we were using ipsec_copy_policy to optimize the IPsec-PCB
cache: when an ACK was received in response to a SYN, we used to copy the
SP cached in the SYN's PCB into the ACK's PCB, so that
ipsec_getpolicybysock could use the cached SP instead of requerying it.

Then we switched to ipsec_copy_pcbpolicy which has always been a no-op. As
a result the SP cached in the SYN was/is not copied in the ACK, and the
first call to ipsec_getpolicybysock had to query the SP and cache it
itself. It's not totally clear to me why this change was made.

But it has been this way for years, and after a conversation with Ryota
Ozaki it turns out the optimization is not valid anymore due to
MP-ification, so it won't be re-enabled.

ok ozaki-r@
2018-04-03 09:03:59 +00:00
maxv
65b46b60ed typo in comments 2018-03-31 19:27:14 +00:00
roy
320ba6e2bf socket: report receive buffer overflows
Add soroverflow() which increments the overflow counter, sets so_error
to ENOBUFS and wakes the receive socket up.
Replace all code that manually increments this counter with soroverflow().
Add soroverflow() to raw_input().

This allows userland to detect route(4) overflows so it can re-sync
with the current state.
2018-03-19 16:26:25 +00:00
knakahara
e7acdb682b comment out confusing (and incorrect) code and add comment. Pointed out by maxv@n.o, thanks. 2018-03-13 03:05:12 +00:00
maxv
7ddcc8beaa Add KASSERTs. 2018-03-10 17:52:50 +00:00
maxv
00c01d2fd1 Fix the computation. Normally that's harmless since ip6_output recomputes
ip6_plen.
2018-03-10 17:48:32 +00:00
knakahara
400c191493 Fix ipsec(4) I/F esp_frag support. 2018-03-09 11:05:21 +00:00
knakahara
4fda12c619 Fix fragment processing in ipsec4_fragout(). Pointed out by maxv@n.o, thanks.
XXX need pullup-8
2018-03-06 10:07:06 +00:00
maxv
f2110e8589 Improve stupid check, style, and fix leak (m, not m0). 2018-03-05 12:42:28 +00:00
maxv
052a8431bf Call m_pullup earlier, fixes one branch. 2018-03-05 11:50:25 +00:00
maxv
52489f2bdd Reduce the diff between ipsec4_output and ipsec6_check_policy. While here
style.
2018-03-03 09:54:55 +00:00
maxv
d219e3b4ad Dedup. 2018-03-03 09:47:01 +00:00
maxv
6c5d24ed60 Add KASSERTs, we don't want m_nextpkt in ipsec{4/6}_process_packet. 2018-03-03 09:39:29 +00:00
ozaki-r
c17f87d4e1 Avoid data races on lifetime counters by using percpu(9)
We don't make them percpu(9) directly because the structure is exposed to
userland and we don't want to break ABI.  So we add another member variable
for percpu(9) and use it internally.  When we export them to userland, they
are converted to the original format.
2018-03-02 07:37:13 +00:00
maxv
f3215192fd add missing static 2018-02-28 11:29:14 +00:00
maxv
d81439a881 Remove unused macros, and while here style. 2018-02-28 11:19:49 +00:00
maxv
e9a0140794 Remove duplicate IPSEC_STATINC(IPSEC_STAT_IN_POLVIO), ipsec_in_reject
already increases it. IPSEC6_STATINC is now unused, so remove it too.
2018-02-28 11:09:03 +00:00
maxv
247966d592 Dedup: merge ipsec4_setspidx_inpcb and ipsec6_setspidx_in6pcb. 2018-02-28 10:16:19 +00:00
maxv
f931621816 ipsec6_setspidx_in6pcb: call ipsec_setspidx() only once, just like the
IPv4 code. While here put the correct variable in sizeof.

ok ozaki-r@
2018-02-28 10:09:17 +00:00
maxv
faad9849ec Dedup: merge ipsec4_set_policy and ipsec6_set_policy. The content of the
original ipsec_set_policy function is inlined into the new one.
2018-02-27 15:01:30 +00:00
maxv
6fd7a9a762 Remove duplicate checks, and no need to initialize 'newsp' in
ipsec_set_policy.
2018-02-27 14:52:51 +00:00
maxv
580ac4be42 Dedup: merge
ipsec4_get_policy and ipsec6_get_policy
	ipsec4_delete_pcbpolicy and ipsec6_delete_pcbpolicy

The already-existing ipsec_get_policy() function is inlined in the new
one.
2018-02-27 14:44:10 +00:00
maxv
be32dea43c Use inpcb_hdr to reduce the diff between
ipsec4_set_policy and ipsec6_set_policy
	ipsec4_get_policy and ipsec6_get_policy
	ipsec4_delete_pcbpolicy and ipsec6_delete_pcbpolicy

No real functional change.
2018-02-27 13:36:21 +00:00
maxv
215e1b4181 Optimize: use ipsec_sp_hdrsiz instead of ipsec_hdrsiz, not to re-query
the SP.

ok ozaki-r@
2018-02-27 08:05:19 +00:00
maxv
0695fe90b1 Dedup: call ipsec_in_reject directly. IPSEC_STAT_IN_POLVIO also gets
increased now.
2018-02-26 10:36:24 +00:00
maxv
768c43840b Reduce the diff between ipsec6_input and ipsec4_input. 2018-02-26 10:19:13 +00:00
maxv
b39a0dd1f8 Dedup: merge ipsec4_in_reject and ipsec6_in_reject into ipsec_in_reject.
While here fix misleading comment.

ok ozaki-r@
2018-02-26 09:04:29 +00:00
maxv
c3c5f13028 Dedup: merge ipsec4_hdrsiz and ipsec6_hdrsiz into ipsec_hdrsiz.
ok ozaki-r@
2018-02-26 08:50:25 +00:00
maxv
2953bb2565 Dedup: merge ipsec4_checkpolicy and ipsec6_checkpolicy into
ipsec_checkpolicy.

ok ozaki-r@
2018-02-26 08:42:16 +00:00
maxv
0f3ae0526d If 'skip' is lower than sizeof(struct ip), we are in trouble. So remove a
nonsensical branch, and add a panic at the beginning of the function.
2018-02-26 06:58:56 +00:00
maxv
1d337420b7 m is never allowed to be NULL, so turn the KASSERT (and the null check)
to a panic.
2018-02-26 06:53:22 +00:00
maxv
8a440faae1 Fix nonsensical checks, neither in6p nor request is allowed to be NULL,
and the former is already dereferenced in a kassert. This code should be
the same as ipsec4_set_policy.
2018-02-26 06:48:01 +00:00
maxv
3e1c4ac085 Add XXX, it seems to me we need to free the mbuf here. 2018-02-26 06:41:27 +00:00
maxv
20ee129912 Reinforce this area, make sure the length field fits the option. Normally
it always does because the options were already sanitized earlier.
2018-02-26 06:40:08 +00:00
maxv
589f503d3d Fix mbuf mistake: we are using ip6 before it is pulled up properly. 2018-02-26 06:34:39 +00:00
maxv
16a6b57077 Merge some minor (mostly stylistic) changes from last week. 2018-02-26 06:17:01 +00:00
maxv
790020449d Style, no functional change. 2018-02-21 17:04:52 +00:00
maxv
2256f36f66 Strengthen this check, to make sure there is room for an ip6_ext structure.
Seems possible to crash m_copydata here (but I didn't test more than that).
2018-02-21 16:55:53 +00:00
maxv
8084c6496d Argh, in my previous commit in this file I forgot to fix the IPv6
entry point; apply the same fix there.
2018-02-21 16:48:28 +00:00
maxv
b9badffce8 Fix ipsec4_get_ulp(). We should do "goto done" instead of "return",
otherwise the port fields of spidx are uninitialized.

ok mlelstv@
2018-02-21 16:42:33 +00:00
maxv
8df55a522b Use inpcb_hdr to reduce the diff between:
ipsec4_hdrsiz      and ipsec6_hdrsiz
	ipsec4_in_reject   and ipsec6_in_reject
	ipsec4_checkpolicy and ipsec4_checkpolicy

The members of these couples are now identical, and could be merged,
giving only three functions instead of six...
2018-02-21 16:38:15 +00:00
maxv
af69f63988 Rename:
ipsec_in_reject -> ipsec_sp_reject
	ipsec_hdrsiz    -> ipsec_sp_hdrsiz

localify the former, and do some cleanup while here.
2018-02-21 16:18:52 +00:00