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

sctp: Prepare sctp_v4_get_dst() to dscp_t conversion.

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.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Acked-by: Xin Long <lucien.xin@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Link: https://patch.msgid.link/1a645f4a0bc60ad18e7c0916642883ce8a43c013.1735835456.git.gnault@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Guillaume Nault and committed by
Jakub Kicinski
3f9f5cd0 286bb998

+13 -3
+6
include/net/inet_sock.h
··· 19 19 #include <linux/netdevice.h> 20 20 21 21 #include <net/flow.h> 22 + #include <net/inet_dscp.h> 22 23 #include <net/sock.h> 23 24 #include <net/request_sock.h> 24 25 #include <net/netns/hash.h> ··· 301 300 static inline unsigned long inet_cmsg_flags(const struct inet_sock *inet) 302 301 { 303 302 return READ_ONCE(inet->inet_flags) & IP_CMSG_ALL; 303 + } 304 + 305 + static inline dscp_t inet_sk_dscp(const struct inet_sock *inet) 306 + { 307 + return inet_dsfield_to_dscp(READ_ONCE(inet->tos)); 304 308 } 305 309 306 310 #define inet_test_bit(nr, sk) \
+7 -3
net/sctp/protocol.c
··· 43 43 #include <net/addrconf.h> 44 44 #include <net/inet_common.h> 45 45 #include <net/inet_ecn.h> 46 + #include <net/inet_sock.h> 46 47 #include <net/udp_tunnel.h> 47 48 #include <net/inet_dscp.h> 48 49 ··· 428 427 struct dst_entry *dst = NULL; 429 428 union sctp_addr *daddr = &t->ipaddr; 430 429 union sctp_addr dst_saddr; 431 - u8 tos = READ_ONCE(inet_sk(sk)->tos); 430 + dscp_t dscp; 432 431 433 432 if (t->dscp & SCTP_DSCP_SET_MASK) 434 - tos = t->dscp & SCTP_DSCP_VAL_MASK; 433 + dscp = inet_dsfield_to_dscp(t->dscp); 434 + else 435 + dscp = inet_sk_dscp(inet_sk(sk)); 436 + 435 437 memset(&_fl, 0x0, sizeof(_fl)); 436 438 fl4->daddr = daddr->v4.sin_addr.s_addr; 437 439 fl4->fl4_dport = daddr->v4.sin_port; 438 440 fl4->flowi4_proto = IPPROTO_SCTP; 439 441 if (asoc) { 440 - fl4->flowi4_tos = tos & INET_DSCP_MASK; 442 + fl4->flowi4_tos = inet_dscp_to_dsfield(dscp); 441 443 fl4->flowi4_scope = ip_sock_rt_scope(asoc->base.sk); 442 444 fl4->flowi4_oif = asoc->base.sk->sk_bound_dev_if; 443 445 fl4->fl4_sport = htons(asoc->base.bind_addr.port);