udp: only choose unbound UDP socket for multicast when not in a VRF
Subsystems (3)
PATCH 1/1 udp: only choose unbound UDP socket for multicast when not in a VRF
By default, packets received in another VRF should not be passed to an unbound socket in the default VRF. This patch updates the IPv4 UDP multicast logic to match the unicast VRF logic (in compute_score()), as well as the IPv6 mcast logic (in __udp_v6_is_mcast_sock()).
The particular case I noticed was DHCP discover packets going to the 255.255.255.255 address, which are handled by __udp4_lib_mcast_deliver(). The previous code meant that running multiple different DHCP server or relay agent instances across VRFs did not work correctly - any server/relay agent in the default VRF received DHCP discover packets for all other VRFs.
--- net/ipv4/udp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv4/udp.c +1 -2
@@ -538,8 +538,7 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk, (inet->inet_dport != rmt_port && inet->inet_dport) || (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||ipv6_only_sock (sk) || - (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif && - sk->sk_bound_dev_if != sdif)) + !udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif)) return false;if (!ip_mc_sf_allow (sk, loc_addr, rmt_addr, dif, sdif))return false;
Signature · 1 line
2.7.4
Quoted 23 lines · Tim Beale
By default, packets received in another VRF should not be passed to an unbound socket in the default VRF. This patch updates the IPv4 UDP multicast logic to match the unicast VRF logic (in
compute_score()), as well as the IPv6 mcast logic (in__udp_v6_is_mcast_sock()).The particular case I noticed was DHCP discover packets going to the 255.255.255.255 address, which are handled by
__udp4_lib_mcast_deliver(). The previous code meant that running multiple different DHCP server or relay agent instances across VRFs did not work correctly - any server/relay agent in the default VRF received DHCP discover packets for all other VRFs.Signed-off-by Tim Beale <[email protected]>--- net/ipv4/udp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)net/ipv4/udp.c +0
-0
net/ipv4/udp.c static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk, · line 544
Quoted 9 lines
net/ipv4/udp.c +1
-2@@ -538,8 +538,7 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk, (inet->inet_dport != rmt_port && inet->inet_dport) || (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||ipv6_only_sock (sk) || - (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif && - sk->sk_bound_dev_if != sdif)) + !udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif)) return false;if (!ip_mc_sf_allow (sk, loc_addr, rmt_addr, dif, sdif))return false;
Thanks for the fix.
Really should have been apart of this commit:
when not in a VRF")
IPv6 mcast socket lookup was converted to udp_sk_bound_dev_eq, so v6 seems ok.
David Miller
maintainerFrom: Tim Beale <[email protected]>
Date: Tue, 4 Jun 2019 13:56:23 +1200
Quoted 5 lines
By default, packets received in another VRF should not be passed to an unbound socket in the default VRF. This patch updates the IPv4 UDP multicast logic to match the unicast VRF logic (in
compute_score()), as well as the IPv6 mcast logic (in__udp_v6_is_mcast_sock()).
Quoted 8 lines
The particular case I noticed was DHCP discover packets going to the 255.255.255.255 address, which are handled by
__udp4_lib_mcast_deliver(). The previous code meant that running multiple different DHCP server or relay agent instances across VRFs did not work correctly - any server/relay agent in the default VRF received DHCP discover packets for all other VRFs.Signed-off-by Tim Beale <[email protected]>
Applied and queued up for -stable, thanks.