2016-05-19 21:19:59 +08:00
|
|
|
/** @file
|
|
|
|
@brief ICMPv4 handler
|
|
|
|
|
|
|
|
This is not to be included by the application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-05-19 21:19:59 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ICMPV4_H
|
|
|
|
#define __ICMPV4_H
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-05-19 21:19:59 +08:00
|
|
|
|
|
|
|
#include <net/net_ip.h>
|
2017-04-03 23:14:35 +08:00
|
|
|
#include <net/net_pkt.h>
|
2016-05-19 21:19:59 +08:00
|
|
|
|
2016-06-14 14:44:18 +08:00
|
|
|
#define NET_ICMPV4_DST_UNREACH 3 /* Destination unreachable */
|
2016-05-19 21:19:59 +08:00
|
|
|
#define NET_ICMPV4_ECHO_REQUEST 8
|
|
|
|
#define NET_ICMPV4_ECHO_REPLY 0
|
|
|
|
|
2016-06-14 14:44:18 +08:00
|
|
|
#define NET_ICMPV4_DST_UNREACH_NO_PROTO 2 /* Protocol not supported */
|
|
|
|
#define NET_ICMPV4_DST_UNREACH_NO_PORT 3 /* Port unreachable */
|
|
|
|
|
2018-12-12 00:18:54 +08:00
|
|
|
#define NET_ICMPV4_UNUSED_LEN 4
|
|
|
|
|
2016-11-13 02:06:42 +08:00
|
|
|
struct net_icmpv4_echo_req {
|
2017-04-21 22:27:50 +08:00
|
|
|
u16_t identifier;
|
|
|
|
u16_t sequence;
|
2016-11-13 02:06:42 +08:00
|
|
|
} __packed;
|
|
|
|
|
2018-12-11 22:23:57 +08:00
|
|
|
typedef enum net_verdict (*icmpv4_callback_handler_t)(
|
|
|
|
struct net_pkt *pkt,
|
|
|
|
struct net_ipv4_hdr *ip_hdr);
|
2017-03-24 16:14:10 +08:00
|
|
|
|
|
|
|
struct net_icmpv4_handler {
|
|
|
|
sys_snode_t node;
|
2018-07-25 18:22:49 +08:00
|
|
|
icmpv4_callback_handler_t handler;
|
2017-04-21 22:27:50 +08:00
|
|
|
u8_t type;
|
|
|
|
u8_t code;
|
2017-03-24 16:14:10 +08:00
|
|
|
};
|
|
|
|
|
2016-06-14 14:44:18 +08:00
|
|
|
/**
|
|
|
|
* @brief Send ICMPv4 error message.
|
2017-04-05 14:37:44 +08:00
|
|
|
* @param pkt Network packet that this error is related to.
|
2016-06-14 14:44:18 +08:00
|
|
|
* @param type Type of the error message.
|
|
|
|
* @param code Code of the type of the error message.
|
|
|
|
* @return Return 0 if the sending succeed, <0 otherwise.
|
|
|
|
*/
|
2017-04-21 22:27:50 +08:00
|
|
|
int net_icmpv4_send_error(struct net_pkt *pkt, u8_t type, u8_t code);
|
2016-06-14 14:44:18 +08:00
|
|
|
|
2016-11-13 02:06:42 +08:00
|
|
|
/**
|
|
|
|
* @brief Send ICMPv4 echo request message.
|
|
|
|
*
|
|
|
|
* @param iface Network interface.
|
|
|
|
* @param dst IPv4 address of the target host.
|
|
|
|
* @param identifier An identifier to aid in matching Echo Replies
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @return Return 0 if the sending succeed, <0 otherwise.
|
|
|
|
*/
|
|
|
|
int net_icmpv4_send_echo_request(struct net_if *iface,
|
|
|
|
struct in_addr *dst,
|
2017-04-21 22:27:50 +08:00
|
|
|
u16_t identifier,
|
|
|
|
u16_t sequence);
|
2016-11-13 02:06:42 +08:00
|
|
|
|
2017-03-24 16:14:10 +08:00
|
|
|
void net_icmpv4_register_handler(struct net_icmpv4_handler *handler);
|
|
|
|
|
|
|
|
void net_icmpv4_unregister_handler(struct net_icmpv4_handler *handler);
|
|
|
|
|
2018-12-11 22:23:57 +08:00
|
|
|
enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
|
|
|
|
struct net_ipv4_hdr *ip_hdr);
|
2016-05-19 21:19:59 +08:00
|
|
|
|
2018-08-10 21:14:22 +08:00
|
|
|
int net_icmpv4_set_chksum(struct net_pkt *pkt);
|
2018-12-11 21:54:07 +08:00
|
|
|
int net_icmpv4_finalize(struct net_pkt *pkt);
|
2017-06-28 20:34:02 +08:00
|
|
|
|
2017-03-24 16:14:10 +08:00
|
|
|
#if defined(CONFIG_NET_IPV4)
|
|
|
|
void net_icmpv4_init(void);
|
|
|
|
#else
|
|
|
|
#define net_icmpv4_init(...)
|
|
|
|
#endif
|
|
|
|
|
2016-05-19 21:19:59 +08:00
|
|
|
#endif /* __ICMPV4_H */
|