2000-07-04 16:35:15 +00:00
|
|
|
/* $FreeBSD$ */
|
2004-01-13 05:39:07 +00:00
|
|
|
/* $KAME: ipsec.c,v 1.207 2004/01/13 03:30:42 itojun Exp $ */
|
2000-07-04 16:35:15 +00:00
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPsec controller part.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
|
|
|
#include "opt_ipsec.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/udp.h>
|
|
|
|
#include <netinet/udp_var.h>
|
|
|
|
#include <netinet/ip_ecn.h>
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet6/ip6_ecn.h>
|
|
|
|
#endif
|
2001-06-11 12:39:29 +00:00
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <netinet/udp.h>
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet/ip6.h>
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef INET6
|
1999-12-22 19:13:38 +00:00
|
|
|
#include <netinet6/ip6_var.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#endif
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet/icmp6.h>
|
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
#include <netinet6/ipsec.h>
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet6/ipsec6.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#endif
|
|
|
|
#include <netinet6/ah.h>
|
|
|
|
#ifdef INET6
|
1999-12-22 19:13:38 +00:00
|
|
|
#include <netinet6/ah6.h>
|
|
|
|
#endif
|
|
|
|
#ifdef IPSEC_ESP
|
|
|
|
#include <netinet6/esp.h>
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet6/esp6.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet6/ipcomp.h>
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet6/ipcomp6.h>
|
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
#include <netkey/key.h>
|
|
|
|
#include <netkey/keydb.h>
|
|
|
|
#include <netkey/key_debug.h>
|
|
|
|
|
2000-05-09 16:56:51 +00:00
|
|
|
#include <machine/in_cksum.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <net/net_osdep.h>
|
|
|
|
|
|
|
|
#ifdef IPSEC_DEBUG
|
|
|
|
int ipsec_debug = 1;
|
|
|
|
#else
|
|
|
|
int ipsec_debug = 0;
|
|
|
|
#endif
|
|
|
|
|
2004-08-28 15:24:53 +00:00
|
|
|
NET_NEEDS_GIANT("ipsec");
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
struct ipsecstat ipsecstat;
|
|
|
|
int ip4_ah_cleartos = 1;
|
|
|
|
int ip4_ah_offsetmask = 0; /* maybe IP_DF? */
|
|
|
|
int ip4_ipsec_dfbit = 0; /* DF bit on encap. 0: clear 1: set 2: copy */
|
|
|
|
int ip4_esp_trans_deflev = IPSEC_LEVEL_USE;
|
|
|
|
int ip4_esp_net_deflev = IPSEC_LEVEL_USE;
|
|
|
|
int ip4_ah_trans_deflev = IPSEC_LEVEL_USE;
|
|
|
|
int ip4_ah_net_deflev = IPSEC_LEVEL_USE;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct secpolicy *ip4_def_policy;
|
1999-12-22 19:13:38 +00:00
|
|
|
int ip4_ipsec_ecn = 0; /* ECN ignore(-1)/forbidden(0)/allowed(1) */
|
2001-06-11 12:39:29 +00:00
|
|
|
int ip4_esp_randpad = -1;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
static int sp_cachegen = 1; /* cache generation # */
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
SYSCTL_DECL(_net_inet_ipsec);
|
|
|
|
#ifdef INET6
|
|
|
|
SYSCTL_DECL(_net_inet6_ipsec6);
|
|
|
|
#endif
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
/* net.inet.ipsec */
|
|
|
|
SYSCTL_STRUCT(_net_inet_ipsec, IPSECCTL_STATS,
|
|
|
|
stats, CTLFLAG_RD, &ipsecstat, ipsecstat, "");
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#if 0
|
1999-12-22 19:13:38 +00:00
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_POLICY,
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
def_policy, CTLFLAG_RW, &ip4_def_policy->policy, 0, "");
|
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_ESP_TRANSLEV, esp_trans_deflev,
|
|
|
|
CTLFLAG_RW, &ip4_esp_trans_deflev, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_ESP_NETLEV, esp_net_deflev,
|
|
|
|
CTLFLAG_RW, &ip4_esp_net_deflev, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_AH_TRANSLEV, ah_trans_deflev,
|
|
|
|
CTLFLAG_RW, &ip4_ah_trans_deflev, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEF_AH_NETLEV, ah_net_deflev,
|
|
|
|
CTLFLAG_RW, &ip4_ah_net_deflev, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_AH_CLEARTOS,
|
|
|
|
ah_cleartos, CTLFLAG_RW, &ip4_ah_cleartos, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_AH_OFFSETMASK,
|
|
|
|
ah_offsetmask, CTLFLAG_RW, &ip4_ah_offsetmask, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DFBIT,
|
|
|
|
dfbit, CTLFLAG_RW, &ip4_ipsec_dfbit, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_ECN,
|
|
|
|
ecn, CTLFLAG_RW, &ip4_ipsec_ecn, 0, "");
|
2000-07-04 16:35:15 +00:00
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_DEBUG,
|
|
|
|
debug, CTLFLAG_RW, &ipsec_debug, 0, "");
|
2001-06-11 12:39:29 +00:00
|
|
|
SYSCTL_INT(_net_inet_ipsec, IPSECCTL_ESP_RANDPAD,
|
|
|
|
esp_randpad, CTLFLAG_RW, &ip4_esp_randpad, 0, "");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
struct ipsecstat ipsec6stat;
|
|
|
|
int ip6_esp_trans_deflev = IPSEC_LEVEL_USE;
|
|
|
|
int ip6_esp_net_deflev = IPSEC_LEVEL_USE;
|
|
|
|
int ip6_ah_trans_deflev = IPSEC_LEVEL_USE;
|
|
|
|
int ip6_ah_net_deflev = IPSEC_LEVEL_USE;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct secpolicy *ip6_def_policy;
|
1999-12-22 19:13:38 +00:00
|
|
|
int ip6_ipsec_ecn = 0; /* ECN ignore(-1)/forbidden(0)/allowed(1) */
|
2001-06-11 12:39:29 +00:00
|
|
|
int ip6_esp_randpad = -1;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* net.inet6.ipsec6 */
|
|
|
|
SYSCTL_STRUCT(_net_inet6_ipsec6, IPSECCTL_STATS,
|
|
|
|
stats, CTLFLAG_RD, &ipsec6stat, ipsecstat, "");
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#if 0
|
1999-12-22 19:13:38 +00:00
|
|
|
SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_POLICY,
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
def_policy, CTLFLAG_RW, &ip6_def_policy->policy, 0, "");
|
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_ESP_TRANSLEV, esp_trans_deflev,
|
|
|
|
CTLFLAG_RW, &ip6_esp_trans_deflev, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_ESP_NETLEV, esp_net_deflev,
|
|
|
|
CTLFLAG_RW, &ip6_esp_net_deflev, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_AH_TRANSLEV, ah_trans_deflev,
|
|
|
|
CTLFLAG_RW, &ip6_ah_trans_deflev, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEF_AH_NETLEV, ah_net_deflev,
|
|
|
|
CTLFLAG_RW, &ip6_ah_net_deflev, 0, "");
|
|
|
|
SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_ECN,
|
|
|
|
ecn, CTLFLAG_RW, &ip6_ipsec_ecn, 0, "");
|
2000-07-04 16:35:15 +00:00
|
|
|
SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_DEBUG,
|
|
|
|
debug, CTLFLAG_RW, &ipsec_debug, 0, "");
|
2001-06-11 12:39:29 +00:00
|
|
|
SYSCTL_INT(_net_inet6_ipsec6, IPSECCTL_ESP_RANDPAD,
|
|
|
|
esp_randpad, CTLFLAG_RW, &ip6_esp_randpad, 0, "");
|
1999-12-22 19:13:38 +00:00
|
|
|
#endif /* INET6 */
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
static struct secpolicy *ipsec_checkpcbcache __P((struct mbuf *,
|
|
|
|
struct inpcbpolicy *, int));
|
|
|
|
static int ipsec_fillpcbcache __P((struct inpcbpolicy *, struct mbuf *,
|
|
|
|
struct secpolicy *, int));
|
|
|
|
static int ipsec_invalpcbcache __P((struct inpcbpolicy *, int));
|
1999-12-22 19:13:38 +00:00
|
|
|
static int ipsec_setspidx_mbuf
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
__P((struct secpolicyindex *, int, struct mbuf *, int));
|
2001-06-11 12:39:29 +00:00
|
|
|
static int ipsec_setspidx __P((struct mbuf *, struct secpolicyindex *, int));
|
2003-10-08 18:26:08 +00:00
|
|
|
static void ipsec4_get_ulp __P((struct mbuf *, struct secpolicyindex *, int));
|
2001-06-11 12:39:29 +00:00
|
|
|
static int ipsec4_setspidx_ipaddr __P((struct mbuf *, struct secpolicyindex *));
|
1999-12-22 19:13:38 +00:00
|
|
|
#ifdef INET6
|
2003-10-08 18:26:08 +00:00
|
|
|
static void ipsec6_get_ulp __P((struct mbuf *, struct secpolicyindex *, int));
|
2001-06-11 12:39:29 +00:00
|
|
|
static int ipsec6_setspidx_ipaddr __P((struct mbuf *, struct secpolicyindex *));
|
1999-12-22 19:13:38 +00:00
|
|
|
#endif
|
2000-07-04 16:35:15 +00:00
|
|
|
static struct inpcbpolicy *ipsec_newpcbpolicy __P((void));
|
|
|
|
static void ipsec_delpcbpolicy __P((struct inpcbpolicy *));
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#if 0
|
|
|
|
static int ipsec_deepcopy_pcbpolicy __P((struct inpcbpolicy *));
|
|
|
|
#endif
|
2003-10-08 18:26:08 +00:00
|
|
|
static struct secpolicy *ipsec_deepcopy_policy __P((struct secpolicy *));
|
|
|
|
static int ipsec_set_policy
|
|
|
|
__P((struct secpolicy **, int, caddr_t, size_t, int));
|
|
|
|
static int ipsec_get_policy __P((struct secpolicy *, struct mbuf **));
|
1999-12-22 19:13:38 +00:00
|
|
|
static void vshiftl __P((unsigned char *, int, int));
|
|
|
|
static int ipsec_in_reject __P((struct secpolicy *, struct mbuf *));
|
|
|
|
static size_t ipsec_hdrsiz __P((struct secpolicy *));
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef INET
|
1999-12-22 19:13:38 +00:00
|
|
|
static struct mbuf *ipsec4_splithdr __P((struct mbuf *));
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
#ifdef INET6
|
|
|
|
static struct mbuf *ipsec6_splithdr __P((struct mbuf *));
|
|
|
|
#endif
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef INET
|
1999-12-22 19:13:38 +00:00
|
|
|
static int ipsec4_encapsulate __P((struct mbuf *, struct secasvar *));
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
#ifdef INET6
|
|
|
|
static int ipsec6_encapsulate __P((struct mbuf *, struct secasvar *));
|
|
|
|
#endif
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
static struct ipsecaux *ipsec_addaux __P((struct mbuf *));
|
|
|
|
static struct ipsecaux *ipsec_findaux __P((struct mbuf *));
|
|
|
|
static void ipsec_optaux __P((struct mbuf *, struct ipsecaux *));
|
|
|
|
#ifdef INET
|
|
|
|
static int ipsec4_checksa __P((struct ipsecrequest *,
|
|
|
|
struct ipsec_output_state *));
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
static int ipsec6_checksa __P((struct ipsecrequest *,
|
|
|
|
struct ipsec_output_state *, int));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* try to validate and use cached policy on a pcb.
|
|
|
|
*/
|
|
|
|
static struct secpolicy *
|
|
|
|
ipsec_checkpcbcache(m, pcbsp, dir)
|
|
|
|
struct mbuf *m;
|
|
|
|
struct inpcbpolicy *pcbsp;
|
|
|
|
int dir;
|
|
|
|
{
|
|
|
|
struct secpolicyindex spidx;
|
|
|
|
struct timeval mono_time;
|
|
|
|
|
|
|
|
microtime(&mono_time);
|
|
|
|
|
|
|
|
switch (dir) {
|
|
|
|
case IPSEC_DIR_INBOUND:
|
|
|
|
case IPSEC_DIR_OUTBOUND:
|
|
|
|
case IPSEC_DIR_ANY:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (dir >= sizeof(pcbsp->cache)/sizeof(pcbsp->cache[0]))
|
|
|
|
panic("dir too big in ipsec_checkpcbcache");
|
|
|
|
#endif
|
|
|
|
/* SPD table change invalidates all the caches */
|
|
|
|
if (pcbsp->cachegen[dir] == 0 || sp_cachegen > pcbsp->cachegen[dir]) {
|
|
|
|
ipsec_invalpcbcache(pcbsp, dir);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!pcbsp->cache[dir])
|
|
|
|
return NULL;
|
|
|
|
if (pcbsp->cache[dir]->state != IPSEC_SPSTATE_ALIVE) {
|
|
|
|
ipsec_invalpcbcache(pcbsp, dir);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if ((pcbsp->cacheflags & IPSEC_PCBSP_CONNECTED) == 0) {
|
|
|
|
if (!pcbsp->cache[dir])
|
|
|
|
return NULL;
|
|
|
|
if (ipsec_setspidx(m, &spidx, 1) != 0)
|
|
|
|
return NULL;
|
|
|
|
if (bcmp(&pcbsp->cacheidx[dir], &spidx, sizeof(spidx))) {
|
|
|
|
if (!pcbsp->cache[dir]->spidx ||
|
|
|
|
!key_cmpspidx_withmask(pcbsp->cache[dir]->spidx,
|
|
|
|
&spidx))
|
|
|
|
return NULL;
|
|
|
|
pcbsp->cacheidx[dir] = spidx;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The pcb is connected, and the L4 code is sure that:
|
|
|
|
* - outgoing side uses inp_[lf]addr
|
|
|
|
* - incoming side looks up policy after inpcb lookup
|
|
|
|
* and address pair is known to be stable. We do not need
|
|
|
|
* to generate spidx again, nor check the address match again.
|
|
|
|
*
|
|
|
|
* For IPv4/v6 SOCK_STREAM sockets, this assumption holds
|
|
|
|
* and there are calls to ipsec_pcbconn() from in_pcbconnect().
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
pcbsp->cache[dir]->lastused = mono_time.tv_sec;
|
|
|
|
pcbsp->cache[dir]->refcnt++;
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
|
|
|
printf("DP ipsec_checkpcbcache cause refcnt++:%d SP:%p\n",
|
|
|
|
pcbsp->cache[dir]->refcnt, pcbsp->cache[dir]));
|
|
|
|
return pcbsp->cache[dir];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ipsec_fillpcbcache(pcbsp, m, sp, dir)
|
|
|
|
struct inpcbpolicy *pcbsp;
|
|
|
|
struct mbuf *m;
|
|
|
|
struct secpolicy *sp;
|
|
|
|
int dir;
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (dir) {
|
|
|
|
case IPSEC_DIR_INBOUND:
|
|
|
|
case IPSEC_DIR_OUTBOUND:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (dir >= sizeof(pcbsp->cache)/sizeof(pcbsp->cache[0]))
|
|
|
|
panic("dir too big in ipsec_checkpcbcache");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pcbsp->cache[dir])
|
|
|
|
key_freesp(pcbsp->cache[dir]);
|
|
|
|
pcbsp->cache[dir] = NULL;
|
|
|
|
if (ipsec_setspidx(m, &pcbsp->cacheidx[dir], 1) != 0) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
pcbsp->cache[dir] = sp;
|
|
|
|
if (pcbsp->cache[dir]) {
|
|
|
|
pcbsp->cache[dir]->refcnt++;
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
|
|
|
printf("DP ipsec_fillpcbcache cause refcnt++:%d SP:%p\n",
|
|
|
|
pcbsp->cache[dir]->refcnt, pcbsp->cache[dir]));
|
|
|
|
}
|
|
|
|
pcbsp->cachegen[dir] = sp_cachegen;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ipsec_invalpcbcache(pcbsp, dir)
|
|
|
|
struct inpcbpolicy *pcbsp;
|
|
|
|
int dir;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = IPSEC_DIR_INBOUND; i <= IPSEC_DIR_OUTBOUND; i++) {
|
|
|
|
if (dir != IPSEC_DIR_ANY && i != dir)
|
|
|
|
continue;
|
|
|
|
if (pcbsp->cache[i])
|
|
|
|
key_freesp(pcbsp->cache[i]);
|
|
|
|
pcbsp->cache[i] = NULL;
|
|
|
|
pcbsp->cachegen[i] = 0;
|
|
|
|
bzero(&pcbsp->cacheidx[i], sizeof(pcbsp->cacheidx[i]));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ipsec_pcbconn(pcbsp)
|
|
|
|
struct inpcbpolicy *pcbsp;
|
|
|
|
{
|
|
|
|
|
|
|
|
pcbsp->cacheflags |= IPSEC_PCBSP_CONNECTED;
|
|
|
|
ipsec_invalpcbcache(pcbsp, IPSEC_DIR_ANY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ipsec_pcbdisconn(pcbsp)
|
|
|
|
struct inpcbpolicy *pcbsp;
|
|
|
|
{
|
|
|
|
|
|
|
|
pcbsp->cacheflags &= ~IPSEC_PCBSP_CONNECTED;
|
|
|
|
ipsec_invalpcbcache(pcbsp, IPSEC_DIR_ANY);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ipsec_invalpcbcacheall()
|
|
|
|
{
|
|
|
|
|
|
|
|
sp_cachegen++;
|
|
|
|
return 0;
|
|
|
|
}
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For OUTBOUND packet having a socket. Searching SPD for packet,
|
|
|
|
* and return a pointer to SP.
|
|
|
|
* OUT: NULL: no apropreate SP found, the following value is set to error.
|
|
|
|
* 0 : bypass
|
|
|
|
* EACCES : discard packet.
|
|
|
|
* ENOENT : ipsec_acquire() in progress, maybe.
|
|
|
|
* others : error occured.
|
|
|
|
* others: a pointer to SP
|
|
|
|
*
|
|
|
|
* NOTE: IPv6 mapped adddress concern is implemented here.
|
|
|
|
*/
|
|
|
|
struct secpolicy *
|
2004-02-03 18:20:55 +00:00
|
|
|
ipsec4_getpolicybypcb(m, dir, inp, error)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
u_int dir;
|
2004-02-03 18:20:55 +00:00
|
|
|
struct inpcb *inp;
|
1999-12-22 19:13:38 +00:00
|
|
|
int *error;
|
|
|
|
{
|
|
|
|
struct inpcbpolicy *pcbsp = NULL;
|
|
|
|
struct secpolicy *currsp = NULL; /* policy on socket */
|
|
|
|
struct secpolicy *kernsp = NULL; /* policy on kernel */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct secpolicyindex spidx;
|
|
|
|
u_int16_t tag;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
2004-02-03 18:20:55 +00:00
|
|
|
if (m == NULL || inp == NULL || error == NULL)
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec4_getpolicybypcb: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2004-02-03 18:20:55 +00:00
|
|
|
pcbsp = inp->inp_sp;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
1999-12-22 19:13:38 +00:00
|
|
|
if (pcbsp == NULL)
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec4_getpolicybypcb: pcbsp is NULL.");
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
tag = 0;
|
|
|
|
|
|
|
|
/* if we have a cached entry, and if it is still valid, use it. */
|
|
|
|
ipsecstat.spdcachelookup++;
|
|
|
|
currsp = ipsec_checkpcbcache(m, pcbsp, dir);
|
|
|
|
if (currsp) {
|
|
|
|
*error = 0;
|
|
|
|
return currsp;
|
|
|
|
}
|
|
|
|
ipsecstat.spdcachemiss++;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
switch (dir) {
|
|
|
|
case IPSEC_DIR_INBOUND:
|
|
|
|
currsp = pcbsp->sp_in;
|
|
|
|
break;
|
|
|
|
case IPSEC_DIR_OUTBOUND:
|
|
|
|
currsp = pcbsp->sp_out;
|
|
|
|
break;
|
|
|
|
default:
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec4_getpolicybypcb: illegal direction.");
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (currsp == NULL)
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec4_getpolicybypcb: currsp is NULL.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2004-01-13 05:39:07 +00:00
|
|
|
/* when privileged socket */
|
1999-12-22 19:13:38 +00:00
|
|
|
if (pcbsp->priv) {
|
|
|
|
switch (currsp->policy) {
|
|
|
|
case IPSEC_POLICY_BYPASS:
|
|
|
|
currsp->refcnt++;
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, currsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return currsp;
|
|
|
|
|
|
|
|
case IPSEC_POLICY_ENTRUST:
|
|
|
|
/* look for a policy in SPD */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (ipsec_setspidx_mbuf(&spidx, AF_INET, m, 1) == 0 &&
|
|
|
|
(kernsp = key_allocsp(tag, &spidx, dir)) != NULL) {
|
|
|
|
/* SP found */
|
1999-12-22 19:13:38 +00:00
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
2004-02-16 18:07:53 +00:00
|
|
|
printf("DP ipsec4_getpolicybypcb called "
|
1999-12-22 19:13:38 +00:00
|
|
|
"to allocate SP:%p\n", kernsp));
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, kernsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return kernsp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no SP found */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ip4_def_policy->refcnt++;
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, ip4_def_policy, dir);
|
|
|
|
return ip4_def_policy;
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
case IPSEC_POLICY_IPSEC:
|
|
|
|
currsp->refcnt++;
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, currsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return currsp;
|
|
|
|
|
|
|
|
default:
|
2004-02-16 18:07:53 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec4_getpolicybypcb: "
|
2000-07-04 16:35:15 +00:00
|
|
|
"Invalid policy for PCB %d\n", currsp->policy));
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2004-01-13 05:39:07 +00:00
|
|
|
/* when non-privileged socket */
|
1999-12-22 19:13:38 +00:00
|
|
|
/* look for a policy in SPD */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (ipsec_setspidx_mbuf(&spidx, AF_INET, m, 1) == 0 &&
|
|
|
|
(kernsp = key_allocsp(tag, &spidx, dir)) != NULL) {
|
|
|
|
/* SP found */
|
1999-12-22 19:13:38 +00:00
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
2004-02-16 18:07:53 +00:00
|
|
|
printf("DP ipsec4_getpolicybypcb called "
|
1999-12-22 19:13:38 +00:00
|
|
|
"to allocate SP:%p\n", kernsp));
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, kernsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return kernsp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no SP found */
|
|
|
|
switch (currsp->policy) {
|
|
|
|
case IPSEC_POLICY_BYPASS:
|
2004-02-16 18:07:53 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec4_getpolicybypcb: "
|
2004-01-13 05:39:07 +00:00
|
|
|
"Illegal policy for non-privileged defined %d\n",
|
2000-07-04 16:35:15 +00:00
|
|
|
currsp->policy));
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case IPSEC_POLICY_ENTRUST:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ip4_def_policy->refcnt++;
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, ip4_def_policy, dir);
|
|
|
|
return ip4_def_policy;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
case IPSEC_POLICY_IPSEC:
|
|
|
|
currsp->refcnt++;
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, currsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return currsp;
|
|
|
|
|
|
|
|
default:
|
2004-02-16 18:07:53 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec4_getpolicybypcb: "
|
2000-07-04 16:35:15 +00:00
|
|
|
"Invalid policy for PCB %d\n", currsp->policy));
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For FORWADING packet or OUTBOUND without a socket. Searching SPD for packet,
|
|
|
|
* and return a pointer to SP.
|
|
|
|
* OUT: positive: a pointer to the entry for security policy leaf matched.
|
|
|
|
* NULL: no apropreate SP found, the following value is set to error.
|
|
|
|
* 0 : bypass
|
|
|
|
* EACCES : discard packet.
|
|
|
|
* ENOENT : ipsec_acquire() in progress, maybe.
|
|
|
|
* others : error occured.
|
|
|
|
*/
|
|
|
|
struct secpolicy *
|
|
|
|
ipsec4_getpolicybyaddr(m, dir, flag, error)
|
|
|
|
struct mbuf *m;
|
|
|
|
u_int dir;
|
|
|
|
int flag;
|
|
|
|
int *error;
|
|
|
|
{
|
|
|
|
struct secpolicy *sp = NULL;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
u_int16_t tag;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (m == NULL || error == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec4_getpolicybyaddr: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
/* get a policy entry matched with the packet */
|
1999-12-22 19:13:38 +00:00
|
|
|
{
|
|
|
|
struct secpolicyindex spidx;
|
|
|
|
|
|
|
|
bzero(&spidx, sizeof(spidx));
|
|
|
|
|
2003-10-08 18:26:08 +00:00
|
|
|
/* make an index to look for a policy */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
*error = ipsec_setspidx_mbuf(&spidx, AF_INET, m,
|
2001-06-11 12:39:29 +00:00
|
|
|
(flag & IP_FORWARDING) ? 0 : 1);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
if (*error != 0)
|
|
|
|
return NULL;
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
tag = 0;
|
|
|
|
|
|
|
|
sp = key_allocsp(tag, &spidx, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SP found */
|
|
|
|
if (sp != NULL) {
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
|
|
|
printf("DP ipsec4_getpolicybyaddr called "
|
|
|
|
"to allocate SP:%p\n", sp));
|
|
|
|
*error = 0;
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no SP found */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ip4_def_policy->refcnt++;
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
return ip4_def_policy;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
/*
|
|
|
|
* For OUTBOUND packet having a socket. Searching SPD for packet,
|
|
|
|
* and return a pointer to SP.
|
|
|
|
* OUT: NULL: no apropreate SP found, the following value is set to error.
|
|
|
|
* 0 : bypass
|
|
|
|
* EACCES : discard packet.
|
|
|
|
* ENOENT : ipsec_acquire() in progress, maybe.
|
|
|
|
* others : error occured.
|
|
|
|
* others: a pointer to SP
|
|
|
|
*/
|
|
|
|
struct secpolicy *
|
2004-02-03 18:20:55 +00:00
|
|
|
ipsec6_getpolicybypcb(m, dir, inp, error)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
u_int dir;
|
2004-02-03 18:20:55 +00:00
|
|
|
struct inpcb *inp;
|
1999-12-22 19:13:38 +00:00
|
|
|
int *error;
|
|
|
|
{
|
|
|
|
struct inpcbpolicy *pcbsp = NULL;
|
|
|
|
struct secpolicy *currsp = NULL; /* policy on socket */
|
|
|
|
struct secpolicy *kernsp = NULL; /* policy on kernel */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct secpolicyindex spidx;
|
|
|
|
u_int16_t tag;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
2004-02-03 18:20:55 +00:00
|
|
|
if (m == NULL || inp == NULL || error == NULL)
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec6_getpolicybypcb: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
2004-02-03 18:20:55 +00:00
|
|
|
if ((inp->inp_vflag & INP_IPV6PROTO) == 0)
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec6_getpolicybypcb: socket domain != inet6");
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
|
|
|
|
2004-02-03 18:20:55 +00:00
|
|
|
pcbsp = inp->in6p_sp;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
1999-12-22 19:13:38 +00:00
|
|
|
if (pcbsp == NULL)
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec6_getpolicybypcb: pcbsp is NULL.");
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
tag = 0;
|
|
|
|
|
|
|
|
/* if we have a cached entry, and if it is still valid, use it. */
|
|
|
|
ipsec6stat.spdcachelookup++;
|
|
|
|
currsp = ipsec_checkpcbcache(m, pcbsp, dir);
|
|
|
|
if (currsp) {
|
|
|
|
*error = 0;
|
|
|
|
return currsp;
|
|
|
|
}
|
|
|
|
ipsec6stat.spdcachemiss++;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
switch (dir) {
|
|
|
|
case IPSEC_DIR_INBOUND:
|
|
|
|
currsp = pcbsp->sp_in;
|
|
|
|
break;
|
|
|
|
case IPSEC_DIR_OUTBOUND:
|
|
|
|
currsp = pcbsp->sp_out;
|
|
|
|
break;
|
|
|
|
default:
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec6_getpolicybypcb: illegal direction.");
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (currsp == NULL)
|
2004-02-16 18:07:53 +00:00
|
|
|
panic("ipsec6_getpolicybypcb: currsp is NULL.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2004-01-13 05:39:07 +00:00
|
|
|
/* when privileged socket */
|
1999-12-22 19:13:38 +00:00
|
|
|
if (pcbsp->priv) {
|
|
|
|
switch (currsp->policy) {
|
|
|
|
case IPSEC_POLICY_BYPASS:
|
|
|
|
currsp->refcnt++;
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, currsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return currsp;
|
|
|
|
|
|
|
|
case IPSEC_POLICY_ENTRUST:
|
|
|
|
/* look for a policy in SPD */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (ipsec_setspidx_mbuf(&spidx, AF_INET6, m, 1) == 0 &&
|
|
|
|
(kernsp = key_allocsp(tag, &spidx, dir)) != NULL) {
|
|
|
|
/* SP found */
|
1999-12-22 19:13:38 +00:00
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
2004-02-16 18:07:53 +00:00
|
|
|
printf("DP ipsec6_getpolicybypcb called "
|
1999-12-22 19:13:38 +00:00
|
|
|
"to allocate SP:%p\n", kernsp));
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, kernsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return kernsp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no SP found */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ip6_def_policy->refcnt++;
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, ip6_def_policy, dir);
|
|
|
|
return ip6_def_policy;
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
case IPSEC_POLICY_IPSEC:
|
|
|
|
currsp->refcnt++;
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, currsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return currsp;
|
|
|
|
|
|
|
|
default:
|
2004-02-16 18:07:53 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec6_getpolicybypcb: "
|
2000-07-04 16:35:15 +00:00
|
|
|
"Invalid policy for PCB %d\n", currsp->policy));
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2004-01-13 05:39:07 +00:00
|
|
|
/* when non-privileged socket */
|
1999-12-22 19:13:38 +00:00
|
|
|
/* look for a policy in SPD */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (ipsec_setspidx_mbuf(&spidx, AF_INET6, m, 1) == 0 &&
|
|
|
|
(kernsp = key_allocsp(tag, &spidx, dir)) != NULL) {
|
|
|
|
/* SP found */
|
1999-12-22 19:13:38 +00:00
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
2004-02-16 18:07:53 +00:00
|
|
|
printf("DP ipsec6_getpolicybypcb called "
|
1999-12-22 19:13:38 +00:00
|
|
|
"to allocate SP:%p\n", kernsp));
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, kernsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return kernsp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no SP found */
|
|
|
|
switch (currsp->policy) {
|
|
|
|
case IPSEC_POLICY_BYPASS:
|
2004-02-16 18:07:53 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec6_getpolicybypcb: "
|
2004-01-13 05:39:07 +00:00
|
|
|
"Illegal policy for non-privileged defined %d\n",
|
2000-07-04 16:35:15 +00:00
|
|
|
currsp->policy));
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case IPSEC_POLICY_ENTRUST:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ip6_def_policy->refcnt++;
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, ip6_def_policy, dir);
|
|
|
|
return ip6_def_policy;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
case IPSEC_POLICY_IPSEC:
|
|
|
|
currsp->refcnt++;
|
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_fillpcbcache(pcbsp, m, currsp, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
return currsp;
|
|
|
|
|
|
|
|
default:
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR,
|
|
|
|
"ipsec6_policybysock: Invalid policy for PCB %d\n",
|
|
|
|
currsp->policy));
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For FORWADING packet or OUTBOUND without a socket. Searching SPD for packet,
|
|
|
|
* and return a pointer to SP.
|
|
|
|
* `flag' means that packet is to be forwarded whether or not.
|
|
|
|
* flag = 1: forwad
|
|
|
|
* OUT: positive: a pointer to the entry for security policy leaf matched.
|
|
|
|
* NULL: no apropreate SP found, the following value is set to error.
|
|
|
|
* 0 : bypass
|
|
|
|
* EACCES : discard packet.
|
|
|
|
* ENOENT : ipsec_acquire() in progress, maybe.
|
|
|
|
* others : error occured.
|
|
|
|
*/
|
|
|
|
#ifndef IP_FORWARDING
|
2000-07-04 16:35:15 +00:00
|
|
|
#define IP_FORWARDING 1
|
1999-12-22 19:13:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct secpolicy *
|
|
|
|
ipsec6_getpolicybyaddr(m, dir, flag, error)
|
|
|
|
struct mbuf *m;
|
|
|
|
u_int dir;
|
|
|
|
int flag;
|
|
|
|
int *error;
|
|
|
|
{
|
|
|
|
struct secpolicy *sp = NULL;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
u_int16_t tag;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (m == NULL || error == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec6_getpolicybyaddr: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
/* get a policy entry matched with the packet */
|
1999-12-22 19:13:38 +00:00
|
|
|
{
|
|
|
|
struct secpolicyindex spidx;
|
|
|
|
|
|
|
|
bzero(&spidx, sizeof(spidx));
|
|
|
|
|
2003-10-08 18:26:08 +00:00
|
|
|
/* make an index to look for a policy */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
*error = ipsec_setspidx_mbuf(&spidx, AF_INET6, m,
|
2001-06-11 12:39:29 +00:00
|
|
|
(flag & IP_FORWARDING) ? 0 : 1);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
if (*error != 0)
|
|
|
|
return NULL;
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
tag = 0;
|
|
|
|
|
|
|
|
sp = key_allocsp(tag, &spidx, dir);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* SP found */
|
|
|
|
if (sp != NULL) {
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
|
|
|
printf("DP ipsec6_getpolicybyaddr called "
|
|
|
|
"to allocate SP:%p\n", sp));
|
|
|
|
*error = 0;
|
|
|
|
return sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no SP found */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ip6_def_policy->refcnt++;
|
1999-12-22 19:13:38 +00:00
|
|
|
*error = 0;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
return ip6_def_policy;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set IP address into spidx from mbuf.
|
|
|
|
* When Forwarding packet and ICMP echo reply, this function is used.
|
|
|
|
*
|
|
|
|
* IN: get the followings from mbuf.
|
|
|
|
* protocol family, src, dst, next protocol
|
|
|
|
* OUT:
|
|
|
|
* 0: success.
|
|
|
|
* other: failure, and set errno.
|
|
|
|
*/
|
|
|
|
int
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_setspidx_mbuf(spidx, family, m, needport)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct secpolicyindex *spidx;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
int family;
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf *m;
|
2001-06-11 12:39:29 +00:00
|
|
|
int needport;
|
1999-12-22 19:13:38 +00:00
|
|
|
{
|
2001-06-11 12:39:29 +00:00
|
|
|
int error;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
/* sanity check */
|
|
|
|
if (spidx == NULL || m == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec_setspidx_mbuf: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
bzero(spidx, sizeof(*spidx));
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
error = ipsec_setspidx(m, spidx, needport);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
return 0;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
bad:
|
|
|
|
/* XXX initialize */
|
|
|
|
bzero(spidx, sizeof(*spidx));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/*
|
|
|
|
* configure security policy index (src/dst/proto/sport/dport)
|
|
|
|
* by looking at the content of mbuf.
|
|
|
|
* the caller is responsible for error recovery (like clearing up spidx).
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipsec_setspidx(m, spidx, needport)
|
|
|
|
struct mbuf *m;
|
|
|
|
struct secpolicyindex *spidx;
|
|
|
|
int needport;
|
|
|
|
{
|
|
|
|
struct ip *ip = NULL;
|
|
|
|
struct ip ipbuf;
|
|
|
|
u_int v;
|
|
|
|
struct mbuf *n;
|
|
|
|
int len;
|
|
|
|
int error;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
if (m == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec_setspidx: m == 0 passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
bzero(spidx, sizeof(*spidx));
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/*
|
|
|
|
* validate m->m_pkthdr.len. we see incorrect length if we
|
|
|
|
* mistakenly call this function with inconsistent mbuf chain
|
|
|
|
* (like 4.4BSD tcp/udp processing). XXX should we panic here?
|
|
|
|
*/
|
|
|
|
len = 0;
|
|
|
|
for (n = m; n; n = n->m_next)
|
|
|
|
len += n->m_len;
|
|
|
|
if (m->m_pkthdr.len != len) {
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec_setspidx: "
|
|
|
|
"total of m_len(%d) != pkthdr.len(%d), "
|
|
|
|
"ignored.\n",
|
|
|
|
len, m->m_pkthdr.len));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
if (m->m_pkthdr.len < sizeof(struct ip)) {
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec_setspidx: "
|
|
|
|
"pkthdr.len(%d) < sizeof(struct ip), ignored.\n",
|
|
|
|
m->m_pkthdr.len));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
if (m->m_len >= sizeof(*ip))
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
else {
|
|
|
|
m_copydata(m, 0, sizeof(ipbuf), (caddr_t)&ipbuf);
|
|
|
|
ip = &ipbuf;
|
|
|
|
}
|
|
|
|
#ifdef _IP_VHL
|
|
|
|
v = _IP_VHL_V(ip->ip_vhl);
|
|
|
|
#else
|
|
|
|
v = ip->ip_v;
|
|
|
|
#endif
|
|
|
|
switch (v) {
|
|
|
|
case 4:
|
|
|
|
error = ipsec4_setspidx_ipaddr(m, spidx);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
ipsec4_get_ulp(m, spidx, needport);
|
|
|
|
return 0;
|
1999-12-22 19:13:38 +00:00
|
|
|
#ifdef INET6
|
2001-06-11 12:39:29 +00:00
|
|
|
case 6:
|
|
|
|
if (m->m_pkthdr.len < sizeof(struct ip6_hdr)) {
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec_setspidx: "
|
|
|
|
"pkthdr.len(%d) < sizeof(struct ip6_hdr), "
|
|
|
|
"ignored.\n", m->m_pkthdr.len));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
error = ipsec6_setspidx_ipaddr(m, spidx);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
ipsec6_get_ulp(m, spidx, needport);
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec_setspidx: "
|
|
|
|
"unknown IP version %u, ignored.\n", v));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
static void
|
2001-06-11 12:39:29 +00:00
|
|
|
ipsec4_get_ulp(m, spidx, needport)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf *m;
|
2000-07-04 16:35:15 +00:00
|
|
|
struct secpolicyindex *spidx;
|
2001-06-11 12:39:29 +00:00
|
|
|
int needport;
|
1999-12-22 19:13:38 +00:00
|
|
|
{
|
2001-06-11 12:39:29 +00:00
|
|
|
struct ip ip;
|
|
|
|
struct ip6_ext ip6e;
|
|
|
|
u_int8_t nxt;
|
|
|
|
int off;
|
|
|
|
struct tcphdr th;
|
|
|
|
struct udphdr uh;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (m == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec4_get_ulp: NULL pointer was passed.");
|
2001-06-11 12:39:29 +00:00
|
|
|
if (m->m_pkthdr.len < sizeof(ip))
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec4_get_ulp: too short");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
/* set default */
|
|
|
|
spidx->ul_proto = IPSEC_ULPROTO_ANY;
|
2001-06-11 12:39:29 +00:00
|
|
|
((struct sockaddr_in *)&spidx->src)->sin_port = IPSEC_PORT_ANY;
|
|
|
|
((struct sockaddr_in *)&spidx->dst)->sin_port = IPSEC_PORT_ANY;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
m_copydata(m, 0, sizeof(ip), (caddr_t)&ip);
|
|
|
|
/* ip_input() flips it into host endian XXX need more checking */
|
|
|
|
if (ip.ip_off & (IP_MF | IP_OFFMASK))
|
2000-07-04 16:35:15 +00:00
|
|
|
return;
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
nxt = ip.ip_p;
|
|
|
|
#ifdef _IP_VHL
|
|
|
|
off = _IP_VHL_HL(ip->ip_vhl) << 2;
|
|
|
|
#else
|
|
|
|
off = ip.ip_hl << 2;
|
|
|
|
#endif
|
|
|
|
while (off < m->m_pkthdr.len) {
|
|
|
|
switch (nxt) {
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
spidx->ul_proto = nxt;
|
|
|
|
if (!needport)
|
|
|
|
return;
|
|
|
|
if (off + sizeof(struct tcphdr) > m->m_pkthdr.len)
|
|
|
|
return;
|
2000-07-04 16:35:15 +00:00
|
|
|
m_copydata(m, off, sizeof(th), (caddr_t)&th);
|
2001-06-11 12:39:29 +00:00
|
|
|
((struct sockaddr_in *)&spidx->src)->sin_port =
|
2000-07-04 16:35:15 +00:00
|
|
|
th.th_sport;
|
2001-06-11 12:39:29 +00:00
|
|
|
((struct sockaddr_in *)&spidx->dst)->sin_port =
|
2000-07-04 16:35:15 +00:00
|
|
|
th.th_dport;
|
2001-06-11 12:39:29 +00:00
|
|
|
return;
|
|
|
|
case IPPROTO_UDP:
|
|
|
|
spidx->ul_proto = nxt;
|
|
|
|
if (!needport)
|
|
|
|
return;
|
|
|
|
if (off + sizeof(struct udphdr) > m->m_pkthdr.len)
|
|
|
|
return;
|
2000-07-04 16:35:15 +00:00
|
|
|
m_copydata(m, off, sizeof(uh), (caddr_t)&uh);
|
2001-06-11 12:39:29 +00:00
|
|
|
((struct sockaddr_in *)&spidx->src)->sin_port =
|
2000-07-04 16:35:15 +00:00
|
|
|
uh.uh_sport;
|
2001-06-11 12:39:29 +00:00
|
|
|
((struct sockaddr_in *)&spidx->dst)->sin_port =
|
2000-07-04 16:35:15 +00:00
|
|
|
uh.uh_dport;
|
2001-06-11 12:39:29 +00:00
|
|
|
return;
|
|
|
|
case IPPROTO_AH:
|
|
|
|
if (m->m_pkthdr.len > off + sizeof(ip6e))
|
|
|
|
return;
|
|
|
|
m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
|
|
|
|
off += (ip6e.ip6e_len + 2) << 2;
|
|
|
|
nxt = ip6e.ip6e_nxt;
|
|
|
|
break;
|
|
|
|
case IPPROTO_ICMP:
|
|
|
|
default:
|
|
|
|
/* XXX intermediate headers??? */
|
|
|
|
spidx->ul_proto = nxt;
|
|
|
|
return;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* assumes that m is sane */
|
|
|
|
static int
|
1999-12-22 19:13:38 +00:00
|
|
|
ipsec4_setspidx_ipaddr(m, spidx)
|
|
|
|
struct mbuf *m;
|
|
|
|
struct secpolicyindex *spidx;
|
|
|
|
{
|
|
|
|
struct ip *ip = NULL;
|
2000-07-04 16:35:15 +00:00
|
|
|
struct ip ipbuf;
|
2001-06-11 12:39:29 +00:00
|
|
|
struct sockaddr_in *sin;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
if (m->m_len >= sizeof(*ip))
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
else {
|
|
|
|
m_copydata(m, 0, sizeof(ipbuf), (caddr_t)&ipbuf);
|
|
|
|
ip = &ipbuf;
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
sin = (struct sockaddr_in *)&spidx->src;
|
|
|
|
bzero(sin, sizeof(*sin));
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_len = sizeof(struct sockaddr_in);
|
|
|
|
bcopy(&ip->ip_src, &sin->sin_addr, sizeof(ip->ip_src));
|
|
|
|
spidx->prefs = sizeof(struct in_addr) << 3;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
sin = (struct sockaddr_in *)&spidx->dst;
|
|
|
|
bzero(sin, sizeof(*sin));
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_len = sizeof(struct sockaddr_in);
|
|
|
|
bcopy(&ip->ip_dst, &sin->sin_addr, sizeof(ip->ip_dst));
|
|
|
|
spidx->prefd = sizeof(struct in_addr) << 3;
|
|
|
|
return 0;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
static void
|
2001-06-11 12:39:29 +00:00
|
|
|
ipsec6_get_ulp(m, spidx, needport)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
struct secpolicyindex *spidx;
|
2001-06-11 12:39:29 +00:00
|
|
|
int needport;
|
|
|
|
{
|
|
|
|
int off, nxt;
|
|
|
|
struct tcphdr th;
|
|
|
|
struct udphdr uh;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct icmp6_hdr ih;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check */
|
2001-06-11 12:39:29 +00:00
|
|
|
if (m == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec6_get_ulp: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec6_get_ulp:\n"); kdebug_mbuf(m));
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* set default */
|
|
|
|
spidx->ul_proto = IPSEC_ULPROTO_ANY;
|
|
|
|
((struct sockaddr_in6 *)&spidx->src)->sin6_port = IPSEC_PORT_ANY;
|
|
|
|
((struct sockaddr_in6 *)&spidx->dst)->sin6_port = IPSEC_PORT_ANY;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
nxt = -1;
|
|
|
|
off = ip6_lasthdr(m, 0, IPPROTO_IPV6, &nxt);
|
|
|
|
if (off < 0 || m->m_pkthdr.len < off)
|
|
|
|
return;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
switch (nxt) {
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
spidx->ul_proto = nxt;
|
|
|
|
if (!needport)
|
|
|
|
break;
|
|
|
|
if (off + sizeof(struct tcphdr) > m->m_pkthdr.len)
|
|
|
|
break;
|
|
|
|
m_copydata(m, off, sizeof(th), (caddr_t)&th);
|
|
|
|
((struct sockaddr_in6 *)&spidx->src)->sin6_port = th.th_sport;
|
|
|
|
((struct sockaddr_in6 *)&spidx->dst)->sin6_port = th.th_dport;
|
|
|
|
break;
|
|
|
|
case IPPROTO_UDP:
|
|
|
|
spidx->ul_proto = nxt;
|
|
|
|
if (!needport)
|
|
|
|
break;
|
|
|
|
if (off + sizeof(struct udphdr) > m->m_pkthdr.len)
|
|
|
|
break;
|
|
|
|
m_copydata(m, off, sizeof(uh), (caddr_t)&uh);
|
|
|
|
((struct sockaddr_in6 *)&spidx->src)->sin6_port = uh.uh_sport;
|
|
|
|
((struct sockaddr_in6 *)&spidx->dst)->sin6_port = uh.uh_dport;
|
|
|
|
break;
|
|
|
|
case IPPROTO_ICMPV6:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
spidx->ul_proto = nxt;
|
|
|
|
if (off + sizeof(struct icmp6_hdr) > m->m_pkthdr.len)
|
|
|
|
break;
|
|
|
|
m_copydata(m, off, sizeof(ih), (caddr_t)&ih);
|
|
|
|
((struct sockaddr_in6 *)&spidx->src)->sin6_port =
|
|
|
|
htons((u_int16_t)ih.icmp6_type);
|
|
|
|
((struct sockaddr_in6 *)&spidx->dst)->sin6_port =
|
|
|
|
htons((u_int16_t)ih.icmp6_code);
|
|
|
|
break;
|
2001-06-11 12:39:29 +00:00
|
|
|
default:
|
|
|
|
/* XXX intermediate headers??? */
|
|
|
|
spidx->ul_proto = nxt;
|
|
|
|
break;
|
|
|
|
}
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* assumes that m is sane */
|
|
|
|
static int
|
1999-12-22 19:13:38 +00:00
|
|
|
ipsec6_setspidx_ipaddr(m, spidx)
|
|
|
|
struct mbuf *m;
|
|
|
|
struct secpolicyindex *spidx;
|
|
|
|
{
|
2000-07-04 16:35:15 +00:00
|
|
|
struct ip6_hdr *ip6 = NULL;
|
|
|
|
struct ip6_hdr ip6buf;
|
|
|
|
struct sockaddr_in6 *sin6;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
if (m->m_len >= sizeof(*ip6))
|
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
1999-12-22 19:13:38 +00:00
|
|
|
else {
|
|
|
|
m_copydata(m, 0, sizeof(ip6buf), (caddr_t)&ip6buf);
|
2000-07-04 16:35:15 +00:00
|
|
|
ip6 = &ip6buf;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)&spidx->src;
|
2001-06-11 12:39:29 +00:00
|
|
|
bzero(sin6, sizeof(*sin6));
|
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_len = sizeof(struct sockaddr_in6);
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
in6_recoverscope(sin6, &ip6->ip6_src, NULL);
|
2001-06-11 12:39:29 +00:00
|
|
|
spidx->prefs = sizeof(struct in6_addr) << 3;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)&spidx->dst;
|
2001-06-11 12:39:29 +00:00
|
|
|
bzero(sin6, sizeof(*sin6));
|
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_len = sizeof(struct sockaddr_in6);
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
in6_recoverscope(sin6, &ip6->ip6_dst, NULL);
|
2001-06-11 12:39:29 +00:00
|
|
|
spidx->prefd = sizeof(struct in6_addr) << 3;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
return 0;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
static struct inpcbpolicy *
|
|
|
|
ipsec_newpcbpolicy()
|
|
|
|
{
|
|
|
|
struct inpcbpolicy *p;
|
|
|
|
|
|
|
|
p = (struct inpcbpolicy *)malloc(sizeof(*p), M_SECA, M_NOWAIT);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ipsec_delpcbpolicy(p)
|
|
|
|
struct inpcbpolicy *p;
|
|
|
|
{
|
2003-10-08 18:26:08 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
free(p, M_SECA);
|
|
|
|
}
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
/* initialize policy in PCB */
|
|
|
|
int
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_init_pcbpolicy(so, pcb_sp)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct socket *so;
|
|
|
|
struct inpcbpolicy **pcb_sp;
|
|
|
|
{
|
|
|
|
struct inpcbpolicy *new;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
static int initialized = 0;
|
|
|
|
static struct secpolicy *in = NULL, *out = NULL;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check. */
|
|
|
|
if (so == NULL || pcb_sp == NULL)
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
panic("ipsec_init_pcbpolicy: NULL pointer was passed.");
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
if ((in = key_newsp(0)) == NULL)
|
|
|
|
return ENOBUFS;
|
|
|
|
if ((out = key_newsp(0)) == NULL) {
|
|
|
|
key_freesp(in);
|
|
|
|
in = NULL;
|
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
in->state = IPSEC_SPSTATE_ALIVE;
|
|
|
|
in->policy = IPSEC_POLICY_ENTRUST;
|
|
|
|
in->dir = IPSEC_DIR_INBOUND;
|
|
|
|
in->readonly = 1;
|
|
|
|
in->persist = 1;
|
|
|
|
in->so = NULL;
|
|
|
|
|
|
|
|
out->state = IPSEC_SPSTATE_ALIVE;
|
|
|
|
out->policy = IPSEC_POLICY_ENTRUST;
|
|
|
|
out->dir = IPSEC_DIR_OUTBOUND;
|
|
|
|
out->readonly = 1;
|
|
|
|
out->persist = 1;
|
|
|
|
out->so = NULL;
|
|
|
|
|
|
|
|
initialized++;
|
|
|
|
}
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
new = ipsec_newpcbpolicy();
|
1999-12-22 19:13:38 +00:00
|
|
|
if (new == NULL) {
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipseclog((LOG_DEBUG, "ipsec_init_pcbpolicy: No more memory.\n"));
|
1999-12-22 19:13:38 +00:00
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
bzero(new, sizeof(*new));
|
|
|
|
|
|
|
|
if (so->so_cred != 0 && so->so_cred->cr_uid == 0)
|
|
|
|
new->priv = 1;
|
|
|
|
else
|
|
|
|
new->priv = 0;
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
new->sp_in = in;
|
|
|
|
new->sp_in->refcnt++;
|
|
|
|
new->sp_out = out;
|
|
|
|
new->sp_out->refcnt++;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
*pcb_sp = new;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy old ipsec policy into new */
|
|
|
|
int
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_copy_pcbpolicy(old, new)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct inpcbpolicy *old, *new;
|
|
|
|
{
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
|
|
|
|
if (new->sp_in)
|
|
|
|
key_freesp(new->sp_in);
|
|
|
|
if (old->sp_in->policy == IPSEC_POLICY_IPSEC)
|
|
|
|
new->sp_in = ipsec_deepcopy_policy(old->sp_in);
|
|
|
|
else {
|
|
|
|
new->sp_in = old->sp_in;
|
|
|
|
new->sp_in->refcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new->sp_out)
|
|
|
|
key_freesp(new->sp_out);
|
|
|
|
if (old->sp_out->policy == IPSEC_POLICY_IPSEC)
|
|
|
|
new->sp_out = ipsec_deepcopy_policy(old->sp_out);
|
|
|
|
else {
|
|
|
|
new->sp_out = old->sp_out;
|
|
|
|
new->sp_out->refcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
new->priv = old->priv;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static int
|
|
|
|
ipsec_deepcopy_pcbpolicy(pcb_sp)
|
|
|
|
struct inpcbpolicy *pcb_sp;
|
|
|
|
{
|
1999-12-22 19:13:38 +00:00
|
|
|
struct secpolicy *sp;
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
sp = ipsec_deepcopy_policy(pcb_sp->sp_in);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (sp) {
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
key_freesp(pcb_sp->sp_in);
|
|
|
|
pcb_sp->sp_in = sp;
|
1999-12-22 19:13:38 +00:00
|
|
|
} else
|
|
|
|
return ENOBUFS;
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
sp = ipsec_deepcopy_policy(pcb_sp->sp_out);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (sp) {
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
key_freesp(pcb_sp->sp_out);
|
|
|
|
pcb_sp->sp_out = sp;
|
1999-12-22 19:13:38 +00:00
|
|
|
} else
|
|
|
|
return ENOBUFS;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* deep-copy a policy in PCB */
|
|
|
|
static struct secpolicy *
|
|
|
|
ipsec_deepcopy_policy(src)
|
|
|
|
struct secpolicy *src;
|
|
|
|
{
|
|
|
|
struct ipsecrequest *newchain = NULL;
|
|
|
|
struct ipsecrequest *p;
|
|
|
|
struct ipsecrequest **q;
|
|
|
|
struct ipsecrequest *r;
|
|
|
|
struct secpolicy *dst;
|
|
|
|
|
2004-01-13 05:32:12 +00:00
|
|
|
if (src == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
dst = key_newsp(0);
|
2004-01-13 05:32:12 +00:00
|
|
|
if (dst == NULL)
|
1999-12-22 19:13:38 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* deep-copy IPsec request chain. This is required since struct
|
|
|
|
* ipsecrequest is not reference counted.
|
|
|
|
*/
|
|
|
|
q = &newchain;
|
|
|
|
for (p = src->req; p; p = p->next) {
|
2000-07-04 16:35:15 +00:00
|
|
|
*q = (struct ipsecrequest *)malloc(sizeof(struct ipsecrequest),
|
|
|
|
M_SECA, M_NOWAIT);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (*q == NULL)
|
|
|
|
goto fail;
|
|
|
|
bzero(*q, sizeof(**q));
|
|
|
|
(*q)->next = NULL;
|
|
|
|
|
|
|
|
(*q)->saidx.proto = p->saidx.proto;
|
|
|
|
(*q)->saidx.mode = p->saidx.mode;
|
|
|
|
(*q)->level = p->level;
|
2000-07-04 16:35:15 +00:00
|
|
|
(*q)->saidx.reqid = p->saidx.reqid;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
bcopy(&p->saidx.src, &(*q)->saidx.src, sizeof((*q)->saidx.src));
|
|
|
|
bcopy(&p->saidx.dst, &(*q)->saidx.dst, sizeof((*q)->saidx.dst));
|
|
|
|
|
|
|
|
(*q)->sav = NULL;
|
|
|
|
(*q)->sp = dst;
|
|
|
|
|
|
|
|
q = &((*q)->next);
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (src->spidx)
|
|
|
|
if (keydb_setsecpolicyindex(dst, src->spidx) != 0)
|
|
|
|
goto fail;
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
dst->req = newchain;
|
|
|
|
dst->state = src->state;
|
|
|
|
dst->policy = src->policy;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
dst->dir = src->dir;
|
|
|
|
dst->so = src->so;
|
1999-12-22 19:13:38 +00:00
|
|
|
/* do not touch the refcnt fields */
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
for (p = newchain; p; p = r) {
|
|
|
|
r = p->next;
|
2000-07-04 16:35:15 +00:00
|
|
|
free(p, M_SECA);
|
1999-12-22 19:13:38 +00:00
|
|
|
p = NULL;
|
|
|
|
}
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
key_freesp(dst);
|
1999-12-22 19:13:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set policy and ipsec request if present. */
|
|
|
|
static int
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_set_policy(spp, optname, request, len, priv)
|
|
|
|
struct secpolicy **spp;
|
1999-12-22 19:13:38 +00:00
|
|
|
int optname;
|
|
|
|
caddr_t request;
|
2000-07-04 16:35:15 +00:00
|
|
|
size_t len;
|
1999-12-22 19:13:38 +00:00
|
|
|
int priv;
|
|
|
|
{
|
2000-07-04 16:35:15 +00:00
|
|
|
struct sadb_x_policy *xpl;
|
1999-12-22 19:13:38 +00:00
|
|
|
struct secpolicy *newsp = NULL;
|
2000-07-04 16:35:15 +00:00
|
|
|
int error;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check. */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (spp == NULL || *spp == NULL || request == NULL)
|
1999-12-22 19:13:38 +00:00
|
|
|
return EINVAL;
|
2000-07-04 16:35:15 +00:00
|
|
|
if (len < sizeof(*xpl))
|
|
|
|
return EINVAL;
|
|
|
|
xpl = (struct sadb_x_policy *)request;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec_set_policy: passed policy\n");
|
|
|
|
kdebug_sadb_x_policy((struct sadb_ext *)xpl));
|
|
|
|
|
|
|
|
/* check policy type */
|
|
|
|
/* ipsec_set_policy() accepts IPSEC, ENTRUST and BYPASS. */
|
2003-10-08 18:26:08 +00:00
|
|
|
if (xpl->sadb_x_policy_type == IPSEC_POLICY_DISCARD ||
|
|
|
|
xpl->sadb_x_policy_type == IPSEC_POLICY_NONE)
|
1999-12-22 19:13:38 +00:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* check privileged socket */
|
|
|
|
if (priv == 0 && xpl->sadb_x_policy_type == IPSEC_POLICY_BYPASS)
|
|
|
|
return EACCES;
|
|
|
|
|
|
|
|
/* allocation new SP entry */
|
2000-07-04 16:35:15 +00:00
|
|
|
if ((newsp = key_msg2sp(xpl, len, &error)) == NULL)
|
|
|
|
return error;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
newsp->state = IPSEC_SPSTATE_ALIVE;
|
|
|
|
|
|
|
|
/* clear old SP and set new SP */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
key_freesp(*spp);
|
|
|
|
*spp = newsp;
|
1999-12-22 19:13:38 +00:00
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec_set_policy: new policy\n");
|
|
|
|
kdebug_secpolicy(newsp));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_get_policy(sp, mp)
|
|
|
|
struct secpolicy *sp;
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf **mp;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* sanity check. */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (sp == NULL || mp == NULL)
|
1999-12-22 19:13:38 +00:00
|
|
|
return EINVAL;
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
*mp = key_sp2msg(sp);
|
2000-07-04 16:35:15 +00:00
|
|
|
if (!*mp) {
|
|
|
|
ipseclog((LOG_DEBUG, "ipsec_get_policy: No more memory.\n"));
|
1999-12-22 19:13:38 +00:00
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
(*mp)->m_type = MT_DATA;
|
1999-12-22 19:13:38 +00:00
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec_get_policy:\n");
|
|
|
|
kdebug_mbuf(*mp));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec4_set_policy(inp, optname, request, len, priv)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct inpcb *inp;
|
|
|
|
int optname;
|
|
|
|
caddr_t request;
|
2000-07-04 16:35:15 +00:00
|
|
|
size_t len;
|
1999-12-22 19:13:38 +00:00
|
|
|
int priv;
|
|
|
|
{
|
2000-07-04 16:35:15 +00:00
|
|
|
struct sadb_x_policy *xpl;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct secpolicy **spp;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check. */
|
|
|
|
if (inp == NULL || request == NULL)
|
|
|
|
return EINVAL;
|
2000-07-04 16:35:15 +00:00
|
|
|
if (len < sizeof(*xpl))
|
|
|
|
return EINVAL;
|
|
|
|
xpl = (struct sadb_x_policy *)request;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* select direction */
|
|
|
|
switch (xpl->sadb_x_policy_dir) {
|
|
|
|
case IPSEC_DIR_INBOUND:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
spp = &inp->inp_sp->sp_in;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
case IPSEC_DIR_OUTBOUND:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
spp = &inp->inp_sp->sp_out;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec4_set_policy: invalid direction=%u\n",
|
|
|
|
xpl->sadb_x_policy_dir));
|
1999-12-22 19:13:38 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_invalpcbcache(inp->inp_sp, IPSEC_DIR_ANY);
|
|
|
|
return ipsec_set_policy(spp, optname, request, len, priv);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec4_get_policy(inp, request, len, mp)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct inpcb *inp;
|
|
|
|
caddr_t request;
|
2000-07-04 16:35:15 +00:00
|
|
|
size_t len;
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf **mp;
|
|
|
|
{
|
2000-07-04 16:35:15 +00:00
|
|
|
struct sadb_x_policy *xpl;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct secpolicy *sp;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check. */
|
|
|
|
if (inp == NULL || request == NULL || mp == NULL)
|
|
|
|
return EINVAL;
|
2000-07-04 16:35:15 +00:00
|
|
|
if (inp->inp_sp == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("policy in PCB is NULL");
|
2000-07-04 16:35:15 +00:00
|
|
|
if (len < sizeof(*xpl))
|
|
|
|
return EINVAL;
|
|
|
|
xpl = (struct sadb_x_policy *)request;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* select direction */
|
|
|
|
switch (xpl->sadb_x_policy_dir) {
|
|
|
|
case IPSEC_DIR_INBOUND:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
sp = inp->inp_sp->sp_in;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
case IPSEC_DIR_OUTBOUND:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
sp = inp->inp_sp->sp_out;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-10-08 18:26:08 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec4_get_policy: invalid direction=%u\n",
|
2000-07-04 16:35:15 +00:00
|
|
|
xpl->sadb_x_policy_dir));
|
1999-12-22 19:13:38 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
return ipsec_get_policy(sp, mp);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* delete policy in PCB */
|
|
|
|
int
|
|
|
|
ipsec4_delete_pcbpolicy(inp)
|
|
|
|
struct inpcb *inp;
|
|
|
|
{
|
|
|
|
/* sanity check. */
|
|
|
|
if (inp == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec4_delete_pcbpolicy: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
if (inp->inp_sp == NULL)
|
|
|
|
return 0;
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
if (inp->inp_sp->sp_in != NULL) {
|
|
|
|
key_freesp(inp->inp_sp->sp_in);
|
|
|
|
inp->inp_sp->sp_in = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inp->inp_sp->sp_out != NULL) {
|
|
|
|
key_freesp(inp->inp_sp->sp_out);
|
|
|
|
inp->inp_sp->sp_out = NULL;
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_invalpcbcache(inp->inp_sp, IPSEC_DIR_ANY);
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec_delpcbpolicy(inp->inp_sp);
|
1999-12-22 19:13:38 +00:00
|
|
|
inp->inp_sp = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
int
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec6_set_policy(in6p, optname, request, len, priv)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct in6pcb *in6p;
|
|
|
|
int optname;
|
|
|
|
caddr_t request;
|
2000-07-04 16:35:15 +00:00
|
|
|
size_t len;
|
1999-12-22 19:13:38 +00:00
|
|
|
int priv;
|
|
|
|
{
|
2000-07-04 16:35:15 +00:00
|
|
|
struct sadb_x_policy *xpl;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct secpolicy **spp;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check. */
|
|
|
|
if (in6p == NULL || request == NULL)
|
|
|
|
return EINVAL;
|
2000-07-04 16:35:15 +00:00
|
|
|
if (len < sizeof(*xpl))
|
|
|
|
return EINVAL;
|
|
|
|
xpl = (struct sadb_x_policy *)request;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* select direction */
|
|
|
|
switch (xpl->sadb_x_policy_dir) {
|
|
|
|
case IPSEC_DIR_INBOUND:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
spp = &in6p->in6p_sp->sp_in;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
case IPSEC_DIR_OUTBOUND:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
spp = &in6p->in6p_sp->sp_out;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec6_set_policy: invalid direction=%u\n",
|
|
|
|
xpl->sadb_x_policy_dir));
|
1999-12-22 19:13:38 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_invalpcbcache(in6p->in6p_sp, IPSEC_DIR_ANY);
|
|
|
|
return ipsec_set_policy(spp, optname, request, len, priv);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec6_get_policy(in6p, request, len, mp)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct in6pcb *in6p;
|
|
|
|
caddr_t request;
|
2000-07-04 16:35:15 +00:00
|
|
|
size_t len;
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf **mp;
|
|
|
|
{
|
2000-07-04 16:35:15 +00:00
|
|
|
struct sadb_x_policy *xpl;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct secpolicy *sp;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* sanity check. */
|
|
|
|
if (in6p == NULL || request == NULL || mp == NULL)
|
|
|
|
return EINVAL;
|
2000-07-04 16:35:15 +00:00
|
|
|
if (in6p->in6p_sp == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("policy in PCB is NULL");
|
2000-07-04 16:35:15 +00:00
|
|
|
if (len < sizeof(*xpl))
|
|
|
|
return EINVAL;
|
|
|
|
xpl = (struct sadb_x_policy *)request;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* select direction */
|
|
|
|
switch (xpl->sadb_x_policy_dir) {
|
|
|
|
case IPSEC_DIR_INBOUND:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
sp = in6p->in6p_sp->sp_in;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
case IPSEC_DIR_OUTBOUND:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
sp = in6p->in6p_sp->sp_out;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-10-08 18:26:08 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec6_get_policy: invalid direction=%u\n",
|
2000-07-04 16:35:15 +00:00
|
|
|
xpl->sadb_x_policy_dir));
|
1999-12-22 19:13:38 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
return ipsec_get_policy(sp, mp);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ipsec6_delete_pcbpolicy(in6p)
|
|
|
|
struct in6pcb *in6p;
|
|
|
|
{
|
|
|
|
/* sanity check. */
|
|
|
|
if (in6p == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec6_delete_pcbpolicy: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
if (in6p->in6p_sp == NULL)
|
|
|
|
return 0;
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
if (in6p->in6p_sp->sp_in != NULL) {
|
|
|
|
key_freesp(in6p->in6p_sp->sp_in);
|
|
|
|
in6p->in6p_sp->sp_in = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in6p->in6p_sp->sp_out != NULL) {
|
|
|
|
key_freesp(in6p->in6p_sp->sp_out);
|
|
|
|
in6p->in6p_sp->sp_out = NULL;
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_invalpcbcache(in6p->in6p_sp, IPSEC_DIR_ANY);
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec_delpcbpolicy(in6p->in6p_sp);
|
1999-12-22 19:13:38 +00:00
|
|
|
in6p->in6p_sp = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return current level.
|
2000-07-04 16:35:15 +00:00
|
|
|
* Either IPSEC_LEVEL_USE or IPSEC_LEVEL_REQUIRE are always returned.
|
1999-12-22 19:13:38 +00:00
|
|
|
*/
|
|
|
|
u_int
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
ipsec_get_reqlevel(isr, af)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct ipsecrequest *isr;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
int af;
|
1999-12-22 19:13:38 +00:00
|
|
|
{
|
|
|
|
u_int level = 0;
|
|
|
|
u_int esp_trans_deflev, esp_net_deflev, ah_trans_deflev, ah_net_deflev;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (isr == NULL || isr->sp == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec_get_reqlevel: NULL pointer is passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* set default level */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
switch (af) {
|
1999-12-22 19:13:38 +00:00
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
esp_trans_deflev = ip4_esp_trans_deflev;
|
|
|
|
esp_net_deflev = ip4_esp_net_deflev;
|
|
|
|
ah_trans_deflev = ip4_ah_trans_deflev;
|
|
|
|
ah_net_deflev = ip4_ah_net_deflev;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
esp_trans_deflev = ip6_esp_trans_deflev;
|
|
|
|
esp_net_deflev = ip6_esp_net_deflev;
|
|
|
|
ah_trans_deflev = ip6_ah_trans_deflev;
|
|
|
|
ah_net_deflev = ip6_ah_net_deflev;
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
|
|
|
default:
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("key_get_reqlevel: Unknown family. %d",
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
((struct sockaddr *)&isr->sp->spidx->src)->sa_family);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set level */
|
|
|
|
switch (isr->level) {
|
|
|
|
case IPSEC_LEVEL_DEFAULT:
|
|
|
|
switch (isr->saidx.proto) {
|
|
|
|
case IPPROTO_ESP:
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TUNNEL)
|
|
|
|
level = esp_net_deflev;
|
|
|
|
else
|
|
|
|
level = esp_trans_deflev;
|
|
|
|
break;
|
|
|
|
case IPPROTO_AH:
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TUNNEL)
|
|
|
|
level = ah_net_deflev;
|
|
|
|
else
|
|
|
|
level = ah_trans_deflev;
|
2004-10-28 09:24:45 +00:00
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
case IPPROTO_IPCOMP:
|
|
|
|
/*
|
|
|
|
* we don't really care, as IPcomp document says that
|
|
|
|
* we shouldn't compress small packets
|
|
|
|
*/
|
|
|
|
level = IPSEC_LEVEL_USE;
|
|
|
|
break;
|
1999-12-22 19:13:38 +00:00
|
|
|
default:
|
|
|
|
panic("ipsec_get_reqlevel: "
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
"Illegal protocol defined %u\n",
|
1999-12-22 19:13:38 +00:00
|
|
|
isr->saidx.proto);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IPSEC_LEVEL_USE:
|
|
|
|
case IPSEC_LEVEL_REQUIRE:
|
|
|
|
level = isr->level;
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
case IPSEC_LEVEL_UNIQUE:
|
|
|
|
level = IPSEC_LEVEL_REQUIRE;
|
|
|
|
break;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
default:
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec_get_reqlevel: Illegal IPsec level %u",
|
1999-12-22 19:13:38 +00:00
|
|
|
isr->level);
|
|
|
|
}
|
|
|
|
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check AH/ESP integrity.
|
|
|
|
* OUT:
|
|
|
|
* 0: valid
|
|
|
|
* 1: invalid
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipsec_in_reject(sp, m)
|
|
|
|
struct secpolicy *sp;
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct ipsecrequest *isr;
|
|
|
|
u_int level;
|
|
|
|
int need_auth, need_conf, need_icv;
|
|
|
|
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DATA,
|
|
|
|
printf("ipsec_in_reject: using SP\n");
|
|
|
|
kdebug_secpolicy(sp));
|
|
|
|
|
|
|
|
/* check policy */
|
|
|
|
switch (sp->policy) {
|
|
|
|
case IPSEC_POLICY_DISCARD:
|
|
|
|
return 1;
|
|
|
|
case IPSEC_POLICY_BYPASS:
|
|
|
|
case IPSEC_POLICY_NONE:
|
|
|
|
return 0;
|
2003-10-08 18:26:08 +00:00
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
case IPSEC_POLICY_IPSEC:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IPSEC_POLICY_ENTRUST:
|
|
|
|
default:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
panic("ipsec_in_reject: Invalid policy found. %d", sp->policy);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
need_auth = 0;
|
|
|
|
need_conf = 0;
|
|
|
|
need_icv = 0;
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* XXX should compare policy against ipsec header history */
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
for (isr = sp->req; isr != NULL; isr = isr->next) {
|
|
|
|
/* get current level */
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
level = ipsec_get_reqlevel(isr, AF_INET);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
switch (isr->saidx.proto) {
|
|
|
|
case IPPROTO_ESP:
|
|
|
|
if (level == IPSEC_LEVEL_REQUIRE) {
|
|
|
|
need_conf++;
|
|
|
|
|
|
|
|
if (isr->sav != NULL
|
|
|
|
&& isr->sav->flags == SADB_X_EXT_NONE
|
|
|
|
&& isr->sav->alg_auth != SADB_AALG_NONE)
|
|
|
|
need_icv++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IPPROTO_AH:
|
|
|
|
if (level == IPSEC_LEVEL_REQUIRE) {
|
|
|
|
need_auth++;
|
|
|
|
need_icv++;
|
|
|
|
}
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
case IPPROTO_IPCOMP:
|
|
|
|
/*
|
|
|
|
* we don't really care, as IPcomp document says that
|
2001-06-11 12:39:29 +00:00
|
|
|
* we shouldn't compress small packets, IPComp policy
|
|
|
|
* should always be treated as being in "use" level.
|
2000-07-04 16:35:15 +00:00
|
|
|
*/
|
|
|
|
break;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DUMP,
|
|
|
|
printf("ipsec_in_reject: auth:%d conf:%d icv:%d m_flags:%x\n",
|
|
|
|
need_auth, need_conf, need_icv, m->m_flags));
|
|
|
|
|
|
|
|
if ((need_conf && !(m->m_flags & M_DECRYPTED))
|
|
|
|
|| (!need_auth && need_icv && !(m->m_flags & M_AUTHIPDGM))
|
|
|
|
|| (need_auth && !(m->m_flags & M_AUTHIPHDR)))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check AH/ESP integrity.
|
|
|
|
* This function is called from tcp_input(), udp_input(),
|
|
|
|
* and {ah,esp}4_input for tunnel mode
|
|
|
|
*/
|
|
|
|
int
|
2004-02-03 18:20:55 +00:00
|
|
|
ipsec4_in_reject(m, inp)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf *m;
|
2004-02-03 18:20:55 +00:00
|
|
|
struct inpcb *inp;
|
1999-12-22 19:13:38 +00:00
|
|
|
{
|
|
|
|
struct secpolicy *sp = NULL;
|
|
|
|
int error;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (m == NULL)
|
|
|
|
return 0; /* XXX should be panic ? */
|
|
|
|
|
|
|
|
/* get SP for this packet.
|
|
|
|
* When we are called from ip_forward(), we call
|
|
|
|
* ipsec4_getpolicybyaddr() with IP_FORWARDING flag.
|
|
|
|
*/
|
2004-02-03 18:20:55 +00:00
|
|
|
if (inp == NULL)
|
2003-10-08 18:26:08 +00:00
|
|
|
sp = ipsec4_getpolicybyaddr(m, IPSEC_DIR_INBOUND,
|
|
|
|
IP_FORWARDING, &error);
|
1999-12-22 19:13:38 +00:00
|
|
|
else
|
2004-02-03 18:20:55 +00:00
|
|
|
sp = ipsec4_getpolicybypcb(m, IPSEC_DIR_INBOUND, inp, &error);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2003-10-08 18:26:08 +00:00
|
|
|
/* XXX should be panic ? -> No, there may be error. */
|
1999-12-22 19:13:38 +00:00
|
|
|
if (sp == NULL)
|
2003-10-08 18:26:08 +00:00
|
|
|
return 0;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
result = ipsec_in_reject(sp, m);
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
2004-02-03 18:20:55 +00:00
|
|
|
printf("DP ipsec4_in_reject call free SP:%p\n", sp));
|
1999-12-22 19:13:38 +00:00
|
|
|
key_freesp(sp);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
/*
|
|
|
|
* Check AH/ESP integrity.
|
|
|
|
* This function is called from tcp6_input(), udp6_input(),
|
|
|
|
* and {ah,esp}6_input for tunnel mode
|
|
|
|
*/
|
|
|
|
int
|
2004-02-03 18:20:55 +00:00
|
|
|
ipsec6_in_reject(m, in6p)
|
1999-12-22 19:13:38 +00:00
|
|
|
struct mbuf *m;
|
2004-02-03 18:20:55 +00:00
|
|
|
struct in6pcb *in6p;
|
1999-12-22 19:13:38 +00:00
|
|
|
{
|
|
|
|
struct secpolicy *sp = NULL;
|
|
|
|
int error;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (m == NULL)
|
|
|
|
return 0; /* XXX should be panic ? */
|
|
|
|
|
|
|
|
/* get SP for this packet.
|
|
|
|
* When we are called from ip_forward(), we call
|
|
|
|
* ipsec6_getpolicybyaddr() with IP_FORWARDING flag.
|
|
|
|
*/
|
2004-02-03 18:20:55 +00:00
|
|
|
if (in6p == NULL)
|
2003-10-08 18:26:08 +00:00
|
|
|
sp = ipsec6_getpolicybyaddr(m, IPSEC_DIR_INBOUND,
|
|
|
|
IP_FORWARDING, &error);
|
1999-12-22 19:13:38 +00:00
|
|
|
else
|
2004-02-03 18:20:55 +00:00
|
|
|
sp = ipsec6_getpolicybypcb(m, IPSEC_DIR_INBOUND, in6p, &error);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
if (sp == NULL)
|
|
|
|
return 0; /* XXX should be panic ? */
|
|
|
|
|
|
|
|
result = ipsec_in_reject(sp, m);
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
2004-02-03 18:20:55 +00:00
|
|
|
printf("DP ipsec6_in_reject call free SP:%p\n", sp));
|
1999-12-22 19:13:38 +00:00
|
|
|
key_freesp(sp);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* compute the byte size to be occupied by IPsec header.
|
|
|
|
* in case it is tunneled, it includes the size of outer IP header.
|
|
|
|
* NOTE: SP passed is free in this function.
|
|
|
|
*/
|
|
|
|
static size_t
|
|
|
|
ipsec_hdrsiz(sp)
|
|
|
|
struct secpolicy *sp;
|
|
|
|
{
|
|
|
|
struct ipsecrequest *isr;
|
|
|
|
size_t siz, clen;
|
|
|
|
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DATA,
|
2002-04-19 04:46:24 +00:00
|
|
|
printf("ipsec_hdrsiz: using SP\n");
|
1999-12-22 19:13:38 +00:00
|
|
|
kdebug_secpolicy(sp));
|
|
|
|
|
|
|
|
/* check policy */
|
|
|
|
switch (sp->policy) {
|
|
|
|
case IPSEC_POLICY_DISCARD:
|
|
|
|
case IPSEC_POLICY_BYPASS:
|
|
|
|
case IPSEC_POLICY_NONE:
|
|
|
|
return 0;
|
2003-10-08 18:26:08 +00:00
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
case IPSEC_POLICY_IPSEC:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IPSEC_POLICY_ENTRUST:
|
|
|
|
default:
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec_hdrsiz: Invalid policy found. %d", sp->policy);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
siz = 0;
|
|
|
|
|
|
|
|
for (isr = sp->req; isr != NULL; isr = isr->next) {
|
|
|
|
|
|
|
|
clen = 0;
|
|
|
|
|
|
|
|
switch (isr->saidx.proto) {
|
|
|
|
case IPPROTO_ESP:
|
|
|
|
#ifdef IPSEC_ESP
|
|
|
|
clen = esp_hdrsiz(isr);
|
|
|
|
#else
|
2002-04-19 04:46:24 +00:00
|
|
|
clen = 0; /* XXX */
|
1999-12-22 19:13:38 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case IPPROTO_AH:
|
|
|
|
clen = ah_hdrsiz(isr);
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
case IPPROTO_IPCOMP:
|
|
|
|
clen = sizeof(struct ipcomp);
|
|
|
|
break;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TUNNEL) {
|
2000-07-04 16:35:15 +00:00
|
|
|
switch (((struct sockaddr *)&isr->saidx.dst)->sa_family) {
|
1999-12-22 19:13:38 +00:00
|
|
|
case AF_INET:
|
|
|
|
clen += sizeof(struct ip);
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
clen += sizeof(struct ip6_hdr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec_hdrsiz: "
|
|
|
|
"unknown AF %d in IPsec tunnel SA\n",
|
|
|
|
((struct sockaddr *)&isr->saidx.dst)->sa_family));
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
siz += clen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return siz;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function is called from ip_forward() and ipsec4_hdrsize_tcp(). */
|
|
|
|
size_t
|
|
|
|
ipsec4_hdrsiz(m, dir, inp)
|
|
|
|
struct mbuf *m;
|
|
|
|
u_int dir;
|
|
|
|
struct inpcb *inp;
|
|
|
|
{
|
|
|
|
struct secpolicy *sp = NULL;
|
|
|
|
int error;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (m == NULL)
|
|
|
|
return 0; /* XXX should be panic ? */
|
2004-02-03 18:20:55 +00:00
|
|
|
#if 0
|
|
|
|
/* this is possible in TIME_WAIT state */
|
1999-12-22 19:13:38 +00:00
|
|
|
if (inp != NULL && inp->inp_socket == NULL)
|
|
|
|
panic("ipsec4_hdrsize: why is socket NULL but there is PCB.");
|
2004-02-03 18:20:55 +00:00
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* get SP for this packet.
|
|
|
|
* When we are called from ip_forward(), we call
|
|
|
|
* ipsec4_getpolicybyaddr() with IP_FORWARDING flag.
|
|
|
|
*/
|
|
|
|
if (inp == NULL)
|
|
|
|
sp = ipsec4_getpolicybyaddr(m, dir, IP_FORWARDING, &error);
|
|
|
|
else
|
2004-02-03 18:20:55 +00:00
|
|
|
sp = ipsec4_getpolicybypcb(m, dir, inp, &error);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
if (sp == NULL)
|
|
|
|
return 0; /* XXX should be panic ? */
|
|
|
|
|
|
|
|
size = ipsec_hdrsiz(sp);
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
|
|
|
printf("DP ipsec4_hdrsiz call free SP:%p\n", sp));
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DATA,
|
|
|
|
printf("ipsec4_hdrsiz: size:%lu.\n", (unsigned long)size));
|
|
|
|
key_freesp(sp);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
/* This function is called from ipsec6_hdrsize_tcp(),
|
|
|
|
* and maybe from ip6_forward.()
|
|
|
|
*/
|
|
|
|
size_t
|
|
|
|
ipsec6_hdrsiz(m, dir, in6p)
|
|
|
|
struct mbuf *m;
|
|
|
|
u_int dir;
|
|
|
|
struct in6pcb *in6p;
|
|
|
|
{
|
|
|
|
struct secpolicy *sp = NULL;
|
|
|
|
int error;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (m == NULL)
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
return 0; /* XXX should be panic ? */
|
2004-02-03 18:20:55 +00:00
|
|
|
#if 0
|
|
|
|
/* this is possible in TIME_WAIT state */
|
1999-12-22 19:13:38 +00:00
|
|
|
if (in6p != NULL && in6p->in6p_socket == NULL)
|
|
|
|
panic("ipsec6_hdrsize: why is socket NULL but there is PCB.");
|
2004-02-03 18:20:55 +00:00
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* get SP for this packet */
|
|
|
|
/* XXX Is it right to call with IP_FORWARDING. */
|
|
|
|
if (in6p == NULL)
|
|
|
|
sp = ipsec6_getpolicybyaddr(m, dir, IP_FORWARDING, &error);
|
|
|
|
else
|
2004-02-03 18:20:55 +00:00
|
|
|
sp = ipsec6_getpolicybypcb(m, dir, in6p, &error);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
if (sp == NULL)
|
|
|
|
return 0;
|
|
|
|
size = ipsec_hdrsiz(sp);
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_STAMP,
|
|
|
|
printf("DP ipsec6_hdrsiz call free SP:%p\n", sp));
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DATA,
|
|
|
|
printf("ipsec6_hdrsiz: size:%lu.\n", (unsigned long)size));
|
|
|
|
key_freesp(sp);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
2002-04-19 04:46:24 +00:00
|
|
|
#endif /* INET6 */
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
/*
|
|
|
|
* encapsulate for ipsec tunnel.
|
|
|
|
* ip->ip_src must be fixed later on.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipsec4_encapsulate(m, sav)
|
|
|
|
struct mbuf *m;
|
|
|
|
struct secasvar *sav;
|
|
|
|
{
|
|
|
|
struct ip *oip;
|
|
|
|
struct ip *ip;
|
|
|
|
size_t hlen;
|
|
|
|
size_t plen;
|
|
|
|
|
|
|
|
/* can't tunnel between different AFs */
|
2000-07-04 16:35:15 +00:00
|
|
|
if (((struct sockaddr *)&sav->sah->saidx.src)->sa_family
|
|
|
|
!= ((struct sockaddr *)&sav->sah->saidx.dst)->sa_family
|
|
|
|
|| ((struct sockaddr *)&sav->sah->saidx.src)->sa_family != AF_INET) {
|
1999-12-22 19:13:38 +00:00
|
|
|
m_freem(m);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
#if 0
|
|
|
|
/* XXX if the dst is myself, perform nothing. */
|
|
|
|
if (key_ismyaddr((struct sockaddr *)&sav->sah->saidx.dst)) {
|
|
|
|
m_freem(m);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (m->m_len < sizeof(*ip))
|
|
|
|
panic("ipsec4_encapsulate: assumption failed (first mbuf length)");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
#ifdef _IP_VHL
|
|
|
|
hlen = _IP_VHL_HL(ip->ip_vhl) << 2;
|
|
|
|
#else
|
|
|
|
hlen = ip->ip_hl << 2;
|
|
|
|
#endif
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
if (m->m_len != hlen)
|
|
|
|
panic("ipsec4_encapsulate: assumption failed (first mbuf length)");
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
/* generate header checksum */
|
|
|
|
ip->ip_sum = 0;
|
|
|
|
#ifdef _IP_VHL
|
|
|
|
if (ip->ip_vhl == IP_VHL_BORING)
|
|
|
|
ip->ip_sum = in_cksum_hdr(ip);
|
|
|
|
else
|
|
|
|
ip->ip_sum = in_cksum(m, hlen);
|
|
|
|
#else
|
|
|
|
ip->ip_sum = in_cksum(m, hlen);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
plen = m->m_pkthdr.len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* grow the mbuf to accomodate the new IPv4 header.
|
|
|
|
* NOTE: IPv4 options will never be copied.
|
|
|
|
*/
|
|
|
|
if (M_LEADINGSPACE(m->m_next) < hlen) {
|
|
|
|
struct mbuf *n;
|
2003-02-19 05:47:46 +00:00
|
|
|
MGET(n, M_DONTWAIT, MT_DATA);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!n) {
|
|
|
|
m_freem(m);
|
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
n->m_len = hlen;
|
|
|
|
n->m_next = m->m_next;
|
|
|
|
m->m_next = n;
|
|
|
|
m->m_pkthdr.len += hlen;
|
|
|
|
oip = mtod(n, struct ip *);
|
|
|
|
} else {
|
|
|
|
m->m_next->m_len += hlen;
|
|
|
|
m->m_next->m_data -= hlen;
|
|
|
|
m->m_pkthdr.len += hlen;
|
|
|
|
oip = mtod(m->m_next, struct ip *);
|
|
|
|
}
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
ovbcopy((caddr_t)ip, (caddr_t)oip, hlen);
|
|
|
|
m->m_len = sizeof(struct ip);
|
|
|
|
m->m_pkthdr.len -= (hlen - sizeof(struct ip));
|
|
|
|
|
|
|
|
/* construct new IPv4 header. see RFC 2401 5.1.2.1 */
|
|
|
|
/* ECN consideration. */
|
|
|
|
ip_ecn_ingress(ip4_ipsec_ecn, &ip->ip_tos, &oip->ip_tos);
|
|
|
|
#ifdef _IP_VHL
|
|
|
|
ip->ip_vhl = IP_MAKE_VHL(IPVERSION, sizeof(struct ip) >> 2);
|
|
|
|
#else
|
|
|
|
ip->ip_hl = sizeof(struct ip) >> 2;
|
|
|
|
#endif
|
|
|
|
ip->ip_off &= htons(~IP_OFFMASK);
|
|
|
|
ip->ip_off &= htons(~IP_MF);
|
|
|
|
switch (ip4_ipsec_dfbit) {
|
2002-04-19 04:46:24 +00:00
|
|
|
case 0: /* clear DF bit */
|
1999-12-22 19:13:38 +00:00
|
|
|
ip->ip_off &= htons(~IP_DF);
|
|
|
|
break;
|
2002-04-19 04:46:24 +00:00
|
|
|
case 1: /* set DF bit */
|
1999-12-22 19:13:38 +00:00
|
|
|
ip->ip_off |= htons(IP_DF);
|
|
|
|
break;
|
2002-04-19 04:46:24 +00:00
|
|
|
default: /* copy DF bit */
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ip->ip_p = IPPROTO_IPIP;
|
|
|
|
if (plen + sizeof(struct ip) < IP_MAXPACKET)
|
|
|
|
ip->ip_len = htons(plen + sizeof(struct ip));
|
|
|
|
else {
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR, "IPv4 ipsec: size exceeds limit: "
|
2003-10-08 18:26:08 +00:00
|
|
|
"leave ip_len as is (invalid packet)\n"));
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
2004-08-14 15:32:40 +00:00
|
|
|
ip->ip_id = ip_newid();
|
1999-12-22 19:13:38 +00:00
|
|
|
bcopy(&((struct sockaddr_in *)&sav->sah->saidx.src)->sin_addr,
|
|
|
|
&ip->ip_src, sizeof(ip->ip_src));
|
|
|
|
bcopy(&((struct sockaddr_in *)&sav->sah->saidx.dst)->sin_addr,
|
|
|
|
&ip->ip_dst, sizeof(ip->ip_dst));
|
2001-06-11 12:39:29 +00:00
|
|
|
ip->ip_ttl = IPDEFTTL;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* XXX Should ip_src be updated later ? */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-19 04:46:24 +00:00
|
|
|
#endif /* INET */
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
static int
|
|
|
|
ipsec6_encapsulate(m, sav)
|
|
|
|
struct mbuf *m;
|
|
|
|
struct secasvar *sav;
|
|
|
|
{
|
|
|
|
struct ip6_hdr *oip6;
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
size_t plen;
|
|
|
|
|
|
|
|
/* can't tunnel between different AFs */
|
2000-07-04 16:35:15 +00:00
|
|
|
if (((struct sockaddr *)&sav->sah->saidx.src)->sa_family
|
|
|
|
!= ((struct sockaddr *)&sav->sah->saidx.dst)->sa_family
|
|
|
|
|| ((struct sockaddr *)&sav->sah->saidx.src)->sa_family != AF_INET6) {
|
1999-12-22 19:13:38 +00:00
|
|
|
m_freem(m);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
#if 0
|
|
|
|
/* XXX if the dst is myself, perform nothing. */
|
|
|
|
if (key_ismyaddr((struct sockaddr *)&sav->sah->saidx.dst)) {
|
|
|
|
m_freem(m);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
plen = m->m_pkthdr.len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* grow the mbuf to accomodate the new IPv6 header.
|
|
|
|
*/
|
|
|
|
if (m->m_len != sizeof(struct ip6_hdr))
|
|
|
|
panic("ipsec6_encapsulate: assumption failed (first mbuf length)");
|
|
|
|
if (M_LEADINGSPACE(m->m_next) < sizeof(struct ip6_hdr)) {
|
|
|
|
struct mbuf *n;
|
2003-02-19 05:47:46 +00:00
|
|
|
MGET(n, M_DONTWAIT, MT_DATA);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!n) {
|
|
|
|
m_freem(m);
|
|
|
|
return ENOBUFS;
|
|
|
|
}
|
|
|
|
n->m_len = sizeof(struct ip6_hdr);
|
|
|
|
n->m_next = m->m_next;
|
|
|
|
m->m_next = n;
|
|
|
|
m->m_pkthdr.len += sizeof(struct ip6_hdr);
|
|
|
|
oip6 = mtod(n, struct ip6_hdr *);
|
|
|
|
} else {
|
|
|
|
m->m_next->m_len += sizeof(struct ip6_hdr);
|
|
|
|
m->m_next->m_data -= sizeof(struct ip6_hdr);
|
|
|
|
m->m_pkthdr.len += sizeof(struct ip6_hdr);
|
|
|
|
oip6 = mtod(m->m_next, struct ip6_hdr *);
|
|
|
|
}
|
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
|
|
|
ovbcopy((caddr_t)ip6, (caddr_t)oip6, sizeof(struct ip6_hdr));
|
|
|
|
|
2003-10-21 20:05:32 +00:00
|
|
|
/* XXX: Fake scoped addresses */
|
|
|
|
in6_clearscope(&oip6->ip6_src);
|
|
|
|
in6_clearscope(&oip6->ip6_dst);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* construct new IPv6 header. see RFC 2401 5.1.2.2 */
|
|
|
|
/* ECN consideration. */
|
|
|
|
ip6_ecn_ingress(ip6_ipsec_ecn, &ip6->ip6_flow, &oip6->ip6_flow);
|
|
|
|
if (plen < IPV6_MAXPACKET - sizeof(struct ip6_hdr))
|
|
|
|
ip6->ip6_plen = htons(plen);
|
|
|
|
else {
|
|
|
|
/* ip6->ip6_plen will be updated in ip6_output() */
|
|
|
|
}
|
|
|
|
ip6->ip6_nxt = IPPROTO_IPV6;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
in6_embedscope(&ip6->ip6_src,
|
|
|
|
(struct sockaddr_in6 *)&sav->sah->saidx.src, NULL, NULL);
|
|
|
|
in6_embedscope(&ip6->ip6_dst,
|
|
|
|
(struct sockaddr_in6 *)&sav->sah->saidx.dst, NULL, NULL);
|
2001-06-11 12:39:29 +00:00
|
|
|
ip6->ip6_hlim = IPV6_DEFHLIM;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* XXX Should ip6_src be updated later ? */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2002-04-19 04:46:24 +00:00
|
|
|
#endif /* INET6 */
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the variable replay window.
|
|
|
|
* ipsec_chkreplay() performs replay check before ICV verification.
|
|
|
|
* ipsec_updatereplay() updates replay bitmap. This must be called after
|
|
|
|
* ICV verification (it also performs replay check, which is usually done
|
|
|
|
* beforehand).
|
|
|
|
* 0 (zero) is returned if packet disallowed, 1 if packet permitted.
|
|
|
|
*
|
|
|
|
* based on RFC 2401.
|
2003-10-08 18:26:08 +00:00
|
|
|
*
|
|
|
|
* XXX need to update for 64bit sequence number - 2401bis
|
1999-12-22 19:13:38 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipsec_chkreplay(seq, sav)
|
|
|
|
u_int32_t seq;
|
|
|
|
struct secasvar *sav;
|
|
|
|
{
|
|
|
|
const struct secreplay *replay;
|
|
|
|
u_int32_t diff;
|
|
|
|
int fr;
|
|
|
|
u_int32_t wsizeb; /* constant: bits of window size */
|
|
|
|
int frlast; /* constant: last frame */
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (sav == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec_chkreplay: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
replay = sav->replay;
|
|
|
|
|
|
|
|
if (replay->wsize == 0)
|
|
|
|
return 1; /* no need to check replay. */
|
|
|
|
|
|
|
|
/* constant */
|
|
|
|
frlast = replay->wsize - 1;
|
|
|
|
wsizeb = replay->wsize << 3;
|
|
|
|
|
|
|
|
/* sequence number of 0 is invalid */
|
|
|
|
if (seq == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* first time is always okay */
|
|
|
|
if (replay->count == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (seq > replay->lastseq) {
|
|
|
|
/* larger sequences are okay */
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
/* seq is equal or less than lastseq. */
|
|
|
|
diff = replay->lastseq - seq;
|
|
|
|
|
|
|
|
/* over range to check, i.e. too old or wrapped */
|
|
|
|
if (diff >= wsizeb)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fr = frlast - diff / 8;
|
|
|
|
|
|
|
|
/* this packet already seen ? */
|
2003-10-08 18:26:08 +00:00
|
|
|
if (replay->bitmap[fr] & (1 << (diff % 8)))
|
1999-12-22 19:13:38 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* out of order but good */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
/*
|
|
|
|
* check replay counter whether to update or not.
|
|
|
|
* OUT: 0: OK
|
|
|
|
* 1: NG
|
2003-10-08 18:26:08 +00:00
|
|
|
* XXX need to update for 64bit sequence number - 2401bis
|
2000-07-04 16:35:15 +00:00
|
|
|
*/
|
1999-12-22 19:13:38 +00:00
|
|
|
int
|
|
|
|
ipsec_updatereplay(seq, sav)
|
|
|
|
u_int32_t seq;
|
|
|
|
struct secasvar *sav;
|
|
|
|
{
|
|
|
|
struct secreplay *replay;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
u_int64_t diff;
|
1999-12-22 19:13:38 +00:00
|
|
|
int fr;
|
|
|
|
u_int32_t wsizeb; /* constant: bits of window size */
|
|
|
|
int frlast; /* constant: last frame */
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (sav == NULL)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec_chkreplay: NULL pointer was passed.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
replay = sav->replay;
|
|
|
|
|
|
|
|
if (replay->wsize == 0)
|
|
|
|
goto ok; /* no need to check replay. */
|
|
|
|
|
|
|
|
/* constant */
|
|
|
|
frlast = replay->wsize - 1;
|
|
|
|
wsizeb = replay->wsize << 3;
|
|
|
|
|
|
|
|
/* sequence number of 0 is invalid */
|
|
|
|
if (seq == 0)
|
2000-07-04 16:35:15 +00:00
|
|
|
return 1;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* first time */
|
|
|
|
if (replay->count == 0) {
|
|
|
|
replay->lastseq = seq;
|
|
|
|
bzero(replay->bitmap, replay->wsize);
|
2003-10-08 18:26:08 +00:00
|
|
|
replay->bitmap[frlast] = 1;
|
1999-12-22 19:13:38 +00:00
|
|
|
goto ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seq > replay->lastseq) {
|
|
|
|
/* seq is larger than lastseq. */
|
|
|
|
diff = seq - replay->lastseq;
|
|
|
|
|
|
|
|
/* new larger sequence number */
|
|
|
|
if (diff < wsizeb) {
|
|
|
|
/* In window */
|
|
|
|
/* set bit for this packet */
|
|
|
|
vshiftl(replay->bitmap, diff, replay->wsize);
|
2003-10-08 18:26:08 +00:00
|
|
|
replay->bitmap[frlast] |= 1;
|
1999-12-22 19:13:38 +00:00
|
|
|
} else {
|
|
|
|
/* this packet has a "way larger" */
|
|
|
|
bzero(replay->bitmap, replay->wsize);
|
2003-10-08 18:26:08 +00:00
|
|
|
replay->bitmap[frlast] = 1;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
replay->lastseq = seq;
|
|
|
|
|
|
|
|
/* larger is good */
|
|
|
|
} else {
|
|
|
|
/* seq is equal or less than lastseq. */
|
|
|
|
diff = replay->lastseq - seq;
|
|
|
|
|
|
|
|
/* over range to check, i.e. too old or wrapped */
|
|
|
|
if (diff >= wsizeb)
|
2000-07-04 16:35:15 +00:00
|
|
|
return 1;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
fr = frlast - diff / 8;
|
|
|
|
|
|
|
|
/* this packet already seen ? */
|
2003-10-08 18:26:08 +00:00
|
|
|
if (replay->bitmap[fr] & (1 << (diff % 8)))
|
2000-07-04 16:35:15 +00:00
|
|
|
return 1;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* mark as seen */
|
2003-10-08 18:26:08 +00:00
|
|
|
replay->bitmap[fr] |= (1 << (diff % 8));
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
/* out of order but good */
|
|
|
|
}
|
|
|
|
|
|
|
|
ok:
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (replay->count == 0xffffffff) {
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
/* set overflow flag */
|
|
|
|
replay->overflow++;
|
|
|
|
|
|
|
|
/* don't increment, no more packets accepted */
|
|
|
|
if ((sav->flags & SADB_X_EXT_CYCSEQ) == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
ipseclog((LOG_WARNING, "replay counter made %d cycle. %s\n",
|
|
|
|
replay->overflow, ipsec_logsastr(sav)));
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
replay->count++;
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
return 0;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-04-19 04:46:24 +00:00
|
|
|
* shift variable length buffer to left.
|
1999-12-22 19:13:38 +00:00
|
|
|
* IN: bitmap: pointer to the buffer
|
|
|
|
* nbit: the number of to shift.
|
|
|
|
* wsize: buffer size (bytes).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vshiftl(bitmap, nbit, wsize)
|
|
|
|
unsigned char *bitmap;
|
|
|
|
int nbit, wsize;
|
|
|
|
{
|
|
|
|
int s, j, i;
|
|
|
|
unsigned char over;
|
|
|
|
|
|
|
|
for (j = 0; j < nbit; j += 8) {
|
|
|
|
s = (nbit - j < 8) ? (nbit - j): 8;
|
|
|
|
bitmap[0] <<= s;
|
|
|
|
for (i = 1; i < wsize; i++) {
|
|
|
|
over = (bitmap[i] >> (8 - s));
|
|
|
|
bitmap[i] <<= s;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
bitmap[i - 1] |= over;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
ipsec4_logpacketstr(ip, spi)
|
|
|
|
struct ip *ip;
|
|
|
|
u_int32_t spi;
|
|
|
|
{
|
|
|
|
static char buf[256];
|
|
|
|
char *p;
|
|
|
|
u_int8_t *s, *d;
|
|
|
|
|
|
|
|
s = (u_int8_t *)(&ip->ip_src);
|
|
|
|
d = (u_int8_t *)(&ip->ip_dst);
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
p = buf;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(buf, sizeof(buf), "packet(SPI=%u ", (u_int32_t)ntohl(spi));
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
2001-06-11 12:39:29 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf), "src=%u.%u.%u.%u",
|
1999-12-22 19:13:38 +00:00
|
|
|
s[0], s[1], s[2], s[3]);
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
2001-06-11 12:39:29 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf), " dst=%u.%u.%u.%u",
|
1999-12-22 19:13:38 +00:00
|
|
|
d[0], d[1], d[2], d[3]);
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf), ")");
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
const char *
|
|
|
|
ipsec6_logpacketstr(ip6, spi)
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
u_int32_t spi;
|
|
|
|
{
|
|
|
|
static char buf[256];
|
|
|
|
char *p;
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
p = buf;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(buf, sizeof(buf), "packet(SPI=%u ", (u_int32_t)ntohl(spi));
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf), "src=%s",
|
|
|
|
ip6_sprintf(&ip6->ip6_src));
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf), " dst=%s",
|
|
|
|
ip6_sprintf(&ip6->ip6_dst));
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf), ")");
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
2002-04-19 04:46:24 +00:00
|
|
|
#endif /* INET6 */
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
const char *
|
|
|
|
ipsec_logsastr(sav)
|
|
|
|
struct secasvar *sav;
|
|
|
|
{
|
|
|
|
static char buf[256];
|
|
|
|
char *p;
|
|
|
|
struct secasindex *saidx = &sav->sah->saidx;
|
|
|
|
|
|
|
|
/* validity check */
|
2000-07-04 16:35:15 +00:00
|
|
|
if (((struct sockaddr *)&sav->sah->saidx.src)->sa_family
|
|
|
|
!= ((struct sockaddr *)&sav->sah->saidx.dst)->sa_family)
|
2003-04-29 08:43:56 +00:00
|
|
|
panic("ipsec_logsastr: family mismatched.");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
p = buf;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(buf, sizeof(buf), "SA(SPI=%u ", (u_int32_t)ntohl(sav->spi));
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
|
|
|
if (((struct sockaddr *)&saidx->src)->sa_family == AF_INET) {
|
1999-12-22 19:13:38 +00:00
|
|
|
u_int8_t *s, *d;
|
|
|
|
s = (u_int8_t *)&((struct sockaddr_in *)&saidx->src)->sin_addr;
|
|
|
|
d = (u_int8_t *)&((struct sockaddr_in *)&saidx->dst)->sin_addr;
|
|
|
|
snprintf(p, sizeof(buf) - (p - buf),
|
|
|
|
"src=%d.%d.%d.%d dst=%d.%d.%d.%d",
|
|
|
|
s[0], s[1], s[2], s[3], d[0], d[1], d[2], d[3]);
|
|
|
|
}
|
|
|
|
#ifdef INET6
|
2000-07-04 16:35:15 +00:00
|
|
|
else if (((struct sockaddr *)&saidx->src)->sa_family == AF_INET6) {
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf),
|
|
|
|
"src=%s",
|
|
|
|
ip6_sprintf(&((struct sockaddr_in6 *)&saidx->src)->sin6_addr));
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf),
|
|
|
|
" dst=%s",
|
|
|
|
ip6_sprintf(&((struct sockaddr_in6 *)&saidx->dst)->sin6_addr));
|
|
|
|
}
|
|
|
|
#endif
|
2000-07-04 16:35:15 +00:00
|
|
|
while (p && *p)
|
|
|
|
p++;
|
1999-12-22 19:13:38 +00:00
|
|
|
snprintf(p, sizeof(buf) - (p - buf), ")");
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ipsec_dumpmbuf(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
int totlen;
|
|
|
|
int i;
|
|
|
|
u_char *p;
|
|
|
|
|
|
|
|
totlen = 0;
|
|
|
|
printf("---\n");
|
|
|
|
while (m) {
|
|
|
|
p = mtod(m, u_char *);
|
|
|
|
for (i = 0; i < m->m_len; i++) {
|
|
|
|
printf("%02x ", p[i]);
|
|
|
|
totlen++;
|
|
|
|
if (totlen % 16 == 0)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
m = m->m_next;
|
|
|
|
}
|
|
|
|
if (totlen % 16 != 0)
|
|
|
|
printf("\n");
|
|
|
|
printf("---\n");
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef INET
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
static int
|
|
|
|
ipsec4_checksa(isr, state)
|
|
|
|
struct ipsecrequest *isr;
|
|
|
|
struct ipsec_output_state *state;
|
|
|
|
{
|
|
|
|
struct ip *ip;
|
|
|
|
struct secasindex saidx;
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
/* make SA index for search proper SA */
|
|
|
|
ip = mtod(state->m, struct ip *);
|
|
|
|
bcopy(&isr->saidx, &saidx, sizeof(saidx));
|
|
|
|
saidx.mode = isr->saidx.mode;
|
|
|
|
saidx.reqid = isr->saidx.reqid;
|
|
|
|
sin = (struct sockaddr_in *)&saidx.src;
|
|
|
|
if (sin->sin_len == 0) {
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_port = IPSEC_PORT_ANY;
|
|
|
|
bcopy(&ip->ip_src, &sin->sin_addr, sizeof(sin->sin_addr));
|
|
|
|
}
|
|
|
|
sin = (struct sockaddr_in *)&saidx.dst;
|
|
|
|
if (sin->sin_len == 0) {
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_port = IPSEC_PORT_ANY;
|
|
|
|
bcopy(&ip->ip_dst, &sin->sin_addr, sizeof(sin->sin_addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
return key_checkrequest(isr, &saidx);
|
|
|
|
}
|
1999-12-22 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* IPsec output logic for IPv4.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipsec4_output(state, sp, flags)
|
|
|
|
struct ipsec_output_state *state;
|
|
|
|
struct secpolicy *sp;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct ip *ip = NULL;
|
|
|
|
struct ipsecrequest *isr = NULL;
|
|
|
|
int s;
|
|
|
|
int error;
|
|
|
|
struct sockaddr_in *dst4;
|
|
|
|
|
|
|
|
if (!state)
|
|
|
|
panic("state == NULL in ipsec4_output");
|
|
|
|
if (!state->m)
|
|
|
|
panic("state->m == NULL in ipsec4_output");
|
|
|
|
if (!state->ro)
|
|
|
|
panic("state->ro == NULL in ipsec4_output");
|
|
|
|
if (!state->dst)
|
|
|
|
panic("state->dst == NULL in ipsec4_output");
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
state->encap = 0;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DATA,
|
|
|
|
printf("ipsec4_output: applyed SP\n");
|
|
|
|
kdebug_secpolicy(sp));
|
|
|
|
|
|
|
|
for (isr = sp->req; isr != NULL; isr = isr->next) {
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
#if 0 /* give up to check restriction of transport mode */
|
|
|
|
/* XXX but should be checked somewhere */
|
|
|
|
/*
|
|
|
|
* some of the IPsec operation must be performed only in
|
|
|
|
* originating case.
|
|
|
|
*/
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TRANSPORT
|
|
|
|
&& (flags & IP_FORWARDING))
|
|
|
|
continue;
|
|
|
|
#endif
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
error = ipsec4_checksa(isr, state);
|
|
|
|
if (error != 0) {
|
1999-12-22 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* IPsec processing is required, but no SA found.
|
|
|
|
* I assume that key_acquire() had been called
|
|
|
|
* to get/establish the SA. Here I discard
|
|
|
|
* this packet because it is responsibility for
|
|
|
|
* upper layer to retransmit the packet.
|
|
|
|
*/
|
|
|
|
ipsecstat.out_nosa++;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* validity check */
|
|
|
|
if (isr->sav == NULL) {
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
switch (ipsec_get_reqlevel(isr, AF_INET)) {
|
1999-12-22 19:13:38 +00:00
|
|
|
case IPSEC_LEVEL_USE:
|
|
|
|
continue;
|
|
|
|
case IPSEC_LEVEL_REQUIRE:
|
|
|
|
/* must be not reached here. */
|
|
|
|
panic("ipsec4_output: no SA found, but required.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
/*
|
|
|
|
* If there is no valid SA, we give up to process any
|
|
|
|
* more. In such a case, the SA's status is changed
|
|
|
|
* from DYING to DEAD after allocating. If a packet
|
|
|
|
* send to the receiver by dead SA, the receiver can
|
|
|
|
* not decode a packet because SA has been dead.
|
|
|
|
*/
|
1999-12-22 19:13:38 +00:00
|
|
|
if (isr->sav->state != SADB_SASTATE_MATURE
|
|
|
|
&& isr->sav->state != SADB_SASTATE_DYING) {
|
|
|
|
ipsecstat.out_nosa++;
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There may be the case that SA status will be changed when
|
|
|
|
* we are refering to one. So calling splsoftnet().
|
|
|
|
*/
|
|
|
|
s = splnet();
|
|
|
|
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TUNNEL) {
|
|
|
|
/*
|
|
|
|
* build IPsec tunnel.
|
|
|
|
*/
|
|
|
|
/* XXX should be processed with other familiy */
|
2000-07-04 16:35:15 +00:00
|
|
|
if (((struct sockaddr *)&isr->sav->sah->saidx.src)->sa_family != AF_INET) {
|
|
|
|
ipseclog((LOG_ERR, "ipsec4_output: "
|
|
|
|
"family mismatched between inner and outer spi=%u\n",
|
|
|
|
(u_int32_t)ntohl(isr->sav->spi)));
|
1999-12-22 19:13:38 +00:00
|
|
|
splx(s);
|
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
state->m = ipsec4_splithdr(state->m);
|
|
|
|
if (!state->m) {
|
|
|
|
splx(s);
|
|
|
|
error = ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
error = ipsec4_encapsulate(state->m, isr->sav);
|
|
|
|
splx(s);
|
|
|
|
if (error) {
|
|
|
|
state->m = NULL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
ip = mtod(state->m, struct ip *);
|
|
|
|
|
|
|
|
state->ro = &isr->sav->sah->sa_route;
|
|
|
|
state->dst = (struct sockaddr *)&state->ro->ro_dst;
|
|
|
|
dst4 = (struct sockaddr_in *)state->dst;
|
|
|
|
if (state->ro->ro_rt
|
|
|
|
&& ((state->ro->ro_rt->rt_flags & RTF_UP) == 0
|
|
|
|
|| dst4->sin_addr.s_addr != ip->ip_dst.s_addr)) {
|
|
|
|
RTFREE(state->ro->ro_rt);
|
2001-06-11 12:39:29 +00:00
|
|
|
state->ro->ro_rt = NULL;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
if (state->ro->ro_rt == 0) {
|
|
|
|
dst4->sin_family = AF_INET;
|
|
|
|
dst4->sin_len = sizeof(*dst4);
|
|
|
|
dst4->sin_addr = ip->ip_dst;
|
|
|
|
rtalloc(state->ro);
|
|
|
|
}
|
|
|
|
if (state->ro->ro_rt == 0) {
|
|
|
|
ipstat.ips_noroute++;
|
|
|
|
error = EHOSTUNREACH;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2001-03-16 17:52:48 +00:00
|
|
|
/* adjust state->dst if tunnel endpoint is offlink */
|
1999-12-22 19:13:38 +00:00
|
|
|
if (state->ro->ro_rt->rt_flags & RTF_GATEWAY) {
|
|
|
|
state->dst = (struct sockaddr *)state->ro->ro_rt->rt_gateway;
|
|
|
|
dst4 = (struct sockaddr_in *)state->dst;
|
|
|
|
}
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
|
|
|
|
state->encap++;
|
1999-12-22 19:13:38 +00:00
|
|
|
} else
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
state->m = ipsec4_splithdr(state->m);
|
|
|
|
if (!state->m) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
switch (isr->saidx.proto) {
|
|
|
|
case IPPROTO_ESP:
|
|
|
|
#ifdef IPSEC_ESP
|
|
|
|
if ((error = esp4_output(state->m, isr)) != 0) {
|
|
|
|
state->m = NULL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
m_freem(state->m);
|
|
|
|
state->m = NULL;
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
#endif
|
|
|
|
case IPPROTO_AH:
|
|
|
|
if ((error = ah4_output(state->m, isr)) != 0) {
|
|
|
|
state->m = NULL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
case IPPROTO_IPCOMP:
|
|
|
|
if ((error = ipcomp4_output(state->m, isr)) != 0) {
|
|
|
|
state->m = NULL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
break;
|
1999-12-22 19:13:38 +00:00
|
|
|
default:
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR,
|
|
|
|
"ipsec4_output: unknown ipsec protocol %d\n",
|
|
|
|
isr->saidx.proto));
|
1999-12-22 19:13:38 +00:00
|
|
|
m_freem(state->m);
|
|
|
|
state->m = NULL;
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->m == 0) {
|
|
|
|
error = ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
ip = mtod(state->m, struct ip *);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(state->m);
|
|
|
|
state->m = NULL;
|
|
|
|
return error;
|
|
|
|
}
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
#ifdef INET6
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
static int
|
|
|
|
ipsec6_checksa(isr, state, tunnel)
|
|
|
|
struct ipsecrequest *isr;
|
|
|
|
struct ipsec_output_state *state;
|
|
|
|
int tunnel;
|
|
|
|
{
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
struct secasindex saidx;
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TUNNEL) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (!tunnel)
|
|
|
|
panic("ipsec6_checksa/inconsistent tunnel attribute");
|
|
|
|
#endif
|
|
|
|
/* When tunnel mode, SA peers must be specified. */
|
|
|
|
return key_checkrequest(isr, &isr->saidx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make SA index for search proper SA */
|
|
|
|
ip6 = mtod(state->m, struct ip6_hdr *);
|
|
|
|
if (tunnel) {
|
|
|
|
bzero(&saidx, sizeof(saidx));
|
|
|
|
saidx.proto = isr->saidx.proto;
|
|
|
|
} else
|
|
|
|
bcopy(&isr->saidx, &saidx, sizeof(saidx));
|
|
|
|
saidx.mode = isr->saidx.mode;
|
|
|
|
saidx.reqid = isr->saidx.reqid;
|
|
|
|
sin6 = (struct sockaddr_in6 *)&saidx.src;
|
|
|
|
if (sin6->sin6_len == 0 || tunnel) {
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_port = IPSEC_PORT_ANY;
|
|
|
|
in6_recoverscope(sin6, &ip6->ip6_src, NULL);
|
|
|
|
}
|
|
|
|
sin6 = (struct sockaddr_in6 *)&saidx.dst;
|
|
|
|
if (sin6->sin6_len == 0 || tunnel) {
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_port = IPSEC_PORT_ANY;
|
|
|
|
in6_recoverscope(sin6, &ip6->ip6_dst, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return key_checkrequest(isr, &saidx);
|
|
|
|
}
|
|
|
|
|
1999-12-22 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* IPsec output logic for IPv6, transport mode.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipsec6_output_trans(state, nexthdrp, mprev, sp, flags, tun)
|
|
|
|
struct ipsec_output_state *state;
|
|
|
|
u_char *nexthdrp;
|
|
|
|
struct mbuf *mprev;
|
|
|
|
struct secpolicy *sp;
|
|
|
|
int flags;
|
|
|
|
int *tun;
|
|
|
|
{
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
struct ipsecrequest *isr = NULL;
|
|
|
|
int error = 0;
|
|
|
|
int plen;
|
|
|
|
|
|
|
|
if (!state)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("state == NULL in ipsec6_output_trans");
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!state->m)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("state->m == NULL in ipsec6_output_trans");
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!nexthdrp)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("nexthdrp == NULL in ipsec6_output_trans");
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!mprev)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("mprev == NULL in ipsec6_output_trans");
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!sp)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("sp == NULL in ipsec6_output_trans");
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!tun)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("tun == NULL in ipsec6_output_trans");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DATA,
|
|
|
|
printf("ipsec6_output_trans: applyed SP\n");
|
|
|
|
kdebug_secpolicy(sp));
|
|
|
|
|
|
|
|
*tun = 0;
|
|
|
|
for (isr = sp->req; isr; isr = isr->next) {
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TUNNEL) {
|
|
|
|
/* the rest will be handled by ipsec6_output_tunnel() */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
error = ipsec6_checksa(isr, state, 0);
|
|
|
|
if (error == EIO)
|
|
|
|
goto bad;
|
|
|
|
if (error == ENOENT) {
|
1999-12-22 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* IPsec processing is required, but no SA found.
|
|
|
|
* I assume that key_acquire() had been called
|
|
|
|
* to get/establish the SA. Here I discard
|
|
|
|
* this packet because it is responsibility for
|
|
|
|
* upper layer to retransmit the packet.
|
|
|
|
*/
|
|
|
|
ipsec6stat.out_nosa++;
|
2001-06-11 12:39:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify the fact that the packet is discarded
|
|
|
|
* to ourselves. I believe this is better than
|
|
|
|
* just silently discarding. (jinmei@kame.net)
|
|
|
|
* XXX: should we restrict the error to TCP packets?
|
|
|
|
* XXX: should we directly notify sockets via
|
|
|
|
* pfctlinputs?
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
*
|
|
|
|
* Noone have initialized rcvif until this point,
|
|
|
|
* so clear it.
|
2001-06-11 12:39:29 +00:00
|
|
|
*/
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if ((state->m->m_flags & M_PKTHDR) != 0)
|
|
|
|
state->m->m_pkthdr.rcvif = NULL;
|
2001-06-11 12:39:29 +00:00
|
|
|
icmp6_error(state->m, ICMP6_DST_UNREACH,
|
|
|
|
ICMP6_DST_UNREACH_ADMIN, 0);
|
|
|
|
state->m = NULL; /* icmp6_error freed the mbuf */
|
1999-12-22 19:13:38 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* validity check */
|
|
|
|
if (isr->sav == NULL) {
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
switch (ipsec_get_reqlevel(isr, AF_INET6)) {
|
1999-12-22 19:13:38 +00:00
|
|
|
case IPSEC_LEVEL_USE:
|
|
|
|
continue;
|
|
|
|
case IPSEC_LEVEL_REQUIRE:
|
|
|
|
/* must be not reached here. */
|
|
|
|
panic("ipsec6_output_trans: no SA found, but required.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
/*
|
|
|
|
* If there is no valid SA, we give up to process.
|
|
|
|
* see same place at ipsec4_output().
|
|
|
|
*/
|
1999-12-22 19:13:38 +00:00
|
|
|
if (isr->sav->state != SADB_SASTATE_MATURE
|
|
|
|
&& isr->sav->state != SADB_SASTATE_DYING) {
|
|
|
|
ipsec6stat.out_nosa++;
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (isr->saidx.proto) {
|
|
|
|
case IPPROTO_ESP:
|
|
|
|
#ifdef IPSEC_ESP
|
|
|
|
error = esp6_output(state->m, nexthdrp, mprev->m_next, isr);
|
|
|
|
#else
|
|
|
|
m_freem(state->m);
|
|
|
|
error = EINVAL;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case IPPROTO_AH:
|
|
|
|
error = ah6_output(state->m, nexthdrp, mprev->m_next, isr);
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
case IPPROTO_IPCOMP:
|
|
|
|
error = ipcomp6_output(state->m, nexthdrp, mprev->m_next, isr);
|
|
|
|
break;
|
1999-12-22 19:13:38 +00:00
|
|
|
default:
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec6_output_trans: "
|
|
|
|
"unknown ipsec protocol %d\n", isr->saidx.proto));
|
1999-12-22 19:13:38 +00:00
|
|
|
m_freem(state->m);
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec6stat.out_inval++;
|
1999-12-22 19:13:38 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
state->m = NULL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
plen = state->m->m_pkthdr.len - sizeof(struct ip6_hdr);
|
|
|
|
if (plen > IPV6_MAXPACKET) {
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec6_output_trans: "
|
|
|
|
"IPsec with IPv6 jumbogram is not supported\n"));
|
1999-12-22 19:13:38 +00:00
|
|
|
ipsec6stat.out_inval++;
|
2002-04-19 04:46:24 +00:00
|
|
|
error = EINVAL; /* XXX */
|
1999-12-22 19:13:38 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
ip6 = mtod(state->m, struct ip6_hdr *);
|
|
|
|
ip6->ip6_plen = htons(plen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we have more to go, we need a tunnel mode processing */
|
|
|
|
if (isr != NULL)
|
|
|
|
*tun = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(state->m);
|
|
|
|
state->m = NULL;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPsec output logic for IPv6, tunnel mode.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ipsec6_output_tunnel(state, sp, flags)
|
|
|
|
struct ipsec_output_state *state;
|
|
|
|
struct secpolicy *sp;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
struct ipsecrequest *isr = NULL;
|
|
|
|
int error = 0;
|
|
|
|
int plen;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct sockaddr_in6 *dst6;
|
1999-12-22 19:13:38 +00:00
|
|
|
int s;
|
|
|
|
|
|
|
|
if (!state)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("state == NULL in ipsec6_output_tunnel");
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!state->m)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("state->m == NULL in ipsec6_output_tunnel");
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!sp)
|
2002-04-19 04:46:24 +00:00
|
|
|
panic("sp == NULL in ipsec6_output_tunnel");
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
KEYDEBUG(KEYDEBUG_IPSEC_DATA,
|
|
|
|
printf("ipsec6_output_tunnel: applyed SP\n");
|
|
|
|
kdebug_secpolicy(sp));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* transport mode ipsec (before the 1st tunnel mode) is already
|
|
|
|
* processed by ipsec6_output_trans().
|
|
|
|
*/
|
|
|
|
for (isr = sp->req; isr; isr = isr->next) {
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TUNNEL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-10-17 13:03:37 +00:00
|
|
|
for (/* already initialized */; isr; isr = isr->next) {
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
error = ipsec6_checksa(isr, state, 1);
|
|
|
|
if (error == EIO)
|
|
|
|
goto bad;
|
|
|
|
if (error == ENOENT) {
|
1999-12-22 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* IPsec processing is required, but no SA found.
|
|
|
|
* I assume that key_acquire() had been called
|
|
|
|
* to get/establish the SA. Here I discard
|
|
|
|
* this packet because it is responsibility for
|
|
|
|
* upper layer to retransmit the packet.
|
|
|
|
*/
|
|
|
|
ipsec6stat.out_nosa++;
|
|
|
|
error = ENOENT;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* validity check */
|
|
|
|
if (isr->sav == NULL) {
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
switch (ipsec_get_reqlevel(isr, AF_INET6)) {
|
1999-12-22 19:13:38 +00:00
|
|
|
case IPSEC_LEVEL_USE:
|
|
|
|
continue;
|
|
|
|
case IPSEC_LEVEL_REQUIRE:
|
|
|
|
/* must be not reached here. */
|
|
|
|
panic("ipsec6_output_tunnel: no SA found, but required.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
/*
|
|
|
|
* If there is no valid SA, we give up to process.
|
|
|
|
* see same place at ipsec4_output().
|
|
|
|
*/
|
1999-12-22 19:13:38 +00:00
|
|
|
if (isr->sav->state != SADB_SASTATE_MATURE
|
|
|
|
&& isr->sav->state != SADB_SASTATE_DYING) {
|
|
|
|
ipsec6stat.out_nosa++;
|
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There may be the case that SA status will be changed when
|
|
|
|
* we are refering to one. So calling splsoftnet().
|
|
|
|
*/
|
|
|
|
s = splnet();
|
|
|
|
|
|
|
|
if (isr->saidx.mode == IPSEC_MODE_TUNNEL) {
|
|
|
|
/*
|
|
|
|
* build IPsec tunnel.
|
|
|
|
*/
|
|
|
|
/* XXX should be processed with other familiy */
|
2000-07-04 16:35:15 +00:00
|
|
|
if (((struct sockaddr *)&isr->sav->sah->saidx.src)->sa_family != AF_INET6) {
|
|
|
|
ipseclog((LOG_ERR, "ipsec6_output_tunnel: "
|
|
|
|
"family mismatched between inner and outer, spi=%u\n",
|
|
|
|
(u_int32_t)ntohl(isr->sav->spi)));
|
1999-12-22 19:13:38 +00:00
|
|
|
splx(s);
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec6stat.out_inval++;
|
1999-12-22 19:13:38 +00:00
|
|
|
error = EAFNOSUPPORT;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
state->m = ipsec6_splithdr(state->m);
|
|
|
|
if (!state->m) {
|
|
|
|
splx(s);
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec6stat.out_nomem++;
|
1999-12-22 19:13:38 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
error = ipsec6_encapsulate(state->m, isr->sav);
|
|
|
|
splx(s);
|
|
|
|
if (error) {
|
|
|
|
state->m = 0;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
ip6 = mtod(state->m, struct ip6_hdr *);
|
|
|
|
|
|
|
|
state->ro = &isr->sav->sah->sa_route;
|
|
|
|
state->dst = (struct sockaddr *)&state->ro->ro_dst;
|
|
|
|
dst6 = (struct sockaddr_in6 *)state->dst;
|
2003-10-08 18:26:08 +00:00
|
|
|
if (state->ro->ro_rt &&
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
(!(state->ro->ro_rt->rt_flags & RTF_UP) ||
|
2003-10-08 18:26:08 +00:00
|
|
|
!IN6_ARE_ADDR_EQUAL(&dst6->sin6_addr,
|
|
|
|
&ip6->ip6_dst))) {
|
1999-12-22 19:13:38 +00:00
|
|
|
RTFREE(state->ro->ro_rt);
|
2001-06-11 12:39:29 +00:00
|
|
|
state->ro->ro_rt = NULL;
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
if (state->ro->ro_rt == 0) {
|
|
|
|
bzero(dst6, sizeof(*dst6));
|
|
|
|
dst6->sin6_family = AF_INET6;
|
|
|
|
dst6->sin6_len = sizeof(*dst6);
|
|
|
|
dst6->sin6_addr = ip6->ip6_dst;
|
|
|
|
rtalloc(state->ro);
|
|
|
|
}
|
|
|
|
if (state->ro->ro_rt == 0) {
|
|
|
|
ip6stat.ip6s_noroute++;
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec6stat.out_noroute++;
|
1999-12-22 19:13:38 +00:00
|
|
|
error = EHOSTUNREACH;
|
|
|
|
goto bad;
|
|
|
|
}
|
2001-03-16 17:52:48 +00:00
|
|
|
|
|
|
|
/* adjust state->dst if tunnel endpoint is offlink */
|
2000-07-04 16:35:15 +00:00
|
|
|
if (state->ro->ro_rt->rt_flags & RTF_GATEWAY) {
|
|
|
|
state->dst = (struct sockaddr *)state->ro->ro_rt->rt_gateway;
|
|
|
|
dst6 = (struct sockaddr_in6 *)state->dst;
|
|
|
|
}
|
1999-12-22 19:13:38 +00:00
|
|
|
} else
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
state->m = ipsec6_splithdr(state->m);
|
|
|
|
if (!state->m) {
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec6stat.out_nomem++;
|
1999-12-22 19:13:38 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
ip6 = mtod(state->m, struct ip6_hdr *);
|
|
|
|
switch (isr->saidx.proto) {
|
|
|
|
case IPPROTO_ESP:
|
|
|
|
#ifdef IPSEC_ESP
|
2003-10-08 18:26:08 +00:00
|
|
|
error = esp6_output(state->m, &ip6->ip6_nxt,
|
|
|
|
state->m->m_next, isr);
|
1999-12-22 19:13:38 +00:00
|
|
|
#else
|
|
|
|
m_freem(state->m);
|
|
|
|
error = EINVAL;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case IPPROTO_AH:
|
2003-10-08 18:26:08 +00:00
|
|
|
error = ah6_output(state->m, &ip6->ip6_nxt,
|
|
|
|
state->m->m_next, isr);
|
1999-12-22 19:13:38 +00:00
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
case IPPROTO_IPCOMP:
|
|
|
|
/* XXX code should be here */
|
2002-04-19 04:46:24 +00:00
|
|
|
/* FALLTHROUGH */
|
1999-12-22 19:13:38 +00:00
|
|
|
default:
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec6_output_tunnel: "
|
|
|
|
"unknown ipsec protocol %d\n", isr->saidx.proto));
|
1999-12-22 19:13:38 +00:00
|
|
|
m_freem(state->m);
|
2000-07-04 16:35:15 +00:00
|
|
|
ipsec6stat.out_inval++;
|
1999-12-22 19:13:38 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
state->m = NULL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
plen = state->m->m_pkthdr.len - sizeof(struct ip6_hdr);
|
|
|
|
if (plen > IPV6_MAXPACKET) {
|
2000-07-04 16:35:15 +00:00
|
|
|
ipseclog((LOG_ERR, "ipsec6_output_tunnel: "
|
|
|
|
"IPsec with IPv6 jumbogram is not supported\n"));
|
1999-12-22 19:13:38 +00:00
|
|
|
ipsec6stat.out_inval++;
|
2002-04-19 04:46:24 +00:00
|
|
|
error = EINVAL; /* XXX */
|
1999-12-22 19:13:38 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
ip6 = mtod(state->m, struct ip6_hdr *);
|
|
|
|
ip6->ip6_plen = htons(plen);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(state->m);
|
|
|
|
state->m = NULL;
|
|
|
|
return error;
|
|
|
|
}
|
2002-04-19 04:46:24 +00:00
|
|
|
#endif /* INET6 */
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef INET
|
1999-12-22 19:13:38 +00:00
|
|
|
/*
|
|
|
|
* Chop IP header and option off from the payload.
|
|
|
|
*/
|
|
|
|
static struct mbuf *
|
|
|
|
ipsec4_splithdr(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct mbuf *mh;
|
|
|
|
struct ip *ip;
|
|
|
|
int hlen;
|
|
|
|
|
|
|
|
if (m->m_len < sizeof(struct ip))
|
|
|
|
panic("ipsec4_splithdr: first mbuf too short");
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
#ifdef _IP_VHL
|
|
|
|
hlen = _IP_VHL_HL(ip->ip_vhl) << 2;
|
|
|
|
#else
|
|
|
|
hlen = ip->ip_hl << 2;
|
|
|
|
#endif
|
|
|
|
if (m->m_len > hlen) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(mh, M_DONTWAIT, MT_HEADER);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!mh) {
|
|
|
|
m_freem(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-12-30 20:22:40 +00:00
|
|
|
M_MOVE_PKTHDR(mh, m);
|
1999-12-22 19:13:38 +00:00
|
|
|
MH_ALIGN(mh, hlen);
|
|
|
|
m->m_len -= hlen;
|
|
|
|
m->m_data += hlen;
|
|
|
|
mh->m_next = m;
|
|
|
|
m = mh;
|
|
|
|
m->m_len = hlen;
|
|
|
|
bcopy((caddr_t)ip, mtod(m, caddr_t), hlen);
|
|
|
|
} else if (m->m_len < hlen) {
|
|
|
|
m = m_pullup(m, hlen);
|
|
|
|
if (!m)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
static struct mbuf *
|
|
|
|
ipsec6_splithdr(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct mbuf *mh;
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
int hlen;
|
|
|
|
|
|
|
|
if (m->m_len < sizeof(struct ip6_hdr))
|
|
|
|
panic("ipsec6_splithdr: first mbuf too short");
|
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
|
|
|
hlen = sizeof(struct ip6_hdr);
|
|
|
|
if (m->m_len > hlen) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(mh, M_DONTWAIT, MT_HEADER);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!mh) {
|
|
|
|
m_freem(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-12-30 20:22:40 +00:00
|
|
|
M_MOVE_PKTHDR(mh, m);
|
1999-12-22 19:13:38 +00:00
|
|
|
MH_ALIGN(mh, hlen);
|
|
|
|
m->m_len -= hlen;
|
|
|
|
m->m_data += hlen;
|
|
|
|
mh->m_next = m;
|
|
|
|
m = mh;
|
|
|
|
m->m_len = hlen;
|
|
|
|
bcopy((caddr_t)ip6, mtod(m, caddr_t), hlen);
|
|
|
|
} else if (m->m_len < hlen) {
|
|
|
|
m = m_pullup(m, hlen);
|
|
|
|
if (!m)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* validate inbound IPsec tunnel packet. */
|
|
|
|
int
|
2001-06-11 12:39:29 +00:00
|
|
|
ipsec4_tunnel_validate(m, off, nxt0, sav)
|
|
|
|
struct mbuf *m; /* no pullup permitted, m->m_len >= ip */
|
|
|
|
int off;
|
1999-12-22 19:13:38 +00:00
|
|
|
u_int nxt0;
|
|
|
|
struct secasvar *sav;
|
|
|
|
{
|
|
|
|
u_int8_t nxt = nxt0 & 0xff;
|
|
|
|
struct sockaddr_in *sin;
|
2001-06-11 12:39:29 +00:00
|
|
|
struct sockaddr_in osrc, odst, isrc, idst;
|
1999-12-22 19:13:38 +00:00
|
|
|
int hlen;
|
2001-06-11 12:39:29 +00:00
|
|
|
struct secpolicy *sp;
|
|
|
|
struct ip *oip;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (m->m_len < sizeof(struct ip))
|
|
|
|
panic("too short mbuf on ipsec4_tunnel_validate");
|
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
if (nxt != IPPROTO_IPV4)
|
|
|
|
return 0;
|
2001-06-11 12:39:29 +00:00
|
|
|
if (m->m_pkthdr.len < off + sizeof(struct ip))
|
|
|
|
return 0;
|
|
|
|
/* do not decapsulate if the SA is for transport mode only */
|
|
|
|
if (sav->sah->saidx.mode == IPSEC_MODE_TRANSPORT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
oip = mtod(m, struct ip *);
|
|
|
|
hlen = oip->ip_hl << 2;
|
1999-12-22 19:13:38 +00:00
|
|
|
if (hlen != sizeof(struct ip))
|
|
|
|
return 0;
|
2001-06-11 12:39:29 +00:00
|
|
|
|
|
|
|
/* AF_INET6 should be supported, but at this moment we don't. */
|
|
|
|
sin = (struct sockaddr_in *)&sav->sah->saidx.dst;
|
|
|
|
if (sin->sin_family != AF_INET)
|
1999-12-22 19:13:38 +00:00
|
|
|
return 0;
|
2001-06-11 12:39:29 +00:00
|
|
|
if (bcmp(&oip->ip_dst, &sin->sin_addr, sizeof(oip->ip_dst)) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* XXX slow */
|
|
|
|
bzero(&osrc, sizeof(osrc));
|
|
|
|
bzero(&odst, sizeof(odst));
|
|
|
|
bzero(&isrc, sizeof(isrc));
|
|
|
|
bzero(&idst, sizeof(idst));
|
2003-10-08 18:26:08 +00:00
|
|
|
osrc.sin_family = odst.sin_family = isrc.sin_family = idst.sin_family =
|
2001-06-11 12:39:29 +00:00
|
|
|
AF_INET;
|
2003-10-08 18:26:08 +00:00
|
|
|
osrc.sin_len = odst.sin_len = isrc.sin_len = idst.sin_len =
|
2001-06-11 12:39:29 +00:00
|
|
|
sizeof(struct sockaddr_in);
|
|
|
|
osrc.sin_addr = oip->ip_src;
|
|
|
|
odst.sin_addr = oip->ip_dst;
|
|
|
|
m_copydata(m, off + offsetof(struct ip, ip_src), sizeof(isrc.sin_addr),
|
|
|
|
(caddr_t)&isrc.sin_addr);
|
|
|
|
m_copydata(m, off + offsetof(struct ip, ip_dst), sizeof(idst.sin_addr),
|
|
|
|
(caddr_t)&idst.sin_addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RFC2401 5.2.1 (b): (assume that we are using tunnel mode)
|
|
|
|
* - if the inner destination is multicast address, there can be
|
|
|
|
* multiple permissible inner source address. implementation
|
|
|
|
* may want to skip verification of inner source address against
|
|
|
|
* SPD selector.
|
|
|
|
* - if the inner protocol is ICMP, the packet may be an error report
|
|
|
|
* from routers on the other side of the VPN cloud (R in the
|
|
|
|
* following diagram). in this case, we cannot verify inner source
|
|
|
|
* address against SPD selector.
|
|
|
|
* me -- gw === gw -- R -- you
|
|
|
|
*
|
|
|
|
* we consider the first bullet to be users responsibility on SPD entry
|
|
|
|
* configuration (if you need to encrypt multicast traffic, set
|
|
|
|
* the source range of SPD selector to 0.0.0.0/0, or have explicit
|
|
|
|
* address ranges for possible senders).
|
|
|
|
* the second bullet is not taken care of (yet).
|
|
|
|
*
|
|
|
|
* therefore, we do not do anything special about inner source.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sp = key_gettunnel((struct sockaddr *)&osrc, (struct sockaddr *)&odst,
|
|
|
|
(struct sockaddr *)&isrc, (struct sockaddr *)&idst);
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
/*
|
|
|
|
* when there is no suitable inbound policy for the packet of the ipsec
|
|
|
|
* tunnel mode, the kernel never decapsulate the tunneled packet
|
|
|
|
* as the ipsec tunnel mode even when the system wide policy is "none".
|
|
|
|
* then the kernel leaves the generic tunnel module to process this
|
|
|
|
* packet. if there is no rule of the generic tunnel, the packet
|
|
|
|
* is rejected and the statistics will be counted up.
|
|
|
|
*/
|
2001-06-11 12:39:29 +00:00
|
|
|
if (!sp)
|
|
|
|
return 0;
|
|
|
|
key_freesp(sp);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
/* validate inbound IPsec tunnel packet. */
|
|
|
|
int
|
2001-06-11 12:39:29 +00:00
|
|
|
ipsec6_tunnel_validate(m, off, nxt0, sav)
|
|
|
|
struct mbuf *m; /* no pullup permitted, m->m_len >= ip */
|
|
|
|
int off;
|
1999-12-22 19:13:38 +00:00
|
|
|
u_int nxt0;
|
|
|
|
struct secasvar *sav;
|
|
|
|
{
|
|
|
|
u_int8_t nxt = nxt0 & 0xff;
|
|
|
|
struct sockaddr_in6 *sin6;
|
2001-06-11 12:39:29 +00:00
|
|
|
struct sockaddr_in6 osrc, odst, isrc, idst;
|
|
|
|
struct secpolicy *sp;
|
|
|
|
struct ip6_hdr *oip6;
|
1999-12-22 19:13:38 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (m->m_len < sizeof(struct ip6_hdr))
|
|
|
|
panic("too short mbuf on ipsec6_tunnel_validate");
|
|
|
|
#endif
|
1999-12-22 19:13:38 +00:00
|
|
|
if (nxt != IPPROTO_IPV6)
|
|
|
|
return 0;
|
2001-06-11 12:39:29 +00:00
|
|
|
if (m->m_pkthdr.len < off + sizeof(struct ip6_hdr))
|
|
|
|
return 0;
|
|
|
|
/* do not decapsulate if the SA is for transport mode only */
|
|
|
|
if (sav->sah->saidx.mode == IPSEC_MODE_TRANSPORT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
oip6 = mtod(m, struct ip6_hdr *);
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/* AF_INET should be supported, but at this moment we don't. */
|
|
|
|
sin6 = (struct sockaddr_in6 *)&sav->sah->saidx.dst;
|
|
|
|
if (sin6->sin6_family != AF_INET6)
|
|
|
|
return 0;
|
|
|
|
if (!IN6_ARE_ADDR_EQUAL(&oip6->ip6_dst, &sin6->sin6_addr))
|
1999-12-22 19:13:38 +00:00
|
|
|
return 0;
|
2001-06-11 12:39:29 +00:00
|
|
|
|
|
|
|
/* XXX slow */
|
|
|
|
bzero(&osrc, sizeof(osrc));
|
|
|
|
bzero(&odst, sizeof(odst));
|
|
|
|
bzero(&isrc, sizeof(isrc));
|
|
|
|
bzero(&idst, sizeof(idst));
|
|
|
|
osrc.sin6_family = odst.sin6_family = isrc.sin6_family =
|
|
|
|
idst.sin6_family = AF_INET6;
|
|
|
|
osrc.sin6_len = odst.sin6_len = isrc.sin6_len = idst.sin6_len =
|
|
|
|
sizeof(struct sockaddr_in6);
|
|
|
|
osrc.sin6_addr = oip6->ip6_src;
|
|
|
|
odst.sin6_addr = oip6->ip6_dst;
|
|
|
|
m_copydata(m, off + offsetof(struct ip6_hdr, ip6_src),
|
|
|
|
sizeof(isrc.sin6_addr), (caddr_t)&isrc.sin6_addr);
|
|
|
|
m_copydata(m, off + offsetof(struct ip6_hdr, ip6_dst),
|
|
|
|
sizeof(idst.sin6_addr), (caddr_t)&idst.sin6_addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* regarding to inner source address validation, see a long comment
|
|
|
|
* in ipsec4_tunnel_validate.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sp = key_gettunnel((struct sockaddr *)&osrc, (struct sockaddr *)&odst,
|
|
|
|
(struct sockaddr *)&isrc, (struct sockaddr *)&idst);
|
|
|
|
if (!sp)
|
|
|
|
return 0;
|
|
|
|
key_freesp(sp);
|
1999-12-22 19:13:38 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make a mbuf chain for encryption.
|
|
|
|
* If the original mbuf chain contains a mbuf with a cluster,
|
|
|
|
* allocate a new cluster and copy the data to the new cluster.
|
|
|
|
* XXX: this hack is inefficient, but is necessary to handle cases
|
|
|
|
* of TCP retransmission...
|
|
|
|
*/
|
|
|
|
struct mbuf *
|
|
|
|
ipsec_copypkt(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct mbuf *n, **mpp, *mnew;
|
|
|
|
|
|
|
|
for (n = m, mpp = &m; n; n = n->m_next) {
|
|
|
|
if (n->m_flags & M_EXT) {
|
|
|
|
/*
|
2003-10-08 18:26:08 +00:00
|
|
|
* Make a copy only if there is more than one
|
2000-11-11 23:07:38 +00:00
|
|
|
* references to the cluster.
|
1999-12-22 19:13:38 +00:00
|
|
|
* XXX: is this approach effective?
|
|
|
|
*/
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
if (!M_WRITABLE(n)) {
|
1999-12-22 19:13:38 +00:00
|
|
|
int remain, copied;
|
|
|
|
struct mbuf *mm;
|
|
|
|
|
|
|
|
if (n->m_flags & M_PKTHDR) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(mnew, M_DONTWAIT, MT_HEADER);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (mnew == NULL)
|
|
|
|
goto fail;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
mnew->m_pkthdr = n->m_pkthdr;
|
|
|
|
#if 0
|
|
|
|
/* XXX: convert to m_tag or delete? */
|
|
|
|
if (n->m_pkthdr.aux) {
|
|
|
|
mnew->m_pkthdr.aux =
|
|
|
|
m_copym(n->m_pkthdr.aux,
|
|
|
|
0, M_COPYALL, M_DONTWAIT);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
#endif
|
|
|
|
M_MOVE_PKTHDR(mnew, n);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-02-19 05:47:46 +00:00
|
|
|
MGET(mnew, M_DONTWAIT, MT_DATA);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (mnew == NULL)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
mnew->m_len = 0;
|
|
|
|
mm = mnew;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy data. If we don't have enough space to
|
|
|
|
* store the whole data, allocate a cluster
|
|
|
|
* or additional mbufs.
|
|
|
|
* XXX: we don't use m_copyback(), since the
|
|
|
|
* function does not use clusters and thus is
|
|
|
|
* inefficient.
|
|
|
|
*/
|
|
|
|
remain = n->m_len;
|
|
|
|
copied = 0;
|
2001-06-11 12:39:29 +00:00
|
|
|
while (1) {
|
1999-12-22 19:13:38 +00:00
|
|
|
int len;
|
|
|
|
struct mbuf *mn;
|
|
|
|
|
|
|
|
if (remain <= (mm->m_flags & M_PKTHDR ? MHLEN : MLEN))
|
|
|
|
len = remain;
|
|
|
|
else { /* allocate a cluster */
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(mm, M_DONTWAIT);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (!(mm->m_flags & M_EXT)) {
|
|
|
|
m_free(mm);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
len = remain < MCLBYTES ?
|
|
|
|
remain : MCLBYTES;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy(n->m_data + copied, mm->m_data,
|
|
|
|
len);
|
|
|
|
|
|
|
|
copied += len;
|
|
|
|
remain -= len;
|
|
|
|
mm->m_len = len;
|
|
|
|
|
|
|
|
if (remain <= 0) /* completed? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* need another mbuf */
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(mn, M_DONTWAIT, MT_HEADER);
|
1999-12-22 19:13:38 +00:00
|
|
|
if (mn == NULL)
|
|
|
|
goto fail;
|
2001-06-11 12:39:29 +00:00
|
|
|
mn->m_pkthdr.rcvif = NULL;
|
1999-12-22 19:13:38 +00:00
|
|
|
mm->m_next = mn;
|
|
|
|
mm = mn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adjust chain */
|
|
|
|
mm->m_next = m_free(n);
|
|
|
|
n = mm;
|
|
|
|
*mpp = mnew;
|
|
|
|
mpp = &n->m_next;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*mpp = n;
|
|
|
|
mpp = &n->m_next;
|
|
|
|
}
|
|
|
|
|
2003-10-06 14:02:09 +00:00
|
|
|
return (m);
|
1999-12-22 19:13:38 +00:00
|
|
|
fail:
|
|
|
|
m_freem(m);
|
2003-10-06 14:02:09 +00:00
|
|
|
return (NULL);
|
1999-12-22 19:13:38 +00:00
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
static struct ipsecaux *
|
|
|
|
ipsec_addaux(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct m_tag *mtag;
|
|
|
|
|
|
|
|
mtag = m_tag_find(m, PACKET_TAG_IPSEC_HISTORY, NULL);
|
|
|
|
if (mtag == NULL) {
|
|
|
|
mtag = m_tag_get(PACKET_TAG_IPSEC_HISTORY,
|
|
|
|
sizeof(struct ipsecaux), M_NOWAIT);
|
|
|
|
if (mtag != NULL)
|
|
|
|
m_tag_prepend(m, mtag);
|
|
|
|
}
|
|
|
|
if (mtag == NULL)
|
|
|
|
return NULL; /* ENOBUFS */
|
|
|
|
/* XXX is this necessary? */
|
|
|
|
bzero((void *)(mtag + 1), sizeof(struct ipsecaux));
|
|
|
|
return mtag ? (struct ipsecaux *)(mtag + 1) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ipsecaux *
|
|
|
|
ipsec_findaux(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct m_tag *mtag;
|
|
|
|
|
|
|
|
mtag = m_tag_find(m, PACKET_TAG_IPSEC_HISTORY, NULL);
|
|
|
|
return mtag ? (struct ipsecaux *)(mtag + 1) : NULL;
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
void
|
2001-06-11 12:39:29 +00:00
|
|
|
ipsec_delaux(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
2003-10-08 18:26:08 +00:00
|
|
|
struct m_tag *mtag;
|
2001-06-11 12:39:29 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
mtag = m_tag_find(m, PACKET_TAG_IPSEC_HISTORY, NULL);
|
|
|
|
if (mtag != NULL)
|
2003-10-08 18:26:08 +00:00
|
|
|
m_tag_delete(m, mtag);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
2001-06-11 12:39:29 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
/* if the aux buffer is unnecessary, nuke it. */
|
|
|
|
static void
|
|
|
|
ipsec_optaux(m, aux)
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ipsecaux *aux;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (aux == NULL)
|
|
|
|
return;
|
2004-02-03 18:20:55 +00:00
|
|
|
ipsec_delaux(m);
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
int
|
|
|
|
ipsec_addhist(m, proto, spi)
|
|
|
|
struct mbuf *m;
|
|
|
|
int proto;
|
|
|
|
u_int32_t spi;
|
|
|
|
{
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
struct ipsecaux *aux;
|
2001-06-11 12:39:29 +00:00
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
aux = ipsec_addaux(m);
|
|
|
|
if (aux == NULL)
|
2001-06-11 12:39:29 +00:00
|
|
|
return ENOBUFS;
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
aux->hdrs++;
|
2001-06-11 12:39:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
- cleanup SP refcnt issue.
- share policy-on-socket for listening socket.
- don't copy policy-on-socket at all. secpolicy no longer contain
spidx, which saves a lot of memory.
- deep-copy pcb policy if it is an ipsec policy. assign ID field to
all SPD entries. make it possible for racoon to grab SPD entry on
pcb.
- fixed the order of searching SA table for packets.
- fixed to get a security association header. a mode is always needed
to compare them.
- fixed that the incorrect time was set to
sadb_comb_{hard|soft}_usetime.
- disallow port spec for tunnel mode policy (as we don't reassemble).
- an user can define a policy-id.
- clear enc/auth key before freeing.
- fixed that the kernel crashed when key_spdacquire() was called
because key_spdacquire() had been implemented imcopletely.
- preparation for 64bit sequence number.
- maintain ordered list of SA, based on SA id.
- cleanup secasvar management; refcnt is key.c responsibility;
alloc/free is keydb.c responsibility.
- cleanup, avoid double-loop.
- use hash for spi-based lookup.
- mark persistent SP "persistent".
XXX in theory refcnt should do the right thing, however, we have
"spdflush" which would touch all SPs. another solution would be to
de-register persistent SPs from sptree.
- u_short -> u_int16_t
- reduce kernel stack usage by auto variable secasindex.
- clarify function name confusion. ipsec_*_policy ->
ipsec_*_pcbpolicy.
- avoid variable name confusion.
(struct inpcbpolicy *)pcb_sp, spp (struct secpolicy **), sp (struct
secpolicy *)
- count number of ipsec encapsulations on ipsec4_output, so that we
can tell ip_output() how to handle the packet further.
- When the value of the ul_proto is ICMP or ICMPV6, the port field in
"src" of the spidx specifies ICMP type, and the port field in "dst"
of the spidx specifies ICMP code.
- avoid from applying IPsec transport mode to the packets when the
kernel forwards the packets.
Tested by: nork
Obtained from: KAME
2003-11-04 16:02:05 +00:00
|
|
|
int
|
|
|
|
ipsec_getnhist(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct ipsecaux *aux;
|
|
|
|
|
|
|
|
aux = ipsec_findaux(m);
|
|
|
|
if (aux == NULL)
|
|
|
|
return 0;
|
|
|
|
return aux->hdrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ipsec_clearhist(m)
|
|
|
|
struct mbuf *m;
|
|
|
|
{
|
|
|
|
struct ipsecaux *aux;
|
|
|
|
|
|
|
|
aux = ipsec_findaux(m);
|
|
|
|
ipsec_optaux(m, aux);
|
2001-06-11 12:39:29 +00:00
|
|
|
}
|