From nobody Fri Feb 03 19:34:21 2023 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 4P7m7L0LXfz3kgCq; Fri, 3 Feb 2023 19:34:22 +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 4P7m7K6nZYz3BxL; Fri, 3 Feb 2023 19:34:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675452862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=t5sJijeUcfH/e0QRA5u0qds7u7ef5Qy6Y5iKjXOD5N8=; b=CkKP0/lSNTYCI6Ru7fHHJgrAdII5dBtSTfWkuWtGd8Vojs2NKLZfpFq233N3InA12PlS2t ziYFzYEm2DyfwjqxW5W7qXG9Imd1V7nOYiyp/Hh0aa4dbjJFsE3pzL/vzVIEMjDkD5n2p5 KA1dsNs0z+wlmQT2D9zEa9tJSybNv2JDBvhZG/oapC9E7Th59qWL2Cex47ZUpQuI9QbNSE utctans/gWwAlgy0DT7cU13qwWDyxnG+1rldWpRNv9NHi3RbLM/Pk6GM+9o0dlH0tLFUOO YceY4npZVJWLVLWsh2C+qsZ4YfPlcAWRUEUF1oNOFHAwLRSMxyqFLNGpHH8cXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675452862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=t5sJijeUcfH/e0QRA5u0qds7u7ef5Qy6Y5iKjXOD5N8=; b=qayOxCQFzlNbMq/47kygil1JJRsLZty+e30A3WfoWZAwkB5qk1t7t9VJqmeRasYTDTFs33 S8DZuOBslHUlH8ftTDFlT2Z1DFfePt9fIOycKQi9JkZQbx4q5kfym7C+oXBfETVrJVxBmr v7A6AjNWiukw3GAw4NH99/mjpp5xmc3HwY7TTd4WKi+A4QBgkmmpQmimLVm+fzHRb6B4lg FRRuxrISNosHJKuhvC9qcXWs4Grr9S8keJwi2m8pYimoVDLgnYWZkXYnWyR2l21IZMm+et 1kdoVm7SUm5/qzKUe6sEsD8ii7shKqlTTg62/CZVV8JcpsZPsii+hwpfTAC0/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675452862; a=rsa-sha256; cv=none; b=MJ4GwDSRBoBbKiADbHZKHgNd5sbRbva1tP2Q2PNwD0nbcQeTvyiRTejklLvwDwg90kldvS Co7KwdIZlAJevAESq78YqZg504pKrlG98xDgO/2QrWfx4v3gMTHjMYU59DaQ/Pe6kIqHZk 3CFMWttCV7b/qcgBzRmp+vQ6Gw95vPczEBFfyUGaH/O1y076bZFzbxdr/zt6fStdXlMFzJ VgC0YFdvM+HoWZQkB8/COq+6zR7Opk9Vcw9HpX0TEh1cFHnubSHI8WZyIky4oKBDoKSZKt Lp/BBqSqGbbuE8yS0WMMztp1rGfd6K2/kNX/wiISGhUDjHB0pOJXEuDTGJQzTA== 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 4P7m7K5sZXzmqW; Fri, 3 Feb 2023 19:34:21 +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 313JYLna041437; Fri, 3 Feb 2023 19:34:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313JYL6D041436; Fri, 3 Feb 2023 19:34:21 GMT (envelope-from git) Date: Fri, 3 Feb 2023 19:34:21 GMT Message-Id: <202302031934.313JYL6D041436@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: a9d22cce10b7 - main - inpcb: use family specific sockaddr argument for connect functions 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: a9d22cce10b710445aba500c96b6eb43cb5e8323 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=a9d22cce10b710445aba500c96b6eb43cb5e8323 commit a9d22cce10b710445aba500c96b6eb43cb5e8323 Author: Gleb Smirnoff AuthorDate: 2023-02-03 19:33:36 +0000 Commit: Gleb Smirnoff CommitDate: 2023-02-03 19:33:36 +0000 inpcb: use family specific sockaddr argument for connect functions Do the cast from sockaddr to either IPv4 or IPv6 sockaddr in the protocol's pr_connect method and from there on go down the call stack with family specific argument. Reviewed by: markj Differential revision: https://reviews.freebsd.org/D38356 --- sys/netinet/in_pcb.c | 7 +++---- sys/netinet/in_pcb.h | 5 +++-- sys/netinet/tcp_syncache.c | 6 ++---- sys/netinet/tcp_usrreq.c | 33 ++++++++++++++------------------- sys/netinet/udp_usrreq.c | 4 ++-- sys/netinet6/in6_pcb.c | 3 +-- sys/netinet6/in6_pcb.h | 3 ++- sys/netinet6/udp6_usrreq.c | 5 ++--- 8 files changed, 29 insertions(+), 37 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 954fe5482076..ab8d0acbd9a7 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1055,7 +1055,7 @@ in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp, * then pick one. */ int -in_pcbconnect(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred, +in_pcbconnect(struct inpcb *inp, struct sockaddr_in *sin, struct ucred *cred, bool rehash) { u_short lport, fport; @@ -1068,7 +1068,7 @@ in_pcbconnect(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred, lport = inp->inp_lport; laddr = inp->inp_laddr.s_addr; anonport = (lport == 0); - error = in_pcbconnect_setup(inp, nam, &laddr, &lport, &faddr, &fport, + error = in_pcbconnect_setup(inp, sin, &laddr, &lport, &faddr, &fport, NULL, cred); if (error) return (error); @@ -1327,11 +1327,10 @@ done: * is set to NULL. */ int -in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam, +in_pcbconnect_setup(struct inpcb *inp, struct sockaddr_in *sin, in_addr_t *laddrp, u_short *lportp, in_addr_t *faddrp, u_short *fportp, struct inpcb **oinpp, struct ucred *cred) { - struct sockaddr_in *sin = (struct sockaddr_in *)nam; struct in_ifaddr *ia; struct inpcb *oinp; struct in_addr laddr, faddr; diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 2f9cebb5ef15..e0e630a8675e 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -742,8 +742,9 @@ int in_pcballoc(struct socket *, struct inpcbinfo *); int in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *); int in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *, u_short *, struct ucred *); -int in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *, bool); -int in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *, +int in_pcbconnect(struct inpcb *, struct sockaddr_in *, struct ucred *, + bool); +int in_pcbconnect_setup(struct inpcb *, struct sockaddr_in *, in_addr_t *, u_short *, in_addr_t *, u_short *, struct inpcb **, struct ucred *); void in_pcbdetach(struct inpcb *); diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index 2b817fee7260..a1f07ed1aadf 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -882,8 +882,7 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m) if (IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_laddr)) inp->in6p_laddr = sc->sc_inc.inc6_laddr; INP_HASH_WLOCK(&V_tcbinfo); - error = in6_pcbconnect(inp, (struct sockaddr *)&sin6, - thread0.td_ucred, false); + error = in6_pcbconnect(inp, &sin6, thread0.td_ucred, false); INP_HASH_WUNLOCK(&V_tcbinfo); if (error != 0) { inp->in6p_laddr = laddr6; @@ -918,8 +917,7 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m) if (inp->inp_laddr.s_addr == INADDR_ANY) inp->inp_laddr = sc->sc_inc.inc_laddr; INP_HASH_WLOCK(&V_tcbinfo); - error = in_pcbconnect(inp, (struct sockaddr *)&sin, - thread0.td_ucred, false); + error = in_pcbconnect(inp, &sin, thread0.td_ucred, false); INP_HASH_WUNLOCK(&V_tcbinfo); if (error != 0) { inp->inp_laddr = laddr; diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index df71b1c88faa..6f979c053a5c 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -118,11 +118,11 @@ __FBSDID("$FreeBSD$"); * TCP protocol interface to socket abstraction. */ #ifdef INET -static int tcp_connect(struct tcpcb *, struct sockaddr *, +static int tcp_connect(struct tcpcb *, struct sockaddr_in *, struct thread *td); #endif /* INET */ #ifdef INET6 -static int tcp6_connect(struct tcpcb *, struct sockaddr *, +static int tcp6_connect(struct tcpcb *, struct sockaddr_in6 *, struct thread *td); #endif /* INET6 */ static void tcp_disconnect(struct tcpcb *); @@ -482,7 +482,7 @@ tcp_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td) } tp = intotcpcb(inp); NET_EPOCH_ENTER(et); - if ((error = tcp_connect(tp, nam, td)) != 0) + if ((error = tcp_connect(tp, sinp, td)) != 0) goto out_in_epoch; #ifdef TCP_OFFLOAD if (registered_toedevs > 0 && @@ -574,7 +574,7 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td) inp->inp_vflag |= INP_IPV4; inp->inp_vflag &= ~INP_IPV6; NET_EPOCH_ENTER(et); - if ((error = tcp_connect(tp, (struct sockaddr *)&sin, td)) != 0) + if ((error = tcp_connect(tp, &sin, td)) != 0) goto out_in_epoch; #ifdef TCP_OFFLOAD if (registered_toedevs > 0 && @@ -597,7 +597,7 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td) inp->inp_vflag |= INP_IPV6; inp->inp_inc.inc_flags |= INC_ISIPV6; NET_EPOCH_ENTER(et); - if ((error = tcp6_connect(tp, nam, td)) != 0) + if ((error = tcp6_connect(tp, sin6, td)) != 0) goto out_in_epoch; #ifdef TCP_OFFLOAD if (registered_toedevs > 0 && @@ -864,6 +864,7 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr_in *sinp; #endif #ifdef INET6 + struct sockaddr_in6 *sin6; int isipv6; #endif u_int8_t incflagsav; @@ -934,9 +935,6 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, #endif /* INET */ #ifdef INET6 case AF_INET6: - { - struct sockaddr_in6 *sin6; - sin6 = (struct sockaddr_in6 *)nam; if (sin6->sin6_len != sizeof(*sin6)) { error = EINVAL; @@ -991,7 +989,6 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, isipv6 = 1; } break; - } #endif /* INET6 */ default: error = EAFNOSUPPORT; @@ -1014,14 +1011,13 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, */ #ifdef INET6 if (isipv6) - error = tcp6_connect(tp, nam, td); + error = tcp6_connect(tp, sin6, td); #endif /* INET6 */ #if defined(INET6) && defined(INET) else #endif #ifdef INET - error = tcp_connect(tp, - (struct sockaddr *)sinp, td); + error = tcp_connect(tp, sinp, td); #endif /* * The bind operation in tcp_connect succeeded. We @@ -1106,14 +1102,13 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, tp->t_flags &= ~TF_FASTOPEN; #ifdef INET6 if (isipv6) - error = tcp6_connect(tp, nam, td); + error = tcp6_connect(tp, sin6, td); #endif /* INET6 */ #if defined(INET6) && defined(INET) else #endif #ifdef INET - error = tcp_connect(tp, - (struct sockaddr *)sinp, td); + error = tcp_connect(tp, sinp, td); #endif /* * The bind operation in tcp_connect succeeded. We @@ -1401,7 +1396,7 @@ struct protosw tcp6_protosw = { * Initialize connection parameters and enter SYN-SENT state. */ static int -tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td) +tcp_connect(struct tcpcb *tp, struct sockaddr_in *sin, struct thread *td) { struct inpcb *inp = tptoinpcb(tp), *oinp; struct socket *so = tptosocket(tp); @@ -1420,7 +1415,7 @@ tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td) */ laddr = inp->inp_laddr; lport = inp->inp_lport; - error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport, + error = in_pcbconnect_setup(inp, sin, &laddr.s_addr, &lport, &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred); if (error && oinp == NULL) goto out; @@ -1468,7 +1463,7 @@ out: #ifdef INET6 static int -tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td) +tcp6_connect(struct tcpcb *tp, struct sockaddr_in6 *sin6, struct thread *td) { struct inpcb *inp = tptoinpcb(tp); struct epoch_tracker et; @@ -1478,7 +1473,7 @@ tcp6_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td) NET_EPOCH_ENTER(et); INP_HASH_WLOCK(&V_tcbinfo); - error = in6_pcbconnect(inp, nam, td->td_ucred, true); + error = in6_pcbconnect(inp, sin6, td->td_ucred, true); INP_HASH_WUNLOCK(&V_tcbinfo); NET_EPOCH_EXIT(et); if (error != 0) diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 4efeb6a0e8e7..540045fc3bc3 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1252,7 +1252,7 @@ udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, sin->sin_addr.s_addr == INADDR_ANY || sin->sin_addr.s_addr == INADDR_BROADCAST) { INP_HASH_WLOCK(pcbinfo); - error = in_pcbconnect_setup(inp, addr, &laddr.s_addr, + error = in_pcbconnect_setup(inp, sin, &laddr.s_addr, &lport, &faddr.s_addr, &fport, NULL, td->td_ucred); if (error) { @@ -1603,7 +1603,7 @@ udp_connect(struct socket *so, struct sockaddr *nam, struct thread *td) } NET_EPOCH_ENTER(et); INP_HASH_WLOCK(pcbinfo); - error = in_pcbconnect(inp, nam, td->td_ucred, true); + error = in_pcbconnect(inp, sin, td->td_ucred, true); INP_HASH_WUNLOCK(pcbinfo); NET_EPOCH_EXIT(et); if (error == 0) diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index a76997d75ff3..1b57fce7ec47 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -412,11 +412,10 @@ in6_pcbladdr(struct inpcb *inp, struct sockaddr_in6 *sin6, * then pick one. */ int -in6_pcbconnect(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred, +in6_pcbconnect(struct inpcb *inp, struct sockaddr_in6 *sin6, struct ucred *cred, bool rehash) { struct inpcbinfo *pcbinfo = inp->inp_pcbinfo; - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam; struct sockaddr_in6 laddr6; int error; diff --git a/sys/netinet6/in6_pcb.h b/sys/netinet6/in6_pcb.h index bf84576736e4..0d3de62ddd54 100644 --- a/sys/netinet6/in6_pcb.h +++ b/sys/netinet6/in6_pcb.h @@ -74,7 +74,8 @@ void in6_pcbpurgeif0(struct inpcbinfo *, struct ifnet *); void in6_losing(struct inpcb *); int in6_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *); -int in6_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *, bool); +int in6_pcbconnect(struct inpcb *, struct sockaddr_in6 *, struct ucred *, + bool); void in6_pcbdisconnect(struct inpcb *); struct inpcb * in6_pcblookup_local(struct inpcbinfo *, diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 7ce4c9974228..3e6c57a8c6ff 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -1147,8 +1147,7 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td) inp->inp_vflag &= ~INP_IPV6; NET_EPOCH_ENTER(et); INP_HASH_WLOCK(pcbinfo); - error = in_pcbconnect(inp, (struct sockaddr *)&sin, - td->td_ucred, true); + error = in_pcbconnect(inp, &sin, td->td_ucred, true); INP_HASH_WUNLOCK(pcbinfo); NET_EPOCH_EXIT(et); /* @@ -1181,7 +1180,7 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct thread *td) inp->inp_vflag |= INP_IPV6; NET_EPOCH_ENTER(et); INP_HASH_WLOCK(pcbinfo); - error = in6_pcbconnect(inp, nam, td->td_ucred, true); + error = in6_pcbconnect(inp, sin6, td->td_ucred, true); INP_HASH_WUNLOCK(pcbinfo); NET_EPOCH_EXIT(et); /*