diff --git a/CHANGELOG b/CHANGELOG index 2a60fd46..0ff9325b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,10 @@ HISTORY ++ New features: + 2007-10-05 Simon Goldschmidt + * tcpip.c, etharp.h, etharp.c: moved ethernet_input from tcpip.c to etharp.c so + all netifs (or ports) can use it. + 2007-10-05 Frédéric Bernon * netifapi.h, netifapi.c: add function netifapi_netif_set_default. Change the common function to reduce a little bit the footprint (for all functions using diff --git a/src/api/tcpip.c b/src/api/tcpip.c index c8cd605f..e79fabe1 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -202,66 +202,6 @@ igmp_timer(void *arg) } #endif /* LWIP_IGMP */ -#if LWIP_ARP -/** - * Process received ethernet frames. Using this function instead of directly - * calling ip_input and passing ARP frames through etharp in ethernetif_input, - * the ARP cache is protected from concurrent access. - * - * @param p the recevied packet, p->payload pointing to the ethernet header - * @param netif the network interface on which the packet was received - */ -static err_t -ethernet_input(struct pbuf *p, struct netif *netif) -{ - struct eth_hdr* ethhdr; - - /* points to packet payload, which starts with an Ethernet header */ - ethhdr = p->payload; - - switch (htons(ethhdr->type)) { - /* IP packet? */ - case ETHTYPE_IP: -#if ETHARP_TRUST_IP_MAC - /* update ARP table */ - etharp_ip_input( netif, p); -#endif /* ETHARP_TRUST_IP_MAC */ - /* skip Ethernet header */ - if(pbuf_header(p, -(s16_t)sizeof(struct eth_hdr))) { - LWIP_ASSERT("Can't move over header in packet", 0); - pbuf_free(p); - p = NULL; - } else { - /* pass to IP layer */ - ip_input(p, netif); - } - break; - - case ETHTYPE_ARP: - /* pass p to ARP module */ - etharp_arp_input(netif, (struct eth_addr*)(netif->hwaddr), p); - break; - -#if PPPOE_SUPPORT - case ETHTYPE_PPPOEDISC: /* PPP Over Ethernet Discovery Stage */ - pppoe_disc_input(netif, p); - break; - - case ETHTYPE_PPPOE: /* PPP Over Ethernet Session Stage */ - pppoe_data_input(netif, p); - break; -#endif /* PPPOE_SUPPORT */ - - default: - pbuf_free(p); - p = NULL; - break; - } - - return ERR_OK; /* return value ignored */ -} -#endif /* LWIP_ARP */ - /** * The main lwIP thread. This thread has exclusive access to lwIP core functions * (unless access to them is not locked). Other threads communicate with this diff --git a/src/include/netif/etharp.h b/src/include/netif/etharp.h index dfe44019..e5d9e15d 100644 --- a/src/include/netif/etharp.h +++ b/src/include/netif/etharp.h @@ -152,6 +152,8 @@ err_t etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr) err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q); err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr); +err_t ethernet_input(struct pbuf *p, struct netif *netif); + #if LWIP_AUTOIP err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, const struct eth_addr *ethdst_addr, diff --git a/src/netif/etharp.c b/src/netif/etharp.c index f611c3ea..77fd2eeb 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -1084,4 +1084,63 @@ etharp_request(struct netif *netif, struct ip_addr *ipaddr) ipaddr, ARP_REQUEST); } +/** + * Process received ethernet frames. Using this function instead of directly + * calling ip_input and passing ARP frames through etharp in ethernetif_input, + * the ARP cache is protected from concurrent access. + * + * @param p the recevied packet, p->payload pointing to the ethernet header + * @param netif the network interface on which the packet was received + */ +err_t +ethernet_input(struct pbuf *p, struct netif *netif) +{ + struct eth_hdr* ethhdr; + + /* points to packet payload, which starts with an Ethernet header */ + ethhdr = p->payload; + + switch (htons(ethhdr->type)) { + /* IP packet? */ + case ETHTYPE_IP: +#if ETHARP_TRUST_IP_MAC + /* update ARP table */ + etharp_ip_input(netif, p); +#endif /* ETHARP_TRUST_IP_MAC */ + /* skip Ethernet header */ + if(pbuf_header(p, -(s16_t)sizeof(struct eth_hdr))) { + LWIP_ASSERT("Can't move over header in packet", 0); + pbuf_free(p); + p = NULL; + } else { + /* pass to IP layer */ + ip_input(p, netif); + } + break; + + case ETHTYPE_ARP: + /* pass p to ARP module */ + etharp_arp_input(netif, (struct eth_addr*)(netif->hwaddr), p); + break; + +#if PPPOE_SUPPORT + case ETHTYPE_PPPOEDISC: /* PPP Over Ethernet Discovery Stage */ + pppoe_disc_input(netif, p); + break; + + case ETHTYPE_PPPOE: /* PPP Over Ethernet Session Stage */ + pppoe_data_input(netif, p); + break; +#endif /* PPPOE_SUPPORT */ + + default: + pbuf_free(p); + p = NULL; + break; + } + + /* This means the pbuf is freed or consumed, + so the caller doesn't have to free it again */ + return ERR_OK; +} #endif /* LWIP_ARP */