LCOV - code coverage report
Current view: top level - plugins/dhcp - dhcp4_packet.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 56 70 80.0 %
Date: 2023-10-26 01:39:38 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * dhcp4_packet.c: dhcp packet format functions
       3             :  *
       4             :  * Copyright (c) 2013 Cisco and/or its affiliates.
       5             :  * Licensed under the Apache License, Version 2.0 (the "License");
       6             :  * you may not use this file except in compliance with the License.
       7             :  * You may obtain a copy of the License at:
       8             :  *
       9             :  *     http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  * Unless required by applicable law or agreed to in writing, software
      12             :  * distributed under the License is distributed on an "AS IS" BASIS,
      13             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  * See the License for the specific language governing permissions and
      15             :  * limitations under the License.
      16             :  */
      17             : 
      18             : #include <dhcp/dhcp4_packet.h>
      19             : #include <vnet/ip/format.h>
      20             : 
      21             : u8 *
      22          17 : format_dhcp_packet_type (u8 * s, va_list * args)
      23             : {
      24          17 :   dhcp_packet_type_t pt = va_arg (*args, dhcp_packet_type_t);
      25             : 
      26          17 :   switch (pt)
      27             :     {
      28           7 :     case DHCP_PACKET_DISCOVER:
      29           7 :       s = format (s, "discover");
      30           7 :       break;
      31           2 :     case DHCP_PACKET_OFFER:
      32           2 :       s = format (s, "offer");
      33           2 :       break;
      34           7 :     case DHCP_PACKET_REQUEST:
      35           7 :       s = format (s, "request");
      36           7 :       break;
      37           1 :     case DHCP_PACKET_ACK:
      38           1 :       s = format (s, "ack");
      39           1 :       break;
      40           0 :     case DHCP_PACKET_NAK:
      41           0 :       s = format (s, "nack");
      42           0 :       break;
      43             :     }
      44          17 :   return (s);
      45             : }
      46             : 
      47             : u8 *
      48           3 : format_dhcp_header (u8 * s, va_list * args)
      49             : {
      50           3 :   dhcp_header_t *d = va_arg (*args, dhcp_header_t *);
      51           3 :   u32 max_bytes = va_arg (*args, u32);
      52             :   dhcp_option_t *o;
      53             :   u32 tmp;
      54             : 
      55           3 :   s = format (s, "opcode:%s", (d->opcode == 1 ? "request" : "reply"));
      56           3 :   s = format (s, " hw[type:%d addr-len:%d addr:%U]",
      57           3 :               d->hardware_type, d->hardware_address_length,
      58           3 :               format_hex_bytes, d->client_hardware_address,
      59           3 :               d->hardware_address_length);
      60           3 :   s = format (s, " hops%d", d->hops);
      61           3 :   s = format (s, " transaction-ID:0x%x", d->transaction_identifier);
      62           3 :   s = format (s, " seconds:%d", d->seconds);
      63           3 :   s = format (s, " flags:0x%x", d->flags);
      64           3 :   s = format (s, " client:%U", format_ip4_address, &d->client_ip_address);
      65           3 :   s = format (s, " your:%U", format_ip4_address, &d->your_ip_address);
      66           3 :   s = format (s, " server:%U", format_ip4_address, &d->server_ip_address);
      67           3 :   s = format (s, " gateway:%U", format_ip4_address, &d->gateway_ip_address);
      68           3 :   s = format (s, " cookie:%U", format_ip4_address, &d->magic_cookie);
      69             : 
      70           3 :   o = (dhcp_option_t *) d->options;
      71             : 
      72          12 :   while (o->option != 0xFF /* end of options */  &&
      73           9 :          (u8 *) o < (u8 *) d + max_bytes)
      74             :     {
      75           9 :       switch (o->option)
      76             :         {
      77           3 :         case 53:                /* dhcp message type */
      78           3 :           tmp = o->data[0];
      79             :           s =
      80           3 :             format (s, ", option-53: type:%U", format_dhcp_packet_type, tmp);
      81           3 :           break;
      82           1 :         case 54:                /* dhcp server address */
      83           1 :           s = format (s, ", option-54: server:%U",
      84             :                       format_ip4_address, &o->data_as_u32[0]);
      85           1 :           break;
      86           0 :         case 58:                /* lease renew time in seconds */
      87           0 :           s = format (s, ", option-58: renewal:%d",
      88             :                       clib_host_to_net_u32 (o->data_as_u32[0]));
      89           0 :           break;
      90           1 :         case 1:         /* subnet mask */
      91           1 :           s = format (s, ", option-1: subnet-mask:%d",
      92             :                       clib_host_to_net_u32 (o->data_as_u32[0]));
      93           1 :           break;
      94           1 :         case 3:         /* router address */
      95           1 :           s = format (s, ", option-3: router:%U",
      96             :                       format_ip4_address, &o->data_as_u32[0]);
      97           1 :           break;
      98           0 :         case 6:         /* domain server address */
      99           0 :           s = format (s, ", option-6: domian-server:%U",
     100           0 :                       format_hex_bytes, o->data, o->length);
     101           0 :           break;
     102           0 :         case 12:                /* hostname */
     103           0 :           s = format (s, ", option-12: hostname:%U",
     104           0 :                       format_hex_bytes, o->data, o->length);
     105           0 :           break;
     106           3 :         default:
     107           3 :           tmp = o->option;
     108           3 :           s = format (s, " option-%d: skipped", tmp);
     109           3 :           break;
     110             :         }
     111           9 :       o = (dhcp_option_t *) (((u8 *) o) + (o->length + 2));
     112             :     }
     113           3 :   return (s);
     114             : }
     115             : 
     116             : /*
     117             :  * fd.io coding-style-patch-verification: ON
     118             :  *
     119             :  * Local Variables:
     120             :  * eval: (c-set-style "gnu")
     121             :  * End:
     122             :  */

Generated by: LCOV version 1.14