net/icmpv6: Allow for arbitrary payload data in ICMP echo
Allow for including arbitrary data in net_icmpv6_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>
This commit is contained in:
parent
dd65cfb533
commit
7c09695344
|
@ -561,7 +561,7 @@ static int execute_upload(const struct shell *shell,
|
|||
* some time and start the test after that.
|
||||
*/
|
||||
net_icmpv6_send_echo_request(net_if_get_default(),
|
||||
&ipv6->sin6_addr, 0, 0);
|
||||
&ipv6->sin6_addr, 0, 0, NULL, 0);
|
||||
|
||||
k_sleep(K_SECONDS(1));
|
||||
}
|
||||
|
|
|
@ -297,7 +297,9 @@ drop_no_pkt:
|
|||
int net_icmpv6_send_echo_request(struct net_if *iface,
|
||||
struct in6_addr *dst,
|
||||
u16_t identifier,
|
||||
u16_t sequence)
|
||||
u16_t sequence,
|
||||
const void *data,
|
||||
size_t data_size)
|
||||
{
|
||||
NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(icmpv6_access,
|
||||
struct net_icmpv6_echo_req);
|
||||
|
@ -309,7 +311,8 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
|
|||
src = net_if_ipv6_select_src_addr(iface, dst);
|
||||
|
||||
pkt = net_pkt_alloc_with_buffer(iface,
|
||||
sizeof(struct net_icmpv6_echo_req),
|
||||
sizeof(struct net_icmpv6_echo_req)
|
||||
+ data_size,
|
||||
AF_INET6, IPPROTO_ICMPV6,
|
||||
PKT_WAIT_TIME);
|
||||
if (!pkt) {
|
||||
|
@ -331,6 +334,7 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
|
|||
echo_req->sequence = htons(sequence);
|
||||
|
||||
net_pkt_set_data(pkt, &icmpv6_access);
|
||||
net_pkt_write(pkt, data, data_size);
|
||||
|
||||
net_pkt_cursor_init(pkt);
|
||||
net_ipv6_finalize(pkt, IPPROTO_ICMPV6);
|
||||
|
|
|
@ -178,13 +178,18 @@ int net_icmpv6_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_icmpv6_send_echo_request(struct net_if *iface,
|
||||
struct in6_addr *dst,
|
||||
u16_t identifier,
|
||||
u16_t sequence);
|
||||
u16_t sequence,
|
||||
const void *data,
|
||||
size_t data_size);
|
||||
|
||||
void net_icmpv6_register_handler(struct net_icmpv6_handler *handler);
|
||||
void net_icmpv6_unregister_handler(struct net_icmpv6_handler *handler);
|
||||
|
|
|
@ -2703,7 +2703,9 @@ static int ping_ipv6(const struct shell *shell, char *host)
|
|||
ret = net_icmpv6_send_echo_request(iface,
|
||||
&ipv6_target,
|
||||
sys_rand32_get(),
|
||||
sys_rand32_get());
|
||||
sys_rand32_get(),
|
||||
NULL,
|
||||
0);
|
||||
if (ret) {
|
||||
remove_ipv6_ping_handler();
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue