1 /** @file
2  @brief ICMPv4 handler
3 
4  This is not to be included by the application.
5  */
6 
7 /*
8  * Copyright (c) 2016 Intel Corporation
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #ifndef __ICMPV4_H
14 #define __ICMPV4_H
15 
16 #include <zephyr/types.h>
17 
18 #include <zephyr/net/net_ip.h>
19 #include <zephyr/net/net_pkt.h>
20 
21 #define NET_ICMPV4_DST_UNREACH  3	/* Destination unreachable */
22 #define NET_ICMPV4_TIME_EXCEEDED 11	/* Time exceeded */
23 #define NET_ICMPV4_BAD_IP_HEADER 12	/* Bad IP header */
24 
25 #define NET_ICMPV4_DST_UNREACH_NO_PROTO  2 /* Protocol not supported */
26 #define NET_ICMPV4_DST_UNREACH_NO_PORT   3 /* Port unreachable */
27 #define NET_ICMPV4_TIME_EXCEEDED_FRAGMENT_REASSEMBLY_TIME 1 /* Fragment reassembly time exceeded */
28 #define NET_ICMPV4_BAD_IP_HEADER_LENGTH  2 /* Bad length field */
29 
30 #define NET_ICMPV4_UNUSED_LEN 4
31 
32 struct net_icmpv4_echo_req {
33 	uint16_t identifier;
34 	uint16_t sequence;
35 } __packed;
36 
37 struct net_icmpv4_dest_unreach {
38 	uint16_t unused;
39 	uint16_t mtu;
40 } __packed;
41 
42 /**
43  * @brief Send ICMPv4 error message.
44  * @param pkt Network packet that this error is related to.
45  * @param type Type of the error message.
46  * @param code Code of the type of the error message.
47  * @return Return 0 if the sending succeed, <0 otherwise.
48  */
49 int net_icmpv4_send_error(struct net_pkt *pkt, uint8_t type, uint8_t code);
50 
51 #if defined(CONFIG_NET_NATIVE_IPV4)
52 enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
53 				  struct net_ipv4_hdr *ip_hdr);
54 
55 int net_icmpv4_create(struct net_pkt *pkt, uint8_t icmp_type, uint8_t icmp_code);
56 int net_icmpv4_finalize(struct net_pkt *pkt, bool force_chksum);
57 
58 void net_icmpv4_init(void);
59 #else
60 #define net_icmpv4_init(...)
61 #endif
62 
63 #endif /* __ICMPV4_H */
64