]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: support VLAN Priority: --vlan-priority
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>
Tue, 14 May 2024 06:54:26 +0000 (09:54 +0300)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 11 Jun 2024 21:30:34 +0000 (23:30 +0200)
Add --vlan-priority option to the command line tool for setting VLAN
priority.

Closes #13907

.github/scripts/spellcheck.words
docs/cmdline-opts/Makefile.inc
docs/cmdline-opts/ip-tos.md
docs/cmdline-opts/vlan-priority.md [new file with mode: 0644]
docs/options-in-versions
src/tool_cfgable.h
src/tool_getparam.c
src/tool_listhelp.c
src/tool_operate.c

index ff09e286204d581d17ffbdca81fa96faa7ecbca0..869d588ea116c24b2fe5e12a06c3f1b1669e647d 100644 (file)
@@ -908,6 +908,7 @@ VC
 vcpkg
 vexxhost
 Viktor
+VLAN
 VM
 VMS
 VMware
index f8e0da680def891a11cb9a78f0a20320c30e12af..087e05c7cf809afe334e59338f6772930c9e81a1 100644 (file)
@@ -304,5 +304,6 @@ DPAGES = \
   variable.md \
   verbose.md \
   version.md \
+  vlan-priority.md \
   write-out.md \
   xattr.md
index fa80ba44999961b56f4cce8921a32506fe8f360e..59729ba8b0de55154b9a5e53316c484816c56e53 100644 (file)
@@ -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 (file)
index 0000000..5d5e23a
--- /dev/null
@@ -0,0 +1,23 @@
+---
+c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+SPDX-License-Identifier: curl
+Long: vlan-priority
+Arg: <priority>
+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 \<priority\> is 0 to 7.
index bdeab85dbf96bc6bed0a5b427b70e96eba68c6e3..15f5a54dfb767e56e9046247c0edc19611d2d3ee 100644 (file)
 --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
index 7a8e023c506eaf1d3dbeafde36a90d3c5d160eb0..f0e904531a2e8f8f2515dc30b05d1b7a9a9e20ff 100644 (file)
@@ -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 */
index 5b1ced0295757f986a1a8f3a3184b0372a161eff..869b8be0dae0a1e84bc8b118c3e4d386f20ba194 100644 (file)
@@ -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;
index e77a9f4c37556087d700e037646f0a706a8ba52c..27f49f8fa8627f1115022e0db8220d0771e22e3d 100644 (file)
@@ -810,6 +810,9 @@ const struct helptxt helptext[] = {
   {"-V, --version",
    "Show version number and quit",
    CURLHELP_IMPORTANT | CURLHELP_CURL},
+  {"    --vlan-priority <priority>",
+   "Set VLAN priority",
+   CURLHELP_CONNECTION},
   {"-w, --write-out <format>",
    "Output FORMAT after completion",
    CURLHELP_VERBOSE},
index 1caf8f0e8e0c60b6db5da5128c5d8dab380a3081..6471ae4f05502ef0bb2bbf802aff37c3c04cf44c 100644 (file)
@@ -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
         }