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