Commit 3038eeac authored by David S. Miller's avatar David S. Miller

ipv4: Lock socket and use cork flow in ip4_datagram_connect().

This is to make sure that an l2tp socket's inet cork flow is
fully filled in, when it's encapsulated in UDP.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fdbb0f07
...@@ -24,7 +24,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -24,7 +24,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
{ {
struct inet_sock *inet = inet_sk(sk); struct inet_sock *inet = inet_sk(sk);
struct sockaddr_in *usin = (struct sockaddr_in *) uaddr; struct sockaddr_in *usin = (struct sockaddr_in *) uaddr;
struct flowi4 fl4; struct flowi4 *fl4;
struct rtable *rt; struct rtable *rt;
__be32 saddr; __be32 saddr;
int oif; int oif;
...@@ -39,6 +39,8 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -39,6 +39,8 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
sk_dst_reset(sk); sk_dst_reset(sk);
lock_sock(sk);
oif = sk->sk_bound_dev_if; oif = sk->sk_bound_dev_if;
saddr = inet->inet_saddr; saddr = inet->inet_saddr;
if (ipv4_is_multicast(usin->sin_addr.s_addr)) { if (ipv4_is_multicast(usin->sin_addr.s_addr)) {
...@@ -47,7 +49,8 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -47,7 +49,8 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
if (!saddr) if (!saddr)
saddr = inet->mc_addr; saddr = inet->mc_addr;
} }
rt = ip_route_connect(&fl4, usin->sin_addr.s_addr, saddr, fl4 = &inet->cork.fl.u.ip4;
rt = ip_route_connect(fl4, usin->sin_addr.s_addr, saddr,
RT_CONN_FLAGS(sk), oif, RT_CONN_FLAGS(sk), oif,
sk->sk_protocol, sk->sk_protocol,
inet->inet_sport, usin->sin_port, sk, true); inet->inet_sport, usin->sin_port, sk, true);
...@@ -55,26 +58,30 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) ...@@ -55,26 +58,30 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
err = PTR_ERR(rt); err = PTR_ERR(rt);
if (err == -ENETUNREACH) if (err == -ENETUNREACH)
IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES); IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
return err; goto out;
} }
if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) { if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) {
ip_rt_put(rt); ip_rt_put(rt);
return -EACCES; err = -EACCES;
goto out;
} }
if (!inet->inet_saddr) if (!inet->inet_saddr)
inet->inet_saddr = fl4.saddr; /* Update source address */ inet->inet_saddr = fl4->saddr; /* Update source address */
if (!inet->inet_rcv_saddr) { if (!inet->inet_rcv_saddr) {
inet->inet_rcv_saddr = fl4.saddr; inet->inet_rcv_saddr = fl4->saddr;
if (sk->sk_prot->rehash) if (sk->sk_prot->rehash)
sk->sk_prot->rehash(sk); sk->sk_prot->rehash(sk);
} }
inet->inet_daddr = fl4.daddr; inet->inet_daddr = fl4->daddr;
inet->inet_dport = usin->sin_port; inet->inet_dport = usin->sin_port;
sk->sk_state = TCP_ESTABLISHED; sk->sk_state = TCP_ESTABLISHED;
inet->inet_id = jiffies; inet->inet_id = jiffies;
sk_dst_set(sk, &rt->dst); sk_dst_set(sk, &rt->dst);
return 0; err = 0;
out:
release_sock(sk);
return err;
} }
EXPORT_SYMBOL(ip4_datagram_connect); EXPORT_SYMBOL(ip4_datagram_connect);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment