heinbali01 wrote on Wednesday, May 06, 2015:
Hi Endre,
Good observation about the difference between the two networks.
Broadcasts are often used in network protocols like NetBIOS, PnP, and many others. For us embedded developers they can be quite bothering.
If all broadcast packets travel all the way to the IP-task, they use quite a bit of resources:
- The queue ‘
xNetworkEventQueue’ of the IP-task
- Entries in the ARP table
- A network buffer descriptor
ad 1) The queue ‘xNetworkEventQueue’ of the IP-task
the queue has a length of ipconfigEVENT_QUEUE_LENGTH, which should be more than enough to hold all network buffers, i.e.
ipconfigEVENT_QUEUE_LENGTH >= ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + EXTRA
where EXTRA >= 5
ad 2) Entries in the ARP table
Care has been taken in the library like here:
if( pxIPHeader->ucProtocol != ipPROTOCOL_UDP )
{
/* Refresh the ARP cache with the IP/MAC-address of the
* received packet. For UDP packets, this will be done
* later in xProcessReceivedUDPPacket() as soon as know
* that the message will be handled by someone. This
* will prevent that the ARP cache will get overwritten
* with the IP-address of useless broadcast packets
*/
vARPRefreshCacheEntry( &( pxIPPacket->xEthernetHeader.xSourceAddress ),
pxIPHeader->ulSourceIPAddress );
}
Only UDP packets that can be treated will create an ARP entry.
ad 3) A network buffer descriptor
the biggest problem with frequent UDP broadcasts is that they can occupy network buffers. This may prevent PING requests from being answered.
It is advisable to define:
#define ipconfigETHERNET_DRIVER_FILTERS_PACKETS 1
in your FreeRTOSIPConfig.h.
And test at a very early stage if a packet can be dropped:
if( pxIPHeader->ucProtocol == ipPROTOCOL_UDP )
{
uint16_t usDestinationPort =
pxProtPacket->xUDPPacket.xUDPHeader.usDestinationPort;
/* xPortHasUdpSocket() returns pdTRUE if a socket has been
opened on a given port number. */
if ( ( xPortHasUdpSocket( usDestinationPort ) == pdFALSE )
#if ipconfigUSE_LLMNR == 1
&& ( usDestinationPort != FreeRTOS_ntohs( ipLLMNR_PORT ) )
#endif
#if ipconfigUSE_NBNS == 1
&& ( usDestinationPort != FreeRTOS_ntohs( ipNBNS_PORT ) )
#endif
#if ipconfigUSE_DNS == 1
&& ( pxProtPacket->xUDPPacket.xUDPHeader.usSourcePort !=
FreeRTOS_ntohs( ipDNS_PORT ) )
#endif
)
{
/* Drop this packet, not for this device. */
xReturn = FALSE;
}
}
PS. the above code can not be used in an interrupt.
See also prvAllowIPPacket() in FreeRTOS_IP.c in which packets are filtered on their IP address.
You wrote that you see big delays (200 ms - 3 sec) for ICMP messages to be replied. Early filtering will help to avoid it, but it isn’t clear to me why you see such delays. I would expect that echo messages will be dropped, not delayed so much.
Hope this helps, Hein