FD.io VPP  v20.05-21-gb1500e9ff
Vector Packet Processing
arp_packet.c
Go to the documentation of this file.
1 /*
2  * ethernet/arp.c: IP v4 ARP node
3  *
4  * Copyright (c) 2010 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 
19 #include <vnet/ethernet/ethernet.h>
20 #include <vnet/ip/format.h>
21 
22 u8 *
23 format_ethernet_arp_opcode (u8 * s, va_list * va)
24 {
26  char *t = 0;
27  switch (o)
28  {
29 #define _(f) case ETHERNET_ARP_OPCODE_##f: t = #f; break;
31 #undef _
32 
33  default:
34  return format (s, "unknown 0x%x", o);
35  }
36 
37  return format (s, "%s", t);
38 }
39 
40 u8 *
42 {
44  char *t = 0;
45  switch (h)
46  {
47 #define _(n,f) case n: t = #f; break;
49 #undef _
50 
51  default:
52  return format (s, "unknown 0x%x", h);
53  }
54 
55  return format (s, "%s", t);
56 }
57 
58 u8 *
59 format_ethernet_arp_header (u8 * s, va_list * va)
60 {
62  u32 max_header_bytes = va_arg (*va, u32);
63  u32 indent;
64  u16 l2_type, l3_type;
65 
66  if (max_header_bytes != 0 && sizeof (a[0]) > max_header_bytes)
67  return format (s, "ARP header truncated");
68 
69  l2_type = clib_net_to_host_u16 (a->l2_type);
70  l3_type = clib_net_to_host_u16 (a->l3_type);
71 
72  indent = format_get_indent (s);
73 
74  s = format (s, "%U, type %U/%U, address size %d/%d",
75  format_ethernet_arp_opcode, clib_net_to_host_u16 (a->opcode),
77  format_ethernet_type, l3_type,
79 
80  if (l2_type == ETHERNET_ARP_HARDWARE_TYPE_ethernet
81  && l3_type == ETHERNET_TYPE_IP4)
82  {
83  s = format (s, "\n%U%U/%U -> %U/%U",
84  format_white_space, indent,
89  }
90  else
91  {
92  uword n2 = a->n_l2_address_bytes;
93  uword n3 = a->n_l3_address_bytes;
94  s = format (s, "\n%U%U/%U -> %U/%U",
95  format_white_space, indent,
96  format_hex_bytes, a->data + 0 * n2 + 0 * n3, n2,
97  format_hex_bytes, a->data + 1 * n2 + 0 * n3, n3,
98  format_hex_bytes, a->data + 1 * n2 + 1 * n3, n2,
99  format_hex_bytes, a->data + 2 * n2 + 1 * n3, n3);
100  }
101 
102  return s;
103 }
104 
105 /*
106  * fd.io coding-style-patch-verification: ON
107  *
108  * Local Variables:
109  * eval: (c-set-style "gnu")
110  * End:
111  */
a
Definition: bitmap.h:538
u8 * format_ethernet_arp_opcode(u8 *s, va_list *va)
Definition: arp_packet.c:23
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u8 * format_ethernet_arp_hardware_type(u8 *s, va_list *va)
Definition: arp_packet.c:41
unsigned char u8
Definition: types.h:56
format_function_t format_ip4_address
Definition: format.h:73
ethernet_arp_ip4_over_ethernet_address_t ip4_over_ethernet[2]
Definition: arp_packet.h:142
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:129
u8 * format_hex_bytes(u8 *s, va_list *va)
Definition: std-formats.c:84
unsigned int u32
Definition: types.h:88
#define foreach_ethernet_arp_opcode
Definition: arp_packet.h:64
unsigned short u16
Definition: types.h:57
vec_header_t h
Definition: buffer.c:322
u8 * format_ethernet_type(u8 *s, va_list *args)
Definition: format.c:64
ethernet_arp_opcode_t
Definition: arp_packet.h:99
ethernet_arp_hardware_type_t
Definition: arp_packet.h:92
u64 uword
Definition: types.h:112
u8 * format_ethernet_arp_header(u8 *s, va_list *va)
Definition: arp_packet.c:59
u8 * format_mac_address_t(u8 *s, va_list *args)
Definition: mac_address.c:27