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 *------------------------------------------------------------------
21 #ifndef __api_helper_macros_h__
22 #define __api_helper_macros_h__
25 #define f64_print(a,b)
27 #define REPLY_MACRO(t) \
29 unix_shared_memory_queue_t * q; \
30 rv = vl_msg_api_pd_handler (mp, rv); \
31 q = vl_api_client_index_to_input_queue (mp->client_index); \
35 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
36 rmp->_vl_msg_id = ntohs((t)); \
37 rmp->context = mp->context; \
38 rmp->retval = ntohl(rv); \
40 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
43 #define REPLY_MACRO2(t, body) \
45 unix_shared_memory_queue_t * q; \
46 rv = vl_msg_api_pd_handler (mp, rv); \
47 q = vl_api_client_index_to_input_queue (mp->client_index); \
51 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
52 rmp->_vl_msg_id = ntohs((t)); \
53 rmp->context = mp->context; \
54 rmp->retval = ntohl(rv); \
55 do {body;} while (0); \
56 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
59 #define REPLY_MACRO3(t, n, body) \
61 unix_shared_memory_queue_t * q; \
62 rv = vl_msg_api_pd_handler (mp, rv); \
63 q = vl_api_client_index_to_input_queue (mp->client_index); \
67 rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \
68 rmp->_vl_msg_id = ntohs((t)); \
69 rmp->context = mp->context; \
70 rmp->retval = ntohl(rv); \
71 do {body;} while (0); \
72 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
75 #define REPLY_MACRO4(t, n, body) \
77 unix_shared_memory_queue_t * q; \
79 rv = vl_msg_api_pd_handler (mp, rv); \
80 q = vl_api_client_index_to_input_queue (mp->client_index); \
84 rmp = vl_msg_api_alloc_or_null (sizeof (*rmp) + n); \
87 /* if there isn't enough memory, try to allocate */ \
88 /* some at least for returning an error */ \
89 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
93 memset (rmp, 0, sizeof (*rmp)); \
94 rv = VNET_API_ERROR_TABLE_TOO_BIG; \
97 rmp->_vl_msg_id = ntohs((t)); \
98 rmp->context = mp->context; \
99 rmp->retval = ntohl(rv); \
101 do {body;} while (0); \
102 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
105 /* "trust, but verify" */
107 #define VALIDATE_SW_IF_INDEX(mp) \
108 do { u32 __sw_if_index = ntohl(mp->sw_if_index); \
109 vnet_main_t *__vnm = vnet_get_main(); \
110 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
112 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
113 goto bad_sw_if_index; \
117 #define BAD_SW_IF_INDEX_LABEL \
123 #define VALIDATE_RX_SW_IF_INDEX(mp) \
124 do { u32 __rx_sw_if_index = ntohl(mp->rx_sw_if_index); \
125 vnet_main_t *__vnm = vnet_get_main(); \
126 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
127 __rx_sw_if_index)) { \
128 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
129 goto bad_rx_sw_if_index; \
133 #define BAD_RX_SW_IF_INDEX_LABEL \
135 bad_rx_sw_if_index: \
139 #define VALIDATE_TX_SW_IF_INDEX(mp) \
140 do { u32 __tx_sw_if_index = ntohl(mp->tx_sw_if_index); \
141 vnet_main_t *__vnm = vnet_get_main(); \
142 if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \
143 __tx_sw_if_index)) { \
144 rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \
145 goto bad_tx_sw_if_index; \
149 #define BAD_TX_SW_IF_INDEX_LABEL \
151 bad_tx_sw_if_index: \
155 #endif /* __api_helper_macros_h__ */
158 * fd.io coding-style-patch-verification: ON
161 * eval: (c-set-style "gnu")