From nobody Mon Oct 18 17:33:53 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id EDC6717F750E; Mon, 18 Oct 2021 17:33:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HY3rd51w1z3H5n; Mon, 18 Oct 2021 17:33:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 866FE248E2; Mon, 18 Oct 2021 17:33:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19IHXr7B045858; Mon, 18 Oct 2021 17:33:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19IHXrFJ045857; Mon, 18 Oct 2021 17:33:53 GMT (envelope-from git) Date: Mon, 18 Oct 2021 17:33:53 GMT Message-Id: <202110181733.19IHXrFJ045857@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 147f018a720b - main - Move in6_pcbsetport() to in6_pcb.c List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 147f018a720b80da4ba61bec90a6efc6eaa4913e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=147f018a720b80da4ba61bec90a6efc6eaa4913e commit 147f018a720b80da4ba61bec90a6efc6eaa4913e Author: Gleb Smirnoff AuthorDate: 2021-10-18 17:11:20 +0000 Commit: Gleb Smirnoff CommitDate: 2021-10-18 17:19:03 +0000 Move in6_pcbsetport() to in6_pcb.c This function was originally carved out of in6_pcbbind(), which is in in6_pcb.c. This function also uses KPI private to the PCB database - in_pcb_lport(). --- sys/netinet6/in6_pcb.c | 38 ++++++++++++++++++++++++++++++++++++++ sys/netinet6/in6_src.c | 42 ------------------------------------------ 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 14b95dfe0254..10a29f339773 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -114,6 +114,44 @@ __FBSDID("$FreeBSD$"); #include #include +int +in6_pcbsetport(struct in6_addr *laddr, struct inpcb *inp, struct ucred *cred) +{ + struct socket *so = inp->inp_socket; + u_int16_t lport = 0; + int error, lookupflags = 0; +#ifdef INVARIANTS + struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; +#endif + + INP_WLOCK_ASSERT(inp); + INP_HASH_WLOCK_ASSERT(pcbinfo); + + error = prison_local_ip6(cred, laddr, + ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)); + if (error) + return(error); + + /* XXX: this is redundant when called from in6_pcbbind */ + if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT|SO_REUSEPORT_LB)) == 0) + lookupflags = INPLOOKUP_WILDCARD; + + inp->inp_flags |= INP_ANONPORT; + + error = in_pcb_lport(inp, NULL, &lport, cred, lookupflags); + if (error != 0) + return (error); + + inp->inp_lport = lport; + if (in_pcbinshash(inp) != 0) { + inp->in6p_laddr = in6addr_any; + inp->inp_lport = 0; + return (EAGAIN); + } + + return (0); +} + int in6_pcbbind(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred) diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 7f623709de13..875e0a63745c 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -926,48 +926,6 @@ in6_selecthlim(struct inpcb *inp, struct ifnet *ifp) return (V_ip6_defhlim); } -/* - * XXX: this is borrowed from in6_pcbbind(). If possible, we should - * share this function by all *bsd*... - */ -int -in6_pcbsetport(struct in6_addr *laddr, struct inpcb *inp, struct ucred *cred) -{ - struct socket *so = inp->inp_socket; - u_int16_t lport = 0; - int error, lookupflags = 0; -#ifdef INVARIANTS - struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; -#endif - - INP_WLOCK_ASSERT(inp); - INP_HASH_WLOCK_ASSERT(pcbinfo); - - error = prison_local_ip6(cred, laddr, - ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)); - if (error) - return(error); - - /* XXX: this is redundant when called from in6_pcbbind */ - if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT|SO_REUSEPORT_LB)) == 0) - lookupflags = INPLOOKUP_WILDCARD; - - inp->inp_flags |= INP_ANONPORT; - - error = in_pcb_lport(inp, NULL, &lport, cred, lookupflags); - if (error != 0) - return (error); - - inp->inp_lport = lport; - if (in_pcbinshash(inp) != 0) { - inp->in6p_laddr = in6addr_any; - inp->inp_lport = 0; - return (EAGAIN); - } - - return (0); -} - void addrsel_policy_init(void) {