FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
arp_packet.h
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 
18 #ifndef __ARP_PACKET_H__
19 #define __ARP_PACKET_H__
20 
21 #include <vnet/arp/arp.h>
22 
23 /* Either we drop the packet or we send a reply to the sender. */
24 typedef enum
25 {
30 
33  vlib_buffer_t * p0,
34  u32 sw_if_index0,
35  const ip4_address_t * if_addr0,
37 {
38  vnet_hw_interface_t *hw_if0;
39  u8 *rewrite0, rewrite0_len;
40  ethernet_header_t *eth_tx;
41  u32 next0;
42 
43  /* Send a reply.
44  An adjacency to the sender is not always present,
45  so we use the interface to build us a rewrite string
46  which will contain all the necessary tags. */
47  rewrite0 = ethernet_build_rewrite (vnm, sw_if_index0,
48  VNET_LINK_ARP, eth_rx->src_address);
49  rewrite0_len = vec_len (rewrite0);
50 
51  /* Figure out how much to rewind current data from adjacency. */
52  vlib_buffer_advance (p0, -rewrite0_len);
53  eth_tx = vlib_buffer_get_current (p0);
54 
55  vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
56  hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
57 
58  /* Send reply back through input interface */
59  vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
61 
62  arp0->opcode = clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply);
63 
64  arp0->ip4_over_ethernet[1] = arp0->ip4_over_ethernet[0];
65 
67  hw_if0->hw_address);
68  clib_mem_unaligned (&arp0->ip4_over_ethernet[0].ip4.data_u32, u32) =
69  if_addr0->data_u32;
70 
71  /* Hardware must be ethernet-like. */
72  ASSERT (vec_len (hw_if0->hw_address) == 6);
73 
74  /* the rx nd tx ethernet headers wil overlap in the case
75  * when we received a tagged VLAN=0 packet, but we are sending
76  * back untagged */
77  clib_memcpy_fast (eth_tx, rewrite0, vec_len (rewrite0));
78  vec_free (rewrite0);
79 
80  return (next0);
81 }
82 
83 #endif
84 
85 /*
86  * fd.io coding-style-patch-verification: ON
87  *
88  * Local Variables:
89  * eval: (c-set-style "gnu")
90  * End:
91  */
ethernet_arp_header_t::opcode
u16 opcode
Definition: arp_packet.h:139
ethernet_build_rewrite
u8 * ethernet_build_rewrite(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
build a rewrite string to use for sending packets of type 'link_type' to 'dst_address'
Definition: interface.c:83
arp_reply_next_t
arp_reply_next_t
Definition: arp_packet.h:24
vnet_hw_interface_t::hw_address
u8 * hw_address
Definition: interface.h:649
ethernet_header_t::src_address
u8 src_address[6]
Definition: packet.h:56
ethernet_arp_header_t::ip4_over_ethernet
ethernet_arp_ip4_over_ethernet_address_t ip4_over_ethernet[2]
Definition: arp_packet.h:142
VNET_LINK_ARP
@ VNET_LINK_ARP
Definition: interface.h:351
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
ARP_REPLY_NEXT_DROP
@ ARP_REPLY_NEXT_DROP
Definition: arp_packet.h:26
ethernet_arp_header_t
Definition: arp_packet.h:133
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
static_always_inline
#define static_always_inline
Definition: clib.h:112
ethernet_header_t
Definition: packet.h:52
clib_mem_unaligned
#define clib_mem_unaligned(pointer, type)
Definition: types.h:155
ip4_address_t
Definition: ip4_packet.h:50
ARP_REPLY_N_NEXT
@ ARP_REPLY_N_NEXT
Definition: arp_packet.h:28
ARP_REPLY_NEXT_REPLY_TX
@ ARP_REPLY_NEXT_REPLY_TX
Definition: arp_packet.h:27
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
u32
unsigned int u32
Definition: types.h:88
vnet_get_sup_hw_interface
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:92
ip4_address_t::data_u32
u32 data_u32
Definition: ip4_packet.h:53
arp_mk_reply
static_always_inline u32 arp_mk_reply(vnet_main_t *vnm, vlib_buffer_t *p0, u32 sw_if_index0, const ip4_address_t *if_addr0, ethernet_arp_header_t *arp0, ethernet_header_t *eth_rx)
Definition: arp_packet.h:32
u8
unsigned char u8
Definition: types.h:56
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
arp.h
mac_address_from_bytes
static_always_inline void mac_address_from_bytes(mac_address_t *mac, const u8 *bytes)
Definition: mac_address.h:92
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111