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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/vnet.h>
17 #include <vlibmemory/api.h>
19 #include <vnet/interface.h>
20 #include <vnet/api_errno.h>
22 #include <vnet/fib/fib_table.h>
23 #include <vnet/syslog/syslog.h>
25 #include <vnet/vnet_msg_enum.h>
27 #define vl_typedefs /* define message structures */
28 #include <vnet/vnet_all_api_h.h>
31 #define vl_endianfun /* define message structures */
32 #include <vnet/vnet_all_api_h.h>
35 /* instantiate all the print functions we know about */
36 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
38 #include <vnet/vnet_all_api_h.h>
41 #include <vlibapi/api_helper_macros.h>
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)
50 syslog_severity_decode (vl_api_syslog_severity_t v, syslog_severity_t * s)
57 case SYSLOG_API_SEVERITY_EMERG:
58 *s = SYSLOG_SEVERITY_EMERGENCY;
60 case SYSLOG_API_SEVERITY_ALERT:
61 *s = SYSLOG_SEVERITY_ALERT;
63 case SYSLOG_API_SEVERITY_CRIT:
64 *s = SYSLOG_SEVERITY_CRITICAL;
66 case SYSLOG_API_SEVERITY_ERR:
67 *s = SYSLOG_SEVERITY_ERROR;
69 case SYSLOG_API_SEVERITY_WARN:
70 *s = SYSLOG_SEVERITY_WARNING;
72 case SYSLOG_API_SEVERITY_NOTICE:
73 *s = SYSLOG_SEVERITY_NOTICE;
75 case SYSLOG_API_SEVERITY_INFO:
76 *s = SYSLOG_SEVERITY_INFORMATIONAL;
78 case SYSLOG_API_SEVERITY_DBG:
79 *s = SYSLOG_SEVERITY_DEBUG;
82 rv = VNET_API_ERROR_INVALID_VALUE;
89 syslog_severity_encode (syslog_severity_t v, vl_api_syslog_severity_t * s)
94 case SYSLOG_SEVERITY_EMERGENCY:
95 *s = SYSLOG_API_SEVERITY_EMERG;
97 case SYSLOG_SEVERITY_ALERT:
98 *s = SYSLOG_API_SEVERITY_ALERT;
100 case SYSLOG_SEVERITY_CRITICAL:
101 *s = SYSLOG_API_SEVERITY_CRIT;
103 case SYSLOG_SEVERITY_ERROR:
104 *s = SYSLOG_API_SEVERITY_ERR;
106 case SYSLOG_SEVERITY_WARNING:
107 *s = SYSLOG_API_SEVERITY_WARN;
109 case SYSLOG_SEVERITY_NOTICE:
110 *s = SYSLOG_API_SEVERITY_NOTICE;
112 case SYSLOG_SEVERITY_INFORMATIONAL:
113 *s = SYSLOG_API_SEVERITY_INFO;
115 case SYSLOG_SEVERITY_DEBUG:
116 *s = SYSLOG_API_SEVERITY_DBG;
119 rv = VNET_API_ERROR_INVALID_VALUE;
127 vl_api_syslog_set_sender_t_handler (vl_api_syslog_set_sender_t * mp)
129 vl_api_syslog_set_sender_reply_t *rmp;
130 ip4_address_t collector, src;
132 clib_memcpy (&collector, &mp->collector_address, sizeof (collector));
133 clib_memcpy (&src, &mp->src_address, sizeof (src));
135 int rv = set_syslog_sender (&collector, ntohs (mp->collector_port), &src,
136 ntohl (mp->vrf_id), ntohl (mp->max_msg_size));
138 REPLY_MACRO (VL_API_SYSLOG_SET_SENDER_REPLY);
142 vl_api_syslog_get_sender_t_handler (vl_api_syslog_get_sender_t * mp)
145 vl_api_syslog_get_sender_reply_t *rmp;
146 syslog_main_t *sm = &syslog_main;
150 REPLY_MACRO2 (VL_API_SYSLOG_GET_SENDER_REPLY,
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)
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);
168 vl_api_syslog_set_filter_t_handler (vl_api_syslog_set_filter_t * mp)
170 vl_api_syslog_set_filter_reply_t *rmp;
171 syslog_main_t *sm = &syslog_main;
175 rv = syslog_severity_decode (mp->severity, &s);
179 sm->severity_filter = s;
182 REPLY_MACRO (VL_API_SYSLOG_SET_FILTER_REPLY);
186 vl_api_syslog_get_filter_t_handler (vl_api_syslog_get_filter_t * mp)
189 vl_api_syslog_get_filter_reply_t *rmp;
190 syslog_main_t *sm = &syslog_main;
193 REPLY_MACRO2 (VL_API_SYSLOG_GET_FILTER_REPLY,
195 rv = syslog_severity_encode (sm->severity_filter, &rmp->severity);
200 #define vl_msg_name_crc_list
201 #include <vnet/vnet_all_api_h.h>
202 #undef vl_msg_name_crc_list
205 setup_message_id_table (api_main_t * am)
207 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
208 foreach_vl_msg_name_crc_syslog;
212 static clib_error_t *
213 syslog_api_hookup (vlib_main_t * vm)
215 api_main_t *am = vlibapi_get_main ();
218 vl_msg_api_set_handlers(VL_API_##N, #n, \
219 vl_api_##n##_t_handler, \
221 vl_api_##n##_t_endian, \
222 vl_api_##n##_t_print, \
223 sizeof(vl_api_##n##_t), 1);
228 * Set up the (msg_name, crc, message-id) table
230 setup_message_id_table (am);
235 VLIB_API_INIT_FUNCTION (syslog_api_hookup);
238 * fd.io coding-style-patch-verification: ON
241 * eval: (c-set-style "gnu")