diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-12-01 11:36:03 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-12-01 11:36:03 -0500 |
commit | 701eaef980de4f7dbb5c31c4fee9b7e1e266d7a1 (patch) | |
tree | c4809e245ee2b797593ba83bdd0659ace8765d79 /src/lib/net/socket.c | |
parent | d4d4a4b2dd95ce0cb8db6fc0074f0ac66d659469 (diff) | |
download | tor-701eaef980de4f7dbb5c31c4fee9b7e1e266d7a1.tar.gz tor-701eaef980de4f7dbb5c31c4fee9b7e1e266d7a1.zip |
Move net.inet.ip.random_id code to lib/net/
Diffstat (limited to 'src/lib/net/socket.c')
-rw-r--r-- | src/lib/net/socket.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/net/socket.c b/src/lib/net/socket.c index cd7c9685cd..8940e00591 100644 --- a/src/lib/net/socket.c +++ b/src/lib/net/socket.c @@ -31,6 +31,9 @@ #endif #include <stddef.h> #include <string.h> +#ifdef __FreeBSD__ +#include <sys/sysctl.h> +#endif /** Called before we make any calls to network-related functions. * (Some operating systems require their network libraries to be @@ -60,6 +63,32 @@ network_init(void) return 0; } +/** + * Warn the user if any system network parameters should be changed. + */ +void +check_network_configuration(bool server_mode) +{ +#ifdef __FreeBSD__ + if (server_mode) { + int random_id_state; + size_t state_size = sizeof(random_id_state); + + if (sysctlbyname("net.inet.ip.random_id", &random_id_state, + &state_size, NULL, 0)) { + log_warn(LD_CONFIG, + "Failed to figure out if IP ids are randomized."); + } else if (random_id_state == 0) { + log_warn(LD_CONFIG, "Looks like IP ids are not randomized. " + "Please consider setting the net.inet.ip.random_id sysctl, " + "so your relay makes it harder to figure out how busy it is."); + } + } +#else + (void) server_mode; +#endif +} + /* When set_max_file_sockets() is called, update this with the max file * descriptor value so we can use it to check the limit when opening a new * socket. Default value is what Debian sets as the default hard limit. */ |