]> www.infradead.org Git - users/hch/block.git/commitdiff
ipv4: Set the routing scope properly in ip_route_output_ports().
authorGuillaume Nault <gnault@redhat.com>
Fri, 9 Feb 2024 16:43:37 +0000 (17:43 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 13 Feb 2024 01:33:05 +0000 (17:33 -0800)
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>
include/net/route.h
net/ipv4/af_inet.c
net/ipv4/datagram.c
net/ipv4/inet_connection_sock.c
net/ipv4/ip_output.c
net/l2tp/l2tp_ip.c

index 980ab474eabdcfb631baa253b44d853be50e7e14..d4a0147942f1a7dff68ee90c2f5fc913f7ceb512 100644 (file)
@@ -37,9 +37,6 @@
 
 #define RTO_ONLINK     0x01
 
-#define RT_CONN_FLAGS(sk)   (RT_TOS(READ_ONCE(inet_sk(sk)->tos)) | sock_flag(sk, SOCK_LOCALROUTE))
-#define RT_CONN_FLAGS_TOS(sk,tos)   (RT_TOS(tos) | sock_flag(sk, SOCK_LOCALROUTE))
-
 static inline __u8 ip_sock_rt_scope(const struct sock *sk)
 {
        if (sock_flag(sk, SOCK_LOCALROUTE))
@@ -163,8 +160,8 @@ static inline struct rtable *ip_route_output_ports(struct net *net, struct flowi
                                                   __u8 proto, __u8 tos, int oif)
 {
        flowi4_init_output(fl4, oif, sk ? READ_ONCE(sk->sk_mark) : 0, tos,
-                          RT_SCOPE_UNIVERSE, proto,
-                          sk ? inet_sk_flowi_flags(sk) : 0,
+                          sk ? ip_sock_rt_scope(sk) : RT_SCOPE_UNIVERSE,
+                          proto, sk ? inet_sk_flowi_flags(sk) : 0,
                           daddr, saddr, dport, sport, sock_net_uid(net, sk));
        if (sk)
                security_sk_classify_flow(sk, flowi4_to_flowi_common(fl4));
index a5a820ee2026691afdd5ca3255962b5116fca290..ad278009e4698c03dfcc7a06e79af39345a41180 100644 (file)
@@ -1326,7 +1326,7 @@ int inet_sk_rebuild_header(struct sock *sk)
        fl4 = &inet->cork.fl.u.ip4;
        rt = ip_route_output_ports(sock_net(sk), fl4, sk, daddr, inet->inet_saddr,
                                   inet->inet_dport, inet->inet_sport,
-                                  sk->sk_protocol, RT_CONN_FLAGS(sk),
+                                  sk->sk_protocol, ip_sock_rt_tos(sk),
                                   sk->sk_bound_dev_if);
        if (!IS_ERR(rt)) {
                err = 0;
index 2cc50cbfc2a31ec91fbdc4a541cb89df689cd9ae..cc6d0bd7b0a96a2676589902da5f1eb114f6d85e 100644 (file)
@@ -119,7 +119,7 @@ void ip4_datagram_release_cb(struct sock *sk)
        rt = ip_route_output_ports(sock_net(sk), &fl4, sk, daddr,
                                   inet->inet_saddr, inet->inet_dport,
                                   inet->inet_sport, sk->sk_protocol,
-                                  RT_CONN_FLAGS(sk), sk->sk_bound_dev_if);
+                                  ip_sock_rt_tos(sk), sk->sk_bound_dev_if);
 
        dst = !IS_ERR(rt) ? &rt->dst : NULL;
        sk_dst_set(sk, dst);
index 459af1f8973958611c43936b0894f6154d23b99a..747ed7344cbe4555860d81802dced6f99d2efc1d 100644 (file)
@@ -1467,7 +1467,7 @@ static struct dst_entry *inet_csk_rebuild_route(struct sock *sk, struct flowi *f
        rt = ip_route_output_ports(sock_net(sk), fl4, sk, daddr,
                                   inet->inet_saddr, inet->inet_dport,
                                   inet->inet_sport, sk->sk_protocol,
-                                  RT_CONN_FLAGS(sk), sk->sk_bound_dev_if);
+                                  ip_sock_rt_tos(sk), sk->sk_bound_dev_if);
        if (IS_ERR(rt))
                rt = NULL;
        if (rt)
index 41537d18eecfd6e1163aacc35e047c22468e04e6..5b5a0adb927ffaf2a925094e421cc4f620d22a9c 100644 (file)
@@ -493,7 +493,7 @@ int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
                                           inet->inet_dport,
                                           inet->inet_sport,
                                           sk->sk_protocol,
-                                          RT_CONN_FLAGS_TOS(sk, tos),
+                                          RT_TOS(tos),
                                           sk->sk_bound_dev_if);
                if (IS_ERR(rt))
                        goto no_route;
index 9a2a9ed3ba478b9d00885b1a00e87f0edde5cb33..970af3983d11672325f7e5ee3be3448a4f200808 100644 (file)
@@ -478,7 +478,7 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
                rt = ip_route_output_ports(sock_net(sk), fl4, sk,
                                           daddr, inet->inet_saddr,
                                           inet->inet_dport, inet->inet_sport,
-                                          sk->sk_protocol, RT_CONN_FLAGS(sk),
+                                          sk->sk_protocol, ip_sock_rt_tos(sk),
                                           sk->sk_bound_dev_if);
                if (IS_ERR(rt))
                        goto no_route;