mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-01-18 17:36:13 +07:00
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>
This commit is contained in:
parent
5de7aee541
commit
de3c7a1827
@ -299,67 +299,27 @@ static int l2tp_ip_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len
|
||||
{
|
||||
struct sockaddr_l2tpip *lsa = (struct sockaddr_l2tpip *) uaddr;
|
||||
struct inet_sock *inet = inet_sk(sk);
|
||||
struct flowi4 *fl4;
|
||||
struct rtable *rt;
|
||||
__be32 saddr;
|
||||
int oif, rc;
|
||||
int rc;
|
||||
|
||||
rc = -EINVAL;
|
||||
if (addr_len < sizeof(*lsa))
|
||||
goto out;
|
||||
return -EINVAL;
|
||||
|
||||
rc = -EAFNOSUPPORT;
|
||||
if (lsa->l2tp_family != AF_INET)
|
||||
goto out;
|
||||
if (ipv4_is_multicast(lsa->l2tp_addr.s_addr))
|
||||
return -EINVAL;
|
||||
|
||||
rc = ip4_datagram_connect(sk, uaddr, addr_len);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
|
||||
lock_sock(sk);
|
||||
|
||||
sk_dst_reset(sk);
|
||||
|
||||
oif = sk->sk_bound_dev_if;
|
||||
saddr = inet->inet_saddr;
|
||||
|
||||
rc = -EINVAL;
|
||||
if (ipv4_is_multicast(lsa->l2tp_addr.s_addr))
|
||||
goto out;
|
||||
|
||||
fl4 = &inet->cork.fl.u.ip4;
|
||||
rt = ip_route_connect(fl4, lsa->l2tp_addr.s_addr, saddr,
|
||||
RT_CONN_FLAGS(sk), oif,
|
||||
IPPROTO_L2TP,
|
||||
0, 0, sk, true);
|
||||
if (IS_ERR(rt)) {
|
||||
rc = PTR_ERR(rt);
|
||||
if (rc == -ENETUNREACH)
|
||||
IP_INC_STATS_BH(&init_net, IPSTATS_MIB_OUTNOROUTES);
|
||||
goto out;
|
||||
}
|
||||
|
||||
rc = -ENETUNREACH;
|
||||
if (rt->rt_flags & (RTCF_MULTICAST | RTCF_BROADCAST)) {
|
||||
ip_rt_put(rt);
|
||||
goto out;
|
||||
}
|
||||
|
||||
l2tp_ip_sk(sk)->peer_conn_id = lsa->l2tp_conn_id;
|
||||
|
||||
if (!inet->inet_saddr)
|
||||
inet->inet_saddr = fl4->saddr;
|
||||
if (!inet->inet_rcv_saddr)
|
||||
inet->inet_rcv_saddr = fl4->saddr;
|
||||
inet->inet_daddr = fl4->daddr;
|
||||
sk->sk_state = TCP_ESTABLISHED;
|
||||
inet->inet_id = jiffies;
|
||||
|
||||
sk_dst_set(sk, &rt->dst);
|
||||
|
||||
write_lock_bh(&l2tp_ip_lock);
|
||||
hlist_del_init(&sk->sk_bind_node);
|
||||
sk_add_bind_node(sk, &l2tp_ip_bind_table);
|
||||
write_unlock_bh(&l2tp_ip_lock);
|
||||
|
||||
rc = 0;
|
||||
out:
|
||||
release_sock(sk);
|
||||
return rc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user