diff options
author | David Goulet <dgoulet@torproject.org> | 2022-11-03 13:05:21 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2022-11-03 13:05:21 -0400 |
commit | 6196e9596a3a10d5b8d2d6574635306d48092388 (patch) | |
tree | e75f94d366ba5be04828ff2bba6d82e3a2343dbe /src/feature/stats | |
parent | 619dd35321c13684d5496b660a3404d2d3fe2827 (diff) | |
download | tor-6196e9596a3a10d5b8d2d6574635306d48092388.tar.gz tor-6196e9596a3a10d5b8d2d6574635306d48092388.zip |
metrics: Add connection socket family to metrics
Adds either ipv4 or ipv6 to the "tor_relay_connections_total" stats.
Closes #40710
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/stats')
-rw-r--r-- | src/feature/stats/rephist.c | 91 | ||||
-rw-r--r-- | src/feature/stats/rephist.h | 12 |
2 files changed, 80 insertions, 23 deletions
diff --git a/src/feature/stats/rephist.c b/src/feature/stats/rephist.c index 021ef6d96e..d1ccc5edf5 100644 --- a/src/feature/stats/rephist.c +++ b/src/feature/stats/rephist.c @@ -1693,70 +1693,127 @@ rep_hist_get_exit_stream_seen(unsigned int cmd) (from_listener) ? CONN_DIRECTION_RECEIVED : CONN_DIRECTION_INITIATED /** Number of connections created as in seen per direction per type. */ -static uint64_t conn_num_created[2][CONN_TYPE_MAX_]; +static uint64_t conn_num_created_v4[2][CONN_TYPE_MAX_]; +static uint64_t conn_num_created_v6[2][CONN_TYPE_MAX_]; /** Number of connections opened per direction per type. */ -static uint64_t conn_num_opened[2][CONN_TYPE_MAX_]; +static uint64_t conn_num_opened_v4[2][CONN_TYPE_MAX_]; +static uint64_t conn_num_opened_v6[2][CONN_TYPE_MAX_]; /** Number of connections rejected per type. Always inbound. */ -static uint64_t conn_num_rejected[CONN_TYPE_MAX_]; +static uint64_t conn_num_rejected_v4[CONN_TYPE_MAX_]; +static uint64_t conn_num_rejected_v6[CONN_TYPE_MAX_]; /** Note that a connection has opened of the given type. */ void -rep_hist_note_conn_opened(bool from_listener, unsigned int type) +rep_hist_note_conn_opened(bool from_listener, unsigned int type, int af) { tor_assert(type <= CONN_TYPE_MAX_); unsigned int dir = CONN_DIRECTION(from_listener); - conn_num_created[dir][type]++; - conn_num_opened[dir][type]++; + switch (af) { + case AF_INET: + conn_num_created_v4[dir][type]++; + conn_num_opened_v4[dir][type]++; + break; + case AF_INET6: + conn_num_created_v6[dir][type]++; + conn_num_opened_v6[dir][type]++; + break; + default: + /* Ignore non IP connections at this point in time. */ + break; + } } /** Note that a connection has closed of the given type. */ void -rep_hist_note_conn_closed(bool from_listener, unsigned int type) +rep_hist_note_conn_closed(bool from_listener, unsigned int type, int af) { tor_assert(type <= CONN_TYPE_MAX_); unsigned int dir = CONN_DIRECTION(from_listener); - if (conn_num_opened[dir][type] > 0) { - conn_num_opened[dir][type]--; + switch (af) { + case AF_INET: + if (conn_num_opened_v4[dir][type] > 0) { + conn_num_opened_v4[dir][type]--; + } + break; + case AF_INET6: + if (conn_num_opened_v6[dir][type] > 0) { + conn_num_opened_v6[dir][type]--; + } + break; + default: + /* Ignore non IP connections at this point in time. */ + break; } } /** Note that a connection has rejected of the given type. */ void -rep_hist_note_conn_rejected(unsigned int type) +rep_hist_note_conn_rejected(unsigned int type, int af) { tor_assert(type <= CONN_TYPE_MAX_); - conn_num_rejected[type]++; + switch (af) { + case AF_INET: + conn_num_rejected_v4[type]++; + break; + case AF_INET6: + conn_num_rejected_v6[type]++; + break; + default: + /* Ignore non IP connections at this point in time. */ + break; + } } /** Return number of created connections of the given type. */ uint64_t -rep_hist_get_conn_created(bool from_listener, unsigned int type) +rep_hist_get_conn_created(bool from_listener, unsigned int type, int af) { tor_assert(type <= CONN_TYPE_MAX_); unsigned int dir = CONN_DIRECTION(from_listener); - return conn_num_created[dir][type]; + switch (af) { + case AF_INET: + return conn_num_created_v4[dir][type]; + case AF_INET6: + return conn_num_created_v6[dir][type]; + default: + return 0; + } } /** Return number of opened connections of the given type. */ uint64_t -rep_hist_get_conn_opened(bool from_listener, unsigned int type) +rep_hist_get_conn_opened(bool from_listener, unsigned int type, int af) { tor_assert(type <= CONN_TYPE_MAX_); unsigned int dir = CONN_DIRECTION(from_listener); - return conn_num_opened[dir][type]; + switch (af) { + case AF_INET: + return conn_num_opened_v4[dir][type]; + case AF_INET6: + return conn_num_opened_v6[dir][type]; + default: + return 0; + } } /** Return number of opened connections of the given type. */ uint64_t -rep_hist_get_conn_rejected(unsigned int type) +rep_hist_get_conn_rejected(unsigned int type, int af) { tor_assert(type <= CONN_TYPE_MAX_); - return conn_num_rejected[type]; + switch (af) { + case AF_INET: + return conn_num_rejected_v4[type]; + case AF_INET6: + return conn_num_rejected_v6[type]; + default: + return 0; + } } /*** cell statistics ***/ diff --git a/src/feature/stats/rephist.h b/src/feature/stats/rephist.h index 02d23a4c1b..fbfab4c451 100644 --- a/src/feature/stats/rephist.h +++ b/src/feature/stats/rephist.h @@ -41,12 +41,12 @@ void rep_hist_note_exit_bytes(uint16_t port, size_t num_written, size_t num_read); void rep_hist_note_exit_stream_opened(uint16_t port); -void rep_hist_note_conn_opened(bool initiated, unsigned int type); -void rep_hist_note_conn_closed(bool initiated, unsigned int type); -void rep_hist_note_conn_rejected(unsigned int type); -uint64_t rep_hist_get_conn_created(bool initiated, unsigned int type); -uint64_t rep_hist_get_conn_opened(bool initiated, unsigned int type); -uint64_t rep_hist_get_conn_rejected(unsigned int type); +void rep_hist_note_conn_opened(bool initiated, unsigned int type, int af); +void rep_hist_note_conn_closed(bool initiated, unsigned int type, int af); +void rep_hist_note_conn_rejected(unsigned int type, int af); +uint64_t rep_hist_get_conn_created(bool initiated, unsigned int type, int af); +uint64_t rep_hist_get_conn_opened(bool initiated, unsigned int type, int af); +uint64_t rep_hist_get_conn_rejected(unsigned int type, int af); void rep_hist_note_exit_stream(unsigned int cmd); uint64_t rep_hist_get_exit_stream_seen(unsigned int cmd); |