aboutsummaryrefslogtreecommitdiffstats
path: root/net/l2tp
diff options
context:
space:
mode:
authorJames Chapman <jchapman@katalix.com>2012-04-29 17:48:47 -0400
committerDavid S. Miller <davem@davemloft.net>2012-05-01 09:30:54 -0400
commitde3c7a1827fa144917270eb66956930012ddae52 (patch)
tree45aa11eafb79423c2aedadcc94de14223954afa2 /net/l2tp
parent5de7aee5413cdfe6f96289a84a5ad22b1314e873 (diff)
l2tp: Use ip4_datagram_connect() in l2tp_ip_connect()
Cleanup the l2tp_ip code to make use of an existing ipv4 support function. Signed-off-by: James Chapman <jchapman@katalix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/l2tp')
-rw-r--r--net/l2tp/l2tp_ip.c54
1 files changed, 7 insertions, 47 deletions
diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
index 585d93ecee2d..516259284846 100644
--- a/net/l2tp/l2tp_ip.c
+++ b/net/l2tp/l2tp_ip.c
@@ -299,67 +299,27 @@ static int l2tp_ip_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len
299{ 299{
300 struct sockaddr_l2tpip *lsa = (struct sockaddr_l2tpip *) uaddr; 300 struct sockaddr_l2tpip *lsa = (struct sockaddr_l2tpip *) uaddr;
301 struct inet_sock *inet = inet_sk(sk); 301 struct inet_sock *inet = inet_sk(sk);
302 struct flowi4 *fl4; 302 int rc;
303 struct rtable *rt;
304 __be32 saddr;
305 int oif, rc;
306 303
307 rc = -EINVAL;
308 if (addr_len < sizeof(*lsa)) 304 if (addr_len < sizeof(*lsa))
309 goto out; 305 return -EINVAL;
310 306
311 rc = -EAFNOSUPPORT;
312 if (lsa->l2tp_family != AF_INET)
313 goto out;
314
315 lock_sock(sk);
316
317 sk_dst_reset(sk);
318
319 oif = sk->sk_bound_dev_if;
320 saddr = inet->inet_saddr;
321
322 rc = -EINVAL;
323 if (ipv4_is_multicast(lsa->l2tp_addr.s_addr)) 307 if (ipv4_is_multicast(lsa->l2tp_addr.s_addr))
324 goto out; 308 return -EINVAL;
325 309
326 fl4 = &inet->cork.fl.u.ip4; 310 rc = ip4_datagram_connect(sk, uaddr, addr_len);
327 rt = ip_route_connect(fl4, lsa->l2tp_addr.s_addr, saddr, 311 if (rc < 0)
328 RT_CONN_FLAGS(sk), oif, 312 return rc;
329 IPPROTO_L2TP,
330 0, 0, sk, true);
331 if (IS_ERR(rt)) {
332 rc = PTR_ERR(rt);
333 if (rc == -ENETUNREACH)
334 IP_INC_STATS_BH(&init_net, IPSTATS_MIB_OUTNOROUTES);
335 goto out;
336 }
337 313
338 rc = -ENETUNREACH; 314 lock_sock(sk);
339 if (rt->rt_flags & (RTCF_MULTICAST | RTCF_BROADCAST)) {
340 ip_rt_put(rt);
341 goto out;
342 }
343 315
344 l2tp_ip_sk(sk)->peer_conn_id = lsa->l2tp_conn_id; 316 l2tp_ip_sk(sk)->peer_conn_id = lsa->l2tp_conn_id;
345 317
346 if (!inet->inet_saddr)
347 inet->inet_saddr = fl4->saddr;
348 if (!inet->inet_rcv_saddr)
349 inet->inet_rcv_saddr = fl4->saddr;
350 inet->inet_daddr = fl4->daddr;
351 sk->sk_state = TCP_ESTABLISHED;
352 inet->inet_id = jiffies;
353
354 sk_dst_set(sk, &rt->dst);
355
356 write_lock_bh(&l2tp_ip_lock); 318 write_lock_bh(&l2tp_ip_lock);
357 hlist_del_init(&sk->sk_bind_node); 319 hlist_del_init(&sk->sk_bind_node);
358 sk_add_bind_node(sk, &l2tp_ip_bind_table); 320 sk_add_bind_node(sk, &l2tp_ip_bind_table);
359 write_unlock_bh(&l2tp_ip_lock); 321 write_unlock_bh(&l2tp_ip_lock);
360 322
361 rc = 0;
362out:
363 release_sock(sk); 323 release_sock(sk);
364 return rc; 324 return rc;
365} 325}