24 #ifndef SURICATA_DECODE_ICMPV6_H
25 #define SURICATA_DECODE_ICMPV6_H
31 #define ICMPV6_HEADER_LEN 8
32 #define ICMPV6_HEADER_PKT_OFFSET 8
36 #define ICMP6_DST_UNREACH 1
37 #define ICMP6_PACKET_TOO_BIG 2
38 #define ICMP6_TIME_EXCEEDED 3
39 #define ICMP6_PARAM_PROB 4
42 #define ICMP6_ECHO_REQUEST 128
43 #define ICMP6_ECHO_REPLY 129
45 #define MLD_LISTENER_QUERY 130
46 #define MLD_LISTENER_REPORT 131
47 #define MLD_LISTENER_REDUCTION 132
49 #define ND_ROUTER_SOLICIT 133
50 #define ND_ROUTER_ADVERT 134
51 #define ND_NEIGHBOR_SOLICIT 135
52 #define ND_NEIGHBOR_ADVERT 136
53 #define ND_REDIRECT 137
56 #define ICMP6_NI_QUERY 139
57 #define ICMP6_NI_REPLY 140
58 #define ND_INVERSE_SOLICIT 141
59 #define ND_INVERSE_ADVERT 142
60 #define MLD_V2_LIST_REPORT 143
61 #define HOME_AGENT_AD_REQUEST 144
62 #define HOME_AGENT_AD_REPLY 145
63 #define MOBILE_PREFIX_SOLICIT 146
64 #define MOBILE_PREFIX_ADVERT 147
65 #define CERT_PATH_SOLICIT 148
66 #define CERT_PATH_ADVERT 149
67 #define ICMP6_MOBILE_EXPERIMENTAL 150
68 #define MC_ROUTER_ADVERT 151
69 #define MC_ROUTER_SOLICIT 152
70 #define MC_ROUTER_TERMINATE 153
71 #define FMIPV6_MSG 154
72 #define RPL_CONTROL_MSG 155
73 #define LOCATOR_UDATE_MSG 156
74 #define DUPL_ADDR_REQUEST 157
75 #define DUPL_ADDR_CONFIRM 158
76 #define MPL_CONTROL_MSG 159
80 #define ICMP6_DST_UNREACH_NOROUTE 0
81 #define ICMP6_DST_UNREACH_ADMIN 1
83 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2
84 #define ICMP6_DST_UNREACH_ADDR 3
85 #define ICMP6_DST_UNREACH_NOPORT 4
86 #define ICMP6_DST_UNREACH_FAILEDPOLICY 5
87 #define ICMP6_DST_UNREACH_REJECTROUTE 6
91 #define ICMP6_TIME_EXCEED_TRANSIT 0
92 #define ICMP6_TIME_EXCEED_REASSEMBLY 1
95 #define ICMP6_PARAMPROB_HEADER 0
96 #define ICMP6_PARAMPROB_NEXTHEADER 1
97 #define ICMP6_PARAMPROB_OPTION 2
101 #define ICMPV6_GET_TYPE(icmp6h) (icmp6h)->type
103 #define ICMPV6_GET_CODE(icmp6h) (icmp6h)->code
107 #define ICMPV6_GET_ID(p) (p)->l4.vars.icmpv6.id
109 #define ICMPV6_GET_SEQ(p) (p)->l4.vars.icmpv6.seq
114 #define ICMPV6_HAS_MTU(icmp6h) ((icmp6h)->type == ICMP6_PACKET_TOO_BIG)
116 #define ICMPV6_GET_MTU(icmp6h) SCNtohl((icmp6h)->icmpv6b.icmpv6e.mtu)
119 #define ICMPV6_GET_EMB_PROTO(p) (p)->l4.vars.icmpv6.emb_ip6_proto_next
179 static inline uint16_t ICMPV6CalculateChecksum(
180 const uint16_t *shdr,
const uint16_t *pkt, uint16_t tlen)
183 uint32_t csum = shdr[0];
185 csum += shdr[1] + shdr[2] + shdr[3] + shdr[4] + shdr[5] + shdr[6] +
186 shdr[7] + shdr[8] + shdr[9] + shdr[10] + shdr[11] + shdr[12] +
187 shdr[13] + shdr[14] + shdr[15] + htons(58 + tlen);
195 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4] + pkt[5] + pkt[6] +
196 pkt[7] + pkt[8] + pkt[9] + pkt[10] + pkt[11] + pkt[12] + pkt[13] +
197 pkt[14] + pkt[15] + pkt[16] + pkt[17] + pkt[18] + pkt[19] +
198 pkt[20] + pkt[21] + pkt[22] + pkt[23] + pkt[24] + pkt[25] +
199 pkt[26] + pkt[27] + pkt[28] + pkt[29] + pkt[30] + pkt[31];
205 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3] + pkt[4] + pkt[5] + pkt[6] +
206 pkt[7] + pkt[8] + pkt[9] + pkt[10] + pkt[11] + pkt[12] + pkt[13] +
213 csum += pkt[0] + pkt[1] + pkt[2] + pkt[3];
219 csum += pkt[0] + pkt[1];
231 *(uint8_t *)(&
pad) = (*(uint8_t *)pkt);
235 csum = (csum >> 16) + (csum & 0x0000FFFF);
236 csum += (csum >> 16);
238 return (uint16_t) ~csum;