Re: ngx_http_v3_init_session function
Thanks you On Fri, Feb 9, 2024 at 1:58 PM Roman Arutyunyan wrote: > Hi Gabriel, > > On Wed, Feb 07, 2024 at 03:34:42PM +0200, Clima Gabriel wrote: > > Hello Roman, > > Thank you. Noted about the mailing list. > > > > > > My function will be called from / inline in ngx_http_ssl_servername. > > ngx_http_ssl_servername itself is registered as a SNI TSL extensions > > callback like this: > > > > #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME > > > > if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx, > >ngx_http_ssl_servername) > > == 0) > > { > > ngx_log_error(NGX_LOG_WARN, cf->log, 0, > > "nginx was built with SNI support, however, now it is linked > " > > "dynamically to an OpenSSL library which has no tlsext > support, > > " > > "therefore SNI is not available"); > > } > > > > #endif > > ./src/http/modules/ngx_http_ssl_module.c > > As you see in ngx_http_ssl_servername() code, it already assumes that > c->data > references a ngx_http_connection_t object, so can you. > > > Regards, > > Gabriel > > > > On Wed, Feb 7, 2024 at 11:29 AM Roman Arutyunyan wrote: > > > > > Hi, > > > > > > On Mon, Feb 05, 2024 at 11:24:39PM +0200, Clima Gabriel wrote: > > > > Hello everyone, > > > > > > > > (the code is probably clearer and attached below) > > > > > > Please note that this mailing list is not for development question. > > > We have a separate list nginx-de...@nginx.org for this. > > > > > > > This function modifies what ngx_connection_t->data points to. > > > > ngx_connection_t->data is initially *ngx_http_connection_t. > > > > The *ngx_http_connection_t is assigned to > > > > ngx_http_v3_session_t->http_connection > > > > And the *ngx_http_v3_session_t assigned to ngx_connection_t->data. > > > > > > > > Result: before ngx_connection_t->data is *ngx_http_connection_t > > > >after ngx_connection_t->data is *ngx_http_v3_session_t > > > > > > > > My question is: what is the proper way to find out what c->data is > at any > > > > given time? I need to know this because I'm writing a function which > uses > > > > the ngx_http_connection_t to obtain the hostname of the request, and > it > > > may > > > > be invoked before or after the ngx_http_v3_init_session. > > > > > > There's no way to tell what object is referenced by c->data without > taking > > > context into consideration. Similarly you can't do that for HTTP/1 as > > > well. > > > > > > You need to know what's the current connection stage to tell this. > > > ngx_http_v3_init_session() is called right before initializing QUIC > > > streams for > > > the session. > > > > > > When exactly do you call your function? > > > > > > [..] > > > > > > -- > > > Roman Arutyunyan > > > ___ > > > nginx mailing list > > > nginx@nginx.org > > > https://mailman.nginx.org/mailman/listinfo/nginx > > > > > > ___ > > nginx mailing list > > nginx@nginx.org > > https://mailman.nginx.org/mailman/listinfo/nginx > > > -- > Roman Arutyunyan > ___ > nginx mailing list > nginx@nginx.org > https://mailman.nginx.org/mailman/listinfo/nginx > ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: ngx_http_v3_init_session function
Hi Gabriel, On Wed, Feb 07, 2024 at 03:34:42PM +0200, Clima Gabriel wrote: > Hello Roman, > Thank you. Noted about the mailing list. > > > My function will be called from / inline in ngx_http_ssl_servername. > ngx_http_ssl_servername itself is registered as a SNI TSL extensions > callback like this: > > #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME > > if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx, >ngx_http_ssl_servername) > == 0) > { > ngx_log_error(NGX_LOG_WARN, cf->log, 0, > "nginx was built with SNI support, however, now it is linked " > "dynamically to an OpenSSL library which has no tlsext support, > " > "therefore SNI is not available"); > } > > #endif > ./src/http/modules/ngx_http_ssl_module.c As you see in ngx_http_ssl_servername() code, it already assumes that c->data references a ngx_http_connection_t object, so can you. > Regards, > Gabriel > > On Wed, Feb 7, 2024 at 11:29 AM Roman Arutyunyan wrote: > > > Hi, > > > > On Mon, Feb 05, 2024 at 11:24:39PM +0200, Clima Gabriel wrote: > > > Hello everyone, > > > > > > (the code is probably clearer and attached below) > > > > Please note that this mailing list is not for development question. > > We have a separate list nginx-de...@nginx.org for this. > > > > > This function modifies what ngx_connection_t->data points to. > > > ngx_connection_t->data is initially *ngx_http_connection_t. > > > The *ngx_http_connection_t is assigned to > > > ngx_http_v3_session_t->http_connection > > > And the *ngx_http_v3_session_t assigned to ngx_connection_t->data. > > > > > > Result: before ngx_connection_t->data is *ngx_http_connection_t > > >after ngx_connection_t->data is *ngx_http_v3_session_t > > > > > > My question is: what is the proper way to find out what c->data is at any > > > given time? I need to know this because I'm writing a function which uses > > > the ngx_http_connection_t to obtain the hostname of the request, and it > > may > > > be invoked before or after the ngx_http_v3_init_session. > > > > There's no way to tell what object is referenced by c->data without taking > > context into consideration. Similarly you can't do that for HTTP/1 as > > well. > > > > You need to know what's the current connection stage to tell this. > > ngx_http_v3_init_session() is called right before initializing QUIC > > streams for > > the session. > > > > When exactly do you call your function? > > > > [..] > > > > -- > > Roman Arutyunyan > > ___ > > nginx mailing list > > nginx@nginx.org > > https://mailman.nginx.org/mailman/listinfo/nginx > > > ___ > nginx mailing list > nginx@nginx.org > https://mailman.nginx.org/mailman/listinfo/nginx -- Roman Arutyunyan ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: ngx_http_v3_init_session function
Hello Roman, Thank you. Noted about the mailing list. My function will be called from / inline in ngx_http_ssl_servername. ngx_http_ssl_servername itself is registered as a SNI TSL extensions callback like this: #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME if (SSL_CTX_set_tlsext_servername_callback(conf->ssl.ctx, ngx_http_ssl_servername) == 0) { ngx_log_error(NGX_LOG_WARN, cf->log, 0, "nginx was built with SNI support, however, now it is linked " "dynamically to an OpenSSL library which has no tlsext support, " "therefore SNI is not available"); } #endif ./src/http/modules/ngx_http_ssl_module.c Regards, Gabriel On Wed, Feb 7, 2024 at 11:29 AM Roman Arutyunyan wrote: > Hi, > > On Mon, Feb 05, 2024 at 11:24:39PM +0200, Clima Gabriel wrote: > > Hello everyone, > > > > (the code is probably clearer and attached below) > > Please note that this mailing list is not for development question. > We have a separate list nginx-de...@nginx.org for this. > > > This function modifies what ngx_connection_t->data points to. > > ngx_connection_t->data is initially *ngx_http_connection_t. > > The *ngx_http_connection_t is assigned to > > ngx_http_v3_session_t->http_connection > > And the *ngx_http_v3_session_t assigned to ngx_connection_t->data. > > > > Result: before ngx_connection_t->data is *ngx_http_connection_t > >after ngx_connection_t->data is *ngx_http_v3_session_t > > > > My question is: what is the proper way to find out what c->data is at any > > given time? I need to know this because I'm writing a function which uses > > the ngx_http_connection_t to obtain the hostname of the request, and it > may > > be invoked before or after the ngx_http_v3_init_session. > > There's no way to tell what object is referenced by c->data without taking > context into consideration. Similarly you can't do that for HTTP/1 as > well. > > You need to know what's the current connection stage to tell this. > ngx_http_v3_init_session() is called right before initializing QUIC > streams for > the session. > > When exactly do you call your function? > > [..] > > -- > Roman Arutyunyan > ___ > nginx mailing list > nginx@nginx.org > https://mailman.nginx.org/mailman/listinfo/nginx > ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: ngx_http_v3_init_session function
Hi, On Mon, Feb 05, 2024 at 11:24:39PM +0200, Clima Gabriel wrote: > Hello everyone, > > (the code is probably clearer and attached below) Please note that this mailing list is not for development question. We have a separate list nginx-de...@nginx.org for this. > This function modifies what ngx_connection_t->data points to. > ngx_connection_t->data is initially *ngx_http_connection_t. > The *ngx_http_connection_t is assigned to > ngx_http_v3_session_t->http_connection > And the *ngx_http_v3_session_t assigned to ngx_connection_t->data. > > Result: before ngx_connection_t->data is *ngx_http_connection_t >after ngx_connection_t->data is *ngx_http_v3_session_t > > My question is: what is the proper way to find out what c->data is at any > given time? I need to know this because I'm writing a function which uses > the ngx_http_connection_t to obtain the hostname of the request, and it may > be invoked before or after the ngx_http_v3_init_session. There's no way to tell what object is referenced by c->data without taking context into consideration. Similarly you can't do that for HTTP/1 as well. You need to know what's the current connection stage to tell this. ngx_http_v3_init_session() is called right before initializing QUIC streams for the session. When exactly do you call your function? [..] -- Roman Arutyunyan ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: ngx_http_v3_init_session function
On Tue, 6 Feb 2024 00:44:56 + J Carter wrote: > On Tue, 6 Feb 2024 00:16:31 + > J Carter wrote: > > > Hello, > > > > On Mon, 5 Feb 2024 23:24:39 +0200 > > Clima Gabriel wrote: > > > > > Hello everyone, > > > > > > (the code is probably clearer and attached below) > > > This function modifies what ngx_connection_t->data points to. > > > ngx_connection_t->data is initially *ngx_http_connection_t. > > > The *ngx_http_connection_t is assigned to > > > ngx_http_v3_session_t->http_connection > > > And the *ngx_http_v3_session_t assigned to ngx_connection_t->data. > > > > > > Result: before ngx_connection_t->data is *ngx_http_connection_t > > >after ngx_connection_t->data is *ngx_http_v3_session_t > > > > In C, a pointer to struct can be cast to a pointer to the first member > > of that struct, as there is no padding before the first member per the > > standard. > > > > The first member of ngx_http_v3_session_t is *ngx_http_connection_t. > > *Sorry typo here - first member is ngx_http_connection_t of course. > > > > Here is the commit where this was implemented. > > > > https://mailman.nginx.org/pipermail/nginx-devel/2023-September/BWH23FTMRUWCUZSNKXJJXEEN76ZYOK62.html > > > > [...] Oh, I've just realized that is the wrong patch. There were a couple of reworks to that patch later that I missed.. Here is the actual changeset version, with *ngx_http_connection_t as you say: https://hg.nginx.org/nginx/rev/4939fd04737f It appears that this macro should be used to get ngx_http_connection_t: https://hg.nginx.org/nginx/file/tip/src/http/v3/ngx_http_v3.h#l85 However it's likely a good idea to wait to see if the author/s will comment on if that is safe and correct in all situations. ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: ngx_http_v3_init_session function
On Tue, 6 Feb 2024 00:16:31 + J Carter wrote: > Hello, > > On Mon, 5 Feb 2024 23:24:39 +0200 > Clima Gabriel wrote: > > > Hello everyone, > > > > (the code is probably clearer and attached below) > > This function modifies what ngx_connection_t->data points to. > > ngx_connection_t->data is initially *ngx_http_connection_t. > > The *ngx_http_connection_t is assigned to > > ngx_http_v3_session_t->http_connection > > And the *ngx_http_v3_session_t assigned to ngx_connection_t->data. > > > > Result: before ngx_connection_t->data is *ngx_http_connection_t > >after ngx_connection_t->data is *ngx_http_v3_session_t > > In C, a pointer to struct can be cast to a pointer to the first member > of that struct, as there is no padding before the first member per the > standard. > > The first member of ngx_http_v3_session_t is *ngx_http_connection_t. *Sorry typo here - first member is ngx_http_connection_t of course. > > Here is the commit where this was implemented. > > https://mailman.nginx.org/pipermail/nginx-devel/2023-September/BWH23FTMRUWCUZSNKXJJXEEN76ZYOK62.html > > [...] ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
Re: ngx_http_v3_init_session function
Hello, On Mon, 5 Feb 2024 23:24:39 +0200 Clima Gabriel wrote: > Hello everyone, > > (the code is probably clearer and attached below) > This function modifies what ngx_connection_t->data points to. > ngx_connection_t->data is initially *ngx_http_connection_t. > The *ngx_http_connection_t is assigned to > ngx_http_v3_session_t->http_connection > And the *ngx_http_v3_session_t assigned to ngx_connection_t->data. > > Result: before ngx_connection_t->data is *ngx_http_connection_t >after ngx_connection_t->data is *ngx_http_v3_session_t In C, a pointer to struct can be cast to a pointer to the first member of that struct, as there is no padding before the first member per the standard. The first member of ngx_http_v3_session_t is *ngx_http_connection_t. Here is the commit where this was implemented. https://mailman.nginx.org/pipermail/nginx-devel/2023-September/BWH23FTMRUWCUZSNKXJJXEEN76ZYOK62.html [...] ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx
ngx_http_v3_init_session function
Hello everyone, (the code is probably clearer and attached below) This function modifies what ngx_connection_t->data points to. ngx_connection_t->data is initially *ngx_http_connection_t. The *ngx_http_connection_t is assigned to ngx_http_v3_session_t->http_connection And the *ngx_http_v3_session_t assigned to ngx_connection_t->data. Result: before ngx_connection_t->data is *ngx_http_connection_t after ngx_connection_t->data is *ngx_http_v3_session_t My question is: what is the proper way to find out what c->data is at any given time? I need to know this because I'm writing a function which uses the ngx_http_connection_t to obtain the hostname of the request, and it may be invoked before or after the ngx_http_v3_init_session. ngx_int_t ngx_http_v3_init_session(ngx_connection_t *c) { ngx_pool_cleanup_t *cln; ngx_http_connection_t *hc; ngx_http_v3_session_t *h3c; hc = c->data; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init session"); h3c = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_session_t)); if (h3c == NULL) { goto failed; } h3c->http_connection = hc; ngx_queue_init(&h3c->blocked); h3c->keepalive.log = c->log; h3c->keepalive.data = c; h3c->keepalive.handler = ngx_http_v3_keepalive_handler; h3c->table.send_insert_count.log = c->log; h3c->table.send_insert_count.data = c; h3c->table.send_insert_count.handler = ngx_http_v3_inc_insert_count_handler; cln = ngx_pool_cleanup_add(c->pool, 0); if (cln == NULL) { goto failed; } cln->handler = ngx_http_v3_cleanup_session; cln->data = h3c; c->data = h3c; return NGX_OK; failed: ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to create http3 session"); return NGX_ERROR; } Regards, Gabriel ___ nginx mailing list nginx@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx