[syslog-ng] Localport() & localip() now working after patch

Balazs Scheidler bazsi at balabit.hu
Wed Apr 4 16:45:39 CEST 2007


On Tue, 2007-04-03 at 15:15 -0500, simonst at wellsfargo.com wrote:
> The patch for localip() & localport() worked - thanks!  Here's those parms
> in my working syslog-ng.conf:
> # sed -n '/localip/,/}/p' /etc/syslog-ng/syslog-ng.conf
> destination logger1 { tcp("10.11.12.13" port(5295) localip(10.9.8.7)
> localport(syslog-ng)
>                           template("$UNIXTIME $HOST $MESSAGE\n") ); };
> destination logger2 { tcp("10.21.22.23" port(5295) localip(10.9.8.7)
> localport(syslog-ng)
>                           template("$UNIXTIME $HOST $MESSAGE\n") ); };
> 
> It's not a big deal to me, but it got errors (or warnings?) when I coded a
> numeric port in localport():
> # sed -n '/localip/,/}/p' syslog-ng.conf_NUMERIC
> destination logger1 { tcp("10.11.12.13" port(5295) localip(10.9.8.7)
> localport(5295)
>                           template("$UNIXTIME $HOST $MESSAGE\n") ); };
> destination logger2 { tcp("10.21.22.23" port(5295) localip(10.9.8.7)
> localport(5295)
>                           template("$UNIXTIME $HOST $MESSAGE\n") ); };
> # syslog-ng -dFsf syslog-ng.conf_NUMERIC
> Error finding port number, falling back to default; service='tcp/5295'
> Error finding port number, falling back to default; service='tcp/5295'

hm.. this is still a problem, this patch should fix it finally.

--- orig/src/afinet.c
+++ mod/src/afinet.c
@@ -41,14 +41,20 @@
 
 
 static void
-afinet_set_port(GSockAddr *addr, gint port, gchar *service, gchar *proto)
+afinet_set_port(GSockAddr *addr, gchar *service, gchar *proto)
 {
   if (addr)
     {
-      if (proto)
+      gchar *end;
+      gint port;
+      
+      /* check if service is numeric */
+      port = strtol(service, &end, 10);
+      if ((*end != 0))
         {
           struct servent *se;
           
+          /* service is not numeric, check if it's a service in /etc/services */
           se = getservbyname(service, proto);
           if (se)
             {
@@ -218,11 +224,11 @@ afinet_setup_socket(gint fd, GSockAddr *
 }
 
 void 
-afinet_sd_set_localport(LogDriver *s, gint port, gchar *service, gchar *proto)
+afinet_sd_set_localport(LogDriver *s, gchar *service, gchar *proto)
 {
   AFSocketSourceDriver *self = (AFSocketSourceDriver *) s;
   
-  afinet_set_port(self->bind_addr, port, service, proto);
+  afinet_set_port(self->bind_addr, service, proto);
 }
 
 void 
@@ -271,19 +277,19 @@ afinet_sd_new(gint af, gchar *host, gint
 /* afinet destination */
 
 void 
-afinet_dd_set_localport(LogDriver *s, gint port, gchar *service, gchar *proto)
+afinet_dd_set_localport(LogDriver *s, gchar *service, gchar *proto)
 {
   AFInetDestDriver *self = (AFInetDestDriver *) s;
   
-  afinet_set_port(self->super.bind_addr, port, service, proto);
+  afinet_set_port(self->super.bind_addr, service, proto);
 }
 
 void 
-afinet_dd_set_destport(LogDriver *s, gint port, gchar *service, gchar *proto)
+afinet_dd_set_destport(LogDriver *s, gchar *service, gchar *proto)
 {
   AFInetDestDriver *self = (AFInetDestDriver *) s;
   
-  afinet_set_port(self->super.dest_addr, port, service, proto);
+  afinet_set_port(self->super.dest_addr, service, proto);
 }
 
 void 


--- orig/src/afinet.h
+++ mod/src/afinet.h
@@ -45,7 +45,7 @@ typedef struct _AFInetSourceDriver
 } AFInetSourceDriver;
 
 LogDriver *afinet_sd_new(gint af, gchar *host, gint port, guint flags);
-void afinet_sd_set_localport(LogDriver *self, gint port, gchar *service, gchar *proto);
+void afinet_sd_set_localport(LogDriver *self, gchar *service, gchar *proto);
 void afinet_sd_set_localip(LogDriver *self, gchar *ip);
 
 #define afinet_sd_set_auth(a,b)
@@ -63,8 +63,8 @@ typedef struct _AFInetDestDriver
 } AFInetDestDriver;
 
 LogDriver *afinet_dd_new(gint af, gchar *host, gint port, guint flags);
-void afinet_dd_set_localport(LogDriver *self, gint port, gchar *service, gchar *proto);
-void afinet_dd_set_destport(LogDriver *self, gint port, gchar *service, gchar *proto);
+void afinet_dd_set_localport(LogDriver *self, gchar *service, gchar *proto);
+void afinet_dd_set_destport(LogDriver *self, gchar *service, gchar *proto);
 void afinet_dd_set_localip(LogDriver *self, gchar *ip);
 void afinet_dd_set_sync_freq(LogDriver *self, gint sync_freq);
 void afinet_dd_set_spoof_source(LogDriver *self, gboolean enable);


--- orig/src/cfg-grammar.y
+++ mod/src/cfg-grammar.y
@@ -375,8 +375,8 @@ source_afinet_udp_options
 
 source_afinet_udp_option
        : source_afinet_option
-       | KW_LOCALPORT '(' string_or_number ')' { afinet_sd_set_localport(last_driver, 0, $3, "udp"); free($3); }
-       | KW_PORT '(' string_or_number ')'      { afinet_sd_set_localport(last_driver, 0, $3, "udp"); free($3); }
+       | KW_LOCALPORT '(' string_or_number ')' { afinet_sd_set_localport(last_driver, $3, "udp"); free($3); }
+       | KW_PORT '(' string_or_number ')'      { afinet_sd_set_localport(last_driver, $3, "udp"); free($3); }
        ;
 
 source_afinet_option
@@ -405,8 +405,8 @@ source_afinet_tcp_options
 
 source_afinet_tcp_option
         : source_afinet_option
-       | KW_LOCALPORT '(' string_or_number ')' { afinet_sd_set_localport(last_driver, 0, $3, "tcp"); free($3); }
-       | KW_PORT '(' string_or_number ')'      { afinet_sd_set_localport(last_driver, 0, $3, "tcp"); free($3); }
+       | KW_LOCALPORT '(' string_or_number ')' { afinet_sd_set_localport(last_driver, $3, "tcp"); free($3); }
+       | KW_PORT '(' string_or_number ')'      { afinet_sd_set_localport(last_driver, $3, "tcp"); free($3); }
        | source_afsocket_stream_params         {}
        ;
 
@@ -606,9 +606,9 @@ dest_afinet_option
 
 dest_afinet_udp_option
        : dest_afinet_option
-       | KW_LOCALPORT '(' string_or_number ')' { afinet_dd_set_localport(last_driver, 0, $3, "udp"); free($3); }
-       | KW_PORT '(' string_or_number ')'      { afinet_dd_set_destport(last_driver, 0, $3, "udp"); free($3); }
-       | KW_DESTPORT '(' string_or_number ')'  { afinet_dd_set_destport(last_driver, 0, $3, "udp"); free($3); }
+       | KW_LOCALPORT '(' string_or_number ')' { afinet_dd_set_localport(last_driver, $3, "udp"); free($3); }
+       | KW_PORT '(' string_or_number ')'      { afinet_dd_set_destport(last_driver, $3, "udp"); free($3); }
+       | KW_DESTPORT '(' string_or_number ')'  { afinet_dd_set_destport(last_driver, $3, "udp"); free($3); }
        | KW_SPOOF_SOURCE '(' yesno ')'         { afinet_dd_set_spoof_source(last_driver, $3); }
        ;
 
@@ -632,9 +632,9 @@ dest_afinet_tcp_options
 
 dest_afinet_tcp_option
        : dest_afinet_option
-       | KW_LOCALPORT '(' string_or_number ')' { afinet_dd_set_localport(last_driver, 0, $3, "tcp"); free($3); }
-       | KW_PORT '(' string_or_number ')'      { afinet_dd_set_destport(last_driver, 0, $3, "tcp"); free($3); }
-       | KW_DESTPORT '(' string_or_number ')'  { afinet_dd_set_destport(last_driver, 0, $3, "tcp"); free($3); }
+       | KW_LOCALPORT '(' string_or_number ')' { afinet_dd_set_localport(last_driver, $3, "tcp"); free($3); }
+       | KW_PORT '(' string_or_number ')'      { afinet_dd_set_destport(last_driver, $3, "tcp"); free($3); }
+       | KW_DESTPORT '(' string_or_number ')'  { afinet_dd_set_destport(last_driver, $3, "tcp"); free($3); }
 /*
        | KW_MAC '(' yesno ')'
        | KW_AUTH '(' yesno ')'




-- 
Bazsi



More information about the syslog-ng mailing list