1. 程式人生 > >LwIP與IPv6

LwIP與IPv6

結構體 arr use ont nat found 區分 mas drive

2.0.0中才開始支持IPv6,在此版本中改寫了SNMP,但還沒有IPv6的統計量。目前最新版本是2.0.2,其中SNMP也沒有IPv6統計量(哪些?與IP的統計量有何區別?)

1.4.1中雖然有ip6.c,但是非常簡單。

(2.0.0)

  ++ Application changes:

  * Changed netif "up" flag handling to be an administrative flag (as opposed to the previous meaning of
    "ip4-address-valid", a netif will now not be used for
transmission if not up) -> even a DHCP netif has to be set "up" before starting the DHCP client * Added IPv6 support (dual-stack or IPv4/IPv6 only) * Changed ip_addr_t to be a union in dual-stack mode (use ip4_addr_t where referring to IPv4 only). * Major rewrite of SNMP (added MIB parser that creates code stubs for
custom MIBs); supports SNMPv2c (experimental v3 support)
* Moved some core applications from contrib repository to src/apps (and include/lwip/apps)

兩個版本netif結構體的對比:IPv6每個接口可以配置多個地址(默認3個),地址有狀態區分

/** Generic data structure used for all lwIP network interfaces.
 *  The following fields should be filled in by the initialization
 *  function for the device driver: hwaddr_len, hwaddr[], mtu, flags 
*/
struct netif { /** pointer to next in linked list */ struct netif *next; /** IP address configuration in network byte order */ ip_addr_t ip_addr; ip_addr_t netmask; ip_addr_t gw; /** Generic data structure used for all lwIP network interfaces. * The following fields should be filled in by the initialization * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ struct netif { /** pointer to next in linked list */ struct netif *next; #if LWIP_IPV4 /** IP address configuration in network byte order */ ip_addr_t ip_addr; ip_addr_t netmask; ip_addr_t gw; #endif /* LWIP_IPV4 */ #if LWIP_IPV6 /** Array of IPv6 addresses for this netif. */ ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES]; /** The state of each IPv6 address (Tentative, Preferred, etc). * @see ip6_addr.h */ u8_t ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES]; #endif /* LWIP_IPV6 */

兩個版本IPv6路由函數對比,新版本會判斷是否是link local地址等等。

/* ip_route:
 *
 * Finds the appropriate network interface for a given IP address. It searches the
 * list of network interfaces linearly. A match is found if the masked IP address of
 * the network interface equals the masked IP address given to the function.
 */
struct netif *
ip_route(struct ip_addr *dest)
{
  struct netif *netif;

  for(netif = netif_list; netif != NULL; netif = netif->next) {
    if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
      return netif;
    }
  }
  return netif_default;
}


/**
 * Finds the appropriate network interface for a given IPv6 address. It tries to select
 * a netif following a sequence of heuristics:
 * 1) if there is only 1 netif, return it
 * 2) if the destination is a link-local address, try to match the src address to a netif.
 *    this is a tricky case because with multiple netifs, link-local addresses only have
 *    meaning within a particular subnet/link.
 * 3) tries to match the destination subnet to a configured address
 * 4) tries to find a router
 * 5) tries to match the source address to the netif
 * 6) returns the default netif, if configured
 *
 * @param src the source IPv6 address, if known
 * @param dest the destination IPv6 address for which to find the route
 * @return the netif on which to send to reach dest
 */
struct netif *
ip6_route(const ip6_addr_t *src, const ip6_addr_t *dest)

LwIP與IPv6