Skip to content

Commit

Permalink
Correct format
Browse files Browse the repository at this point in the history
Signed-off-by: Shivshankar-Reddy <[email protected]>
Signed-off-by: hwware <[email protected]>
  • Loading branch information
Shivshankar-Reddy authored and hwware committed Jul 9, 2024
1 parent a80a776 commit 8f61f8b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
6 changes: 4 additions & 2 deletions src/anet.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ static int anetGenericAccept(char *err, int s, struct sockaddr *sa, socklen_t *l

/* Accept a connection and also make sure the socket is non-blocking, and CLOEXEC.
* returns the new socket FD, or -1 on error.
* If client_addr is not null, it will receive a copy of the client's sockaddr_storage structure. */
* If client_addr is not null, it will receive a copy of the client's sockaddr_storage structure. */
int anetTcpAccept(char *err, int serversock, char *ip, size_t ip_len, int *port, struct sockaddr_storage *client_addr) {
int fd;
struct sockaddr_storage sa;
Expand All @@ -646,7 +646,9 @@ int anetTcpAccept(char *err, int serversock, char *ip, size_t ip_len, int *port,
if (ip) inet_ntop(AF_INET6, (void *)&(s->sin6_addr), ip, ip_len);
if (port) *port = ntohs(s->sin6_port);
}
if (client_addr) { memcpy(client_addr, &sa, sizeof(sa)); }
if (client_addr) {
memcpy(client_addr, &sa, sizeof(sa));
}
return fd;
}

Expand Down
22 changes: 11 additions & 11 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,7 @@ static sds getConfigNotifyKeyspaceEventsOption(standardConfig *config) {
return keyspaceEventsFlagsToString(server.notify_keyspace_events);
}

static int setConfigTrustedAddresses(standardConfig *config, sds* argv, int argc, const char **err) {
static int setConfigTrustedAddresses(standardConfig *config, sds *argv, int argc, const char **err) {
UNUSED(config);
int j;
int skip = 0;
Expand All @@ -2871,10 +2871,10 @@ static int setConfigTrustedAddresses(standardConfig *config, sds* argv, int argc
if (argc == 1 && sdslen(argv[0]) == 0) argc = 0;

for (j = 0; j < argc; j++) {
const char* ip = zstrdup(argv[j]);
const char *ip = zstrdup(argv[j]);
in_addr_t addr = inet_addr(ip);
if (addr == 0 || addr == INADDR_NONE) {
if(!ip) sds_free((void *)ip);
if (!ip) sds_free((void *)ip);
*err = "Invalid address is specified.";
return 0;
}
Expand All @@ -2883,8 +2883,8 @@ static int setConfigTrustedAddresses(standardConfig *config, sds* argv, int argc
skip++;
continue;
}
server.trustedIPList = zrealloc(server.trustedIPList,
sizeof(in_addr_t) * (server.trustedIPCount + j - skip + 1));
server.trustedIPList =
zrealloc(server.trustedIPList, sizeof(in_addr_t) * (server.trustedIPCount + j - skip + 1));
server.trustedIPList[j + server.trustedIPCount - skip] = addr;
sds_free((void *)ip);
}
Expand All @@ -2901,11 +2901,11 @@ static sds getConfigTrustedAddresses(standardConfig *config) {
sds reply = sdsempty();

for (i = 0; i < server.trustedIPCount; i++) {
struct in_addr addr = { 0 };
struct in_addr addr = {0};
addr.s_addr = server.trustedIPList[i];
reply = sdscat(reply, inet_ntoa(addr));
if (i != (server.trustedIPCount - 1)) {
reply = sdscat(reply," ");
reply = sdscat(reply, " ");
}
}
return reply;
Expand All @@ -2921,14 +2921,14 @@ void rewriteConfigTrustedAddresses(standardConfig *config, const char *name, str
sdsfree(line);
return;
} else {
line = sdscat(line,name);
line = sdscat(line," ");
line = sdscat(line, name);
line = sdscat(line, " ");
for (unsigned int j = 0; j < server.trustedIPCount; j++) {
struct in_addr addr = { 0 };
struct in_addr addr = {0};
addr.s_addr = server.trustedIPList[j];
line = sdscat(line, inet_ntoa(addr));
if (j != (server.trustedIPCount - 1)) {
line = sdscat(line," ");
line = sdscat(line, " ");
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,8 +1357,7 @@ void acceptCommonHandler(connection *conn, struct ClientFlags flags, char *ip, c
return;
}
in_addr_t ip_addr = 0;
if (sa != NULL && sa->ss_family == AF_INET)
ip_addr = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
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)) {
Expand All @@ -1367,7 +1366,7 @@ void acceptCommonHandler(connection *conn, struct ClientFlags flags, char *ip, c
char *err = "-ERR client's IP 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) {
if (connWrite(conn, err, strlen(err)) == -1) {
/* Nothing to do, Just to avoid the warning... */
}
server.stat_rejected_conn++;
Expand All @@ -1393,8 +1392,7 @@ void acceptCommonHandler(connection *conn, struct ClientFlags flags, char *ip, c
* Admission control will happen before a client is created and connAccept()
* called, because we don't want to even start transport-level negotiation
* if rejected. */
if (!checkTrustedIP(ip_addr) &&
(listLength(server.clients) + getClusterConnectionsCount() >= server.maxclients)) {
if (!checkTrustedIP(ip_addr) && (listLength(server.clients) + getClusterConnectionsCount() >= server.maxclients)) {
char *err;
if (server.cluster_enabled)
err = "-ERR max number of clients + cluster "
Expand Down
4 changes: 2 additions & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2583,8 +2583,8 @@ void initServer(void) {
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]);
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.");
Expand Down
16 changes: 6 additions & 10 deletions src/trusted_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ int compareIP(const void *arg1, const void *arg2) {
if (ip1 == ip2)
return 0;
else if (ip1 < ip2)
return -1;
return -1;
else
return 1;
return 1;
}

void valkeySortIP(in_addr_t *IPlist, unsigned int IPcount) {
qsort(IPlist, IPcount, sizeof(IPlist[0]), compareIP);
}

int checkTrustedIP(in_addr_t ip) {
return bsearch(&ip, server.trustedIPList, server.trustedIPCount,
sizeof(server.trustedIPList[0]), compareIP) != NULL ? 1 : 0;
return bsearch(&ip, server.trustedIPList, server.trustedIPCount, sizeof(server.trustedIPList[0]), compareIP) != NULL ? 1 : 0;
}

int isUnixNetwork(client *c) {
Expand All @@ -36,15 +35,12 @@ in_addr_t getIPv4Netmask(in_addr_t ip) {
struct ifaddrs *addrs = NULL;
in_addr_t netmask = 0;

if (getifaddrs(&addrs) == -1)
return 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 == NULL || addr->ifa_netmask == NULL) continue;

if (addr->ifa_addr->sa_family != AF_INET || addr->ifa_netmask->sa_family != AF_INET)
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) {
Expand Down

0 comments on commit 8f61f8b

Please sign in to comment.