Line data Source code
1 : /* 2 : * Copyright (c) 2016 Cisco and/or its affiliates. 3 : * Licensed under the Apache License, Version 2.0 (the "License"); 4 : * you may not use this file except in compliance with the License. 5 : * You may obtain a copy of the License at: 6 : * 7 : * http://www.apache.org/licenses/LICENSE-2.0 8 : * 9 : * Unless required by applicable law or agreed to in writing, software 10 : * distributed under the License is distributed on an "AS IS" BASIS, 11 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : * See the License for the specific language governing permissions and 13 : * limitations under the License. 14 : */ 15 : 16 : #include <stddef.h> 17 : 18 : #include <vnet/arp/arp.h> 19 : 20 : #include <vnet/fib/fib_table.h> 21 : #include <vnet/ip/ip_types_api.h> 22 : 23 : #include <vpp/app/version.h> 24 : 25 : #include <vlibapi/api.h> 26 : #include <vlibmemory/api.h> 27 : 28 : /* define message IDs */ 29 : #include <vnet/format_fns.h> 30 : #include <vnet/arp/arp.api_enum.h> 31 : #include <vnet/arp/arp.api_types.h> 32 : 33 : /** 34 : * Base message ID fot the plugin 35 : */ 36 : static u32 arp_base_msg_id; 37 : #define REPLY_MSG_ID_BASE arp_base_msg_id 38 : 39 : #include <vlibapi/api_helper_macros.h> 40 : 41 : static void 42 3 : vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp) 43 : { 44 : vl_api_proxy_arp_add_del_reply_t *rmp; 45 : ip4_address_t lo, hi; 46 : u32 fib_index; 47 : int rv; 48 : 49 3 : fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->proxy.table_id)); 50 : 51 3 : if (~0 == fib_index) 52 : { 53 0 : rv = VNET_API_ERROR_NO_SUCH_FIB; 54 0 : goto out; 55 : } 56 : 57 3 : ip4_address_decode (mp->proxy.low, &lo); 58 3 : ip4_address_decode (mp->proxy.hi, &hi); 59 : 60 3 : if (mp->is_add) 61 2 : rv = arp_proxy_add (fib_index, &lo, &hi); 62 : else 63 1 : rv = arp_proxy_del (fib_index, &lo, &hi); 64 : 65 3 : out: 66 3 : REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY); 67 : } 68 : 69 : typedef struct proxy_arp_walk_ctx_t_ 70 : { 71 : vl_api_registration_t *reg; 72 : u32 context; 73 : } proxy_arp_walk_ctx_t; 74 : 75 : static walk_rc_t 76 0 : send_proxy_arp_details (const ip4_address_t * lo_addr, 77 : const ip4_address_t * hi_addr, 78 : u32 fib_index, void *data) 79 : { 80 : vl_api_proxy_arp_details_t *mp; 81 : proxy_arp_walk_ctx_t *ctx; 82 : 83 0 : ctx = data; 84 : 85 0 : mp = vl_msg_api_alloc (sizeof (*mp)); 86 0 : clib_memset (mp, 0, sizeof (*mp)); 87 0 : mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_DETAILS + REPLY_MSG_ID_BASE); 88 0 : mp->context = ctx->context; 89 0 : mp->proxy.table_id = htonl (fib_index); 90 : 91 0 : ip4_address_encode (lo_addr, mp->proxy.low); 92 0 : ip4_address_encode (hi_addr, mp->proxy.hi); 93 : 94 0 : vl_api_send_msg (ctx->reg, (u8 *) mp); 95 : 96 0 : return (WALK_CONTINUE); 97 : } 98 : 99 : static void 100 0 : vl_api_proxy_arp_dump_t_handler (vl_api_proxy_arp_dump_t * mp) 101 : { 102 : vl_api_registration_t *reg; 103 : 104 0 : reg = vl_api_client_index_to_registration (mp->client_index); 105 0 : if (!reg) 106 0 : return; 107 : 108 0 : proxy_arp_walk_ctx_t wctx = { 109 : .reg = reg, 110 0 : .context = mp->context, 111 : }; 112 : 113 0 : proxy_arp_walk (send_proxy_arp_details, &wctx); 114 : } 115 : 116 : static walk_rc_t 117 0 : send_proxy_arp_intfc_details (u32 sw_if_index, void *data) 118 : { 119 : vl_api_proxy_arp_intfc_details_t *mp; 120 : proxy_arp_walk_ctx_t *ctx; 121 : 122 0 : ctx = data; 123 : 124 0 : mp = vl_msg_api_alloc (sizeof (*mp)); 125 0 : clib_memset (mp, 0, sizeof (*mp)); 126 0 : mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_INTFC_DETAILS + REPLY_MSG_ID_BASE); 127 0 : mp->context = ctx->context; 128 0 : mp->sw_if_index = htonl (sw_if_index); 129 : 130 0 : vl_api_send_msg (ctx->reg, (u8 *) mp); 131 : 132 0 : return (WALK_CONTINUE); 133 : } 134 : 135 : static void 136 0 : vl_api_proxy_arp_intfc_dump_t_handler (vl_api_proxy_arp_intfc_dump_t * mp) 137 : { 138 : vl_api_registration_t *reg; 139 : 140 0 : reg = vl_api_client_index_to_registration (mp->client_index); 141 0 : if (!reg) 142 0 : return; 143 : 144 0 : proxy_arp_walk_ctx_t wctx = { 145 : .reg = reg, 146 0 : .context = mp->context, 147 : }; 148 : 149 0 : proxy_arp_intfc_walk (send_proxy_arp_intfc_details, &wctx); 150 : } 151 : 152 : static void 153 9 : vl_api_proxy_arp_intfc_enable_disable_t_handler 154 : (vl_api_proxy_arp_intfc_enable_disable_t * mp) 155 : { 156 : vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp; 157 : int rv; 158 : 159 9 : VALIDATE_SW_IF_INDEX (mp); 160 : 161 9 : if (mp->enable) 162 5 : rv = arp_proxy_enable (ntohl (mp->sw_if_index)); 163 : else 164 4 : rv = arp_proxy_disable (ntohl (mp->sw_if_index)); 165 : 166 9 : BAD_SW_IF_INDEX_LABEL; 167 : 168 9 : REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY); 169 : } 170 : 171 : #include <vnet/arp/arp.api.c> 172 : 173 : static clib_error_t * 174 559 : arp_api_init (vlib_main_t * vm) 175 : { 176 : /* Ask for a correctly-sized block of API message decode slots */ 177 559 : arp_base_msg_id = setup_message_id_table (); 178 : 179 559 : return 0; 180 : } 181 : 182 93519 : VLIB_INIT_FUNCTION (arp_api_init); 183 : 184 : /* 185 : * fd.io coding-style-patch-verification: ON 186 : * 187 : * Local Variables: 188 : * eval: (c-set-style "gnu") 189 : * End: 190 : */