2 * ip/ip6_neighbor.h: IP6 NS transmit
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:
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 __IP6_NEIGHBOR_H__
19 #define __IP6_NEIGHBOR_H__
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>
29 /* Template used to generate IP6 neighbor solicitation packets. */
30 extern vlib_packet_template_t ip6_neighbor_packet_template;
32 extern void ip6_neighbor_advertise (vlib_main_t * vm,
35 const ip6_address_t * addr);
37 extern void ip6_neighbor_probe_dst (const ip_adjacency_t * adj,
38 const ip6_address_t * dst);
40 always_inline vlib_buffer_t *
41 ip6_neighbor_probe (vlib_main_t * vm,
43 const ip_adjacency_t * adj,
44 const ip6_address_t * src, const ip6_address_t * dst)
46 icmp6_neighbor_solicitation_header_t *h0;
47 vnet_hw_interface_t *hw_if0;
52 h0 = vlib_packet_template_get_packet
53 (vm, &ip6_neighbor_packet_template, &bi0);
57 b0 = vlib_get_buffer (vm, bi0);
59 hw_if0 = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index);
62 * Destination address is a solicited node multicast address.
64 * the low 24 bits with low 24 bits of target's address.
66 h0->ip.src_address = *src;
67 h0->ip.dst_address.as_u8[13] = dst->as_u8[13];
68 h0->ip.dst_address.as_u8[14] = dst->as_u8[14];
69 h0->ip.dst_address.as_u8[15] = dst->as_u8[15];
71 h0->neighbor.target_address = *dst;
73 clib_memcpy (h0->link_layer_option.ethernet_address,
74 hw_if0->hw_address, vec_len (hw_if0->hw_address));
76 /* $$$$ appears we need this; why is the checksum non-zero? */
77 h0->neighbor.icmp.checksum = 0;
78 h0->neighbor.icmp.checksum =
79 ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip, &bogus_length);
81 ASSERT (bogus_length == 0);
82 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0);
84 vnet_buffer (b0)->sw_if_index[VLIB_TX] = adj->rewrite_header.sw_if_index;
86 /* Use the link's mcast adj to ship the packet */
87 vnet_buffer (b0)->ip.adj_index[VLIB_TX] =
88 ip6_link_get_mcast_adj (adj->rewrite_header.sw_if_index);
89 adj = adj_get (vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
91 b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
94 vlib_frame_t *f = vlib_get_frame_to_node (vm, adj->ia_node_index);
95 u32 *to_next = vlib_frame_vector_args (f);
98 vlib_put_frame_to_node (vm, adj->ia_node_index, f);
107 * fd.io coding-style-patch-verification: ON
110 * eval: (c-set-style "gnu")