From 925a7f96ea5d44e6689fafbdde3f61eca3ddefc3 Mon Sep 17 00:00:00 2001 From: hwware Date: Tue, 9 Jul 2024 19:38:39 +0000 Subject: [PATCH] remove some codes non-related to this PR Signed-off-by: hwware --- src/networking.c | 4 ++-- src/server.c | 22 ---------------------- src/server.h | 7 ------- src/trusted_network.c | 28 ---------------------------- 4 files changed, 2 insertions(+), 59 deletions(-) diff --git a/src/networking.c b/src/networking.c index 62da92d848..332d39a4ce 100644 --- a/src/networking.c +++ b/src/networking.c @@ -1360,10 +1360,10 @@ void acceptCommonHandler(connection *conn, struct ClientFlags flags, char *ip, c if (sa != NULL && sa->ss_family == AF_INET) ip_addr = ((struct sockaddr_in *)sa)->sin_addr.s_addr; if (server.trustedIPCount && ip_addr) { - if (/*!isTrustedNetwork(c) &&*/ !checkTrustedIP(ip_addr)) { + if (!checkTrustedIP(ip_addr)) { serverLog(LL_VERBOSE, "Access denied as connection is not from trusted source"); - char *err = "-ERR client's IP is not found in trusted-addresses list, access denied\r\n"; + char *err = "-ERR client's IP address is not found in trusted-addresses list, access denied\r\n"; /* That's a best effort error message, don't check write errors */ if (connWrite(conn, err, strlen(err)) == -1) { diff --git a/src/server.c b/src/server.c index b975b486b5..e0e4da128e 100644 --- a/src/server.c +++ b/src/server.c @@ -1987,8 +1987,6 @@ void initServerConfig(void) { server.bindaddr_count = CONFIG_DEFAULT_BINDADDR_COUNT; for (j = 0; j < CONFIG_DEFAULT_BINDADDR_COUNT; j++) server.bindaddr[j] = zstrdup(default_bindaddr[j]); memset(server.listeners, 0x00, sizeof(server.listeners)); - server.host_machine_ip = 0; - server.host_machine_netmask = 0; server.active_expire_enabled = 1; server.lazy_expire_disabled = 0; server.skip_checksum_validation = 0; @@ -2582,26 +2580,6 @@ void initServer(void) { server.reply_buffer_resizing_enabled = 1; server.client_mem_usage_buckets = NULL; resetReplicationBuffer(); - char *default_bindaddr[CONFIG_DEFAULT_BINDADDR_COUNT] = CONFIG_DEFAULT_BINDADDR; - if (server.bindaddr_count > 0 && strcmp(server.bindaddr[0], default_bindaddr[0])) { - serverLog(LL_WARNING, "bind adrs.%d : %s", server.bindaddr_count, server.bindaddr[0]); - server.host_machine_ip = inet_addr(server.bindaddr[0]); - } else { - serverLog(LL_WARNING, "local loopback."); - server.host_machine_ip = inet_addr("127.0.0.1"); - } - - if (server.host_machine_ip <= 0) { - serverLog(LL_WARNING, "Can not get host machine network ip, exiting."); - exit(1); - } - - server.host_machine_netmask = getIPv4Netmask(server.host_machine_ip); - if (server.host_machine_netmask <= 0) { - serverLog(LL_WARNING, "Can not get host machine network netmask, exiting."); - exit(1); - } - /* Make sure the locale is set on startup based on the config file. */ if (setlocale(LC_COLLATE, server.locale_collate) == NULL) { serverLog(LL_WARNING, "Failed to configure LOCALE for invalid locale name."); diff --git a/src/server.h b/src/server.h index 9fa4541ee4..0d411d28f8 100644 --- a/src/server.h +++ b/src/server.h @@ -1650,8 +1650,6 @@ struct valkeyServer { list *replicas, *monitors; /* List of replicas and MONITORs */ client *current_client; /* The client that triggered the command execution (External or AOF). */ client *executing_client; /* The client executing the current command (possibly script or module). */ - in_addr_t host_machine_ip; /*Listening ip for host machine network*/ - in_addr_t host_machine_netmask; /*Netmask for host_machine_ip*/ in_addr_t *trustedIPList; unsigned int trustedIPCount; @@ -2763,11 +2761,6 @@ void ioThreadWriteToClient(void *data); int canParseCommand(client *c); int processIOThreadsReadDone(void); int processIOThreadsWriteDone(void); -void setTrustedNetworkFlag(client *c, const struct sockaddr_storage *sa); -int isUnixNetwork(client *c); -int checkConnFromTrustedNetwork(client *c); -int isTrustedNetwork(client *c); -in_addr_t getIPv4Netmask(in_addr_t ip); int checkTrustedIP(in_addr_t ip); void valkeySortIP(in_addr_t *IPlist, unsigned int IPcount); diff --git a/src/trusted_network.c b/src/trusted_network.c index b3f7feb309..4e73f8bf59 100644 --- a/src/trusted_network.c +++ b/src/trusted_network.c @@ -27,31 +27,3 @@ int checkTrustedIP(in_addr_t ip) { ? 1 : 0; } - -int isUnixNetwork(client *c) { - return c->flag.unix_socket; -} - - -in_addr_t getIPv4Netmask(in_addr_t ip) { - struct ifaddrs *addrs = NULL; - in_addr_t netmask = 0; - - if (getifaddrs(&addrs) == -1) return 0; - - for (struct ifaddrs *addr = addrs; addr != NULL; addr = addr->ifa_next) { - if (addr->ifa_addr == NULL || addr->ifa_netmask == NULL) continue; - - if (addr->ifa_addr->sa_family != AF_INET || addr->ifa_netmask->sa_family != AF_INET) continue; - - struct sockaddr_in *in_addr = (struct sockaddr_in *)addr->ifa_addr; - if (in_addr->sin_addr.s_addr == ip) { - struct sockaddr_in *mask = (struct sockaddr_in *)addr->ifa_netmask; - netmask = mask->sin_addr.s_addr; - break; - } - } - - freeifaddrs(addrs); - return netmask; -}