source socket keepalive patch suggestion
I previously enquired whether it would be possible to allow for a keep-alive option on Unix DGRAM sockets to help avoid the situation on some platforms when daemons such as sendmail have the /dev/log socket 'whipped from under them' during syslog-ng/SIGHUP. It also occurred to me that avoiding closing/re-opening UDP sockets on HUP should help to avoid any loss of messages across HUP on a very busy central syslog server. I assumed - whether this is valid or not I don't know - that the current 1.5.20 source always rebuilds Unix DGRAM sockets on HUP. Likewise for UDP sockets. Having had a look at the YACC source, I think I may have come up with a patch to help with this - it certainly appears to compile and run but it's a bit difficult to test all the possible variations on the theme, and whether it actually fulfils my original requirements. The changes involved in the patch are as follows: Split parsing of Unix DGRAM and STREAM options apart a little more - previously it seems that the Yacc allowed for a max-connections options on a Unix DGRAM socket, even though I don't believe this is actually meaningful(?). The original source also seems to be at variance with the documentation here. Force default keepalive setting on TCP socket. The documentation suggests this is the default, but my reading of the Yacc suggests otherwise. Enable keepalive option on both flavours of DGRAM socket Disable max-connections option on Unix DGRAM socket. Force default keepalive setting on both flavours of DGRAM socket. Could you enlighten me further as to whether this patch actually helps to acheive my original intent. Thanks. diff, gzip of diff , and snippet of cfg-grammar.y before and after attached. Ted ========================================================== $ diff -u cfg-grammar.y.1.5.20.orig cfg-grammar.y.1.5.20.patched --- cfg-grammar.y.1.5.20.orig Wed Sep 11 09:33:53 2002 +++ cfg-grammar.y.1.5.20.patched Wed Sep 11 11:10:32 2002 @@ -120,6 +120,7 @@ %type <ptr> source_afunix_stream_params %type <ptr> source_afinet_udp_params %type <ptr> source_afinet_tcp_params +%type <ptr> source_afsocket_dgram_params %type <ptr> source_afsocket_stream_params %type <ptr> source_afstreams %type <ptr> source_afstreams_params @@ -248,10 +249,10 @@ { last_source_driver = make_afunix_source( &make_unix_address_c($1)->super, - AFSOCKET_DGRAM); + AFSOCKET_DGRAM | AFSOCKET_KEEP_ALIVE); free($1); } - source_afunix_options { $$ = last_source_driver; } + source_afunix_dgram_options { $$ = last_source_driver; } ; source_afunix_stream_params @@ -262,28 +263,41 @@ AFSOCKET_STREAM | AFSOCKET_KEEP_ALIVE); free($1); } - source_afunix_options { $$ = last_source_driver; } + source_afunix_stream_options { $$ = last_source_driver; } ; -/* options are common between dgram & stream */ -source_afunix_options - : source_afunix_option source_afunix_options +source_afunix_stream_options + : source_afunix_stream_option source_afunix_stream_options | ; +source_afunix_dgram_options + : source_afunix_dgram_option source_afunix_dgram_options + | + ; + +source_afunix_dgram_option + : source_afunix_option + | source_afsocket_dgram_params {} + ; + +source_afunix_stream_option + : source_afunix_option + | source_afsocket_stream_params {} + ; + source_afunix_option : KW_OWNER '(' string ')' { afunix_set_owner(last_source_driver, $3); free($3); } | KW_GROUP '(' string ')' { afunix_set_group(last_source_driver, $3); free($3); } | KW_PERM '(' NUMBER ')' { afunix_set_perm(last_source_driver, $3); } - | source_afsocket_stream_params {} - ; + ; source_afinet_udp_params : { last_source_driver = make_afinet_source( &make_inet_address_c("0.0.0.0", "514")->super, - AFSOCKET_DGRAM); + AFSOCKET_DGRAM | AFSOCKET_KEEP_ALIVE); } source_afinet_udp_options { $$ = last_source_driver; } ; @@ -297,6 +311,7 @@ : source_afinet_option | KW_LOCALPORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3 ,"udp"); free($3); } | KW_PORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3, "udp"); free($3); } + | source_afsocket_dgram_params {} ; source_afinet_option @@ -311,7 +326,7 @@ { last_source_driver = make_afinet_source( &make_inet_address_c("0.0.0.0", "514")->super, - AFSOCKET_STREAM); + AFSOCKET_STREAM | AFSOCKET_KEEP_ALIVE); } source_afinet_tcp_options { $$ = last_source_driver; } ; @@ -331,6 +346,10 @@ | source_afsocket_stream_params {} ; +source_afsocket_dgram_params + : KW_KEEP_ALIVE '(' yesno ')' { afsocket_src_set_keep_alive(last_source_driver, $3); } + ; + source_afsocket_stream_params : KW_KEEP_ALIVE '(' yesno ')' { afsocket_src_set_keep_alive(last_source_driver, $3); } | KW_MAX_CONNECTIONS '(' NUMBER ')' { afsocket_src_set_max_connections(last_source_driver, $3); } $ BEFORE: source_afsocket : KW_UNIX_DGRAM '(' source_afunix_dgram_params ')' { $$ = $3; } | KW_UNIX_STREAM '(' source_afunix_stream_params ')' { $$ = $3; } | KW_UDP '(' source_afinet_udp_params ')' { $$ = $3; } | KW_TCP '(' source_afinet_tcp_params ')' { $$ = $3; } ; source_afunix_dgram_params : string { last_source_driver = make_afunix_source( &make_unix_address_c($1)->super, AFSOCKET_DGRAM); free($1); } source_afunix_options { $$ = last_source_driver; } ; source_afunix_stream_params : string { last_source_driver = make_afunix_source( &make_unix_address_c($1)->super, AFSOCKET_STREAM | AFSOCKET_KEEP_ALIVE); free($1); } source_afunix_options { $$ = last_source_driver; } ; /* options are common between dgram & stream */ source_afunix_options : source_afunix_option source_afunix_options | ; source_afunix_option : KW_OWNER '(' string ')' { afunix_set_owner(last_source_driver, $3); free($3); } | KW_GROUP '(' string ')' { afunix_set_group(last_source_driver, $3); free($3); } | KW_PERM '(' NUMBER ')' { afunix_set_perm(last_source_driver, $3); } | source_afsocket_stream_params {} ; source_afinet_udp_params : { last_source_driver = make_afinet_source( &make_inet_address_c("0.0.0.0", "514")->super, AFSOCKET_DGRAM); } source_afinet_udp_options { $$ = last_source_driver; } ; source_afinet_udp_options : source_afinet_udp_option source_afinet_udp_options | ; source_afinet_udp_option : source_afinet_option | KW_LOCALPORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3 ,"udp"); free($3); } : | KW_PORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3, "udp"); free($3); } ; source_afinet_option : KW_LOCALIP '(' string ')' { afinet_src_set_localip(last_source_driver, $3); free($3); } | KW_LOCALPORT '(' NUMBER ')' { afinet_src_set_localport(last_source_driver, $3, NULL, NULL); } | KW_PORT '(' NUMBER ')' { afinet_src_set_localport(last_source_driver, $3, NULL, NULL); } | KW_IP '(' string ')' { afinet_src_set_localip(last_source_driver, $3); free($3); } ; source_afinet_tcp_params : { last_source_driver = make_afinet_source( &make_inet_address_c("0.0.0.0", "514")->super, AFSOCKET_STREAM); } source_afinet_tcp_options { $$ = last_source_driver; } ; source_afinet_tcp_options : source_afinet_tcp_option source_afinet_tcp_options | ; source_afinet_tcp_option : source_afinet_option | KW_LOCALPORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3, "tcp"); free($3); } | KW_PORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3, "tcp"); free($3); } | KW_AUTH '(' tripleoption ')' { afinet_src_set_auth(last_source_driver, $3); } | KW_MAC '(' tripleoption ')' { afinet_src_set_mac(last_source_driver, $3); } | KW_ENCRYPT '(' tripleoption ')' { afinet_src_set_encrypt(last_source_driver, $3); } | source_afsocket_stream_params {} ; source_afsocket_stream_params : KW_KEEP_ALIVE '(' yesno ')' { afsocket_src_set_keep_alive(last_source_driver, $3); } | KW_MAX_CONNECTIONS '(' NUMBER ')' { afsocket_src_set_max_connections(last_source_driver, $3); } ; ================================================================================================ AFTER: source_afsocket : KW_UNIX_DGRAM '(' source_afunix_dgram_params ')' { $$ = $3; } | KW_UNIX_STREAM '(' source_afunix_stream_params ')' { $$ = $3; } | KW_UDP '(' source_afinet_udp_params ')' { $$ = $3; } | KW_TCP '(' source_afinet_tcp_params ')' { $$ = $3; } ; source_afunix_dgram_params : string { last_source_driver = make_afunix_source( &make_unix_address_c($1)->super, AFSOCKET_DGRAM | AFSOCKET_KEEP_ALIVE); free($1); } source_afunix_dgram_options { $$ = last_source_driver; } ; source_afunix_stream_params : string { last_source_driver = make_afunix_source( &make_unix_address_c($1)->super, AFSOCKET_STREAM | AFSOCKET_KEEP_ALIVE); free($1); } source_afunix_stream_options { $$ = last_source_driver; } ; source_afunix_stream_options : source_afunix_stream_option source_afunix_stream_options | ; source_afunix_dgram_options : source_afunix_dgram_option source_afunix_dgram_options | ; source_afunix_dgram_option : source_afunix_option | source_afsocket_dgram_params {} ; source_afunix_stream_option : source_afunix_option | source_afsocket_stream_params {} ; source_afunix_option : KW_OWNER '(' string ')' { afunix_set_owner(last_source_driver, $3); free($3); } | KW_GROUP '(' string ')' { afunix_set_group(last_source_driver, $3); free($3); } | KW_PERM '(' NUMBER ')' { afunix_set_perm(last_source_driver, $3); } ; source_afinet_udp_params : { last_source_driver = make_afinet_source( &make_inet_address_c("0.0.0.0", "514")->super, AFSOCKET_DGRAM | AFSOCKET_KEEP_ALIVE); } source_afinet_udp_options { $$ = last_source_driver; } ; source_afinet_udp_options : source_afinet_udp_option source_afinet_udp_options | ; source_afinet_udp_option : source_afinet_option | KW_LOCALPORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3 ,"udp"); free($3); } | KW_PORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3, "udp"); free($3); } | source_afsocket_dgram_params {} ; source_afinet_option : KW_LOCALIP '(' string ')' { afinet_src_set_localip(last_source_driver, $3); free($3); } | KW_LOCALPORT '(' NUMBER ')' { afinet_src_set_localport(last_source_driver, $3, NULL, NULL); } | KW_PORT '(' NUMBER ')' { afinet_src_set_localport(last_source_driver, $3, NULL, NULL); } | KW_IP '(' string ')' { afinet_src_set_localip(last_source_driver, $3); free($3); } ; source_afinet_tcp_params : { last_source_driver = make_afinet_source( &make_inet_address_c("0.0.0.0", "514")->super, AFSOCKET_STREAM | AFSOCKET_KEEP_ALIVE); } source_afinet_tcp_options { $$ = last_source_driver; } ; source_afinet_tcp_options : source_afinet_tcp_option source_afinet_tcp_options | ; source_afinet_tcp_option : source_afinet_option | KW_LOCALPORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3, "tcp"); free($3); } | KW_PORT '(' string ')' { afinet_src_set_localport(last_source_driver, 0, $3, "tcp"); free($3); } | KW_AUTH '(' tripleoption ')' { afinet_src_set_auth(last_source_driver, $3); } | KW_MAC '(' tripleoption ')' { afinet_src_set_mac(last_source_driver, $3); } | KW_ENCRYPT '(' tripleoption ')' { afinet_src_set_encrypt(last_source_driver, $3); } | source_afsocket_stream_params {} ; source_afsocket_dgram_params : KW_KEEP_ALIVE '(' yesno ')' { afsocket_src_set_keep_alive(last_source_driver, $3); } ; source_afsocket_stream_params : KW_KEEP_ALIVE '(' yesno ')' { afsocket_src_set_keep_alive(last_source_driver, $3); } | KW_MAX_CONNECTIONS '(' NUMBER ')' { afsocket_src_set_max_connections(last_source_driver, $3); } ; (See attached file: cfg-grammar.y.1.5.20.diff.gz) *************************************************************************************************** This E-mail message, including any attachments, is intended only for the person or entity to which it is addressed, and may contain confidential information. If you are not the intended recipient, any review, retransmission, disclosure, copying, modification or other use of this E-mail message or attachments is strictly forbidden. If you have received this E-mail message in error, please contact the author and delete the message and any attachments from your computer. You are also advised that the views and opinions expressed in this E-mail message and any attachments are the author's own, and may not reflect the views and opinions of FLEXTECH Television Limited. ***************************************************************************************************
Ted_Rule@flextech.co.uk writes:
I previously enquired whether it would be possible to allow for a keep-alive option on Unix DGRAM sockets to help avoid the situation on some platforms when daemons such as sendmail have the /dev/log socket 'whipped from under them' during syslog-ng/SIGHUP.
Why not fix the libc code on those platforms so it does basic sanity checking on the socket, and re-opens the socket when it discovers that its cached filehandle for /dev/log is invalid? I encountered this on NetBSD and it was an easy library fix (it's patched in all current releases (1.5.3 and 1.6 candidates) - what OS are you using?
Thanks for your contribution. On Wed, Sep 11, 2002 at 11:55:26AM +0100, Ted_Rule@flextech.co.uk wrote:
I previously enquired whether it would be possible to allow for a keep-alive option on Unix DGRAM sockets to help avoid the situation on some platforms when daemons such as sendmail have the /dev/log socket 'whipped from under them' during syslog-ng/SIGHUP.
It also occurred to me that avoiding closing/re-opening UDP sockets on HUP should help to avoid any loss of messages across HUP on a very busy central syslog server.
I assumed - whether this is valid or not I don't know - that the current 1.5.20 source always rebuilds Unix DGRAM sockets on HUP. Likewise for UDP sockets.
Having had a look at the YACC source, I think I may have come up with a patch to help with this - it certainly appears to compile and run but it's a bit difficult to test all the possible variations on the theme, and whether it actually fulfils my original requirements.
No it doesn't. The keepalive flag is not implemented for unix-dgram sockets.
The changes involved in the patch are as follows:
Split parsing of Unix DGRAM and STREAM options apart a little more - previously it seems that the Yacc allowed for a max-connections options on a Unix DGRAM socket, even though I don't believe this is actually meaningful(?). The original source also seems to be at variance with the documentation here.
Force default keepalive setting on TCP socket. The documentation suggests this is the default, but my reading of the Yacc suggests otherwise.
Enable keepalive option on both flavours of DGRAM socket
I think it is better to use a separate option, like 'keep-socket-alive' or 'keep-listener-alive' as it might be a good idea to enable the same behaviour for stream sockets as well (e.g. not to reopen the socket)
Disable max-connections option on Unix DGRAM socket.
that's fine.
Force default keepalive setting on both flavours of DGRAM socket.
Could you enlighten me further as to whether this patch actually helps to acheive my original intent.
I'm afraid it doesn't. -- Bazsi PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1
participants (3)
-
Balazs Scheidler
-
Ed Ravin
-
Ted_Rule@flextech.co.uk