vppapigen: remove support for legacy typedefs
[vpp.git] / src / plugins / acl / manual_fns.h
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 #ifndef included_manual_fns_h
17 #define included_manual_fns_h
18
19 #include <vnet/ip/format.h>
20 #include <vnet/ethernet/ethernet.h>
21
22 /* Macro to finish up custom dump fns */
23 #define PRINT_S \
24     vec_add1 (s, 0);                            \
25     vl_print (handle, (char *)s);               \
26     vec_free (s);
27
28 static inline void
29 vl_api_acl_rule_t_array_endian(vl_api_acl_rule_t *rules, u32 count)
30 {
31   u32 i;
32   for(i=0; i<count; i++) {
33     vl_api_acl_rule_t_endian (&rules[i]);
34   }
35 }
36
37 static inline void
38 vl_api_macip_acl_rule_t_array_endian(vl_api_macip_acl_rule_t *rules, u32 count)
39 {
40   u32 i;
41   for(i=0; i<count; i++) {
42     vl_api_macip_acl_rule_t_endian (&rules[i]);
43   }
44 }
45
46 static inline void
47 vl_api_acl_details_t_endian (vl_api_acl_details_t * a)
48 {
49   a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
50   a->context = clib_net_to_host_u32 (a->context);
51   a->acl_index = clib_net_to_host_u32 (a->acl_index);
52   /* a->tag[0..63] = a->tag[0..63] (no-op) */
53   a->count = clib_net_to_host_u32 (a->count);
54   vl_api_acl_rule_t_array_endian (a->r, a->count);
55 }
56
57 static inline void
58 vl_api_macip_acl_details_t_endian (vl_api_macip_acl_details_t * a)
59 {
60   a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
61   a->context = clib_net_to_host_u32 (a->context);
62   a->acl_index = clib_net_to_host_u32 (a->acl_index);
63   /* a->tag[0..63] = a->tag[0..63] (no-op) */
64   a->count = clib_net_to_host_u32 (a->count);
65   vl_api_macip_acl_rule_t_array_endian (a->r, a->count);
66 }
67
68
69 static inline void
70 vl_api_acl_add_replace_t_endian (vl_api_acl_add_replace_t * a)
71 {
72   a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
73   a->client_index = clib_net_to_host_u32 (a->client_index);
74   a->context = clib_net_to_host_u32 (a->context);
75   a->acl_index = clib_net_to_host_u32 (a->acl_index);
76   /* a->tag[0..63] = a->tag[0..63] (no-op) */
77   a->count = clib_net_to_host_u32 (a->count);
78   vl_api_acl_rule_t_array_endian (a->r, a->count);
79 }
80
81 static inline void
82 vl_api_macip_acl_add_t_endian (vl_api_macip_acl_add_t * a)
83 {
84   a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
85   a->client_index = clib_net_to_host_u32 (a->client_index);
86   a->context = clib_net_to_host_u32 (a->context);
87   /* a->tag[0..63] = a->tag[0..63] (no-op) */
88   a->count = clib_net_to_host_u32 (a->count);
89   vl_api_macip_acl_rule_t_array_endian (a->r, a->count);
90 }
91
92 static inline void
93 vl_api_macip_acl_add_replace_t_endian (vl_api_macip_acl_add_replace_t * a)
94 {
95   a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
96   a->client_index = clib_net_to_host_u32 (a->client_index);
97   a->context = clib_net_to_host_u32 (a->context);
98   a->acl_index = clib_net_to_host_u32 (a->acl_index);
99   /* a->tag[0..63] = a->tag[0..63] (no-op) */
100   a->count = clib_net_to_host_u32 (a->count);
101   vl_api_macip_acl_rule_t_array_endian (a->r, a->count);
102 }
103
104 static inline u8 *
105 format_acl_action(u8 *s, u8 action)
106 {
107   switch(action) {
108     case 0:
109       s = format (s, "deny");
110       break;
111     case 1:
112       s = format (s, "permit");
113       break;
114     case 2:
115       s = format (s, "permit+reflect");
116       break;
117     default:
118       s = format (s, "action %d", action);
119   }
120   return(s);
121 }
122
123 static inline void *
124 vl_api_acl_add_replace_t_print (vl_api_acl_add_replace_t * a, void *handle)
125 {
126   u8 *s = 0;
127   int i;
128   u32 acl_index = clib_net_to_host_u32 (a->acl_index);
129   u32 count = clib_net_to_host_u32 (a->count);
130   if (count > 0x100000)
131     {
132       s = format (s, "WARN: acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
133       count = a->count;
134     }
135
136   s = format (s, "SCRIPT: acl_add_replace %d count %d ",
137               acl_index, count);
138
139   if (a->tag[0])
140     s = format (s, "tag %s ", a->tag);
141
142   s = format(s, "\\\n");
143   PRINT_S;
144
145   for (i = 0; i < count; i++)
146     vl_api_acl_rule_t_print (&a->r[i], handle);
147
148   s = format(s, "\n");
149   PRINT_S;
150   return handle;
151 }
152
153 static inline void *
154 vl_api_acl_del_t_print (vl_api_macip_acl_del_t * a, void *handle)
155 {
156   u8 *s;
157
158   s = format (0, "SCRIPT: acl_del %d ",
159               clib_host_to_net_u32 (a->acl_index));
160
161   PRINT_S;
162   return handle;
163 }
164
165
166 static inline void *
167 vl_api_acl_details_t_print (vl_api_acl_details_t * a, void *handle)
168 {
169   u8 *s = 0;
170   int i;
171   u32 acl_index = clib_net_to_host_u32 (a->acl_index);
172   u32 count = clib_net_to_host_u32 (a->count);
173   if (count > 0x100000)
174     {
175       s = format (s, "WARN: acl_details count endianness wrong? Fixup to avoid long loop.\n");
176       count = a->count;
177     }
178
179   s = format (s, "acl_details index %d count %d ",
180               acl_index, count);
181
182   if (a->tag[0])
183     s = format (s, "tag %s ", a->tag);
184
185   s = format(s, "\n");
186   PRINT_S;
187
188   for (i = 0; i < count; i++)
189     vl_api_acl_rule_t_print (&a->r[i], handle);
190
191   return handle;
192 }
193
194 static inline void *
195 vl_api_macip_acl_details_t_print (vl_api_macip_acl_details_t * a,
196                                   void *handle)
197 {
198   u8 *s = 0;
199   int i;
200   u32 acl_index = clib_net_to_host_u32 (a->acl_index);
201   u32 count = clib_net_to_host_u32 (a->count);
202   if (count > 0x100000)
203     {
204       s = format (s, "WARN: macip_acl_details count endianness wrong? Fixup to avoid long loop.\n");
205       count = a->count;
206     }
207
208   s = format (s, "macip_acl_details index %d count %d ",
209               acl_index, count);
210
211   if (a->tag[0])
212     s = format (s, "tag %s ", a->tag);
213
214   s = format(s, "\n");
215   PRINT_S;
216
217   for (i = 0; i < count; i++)
218     vl_api_macip_acl_rule_t_print (&a->r[i], handle);
219
220   return handle;
221 }
222
223 static inline void *
224 vl_api_macip_acl_add_t_print (vl_api_macip_acl_add_t * a, void *handle)
225 {
226   u8 *s = 0;
227   int i;
228   u32 count = clib_net_to_host_u32 (a->count);
229   if (count > 0x100000)
230     {
231       s = format (s, "WARN: macip_acl_add count endianness wrong? Fixup to avoid long loop.\n");
232       count = a->count;
233     }
234
235   s = format (s, "SCRIPT: macip_acl_add ");
236   if (a->tag[0])
237     s = format (s, "tag %s ", a->tag);
238
239   s = format (s, "count %d \\\n", count);
240
241   PRINT_S;
242
243   for (i = 0; i < count; i++)
244     vl_api_macip_acl_rule_t_print (&a->r[i], handle);
245
246   s = format (0, "\n");
247   PRINT_S;
248
249   return handle;
250 }
251
252 static inline void *
253 vl_api_macip_acl_add_replace_t_print (vl_api_macip_acl_add_replace_t * a, void *handle)
254 {
255   u8 *s = 0;
256   int i;
257   u32 acl_index = clib_net_to_host_u32 (a->acl_index);
258   u32 count = clib_net_to_host_u32 (a->count);
259   if (count > 0x100000)
260     {
261       s = format (s, "WARN: macip_acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
262       count = a->count;
263     }
264
265   s = format (s, "SCRIPT: macip_acl_add_replace %d count %d ",
266         acl_index, count);
267   if (a->tag[0])
268     s = format (s, "tag %s ", a->tag);
269
270   s = format (s, "count %d \\\n", count);
271
272   PRINT_S;
273
274   for (i = 0; i < count; i++)
275     vl_api_macip_acl_rule_t_print (&a->r[i], handle);
276
277   s = format (0, "\n");
278   PRINT_S;
279
280   return handle;
281 }
282
283 static inline void *
284 vl_api_acl_interface_set_acl_list_t_print (vl_api_acl_interface_set_acl_list_t
285                                            * a, void *handle)
286 {
287   u8 *s;
288   int i;
289
290   s = format
291     (0, "SCRIPT: acl_interface_set_acl_list sw_if_index %d count %d\n",
292      clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
293
294   s = format (s, "    input ");
295
296   for (i = 0; i < a->count; i++)
297     {
298       if (i == a->n_input)
299         s = format (s, "output ");
300       s = format (s, "%d ", clib_net_to_host_u32 (a->acls[i]));
301     }
302
303   PRINT_S;
304   return handle;
305 }
306
307 static inline void *
308 vl_api_acl_interface_set_etype_whitelist_t_print (vl_api_acl_interface_set_etype_whitelist_t
309                                            * a, void *handle)
310 {
311   u8 *s;
312   int i;
313
314   s = format
315     (0, "SCRIPT: acl_interface_set_etype_whitelist sw_if_index %d count %d\n",
316      clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
317
318   s = format (s, "    input ");
319
320   for (i = 0; i < a->count; i++)
321     {
322       if (i == a->n_input)
323         s = format (s, "output ");
324       s = format (s, "%x ", clib_net_to_host_u16 (a->whitelist[i]));
325     }
326
327   PRINT_S;
328   return handle;
329 }
330
331 static inline void *
332 vl_api_acl_interface_add_del_t_print (vl_api_acl_interface_add_del_t * a,
333                                       void *handle)
334 {
335   u8 *s;
336
337   s = format (0, "SCRIPT: acl_interface_add_del sw_if_index %d acl %d ",
338               clib_net_to_host_u32 (a->sw_if_index),
339               clib_net_to_host_u32 (a->acl_index));
340   s = format (s, "%s %s",
341               a->is_input ? "input" : "output", a->is_add ? "add" : "del");
342
343   PRINT_S;
344   return handle;
345 }
346
347 static inline void *vl_api_macip_acl_interface_add_del_t_print
348   (vl_api_macip_acl_interface_add_del_t * a, void *handle)
349 {
350   u8 *s;
351
352   s = format
353     (0,
354      "SCRIPT: macip_acl_interface_add_del sw_if_index %d acl_index %d ",
355      clib_net_to_host_u32 (a->sw_if_index),
356      clib_net_to_host_u32 (a->acl_index));
357   s = format (s, "%s", a->is_add ? "add" : "del");
358
359   PRINT_S;
360   return handle;
361 }
362
363
364 static inline void *
365 vl_api_macip_acl_del_t_print (vl_api_macip_acl_del_t * a, void *handle)
366 {
367   u8 *s;
368
369   s = format (0, "SCRIPT: macip_acl_del %d ",
370               clib_host_to_net_u32 (a->acl_index));
371
372   PRINT_S;
373   return handle;
374 }
375
376
377 #endif /* included_manual_fns_h */