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