@@ -60,10 +60,13 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
ip_rt_put(rt);
return -EACCES;
}
- if (!inet->inet_saddr)
- inet->inet_saddr = rt->rt_src; /* Update source address */
- if (!inet->inet_rcv_saddr)
- inet->inet_rcv_saddr = rt->rt_src;
+ /*
+ * Should connect() change inet_rcv_saddr / inet_saddr ?
+ * It should not, because we want to specify the peer to which
+ * datagrams are to be sent, regardless of our source address that
+ * might change in the future, after a route change.
+ * To specify our source address, bind() is the right API.
+ */
inet->inet_daddr = rt->rt_dst;
inet->inet_dport = usin->sin_port;
sk->sk_state = TCP_ESTABLISHED;
@@ -102,13 +102,14 @@ ipv4_connected:
ipv6_addr_set_v4mapped(inet->inet_daddr, &np->daddr);
- if (ipv6_addr_any(&np->saddr))
- ipv6_addr_set_v4mapped(inet->inet_saddr, &np->saddr);
-
- if (ipv6_addr_any(&np->rcv_saddr))
- ipv6_addr_set_v4mapped(inet->inet_rcv_saddr,
- &np->rcv_saddr);
-
+ /*
+ * Should connect() change np->rcv_saddr / np->saddr ?
+ * It should not, because we want to specify the
+ * peer to which datagrams are to be sent, regardless
+ * of our source address that might change in the
+ * future, after a route change. To specify our
+ * source address, bind() is the right API.
+ */
goto out;
}
@@ -173,15 +174,13 @@ ipv4_connected:
goto out;
}
- /* source address lookup done in ip6_dst_lookup */
-
- if (ipv6_addr_any(&np->saddr))
- ipv6_addr_copy(&np->saddr, &fl.fl6_src);
-
- if (ipv6_addr_any(&np->rcv_saddr)) {
- ipv6_addr_copy(&np->rcv_saddr, &fl.fl6_src);
- inet->inet_rcv_saddr = LOOPBACK4_IPV6;
- }
+ /*
+ * Should connect() change np->rcv_saddr / np->saddr ?
+ * It should not, because we want to specify the peer to which
+ * datagrams are to be sent, regardless of our source address that
+ * might change in the future, after a route change.
+ * To specify our source address, bind() is the right API.
+ */
ip6_dst_store(sk, dst,
ipv6_addr_equal(&fl.fl6_dst, &np->daddr) ?