diff --git a/app/nginx-1.16.1/src/event/ngx_event_connect.c b/app/nginx-1.16.1/src/event/ngx_event_connect.c index a3589e672..36858f482 100644 --- a/app/nginx-1.16.1/src/event/ngx_event_connect.c +++ b/app/nginx-1.16.1/src/event/ngx_event_connect.c @@ -349,10 +349,20 @@ failed: #if (NGX_HAVE_TRANSPARENT_PROXY) +#if (NGX_HAVE_FSTACK) +extern int is_fstack_fd(int sockfd); +#ifndef IP_BINDANY +#define IP_BINDANY 24 +#endif +#endif + static ngx_int_t ngx_event_connect_set_transparent(ngx_peer_connection_t *pc, ngx_socket_t s) { int value; +#if defined(NGX_HAVE_FSTACK) + int optname; +#endif value = 1; @@ -377,12 +387,17 @@ ngx_event_connect_set_transparent(ngx_peer_connection_t *pc, ngx_socket_t s) FreeBSD define IP_BINDANY in freebsd/netinet/in.h Fstack should only support IP_BINDANY. ****/ - #define IP_BINDANY 24 - if (setsockopt(s, IPPROTO_IP, IP_BINDANY, + if(is_fstack_fd(s)){ + optname = IP_BINDANY; + } else { + optname = IP_TRANSPARENT; + } + + if (setsockopt(s, IPPROTO_IP, optname, (const void *) &value, sizeof(int)) == -1) { ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, - "setsockopt(IP_BINDANY) failed"); + "setsockopt(IP_BINDANY/IP_TRANSPARENT) failed"); return NGX_ERROR; }