misc: move to new pool_foreach macros
[vpp.git] / src / plugins / dhcp / dhcp6_ia_na_client_cp.c
index f9c379c..edc6f49 100644 (file)
@@ -20,6 +20,7 @@
 #include <dhcp/dhcp6_ia_na_client_dp.h>
 #include <vnet/ip/ip.h>
 #include <vnet/ip/ip6.h>
+#include <vnet/ip/ip6_link.h>
 #include <float.h>
 #include <math.h>
 
@@ -144,17 +145,6 @@ send_client_message_start_stop (u32 sw_if_index, u32 server_index,
 
 static void interrupt_process (void);
 
-static u32
-ip6_enable (u32 sw_if_index)
-{
-  dhcp6_client_cp_main_t *rm = &dhcp6_client_cp_main;
-  clib_error_t *rv;
-
-  rv = enable_ip6_interface (rm->vlib_main, sw_if_index);
-
-  return rv != 0;
-}
-
 static u8
 ip6_addresses_equal (ip6_address_t * address1, ip6_address_t * address2)
 {
@@ -283,8 +273,8 @@ dhcp6_reply_event_handler (vl_api_dhcp6_reply_event_t * mp)
 
       u8 address_already_present = 0;
       /* *INDENT-OFF* */
-      pool_foreach (address_info, rm->address_pool,
-      ({
+      pool_foreach (address_info, rm->address_pool)
+       {
         if (address_info->sw_if_index != sw_if_index)
           ;
         else if (!ip6_addresses_equal (&address_info->address, address))
@@ -294,7 +284,7 @@ dhcp6_reply_event_handler (vl_api_dhcp6_reply_event_t * mp)
             address_already_present = 1;
             goto address_pool_foreach_out;
           }
-      }));
+      }
       /* *INDENT-ON* */
     address_pool_foreach_out:
 
@@ -356,15 +346,15 @@ create_address_list (u32 sw_if_index)
   address_info_t *address_info, *address_list = 0;;
 
   /* *INDENT-OFF* */
-  pool_foreach (address_info, rm->address_pool,
-  ({
+  pool_foreach (address_info, rm->address_pool)
+   {
     if (address_info->sw_if_index == sw_if_index)
       {
         u32 pos = vec_len (address_list);
         vec_validate (address_list, pos);
         clib_memcpy (&address_list[pos], address_info, sizeof (*address_info));
       }
-  }));
+  }
   /* *INDENT-ON* */
 
   return address_list;
@@ -405,8 +395,8 @@ dhcp6_client_cp_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
        {
          due_time = current_time + 1e9;
           /* *INDENT-OFF* */
-          pool_foreach (address_info, rm->address_pool,
-          ({
+          pool_foreach (address_info, rm->address_pool)
+           {
             if (address_info->due_time > current_time)
               {
                 if (address_info->due_time < due_time)
@@ -422,7 +412,7 @@ dhcp6_client_cp_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
                     clib_warning ("Failed to delete interface address");
                 pool_put (rm->address_pool, address_info);
                 /* make sure ip6 stays enabled */
-                ip6_enable (sw_if_index);
+                ip6_link_enable (sw_if_index, NULL);
                 client_state = &rm->client_state_by_sw_if_index[sw_if_index];
                 if (--client_state->address_count == 0)
                   {
@@ -433,7 +423,7 @@ dhcp6_client_cp_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
                                                     0, 1);
                   }
               }
-          }));
+          }
           /* *INDENT-ON* */
          for (i = 0; i < vec_len (rm->client_state_by_sw_if_index); i++)
            {
@@ -536,15 +526,15 @@ dhcp6_addresses_show_command_function (vlib_main_t * vm,
   f64 current_time = vlib_time_now (vm);
 
   /* *INDENT-OFF* */
-  pool_foreach (address_info, dm->address_pool,
-  ({
+  pool_foreach (address_info, dm->address_pool)
+   {
     vlib_cli_output (vm, "address: %U, "
                      "preferred lifetime: %u, valid lifetime: %u "
                      "(%f remaining)",
                      format_ip6_address, &address_info->address,
                      address_info->preferred_lt, address_info->valid_lt,
                      address_info->due_time - current_time);
-  }));
+  }
   /* *INDENT-ON* */
 
   return error;
@@ -567,8 +557,8 @@ dhcp6_clients_show_command_function (vlib_main_t * vm,
   clib_error_t *error = 0;
   client_state_t *cs;
   f64 current_time = vlib_time_now (vm);
-  char buf1[256];
-  char buf2[256];
+  u8 *buf1 = 0;
+  u8 *buf2 = 0;
   const char *rebinding;
   u32 i;
 
@@ -577,26 +567,28 @@ dhcp6_clients_show_command_function (vlib_main_t * vm,
       cs = &rm->client_state_by_sw_if_index[i];
       if (cs->enabled)
        {
+         vec_reset_length (buf1);
+         vec_reset_length (buf2);
          if (cs->T1_due_time != DBL_MAX && cs->T1_due_time > current_time)
            {
-             sprintf (buf1, "%u remaining",
-                      (u32) round (cs->T1_due_time - current_time));
+             buf1 = format (buf1, "%u remaining",
+                            (u32) round (cs->T1_due_time - current_time));
            }
          else
-           sprintf (buf1, "timeout");
+           buf1 = format (buf1, "timeout");
          if (cs->T2_due_time != DBL_MAX && cs->T2_due_time > current_time)
-           sprintf (buf2, "%u remaining",
-                    (u32) round (cs->T2_due_time - current_time));
+           buf2 = format (buf2, "%u remaining",
+                          (u32) round (cs->T2_due_time - current_time));
          else
-           sprintf (buf2, "timeout");
+           buf2 = format (buf2, "timeout");
          if (cs->rebinding)
            rebinding = ", REBINDING";
          else
            rebinding = "";
          if (cs->T1)
            vlib_cli_output (vm,
-                            "sw_if_index: %u, T1: %u (%s), "
-                            "T2: %u (%s), server index: %d%s", i,
+                            "sw_if_index: %u, T1: %u (%v), "
+                            "T2: %u (%v), server index: %d%s", i,
                             cs->T1, buf1, cs->T2, buf2,
                             cs->server_index, rebinding);
          else
@@ -604,6 +596,9 @@ dhcp6_clients_show_command_function (vlib_main_t * vm,
        }
     }
 
+  vec_free (buf1);
+  vec_free (buf2);
+
   return error;
 }
 
@@ -650,7 +645,7 @@ dhcp6_client_enable_disable (u32 sw_if_index, u8 enable)
          dhcp6_clients_enable_disable (1);
        }
 
-      ip6_enable (sw_if_index);
+      ip6_link_enable (sw_if_index, NULL);
       send_client_message_start_stop (sw_if_index, ~0, DHCPV6_MSG_SOLICIT,
                                      0, 1);
     }
@@ -666,8 +661,8 @@ dhcp6_client_enable_disable (u32 sw_if_index, u8 enable)
        }
 
       /* *INDENT-OFF* */
-      pool_foreach (address_info, rm->address_pool,
-      ({
+      pool_foreach (address_info, rm->address_pool)
+       {
         if (address_info->sw_if_index == sw_if_index)
           {
             ASSERT (sw_if_index < vec_len (rm->client_state_by_sw_if_index) &&
@@ -685,7 +680,7 @@ dhcp6_client_enable_disable (u32 sw_if_index, u8 enable)
                 clib_warning ("Failed to delete interface address");
             pool_put (rm->address_pool, address_info);
           }
-      }));
+      }
       /* *INDENT-ON* */
     }