Index: sys/dev/iscsi/iscsi_ioctl.h =================================================================== --- sys/dev/iscsi/iscsi_ioctl.h +++ sys/dev/iscsi/iscsi_ioctl.h @@ -70,7 +70,8 @@ int isc_iser; char isc_offload[ISCSI_OFFLOAD_LEN]; int isc_enable; - int isc_spare[4]; + int isc_dscp; + int isc_spare[3]; }; /* Index: usr.bin/iscsictl/Makefile =================================================================== --- usr.bin/iscsictl/Makefile +++ usr.bin/iscsictl/Makefile @@ -7,7 +7,7 @@ CFLAGS+= -I${SRCTOP}/sys/dev/iscsi MAN= iscsi.conf.5 iscsictl.8 -LIBADD= xo +LIBADD= util xo YFLAGS+= -v LFLAGS+= -i Index: usr.bin/iscsictl/iscsictl.h =================================================================== --- usr.bin/iscsictl/iscsictl.h +++ usr.bin/iscsictl/iscsictl.h @@ -78,6 +78,7 @@ int t_session_type; int t_enable; int t_protocol; + int t_dscp; char *t_offload; char *t_user; char *t_secret; Index: usr.bin/iscsictl/iscsictl.c =================================================================== --- usr.bin/iscsictl/iscsictl.c +++ usr.bin/iscsictl/iscsictl.c @@ -87,6 +87,7 @@ 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->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,8 @@ "Target portal:", conf->isc_target_addr); xo_emit("{L:/%-26s}{V:alias/%s}\n", "Target alias:", state->iss_target_alias); + xo_emit("{L:/%-02x}{V:dscp/%02x}\n", + "Target DSCP:", conf->isc_dscp); xo_close_container("target"); xo_open_container("auth"); @@ -585,6 +589,8 @@ "Offload driver:", state->iss_offload); xo_emit("{L:/%-26s}", "Device nodes:"); + xo_emit("{L:/%-26s}{V:dscp/%02x}\n", + "DSCP:", conf->isc_dscp); print_periphs(state->iss_id); xo_emit("\n\n"); xo_close_instance("session"); Index: usr.bin/iscsictl/parse.y =================================================================== --- usr.bin/iscsictl/parse.y +++ usr.bin/iscsictl/parse.y @@ -44,6 +44,8 @@ #include #include "iscsictl.h" +#include +#include extern FILE *yyin; extern char *yytext; @@ -61,7 +63,9 @@ %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 @@ protocol | ignored + | + dscp ; target_name: TARGET_NAME EQUALS STR @@ -296,6 +302,48 @@ } ; +dscp: DSCP STR + { + uint64_t tmp; + + if (strcmp($2, "0x") == 0) { + tmp = strtol($2 + 2, NULL, 16); + } else if (expand_number($2, &tmp) != 0) { + yyerror("invalid numeric value"); + free($2); + return(1); + } + if (tmp >= 0x40) { + yyerror("invalid dscp value"); + return(1); + } + + target->t_dscp = tmp; + } + | DSCP BE { target->t_dscp = IPTOS_DSCP_CS0 >> 2 ; } + | DSCP EF { target->t_dscp = IPTOS_DSCP_EF >> 2 ; } + | DSCP CS0 { target->t_dscp = IPTOS_DSCP_CS0 >> 2 ; } + | DSCP CS1 { target->t_dscp = IPTOS_DSCP_CS1 >> 2 ; } + | DSCP CS2 { target->t_dscp = IPTOS_DSCP_CS2 >> 2 ; } + | DSCP CS3 { target->t_dscp = IPTOS_DSCP_CS3 >> 2 ; } + | DSCP CS4 { target->t_dscp = IPTOS_DSCP_CS4 >> 2 ; } + | DSCP CS5 { target->t_dscp = IPTOS_DSCP_CS5 >> 2 ; } + | DSCP CS6 { target->t_dscp = IPTOS_DSCP_CS6 >> 2 ; } + | DSCP CS7 { target->t_dscp = IPTOS_DSCP_CS7 >> 2 ; } + | DSCP AF11 { target->t_dscp = IPTOS_DSCP_AF11 >> 2 ; } + | DSCP AF12 { target->t_dscp = IPTOS_DSCP_AF12 >> 2 ; } + | DSCP AF13 { target->t_dscp = IPTOS_DSCP_AF13 >> 2 ; } + | DSCP AF21 { target->t_dscp = IPTOS_DSCP_AF21 >> 2 ; } + | DSCP AF22 { target->t_dscp = IPTOS_DSCP_AF22 >> 2 ; } + | DSCP AF23 { target->t_dscp = IPTOS_DSCP_AF23 >> 2 ; } + | DSCP AF31 { target->t_dscp = IPTOS_DSCP_AF31 >> 2 ; } + | DSCP AF32 { target->t_dscp = IPTOS_DSCP_AF32 >> 2 ; } + | DSCP AF33 { target->t_dscp = IPTOS_DSCP_AF33 >> 2 ; } + | DSCP AF41 { target->t_dscp = IPTOS_DSCP_AF41 >> 2 ; } + | DSCP AF42 { target->t_dscp = IPTOS_DSCP_AF42 >> 2 ; } + | DSCP AF43 { target->t_dscp = IPTOS_DSCP_AF43 >> 2 ; } + ; + %% void Index: usr.bin/iscsictl/token.l =================================================================== --- usr.bin/iscsictl/token.l +++ usr.bin/iscsictl/token.l @@ -68,6 +68,7 @@ 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 @@ 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; } Index: usr.sbin/iscsid/iscsid.c =================================================================== --- usr.sbin/iscsid/iscsid.c +++ usr.sbin/iscsid/iscsid.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -276,6 +277,25 @@ 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);