diff options
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: packet.c,v 1.264 2017/09/12 06:32:07 djm Exp $ */ | 1 | /* $OpenBSD: packet.c,v 1.269 2017/12/18 23:13:42 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -557,6 +557,18 @@ ssh_local_port(struct ssh *ssh) | |||
557 | return ssh->local_port; | 557 | return ssh->local_port; |
558 | } | 558 | } |
559 | 559 | ||
560 | /* Returns the routing domain of the input socket, or NULL if unavailable */ | ||
561 | const char * | ||
562 | ssh_packet_rdomain_in(struct ssh *ssh) | ||
563 | { | ||
564 | if (ssh->rdomain_in != NULL) | ||
565 | return ssh->rdomain_in; | ||
566 | if (!ssh_packet_connection_is_on_socket(ssh)) | ||
567 | return NULL; | ||
568 | ssh->rdomain_in = get_rdomain(ssh->state->connection_in); | ||
569 | return ssh->rdomain_in; | ||
570 | } | ||
571 | |||
560 | /* Closes the connection and clears and frees internal data structures. */ | 572 | /* Closes the connection and clears and frees internal data structures. */ |
561 | 573 | ||
562 | static void | 574 | static void |
@@ -1320,7 +1332,7 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p) | |||
1320 | for (;;) { | 1332 | for (;;) { |
1321 | if (state->packet_timeout_ms != -1) { | 1333 | if (state->packet_timeout_ms != -1) { |
1322 | ms_to_timeval(&timeout, ms_remain); | 1334 | ms_to_timeval(&timeout, ms_remain); |
1323 | gettimeofday(&start, NULL); | 1335 | monotime_tv(&start); |
1324 | } | 1336 | } |
1325 | if ((r = select(state->connection_in + 1, setp, | 1337 | if ((r = select(state->connection_in + 1, setp, |
1326 | NULL, NULL, timeoutp)) >= 0) | 1338 | NULL, NULL, timeoutp)) >= 0) |
@@ -1774,6 +1786,8 @@ ssh_packet_send_debug(struct ssh *ssh, const char *fmt,...) | |||
1774 | vsnprintf(buf, sizeof(buf), fmt, args); | 1786 | vsnprintf(buf, sizeof(buf), fmt, args); |
1775 | va_end(args); | 1787 | va_end(args); |
1776 | 1788 | ||
1789 | debug3("sending debug message: %s", buf); | ||
1790 | |||
1777 | if ((r = sshpkt_start(ssh, SSH2_MSG_DEBUG)) != 0 || | 1791 | if ((r = sshpkt_start(ssh, SSH2_MSG_DEBUG)) != 0 || |
1778 | (r = sshpkt_put_u8(ssh, 0)) != 0 || /* always display */ | 1792 | (r = sshpkt_put_u8(ssh, 0)) != 0 || /* always display */ |
1779 | (r = sshpkt_put_cstring(ssh, buf)) != 0 || | 1793 | (r = sshpkt_put_cstring(ssh, buf)) != 0 || |
@@ -1783,8 +1797,8 @@ ssh_packet_send_debug(struct ssh *ssh, const char *fmt,...) | |||
1783 | fatal("%s: %s", __func__, ssh_err(r)); | 1797 | fatal("%s: %s", __func__, ssh_err(r)); |
1784 | } | 1798 | } |
1785 | 1799 | ||
1786 | static void | 1800 | void |
1787 | fmt_connection_id(struct ssh *ssh, char *s, size_t l) | 1801 | sshpkt_fmt_connection_id(struct ssh *ssh, char *s, size_t l) |
1788 | { | 1802 | { |
1789 | snprintf(s, l, "%.200s%s%s port %d", | 1803 | snprintf(s, l, "%.200s%s%s port %d", |
1790 | ssh->log_preamble ? ssh->log_preamble : "", | 1804 | ssh->log_preamble ? ssh->log_preamble : "", |
@@ -1800,7 +1814,7 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r) | |||
1800 | { | 1814 | { |
1801 | char remote_id[512]; | 1815 | char remote_id[512]; |
1802 | 1816 | ||
1803 | fmt_connection_id(ssh, remote_id, sizeof(remote_id)); | 1817 | sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id)); |
1804 | 1818 | ||
1805 | switch (r) { | 1819 | switch (r) { |
1806 | case SSH_ERR_CONN_CLOSED: | 1820 | case SSH_ERR_CONN_CLOSED: |
@@ -1862,7 +1876,7 @@ ssh_packet_disconnect(struct ssh *ssh, const char *fmt,...) | |||
1862 | * Format the message. Note that the caller must make sure the | 1876 | * Format the message. Note that the caller must make sure the |
1863 | * message is of limited size. | 1877 | * message is of limited size. |
1864 | */ | 1878 | */ |
1865 | fmt_connection_id(ssh, remote_id, sizeof(remote_id)); | 1879 | sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id)); |
1866 | va_start(args, fmt); | 1880 | va_start(args, fmt); |
1867 | vsnprintf(buf, sizeof(buf), fmt, args); | 1881 | vsnprintf(buf, sizeof(buf), fmt, args); |
1868 | va_end(args); | 1882 | va_end(args); |
@@ -1945,7 +1959,7 @@ ssh_packet_write_wait(struct ssh *ssh) | |||
1945 | for (;;) { | 1959 | for (;;) { |
1946 | if (state->packet_timeout_ms != -1) { | 1960 | if (state->packet_timeout_ms != -1) { |
1947 | ms_to_timeval(&timeout, ms_remain); | 1961 | ms_to_timeval(&timeout, ms_remain); |
1948 | gettimeofday(&start, NULL); | 1962 | monotime_tv(&start); |
1949 | } | 1963 | } |
1950 | if ((ret = select(state->connection_out + 1, | 1964 | if ((ret = select(state->connection_out + 1, |
1951 | NULL, setp, NULL, timeoutp)) >= 0) | 1965 | NULL, setp, NULL, timeoutp)) >= 0) |
@@ -2159,7 +2173,9 @@ kex_to_blob(struct sshbuf *m, struct kex *kex) | |||
2159 | if ((r = sshbuf_put_string(m, kex->session_id, | 2173 | if ((r = sshbuf_put_string(m, kex->session_id, |
2160 | kex->session_id_len)) != 0 || | 2174 | kex->session_id_len)) != 0 || |
2161 | (r = sshbuf_put_u32(m, kex->we_need)) != 0 || | 2175 | (r = sshbuf_put_u32(m, kex->we_need)) != 0 || |
2176 | (r = sshbuf_put_cstring(m, kex->hostkey_alg)) != 0 || | ||
2162 | (r = sshbuf_put_u32(m, kex->hostkey_type)) != 0 || | 2177 | (r = sshbuf_put_u32(m, kex->hostkey_type)) != 0 || |
2178 | (r = sshbuf_put_u32(m, kex->hostkey_nid)) != 0 || | ||
2163 | (r = sshbuf_put_u32(m, kex->kex_type)) != 0 || | 2179 | (r = sshbuf_put_u32(m, kex->kex_type)) != 0 || |
2164 | (r = sshbuf_put_stringb(m, kex->my)) != 0 || | 2180 | (r = sshbuf_put_stringb(m, kex->my)) != 0 || |
2165 | (r = sshbuf_put_stringb(m, kex->peer)) != 0 || | 2181 | (r = sshbuf_put_stringb(m, kex->peer)) != 0 || |
@@ -2323,7 +2339,9 @@ kex_from_blob(struct sshbuf *m, struct kex **kexp) | |||
2323 | } | 2339 | } |
2324 | if ((r = sshbuf_get_string(m, &kex->session_id, &kex->session_id_len)) != 0 || | 2340 | if ((r = sshbuf_get_string(m, &kex->session_id, &kex->session_id_len)) != 0 || |
2325 | (r = sshbuf_get_u32(m, &kex->we_need)) != 0 || | 2341 | (r = sshbuf_get_u32(m, &kex->we_need)) != 0 || |
2342 | (r = sshbuf_get_cstring(m, &kex->hostkey_alg, NULL)) != 0 || | ||
2326 | (r = sshbuf_get_u32(m, (u_int *)&kex->hostkey_type)) != 0 || | 2343 | (r = sshbuf_get_u32(m, (u_int *)&kex->hostkey_type)) != 0 || |
2344 | (r = sshbuf_get_u32(m, (u_int *)&kex->hostkey_nid)) != 0 || | ||
2327 | (r = sshbuf_get_u32(m, &kex->kex_type)) != 0 || | 2345 | (r = sshbuf_get_u32(m, &kex->kex_type)) != 0 || |
2328 | (r = sshbuf_get_stringb(m, kex->my)) != 0 || | 2346 | (r = sshbuf_get_stringb(m, kex->my)) != 0 || |
2329 | (r = sshbuf_get_stringb(m, kex->peer)) != 0 || | 2347 | (r = sshbuf_get_stringb(m, kex->peer)) != 0 || |