Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 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> |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 21 | #include <vnet/ip-neighbor/ip_neighbor_types.h> |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 22 | |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 23 | extern void ip4_neighbor_probe_dst (u32 sw_if_index, u32 thread_index, |
| 24 | const ip4_address_t *dst); |
| 25 | extern void ip4_neighbor_advertise (vlib_main_t *vm, vnet_main_t *vnm, |
| 26 | u32 sw_if_index, u32 thread_index, |
| 27 | const ip4_address_t *addr); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 28 | |
| 29 | always_inline vlib_buffer_t * |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 30 | ip4_neighbor_probe (vlib_main_t *vm, vnet_main_t *vnm, |
| 31 | const ip_adjacency_t *adj0, const ip4_address_t *src, |
| 32 | const ip4_address_t *dst) |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 33 | { |
| 34 | vnet_hw_interface_t *hw_if0; |
| 35 | ethernet_arp_header_t *h0; |
| 36 | vlib_buffer_t *b0; |
| 37 | u32 bi0; |
| 38 | |
Neale Ranns | bd8e43d | 2021-03-15 14:42:30 +0000 | [diff] [blame] | 39 | hw_if0 = vnet_get_sup_hw_interface (vnm, adj0->rewrite_header.sw_if_index); |
| 40 | |
| 41 | /* if (NULL == hw_if0->hw_address) */ |
| 42 | /* return (NULL); */ |
| 43 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 44 | /* Send ARP request. */ |
| 45 | h0 = vlib_packet_template_get_packet (vm, |
| 46 | &ip4_main.ip4_arp_request_packet_template, |
| 47 | &bi0); |
| 48 | /* Seems we're out of buffers */ |
| 49 | if (PREDICT_FALSE (!h0)) |
| 50 | return (NULL); |
| 51 | |
| 52 | b0 = vlib_get_buffer (vm, bi0); |
| 53 | |
| 54 | /* Add rewrite/encap string for ARP packet. */ |
| 55 | vnet_rewrite_one_header (adj0[0], h0, sizeof (ethernet_header_t)); |
| 56 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 57 | /* Src ethernet address in ARP header. */ |
| 58 | mac_address_from_bytes (&h0->ip4_over_ethernet[0].mac, hw_if0->hw_address); |
| 59 | |
| 60 | h0->ip4_over_ethernet[0].ip4 = *src; |
| 61 | h0->ip4_over_ethernet[1].ip4 = *dst; |
| 62 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 63 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = adj0->rewrite_header.sw_if_index; |
Stanislav Zaikin | 7dc351f | 2022-05-10 20:50:36 +0200 | [diff] [blame] | 64 | b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 65 | |
| 66 | vlib_buffer_advance (b0, -adj0->rewrite_header.data_bytes); |
| 67 | |
| 68 | { |
| 69 | vlib_frame_t *f = vlib_get_frame_to_node (vm, hw_if0->output_node_index); |
| 70 | u32 *to_next = vlib_frame_vector_args (f); |
| 71 | to_next[0] = bi0; |
| 72 | f->n_vectors = 1; |
| 73 | vlib_put_frame_to_node (vm, hw_if0->output_node_index, f); |
| 74 | } |
| 75 | |
Neale Ranns | fd2417b | 2021-07-16 14:00:16 +0000 | [diff] [blame] | 76 | vlib_increment_simple_counter ( |
| 77 | &ip_neighbor_counters[AF_IP4].ipnc[VLIB_TX][IP_NEIGHBOR_CTR_REQUEST], |
| 78 | vm->thread_index, adj0->rewrite_header.sw_if_index, 1); |
| 79 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 80 | return b0; |
| 81 | } |
| 82 | |
| 83 | #endif |
| 84 | |
| 85 | /* |
| 86 | * fd.io coding-style-patch-verification: ON |
| 87 | * |
| 88 | * Local Variables: |
| 89 | * eval: (c-set-style "gnu") |
| 90 | * End: |
| 91 | */ |