diff options
author | djm@openbsd.org <djm@openbsd.org> | 2020-11-27 00:49:58 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2020-11-27 13:21:16 +1100 |
commit | 33313ebc1c7135085676db62189e3520341d6b73 (patch) | |
tree | 0ae54394e89d6b928fd9b4df57a96f92583c8b0d /misc.c | |
parent | b2bcec13f17ce9174238a704e91d52203e916432 (diff) | |
download | openssh-git-33313ebc1c7135085676db62189e3520341d6b73.tar.gz |
upstream: Set the specified TOS/DSCP for interactive use prior to
TCP connect. The connection phase of the SSH session is time-sensitive (due
to server side login grace periods) and is frequently interactive (e.g.
entering passwords). The ultimate interactive/bulk TOS/DSCP will be set after
authentication completes.
ok dtucker@
OpenBSD-Commit-ID: f31ab10d9233363a6d2c9996007083ba43a093f1
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 56 |
1 files changed, 55 insertions, 1 deletions
@@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.155 2020/10/18 11:32:01 djm Exp $ */ +/* $OpenBSD: misc.c,v 1.156 2020/11/27 00:49:58 djm Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * Copyright (c) 2005-2020 Damien Miller. All rights reserved. @@ -231,6 +231,60 @@ set_rdomain(int fd, const char *name) #endif } +int +get_sock_af(int fd) +{ + struct sockaddr_storage to; + socklen_t tolen = sizeof(to); + + memset(&to, 0, sizeof(to)); + if (getsockname(fd, (struct sockaddr *)&to, &tolen) == -1) + return -1; +#ifdef IPV4_IN_IPV6 + if (to.ss_family == AF_INET6 && + IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&to)->sin6_addr)) + return AF_INET; +#endif + return to.ss_family; +} + +void +set_sock_tos(int fd, int tos) +{ +#ifndef IP_TOS_IS_BROKEN + int af; + + switch ((af = get_sock_af(fd))) { + case -1: + /* assume not a socket */ + break; + case AF_INET: +# ifdef IP_TOS + debug3_f("set socket %d IP_TOS 0x%02x", fd, tos); + if (setsockopt(fd, IPPROTO_IP, IP_TOS, + &tos, sizeof(tos)) == -1) { + error("setsockopt socket %d IP_TOS %d: %s:", + fd, tos, strerror(errno)); + } +# endif /* IP_TOS */ + break; + case AF_INET6: +# ifdef IPV6_TCLASS + debug3_f("set socket %d IPV6_TCLASS 0x%02x", fd, tos); + if (setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, + &tos, sizeof(tos)) == -1) { + error("setsockopt socket %d IPV6_TCLASS %d: %.100s:", + fd, tos, strerror(errno)); + } +# endif /* IPV6_TCLASS */ + break; + default: + debug2_f("unsupported socket family %d", af); + break; + } +#endif /* IP_TOS_IS_BROKEN */ +} + /* * Wait up to *timeoutp milliseconds for events on fd. Updates * *timeoutp with time remaining. |