Skip to content

Commit

Permalink
net: icmpv4: Merge process_icmpv4_pkt() into net_icmpv4_input()
Browse files Browse the repository at this point in the history
Both are small, merging makes the flow clearer.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
  • Loading branch information
ozhuraki authored and jukkar committed Jul 2, 2018
1 parent 58e40cb commit 2b6e70d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
16 changes: 13 additions & 3 deletions subsys/net/ip/icmpv4.c
Expand Up @@ -373,15 +373,25 @@ void net_icmpv4_unregister_handler(struct net_icmpv4_handler *handler)
sys_slist_find_and_remove(&handlers, &handler->node);
}

enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
u8_t type, u8_t code)
enum net_verdict net_icmpv4_input(struct net_pkt *pkt)
{
struct net_icmpv4_handler *cb;
struct net_icmp_hdr hdr, *icmp_hdr;

icmp_hdr = net_icmpv4_get_hdr(pkt, &hdr);
if (!icmp_hdr) {
NET_DBG("NULL ICMPv4 header - dropping");
return NET_DROP;
}

NET_DBG("ICMPv4 packet received type %d code %d",
icmp_hdr->type, icmp_hdr->code);

net_stats_update_icmp_recv(net_pkt_iface(pkt));

SYS_SLIST_FOR_EACH_CONTAINER(&handlers, cb, node) {
if (cb->type == type && (cb->code == code || cb->code == 0)) {
if (cb->type == icmp_hdr->type &&
(cb->code == icmp_hdr->code || cb->code == 0)) {
return cb->handler(pkt);
}
}
Expand Down
3 changes: 1 addition & 2 deletions subsys/net/ip/icmpv4.h
Expand Up @@ -73,8 +73,7 @@ void net_icmpv4_register_handler(struct net_icmpv4_handler *handler);

void net_icmpv4_unregister_handler(struct net_icmpv4_handler *handler);

enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
u8_t type, u8_t code);
enum net_verdict net_icmpv4_input(struct net_pkt *pkt);

struct net_icmp_hdr *net_icmpv4_get_hdr(struct net_pkt *pkt,
struct net_icmp_hdr *hdr);
Expand Down
19 changes: 1 addition & 18 deletions subsys/net/ip/ipv4.c
Expand Up @@ -111,23 +111,6 @@ const struct in_addr *net_ipv4_broadcast_address(void)
return &addr;
}

static inline enum net_verdict process_icmpv4_pkt(struct net_pkt *pkt,
struct net_ipv4_hdr *ipv4)
{
struct net_icmp_hdr hdr, *icmp_hdr;

icmp_hdr = net_icmpv4_get_hdr(pkt, &hdr);
if (!icmp_hdr) {
NET_DBG("NULL ICMPv4 header - dropping");
return NET_DROP;
}

NET_DBG("ICMPv4 packet received type %d code %d",
icmp_hdr->type, icmp_hdr->code);

return net_icmpv4_input(pkt, icmp_hdr->type, icmp_hdr->code);
}

enum net_verdict net_ipv4_process_pkt(struct net_pkt *pkt)
{
struct net_ipv4_hdr *hdr = NET_IPV4_HDR(pkt);
Expand Down Expand Up @@ -173,7 +156,7 @@ enum net_verdict net_ipv4_process_pkt(struct net_pkt *pkt)

switch (hdr->proto) {
case IPPROTO_ICMP:
verdict = process_icmpv4_pkt(pkt, hdr);
verdict = net_icmpv4_input(pkt);
break;
case IPPROTO_UDP:
verdict = net_conn_input(IPPROTO_UDP, pkt);
Expand Down

0 comments on commit 2b6e70d

Please sign in to comment.