Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | #include <vnet/adj/adj_nbr.h> |
| 17 | #include <vnet/adj/adj_internal.h> |
| 18 | #include <vnet/ethernet/arp_packet.h> |
| 19 | #include <vnet/fib/fib_walk.h> |
| 20 | |
| 21 | /* |
| 22 | * Vector Hash tables of neighbour (traditional) adjacencies |
| 23 | * Key: interface(for the vector index), address (and its proto), |
| 24 | * link-type/ether-type. |
| 25 | */ |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 26 | static uword **adj_nbr_tables[FIB_PROTOCOL_IP_MAX]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 27 | |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 28 | typedef struct adj_nbr_key_t_ |
| 29 | { |
| 30 | ip46_address_t ank_ip; |
| 31 | u64 ank_linkt; |
| 32 | } adj_nbr_key_t; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 33 | |
| 34 | #define ADJ_NBR_SET_KEY(_key, _lt, _nh) \ |
| 35 | { \ |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 36 | ip46_address_copy(&(_key).ank_ip, (_nh)); \ |
| 37 | _key.ank_linkt = (_lt); \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | #define ADJ_NBR_ITF_OK(_proto, _itf) \ |
| 41 | (((_itf) < vec_len(adj_nbr_tables[_proto])) && \ |
| 42 | (NULL != adj_nbr_tables[_proto][sw_if_index])) |
| 43 | |
| 44 | static void |
| 45 | adj_nbr_insert (fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 46 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 47 | const ip46_address_t *nh_addr, |
| 48 | u32 sw_if_index, |
| 49 | adj_index_t adj_index) |
| 50 | { |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 51 | adj_nbr_key_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 52 | |
| 53 | if (sw_if_index >= vec_len(adj_nbr_tables[nh_proto])) |
| 54 | { |
| 55 | vec_validate(adj_nbr_tables[nh_proto], sw_if_index); |
| 56 | } |
| 57 | if (NULL == adj_nbr_tables[nh_proto][sw_if_index]) |
| 58 | { |
| 59 | adj_nbr_tables[nh_proto][sw_if_index] = |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 60 | hash_create_mem(0, sizeof(adj_nbr_key_t), sizeof(adj_index_t)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | ADJ_NBR_SET_KEY(kv, link_type, nh_addr); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 64 | |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 65 | hash_set_mem_alloc (&adj_nbr_tables[nh_proto][sw_if_index], |
| 66 | &kv, adj_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | void |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 70 | adj_nbr_remove (adj_index_t ai, |
| 71 | fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 72 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 73 | const ip46_address_t *nh_addr, |
| 74 | u32 sw_if_index) |
| 75 | { |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 76 | adj_nbr_key_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 77 | |
| 78 | if (!ADJ_NBR_ITF_OK(nh_proto, sw_if_index)) |
| 79 | return; |
| 80 | |
| 81 | ADJ_NBR_SET_KEY(kv, link_type, nh_addr); |
| 82 | |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 83 | hash_unset_mem_free(&adj_nbr_tables[nh_proto][sw_if_index], &kv); |
| 84 | |
| 85 | if (0 == hash_elts(adj_nbr_tables[nh_proto][sw_if_index])) |
| 86 | { |
| 87 | hash_free(adj_nbr_tables[nh_proto][sw_if_index]); |
| 88 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Florin Coras | f9d0568 | 2018-04-26 08:26:52 -0700 | [diff] [blame] | 91 | adj_index_t |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 92 | adj_nbr_find (fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 93 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 94 | const ip46_address_t *nh_addr, |
| 95 | u32 sw_if_index) |
| 96 | { |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 97 | adj_nbr_key_t kv; |
| 98 | uword *p; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 99 | |
| 100 | ADJ_NBR_SET_KEY(kv, link_type, nh_addr); |
| 101 | |
| 102 | if (!ADJ_NBR_ITF_OK(nh_proto, sw_if_index)) |
| 103 | return (ADJ_INDEX_INVALID); |
| 104 | |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 105 | p = hash_get_mem(adj_nbr_tables[nh_proto][sw_if_index], &kv); |
| 106 | |
| 107 | if (p) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 108 | { |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 109 | return (p[0]); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 110 | } |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 111 | return (ADJ_INDEX_INVALID); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 114 | static inline u32 |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 115 | adj_get_nd_node (fib_protocol_t proto) |
| 116 | { |
| 117 | switch (proto) { |
| 118 | case FIB_PROTOCOL_IP4: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 119 | return (ip4_arp_node.index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 120 | case FIB_PROTOCOL_IP6: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 121 | return (ip6_discover_neighbor_node.index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 122 | case FIB_PROTOCOL_MPLS: |
| 123 | break; |
| 124 | } |
| 125 | ASSERT(0); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 126 | return (ip4_arp_node.index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 127 | } |
| 128 | |
AkshayaNadahalli | 17f5f60 | 2017-03-27 14:47:41 +0530 | [diff] [blame] | 129 | /** |
| 130 | * @brief Check and set feature flags if o/p interface has any o/p features. |
| 131 | */ |
| 132 | static void |
| 133 | adj_nbr_evaluate_feature (adj_index_t ai) |
| 134 | { |
| 135 | ip_adjacency_t *adj; |
| 136 | vnet_feature_main_t *fm = &feature_main; |
| 137 | i16 feature_count; |
| 138 | u8 arc_index; |
| 139 | u32 sw_if_index; |
| 140 | |
| 141 | adj = adj_get(ai); |
| 142 | |
| 143 | switch (adj->ia_link) |
| 144 | { |
| 145 | case VNET_LINK_IP4: |
| 146 | arc_index = ip4_main.lookup_main.output_feature_arc_index; |
| 147 | break; |
| 148 | case VNET_LINK_IP6: |
| 149 | arc_index = ip6_main.lookup_main.output_feature_arc_index; |
| 150 | break; |
| 151 | case VNET_LINK_MPLS: |
| 152 | arc_index = mpls_main.output_feature_arc_index; |
| 153 | break; |
| 154 | default: |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | sw_if_index = adj->rewrite_header.sw_if_index; |
AkshayaNadahalli | 98ab091 | 2017-03-27 17:21:05 +0000 | [diff] [blame] | 159 | if (vec_len(fm->feature_count_by_sw_if_index[arc_index]) > sw_if_index) |
| 160 | { |
| 161 | feature_count = fm->feature_count_by_sw_if_index[arc_index][sw_if_index]; |
| 162 | if (feature_count > 0) |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 163 | { |
| 164 | vnet_feature_config_main_t *cm; |
AkshayaNadahalli | 17f5f60 | 2017-03-27 14:47:41 +0530 | [diff] [blame] | 165 | |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 166 | adj->rewrite_header.flags |= VNET_REWRITE_HAS_FEATURES; |
| 167 | cm = &fm->feature_config_mains[arc_index]; |
| 168 | |
| 169 | adj->ia_cfg_index = vec_elt (cm->config_index_by_sw_if_index, |
| 170 | sw_if_index); |
| 171 | } |
| 172 | } |
AkshayaNadahalli | 17f5f60 | 2017-03-27 14:47:41 +0530 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 176 | static ip_adjacency_t* |
| 177 | adj_nbr_alloc (fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 178 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 179 | const ip46_address_t *nh_addr, |
| 180 | u32 sw_if_index) |
| 181 | { |
| 182 | ip_adjacency_t *adj; |
| 183 | |
| 184 | adj = adj_alloc(nh_proto); |
| 185 | |
| 186 | adj_nbr_insert(nh_proto, link_type, nh_addr, |
| 187 | sw_if_index, |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 188 | adj_get_index(adj)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 189 | |
| 190 | /* |
| 191 | * since we just added the ADJ we have no rewrite string for it, |
| 192 | * so its for ARP |
| 193 | */ |
| 194 | adj->lookup_next_index = IP_LOOKUP_NEXT_ARP; |
| 195 | adj->sub_type.nbr.next_hop = *nh_addr; |
| 196 | adj->ia_link = link_type; |
| 197 | adj->ia_nh_proto = nh_proto; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 198 | adj->rewrite_header.sw_if_index = sw_if_index; |
Neale Ranns | 1bce5a9 | 2018-10-30 06:34:25 -0700 | [diff] [blame] | 199 | vnet_rewrite_update_mtu(vnet_get_main(), adj->ia_link, |
| 200 | &adj->rewrite_header); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 201 | |
AkshayaNadahalli | 17f5f60 | 2017-03-27 14:47:41 +0530 | [diff] [blame] | 202 | adj_nbr_evaluate_feature (adj_get_index(adj)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 203 | return (adj); |
| 204 | } |
| 205 | |
| 206 | /* |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 207 | * adj_nbr_add_or_lock |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 208 | * |
| 209 | * Add an adjacency for the neighbour requested. |
| 210 | * |
| 211 | * The key for an adj is: |
| 212 | * - the Next-hops protocol (i.e. v4 or v6) |
| 213 | * - the address of the next-hop |
| 214 | * - the interface the next-hop is reachable through |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 215 | */ |
| 216 | adj_index_t |
| 217 | adj_nbr_add_or_lock (fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 218 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 219 | const ip46_address_t *nh_addr, |
| 220 | u32 sw_if_index) |
| 221 | { |
| 222 | adj_index_t adj_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 223 | |
| 224 | adj_index = adj_nbr_find(nh_proto, link_type, nh_addr, sw_if_index); |
| 225 | |
| 226 | if (ADJ_INDEX_INVALID == adj_index) |
| 227 | { |
Neale Ranns | 77cfc01 | 2019-12-15 22:26:37 +0000 | [diff] [blame] | 228 | ip_adjacency_t *adj; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 229 | vnet_main_t *vnm; |
| 230 | |
| 231 | vnm = vnet_get_main(); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 232 | adj = adj_nbr_alloc(nh_proto, link_type, nh_addr, sw_if_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 233 | adj_index = adj_get_index(adj); |
| 234 | adj_lock(adj_index); |
| 235 | |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 236 | if (ip46_address_is_equal(&ADJ_BCAST_ADDR, nh_addr)) |
| 237 | { |
| 238 | adj->lookup_next_index = IP_LOOKUP_NEXT_BCAST; |
| 239 | } |
| 240 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 241 | vnet_rewrite_init(vnm, sw_if_index, link_type, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 242 | adj_get_nd_node(nh_proto), |
| 243 | vnet_tx_node_index_for_sw_interface(vnm, sw_if_index), |
| 244 | &adj->rewrite_header); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 245 | |
| 246 | /* |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 247 | * we need a rewrite where the destination IP address is converted |
| 248 | * to the appropriate link-layer address. This is interface specific. |
| 249 | * So ask the interface to do it. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 250 | */ |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 251 | vnet_update_adjacency_for_sw_interface(vnm, sw_if_index, adj_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 252 | } |
| 253 | else |
| 254 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 255 | adj_lock(adj_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 256 | } |
| 257 | |
Neale Ranns | 77cfc01 | 2019-12-15 22:26:37 +0000 | [diff] [blame] | 258 | adj_delegate_adj_created(adj_get(adj_index)); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 259 | return (adj_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | adj_index_t |
| 263 | adj_nbr_add_or_lock_w_rewrite (fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 264 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 265 | const ip46_address_t *nh_addr, |
| 266 | u32 sw_if_index, |
| 267 | u8 *rewrite) |
| 268 | { |
| 269 | adj_index_t adj_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 270 | |
| 271 | adj_index = adj_nbr_find(nh_proto, link_type, nh_addr, sw_if_index); |
| 272 | |
| 273 | if (ADJ_INDEX_INVALID == adj_index) |
| 274 | { |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 275 | ip_adjacency_t *adj; |
| 276 | |
| 277 | adj = adj_nbr_alloc(nh_proto, link_type, nh_addr, sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 278 | adj->rewrite_header.sw_if_index = sw_if_index; |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 279 | adj_index = adj_get_index(adj); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 282 | adj_lock(adj_index); |
| 283 | adj_nbr_update_rewrite(adj_index, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 284 | ADJ_NBR_REWRITE_FLAG_COMPLETE, |
| 285 | rewrite); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 286 | |
Neale Ranns | 77cfc01 | 2019-12-15 22:26:37 +0000 | [diff] [blame] | 287 | adj_delegate_adj_created(adj_get(adj_index)); |
| 288 | |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 289 | return (adj_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /** |
| 293 | * adj_nbr_update_rewrite |
| 294 | * |
| 295 | * Update the adjacency's rewrite string. A NULL string implies the |
Jim Thompson | f324dec | 2019-04-08 03:22:21 -0500 | [diff] [blame] | 296 | * rewrite is reset (i.e. when ARP/ND entry is gone). |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 297 | * NB: the adj being updated may be handling traffic in the DP. |
| 298 | */ |
| 299 | void |
| 300 | adj_nbr_update_rewrite (adj_index_t adj_index, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 301 | adj_nbr_rewrite_flag_t flags, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 302 | u8 *rewrite) |
| 303 | { |
| 304 | ip_adjacency_t *adj; |
| 305 | |
| 306 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 307 | |
| 308 | adj = adj_get(adj_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 309 | |
| 310 | if (flags & ADJ_NBR_REWRITE_FLAG_COMPLETE) |
| 311 | { |
| 312 | /* |
| 313 | * update the adj's rewrite string and build the arc |
| 314 | * from the rewrite node to the interface's TX node |
| 315 | */ |
| 316 | adj_nbr_update_rewrite_internal(adj, IP_LOOKUP_NEXT_REWRITE, |
| 317 | adj_get_rewrite_node(adj->ia_link), |
| 318 | vnet_tx_node_index_for_sw_interface( |
| 319 | vnet_get_main(), |
| 320 | adj->rewrite_header.sw_if_index), |
| 321 | rewrite); |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | adj_nbr_update_rewrite_internal(adj, IP_LOOKUP_NEXT_ARP, |
| 326 | adj_get_nd_node(adj->ia_nh_proto), |
| 327 | vnet_tx_node_index_for_sw_interface( |
| 328 | vnet_get_main(), |
| 329 | adj->rewrite_header.sw_if_index), |
| 330 | rewrite); |
| 331 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /** |
| 335 | * adj_nbr_update_rewrite_internal |
| 336 | * |
| 337 | * Update the adjacency's rewrite string. A NULL string implies the |
Jim Thompson | f324dec | 2019-04-08 03:22:21 -0500 | [diff] [blame] | 338 | * rewrite is reset (i.e. when ARP/ND entry is gone). |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 339 | * NB: the adj being updated may be handling traffic in the DP. |
| 340 | */ |
| 341 | void |
| 342 | adj_nbr_update_rewrite_internal (ip_adjacency_t *adj, |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 343 | ip_lookup_next_t adj_next_index, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 344 | u32 this_node, |
| 345 | u32 next_node, |
| 346 | u8 *rewrite) |
| 347 | { |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 348 | ip_adjacency_t *walk_adj; |
Neale Ranns | 66300f6 | 2020-01-12 21:16:55 +0000 | [diff] [blame] | 349 | adj_index_t walk_ai, ai; |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 350 | vlib_main_t * vm; |
| 351 | u32 old_next; |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 352 | int do_walk; |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 353 | |
| 354 | vm = vlib_get_main(); |
| 355 | old_next = adj->lookup_next_index; |
| 356 | |
Neale Ranns | 66300f6 | 2020-01-12 21:16:55 +0000 | [diff] [blame] | 357 | ai = walk_ai = adj_get_index(adj); |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 358 | if (VNET_LINK_MPLS == adj->ia_link) |
| 359 | { |
| 360 | /* |
| 361 | * The link type MPLS has no children in the control plane graph, it only |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 362 | * has children in the data-plane graph. The backwalk is up the former. |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 363 | * So we need to walk from its IP cousin. |
| 364 | */ |
| 365 | walk_ai = adj_nbr_find(adj->ia_nh_proto, |
| 366 | fib_proto_to_link(adj->ia_nh_proto), |
| 367 | &adj->sub_type.nbr.next_hop, |
| 368 | adj->rewrite_header.sw_if_index); |
| 369 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 370 | |
| 371 | /* |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 372 | * Don't call the walk re-entrantly |
| 373 | */ |
| 374 | if (ADJ_INDEX_INVALID != walk_ai) |
| 375 | { |
| 376 | walk_adj = adj_get(walk_ai); |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 377 | if (ADJ_FLAG_SYNC_WALK_ACTIVE & walk_adj->ia_flags) |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 378 | { |
| 379 | do_walk = 0; |
| 380 | } |
| 381 | else |
| 382 | { |
| 383 | /* |
| 384 | * Prevent re-entrant walk of the same adj |
| 385 | */ |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 386 | walk_adj->ia_flags |= ADJ_FLAG_SYNC_WALK_ACTIVE; |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 387 | do_walk = 1; |
| 388 | } |
| 389 | } |
| 390 | else |
| 391 | { |
| 392 | do_walk = 0; |
| 393 | } |
| 394 | |
| 395 | /* |
| 396 | * lock the adjacencies that are affected by updates this walk will provoke. |
| 397 | * Since the aim of the walk is to update children to link to a different |
| 398 | * DPO, this adj will no longer be in use and its lock count will drop to 0. |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 399 | * We don't want it to be deleted as part of this endeavour. |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 400 | */ |
Neale Ranns | 66300f6 | 2020-01-12 21:16:55 +0000 | [diff] [blame] | 401 | adj_lock(ai); |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 402 | adj_lock(walk_ai); |
| 403 | |
| 404 | /* |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 405 | * Updating a rewrite string is not atomic; |
| 406 | * - the rewrite string is too long to write in one instruction |
| 407 | * - when swapping from incomplete to complete, we also need to update |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 408 | * the VLIB graph next-index of the adj. |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 409 | * ideally we would only want to suspend forwarding via this adj whilst we |
| 410 | * do this, but we do not have that level of granularity - it's suspend all |
| 411 | * worker threads or nothing. |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 412 | * The other choices are: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 413 | * - to mark the adj down and back walk so child load-balances drop this adj |
| 414 | * from the set. |
| 415 | * - update the next_node index of this adj to point to error-drop |
| 416 | * both of which will mean for MAC change we will drop for this adj |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 417 | * which is not acceptable. However, when the adj changes type (from |
| 418 | * complete to incomplete and vice-versa) the child DPOs, which have the |
| 419 | * VLIB graph next node index, will be sending packets to the wrong graph |
| 420 | * node. So from the options above, updating the next_node of the adj to |
| 421 | * be drop will work, but it relies on each graph node v4/v6/mpls, rewrite/ |
| 422 | * arp/midchain always be valid w.r.t. a mis-match of adj type and node type |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 423 | * (i.e. a rewrite adj in the arp node). This is not enforceable. Getting it |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 424 | * wrong will lead to hard to find bugs since its a race condition. So we |
| 425 | * choose the more reliable method of updating the children to use the drop, |
| 426 | * then switching adj's type, then updating the children again. Did I mention |
| 427 | * that this doesn't happen often... |
| 428 | * So we need to distinguish between the two cases: |
| 429 | * 1 - mac change |
| 430 | * 2 - adj type change |
| 431 | */ |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 432 | if (do_walk && |
| 433 | old_next != adj_next_index && |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 434 | ADJ_INDEX_INVALID != walk_ai) |
| 435 | { |
| 436 | /* |
| 437 | * the adj is changing type. we need to fix all children so that they |
| 438 | * stack momentarily on a drop, while the adj changes. If we don't do |
| 439 | * this the children will send packets to a VLIB graph node that does |
| 440 | * not correspond to the adj's type - and it goes downhill from there. |
| 441 | */ |
| 442 | fib_node_back_walk_ctx_t bw_ctx = { |
| 443 | .fnbw_reason = FIB_NODE_BW_REASON_FLAG_ADJ_DOWN, |
| 444 | /* |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 445 | * force this walk to be synchronous. if we don't and a node in the graph |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 446 | * (a heavily shared path-list) chooses to back-ground the walk (make it |
| 447 | * async) then it will pause and we will do the adj update below, before |
| 448 | * all the children are updated. not good. |
| 449 | */ |
| 450 | .fnbw_flags = FIB_NODE_BW_FLAG_FORCE_SYNC, |
| 451 | }; |
| 452 | |
| 453 | fib_walk_sync(FIB_NODE_TYPE_ADJ, walk_ai, &bw_ctx); |
Steven Luong | 3d5f622 | 2020-01-30 09:11:18 -0800 | [diff] [blame] | 454 | /* |
| 455 | * fib_walk_sync may allocate a new adjacency and potentially cuase a |
| 456 | * realloc for adj_pool. When that happens, adj pointer is no longer |
| 457 | * valid here. We refresh the adj pointer accordingly. |
| 458 | */ |
| 459 | adj = adj_get (ai); |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /* |
| 463 | * If we are just updating the MAC string of the adj (which we also can't |
| 464 | * do atomically), then we need to stop packets switching through the adj. |
| 465 | * We can't do that on a per-adj basis, so it's all the packets. |
| 466 | * If we are updating the type, and we walked back to the children above, |
| 467 | * then this barrier serves to flush the queues/frames. |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 468 | */ |
| 469 | vlib_worker_thread_barrier_sync(vm); |
| 470 | |
| 471 | adj->lookup_next_index = adj_next_index; |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 472 | adj->ia_node_index = this_node; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 473 | |
| 474 | if (NULL != rewrite) |
| 475 | { |
| 476 | /* |
| 477 | * new rewrite provided. |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 478 | * fill in the adj's rewrite string, and build the VLIB graph arc. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 479 | */ |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 480 | vnet_rewrite_set_data_internal(&adj->rewrite_header, |
| 481 | sizeof(adj->rewrite_data), |
| 482 | rewrite, |
| 483 | vec_len(rewrite)); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 484 | vec_free(rewrite); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 485 | } |
| 486 | else |
| 487 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 488 | vnet_rewrite_clear_data_internal(&adj->rewrite_header, |
| 489 | sizeof(adj->rewrite_data)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 490 | } |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 491 | adj->rewrite_header.next_index = vlib_node_add_next(vlib_get_main(), |
| 492 | this_node, |
| 493 | next_node); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 494 | |
| 495 | /* |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 496 | * done with the rewrite update - let the workers loose. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 497 | */ |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 498 | vlib_worker_thread_barrier_release(vm); |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 499 | |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 500 | if (do_walk && |
| 501 | (old_next != adj->lookup_next_index) && |
| 502 | (ADJ_INDEX_INVALID != walk_ai)) |
Neale Ranns | ad95b5d | 2016-11-10 20:35:14 +0000 | [diff] [blame] | 503 | { |
| 504 | /* |
| 505 | * backwalk to the children so they can stack on the now updated |
| 506 | * adjacency |
| 507 | */ |
| 508 | fib_node_back_walk_ctx_t bw_ctx = { |
| 509 | .fnbw_reason = FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE, |
| 510 | }; |
| 511 | |
| 512 | fib_walk_sync(FIB_NODE_TYPE_ADJ, walk_ai, &bw_ctx); |
| 513 | } |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 514 | /* |
| 515 | * Prevent re-entrant walk of the same adj |
| 516 | */ |
| 517 | if (do_walk) |
| 518 | { |
Neale Ranns | 37157d5 | 2020-01-23 22:46:06 +0000 | [diff] [blame] | 519 | walk_adj = adj_get(walk_ai); |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 520 | walk_adj->ia_flags &= ~ADJ_FLAG_SYNC_WALK_ACTIVE; |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 523 | adj_delegate_adj_modified(adj); |
Neale Ranns | 66300f6 | 2020-01-12 21:16:55 +0000 | [diff] [blame] | 524 | adj_unlock(ai); |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 525 | adj_unlock(walk_ai); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 528 | u32 |
| 529 | adj_nbr_db_size (void) |
| 530 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 531 | fib_protocol_t proto; |
| 532 | u32 sw_if_index = 0; |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 533 | u64 count = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 534 | |
| 535 | for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++) |
| 536 | { |
| 537 | vec_foreach_index(sw_if_index, adj_nbr_tables[proto]) |
| 538 | { |
| 539 | if (NULL != adj_nbr_tables[proto][sw_if_index]) |
| 540 | { |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 541 | count += hash_elts(adj_nbr_tables[proto][sw_if_index]); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | } |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 545 | return (count); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /** |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 549 | * @brief Walk all adjacencies on a link for a given next-hop protocol |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 550 | */ |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 551 | void |
| 552 | adj_nbr_walk (u32 sw_if_index, |
| 553 | fib_protocol_t adj_nh_proto, |
| 554 | adj_walk_cb_t cb, |
| 555 | void *ctx) |
| 556 | { |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 557 | adj_nbr_key_t *key; |
| 558 | adj_index_t ai; |
| 559 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 560 | if (!ADJ_NBR_ITF_OK(adj_nh_proto, sw_if_index)) |
| 561 | return; |
| 562 | |
Neale Ranns | 20aec3d | 2020-05-25 09:09:36 +0000 | [diff] [blame^] | 563 | if (adj_nbr_tables[adj_nh_proto][sw_if_index] || |
| 564 | hash_elts(adj_nbr_tables[adj_nh_proto][sw_if_index])) |
| 565 | { |
| 566 | hash_foreach_mem (key, ai, adj_nbr_tables[adj_nh_proto][sw_if_index], |
| 567 | ({ |
| 568 | ASSERT(key); |
| 569 | cb(ai, ctx); |
| 570 | })); |
| 571 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | /** |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 575 | * @brief Walk adjacencies on a link with a given v4 next-hop. |
| 576 | * that is visit the adjacencies with different link types. |
| 577 | */ |
| 578 | void |
| 579 | adj_nbr_walk_nh4 (u32 sw_if_index, |
| 580 | const ip4_address_t *addr, |
| 581 | adj_walk_cb_t cb, |
| 582 | void *ctx) |
| 583 | { |
| 584 | if (!ADJ_NBR_ITF_OK(FIB_PROTOCOL_IP4, sw_if_index)) |
| 585 | return; |
| 586 | |
| 587 | ip46_address_t nh = { |
| 588 | .ip4 = *addr, |
| 589 | }; |
Neale Ranns | 580bba7 | 2018-04-23 05:31:19 -0700 | [diff] [blame] | 590 | vnet_link_t linkt; |
| 591 | adj_index_t ai; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 592 | |
Neale Ranns | 580bba7 | 2018-04-23 05:31:19 -0700 | [diff] [blame] | 593 | FOR_EACH_VNET_LINK(linkt) |
| 594 | { |
| 595 | ai = adj_nbr_find (FIB_PROTOCOL_IP4, linkt, &nh, sw_if_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 596 | |
Neale Ranns | 580bba7 | 2018-04-23 05:31:19 -0700 | [diff] [blame] | 597 | if (INDEX_INVALID != ai) |
| 598 | cb(ai, ctx); |
| 599 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /** |
| 603 | * @brief Walk adjacencies on a link with a given v6 next-hop. |
| 604 | * that is visit the adjacencies with different link types. |
| 605 | */ |
| 606 | void |
| 607 | adj_nbr_walk_nh6 (u32 sw_if_index, |
| 608 | const ip6_address_t *addr, |
| 609 | adj_walk_cb_t cb, |
| 610 | void *ctx) |
| 611 | { |
| 612 | if (!ADJ_NBR_ITF_OK(FIB_PROTOCOL_IP6, sw_if_index)) |
| 613 | return; |
| 614 | |
| 615 | ip46_address_t nh = { |
| 616 | .ip6 = *addr, |
| 617 | }; |
Neale Ranns | 580bba7 | 2018-04-23 05:31:19 -0700 | [diff] [blame] | 618 | vnet_link_t linkt; |
| 619 | adj_index_t ai; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 620 | |
Neale Ranns | 580bba7 | 2018-04-23 05:31:19 -0700 | [diff] [blame] | 621 | FOR_EACH_VNET_LINK(linkt) |
| 622 | { |
| 623 | ai = adj_nbr_find (FIB_PROTOCOL_IP6, linkt, &nh, sw_if_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 624 | |
Neale Ranns | 580bba7 | 2018-04-23 05:31:19 -0700 | [diff] [blame] | 625 | if (INDEX_INVALID != ai) |
| 626 | cb(ai, ctx); |
| 627 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /** |
| 631 | * @brief Walk adjacencies on a link with a given next-hop. |
| 632 | * that is visit the adjacencies with different link types. |
| 633 | */ |
| 634 | void |
| 635 | adj_nbr_walk_nh (u32 sw_if_index, |
| 636 | fib_protocol_t adj_nh_proto, |
| 637 | const ip46_address_t *nh, |
| 638 | adj_walk_cb_t cb, |
| 639 | void *ctx) |
| 640 | { |
| 641 | if (!ADJ_NBR_ITF_OK(adj_nh_proto, sw_if_index)) |
| 642 | return; |
| 643 | |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 644 | switch (adj_nh_proto) |
Neale Ranns | 580bba7 | 2018-04-23 05:31:19 -0700 | [diff] [blame] | 645 | { |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 646 | case FIB_PROTOCOL_IP4: |
| 647 | adj_nbr_walk_nh4(sw_if_index, &nh->ip4, cb, ctx); |
| 648 | break; |
| 649 | case FIB_PROTOCOL_IP6: |
| 650 | adj_nbr_walk_nh6(sw_if_index, &nh->ip6, cb, ctx); |
| 651 | break; |
| 652 | case FIB_PROTOCOL_MPLS: |
| 653 | ASSERT(0); |
| 654 | break; |
Neale Ranns | 580bba7 | 2018-04-23 05:31:19 -0700 | [diff] [blame] | 655 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | /** |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 659 | * Flags associated with the interface state walks |
| 660 | */ |
| 661 | typedef enum adj_nbr_interface_flags_t_ |
| 662 | { |
| 663 | ADJ_NBR_INTERFACE_UP = (1 << 0), |
| 664 | } adj_nbr_interface_flags_t; |
| 665 | |
| 666 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 667 | * Context for the state change walk of the DB |
| 668 | */ |
| 669 | typedef struct adj_nbr_interface_state_change_ctx_t_ |
| 670 | { |
| 671 | /** |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 672 | * Flags on the interface |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 673 | */ |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 674 | adj_nbr_interface_flags_t flags; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 675 | } adj_nbr_interface_state_change_ctx_t; |
| 676 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 677 | static adj_walk_rc_t |
| 678 | adj_nbr_interface_state_change_one (adj_index_t ai, |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 679 | void *arg) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 680 | { |
| 681 | /* |
| 682 | * Back walk the graph to inform the forwarding entries |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 683 | * that this interface state has changed. Do this synchronously |
| 684 | * since this is the walk that provides convergence |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 685 | */ |
| 686 | adj_nbr_interface_state_change_ctx_t *ctx = arg; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 687 | fib_node_back_walk_ctx_t bw_ctx = { |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 688 | .fnbw_reason = ((ctx->flags & ADJ_NBR_INTERFACE_UP) ? |
| 689 | FIB_NODE_BW_REASON_FLAG_INTERFACE_UP : |
| 690 | FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN), |
| 691 | /* |
| 692 | * the force sync applies only as far as the first fib_entry. |
| 693 | * And it's the fib_entry's we need to converge away from |
| 694 | * the adjacencies on the now down link |
| 695 | */ |
| 696 | .fnbw_flags = (!(ctx->flags & ADJ_NBR_INTERFACE_UP) ? |
| 697 | FIB_NODE_BW_FLAG_FORCE_SYNC : |
Neale Ranns | 30d5364 | 2018-08-27 07:29:15 -0700 | [diff] [blame] | 698 | FIB_NODE_BW_FLAG_NONE), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 699 | }; |
Neale Ranns | 30d5364 | 2018-08-27 07:29:15 -0700 | [diff] [blame] | 700 | ip_adjacency_t *adj; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 701 | |
Neale Ranns | 30d5364 | 2018-08-27 07:29:15 -0700 | [diff] [blame] | 702 | adj = adj_get(ai); |
| 703 | |
| 704 | adj->ia_flags |= ADJ_FLAG_SYNC_WALK_ACTIVE; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 705 | fib_walk_sync(FIB_NODE_TYPE_ADJ, ai, &bw_ctx); |
Neale Ranns | 30d5364 | 2018-08-27 07:29:15 -0700 | [diff] [blame] | 706 | adj->ia_flags &= ~ADJ_FLAG_SYNC_WALK_ACTIVE; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 707 | |
| 708 | return (ADJ_WALK_RC_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 709 | } |
| 710 | |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 711 | /** |
| 712 | * @brief Registered function for SW interface state changes |
| 713 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 714 | static clib_error_t * |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 715 | adj_nbr_sw_interface_state_change (vnet_main_t * vnm, |
| 716 | u32 sw_if_index, |
| 717 | u32 flags) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 718 | { |
| 719 | fib_protocol_t proto; |
| 720 | |
| 721 | /* |
| 722 | * walk each adj on the interface and trigger a walk from that adj |
| 723 | */ |
| 724 | for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++) |
| 725 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 726 | adj_nbr_interface_state_change_ctx_t ctx = { |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 727 | .flags = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
| 728 | ADJ_NBR_INTERFACE_UP : |
| 729 | 0), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 730 | }; |
| 731 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 732 | adj_nbr_walk(sw_if_index, proto, |
| 733 | adj_nbr_interface_state_change_one, |
| 734 | &ctx); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | return (NULL); |
| 738 | } |
| 739 | |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 740 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION_PRIO( |
| 741 | adj_nbr_sw_interface_state_change, |
| 742 | VNET_ITF_FUNC_PRIORITY_HIGH); |
| 743 | |
| 744 | /** |
| 745 | * @brief Invoked on each SW interface of a HW interface when the |
| 746 | * HW interface state changes |
| 747 | */ |
Neale Ranns | 0053de6 | 2018-05-22 08:40:52 -0700 | [diff] [blame] | 748 | static walk_rc_t |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 749 | adj_nbr_hw_sw_interface_state_change (vnet_main_t * vnm, |
| 750 | u32 sw_if_index, |
| 751 | void *arg) |
| 752 | { |
| 753 | adj_nbr_interface_state_change_ctx_t *ctx = arg; |
| 754 | fib_protocol_t proto; |
| 755 | |
| 756 | /* |
| 757 | * walk each adj on the interface and trigger a walk from that adj |
| 758 | */ |
| 759 | for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++) |
| 760 | { |
| 761 | adj_nbr_walk(sw_if_index, proto, |
| 762 | adj_nbr_interface_state_change_one, |
| 763 | ctx); |
| 764 | } |
Neale Ranns | 0053de6 | 2018-05-22 08:40:52 -0700 | [diff] [blame] | 765 | return (WALK_CONTINUE); |
Neale Ranns | 8b37b87 | 2016-11-21 12:25:22 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | /** |
| 769 | * @brief Registered callback for HW interface state changes |
| 770 | */ |
| 771 | static clib_error_t * |
| 772 | adj_nbr_hw_interface_state_change (vnet_main_t * vnm, |
| 773 | u32 hw_if_index, |
| 774 | u32 flags) |
| 775 | { |
| 776 | /* |
| 777 | * walk SW interface on the HW |
| 778 | */ |
| 779 | adj_nbr_interface_state_change_ctx_t ctx = { |
| 780 | .flags = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? |
| 781 | ADJ_NBR_INTERFACE_UP : |
| 782 | 0), |
| 783 | }; |
| 784 | |
| 785 | vnet_hw_interface_walk_sw(vnm, hw_if_index, |
| 786 | adj_nbr_hw_sw_interface_state_change, |
| 787 | &ctx); |
| 788 | |
| 789 | return (NULL); |
| 790 | } |
| 791 | |
| 792 | VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION_PRIO( |
| 793 | adj_nbr_hw_interface_state_change, |
| 794 | VNET_ITF_FUNC_PRIORITY_HIGH); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 795 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 796 | static adj_walk_rc_t |
| 797 | adj_nbr_interface_delete_one (adj_index_t ai, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 798 | void *arg) |
| 799 | { |
| 800 | /* |
| 801 | * Back walk the graph to inform the forwarding entries |
| 802 | * that this interface has been deleted. |
| 803 | */ |
| 804 | fib_node_back_walk_ctx_t bw_ctx = { |
| 805 | .fnbw_reason = FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE, |
| 806 | }; |
Neale Ranns | 30d5364 | 2018-08-27 07:29:15 -0700 | [diff] [blame] | 807 | ip_adjacency_t *adj; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 808 | |
Benoît Ganne | 7391156 | 2019-10-16 15:08:37 +0200 | [diff] [blame] | 809 | adj_lock(ai); |
| 810 | |
Neale Ranns | 30d5364 | 2018-08-27 07:29:15 -0700 | [diff] [blame] | 811 | adj = adj_get(ai); |
| 812 | |
| 813 | adj->ia_flags |= ADJ_FLAG_SYNC_WALK_ACTIVE; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 814 | fib_walk_sync(FIB_NODE_TYPE_ADJ, ai, &bw_ctx); |
Neale Ranns | 30d5364 | 2018-08-27 07:29:15 -0700 | [diff] [blame] | 815 | adj->ia_flags &= ~ADJ_FLAG_SYNC_WALK_ACTIVE; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 816 | |
Benoît Ganne | 7391156 | 2019-10-16 15:08:37 +0200 | [diff] [blame] | 817 | adj_unlock(ai); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 818 | return (ADJ_WALK_RC_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /** |
| 822 | * adj_nbr_interface_add_del |
| 823 | * |
| 824 | * Registered to receive interface Add and delete notifications |
| 825 | */ |
| 826 | static clib_error_t * |
| 827 | adj_nbr_interface_add_del (vnet_main_t * vnm, |
| 828 | u32 sw_if_index, |
| 829 | u32 is_add) |
| 830 | { |
| 831 | fib_protocol_t proto; |
| 832 | |
| 833 | if (is_add) |
| 834 | { |
| 835 | /* |
| 836 | * not interested in interface additions. we will not back walk |
| 837 | * to resolve paths through newly added interfaces. Why? The control |
| 838 | * plane should have the brains to add interfaces first, then routes. |
| 839 | * So the case where there are paths with a interface that matches |
| 840 | * one just created is the case where the path resolved through an |
| 841 | * interface that was deleted, and still has not been removed. The |
| 842 | * new interface added, is NO GUARANTEE that the interface being |
| 843 | * added now, even though it may have the same sw_if_index, is the |
| 844 | * same interface that the path needs. So tough! |
| 845 | * If the control plane wants these routes to resolve it needs to |
| 846 | * remove and add them again. |
| 847 | */ |
| 848 | return (NULL); |
| 849 | } |
| 850 | |
| 851 | for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++) |
| 852 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 853 | adj_nbr_walk(sw_if_index, proto, |
| 854 | adj_nbr_interface_delete_one, |
| 855 | NULL); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | return (NULL); |
| 859 | |
| 860 | } |
| 861 | |
| 862 | VNET_SW_INTERFACE_ADD_DEL_FUNCTION(adj_nbr_interface_add_del); |
| 863 | |
| 864 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 865 | static adj_walk_rc_t |
| 866 | adj_nbr_show_one (adj_index_t ai, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 867 | void *arg) |
| 868 | { |
| 869 | vlib_cli_output (arg, "[@%d] %U", |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 870 | ai, |
| 871 | format_ip_adjacency, ai, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 872 | FORMAT_IP_ADJACENCY_NONE); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 873 | |
| 874 | return (ADJ_WALK_RC_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | static clib_error_t * |
| 878 | adj_nbr_show (vlib_main_t * vm, |
| 879 | unformat_input_t * input, |
| 880 | vlib_cli_command_t * cmd) |
| 881 | { |
| 882 | adj_index_t ai = ADJ_INDEX_INVALID; |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 883 | ip46_address_t nh = ip46_address_initializer; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 884 | u32 sw_if_index = ~0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 885 | |
| 886 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 887 | { |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 888 | if (unformat (input, "%U", |
| 889 | unformat_vnet_sw_interface, vnet_get_main(), |
| 890 | &sw_if_index)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 891 | ; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 892 | else if (unformat (input, "%U", |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 893 | unformat_ip46_address, &nh, IP46_TYPE_ANY)) |
| 894 | ; |
| 895 | else if (unformat (input, "%d", &ai)) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 896 | ; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 897 | else |
| 898 | break; |
| 899 | } |
| 900 | |
| 901 | if (ADJ_INDEX_INVALID != ai) |
| 902 | { |
| 903 | vlib_cli_output (vm, "[@%d] %U", |
| 904 | ai, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 905 | format_ip_adjacency, ai, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 906 | FORMAT_IP_ADJACENCY_DETAIL); |
| 907 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 908 | else if (~0 != sw_if_index) |
| 909 | { |
| 910 | fib_protocol_t proto; |
| 911 | |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 912 | if (ip46_address_is_zero(&nh)) |
| 913 | { |
| 914 | for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++) |
| 915 | { |
| 916 | adj_nbr_walk(sw_if_index, proto, |
| 917 | adj_nbr_show_one, |
| 918 | vm); |
| 919 | } |
| 920 | } |
| 921 | else |
| 922 | { |
| 923 | proto = (ip46_address_is_ip4(&nh) ? |
| 924 | FIB_PROTOCOL_IP4 : |
| 925 | FIB_PROTOCOL_IP6); |
| 926 | adj_nbr_walk_nh(sw_if_index, proto, &nh, |
| 927 | adj_nbr_show_one, |
| 928 | vm); |
| 929 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 930 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 931 | else |
| 932 | { |
| 933 | fib_protocol_t proto; |
| 934 | |
| 935 | for (proto = FIB_PROTOCOL_IP4; proto <= FIB_PROTOCOL_IP6; proto++) |
| 936 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 937 | vec_foreach_index(sw_if_index, adj_nbr_tables[proto]) |
| 938 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 939 | adj_nbr_walk(sw_if_index, proto, |
| 940 | adj_nbr_show_one, |
| 941 | vm); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | return 0; |
| 947 | } |
| 948 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 949 | /*? |
| 950 | * Show all neighbour adjacencies. |
| 951 | * @cliexpar |
| 952 | * @cliexstart{sh adj nbr} |
| 953 | * [@2] ipv4 via 1.0.0.2 loop0: IP4: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc |
| 954 | * [@3] mpls via 1.0.0.2 loop0: MPLS_UNICAST: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc |
| 955 | * [@4] ipv4 via 1.0.0.3 loop0: IP4: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc |
| 956 | * [@5] mpls via 1.0.0.3 loop0: MPLS_UNICAST: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc |
| 957 | * @cliexend |
| 958 | ?*/ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 959 | VLIB_CLI_COMMAND (ip4_show_fib_command, static) = { |
| 960 | .path = "show adj nbr", |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 961 | .short_help = "show adj nbr [<adj_index>] [interface]", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 962 | .function = adj_nbr_show, |
| 963 | }; |
| 964 | |
| 965 | u8* |
| 966 | format_adj_nbr_incomplete (u8* s, va_list *ap) |
| 967 | { |
Billy McFall | cfcf1e2 | 2016-10-14 09:51:49 -0400 | [diff] [blame] | 968 | index_t index = va_arg(*ap, index_t); |
| 969 | CLIB_UNUSED(u32 indent) = va_arg(*ap, u32); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 970 | vnet_main_t * vnm = vnet_get_main(); |
| 971 | ip_adjacency_t * adj = adj_get(index); |
| 972 | |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 973 | s = format (s, "arp-%U", format_vnet_link, adj->ia_link); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 974 | s = format (s, ": via %U", |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 975 | format_ip46_address, &adj->sub_type.nbr.next_hop, |
| 976 | adj_proto_to_46(adj->ia_nh_proto)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 977 | s = format (s, " %U", |
Steven | 70488ab | 2018-03-28 17:59:00 -0700 | [diff] [blame] | 978 | format_vnet_sw_if_index_name, |
| 979 | vnm, adj->rewrite_header.sw_if_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 980 | |
| 981 | return (s); |
| 982 | } |
| 983 | |
| 984 | u8* |
| 985 | format_adj_nbr (u8* s, va_list *ap) |
| 986 | { |
Billy McFall | cfcf1e2 | 2016-10-14 09:51:49 -0400 | [diff] [blame] | 987 | index_t index = va_arg(*ap, index_t); |
| 988 | CLIB_UNUSED(u32 indent) = va_arg(*ap, u32); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 989 | ip_adjacency_t * adj = adj_get(index); |
| 990 | |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 991 | s = format (s, "%U", format_vnet_link, adj->ia_link); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 992 | s = format (s, " via %U ", |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 993 | format_ip46_address, &adj->sub_type.nbr.next_hop, |
| 994 | adj_proto_to_46(adj->ia_nh_proto)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 995 | s = format (s, "%U", |
| 996 | format_vnet_rewrite, |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 997 | &adj->rewrite_header, sizeof (adj->rewrite_data), 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 998 | |
| 999 | return (s); |
| 1000 | } |
| 1001 | |
| 1002 | static void |
| 1003 | adj_dpo_lock (dpo_id_t *dpo) |
| 1004 | { |
| 1005 | adj_lock(dpo->dpoi_index); |
| 1006 | } |
| 1007 | static void |
| 1008 | adj_dpo_unlock (dpo_id_t *dpo) |
| 1009 | { |
| 1010 | adj_unlock(dpo->dpoi_index); |
| 1011 | } |
| 1012 | |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 1013 | static void |
| 1014 | adj_mem_show (void) |
| 1015 | { |
| 1016 | fib_show_memory_usage("Adjacency", |
| 1017 | pool_elts(adj_pool), |
| 1018 | pool_len(adj_pool), |
| 1019 | sizeof(ip_adjacency_t)); |
| 1020 | } |
| 1021 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1022 | const static dpo_vft_t adj_nbr_dpo_vft = { |
| 1023 | .dv_lock = adj_dpo_lock, |
| 1024 | .dv_unlock = adj_dpo_unlock, |
| 1025 | .dv_format = format_adj_nbr, |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 1026 | .dv_mem_show = adj_mem_show, |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 1027 | .dv_get_urpf = adj_dpo_get_urpf, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1028 | }; |
| 1029 | const static dpo_vft_t adj_nbr_incompl_dpo_vft = { |
| 1030 | .dv_lock = adj_dpo_lock, |
| 1031 | .dv_unlock = adj_dpo_unlock, |
| 1032 | .dv_format = format_adj_nbr_incomplete, |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 1033 | .dv_get_urpf = adj_dpo_get_urpf, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1034 | }; |
| 1035 | |
| 1036 | /** |
| 1037 | * @brief The per-protocol VLIB graph nodes that are assigned to an adjacency |
| 1038 | * object. |
| 1039 | * |
| 1040 | * this means that these graph nodes are ones from which a nbr is the |
| 1041 | * parent object in the DPO-graph. |
| 1042 | */ |
| 1043 | const static char* const nbr_ip4_nodes[] = |
| 1044 | { |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 1045 | "ip4-rewrite", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1046 | NULL, |
| 1047 | }; |
| 1048 | const static char* const nbr_ip6_nodes[] = |
| 1049 | { |
| 1050 | "ip6-rewrite", |
| 1051 | NULL, |
| 1052 | }; |
| 1053 | const static char* const nbr_mpls_nodes[] = |
| 1054 | { |
| 1055 | "mpls-output", |
| 1056 | NULL, |
| 1057 | }; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 1058 | const static char* const nbr_ethernet_nodes[] = |
| 1059 | { |
| 1060 | "adj-l2-rewrite", |
| 1061 | NULL, |
| 1062 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1063 | const static char* const * const nbr_nodes[DPO_PROTO_NUM] = |
| 1064 | { |
| 1065 | [DPO_PROTO_IP4] = nbr_ip4_nodes, |
| 1066 | [DPO_PROTO_IP6] = nbr_ip6_nodes, |
| 1067 | [DPO_PROTO_MPLS] = nbr_mpls_nodes, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 1068 | [DPO_PROTO_ETHERNET] = nbr_ethernet_nodes, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1069 | }; |
| 1070 | |
| 1071 | const static char* const nbr_incomplete_ip4_nodes[] = |
| 1072 | { |
| 1073 | "ip4-arp", |
| 1074 | NULL, |
| 1075 | }; |
| 1076 | const static char* const nbr_incomplete_ip6_nodes[] = |
| 1077 | { |
| 1078 | "ip6-discover-neighbor", |
| 1079 | NULL, |
| 1080 | }; |
| 1081 | const static char* const nbr_incomplete_mpls_nodes[] = |
| 1082 | { |
| 1083 | "mpls-adj-incomplete", |
| 1084 | NULL, |
| 1085 | }; |
| 1086 | |
| 1087 | const static char* const * const nbr_incomplete_nodes[DPO_PROTO_NUM] = |
| 1088 | { |
| 1089 | [DPO_PROTO_IP4] = nbr_incomplete_ip4_nodes, |
| 1090 | [DPO_PROTO_IP6] = nbr_incomplete_ip6_nodes, |
| 1091 | [DPO_PROTO_MPLS] = nbr_incomplete_mpls_nodes, |
| 1092 | }; |
| 1093 | |
| 1094 | void |
| 1095 | adj_nbr_module_init (void) |
| 1096 | { |
| 1097 | dpo_register(DPO_ADJACENCY, |
| 1098 | &adj_nbr_dpo_vft, |
| 1099 | nbr_nodes); |
| 1100 | dpo_register(DPO_ADJACENCY_INCOMPLETE, |
| 1101 | &adj_nbr_incompl_dpo_vft, |
| 1102 | nbr_incomplete_nodes); |
| 1103 | } |