Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * ip_api.c - vnet ip api |
| 4 | * |
| 5 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at: |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | *------------------------------------------------------------------ |
| 18 | */ |
| 19 | |
| 20 | #include <vnet/vnet.h> |
| 21 | #include <vlibmemory/api.h> |
| 22 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 23 | #include <vpp/stats/stats.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 24 | #include <vnet/interface.h> |
| 25 | #include <vnet/api_errno.h> |
| 26 | #include <vnet/ethernet/ethernet.h> |
| 27 | #include <vnet/ip/ip.h> |
| 28 | #include <vnet/ip/ip6_neighbor.h> |
| 29 | #include <vnet/fib/fib_table.h> |
| 30 | #include <vnet/fib/fib_api.h> |
| 31 | #include <vnet/dpo/drop_dpo.h> |
| 32 | #include <vnet/dpo/receive_dpo.h> |
| 33 | #include <vnet/dpo/lookup_dpo.h> |
| 34 | #include <vnet/dpo/classify_dpo.h> |
| 35 | #include <vnet/dpo/ip_null_dpo.h> |
| 36 | #include <vnet/ethernet/arp_packet.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 37 | #include <vnet/mfib/ip6_mfib.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 38 | #include <vnet/mfib/ip4_mfib.h> |
| 39 | #include <vnet/mfib/mfib_signal.h> |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 40 | #include <vnet/mfib/mfib_entry.h> |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 41 | #include <vnet/ip/ip_source_and_port_range_check.h> |
| 42 | #include <vnet/fib/ip4_fib.h> |
| 43 | #include <vnet/fib/ip6_fib.h> |
| 44 | #include <vnet/ip/ip6_hop_by_hop.h> |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 45 | #include <vnet/ip/ip4_reassembly.h> |
| 46 | #include <vnet/ip/ip6_reassembly.h> |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 47 | |
| 48 | #include <vnet/vnet_msg_enum.h> |
| 49 | |
| 50 | #define vl_typedefs /* define message structures */ |
| 51 | #include <vnet/vnet_all_api_h.h> |
| 52 | #undef vl_typedefs |
| 53 | |
| 54 | #define vl_endianfun /* define message structures */ |
| 55 | #include <vnet/vnet_all_api_h.h> |
| 56 | #undef vl_endianfun |
| 57 | |
| 58 | /* instantiate all the print functions we know about */ |
| 59 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 60 | #define vl_printfun |
| 61 | #include <vnet/vnet_all_api_h.h> |
| 62 | #undef vl_printfun |
| 63 | |
| 64 | #include <vlibapi/api_helper_macros.h> |
| 65 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 66 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 67 | #define foreach_ip_api_msg \ |
| 68 | _(IP_FIB_DUMP, ip_fib_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 69 | _(IP6_FIB_DUMP, ip6_fib_dump) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 70 | _(IP_MFIB_DUMP, ip_mfib_dump) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 71 | _(IP6_MFIB_DUMP, ip6_mfib_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 72 | _(IP_NEIGHBOR_DUMP, ip_neighbor_dump) \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 73 | _(IP_MROUTE_ADD_DEL, ip_mroute_add_del) \ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 74 | _(MFIB_SIGNAL_DUMP, mfib_signal_dump) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 75 | _(IP_ADDRESS_DUMP, ip_address_dump) \ |
| 76 | _(IP_DUMP, ip_dump) \ |
| 77 | _(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 78 | _(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit) \ |
John Lo | c7b4304 | 2018-04-13 16:46:22 -0400 | [diff] [blame] | 79 | _(IP_PROBE_NEIGHBOR, ip_probe_neighbor) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 80 | _(WANT_IP4_ARP_EVENTS, want_ip4_arp_events) \ |
| 81 | _(WANT_IP6_ND_EVENTS, want_ip6_nd_events) \ |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 82 | _(WANT_IP6_RA_EVENTS, want_ip6_ra_events) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 83 | _(PROXY_ARP_ADD_DEL, proxy_arp_add_del) \ |
| 84 | _(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable) \ |
| 85 | _(RESET_FIB, reset_fib) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 86 | _(IP_ADD_DEL_ROUTE, ip_add_del_route) \ |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 87 | _(IP_TABLE_ADD_DEL, ip_table_add_del) \ |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 88 | _(IP_PUNT_POLICE, ip_punt_police) \ |
| 89 | _(IP_PUNT_REDIRECT, ip_punt_redirect) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 90 | _(SET_IP_FLOW_HASH,set_ip_flow_hash) \ |
| 91 | _(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config) \ |
| 92 | _(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix) \ |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 93 | _(IP6ND_PROXY_ADD_DEL, ip6nd_proxy_add_del) \ |
| 94 | _(IP6ND_PROXY_DUMP, ip6nd_proxy_dump) \ |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 95 | _(IP6ND_SEND_ROUTER_SOLICITATION, ip6nd_send_router_solicitation) \ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 96 | _(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable ) \ |
| 97 | _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \ |
Florin Coras | 595992c | 2017-11-06 17:17:08 -0800 | [diff] [blame] | 98 | sw_interface_ip6_set_link_local_address) \ |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 99 | _(IP_CONTAINER_PROXY_ADD_DEL, ip_container_proxy_add_del) \ |
| 100 | _(IOAM_ENABLE, ioam_enable) \ |
| 101 | _(IOAM_DISABLE, ioam_disable) \ |
| 102 | _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, \ |
| 103 | ip_source_and_port_range_check_add_del) \ |
| 104 | _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, \ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 105 | ip_source_and_port_range_check_interface_add_del) \ |
| 106 | _(IP_REASSEMBLY_SET, ip_reassembly_set) \ |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 107 | _(IP_REASSEMBLY_GET, ip_reassembly_get) \ |
| 108 | _(IP_REASSEMBLY_ENABLE_DISABLE, ip_reassembly_enable_disable) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 109 | |
| 110 | extern void stats_dslock_with_hint (int hint, int tag); |
| 111 | extern void stats_dsunlock (void); |
| 112 | |
| 113 | static void |
Jon Loeliger | af8dfbf | 2017-11-08 13:07:39 -0600 | [diff] [blame] | 114 | send_ip_neighbor_details (u32 sw_if_index, |
| 115 | u8 is_ipv6, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 116 | u8 is_static, |
| 117 | u8 * mac_address, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 118 | u8 * ip_address, vl_api_registration_t * reg, |
| 119 | u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 120 | { |
| 121 | vl_api_ip_neighbor_details_t *mp; |
| 122 | |
| 123 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 124 | memset (mp, 0, sizeof (*mp)); |
| 125 | mp->_vl_msg_id = ntohs (VL_API_IP_NEIGHBOR_DETAILS); |
| 126 | mp->context = context; |
Jon Loeliger | af8dfbf | 2017-11-08 13:07:39 -0600 | [diff] [blame] | 127 | mp->sw_if_index = htonl (sw_if_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 128 | mp->is_ipv6 = is_ipv6; |
| 129 | mp->is_static = is_static; |
| 130 | memcpy (mp->mac_address, mac_address, 6); |
| 131 | memcpy (mp->ip_address, ip_address, (is_ipv6) ? 16 : 4); |
| 132 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 133 | vl_api_send_msg (reg, (u8 *) mp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 137 | vl_api_ip_neighbor_dump_t_handler (vl_api_ip_neighbor_dump_t * mp) |
| 138 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 139 | vl_api_registration_t *reg; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 140 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 141 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 142 | if (!reg) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 143 | return; |
| 144 | |
| 145 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 146 | |
| 147 | if (mp->is_ipv6) |
| 148 | { |
| 149 | ip6_neighbor_t *n, *ns; |
| 150 | |
| 151 | ns = ip6_neighbors_entries (sw_if_index); |
| 152 | /* *INDENT-OFF* */ |
| 153 | vec_foreach (n, ns) |
| 154 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 155 | send_ip_neighbor_details |
Jon Loeliger | af8dfbf | 2017-11-08 13:07:39 -0600 | [diff] [blame] | 156 | (sw_if_index, mp->is_ipv6, |
| 157 | ((n->flags & IP6_NEIGHBOR_FLAG_STATIC) ? 1 : 0), |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 158 | (u8 *) n->link_layer_address, |
| 159 | (u8 *) & (n->key.ip6_address.as_u8), |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 160 | reg, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 161 | } |
| 162 | /* *INDENT-ON* */ |
| 163 | vec_free (ns); |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | ethernet_arp_ip4_entry_t *n, *ns; |
| 168 | |
| 169 | ns = ip4_neighbor_entries (sw_if_index); |
| 170 | /* *INDENT-OFF* */ |
| 171 | vec_foreach (n, ns) |
| 172 | { |
Jon Loeliger | af8dfbf | 2017-11-08 13:07:39 -0600 | [diff] [blame] | 173 | send_ip_neighbor_details (sw_if_index, mp->is_ipv6, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 174 | ((n->flags & ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC) ? 1 : 0), |
| 175 | (u8*) n->ethernet_address, |
| 176 | (u8*) & (n->ip4_address.as_u8), |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 177 | reg, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 178 | } |
| 179 | /* *INDENT-ON* */ |
| 180 | vec_free (ns); |
| 181 | } |
| 182 | } |
| 183 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 184 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 185 | send_ip_fib_details (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 186 | vl_api_registration_t * reg, |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 187 | const fib_table_t * table, |
| 188 | const fib_prefix_t * pfx, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 189 | fib_route_path_encode_t * api_rpaths, u32 context) |
| 190 | { |
| 191 | vl_api_ip_fib_details_t *mp; |
| 192 | fib_route_path_encode_t *api_rpath; |
| 193 | vl_api_fib_path_t *fp; |
| 194 | int path_count; |
| 195 | |
| 196 | path_count = vec_len (api_rpaths); |
| 197 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 198 | if (!mp) |
| 199 | return; |
| 200 | memset (mp, 0, sizeof (*mp)); |
| 201 | mp->_vl_msg_id = ntohs (VL_API_IP_FIB_DETAILS); |
| 202 | mp->context = context; |
| 203 | |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 204 | mp->table_id = htonl (table->ft_table_id); |
| 205 | memcpy (mp->table_name, table->ft_desc, |
| 206 | clib_min (vec_len (table->ft_desc), sizeof (mp->table_name))); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 207 | mp->address_length = pfx->fp_len; |
| 208 | memcpy (mp->address, &pfx->fp_addr.ip4, sizeof (pfx->fp_addr.ip4)); |
| 209 | |
| 210 | mp->count = htonl (path_count); |
| 211 | fp = mp->path; |
| 212 | vec_foreach (api_rpath, api_rpaths) |
| 213 | { |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 214 | fib_api_path_encode (api_rpath, fp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 215 | fp++; |
| 216 | } |
| 217 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 218 | vl_api_send_msg (reg, (u8 *) mp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 219 | } |
| 220 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 221 | typedef struct vl_api_ip_fib_dump_walk_ctx_t_ |
| 222 | { |
| 223 | fib_node_index_t *feis; |
| 224 | } vl_api_ip_fib_dump_walk_ctx_t; |
| 225 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 226 | static fib_table_walk_rc_t |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 227 | vl_api_ip_fib_dump_walk (fib_node_index_t fei, void *arg) |
| 228 | { |
| 229 | vl_api_ip_fib_dump_walk_ctx_t *ctx = arg; |
| 230 | |
| 231 | vec_add1 (ctx->feis, fei); |
| 232 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 233 | return (FIB_TABLE_WALK_CONTINUE); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 236 | static void |
| 237 | vl_api_ip_fib_dump_t_handler (vl_api_ip_fib_dump_t * mp) |
| 238 | { |
| 239 | vpe_api_main_t *am = &vpe_api_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 240 | vl_api_registration_t *reg; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 241 | ip4_main_t *im = &ip4_main; |
| 242 | fib_table_t *fib_table; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 243 | fib_node_index_t *lfeip; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 244 | fib_prefix_t pfx; |
| 245 | u32 fib_index; |
| 246 | fib_route_path_encode_t *api_rpaths; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 247 | vl_api_ip_fib_dump_walk_ctx_t ctx = { |
| 248 | .feis = NULL, |
| 249 | }; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 250 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 251 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 252 | if (!reg) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 253 | return; |
| 254 | |
| 255 | /* *INDENT-OFF* */ |
| 256 | pool_foreach (fib_table, im->fibs, |
| 257 | ({ |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 258 | fib_table_walk(fib_table->ft_index, |
| 259 | FIB_PROTOCOL_IP4, |
| 260 | vl_api_ip_fib_dump_walk, |
| 261 | &ctx); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 262 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 263 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 264 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 265 | vec_sort_with_function (ctx.feis, fib_entry_cmp_for_sort); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 266 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 267 | vec_foreach (lfeip, ctx.feis) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 268 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 269 | fib_entry_get_prefix (*lfeip, &pfx); |
| 270 | fib_index = fib_entry_get_fib_index (*lfeip); |
| 271 | fib_table = fib_table_get (fib_index, pfx.fp_proto); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 272 | api_rpaths = NULL; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 273 | fib_entry_encode (*lfeip, &api_rpaths); |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 274 | send_ip_fib_details (am, reg, fib_table, &pfx, api_rpaths, mp->context); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 275 | vec_free (api_rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 276 | } |
| 277 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 278 | vec_free (ctx.feis); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 282 | send_ip6_fib_details (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 283 | vl_api_registration_t * reg, |
Neale Ranns | a161a6d | 2017-11-14 08:10:41 -0800 | [diff] [blame] | 284 | const fib_table_t * table, |
| 285 | const fib_prefix_t * pfx, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 286 | fib_route_path_encode_t * api_rpaths, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 287 | { |
| 288 | vl_api_ip6_fib_details_t *mp; |
| 289 | fib_route_path_encode_t *api_rpath; |
| 290 | vl_api_fib_path_t *fp; |
| 291 | int path_count; |
| 292 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 293 | path_count = vec_len (api_rpaths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 294 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 295 | if (!mp) |
| 296 | return; |
| 297 | memset (mp, 0, sizeof (*mp)); |
| 298 | mp->_vl_msg_id = ntohs (VL_API_IP6_FIB_DETAILS); |
| 299 | mp->context = context; |
| 300 | |
Neale Ranns | a161a6d | 2017-11-14 08:10:41 -0800 | [diff] [blame] | 301 | mp->table_id = htonl (table->ft_table_id); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 302 | mp->address_length = pfx->fp_len; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 303 | memcpy (mp->address, &pfx->fp_addr.ip6, sizeof (pfx->fp_addr.ip6)); |
Neale Ranns | a161a6d | 2017-11-14 08:10:41 -0800 | [diff] [blame] | 304 | memcpy (mp->table_name, table->ft_desc, |
| 305 | clib_min (vec_len (table->ft_desc), sizeof (mp->table_name))); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 306 | |
| 307 | mp->count = htonl (path_count); |
| 308 | fp = mp->path; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 309 | vec_foreach (api_rpath, api_rpaths) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 310 | { |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 311 | fib_api_path_encode (api_rpath, fp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 312 | fp++; |
| 313 | } |
| 314 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 315 | vl_api_send_msg (reg, (u8 *) mp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 316 | } |
| 317 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 318 | typedef struct apt_ip6_fib_show_ctx_t_ |
| 319 | { |
| 320 | u32 fib_index; |
| 321 | fib_node_index_t *entries; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 322 | } api_ip6_fib_show_ctx_t; |
| 323 | |
| 324 | static void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 325 | api_ip6_fib_table_put_entries (clib_bihash_kv_24_8_t * kvp, void *arg) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 326 | { |
| 327 | api_ip6_fib_show_ctx_t *ctx = arg; |
| 328 | |
| 329 | if ((kvp->key[2] >> 32) == ctx->fib_index) |
| 330 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 331 | vec_add1 (ctx->entries, kvp->value); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 332 | } |
| 333 | } |
| 334 | |
| 335 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 336 | api_ip6_fib_table_get_all (vl_api_registration_t * reg, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 337 | vl_api_ip6_fib_dump_t * mp, |
| 338 | fib_table_t * fib_table) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 339 | { |
| 340 | vpe_api_main_t *am = &vpe_api_main; |
| 341 | ip6_main_t *im6 = &ip6_main; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 342 | fib_node_index_t *fib_entry_index; |
| 343 | api_ip6_fib_show_ctx_t ctx = { |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 344 | .fib_index = fib_table->ft_index, |
| 345 | .entries = NULL, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 346 | }; |
| 347 | fib_route_path_encode_t *api_rpaths; |
| 348 | fib_prefix_t pfx; |
| 349 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 350 | BV (clib_bihash_foreach_key_value_pair) |
| 351 | ((BVT (clib_bihash) *) & im6->ip6_table[IP6_FIB_TABLE_NON_FWDING]. |
| 352 | ip6_hash, api_ip6_fib_table_put_entries, &ctx); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 353 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 354 | vec_sort_with_function (ctx.entries, fib_entry_cmp_for_sort); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 355 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 356 | vec_foreach (fib_entry_index, ctx.entries) |
| 357 | { |
| 358 | fib_entry_get_prefix (*fib_entry_index, &pfx); |
| 359 | api_rpaths = NULL; |
| 360 | fib_entry_encode (*fib_entry_index, &api_rpaths); |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 361 | send_ip6_fib_details (am, reg, fib_table, &pfx, api_rpaths, mp->context); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 362 | vec_free (api_rpaths); |
| 363 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 364 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 365 | vec_free (ctx.entries); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | static void |
| 369 | vl_api_ip6_fib_dump_t_handler (vl_api_ip6_fib_dump_t * mp) |
| 370 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 371 | vl_api_registration_t *reg; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 372 | ip6_main_t *im6 = &ip6_main; |
| 373 | fib_table_t *fib_table; |
| 374 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 375 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 376 | if (!reg) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 377 | return; |
| 378 | |
| 379 | /* *INDENT-OFF* */ |
| 380 | pool_foreach (fib_table, im6->fibs, |
| 381 | ({ |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 382 | /* don't send link locals */ |
| 383 | if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL) |
| 384 | continue; |
| 385 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 386 | api_ip6_fib_table_get_all(reg, mp, fib_table); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 387 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 388 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 392 | send_ip_mfib_details (vl_api_registration_t * reg, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 393 | u32 context, u32 table_id, fib_node_index_t mfei) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 394 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 395 | fib_route_path_encode_t *api_rpath, *api_rpaths = NULL; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 396 | vl_api_ip_mfib_details_t *mp; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 397 | mfib_entry_t *mfib_entry; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 398 | vl_api_fib_path_t *fp; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 399 | mfib_prefix_t pfx; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 400 | int path_count; |
| 401 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 402 | mfib_entry = mfib_entry_get (mfei); |
| 403 | mfib_entry_get_prefix (mfei, &pfx); |
| 404 | mfib_entry_encode (mfei, &api_rpaths); |
| 405 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 406 | path_count = vec_len (api_rpaths); |
| 407 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 408 | if (!mp) |
| 409 | return; |
| 410 | memset (mp, 0, sizeof (*mp)); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 411 | mp->_vl_msg_id = ntohs (VL_API_IP_MFIB_DETAILS); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 412 | mp->context = context; |
| 413 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 414 | mp->rpf_id = mfib_entry->mfe_rpf_id; |
| 415 | mp->entry_flags = mfib_entry->mfe_flags; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 416 | mp->table_id = htonl (table_id); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 417 | mp->address_length = pfx.fp_len; |
| 418 | memcpy (mp->grp_address, &pfx.fp_grp_addr.ip4, |
| 419 | sizeof (pfx.fp_grp_addr.ip4)); |
| 420 | memcpy (mp->src_address, &pfx.fp_src_addr.ip4, |
| 421 | sizeof (pfx.fp_src_addr.ip4)); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 422 | |
| 423 | mp->count = htonl (path_count); |
| 424 | fp = mp->path; |
| 425 | vec_foreach (api_rpath, api_rpaths) |
| 426 | { |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 427 | fib_api_path_encode (api_rpath, fp); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 428 | fp++; |
| 429 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 430 | vec_free (api_rpaths); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 431 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 432 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | typedef struct vl_api_ip_mfib_dump_ctc_t_ |
| 436 | { |
| 437 | fib_node_index_t *entries; |
| 438 | } vl_api_ip_mfib_dump_ctc_t; |
| 439 | |
| 440 | static int |
| 441 | vl_api_ip_mfib_table_dump_walk (fib_node_index_t fei, void *arg) |
| 442 | { |
| 443 | vl_api_ip_mfib_dump_ctc_t *ctx = arg; |
| 444 | |
| 445 | vec_add1 (ctx->entries, fei); |
| 446 | |
| 447 | return (0); |
| 448 | } |
| 449 | |
| 450 | static void |
| 451 | vl_api_ip_mfib_dump_t_handler (vl_api_ip_mfib_dump_t * mp) |
| 452 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 453 | vl_api_registration_t *reg; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 454 | ip4_main_t *im = &ip4_main; |
| 455 | mfib_table_t *mfib_table; |
| 456 | fib_node_index_t *mfeip; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 457 | vl_api_ip_mfib_dump_ctc_t ctx = { |
| 458 | .entries = NULL, |
| 459 | }; |
| 460 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 461 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 462 | if (!reg) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 463 | return; |
| 464 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 465 | /* *INDENT-OFF* */ |
| 466 | pool_foreach (mfib_table, im->mfibs, |
| 467 | ({ |
| 468 | ip4_mfib_table_walk(&mfib_table->v4, |
| 469 | vl_api_ip_mfib_table_dump_walk, |
| 470 | &ctx); |
| 471 | |
| 472 | vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort); |
| 473 | |
| 474 | vec_foreach (mfeip, ctx.entries) |
| 475 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 476 | send_ip_mfib_details (reg, mp->context, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 477 | mfib_table->mft_table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 478 | *mfeip); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 479 | } |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 480 | vec_reset_length (ctx.entries); |
| 481 | |
| 482 | })); |
| 483 | /* *INDENT-ON* */ |
| 484 | |
| 485 | vec_free (ctx.entries); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 489 | send_ip6_mfib_details (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 490 | vl_api_registration_t * reg, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 491 | u32 table_id, |
| 492 | mfib_prefix_t * pfx, |
| 493 | fib_route_path_encode_t * api_rpaths, u32 context) |
| 494 | { |
| 495 | vl_api_ip6_mfib_details_t *mp; |
| 496 | fib_route_path_encode_t *api_rpath; |
| 497 | vl_api_fib_path_t *fp; |
| 498 | int path_count; |
| 499 | |
| 500 | path_count = vec_len (api_rpaths); |
| 501 | mp = vl_msg_api_alloc (sizeof (*mp) + path_count * sizeof (*fp)); |
| 502 | if (!mp) |
| 503 | return; |
| 504 | memset (mp, 0, sizeof (*mp)); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 505 | mp->_vl_msg_id = ntohs (VL_API_IP6_MFIB_DETAILS); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 506 | mp->context = context; |
| 507 | |
| 508 | mp->table_id = htonl (table_id); |
| 509 | mp->address_length = pfx->fp_len; |
| 510 | memcpy (mp->grp_address, &pfx->fp_grp_addr.ip6, |
| 511 | sizeof (pfx->fp_grp_addr.ip6)); |
| 512 | memcpy (mp->src_address, &pfx->fp_src_addr.ip6, |
| 513 | sizeof (pfx->fp_src_addr.ip6)); |
| 514 | |
| 515 | mp->count = htonl (path_count); |
| 516 | fp = mp->path; |
| 517 | vec_foreach (api_rpath, api_rpaths) |
| 518 | { |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 519 | fib_api_path_encode (api_rpath, fp); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 520 | fp++; |
| 521 | } |
| 522 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 523 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | typedef struct vl_api_ip6_mfib_dump_ctc_t_ |
| 527 | { |
| 528 | fib_node_index_t *entries; |
| 529 | } vl_api_ip6_mfib_dump_ctc_t; |
| 530 | |
| 531 | static int |
| 532 | vl_api_ip6_mfib_table_dump_walk (fib_node_index_t fei, void *arg) |
| 533 | { |
| 534 | vl_api_ip6_mfib_dump_ctc_t *ctx = arg; |
| 535 | |
| 536 | vec_add1 (ctx->entries, fei); |
| 537 | |
| 538 | return (0); |
| 539 | } |
| 540 | |
| 541 | static void |
| 542 | vl_api_ip6_mfib_dump_t_handler (vl_api_ip6_mfib_dump_t * mp) |
| 543 | { |
| 544 | vpe_api_main_t *am = &vpe_api_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 545 | vl_api_registration_t *reg; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 546 | ip6_main_t *im = &ip6_main; |
| 547 | mfib_table_t *mfib_table; |
| 548 | fib_node_index_t *mfeip; |
| 549 | mfib_prefix_t pfx; |
| 550 | fib_route_path_encode_t *api_rpaths = NULL; |
| 551 | vl_api_ip6_mfib_dump_ctc_t ctx = { |
| 552 | .entries = NULL, |
| 553 | }; |
| 554 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 555 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 556 | if (!reg) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 557 | return; |
| 558 | |
| 559 | |
| 560 | /* *INDENT-OFF* */ |
| 561 | pool_foreach (mfib_table, im->mfibs, |
| 562 | ({ |
| 563 | ip6_mfib_table_walk(&mfib_table->v6, |
| 564 | vl_api_ip6_mfib_table_dump_walk, |
| 565 | &ctx); |
| 566 | |
| 567 | vec_sort_with_function (ctx.entries, mfib_entry_cmp_for_sort); |
| 568 | |
| 569 | vec_foreach(mfeip, ctx.entries) |
| 570 | { |
| 571 | mfib_entry_get_prefix (*mfeip, &pfx); |
| 572 | mfib_entry_encode (*mfeip, &api_rpaths); |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 573 | send_ip6_mfib_details (am, reg, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 574 | mfib_table->mft_table_id, |
| 575 | &pfx, api_rpaths, |
| 576 | mp->context); |
| 577 | } |
| 578 | vec_reset_length (api_rpaths); |
| 579 | vec_reset_length (ctx.entries); |
| 580 | |
| 581 | })); |
| 582 | /* *INDENT-ON* */ |
| 583 | |
| 584 | vec_free (ctx.entries); |
| 585 | vec_free (api_rpaths); |
| 586 | } |
| 587 | |
| 588 | static void |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 589 | vl_api_ip_punt_police_t_handler (vl_api_ip_punt_police_t * mp, |
| 590 | vlib_main_t * vm) |
| 591 | { |
| 592 | vl_api_ip_punt_police_reply_t *rmp; |
| 593 | int rv = 0; |
| 594 | |
| 595 | if (mp->is_ip6) |
| 596 | ip6_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index)); |
| 597 | else |
| 598 | ip4_punt_policer_add_del (mp->is_add, ntohl (mp->policer_index)); |
| 599 | |
| 600 | REPLY_MACRO (VL_API_IP_PUNT_POLICE_REPLY); |
| 601 | } |
| 602 | |
| 603 | static void |
| 604 | vl_api_ip_punt_redirect_t_handler (vl_api_ip_punt_redirect_t * mp, |
| 605 | vlib_main_t * vm) |
| 606 | { |
| 607 | vl_api_ip_punt_redirect_reply_t *rmp; |
| 608 | int rv = 0; |
| 609 | |
| 610 | if (mp->is_add) |
| 611 | { |
| 612 | ip46_address_t nh; |
| 613 | |
| 614 | memset (&nh, 0, sizeof (nh)); |
| 615 | |
| 616 | if (mp->is_ip6) |
| 617 | { |
| 618 | memcpy (&nh.ip6, mp->nh, sizeof (nh.ip6)); |
| 619 | |
| 620 | ip6_punt_redirect_add (ntohl (mp->rx_sw_if_index), |
| 621 | ntohl (mp->tx_sw_if_index), &nh); |
| 622 | } |
| 623 | else |
| 624 | { |
| 625 | memcpy (&nh.ip4, mp->nh, sizeof (nh.ip4)); |
| 626 | |
| 627 | ip4_punt_redirect_add (ntohl (mp->rx_sw_if_index), |
| 628 | ntohl (mp->tx_sw_if_index), &nh); |
| 629 | } |
| 630 | } |
| 631 | else |
| 632 | { |
| 633 | if (mp->is_ip6) |
| 634 | { |
| 635 | ip6_punt_redirect_del (ntohl (mp->rx_sw_if_index)); |
| 636 | } |
| 637 | else |
| 638 | { |
| 639 | ip4_punt_redirect_del (ntohl (mp->rx_sw_if_index)); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | REPLY_MACRO (VL_API_IP_PUNT_REDIRECT_REPLY); |
| 644 | } |
| 645 | |
| 646 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 647 | vl_api_ip_neighbor_add_del_t_handler (vl_api_ip_neighbor_add_del_t * mp, |
| 648 | vlib_main_t * vm) |
| 649 | { |
| 650 | vl_api_ip_neighbor_add_del_reply_t *rmp; |
| 651 | vnet_main_t *vnm = vnet_get_main (); |
| 652 | int rv = 0; |
| 653 | |
| 654 | VALIDATE_SW_IF_INDEX (mp); |
| 655 | |
| 656 | stats_dslock_with_hint (1 /* release hint */ , 7 /* tag */ ); |
| 657 | |
| 658 | /* |
| 659 | * there's no validation here of the ND/ARP entry being added. |
| 660 | * The expectation is that the FIB will ensure that nothing bad |
| 661 | * will come of adding bogus entries. |
| 662 | */ |
| 663 | if (mp->is_ipv6) |
| 664 | { |
| 665 | if (mp->is_add) |
| 666 | rv = vnet_set_ip6_ethernet_neighbor |
| 667 | (vm, ntohl (mp->sw_if_index), |
| 668 | (ip6_address_t *) (mp->dst_address), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 669 | mp->mac_address, sizeof (mp->mac_address), mp->is_static, |
| 670 | mp->is_no_adj_fib); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 671 | else |
| 672 | rv = vnet_unset_ip6_ethernet_neighbor |
| 673 | (vm, ntohl (mp->sw_if_index), |
| 674 | (ip6_address_t *) (mp->dst_address), |
| 675 | mp->mac_address, sizeof (mp->mac_address)); |
| 676 | } |
| 677 | else |
| 678 | { |
| 679 | ethernet_arp_ip4_over_ethernet_address_t a; |
| 680 | |
| 681 | clib_memcpy (&a.ethernet, mp->mac_address, 6); |
| 682 | clib_memcpy (&a.ip4, mp->dst_address, 4); |
| 683 | |
| 684 | if (mp->is_add) |
| 685 | rv = vnet_arp_set_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 686 | &a, mp->is_static, |
| 687 | mp->is_no_adj_fib); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 688 | else |
| 689 | rv = |
| 690 | vnet_arp_unset_ip4_over_ethernet (vnm, ntohl (mp->sw_if_index), &a); |
| 691 | } |
| 692 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 693 | stats_dsunlock (); |
Neale Ranns | 8edad03 | 2017-10-09 05:26:13 -0700 | [diff] [blame] | 694 | |
| 695 | BAD_SW_IF_INDEX_LABEL; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 696 | REPLY_MACRO (VL_API_IP_NEIGHBOR_ADD_DEL_REPLY); |
| 697 | } |
| 698 | |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 699 | void |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 700 | ip_table_delete (fib_protocol_t fproto, u32 table_id, u8 is_api) |
| 701 | { |
| 702 | u32 fib_index, mfib_index; |
| 703 | |
| 704 | /* |
| 705 | * ignore action on the default table - this is always present |
| 706 | * and cannot be added nor deleted from the API |
| 707 | */ |
| 708 | if (0 != table_id) |
| 709 | { |
| 710 | /* |
| 711 | * The API holds only one lock on the table. |
| 712 | * i.e. it can be added many times via the API but needs to be |
| 713 | * deleted only once. |
| 714 | * The FIB index for unicast and multicast is not necessarily the |
| 715 | * same, since internal VPP systesm (like LISP and SR) create |
| 716 | * their own unicast tables. |
| 717 | */ |
| 718 | fib_index = fib_table_find (fproto, table_id); |
| 719 | mfib_index = mfib_table_find (fproto, table_id); |
| 720 | |
| 721 | if (~0 != fib_index) |
| 722 | { |
| 723 | fib_table_unlock (fib_index, fproto, |
| 724 | (is_api ? FIB_SOURCE_API : FIB_SOURCE_CLI)); |
| 725 | } |
| 726 | if (~0 != mfib_index) |
| 727 | { |
| 728 | mfib_table_unlock (mfib_index, fproto, |
| 729 | (is_api ? MFIB_SOURCE_API : MFIB_SOURCE_CLI)); |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | void |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 735 | vl_api_ip_table_add_del_t_handler (vl_api_ip_table_add_del_t * mp) |
| 736 | { |
| 737 | vl_api_ip_table_add_del_reply_t *rmp; |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 738 | fib_protocol_t fproto = (mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 739 | u32 table_id = ntohl (mp->table_id); |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 740 | int rv = 0; |
| 741 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 742 | if (mp->is_add) |
| 743 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 744 | ip_table_create (fproto, table_id, 1, mp->name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 745 | } |
| 746 | else |
| 747 | { |
| 748 | ip_table_delete (fproto, table_id, 1); |
| 749 | } |
| 750 | |
Neale Ranns | 28ab9cc | 2017-08-14 07:18:42 -0700 | [diff] [blame] | 751 | REPLY_MACRO (VL_API_IP_TABLE_ADD_DEL_REPLY); |
| 752 | } |
| 753 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 754 | int |
| 755 | add_del_route_t_handler (u8 is_multipath, |
| 756 | u8 is_add, |
| 757 | u8 is_drop, |
| 758 | u8 is_unreach, |
| 759 | u8 is_prohibit, |
| 760 | u8 is_local, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 761 | u8 is_multicast, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 762 | u8 is_classify, |
| 763 | u32 classify_table_index, |
| 764 | u8 is_resolve_host, |
| 765 | u8 is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 766 | u8 is_interface_rx, |
| 767 | u8 is_rpf_id, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 768 | u8 is_dvr, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 769 | u8 is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 770 | u8 is_udp_encap, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 771 | u32 fib_index, |
| 772 | const fib_prefix_t * prefix, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 773 | dpo_proto_t next_hop_proto, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 774 | const ip46_address_t * next_hop, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 775 | u32 next_hop_id, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 776 | u32 next_hop_sw_if_index, |
| 777 | u8 next_hop_fib_index, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 778 | u16 next_hop_weight, |
| 779 | u16 next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 780 | mpls_label_t next_hop_via_label, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 781 | fib_mpls_label_t * next_hop_out_label_stack) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 782 | { |
| 783 | vnet_classify_main_t *cm = &vnet_classify_main; |
| 784 | fib_route_path_flags_t path_flags = FIB_ROUTE_PATH_FLAG_NONE; |
| 785 | fib_route_path_t path = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 786 | .frp_proto = next_hop_proto, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 787 | .frp_addr = (NULL == next_hop ? zero_addr : *next_hop), |
| 788 | .frp_sw_if_index = next_hop_sw_if_index, |
| 789 | .frp_fib_index = next_hop_fib_index, |
| 790 | .frp_weight = next_hop_weight, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 791 | .frp_preference = next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 792 | .frp_label_stack = next_hop_out_label_stack, |
| 793 | }; |
| 794 | fib_route_path_t *paths = NULL; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 795 | fib_entry_flag_t entry_flags = FIB_ENTRY_FLAG_NONE; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 796 | |
Neale Ranns | caac350 | 2017-09-18 18:04:10 -0700 | [diff] [blame] | 797 | /* |
| 798 | * the special INVALID label meams we are not recursing via a |
| 799 | * label. Exp-null value is never a valid via-label so that |
| 800 | * also means it's not a via-label and means clients that set |
| 801 | * it to 0 by default get the expected behaviour |
| 802 | */ |
| 803 | if ((MPLS_LABEL_INVALID != next_hop_via_label) && (0 != next_hop_via_label)) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 804 | { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 805 | path.frp_proto = DPO_PROTO_MPLS; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 806 | path.frp_local_label = next_hop_via_label; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 807 | path.frp_eos = MPLS_NON_EOS; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 808 | } |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 809 | if (is_dvr) |
| 810 | path_flags |= FIB_ROUTE_PATH_DVR; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 811 | if (is_resolve_host) |
| 812 | path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST; |
| 813 | if (is_resolve_attached) |
| 814 | path_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 815 | if (is_interface_rx) |
| 816 | path_flags |= FIB_ROUTE_PATH_INTF_RX; |
| 817 | if (is_rpf_id) |
| 818 | path_flags |= FIB_ROUTE_PATH_RPF_ID; |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 819 | if (is_source_lookup) |
| 820 | path_flags |= FIB_ROUTE_PATH_SOURCE_LOOKUP; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 821 | if (is_multicast) |
| 822 | entry_flags |= FIB_ENTRY_FLAG_MULTICAST; |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 823 | if (is_udp_encap) |
| 824 | { |
| 825 | path_flags |= FIB_ROUTE_PATH_UDP_ENCAP; |
| 826 | path.frp_udp_encap_id = next_hop_id; |
| 827 | } |
Florin Coras | 79ae2d3 | 2017-12-16 08:31:06 -0800 | [diff] [blame] | 828 | if (path.frp_sw_if_index == ~0 && ip46_address_is_zero (&path.frp_addr) |
| 829 | && path.frp_fib_index != ~0) |
| 830 | { |
| 831 | path_flags |= FIB_ROUTE_PATH_DEAG; |
| 832 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 833 | |
| 834 | path.frp_flags = path_flags; |
| 835 | |
| 836 | if (is_multipath) |
| 837 | { |
| 838 | stats_dslock_with_hint (1 /* release hint */ , 10 /* tag */ ); |
| 839 | |
| 840 | |
| 841 | vec_add1 (paths, path); |
| 842 | |
| 843 | if (is_add) |
| 844 | fib_table_entry_path_add2 (fib_index, |
| 845 | prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 846 | FIB_SOURCE_API, entry_flags, paths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 847 | else |
| 848 | fib_table_entry_path_remove2 (fib_index, |
| 849 | prefix, FIB_SOURCE_API, paths); |
| 850 | |
| 851 | vec_free (paths); |
| 852 | stats_dsunlock (); |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ ); |
| 857 | |
| 858 | if (is_drop || is_local || is_classify || is_unreach || is_prohibit) |
| 859 | { |
| 860 | /* |
| 861 | * special route types that link directly to the adj |
| 862 | */ |
| 863 | if (is_add) |
| 864 | { |
| 865 | dpo_id_t dpo = DPO_INVALID; |
| 866 | dpo_proto_t dproto; |
| 867 | |
| 868 | dproto = fib_proto_to_dpo (prefix->fp_proto); |
| 869 | |
| 870 | if (is_drop) |
| 871 | ip_null_dpo_add_and_lock (dproto, IP_NULL_ACTION_NONE, &dpo); |
| 872 | else if (is_local) |
| 873 | receive_dpo_add_or_lock (dproto, ~0, NULL, &dpo); |
| 874 | else if (is_unreach) |
| 875 | ip_null_dpo_add_and_lock (dproto, |
| 876 | IP_NULL_ACTION_SEND_ICMP_UNREACH, &dpo); |
| 877 | else if (is_prohibit) |
| 878 | ip_null_dpo_add_and_lock (dproto, |
| 879 | IP_NULL_ACTION_SEND_ICMP_PROHIBIT, |
| 880 | &dpo); |
| 881 | else if (is_classify) |
| 882 | { |
| 883 | if (pool_is_free_index (cm->tables, |
| 884 | ntohl (classify_table_index))) |
| 885 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 886 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 887 | return VNET_API_ERROR_NO_SUCH_TABLE; |
| 888 | } |
| 889 | |
| 890 | dpo_set (&dpo, DPO_CLASSIFY, dproto, |
| 891 | classify_dpo_create (dproto, |
| 892 | ntohl (classify_table_index))); |
| 893 | } |
| 894 | else |
| 895 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 896 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 897 | return VNET_API_ERROR_NO_SUCH_TABLE; |
| 898 | } |
| 899 | |
| 900 | fib_table_entry_special_dpo_update (fib_index, |
| 901 | prefix, |
| 902 | FIB_SOURCE_API, |
| 903 | FIB_ENTRY_FLAG_EXCLUSIVE, &dpo); |
| 904 | dpo_reset (&dpo); |
| 905 | } |
| 906 | else |
| 907 | { |
| 908 | fib_table_entry_special_remove (fib_index, prefix, FIB_SOURCE_API); |
| 909 | } |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | if (is_add) |
| 914 | { |
| 915 | vec_add1 (paths, path); |
| 916 | fib_table_entry_update (fib_index, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 917 | prefix, FIB_SOURCE_API, entry_flags, paths); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 918 | vec_free (paths); |
| 919 | } |
| 920 | else |
| 921 | { |
| 922 | fib_table_entry_delete (fib_index, prefix, FIB_SOURCE_API); |
| 923 | } |
| 924 | } |
| 925 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 926 | stats_dsunlock (); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 927 | return (0); |
| 928 | } |
| 929 | |
| 930 | int |
| 931 | add_del_route_check (fib_protocol_t table_proto, |
| 932 | u32 table_id, |
| 933 | u32 next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 934 | dpo_proto_t next_hop_table_proto, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 935 | u32 next_hop_table_id, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 936 | u8 is_rpf_id, u32 * fib_index, u32 * next_hop_fib_index) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 937 | { |
| 938 | vnet_main_t *vnm = vnet_get_main (); |
| 939 | |
| 940 | *fib_index = fib_table_find (table_proto, ntohl (table_id)); |
| 941 | if (~0 == *fib_index) |
| 942 | { |
Neale Ranns | b93078d | 2018-01-25 07:48:12 -0800 | [diff] [blame] | 943 | /* No such VRF, and we weren't asked to create one */ |
| 944 | return VNET_API_ERROR_NO_SUCH_FIB; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 945 | } |
| 946 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 947 | if (!is_rpf_id && ~0 != ntohl (next_hop_sw_if_index)) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 948 | { |
| 949 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, |
| 950 | ntohl (next_hop_sw_if_index))) |
| 951 | { |
| 952 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 953 | } |
| 954 | } |
| 955 | else |
| 956 | { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 957 | fib_protocol_t fib_nh_proto; |
| 958 | |
| 959 | if (next_hop_table_proto > DPO_PROTO_MPLS) |
| 960 | return (0); |
| 961 | |
| 962 | fib_nh_proto = dpo_proto_to_fib (next_hop_table_proto); |
| 963 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 964 | if (is_rpf_id) |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 965 | *next_hop_fib_index = mfib_table_find (fib_nh_proto, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 966 | ntohl (next_hop_table_id)); |
| 967 | else |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 968 | *next_hop_fib_index = fib_table_find (fib_nh_proto, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 969 | ntohl (next_hop_table_id)); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 970 | |
| 971 | if (~0 == *next_hop_fib_index) |
| 972 | { |
Neale Ranns | b93078d | 2018-01-25 07:48:12 -0800 | [diff] [blame] | 973 | /* No such VRF, and we weren't asked to create one */ |
| 974 | return VNET_API_ERROR_NO_SUCH_FIB; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | |
| 978 | return (0); |
| 979 | } |
| 980 | |
| 981 | static int |
| 982 | ip4_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 983 | { |
| 984 | u32 fib_index, next_hop_fib_index; |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 985 | fib_mpls_label_t *label_stack = NULL; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 986 | int rv, ii, n_labels;; |
| 987 | |
| 988 | rv = add_del_route_check (FIB_PROTOCOL_IP4, |
| 989 | mp->table_id, |
| 990 | mp->next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 991 | DPO_PROTO_IP4, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 992 | mp->next_hop_table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 993 | 0, &fib_index, &next_hop_fib_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 994 | |
| 995 | if (0 != rv) |
| 996 | return (rv); |
| 997 | |
| 998 | fib_prefix_t pfx = { |
| 999 | .fp_len = mp->dst_address_length, |
| 1000 | .fp_proto = FIB_PROTOCOL_IP4, |
| 1001 | }; |
| 1002 | clib_memcpy (&pfx.fp_addr.ip4, mp->dst_address, sizeof (pfx.fp_addr.ip4)); |
| 1003 | |
| 1004 | ip46_address_t nh; |
| 1005 | memset (&nh, 0, sizeof (nh)); |
| 1006 | memcpy (&nh.ip4, mp->next_hop_address, sizeof (nh.ip4)); |
| 1007 | |
| 1008 | n_labels = mp->next_hop_n_out_labels; |
| 1009 | if (n_labels == 0) |
| 1010 | ; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1011 | else |
| 1012 | { |
| 1013 | vec_validate (label_stack, n_labels - 1); |
| 1014 | for (ii = 0; ii < n_labels; ii++) |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1015 | { |
| 1016 | label_stack[ii].fml_value = |
| 1017 | ntohl (mp->next_hop_out_label_stack[ii].label); |
| 1018 | label_stack[ii].fml_ttl = mp->next_hop_out_label_stack[ii].ttl; |
| 1019 | label_stack[ii].fml_exp = mp->next_hop_out_label_stack[ii].exp; |
| 1020 | label_stack[ii].fml_mode = |
| 1021 | (mp->next_hop_out_label_stack[ii].is_uniform ? |
| 1022 | FIB_MPLS_LSP_MODE_UNIFORM : FIB_MPLS_LSP_MODE_PIPE); |
| 1023 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | return (add_del_route_t_handler (mp->is_multipath, |
| 1027 | mp->is_add, |
| 1028 | mp->is_drop, |
| 1029 | mp->is_unreach, |
| 1030 | mp->is_prohibit, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1031 | mp->is_local, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1032 | mp->is_classify, |
| 1033 | mp->classify_table_index, |
| 1034 | mp->is_resolve_host, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1035 | mp->is_resolve_attached, 0, 0, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 1036 | mp->is_dvr, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 1037 | mp->is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1038 | mp->is_udp_encap, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1039 | fib_index, &pfx, DPO_PROTO_IP4, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1040 | &nh, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1041 | ntohl (mp->next_hop_id), |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1042 | ntohl (mp->next_hop_sw_if_index), |
| 1043 | next_hop_fib_index, |
| 1044 | mp->next_hop_weight, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1045 | mp->next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1046 | ntohl (mp->next_hop_via_label), |
| 1047 | label_stack)); |
| 1048 | } |
| 1049 | |
| 1050 | static int |
| 1051 | ip6_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1052 | { |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1053 | fib_mpls_label_t *label_stack = NULL; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1054 | u32 fib_index, next_hop_fib_index; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1055 | int rv, ii, n_labels;; |
| 1056 | |
| 1057 | rv = add_del_route_check (FIB_PROTOCOL_IP6, |
| 1058 | mp->table_id, |
| 1059 | mp->next_hop_sw_if_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1060 | DPO_PROTO_IP6, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1061 | mp->next_hop_table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1062 | 0, &fib_index, &next_hop_fib_index); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1063 | |
| 1064 | if (0 != rv) |
| 1065 | return (rv); |
| 1066 | |
| 1067 | fib_prefix_t pfx = { |
| 1068 | .fp_len = mp->dst_address_length, |
| 1069 | .fp_proto = FIB_PROTOCOL_IP6, |
| 1070 | }; |
| 1071 | clib_memcpy (&pfx.fp_addr.ip6, mp->dst_address, sizeof (pfx.fp_addr.ip6)); |
| 1072 | |
| 1073 | ip46_address_t nh; |
| 1074 | memset (&nh, 0, sizeof (nh)); |
| 1075 | memcpy (&nh.ip6, mp->next_hop_address, sizeof (nh.ip6)); |
| 1076 | |
| 1077 | n_labels = mp->next_hop_n_out_labels; |
| 1078 | if (n_labels == 0) |
| 1079 | ; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1080 | else |
| 1081 | { |
| 1082 | vec_validate (label_stack, n_labels - 1); |
| 1083 | for (ii = 0; ii < n_labels; ii++) |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 1084 | { |
| 1085 | label_stack[ii].fml_value = |
| 1086 | ntohl (mp->next_hop_out_label_stack[ii].label); |
| 1087 | label_stack[ii].fml_ttl = mp->next_hop_out_label_stack[ii].ttl; |
| 1088 | label_stack[ii].fml_exp = mp->next_hop_out_label_stack[ii].exp; |
| 1089 | label_stack[ii].fml_mode = |
| 1090 | (mp->next_hop_out_label_stack[ii].is_uniform ? |
| 1091 | FIB_MPLS_LSP_MODE_UNIFORM : FIB_MPLS_LSP_MODE_PIPE); |
| 1092 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | return (add_del_route_t_handler (mp->is_multipath, |
| 1096 | mp->is_add, |
| 1097 | mp->is_drop, |
| 1098 | mp->is_unreach, |
| 1099 | mp->is_prohibit, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1100 | mp->is_local, 0, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1101 | mp->is_classify, |
| 1102 | mp->classify_table_index, |
| 1103 | mp->is_resolve_host, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1104 | mp->is_resolve_attached, 0, 0, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 1105 | mp->is_dvr, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 1106 | mp->is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1107 | mp->is_udp_encap, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1108 | fib_index, &pfx, DPO_PROTO_IP6, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1109 | &nh, ntohl (mp->next_hop_id), |
| 1110 | ntohl (mp->next_hop_sw_if_index), |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1111 | next_hop_fib_index, |
| 1112 | mp->next_hop_weight, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 1113 | mp->next_hop_preference, |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1114 | ntohl (mp->next_hop_via_label), |
| 1115 | label_stack)); |
| 1116 | } |
| 1117 | |
| 1118 | void |
| 1119 | vl_api_ip_add_del_route_t_handler (vl_api_ip_add_del_route_t * mp) |
| 1120 | { |
| 1121 | vl_api_ip_add_del_route_reply_t *rmp; |
| 1122 | int rv; |
| 1123 | vnet_main_t *vnm = vnet_get_main (); |
| 1124 | |
| 1125 | vnm->api_errno = 0; |
| 1126 | |
| 1127 | if (mp->is_ipv6) |
| 1128 | rv = ip6_add_del_route_t_handler (mp); |
| 1129 | else |
| 1130 | rv = ip4_add_del_route_t_handler (mp); |
| 1131 | |
| 1132 | rv = (rv == 0) ? vnm->api_errno : rv; |
| 1133 | |
| 1134 | REPLY_MACRO (VL_API_IP_ADD_DEL_ROUTE_REPLY); |
| 1135 | } |
| 1136 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1137 | void |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1138 | ip_table_create (fib_protocol_t fproto, |
| 1139 | u32 table_id, u8 is_api, const u8 * name) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1140 | { |
| 1141 | u32 fib_index, mfib_index; |
| 1142 | |
| 1143 | /* |
| 1144 | * ignore action on the default table - this is always present |
| 1145 | * and cannot be added nor deleted from the API |
| 1146 | */ |
| 1147 | if (0 != table_id) |
| 1148 | { |
| 1149 | /* |
| 1150 | * The API holds only one lock on the table. |
| 1151 | * i.e. it can be added many times via the API but needs to be |
| 1152 | * deleted only once. |
| 1153 | * The FIB index for unicast and multicast is not necessarily the |
| 1154 | * same, since internal VPP systesm (like LISP and SR) create |
| 1155 | * their own unicast tables. |
| 1156 | */ |
| 1157 | fib_index = fib_table_find (fproto, table_id); |
| 1158 | mfib_index = mfib_table_find (fproto, table_id); |
| 1159 | |
| 1160 | if (~0 == fib_index) |
| 1161 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1162 | fib_table_find_or_create_and_lock_w_name (fproto, table_id, |
| 1163 | (is_api ? |
| 1164 | FIB_SOURCE_API : |
| 1165 | FIB_SOURCE_CLI), name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1166 | } |
| 1167 | if (~0 == mfib_index) |
| 1168 | { |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 1169 | mfib_table_find_or_create_and_lock_w_name (fproto, table_id, |
| 1170 | (is_api ? |
| 1171 | MFIB_SOURCE_API : |
| 1172 | MFIB_SOURCE_CLI), name); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1177 | static int |
| 1178 | add_del_mroute_check (fib_protocol_t table_proto, |
| 1179 | u32 table_id, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1180 | u32 next_hop_sw_if_index, u8 is_local, u32 * fib_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1181 | { |
| 1182 | vnet_main_t *vnm = vnet_get_main (); |
| 1183 | |
| 1184 | *fib_index = mfib_table_find (table_proto, ntohl (table_id)); |
| 1185 | if (~0 == *fib_index) |
| 1186 | { |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1187 | /* No such table */ |
| 1188 | return VNET_API_ERROR_NO_SUCH_FIB; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | if (~0 != ntohl (next_hop_sw_if_index)) |
| 1192 | { |
| 1193 | if (pool_is_free_index (vnm->interface_main.sw_interfaces, |
| 1194 | ntohl (next_hop_sw_if_index))) |
| 1195 | { |
| 1196 | return VNET_API_ERROR_NO_MATCHING_INTERFACE; |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | return (0); |
| 1201 | } |
| 1202 | |
| 1203 | static int |
| 1204 | mroute_add_del_handler (u8 is_add, |
| 1205 | u8 is_local, |
| 1206 | u32 fib_index, |
| 1207 | const mfib_prefix_t * prefix, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1208 | dpo_proto_t nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1209 | u32 entry_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1210 | fib_rpf_id_t rpf_id, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1211 | u32 next_hop_sw_if_index, u32 itf_flags, u32 bier_imp) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1212 | { |
| 1213 | stats_dslock_with_hint (1 /* release hint */ , 2 /* tag */ ); |
| 1214 | |
| 1215 | fib_route_path_t path = { |
| 1216 | .frp_sw_if_index = next_hop_sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1217 | .frp_proto = nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1218 | }; |
| 1219 | |
| 1220 | if (is_local) |
| 1221 | path.frp_flags |= FIB_ROUTE_PATH_LOCAL; |
| 1222 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1223 | if (DPO_PROTO_BIER == nh_proto) |
| 1224 | { |
| 1225 | path.frp_bier_imp = bier_imp; |
| 1226 | path.frp_flags = FIB_ROUTE_PATH_BIER_IMP; |
| 1227 | } |
| 1228 | else if (!is_local && ~0 == next_hop_sw_if_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1229 | { |
| 1230 | mfib_table_entry_update (fib_index, prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1231 | MFIB_SOURCE_API, rpf_id, entry_flags); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1232 | goto done; |
| 1233 | } |
| 1234 | |
| 1235 | if (is_add) |
| 1236 | { |
| 1237 | mfib_table_entry_path_update (fib_index, prefix, |
| 1238 | MFIB_SOURCE_API, &path, itf_flags); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1239 | } |
| 1240 | else |
| 1241 | { |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1242 | mfib_table_entry_path_remove (fib_index, prefix, |
| 1243 | MFIB_SOURCE_API, &path); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1246 | done: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1247 | stats_dsunlock (); |
| 1248 | return (0); |
| 1249 | } |
| 1250 | |
| 1251 | static int |
| 1252 | api_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 1253 | { |
| 1254 | fib_protocol_t fproto; |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1255 | dpo_proto_t nh_proto; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1256 | u32 fib_index; |
| 1257 | int rv; |
| 1258 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1259 | nh_proto = mp->next_hop_afi; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1260 | fproto = (mp->is_ipv6 ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4); |
| 1261 | rv = add_del_mroute_check (fproto, |
| 1262 | mp->table_id, |
| 1263 | mp->next_hop_sw_if_index, |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1264 | mp->is_local, &fib_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1265 | |
| 1266 | if (0 != rv) |
| 1267 | return (rv); |
| 1268 | |
| 1269 | mfib_prefix_t pfx = { |
| 1270 | .fp_len = ntohs (mp->grp_address_length), |
| 1271 | .fp_proto = fproto, |
| 1272 | }; |
| 1273 | |
| 1274 | if (FIB_PROTOCOL_IP4 == fproto) |
| 1275 | { |
| 1276 | clib_memcpy (&pfx.fp_grp_addr.ip4, mp->grp_address, |
| 1277 | sizeof (pfx.fp_grp_addr.ip4)); |
| 1278 | clib_memcpy (&pfx.fp_src_addr.ip4, mp->src_address, |
| 1279 | sizeof (pfx.fp_src_addr.ip4)); |
| 1280 | } |
| 1281 | else |
| 1282 | { |
| 1283 | clib_memcpy (&pfx.fp_grp_addr.ip6, mp->grp_address, |
| 1284 | sizeof (pfx.fp_grp_addr.ip6)); |
| 1285 | clib_memcpy (&pfx.fp_src_addr.ip6, mp->src_address, |
| 1286 | sizeof (pfx.fp_src_addr.ip6)); |
| 1287 | } |
| 1288 | |
| 1289 | return (mroute_add_del_handler (mp->is_add, |
| 1290 | mp->is_local, |
| 1291 | fib_index, &pfx, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1292 | nh_proto, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1293 | ntohl (mp->entry_flags), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1294 | ntohl (mp->rpf_id), |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1295 | ntohl (mp->next_hop_sw_if_index), |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 1296 | ntohl (mp->itf_flags), |
| 1297 | ntohl (mp->bier_imp))); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | void |
| 1301 | vl_api_ip_mroute_add_del_t_handler (vl_api_ip_mroute_add_del_t * mp) |
| 1302 | { |
| 1303 | vl_api_ip_mroute_add_del_reply_t *rmp; |
| 1304 | int rv; |
| 1305 | vnet_main_t *vnm = vnet_get_main (); |
| 1306 | |
| 1307 | vnm->api_errno = 0; |
| 1308 | |
| 1309 | rv = api_mroute_add_del_t_handler (mp); |
| 1310 | |
| 1311 | rv = (rv == 0) ? vnm->api_errno : rv; |
| 1312 | |
| 1313 | REPLY_MACRO (VL_API_IP_MROUTE_ADD_DEL_REPLY); |
| 1314 | } |
| 1315 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1316 | static void |
| 1317 | send_ip_details (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1318 | vl_api_registration_t * reg, u32 sw_if_index, u8 is_ipv6, |
| 1319 | u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1320 | { |
| 1321 | vl_api_ip_details_t *mp; |
| 1322 | |
| 1323 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1324 | memset (mp, 0, sizeof (*mp)); |
| 1325 | mp->_vl_msg_id = ntohs (VL_API_IP_DETAILS); |
| 1326 | |
| 1327 | mp->sw_if_index = ntohl (sw_if_index); |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1328 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1329 | mp->context = context; |
| 1330 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1331 | vl_api_send_msg (reg, (u8 *) mp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | static void |
| 1335 | send_ip_address_details (vpe_api_main_t * am, |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1336 | vl_api_registration_t * reg, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1337 | u8 * ip, u16 prefix_length, |
| 1338 | u32 sw_if_index, u8 is_ipv6, u32 context) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1339 | { |
| 1340 | vl_api_ip_address_details_t *mp; |
| 1341 | |
| 1342 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1343 | memset (mp, 0, sizeof (*mp)); |
| 1344 | mp->_vl_msg_id = ntohs (VL_API_IP_ADDRESS_DETAILS); |
| 1345 | |
| 1346 | if (is_ipv6) |
| 1347 | { |
| 1348 | clib_memcpy (&mp->ip, ip, sizeof (mp->ip)); |
| 1349 | } |
| 1350 | else |
| 1351 | { |
| 1352 | u32 *tp = (u32 *) mp->ip; |
| 1353 | *tp = *(u32 *) ip; |
| 1354 | } |
| 1355 | mp->prefix_length = prefix_length; |
| 1356 | mp->context = context; |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1357 | mp->sw_if_index = htonl (sw_if_index); |
| 1358 | mp->is_ipv6 = is_ipv6; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1359 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1360 | vl_api_send_msg (reg, (u8 *) mp); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static void |
| 1364 | vl_api_ip_address_dump_t_handler (vl_api_ip_address_dump_t * mp) |
| 1365 | { |
| 1366 | vpe_api_main_t *am = &vpe_api_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1367 | vl_api_registration_t *reg; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1368 | ip6_address_t *r6; |
| 1369 | ip4_address_t *r4; |
| 1370 | ip6_main_t *im6 = &ip6_main; |
| 1371 | ip4_main_t *im4 = &ip4_main; |
| 1372 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 1373 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 1374 | ip_interface_address_t *ia = 0; |
| 1375 | u32 sw_if_index = ~0; |
| 1376 | int rv __attribute__ ((unused)) = 0; |
| 1377 | |
| 1378 | VALIDATE_SW_IF_INDEX (mp); |
| 1379 | |
| 1380 | sw_if_index = ntohl (mp->sw_if_index); |
| 1381 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1382 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1383 | if (!reg) |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1384 | return; |
| 1385 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1386 | if (mp->is_ipv6) |
| 1387 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1388 | /* *INDENT-OFF* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1389 | foreach_ip_interface_address (lm6, ia, sw_if_index, |
| 1390 | 1 /* honor unnumbered */, |
| 1391 | ({ |
| 1392 | r6 = ip_interface_address_get_address (lm6, ia); |
| 1393 | u16 prefix_length = ia->address_length; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1394 | send_ip_address_details(am, reg, (u8*)r6, prefix_length, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1395 | sw_if_index, 1, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1396 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1397 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1398 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1399 | else |
| 1400 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1401 | /* *INDENT-OFF* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1402 | foreach_ip_interface_address (lm4, ia, sw_if_index, |
| 1403 | 1 /* honor unnumbered */, |
| 1404 | ({ |
| 1405 | r4 = ip_interface_address_get_address (lm4, ia); |
| 1406 | u16 prefix_length = ia->address_length; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1407 | send_ip_address_details(am, reg, (u8*)r4, prefix_length, |
Jon Loeliger | 466f0d4 | 2017-02-09 12:17:50 -0600 | [diff] [blame] | 1408 | sw_if_index, 0, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1409 | })); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 1410 | /* *INDENT-ON* */ |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1411 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1412 | BAD_SW_IF_INDEX_LABEL; |
| 1413 | } |
| 1414 | |
| 1415 | static void |
| 1416 | vl_api_ip_dump_t_handler (vl_api_ip_dump_t * mp) |
| 1417 | { |
| 1418 | vpe_api_main_t *am = &vpe_api_main; |
| 1419 | vnet_main_t *vnm = vnet_get_main (); |
| 1420 | vlib_main_t *vm = vlib_get_main (); |
| 1421 | vnet_interface_main_t *im = &vnm->interface_main; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1422 | vl_api_registration_t *reg; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1423 | vnet_sw_interface_t *si, *sorted_sis; |
| 1424 | u32 sw_if_index = ~0; |
| 1425 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1426 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1427 | if (!reg) |
| 1428 | return; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1429 | |
| 1430 | /* Gather interfaces. */ |
| 1431 | sorted_sis = vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
| 1432 | _vec_len (sorted_sis) = 0; |
| 1433 | /* *INDENT-OFF* */ |
| 1434 | pool_foreach (si, im->sw_interfaces, |
| 1435 | ({ |
| 1436 | vec_add1 (sorted_sis, si[0]); |
| 1437 | })); |
| 1438 | /* *INDENT-ON* */ |
| 1439 | |
| 1440 | vec_foreach (si, sorted_sis) |
| 1441 | { |
| 1442 | if (!(si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)) |
| 1443 | { |
| 1444 | if (mp->is_ipv6 && !ip6_interface_enabled (vm, si->sw_if_index)) |
| 1445 | { |
| 1446 | continue; |
| 1447 | } |
| 1448 | sw_if_index = si->sw_if_index; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1449 | send_ip_details (am, reg, sw_if_index, mp->is_ipv6, mp->context); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1450 | } |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | static void |
| 1455 | set_ip6_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1456 | { |
| 1457 | vl_api_set_ip_flow_hash_reply_t *rmp; |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1458 | int rv; |
| 1459 | u32 table_id; |
| 1460 | flow_hash_config_t flow_hash_config = 0; |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1461 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 1462 | table_id = ntohl (mp->vrf_id); |
| 1463 | |
| 1464 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1465 | foreach_flow_hash_bit; |
| 1466 | #undef _ |
| 1467 | |
| 1468 | rv = vnet_set_ip6_flow_hash (table_id, flow_hash_config); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1469 | |
| 1470 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1471 | } |
| 1472 | |
| 1473 | static void |
| 1474 | set_ip4_flow_hash (vl_api_set_ip_flow_hash_t * mp) |
| 1475 | { |
| 1476 | vl_api_set_ip_flow_hash_reply_t *rmp; |
| 1477 | int rv; |
| 1478 | u32 table_id; |
| 1479 | flow_hash_config_t flow_hash_config = 0; |
| 1480 | |
| 1481 | table_id = ntohl (mp->vrf_id); |
| 1482 | |
| 1483 | #define _(a,b) if (mp->a) flow_hash_config |= b; |
| 1484 | foreach_flow_hash_bit; |
| 1485 | #undef _ |
| 1486 | |
| 1487 | rv = vnet_set_ip4_flow_hash (table_id, flow_hash_config); |
| 1488 | |
| 1489 | REPLY_MACRO (VL_API_SET_IP_FLOW_HASH_REPLY); |
| 1490 | } |
| 1491 | |
| 1492 | |
| 1493 | static void |
| 1494 | vl_api_set_ip_flow_hash_t_handler (vl_api_set_ip_flow_hash_t * mp) |
| 1495 | { |
| 1496 | if (mp->is_ipv6 == 0) |
| 1497 | set_ip4_flow_hash (mp); |
| 1498 | else |
| 1499 | set_ip6_flow_hash (mp); |
| 1500 | } |
| 1501 | |
| 1502 | static void |
| 1503 | vl_api_sw_interface_ip6nd_ra_config_t_handler |
| 1504 | (vl_api_sw_interface_ip6nd_ra_config_t * mp) |
| 1505 | { |
| 1506 | vl_api_sw_interface_ip6nd_ra_config_reply_t *rmp; |
| 1507 | vlib_main_t *vm = vlib_get_main (); |
| 1508 | int rv = 0; |
| 1509 | u8 is_no, suppress, managed, other, ll_option, send_unicast, cease, |
| 1510 | default_router; |
| 1511 | |
| 1512 | is_no = mp->is_no == 1; |
| 1513 | suppress = mp->suppress == 1; |
| 1514 | managed = mp->managed == 1; |
| 1515 | other = mp->other == 1; |
| 1516 | ll_option = mp->ll_option == 1; |
| 1517 | send_unicast = mp->send_unicast == 1; |
| 1518 | cease = mp->cease == 1; |
| 1519 | default_router = mp->default_router == 1; |
| 1520 | |
| 1521 | VALIDATE_SW_IF_INDEX (mp); |
| 1522 | |
| 1523 | rv = ip6_neighbor_ra_config (vm, ntohl (mp->sw_if_index), |
| 1524 | suppress, managed, other, |
| 1525 | ll_option, send_unicast, cease, |
| 1526 | default_router, ntohl (mp->lifetime), |
| 1527 | ntohl (mp->initial_count), |
| 1528 | ntohl (mp->initial_interval), |
| 1529 | ntohl (mp->max_interval), |
| 1530 | ntohl (mp->min_interval), is_no); |
| 1531 | |
| 1532 | BAD_SW_IF_INDEX_LABEL; |
| 1533 | |
| 1534 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_CONFIG_REPLY); |
| 1535 | } |
| 1536 | |
| 1537 | static void |
| 1538 | vl_api_sw_interface_ip6nd_ra_prefix_t_handler |
| 1539 | (vl_api_sw_interface_ip6nd_ra_prefix_t * mp) |
| 1540 | { |
| 1541 | vlib_main_t *vm = vlib_get_main (); |
| 1542 | vl_api_sw_interface_ip6nd_ra_prefix_reply_t *rmp; |
| 1543 | int rv = 0; |
| 1544 | u8 is_no, use_default, no_advertise, off_link, no_autoconfig, no_onlink; |
| 1545 | |
| 1546 | VALIDATE_SW_IF_INDEX (mp); |
| 1547 | |
| 1548 | is_no = mp->is_no == 1; |
| 1549 | use_default = mp->use_default == 1; |
| 1550 | no_advertise = mp->no_advertise == 1; |
| 1551 | off_link = mp->off_link == 1; |
| 1552 | no_autoconfig = mp->no_autoconfig == 1; |
| 1553 | no_onlink = mp->no_onlink == 1; |
| 1554 | |
| 1555 | rv = ip6_neighbor_ra_prefix (vm, ntohl (mp->sw_if_index), |
| 1556 | (ip6_address_t *) mp->address, |
| 1557 | mp->address_length, use_default, |
| 1558 | ntohl (mp->val_lifetime), |
| 1559 | ntohl (mp->pref_lifetime), no_advertise, |
| 1560 | off_link, no_autoconfig, no_onlink, is_no); |
| 1561 | |
| 1562 | BAD_SW_IF_INDEX_LABEL; |
| 1563 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6ND_RA_PREFIX_REPLY); |
| 1564 | } |
| 1565 | |
| 1566 | static void |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1567 | send_ip6nd_proxy_details (vl_api_registration_t * reg, |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1568 | u32 context, |
| 1569 | const ip46_address_t * addr, u32 sw_if_index) |
| 1570 | { |
| 1571 | vl_api_ip6nd_proxy_details_t *mp; |
| 1572 | |
| 1573 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1574 | memset (mp, 0, sizeof (*mp)); |
| 1575 | mp->_vl_msg_id = ntohs (VL_API_IP6ND_PROXY_DETAILS); |
| 1576 | mp->context = context; |
| 1577 | mp->sw_if_index = htonl (sw_if_index); |
| 1578 | memcpy (mp->address, addr, 16); |
| 1579 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1580 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1581 | } |
| 1582 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1583 | typedef struct api_ip6nd_proxy_fib_table_walk_ctx_t_ |
| 1584 | { |
| 1585 | u32 *indices; |
| 1586 | } api_ip6nd_proxy_fib_table_walk_ctx_t; |
| 1587 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1588 | static fib_table_walk_rc_t |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1589 | api_ip6nd_proxy_fib_table_walk (fib_node_index_t fei, void *arg) |
| 1590 | { |
| 1591 | api_ip6nd_proxy_fib_table_walk_ctx_t *ctx = arg; |
| 1592 | |
| 1593 | if (fib_entry_is_sourced (fei, FIB_SOURCE_IP6_ND_PROXY)) |
| 1594 | { |
| 1595 | vec_add1 (ctx->indices, fei); |
| 1596 | } |
| 1597 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1598 | return (FIB_TABLE_WALK_CONTINUE); |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | static void |
| 1602 | vl_api_ip6nd_proxy_dump_t_handler (vl_api_ip6nd_proxy_dump_t * mp) |
| 1603 | { |
| 1604 | ip6_main_t *im6 = &ip6_main; |
| 1605 | fib_table_t *fib_table; |
| 1606 | api_ip6nd_proxy_fib_table_walk_ctx_t ctx = { |
| 1607 | .indices = NULL, |
| 1608 | }; |
| 1609 | fib_node_index_t *feip; |
| 1610 | fib_prefix_t pfx; |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1611 | vl_api_registration_t *reg; |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1612 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1613 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1614 | if (!reg) |
| 1615 | return; |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1616 | |
| 1617 | /* *INDENT-OFF* */ |
| 1618 | pool_foreach (fib_table, im6->fibs, |
| 1619 | ({ |
| 1620 | fib_table_walk(fib_table->ft_index, |
| 1621 | FIB_PROTOCOL_IP6, |
| 1622 | api_ip6nd_proxy_fib_table_walk, |
| 1623 | &ctx); |
| 1624 | })); |
| 1625 | /* *INDENT-ON* */ |
| 1626 | |
| 1627 | vec_sort_with_function (ctx.indices, fib_entry_cmp_for_sort); |
| 1628 | |
| 1629 | vec_foreach (feip, ctx.indices) |
| 1630 | { |
| 1631 | fib_entry_get_prefix (*feip, &pfx); |
| 1632 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 1633 | send_ip6nd_proxy_details (reg, |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 1634 | mp->context, |
| 1635 | &pfx.fp_addr, |
| 1636 | fib_entry_get_resolving_interface (*feip)); |
| 1637 | } |
| 1638 | |
| 1639 | vec_free (ctx.indices); |
| 1640 | } |
| 1641 | |
| 1642 | static void |
| 1643 | vl_api_ip6nd_proxy_add_del_t_handler (vl_api_ip6nd_proxy_add_del_t * mp) |
| 1644 | { |
| 1645 | vl_api_ip6nd_proxy_add_del_reply_t *rmp; |
| 1646 | int rv = 0; |
| 1647 | |
| 1648 | VALIDATE_SW_IF_INDEX (mp); |
| 1649 | |
| 1650 | rv = ip6_neighbor_proxy_add_del (ntohl (mp->sw_if_index), |
| 1651 | (ip6_address_t *) mp->address, mp->is_del); |
| 1652 | |
| 1653 | BAD_SW_IF_INDEX_LABEL; |
| 1654 | REPLY_MACRO (VL_API_IP6ND_PROXY_ADD_DEL_REPLY); |
| 1655 | } |
| 1656 | |
| 1657 | static void |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 1658 | vl_api_ip6nd_send_router_solicitation_t_handler |
| 1659 | (vl_api_ip6nd_send_router_solicitation_t * mp) |
| 1660 | { |
| 1661 | vl_api_ip6nd_send_router_solicitation_reply_t *rmp; |
| 1662 | icmp6_send_router_solicitation_params_t params; |
| 1663 | vlib_main_t *vm = vlib_get_main (); |
| 1664 | int rv = 0; |
| 1665 | |
| 1666 | VALIDATE_SW_IF_INDEX (mp); |
| 1667 | |
| 1668 | BAD_SW_IF_INDEX_LABEL; |
| 1669 | REPLY_MACRO (VL_API_IP6ND_SEND_ROUTER_SOLICITATION_REPLY); |
| 1670 | |
| 1671 | if (rv != 0) |
| 1672 | return; |
| 1673 | |
| 1674 | params.irt = ntohl (mp->irt); |
| 1675 | params.mrt = ntohl (mp->mrt); |
| 1676 | params.mrc = ntohl (mp->mrc); |
| 1677 | params.mrd = ntohl (mp->mrd); |
| 1678 | |
| 1679 | icmp6_send_router_solicitation (vm, ntohl (mp->sw_if_index), mp->stop, |
| 1680 | ¶ms); |
| 1681 | } |
| 1682 | |
| 1683 | static void |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1684 | vl_api_sw_interface_ip6_enable_disable_t_handler |
| 1685 | (vl_api_sw_interface_ip6_enable_disable_t * mp) |
| 1686 | { |
| 1687 | vlib_main_t *vm = vlib_get_main (); |
| 1688 | vl_api_sw_interface_ip6_enable_disable_reply_t *rmp; |
| 1689 | vnet_main_t *vnm = vnet_get_main (); |
| 1690 | int rv = 0; |
| 1691 | clib_error_t *error; |
| 1692 | |
| 1693 | vnm->api_errno = 0; |
| 1694 | |
| 1695 | VALIDATE_SW_IF_INDEX (mp); |
| 1696 | |
| 1697 | error = |
| 1698 | (mp->enable == 1) ? enable_ip6_interface (vm, |
| 1699 | ntohl (mp->sw_if_index)) : |
| 1700 | disable_ip6_interface (vm, ntohl (mp->sw_if_index)); |
| 1701 | |
| 1702 | if (error) |
| 1703 | { |
| 1704 | clib_error_report (error); |
| 1705 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1706 | } |
| 1707 | else |
| 1708 | { |
| 1709 | rv = vnm->api_errno; |
| 1710 | } |
| 1711 | |
| 1712 | BAD_SW_IF_INDEX_LABEL; |
| 1713 | |
| 1714 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY); |
| 1715 | } |
| 1716 | |
| 1717 | static void |
| 1718 | vl_api_sw_interface_ip6_set_link_local_address_t_handler |
| 1719 | (vl_api_sw_interface_ip6_set_link_local_address_t * mp) |
| 1720 | { |
| 1721 | vlib_main_t *vm = vlib_get_main (); |
| 1722 | vl_api_sw_interface_ip6_set_link_local_address_reply_t *rmp; |
| 1723 | int rv = 0; |
| 1724 | clib_error_t *error; |
| 1725 | vnet_main_t *vnm = vnet_get_main (); |
| 1726 | |
| 1727 | vnm->api_errno = 0; |
| 1728 | |
| 1729 | VALIDATE_SW_IF_INDEX (mp); |
| 1730 | |
| 1731 | error = set_ip6_link_local_address (vm, |
| 1732 | ntohl (mp->sw_if_index), |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 1733 | (ip6_address_t *) mp->address); |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1734 | if (error) |
| 1735 | { |
| 1736 | clib_error_report (error); |
| 1737 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 1738 | } |
| 1739 | else |
| 1740 | { |
| 1741 | rv = vnm->api_errno; |
| 1742 | } |
| 1743 | |
| 1744 | BAD_SW_IF_INDEX_LABEL; |
| 1745 | |
| 1746 | REPLY_MACRO (VL_API_SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY); |
| 1747 | } |
| 1748 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1749 | void |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1750 | vl_mfib_signal_send_one (vl_api_registration_t * reg, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1751 | u32 context, const mfib_signal_t * mfs) |
| 1752 | { |
| 1753 | vl_api_mfib_signal_details_t *mp; |
| 1754 | mfib_prefix_t prefix; |
| 1755 | mfib_table_t *mfib; |
| 1756 | mfib_itf_t *mfi; |
| 1757 | |
| 1758 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 1759 | |
| 1760 | memset (mp, 0, sizeof (*mp)); |
| 1761 | mp->_vl_msg_id = ntohs (VL_API_MFIB_SIGNAL_DETAILS); |
| 1762 | mp->context = context; |
| 1763 | |
| 1764 | mfi = mfib_itf_get (mfs->mfs_itf); |
| 1765 | mfib_entry_get_prefix (mfs->mfs_entry, &prefix); |
| 1766 | mfib = mfib_table_get (mfib_entry_get_fib_index (mfs->mfs_entry), |
| 1767 | prefix.fp_proto); |
| 1768 | mp->table_id = ntohl (mfib->mft_table_id); |
| 1769 | mp->sw_if_index = ntohl (mfi->mfi_sw_if_index); |
| 1770 | |
| 1771 | if (FIB_PROTOCOL_IP4 == prefix.fp_proto) |
| 1772 | { |
| 1773 | mp->grp_address_len = ntohs (prefix.fp_len); |
| 1774 | |
| 1775 | memcpy (mp->grp_address, &prefix.fp_grp_addr.ip4, 4); |
| 1776 | if (prefix.fp_len > 32) |
| 1777 | { |
| 1778 | memcpy (mp->src_address, &prefix.fp_src_addr.ip4, 4); |
| 1779 | } |
| 1780 | } |
| 1781 | else |
| 1782 | { |
| 1783 | mp->grp_address_len = ntohs (prefix.fp_len); |
| 1784 | |
| 1785 | ASSERT (0); |
| 1786 | } |
| 1787 | |
| 1788 | if (0 != mfs->mfs_buffer_len) |
| 1789 | { |
| 1790 | mp->ip_packet_len = ntohs (mfs->mfs_buffer_len); |
| 1791 | |
| 1792 | memcpy (mp->ip_packet_data, mfs->mfs_buffer, mfs->mfs_buffer_len); |
| 1793 | } |
| 1794 | else |
| 1795 | { |
| 1796 | mp->ip_packet_len = 0; |
| 1797 | } |
| 1798 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1799 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static void |
| 1803 | vl_api_mfib_signal_dump_t_handler (vl_api_mfib_signal_dump_t * mp) |
| 1804 | { |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1805 | vl_api_registration_t *reg; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1806 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1807 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 1808 | if (!reg) |
| 1809 | return; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1810 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 1811 | while (vl_api_can_send_msg (reg) && mfib_signal_send_one (reg, mp->context)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1812 | ; |
| 1813 | } |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 1814 | |
Florin Coras | 595992c | 2017-11-06 17:17:08 -0800 | [diff] [blame] | 1815 | static void |
| 1816 | vl_api_ip_container_proxy_add_del_t_handler |
| 1817 | (vl_api_ip_container_proxy_add_del_t * mp) |
| 1818 | { |
| 1819 | vl_api_ip_container_proxy_add_del_reply_t *rmp; |
| 1820 | vnet_ip_container_proxy_args_t args; |
| 1821 | int rv = 0; |
| 1822 | clib_error_t *error; |
| 1823 | |
| 1824 | memset (&args, 0, sizeof (args)); |
| 1825 | ip_set (&args.prefix.fp_addr, mp->ip, mp->is_ip4); |
| 1826 | args.prefix.fp_len = mp->plen ? mp->plen : (mp->is_ip4 ? 32 : 128); |
| 1827 | args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index); |
| 1828 | args.is_add = mp->is_add; |
| 1829 | if ((error = vnet_ip_container_proxy_add_del (&args))) |
| 1830 | { |
| 1831 | rv = clib_error_get_code (error); |
| 1832 | clib_error_report (error); |
| 1833 | } |
| 1834 | |
| 1835 | REPLY_MACRO (VL_API_IP_CONTAINER_PROXY_ADD_DEL_REPLY); |
| 1836 | } |
| 1837 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 1838 | static void |
| 1839 | vl_api_ioam_enable_t_handler (vl_api_ioam_enable_t * mp) |
| 1840 | { |
| 1841 | int rv = 0; |
| 1842 | vl_api_ioam_enable_reply_t *rmp; |
| 1843 | clib_error_t *error; |
| 1844 | |
| 1845 | /* Ignoring the profile id as currently a single profile |
| 1846 | * is supported */ |
| 1847 | error = ip6_ioam_enable (mp->trace_enable, mp->pot_enable, |
| 1848 | mp->seqno, mp->analyse); |
| 1849 | if (error) |
| 1850 | { |
| 1851 | clib_error_report (error); |
| 1852 | rv = clib_error_get_code (error); |
| 1853 | } |
| 1854 | |
| 1855 | REPLY_MACRO (VL_API_IOAM_ENABLE_REPLY); |
| 1856 | } |
| 1857 | |
| 1858 | static void |
| 1859 | vl_api_ioam_disable_t_handler (vl_api_ioam_disable_t * mp) |
| 1860 | { |
| 1861 | int rv = 0; |
| 1862 | vl_api_ioam_disable_reply_t *rmp; |
| 1863 | clib_error_t *error; |
| 1864 | |
| 1865 | error = clear_ioam_rewrite_fn (); |
| 1866 | if (error) |
| 1867 | { |
| 1868 | clib_error_report (error); |
| 1869 | rv = clib_error_get_code (error); |
| 1870 | } |
| 1871 | |
| 1872 | REPLY_MACRO (VL_API_IOAM_DISABLE_REPLY); |
| 1873 | } |
| 1874 | |
| 1875 | static void |
| 1876 | vl_api_ip_source_and_port_range_check_add_del_t_handler |
| 1877 | (vl_api_ip_source_and_port_range_check_add_del_t * mp) |
| 1878 | { |
| 1879 | vl_api_ip_source_and_port_range_check_add_del_reply_t *rmp; |
| 1880 | int rv = 0; |
| 1881 | |
| 1882 | u8 is_ipv6 = mp->is_ipv6; |
| 1883 | u8 is_add = mp->is_add; |
| 1884 | u8 mask_length = mp->mask_length; |
| 1885 | ip4_address_t ip4_addr; |
| 1886 | ip6_address_t ip6_addr; |
| 1887 | u16 *low_ports = 0; |
| 1888 | u16 *high_ports = 0; |
| 1889 | u32 vrf_id; |
| 1890 | u16 tmp_low, tmp_high; |
| 1891 | u8 num_ranges; |
| 1892 | int i; |
| 1893 | |
| 1894 | // Validate port range |
| 1895 | num_ranges = mp->number_of_ranges; |
| 1896 | if (num_ranges > 32) |
| 1897 | { // This is size of array in VPE.API |
| 1898 | rv = VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY; |
| 1899 | goto reply; |
| 1900 | } |
| 1901 | |
| 1902 | vec_reset_length (low_ports); |
| 1903 | vec_reset_length (high_ports); |
| 1904 | |
| 1905 | for (i = 0; i < num_ranges; i++) |
| 1906 | { |
| 1907 | tmp_low = mp->low_ports[i]; |
| 1908 | tmp_high = mp->high_ports[i]; |
| 1909 | // If tmp_low <= tmp_high then only need to check tmp_low = 0 |
| 1910 | // If tmp_low <= tmp_high then only need to check tmp_high > 65535 |
| 1911 | if (tmp_low > tmp_high || tmp_low == 0 || tmp_high > 65535) |
| 1912 | { |
| 1913 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1914 | goto reply; |
| 1915 | } |
| 1916 | vec_add1 (low_ports, tmp_low); |
| 1917 | vec_add1 (high_ports, tmp_high + 1); |
| 1918 | } |
| 1919 | |
| 1920 | // Validate mask_length |
| 1921 | if ((is_ipv6 && mask_length > 128) || (!is_ipv6 && mask_length > 32)) |
| 1922 | { |
| 1923 | rv = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH; |
| 1924 | goto reply; |
| 1925 | } |
| 1926 | |
| 1927 | vrf_id = ntohl (mp->vrf_id); |
| 1928 | |
| 1929 | if (vrf_id < 1) |
| 1930 | { |
| 1931 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1932 | goto reply; |
| 1933 | } |
| 1934 | |
| 1935 | |
| 1936 | if (is_ipv6) |
| 1937 | { |
| 1938 | clib_memcpy (ip6_addr.as_u8, mp->address, sizeof (ip6_addr.as_u8)); |
| 1939 | rv = ip6_source_and_port_range_check_add_del (&ip6_addr, |
| 1940 | mask_length, |
| 1941 | vrf_id, |
| 1942 | low_ports, |
| 1943 | high_ports, is_add); |
| 1944 | } |
| 1945 | else |
| 1946 | { |
| 1947 | clib_memcpy (ip4_addr.data, mp->address, sizeof (ip4_addr)); |
| 1948 | rv = ip4_source_and_port_range_check_add_del (&ip4_addr, |
| 1949 | mask_length, |
| 1950 | vrf_id, |
| 1951 | low_ports, |
| 1952 | high_ports, is_add); |
| 1953 | } |
| 1954 | |
| 1955 | reply: |
| 1956 | vec_free (low_ports); |
| 1957 | vec_free (high_ports); |
| 1958 | REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY); |
| 1959 | } |
| 1960 | |
| 1961 | static void |
| 1962 | vl_api_ip_source_and_port_range_check_interface_add_del_t_handler |
| 1963 | (vl_api_ip_source_and_port_range_check_interface_add_del_t * mp) |
| 1964 | { |
| 1965 | vlib_main_t *vm = vlib_get_main (); |
| 1966 | vl_api_ip_source_and_port_range_check_interface_add_del_reply_t *rmp; |
| 1967 | ip4_main_t *im = &ip4_main; |
| 1968 | int rv; |
| 1969 | u32 sw_if_index; |
| 1970 | u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; |
| 1971 | u32 vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]; |
| 1972 | uword *p = 0; |
| 1973 | int i; |
| 1974 | |
| 1975 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT] = |
| 1976 | ntohl (mp->tcp_out_vrf_id); |
| 1977 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT] = |
| 1978 | ntohl (mp->udp_out_vrf_id); |
| 1979 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN] = |
| 1980 | ntohl (mp->tcp_in_vrf_id); |
| 1981 | vrf_id[IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN] = |
| 1982 | ntohl (mp->udp_in_vrf_id); |
| 1983 | |
| 1984 | |
| 1985 | for (i = 0; i < IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS; i++) |
| 1986 | { |
| 1987 | if (vrf_id[i] != 0 && vrf_id[i] != ~0) |
| 1988 | { |
| 1989 | p = hash_get (im->fib_index_by_table_id, vrf_id[i]); |
| 1990 | |
| 1991 | if (p == 0) |
| 1992 | { |
| 1993 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 1994 | goto reply; |
| 1995 | } |
| 1996 | |
| 1997 | fib_index[i] = p[0]; |
| 1998 | } |
| 1999 | else |
| 2000 | fib_index[i] = ~0; |
| 2001 | } |
| 2002 | sw_if_index = ntohl (mp->sw_if_index); |
| 2003 | |
| 2004 | VALIDATE_SW_IF_INDEX (mp); |
| 2005 | |
| 2006 | rv = |
| 2007 | set_ip_source_and_port_range_check (vm, fib_index, sw_if_index, |
| 2008 | mp->is_add); |
| 2009 | |
| 2010 | BAD_SW_IF_INDEX_LABEL; |
| 2011 | reply: |
| 2012 | |
| 2013 | REPLY_MACRO (VL_API_IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY); |
| 2014 | } |
| 2015 | |
| 2016 | #define IP4_ARP_EVENT 3 |
| 2017 | #define IP6_ND_EVENT 4 |
| 2018 | |
| 2019 | static int arp_change_delete_callback (u32 pool_index, u8 * notused); |
| 2020 | static int nd_change_delete_callback (u32 pool_index, u8 * notused); |
| 2021 | static vlib_node_registration_t ip_resolver_process_node; |
| 2022 | |
| 2023 | static void |
| 2024 | handle_ip4_arp_event (u32 pool_index) |
| 2025 | { |
| 2026 | vpe_api_main_t *vam = &vpe_api_main; |
| 2027 | vnet_main_t *vnm = vam->vnet_main; |
| 2028 | vlib_main_t *vm = vam->vlib_main; |
| 2029 | vl_api_ip4_arp_event_t *event; |
| 2030 | vl_api_ip4_arp_event_t *mp; |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2031 | vl_api_registration_t *reg; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2032 | |
| 2033 | /* Client can cancel, die, etc. */ |
| 2034 | if (pool_is_free_index (vam->arp_events, pool_index)) |
| 2035 | return; |
| 2036 | |
| 2037 | event = pool_elt_at_index (vam->arp_events, pool_index); |
| 2038 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2039 | reg = vl_api_client_index_to_registration (event->client_index); |
| 2040 | if (!reg) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2041 | { |
| 2042 | (void) vnet_add_del_ip4_arp_change_event |
| 2043 | (vnm, arp_change_delete_callback, |
| 2044 | event->pid, &event->address, |
| 2045 | ip_resolver_process_node.index, IP4_ARP_EVENT, |
| 2046 | ~0 /* pool index, notused */ , 0 /* is_add */ ); |
| 2047 | return; |
| 2048 | } |
| 2049 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2050 | if (vl_api_can_send_msg (reg)) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2051 | { |
| 2052 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 2053 | clib_memcpy (mp, event, sizeof (*mp)); |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2054 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2055 | } |
| 2056 | else |
| 2057 | { |
| 2058 | static f64 last_time; |
| 2059 | /* |
| 2060 | * Throttle syslog msgs. |
| 2061 | * It's pretty tempting to just revoke the registration... |
| 2062 | */ |
| 2063 | if (vlib_time_now (vm) > last_time + 10.0) |
| 2064 | { |
| 2065 | clib_warning ("arp event for %U to pid %d: queue stuffed!", |
| 2066 | format_ip4_address, &event->address, event->pid); |
| 2067 | last_time = vlib_time_now (vm); |
| 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | void |
| 2073 | handle_ip6_nd_event (u32 pool_index) |
| 2074 | { |
| 2075 | vpe_api_main_t *vam = &vpe_api_main; |
| 2076 | vnet_main_t *vnm = vam->vnet_main; |
| 2077 | vlib_main_t *vm = vam->vlib_main; |
| 2078 | vl_api_ip6_nd_event_t *event; |
| 2079 | vl_api_ip6_nd_event_t *mp; |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2080 | vl_api_registration_t *reg; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2081 | |
| 2082 | /* Client can cancel, die, etc. */ |
| 2083 | if (pool_is_free_index (vam->nd_events, pool_index)) |
| 2084 | return; |
| 2085 | |
| 2086 | event = pool_elt_at_index (vam->nd_events, pool_index); |
| 2087 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2088 | reg = vl_api_client_index_to_registration (event->client_index); |
| 2089 | if (!reg) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2090 | { |
| 2091 | (void) vnet_add_del_ip6_nd_change_event |
| 2092 | (vnm, nd_change_delete_callback, |
| 2093 | event->pid, &event->address, |
| 2094 | ip_resolver_process_node.index, IP6_ND_EVENT, |
| 2095 | ~0 /* pool index, notused */ , 0 /* is_add */ ); |
| 2096 | return; |
| 2097 | } |
| 2098 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2099 | if (vl_api_can_send_msg (reg)) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2100 | { |
| 2101 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 2102 | clib_memcpy (mp, event, sizeof (*mp)); |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2103 | vl_api_send_msg (reg, (u8 *) mp); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2104 | } |
| 2105 | else |
| 2106 | { |
| 2107 | static f64 last_time; |
| 2108 | /* |
| 2109 | * Throttle syslog msgs. |
| 2110 | * It's pretty tempting to just revoke the registration... |
| 2111 | */ |
| 2112 | if (vlib_time_now (vm) > last_time + 10.0) |
| 2113 | { |
| 2114 | clib_warning ("ip6 nd event for %U to pid %d: queue stuffed!", |
| 2115 | format_ip6_address, &event->address, event->pid); |
| 2116 | last_time = vlib_time_now (vm); |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | static uword |
| 2122 | resolver_process (vlib_main_t * vm, |
| 2123 | vlib_node_runtime_t * rt, vlib_frame_t * f) |
| 2124 | { |
| 2125 | volatile f64 timeout = 100.0; |
| 2126 | volatile uword *event_data = 0; |
| 2127 | |
| 2128 | while (1) |
| 2129 | { |
| 2130 | vlib_process_wait_for_event_or_clock (vm, timeout); |
| 2131 | |
| 2132 | uword event_type = |
| 2133 | vlib_process_get_events (vm, (uword **) & event_data); |
| 2134 | |
| 2135 | int i; |
| 2136 | switch (event_type) |
| 2137 | { |
| 2138 | case IP4_ARP_EVENT: |
| 2139 | for (i = 0; i < vec_len (event_data); i++) |
| 2140 | handle_ip4_arp_event (event_data[i]); |
| 2141 | break; |
| 2142 | |
| 2143 | case IP6_ND_EVENT: |
| 2144 | for (i = 0; i < vec_len (event_data); i++) |
| 2145 | handle_ip6_nd_event (event_data[i]); |
| 2146 | break; |
| 2147 | |
| 2148 | case ~0: /* timeout */ |
| 2149 | break; |
| 2150 | } |
| 2151 | |
| 2152 | vec_reset_length (event_data); |
| 2153 | } |
| 2154 | return 0; /* or not */ |
| 2155 | } |
| 2156 | |
| 2157 | /* *INDENT-OFF* */ |
| 2158 | VLIB_REGISTER_NODE (ip_resolver_process_node,static) = { |
| 2159 | .function = resolver_process, |
| 2160 | .type = VLIB_NODE_TYPE_PROCESS, |
| 2161 | .name = "ip-route-resolver-process", |
| 2162 | }; |
| 2163 | /* *INDENT-ON* */ |
| 2164 | |
| 2165 | static int |
| 2166 | nd_change_data_callback (u32 pool_index, u8 * new_mac, |
| 2167 | u32 sw_if_index, ip6_address_t * address) |
| 2168 | { |
| 2169 | vpe_api_main_t *am = &vpe_api_main; |
| 2170 | vl_api_ip6_nd_event_t *event; |
| 2171 | |
| 2172 | if (pool_is_free_index (am->nd_events, pool_index)) |
| 2173 | return 1; |
| 2174 | |
| 2175 | event = pool_elt_at_index (am->nd_events, pool_index); |
| 2176 | if (eth_mac_equal (event->new_mac, new_mac) && |
| 2177 | sw_if_index == ntohl (event->sw_if_index)) |
| 2178 | { |
| 2179 | return 1; |
| 2180 | } |
| 2181 | |
| 2182 | clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac)); |
| 2183 | event->sw_if_index = htonl (sw_if_index); |
| 2184 | return 0; |
| 2185 | } |
| 2186 | |
| 2187 | static int |
| 2188 | arp_change_delete_callback (u32 pool_index, u8 * notused) |
| 2189 | { |
| 2190 | vpe_api_main_t *am = &vpe_api_main; |
| 2191 | |
| 2192 | if (pool_is_free_index (am->arp_events, pool_index)) |
| 2193 | return 1; |
| 2194 | |
| 2195 | pool_put_index (am->arp_events, pool_index); |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
| 2199 | static int |
| 2200 | nd_change_delete_callback (u32 pool_index, u8 * notused) |
| 2201 | { |
| 2202 | vpe_api_main_t *am = &vpe_api_main; |
| 2203 | |
| 2204 | if (pool_is_free_index (am->nd_events, pool_index)) |
| 2205 | return 1; |
| 2206 | |
| 2207 | pool_put_index (am->nd_events, pool_index); |
| 2208 | return 0; |
| 2209 | } |
| 2210 | |
| 2211 | static vlib_node_registration_t wc_arp_process_node; |
| 2212 | |
| 2213 | enum |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2214 | { WC_ARP_REPORT, WC_ND_REPORT, RA_REPORT, REPORT_MAX }; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2215 | |
| 2216 | static uword |
| 2217 | wc_arp_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) |
| 2218 | { |
| 2219 | /* These cross the longjmp boundry (vlib_process_wait_for_event) |
| 2220 | * and need to be volatile - to prevent them from being optimized into |
| 2221 | * a register - which could change during suspension */ |
| 2222 | |
| 2223 | volatile wc_arp_report_t arp_prev = { 0 }; |
| 2224 | volatile wc_nd_report_t nd_prev = { 0 }; |
| 2225 | volatile f64 last_arp = vlib_time_now (vm); |
| 2226 | volatile f64 last_nd = vlib_time_now (vm); |
| 2227 | |
| 2228 | while (1) |
| 2229 | { |
| 2230 | vlib_process_wait_for_event (vm); |
| 2231 | uword event_type = WC_ARP_REPORT; |
| 2232 | void *event_data = vlib_process_get_event_data (vm, &event_type); |
| 2233 | |
| 2234 | f64 now = vlib_time_now (vm); |
| 2235 | int i; |
| 2236 | if (event_type == WC_ARP_REPORT) |
| 2237 | { |
| 2238 | wc_arp_report_t *arp_events = event_data; |
| 2239 | for (i = 0; i < vec_len (arp_events); i++) |
| 2240 | { |
| 2241 | /* discard dup event */ |
| 2242 | if (arp_prev.ip4 == arp_events[i].ip4 && |
| 2243 | eth_mac_equal ((u8 *) arp_prev.mac, arp_events[i].mac) && |
| 2244 | arp_prev.sw_if_index == arp_events[i].sw_if_index && |
| 2245 | (now - last_arp) < 10.0) |
| 2246 | { |
| 2247 | continue; |
| 2248 | } |
| 2249 | arp_prev = arp_events[i]; |
| 2250 | last_arp = now; |
| 2251 | vpe_client_registration_t *reg; |
| 2252 | /* *INDENT-OFF* */ |
| 2253 | pool_foreach(reg, vpe_api_main.wc_ip4_arp_events_registrations, |
| 2254 | ({ |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2255 | vl_api_registration_t *vl_reg; |
| 2256 | vl_reg = vl_api_client_index_to_registration (reg->client_index); |
Chris Luke | 30684ac | 2018-03-29 12:56:58 -0700 | [diff] [blame] | 2257 | ASSERT (vl_reg != NULL); |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2258 | if (reg && vl_api_can_send_msg (vl_reg)) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2259 | { |
| 2260 | vl_api_ip4_arp_event_t * event = vl_msg_api_alloc (sizeof *event); |
| 2261 | memset (event, 0, sizeof *event); |
| 2262 | event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT); |
| 2263 | event->client_index = reg->client_index; |
| 2264 | event->pid = reg->client_pid; |
| 2265 | event->mac_ip = 1; |
| 2266 | event->address = arp_events[i].ip4; |
| 2267 | event->sw_if_index = htonl(arp_events[i].sw_if_index); |
| 2268 | memcpy(event->new_mac, arp_events[i].mac, sizeof event->new_mac); |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2269 | vl_api_send_msg (vl_reg, (u8 *) event); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2270 | } |
| 2271 | })); |
| 2272 | /* *INDENT-ON* */ |
| 2273 | } |
| 2274 | } |
| 2275 | else if (event_type == WC_ND_REPORT) |
| 2276 | { |
| 2277 | wc_nd_report_t *nd_events = event_data; |
| 2278 | for (i = 0; i < vec_len (nd_events); i++) |
| 2279 | { |
| 2280 | /* discard dup event */ |
| 2281 | if (ip6_address_is_equal |
| 2282 | ((ip6_address_t *) & nd_prev.ip6, &nd_events[i].ip6) |
| 2283 | && eth_mac_equal ((u8 *) nd_prev.mac, nd_events[i].mac) |
| 2284 | && nd_prev.sw_if_index == nd_events[i].sw_if_index |
| 2285 | && (now - last_nd) < 10.0) |
| 2286 | { |
| 2287 | continue; |
| 2288 | } |
| 2289 | nd_prev = nd_events[i]; |
| 2290 | last_nd = now; |
| 2291 | vpe_client_registration_t *reg; |
| 2292 | /* *INDENT-OFF* */ |
| 2293 | pool_foreach(reg, vpe_api_main.wc_ip6_nd_events_registrations, |
| 2294 | ({ |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2295 | vl_api_registration_t *vl_reg; |
| 2296 | vl_reg = vl_api_client_index_to_registration (reg->client_index); |
| 2297 | if (vl_reg && vl_api_can_send_msg (vl_reg)) |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2298 | { |
| 2299 | vl_api_ip6_nd_event_t * event = vl_msg_api_alloc (sizeof *event); |
| 2300 | memset (event, 0, sizeof *event); |
| 2301 | event->_vl_msg_id = htons (VL_API_IP6_ND_EVENT); |
| 2302 | event->client_index = reg->client_index; |
| 2303 | event->pid = reg->client_pid; |
| 2304 | event->mac_ip = 1; |
| 2305 | memcpy(event->address, nd_events[i].ip6.as_u8, sizeof event->address); |
| 2306 | event->sw_if_index = htonl(nd_events[i].sw_if_index); |
| 2307 | memcpy(event->new_mac, nd_events[i].mac, sizeof event->new_mac); |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 2308 | vl_api_send_msg (vl_reg, (u8 *) event); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2309 | } |
| 2310 | })); |
| 2311 | /* *INDENT-ON* */ |
| 2312 | } |
| 2313 | } |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2314 | else if (event_type == RA_REPORT) |
| 2315 | { |
| 2316 | ra_report_t *ra_events = event_data; |
| 2317 | for (i = 0; i < vec_len (ra_events); i++) |
| 2318 | { |
| 2319 | vpe_client_registration_t *reg; |
| 2320 | /* *INDENT-OFF* */ |
| 2321 | pool_foreach(reg, vpe_api_main.ip6_ra_events_registrations, |
| 2322 | ({ |
| 2323 | vl_api_registration_t *vl_reg; |
| 2324 | vl_reg = |
| 2325 | vl_api_client_index_to_registration (reg->client_index); |
| 2326 | if (vl_reg && vl_api_can_send_msg (vl_reg)) |
| 2327 | { |
| 2328 | u32 event_size = |
| 2329 | sizeof (vl_api_ip6_ra_event_t) + |
| 2330 | vec_len (ra_events[i].prefixes) * |
| 2331 | sizeof (vl_api_ip6_ra_prefix_info_t); |
| 2332 | vl_api_ip6_ra_event_t *event = |
| 2333 | vl_msg_api_alloc (event_size); |
| 2334 | memset (event, 0, event_size); |
| 2335 | event->_vl_msg_id = htons (VL_API_IP6_RA_EVENT); |
| 2336 | event->client_index = reg->client_index; |
| 2337 | event->pid = reg->client_pid; |
| 2338 | |
| 2339 | event->sw_if_index = clib_host_to_net_u32 (ra_events[i].sw_if_index); |
| 2340 | |
| 2341 | memcpy (event->router_address, ra_events[i].router_address, 16); |
| 2342 | |
| 2343 | event->current_hop_limit = ra_events[i].current_hop_limit; |
| 2344 | event->flags = ra_events[i].flags; |
| 2345 | event->router_lifetime_in_sec = |
| 2346 | clib_host_to_net_u16 (ra_events |
| 2347 | [i].router_lifetime_in_sec); |
| 2348 | event->neighbor_reachable_time_in_msec = |
| 2349 | clib_host_to_net_u32 (ra_events |
| 2350 | [i].neighbor_reachable_time_in_msec); |
| 2351 | event->time_in_msec_between_retransmitted_neighbor_solicitations |
| 2352 | = |
| 2353 | clib_host_to_net_u32 (ra_events |
| 2354 | [i].time_in_msec_between_retransmitted_neighbor_solicitations); |
| 2355 | |
| 2356 | event->n_prefixes = |
| 2357 | clib_host_to_net_u32 (vec_len (ra_events[i].prefixes)); |
| 2358 | vl_api_ip6_ra_prefix_info_t *prefix = |
| 2359 | (typeof (prefix)) event->prefixes; |
| 2360 | u32 j; |
| 2361 | for (j = 0; j < vec_len (ra_events[i].prefixes); j++) |
| 2362 | { |
| 2363 | ra_report_prefix_info_t *info = |
| 2364 | &ra_events[i].prefixes[j]; |
| 2365 | memcpy (prefix->dst_address, info->dst_address.as_u8, |
| 2366 | 16); |
| 2367 | prefix->dst_address_length = info->dst_address_length; |
| 2368 | prefix->flags = info->flags; |
| 2369 | prefix->valid_time = |
| 2370 | clib_host_to_net_u32 (info->valid_time); |
| 2371 | prefix->preferred_time = |
| 2372 | clib_host_to_net_u32 (info->preferred_time); |
| 2373 | prefix++; |
| 2374 | } |
| 2375 | |
| 2376 | vl_api_send_msg (vl_reg, (u8 *) event); |
| 2377 | } |
| 2378 | })); |
| 2379 | /* *INDENT-ON* */ |
| 2380 | } |
| 2381 | } |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2382 | vlib_process_put_event_data (vm, event_data); |
| 2383 | } |
| 2384 | |
| 2385 | return 0; |
| 2386 | } |
| 2387 | |
| 2388 | /* *INDENT-OFF* */ |
| 2389 | VLIB_REGISTER_NODE (wc_arp_process_node,static) = { |
| 2390 | .function = wc_arp_process, |
| 2391 | .type = VLIB_NODE_TYPE_PROCESS, |
| 2392 | .name = "wildcard-ip4-arp-publisher-process", |
| 2393 | }; |
| 2394 | /* *INDENT-ON* */ |
| 2395 | |
| 2396 | static int |
| 2397 | arp_change_data_callback (u32 pool_index, u8 * new_mac, |
| 2398 | u32 sw_if_index, u32 address) |
| 2399 | { |
| 2400 | vpe_api_main_t *am = &vpe_api_main; |
| 2401 | vl_api_ip4_arp_event_t *event; |
| 2402 | |
| 2403 | if (pool_is_free_index (am->arp_events, pool_index)) |
| 2404 | return 1; |
| 2405 | |
| 2406 | event = pool_elt_at_index (am->arp_events, pool_index); |
| 2407 | if (eth_mac_equal (event->new_mac, new_mac) && |
| 2408 | sw_if_index == ntohl (event->sw_if_index)) |
| 2409 | { |
| 2410 | return 1; |
| 2411 | } |
| 2412 | |
| 2413 | clib_memcpy (event->new_mac, new_mac, sizeof (event->new_mac)); |
| 2414 | event->sw_if_index = htonl (sw_if_index); |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
| 2418 | static void |
| 2419 | vl_api_want_ip4_arp_events_t_handler (vl_api_want_ip4_arp_events_t * mp) |
| 2420 | { |
| 2421 | vpe_api_main_t *am = &vpe_api_main; |
| 2422 | vnet_main_t *vnm = vnet_get_main (); |
| 2423 | vl_api_want_ip4_arp_events_reply_t *rmp; |
| 2424 | int rv = 0; |
| 2425 | |
| 2426 | if (mp->address == 0) |
| 2427 | { |
| 2428 | uword *p = |
| 2429 | hash_get (am->wc_ip4_arp_events_registration_hash, mp->client_index); |
| 2430 | vpe_client_registration_t *rp; |
| 2431 | if (p) |
| 2432 | { |
| 2433 | if (mp->enable_disable) |
| 2434 | { |
| 2435 | clib_warning ("pid %d: already enabled...", mp->pid); |
| 2436 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2437 | goto reply; |
| 2438 | } |
| 2439 | else |
| 2440 | { |
| 2441 | rp = |
| 2442 | pool_elt_at_index (am->wc_ip4_arp_events_registrations, p[0]); |
| 2443 | pool_put (am->wc_ip4_arp_events_registrations, rp); |
| 2444 | hash_unset (am->wc_ip4_arp_events_registration_hash, |
| 2445 | mp->client_index); |
| 2446 | if (pool_elts (am->wc_ip4_arp_events_registrations) == 0) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2447 | wc_arp_set_publisher_node (~0, REPORT_MAX); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2448 | goto reply; |
| 2449 | } |
| 2450 | } |
| 2451 | if (mp->enable_disable == 0) |
| 2452 | { |
| 2453 | clib_warning ("pid %d: already disabled...", mp->pid); |
| 2454 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2455 | goto reply; |
| 2456 | } |
| 2457 | pool_get (am->wc_ip4_arp_events_registrations, rp); |
| 2458 | rp->client_index = mp->client_index; |
| 2459 | rp->client_pid = mp->pid; |
| 2460 | hash_set (am->wc_ip4_arp_events_registration_hash, rp->client_index, |
| 2461 | rp - am->wc_ip4_arp_events_registrations); |
| 2462 | wc_arp_set_publisher_node (wc_arp_process_node.index, WC_ARP_REPORT); |
| 2463 | goto reply; |
| 2464 | } |
| 2465 | |
| 2466 | if (mp->enable_disable) |
| 2467 | { |
| 2468 | vl_api_ip4_arp_event_t *event; |
| 2469 | pool_get (am->arp_events, event); |
| 2470 | rv = vnet_add_del_ip4_arp_change_event |
| 2471 | (vnm, arp_change_data_callback, |
| 2472 | mp->pid, &mp->address /* addr, in net byte order */ , |
| 2473 | ip_resolver_process_node.index, |
| 2474 | IP4_ARP_EVENT, event - am->arp_events, 1 /* is_add */ ); |
| 2475 | |
| 2476 | if (rv) |
| 2477 | { |
| 2478 | pool_put (am->arp_events, event); |
| 2479 | goto reply; |
| 2480 | } |
| 2481 | memset (event, 0, sizeof (*event)); |
| 2482 | |
| 2483 | /* Python API expects events to have no context */ |
| 2484 | event->_vl_msg_id = htons (VL_API_IP4_ARP_EVENT); |
| 2485 | event->client_index = mp->client_index; |
| 2486 | event->address = mp->address; |
| 2487 | event->pid = mp->pid; |
| 2488 | if (mp->address == 0) |
| 2489 | event->mac_ip = 1; |
| 2490 | } |
| 2491 | else |
| 2492 | { |
| 2493 | rv = vnet_add_del_ip4_arp_change_event |
| 2494 | (vnm, arp_change_delete_callback, |
| 2495 | mp->pid, &mp->address /* addr, in net byte order */ , |
| 2496 | ip_resolver_process_node.index, |
| 2497 | IP4_ARP_EVENT, ~0 /* pool index */ , 0 /* is_add */ ); |
| 2498 | } |
| 2499 | reply: |
| 2500 | REPLY_MACRO (VL_API_WANT_IP4_ARP_EVENTS_REPLY); |
| 2501 | } |
| 2502 | |
| 2503 | static void |
| 2504 | vl_api_want_ip6_nd_events_t_handler (vl_api_want_ip6_nd_events_t * mp) |
| 2505 | { |
| 2506 | vpe_api_main_t *am = &vpe_api_main; |
| 2507 | vnet_main_t *vnm = vnet_get_main (); |
| 2508 | vl_api_want_ip6_nd_events_reply_t *rmp; |
| 2509 | int rv = 0; |
| 2510 | |
| 2511 | if (ip6_address_is_zero ((ip6_address_t *) mp->address)) |
| 2512 | { |
| 2513 | uword *p = |
| 2514 | hash_get (am->wc_ip6_nd_events_registration_hash, mp->client_index); |
| 2515 | vpe_client_registration_t *rp; |
| 2516 | if (p) |
| 2517 | { |
| 2518 | if (mp->enable_disable) |
| 2519 | { |
| 2520 | clib_warning ("pid %d: already enabled...", mp->pid); |
| 2521 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2522 | goto reply; |
| 2523 | } |
| 2524 | else |
| 2525 | { |
| 2526 | rp = |
| 2527 | pool_elt_at_index (am->wc_ip6_nd_events_registrations, p[0]); |
| 2528 | pool_put (am->wc_ip6_nd_events_registrations, rp); |
| 2529 | hash_unset (am->wc_ip6_nd_events_registration_hash, |
| 2530 | mp->client_index); |
| 2531 | if (pool_elts (am->wc_ip6_nd_events_registrations) == 0) |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2532 | wc_nd_set_publisher_node (~0, REPORT_MAX); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2533 | goto reply; |
| 2534 | } |
| 2535 | } |
| 2536 | if (mp->enable_disable == 0) |
| 2537 | { |
| 2538 | clib_warning ("pid %d: already disabled...", mp->pid); |
| 2539 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2540 | goto reply; |
| 2541 | } |
| 2542 | pool_get (am->wc_ip6_nd_events_registrations, rp); |
| 2543 | rp->client_index = mp->client_index; |
| 2544 | rp->client_pid = mp->pid; |
| 2545 | hash_set (am->wc_ip6_nd_events_registration_hash, rp->client_index, |
| 2546 | rp - am->wc_ip6_nd_events_registrations); |
| 2547 | wc_nd_set_publisher_node (wc_arp_process_node.index, WC_ND_REPORT); |
| 2548 | goto reply; |
| 2549 | } |
| 2550 | |
| 2551 | if (mp->enable_disable) |
| 2552 | { |
| 2553 | vl_api_ip6_nd_event_t *event; |
| 2554 | pool_get (am->nd_events, event); |
| 2555 | |
| 2556 | rv = vnet_add_del_ip6_nd_change_event |
| 2557 | (vnm, nd_change_data_callback, |
| 2558 | mp->pid, mp->address /* addr, in net byte order */ , |
| 2559 | ip_resolver_process_node.index, |
| 2560 | IP6_ND_EVENT, event - am->nd_events, 1 /* is_add */ ); |
| 2561 | |
| 2562 | if (rv) |
| 2563 | { |
| 2564 | pool_put (am->nd_events, event); |
| 2565 | goto reply; |
| 2566 | } |
| 2567 | memset (event, 0, sizeof (*event)); |
| 2568 | |
| 2569 | event->_vl_msg_id = ntohs (VL_API_IP6_ND_EVENT); |
| 2570 | event->client_index = mp->client_index; |
| 2571 | clib_memcpy (event->address, mp->address, sizeof event->address); |
| 2572 | event->pid = mp->pid; |
| 2573 | } |
| 2574 | else |
| 2575 | { |
| 2576 | rv = vnet_add_del_ip6_nd_change_event |
| 2577 | (vnm, nd_change_delete_callback, |
| 2578 | mp->pid, mp->address /* addr, in net byte order */ , |
| 2579 | ip_resolver_process_node.index, |
| 2580 | IP6_ND_EVENT, ~0 /* pool index */ , 0 /* is_add */ ); |
| 2581 | } |
| 2582 | reply: |
| 2583 | REPLY_MACRO (VL_API_WANT_IP6_ND_EVENTS_REPLY); |
| 2584 | } |
| 2585 | |
| 2586 | static void |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 2587 | vl_api_want_ip6_ra_events_t_handler (vl_api_want_ip6_ra_events_t * mp) |
| 2588 | { |
| 2589 | vpe_api_main_t *am = &vpe_api_main; |
| 2590 | vl_api_want_ip6_ra_events_reply_t *rmp; |
| 2591 | int rv = 0; |
| 2592 | |
| 2593 | uword *p = hash_get (am->ip6_ra_events_registration_hash, mp->client_index); |
| 2594 | vpe_client_registration_t *rp; |
| 2595 | if (p) |
| 2596 | { |
| 2597 | if (mp->enable_disable) |
| 2598 | { |
| 2599 | clib_warning ("pid %d: already enabled...", ntohl (mp->pid)); |
| 2600 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2601 | goto reply; |
| 2602 | } |
| 2603 | else |
| 2604 | { |
| 2605 | rp = pool_elt_at_index (am->ip6_ra_events_registrations, p[0]); |
| 2606 | pool_put (am->ip6_ra_events_registrations, rp); |
| 2607 | hash_unset (am->ip6_ra_events_registration_hash, mp->client_index); |
| 2608 | if (pool_elts (am->ip6_ra_events_registrations) == 0) |
| 2609 | ra_set_publisher_node (~0, REPORT_MAX); |
| 2610 | goto reply; |
| 2611 | } |
| 2612 | } |
| 2613 | if (mp->enable_disable == 0) |
| 2614 | { |
| 2615 | clib_warning ("pid %d: already disabled...", ntohl (mp->pid)); |
| 2616 | rv = VNET_API_ERROR_INVALID_REGISTRATION; |
| 2617 | goto reply; |
| 2618 | } |
| 2619 | pool_get (am->ip6_ra_events_registrations, rp); |
| 2620 | rp->client_index = mp->client_index; |
| 2621 | rp->client_pid = ntohl (mp->pid); |
| 2622 | hash_set (am->ip6_ra_events_registration_hash, rp->client_index, |
| 2623 | rp - am->ip6_ra_events_registrations); |
| 2624 | ra_set_publisher_node (wc_arp_process_node.index, RA_REPORT); |
| 2625 | |
| 2626 | reply: |
| 2627 | REPLY_MACRO (VL_API_WANT_IP6_RA_EVENTS_REPLY); |
| 2628 | } |
| 2629 | |
| 2630 | static void |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2631 | vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp) |
| 2632 | { |
| 2633 | vl_api_proxy_arp_add_del_reply_t *rmp; |
| 2634 | u32 fib_index; |
| 2635 | int rv; |
| 2636 | ip4_main_t *im = &ip4_main; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2637 | int vnet_proxy_arp_add_del (ip4_address_t * lo_addr, |
| 2638 | ip4_address_t * hi_addr, |
| 2639 | u32 fib_index, int is_del); |
| 2640 | uword *p; |
| 2641 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2642 | stats_dslock_with_hint (1 /* release hint */ , 6 /* tag */ ); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2643 | |
| 2644 | p = hash_get (im->fib_index_by_table_id, ntohl (mp->vrf_id)); |
| 2645 | |
| 2646 | if (!p) |
| 2647 | { |
| 2648 | rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2649 | goto out; |
| 2650 | } |
| 2651 | |
| 2652 | fib_index = p[0]; |
| 2653 | |
| 2654 | rv = vnet_proxy_arp_add_del ((ip4_address_t *) mp->low_address, |
| 2655 | (ip4_address_t *) mp->hi_address, |
| 2656 | fib_index, mp->is_add == 0); |
| 2657 | |
| 2658 | out: |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2659 | stats_dsunlock (); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2660 | REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY); |
| 2661 | } |
| 2662 | |
| 2663 | static void |
| 2664 | vl_api_proxy_arp_intfc_enable_disable_t_handler |
| 2665 | (vl_api_proxy_arp_intfc_enable_disable_t * mp) |
| 2666 | { |
| 2667 | int rv = 0; |
| 2668 | vnet_main_t *vnm = vnet_get_main (); |
| 2669 | vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp; |
| 2670 | |
| 2671 | VALIDATE_SW_IF_INDEX (mp); |
| 2672 | |
| 2673 | vnet_sw_interface_t *si = |
| 2674 | vnet_get_sw_interface (vnm, ntohl (mp->sw_if_index)); |
| 2675 | |
| 2676 | ASSERT (si); |
| 2677 | |
| 2678 | if (mp->enable_disable) |
| 2679 | si->flags |= VNET_SW_INTERFACE_FLAG_PROXY_ARP; |
| 2680 | else |
| 2681 | si->flags &= ~VNET_SW_INTERFACE_FLAG_PROXY_ARP; |
| 2682 | |
| 2683 | BAD_SW_IF_INDEX_LABEL; |
| 2684 | |
| 2685 | REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY); |
| 2686 | } |
| 2687 | |
John Lo | c7b4304 | 2018-04-13 16:46:22 -0400 | [diff] [blame] | 2688 | static void |
| 2689 | vl_api_ip_probe_neighbor_t_handler (vl_api_ip_probe_neighbor_t * mp) |
| 2690 | { |
| 2691 | int rv = 0; |
| 2692 | vlib_main_t *vm = vlib_get_main (); |
| 2693 | vl_api_ip_probe_neighbor_reply_t *rmp; |
| 2694 | clib_error_t *error; |
| 2695 | |
| 2696 | VALIDATE_SW_IF_INDEX (mp); |
| 2697 | |
| 2698 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 2699 | |
| 2700 | if (mp->is_ipv6) |
| 2701 | error = ip6_probe_neighbor (vm, (ip6_address_t *) mp->dst_address, |
| 2702 | sw_if_index); |
| 2703 | else |
| 2704 | error = ip4_probe_neighbor (vm, (ip4_address_t *) mp->dst_address, |
| 2705 | sw_if_index); |
| 2706 | |
| 2707 | if (error) |
| 2708 | { |
| 2709 | clib_error_report (error); |
| 2710 | rv = clib_error_get_code (error); |
| 2711 | } |
| 2712 | |
| 2713 | BAD_SW_IF_INDEX_LABEL; |
| 2714 | |
| 2715 | REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY); |
| 2716 | } |
| 2717 | |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2718 | static int |
| 2719 | ip4_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2720 | { |
| 2721 | vnet_main_t *vnm = vnet_get_main (); |
| 2722 | vnet_interface_main_t *im = &vnm->interface_main; |
| 2723 | ip4_main_t *im4 = &ip4_main; |
| 2724 | static u32 *sw_if_indices_to_shut; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2725 | fib_table_t *fib_table; |
| 2726 | ip4_fib_t *fib; |
| 2727 | u32 sw_if_index; |
| 2728 | int i; |
| 2729 | int rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2730 | u32 target_fib_id = ntohl (mp->vrf_id); |
| 2731 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2732 | stats_dslock_with_hint (1 /* release hint */ , 8 /* tag */ ); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2733 | |
| 2734 | /* *INDENT-OFF* */ |
| 2735 | pool_foreach (fib_table, im4->fibs, |
| 2736 | ({ |
| 2737 | vnet_sw_interface_t * si; |
| 2738 | |
| 2739 | fib = pool_elt_at_index (im4->v4_fibs, fib_table->ft_index); |
| 2740 | |
| 2741 | if (fib->table_id != target_fib_id) |
| 2742 | continue; |
| 2743 | |
| 2744 | /* remove any mpls encap/decap labels */ |
| 2745 | mpls_fib_reset_labels (fib->table_id); |
| 2746 | |
| 2747 | /* remove any proxy arps in this fib */ |
| 2748 | vnet_proxy_arp_fib_reset (fib->table_id); |
| 2749 | |
| 2750 | /* Set the flow hash for this fib to the default */ |
| 2751 | vnet_set_ip4_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT); |
| 2752 | |
| 2753 | vec_reset_length (sw_if_indices_to_shut); |
| 2754 | |
| 2755 | /* Shut down interfaces in this FIB / clean out intfc routes */ |
| 2756 | pool_foreach (si, im->sw_interfaces, |
| 2757 | ({ |
| 2758 | u32 sw_if_index = si->sw_if_index; |
| 2759 | |
| 2760 | if (sw_if_index < vec_len (im4->fib_index_by_sw_if_index) |
| 2761 | && (im4->fib_index_by_sw_if_index[si->sw_if_index] == |
| 2762 | fib->index)) |
| 2763 | vec_add1 (sw_if_indices_to_shut, si->sw_if_index); |
| 2764 | })); |
| 2765 | |
| 2766 | for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) { |
| 2767 | sw_if_index = sw_if_indices_to_shut[i]; |
| 2768 | |
| 2769 | u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index); |
| 2770 | flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 2771 | vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 2772 | } |
| 2773 | |
| 2774 | fib_table_flush(fib->index, FIB_PROTOCOL_IP4, FIB_SOURCE_API); |
| 2775 | |
| 2776 | rv = 0; |
| 2777 | break; |
| 2778 | })); /* pool_foreach (fib) */ |
| 2779 | /* *INDENT-ON* */ |
| 2780 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2781 | stats_dsunlock (); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2782 | return rv; |
| 2783 | } |
| 2784 | |
| 2785 | static int |
| 2786 | ip6_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2787 | { |
| 2788 | vnet_main_t *vnm = vnet_get_main (); |
| 2789 | vnet_interface_main_t *im = &vnm->interface_main; |
| 2790 | ip6_main_t *im6 = &ip6_main; |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2791 | static u32 *sw_if_indices_to_shut; |
| 2792 | fib_table_t *fib_table; |
| 2793 | ip6_fib_t *fib; |
| 2794 | u32 sw_if_index; |
| 2795 | int i; |
| 2796 | int rv = VNET_API_ERROR_NO_SUCH_FIB; |
| 2797 | u32 target_fib_id = ntohl (mp->vrf_id); |
| 2798 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2799 | stats_dslock_with_hint (1 /* release hint */ , 9 /* tag */ ); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2800 | |
| 2801 | /* *INDENT-OFF* */ |
| 2802 | pool_foreach (fib_table, im6->fibs, |
| 2803 | ({ |
| 2804 | vnet_sw_interface_t * si; |
| 2805 | |
| 2806 | fib = pool_elt_at_index (im6->v6_fibs, fib_table->ft_index); |
| 2807 | |
| 2808 | if (fib->table_id != target_fib_id) |
| 2809 | continue; |
| 2810 | |
| 2811 | vec_reset_length (sw_if_indices_to_shut); |
| 2812 | |
| 2813 | /* Set the flow hash for this fib to the default */ |
| 2814 | vnet_set_ip6_flow_hash (fib->table_id, IP_FLOW_HASH_DEFAULT); |
| 2815 | |
| 2816 | /* Shut down interfaces in this FIB / clean out intfc routes */ |
| 2817 | pool_foreach (si, im->sw_interfaces, |
| 2818 | ({ |
| 2819 | if (im6->fib_index_by_sw_if_index[si->sw_if_index] == |
| 2820 | fib->index) |
| 2821 | vec_add1 (sw_if_indices_to_shut, si->sw_if_index); |
| 2822 | })); |
| 2823 | |
| 2824 | for (i = 0; i < vec_len (sw_if_indices_to_shut); i++) { |
| 2825 | sw_if_index = sw_if_indices_to_shut[i]; |
| 2826 | |
| 2827 | u32 flags = vnet_sw_interface_get_flags (vnm, sw_if_index); |
| 2828 | flags &= ~(VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
| 2829 | vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 2830 | } |
| 2831 | |
| 2832 | fib_table_flush(fib->index, FIB_PROTOCOL_IP6, FIB_SOURCE_API); |
| 2833 | |
| 2834 | rv = 0; |
| 2835 | break; |
| 2836 | })); /* pool_foreach (fib) */ |
| 2837 | /* *INDENT-ON* */ |
| 2838 | |
Ole Troan | 3288ed7 | 2017-12-06 17:00:05 +0100 | [diff] [blame] | 2839 | stats_dsunlock (); |
Neale Ranns | b8d4481 | 2017-11-10 06:53:54 -0800 | [diff] [blame] | 2840 | return rv; |
| 2841 | } |
| 2842 | |
| 2843 | static void |
| 2844 | vl_api_reset_fib_t_handler (vl_api_reset_fib_t * mp) |
| 2845 | { |
| 2846 | int rv; |
| 2847 | vl_api_reset_fib_reply_t *rmp; |
| 2848 | |
| 2849 | if (mp->is_ipv6) |
| 2850 | rv = ip6_reset_fib_t_handler (mp); |
| 2851 | else |
| 2852 | rv = ip4_reset_fib_t_handler (mp); |
| 2853 | |
| 2854 | REPLY_MACRO (VL_API_RESET_FIB_REPLY); |
| 2855 | } |
| 2856 | |
| 2857 | static void |
| 2858 | vl_api_set_arp_neighbor_limit_t_handler (vl_api_set_arp_neighbor_limit_t * mp) |
| 2859 | { |
| 2860 | int rv; |
| 2861 | vl_api_set_arp_neighbor_limit_reply_t *rmp; |
| 2862 | vnet_main_t *vnm = vnet_get_main (); |
| 2863 | clib_error_t *error; |
| 2864 | |
| 2865 | vnm->api_errno = 0; |
| 2866 | |
| 2867 | if (mp->is_ipv6) |
| 2868 | error = ip6_set_neighbor_limit (ntohl (mp->arp_neighbor_limit)); |
| 2869 | else |
| 2870 | error = ip4_set_arp_limit (ntohl (mp->arp_neighbor_limit)); |
| 2871 | |
| 2872 | if (error) |
| 2873 | { |
| 2874 | clib_error_report (error); |
| 2875 | rv = VNET_API_ERROR_UNSPECIFIED; |
| 2876 | } |
| 2877 | else |
| 2878 | { |
| 2879 | rv = vnm->api_errno; |
| 2880 | } |
| 2881 | |
| 2882 | REPLY_MACRO (VL_API_SET_ARP_NEIGHBOR_LIMIT_REPLY); |
| 2883 | } |
| 2884 | |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 2885 | void |
| 2886 | vl_api_ip_reassembly_set_t_handler (vl_api_ip_reassembly_set_t * mp) |
| 2887 | { |
| 2888 | vl_api_ip_reassembly_set_reply_t *rmp; |
| 2889 | int rv = 0; |
| 2890 | if (mp->is_ip6) |
| 2891 | { |
| 2892 | rv = ip6_reass_set (clib_net_to_host_u32 (mp->timeout_ms), |
| 2893 | clib_net_to_host_u32 (mp->max_reassemblies), |
| 2894 | clib_net_to_host_u32 (mp->expire_walk_interval_ms)); |
| 2895 | } |
| 2896 | else |
| 2897 | { |
| 2898 | rv = ip4_reass_set (clib_net_to_host_u32 (mp->timeout_ms), |
| 2899 | clib_net_to_host_u32 (mp->max_reassemblies), |
| 2900 | clib_net_to_host_u32 (mp->expire_walk_interval_ms)); |
| 2901 | } |
| 2902 | |
| 2903 | REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY); |
| 2904 | } |
| 2905 | |
| 2906 | void |
| 2907 | vl_api_ip_reassembly_get_t_handler (vl_api_ip_reassembly_get_t * mp) |
| 2908 | { |
| 2909 | unix_shared_memory_queue_t *q; |
| 2910 | |
| 2911 | q = vl_api_client_index_to_input_queue (mp->client_index); |
| 2912 | |
| 2913 | if (q == 0) |
| 2914 | return; |
| 2915 | |
| 2916 | vl_api_ip_reassembly_get_reply_t *rmp = vl_msg_api_alloc (sizeof (*rmp)); |
| 2917 | memset (rmp, 0, sizeof (*rmp)); |
| 2918 | rmp->_vl_msg_id = ntohs (VL_API_IP_REASSEMBLY_GET_REPLY); |
| 2919 | rmp->context = mp->context; |
| 2920 | rmp->retval = 0; |
| 2921 | if (mp->is_ip6) |
| 2922 | { |
| 2923 | rmp->is_ip6 = 1; |
| 2924 | ip6_reass_get (&rmp->timeout_ms, &rmp->max_reassemblies, |
| 2925 | &rmp->expire_walk_interval_ms); |
| 2926 | } |
| 2927 | else |
| 2928 | { |
| 2929 | rmp->is_ip6 = 0; |
| 2930 | ip4_reass_get (&rmp->timeout_ms, &rmp->max_reassemblies, |
| 2931 | &rmp->expire_walk_interval_ms); |
| 2932 | } |
| 2933 | rmp->timeout_ms = clib_host_to_net_u32 (rmp->timeout_ms); |
| 2934 | rmp->max_reassemblies = clib_host_to_net_u32 (rmp->max_reassemblies); |
| 2935 | rmp->expire_walk_interval_ms = |
| 2936 | clib_host_to_net_u32 (rmp->expire_walk_interval_ms); |
| 2937 | vl_msg_api_send_shmem (q, (u8 *) & rmp); |
| 2938 | } |
| 2939 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 2940 | void |
| 2941 | vl_api_ip_reassembly_enable_disable_t_handler |
| 2942 | (vl_api_ip_reassembly_enable_disable_t * mp) |
| 2943 | { |
| 2944 | vl_api_ip_reassembly_enable_disable_reply_t *rmp; |
| 2945 | int rv = 0; |
| 2946 | rv = ip4_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index), |
| 2947 | mp->enable_ip4); |
| 2948 | if (0 == rv) |
| 2949 | { |
| 2950 | rv = ip6_reass_enable_disable (clib_net_to_host_u32 (mp->sw_if_index), |
| 2951 | mp->enable_ip6); |
| 2952 | } |
| 2953 | |
| 2954 | REPLY_MACRO (VL_API_IP_REASSEMBLY_SET_REPLY); |
| 2955 | } |
| 2956 | |
Dave Barach | b5e8a77 | 2016-12-06 12:04:42 -0500 | [diff] [blame] | 2957 | #define vl_msg_name_crc_list |
| 2958 | #include <vnet/ip/ip.api.h> |
| 2959 | #undef vl_msg_name_crc_list |
| 2960 | |
| 2961 | static void |
| 2962 | setup_message_id_table (api_main_t * am) |
| 2963 | { |
| 2964 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 2965 | foreach_vl_msg_name_crc_ip; |
| 2966 | #undef _ |
| 2967 | } |
| 2968 | |
| 2969 | static clib_error_t * |
| 2970 | ip_api_hookup (vlib_main_t * vm) |
| 2971 | { |
| 2972 | api_main_t *am = &api_main; |
| 2973 | |
| 2974 | #define _(N,n) \ |
| 2975 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 2976 | vl_api_##n##_t_handler, \ |
| 2977 | vl_noop_handler, \ |
| 2978 | vl_api_##n##_t_endian, \ |
| 2979 | vl_api_##n##_t_print, \ |
| 2980 | sizeof(vl_api_##n##_t), 1); |
| 2981 | foreach_ip_api_msg; |
| 2982 | #undef _ |
| 2983 | |
| 2984 | /* |
| 2985 | * Set up the (msg_name, crc, message-id) table |
| 2986 | */ |
| 2987 | setup_message_id_table (am); |
| 2988 | |
| 2989 | return 0; |
| 2990 | } |
| 2991 | |
| 2992 | VLIB_API_INIT_FUNCTION (ip_api_hookup); |
| 2993 | |
| 2994 | /* |
| 2995 | * fd.io coding-style-patch-verification: ON |
| 2996 | * |
| 2997 | * Local Variables: |
| 2998 | * eval: (c-set-style "gnu") |
| 2999 | * End: |
| 3000 | */ |