api: autogenerate api trace print/endian
[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_rule_t_print (vl_api_acl_rule_t * a, void *handle)
125 {
126   u8 *s;
127
128   s = format (0, "  %s ", a->is_ipv6 ? "ipv6" : "ipv4");
129   s = format_acl_action (s, a->is_permit);
130   s = format (s, " \\\n");
131
132   if (a->is_ipv6)
133     s = format (s, "    src %U/%d dst %U/%d \\\n",
134                 format_ip6_address, a->src_ip_addr, a->src_ip_prefix_len,
135                 format_ip6_address, a->dst_ip_addr, a->dst_ip_prefix_len);
136   else
137     s = format (s, "    src %U/%d dst %U/%d \\\n",
138                 format_ip4_address, a->src_ip_addr, a->src_ip_prefix_len,
139                 format_ip4_address, a->dst_ip_addr, a->dst_ip_prefix_len);
140   s = format (s, "    proto %d \\\n", a->proto);
141   s = format (s, "    sport %d-%d dport %d-%d \\\n",
142               clib_net_to_host_u16 (a->srcport_or_icmptype_first),
143               clib_net_to_host_u16 (a->srcport_or_icmptype_last),
144               clib_net_to_host_u16 (a->dstport_or_icmpcode_first),
145               clib_net_to_host_u16 (a->dstport_or_icmpcode_last));
146
147   s = format (s, "    tcpflags %u mask %u, \\",
148               a->tcp_flags_value, a->tcp_flags_mask);
149   PRINT_S;
150   return handle;
151 }
152
153 static inline void *
154 vl_api_macip_acl_rule_t_print (vl_api_macip_acl_rule_t * a, void *handle)
155 {
156   u8 *s;
157
158   s = format (0, "  %s %s \\\n", a->is_ipv6 ? "ipv6" : "ipv4",
159               a->is_permit ? "permit" : "deny");
160
161   s = format (s, "    src mac %U mask %U \\\n",
162               format_ethernet_address, a->src_mac,
163               format_ethernet_address, a->src_mac_mask);
164
165   if (a->is_ipv6)
166     s = format (s, "    src ip %U/%d, \\",
167                 format_ip6_address, a->src_ip_addr, a->src_ip_prefix_len);
168   else
169     s = format (s, "    src ip %U/%d, \\",
170                 format_ip4_address, a->src_ip_addr, a->src_ip_prefix_len);
171
172   PRINT_S;
173   return handle;
174 }
175
176 static inline void *
177 vl_api_acl_add_replace_t_print (vl_api_acl_add_replace_t * a, void *handle)
178 {
179   u8 *s = 0;
180   int i;
181   u32 acl_index = clib_net_to_host_u32 (a->acl_index);
182   u32 count = clib_net_to_host_u32 (a->count);
183   if (count > 0x100000)
184     {
185       s = format (s, "WARN: acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
186       count = a->count;
187     }
188
189   s = format (s, "SCRIPT: acl_add_replace %d count %d ",
190               acl_index, count);
191
192   if (a->tag[0])
193     s = format (s, "tag %s ", a->tag);
194
195   s = format(s, "\\\n");
196   PRINT_S;
197
198   for (i = 0; i < count; i++)
199     vl_api_acl_rule_t_print (&a->r[i], handle);
200
201   s = format(s, "\n");
202   PRINT_S;
203   return handle;
204 }
205
206 static inline void *
207 vl_api_acl_del_t_print (vl_api_macip_acl_del_t * a, void *handle)
208 {
209   u8 *s;
210
211   s = format (0, "SCRIPT: acl_del %d ",
212               clib_host_to_net_u32 (a->acl_index));
213
214   PRINT_S;
215   return handle;
216 }
217
218
219 static inline void *
220 vl_api_acl_details_t_print (vl_api_acl_details_t * a, void *handle)
221 {
222   u8 *s = 0;
223   int i;
224   u32 acl_index = clib_net_to_host_u32 (a->acl_index);
225   u32 count = clib_net_to_host_u32 (a->count);
226   if (count > 0x100000)
227     {
228       s = format (s, "WARN: acl_details count endianness wrong? Fixup to avoid long loop.\n");
229       count = a->count;
230     }
231
232   s = format (s, "acl_details index %d count %d ",
233               acl_index, count);
234
235   if (a->tag[0])
236     s = format (s, "tag %s ", a->tag);
237
238   s = format(s, "\n");
239   PRINT_S;
240
241   for (i = 0; i < count; i++)
242     vl_api_acl_rule_t_print (&a->r[i], handle);
243
244   return handle;
245 }
246
247 static inline void *
248 vl_api_macip_acl_details_t_print (vl_api_macip_acl_details_t * a,
249                                   void *handle)
250 {
251   u8 *s = 0;
252   int i;
253   u32 acl_index = clib_net_to_host_u32 (a->acl_index);
254   u32 count = clib_net_to_host_u32 (a->count);
255   if (count > 0x100000)
256     {
257       s = format (s, "WARN: macip_acl_details count endianness wrong? Fixup to avoid long loop.\n");
258       count = a->count;
259     }
260
261   s = format (s, "macip_acl_details index %d count %d ",
262               acl_index, count);
263
264   if (a->tag[0])
265     s = format (s, "tag %s ", a->tag);
266
267   s = format(s, "\n");
268   PRINT_S;
269
270   for (i = 0; i < count; i++)
271     vl_api_macip_acl_rule_t_print (&a->r[i], handle);
272
273   return handle;
274 }
275
276 static inline void *
277 vl_api_macip_acl_add_t_print (vl_api_macip_acl_add_t * a, void *handle)
278 {
279   u8 *s = 0;
280   int i;
281   u32 count = clib_net_to_host_u32 (a->count);
282   if (count > 0x100000)
283     {
284       s = format (s, "WARN: macip_acl_add count endianness wrong? Fixup to avoid long loop.\n");
285       count = a->count;
286     }
287
288   s = format (s, "SCRIPT: macip_acl_add ");
289   if (a->tag[0])
290     s = format (s, "tag %s ", a->tag);
291
292   s = format (s, "count %d \\\n", count);
293
294   PRINT_S;
295
296   for (i = 0; i < count; i++)
297     vl_api_macip_acl_rule_t_print (&a->r[i], handle);
298
299   s = format (0, "\n");
300   PRINT_S;
301
302   return handle;
303 }
304
305 static inline void *
306 vl_api_macip_acl_add_replace_t_print (vl_api_macip_acl_add_replace_t * a, void *handle)
307 {
308   u8 *s = 0;
309   int i;
310   u32 acl_index = clib_net_to_host_u32 (a->acl_index);
311   u32 count = clib_net_to_host_u32 (a->count);
312   if (count > 0x100000)
313     {
314       s = format (s, "WARN: macip_acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
315       count = a->count;
316     }
317
318   s = format (s, "SCRIPT: macip_acl_add_replace %d count %d ",
319         acl_index, count);
320   if (a->tag[0])
321     s = format (s, "tag %s ", a->tag);
322
323   s = format (s, "count %d \\\n", count);
324
325   PRINT_S;
326
327   for (i = 0; i < count; i++)
328     vl_api_macip_acl_rule_t_print (&a->r[i], handle);
329
330   s = format (0, "\n");
331   PRINT_S;
332
333   return handle;
334 }
335
336 static inline void *
337 vl_api_acl_interface_set_acl_list_t_print (vl_api_acl_interface_set_acl_list_t
338                                            * a, void *handle)
339 {
340   u8 *s;
341   int i;
342
343   s = format
344     (0, "SCRIPT: acl_interface_set_acl_list sw_if_index %d count %d\n",
345      clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
346
347   s = format (s, "    input ");
348
349   for (i = 0; i < a->count; i++)
350     {
351       if (i == a->n_input)
352         s = format (s, "output ");
353       s = format (s, "%d ", clib_net_to_host_u32 (a->acls[i]));
354     }
355
356   PRINT_S;
357   return handle;
358 }
359
360 static inline void *
361 vl_api_acl_interface_set_etype_whitelist_t_print (vl_api_acl_interface_set_etype_whitelist_t
362                                            * a, void *handle)
363 {
364   u8 *s;
365   int i;
366
367   s = format
368     (0, "SCRIPT: acl_interface_set_etype_whitelist sw_if_index %d count %d\n",
369      clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
370
371   s = format (s, "    input ");
372
373   for (i = 0; i < a->count; i++)
374     {
375       if (i == a->n_input)
376         s = format (s, "output ");
377       s = format (s, "%x ", clib_net_to_host_u16 (a->whitelist[i]));
378     }
379
380   PRINT_S;
381   return handle;
382 }
383
384 static inline void *
385 vl_api_acl_interface_add_del_t_print (vl_api_acl_interface_add_del_t * a,
386                                       void *handle)
387 {
388   u8 *s;
389
390   s = format (0, "SCRIPT: acl_interface_add_del sw_if_index %d acl %d ",
391               clib_net_to_host_u32 (a->sw_if_index),
392               clib_net_to_host_u32 (a->acl_index));
393   s = format (s, "%s %s",
394               a->is_input ? "input" : "output", a->is_add ? "add" : "del");
395
396   PRINT_S;
397   return handle;
398 }
399
400 static inline void *vl_api_macip_acl_interface_add_del_t_print
401   (vl_api_macip_acl_interface_add_del_t * a, void *handle)
402 {
403   u8 *s;
404
405   s = format
406     (0,
407      "SCRIPT: macip_acl_interface_add_del sw_if_index %d acl_index %d ",
408      clib_net_to_host_u32 (a->sw_if_index),
409      clib_net_to_host_u32 (a->acl_index));
410   s = format (s, "%s", a->is_add ? "add" : "del");
411
412   PRINT_S;
413   return handle;
414 }
415
416
417 static inline void *
418 vl_api_macip_acl_del_t_print (vl_api_macip_acl_del_t * a, void *handle)
419 {
420   u8 *s;
421
422   s = format (0, "SCRIPT: macip_acl_del %d ",
423               clib_host_to_net_u32 (a->acl_index));
424
425   PRINT_S;
426   return handle;
427 }
428
429
430 #endif /* included_manual_fns_h */