FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
manual_fns.h
Go to the documentation of this file.
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 
32 static inline void
34 {
35  u32 i;
36  for(i=0; i<count; i++) {
37  vl_api_acl_rule_t_endian (&rules[i]);
38  }
39 }
40 
41 static inline void
43 {
44  u32 i;
45  for(i=0; i<count; i++) {
46  vl_api_macip_acl_rule_t_endian (&rules[i]);
47  }
48 }
49 
50 static inline void
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);
59 }
60 
61 static inline void
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);
70 }
71 
72 
73 static inline void
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);
83 }
84 
85 static inline void
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);
94 }
95 
96 static inline void
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);
106 }
107 
108 static inline u8 *
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 
127 static inline void *
128 vl_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 
157 static inline void *
158 vl_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 
180 static inline void *
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 
210 static inline void *
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 
223 static inline void *
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 
251 static inline void *
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 
280 static inline void *
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 
309 static inline void *
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 
340 static inline void *
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 
364 static inline void *
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 
388 static inline void *
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 
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 
421 static inline void *
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 */
u8 count
Definition: dhcp.api:208
static void * vl_api_macip_acl_interface_add_del_t_print(vl_api_macip_acl_interface_add_del_t *a, void *handle)
Definition: manual_fns.h:405
Use acl_interface_set_acl_list instead Append/remove an ACL index to/from the list of ACLs checked fo...
Definition: acl.api:153
u32 acl_index
Definition: abf.api:58
Set the vector of input/output ACLs checked for an interface.
Definition: acl.api:177
Set the ethertype whitelists on an interface.
Definition: acl.api:444
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:269
#define PRINT_S
Definition: manual_fns.h:27
static void * vl_api_acl_details_t_print(vl_api_acl_details_t *a, void *handle)
Definition: manual_fns.h:224
int i
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
Delete a MACIP ACL.
Definition: acl.api:325
unsigned char u8
Definition: types.h:56
static void vl_api_macip_acl_add_replace_t_endian(vl_api_macip_acl_add_replace_t *a)
Definition: manual_fns.h:97
Details about one MACIP ACL.
Definition: acl.api:374
format_function_t format_ip4_address
Definition: format.h:73
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
static void * vl_api_acl_interface_set_acl_list_t_print(vl_api_acl_interface_set_acl_list_t *a, void *handle)
Definition: manual_fns.h:341
Add or delete a MACIP ACL to/from interface.
Definition: acl.api:341
static u8 * format_acl_action(u8 *s, u8 action)
Definition: manual_fns.h:109
unsigned int u32
Definition: types.h:88
static void vl_api_macip_acl_rule_t_array_endian(vl_api_macip_acl_rule_t *rules, u32 count)
Definition: manual_fns.h:42
static void * vl_api_acl_interface_add_del_t_print(vl_api_acl_interface_add_del_t *a, void *handle)
Definition: manual_fns.h:389
static void * vl_api_macip_acl_rule_t_print(vl_api_macip_acl_rule_t *a, void *handle)
Definition: manual_fns.h:158
static void * vl_api_macip_acl_add_replace_t_print(vl_api_macip_acl_add_replace_t *a, void *handle)
Definition: manual_fns.h:310
Replace an existing ACL in-place or create a new ACL.
Definition: acl.api:104
vl_api_acl_rule_t r[count]
Definition: acl.api:111
static void vl_api_acl_add_replace_t_endian(vl_api_acl_add_replace_t *a)
Definition: manual_fns.h:74
static void * vl_api_macip_acl_add_t_print(vl_api_macip_acl_add_t *a, void *handle)
Definition: manual_fns.h:281
vl_api_acl_rule_t r[count]
Definition: acl.api:221
format_function_t format_ip6_address
Definition: format.h:91
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:302
static void * vl_api_acl_rule_t_print(vl_api_acl_rule_t *a, void *handle)
Definition: manual_fns.h:128
static void * vl_api_acl_add_replace_t_print(vl_api_acl_add_replace_t *a, void *handle)
Definition: manual_fns.h:181
vl_api_gbp_rule_t rules[n_rules]
Definition: gbp.api:315
static void vl_api_macip_acl_details_t_endian(vl_api_macip_acl_details_t *a)
Definition: manual_fns.h:62
static void vl_api_macip_acl_add_t_endian(vl_api_macip_acl_add_t *a)
Definition: manual_fns.h:86
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:380
Add/Replace a MACIP ACL.
Definition: acl.api:295
u8 action
Definition: l2.api:173
static void * vl_api_acl_interface_set_etype_whitelist_t_print(vl_api_acl_interface_set_etype_whitelist_t *a, void *handle)
Definition: manual_fns.h:365
Details about a single ACL contents.
Definition: acl.api:215
static void * vl_api_macip_acl_details_t_print(vl_api_macip_acl_details_t *a, void *handle)
Definition: manual_fns.h:252
Add a MACIP ACL.
Definition: acl.api:263
static void * vl_api_acl_del_t_print(vl_api_macip_acl_del_t *a, void *handle)
Definition: manual_fns.h:211
static void vl_api_acl_rule_t_array_endian(vl_api_acl_rule_t *rules, u32 count)
Definition: manual_fns.h:33
static void * vl_api_macip_acl_del_t_print(vl_api_macip_acl_del_t *a, void *handle)
Definition: manual_fns.h:422
static void vl_api_acl_details_t_endian(vl_api_acl_details_t *a)
Definition: manual_fns.h:51