manual_fns.h revision d6a72f86
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#define vl_endianfun            /* define message structures */
23#include <acl/acl_types.api.h>
24#undef vl_endianfun
25
26/* Macro to finish up custom dump fns */
27#define PRINT_S \
28    vec_add1 (s, 0);                            \
29    vl_print (handle, (char *)s);               \
30    vec_free (s);
31
32static inline void
33vl_api_acl_rule_t_array_endian(vl_api_acl_rule_t *rules, u32 count)
34{
35  u32 i;
36  for(i=0; i<count; i++) {
37    vl_api_acl_rule_t_endian (&rules[i]);
38  }
39}
40
41static inline void
42vl_api_macip_acl_rule_t_array_endian(vl_api_macip_acl_rule_t *rules, u32 count)
43{
44  u32 i;
45  for(i=0; i<count; i++) {
46    vl_api_macip_acl_rule_t_endian (&rules[i]);
47  }
48}
49
50static inline void
51vl_api_acl_details_t_endian (vl_api_acl_details_t * a)
52{
53  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
54  a->context = clib_net_to_host_u32 (a->context);
55  a->acl_index = clib_net_to_host_u32 (a->acl_index);
56  /* a->tag[0..63] = a->tag[0..63] (no-op) */
57  a->count = clib_net_to_host_u32 (a->count);
58  vl_api_acl_rule_t_array_endian (a->r, a->count);
59}
60
61static inline void
62vl_api_macip_acl_details_t_endian (vl_api_macip_acl_details_t * a)
63{
64  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
65  a->context = clib_net_to_host_u32 (a->context);
66  a->acl_index = clib_net_to_host_u32 (a->acl_index);
67  /* a->tag[0..63] = a->tag[0..63] (no-op) */
68  a->count = clib_net_to_host_u32 (a->count);
69  vl_api_macip_acl_rule_t_array_endian (a->r, a->count);
70}
71
72
73static inline void
74vl_api_acl_add_replace_t_endian (vl_api_acl_add_replace_t * a)
75{
76  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
77  a->client_index = clib_net_to_host_u32 (a->client_index);
78  a->context = clib_net_to_host_u32 (a->context);
79  a->acl_index = clib_net_to_host_u32 (a->acl_index);
80  /* a->tag[0..63] = a->tag[0..63] (no-op) */
81  a->count = clib_net_to_host_u32 (a->count);
82  vl_api_acl_rule_t_array_endian (a->r, a->count);
83}
84
85static inline void
86vl_api_macip_acl_add_t_endian (vl_api_macip_acl_add_t * a)
87{
88  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
89  a->client_index = clib_net_to_host_u32 (a->client_index);
90  a->context = clib_net_to_host_u32 (a->context);
91  /* a->tag[0..63] = a->tag[0..63] (no-op) */
92  a->count = clib_net_to_host_u32 (a->count);
93  vl_api_macip_acl_rule_t_array_endian (a->r, a->count);
94}
95
96static inline void
97vl_api_macip_acl_add_replace_t_endian (vl_api_macip_acl_add_replace_t * a)
98{
99  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
100  a->client_index = clib_net_to_host_u32 (a->client_index);
101  a->context = clib_net_to_host_u32 (a->context);
102  a->acl_index = clib_net_to_host_u32 (a->acl_index);
103  /* a->tag[0..63] = a->tag[0..63] (no-op) */
104  a->count = clib_net_to_host_u32 (a->count);
105  vl_api_macip_acl_rule_t_array_endian (a->r, a->count);
106}
107
108static inline u8 *
109format_acl_action(u8 *s, u8 action)
110{
111  switch(action) {
112    case 0:
113      s = format (s, "deny");
114      break;
115    case 1:
116      s = format (s, "permit");
117      break;
118    case 2:
119      s = format (s, "permit+reflect");
120      break;
121    default:
122      s = format (s, "action %d", action);
123  }
124  return(s);
125}
126
127static inline void *
128vl_api_acl_rule_t_print (vl_api_acl_rule_t * a, void *handle)
129{
130  u8 *s;
131
132  s = format (0, "  %s ", a->is_ipv6 ? "ipv6" : "ipv4");
133  s = format_acl_action (s, a->is_permit);
134  s = format (s, " \\\n");
135
136  if (a->is_ipv6)
137    s = format (s, "    src %U/%d dst %U/%d \\\n",
138		format_ip6_address, a->src_ip_addr, a->src_ip_prefix_len,
139		format_ip6_address, a->dst_ip_addr, a->dst_ip_prefix_len);
140  else
141    s = format (s, "    src %U/%d dst %U/%d \\\n",
142		format_ip4_address, a->src_ip_addr, a->src_ip_prefix_len,
143		format_ip4_address, a->dst_ip_addr, a->dst_ip_prefix_len);
144  s = format (s, "    proto %d \\\n", a->proto);
145  s = format (s, "    sport %d-%d dport %d-%d \\\n",
146	      clib_net_to_host_u16 (a->srcport_or_icmptype_first),
147	      clib_net_to_host_u16 (a->srcport_or_icmptype_last),
148	      clib_net_to_host_u16 (a->dstport_or_icmpcode_first),
149	      clib_net_to_host_u16 (a->dstport_or_icmpcode_last));
150
151  s = format (s, "    tcpflags %u mask %u, \\",
152	      a->tcp_flags_value, a->tcp_flags_mask);
153  PRINT_S;
154  return handle;
155}
156
157static inline void *
158vl_api_macip_acl_rule_t_print (vl_api_macip_acl_rule_t * a, void *handle)
159{
160  u8 *s;
161
162  s = format (0, "  %s %s \\\n", a->is_ipv6 ? "ipv6" : "ipv4",
163              a->is_permit ? "permit" : "deny");
164
165  s = format (s, "    src mac %U mask %U \\\n",
166	      format_ethernet_address, a->src_mac,
167	      format_ethernet_address, a->src_mac_mask);
168
169  if (a->is_ipv6)
170    s = format (s, "    src ip %U/%d, \\",
171		format_ip6_address, a->src_ip_addr, a->src_ip_prefix_len);
172  else
173    s = format (s, "    src ip %U/%d, \\",
174		format_ip4_address, a->src_ip_addr, a->src_ip_prefix_len);
175
176  PRINT_S;
177  return handle;
178}
179
180static inline void *
181vl_api_acl_add_replace_t_print (vl_api_acl_add_replace_t * a, void *handle)
182{
183  u8 *s = 0;
184  int i;
185  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
186  u32 count = clib_net_to_host_u32 (a->count);
187  if (count > 0x100000)
188    {
189      s = format (s, "WARN: acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
190      count = a->count;
191    }
192
193  s = format (s, "SCRIPT: acl_add_replace %d count %d ",
194	      acl_index, count);
195
196  if (a->tag[0])
197    s = format (s, "tag %s ", a->tag);
198
199  s = format(s, "\\\n");
200  PRINT_S;
201
202  for (i = 0; i < count; i++)
203    vl_api_acl_rule_t_print (&a->r[i], handle);
204
205  s = format(s, "\n");
206  PRINT_S;
207  return handle;
208}
209
210static inline void *
211vl_api_acl_del_t_print (vl_api_macip_acl_del_t * a, void *handle)
212{
213  u8 *s;
214
215  s = format (0, "SCRIPT: acl_del %d ",
216              clib_host_to_net_u32 (a->acl_index));
217
218  PRINT_S;
219  return handle;
220}
221
222
223static inline void *
224vl_api_acl_details_t_print (vl_api_acl_details_t * a, void *handle)
225{
226  u8 *s = 0;
227  int i;
228  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
229  u32 count = clib_net_to_host_u32 (a->count);
230  if (count > 0x100000)
231    {
232      s = format (s, "WARN: acl_details count endianness wrong? Fixup to avoid long loop.\n");
233      count = a->count;
234    }
235
236  s = format (s, "acl_details index %d count %d ",
237	      acl_index, count);
238
239  if (a->tag[0])
240    s = format (s, "tag %s ", a->tag);
241
242  s = format(s, "\n");
243  PRINT_S;
244
245  for (i = 0; i < count; i++)
246    vl_api_acl_rule_t_print (&a->r[i], handle);
247
248  return handle;
249}
250
251static inline void *
252vl_api_macip_acl_details_t_print (vl_api_macip_acl_details_t * a,
253				  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_details count endianness wrong? Fixup to avoid long loop.\n");
262      count = a->count;
263    }
264
265  s = format (s, "macip_acl_details index %d count %d ",
266	      acl_index, count);
267
268  if (a->tag[0])
269    s = format (s, "tag %s ", a->tag);
270
271  s = format(s, "\n");
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  return handle;
278}
279
280static inline void *
281vl_api_macip_acl_add_t_print (vl_api_macip_acl_add_t * a, void *handle)
282{
283  u8 *s = 0;
284  int i;
285  u32 count = clib_net_to_host_u32 (a->count);
286  if (count > 0x100000)
287    {
288      s = format (s, "WARN: macip_acl_add count endianness wrong? Fixup to avoid long loop.\n");
289      count = a->count;
290    }
291
292  s = format (s, "SCRIPT: macip_acl_add ");
293  if (a->tag[0])
294    s = format (s, "tag %s ", a->tag);
295
296  s = format (s, "count %d \\\n", count);
297
298  PRINT_S;
299
300  for (i = 0; i < count; i++)
301    vl_api_macip_acl_rule_t_print (&a->r[i], handle);
302
303  s = format (0, "\n");
304  PRINT_S;
305
306  return handle;
307}
308
309static inline void *
310vl_api_macip_acl_add_replace_t_print (vl_api_macip_acl_add_replace_t * a, void *handle)
311{
312  u8 *s = 0;
313  int i;
314  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
315  u32 count = clib_net_to_host_u32 (a->count);
316  if (count > 0x100000)
317    {
318      s = format (s, "WARN: macip_acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
319      count = a->count;
320    }
321
322  s = format (s, "SCRIPT: macip_acl_add_replace %d count %d ",
323        acl_index, count);
324  if (a->tag[0])
325    s = format (s, "tag %s ", a->tag);
326
327  s = format (s, "count %d \\\n", count);
328
329  PRINT_S;
330
331  for (i = 0; i < count; i++)
332    vl_api_macip_acl_rule_t_print (&a->r[i], handle);
333
334  s = format (0, "\n");
335  PRINT_S;
336
337  return handle;
338}
339
340static inline void *
341vl_api_acl_interface_set_acl_list_t_print (vl_api_acl_interface_set_acl_list_t
342					   * a, void *handle)
343{
344  u8 *s;
345  int i;
346
347  s = format
348    (0, "SCRIPT: acl_interface_set_acl_list sw_if_index %d count %d\n",
349     clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
350
351  s = format (s, "    input ");
352
353  for (i = 0; i < a->count; i++)
354    {
355      if (i == a->n_input)
356        s = format (s, "output ");
357      s = format (s, "%d ", clib_net_to_host_u32 (a->acls[i]));
358    }
359
360  PRINT_S;
361  return handle;
362}
363
364static inline void *
365vl_api_acl_interface_set_etype_whitelist_t_print (vl_api_acl_interface_set_etype_whitelist_t
366					   * a, void *handle)
367{
368  u8 *s;
369  int i;
370
371  s = format
372    (0, "SCRIPT: acl_interface_set_etype_whitelist sw_if_index %d count %d\n",
373     clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
374
375  s = format (s, "    input ");
376
377  for (i = 0; i < a->count; i++)
378    {
379      if (i == a->n_input)
380        s = format (s, "output ");
381      s = format (s, "%x ", clib_net_to_host_u16 (a->whitelist[i]));
382    }
383
384  PRINT_S;
385  return handle;
386}
387
388static inline void *
389vl_api_acl_interface_add_del_t_print (vl_api_acl_interface_add_del_t * a,
390				      void *handle)
391{
392  u8 *s;
393
394  s = format (0, "SCRIPT: acl_interface_add_del sw_if_index %d acl %d ",
395	      clib_net_to_host_u32 (a->sw_if_index),
396	      clib_net_to_host_u32 (a->acl_index));
397  s = format (s, "%s %s",
398	      a->is_input ? "input" : "output", a->is_add ? "add" : "del");
399
400  PRINT_S;
401  return handle;
402}
403
404static inline void *vl_api_macip_acl_interface_add_del_t_print
405  (vl_api_macip_acl_interface_add_del_t * a, void *handle)
406{
407  u8 *s;
408
409  s = format
410    (0,
411     "SCRIPT: macip_acl_interface_add_del sw_if_index %d acl_index %d ",
412     clib_net_to_host_u32 (a->sw_if_index),
413     clib_net_to_host_u32 (a->acl_index));
414  s = format (s, "%s", a->is_add ? "add" : "del");
415
416  PRINT_S;
417  return handle;
418}
419
420
421static inline void *
422vl_api_macip_acl_del_t_print (vl_api_macip_acl_del_t * a, void *handle)
423{
424  u8 *s;
425
426  s = format (0, "SCRIPT: macip_acl_del %d ",
427	      clib_host_to_net_u32 (a->acl_index));
428
429  PRINT_S;
430  return handle;
431}
432
433
434#endif /* included_manual_fns_h */
435