From 8f61f8b5864d1ab3bc516e4d3a811250686341e9 Mon Sep 17 00:00:00 2001 From: Shivshankar-Reddy Date: Tue, 18 Jun 2024 18:00:03 +0000 Subject: [PATCH] Correct format Signed-off-by: Shivshankar-Reddy Signed-off-by: hwware --- src/anet.c | 6 ++++-- src/config.c | 22 +++++++++++----------- src/networking.c | 8 +++----- src/server.c | 4 ++-- src/trusted_network.c | 16 ++++++---------- 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/anet.c b/src/anet.c index ead77211fc4..1e6d7fd185e 100644 --- a/src/anet.c +++ b/src/anet.c @@ -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; @@ -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; } diff --git a/src/config.c b/src/config.c index 344fb20cd97..089b88f7a97 100644 --- a/src/config.c +++ b/src/config.c @@ -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; @@ -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; } @@ -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); } @@ -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; @@ -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, " "); } } } diff --git a/src/networking.c b/src/networking.c index 649d2957c49..42b79927aff 100644 --- a/src/networking.c +++ b/src/networking.c @@ -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)) { @@ -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++; @@ -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 " diff --git a/src/server.c b/src/server.c index 5103c51a6f5..b975b486b56 100644 --- a/src/server.c +++ b/src/server.c @@ -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."); diff --git a/src/trusted_network.c b/src/trusted_network.c index 6202075a2c2..8616a6bdd31 100644 --- a/src/trusted_network.c +++ b/src/trusted_network.c @@ -13,9 +13,9 @@ 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) { @@ -23,8 +23,7 @@ void valkeySortIP(in_addr_t *IPlist, unsigned int IPcount) { } 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) { @@ -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) {