FD.io VPP  v21.10.1-2-g0a485f517
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 #include <vnet/fib/fib_table.h>
22 #include <vnet/syslog/syslog.h>
23 
24 #include <vnet/format_fns.h>
25 #include <vnet/syslog/syslog.api_enum.h>
26 #include <vnet/syslog/syslog.api_types.h>
27 
28 #define REPLY_MSG_ID_BASE syslog_main.msg_id_base
30 
31 static int
32 syslog_severity_decode (vl_api_syslog_severity_t v, syslog_severity_t * s)
33 {
34  v = ntohl (v);
35  int rv = 0;
36 
37  switch (v)
38  {
40  *s = SYSLOG_SEVERITY_EMERGENCY;
41  break;
43  *s = SYSLOG_SEVERITY_ALERT;
44  break;
46  *s = SYSLOG_SEVERITY_CRITICAL;
47  break;
49  *s = SYSLOG_SEVERITY_ERROR;
50  break;
52  *s = SYSLOG_SEVERITY_WARNING;
53  break;
55  *s = SYSLOG_SEVERITY_NOTICE;
56  break;
58  *s = SYSLOG_SEVERITY_INFORMATIONAL;
59  break;
61  *s = SYSLOG_SEVERITY_DEBUG;
62  break;
63  default:
64  rv = VNET_API_ERROR_INVALID_VALUE;
65  }
66 
67  return rv;
68 }
69 
70 static int
71 syslog_severity_encode (syslog_severity_t v, vl_api_syslog_severity_t * s)
72 {
73  int rv = 0;
74  switch (v)
75  {
76  case SYSLOG_SEVERITY_EMERGENCY:
78  break;
79  case SYSLOG_SEVERITY_ALERT:
81  break;
82  case SYSLOG_SEVERITY_CRITICAL:
84  break;
85  case SYSLOG_SEVERITY_ERROR:
87  break;
88  case SYSLOG_SEVERITY_WARNING:
90  break;
91  case SYSLOG_SEVERITY_NOTICE:
93  break;
94  case SYSLOG_SEVERITY_INFORMATIONAL:
96  break;
97  case SYSLOG_SEVERITY_DEBUG:
99  break;
100  default:
101  rv = VNET_API_ERROR_INVALID_VALUE;
102  }
103 
104  *s = htonl (*s);
105  return rv;
106 }
107 
108 static void
110 {
111  vl_api_syslog_set_sender_reply_t *rmp;
112  ip4_address_t collector, src;
113 
114  clib_memcpy (&collector, &mp->collector_address, sizeof (collector));
115  clib_memcpy (&src, &mp->src_address, sizeof (src));
116 
117  int rv = set_syslog_sender (&collector, ntohs (mp->collector_port), &src,
118  ntohl (mp->vrf_id), ntohl (mp->max_msg_size));
119 
120  REPLY_MACRO (VL_API_SYSLOG_SET_SENDER_REPLY);
121 }
122 
123 static void
125 {
126  int rv = 0;
128  syslog_main_t *sm = &syslog_main;
129  u32 vrf_id;
130 
131  /* *INDENT-OFF* */
132  REPLY_MACRO2 (VL_API_SYSLOG_GET_SENDER_REPLY,
133  ({
134  clib_memcpy (&rmp->collector_address, &(sm->collector),
135  sizeof(ip4_address_t));
136  clib_memcpy (&rmp->src_address, &(sm->src_address),
137  sizeof(ip4_address_t));
138  rmp->collector_port = htons (sm->collector_port);
139  if (sm->fib_index == ~0)
140  vrf_id = ~0;
141  else
143  rmp->vrf_id = vrf_id;
144  rmp->max_msg_size = htonl (sm->max_msg_size);
145  }))
146  /* *INDENT-ON* */
147 }
148 
149 static void
151 {
152  vl_api_syslog_set_filter_reply_t *rmp;
153  syslog_main_t *sm = &syslog_main;
154  int rv = 0;
156 
157  rv = syslog_severity_decode (mp->severity, &s);
158  if (rv)
159  goto send_reply;
160 
161  sm->severity_filter = s;
162 
163 send_reply:
164  REPLY_MACRO (VL_API_SYSLOG_SET_FILTER_REPLY);
165 }
166 
167 static void
169 {
170  int rv = 0;
172  syslog_main_t *sm = &syslog_main;
173 
174  /* *INDENT-OFF* */
175  REPLY_MACRO2 (VL_API_SYSLOG_GET_FILTER_REPLY,
176  ({
178  }))
179  /* *INDENT-ON* */
180 }
181 
182 #include <vnet/syslog/syslog.api.c>
183 
184 static clib_error_t *
186 {
187  /*
188  * Set up the (msg_name, crc, message-id) table
189  */
191 
192  return 0;
193 }
194 
196 
197 /*
198  * fd.io coding-style-patch-verification: ON
199  *
200  * Local Variables:
201  * eval: (c-set-style "gnu")
202  * End:
203  */
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:1100
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:32
fib_table.h
vl_api_syslog_get_sender_reply_t
Get syslog sender configuration reply.
Definition: syslog.api:70
SYSLOG_API_SEVERITY_NOTICE
@ SYSLOG_API_SEVERITY_NOTICE
Definition: syslog.api:26
REPLY_MSG_ID_BASE
#define REPLY_MSG_ID_BASE
Definition: syslog_api.c:28
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:109
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:71
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
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
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:185
syslog.h
vl_api_syslog_set_sender_t
Set syslog sender configuration.
Definition: syslog.api:40
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
format_fns.h
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:150
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:168
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
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:124