summaryrefslogtreecommitdiff
path: root/memcached.c
diff options
context:
space:
mode:
authorDavid CARLIER <devnexen@gmail.com>2022-02-26 08:13:46 +0000
committerdormando <dormando@rydia.net>2022-08-25 20:38:07 -0700
commita76c1155140bf04751ff437db6d1eb0b66af349b (patch)
tree4affa9d513bf52d9d3cd018d41ed56f6a09564a0 /memcached.c
parent8f478cdaf50c1467fc2191ac1c3a8e85ec2efcff (diff)
downloadmemcached-a76c1155140bf04751ff437db6d1eb0b66af349b.tar.gz
sock ip filtering tagging support for FBSD/OBSD
Also linux.
Diffstat (limited to 'memcached.c')
-rw-r--r--memcached.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/memcached.c b/memcached.c
index d53b607..7871fe8 100644
--- a/memcached.c
+++ b/memcached.c
@@ -292,6 +292,9 @@ static void settings_init(void) {
#endif
settings.num_napi_ids = 0;
settings.memory_file = NULL;
+#ifdef SOCK_COOKIE_ID
+ settings.sock_cookie_id = 0;
+#endif
}
extern pthread_mutex_t conn_lock;
@@ -3539,6 +3542,13 @@ static int server_socket(const char *interface,
}
}
#endif
+#ifdef SOCK_COOKIE_ID
+ if (settings.sock_cookie_id != 0) {
+ error = setsockopt(sfd, SOL_SOCKET, SOCK_COOKIE_ID, (void *)&settings.sock_cookie_id, sizeof(uint32_t));
+ if (error != 0)
+ perror("setsockopt");
+ }
+#endif
setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags));
if (IS_UDP(transport)) {
@@ -4108,6 +4118,9 @@ static void usage(void) {
flag_enabled_disabled(settings.relaxed_privileges));
#endif
#endif
+#ifdef SOCK_COOKIE_ID
+ printf(" - sock_cookie_id: attributes an ID to a socket for ip filtering/firewalls \n");
+#endif
#ifdef EXTSTORE
printf("\n - External storage (ext_*) related options (see: https://memcached.org/extstore)\n");
printf(" - ext_path: file to write to for external storage.\n"
@@ -4837,6 +4850,9 @@ int main (int argc, char **argv) {
#ifdef MEMCACHED_DEBUG
RELAXED_PRIVILEGES,
#endif
+#ifdef SOCK_COOKIE_ID
+ COOKIE_ID,
+#endif
};
char *const subopts_tokens[] = {
[MAXCONNS_FAST] = "maxconns_fast",
@@ -4897,6 +4913,9 @@ int main (int argc, char **argv) {
#ifdef MEMCACHED_DEBUG
[RELAXED_PRIVILEGES] = "relaxed_privileges",
#endif
+#ifdef SOCK_COOKIE_ID
+ [COOKIE_ID] = "sock_cookie_id",
+#endif
NULL
};
@@ -5664,6 +5683,11 @@ int main (int argc, char **argv) {
settings.relaxed_privileges = true;
break;
#endif
+#ifdef SOCK_COOKIE_ID
+ case COOKIE_ID:
+ (void)safe_strtoul(subopts_value, &settings.sock_cookie_id);
+ break;
+#endif
default:
#ifdef EXTSTORE
// TODO: differentiating response code.