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
This commit is contained in:
chenwei 2018-01-31 13:37:58 +08:00
parent 0a6b81772e
commit f6a681c496
2 changed files with 41 additions and 27 deletions

View File

@ -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)

View File

@ -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