From 44e2ec05f56a15fdf8da04127b46c66341c7dbe4 Mon Sep 17 00:00:00 2001 From: mav Date: Fri, 26 Apr 2019 17:01:56 +0000 Subject: [PATCH] MFC r335837 (by kp): carp: Set DSCP value CS7 Update carp to set DSCP value CS7(Network Traffic) in the flowlabel field of packets by default. Currently carp only sets TOS_LOWDELAY in IPv4 which was deprecated in 1998. This also implements sysctl that can revert carp back to it's old behavior if desired. This will allow implementation of QOS on modern network devices to make sure carp packets aren't dropped during interface contention. Submitted by: Nick Wolff Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D14536 --- UPDATING | 6 ++++++ share/man/man4/carp.4 | 8 +++++++- sys/netinet/ip.h | 5 +++++ sys/netinet/ip6.h | 1 + sys/netinet/ip_carp.c | 32 +++++++++++++++++++++++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/UPDATING b/UPDATING index 9e2eb20c0b2..06b74c60e5d 100644 --- a/UPDATING +++ b/UPDATING @@ -16,6 +16,12 @@ from older versions of FreeBSD, try WITHOUT_CLANG and WITH_GCC to bootstrap to the tip of head, and then rebuild without this option. The bootstrap process from older version of current across the gcc/clang cutover is a bit fragile. +20190426: + CARP now sets DSCP value CS7(Network Traffic) in the flowlabel field + of packets by default instead of only setting TOS_LOWDELAY in IPv4, + which was deprecated in 1998. Original behavior can be restored by + setting sysctl net.inet.carp.dscp=4. + 20190416: Clang, llvm, lld, lldb, compiler-rt and libc++ have been upgraded to 8.0.0. Please see the 20141231 entry below for information about diff --git a/share/man/man4/carp.4 b/share/man/man4/carp.4 index c7895122842..877f6a76f1f 100644 --- a/share/man/man4/carp.4 +++ b/share/man/man4/carp.4 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 21, 2013 +.Dd July 1, 2018 .Dt CARP 4 .Os .Sh NAME @@ -102,6 +102,12 @@ Allow virtual hosts to preempt each other. When enabled, a vhid in a backup state would preempt a master that is announcing itself with a lower advskew. Disabled by default. +.It Va net.inet.carp.dscp +DSCP value in carp packet. +Valid Values are 0 to 63. +A value of 4 is equivalent to the old standard of TOS LOW_DELAY. +TOS values were deprecated and replaced by DSCP in 1998. +The default value is 56 (CS7/Network Control). .It Va net.inet.carp.log Determines what events relating to .Nm diff --git a/sys/netinet/ip.h b/sys/netinet/ip.h index 98bd1e99940..e17c4376865 100644 --- a/sys/netinet/ip.h +++ b/sys/netinet/ip.h @@ -91,6 +91,11 @@ struct ip { #define IPTOS_PREC_PRIORITY IPTOS_DSCP_CS1 #define IPTOS_PREC_ROUTINE IPTOS_DSCP_CS0 +/* + * Offset of Diffserv decimal value to convert it to tos value . + */ +#define IPTOS_DSCP_OFFSET 2 + /* * Definitions for DiffServ Codepoints as per RFC2474 and RFC5865. */ diff --git a/sys/netinet/ip6.h b/sys/netinet/ip6.h index ff870579bbc..8d601652156 100644 --- a/sys/netinet/ip6.h +++ b/sys/netinet/ip6.h @@ -102,6 +102,7 @@ struct ip6_hdr { #define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */ #endif /* LITTLE_ENDIAN */ #endif +#define IPV6_FLOWLABEL_LEN 20 #if 1 /* ECN bits proposed by Sally Floyd */ #define IP6TOS_CE 0x01 /* congestion experienced */ diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 32e0185c337..9a9e609fe3a 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -190,6 +190,10 @@ static int proto_reg[] = {-1, -1}; static VNET_DEFINE(int, carp_allow) = 1; #define V_carp_allow VNET(carp_allow) +/* Set DSCP in outgoing CARP packets. */ +static VNET_DEFINE(int, carp_dscp) = 56; +#define V_carp_dscp VNET(carp_dscp) + /* Preempt slower nodes. */ static VNET_DEFINE(int, carp_preempt) = 0; #define V_carp_preempt VNET(carp_preempt) @@ -210,11 +214,15 @@ static VNET_DEFINE(int, carp_senderr_adj) = CARP_MAXSKEW; static VNET_DEFINE(int, carp_ifdown_adj) = CARP_MAXSKEW; #define V_carp_ifdown_adj VNET(carp_ifdown_adj) +static int carp_dscp_sysctl(SYSCTL_HANDLER_ARGS); static int carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS); SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP"); SYSCTL_INT(_net_inet_carp, OID_AUTO, allow, CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(carp_allow), 0, "Accept incoming CARP packets"); +SYSCTL_PROC(_net_inet_carp, OID_AUTO, dscp, + CTLFLAG_VNET | CTLTYPE_INT | CTLFLAG_RW, 0, 0, carp_dscp_sysctl, "I", + "DSCP value for carp packets"); SYSCTL_INT(_net_inet_carp, OID_AUTO, preempt, CTLFLAG_VNET | CTLFLAG_RW, &VNET_NAME(carp_preempt), 0, "High-priority backup preemption mode"); SYSCTL_INT(_net_inet_carp, OID_AUTO, log, CTLFLAG_VNET | CTLFLAG_RW, @@ -834,7 +842,7 @@ carp_send_ad_locked(struct carp_softc *sc) ip = mtod(m, struct ip *); ip->ip_v = IPVERSION; ip->ip_hl = sizeof(*ip) >> 2; - ip->ip_tos = IPTOS_LOWDELAY; + ip->ip_tos = V_carp_dscp << IPTOS_DSCP_OFFSET; ip->ip_len = htons(len); ip->ip_off = htons(IP_DF); ip->ip_ttl = CARP_DFLTTL; @@ -886,6 +894,10 @@ carp_send_ad_locked(struct carp_softc *sc) ip6 = mtod(m, struct ip6_hdr *); bzero(ip6, sizeof(*ip6)); ip6->ip6_vfc |= IPV6_VERSION; + /* Traffic class isn't defined in ip6 struct instead + * it gets offset into flowid field */ + ip6->ip6_flow |= htonl(V_carp_dscp << (IPV6_FLOWLABEL_LEN + + IPTOS_DSCP_OFFSET)); ip6->ip6_hlim = CARP_DFLTTL; ip6->ip6_nxt = IPPROTO_CARP; bzero(&sa, sizeof(sa)); @@ -2002,6 +2014,24 @@ carp_demote_adj(int adj, char *reason) taskqueue_enqueue(taskqueue_swi, &carp_sendall_task); } +static int +carp_dscp_sysctl(SYSCTL_HANDLER_ARGS) +{ + int new, error; + + new = V_carp_dscp; + error = sysctl_handle_int(oidp, &new, 0, req); + if (error || !req->newptr) + return (error); + + if (new < 0 || new > 63) + return (EINVAL); + + V_carp_dscp = new; + + return (0); +} + static int carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS) { -- 2.45.0