From f6a681c4961b7fbeae9074685e864b06bab4c111 Mon Sep 17 00:00:00 2001 From: chenwei Date: Wed, 31 Jan 2018 13:37:58 +0800 Subject: [PATCH] Nginx : ngx_configure_listening_sockets 1. Nginx based on fstack delays setting up server on fstack until ngx_worker_process_init. ngx_configure_listening_sockets should as well. 2. FStack does not support IP_PKTINFO --- app/nginx-1.11.10/src/core/ngx_connection.c | 64 +++++++++++-------- .../src/os/unix/ngx_process_cycle.c | 4 ++ 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/app/nginx-1.11.10/src/core/ngx_connection.c b/app/nginx-1.11.10/src/core/ngx_connection.c index 9739fed66..fd4d2ada3 100644 --- a/app/nginx-1.11.10/src/core/ngx_connection.c +++ b/app/nginx-1.11.10/src/core/ngx_connection.c @@ -13,6 +13,33 @@ #if (NGX_HAVE_FSTACK) extern int fstack_territory(int domain, int type, int protocol); extern int is_fstack_fd(int sockfd); + +#define ngx_ff_skip_listening_socket(ls) \ + if (ngx_process <= NGX_PROCESS_MASTER) { \ + \ + /* process master, kernel network stack*/ \ + if (!ls[i].belong_to_host) { \ + /* We should continue to process the listening socket, */ \ + /* if it is not supported by fstack. */ \ + if (fstack_territory(ls[i].sockaddr->sa_family, ls[i].type, 0)) { \ + continue; \ + } \ + } \ + } else if (NGX_PROCESS_WORKER == ngx_process) { \ + /* process worker, fstack */ \ + if (ls[i].belong_to_host) { \ + continue; \ + } \ + \ + if (!fstack_territory(ls[i].sockaddr->sa_family, ls[i].type, 0)) { \ + continue; \ + } \ + } else { \ + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, \ + "unexpected process type: %d, ignored", \ + ngx_process); \ + exit(1); \ + } #endif @@ -411,31 +438,7 @@ ngx_open_listening_sockets(ngx_cycle_t *cycle) #if (NGX_HAVE_FSTACK) - if (ngx_process <= NGX_PROCESS_MASTER) { - - /* process master, kernel network stack*/ - if (!ls[i].belong_to_host) { - /* We should continue to process the listening socket, - if it is not supported by fstack.*/ - if (fstack_territory(ls[i].sockaddr->sa_family, ls[i].type, 0)) { - continue; - } - } - } else if (NGX_PROCESS_WORKER == ngx_process) { - /* process worker, fstack */ - if (ls[i].belong_to_host) { - continue; - } - - if (!fstack_territory(ls[i].sockaddr->sa_family, ls[i].type, 0)) { - continue; - } - } else { - ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, - "unexpected process type: %d, ignored", - ngx_process); - exit(1); - } + ngx_ff_skip_listening_socket(ls); #endif @@ -695,6 +698,12 @@ ngx_configure_listening_sockets(ngx_cycle_t *cycle) ls = cycle->listening.elts; for (i = 0; i < cycle->listening.nelts; i++) { +#if (NGX_HAVE_FSTACK) + + ngx_ff_skip_listening_socket(ls); + +#endif + ls[i].log = *ls[i].logp; if (ls[i].rcvbuf != -1) { @@ -941,7 +950,8 @@ ngx_configure_listening_sockets(ngx_cycle_t *cycle) &ls[i].addr_text); } } - +/* TODO: configure , auto/feature */ +#if !(NGX_HAVE_FSTACK) #elif (NGX_HAVE_IP_PKTINFO) if (ls[i].wildcard @@ -960,7 +970,7 @@ ngx_configure_listening_sockets(ngx_cycle_t *cycle) &ls[i].addr_text); } } - +#endif /* NGX_HAVE_FSTACK */ #endif #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO) diff --git a/app/nginx-1.11.10/src/os/unix/ngx_process_cycle.c b/app/nginx-1.11.10/src/os/unix/ngx_process_cycle.c index 9ccfe6fdd..abfb814ef 100644 --- a/app/nginx-1.11.10/src/os/unix/ngx_process_cycle.c +++ b/app/nginx-1.11.10/src/os/unix/ngx_process_cycle.c @@ -1002,6 +1002,10 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker) "ngx_open_listening_sockets failed"); exit(2); } + + if (!ngx_test_config) { + ngx_configure_listening_sockets(cycle); + } } #endif