Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Oct 2020 20:52:05 +0000 (UTC)
From:      Richard Scheffenegger <rscheff@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r367019 - in stable/12: sys/dev/iscsi usr.bin/iscsictl usr.sbin/iscsid
Message-ID:  <202010242052.09OKq5tY066818@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rscheff
Date: Sat Oct 24 20:52:05 2020
New Revision: 367019
URL: https://svnweb.freebsd.org/changeset/base/367019

Log:
  MFC r366573: Add DSCP support for network QoS to iscsi initiator.
  
  Allow the DSCP codepoint also to be configurable
  for the traffic in the direction from the initiator
  to the target, such that writes and any requests
  are also treated in the appropriate QoS class.
  
  Reviewed by:	mav
  MFC after:	2 weeks
  Sponsored by:	NetApp, Inc.
  Differential Revision:	https://reviews.freebsd.org/D26714

Modified:
  stable/12/sys/dev/iscsi/iscsi_ioctl.h
  stable/12/usr.bin/iscsictl/Makefile
  stable/12/usr.bin/iscsictl/iscsi.conf.5
  stable/12/usr.bin/iscsictl/iscsictl.c
  stable/12/usr.bin/iscsictl/iscsictl.h
  stable/12/usr.bin/iscsictl/parse.y
  stable/12/usr.bin/iscsictl/token.l
  stable/12/usr.sbin/iscsid/iscsid.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/dev/iscsi/iscsi_ioctl.h
==============================================================================
--- stable/12/sys/dev/iscsi/iscsi_ioctl.h	Sat Oct 24 20:48:35 2020	(r367018)
+++ stable/12/sys/dev/iscsi/iscsi_ioctl.h	Sat Oct 24 20:52:05 2020	(r367019)
@@ -70,7 +70,8 @@ struct iscsi_session_conf {
 	int		isc_iser;
 	char		isc_offload[ISCSI_OFFLOAD_LEN];
 	int		isc_enable;
-	int		isc_spare[4];
+	int		isc_dscp;
+	int		isc_spare[3];
 };
 
 /*

Modified: stable/12/usr.bin/iscsictl/Makefile
==============================================================================
--- stable/12/usr.bin/iscsictl/Makefile	Sat Oct 24 20:48:35 2020	(r367018)
+++ stable/12/usr.bin/iscsictl/Makefile	Sat Oct 24 20:52:05 2020	(r367019)
@@ -7,7 +7,7 @@ CFLAGS+=	-I${.CURDIR}
 CFLAGS+=	-I${SRCTOP}/sys/dev/iscsi
 MAN=		iscsi.conf.5 iscsictl.8
 
-LIBADD=		xo
+LIBADD=		util xo
 
 YFLAGS+=	-v
 LFLAGS+=	-i

Modified: stable/12/usr.bin/iscsictl/iscsi.conf.5
==============================================================================
--- stable/12/usr.bin/iscsictl/iscsi.conf.5	Sat Oct 24 20:48:35 2020	(r367018)
+++ stable/12/usr.bin/iscsictl/iscsi.conf.5	Sat Oct 24 20:52:05 2020	(r367019)
@@ -145,6 +145,16 @@ for iSCSI over RDMA, or
 .Qq Ar iSCSI .
 Default is
 .Qq Ar iSCSI .
+.It Cm dscp
+The DiffServ Codepoint used for sending data. The DSCP can be
+set to numeric, or hexadecimal values directly, as well as the
+well-defined
+.Qq Ar cs<n>
+and
+.Qq Ar af<xx>
+codepoints.
+Default is no specified dscp codepoint, which means the default
+of the outgoing interface is used.
 .El
 .Sh FILES
 .Bl -tag -width indent

Modified: stable/12/usr.bin/iscsictl/iscsictl.c
==============================================================================
--- stable/12/usr.bin/iscsictl/iscsictl.c	Sat Oct 24 20:48:35 2020	(r367018)
+++ stable/12/usr.bin/iscsictl/iscsictl.c	Sat Oct 24 20:52:05 2020	(r367019)
@@ -87,6 +87,7 @@ target_new(struct conf *conf)
 	if (targ == NULL)
 		xo_err(1, "calloc");
 	targ->t_conf = conf;
+	targ->t_dscp = -1;
 	TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next);
 
 	return (targ);
@@ -358,6 +359,7 @@ conf_from_target(struct iscsi_session_conf *conf,
 		conf->isc_data_digest = ISCSI_DIGEST_CRC32C;
 	else
 		conf->isc_data_digest = ISCSI_DIGEST_NONE;
+	conf->isc_dscp = targ->t_dscp;
 }
 
 static int
@@ -535,6 +537,9 @@ kernel_list(int iscsi_fd, const struct target *targ __
 			    "Target portal:", conf->isc_target_addr);
 			xo_emit("{L:/%-26s}{V:alias/%s}\n",
 			    "Target alias:", state->iss_target_alias);
+			if (conf->isc_dscp != -1)
+				xo_emit("{L:/%-26s}{V:dscp/0x%02x}\n",
+				    "Target DSCP:", conf->isc_dscp);
 			xo_close_container("target");
 
 			xo_open_container("auth");

Modified: stable/12/usr.bin/iscsictl/iscsictl.h
==============================================================================
--- stable/12/usr.bin/iscsictl/iscsictl.h	Sat Oct 24 20:48:35 2020	(r367018)
+++ stable/12/usr.bin/iscsictl/iscsictl.h	Sat Oct 24 20:52:05 2020	(r367019)
@@ -78,6 +78,7 @@ struct target {
 	int			t_session_type;
 	int			t_enable;
 	int			t_protocol;
+	int			t_dscp;
 	char			*t_offload;
 	char			*t_user;
 	char			*t_secret;

Modified: stable/12/usr.bin/iscsictl/parse.y
==============================================================================
--- stable/12/usr.bin/iscsictl/parse.y	Sat Oct 24 20:48:35 2020	(r367018)
+++ stable/12/usr.bin/iscsictl/parse.y	Sat Oct 24 20:52:05 2020	(r367019)
@@ -44,6 +44,8 @@
 #include <libxo/xo.h>
 
 #include "iscsictl.h"
+#include <netinet/in.h>
+#include <netinet/ip.h>
 
 extern FILE *yyin;
 extern char *yytext;
@@ -61,7 +63,9 @@ extern void	yyrestart(FILE *);
 %token AUTH_METHOD ENABLE HEADER_DIGEST DATA_DIGEST TARGET_NAME TARGET_ADDRESS
 %token INITIATOR_NAME INITIATOR_ADDRESS INITIATOR_ALIAS USER SECRET
 %token MUTUAL_USER MUTUAL_SECRET SEMICOLON SESSION_TYPE PROTOCOL OFFLOAD
-%token IGNORED EQUALS OPENING_BRACKET CLOSING_BRACKET
+%token IGNORED EQUALS OPENING_BRACKET CLOSING_BRACKET DSCP
+%token AF11 AF12 AF13 AF21 AF22 AF23 AF31 AF32 AF33 AF41 AF42 AF43
+%token BE EF CS0 CS1 CS2 CS3 CS4 CS5 CS6 CS7
 
 %union
 {
@@ -127,6 +131,8 @@ target_entry:
 	protocol
 	|
 	ignored
+	|
+	dscp
 	;
 
 target_name:	TARGET_NAME EQUALS STR
@@ -294,6 +300,48 @@ ignored:	IGNORED EQUALS STR
 	{
 		xo_warnx("obsolete statement ignored at line %d", lineno);
 	}
+	;
+
+dscp:		DSCP EQUALS STR
+	{
+		uint64_t tmp;
+
+		if (strcmp($3, "0x") == 0) {
+			tmp = strtol($3 + 2, NULL, 16);
+		} else if (expand_number($3, &tmp) != 0) {
+			yyerror("invalid numeric value");
+			free($3);
+			return(1);
+		}
+		if (tmp >= 0x40) {
+			yyerror("invalid dscp value");
+			return(1);
+		}
+
+		target->t_dscp = tmp;
+	}
+	| DSCP EQUALS BE	{ target->t_dscp = IPTOS_DSCP_CS0  >> 2 ; }
+	| DSCP EQUALS EF	{ target->t_dscp = IPTOS_DSCP_EF   >> 2 ; }
+	| DSCP EQUALS CS0	{ target->t_dscp = IPTOS_DSCP_CS0  >> 2 ; }
+	| DSCP EQUALS CS1	{ target->t_dscp = IPTOS_DSCP_CS1  >> 2 ; }
+	| DSCP EQUALS CS2	{ target->t_dscp = IPTOS_DSCP_CS2  >> 2 ; }
+	| DSCP EQUALS CS3	{ target->t_dscp = IPTOS_DSCP_CS3  >> 2 ; }
+	| DSCP EQUALS CS4	{ target->t_dscp = IPTOS_DSCP_CS4  >> 2 ; }
+	| DSCP EQUALS CS5	{ target->t_dscp = IPTOS_DSCP_CS5  >> 2 ; }
+	| DSCP EQUALS CS6	{ target->t_dscp = IPTOS_DSCP_CS6  >> 2 ; }
+	| DSCP EQUALS CS7	{ target->t_dscp = IPTOS_DSCP_CS7  >> 2 ; }
+	| DSCP EQUALS AF11	{ target->t_dscp = IPTOS_DSCP_AF11 >> 2 ; }
+	| DSCP EQUALS AF12	{ target->t_dscp = IPTOS_DSCP_AF12 >> 2 ; }
+	| DSCP EQUALS AF13	{ target->t_dscp = IPTOS_DSCP_AF13 >> 2 ; }
+	| DSCP EQUALS AF21	{ target->t_dscp = IPTOS_DSCP_AF21 >> 2 ; }
+	| DSCP EQUALS AF22	{ target->t_dscp = IPTOS_DSCP_AF22 >> 2 ; }
+	| DSCP EQUALS AF23	{ target->t_dscp = IPTOS_DSCP_AF23 >> 2 ; }
+	| DSCP EQUALS AF31	{ target->t_dscp = IPTOS_DSCP_AF31 >> 2 ; }
+	| DSCP EQUALS AF32	{ target->t_dscp = IPTOS_DSCP_AF32 >> 2 ; }
+	| DSCP EQUALS AF33	{ target->t_dscp = IPTOS_DSCP_AF33 >> 2 ; }
+	| DSCP EQUALS AF41	{ target->t_dscp = IPTOS_DSCP_AF41 >> 2 ; }
+	| DSCP EQUALS AF42	{ target->t_dscp = IPTOS_DSCP_AF42 >> 2 ; }
+	| DSCP EQUALS AF43	{ target->t_dscp = IPTOS_DSCP_AF43 >> 2 ; }
 	;
 
 %%

Modified: stable/12/usr.bin/iscsictl/token.l
==============================================================================
--- stable/12/usr.bin/iscsictl/token.l	Sat Oct 24 20:48:35 2020	(r367018)
+++ stable/12/usr.bin/iscsictl/token.l	Sat Oct 24 20:52:05 2020	(r367019)
@@ -68,6 +68,7 @@ enable			{ return ENABLE; }
 protocol		{ return PROTOCOL; }
 offload			{ return OFFLOAD; }
 port			{ return IGNORED; }
+dscp			{ return DSCP; }
 MaxConnections		{ return IGNORED; }
 TargetAlias		{ return IGNORED; }
 TargetPortalGroupTag	{ return IGNORED; }
@@ -86,6 +87,28 @@ tags			{ return IGNORED; }
 maxluns			{ return IGNORED; }
 sockbufsize		{ return IGNORED; }
 chapDigest		{ return IGNORED; }
+af11			{ return AF11; }
+af12			{ return AF12; }
+af13			{ return AF13; }
+af21			{ return AF21; }
+af22			{ return AF22; }
+af23			{ return AF23; }
+af31			{ return AF31; }
+af32			{ return AF32; }
+af33			{ return AF33; }
+af41			{ return AF41; }
+af42			{ return AF42; }
+af43			{ return AF43; }
+be			{ return CS0;  }
+ef			{ return EF;   }
+cs0			{ return CS0;  }
+cs1			{ return CS1;  }
+cs2			{ return CS2;  }
+cs3			{ return CS3;  }
+cs4			{ return CS4;  }
+cs5			{ return CS5;  }
+cs6			{ return CS6;  }
+cs7			{ return CS7;  }
 \"[^"]+\"		{ yylval.str = strndup(yytext + 1,
 			    strlen(yytext) - 2); return STR; }
 [a-zA-Z0-9\.\-_/\:\[\]]+ { yylval.str = strdup(yytext); return STR; }

Modified: stable/12/usr.sbin/iscsid/iscsid.c
==============================================================================
--- stable/12/usr.sbin/iscsid/iscsid.c	Sat Oct 24 20:48:35 2020	(r367018)
+++ stable/12/usr.sbin/iscsid/iscsid.c	Sat Oct 24 20:52:05 2020	(r367019)
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/socket.h>
 #include <sys/capsicum.h>
 #include <sys/wait.h>
+#include <netinet/in.h>
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -275,6 +276,25 @@ connection_new(int iscsi_fd, const struct iscsi_daemon
 	if (setsockopt(conn->conn_socket, SOL_SOCKET, SO_SNDBUF,
 	    &sockbuf, sizeof(sockbuf)) == -1)
 		log_warn("setsockopt(SO_SNDBUF) failed");
+	if (conn->conn_conf.isc_dscp != -1) {
+		int tos = conn->conn_conf.isc_dscp << 2;
+		if (to_ai->ai_family == AF_INET) {
+			if (setsockopt(conn->conn_socket,
+			    IPPROTO_IP, IP_TOS,
+			    &tos, sizeof(tos)) == -1)
+				log_warn("setsockopt(IP_TOS) "
+				    "failed for %s",
+				    from_addr);
+		} else
+		if (to_ai->ai_family == AF_INET6) {
+			if (setsockopt(conn->conn_socket,
+			    IPPROTO_IPV6, IPV6_TCLASS,
+			    &tos, sizeof(tos)) == -1)
+				log_warn("setsockopt(IPV6_TCLASS) "
+				    "failed for %s",
+				    from_addr);
+		}
+	}
 	if (from_ai != NULL) {
 		error = bind(conn->conn_socket, from_ai->ai_addr,
 		    from_ai->ai_addrlen);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202010242052.09OKq5tY066818>