2 *------------------------------------------------------------------
3 * api_helper_macros.h - message handler helper macros
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #ifndef __api_helper_macros_h__
21 #define __api_helper_macros_h__
24 #define f64_print(a,b)
26 #define REPLY_MACRO(t) \
28 unix_shared_memory_queue_t * q; \
29 rv = vl_msg_api_pd_handler (mp, rv); \
30 q = vl_api_client_index_to_input_queue (mp->client_index); \
34 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
35 rmp->_vl_msg_id = ntohs((t)); \
36 rmp->context = mp->context; \
37 rmp->retval = ntohl(rv); \
39 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
42 #define REPLY_MACRO2(t, body) \
44 unix_shared_memory_queue_t * q; \
45 rv = vl_msg_api_pd_handler (mp, rv); \
46 q = vl_api_client_index_to_input_queue (mp->client_index); \
50 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
51 rmp->_vl_msg_id = ntohs((t)); \
52 rmp->context = mp->context; \
53 rmp->retval = ntohl(rv); \
54 do {body;} while (0); \
55 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
58 #define REPLY_MACRO3(t, n, body) \
60 unix_shared_memory_queue_t * q; \
61 rv = vl_msg_api_pd_handler (mp, rv); \
62 q = vl_api_client_index_to_input_queue (mp->client_index); \
66 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
67 rmp->_vl_msg_id = ntohs((t)); \
68 rmp->context = mp->context; \
69 rmp->retval = ntohl(rv); \
70 do {body;} while (0); \
71 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
74 #define REPLY_MACRO4(t, n, body) \
76 unix_shared_memory_queue_t * q; \
78 rv = vl_msg_api_pd_handler (mp, rv); \
79 q = vl_api_client_index_to_input_queue (mp->client_index); \
83 rmp = vl_msg_api_alloc_or_null (sizeof (*rmp) + n); \
86 /* if there isn't enough memory, try to allocate */ \
87 /* some at least for returning an error */ \
88 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
92 memset (rmp, 0, sizeof (*rmp)); \
93 rv = VNET_API_ERROR_TABLE_TOO_BIG; \
96 rmp->_vl_msg_id = ntohs((t)); \
97 rmp->context = mp->context; \
98 rmp->retval = ntohl(rv); \
100 do {body;} while (0); \
101 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
104 /* "trust, but verify" */
106 #define VALIDATE_SW_IF_INDEX(mp) \
107 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
108 vnet_main_t *__vnm = vnet_get_main(); \
109 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
111 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
112 goto bad_sw_if_index; \
116 #define BAD_SW_IF_INDEX_LABEL \
122 #define VALIDATE_RX_SW_IF_INDEX(mp) \
123 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
124 vnet_main_t *__vnm = vnet_get_main(); \
125 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
126 __rx_sw_if_index)) { \
127 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
128 goto bad_rx_sw_if_index; \
132 #define BAD_RX_SW_IF_INDEX_LABEL \
134 bad_rx_sw_if_index: \
138 #define VALIDATE_TX_SW_IF_INDEX(mp) \
139 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
140 vnet_main_t *__vnm = vnet_get_main(); \
141 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
142 __tx_sw_if_index)) { \
143 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
144 goto bad_tx_sw_if_index; \
148 #define BAD_TX_SW_IF_INDEX_LABEL \
150 bad_tx_sw_if_index: \
154 #define pub_sub_handler(lca,UCA) \
155 static void vl_api_want_##lca##_t_handler ( \
156 vl_api_want_##lca##_t *mp) \
158 vpe_api_main_t *vam = &vpe_api_main; \
159 vpe_client_registration_t *rp; \
160 vl_api_want_##lca##_reply_t *rmp; \
164 p = hash_get (vam->lca##_registration_hash, mp->client_index); \
166 if (mp->enable_disable) { \
167 clib_warning ("pid %d: already enabled...", mp->pid); \
168 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
171 rp = pool_elt_at_index (vam->lca##_registrations, p[0]); \
172 pool_put (vam->lca##_registrations, rp); \
173 hash_unset (vam->lca##_registration_hash, \
178 if (mp->enable_disable == 0) { \
179 clib_warning ("pid %d: already disabled...", mp->pid); \
180 rv = VNET_API_ERROR_INVALID_REGISTRATION; \
183 pool_get (vam->lca##_registrations, rp); \
184 rp->client_index = mp->client_index; \
185 rp->client_pid = mp->pid; \
186 hash_set (vam->lca##_registration_hash, rp->client_index, \
187 rp - vam->lca##_registrations); \
190 REPLY_MACRO (VL_API_WANT_##UCA##_REPLY); \
193 #define foreach_registration_hash \
194 _(interface_events) \
195 _(to_netconf_server) \
196 _(from_netconf_server) \
197 _(to_netconf_client) \
198 _(from_netconf_client) \
202 /* WARNING: replicated in vpp/stats.h */
205 u32 client_index; /* in memclnt registration pool */
207 } vpe_client_registration_t;
209 struct _vl_api_ip4_arp_event;
210 struct _vl_api_ip6_nd_event;
214 #define _(a) uword *a##_registration_hash; \
215 vpe_client_registration_t * a##_registrations;
216 foreach_registration_hash
218 /* notifications happen really early in the game */
219 u8 link_state_process_up;
221 /* ip4 arp event registration pool */
222 struct _vl_api_ip4_arp_event *arp_events;
224 /* ip6 nd event registration pool */
225 struct _vl_api_ip6_nd_event *nd_events;
228 vlib_main_t *vlib_main;
229 vnet_main_t *vnet_main;
232 extern vpe_api_main_t vpe_api_main;
234 #endif /* __api_helper_macros_h__ */
237 * fd.io coding-style-patch-verification: ON
240 * eval: (c-set-style "gnu")