diff options
author | David Goulet <dgoulet@torproject.org> | 2022-11-08 15:25:08 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2022-11-08 15:25:08 -0500 |
commit | 5b0103cfb4a8e3c9807eab8d381cff0cf65d7ab8 (patch) | |
tree | 254c05c53fff5395e0f905d55f98605db93af1ed /src/feature | |
parent | 00633bc619046e09536d742e5f862d75c35e476f (diff) | |
parent | 6196e9596a3a10d5b8d2d6574635306d48092388 (diff) | |
download | tor-5b0103cfb4a8e3c9807eab8d381cff0cf65d7ab8.tar.gz tor-5b0103cfb4a8e3c9807eab8d381cff0cf65d7ab8.zip |
Merge branch 'tor-gitlab/mr/651' into maint-0.4.7
Diffstat (limited to 'src/feature')
-rw-r--r-- | src/feature/relay/relay_metrics.c | 60 | ||||
-rw-r--r-- | src/feature/stats/rephist.c | 91 | ||||
-rw-r--r-- | src/feature/stats/rephist.h | 12 |
3 files changed, 130 insertions, 33 deletions
diff --git a/src/feature/relay/relay_metrics.c b/src/feature/relay/relay_metrics.c index cd80c5e95e..02e38d7699 100644 --- a/src/feature/relay/relay_metrics.c +++ b/src/feature/relay/relay_metrics.c @@ -184,6 +184,22 @@ handshake_type_to_str(const uint16_t type) } } +/** Helper function to convert a socket family type into a string. */ +static inline const char * +af_to_string(const int af) +{ + switch (af) { + case AF_INET: + return "ipv4"; + case AF_INET6: + return "ipv6"; + case AF_UNIX: + return "unix"; + default: + return "<unknown>"; + } +} + /** Fill function for the RELAY_METRICS_NUM_CIRCUITS metric. */ static void fill_circuits_values(void) @@ -515,6 +531,7 @@ fill_single_connection_value(metrics_store_entry_t *sentry, unsigned int conn_type, const char* direction, const char* state, + int socket_family, uint64_t value) { metrics_store_entry_add_label(sentry, @@ -523,6 +540,8 @@ fill_single_connection_value(metrics_store_entry_t *sentry, metrics_format_label("direction", direction)); metrics_store_entry_add_label(sentry, metrics_format_label("state", state)); + metrics_store_entry_add_label(sentry, + metrics_format_label("family", af_to_string(socket_family))); metrics_store_entry_update(sentry, value); } @@ -540,28 +559,49 @@ fill_connections_values(void) } metrics_store_entry_t *sentry = metrics_store_add(the_store, rentry->type, rentry->name, rentry->help); - fill_single_connection_value(sentry, i, "initiated", "created", - rep_hist_get_conn_created(false, i)); + fill_single_connection_value(sentry, i, "initiated", "created", AF_INET, + rep_hist_get_conn_created(false, i, AF_INET)); + sentry = metrics_store_add(the_store, rentry->type, rentry->name, + rentry->help); + fill_single_connection_value(sentry, i, "initiated", "created", AF_INET6, + rep_hist_get_conn_created(false, i, + AF_INET6)); sentry = metrics_store_add(the_store, rentry->type, rentry->name, rentry->help); - fill_single_connection_value(sentry, i, "received", "created", - rep_hist_get_conn_created(true, i)); + fill_single_connection_value(sentry, i, "received", "created", AF_INET, + rep_hist_get_conn_created(true, i, AF_INET)); + sentry = metrics_store_add(the_store, rentry->type, rentry->name, + rentry->help); + fill_single_connection_value(sentry, i, "received", "created", AF_INET6, + rep_hist_get_conn_created(true, i, AF_INET6)); sentry = metrics_store_add(the_store, rentry->type, rentry->name, rentry->help); - fill_single_connection_value(sentry, i, "initiated", "opened", - rep_hist_get_conn_opened(false, i)); + fill_single_connection_value(sentry, i, "initiated", "opened", AF_INET, + rep_hist_get_conn_opened(false, i, AF_INET)); + sentry = metrics_store_add(the_store, rentry->type, rentry->name, + rentry->help); + fill_single_connection_value(sentry, i, "initiated", "opened", AF_INET6, + rep_hist_get_conn_opened(false, i, AF_INET6)); sentry = metrics_store_add(the_store, rentry->type, rentry->name, rentry->help); - fill_single_connection_value(sentry, i, "received", "opened", - rep_hist_get_conn_opened(true, i)); + fill_single_connection_value(sentry, i, "received", "opened", AF_INET, + rep_hist_get_conn_opened(true, i, AF_INET)); + sentry = metrics_store_add(the_store, rentry->type, rentry->name, + rentry->help); + fill_single_connection_value(sentry, i, "received", "opened", AF_INET6, + rep_hist_get_conn_opened(true, i, AF_INET6)); sentry = metrics_store_add(the_store, rentry->type, rentry->name, rentry->help); - fill_single_connection_value(sentry, i, "received", "rejected", - rep_hist_get_conn_rejected(i)); + fill_single_connection_value(sentry, i, "received", "rejected", AF_INET, + rep_hist_get_conn_rejected(i, AF_INET)); + sentry = metrics_store_add(the_store, rentry->type, rentry->name, + rentry->help); + fill_single_connection_value(sentry, i, "received", "rejected", AF_INET6, + rep_hist_get_conn_rejected(i, AF_INET6)); } } 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); |