Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 3 | * teib_api.c - teib api |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 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 | |
| 23 | #include <vnet/api_errno.h> |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 24 | #include <vnet/teib/teib.h> |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 25 | #include <vnet/ip/ip_types_api.h> |
| 26 | #include <vnet/fib/fib_table.h> |
| 27 | |
| 28 | /* define message IDs */ |
| 29 | #include <vnet/format_fns.h> |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 30 | #include <vnet/teib/teib.api_enum.h> |
| 31 | #include <vnet/teib/teib.api_types.h> |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 32 | |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 33 | static u32 teib_base_msg_id; |
| 34 | #define REPLY_MSG_ID_BASE teib_base_msg_id |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 35 | |
| 36 | #include <vlibapi/api_helper_macros.h> |
| 37 | |
| 38 | static void |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 39 | vl_api_teib_entry_add_del_t_handler (vl_api_teib_entry_add_del_t * mp) |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 40 | { |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 41 | vl_api_teib_entry_add_del_reply_t *rmp; |
Neale Ranns | e6b8305 | 2020-09-17 12:56:47 +0000 | [diff] [blame] | 42 | ip_address_t peer, nh; |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 43 | int rv; |
| 44 | |
| 45 | VALIDATE_SW_IF_INDEX ((&mp->entry)); |
| 46 | |
Neale Ranns | 256b67b | 2020-09-02 14:46:53 +0000 | [diff] [blame] | 47 | ip_address_decode2 (&mp->entry.peer, &peer); |
Neale Ranns | e6b8305 | 2020-09-17 12:56:47 +0000 | [diff] [blame] | 48 | ip_address_decode2 (&mp->entry.nh, &nh); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 49 | |
| 50 | if (mp->is_add) |
Neale Ranns | 256b67b | 2020-09-02 14:46:53 +0000 | [diff] [blame] | 51 | rv = teib_entry_add (ntohl (mp->entry.sw_if_index), |
Neale Ranns | e6b8305 | 2020-09-17 12:56:47 +0000 | [diff] [blame] | 52 | &peer, ntohl (mp->entry.nh_table_id), &nh); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 53 | else |
Neale Ranns | e6b8305 | 2020-09-17 12:56:47 +0000 | [diff] [blame] | 54 | rv = teib_entry_del (ntohl (mp->entry.sw_if_index), &peer); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 55 | |
| 56 | BAD_SW_IF_INDEX_LABEL; |
| 57 | |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 58 | REPLY_MACRO (VL_API_TEIB_ENTRY_ADD_DEL_REPLY); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 61 | typedef struct vl_api_teib_send_t_ |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 62 | { |
| 63 | vl_api_registration_t *reg; |
| 64 | u32 context; |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 65 | } vl_api_teib_send_t; |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 66 | |
| 67 | static walk_rc_t |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 68 | vl_api_teib_send_one (index_t nei, void *arg) |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 69 | { |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 70 | vl_api_teib_details_t *mp; |
| 71 | vl_api_teib_send_t *ctx = arg; |
| 72 | const teib_entry_t *ne; |
Neale Ranns | 4c16d80 | 2019-12-17 20:15:03 +0000 | [diff] [blame] | 73 | const fib_prefix_t *pfx; |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 74 | |
Neale Ranns | 2828721 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 75 | mp = vl_msg_api_alloc_zero (sizeof (*mp)); |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 76 | mp->_vl_msg_id = ntohs (VL_API_TEIB_DETAILS + REPLY_MSG_ID_BASE); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 77 | mp->context = ctx->context; |
| 78 | |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 79 | ne = teib_entry_get (nei); |
| 80 | pfx = teib_entry_get_nh (ne); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 81 | |
Neale Ranns | e6b8305 | 2020-09-17 12:56:47 +0000 | [diff] [blame] | 82 | ip_address_encode2 (teib_entry_get_peer (ne), &mp->entry.peer); |
Neale Ranns | 4c16d80 | 2019-12-17 20:15:03 +0000 | [diff] [blame] | 83 | ip_address_encode (&pfx->fp_addr, IP46_TYPE_ANY, &mp->entry.nh); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 84 | mp->entry.nh_table_id = |
Neale Ranns | 4c16d80 | 2019-12-17 20:15:03 +0000 | [diff] [blame] | 85 | htonl (fib_table_get_table_id |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 86 | (teib_entry_get_fib_index (ne), pfx->fp_proto)); |
| 87 | mp->entry.sw_if_index = htonl (teib_entry_get_sw_if_index (ne)); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 88 | |
| 89 | vl_api_send_msg (ctx->reg, (u8 *) mp); |
| 90 | |
| 91 | return (WALK_CONTINUE); |
| 92 | } |
| 93 | |
| 94 | static void |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 95 | vl_api_teib_dump_t_handler (vl_api_teib_dump_t * mp) |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 96 | { |
| 97 | vl_api_registration_t *reg; |
| 98 | |
| 99 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 100 | if (!reg) |
| 101 | return; |
| 102 | |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 103 | vl_api_teib_send_t ctx = { |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 104 | .reg = reg, |
| 105 | .context = mp->context, |
| 106 | }; |
| 107 | |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 108 | teib_walk (vl_api_teib_send_one, &ctx); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 112 | * teib_api_hookup |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 113 | * Add vpe's API message handlers to the table. |
| 114 | * vlib has already mapped shared memory and |
| 115 | * added the client registration handlers. |
| 116 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 117 | */ |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 118 | #include <vnet/teib/teib.api.c> |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 119 | |
| 120 | static clib_error_t * |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 121 | teib_api_hookup (vlib_main_t * vm) |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 122 | { |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 123 | teib_base_msg_id = setup_message_id_table (); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 124 | |
| 125 | return (NULL); |
| 126 | } |
| 127 | |
Neale Ranns | 03ce462 | 2020-02-03 10:55:09 +0000 | [diff] [blame] | 128 | VLIB_API_INIT_FUNCTION (teib_api_hookup); |
Neale Ranns | 5f8f617 | 2019-04-18 10:23:56 +0000 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * fd.io coding-style-patch-verification: ON |
| 132 | * |
| 133 | * Local Variables: |
| 134 | * eval: (c-set-style "gnu") |
| 135 | * End: |
| 136 | */ |