24 #ifndef __DECODE_ICMPV4_H__
25 #define __DECODE_ICMPV4_H__
32 #define ICMPV4_HEADER_LEN 8
34 #ifndef ICMP_ECHOREPLY
35 #define ICMP_ECHOREPLY 0
37 #ifndef ICMP_DEST_UNREACH
38 #define ICMP_DEST_UNREACH 3
40 #ifndef ICMP_SOURCE_QUENCH
41 #define ICMP_SOURCE_QUENCH 4
44 #define ICMP_REDIRECT 5
49 #ifndef ICMP_ROUTERADVERT
50 #define ICMP_ROUTERADVERT 9
52 #ifndef ICMP_ROUTERSOLICIT
53 #define ICMP_ROUTERSOLICIT 10
55 #ifndef ICMP_TIME_EXCEEDED
56 #define ICMP_TIME_EXCEEDED 11
58 #ifndef ICMP_PARAMETERPROB
59 #define ICMP_PARAMETERPROB 12
61 #ifndef ICMP_TIMESTAMP
62 #define ICMP_TIMESTAMP 13
64 #ifndef ICMP_TIMESTAMPREPLY
65 #define ICMP_TIMESTAMPREPLY 14
67 #ifndef ICMP_INFO_REQUEST
68 #define ICMP_INFO_REQUEST 15
70 #ifndef ICMP_INFO_REPLY
71 #define ICMP_INFO_REPLY 16
74 #define ICMP_ADDRESS 17
76 #ifndef ICMP_ADDRESSREPLY
77 #define ICMP_ADDRESSREPLY 18
80 #define NR_ICMP_TYPES 18
85 #ifndef ICMP_NET_UNREACH
86 #define ICMP_NET_UNREACH 0
88 #ifndef ICMP_HOST_UNREACH
89 #define ICMP_HOST_UNREACH 1
91 #ifndef ICMP_PROT_UNREACH
92 #define ICMP_PROT_UNREACH 2
94 #ifndef ICMP_PORT_UNREACH
95 #define ICMP_PORT_UNREACH 3
97 #ifndef ICMP_FRAG_NEEDED
98 #define ICMP_FRAG_NEEDED 4
100 #ifndef ICMP_SR_FAILED
101 #define ICMP_SR_FAILED 5
103 #ifndef ICMP_NET_UNKNOWN
104 #define ICMP_NET_UNKNOWN 6
106 #ifndef ICMP_HOST_UNKNOWN
107 #define ICMP_HOST_UNKNOWN 7
109 #ifndef ICMP_HOST_ISOLATED
110 #define ICMP_HOST_ISOLATED 8
113 #define ICMP_NET_ANO 9
115 #ifndef ICMP_HOST_ANO
116 #define ICMP_HOST_ANO 10
118 #ifndef ICMP_NET_UNR_TOS
119 #define ICMP_NET_UNR_TOS 11
121 #ifndef ICMP_HOST_UNR_TOS
122 #define ICMP_HOST_UNR_TOS 12
124 #ifndef ICMP_PKT_FILTERED
125 #define ICMP_PKT_FILTERED 13
127 #ifndef ICMP_PREC_VIOLATION
128 #define ICMP_PREC_VIOLATION 14
131 #ifndef ICMP_PREC_CUTOFF
132 #define ICMP_PREC_CUTOFF 15
134 #ifndef NR_ICMP_UNREACH
135 #define NR_ICMP_UNREACH 15
139 #ifndef ICMP_REDIR_NET
140 #define ICMP_REDIR_NET 0
142 #ifndef ICMP_REDIR_HOST
143 #define ICMP_REDIR_HOST 1
145 #ifndef ICMP_REDIR_NETTOS
146 #define ICMP_REDIR_NETTOS 2
148 #ifndef ICMP_REDIR_HOSTTOS
149 #define ICMP_REDIR_HOSTTOS 3
154 #define ICMP_EXC_TTL 0
156 #ifndef ICMP_EXC_FRAGTIME
157 #define ICMP_EXC_FRAGTIME 1
161 #define ICMPV4_GET_TYPE(p) (p)->icmpv4h->type
163 #define ICMPV4_GET_CODE(p) (p)->icmpv4h->code
226 #define CLEAR_ICMPV4_PACKET(p) do { \
227 (p)->level4_comp_csum = -1; \
228 PACKET_CLEAR_L4VARS((p)); \
229 (p)->icmpv4h = NULL; \
232 #define ICMPV4_HEADER_PKT_OFFSET 8
235 #define ICMPV4_GET_TYPE(p) (p)->icmpv4h->type
237 #define ICMPV4_GET_CODE(p) (p)->icmpv4h->code
239 #define ICMPV4_GET_RAW_CSUM(p) SCNtohs((p)->icmpv4h->checksum)
240 #define ICMPV4_GET_CSUM(p) (p)->icmpv4h->checksum
245 #define ICMPV4_GET_ID(p) ((p)->icmpv4vars.id)
247 #define ICMPV4_GET_SEQ(p) ((p)->icmpv4vars.seq)
252 #define ICMPV4_GET_EMB_PROTO(p) (p)->icmpv4vars.emb_ip4_proto
254 #define ICMPV4_GET_EMB_IPV4(p) (p)->icmpv4vars.emb_ipv4h
256 #define ICMPV4_GET_EMB_TCP(p) (p)->icmpv4vars.emb_tcph
258 #define ICMPV4_GET_EMB_UDP(p) (p)->icmpv4vars.emb_udph
260 #define ICMPV4_GET_EMB_ICMPV4H(p) (p)->icmpv4vars.emb_icmpv4h
262 #define ICMPV4_GET_HLEN_ICMPV4H(p) (p)->icmpv4vars.hlen
269 #define ICMPV4_DEST_UNREACH_IS_VALID(p) ( \
270 (!((p)->flags & PKT_IS_INVALID)) && \
271 ((p)->icmpv4h != NULL) && \
272 (ICMPV4_GET_TYPE((p)) == ICMP_DEST_UNREACH) && \
273 (ICMPV4_GET_EMB_IPV4((p)) != NULL) && \
274 ((ICMPV4_GET_EMB_TCP((p)) != NULL) || \
275 (ICMPV4_GET_EMB_UDP((p)) != NULL)))
286 #define ICMPV4_IS_ERROR_MSG(p) (ICMPV4_GET_TYPE((p)) == ICMP_DEST_UNREACH || \
287 ICMPV4_GET_TYPE((p)) == ICMP_SOURCE_QUENCH || \
288 ICMPV4_GET_TYPE((p)) == ICMP_REDIRECT || \
289 ICMPV4_GET_TYPE((p)) == ICMP_TIME_EXCEEDED || \
290 ICMPV4_GET_TYPE((p)) == ICMP_PARAMETERPROB)
304 static inline uint16_t ICMPV4CalculateChecksum(
const uint16_t *pkt, uint16_t tlen)
307 uint32_t csum = pkt[0];
313 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4] + pkt[5] + pkt[6] +
314 pkt[7] + pkt[8] + pkt[9] + pkt[10] + pkt[11] + pkt[12] + pkt[13] +
321 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3];
327 csum += pkt[0] + pkt[1];
339 *(uint8_t *)(&
pad) = (*(uint8_t *)pkt);
343 csum = (csum >> 16) + (csum & 0x0000FFFF);
344 csum += (csum >> 16);
346 return (uint16_t) ~csum;