comparison netio.c @ 1858:ed3326f21888

Test for IP_TOS and hardcode DSCP values This allows it to work on macos too
author Matt Johnston <matt@ucc.asn.au>
date Tue, 25 Jan 2022 17:57:05 +0800
parents 6022df862942
children 5001e9c5641f
comparison
equal deleted inserted replaced
1857:6022df862942 1858:ed3326f21888
372 } 372 }
373 #endif 373 #endif
374 /* Don't log ENOTSOCK errors so that this can harmlessly be called 374 /* Don't log ENOTSOCK errors so that this can harmlessly be called
375 * on a client '-J' proxy pipe */ 375 * on a client '-J' proxy pipe */
376 376
377 #ifdef IPTOS_DSCP_AF21 377 #ifdef IP_TOS
378 /* Set the DSCP field for outbound IP packet priority. 378 /* Set the DSCP field for outbound IP packet priority.
379 rfc4594 has some guidance to meanings. 379 rfc4594 has some guidance to meanings.
380 380
381 We set AF21 as "Low-Latency" class for interactive (tty session). 381 We set AF21 as "Low-Latency" class for interactive (tty session).
382 Set AF11 "High-Throughput" for bulk data (which includes things 382 Set AF11 "High-Throughput" for bulk data (which includes things
386 OpenSSH at present uses AF21/CS1, rationale 386 OpenSSH at present uses AF21/CS1, rationale
387 https://cvsweb.openbsd.org/src/usr.bin/ssh/readconf.c#rev1.284 387 https://cvsweb.openbsd.org/src/usr.bin/ssh/readconf.c#rev1.284
388 388
389 Old Dropbear/OpenSSH and Debian/Ubuntu OpenSSH (at Jan 2022) use 389 Old Dropbear/OpenSSH and Debian/Ubuntu OpenSSH (at Jan 2022) use
390 IPTOS_LOWDELAY/IPTOS_THROUGHPUT 390 IPTOS_LOWDELAY/IPTOS_THROUGHPUT
391
392 DSCP constants are from Linux headers, applicable to other platforms
393 such as macos.
391 */ 394 */
392 if (prio == DROPBEAR_PRIO_LOWDELAY) { 395 if (prio == DROPBEAR_PRIO_LOWDELAY) {
393 val = IPTOS_DSCP_AF21; 396 val = 0x48; /* IPTOS_DSCP_AF21 */
394 } else if (prio == DROPBEAR_PRIO_BULK) { 397 } else if (prio == DROPBEAR_PRIO_BULK) {
395 val = IPTOS_DSCP_AF11; 398 val = 0x28; /* IPTOS_DSCP_AF11; */
396 } else { 399 } else {
397 val = 0; /* default */ 400 val = 0; /* default */
398 } 401 }
399 #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) 402 #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)
400 rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val)); 403 rc = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, (void*)&val, sizeof(val));
404 #endif 407 #endif
405 rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val)); 408 rc = setsockopt(sock, IPPROTO_IP, IP_TOS, (void*)&val, sizeof(val));
406 if (rc < 0 && errno != ENOTSOCK) { 409 if (rc < 0 && errno != ENOTSOCK) {
407 TRACE(("Couldn't set IP_TOS (%s)", strerror(errno))); 410 TRACE(("Couldn't set IP_TOS (%s)", strerror(errno)));
408 } 411 }
409 #endif 412 #endif /* IP_TOS */
410 413
411 #ifdef HAVE_LINUX_PKT_SCHED_H 414 #ifdef HAVE_LINUX_PKT_SCHED_H
412 /* Set scheduling priority within the local Linux network stack */ 415 /* Set scheduling priority within the local Linux network stack */
413 if (prio == DROPBEAR_PRIO_LOWDELAY) { 416 if (prio == DROPBEAR_PRIO_LOWDELAY) {
414 val = TC_PRIO_INTERACTIVE; 417 val = TC_PRIO_INTERACTIVE;