From: Ralf Lici <[email protected]>

Use the socket's locally bound address if it's explicitly specified via
the --local option in openvpn.

Signed-off-by: Ralf Lici <[email protected]>
Signed-off-by: Antonio Quartulli <[email protected]>
---
 drivers/net/ovpn/udp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ovpn/udp.c b/drivers/net/ovpn/udp.c
index 328819f27e1e..42798aca7bce 100644
--- a/drivers/net/ovpn/udp.c
+++ b/drivers/net/ovpn/udp.c
@@ -148,7 +148,7 @@ static int ovpn_udp4_output(struct ovpn_peer *peer, struct 
ovpn_bind *bind,
 {
        struct rtable *rt;
        struct flowi4 fl = {
-               .saddr = bind->local.ipv4.s_addr,
+               .saddr = inet_sk(sk)->inet_rcv_saddr ?: bind->local.ipv4.s_addr,
                .daddr = bind->remote.in4.sin_addr.s_addr,
                .fl4_sport = inet_sk(sk)->inet_sport,
                .fl4_dport = bind->remote.in4.sin_port,
@@ -226,7 +226,9 @@ static int ovpn_udp6_output(struct ovpn_peer *peer, struct 
ovpn_bind *bind,
        int ret;
 
        struct flowi6 fl = {
-               .saddr = bind->local.ipv6,
+               .saddr = ipv6_addr_any(&sk->sk_v6_rcv_saddr) ?
+                                bind->local.ipv6 :
+                                sk->sk_v6_rcv_saddr,
                .daddr = bind->remote.in6.sin6_addr,
                .fl6_sport = inet_sk(sk)->inet_sport,
                .fl6_dport = bind->remote.in6.sin6_port,
-- 
2.51.2


Reply via email to