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