2002-10-16 02:10:08 +00:00
|
|
|
/* $FreeBSD$ */
|
|
|
|
/* $KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $ */
|
|
|
|
|
2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2002-10-16 02:10:08 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NETIPSEC_IPSEC_H_
|
|
|
|
#define _NETIPSEC_IPSEC_H_
|
|
|
|
|
|
|
|
#if defined(_KERNEL) && !defined(_LKM) && !defined(KLD_MODULE)
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_ipsec.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <net/pfkeyv2.h>
|
|
|
|
#include <netipsec/keydb.h>
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
|
2014-12-02 04:20:50 +00:00
|
|
|
#include <sys/_lock.h>
|
|
|
|
#include <sys/_mutex.h>
|
|
|
|
#include <sys/_rwlock.h>
|
|
|
|
|
2008-05-17 04:00:11 +00:00
|
|
|
#define IPSEC_ASSERT(_c,_m) KASSERT(_c, _m)
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
/*
|
|
|
|
* Security Policy Index
|
|
|
|
* Ensure that both address families in the "src" and "dst" are same.
|
|
|
|
* When the value of the ul_proto is ICMPv6, the port field in "src"
|
|
|
|
* specifies ICMPv6 type, and the port field in "dst" specifies ICMPv6 code.
|
|
|
|
*/
|
|
|
|
struct secpolicyindex {
|
|
|
|
union sockaddr_union src; /* IP src address for SP */
|
|
|
|
union sockaddr_union dst; /* IP dst address for SP */
|
2017-02-06 08:49:57 +00:00
|
|
|
uint8_t ul_proto; /* upper layer Protocol */
|
|
|
|
uint8_t dir; /* direction of packet flow */
|
|
|
|
uint8_t prefs; /* prefix length in bits for src */
|
|
|
|
uint8_t prefd; /* prefix length in bits for dst */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Request for IPsec */
|
|
|
|
struct ipsecrequest {
|
|
|
|
struct secasindex saidx;/* hint for search proper SA */
|
|
|
|
/* if __ss_len == 0 then no address specified.*/
|
|
|
|
u_int level; /* IPsec level defined below. */
|
2002-10-16 02:10:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Security Policy Data Base */
|
|
|
|
struct secpolicy {
|
2014-12-24 18:34:56 +00:00
|
|
|
TAILQ_ENTRY(secpolicy) chain;
|
2017-02-06 08:49:57 +00:00
|
|
|
LIST_ENTRY(secpolicy) idhash;
|
|
|
|
LIST_ENTRY(secpolicy) drainq;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
struct secpolicyindex spidx; /* selector */
|
2017-02-06 08:49:57 +00:00
|
|
|
#define IPSEC_MAXREQ 4
|
|
|
|
struct ipsecrequest *req[IPSEC_MAXREQ];
|
|
|
|
u_int tcount; /* IPsec transforms count */
|
|
|
|
volatile u_int refcnt; /* reference count */
|
2014-12-24 18:34:56 +00:00
|
|
|
u_int policy; /* policy_type per pfkeyv2.h */
|
2015-02-24 10:35:07 +00:00
|
|
|
u_int state;
|
|
|
|
#define IPSEC_SPSTATE_DEAD 0
|
2017-02-06 08:49:57 +00:00
|
|
|
#define IPSEC_SPSTATE_LARVAL 1
|
|
|
|
#define IPSEC_SPSTATE_ALIVE 2
|
|
|
|
#define IPSEC_SPSTATE_PCB 3
|
|
|
|
#define IPSEC_SPSTATE_IFNET 4
|
|
|
|
uint32_t priority; /* priority of this policy */
|
|
|
|
uint32_t id; /* It's unique number on the system. */
|
2002-10-16 02:10:08 +00:00
|
|
|
/*
|
|
|
|
* lifetime handler.
|
|
|
|
* the policy can be used without limitiation if both lifetime and
|
|
|
|
* validtime are zero.
|
|
|
|
* "lifetime" is passed by sadb_lifetime.sadb_lifetime_addtime.
|
|
|
|
* "validtime" is passed by sadb_lifetime.sadb_lifetime_usetime.
|
|
|
|
*/
|
2003-09-29 22:57:43 +00:00
|
|
|
time_t created; /* time created the policy */
|
|
|
|
time_t lastused; /* updated every when kernel sends a packet */
|
2002-10-16 02:10:08 +00:00
|
|
|
long lifetime; /* duration of the lifetime of this policy */
|
|
|
|
long validtime; /* duration this policy is valid without use */
|
|
|
|
};
|
|
|
|
|
2003-09-29 22:57:43 +00:00
|
|
|
/*
|
2017-02-06 08:49:57 +00:00
|
|
|
* PCB security policies.
|
|
|
|
* Application can setup private security policies for socket.
|
|
|
|
* Such policies can have IPSEC, BYPASS and ENTRUST type.
|
|
|
|
* By default, policies are set to NULL. This means that they have ENTRUST type.
|
|
|
|
* When application sets BYPASS or IPSEC type policy, the flags field
|
|
|
|
* is also updated. When flags is not set, the system could store
|
|
|
|
* used security policy into the sp_in/sp_out pointer to speed up further
|
|
|
|
* lookups.
|
2003-09-29 22:57:43 +00:00
|
|
|
*/
|
2002-10-16 02:10:08 +00:00
|
|
|
struct inpcbpolicy {
|
2017-02-06 08:49:57 +00:00
|
|
|
struct secpolicy *sp_in;
|
|
|
|
struct secpolicy *sp_out;
|
|
|
|
|
|
|
|
uint32_t genid;
|
|
|
|
uint16_t flags;
|
|
|
|
#define INP_INBOUND_POLICY 0x0001
|
|
|
|
#define INP_OUTBOUND_POLICY 0x0002
|
|
|
|
uint16_t hdrsz;
|
2002-10-16 02:10:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* SP acquiring list table. */
|
|
|
|
struct secspacq {
|
|
|
|
LIST_ENTRY(secspacq) chain;
|
|
|
|
|
|
|
|
struct secpolicyindex spidx;
|
|
|
|
|
2003-09-29 22:57:43 +00:00
|
|
|
time_t created; /* for lifetime */
|
2002-10-16 02:10:08 +00:00
|
|
|
int count; /* for lifetime */
|
|
|
|
/* XXX: here is mbuf place holder to be sent ? */
|
|
|
|
};
|
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
/* buffer size for formatted output of ipsec address */
|
|
|
|
#define IPSEC_ADDRSTRLEN (INET6_ADDRSTRLEN + 11)
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
/* according to IANA assignment, port 0x0000 and proto 0xff are reserved. */
|
|
|
|
#define IPSEC_PORT_ANY 0
|
|
|
|
#define IPSEC_ULPROTO_ANY 255
|
|
|
|
#define IPSEC_PROTO_ANY 255
|
|
|
|
|
|
|
|
/* mode of security protocol */
|
|
|
|
/* NOTE: DON'T use IPSEC_MODE_ANY at SPD. It's only use in SAD */
|
|
|
|
#define IPSEC_MODE_ANY 0 /* i.e. wildcard. */
|
|
|
|
#define IPSEC_MODE_TRANSPORT 1
|
|
|
|
#define IPSEC_MODE_TUNNEL 2
|
Initial import of RFC 2385 (TCP-MD5) digest support.
This is the first of two commits; bringing in the kernel support first.
This can be enabled by compiling a kernel with options TCP_SIGNATURE
and FAST_IPSEC.
For the uninitiated, this is a TCP option which provides for a means of
authenticating TCP sessions which came into being before IPSEC. It is
still relevant today, however, as it is used by many commercial router
vendors, particularly with BGP, and as such has become a requirement for
interconnect at many major Internet points of presence.
Several parts of the TCP and IP headers, including the segment payload,
are digested with MD5, including a shared secret. The PF_KEY interface
is used to manage the secrets using security associations in the SADB.
There is a limitation here in that as there is no way to map a TCP flow
per-port back to an SPI without polluting tcpcb or using the SPD; the
code to do the latter is unstable at this time. Therefore this code only
supports per-host keying granularity.
Whilst FAST_IPSEC is mutually exclusive with KAME IPSEC (and thus IPv6),
TCP_SIGNATURE applies only to IPv4. For the vast majority of prospective
users of this feature, this will not pose any problem.
This implementation is output-only; that is, the option is honoured when
responding to a host initiating a TCP session, but no effort is made
[yet] to authenticate inbound traffic. This is, however, sufficient to
interwork with Cisco equipment.
Tested with a Cisco 2501 running IOS 12.0(27), and Quagga 0.96.4 with
local patches. Patches for tcpdump to validate TCP-MD5 sessions are also
available from me upon request.
Sponsored by: sentex.net
2004-02-11 04:26:04 +00:00
|
|
|
#define IPSEC_MODE_TCPMD5 3 /* TCP MD5 mode */
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Direction of security policy.
|
|
|
|
* NOTE: Since INVALID is used just as flag.
|
|
|
|
* The other are used for loop counter too.
|
|
|
|
*/
|
|
|
|
#define IPSEC_DIR_ANY 0
|
|
|
|
#define IPSEC_DIR_INBOUND 1
|
|
|
|
#define IPSEC_DIR_OUTBOUND 2
|
|
|
|
#define IPSEC_DIR_MAX 3
|
|
|
|
#define IPSEC_DIR_INVALID 4
|
|
|
|
|
|
|
|
/* Policy level */
|
|
|
|
/*
|
|
|
|
* IPSEC, ENTRUST and BYPASS are allowed for setsockopt() in PCB,
|
|
|
|
* DISCARD, IPSEC and NONE are allowed for setkey() in SPD.
|
|
|
|
* DISCARD and NONE are allowed for system default.
|
|
|
|
*/
|
|
|
|
#define IPSEC_POLICY_DISCARD 0 /* discarding packet */
|
|
|
|
#define IPSEC_POLICY_NONE 1 /* through IPsec engine */
|
|
|
|
#define IPSEC_POLICY_IPSEC 2 /* do IPsec */
|
|
|
|
#define IPSEC_POLICY_ENTRUST 3 /* consulting SPD if present. */
|
|
|
|
#define IPSEC_POLICY_BYPASS 4 /* only for privileged socket. */
|
|
|
|
|
2017-03-07 00:13:53 +00:00
|
|
|
/* Policy scope */
|
|
|
|
#define IPSEC_POLICYSCOPE_ANY 0x00 /* unspecified */
|
|
|
|
#define IPSEC_POLICYSCOPE_GLOBAL 0x01 /* global scope */
|
|
|
|
#define IPSEC_POLICYSCOPE_IFNET 0x02 /* if_ipsec(4) scope */
|
|
|
|
#define IPSEC_POLICYSCOPE_PCB 0x04 /* PCB scope */
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
/* Security protocol level */
|
|
|
|
#define IPSEC_LEVEL_DEFAULT 0 /* reference to system default */
|
|
|
|
#define IPSEC_LEVEL_USE 1 /* use SA if present. */
|
|
|
|
#define IPSEC_LEVEL_REQUIRE 2 /* require SA. */
|
|
|
|
#define IPSEC_LEVEL_UNIQUE 3 /* unique SA. */
|
|
|
|
|
|
|
|
#define IPSEC_MANUAL_REQID_MAX 0x3fff
|
|
|
|
/*
|
|
|
|
* if security policy level == unique, this id
|
|
|
|
* indicate to a relative SA for use, else is
|
|
|
|
* zero.
|
|
|
|
* 1 - 0x3fff are reserved for manual keying.
|
|
|
|
* 0 are reserved for above reason. Others is
|
|
|
|
* for kernel use.
|
|
|
|
* Note that this id doesn't identify SA
|
|
|
|
* by only itself.
|
|
|
|
*/
|
|
|
|
#define IPSEC_REPLAYWSIZE 32
|
|
|
|
|
2007-07-01 11:41:27 +00:00
|
|
|
/* statistics for ipsec processing */
|
2002-10-16 02:10:08 +00:00
|
|
|
struct ipsecstat {
|
Prepare network statistics structures for migration to PCPU counters.
Use uint64_t as type for all fields of structures.
Changed structures: ahstat, arpstat, espstat, icmp6_ifstat, icmp6stat,
in6_ifstat, ip6stat, ipcompstat, ipipstat, ipsecstat, mrt6stat, mrtstat,
pfkeystat, pim6stat, pimstat, rip6stat, udpstat.
Discussed with: arch@
2013-07-09 09:32:06 +00:00
|
|
|
uint64_t ips_in_polvio; /* input: sec policy violation */
|
2013-07-23 14:14:24 +00:00
|
|
|
uint64_t ips_in_nomem; /* input: no memory available */
|
|
|
|
uint64_t ips_in_inval; /* input: generic error */
|
|
|
|
|
Prepare network statistics structures for migration to PCPU counters.
Use uint64_t as type for all fields of structures.
Changed structures: ahstat, arpstat, espstat, icmp6_ifstat, icmp6stat,
in6_ifstat, ip6stat, ipcompstat, ipipstat, ipsecstat, mrt6stat, mrtstat,
pfkeystat, pim6stat, pimstat, rip6stat, udpstat.
Discussed with: arch@
2013-07-09 09:32:06 +00:00
|
|
|
uint64_t ips_out_polvio; /* output: sec policy violation */
|
|
|
|
uint64_t ips_out_nosa; /* output: SA unavailable */
|
|
|
|
uint64_t ips_out_nomem; /* output: no memory available */
|
|
|
|
uint64_t ips_out_noroute; /* output: no route available */
|
|
|
|
uint64_t ips_out_inval; /* output: generic error */
|
|
|
|
uint64_t ips_out_bundlesa; /* output: bundled SA processed */
|
2013-07-23 14:14:24 +00:00
|
|
|
|
2018-05-22 15:54:25 +00:00
|
|
|
uint64_t ips_spdcache_hits; /* SPD cache hits */
|
|
|
|
uint64_t ips_spdcache_misses; /* SPD cache misses */
|
|
|
|
|
Prepare network statistics structures for migration to PCPU counters.
Use uint64_t as type for all fields of structures.
Changed structures: ahstat, arpstat, espstat, icmp6_ifstat, icmp6stat,
in6_ifstat, ip6stat, ipcompstat, ipipstat, ipsecstat, mrt6stat, mrtstat,
pfkeystat, pim6stat, pimstat, rip6stat, udpstat.
Discussed with: arch@
2013-07-09 09:32:06 +00:00
|
|
|
uint64_t ips_clcopied; /* clusters copied during clone */
|
|
|
|
uint64_t ips_mbinserted; /* mbufs inserted during makespace */
|
2002-10-16 02:10:08 +00:00
|
|
|
/*
|
|
|
|
* Temporary statistics for performance analysis.
|
|
|
|
*/
|
|
|
|
/* See where ESP/AH/IPCOMP header land in mbuf on input */
|
Prepare network statistics structures for migration to PCPU counters.
Use uint64_t as type for all fields of structures.
Changed structures: ahstat, arpstat, espstat, icmp6_ifstat, icmp6stat,
in6_ifstat, ip6stat, ipcompstat, ipipstat, ipsecstat, mrt6stat, mrtstat,
pfkeystat, pim6stat, pimstat, rip6stat, udpstat.
Discussed with: arch@
2013-07-09 09:32:06 +00:00
|
|
|
uint64_t ips_input_front;
|
|
|
|
uint64_t ips_input_middle;
|
|
|
|
uint64_t ips_input_end;
|
2002-10-16 02:10:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Definitions for IPsec & Key sysctl operations.
|
|
|
|
*/
|
|
|
|
#define IPSECCTL_STATS 1 /* stats */
|
|
|
|
#define IPSECCTL_DEF_POLICY 2
|
|
|
|
#define IPSECCTL_DEF_ESP_TRANSLEV 3 /* int; ESP transport mode */
|
|
|
|
#define IPSECCTL_DEF_ESP_NETLEV 4 /* int; ESP tunnel mode */
|
|
|
|
#define IPSECCTL_DEF_AH_TRANSLEV 5 /* int; AH transport mode */
|
|
|
|
#define IPSECCTL_DEF_AH_NETLEV 6 /* int; AH tunnel mode */
|
|
|
|
#if 0 /* obsolete, do not reuse */
|
|
|
|
#define IPSECCTL_INBOUND_CALL_IKE 7
|
|
|
|
#endif
|
|
|
|
#define IPSECCTL_AH_CLEARTOS 8
|
|
|
|
#define IPSECCTL_AH_OFFSETMASK 9
|
|
|
|
#define IPSECCTL_DFBIT 10
|
|
|
|
#define IPSECCTL_ECN 11
|
|
|
|
#define IPSECCTL_DEBUG 12
|
|
|
|
#define IPSECCTL_ESP_RANDPAD 13
|
|
|
|
|
|
|
|
#ifdef _KERNEL
|
2013-07-09 10:08:13 +00:00
|
|
|
#include <sys/counter.h>
|
|
|
|
|
2015-11-25 07:31:59 +00:00
|
|
|
struct ipsec_ctx_data;
|
2017-07-31 11:04:35 +00:00
|
|
|
#define IPSEC_INIT_CTX(_ctx, _mp, _inp, _sav, _af, _enc) do { \
|
2015-11-25 07:31:59 +00:00
|
|
|
(_ctx)->mp = (_mp); \
|
2017-07-31 11:04:35 +00:00
|
|
|
(_ctx)->inp = (_inp); \
|
2015-11-25 07:31:59 +00:00
|
|
|
(_ctx)->sav = (_sav); \
|
|
|
|
(_ctx)->af = (_af); \
|
|
|
|
(_ctx)->enc = (_enc); \
|
|
|
|
} while(0)
|
|
|
|
int ipsec_run_hhooks(struct ipsec_ctx_data *ctx, int direction);
|
|
|
|
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
VNET_DECLARE(int, ipsec_debug);
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_ipsec_debug VNET(ipsec_debug)
|
2010-04-29 11:52:42 +00:00
|
|
|
|
|
|
|
#ifdef REGRESSION
|
|
|
|
VNET_DECLARE(int, ipsec_replay);
|
|
|
|
VNET_DECLARE(int, ipsec_integrity);
|
|
|
|
|
|
|
|
#define V_ipsec_replay VNET(ipsec_replay)
|
|
|
|
#define V_ipsec_integrity VNET(ipsec_integrity)
|
|
|
|
#endif
|
|
|
|
|
2013-07-09 10:08:13 +00:00
|
|
|
VNET_PCPUSTAT_DECLARE(struct ipsecstat, ipsec4stat);
|
2010-04-29 11:52:42 +00:00
|
|
|
VNET_DECLARE(int, ip4_esp_trans_deflev);
|
|
|
|
VNET_DECLARE(int, ip4_esp_net_deflev);
|
|
|
|
VNET_DECLARE(int, ip4_ah_trans_deflev);
|
|
|
|
VNET_DECLARE(int, ip4_ah_net_deflev);
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
VNET_DECLARE(int, ip4_ipsec_dfbit);
|
2010-04-29 11:52:42 +00:00
|
|
|
VNET_DECLARE(int, ip4_ipsec_ecn);
|
|
|
|
VNET_DECLARE(int, crypto_support);
|
2017-11-03 10:27:22 +00:00
|
|
|
VNET_DECLARE(int, async_crypto);
|
2017-02-06 08:49:57 +00:00
|
|
|
VNET_DECLARE(int, natt_cksum_policy);
|
2010-04-29 11:52:42 +00:00
|
|
|
|
2013-07-09 10:08:13 +00:00
|
|
|
#define IPSECSTAT_INC(name) \
|
|
|
|
VNET_PCPUSTAT_ADD(struct ipsecstat, ipsec4stat, name, 1)
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_ip4_esp_trans_deflev VNET(ip4_esp_trans_deflev)
|
|
|
|
#define V_ip4_esp_net_deflev VNET(ip4_esp_net_deflev)
|
|
|
|
#define V_ip4_ah_trans_deflev VNET(ip4_ah_trans_deflev)
|
|
|
|
#define V_ip4_ah_net_deflev VNET(ip4_ah_net_deflev)
|
2010-04-29 11:52:42 +00:00
|
|
|
#define V_ip4_ipsec_dfbit VNET(ip4_ipsec_dfbit)
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_ip4_ipsec_ecn VNET(ip4_ipsec_ecn)
|
|
|
|
#define V_crypto_support VNET(crypto_support)
|
2017-11-03 10:27:22 +00:00
|
|
|
#define V_async_crypto VNET(async_crypto)
|
2017-02-06 08:49:57 +00:00
|
|
|
#define V_natt_cksum_policy VNET(natt_cksum_policy)
|
2002-10-16 02:10:08 +00:00
|
|
|
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
#define ipseclog(x) do { if (V_ipsec_debug) log x; } while (0)
|
2002-10-16 02:10:08 +00:00
|
|
|
/* for openbsd compatibility */
|
2017-05-29 09:30:38 +00:00
|
|
|
#ifdef IPSEC_DEBUG
|
|
|
|
#define IPSEC_DEBUG_DECLARE(x) x
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
#define DPRINTF(x) do { if (V_ipsec_debug) printf x; } while (0)
|
2017-05-29 09:30:38 +00:00
|
|
|
#else
|
|
|
|
#define IPSEC_DEBUG_DECLARE(x)
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
struct inpcb;
|
2017-02-06 08:49:57 +00:00
|
|
|
struct m_tag;
|
|
|
|
struct secasvar;
|
|
|
|
struct sockopt;
|
|
|
|
struct tcphdr;
|
2002-10-16 02:10:08 +00:00
|
|
|
union sockaddr_union;
|
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
int ipsec_if_input(struct mbuf *, struct secasvar *, uint32_t);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
2017-02-06 08:49:57 +00:00
|
|
|
struct ipsecrequest *ipsec_newisr(void);
|
|
|
|
void ipsec_delisr(struct ipsecrequest *);
|
|
|
|
struct secpolicy *ipsec4_checkpolicy(const struct mbuf *, struct inpcb *,
|
2017-08-21 13:52:21 +00:00
|
|
|
int *, int);
|
2017-02-06 08:49:57 +00:00
|
|
|
|
|
|
|
u_int ipsec_get_reqlevel(struct secpolicy *, u_int);
|
|
|
|
|
|
|
|
void udp_ipsec_adjust_cksum(struct mbuf *, struct secasvar *, int, int);
|
|
|
|
int udp_ipsec_output(struct mbuf *, struct secasvar *);
|
|
|
|
int udp_ipsec_input(struct mbuf *, int, int);
|
|
|
|
int udp_ipsec_pcbctl(struct inpcb *, struct sockopt *);
|
|
|
|
|
|
|
|
int ipsec_chkreplay(uint32_t, struct secasvar *);
|
|
|
|
int ipsec_updatereplay(uint32_t, struct secasvar *);
|
2018-07-13 23:46:07 +00:00
|
|
|
int ipsec_updateid(struct secasvar *, crypto_session_t *, crypto_session_t *);
|
2017-02-06 08:49:57 +00:00
|
|
|
int ipsec_initialized(void);
|
|
|
|
|
|
|
|
void ipsec_setspidx_inpcb(struct inpcb *, struct secpolicyindex *, u_int);
|
|
|
|
|
|
|
|
void ipsec4_setsockaddrs(const struct mbuf *, union sockaddr_union *,
|
|
|
|
union sockaddr_union *);
|
|
|
|
int ipsec4_in_reject(const struct mbuf *, struct inpcb *);
|
|
|
|
int ipsec4_input(struct mbuf *, int, int);
|
|
|
|
int ipsec4_forward(struct mbuf *);
|
|
|
|
int ipsec4_pcbctl(struct inpcb *, struct sockopt *);
|
|
|
|
int ipsec4_output(struct mbuf *, struct inpcb *);
|
|
|
|
int ipsec4_capability(struct mbuf *, u_int);
|
|
|
|
int ipsec4_common_input_cb(struct mbuf *, struct secasvar *, int, int);
|
|
|
|
int ipsec4_process_packet(struct mbuf *, struct secpolicy *, struct inpcb *);
|
|
|
|
int ipsec_process_done(struct mbuf *, struct secpolicy *, struct secasvar *,
|
|
|
|
u_int);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
extern void m_checkalignment(const char* where, struct mbuf *m0,
|
|
|
|
int off, int len);
|
|
|
|
extern struct mbuf *m_makespace(struct mbuf *m0, int skip, int hlen, int *off);
|
|
|
|
extern caddr_t m_pad(struct mbuf *m, int n);
|
|
|
|
extern int m_striphdr(struct mbuf *m, int skip, int hlen);
|
2007-11-28 22:33:53 +00:00
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
|
|
|
#ifndef _KERNEL
|
2014-12-03 04:08:41 +00:00
|
|
|
extern caddr_t ipsec_set_policy(char *, int);
|
|
|
|
extern int ipsec_get_policylen(caddr_t);
|
|
|
|
extern char *ipsec_dump_policy(caddr_t, char *);
|
|
|
|
extern const char *ipsec_strerror(void);
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
|
|
|
|
#endif /* ! KERNEL */
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
#endif /* _NETIPSEC_IPSEC_H_ */
|