FD.io VPP  v21.10.1-2-g0a485f517
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 */
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  */
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
api.h
arp_proxy_add
int arp_proxy_add(u32 fib_index, const ip4_address_t *lo_addr, const ip4_address_t *hi_addr)
Definition: arp_proxy.c:127
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
vl_api_proxy_arp_add_del_t
Proxy ARP add / del request.
Definition: arp.api:46
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
ip4_address_decode
void ip4_address_decode(const vl_api_ip4_address_t in, ip4_address_t *out)
Definition: ip_types_api.c:141
arp_proxy_del
int arp_proxy_del(u32 fib_index, const ip4_address_t *lo_addr, const ip4_address_t *hi_addr)
Definition: arp_proxy.c:134
vl_api_proxy_arp_intfc_enable_disable_t_handler
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
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vl_api_proxy_arp_add_del_t::is_add
bool is_add
Definition: arp.api:50
send_proxy_arp_details
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
proxy_arp_walk
void proxy_arp_walk(proxy_arp_walk_t cb, void *data)
Definition: arp_proxy.c:42
fib_table.h
proxy_arp_walk_ctx_t_
Definition: arp_api.c:69
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
proxy_arp_walk_ctx_t_::context
u32 context
Definition: arp_api.c:72
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
arp_base_msg_id
static u32 arp_base_msg_id
Base message ID fot the plugin.
Definition: arp_api.c:36
vl_api_proxy_arp_intfc_enable_disable_t
Proxy ARP add / del interface request.
Definition: arp.api:77
vl_api_proxy_arp_intfc_details_t::context
u32 context
Definition: arp.api:98
vl_api_proxy_arp_intfc_enable_disable_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: arp.api:81
arp_api_init
static clib_error_t * arp_api_init(vlib_main_t *vm)
Definition: arp_api.c:174
vl_api_proxy_arp_dump_t_handler
static void vl_api_proxy_arp_dump_t_handler(vl_api_proxy_arp_dump_t *mp)
Definition: arp_api.c:100
vl_api_proxy_arp_intfc_details_t
Proxy ARP interface dump details reply.
Definition: arp.api:96
arp_proxy_disable
int arp_proxy_disable(u32 sw_if_index)
Definition: arp_proxy.c:55
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
vl_api_proxy_arp_dump_t
Proxy ARP dump request.
Definition: arp.api:56
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
arp_proxy_enable
int arp_proxy_enable(u32 sw_if_index)
Definition: arp_proxy.c:72
vl_api_proxy_arp_intfc_dump_t
Proxy ARP interface dump request.
Definition: arp.api:87
vl_api_proxy_arp_details_t::context
u32 context
Definition: arp.api:67
ip4_address_t
Definition: ip4_packet.h:50
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
proxy_arp_walk_ctx_t_::reg
vl_api_registration_t * reg
Definition: arp_api.c:71
proxy_arp_walk_ctx_t
struct proxy_arp_walk_ctx_t_ proxy_arp_walk_ctx_t
vl_api_proxy_arp_intfc_dump_t::context
u32 context
Definition: arp.api:90
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
data
u8 data[128]
Definition: ipsec_types.api:95
vl_api_proxy_arp_details_t::proxy
vl_api_proxy_arp_t proxy
Definition: arp.api:68
vl_api_proxy_arp_add_del_t::proxy
vl_api_proxy_arp_t proxy
Definition: arp.api:51
proxy_arp_intfc_walk
void proxy_arp_intfc_walk(proxy_arp_intf_walk_t cb, void *data)
Definition: arp_proxy.c:141
vl_api_proxy_arp_dump_t::client_index
u32 client_index
Definition: arp.api:58
format_fns.h
vl_api_proxy_arp_add_del_t_handler
static void vl_api_proxy_arp_add_del_t_handler(vl_api_proxy_arp_add_del_t *mp)
Definition: arp_api.c:42
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
send_proxy_arp_intfc_details
static walk_rc_t send_proxy_arp_intfc_details(u32 sw_if_index, void *data)
Definition: arp_api.c:117
api_helper_macros.h
vl_api_proxy_arp_intfc_dump_t_handler
static void vl_api_proxy_arp_intfc_dump_t_handler(vl_api_proxy_arp_intfc_dump_t *mp)
Definition: arp_api.c:136
ip4_address_encode
void ip4_address_encode(const ip4_address_t *in, vl_api_ip4_address_t out)
Definition: ip_types_api.c:135
vl_api_proxy_arp_intfc_dump_t::client_index
u32 client_index
Definition: arp.api:89
vl_api_proxy_arp_intfc_details_t::sw_if_index
u32 sw_if_index
Definition: arp.api:99
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vl_api_proxy_arp_details_t
Proxy ARP dump details reply.
Definition: arp.api:65
rv
int __clib_unused rv
Definition: application.c:491
fib_table_find
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:1111
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ip_types_api.h
arp.h
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
lo
lo
Definition: vector_altivec.h:87
vl_api_proxy_arp_dump_t::context
u32 context
Definition: arp.api:59
REPLY_MSG_ID_BASE
#define REPLY_MSG_ID_BASE
Definition: arp_api.c:37
vl_api_proxy_arp_intfc_enable_disable_t::enable
bool enable
Definition: arp.api:82
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199