Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 doc/reference/networking/net_shell.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The following net-shell commands are implemented:
print more information if :option:`CONFIG_NET_BUF_POOL_USAGE` is set."
"net nbr", "Print neighbor information. Only available if
:option:`CONFIG_NET_IPV6` is set."
"net ping", "Ping a network host."
"net ping [-c count] [-i interval ms]", "Ping a network host."
"net route", "Show IPv6 network routes. Only available if
:option:`CONFIG_NET_ROUTE` is set."
"net stats", "Show network statistics."
Expand Down
2 changes: 1 addition & 1 deletion samples/net/zperf/src/zperf_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
13 changes: 9 additions & 4 deletions subsys/net/ip/icmpv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ int net_icmpv4_finalize(struct net_pkt *pkt)
}

static enum net_verdict icmpv4_handle_echo_request(struct net_pkt *pkt,
struct net_ipv4_hdr *ip_hdr)
struct net_ipv4_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
struct net_pkt *reply = NULL;
s16_t payload_len;
Expand Down Expand Up @@ -128,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);
Expand All @@ -145,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) {
Expand All @@ -167,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);

Expand Down Expand Up @@ -319,7 +324,7 @@ enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
SYS_SLIST_FOR_EACH_CONTAINER(&handlers, cb, node) {
if (cb->type == icmp_hdr->type &&
(cb->code == icmp_hdr->code || cb->code == 0U)) {
return cb->handler(pkt, ip_hdr);
return cb->handler(pkt, ip_hdr, icmp_hdr);
}
}

Expand Down
10 changes: 8 additions & 2 deletions subsys/net/ip/icmpv4.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ struct net_icmpv4_echo_req {

typedef enum net_verdict (*icmpv4_callback_handler_t)(
struct net_pkt *pkt,
struct net_ipv4_hdr *ip_hdr);
struct net_ipv4_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr);

struct net_icmpv4_handler {
sys_snode_t node;
Expand All @@ -61,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);

Expand Down
8 changes: 6 additions & 2 deletions subsys/net/ip/icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,9 @@ int net_icmpv6_send_error(struct net_pkt *orig, u8_t type, u8_t code,
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);
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion subsys/net/ip/icmpv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading