diff options
Diffstat (limited to 'src/plugins/acl/acl_test.c')
-rw-r--r-- | src/plugins/acl/acl_test.c | 135 |
1 files changed, 102 insertions, 33 deletions
diff --git a/src/plugins/acl/acl_test.c b/src/plugins/acl/acl_test.c index 79058cdc268..98803a916cb 100644 --- a/src/plugins/acl/acl_test.c +++ b/src/plugins/acl/acl_test.c @@ -18,6 +18,8 @@ *------------------------------------------------------------------ */ +#include <byteswap.h> + #include <vat/vat.h> #include <vlibapi/api.h> #include <vlibmemory/api.h> @@ -36,8 +38,6 @@ uword unformat_sw_if_index (unformat_input_t * input, va_list * args); /* Declare message IDs */ #include <acl/acl.api_enum.h> #include <acl/acl.api_types.h> -#define vl_print(handle, ...) -#undef vl_print #define vl_endianfun /* define message structures */ #include <acl/acl.api.h> #undef vl_endianfun @@ -99,13 +99,22 @@ static void vl_api_acl_plugin_get_version_reply_t_handler vam->result_ready = 1; } + static void + vl_api_acl_plugin_use_hash_lookup_get_reply_t_handler ( + vl_api_acl_plugin_use_hash_lookup_get_reply_t *mp) + { + vat_main_t *vam = acl_test_main.vat_main; + clib_warning ("ACL hash lookups enabled: %d", mp->enable); + vam->result_ready = 1; + } + static void vl_api_acl_interface_list_details_t_handler (vl_api_acl_interface_list_details_t * mp) { int i; vat_main_t * vam = acl_test_main.vat_main; u8 *out = 0; - vl_api_acl_interface_list_details_t_endian(mp); + vl_api_acl_interface_list_details_t_endian (mp, 0 /* from network */); out = format(out, "sw_if_index: %d, count: %d, n_input: %d\n", mp->sw_if_index, mp->count, mp->n_input); out = format(out, " input "); for(i=0; i<mp->count; i++) { @@ -132,7 +141,8 @@ static void vl_api_acl_interface_etype_whitelist_details_t_handler int i; vat_main_t * vam = acl_test_main.vat_main; u8 *out = 0; - vl_api_acl_interface_etype_whitelist_details_t_endian(mp); + vl_api_acl_interface_etype_whitelist_details_t_endian ( + mp, 0 /* from network */); out = format(out, "sw_if_index: %d, count: %d, n_input: %d\n", mp->sw_if_index, mp->count, mp->n_input); out = format(out, " input "); for(i=0; i<mp->count; i++) { @@ -150,9 +160,9 @@ static void vl_api_acl_plugin_get_conn_table_max_entries_reply_t_handler (vl_api_acl_plugin_get_conn_table_max_entries_reply_t * mp) { vat_main_t * vam = acl_test_main.vat_main; - clib_warning("\nConn table max entries: %d", - __bswap_64(mp->conn_table_max_entries) ); - vam->result_ready = 1; + clib_warning ("\nConn table max entries: %d", + clib_net_to_host_u64 (mp->conn_table_max_entries)); + vam->result_ready = 1; } static inline u8 * @@ -164,15 +174,15 @@ vl_api_acl_rule_t_pretty_format (u8 *out, vl_api_acl_rule_t * a) inet_ntop(af, &a->src_prefix.address.un, (void *)src, sizeof(src)); inet_ntop(af, &a->dst_prefix.address.un, (void *)dst, sizeof(dst)); - out = format(out, "%s action %d src %s/%d dst %s/%d proto %d sport %d-%d dport %d-%d tcpflags %d mask %d", - a->src_prefix.address.af ? "ipv6" : "ipv4", a->is_permit, - src, a->src_prefix.len, - dst, a->dst_prefix.len, - a->proto, - a->srcport_or_icmptype_first, a->srcport_or_icmptype_last, - a->dstport_or_icmpcode_first, a->dstport_or_icmpcode_last, - a->tcp_flags_value, a->tcp_flags_mask); - return(out); + out = format (out, + "%s action %d src %s/%d dst %s/%d proto %d sport %d-%d dport " + "%d-%d tcpflags %d mask %d", + a->src_prefix.address.af ? "ipv6" : "ipv4", a->is_permit, src, + a->src_prefix.len, dst, a->dst_prefix.len, a->proto, + a->srcport_or_icmptype_first, a->srcport_or_icmptype_last, + a->dstport_or_icmpcode_first, a->dstport_or_icmpcode_last, + a->tcp_flags_value, a->tcp_flags_mask); + return (out); } @@ -182,9 +192,10 @@ static void vl_api_acl_details_t_handler { int i; vat_main_t * vam = acl_test_main.vat_main; - vl_api_acl_details_t_endian(mp); - u8 *out = 0; - out = format(0, "acl_index: %d, count: %d\n tag {%s}\n", mp->acl_index, mp->count, mp->tag); + vl_api_acl_details_t_endian (mp, 0 /* from network */); + u8 *out = 0; + out = format (0, "acl_index: %d, count: %d\n tag {%s}\n", + mp->acl_index, mp->count, mp->tag); for(i=0; i<mp->count; i++) { out = format(out, " "); out = vl_api_acl_rule_t_pretty_format(out, &mp->r[i]); @@ -216,8 +227,9 @@ static void vl_api_macip_acl_details_t_handler { int i; vat_main_t * vam = acl_test_main.vat_main; - vl_api_macip_acl_details_t_endian(mp); - u8 *out = format(0,"MACIP acl_index: %d, count: %d\n tag {%s}\n", mp->acl_index, mp->count, mp->tag); + vl_api_macip_acl_details_t_endian (mp, 0 /* from network */); + u8 *out = format (0, "MACIP acl_index: %d, count: %d\n tag {%s}\n", + mp->acl_index, mp->count, mp->tag); for(i=0; i<mp->count; i++) { out = format(out, " "); out = vl_api_macip_acl_rule_t_pretty_format(out, &mp->r[i]); @@ -484,10 +496,10 @@ static int api_acl_add_replace (vat_main_t * vam) if (vec_len(tag) >= sizeof(mp->tag)) { tag[sizeof(mp->tag)-1] = 0; - _vec_len(tag) = sizeof(mp->tag); - } - clib_memcpy(mp->tag, tag, vec_len(tag)); - vec_free(tag); + vec_set_len (tag, sizeof (mp->tag)); + } + clib_memcpy (mp->tag, tag, vec_len (tag)); + vec_free (tag); } mp->acl_index = ntohl(acl_index); mp->count = htonl(n_rules); @@ -551,6 +563,63 @@ static int api_acl_stats_intf_counters_enable (vat_main_t * vam) return ret; } +static int +api_acl_plugin_use_hash_lookup_set (vat_main_t *vam) +{ + acl_test_main_t *sm = &acl_test_main; + unformat_input_t *i = vam->input; + vl_api_acl_plugin_use_hash_lookup_set_t *mp; + u32 msg_size = sizeof (*mp); + int ret; + + vam->result_ready = 0; + mp = vl_msg_api_alloc_as_if_client (msg_size); + memset (mp, 0, msg_size); + mp->_vl_msg_id = + ntohs (VL_API_ACL_PLUGIN_USE_HASH_LOOKUP_SET + sm->msg_id_base); + mp->client_index = vam->my_client_index; + mp->enable = 1; + + while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) + { + if (unformat (i, "disable")) + mp->enable = 0; + else if (unformat (i, "enable")) + mp->enable = 1; + else + break; + } + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} + +static int +api_acl_plugin_use_hash_lookup_get (vat_main_t *vam) +{ + acl_test_main_t *sm = &acl_test_main; + vl_api_acl_plugin_use_hash_lookup_set_t *mp; + u32 msg_size = sizeof (*mp); + int ret; + + vam->result_ready = 0; + mp = vl_msg_api_alloc_as_if_client (msg_size); + memset (mp, 0, msg_size); + mp->_vl_msg_id = + ntohs (VL_API_ACL_PLUGIN_USE_HASH_LOOKUP_GET + sm->msg_id_base); + mp->client_index = vam->my_client_index; + + /* send it... */ + S (mp); + + /* Wait for a reply... */ + W (ret); + return ret; +} /* * Read the series of ACL entries from file in the following format: @@ -1267,10 +1336,10 @@ static int api_macip_acl_add (vat_main_t * vam) if (vec_len(tag) >= sizeof(mp->tag)) { tag[sizeof(mp->tag)-1] = 0; - _vec_len(tag) = sizeof(mp->tag); - } - clib_memcpy(mp->tag, tag, vec_len(tag)); - vec_free(tag); + vec_set_len (tag, sizeof (mp->tag)); + } + clib_memcpy (mp->tag, tag, vec_len (tag)); + vec_free (tag); } mp->count = htonl(n_rules); @@ -1409,10 +1478,10 @@ static int api_macip_acl_add_replace (vat_main_t * vam) if (vec_len(tag) >= sizeof(mp->tag)) { tag[sizeof(mp->tag)-1] = 0; - _vec_len(tag) = sizeof(mp->tag); - } - clib_memcpy(mp->tag, tag, vec_len(tag)); - vec_free(tag); + vec_set_len (tag, sizeof (mp->tag)); + } + clib_memcpy (mp->tag, tag, vec_len (tag)); + vec_free (tag); } mp->acl_index = ntohl(acl_index); |