Exemplo 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;
}
Exemplo n.º 2
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;

}
Boolean
ssh_interceptor_dst_entry_cache_init(SshInterceptor interceptor)
{
  SSH_DEBUG(SSH_D_MIDOK, ("Initialising dst entry cache"));

  /* When the IPM is open, we cache dst entries with usermode engine. */
  interceptor->dst_entry_cache_lock = ssh_kernel_mutex_alloc();
  if (interceptor->dst_entry_cache_lock == NULL)
    return FALSE;

  interceptor->dst_entry_cache_timeout_registered = FALSE;
  memset(interceptor->dst_entry_table, 0x0,
	 sizeof(SshDstEntry) * SSH_DST_ENTRY_TBL_SIZE);

  interceptor->dst_entry_id = 1;
  interceptor->dst_entry_cached_items = 0;

  return TRUE;
}