iPXE
syslogs.c File Reference

Encrypted syslog protocol. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.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)
 FILE_SECBOOT (PERMITTED)
static void syslogs_close (struct interface *intf, int rc)
 Handle encrypted syslog TLS interface close.
static void syslogs_window_changed (struct interface *intf)
 Handle encrypted syslog TLS interface window change.
static void syslogs_handle_priority (struct ansiesc_context *ctx __unused, unsigned int count __unused, int params[])
 Handle ANSI set encrypted syslog priority (private sequence)
static void syslogs_putchar (int character)
 Print a character to encrypted syslog console.
const struct setting syslogs_setting __setting (SETTING_MISC, syslogs)
 Encrypted syslog server setting.
static int apply_syslogs_settings (void)
 Apply encrypted syslog settings.

Variables

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

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 52 of file syslogs.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ syslogs_close()

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

Handle encrypted syslog TLS interface close.

Parameters
intfInterface
rcReason for close

Definition at line 66 of file syslogs.c.

66 {
67
68 DBG ( "SYSLOGS console disconnected: %s\n", strerror ( rc ) );
69 intf_restart ( intf, rc );
70}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition interface.c:344
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79

References DBG, intf_restart(), rc, and strerror().

Referenced by apply_syslogs_settings().

◆ syslogs_window_changed()

void syslogs_window_changed ( struct interface * intf)
static

Handle encrypted syslog TLS interface window change.

Parameters
intfInterface

Definition at line 77 of file syslogs.c.

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

References DBG, and xfer_window().

◆ syslogs_handle_priority()

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 125 of file syslogs.c.

127 {
128 if ( params[0] >= 0 ) {
129 syslogs_severity = params[0];
130 } else {
132 }
133}
#define SYSLOG_DEFAULT_SEVERITY
Syslog default severity.
Definition syslog.h:34
static unsigned int syslogs_severity
Encrypted syslog severity.
Definition syslogs.c:116

References __unused, count, ctx, SYSLOG_DEFAULT_SEVERITY, and syslogs_severity.

◆ syslogs_putchar()

void syslogs_putchar ( int character)
static

Print a character to encrypted syslog console.

Parameters
characterCharacter to be printed

Definition at line 158 of file syslogs.c.

158 {
159 int rc;
160
161 /* Ignore if we are already mid-logging */
162 if ( syslogs_entered )
163 return;
164
165 /* Fill line buffer */
166 if ( line_putchar ( &syslogs_line, character ) == 0 )
167 return;
168
169 /* Guard against re-entry */
170 syslogs_entered = 1;
171
172 /* Send log message */
174 syslogs_buffer, "\n" ) ) != 0 ) {
175 DBG ( "SYSLOGS could not send log message: %s\n",
176 strerror ( rc ) );
177 }
178
179 /* Clear re-entry flag */
180 syslogs_entered = 0;
181}
size_t line_putchar(struct line_console *line, int character)
Print a character to a line-based console.
Definition lineconsole.c:44
int syslog_send(struct interface *xfer, unsigned int severity, const char *message, const char *terminator)
Transmit formatted syslog message.
Definition syslog.c:99
static char syslogs_buffer[SYSLOG_BUFSIZE]
Encrypted syslog line buffer.
Definition syslogs.c:113
static struct interface syslogs
The encrypted syslog TLS interface.
Definition syslogs.c:103
static struct line_console syslogs_line
Encrypted syslog line console.
Definition syslogs.c:142
static int syslogs_entered
Encrypted syslog recursion marker.
Definition syslogs.c:151

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.

References __setting, DHCP_EB_SYSLOGS_SERVER, SETTING_MISC, and syslogs.

◆ apply_syslogs_settings()

int apply_syslogs_settings ( void )
static

Apply encrypted syslog settings.

Return values
rcReturn status code

Definition at line 210 of file syslogs.c.

210 {
211 static char *old_server;
212 char *server;
213 char *sep;
214 char *end;
215 unsigned int port;
216 int rc;
217
218 /* Fetch log server */
219 fetch_string_setting_copy ( NULL, &syslogs_setting, &server );
220
221 /* Do nothing unless log server has changed */
222 if ( ( ( server == NULL ) && ( old_server == NULL ) ) ||
223 ( ( server != NULL ) && ( old_server != NULL ) &&
224 ( strcmp ( server, old_server ) == 0 ) ) ) {
225 rc = 0;
226 goto out_no_change;
227 }
228 free ( old_server );
229 old_server = NULL;
230
231 /* Reset encrypted syslog connection */
232 syslogs_console.disabled = CONSOLE_DISABLED;
233 intf_restart ( &syslogs, 0 );
234
235 /* Do nothing unless we have a log server */
236 if ( ! server ) {
237 DBG ( "SYSLOGS has no log server\n" );
238 rc = 0;
239 goto out_no_server;
240 }
241
242 /* Identify port */
244 if ( ( sep = strrchr ( server, ':' ) ) &&
245 ( server[ strlen ( server ) - 1 ] != ']' ) ) {
246 *(sep++) = '\0';
247 port = strtoul ( sep, &end, 0 );
248 if ( *end || ( ! *sep ) ) {
249 DBG ( "SYSLOGS log server %s:%s has invalid port\n",
250 server, sep );
251 rc = -EINVAL;
252 goto err_port;
253 }
254 }
255 logserver.st_port = htons ( port );
256 DBG ( "SYSLOGS using log server %s:%d\n", server, port );
257
258 /* Connect to log server */
260 (( struct sockaddr *) &logserver ),
261 server, NULL ) ) != 0 ) {
262 DBG ( "SYSLOGS cannot connect to log server: %s\n",
263 strerror ( rc ) );
264 goto err_open_named_socket;
265 }
266
267 /* Add TLS filter */
268 if ( ( rc = add_tls ( &syslogs, server, NULL, NULL ) ) != 0 ) {
269 DBG ( "SYSLOGS cannot create TLS filter: %s\n",
270 strerror ( rc ) );
271 goto err_add_tls;
272 }
273
274 /* Record log server */
275 old_server = server;
276 if ( sep )
277 *(--sep) = ':';
278
279 return 0;
280
281 err_add_tls:
282 err_open_named_socket:
284 err_port:
285 out_no_server:
286 out_no_change:
287 free ( server );
288 return rc;
289}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
u8 port
Port number.
Definition CIB_PRM.h:3
#define SOCK_STREAM
Definition socket.h:25
#define EINVAL
Invalid argument.
Definition errno.h:429
#define htons(value)
Definition byteswap.h:136
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition console.h:112
#define SYSLOG_PORT
Syslog server port.
Definition syslog.h:16
uint32_t end
Ending offset.
Definition netvsc.h:7
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
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:403
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition settings.c:874
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition string.c:485
int strcmp(const char *first, const char *second)
Compare strings.
Definition string.c:174
char * strrchr(const char *src, int character)
Find rightmost character within a string.
Definition string.c:290
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
Generalized socket address structure.
Definition socket.h:97
static struct sockaddr_tcpip logserver
The encrypted syslog server.
Definition syslogs.c:58
static void syslogs_close(struct interface *intf, int rc)
Handle encrypted syslog TLS interface close.
Definition syslogs.c:66
int add_tls(struct interface *xfer, const char *name, struct x509_root *root, struct private_key *key)
Add TLS on an interface.
Definition tls.c:3962

References add_tls(), CONSOLE_DISABLED, DBG, EINVAL, end, fetch_string_setting_copy(), free, htons, intf_restart(), logserver, NULL, port, rc, SOCK_STREAM, strcmp(), strerror(), strlen(), strrchr(), strtoul(), SYSLOG_PORT, syslogs, syslogs_close(), 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:158
#define CONSOLE_SYSLOGS
Definition syslogs.c:52

Encrypted syslog console driver.

Definition at line 55 of file syslogs.c.

◆ logserver

struct sockaddr_tcpip logserver
static

The encrypted syslog server.

Definition at line 58 of file syslogs.c.

Referenced by apply_syslog_settings(), and apply_syslogs_settings().

◆ syslogs_operations

struct interface_operation syslogs_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition interface.h:33
An object interface.
Definition interface.h:125
static void syslogs_window_changed(struct interface *intf)
Handle encrypted syslog TLS interface window change.
Definition syslogs.c:77
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition xfer.c:147

Encrypted syslog TLS interface operations.

Definition at line 92 of file syslogs.c.

◆ syslogs_desc

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

Encrypted syslog TLS interface descriptor.

Definition at line 99 of file syslogs.c.

◆ syslogs

struct interface syslogs = INTF_INIT ( syslogs_desc )
static

The encrypted syslog TLS interface.

Definition at line 103 of file syslogs.c.

Referenced by __setting(), apply_syslogs_settings(), PROVIDE_REQUIRING_SYMBOL(), and syslogs_putchar().

◆ syslogs_buffer

char syslogs_buffer[SYSLOG_BUFSIZE]
static

Encrypted syslog line buffer.

Definition at line 113 of file syslogs.c.

Referenced by syslogs_putchar().

◆ syslogs_severity

unsigned int syslogs_severity = SYSLOG_DEFAULT_SEVERITY
static

Encrypted syslog severity.

Definition at line 116 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:126
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:125

Encrypted syslog ANSI escape sequence handlers.

Definition at line 136 of file syslogs.c.

136 {
138 { 0, NULL }
139};

◆ syslogs_line

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

Encrypted syslog line console.

Definition at line 142 of file syslogs.c.

142 {
143 .buffer = syslogs_buffer,
144 .len = sizeof ( syslogs_buffer ),
145 .ctx = {
146 .handlers = syslogs_handlers,
147 },
148};

Referenced by syslogs_putchar().

◆ syslogs_entered

int syslogs_entered
static

Encrypted syslog recursion marker.

Definition at line 151 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:210

Encrypted syslog settings applicator.

Definition at line 292 of file syslogs.c.

292 {
293 .apply = apply_syslogs_settings,
294};