FD.io VPP  v20.09-64-g4f7b92f0a
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 #include <vnet/ip/ip_types_api.h>
22 
23 #define vl_endianfun /* define message structures */
24 #include <acl/acl_types.api.h>
25 #undef vl_endianfun
26 
27 /* Macro to finish up custom dump fns */
28 #define PRINT_S \
29  vec_add1 (s, 0); \
30  vl_print (handle, (char *)s); \
31  vec_free (s);
32 
33 static inline void
35 {
36  u32 i;
37  for(i=0; i<count; i++) {
38  vl_api_acl_rule_t_endian (&rules[i]);
39  }
40 }
41 
42 static inline void
44 {
45  u32 i;
46  for(i=0; i<count; i++) {
47  vl_api_macip_acl_rule_t_endian (&rules[i]);
48  }
49 }
50 
51 static inline void
53 {
54  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
55  a->context = clib_net_to_host_u32 (a->context);
56  a->acl_index = clib_net_to_host_u32 (a->acl_index);
57  /* a->tag[0..63] = a->tag[0..63] (no-op) */
58  a->count = clib_net_to_host_u32 (a->count);
60 }
61 
62 static inline void
64 {
65  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
66  a->context = clib_net_to_host_u32 (a->context);
67  a->acl_index = clib_net_to_host_u32 (a->acl_index);
68  /* a->tag[0..63] = a->tag[0..63] (no-op) */
69  a->count = clib_net_to_host_u32 (a->count);
71 }
72 
73 
74 static inline void
76 {
77  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
78  a->client_index = clib_net_to_host_u32 (a->client_index);
79  a->context = clib_net_to_host_u32 (a->context);
80  a->acl_index = clib_net_to_host_u32 (a->acl_index);
81  /* a->tag[0..63] = a->tag[0..63] (no-op) */
82  a->count = clib_net_to_host_u32 (a->count);
84 }
85 
86 static inline void
88 {
89  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
90  a->client_index = clib_net_to_host_u32 (a->client_index);
91  a->context = clib_net_to_host_u32 (a->context);
92  /* a->tag[0..63] = a->tag[0..63] (no-op) */
93  a->count = clib_net_to_host_u32 (a->count);
95 }
96 
97 static inline void
99 {
100  a->_vl_msg_id = clib_net_to_host_u16 (a->_vl_msg_id);
101  a->client_index = clib_net_to_host_u32 (a->client_index);
102  a->context = clib_net_to_host_u32 (a->context);
103  a->acl_index = clib_net_to_host_u32 (a->acl_index);
104  /* a->tag[0..63] = a->tag[0..63] (no-op) */
105  a->count = clib_net_to_host_u32 (a->count);
107 }
108 
109 static inline u8 *
111 {
112  switch(action) {
113  case 0:
114  s = format (s, "deny");
115  break;
116  case 1:
117  s = format (s, "permit");
118  break;
119  case 2:
120  s = format (s, "permit+reflect");
121  break;
122  default:
123  s = format (s, "action %d", action);
124  }
125  return(s);
126 }
127 
128 static inline void *
129 vl_api_acl_rule_t_print (vl_api_acl_rule_t * a, void *handle)
130 {
131  u8 *s;
133 
134  ip_prefix_decode2 (&a->src_prefix, &src);
135  ip_prefix_decode2 (&a->dst_prefix, &dst);
136 
137  s = format (0, " %s ", a->src_prefix.address.af ? "ipv6" : "ipv4");
138  s = format_acl_action (s, a->is_permit);
139  s = format (s, " \\\n");
140 
141  s = format (s, " src %U dst %U \\\n",
142  format_ip_prefix, &src,
143  format_ip_prefix, &dst);
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;
162 
163  ip_prefix_decode2 (&a->src_prefix, &src);
164 
165  s = format (0, " %s %s \\\n", a->src_prefix.address.af ? "ipv6" : "ipv4",
166  a->is_permit ? "permit" : "deny");
167 
168  s = format (s, " src mac %U mask %U \\\n",
169  format_ethernet_address, a->src_mac,
170  format_ethernet_address, a->src_mac_mask);
171 
172  s = format (s, " src ip %U, \\",
173  format_ip_prefix, &src);
174 
175  PRINT_S;
176  return handle;
177 }
178 
179 static inline void *
181 {
182  u8 *s = 0;
183  int i;
184  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
185  u32 count = clib_net_to_host_u32 (a->count);
186  if (count > 0x100000)
187  {
188  s = format (s, "WARN: acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
189  count = a->count;
190  }
191 
192  s = format (s, "SCRIPT: acl_add_replace %d count %d ",
193  acl_index, count);
194 
195  if (a->tag[0])
196  s = format (s, "tag %s ", a->tag);
197 
198  s = format(s, "\\\n");
199  PRINT_S;
200 
201  for (i = 0; i < count; i++)
202  vl_api_acl_rule_t_print (&a->r[i], handle);
203 
204  s = format(s, "\n");
205  PRINT_S;
206  return handle;
207 }
208 
209 static inline void *
211 {
212  u8 *s;
213 
214  s = format (0, "SCRIPT: acl_del %d ",
215  clib_host_to_net_u32 (a->acl_index));
216 
217  PRINT_S;
218  return handle;
219 }
220 
221 
222 static inline void *
224 {
225  u8 *s = 0;
226  int i;
227  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
228  u32 count = clib_net_to_host_u32 (a->count);
229  if (count > 0x100000)
230  {
231  s = format (s, "WARN: acl_details count endianness wrong? Fixup to avoid long loop.\n");
232  count = a->count;
233  }
234 
235  s = format (s, "acl_details index %d count %d ",
236  acl_index, count);
237 
238  if (a->tag[0])
239  s = format (s, "tag %s ", a->tag);
240 
241  s = format(s, "\n");
242  PRINT_S;
243 
244  for (i = 0; i < count; i++)
245  vl_api_acl_rule_t_print (&a->r[i], handle);
246 
247  return handle;
248 }
249 
250 static inline void *
252  void *handle)
253 {
254  u8 *s = 0;
255  int i;
256  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
257  u32 count = clib_net_to_host_u32 (a->count);
258  if (count > 0x100000)
259  {
260  s = format (s, "WARN: macip_acl_details count endianness wrong? Fixup to avoid long loop.\n");
261  count = a->count;
262  }
263 
264  s = format (s, "macip_acl_details index %d count %d ",
265  acl_index, count);
266 
267  if (a->tag[0])
268  s = format (s, "tag %s ", a->tag);
269 
270  s = format(s, "\n");
271  PRINT_S;
272 
273  for (i = 0; i < count; i++)
274  vl_api_macip_acl_rule_t_print (&a->r[i], handle);
275 
276  return handle;
277 }
278 
279 static inline void *
281 {
282  u8 *s = 0;
283  int i;
284  u32 count = clib_net_to_host_u32 (a->count);
285  if (count > 0x100000)
286  {
287  s = format (s, "WARN: macip_acl_add count endianness wrong? Fixup to avoid long loop.\n");
288  count = a->count;
289  }
290 
291  s = format (s, "SCRIPT: macip_acl_add ");
292  if (a->tag[0])
293  s = format (s, "tag %s ", a->tag);
294 
295  s = format (s, "count %d \\\n", count);
296 
297  PRINT_S;
298 
299  for (i = 0; i < count; i++)
300  vl_api_macip_acl_rule_t_print (&a->r[i], handle);
301 
302  s = format (0, "\n");
303  PRINT_S;
304 
305  return handle;
306 }
307 
308 static inline void *
310 {
311  u8 *s = 0;
312  int i;
313  u32 acl_index = clib_net_to_host_u32 (a->acl_index);
314  u32 count = clib_net_to_host_u32 (a->count);
315  if (count > 0x100000)
316  {
317  s = format (s, "WARN: macip_acl_add_replace count endianness wrong? Fixup to avoid long loop.\n");
318  count = a->count;
319  }
320 
321  s = format (s, "SCRIPT: macip_acl_add_replace %d count %d ",
322  acl_index, count);
323  if (a->tag[0])
324  s = format (s, "tag %s ", a->tag);
325 
326  s = format (s, "count %d \\\n", count);
327 
328  PRINT_S;
329 
330  for (i = 0; i < count; i++)
331  vl_api_macip_acl_rule_t_print (&a->r[i], handle);
332 
333  s = format (0, "\n");
334  PRINT_S;
335 
336  return handle;
337 }
338 
339 static inline void *
341  * a, void *handle)
342 {
343  u8 *s;
344  int i;
345 
346  s = format
347  (0, "SCRIPT: acl_interface_set_acl_list sw_if_index %d count %d\n",
348  clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
349 
350  s = format (s, " input ");
351 
352  for (i = 0; i < a->count; i++)
353  {
354  if (i == a->n_input)
355  s = format (s, "output ");
356  s = format (s, "%d ", clib_net_to_host_u32 (a->acls[i]));
357  }
358 
359  PRINT_S;
360  return handle;
361 }
362 
363 static inline void *
365  * a, void *handle)
366 {
367  u8 *s;
368  int i;
369 
370  s = format
371  (0, "SCRIPT: acl_interface_set_etype_whitelist sw_if_index %d count %d\n",
372  clib_net_to_host_u32 (a->sw_if_index), (u32) a->count);
373 
374  s = format (s, " input ");
375 
376  for (i = 0; i < a->count; i++)
377  {
378  if (i == a->n_input)
379  s = format (s, "output ");
380  s = format (s, "%x ", clib_net_to_host_u16 (a->whitelist[i]));
381  }
382 
383  PRINT_S;
384  return handle;
385 }
386 
387 static inline void *
389  void *handle)
390 {
391  u8 *s;
392 
393  s = format (0, "SCRIPT: acl_interface_add_del sw_if_index %d acl %d ",
394  clib_net_to_host_u32 (a->sw_if_index),
395  clib_net_to_host_u32 (a->acl_index));
396  s = format (s, "%s %s",
397  a->is_input ? "input" : "output", a->is_add ? "add" : "del");
398 
399  PRINT_S;
400  return handle;
401 }
402 
405 {
406  u8 *s;
407 
408  s = format
409  (0,
410  "SCRIPT: macip_acl_interface_add_del sw_if_index %d acl_index %d ",
411  clib_net_to_host_u32 (a->sw_if_index),
412  clib_net_to_host_u32 (a->acl_index));
413  s = format (s, "%s", a->is_add ? "add" : "del");
414 
415  PRINT_S;
416  return handle;
417 }
418 
419 
420 static inline void *
422 {
423  u8 *s;
424 
425  s = format (0, "SCRIPT: macip_acl_del %d ",
426  clib_host_to_net_u32 (a->acl_index));
427 
428  PRINT_S;
429  return handle;
430 }
431 
432 
433 #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:404
Use acl_interface_set_acl_list instead Append/remove an ACL index to/from the list of ACLs checked fo...
Definition: acl.api:154
u32 acl_index
Definition: abf.api:60
Set the vector of input/output ACLs checked for an interface.
Definition: acl.api:178
Set the ethertype whitelists on an interface.
Definition: acl.api:445
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:270
bool is_add[default=true]
Definition: acl.api:346
#define PRINT_S
Definition: manual_fns.h:28
static void * vl_api_acl_details_t_print(vl_api_acl_details_t *a, void *handle)
Definition: manual_fns.h:223
vl_api_address_t src
Definition: gre.api:54
bool is_add[default=true]
Definition: acl.api:158
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
Delete a MACIP ACL.
Definition: acl.api:326
unsigned char u8
Definition: types.h:56
vl_api_interface_index_t sw_if_index
Definition: acl.api:164
static void vl_api_macip_acl_add_replace_t_endian(vl_api_macip_acl_add_replace_t *a)
Definition: manual_fns.h:98
Details about one MACIP ACL.
Definition: acl.api:375
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:340
Add or delete a MACIP ACL to/from interface.
Definition: acl.api:342
static u8 * format_acl_action(u8 *s, u8 action)
Definition: manual_fns.h:110
u32 acl_index[default=0xffffffff]
Definition: acl.api:300
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:43
static void * vl_api_acl_interface_add_del_t_print(vl_api_acl_interface_add_del_t *a, void *handle)
Definition: manual_fns.h:388
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:309
string tag[64]
Definition: acl.api:220
Replace an existing ACL in-place or create a new ACL.
Definition: acl.api:105
vl_api_acl_rule_t r[count]
Definition: acl.api:112
static void vl_api_acl_add_replace_t_endian(vl_api_acl_add_replace_t *a)
Definition: manual_fns.h:75
static void * vl_api_macip_acl_add_t_print(vl_api_macip_acl_add_t *a, void *handle)
Definition: manual_fns.h:280
vl_api_address_t dst
Definition: gre.api:55
vl_api_acl_rule_t r[count]
Definition: acl.api:222
int ip_prefix_decode2(const vl_api_prefix_t *in, ip_prefix_t *out)
Definition: ip_types_api.c:250
u8 * format_ip_prefix(u8 *s, va_list *args)
Definition: ip_types.c:56
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
vl_api_interface_index_t sw_if_index
Definition: acl.api:449
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:303
static void * vl_api_acl_rule_t_print(vl_api_acl_rule_t *a, void *handle)
Definition: manual_fns.h:129
vl_api_interface_index_t sw_if_index
Definition: acl.api:348
static void * vl_api_acl_add_replace_t_print(vl_api_acl_add_replace_t *a, void *handle)
Definition: manual_fns.h:180
vl_api_gbp_rule_t rules[n_rules]
Definition: gbp.api:338
static void vl_api_macip_acl_details_t_endian(vl_api_macip_acl_details_t *a)
Definition: manual_fns.h:63
static void vl_api_macip_acl_add_t_endian(vl_api_macip_acl_add_t *a)
Definition: manual_fns.h:87
vl_api_macip_acl_rule_t r[count]
Definition: acl.api:381
Add/Replace a MACIP ACL.
Definition: acl.api:296
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:364
vl_api_mac_event_action_t action
Definition: l2.api:181
Details about a single ACL contents.
Definition: acl.api:216
vl_api_interface_index_t sw_if_index
Definition: acl.api:182
static void * vl_api_macip_acl_details_t_print(vl_api_macip_acl_details_t *a, void *handle)
Definition: manual_fns.h:251
Add a MACIP ACL.
Definition: acl.api:264
static void * vl_api_acl_del_t_print(vl_api_macip_acl_del_t *a, void *handle)
Definition: manual_fns.h:210
static void vl_api_acl_rule_t_array_endian(vl_api_acl_rule_t *rules, u32 count)
Definition: manual_fns.h:34
static void * vl_api_macip_acl_del_t_print(vl_api_macip_acl_del_t *a, void *handle)
Definition: manual_fns.h:421
string tag[64]
Definition: acl.api:268
static void vl_api_acl_details_t_endian(vl_api_acl_details_t *a)
Definition: manual_fns.h:52