wiki:TBR/UserManual/Controlling_ICMP_ECHO_(PING)_requests
Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Version 3 (modified by taneka zenon hans, on 11/13/18 at 13:16:18) (diff)

Error in instructions. Setting allecho sysctl to 0 should prevent echos NOT prevent them from not being echoed

Controlling ICMP ECHO (PING) requests

Note: The allecho sysctl feature discussed here is only available in RTEMS CVS, and versions after 4.6.99.3.

RTEMS provides 2 methods for controlling replies generated to ICMP ECHO requests (known as a PING).

By default, the RTEMS network stack will reply to a "PING" directed both to the IP address of the device running RTEMS and to the broadcast address.

The standard "BSD" way to prevent a ping to a broadcast/multicast address being echoed is to use the bmcastecho sysctl. Setting this sysctl to 0 will prevent any ping to a broadcast/multicast address being echoed.

However, some applications also require that ANY ping directed to the device not be echoed. The BSD network stack utilised by RTEM has no standard feature to allow this. RTEMS has implemented a non-portable "Extension" to allow all Pings recieved by a device to not be echoed. This feature is controlled by the allecho sysctl. Setting this sysctl to 0 will prevent any "ping" to the device from being echoed. As this extension is specific to RTEMS, code that uses it will not function as expected on other systems, use with caution if portability is desired.

allecho set to 0 - prevents all echos.
allecho set to 1, bmcastecho set to 0 - only prevents all broadcast/multcast echo's.
allecho set to 1, bmcastecho set to 1 - allows all echo's (default state).

For details on setting sysctl's in the network stack, refer to TCP-IP Setup Using SYSCTL?

Both of these sysctl's are of the OID_AUTO type. sysctlbyname is the most convenient way to modify these values.

Examples:

Prevent icmp echo replies to a broadcast/multicast address:

int    value = 0;
size_t len   = sizeof(value);

result = sysctlbyname ("bmcastecho", NULL, 0, &value, len);

Allow icmp echo replies to a broadcast/multicast address:

int    value = 1;
size_t len   = sizeof(value);

result = sysctlbyname ("bmcastecho", NULL, 0, &value, len);

Prevent all echo replies:

int    value = 0;
size_t len   = sizeof(value);

result = sysctlbyname ("allecho", NULL, 0, &value, len);

Allow all echo replies, broadcast/multicast echo's may still be blocked by bmcastecho:

int    value = 1;
size_t len   = sizeof(value);

result = sysctlbyname ("allecho", NULL, 0, &value, len);