Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[syslog] Add support for IPv6 syslog server
Note that IANA has not yet assigned a DHCPv6 option code for the
syslog server.  When a code is assigned, the definition of
DHCPV6_LOG_SERVERS should be updated.  Until then, an IPv6 address of
a syslog server can be configured manually using e.g.

  set syslog6 3ffe:302:11:2::8309

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Dec 5, 2013
1 parent 2649e8e commit 44a0dc7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/include/ipxe/dhcpv6.h
Expand Up @@ -152,6 +152,13 @@ struct dhcpv6_user_class_option {
/** DHCPv6 domain search list option */
#define DHCPV6_DOMAIN_LIST 24

/** DHCPv6 syslog server option
*
* This option code has not yet been assigned by IANA. Please update
* this definition once an option code has been assigned.
*/
#define DHCPV6_LOG_SERVERS 0xffffffffUL

/**
* Any DHCPv6 option
*
Expand Down
1 change: 0 additions & 1 deletion src/net/tcp/syslogs.c
Expand Up @@ -49,7 +49,6 @@ struct console_driver syslogs_console __console_driver;

/** The encrypted syslog server */
static struct sockaddr_tcpip logserver = {
.st_family = AF_INET,
.st_port = htons ( SYSLOG_PORT ),
};

Expand Down
51 changes: 35 additions & 16 deletions src/net/udp/syslog.c
Expand Up @@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/open.h>
#include <ipxe/tcpip.h>
#include <ipxe/dhcp.h>
#include <ipxe/dhcpv6.h>
#include <ipxe/settings.h>
#include <ipxe/console.h>
#include <ipxe/lineconsole.h>
Expand All @@ -45,9 +46,15 @@ FILE_LICENCE ( GPL2_OR_LATER );
#endif

/** The syslog server */
static struct sockaddr_tcpip logserver = {
.st_family = AF_INET,
.st_port = htons ( SYSLOG_PORT ),
static union {
struct sockaddr sa;
struct sockaddr_tcpip st;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} logserver = {
.st = {
.st_port = htons ( SYSLOG_PORT ),
},
};

/** Syslog UDP interface operations */
Expand Down Expand Up @@ -187,24 +194,30 @@ struct console_driver syslog_console __console_driver = {
******************************************************************************
*/

/** Syslog server setting */
/** IPv4 syslog server setting */
const struct setting syslog_setting __setting ( SETTING_MISC ) = {
.name = "syslog",
.description = "Syslog server",
.tag = DHCP_LOG_SERVERS,
.type = &setting_type_ipv4,
};

/** IPv6 syslog server setting */
const struct setting syslog6_setting __setting ( SETTING_MISC ) = {
.name = "syslog6",
.description = "Syslog server",
.tag = DHCPV6_LOG_SERVERS,
.type = &setting_type_ipv6,
.scope = &ipv6_scope,
};

/**
* Apply syslog settings
*
* @ret rc Return status code
*/
static int apply_syslog_settings ( void ) {
struct sockaddr_in *sin_logserver =
( struct sockaddr_in * ) &logserver;
struct in_addr old_addr;
int len;
struct sockaddr old_logserver;
int rc;

/* Fetch hostname and domain name */
Expand All @@ -215,14 +228,23 @@ static int apply_syslog_settings ( void ) {

/* Fetch log server */
syslog_console.disabled = CONSOLE_DISABLED;
old_addr.s_addr = sin_logserver->sin_addr.s_addr;
if ( ( len = fetch_ipv4_setting ( NULL, &syslog_setting,
&sin_logserver->sin_addr ) ) >= 0 ) {
memcpy ( &old_logserver, &logserver, sizeof ( old_logserver ) );
logserver.sa.sa_family = 0;
if ( fetch_ipv6_setting ( NULL, &syslog6_setting,
&logserver.sin6.sin6_addr ) >= 0 ) {
logserver.sin6.sin6_family = AF_INET6;
} else if ( fetch_ipv4_setting ( NULL, &syslog_setting,
&logserver.sin.sin_addr ) >= 0 ) {
logserver.sin.sin_family = AF_INET;
}
if ( logserver.sa.sa_family ) {
syslog_console.disabled = 0;
DBG ( "SYSLOG using log server %s\n",
sock_ntoa ( &logserver.sa ) );
}

/* Do nothing unless log server has changed */
if ( sin_logserver->sin_addr.s_addr == old_addr.s_addr )
if ( memcmp ( &logserver, &old_logserver, sizeof ( logserver ) ) == 0 )
return 0;

/* Reset syslog connection */
Expand All @@ -236,14 +258,11 @@ static int apply_syslog_settings ( void ) {

/* Connect to log server */
if ( ( rc = xfer_open_socket ( &syslogger, SOCK_DGRAM,
( ( struct sockaddr * ) &logserver ),
NULL ) ) != 0 ) {
&logserver.sa, NULL ) ) != 0 ) {
DBG ( "SYSLOG cannot connect to log server: %s\n",
strerror ( rc ) );
return rc;
}
DBG ( "SYSLOG using log server %s\n",
inet_ntoa ( sin_logserver->sin_addr ) );

return 0;
}
Expand Down

0 comments on commit 44a0dc7

Please sign in to comment.