lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 15 Nov 2020 09:09:54 +1000
From:   Russell Strong <russell@...ong.id.au>
To:     Guillaume Nault <gnault@...hat.com>,
        Stephen Hemminger <stephen@...workplumber.org>
Cc:     netdev@...r.kernel.org
Subject: Re: [PATCH net-next] net: DSCP in IPv4 routing

[PATCH 1/2] DSCP in IPv4 routing

TOS handling in ipv4 routing does not use all the bits in a DSCP
value.  This change introduces a sysctl "route_tos_as_dscp" control
that, when enabled, widens masks to used the 6 DSCP bits in routing.

This commit adds the sysctl

Signed-off-by: Russell Strong <russell@...ong.id.au>
---
 Documentation/networking/ip-sysctl.rst |  5 +++++
 include/net/netns/ipv4.h               |  2 ++
 include/net/route.h                    | 16 ++++++++++++++++
 include/uapi/linux/in_route.h          |  3 +++
 include/uapi/linux/ip.h                |  2 ++
 net/ipv4/sysctl_net_ipv4.c             |  9 +++++++++
 6 files changed, 37 insertions(+)

diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index dd2b12a32b73..e728c58dbc08 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -1596,6 +1596,11 @@ igmp_link_local_mcast_reports - BOOLEAN
 
 	Default TRUE
 
+route_tos_as_dscp - BOOLEAN
+        Interpret TOS as DSCP for routing purposes
+
+        Default 0
+
 Alexey Kuznetsov.
 kuznet@....inr.ac.ru
 
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 8e4fcac4df72..8c4230090149 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -197,6 +197,8 @@ struct netns_ipv4 {
 	int sysctl_igmp_llm_reports;
 	int sysctl_igmp_qrv;
 
+	int sysctl_route_tos_as_dscp;
+
 	struct ping_group_range ping_group_range;
 
 	atomic_t dev_addr_genid;
diff --git a/include/net/route.h b/include/net/route.h
index ff021cab657e..0cc8ce316940 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -38,6 +38,22 @@
 /* IPv4 datagram length is stored into 16bit field (tot_len) */
 #define IP_MAX_MTU	0xFFFFU
 
+static inline u8 iptos_rt_mask(const struct net *net)
+{
+	if (net->ipv4.sysctl_route_tos_as_dscp)
+		return IPTOS_DS_MASK;
+	else
+		return IPTOS_TOS_MASK & ~3;
+}
+
+static inline u8 rt_tos(const struct net *net, u8 tos)
+{
+	if (net->ipv4.sysctl_route_tos_as_dscp)
+		return RT_DS(tos);
+	else
+		return RT_TOS(tos);
+}
+
 #define RTO_ONLINK	0x01
 
 #define RT_CONN_FLAGS(sk)   (RT_TOS(inet_sk(sk)->tos) | sock_flag(sk, SOCK_LOCALROUTE))
diff --git a/include/uapi/linux/in_route.h b/include/uapi/linux/in_route.h
index 0cc2c23b47f8..61a95ed2a2e0 100644
--- a/include/uapi/linux/in_route.h
+++ b/include/uapi/linux/in_route.h
@@ -28,6 +28,9 @@
 
 #define RTCF_NAT	(RTCF_DNAT|RTCF_SNAT)
 
+/* sysctl route_tos_as_dscp = 0 */
 #define RT_TOS(tos)	((tos)&IPTOS_TOS_MASK)
+/* sysctl route_tos_as_dscp = 1 */
+#define RT_DS(tos)	((tos)&IPTOS_DS_MASK)
 
 #endif /* _LINUX_IN_ROUTE_H */
diff --git a/include/uapi/linux/ip.h b/include/uapi/linux/ip.h
index e42d13b55cf3..4a6b01e03cab 100644
--- a/include/uapi/linux/ip.h
+++ b/include/uapi/linux/ip.h
@@ -20,6 +20,8 @@
 #include <linux/types.h>
 #include <asm/byteorder.h>
 
+#define IPTOS_DS_MASK		0xFC
+#define IPTOS_DS(tos)		((tos)&IPTOS_DS_MASK)
 #define IPTOS_TOS_MASK		0x1E
 #define IPTOS_TOS(tos)		((tos)&IPTOS_TOS_MASK)
 #define	IPTOS_LOWDELAY		0x10
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 3e5f4f2e705e..61b1e2bd6bc5 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -790,6 +790,15 @@ static struct ctl_table ipv4_net_table[] = {
 		.extra2		= SYSCTL_ONE,
 	},
 #endif
+	{
+		.procname	= "route_tos_as_dscp",
+		.data		= &init_net.ipv4.sysctl_route_tos_as_dscp,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
 	{
 		.procname	= "tcp_mtu_probing",
 		.data		= &init_net.ipv4.sysctl_tcp_mtu_probing,
-- 
2.26.2



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ