2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 *------------------------------------------------------------------
17 * acl_test.c - test harness plugin
18 *------------------------------------------------------------------
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vlibsocket/api.h>
25 #include <vppinfra/error.h>
26 #include <vnet/ip/ip.h>
27 #include <arpa/inet.h>
29 #define __plugin_msg_base acl_test_main.msg_id_base
30 #include <vlibapi/vat_helper_macros.h>
32 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
34 /* Declare message IDs */
35 #include <acl/acl_msg_enum.h>
37 /* define message structures */
39 #include <acl/acl_all_api_h.h>
42 /* define message structures */
44 #include <acl/acl_all_api_h.h>
47 /* instantiate all the print functions we know about */
48 #define vl_print(handle, ...)
50 #include <acl/acl_all_api_h.h>
53 /* Get the API version number. */
54 #define vl_api_version(n,v) static u32 api_version=(v);
55 #include <acl/acl_all_api_h.h>
59 /* API message ID base */
64 acl_test_main_t acl_test_main;
66 #define foreach_standard_reply_retval_handler \
68 _(acl_interface_add_del_reply) \
69 _(macip_acl_interface_add_del_reply) \
70 _(acl_interface_set_acl_list_reply) \
71 _(macip_acl_del_reply)
73 #define foreach_reply_retval_aclindex_handler \
74 _(acl_add_replace_reply) \
75 _(macip_acl_add_reply)
78 static void vl_api_##n##_t_handler \
79 (vl_api_##n##_t * mp) \
81 vat_main_t * vam = acl_test_main.vat_main; \
82 i32 retval = ntohl(mp->retval); \
83 if (vam->async_mode) { \
84 vam->async_errors += (retval < 0); \
86 vam->retval = retval; \
87 vam->result_ready = 1; \
90 foreach_standard_reply_retval_handler;
94 static void vl_api_##n##_t_handler \
95 (vl_api_##n##_t * mp) \
97 vat_main_t * vam = acl_test_main.vat_main; \
98 i32 retval = ntohl(mp->retval); \
99 if (vam->async_mode) { \
100 vam->async_errors += (retval < 0); \
102 clib_warning("ACL index: %d", ntohl(mp->acl_index)); \
103 vam->retval = retval; \
104 vam->result_ready = 1; \
107 foreach_reply_retval_aclindex_handler;
110 /* These two ought to be in a library somewhere but they aren't */
112 my_unformat_mac_address (unformat_input_t * input, va_list * args)
114 u8 *a = va_arg (*args, u8 *);
115 return unformat (input, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3],
120 my_format_mac_address (u8 * s, va_list * args)
122 u8 *a = va_arg (*args, u8 *);
123 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
124 a[0], a[1], a[2], a[3], a[4], a[5]);
129 static void vl_api_acl_plugin_get_version_reply_t_handler
130 (vl_api_acl_plugin_get_version_reply_t * mp)
132 vat_main_t * vam = acl_test_main.vat_main;
133 clib_warning("ACL plugin version: %d.%d", ntohl(mp->major), ntohl(mp->minor));
134 vam->result_ready = 1;
137 static void vl_api_acl_interface_list_details_t_handler
138 (vl_api_acl_interface_list_details_t * mp)
141 vat_main_t * vam = acl_test_main.vat_main;
143 vl_api_acl_interface_list_details_t_endian(mp);
144 out = format(out, "sw_if_index: %d, count: %d, n_input: %d\n", mp->sw_if_index, mp->count, mp->n_input);
145 out = format(out, " input ");
146 for(i=0; i<mp->count; i++) {
147 out = format(out, "%d ", mp->acls[i]);
148 if (i == mp->n_input-1)
149 out = format(out, "\n output ");
151 out = format(out, "\n");
152 clib_warning("%s", out);
154 vam->result_ready = 1;
159 vl_api_acl_rule_t_pretty_format (u8 *out, vl_api_acl_rule_t * a)
161 int af = a->is_ipv6 ? AF_INET6 : AF_INET;
162 u8 src[INET6_ADDRSTRLEN];
163 u8 dst[INET6_ADDRSTRLEN];
164 inet_ntop(af, a->src_ip_addr, (void *)src, sizeof(src));
165 inet_ntop(af, a->dst_ip_addr, (void *)dst, sizeof(dst));
167 out = format(out, "%s action %d src %s/%d dst %s/%d proto %d sport %d-%d dport %d-%d tcpflags %d %d",
168 a->is_ipv6 ? "ipv6" : "ipv4", a->is_permit,
169 src, a->src_ip_prefix_len,
170 dst, a->dst_ip_prefix_len,
172 a->srcport_or_icmptype_first, a->srcport_or_icmptype_last,
173 a->dstport_or_icmpcode_first, a->dstport_or_icmpcode_last,
174 a->tcp_flags_mask, a->tcp_flags_value);
180 static void vl_api_acl_details_t_handler
181 (vl_api_acl_details_t * mp)
184 vat_main_t * vam = acl_test_main.vat_main;
185 vl_api_acl_details_t_endian(mp);
187 out = format(0, "acl_index: %d, count: %d\n tag {%s}\n", mp->acl_index, mp->count, mp->tag);
188 for(i=0; i<mp->count; i++) {
189 out = format(out, " ");
190 out = vl_api_acl_rule_t_pretty_format(out, &mp->r[i]);
191 out = format(out, "%s\n", i<mp->count-1 ? "," : "");
193 clib_warning("%s", out);
195 vam->result_ready = 1;
199 vl_api_macip_acl_rule_t_pretty_format (u8 *out, vl_api_macip_acl_rule_t * a)
201 int af = a->is_ipv6 ? AF_INET6 : AF_INET;
202 u8 src[INET6_ADDRSTRLEN];
203 inet_ntop(af, a->src_ip_addr, (void *)src, sizeof(src));
205 out = format(out, "%s action %d ip %s/%d mac %U mask %U",
206 a->is_ipv6 ? "ipv6" : "ipv4", a->is_permit,
207 src, a->src_ip_prefix_len,
208 my_format_mac_address, a->src_mac,
209 my_format_mac_address, a->src_mac_mask);
214 static void vl_api_macip_acl_details_t_handler
215 (vl_api_macip_acl_details_t * mp)
218 vat_main_t * vam = acl_test_main.vat_main;
219 vl_api_macip_acl_details_t_endian(mp);
220 u8 *out = format(0,"MACIP acl_index: %d, count: %d\n tag {%s}\n", mp->acl_index, mp->count, mp->tag);
221 for(i=0; i<mp->count; i++) {
222 out = format(out, " ");
223 out = vl_api_macip_acl_rule_t_pretty_format(out, &mp->r[i]);
224 out = format(out, "%s\n", i<mp->count-1 ? "," : "");
226 clib_warning("%s", out);
228 vam->result_ready = 1;
231 static void vl_api_macip_acl_interface_get_reply_t_handler
232 (vl_api_macip_acl_interface_get_reply_t * mp)
235 vat_main_t * vam = acl_test_main.vat_main;
236 u8 *out = format(0, "sw_if_index with MACIP ACL count: %d\n", ntohl(mp->count));
237 for(i=0; i<ntohl(mp->count); i++) {
238 out = format(out, " macip_acl_interface_add_del sw_if_index %d add acl %d\n", i, ntohl(mp->acls[i]));
240 out = format(out, "\n");
241 clib_warning("%s", out);
243 vam->result_ready = 1;
248 * Table of message reply handlers, must include boilerplate handlers
251 #define foreach_vpe_api_reply_msg \
252 _(ACL_ADD_REPLACE_REPLY, acl_add_replace_reply) \
253 _(ACL_DEL_REPLY, acl_del_reply) \
254 _(ACL_INTERFACE_ADD_DEL_REPLY, acl_interface_add_del_reply) \
255 _(ACL_INTERFACE_SET_ACL_LIST_REPLY, acl_interface_set_acl_list_reply) \
256 _(ACL_INTERFACE_LIST_DETAILS, acl_interface_list_details) \
257 _(ACL_DETAILS, acl_details) \
258 _(MACIP_ACL_ADD_REPLY, macip_acl_add_reply) \
259 _(MACIP_ACL_DEL_REPLY, macip_acl_del_reply) \
260 _(MACIP_ACL_DETAILS, macip_acl_details) \
261 _(MACIP_ACL_INTERFACE_ADD_DEL_REPLY, macip_acl_interface_add_del_reply) \
262 _(MACIP_ACL_INTERFACE_GET_REPLY, macip_acl_interface_get_reply) \
263 _(ACL_PLUGIN_GET_VERSION_REPLY, acl_plugin_get_version_reply)
265 static int api_acl_plugin_get_version (vat_main_t * vam)
267 acl_test_main_t * sm = &acl_test_main;
268 vl_api_acl_plugin_get_version_t * mp;
269 u32 msg_size = sizeof(*mp);
272 vam->result_ready = 0;
273 mp = vl_msg_api_alloc_as_if_client(msg_size);
274 memset (mp, 0, msg_size);
275 mp->_vl_msg_id = ntohs (VL_API_ACL_PLUGIN_GET_VERSION + sm->msg_id_base);
276 mp->client_index = vam->my_client_index;
281 /* Wait for a reply... */
287 static int api_macip_acl_interface_get (vat_main_t * vam)
289 acl_test_main_t * sm = &acl_test_main;
290 vl_api_acl_plugin_get_version_t * mp;
291 u32 msg_size = sizeof(*mp);
294 vam->result_ready = 0;
295 mp = vl_msg_api_alloc_as_if_client(msg_size);
296 memset (mp, 0, msg_size);
297 mp->_vl_msg_id = ntohs (VL_API_MACIP_ACL_INTERFACE_GET + sm->msg_id_base);
298 mp->client_index = vam->my_client_index;
303 /* Wait for a reply... */
309 #define vec_validate_acl_rules(v, idx) \
311 if (vec_len(v) < idx+1) { \
312 vec_validate(v, idx); \
313 v[idx].is_permit = 0x1; \
314 v[idx].srcport_or_icmptype_last = 0xffff; \
315 v[idx].dstport_or_icmpcode_last = 0xffff; \
320 static int api_acl_add_replace (vat_main_t * vam)
322 acl_test_main_t * sm = &acl_test_main;
323 unformat_input_t * i = vam->input;
325 vl_api_acl_add_replace_t * mp;
327 u32 msg_size = sizeof (*mp); /* without the rules */
329 vl_api_acl_rule_t *rules = 0;
336 u32 tcpflags, tcpmask;
337 u32 src_prefix_length = 0, dst_prefix_length = 0;
338 ip4_address_t src_v4address, dst_v4address;
339 ip6_address_t src_v6address, dst_v6address;
342 if (!unformat (i, "%d", &acl_index)) {
346 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
348 if (unformat (i, "ipv6"))
350 vec_validate_acl_rules(rules, rule_idx);
351 rules[rule_idx].is_ipv6 = 1;
353 else if (unformat (i, "ipv4"))
355 vec_validate_acl_rules(rules, rule_idx);
356 rules[rule_idx].is_ipv6 = 0;
358 else if (unformat (i, "permit+reflect"))
360 vec_validate_acl_rules(rules, rule_idx);
361 rules[rule_idx].is_permit = 2;
363 else if (unformat (i, "permit"))
365 vec_validate_acl_rules(rules, rule_idx);
366 rules[rule_idx].is_permit = 1;
368 else if (unformat (i, "action %d", &action))
370 vec_validate_acl_rules(rules, rule_idx);
371 rules[rule_idx].is_permit = action;
373 else if (unformat (i, "src %U/%d",
374 unformat_ip4_address, &src_v4address, &src_prefix_length))
376 vec_validate_acl_rules(rules, rule_idx);
377 memcpy (rules[rule_idx].src_ip_addr, &src_v4address, 4);
378 rules[rule_idx].src_ip_prefix_len = src_prefix_length;
379 rules[rule_idx].is_ipv6 = 0;
381 else if (unformat (i, "src %U/%d",
382 unformat_ip6_address, &src_v6address, &src_prefix_length))
384 vec_validate_acl_rules(rules, rule_idx);
385 memcpy (rules[rule_idx].src_ip_addr, &src_v6address, 16);
386 rules[rule_idx].src_ip_prefix_len = src_prefix_length;
387 rules[rule_idx].is_ipv6 = 1;
389 else if (unformat (i, "dst %U/%d",
390 unformat_ip4_address, &dst_v4address, &dst_prefix_length))
392 vec_validate_acl_rules(rules, rule_idx);
393 memcpy (rules[rule_idx].dst_ip_addr, &dst_v4address, 4);
394 rules[rule_idx].dst_ip_prefix_len = dst_prefix_length;
395 rules[rule_idx].is_ipv6 = 0;
397 else if (unformat (i, "dst %U/%d",
398 unformat_ip6_address, &dst_v6address, &dst_prefix_length))
400 vec_validate_acl_rules(rules, rule_idx);
401 memcpy (rules[rule_idx].dst_ip_addr, &dst_v6address, 16);
402 rules[rule_idx].dst_ip_prefix_len = dst_prefix_length;
403 rules[rule_idx].is_ipv6 = 1;
405 else if (unformat (i, "sport %d-%d", &port1, &port2))
407 vec_validate_acl_rules(rules, rule_idx);
408 rules[rule_idx].srcport_or_icmptype_first = htons(port1);
409 rules[rule_idx].srcport_or_icmptype_last = htons(port2);
411 else if (unformat (i, "sport %d", &port1))
413 vec_validate_acl_rules(rules, rule_idx);
414 rules[rule_idx].srcport_or_icmptype_first = htons(port1);
415 rules[rule_idx].srcport_or_icmptype_last = htons(port1);
417 else if (unformat (i, "dport %d-%d", &port1, &port2))
419 vec_validate_acl_rules(rules, rule_idx);
420 rules[rule_idx].dstport_or_icmpcode_first = htons(port1);
421 rules[rule_idx].dstport_or_icmpcode_last = htons(port2);
423 else if (unformat (i, "dport %d", &port1))
425 vec_validate_acl_rules(rules, rule_idx);
426 rules[rule_idx].dstport_or_icmpcode_first = htons(port1);
427 rules[rule_idx].dstport_or_icmpcode_last = htons(port1);
429 else if (unformat (i, "tcpflags %d %d", &tcpflags, &tcpmask))
431 vec_validate_acl_rules(rules, rule_idx);
432 rules[rule_idx].tcp_flags_value = tcpflags;
433 rules[rule_idx].tcp_flags_mask = tcpmask;
435 else if (unformat (i, "proto %d", &proto))
437 vec_validate_acl_rules(rules, rule_idx);
438 rules[rule_idx].proto = proto;
440 else if (unformat (i, "tag %s", &tag))
443 else if (unformat (i, ","))
446 vec_validate_acl_rules(rules, rule_idx);
452 /* Construct the API message */
453 vam->result_ready = 0;
456 n_rules = vec_len(rules);
460 msg_size += n_rules*sizeof(rules[0]);
462 mp = vl_msg_api_alloc_as_if_client(msg_size);
463 memset (mp, 0, msg_size);
464 mp->_vl_msg_id = ntohs (VL_API_ACL_ADD_REPLACE + sm->msg_id_base);
465 mp->client_index = vam->my_client_index;
467 clib_memcpy(mp->r, rules, n_rules*sizeof (vl_api_acl_rule_t));
470 if (vec_len(tag) >= sizeof(mp->tag))
472 tag[sizeof(mp->tag)-1] = 0;
473 _vec_len(tag) = sizeof(mp->tag);
475 clib_memcpy(mp->tag, tag, vec_len(tag));
478 mp->acl_index = ntohl(acl_index);
479 mp->count = htonl(n_rules);
484 /* Wait for a reply... */
488 static int api_acl_del (vat_main_t * vam)
490 unformat_input_t * i = vam->input;
492 vl_api_acl_del_t * mp;
495 if (!unformat (i, "%d", &acl_index)) {
496 errmsg ("missing acl index\n");
500 /* Construct the API message */
502 mp->acl_index = ntohl(acl_index);
507 /* Wait for a reply... */
511 static int api_macip_acl_del (vat_main_t * vam)
513 unformat_input_t * i = vam->input;
515 vl_api_acl_del_t * mp;
518 if (!unformat (i, "%d", &acl_index)) {
519 errmsg ("missing acl index\n");
523 /* Construct the API message */
524 M(MACIP_ACL_DEL, acl_del);
525 mp->acl_index = ntohl(acl_index);
530 /* Wait for a reply... */
534 static int api_acl_interface_add_del (vat_main_t * vam)
536 unformat_input_t * i = vam->input;
538 vl_api_acl_interface_add_del_t * mp;
539 u32 sw_if_index = ~0;
544 // acl_interface_add_del <intfc> | sw_if_index <if-idx> acl_index <acl-idx> [out] [del]
546 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
548 if (unformat (i, "%d", &acl_index))
555 /* Parse args required to build the message */
556 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
557 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
559 else if (unformat (i, "sw_if_index %d", &sw_if_index))
561 else if (unformat (i, "add"))
563 else if (unformat (i, "del"))
565 else if (unformat (i, "acl %d", &acl_index))
567 else if (unformat (i, "input"))
569 else if (unformat (i, "output"))
575 if (sw_if_index == ~0) {
576 errmsg ("missing interface name / explicit sw_if_index number \n");
580 if (acl_index == ~0) {
581 errmsg ("missing ACL index\n");
587 /* Construct the API message */
588 M(ACL_INTERFACE_ADD_DEL, acl_interface_add_del);
589 mp->acl_index = ntohl(acl_index);
590 mp->sw_if_index = ntohl(sw_if_index);
592 mp->is_input = is_input;
597 /* Wait for a reply... */
601 static int api_macip_acl_interface_add_del (vat_main_t * vam)
603 unformat_input_t * i = vam->input;
605 vl_api_macip_acl_interface_add_del_t * mp;
606 u32 sw_if_index = ~0;
610 /* Parse args required to build the message */
611 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
612 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
614 else if (unformat (i, "sw_if_index %d", &sw_if_index))
616 else if (unformat (i, "add"))
618 else if (unformat (i, "del"))
620 else if (unformat (i, "acl %d", &acl_index))
626 if (sw_if_index == ~0) {
627 errmsg ("missing interface name / explicit sw_if_index number \n");
631 if (acl_index == ~0) {
632 errmsg ("missing ACL index\n");
638 /* Construct the API message */
639 M(MACIP_ACL_INTERFACE_ADD_DEL, macip_acl_interface_add_del);
640 mp->acl_index = ntohl(acl_index);
641 mp->sw_if_index = ntohl(sw_if_index);
647 /* Wait for a reply... */
651 static int api_acl_interface_set_acl_list (vat_main_t * vam)
653 unformat_input_t * i = vam->input;
655 vl_api_acl_interface_set_acl_list_t * mp;
656 u32 sw_if_index = ~0;
662 // acl_interface_set_acl_list <intfc> | sw_if_index <if-idx> input [acl-idx list] output [acl-idx list]
664 /* Parse args required to build the message */
665 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
666 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
668 else if (unformat (i, "sw_if_index %d", &sw_if_index))
670 else if (unformat (i, "%d", &acl_index))
673 vec_add1(inacls, htonl(acl_index));
675 vec_add1(outacls, htonl(acl_index));
677 else if (unformat (i, "acl %d", &acl_index))
679 else if (unformat (i, "input"))
681 else if (unformat (i, "output"))
687 if (sw_if_index == ~0) {
688 errmsg ("missing interface name / explicit sw_if_index number \n");
692 /* Construct the API message */
693 M2(ACL_INTERFACE_SET_ACL_LIST, acl_interface_set_acl_list, sizeof(u32) * (vec_len(inacls) + vec_len(outacls)));
694 mp->sw_if_index = ntohl(sw_if_index);
695 mp->n_input = vec_len(inacls);
696 mp->count = vec_len(inacls) + vec_len(outacls);
697 vec_append(inacls, outacls);
698 if (vec_len(inacls) > 0)
699 clib_memcpy(mp->acls, inacls, vec_len(inacls)*sizeof(u32));
704 /* Wait for a reply... */
709 static int api_acl_interface_list_dump (vat_main_t * vam)
711 unformat_input_t * i = vam->input;
713 u32 sw_if_index = ~0;
714 vl_api_acl_interface_list_dump_t * mp;
716 /* Parse args required to build the message */
717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
718 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
720 else if (unformat (i, "sw_if_index %d", &sw_if_index))
726 /* Construct the API message */
727 M(ACL_INTERFACE_LIST_DUMP, acl_interface_list_dump);
728 mp->sw_if_index = ntohl (sw_if_index);
733 /* Wait for a reply... */
737 static int api_acl_dump (vat_main_t * vam)
739 unformat_input_t * i = vam->input;
742 vl_api_acl_dump_t * mp;
744 /* Parse args required to build the message */
745 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
746 if (unformat (i, "%d", &acl_index))
752 /* Construct the API message */
753 M(ACL_DUMP, acl_dump);
754 mp->acl_index = ntohl (acl_index);
759 /* Wait for a reply... */
763 static int api_macip_acl_dump (vat_main_t * vam)
765 unformat_input_t * i = vam->input;
768 vl_api_acl_dump_t * mp;
770 /* Parse args required to build the message */
771 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
772 if (unformat (i, "%d", &acl_index))
778 /* Construct the API message */
779 M(MACIP_ACL_DUMP, macip_acl_dump);
780 mp->acl_index = ntohl (acl_index);
785 /* Wait for a reply... */
789 #define vec_validate_macip_acl_rules(v, idx) \
791 if (vec_len(v) < idx+1) { \
792 vec_validate(v, idx); \
793 v[idx].is_permit = 0x1; \
798 static int api_macip_acl_add (vat_main_t * vam)
800 acl_test_main_t * sm = &acl_test_main;
801 unformat_input_t * i = vam->input;
803 vl_api_macip_acl_add_t * mp;
804 u32 msg_size = sizeof (*mp); /* without the rules */
806 vl_api_macip_acl_rule_t *rules = 0;
809 u32 src_prefix_length = 0;
811 ip4_address_t src_v4address;
812 ip6_address_t src_v6address;
815 u8 mac_mask_all_1[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
817 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
819 if (unformat (i, "ipv6"))
821 vec_validate_macip_acl_rules(rules, rule_idx);
822 rules[rule_idx].is_ipv6 = 1;
824 else if (unformat (i, "ipv4"))
826 vec_validate_macip_acl_rules(rules, rule_idx);
827 rules[rule_idx].is_ipv6 = 1;
829 else if (unformat (i, "permit"))
831 vec_validate_macip_acl_rules(rules, rule_idx);
832 rules[rule_idx].is_permit = 1;
834 else if (unformat (i, "deny"))
836 vec_validate_macip_acl_rules(rules, rule_idx);
837 rules[rule_idx].is_permit = 0;
839 else if (unformat (i, "action %d", &action))
841 vec_validate_macip_acl_rules(rules, rule_idx);
842 rules[rule_idx].is_permit = action;
844 else if (unformat (i, "ip %U/%d",
845 unformat_ip4_address, &src_v4address, &src_prefix_length))
847 vec_validate_macip_acl_rules(rules, rule_idx);
848 memcpy (rules[rule_idx].src_ip_addr, &src_v4address, 4);
849 rules[rule_idx].src_ip_prefix_len = src_prefix_length;
850 rules[rule_idx].is_ipv6 = 0;
852 else if (unformat (i, "ip %U/%d",
853 unformat_ip6_address, &src_v6address, &src_prefix_length))
855 vec_validate_macip_acl_rules(rules, rule_idx);
856 memcpy (rules[rule_idx].src_ip_addr, &src_v6address, 16);
857 rules[rule_idx].src_ip_prefix_len = src_prefix_length;
858 rules[rule_idx].is_ipv6 = 1;
860 else if (unformat (i, "mac %U",
861 my_unformat_mac_address, &src_mac))
863 vec_validate_macip_acl_rules(rules, rule_idx);
864 memcpy (rules[rule_idx].src_mac, &src_mac, 6);
865 memcpy (rules[rule_idx].src_mac_mask, &mac_mask_all_1, 6);
867 else if (unformat (i, "mask %U",
868 my_unformat_mac_address, &src_mac))
870 vec_validate_macip_acl_rules(rules, rule_idx);
871 memcpy (rules[rule_idx].src_mac_mask, &src_mac, 6);
873 else if (unformat (i, "tag %s", &tag))
876 else if (unformat (i, ","))
879 vec_validate_macip_acl_rules(rules, rule_idx);
885 /* Construct the API message */
886 vam->result_ready = 0;
889 n_rules = vec_len(rules);
893 msg_size += n_rules*sizeof(rules[0]);
895 mp = vl_msg_api_alloc_as_if_client(msg_size);
896 memset (mp, 0, msg_size);
897 mp->_vl_msg_id = ntohs (VL_API_MACIP_ACL_ADD + sm->msg_id_base);
898 mp->client_index = vam->my_client_index;
900 clib_memcpy(mp->r, rules, n_rules*sizeof (mp->r[0]));
903 if (vec_len(tag) >= sizeof(mp->tag))
905 tag[sizeof(mp->tag)-1] = 0;
906 _vec_len(tag) = sizeof(mp->tag);
908 clib_memcpy(mp->tag, tag, vec_len(tag));
912 mp->count = htonl(n_rules);
917 /* Wait for a reply... */
922 * List of messages that the api test plugin sends,
923 * and that the data plane plugin processes
925 #define foreach_vpe_api_msg \
926 _(acl_plugin_get_version, "") \
927 _(acl_add_replace, "<acl-idx> [<ipv4|ipv6> <permit|permit+reflect|deny|action N> [src IP/plen] [dst IP/plen] [sport X-Y] [dport X-Y] [proto P] [tcpflags FL MASK], ... , ...") \
928 _(acl_del, "<acl-idx>") \
929 _(acl_dump, "[<acl-idx>]") \
930 _(acl_interface_add_del, "<intfc> | sw_if_index <if-idx> [add|del] [input|output] acl <acl-idx>") \
931 _(acl_interface_set_acl_list, "<intfc> | sw_if_index <if-idx> input [acl-idx list] output [acl-idx list]") \
932 _(acl_interface_list_dump, "[<intfc> | sw_if_index <if-idx>]") \
933 _(macip_acl_add, "...") \
934 _(macip_acl_del, "<acl-idx>")\
935 _(macip_acl_dump, "[<acl-idx>]") \
936 _(macip_acl_interface_add_del, "<intfc> | sw_if_index <if-idx> [add|del] acl <acl-idx>") \
937 _(macip_acl_interface_get, "")
941 void acl_vat_api_hookup (vat_main_t *vam)
943 acl_test_main_t * sm = &acl_test_main;
944 /* Hook up handlers for replies from the data plane plug-in */
946 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
948 vl_api_##n##_t_handler, \
950 vl_api_##n##_t_endian, \
951 vl_api_##n##_t_print, \
952 sizeof(vl_api_##n##_t), 1);
953 foreach_vpe_api_reply_msg;
956 /* API messages we can send */
957 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
962 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
967 clib_error_t * vat_plugin_register (vat_main_t *vam)
969 acl_test_main_t * sm = &acl_test_main;
974 name = format (0, "acl_%08x%c", api_version, 0);
975 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
977 if (sm->msg_id_base != (u16) ~0)
978 acl_vat_api_hookup (vam);