mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-18 20:10:53 +00:00
Changed etharp to use a defined hardware address length of 6 to avoid loading netif->hwaddr_len every time (since this file is only used for ethernet and struct eth_addr already had a defined length of 6).
This commit is contained in:
parent
ec7333d406
commit
d3f0a3211d
@ -19,6 +19,11 @@ HISTORY
|
|||||||
|
|
||||||
++ New features:
|
++ New features:
|
||||||
|
|
||||||
|
2007-06-18 Simon Goldschmidt
|
||||||
|
* etharp.c, etharp.h: Changed etharp to use a defined hardware address length
|
||||||
|
of 6 to avoid loading netif->hwaddr_len every time (since this file is only
|
||||||
|
used for ethernet and struct eth_addr already had a defined length of 6).
|
||||||
|
|
||||||
2007-06-17 Simon Goldschmidt
|
2007-06-17 Simon Goldschmidt
|
||||||
* sockets.c, sockets.h: Implemented socket options SO_NO_CHECK for UDP sockets
|
* sockets.c, sockets.h: Implemented socket options SO_NO_CHECK for UDP sockets
|
||||||
to disable UDP checksum generation on transmit.
|
to disable UDP checksum generation on transmit.
|
||||||
|
@ -49,12 +49,16 @@ extern "C" {
|
|||||||
#define ETH_PAD_SIZE 0
|
#define ETH_PAD_SIZE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ETHARP_HWADDR_LEN
|
||||||
|
#define ETHARP_HWADDR_LEN 6
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
# include "arch/bpstruct.h"
|
# include "arch/bpstruct.h"
|
||||||
#endif
|
#endif
|
||||||
PACK_STRUCT_BEGIN
|
PACK_STRUCT_BEGIN
|
||||||
struct eth_addr {
|
struct eth_addr {
|
||||||
PACK_STRUCT_FIELD(u8_t addr[6]);
|
PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
|
||||||
} PACK_STRUCT_STRUCT;
|
} PACK_STRUCT_STRUCT;
|
||||||
PACK_STRUCT_END
|
PACK_STRUCT_END
|
||||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||||
@ -150,7 +154,7 @@ err_t etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_a
|
|||||||
unsigned short int opcode);
|
unsigned short int opcode);
|
||||||
#endif /* LWIP_AUTOIP */
|
#endif /* LWIP_AUTOIP */
|
||||||
|
|
||||||
#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, 6) == 0)
|
#define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -403,7 +403,7 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
|
|||||||
s8_t i;
|
s8_t i;
|
||||||
u8_t k;
|
u8_t k;
|
||||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 3, ("update_arp_entry()\n"));
|
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 3, ("update_arp_entry()\n"));
|
||||||
LWIP_ASSERT("netif->hwaddr_len == 6", netif->hwaddr_len == 6);
|
LWIP_ASSERT("netif->hwaddr_len == ETHARP_HWADDR_LEN", netif->hwaddr_len == ETHARP_HWADDR_LEN);
|
||||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F" - %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F"\n",
|
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F" - %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F"\n",
|
||||||
ip4_addr1(ipaddr), ip4_addr2(ipaddr), ip4_addr3(ipaddr), ip4_addr4(ipaddr),
|
ip4_addr1(ipaddr), ip4_addr2(ipaddr), ip4_addr3(ipaddr), ip4_addr4(ipaddr),
|
||||||
ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2],
|
ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2],
|
||||||
@ -431,15 +431,15 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
|
|||||||
|
|
||||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: updating stable entry %"S16_F"\n", (s16_t)i));
|
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: updating stable entry %"S16_F"\n", (s16_t)i));
|
||||||
/* update address */
|
/* update address */
|
||||||
k = netif->hwaddr_len;
|
k = ETHARP_HWADDR_LEN;
|
||||||
while (k > 0) {
|
while (k > 0) {
|
||||||
k--;
|
k--;
|
||||||
arp_table[i].ethaddr.addr[k] = ethaddr->addr[k];
|
arp_table[i].ethaddr.addr[k] = ethaddr->addr[k];
|
||||||
}
|
}
|
||||||
/* reset time stamp */
|
/* reset time stamp */
|
||||||
arp_table[i].ctime = 0;
|
arp_table[i].ctime = 0;
|
||||||
/* this is where we will send out queued packets! */
|
|
||||||
#if ARP_QUEUEING
|
#if ARP_QUEUEING
|
||||||
|
/* this is where we will send out queued packets! */
|
||||||
while (arp_table[i].q != NULL) {
|
while (arp_table[i].q != NULL) {
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
struct eth_hdr *ethhdr;
|
struct eth_hdr *ethhdr;
|
||||||
@ -454,7 +454,7 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
|
|||||||
/* Ethernet header */
|
/* Ethernet header */
|
||||||
ethhdr = p->payload;
|
ethhdr = p->payload;
|
||||||
/* fill-in Ethernet header */
|
/* fill-in Ethernet header */
|
||||||
k = netif->hwaddr_len;
|
k = ETHARP_HWADDR_LEN;
|
||||||
while(k > 0) {
|
while(k > 0) {
|
||||||
k--;
|
k--;
|
||||||
ethhdr->dest.addr[k] = ethaddr->addr[k];
|
ethhdr->dest.addr[k] = ethaddr->addr[k];
|
||||||
@ -620,7 +620,9 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
|||||||
hdr->dipaddr = hdr->sipaddr;
|
hdr->dipaddr = hdr->sipaddr;
|
||||||
hdr->sipaddr = *(struct ip_addr2 *)&netif->ip_addr;
|
hdr->sipaddr = *(struct ip_addr2 *)&netif->ip_addr;
|
||||||
|
|
||||||
i = netif->hwaddr_len;
|
LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!",
|
||||||
|
(netif->hwaddr_len == ETHARP_HWADDR_LEN));
|
||||||
|
i = ETHARP_HWADDR_LEN;
|
||||||
while(i > 0) {
|
while(i > 0) {
|
||||||
i--;
|
i--;
|
||||||
hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i];
|
hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i];
|
||||||
@ -743,7 +745,9 @@ etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr)
|
|||||||
/* obtain source Ethernet address of the given interface */
|
/* obtain source Ethernet address of the given interface */
|
||||||
srcaddr = (struct eth_addr *)netif->hwaddr;
|
srcaddr = (struct eth_addr *)netif->hwaddr;
|
||||||
ethhdr = q->payload;
|
ethhdr = q->payload;
|
||||||
i = netif->hwaddr_len;
|
LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!",
|
||||||
|
(netif->hwaddr_len == ETHARP_HWADDR_LEN));
|
||||||
|
i = ETHARP_HWADDR_LEN;
|
||||||
while(i > 0) {
|
while(i > 0) {
|
||||||
i--;
|
i--;
|
||||||
ethhdr->dest.addr[i] = dest->addr[i];
|
ethhdr->dest.addr[i] = dest->addr[i];
|
||||||
@ -807,8 +811,7 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
i = find_entry(ipaddr, ETHARP_TRY_HARD);
|
i = find_entry(ipaddr, ETHARP_TRY_HARD);
|
||||||
|
|
||||||
/* could not find or create entry? */
|
/* could not find or create entry? */
|
||||||
if (i < 0)
|
if (i < 0) {
|
||||||
{
|
|
||||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not create ARP entry\n"));
|
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not create ARP entry\n"));
|
||||||
if (q)
|
if (q)
|
||||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: packet dropped\n"));
|
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: packet dropped\n"));
|
||||||
@ -838,7 +841,9 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
/* we have a valid IP->Ethernet address mapping,
|
/* we have a valid IP->Ethernet address mapping,
|
||||||
* fill in the Ethernet header for the outgoing packet */
|
* fill in the Ethernet header for the outgoing packet */
|
||||||
struct eth_hdr *ethhdr = q->payload;
|
struct eth_hdr *ethhdr = q->payload;
|
||||||
k = netif->hwaddr_len;
|
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) {
|
while(k > 0) {
|
||||||
k--;
|
k--;
|
||||||
ethhdr->dest.addr[k] = arp_table[i].ethaddr.addr[k];
|
ethhdr->dest.addr[k] = arp_table[i].ethaddr.addr[k];
|
||||||
@ -859,8 +864,6 @@ etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
p = q;
|
p = q;
|
||||||
while (p) {
|
while (p) {
|
||||||
LWIP_ASSERT("no packet queues allowed!", (p->len == p->tot_len) || (p->next == 0));
|
LWIP_ASSERT("no packet queues allowed!", (p->len == p->tot_len) || (p->next == 0));
|
||||||
if(p->len == p->tot_len) {
|
|
||||||
}
|
|
||||||
if(p->flags != PBUF_FLAG_ROM) {
|
if(p->flags != PBUF_FLAG_ROM) {
|
||||||
copy_needed = 1;
|
copy_needed = 1;
|
||||||
break;
|
break;
|
||||||
@ -931,7 +934,10 @@ err_t
|
|||||||
etharp_request(struct netif *netif, struct ip_addr *ipaddr)
|
etharp_request(struct netif *netif, struct ip_addr *ipaddr)
|
||||||
{
|
{
|
||||||
struct eth_addr eth_addr_bc, eth_addr_zero;
|
struct eth_addr eth_addr_bc, eth_addr_zero;
|
||||||
u8_t k = netif->hwaddr_len;
|
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) {
|
while(k > 0) {
|
||||||
k--;
|
k--;
|
||||||
eth_addr_bc.addr[k] = 0xFF;
|
eth_addr_bc.addr[k] = 0xFF;
|
||||||
@ -964,7 +970,9 @@ etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *e
|
|||||||
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 = netif->hwaddr_len;
|
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));
|
||||||
|
|
||||||
/* Write the ARP MAC-Addresses */
|
/* Write the ARP MAC-Addresses */
|
||||||
while(k > 0) {
|
while(k > 0) {
|
||||||
@ -980,7 +988,7 @@ etharp_raw(struct netif *netif, struct eth_addr *ethsrc_addr, struct eth_addr *e
|
|||||||
|
|
||||||
hdr->proto = htons(ETHTYPE_IP);
|
hdr->proto = htons(ETHTYPE_IP);
|
||||||
ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr));
|
ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr));
|
||||||
k = netif->hwaddr_len;
|
k = ETHARP_HWADDR_LEN;
|
||||||
|
|
||||||
/* Write the Ethernet MAC-Addresses */
|
/* Write the Ethernet MAC-Addresses */
|
||||||
while(k > 0) {
|
while(k > 0) {
|
||||||
@ -1027,7 +1035,9 @@ etharp_request(struct netif *netif, struct ip_addr *ipaddr)
|
|||||||
struct etharp_hdr *hdr = p->payload;
|
struct etharp_hdr *hdr = p->payload;
|
||||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n"));
|
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n"));
|
||||||
hdr->opcode = htons(ARP_REQUEST);
|
hdr->opcode = htons(ARP_REQUEST);
|
||||||
k = netif->hwaddr_len;
|
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) {
|
while(k > 0) {
|
||||||
k--;
|
k--;
|
||||||
hdr->shwaddr.addr[k] = srcaddr->addr[k];
|
hdr->shwaddr.addr[k] = srcaddr->addr[k];
|
||||||
@ -1043,7 +1053,7 @@ etharp_request(struct netif *netif, struct ip_addr *ipaddr)
|
|||||||
|
|
||||||
hdr->proto = htons(ETHTYPE_IP);
|
hdr->proto = htons(ETHTYPE_IP);
|
||||||
ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr));
|
ARPH_PROTOLEN_SET(hdr, sizeof(struct ip_addr));
|
||||||
k = netif->hwaddr_len;
|
k = ETHARP_HWADDR_LEN;
|
||||||
while(k > 0) {
|
while(k > 0) {
|
||||||
k--;
|
k--;
|
||||||
/* broadcast to all network interfaces on the local network */
|
/* broadcast to all network interfaces on the local network */
|
||||||
|
Loading…
Reference in New Issue
Block a user