Skip to content

Commit

Permalink
Add Linux and OpenBSD support
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Apr 14, 2022
1 parent e5b7e84 commit 7487ced
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion redis.conf
Expand Up @@ -177,7 +177,7 @@ tcp-keepalive 300

# Assign a cookie ID to the listener socket mostly for IP filtering purpose
# e.g. ipfw can redirect packets to a specified identifier, 0 is the default.
#socket-id 0
# socket-id 0

################################# TLS/SSL #####################################

Expand Down
18 changes: 9 additions & 9 deletions src/anet.c
Expand Up @@ -686,15 +686,15 @@ int anetPipe(int fds[2], int read_flags, int write_flags) {
int anetSockId(char *err, int fd, uint32_t id)
{
#ifdef HAVE_SOCKOPTID
if (setsockopt(fd, SOL_SOCKET, SO_USER_COOKIE, (void *)&id, sizeof(id)) == -1) {
anetSetError(err, "setsockopt: %s", strerror(errno));
return ANET_ERR;
}
return ANET_OK;
if (setsockopt(fd, SOL_SOCKET, SOCKOPTID, (void *)&id, sizeof(id)) == -1) {
anetSetError(err, "setsockopt: %s", strerror(errno));
return ANET_ERR;
}
return ANET_OK;
#else
UNUSED(fd);
if (id > 0)
anetSetError(err,"anetSockid unsupported on this platform");
return ANET_OK;
UNUSED(fd);
if (id > 0)
anetSetError(err,"anetSockid unsupported on this platform");
return ANET_OK;
#endif
}
2 changes: 1 addition & 1 deletion src/config.c
Expand Up @@ -2971,7 +2971,7 @@ standardConfig static_configs[] = {
/* Unsigned int configs */
createUIntConfig("maxclients", NULL, MODIFIABLE_CONFIG, 1, UINT_MAX, server.maxclients, 10000, INTEGER_CONFIG, NULL, updateMaxclients),
createUIntConfig("unixsocketperm", NULL, IMMUTABLE_CONFIG, 0, 0777, server.unixsocketperm, 0, OCTAL_CONFIG, NULL, NULL),
createUIntConfig("socket-id", NULL, MODIFIABLE_CONFIG, 0, UINT_MAX, server.soid, 0, INTEGER_CONFIG, NULL, NULL),
createUIntConfig("socket-id", NULL, IMMUTABLE_CONFIG, 0, UINT_MAX, server.soid, 0, INTEGER_CONFIG, NULL, NULL),

/* Unsigned Long configs */
createULongConfig("active-defrag-max-scan-fields", NULL, MODIFIABLE_CONFIG, 1, LONG_MAX, server.active_defrag_max_scan_fields, 1000, INTEGER_CONFIG, NULL, NULL), /* Default: keys with more than 1000 fields will be processed separately */
Expand Down
14 changes: 14 additions & 0 deletions src/config.h
Expand Up @@ -80,6 +80,10 @@
/* MSG_NOSIGNAL. */
#ifdef __linux__
#define HAVE_MSG_NOSIGNAL 1
#if defined(SO_MARK)
#define HAVE_SOCKOPTID 1
#define SOCKOPTID SO_MARK
#endif
#endif

/* Test for polling API */
Expand Down Expand Up @@ -114,7 +118,17 @@
#endif

#if defined(__FreeBSD__)
#if defined(SO_USER_COOKIE)
#define HAVE_SOCKOPTID 1
#define SOCKOPTID SO_USER_COOKIE
#endif
#endif

#if defined(__OpenBSD__)
#if defined(SO_RTABLE)
#define HAVE_SOCKOPTID 1
#define SOCKOPTID SO_RTABLE
#endif
#endif

#if __GNUC__ >= 4
Expand Down

0 comments on commit 7487ced

Please sign in to comment.