2 * ethernet/arp.c: IP v4 ARP node
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __ARP_PACKET_H__
19 #define __ARP_PACKET_H__
21 #include <vnet/arp/arp.h>
23 /* Either we drop the packet or we send a reply to the sender. */
27 ARP_REPLY_NEXT_REPLY_TX,
31 static_always_inline u32
32 arp_mk_reply (vnet_main_t * vnm,
35 const ip4_address_t * if_addr0,
36 ethernet_arp_header_t * arp0, ethernet_header_t * eth_rx)
38 vnet_hw_interface_t *hw_if0;
39 u8 *rewrite0, rewrite0_len;
40 ethernet_header_t *eth_tx;
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);
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);
55 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
56 hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index0);
58 /* Send reply back through input interface */
59 vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0;
60 next0 = ARP_REPLY_NEXT_REPLY_TX;
62 arp0->opcode = clib_host_to_net_u16 (ETHERNET_ARP_OPCODE_reply);
64 arp0->ip4_over_ethernet[1] = arp0->ip4_over_ethernet[0];
66 mac_address_from_bytes (&arp0->ip4_over_ethernet[0].mac,
68 clib_mem_unaligned (&arp0->ip4_over_ethernet[0].ip4.data_u32, u32) =
71 /* Hardware must be ethernet-like. */
72 ASSERT (vec_len (hw_if0->hw_address) == 6);
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
77 clib_memcpy_fast (eth_tx, rewrite0, vec_len (rewrite0));
86 * fd.io coding-style-patch-verification: ON
89 * eval: (c-set-style "gnu")