pls. help for adding another parameter to ngx_upstream_server

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


Hello,

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.
http://forum.nginx.org/read.php?29,244686 

mdounin> Well, as far as I can tell there is no reasons to do per-server 
mdounin> setfib in this usecase, and 
mdounin> 
mdounin>     proxy_setfib N;
mdounin> 
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 {
        (snip)
        upstream UPSTREAM {
                proxy_setfib 5;
                server 10.200.195.70:80 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().

    http://lxr.evanmiller.org/http/source/event/ngx_event_connect.c#L15

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

  - seeing keepalive module, the initialization chain is connected:

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

    http://lxr.evanmiller.org/http/source/http/ngx_http_upstream.c#L1132

   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
1.4.3.

Thank you very much.





Best Regards,


-- 
moto kawasaki <moto at kawasaki3.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setfib_module.tar.gz
Type: application/octet-stream
Size: 2056 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20131126/361edf51/attachment.obj>


More information about the nginx-devel mailing list