Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS callback to use new xDNSDoCallback API #985

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/FreeRTOS_DNS_Callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
if( listLIST_IS_EMPTY( &xCallbackList ) != pdFALSE )
{
/* This is the first one, start the DNS timer to check for timeouts */
vDNSTimerReload( FreeRTOS_min_uint32( 1000U, uxTimeout ) );
vDNSTimerReload( FreeRTOS_min_uint32( 1000U, ( uint32_t ) uxTimeout ) );
}

( void ) strcpy( pxCallback->pcName, pcHostName );
Expand Down
12 changes: 2 additions & 10 deletions source/FreeRTOS_DNS_Parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,15 +786,7 @@
{
BaseType_t xCallbackResult;

#if ( ipconfigUSE_IPv6 != 0 )
{
xCallbackResult = xDNSDoCallback( pxSet, ( ppxAddressInfo != NULL ) ? *( ppxAddressInfo ) : NULL );
}
#else
{
xCallbackResult = xDNSDoCallback( pxSet, pxSet->ulIPAddress );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good find. Thank you.
Please check once why this "integer to pointer" assignment is not being treated as an error in our build.

}
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
xCallbackResult = xDNSDoCallback( pxSet, ( ppxAddressInfo != NULL ) ? *( ppxAddressInfo ) : NULL );

/* See if any asynchronous call was made to FreeRTOS_gethostbyname_a() */
if( xCallbackResult != pdFALSE )
Expand Down Expand Up @@ -997,7 +989,7 @@
/* Calculate the IP header checksum. */
pxIPHeader->usHeaderChecksum = 0U;
pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0U, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), uxIPHeaderLength );
pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
pxIPHeader->usHeaderChecksum = ( uint16_t ) ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
}

/* calculate the UDP checksum for outgoing package */
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_ICMP.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
/* calculate the IP header checksum, in case the driver won't do that. */
pxIPHeader->usHeaderChecksum = 0x00U;
pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0U, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), uxIPHeaderSizePacket( pxNetworkBuffer ) );
pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
pxIPHeader->usHeaderChecksum = ( uint16_t ) ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );

/* calculate the ICMP checksum for an outgoing packet. */
( void ) usGenerateProtocolChecksum( ( uint8_t * ) pxICMPPacket, pxNetworkBuffer->xDataLength, pdTRUE );
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_TCP_Transmission_IPV4.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket,
/* calculate the IP header checksum, in case the driver won't do that. */
pxIPHeader->usHeaderChecksum = 0x00U;
pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0U, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), uxIPHeaderSize );
pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
pxIPHeader->usHeaderChecksum = ( uint16_t ) ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );

/* calculate the TCP checksum for an outgoing packet. */
( void ) usGenerateProtocolChecksum( ( uint8_t * ) pxTCPPacket, pxNetworkBuffer->xDataLength, pdTRUE );
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_UDP_IPv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void vProcessGeneratedUDPPacket_IPv4( NetworkBufferDescriptor_t * const pxNetwor
{
pxIPHeader->usHeaderChecksum = 0U;
pxIPHeader->usHeaderChecksum = usGenerateChecksum( 0U, ( uint8_t * ) &( pxIPHeader->ucVersionHeaderLength ), uxIPHeaderSizePacket( pxNetworkBuffer ) );
pxIPHeader->usHeaderChecksum = ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );
pxIPHeader->usHeaderChecksum = ( uint16_t ) ~FreeRTOS_htons( pxIPHeader->usHeaderChecksum );

if( ( ucSocketOptions & ( uint8_t ) FREERTOS_SO_UDPCKSUM_OUT ) != 0U )
{
Expand Down
8 changes: 8 additions & 0 deletions test/build-combination/AllEnable/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
#define ipconfigSELECT_USES_NOTIFY 1
#define ipconfigSUPPORT_SIGNALS 1
#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 1
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigCOMPATIBLE_WITH_SINGLE 1
#define ipconfigIGNORE_UNKNOWN_PACKETS 1
#define ipconfigCHECK_IP_QUEUE_SPACE 1
#define ipconfigUDP_MAX_RX_PACKETS 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES 1
#define ipconfigTCP_IP_SANITY 1
#define ipconfigSUPPORT_NETWORK_DOWN_EVENT 1

/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
Expand Down
7 changes: 7 additions & 0 deletions test/build-combination/Enable_IPv4/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
#define ipconfigSELECT_USES_NOTIFY 1
#define ipconfigSUPPORT_SIGNALS 1
#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 1
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigIGNORE_UNKNOWN_PACKETS 1
#define ipconfigCHECK_IP_QUEUE_SPACE 1
#define ipconfigUDP_MAX_RX_PACKETS 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES 1
#define ipconfigTCP_IP_SANITY 1
#define ipconfigSUPPORT_NETWORK_DOWN_EVENT 1

/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
Expand Down
7 changes: 7 additions & 0 deletions test/build-combination/Enable_IPv4_IPv6/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
#define ipconfigSELECT_USES_NOTIFY 1
#define ipconfigSUPPORT_SIGNALS 1
#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 1
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigIGNORE_UNKNOWN_PACKETS 1
#define ipconfigCHECK_IP_QUEUE_SPACE 1
#define ipconfigUDP_MAX_RX_PACKETS 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES 1
#define ipconfigTCP_IP_SANITY 1
#define ipconfigSUPPORT_NETWORK_DOWN_EVENT 1

/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
Expand Down
7 changes: 7 additions & 0 deletions test/build-combination/Enable_IPv4_TCP/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
#define ipconfigSELECT_USES_NOTIFY 1
#define ipconfigSUPPORT_SIGNALS 1
#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 1
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigIGNORE_UNKNOWN_PACKETS 1
#define ipconfigCHECK_IP_QUEUE_SPACE 1
#define ipconfigUDP_MAX_RX_PACKETS 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES 1
#define ipconfigTCP_IP_SANITY 1
#define ipconfigSUPPORT_NETWORK_DOWN_EVENT 1

/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
Expand Down
7 changes: 7 additions & 0 deletions test/build-combination/Enable_IPv6/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
#define ipconfigSELECT_USES_NOTIFY 1
#define ipconfigSUPPORT_SIGNALS 1
#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 1
#define ipconfigDNS_USE_CALLBACKS 0
#define ipconfigIGNORE_UNKNOWN_PACKETS 1
#define ipconfigCHECK_IP_QUEUE_SPACE 1
#define ipconfigUDP_MAX_RX_PACKETS 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES 1
#define ipconfigTCP_IP_SANITY 1
#define ipconfigSUPPORT_NETWORK_DOWN_EVENT 1

/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
Expand Down
7 changes: 7 additions & 0 deletions test/build-combination/Enable_IPv6_TCP/FreeRTOSIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
#define ipconfigSELECT_USES_NOTIFY 1
#define ipconfigSUPPORT_SIGNALS 1
#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 1
#define ipconfigDNS_USE_CALLBACKS 0
#define ipconfigIGNORE_UNKNOWN_PACKETS 1
#define ipconfigCHECK_IP_QUEUE_SPACE 1
#define ipconfigUDP_MAX_RX_PACKETS 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES 1
#define ipconfigTCP_IP_SANITY 1
#define ipconfigSUPPORT_NETWORK_DOWN_EVENT 1

/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
#define ipconfigSELECT_USES_NOTIFY 1
#define ipconfigSUPPORT_SIGNALS 1
#define ipconfigPROCESS_CUSTOM_ETHERNET_FRAMES 1
#define ipconfigDNS_USE_CALLBACKS 1
#define ipconfigIGNORE_UNKNOWN_PACKETS 1
#define ipconfigCHECK_IP_QUEUE_SPACE 1
#define ipconfigUDP_MAX_RX_PACKETS 1
#define ipconfigETHERNET_MINIMUM_PACKET_BYTES 1
#define ipconfigTCP_IP_SANITY 1
#define ipconfigSUPPORT_NETWORK_DOWN_EVENT 1

/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
Expand Down
141 changes: 59 additions & 82 deletions tools/tcp_utilities/plus_tcp_demo_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,9 @@ static struct freertos_addrinfo * pxDNSLookup( char * pcHost,
BaseType_t xAsynchronous,
BaseType_t xDoClear );

#if ( ipconfigUSE_IPv6 == 0 )
/* In the old days, an IP-address was just a number. */
static void vDNSEvent( const char * pcName,
void * pvSearchID,
uint32_t ulIPAddress );
#else
/* freertos_addrinfo can contain either an IPv4 or an IPv6 address. */
static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo );
#endif
static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo );

#if ( ipconfigMULTI_INTERFACE != 0 )
/* Defined in FreeRTOS_DNS.c */
Expand Down Expand Up @@ -1485,95 +1477,80 @@ void xHandleTesting()
#endif /* ( ipconfigMULTI_INTERFACE != 0 ) */
/*-----------------------------------------------------------*/

#if ( ipconfigUSE_IPv6 != 0 )
static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo )

static void vDNSEvent( const char * pcName,
void * pvSearchID,
struct freertos_addrinfo * pxAddrInfo )
{
( void ) pvSearchID;

if( pxAddrInfo == NULL )
{
FreeRTOS_printf( ( "vDNSEvent(%s) : nothing found\n", pcName ) );
}
else
{
( void ) pvSearchID;
FreeRTOS_printf( ( "vDNSEvent: family = %d\n", ( int ) pxAddrInfo->ai_family ) );

if( pxAddrInfo == NULL )
{
FreeRTOS_printf( ( "vDNSEvent(%s) : nothing found\n", pcName ) );
}
else
switch( pxAddrInfo->ai_family )
{
FreeRTOS_printf( ( "vDNSEvent: family = %d\n", ( int ) pxAddrInfo->ai_family ) );
#if ( ipconfigUSE_IPv4 != 0 )
case FREERTOS_AF_INET:
{
uint32_t ulIPaddress = pxAddrInfo->ai_addr->sin_address.ulIP_IPv4;

switch( pxAddrInfo->ai_family )
{
#if ( ipconfigUSE_IPv4 != 0 )
case FREERTOS_AF_INET:
if( ulIPaddress == 0uL )
{
uint32_t ulIPaddress = pxAddrInfo->ai_addr->sin_address.ulIP_IPv4;

if( ulIPaddress == 0uL )
{
FreeRTOS_printf( ( "vDNSEvent/v4: '%s' timed out\n", pcName ) );
}
else
{
FreeRTOS_printf( ( "vDNSEvent/v4: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPaddress ) ) );
}
FreeRTOS_printf( ( "vDNSEvent/v4: '%s' timed out\n", pcName ) );
}
break;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

#if ( ipconfigUSE_IPv6 != 0 )
case FREERTOS_AF_INET6:
else
{
BaseType_t xIsEmpty = pdTRUE, xIndex;
FreeRTOS_printf( ( "vDNSEvent/v4: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPaddress ) ) );
}
}
break;
#endif /* ( ipconfigUSE_IPv4 != 0 ) */

for( xIndex = 0; xIndex < ( BaseType_t ) ARRAY_SIZE( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ); xIndex++ )
{
if( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes[ xIndex ] != ( uint8_t ) 0u )
{
xIsEmpty = pdFALSE;
break;
}
}
#if ( ipconfigUSE_IPv6 != 0 )
case FREERTOS_AF_INET6:
{
BaseType_t xIsEmpty = pdTRUE, xIndex;

if( xIsEmpty )
{
FreeRTOS_printf( ( "vDNSEvent/v6: '%s' timed out\n", pcName ) );
}
else
for( xIndex = 0; xIndex < ( BaseType_t ) ARRAY_SIZE( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ); xIndex++ )
{
if( pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes[ xIndex ] != ( uint8_t ) 0u )
{
FreeRTOS_printf( ( "vDNSEvent/v6: found '%s' on %pip\n", pcName, pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ) );
xIsEmpty = pdFALSE;
break;
}
}
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "vDNSEvent: Undefined Family Type \n" ) );
break;
}
}
if( xIsEmpty )
{
FreeRTOS_printf( ( "vDNSEvent/v6: '%s' timed out\n", pcName ) );
}
else
{
FreeRTOS_printf( ( "vDNSEvent/v6: found '%s' on %pip\n", pcName, pxAddrInfo->ai_addr->sin_address.xIP_IPv6.ucBytes ) );
}
}
break;
#endif /* ( ipconfigUSE_IPv6 != 0 ) */

if( xServerWorkTaskHandle != NULL )
{
xDNSCount++;
xTaskNotifyGive( xServerWorkTaskHandle );
default:
/* MISRA 16.4 Compliance */
FreeRTOS_debug_printf( ( "vDNSEvent: Undefined Family Type \n" ) );
break;
}
}
#else /* if ( ipconfigUSE_IPv6 != 0 ) */
static void vDNSEvent( const char * pcName,
void * pvSearchID,
uint32_t ulIPAddress )
{
( void ) pvSearchID;

FreeRTOS_printf( ( "vDNSEvent: found '%s' on %lxip\n", pcName, FreeRTOS_ntohl( ulIPAddress ) ) );

if( xServerWorkTaskHandle != NULL )
{
xDNSCount++;
xTaskNotifyGive( xServerWorkTaskHandle );
}
if( xServerWorkTaskHandle != NULL )
{
xDNSCount++;
xTaskNotifyGive( xServerWorkTaskHandle );
}
#endif /* if ( ipconfigUSE_IPv6 != 0 ) */
}

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

#if ( ipconfigMULTI_INTERFACE != 0 )
Expand Down