static void
ssh_eap_resend_timeout_cb(void *ctx)
{
  unsigned long max_retransmit;
  SshEap eap = (void*)ctx;

  SSH_ASSERT(eap != NULL);
  SSH_ASSERT(eap->retransmit_timer_active == 1);
  SSH_ASSERT(eap->prev_pkt != NULL);

  SSH_DEBUG(SSH_D_LOWOK,("resend timeout"));

  eap->retransmit_timer_active = 0;
  eap->num_retransmit++;

  max_retransmit = ssh_eap_config_get_ulong(eap->params,
                                            SSH_EAP_PARAM_MAX_RETRANSMIT);

  if (eap->is_authenticator == 1)
    {
      if ((unsigned long)eap->num_retransmit > max_retransmit
          && eap->num_retransmit >= 0)
        {
          ssh_eap_timeout(eap);
          return;
        }

      ssh_eap_set_resend_timeout(eap);
    }

  ssh_eap_send_packet(eap, eap->prev_pkt);
}
Example #2
0
/*-------------------------------------------------------------------------
  ssh_driver_transfer_data()

  Copies received network data to a given upper layer supplied NDIS packet.
  
  Arguments:
  pkt - NDIS packet for data  
  bytes_transferred - how many bytes has been written into the packet
  miniport_context - virtual NIC object
  receive_context - ???
  byte_offset - where to start copy operation
  bytes_to_transfer -   how may bytes to copy

  Returns:
  NDIS_STATUS_FAILURE - always
  
  Notes:
  This function is not supported because we always indicate complete 
  NDIS packets to the upper layer. So upper layer should never call this 
  function but we anyway return the FAILURE status code to upper layer.

  Default IRQL: DISPATCH_LEVEL
  -------------------------------------------------------------------------*/
static NDIS_STATUS
ssh_driver_transfer_data(PNDIS_PACKET pkt,
                         PUINT bytes_transferred,
                         NDIS_HANDLE miniport_context,
                         NDIS_HANDLE receive_context,
                         UINT byte_offset,
                         UINT bytes_to_transfer)
{
  SshNdisIMAdapter adapter = (SshNdisIMAdapter)miniport_context;

  SSH_ASSERT(SSH_GET_IRQL() <= SSH_DISPATCH_LEVEL);
  SSH_ASSERT(miniport_context != NULL);
  SSH_ASSERT(receive_context != NULL);
  SSH_ASSERT(pkt != NULL);
  SSH_ASSERT(bytes_transferred != NULL);

  *bytes_transferred = 0;

  SSH_DEBUG(SSH_D_ERROR, 
            ("Adapter %@: Unexpected MiniportTransferData() call.",
             ssh_adapter_id_st_render, adapter));

  NDIS_SET_PACKET_STATUS(pkt, NDIS_STATUS_FAILURE);

  return (NDIS_STATUS_FAILURE);
}
Example #3
0
void ssh_interceptor_iface_uninit(SshInterceptor interceptor)
{
  /* Clear interface table and release net_device references. */
  ssh_interceptor_clear_ifaces(interceptor);

  if (interceptor->nf->iface_notifiers_installed == FALSE)
    return;

  SSH_ASSERT(in_softirq());
  local_bh_enable();
  SSH_ASSERT(!in_softirq());

  /* Unregister notifier callback */
  unregister_netdevice_notifier(&interceptor->nf->notifier_netdev);
  unregister_inetaddr_notifier(&interceptor->nf->notifier_inetaddr);
#ifdef SSH_LINUX_INTERCEPTOR_IPV6
  unregister_inet6addr_notifier(&interceptor->nf->notifier_inet6addr);
#endif /* SSH_LINUX_INTERCEPTOR_IPV6 */

  local_bh_disable();

  /* Due to lack of proper locking in linux kernel notifier code, 
     the unregister_*_notifier functions might leave the notifier 
     blocks out of sync, resulting in that the kernel may call an
     unregistered notifier function.

     Sleep for a while to decrease the possibility of the bug causing
     trouble (crash during module unloading). */
  mdelay(500);
  
  interceptor->nf->iface_notifiers_installed = FALSE;
}
/* ssh_virtual_adapter_deregister()
 *
 *
 *
 */
void
ssh_virtual_adapter_deregister(SshVirtualAdapter va)
{
  SshInterceptor interceptor = va->interceptor;
  Boolean was_connected = FALSE;

  SSH_DEBUG(SSH_D_HIGHSTART, ("ssh_virtual_adapter_deregister(0x%p)", va));

  ssh_kernel_mutex_lock(&va->connect_lock);
  was_connected = va->va_connected;
  va->va_connect_aborted = TRUE;
  ssh_kernel_mutex_unlock(&va->connect_lock);

  SSH_ASSERT(va->interceptor != NULL);
  SSH_ASSERT(va != NULL);
  SSH_ASSERT(va->adapter != NULL);

  if (was_connected)
    {
      SSH_ASSERT(va->vnic_disable_cb != NULL_FNPTR);
      SSH_ASSERT(va->vnic_cb_context != NULL);
      
      /* disable adapter - this 'unplugs the cable' */
      (*va->vnic_disable_cb)(va->vnic_cb_context);

      /* Disconnect from underlying virtual NIC */
      ssh_virtual_adapter_disconnect(va);
    }

  /* Decrement the count of virtual adapters */
  InterlockedDecrement(&interceptor->va_interface_cnt);

  /* release the virtual adapter. */
  ssh_virtual_adapter_release(va);
}
Example #5
0
SshIoctlRegHandle
ssh_interceptor_iodevice_register_ioctl(SshInterceptorIoDevice iodevice,
                                        SshUInt32 ioctl_code,
                                        SshIoctlHandler ioctl_handler,
                                        SshIoctlCancelFunction cancel_fn,
                                        void *context)
{
  SshIoDeviceIoctlHandler handler;
  
  SSH_ASSERT(iodevice != NULL);
  SSH_ASSERT(ioctl_code != 0);
  SSH_ASSERT(ioctl_handler != NULL_FNPTR);

  handler = ssh_calloc(1, sizeof(*handler));
  if (handler == NULL)
    {
      SSH_DEBUG(SSH_D_FAIL, 
                ("Failed to register handler for IOCTL code 0x%08x", 
                ioctl_code));
      return NULL;
    }

  handler->ioctl_code = ioctl_code;
  handler->handle = handler;
  handler->ioctl_handler = ioctl_handler;
  handler->cancel_fn = cancel_fn;
  handler->context = context;

  NdisAcquireSpinLock(&iodevice->ioctl_handler_list_lock);
  InsertTailList(&iodevice->ioctl_handler_list, &handler->link);
  NdisReleaseSpinLock(&iodevice->ioctl_handler_list_lock);

  return handler->handle;
}
Example #6
0
/* Internal mapping from ifnum to net_device. 
   This function will assert that 'ifnum' is a valid 
   SshInterceptorIfnum and that the corresponding net_device
   exists in the interface hashtable. This function will dev_hold()
   the net_device. The caller of this function must release it by 
   calling ssh_interceptor_release_netdev(). If `context_return' is
   not NULL then this sets it to point to the interface context. */
inline struct net_device *
ssh_interceptor_ifnum_to_netdev_ctx(SshInterceptor interceptor,
				    SshUInt32 ifnum,
				    void **context_return)
{
  SshInterceptorInternalInterface iface;
  struct net_device *dev = NULL;

  SSH_LINUX_ASSERT_VALID_IFNUM(ifnum);

  read_lock(&interceptor->nf->if_table_lock);
  for (iface = interceptor->nf->if_hash[ifnum % SSH_LINUX_IFACE_HASH_SIZE];
       iface && iface->ifindex != ifnum;
       iface = iface->next)
    ;
  if (iface)
    {
      SSH_ASSERT(iface->generation == interceptor->nf->if_generation);
      dev = iface->dev;
      SSH_ASSERT(dev != NULL);
      dev_hold(dev);
      if (context_return != NULL)
	*context_return = iface->context;
    }
  read_unlock(&interceptor->nf->if_table_lock);
  
  return dev;
}
Example #7
0
static void ikev2_reply_cb_get_address_pair(SshIkev2Error error_code,
					    SshIkev2Server local_server,
					    SshIpAddr remote_ip,
					    void *context)
{
  SshIkev2Packet packet = context;
  
  packet->operation = NULL;
  SSH_FSM_CONTINUE_AFTER_CALLBACK(packet->thread);

  if (error_code != SSH_IKEV2_ERROR_OK)
    {
      SSH_IKEV2_DEBUG(SSH_D_FAIL, ("Error: Get address pair failed: %d", 
				   error_code));
      ikev2_error(packet, error_code);
      return;
    }
  SSH_ASSERT(SSH_IP_DEFINED(remote_ip));
  SSH_ASSERT(local_server != NULL);

  SSH_DEBUG(SSH_D_LOWOK, 
	    ("Address pair returned from policy local=%@, remote=%@",
	     ssh_ipaddr_render, local_server->ip_address,
	     ssh_ipaddr_render, remote_ip));

  packet->remote_ip[0] = *remote_ip;
  packet->remote_port = packet->use_natt ? 
    local_server->nat_t_remote_port : local_server->normal_remote_port;
  packet->server = local_server;

}
/* ssh_virtual_adapter_connect_retry_timeout_cb()
 *
 * This function gets never invoked on Win9x platforms
 */
static void
ssh_virtual_adapter_connect_retry_timeout_cb(SshVirtualAdapter va)
{
  Boolean aborted;
  SSH_DEBUG(SSH_D_MIDSTART,
	    ("ssh_virtual_adapter_connect_retry_timeout_cb()"));

  SSH_ASSERT(va != NULL);
  SSH_ASSERT(va->interceptor != NULL);

  ssh_kernel_mutex_lock(&va->connect_lock);
  SSH_ASSERT(va->va_connected == 0);
  aborted = va->va_connect_aborted;
  ssh_kernel_mutex_unlock(&va->connect_lock);

  if (aborted)
    {
      SSH_DEBUG(SSH_D_MIDSTART,
                ("Virtual adapter connect aborted."));

      ssh_virtual_adapter_release(va);
    }
  else
    {
      /* force execution in passive level */
      ssh_ndis_wrkqueue_queue_item(va->interceptor->work_queue,
                                   ssh_virtual_adapter_connect, va);
    }
}
Example #9
0
size_t ssh_buffer_len(const SshBuffer *buffer)
{
  SSH_ASSERT(buffer);
  SSH_ASSERT(buffer->offset <= buffer->end);

  return buffer->end - buffer->offset;
}
/* Pullup information from a packetcontext which has been
   sent to the fragentry fe. */
static void
ssh_fastpath_fragmagic_sent(SshFastpath fastpath,
                          SshFastpathFragEntry fe,
                          SshEnginePacketContext pc)
{
  const unsigned char *ucp;
  SshUInt32 fragoff, next_off;

  ssh_fastpath_fragmagic_pullup(fastpath,fe,pc);

  if (pc->pp->flags & SSH_ENGINE_P_FIRSTFRAG)
    {
      /* Indicate that we have received the first fragment, and save
         the flow id. The HAVE_LAST flag will be set in
         ssh_fastpath_fragmagic_enqueue. */
      fe->flags |= SSH_ENGINE_FRAG_SENT_FIRST;
    }

  if (pc->pp->flags & SSH_ENGINE_P_LASTFRAG)
    {
      /* If SSH_ENGINE_P_LASTFRAG is set then ssh_fastpath_context_pullup()
         must have initialized frag_packet_size. */
      fe->packet_size = pc->frag_packet_size;
      fe->flags |= SSH_ENGINE_FRAG_SENT_LAST;
    }

#if defined (WITH_IPV6)
  if (pc->pp->protocol == SSH_PROTOCOL_IP6)
    fragoff = pc->fragment_offset;
  else
#endif /* WITH_IPV6 */
    {
#ifndef SSH_IPSEC_IP_ONLY_INTERCEPTOR
      SSH_ASSERT(pc->protocol_offset == 0);
#endif /* not SSH_IPSEC_IP_ONLY_INTERCEPTOR */

      ucp = ssh_interceptor_packet_pullup_read(pc->pp, SSH_IPH4_HDRLEN);
      if (!ucp)
        {
	  pc->pp = NULL;
          SSH_DEBUG(SSH_D_FAIL, 
		    ("ssh_interceptor_packet_pullup_read failed"));
          return;
        }

      fragoff = 8 * (SSH_IPH4_FRAGOFF(ucp) & SSH_IPH4_FRAGOFF_OFFMASK);
    }

  next_off = fragoff + (SshUInt32) (pc->packet_len - pc->hdrlen);
  /* This should be guaranteed by sanity checks. */

  SSH_ASSERT(next_off <= 0xFFFF);
  fe->next_offset = (SshUInt16) next_off;

  SSH_DEBUG(SSH_D_NICETOKNOW,
            ("sending fragment offset %u length %u",
             (unsigned int) fragoff,
	     pc->packet_len - pc->hdrlen));
}
const char *
ssh_directory_file_name(SshDirectoryHandle directory)
{
  SSH_ASSERT(directory != NULL);
  SSH_ASSERT(directory->dirent != NULL);

  return directory->dirent->d_name;
}
Example #12
0
SshPmP1
ssh_pm_lookup_p1(SshPm pm, SshPmRule rule, SshPmTunnel tunnel,
		 SshUInt32 peer_handle, SshIpAddr src, SshIpAddr dst,
		 Boolean require_completed)
{
  SshPmLookupP1CtxStruct ctx;
  SshPmP1 p1;
  SshUInt32 hash;

  /* Initialize a search context. */
  memset(&ctx, 0, sizeof(ctx));
  ctx.tunnel = tunnel;
  ctx.rule = rule;
  ctx.peer = ssh_pm_peer_by_handle(pm, peer_handle);
  ctx.pm = pm;
  ctx.require_completed = require_completed;

  /* Use IP addresses from peer if not explicitly specified and peer exists. */
  ctx.src = src;
  if (ctx.src == NULL && ctx.peer != NULL)
    ctx.src = ctx.peer->local_ip;
  ctx.dst = dst;
  if (ctx.dst == NULL && ctx.peer != NULL)
    ctx.dst = ctx.peer->remote_ip;

  /* Peer IP must be defined either explicitly or by peer. Fail lookup if
     it is not defined. */
  if (ctx.dst == NULL)
    {
      SSH_DEBUG(SSH_D_FAIL, ("Missing dst IP address"));
      return NULL;
    }

  SSH_ASSERT(rule != NULL);
  SSH_ASSERT(tunnel != NULL);

  if (!require_completed)
    {
      /* Lookup active Phase-1 initiator and responder negotiations. */
      for (p1 = pm->active_p1_negotiations; p1; p1 = p1->n->next)
	{
	  if (ssh_pm_lookup_p1_check_p1(&ctx, p1))
	    return p1;
	}
    }

  /* Check IKE SA hash table. */
  hash = SSH_PM_IKE_PEER_HASH(ctx.dst);
  for (p1 = pm->ike_sa_hash[hash]; p1; p1 = p1->hash_next)
    {
      if (ssh_pm_lookup_p1_check_p1(&ctx, p1))
	return p1;
    }

  /* No match found. */
  return NULL;
}
Example #13
0
/* Return a list of ciphers, including native names and aliases. The
   caller must free the returned string with ssh_free. Can return NULL
   on memory allocation failure (if no ciphers are supported, then
   just an empty string is returned). */
char *ssh_cipher_alias_get_supported(void)
{
  int i;
  unsigned char *list, *tmp;
  size_t offset, list_len;

  list = ssh_ustr(ssh_cipher_get_supported());

  if (!list)
    return NULL;

  tmp = ssh_strdup(list);

  if (!tmp)
    return NULL;

  list = tmp;
  offset = ssh_ustrlen(list);
  list_len = offset + 1;

  for (i = 0; ssh_cipher_aliases[i].name != NULL; i++)
    {
      size_t newsize;

      /* It is possible that our alias list has ciphers which are not
         supported by the crypto core */
      if (!ssh_cipher_supported(ssh_cipher_aliases[i].real_name))
        continue;

      newsize = offset + 1 + !!offset + strlen(ssh_cipher_aliases[i].name);

      if (list_len < newsize)
        {
          newsize *= 2;

          if ((tmp = ssh_realloc(list, list_len, newsize)) == NULL)
            {
              ssh_free(list);
              return NULL;
            }

          list = tmp;
          list_len = newsize;
        }

      SSH_ASSERT(list_len > 0);
      SSH_ASSERT(list != NULL);

      offset += ssh_snprintf(list + offset, list_len - offset, "%s%s",
                             offset ? "," : "",
                             ssh_cipher_aliases[i].name);

    }

  return (char *) list;
}
Example #14
0
void __fastcall
ssh_interceptor_iodevice_close_device(SshInterceptorIoDevice io_dev)
{
  SSH_DEBUG(SSH_D_HIGHSTART, ("Closing stream device..."));

  SSH_ASSERT(io_dev != NULL);
  SSH_ASSERT(ssh_interceptor_iodevice_is_open(io_dev) == FALSE);

  if (io_dev->handle)  
    DeactivateDevice(io_dev->handle);
}
Example #15
0
/* Attach a file pointer with a read callback. */
Boolean ssh_file_buffer_attach_with_read_callback(SshFileBuffer buf,
                                      SshFileBufferReadCallback read_callback,
                                      void *read_context)
{
  SSH_ASSERT(buf != NULL);
  SSH_ASSERT(read_callback != NULL_FNPTR);
  ssh_file_buffer_detach(buf);
  buf->read_callback = read_callback;
  buf->read_context = read_context;
  return TRUE;
}
Example #16
0
void ssh_buffer_get(SshBuffer *buffer, unsigned char *buf, size_t len)
{
  SSH_ASSERT(buffer);
  SSH_ASSERT(len >= 0);

  if (len > buffer->end - buffer->offset)
    ssh_fatal("buffer_get trying to get more bytes than in buffer");
  if (len > 0)
    memcpy(buf, buffer->buf + buffer->offset, len);
  buffer->offset += len;
}
Example #17
0
/*-------------------------------------------------------------------------
  ssh_driver_check_for_hang()
  
  Reports the operational state of virtual NIC.
 
  Arguments:
        miniport_context - virtual NIC object
  
  Returns:
        FALSE - always (virtual NIC is operating normally)
  
  Notes:

  Default IRQL: DISPATCH_LEVEL
  --------------------------------------------------------------------------*/
static BOOLEAN
ssh_driver_check_for_hang(NDIS_HANDLE miniport_context)
{

  SSH_DEBUG(SSH_D_HIGHSTART, ("MiniportCheckForHang: miniport context 0x%p",
                              miniport_context));

  SSH_ASSERT(SSH_GET_IRQL() <= SSH_DISPATCH_LEVEL);
  SSH_ASSERT(miniport_context != NULL);

  return (FALSE);
}
Example #18
0
/*-------------------------------------------------------------------------
  ssh_event_destroy()
  
  Destructor for event object.

  Arguments:
  event - SshEvent object

  Returns:
  Notes:
  ------------------------------------------------------------------------*/
void
ssh_event_destroy(SshEvent event_obj)
{
  SSH_ASSERT(event_obj != NULL);
  SSH_ASSERT(event_obj->os_event != NULL);

#ifdef _WIN32_WCE
  CloseHandle(event_obj->os_event);
#endif /* _WIN32_WCE */

  ssh_free(event_obj);
}
static Boolean
ssh_wan_alloc_buffer(SshInterceptor interceptor,
                     SshUInt32 length,
                     SshNetDataBuffer *buf_return,
                     unsigned char **buf_addr_return)
{
  SshCpuContext cpu_ctx;
  SshNetDataBuffer buffer;
  unsigned char *buf_addr;
  SshUInt32 buf_size;

  SSH_ASSERT(interceptor != NULL);
  SSH_ASSERT(buf_return != NULL);
  SSH_ASSERT(buf_addr_return != NULL);

  ssh_kernel_critical_section_start(&interceptor->packet_pool_cs);
  cpu_ctx = &interceptor->cpu_ctx[ssh_kernel_get_cpu()];
  buffer = ssh_net_buffer_alloc(interceptor, &cpu_ctx->packet_pool);
  ssh_kernel_critical_section_end(&interceptor->packet_pool_cs);  

  if (buffer == NULL)
    {
      SSH_DEBUG(SSH_D_FAIL, ("Out of buffer pool!"));
      return FALSE;
    }

  SSH_RESET_BUFFER(buffer, 0);  

  if (buffer->total_size < length)
    {
      ssh_wan_free_buffer(interceptor, buffer);
      SSH_DEBUG(SSH_D_FAIL, 
                ("Could not allocate contiguous buffer (%u bytes "
                 "requested)", length));
      return FALSE;
    }

  NdisAdjustBufferLength(buffer->nb, length);
  buffer->data_len = length;

  if (!ssh_query_data_block(buffer->nb, &buf_addr, &buf_size))
    {
      ssh_wan_free_buffer(interceptor, buffer);
      SSH_DEBUG(SSH_D_FAIL,
                ("Failed to query buffer address!"));
      return FALSE;
    }

  *buf_return = buffer;
  *buf_addr_return = buf_addr;

  return TRUE;
}
Example #20
0
/*-------------------------------------------------------------------------
  Sets the given event to signalled state.
  ------------------------------------------------------------------------*/
void __fastcall
ssh_event_signal(SshEvent event_obj)
{
  SSH_ASSERT(event_obj != NULL);
  SSH_ASSERT(event_obj->os_event != NULL);

#ifdef _WIN32_WCE
  SetEvent(event_obj->os_event);
#else
  KeSetEvent(event_obj->os_event, IO_NO_INCREMENT, FALSE);
#endif /* _WIN32_WCE */
}
Example #21
0
/*------------------------------------------------------------------------
  Resets the given event.
  ------------------------------------------------------------------------*/
void __fastcall
ssh_event_reset(SshEvent event_obj)
{
  SSH_ASSERT(event_obj != NULL);
  SSH_ASSERT(event_obj->os_event != NULL);

#ifdef _WIN32_WCE
  ResetEvent(event_obj->os_event);
#else
  KeClearEvent(event_obj->os_event);
#endif /* _WIN32_WCE */
}
static void
ssh_virtual_adapter_disconnect(SshVirtualAdapter va)
{
  SSH_ASSERT(va != NULL);
  SSH_ASSERT(va->vnic_disconnect_cb != NULL_FNPTR);
  
  /* disconnect from virtual NIC */
  (*va->vnic_disconnect_cb)(va->vnic_cb_context);
  
  /* decrement the reference count of vnic device */
  ssh_virtual_adapter_device_release(va);
}
Example #23
0
/*-------------------------------------------------------------------------
  ssh_driver_reset()
  
  Resets the software status of the driver. 

  Arguments:
  addressing_reset - returns TRUE or FALSE depending on the status
                     of the call.
  miniport_adapter_context NDIS_HANDLE to the miniport driver.

  Returns:
  NDIS_STATUS_SUCCESS - reset succeeded
  NDIS_STATUS_PENDING - the call is left in asynchronous operation
  NDIS_STATUS_FAILURE - otherwise

  Notes:
  
  Default IRQL: <= DISPATCH_LEVEL
  -------------------------------------------------------------------------*/
static NDIS_STATUS
ssh_driver_reset(PBOOLEAN addressing_reset,
		 NDIS_HANDLE miniport_adapter_context)
{
  SSH_ASSERT(addressing_reset != NULL);
  SSH_ASSERT(miniport_adapter_context != NULL);

  if (addressing_reset)
    *addressing_reset = FALSE;

  return NDIS_STATUS_SUCCESS;
}
Example #24
0
void
ikev2_fb_phase_ii_clear_pm_data(SshIkePMPhaseII pm_info,
				SshIkev2FbNegotiation neg)
{
  SSH_ASSERT(pm_info != NULL);
  SSH_ASSERT(neg != NULL);

  SSH_DEBUG(SSH_D_LOWOK, ("Clearing FB negotiation %p from p2_info %p",
			  neg, pm_info));  

  ikev2_fallback_negotiation_free(neg->fb, neg);
  pm_info->policy_manager_data = NULL;
}
Example #25
0
void
ikev2_fb_phase_ii_set_pm_data(SshIkePMPhaseII pm_info,
			      SshIkev2FbNegotiation neg)
{
  SSH_ASSERT(pm_info != NULL);
  SSH_ASSERT(neg != NULL);

  IKEV2_FB_NEG_TAKE_REF(neg);
  pm_info->policy_manager_data = neg;

  SSH_DEBUG(SSH_D_LOWOK, ("Setting FB negotiation %p to p2_info %p",
			  neg, pm_info));
}
/* ssh_virtual_adapter_add_ref()
 *
 * Increase the reference count of a virtual adapter.
 */
void
ssh_virtual_adapter_add_ref(SshVirtualAdapter va)
{
  LONG new_value;

  SSH_DEBUG(SSH_D_LOWSTART, ("ssh_virtual_adapter_add_ref(0x%p)", va));

  SSH_ASSERT(va != NULL);
  SSH_ASSERT(va->interceptor != NULL);

  new_value = InterlockedIncrement(&va->ref_count);
  SSH_ASSERT(new_value > 1);
}
Example #27
0
/*-------------------------------------------------------------------------
  ssh_driver_initialize()
  
  Sets up virtual NIC so that it is ready for network I/O operations.

  Arguments:
  open_error_status - additional error information
  selected_medium_index - index to specified media type in medium array 
  medium_array - media array
  medium_array_size - length of media array
  miniport_handle - handle that identifies virtual NIC
  configuration_context -  handle to registry configuration of virtual NIC

  Returns:
  NDIS_STATUS_SUCCESS - initialization succeeded
  NDIS_STATUS_FAILURE - otherwise

  Notes:
  This handler is called after successful binding creation with 
  underlaying NIC.

  Default IRQL: PASSIVE_LEVEL
  -------------------------------------------------------------------------*/
static NDIS_STATUS
ssh_driver_initialize(PNDIS_STATUS open_error_status,
                      PUINT selected_medium_index,
                      PNDIS_MEDIUM medium_array,
                      UINT medium_array_size,
                      NDIS_HANDLE miniport_handle,
                      NDIS_HANDLE configuration_context)
{
  NDIS_STATUS status;
  SshNdisIMAdapter adapter;

  SSH_ASSERT(SSH_GET_IRQL() < SSH_DISPATCH_LEVEL);

  /* Retrieve the adapter context and then initialize our adapter */
  adapter = (SshNdisIMAdapter) NdisIMGetDeviceContext(miniport_handle);

  SSH_ASSERT(adapter != NULL);

  SSH_DEBUG(SSH_D_HIGHSTART, 
            ("Adapter %@ MiniportInitialize", 
             ssh_adapter_id_st_render, adapter));

  status = ssh_adapter_initialize(adapter,
                                  miniport_handle,
                                  configuration_context,
                                  medium_array_size,
                                  medium_array,
                                  selected_medium_index);

  if (status == NDIS_STATUS_SUCCESS)
    SSH_DEBUG(SSH_D_HIGHOK,
              ("Adapter %@ MiniportInitialize: status=%@, "
               "selected medium index %u",
               ssh_adapter_id_st_render, adapter,
               ssh_ndis_status_render, &status, 
               *selected_medium_index));
  else if (status == NDIS_STATUS_OPEN_FAILED)
    SSH_DEBUG(SSH_D_FAIL,
              ("Adapter %@ MiniportInitialize: status=%@, "
               "open error status %@",
               ssh_adapter_id_st_render, adapter,
               ssh_ndis_status_render, &status, 
               ssh_ndis_status_render, open_error_status));
  else
    SSH_DEBUG(SSH_D_FAIL,
              ("Adapter %@ MiniportInitialize: status=%@", 
               ssh_adapter_id_st_render, adapter,
               ssh_ndis_status_render, &status));

  return (status);
}
static void
ssh_wan_free_buffer(SshInterceptor interceptor,
                    SshNetDataBuffer buffer)
{
  SshCpuContext cpu_ctx;

  SSH_ASSERT(interceptor != NULL);
  SSH_ASSERT(buffer != NULL);

  ssh_kernel_critical_section_start(&interceptor->packet_pool_cs);
  cpu_ctx = &interceptor->cpu_ctx[ssh_kernel_get_cpu()];
  ssh_net_buffer_free(interceptor, &cpu_ctx->packet_pool, buffer);
  ssh_kernel_critical_section_end(&interceptor->packet_pool_cs);  
}
Example #29
0
static Boolean prf_xor(unsigned char *dest, int dest_len,
		       SshMac mac, int mac_len, unsigned char *seed,
		       int seed_len)
{
  unsigned char A[20];
  unsigned char digest[20];
  int i;

  SSH_ASSERT(mac_len <= 20);

  /* Calculate A(1). (Notation from RFC 2246.) */
  ssh_mac_reset(mac);
  ssh_mac_update(mac, seed, seed_len);
  if (ssh_mac_final(mac, A) != SSH_CRYPTO_OK)
    return FALSE;
  
  while (1)
    {
      SSH_ASSERT(dest_len > 0);
      
      ssh_mac_reset(mac);
      ssh_mac_update(mac, A, mac_len);
      ssh_mac_update(mac, seed, seed_len);
      if (ssh_mac_final(mac, digest) != SSH_CRYPTO_OK)
	return FALSE;

      for (i = 0; i < mac_len; i++)
        {
          *dest ^= digest[i];
          dest++;
          dest_len--;
          if (dest_len == 0)
            {
              memset(A, 0, 20); 
	      memset(digest, 0, 20);
              return TRUE;
            }
        }
      
      /* Compute A(i+1) (see RFC 2246. `i' is induction variable, not
         the loop variable above. */
      ssh_mac_reset(mac);
      ssh_mac_update(mac, A, mac_len);
      if (ssh_mac_final(mac, A) != SSH_CRYPTO_OK)
	return FALSE;
      
    }

  return TRUE;
}
Example #30
0
static void
kenny_destructor(SshFSM fsm, void *context)
{
#ifdef DEBUG_LIGHT
  char *name = (char *) context;
#endif /* DEBUG_LIGHT */

  SSH_ASSERT(SSH_FSM_IS_THREAD_DONE(&thread1));
  SSH_ASSERT(!SSH_FSM_IS_THREAD_RUNNING(&thread1));
  SSH_ASSERT(!SSH_FSM_THREAD_EXISTS(&thread1));

  SSH_DEBUG(SSH_D_NICETOKNOW, ("Oh my God, they killed %s!", name));
  rounds++;
}