Skip to content

Commit 9a24abf

Browse files
David Aherndavem330
authored andcommitted
udp: Handle VRF device in sendmsg
For unconnected UDP sockets using a VRF device lookup source address based on VRF table. This allows the UDP header to be properly setup before showing up at the VRF device via the dst. Signed-off-by: Shrijeet Mukherjee <[email protected]> Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 613d09b commit 9a24abf

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

net/ipv4/udp.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,11 +1013,31 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
10131013

10141014
if (!rt) {
10151015
struct net *net = sock_net(sk);
1016+
__u8 flow_flags = inet_sk_flowi_flags(sk);
10161017

10171018
fl4 = &fl4_stack;
1019+
1020+
/* unconnected socket. If output device is enslaved to a VRF
1021+
* device lookup source address from VRF table. This mimics
1022+
* behavior of ip_route_connect{_init}.
1023+
*/
1024+
if (netif_index_is_vrf(net, ipc.oif)) {
1025+
flowi4_init_output(fl4, ipc.oif, sk->sk_mark, tos,
1026+
RT_SCOPE_UNIVERSE, sk->sk_protocol,
1027+
(flow_flags | FLOWI_FLAG_VRFSRC),
1028+
faddr, saddr, dport,
1029+
inet->inet_sport);
1030+
1031+
rt = ip_route_output_flow(net, fl4, sk);
1032+
if (!IS_ERR(rt)) {
1033+
saddr = fl4->saddr;
1034+
ip_rt_put(rt);
1035+
}
1036+
}
1037+
10181038
flowi4_init_output(fl4, ipc.oif, sk->sk_mark, tos,
10191039
RT_SCOPE_UNIVERSE, sk->sk_protocol,
1020-
inet_sk_flowi_flags(sk),
1040+
flow_flags,
10211041
faddr, saddr, dport, inet->inet_sport);
10221042

10231043
security_sk_classify_flow(sk, flowi4_to_flowi(fl4));

0 commit comments

Comments
 (0)