26 #define SYSLOG_VERSION "1" 28 #define DEFAULT_UDP_PORT 514 29 #define DEFAULT_MAX_MSG_SIZE 480 31 #define encode_priority(f, p) ((f << 3) | p) 45 msec = 1e6 * (timestamp - t);
46 return format (s,
"%4d-%02d-%02dT%02d:%02d:%02d.%06dZ", 1900 + tm->tm_year,
47 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min,
70 u8 **sds = va_arg (*args,
u8 **);
75 for (i = 0; i <
vec_len (sds); i++)
76 s =
format (s,
"[%v]", sds[i]);
105 sd =
format (0,
"%s", sd_id);
124 " %s=\"%s\"", name, value);
139 syslog_msg->
msg = msg;
164 u32 bi, msg_len, *to_next;
203 u32 *r = va_arg (*args,
u32 *);
206 #define _(v,f,s) else if (unformat (input, s)) *r = SYSLOG_FACILITY_##f; 218 u32 *r = va_arg (*args,
u32 *);
221 #define _(v,f,s) else if (unformat (input, s)) *r = SYSLOG_SEVERITY_##f; 238 #define _(v,f,str) case SYSLOG_SEVERITY_##f: t = (u8 *) str; break; 242 return format (s,
"unknown");
245 return format (s,
"%s", t);
256 return VNET_API_ERROR_INVALID_VALUE;
258 if (collector->
as_u32 == 0 || collector_port == 0 || src->
as_u32 == 0)
259 return VNET_API_ERROR_INVALID_VALUE;
269 return VNET_API_ERROR_NO_SUCH_FIB;
305 else if (
unformat (line_input,
"port %u", &collector_port))
309 else if (
unformat (line_input,
"vrf-id %u", &vrf_id))
311 else if (
unformat (line_input,
"max-msg-size %u", &max_msg_size))
321 if (collector.
as_u32 == 0)
386 u8 *app_name = 0, *msgid = 0, *sd_id = 0, *param_name = 0, *param_value = 0;
402 if (
unformat (line_input,
"%s", &app_name))
404 if (
unformat (line_input,
"%s", &msgid))
407 (
char *) app_name, (
char *) msgid);
408 while (
unformat (line_input,
"sd-id %s", &sd_id))
412 (line_input,
"sd-param %s %s", ¶m_name,
417 (
char *) param_value);
523 .path =
"set syslog sender",
524 .short_help =
"set syslog sender " 525 "collector <ip4-address> [port <port>] " 526 "src <ip4-address> [vrf-id <vrf-id>] " 527 "[max-msg-size <max-msg-size>]",
544 .path =
"show syslog sender",
545 .short_help =
"show syslog sender",
565 .path =
"test syslog",
566 .short_help =
"test syslog <facility> <severity> <app-name> <msgid> " 567 "[sd-id <sd-id> sd-param <name> <value>] [<message]",
582 .path =
"set syslog filter",
583 .short_help =
"set syslog filter severity <severity>",
600 .path =
"show syslog filter",
601 .short_help =
"show syslog filter",
611 struct timeval timeval_0;
618 gettimeofday (&timeval_0, 0);
620 (
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.
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
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.
syslog protocol UDP transport layer declaration (RFC5426)
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.
RFC5424 syslog protocol declarations.
syslog_severity_t severity_filter
severity filter (specified severity and greater match)
#define encode_priority(f, p)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
static clib_error_t * syslog_init(vlib_main_t *vm)
#define VLIB_CLI_COMMAND(x,...)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
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.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.