Home | History | Annotate | Line # | Download | only in netipsec
ipsec_netbsd.c revision 1.47.2.2
      1  1.47.2.2  pgoyette /*	$NetBSD: ipsec_netbsd.c,v 1.47.2.2 2018/05/02 07:20:24 pgoyette 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.47.2.2  pgoyette __KERNEL_RCSID(0, "$NetBSD: ipsec_netbsd.c,v 1.47.2.2 2018/05/02 07:20:24 pgoyette Exp $");
     36       1.1  jonathan 
     37      1.40     ozaki #if defined(_KERNEL_OPT)
     38       1.1  jonathan #include "opt_inet.h"
     39       1.1  jonathan #include "opt_ipsec.h"
     40      1.40     ozaki #endif
     41       1.1  jonathan 
     42       1.1  jonathan #include <sys/param.h>
     43       1.1  jonathan #include <sys/systm.h>
     44       1.1  jonathan #include <sys/mbuf.h>
     45       1.1  jonathan #include <sys/domain.h>
     46       1.1  jonathan #include <sys/protosw.h>
     47       1.1  jonathan #include <sys/socket.h>
     48       1.1  jonathan #include <sys/errno.h>
     49       1.1  jonathan #include <sys/time.h>
     50       1.1  jonathan #include <sys/kernel.h>
     51       1.1  jonathan #include <sys/sysctl.h>
     52       1.1  jonathan 
     53       1.1  jonathan #include <net/if.h>
     54       1.1  jonathan #include <net/route.h>
     55       1.1  jonathan #include <net/netisr.h>
     56      1.29        ad #include <sys/cpu.h>
     57       1.1  jonathan 
     58       1.1  jonathan #include <netinet/in.h>
     59       1.1  jonathan #include <netinet/in_systm.h>
     60       1.1  jonathan #include <netinet/in_var.h>
     61       1.1  jonathan #include <netinet/ip.h>
     62       1.1  jonathan #include <netinet/ip_var.h>
     63       1.1  jonathan #include <netinet/ip_ecn.h>
     64       1.1  jonathan #include <netinet/ip_icmp.h>
     65       1.1  jonathan 
     66       1.1  jonathan #include <netipsec/ipsec.h>
     67      1.10  jonathan #include <netipsec/ipsec_var.h>
     68      1.30   thorpej #include <netipsec/ipsec_private.h>
     69       1.3       tls #include <netipsec/key.h>
     70       1.3       tls #include <netipsec/keydb.h>
     71       1.3       tls #include <netipsec/key_debug.h>
     72      1.18  degroote #include <netipsec/ah.h>
     73       1.1  jonathan #include <netipsec/ah_var.h>
     74       1.5  jonathan #include <netipsec/esp.h>
     75      1.10  jonathan #include <netipsec/esp_var.h>
     76      1.10  jonathan #include <netipsec/ipip_var.h>
     77      1.10  jonathan #include <netipsec/ipcomp_var.h>
     78       1.5  jonathan 
     79       1.5  jonathan #ifdef INET6
     80       1.5  jonathan #include <netipsec/ipsec6.h>
     81       1.5  jonathan #include <netinet6/ip6protosw.h>
     82       1.5  jonathan #include <netinet/icmp6.h>
     83       1.1  jonathan #endif
     84       1.1  jonathan 
     85       1.3       tls #include <netipsec/key.h>
     86       1.1  jonathan 
     87       1.1  jonathan /* assumes that ip header and ah header are contiguous on mbuf */
     88      1.47      maxv void *
     89      1.28  degroote ah4_ctlinput(int cmd, const struct sockaddr *sa, void *v)
     90       1.1  jonathan {
     91       1.1  jonathan 	struct ip *ip = v;
     92       1.1  jonathan 	struct ah *ah;
     93       1.1  jonathan 	struct icmp *icp;
     94       1.1  jonathan 	struct secasvar *sav;
     95       1.1  jonathan 
     96       1.1  jonathan 	if (sa->sa_family != AF_INET ||
     97      1.47      maxv 	    sa->sa_len != sizeof(struct sockaddr_in))
     98      1.38   msaitoh 		return NULL;
     99       1.1  jonathan 	if ((unsigned)cmd >= PRC_NCMDS)
    100       1.1  jonathan 		return NULL;
    101      1.20  degroote 
    102       1.1  jonathan 	if (cmd == PRC_MSGSIZE && ip_mtudisc && ip && ip->ip_v == 4) {
    103       1.1  jonathan 		/*
    104       1.1  jonathan 		 * Check to see if we have a valid SA corresponding to
    105       1.1  jonathan 		 * the address in the ICMP message payload.
    106       1.1  jonathan 		 */
    107      1.23  degroote 		ah = (struct ah *)((char *)ip + (ip->ip_hl << 2));
    108      1.44     ozaki 		sav = KEY_LOOKUP_SA((const union sockaddr_union *)sa,
    109      1.47      maxv 		    IPPROTO_AH, ah->ah_spi, 0, 0);
    110       1.1  jonathan 
    111      1.20  degroote 		if (sav) {
    112      1.42     ozaki 			if (SADB_SASTATE_USABLE_P(sav)) {
    113      1.20  degroote 				/*
    114      1.47      maxv 				 * Now that we've validated that we are actually
    115      1.47      maxv 				 * communicating with the host indicated in the
    116      1.47      maxv 				 * ICMP message, locate the ICMP header,
    117      1.20  degroote 				 * recalculate the new MTU, and create the
    118      1.47      maxv 				 * corresponding routing entry.
    119      1.47      maxv 				 */
    120      1.47      maxv 				icp = (struct icmp *)((char *)ip -
    121      1.43     ozaki 				    offsetof(struct icmp, icmp_ip));
    122      1.20  degroote 				icmp_mtudisc(icp, ip->ip_dst);
    123      1.20  degroote 			}
    124      1.45     ozaki 			KEY_SA_UNREF(&sav);
    125      1.20  degroote 		}
    126       1.1  jonathan 	}
    127       1.1  jonathan 	return NULL;
    128       1.1  jonathan }
    129       1.1  jonathan 
    130       1.1  jonathan /* assumes that ip header and esp header are contiguous on mbuf */
    131      1.47      maxv void *
    132      1.28  degroote esp4_ctlinput(int cmd, const struct sockaddr *sa, void *v)
    133       1.1  jonathan {
    134       1.1  jonathan 	struct ip *ip = v;
    135       1.1  jonathan 	struct esp *esp;
    136       1.1  jonathan 	struct icmp *icp;
    137       1.1  jonathan 	struct secasvar *sav;
    138       1.1  jonathan 
    139       1.1  jonathan 	if (sa->sa_family != AF_INET ||
    140       1.1  jonathan 	    sa->sa_len != sizeof(struct sockaddr_in))
    141       1.1  jonathan 		return NULL;
    142       1.1  jonathan 	if ((unsigned)cmd >= PRC_NCMDS)
    143       1.1  jonathan 		return NULL;
    144      1.20  degroote 
    145       1.1  jonathan 	if (cmd == PRC_MSGSIZE && ip_mtudisc && ip && ip->ip_v == 4) {
    146       1.1  jonathan 		/*
    147       1.1  jonathan 		 * Check to see if we have a valid SA corresponding to
    148       1.1  jonathan 		 * the address in the ICMP message payload.
    149       1.1  jonathan 		 */
    150      1.23  degroote 		esp = (struct esp *)((char *)ip + (ip->ip_hl << 2));
    151      1.44     ozaki 		sav = KEY_LOOKUP_SA((const union sockaddr_union *)sa,
    152      1.47      maxv 		    IPPROTO_ESP, esp->esp_spi, 0, 0);
    153       1.1  jonathan 
    154      1.20  degroote 		if (sav) {
    155      1.42     ozaki 			if (SADB_SASTATE_USABLE_P(sav)) {
    156      1.20  degroote 				/*
    157      1.47      maxv 				 * Now that we've validated that we are actually
    158      1.47      maxv 				 * communicating with the host indicated in the
    159      1.47      maxv 				 * ICMP message, locate the ICMP header,
    160      1.20  degroote 				 * recalculate the new MTU, and create the
    161      1.47      maxv 				 * corresponding routing entry.
    162      1.47      maxv 				 */
    163      1.47      maxv 				icp = (struct icmp *)((char *)ip -
    164      1.43     ozaki 				    offsetof(struct icmp, icmp_ip));
    165      1.20  degroote 				icmp_mtudisc(icp, ip->ip_dst);
    166      1.20  degroote 			}
    167      1.45     ozaki 			KEY_SA_UNREF(&sav);
    168      1.20  degroote 		}
    169       1.1  jonathan 	}
    170       1.1  jonathan 	return NULL;
    171       1.1  jonathan }
    172       1.1  jonathan 
    173       1.1  jonathan #ifdef INET6
    174      1.31  degroote void *
    175      1.28  degroote ah6_ctlinput(int cmd, const struct sockaddr *sa, void *d)
    176      1.18  degroote {
    177      1.41     ozaki 	const struct newah *ahp;
    178      1.41     ozaki 	struct newah ah;
    179      1.41     ozaki 	struct secasvar *sav;
    180      1.41     ozaki 	struct ip6_hdr *ip6;
    181      1.41     ozaki 	struct mbuf *m;
    182      1.41     ozaki 	struct ip6ctlparam *ip6cp = NULL;
    183      1.41     ozaki 	int off;
    184      1.41     ozaki 
    185      1.41     ozaki 	if (sa->sa_family != AF_INET6 ||
    186      1.41     ozaki 	    sa->sa_len != sizeof(struct sockaddr_in6))
    187      1.41     ozaki 		return NULL;
    188      1.41     ozaki 	if ((unsigned)cmd >= PRC_NCMDS)
    189      1.41     ozaki 		return NULL;
    190      1.41     ozaki 
    191      1.41     ozaki 	/* if the parameter is from icmp6, decode it. */
    192      1.41     ozaki 	if (d != NULL) {
    193      1.41     ozaki 		ip6cp = (struct ip6ctlparam *)d;
    194      1.41     ozaki 		m = ip6cp->ip6c_m;
    195      1.41     ozaki 		ip6 = ip6cp->ip6c_ip6;
    196      1.41     ozaki 		off = ip6cp->ip6c_off;
    197      1.41     ozaki 	} else {
    198      1.41     ozaki 		m = NULL;
    199      1.41     ozaki 		ip6 = NULL;
    200      1.41     ozaki 		off = 0;
    201      1.41     ozaki 	}
    202      1.41     ozaki 
    203      1.41     ozaki 	if (ip6) {
    204      1.41     ozaki 		/* check if we can safely examine src and dst ports */
    205      1.41     ozaki 		if (m->m_pkthdr.len < off + sizeof(ah))
    206      1.41     ozaki 			return NULL;
    207      1.41     ozaki 
    208      1.41     ozaki 		if (m->m_len < off + sizeof(ah)) {
    209      1.41     ozaki 			/*
    210      1.41     ozaki 			 * this should be rare case,
    211      1.41     ozaki 			 * so we compromise on this copy...
    212      1.41     ozaki 			 */
    213      1.41     ozaki 			m_copydata(m, off, sizeof(ah), &ah);
    214      1.41     ozaki 			ahp = &ah;
    215      1.41     ozaki 		} else
    216      1.41     ozaki 			ahp = (struct newah *)(mtod(m, char *) + off);
    217      1.41     ozaki 
    218      1.41     ozaki 		if (cmd == PRC_MSGSIZE) {
    219      1.41     ozaki 			int valid = 0;
    220      1.41     ozaki 
    221      1.41     ozaki 			/*
    222      1.41     ozaki 			 * Check to see if we have a valid SA corresponding
    223      1.41     ozaki 			 * to the address in the ICMP message payload.
    224      1.41     ozaki 			 */
    225  1.47.2.1  pgoyette 			sav = KEY_LOOKUP_SA((const union sockaddr_union *)sa,
    226      1.41     ozaki 			    IPPROTO_AH, ahp->ah_spi, 0, 0);
    227      1.41     ozaki 
    228      1.41     ozaki 			if (sav) {
    229      1.42     ozaki 				if (SADB_SASTATE_USABLE_P(sav))
    230      1.41     ozaki 					valid++;
    231      1.45     ozaki 				KEY_SA_UNREF(&sav);
    232      1.41     ozaki 			}
    233      1.41     ozaki 
    234      1.41     ozaki 			/* XXX Further validation? */
    235      1.41     ozaki 
    236      1.41     ozaki 			/*
    237      1.41     ozaki 			 * Depending on the value of "valid" and routing
    238      1.41     ozaki 			 * table size (mtudisc_{hi,lo}wat), we will:
    239      1.47      maxv 			 * - recalculate the new MTU and create the
    240      1.41     ozaki 			 *   corresponding routing entry, or
    241      1.41     ozaki 			 * - ignore the MTU change notification.
    242      1.41     ozaki 			 */
    243      1.47      maxv 			icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
    244      1.41     ozaki 		}
    245      1.41     ozaki 
    246      1.41     ozaki 		/* we normally notify single pcb here */
    247      1.41     ozaki 	} else {
    248      1.41     ozaki 		/* we normally notify any pcb here */
    249      1.41     ozaki 	}
    250      1.41     ozaki 	return NULL;
    251      1.18  degroote }
    252      1.18  degroote 
    253      1.31  degroote void *
    254      1.28  degroote esp6_ctlinput(int cmd, const struct sockaddr *sa, void *d)
    255       1.1  jonathan {
    256       1.1  jonathan 	const struct newesp *espp;
    257       1.1  jonathan 	struct newesp esp;
    258       1.1  jonathan 	struct ip6ctlparam *ip6cp = NULL, ip6cp1;
    259       1.1  jonathan 	struct secasvar *sav;
    260       1.1  jonathan 	struct ip6_hdr *ip6;
    261       1.1  jonathan 	struct mbuf *m;
    262       1.1  jonathan 	int off;
    263       1.1  jonathan 
    264       1.1  jonathan 	if (sa->sa_family != AF_INET6 ||
    265       1.1  jonathan 	    sa->sa_len != sizeof(struct sockaddr_in6))
    266      1.31  degroote 		return NULL;
    267       1.1  jonathan 	if ((unsigned)cmd >= PRC_NCMDS)
    268      1.31  degroote 		return NULL;
    269       1.1  jonathan 
    270       1.1  jonathan 	/* if the parameter is from icmp6, decode it. */
    271       1.1  jonathan 	if (d != NULL) {
    272       1.1  jonathan 		ip6cp = (struct ip6ctlparam *)d;
    273       1.1  jonathan 		m = ip6cp->ip6c_m;
    274       1.1  jonathan 		ip6 = ip6cp->ip6c_ip6;
    275       1.1  jonathan 		off = ip6cp->ip6c_off;
    276       1.1  jonathan 	} else {
    277       1.1  jonathan 		m = NULL;
    278       1.1  jonathan 		ip6 = NULL;
    279       1.7  jonathan 		off = 0;
    280       1.1  jonathan 	}
    281       1.1  jonathan 
    282       1.1  jonathan 	if (ip6) {
    283       1.1  jonathan 		/*
    284       1.1  jonathan 		 * Notify the error to all possible sockets via pfctlinput2.
    285       1.1  jonathan 		 * Since the upper layer information (such as protocol type,
    286       1.1  jonathan 		 * source and destination ports) is embedded in the encrypted
    287       1.1  jonathan 		 * data and might have been cut, we can't directly call
    288       1.1  jonathan 		 * an upper layer ctlinput function. However, the pcbnotify
    289       1.1  jonathan 		 * function will consider source and destination addresses
    290       1.1  jonathan 		 * as well as the flow info value, and may be able to find
    291       1.1  jonathan 		 * some PCB that should be notified.
    292       1.1  jonathan 		 * Although pfctlinput2 will call esp6_ctlinput(), there is
    293       1.1  jonathan 		 * no possibility of an infinite loop of function calls,
    294       1.1  jonathan 		 * because we don't pass the inner IPv6 header.
    295       1.1  jonathan 		 */
    296      1.20  degroote 		memset(&ip6cp1, 0, sizeof(ip6cp1));
    297       1.1  jonathan 		ip6cp1.ip6c_src = ip6cp->ip6c_src;
    298      1.24  degroote 		pfctlinput2(cmd, sa, &ip6cp1);
    299       1.1  jonathan 
    300       1.1  jonathan 		/* check if we can safely examine src and dst ports */
    301       1.1  jonathan 		if (m->m_pkthdr.len < off + sizeof(esp))
    302      1.31  degroote 			return NULL;
    303       1.1  jonathan 
    304       1.1  jonathan 		if (m->m_len < off + sizeof(esp)) {
    305       1.1  jonathan 			/*
    306       1.1  jonathan 			 * this should be rare case,
    307       1.1  jonathan 			 * so we compromise on this copy...
    308       1.1  jonathan 			 */
    309      1.24  degroote 			m_copydata(m, off, sizeof(esp), &esp);
    310       1.1  jonathan 			espp = &esp;
    311       1.1  jonathan 		} else
    312  1.47.2.1  pgoyette 			espp = (struct newesp *)(mtod(m, char *) + off);
    313       1.1  jonathan 
    314       1.1  jonathan 		if (cmd == PRC_MSGSIZE) {
    315       1.1  jonathan 			int valid = 0;
    316       1.1  jonathan 
    317       1.1  jonathan 			/*
    318       1.1  jonathan 			 * Check to see if we have a valid SA corresponding to
    319       1.1  jonathan 			 * the address in the ICMP message payload.
    320       1.1  jonathan 			 */
    321      1.19  degroote 
    322  1.47.2.1  pgoyette 			sav = KEY_LOOKUP_SA((const union sockaddr_union *)sa,
    323      1.47      maxv 			    IPPROTO_ESP, espp->esp_spi, 0, 0);
    324       1.7  jonathan 
    325       1.1  jonathan 			if (sav) {
    326      1.42     ozaki 				if (SADB_SASTATE_USABLE_P(sav))
    327       1.1  jonathan 					valid++;
    328      1.45     ozaki 				KEY_SA_UNREF(&sav);
    329       1.1  jonathan 			}
    330       1.1  jonathan 
    331       1.1  jonathan 			/* XXX Further validation? */
    332       1.1  jonathan 
    333       1.1  jonathan 			/*
    334       1.1  jonathan 			 * Depending on the value of "valid" and routing table
    335       1.1  jonathan 			 * size (mtudisc_{hi,lo}wat), we will:
    336       1.1  jonathan 			 * - recalcurate the new MTU and create the
    337       1.1  jonathan 			 *   corresponding routing entry, or
    338       1.1  jonathan 			 * - ignore the MTU change notification.
    339       1.1  jonathan 			 */
    340       1.1  jonathan 			icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
    341       1.1  jonathan 		}
    342       1.1  jonathan 	} else {
    343       1.1  jonathan 		/* we normally notify any pcb here */
    344       1.1  jonathan 	}
    345      1.31  degroote 	return NULL;
    346       1.1  jonathan }
    347       1.1  jonathan #endif /* INET6 */
    348       1.1  jonathan 
    349       1.4    atatat static int
    350      1.35  christos sysctl_ipsec(SYSCTLFN_ARGS)
    351       1.1  jonathan {
    352       1.4    atatat 	int error, t;
    353       1.4    atatat 	struct sysctlnode node;
    354       1.4    atatat 
    355       1.4    atatat 	node = *rnode;
    356  1.47.2.1  pgoyette 	t = *(int *)rnode->sysctl_data;
    357       1.4    atatat 	node.sysctl_data = &t;
    358       1.4    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    359       1.4    atatat 	if (error || newp == NULL)
    360  1.47.2.1  pgoyette 		return error;
    361       1.1  jonathan 
    362       1.4    atatat 	switch (rnode->sysctl_num) {
    363       1.1  jonathan 	case IPSECCTL_DEF_ESP_TRANSLEV:
    364       1.1  jonathan 	case IPSECCTL_DEF_ESP_NETLEV:
    365       1.1  jonathan 	case IPSECCTL_DEF_AH_TRANSLEV:
    366       1.1  jonathan 	case IPSECCTL_DEF_AH_NETLEV:
    367      1.13     perry 		if (t != IPSEC_LEVEL_USE &&
    368       1.4    atatat 		    t != IPSEC_LEVEL_REQUIRE)
    369  1.47.2.1  pgoyette 			return EINVAL;
    370       1.4    atatat 		ipsec_invalpcbcacheall();
    371       1.1  jonathan 		break;
    372      1.47      maxv 	case IPSECCTL_DEF_POLICY:
    373       1.4    atatat 		if (t != IPSEC_POLICY_DISCARD &&
    374       1.4    atatat 		    t != IPSEC_POLICY_NONE)
    375  1.47.2.1  pgoyette 			return EINVAL;
    376       1.4    atatat 		ipsec_invalpcbcacheall();
    377       1.1  jonathan 		break;
    378       1.4    atatat 	default:
    379  1.47.2.1  pgoyette 		return EINVAL;
    380       1.1  jonathan 	}
    381       1.1  jonathan 
    382  1.47.2.1  pgoyette 	*(int *)rnode->sysctl_data = t;
    383       1.4    atatat 
    384  1.47.2.1  pgoyette 	return 0;
    385       1.4    atatat }
    386       1.4    atatat 
    387      1.16    rpaulo #ifdef IPSEC_DEBUG
    388      1.16    rpaulo static int
    389      1.35  christos sysctl_ipsec_test(SYSCTLFN_ARGS)
    390      1.16    rpaulo {
    391      1.16    rpaulo 	int t, error;
    392      1.16    rpaulo 	struct sysctlnode node;
    393      1.16    rpaulo 
    394      1.38   msaitoh 	node = *rnode;
    395  1.47.2.1  pgoyette 	t = *(int *)rnode->sysctl_data;
    396      1.16    rpaulo 	node.sysctl_data = &t;
    397      1.16    rpaulo 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    398      1.16    rpaulo 	if (error || newp == NULL)
    399  1.47.2.1  pgoyette 		return error;
    400      1.16    rpaulo 
    401      1.16    rpaulo 	if (t < 0 || t > 1)
    402      1.16    rpaulo 		return EINVAL;
    403      1.16    rpaulo 
    404      1.16    rpaulo 	if (rnode->sysctl_data == &ipsec_replay)
    405      1.35  christos 		printf("ipsec: Anti-Replay service %s\n",
    406      1.16    rpaulo 		    (t == 1) ? "deactivated" : "activated");
    407      1.16    rpaulo 	else if (rnode->sysctl_data == &ipsec_integrity)
    408      1.35  christos 		 printf("ipsec: HMAC corruption %s\n",
    409      1.16    rpaulo 		     (t == 0) ? "deactivated" : "activated");
    410      1.16    rpaulo 
    411  1.47.2.1  pgoyette 	*(int *)rnode->sysctl_data = t;
    412      1.16    rpaulo 
    413      1.16    rpaulo 	return 0;
    414      1.16    rpaulo }
    415      1.16    rpaulo #endif
    416      1.16    rpaulo 
    417      1.30   thorpej static int
    418      1.35  christos sysctl_net_inet_ipsec_stats(SYSCTLFN_ARGS)
    419      1.30   thorpej {
    420      1.30   thorpej 
    421      1.32   thorpej 	return (NETSTAT_SYSCTL(ipsecstat_percpu, IPSEC_NSTATS));
    422      1.30   thorpej }
    423      1.30   thorpej 
    424      1.30   thorpej static int
    425      1.30   thorpej sysctl_net_inet_ah_stats(SYSCTLFN_ARGS)
    426      1.30   thorpej {
    427      1.30   thorpej 
    428      1.32   thorpej 	return (NETSTAT_SYSCTL(ahstat_percpu, AH_NSTATS));
    429      1.30   thorpej }
    430      1.30   thorpej 
    431      1.30   thorpej static int
    432      1.30   thorpej sysctl_net_inet_esp_stats(SYSCTLFN_ARGS)
    433      1.30   thorpej {
    434      1.30   thorpej 
    435      1.32   thorpej 	return (NETSTAT_SYSCTL(espstat_percpu, ESP_NSTATS));
    436      1.30   thorpej }
    437      1.30   thorpej 
    438      1.30   thorpej static int
    439      1.30   thorpej sysctl_net_inet_ipcomp_stats(SYSCTLFN_ARGS)
    440      1.30   thorpej {
    441      1.30   thorpej 
    442      1.32   thorpej 	return (NETSTAT_SYSCTL(ipcompstat_percpu, IPCOMP_NSTATS));
    443      1.30   thorpej }
    444      1.30   thorpej 
    445      1.30   thorpej static int
    446      1.30   thorpej sysctl_net_inet_ipip_stats(SYSCTLFN_ARGS)
    447      1.30   thorpej {
    448      1.30   thorpej 
    449      1.32   thorpej 	return (NETSTAT_SYSCTL(ipipstat_percpu, IPIP_NSTATS));
    450      1.30   thorpej }
    451      1.30   thorpej 
    452      1.37  christos static int
    453      1.37  christos sysctl_net_ipsec_enabled(SYSCTLFN_ARGS)
    454      1.37  christos {
    455      1.37  christos 	int newenabled, error;
    456      1.37  christos 	struct sysctlnode node;
    457      1.37  christos 	node = *rnode;
    458      1.37  christos 	node.sysctl_data = &newenabled;
    459      1.37  christos 
    460      1.37  christos 	newenabled = ipsec_enabled;
    461      1.37  christos 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    462      1.37  christos 	if (error || newp == NULL)
    463      1.37  christos 		return error;
    464      1.37  christos 
    465      1.37  christos 	switch (newenabled) {
    466      1.37  christos 	case 0:
    467      1.37  christos 		if (key_get_used())
    468      1.37  christos 			return EBUSY;
    469      1.37  christos 		/*FALLTHROUGH*/
    470      1.37  christos 	case 1:
    471      1.37  christos 	case 2:
    472      1.37  christos 		ipsec_enabled = newenabled;
    473      1.37  christos 		key_update_used();
    474      1.37  christos 		return 0;
    475      1.37  christos 	default:
    476      1.37  christos 		return EINVAL;
    477      1.37  christos 	}
    478      1.37  christos }
    479      1.37  christos 
    480       1.4    atatat /* XXX will need a different oid at parent */
    481      1.40     ozaki void
    482      1.40     ozaki sysctl_net_inet_ipsec_setup(struct sysctllog **clog)
    483       1.4    atatat {
    484      1.14    atatat 	const struct sysctlnode *_ipsec;
    485      1.11    atatat 	int ipproto_ipsec;
    486       1.4    atatat 
    487       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    488       1.8    atatat 		       CTLFLAG_PERMANENT,
    489       1.4    atatat 		       CTLTYPE_NODE, "inet", NULL,
    490       1.4    atatat 		       NULL, 0, NULL, 0,
    491       1.4    atatat 		       CTL_NET, PF_INET, CTL_EOL);
    492      1.10  jonathan 
    493      1.11    atatat 	/*
    494      1.11    atatat 	 * in numerical order:
    495      1.11    atatat 	 *
    496      1.11    atatat 	 * net.inet.ipip:	CTL_NET.PF_INET.IPPROTO_IPIP
    497      1.11    atatat 	 * net.inet.esp:	CTL_NET.PF_INET.IPPROTO_ESP
    498      1.11    atatat 	 * net.inet.ah:		CTL_NET.PF_INET.IPPROTO_AH
    499      1.11    atatat 	 * net.inet.ipcomp:	CTL_NET.PF_INET.IPPROTO_IPCOMP
    500      1.11    atatat 	 * net.inet.ipsec:	CTL_NET.PF_INET.CTL_CREATE
    501      1.11    atatat 	 *
    502      1.11    atatat 	 * this creates separate trees by name, but maintains that the
    503      1.11    atatat 	 * ipsec name leads to all the old leaves.
    504      1.11    atatat 	 */
    505      1.11    atatat 
    506      1.11    atatat 	/* create net.inet.ipip */
    507       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    508       1.8    atatat 		       CTLFLAG_PERMANENT,
    509      1.11    atatat 		       CTLTYPE_NODE, "ipip", NULL,
    510       1.4    atatat 		       NULL, 0, NULL, 0,
    511      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_IPIP, CTL_EOL);
    512      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    513      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    514      1.11    atatat 		       CTLTYPE_STRUCT, "ipip_stats", NULL,
    515      1.30   thorpej 		       sysctl_net_inet_ipip_stats, 0, NULL, 0,
    516      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_IPIP,
    517      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    518       1.4    atatat 
    519      1.11    atatat 	/* create net.inet.esp subtree under IPPROTO_ESP */
    520      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    521      1.11    atatat 		       CTLFLAG_PERMANENT,
    522      1.11    atatat 		       CTLTYPE_NODE, "esp", NULL,
    523      1.11    atatat 		       NULL, 0, NULL, 0,
    524      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_ESP, CTL_EOL);
    525      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    526      1.10  jonathan 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    527      1.11    atatat 		       CTLTYPE_STRUCT, "esp_stats", NULL,
    528      1.30   thorpej 		       sysctl_net_inet_esp_stats, 0, NULL, 0,
    529      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_ESP,
    530      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    531      1.10  jonathan 
    532      1.11    atatat 	/* create net.inet.ah subtree under IPPROTO_AH */
    533      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    534      1.11    atatat 		       CTLFLAG_PERMANENT,
    535      1.11    atatat 		       CTLTYPE_NODE, "ah", NULL,
    536      1.11    atatat 		       NULL, 0, NULL, 0,
    537      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_AH, CTL_EOL);
    538       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    539      1.10  jonathan 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    540      1.11    atatat 		       CTLTYPE_STRUCT, "ah_stats", NULL,
    541      1.30   thorpej 		       sysctl_net_inet_ah_stats, 0, NULL, 0,
    542      1.11    atatat 		       CTL_NET, PF_INET, IPPROTO_AH,
    543      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    544      1.10  jonathan 
    545      1.10  jonathan 	/* create net.inet.ipcomp */
    546      1.10  jonathan 	sysctl_createv(clog, 0, NULL, NULL,
    547      1.10  jonathan 		       CTLFLAG_PERMANENT,
    548      1.10  jonathan 		       CTLTYPE_NODE, "ipcomp", NULL,
    549      1.10  jonathan 		       NULL, 0, NULL, 0,
    550      1.10  jonathan 		       CTL_NET, PF_INET, IPPROTO_IPCOMP, CTL_EOL);
    551      1.10  jonathan 	sysctl_createv(clog, 0, NULL, NULL,
    552      1.10  jonathan 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    553      1.11    atatat 		       CTLTYPE_STRUCT, "ipcomp_stats", NULL,
    554      1.30   thorpej 		       sysctl_net_inet_ipcomp_stats, 0, NULL, 0,
    555      1.10  jonathan 		       CTL_NET, PF_INET, IPPROTO_IPCOMP,
    556      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    557      1.10  jonathan 
    558      1.11    atatat 	/* create net.inet.ipsec subtree under dynamic oid */
    559      1.11    atatat 	sysctl_createv(clog, 0, NULL, &_ipsec,
    560      1.10  jonathan 		       CTLFLAG_PERMANENT,
    561      1.10  jonathan 		       CTLTYPE_NODE, "ipsec", NULL,
    562      1.10  jonathan 		       NULL, 0, NULL, 0,
    563      1.11    atatat 		       CTL_NET, PF_INET, CTL_CREATE, CTL_EOL);
    564      1.11    atatat 	ipproto_ipsec = (_ipsec != NULL) ? _ipsec->sysctl_num : 0;
    565      1.10  jonathan 
    566       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    567       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    568      1.10  jonathan 		       CTLTYPE_INT, "def_policy", NULL,
    569      1.35  christos 		       sysctl_ipsec, 0, &ip4_def_policy.policy, 0,
    570      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    571      1.10  jonathan 		       IPSECCTL_DEF_POLICY, CTL_EOL);
    572       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    573       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    574      1.11    atatat 		       CTLTYPE_INT, "esp_trans_deflev", NULL,
    575      1.35  christos 		       sysctl_ipsec, 0, &ip4_esp_trans_deflev, 0,
    576      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    577      1.11    atatat 		       IPSECCTL_DEF_ESP_TRANSLEV, CTL_EOL);
    578      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    579      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    580      1.11    atatat 		       CTLTYPE_INT, "esp_net_deflev", NULL,
    581      1.35  christos 		       sysctl_ipsec, 0, &ip4_esp_net_deflev, 0,
    582      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    583      1.11    atatat 		       IPSECCTL_DEF_ESP_NETLEV, CTL_EOL);
    584      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    585      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    586      1.11    atatat 		       CTLTYPE_INT, "ah_trans_deflev", NULL,
    587      1.35  christos 		       sysctl_ipsec, 0, &ip4_ah_trans_deflev, 0,
    588      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    589      1.11    atatat 		       IPSECCTL_DEF_AH_TRANSLEV, CTL_EOL);
    590      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    591      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    592      1.11    atatat 		       CTLTYPE_INT, "ah_net_deflev", NULL,
    593      1.35  christos 		       sysctl_ipsec, 0, &ip4_ah_net_deflev, 0,
    594      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    595      1.11    atatat 		       IPSECCTL_DEF_AH_NETLEV, CTL_EOL);
    596      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    597      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    598      1.11    atatat 		       CTLTYPE_INT, "ah_cleartos", NULL,
    599      1.25  degroote 		       NULL, 0, &ip4_ah_cleartos, 0,
    600      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    601      1.11    atatat 		       IPSECCTL_AH_CLEARTOS, CTL_EOL);
    602      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    603      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    604      1.11    atatat 		       CTLTYPE_INT, "ah_offsetmask", NULL,
    605      1.11    atatat 		       NULL, 0, &ip4_ah_offsetmask, 0,
    606      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    607      1.11    atatat 		       IPSECCTL_AH_OFFSETMASK, CTL_EOL);
    608      1.11    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    609      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    610       1.4    atatat 		       CTLTYPE_INT, "dfbit", NULL,
    611       1.4    atatat 		       NULL, 0, &ip4_ipsec_dfbit, 0,
    612      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    613       1.4    atatat 		       IPSECCTL_DFBIT, CTL_EOL);
    614       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    615       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    616       1.4    atatat 		       CTLTYPE_INT, "ecn", NULL,
    617       1.4    atatat 		       NULL, 0, &ip4_ipsec_ecn, 0,
    618      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    619       1.4    atatat 		       IPSECCTL_ECN, CTL_EOL);
    620       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    621       1.8    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    622       1.4    atatat 		       CTLTYPE_INT, "debug", NULL,
    623       1.4    atatat 		       NULL, 0, &ipsec_debug, 0,
    624      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    625       1.4    atatat 		       IPSECCTL_DEBUG, CTL_EOL);
    626       1.8    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    627  1.47.2.2  pgoyette 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    628  1.47.2.2  pgoyette 		       CTLTYPE_INT, "ipip_spoofcheck", NULL,
    629  1.47.2.2  pgoyette 		       NULL, 0, &ipip_spoofcheck, 0,
    630  1.47.2.2  pgoyette 		       CTL_NET, PF_INET, ipproto_ipsec,
    631  1.47.2.2  pgoyette 		       CTL_CREATE, CTL_EOL);
    632  1.47.2.2  pgoyette 	sysctl_createv(clog, 0, NULL, NULL,
    633      1.11    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    634      1.11    atatat 		       CTLTYPE_STRUCT, "ipsecstats", NULL,
    635      1.35  christos 		       sysctl_net_inet_ipsec_stats, 0, NULL, 0,
    636      1.11    atatat 		       CTL_NET, PF_INET, ipproto_ipsec,
    637      1.11    atatat 		       CTL_CREATE, CTL_EOL);
    638      1.37  christos 	sysctl_createv(clog, 0, NULL, NULL,
    639      1.37  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    640      1.37  christos 		       CTLTYPE_INT, "enabled",
    641      1.37  christos 		       SYSCTL_DESCR("Enable IPSec processing"),
    642      1.37  christos 		       sysctl_net_ipsec_enabled, 0, NULL, 0,
    643      1.37  christos 		       CTL_NET, PF_INET, ipproto_ipsec,
    644      1.37  christos 		       CTL_CREATE, CTL_EOL);
    645      1.37  christos 	sysctl_createv(clog, 0, NULL, NULL,
    646      1.37  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    647      1.37  christos 		       CTLTYPE_INT, "used",
    648      1.37  christos 		       SYSCTL_DESCR("Is IPSec active?"),
    649      1.37  christos 		       NULL, 0, &ipsec_used, 0,
    650      1.37  christos 		       CTL_NET, PF_INET, ipproto_ipsec,
    651      1.37  christos 		       CTL_CREATE, CTL_EOL);
    652      1.39  knakahar 	sysctl_createv(clog, 0, NULL, NULL,
    653      1.39  knakahar 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    654      1.46      maxv 		       CTLTYPE_INT, "ah_enable", NULL,
    655      1.46      maxv 		       NULL, 0, &ah_enable, 0,
    656      1.46      maxv 		       CTL_NET, PF_INET, ipproto_ipsec,
    657      1.46      maxv 		       CTL_CREATE, CTL_EOL);
    658      1.46      maxv 	sysctl_createv(clog, 0, NULL, NULL,
    659      1.46      maxv 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    660      1.46      maxv 		       CTLTYPE_INT, "esp_enable", NULL,
    661      1.46      maxv 		       NULL, 0, &esp_enable, 0,
    662      1.46      maxv 		       CTL_NET, PF_INET, ipproto_ipsec,
    663      1.46      maxv 		       CTL_CREATE, CTL_EOL);
    664      1.46      maxv 	sysctl_createv(clog, 0, NULL, NULL,
    665      1.46      maxv 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    666      1.46      maxv 		       CTLTYPE_INT, "ipcomp_enable", NULL,
    667      1.46      maxv 		       NULL, 0, &ipcomp_enable, 0,
    668      1.46      maxv 		       CTL_NET, PF_INET, ipproto_ipsec,
    669      1.46      maxv 		       CTL_CREATE, CTL_EOL);
    670      1.46      maxv 	sysctl_createv(clog, 0, NULL, NULL,
    671      1.46      maxv 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    672      1.39  knakahar 		       CTLTYPE_INT, "crypto_support", NULL,
    673      1.39  knakahar 		       NULL, 0, &crypto_support, 0,
    674      1.39  knakahar 		       CTL_NET, PF_INET, ipproto_ipsec,
    675      1.39  knakahar 		       CTL_CREATE, CTL_EOL);
    676      1.46      maxv 
    677      1.16    rpaulo #ifdef IPSEC_DEBUG
    678      1.16    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
    679      1.16    rpaulo 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    680      1.16    rpaulo 		       CTLTYPE_INT, "test_replay",
    681      1.16    rpaulo 		       SYSCTL_DESCR("Emulate replay attack"),
    682      1.35  christos 		       sysctl_ipsec_test, 0, &ipsec_replay, 0,
    683      1.16    rpaulo 		       CTL_NET, PF_INET, ipproto_ipsec,
    684      1.16    rpaulo 		       CTL_CREATE, CTL_EOL);
    685      1.16    rpaulo 	sysctl_createv(clog, 0, NULL, NULL,
    686      1.16    rpaulo 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    687      1.16    rpaulo 		       CTLTYPE_INT, "test_integrity",
    688      1.16    rpaulo 		       SYSCTL_DESCR("Emulate man-in-the-middle attack"),
    689      1.35  christos 		       sysctl_ipsec_test, 0, &ipsec_integrity, 0,
    690      1.16    rpaulo 		       CTL_NET, PF_INET, ipproto_ipsec,
    691      1.16    rpaulo 		       CTL_CREATE, CTL_EOL);
    692      1.16    rpaulo #endif
    693       1.1  jonathan }
    694      1.26  degroote 
    695      1.26  degroote #ifdef INET6
    696      1.40     ozaki void
    697      1.40     ozaki sysctl_net_inet6_ipsec6_setup(struct sysctllog **clog)
    698      1.26  degroote {
    699      1.26  degroote 
    700      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    701      1.26  degroote 		       CTLFLAG_PERMANENT,
    702      1.26  degroote 		       CTLTYPE_NODE, "inet6", NULL,
    703      1.26  degroote 		       NULL, 0, NULL, 0,
    704      1.26  degroote 		       CTL_NET, PF_INET6, CTL_EOL);
    705      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    706      1.26  degroote 		       CTLFLAG_PERMANENT,
    707      1.26  degroote 		       CTLTYPE_NODE, "ipsec6",
    708      1.26  degroote 		       SYSCTL_DESCR("IPv6 related IPSec settings"),
    709      1.26  degroote 		       NULL, 0, NULL, 0,
    710      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH, CTL_EOL);
    711      1.26  degroote 
    712      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    713      1.26  degroote 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    714      1.26  degroote 		       CTLTYPE_STRUCT, "stats",
    715      1.26  degroote 		       SYSCTL_DESCR("IPSec statistics and counters"),
    716      1.35  christos 		       sysctl_net_inet_ipsec_stats, 0, NULL, 0,
    717      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH,
    718      1.26  degroote 		       IPSECCTL_STATS, CTL_EOL);
    719      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    720      1.26  degroote 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    721      1.26  degroote 		       CTLTYPE_INT, "def_policy",
    722      1.26  degroote 		       SYSCTL_DESCR("Default action for non-IPSec packets"),
    723  1.47.2.2  pgoyette 		       sysctl_ipsec, 0, &ip6_def_policy.policy, 0,
    724      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH,
    725      1.26  degroote 		       IPSECCTL_DEF_POLICY, CTL_EOL);
    726      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    727      1.26  degroote 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    728      1.26  degroote 		       CTLTYPE_INT, "esp_trans_deflev",
    729      1.26  degroote 		       SYSCTL_DESCR("Default required security level for "
    730      1.26  degroote 				    "transport mode traffic"),
    731      1.35  christos 		       sysctl_ipsec, 0, &ip6_esp_trans_deflev, 0,
    732      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH,
    733      1.26  degroote 		       IPSECCTL_DEF_ESP_TRANSLEV, CTL_EOL);
    734      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    735      1.26  degroote 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    736      1.26  degroote 		       CTLTYPE_INT, "esp_net_deflev",
    737      1.26  degroote 		       SYSCTL_DESCR("Default required security level for "
    738      1.26  degroote 				    "tunneled traffic"),
    739      1.35  christos 		       sysctl_ipsec, 0, &ip6_esp_net_deflev, 0,
    740      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH,
    741      1.26  degroote 		       IPSECCTL_DEF_ESP_NETLEV, CTL_EOL);
    742      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    743      1.26  degroote 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    744      1.26  degroote 		       CTLTYPE_INT, "ah_trans_deflev",
    745      1.26  degroote 		       SYSCTL_DESCR("Default required security level for "
    746      1.26  degroote 				    "transport mode headers"),
    747      1.35  christos 		       sysctl_ipsec, 0, &ip6_ah_trans_deflev, 0,
    748      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH,
    749      1.26  degroote 		       IPSECCTL_DEF_AH_TRANSLEV, CTL_EOL);
    750      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    751      1.26  degroote 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    752      1.26  degroote 		       CTLTYPE_INT, "ah_net_deflev",
    753      1.26  degroote 		       SYSCTL_DESCR("Default required security level for "
    754      1.26  degroote 				    "tunneled headers"),
    755      1.35  christos 		       sysctl_ipsec, 0, &ip6_ah_net_deflev, 0,
    756      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH,
    757      1.26  degroote 		       IPSECCTL_DEF_AH_NETLEV, CTL_EOL);
    758      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    759      1.26  degroote 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    760      1.26  degroote 		       CTLTYPE_INT, "ecn",
    761      1.26  degroote 		       SYSCTL_DESCR("Behavior of ECN for tunneled traffic"),
    762      1.26  degroote 		       NULL, 0, &ip6_ipsec_ecn, 0,
    763      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH,
    764      1.26  degroote 		       IPSECCTL_ECN, CTL_EOL);
    765      1.26  degroote 	sysctl_createv(clog, 0, NULL, NULL,
    766      1.26  degroote 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    767      1.26  degroote 		       CTLTYPE_INT, "debug",
    768      1.26  degroote 		       SYSCTL_DESCR("Enable IPSec debugging output"),
    769      1.26  degroote 		       NULL, 0, &ipsec_debug, 0,
    770      1.26  degroote 		       CTL_NET, PF_INET6, IPPROTO_AH,
    771      1.26  degroote 		       IPSECCTL_DEBUG, CTL_EOL);
    772      1.37  christos 	sysctl_createv(clog, 0, NULL, NULL,
    773      1.37  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    774      1.37  christos 		       CTLTYPE_INT, "enabled",
    775      1.37  christos 		       SYSCTL_DESCR("Enable IPSec processing"),
    776      1.37  christos 		       sysctl_net_ipsec_enabled, 0, NULL, 0,
    777      1.37  christos 		       CTL_NET, PF_INET6, IPPROTO_AH,
    778      1.37  christos 		       CTL_CREATE, CTL_EOL);
    779      1.37  christos 	sysctl_createv(clog, 0, NULL, NULL,
    780      1.37  christos 		       CTLFLAG_PERMANENT|CTLFLAG_READONLY,
    781      1.37  christos 		       CTLTYPE_INT, "used",
    782      1.37  christos 		       SYSCTL_DESCR("Is IPSec active?"),
    783      1.37  christos 		       NULL, 0, &ipsec_used, 0,
    784      1.37  christos 		       CTL_NET, PF_INET6, IPPROTO_AH,
    785      1.37  christos 		       CTL_CREATE, CTL_EOL);
    786      1.26  degroote }
    787      1.26  degroote #endif /* INET6 */
    788