mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-01 04:12:07 +00:00
Combined etharp_request with etharp_raw for both LWIP_AUTOIP =0 and =1 to remove redundant code.
This commit is contained in:
parent
4848de3a8e
commit
b51d1b79a3
@ -19,6 +19,10 @@ HISTORY
|
|||||||
|
|
||||||
++ New features:
|
++ 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
|
2007-06-21 Simon Goldschmidt
|
||||||
* mem.c, memp.c, mem.h, memp.h, opt.h: task #6863: Introduced the option
|
* 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
|
MEM_USE_POOLS to use 4 pools with different sized elements instead of a
|
||||||
|
@ -216,51 +216,46 @@
|
|||||||
#define ARP_TABLE_SIZE 10
|
#define ARP_TABLE_SIZE 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/** If enabled, outgoing packets are queued during hardware address
|
||||||
* If enabled, outgoing packets are queued during hardware address
|
|
||||||
* resolution.
|
* 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
|
#ifndef ARP_QUEUEING
|
||||||
#define ARP_QUEUEING 1
|
#define ARP_QUEUEING 1
|
||||||
#endif
|
#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
|
* 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
|
* 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
|
* correct addresses, or as a limited approach to attempt to handle
|
||||||
* spoofing. If disabled, lwIP will need to make a new ARP request if
|
* 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.
|
* the peer is not already in the ARP table, adding a little latency.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ETHARP_TRUST_IP_MAC
|
#ifndef ETHARP_TRUST_IP_MAC
|
||||||
#define ETHARP_TRUST_IP_MAC 1
|
#define ETHARP_TRUST_IP_MAC 1
|
||||||
#endif
|
#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
|
#ifndef ETHARP_TCPIP_INPUT
|
||||||
#define ETHARP_TCPIP_INPUT 1
|
#define ETHARP_TCPIP_INPUT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If enabled, allow to do ARP processing for incoming packets inside tcpip_thread, using the tcpip_ethinput (and not tcpip_input).
|
/** If enabled, allow to do ARP processing for incoming packets inside tcpip_thread,
|
||||||
The aim is to protect ARP layer against concurrent access. Older ports have to be update to use tcpip_ethinput. */
|
* 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
|
#ifndef ETHARP_TCPIP_ETHINPUT
|
||||||
#define ETHARP_TCPIP_ETHINPUT 1
|
#define ETHARP_TCPIP_ETHINPUT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This option is deprecated */
|
/** This option is deprecated */
|
||||||
#ifdef ETHARP_QUEUE_FIRST
|
#ifdef ETHARP_QUEUE_FIRST
|
||||||
#error ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h.
|
#error ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h.
|
||||||
#endif
|
#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
|
#ifdef ETHARP_ALWAYS_INSERT
|
||||||
#error ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h.
|
#error ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h.
|
||||||
#endif
|
#endif
|
||||||
|
@ -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);
|
err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr);
|
||||||
|
|
||||||
#if LWIP_AUTOIP
|
#if LWIP_AUTOIP
|
||||||
err_t etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *ethdst_addr,
|
err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
|
||||||
struct eth_addr *hwsrc_addr, struct ip_addr *ipsrc_addr,
|
const struct eth_addr *ethdst_addr,
|
||||||
struct eth_addr *hwdst_addr, struct ip_addr *ipdst_addr,
|
const struct eth_addr *hwsrc_addr, const struct ip_addr *ipsrc_addr,
|
||||||
unsigned short int opcode);
|
const struct eth_addr *hwdst_addr, const struct ip_addr *ipdst_addr,
|
||||||
|
const u16_t opcode);
|
||||||
#endif /* LWIP_AUTOIP */
|
#endif /* LWIP_AUTOIP */
|
||||||
|
|
||||||
#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
|
#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
|
||||||
|
@ -103,6 +103,7 @@ struct etharp_entry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
|
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 struct etharp_entry arp_table[ARP_TABLE_SIZE];
|
||||||
static u8_t etharp_cached_entry = 0;
|
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;
|
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 netif the lwip network interface on which to send the ARP packet
|
||||||
* @param ipaddr the IP address for which to ask
|
* @param ethsrc_addr the source MAC address for the ethernet header
|
||||||
* @return ERR_OK if the request has been sent
|
* @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
|
* any other err_t on failure
|
||||||
*/
|
*/
|
||||||
|
#if !LWIP_AUTOIP
|
||||||
|
static
|
||||||
|
#endif /* LWIP_AUTOIP */
|
||||||
err_t
|
err_t
|
||||||
etharp_request(struct netif *netif, struct ip_addr *ipaddr)
|
etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
|
||||||
{
|
const struct eth_addr *ethdst_addr,
|
||||||
struct eth_addr eth_addr_bc, eth_addr_zero;
|
const struct eth_addr *hwsrc_addr, const struct ip_addr *ipsrc_addr,
|
||||||
u8_t k = ETHARP_HWADDR_LEN;
|
const struct eth_addr *hwdst_addr, const struct ip_addr *ipdst_addr,
|
||||||
|
const u16_t opcode)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
err_t result = ERR_OK;
|
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) {
|
if (p != NULL) {
|
||||||
struct etharp_hdr *hdr = p->payload;
|
struct etharp_hdr *hdr = p->payload;
|
||||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n"));
|
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n"));
|
||||||
hdr->opcode = htons(OpCode);
|
hdr->opcode = htons(opcode);
|
||||||
k = ETHARP_HWADDR_LEN;
|
|
||||||
LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!",
|
LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!",
|
||||||
(netif->hwaddr_len == ETHARP_HWADDR_LEN));
|
(netif->hwaddr_len == ETHARP_HWADDR_LEN));
|
||||||
|
k = ETHARP_HWADDR_LEN;
|
||||||
/* Write the ARP MAC-Addresses */
|
/* Write the ARP MAC-Addresses */
|
||||||
while(k > 0) {
|
while(k > 0) {
|
||||||
k--;
|
k--;
|
||||||
@ -1017,7 +1003,7 @@ etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *e
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
/**
|
/**
|
||||||
* Send an ARP request packet asking for ipaddr.
|
* 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
|
err_t
|
||||||
etharp_request(struct netif *netif, struct ip_addr *ipaddr)
|
etharp_request(struct netif *netif, struct ip_addr *ipaddr)
|
||||||
{
|
{
|
||||||
struct pbuf *p;
|
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n"));
|
||||||
struct eth_addr * srcaddr = (struct eth_addr *)netif->hwaddr;
|
return etharp_raw( netif,
|
||||||
err_t result = ERR_OK;
|
(struct eth_addr *)netif->hwaddr,
|
||||||
u8_t k; /* ARP entry index */
|
ðbroadcast,
|
||||||
|
(struct eth_addr *)netif->hwaddr,
|
||||||
/* allocate a pbuf for the outgoing ARP request packet */
|
&netif->ip_addr,
|
||||||
p = pbuf_alloc(PBUF_LINK, sizeof(struct etharp_hdr), PBUF_RAM);
|
ðzero,
|
||||||
/* could allocate a pbuf for an ARP request? */
|
ipaddr,
|
||||||
if (p != NULL) {
|
ARP_REQUEST
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
#endif /* LWIP_AUTOIP */
|
|
||||||
|
Loading…
Reference in New Issue
Block a user