diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2020-11-27 00:49:59 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2020-11-27 00:49:59 +0000 |
commit | 06cbef289c5424653efc66cedbcef7545f3770a1 (patch) | |
tree | f847f4b55fb2f58974ca18af5110b790ea46374f /usr.bin | |
parent | 2ec23c229de86129ec3f2743ddc6adcd92a80c66 (diff) |
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@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ssh/misc.c | 45 | ||||
-rw-r--r-- | usr.bin/ssh/misc.h | 4 | ||||
-rw-r--r-- | usr.bin/ssh/packet.c | 31 | ||||
-rw-r--r-- | usr.bin/ssh/sshconnect.c | 7 |
4 files changed, 57 insertions, 30 deletions
diff --git a/usr.bin/ssh/misc.c b/usr.bin/ssh/misc.c index 59006e54173..f73239ce180 100644 --- a/usr.bin/ssh/misc.c +++ b/usr.bin/ssh/misc.c @@ -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. @@ -204,6 +204,49 @@ set_rdomain(int fd, const char *name) return 0; } +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; + return to.ss_family; +} + +void +set_sock_tos(int fd, int tos) +{ + int af; + + switch ((af = get_sock_af(fd))) { + case -1: + /* assume not a socket */ + break; + case AF_INET: + 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)); + } + break; + case AF_INET6: + 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)); + } + break; + default: + debug2_f("unsupported socket family %d", af); + break; + } +} + /* * Wait up to *timeoutp milliseconds for events on fd. Updates * *timeoutp with time remaining. diff --git a/usr.bin/ssh/misc.h b/usr.bin/ssh/misc.h index e259dd49dea..b5d7cc57272 100644 --- a/usr.bin/ssh/misc.h +++ b/usr.bin/ssh/misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.h,v 1.89 2020/11/08 22:37:24 djm Exp $ */ +/* $OpenBSD: misc.h,v 1.90 2020/11/27 00:49:58 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> @@ -53,6 +53,8 @@ void set_nodelay(int); int set_reuseaddr(int); char *get_rdomain(int); int set_rdomain(int, const char *); +int get_sock_af(int); +void set_sock_tos(int, int); int waitrfd(int, int *); int timeout_connect(int, const struct sockaddr *, socklen_t, int *); int a2port(const char *); diff --git a/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c index 1f03beab60b..2e96b0c30d8 100644 --- a/usr.bin/ssh/packet.c +++ b/usr.bin/ssh/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.297 2020/10/18 11:32:01 djm Exp $ */ +/* $OpenBSD: packet.c,v 1.298 2020/11/27 00:49:58 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -455,14 +455,7 @@ ssh_packet_get_bytes(struct ssh *ssh, u_int64_t *ibytes, u_int64_t *obytes) int ssh_packet_connection_af(struct ssh *ssh) { - struct sockaddr_storage to; - socklen_t tolen = sizeof(to); - - memset(&to, 0, sizeof(to)); - if (getsockname(ssh->state->connection_out, (struct sockaddr *)&to, - &tolen) == -1) - return 0; - return to.ss_family; + return get_sock_af(ssh->state->connection_out); } /* Sets the connection into non-blocking mode. */ @@ -2043,22 +2036,7 @@ ssh_packet_set_tos(struct ssh *ssh, int tos) { if (!ssh_packet_connection_is_on_socket(ssh) || tos == INT_MAX) return; - switch (ssh_packet_connection_af(ssh)) { - case AF_INET: - debug3_f("set IP_TOS 0x%02x", tos); - if (setsockopt(ssh->state->connection_in, - IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1) - error("setsockopt IP_TOS %d: %.100s:", - tos, strerror(errno)); - break; - case AF_INET6: - debug3_f("set IPV6_TCLASS 0x%02x", tos); - if (setsockopt(ssh->state->connection_in, - IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof(tos)) == -1) - error("setsockopt IPV6_TCLASS %d: %.100s:", - tos, strerror(errno)); - break; - } + set_sock_tos(ssh->state->connection_in, tos); } /* Informs that the current session is interactive. Sets IP flags for that. */ @@ -2079,8 +2057,7 @@ ssh_packet_set_interactive(struct ssh *ssh, int interactive, int qos_interactive if (!ssh_packet_connection_is_on_socket(ssh)) return; set_nodelay(state->connection_in); - ssh_packet_set_tos(ssh, interactive ? qos_interactive : - qos_bulk); + ssh_packet_set_tos(ssh, interactive ? qos_interactive : qos_bulk); } /* Returns true if the current connection is interactive. */ diff --git a/usr.bin/ssh/sshconnect.c b/usr.bin/ssh/sshconnect.c index 7eb23deb22c..f07d342a925 100644 --- a/usr.bin/ssh/sshconnect.c +++ b/usr.bin/ssh/sshconnect.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sshconnect.c,v 1.344 2020/11/22 22:37:11 djm Exp $ */ +/* $OpenBSD: sshconnect.c,v 1.345 2020/11/27 00:49:58 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -26,6 +26,7 @@ #include <errno.h> #include <fcntl.h> #include <netdb.h> +#include <limits.h> #include <paths.h> #include <signal.h> #include <pwd.h> @@ -347,6 +348,10 @@ ssh_create_socket(struct addrinfo *ai) } fcntl(sock, F_SETFD, FD_CLOEXEC); + /* Use interactive QOS (if specified) until authentication completed */ + if (options.ip_qos_interactive != INT_MAX) + set_sock_tos(sock, options.ip_qos_interactive); + /* Bind the socket to an alternative local IP address */ if (options.bind_address == NULL && options.bind_interface == NULL) return sock; |