iPXE
Defines | 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.

Defines

#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.
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.
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.


Define Documentation

Definition at line 49 of file syslogs.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

References DBG, and strerror().

                                                                      {

        DBG ( "SYSLOGS console disconnected: %s\n", strerror ( rc ) );
}
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.

References DBG, and xfer_window().

                                                              {

        /* Mark console as enabled when window first opens, indicating
         * that TLS negotiation is complete.  (Do not disable console
         * when window closes again, since TCP will close the window
         * whenever there is unACKed data.)
         */
        if ( xfer_window ( intf ) ) {
                if ( syslogs_console.disabled )
                        DBG ( "SYSLOGS console connected\n" );
                syslogs_console.disabled = 0;
        }
}
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.

References SYSLOG_DEFAULT_SEVERITY, and syslogs_severity.

                                                     {
        if ( params[0] >= 0 ) {
                syslogs_severity = params[0];
        } else {
                syslogs_severity = SYSLOG_DEFAULT_SEVERITY;
        }
}
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.

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

                                              {
        int rc;

        /* Ignore if we are already mid-logging */
        if ( syslogs_entered )
                return;

        /* Fill line buffer */
        if ( line_putchar ( &syslogs_line, character ) == 0 )
                return;

        /* Guard against re-entry */
        syslogs_entered = 1;

        /* Send log message */
        if ( ( rc = syslog_send ( &syslogs, syslogs_severity,
                                  syslogs_buffer, "\n" ) ) != 0 ) {
                DBG ( "SYSLOGS could not send log message: %s\n",
                      strerror ( rc ) );
        }

        /* Clear re-entry flag */
        syslogs_entered = 0;
}
struct setting syslogs_setting __setting ( SETTING_MISC  ,
syslogs   
) [read]

Encrypted syslog server setting.

static int apply_syslogs_settings ( void  ) [static]

Apply encrypted syslog settings.

Return values:
rcReturn status code

Definition at line 208 of file syslogs.c.

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

                                           {
        static char *old_server;
        char *server;
        struct interface *socket;
        int rc;

        /* Fetch log server */
        fetch_string_setting_copy ( NULL, &syslogs_setting, &server );

        /* Do nothing unless log server has changed */
        if ( ( ( server == NULL ) && ( old_server == NULL ) ) ||
             ( ( server != NULL ) && ( old_server != NULL ) &&
               ( strcmp ( server, old_server ) == 0 ) ) ) {
                rc = 0;
                goto out_no_change;
        }
        free ( old_server );
        old_server = NULL;

        /* Reset encrypted syslog connection */
        syslogs_console.disabled = CONSOLE_DISABLED;
        intf_restart ( &syslogs, 0 );

        /* Do nothing unless we have a log server */
        if ( ! server ) {
                DBG ( "SYSLOGS has no log server\n" );
                rc = 0;
                goto out_no_server;
        }

        /* Add TLS filter */
        if ( ( rc = add_tls ( &syslogs, server, &socket ) ) != 0 ) {
                DBG ( "SYSLOGS cannot create TLS filter: %s\n",
                      strerror ( rc ) );
                goto err_add_tls;
        }

        /* Connect to log server */
        if ( ( rc = xfer_open_named_socket ( socket, SOCK_STREAM,
                                             (( struct sockaddr *) &logserver ),
                                             server, NULL ) ) != 0 ) {
                DBG ( "SYSLOGS cannot connect to log server: %s\n",
                      strerror ( rc ) );
                goto err_open_named_socket;
        }
        DBG ( "SYSLOGS using log server %s\n", server );

        /* Record log server */
        old_server = server;
        server = NULL;

        /* Success */
        rc = 0;

 err_open_named_socket:
 err_add_tls:
 out_no_server:
 out_no_change:
        free ( server );
        return rc;
}

Variable Documentation

struct console_driver syslogs_console __console_driver
Initial value:
 {
        .putchar = syslogs_putchar,
        .disabled = CONSOLE_DISABLED,
        .usage = CONSOLE_SYSLOGS,
}

Encrypted syslog console driver.

Definition at line 52 of file syslogs.c.

struct sockaddr_tcpip logserver [static]
Initial value:
 {
        .st_port = htons ( SYSLOG_PORT ),
}

The encrypted syslog server.

Definition at line 55 of file syslogs.c.

Initial value:

Encrypted syslog TLS interface operations.

Definition at line 90 of file syslogs.c.

Initial value:

Encrypted syslog TLS interface descriptor.

Definition at line 97 of file syslogs.c.

struct interface syslogs = INTF_INIT ( syslogs_desc ) [static]

The encrypted syslog TLS interface.

Definition at line 101 of file syslogs.c.

Encrypted syslog line buffer.

Definition at line 111 of file syslogs.c.

Referenced by syslogs_putchar().

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().

struct ansiesc_handler syslogs_handlers[] [static]
Initial value:

Encrypted syslog ANSI escape sequence handlers.

Definition at line 134 of file syslogs.c.

struct line_console syslogs_line [static]
Initial value:
 {
        .buffer = syslogs_buffer,
        .len = sizeof ( syslogs_buffer ),
        .ctx = {
                .handlers = syslogs_handlers,
        },
}

Encrypted syslog line console.

Definition at line 140 of file syslogs.c.

int syslogs_entered [static]

Encrypted syslog recursion marker.

Definition at line 149 of file syslogs.c.

Referenced by syslogs_putchar().

struct settings_applicator syslogs_applicator __settings_applicator
Initial value:
 {
        .apply = apply_syslogs_settings,
}

Encrypted syslog settings applicator.

Definition at line 271 of file syslogs.c.