Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 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. */ |
| 30 | extern vlib_packet_template_t ip6_neighbor_packet_template; |
| 31 | |
| 32 | extern void ip6_neighbor_advertise (vlib_main_t * vm, |
| 33 | vnet_main_t * vnm, |
| 34 | u32 sw_if_index, |
| 35 | const ip6_address_t * addr); |
| 36 | |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 37 | extern void ip6_neighbor_probe_dst (u32 sw_if_index, |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 38 | const ip6_address_t * dst); |
| 39 | |
| 40 | always_inline vlib_buffer_t * |
| 41 | ip6_neighbor_probe (vlib_main_t * vm, |
| 42 | vnet_main_t * vnm, |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 43 | u32 sw_if_index, |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 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; |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 48 | const ip_adjacency_t *adj; |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 49 | vlib_buffer_t *b0; |
| 50 | int bogus_length; |
| 51 | u32 bi0 = 0; |
| 52 | |
| 53 | h0 = vlib_packet_template_get_packet |
| 54 | (vm, &ip6_neighbor_packet_template, &bi0); |
| 55 | if (!h0) |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 56 | return NULL; |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 57 | |
Matthew Smith | 4fa3aad | 2020-08-04 15:26:16 -0500 | [diff] [blame] | 58 | /* if the interface has been disabled for ip6, later steps to retrieve |
| 59 | * an adjacency will result in a segv. |
| 60 | */ |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 61 | if (!ip6_link_is_enabled (sw_if_index)) |
Matthew Smith | 4fa3aad | 2020-08-04 15:26:16 -0500 | [diff] [blame] | 62 | return NULL; |
| 63 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 64 | b0 = vlib_get_buffer (vm, bi0); |
| 65 | |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 66 | hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * Destination address is a solicited node multicast address. |
| 70 | * We need to fill in |
| 71 | * the low 24 bits with low 24 bits of target's address. |
| 72 | */ |
| 73 | h0->ip.src_address = *src; |
| 74 | h0->ip.dst_address.as_u8[13] = dst->as_u8[13]; |
| 75 | h0->ip.dst_address.as_u8[14] = dst->as_u8[14]; |
| 76 | h0->ip.dst_address.as_u8[15] = dst->as_u8[15]; |
| 77 | |
| 78 | h0->neighbor.target_address = *dst; |
| 79 | |
| 80 | clib_memcpy (h0->link_layer_option.ethernet_address, |
| 81 | hw_if0->hw_address, vec_len (hw_if0->hw_address)); |
| 82 | |
| 83 | /* $$$$ appears we need this; why is the checksum non-zero? */ |
| 84 | h0->neighbor.icmp.checksum = 0; |
| 85 | h0->neighbor.icmp.checksum = |
| 86 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h0->ip, &bogus_length); |
| 87 | |
| 88 | ASSERT (bogus_length == 0); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 89 | |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 90 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index; |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 91 | |
| 92 | /* Use the link's mcast adj to ship the packet */ |
| 93 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 94 | ip6_link_get_mcast_adj (sw_if_index); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 95 | adj = adj_get (vnet_buffer (b0)->ip.adj_index[VLIB_TX]); |
| 96 | |
| 97 | b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
| 98 | |
| 99 | { |
| 100 | vlib_frame_t *f = vlib_get_frame_to_node (vm, adj->ia_node_index); |
| 101 | u32 *to_next = vlib_frame_vector_args (f); |
| 102 | to_next[0] = bi0; |
| 103 | f->n_vectors = 1; |
| 104 | vlib_put_frame_to_node (vm, adj->ia_node_index, f); |
| 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 | */ |