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