Line data Source code
1 : /* 2 : *------------------------------------------------------------------ 3 : * Copyright (c) 2021 Cisco and/or its affiliates. 4 : * Licensed under the Apache License, Version 2.0 (the "License"); 5 : * you may not use this file except in compliance with the License. 6 : * You may obtain a copy of the License at: 7 : * 8 : * http://www.apache.org/licenses/LICENSE-2.0 9 : * 10 : * Unless required by applicable law or agreed to in writing, software 11 : * distributed under the License is distributed on an "AS IS" BASIS, 12 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 : * See the License for the specific language governing permissions and 14 : * limitations under the License. 15 : *------------------------------------------------------------------ 16 : */ 17 : 18 : #include <vlib/vlib.h> 19 : #include <vlib/unix/unix.h> 20 : #include <vlib/pci/pci.h> 21 : #include <vnet/ethernet/ethernet.h> 22 : #include <vnet/format_fns.h> 23 : #include <vnet/ip/ip_types_api.h> 24 : 25 : #include <arping/arping.h> 26 : 27 : #include <vlibapi/api.h> 28 : #include <vlibmemory/api.h> 29 : #include <vnet/ethernet/ethernet_types_api.h> 30 : 31 : /* define message IDs */ 32 : #include <arping/arping.api_enum.h> 33 : #include <arping/arping.api_types.h> 34 : 35 : #define REPLY_MSG_ID_BASE (am->msg_id_base) 36 : #include <vlibapi/api_helper_macros.h> 37 : 38 : static void 39 8 : vl_api_arping_t_handler (vl_api_arping_t *mp) 40 : { 41 8 : vlib_main_t *vm = vlib_get_main (); 42 8 : arping_main_t *am = &arping_main; 43 : vl_api_arping_reply_t *rmp; 44 8 : arping_args_t args = { 0 }; 45 : int rv; 46 : 47 8 : if (mp->sw_if_index != ~0) 48 8 : VALIDATE_SW_IF_INDEX (mp); 49 : 50 8 : ip_address_decode2 (&mp->address, &args.address); 51 8 : args.interval = clib_net_to_host_f64 (mp->interval); 52 8 : args.repeat = ntohl (mp->repeat); 53 8 : args.is_garp = mp->is_garp; 54 8 : args.sw_if_index = ntohl (mp->sw_if_index); 55 8 : args.silence = 1; 56 : 57 8 : arping_run_command (vm, &args); 58 8 : rv = args.rv; 59 : 60 8 : BAD_SW_IF_INDEX_LABEL; 61 : 62 8 : REPLY_MACRO2 (VL_API_ARPING_REPLY, 63 : ({ rmp->reply_count = ntohl (args.reply_count); })); 64 : } 65 : 66 : static void 67 0 : vl_api_arping_acd_t_handler (vl_api_arping_acd_t *mp) 68 : { 69 0 : vlib_main_t *vm = vlib_get_main (); 70 0 : arping_main_t *am = &arping_main; 71 : vl_api_arping_acd_reply_t *rmp; 72 0 : arping_args_t args = { 0 }; 73 : int rv; 74 : 75 0 : if (mp->sw_if_index != ~0) 76 0 : VALIDATE_SW_IF_INDEX (mp); 77 : 78 0 : ip_address_decode2 (&mp->address, &args.address); 79 0 : args.interval = clib_net_to_host_f64 (mp->interval); 80 0 : args.repeat = ntohl (mp->repeat); 81 0 : args.is_garp = mp->is_garp; 82 0 : args.sw_if_index = ntohl (mp->sw_if_index); 83 0 : args.silence = 1; 84 : 85 0 : arping_run_command (vm, &args); 86 0 : rv = args.rv; 87 : 88 0 : BAD_SW_IF_INDEX_LABEL; 89 : 90 0 : REPLY_MACRO2 (VL_API_ARPING_ACD_REPLY, ({ 91 : rmp->reply_count = ntohl (args.reply_count); 92 : mac_address_encode (&args.recv.from4.mac, rmp->mac_address); 93 : })); 94 : } 95 : 96 : /* set tup the API message handling tables */ 97 : #include <arping/arping.api.c> 98 : clib_error_t * 99 575 : arping_plugin_api_hookup (vlib_main_t *vm) 100 : { 101 575 : arping_main_t *am = &arping_main; 102 575 : api_main_t *vam = vlibapi_get_main (); 103 : 104 : /* ask for a correctly-sized block of API message decode slots */ 105 575 : am->msg_id_base = setup_message_id_table (); 106 : 107 : /* Mark API as mp safe */ 108 575 : vl_api_set_msg_thread_safe (vam, am->msg_id_base + VL_API_ARPING, 1); 109 575 : vl_api_set_msg_thread_safe (vam, am->msg_id_base + VL_API_ARPING_ACD, 1); 110 : 111 575 : return 0; 112 : } 113 : 114 : /* 115 : * fd.io coding-style-patch-verification: ON 116 : * 117 : * Local Variables: 118 : * eval: (c-set-style "gnu") 119 : * End: 120 : */