Pavel Kotucek | 8b2b794 | 2016-12-20 14:05:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * netmap_api.c - netmap 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/devices/netmap/netmap.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 | _(NETMAP_CREATE, netmap_create) \ |
| 47 | _(NETMAP_DELETE, netmap_delete) \ |
| 48 | |
| 49 | static void |
| 50 | vl_api_netmap_create_t_handler (vl_api_netmap_create_t * mp) |
| 51 | { |
| 52 | vlib_main_t *vm = vlib_get_main (); |
| 53 | vl_api_netmap_create_reply_t *rmp; |
| 54 | int rv = 0; |
| 55 | u8 *if_name = NULL; |
| 56 | |
| 57 | if_name = format (0, "%s", mp->netmap_if_name); |
| 58 | vec_add1 (if_name, 0); |
| 59 | |
| 60 | rv = |
| 61 | netmap_create_if (vm, if_name, mp->use_random_hw_addr ? 0 : mp->hw_addr, |
| 62 | mp->is_pipe, mp->is_master, 0); |
| 63 | |
| 64 | vec_free (if_name); |
| 65 | |
| 66 | REPLY_MACRO (VL_API_NETMAP_CREATE_REPLY); |
| 67 | } |
| 68 | |
| 69 | static void |
| 70 | vl_api_netmap_delete_t_handler (vl_api_netmap_delete_t * mp) |
| 71 | { |
| 72 | vlib_main_t *vm = vlib_get_main (); |
| 73 | vl_api_netmap_delete_reply_t *rmp; |
| 74 | int rv = 0; |
| 75 | u8 *if_name = NULL; |
| 76 | |
| 77 | if_name = format (0, "%s", mp->netmap_if_name); |
| 78 | vec_add1 (if_name, 0); |
| 79 | |
| 80 | rv = netmap_delete_if (vm, if_name); |
| 81 | |
| 82 | vec_free (if_name); |
| 83 | |
| 84 | REPLY_MACRO (VL_API_NETMAP_DELETE_REPLY); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * netmap_api_hookup |
| 89 | * Add vpe's API message handlers to the table. |
Jim Thompson | f324dec | 2019-04-08 03:22:21 -0500 | [diff] [blame] | 90 | * vlib has already mapped shared memory and |
Pavel Kotucek | 8b2b794 | 2016-12-20 14:05:46 +0100 | [diff] [blame] | 91 | * added the client registration handlers. |
| 92 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 93 | */ |
| 94 | #define vl_msg_name_crc_list |
| 95 | #include <vnet/vnet_all_api_h.h> |
| 96 | #undef vl_msg_name_crc_list |
| 97 | |
| 98 | static void |
| 99 | setup_message_id_table (api_main_t * am) |
| 100 | { |
| 101 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 102 | foreach_vl_msg_name_crc_netmap; |
| 103 | #undef _ |
| 104 | } |
| 105 | |
| 106 | static clib_error_t * |
| 107 | netmap_api_hookup (vlib_main_t * vm) |
| 108 | { |
| 109 | api_main_t *am = &api_main; |
| 110 | |
| 111 | #define _(N,n) \ |
| 112 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 113 | vl_api_##n##_t_handler, \ |
| 114 | vl_noop_handler, \ |
| 115 | vl_api_##n##_t_endian, \ |
| 116 | vl_api_##n##_t_print, \ |
| 117 | sizeof(vl_api_##n##_t), 1); |
| 118 | foreach_vpe_api_msg; |
| 119 | #undef _ |
| 120 | |
| 121 | /* |
| 122 | * Set up the (msg_name, crc, message-id) table |
| 123 | */ |
| 124 | setup_message_id_table (am); |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | VLIB_API_INIT_FUNCTION (netmap_api_hookup); |
| 130 | |
| 131 | /* |
| 132 | * fd.io coding-style-patch-verification: ON |
| 133 | * |
| 134 | * Local Variables: |
| 135 | * eval: (c-set-style "gnu") |
| 136 | * End: |
| 137 | */ |