Pavel Kotucek | 884cf26 | 2017-01-25 08:27:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * cop_api.c - cop 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 | |
| 23 | #include <vnet/interface.h> |
| 24 | #include <vnet/api_errno.h> |
| 25 | #include <vnet/cop/cop.h> |
| 26 | |
| 27 | #include <vnet/vnet_msg_enum.h> |
| 28 | |
| 29 | #define vl_typedefs /* define message structures */ |
| 30 | #include <vnet/vnet_all_api_h.h> |
| 31 | #undef vl_typedefs |
| 32 | |
| 33 | #define vl_endianfun /* define message structures */ |
| 34 | #include <vnet/vnet_all_api_h.h> |
| 35 | #undef vl_endianfun |
| 36 | |
| 37 | /* instantiate all the print functions we know about */ |
| 38 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 39 | #define vl_printfun |
| 40 | #include <vnet/vnet_all_api_h.h> |
| 41 | #undef vl_printfun |
| 42 | |
| 43 | #include <vlibapi/api_helper_macros.h> |
| 44 | |
| 45 | #define foreach_vpe_api_msg \ |
| 46 | _(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \ |
| 47 | _(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) |
| 48 | |
| 49 | static void vl_api_cop_interface_enable_disable_t_handler |
| 50 | (vl_api_cop_interface_enable_disable_t * mp) |
| 51 | { |
| 52 | vl_api_cop_interface_enable_disable_reply_t *rmp; |
| 53 | int rv; |
| 54 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 55 | int enable_disable; |
| 56 | |
| 57 | VALIDATE_SW_IF_INDEX (mp); |
| 58 | |
| 59 | enable_disable = (int) mp->enable_disable; |
| 60 | |
| 61 | rv = cop_interface_enable_disable (sw_if_index, enable_disable); |
| 62 | |
| 63 | BAD_SW_IF_INDEX_LABEL; |
| 64 | |
| 65 | REPLY_MACRO (VL_API_COP_INTERFACE_ENABLE_DISABLE_REPLY); |
| 66 | } |
| 67 | |
| 68 | static void vl_api_cop_whitelist_enable_disable_t_handler |
| 69 | (vl_api_cop_whitelist_enable_disable_t * mp) |
| 70 | { |
| 71 | vl_api_cop_whitelist_enable_disable_reply_t *rmp; |
| 72 | cop_whitelist_enable_disable_args_t _a, *a = &_a; |
| 73 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 74 | int rv; |
| 75 | |
| 76 | VALIDATE_SW_IF_INDEX (mp); |
| 77 | |
| 78 | a->sw_if_index = sw_if_index; |
| 79 | a->ip4 = mp->ip4; |
| 80 | a->ip6 = mp->ip6; |
| 81 | a->default_cop = mp->default_cop; |
| 82 | a->fib_id = ntohl (mp->fib_id); |
| 83 | |
| 84 | rv = cop_whitelist_enable_disable (a); |
| 85 | |
| 86 | BAD_SW_IF_INDEX_LABEL; |
| 87 | |
| 88 | REPLY_MACRO (VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY); |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * cop_api_hookup |
| 93 | * Add vpe's API message handlers to the table. |
Jim Thompson | f324dec | 2019-04-08 03:22:21 -0500 | [diff] [blame] | 94 | * vlib has already mapped shared memory and |
Pavel Kotucek | 884cf26 | 2017-01-25 08:27:15 +0100 | [diff] [blame] | 95 | * added the client registration handlers. |
| 96 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 97 | */ |
| 98 | #define vl_msg_name_crc_list |
| 99 | #include <vnet/vnet_all_api_h.h> |
| 100 | #undef vl_msg_name_crc_list |
| 101 | |
| 102 | static void |
| 103 | setup_message_id_table (api_main_t * am) |
| 104 | { |
| 105 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 106 | foreach_vl_msg_name_crc_cop; |
| 107 | #undef _ |
| 108 | } |
| 109 | |
| 110 | static clib_error_t * |
| 111 | cop_api_hookup (vlib_main_t * vm) |
| 112 | { |
| 113 | api_main_t *am = &api_main; |
| 114 | |
| 115 | #define _(N,n) \ |
| 116 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 117 | vl_api_##n##_t_handler, \ |
| 118 | vl_noop_handler, \ |
| 119 | vl_api_##n##_t_endian, \ |
| 120 | vl_api_##n##_t_print, \ |
| 121 | sizeof(vl_api_##n##_t), 1); |
| 122 | foreach_vpe_api_msg; |
| 123 | #undef _ |
| 124 | |
| 125 | /* |
| 126 | * Set up the (msg_name, crc, message-id) table |
| 127 | */ |
| 128 | setup_message_id_table (am); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | VLIB_API_INIT_FUNCTION (cop_api_hookup); |
| 134 | |
| 135 | /* |
| 136 | * fd.io coding-style-patch-verification: ON |
| 137 | * |
| 138 | * Local Variables: |
| 139 | * eval: (c-set-style "gnu") |
| 140 | * End: |
| 141 | */ |