[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CADvbK_fsM_EfoNjhybKJr92ojqFo6OdnuA2WiFJyi6Y1=rX4Gw@mail.gmail.com>
Date: Fri, 3 Jan 2025 10:35:55 -0500
From: Xin Long <lucien.xin@...il.com>
To: Guillaume Nault <gnault@...hat.com>
Cc: David Miller <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Eric Dumazet <edumazet@...gle.com>, netdev@...r.kernel.org,
Simon Horman <horms@...nel.org>, Marcelo Ricardo Leitner <marcelo.leitner@...il.com>, linux-sctp@...r.kernel.org,
Ido Schimmel <idosch@...dia.com>
Subject: Re: [PATCH net-next] sctp: Prepare sctp_v4_get_dst() to dscp_t conversion.
On Thu, Jan 2, 2025 at 11:34 AM Guillaume Nault <gnault@...hat.com> wrote:
>
> Define inet_sk_dscp() to get a dscp_t value from struct inet_sock, so
> that sctp_v4_get_dst() can easily set ->flowi4_tos from a dscp_t
> variable. For the SCTP_DSCP_SET_MASK case, we can just use
> inet_dsfield_to_dscp() to get a dscp_t value.
>
> Then, when converting ->flowi4_tos from __u8 to dscp_t, we'll just have
> to drop the inet_dscp_to_dsfield() conversion function.
With inet_dsfield_to_dscp() && inet_dsfield_to_dscp(), the logic
looks like: tos(dsfield) -> dscp_t -> tos(dsfield)
It's a bit confusing, but it has been doing that all over routing places.
In sctp_v4_xmit(), there's the similar tos/dscp thing, although it's not
for fl4.flowi4_tos.
Also, I'm curious there are still a few places under net/ using:
fl4.flowi4_tos = tos & INET_DSCP_MASK;
Will you consider changing all of them with
inet_dsfield_to_dscp() && inet_dsfield_to_dscp() as well?
Thanks.
>
> Signed-off-by: Guillaume Nault <gnault@...hat.com>
> ---
> include/net/inet_sock.h | 6 ++++++
> net/sctp/protocol.c | 10 +++++++---
> 2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h
> index 3ccbad881d74..1086256549fa 100644
> --- a/include/net/inet_sock.h
> +++ b/include/net/inet_sock.h
> @@ -19,6 +19,7 @@
> #include <linux/netdevice.h>
>
> #include <net/flow.h>
> +#include <net/inet_dscp.h>
> #include <net/sock.h>
> #include <net/request_sock.h>
> #include <net/netns/hash.h>
> @@ -302,6 +303,11 @@ static inline unsigned long inet_cmsg_flags(const struct inet_sock *inet)
> return READ_ONCE(inet->inet_flags) & IP_CMSG_ALL;
> }
>
> +static inline dscp_t inet_sk_dscp(const struct inet_sock *inet)
> +{
> + return inet_dsfield_to_dscp(READ_ONCE(inet->tos));
> +}
> +
> #define inet_test_bit(nr, sk) \
> test_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags)
> #define inet_set_bit(nr, sk) \
> diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
> index 8b9a1b96695e..29727ed1008e 100644
> --- a/net/sctp/protocol.c
> +++ b/net/sctp/protocol.c
> @@ -43,6 +43,7 @@
> #include <net/addrconf.h>
> #include <net/inet_common.h>
> #include <net/inet_ecn.h>
> +#include <net/inet_sock.h>
> #include <net/udp_tunnel.h>
> #include <net/inet_dscp.h>
>
> @@ -427,16 +428,19 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
> struct dst_entry *dst = NULL;
> union sctp_addr *daddr = &t->ipaddr;
> union sctp_addr dst_saddr;
> - u8 tos = READ_ONCE(inet_sk(sk)->tos);
> + dscp_t dscp;
>
> if (t->dscp & SCTP_DSCP_SET_MASK)
> - tos = t->dscp & SCTP_DSCP_VAL_MASK;
> + dscp = inet_dsfield_to_dscp(t->dscp);
> + else
> + dscp = inet_sk_dscp(inet_sk(sk));
> +
> memset(&_fl, 0x0, sizeof(_fl));
> fl4->daddr = daddr->v4.sin_addr.s_addr;
> fl4->fl4_dport = daddr->v4.sin_port;
> fl4->flowi4_proto = IPPROTO_SCTP;
> if (asoc) {
> - fl4->flowi4_tos = tos & INET_DSCP_MASK;
> + fl4->flowi4_tos = inet_dscp_to_dsfield(dscp);
> fl4->flowi4_scope = ip_sock_rt_scope(asoc->base.sk);
> fl4->flowi4_oif = asoc->base.sk->sk_bound_dev_if;
> fl4->fl4_sport = htons(asoc->base.bind_addr.port);
> --
> 2.39.2
>
Powered by blists - more mailing lists