Пример #1
0
/*
 * Callback for netif_add() to initialize the interface.
 */
err_t VBoxNetLwipNAT::netifInit(netif *pNetif)
{
    err_t rcLwip = ERR_OK;

    AssertPtrReturn(pNetif, ERR_ARG);

    VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(pNetif->state);
    AssertPtrReturn(pNat, ERR_ARG);

    LogFlowFunc(("ENTER: pNetif[%c%c%d]\n", pNetif->name[0], pNetif->name[1], pNetif->num));
    /* validity */
    AssertReturn(   pNetif->name[0] == 'N'
                 && pNetif->name[1] == 'T', ERR_ARG);


    pNetif->hwaddr_len = sizeof(RTMAC);
    RTMAC mac = g_pLwipNat->getMacAddress();
    memcpy(pNetif->hwaddr, &mac, sizeof(RTMAC));

    pNat->m_u16Mtu = 1500; // XXX: FIXME
    pNetif->mtu = pNat->m_u16Mtu;

    pNetif->flags = NETIF_FLAG_BROADCAST
      | NETIF_FLAG_ETHARP                /* Don't bother driver with ARP and let Lwip resolve ARP handling */
      | NETIF_FLAG_ETHERNET;             /* Lwip works with ethernet too */

    pNetif->linkoutput = netifLinkoutput; /* ether-level-pipe */
    pNetif->output = etharp_output;       /* ip-pipe */

    if (pNat->m_ProxyOptions.ipv6_enabled) {
        pNetif->output_ip6 = ethip6_output;

        /* IPv6 link-local address in slot 0 */
        netif_create_ip6_linklocal_address(pNetif, /* :from_mac_48bit */ 1);
        netif_ip6_addr_set_state(pNetif, 0, IP6_ADDR_PREFERRED); // skip DAD

        /*
         * RFC 4193 Locally Assigned Global ID (ULA) in slot 1
         * [fd17:625c:f037:XXXX::1] where XXXX, 16 bit Subnet ID, are two
         * bytes from the middle of the IPv4 address, e.g. :dead: for
         * 10.222.173.1
         */
        u8_t nethi = ip4_addr2(&pNetif->ip_addr);
        u8_t netlo = ip4_addr3(&pNetif->ip_addr);

        ip6_addr_t *paddr = netif_ip6_addr(pNetif, 1);
        IP6_ADDR(paddr, 0,   0xFD, 0x17,   0x62, 0x5C);
        IP6_ADDR(paddr, 1,   0xF0, 0x37,  nethi, netlo);
        IP6_ADDR(paddr, 2,   0x00, 0x00,   0x00, 0x00);
        IP6_ADDR(paddr, 3,   0x00, 0x00,   0x00, 0x01);
        netif_ip6_addr_set_state(pNetif, 1, IP6_ADDR_PREFERRED);

#if LWIP_IPV6_SEND_ROUTER_SOLICIT
        pNetif->rs_count = 0;
#endif
    }

    LogFlowFunc(("LEAVE: %d\n", rcLwip));
    return rcLwip;
}
Пример #2
0
/** This function allows for the easy addition of a new IPv6 address to an interface.
 * It takes care of finding an empty slot and then sets the address tentative
 * (to make sure that all the subsequent processing happens).
 *
 * @param netif netif to add the address on
 * @param ip6addr address to add
 * @param chosen_idx if != NULL, the chosen IPv6 address index will be stored here
 */
err_t
netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx)
{
  s8_t i;

  i = netif_get_ip6_addr_match(netif, ip6addr);
  if (i >= 0) {
    /* Address already added */
    if (chosen_idx != NULL) {
      *chosen_idx = i;
    }
    return ERR_OK;
  }

  /* Find a free slot -- musn't be the first one (reserved for link local) */
  for (i = 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
    if (!ip6_addr_isvalid(netif->ip6_addr_state[i])) {
      ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr);
      netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
      if (chosen_idx != NULL) {
        *chosen_idx = i;
      }
      return ERR_OK;
    }
  }

  if (chosen_idx != NULL) {
    *chosen_idx = -1;
  }
  return ERR_VAL;
}
Пример #3
0
/**
 * Callback for tcpip_init()
 */
static void tcpip_init_cb(void *args){/*{{{*/
    ip_addr_t ip_addr;
    ip_addr_t netmask;
    ip_addr_t gw_addr;
    BaseType_t retval;
    eth_int_q_handle = xQueueCreate(1, sizeof(uint32_t));

    retval = xTaskCreate( eth_int_task,
            "eth_int",
            ETH_INT_STACK,
            NULL,
            tskIDLE_PRIORITY+ETH_PRIO,
            &eth_int_task_handle);
    LOOP_ERRMSG(retval != pdPASS, "Could not start lwip eth_int task\n" );


#if XBH_IP4_STATIC
    ip_addr.addr = htonl(XBH_IP4_ADDR);
    netmask.addr = htonl(XBH_IP4_NETMASK);
    gw_addr.addr = 0;
#else
    ip_addr.addr = 0;
    netmask.addr = 0;
    gw_addr.addr = 0;
#endif
    netif_add(&lwip_netif, &ip_addr, &netmask, &gw_addr, NULL, tivaif_init,
            tcpip_input);

    //netif_add sets everything to defaults, so run after netif_add
    netif_set_hostname(&lwip_netif, XBH_HOSTNAME);
    netif_set_status_callback(&lwip_netif, link_status);
    netif_set_default(&lwip_netif);

#if LWIP_IPV6
    lwip_netif.ip6_autoconfig_enabled = 1;
    lwip_netif.output_ip6 = ethip6_output;
    //IPv6, enable linklocal addresses and SLAAC
    netif_create_ip6_linklocal_address(&lwip_netif, 1);
    netif_ip6_addr_set_state((&lwip_netif), 0, IP6_ADDR_TENTATIVE); 
#endif
#if XBH_IP4_STATIC
    netif_set_up(&lwip_netif);
#else
    dhcp_start(&lwip_netif);
#endif
    
#if DEBUG_STACK
    DEBUG_OUT("Stack Usage: %s: %d\n", __PRETTY_FUNCTION__, uxTaskGetStackHighWaterMark(NULL));
#endif
}/*}}}*/
Пример #4
0
void cbIP_initPanInterfaceDHCP(
    char* hostname, 
    const cbIP_IPv6Settings * const IPv6Settings, 
    cbIP_interfaceSettings const * const ifConfig, 
    cbIP_statusIndication callback, 
    void* callbackArg)
{
    struct ip_addr ipaddr;
    struct ip_addr netmask;
    struct ip_addr gw;
    struct ip6_addr ip6addr;

    MBED_ASSERT(callback != NULL && hostname != NULL && ifConfig != NULL);

    IP4_ADDR(&gw, 0, 0, 0, 0);
    IP4_ADDR(&ipaddr, 0, 0, 0, 0);
    IP4_ADDR(&netmask, 0, 0, 0, 0);

    memcpy(&ip6addr, &IPv6Settings->linklocal.value, sizeof(ip6addr));

    memcpy(&panIf.ifConfig, ifConfig, sizeof(panIf.ifConfig));

    netif_add(&panIf.hInterface, &ipaddr, &netmask, &gw, &panIf, cb_netif_init, ethernet_input);
    panIf.hInterface.hostname = hostname;
    panIf.callbackArg = callbackArg;
    panIf.hInterface.ip6_autoconfig_enabled = 0;
    if ((ip6addr.addr[0] == 0) && (ip6addr.addr[1] == 0) &&
        (ip6addr.addr[2] == 0) && (ip6addr.addr[3] == 0)) {
        netif_create_ip6_linklocal_address(&panIf.hInterface, 1);
    } else {
        panIf.hInterface.ip6_addr[0] = ip6addr;
    }
    netif_ip6_addr_set_state((&panIf.hInterface), 0, IP6_ADDR_TENTATIVE);

    panIf.statusCallback = callback;
    netif_set_status_callback(&panIf.hInterface, netif_status_callback);

    LWIP_PRINT("Using DHCP\n");
    dhcp_start(&panIf.hInterface);

    cb_uint32 result;
    result = cbBTPAN_registerDataCallback(&_panCallBack);
    MBED_ASSERT(result == cbBTPAN_RESULT_OK);
}
Пример #5
0
/**
 * Add a network interface to the list of lwIP netifs.
 *
 * @param netif a pre-allocated netif structure
 * @param ipaddr IP address for the new netif
 * @param netmask network mask for the new netif
 * @param gw default gateway IP address for the new netif
 * @param state opaque data passed to the new netif
 * @param init callback function that initializes the interface
 * @param input callback function that is called to pass
 * ingress packets up in the protocol layer stack.
 *
 * @return netif, or NULL if failed.
 */
struct netif *
netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask,
  ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
{
#if LWIP_IPV6
  u32_t i;
#endif

  LWIP_ASSERT("No init function given", init != NULL);

  /* reset new interface configuration state */
  ip_addr_set_zero(&netif->ip_addr);
  ip_addr_set_zero(&netif->netmask);
  ip_addr_set_zero(&netif->gw);
#if LWIP_IPV6
  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
    ip6_addr_set_zero(&netif->ip6_addr[i]);
    netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID);
  }
  netif->output_ip6 = netif_null_output_ip6;
#endif /* LWIP_IPV6 */
  netif->flags = 0;
#if LWIP_DHCP
  /* netif not under DHCP control by default */
  netif->dhcp = NULL;
#endif /* LWIP_DHCP */
#if LWIP_AUTOIP
  /* netif not under AutoIP control by default */
  netif->autoip = NULL;
#endif /* LWIP_AUTOIP */
#if LWIP_IPV6_AUTOCONFIG
  /* IPv6 address autoconfiguration not enabled by default */
  netif->ip6_autoconfig_enabled = 0;
#endif /* LWIP_IPV6_AUTOCONFIG */
#if LWIP_IPV6_SEND_ROUTER_SOLICIT
  netif->rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT;
#endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
#if LWIP_IPV6_DHCP6
  /* netif not under DHCPv6 control by default */
  netif->dhcp6 = NULL;
#endif /* LWIP_IPV6_DHCP6 */
#if LWIP_NETIF_STATUS_CALLBACK
  netif->status_callback = NULL;
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
  netif->link_callback = NULL;
#endif /* LWIP_NETIF_LINK_CALLBACK */
#if LWIP_IGMP
  netif->igmp_mac_filter = NULL;
#endif /* LWIP_IGMP */
#if LWIP_IPV6 && LWIP_IPV6_MLD
  netif->mld_mac_filter = NULL;
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
#if ENABLE_LOOPBACK
  netif->loop_first = NULL;
  netif->loop_last = NULL;
#endif /* ENABLE_LOOPBACK */

  /* remember netif specific state information data */
  netif->state = state;
#ifdef PSIPHON
  /* tun2socks as a library, with a multi-run lifetime,
     may invoke this multiple times */
  netif->num = netif_num;
#else
  netif->num = netif_num++;
#endif /* PSIPHON */
  netif->input = input;
  NETIF_SET_HWADDRHINT(netif, NULL);
#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
  netif->loop_cnt_current = 0;
#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */

  netif_set_addr(netif, ipaddr, netmask, gw);

  /* call user specified initialization function for netif */
  if (init(netif) != ERR_OK) {
    return NULL;
  }

  /* add this netif to the list */
  netif->next = netif_list;
  netif_list = netif;
  snmp_inc_iflist();

#if LWIP_IGMP
  /* start IGMP processing */
  if (netif->flags & NETIF_FLAG_IGMP) {
    igmp_start(netif);
  }
#endif /* LWIP_IGMP */

  LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
    netif->name[0], netif->name[1]));
  ip_addr_debug_print(NETIF_DEBUG, ipaddr);
  LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
  ip_addr_debug_print(NETIF_DEBUG, netmask);
  LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
  ip_addr_debug_print(NETIF_DEBUG, gw);
  LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
  return netif;
}
Пример #6
0
static void mbed_lwip_clear_ipv6_addresses(struct netif *netif)
{
    for (u8_t i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
        netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID);
    }
}
Пример #7
0
void interface_init (struct interface *netif, void *state, netif_input_fn input)
{
    static u8_t         netifnum = 0;

#if LWIP_IPV6
  u32_t i;
#endif

  /* reset new interface configuration state */
  ip_addr_set_zero(&netif->ip_addr);
  ip_addr_set_zero(&netif->netmask);
  ip_addr_set_zero(&netif->gw);
#if LWIP_IPV6
  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
    ip6_addr_set_zero(&netif->ip6_addr[i]);
    netif_ip6_addr_set_state(netif, i, IP6_ADDR_INVALID);
  }
#endif /* LWIP_IPV6 */

    netif->flags = 0;
#if LWIP_DHCP
    /* netif not under DHCP control by default */
    netif->dhcp = NULL;
#endif /* LWIP_DHCP */
#if LWIP_AUTOIP
    /* netif not under AutoIP control by default */
    netif->autoip = NULL;
#endif /* LWIP_AUTOIP */
#if LWIP_IPV6_AUTOCONFIG
  /* IPv6 address autoconfiguration not enabled by default */
  netif->ip6_autoconfig_enabled = 0;
#endif /* LWIP_IPV6_AUTOCONFIG */
#if LWIP_IPV6_SEND_ROUTER_SOLICIT
  netif->rs_count = LWIP_ND6_MAX_MULTICAST_SOLICIT;
#endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
#if LWIP_IPV6_DHCP6
  /* netif not under DHCPv6 control by default */
  netif->dhcp6 = NULL;
#endif /* LWIP_IPV6_DHCP6 */
#if LWIP_NETIF_STATUS_CALLBACK
    netif->status_callback = NULL;
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
    netif->link_callback = NULL;
#endif /* LWIP_NETIF_LINK_CALLBACK */
#if LWIP_IGMP
    netif->igmp_mac_filter = NULL;
#endif /* LWIP_IGMP */
#if LWIP_IPV6 && LWIP_IPV6_MLD
  netif->mld_mac_filter = NULL;
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
#if ENABLE_LOOPBACK
    netif->loop_first = NULL;
    netif->loop_last = NULL;
#endif /* ENABLE_LOOPBACK */

    /* remember netif specific state information data */
    netif->state = state;
    netif->num = netifnum++;
    netif->input = input;
#if LWIP_NETIF_HWADDRHINT
    netif->addr_hint = NULL;
#endif /* LWIP_NETIF_HWADDRHINT */
#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
    netif->loop_cnt_current = 0;
#endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */

#ifdef CONFIG_OPENSWITCH_TCP_IP
    ethernetif_init (netif);
#else
    netif->linkoutput = low_level_output;
#endif

    if_zebra_new_hook (netif);

#if 0
    /* call user specified initialization function for netif */
    if (init (netif) != ERR_OK)
    {
        return NULL;
    }
#endif

    /* add this netif to the list */
#ifdef CONFIG_OPENSWITCH_TCP_IP
    snmp_inc_iflist ();
#endif

#if 0
    /* start IGMP processing */
    if (netif->flags & NETIF_FLAG_IGMP)
    {
        igmp_start (netif);
    }
#endif /* LWIP_IGMP */

    LWIP_DEBUGF (NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
                               netif->ifDescr[0], netif->ifDescr[1]));
    LWIP_DEBUGF (NETIF_DEBUG, ("\n"));
    return;
}
Пример #8
0
void cbIP_initPanInterfaceStatic(
	
    char* hostname, 
    const cbIP_IPv4Settings * const IPv4Settings, 
    const cbIP_IPv6Settings * const IPv6Settings, 
    cbIP_interfaceSettings const * const ifConfig, 
    cbIP_statusIndication callback, 
    void* callbackArg)
{
    struct ip_addr ipaddr;
    struct ip_addr netmask;
    struct ip_addr gw;
    struct ip_addr dns0;
    struct ip_addr dns1;
    struct ip6_addr ip6addr;

	MBED_ASSERT(callback != NULL && hostname != NULL && IPv4Settings != NULL && ifConfig != NULL);

    gw.addr = IPv4Settings->gateway.value;
    ipaddr.addr = IPv4Settings->address.value;
    netmask.addr = IPv4Settings->netmask.value;
    dns0.addr = IPv4Settings->dns0.value;
    dns1.addr = IPv4Settings->dns1.value;

    memcpy(&ip6addr, &IPv6Settings->linklocal.value, sizeof(ip6addr));

    memcpy(&panIf.ifConfig, ifConfig, sizeof(panIf.ifConfig));
    panIf.statusCallback = callback;
    panIf.callbackArg = callbackArg;
    netif_add(&panIf.hInterface, &ipaddr, &netmask, &gw, &panIf, cb_netif_init, ethernet_input);
    panIf.hInterface.hostname = hostname;

    panIf.hInterface.ip6_autoconfig_enabled = 0;
    if ((ip6addr.addr[0] == 0) && (ip6addr.addr[1] == 0) &&
        (ip6addr.addr[2] == 0) && (ip6addr.addr[3] == 0)) {
        netif_create_ip6_linklocal_address(&panIf.hInterface, 1);
    } else {
        memcpy(&panIf.hInterface.ip6_addr[0], &ip6addr, sizeof(ip6addr));
    }
    netif_ip6_addr_set_state((&panIf.hInterface), 0, IP6_ADDR_TENTATIVE);

    dns_setserver(0, &dns0);
    dns_setserver(1, &dns1);

    LWIP_PRINT("Using static ip addresses\n");
    LWIP_PRINT("IP address: %d.%d.%d.%d\n",
               ip4_addr1(&ipaddr), ip4_addr2(&ipaddr),
               ip4_addr3(&ipaddr), ip4_addr4(&ipaddr));
    LWIP_PRINT("Netmask:    %d.%d.%d.%d\n",
               ip4_addr1(&netmask), ip4_addr2(&netmask),
               ip4_addr3(&netmask), ip4_addr4(&netmask));
    LWIP_PRINT("Gateway:    %d.%d.%d.%d\n",
               ip4_addr1(&gw), ip4_addr2(&gw),
               ip4_addr3(&gw), ip4_addr4(&gw));
    LWIP_PRINT("Primary dns:    %d.%d.%d.%d\n",
               ip4_addr1(&dns0), ip4_addr2(&dns0),
               ip4_addr3(&dns0), ip4_addr4(&dns0));
    LWIP_PRINT("Secondary dns:    %d.%d.%d.%d\n",
               ip4_addr1(&dns1), ip4_addr2(&dns1),
               ip4_addr3(&dns1), ip4_addr4(&dns1));

    panIf.statusCallback = callback;
    panIf.hInterface.state = &panIf;
    netif_set_status_callback(&panIf.hInterface, netif_status_callback);
    netif_set_up(&panIf.hInterface);

    cb_uint32 result;
    result = cbBTPAN_registerDataCallback(&_panCallBack);
    MBED_ASSERT(result == cbBTPAN_RESULT_OK);
}