diff --git a/sys/net/if_ipsec.c b/sys/net/if_ipsec.c index ce1023d9e847..956871e2478e 100644 --- a/sys/net/if_ipsec.c +++ b/sys/net/if_ipsec.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_ipsec.c,v 1.13 2018/04/27 09:55:27 knakahara Exp $ */ +/* $NetBSD: if_ipsec.c,v 1.14 2018/05/24 07:00:28 knakahara Exp $ */ /* * Copyright (c) 2017 Internet Initiative Japan Inc. @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.13 2018/04/27 09:55:27 knakahara Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ipsec.c,v 1.14 2018/05/24 07:00:28 knakahara Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -1574,13 +1574,18 @@ if_ipsec_add_sp0(struct sockaddr *src, in_port_t sport, m_copyback(m, 0, sizeof(msg), &msg); if_ipsec_add_mbuf(m, &xsrc, sizeof(xsrc)); - if_ipsec_add_mbuf_addr_port(m, src, sport, true); + /* + * secpolicy.spidx.{src, dst} must not be set port number, + * even if it is used for NAT-T. + */ + if_ipsec_add_mbuf_addr_port(m, src, 0, true); padlen = PFKEY_UNUNIT64(xsrc.sadb_address_len) - (sizeof(xsrc) + PFKEY_ALIGN8(src->sa_len)); if_ipsec_add_pad(m, padlen); if_ipsec_add_mbuf(m, &xdst, sizeof(xdst)); - if_ipsec_add_mbuf_addr_port(m, dst, dport, true); + /* ditto */ + if_ipsec_add_mbuf_addr_port(m, dst, 0, true); padlen = PFKEY_UNUNIT64(xdst.sadb_address_len) - (sizeof(xdst) + PFKEY_ALIGN8(dst->sa_len)); if_ipsec_add_pad(m, padlen); @@ -1588,6 +1593,10 @@ if_ipsec_add_sp0(struct sockaddr *src, in_port_t sport, if_ipsec_add_mbuf(m, &xpl, sizeof(xpl)); if (policy == IPSEC_POLICY_IPSEC) { if_ipsec_add_mbuf(m, &xisr, sizeof(xisr)); + /* + * secpolicy.req->saidx.{src, dst} must be set port number, + * when it is used for NAT-T. + */ if_ipsec_add_mbuf_addr_port(m, src, sport, false); if_ipsec_add_mbuf_addr_port(m, dst, dport, false); }