Home | History | Annotate | Line # | Download | only in netipsec
ipsec_netbsd.c revision 1.15.6.1
      1  1.15.6.1    simonb /*	$NetBSD: ipsec_netbsd.c,v 1.15.6.1 2006/04/22 11:40:13 simonb Exp $	*/
      2       1.1  jonathan /*	$KAME: esp_input.c,v 1.60 2001/09/04 08:43:19 itojun Exp $	*/
      3       1.1  jonathan /*	$KAME: ah_input.c,v 1.64 2001/09/04 08:43:19 itojun Exp $	*/
      4       1.1  jonathan 
      5       1.1  jonathan /*
      6       1.1  jonathan  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      7       1.1  jonathan  * All rights reserved.
      8       1.1  jonathan  *
      9       1.1  jonathan  * Redistribution and use in source and binary forms, with or without
     10       1.1  jonathan  * modification, are permitted provided that the following conditions
     11       1.1  jonathan  * are met:
     12       1.1  jonathan  * 1. Redistributions of source code must retain the above copyright
     13       1.1  jonathan  *    notice, this list of conditions and the following disclaimer.
     14       1.1  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1  jonathan  *    notice, this list of conditions and the following disclaimer in the
     16       1.1  jonathan  *    documentation and/or other materials provided with the distribution.
     17       1.1  jonathan  * 3. Neither the name of the project nor the names of its contributors
     18       1.1  jonathan  *    may be used to endorse or promote products derived from this software
     19       1.1  jonathan  *    without specific prior written permission.
     20       1.1  jonathan  *
     21       1.1  jonathan  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     22       1.1  jonathan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23       1.1  jonathan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24       1.1  jonathan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     25       1.1  jonathan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26       1.1  jonathan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27       1.1  jonathan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28       1.1  jonathan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29       1.1  jonathan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30       1.1  jonathan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31       1.1  jonathan  * SUCH DAMAGE.
     32       1.1  jonathan  */
     33       1.1  jonathan 
     34       1.1  jonathan #include <sys/cdefs.h>
     35  1.15.6.1    simonb __KERNEL_RCSID(0, "$NetBSD: ipsec_netbsd.c,v 1.15.6.1 2006/04/22 11:40:13 simonb Exp $");
     36       1.1  jonathan 
     37       1.1  jonathan #include "opt_inet.h"
     38       1.1  jonathan #include "opt_ipsec.h"
     39       1.1  jonathan 
     40       1.1  jonathan #include <sys/param.h>
     41       1.1  jonathan #include <sys/systm.h>
     42       1.1  jonathan #include <sys/malloc.h>
     43       1.1  jonathan #include <sys/mbuf.h>
     44       1.1  jonathan #include <sys/domain.h>
     45       1.1  jonathan #include <sys/protosw.h>
     46       1.1  jonathan #include <sys/socket.h>
     47       1.1  jonathan #include <sys/errno.h>
     48       1.1  jonathan #include <sys/time.h>
     49       1.1  jonathan #include <sys/kernel.h>
     50       1.1  jonathan #include <sys/sysctl.h>
     51       1.1  jonathan 
     52       1.1  jonathan #include <net/if.h>
     53       1.1  jonathan #include <net/route.h>
     54       1.1  jonathan #include <net/netisr.h>
     55       1.1  jonathan #include <machine/cpu.h>
     56       1.1  jonathan 
     57       1.1  jonathan #include <netinet/in.h>
     58       1.1  jonathan #include <netinet/in_systm.h>
     59       1.1  jonathan #include <netinet/in_var.h>
     60       1.1  jonathan #include <netinet/ip.h>
     61       1.1  jonathan #include <netinet/ip_var.h>
     62       1.1  jonathan #include <netinet/ip_ecn.h>
     63       1.1  jonathan #include <netinet/ip_icmp.h>
     64       1.1  jonathan 
     65       1.1  jonathan 
     66       1.1  jonathan #include <netipsec/ipsec.h>
     67      1.10  jonathan #include <netipsec/ipsec_var.h>
     68       1.3       tls #include <netipsec/key.h>
     69       1.3       tls #include <netipsec/keydb.h>
     70       1.3       tls #include <netipsec/key_debug.h>
     71       1.1  jonathan #include <netipsec/ah_var.h>
     72       1.5  jonathan #include <netipsec/esp.h>
     73      1.10  jonathan #include <netipsec/esp_var.h>
     74      1.10  jonathan #include <netipsec/ipip_var.h>
     75      1.10  jonathan #include <netipsec/ipcomp_var.h>
     76       1.5  jonathan 
     77       1.5  jonathan #ifdef INET6
     78       1.5  jonathan #include <netipsec/ipsec6.h>
     79       1.5  jonathan #include <netinet6/ip6protosw.h>
     80       1.5  jonathan #include <netinet/icmp6.h>
     81       1.1  jonathan #endif
     82       1.1  jonathan 
     83       1.1  jonathan #include <machine/stdarg.h>
     84       1.1  jonathan 
     85       1.1  jonathan 
     86       1.1  jonathan 
     87       1.3       tls #include <netipsec/key.h>
     88       1.1  jonathan 
     89       1.1  jonathan /* assumes that ip header and ah header are contiguous on mbuf */
     90       1.1  jonathan void *
     91       1.1  jonathan ah4_ctlinput(cmd, sa, v)
     92       1.1  jonathan 	int cmd;
     93       1.1  jonathan 	struct sockaddr *sa;
     94       1.1  jonathan 	void *v;
     95       1.1  jonathan {
     96       1.1  jonathan 	struct ip *ip = v;
     97       1.1  jonathan 	struct ah *ah;
     98       1.1  jonathan 	struct icmp *icp;
     99       1.1  jonathan 	struct secasvar *sav;
    100       1.1  jonathan 
    101       1.1  jonathan 	if (sa->sa_family != AF_INET ||
    102       1.1  jonathan 	    sa->sa_len != sizeof(struct sockaddr_in))
    103       1.1  jonathan 		return NULL;
    104       1.1  jonathan 	if ((unsigned)cmd >= PRC_NCMDS)
    105       1.1  jonathan 		return NULL;
    106       1.1  jonathan #ifndef notyet
    107      1.13     perry 	/* jonathan (at) NetBSD.org: XXX FIXME */
    108       1.1  jonathan 	(void) ip; (void) ah; (void) icp; (void) sav;
    109       1.1  jonathan #else
    110       1.1  jonathan 	if (cmd == PRC_MSGSIZE && ip_mtudisc && ip && ip->ip_v == 4) {
    111       1.1  jonathan 		/*
    112       1.1  jonathan 		 * Check to see if we have a valid SA corresponding to
    113       1.1  jonathan 		 * the address in the ICMP message payload.
    114       1.1  jonathan 		 */
    115       1.1  jonathan 		ah = (struct ah *)((caddr_t)ip + (ip->ip_hl << 2));
    116       1.1  jonathan 		if ((sav = key_allocsa(AF_INET,
    117       1.1  jonathan 				       (caddr_t) &ip->ip_src,
    118       1.1  jonathan 				       (caddr_t) &ip->ip_dst,
    119       1.1  jonathan 				       IPPROTO_AH, ah->ah_spi)) == NULL)
    120       1.1  jonathan 			return NULL;
    121       1.1  jonathan 		if (sav->state != SADB_SASTATE_MATURE &&
    122       1.1  jonathan 		    sav->state != SADB_SASTATE_DYING) {
    123       1.1  jonathan 			key_freesav(sav);
    124       1.1  jonathan 			return NULL;
    125       1.1  jonathan 		}
    126       1.1  jonathan 
    127       1.1  jonathan 		/* XXX Further validation? */
    128       1.1  jonathan 
    129       1.1  jonathan 		key_freesav(sav);
    130       1.1  jonathan 
    131       1.1  jonathan 		/*
    132       1.1  jonathan 		 * Now that we've validated that we are actually communicating
    133       1.1  jonathan 		 * with the host indicated in the ICMP message, locate the
    134       1.1  jonathan 		 * ICMP header, recalculate the new MTU, and create the
    135       1.1  jonathan 		 * corresponding routing entry.
    136       1.1  jonathan 		 */
    137       1.1  jonathan 		icp = (struct icmp *)((caddr_t)ip -
    138       1.1  jonathan 		    offsetof(struct icmp, icmp_ip));
    139       1.1  jonathan 		icmp_mtudisc(icp, ip->ip_dst);
    140       1.1  jonathan 
    141       1.1  jonathan 		return NULL;
    142       1.1  jonathan 	}
    143       1.1  jonathan #endif
    144       1.1  jonathan 
    145       1.1  jonathan 	return NULL;
    146       1.1  jonathan }
    147       1.1  jonathan 
    148       1.1  jonathan /* assumes that ip header and esp header are contiguous on mbuf */
    149       1.1  jonathan void *
    150       1.1  jonathan esp4_ctlinput(cmd, sa, v)
    151       1.1  jonathan 	int cmd;
    152       1.1  jonathan 	struct sockaddr *sa;
    153       1.1  jonathan 	void *v;
    154       1.1  jonathan {
    155       1.1  jonathan 	struct ip *ip = v;
    156       1.1  jonathan 	struct esp *esp;
    157       1.1  jonathan 	struct icmp *icp;
    158       1.1  jonathan 	struct secasvar *sav;
    159       1.1  jonathan 
    160       1.1  jonathan 	if (sa->sa_family != AF_INET ||
    161       1.1  jonathan 	    sa->sa_len != sizeof(struct sockaddr_in))
    162       1.1  jonathan 		return NULL;
    163       1.1  jonathan 	if ((unsigned)cmd >= PRC_NCMDS)
    164       1.1  jonathan 		return NULL;
    165       1.1  jonathan #ifndef notyet
    166      1.13     perry 	/* jonathan (at) NetBSD.org: XXX FIXME */
    167       1.1  jonathan 	(void) ip; (void) esp; (void) icp; (void) sav;
    168       1.1  jonathan #else
    169       1.1  jonathan 	if (cmd == PRC_MSGSIZE && ip_mtudisc && ip && ip->ip_v == 4) {
    170       1.1  jonathan 		/*
    171       1.1  jonathan 		 * Check to see if we have a valid SA corresponding to
    172       1.1  jonathan 		 * the address in the ICMP message payload.
    173       1.1  jonathan 		 */
    174       1.1  jonathan 		esp = (struct esp *)((caddr_t)ip + (ip->ip_hl << 2));
    175       1.1  jonathan 		if ((sav = key_allocsa(AF_INET,
    176       1.1  jonathan 				       (caddr_t) &ip->ip_src,
    177       1.1  jonathan 				       (caddr_t) &ip->ip_dst,
    178       1.1  jonathan 				       IPPROTO_ESP, esp->esp_spi)) == NULL)
    179       1.1  jonathan 			return NULL;
    180       1.1  jonathan 		if (sav->state != SADB_SASTATE_MATURE &&
    181       1.1  jonathan 		    sav->state != SADB_SASTATE_DYING) {
    182       1.1  jonathan 			key_freesav(sav);
    183       1.1  jonathan 			return NULL;
    184       1.1  jonathan 		}
    185       1.1  jonathan 
    186       1.1  jonathan 		/* XXX Further validation? */
    187       1.1  jonathan 
    188       1.1  jonathan 		key_freesav(sav);
    189       1.1  jonathan 
    190       1.1  jonathan 		/*
    191       1.1  jonathan 		 * Now that we've validated that we are actually communicating
    192       1.1  jonathan 		 * with the host indicated in the ICMP message, locate the
    193       1.1  jonathan 		 * ICMP header, recalculate the new MTU, and create the
    194       1.1  jonathan 		 * corresponding routing entry.
    195       1.1  jonathan 		 */
    196       1.1  jonathan 		icp = (struct icmp *)((caddr_t)ip -
    197       1.1  jonathan 		    offsetof(struct icmp, icmp_ip));
    198       1.1  jonathan 		icmp_mtudisc(icp, ip->ip_dst);
    199       1.1  jonathan 
    200       1.1  jonathan 		return NULL;
    201       1.1  jonathan 	}
    202       1.1  jonathan #endif
    203       1.1  jonathan 
    204       1.1  jonathan 	return NULL;
    205       1.1  jonathan }
    206       1.1  jonathan 
    207       1.1  jonathan #ifdef INET6
    208       1.1  jonathan void
    209       1.1  jonathan esp6_ctlinput(cmd, sa, d)
    210       1.1  jonathan 	int cmd;
    211       1.1  jonathan 	struct sockaddr *sa;
    212       1.1  jonathan 	void *d;
    213       1.1  jonathan {
    214       1.1  jonathan 	const struct newesp *espp;
    215       1.1  jonathan 	struct newesp esp;
    216       1.1  jonathan 	struct ip6ctlparam *ip6cp = NULL, ip6cp1;
    217       1.1  jonathan 	struct secasvar *sav;
    218       1.1  jonathan 	struct ip6_hdr *ip6;
    219       1.1  jonathan 	struct mbuf *m;
    220       1.1  jonathan 	int off;
    221       1.1  jonathan 	struct sockaddr_in6 *sa6_src, *sa6_dst;
    222       1.1  jonathan 
    223       1.1  jonathan 	if (sa->sa_family != AF_INET6 ||
    224       1.1  jonathan 	    sa->sa_len != sizeof(struct sockaddr_in6))
    225       1.1  jonathan 		return;
    226       1.1  jonathan 	if ((unsigned)cmd >= PRC_NCMDS)
    227       1.1  jonathan 		return;
    228       1.1  jonathan 
    229       1.1  jonathan 	/* if the parameter is from icmp6, decode it. */
    230       1.1  jonathan 	if (d != NULL) {
    231       1.1  jonathan 		ip6cp = (struct ip6ctlparam *)d;
    232       1.1  jonathan 		m = ip6cp->ip6c_m;
    233       1.1  jonathan 		ip6 = ip6cp->ip6c_ip6;
    234       1.1  jonathan 		off = ip6cp->ip6c_off;
    235       1.1  jonathan 	} else {
    236       1.1  jonathan 		m = NULL;
    237       1.1  jonathan 		ip6 = NULL;
    238       1.7  jonathan 		off = 0;
    239       1.1  jonathan 	}
    240       1.1  jonathan 
    241       1.1  jonathan 	if (ip6) {
    242       1.1  jonathan 		/*
    243       1.1  jonathan 		 * Notify the error to all possible sockets via pfctlinput2.
    244       1.1  jonathan 		 * Since the upper layer information (such as protocol type,
    245       1.1  jonathan 		 * source and destination ports) is embedded in the encrypted
    246       1.1  jonathan 		 * data and might have been cut, we can't directly call
    247       1.1  jonathan 		 * an upper layer ctlinput function. However, the pcbnotify
    248       1.1  jonathan 		 * function will consider source and destination addresses
    249       1.1  jonathan 		 * as well as the flow info value, and may be able to find
    250       1.1  jonathan 		 * some PCB that should be notified.
    251       1.1  jonathan 		 * Although pfctlinput2 will call esp6_ctlinput(), there is
    252       1.1  jonathan 		 * no possibility of an infinite loop of function calls,
    253       1.1  jonathan 		 * because we don't pass the inner IPv6 header.
    254       1.1  jonathan 		 */
    255       1.1  jonathan 		bzero(&ip6cp1, sizeof(ip6cp1));
    256       1.1  jonathan 		ip6cp1.ip6c_src = ip6cp->ip6c_src;
    257       1.1  jonathan 		pfctlinput2(cmd, sa, (void *)&ip6cp1);
    258       1.1  jonathan 
    259       1.1  jonathan 		/*
    260       1.1  jonathan 		 * Then go to special cases that need ESP header information.
    261       1.1  jonathan 		 * XXX: We assume that when ip6 is non NULL,
    262       1.1  jonathan 		 * M and OFF are valid.
    263       1.1  jonathan 		 */
    264       1.1  jonathan 
    265       1.1  jonathan 		/* check if we can safely examine src and dst ports */
    266       1.1  jonathan 		if (m->m_pkthdr.len < off + sizeof(esp))
    267       1.1  jonathan 			return;
    268       1.1  jonathan 
    269       1.1  jonathan 		if (m->m_len < off + sizeof(esp)) {
    270       1.1  jonathan 			/*
    271       1.1  jonathan 			 * this should be rare case,
    272       1.1  jonathan 			 * so we compromise on this copy...
    273       1.1  jonathan 			 */
    274       1.1  jonathan 			m_copydata(m, off, sizeof(esp), (caddr_t)&esp);
    275       1.1  jonathan 			espp = &esp;
    276       1.1  jonathan 		} else
    277       1.1  jonathan 			espp = (struct newesp*)(mtod(m, caddr_t) + off);
    278       1.1  jonathan 
    279       1.1  jonathan 		if (cmd == PRC_MSGSIZE) {
    280       1.1  jonathan 			int valid = 0;
    281       1.1  jonathan 
    282       1.1  jonathan 			/*
    283       1.1  jonathan 			 * Check to see if we have a valid SA corresponding to
    284       1.1  jonathan 			 * the address in the ICMP message payload.
    285       1.1  jonathan 			 */
    286       1.1  jonathan 			sa6_src = ip6cp->ip6c_src;
    287       1.1  jonathan 			sa6_dst = (struct sockaddr_in6 *)sa;
    288       1.7  jonathan #ifdef KAME
    289       1.1  jonathan 			sav = key_allocsa(AF_INET6,
    290       1.1  jonathan 					  (caddr_t)&sa6_src->sin6_addr,
    291       1.1  jonathan 					  (caddr_t)&sa6_dst->sin6_addr,
    292       1.1  jonathan 					  IPPROTO_ESP, espp->esp_spi);
    293       1.7  jonathan #else
    294      1.13     perry 			/* jonathan (at) NetBSD.org: XXX FIXME */
    295       1.7  jonathan 			(void)sa6_src; (void)sa6_dst;
    296       1.7  jonathan 			sav = KEY_ALLOCSA((union sockaddr_union*)sa,
    297       1.7  jonathan 					  IPPROTO_ESP, espp->esp_spi);
    298       1.7  jonathan 
    299       1.7  jonathan #endif
    300       1.1  jonathan 			if (sav) {
    301       1.1  jonathan 				if (sav->state == SADB_SASTATE_MATURE ||
    302       1.1  jonathan 				    sav->state == SADB_SASTATE_DYING)
    303       1.1  jonathan 					valid++;
    304       1.7  jonathan 				KEY_FREESAV(&sav);
    305       1.1  jonathan 			}
    306       1.1  jonathan 
    307       1.1  jonathan 			/* XXX Further validation? */
    308       1.1  jonathan 
    309       1.1  jonathan 			/*
    310       1.1  jonathan 			 * Depending on the value of "valid" and routing table
    311       1.1  jonathan 			 * size (mtudisc_{hi,lo}wat), we will:
    312       1.1  jonathan 			 * - recalcurate the new MTU and create the
    313       1.1  jonathan 			 *   corresponding routing entry, or
    314       1.1  jonathan 			 * - ignore the MTU change notification.
    315       1.1  jonathan 			 */
    316       1.1  jonathan 			icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
    317       1.1  jonathan 		}
    318       1.1  jonathan 	} else {
    319       1.1  jonathan 		/* we normally notify any pcb here */
    320       1.1  jonathan 	}
    321       1.1  jonathan }
    322       1.1  jonathan #endif /* INET6 */
    323       1.1  jonathan 
    324       1.4    atatat static int
    325       1.4    atatat sysctl_fast_ipsec(SYSCTLFN_ARGS)
    326       1.1  jonathan {
    327       1.4    atatat 	int error, t;
    328       1.4    atatat 	struct sysctlnode node;
    329       1.4    atatat 
    330       1.4    atatat 	node = *rnode;
    331       1.4    atatat 	t = *(int*)rnode->sysctl_data;
    332       1.4    atatat 	node.sysctl_data = &t;
    333       1.4    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    334       1.4    atatat 	if (error || newp == NULL)
    335       1.4    atatat 		return (error);
    336       1.1  jonathan 
    337       1.4    atatat 	switch (rnode->sysctl_num) {
    338       1.1  jonathan 	case IPSECCTL_DEF_ESP_TRANSLEV:
    339       1.1  jonathan 	case IPSECCTL_DEF_ESP_NETLEV:
    340       1.1  jonathan 	case IPSECCTL_DEF_AH_TRANSLEV:
    341       1.1  jonathan 	case IPSECCTL_DEF_AH_NETLEV:
    342      1.13     perry 		if (t != IPSEC_LEVEL_USE &&
    343       1.4    atatat 		    t != IPSEC_LEVEL_REQUIRE)
    344       1.4    atatat 			return (EINVAL);
    345       1.4    atatat 		ipsec_invalpcbcacheall();
    346       1.1  jonathan 		break;
    347       1.4    atatat       	case IPSECCTL_DEF_POLICY:
    348       1.4    atatat 		if (t != IPSEC_POLICY_DISCARD &&
    349       1.4    atatat 		    t != IPSEC_POLICY_NONE)
    350       1.4    atatat 			return (EINVAL);
    351       1.4    atatat 		ipsec_invalpcbcacheall();
    352       1.1  jonathan 		break;
    353       1.4    atatat 	default:
    354       1.4    atatat 		return (EINVAL);
    355       1.1  jonathan 	}
    356       1.1  jonathan 
    357       1.4    atatat 	*(int*)rnode->sysctl_data = t;
    358       1.4    atatat 
    359       1.4    atatat 	return (0);
    360       1.4    atatat }
    361       1.4    atatat 
    362  1.15.6.1    simonb #ifdef IPSEC_DEBUG
    363  1.15.6.1    simonb static int
    364  1.15.6.1    simonb sysctl_fast_ipsec_test(SYSCTLFN_ARGS)
    365  1.15.6.1    simonb {
    366  1.15.6.1    simonb 	int t, error;
    367  1.15.6.1    simonb 	struct sysctlnode node;
    368  1.15.6.1    simonb 
    369  1.15.6.1    simonb 	node = *rnode;
    370  1.15.6.1    simonb 	t = *(int*)rnode->sysctl_data;
    371  1.15.6.1    simonb 	node.sysctl_data = &t;
    372  1.15.6.1    simonb 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    373  1.15.6.1    simonb 	if (error || newp == NULL)
    374  1.15.6.1    simonb 		return (error);
    375  1.15.6.1    simonb 
    376  1.15.6.1    simonb 	if (t < 0 || t > 1)
    377  1.15.6.1    simonb 		return EINVAL;
    378  1.15.6.1    simonb 
    379  1.15.6.1    simonb 	if (rnode->sysctl_data == &ipsec_replay)
    380  1.15.6.1    simonb 		printf("fast_ipsec: Anti-Replay service %s\n",
    381  1.15.6.1    simonb 		    (t == 1) ? "deactivated" : "activated");
    382  1.15.6.1    simonb 	else if (rnode->sysctl_data == &ipsec_integrity)
    383  1.15.6.1    simonb 		 printf("fast_ipsec: HMAC corruption %s\n",
    384  1.15.6.1    simonb 		     (t == 0) ? "deactivated" : "activated");
    385  1.15.6.1    simonb 
    386  1.15.6.1    simonb 	*(int*)rnode->sysctl_data = t;
    387  1.15.6.1    simonb 
    388  1.15.6.1    simonb 	return 0;
    389  1.15.6.1    simonb }
    390  1.15.6.1    simonb #endif
    391  1.15.6.1    simonb 
    392       1.4    atatat /* XXX will need a different oid at parent */
    393      1.10  jonathan SYSCTL_SETUP(sysctl_net_inet_fast_ipsec_setup, "sysctl net.inet.ipsec subtree setup")
    394       1.4    atatat {
    395      1.14    atatat 	const struct sysctlnode *_ipsec;
    396      1.11    atatat 	int ipproto_ipsec;
    397       1.4    atatat 
    398       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    399       1.8    atatat 		       CTLFLAG_PERMANENT,
    400       1.4    atatat 		       CTLTYPE_NODE, "net", NULL,
    401       1.4    atatat 		       NULL, 0, NULL, 0,
    402       1.4    atatat 		       CTL_NET, CTL_EOL);
    403       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    404       1.8    atatat 		       CTLFLAG_PERMANENT,
    405       1.4    atatat 		       CTLTYPE_NODE, "inet", NULL,
    406       1.4    atatat 		       NULL, 0, NULL, 0,
    407       1.4    atatat 		       CTL_NET, PF_INET, CTL_EOL);
    408      1.10  jonathan 
    409      1.11    atatat 	/*
    410      1.11    atatat 	 * in numerical order:
    411      1.11    atatat 	 *
    412      1.11    atatat 	 * net.inet.ipip:	CTL_NET.PF_INET.IPPROTO_IPIP
    413      1.11    atatat 	 * net.inet.esp:	CTL_NET.PF_INET.IPPROTO_ESP
    414      1.11    atatat 	 * net.inet.ah:		CTL_NET.PF_INET.IPPROTO_AH
    415      1.11    atatat 	 * net.inet.ipcomp:	CTL_NET.PF_INET.IPPROTO_IPCOMP
    416      1.11    atatat 	 * net.inet.ipsec:	CTL_NET.PF_INET.CTL_CREATE
    417      1.11    atatat 	 *
    418      1.11    atatat 	 * this creates separate trees by name, but maintains that the
    419      1.11    atatat 	 * ipsec name leads to all the old leaves.
    420      1.11    atatat 	 */
    421      1.11    atatat 
    422      1.11    atatat 	/* create net.inet.ipip */
    423       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    424       1.8    atatat 		       CTLFLAG_PERMANENT,
    425      1.11    atatat 		       CTLTYPE_NODE, "ipip", NULL,
    426       1.4    atatat 		       NULL, 0, NULL, 0,
    427      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_IPIP, CTL_EOL);
    428      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    429      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    430      1.11    atatat 		       CTLTYPE_STRUCT, "ipip_stats", NULL,
    431      1.11    atatat 		       NULL, 0, &ipipstat, sizeof(ipipstat),
    432      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_IPIP,
    433      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    434       1.4    atatat 
    435      1.11    atatat 	/* create net.inet.esp subtree under IPPROTO_ESP */
    436      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    437      1.11    atatat 		       CTLFLAG_PERMANENT,
    438      1.11    atatat 		       CTLTYPE_NODE, "esp", NULL,
    439      1.11    atatat 		       NULL, 0, NULL, 0,
    440      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_ESP, CTL_EOL);
    441      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    442      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    443      1.11    atatat 		       CTLTYPE_INT, "trans_deflev", NULL,
    444      1.11    atatat 		       sysctl_fast_ipsec, 0, &ip4_esp_trans_deflev, 0,
    445      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_ESP,
    446      1.11    atatat 		       IPSECCTL_DEF_ESP_TRANSLEV, CTL_EOL);
    447      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    448      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    449      1.11    atatat 		       CTLTYPE_INT, "net_deflev", NULL,
    450      1.11    atatat 		       sysctl_fast_ipsec, 0, &ip4_esp_net_deflev, 0,
    451      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_ESP,
    452      1.11    atatat 		       IPSECCTL_DEF_ESP_NETLEV, CTL_EOL);
    453       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    454      1.10  jonathan 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    455      1.11    atatat 		       CTLTYPE_STRUCT, "esp_stats", NULL,
    456      1.11    atatat 		       NULL, 0, &espstat, sizeof(espstat),
    457      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_ESP,
    458      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    459      1.10  jonathan 
    460      1.11    atatat 	/* create net.inet.ah subtree under IPPROTO_AH */
    461      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    462      1.11    atatat 		       CTLFLAG_PERMANENT,
    463      1.11    atatat 		       CTLTYPE_NODE, "ah", NULL,
    464      1.11    atatat 		       NULL, 0, NULL, 0,
    465      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_AH, CTL_EOL);
    466       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    467       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    468      1.10  jonathan 		       CTLTYPE_INT, "cleartos", NULL,
    469      1.10  jonathan 		       NULL, 0, &/*ip4_*/ah_cleartos, 0,
    470       1.4    atatat 		       CTL_NET, PF_INET, IPPROTO_AH,
    471      1.10  jonathan 		       IPSECCTL_AH_CLEARTOS, CTL_EOL);
    472       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    473       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    474      1.10  jonathan 		       CTLTYPE_INT, "offsetmask", NULL,
    475      1.10  jonathan 		       NULL, 0, &ip4_ah_offsetmask, 0,
    476       1.4    atatat 		       CTL_NET, PF_INET, IPPROTO_AH,
    477      1.10  jonathan 		       IPSECCTL_AH_OFFSETMASK, CTL_EOL);
    478       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    479       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    480      1.10  jonathan 		       CTLTYPE_INT, "trans_deflev", NULL,
    481       1.4    atatat 		       sysctl_fast_ipsec, 0, &ip4_ah_trans_deflev, 0,
    482      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_AH,
    483       1.4    atatat 		       IPSECCTL_DEF_AH_TRANSLEV, CTL_EOL);
    484       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    485       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    486      1.10  jonathan 		       CTLTYPE_INT, "net_deflev", NULL,
    487       1.4    atatat 		       sysctl_fast_ipsec, 0, &ip4_ah_net_deflev, 0,
    488      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_AH,
    489       1.4    atatat 		       IPSECCTL_DEF_AH_NETLEV, CTL_EOL);
    490      1.10  jonathan 	sysctl_createv(clog, 0, NULL, NULL,
    491      1.10  jonathan 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    492      1.11    atatat 		       CTLTYPE_STRUCT, "ah_stats", NULL,
    493      1.11    atatat 		       NULL, 0, &ahstat, sizeof(ahstat),
    494      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_AH,
    495      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    496      1.10  jonathan 
    497      1.10  jonathan 	/* create net.inet.ipcomp */
    498      1.10  jonathan 	sysctl_createv(clog, 0, NULL, NULL,
    499      1.10  jonathan 		       CTLFLAG_PERMANENT,
    500      1.10  jonathan 		       CTLTYPE_NODE, "ipcomp", NULL,
    501      1.10  jonathan 		       NULL, 0, NULL, 0,
    502      1.10  jonathan 		       CTL_NET, PF_INET, IPPROTO_IPCOMP, CTL_EOL);
    503      1.10  jonathan 	sysctl_createv(clog, 0, NULL, NULL,
    504      1.10  jonathan 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    505      1.11    atatat 		       CTLTYPE_STRUCT, "ipcomp_stats", NULL,
    506      1.10  jonathan 		       NULL, 0, &ipcompstat, sizeof(ipcompstat),
    507      1.10  jonathan 		       CTL_NET, PF_INET, IPPROTO_IPCOMP,
    508      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    509      1.10  jonathan 
    510      1.11    atatat 	/* create net.inet.ipsec subtree under dynamic oid */
    511      1.11    atatat 	sysctl_createv(clog, 0, NULL, &_ipsec,
    512      1.10  jonathan 		       CTLFLAG_PERMANENT,
    513      1.10  jonathan 		       CTLTYPE_NODE, "ipsec", NULL,
    514      1.10  jonathan 		       NULL, 0, NULL, 0,
    515      1.11    atatat 		       CTL_NET, PF_INET, CTL_CREATE, CTL_EOL);
    516      1.11    atatat 	ipproto_ipsec = (_ipsec != NULL) ? _ipsec->sysctl_num : 0;
    517      1.10  jonathan 
    518       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    519       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    520      1.10  jonathan 		       CTLTYPE_INT, "def_policy", NULL,
    521      1.10  jonathan 		       sysctl_fast_ipsec, 0, &ip4_def_policy.policy, 0,
    522      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    523      1.10  jonathan 		       IPSECCTL_DEF_POLICY, CTL_EOL);
    524       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    525       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    526      1.11    atatat 		       CTLTYPE_INT, "esp_trans_deflev", NULL,
    527      1.11    atatat 		       sysctl_fast_ipsec, 0, &ip4_esp_trans_deflev, 0,
    528      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    529      1.11    atatat 		       IPSECCTL_DEF_ESP_TRANSLEV, CTL_EOL);
    530      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    531      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    532      1.11    atatat 		       CTLTYPE_INT, "esp_net_deflev", NULL,
    533      1.11    atatat 		       sysctl_fast_ipsec, 0, &ip4_esp_net_deflev, 0,
    534      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    535      1.11    atatat 		       IPSECCTL_DEF_ESP_NETLEV, CTL_EOL);
    536      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    537      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    538      1.11    atatat 		       CTLTYPE_INT, "ah_trans_deflev", NULL,
    539      1.11    atatat 		       sysctl_fast_ipsec, 0, &ip4_ah_trans_deflev, 0,
    540      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    541      1.11    atatat 		       IPSECCTL_DEF_AH_TRANSLEV, CTL_EOL);
    542      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    543      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    544      1.11    atatat 		       CTLTYPE_INT, "ah_net_deflev", NULL,
    545      1.11    atatat 		       sysctl_fast_ipsec, 0, &ip4_ah_net_deflev, 0,
    546      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    547      1.11    atatat 		       IPSECCTL_DEF_AH_NETLEV, CTL_EOL);
    548      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    549      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    550      1.11    atatat 		       CTLTYPE_INT, "ah_cleartos", NULL,
    551      1.11    atatat 		       NULL, 0, &/*ip4_*/ah_cleartos, 0,
    552      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    553      1.11    atatat 		       IPSECCTL_AH_CLEARTOS, CTL_EOL);
    554      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    555      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    556      1.11    atatat 		       CTLTYPE_INT, "ah_offsetmask", NULL,
    557      1.11    atatat 		       NULL, 0, &ip4_ah_offsetmask, 0,
    558      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    559      1.11    atatat 		       IPSECCTL_AH_OFFSETMASK, CTL_EOL);
    560      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    561      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    562       1.4    atatat 		       CTLTYPE_INT, "dfbit", NULL,
    563       1.4    atatat 		       NULL, 0, &ip4_ipsec_dfbit, 0,
    564      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    565       1.4    atatat 		       IPSECCTL_DFBIT, CTL_EOL);
    566       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    567       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    568       1.4    atatat 		       CTLTYPE_INT, "ecn", NULL,
    569       1.4    atatat 		       NULL, 0, &ip4_ipsec_ecn, 0,
    570      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    571       1.4    atatat 		       IPSECCTL_ECN, CTL_EOL);
    572       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    573       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    574       1.4    atatat 		       CTLTYPE_INT, "debug", NULL,
    575       1.4    atatat 		       NULL, 0, &ipsec_debug, 0,
    576      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    577       1.4    atatat 		       IPSECCTL_DEBUG, CTL_EOL);
    578       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    579      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    580      1.11    atatat 		       CTLTYPE_STRUCT, "ipsecstats", NULL,
    581      1.11    atatat 		       NULL, 0, &ipsecstat, sizeof(ipsecstat),
    582      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    583      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    584  1.15.6.1    simonb #ifdef IPSEC_DEBUG
    585  1.15.6.1    simonb 	sysctl_createv(clog, 0, NULL, NULL,
    586  1.15.6.1    simonb 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    587  1.15.6.1    simonb 		       CTLTYPE_INT, "test_replay",
    588  1.15.6.1    simonb 		       SYSCTL_DESCR("Emulate replay attack"),
    589  1.15.6.1    simonb 		       sysctl_fast_ipsec_test, 0, &ipsec_replay, 0,
    590  1.15.6.1    simonb 		       CTL_NET, PF_INET, ipproto_ipsec,
    591  1.15.6.1    simonb 		       CTL_CREATE, CTL_EOL);
    592  1.15.6.1    simonb 	sysctl_createv(clog, 0, NULL, NULL,
    593  1.15.6.1    simonb 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    594  1.15.6.1    simonb 		       CTLTYPE_INT, "test_integrity",
    595  1.15.6.1    simonb 		       SYSCTL_DESCR("Emulate man-in-the-middle attack"),
    596  1.15.6.1    simonb 		       sysctl_fast_ipsec_test, 0, &ipsec_integrity, 0,
    597  1.15.6.1    simonb 		       CTL_NET, PF_INET, ipproto_ipsec,
    598  1.15.6.1    simonb 		       CTL_CREATE, CTL_EOL);
    599  1.15.6.1    simonb #endif
    600       1.1  jonathan }
    601