From cff23a6b16962577314a62a2c3229aba06fe95e3 Mon Sep 17 00:00:00 2001 From: bluhm Date: Fri, 1 Dec 2023 14:08:03 +0000 Subject: [PATCH] Make internet PCB connect more consistent. The public interface is in_pcbconnect(). It dispatches to in6_pcbconnect() if necessary. Call the former from tcp_connect() and udp_connect(). In in6_pcbconnect() initialization in6a = NULL is not necessary. in6_pcbselsrc() sets the pointer, but does not read the value. Pass a constant in6_addr pointer to in6_pcbselsrc() and in6_selectsrc(). It returns a reference to the address of some internal data structure. We want to be sure that in6_addr is not modified this way. IPv4 in_pcbselsrc() solves this by passing a copy of the address. OK kn@ sashan@ mvs@ --- sys/netinet/tcp_usrreq.c | 5 ++--- sys/netinet/udp_usrreq.c | 6 ++---- sys/netinet6/in6_pcb.c | 4 ++-- sys/netinet6/in6_src.c | 6 +++--- sys/netinet6/ip6_var.h | 6 +++--- sys/netinet6/raw_ip6.c | 6 +++--- sys/netinet6/udp6_output.c | 4 ++-- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index e83ad108289..e7f9767e0ae 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_usrreq.c,v 1.224 2023/11/28 13:23:20 bluhm Exp $ */ +/* $OpenBSD: tcp_usrreq.c,v 1.225 2023/12/01 14:08:03 bluhm Exp $ */ /* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */ /* @@ -635,7 +635,6 @@ tcp_connect(struct socket *so, struct mbuf *nam) error = EINVAL; goto out; } - error = in6_pcbconnect(inp, nam); } else #endif /* INET6 */ { @@ -650,8 +649,8 @@ tcp_connect(struct socket *so, struct mbuf *nam) error = EINVAL; goto out; } - error = in_pcbconnect(inp, nam); } + error = in_pcbconnect(inp, nam); if (error) goto out; diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 6c40f766a21..836939175a0 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.310 2023/11/29 18:30:48 bluhm Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.311 2023/12/01 14:08:03 bluhm Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -1153,15 +1153,13 @@ udp_connect(struct socket *so, struct mbuf *addr) if (inp->inp_flags & INP_IPV6) { if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) return (EISCONN); - error = in6_pcbconnect(inp, addr); } else #endif /* INET6 */ { if (inp->inp_faddr.s_addr != INADDR_ANY) return (EISCONN); - error = in_pcbconnect(inp, addr); } - + error = in_pcbconnect(inp, addr); if (error) return (error); diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 8933b493e97..6529063e49d 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_pcb.c,v 1.126 2023/11/29 18:30:48 bluhm Exp $ */ +/* $OpenBSD: in6_pcb.c,v 1.127 2023/12/01 14:08:04 bluhm Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -245,7 +245,7 @@ in6_pcbaddrisavail(struct inpcb *inp, struct sockaddr_in6 *sin6, int wild, int in6_pcbconnect(struct inpcb *inp, struct mbuf *nam) { - struct in6_addr *in6a = NULL; + const struct in6_addr *in6a; struct sockaddr_in6 *sin6; struct inpcb *t; int error; diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index a3741c0892d..7128b0d2f9e 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6_src.c,v 1.87 2023/11/28 13:23:20 bluhm Exp $ */ +/* $OpenBSD: in6_src.c,v 1.88 2023/12/01 14:08:04 bluhm Exp $ */ /* $KAME: in6_src.c,v 1.36 2001/02/06 04:08:17 itojun Exp $ */ /* @@ -91,7 +91,7 @@ int in6_selectif(struct sockaddr_in6 *, struct ip6_pktopts *, * the values set at pcb level can be overridden via cmsg. */ int -in6_pcbselsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock, +in6_pcbselsrc(const struct in6_addr **in6src, struct sockaddr_in6 *dstsock, struct inpcb *inp, struct ip6_pktopts *opts) { struct ip6_moptions *mopts = inp->inp_moptions6; @@ -249,7 +249,7 @@ in6_pcbselsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock, * an entry to the caller for later use. */ int -in6_selectsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock, +in6_selectsrc(const struct in6_addr **in6src, struct sockaddr_in6 *dstsock, struct ip6_moptions *mopts, unsigned int rtableid) { struct ifnet *ifp = NULL; diff --git a/sys/netinet6/ip6_var.h b/sys/netinet6/ip6_var.h index f5b8839b266..ae7c7f92560 100644 --- a/sys/netinet6/ip6_var.h +++ b/sys/netinet6/ip6_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_var.h,v 1.107 2023/11/26 22:08:10 bluhm Exp $ */ +/* $OpenBSD: ip6_var.h,v 1.108 2023/12/01 14:08:04 bluhm Exp $ */ /* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */ /* @@ -365,9 +365,9 @@ int rip6_sysctl(int *, u_int, void *, size_t *, void *, size_t); int dest6_input(struct mbuf **, int *, int, int); int none_input(struct mbuf **, int *, int); -int in6_pcbselsrc(struct in6_addr **, struct sockaddr_in6 *, +int in6_pcbselsrc(const struct in6_addr **, struct sockaddr_in6 *, struct inpcb *, struct ip6_pktopts *); -int in6_selectsrc(struct in6_addr **, struct sockaddr_in6 *, +int in6_selectsrc(const struct in6_addr **, struct sockaddr_in6 *, struct ip6_moptions *, unsigned int); struct rtentry *in6_selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, struct route_in6 *, unsigned int rtableid); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 0a91302e407..94bf4934ccf 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: raw_ip6.c,v 1.175 2023/11/28 13:23:20 bluhm Exp $ */ +/* $OpenBSD: raw_ip6.c,v 1.176 2023/12/01 14:08:04 bluhm Exp $ */ /* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */ /* @@ -451,7 +451,7 @@ rip6_output(struct mbuf *m, struct socket *so, struct sockaddr *dstaddr, * Source address selection. */ { - struct in6_addr *in6a; + const struct in6_addr *in6a; error = in6_pcbselsrc(&in6a, satosin6(dstaddr), in6p, optp); if (error) @@ -683,7 +683,7 @@ rip6_connect(struct socket *so, struct mbuf *nam) { struct inpcb *in6p = sotoinpcb(so); struct sockaddr_in6 *addr; - struct in6_addr *in6a = NULL; + const struct in6_addr *in6a; int error; soassertlocked(so); diff --git a/sys/netinet6/udp6_output.c b/sys/netinet6/udp6_output.c index 876b9b753a8..4638c1e81a0 100644 --- a/sys/netinet6/udp6_output.c +++ b/sys/netinet6/udp6_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp6_output.c,v 1.61 2023/11/28 13:23:20 bluhm Exp $ */ +/* $OpenBSD: udp6_output.c,v 1.62 2023/12/01 14:08:04 bluhm Exp $ */ /* $KAME: udp6_output.c,v 1.21 2001/02/07 11:51:54 itojun Exp $ */ /* @@ -101,7 +101,7 @@ udp6_output(struct inpcb *in6p, struct mbuf *m, struct mbuf *addr6, int error = 0, priv = 0, hlen, flags; struct ip6_hdr *ip6; struct udphdr *udp6; - struct in6_addr *laddr, *faddr; + const struct in6_addr *laddr, *faddr; struct ip6_pktopts *optp, opt; struct sockaddr_in6 tmp, valid; struct proc *p = curproc; /* XXX */ -- 2.20.1