FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
ip4_neighbor.h
Go to the documentation of this file.
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>
21 
23  const ip4_address_t * dst);
25  vnet_main_t * vnm,
27  const ip4_address_t * addr);
28 
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;
37  vlib_buffer_t *b0;
38  u32 bi0;
39 
40  hw_if0 = vnet_get_sup_hw_interface (vnm, adj0->rewrite_header.sw_if_index);
41 
42  /* if (NULL == hw_if0->hw_address) */
43  /* return (NULL); */
44 
45  /* Send ARP request. */
48  &bi0);
49  /* Seems we're out of buffers */
50  if (PREDICT_FALSE (!h0))
51  return (NULL);
52 
53  b0 = vlib_get_buffer (vm, bi0);
54 
55  /* Add rewrite/encap string for ARP packet. */
56  vnet_rewrite_one_header (adj0[0], h0, sizeof (ethernet_header_t));
57 
58  /* Src ethernet address in ARP header. */
60 
61  h0->ip4_over_ethernet[0].ip4 = *src;
62  h0->ip4_over_ethernet[1].ip4 = *dst;
63 
64  vnet_buffer (b0)->sw_if_index[VLIB_TX] = adj0->rewrite_header.sw_if_index;
65 
66  vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes);
67 
68  {
70  u32 *to_next = vlib_frame_vector_args (f);
71  to_next[0] = bi0;
72  f->n_vectors = 1;
74  }
75 
76  return b0;
77 }
78 
79 #endif
80 
81 /*
82  * fd.io coding-style-patch-verification: ON
83  *
84  * Local Variables:
85  * eval: (c-set-style "gnu")
86  * End:
87  */
vlib_frame_t::n_vectors
u16 n_vectors
Definition: node.h:387
ip4_main
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1104
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
f
vlib_frame_t * f
Definition: interface_output.c:1098
vnet_hw_interface_t::hw_address
u8 * hw_address
Definition: interface.h:649
ethernet_arp_header_t::ip4_over_ethernet
ethernet_arp_ip4_over_ethernet_address_t ip4_over_ethernet[2]
Definition: arp_packet.h:142
ip4_main_t::ip4_arp_request_packet_template
vlib_packet_template_t ip4_arp_request_packet_template
Template used to generate IP4 ARP packets.
Definition: ip4.h:148
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
vlib_frame_t
Definition: node.h:372
vlib_get_frame_to_node
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:184
ip4_neighbor_probe_dst
void ip4_neighbor_probe_dst(u32 sw_if_index, const ip4_address_t *dst)
Definition: ip4_neighbor.c:57
ethernet_arp_header_t
Definition: arp_packet.h:133
vlib_put_frame_to_node
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:218
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
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
ethernet_header_t
Definition: packet.h:52
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
ip_adjacency_t_
IP unicast adjacency.
Definition: adj.h:235
ip4_neighbor_probe
static vlib_buffer_t * ip4_neighbor_probe(vlib_main_t *vm, vnet_main_t *vnm, const ip_adjacency_t *adj0, const ip4_address_t *src, const ip4_address_t *dst)
Definition: ip4_neighbor.h:30
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
vlib_packet_template_get_packet
void * vlib_packet_template_get_packet(vlib_main_t *vm, vlib_packet_template_t *t, u32 *bi_result)
Definition: buffer.c:377
ip.h
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
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
vlib_main_t
Definition: main.h:102
vnet_hw_interface_t::output_node_index
u32 output_node_index
Definition: interface.h:653
arp_packet.h
vnet_rewrite_one_header
#define vnet_rewrite_one_header(rw0, p0, most_likely_size)
Definition: rewrite.h:218
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
ip4_neighbor_advertise
void ip4_neighbor_advertise(vlib_main_t *vm, vnet_main_t *vnm, u32 sw_if_index, const ip4_address_t *addr)
Definition: ip4_neighbor.c:71
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