iPXE
Macros | Functions | Variables
syslogs.c File Reference

Encrypted syslog protocol. More...

#include <stdint.h>
#include <stdlib.h>
#include <byteswap.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/tcpip.h>
#include <ipxe/dhcp.h>
#include <ipxe/settings.h>
#include <ipxe/console.h>
#include <ipxe/lineconsole.h>
#include <ipxe/tls.h>
#include <ipxe/syslog.h>
#include <config/console.h>

Go to the source code of this file.

Macros

#define CONSOLE_SYSLOGS   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void syslogs_close (struct interface *intf __unused, int rc)
 Handle encrypted syslog TLS interface close. More...
 
static void syslogs_window_changed (struct interface *intf)
 Handle encrypted syslog TLS interface window change. More...
 
static void syslogs_handle_priority (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[])
 Handle ANSI set encrypted syslog priority (private sequence) More...
 
static void syslogs_putchar (int character)
 Print a character to encrypted syslog console. More...
 
const struct setting syslogs_setting __setting (SETTING_MISC, syslogs)
 Encrypted syslog server setting. More...
 
static int apply_syslogs_settings (void)
 Apply encrypted syslog settings. More...
 

Variables

struct console_driver syslogs_console __console_driver
 Encrypted syslog console driver. More...
 
static struct sockaddr_tcpip logserver
 The encrypted syslog server. More...
 
static struct interface_operation syslogs_operations []
 Encrypted syslog TLS interface operations. More...
 
static struct interface_descriptor syslogs_desc
 Encrypted syslog TLS interface descriptor. More...
 
static struct interface syslogs = INTF_INIT ( syslogs_desc )
 The encrypted syslog TLS interface. More...
 
static char syslogs_buffer [SYSLOG_BUFSIZE]
 Encrypted syslog line buffer. More...
 
static unsigned int syslogs_severity = SYSLOG_DEFAULT_SEVERITY
 Encrypted syslog severity. More...
 
static struct ansiesc_handler syslogs_handlers []
 Encrypted syslog ANSI escape sequence handlers. More...
 
static struct line_console syslogs_line
 Encrypted syslog line console. More...
 
static int syslogs_entered
 Encrypted syslog recursion marker. More...
 
struct settings_applicator syslogs_applicator __settings_applicator
 Encrypted syslog settings applicator. More...
 

Detailed Description

Encrypted syslog protocol.

Definition in file syslogs.c.

Macro Definition Documentation

◆ CONSOLE_SYSLOGS

#define CONSOLE_SYSLOGS   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_TUI )

Definition at line 49 of file syslogs.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ syslogs_close()

static void syslogs_close ( struct interface *intf  __unused,
int  rc 
)
static

Handle encrypted syslog TLS interface close.

Parameters
intfInterface
rcReason for close

Definition at line 65 of file syslogs.c.

65  {
66 
67  DBG ( "SYSLOGS console disconnected: %s\n", strerror ( rc ) );
68 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, rc, and strerror().

◆ syslogs_window_changed()

static void syslogs_window_changed ( struct interface intf)
static

Handle encrypted syslog TLS interface window change.

Parameters
intfInterface

Definition at line 75 of file syslogs.c.

75  {
76 
77  /* Mark console as enabled when window first opens, indicating
78  * that TLS negotiation is complete. (Do not disable console
79  * when window closes again, since TCP will close the window
80  * whenever there is unACKed data.)
81  */
82  if ( xfer_window ( intf ) ) {
83  if ( syslogs_console.disabled )
84  DBG ( "SYSLOGS console connected\n" );
85  syslogs_console.disabled = 0;
86  }
87 }
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:115
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, and xfer_window().

◆ syslogs_handle_priority()

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

Handle ANSI set encrypted syslog priority (private sequence)

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

Definition at line 123 of file syslogs.c.

125  {
126  if ( params[0] >= 0 ) {
127  syslogs_severity = params[0];
128  } else {
130  }
131 }
static unsigned int syslogs_severity
Encrypted syslog severity.
Definition: syslogs.c:114
#define SYSLOG_DEFAULT_SEVERITY
Syslog default severity.
Definition: syslog.h:33

References SYSLOG_DEFAULT_SEVERITY, and syslogs_severity.

◆ syslogs_putchar()

static void syslogs_putchar ( int  character)
static

Print a character to encrypted syslog console.

Parameters
characterCharacter to be printed

Definition at line 156 of file syslogs.c.

156  {
157  int rc;
158 
159  /* Ignore if we are already mid-logging */
160  if ( syslogs_entered )
161  return;
162 
163  /* Fill line buffer */
164  if ( line_putchar ( &syslogs_line, character ) == 0 )
165  return;
166 
167  /* Guard against re-entry */
168  syslogs_entered = 1;
169 
170  /* Send log message */
171  if ( ( rc = syslog_send ( &syslogs, syslogs_severity,
172  syslogs_buffer, "\n" ) ) != 0 ) {
173  DBG ( "SYSLOGS could not send log message: %s\n",
174  strerror ( rc ) );
175  }
176 
177  /* Clear re-entry flag */
178  syslogs_entered = 0;
179 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static unsigned int syslogs_severity
Encrypted syslog severity.
Definition: syslogs.c:114
size_t line_putchar(struct line_console *line, int character)
Print a character to a line-based console.
Definition: lineconsole.c:43
static char syslogs_buffer[SYSLOG_BUFSIZE]
Encrypted syslog line buffer.
Definition: syslogs.c:111
static int syslogs_entered
Encrypted syslog recursion marker.
Definition: syslogs.c:149
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
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 syslogs
The encrypted syslog TLS interface.
Definition: syslogs.c:101
static struct line_console syslogs_line
Encrypted syslog line console.
Definition: syslogs.c:140

References DBG, line_putchar(), rc, strerror(), syslog_send(), syslogs, syslogs_buffer, syslogs_entered, syslogs_line, and syslogs_severity.

◆ __setting()

const struct setting syslogs_setting __setting ( SETTING_MISC  ,
syslogs   
)

Encrypted syslog server setting.

◆ apply_syslogs_settings()

static int apply_syslogs_settings ( void  )
static

Apply encrypted syslog settings.

Return values
rcReturn status code

Definition at line 208 of file syslogs.c.

208  {
209  static char *old_server;
210  char *server;
211  struct interface *socket;
212  int rc;
213 
214  /* Fetch log server */
215  fetch_string_setting_copy ( NULL, &syslogs_setting, &server );
216 
217  /* Do nothing unless log server has changed */
218  if ( ( ( server == NULL ) && ( old_server == NULL ) ) ||
219  ( ( server != NULL ) && ( old_server != NULL ) &&
220  ( strcmp ( server, old_server ) == 0 ) ) ) {
221  rc = 0;
222  goto out_no_change;
223  }
224  free ( old_server );
225  old_server = NULL;
226 
227  /* Reset encrypted syslog connection */
228  syslogs_console.disabled = CONSOLE_DISABLED;
229  intf_restart ( &syslogs, 0 );
230 
231  /* Do nothing unless we have a log server */
232  if ( ! server ) {
233  DBG ( "SYSLOGS has no log server\n" );
234  rc = 0;
235  goto out_no_server;
236  }
237 
238  /* Add TLS filter */
239  if ( ( rc = add_tls ( &syslogs, server, &socket ) ) != 0 ) {
240  DBG ( "SYSLOGS cannot create TLS filter: %s\n",
241  strerror ( rc ) );
242  goto err_add_tls;
243  }
244 
245  /* Connect to log server */
246  if ( ( rc = xfer_open_named_socket ( socket, SOCK_STREAM,
247  (( struct sockaddr *) &logserver ),
248  server, NULL ) ) != 0 ) {
249  DBG ( "SYSLOGS cannot connect to log server: %s\n",
250  strerror ( rc ) );
251  goto err_open_named_socket;
252  }
253  DBG ( "SYSLOGS using log server %s\n", server );
254 
255  /* Record log server */
256  old_server = server;
257  server = NULL;
258 
259  /* Success */
260  rc = 0;
261 
262  err_open_named_socket:
263  err_add_tls:
264  out_no_server:
265  out_no_change:
266  free ( server );
267  return rc;
268 }
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
static struct sockaddr_tcpip logserver
The encrypted syslog server.
Definition: syslogs.c:55
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
An object interface.
Definition: interface.h:109
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
#define SOCK_STREAM
Definition: socket.h:24
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:157
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
int add_tls(struct interface *xfer, const char *name, struct interface **next)
Definition: tls.c:3073
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static struct interface syslogs
The encrypted syslog TLS interface.
Definition: syslogs.c:101
int xfer_open_named_socket(struct interface *xfer, int semantics, struct sockaddr *peer, const char *name, struct sockaddr *local)
Open named socket.
Definition: resolv.c:402

References add_tls(), CONSOLE_DISABLED, DBG, fetch_string_setting_copy(), free, intf_restart(), logserver, NULL, rc, SOCK_STREAM, strcmp(), strerror(), syslogs, and xfer_open_named_socket().

Variable Documentation

◆ __console_driver

struct console_driver syslogs_console __console_driver
Initial value:
= {
.putchar = syslogs_putchar,
.disabled = CONSOLE_DISABLED,
.usage = CONSOLE_SYSLOGS,
}
static void syslogs_putchar(int character)
Print a character to encrypted syslog console.
Definition: syslogs.c:156
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
#define CONSOLE_SYSLOGS
Definition: syslogs.c:49

Encrypted syslog console driver.

Definition at line 52 of file syslogs.c.

◆ logserver

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

The encrypted syslog server.

Definition at line 55 of file syslogs.c.

Referenced by apply_syslogs_settings().

◆ syslogs_operations

struct interface_operation syslogs_operations[]
static
Initial value:
= {
}
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:145
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
static void syslogs_window_changed(struct interface *intf)
Handle encrypted syslog TLS interface window change.
Definition: syslogs.c:75
An object interface.
Definition: interface.h:109
static void syslogs_close(struct interface *intf __unused, int rc)
Handle encrypted syslog TLS interface close.
Definition: syslogs.c:65
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32

Encrypted syslog TLS interface operations.

Definition at line 90 of file syslogs.c.

◆ syslogs_desc

struct interface_descriptor syslogs_desc
static
Initial value:
=
static struct interface_operation syslogs_operations[]
Encrypted syslog TLS interface operations.
Definition: syslogs.c:90
#define INTF_DESC_PURE(operations)
Define an object interface descriptor for a pure-interface object.
Definition: interface.h:100

Encrypted syslog TLS interface descriptor.

Definition at line 97 of file syslogs.c.

◆ syslogs

struct interface syslogs = INTF_INIT ( syslogs_desc )
static

The encrypted syslog TLS interface.

Definition at line 101 of file syslogs.c.

Referenced by apply_syslogs_settings(), and syslogs_putchar().

◆ syslogs_buffer

char syslogs_buffer[SYSLOG_BUFSIZE]
static

Encrypted syslog line buffer.

Definition at line 111 of file syslogs.c.

Referenced by syslogs_putchar().

◆ syslogs_severity

unsigned int syslogs_severity = SYSLOG_DEFAULT_SEVERITY
static

Encrypted syslog severity.

Definition at line 114 of file syslogs.c.

Referenced by syslogs_handle_priority(), and syslogs_putchar().

◆ syslogs_handlers

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

Encrypted syslog ANSI escape sequence handlers.

Definition at line 134 of file syslogs.c.

◆ syslogs_line

struct line_console syslogs_line
static
Initial value:
= {
.buffer = syslogs_buffer,
.len = sizeof ( syslogs_buffer ),
.ctx = {
.handlers = syslogs_handlers,
},
}
static struct ansiesc_handler syslogs_handlers[]
Encrypted syslog ANSI escape sequence handlers.
Definition: syslogs.c:134
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
static char syslogs_buffer[SYSLOG_BUFSIZE]
Encrypted syslog line buffer.
Definition: syslogs.c:111

Encrypted syslog line console.

Definition at line 140 of file syslogs.c.

Referenced by syslogs_putchar().

◆ syslogs_entered

int syslogs_entered
static

Encrypted syslog recursion marker.

Definition at line 149 of file syslogs.c.

Referenced by syslogs_putchar().

◆ __settings_applicator

struct settings_applicator syslogs_applicator __settings_applicator
Initial value:
= {
}
static int apply_syslogs_settings(void)
Apply encrypted syslog settings.
Definition: syslogs.c:208

Encrypted syslog settings applicator.

Definition at line 271 of file syslogs.c.