24 #ifndef __DECODE_ICMPV4_H__
25 #define __DECODE_ICMPV4_H__
30 #define ICMPV4_HEADER_LEN 8
32 #ifndef ICMP_ECHOREPLY
33 #define ICMP_ECHOREPLY 0
35 #ifndef ICMP_DEST_UNREACH
36 #define ICMP_DEST_UNREACH 3
38 #ifndef ICMP_SOURCE_QUENCH
39 #define ICMP_SOURCE_QUENCH 4
42 #define ICMP_REDIRECT 5
47 #ifndef ICMP_ROUTERADVERT
48 #define ICMP_ROUTERADVERT 9
50 #ifndef ICMP_ROUTERSOLICIT
51 #define ICMP_ROUTERSOLICIT 10
53 #ifndef ICMP_TIME_EXCEEDED
54 #define ICMP_TIME_EXCEEDED 11
56 #ifndef ICMP_PARAMETERPROB
57 #define ICMP_PARAMETERPROB 12
59 #ifndef ICMP_TIMESTAMP
60 #define ICMP_TIMESTAMP 13
62 #ifndef ICMP_TIMESTAMPREPLY
63 #define ICMP_TIMESTAMPREPLY 14
65 #ifndef ICMP_INFO_REQUEST
66 #define ICMP_INFO_REQUEST 15
68 #ifndef ICMP_INFO_REPLY
69 #define ICMP_INFO_REPLY 16
72 #define ICMP_ADDRESS 17
74 #ifndef ICMP_ADDRESSREPLY
75 #define ICMP_ADDRESSREPLY 18
78 #define NR_ICMP_TYPES 18
83 #ifndef ICMP_NET_UNREACH
84 #define ICMP_NET_UNREACH 0
86 #ifndef ICMP_HOST_UNREACH
87 #define ICMP_HOST_UNREACH 1
89 #ifndef ICMP_PROT_UNREACH
90 #define ICMP_PROT_UNREACH 2
92 #ifndef ICMP_PORT_UNREACH
93 #define ICMP_PORT_UNREACH 3
95 #ifndef ICMP_FRAG_NEEDED
96 #define ICMP_FRAG_NEEDED 4
98 #ifndef ICMP_SR_FAILED
99 #define ICMP_SR_FAILED 5
101 #ifndef ICMP_NET_UNKNOWN
102 #define ICMP_NET_UNKNOWN 6
104 #ifndef ICMP_HOST_UNKNOWN
105 #define ICMP_HOST_UNKNOWN 7
107 #ifndef ICMP_HOST_ISOLATED
108 #define ICMP_HOST_ISOLATED 8
111 #define ICMP_NET_ANO 9
113 #ifndef ICMP_HOST_ANO
114 #define ICMP_HOST_ANO 10
116 #ifndef ICMP_NET_UNR_TOS
117 #define ICMP_NET_UNR_TOS 11
119 #ifndef ICMP_HOST_UNR_TOS
120 #define ICMP_HOST_UNR_TOS 12
122 #ifndef ICMP_PKT_FILTERED
123 #define ICMP_PKT_FILTERED 13
125 #ifndef ICMP_PREC_VIOLATION
126 #define ICMP_PREC_VIOLATION 14
129 #ifndef ICMP_PREC_CUTOFF
130 #define ICMP_PREC_CUTOFF 15
132 #ifndef NR_ICMP_UNREACH
133 #define NR_ICMP_UNREACH 15
137 #ifndef ICMP_REDIR_NET
138 #define ICMP_REDIR_NET 0
140 #ifndef ICMP_REDIR_HOST
141 #define ICMP_REDIR_HOST 1
143 #ifndef ICMP_REDIR_NETTOS
144 #define ICMP_REDIR_NETTOS 2
146 #ifndef ICMP_REDIR_HOSTTOS
147 #define ICMP_REDIR_HOSTTOS 3
152 #define ICMP_EXC_TTL 0
154 #ifndef ICMP_EXC_FRAGTIME
155 #define ICMP_EXC_FRAGTIME 1
159 #define ICMPV4_GET_TYPE(p) (p)->icmpv4h->type
161 #define ICMPV4_GET_CODE(p) (p)->icmpv4h->code
224 #define CLEAR_ICMPV4_PACKET(p) do { \
225 (p)->level4_comp_csum = -1; \
226 PACKET_CLEAR_L4VARS((p)); \
227 (p)->icmpv4h = NULL; \
230 #define ICMPV4_HEADER_PKT_OFFSET 8
233 #define ICMPV4_GET_TYPE(p) (p)->icmpv4h->type
235 #define ICMPV4_GET_CODE(p) (p)->icmpv4h->code
237 #define ICMPV4_GET_RAW_CSUM(p) SCNtohs((p)->icmpv4h->checksum)
238 #define ICMPV4_GET_CSUM(p) (p)->icmpv4h->checksum
243 #define ICMPV4_GET_ID(p) ((p)->icmpv4vars.id)
245 #define ICMPV4_GET_SEQ(p) ((p)->icmpv4vars.seq)
250 #define ICMPV4_GET_EMB_PROTO(p) (p)->icmpv4vars.emb_ip4_proto
252 #define ICMPV4_GET_EMB_IPV4(p) (p)->icmpv4vars.emb_ipv4h
254 #define ICMPV4_GET_EMB_TCP(p) (p)->icmpv4vars.emb_tcph
256 #define ICMPV4_GET_EMB_UDP(p) (p)->icmpv4vars.emb_udph
258 #define ICMPV4_GET_EMB_ICMPV4H(p) (p)->icmpv4vars.emb_icmpv4h
260 #define ICMPV4_GET_HLEN_ICMPV4H(p) (p)->icmpv4vars.hlen
267 #define ICMPV4_DEST_UNREACH_IS_VALID(p) ( \
268 (!((p)->flags & PKT_IS_INVALID)) && \
269 ((p)->icmpv4h != NULL) && \
270 (ICMPV4_GET_TYPE((p)) == ICMP_DEST_UNREACH) && \
271 (ICMPV4_GET_EMB_IPV4((p)) != NULL) && \
272 ((ICMPV4_GET_EMB_TCP((p)) != NULL) || \
273 (ICMPV4_GET_EMB_UDP((p)) != NULL)))
284 #define ICMPV4_IS_ERROR_MSG(p) (ICMPV4_GET_TYPE((p)) == ICMP_DEST_UNREACH || \
285 ICMPV4_GET_TYPE((p)) == ICMP_SOURCE_QUENCH || \
286 ICMPV4_GET_TYPE((p)) == ICMP_REDIRECT || \
287 ICMPV4_GET_TYPE((p)) == ICMP_TIME_EXCEEDED || \
288 ICMPV4_GET_TYPE((p)) == ICMP_PARAMETERPROB)
302 static inline uint16_t ICMPV4CalculateChecksum(
const uint16_t *pkt, uint16_t tlen)
305 uint32_t csum = pkt[0];
311 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4] + pkt[5] + pkt[6] +
312 pkt[7] + pkt[8] + pkt[9] + pkt[10] + pkt[11] + pkt[12] + pkt[13] +
319 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3];
325 csum += pkt[0] + pkt[1];
337 *(uint8_t *)(&
pad) = (*(uint8_t *)pkt);
341 csum = (csum >> 16) + (csum & 0x0000FFFF);
342 csum += (csum >> 16);
344 return (uint16_t) ~csum;