summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2015-12-11 03:24:25 +0000
committerDamien Miller <djm@mindrot.org>2015-12-18 14:50:10 +1100
commita4b9e0f4e4a6980a0eb8072f76ea611cab5b77e7 (patch)
tree7397fdf323565afa9a832b389334359eeccdf9e7
parent6091c362e89079397e68744ae30df121b0a72c07 (diff)
upstream commit
include remote port number in a few more messages; makes tying log messages together into a session a bit easier; bz#2503 ok dtucker@ Upstream-ID: 9300dc354015f7a7368d94a8ff4a4266a69d237e
-rw-r--r--packet.c66
-rw-r--r--packet.h3
2 files changed, 46 insertions, 23 deletions
diff --git a/packet.c b/packet.c
index 06e16536c..8d9bcd8db 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.c,v 1.219 2015/12/10 17:08:40 mmcc Exp $ */ 1/* $OpenBSD: packet.c,v 1.220 2015/12/11 03:24:25 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
@@ -338,7 +338,8 @@ ssh_packet_stop_discard(struct ssh *ssh)
338 sshbuf_ptr(state->incoming_packet), PACKET_MAX_SIZE, 338 sshbuf_ptr(state->incoming_packet), PACKET_MAX_SIZE,
339 NULL, 0); 339 NULL, 0);
340 } 340 }
341 logit("Finished discarding for %.200s", ssh_remote_ipaddr(ssh)); 341 logit("Finished discarding for %.200s port %d",
342 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
342 return SSH_ERR_MAC_INVALID; 343 return SSH_ERR_MAC_INVALID;
343} 344}
344 345
@@ -455,16 +456,30 @@ ssh_packet_get_connection_out(struct ssh *ssh)
455const char * 456const char *
456ssh_remote_ipaddr(struct ssh *ssh) 457ssh_remote_ipaddr(struct ssh *ssh)
457{ 458{
459 const int sock = ssh->state->connection_in;
460
458 /* Check whether we have cached the ipaddr. */ 461 /* Check whether we have cached the ipaddr. */
459 if (ssh->remote_ipaddr == NULL) 462 if (ssh->remote_ipaddr == NULL) {
460 ssh->remote_ipaddr = ssh_packet_connection_is_on_socket(ssh) ? 463 if (ssh_packet_connection_is_on_socket(ssh)) {
461 get_peer_ipaddr(ssh->state->connection_in) : 464 ssh->remote_ipaddr = get_peer_ipaddr(sock);
462 strdup("UNKNOWN"); 465 ssh->remote_port = get_sock_port(sock, 0);
463 if (ssh->remote_ipaddr == NULL) 466 } else {
464 return "UNKNOWN"; 467 ssh->remote_ipaddr = strdup("UNKNOWN");
468 ssh->remote_port = 0;
469 }
470 }
465 return ssh->remote_ipaddr; 471 return ssh->remote_ipaddr;
466} 472}
467 473
474/* Returns the port number of the remote host. */
475
476int
477ssh_remote_port(struct ssh *ssh)
478{
479 (void)ssh_remote_ipaddr(ssh); /* Will lookup and cache. */
480 return ssh->remote_port;
481}
482
468/* Closes the connection and clears and frees internal data structures. */ 483/* Closes the connection and clears and frees internal data structures. */
469 484
470void 485void
@@ -1796,8 +1811,9 @@ ssh_packet_read_poll_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
1796 do_log2(ssh->state->server_side && 1811 do_log2(ssh->state->server_side &&
1797 reason == SSH2_DISCONNECT_BY_APPLICATION ? 1812 reason == SSH2_DISCONNECT_BY_APPLICATION ?
1798 SYSLOG_LEVEL_INFO : SYSLOG_LEVEL_ERROR, 1813 SYSLOG_LEVEL_INFO : SYSLOG_LEVEL_ERROR,
1799 "Received disconnect from %s: %u: %.400s", 1814 "Received disconnect from %s port %d:"
1800 ssh_remote_ipaddr(ssh), reason, msg); 1815 "%u: %.400s", ssh_remote_ipaddr(ssh),
1816 ssh_remote_port(ssh), reason, msg);
1801 free(msg); 1817 free(msg);
1802 return SSH_ERR_DISCONNECTED; 1818 return SSH_ERR_DISCONNECTED;
1803 case SSH2_MSG_UNIMPLEMENTED: 1819 case SSH2_MSG_UNIMPLEMENTED:
@@ -1825,8 +1841,9 @@ ssh_packet_read_poll_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
1825 case SSH_MSG_DISCONNECT: 1841 case SSH_MSG_DISCONNECT:
1826 if ((r = sshpkt_get_string(ssh, &msg, NULL)) != 0) 1842 if ((r = sshpkt_get_string(ssh, &msg, NULL)) != 0)
1827 return r; 1843 return r;
1828 error("Received disconnect from %s: %.400s", 1844 error("Received disconnect from %s port %d: "
1829 ssh_remote_ipaddr(ssh), msg); 1845 "%.400s", ssh_remote_ipaddr(ssh),
1846 ssh_remote_port(ssh), msg);
1830 free(msg); 1847 free(msg);
1831 return SSH_ERR_DISCONNECTED; 1848 return SSH_ERR_DISCONNECTED;
1832 default: 1849 default:
@@ -1916,19 +1933,22 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
1916{ 1933{
1917 switch (r) { 1934 switch (r) {
1918 case SSH_ERR_CONN_CLOSED: 1935 case SSH_ERR_CONN_CLOSED:
1919 logit("Connection closed by %.200s", ssh_remote_ipaddr(ssh)); 1936 logit("Connection closed by %.200s port %d",
1937 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1920 cleanup_exit(255); 1938 cleanup_exit(255);
1921 case SSH_ERR_CONN_TIMEOUT: 1939 case SSH_ERR_CONN_TIMEOUT:
1922 logit("Connection to %.200s timed out", ssh_remote_ipaddr(ssh)); 1940 logit("Connection %s %.200s port %d timed out",
1941 ssh->state->server_side ? "from" : "to",
1942 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1923 cleanup_exit(255); 1943 cleanup_exit(255);
1924 case SSH_ERR_DISCONNECTED: 1944 case SSH_ERR_DISCONNECTED:
1925 logit("Disconnected from %.200s", 1945 logit("Disconnected from %.200s port %d",
1926 ssh_remote_ipaddr(ssh)); 1946 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1927 cleanup_exit(255); 1947 cleanup_exit(255);
1928 case SSH_ERR_SYSTEM_ERROR: 1948 case SSH_ERR_SYSTEM_ERROR:
1929 if (errno == ECONNRESET) { 1949 if (errno == ECONNRESET) {
1930 logit("Connection reset by %.200s", 1950 logit("Connection reset by %.200s port %d",
1931 ssh_remote_ipaddr(ssh)); 1951 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1932 cleanup_exit(255); 1952 cleanup_exit(255);
1933 } 1953 }
1934 /* FALLTHROUGH */ 1954 /* FALLTHROUGH */
@@ -1938,15 +1958,17 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
1938 case SSH_ERR_NO_KEX_ALG_MATCH: 1958 case SSH_ERR_NO_KEX_ALG_MATCH:
1939 case SSH_ERR_NO_HOSTKEY_ALG_MATCH: 1959 case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
1940 if (ssh && ssh->kex && ssh->kex->failed_choice) { 1960 if (ssh && ssh->kex && ssh->kex->failed_choice) {
1941 fatal("Unable to negotiate with %.200s: %s. " 1961 fatal("Unable to negotiate with %.200s port %d: %s. "
1942 "Their offer: %s", ssh_remote_ipaddr(ssh), 1962 "Their offer: %s", ssh_remote_ipaddr(ssh),
1943 ssh_err(r), ssh->kex->failed_choice); 1963 ssh_remote_port(ssh), ssh_err(r),
1964 ssh->kex->failed_choice);
1944 } 1965 }
1945 /* FALLTHROUGH */ 1966 /* FALLTHROUGH */
1946 default: 1967 default:
1947 fatal("%s%sConnection to %.200s: %s", 1968 fatal("%s%sConnection %s %.200s port %d: %s",
1948 tag != NULL ? tag : "", tag != NULL ? ": " : "", 1969 tag != NULL ? tag : "", tag != NULL ? ": " : "",
1949 ssh_remote_ipaddr(ssh), ssh_err(r)); 1970 ssh->state->server_side ? "from" : "to",
1971 ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), ssh_err(r));
1950 } 1972 }
1951} 1973}
1952 1974
diff --git a/packet.h b/packet.h
index 7b06544e8..bc2e2ba2e 100644
--- a/packet.h
+++ b/packet.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.h,v 1.66 2015/01/30 01:13:33 djm Exp $ */ 1/* $OpenBSD: packet.h,v 1.67 2015/12/11 03:24:25 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -143,6 +143,7 @@ int ssh_packet_get_state(struct ssh *, struct sshbuf *);
143int ssh_packet_set_state(struct ssh *, struct sshbuf *); 143int ssh_packet_set_state(struct ssh *, struct sshbuf *);
144 144
145const char *ssh_remote_ipaddr(struct ssh *); 145const char *ssh_remote_ipaddr(struct ssh *);
146int ssh_remote_port(struct ssh *);
146 147
147int ssh_packet_need_rekeying(struct ssh *); 148int ssh_packet_need_rekeying(struct ssh *);
148void ssh_packet_set_rekey_limits(struct ssh *, u_int32_t, time_t); 149void ssh_packet_set_rekey_limits(struct ssh *, u_int32_t, time_t);