From owner-svn-src-projects@freebsd.org Sun Jan 1 22:49:16 2017 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5F9B9C9B6AE for ; Sun, 1 Jan 2017 22:49:16 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 085FB1A04; Sun, 1 Jan 2017 22:49:15 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v01MnFQj041811; Sun, 1 Jan 2017 22:49:15 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v01MnFqJ041810; Sun, 1 Jan 2017 22:49:15 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201701012249.v01MnFqJ041810@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Sun, 1 Jan 2017 22:49:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r311038 - projects/ipsec/sys/netipsec X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Jan 2017 22:49:16 -0000 Author: ae Date: Sun Jan 1 22:49:15 2017 New Revision: 311038 URL: https://svnweb.freebsd.org/changeset/base/311038 Log: Simplify ipsec_copy_pcbpolicy(). It is called from TCP syncache code for new socket. So, it is expected, that it has not configured policies. Modified: projects/ipsec/sys/netipsec/ipsec_pcb.c Modified: projects/ipsec/sys/netipsec/ipsec_pcb.c ============================================================================== --- projects/ipsec/sys/netipsec/ipsec_pcb.c Sun Jan 1 21:24:20 2017 (r311037) +++ projects/ipsec/sys/netipsec/ipsec_pcb.c Sun Jan 1 22:49:15 2017 (r311038) @@ -125,7 +125,10 @@ ipsec_deepcopy_pcbpolicy(struct secpolic return (dst); } -/* Copy old IPsec policy into new. */ +/* + * Copy IPsec policy from old INPCB into new. + * It is expected that new INPCB has not configured policies. + */ int ipsec_copy_pcbpolicy(struct inpcb *old, struct inpcb *new) { @@ -140,39 +143,26 @@ ipsec_copy_pcbpolicy(struct inpcb *old, return (0); IPSEC_ASSERT(new->inp_sp != NULL, ("new inp_sp is NULL")); + IPSEC_ASSERT((new->inp_sp->flags & ( + INP_INBOUND_POLICY | INP_OUTBOUND_POLICY)) == 0, + ("new PCB already has configured policies")); INP_WLOCK_ASSERT(new); + INP_LOCK_ASSERT(old); if (old->inp_sp->flags & INP_INBOUND_POLICY) { sp = ipsec_deepcopy_pcbpolicy(old->inp_sp->sp_in); if (sp == NULL) return (ENOBUFS); - } else - sp = NULL; - - if (new->inp_sp->flags & INP_INBOUND_POLICY) - key_freesp(&new->inp_sp->sp_in); - - new->inp_sp->sp_in = sp; - if (sp != NULL) + new->inp_sp->sp_in = sp; new->inp_sp->flags |= INP_INBOUND_POLICY; - else - new->inp_sp->flags &= ~INP_INBOUND_POLICY; - + } if (old->inp_sp->flags & INP_OUTBOUND_POLICY) { sp = ipsec_deepcopy_pcbpolicy(old->inp_sp->sp_out); if (sp == NULL) return (ENOBUFS); - } else - sp = NULL; - - if (new->inp_sp->flags & INP_OUTBOUND_POLICY) - key_freesp(&new->inp_sp->sp_out); - - new->inp_sp->sp_out = sp; - if (sp != NULL) + new->inp_sp->sp_out = sp; new->inp_sp->flags |= INP_OUTBOUND_POLICY; - else - new->inp_sp->flags &= ~INP_OUTBOUND_POLICY; + } return (0); }