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) 38 f64 timestamp = va_arg (*args,
f64);
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,
"[%s]", 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;
206 u32 *r = va_arg (*args,
u32 *);
209 #define _(v,f,s) else if (unformat (input, s)) *r = SYSLOG_FACILITY_##f; 221 u32 *r = va_arg (*args,
u32 *);
224 #define _(v,f,s) else if (unformat (input, s)) *r = SYSLOG_SEVERITY_##f; 241 #define _(v,f,str) case SYSLOG_SEVERITY_##f: t = (u8 *) str; break; 245 return format (s,
"unknown");
248 return format (s,
"%s", t);
259 return VNET_API_ERROR_INVALID_VALUE;
261 if (collector->
as_u32 == 0 || collector_port == 0 || src->
as_u32 == 0)
262 return VNET_API_ERROR_INVALID_VALUE;
272 return VNET_API_ERROR_NO_SUCH_FIB;
308 else if (
unformat (line_input,
"port %u", &collector_port))
312 else if (
unformat (line_input,
"vrf-id %u", &vrf_id))
314 else if (
unformat (line_input,
"max-msg-size %u", &max_msg_size))
324 if (collector.
as_u32 == 0)
389 u8 *app_name = 0, *msgid = 0, *sd_id = 0, *param_name = 0, *param_value = 0;
405 if (
unformat (line_input,
"%s", &app_name))
407 if (
unformat (line_input,
"%s", &msgid))
410 (
char *) app_name, (
char *) msgid);
411 while (
unformat (line_input,
"sd-id %s", &sd_id))
415 (line_input,
"sd-param %s %s", ¶m_name,
420 (
char *) param_value);
526 .path =
"set syslog sender",
527 .short_help =
"set syslog sender " 528 "collector <ip4-address> [port <port>] " 529 "src <ip4-address> [vrf-id <vrf-id>] " 530 "[max-msg-size <max-msg-size>]",
547 .path =
"show syslog sender",
548 .short_help =
"show syslog sender",
568 .path =
"test syslog",
569 .short_help =
"test syslog <facility> <severity> <app-name> <msgid> " 570 "[sd-id <sd-id> sd-param <name> <value>] [<message]",
585 .path =
"set syslog filter",
586 .short_help =
"set syslog filter severity <severity>",
603 .path =
"show syslog filter",
604 .short_help =
"show syslog filter",
614 struct timeval timeval_0;
621 gettimeofday (&timeval_0, 0);
623 (
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)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
#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.
u16 current_length
Nbytes between current data and the end of this buffer.
#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)
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
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
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
u8 ** structured_data
structured data RFC5424 6.3.
static void vlib_buffer_init_for_free_list(vlib_buffer_t *dst, vlib_buffer_free_list_t *fl)
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 vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, vlib_buffer_free_list_index_t free_list_index)
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.