sr: fix coverity warning
[vpp.git] / src / vnet / srv6 / sr_steering.c
old mode 100755 (executable)
new mode 100644 (file)
index 66186e9..6e5c5e0
@@ -135,21 +135,22 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
          else if (steer_pl->classify.traffic_type == SR_STEER_L2)
            {
              /* Remove HW redirection */
-             vnet_feature_enable_disable ("device-input",
-                                          "sr-policy-rewrite-encaps-l2",
-                                          sw_if_index, 0, 0, 0);
+             int ret = vnet_feature_enable_disable ("device-input",
+                                                    "sr-pl-rewrite-encaps-l2",
+                                                    sw_if_index, 0, 0, 0);
+
+             if (ret != 0)
+               return -1;
+
              sm->sw_iface_sr_policies[sw_if_index] = ~(u32) 0;
 
              /* Remove promiscous mode from interface */
              vnet_main_t *vnm = vnet_get_main ();
-             ethernet_main_t *em = &ethernet_main;
-             ethernet_interface_t *eif =
-               ethernet_get_interface (em, sw_if_index);
-
-             if (!eif)
-               goto cleanup_error_redirection;
-
-             ethernet_set_flags (vnm, sw_if_index, 0);
+             vnet_hw_interface_t *hi =
+               vnet_get_sup_hw_interface (vnm, sw_if_index);
+             /* Make sure it is main interface */
+             if (hi->sw_if_index == sw_if_index)
+               ethernet_set_flags (vnm, hi->hw_if_index, 0);
            }
 
          /* Delete SR steering policy entry */
@@ -183,9 +184,6 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
          else
            sr_policy = pool_elt_at_index (sm->sr_policies, sr_policy_index);
 
-         if (!sr_policy)
-           return -2;
-
          steer_pl->sr_policy = sr_policy - sm->sr_policies;
 
          /* Remove old FIB/hw redirection and create a new one */
@@ -285,14 +283,11 @@ sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
 
       /* Set promiscous mode on interface */
       vnet_main_t *vnm = vnet_get_main ();
-      ethernet_main_t *em = &ethernet_main;
-      ethernet_interface_t *eif = ethernet_get_interface (em, sw_if_index);
-
-      if (!eif)
-       goto cleanup_error_redirection;
-
-      ethernet_set_flags (vnm, sw_if_index,
-                         ETHERNET_INTERFACE_FLAG_ACCEPT_ALL);
+      vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
+      /* Make sure it is main interface */
+      if (hi->sw_if_index == sw_if_index)
+       ethernet_set_flags (vnm, hi->hw_if_index,
+                           ETHERNET_INTERFACE_FLAG_ACCEPT_ALL);
     }
   else if (traffic_type == SR_STEER_IPV4)
     if (!sr_policy->is_encap)
@@ -413,7 +408,7 @@ sr_steer_policy_command_fn (vlib_main_t * vm, unformat_input_t * input,
 
   if (!traffic_type)
     return clib_error_return (0, "No L2/L3 traffic specified");
-  if (!sr_policy_set)
+  if (!is_del && !sr_policy_set)
     return clib_error_return (0, "No SR policy specified");
 
   /* Make sure that the prefixes are clean */
@@ -494,7 +489,7 @@ show_sr_steering_policies_command_fn (vlib_main_t * vm,
 
   vlib_cli_output (vm, "SR steering policies:");
   /* *INDENT-OFF* */
-  pool_foreach (steer_pl, sm->steer_policies, ({vec_add1(steer_policies, steer_pl);}));
+  pool_foreach (steer_pl, sm->steer_policies) {vec_add1(steer_policies, steer_pl);}
   /* *INDENT-ON* */
   vlib_cli_output (vm, "Traffic\t\tSR policy BSID");
   for (i = 0; i < vec_len (steer_policies); i++)