1cbe25aabSNeale Ranns/*
2cbe25aabSNeale Ranns * Copyright (c) 2019 Cisco and/or its affiliates.
3cbe25aabSNeale Ranns * Licensed under the Apache License, Version 2.0 (the "License");
4cbe25aabSNeale Ranns * you may not use this file except in compliance with the License.
5cbe25aabSNeale Ranns * You may obtain a copy of the License at:
6cbe25aabSNeale Ranns *
7cbe25aabSNeale Ranns *     http://www.apache.org/licenses/LICENSE-2.0
8cbe25aabSNeale Ranns *
9cbe25aabSNeale Ranns * Unless required by applicable law or agreed to in writing, software
10cbe25aabSNeale Ranns * distributed under the License is distributed on an "AS IS" BASIS,
11cbe25aabSNeale Ranns * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cbe25aabSNeale Ranns * See the License for the specific language governing permissions and
13cbe25aabSNeale Ranns * limitations under the License.
14cbe25aabSNeale Ranns */
15cbe25aabSNeale Ranns
16cbe25aabSNeale Ranns#ifndef __IP4_NEIGHBOR_H__
17cbe25aabSNeale Ranns#define __IP4_NEIGHBOR_H__
18cbe25aabSNeale Ranns
19cbe25aabSNeale Ranns#include <vnet/ip/ip.h>
20cbe25aabSNeale Ranns#include <vnet/ethernet/arp_packet.h>
21cbe25aabSNeale Ranns
22cbe25aabSNeale Rannsextern void ip4_neighbor_probe_dst (const ip_adjacency_t * adj,
23cbe25aabSNeale Ranns				    const ip4_address_t * dst);
24cbe25aabSNeale Rannsextern void ip4_neighbor_advertise (vlib_main_t * vm,
25cbe25aabSNeale Ranns				    vnet_main_t * vnm,
26cbe25aabSNeale Ranns				    u32 sw_if_index,
27cbe25aabSNeale Ranns				    const ip4_address_t * addr);
28cbe25aabSNeale Ranns
29cbe25aabSNeale Rannsalways_inline vlib_buffer_t *
30cbe25aabSNeale Rannsip4_neighbor_probe (vlib_main_t * vm,
31cbe25aabSNeale Ranns		    vnet_main_t * vnm,
32cbe25aabSNeale Ranns		    const ip_adjacency_t * adj0,
33cbe25aabSNeale Ranns		    const ip4_address_t * src, const ip4_address_t * dst)
34cbe25aabSNeale Ranns{
35cbe25aabSNeale Ranns  vnet_hw_interface_t *hw_if0;
36cbe25aabSNeale Ranns  ethernet_arp_header_t *h0;
37cbe25aabSNeale Ranns  vlib_buffer_t *b0;
38cbe25aabSNeale Ranns  u32 bi0;
39cbe25aabSNeale Ranns
40cbe25aabSNeale Ranns  /* Send ARP request. */
41cbe25aabSNeale Ranns  h0 = vlib_packet_template_get_packet (vm,
42cbe25aabSNeale Ranns					&ip4_main.ip4_arp_request_packet_template,
43cbe25aabSNeale Ranns					&bi0);
44cbe25aabSNeale Ranns  /* Seems we're out of buffers */
45cbe25aabSNeale Ranns  if (PREDICT_FALSE (!h0))
46cbe25aabSNeale Ranns    return (NULL);
47cbe25aabSNeale Ranns
48cbe25aabSNeale Ranns  b0 = vlib_get_buffer (vm, bi0);
49cbe25aabSNeale Ranns
50cbe25aabSNeale Ranns  /* Add rewrite/encap string for ARP packet. */
51cbe25aabSNeale Ranns  vnet_rewrite_one_header (adj0[0], h0, sizeof (ethernet_header_t));
52cbe25aabSNeale Ranns
53cbe25aabSNeale Ranns  hw_if0 = vnet_get_sup_hw_interface (vnm, adj0->rewrite_header.sw_if_index);
54cbe25aabSNeale Ranns
55cbe25aabSNeale Ranns  /* Src ethernet address in ARP header. */
56cbe25aabSNeale Ranns  mac_address_from_bytes (&h0->ip4_over_ethernet[0].mac, hw_if0->hw_address);
57cbe25aabSNeale Ranns
58cbe25aabSNeale Ranns  h0->ip4_over_ethernet[0].ip4 = *src;
59cbe25aabSNeale Ranns  h0->ip4_over_ethernet[1].ip4 = *dst;
60cbe25aabSNeale Ranns
61cbe25aabSNeale Ranns  VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
62cbe25aabSNeale Ranns  vnet_buffer (b0)->sw_if_index[VLIB_TX] = adj0->rewrite_header.sw_if_index;
63cbe25aabSNeale Ranns
64cbe25aabSNeale Ranns  vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
65cbe25aabSNeale Ranns
66cbe25aabSNeale Ranns  {
67cbe25aabSNeale Ranns    vlib_frame_t *f = vlib_get_frame_to_node (vm, hw_if0->output_node_index);
68cbe25aabSNeale Ranns    u32 *to_next = vlib_frame_vector_args (f);
69cbe25aabSNeale Ranns    to_next[0] = bi0;
70cbe25aabSNeale Ranns    f->n_vectors = 1;
71cbe25aabSNeale Ranns    vlib_put_frame_to_node (vm, hw_if0->output_node_index, f);
72cbe25aabSNeale Ranns  }
73cbe25aabSNeale Ranns
74cbe25aabSNeale Ranns  return b0;
75cbe25aabSNeale Ranns}
76cbe25aabSNeale Ranns
77cbe25aabSNeale Ranns#endif
78cbe25aabSNeale Ranns
79cbe25aabSNeale Ranns/*
80cbe25aabSNeale Ranns * fd.io coding-style-patch-verification: ON
81cbe25aabSNeale Ranns *
82cbe25aabSNeale Ranns * Local Variables:
83cbe25aabSNeale Ranns * eval: (c-set-style "gnu")
84cbe25aabSNeale Ranns * End:
85cbe25aabSNeale Ranns */
86