Ticket #287: nginx-1.13.6.2-listen-transparent.patch

File nginx-1.13.6.2-listen-transparent.patch, 9.3 KB (added by James Callahan, 8 years ago)
  • bundle/nginx-1.13.6/src/core/ngx_connection.c

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/core/ngx_connection.c ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/core/ngx_connection.c
    old new  
    501501            }
    502502#endif
    503503
     504#if (NGX_HAVE_TRANSPARENT_PROXY && __linux)
     505            /* Don't need to set on FreeBSD or OSX */
     506
     507            if (ls[i].transparent && !ngx_test_config) {
     508
     509                int transparent = 1;
     510
     511                switch (ls[i].sockaddr->sa_family) {
     512
     513                case AF_INET:
     514
     515                    if (setsockopt(s, IPPROTO_IP, IP_TRANSPARENT,
     516                                   (const void *) &transparent, sizeof(int)) == -1)
     517                    {
     518                        ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
     519                                      "setsockopt(IP_TRANSPARENT) %V failed",
     520                                      &ls[i].addr_text);
     521                        return NGX_ERROR;
     522                    }
     523
     524                    break;
     525
     526#if (NGX_HAVE_INET6)
     527
     528                case AF_INET6:
     529
     530                    if (setsockopt(s, IPPROTO_IPV6, IPV6_TRANSPARENT,
     531                                   (const void *) &transparent, sizeof(int)) == -1)
     532                    {
     533                        ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
     534                                      "setsockopt(IPV6_TRANSPARENT) %V failed",
     535                                      &ls[i].addr_text);
     536                        return NGX_ERROR;
     537                    }
     538
     539                    break;
     540
     541#endif /* NGX_HAVE_INET6 */
     542
     543                }
     544            }
     545#endif /* NGX_HAVE_TRANSPARENT_PROXY */
     546
    504547#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
    505548
    506549            if (ls[i].sockaddr->sa_family == AF_INET6) {
  • bundle/nginx-1.13.6/src/core/ngx_connection.h

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/core/ngx_connection.h ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/core/ngx_connection.h
    old new  
    7171#endif
    7272    unsigned            reuseport:1;
    7373    unsigned            add_reuseport:1;
     74
     75#if (NGX_HAVE_TRANSPARENT_PROXY)
     76    unsigned            transparent:1;
     77#endif
    7478    unsigned            keepalive:2;
    7579
    7680    unsigned            deferred_accept:1;
  • bundle/nginx-1.13.6/src/event/ngx_event_accept.c

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/event/ngx_event_accept.c ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/event/ngx_event_accept.c
    old new  
    232232        c->local_sockaddr = ls->sockaddr;
    233233        c->local_socklen = ls->socklen;
    234234
     235#if (NGX_HAVE_TRANSPARENT_PROXY)
     236        if (ls->transparent) {
     237            c->local_sockaddr = NULL;
     238            c->local_socklen = 0;
     239        }
     240#endif
     241
    235242#if (NGX_HAVE_UNIX_DOMAIN)
    236243        if (c->sockaddr->sa_family == AF_UNIX) {
    237244            c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
  • bundle/nginx-1.13.6/src/http/ngx_http.c

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/http/ngx_http.c ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/http/ngx_http.c
    old new  
    17761776    ls->reuseport = addr->opt.reuseport;
    17771777#endif
    17781778
     1779#if (NGX_HAVE_TRANSPARENT_PROXY)
     1780    ls->transparent = addr->opt.transparent;
     1781#endif
     1782
    17791783    return ls;
    17801784}
    17811785
  • bundle/nginx-1.13.6/src/http/ngx_http_core_module.c

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/http/ngx_http_core_module.c ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/http/ngx_http_core_module.c
    old new  
    39523952            continue;
    39533953        }
    39543954
     3955        if (ngx_strcmp(value[n].data, "transparent") == 0) {
     3956#if (NGX_HAVE_TRANSPARENT_PROXY)
     3957            lsopt.transparent = 1;
     3958            continue;
     3959#else
     3960            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
     3961                               "transparent is not supported "
     3962                               "on this platform");
     3963            return NGX_CONF_ERROR;
     3964#endif
     3965        }
     3966
    39553967        if (ngx_strcmp(value[n].data, "ssl") == 0) {
    39563968#if (NGX_HTTP_SSL)
    39573969            lsopt.ssl = 1;
  • bundle/nginx-1.13.6/src/http/ngx_http_core_module.h

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/http/ngx_http_core_module.h ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/http/ngx_http_core_module.h
    old new  
    7979#endif
    8080    unsigned                   deferred_accept:1;
    8181    unsigned                   reuseport:1;
     82#if (NGX_HAVE_TRANSPARENT_PROXY)
     83    unsigned                   transparent:1;
     84#endif
    8285    unsigned                   so_keepalive:2;
    8386    unsigned                   proxy_protocol:1;
    8487
  • bundle/nginx-1.13.6/src/http/ngx_http_request.c

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/http/ngx_http_request.c ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/http/ngx_http_request.c
    old new  
    226226
    227227    port = c->listening->servers;
    228228
    229     if (port->naddrs > 1) {
     229    if (port->naddrs > 1
     230#if (NGX_HAVE_TRANSPARENT_PROXY)
     231        || c->listening->transparent
     232#endif
     233    ) {
    230234
    231235        /*
    232236         * there are several addresses on this port and one of them
  • bundle/nginx-1.13.6/src/stream/ngx_stream.c

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/stream/ngx_stream.c ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/stream/ngx_stream.c
    old new  
    513513#if (NGX_HAVE_REUSEPORT)
    514514            ls->reuseport = addr[i].opt.reuseport;
    515515#endif
     516#if (NGX_HAVE_TRANSPARENT_PROXY)
     517            ls->transparent = addr[i].opt.transparent;
     518#endif
    516519
    517520            stport = ngx_palloc(cf->pool, sizeof(ngx_stream_port_t));
    518521            if (stport == NULL) {
  • bundle/nginx-1.13.6/src/stream/ngx_stream_core_module.c

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/stream/ngx_stream_core_module.c ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/stream/ngx_stream_core_module.c
    old new  
    732732            continue;
    733733        }
    734734
     735        if (ngx_strcmp(value[i].data, "transparent") == 0) {
     736#if (NGX_HAVE_TRANSPARENT_PROXY)
     737            ls->transparent = 1;
     738            continue;
     739#else
     740            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
     741                               "transparent is not supported "
     742                               "on this platform");
     743            return NGX_CONF_ERROR;
     744#endif
     745        }
     746
    735747        if (ngx_strcmp(value[i].data, "ssl") == 0) {
    736748#if (NGX_STREAM_SSL)
    737749            ls->ssl = 1;
  • bundle/nginx-1.13.6/src/stream/ngx_stream.h

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/stream/ngx_stream.h ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/stream/ngx_stream.h
    old new  
    5555    unsigned                       ipv6only:1;
    5656#endif
    5757    unsigned                       reuseport:1;
     58#if (NGX_HAVE_TRANSPARENT_PROXY)
     59    unsigned                       transparent:1;
     60#endif
    5861    unsigned                       so_keepalive:2;
    5962    unsigned                       proxy_protocol:1;
    6063#if (NGX_HAVE_KEEPALIVE_TUNABLE)
  • bundle/nginx-1.13.6/src/stream/ngx_stream_handler.c

    diff -ru ../openresty-1.13.6.2-patched/bundle/nginx-1.13.6/src/stream/ngx_stream_handler.c ../openresty-1.13.6.2-modified/bundle/nginx-1.13.6/src/stream/ngx_stream_handler.c
    old new  
    4242
    4343    port = c->listening->servers;
    4444
    45     if (port->naddrs > 1) {
     45    if (port->naddrs > 1
     46#if (NGX_HAVE_TRANSPARENT_PROXY)
     47        || c->listening->transparent
     48#endif
     49    ) {
    4650
    4751        /*
    4852         * There are several addresses on this port and one of them