net/icmpv6: Improve callback signature to pass icmp header

In nbr part, this is a useful information. Since net_icmpv6_input has
already parsed the icmpv6 header, let's get pass it, instead of
retrieving/parsing it again in various handler functions.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2018-12-20 12:59:56 +01:00 committed by Jukka Rissanen
parent 7a3150ea5e
commit 9a6027ba5c
7 changed files with 27 additions and 12 deletions

View file

@ -291,13 +291,17 @@ int net_icmpv6_create(struct net_pkt *pkt, u8_t icmp_type, u8_t icmp_code)
return net_pkt_set_data(pkt, &icmp_access);
}
static enum net_verdict icmpv6_handle_echo_request(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr)
static
enum net_verdict icmpv6_handle_echo_request(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
struct net_pkt *reply = NULL;
const struct in6_addr *src;
s16_t payload_len;
ARG_UNUSED(icmp_hdr);
NET_DBG("Received Echo Request from %s to %s",
log_strdup(net_sprint_ipv6_addr(&ip_hdr->src)),
log_strdup(net_sprint_ipv6_addr(&ip_hdr->dst)));
@ -571,7 +575,7 @@ enum net_verdict net_icmpv6_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 == 0)) {
return cb->handler(pkt, ip_hdr);
return cb->handler(pkt, ip_hdr, icmp_hdr);
}
}
drop:

View file

@ -134,7 +134,8 @@ struct net_icmpv6_echo_req {
typedef enum net_verdict (*icmpv6_callback_handler_t)(
struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr);
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr);
const char *net_icmpv6_type2str(int icmpv6_type);

View file

@ -299,7 +299,8 @@ drop:
dbg_addr("Received", pkt_str, src, dst)
static enum net_verdict handle_mld_query(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr)
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
u16_t total_len = net_pkt_get_len(pkt);
struct in6_addr mcast;

View file

@ -1062,7 +1062,8 @@ static void ns_routing_info(struct net_pkt *pkt,
}
static enum net_verdict handle_ns_input(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr)
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
u16_t total_len = net_pkt_get_len(pkt);
u8_t prev_opt_len = 0U;
@ -1650,7 +1651,8 @@ send_pending:
}
static enum net_verdict handle_na_input(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr)
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
u16_t total_len = net_pkt_get_len(pkt);
u16_t tllao_offset = 0U;
@ -2268,7 +2270,8 @@ static inline struct net_buf *handle_ra_6co(struct net_pkt *pkt,
#endif
static enum net_verdict handle_ra_input(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr)
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
u16_t total_len = net_pkt_get_len(pkt);
struct net_nbr *nbr = NULL;

View file

@ -2742,7 +2742,8 @@ static const struct shell *shell_for_ping;
#if defined(CONFIG_NET_IPV6)
static enum net_verdict _handle_ipv6_echo_reply(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr);
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr);
static struct net_icmpv6_handler ping6_handler = {
.type = NET_ICMPV6_ECHO_REPLY,
@ -2756,8 +2757,11 @@ static inline void _remove_ipv6_ping_handler(void)
}
static enum net_verdict _handle_ipv6_echo_reply(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr)
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
ARG_UNUSED(icmp_hdr);
PR_SHELL(shell_for_ping, "Received echo reply from %s to %s\n",
net_sprint_ipv6_addr(&ip_hdr->src),
net_sprint_ipv6_addr(&ip_hdr->dst));

View file

@ -61,7 +61,8 @@ NET_PKT_TX_SLAB_DEFINE(pkts_slab, 2);
NET_BUF_POOL_DEFINE(data_pool, 2, 128, 0, NULL);
static enum net_verdict handle_test_msg(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr)
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
struct net_buf *last = net_buf_frag_last(pkt->frags);
enum net_verdict ret;

View file

@ -368,7 +368,8 @@ static void send_query(struct net_if *iface)
/* We are not really interested to parse the query at this point */
static enum net_verdict handle_mld_query(struct net_pkt *pkt,
struct net_ipv6_hdr *ip_hdr)
struct net_ipv6_hdr *ip_hdr,
struct net_icmp_hdr *icmp_hdr)
{
is_query_received = true;