[syslog-ng]source socket keepalive patch suggestion

Ted_Rule@flextech.co.uk Ted_Rule@flextech.co.uk
Wed, 11 Sep 2002 11:55:26 +0100


--0__=LyZk5vEu14b3ISvSFdj0lQCzmRIA4vbRuGGCyYVqw46jW8k98UVLgnz3
Content-type: text/plain; charset="us-ascii"
Content-Disposition: inline



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.

***************************************************************************************************


--0__=LyZk5vEu14b3ISvSFdj0lQCzmRIA4vbRuGGCyYVqw46jW8k98UVLgnz3
Content-type: application/octet-stream; 
	name="cfg-grammar.y.1.5.20.diff.gz"
Content-Disposition: attachment; filename="cfg-grammar.y.1.5.20.diff.gz"
Content-transfer-encoding: base64

H4sICD0Zfz0AA2NmZy1ncmFtbWFyLnkuMS41LjIwLmRpZmYAvVbbbtpAEH22v2KEaIDYJr4QkkAb
QagbRQkXAWn6ZrlmQ1HwRWvTJAr59+6uzX1xjZSWiBitZ87MnDk7u4qigPM4VsbYdl0bl1/LWvm0
rKtlH0/GwgMawQAFoGmgXtQMo3ZqgK6quihJEt8tsCPnFxqte2paTVNrhh57NhqgaLoqV0GijzNo
NET4FL0GSPgcRPgSQn+GHWTZjzNv8mKFEUa2awU2CRTuMZx4KLJmoyCDVeQsrSRmBQBbdqHvPBHL
ES1tE3GvbZYkY5u/vF1AUJL0yrmsqSDplQv6pDQJAG/AHgBTOySBY/8RnvxGGL6Aaz+tmGPvisRc
OGLrbNUejTAKQ8sp5rWSchnOAoRlEBVBaH4bdFu35tD6et1vtkt1EKXtRZjDcuHWNHtW8+7mu1mq
Jyk9YoQobD3O8Z2gwlY7/SCa+F4oCMIb5PMk490y6sRR2nGM27F0T/UGgWYkpiqJMVzVZf2cMFw1
5IoWM7yqeDDsm9lL/viKk3wPKFlUTo4hsQcbI3B81/U9+ImiZ4Q8YBzCEcTIcHwiKtxcSRU1bhX8
0kQpLXFS2TbYhkFq1aSueVKblKIHToz192lSIq5z8q2LUloEToDli3nq6CB9o82luymVp8MibGh5
PQQfAgj27YPVfeiYfSgUC1QBE28MhVKB6mqRDwH2nz2Ei7sakyFvkH0dy53+opKbU9Drfve+lw46
xv4sOAi0Z/bbDLNz376iOe9gkrHl7oekGzELawpjjekr5ThZfGqw+p1xEjOstUmcjGK2vBrFObXM
/nIy5E61Sm5zMO9MZjqYD5nM7+z/bn3ZRwublhdn9NA2NC05tNcFyzCXamM9vOu2mne9bn/IFUdM
DHZYM6e+Y08DH0fcjqq0qSDnSMq5PXL5qCiEf06UTHsceCpKGKH0xbxJhl5d0Pd/JLSpoPhQ25ZQ
hqOOpyF6mVpoKJOEDENjEqpUlzeaLLt0+wDg3dCkeMSt8mZ6eEWh56/ksIiQCOIJocCypyTLtEnC
Dof12wT/0vfP4icabzd/WK1up2O2hjfdzmB7OnLgXfvFcnzPQw5rUVqMP6c0cZAGDAAA

--0__=LyZk5vEu14b3ISvSFdj0lQCzmRIA4vbRuGGCyYVqw46jW8k98UVLgnz3--