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
This commit is contained in:
djm@openbsd.org 2015-12-11 03:24:25 +00:00 committed by Damien Miller
parent 6091c362e8
commit a4b9e0f4e4
2 changed files with 46 additions and 23 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: packet.c,v 1.219 2015/12/10 17:08:40 mmcc Exp $ */ /* $OpenBSD: packet.c,v 1.220 2015/12/11 03:24:25 djm Exp $ */
/* /*
* Author: Tatu Ylonen <ylo@cs.hut.fi> * Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@ -338,7 +338,8 @@ ssh_packet_stop_discard(struct ssh *ssh)
sshbuf_ptr(state->incoming_packet), PACKET_MAX_SIZE, sshbuf_ptr(state->incoming_packet), PACKET_MAX_SIZE,
NULL, 0); NULL, 0);
} }
logit("Finished discarding for %.200s", ssh_remote_ipaddr(ssh)); logit("Finished discarding for %.200s port %d",
ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
return SSH_ERR_MAC_INVALID; return SSH_ERR_MAC_INVALID;
} }
@ -455,16 +456,30 @@ ssh_packet_get_connection_out(struct ssh *ssh)
const char * const char *
ssh_remote_ipaddr(struct ssh *ssh) ssh_remote_ipaddr(struct ssh *ssh)
{ {
const int sock = ssh->state->connection_in;
/* Check whether we have cached the ipaddr. */ /* Check whether we have cached the ipaddr. */
if (ssh->remote_ipaddr == NULL) if (ssh->remote_ipaddr == NULL) {
ssh->remote_ipaddr = ssh_packet_connection_is_on_socket(ssh) ? if (ssh_packet_connection_is_on_socket(ssh)) {
get_peer_ipaddr(ssh->state->connection_in) : ssh->remote_ipaddr = get_peer_ipaddr(sock);
strdup("UNKNOWN"); ssh->remote_port = get_sock_port(sock, 0);
if (ssh->remote_ipaddr == NULL) } else {
return "UNKNOWN"; ssh->remote_ipaddr = strdup("UNKNOWN");
ssh->remote_port = 0;
}
}
return ssh->remote_ipaddr; return ssh->remote_ipaddr;
} }
/* Returns the port number of the remote host. */
int
ssh_remote_port(struct ssh *ssh)
{
(void)ssh_remote_ipaddr(ssh); /* Will lookup and cache. */
return ssh->remote_port;
}
/* Closes the connection and clears and frees internal data structures. */ /* Closes the connection and clears and frees internal data structures. */
void void
@ -1796,8 +1811,9 @@ ssh_packet_read_poll_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
do_log2(ssh->state->server_side && do_log2(ssh->state->server_side &&
reason == SSH2_DISCONNECT_BY_APPLICATION ? reason == SSH2_DISCONNECT_BY_APPLICATION ?
SYSLOG_LEVEL_INFO : SYSLOG_LEVEL_ERROR, SYSLOG_LEVEL_INFO : SYSLOG_LEVEL_ERROR,
"Received disconnect from %s: %u: %.400s", "Received disconnect from %s port %d:"
ssh_remote_ipaddr(ssh), reason, msg); "%u: %.400s", ssh_remote_ipaddr(ssh),
ssh_remote_port(ssh), reason, msg);
free(msg); free(msg);
return SSH_ERR_DISCONNECTED; return SSH_ERR_DISCONNECTED;
case SSH2_MSG_UNIMPLEMENTED: case SSH2_MSG_UNIMPLEMENTED:
@ -1825,8 +1841,9 @@ ssh_packet_read_poll_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
case SSH_MSG_DISCONNECT: case SSH_MSG_DISCONNECT:
if ((r = sshpkt_get_string(ssh, &msg, NULL)) != 0) if ((r = sshpkt_get_string(ssh, &msg, NULL)) != 0)
return r; return r;
error("Received disconnect from %s: %.400s", error("Received disconnect from %s port %d: "
ssh_remote_ipaddr(ssh), msg); "%.400s", ssh_remote_ipaddr(ssh),
ssh_remote_port(ssh), msg);
free(msg); free(msg);
return SSH_ERR_DISCONNECTED; return SSH_ERR_DISCONNECTED;
default: default:
@ -1916,19 +1933,22 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
{ {
switch (r) { switch (r) {
case SSH_ERR_CONN_CLOSED: case SSH_ERR_CONN_CLOSED:
logit("Connection closed by %.200s", ssh_remote_ipaddr(ssh)); logit("Connection closed by %.200s port %d",
ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
cleanup_exit(255); cleanup_exit(255);
case SSH_ERR_CONN_TIMEOUT: case SSH_ERR_CONN_TIMEOUT:
logit("Connection to %.200s timed out", ssh_remote_ipaddr(ssh)); logit("Connection %s %.200s port %d timed out",
ssh->state->server_side ? "from" : "to",
ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
cleanup_exit(255); cleanup_exit(255);
case SSH_ERR_DISCONNECTED: case SSH_ERR_DISCONNECTED:
logit("Disconnected from %.200s", logit("Disconnected from %.200s port %d",
ssh_remote_ipaddr(ssh)); ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
cleanup_exit(255); cleanup_exit(255);
case SSH_ERR_SYSTEM_ERROR: case SSH_ERR_SYSTEM_ERROR:
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
logit("Connection reset by %.200s", logit("Connection reset by %.200s port %d",
ssh_remote_ipaddr(ssh)); ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
cleanup_exit(255); cleanup_exit(255);
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
@ -1938,15 +1958,17 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
case SSH_ERR_NO_KEX_ALG_MATCH: case SSH_ERR_NO_KEX_ALG_MATCH:
case SSH_ERR_NO_HOSTKEY_ALG_MATCH: case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
if (ssh && ssh->kex && ssh->kex->failed_choice) { if (ssh && ssh->kex && ssh->kex->failed_choice) {
fatal("Unable to negotiate with %.200s: %s. " fatal("Unable to negotiate with %.200s port %d: %s. "
"Their offer: %s", ssh_remote_ipaddr(ssh), "Their offer: %s", ssh_remote_ipaddr(ssh),
ssh_err(r), ssh->kex->failed_choice); ssh_remote_port(ssh), ssh_err(r),
ssh->kex->failed_choice);
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
fatal("%s%sConnection to %.200s: %s", fatal("%s%sConnection %s %.200s port %d: %s",
tag != NULL ? tag : "", tag != NULL ? ": " : "", tag != NULL ? tag : "", tag != NULL ? ": " : "",
ssh_remote_ipaddr(ssh), ssh_err(r)); ssh->state->server_side ? "from" : "to",
ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), ssh_err(r));
} }
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: packet.h,v 1.66 2015/01/30 01:13:33 djm Exp $ */ /* $OpenBSD: packet.h,v 1.67 2015/12/11 03:24:25 djm Exp $ */
/* /*
* Author: Tatu Ylonen <ylo@cs.hut.fi> * Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -143,6 +143,7 @@ int ssh_packet_get_state(struct ssh *, struct sshbuf *);
int ssh_packet_set_state(struct ssh *, struct sshbuf *); int ssh_packet_set_state(struct ssh *, struct sshbuf *);
const char *ssh_remote_ipaddr(struct ssh *); const char *ssh_remote_ipaddr(struct ssh *);
int ssh_remote_port(struct ssh *);
int ssh_packet_need_rekeying(struct ssh *); int ssh_packet_need_rekeying(struct ssh *);
void ssh_packet_set_rekey_limits(struct ssh *, u_int32_t, time_t); void ssh_packet_set_rekey_limits(struct ssh *, u_int32_t, time_t);