* [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets.
@ 2023-05-22 14:37 Guillaume Nault
2023-05-22 14:37 ` [PATCH net-next 1/3] ping: Stop using RTO_ONLINK Guillaume Nault
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Guillaume Nault @ 2023-05-22 14:37 UTC (permalink / raw)
To: David Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet
Cc: netdev, David Ahern, Willem de Bruijn
udp_sendmsg(), ping_v4_sendmsg() and raw_sendmsg() use similar patterns
for restricting their route lookup to on-link hosts. Although they use
slightly different code, they all use RTO_ONLINK to override the least
significant bit of their tos value.
RTO_ONLINK is used to restrict the route scope even when the scope is
set to RT_SCOPE_UNIVERSE. Therefore it isn't necessary: we can properly
set the scope to RT_SCOPE_LINK instead.
Removing RTO_ONLINK will allow to convert .flowi4_tos to dscp_t in the
future, thus allowing to properly separate the DSCP from the ECN bits
in the networking stack.
This patch series defines a common helper to figure out what's the
scope of the route lookup. This unifies the way udp, ping and raw
sockets get their routing scope and removes their dependency on
RTO_ONLINK.
Guillaume Nault (3):
ping: Stop using RTO_ONLINK.
raw: Stop using RTO_ONLINK.
udp: Stop using RTO_ONLINK.
include/net/ip.h | 16 ++++++++++++----
net/ipv4/ping.c | 15 +++++----------
net/ipv4/raw.c | 10 ++++------
net/ipv4/udp.c | 17 ++++++-----------
4 files changed, 27 insertions(+), 31 deletions(-)
--
2.39.2
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net-next 1/3] ping: Stop using RTO_ONLINK.
2023-05-22 14:37 [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets Guillaume Nault
@ 2023-05-22 14:37 ` Guillaume Nault
2023-05-23 15:09 ` David Ahern
2023-05-22 14:38 ` [PATCH net-next 2/3] raw: " Guillaume Nault
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Guillaume Nault @ 2023-05-22 14:37 UTC (permalink / raw)
To: David Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet
Cc: netdev, David Ahern, Willem de Bruijn
Define a new helper to figure out the correct route scope to use on TX,
depending on socket configuration, ancillary data and send flags.
Use this new helper to properly initialise the scope in
flowi4_init_output(), instead of overriding tos with the RTO_ONLINK
flag.
The objective is to eventually remove RTO_ONLINK, which will allow
converting .flowi4_tos to dscp_t.
Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
include/net/ip.h | 13 +++++++++++++
net/ipv4/ping.c | 15 +++++----------
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/include/net/ip.h b/include/net/ip.h
index c3fffaa92d6e..6e262efa0d55 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -242,6 +242,19 @@ static inline struct sk_buff *ip_finish_skb(struct sock *sk, struct flowi4 *fl4)
return __ip_make_skb(sk, fl4, &sk->sk_write_queue, &inet_sk(sk)->cork.base);
}
+/* Get the route scope that should be used when sending a packet. */
+static inline u8 ip_sendmsg_scope(const struct inet_sock *inet,
+ const struct ipcm_cookie *ipc,
+ const struct msghdr *msg)
+{
+ if (sock_flag(&inet->sk, SOCK_LOCALROUTE) ||
+ msg->msg_flags & MSG_DONTROUTE ||
+ (ipc->opt && ipc->opt->opt.is_strictroute))
+ return RT_SCOPE_LINK;
+
+ return RT_SCOPE_UNIVERSE;
+}
+
static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
{
return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(inet->tos);
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 3793c81bda8a..25dd78cee179 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -705,7 +705,7 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
struct ip_options_data opt_copy;
int free = 0;
__be32 saddr, daddr, faddr;
- u8 tos;
+ u8 tos, scope;
int err;
pr_debug("ping_v4_sendmsg(sk=%p,sk->num=%u)\n", inet, inet->inet_num);
@@ -769,11 +769,7 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
faddr = ipc.opt->opt.faddr;
}
tos = get_rttos(&ipc, inet);
- if (sock_flag(sk, SOCK_LOCALROUTE) ||
- (msg->msg_flags & MSG_DONTROUTE) ||
- (ipc.opt && ipc.opt->opt.is_strictroute)) {
- tos |= RTO_ONLINK;
- }
+ scope = ip_sendmsg_scope(inet, &ipc, msg);
if (ipv4_is_multicast(daddr)) {
if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
@@ -783,10 +779,9 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
} else if (!ipc.oif)
ipc.oif = inet->uc_index;
- flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos,
- RT_SCOPE_UNIVERSE, sk->sk_protocol,
- inet_sk_flowi_flags(sk), faddr, saddr, 0, 0,
- sk->sk_uid);
+ flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope,
+ sk->sk_protocol, inet_sk_flowi_flags(sk), faddr,
+ saddr, 0, 0, sk->sk_uid);
fl4.fl4_icmp_type = user_icmph.type;
fl4.fl4_icmp_code = user_icmph.code;
--
2.39.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 2/3] raw: Stop using RTO_ONLINK.
2023-05-22 14:37 [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets Guillaume Nault
2023-05-22 14:37 ` [PATCH net-next 1/3] ping: Stop using RTO_ONLINK Guillaume Nault
@ 2023-05-22 14:38 ` Guillaume Nault
2023-05-23 15:13 ` David Ahern
2023-05-22 14:38 ` [PATCH net-next 3/3] udp: " Guillaume Nault
2023-05-24 7:30 ` [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets patchwork-bot+netdevbpf
3 siblings, 1 reply; 8+ messages in thread
From: Guillaume Nault @ 2023-05-22 14:38 UTC (permalink / raw)
To: David Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet
Cc: netdev, David Ahern, Willem de Bruijn
Use ip_sendmsg_scope() to properly initialise the scope in
flowi4_init_output(), instead of overriding tos with the RTO_ONLINK
flag. The objective is to eventually remove RTO_ONLINK, which will
allow converting .flowi4_tos to dscp_t.
The MSG_DONTROUTE and SOCK_LOCALROUTE cases were already handled by
raw_sendmsg() (SOCK_LOCALROUTE was handled by the RT_CONN_FLAGS*()
macros called by get_rtconn_flags()). However, opt.is_strictroute
wasn't taken into account. Therefore, a side effect of this patch is to
now honour opt.is_strictroute, and thus align raw_sendmsg() with
ping_v4_sendmsg() and udp_sendmsg().
Since raw_sendmsg() was the only user of get_rtconn_flags(), we can now
remove this function.
Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
include/net/ip.h | 5 -----
net/ipv4/raw.c | 10 ++++------
2 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/include/net/ip.h b/include/net/ip.h
index 6e262efa0d55..fab910be252c 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -260,11 +260,6 @@ static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet)
return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(inet->tos);
}
-static inline __u8 get_rtconn_flags(struct ipcm_cookie* ipc, struct sock* sk)
-{
- return (ipc->tos != -1) ? RT_CONN_FLAGS_TOS(sk, ipc->tos) : RT_CONN_FLAGS(sk);
-}
-
/* datagram.c */
int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len);
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
index ff712bf2a98d..8b7b5c842bdd 100644
--- a/net/ipv4/raw.c
+++ b/net/ipv4/raw.c
@@ -476,10 +476,10 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
struct ipcm_cookie ipc;
struct rtable *rt = NULL;
struct flowi4 fl4;
+ u8 tos, scope;
int free = 0;
__be32 daddr;
__be32 saddr;
- u8 tos;
int err;
struct ip_options_data opt_copy;
struct raw_frag_vec rfv;
@@ -572,9 +572,8 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
daddr = ipc.opt->opt.faddr;
}
}
- tos = get_rtconn_flags(&ipc, sk);
- if (msg->msg_flags & MSG_DONTROUTE)
- tos |= RTO_ONLINK;
+ tos = get_rttos(&ipc, inet);
+ scope = ip_sendmsg_scope(inet, &ipc, msg);
if (ipv4_is_multicast(daddr)) {
if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
@@ -597,8 +596,7 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
}
}
- flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos,
- RT_SCOPE_UNIVERSE,
+ flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope,
hdrincl ? IPPROTO_RAW : sk->sk_protocol,
inet_sk_flowi_flags(sk) |
(hdrincl ? FLOWI_FLAG_KNOWN_NH : 0),
--
2.39.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 3/3] udp: Stop using RTO_ONLINK.
2023-05-22 14:37 [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets Guillaume Nault
2023-05-22 14:37 ` [PATCH net-next 1/3] ping: Stop using RTO_ONLINK Guillaume Nault
2023-05-22 14:38 ` [PATCH net-next 2/3] raw: " Guillaume Nault
@ 2023-05-22 14:38 ` Guillaume Nault
2023-05-23 15:14 ` David Ahern
2023-05-24 7:30 ` [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets patchwork-bot+netdevbpf
3 siblings, 1 reply; 8+ messages in thread
From: Guillaume Nault @ 2023-05-22 14:38 UTC (permalink / raw)
To: David Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet
Cc: netdev, David Ahern, Willem de Bruijn
Use ip_sendmsg_scope() to properly initialise the scope in
flowi4_init_output(), instead of overriding tos with the RTO_ONLINK
flag. The objective is to eventually remove RTO_ONLINK, which will
allow converting .flowi4_tos to dscp_t.
Now that the scope is determined by ip_sendmsg_scope(), we need to
check its result to set the 'connected' variable.
Signed-off-by: Guillaume Nault <gnault@redhat.com>
---
net/ipv4/udp.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index aa32afd871ee..64750baa55d6 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1062,8 +1062,8 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
int free = 0;
int connected = 0;
__be32 daddr, faddr, saddr;
+ u8 tos, scope;
__be16 dport;
- u8 tos;
int err, is_udplite = IS_UDPLITE(sk);
int corkreq = READ_ONCE(up->corkflag) || msg->msg_flags&MSG_MORE;
int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
@@ -1183,12 +1183,9 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
connected = 0;
}
tos = get_rttos(&ipc, inet);
- if (sock_flag(sk, SOCK_LOCALROUTE) ||
- (msg->msg_flags & MSG_DONTROUTE) ||
- (ipc.opt && ipc.opt->opt.is_strictroute)) {
- tos |= RTO_ONLINK;
+ scope = ip_sendmsg_scope(inet, &ipc, msg);
+ if (scope == RT_SCOPE_LINK)
connected = 0;
- }
if (ipv4_is_multicast(daddr)) {
if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
@@ -1221,11 +1218,9 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
fl4 = &fl4_stack;
- flowi4_init_output(fl4, ipc.oif, ipc.sockc.mark, tos,
- RT_SCOPE_UNIVERSE, sk->sk_protocol,
- flow_flags,
- faddr, saddr, dport, inet->inet_sport,
- sk->sk_uid);
+ flowi4_init_output(fl4, ipc.oif, ipc.sockc.mark, tos, scope,
+ sk->sk_protocol, flow_flags, faddr, saddr,
+ dport, inet->inet_sport, sk->sk_uid);
security_sk_classify_flow(sk, flowi4_to_flowi_common(fl4));
rt = ip_route_output_flow(net, fl4, sk);
--
2.39.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 1/3] ping: Stop using RTO_ONLINK.
2023-05-22 14:37 ` [PATCH net-next 1/3] ping: Stop using RTO_ONLINK Guillaume Nault
@ 2023-05-23 15:09 ` David Ahern
0 siblings, 0 replies; 8+ messages in thread
From: David Ahern @ 2023-05-23 15:09 UTC (permalink / raw)
To: Guillaume Nault, David Miller, Jakub Kicinski, Paolo Abeni,
Eric Dumazet
Cc: netdev, Willem de Bruijn
On 5/22/23 8:37 AM, Guillaume Nault wrote:
> Define a new helper to figure out the correct route scope to use on TX,
> depending on socket configuration, ancillary data and send flags.
>
> Use this new helper to properly initialise the scope in
> flowi4_init_output(), instead of overriding tos with the RTO_ONLINK
> flag.
>
> The objective is to eventually remove RTO_ONLINK, which will allow
> converting .flowi4_tos to dscp_t.
>
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
> include/net/ip.h | 13 +++++++++++++
> net/ipv4/ping.c | 15 +++++----------
> 2 files changed, 18 insertions(+), 10 deletions(-)
>
Reviewed-by: David Ahern <dsahern@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 2/3] raw: Stop using RTO_ONLINK.
2023-05-22 14:38 ` [PATCH net-next 2/3] raw: " Guillaume Nault
@ 2023-05-23 15:13 ` David Ahern
0 siblings, 0 replies; 8+ messages in thread
From: David Ahern @ 2023-05-23 15:13 UTC (permalink / raw)
To: Guillaume Nault, David Miller, Jakub Kicinski, Paolo Abeni,
Eric Dumazet
Cc: netdev, Willem de Bruijn
On 5/22/23 8:38 AM, Guillaume Nault wrote:
> Use ip_sendmsg_scope() to properly initialise the scope in
> flowi4_init_output(), instead of overriding tos with the RTO_ONLINK
> flag. The objective is to eventually remove RTO_ONLINK, which will
> allow converting .flowi4_tos to dscp_t.
>
> The MSG_DONTROUTE and SOCK_LOCALROUTE cases were already handled by
> raw_sendmsg() (SOCK_LOCALROUTE was handled by the RT_CONN_FLAGS*()
> macros called by get_rtconn_flags()). However, opt.is_strictroute
> wasn't taken into account. Therefore, a side effect of this patch is to
> now honour opt.is_strictroute, and thus align raw_sendmsg() with
> ping_v4_sendmsg() and udp_sendmsg().
>
> Since raw_sendmsg() was the only user of get_rtconn_flags(), we can now
> remove this function.
>
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
> include/net/ip.h | 5 -----
> net/ipv4/raw.c | 10 ++++------
> 2 files changed, 4 insertions(+), 11 deletions(-)
>
Reviewed-by: David Ahern <dsahern@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 3/3] udp: Stop using RTO_ONLINK.
2023-05-22 14:38 ` [PATCH net-next 3/3] udp: " Guillaume Nault
@ 2023-05-23 15:14 ` David Ahern
0 siblings, 0 replies; 8+ messages in thread
From: David Ahern @ 2023-05-23 15:14 UTC (permalink / raw)
To: Guillaume Nault, David Miller, Jakub Kicinski, Paolo Abeni,
Eric Dumazet
Cc: netdev, Willem de Bruijn
On 5/22/23 8:38 AM, Guillaume Nault wrote:
> Use ip_sendmsg_scope() to properly initialise the scope in
> flowi4_init_output(), instead of overriding tos with the RTO_ONLINK
> flag. The objective is to eventually remove RTO_ONLINK, which will
> allow converting .flowi4_tos to dscp_t.
>
> Now that the scope is determined by ip_sendmsg_scope(), we need to
> check its result to set the 'connected' variable.
>
> Signed-off-by: Guillaume Nault <gnault@redhat.com>
> ---
> net/ipv4/udp.c | 17 ++++++-----------
> 1 file changed, 6 insertions(+), 11 deletions(-)
>
Reviewed-by: David Ahern <dsahern@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets.
2023-05-22 14:37 [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets Guillaume Nault
` (2 preceding siblings ...)
2023-05-22 14:38 ` [PATCH net-next 3/3] udp: " Guillaume Nault
@ 2023-05-24 7:30 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-05-24 7:30 UTC (permalink / raw)
To: Guillaume Nault
Cc: davem, kuba, pabeni, edumazet, netdev, dsahern,
willemdebruijn.kernel
Hello:
This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Mon, 22 May 2023 16:37:50 +0200 you wrote:
> udp_sendmsg(), ping_v4_sendmsg() and raw_sendmsg() use similar patterns
> for restricting their route lookup to on-link hosts. Although they use
> slightly different code, they all use RTO_ONLINK to override the least
> significant bit of their tos value.
>
> RTO_ONLINK is used to restrict the route scope even when the scope is
> set to RT_SCOPE_UNIVERSE. Therefore it isn't necessary: we can properly
> set the scope to RT_SCOPE_LINK instead.
>
> [...]
Here is the summary with links:
- [net-next,1/3] ping: Stop using RTO_ONLINK.
https://git.kernel.org/netdev/net-next/c/726de790f660
- [net-next,2/3] raw: Stop using RTO_ONLINK.
https://git.kernel.org/netdev/net-next/c/c85be08fc4fa
- [net-next,3/3] udp: Stop using RTO_ONLINK.
https://git.kernel.org/netdev/net-next/c/0e26371db548
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-05-24 7:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-22 14:37 [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets Guillaume Nault
2023-05-22 14:37 ` [PATCH net-next 1/3] ping: Stop using RTO_ONLINK Guillaume Nault
2023-05-23 15:09 ` David Ahern
2023-05-22 14:38 ` [PATCH net-next 2/3] raw: " Guillaume Nault
2023-05-23 15:13 ` David Ahern
2023-05-22 14:38 ` [PATCH net-next 3/3] udp: " Guillaume Nault
2023-05-23 15:14 ` David Ahern
2023-05-24 7:30 ` [PATCH net-next 0/3] ipv4: Remove RTO_ONLINK from udp, ping and raw sockets patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).