diff options
author | David S. Miller <davem@davemloft.net> | 2011-05-07 01:27:25 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-05-08 16:48:57 -0400 |
commit | 3038eeac027d8ec62e4936143498f2b37baf4cb5 (patch) | |
tree | 6bbc1d63430437c9f0d3cd65c6d1b2254515834a /net/ipv4 | |
parent | fdbb0f076b065a0c753ba26925f10357505f1d42 (diff) |
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: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/datagram.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c index d5a2e6995bae..424fafbc8cb0 100644 --- a/net/ipv4/datagram.c +++ b/net/ipv4/datagram.c | |||
@@ -24,7 +24,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
24 | { | 24 | { |
25 | struct inet_sock *inet = inet_sk(sk); | 25 | struct inet_sock *inet = inet_sk(sk); |
26 | struct sockaddr_in *usin = (struct sockaddr_in *) uaddr; | 26 | struct sockaddr_in *usin = (struct sockaddr_in *) uaddr; |
27 | struct flowi4 fl4; | 27 | struct flowi4 *fl4; |
28 | struct rtable *rt; | 28 | struct rtable *rt; |
29 | __be32 saddr; | 29 | __be32 saddr; |
30 | int oif; | 30 | int oif; |
@@ -39,6 +39,8 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) | |||
39 | 39 | ||
40 | sk_dst_reset(sk); | 40 | sk_dst_reset(sk); |
41 | 41 | ||
42 | lock_sock(sk); | ||
43 | |||
42 | oif = sk->sk_bound_dev_if; | 44 | oif = sk->sk_bound_dev_if; |
43 | saddr = inet->inet_saddr; | 45 | saddr = inet->inet_saddr; |
44 | if (ipv4_is_multicast(usin->sin_addr.s_addr)) { | 46 | 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 | if (!saddr) | 49 | if (!saddr) |
48 | saddr = inet->mc_addr; | 50 | saddr = inet->mc_addr; |
49 | } | 51 | } |
50 | rt = ip_route_connect(&fl4, usin->sin_addr.s_addr, saddr, | 52 | fl4 = &inet->cork.fl.u.ip4; |
53 | rt = ip_route_connect(fl4, usin->sin_addr.s_addr, saddr, | ||
51 | RT_CONN_FLAGS(sk), oif, | 54 | RT_CONN_FLAGS(sk), oif, |
52 | sk->sk_protocol, | 55 | sk->sk_protocol, |
53 | inet->inet_sport, usin->sin_port, sk, true); | 56 | 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 | err = PTR_ERR(rt); | 58 | err = PTR_ERR(rt); |
56 | if (err == -ENETUNREACH) | 59 | if (err == -ENETUNREACH) |
57 | IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES); | 60 | IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES); |
58 | return err; | 61 | goto out; |
59 | } | 62 | } |
60 | 63 | ||
61 | if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) { | 64 | if ((rt->rt_flags & RTCF_BROADCAST) && !sock_flag(sk, SOCK_BROADCAST)) { |
62 | ip_rt_put(rt); | 65 | ip_rt_put(rt); |
63 | return -EACCES; | 66 | err = -EACCES; |
67 | goto out; | ||
64 | } | 68 | } |
65 | if (!inet->inet_saddr) | 69 | if (!inet->inet_saddr) |
66 | inet->inet_saddr = fl4.saddr; /* Update source address */ | 70 | inet->inet_saddr = fl4->saddr; /* Update source address */ |
67 | if (!inet->inet_rcv_saddr) { | 71 | if (!inet->inet_rcv_saddr) { |
68 | inet->inet_rcv_saddr = fl4.saddr; | 72 | inet->inet_rcv_saddr = fl4->saddr; |
69 | if (sk->sk_prot->rehash) | 73 | if (sk->sk_prot->rehash) |
70 | sk->sk_prot->rehash(sk); | 74 | sk->sk_prot->rehash(sk); |
71 | } | 75 | } |
72 | inet->inet_daddr = fl4.daddr; | 76 | inet->inet_daddr = fl4->daddr; |
73 | inet->inet_dport = usin->sin_port; | 77 | inet->inet_dport = usin->sin_port; |
74 | sk->sk_state = TCP_ESTABLISHED; | 78 | sk->sk_state = TCP_ESTABLISHED; |
75 | inet->inet_id = jiffies; | 79 | inet->inet_id = jiffies; |
76 | 80 | ||
77 | sk_dst_set(sk, &rt->dst); | 81 | sk_dst_set(sk, &rt->dst); |
78 | return 0; | 82 | err = 0; |
83 | out: | ||
84 | release_sock(sk); | ||
85 | return err; | ||
79 | } | 86 | } |
80 | EXPORT_SYMBOL(ip4_datagram_connect); | 87 | EXPORT_SYMBOL(ip4_datagram_connect); |