FD.io VPP  v19.04.4-rc0-5-ge88582fac
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 /* 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
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
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
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);
55 }
56 
57 static inline void
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);
66 }
67 
68 
69 static inline void
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);
79 }
80 
81 static inline void
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);
90 }
91 
92 static inline void
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);
102 }
103 
104 static inline u8 *
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 *
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",
136  else
137  s = format (s, " src %U/%d dst %U/%d \\\n",
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, \\",
149  PRINT_S;
150  return handle;
151 }
152 
153 
154 
155 static inline void *
157 {
158  u8 *s;
159 
160  s = format (0, " %s %s \\\n", a->is_ipv6 ? "ipv6" : "ipv4",
161  a->is_permit ? "permit" : "deny");
162 
163  s = format (s, " src mac %U mask %U \\\n",
166 
167  if (a->is_ipv6)
168  s = format (s, " src ip %U/%d, \\",
170  else
171  s = format (s, " src ip %U/%d, \\",
173 
174  PRINT_S;
175  return handle;
176 }
177 
178 static inline void *
180 {
181  u8 *s = 0;
182  int i;
183  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
184  u32 count = clib_net_to_host_u32 (a->count);
185  if (count > 0x100000)
186  {
187  s = format (s, "WARN: acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
188  count = a->count;
189  }
190 
191  s = format (s, "SCRIPT: acl_add_replace %d count %d ",
192  acl_index, count);
193 
194  if (a->tag[0])
195  s = format (s, "tag %s ", a->tag);
196 
197  s = format(s, "\\\n");
198  PRINT_S;
199 
200  for (i = 0; i < count; i++)
201  vl_api_acl_rule_t_print (&a->r[i], handle);
202 
203  s = format(s, "\n");
204  PRINT_S;
205  return handle;
206 }
207 
208 static inline void *
210 {
211  u8 *s;
212 
213  s = format (0, "SCRIPT: acl_del %d ",
214  clib_host_to_net_u32 (a->acl_index));
215 
216  PRINT_S;
217  return handle;
218 }
219 
220 
221 static inline void *
223 {
224  u8 *s = 0;
225  int i;
226  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
227  u32 count = clib_net_to_host_u32 (a->count);
228  if (count > 0x100000)
229  {
230  s = format (s, "WARN: acl_details count endianness wrong? Fixup to avoid long loop.\n");
231  count = a->count;
232  }
233 
234  s = format (s, "acl_details index %d count %d ",
235  acl_index, count);
236 
237  if (a->tag[0])
238  s = format (s, "tag %s ", a->tag);
239 
240  s = format(s, "\n");
241  PRINT_S;
242 
243  for (i = 0; i < count; i++)
244  vl_api_acl_rule_t_print (&a->r[i], handle);
245 
246  return handle;
247 }
248 
249 static inline void *
251  void *handle)
252 {
253  u8 *s = 0;
254  int i;
255  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
256  u32 count = clib_net_to_host_u32 (a->count);
257  if (count > 0x100000)
258  {
259  s = format (s, "WARN: macip_acl_details count endianness wrong? Fixup to avoid long loop.\n");
260  count = a->count;
261  }
262 
263  s = format (s, "macip_acl_details index %d count %d ",
264  acl_index, count);
265 
266  if (a->tag[0])
267  s = format (s, "tag %s ", a->tag);
268 
269  s = format(s, "\n");
270  PRINT_S;
271 
272  for (i = 0; i < count; i++)
273  vl_api_macip_acl_rule_t_print (&a->r[i], handle);
274 
275  return handle;
276 }
277 
278 static inline void *
280 {
281  u8 *s = 0;
282  int i;
283  u32 count = clib_net_to_host_u32 (a->count);
284  if (count > 0x100000)
285  {
286  s = format (s, "WARN: macip_acl_add count endianness wrong? Fixup to avoid long loop.\n");
287  count = a->count;
288  }
289 
290  s = format (s, "SCRIPT: macip_acl_add ");
291  if (a->tag[0])
292  s = format (s, "tag %s ", a->tag);
293 
294  s = format (s, "count %d \\\n", count);
295 
296  PRINT_S;
297 
298  for (i = 0; i < count; i++)
299  vl_api_macip_acl_rule_t_print (&a->r[i], handle);
300 
301  s = format (0, "\n");
302  PRINT_S;
303 
304  return handle;
305 }
306 
307 static inline void *
309 {
310  u8 *s = 0;
311  int i;
312  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
313  u32 count = clib_net_to_host_u32 (a->count);
314  if (count > 0x100000)
315  {
316  s = format (s, "WARN: macip_acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
317  count = a->count;
318  }
319 
320  s = format (s, "SCRIPT: macip_acl_add_replace %d count %d ",
321  acl_index, count);
322  if (a->tag[0])
323  s = format (s, "tag %s ", a->tag);
324 
325  s = format (s, "count %d \\\n", count);
326 
327  PRINT_S;
328 
329  for (i = 0; i < count; i++)
330  vl_api_macip_acl_rule_t_print (&a->r[i], handle);
331 
332  s = format (0, "\n");
333  PRINT_S;
334 
335  return handle;
336 }
337 
338 static inline void *
340  * a, void *handle)
341 {
342  u8 *s;
343  int i;
344 
345  s = format
346  (0, "SCRIPT: acl_interface_set_acl_list sw_if_index %d count %d\n",
347  clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
348 
349  s = format (s, " input ");
350 
351  for (i = 0; i < a->count; i++)
352  {
353  if (i == a->n_input)
354  s = format (s, "output ");
355  s = format (s, "%d ", clib_net_to_host_u32 (a->acls[i]));
356  }
357 
358  PRINT_S;
359  return handle;
360 }
361 
362 static inline void *
364  * a, void *handle)
365 {
366  u8 *s;
367  int i;
368 
369  s = format
370  (0, "SCRIPT: acl_interface_set_etype_whitelist sw_if_index %d count %d\n",
371  clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
372 
373  s = format (s, " input ");
374 
375  for (i = 0; i < a->count; i++)
376  {
377  if (i == a->n_input)
378  s = format (s, "output ");
379  s = format (s, "%x ", clib_net_to_host_u16 (a->whitelist[i]));
380  }
381 
382  PRINT_S;
383  return handle;
384 }
385 
386 static inline void *
388  void *handle)
389 {
390  u8 *s;
391 
392  s = format (0, "SCRIPT: acl_interface_add_del sw_if_index %d acl %d ",
393  clib_net_to_host_u32 (a->sw_if_index),
394  clib_net_to_host_u32 (a->acl_index));
395  s = format (s, "%s %s",
396  a->is_input ? "input" : "output", a->is_add ? "add" : "del");
397 
398  PRINT_S;
399  return handle;
400 }
401 
404 {
405  u8 *s;
406 
407  s = format
408  (0,
409  "SCRIPT: macip_acl_interface_add_del sw_if_index %d acl_index %d ",
410  clib_net_to_host_u32 (a->sw_if_index),
411  clib_net_to_host_u32 (a->acl_index));
412  s = format (s, "%s", a->is_add ? "add" : "del");
413 
414  PRINT_S;
415  return handle;
416 }
417 
418 
419 static inline void *
421 {
422  u8 *s;
423 
424  s = format (0, "SCRIPT: macip_acl_del %d ",
425  clib_host_to_net_u32 (a->acl_index));
426 
427  PRINT_S;
428  return handle;
429 }
430 
431 
432 #endif /* included_manual_fns_h */
u32 acl_index
Definition: gbp.api:304
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:403
Use acl_interface_set_acl_list instead Append/remove an ACL index to/from the list of ACLs checked fo...
Definition: acl.api:228
Set the vector of input/output ACLs checked for an interface.
Definition: acl.api:251
Set the ethertype whitelists on an interface.
Definition: acl.api:510
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:340
#define PRINT_S
Definition: manual_fns.h:23
u8 src_ip_addr[16]
Definition: acl.api:113
static void * vl_api_acl_details_t_print(vl_api_acl_details_t *a, void *handle)
Definition: manual_fns.h:222
int i
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
Access List Rule entry.
Definition: acl.api:109
u16 dstport_or_icmpcode_last
Definition: acl.api:134
Delete a MACIP ACL.
Definition: acl.api:394
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:93
Details about one MACIP ACL.
Definition: acl.api:440
format_function_t format_ip4_address
Definition: format.h:75
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
u16 dstport_or_icmpcode_first
Definition: acl.api:133
u8 src_ip_prefix_len
Definition: acl.api:114
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:339
u8 tcp_flags_value
Definition: acl.api:141
Add or delete a MACIP ACL to/from interface.
Definition: acl.api:409
static u8 * format_acl_action(u8 *s, u8 action)
Definition: manual_fns.h:105
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:38
static void * vl_api_acl_interface_add_del_t_print(vl_api_acl_interface_add_del_t *a, void *handle)
Definition: manual_fns.h:387
static void * vl_api_macip_acl_rule_t_print(vl_api_macip_acl_rule_t *a, void *handle)
Definition: manual_fns.h:156
static void * vl_api_macip_acl_add_replace_t_print(vl_api_macip_acl_add_replace_t *a, void *handle)
Definition: manual_fns.h:308
Replace an existing ACL in-place or create a new ACL.
Definition: acl.api:181
vl_api_acl_rule_t r[count]
Definition: acl.api:188
static void vl_api_acl_add_replace_t_endian(vl_api_acl_add_replace_t *a)
Definition: manual_fns.h:70
static void * vl_api_macip_acl_add_t_print(vl_api_macip_acl_add_t *a, void *handle)
Definition: manual_fns.h:279
u8 dst_ip_addr[16]
Definition: acl.api:115
vl_api_acl_rule_t r[count]
Definition: acl.api:293
format_function_t format_ip6_address
Definition: format.h:93
u16 srcport_or_icmptype_first
Definition: acl.api:131
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:372
static void * vl_api_acl_rule_t_print(vl_api_acl_rule_t *a, void *handle)
Definition: manual_fns.h:124
static void * vl_api_acl_add_replace_t_print(vl_api_acl_add_replace_t *a, void *handle)
Definition: manual_fns.h:179
vl_api_gbp_rule_t rules[n_rules]
Definition: gbp.api:308
u16 srcport_or_icmptype_last
Definition: acl.api:132
static void vl_api_macip_acl_details_t_endian(vl_api_macip_acl_details_t *a)
Definition: manual_fns.h:58
static void vl_api_macip_acl_add_t_endian(vl_api_macip_acl_add_t *a)
Definition: manual_fns.h:82
MACIP Access List Rule entry.
Definition: acl.api:153
u8 dst_ip_prefix_len
Definition: acl.api:116
size_t count
Definition: vapi.c:47
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:446
Add/Replace a MACIP ACL.
Definition: acl.api:365
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:363
Details about a single ACL contents.
Definition: acl.api:287
static void * vl_api_macip_acl_details_t_print(vl_api_macip_acl_details_t *a, void *handle)
Definition: manual_fns.h:250
Add a MACIP ACL.
Definition: acl.api:334
static void * vl_api_acl_del_t_print(vl_api_macip_acl_del_t *a, void *handle)
Definition: manual_fns.h:209
static void vl_api_acl_rule_t_array_endian(vl_api_acl_rule_t *rules, u32 count)
Definition: manual_fns.h:29
static void * vl_api_macip_acl_del_t_print(vl_api_macip_acl_del_t *a, void *handle)
Definition: manual_fns.h:420
static void vl_api_acl_details_t_endian(vl_api_acl_details_t *a)
Definition: manual_fns.h:47