Skip to content

FPM add routing view global option (for FreeBSD for now). #8470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sapi/fpm/fpm/fpm_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = {
{ "listen.group", &fpm_conf_set_string, WPO(listen_group) },
{ "listen.mode", &fpm_conf_set_string, WPO(listen_mode) },
{ "listen.allowed_clients", &fpm_conf_set_string, WPO(listen_allowed_clients) },
#ifdef SO_SETFIB
{ "listen.setfib", &fpm_conf_set_integer, WPO(listen_setfib) },
#endif
{ "process.priority", &fpm_conf_set_integer, WPO(process_priority) },
{ "process.dumpable", &fpm_conf_set_boolean, WPO(process_dumpable) },
{ "pm", &fpm_conf_set_pm, WPO(pm) },
Expand Down Expand Up @@ -1715,6 +1718,9 @@ static void fpm_conf_dump(void) /* {{{ */
zlog(ZLOG_NOTICE, "\tlisten.group = %s", STR2STR(wp->config->listen_group));
zlog(ZLOG_NOTICE, "\tlisten.mode = %s", STR2STR(wp->config->listen_mode));
zlog(ZLOG_NOTICE, "\tlisten.allowed_clients = %s", STR2STR(wp->config->listen_allowed_clients));
#ifdef HAVE_SETFIB
zlog(ZLOG_NOTICE, "\tlisten.setfib = %d", wp->config->listen_setfib);
#endif
if (wp->config->process_priority == 64) {
zlog(ZLOG_NOTICE, "\tprocess.priority = undefined");
} else {
Expand Down
3 changes: 3 additions & 0 deletions sapi/fpm/fpm/fpm_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ struct fpm_worker_pool_config_s {
char *listen_acl_users;
char *listen_acl_groups;
#endif
#ifdef SO_SETFIB
int listen_setfib;
#endif
};

struct ini_value_parser_s {
Expand Down
38 changes: 38 additions & 0 deletions sapi/fpm/fpm/fpm_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ static struct fpm_array_s sockets_list;

enum { FPM_GET_USE_SOCKET = 1, FPM_STORE_SOCKET = 2, FPM_STORE_USE_SOCKET = 3 };

#ifdef SO_SETFIB
static int routemax = -1;
#endif

static inline void fpm_sockets_get_env_name(char *envname, unsigned idx) /* {{{ */
{
if (!idx) {
Expand Down Expand Up @@ -250,6 +254,20 @@ static int fpm_sockets_new_listening_socket(struct fpm_worker_pool_s *wp, struct
return -1;
}

#ifdef SO_SETFIB
if (-1 < wp->config->listen_setfib) {
if (routemax < wp->config->listen_setfib) {
zlog(ZLOG_ERROR, "Invalid routing table id %d, max is %d", wp->config->listen_setfib, routemax);
close(sock);
return -1;
}

if (0 > setsockopt(sock, SOL_SOCKET, SO_SETFIB, &wp->config->listen_setfib, sizeof(wp->config->listen_setfib))) {
zlog(ZLOG_WARNING, "failed to change socket SO_SETFIB attribute");
}
}
#endif

return sock;
}
/* }}} */
Expand Down Expand Up @@ -386,6 +404,20 @@ static int fpm_socket_af_unix_listening_socket(struct fpm_worker_pool_s *wp) /*
}
/* }}} */

#ifdef SO_SETFIB
static zend_result fpm_socket_setfib_init(void)
{
/* potentially up to 65536 but needs to check the actual cap beforehand */
size_t len = sizeof(routemax);
if (sysctlbyname("net.fibs", &routemax, &len, NULL, 0) < 0) {
zlog(ZLOG_ERROR, "failed to get max routing table");
return FAILURE;
}

return SUCCESS;
}
#endif

int fpm_sockets_init_main() /* {{{ */
{
unsigned i, lq_len;
Expand All @@ -399,6 +431,12 @@ int fpm_sockets_init_main() /* {{{ */
return -1;
}

#ifdef SO_SETFIB
if (fpm_socket_setfib_init() == FAILURE) {
return -1;
}
#endif

/* import inherited sockets */
for (i = 0; i < FPM_ENV_SOCKET_SET_MAX; i++) {
fpm_sockets_get_env_name(envname, i);
Expand Down
3 changes: 3 additions & 0 deletions sapi/fpm/fpm/fpm_sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include <sys/types.h>
#include <sys/socket.h>
#if defined(__FreeBSD__)
#include <sys/sysctl.h>
#endif
#include <sys/un.h>
#include <unistd.h>
#include <fcntl.h>
Expand Down
44 changes: 44 additions & 0 deletions sapi/fpm/tests/setsofib.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
--TEST--
FPM: listen.setfib`
--SKIPIF--
<?php
include "skipif.inc";

if (!str_contains(PHP_OS, 'FreeBSD')) {
die('skipped supported only on FreeBSD');
}
?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
pid = {{FILE:PID}}
[setfib]
listen = {{ADDR}}
listen.setfib = 68000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;

$tester = new FPM\Tester($cfg);
$tester->start();
$tester->expectLogError('Invalid routing table id 68000, max is 1');
$tester->terminate();
$tester->close();

?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>