Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipv4: Set the routing scope properly in ip_route_output_ports().

Set scope automatically in ip_route_output_ports() (using the socket
SOCK_LOCALROUTE flag). This way, callers don't have to overload the
tos with the RTO_ONLINK flag, like RT_CONN_FLAGS() does.

For callers that don't pass a struct sock, this doesn't change anything
as the scope is still set to RT_SCOPE_UNIVERSE when sk is NULL.

Callers that passed a struct sock and used RT_CONN_FLAGS(sk) or
RT_CONN_FLAGS_TOS(sk, tos) for the tos are modified to use
ip_sock_tos(sk) and RT_TOS(tos) respectively, as overloading tos with
the RTO_ONLINK flag now becomes unnecessary.

In drivers/net/amt.c, all ip_route_output_ports() calls use a 0 tos
parameter, ignoring the SOCK_LOCALROUTE flag of the socket. But the sk
parameter is a kernel socket, which doesn't have any configuration path
for setting SOCK_LOCALROUTE anyway. Therefore, ip_route_output_ports()
will continue to initialise scope with RT_SCOPE_UNIVERSE and amt.c
doesn't need to be modified.

Also, remove RT_CONN_FLAGS() and RT_CONN_FLAGS_TOS() from route.h as
these macros are now unused.

The objective is to eventually remove RTO_ONLINK entirely to allow
converting ->flowi4_tos to dscp_t. This will ensure proper isolation
between the DSCP and ECN bits, thus minimising the risk of introducing
bugs where TOS values interfere with ECN.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/dacfd2ab40685e20959ab7b53c427595ba229e7d.1707496938.git.gnault@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Guillaume Nault and committed by
Jakub Kicinski
a3522a2e f25e7b82

+7 -10
+2 -5
include/net/route.h
··· 37 37 38 38 #define RTO_ONLINK 0x01 39 39 40 - #define RT_CONN_FLAGS(sk) (RT_TOS(READ_ONCE(inet_sk(sk)->tos)) | sock_flag(sk, SOCK_LOCALROUTE)) 41 - #define RT_CONN_FLAGS_TOS(sk,tos) (RT_TOS(tos) | sock_flag(sk, SOCK_LOCALROUTE)) 42 - 43 40 static inline __u8 ip_sock_rt_scope(const struct sock *sk) 44 41 { 45 42 if (sock_flag(sk, SOCK_LOCALROUTE)) ··· 160 163 __u8 proto, __u8 tos, int oif) 161 164 { 162 165 flowi4_init_output(fl4, oif, sk ? READ_ONCE(sk->sk_mark) : 0, tos, 163 - RT_SCOPE_UNIVERSE, proto, 164 - sk ? inet_sk_flowi_flags(sk) : 0, 166 + sk ? ip_sock_rt_scope(sk) : RT_SCOPE_UNIVERSE, 167 + proto, sk ? inet_sk_flowi_flags(sk) : 0, 165 168 daddr, saddr, dport, sport, sock_net_uid(net, sk)); 166 169 if (sk) 167 170 security_sk_classify_flow(sk, flowi4_to_flowi_common(fl4));
+1 -1
net/ipv4/af_inet.c
··· 1326 1326 fl4 = &inet->cork.fl.u.ip4; 1327 1327 rt = ip_route_output_ports(sock_net(sk), fl4, sk, daddr, inet->inet_saddr, 1328 1328 inet->inet_dport, inet->inet_sport, 1329 - sk->sk_protocol, RT_CONN_FLAGS(sk), 1329 + sk->sk_protocol, ip_sock_rt_tos(sk), 1330 1330 sk->sk_bound_dev_if); 1331 1331 if (!IS_ERR(rt)) { 1332 1332 err = 0;
+1 -1
net/ipv4/datagram.c
··· 119 119 rt = ip_route_output_ports(sock_net(sk), &fl4, sk, daddr, 120 120 inet->inet_saddr, inet->inet_dport, 121 121 inet->inet_sport, sk->sk_protocol, 122 - RT_CONN_FLAGS(sk), sk->sk_bound_dev_if); 122 + ip_sock_rt_tos(sk), sk->sk_bound_dev_if); 123 123 124 124 dst = !IS_ERR(rt) ? &rt->dst : NULL; 125 125 sk_dst_set(sk, dst);
+1 -1
net/ipv4/inet_connection_sock.c
··· 1467 1467 rt = ip_route_output_ports(sock_net(sk), fl4, sk, daddr, 1468 1468 inet->inet_saddr, inet->inet_dport, 1469 1469 inet->inet_sport, sk->sk_protocol, 1470 - RT_CONN_FLAGS(sk), sk->sk_bound_dev_if); 1470 + ip_sock_rt_tos(sk), sk->sk_bound_dev_if); 1471 1471 if (IS_ERR(rt)) 1472 1472 rt = NULL; 1473 1473 if (rt)
+1 -1
net/ipv4/ip_output.c
··· 493 493 inet->inet_dport, 494 494 inet->inet_sport, 495 495 sk->sk_protocol, 496 - RT_CONN_FLAGS_TOS(sk, tos), 496 + RT_TOS(tos), 497 497 sk->sk_bound_dev_if); 498 498 if (IS_ERR(rt)) 499 499 goto no_route;
+1 -1
net/l2tp/l2tp_ip.c
··· 478 478 rt = ip_route_output_ports(sock_net(sk), fl4, sk, 479 479 daddr, inet->inet_saddr, 480 480 inet->inet_dport, inet->inet_sport, 481 - sk->sk_protocol, RT_CONN_FLAGS(sk), 481 + sk->sk_protocol, ip_sock_rt_tos(sk), 482 482 sk->sk_bound_dev_if); 483 483 if (IS_ERR(rt)) 484 484 goto no_route;