pls. help for adding another parameter to ngx_upstream_server

moto kawasaki moto at
Tue Nov 26 09:37:59 UTC 2013


I am the questioner about setfib feature on the upstream side.
And I am back for asking you comments/suggestions/help.
Thank you very much in advance.

Please refer the following URL for the conversation before.,244686 

mdounin> Well, as far as I can tell there is no reasons to do per-server 
mdounin> setfib in this usecase, and 
mdounin>     proxy_setfib N;
mdounin> should be enough.  It should be much easier to implement than what 
mdounin> you are trying to do in your patch.

Thank you very much, Mr. Dounin, I followed your advice.

Now, I am refering src/http/modules/ngx_http_upstream_keepalive_module.c, 
and create a new module "ngx_http_upstream_proxy_setfib_module.c".

With this module, I can write "setfib N" in nginx.conf like;

  http {
        upstream UPSTREAM {
                proxy_setfib 5;
                server max_fails=3 fail_timeout=300;

And also I can create server config for this module, and the config
"proxy_setfib 5" can be read and set into server config.

Now, I want to do setsockopt(2) with SO_SETFIB, so that I can make a
connection to upstream (contents) server with a given fib number (5 in
above case).

But I am lost in the nginx architecture, so please advice me in which
function should I call setsockopt() ??

My incomplete understandings are:

  - I need to override ngx_event_connect_peer(), since this function
    has socket(), setsockopt(SO_RCVBUF), and bind().
    I cannot find any hook/callback point between socket() and bind().

  - ngx_event_connect_peer() is called from ngx_http_upstream_connect() 
    etc. but I don't understand when and by which function it is

  - seeing keepalive module, the initialization chain is connected:

     -> ngx_http_upstream_init_keepalive()
     -> ngx_http_upstream_init_keepalive_peer()
     -> ngx_http_upstream_init_get_keepalive_peer()
     -> ...

   But I could not find any place on that chain which might call
   ngx_http_upstream_connect() so far.

I am embarrassed to ask such basic questions but any
comments/suggestions are really appreciated.

I've attached my module source code, configure option, and nginx.conf.
I am running them on FreeBSD 9.2-RELEASE (amd64), and nginx version is

Thank you very much.

Best Regards,

moto kawasaki <moto at>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setfib_module.tar.gz
Type: application/octet-stream
Size: 2056 bytes
Desc: not available
URL: <>

More information about the nginx-devel mailing list