ip: Replace Sematics for Interface IP addresses
[vpp.git] / src / plugins / abf / abf_policy.c
index 9c74065..8defa75 100644 (file)
@@ -76,7 +76,7 @@ abf_policy_find (u32 policy_id)
 }
 
 
-void
+int
 abf_policy_update (u32 policy_id,
                   u32 acl_index, const fib_route_path_t * rpaths)
 {
@@ -121,13 +121,18 @@ abf_policy_update (u32 policy_id,
     {
       /*
        * update an existing policy.
-       * - add the path to the path-list and swap our ancestory
+       * - add the path to the path-list and swap our ancestry
        * - backwalk to poke all attachments to update
        */
       fib_node_index_t old_pl;
 
       ap = abf_policy_get (api);
       old_pl = ap->ap_pl;
+      if (ap->ap_acl != acl_index)
+       {
+         /* Should change this error code to something more descriptive */
+         return (VNET_API_ERROR_INVALID_VALUE);
+       }
 
       if (FIB_NODE_INDEX_INVALID != old_pl)
        {
@@ -155,6 +160,7 @@ abf_policy_update (u32 policy_id,
 
       fib_walk_sync (abf_policy_fib_node_type, api, &ctx);
     }
+  return (0);
 }
 
 static void
@@ -184,13 +190,13 @@ abf_policy_delete (u32 policy_id, const fib_route_path_t * rpaths)
       /*
        * no such policy
        */
-      return (-1);
+      return (VNET_API_ERROR_INVALID_VALUE);
     }
   else
     {
       /*
        * update an existing policy.
-       * - add the path to the path-list and swap our ancestory
+       * - add the path to the path-list and swap our ancestry
        * - backwalk to poke all attachments to update
        */
       fib_node_index_t old_pl;
@@ -198,6 +204,7 @@ abf_policy_delete (u32 policy_id, const fib_route_path_t * rpaths)
       ap = abf_policy_get (api);
       old_pl = ap->ap_pl;
 
+      fib_path_list_lock (old_pl);
       ap->ap_pl =
        fib_path_list_copy_and_path_remove (ap->ap_pl,
                                            (FIB_PATH_LIST_FLAG_SHARED |
@@ -227,6 +234,7 @@ abf_policy_delete (u32 policy_id, const fib_route_path_t * rpaths)
 
          fib_walk_sync (abf_policy_fib_node_type, api, &ctx);
        }
+      fib_path_list_unlock (old_pl);
     }
 
   return (0);
@@ -237,9 +245,10 @@ abf_policy_cmd (vlib_main_t * vm,
                unformat_input_t * main_input, vlib_cli_command_t * cmd)
 {
   unformat_input_t _line_input, *line_input = &_line_input;
-  u32 acl_index, policy_id;
   fib_route_path_t *rpaths = NULL, rpath;
-  u32 is_del;
+  u32 acl_index, policy_id, is_del;
+  dpo_proto_t payload_proto;
+  int rv = 0;
 
   is_del = 0;
   acl_index = INDEX_INVALID;
@@ -260,7 +269,7 @@ abf_policy_cmd (vlib_main_t * vm,
       else if (unformat (line_input, "add"))
        is_del = 0;
       else if (unformat (line_input, "via %U",
-                        unformat_fib_route_path, &rpath))
+                        unformat_fib_route_path, &rpath, &payload_proto))
        vec_add1 (rpaths, rpath);
       else
        return (clib_error_return (0, "unknown input '%U'",
@@ -281,7 +290,14 @@ abf_policy_cmd (vlib_main_t * vm,
          return 0;
        }
 
-      abf_policy_update (policy_id, acl_index, rpaths);
+      rv = abf_policy_update (policy_id, acl_index, rpaths);
+      /* Should change this error code to something more descriptive */
+      if (rv == VNET_API_ERROR_INVALID_VALUE)
+       {
+         vlib_cli_output (vm,
+                          "ACL index must match existing ACL index in policy");
+         return 0;
+       }
     }
   else
     {