this is basically the same as what i did for in_pcbselsrc, and
completely mechanical. im too tired to figure out if there's a smarter
way to do it.

lightly tested, and more eyes are welcome because of the tiredness
thing.

Index: in6_pcb.c
===================================================================
RCS file: /cvs/src/sys/netinet6/in6_pcb.c,v
retrieving revision 1.117
diff -u -p -r1.117 in6_pcb.c
--- in6_pcb.c   14 Apr 2022 14:10:22 -0000      1.117
+++ in6_pcb.c   15 May 2022 09:53:53 -0000
@@ -235,7 +235,7 @@ in6_pcbaddrisavail(struct inpcb *inp, st
 int
 in6_pcbconnect(struct inpcb *inp, struct mbuf *nam)
 {
-       struct in6_addr *in6a = NULL;
+       struct in6_addr in6a;
        struct sockaddr_in6 *sin6;
        int error;
        struct sockaddr_in6 tmp;
@@ -273,7 +273,8 @@ in6_pcbconnect(struct inpcb *inp, struct
        inp->inp_ipv6.ip6_hlim = (u_int8_t)in6_selecthlim(inp);
 
        if (in6_pcbhashlookup(inp->inp_table, &sin6->sin6_addr, sin6->sin6_port,
-           IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) ? in6a : &inp->inp_laddr6,
+           IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) ?
+            &in6a : &inp->inp_laddr6,
            inp->inp_lport, inp->inp_rtableid) != NULL) {
                return (EADDRINUSE);
        }
@@ -286,13 +287,13 @@ in6_pcbconnect(struct inpcb *inp, struct
                        if (error)
                                return (error);
                        if (in6_pcbhashlookup(inp->inp_table, &sin6->sin6_addr,
-                           sin6->sin6_port, in6a, inp->inp_lport,
+                           sin6->sin6_port, &in6a, inp->inp_lport,
                            inp->inp_rtableid) != NULL) {
                                inp->inp_lport = 0;
                                return (EADDRINUSE);
                        }
                }
-               inp->inp_laddr6 = *in6a;
+               inp->inp_laddr6 = in6a;
        }
        inp->inp_faddr6 = sin6->sin6_addr;
        inp->inp_fport = sin6->sin6_port;
Index: in6_src.c
===================================================================
RCS file: /cvs/src/sys/netinet6/in6_src.c,v
retrieving revision 1.86
diff -u -p -r1.86 in6_src.c
--- in6_src.c   22 Feb 2022 01:15:02 -0000      1.86
+++ in6_src.c   15 May 2022 09:53:53 -0000
@@ -91,7 +91,7 @@ int in6_selectif(struct sockaddr_in6 *, 
  * the values set at pcb level can be overridden via cmsg.
  */
 int
-in6_pcbselsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock,
+in6_pcbselsrc(struct in6_addr *in6src, struct sockaddr_in6 *dstsock,
     struct inpcb *inp, struct ip6_pktopts *opts)
 {
        struct ip6_moptions *mopts = inp->inp_moptions6;
@@ -138,7 +138,7 @@ in6_pcbselsrc(struct in6_addr **in6src, 
 
                pi->ipi6_addr = sa6.sin6_addr; /* XXX: this overrides pi */
 
-               *in6src = &pi->ipi6_addr;
+               *in6src = pi->ipi6_addr;
                return (0);
        }
 
@@ -147,7 +147,7 @@ in6_pcbselsrc(struct in6_addr **in6src, 
         * is already bound, use the bound address.
         */
        if (laddr && !IN6_IS_ADDR_UNSPECIFIED(laddr)) {
-               *in6src = laddr;
+               *in6src = *laddr;
                return (0);
        }
 
@@ -167,7 +167,7 @@ in6_pcbselsrc(struct in6_addr **in6src, 
                if (ia6 == NULL)
                        return (EADDRNOTAVAIL);
 
-               *in6src = &ia6->ia_addr.sin6_addr;
+               *in6src = ia6->ia_addr.sin6_addr;
                return (0);
        }
 
@@ -229,7 +229,7 @@ in6_pcbselsrc(struct in6_addr **in6src, 
                        struct ifaddr *ifa;
                        if ((ifa = ifa_ifwithaddr(ip6_source, rtableid)) !=
                            NULL && ISSET(ifa->ifa_ifp->if_flags, IFF_UP)) {
-                               *in6src = &satosin6(ip6_source)->sin6_addr;
+                               *in6src = satosin6(ip6_source)->sin6_addr;
                                return (0);
                        }
                }
@@ -238,7 +238,7 @@ in6_pcbselsrc(struct in6_addr **in6src, 
        if (ia6 == NULL)
                return (EHOSTUNREACH);  /* no route */
 
-       *in6src = &ia6->ia_addr.sin6_addr;
+       *in6src = ia6->ia_addr.sin6_addr;
        return (0);
 }
 
@@ -249,7 +249,7 @@ in6_pcbselsrc(struct in6_addr **in6src, 
  * an entry to the caller for later use.
  */
 int
-in6_selectsrc(struct in6_addr **in6src, struct sockaddr_in6 *dstsock,
+in6_selectsrc(struct in6_addr *in6src, struct sockaddr_in6 *dstsock,
     struct ip6_moptions *mopts, unsigned int rtableid)
 {
        struct ifnet *ifp = NULL;
@@ -279,7 +279,7 @@ in6_selectsrc(struct in6_addr **in6src, 
                if (ia6 == NULL)
                        return (EADDRNOTAVAIL);
 
-               *in6src = &ia6->ia_addr.sin6_addr;
+               *in6src = ia6->ia_addr.sin6_addr;
                return (0);
        }
 
@@ -303,7 +303,7 @@ in6_selectsrc(struct in6_addr **in6src, 
                        if (ia6 == NULL)
                                return (EADDRNOTAVAIL);
 
-                       *in6src = &ia6->ia_addr.sin6_addr;
+                       *in6src = ia6->ia_addr.sin6_addr;
                        return (0);
                }
        }
Index: ip6_var.h
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_var.h,v
retrieving revision 1.92
diff -u -p -r1.92 ip6_var.h
--- ip6_var.h   5 May 2022 13:57:41 -0000       1.92
+++ ip6_var.h   15 May 2022 09:53:53 -0000
@@ -355,9 +355,9 @@ int rip6_sysctl(int *, u_int, void *, si
 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(struct in6_addr *, struct sockaddr_in6 *,
            struct inpcb *, struct ip6_pktopts *);
-int    in6_selectsrc(struct in6_addr **, struct sockaddr_in6 *,
+int    in6_selectsrc(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);
Index: raw_ip6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.147
diff -u -p -r1.147 raw_ip6.c
--- raw_ip6.c   23 Mar 2022 00:16:07 -0000      1.147
+++ raw_ip6.c   15 May 2022 09:53:53 -0000
@@ -423,15 +423,9 @@ rip6_output(struct mbuf *m, struct socke
        /*
         * Source address selection.
         */
-       {
-               struct in6_addr *in6a;
-
-               error = in6_pcbselsrc(&in6a, satosin6(dstaddr), in6p, optp);
-               if (error)
-                       goto bad;
-
-               ip6->ip6_src = *in6a;
-       }
+       error = in6_pcbselsrc(&ip6->ip6_src, satosin6(dstaddr), in6p, optp);
+       if (error)
+               goto bad;
 
        ip6->ip6_flow = in6p->inp_flowinfo & IPV6_FLOWINFO_MASK;
        ip6->ip6_vfc  &= ~IPV6_VERSION_MASK;
@@ -619,15 +613,15 @@ rip6_usrreq(struct socket *so, int req, 
        case PRU_CONNECT:
        {
                struct sockaddr_in6 *addr;
-               struct in6_addr *in6a = NULL;
 
                if ((error = in6_nam2sin6(nam, &addr)))
                        break;
                /* Source address selection. XXX: need pcblookup? */
-               error = in6_pcbselsrc(&in6a, addr, in6p, in6p->inp_outputopts6);
+               error = in6_pcbselsrc(&in6p->inp_laddr6, addr, in6p,
+                   in6p->inp_outputopts6);
                if (error)
                        break;
-               in6p->inp_laddr6 = *in6a;
+
                in6p->inp_faddr6 = addr->sin6_addr;
                soisconnected(so);
                break;
Index: udp6_output.c
===================================================================
RCS file: /cvs/src/sys/netinet6/udp6_output.c,v
retrieving revision 1.59
diff -u -p -r1.59 udp6_output.c
--- udp6_output.c       22 Feb 2022 01:35:41 -0000      1.59
+++ udp6_output.c       15 May 2022 09:53:53 -0000
@@ -101,7 +101,7 @@ udp6_output(struct inpcb *in6p, struct m
        int error = 0, priv = 0, hlen, flags;
        struct ip6_hdr *ip6;
        struct udphdr *udp6;
-       struct in6_addr *laddr, *faddr;
+       struct in6_addr laddr, *faddr;
        struct ip6_pktopts *optp, opt;
        struct sockaddr_in6 tmp, valid;
        struct proc *p = curproc;       /* XXX */
@@ -159,8 +159,8 @@ udp6_output(struct inpcb *in6p, struct m
                }
 
                if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->inp_laddr6) &&
-                   !IN6_ARE_ADDR_EQUAL(&in6p->inp_laddr6, laddr)) {
-                       valid.sin6_addr = *laddr;
+                   !IN6_ARE_ADDR_EQUAL(&in6p->inp_laddr6, &laddr)) {
+                       valid.sin6_addr = laddr;
                        valid.sin6_port = in6p->inp_lport;
                        valid.sin6_scope_id = 0;
                        valid.sin6_family = AF_INET6;
@@ -174,7 +174,7 @@ udp6_output(struct inpcb *in6p, struct m
                        error = ENOTCONN;
                        goto release;
                }
-               laddr = &in6p->inp_laddr6;
+               laddr = in6p->inp_laddr6;
                faddr = &in6p->inp_faddr6;
                fport = in6p->inp_fport;
        }
@@ -212,7 +212,7 @@ udp6_output(struct inpcb *in6p, struct m
 #endif
        ip6->ip6_nxt    = IPPROTO_UDP;
        ip6->ip6_hlim   = in6_selecthlim(in6p);
-       ip6->ip6_src    = *laddr;
+       ip6->ip6_src    = laddr;
        ip6->ip6_dst    = *faddr;
 
        m->m_pkthdr.csum_flags |= M_UDP_CSUM_OUT;

Reply via email to