Ejemplo n.º 1
0
/* Prepare data from inner uIP stack to be sent out to the remote host,
   this is fill the IP and UDP headers of the outer stack part.  */
void
openvpn_process_out (void)
{
  uip_udp_conn = openvpn_conn;	/* Change back to OpenVPN connection. */

  uint8_t stackno = router_find_stack (&uip_udp_conn->ripaddr);
  if (stackno == STACK_OPENVPN)
    {
      uip_len = 0;
      return;
    }

  uip_stack_set_active (stackno);

  /* uip_len is set to the number of data bytes including TCP/UDP/IP header. */
  memmove (uip_buf + OPENVPN_TOTAL_LLH_LEN,
	   uip_buf + BASE_LLH_LEN,
	   uip_len);

  /* Make sure openvpn_process sends the data. */
  uip_sappdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
  uip_slen = uip_len + OPENVPN_HMAC_CRYPT_LEN;

  printf ("ready to send %d bytes.\n", uip_slen);

  openvpn_encrypt ();
  openvpn_hmac_create ();
}
Ejemplo n.º 2
0
void
router_output(void) {
#ifdef IPCHAIR_HAVE_OUTPUT
  ipchair_OUTPUT_chair();
#endif

  uint8_t dest = router_find_stack(&BUF->destipaddr);
  if (dest == 255)
    {
      uip_len = 0;
      return;
    }

  router_output_to(dest);
}
Ejemplo n.º 3
0
void
router_input(uint8_t origin)
{
#ifdef IPCHAIR_HAVE_PREROUTING
  ipchair_PREROUTING_chair();
  if(!uip_len) return;
#endif
  /* uip_len is set to the number of received bytes, including the LLH.
     For RFM12, ZBus, etc.  it's the full 14-byte Ethernet LLH even also. */

  /* Check if packet is addressed to one stack's
     configured host address. */
  uint8_t dest = router_find_stack(NULL);
  if (dest < 255) {
      uip_stack_set_active(dest);
#ifdef IPCHAIR_HAVE_INPUT
      ipchair_INPUT_chair();
      if(!uip_len) return;
#endif
      uip_input ();
  }
#if UIP_CONF_IPV6 && defined(ENC28J60_SUPPORT)
  else if (BUF->destipaddr[0] == HTONS(0xff02))
    {
      /* Packet is addressed to one of the multicast addresses. */
      uip_stack_set_active (STACK_ENC);
      uip_input ();
    }
#endif	/* UIP_CONF_IPV6 */
  else
    {
#ifdef IP_FORWARDING_SUPPORT
      /* Packet not addressed to us, check destination address to where
	 the packet has to be routed. */
      uint8_t dest = router_find_stack(&BUF->destipaddr);
      if (dest == 255)
        {
	  uip_len = 0;
          return; /* Packet was dropped by the router */
        }

      if (origin == dest)
	goto drop;

      if (-- BUF->ttl == 0)
	{
	  /* TODO send ICMP message */
	  printf ("ttl exceeded, should send ICMP message.\n");
	  goto drop;
	}

#ifdef IPCHAIR_HAVE_FORWARD
      ipchair_FORWARD_chair();
      if(!uip_len) return;
#endif

#if !UIP_CONF_IPV6
      /* For IPv4 we must adjust the chksum */
      if(BUF->ipchksum >= HTONS(0xffff - (1 << 8)))
	BUF->ipchksum += HTONS(1 << 8) + 1;

      else
	BUF->ipchksum += HTONS(1 << 8);
#endif

      /* For router_output_to uip_len must be set to the number of
	 bytes to send, excluding the LLH (since it'll generate the needed
	 one itself).  However uip_len is currently set to the number of
	 received bytes, i.e. including the LLH. */
      uip_len -= UIP_LLH_LEN;

      /* TODO check MTU and send suitable ICMP message if needed. */
      router_output_to (dest);

#endif /* IP_FORWARDING_SUPPORT */

      goto drop;
    }

  return;

 drop:
  uip_len = 0;
  return;
}