iPXE
Macros | Functions | Variables
syslog.c File Reference

Syslog protocol. More...

#include <stdint.h>
#include <stdlib.h>
#include <ctype.h>
#include <byteswap.h>
#include <ipxe/xfer.h>
#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>
#include <ipxe/syslog.h>
#include <config/console.h>

Go to the source code of this file.

Macros

#define CONSOLE_SYSLOG   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int syslog_send (struct interface *xfer, unsigned int severity, const char *message, const char *terminator)
 Transmit formatted syslog message. More...
 
static void syslog_handle_priority (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[])
 Handle ANSI set syslog priority (private sequence) More...
 
static void syslog_putchar (int character)
 Print a character to syslog console. More...
 
const struct setting syslog_setting __setting (SETTING_MISC, syslog)
 IPv4 syslog server setting. More...
 
const struct setting syslog6_setting __setting (SETTING_MISC, syslog6)
 IPv6 syslog server setting. More...
 
static void syslog_fix_name (char *name)
 Strip invalid characters from host/domain name. More...
 
static int apply_syslog_settings (void)
 Apply syslog settings. More...
 

Variables

union {
   struct sockaddr   sa
 
   struct sockaddr_tcpip   st
 
   struct sockaddr_in   sin
 
   struct sockaddr_in6   sin6
 
logserver
 The syslog server. More...
 
static struct interface_operation syslogger_operations [] = {}
 Syslog UDP interface operations. More...
 
static struct interface_descriptor syslogger_desc
 Syslog UDP interface descriptor. More...
 
static struct interface syslogger = INTF_INIT ( syslogger_desc )
 The syslog UDP interface. More...
 
static char * syslog_hostname
 Host name (for log messages) More...
 
static char * syslog_domain
 Domain name (for log messages) More...
 
static char syslog_buffer [SYSLOG_BUFSIZE]
 Syslog line buffer. More...
 
static unsigned int syslog_severity = SYSLOG_DEFAULT_SEVERITY
 Syslog severity. More...
 
static struct ansiesc_handler syslog_handlers []
 Syslog ANSI escape sequence handlers. More...
 
static struct line_console syslog_line
 Syslog line console. More...
 
static int syslog_entered
 Syslog recursion marker. More...
 
struct console_driver syslog_console __console_driver
 Syslog console driver. More...
 
struct settings_applicator syslog_applicator __settings_applicator
 Syslog settings applicator. More...
 

Detailed Description

Syslog protocol.

Definition in file syslog.c.

Macro Definition Documentation

◆ CONSOLE_SYSLOG

#define CONSOLE_SYSLOG   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )

Definition at line 50 of file syslog.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ syslog_send()

int syslog_send ( struct interface xfer,
unsigned int  severity,
const char *  message,
const char *  terminator 
)

Transmit formatted syslog message.

Parameters
xferData transfer interface
severitySeverity
messageMessage
terminatorMessage terminator
Return values
rcReturn status code

Definition at line 97 of file syslog.c.

98  {
99  const char *hostname = ( syslog_hostname ? syslog_hostname : "" );
100  const char *domain = ( ( hostname[0] && syslog_domain ) ?
101  syslog_domain : "" );
102 
103  return xfer_printf ( xfer, "<%d>%s%s%s%sipxe: %s%s",
105  severity ), hostname,
106  ( domain[0] ? "." : "" ), domain,
107  ( hostname[0] ? " " : "" ), message, terminator );
108 }
#define SYSLOG_PRIORITY(facility, severity)
Syslog priority.
Definition: syslog.h:36
static char * syslog_domain
Domain name (for log messages)
Definition: syslog.c:86
static char * syslog_hostname
Host name (for log messages)
Definition: syslog.c:83
int xfer_printf(struct interface *intf, const char *format,...)
Deliver formatted string.
Definition: xfer.c:333
char message[VMCONSOLE_BUFSIZE]
Definition: vmconsole.c:54
#define SYSLOG_DEFAULT_FACILITY
Syslog default facility.
Definition: syslog.h:27
struct eth_slow_terminator_tlv terminator
Terminator.
Definition: eth_slow.h:20
struct ntlm_data domain
Domain name.
Definition: ntlm.h:16

References domain, message, SYSLOG_DEFAULT_FACILITY, syslog_domain, syslog_hostname, SYSLOG_PRIORITY, terminator, and xfer_printf().

Referenced by syslog_putchar(), and syslogs_putchar().

◆ syslog_handle_priority()

static void syslog_handle_priority ( struct ansiesc_context *ctx  __unused,
unsigned int count  __unused,
int  params[] 
)
static

Handle ANSI set syslog priority (private sequence)

Parameters
ctxANSI escape sequence context
countParameter count
paramsList of graphic rendition aspects

Definition at line 130 of file syslog.c.

132  {
133  if ( params[0] >= 0 ) {
134  syslog_severity = params[0];
135  } else {
137  }
138 }
static unsigned int syslog_severity
Syslog severity.
Definition: syslog.c:121
#define SYSLOG_DEFAULT_SEVERITY
Syslog default severity.
Definition: syslog.h:33

References SYSLOG_DEFAULT_SEVERITY, and syslog_severity.

◆ syslog_putchar()

static void syslog_putchar ( int  character)
static

Print a character to syslog console.

Parameters
characterCharacter to be printed

Definition at line 163 of file syslog.c.

163  {
164  int rc;
165 
166  /* Ignore if we are already mid-logging */
167  if ( syslog_entered )
168  return;
169 
170  /* Fill line buffer */
171  if ( line_putchar ( &syslog_line, character ) == 0 )
172  return;
173 
174  /* Guard against re-entry */
175  syslog_entered = 1;
176 
177  /* Send log message */
179  syslog_buffer, "" ) ) != 0 ) {
180  DBG ( "SYSLOG could not send log message: %s\n",
181  strerror ( rc ) );
182  }
183 
184  /* Clear re-entry flag */
185  syslog_entered = 0;
186 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static char syslog_buffer[SYSLOG_BUFSIZE]
Syslog line buffer.
Definition: syslog.c:118
static unsigned int syslog_severity
Syslog severity.
Definition: syslog.c:121
size_t line_putchar(struct line_console *line, int character)
Print a character to a line-based console.
Definition: lineconsole.c:43
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static int syslog_entered
Syslog recursion marker.
Definition: syslog.c:156
static struct line_console syslog_line
Syslog line console.
Definition: syslog.c:147
int syslog_send(struct interface *xfer, unsigned int severity, const char *message, const char *terminator)
Transmit formatted syslog message.
Definition: syslog.c:97
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static struct interface syslogger
The syslog UDP interface.
Definition: syslog.c:73

References DBG, line_putchar(), rc, strerror(), syslog_buffer, syslog_entered, syslog_line, syslog_send(), syslog_severity, and syslogger.

◆ __setting() [1/2]

const struct setting syslog_setting __setting ( SETTING_MISC  ,
syslog   
)

IPv4 syslog server setting.

◆ __setting() [2/2]

const struct setting syslog6_setting __setting ( SETTING_MISC  ,
syslog6   
)

IPv6 syslog server setting.

◆ syslog_fix_name()

static void syslog_fix_name ( char *  name)
static

Strip invalid characters from host/domain name.

Parameters
nameName to strip

Definition at line 224 of file syslog.c.

224  {
225  char *fixed = name;
226  int c;
227 
228  /* Do nothing if name does not exist */
229  if ( ! name )
230  return;
231 
232  /* Strip any non-printable or whitespace characters from the name */
233  do {
234  c = *(name++);
235  *fixed = c;
236  if ( isprint ( c ) && ! isspace ( c ) )
237  fixed++;
238  } while ( c );
239 }
uint32_t c
Definition: md4.c:30
const char * name
Definition: ath9k_hw.c:1984
struct eltorito_descriptor_fixed fixed
Fixed portion.
Definition: eltorito.h:13
static int isprint(int character)
Check if character is printable.
Definition: ctype.h:86
int isspace(int character)
Check to see if character is a space.
Definition: ctype.c:41

References c, fixed, isprint(), isspace(), and name.

Referenced by apply_syslog_settings().

◆ apply_syslog_settings()

static int apply_syslog_settings ( void  )
static

Apply syslog settings.

Return values
rcReturn status code

Definition at line 246 of file syslog.c.

246  {
247  struct sockaddr old_logserver;
248  int rc;
249 
250  /* Fetch hostname and domain name */
251  free ( syslog_hostname );
252  fetch_string_setting_copy ( NULL, &hostname_setting, &syslog_hostname );
254  free ( syslog_domain );
255  fetch_string_setting_copy ( NULL, &domain_setting, &syslog_domain );
257 
258  /* Fetch log server */
259  syslog_console.disabled = CONSOLE_DISABLED;
260  memcpy ( &old_logserver, &logserver, sizeof ( old_logserver ) );
261  logserver.sa.sa_family = 0;
262  if ( fetch_ipv6_setting ( NULL, &syslog6_setting,
263  &logserver.sin6.sin6_addr ) >= 0 ) {
264  logserver.sin6.sin6_family = AF_INET6;
265  } else if ( fetch_ipv4_setting ( NULL, &syslog_setting,
266  &logserver.sin.sin_addr ) >= 0 ) {
267  logserver.sin.sin_family = AF_INET;
268  }
269  if ( logserver.sa.sa_family ) {
270  syslog_console.disabled = 0;
271  DBG ( "SYSLOG using log server %s\n",
272  sock_ntoa ( &logserver.sa ) );
273  }
274 
275  /* Do nothing unless log server has changed */
276  if ( memcmp ( &logserver, &old_logserver, sizeof ( logserver ) ) == 0 )
277  return 0;
278 
279  /* Reset syslog connection */
280  intf_restart ( &syslogger, 0 );
281 
282  /* Do nothing unless we have a log server */
283  if ( syslog_console.disabled ) {
284  DBG ( "SYSLOG has no log server\n" );
285  return 0;
286  }
287 
288  /* Connect to log server */
290  &logserver.sa, NULL ) ) != 0 ) {
291  DBG ( "SYSLOG cannot connect to log server: %s\n",
292  strerror ( rc ) );
293  return rc;
294  }
295 
296  return 0;
297 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition: interface.c:337
#define AF_INET6
IPv6 Internet addresses.
Definition: socket.h:64
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.c:141
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition: settings.c:916
static union @6 logserver
The syslog server.
#define SOCK_DGRAM
Definition: socket.h:29
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
static void syslog_fix_name(char *name)
Strip invalid characters from host/domain name.
Definition: syslog.c:224
static char * syslog_domain
Domain name (for log messages)
Definition: syslog.c:86
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:877
Generalized socket address structure.
Definition: socket.h:96
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static char * syslog_hostname
Host name (for log messages)
Definition: syslog.c:83
const char * sock_ntoa(struct sockaddr *sa)
Transcribe socket address.
Definition: socket.c:42
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
int fetch_ipv6_setting(struct settings *settings, const struct setting *setting, struct in6_addr *inp)
Fetch value of IPv6 address setting.
Definition: settings.c:954
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:113
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
static struct interface syslogger
The syslog UDP interface.
Definition: syslog.c:73

References AF_INET, AF_INET6, CONSOLE_DISABLED, DBG, fetch_ipv4_setting(), fetch_ipv6_setting(), fetch_string_setting_copy(), free, intf_restart(), logserver, memcmp(), memcpy(), NULL, rc, SOCK_DGRAM, sock_ntoa(), strerror(), syslog_domain, syslog_fix_name(), syslog_hostname, syslogger, and xfer_open_socket().

Variable Documentation

◆ sa

struct sockaddr sa

◆ st

u8 st

◆ sin

struct sockaddr_in sin

◆ sin6

struct sockaddr_in6 sin6

◆ logserver

union { ... } logserver
Initial value:
= {
.st = {
.st_port = htons ( SYSLOG_PORT ),
},
}
#define SYSLOG_PORT
Syslog server port.
Definition: syslog.h:15
#define htons(value)
Definition: byteswap.h:135

The syslog server.

Referenced by apply_syslog_settings().

◆ syslogger_operations

struct interface_operation syslogger_operations[] = {}
static

Syslog UDP interface operations.

Definition at line 66 of file syslog.c.

◆ syslogger_desc

struct interface_descriptor syslogger_desc
static
Initial value:
=
static struct interface_operation syslogger_operations[]
Syslog UDP interface operations.
Definition: syslog.c:66
#define INTF_DESC_PURE(operations)
Define an object interface descriptor for a pure-interface object.
Definition: interface.h:115

Syslog UDP interface descriptor.

Definition at line 69 of file syslog.c.

◆ syslogger

struct interface syslogger = INTF_INIT ( syslogger_desc )
static

The syslog UDP interface.

Definition at line 73 of file syslog.c.

Referenced by apply_syslog_settings(), and syslog_putchar().

◆ syslog_hostname

char* syslog_hostname
static

Host name (for log messages)

Definition at line 83 of file syslog.c.

Referenced by apply_syslog_settings(), and syslog_send().

◆ syslog_domain

char* syslog_domain
static

Domain name (for log messages)

Definition at line 86 of file syslog.c.

Referenced by apply_syslog_settings(), and syslog_send().

◆ syslog_buffer

char syslog_buffer[SYSLOG_BUFSIZE]
static

Syslog line buffer.

Definition at line 118 of file syslog.c.

Referenced by syslog_putchar().

◆ syslog_severity

unsigned int syslog_severity = SYSLOG_DEFAULT_SEVERITY
static

Syslog severity.

Definition at line 121 of file syslog.c.

Referenced by syslog_handle_priority(), and syslog_putchar().

◆ syslog_handlers

struct ansiesc_handler syslog_handlers[]
static
Initial value:
= {
{ 0, NULL }
}
static void syslog_handle_priority(struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[])
Handle ANSI set syslog priority (private sequence)
Definition: syslog.c:130
#define ANSIESC_LOG_PRIORITY
Explicit log message priority.
Definition: ansiesc.h:125
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

Syslog ANSI escape sequence handlers.

Definition at line 141 of file syslog.c.

◆ syslog_line

struct line_console syslog_line
static
Initial value:
= {
.buffer = syslog_buffer,
.len = sizeof ( syslog_buffer ),
.ctx = {
.handlers = syslog_handlers,
},
}
static char syslog_buffer[SYSLOG_BUFSIZE]
Syslog line buffer.
Definition: syslog.c:118
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static struct ansiesc_handler syslog_handlers[]
Syslog ANSI escape sequence handlers.
Definition: syslog.c:141

Syslog line console.

Definition at line 147 of file syslog.c.

Referenced by syslog_putchar().

◆ syslog_entered

int syslog_entered
static

Syslog recursion marker.

Definition at line 156 of file syslog.c.

Referenced by syslog_putchar().

◆ __console_driver

struct console_driver syslog_console __console_driver
Initial value:
= {
.putchar = syslog_putchar,
.disabled = CONSOLE_DISABLED,
.usage = CONSOLE_SYSLOG,
}
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
#define CONSOLE_SYSLOG
Definition: syslog.c:50
static void syslog_putchar(int character)
Print a character to syslog console.
Definition: syslog.c:163

Syslog console driver.

Definition at line 189 of file syslog.c.

◆ __settings_applicator

struct settings_applicator syslog_applicator __settings_applicator
Initial value:
= {
}
static int apply_syslog_settings(void)
Apply syslog settings.
Definition: syslog.c:246

Syslog settings applicator.

Definition at line 300 of file syslog.c.