FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
syslog_api.c
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 #include <vnet/vnet.h>
17 #include <vlibmemory/api.h>
18 
19 #include <vnet/interface.h>
20 #include <vnet/api_errno.h>
21 
22 #include <vnet/fib/fib_table.h>
23 #include <vnet/syslog/syslog.h>
24 
25 #include <vnet/vnet_msg_enum.h>
26 
27 #define vl_typedefs /* define message structures */
28 #include <vnet/vnet_all_api_h.h>
29 #undef vl_typedefs
30 
31 #define vl_endianfun /* define message structures */
32 #include <vnet/vnet_all_api_h.h>
33 #undef vl_endianfun
34 
35 /* instantiate all the print functions we know about */
36 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
37 #define vl_printfun
38 #include <vnet/vnet_all_api_h.h>
39 #undef vl_printfun
40 
42 
43 #define foreach_vpe_api_msg \
44 _(SYSLOG_SET_SENDER, syslog_set_sender) \
45 _(SYSLOG_GET_SENDER, syslog_get_sender) \
46 _(SYSLOG_SET_FILTER, syslog_set_filter) \
47 _(SYSLOG_GET_FILTER, syslog_get_filter)
48 
49 static int
50 syslog_severity_decode (vl_api_syslog_severity_t v, syslog_severity_t * s)
51 {
52  v = ntohl (v);
53  int rv = 0;
54 
55  switch (v)
56  {
58  *s = SYSLOG_SEVERITY_EMERGENCY;
59  break;
61  *s = SYSLOG_SEVERITY_ALERT;
62  break;
64  *s = SYSLOG_SEVERITY_CRITICAL;
65  break;
67  *s = SYSLOG_SEVERITY_ERROR;
68  break;
70  *s = SYSLOG_SEVERITY_WARNING;
71  break;
73  *s = SYSLOG_SEVERITY_NOTICE;
74  break;
76  *s = SYSLOG_SEVERITY_INFORMATIONAL;
77  break;
79  *s = SYSLOG_SEVERITY_DEBUG;
80  break;
81  default:
82  rv = VNET_API_ERROR_INVALID_VALUE;
83  }
84 
85  return rv;
86 }
87 
88 static int
89 syslog_severity_encode (syslog_severity_t v, vl_api_syslog_severity_t * s)
90 {
91  int rv = 0;
92  switch (v)
93  {
94  case SYSLOG_SEVERITY_EMERGENCY:
96  break;
97  case SYSLOG_SEVERITY_ALERT:
99  break;
100  case SYSLOG_SEVERITY_CRITICAL:
102  break;
103  case SYSLOG_SEVERITY_ERROR:
105  break;
106  case SYSLOG_SEVERITY_WARNING:
108  break;
109  case SYSLOG_SEVERITY_NOTICE:
111  break;
112  case SYSLOG_SEVERITY_INFORMATIONAL:
114  break;
115  case SYSLOG_SEVERITY_DEBUG:
117  break;
118  default:
119  rv = VNET_API_ERROR_INVALID_VALUE;
120  }
121 
122  *s = htonl (*s);
123  return rv;
124 }
125 
126 static void
128 {
129  vl_api_syslog_set_sender_reply_t *rmp;
130  ip4_address_t collector, src;
131 
132  clib_memcpy (&collector, &mp->collector_address, sizeof (collector));
133  clib_memcpy (&src, &mp->src_address, sizeof (src));
134 
135  int rv = set_syslog_sender (&collector, ntohs (mp->collector_port), &src,
136  ntohl (mp->vrf_id), ntohl (mp->max_msg_size));
137 
138  REPLY_MACRO (VL_API_SYSLOG_SET_SENDER_REPLY);
139 }
140 
141 static void
143 {
144  int rv = 0;
146  syslog_main_t *sm = &syslog_main;
147  u32 vrf_id;
148 
149  /* *INDENT-OFF* */
150  REPLY_MACRO2 (VL_API_SYSLOG_GET_SENDER_REPLY,
151  ({
152  clib_memcpy (&rmp->collector_address, &(sm->collector),
153  sizeof(ip4_address_t));
154  clib_memcpy (&rmp->src_address, &(sm->src_address),
155  sizeof(ip4_address_t));
156  rmp->collector_port = htons (sm->collector_port);
157  if (sm->fib_index == ~0)
158  vrf_id = ~0;
159  else
161  rmp->vrf_id = vrf_id;
162  rmp->max_msg_size = htonl (sm->max_msg_size);
163  }))
164  /* *INDENT-ON* */
165 }
166 
167 static void
169 {
170  vl_api_syslog_set_filter_reply_t *rmp;
171  syslog_main_t *sm = &syslog_main;
172  int rv = 0;
174 
175  rv = syslog_severity_decode (mp->severity, &s);
176  if (rv)
177  goto send_reply;
178 
179  sm->severity_filter = s;
180 
181 send_reply:
182  REPLY_MACRO (VL_API_SYSLOG_SET_FILTER_REPLY);
183 }
184 
185 static void
187 {
188  int rv = 0;
190  syslog_main_t *sm = &syslog_main;
191 
192  /* *INDENT-OFF* */
193  REPLY_MACRO2 (VL_API_SYSLOG_GET_FILTER_REPLY,
194  ({
196  }))
197  /* *INDENT-ON* */
198 }
199 
200 #define vl_msg_name_crc_list
201 #include <vnet/vnet_all_api_h.h>
202 #undef vl_msg_name_crc_list
203 
204 static void
206 {
207 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
208  foreach_vl_msg_name_crc_syslog;
209 #undef _
210 }
211 
212 static clib_error_t *
214 {
216 
217 #define _(N,n) \
218  vl_msg_api_set_handlers(VL_API_##N, #n, \
219  vl_api_##n##_t_handler, \
220  vl_noop_handler, \
221  vl_api_##n##_t_endian, \
222  vl_api_##n##_t_print, \
223  sizeof(vl_api_##n##_t), 1);
225 #undef _
226 
227  /*
228  * Set up the (msg_name, crc, message-id) table
229  */
231 
232  return 0;
233 }
234 
236 
237 /*
238  * fd.io coding-style-patch-verification: ON
239  *
240  * Local Variables:
241  * eval: (c-set-style "gnu")
242  * End:
243  */
vl_api_syslog_get_sender_reply_t::max_msg_size
u32 max_msg_size
Definition: syslog.api:78
api.h
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
SYSLOG_API_SEVERITY_CRIT
@ SYSLOG_API_SEVERITY_CRIT
Definition: syslog.api:23
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
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
fib_table_get_table_id
u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto)
Get the Table-ID of the FIB from protocol and index.
Definition: fib_table.c:1095
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: syslog_api.c:205
syslog_main_t::src_address
ip4_address_t src_address
IPv4 address of sender (source)
Definition: syslog.h:124
vl_api_syslog_set_sender_t::collector_port
u16 collector_port[default=514]
Definition: syslog.api:46
SYSLOG_API_SEVERITY_DBG
@ SYSLOG_API_SEVERITY_DBG
Definition: syslog.api:28
syslog_severity_decode
static int syslog_severity_decode(vl_api_syslog_severity_t v, syslog_severity_t *s)
Definition: syslog_api.c:50
fib_table.h
vl_api_syslog_get_sender_reply_t
Get syslog sender configuration reply.
Definition: syslog.api:70
am
app_main_t * am
Definition: application.c:489
SYSLOG_API_SEVERITY_NOTICE
@ SYSLOG_API_SEVERITY_NOTICE
Definition: syslog.api:26
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
syslog_severity_t
syslog_severity_t
Definition: syslog.h:69
SYSLOG_API_SEVERITY_EMERG
@ SYSLOG_API_SEVERITY_EMERG
Definition: syslog.api:21
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(syslog_api_hookup)
syslog_main_t::severity_filter
syslog_severity_t severity_filter
severity filter (specified severity and greater match)
Definition: syslog.h:133
vl_api_syslog_get_sender_reply_t::src_address
vl_api_ip4_address_t src_address
Definition: syslog.api:74
vl_api_syslog_get_filter_t
Get syslog filter.
Definition: syslog.api:97
vl_api_syslog_set_sender_t_handler
static void vl_api_syslog_set_sender_t_handler(vl_api_syslog_set_sender_t *mp)
Definition: syslog_api.c:127
vl_api_syslog_set_sender_t::collector_address
vl_api_ip4_address_t collector_address
Definition: syslog.api:45
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_severity_encode
static int syslog_severity_encode(syslog_severity_t v, vl_api_syslog_severity_t *s)
Definition: syslog_api.c:89
vnet_msg_enum.h
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
vl_api_syslog_get_sender_reply_t::collector_address
vl_api_ip4_address_t collector_address
Definition: syslog.api:75
syslog_main_t::max_msg_size
u32 max_msg_size
message size limit
Definition: syslog.h:130
SYSLOG_API_SEVERITY_ERR
@ SYSLOG_API_SEVERITY_ERR
Definition: syslog.api:24
vl_api_syslog_get_sender_reply_t::collector_port
u16 collector_port
Definition: syslog.api:76
vlibapi_get_main
static api_main_t * vlibapi_get_main(void)
Definition: api_common.h:390
interface.h
vl_api_syslog_set_filter_t
Set syslog filter.
Definition: syslog.api:86
SYSLOG_API_SEVERITY_WARN
@ SYSLOG_API_SEVERITY_WARN
Definition: syslog.api:25
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
syslog_api_hookup
static clib_error_t * syslog_api_hookup(vlib_main_t *vm)
Definition: syslog_api.c:213
syslog.h
vl_api_syslog_set_sender_t
Set syslog sender configuration.
Definition: syslog.api:40
api_main_t
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:228
vl_api_syslog_get_filter_reply_t
Get syslog filter reply.
Definition: syslog.api:108
syslog_main_t::collector
ip4_address_t collector
IPv4 address of remote host (destination)
Definition: syslog.h:118
vl_api_syslog_set_sender_t::src_address
vl_api_ip4_address_t src_address
Definition: syslog.api:44
vl_api_syslog_get_sender_reply_t::vrf_id
u32 vrf_id
Definition: syslog.api:77
vl_api_syslog_set_filter_t_handler
static void vl_api_syslog_set_filter_t_handler(vl_api_syslog_set_filter_t *mp)
Definition: syslog_api.c:168
u32
unsigned int u32
Definition: types.h:88
vl_api_syslog_set_sender_t::vrf_id
u32 vrf_id
Definition: syslog.api:47
vl_api_syslog_set_sender_t::max_msg_size
u32 max_msg_size[default=480]
Definition: syslog.api:48
SYSLOG_API_SEVERITY_ALERT
@ SYSLOG_API_SEVERITY_ALERT
Definition: syslog.api:22
api_helper_macros.h
vl_api_syslog_get_filter_t_handler
static void vl_api_syslog_get_filter_t_handler(vl_api_syslog_get_filter_t *mp)
Definition: syslog_api.c:186
vl_api_syslog_get_filter_reply_t::severity
vl_api_syslog_severity_t severity
Definition: syslog.api:112
vlib_main_t
Definition: main.h:102
SYSLOG_API_SEVERITY_INFO
@ SYSLOG_API_SEVERITY_INFO
Definition: syslog.api:27
syslog_main_t
Definition: syslog.h:109
vl_api_syslog_get_sender_t
Get syslog sender configuration.
Definition: syslog.api:55
clib_error_t
Definition: clib_error.h:21
syslog_main_t::fib_index
u32 fib_index
FIB table index.
Definition: syslog.h:127
vnet_all_api_h.h
rv
int __clib_unused rv
Definition: application.c:491
vrf_id
u32 vrf_id
Definition: nat44_ed.api:1053
vl_api_syslog_set_filter_t::severity
vl_api_syslog_severity_t severity
Definition: syslog.api:90
vnet.h
api_errno.h
vl_api_syslog_get_sender_t_handler
static void vl_api_syslog_get_sender_t_handler(vl_api_syslog_get_sender_t *mp)
Definition: syslog_api.c:142
foreach_vpe_api_msg
#define foreach_vpe_api_msg
Definition: syslog_api.c:43