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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <vnet/arp/arp.h>
20 #include <vnet/fib/fib_table.h>
21 #include <vnet/ip/ip_types_api.h>
23 #include <vpp/app/version.h>
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
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>
34 * Base message ID fot the plugin
36 static u32 arp_base_msg_id;
37 #define REPLY_MSG_ID_BASE arp_base_msg_id
39 #include <vlibapi/api_helper_macros.h>
42 vl_api_proxy_arp_add_del_t_handler (vl_api_proxy_arp_add_del_t * mp)
44 vl_api_proxy_arp_add_del_reply_t *rmp;
49 fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->proxy.table_id));
53 rv = VNET_API_ERROR_NO_SUCH_FIB;
57 ip4_address_decode (mp->proxy.low, &lo);
58 ip4_address_decode (mp->proxy.hi, &hi);
61 rv = arp_proxy_add (fib_index, &lo, &hi);
63 rv = arp_proxy_del (fib_index, &lo, &hi);
66 REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
69 typedef struct proxy_arp_walk_ctx_t_
71 vl_api_registration_t *reg;
73 } proxy_arp_walk_ctx_t;
76 send_proxy_arp_details (const ip4_address_t * lo_addr,
77 const ip4_address_t * hi_addr,
78 u32 fib_index, void *data)
80 vl_api_proxy_arp_details_t *mp;
81 proxy_arp_walk_ctx_t *ctx;
85 mp = vl_msg_api_alloc (sizeof (*mp));
86 clib_memset (mp, 0, sizeof (*mp));
87 mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_DETAILS + REPLY_MSG_ID_BASE);
88 mp->context = ctx->context;
89 mp->proxy.table_id = htonl (fib_index);
91 ip4_address_encode (lo_addr, mp->proxy.low);
92 ip4_address_encode (hi_addr, mp->proxy.hi);
94 vl_api_send_msg (ctx->reg, (u8 *) mp);
96 return (WALK_CONTINUE);
100 vl_api_proxy_arp_dump_t_handler (vl_api_proxy_arp_dump_t * mp)
102 vl_api_registration_t *reg;
104 reg = vl_api_client_index_to_registration (mp->client_index);
108 proxy_arp_walk_ctx_t wctx = {
110 .context = mp->context,
113 proxy_arp_walk (send_proxy_arp_details, &wctx);
117 send_proxy_arp_intfc_details (u32 sw_if_index, void *data)
119 vl_api_proxy_arp_intfc_details_t *mp;
120 proxy_arp_walk_ctx_t *ctx;
124 mp = vl_msg_api_alloc (sizeof (*mp));
125 clib_memset (mp, 0, sizeof (*mp));
126 mp->_vl_msg_id = ntohs (VL_API_PROXY_ARP_INTFC_DETAILS + REPLY_MSG_ID_BASE);
127 mp->context = ctx->context;
128 mp->sw_if_index = htonl (sw_if_index);
130 vl_api_send_msg (ctx->reg, (u8 *) mp);
132 return (WALK_CONTINUE);
136 vl_api_proxy_arp_intfc_dump_t_handler (vl_api_proxy_arp_intfc_dump_t * mp)
138 vl_api_registration_t *reg;
140 reg = vl_api_client_index_to_registration (mp->client_index);
144 proxy_arp_walk_ctx_t wctx = {
146 .context = mp->context,
149 proxy_arp_intfc_walk (send_proxy_arp_intfc_details, &wctx);
153 vl_api_proxy_arp_intfc_enable_disable_t_handler
154 (vl_api_proxy_arp_intfc_enable_disable_t * mp)
156 vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
159 VALIDATE_SW_IF_INDEX (mp);
162 rv = arp_proxy_enable (ntohl (mp->sw_if_index));
164 rv = arp_proxy_disable (ntohl (mp->sw_if_index));
166 BAD_SW_IF_INDEX_LABEL;
168 REPLY_MACRO (VL_API_PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY);
171 #include <vnet/arp/arp.api.c>
173 static clib_error_t *
174 arp_api_init (vlib_main_t * vm)
176 /* Ask for a correctly-sized block of API message decode slots */
177 arp_base_msg_id = setup_message_id_table ();
182 VLIB_INIT_FUNCTION (arp_api_init);
185 * fd.io coding-style-patch-verification: ON
188 * eval: (c-set-style "gnu")