git: a9d22cce10b7 - main - inpcb: use family specific sockaddr argument for connect functions
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 03 Feb 2023 19:34:21 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=a9d22cce10b710445aba500c96b6eb43cb5e8323 commit a9d22cce10b710445aba500c96b6eb43cb5e8323 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2023-02-03 19:33:36 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> 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); /*