Skip to content
Permalink
Browse files

net/icmpv4: Include icmp_hdr in callback

Allow accessing already parsed information from the ICMP header
that callbacks might be interested in.

This makes the callback signature and behaviour match that of
the ICMPv6 implementation.

Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
  • Loading branch information...
benpicco authored and jukkar committed Mar 4, 2019
1 parent a25dce9 commit b9383243459481ec69888b6e3d19b54ed0b5fe9a
Showing with 9 additions and 5 deletions.
  1. +3 −2 subsys/net/ip/icmpv4.c
  2. +2 −1 subsys/net/ip/icmpv4.h
  3. +4 −2 subsys/net/ip/net_shell.c
@@ -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;
@@ -319,7 +320,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);
}
}

@@ -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;
@@ -2720,7 +2720,8 @@ static int ping_ipv6(const struct shell *shell, char *host)
#if defined(CONFIG_NET_IPV4)

static enum net_verdict handle_ipv4_echo_reply(struct net_pkt *pkt,
struct net_ipv4_hdr *ip_hdr);
struct net_ipv4_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr);

static struct net_icmpv4_handler ping4_handler = {
.type = NET_ICMPV4_ECHO_REPLY,
@@ -2734,7 +2735,8 @@ static inline void remove_ipv4_ping_handler(void)
}

static enum net_verdict handle_ipv4_echo_reply(struct net_pkt *pkt,
struct net_ipv4_hdr *ip_hdr)
struct net_ipv4_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
PR_SHELL(shell_for_ping, "Received echo reply from %s to %s\n",
net_sprint_ipv4_addr(&ip_hdr->src),

0 comments on commit b938324

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