Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ip/ip6_neighbor.c: IP6 neighbor handling |
| 3 | * |
| 4 | * Copyright (c) 2010 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 | #include <vnet/ip/ip.h> |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 19 | #include <vnet/ip/ip6_neighbor.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | #include <vnet/ethernet/ethernet.h> |
| 21 | #include <vppinfra/mhash.h> |
| 22 | #include <vppinfra/md5.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 23 | #include <vnet/adj/adj.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 24 | #include <vnet/adj/adj_mcast.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 25 | #include <vnet/fib/fib_table.h> |
| 26 | #include <vnet/fib/ip6_fib.h> |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 27 | #include <vnet/mfib/ip6_mfib.h> |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 28 | #include <vnet/ip/ip6_ll_table.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 30 | /** |
| 31 | * @file |
| 32 | * @brief IPv6 Neighbor Adjacency and Neighbor Discovery. |
| 33 | * |
| 34 | * The files contains the API and CLI code for managing IPv6 neighbor |
| 35 | * adjacency tables and neighbor discovery logic. |
| 36 | */ |
| 37 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 38 | /* can't use sizeof link_layer_address, that's 8 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | #define ETHER_MAC_ADDR_LEN 6 |
| 40 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 41 | /* advertised prefix option */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 42 | typedef struct |
| 43 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | /* basic advertised information */ |
| 45 | ip6_address_t prefix; |
| 46 | u8 prefix_len; |
| 47 | int adv_on_link_flag; |
| 48 | int adv_autonomous_flag; |
| 49 | u32 adv_valid_lifetime_in_secs; |
| 50 | u32 adv_pref_lifetime_in_secs; |
| 51 | |
| 52 | /* advertised values are computed from these times if decrementing */ |
| 53 | f64 valid_lifetime_expires; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 54 | f64 pref_lifetime_expires; |
| 55 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | /* local information */ |
| 57 | int enabled; |
| 58 | int deprecated_prefix_flag; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 59 | int decrement_lifetime_flag; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | |
| 61 | #define MIN_ADV_VALID_LIFETIME 7203 /* seconds */ |
| 62 | #define DEF_ADV_VALID_LIFETIME 2592000 |
| 63 | #define DEF_ADV_PREF_LIFETIME 604800 |
| 64 | |
| 65 | /* extensions are added here, mobile, DNS etc.. */ |
| 66 | } ip6_radv_prefix_t; |
| 67 | |
| 68 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 69 | typedef struct |
| 70 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | /* group information */ |
| 72 | u8 type; |
| 73 | ip6_address_t mcast_address; |
| 74 | u16 num_sources; |
| 75 | ip6_address_t *mcast_source_address_pool; |
| 76 | } ip6_mldp_group_t; |
| 77 | |
| 78 | /* configured router advertisement information per ipv6 interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 79 | typedef struct |
| 80 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 81 | |
| 82 | /* advertised config information, zero means unspecified */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 83 | u8 curr_hop_limit; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | int adv_managed_flag; |
| 85 | int adv_other_flag; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 86 | u16 adv_router_lifetime_in_sec; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | u32 adv_neighbor_reachable_time_in_msec; |
| 88 | u32 adv_time_in_msec_between_retransmitted_neighbor_solicitations; |
| 89 | |
| 90 | /* mtu option */ |
| 91 | u32 adv_link_mtu; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 92 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | /* source link layer option */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 94 | u8 link_layer_address[8]; |
| 95 | u8 link_layer_addr_len; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 96 | |
| 97 | /* prefix option */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 98 | ip6_radv_prefix_t *adv_prefixes_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | |
| 100 | /* Hash table mapping address to index in interface advertised prefix pool. */ |
| 101 | mhash_t address_to_prefix_index; |
| 102 | |
| 103 | /* MLDP group information */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 104 | ip6_mldp_group_t *mldp_group_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | |
| 106 | /* Hash table mapping address to index in mldp address pool. */ |
| 107 | mhash_t address_to_mldp_index; |
| 108 | |
| 109 | /* local information */ |
| 110 | u32 sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 111 | int send_radv; /* radv on/off on this interface - set by config */ |
| 112 | int cease_radv; /* we are ceasing to send - set byf config */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | int send_unicast; |
| 114 | int adv_link_layer_address; |
| 115 | int prefix_option; |
| 116 | int failed_device_check; |
| 117 | int all_routers_mcast; |
| 118 | u32 seed; |
| 119 | u64 randomizer; |
| 120 | int ref_count; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 121 | adj_index_t mcast_adj_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 122 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | /* timing information */ |
| 124 | #define DEF_MAX_RADV_INTERVAL 200 |
| 125 | #define DEF_MIN_RADV_INTERVAL .75 * DEF_MAX_RADV_INTERVAL |
| 126 | #define DEF_CURR_HOP_LIMIT 64 |
| 127 | #define DEF_DEF_RTR_LIFETIME 3 * DEF_MAX_RADV_INTERVAL |
| 128 | #define MAX_DEF_RTR_LIFETIME 9000 |
| 129 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 130 | #define MAX_INITIAL_RTR_ADVERT_INTERVAL 16 /* seconds */ |
| 131 | #define MAX_INITIAL_RTR_ADVERTISEMENTS 3 /*transmissions */ |
| 132 | #define MIN_DELAY_BETWEEN_RAS 3 /* seconds */ |
| 133 | #define MAX_DELAY_BETWEEN_RAS 1800 /* seconds */ |
| 134 | #define MAX_RA_DELAY_TIME .5 /* seconds */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | |
| 136 | f64 max_radv_interval; |
| 137 | f64 min_radv_interval; |
| 138 | f64 min_delay_between_radv; |
| 139 | f64 max_delay_between_radv; |
| 140 | f64 max_rtr_default_lifetime; |
| 141 | |
| 142 | f64 last_radv_time; |
| 143 | f64 last_multicast_time; |
| 144 | f64 next_multicast_time; |
| 145 | |
| 146 | |
| 147 | u32 initial_adverts_count; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 148 | f64 initial_adverts_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | u32 initial_adverts_sent; |
| 150 | |
| 151 | /* stats */ |
| 152 | u32 n_advertisements_sent; |
| 153 | u32 n_solicitations_rcvd; |
| 154 | u32 n_solicitations_dropped; |
| 155 | |
| 156 | /* Link local address to use (defaults to underlying physical for logical interfaces */ |
| 157 | ip6_address_t link_local_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | } ip6_radv_t; |
| 159 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 160 | typedef struct |
| 161 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 162 | u32 next_index; |
| 163 | uword node_index; |
| 164 | uword type_opaque; |
| 165 | uword data; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 166 | /* Used for nd event notification only */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 167 | void *data_callback; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 168 | u32 pid; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | } pending_resolution_t; |
| 170 | |
| 171 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 172 | typedef struct |
| 173 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 174 | /* Hash tables mapping name to opcode. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 175 | uword *opcode_by_name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 176 | |
| 177 | /* lite beer "glean" adjacency handling */ |
| 178 | mhash_t pending_resolutions_by_address; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 179 | pending_resolution_t *pending_resolutions; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 181 | /* Mac address change notification */ |
| 182 | mhash_t mac_changes_by_address; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 183 | pending_resolution_t *mac_changes; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 184 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 185 | u32 *neighbor_input_next_index_by_hw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 187 | ip6_neighbor_t *neighbor_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | |
| 189 | mhash_t neighbor_index_by_key; |
| 190 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 191 | u32 *if_radv_pool_index_by_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 192 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 193 | ip6_radv_t *if_radv_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 194 | |
| 195 | /* Neighbor attack mitigation */ |
| 196 | u32 limit_neighbor_cache_size; |
| 197 | u32 neighbor_delete_rotor; |
| 198 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 199 | /* Wildcard nd report publisher */ |
| 200 | uword wc_ip6_nd_publisher_node; |
| 201 | uword wc_ip6_nd_publisher_et; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 202 | } ip6_neighbor_main_t; |
| 203 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 204 | /* ipv6 neighbor discovery - timer/event types */ |
| 205 | typedef enum |
| 206 | { |
| 207 | ICMP6_ND_EVENT_INIT, |
| 208 | } ip6_icmp_neighbor_discovery_event_type_t; |
| 209 | |
| 210 | typedef union |
| 211 | { |
| 212 | u32 add_del_swindex; |
| 213 | struct |
| 214 | { |
| 215 | u32 up_down_swindex; |
| 216 | u32 fib_index; |
| 217 | } up_down_event; |
| 218 | } ip6_icmp_neighbor_discovery_event_data_t; |
| 219 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 220 | static ip6_neighbor_main_t ip6_neighbor_main; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 221 | static ip6_address_t ip6a_zero; /* ip6 address 0 */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 222 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 223 | static void wc_nd_signal_report (wc_nd_report_t * r); |
| 224 | |
| 225 | /** |
| 226 | * @brief publish wildcard arp event |
| 227 | * @param sw_if_index The interface on which the ARP entires are acted |
| 228 | */ |
| 229 | static int |
| 230 | vnet_nd_wc_publish (u32 sw_if_index, u8 * mac, ip6_address_t * ip6) |
| 231 | { |
| 232 | wc_nd_report_t r = { |
| 233 | .sw_if_index = sw_if_index, |
| 234 | .ip6 = *ip6, |
| 235 | }; |
| 236 | memcpy (r.mac, mac, sizeof r.mac); |
| 237 | |
| 238 | void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); |
| 239 | vl_api_rpc_call_main_thread (wc_nd_signal_report, (u8 *) & r, sizeof r); |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static void |
| 244 | wc_nd_signal_report (wc_nd_report_t * r) |
| 245 | { |
| 246 | vlib_main_t *vm = vlib_get_main (); |
| 247 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 248 | uword ni = nm->wc_ip6_nd_publisher_node; |
| 249 | uword et = nm->wc_ip6_nd_publisher_et; |
| 250 | |
| 251 | if (ni == (uword) ~ 0) |
| 252 | return; |
| 253 | wc_nd_report_t *q = |
| 254 | vlib_process_signal_event_data (vm, ni, et, 1, sizeof *q); |
| 255 | |
| 256 | *q = *r; |
| 257 | } |
| 258 | |
| 259 | void |
| 260 | wc_nd_set_publisher_node (uword node_index, uword event_type) |
| 261 | { |
| 262 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 263 | nm->wc_ip6_nd_publisher_node = node_index; |
| 264 | nm->wc_ip6_nd_publisher_et = event_type; |
| 265 | } |
| 266 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 267 | static u8 * |
| 268 | format_ip6_neighbor_ip6_entry (u8 * s, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 270 | vlib_main_t *vm = va_arg (*va, vlib_main_t *); |
| 271 | ip6_neighbor_t *n = va_arg (*va, ip6_neighbor_t *); |
| 272 | vnet_main_t *vnm = vnet_get_main (); |
| 273 | vnet_sw_interface_t *si; |
| 274 | u8 *flags = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 275 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 276 | if (!n) |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 277 | return format (s, "%=12s%=25s%=6s%=20s%=40s", "Time", "Address", "Flags", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 278 | "Link layer", "Interface"); |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 279 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 280 | if (n->flags & IP6_NEIGHBOR_FLAG_DYNAMIC) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 281 | flags = format (flags, "D"); |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 282 | |
| 283 | if (n->flags & IP6_NEIGHBOR_FLAG_STATIC) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 284 | flags = format (flags, "S"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 285 | |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 286 | if (n->flags & IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY) |
| 287 | flags = format (flags, "N"); |
| 288 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | si = vnet_get_sw_interface (vnm, n->key.sw_if_index); |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 290 | s = format (s, "%=12U%=25U%=6s%=20U%=40U", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 291 | format_vlib_cpu_time, vm, n->cpu_time_last_updated, |
| 292 | format_ip6_address, &n->key.ip6_address, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 293 | flags ? (char *) flags : "", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 294 | format_ethernet_address, n->link_layer_address, |
| 295 | format_vnet_sw_interface_name, vnm, si); |
| 296 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 297 | vec_free (flags); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 298 | return s; |
| 299 | } |
| 300 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 301 | static void |
Neale Ranns | 6b3a8ef | 2017-09-11 10:34:33 -0700 | [diff] [blame] | 302 | ip6_neighbor_adj_fib_remove (ip6_neighbor_t * n, u32 fib_index) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 303 | { |
| 304 | if (FIB_NODE_INDEX_INVALID != n->fib_entry_index) |
| 305 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 306 | if (ip6_address_is_link_local_unicast (&n->key.ip6_address)) |
| 307 | { |
| 308 | ip6_ll_prefix_t pfx = { |
| 309 | .ilp_addr = n->key.ip6_address, |
| 310 | .ilp_sw_if_index = n->key.sw_if_index, |
| 311 | }; |
| 312 | ip6_ll_table_entry_delete (&pfx); |
| 313 | } |
| 314 | else |
| 315 | { |
| 316 | fib_prefix_t pfx = { |
| 317 | .fp_len = 128, |
| 318 | .fp_proto = FIB_PROTOCOL_IP6, |
| 319 | .fp_addr.ip6 = n->key.ip6_address, |
| 320 | }; |
| 321 | fib_table_entry_path_remove (fib_index, |
| 322 | &pfx, |
| 323 | FIB_SOURCE_ADJ, |
| 324 | DPO_PROTO_IP6, |
| 325 | &pfx.fp_addr, |
| 326 | n->key.sw_if_index, ~0, |
| 327 | 1, FIB_ROUTE_PATH_FLAG_NONE); |
| 328 | } |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 332 | static clib_error_t * |
| 333 | ip6_neighbor_sw_interface_up_down (vnet_main_t * vnm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 334 | u32 sw_if_index, u32 flags) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 335 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 336 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 337 | ip6_neighbor_t *n; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 338 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 339 | if (!(flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)) |
| 340 | { |
| 341 | u32 i, *to_delete = 0; |
| 342 | |
| 343 | /* *INDENT-OFF* */ |
| 344 | pool_foreach (n, nm->neighbor_pool, |
| 345 | ({ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | if (n->key.sw_if_index == sw_if_index) |
| 347 | vec_add1 (to_delete, n - nm->neighbor_pool); |
| 348 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 349 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 350 | |
| 351 | for (i = 0; i < vec_len (to_delete); i++) |
| 352 | { |
| 353 | n = pool_elt_at_index (nm->neighbor_pool, to_delete[i]); |
| 354 | mhash_unset (&nm->neighbor_index_by_key, &n->key, 0); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 355 | ip6_neighbor_adj_fib_remove (n, |
| 356 | ip6_fib_table_get_index_for_sw_if_index |
| 357 | (n->key.sw_if_index)); |
| 358 | pool_put (nm->neighbor_pool, n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 360 | vec_free (to_delete); |
| 361 | } |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip6_neighbor_sw_interface_up_down); |
| 367 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 368 | static void |
| 369 | unset_random_neighbor_entry (void) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 370 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 371 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 372 | vnet_main_t *vnm = vnet_get_main (); |
| 373 | vlib_main_t *vm = vnm->vlib_main; |
| 374 | ip6_neighbor_t *e; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | u32 index; |
| 376 | |
| 377 | index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor); |
| 378 | nm->neighbor_delete_rotor = index; |
| 379 | |
| 380 | /* Try again from elt 0, could happen if an intfc goes down */ |
| 381 | if (index == ~0) |
| 382 | { |
| 383 | index = pool_next_index (nm->neighbor_pool, nm->neighbor_delete_rotor); |
| 384 | nm->neighbor_delete_rotor = index; |
| 385 | } |
| 386 | |
| 387 | /* Nothing left in the pool */ |
| 388 | if (index == ~0) |
| 389 | return; |
| 390 | |
| 391 | e = pool_elt_at_index (nm->neighbor_pool, index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 392 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 393 | vnet_unset_ip6_ethernet_neighbor (vm, e->key.sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 394 | &e->key.ip6_address, |
| 395 | e->link_layer_address, |
| 396 | ETHER_MAC_ADDR_LEN); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 399 | typedef struct |
| 400 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | u8 is_add; |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 402 | u8 is_static; |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 403 | u8 is_no_fib_entry; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | u8 link_layer_address[6]; |
| 405 | u32 sw_if_index; |
| 406 | ip6_address_t addr; |
| 407 | } ip6_neighbor_set_unset_rpc_args_t; |
| 408 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 409 | static void ip6_neighbor_set_unset_rpc_callback |
| 410 | (ip6_neighbor_set_unset_rpc_args_t * a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 411 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 412 | static void set_unset_ip6_neighbor_rpc |
| 413 | (vlib_main_t * vm, |
| 414 | u32 sw_if_index, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 415 | ip6_address_t * a, u8 * link_layer_address, int is_add, int is_static, |
| 416 | int is_no_fib_entry) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 417 | { |
| 418 | ip6_neighbor_set_unset_rpc_args_t args; |
Dave Barach | f9bd620 | 2015-12-14 13:22:11 -0500 | [diff] [blame] | 419 | void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 420 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 421 | args.sw_if_index = sw_if_index; |
| 422 | args.is_add = is_add; |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 423 | args.is_static = is_static; |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 424 | args.is_no_fib_entry = is_no_fib_entry; |
Damjan Marion | f1213b8 | 2016-03-13 02:22:06 +0100 | [diff] [blame] | 425 | clib_memcpy (&args.addr, a, sizeof (*a)); |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 426 | if (NULL != link_layer_address) |
| 427 | clib_memcpy (args.link_layer_address, link_layer_address, 6); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 428 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 429 | vl_api_rpc_call_main_thread (ip6_neighbor_set_unset_rpc_callback, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 430 | (u8 *) & args, sizeof (args)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 431 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 433 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 434 | ip6_nbr_probe (ip_adjacency_t * adj) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 435 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 436 | icmp6_neighbor_solicitation_header_t *h; |
| 437 | vnet_main_t *vnm = vnet_get_main (); |
| 438 | ip6_main_t *im = &ip6_main; |
| 439 | ip_interface_address_t *ia; |
| 440 | ip6_address_t *dst, *src; |
| 441 | vnet_hw_interface_t *hi; |
| 442 | vnet_sw_interface_t *si; |
| 443 | vlib_buffer_t *b; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 444 | int bogus_length; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 445 | vlib_main_t *vm; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 446 | u32 bi = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 447 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 448 | vm = vlib_get_main (); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 449 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 450 | si = vnet_get_sw_interface (vnm, adj->rewrite_header.sw_if_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 451 | dst = &adj->sub_type.nbr.next_hop.ip6; |
| 452 | |
| 453 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 454 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 455 | return; |
| 456 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 457 | src = ip6_interface_address_matching_destination (im, dst, |
| 458 | adj->rewrite_header. |
| 459 | sw_if_index, &ia); |
| 460 | if (!src) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 461 | { |
| 462 | return; |
| 463 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 464 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 465 | h = vlib_packet_template_get_packet (vm, |
| 466 | &im->discover_neighbor_packet_template, |
| 467 | &bi); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 468 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 469 | hi = vnet_get_sup_hw_interface (vnm, adj->rewrite_header.sw_if_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 470 | |
| 471 | h->ip.dst_address.as_u8[13] = dst->as_u8[13]; |
| 472 | h->ip.dst_address.as_u8[14] = dst->as_u8[14]; |
| 473 | h->ip.dst_address.as_u8[15] = dst->as_u8[15]; |
| 474 | h->ip.src_address = src[0]; |
| 475 | h->neighbor.target_address = dst[0]; |
| 476 | |
| 477 | clib_memcpy (h->link_layer_option.ethernet_address, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 478 | hi->hw_address, vec_len (hi->hw_address)); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 479 | |
| 480 | h->neighbor.icmp.checksum = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 481 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length); |
| 482 | ASSERT (bogus_length == 0); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 483 | |
| 484 | b = vlib_get_buffer (vm, bi); |
| 485 | vnet_buffer (b)->sw_if_index[VLIB_RX] = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 486 | vnet_buffer (b)->sw_if_index[VLIB_TX] = adj->rewrite_header.sw_if_index; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 487 | |
| 488 | /* Add encapsulation string for software interface (e.g. ethernet header). */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 489 | vnet_rewrite_one_header (adj[0], h, sizeof (ethernet_header_t)); |
| 490 | vlib_buffer_advance (b, -adj->rewrite_header.data_bytes); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 491 | |
| 492 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 493 | vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index); |
| 494 | u32 *to_next = vlib_frame_vector_args (f); |
| 495 | to_next[0] = bi; |
| 496 | f->n_vectors = 1; |
| 497 | vlib_put_frame_to_node (vm, hi->output_node_index, f); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| 501 | static void |
| 502 | ip6_nd_mk_complete (adj_index_t ai, ip6_neighbor_t * nbr) |
| 503 | { |
| 504 | adj_nbr_update_rewrite (ai, ADJ_NBR_REWRITE_FLAG_COMPLETE, |
| 505 | ethernet_build_rewrite (vnet_get_main (), |
| 506 | nbr->key.sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 507 | adj_get_link_type (ai), |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 508 | nbr->link_layer_address)); |
| 509 | } |
| 510 | |
| 511 | static void |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 512 | ip6_nd_mk_incomplete (adj_index_t ai) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 513 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 514 | ip_adjacency_t *adj = adj_get (ai); |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 515 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 516 | adj_nbr_update_rewrite (ai, |
| 517 | ADJ_NBR_REWRITE_FLAG_INCOMPLETE, |
| 518 | ethernet_build_rewrite (vnet_get_main (), |
| 519 | adj->rewrite_header. |
| 520 | sw_if_index, |
| 521 | adj_get_link_type (ai), |
| 522 | VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST)); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | #define IP6_NBR_MK_KEY(k, sw_if_index, addr) \ |
| 526 | { \ |
| 527 | k.sw_if_index = sw_if_index; \ |
| 528 | k.ip6_address = *addr; \ |
| 529 | k.pad = 0; \ |
| 530 | } |
| 531 | |
| 532 | static ip6_neighbor_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 533 | ip6_nd_find (u32 sw_if_index, const ip6_address_t * addr) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 534 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 535 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 536 | ip6_neighbor_t *n = NULL; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 537 | ip6_neighbor_key_t k; |
| 538 | uword *p; |
| 539 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 540 | IP6_NBR_MK_KEY (k, sw_if_index, addr); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 541 | |
| 542 | p = mhash_get (&nm->neighbor_index_by_key, &k); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 543 | if (p) |
| 544 | { |
| 545 | n = pool_elt_at_index (nm->neighbor_pool, p[0]); |
| 546 | } |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 547 | |
| 548 | return (n); |
| 549 | } |
| 550 | |
| 551 | static adj_walk_rc_t |
| 552 | ip6_nd_mk_complete_walk (adj_index_t ai, void *ctx) |
| 553 | { |
| 554 | ip6_neighbor_t *nbr = ctx; |
| 555 | |
| 556 | ip6_nd_mk_complete (ai, nbr); |
| 557 | |
| 558 | return (ADJ_WALK_RC_CONTINUE); |
| 559 | } |
| 560 | |
| 561 | static adj_walk_rc_t |
| 562 | ip6_nd_mk_incomplete_walk (adj_index_t ai, void *ctx) |
| 563 | { |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 564 | ip6_nd_mk_incomplete (ai); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 565 | |
| 566 | return (ADJ_WALK_RC_CONTINUE); |
| 567 | } |
| 568 | |
| 569 | void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 570 | ip6_ethernet_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 571 | { |
| 572 | ip6_neighbor_t *nbr; |
| 573 | ip_adjacency_t *adj; |
| 574 | |
| 575 | adj = adj_get (ai); |
| 576 | |
| 577 | nbr = ip6_nd_find (sw_if_index, &adj->sub_type.nbr.next_hop.ip6); |
| 578 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 579 | switch (adj->lookup_next_index) |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 580 | { |
Ole Trøan | 438f630 | 2018-02-15 21:56:06 +0000 | [diff] [blame] | 581 | case IP_LOOKUP_NEXT_GLEAN: |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 582 | adj_glean_update_rewrite (ai); |
| 583 | break; |
| 584 | case IP_LOOKUP_NEXT_ARP: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 585 | if (NULL != nbr) |
| 586 | { |
| 587 | adj_nbr_walk_nh6 (sw_if_index, &nbr->key.ip6_address, |
| 588 | ip6_nd_mk_complete_walk, nbr); |
| 589 | } |
| 590 | else |
| 591 | { |
| 592 | /* |
| 593 | * no matching ND entry. |
| 594 | * construct the rewrite required to for an ND packet, and stick |
| 595 | * that in the adj's pipe to smoke. |
| 596 | */ |
| 597 | adj_nbr_update_rewrite (ai, |
| 598 | ADJ_NBR_REWRITE_FLAG_INCOMPLETE, |
| 599 | ethernet_build_rewrite (vnm, |
| 600 | sw_if_index, |
| 601 | VNET_LINK_IP6, |
| 602 | VNET_REWRITE_FOR_SW_INTERFACE_ADDRESS_BROADCAST)); |
| 603 | |
| 604 | /* |
| 605 | * since the FIB has added this adj for a route, it makes sense it may |
| 606 | * want to forward traffic sometime soon. Let's send a speculative ND. |
| 607 | * just one. If we were to do periodically that wouldn't be bad either, |
| 608 | * but that's more code than i'm prepared to write at this time for |
| 609 | * relatively little reward. |
| 610 | */ |
| 611 | ip6_nbr_probe (adj); |
| 612 | } |
| 613 | break; |
| 614 | case IP_LOOKUP_NEXT_MCAST: |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 615 | { |
| 616 | /* |
| 617 | * Construct a partial rewrite from the known ethernet mcast dest MAC |
| 618 | */ |
| 619 | u8 *rewrite; |
| 620 | u8 offset; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 621 | |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 622 | rewrite = ethernet_build_rewrite (vnm, |
| 623 | sw_if_index, |
| 624 | adj->ia_link, |
| 625 | ethernet_ip6_mcast_dst_addr ()); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 626 | |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 627 | /* |
| 628 | * Complete the remaining fields of the adj's rewrite to direct the |
| 629 | * complete of the rewrite at switch time by copying in the IP |
| 630 | * dst address's bytes. |
| 631 | * Ofset is 2 bytes into the desintation address. And we write 4 bytes. |
| 632 | */ |
| 633 | offset = vec_len (rewrite) - 2; |
| 634 | adj_mcast_update_rewrite (ai, rewrite, offset, 0xffffffff); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 635 | |
Neale Ranns | 2e7fbcc | 2017-03-15 04:22:25 -0700 | [diff] [blame] | 636 | break; |
| 637 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 638 | case IP_LOOKUP_NEXT_DROP: |
| 639 | case IP_LOOKUP_NEXT_PUNT: |
| 640 | case IP_LOOKUP_NEXT_LOCAL: |
| 641 | case IP_LOOKUP_NEXT_REWRITE: |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 642 | case IP_LOOKUP_NEXT_MCAST_MIDCHAIN: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 643 | case IP_LOOKUP_NEXT_MIDCHAIN: |
| 644 | case IP_LOOKUP_NEXT_ICMP_ERROR: |
| 645 | case IP_LOOKUP_N_NEXT: |
| 646 | ASSERT (0); |
| 647 | break; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 651 | |
| 652 | static void |
Neale Ranns | 6b3a8ef | 2017-09-11 10:34:33 -0700 | [diff] [blame] | 653 | ip6_neighbor_adj_fib_add (ip6_neighbor_t * n, u32 fib_index) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 654 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 655 | if (ip6_address_is_link_local_unicast (&n->key.ip6_address)) |
| 656 | { |
| 657 | ip6_ll_prefix_t pfx = { |
| 658 | .ilp_addr = n->key.ip6_address, |
| 659 | .ilp_sw_if_index = n->key.sw_if_index, |
| 660 | }; |
| 661 | n->fib_entry_index = |
| 662 | ip6_ll_table_entry_update (&pfx, FIB_ROUTE_PATH_FLAG_NONE); |
| 663 | } |
| 664 | else |
| 665 | { |
| 666 | fib_prefix_t pfx = { |
| 667 | .fp_len = 128, |
| 668 | .fp_proto = FIB_PROTOCOL_IP6, |
| 669 | .fp_addr.ip6 = n->key.ip6_address, |
| 670 | }; |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 671 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 672 | n->fib_entry_index = |
| 673 | fib_table_entry_path_add (fib_index, &pfx, FIB_SOURCE_ADJ, |
| 674 | FIB_ENTRY_FLAG_ATTACHED, |
| 675 | DPO_PROTO_IP6, &pfx.fp_addr, |
| 676 | n->key.sw_if_index, ~0, 1, NULL, |
| 677 | FIB_ROUTE_PATH_FLAG_NONE); |
| 678 | } |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 681 | int |
| 682 | vnet_set_ip6_ethernet_neighbor (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 683 | u32 sw_if_index, |
| 684 | ip6_address_t * a, |
| 685 | u8 * link_layer_address, |
| 686 | uword n_bytes_link_layer_address, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 687 | int is_static, int is_no_fib_entry) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 688 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 689 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 690 | ip6_neighbor_key_t k; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 691 | ip6_neighbor_t *n = 0; |
| 692 | int make_new_nd_cache_entry = 1; |
| 693 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 694 | u32 next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 695 | pending_resolution_t *pr, *mc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 696 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 697 | if (vlib_get_thread_index ()) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 698 | { |
| 699 | set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 700 | 1 /* set new neighbor */ , is_static, |
| 701 | is_no_fib_entry); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 702 | return 0; |
| 703 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 704 | |
| 705 | k.sw_if_index = sw_if_index; |
| 706 | k.ip6_address = a[0]; |
| 707 | k.pad = 0; |
| 708 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 709 | p = mhash_get (&nm->neighbor_index_by_key, &k); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 710 | if (p) |
| 711 | { |
| 712 | n = pool_elt_at_index (nm->neighbor_pool, p[0]); |
| 713 | /* Refuse to over-write static neighbor entry. */ |
| 714 | if (!is_static && (n->flags & IP6_NEIGHBOR_FLAG_STATIC)) |
| 715 | return -2; |
| 716 | make_new_nd_cache_entry = 0; |
| 717 | } |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 718 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 719 | if (make_new_nd_cache_entry) |
| 720 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 721 | pool_get (nm->neighbor_pool, n); |
| 722 | mhash_set (&nm->neighbor_index_by_key, &k, n - nm->neighbor_pool, |
| 723 | /* old value */ 0); |
| 724 | n->key = k; |
Neale Ranns | d5b6aa1 | 2017-05-16 08:46:45 -0700 | [diff] [blame] | 725 | n->fib_entry_index = FIB_NODE_INDEX_INVALID; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 726 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 727 | clib_memcpy (n->link_layer_address, |
| 728 | link_layer_address, n_bytes_link_layer_address); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 729 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 730 | /* |
| 731 | * create the adj-fib. the entry in the FIB table for and to the peer. |
| 732 | */ |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 733 | if (!is_no_fib_entry) |
| 734 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 735 | ip6_neighbor_adj_fib_add |
| 736 | (n, ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index)); |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 737 | } |
| 738 | else |
| 739 | { |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 740 | n->flags |= IP6_NEIGHBOR_FLAG_NO_FIB_ENTRY; |
| 741 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 742 | } |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 743 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 744 | { |
| 745 | /* |
| 746 | * prevent a DoS attack from the data-plane that |
| 747 | * spams us with no-op updates to the MAC address |
| 748 | */ |
| 749 | if (0 == memcmp (n->link_layer_address, |
| 750 | link_layer_address, n_bytes_link_layer_address)) |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 751 | goto check_customers; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 752 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 753 | clib_memcpy (n->link_layer_address, |
| 754 | link_layer_address, n_bytes_link_layer_address); |
| 755 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 756 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 757 | /* Update time stamp and flags. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 758 | n->cpu_time_last_updated = clib_cpu_time_now (); |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 759 | if (is_static) |
| 760 | n->flags |= IP6_NEIGHBOR_FLAG_STATIC; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 761 | else |
| 762 | n->flags |= IP6_NEIGHBOR_FLAG_DYNAMIC; |
| 763 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 764 | adj_nbr_walk_nh6 (sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 765 | &n->key.ip6_address, ip6_nd_mk_complete_walk, n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 766 | |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 767 | check_customers: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 768 | /* Customer(s) waiting for this address to be resolved? */ |
| 769 | p = mhash_get (&nm->pending_resolutions_by_address, a); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 770 | if (p) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 771 | { |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 772 | next_index = p[0]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 773 | |
| 774 | while (next_index != (u32) ~ 0) |
| 775 | { |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 776 | pr = pool_elt_at_index (nm->pending_resolutions, next_index); |
| 777 | vlib_process_signal_event (vm, pr->node_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 778 | pr->type_opaque, pr->data); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 779 | next_index = pr->next_index; |
| 780 | pool_put (nm->pending_resolutions, pr); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 781 | } |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 782 | |
| 783 | mhash_unset (&nm->pending_resolutions_by_address, a, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 784 | } |
| 785 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 786 | /* Customer(s) requesting ND event for this address? */ |
| 787 | p = mhash_get (&nm->mac_changes_by_address, a); |
| 788 | if (p) |
| 789 | { |
| 790 | next_index = p[0]; |
| 791 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 792 | while (next_index != (u32) ~ 0) |
| 793 | { |
| 794 | int (*fp) (u32, u8 *, u32, ip6_address_t *); |
| 795 | int rv = 1; |
| 796 | mc = pool_elt_at_index (nm->mac_changes, next_index); |
| 797 | fp = mc->data_callback; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 798 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 799 | /* Call the user's data callback, return 1 to suppress dup events */ |
| 800 | if (fp) |
| 801 | rv = |
| 802 | (*fp) (mc->data, link_layer_address, sw_if_index, &ip6a_zero); |
| 803 | /* |
| 804 | * Signal the resolver process, as long as the user |
| 805 | * says they want to be notified |
| 806 | */ |
| 807 | if (rv == 0) |
| 808 | vlib_process_signal_event (vm, mc->node_index, |
| 809 | mc->type_opaque, mc->data); |
| 810 | next_index = mc->next_index; |
| 811 | } |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 812 | } |
| 813 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | int |
| 818 | vnet_unset_ip6_ethernet_neighbor (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 819 | u32 sw_if_index, |
| 820 | ip6_address_t * a, |
| 821 | u8 * link_layer_address, |
| 822 | uword n_bytes_link_layer_address) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 823 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 824 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 825 | ip6_neighbor_key_t k; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 826 | ip6_neighbor_t *n; |
| 827 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 828 | int rv = 0; |
| 829 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 830 | if (vlib_get_thread_index ()) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 831 | { |
| 832 | set_unset_ip6_neighbor_rpc (vm, sw_if_index, a, link_layer_address, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 833 | 0 /* unset */ , 0, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 834 | return 0; |
| 835 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 836 | |
| 837 | k.sw_if_index = sw_if_index; |
| 838 | k.ip6_address = a[0]; |
| 839 | k.pad = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 840 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 841 | p = mhash_get (&nm->neighbor_index_by_key, &k); |
| 842 | if (p == 0) |
| 843 | { |
| 844 | rv = -1; |
| 845 | goto out; |
| 846 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 847 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 848 | n = pool_elt_at_index (nm->neighbor_pool, p[0]); |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 849 | mhash_unset (&nm->neighbor_index_by_key, &n->key, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 850 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 851 | adj_nbr_walk_nh6 (sw_if_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 852 | &n->key.ip6_address, ip6_nd_mk_incomplete_walk, NULL); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 853 | |
Neale Ranns | d5b6aa1 | 2017-05-16 08:46:45 -0700 | [diff] [blame] | 854 | |
| 855 | if (FIB_NODE_INDEX_INVALID != n->fib_entry_index) |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 856 | { |
| 857 | fib_prefix_t pfx = { |
| 858 | .fp_len = 128, |
| 859 | .fp_proto = FIB_PROTOCOL_IP6, |
| 860 | .fp_addr.ip6 = n->key.ip6_address, |
| 861 | }; |
| 862 | fib_table_entry_path_remove |
| 863 | (ip6_fib_table_get_index_for_sw_if_index (n->key.sw_if_index), |
| 864 | &pfx, |
| 865 | FIB_SOURCE_ADJ, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 866 | DPO_PROTO_IP6, |
Neale Ranns | dcd6d62 | 2017-05-26 02:59:16 -0700 | [diff] [blame] | 867 | &pfx.fp_addr, n->key.sw_if_index, ~0, 1, FIB_ROUTE_PATH_FLAG_NONE); |
| 868 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 869 | pool_put (nm->neighbor_pool, n); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 870 | |
| 871 | out: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 872 | return rv; |
| 873 | } |
| 874 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 875 | static void ip6_neighbor_set_unset_rpc_callback |
| 876 | (ip6_neighbor_set_unset_rpc_args_t * a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 877 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 878 | vlib_main_t *vm = vlib_get_main (); |
| 879 | if (a->is_add) |
| 880 | vnet_set_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 881 | a->link_layer_address, 6, a->is_static, |
| 882 | a->is_no_fib_entry); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 883 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 884 | vnet_unset_ip6_ethernet_neighbor (vm, a->sw_if_index, &a->addr, |
| 885 | a->link_layer_address, 6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 886 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 887 | |
| 888 | static int |
| 889 | ip6_neighbor_sort (void *a1, void *a2) |
| 890 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 891 | vnet_main_t *vnm = vnet_get_main (); |
| 892 | ip6_neighbor_t *n1 = a1, *n2 = a2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 893 | int cmp; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 894 | cmp = vnet_sw_interface_compare (vnm, n1->key.sw_if_index, |
| 895 | n2->key.sw_if_index); |
| 896 | if (!cmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 897 | cmp = ip6_address_compare (&n1->key.ip6_address, &n2->key.ip6_address); |
| 898 | return cmp; |
| 899 | } |
| 900 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 901 | ip6_neighbor_t * |
| 902 | ip6_neighbors_entries (u32 sw_if_index) |
| 903 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 904 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 905 | ip6_neighbor_t *n, *ns = 0; |
| 906 | |
| 907 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 908 | pool_foreach (n, nm->neighbor_pool, |
| 909 | ({ |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 910 | if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index) |
| 911 | continue; |
| 912 | vec_add1 (ns, n[0]); |
| 913 | })); |
| 914 | /* *INDENT-ON* */ |
| 915 | |
| 916 | if (ns) |
| 917 | vec_sort_with_function (ns, ip6_neighbor_sort); |
| 918 | return ns; |
| 919 | } |
| 920 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 921 | static clib_error_t * |
| 922 | show_ip6_neighbors (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 923 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 924 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 925 | vnet_main_t *vnm = vnet_get_main (); |
| 926 | ip6_neighbor_t *n, *ns; |
| 927 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 928 | u32 sw_if_index; |
| 929 | |
| 930 | /* Filter entries by interface if given. */ |
| 931 | sw_if_index = ~0; |
| 932 | (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index); |
| 933 | |
Pavel Kotucek | 3e046ea | 2016-12-05 08:27:37 +0100 | [diff] [blame] | 934 | ns = ip6_neighbors_entries (sw_if_index); |
Billy McFall | 46529cd | 2016-10-14 10:45:49 -0400 | [diff] [blame] | 935 | if (ns) |
| 936 | { |
Billy McFall | 46529cd | 2016-10-14 10:45:49 -0400 | [diff] [blame] | 937 | vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 938 | vec_foreach (n, ns) |
| 939 | { |
| 940 | vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, n); |
Billy McFall | 46529cd | 2016-10-14 10:45:49 -0400 | [diff] [blame] | 941 | } |
| 942 | vec_free (ns); |
| 943 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 944 | |
| 945 | return error; |
| 946 | } |
| 947 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 948 | /*? |
| 949 | * This command is used to display the adjacent IPv6 hosts found via |
| 950 | * neighbor discovery. Optionally, limit the output to the specified |
| 951 | * interface. |
| 952 | * |
| 953 | * @cliexpar |
| 954 | * Example of how to display the IPv6 neighbor adjacency table: |
| 955 | * @cliexstart{show ip6 neighbors} |
| 956 | * Time Address Flags Link layer Interface |
| 957 | * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0 |
| 958 | * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0 |
| 959 | * 886.6654 ::1:1:c:0:9 S 02:fe:e4:45:27:5b GigabitEthernet3/0/0 |
| 960 | * @cliexend |
| 961 | * Example of how to display the IPv6 neighbor adjacency table for given interface: |
| 962 | * @cliexstart{show ip6 neighbors GigabitEthernet2/0/0} |
| 963 | * Time Address Flags Link layer Interface |
| 964 | * 34.0910 ::a:1:1:0:7 02:fe:6a:07:39:6f GigabitEthernet2/0/0 |
| 965 | * 173.2916 ::b:5:1:c:2 02:fe:50:62:3a:94 GigabitEthernet2/0/0 |
| 966 | * @cliexend |
| 967 | ?*/ |
| 968 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 969 | VLIB_CLI_COMMAND (show_ip6_neighbors_command, static) = { |
| 970 | .path = "show ip6 neighbors", |
| 971 | .function = show_ip6_neighbors, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 972 | .short_help = "show ip6 neighbors [<interface>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 973 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 974 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 975 | |
| 976 | static clib_error_t * |
| 977 | set_ip6_neighbor (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 978 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 979 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 980 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 981 | ip6_address_t addr; |
| 982 | u8 mac_address[6]; |
| 983 | int addr_valid = 0; |
| 984 | int is_del = 0; |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 985 | int is_static = 0; |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 986 | int is_no_fib_entry = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 987 | u32 sw_if_index; |
| 988 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 989 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 990 | { |
| 991 | /* intfc, ip6-address, mac-address */ |
| 992 | if (unformat (input, "%U %U %U", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 993 | unformat_vnet_sw_interface, vnm, &sw_if_index, |
| 994 | unformat_ip6_address, &addr, |
| 995 | unformat_ethernet_address, mac_address)) |
| 996 | addr_valid = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 997 | |
| 998 | else if (unformat (input, "delete") || unformat (input, "del")) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 999 | is_del = 1; |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 1000 | else if (unformat (input, "static")) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1001 | is_static = 1; |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 1002 | else if (unformat (input, "no-fib-entry")) |
| 1003 | is_no_fib_entry = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1004 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1005 | break; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | if (!addr_valid) |
| 1009 | return clib_error_return (0, "Missing interface, ip6 or hw address"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1010 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1011 | if (!is_del) |
| 1012 | vnet_set_ip6_ethernet_neighbor (vm, sw_if_index, &addr, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1013 | mac_address, sizeof (mac_address), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 1014 | is_static, is_no_fib_entry); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1015 | else |
| 1016 | vnet_unset_ip6_ethernet_neighbor (vm, sw_if_index, &addr, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1017 | mac_address, sizeof (mac_address)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1018 | return 0; |
| 1019 | } |
| 1020 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1021 | /*? |
| 1022 | * This command is used to manually add an entry to the IPv6 neighbor |
| 1023 | * adjacency table. Optionally, the entry can be added as static. It is |
| 1024 | * also used to remove an entry from the table. Use the '<em>show ip6 |
| 1025 | * neighbors</em>' command to display all learned and manually entered entries. |
| 1026 | * |
| 1027 | * @cliexpar |
| 1028 | * Example of how to add a static entry to the IPv6 neighbor adjacency table: |
| 1029 | * @cliexcmd{set ip6 neighbor GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b static} |
| 1030 | * Example of how to delete an entry from the IPv6 neighbor adjacency table: |
| 1031 | * @cliexcmd{set ip6 neighbor del GigabitEthernet2/0/0 ::1:1:c:0:9 02:fe:e4:45:27:5b} |
| 1032 | ?*/ |
| 1033 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1034 | VLIB_CLI_COMMAND (set_ip6_neighbor_command, static) = |
| 1035 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1036 | .path = "set ip6 neighbor", |
| 1037 | .function = set_ip6_neighbor, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1038 | .short_help = "set ip6 neighbor [del] <interface> <ip6-address> <mac-address> [static]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1039 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 1040 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1041 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1042 | typedef enum |
| 1043 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1044 | ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP, |
| 1045 | ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY, |
| 1046 | ICMP6_NEIGHBOR_SOLICITATION_N_NEXT, |
| 1047 | } icmp6_neighbor_solicitation_or_advertisement_next_t; |
| 1048 | |
| 1049 | static_always_inline uword |
| 1050 | icmp6_neighbor_solicitation_or_advertisement (vlib_main_t * vm, |
| 1051 | vlib_node_runtime_t * node, |
| 1052 | vlib_frame_t * frame, |
| 1053 | uword is_solicitation) |
| 1054 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1055 | vnet_main_t *vnm = vnet_get_main (); |
| 1056 | ip6_main_t *im = &ip6_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1057 | uword n_packets = frame->n_vectors; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1058 | u32 *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1059 | u32 n_left_from, n_left_to_next, next_index, n_advertisements_sent; |
| 1060 | icmp6_neighbor_discovery_option_type_t option_type; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1061 | vlib_node_runtime_t *error_node = |
| 1062 | vlib_node_get_runtime (vm, ip6_icmp_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1063 | int bogus_length; |
| 1064 | |
| 1065 | from = vlib_frame_vector_args (frame); |
| 1066 | n_left_from = n_packets; |
| 1067 | next_index = node->cached_next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1068 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1069 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1070 | vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors, |
| 1071 | /* stride */ 1, |
| 1072 | sizeof (icmp6_input_trace_t)); |
| 1073 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1074 | option_type = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1075 | (is_solicitation |
| 1076 | ? ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address |
| 1077 | : ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address); |
| 1078 | n_advertisements_sent = 0; |
| 1079 | |
| 1080 | while (n_left_from > 0) |
| 1081 | { |
| 1082 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 1083 | |
| 1084 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1085 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1086 | vlib_buffer_t *p0; |
| 1087 | ip6_header_t *ip0; |
| 1088 | icmp6_neighbor_solicitation_or_advertisement_header_t *h0; |
| 1089 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1090 | u32 bi0, options_len0, sw_if_index0, next0, error0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1091 | u32 ip6_sadd_link_local, ip6_sadd_unspecified; |
| 1092 | int is_rewrite0; |
| 1093 | u32 ni0; |
| 1094 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1095 | bi0 = to_next[0] = from[0]; |
| 1096 | |
| 1097 | from += 1; |
| 1098 | to_next += 1; |
| 1099 | n_left_from -= 1; |
| 1100 | n_left_to_next -= 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1101 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1102 | p0 = vlib_get_buffer (vm, bi0); |
| 1103 | ip0 = vlib_buffer_get_current (p0); |
| 1104 | h0 = ip6_next_header (ip0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1105 | options_len0 = |
| 1106 | clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1107 | |
| 1108 | error0 = ICMP6_ERROR_NONE; |
| 1109 | sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1110 | ip6_sadd_link_local = |
| 1111 | ip6_address_is_link_local_unicast (&ip0->src_address); |
| 1112 | ip6_sadd_unspecified = |
| 1113 | ip6_address_is_unspecified (&ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1114 | |
| 1115 | /* Check that source address is unspecified, link-local or else on-link. */ |
| 1116 | if (!ip6_sadd_unspecified && !ip6_sadd_link_local) |
| 1117 | { |
| 1118 | u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1119 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1120 | if (ADJ_INDEX_INVALID != src_adj_index0) |
| 1121 | { |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 1122 | ip_adjacency_t *adj0 = adj_get (src_adj_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1123 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1124 | /* Allow all realistic-looking rewrite adjacencies to pass */ |
| 1125 | ni0 = adj0->lookup_next_index; |
| 1126 | is_rewrite0 = (ni0 >= IP_LOOKUP_NEXT_ARP) && |
| 1127 | (ni0 < IP6_LOOKUP_N_NEXT); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1128 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1129 | error0 = ((adj0->rewrite_header.sw_if_index != sw_if_index0 |
| 1130 | || !is_rewrite0) |
| 1131 | ? |
| 1132 | ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK |
| 1133 | : error0); |
| 1134 | } |
| 1135 | else |
| 1136 | { |
| 1137 | error0 = |
| 1138 | ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_NOT_ON_LINK; |
| 1139 | } |
| 1140 | } |
| 1141 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1142 | o0 = (void *) (h0 + 1); |
| 1143 | o0 = ((options_len0 == 8 && o0->header.type == option_type |
| 1144 | && o0->header.n_data_u64s == 1) ? o0 : 0); |
| 1145 | |
| 1146 | /* If src address unspecified or link local, donot learn neighbor MAC */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1147 | if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 && |
Neale Ranns | 2a3ea49 | 2017-04-19 05:24:40 -0700 | [diff] [blame] | 1148 | !ip6_sadd_unspecified)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1149 | { |
| 1150 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 1151 | if (nm->limit_neighbor_cache_size && |
| 1152 | pool_elts (nm->neighbor_pool) >= |
| 1153 | nm->limit_neighbor_cache_size) |
| 1154 | unset_random_neighbor_entry (); |
| 1155 | vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0, |
| 1156 | is_solicitation ? |
| 1157 | &ip0->src_address : |
| 1158 | &h0->target_address, |
| 1159 | o0->ethernet_address, |
| 1160 | sizeof (o0->ethernet_address), |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 1161 | 0, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1162 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1163 | |
| 1164 | if (is_solicitation && error0 == ICMP6_ERROR_NONE) |
| 1165 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1166 | /* Check that target address is local to this router. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1167 | fib_node_index_t fei; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1168 | u32 fib_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1169 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1170 | fib_index = |
| 1171 | ip6_fib_table_get_index_for_sw_if_index (sw_if_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1172 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1173 | if (~0 == fib_index) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1174 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1175 | error0 = ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN; |
| 1176 | } |
| 1177 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1178 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 1179 | if (ip6_address_is_link_local_unicast (&h0->target_address)) |
| 1180 | { |
| 1181 | fei = ip6_fib_table_lookup_exact_match |
| 1182 | (ip6_ll_fib_get (sw_if_index0), |
| 1183 | &h0->target_address, 128); |
| 1184 | } |
| 1185 | else |
| 1186 | { |
| 1187 | fei = ip6_fib_table_lookup_exact_match (fib_index, |
| 1188 | &h0->target_address, |
| 1189 | 128); |
| 1190 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1191 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1192 | if (FIB_NODE_INDEX_INVALID == fei) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1193 | { |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1194 | /* The target address is not in the FIB */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1195 | error0 = |
| 1196 | ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1197 | } |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1198 | else |
| 1199 | { |
| 1200 | if (FIB_ENTRY_FLAG_LOCAL & |
| 1201 | fib_entry_get_flags_for_source (fei, |
| 1202 | FIB_SOURCE_INTERFACE)) |
| 1203 | { |
| 1204 | /* It's an address that belongs to one of our interfaces |
| 1205 | * that's good. */ |
| 1206 | } |
| 1207 | else |
| 1208 | if (fib_entry_is_sourced |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 1209 | (fei, FIB_SOURCE_IP6_ND_PROXY) || |
| 1210 | fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND)) |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1211 | { |
| 1212 | /* The address was added by IPv6 Proxy ND config. |
| 1213 | * We should only respond to these if the NS arrived on |
| 1214 | * the link that has a matching covering prefix */ |
| 1215 | } |
| 1216 | else |
| 1217 | { |
| 1218 | error0 = |
| 1219 | ICMP6_ERROR_NEIGHBOR_SOLICITATION_SOURCE_UNKNOWN; |
| 1220 | } |
| 1221 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1222 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | if (is_solicitation) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1226 | next0 = (error0 != ICMP6_ERROR_NONE |
| 1227 | ? ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP |
| 1228 | : ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1229 | else |
| 1230 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1231 | next0 = 0; |
| 1232 | error0 = error0 == ICMP6_ERROR_NONE ? |
| 1233 | ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_RX : error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | if (is_solicitation && error0 == ICMP6_ERROR_NONE) |
| 1237 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1238 | vnet_sw_interface_t *sw_if0; |
| 1239 | ethernet_interface_t *eth_if0; |
| 1240 | ethernet_header_t *eth0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1241 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1242 | /* dst address is either source address or the all-nodes mcast addr */ |
| 1243 | if (!ip6_sadd_unspecified) |
| 1244 | ip0->dst_address = ip0->src_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1245 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1246 | ip6_set_reserved_multicast_address (&ip0->dst_address, |
| 1247 | IP6_MULTICAST_SCOPE_link_local, |
| 1248 | IP6_MULTICAST_GROUP_ID_all_hosts); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1249 | |
| 1250 | ip0->src_address = h0->target_address; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1251 | ip0->hop_limit = 255; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1252 | h0->icmp.type = ICMP6_neighbor_advertisement; |
| 1253 | |
| 1254 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0); |
| 1255 | ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1256 | eth_if0 = |
| 1257 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1258 | if (eth_if0 && o0) |
| 1259 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1260 | clib_memcpy (o0->ethernet_address, eth_if0->address, 6); |
| 1261 | o0->header.type = |
| 1262 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | h0->advertisement_flags = clib_host_to_net_u32 |
| 1266 | (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED |
| 1267 | | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE); |
| 1268 | |
| 1269 | h0->icmp.checksum = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1270 | h0->icmp.checksum = |
| 1271 | ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, |
| 1272 | &bogus_length); |
| 1273 | ASSERT (bogus_length == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1274 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1275 | /* Reuse current MAC header, copy SMAC to DMAC and |
| 1276 | * interface MAC to SMAC */ |
| 1277 | vlib_buffer_advance (p0, -ethernet_buffer_header_size (p0)); |
| 1278 | eth0 = vlib_buffer_get_current (p0); |
| 1279 | clib_memcpy (eth0->dst_address, eth0->src_address, 6); |
| 1280 | if (eth_if0) |
| 1281 | clib_memcpy (eth0->src_address, eth_if0->address, 6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1282 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1283 | /* Setup input and output sw_if_index for packet */ |
| 1284 | ASSERT (vnet_buffer (p0)->sw_if_index[VLIB_RX] == sw_if_index0); |
| 1285 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = sw_if_index0; |
| 1286 | vnet_buffer (p0)->sw_if_index[VLIB_RX] = |
| 1287 | vnet_main.local_interface_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1288 | |
| 1289 | n_advertisements_sent++; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1290 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1291 | |
| 1292 | p0->error = error_node->errors[error0]; |
| 1293 | |
| 1294 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 1295 | to_next, n_left_to_next, |
| 1296 | bi0, next0); |
| 1297 | } |
| 1298 | |
| 1299 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1300 | } |
| 1301 | |
| 1302 | /* Account for advertisements sent. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1303 | vlib_error_count (vm, error_node->node_index, |
| 1304 | ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, |
| 1305 | n_advertisements_sent); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1306 | |
| 1307 | return frame->n_vectors; |
| 1308 | } |
| 1309 | |
| 1310 | /* for "syslogging" - use elog for now */ |
| 1311 | #define foreach_log_level \ |
| 1312 | _ (DEBUG, "DEBUG") \ |
| 1313 | _ (INFO, "INFORMATION") \ |
| 1314 | _ (NOTICE, "NOTICE") \ |
| 1315 | _ (WARNING, "WARNING") \ |
| 1316 | _ (ERR, "ERROR") \ |
| 1317 | _ (CRIT, "CRITICAL") \ |
| 1318 | _ (ALERT, "ALERT") \ |
| 1319 | _ (EMERG, "EMERGENCY") |
| 1320 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1321 | typedef enum |
| 1322 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1323 | #define _(f,s) LOG_##f, |
| 1324 | foreach_log_level |
| 1325 | #undef _ |
| 1326 | } log_level_t; |
| 1327 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1328 | static char *log_level_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1329 | #define _(f,s) s, |
| 1330 | foreach_log_level |
| 1331 | #undef _ |
| 1332 | }; |
| 1333 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1334 | static int logmask = 1 << LOG_DEBUG; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1335 | |
| 1336 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1337 | ip6_neighbor_syslog (vlib_main_t * vm, int priority, char *fmt, ...) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1338 | { |
| 1339 | /* just use elog for now */ |
| 1340 | u8 *what; |
| 1341 | va_list va; |
| 1342 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1343 | if ((priority > LOG_EMERG) || !(logmask & (1 << priority))) |
| 1344 | return; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1345 | |
| 1346 | va_start (va, fmt); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1347 | if (fmt) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1348 | { |
| 1349 | what = va_format (0, fmt, &va); |
| 1350 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1351 | ELOG_TYPE_DECLARE (e) = |
| 1352 | { |
| 1353 | .format = "ip6 nd: (%s): %s",.format_args = "T4T4",}; |
| 1354 | struct |
| 1355 | { |
| 1356 | u32 s[2]; |
| 1357 | } *ed; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1358 | ed = ELOG_DATA (&vm->elog_main, e); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1359 | ed->s[0] = elog_string (&vm->elog_main, log_level_strings[priority]); |
| 1360 | ed->s[1] = elog_string (&vm->elog_main, (char *) what); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1361 | } |
| 1362 | va_end (va); |
| 1363 | return; |
| 1364 | } |
| 1365 | |
| 1366 | /* ipv6 neighbor discovery - router advertisements */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1367 | typedef enum |
| 1368 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1369 | ICMP6_ROUTER_SOLICITATION_NEXT_DROP, |
| 1370 | ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW, |
| 1371 | ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX, |
| 1372 | ICMP6_ROUTER_SOLICITATION_N_NEXT, |
| 1373 | } icmp6_router_solicitation_or_advertisement_next_t; |
| 1374 | |
| 1375 | static_always_inline uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1376 | icmp6_router_solicitation (vlib_main_t * vm, |
| 1377 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1378 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1379 | vnet_main_t *vnm = vnet_get_main (); |
| 1380 | ip6_main_t *im = &ip6_main; |
| 1381 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1382 | uword n_packets = frame->n_vectors; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1383 | u32 *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1384 | u32 n_left_from, n_left_to_next, next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1385 | u32 n_advertisements_sent = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1386 | int bogus_length; |
| 1387 | |
| 1388 | icmp6_neighbor_discovery_option_type_t option_type; |
| 1389 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1390 | vlib_node_runtime_t *error_node = |
| 1391 | vlib_node_get_runtime (vm, ip6_icmp_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1392 | |
| 1393 | from = vlib_frame_vector_args (frame); |
| 1394 | n_left_from = n_packets; |
| 1395 | next_index = node->cached_next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1396 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1397 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1398 | vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors, |
| 1399 | /* stride */ 1, |
| 1400 | sizeof (icmp6_input_trace_t)); |
| 1401 | |
| 1402 | /* source may append his LL address */ |
| 1403 | option_type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address; |
| 1404 | |
| 1405 | while (n_left_from > 0) |
| 1406 | { |
| 1407 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1408 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1409 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1410 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1411 | vlib_buffer_t *p0; |
| 1412 | ip6_header_t *ip0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1413 | ip6_radv_t *radv_info = 0; |
| 1414 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1415 | icmp6_neighbor_discovery_header_t *h0; |
| 1416 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *o0; |
| 1417 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1418 | u32 bi0, options_len0, sw_if_index0, next0, error0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1419 | u32 is_solicitation = 1, is_dropped = 0; |
| 1420 | u32 is_unspecified, is_link_local; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1421 | |
| 1422 | bi0 = to_next[0] = from[0]; |
| 1423 | |
| 1424 | from += 1; |
| 1425 | to_next += 1; |
| 1426 | n_left_from -= 1; |
| 1427 | n_left_to_next -= 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1428 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1429 | p0 = vlib_get_buffer (vm, bi0); |
| 1430 | ip0 = vlib_buffer_get_current (p0); |
| 1431 | h0 = ip6_next_header (ip0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1432 | options_len0 = |
| 1433 | clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]); |
| 1434 | is_unspecified = ip6_address_is_unspecified (&ip0->src_address); |
| 1435 | is_link_local = |
| 1436 | ip6_address_is_link_local_unicast (&ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1437 | |
| 1438 | error0 = ICMP6_ERROR_NONE; |
| 1439 | sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1440 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1441 | /* check if solicitation (not from nd_timer node) */ |
| 1442 | if (ip6_address_is_unspecified (&ip0->dst_address)) |
| 1443 | is_solicitation = 0; |
| 1444 | |
| 1445 | /* Check that source address is unspecified, link-local or else on-link. */ |
| 1446 | if (!is_unspecified && !is_link_local) |
| 1447 | { |
| 1448 | u32 src_adj_index0 = ip6_src_lookup_for_packet (im, p0, ip0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1449 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1450 | if (ADJ_INDEX_INVALID != src_adj_index0) |
| 1451 | { |
Neale Ranns | 107e7d4 | 2017-04-11 09:55:19 -0700 | [diff] [blame] | 1452 | ip_adjacency_t *adj0 = adj_get (src_adj_index0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1453 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1454 | error0 = (adj0->rewrite_header.sw_if_index != sw_if_index0 |
| 1455 | ? |
| 1456 | ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK |
| 1457 | : error0); |
| 1458 | } |
| 1459 | else |
| 1460 | { |
| 1461 | error0 = ICMP6_ERROR_ROUTER_SOLICITATION_SOURCE_NOT_ON_LINK; |
| 1462 | } |
| 1463 | } |
| 1464 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1465 | /* check for source LL option and process */ |
| 1466 | o0 = (void *) (h0 + 1); |
| 1467 | o0 = ((options_len0 == 8 |
| 1468 | && o0->header.type == option_type |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1469 | && o0->header.n_data_u64s == 1) ? o0 : 0); |
| 1470 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1471 | /* if src address unspecified IGNORE any options */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1472 | if (PREDICT_TRUE (error0 == ICMP6_ERROR_NONE && o0 != 0 && |
| 1473 | !is_unspecified && !is_link_local)) |
| 1474 | { |
| 1475 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 1476 | if (nm->limit_neighbor_cache_size && |
| 1477 | pool_elts (nm->neighbor_pool) >= |
| 1478 | nm->limit_neighbor_cache_size) |
| 1479 | unset_random_neighbor_entry (); |
| 1480 | |
| 1481 | vnet_set_ip6_ethernet_neighbor (vm, sw_if_index0, |
| 1482 | &ip0->src_address, |
| 1483 | o0->ethernet_address, |
| 1484 | sizeof (o0->ethernet_address), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 1485 | 0, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1486 | } |
| 1487 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1488 | /* default is to drop */ |
| 1489 | next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1490 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1491 | if (error0 == ICMP6_ERROR_NONE) |
| 1492 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1493 | vnet_sw_interface_t *sw_if0; |
| 1494 | ethernet_interface_t *eth_if0; |
| 1495 | u32 adj_index0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1496 | |
| 1497 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0); |
| 1498 | ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1499 | eth_if0 = |
| 1500 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1501 | |
| 1502 | /* only support ethernet interface type for now */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1503 | error0 = |
| 1504 | (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF |
| 1505 | : error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1506 | |
| 1507 | if (error0 == ICMP6_ERROR_NONE) |
| 1508 | { |
| 1509 | u32 ri; |
| 1510 | |
| 1511 | /* adjust the sizeof the buffer to just include the ipv6 header */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1512 | p0->current_length -= |
| 1513 | (options_len0 + |
| 1514 | sizeof (icmp6_neighbor_discovery_header_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1515 | |
| 1516 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1517 | vec_validate_init_empty |
| 1518 | (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1519 | |
| 1520 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0]; |
| 1521 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1522 | if (ri != ~0) |
| 1523 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 1524 | |
| 1525 | error0 = |
| 1526 | ((!radv_info) ? |
| 1527 | ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG : |
| 1528 | error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1529 | |
| 1530 | if (error0 == ICMP6_ERROR_NONE) |
| 1531 | { |
| 1532 | f64 now = vlib_time_now (vm); |
| 1533 | |
| 1534 | /* for solicited adverts - need to rate limit */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1535 | if (is_solicitation) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1536 | { |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 1537 | if (0 != radv_info->last_radv_time && |
| 1538 | (now - radv_info->last_radv_time) < |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1539 | MIN_DELAY_BETWEEN_RAS) |
| 1540 | is_dropped = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1541 | else |
| 1542 | radv_info->last_radv_time = now; |
| 1543 | } |
| 1544 | |
| 1545 | /* send now */ |
| 1546 | icmp6_router_advertisement_header_t rh; |
| 1547 | |
| 1548 | rh.icmp.type = ICMP6_router_advertisement; |
| 1549 | rh.icmp.code = 0; |
| 1550 | rh.icmp.checksum = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1551 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1552 | rh.current_hop_limit = radv_info->curr_hop_limit; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1553 | rh.router_lifetime_in_sec = |
| 1554 | clib_host_to_net_u16 |
| 1555 | (radv_info->adv_router_lifetime_in_sec); |
| 1556 | rh. |
| 1557 | time_in_msec_between_retransmitted_neighbor_solicitations |
| 1558 | = |
| 1559 | clib_host_to_net_u32 (radv_info-> |
| 1560 | adv_time_in_msec_between_retransmitted_neighbor_solicitations); |
| 1561 | rh.neighbor_reachable_time_in_msec = |
| 1562 | clib_host_to_net_u32 (radv_info-> |
| 1563 | adv_neighbor_reachable_time_in_msec); |
| 1564 | |
| 1565 | rh.flags = |
| 1566 | (radv_info->adv_managed_flag) ? |
| 1567 | ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP : |
| 1568 | 0; |
| 1569 | rh.flags |= |
| 1570 | ((radv_info->adv_other_flag) ? |
| 1571 | ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP : |
| 1572 | 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1573 | |
| 1574 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1575 | u16 payload_length = |
| 1576 | sizeof (icmp6_router_advertisement_header_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1577 | |
| 1578 | vlib_buffer_add_data (vm, |
Damjan Marion | 072401e | 2017-07-13 18:53:27 +0200 | [diff] [blame] | 1579 | vlib_buffer_get_free_list_index |
| 1580 | (p0), bi0, (void *) &rh, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1581 | sizeof |
| 1582 | (icmp6_router_advertisement_header_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1583 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1584 | if (radv_info->adv_link_layer_address) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1585 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1586 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t |
| 1587 | h; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1588 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1589 | h.header.type = |
| 1590 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1591 | h.header.n_data_u64s = 1; |
| 1592 | |
| 1593 | /* copy ll address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1594 | clib_memcpy (&h.ethernet_address[0], |
| 1595 | eth_if0->address, 6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1596 | |
| 1597 | vlib_buffer_add_data (vm, |
Damjan Marion | 072401e | 2017-07-13 18:53:27 +0200 | [diff] [blame] | 1598 | vlib_buffer_get_free_list_index |
| 1599 | (p0), bi0, (void *) &h, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1600 | sizeof |
| 1601 | (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1602 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1603 | payload_length += |
| 1604 | sizeof |
| 1605 | (icmp6_neighbor_discovery_ethernet_link_layer_address_option_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1606 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1607 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1608 | /* add MTU option */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1609 | if (radv_info->adv_link_mtu) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1610 | { |
| 1611 | icmp6_neighbor_discovery_mtu_option_t h; |
| 1612 | |
| 1613 | h.unused = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1614 | h.mtu = |
| 1615 | clib_host_to_net_u32 (radv_info->adv_link_mtu); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1616 | h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu; |
| 1617 | h.header.n_data_u64s = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1618 | |
| 1619 | payload_length += |
| 1620 | sizeof (icmp6_neighbor_discovery_mtu_option_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1621 | |
| 1622 | vlib_buffer_add_data (vm, |
Damjan Marion | 072401e | 2017-07-13 18:53:27 +0200 | [diff] [blame] | 1623 | vlib_buffer_get_free_list_index |
| 1624 | (p0), bi0, (void *) &h, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1625 | sizeof |
| 1626 | (icmp6_neighbor_discovery_mtu_option_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1627 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1628 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1629 | /* add advertised prefix options */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1630 | ip6_radv_prefix_t *pr_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1631 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1632 | /* *INDENT-OFF* */ |
| 1633 | pool_foreach (pr_info, radv_info->adv_prefixes_pool, |
| 1634 | ({ |
| 1635 | if(pr_info->enabled && |
| 1636 | (!pr_info->decrement_lifetime_flag |
| 1637 | || (pr_info->pref_lifetime_expires >0))) |
| 1638 | { |
| 1639 | /* advertise this prefix */ |
| 1640 | icmp6_neighbor_discovery_prefix_information_option_t h; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1641 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1642 | h.header.type = ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information; |
| 1643 | h.header.n_data_u64s = (sizeof(icmp6_neighbor_discovery_prefix_information_option_t) >> 3); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1644 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1645 | h.dst_address_length = pr_info->prefix_len; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1646 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1647 | h.flags = (pr_info->adv_on_link_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK : 0; |
| 1648 | h.flags |= (pr_info->adv_autonomous_flag) ? ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO : 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1649 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1650 | if(radv_info->cease_radv && pr_info->deprecated_prefix_flag) |
| 1651 | { |
| 1652 | h.valid_time = clib_host_to_net_u32(MIN_ADV_VALID_LIFETIME); |
| 1653 | h.preferred_time = 0; |
| 1654 | } |
| 1655 | else |
| 1656 | { |
| 1657 | if(pr_info->decrement_lifetime_flag) |
| 1658 | { |
| 1659 | pr_info->adv_valid_lifetime_in_secs = ((pr_info->valid_lifetime_expires > now)) ? |
| 1660 | (pr_info->valid_lifetime_expires - now) : 0; |
| 1661 | |
| 1662 | pr_info->adv_pref_lifetime_in_secs = ((pr_info->pref_lifetime_expires > now)) ? |
| 1663 | (pr_info->pref_lifetime_expires - now) : 0; |
| 1664 | } |
| 1665 | |
| 1666 | h.valid_time = clib_host_to_net_u32(pr_info->adv_valid_lifetime_in_secs); |
| 1667 | h.preferred_time = clib_host_to_net_u32(pr_info->adv_pref_lifetime_in_secs) ; |
| 1668 | } |
| 1669 | h.unused = 0; |
| 1670 | |
| 1671 | clib_memcpy(&h.dst_address, &pr_info->prefix, sizeof(ip6_address_t)); |
| 1672 | |
| 1673 | payload_length += sizeof( icmp6_neighbor_discovery_prefix_information_option_t); |
| 1674 | |
| 1675 | vlib_buffer_add_data (vm, |
Damjan Marion | 072401e | 2017-07-13 18:53:27 +0200 | [diff] [blame] | 1676 | vlib_buffer_get_free_list_index (p0), |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1677 | bi0, |
| 1678 | (void *)&h, sizeof(icmp6_neighbor_discovery_prefix_information_option_t)); |
| 1679 | |
| 1680 | } |
| 1681 | })); |
| 1682 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1683 | |
| 1684 | /* add additional options before here */ |
| 1685 | |
| 1686 | /* finish building the router advertisement... */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1687 | if (!is_unspecified && radv_info->send_unicast) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1688 | { |
| 1689 | ip0->dst_address = ip0->src_address; |
| 1690 | } |
| 1691 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1692 | { |
| 1693 | /* target address is all-nodes mcast addr */ |
| 1694 | ip6_set_reserved_multicast_address |
| 1695 | (&ip0->dst_address, |
| 1696 | IP6_MULTICAST_SCOPE_link_local, |
| 1697 | IP6_MULTICAST_GROUP_ID_all_hosts); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1698 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1699 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1700 | /* source address MUST be the link-local address */ |
| 1701 | ip0->src_address = radv_info->link_local_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1702 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1703 | ip0->hop_limit = 255; |
| 1704 | ip0->payload_length = |
| 1705 | clib_host_to_net_u16 (payload_length); |
| 1706 | |
| 1707 | icmp6_router_advertisement_header_t *rh0 = |
| 1708 | (icmp6_router_advertisement_header_t *) (ip0 + 1); |
| 1709 | rh0->icmp.checksum = |
| 1710 | ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip0, |
| 1711 | &bogus_length); |
| 1712 | ASSERT (bogus_length == 0); |
| 1713 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1714 | /* setup output if and adjacency */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1715 | vnet_buffer (p0)->sw_if_index[VLIB_RX] = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1716 | vnet_main.local_interface_sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1717 | |
| 1718 | if (is_solicitation) |
| 1719 | { |
| 1720 | ethernet_header_t *eth0; |
| 1721 | /* Reuse current MAC header, copy SMAC to DMAC and |
| 1722 | * interface MAC to SMAC */ |
| 1723 | vlib_buffer_reset (p0); |
| 1724 | eth0 = vlib_buffer_get_current (p0); |
| 1725 | clib_memcpy (eth0->dst_address, eth0->src_address, |
| 1726 | 6); |
| 1727 | clib_memcpy (eth0->src_address, eth_if0->address, |
| 1728 | 6); |
| 1729 | next0 = |
| 1730 | is_dropped ? next0 : |
| 1731 | ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX; |
| 1732 | vnet_buffer (p0)->sw_if_index[VLIB_TX] = |
| 1733 | sw_if_index0; |
| 1734 | } |
| 1735 | else |
| 1736 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1737 | adj_index0 = radv_info->mcast_adj_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1738 | if (adj_index0 == 0) |
| 1739 | error0 = ICMP6_ERROR_DST_LOOKUP_MISS; |
| 1740 | else |
| 1741 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1742 | next0 = |
| 1743 | is_dropped ? next0 : |
| 1744 | ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW; |
| 1745 | vnet_buffer (p0)->ip.adj_index[VLIB_TX] = |
| 1746 | adj_index0; |
| 1747 | } |
| 1748 | } |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1749 | p0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1750 | |
| 1751 | radv_info->n_solicitations_dropped += is_dropped; |
| 1752 | radv_info->n_solicitations_rcvd += is_solicitation; |
| 1753 | |
| 1754 | if ((error0 == ICMP6_ERROR_NONE) && !is_dropped) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1755 | { |
| 1756 | radv_info->n_advertisements_sent++; |
| 1757 | n_advertisements_sent++; |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | p0->error = error_node->errors[error0]; |
| 1764 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1765 | if (error0 != ICMP6_ERROR_NONE) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1766 | vlib_error_count (vm, error_node->node_index, error0, 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1767 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1768 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 1769 | to_next, n_left_to_next, |
| 1770 | bi0, next0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1771 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1772 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1773 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1774 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1775 | } |
| 1776 | |
| 1777 | /* Account for router advertisements sent. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1778 | vlib_error_count (vm, error_node->node_index, |
| 1779 | ICMP6_ERROR_ROUTER_ADVERTISEMENTS_TX, |
| 1780 | n_advertisements_sent); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1781 | |
| 1782 | return frame->n_vectors; |
| 1783 | } |
| 1784 | |
| 1785 | /* validate advertised info for consistancy (see RFC-4861 section 6.2.7) - log any inconsistencies, packet will always be dropped */ |
| 1786 | static_always_inline uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1787 | icmp6_router_advertisement (vlib_main_t * vm, |
| 1788 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1789 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1790 | vnet_main_t *vnm = vnet_get_main (); |
| 1791 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1792 | uword n_packets = frame->n_vectors; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1793 | u32 *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1794 | u32 n_left_from, n_left_to_next, next_index; |
| 1795 | u32 n_advertisements_rcvd = 0; |
| 1796 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1797 | vlib_node_runtime_t *error_node = |
| 1798 | vlib_node_get_runtime (vm, ip6_icmp_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1799 | |
| 1800 | from = vlib_frame_vector_args (frame); |
| 1801 | n_left_from = n_packets; |
| 1802 | next_index = node->cached_next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1803 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1804 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 1805 | vlib_trace_frame_buffers_only (vm, node, from, frame->n_vectors, |
| 1806 | /* stride */ 1, |
| 1807 | sizeof (icmp6_input_trace_t)); |
| 1808 | |
| 1809 | while (n_left_from > 0) |
| 1810 | { |
| 1811 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1812 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1813 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1814 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1815 | vlib_buffer_t *p0; |
| 1816 | ip6_header_t *ip0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1817 | ip6_radv_t *radv_info = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1818 | icmp6_router_advertisement_header_t *h0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1819 | u32 bi0, options_len0, sw_if_index0, next0, error0; |
| 1820 | |
| 1821 | bi0 = to_next[0] = from[0]; |
| 1822 | |
| 1823 | from += 1; |
| 1824 | to_next += 1; |
| 1825 | n_left_from -= 1; |
| 1826 | n_left_to_next -= 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1827 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1828 | p0 = vlib_get_buffer (vm, bi0); |
| 1829 | ip0 = vlib_buffer_get_current (p0); |
| 1830 | h0 = ip6_next_header (ip0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1831 | options_len0 = |
| 1832 | clib_net_to_host_u16 (ip0->payload_length) - sizeof (h0[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1833 | |
| 1834 | error0 = ICMP6_ERROR_NONE; |
| 1835 | sw_if_index0 = vnet_buffer (p0)->sw_if_index[VLIB_RX]; |
| 1836 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1837 | /* Check that source address is link-local */ |
| 1838 | error0 = (!ip6_address_is_link_local_unicast (&ip0->src_address)) ? |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1839 | ICMP6_ERROR_ROUTER_ADVERTISEMENT_SOURCE_NOT_LINK_LOCAL : error0; |
| 1840 | |
| 1841 | /* default is to drop */ |
| 1842 | next0 = ICMP6_ROUTER_SOLICITATION_NEXT_DROP; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1843 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1844 | n_advertisements_rcvd++; |
| 1845 | |
| 1846 | if (error0 == ICMP6_ERROR_NONE) |
| 1847 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1848 | vnet_sw_interface_t *sw_if0; |
| 1849 | ethernet_interface_t *eth_if0; |
| 1850 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1851 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index0); |
| 1852 | ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1853 | eth_if0 = |
| 1854 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1855 | |
| 1856 | /* only support ethernet interface type for now */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1857 | error0 = |
| 1858 | (!eth_if0) ? ICMP6_ERROR_ROUTER_SOLICITATION_UNSUPPORTED_INTF |
| 1859 | : error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1860 | |
| 1861 | if (error0 == ICMP6_ERROR_NONE) |
| 1862 | { |
| 1863 | u32 ri; |
| 1864 | |
| 1865 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1866 | vec_validate_init_empty |
| 1867 | (nm->if_radv_pool_index_by_sw_if_index, sw_if_index0, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1868 | |
| 1869 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index0]; |
| 1870 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1871 | if (ri != ~0) |
| 1872 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 1873 | |
| 1874 | error0 = |
| 1875 | ((!radv_info) ? |
| 1876 | ICMP6_ERROR_ROUTER_SOLICITATION_RADV_NOT_CONFIG : |
| 1877 | error0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1878 | |
| 1879 | if (error0 == ICMP6_ERROR_NONE) |
| 1880 | { |
| 1881 | /* validate advertised information */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1882 | if ((h0->current_hop_limit && radv_info->curr_hop_limit) |
| 1883 | && (h0->current_hop_limit != |
| 1884 | radv_info->curr_hop_limit)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1885 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1886 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 1887 | "our AdvCurHopLimit on %U doesn't agree with %U", |
| 1888 | format_vnet_sw_if_index_name, |
| 1889 | vnm, sw_if_index0, |
| 1890 | format_ip6_address, |
| 1891 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1894 | if ((h0->flags & |
| 1895 | ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP) |
| 1896 | != radv_info->adv_managed_flag) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1897 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1898 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 1899 | "our AdvManagedFlag on %U doesn't agree with %U", |
| 1900 | format_vnet_sw_if_index_name, |
| 1901 | vnm, sw_if_index0, |
| 1902 | format_ip6_address, |
| 1903 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1906 | if ((h0->flags & |
| 1907 | ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP) |
| 1908 | != radv_info->adv_other_flag) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1909 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1910 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 1911 | "our AdvOtherConfigFlag on %U doesn't agree with %U", |
| 1912 | format_vnet_sw_if_index_name, |
| 1913 | vnm, sw_if_index0, |
| 1914 | format_ip6_address, |
| 1915 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1918 | if ((h0-> |
| 1919 | time_in_msec_between_retransmitted_neighbor_solicitations |
| 1920 | && radv_info-> |
| 1921 | adv_time_in_msec_between_retransmitted_neighbor_solicitations) |
| 1922 | && (h0-> |
| 1923 | time_in_msec_between_retransmitted_neighbor_solicitations |
| 1924 | != |
| 1925 | clib_host_to_net_u32 (radv_info-> |
| 1926 | adv_time_in_msec_between_retransmitted_neighbor_solicitations))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1927 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1928 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 1929 | "our AdvRetransTimer on %U doesn't agree with %U", |
| 1930 | format_vnet_sw_if_index_name, |
| 1931 | vnm, sw_if_index0, |
| 1932 | format_ip6_address, |
| 1933 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1936 | if ((h0->neighbor_reachable_time_in_msec && |
| 1937 | radv_info->adv_neighbor_reachable_time_in_msec) && |
| 1938 | (h0->neighbor_reachable_time_in_msec != |
| 1939 | clib_host_to_net_u32 |
| 1940 | (radv_info->adv_neighbor_reachable_time_in_msec))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1941 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1942 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 1943 | "our AdvReachableTime on %U doesn't agree with %U", |
| 1944 | format_vnet_sw_if_index_name, |
| 1945 | vnm, sw_if_index0, |
| 1946 | format_ip6_address, |
| 1947 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | /* check for MTU or prefix options or .. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1951 | u8 *opt_hdr = (u8 *) (h0 + 1); |
| 1952 | while (options_len0 > 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1953 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1954 | icmp6_neighbor_discovery_option_header_t *o0 = |
| 1955 | (icmp6_neighbor_discovery_option_header_t *) |
| 1956 | opt_hdr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1957 | int opt_len = o0->n_data_u64s << 3; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1958 | icmp6_neighbor_discovery_option_type_t option_type = |
| 1959 | o0->type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1960 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1961 | if (options_len0 < 2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1962 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1963 | ip6_neighbor_syslog (vm, LOG_ERR, |
| 1964 | "malformed RA packet on %U from %U", |
| 1965 | format_vnet_sw_if_index_name, |
| 1966 | vnm, sw_if_index0, |
| 1967 | format_ip6_address, |
| 1968 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1969 | break; |
| 1970 | } |
| 1971 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1972 | if (opt_len == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1973 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1974 | ip6_neighbor_syslog (vm, LOG_ERR, |
| 1975 | " zero length option in RA on %U from %U", |
| 1976 | format_vnet_sw_if_index_name, |
| 1977 | vnm, sw_if_index0, |
| 1978 | format_ip6_address, |
| 1979 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1980 | break; |
| 1981 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1982 | else if (opt_len > options_len0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1983 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1984 | ip6_neighbor_syslog (vm, LOG_ERR, |
| 1985 | "option length in RA packet greater than total length on %U from %U", |
| 1986 | format_vnet_sw_if_index_name, |
| 1987 | vnm, sw_if_index0, |
| 1988 | format_ip6_address, |
| 1989 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1990 | break; |
| 1991 | } |
| 1992 | |
| 1993 | options_len0 -= opt_len; |
| 1994 | opt_hdr += opt_len; |
| 1995 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1996 | switch (option_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1997 | { |
| 1998 | case ICMP6_NEIGHBOR_DISCOVERY_OPTION_mtu: |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1999 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2000 | icmp6_neighbor_discovery_mtu_option_t *h = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2001 | (icmp6_neighbor_discovery_mtu_option_t |
| 2002 | *) (o0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2003 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2004 | if (opt_len < sizeof (*h)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2005 | break; |
| 2006 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2007 | if ((h->mtu && radv_info->adv_link_mtu) && |
| 2008 | (h->mtu != |
| 2009 | clib_host_to_net_u32 |
| 2010 | (radv_info->adv_link_mtu))) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2011 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2012 | ip6_neighbor_syslog (vm, LOG_WARNING, |
| 2013 | "our AdvLinkMTU on %U doesn't agree with %U", |
| 2014 | format_vnet_sw_if_index_name, |
| 2015 | vnm, sw_if_index0, |
| 2016 | format_ip6_address, |
| 2017 | &ip0->src_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2018 | } |
| 2019 | } |
| 2020 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2021 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2022 | case ICMP6_NEIGHBOR_DISCOVERY_OPTION_prefix_information: |
| 2023 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2024 | icmp6_neighbor_discovery_prefix_information_option_t |
| 2025 | * h = |
| 2026 | (icmp6_neighbor_discovery_prefix_information_option_t |
| 2027 | *) (o0); |
| 2028 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2029 | /* validate advertised prefix options */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2030 | ip6_radv_prefix_t *pr_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2031 | u32 preferred, valid; |
| 2032 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2033 | if (opt_len < sizeof (*h)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2034 | break; |
| 2035 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2036 | preferred = |
| 2037 | clib_net_to_host_u32 (h->preferred_time); |
| 2038 | valid = clib_net_to_host_u32 (h->valid_time); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2039 | |
| 2040 | /* look for matching prefix - if we our advertising it, it better be consistant */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2041 | /* *INDENT-OFF* */ |
| 2042 | pool_foreach (pr_info, radv_info->adv_prefixes_pool, |
| 2043 | ({ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2044 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2045 | ip6_address_t mask; |
| 2046 | ip6_address_mask_from_width(&mask, pr_info->prefix_len); |
| 2047 | |
| 2048 | if(pr_info->enabled && |
| 2049 | (pr_info->prefix_len == h->dst_address_length) && |
| 2050 | ip6_address_is_equal_masked (&pr_info->prefix, &h->dst_address, &mask)) |
| 2051 | { |
| 2052 | /* found it */ |
| 2053 | if(!pr_info->decrement_lifetime_flag && |
| 2054 | valid != pr_info->adv_valid_lifetime_in_secs) |
| 2055 | { |
| 2056 | ip6_neighbor_syslog(vm, LOG_WARNING, |
| 2057 | "our ADV validlifetime on %U for %U does not agree with %U", |
| 2058 | format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix, |
| 2059 | format_ip6_address, &h->dst_address); |
| 2060 | } |
| 2061 | if(!pr_info->decrement_lifetime_flag && |
| 2062 | preferred != pr_info->adv_pref_lifetime_in_secs) |
| 2063 | { |
| 2064 | ip6_neighbor_syslog(vm, LOG_WARNING, |
| 2065 | "our ADV preferredlifetime on %U for %U does not agree with %U", |
| 2066 | format_vnet_sw_if_index_name, vnm, sw_if_index0,format_ip6_address, &pr_info->prefix, |
| 2067 | format_ip6_address, &h->dst_address); |
| 2068 | } |
| 2069 | } |
| 2070 | break; |
| 2071 | })); |
| 2072 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2073 | break; |
| 2074 | } |
| 2075 | default: |
| 2076 | /* skip this one */ |
| 2077 | break; |
| 2078 | } |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | p0->error = error_node->errors[error0]; |
| 2085 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2086 | if (error0 != ICMP6_ERROR_NONE) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2087 | vlib_error_count (vm, error_node->node_index, error0, 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2088 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2089 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 2090 | to_next, n_left_to_next, |
| 2091 | bi0, next0); |
| 2092 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2093 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2094 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 2095 | } |
| 2096 | |
| 2097 | /* Account for router advertisements sent. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2098 | vlib_error_count (vm, error_node->node_index, |
| 2099 | ICMP6_ERROR_ROUTER_ADVERTISEMENTS_RX, |
| 2100 | n_advertisements_rcvd); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2101 | |
| 2102 | return frame->n_vectors; |
| 2103 | } |
| 2104 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2105 | /** |
| 2106 | * @brief Add a multicast Address to the advertised MLD set |
| 2107 | */ |
| 2108 | static void |
| 2109 | ip6_neighbor_add_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr) |
| 2110 | { |
| 2111 | ip6_mldp_group_t *mcast_group_info; |
| 2112 | uword *p; |
| 2113 | |
| 2114 | /* lookup mldp info for this interface */ |
Neale Ranns | e0a3544 | 2018-02-25 10:39:02 -0800 | [diff] [blame] | 2115 | p = mhash_get (&radv_info->address_to_mldp_index, addr); |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2116 | mcast_group_info = |
| 2117 | p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0; |
| 2118 | |
| 2119 | /* add address */ |
| 2120 | if (!mcast_group_info) |
| 2121 | { |
| 2122 | /* add */ |
| 2123 | u32 mi; |
| 2124 | pool_get (radv_info->mldp_group_pool, mcast_group_info); |
| 2125 | |
| 2126 | mi = mcast_group_info - radv_info->mldp_group_pool; |
Neale Ranns | e0a3544 | 2018-02-25 10:39:02 -0800 | [diff] [blame] | 2127 | mhash_set (&radv_info->address_to_mldp_index, addr, mi, /* old_value */ |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2128 | 0); |
| 2129 | |
| 2130 | mcast_group_info->type = 4; |
| 2131 | mcast_group_info->mcast_source_address_pool = 0; |
| 2132 | mcast_group_info->num_sources = 0; |
Neale Ranns | e0a3544 | 2018-02-25 10:39:02 -0800 | [diff] [blame] | 2133 | clib_memcpy (&mcast_group_info->mcast_address, addr, |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2134 | sizeof (ip6_address_t)); |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | /** |
| 2139 | * @brief Delete a multicast Address from the advertised MLD set |
| 2140 | */ |
| 2141 | static void |
| 2142 | ip6_neighbor_del_mld_prefix (ip6_radv_t * radv_info, ip6_address_t * addr) |
| 2143 | { |
| 2144 | ip6_mldp_group_t *mcast_group_info; |
| 2145 | uword *p; |
| 2146 | |
| 2147 | p = mhash_get (&radv_info->address_to_mldp_index, &addr); |
| 2148 | mcast_group_info = |
| 2149 | p ? pool_elt_at_index (radv_info->mldp_group_pool, p[0]) : 0; |
| 2150 | |
| 2151 | if (mcast_group_info) |
| 2152 | { |
| 2153 | mhash_unset (&radv_info->address_to_mldp_index, &addr, |
| 2154 | /* old_value */ 0); |
| 2155 | pool_put (radv_info->mldp_group_pool, mcast_group_info); |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | /** |
| 2160 | * @brief Add a multicast Address to the advertised MLD set |
| 2161 | */ |
| 2162 | static void |
| 2163 | ip6_neighbor_add_mld_grp (ip6_radv_t * a, |
| 2164 | ip6_multicast_address_scope_t scope, |
| 2165 | ip6_multicast_link_local_group_id_t group) |
| 2166 | { |
| 2167 | ip6_address_t addr; |
| 2168 | |
| 2169 | ip6_set_reserved_multicast_address (&addr, scope, group); |
| 2170 | |
| 2171 | ip6_neighbor_add_mld_prefix (a, &addr); |
| 2172 | } |
| 2173 | |
| 2174 | /** |
| 2175 | * @brief create and initialize router advertisement parameters with default |
| 2176 | * values for this intfc |
| 2177 | */ |
Pavel Kotucek | 9f5a2b6 | 2017-06-14 13:56:55 +0200 | [diff] [blame] | 2178 | u32 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2179 | ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2180 | u32 sw_if_index, u32 is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2181 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2182 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2183 | ip6_radv_t *a = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 2184 | u32 ri = ~0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2185 | vnet_sw_interface_t *sw_if0; |
| 2186 | ethernet_interface_t *eth_if0 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2187 | |
| 2188 | /* lookup radv container - ethernet interfaces only */ |
| 2189 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2190 | if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2191 | eth_if0 = ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
| 2192 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2193 | if (!eth_if0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2194 | return ri; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2195 | |
| 2196 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 2197 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2198 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 2199 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2200 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2201 | { |
| 2202 | a = pool_elt_at_index (nm->if_radv_pool, ri); |
| 2203 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2204 | if (!is_add) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2205 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2206 | ip6_radv_prefix_t *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2207 | ip6_mldp_group_t *m; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2208 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2209 | /* release the lock on the interface's mcast adj */ |
| 2210 | adj_unlock (a->mcast_adj_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2211 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2212 | /* clean up prefix and MDP pools */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2213 | /* *INDENT-OFF* */ |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2214 | pool_flush(p, a->adv_prefixes_pool, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2215 | ({ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2216 | mhash_unset (&a->address_to_prefix_index, &p->prefix, 0); |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2217 | })); |
| 2218 | pool_flush (m, a->mldp_group_pool, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2219 | ({ |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2220 | mhash_unset (&a->address_to_mldp_index, &m->mcast_address, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2221 | })); |
| 2222 | /* *INDENT-ON* */ |
| 2223 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2224 | pool_free (a->mldp_group_pool); |
| 2225 | pool_free (a->adv_prefixes_pool); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2226 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2227 | mhash_free (&a->address_to_prefix_index); |
| 2228 | mhash_free (&a->address_to_mldp_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2229 | |
| 2230 | pool_put (nm->if_radv_pool, a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2231 | nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ~0; |
| 2232 | ri = ~0; |
| 2233 | } |
| 2234 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2235 | else |
| 2236 | { |
| 2237 | if (is_add) |
| 2238 | { |
| 2239 | vnet_hw_interface_t *hw_if0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2240 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2241 | hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index); |
| 2242 | |
| 2243 | pool_get (nm->if_radv_pool, a); |
| 2244 | |
| 2245 | ri = a - nm->if_radv_pool; |
| 2246 | nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ri; |
| 2247 | |
| 2248 | /* initialize default values (most of which are zero) */ |
| 2249 | memset (a, 0, sizeof (a[0])); |
| 2250 | |
| 2251 | a->sw_if_index = sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2252 | a->max_radv_interval = DEF_MAX_RADV_INTERVAL; |
| 2253 | a->min_radv_interval = DEF_MIN_RADV_INTERVAL; |
| 2254 | a->curr_hop_limit = DEF_CURR_HOP_LIMIT; |
| 2255 | a->adv_router_lifetime_in_sec = DEF_DEF_RTR_LIFETIME; |
| 2256 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2257 | /* send ll address source address option */ |
| 2258 | a->adv_link_layer_address = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2259 | |
| 2260 | a->min_delay_between_radv = MIN_DELAY_BETWEEN_RAS; |
| 2261 | a->max_delay_between_radv = MAX_DELAY_BETWEEN_RAS; |
| 2262 | a->max_rtr_default_lifetime = MAX_DEF_RTR_LIFETIME; |
| 2263 | a->seed = (u32) clib_cpu_time_now (); |
| 2264 | (void) random_u32 (&a->seed); |
| 2265 | a->randomizer = clib_cpu_time_now (); |
| 2266 | (void) random_u64 (&a->randomizer); |
| 2267 | |
| 2268 | a->initial_adverts_count = MAX_INITIAL_RTR_ADVERTISEMENTS; |
| 2269 | a->initial_adverts_sent = a->initial_adverts_count - 1; |
| 2270 | a->initial_adverts_interval = MAX_INITIAL_RTR_ADVERT_INTERVAL; |
| 2271 | |
| 2272 | /* deafult is to send */ |
| 2273 | a->send_radv = 1; |
| 2274 | |
| 2275 | /* fill in radv_info for this interface that will be needed later */ |
| 2276 | a->adv_link_mtu = hw_if0->max_l3_packet_bytes[VLIB_RX]; |
| 2277 | |
| 2278 | clib_memcpy (a->link_layer_address, eth_if0->address, 6); |
| 2279 | |
| 2280 | /* fill in default link-local address (this may be overridden) */ |
| 2281 | ip6_link_local_address_from_ethernet_address |
| 2282 | (&a->link_local_address, eth_if0->address); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2283 | |
| 2284 | mhash_init (&a->address_to_prefix_index, sizeof (uword), |
| 2285 | sizeof (ip6_address_t)); |
| 2286 | mhash_init (&a->address_to_mldp_index, sizeof (uword), |
| 2287 | sizeof (ip6_address_t)); |
| 2288 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2289 | a->mcast_adj_index = adj_mcast_add_or_lock (FIB_PROTOCOL_IP6, |
| 2290 | VNET_LINK_IP6, |
| 2291 | sw_if_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2292 | |
| 2293 | /* add multicast groups we will always be reporting */ |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 2294 | ip6_neighbor_add_mld_grp (a, |
| 2295 | IP6_MULTICAST_SCOPE_link_local, |
| 2296 | IP6_MULTICAST_GROUP_ID_all_hosts); |
| 2297 | ip6_neighbor_add_mld_grp (a, |
| 2298 | IP6_MULTICAST_SCOPE_link_local, |
| 2299 | IP6_MULTICAST_GROUP_ID_all_routers); |
| 2300 | ip6_neighbor_add_mld_grp (a, |
| 2301 | IP6_MULTICAST_SCOPE_link_local, |
| 2302 | IP6_MULTICAST_GROUP_ID_mldv2_routers); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | return ri; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | /* send an mldpv2 report */ |
| 2309 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2310 | ip6_neighbor_send_mldpv2_report (u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2311 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2312 | vnet_main_t *vnm = vnet_get_main (); |
| 2313 | vlib_main_t *vm = vnm->vlib_main; |
| 2314 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2315 | vnet_sw_interface_t *sw_if0; |
| 2316 | ethernet_interface_t *eth_if0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2317 | u32 ri; |
| 2318 | int bogus_length; |
| 2319 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2320 | ip6_radv_t *radv_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2321 | u16 payload_length; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2322 | vlib_buffer_t *b0; |
| 2323 | ip6_header_t *ip0; |
| 2324 | u32 *to_next; |
| 2325 | vlib_frame_t *f; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2326 | u32 bo0; |
| 2327 | u32 n_to_alloc = 1; |
| 2328 | u32 n_allocated; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2329 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2330 | icmp6_multicast_listener_report_header_t *rh0; |
| 2331 | icmp6_multicast_listener_report_packet_t *rp0; |
| 2332 | |
| 2333 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index); |
| 2334 | ASSERT (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
| 2335 | eth_if0 = ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
| 2336 | |
| 2337 | if (!eth_if0 || !vnet_sw_interface_is_admin_up (vnm, sw_if_index)) |
| 2338 | return; |
| 2339 | |
| 2340 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2341 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 2342 | ~0); |
| 2343 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2344 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2345 | |
| 2346 | if (ri == ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2347 | return; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2348 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2349 | /* send report now - build a mldpv2 report packet */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2350 | n_allocated = vlib_buffer_alloc_from_free_list (vm, |
| 2351 | &bo0, |
| 2352 | n_to_alloc, |
| 2353 | VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); |
| 2354 | if (PREDICT_FALSE (n_allocated == 0)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2355 | { |
| 2356 | clib_warning ("buffer allocation failure"); |
| 2357 | return; |
| 2358 | } |
| 2359 | |
| 2360 | b0 = vlib_get_buffer (vm, bo0); |
| 2361 | |
| 2362 | /* adjust the sizeof the buffer to just include the ipv6 header */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2363 | b0->current_length = sizeof (icmp6_multicast_listener_report_packet_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2364 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2365 | payload_length = sizeof (icmp6_multicast_listener_report_header_t); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2366 | |
| 2367 | b0->error = ICMP6_ERROR_NONE; |
| 2368 | |
| 2369 | rp0 = vlib_buffer_get_current (b0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2370 | ip0 = (ip6_header_t *) & rp0->ip; |
| 2371 | rh0 = (icmp6_multicast_listener_report_header_t *) & rp0->report_hdr; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2372 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2373 | memset (rp0, 0x0, sizeof (icmp6_multicast_listener_report_packet_t)); |
| 2374 | |
| 2375 | ip0->ip_version_traffic_class_and_flow_label = |
| 2376 | clib_host_to_net_u32 (0x6 << 28); |
| 2377 | |
| 2378 | ip0->protocol = IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2379 | /* for DEBUG - vnet driver won't seem to emit router alerts */ |
| 2380 | /* ip0->protocol = IP_PROTOCOL_ICMP6; */ |
| 2381 | ip0->hop_limit = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2382 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2383 | rh0->icmp.type = ICMP6_multicast_listener_report_v2; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2384 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2385 | /* source address MUST be the link-local address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2386 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 2387 | ip0->src_address = radv_info->link_local_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2388 | |
| 2389 | /* destination is all mldpv2 routers */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2390 | ip6_set_reserved_multicast_address (&ip0->dst_address, |
| 2391 | IP6_MULTICAST_SCOPE_link_local, |
| 2392 | IP6_MULTICAST_GROUP_ID_mldv2_routers); |
| 2393 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2394 | /* add reports here */ |
| 2395 | ip6_mldp_group_t *m; |
| 2396 | int num_addr_records = 0; |
| 2397 | icmp6_multicast_address_record_t rr; |
| 2398 | |
| 2399 | /* fill in the hop-by-hop extension header (router alert) info */ |
| 2400 | rh0->ext_hdr.next_hdr = IP_PROTOCOL_ICMP6; |
| 2401 | rh0->ext_hdr.n_data_u64s = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2402 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2403 | rh0->alert.type = IP6_MLDP_ALERT_TYPE; |
| 2404 | rh0->alert.len = 2; |
| 2405 | rh0->alert.value = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2406 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2407 | rh0->pad.type = 1; |
| 2408 | rh0->pad.len = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2409 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2410 | rh0->icmp.checksum = 0; |
| 2411 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2412 | /* *INDENT-OFF* */ |
| 2413 | pool_foreach (m, radv_info->mldp_group_pool, |
| 2414 | ({ |
| 2415 | rr.type = m->type; |
| 2416 | rr.aux_data_len_u32s = 0; |
| 2417 | rr.num_sources = clib_host_to_net_u16 (m->num_sources); |
| 2418 | clib_memcpy(&rr.mcast_addr, &m->mcast_address, sizeof(ip6_address_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2419 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2420 | num_addr_records++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2421 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2422 | vlib_buffer_add_data |
Damjan Marion | 072401e | 2017-07-13 18:53:27 +0200 | [diff] [blame] | 2423 | (vm, vlib_buffer_get_free_list_index (b0), bo0, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2424 | (void *)&rr, sizeof(icmp6_multicast_address_record_t)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2425 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2426 | payload_length += sizeof( icmp6_multicast_address_record_t); |
| 2427 | })); |
| 2428 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2429 | |
| 2430 | rh0->rsvd = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2431 | rh0->num_addr_records = clib_host_to_net_u16 (num_addr_records); |
| 2432 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2433 | /* update lengths */ |
| 2434 | ip0->payload_length = clib_host_to_net_u16 (payload_length); |
| 2435 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2436 | rh0->icmp.checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, |
| 2437 | &bogus_length); |
| 2438 | ASSERT (bogus_length == 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2439 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2440 | /* |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2441 | * OK to override w/ no regard for actual FIB, because |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 2442 | * ip6-rewrite only looks at the adjacency. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2443 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2444 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2445 | vnet_main.local_interface_sw_if_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2446 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2447 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = radv_info->mcast_adj_index; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 2448 | b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2449 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2450 | vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "ip6-rewrite-mcast"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2451 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2452 | f = vlib_get_frame_to_node (vm, node->index); |
| 2453 | to_next = vlib_frame_vector_args (f); |
| 2454 | to_next[0] = bo0; |
| 2455 | f->n_vectors = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2456 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2457 | vlib_put_frame_to_node (vm, node->index, f); |
| 2458 | return; |
| 2459 | } |
| 2460 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2461 | /* *INDENT-OFF* */ |
| 2462 | VLIB_REGISTER_NODE (ip6_icmp_router_solicitation_node,static) = |
| 2463 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2464 | .function = icmp6_router_solicitation, |
| 2465 | .name = "icmp6-router-solicitation", |
| 2466 | |
| 2467 | .vector_size = sizeof (u32), |
| 2468 | |
| 2469 | .format_trace = format_icmp6_input_trace, |
| 2470 | |
| 2471 | .n_next_nodes = ICMP6_ROUTER_SOLICITATION_N_NEXT, |
| 2472 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 2473 | [ICMP6_ROUTER_SOLICITATION_NEXT_DROP] = "ip6-drop", |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2474 | [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_RW] = "ip6-rewrite-mcast", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2475 | [ICMP6_ROUTER_SOLICITATION_NEXT_REPLY_TX] = "interface-output", |
| 2476 | }, |
| 2477 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2478 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2479 | |
| 2480 | /* send a RA or update the timer info etc.. */ |
| 2481 | static uword |
| 2482 | ip6_neighbor_process_timer_event (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2483 | vlib_node_runtime_t * node, |
| 2484 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2485 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2486 | vnet_main_t *vnm = vnet_get_main (); |
| 2487 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2488 | ip6_radv_t *radv_info; |
| 2489 | vlib_frame_t *f = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2490 | u32 n_this_frame = 0; |
Benoît Ganne | d530445 | 2016-04-08 22:25:05 -0700 | [diff] [blame] | 2491 | u32 n_left_to_next = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2492 | u32 *to_next = 0; |
| 2493 | u32 bo0; |
| 2494 | icmp6_router_solicitation_header_t *h0; |
| 2495 | vlib_buffer_t *b0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2496 | f64 now = vlib_time_now (vm); |
| 2497 | |
| 2498 | /* Interface ip6 radv info list */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2499 | /* *INDENT-OFF* */ |
| 2500 | pool_foreach (radv_info, nm->if_radv_pool, |
| 2501 | ({ |
| 2502 | if( !vnet_sw_interface_is_admin_up (vnm, radv_info->sw_if_index)) |
| 2503 | { |
| 2504 | radv_info->initial_adverts_sent = radv_info->initial_adverts_count-1; |
| 2505 | radv_info->next_multicast_time = now; |
| 2506 | radv_info->last_multicast_time = now; |
| 2507 | radv_info->last_radv_time = 0; |
| 2508 | radv_info->all_routers_mcast = 0; |
| 2509 | continue; |
| 2510 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2511 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2512 | /* Make sure that we've joined the all-routers multicast group */ |
| 2513 | if(!radv_info->all_routers_mcast) |
| 2514 | { |
| 2515 | /* send MDLP_REPORT_EVENT message */ |
| 2516 | ip6_neighbor_send_mldpv2_report(radv_info->sw_if_index); |
| 2517 | radv_info->all_routers_mcast = 1; |
| 2518 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2519 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2520 | /* is it time to send a multicast RA on this interface? */ |
| 2521 | if(radv_info->send_radv && (now >= radv_info->next_multicast_time)) |
| 2522 | { |
| 2523 | u32 n_to_alloc = 1; |
| 2524 | u32 n_allocated; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2525 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2526 | f64 rfn = (radv_info->max_radv_interval - radv_info->min_radv_interval) * |
| 2527 | random_f64 (&radv_info->seed) + radv_info->min_radv_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2528 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2529 | /* multicast send - compute next multicast send time */ |
| 2530 | if( radv_info->initial_adverts_sent > 0) |
| 2531 | { |
| 2532 | radv_info->initial_adverts_sent--; |
| 2533 | if(rfn > radv_info-> initial_adverts_interval) |
| 2534 | rfn = radv_info-> initial_adverts_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2535 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2536 | /* check to see if we are ceasing to send */ |
| 2537 | if( radv_info->initial_adverts_sent == 0) |
| 2538 | if(radv_info->cease_radv) |
| 2539 | radv_info->send_radv = 0; |
| 2540 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2541 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2542 | radv_info->next_multicast_time = rfn + now; |
| 2543 | radv_info->last_multicast_time = now; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2544 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2545 | /* send advert now - build a "solicted" router advert with unspecified source address */ |
| 2546 | n_allocated = vlib_buffer_alloc_from_free_list |
| 2547 | (vm, &bo0, n_to_alloc, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2548 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2549 | if (PREDICT_FALSE(n_allocated == 0)) |
| 2550 | { |
| 2551 | clib_warning ("buffer allocation failure"); |
| 2552 | continue; |
| 2553 | } |
| 2554 | b0 = vlib_get_buffer (vm, bo0); |
| 2555 | b0->current_length = sizeof( icmp6_router_solicitation_header_t); |
| 2556 | b0->error = ICMP6_ERROR_NONE; |
| 2557 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = radv_info->sw_if_index; |
| 2558 | |
| 2559 | h0 = vlib_buffer_get_current (b0); |
| 2560 | |
| 2561 | memset (h0, 0, sizeof (icmp6_router_solicitation_header_t)); |
| 2562 | |
| 2563 | h0->ip.ip_version_traffic_class_and_flow_label = clib_host_to_net_u32 (0x6 << 28); |
| 2564 | h0->ip.payload_length = clib_host_to_net_u16 (sizeof (icmp6_router_solicitation_header_t) |
| 2565 | - STRUCT_OFFSET_OF (icmp6_router_solicitation_header_t, neighbor)); |
| 2566 | h0->ip.protocol = IP_PROTOCOL_ICMP6; |
| 2567 | h0->ip.hop_limit = 255; |
| 2568 | |
| 2569 | /* set src/dst address as "unspecified" this marks this packet as internally generated rather than recieved */ |
| 2570 | h0->ip.src_address.as_u64[0] = 0; |
| 2571 | h0->ip.src_address.as_u64[1] = 0; |
| 2572 | |
| 2573 | h0->ip.dst_address.as_u64[0] = 0; |
| 2574 | h0->ip.dst_address.as_u64[1] = 0; |
| 2575 | |
| 2576 | h0->neighbor.icmp.type = ICMP6_router_solicitation; |
| 2577 | |
| 2578 | if (PREDICT_FALSE(f == 0)) |
| 2579 | { |
| 2580 | f = vlib_get_frame_to_node (vm, ip6_icmp_router_solicitation_node.index); |
| 2581 | to_next = vlib_frame_vector_args (f); |
| 2582 | n_left_to_next = VLIB_FRAME_SIZE; |
| 2583 | n_this_frame = 0; |
| 2584 | } |
| 2585 | |
| 2586 | n_this_frame++; |
| 2587 | n_left_to_next--; |
| 2588 | to_next[0] = bo0; |
| 2589 | to_next += 1; |
| 2590 | |
| 2591 | if (PREDICT_FALSE(n_left_to_next == 0)) |
| 2592 | { |
| 2593 | f->n_vectors = n_this_frame; |
| 2594 | vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f); |
| 2595 | f = 0; |
| 2596 | } |
| 2597 | } |
| 2598 | })); |
| 2599 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2600 | |
| 2601 | if (f) |
| 2602 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2603 | ASSERT (n_this_frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2604 | f->n_vectors = n_this_frame; |
| 2605 | vlib_put_frame_to_node (vm, ip6_icmp_router_solicitation_node.index, f); |
| 2606 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2607 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | static uword |
| 2611 | ip6_icmp_neighbor_discovery_event_process (vlib_main_t * vm, |
| 2612 | vlib_node_runtime_t * node, |
| 2613 | vlib_frame_t * frame) |
| 2614 | { |
| 2615 | uword event_type; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2616 | ip6_icmp_neighbor_discovery_event_data_t *event_data; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2617 | |
| 2618 | /* init code here */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2619 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2620 | while (1) |
| 2621 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2622 | vlib_process_wait_for_event_or_clock (vm, 1. /* seconds */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2623 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2624 | event_data = vlib_process_get_event_data (vm, &event_type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2625 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2626 | if (!event_data) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2627 | { |
| 2628 | /* No events found: timer expired. */ |
| 2629 | /* process interface list and send RAs as appropriate, update timer info */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2630 | ip6_neighbor_process_timer_event (vm, node, frame); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2631 | } |
| 2632 | else |
| 2633 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2634 | switch (event_type) |
| 2635 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2636 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2637 | case ICMP6_ND_EVENT_INIT: |
| 2638 | break; |
| 2639 | |
| 2640 | case ~0: |
| 2641 | break; |
| 2642 | |
| 2643 | default: |
| 2644 | ASSERT (0); |
| 2645 | } |
| 2646 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2647 | if (event_data) |
| 2648 | _vec_len (event_data) = 0; |
| 2649 | } |
| 2650 | } |
| 2651 | return frame->n_vectors; |
| 2652 | } |
| 2653 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2654 | /* *INDENT-OFF* */ |
| 2655 | VLIB_REGISTER_NODE (ip6_icmp_router_advertisement_node,static) = |
| 2656 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2657 | .function = icmp6_router_advertisement, |
| 2658 | .name = "icmp6-router-advertisement", |
| 2659 | |
| 2660 | .vector_size = sizeof (u32), |
| 2661 | |
| 2662 | .format_trace = format_icmp6_input_trace, |
| 2663 | |
| 2664 | .n_next_nodes = 1, |
| 2665 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 2666 | [0] = "ip6-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2667 | }, |
| 2668 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2669 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2670 | |
| 2671 | vlib_node_registration_t ip6_icmp_neighbor_discovery_event_node = { |
| 2672 | |
| 2673 | .function = ip6_icmp_neighbor_discovery_event_process, |
| 2674 | .name = "ip6-icmp-neighbor-discovery-event-process", |
| 2675 | .type = VLIB_NODE_TYPE_PROCESS, |
| 2676 | }; |
| 2677 | |
| 2678 | static uword |
| 2679 | icmp6_neighbor_solicitation (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2680 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 2681 | { |
| 2682 | return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame, |
| 2683 | /* is_solicitation */ |
| 2684 | 1); |
| 2685 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2686 | |
| 2687 | static uword |
| 2688 | icmp6_neighbor_advertisement (vlib_main_t * vm, |
| 2689 | vlib_node_runtime_t * node, |
| 2690 | vlib_frame_t * frame) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2691 | { |
| 2692 | return icmp6_neighbor_solicitation_or_advertisement (vm, node, frame, |
| 2693 | /* is_solicitation */ |
| 2694 | 0); |
| 2695 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2696 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2697 | /* *INDENT-OFF* */ |
| 2698 | VLIB_REGISTER_NODE (ip6_icmp_neighbor_solicitation_node,static) = |
| 2699 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2700 | .function = icmp6_neighbor_solicitation, |
| 2701 | .name = "icmp6-neighbor-solicitation", |
| 2702 | |
| 2703 | .vector_size = sizeof (u32), |
| 2704 | |
| 2705 | .format_trace = format_icmp6_input_trace, |
| 2706 | |
| 2707 | .n_next_nodes = ICMP6_NEIGHBOR_SOLICITATION_N_NEXT, |
| 2708 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 2709 | [ICMP6_NEIGHBOR_SOLICITATION_NEXT_DROP] = "ip6-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2710 | [ICMP6_NEIGHBOR_SOLICITATION_NEXT_REPLY] = "interface-output", |
| 2711 | }, |
| 2712 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2713 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2714 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2715 | /* *INDENT-OFF* */ |
| 2716 | VLIB_REGISTER_NODE (ip6_icmp_neighbor_advertisement_node,static) = |
| 2717 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2718 | .function = icmp6_neighbor_advertisement, |
| 2719 | .name = "icmp6-neighbor-advertisement", |
| 2720 | |
| 2721 | .vector_size = sizeof (u32), |
| 2722 | |
| 2723 | .format_trace = format_icmp6_input_trace, |
| 2724 | |
| 2725 | .n_next_nodes = 1, |
| 2726 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 2727 | [0] = "ip6-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2728 | }, |
| 2729 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2730 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2731 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2732 | /* API support functions */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2733 | int |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2734 | ip6_neighbor_ra_config (vlib_main_t * vm, u32 sw_if_index, |
| 2735 | u8 suppress, u8 managed, u8 other, |
| 2736 | u8 ll_option, u8 send_unicast, u8 cease, |
| 2737 | u8 use_lifetime, u32 lifetime, |
| 2738 | u32 initial_count, u32 initial_interval, |
| 2739 | u32 max_interval, u32 min_interval, u8 is_no) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2740 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2741 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2742 | int error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2743 | u32 ri; |
| 2744 | |
| 2745 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2746 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 2747 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2748 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2749 | error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2750 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2751 | if (!error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2752 | { |
| 2753 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2754 | ip6_radv_t *radv_info; |
| 2755 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2756 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2757 | if ((max_interval != 0) && (min_interval == 0)) |
| 2758 | min_interval = .75 * max_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2759 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2760 | max_interval = |
| 2761 | (max_interval != |
| 2762 | 0) ? ((is_no) ? DEF_MAX_RADV_INTERVAL : max_interval) : |
| 2763 | radv_info->max_radv_interval; |
| 2764 | min_interval = |
| 2765 | (min_interval != |
| 2766 | 0) ? ((is_no) ? DEF_MIN_RADV_INTERVAL : min_interval) : |
| 2767 | radv_info->min_radv_interval; |
| 2768 | lifetime = |
| 2769 | (use_lifetime != |
| 2770 | 0) ? ((is_no) ? DEF_DEF_RTR_LIFETIME : lifetime) : |
| 2771 | radv_info->adv_router_lifetime_in_sec; |
| 2772 | |
| 2773 | if (lifetime) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2774 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2775 | if (lifetime > MAX_DEF_RTR_LIFETIME) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2776 | lifetime = MAX_DEF_RTR_LIFETIME; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2777 | |
| 2778 | if (lifetime <= max_interval) |
| 2779 | return VNET_API_ERROR_INVALID_VALUE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2780 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2781 | |
| 2782 | if (min_interval != 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2783 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2784 | if ((min_interval > .75 * max_interval) || (min_interval < 3)) |
| 2785 | return VNET_API_ERROR_INVALID_VALUE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2788 | if ((initial_count > MAX_INITIAL_RTR_ADVERTISEMENTS) || |
| 2789 | (initial_interval > MAX_INITIAL_RTR_ADVERT_INTERVAL)) |
| 2790 | return VNET_API_ERROR_INVALID_VALUE; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2791 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2792 | /* |
| 2793 | if "flag" is set and is_no is true then restore default value else set value corresponding to "flag" |
| 2794 | if "flag" is clear don't change corresponding value |
| 2795 | */ |
| 2796 | radv_info->send_radv = |
| 2797 | (suppress != 0) ? ((is_no != 0) ? 1 : 0) : radv_info->send_radv; |
| 2798 | radv_info->adv_managed_flag = |
| 2799 | (managed != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_managed_flag; |
| 2800 | radv_info->adv_other_flag = |
| 2801 | (other != 0) ? ((is_no) ? 0 : 1) : radv_info->adv_other_flag; |
| 2802 | radv_info->adv_link_layer_address = |
| 2803 | (ll_option != |
| 2804 | 0) ? ((is_no) ? 1 : 0) : radv_info->adv_link_layer_address; |
| 2805 | radv_info->send_unicast = |
| 2806 | (send_unicast != 0) ? ((is_no) ? 0 : 1) : radv_info->send_unicast; |
| 2807 | radv_info->cease_radv = |
| 2808 | (cease != 0) ? ((is_no) ? 0 : 1) : radv_info->cease_radv; |
| 2809 | |
| 2810 | radv_info->min_radv_interval = min_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2811 | radv_info->max_radv_interval = max_interval; |
| 2812 | radv_info->adv_router_lifetime_in_sec = lifetime; |
| 2813 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2814 | radv_info->initial_adverts_count = |
| 2815 | (initial_count != |
| 2816 | 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERTISEMENTS : initial_count) : |
| 2817 | radv_info->initial_adverts_count; |
| 2818 | radv_info->initial_adverts_interval = |
| 2819 | (initial_interval != |
| 2820 | 0) ? ((is_no) ? MAX_INITIAL_RTR_ADVERT_INTERVAL : initial_interval) : |
| 2821 | radv_info->initial_adverts_interval; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2822 | |
| 2823 | /* restart */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2824 | if ((cease != 0) && (is_no)) |
| 2825 | radv_info->send_radv = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2826 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2827 | radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1; |
| 2828 | radv_info->next_multicast_time = vlib_time_now (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2829 | radv_info->last_multicast_time = vlib_time_now (vm); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2830 | radv_info->last_radv_time = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2831 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2832 | return (error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | int |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2836 | ip6_neighbor_ra_prefix (vlib_main_t * vm, u32 sw_if_index, |
| 2837 | ip6_address_t * prefix_addr, u8 prefix_len, |
| 2838 | u8 use_default, u32 val_lifetime, u32 pref_lifetime, |
| 2839 | u8 no_advertise, u8 off_link, u8 no_autoconfig, |
| 2840 | u8 no_onlink, u8 is_no) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2841 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2842 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2843 | int error; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2844 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2845 | u32 ri; |
| 2846 | |
| 2847 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2848 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 2849 | ~0); |
| 2850 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2851 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 2852 | |
| 2853 | error = (ri != ~0) ? 0 : VNET_API_ERROR_INVALID_SW_IF_INDEX; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2854 | |
| 2855 | if (!error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2856 | { |
| 2857 | f64 now = vlib_time_now (vm); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2858 | ip6_radv_t *radv_info; |
| 2859 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2860 | |
| 2861 | /* prefix info add, delete or update */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2862 | ip6_radv_prefix_t *prefix; |
| 2863 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2864 | /* lookup prefix info for this address on this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2865 | uword *p = mhash_get (&radv_info->address_to_prefix_index, prefix_addr); |
| 2866 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2867 | prefix = p ? pool_elt_at_index (radv_info->adv_prefixes_pool, p[0]) : 0; |
| 2868 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2869 | if (is_no) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2870 | { |
| 2871 | /* delete */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2872 | if (!prefix) |
| 2873 | return VNET_API_ERROR_INVALID_VALUE; /* invalid prefix */ |
| 2874 | |
| 2875 | if (prefix->prefix_len != prefix_len) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2876 | return VNET_API_ERROR_INVALID_VALUE_2; |
| 2877 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2878 | /* FIXME - Should the DP do this or the CP ? */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2879 | /* do specific delete processing here before returning */ |
| 2880 | /* try to remove from routing table */ |
| 2881 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2882 | mhash_unset (&radv_info->address_to_prefix_index, prefix_addr, |
| 2883 | /* old_value */ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2884 | pool_put (radv_info->adv_prefixes_pool, prefix); |
| 2885 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2886 | radv_info->initial_adverts_sent = |
| 2887 | radv_info->initial_adverts_count - 1; |
| 2888 | radv_info->next_multicast_time = vlib_time_now (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2889 | radv_info->last_multicast_time = vlib_time_now (vm); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2890 | radv_info->last_radv_time = 0; |
| 2891 | return (error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
| 2894 | /* adding or changing */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2895 | if (!prefix) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2896 | { |
| 2897 | /* add */ |
| 2898 | u32 pi; |
| 2899 | pool_get (radv_info->adv_prefixes_pool, prefix); |
| 2900 | pi = prefix - radv_info->adv_prefixes_pool; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2901 | mhash_set (&radv_info->address_to_prefix_index, prefix_addr, pi, |
| 2902 | /* old_value */ 0); |
| 2903 | |
| 2904 | memset (prefix, 0x0, sizeof (ip6_radv_prefix_t)); |
| 2905 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2906 | prefix->prefix_len = prefix_len; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2907 | clib_memcpy (&prefix->prefix, prefix_addr, sizeof (ip6_address_t)); |
| 2908 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2909 | /* initialize default values */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2910 | prefix->adv_on_link_flag = 1; /* L bit set */ |
| 2911 | prefix->adv_autonomous_flag = 1; /* A bit set */ |
| 2912 | prefix->adv_valid_lifetime_in_secs = DEF_ADV_VALID_LIFETIME; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2913 | prefix->adv_pref_lifetime_in_secs = DEF_ADV_PREF_LIFETIME; |
| 2914 | prefix->enabled = 1; |
| 2915 | prefix->decrement_lifetime_flag = 1; |
| 2916 | prefix->deprecated_prefix_flag = 1; |
| 2917 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2918 | if (off_link == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2919 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2920 | /* FIXME - Should the DP do this or the CP ? */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2921 | /* insert prefix into routing table as a connected prefix */ |
| 2922 | } |
| 2923 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2924 | if (use_default) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2925 | goto restart; |
| 2926 | } |
| 2927 | else |
| 2928 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2929 | |
| 2930 | if (prefix->prefix_len != prefix_len) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2931 | return VNET_API_ERROR_INVALID_VALUE_2; |
| 2932 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2933 | if (off_link != 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2934 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2935 | /* FIXME - Should the DP do this or the CP ? */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2936 | /* remove from routing table if already there */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2937 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2940 | if ((val_lifetime == ~0) || (pref_lifetime == ~0)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2941 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2942 | prefix->adv_valid_lifetime_in_secs = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2943 | prefix->adv_pref_lifetime_in_secs = ~0; |
| 2944 | prefix->decrement_lifetime_flag = 0; |
| 2945 | } |
| 2946 | else |
| 2947 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2948 | prefix->adv_valid_lifetime_in_secs = val_lifetime;; |
| 2949 | prefix->adv_pref_lifetime_in_secs = pref_lifetime; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2950 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2951 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2952 | /* copy remaining */ |
| 2953 | prefix->enabled = !(no_advertise != 0); |
| 2954 | prefix->adv_on_link_flag = !((off_link != 0) || (no_onlink != 0)); |
| 2955 | prefix->adv_autonomous_flag = !(no_autoconfig != 0); |
| 2956 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2957 | restart: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2958 | /* restart */ |
| 2959 | /* fill in the expiration times */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2960 | prefix->valid_lifetime_expires = |
| 2961 | now + prefix->adv_valid_lifetime_in_secs; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2962 | prefix->pref_lifetime_expires = now + prefix->adv_pref_lifetime_in_secs; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2963 | |
| 2964 | radv_info->initial_adverts_sent = radv_info->initial_adverts_count - 1; |
| 2965 | radv_info->next_multicast_time = vlib_time_now (vm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2966 | radv_info->last_multicast_time = vlib_time_now (vm); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2967 | radv_info->last_radv_time = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2968 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2969 | return (error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2973 | ip6_neighbor_cmd (vlib_main_t * vm, unformat_input_t * main_input, |
| 2974 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2975 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2976 | vnet_main_t *vnm = vnet_get_main (); |
| 2977 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 2978 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2979 | u8 is_no = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2980 | u8 suppress = 0, managed = 0, other = 0; |
| 2981 | u8 suppress_ll_option = 0, send_unicast = 0, cease = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2982 | u8 use_lifetime = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2983 | u32 sw_if_index, ra_lifetime = 0, ra_initial_count = |
| 2984 | 0, ra_initial_interval = 0; |
| 2985 | u32 ra_max_interval = 0, ra_min_interval = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2986 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2987 | unformat_input_t _line_input, *line_input = &_line_input; |
| 2988 | vnet_sw_interface_t *sw_if0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2989 | |
| 2990 | int add_radv_info = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2991 | __attribute__ ((unused)) ip6_radv_t *radv_info = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2992 | ip6_address_t ip6_addr; |
| 2993 | u32 addr_len; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2994 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2995 | |
| 2996 | /* Get a line of input. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 2997 | if (!unformat_user (main_input, unformat_line_input, line_input)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 2998 | return 0; |
| 2999 | |
| 3000 | /* get basic radv info for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3001 | if (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3002 | { |
| 3003 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3004 | if (unformat_user (line_input, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3005 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 3006 | { |
| 3007 | u32 ri; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3008 | ethernet_interface_t *eth_if0 = 0; |
| 3009 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3010 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3011 | if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 3012 | eth_if0 = |
| 3013 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
| 3014 | |
| 3015 | if (!eth_if0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3016 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3017 | error = |
| 3018 | clib_error_return (0, "Interface must be of ethernet type"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3019 | goto done; |
| 3020 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3021 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3022 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3023 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, |
| 3024 | sw_if_index, ~0); |
| 3025 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3026 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3027 | |
| 3028 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3029 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3030 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3031 | } |
| 3032 | else |
| 3033 | { |
| 3034 | error = clib_error_return (0, "unknown interface %U'", |
| 3035 | format_unformat_error, line_input); |
| 3036 | goto done; |
| 3037 | } |
| 3038 | } |
| 3039 | else |
| 3040 | { |
| 3041 | error = clib_error_return (0, "invalid interface name %U'", |
| 3042 | format_unformat_error, line_input); |
| 3043 | goto done; |
| 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | /* get the rest of the command */ |
| 3048 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 3049 | { |
| 3050 | if (unformat (line_input, "no")) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3051 | is_no = 1; |
| 3052 | else if (unformat (line_input, "prefix %U/%d", |
| 3053 | unformat_ip6_address, &ip6_addr, &addr_len)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3054 | { |
| 3055 | add_radv_info = 0; |
| 3056 | break; |
| 3057 | } |
| 3058 | else if (unformat (line_input, "ra-managed-config-flag")) |
| 3059 | { |
| 3060 | managed = 1; |
| 3061 | break; |
| 3062 | } |
| 3063 | else if (unformat (line_input, "ra-other-config-flag")) |
| 3064 | { |
| 3065 | other = 1; |
| 3066 | break; |
| 3067 | } |
Chris Luke | 33879c9 | 2016-06-28 19:54:21 -0400 | [diff] [blame] | 3068 | else if (unformat (line_input, "ra-suppress") || |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3069 | unformat (line_input, "ra-surpress")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3070 | { |
Chris Luke | 33879c9 | 2016-06-28 19:54:21 -0400 | [diff] [blame] | 3071 | suppress = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3072 | break; |
| 3073 | } |
Chris Luke | 33879c9 | 2016-06-28 19:54:21 -0400 | [diff] [blame] | 3074 | else if (unformat (line_input, "ra-suppress-link-layer") || |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3075 | unformat (line_input, "ra-surpress-link-layer")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3076 | { |
Chris Luke | 33879c9 | 2016-06-28 19:54:21 -0400 | [diff] [blame] | 3077 | suppress_ll_option = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3078 | break; |
| 3079 | } |
| 3080 | else if (unformat (line_input, "ra-send-unicast")) |
| 3081 | { |
| 3082 | send_unicast = 1; |
| 3083 | break; |
| 3084 | } |
| 3085 | else if (unformat (line_input, "ra-lifetime")) |
| 3086 | { |
| 3087 | if (!unformat (line_input, "%d", &ra_lifetime)) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3088 | { |
| 3089 | error = unformat_parse_error (line_input); |
| 3090 | goto done; |
| 3091 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3092 | use_lifetime = 1; |
| 3093 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3094 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3095 | else if (unformat (line_input, "ra-initial")) |
| 3096 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3097 | if (!unformat |
| 3098 | (line_input, "%d %d", &ra_initial_count, &ra_initial_interval)) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3099 | { |
| 3100 | error = unformat_parse_error (line_input); |
| 3101 | goto done; |
| 3102 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3103 | break; |
| 3104 | } |
| 3105 | else if (unformat (line_input, "ra-interval")) |
| 3106 | { |
| 3107 | if (!unformat (line_input, "%d", &ra_max_interval)) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3108 | { |
| 3109 | error = unformat_parse_error (line_input); |
| 3110 | goto done; |
| 3111 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3112 | |
| 3113 | if (!unformat (line_input, "%d", &ra_min_interval)) |
| 3114 | ra_min_interval = 0; |
| 3115 | break; |
| 3116 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3117 | else if (unformat (line_input, "ra-cease")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3118 | { |
| 3119 | cease = 1; |
| 3120 | break; |
| 3121 | } |
| 3122 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3123 | { |
| 3124 | error = unformat_parse_error (line_input); |
| 3125 | goto done; |
| 3126 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3129 | if (add_radv_info) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3130 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3131 | ip6_neighbor_ra_config (vm, sw_if_index, |
| 3132 | suppress, managed, other, |
| 3133 | suppress_ll_option, send_unicast, cease, |
| 3134 | use_lifetime, ra_lifetime, |
| 3135 | ra_initial_count, ra_initial_interval, |
| 3136 | ra_max_interval, ra_min_interval, is_no); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3137 | } |
| 3138 | else |
| 3139 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3140 | u32 valid_lifetime_in_secs = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3141 | u32 pref_lifetime_in_secs = 0; |
| 3142 | u8 use_prefix_default_values = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3143 | u8 no_advertise = 0; |
| 3144 | u8 off_link = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3145 | u8 no_autoconfig = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3146 | u8 no_onlink = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3147 | |
| 3148 | /* get the rest of the command */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3149 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3150 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3151 | if (unformat (line_input, "default")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3152 | { |
| 3153 | use_prefix_default_values = 1; |
| 3154 | break; |
| 3155 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3156 | else if (unformat (line_input, "infinite")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3157 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3158 | valid_lifetime_in_secs = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3159 | pref_lifetime_in_secs = ~0; |
| 3160 | break; |
| 3161 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3162 | else if (unformat (line_input, "%d %d", &valid_lifetime_in_secs, |
| 3163 | &pref_lifetime_in_secs)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3164 | break; |
| 3165 | else |
| 3166 | break; |
| 3167 | } |
| 3168 | |
| 3169 | |
| 3170 | /* get the rest of the command */ |
| 3171 | while (!use_prefix_default_values && |
| 3172 | unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 3173 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3174 | if (unformat (line_input, "no-advertise")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3175 | no_advertise = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3176 | else if (unformat (line_input, "off-link")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3177 | off_link = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3178 | else if (unformat (line_input, "no-autoconfig")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3179 | no_autoconfig = 1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3180 | else if (unformat (line_input, "no-onlink")) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3181 | no_onlink = 1; |
| 3182 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3183 | { |
| 3184 | error = unformat_parse_error (line_input); |
| 3185 | goto done; |
| 3186 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3187 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3188 | |
| 3189 | ip6_neighbor_ra_prefix (vm, sw_if_index, |
| 3190 | &ip6_addr, addr_len, |
| 3191 | use_prefix_default_values, |
| 3192 | valid_lifetime_in_secs, |
| 3193 | pref_lifetime_in_secs, |
| 3194 | no_advertise, |
| 3195 | off_link, no_autoconfig, no_onlink, is_no); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 3198 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3199 | unformat_free (line_input); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3200 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3201 | return error; |
| 3202 | } |
| 3203 | |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3204 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3205 | ip6_print_addrs (vlib_main_t * vm, u32 * addrs) |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3206 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3207 | ip_lookup_main_t *lm = &ip6_main.lookup_main; |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3208 | u32 i; |
| 3209 | |
| 3210 | for (i = 0; i < vec_len (addrs); i++) |
| 3211 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3212 | ip_interface_address_t *a = |
| 3213 | pool_elt_at_index (lm->if_address_pool, addrs[i]); |
| 3214 | ip6_address_t *address = ip_interface_address_get_address (lm, a); |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3215 | |
| 3216 | vlib_cli_output (vm, "\t\t%U/%d", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3217 | format_ip6_address, address, a->address_length); |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3218 | } |
| 3219 | } |
| 3220 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3221 | static clib_error_t * |
| 3222 | show_ip6_interface_cmd (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3223 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3224 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3225 | vnet_main_t *vnm = vnet_get_main (); |
| 3226 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3227 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3228 | u32 sw_if_index; |
| 3229 | |
| 3230 | sw_if_index = ~0; |
| 3231 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3232 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3233 | { |
| 3234 | u32 ri; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3235 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3236 | /* look up the radv_t information for this interface */ |
| 3237 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, |
| 3238 | sw_if_index, ~0); |
| 3239 | |
| 3240 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 3241 | |
| 3242 | if (ri != ~0) |
| 3243 | { |
| 3244 | ip_lookup_main_t *lm = &ip6_main.lookup_main; |
| 3245 | ip6_radv_t *radv_info; |
| 3246 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 3247 | |
| 3248 | vlib_cli_output (vm, "%U is admin %s\n", |
| 3249 | format_vnet_sw_interface_name, vnm, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3250 | vnet_get_sw_interface (vnm, sw_if_index), |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3251 | (vnet_sw_interface_is_admin_up (vnm, sw_if_index) ? |
| 3252 | "up" : "down")); |
| 3253 | |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3254 | u32 ai; |
| 3255 | u32 *link_scope = 0, *global_scope = 0; |
| 3256 | u32 *local_scope = 0, *unknown_scope = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3257 | ip_interface_address_t *a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3258 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3259 | vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index, |
| 3260 | sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3261 | ai = lm->if_address_pool_index_by_sw_if_index[sw_if_index]; |
| 3262 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3263 | while (ai != (u32) ~ 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3264 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3265 | a = pool_elt_at_index (lm->if_address_pool, ai); |
| 3266 | ip6_address_t *address = |
| 3267 | ip_interface_address_get_address (lm, a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3268 | |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3269 | if (ip6_address_is_link_local_unicast (address)) |
| 3270 | vec_add1 (link_scope, ai); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3271 | else if (ip6_address_is_global_unicast (address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3272 | vec_add1 (global_scope, ai); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3273 | else if (ip6_address_is_local_unicast (address)) |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3274 | vec_add1 (local_scope, ai); |
| 3275 | else |
| 3276 | vec_add1 (unknown_scope, ai); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3277 | |
| 3278 | ai = a->next_this_sw_interface; |
| 3279 | } |
| 3280 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3281 | if (vec_len (link_scope)) |
| 3282 | { |
| 3283 | vlib_cli_output (vm, "\tLink-local address(es):\n"); |
| 3284 | ip6_print_addrs (vm, link_scope); |
| 3285 | vec_free (link_scope); |
| 3286 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3287 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3288 | if (vec_len (local_scope)) |
| 3289 | { |
| 3290 | vlib_cli_output (vm, "\tLocal unicast address(es):\n"); |
| 3291 | ip6_print_addrs (vm, local_scope); |
| 3292 | vec_free (local_scope); |
| 3293 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3294 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3295 | if (vec_len (global_scope)) |
| 3296 | { |
| 3297 | vlib_cli_output (vm, "\tGlobal unicast address(es):\n"); |
| 3298 | ip6_print_addrs (vm, global_scope); |
| 3299 | vec_free (global_scope); |
| 3300 | } |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3301 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3302 | if (vec_len (unknown_scope)) |
| 3303 | { |
| 3304 | vlib_cli_output (vm, "\tOther-scope address(es):\n"); |
| 3305 | ip6_print_addrs (vm, unknown_scope); |
| 3306 | vec_free (unknown_scope); |
| 3307 | } |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3308 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3309 | vlib_cli_output (vm, "\tLink-local address(es):\n"); |
| 3310 | vlib_cli_output (vm, "\t\t%U\n", format_ip6_address, |
| 3311 | &radv_info->link_local_address); |
| 3312 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3313 | vlib_cli_output (vm, "\tJoined group address(es):\n"); |
| 3314 | ip6_mldp_group_t *m; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3315 | /* *INDENT-OFF* */ |
| 3316 | pool_foreach (m, radv_info->mldp_group_pool, |
| 3317 | ({ |
| 3318 | vlib_cli_output (vm, "\t\t%U\n", format_ip6_address, |
| 3319 | &m->mcast_address); |
| 3320 | })); |
| 3321 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3322 | |
| 3323 | vlib_cli_output (vm, "\tAdvertised Prefixes:\n"); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3324 | ip6_radv_prefix_t *p; |
| 3325 | /* *INDENT-OFF* */ |
| 3326 | pool_foreach (p, radv_info->adv_prefixes_pool, |
| 3327 | ({ |
| 3328 | vlib_cli_output (vm, "\t\tprefix %U, length %d\n", |
| 3329 | format_ip6_address, &p->prefix, p->prefix_len); |
| 3330 | })); |
| 3331 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3332 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3333 | vlib_cli_output (vm, "\tMTU is %d\n", radv_info->adv_link_mtu); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3334 | vlib_cli_output (vm, "\tICMP error messages are unlimited\n"); |
| 3335 | vlib_cli_output (vm, "\tICMP redirects are disabled\n"); |
| 3336 | vlib_cli_output (vm, "\tICMP unreachables are not sent\n"); |
| 3337 | vlib_cli_output (vm, "\tND DAD is disabled\n"); |
| 3338 | //vlib_cli_output (vm, "\tND reachable time is %d milliseconds\n",); |
| 3339 | vlib_cli_output (vm, "\tND advertised reachable time is %d\n", |
| 3340 | radv_info->adv_neighbor_reachable_time_in_msec); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3341 | vlib_cli_output (vm, |
| 3342 | "\tND advertised retransmit interval is %d (msec)\n", |
| 3343 | radv_info-> |
| 3344 | adv_time_in_msec_between_retransmitted_neighbor_solicitations); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3345 | |
| 3346 | u32 ra_interval = radv_info->max_radv_interval; |
| 3347 | u32 ra_interval_min = radv_info->min_radv_interval; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3348 | vlib_cli_output (vm, |
| 3349 | "\tND router advertisements are sent every %d seconds (min interval is %d)\n", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3350 | ra_interval, ra_interval_min); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3351 | vlib_cli_output (vm, |
| 3352 | "\tND router advertisements live for %d seconds\n", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3353 | radv_info->adv_router_lifetime_in_sec); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3354 | vlib_cli_output (vm, |
| 3355 | "\tHosts %s stateless autoconfig for addresses\n", |
| 3356 | (radv_info->adv_managed_flag) ? "use" : |
| 3357 | " don't use"); |
| 3358 | vlib_cli_output (vm, "\tND router advertisements sent %d\n", |
| 3359 | radv_info->n_advertisements_sent); |
| 3360 | vlib_cli_output (vm, "\tND router solicitations received %d\n", |
| 3361 | radv_info->n_solicitations_rcvd); |
| 3362 | vlib_cli_output (vm, "\tND router solicitations dropped %d\n", |
| 3363 | radv_info->n_solicitations_dropped); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3364 | } |
| 3365 | else |
| 3366 | { |
Chris Luke | bfd32fd | 2016-06-24 20:38:06 -0400 | [diff] [blame] | 3367 | error = clib_error_return (0, "IPv6 not enabled on interface", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3368 | format_unformat_error, input); |
| 3369 | |
| 3370 | } |
| 3371 | } |
| 3372 | return error; |
| 3373 | } |
| 3374 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3375 | /*? |
| 3376 | * This command is used to display various IPv6 attributes on a given |
| 3377 | * interface. |
| 3378 | * |
| 3379 | * @cliexpar |
| 3380 | * Example of how to display IPv6 settings: |
| 3381 | * @cliexstart{show ip6 interface GigabitEthernet2/0/0} |
| 3382 | * GigabitEthernet2/0/0 is admin up |
| 3383 | * Link-local address(es): |
| 3384 | * fe80::ab8/64 |
| 3385 | * Joined group address(es): |
| 3386 | * ff02::1 |
| 3387 | * ff02::2 |
| 3388 | * ff02::16 |
| 3389 | * ff02::1:ff00:ab8 |
| 3390 | * Advertised Prefixes: |
| 3391 | * prefix fe80::fe:28ff:fe9c:75b3, length 64 |
| 3392 | * MTU is 1500 |
| 3393 | * ICMP error messages are unlimited |
| 3394 | * ICMP redirects are disabled |
| 3395 | * ICMP unreachables are not sent |
| 3396 | * ND DAD is disabled |
| 3397 | * ND advertised reachable time is 0 |
| 3398 | * ND advertised retransmit interval is 0 (msec) |
| 3399 | * ND router advertisements are sent every 200 seconds (min interval is 150) |
| 3400 | * ND router advertisements live for 600 seconds |
| 3401 | * Hosts use stateless autoconfig for addresses |
| 3402 | * ND router advertisements sent 19336 |
| 3403 | * ND router solicitations received 0 |
| 3404 | * ND router solicitations dropped 0 |
| 3405 | * @cliexend |
| 3406 | * Example of output if IPv6 is not enabled on the interface: |
| 3407 | * @cliexstart{show ip6 interface GigabitEthernet2/0/0} |
| 3408 | * show ip6 interface: IPv6 not enabled on interface |
| 3409 | * @cliexend |
| 3410 | ?*/ |
| 3411 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3412 | VLIB_CLI_COMMAND (show_ip6_interface_command, static) = |
| 3413 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3414 | .path = "show ip6 interface", |
| 3415 | .function = show_ip6_interface_cmd, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3416 | .short_help = "show ip6 interface <interface>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3417 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3418 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3419 | |
| 3420 | clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3421 | disable_ip6_interface (vlib_main_t * vm, u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3422 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3423 | clib_error_t *error = 0; |
| 3424 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3425 | u32 ri; |
| 3426 | |
| 3427 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3428 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 3429 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3430 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3431 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3432 | /* if not created - do nothing */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3433 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3434 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3435 | ip6_radv_t *radv_info; |
| 3436 | |
| 3437 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3438 | |
| 3439 | /* check radv_info ref count for other ip6 addresses on this interface */ |
Wojciech Dec | 7bc7310 | 2017-02-14 16:24:28 +0100 | [diff] [blame] | 3440 | /* This implicitly excludes the link local address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3441 | if (radv_info->ref_count == 0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3442 | { |
| 3443 | /* essentially "disables" ipv6 on this interface */ |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3444 | ip6_ll_prefix_t ilp = { |
| 3445 | .ilp_addr = radv_info->link_local_address, |
| 3446 | .ilp_sw_if_index = sw_if_index, |
| 3447 | }; |
| 3448 | ip6_ll_table_entry_delete (&ilp); |
| 3449 | ip6_sw_interface_enable_disable (sw_if_index, 0); |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 3450 | ip6_mfib_interface_enable_disable (sw_if_index, 0); |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3451 | ip6_neighbor_sw_interface_add_del (vnet_get_main (), sw_if_index, |
| 3452 | 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3453 | } |
| 3454 | } |
| 3455 | return error; |
| 3456 | } |
| 3457 | |
| 3458 | int |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3459 | ip6_interface_enabled (vlib_main_t * vm, u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3460 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3461 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3462 | u32 ri = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3463 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3464 | /* look up the radv_t information for this interface */ |
| 3465 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 3466 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3467 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3468 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3469 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3470 | return ri != ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3471 | } |
| 3472 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3473 | clib_error_t * |
| 3474 | enable_ip6_interface (vlib_main_t * vm, u32 sw_if_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3475 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3476 | clib_error_t *error = 0; |
| 3477 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3478 | u32 ri; |
| 3479 | int is_add = 1; |
| 3480 | |
| 3481 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3482 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, sw_if_index, |
| 3483 | ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3484 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3485 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 3486 | |
| 3487 | /* if not created yet */ |
| 3488 | if (ri == ~0) |
| 3489 | { |
| 3490 | vnet_main_t *vnm = vnet_get_main (); |
| 3491 | vnet_sw_interface_t *sw_if0; |
| 3492 | |
| 3493 | sw_if0 = vnet_get_sup_sw_interface (vnm, sw_if_index); |
| 3494 | if (sw_if0->type == VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 3495 | { |
| 3496 | ethernet_interface_t *eth_if0; |
| 3497 | |
| 3498 | eth_if0 = |
| 3499 | ethernet_get_interface (ðernet_main, sw_if0->hw_if_index); |
| 3500 | if (eth_if0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3501 | { |
| 3502 | /* create radv_info. for this interface. This holds all the info needed for router adverts */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3503 | ri = |
| 3504 | ip6_neighbor_sw_interface_add_del (vnm, sw_if_index, is_add); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3505 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3506 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3507 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3508 | ip6_radv_t *radv_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3509 | ip6_address_t link_local_address; |
| 3510 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3511 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3512 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3513 | ip6_link_local_address_from_ethernet_mac_address |
| 3514 | (&link_local_address, eth_if0->address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3515 | |
| 3516 | sw_if0 = vnet_get_sw_interface (vnm, sw_if_index); |
Pavel Kotucek | 8dc8020 | 2017-08-15 13:52:22 +0200 | [diff] [blame] | 3517 | if (sw_if0->type == VNET_SW_INTERFACE_TYPE_SUB || |
| 3518 | sw_if0->type == VNET_SW_INTERFACE_TYPE_P2P) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3519 | { |
| 3520 | /* make up an interface id */ |
| 3521 | md5_context_t m; |
| 3522 | u8 digest[16]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3523 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3524 | link_local_address.as_u64[0] = radv_info->randomizer; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3525 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3526 | md5_init (&m); |
| 3527 | md5_add (&m, &link_local_address, 16); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3528 | md5_finish (&m, digest); |
| 3529 | |
| 3530 | clib_memcpy (&link_local_address, digest, 16); |
| 3531 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3532 | radv_info->randomizer = link_local_address.as_u64[0]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3533 | |
| 3534 | link_local_address.as_u64[0] = |
| 3535 | clib_host_to_net_u64 (0xFE80000000000000ULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3536 | /* clear u bit */ |
| 3537 | link_local_address.as_u8[8] &= 0xfd; |
| 3538 | } |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3539 | { |
| 3540 | ip6_ll_prefix_t ilp = { |
| 3541 | .ilp_addr = link_local_address, |
| 3542 | .ilp_sw_if_index = sw_if_index, |
| 3543 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3544 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3545 | ip6_ll_table_entry_update (&ilp, FIB_ROUTE_PATH_LOCAL); |
| 3546 | } |
Neale Ranns | 4008ac9 | 2017-02-13 23:20:04 -0800 | [diff] [blame] | 3547 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3548 | /* essentially "enables" ipv6 on this interface */ |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3549 | ip6_mfib_interface_enable_disable (sw_if_index, 1); |
| 3550 | ip6_sw_interface_enable_disable (sw_if_index, 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3551 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3552 | if (!error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3553 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3554 | radv_info->link_local_address = link_local_address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3555 | } |
| 3556 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3557 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3558 | } |
| 3559 | } |
| 3560 | return error; |
| 3561 | } |
| 3562 | |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 3563 | int |
| 3564 | ip6_get_ll_address (u32 sw_if_index, ip6_address_t * addr) |
| 3565 | { |
| 3566 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3567 | ip6_radv_t *radv_info; |
| 3568 | u32 ri; |
| 3569 | |
| 3570 | if (vec_len (nm->if_radv_pool_index_by_sw_if_index) < sw_if_index) |
| 3571 | return 0; |
| 3572 | |
| 3573 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
| 3574 | |
| 3575 | if (ri == ~0) |
| 3576 | return 0; |
| 3577 | |
| 3578 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 3579 | *addr = radv_info->link_local_address; |
| 3580 | |
| 3581 | return (!0); |
| 3582 | } |
| 3583 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3584 | static clib_error_t * |
| 3585 | enable_ip6_interface_cmd (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3586 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3587 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3588 | vnet_main_t *vnm = vnet_get_main (); |
| 3589 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3590 | u32 sw_if_index; |
| 3591 | |
| 3592 | sw_if_index = ~0; |
| 3593 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3594 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3595 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3596 | enable_ip6_interface (vm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3597 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3598 | else |
| 3599 | { |
| 3600 | error = clib_error_return (0, "unknown interface\n'", |
| 3601 | format_unformat_error, input); |
| 3602 | |
| 3603 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3604 | return error; |
| 3605 | } |
| 3606 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3607 | /*? |
| 3608 | * This command is used to enable IPv6 on a given interface. |
| 3609 | * |
| 3610 | * @cliexpar |
| 3611 | * Example of how enable IPv6 on a given interface: |
| 3612 | * @cliexcmd{enable ip6 interface GigabitEthernet2/0/0} |
| 3613 | ?*/ |
| 3614 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3615 | VLIB_CLI_COMMAND (enable_ip6_interface_command, static) = |
| 3616 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3617 | .path = "enable ip6 interface", |
| 3618 | .function = enable_ip6_interface_cmd, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3619 | .short_help = "enable ip6 interface <interface>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3620 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3621 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3622 | |
| 3623 | static clib_error_t * |
| 3624 | disable_ip6_interface_cmd (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3625 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3626 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3627 | vnet_main_t *vnm = vnet_get_main (); |
| 3628 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3629 | u32 sw_if_index; |
| 3630 | |
| 3631 | sw_if_index = ~0; |
| 3632 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3633 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3634 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3635 | error = disable_ip6_interface (vm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3636 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3637 | else |
| 3638 | { |
| 3639 | error = clib_error_return (0, "unknown interface\n'", |
| 3640 | format_unformat_error, input); |
| 3641 | |
| 3642 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3643 | return error; |
| 3644 | } |
| 3645 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3646 | /*? |
| 3647 | * This command is used to disable IPv6 on a given interface. |
| 3648 | * |
| 3649 | * @cliexpar |
| 3650 | * Example of how disable IPv6 on a given interface: |
| 3651 | * @cliexcmd{disable ip6 interface GigabitEthernet2/0/0} |
| 3652 | ?*/ |
| 3653 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3654 | VLIB_CLI_COMMAND (disable_ip6_interface_command, static) = |
| 3655 | { |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3656 | .path = "disable ip6 interface", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3657 | .function = disable_ip6_interface_cmd, |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3658 | .short_help = "disable ip6 interface <interface>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3659 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3660 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3661 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3662 | /*? |
| 3663 | * This command is used to configure the neighbor discovery |
| 3664 | * parameters on a given interface. Use the '<em>show ip6 interface</em>' |
| 3665 | * command to display some of the current neighbor discovery parameters |
| 3666 | * on a given interface. This command has three formats: |
| 3667 | * |
| 3668 | * |
| 3669 | * <b>Format 1 - Router Advertisement Options:</b> (Only one can be entered in a single command) |
| 3670 | * |
| 3671 | * '<em><b>ip6 nd <interface> [no] [ra-managed-config-flag] | [ra-other-config-flag] | [ra-suppress] | [ra-suppress-link-layer] | [ra-send-unicast] | [ra-lifetime <lifetime>] | [ra-initial <cnt> <interval>] | [ra-interval <max-interval> [<min-interval>]] | [ra-cease]</b></em>' |
| 3672 | * |
| 3673 | * Where: |
| 3674 | * |
| 3675 | * <em>[no] ra-managed-config-flag</em> - Advertises in ICMPv6 |
| 3676 | * router-advertisement messages to use stateful address |
| 3677 | * auto-configuration to obtain address information (sets the M-bit). |
| 3678 | * Default is the M-bit is not set and the '<em>no</em>' option |
| 3679 | * returns it to this default state. |
| 3680 | * |
| 3681 | * <em>[no] ra-other-config-flag</em> - Indicates in ICMPv6 |
| 3682 | * router-advertisement messages that hosts use stateful auto |
| 3683 | * configuration to obtain nonaddress related information (sets |
| 3684 | * the O-bit). Default is the O-bit is not set and the '<em>no</em>' |
| 3685 | * option returns it to this default state. |
| 3686 | * |
| 3687 | * <em>[no] ra-suppress</em> - Disables sending ICMPv6 router-advertisement |
| 3688 | * messages. The '<em>no</em>' option implies to enable sending ICMPv6 |
| 3689 | * router-advertisement messages. |
| 3690 | * |
| 3691 | * <em>[no] ra-suppress-link-layer</em> - Indicates not to include the |
| 3692 | * optional source link-layer address in the ICMPv6 router-advertisement |
| 3693 | * messages. Default is to include the optional source link-layer address |
| 3694 | * and the '<em>no</em>' option returns it to this default state. |
| 3695 | * |
| 3696 | * <em>[no] ra-send-unicast</em> - Use the source address of the |
| 3697 | * router-solicitation message if availiable. The default is to use |
| 3698 | * multicast address of all nodes, and the '<em>no</em>' option returns |
| 3699 | * it to this default state. |
| 3700 | * |
| 3701 | * <em>[no] ra-lifetime <lifetime></em> - Advertises the lifetime of a |
| 3702 | * default router in ICMPv6 router-advertisement messages. The range is |
| 3703 | * from 0 to 9000 seconds. '<em><lifetime></em>' must be greater than |
| 3704 | * '<em><max-interval></em>'. The default value is 600 seconds and the |
| 3705 | * '<em>no</em>' option returns it to this default value. |
| 3706 | * |
| 3707 | * <em>[no] ra-initial <cnt> <interval></em> - Number of initial ICMPv6 |
| 3708 | * router-advertisement messages sent and the interval between each |
| 3709 | * message. Range for count is 1 - 3 and default is 3. Range for interval |
| 3710 | * is 1 to 16 seconds, and default is 16 seconds. The '<em>no</em>' option |
| 3711 | * returns both to their default value. |
| 3712 | * |
| 3713 | * <em>[no] ra-interval <max-interval> [<min-interval>]</em> - Configures the |
| 3714 | * interval between sending ICMPv6 router-advertisement messages. The |
| 3715 | * range for max-interval is from 4 to 200 seconds. min-interval can not |
| 3716 | * be more than 75% of max-interval. If not set, min-interval will be |
| 3717 | * set to 75% of max-interval. The range for min-interval is from 3 to |
| 3718 | * 150 seconds. The '<em>no</em>' option returns both to their default |
| 3719 | * value. |
| 3720 | * |
| 3721 | * <em>[no] ra-cease</em> - Cease sending ICMPv6 router-advertisement messages. |
| 3722 | * The '<em>no</em>' options implies to start (or restart) sending |
| 3723 | * ICMPv6 router-advertisement messages. |
| 3724 | * |
| 3725 | * |
| 3726 | * <b>Format 2 - Prefix Options:</b> |
| 3727 | * |
| 3728 | * '<em><b>ip6 nd <interface> [no] prefix <ip6-address>/<width> [<valid-lifetime> <pref-lifetime> | infinite] [no-advertise] [off-link] [no-autoconfig] [no-onlink]</b></em>' |
| 3729 | * |
| 3730 | * Where: |
| 3731 | * |
| 3732 | * <em>no</em> - All additional flags are ignored and the prefix is deleted. |
| 3733 | * |
| 3734 | * <em><valid-lifetime> <pref-lifetime></em> - '<em><valid-lifetime></em>' is the |
| 3735 | * length of time in seconds during what the prefix is valid for the purpose of |
| 3736 | * on-link determination. Range is 7203 to 2592000 seconds and default is 2592000 |
| 3737 | * seconds (30 days). '<em><pref-lifetime></em>' is the prefered-lifetime and is the |
| 3738 | * length of time in seconds during what addresses generated from the prefix remain |
| 3739 | * preferred. Range is 0 to 604800 seconds and default is 604800 seconds (7 days). |
| 3740 | * |
| 3741 | * <em>infinite</em> - Both '<em><valid-lifetime></em>' and '<em><<pref-lifetime></em>' |
| 3742 | * are inifinte, no timeout. |
| 3743 | * |
| 3744 | * <em>no-advertise</em> - Do not send full router address in prefix |
| 3745 | * advertisement. Default is to advertise (i.e. - This flag is off by default). |
| 3746 | * |
| 3747 | * <em>off-link</em> - Prefix is off-link, clear L-bit in packet. Default is on-link |
| 3748 | * (i.e. - This flag is off and L-bit in packet is set by default and this prefix can |
| 3749 | * be used for on-link determination). '<em>no-onlink</em>' also controls the L-bit. |
| 3750 | * |
| 3751 | * <em>no-autoconfig</em> - Do not use prefix for autoconfiguration, clear A-bit in packet. |
| 3752 | * Default is autoconfig (i.e. - This flag is off and A-bit in packet is set by default. |
| 3753 | * |
| 3754 | * <em>no-onlink</em> - Do not use prefix for onlink determination, clear L-bit in packet. |
| 3755 | * Default is on-link (i.e. - This flag is off and L-bit in packet is set by default and |
| 3756 | * this prefix can be used for on-link determination). '<em>off-link</em>' also controls |
| 3757 | * the L-bit. |
| 3758 | * |
| 3759 | * |
| 3760 | * <b>Format 3: - Default of Prefix:</b> |
| 3761 | * |
| 3762 | * '<em><b>ip6 nd <interface> [no] prefix <ip6-address>/<width> default</b></em>' |
| 3763 | * |
| 3764 | * When a new prefix is added (or existing one is being overwritten) <em>default</em> |
| 3765 | * uses default values for the prefix. If <em>no</em> is used, the <em>default</em> |
| 3766 | * is ignored and the prefix is deleted. |
| 3767 | * |
| 3768 | * |
| 3769 | * @cliexpar |
| 3770 | * Example of how set a router advertisement option: |
| 3771 | * @cliexcmd{ip6 nd GigabitEthernet2/0/0 ra-interval 100 20} |
| 3772 | * Example of how to add a prefix: |
| 3773 | * @cliexcmd{ip6 nd GigabitEthernet2/0/0 prefix fe80::fe:28ff:fe9c:75b3/64 infinite no-advertise} |
| 3774 | * Example of how to delete a prefix: |
| 3775 | * @cliexcmd{ip6 nd GigabitEthernet2/0/0 no prefix fe80::fe:28ff:fe9c:75b3/64} |
| 3776 | ?*/ |
| 3777 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3778 | VLIB_CLI_COMMAND (ip6_nd_command, static) = |
| 3779 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3780 | .path = "ip6 nd", |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3781 | .short_help = "ip6 nd <interface> ...", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3782 | .function = ip6_neighbor_cmd, |
| 3783 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3784 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3785 | |
| 3786 | clib_error_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3787 | set_ip6_link_local_address (vlib_main_t * vm, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 3788 | u32 sw_if_index, ip6_address_t * address) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3789 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3790 | clib_error_t *error = 0; |
| 3791 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3792 | u32 ri; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3793 | ip6_radv_t *radv_info; |
| 3794 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3795 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3796 | if (!ip6_address_is_link_local_unicast (address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3797 | { |
| 3798 | vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_LINK_LOCAL; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3799 | return (error = clib_error_return (0, "address not link-local", |
| 3800 | format_unformat_error)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | /* call enable ipv6 */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3804 | enable_ip6_interface (vm, sw_if_index); |
| 3805 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3806 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3807 | |
| 3808 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3809 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3810 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3811 | |
| 3812 | /* save if link local address (overwrite default) */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3813 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3814 | /* delete the old one */ |
| 3815 | error = ip6_add_del_interface_address (vm, sw_if_index, |
| 3816 | &radv_info->link_local_address, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 3817 | 128, 1 /* is_del */ ); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3818 | |
| 3819 | if (!error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3820 | { |
| 3821 | /* add the new one */ |
| 3822 | error = ip6_add_del_interface_address (vm, sw_if_index, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 3823 | address, 128, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3824 | 0 /* is_del */ ); |
| 3825 | |
| 3826 | if (!error) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3827 | { |
| 3828 | radv_info->link_local_address = *address; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3829 | } |
| 3830 | } |
| 3831 | } |
| 3832 | else |
| 3833 | { |
| 3834 | vnm->api_errno = VNET_API_ERROR_IP6_NOT_ENABLED; |
| 3835 | error = clib_error_return (0, "ip6 not enabled for interface", |
| 3836 | format_unformat_error); |
| 3837 | } |
| 3838 | return error; |
| 3839 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3840 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3841 | clib_error_t * |
| 3842 | set_ip6_link_local_address_cmd (vlib_main_t * vm, |
| 3843 | unformat_input_t * input, |
| 3844 | vlib_cli_command_t * cmd) |
| 3845 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3846 | vnet_main_t *vnm = vnet_get_main (); |
| 3847 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3848 | u32 sw_if_index; |
| 3849 | ip6_address_t ip6_addr; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3850 | |
| 3851 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3852 | { |
| 3853 | /* get the rest of the command */ |
| 3854 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 3855 | { |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 3856 | if (unformat (input, "%U", unformat_ip6_address, &ip6_addr)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3857 | break; |
| 3858 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3859 | return (unformat_parse_error (input)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3860 | } |
| 3861 | } |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 3862 | error = set_ip6_link_local_address (vm, sw_if_index, &ip6_addr); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3863 | return error; |
| 3864 | } |
| 3865 | |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3866 | /*? |
| 3867 | * This command is used to assign an IPv6 Link-local address to an |
| 3868 | * interface. This command will enable IPv6 on an interface if it |
| 3869 | * is not already enabled. Use the '<em>show ip6 interface</em>' command |
| 3870 | * to display the assigned Link-local address. |
| 3871 | * |
| 3872 | * @cliexpar |
| 3873 | * Example of how to assign an IPv6 Link-local address to an interface: |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 3874 | * @cliexcmd{set ip6 link-local address GigabitEthernet2/0/0 FE80::AB8} |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3875 | ?*/ |
| 3876 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3877 | VLIB_CLI_COMMAND (set_ip6_link_local_address_command, static) = |
| 3878 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3879 | .path = "set ip6 link-local address", |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 3880 | .short_help = "set ip6 link-local address <interface> <ip6-address>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3881 | .function = set_ip6_link_local_address_cmd, |
| 3882 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 3883 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3884 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 3885 | /** |
| 3886 | * @brief callback when an interface address is added or deleted |
| 3887 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3888 | static void |
| 3889 | ip6_neighbor_add_del_interface_address (ip6_main_t * im, |
| 3890 | uword opaque, |
| 3891 | u32 sw_if_index, |
| 3892 | ip6_address_t * address, |
| 3893 | u32 address_length, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3894 | u32 if_address_index, u32 is_delete) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3895 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3896 | vnet_main_t *vnm = vnet_get_main (); |
| 3897 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3898 | u32 ri; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3899 | vlib_main_t *vm = vnm->vlib_main; |
| 3900 | ip6_radv_t *radv_info; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3901 | ip6_address_t a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3902 | |
| 3903 | /* create solicited node multicast address for this interface adddress */ |
| 3904 | ip6_set_solicited_node_multicast_address (&a, 0); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3905 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3906 | a.as_u8[0xd] = address->as_u8[0xd]; |
| 3907 | a.as_u8[0xe] = address->as_u8[0xe]; |
| 3908 | a.as_u8[0xf] = address->as_u8[0xf]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3909 | |
| 3910 | if (!is_delete) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3911 | { |
| 3912 | /* try to create radv_info - does nothing if ipv6 already enabled */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3913 | enable_ip6_interface (vm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3914 | |
| 3915 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3916 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, |
| 3917 | sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3918 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3919 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3920 | { |
| 3921 | /* get radv_info */ |
| 3922 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 3923 | |
| 3924 | /* add address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3925 | if (!ip6_address_is_link_local_unicast (address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3926 | radv_info->ref_count++; |
| 3927 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 3928 | ip6_neighbor_add_mld_prefix (radv_info, &a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3929 | } |
| 3930 | } |
| 3931 | else |
| 3932 | { |
| 3933 | |
| 3934 | /* delete */ |
| 3935 | /* look up the radv_t information for this interface */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3936 | vec_validate_init_empty (nm->if_radv_pool_index_by_sw_if_index, |
| 3937 | sw_if_index, ~0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3938 | ri = nm->if_radv_pool_index_by_sw_if_index[sw_if_index]; |
Wojciech Dec | 7bc7310 | 2017-02-14 16:24:28 +0100 | [diff] [blame] | 3939 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3940 | if (ri != ~0) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3941 | { |
| 3942 | /* get radv_info */ |
| 3943 | radv_info = pool_elt_at_index (nm->if_radv_pool, ri); |
| 3944 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 3945 | ip6_neighbor_del_mld_prefix (radv_info, &a); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3946 | |
| 3947 | /* if interface up send MLDP "report" */ |
| 3948 | radv_info->all_routers_mcast = 0; |
| 3949 | |
| 3950 | /* add address */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3951 | if (!ip6_address_is_link_local_unicast (address)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3952 | radv_info->ref_count--; |
| 3953 | } |
Wojciech Dec | 7bc7310 | 2017-02-14 16:24:28 +0100 | [diff] [blame] | 3954 | /* Ensure that IPv6 is disabled, and LL removed after ref_count reaches 0 */ |
| 3955 | disable_ip6_interface (vm, sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3956 | } |
| 3957 | } |
| 3958 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3959 | clib_error_t * |
| 3960 | ip6_set_neighbor_limit (u32 neighbor_limit) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3961 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3962 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3963 | |
| 3964 | nm->limit_neighbor_cache_size = neighbor_limit; |
| 3965 | return 0; |
| 3966 | } |
| 3967 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 3968 | static void |
| 3969 | ip6_neighbor_table_bind (ip6_main_t * im, |
| 3970 | uword opaque, |
| 3971 | u32 sw_if_index, |
| 3972 | u32 new_fib_index, u32 old_fib_index) |
| 3973 | { |
| 3974 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3975 | ip6_neighbor_t *n = NULL; |
| 3976 | u32 i, *to_re_add = 0; |
| 3977 | |
| 3978 | /* *INDENT-OFF* */ |
| 3979 | pool_foreach (n, nm->neighbor_pool, |
| 3980 | ({ |
| 3981 | if (n->key.sw_if_index == sw_if_index) |
| 3982 | vec_add1 (to_re_add, n - nm->neighbor_pool); |
| 3983 | })); |
| 3984 | /* *INDENT-ON* */ |
| 3985 | |
| 3986 | for (i = 0; i < vec_len (to_re_add); i++) |
| 3987 | { |
| 3988 | n = pool_elt_at_index (nm->neighbor_pool, to_re_add[i]); |
| 3989 | ip6_neighbor_adj_fib_remove (n, old_fib_index); |
| 3990 | ip6_neighbor_adj_fib_add (n, new_fib_index); |
| 3991 | } |
| 3992 | vec_free (to_re_add); |
| 3993 | } |
| 3994 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3995 | static clib_error_t * |
| 3996 | ip6_neighbor_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3997 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 3998 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 3999 | ip6_main_t *im = &ip6_main; |
| 4000 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4001 | mhash_init (&nm->neighbor_index_by_key, |
| 4002 | /* value size */ sizeof (uword), |
| 4003 | /* key size */ sizeof (ip6_neighbor_key_t)); |
| 4004 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4005 | icmp6_register_type (vm, ICMP6_neighbor_solicitation, |
| 4006 | ip6_icmp_neighbor_solicitation_node.index); |
| 4007 | icmp6_register_type (vm, ICMP6_neighbor_advertisement, |
| 4008 | ip6_icmp_neighbor_advertisement_node.index); |
| 4009 | icmp6_register_type (vm, ICMP6_router_solicitation, |
| 4010 | ip6_icmp_router_solicitation_node.index); |
| 4011 | icmp6_register_type (vm, ICMP6_router_advertisement, |
| 4012 | ip6_icmp_router_advertisement_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4013 | |
| 4014 | /* handler node for ip6 neighbor discovery events and timers */ |
| 4015 | vlib_register_node (vm, &ip6_icmp_neighbor_discovery_event_node); |
| 4016 | |
| 4017 | /* add call backs */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4018 | ip6_add_del_interface_address_callback_t cb; |
| 4019 | memset (&cb, 0x0, sizeof (ip6_add_del_interface_address_callback_t)); |
| 4020 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4021 | /* when an interface address changes... */ |
| 4022 | cb.function = ip6_neighbor_add_del_interface_address; |
| 4023 | cb.function_opaque = 0; |
| 4024 | vec_add1 (im->add_del_interface_address_callbacks, cb); |
| 4025 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 4026 | ip6_table_bind_callback_t cbt; |
| 4027 | cbt.function = ip6_neighbor_table_bind; |
| 4028 | cbt.function_opaque = 0; |
| 4029 | vec_add1 (im->table_bind_callbacks, cbt); |
| 4030 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4031 | mhash_init (&nm->pending_resolutions_by_address, |
| 4032 | /* value size */ sizeof (uword), |
| 4033 | /* key size */ sizeof (ip6_address_t)); |
| 4034 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4035 | mhash_init (&nm->mac_changes_by_address, |
| 4036 | /* value size */ sizeof (uword), |
| 4037 | /* key size */ sizeof (ip6_address_t)); |
| 4038 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4039 | /* default, configurable */ |
| 4040 | nm->limit_neighbor_cache_size = 50000; |
| 4041 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 4042 | nm->wc_ip6_nd_publisher_node = (uword) ~ 0; |
| 4043 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4044 | #if 0 |
| 4045 | /* $$$$ Hack fix for today */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4046 | vec_validate_init_empty |
| 4047 | (im->discover_neighbor_next_index_by_hw_if_index, 32, 0 /* drop */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4048 | #endif |
| 4049 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4050 | return 0; |
| 4051 | } |
| 4052 | |
| 4053 | VLIB_INIT_FUNCTION (ip6_neighbor_init); |
| 4054 | |
| 4055 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4056 | void |
| 4057 | vnet_register_ip6_neighbor_resolution_event (vnet_main_t * vnm, |
| 4058 | void *address_arg, |
| 4059 | uword node_index, |
| 4060 | uword type_opaque, uword data) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4061 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4062 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4063 | ip6_address_t *address = address_arg; |
| 4064 | uword *p; |
| 4065 | pending_resolution_t *pr; |
| 4066 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4067 | pool_get (nm->pending_resolutions, pr); |
| 4068 | |
| 4069 | pr->next_index = ~0; |
| 4070 | pr->node_index = node_index; |
| 4071 | pr->type_opaque = type_opaque; |
| 4072 | pr->data = data; |
| 4073 | |
| 4074 | p = mhash_get (&nm->pending_resolutions_by_address, address); |
| 4075 | if (p) |
| 4076 | { |
| 4077 | /* Insert new resolution at the head of the list */ |
| 4078 | pr->next_index = p[0]; |
| 4079 | mhash_unset (&nm->pending_resolutions_by_address, address, 0); |
| 4080 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4081 | |
| 4082 | mhash_set (&nm->pending_resolutions_by_address, address, |
| 4083 | pr - nm->pending_resolutions, 0 /* old value */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 4084 | } |
| 4085 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4086 | int |
| 4087 | vnet_add_del_ip6_nd_change_event (vnet_main_t * vnm, |
| 4088 | void *data_callback, |
| 4089 | u32 pid, |
| 4090 | void *address_arg, |
| 4091 | uword node_index, |
| 4092 | uword type_opaque, uword data, int is_add) |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4093 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4094 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4095 | ip6_address_t *address = address_arg; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4096 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4097 | /* Try to find an existing entry */ |
| 4098 | u32 *first = (u32 *) mhash_get (&nm->mac_changes_by_address, address); |
| 4099 | u32 *p = first; |
| 4100 | pending_resolution_t *mc; |
| 4101 | while (p && *p != ~0) |
| 4102 | { |
| 4103 | mc = pool_elt_at_index (nm->mac_changes, *p); |
| 4104 | if (mc->node_index == node_index && mc->type_opaque == type_opaque |
| 4105 | && mc->pid == pid) |
| 4106 | break; |
| 4107 | p = &mc->next_index; |
| 4108 | } |
| 4109 | |
| 4110 | int found = p && *p != ~0; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4111 | if (is_add) |
| 4112 | { |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4113 | if (found) |
| 4114 | return VNET_API_ERROR_ENTRY_ALREADY_EXISTS; |
| 4115 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4116 | pool_get (nm->mac_changes, mc); |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4117 | *mc = (pending_resolution_t) |
| 4118 | { |
| 4119 | .next_index = ~0,.node_index = node_index,.type_opaque = |
| 4120 | type_opaque,.data = data,.data_callback = data_callback,.pid = |
| 4121 | pid,}; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4122 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4123 | /* Insert new resolution at the end of the list */ |
| 4124 | u32 new_idx = mc - nm->mac_changes; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4125 | if (p) |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4126 | p[0] = new_idx; |
| 4127 | else |
| 4128 | mhash_set (&nm->mac_changes_by_address, address, new_idx, 0); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4129 | } |
| 4130 | else |
| 4131 | { |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4132 | if (!found) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4133 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4134 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4135 | /* Clients may need to clean up pool entries, too */ |
| 4136 | void (*fp) (u32, u8 *) = data_callback; |
| 4137 | if (fp) |
| 4138 | (*fp) (mc->data, 0 /* no new mac addrs */ ); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4139 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4140 | /* Remove the entry from the list and delete the entry */ |
| 4141 | *p = mc->next_index; |
| 4142 | pool_put (nm->mac_changes, mc); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4143 | |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4144 | /* Remove from hash if we deleted the last entry */ |
| 4145 | if (*p == ~0 && p == first) |
| 4146 | mhash_unset (&nm->mac_changes_by_address, address, 0); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4147 | } |
Eyal Bari | f9f4065 | 2017-04-01 03:55:08 +0300 | [diff] [blame] | 4148 | return 0; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4149 | } |
| 4150 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4151 | int |
| 4152 | vnet_ip6_nd_term (vlib_main_t * vm, |
| 4153 | vlib_node_runtime_t * node, |
| 4154 | vlib_buffer_t * p0, |
| 4155 | ethernet_header_t * eth, |
Eyal Bari | a0623f8 | 2017-03-30 03:05:06 +0300 | [diff] [blame] | 4156 | ip6_header_t * ip, u32 sw_if_index, u16 bd_index) |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4157 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4158 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4159 | icmp6_neighbor_solicitation_or_advertisement_header_t *ndh; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4160 | |
| 4161 | ndh = ip6_next_header (ip); |
| 4162 | if (ndh->icmp.type != ICMP6_neighbor_solicitation && |
| 4163 | ndh->icmp.type != ICMP6_neighbor_advertisement) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4164 | return 0; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4165 | |
| 4166 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 4167 | (p0->flags & VLIB_BUFFER_IS_TRACED))) |
| 4168 | { |
| 4169 | u8 *t0 = vlib_add_trace (vm, node, p0, |
| 4170 | sizeof (icmp6_input_trace_t)); |
| 4171 | clib_memcpy (t0, ip, sizeof (icmp6_input_trace_t)); |
| 4172 | } |
| 4173 | |
| 4174 | /* Check if anyone want ND events for L2 BDs */ |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 4175 | if (PREDICT_FALSE |
| 4176 | (nm->wc_ip6_nd_publisher_node != (uword) ~ 0 |
| 4177 | && !ip6_address_is_link_local_unicast (&ip->src_address))) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4178 | { |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 4179 | vnet_nd_wc_publish (sw_if_index, eth->src_address, &ip->src_address); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | /* Check if MAC entry exsist for solicited target IP */ |
| 4183 | if (ndh->icmp.type == ICMP6_neighbor_solicitation) |
| 4184 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4185 | icmp6_neighbor_discovery_ethernet_link_layer_address_option_t *opt; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4186 | l2_bridge_domain_t *bd_config; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4187 | u8 *macp; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4188 | |
| 4189 | opt = (void *) (ndh + 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4190 | if ((opt->header.type != |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4191 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_source_link_layer_address) || |
| 4192 | (opt->header.n_data_u64s != 1)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4193 | return 0; /* source link layer address option not present */ |
| 4194 | |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4195 | bd_config = vec_elt_at_index (l2input_main.bd_configs, bd_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4196 | macp = |
| 4197 | (u8 *) hash_get_mem (bd_config->mac_by_ip6, &ndh->target_address); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4198 | if (macp) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4199 | { /* found ip-mac entry, generate eighbor advertisement response */ |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4200 | int bogus_length; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4201 | vlib_node_runtime_t *error_node = |
| 4202 | vlib_node_get_runtime (vm, ip6_icmp_input_node.index); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4203 | ip->dst_address = ip->src_address; |
| 4204 | ip->src_address = ndh->target_address; |
| 4205 | ip->hop_limit = 255; |
| 4206 | opt->header.type = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4207 | ICMP6_NEIGHBOR_DISCOVERY_OPTION_target_link_layer_address; |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4208 | clib_memcpy (opt->ethernet_address, macp, 6); |
| 4209 | ndh->icmp.type = ICMP6_neighbor_advertisement; |
| 4210 | ndh->advertisement_flags = clib_host_to_net_u32 |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4211 | (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED | |
| 4212 | ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE); |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4213 | ndh->icmp.checksum = 0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4214 | ndh->icmp.checksum = |
| 4215 | ip6_tcp_udp_icmp_compute_checksum (vm, p0, ip, &bogus_length); |
| 4216 | clib_memcpy (eth->dst_address, eth->src_address, 6); |
| 4217 | clib_memcpy (eth->src_address, macp, 6); |
| 4218 | vlib_error_count (vm, error_node->node_index, |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4219 | ICMP6_ERROR_NEIGHBOR_ADVERTISEMENTS_TX, 1); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4220 | return 1; |
| 4221 | } |
John Lo | 1edfba9 | 2016-08-27 01:11:57 -0400 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | return 0; |
| 4225 | |
| 4226 | } |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4227 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 4228 | int |
| 4229 | ip6_neighbor_proxy_add_del (u32 sw_if_index, ip6_address_t * addr, u8 is_del) |
| 4230 | { |
| 4231 | u32 fib_index; |
| 4232 | |
| 4233 | fib_prefix_t pfx = { |
| 4234 | .fp_len = 128, |
| 4235 | .fp_proto = FIB_PROTOCOL_IP6, |
| 4236 | .fp_addr = { |
| 4237 | .ip6 = *addr, |
| 4238 | }, |
| 4239 | }; |
| 4240 | ip46_address_t nh = { |
| 4241 | .ip6 = *addr, |
| 4242 | }; |
| 4243 | |
| 4244 | fib_index = ip6_fib_table_get_index_for_sw_if_index (sw_if_index); |
| 4245 | |
| 4246 | if (~0 == fib_index) |
| 4247 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 4248 | |
| 4249 | if (is_del) |
| 4250 | { |
| 4251 | fib_table_entry_path_remove (fib_index, |
| 4252 | &pfx, |
| 4253 | FIB_SOURCE_IP6_ND_PROXY, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4254 | DPO_PROTO_IP6, |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 4255 | &nh, |
| 4256 | sw_if_index, |
| 4257 | ~0, 1, FIB_ROUTE_PATH_FLAG_NONE); |
| 4258 | /* flush the ND cache of this address if it's there */ |
| 4259 | vnet_unset_ip6_ethernet_neighbor (vlib_get_main (), |
| 4260 | sw_if_index, addr, NULL, 0); |
| 4261 | } |
| 4262 | else |
| 4263 | { |
| 4264 | fib_table_entry_path_add (fib_index, |
| 4265 | &pfx, |
| 4266 | FIB_SOURCE_IP6_ND_PROXY, |
| 4267 | FIB_ENTRY_FLAG_NONE, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 4268 | DPO_PROTO_IP6, |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 4269 | &nh, |
| 4270 | sw_if_index, |
| 4271 | ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE); |
| 4272 | } |
| 4273 | return (0); |
| 4274 | } |
| 4275 | |
| 4276 | static clib_error_t * |
| 4277 | set_ip6_nd_proxy_cmd (vlib_main_t * vm, |
| 4278 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 4279 | { |
| 4280 | vnet_main_t *vnm = vnet_get_main (); |
| 4281 | clib_error_t *error = 0; |
| 4282 | ip6_address_t addr; |
| 4283 | u32 sw_if_index; |
| 4284 | u8 is_del = 0; |
| 4285 | |
| 4286 | if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 4287 | { |
| 4288 | /* get the rest of the command */ |
| 4289 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 4290 | { |
| 4291 | if (unformat (input, "%U", unformat_ip6_address, &addr)) |
| 4292 | break; |
| 4293 | else if (unformat (input, "delete") || unformat (input, "del")) |
| 4294 | is_del = 1; |
| 4295 | else |
| 4296 | return (unformat_parse_error (input)); |
| 4297 | } |
| 4298 | } |
| 4299 | |
| 4300 | ip6_neighbor_proxy_add_del (sw_if_index, &addr, is_del); |
| 4301 | |
| 4302 | return error; |
| 4303 | } |
| 4304 | |
| 4305 | /* *INDENT-OFF* */ |
| 4306 | VLIB_CLI_COMMAND (set_ip6_nd_proxy_command, static) = |
| 4307 | { |
| 4308 | .path = "set ip6 nd proxy", |
| 4309 | .short_help = "set ip6 nd proxy <HOST> <INTERFACE>", |
| 4310 | .function = set_ip6_nd_proxy_cmd, |
| 4311 | }; |
| 4312 | /* *INDENT-ON* */ |
| 4313 | |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4314 | void |
Neale Ranns | 3be6b28 | 2016-12-20 14:24:01 +0000 | [diff] [blame] | 4315 | ethernet_ndp_change_mac (u32 sw_if_index) |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4316 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4317 | ip6_neighbor_main_t *nm = &ip6_neighbor_main; |
| 4318 | ip6_neighbor_t *n; |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 4319 | adj_index_t ai; |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4320 | |
| 4321 | /* *INDENT-OFF* */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4322 | pool_foreach (n, nm->neighbor_pool, |
| 4323 | ({ |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4324 | if (n->key.sw_if_index == sw_if_index) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4325 | { |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 4326 | adj_nbr_walk_nh6 (sw_if_index, |
| 4327 | &n->key.ip6_address, |
| 4328 | ip6_nd_mk_complete_walk, n); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4329 | } |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4330 | })); |
| 4331 | /* *INDENT-ON* */ |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 4332 | |
| 4333 | ai = adj_glean_get (FIB_PROTOCOL_IP6, sw_if_index); |
| 4334 | |
| 4335 | if (ADJ_INDEX_INVALID != ai) |
| 4336 | adj_glean_update_rewrite (ai); |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 4337 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4338 | |
John Lo | 8b81cb4 | 2017-06-26 01:40:20 -0400 | [diff] [blame] | 4339 | void |
| 4340 | send_ip6_na (vlib_main_t * vm, vnet_hw_interface_t * hi) |
| 4341 | { |
| 4342 | ip6_main_t *i6m = &ip6_main; |
| 4343 | u32 sw_if_index = hi->sw_if_index; |
| 4344 | ip6_address_t *ip6_addr = ip6_interface_first_address (i6m, sw_if_index); |
| 4345 | if (ip6_addr) |
| 4346 | { |
| 4347 | clib_warning |
| 4348 | ("Sending unsolicitated NA IP6 address %U on sw_if_idex %d", |
| 4349 | format_ip6_address, ip6_addr, sw_if_index); |
| 4350 | |
| 4351 | /* Form unsolicited neighbor advertisement packet from NS pkt template */ |
| 4352 | int bogus_length; |
| 4353 | u32 bi = 0; |
| 4354 | icmp6_neighbor_solicitation_header_t *h = |
| 4355 | vlib_packet_template_get_packet (vm, |
| 4356 | &i6m->discover_neighbor_packet_template, |
| 4357 | &bi); |
| 4358 | ip6_set_reserved_multicast_address (&h->ip.dst_address, |
| 4359 | IP6_MULTICAST_SCOPE_link_local, |
| 4360 | IP6_MULTICAST_GROUP_ID_all_hosts); |
| 4361 | h->ip.src_address = ip6_addr[0]; |
| 4362 | h->neighbor.icmp.type = ICMP6_neighbor_advertisement; |
| 4363 | h->neighbor.target_address = ip6_addr[0]; |
| 4364 | h->neighbor.advertisement_flags = clib_host_to_net_u32 |
| 4365 | (ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE); |
| 4366 | clib_memcpy (h->link_layer_option.ethernet_address, |
| 4367 | hi->hw_address, vec_len (hi->hw_address)); |
| 4368 | h->neighbor.icmp.checksum = |
| 4369 | ip6_tcp_udp_icmp_compute_checksum (vm, 0, &h->ip, &bogus_length); |
| 4370 | ASSERT (bogus_length == 0); |
| 4371 | |
| 4372 | /* Setup MAC header with IP6 Etype and mcast DMAC */ |
| 4373 | vlib_buffer_t *b = vlib_get_buffer (vm, bi); |
| 4374 | vlib_buffer_advance (b, -sizeof (ethernet_header_t)); |
| 4375 | ethernet_header_t *e = vlib_buffer_get_current (b); |
| 4376 | e->type = clib_host_to_net_u16 (ETHERNET_TYPE_IP6); |
| 4377 | clib_memcpy (e->src_address, hi->hw_address, sizeof (e->src_address)); |
| 4378 | ip6_multicast_ethernet_address (e->dst_address, |
| 4379 | IP6_MULTICAST_GROUP_ID_all_hosts); |
| 4380 | |
| 4381 | /* Send unsolicited ND advertisement packet out the specified interface */ |
| 4382 | vnet_buffer (b)->sw_if_index[VLIB_RX] = |
| 4383 | vnet_buffer (b)->sw_if_index[VLIB_TX] = sw_if_index; |
| 4384 | vlib_frame_t *f = vlib_get_frame_to_node (vm, hi->output_node_index); |
| 4385 | u32 *to_next = vlib_frame_vector_args (f); |
| 4386 | to_next[0] = bi; |
| 4387 | f->n_vectors = 1; |
| 4388 | vlib_put_frame_to_node (vm, hi->output_node_index, f); |
| 4389 | } |
| 4390 | } |
| 4391 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 4392 | /* |
| 4393 | * fd.io coding-style-patch-verification: ON |
| 4394 | * |
| 4395 | * Local Variables: |
| 4396 | * eval: (c-set-style "gnu") |
| 4397 | * End: |
| 4398 | */ |