FD.io VPP  v21.01.1
Vector Packet Processing
arp_api.c
Go to the documentation of this file.
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  */
37 #define REPLY_MSG_ID_BASE arp_base_msg_id
38 
40 
41 static void
43 {
44  vl_api_proxy_arp_add_del_reply_t *rmp;
46  u32 fib_index;
47  int rv;
48 
49  fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->proxy.table_id));
50 
51  if (~0 == fib_index)
52  {
53  rv = VNET_API_ERROR_NO_SUCH_FIB;
54  goto out;
55  }
56 
57  ip4_address_decode (mp->proxy.low, &lo);
58  ip4_address_decode (mp->proxy.hi, &hi);
59 
60  if (mp->is_add)
61  rv = arp_proxy_add (fib_index, &lo, &hi);
62  else
63  rv = arp_proxy_del (fib_index, &lo, &hi);
64 
65 out:
66  REPLY_MACRO (VL_API_PROXY_ARP_ADD_DEL_REPLY);
67 }
68 
69 typedef struct proxy_arp_walk_ctx_t_
70 {
74 
75 static walk_rc_t
77  const ip4_address_t * hi_addr,
78  u32 fib_index, void *data)
79 {
82 
83  ctx = data;
84 
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);
90 
91  ip4_address_encode (lo_addr, mp->proxy.low);
92  ip4_address_encode (hi_addr, mp->proxy.hi);
93 
94  vl_api_send_msg (ctx->reg, (u8 *) mp);
95 
96  return (WALK_CONTINUE);
97 }
98 
99 static void
101 {
103 
105  if (!reg)
106  return;
107 
108  proxy_arp_walk_ctx_t wctx = {
109  .reg = reg,
110  .context = mp->context,
111  };
112 
114 }
115 
116 static walk_rc_t
118 {
121 
122  ctx = data;
123 
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);
129 
130  vl_api_send_msg (ctx->reg, (u8 *) mp);
131 
132  return (WALK_CONTINUE);
133 }
134 
135 static void
137 {
139 
141  if (!reg)
142  return;
143 
144  proxy_arp_walk_ctx_t wctx = {
145  .reg = reg,
146  .context = mp->context,
147  };
148 
150 }
151 
152 static void
155 {
156  vl_api_proxy_arp_intfc_enable_disable_reply_t *rmp;
157  int rv;
158 
160 
161  if (mp->enable)
162  rv = arp_proxy_enable (ntohl (mp->sw_if_index));
163  else
164  rv = arp_proxy_disable (ntohl (mp->sw_if_index));
165 
167 
168  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 *
175 {
176  /* Ask for a correctly-sized block of API message decode slots */
177  arp_base_msg_id = setup_message_id_table ();
178 
179  return 0;
180 }
181 
183 
184 /*
185  * fd.io coding-style-patch-verification: ON
186  *
187  * Local Variables:
188  * eval: (c-set-style "gnu")
189  * End:
190  */
Proxy ARP add / del request.
Definition: arp.api:46
vl_api_proxy_arp_t proxy
Definition: arp.api:51
vl_api_proxy_arp_t proxy
Definition: arp.api:68
#define ntohs(x)
Definition: af_xdp.bpf.c:29
Proxy ARP interface dump request.
Definition: arp.api:87
#define REPLY_MSG_ID_BASE
Definition: arp_api.c:37
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
static clib_error_t * arp_api_init(vlib_main_t *vm)
Definition: arp_api.c:174
vlib_main_t * vm
Definition: in2out_ed.c:1580
static void vl_api_proxy_arp_dump_t_handler(vl_api_proxy_arp_dump_t *mp)
Definition: arp_api.c:100
int arp_proxy_del(u32 fib_index, const ip4_address_t *lo_addr, const ip4_address_t *hi_addr)
Definition: arp_proxy.c:134
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
u8 data[128]
Definition: ipsec_types.api:90
enum walk_rc_t_ walk_rc_t
Walk return code.
Proxy ARP add / del interface request.
Definition: arp.api:77
void proxy_arp_intfc_walk(proxy_arp_intf_walk_t cb, void *data)
Definition: arp_proxy.c:141
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
static void vl_api_proxy_arp_intfc_enable_disable_t_handler(vl_api_proxy_arp_intfc_enable_disable_t *mp)
Definition: arp_api.c:154
unsigned int u32
Definition: types.h:88
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1106
int arp_proxy_add(u32 fib_index, const ip4_address_t *lo_addr, const ip4_address_t *hi_addr)
Definition: arp_proxy.c:127
lo
long ctx[MAX_CONNS]
Definition: main.c:144
static u32 arp_base_msg_id
Base message ID fot the plugin.
Definition: arp_api.c:36
#define REPLY_MACRO(t)
Proxy ARP dump details reply.
Definition: arp.api:65
vl_api_interface_index_t sw_if_index
Definition: arp.api:81
static walk_rc_t send_proxy_arp_intfc_details(u32 sw_if_index, void *data)
Definition: arp_api.c:117
int arp_proxy_disable(u32 sw_if_index)
Definition: arp_proxy.c:55
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
vl_api_registration_t * reg
Definition: arp_api.c:71
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:409
#define BAD_SW_IF_INDEX_LABEL
Proxy ARP interface dump details reply.
Definition: arp.api:96
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
struct proxy_arp_walk_ctx_t_ proxy_arp_walk_ctx_t
int arp_proxy_enable(u32 sw_if_index)
Definition: arp_proxy.c:72
vl_api_ip4_address_t hi
Definition: arp.api:37
void ip4_address_decode(const vl_api_ip4_address_t in, ip4_address_t *out)
Definition: ip_types_api.c:155
Proxy ARP dump request.
Definition: arp.api:56
static void vl_api_proxy_arp_intfc_dump_t_handler(vl_api_proxy_arp_intfc_dump_t *mp)
Definition: arp_api.c:136
void ip4_address_encode(const ip4_address_t *in, vl_api_ip4_address_t out)
Definition: ip_types_api.c:149
static void vl_api_proxy_arp_add_del_t_handler(vl_api_proxy_arp_add_del_t *mp)
Definition: arp_api.c:42
void proxy_arp_walk(proxy_arp_walk_t cb, void *data)
Definition: arp_proxy.c:42
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
#define VALIDATE_SW_IF_INDEX(mp)
static walk_rc_t send_proxy_arp_details(const ip4_address_t *lo_addr, const ip4_address_t *hi_addr, u32 fib_index, void *data)
Definition: arp_api.c:76