Beispiel #1
0
void
syslog_flush (void)
{

  /* FIXME: use perhaps router to determine target Stack */
  uip_stack_set_active(STACK_ENC);

  if (syslog_check_cache ())
    return;			/* ARP cache not ready, don't send request
				   here (would flood, wait for poll event). */

  uip_slen = 0;
  uip_appdata = uip_sappdata = uip_buf + UIP_IPUDPH_LEN + UIP_LLH_LEN;

  for (uint8_t i = 0; i < SYSLOG_CALLBACKS; i++)
    if (syslog_callbacks[i].callback != NULL) {
      syslog_callbacks[i].callback(syslog_callbacks[i].data);
      syslog_callbacks[i].callback = NULL;
      break;
    }

  if (! uip_slen)
    return;

  uip_udp_conn = syslog_conn;
  uip_process (UIP_UDP_SEND_CONN);
  router_output ();

  uip_slen = 0;
}
Beispiel #2
0
uint8_t
router_find_stack(uip_ipaddr_t *forwardip)
{
  uint8_t i;
routing_input:
  for (i = 0; i < STACK_LEN; i++) {
    uip_stack_set_active(i);
    if((! forwardip) && uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr))
      return i;
#ifdef IPV6_SUPPORT
    if(forwardip && uip_ipaddr_prefixlencmp(*forwardip, uip_hostaddr,
                                            uip_prefix_len))
      return i;
#else /* !UIP_CONF_IPV6 */
    if(forwardip && uip_ipaddr_maskcmp(*forwardip, uip_hostaddr,
                                       uip_netmask))
       return i;
#endif
  }
  /* we didn't find an interface for the forwadip, so try it again with the
   * default router
   */
  if (forwardip && forwardip != &uip_draddr){
    forwardip = &uip_draddr;
    goto routing_input;
  }

  /* Drop the packet */
  return 255;
}
Beispiel #3
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 ();
}
Beispiel #4
0
uint8_t
router_output_to (uint8_t dest)
{
  uint8_t retval = 0;

  uip_stack_set_active (dest);

#ifdef IPCHAIR_HAVE_POSTROUTING
  ipchair_POSTROUTING_chair();
  if(!uip_len) return 0;
#endif

  switch (dest)
    {

#ifdef ENC28J60_SUPPORT
    case STACK_ENC:
      printf ("router_output_to: ENC28J60.\n");
      enc28j60_txstart ();
      break;
#endif	/* ENC28J60_SUPPORT */


#ifdef RFM12_IP_SUPPORT
    case STACK_RFM12:
      printf ("router_output_to: RFM12.\n");
      rfm12_txstart (uip_len);
      break;
#endif	/* RFM12_IP_SUPPORT */


#ifdef ZBUS_SUPPORT
    case STACK_ZBUS:
      printf ("router_output_to: ZBUS.\n");
      zbus_txstart (uip_len);
      break;
#endif	/* ZBUS_SUPPORT */


#ifdef USB_NET_SUPPORT
    case STACK_USB:
      printf ("router_output_to: USB.\n");
      usb_net_txstart ();
      break;
#endif	/* USB_NET_SUPPORT */


#ifdef OPENVPN_SUPPORT
    case STACK_OPENVPN:
      printf ("router_output_to: OpenVPN.\n");
      openvpn_txstart ();
      break;
#endif  /* OPENVPN_SUPPORT */

    }

  return retval;
}
Beispiel #5
0
void
uip_arp_ipin(void)
{

    /* Only insert/update an entry if the source IP address of the
       incoming IP packet comes from a host on the local network. */
    uip_stack_set_active(STACK_ENC);
    if (uip_ipaddr_maskcmp(IPBUF->srcipaddr, uip_hostaddr, uip_netmask))
        uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));

    return;
}
Beispiel #6
0
void
rfm12_process(void)
{
  uip_len = rfm12_rxfinish();
  if (!uip_len)
    return;

#ifdef ROUTER_SUPPORT
#ifdef RFM12_RAW_SUPPORT
  if (rfm12_raw_conn->rport)
  {
    /* rfm12 raw capturing active, forward in udp/ip encapsulated form,
     * thusly don't push to the stack. */
    /* FIXME This way we cannot accept rfm12_raw requests from anything
     * but ethernet.  This shalt be improved somewhen. */
    uip_stack_set_active(STACK_ENC);
    memmove(uip_buf + UIP_IPUDPH_LEN + UIP_LLH_LEN, rfm12_data, uip_len);
    uip_slen = uip_len;
    uip_udp_conn = rfm12_raw_conn;
    uip_process(UIP_UDP_SEND_CONN);
    router_output();

    uip_buf_unlock();
    rfm12_rxstart();
    return;
  }
#endif /* RFM12_RAW_SUPPORT */

  /* uip_input expects the number of bytes including the LLH. */
  uip_len = uip_len + RFM12_BRIDGE_OFFSET + RFM12_LLH_LEN;
#endif /* not ROUTER_SUPPORT */

  rfm12_rxstart();

  router_input(STACK_RFM12);

  if (uip_len == 0)
  {
    uip_buf_unlock();
    return;                     /* The stack didn't generate any data
                                 * that has to be sent back. */
  }

  /* Application has generated output, send it out. */
  router_output();
}
Beispiel #7
0
void
usb_net_init (void)
{
#ifdef UIP_MULTI_STACK
  uip_ipaddr_t ip;

  uip_stack_set_active (STACK_USB);

  set_CONF_USB_NET_IP(&ip);
  uip_sethostaddr (&ip);

#ifdef IPV6_SUPPORT
  uip_setprefixlen (CONF_USB_NET_IP6_PREFIX_LEN);
#else
  set_CONF_USB_NET_IP4_NETMASK(&ip);
  uip_setnetmask (&ip);
#endif
#endif /* UIP_MULTI_STACK */
}
Beispiel #8
0
void
network_init(void)
{
    uip_ipaddr_t ip;
    (void) ip;			/* Keep GCC quiet. */

    uip_init();

#if defined(RFM12_IP_SUPPORT) && defined(UIP_MULTI_STACK)
    uip_stack_set_active(STACK_RFM12);
    rfm12_stack_init();
#endif

#if defined(ZBUS_SUPPORT) && defined(UIP_MULTI_STACK)
    uip_stack_set_active(STACK_ZBUS);
    zbus_stack_init();
#endif

#ifdef OPENVPN_SUPPORT
    uip_stack_set_active(STACK_OPENVPN);
    openvpn_init();
#endif

    /* load base network settings */
#   ifdef DEBUG_NET_CONFIG
    debug_printf("net: loading base network settings\n");
#   endif

#ifdef ETHERNET_SUPPORT
# ifdef ENC28J60_SUPPORT
    uip_stack_set_active(STACK_ENC);
# else  /* TAP_SUPPORT */
    uip_stack_set_active(STACK_TAP);
#endif

    /* use uip buffer as generic space here, since when this function is called,
     * no network packets will be processed */

#ifdef EEPROM_SUPPORT
    /* use global network packet buffer for configuration */
    uint8_t checksum = eeprom_get_chksum();
    uint8_t saved_checksum;
    eeprom_restore_char(crc, &saved_checksum);


    if (checksum != saved_checksum)
      eeprom_init();
#endif

#ifdef ETHERNET_SUPPORT
    network_config_load();
#endif



    /* Do the autoconfiguration after the MAC is set */
#   if UIP_CONF_IPV6 && !defined(IPV6_STATIC_SUPPORT)
    uip_setprefixlen(64);
    uip_ip6autoconfig(0xFE80, 0x0000, 0x0000, 0x0000);
#   endif

#   if defined(IPV6_STATIC_SUPPORT) && defined(TFTPOMATIC_SUPPORT)
    const char *filename = CONF_TFTP_IMAGE;
    set_CONF_TFTP_IP(&ip);

    tftp_fire_tftpomatic(&ip, filename);
    bootload_delay = CONF_BOOTLOAD_DELAY;
#   endif /* IPV6_STATIC_SUPPORT && TFTPOMATIC_SUPPORT */


#   elif !defined(ROUTER_SUPPORT) /* and not ETHERNET_SUPPORT */
    /* Don't allow for eeprom-based configuration of rfm12/zbus IP address,
       mainly for code size reasons. */
    set_CONF_ETHERRAPE_IP(&ip);
    uip_sethostaddr(&ip);

#   endif /* not ETHERNET_SUPPORT and not ROUTER_SUPPORT */

    ethersex_meta_netinit();

#   ifdef ENC28J60_SUPPORT
    init_enc28j60();
#   endif

#   ifdef ETHERNET_SUPPORT
#   if UIP_CONF_IPV6
    uip_neighbor_init();
#   else
    uip_arp_init();
#   endif
#   else /* ETHERNET_SUPPORT */
    /* set at least fixed default gateway address
     * to allow multi stack routing */
    set_CONF_ETHERRAPE_GATEWAY(&ip);
    uip_setdraddr(&ip);
#   endif  /* ETHERNET_SUPPORT */

}
Beispiel #9
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;
}