Skip to contentSkip to conversation

ipv4: make DSCP values works with ip rules

PATCH In review Pavel Balaev 2 participants 2 messages Nov 27, 2018 – Dec 1, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ipv4: make DSCP values works with ip rules

Introduce support of DSCP values in ip rules (as
described in RFC2474 and RFC2597).
Values are defined in /etc/iproute2/rt_dsfield.

Example:

$ ip ru add from 10.88.0.2 tos AF23 lookup dscp_table
$ ip ru add tos CS1 lookup dscp_table

Patch was tested with this configuration:

+-----------+
| 10.88.0.2 | -> ping 172.16.0.1 -Q 0x58 ->
|   host0   |
+-----------+
   +-------------------------------------+
   | router with patched kernel          |
   |                                     |
-> | from 10.88.0.2 tos AF43 lookup dscp |->
   | table dscp:                         |
   |   172.16.0.0/24 via 10.200.0.2      |
   +-------------------------------------+
   +------------------+
-> | eth0: 10.200.0.2 |
   | eth1: 172.16.0.1 |
   |      host1       |
   +------------------+
---
 include/net/route.h     | 2 +-
 include/uapi/linux/ip.h | 2 ++
 net/ipv4/fib_rules.c    | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)
include/net/route.h +1 -1
index bb53cdba..b984ecff 100644
@@ -239,7 +239,7 @@ static inline void ip_rt_put(struct rtable *rt)
 	dst_release(&rt->dst);
 }
 
-#define IPTOS_RT_MASK	(IPTOS_TOS_MASK & ~3)
+#define IPTOS_RT_MASK	(IPTOS_DSCP_MASK & ~3)
 
 extern const __u8 ip_tos2prio[16];
 
include/uapi/linux/ip.h +2 -0
index e42d13b5..307ce2b1 100644
@@ -38,6 +38,8 @@
 #define IPTOS_PREC_PRIORITY             0x20
 #define IPTOS_PREC_ROUTINE              0x00
 
+#define IPTOS_DSCP_MASK		(IPTOS_TOS_MASK | IPTOS_PREC_MASK)
+#define IPTOS_DSCP(tos)		((tos)&IPTOS_DSCP_MASK)
 
 /* IP options */
 #define IPOPT_COPY		0x80
net/ipv4/fib_rules.c +1 -1
index f8eb78d0..9ba91ef0 100644
@@ -220,7 +220,7 @@ static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
 	int err = -EINVAL;
 	struct fib4_rule *rule4 = (struct fib4_rule *) rule;
 
-	if (frh->tos & ~IPTOS_TOS_MASK) {
+	if (frh->tos & ~IPTOS_DSCP_MASK) {
 		NL_SET_ERR_MSG(extack, "Invalid tos");
 		goto errout;
 	}
Signature · 1 line
2.18.1
maintainer
#1 lore raw

From: Pavel Balaev <[email protected]>
Date: Tue, 27 Nov 2018 13:07:10 +0300

include/net/route.h static inline void ip_rt_put(struct rtable *rt) · line 242

Quoted 2 lines
include/net/route.h +1 -1
-#define IPTOS_RT_MASK	(IPTOS_TOS_MASK & ~3)
+#define IPTOS_RT_MASK	(IPTOS_DSCP_MASK & ~3)

I was hoping my original feedback would have you actually go investigate why IPTOS_RT_MASK is defined the way that it is.

I will try again.

Please grep around for RTO_ONLINK and see how that specifically interferes with what you are trying to do here.

I don't think your goal is achievable with how things are defined currently.

Sorry.