Skip to content

Commit

Permalink
Remove macros ipLOCAL_MAC_ADDRESS and ipLOCAL_IP_ADDRESS_POINTER (#1097)
Browse files Browse the repository at this point in the history
* remove deprecated ipLOCAL_MAC_ADDRESS

* remove ipLOCAL_IP_ADDRESS_POINTER

* remove xDefaultPartUDPPacketHeader

* Uncrustify: triggered by comment.

* switch remote to local address

* Address Review Comments

---------

Co-authored-by: GitHub Action <[email protected]>
Co-authored-by: Tony Josi <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent b72e2b6 commit 88e1475
Show file tree
Hide file tree
Showing 42 changed files with 169 additions and 674 deletions.
4 changes: 0 additions & 4 deletions source/FreeRTOS_DHCP.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,6 @@
EP_IPv4_SETTINGS.ulBroadcastAddress = EP_DHCPData.ulOfferedIPAddress | ~( EP_IPv4_SETTINGS.ulNetMask );
EP_DHCPData.eDHCPState = eLeasedAddress;

/* _HT_ This macro must be removed later.
* It is enough to set 'EP_IPv4_SETTINGS.ulIPAddress'. */
*ipLOCAL_IP_ADDRESS_POINTER = EP_IPv4_SETTINGS.ulIPAddress;

iptraceDHCP_SUCCEEDED( EP_DHCPData.ulOfferedIPAddress );

/* DHCP failed, the default configured IP-address will be used
Expand Down
4 changes: 0 additions & 4 deletions source/FreeRTOS_IP_Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,10 +951,6 @@ void prvProcessNetworkDownEvent( struct xNetworkInterface * pxInterface )
break;
}

#if ( ipconfigUSE_IPv4 != 0 )
*ipLOCAL_IP_ADDRESS_POINTER = pxEndPoint->ipv4_settings.ulIPAddress;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

/* DHCP or Router Advertisement are not enabled for this end-point.
* Perform any necessary 'network up' processing. */
vIPNetworkUpCalls( pxEndPoint );
Expand Down
3 changes: 1 addition & 2 deletions source/FreeRTOS_TCP_State_Handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,7 @@
#endif /* ipconfigSUPPORT_SELECT_FUNCTION */

/* And bind it to the same local port as its parent. */
/*TODO xAddress.sin_address.ulIP_IPv4 = *ipLOCAL_IP_ADDRESS_POINTER; */
xAddress.sin_port = FreeRTOS_htons( pxSocket->usLocalPort );
( void ) FreeRTOS_GetLocalAddress( pxSocket, &xAddress );

#if ( ipconfigTCP_HANG_PROTECTION == 1 )
{
Expand Down
1 change: 0 additions & 1 deletion source/FreeRTOS_TCP_Transmission_IPv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket,
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
/* The source MAC addresses is fixed to 'ipLOCAL_MAC_ADDRESS'. */
pvCopySource = pxNetworkBuffer->pxEndPoint->xMACAddress.ucBytes;
pvCopyDest = &pxEthernetHeader->xSourceAddress;
( void ) memcpy( pvCopyDest, pvCopySource, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
Expand Down
1 change: 0 additions & 1 deletion source/FreeRTOS_TCP_Transmission_IPv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket,
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
/* The source MAC addresses is fixed to 'ipLOCAL_MAC_ADDRESS'. */
pvCopySource = pxNetworkBuffer->pxEndPoint->xMACAddress.ucBytes;
pvCopyDest = &pxEthernetHeader->xSourceAddress;
( void ) memcpy( pvCopyDest, pvCopySource, ( size_t ) ipMAC_ADDRESS_LENGTH_BYTES );
Expand Down
26 changes: 0 additions & 26 deletions source/FreeRTOS_UDP_IP.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,32 +60,6 @@
#include "FreeRTOS_DNS.h"
#endif

/** @brief The expected IP version and header length coded into the IP header itself. */
#define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 )

/** @brief Part of the Ethernet and IP headers are always constant when sending an IPv4
* UDP packet. This array defines the constant parts, allowing this part of the
* packet to be filled in using a simple memcpy() instead of individual writes. */
/*lint -e708 (Info -- union initialization). */
UDPPacketHeader_t xDefaultPartUDPPacketHeader =
{
/* .ucBytes : */
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Ethernet source MAC address. */
0x08, 0x00, /* Ethernet frame type. */
ipIP_VERSION_AND_HEADER_LENGTH_BYTE, /* ucVersionHeaderLength. */
0x00, /* ucDifferentiatedServicesCode. */
0x00, 0x00, /* usLength. */
0x00, 0x00, /* usIdentification. */
0x00, 0x00, /* usFragmentOffset. */
ipconfigUDP_TIME_TO_LIVE, /* ucTimeToLive */
ipPROTOCOL_UDP, /* ucProtocol. */
0x00, 0x00, /* usHeaderChecksum. */
0x00, 0x00, 0x00, 0x00 /* Source IP address. */
}
};
/*-----------------------------------------------------------*/

/**
* @brief Process the generated UDP packet and do other checks before sending the
* packet such as ARP cache check and address resolution.
Expand Down
25 changes: 20 additions & 5 deletions source/FreeRTOS_UDP_IPv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
#if( ipconfigUSE_IPv4 != 0 )
/* *INDENT-ON* */

/** @brief The expected IP version and header length coded into the IP header itself. */
#define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 )

/*-----------------------------------------------------------*/

/**
Expand Down Expand Up @@ -117,6 +114,24 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor
{
if( eReturned == eARPCacheHit )
{
/* Part of the Ethernet and IP headers are always constant when sending an IPv4
* UDP packet. This array defines the constant parts, allowing this part of the
* packet to be filled in using a simple memcpy() instead of individual writes. */
static const uint8_t ucDefaultPartUDPPacketHeader[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Ethernet source MAC address. */
0x08, 0x00, /* Ethernet frame type. */
ipIPV4_VERSION_HEADER_LENGTH_MIN, /* ucVersionHeaderLength. */
0x00, /* ucDifferentiatedServicesCode. */
0x00, 0x00, /* usLength. */
0x00, 0x00, /* usIdentification. */
0x00, 0x00, /* usFragmentOffset. */
ipconfigUDP_TIME_TO_LIVE, /* ucTimeToLive */
ipPROTOCOL_UDP, /* ucProtocol. */
0x00, 0x00, /* usHeaderChecksum. */
0x00, 0x00, 0x00, 0x00 /* Source IP address. */
};

#if ( ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0 )
uint8_t ucSocketOptions;
#endif
Expand Down Expand Up @@ -175,10 +190,10 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor
* compliant with MISRA Rule 21.15. These should be
* optimized away.
*/
pvCopySource = xDefaultPartUDPPacketHeader.ucBytes;
pvCopySource = ucDefaultPartUDPPacketHeader;
/* The Ethernet source address is at offset 6. */
pvCopyDest = &pxNetworkBuffer->pucEthernetBuffer[ sizeof( MACAddress_t ) ];
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( xDefaultPartUDPPacketHeader ) );
( void ) memcpy( pvCopyDest, pvCopySource, sizeof( ucDefaultPartUDPPacketHeader ) );

#if ipconfigSUPPORT_OUTGOING_PINGS == 1
if( pxNetworkBuffer->usPort == ( uint16_t ) ipPACKET_CONTAINS_ICMP_DATA )
Expand Down
4 changes: 0 additions & 4 deletions source/FreeRTOS_UDP_IPv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@
#if( ipconfigUSE_IPv6 != 0 )
/* *INDENT-ON* */


/** @brief The expected IP version and header length coded into the IP header itself. */
#define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 )

/*-----------------------------------------------------------*/

/* _HT_ this is a temporary aid while testing. In case an end-0point is not found,
Expand Down
18 changes: 0 additions & 18 deletions source/include/FreeRTOS_ICMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,9 @@
#ifndef FREERTOS_ICMP_H
#define FREERTOS_ICMP_H

/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <string.h>

/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"
#include "FreeRTOS_ARP.h"
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_DHCP.h"
#include "NetworkInterface.h"
#include "NetworkBufferManagement.h"
#include "FreeRTOS_DNS.h"

/* *INDENT-OFF* */
#ifdef __cplusplus
Expand Down
19 changes: 0 additions & 19 deletions source/include/FreeRTOS_IP_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,6 @@ extern uint16_t usPacketIdentifier;
*/
extern List_t xBoundUDPSocketsList;

/**
* Define a default UDP packet header (declared in FreeRTOS_UDP_IP.c)
*/
typedef union xUDPPacketHeader
{
uint8_t ucBytes[ 24 ]; /**< Member: 8-bit array */
uint32_t ulWords[ 6 ]; /**< Member: 32-bit array */
} UDPPacketHeader_t;
extern UDPPacketHeader_t xDefaultPartUDPPacketHeader;


/* True when BufferAllocation_1.c was included, false for BufferAllocation_2.c */
extern const BaseType_t xBufferAllocFixedSize;

Expand All @@ -357,14 +346,6 @@ extern struct xNetworkInterface * pxNetworkInterfaces;
extern List_t xBoundTCPSocketsList;
#endif

/* The local IP address is accessed from within xDefaultPartUDPPacketHeader,
* rather than duplicated in its own variable. */
#define ipLOCAL_IP_ADDRESS_POINTER ( ( uint32_t * ) &( xDefaultPartUDPPacketHeader.ulWords[ 20U / sizeof( uint32_t ) ] ) )

/* The local MAC address is accessed from within xDefaultPartUDPPacketHeader,
* rather than duplicated in its own variable. */
#define ipLOCAL_MAC_ADDRESS ( xDefaultPartUDPPacketHeader.ucBytes )

/* ICMP packets are sent using the same function as UDP packets. The port
* number is used to distinguish between the two, as 0 is an invalid UDP port. */
#define ipPACKET_CONTAINS_ICMP_DATA ( 0 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ static void prvSetMACAddress( void )

/* Using local variables to make sure the right alignment is used. The MAC
* address is 6 bytes, hence the copy of 4 bytes followed by 2 bytes. */
memcpy( ( void * ) &ucMACLow, ( void * ) ipLOCAL_MAC_ADDRESS, 4 );
memcpy( ( void * ) &ucMACHigh, ( void * ) ( ipLOCAL_MAC_ADDRESS + 4 ), 2 );
memcpy( ( void * ) &ucMACLow, ( void * ) pxMyInterface->pxEndPoint->xMACAddress.ucBytes, 4 );
memcpy( ( void * ) &ucMACHigh, ( void * ) ( pxMyInterface->pxEndPoint->xMACAddress.ucBytes + 4 ), 2 );

if( smsc9220_mac_regwrite( dev, SMSC9220_MAC_REG_OFFSET_ADDRL, ucMACLow ) != 0 )
{
Expand Down
13 changes: 0 additions & 13 deletions source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,19 +982,6 @@ static BaseType_t xMayAcceptPacket( uint8_t * pucEthernetBuffer )

ulDestinationIPAddress = pxIPHeader->ulDestinationIPAddress;

/* Is the packet for this node? */
if( ( ulDestinationIPAddress != *ipLOCAL_IP_ADDRESS_POINTER ) &&
/* Is it a broadcast address x.x.x.255 ? */
( ( FreeRTOS_ntohl( ulDestinationIPAddress ) & 0xff ) != 0xff ) &&
#if ( ipconfigUSE_LLMNR == 1 )
( ulDestinationIPAddress != ipLLMNR_IP_ADDR ) &&
#endif
( *ipLOCAL_IP_ADDRESS_POINTER != 0 ) )
{
FreeRTOS_debug_printf( ( "Drop IP %lxip\n", FreeRTOS_ntohl( ulDestinationIPAddress ) ) );
return pdFALSE;
}

if( pxIPHeader->ucProtocol == ipPROTOCOL_UDP )
{
#if ( ipconfigUSE_LLMNR == 1 ) || ( ipconfigUSE_MDNS == 1 ) || ( ipconfigUSE_NBNS == 1 ) || ( ipconfigUSE_DNS == 1 )
Expand Down
12 changes: 6 additions & 6 deletions source/portable/NetworkInterface/linux/NetworkInterface.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,12 @@ static int prvConfigureCaptureBehaviour( void )
* stack. errbuf is used for convenience to create the string. Don't
* confuse this with an error message. */
sprintf( pcap_filter, "broadcast or multicast or ether host %x:%x:%x:%x:%x:%x",
ipLOCAL_MAC_ADDRESS[ 0 ],
ipLOCAL_MAC_ADDRESS[ 1 ],
ipLOCAL_MAC_ADDRESS[ 2 ],
ipLOCAL_MAC_ADDRESS[ 3 ],
ipLOCAL_MAC_ADDRESS[ 4 ],
ipLOCAL_MAC_ADDRESS[ 5 ] );
pxMyInterface->pxEndPoint->xMACAddress.ucBytes[ 0 ],
pxMyInterface->pxEndPoint->xMACAddress.ucBytes[ 1 ],
pxMyInterface->pxEndPoint->xMACAddress.ucBytes[ 2 ],
pxMyInterface->pxEndPoint->xMACAddress.ucBytes[ 3 ],
pxMyInterface->pxEndPoint->xMACAddress.ucBytes[ 4 ],
pxMyInterface->pxEndPoint->xMACAddress.ucBytes[ 5 ] );
FreeRTOS_debug_printf( ( "pcap filter to compile: %s\n", pcap_filter ) );

ulNetMask = FreeRTOS_inet_addr_quick( configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
Expand Down
21 changes: 0 additions & 21 deletions test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ NetworkBufferDescriptor_t * pxARPWaitingNetworkBuffer = NULL;

volatile BaseType_t xInsideInterrupt = pdFALSE;

/** @brief The expected IP version and header length coded into the IP header itself. */
#define ipIP_VERSION_AND_HEADER_LENGTH_BYTE ( ( uint8_t ) 0x45 )

UDPPacketHeader_t xDefaultPartUDPPacketHeader =
{
/* .ucBytes : */
{
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, /* Ethernet source MAC address. */
0x08, 0x00, /* Ethernet frame type. */
ipIP_VERSION_AND_HEADER_LENGTH_BYTE, /* ucVersionHeaderLength. */
0x00, /* ucDifferentiatedServicesCode. */
0x00, 0x00, /* usLength. */
0x00, 0x00, /* usIdentification. */
0x00, 0x00, /* usFragmentOffset. */
ipconfigUDP_TIME_TO_LIVE, /* ucTimeToLive */
ipPROTOCOL_UDP, /* ucProtocol. */
0x00, 0x00, /* usHeaderChecksum. */
0x00, 0x00, 0x00, 0x00 /* Source IP address. */
}
};

/** @brief For convenience, a MAC address of all 0xffs is defined const for quick
* reference. */
const MACAddress_t xBroadcastMACAddress = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
Expand Down
Loading

0 comments on commit 88e1475

Please sign in to comment.