diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index 277b7b6c..a4bced37 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -199,39 +199,6 @@ static err_t e1000if_output(struct netif* netif, struct pbuf* p) return ERR_OK; } -static void e1000if_input(struct netif* netif, struct pbuf* p) -{ - struct eth_hdr *ethhdr; - err_t err; - - /* points to packet payload, which starts with an Ethernet header */ - ethhdr = p->payload; - - switch (htons(ethhdr->type)) { - /* IP or ARP packet? */ - case ETHTYPE_ARP: - case ETHTYPE_IP: -#if PPPOE_SUPPORT - /* PPPoE packet? */ - case ETHTYPE_PPPOEDISC: - case ETHTYPE_PPPOE: -#endif /* PPPOE_SUPPORT */ - /* - * This function is called in the context of the tcpip thread. - * Therefore, we are able to call directly the input functions. - */ - err = ethernet_input(p, netif); - if (err != ERR_OK) { - LWIP_DEBUGF(NETIF_DEBUG, ("e1000if_input: ethernet_input failed %d\n", err)); - } - break; - default: - LWIP_DEBUGF(NETIF_DEBUG, ("e1000if_input: invalid ethernet header 0x%x\n", htons(ethhdr->type))); - pbuf_free(p); - break; - } -} - static void e1000_rx_inthandler(struct netif* netif) { e1000if_t* e1000if = netif->state; @@ -268,7 +235,7 @@ static void e1000_rx_inthandler(struct netif* netif) LINK_STATS_INC(link.recv); // forward packet to LwIP - e1000if_input(netif, p); + netif->input(p, netif); } else { LWIP_DEBUGF(NETIF_DEBUG, ("e1000if_rx_inthandler: not enough memory!\n")); LINK_STATS_INC(link.memerr); diff --git a/drivers/net/mmnif.c b/drivers/net/mmnif.c index e6142260..8cf69876 100644 --- a/drivers/net/mmnif.c +++ b/drivers/net/mmnif.c @@ -1175,7 +1175,7 @@ anotherpacket: * This function is called in the context of the tcpip thread. * Therefore, we are able to call directly the input functions. */ - if ((err = ip_input(p, mmnif_dev)) != ERR_OK) + if ((err = mmnif_dev->input(p, mmnif_dev)) != ERR_OK) { DEBUGPRINTF("mmnif_rx: IP input error\n"); pbuf_free(p); diff --git a/drivers/net/rckemac.c b/drivers/net/rckemac.c index bafacfe4..16f42c09 100644 --- a/drivers/net/rckemac.c +++ b/drivers/net/rckemac.c @@ -334,39 +334,6 @@ again: return ERR_OK; } -static void rckemacif_input(struct netif* netif, struct pbuf* p) -{ - struct eth_hdr *ethhdr; - err_t err; - - /* points to packet payload, which starts with an Ethernet header */ - ethhdr = (struct eth_hdr *) p->payload; - - switch (htons(ethhdr->type)) { - /* IP or ARP packet? */ - case ETHTYPE_ARP: - case ETHTYPE_IP: -#if PPPOE_SUPPORT - /* PPPoE packet? */ - case ETHTYPE_PPPOEDISC: - case ETHTYPE_PPPOE: -#endif /* PPPOE_SUPPORT */ - /* - * This function is called in the context of the tcpip thread. - * Therefore, we are able to call directly the input functions. - */ - err = ethernet_input(p, netif); - if (err != ERR_OK) { - LWIP_DEBUGF(NETIF_DEBUG, ("rckemacif_input: ethernet_input failed %d\n", err)); - } - break; - default: - LWIP_DEBUGF(NETIF_DEBUG, ("rckemacif_input: invalid ethernet header 0x%x\n", htons(ethhdr->type))); - pbuf_free(p); - break; - } -} - static void rckemacif_rx_handler(struct netif* netif, unsigned int write_offset) { rckemacif_t* rckemacif = netif->state; @@ -501,7 +468,7 @@ rxDone: rckemacif->rx_read_offset = read_offset; if (p) { - rckemacif_input(netif, p); + netif->input(p, netif); p = NULL; } diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c index 4ac26dfe..051c30af 100644 --- a/drivers/net/rtl8139.c +++ b/drivers/net/rtl8139.c @@ -133,39 +133,6 @@ static err_t rtl8139if_output(struct netif* netif, struct pbuf* p) return ERR_OK; } -static void rtl8139if_input(struct netif* netif, struct pbuf* p) -{ - struct eth_hdr *ethhdr; - err_t err; - - /* points to packet payload, which starts with an Ethernet header */ - ethhdr = p->payload; - - switch (htons(ethhdr->type)) { - /* IP or ARP packet? */ - case ETHTYPE_ARP: - case ETHTYPE_IP: -#if PPPOE_SUPPORT - /* PPPoE packet? */ - case ETHTYPE_PPPOEDISC: - case ETHTYPE_PPPOE: -#endif /* PPPOE_SUPPORT */ - /* - * This function is called in the context of the tcpip thread. - * Therefore, we are able to call directly the input functions. - */ - err = ethernet_input(p, netif); - if (err != ERR_OK) { - LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_input: ethernet_input failed %d\n", err)); - } - break; - default: - LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139_input: invalid ethernet header 0x%x\n", htons(ethhdr->type))); - pbuf_free(p); - break; - } -} - static void rtl_rx_inthandler(struct netif* netif) { rtl1839if_t* rtl8139if = netif->state; @@ -205,7 +172,7 @@ static void rtl_rx_inthandler(struct netif* netif) LINK_STATS_INC(link.recv); // forward packet to LwIP - rtl8139if_input(netif, p); + netif->input(p, netif); } else { LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_rx_inthandler: not enough memory!\n")); rtl8139if->rx_pos += (rtl8139if->rx_pos + length) % RX_BUF_LEN; diff --git a/kernel/init.c b/kernel/init.c index af6e227b..c3f6d0e9 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -109,7 +109,9 @@ static int init_netifs(void) netif_set_default(&default_netif); netif_set_up(&default_netif); #else - if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rckemacif_init, tcpip_input)) != ERR_OK) { + /* Note: Our drivers guarantee that the input function will be called in the context of the tcpip thread. + * => Therefore, we are able to use ethernet_input instead of tcpip_input */ + if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rckemacif_init, ethernet_input)) != ERR_OK) { kprintf("Unable to add the network interface: err = %d\n", err); return -ENODEV; } @@ -133,15 +135,17 @@ static int init_netifs(void) * - ipaddr : the ip address wich should be used * - gw : the gateway wicht should be used * - mmnif_init : the initialization which has to be done in order to use our interface - * - ethernet_input : tells him that he should get ethernet input (inclusice ARP) + * - ip_input : tells him that he should use ip_input */ #if NO_SYS - netif_add(&mmnif_netif, &intra_ipaddr, &intra_netmask, &intra_gw, NULL, mmnif_init, ethernet_input); + netif_add(&mmnif_netif, &intra_ipaddr, &intra_netmask, &intra_gw, NULL, mmnif_init, ip_input); /* tell lwip all initialization is done and we want to set it ab */ netif_set_up(&mmnif_netif); #else - if ((err = netifapi_netif_add(&mmnif_netif, &intra_ipaddr, &intra_netmask, &intra_gw, NULL, mmnif_init, tcpip_input)) != ERR_OK) + /* Note: Our drivers guarantee that the input function will be called in the context of the tcpip thread. + * => Therefore, we are able to use ip_input instead of tcpip_input */ + if ((err = netifapi_netif_add(&mmnif_netif, &intra_ipaddr, &intra_netmask, &intra_gw, NULL, mmnif_init, ip_input)) != ERR_OK) { kprintf("Unable to add the intra network interface: err = %d\n", err); return -ENODEV; @@ -162,9 +166,11 @@ static int init_netifs(void) netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, ethernet_input); netif_set_default(&default_netif); #else - if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, tcpip_input)) == ERR_OK) + /* Note: Our drivers guarantee that the input function will be called in the context of the tcpip thread. + * => Therefore, we are able to use ethernet_input instead of tcpip_input */ + if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, ethernet_input)) == ERR_OK) goto success; - if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, e1000if_init, tcpip_input)) == ERR_OK) + if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, e1000if_init, ethernet_input)) == ERR_OK) goto success; kprintf("Unable to add the network interface: err = %d\n", err);