Skip to content

Commit c63e9f3

Browse files
Guillaume Naultkuba-moo
authored andcommitted
l2tp: Use inet_sk_init_flowi4() in l2tp_ip_sendmsg().
Use inet_sk_init_flowi4() to automatically initialise the flowi4 structure in l2tp_ip_sendmsg() instead of passing parameters manually to ip_route_output_ports(). Override ->daddr with the value passed in the msghdr structure if provided. Signed-off-by: Guillaume Nault <[email protected]> Reviewed-by: James Chapman <[email protected]> Link: https://patch.msgid.link/2ff22a3560c5050228928456662b80b9c84a8fe4.1734357769.git.gnault@redhat.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 148721f commit c63e9f3

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

net/l2tp/l2tp_ip.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
425425
int rc;
426426
struct inet_sock *inet = inet_sk(sk);
427427
struct rtable *rt = NULL;
428-
struct flowi4 *fl4;
429428
int connected = 0;
430429
__be32 daddr;
431430

@@ -455,7 +454,6 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
455454
if (sk->sk_state != TCP_ESTABLISHED)
456455
goto out;
457456

458-
daddr = inet->inet_daddr;
459457
connected = 1;
460458
}
461459

@@ -482,29 +480,24 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
482480
goto error;
483481
}
484482

485-
fl4 = &inet->cork.fl.u.ip4;
486483
if (connected)
487484
rt = dst_rtable(__sk_dst_check(sk, 0));
488485

489486
rcu_read_lock();
490487
if (!rt) {
491-
const struct ip_options_rcu *inet_opt;
488+
struct flowi4 *fl4 = &inet->cork.fl.u.ip4;
492489

493-
inet_opt = rcu_dereference(inet->inet_opt);
490+
inet_sk_init_flowi4(inet, fl4);
494491

495-
/* Use correct destination address if we have options. */
496-
if (inet_opt && inet_opt->opt.srr)
497-
daddr = inet_opt->opt.faddr;
492+
/* Overwrite ->daddr if msg->msg_name was provided */
493+
if (!connected)
494+
fl4->daddr = daddr;
498495

499496
/* If this fails, retransmit mechanism of transport layer will
500497
* keep trying until route appears or the connection times
501498
* itself out.
502499
*/
503-
rt = ip_route_output_ports(sock_net(sk), fl4, sk,
504-
daddr, inet->inet_saddr,
505-
inet->inet_dport, inet->inet_sport,
506-
sk->sk_protocol, ip_sock_rt_tos(sk),
507-
sk->sk_bound_dev_if);
500+
rt = ip_route_output_flow(sock_net(sk), fl4, sk);
508501
if (IS_ERR(rt))
509502
goto no_route;
510503
if (connected) {

0 commit comments

Comments
 (0)