dhcp: Move to plugin
[vpp.git] / src / plugins / dhcp / dhcp6_ia_na_client_dp.c
similarity index 64%
rename from src/vnet/dhcp/dhcp6_ia_na_client_dp.c
rename to src/plugins/dhcp/dhcp6_ia_na_client_dp.c
index f49017b..6ea822f 100644 (file)
  */
 
 #include <vlib/vlib.h>
-#include <vnet/dhcp/dhcp6_packet.h>
-#include <vnet/dhcp/dhcp_proxy.h>
+#include <dhcp/dhcp6_packet.h>
+#include <dhcp/dhcp_proxy.h>
 #include <vnet/mfib/mfib_table.h>
 #include <vnet/mfib/ip6_mfib.h>
 #include <vnet/fib/fib.h>
 #include <vnet/adj/adj_mcast.h>
 #include <vnet/ip/ip6_neighbor.h>
-#include <vlibapi/api_common.h>
-#include <vlibmemory/api.h>
-#include <vnet/dhcp/dhcp6_ia_na_client_dp.h>
-#include <vnet/dhcp/dhcp6_client_common_dp.h>
+#include <dhcp/dhcp6_ia_na_client_dp.h>
+#include <dhcp/dhcp6_client_common_dp.h>
 #include <vnet/ip/ip_types_api.h>
 
-#include <vnet/vnet_msg_enum.h>
-
-#define vl_typedefs            /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_typedefs
-
-#define vl_endianfun           /* define message structures */
-#include <vnet/vnet_all_api_h.h>
-#undef vl_endianfun
-
-/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
-#define vl_printfun
-#include <vnet/vnet_all_api_h.h>
-#undef vl_printfun
-
-#include <vlibapi/api_helper_macros.h>
-
 dhcp6_ia_na_client_main_t dhcp6_ia_na_client_main;
 dhcp6_ia_na_client_public_main_t dhcp6_ia_na_client_public_main;
 
@@ -430,208 +410,6 @@ dhcp6_send_client_message (vlib_main_t * vm, u32 sw_if_index, u8 stop,
     }
 }
 
-void
-  vl_api_dhcp6_send_client_message_t_handler
-  (vl_api_dhcp6_send_client_message_t * mp)
-{
-  vl_api_dhcp6_send_client_message_reply_t *rmp;
-  dhcp6_send_client_message_params_t params;
-  vlib_main_t *vm = vlib_get_main ();
-  u32 n_addresses;
-  u32 i;
-  int rv = 0;
-
-  VALIDATE_SW_IF_INDEX (mp);
-
-  BAD_SW_IF_INDEX_LABEL;
-  REPLY_MACRO (VL_API_DHCP6_SEND_CLIENT_MESSAGE_REPLY);
-
-  if (rv != 0)
-    return;
-
-  params.sw_if_index = ntohl (mp->sw_if_index);
-  params.server_index = ntohl (mp->server_index);
-  params.irt = ntohl (mp->irt);
-  params.mrt = ntohl (mp->mrt);
-  params.mrc = ntohl (mp->mrc);
-  params.mrd = ntohl (mp->mrd);
-  params.msg_type = ntohl (mp->msg_type);
-  params.T1 = ntohl (mp->T1);
-  params.T2 = ntohl (mp->T2);
-  n_addresses = ntohl (mp->n_addresses);
-  params.addresses = 0;
-  if (n_addresses > 0)
-    vec_validate (params.addresses, n_addresses - 1);
-  for (i = 0; i < n_addresses; i++)
-    {
-      vl_api_dhcp6_address_info_t *ai = &mp->addresses[i];
-      dhcp6_send_client_message_params_address_t *addr = &params.addresses[i];
-      addr->preferred_lt = ntohl (ai->preferred_time);
-      addr->valid_lt = ntohl (ai->valid_time);
-      ip6_address_decode (ai->address, &addr->address);
-    }
-
-  dhcp6_send_client_message (vm, ntohl (mp->sw_if_index), mp->stop, &params);
-}
-
-clib_error_t *
-call_dhcp6_reply_event_callbacks (void *data,
-                                 _vnet_dhcp6_reply_event_function_list_elt_t
-                                 * elt)
-{
-  clib_error_t *error = 0;
-
-  while (elt)
-    {
-      error = elt->fp (data);
-      if (error)
-       return error;
-      elt = elt->next_dhcp6_reply_event_function;
-    }
-
-  return error;
-}
-
-static uword
-dhcp6_reply_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
-                    vlib_frame_t * f)
-{
-  /* These cross the longjmp  boundary (vlib_process_wait_for_event)
-   * and need to be volatile - to prevent them from being optimized into
-   * a register - which could change during suspension */
-
-  while (1)
-    {
-      vlib_process_wait_for_event (vm);
-      uword event_type = DHCP6_DP_REPLY_REPORT;
-      void *event_data = vlib_process_get_event_data (vm, &event_type);
-
-      int i;
-      if (event_type == DHCP6_DP_REPLY_REPORT)
-       {
-         address_report_t *events = event_data;
-         for (i = 0; i < vec_len (events); i++)
-           {
-             u32 event_size =
-               sizeof (vl_api_dhcp6_reply_event_t) +
-               vec_len (events[i].addresses) *
-               sizeof (vl_api_dhcp6_address_info_t);
-             vl_api_dhcp6_reply_event_t *event = clib_mem_alloc (event_size);
-             clib_memset (event, 0, event_size);
-
-             event->sw_if_index = htonl (events[i].body.sw_if_index);
-             event->server_index = htonl (events[i].body.server_index);
-             event->msg_type = events[i].body.msg_type;
-             event->T1 = htonl (events[i].body.T1);
-             event->T2 = htonl (events[i].body.T2);
-             event->inner_status_code =
-               htons (events[i].body.inner_status_code);
-             event->status_code = htons (events[i].body.status_code);
-             event->preference = events[i].body.preference;
-
-             event->n_addresses = htonl (vec_len (events[i].addresses));
-             vl_api_dhcp6_address_info_t *address =
-               (typeof (address)) event->addresses;
-             u32 j;
-             for (j = 0; j < vec_len (events[i].addresses); j++)
-               {
-                 dhcp6_address_info_t *info = &events[i].addresses[j];
-                 ip6_address_encode (&info->address, address->address);
-                 address->valid_time = htonl (info->valid_time);
-                 address->preferred_time = htonl (info->preferred_time);
-                 address++;
-               }
-             vec_free (events[i].addresses);
-
-             dhcp6_ia_na_client_public_main_t *dcpm =
-               &dhcp6_ia_na_client_public_main;
-             call_dhcp6_reply_event_callbacks (event, dcpm->functions);
-
-             vpe_client_registration_t *reg;
-              /* *INDENT-OFF* */
-              pool_foreach(reg, vpe_api_main.dhcp6_reply_events_registrations,
-              ({
-                vl_api_registration_t *vl_reg;
-                vl_reg =
-                  vl_api_client_index_to_registration (reg->client_index);
-                if (vl_reg && vl_api_can_send_msg (vl_reg))
-                  {
-                    vl_api_dhcp6_reply_event_t *msg =
-                      vl_msg_api_alloc (event_size);
-                    clib_memcpy (msg, event, event_size);
-                    msg->_vl_msg_id = htons (VL_API_DHCP6_REPLY_EVENT);
-                    msg->client_index = reg->client_index;
-                    msg->pid = reg->client_pid;
-                    vl_api_send_msg (vl_reg, (u8 *) msg);
-                  }
-              }));
-              /* *INDENT-ON* */
-
-             clib_mem_free (event);
-           }
-       }
-      vlib_process_put_event_data (vm, event_data);
-    }
-
-  return 0;
-}
-
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (dhcp6_reply_process_node) = {
-  .function = dhcp6_reply_process,
-  .type = VLIB_NODE_TYPE_PROCESS,
-  .name = "dhcp6-reply-publisher-process",
-};
-/* *INDENT-ON* */
-
-void
-  vl_api_want_dhcp6_reply_events_t_handler
-  (vl_api_want_dhcp6_reply_events_t * mp)
-{
-  vpe_api_main_t *am = &vpe_api_main;
-  vl_api_want_dhcp6_reply_events_reply_t *rmp;
-  int rv = 0;
-
-  uword *p =
-    hash_get (am->dhcp6_reply_events_registration_hash, mp->client_index);
-  vpe_client_registration_t *rp;
-  if (p)
-    {
-      if (mp->enable_disable)
-       {
-         clib_warning ("pid %d: already enabled...", ntohl (mp->pid));
-         rv = VNET_API_ERROR_INVALID_REGISTRATION;
-         goto reply;
-       }
-      else
-       {
-         rp = pool_elt_at_index (am->dhcp6_reply_events_registrations, p[0]);
-         pool_put (am->dhcp6_reply_events_registrations, rp);
-         hash_unset (am->dhcp6_reply_events_registration_hash,
-                     mp->client_index);
-         if (pool_elts (am->dhcp6_reply_events_registrations) == 0)
-           dhcp6_set_publisher_node (~0, DHCP6_DP_REPORT_MAX);
-         goto reply;
-       }
-    }
-  if (mp->enable_disable == 0)
-    {
-      clib_warning ("pid %d: already disabled...", ntohl (mp->pid));
-      rv = VNET_API_ERROR_INVALID_REGISTRATION;
-      goto reply;
-    }
-  pool_get (am->dhcp6_reply_events_registrations, rp);
-  rp->client_index = mp->client_index;
-  rp->client_pid = ntohl (mp->pid);
-  hash_set (am->dhcp6_reply_events_registration_hash, rp->client_index,
-           rp - am->dhcp6_reply_events_registrations);
-  dhcp6_set_publisher_node (dhcp6_reply_process_node.index,
-                           DHCP6_DP_REPLY_REPORT);
-
-reply:
-  REPLY_MACRO (VL_API_WANT_DHCP6_REPLY_EVENTS_REPLY);
-}
-
 static clib_error_t *
 dhcp6_client_init (vlib_main_t * vm)
 {