Ejemplo n.º 1
0
int
ssh_interceptor_init_kernel_services(void)
{
  /* Interceptor object is always preallocated. */
  SSH_ASSERT(ssh_interceptor_context == NULL);
  memset(&interceptor_struct, 0, sizeof(interceptor_struct));
  ssh_interceptor_context = &interceptor_struct;

#ifdef DEBUG_LIGHT
  spin_lock_init(&ssh_interceptor_context->statistics_lock);
#endif /* DEBUG_LIGHT */

  /* General init */
  ssh_interceptor_context->interceptor_lock = ssh_kernel_mutex_alloc();
  ssh_interceptor_context->packet_lock = ssh_kernel_mutex_alloc();

  if (ssh_interceptor_context->interceptor_lock == NULL
      || ssh_interceptor_context->packet_lock == NULL)
    goto error;

  rwlock_init(&ssh_interceptor_context->if_table_lock);

  /* Init packet data structure */
  if (!ssh_interceptor_packet_freelist_init(ssh_interceptor_context))
    {
      printk(KERN_ERR
             "VPNClient packet processing engine failed to start "
             "(out of memory).\n");
      goto error;
    }

  /* Initialize ipm channel */
  if (!ssh_interceptor_ipm_init(ssh_interceptor_context))
    {
      printk(KERN_ERR 
	     "VPNClient packet processing engine failed to start "
	     "(proc filesystem initialization error)\n");
      goto error1;
    }

  return 0;
  
 error1:
  local_bh_disable();
  ssh_interceptor_packet_freelist_uninit(ssh_interceptor_context);
  local_bh_enable();

 error:
  ssh_kernel_mutex_free(ssh_interceptor_context->interceptor_lock);
  ssh_interceptor_context->interceptor_lock = NULL;

  ssh_kernel_mutex_free(ssh_interceptor_context->packet_lock);
  ssh_interceptor_context->packet_lock = NULL;

  ssh_interceptor_context = NULL;

  return -ENOMEM;
}
Ejemplo n.º 2
0
static void
ssh_interceptor_uninit_kernel_services(void)
{
  /* Remove interface event handlers and free interface table. */
  ssh_interceptor_iface_uninit(ssh_interceptor_context);

  /* Uninitialize ipm channel */
  ssh_interceptor_ipm_uninit(ssh_interceptor_context);

  /* Free locks */
  ssh_kernel_mutex_free(ssh_interceptor_context->interceptor_lock);
  ssh_interceptor_context->interceptor_lock = NULL;
  ssh_kernel_mutex_free(ssh_interceptor_context->packet_lock);
  ssh_interceptor_context->packet_lock = NULL;

  ssh_interceptor_context = NULL;
}
Ejemplo n.º 3
0
SshEngine ssh_engine_start(SshEngineSendProc send,
                           void *machine_context,
                           SshUInt32 flags)
{
    SshEngine engine;

    engine = ssh_calloc(1, sizeof(*engine));
    if (engine == NULL)
    {
        SSH_DEBUG(1, ("allocating the engine object failed"));
        goto fail;
    }

    /* Transform data pointers are already all zero (assumed to equal NULL). */
    /* Fragment magic data initialized to zero. */
    engine->lock = ssh_kernel_mutex_alloc();
    engine->send = send;
    engine->machine_context = machine_context;
    engine->drop_if_no_ipm = (flags & SSH_ENGINE_DROP_IF_NO_IPM) != 0;
    engine->ipm_open = FALSE;
    engine->interceptor = NULL;

    /* Create the interceptor. */
    if (!ssh_interceptor_create(machine_context, &engine->interceptor))
    {
        SSH_DEBUG(1, ("creating the interceptor failed"));
        goto fail;
    }

    /* Open the interceptor. */
    if (!ssh_interceptor_open(engine->interceptor,
                              ssh_engine_packet_callback,
                              ssh_engine_interfaces_callback,
                              ssh_engine_route_change_callback,
                              (void *)engine))
    {
        SSH_DEBUG(1, ("opening the interceptor failed"));
        goto fail;
    }

    SSH_DEBUG(1, ("SSH tester engine started"));
    return engine;

fail:
    if (engine)
    {
        if (engine->interceptor)
            ssh_interceptor_stop(engine->interceptor);
        ssh_kernel_mutex_free(engine->lock);
        ssh_free(engine);
    }
    return NULL;

}
void
ssh_interceptor_dst_entry_cache_uninit(SshInterceptor interceptor)
{
  /* Something failed during initialization. */
  if (interceptor->dst_entry_cache_lock == NULL)
    return;

  SSH_DEBUG(SSH_D_MIDOK, ("Dst entry cache uninit, %lu items in cache",
			  (unsigned long)interceptor->dst_entry_cached_items));

  ssh_interceptor_dst_entry_cache_flush(interceptor);
  ssh_kernel_mutex_uninit(interceptor->dst_entry_cache_lock);
  ssh_kernel_mutex_free(interceptor->dst_entry_cache_lock);
}
Ejemplo n.º 5
0
Boolean ssh_engine_stop(SshEngine engine)
{
    /* Stop the interceptor.  This means that no more new callbacks will
       arrive. */
    if (!ssh_interceptor_stop(engine->interceptor))
        return FALSE;

    /* Close the packet interceptor. */
    ssh_interceptor_close(engine->interceptor);

    /* Free the engine data structures. */
    ssh_kernel_mutex_free(engine->lock);
    memset(engine, 'F', sizeof(*engine));
    ssh_free(engine);
    return TRUE;
}