FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
syslog.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @file syslog.h
17  * RFC5424 syslog protocol declarations
18  */
19 #ifndef __included_syslog_h__
20 #define __included_syslog_h__
21 
22 #include <vlib/vlib.h>
23 #include <vnet/vnet.h>
24 #include <vnet/ip/ip4_packet.h>
25 
26 /* syslog message facilities */
27 #define foreach_syslog_facility \
28  _(0, KERNEL, "kernel") \
29  _(1, USER_LEVEL, "user-level") \
30  _(2, MAIL_SYSTEM, "mail-system") \
31  _(3, SYSTEM_DAEMONS, "system-daemons") \
32  _(4, SEC_AUTH, "security-authorization") \
33  _(5, SYSLOGD, "syslogd") \
34  _(6, LINE_PRINTER, "line-printer") \
35  _(7, NETWORK_NEWS, "network-news") \
36  _(8, UUCP, "uucp") \
37  _(9, CLOCK, "clock-daemon") \
38  _(11, FTP, "ftp-daemon") \
39  _(12, NTP, "ntp-subsystem") \
40  _(13, LOG_AUDIT, "log-audit") \
41  _(14, LOG_ALERT, "log-alert") \
42  _(16, LOCAL0, "local0") \
43  _(17, LOCAL1, "local1") \
44  _(18, LOCAL2, "local2") \
45  _(19, LOCAL3, "local3") \
46  _(20, LOCAL4, "local4") \
47  _(21, LOCAL5, "local5") \
48  _(22, LOCAL6, "local6") \
49  _(23, LOCAL7, "local7")
50 
51 typedef enum
52 {
53 #define _(v, N, s) SYSLOG_FACILITY_##N = v,
55 #undef _
57 
58 /* syslog message severities */
59 #define foreach_syslog_severity \
60  _(0, EMERGENCY, "emergency") \
61  _(1, ALERT, "alert") \
62  _(2, CRITICAL, "critical") \
63  _(3, ERROR, "error") \
64  _(4, WARNING, "warning") \
65  _(5, NOTICE, "notice") \
66  _(6, INFORMATIONAL, "informational") \
67  _(7, DEBUG, "debug")
68 
69 typedef enum
70 {
71 #define _(v, N, s) SYSLOG_SEVERITY_##N = v,
73 #undef _
75 
76 /** syslog header */
77 typedef struct
78 {
79  /** facility value, part of priority */
81 
82  /** severity value, part of priority */
84 
85  /** message timestamp */
87 
88  /** application that originated the message RFC5424 6.2.5. */
89  char *app_name;
90 
91  /** identify the type of message RFC5424 6.2.7. */
92  char *msgid;
94 
95 /** syslog message */
96 typedef struct
97 {
98  /** header */
100 
101  /** structured data RFC5424 6.3. */
104 
105  /** free-form message RFC5424 6.4. */
106  u8 *msg;
107 } syslog_msg_t;
108 
109 typedef struct
110 {
111  /** process ID RFC5424 6.2.6. */
113 
114  /** time offset */
116 
117  /** IPv4 address of remote host (destination) */
119 
120  /** UDP port number of remote host (destination) */
122 
123  /** IPv4 address of sender (source) */
125 
126  /** FIB table index */
128 
129  /** message size limit */
131 
132  /** severity filter (specified severity and greater match) */
134 
135  /** ip4-lookup node index */
137 
138  /** convenience variables */
140 
142 } syslog_main_t;
143 
145 
146 /**
147  * @brief Initialize syslog message header
148  *
149  * @param facility facility value
150  * @param severity severity level
151  * @param app_name application that originated message RFC424 6.2.5. (optional)
152  * @param msgid identify the type of message RFC5424 6.2.7. (optional)
153  */
155  syslog_severity_t severity, char *app_name,
156  char *msgid);
157 /**
158  * @brief Initialize structured data element
159  *
160  * @param sd_id structured data element name RFC5424 6.3.2.
161  */
162 void syslog_msg_sd_init (syslog_msg_t * syslog_msg, char *sd_id);
163 
164 /**
165  * @brief Add structured data elemnt parameter name-value pair RFC5424 6.3.3.
166  */
168  char *fmt, ...);
169 
170 /**
171  * @brief Add free-form message RFC5424 6.4.
172  */
173 void syslog_msg_add_msg (syslog_msg_t * syslog_msg, char *fmt, ...);
174 
175 /**
176  * @brief Send syslog message
177  */
179 
180 /**
181  * @brief Set syslog sender configuration
182  *
183  * @param collector IPv4 address of syslog collector (destination)
184  * @param collector_port UDP port of syslog colector (destination)
185  * @param src IPv4 address of syslog sender (source)
186  * @param vrf_id VRF/FIB table ID
187  * @param max_msg_size maximum message length
188  */
190  u16 collector_port, ip4_address_t * src,
191  u32 vrf_id, u32 max_msg_size);
192 
193 /**
194  * @brief Check if syslog logging is enabled
195  *
196  * @return 1 if syslog logging is enabled, 0 otherwise
197  */
198 always_inline int
200 {
201  syslog_main_t *sm = &syslog_main;
202 
203  return sm->collector.as_u32 ? 1 : 0;
204 }
205 
206 /**
207  * @brief Severity filter test
208  *
209  * @return 1 if message with specified severity is not selected to be logged
210  */
211 always_inline int
213 {
214  syslog_main_t *sm = &syslog_main;
215 
216  return (sm->severity_filter < s);
217 }
218 
219 #endif /* __included_syslog_h__ */
220 
221 /*
222  * fd.io coding-style-patch-verification: ON
223  *
224  * Local Variables:
225  * eval: (c-set-style "gnu")
226  * End:
227  */
vlib.h
syslog_header_t
syslog header
Definition: syslog.h:77
syslog_header_t::app_name
char * app_name
application that originated the message RFC5424 6.2.5.
Definition: syslog.h:89
syslog_main_t::procid
u32 procid
process ID RFC5424 6.2.6.
Definition: syslog.h:112
syslog_msg_t::structured_data
u8 ** structured_data
structured data RFC5424 6.3.
Definition: syslog.h:102
syslog_facility_t
syslog_facility_t
Definition: syslog.h:51
syslog_msg_add_msg
void syslog_msg_add_msg(syslog_msg_t *syslog_msg, char *fmt,...)
Add free-form message RFC5424 6.4.
Definition: syslog.c:129
name
string name[64]
Definition: fib.api:25
syslog_main_t::src_address
ip4_address_t src_address
IPv4 address of sender (source)
Definition: syslog.h:124
syslog_main_t::msg_id_base
u16 msg_id_base
Definition: syslog.h:141
syslog_msg
static u8 * syslog_msg
Definition: main.c:95
ip4_address_t::as_u32
u32 as_u32
Definition: ip4_packet.h:57
syslog_main_t::ip4_lookup_node_index
u32 ip4_lookup_node_index
ip4-lookup node index
Definition: syslog.h:136
u16
unsigned short u16
Definition: types.h:57
syslog_msg_add_sd_param
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.
Definition: syslog.c:111
syslog_severity_t
syslog_severity_t
Definition: syslog.h:69
syslog_main_t::vnet_main
vnet_main_t * vnet_main
convenience variables
Definition: syslog.h:139
syslog_main_t::severity_filter
syslog_severity_t severity_filter
severity filter (specified severity and greater match)
Definition: syslog.h:133
syslog_main
syslog_main_t syslog_main
Definition: syslog.c:33
syslog_main_t::collector_port
u16 collector_port
UDP port number of remote host (destination)
Definition: syslog.h:121
syslog_msg_init
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.
Definition: syslog.c:143
set_syslog_sender
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.
Definition: syslog.c:247
syslog_main_t::max_msg_size
u32 max_msg_size
message size limit
Definition: syslog.h:130
syslog_severity_filter_block
static int syslog_severity_filter_block(syslog_severity_t s)
Severity filter test.
Definition: syslog.h:212
foreach_syslog_facility
#define foreach_syslog_facility
Definition: syslog.h:27
syslog_header_t::msgid
char * msgid
identify the type of message RFC5424 6.2.7.
Definition: syslog.h:92
f64
double f64
Definition: types.h:142
app_name
static char * app_name
Definition: vapi_cpp_test.cpp:33
src
vl_api_address_t src
Definition: gre.api:54
syslog_header_t::facility
syslog_facility_t facility
facility value, part of priority
Definition: syslog.h:80
ip4_address_t
Definition: ip4_packet.h:50
fmt
int cJSON_bool fmt
Definition: cJSON.h:160
ip4_packet.h
foreach_syslog_severity
#define foreach_syslog_severity
Definition: syslog.h:59
syslog_main_t::collector
ip4_address_t collector
IPv4 address of remote host (destination)
Definition: syslog.h:118
vnet_main_t
Definition: vnet.h:76
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
syslog_msg_t::curr_sd_index
u32 curr_sd_index
Definition: syslog.h:103
syslog_msg_t::header
syslog_header_t header
header
Definition: syslog.h:99
u32
unsigned int u32
Definition: types.h:88
syslog_msg_t::msg
u8 * msg
free-form message RFC5424 6.4.
Definition: syslog.h:106
syslog_is_enabled
static int syslog_is_enabled(void)
Check if syslog logging is enabled.
Definition: syslog.h:199
syslog_msg_t
syslog message
Definition: syslog.h:96
syslog_main_t::time_offset
f64 time_offset
time offset
Definition: syslog.h:115
syslog_main_t
Definition: syslog.h:109
u8
unsigned char u8
Definition: types.h:56
syslog_msg_send
int syslog_msg_send(syslog_msg_t *syslog_msg)
Send syslog message.
Definition: syslog.c:159
syslog_main_t::fib_index
u32 fib_index
FIB table index.
Definition: syslog.h:127
syslog_header_t::timestamp
f64 timestamp
message timestamp
Definition: syslog.h:86
vrf_id
u32 vrf_id
Definition: nat44_ed.api:1053
syslog_msg_sd_init
void syslog_msg_sd_init(syslog_msg_t *syslog_msg, char *sd_id)
Initialize structured data element.
Definition: syslog.c:101
vnet.h
syslog_header_t::severity
syslog_severity_t severity
severity value, part of priority
Definition: syslog.h:83
vnet_api_error_t
vnet_api_error_t
Definition: api_errno.h:162