acl-plugin: missing "deny" parameter in API
[vpp.git] / src / plugins / acl / acl_test.c
index 04683a1..847c5b5 100644 (file)
@@ -164,14 +164,14 @@ vl_api_acl_rule_t_pretty_format (u8 *out, vl_api_acl_rule_t * a)
   inet_ntop(af, a->src_ip_addr, (void *)src, sizeof(src));
   inet_ntop(af, a->dst_ip_addr, (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 %d",
+  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->is_ipv6 ? "ipv6" : "ipv4", a->is_permit,
                      src, a->src_ip_prefix_len,
                      dst, a->dst_ip_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_mask, a->tcp_flags_value);
+                     a->tcp_flags_value, a->tcp_flags_mask);
   return(out);
 }
 
@@ -267,7 +267,7 @@ static int api_acl_plugin_get_version (vat_main_t * vam)
     acl_test_main_t * sm = &acl_test_main;
     vl_api_acl_plugin_get_version_t * mp;
     u32 msg_size = sizeof(*mp);
-    f64 timeout;
+    int ret;
 
     vam->result_ready = 0;
     mp = vl_msg_api_alloc_as_if_client(msg_size);
@@ -276,12 +276,11 @@ static int api_acl_plugin_get_version (vat_main_t * vam)
     mp->client_index = vam->my_client_index;
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
-
-    return 0;
+    W (ret);
+    return ret;
 }
 
 static int api_macip_acl_interface_get (vat_main_t * vam)
@@ -289,7 +288,7 @@ static int api_macip_acl_interface_get (vat_main_t * vam)
     acl_test_main_t * sm = &acl_test_main;
     vl_api_acl_plugin_get_version_t * mp;
     u32 msg_size = sizeof(*mp);
-    f64 timeout;
+    int ret;
 
     vam->result_ready = 0;
     mp = vl_msg_api_alloc_as_if_client(msg_size);
@@ -298,12 +297,11 @@ static int api_macip_acl_interface_get (vat_main_t * vam)
     mp->client_index = vam->my_client_index;
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
-
-    return 0;
+    W (ret);
+    return ret;
 }
 
 #define vec_validate_acl_rules(v, idx) \
@@ -321,7 +319,6 @@ static int api_acl_add_replace (vat_main_t * vam)
 {
     acl_test_main_t * sm = &acl_test_main;
     unformat_input_t * i = vam->input;
-    f64 timeout;
     vl_api_acl_add_replace_t * mp;
     u32 acl_index = ~0;
     u32 msg_size = sizeof (*mp); /* without the rules */
@@ -329,6 +326,7 @@ static int api_acl_add_replace (vat_main_t * vam)
     vl_api_acl_rule_t *rules = 0;
     int rule_idx = 0;
     int n_rules = 0;
+    int n_rules_override = -1;
     u32 proto = 0;
     u32 port1 = 0;
     u32 port2 = 0;
@@ -338,6 +336,7 @@ static int api_acl_add_replace (vat_main_t * vam)
     ip4_address_t src_v4address, dst_v4address;
     ip6_address_t src_v6address, dst_v6address;
     u8 *tag = 0;
+    int ret;
 
     if (!unformat (i, "%d", &acl_index)) {
        /* Just assume -1 */
@@ -365,6 +364,15 @@ static int api_acl_add_replace (vat_main_t * vam)
             vec_validate_acl_rules(rules, rule_idx);
             rules[rule_idx].is_permit = 1;
           }
+        else if (unformat (i, "deny"))
+          {
+            vec_validate_acl_rules(rules, rule_idx);
+            rules[rule_idx].is_permit = 0;
+          }
+        else if (unformat (i, "count %d", &n_rules_override))
+          {
+            /* we will use this later */
+          }
         else if (unformat (i, "action %d", &action))
           {
             vec_validate_acl_rules(rules, rule_idx);
@@ -432,6 +440,12 @@ static int api_acl_add_replace (vat_main_t * vam)
             rules[rule_idx].tcp_flags_value = tcpflags;
             rules[rule_idx].tcp_flags_mask = tcpmask;
           }
+        else if (unformat (i, "tcpflags %d mask %d", &tcpflags, &tcpmask))
+          {
+            vec_validate_acl_rules(rules, rule_idx);
+            rules[rule_idx].tcp_flags_value = tcpflags;
+            rules[rule_idx].tcp_flags_mask = tcpmask;
+          }
         else if (unformat (i, "proto %d", &proto))
           {
             vec_validate_acl_rules(rules, rule_idx);
@@ -457,6 +471,9 @@ static int api_acl_add_replace (vat_main_t * vam)
     else
       n_rules = 0;
 
+    if (n_rules_override >= 0)
+      n_rules = n_rules_override;
+
     msg_size += n_rules*sizeof(rules[0]);
 
     mp = vl_msg_api_alloc_as_if_client(msg_size);
@@ -479,18 +496,19 @@ static int api_acl_add_replace (vat_main_t * vam)
     mp->count = htonl(n_rules);
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 static int api_acl_del (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
-    f64 timeout;
     vl_api_acl_del_t * mp;
     u32 acl_index = ~0;
+    int ret;
 
     if (!unformat (i, "%d", &acl_index)) {
       errmsg ("missing acl index\n");
@@ -502,18 +520,19 @@ static int api_acl_del (vat_main_t * vam)
     mp->acl_index = ntohl(acl_index);
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 static int api_macip_acl_del (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
-    f64 timeout;
     vl_api_acl_del_t * mp;
     u32 acl_index = ~0;
+    int ret;
 
     if (!unformat (i, "%d", &acl_index)) {
       errmsg ("missing acl index\n");
@@ -525,21 +544,22 @@ static int api_macip_acl_del (vat_main_t * vam)
     mp->acl_index = ntohl(acl_index);
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 static int api_acl_interface_add_del (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
-    f64 timeout;
     vl_api_acl_interface_add_del_t * mp;
     u32 sw_if_index = ~0;
     u32 acl_index = ~0;
     u8 is_input = 0;
     u8 is_add = 0;
+    int ret;
 
 //    acl_interface_add_del <intfc> | sw_if_index <if-idx> acl_index <acl-idx> [out] [del]
 
@@ -592,20 +612,21 @@ static int api_acl_interface_add_del (vat_main_t * vam)
     mp->is_input = is_input;
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 static int api_macip_acl_interface_add_del (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
-    f64 timeout;
     vl_api_macip_acl_interface_add_del_t * mp;
     u32 sw_if_index = ~0;
     u32 acl_index = ~0;
     u8 is_add = 0;
+    int ret;
 
     /* Parse args required to build the message */
     while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
@@ -642,22 +663,23 @@ static int api_macip_acl_interface_add_del (vat_main_t * vam)
     mp->is_add = is_add;
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 static int api_acl_interface_set_acl_list (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
-    f64 timeout;
     vl_api_acl_interface_set_acl_list_t * mp;
     u32 sw_if_index = ~0;
     u32 acl_index = ~0;
     u32 *inacls = 0;
     u32 *outacls = 0;
     u8 is_input = 0;
+    int ret;
 
 //  acl_interface_set_acl_list <intfc> | sw_if_index <if-idx> input [acl-idx list] output [acl-idx list]
 
@@ -699,19 +721,20 @@ static int api_acl_interface_set_acl_list (vat_main_t * vam)
       clib_memcpy(mp->acls, inacls, vec_len(inacls)*sizeof(u32));
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 
 static int api_acl_interface_list_dump (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
-    f64 timeout;
     u32 sw_if_index = ~0;
     vl_api_acl_interface_list_dump_t * mp;
+    int ret;
 
     /* Parse args required to build the message */
     while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
@@ -728,18 +751,19 @@ static int api_acl_interface_list_dump (vat_main_t * vam)
     mp->sw_if_index = ntohl (sw_if_index);
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 static int api_acl_dump (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
-    f64 timeout;
     u32 acl_index = ~0;
     vl_api_acl_dump_t * mp;
+    int ret;
 
     /* Parse args required to build the message */
     while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
@@ -754,18 +778,19 @@ static int api_acl_dump (vat_main_t * vam)
     mp->acl_index = ntohl (acl_index);
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 static int api_macip_acl_dump (vat_main_t * vam)
 {
     unformat_input_t * i = vam->input;
-    f64 timeout;
     u32 acl_index = ~0;
     vl_api_acl_dump_t * mp;
+    int ret;
 
     /* Parse args required to build the message */
     while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
@@ -780,10 +805,11 @@ static int api_macip_acl_dump (vat_main_t * vam)
     mp->acl_index = ntohl (acl_index);
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 #define vec_validate_macip_acl_rules(v, idx) \
@@ -799,13 +825,13 @@ static int api_macip_acl_add (vat_main_t * vam)
 {
     acl_test_main_t * sm = &acl_test_main;
     unformat_input_t * i = vam->input;
-    f64 timeout;
     vl_api_macip_acl_add_t * mp;
     u32 msg_size = sizeof (*mp); /* without the rules */
 
     vl_api_macip_acl_rule_t *rules = 0;
     int rule_idx = 0;
     int n_rules = 0;
+    int n_rules_override = -1;
     u32 src_prefix_length = 0;
     u32 action = 0;
     ip4_address_t src_v4address;
@@ -813,6 +839,7 @@ static int api_macip_acl_add (vat_main_t * vam)
     u8 src_mac[6];
     u8 *tag = 0;
     u8 mac_mask_all_1[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+    int ret;
 
     while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
     {
@@ -836,6 +863,10 @@ static int api_macip_acl_add (vat_main_t * vam)
             vec_validate_macip_acl_rules(rules, rule_idx);
             rules[rule_idx].is_permit = 0;
           }
+        else if (unformat (i, "count %d", &n_rules_override))
+          {
+            /* we will use this later */
+          }
         else if (unformat (i, "action %d", &action))
           {
             vec_validate_macip_acl_rules(rules, rule_idx);
@@ -849,6 +880,10 @@ static int api_macip_acl_add (vat_main_t * vam)
             rules[rule_idx].src_ip_prefix_len = src_prefix_length;
             rules[rule_idx].is_ipv6 = 0;
           }
+        else if (unformat (i, "src"))
+          {
+            /* Everything in MACIP is "source" but allow this verbosity */
+          }
         else if (unformat (i, "ip %U/%d",
          unformat_ip6_address, &src_v6address, &src_prefix_length))
           {
@@ -890,6 +925,9 @@ static int api_macip_acl_add (vat_main_t * vam)
     else
       n_rules = 0;
 
+    if (n_rules_override >= 0)
+      n_rules = n_rules_override;
+
     msg_size += n_rules*sizeof(rules[0]);
 
     mp = vl_msg_api_alloc_as_if_client(msg_size);
@@ -912,10 +950,11 @@ static int api_macip_acl_add (vat_main_t * vam)
     mp->count = htonl(n_rules);
 
     /* send it... */
-    S;
+    S(mp);
 
     /* Wait for a reply... */
-    W;
+    W (ret);
+    return ret;
 }
 
 /*