summaryrefslogtreecommitdiffstats
path: root/src/vnet/syslog/syslog_udp.c
diff options
context:
space:
mode:
authorMatus Fabian <matfabia@cisco.com>2018-11-19 04:25:32 -0800
committerOle Trøan <otroan@employees.org>2018-11-22 06:31:53 +0000
commitb4515b4be4ead1ea5d0af205989cf313272e8770 (patch)
tree8a87c5c74cd8583690bdcf612727a2b4f4136cf2 /src/vnet/syslog/syslog_udp.c
parent19ca78fbd7567c676beefc2b511dfdcd9f20201a (diff)
Add RFC5424 syslog protocol support (VPP-1139)
Syslog protocol logging transport event messages across network over UDP protocol based on RFC5426. Change-Id: Ica74b40bcc2e6d0fbd41e9bf78e76395fbabab3c Signed-off-by: Matus Fabian <matfabia@cisco.com>
Diffstat (limited to 'src/vnet/syslog/syslog_udp.c')
-rw-r--r--src/vnet/syslog/syslog_udp.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/vnet/syslog/syslog_udp.c b/src/vnet/syslog/syslog_udp.c
new file mode 100644
index 00000000000..f4fa1d0baf5
--- /dev/null
+++ b/src/vnet/syslog/syslog_udp.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file syslog protocol UDP transport layer implementation (RFC5426)
+ */
+
+#include <vnet/syslog/syslog_udp.h>
+#include <vnet/ip/ip4.h>
+#include <vnet/udp/udp_packet.h>
+
+void
+syslog_add_udp_transport (vlib_main_t * vm, u32 bi)
+{
+ syslog_main_t *sm = &syslog_main;
+ vlib_buffer_t *b = vlib_get_buffer (vm, bi);
+ ip4_header_t *ip;
+ udp_header_t *udp;
+
+ vlib_buffer_advance (b, -(sizeof (ip4_header_t) + sizeof (udp_header_t)));
+
+ b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
+ vnet_buffer (b)->sw_if_index[VLIB_RX] = 0;
+ vnet_buffer (b)->sw_if_index[VLIB_TX] = sm->fib_index;
+
+ ip = vlib_buffer_get_current (b);
+ clib_memset (ip, 0, sizeof (*ip));
+ udp = (udp_header_t *) (ip + 1);
+ clib_memset (udp, 0, sizeof (*udp));
+
+ ip->ip_version_and_header_length = 0x45;
+ ip->flags_and_fragment_offset =
+ clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
+ ip->ttl = 255;
+ ip->protocol = IP_PROTOCOL_UDP;
+ ip->src_address.as_u32 = sm->src_address.as_u32;
+ ip->dst_address.as_u32 = sm->collector.as_u32;
+
+ udp->src_port = udp->dst_port = clib_host_to_net_u16 (sm->collector_port);
+
+ const u16 ip_length = vlib_buffer_length_in_chain (vm, b);
+ ip->length = clib_host_to_net_u16 (ip_length);
+ ip->checksum = ip4_header_checksum (ip);
+
+ const u16 udp_length = ip_length - (sizeof (ip4_header_t));
+ udp->length = clib_host_to_net_u16 (udp_length);
+ /* RFC5426 3.6. */
+ udp->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip);
+ if (udp->checksum == 0)
+ udp->checksum = 0xffff;
+
+ b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */