diff --git a/CHANGELOG b/CHANGELOG index 3d147823..69d2110b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,10 @@ HISTORY ++ New features: + 2007-06-21 Simon Goldschmidt + * etharp.h, etharp.c: Combined etharp_request with etharp_raw for both + LWIP_AUTOIP =0 and =1 to remove redundant code. + 2007-06-21 Simon Goldschmidt * mem.c, memp.c, mem.h, memp.h, opt.h: task #6863: Introduced the option MEM_USE_POOLS to use 4 pools with different sized elements instead of a diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 0fd1d20a..fe8bbabe 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -216,51 +216,46 @@ #define ARP_TABLE_SIZE 10 #endif -/** - * If enabled, outgoing packets are queued during hardware address +/** If enabled, outgoing packets are queued during hardware address * resolution. - * - * This feature has not stabilized yet. Single-packet queueing is - * believed to be stable, multi-packet queueing is believed to - * clash with the TCP segment queueing. - * - * As multi-packet-queueing is currently disabled, enabling this - * _should_ work, but we need your testing feedback on lwip-users. - * */ #ifndef ARP_QUEUEING #define ARP_QUEUEING 1 #endif -/* If enabled, incoming IP packets cause the ARP table to be updated +/** If enabled, incoming IP packets cause the ARP table to be updated * with the source MAC and IP addresses supplied in the packet. You may * want to disable this if you do not trust LAN peers to have the * correct addresses, or as a limited approach to attempt to handle * spoofing. If disabled, lwIP will need to make a new ARP request if * the peer is not already in the ARP table, adding a little latency. */ - #ifndef ETHARP_TRUST_IP_MAC #define ETHARP_TRUST_IP_MAC 1 #endif -/* If enabled, allow to do ARP processing for incoming packets inside network driver, before process packets using the tcpip_input. */ +/** If enabled, allow to do ARP processing for incoming packets inside network + * driver, before process packets using the tcpip_input. + */ #ifndef ETHARP_TCPIP_INPUT #define ETHARP_TCPIP_INPUT 1 #endif -/* If enabled, allow to do ARP processing for incoming packets inside tcpip_thread, using the tcpip_ethinput (and not tcpip_input). - The aim is to protect ARP layer against concurrent access. Older ports have to be update to use tcpip_ethinput. */ +/** If enabled, allow to do ARP processing for incoming packets inside tcpip_thread, + * using the tcpip_ethinput (and not tcpip_input). + * The aim is to protect ARP layer against concurrent access. Older ports have + * to be update to use tcpip_ethinput. + */ #ifndef ETHARP_TCPIP_ETHINPUT #define ETHARP_TCPIP_ETHINPUT 1 #endif -/* This option is deprecated */ +/** This option is deprecated */ #ifdef ETHARP_QUEUE_FIRST #error ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h. #endif -/* This option is removed to comply with the ARP standard */ +/** This option is removed to comply with the ARP standard */ #ifdef ETHARP_ALWAYS_INSERT #error ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h. #endif diff --git a/src/include/netif/etharp.h b/src/include/netif/etharp.h index 1f151c6f..481471a9 100644 --- a/src/include/netif/etharp.h +++ b/src/include/netif/etharp.h @@ -148,10 +148,11 @@ 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); #if LWIP_AUTOIP -err_t etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *ethdst_addr, - struct eth_addr *hwsrc_addr, struct ip_addr *ipsrc_addr, - struct eth_addr *hwdst_addr, struct ip_addr *ipdst_addr, - unsigned short int opcode); +err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, + const struct eth_addr *ethdst_addr, + const struct eth_addr *hwsrc_addr, const struct ip_addr *ipsrc_addr, + const struct eth_addr *hwdst_addr, const struct ip_addr *ipdst_addr, + const u16_t opcode); #endif /* LWIP_AUTOIP */ #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0) diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 3c02df14..52c15bab 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -103,6 +103,7 @@ struct etharp_entry { }; static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; +static const struct eth_addr ethzero = {{0,0,0,0,0,0}}; static struct etharp_entry arp_table[ARP_TABLE_SIZE]; static u8_t etharp_cached_entry = 0; @@ -927,43 +928,29 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q) return result; } -#if LWIP_AUTOIP /** - * Send an ARP request packet asking for ipaddr. + * Send a raw ARP packet (opcode and all addresses can be modified) * - * @param netif the lwip network interface on which to send the request - * @param ipaddr the IP address for which to ask - * @return ERR_OK if the request has been sent + * @param netif the lwip network interface on which to send the ARP packet + * @param ethsrc_addr the source MAC address for the ethernet header + * @param ethdst_addr the destination MAC address for the ethernet header + * @param hwsrc_addr the source MAC address for the ARP protocol header + * @param ipsrc_addr the source IP address for the ARP protocol header + * @param hwdst_addr the destination MAC address for the ARP protocol header + * @param ipdst_addr the destination IP address for the ARP protocol header + * @param opcode the type of the ARP packet + * @return ERR_OK if the ARP packet has been sent * any other err_t on failure */ +#if !LWIP_AUTOIP +static +#endif /* LWIP_AUTOIP */ err_t -etharp_request(struct netif *netif, struct ip_addr *ipaddr) -{ - struct eth_addr eth_addr_bc, eth_addr_zero; - u8_t k = ETHARP_HWADDR_LEN; - - LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!", - (netif->hwaddr_len == ETHARP_HWADDR_LEN)); - while(k > 0) { - k--; - eth_addr_bc.addr[k] = 0xFF; - eth_addr_zero.addr[k] = 0x00; - } - - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n")); - return etharp_raw( netif, - (struct eth_addr *)netif->hwaddr, - ð_addr_bc, - (struct eth_addr *)netif->hwaddr, - &netif->ip_addr, - ð_addr_zero, - ipaddr, - ARP_REQUEST - ); -} - -err_t -etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *ethdst_addr, struct eth_addr *hwsrc_addr, struct ip_addr *ipsrc_addr, struct eth_addr *hwdst_addr, struct ip_addr *ipdst_addr, unsigned short int OpCode) +etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, + const struct eth_addr *ethdst_addr, + const struct eth_addr *hwsrc_addr, const struct ip_addr *ipsrc_addr, + const struct eth_addr *hwdst_addr, const struct ip_addr *ipdst_addr, + const u16_t opcode) { struct pbuf *p; err_t result = ERR_OK; @@ -975,11 +962,10 @@ etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *e if (p != NULL) { struct etharp_hdr *hdr = p->payload; LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n")); - hdr->opcode = htons(OpCode); - k = ETHARP_HWADDR_LEN; + hdr->opcode = htons(opcode); LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!", (netif->hwaddr_len == ETHARP_HWADDR_LEN)); - + k = ETHARP_HWADDR_LEN; /* Write the ARP MAC-Addresses */ while(k > 0) { k--; @@ -1017,7 +1003,7 @@ etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *e return result; } -#else + /** * Send an ARP request packet asking for ipaddr. * @@ -1029,54 +1015,15 @@ etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *e err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr) { - struct pbuf *p; - struct eth_addr * srcaddr = (struct eth_addr *)netif->hwaddr; - err_t result = ERR_OK; - u8_t k; /* ARP entry index */ - - /* allocate a pbuf for the outgoing ARP request packet */ - p = pbuf_alloc(PBUF_LINK, sizeof(struct etharp_hdr), PBUF_RAM); - /* could allocate a pbuf for an ARP request? */ - if (p != NULL) { - struct etharp_hdr *hdr = p->payload; - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n")); - hdr->opcode = htons(ARP_REQUEST); - LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!", - (netif->hwaddr_len == ETHARP_HWADDR_LEN)); - k = ETHARP_HWADDR_LEN; - while(k > 0) { - k--; - hdr->shwaddr.addr[k] = srcaddr->addr[k]; - /* the hardware address is what we ask for, in - * a request it is a don't-care value, we use zeroes */ - hdr->dhwaddr.addr[k] = 0x00; - } - hdr->dipaddr = *(struct ip_addr2 *)ipaddr; - hdr->sipaddr = *(struct ip_addr2 *)&netif->ip_addr; - - hdr->hwtype = htons(HWTYPE_ETHERNET); - ARPH_HWLEN_SET(hdr, netif->hwaddr_len); - - hdr->proto = htons(ETHTYPE_IP); - ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr)); - k = ETHARP_HWADDR_LEN; - while(k > 0) { - k--; - /* broadcast to all network interfaces on the local network */ - hdr->ethhdr.dest.addr[k] = 0xff; - hdr->ethhdr.src.addr[k] = srcaddr->addr[k]; - } - hdr->ethhdr.type = htons(ETHTYPE_ARP); - /* send ARP query */ - result = netif->linkoutput(netif, p); - /* free ARP query packet */ - pbuf_free(p); - p = NULL; - /* could not allocate pbuf for ARP request */ - } else { - result = ERR_MEM; - LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 2, ("etharp_request: could not allocate pbuf for ARP request.\n")); - } - return result; + LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n")); + return etharp_raw( netif, + (struct eth_addr *)netif->hwaddr, + ðbroadcast, + (struct eth_addr *)netif->hwaddr, + &netif->ip_addr, + ðzero, + ipaddr, + ARP_REQUEST + ); } -#endif /* LWIP_AUTOIP */ +