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>
21 #include <vnet/fib/fib_table.h>
22 #include <vnet/syslog/syslog.h>
24 #include <vnet/format_fns.h>
25 #include <vnet/syslog/syslog.api_enum.h>
26 #include <vnet/syslog/syslog.api_types.h>
28 #define REPLY_MSG_ID_BASE syslog_main.msg_id_base
29 #include <vlibapi/api_helper_macros.h>
32 syslog_severity_decode (vl_api_syslog_severity_t v, syslog_severity_t * s)
39 case SYSLOG_API_SEVERITY_EMERG:
40 *s = SYSLOG_SEVERITY_EMERGENCY;
42 case SYSLOG_API_SEVERITY_ALERT:
43 *s = SYSLOG_SEVERITY_ALERT;
45 case SYSLOG_API_SEVERITY_CRIT:
46 *s = SYSLOG_SEVERITY_CRITICAL;
48 case SYSLOG_API_SEVERITY_ERR:
49 *s = SYSLOG_SEVERITY_ERROR;
51 case SYSLOG_API_SEVERITY_WARN:
52 *s = SYSLOG_SEVERITY_WARNING;
54 case SYSLOG_API_SEVERITY_NOTICE:
55 *s = SYSLOG_SEVERITY_NOTICE;
57 case SYSLOG_API_SEVERITY_INFO:
58 *s = SYSLOG_SEVERITY_INFORMATIONAL;
60 case SYSLOG_API_SEVERITY_DBG:
61 *s = SYSLOG_SEVERITY_DEBUG;
64 rv = VNET_API_ERROR_INVALID_VALUE;
71 syslog_severity_encode (syslog_severity_t v, vl_api_syslog_severity_t * s)
76 case SYSLOG_SEVERITY_EMERGENCY:
77 *s = SYSLOG_API_SEVERITY_EMERG;
79 case SYSLOG_SEVERITY_ALERT:
80 *s = SYSLOG_API_SEVERITY_ALERT;
82 case SYSLOG_SEVERITY_CRITICAL:
83 *s = SYSLOG_API_SEVERITY_CRIT;
85 case SYSLOG_SEVERITY_ERROR:
86 *s = SYSLOG_API_SEVERITY_ERR;
88 case SYSLOG_SEVERITY_WARNING:
89 *s = SYSLOG_API_SEVERITY_WARN;
91 case SYSLOG_SEVERITY_NOTICE:
92 *s = SYSLOG_API_SEVERITY_NOTICE;
94 case SYSLOG_SEVERITY_INFORMATIONAL:
95 *s = SYSLOG_API_SEVERITY_INFO;
97 case SYSLOG_SEVERITY_DEBUG:
98 *s = SYSLOG_API_SEVERITY_DBG;
101 rv = VNET_API_ERROR_INVALID_VALUE;
109 vl_api_syslog_set_sender_t_handler (vl_api_syslog_set_sender_t * mp)
111 vl_api_syslog_set_sender_reply_t *rmp;
112 ip4_address_t collector, src;
114 clib_memcpy (&collector, &mp->collector_address, sizeof (collector));
115 clib_memcpy (&src, &mp->src_address, sizeof (src));
117 int rv = set_syslog_sender (&collector, ntohs (mp->collector_port), &src,
118 ntohl (mp->vrf_id), ntohl (mp->max_msg_size));
120 REPLY_MACRO (VL_API_SYSLOG_SET_SENDER_REPLY);
124 vl_api_syslog_get_sender_t_handler (vl_api_syslog_get_sender_t * mp)
127 vl_api_syslog_get_sender_reply_t *rmp;
128 syslog_main_t *sm = &syslog_main;
131 REPLY_MACRO2 (VL_API_SYSLOG_GET_SENDER_REPLY,
133 clib_memcpy (&rmp->collector_address, &(sm->collector),
134 sizeof(ip4_address_t));
135 clib_memcpy (&rmp->src_address, &(sm->src_address),
136 sizeof(ip4_address_t));
137 rmp->collector_port = htons (sm->collector_port);
138 if (sm->fib_index == ~0)
141 vrf_id = htonl (fib_table_get_table_id (sm->fib_index, FIB_PROTOCOL_IP4));
142 rmp->vrf_id = vrf_id;
143 rmp->max_msg_size = htonl (sm->max_msg_size);
148 vl_api_syslog_set_filter_t_handler (vl_api_syslog_set_filter_t * mp)
150 vl_api_syslog_set_filter_reply_t *rmp;
151 syslog_main_t *sm = &syslog_main;
155 rv = syslog_severity_decode (mp->severity, &s);
159 sm->severity_filter = s;
162 REPLY_MACRO (VL_API_SYSLOG_SET_FILTER_REPLY);
166 vl_api_syslog_get_filter_t_handler (vl_api_syslog_get_filter_t * mp)
169 vl_api_syslog_get_filter_reply_t *rmp;
170 syslog_main_t *sm = &syslog_main;
172 REPLY_MACRO2 (VL_API_SYSLOG_GET_FILTER_REPLY,
174 rv = syslog_severity_encode (sm->severity_filter, &rmp->severity);
178 #include <vnet/syslog/syslog.api.c>
180 static clib_error_t *
181 syslog_api_hookup (vlib_main_t * vm)
184 * Set up the (msg_name, crc, message-id) table
186 REPLY_MSG_ID_BASE = setup_message_id_table ();
191 VLIB_API_INIT_FUNCTION (syslog_api_hookup);
194 * fd.io coding-style-patch-verification: ON
197 * eval: (c-set-style "gnu")