25 #define SYSLOG_VERSION "1" 27 #define DEFAULT_UDP_PORT 514 28 #define DEFAULT_MAX_MSG_SIZE 480 30 #define encode_priority(f, p) ((f << 3) | p) 44 msec = 1e6 * (timestamp - t);
45 return format (s,
"%4d-%02d-%02dT%02d:%02d:%02d.%06dZ", 1900 + tm->tm_year,
46 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min,
69 u8 **sds = va_arg (*args,
u8 **);
74 for (i = 0; i <
vec_len (sds); i++)
75 s =
format (s,
"[%v]", sds[i]);
104 sd =
format (0,
"%s", sd_id);
123 " %s=\"%s\"", name, value);
138 syslog_msg->
msg = msg;
163 u32 bi, msg_len, *to_next;
202 u32 *r = va_arg (*args,
u32 *);
205 #define _(v,f,s) else if (unformat (input, s)) *r = SYSLOG_FACILITY_##f; 217 u32 *r = va_arg (*args,
u32 *);
220 #define _(v,f,s) else if (unformat (input, s)) *r = SYSLOG_SEVERITY_##f; 237 #define _(v,f,str) case SYSLOG_SEVERITY_##f: t = (u8 *) str; break; 241 return format (s,
"unknown");
244 return format (s,
"%s", t);
255 return VNET_API_ERROR_INVALID_VALUE;
257 if (collector->
as_u32 == 0 || collector_port == 0 || src->
as_u32 == 0)
258 return VNET_API_ERROR_INVALID_VALUE;
268 return VNET_API_ERROR_NO_SUCH_FIB;
304 else if (
unformat (line_input,
"port %u", &collector_port))
308 else if (
unformat (line_input,
"vrf-id %u", &vrf_id))
310 else if (
unformat (line_input,
"max-msg-size %u", &max_msg_size))
320 if (collector.
as_u32 == 0)
385 u8 *app_name = 0, *msgid = 0, *sd_id = 0, *param_name = 0, *param_value = 0;
401 if (
unformat (line_input,
"%s", &app_name))
403 if (
unformat (line_input,
"%s", &msgid))
406 (
char *) app_name, (
char *) msgid);
407 while (
unformat (line_input,
"sd-id %s", &sd_id))
411 (line_input,
"sd-param %s %s", ¶m_name,
416 (
char *) param_value);
522 .path =
"set syslog sender",
523 .short_help =
"set syslog sender " 524 "collector <ip4-address> [port <port>] " 525 "src <ip4-address> [vrf-id <vrf-id>] " 526 "[max-msg-size <max-msg-size>]",
543 .path =
"show syslog sender",
544 .short_help =
"show syslog sender",
564 .path =
"test syslog",
565 .short_help =
"test syslog <facility> <severity> <app-name> <msgid> " 566 "[sd-id <sd-id> sd-param <name> <value>] [<message]",
581 .path =
"set syslog filter",
582 .short_help =
"set syslog filter severity <severity>",
599 .path =
"show syslog filter",
600 .short_help =
"show syslog filter",
610 struct timeval timeval_0;
617 gettimeofday (&timeval_0, 0);
619 (
f64) timeval_0.tv_sec + (((
f64) timeval_0.tv_usec) * 1e-6) - vlib_time_0;
u16 collector_port
UDP port number of remote host (destination)
f64 time_offset
time offset
#define vec_c_string_is_terminated(V)
Test whether a vector is a NULL terminated c-string.
void syslog_msg_add_msg(syslog_msg_t *syslog_msg, char *fmt,...)
Add free-form message RFC5424 6.4.
vnet_main_t * vnet_get_main(void)
static u8 * format_syslog_msg(u8 *s, va_list *args)
#define clib_memcpy_fast(a, b, c)
static f64 vlib_time_now(vlib_main_t *vm)
u16 current_length
Nbytes between current data and the end of this buffer.
#define vec_terminate_c_string(V)
(If necessary) NULL terminate a vector containing a c-string.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static clib_error_t * show_syslog_sender_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static uword unformat_syslog_facility(unformat_input_t *input, va_list *args)
u32 fib_index
FIB table index.
u32 max_msg_size
message size limit
vlib_main_t * vlib_main
convenience variables
static u8 * format_syslog_header(u8 *s, va_list *args)
static clib_error_t * set_syslog_sender_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
static clib_error_t * test_syslog_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VLIB_INIT_FUNCTION(x)
static clib_error_t * set_syslog_filter_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static u8 * format_syslog_timestamp(u8 *s, va_list *args)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
#define clib_error_return(e, args...)
u32 procid
process ID RFC5424 6.2.6.
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
int syslog_msg_send(syslog_msg_t *syslog_msg)
Send syslog message.
#define DEFAULT_MAX_MSG_SIZE
syslog_header_t header
header
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
static clib_error_t * show_syslog_filter_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void syslog_add_udp_transport(vlib_main_t *vm, u32 bi)
Add UDP/IP transport layer by prepending it to existing data.
static uword unformat_syslog_severity(unformat_input_t *input, va_list *args)
static u8 * format_syslog_severity(u8 *s, va_list *args)
void syslog_msg_sd_init(syslog_msg_t *syslog_msg, char *sd_id)
Initialize structured data element.
static u8 * format_vnet_api_errno(u8 *s, va_list *args)
u8 * msg
free-form message RFC5424 6.4.
syslog_severity_t severity_filter
severity filter (specified severity and greater match)
#define encode_priority(f, p)
#define vec_free(V)
Free vector's memory (no header).
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static clib_error_t * syslog_init(vlib_main_t *vm)
#define VLIB_CLI_COMMAND(x,...)
void syslog_msg_init(syslog_msg_t *syslog_msg, syslog_facility_t facility, syslog_severity_t severity, char *app_name, char *msgid)
Initialize syslog message header.
u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto)
Get the Table-ID of the FIB from protocol and index.
syslog_main_t syslog_main
ip4_address_t src_address
IPv4 address of sender (source)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
u32 ip4_lookup_node_index
ip4-lookup node index
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
u8 ** structured_data
structured data RFC5424 6.3.
void syslog_msg_add_sd_param(syslog_msg_t *syslog_msg, char *name, char *fmt,...)
Add structured data elemnt parameter name-value pair RFC5424 6.3.3.
ip4_address_t collector
IPv4 address of remote host (destination)
static int syslog_severity_filter_block(syslog_severity_t s)
Severity filter test.
static int syslog_is_enabled(void)
Check if syslog logging is enabled.
vnet_api_error_t set_syslog_sender(ip4_address_t *collector, u16 collector_port, ip4_address_t *src, u32 vrf_id, u32 max_msg_size)
Set syslog sender configuration.
static u8 * format_syslog_structured_data(u8 *s, va_list *args)
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.