Skip to content

Commit 3f9f5cd

Browse files
Guillaume Naultkuba-moo
Guillaume Nault
authored andcommitted
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 <[email protected]> Acked-by: Xin Long <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/1a645f4a0bc60ad18e7c0916642883ce8a43c013.1735835456.git.gnault@redhat.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 286bb99 commit 3f9f5cd

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/net/inet_sock.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/netdevice.h>
2020

2121
#include <net/flow.h>
22+
#include <net/inet_dscp.h>
2223
#include <net/sock.h>
2324
#include <net/request_sock.h>
2425
#include <net/netns/hash.h>
@@ -302,6 +303,11 @@ static inline unsigned long inet_cmsg_flags(const struct inet_sock *inet)
302303
return READ_ONCE(inet->inet_flags) & IP_CMSG_ALL;
303304
}
304305

306+
static inline dscp_t inet_sk_dscp(const struct inet_sock *inet)
307+
{
308+
return inet_dsfield_to_dscp(READ_ONCE(inet->tos));
309+
}
310+
305311
#define inet_test_bit(nr, sk) \
306312
test_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags)
307313
#define inet_set_bit(nr, sk) \

net/sctp/protocol.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <net/addrconf.h>
4444
#include <net/inet_common.h>
4545
#include <net/inet_ecn.h>
46+
#include <net/inet_sock.h>
4647
#include <net/udp_tunnel.h>
4748
#include <net/inet_dscp.h>
4849

@@ -427,16 +428,19 @@ static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
427428
struct dst_entry *dst = NULL;
428429
union sctp_addr *daddr = &t->ipaddr;
429430
union sctp_addr dst_saddr;
430-
u8 tos = READ_ONCE(inet_sk(sk)->tos);
431+
dscp_t dscp;
431432

432433
if (t->dscp & SCTP_DSCP_SET_MASK)
433-
tos = t->dscp & SCTP_DSCP_VAL_MASK;
434+
dscp = inet_dsfield_to_dscp(t->dscp);
435+
else
436+
dscp = inet_sk_dscp(inet_sk(sk));
437+
434438
memset(&_fl, 0x0, sizeof(_fl));
435439
fl4->daddr = daddr->v4.sin_addr.s_addr;
436440
fl4->fl4_dport = daddr->v4.sin_port;
437441
fl4->flowi4_proto = IPPROTO_SCTP;
438442
if (asoc) {
439-
fl4->flowi4_tos = tos & INET_DSCP_MASK;
443+
fl4->flowi4_tos = inet_dscp_to_dsfield(dscp);
440444
fl4->flowi4_scope = ip_sock_rt_scope(asoc->base.sk);
441445
fl4->flowi4_oif = asoc->base.sk->sk_bound_dev_if;
442446
fl4->fl4_sport = htons(asoc->base.bind_addr.port);

0 commit comments

Comments
 (0)