Skip to content
Permalink
Browse files

net/icmpv4: Allow for arbitrary payload data in ICMP echo

Allow for including arbitrary data in net_icmpv4_send_echo_request()
that will be echoed verbatim by the receiver.

This allows to use ICMP echo for diagnostic use cases, e.g. by testing
packet framentation (large payload) or measuring round-trip-time.

Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
  • Loading branch information...
benpicco authored and jukkar committed Mar 5, 2019
1 parent b938324 commit dd65cfb5337d96479b08672ddc5d5f31005438b1
Showing with 15 additions and 4 deletions.
  1. +6 −2 subsys/net/ip/icmpv4.c
  2. +6 −1 subsys/net/ip/icmpv4.h
  3. +3 −1 subsys/net/ip/net_shell.c
@@ -129,7 +129,9 @@ static enum net_verdict icmpv4_handle_echo_request(struct net_pkt *pkt,
int net_icmpv4_send_echo_request(struct net_if *iface,
struct in_addr *dst,
u16_t identifier,
u16_t sequence)
u16_t sequence,
const void *data,
size_t data_size)
{
NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(icmpv4_access,
struct net_icmpv4_echo_req);
@@ -146,7 +148,8 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
src = &iface->config.ip.ipv4->unicast[0].address.in_addr;

pkt = net_pkt_alloc_with_buffer(iface,
sizeof(struct net_icmpv4_echo_req),
sizeof(struct net_icmpv4_echo_req)
+ data_size,
AF_INET, IPPROTO_ICMP,
PKT_WAIT_TIME);
if (!pkt) {
@@ -168,6 +171,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
echo_req->sequence = htons(sequence);

net_pkt_set_data(pkt, &icmpv4_access);
net_pkt_write(pkt, data, data_size);

net_pkt_cursor_init(pkt);

@@ -62,13 +62,18 @@ int net_icmpv4_send_error(struct net_pkt *pkt, u8_t type, u8_t code);
* to this Echo Request. May be zero.
* @param sequence A sequence number to aid in matching Echo Replies
* to this Echo Request. May be zero.
* @param data Arbitrary payload data that will be included in the
* Echo Reply verbatim. May be zero.
* @param data_size Size of the Payload Data in bytes. May be zero.
*
* @return Return 0 if the sending succeed, <0 otherwise.
*/
int net_icmpv4_send_echo_request(struct net_if *iface,
struct in_addr *dst,
u16_t identifier,
u16_t sequence);
u16_t sequence,
const void *data,
size_t data_size);

void net_icmpv4_register_handler(struct net_icmpv4_handler *handler);

@@ -2763,7 +2763,9 @@ static int ping_ipv4(const struct shell *shell, char *host)
net_if_ipv4_select_src_iface(&ipv4_target),
&ipv4_target,
sys_rand32_get(),
sys_rand32_get());
sys_rand32_get(),
NULL,
0);
if (ret) {
remove_ipv4_ping_handler();
} else {

0 comments on commit dd65cfb

Please sign in to comment.
You can’t perform that action at this time.