Skip to content

Commit

Permalink
network(): added new network source and destination drivers
Browse files Browse the repository at this point in the history
This patch implements both source and destination drivers called
"network()", which encapsulates the previous tcp() and udp() drivers. The
advantage of using network() over tcp/udp is that it separates the message
format from the transport being used.

The transport can be specified using the transport() parameter (akin to
syslog()), the newly introduced plugin support for pluggable transport
mechanisms become available this way.

The message format defaults to traditional BSD syslog, but can
completely be customized using the template() option.

Here's a sample network source:

source s_network {
	network(port(2000) transport(udp));
};

Destination:

destination d_network {
	network("hostname" port(2000) transport(framed));
};

As you can see it is possible to use the new-style RFC5425 framing with
whatever (e.g. BSD or custom template formatted) message contents.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
  • Loading branch information
bazsi committed Dec 2, 2012
1 parent 5275d8b commit 5a80e09
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 16 deletions.
6 changes: 5 additions & 1 deletion modules/afsocket/afinet-dest.c
Expand Up @@ -535,6 +535,10 @@ afsyslog_dd_new(gchar *host)
return &self->super.super.super;
}

self->super.syslog_protocol = TRUE;
LogDriver *
afnetwork_dd_new(gchar *host)
{
AFInetDestDriver *self = afinet_dd_new_instance(AF_INET, SOCK_STREAM, host);

return &self->super.super.super;
}
1 change: 1 addition & 0 deletions modules/afsocket/afinet-dest.h
Expand Up @@ -61,5 +61,6 @@ void afinet_dd_set_spoof_source(LogDriver *self, gboolean enable);

LogDriver *afinet_dd_new(gint af, gint sock_type, gchar *host);
LogDriver *afsyslog_dd_new(gchar *host);
LogDriver *afnetwork_dd_new(gchar *host);

#endif
8 changes: 8 additions & 0 deletions modules/afsocket/afinet-source.c
Expand Up @@ -252,3 +252,11 @@ afsyslog_sd_new(void)
self->super.syslog_protocol = TRUE;
return &self->super.super.super;
}

LogDriver *
afnetwork_sd_new(void)
{
AFInetSourceDriver *self = afinet_sd_new_instance(AF_INET, SOCK_STREAM);

return &self->super.super.super;
}
1 change: 1 addition & 0 deletions modules/afsocket/afinet-source.h
Expand Up @@ -39,6 +39,7 @@ typedef struct _AFInetSourceDriver

LogDriver *afinet_sd_new(gint af, gint sock_type);
LogDriver *afsyslog_sd_new(void);
LogDriver *afnetwork_sd_new(void);

void afinet_sd_set_localport(LogDriver *self, gchar *service);
void afinet_sd_set_localip(LogDriver *self, gchar *ip);
Expand Down
67 changes: 52 additions & 15 deletions modules/afsocket/afsocket-grammar.ym
Expand Up @@ -290,6 +290,32 @@ source_afsyslog_option
| source_afsocket_stream_params {}
;

source_afnetwork
: KW_NETWORK '(' source_afnetwork_params ')' { $$ = $3; }
;

source_afnetwork_params
:
{
/* we use transport(tcp) transport by default */
last_driver = *instance = afnetwork_sd_new();
last_reader_options = &((AFSocketSourceDriver *) last_driver)->reader_options;
last_sock_options = &((AFInetSourceDriver *) last_driver)->sock_options.super;
}
source_afnetwork_options { $$ = last_driver; }
;

source_afnetwork_options
: source_afnetwork_option source_afnetwork_options
|
;

source_afnetwork_option
: source_afinet_option
| source_afsocket_transport
| source_afsocket_stream_params {}
;

source_afsocket_transport
: KW_TRANSPORT '(' string ')' { afsocket_sd_set_transport(last_driver, $3); free($3); }
| KW_TRANSPORT '(' KW_TCP ')' { afsocket_sd_set_transport(last_driver, "tcp"); }
Expand All @@ -307,13 +333,6 @@ source_afsocket_transport
afsocket_sd_set_tls_context(last_driver, last_tls_context);
#endif
}

source_afnetwork
: KW_NETWORK { last_addr_family = AF_INET; } '(' source_afnetwork_params ')' { $$ = $4; }
;

source_afnetwork_params
: source_afsyslog_params { $$ = $1; }
;


Expand Down Expand Up @@ -455,7 +474,32 @@ dest_afsyslog_options

dest_afsyslog_option
: dest_afinet_option
: dest_afsocket_transport
| dest_afsocket_transport
;

dest_afnetwork
: KW_NETWORK '(' dest_afnetwork_params ')' { $$ = $3; }
;

dest_afnetwork_params
: string
{
last_driver = *instance = afnetwork_dd_new($1);
last_writer_options = &((AFSocketDestDriver *) last_driver)->writer_options;
last_sock_options = &((AFInetDestDriver *) last_driver)->sock_options.super;
free($1);
}
dest_afnetwork_options { $$ = last_driver; }
;

dest_afnetwork_options
: dest_afnetwork_options dest_afnetwork_option
|
;

dest_afnetwork_option
: dest_afinet_option
| dest_afsocket_transport
;

dest_afsocket_transport
Expand All @@ -478,13 +522,6 @@ dest_afsocket_transport
}
;

dest_afnetwork
: KW_NETWORK { last_addr_family = AF_INET; } '(' dest_afnetwork_params ')' { $$ = $4; }
;

dest_afnetwork_params
: dest_afsyslog_params { $$ = $1; }
;

tls_options
: tls_option tls_options
Expand Down

0 comments on commit 5a80e09

Please sign in to comment.