static void ip6_forward(struct pbuf *p, struct ip6_hdr *iphdr) { struct netif *netif; PERF_START; if ((netif = ip6_route((struct ip6_addr *) &(iphdr->dest))) == NULL) { LWIP_DEBUGF(IP_DEBUG, ("ip_input: no forwarding route found for ")); #if IP_DEBUG ip6_addr_debug_print(IP_DEBUG, ((struct ip6_addr *)&(iphdr->dest))); #endif /* IP_DEBUG */ LWIP_DEBUGF(IP_DEBUG, ("\n")); pbuf_free(p); return; } /* Decrement TTL and send ICMP if ttl == 0. */ if (--iphdr->hoplim == 0) { #if LWIP_ICMP /* Don't send ICMP messages in response to ICMP messages */ if (iphdr->nexthdr != IP6_PROTO_ICMP) { icmp6_time_exceeded(p, ICMP_TE_TTL); } #endif /* LWIP_ICMP */ pbuf_free(p); return; } /* Incremental update of the IP checksum. */ /* if (iphdr->chksum >= htons(0xffff - 0x100)) { iphdr->chksum += htons(0x100) + 1; } else { iphdr->chksum += htons(0x100); }*/ LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to ")); #if IP_DEBUG ip6_addr_debug_print(IP_DEBUG, ((struct ip6_addr *)&(iphdr->dest))); #endif /* IP_DEBUG */ LWIP_DEBUGF(IP_DEBUG, ("\n")); IP_STATS_INC(ip.fw); IP_STATS_INC(ip.xmit); PERF_STOP("ip_forward"); netif->ip6_output(netif, p, (struct ip6_addr *) &(iphdr->dest)); }
/* This function initializes all network interfaces */ static void msvc_netif_init() { #if USE_ETHERNET ip_addr_t ipaddr, netmask, gw; #endif /* USE_ETHERNET */ #if PPP_SUPPORT const char *username = NULL, *password = NULL; #ifdef PPP_USERNAME username = PPP_USERNAME; #endif #ifdef PPP_PASSWORD password = PPP_PASSWORD; #endif printf("pppInit\n"); pppInit(); pppSetAuth(PPPAUTHTYPE_ANY, username, password); printf("pppOpen: COM%d\n", (int)sio_idx); #if PPPOS_SUPPORT ppp_sio = sio_open(sio_idx); if (ppp_sio == NULL) { printf("sio_open error\n"); } else { ppp_desc = pppOpen(ppp_sio, pppLinkStatusCallback, NULL); } #endif /* PPPOS_SUPPORT */ #endif /* PPP_SUPPORT */ #if USE_ETHERNET ip_addr_set_zero(&gw); ip_addr_set_zero(&ipaddr); ip_addr_set_zero(&netmask); #if USE_ETHERNET_TCPIP #if USE_DHCP printf("Starting lwIP, local interface IP is dhcp-enabled\n"); #elif USE_AUTOIP printf("Starting lwIP, local interface IP is autoip-enabled\n"); #else /* USE_DHCP */ LWIP_PORT_INIT_GW(&gw); LWIP_PORT_INIT_IPADDR(&ipaddr); LWIP_PORT_INIT_NETMASK(&netmask); printf("Starting lwIP, local interface IP is %s\n", ip_ntoa(&ipaddr)); #endif /* USE_DHCP */ #endif /* USE_ETHERNET_TCPIP */ #if NO_SYS #if LWIP_ARP netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, ethernet_input)); #else /* LWIP_ARP */ netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, ip_input)); #endif /* LWIP_ARP */ #else /* NO_SYS */ netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input)); #if LWIP_IPV6 netif_create_ip6_linklocal_address(&netif, 1); printf("ip6 linklocal address: "); ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, &netif.ip6_addr[0]); printf("\n"); #endif /* LWIP_IPV6 */ #endif /* NO_SYS */ #if LWIP_NETIF_STATUS_CALLBACK netif_set_status_callback(&netif, status_callback); #endif /* LWIP_NETIF_STATUS_CALLBACK */ #if LWIP_NETIF_LINK_CALLBACK netif_set_link_callback(&netif, link_callback); #endif /* LWIP_NETIF_LINK_CALLBACK */ #if USE_ETHERNET_TCPIP #if LWIP_AUTOIP autoip_set_struct(&netif, &netif_autoip); #endif /* LWIP_AUTOIP */ #if LWIP_DHCP dhcp_set_struct(&netif, &netif_dhcp); #endif /* LWIP_DHCP */ #if USE_DHCP dhcp_start(&netif); #elif USE_AUTOIP autoip_start(&netif); #else /* USE_DHCP */ netif_set_up(&netif); #endif /* USE_DHCP */ #else /* USE_ETHERNET_TCPIP */ /* Use ethernet for PPPoE only */ netif.flags &= ~(NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP); /* no ARP */ netif.flags |= NETIF_FLAG_ETHERNET; /* but pure ethernet */ #endif /* USE_ETHERNET_TCPIP */ #if PPP_SUPPORT && PPPOE_SUPPORT /* start PPPoE after ethernet netif is added! */ ppp_desc = pppOverEthernetOpen(&netif, NULL, NULL, pppLinkStatusCallback, NULL); #endif /* PPP_SUPPORT && PPPOE_SUPPORT */ #endif /* USE_ETHERNET */ }
void ip6_input(struct pbuf *p, struct netif *inp) { struct ip6_hdr *iphdr; struct netif *netif; PERF_START; #if IP_DEBUG ip6_debug_print(p); #endif /* IP_DEBUG */ IP_STATS_INC(ip.recv); /* identify the IP header */ iphdr = p->payload; if (iphdr->v != 6) { LWIP_DEBUGF(IP_DEBUG, ("IP packet dropped due to bad version number\n")); #if IP_DEBUG ip6_debug_print(p); #endif /* IP_DEBUG */ pbuf_free(p); IP_STATS_INC(ip.err);IP_STATS_INC(ip.drop); return; } char forus = 0; /* is this packet for us? */ for (netif = netif_list; netif != NULL; netif = netif->next) { #if IP_DEBUG LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest ")); ip6_addr_debug_print(IP_DEBUG, ((struct ip6_addr *)&(iphdr->dest))); LWIP_DEBUGF(IP_DEBUG, ("netif->ip6_addr ")); ip6_addr_debug_print(IP_DEBUG, ((struct ip6_addr *)&(netif->ip6_addr))); LWIP_DEBUGF(IP_DEBUG, ("\n\r")); #endif /* IP_DEBUG */ if (ip6_addr_cmp(&(iphdr->dest), &(netif->ip6_addr))) { forus = 1; LWIP_DEBUGF(IP_DEBUG, ("ip6_input: packet for us: perfect match")); break; } if (ip6_addr_issolicitedmulticast(&(iphdr->dest), &(netif->ip6_addr))) { forus = 1; LWIP_DEBUGF(IP_DEBUG, ("ip6_input: packet for us on solicited multicast address\n")); break; } } // check if it is a multicast address and we are listening on that address if (ip6_addr_isallnodes(&(iphdr->dest))) forus = 1; if (forus == 0) { /* packet not for us, route or discard */ LWIP_DEBUGF(IP_DEBUG, ("ip6_input: packet not for us.\n")); #if IP_FORWARD ip6_forward(p, iphdr); #endif pbuf_free(p); return; } pbuf_realloc(p, IP6_HLEN + ntohs(iphdr->len)); /* send to upper layers */ #if IP_DEBUG /* LWIP_DEBUGF("ip_input: \n"); ip_debug_print(p); LWIP_DEBUGF("ip_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len);*/ #endif /* IP_DEBUG */ /*if(pbuf_header(p, -IP6_HLEN)) { LWIP_ASSERT("Can't move over header in packet", 0); return; }*/ switch (iphdr->nexthdr) { #if LWIP_UDP case IP6_PROTO_UDP: udp_input(p, inp); break; #endif #if LWIP_TCP case IP6_PROTO_TCP: tcp_input(p, inp); break; #endif #if LWIP_ICMP case IP6_PROTO_ICMP: icmp6_input(p, inp); break; #endif /* LWIP_ICMP */ default: #if LWIP_ICMP /* send ICMP destination protocol unreachable */ icmp6_dest_unreach(p, ICMP_DUR_PROTO); #endif /* LWIP_ICMP */ pbuf_free(p); LWIP_DEBUGF(IP_DEBUG, ("Unsupported transport protocol %"U16_F"\n", iphdr->nexthdr)); IP_STATS_INC(ip.proterr); IP_STATS_INC(ip.drop); }PERF_STOP("ip_input"); }
/* This function initializes all network interfaces */ static void msvc_netif_init(void) { #if LWIP_IPV4 && USE_ETHERNET ip4_addr_t ipaddr, netmask, gw; #endif /* LWIP_IPV4 && USE_ETHERNET */ #if USE_SLIPIF u8_t num_slip1 = 0; #if LWIP_IPV4 ip4_addr_t ipaddr_slip1, netmask_slip1, gw_slip1; #endif #if USE_SLIPIF > 1 u8_t num_slip2 = 1; #if LWIP_IPV4 ip4_addr_t ipaddr_slip2, netmask_slip2, gw_slip2; #endif #endif /* USE_SLIPIF > 1 */ #endif /* USE_SLIPIF */ #if USE_DHCP || USE_AUTOIP err_t err; #endif #if USE_PPP const char *username = NULL, *password = NULL; #ifdef PPP_USERNAME username = PPP_USERNAME; #endif #ifdef PPP_PASSWORD password = PPP_PASSWORD; #endif printf("ppp_connect: COM%d\n", (int)sio_idx); #if PPPOS_SUPPORT ppp_sio = sio_open(sio_idx); if (ppp_sio == NULL) { printf("sio_open error\n"); } else { ppp = pppos_create(&ppp_netif, ppp_output_cb, pppLinkStatusCallback, NULL); if (ppp == NULL) { printf("pppos_create error\n"); } else { ppp_set_auth(ppp, PPPAUTHTYPE_ANY, username, password); ppp_connect(ppp, 0); } } #endif /* PPPOS_SUPPORT */ #endif /* USE_PPP */ #if USE_ETHERNET #if LWIP_IPV4 #define NETIF_ADDRS &ipaddr, &netmask, &gw, ip4_addr_set_zero(&gw); ip4_addr_set_zero(&ipaddr); ip4_addr_set_zero(&netmask); #if USE_ETHERNET_TCPIP #if USE_DHCP printf("Starting lwIP, local interface IP is dhcp-enabled\n"); #elif USE_AUTOIP printf("Starting lwIP, local interface IP is autoip-enabled\n"); #else /* USE_DHCP */ LWIP_PORT_INIT_GW(&gw); LWIP_PORT_INIT_IPADDR(&ipaddr); LWIP_PORT_INIT_NETMASK(&netmask); printf("Starting lwIP, local interface IP is %s\n", ip4addr_ntoa(&ipaddr)); #endif /* USE_DHCP */ #endif /* USE_ETHERNET_TCPIP */ #else /* LWIP_IPV4 */ #define NETIF_ADDRS printf("Starting lwIP, IPv4 disable\n"); #endif /* LWIP_IPV4 */ #if NO_SYS netif_set_default(netif_add(&netif, NETIF_ADDRS NULL, pcapif_init, netif_input)); #else /* NO_SYS */ netif_set_default(netif_add(&netif, NETIF_ADDRS NULL, pcapif_init, tcpip_input)); #endif /* NO_SYS */ #if LWIP_IPV6 netif_create_ip6_linklocal_address(&netif, 1); printf("ip6 linklocal address: "); ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, netif_ip6_addr(&netif, 0)); printf("\n"); #endif /* LWIP_IPV6 */ #if LWIP_NETIF_STATUS_CALLBACK netif_set_status_callback(&netif, status_callback); #endif /* LWIP_NETIF_STATUS_CALLBACK */ #if LWIP_NETIF_LINK_CALLBACK netif_set_link_callback(&netif, link_callback); #endif /* LWIP_NETIF_LINK_CALLBACK */ #if USE_ETHERNET_TCPIP #if LWIP_AUTOIP autoip_set_struct(&netif, &netif_autoip); #endif /* LWIP_AUTOIP */ #if LWIP_DHCP dhcp_set_struct(&netif, &netif_dhcp); #endif /* LWIP_DHCP */ netif_set_up(&netif); #if USE_DHCP err = dhcp_start(&netif); LWIP_ASSERT("dhcp_start failed", err == ERR_OK); #elif USE_AUTOIP err = autoip_start(&netif); LWIP_ASSERT("autoip_start failed", err == ERR_OK); #endif /* USE_DHCP */ #else /* USE_ETHERNET_TCPIP */ /* Use ethernet for PPPoE only */ netif.flags &= ~(NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP); /* no ARP */ netif.flags |= NETIF_FLAG_ETHERNET; /* but pure ethernet */ #endif /* USE_ETHERNET_TCPIP */ #if USE_PPP && PPPOE_SUPPORT /* start PPPoE after ethernet netif is added! */ ppp = pppoe_create(&ppp_netif, &netif, NULL, NULL, pppLinkStatusCallback, NULL); if (ppp == NULL) { printf("pppos_create error\n"); } else { ppp_set_auth(ppp, PPPAUTHTYPE_ANY, username, password); ppp_connect(ppp, 0); } #endif /* USE_PPP && PPPOE_SUPPORT */ #endif /* USE_ETHERNET */ #if USE_SLIPIF #if LWIP_IPV4 #define SLIP1_ADDRS &ipaddr_slip1, &netmask_slip1, &gw_slip1, LWIP_PORT_INIT_SLIP1_IPADDR(&ipaddr_slip1); LWIP_PORT_INIT_SLIP1_GW(&gw_slip1); LWIP_PORT_INIT_SLIP1_NETMASK(&netmask_slip1); printf("Starting lwIP slipif, local interface IP is %s\n", ip4addr_ntoa(&ipaddr_slip1)); #else #define SLIP1_ADDRS printf("Starting lwIP slipif\n"); #endif #if defined(SIO_USE_COMPORT) && SIO_USE_COMPORT num_slip1++; /* COM ports cannot be 0-based */ #endif netif_add(&slipif1, SLIP1_ADDRS &num_slip1, slipif_init, ip_input); #if !USE_ETHERNET netif_set_default(&slipif1); #endif /* !USE_ETHERNET */ #if LWIP_IPV6 netif_create_ip6_linklocal_address(&slipif1, 1); printf("SLIP ip6 linklocal address: "); ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, netif_ip6_addr(&slipif1, 0)); printf("\n"); #endif /* LWIP_IPV6 */ #if LWIP_NETIF_STATUS_CALLBACK netif_set_status_callback(&slipif1, status_callback); #endif /* LWIP_NETIF_STATUS_CALLBACK */ #if LWIP_NETIF_LINK_CALLBACK netif_set_link_callback(&slipif1, link_callback); #endif /* LWIP_NETIF_LINK_CALLBACK */ netif_set_up(&slipif1); #if USE_SLIPIF > 1 #if LWIP_IPV4 #define SLIP2_ADDRS &ipaddr_slip2, &netmask_slip2, &gw_slip2, LWIP_PORT_INIT_SLIP2_IPADDR(&ipaddr_slip2); LWIP_PORT_INIT_SLIP2_GW(&gw_slip2); LWIP_PORT_INIT_SLIP2_NETMASK(&netmask_slip2); printf("Starting lwIP SLIP if #2, local interface IP is %s\n", ip4addr_ntoa(&ipaddr_slip2)); #else #define SLIP2_ADDRS printf("Starting lwIP SLIP if #2\n"); #endif #if defined(SIO_USE_COMPORT) && SIO_USE_COMPORT num_slip2++; /* COM ports cannot be 0-based */ #endif netif_add(&slipif2, SLIP2_ADDRS &num_slip2, slipif_init, ip_input); #if LWIP_IPV6 netif_create_ip6_linklocal_address(&slipif1, 1); printf("SLIP2 ip6 linklocal address: "); ip6_addr_debug_print(0xFFFFFFFF & ~LWIP_DBG_HALT, netif_ip6_addr(&slipif2, 0)); printf("\n"); #endif /* LWIP_IPV6 */ #if LWIP_NETIF_STATUS_CALLBACK netif_set_status_callback(&slipif2, status_callback); #endif /* LWIP_NETIF_STATUS_CALLBACK */ #if LWIP_NETIF_LINK_CALLBACK netif_set_link_callback(&slipif2, link_callback); #endif /* LWIP_NETIF_LINK_CALLBACK */ netif_set_up(&slipif2); #endif /* USE_SLIPIF > 1*/ #endif /* USE_SLIPIF */ }