View | Details | Raw Unified | Return to bug 2503
Collapse All | Expand All

(-)packet.c (-21 / +43 lines)
Lines 332-338 ssh_packet_stop_discard(struct ssh *ssh) Link Here
332
		    sshbuf_ptr(state->incoming_packet), PACKET_MAX_SIZE,
332
		    sshbuf_ptr(state->incoming_packet), PACKET_MAX_SIZE,
333
		    NULL, 0);
333
		    NULL, 0);
334
	}
334
	}
335
	logit("Finished discarding for %.200s", ssh_remote_ipaddr(ssh));
335
	logit("Finished discarding for %.200s port %d",
336
	    ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
336
	return SSH_ERR_MAC_INVALID;
337
	return SSH_ERR_MAC_INVALID;
337
}
338
}
338
339
Lines 444-459 ssh_packet_get_connection_out(struct ssh Link Here
444
const char *
445
const char *
445
ssh_remote_ipaddr(struct ssh *ssh)
446
ssh_remote_ipaddr(struct ssh *ssh)
446
{
447
{
448
	const int sock = ssh->state->connection_in;
449
447
	/* Check whether we have cached the ipaddr. */
450
	/* Check whether we have cached the ipaddr. */
448
	if (ssh->remote_ipaddr == NULL)
451
	if (ssh->remote_ipaddr == NULL) {
449
		ssh->remote_ipaddr = ssh_packet_connection_is_on_socket(ssh) ?
452
		if (ssh_packet_connection_is_on_socket(ssh)) {
450
		    get_peer_ipaddr(ssh->state->connection_in) :
453
			ssh->remote_ipaddr = get_peer_ipaddr(sock);
451
		    strdup("UNKNOWN");
454
			ssh->remote_port = get_sock_port(sock, 0);
452
	if (ssh->remote_ipaddr == NULL)
455
		} else {
453
		return "UNKNOWN";
456
			ssh->remote_ipaddr = strdup("UNKNOWN");
457
			ssh->remote_port = 0;
458
		}
459
	}
454
	return ssh->remote_ipaddr;
460
	return ssh->remote_ipaddr;
455
}
461
}
456
462
463
/* Returns the port number of the remote host. */
464
465
int
466
ssh_remote_port(struct ssh *ssh)
467
{
468
	(void)ssh_remote_ipaddr(ssh); /* Will lookup and cache. */
469
	return ssh->remote_port;
470
}
471
457
/* Closes the connection and clears and frees internal data structures. */
472
/* Closes the connection and clears and frees internal data structures. */
458
473
459
void
474
void
Lines 1784-1791 ssh_packet_read_poll_seqnr(struct ssh *s Link Here
1784
				do_log2(ssh->state->server_side &&
1799
				do_log2(ssh->state->server_side &&
1785
				    reason == SSH2_DISCONNECT_BY_APPLICATION ?
1800
				    reason == SSH2_DISCONNECT_BY_APPLICATION ?
1786
				    SYSLOG_LEVEL_INFO : SYSLOG_LEVEL_ERROR,
1801
				    SYSLOG_LEVEL_INFO : SYSLOG_LEVEL_ERROR,
1787
				    "Received disconnect from %s: %u: %.400s",
1802
				    "Received disconnect from %s port %d:"
1788
				    ssh_remote_ipaddr(ssh), reason, msg);
1803
				    "%u: %.400s", ssh_remote_ipaddr(ssh),
1804
				    ssh_remote_port(ssh), reason, msg);
1789
				free(msg);
1805
				free(msg);
1790
				return SSH_ERR_DISCONNECTED;
1806
				return SSH_ERR_DISCONNECTED;
1791
			case SSH2_MSG_UNIMPLEMENTED:
1807
			case SSH2_MSG_UNIMPLEMENTED:
Lines 1813-1820 ssh_packet_read_poll_seqnr(struct ssh *s Link Here
1813
			case SSH_MSG_DISCONNECT:
1829
			case SSH_MSG_DISCONNECT:
1814
				if ((r = sshpkt_get_string(ssh, &msg, NULL)) != 0)
1830
				if ((r = sshpkt_get_string(ssh, &msg, NULL)) != 0)
1815
					return r;
1831
					return r;
1816
				error("Received disconnect from %s: %.400s",
1832
				error("Received disconnect from %s port %d: "
1817
				    ssh_remote_ipaddr(ssh), msg);
1833
				    "%.400s", ssh_remote_ipaddr(ssh),
1834
				    ssh_remote_port(ssh), msg);
1818
				free(msg);
1835
				free(msg);
1819
				return SSH_ERR_DISCONNECTED;
1836
				return SSH_ERR_DISCONNECTED;
1820
			default:
1837
			default:
Lines 1904-1922 sshpkt_fatal(struct ssh *ssh, const char Link Here
1904
{
1921
{
1905
	switch (r) {
1922
	switch (r) {
1906
	case SSH_ERR_CONN_CLOSED:
1923
	case SSH_ERR_CONN_CLOSED:
1907
		logit("Connection closed by %.200s", ssh_remote_ipaddr(ssh));
1924
		logit("Connection closed by %.200s port %d",
1925
		    ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1908
		cleanup_exit(255);
1926
		cleanup_exit(255);
1909
	case SSH_ERR_CONN_TIMEOUT:
1927
	case SSH_ERR_CONN_TIMEOUT:
1910
		logit("Connection to %.200s timed out", ssh_remote_ipaddr(ssh));
1928
		logit("Connection %s %.200s port %d timed out",
1929
		    ssh->state->server_side ? "from" : "to",
1930
		    ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1911
		cleanup_exit(255);
1931
		cleanup_exit(255);
1912
	case SSH_ERR_DISCONNECTED:
1932
	case SSH_ERR_DISCONNECTED:
1913
		logit("Disconnected from %.200s",
1933
		logit("Disconnected from %.200s port %d",
1914
		    ssh_remote_ipaddr(ssh));
1934
		    ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1915
		cleanup_exit(255);
1935
		cleanup_exit(255);
1916
	case SSH_ERR_SYSTEM_ERROR:
1936
	case SSH_ERR_SYSTEM_ERROR:
1917
		if (errno == ECONNRESET) {
1937
		if (errno == ECONNRESET) {
1918
			logit("Connection reset by %.200s",
1938
			logit("Connection reset by %.200s port %d",
1919
			    ssh_remote_ipaddr(ssh));
1939
			    ssh_remote_ipaddr(ssh), ssh_remote_port(ssh));
1920
			cleanup_exit(255);
1940
			cleanup_exit(255);
1921
		}
1941
		}
1922
		/* FALLTHROUGH */
1942
		/* FALLTHROUGH */
Lines 1926-1940 sshpkt_fatal(struct ssh *ssh, const char Link Here
1926
	case SSH_ERR_NO_KEX_ALG_MATCH:
1946
	case SSH_ERR_NO_KEX_ALG_MATCH:
1927
	case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
1947
	case SSH_ERR_NO_HOSTKEY_ALG_MATCH:
1928
		if (ssh && ssh->kex && ssh->kex->failed_choice) {
1948
		if (ssh && ssh->kex && ssh->kex->failed_choice) {
1929
			fatal("Unable to negotiate with %.200s: %s. "
1949
			fatal("Unable to negotiate with %.200s port %d: %s. "
1930
			    "Their offer: %s", ssh_remote_ipaddr(ssh),
1950
			    "Their offer: %s", ssh_remote_ipaddr(ssh),
1931
			    ssh_err(r), ssh->kex->failed_choice);
1951
			    ssh_remote_port(ssh), ssh_err(r),
1952
			    ssh->kex->failed_choice);
1932
		}
1953
		}
1933
		/* FALLTHROUGH */
1954
		/* FALLTHROUGH */
1934
	default:
1955
	default:
1935
		fatal("%s%sConnection to %.200s: %s",
1956
		fatal("%s%sConnection %s %.200s port %d: %s",
1936
		    tag != NULL ? tag : "", tag != NULL ? ": " : "",
1957
		    tag != NULL ? tag : "", tag != NULL ? ": " : "",
1937
		    ssh_remote_ipaddr(ssh), ssh_err(r));
1958
		    ssh->state->server_side ? "from" : "to",
1959
		    ssh_remote_ipaddr(ssh), ssh_remote_port(ssh), ssh_err(r));
1938
	}
1960
	}
1939
}
1961
}
1940
1962
(-)packet.h (+1 lines)
Lines 129-134 int ssh_packet_get_state(struct ssh *, Link Here
129
int	 ssh_packet_set_state(struct ssh *, struct sshbuf *);
129
int	 ssh_packet_set_state(struct ssh *, struct sshbuf *);
130
130
131
const char *ssh_remote_ipaddr(struct ssh *);
131
const char *ssh_remote_ipaddr(struct ssh *);
132
int	 ssh_remote_port(struct ssh *);
132
133
133
int	 ssh_packet_need_rekeying(struct ssh *);
134
int	 ssh_packet_need_rekeying(struct ssh *);
134
void	 ssh_packet_set_rekey_limits(struct ssh *, u_int32_t, time_t);
135
void	 ssh_packet_set_rekey_limits(struct ssh *, u_int32_t, time_t);

Return to bug 2503