| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: key.c,v 1.163 2017/06/02 03:32:51 ozaki-r Exp $ */ | | 1 | /* $NetBSD: key.c,v 1.164 2017/06/10 14:21:01 ozaki-r Exp $ */ |
2 | /* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */ | | 2 | /* $FreeBSD: src/sys/netipsec/key.c,v 1.3.2.3 2004/02/14 22:23:23 bms Exp $ */ |
3 | /* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */ | | 3 | /* $KAME: key.c,v 1.191 2001/06/27 10:46:49 sakane Exp $ */ |
4 | | | 4 | |
5 | /* | | 5 | /* |
6 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | | 6 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
7 | * All rights reserved. | | 7 | * All rights reserved. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -22,27 +22,27 @@ | | | @@ -22,27 +22,27 @@ |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | | 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | * SUCH DAMAGE. | | 31 | * SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | #include <sys/cdefs.h> | | 34 | #include <sys/cdefs.h> |
35 | __KERNEL_RCSID(0, "$NetBSD: key.c,v 1.163 2017/06/02 03:32:51 ozaki-r Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: key.c,v 1.164 2017/06/10 14:21:01 ozaki-r Exp $"); |
36 | | | 36 | |
37 | /* | | 37 | /* |
38 | * This code is referd to RFC 2367 | | 38 | * This code is referd to RFC 2367 |
39 | */ | | 39 | */ |
40 | | | 40 | |
41 | #if defined(_KERNEL_OPT) | | 41 | #if defined(_KERNEL_OPT) |
42 | #include "opt_inet.h" | | 42 | #include "opt_inet.h" |
43 | #include "opt_ipsec.h" | | 43 | #include "opt_ipsec.h" |
44 | #include "opt_gateway.h" | | 44 | #include "opt_gateway.h" |
45 | #endif | | 45 | #endif |
46 | | | 46 | |
47 | #include <sys/types.h> | | 47 | #include <sys/types.h> |
48 | #include <sys/param.h> | | 48 | #include <sys/param.h> |
| @@ -6006,26 +6006,32 @@ key_getcomb_ah(void) | | | @@ -6006,26 +6006,32 @@ key_getcomb_ah(void) |
6006 | KASSERTMSG(l <= MLEN, | | 6006 | KASSERTMSG(l <= MLEN, |
6007 | "l=%u > MLEN=%lu", l, (u_long) MLEN); | | 6007 | "l=%u > MLEN=%lu", l, (u_long) MLEN); |
6008 | MGET(m, M_DONTWAIT, MT_DATA); | | 6008 | MGET(m, M_DONTWAIT, MT_DATA); |
6009 | if (m) { | | 6009 | if (m) { |
6010 | M_ALIGN(m, l); | | 6010 | M_ALIGN(m, l); |
6011 | m->m_len = l; | | 6011 | m->m_len = l; |
6012 | m->m_next = NULL; | | 6012 | m->m_next = NULL; |
6013 | } | | 6013 | } |
6014 | } else | | 6014 | } else |
6015 | M_PREPEND(m, l, M_DONTWAIT); | | 6015 | M_PREPEND(m, l, M_DONTWAIT); |
6016 | if (!m) | | 6016 | if (!m) |
6017 | return NULL; | | 6017 | return NULL; |
6018 | | | 6018 | |
| | | 6019 | if (m->m_len < sizeof(struct sadb_comb)) { |
| | | 6020 | m = m_pullup(m, sizeof(struct sadb_comb)); |
| | | 6021 | if (m == NULL) |
| | | 6022 | return NULL; |
| | | 6023 | } |
| | | 6024 | |
6019 | comb = mtod(m, struct sadb_comb *); | | 6025 | comb = mtod(m, struct sadb_comb *); |
6020 | memset(comb, 0, sizeof(*comb)); | | 6026 | memset(comb, 0, sizeof(*comb)); |
6021 | key_getcomb_setlifetime(comb); | | 6027 | key_getcomb_setlifetime(comb); |
6022 | comb->sadb_comb_auth = i; | | 6028 | comb->sadb_comb_auth = i; |
6023 | comb->sadb_comb_auth_minbits = _BITS(minkeysize); | | 6029 | comb->sadb_comb_auth_minbits = _BITS(minkeysize); |
6024 | comb->sadb_comb_auth_maxbits = _BITS(maxkeysize); | | 6030 | comb->sadb_comb_auth_maxbits = _BITS(maxkeysize); |
6025 | } | | 6031 | } |
6026 | | | 6032 | |
6027 | return m; | | 6033 | return m; |
6028 | } | | 6034 | } |
6029 | | | 6035 | |
6030 | /* | | 6036 | /* |
6031 | * not really an official behavior. discussed in pf_key@inner.net in Sep2000. | | 6037 | * not really an official behavior. discussed in pf_key@inner.net in Sep2000. |
| @@ -6050,26 +6056,32 @@ key_getcomb_ipcomp(void) | | | @@ -6050,26 +6056,32 @@ key_getcomb_ipcomp(void) |
6050 | KASSERTMSG(l <= MLEN, | | 6056 | KASSERTMSG(l <= MLEN, |
6051 | "l=%u > MLEN=%lu", l, (u_long) MLEN); | | 6057 | "l=%u > MLEN=%lu", l, (u_long) MLEN); |
6052 | MGET(m, M_DONTWAIT, MT_DATA); | | 6058 | MGET(m, M_DONTWAIT, MT_DATA); |
6053 | if (m) { | | 6059 | if (m) { |
6054 | M_ALIGN(m, l); | | 6060 | M_ALIGN(m, l); |
6055 | m->m_len = l; | | 6061 | m->m_len = l; |
6056 | m->m_next = NULL; | | 6062 | m->m_next = NULL; |
6057 | } | | 6063 | } |
6058 | } else | | 6064 | } else |
6059 | M_PREPEND(m, l, M_DONTWAIT); | | 6065 | M_PREPEND(m, l, M_DONTWAIT); |
6060 | if (!m) | | 6066 | if (!m) |
6061 | return NULL; | | 6067 | return NULL; |
6062 | | | 6068 | |
| | | 6069 | if (m->m_len < sizeof(struct sadb_comb)) { |
| | | 6070 | m = m_pullup(m, sizeof(struct sadb_comb)); |
| | | 6071 | if (m == NULL) |
| | | 6072 | return NULL; |
| | | 6073 | } |
| | | 6074 | |
6063 | comb = mtod(m, struct sadb_comb *); | | 6075 | comb = mtod(m, struct sadb_comb *); |
6064 | memset(comb, 0, sizeof(*comb)); | | 6076 | memset(comb, 0, sizeof(*comb)); |
6065 | key_getcomb_setlifetime(comb); | | 6077 | key_getcomb_setlifetime(comb); |
6066 | comb->sadb_comb_encrypt = i; | | 6078 | comb->sadb_comb_encrypt = i; |
6067 | /* what should we set into sadb_comb_*_{min,max}bits? */ | | 6079 | /* what should we set into sadb_comb_*_{min,max}bits? */ |
6068 | } | | 6080 | } |
6069 | | | 6081 | |
6070 | return m; | | 6082 | return m; |
6071 | } | | 6083 | } |
6072 | | | 6084 | |
6073 | /* | | 6085 | /* |
6074 | * XXX no way to pass mode (transport/tunnel) to userland | | 6086 | * XXX no way to pass mode (transport/tunnel) to userland |
6075 | * XXX replay checking? | | 6087 | * XXX replay checking? |