Skip to content

Commit

Permalink
remove some codes non-related to this PR
Browse files Browse the repository at this point in the history
Signed-off-by: hwware <[email protected]>
  • Loading branch information
hwware committed Jul 9, 2024
1 parent 1e5adf7 commit 925a7f9
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 0 additions & 22 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
Expand Down
7 changes: 0 additions & 7 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
28 changes: 0 additions & 28 deletions src/trusted_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 925a7f9

Please sign in to comment.