1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * inet_dscp.h: helpers for handling differentiated services codepoints (DSCP)
5 * DSCP is defined in RFC 2474:
8 * +---+---+---+---+---+---+---+---+
10 * +---+---+---+---+---+---+---+---+
12 * DSCP: differentiated services codepoint
13 * CU: currently unused
15 * The whole DSCP + CU bits form the DS field.
16 * The DS field is also commonly called TOS or Traffic Class (for IPv6).
18 * Note: the CU bits are now used for Explicit Congestion Notification
25 #include <linux/types.h>
27 /* Special type for storing DSCP values.
29 * A dscp_t variable stores a DS field with the CU (ECN) bits cleared.
30 * Using dscp_t allows to strictly separate DSCP and ECN bits, thus avoiding
31 * bugs where ECN bits are erroneously taken into account during FIB lookups
34 * Note: to get the real DSCP value contained in a dscp_t variable one would
35 * have to do a bit shift after calling inet_dscp_to_dsfield(). We could have
36 * a helper for that, but there's currently no users.
38 typedef u8 __bitwise dscp_t
;
40 #define INET_DSCP_MASK 0xfc
42 static inline dscp_t
inet_dsfield_to_dscp(__u8 dsfield
)
44 return (__force dscp_t
)(dsfield
& INET_DSCP_MASK
);
47 static inline __u8
inet_dscp_to_dsfield(dscp_t dscp
)
49 return (__force __u8
)dscp
;
52 static inline bool inet_validate_dscp(__u8 val
)
54 return !(val
& ~INET_DSCP_MASK
);
57 #endif /* _INET_DSCP_H */