Skip to content

Commit 8a966ec

Browse files
committed
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 <[email protected]>
1 parent 318a98a commit 8a966ec

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

subsys/net/ip/icmpv4.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ int net_icmpv4_finalize(struct net_pkt *pkt)
6060
}
6161

6262
static enum net_verdict icmpv4_handle_echo_request(struct net_pkt *pkt,
63-
struct net_ipv4_hdr *ip_hdr)
63+
struct net_ipv4_hdr *ip_hdr,
64+
struct net_icmp_hdr *icmp_hdr)
6465
{
6566
struct net_pkt *reply = NULL;
6667
s16_t payload_len;
@@ -319,7 +320,7 @@ enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
319320
SYS_SLIST_FOR_EACH_CONTAINER(&handlers, cb, node) {
320321
if (cb->type == icmp_hdr->type &&
321322
(cb->code == icmp_hdr->code || cb->code == 0U)) {
322-
return cb->handler(pkt, ip_hdr);
323+
return cb->handler(pkt, ip_hdr, icmp_hdr);
323324
}
324325
}
325326

subsys/net/ip/icmpv4.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ struct net_icmpv4_echo_req {
3434

3535
typedef enum net_verdict (*icmpv4_callback_handler_t)(
3636
struct net_pkt *pkt,
37-
struct net_ipv4_hdr *ip_hdr);
37+
struct net_ipv4_hdr *ip_hdr,
38+
struct net_icmp_hdr *icmp_hdr);
3839

3940
struct net_icmpv4_handler {
4041
sys_snode_t node;

subsys/net/ip/net_shell.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,8 @@ static int ping_ipv6(const struct shell *shell, char *host)
27202720
#if defined(CONFIG_NET_IPV4)
27212721

27222722
static enum net_verdict handle_ipv4_echo_reply(struct net_pkt *pkt,
2723-
struct net_ipv4_hdr *ip_hdr);
2723+
struct net_ipv4_hdr *ip_hdr,
2724+
struct net_icmp_hdr *icmp_hdr);
27242725

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

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

0 commit comments

Comments
 (0)