summaryrefslogtreecommitdiff
path: root/src/socket.c
diff options
context:
space:
mode:
authorzhenwei pi <pizhenwei@bytedance.com>2023-01-04 16:52:56 +0800
committerGitHub <noreply@github.com>2023-01-04 10:52:56 +0200
commitdec529f4be3e3314300bb513e7a9f3af636e13b0 (patch)
treeaeca1a2a40c5da584fac4c220aaf85d4064ad6e4 /src/socket.c
parent884ca601b21ec6ef4d216ae850c0cf503f762623 (diff)
downloadredis-dec529f4be3e3314300bb513e7a9f3af636e13b0.tar.gz
Introduce .is_local method for connection layer (#11672)
Introduce .is_local method to connection, and implement for TCP/TLS/ Unix socket, also drop 'int islocalClient(client *c)'. Then we can hide the detail into the specific connection types. Uplayer tests a connection is local or not by abstract method only. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com> Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Diffstat (limited to 'src/socket.c')
-rw-r--r--src/socket.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/socket.c b/src/socket.c
index 7190d5358..e7f6a5125 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -335,6 +335,15 @@ static int connSocketAddr(connection *conn, char *ip, size_t ip_len, int *port,
return C_ERR;
}
+static int connSocketIsLocal(connection *conn) {
+ char cip[NET_IP_STR_LEN + 1] = { 0 };
+
+ if (connSocketAddr(conn, cip, sizeof(cip) - 1, NULL, 1) == C_ERR)
+ return -1;
+
+ return !strcmp(cip,"127.0.0.1") || !strcmp(cip,"::1");
+}
+
static int connSocketListen(connListener *listener) {
return listenToPort(listener);
}
@@ -392,6 +401,7 @@ static ConnectionType CT_Socket = {
.ae_handler = connSocketEventHandler,
.accept_handler = connSocketAcceptHandler,
.addr = connSocketAddr,
+ .is_local = connSocketIsLocal,
.listen = connSocketListen,
/* create/shutdown/close connection */