LCOV - code coverage report
Current view: top level - vnet/syslog - syslog_udp.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 28 29 96.6 %
Date: 2023-10-26 01:39:38 Functions: 1 1 100.0 %

          Line data    Source code
       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             :  * @file syslog_udp.c
      17             :  * syslog protocol UDP transport layer implementation (RFC5426)
      18             :  */
      19             : 
      20             : #include <vnet/syslog/syslog_udp.h>
      21             : #include <vnet/ip/ip4.h>
      22             : #include <vnet/udp/udp_packet.h>
      23             : 
      24             : void
      25          42 : syslog_add_udp_transport (vlib_main_t * vm, u32 bi)
      26             : {
      27          42 :   syslog_main_t *sm = &syslog_main;
      28          42 :   vlib_buffer_t *b = vlib_get_buffer (vm, bi);
      29             :   ip4_header_t *ip;
      30             :   udp_header_t *udp;
      31             : 
      32          42 :   vlib_buffer_advance (b, -(sizeof (ip4_header_t) + sizeof (udp_header_t)));
      33             : 
      34          42 :   b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
      35          42 :   vnet_buffer (b)->sw_if_index[VLIB_RX] = 0;
      36          42 :   vnet_buffer (b)->sw_if_index[VLIB_TX] = sm->fib_index;
      37             : 
      38          42 :   ip = vlib_buffer_get_current (b);
      39          42 :   clib_memset (ip, 0, sizeof (*ip));
      40          42 :   udp = (udp_header_t *) (ip + 1);
      41          42 :   clib_memset (udp, 0, sizeof (*udp));
      42             : 
      43          42 :   ip->ip_version_and_header_length = 0x45;
      44          42 :   ip->flags_and_fragment_offset =
      45          42 :     clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
      46          42 :   ip->ttl = 255;
      47          42 :   ip->protocol = IP_PROTOCOL_UDP;
      48          42 :   ip->src_address.as_u32 = sm->src_address.as_u32;
      49          42 :   ip->dst_address.as_u32 = sm->collector.as_u32;
      50             : 
      51          42 :   udp->src_port = udp->dst_port = clib_host_to_net_u16 (sm->collector_port);
      52             : 
      53          42 :   const u16 ip_length = vlib_buffer_length_in_chain (vm, b);
      54          42 :   ip->length = clib_host_to_net_u16 (ip_length);
      55          42 :   ip->checksum = ip4_header_checksum (ip);
      56             : 
      57          42 :   const u16 udp_length = ip_length - (sizeof (ip4_header_t));
      58          42 :   udp->length = clib_host_to_net_u16 (udp_length);
      59             :   /* RFC5426 3.6. */
      60          42 :   udp->checksum = ip4_tcp_udp_compute_checksum (vm, b, ip);
      61          42 :   if (udp->checksum == 0)
      62           0 :     udp->checksum = 0xffff;
      63             : 
      64          42 :   b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
      65          42 : }
      66             : 
      67             : /*
      68             :  * fd.io coding-style-patch-verification: ON
      69             :  *
      70             :  * Local Variables:
      71             :  * eval: (c-set-style "gnu")
      72             :  * End:
      73             :  */

Generated by: LCOV version 1.14