FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
ip6_neighbor.h
Go to the documentation of this file.
1 /*
2  * ip/ip6_neighbor.h: IP6 NS transmit
3  *
4  * Copyright (c) 2019 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 __IP6_NEIGHBOR_H__
19 #define __IP6_NEIGHBOR_H__
20 
21 #include <vlib/vlib.h>
22 #include <vnet/ip/format.h>
23 #include <vnet/ip/ip6.h>
24 #include <vnet/ip/ip6_link.h>
25 #include <vnet/ip/icmp46_packet.h>
26 #include <vnet/ethernet/ethernet.h>
27 #include <vnet/adj/adj_internal.h>
28 
29 /* Template used to generate IP6 neighbor solicitation packets. */
31 
33  vnet_main_t * vnm,
35  const ip6_address_t * addr);
36 
37 extern void ip6_neighbor_probe_dst (const ip_adjacency_t * adj,
38  const ip6_address_t * dst);
39 
42  vnet_main_t * vnm,
43  const ip_adjacency_t * adj,
44  const ip6_address_t * src, const ip6_address_t * dst)
45 {
46  icmp6_neighbor_solicitation_header_t *h0;
47  vnet_hw_interface_t *hw_if0;
48  vlib_buffer_t *b0;
49  int bogus_length;
50  u32 bi0 = 0;
51 
53  (vm, &ip6_neighbor_packet_template, &bi0);
54  if (!h0)
55  return NULL;;
56 
57  /* if the interface has been disabled for ip6, later steps to retrieve
58  * an adjacency will result in a segv.
59  */
60  if (!ip6_link_is_enabled (adj->rewrite_header.sw_if_index))
61  return NULL;
62 
63  b0 = vlib_get_buffer (vm, bi0);
64 
65  hw_if0 = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index);
66 
67  /*
68  * Destination address is a solicited node multicast address.
69  * We need to fill in
70  * the low 24 bits with low 24 bits of target's address.
71  */
72  h0->ip.src_address = *src;
73  h0->ip.dst_address.as_u8[13] = dst->as_u8[13];
74  h0->ip.dst_address.as_u8[14] = dst->as_u8[14];
75  h0->ip.dst_address.as_u8[15] = dst->as_u8[15];
76 
77  h0->neighbor.target_address = *dst;
78 
79  clib_memcpy (h0->link_layer_option.ethernet_address,
80  hw_if0->hw_address, vec_len (hw_if0->hw_address));
81 
82  /* $$$$ appears we need this; why is the checksum non-zero? */
83  h0->neighbor.icmp.checksum = 0;
84  h0->neighbor.icmp.checksum =
85  ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip, &bogus_length);
86 
87  ASSERT (bogus_length == 0);
89 
90  vnet_buffer (b0)->sw_if_index[VLIB_TX] = adj->rewrite_header.sw_if_index;
91 
92  /* Use the link's mcast adj to ship the packet */
93  vnet_buffer (b0)->ip.adj_index[VLIB_TX] =
94  ip6_link_get_mcast_adj (adj->rewrite_header.sw_if_index);
95  adj = adj_get (vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
96 
97  b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
98 
99  {
101  u32 *to_next = vlib_frame_vector_args (f);
102  to_next[0] = bi0;
103  f->n_vectors = 1;
105  }
106 
107  return b0;
108 }
109 
110 #endif
111 
112 /*
113  * fd.io coding-style-patch-verification: ON
114  *
115  * Local Variables:
116  * eval: (c-set-style "gnu")
117  * End:
118  */
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
static vlib_buffer_t * ip6_neighbor_probe(vlib_main_t *vm, vnet_main_t *vnm, const ip_adjacency_t *adj, const ip6_address_t *src, const ip6_address_t *dst)
Definition: ip6_neighbor.h:41
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
IP unicast adjacency.
Definition: adj.h:227
vl_api_address_t src
Definition: gre.api:54
vlib_main_t * vm
Definition: in2out_ed.c:1582
vhost_vring_addr_t addr
Definition: vhost_user.h:111
#define clib_memcpy(d, s, n)
Definition: string.h:180
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:459
void * vlib_packet_template_get_packet(vlib_main_t *vm, vlib_packet_template_t *t, u32 *bi_result)
Definition: buffer.c:400
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:182
unsigned int u32
Definition: types.h:88
void ip6_neighbor_probe_dst(const ip_adjacency_t *adj, const ip6_address_t *dst)
Definition: ip6_neighbor.c:21
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:216
u32 ia_node_index
The VLIB node in which this adj is used to forward packets.
Definition: adj.h:322
#define always_inline
Definition: ipsec.h:28
vl_api_address_t dst
Definition: gre.api:55
u16 n_vectors
Definition: node.h:396
u16 ip6_tcp_udp_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip6_header_t *ip0, int *bogus_lengthp)
Definition: ip6_forward.c:1095
#define ASSERT(truth)
Definition: defs.h:47
vlib_packet_template_t ip6_neighbor_packet_template
Definition: ip6_neighbor.c:296
vl_api_address_t ip
Definition: l2.api:501
void ip6_neighbor_advertise(vlib_main_t *vm, vnet_main_t *vnm, u32 sw_if_index, const ip6_address_t *addr)
Definition: ip6_neighbor.c:36
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:492
VLIB buffer representation.
Definition: buffer.h:102
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:297
#define vnet_buffer(b)
Definition: buffer.h:417
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33