From 54fe8c44e1bd72182ff0def37f883f15f5f7e2d2 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 14 May 2024 09:54:26 +0300 Subject: [PATCH] curl: support VLAN Priority: --vlan-priority Add --vlan-priority option to the command line tool for setting VLAN priority. Closes #13907 --- .github/scripts/spellcheck.words | 1 + docs/cmdline-opts/Makefile.inc | 1 + docs/cmdline-opts/ip-tos.md | 1 + docs/cmdline-opts/vlan-priority.md | 23 ++++++++++++++++++++++ docs/options-in-versions | 1 + src/tool_cfgable.h | 1 + src/tool_getparam.c | 5 +++++ src/tool_listhelp.c | 3 +++ src/tool_operate.c | 31 +++++++++++++++++++++++++----- 9 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 docs/cmdline-opts/vlan-priority.md diff --git a/.github/scripts/spellcheck.words b/.github/scripts/spellcheck.words index ff09e28620..869d588ea1 100644 --- a/.github/scripts/spellcheck.words +++ b/.github/scripts/spellcheck.words @@ -908,6 +908,7 @@ VC vcpkg vexxhost Viktor +VLAN VM VMS VMware diff --git a/docs/cmdline-opts/Makefile.inc b/docs/cmdline-opts/Makefile.inc index f8e0da680d..087e05c7cf 100644 --- a/docs/cmdline-opts/Makefile.inc +++ b/docs/cmdline-opts/Makefile.inc @@ -304,5 +304,6 @@ DPAGES = \ variable.md \ verbose.md \ version.md \ + vlan-priority.md \ write-out.md \ xattr.md diff --git a/docs/cmdline-opts/ip-tos.md b/docs/cmdline-opts/ip-tos.md index fa80ba4499..59729ba8b0 100644 --- a/docs/cmdline-opts/ip-tos.md +++ b/docs/cmdline-opts/ip-tos.md @@ -10,6 +10,7 @@ Protocols: All Multi: single See-also: - tcp-nodelay + - vlan-priority Example: - --ip-tos CS5 $URL --- diff --git a/docs/cmdline-opts/vlan-priority.md b/docs/cmdline-opts/vlan-priority.md new file mode 100644 index 0000000000..5d5e23a389 --- /dev/null +++ b/docs/cmdline-opts/vlan-priority.md @@ -0,0 +1,23 @@ +--- +c: Copyright (C) Daniel Stenberg, , et al. +SPDX-License-Identifier: curl +Long: vlan-priority +Arg: +Help: Set VLAN priority +Added: 8.9.0 +Category: connection +Protocols: All +Multi: single +See-also: + - ip-tos +Example: + - --vlan-priority 4 $URL +--- + +# `--vlan-priority` + +Set VLAN priority as defined in IEEE 802.1Q. (Added in 8.9.0). + +This field is set on Ethernet level, and only works within a local network. + +The valid range for \ is 0 to 7. diff --git a/docs/options-in-versions b/docs/options-in-versions index bdeab85dbf..15f5a54dfb 100644 --- a/docs/options-in-versions +++ b/docs/options-in-versions @@ -269,5 +269,6 @@ --variable 8.3.0 --verbose (-v) 4.0 --version (-V) 4.0 +--vlan-priority 8.9.0 --write-out (-w) 6.5 --xattr 7.21.3 diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h index 7a8e023c50..f0e904531a 100644 --- a/src/tool_cfgable.h +++ b/src/tool_cfgable.h @@ -86,6 +86,7 @@ struct OperationConfig { long low_speed_limit; long low_speed_time; long ip_tos; /* IP Type of Service */ + long vlan_priority; /* VLAN priority */ char *dns_servers; /* dot notation: 1.1.1.1;2.2.2.2 */ char *dns_interface; /* interface name */ char *dns_ipv4_addr; /* dot notation */ diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 5b1ced0295..869b8be0da 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -340,6 +340,7 @@ typedef enum { C_VARIABLE, C_VERBOSE, C_VERSION, + C_VLAN_PRIORITY, C_WDEBUG, C_WRITE_OUT, C_XATTR @@ -624,6 +625,7 @@ static const struct LongShort aliases[]= { {"variable", ARG_STRG, ' ', C_VARIABLE}, {"verbose", ARG_BOOL, 'v', C_VERBOSE}, {"version", ARG_BOOL, 'V', C_VERSION}, + {"vlan-priority", ARG_STRG, ' ', C_VLAN_PRIORITY}, #ifdef USE_WATT32 {"wdebug", ARG_BOOL, ' ', C_WDEBUG}, #endif @@ -1690,6 +1692,9 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ err = str2unummax(&config->ip_tos, nextarg, 0xFF); break; } + case C_VLAN_PRIORITY: /* --vlan-priority */ + err = str2unummax(&config->vlan_priority, nextarg, 7); + break; case C_PROXY_DIGEST: /* --proxy-digest */ config->proxydigest = toggle; break; diff --git a/src/tool_listhelp.c b/src/tool_listhelp.c index e77a9f4c37..27f49f8fa8 100644 --- a/src/tool_listhelp.c +++ b/src/tool_listhelp.c @@ -810,6 +810,9 @@ const struct helptxt helptext[] = { {"-V, --version", "Show version number and quit", CURLHELP_IMPORTANT | CURLHELP_CURL}, + {" --vlan-priority ", + "Set VLAN priority", + CURLHELP_CONNECTION}, {"-w, --write-out ", "Output FORMAT after completion", CURLHELP_VERBOSE}, diff --git a/src/tool_operate.c b/src/tool_operate.c index 1caf8f0e8e..6471ae4f05 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -162,7 +162,7 @@ static int get_address_family(curl_socket_t sockfd) } #endif -#if defined(IP_TOS) || defined(IPV6_TCLASS) +#if defined(IP_TOS) || defined(IPV6_TCLASS) || defined(SO_PRIORITY) static int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose) { @@ -171,6 +171,7 @@ static int sockopt_callback(void *clientp, curl_socket_t curlfd, return CURL_SOCKOPT_OK; (void)config; (void)curlfd; +#if defined(IP_TOS) || defined(IPV6_TCLASS) if(config->ip_tos > 0) { int tos = (int)config->ip_tos; int result = 0; @@ -195,6 +196,18 @@ static int sockopt_callback(void *clientp, curl_socket_t curlfd, tos, error, strerror(error)); } } +#endif +#ifdef SO_PRIORITY + if(config->vlan_priority > 0) { + int priority = (int)config->vlan_priority; + if(setsockopt(curlfd, SOL_SOCKET, SO_PRIORITY, + (const char *)&priority, sizeof(priority)) != 0) { + int error = errno; + warnf(config->global, "VLAN priority %d failed with errno %d: %s;\n", + priority, error, strerror(error)); + } + } +#endif return CURL_SOCKOPT_OK; } #endif @@ -2253,13 +2266,21 @@ static CURLcode single_transfer(struct GlobalConfig *global, #endif /* new in 8.9.0 */ - if(config->ip_tos > 0) { -#if defined(IP_TOS) || defined(IPV6_TCLASS) + if(config->ip_tos > 0 || config->vlan_priority > 0) { +#if defined(IP_TOS) || defined(IPV6_TCLASS) || defined(SO_PRIORITY) my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback); my_setopt(curl, CURLOPT_SOCKOPTDATA, config); #else - warnf(config->global, - "Type of service is not supported in this build."); + if(config->ip_tos > 0) { + errorf(config->global, + "Type of service is not supported in this build."); + result = CURLE_NOT_BUILT_IN; + } + if(config->vlan_priority > 0) { + errorf(config->global, + "VLAN priority is not supported in this build."); + result = CURLE_NOT_BUILT_IN; + } #endif } -- 2.47.3