curl: support IP Type of Service / Traffic Class: --ip-tos

Add --ip-tos option to the command line tool for setting TOS for IPv4 or
Traffic Class for IPv6.

Closes #13606
This commit is contained in:
Orgad Shaneh 2024-05-12 08:31:15 +03:00 committed by Daniel Stenberg
parent f786fce914
commit 3c20ae08b9
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 192 additions and 0 deletions

View file

@ -328,6 +328,7 @@ typedef enum {
C_TRACE_CONFIG,
C_TRACE_IDS,
C_TRACE_TIME,
C_IP_TOS,
C_UNIX_SOCKET,
C_UPLOAD_FILE,
C_URL,
@ -455,6 +456,7 @@ static const struct LongShort aliases[]= {
{"include", ARG_BOOL, 'i', C_INCLUDE},
{"insecure", ARG_BOOL, 'k', C_INSECURE},
{"interface", ARG_STRG, ' ', C_INTERFACE},
{"ip-tos", ARG_STRG, ' ', C_IP_TOS},
{"ipfs-gateway", ARG_STRG, ' ', C_IPFS_GATEWAY},
{"ipv4", ARG_NONE, '4', C_IPV4},
{"ipv6", ARG_NONE, '6', C_IPV6},
@ -1027,6 +1029,52 @@ static const struct LongShort *single(char letter)
return singles[letter - ' '];
}
struct TOSEntry {
const char *name;
unsigned char value;
};
static const struct TOSEntry tos_entries[] = {
{"AF11", 0x28},
{"AF12", 0x30},
{"AF13", 0x38},
{"AF21", 0x48},
{"AF22", 0x50},
{"AF23", 0x58},
{"AF31", 0x68},
{"AF32", 0x70},
{"AF33", 0x78},
{"AF41", 0x88},
{"AF42", 0x90},
{"AF43", 0x98},
{"CE", 0x03},
{"CS0", 0x00},
{"CS1", 0x20},
{"CS2", 0x40},
{"CS3", 0x60},
{"CS4", 0x80},
{"CS5", 0xa0},
{"CS6", 0xc0},
{"CS7", 0xe0},
{"ECT0", 0x02},
{"ECT1", 0x01},
{"EF", 0xb8},
{"LE", 0x04},
{"LOWCOST", 0x02},
{"LOWDELAY", 0x10},
{"MINCOST", 0x02},
{"RELIABILITY", 0x04},
{"THROUGHPUT", 0x08},
{"VOICE-ADMIT", 0xb0}
};
static int find_tos(const void *a, const void *b)
{
const struct TOSEntry *aa = a;
const struct TOSEntry *bb = b;
return strcmp(aa->name, bb->name);
}
#define MAX_QUERY_LEN 100000 /* larger is not likely to ever work */
static ParameterError url_query(char *nextarg,
struct GlobalConfig *global,
@ -1630,6 +1678,16 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
case C_TCP_NODELAY: /* --tcp-nodelay */
config->tcp_nodelay = toggle;
break;
case C_IP_TOS: { /* --ip-tos */
const struct TOSEntry *entry = bsearch(
&nextarg, tos_entries, sizeof(tos_entries)/sizeof(*tos_entries),
sizeof(*tos_entries), find_tos);
if(entry)
config->ip_tos = entry->value;
else /* numeric tos value */
err = str2unummax(&config->ip_tos, nextarg, 0xFF);
break;
}
case C_PROXY_DIGEST: /* --proxy-digest */
config->proxydigest = toggle;
break;