FD.io VPP  v19.04.4-rc0-5-ge88582fac
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
160  vrf_id = htonl (fib_table_get_table_id (sm->fib_index, FIB_PROTOCOL_IP4));
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 {
215  api_main_t *am = &api_main;
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  */
u16 collector_port
UDP port number of remote host (destination)
Definition: syslog.h:120
Get syslog sender configuration.
Definition: syslog.api:55
static void vl_api_syslog_set_filter_t_handler(vl_api_syslog_set_filter_t *mp)
Definition: syslog_api.c:168
static void setup_message_id_table(api_main_t *am)
Definition: syslog_api.c:205
Get syslog sender configuration reply.
Definition: syslog.api:70
static clib_error_t * syslog_api_hookup(vlib_main_t *vm)
Definition: syslog_api.c:213
#define REPLY_MACRO2(t, body)
vl_api_syslog_severity_t severity
Definition: syslog.api:90
u32 fib_index
FIB table index.
Definition: syslog.h:126
u32 max_msg_size
message size limit
Definition: syslog.h:129
#define clib_memcpy(d, s, n)
Definition: string.h:180
unsigned int u32
Definition: types.h:88
static int syslog_severity_encode(syslog_severity_t v, vl_api_syslog_severity_t *s)
Definition: syslog_api.c:89
syslog_severity_t
Definition: syslog.h:68
#define foreach_vpe_api_msg
Definition: syslog_api.c:43
#define REPLY_MACRO(t)
Get syslog filter.
Definition: syslog.api:97
vl_api_ip4_address_t src
Definition: ipsec_gre.api:38
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
vl_api_ip4_address_t collector_address
Definition: syslog.api:75
syslog_severity_t severity_filter
severity filter (specified severity and greater match)
Definition: syslog.h:132
vlib_main_t * vm
Definition: buffer.c:312
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:1053
syslog_main_t syslog_main
Definition: syslog.c:32
static void vl_api_syslog_get_filter_t_handler(vl_api_syslog_get_filter_t *mp)
Definition: syslog_api.c:186
ip4_address_t src_address
IPv4 address of sender (source)
Definition: syslog.h:123
Set syslog filter.
Definition: syslog.api:86
vl_api_syslog_severity_t severity
Definition: syslog.api:112
vl_api_ip4_address_t src_address
Definition: syslog.api:44
VLIB_API_INIT_FUNCTION(syslog_api_hookup)
Get syslog filter reply.
Definition: syslog.api:108
Set syslog sender configuration.
Definition: syslog.api:40
static int syslog_severity_decode(vl_api_syslog_severity_t v, syslog_severity_t *s)
Definition: syslog_api.c:50
ip4_address_t collector
IPv4 address of remote host (destination)
Definition: syslog.h:117
vl_api_ip4_address_t src_address
Definition: syslog.api:74
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
static void vl_api_syslog_set_sender_t_handler(vl_api_syslog_set_sender_t *mp)
Definition: syslog_api.c:127
api_main_t api_main
Definition: api_shared.c:35
static void vl_api_syslog_get_sender_t_handler(vl_api_syslog_get_sender_t *mp)
Definition: syslog_api.c:142
vl_api_ip4_address_t collector_address
Definition: syslog.api:45