1 mod dest_unreachable_code; 2 pub use dest_unreachable_code::*; 3 4 mod parameter_problem_code; 5 pub use parameter_problem_code::*; 6 7 mod parameter_problem_header; 8 pub use parameter_problem_header::*; 9 10 mod time_exceeded_code; 11 pub use time_exceeded_code::*; 12 13 /// The maximum number of bytes/octets the ICMPv6 part of a packet can contain. 14 /// 15 /// The value is determined by the maximum value of the "Upper-Layer Packet Length" 16 /// field. This field is not directly part of the packet but used during the checksum 17 /// calculation in the pseudo header. 18 /// 19 /// The "Upper-Layer Packet Length" is represented as an `u32` and defined as 20 /// "...the Payload Length from the IPv6 header, minus the length of any 21 /// extension headers present between the IPv6 header and the upper-layer 22 /// header" (according to RFC 2460 Section 8.1). In other words, the length of the 23 /// ICMPv6 part of the packet. 24 /// 25 /// Therefor the maximum size of an ICMPv6 packet is `u32::MAX`. 26 pub const MAX_ICMPV6_BYTE_LEN: usize = u32::MAX as usize; 27 28 /// ICMPv6 type value indicating a "Destination Unreachable" message. 29 pub const TYPE_DST_UNREACH: u8 = 1; 30 31 /// ICMPv6 type value indicating a "Packet Too Big" message. 32 pub const TYPE_PACKET_TOO_BIG: u8 = 2; 33 34 /// ICMPv6 type value indicating a "Time Exceeded" message. 35 pub const TYPE_TIME_EXCEEDED: u8 = 3; 36 37 /// ICMPv6 type value indicating a "Parameter Problem" message. 38 pub const TYPE_PARAMETER_PROBLEM: u8 = 4; 39 40 /// ICMPv6 type value indicating an "Echo Request" message. 41 pub const TYPE_ECHO_REQUEST: u8 = 128; 42 43 /// ICMPv6 type value indicating an "Echo Reply" message. 44 pub const TYPE_ECHO_REPLY: u8 = 129; 45 46 /// ICMPv6 type value indicating a "Multicast Listener Query" message. 47 pub const TYPE_MULTICAST_LISTENER_QUERY: u8 = 130; 48 49 /// ICMPv6 type value indicating a "Multicast Listener Report" message. 50 pub const TYPE_MULTICAST_LISTENER_REPORT: u8 = 131; 51 52 /// ICMPv6 type value indicating a "Multicast Listener Done" message. 53 pub const TYPE_MULTICAST_LISTENER_REDUCTION: u8 = 132; 54 55 /// ICMPv6 type value indicating a "Router Solicitation" message. 56 pub const TYPE_ROUTER_SOLICITATION: u8 = 133; 57 58 /// ICMPv6 type value indicating a "Router Advertisement" message. 59 pub const TYPE_ROUTER_ADVERTISEMENT: u8 = 134; 60 61 /// ICMPv6 type value indicating a "Neighbor Solicitation" message. 62 pub const TYPE_NEIGHBOR_SOLICITATION: u8 = 135; 63 64 /// ICMPv6 type value indicating a "Neighbor Advertisement" message. 65 pub const TYPE_NEIGHBOR_ADVERTISEMENT: u8 = 136; 66 67 /// ICMPv6 type value indicating a "Redirect Message" message. 68 pub const TYPE_REDIRECT_MESSAGE: u8 = 137; 69 70 /// ICMPv6 type value indicating a "Router Renumbering" message. 71 pub const TYPE_ROUTER_RENUMBERING: u8 = 138; 72 73 /// ICMPv6 type value indicating a "Inverse Neighbor Discovery Solicitation" message. 74 pub const TYPE_INVERSE_NEIGHBOR_DISCOVERY_SOLICITATION: u8 = 141; 75 76 /// ICMPv6 type value indicating a "Inverse Neighbor Discovery Advertisement" message. 77 pub const TYPE_INVERSE_NEIGHBOR_DISCOVERY_ADVERTISEMENT: u8 = 142; 78 79 /// ICMPv6 type value indicating a "Extended Echo Request" message. 80 pub const TYPE_EXT_ECHO_REQUEST: u8 = 160; 81 82 /// ICMPv6 type value indicating a "Extended Echo Reply" message. 83 pub const TYPE_EXT_ECHO_REPLY: u8 = 161; 84 85 /// ICMPv6 destination unreachable code for "no route to destination". 86 pub const CODE_DST_UNREACH_NO_ROUTE: u8 = 0; 87 88 /// ICMPv6 destination unreachable code for "communication with 89 /// destination administratively prohibited". 90 pub const CODE_DST_UNREACH_PROHIBITED: u8 = 1; 91 92 /// ICMPv6 destination unreachable code for "beyond scope of source address". 93 pub const CODE_DST_UNREACH_BEYOND_SCOPE: u8 = 2; 94 95 /// ICMPv6 destination unreachable code for "address unreachable". 96 pub const CODE_DST_UNREACH_ADDR: u8 = 3; 97 98 /// ICMPv6 destination unreachable code for "port unreachable". 99 pub const CODE_DST_UNREACH_PORT: u8 = 4; 100 101 /// ICMPv6 destination unreachable code for "source address failed ingress/egress policy". 102 pub const CODE_DST_UNREACH_SOURCE_ADDRESS_FAILED_POLICY: u8 = 5; 103 104 /// ICMPv6 destination unreachable code for "reject route to destination". 105 pub const CODE_DST_UNREACH_REJECT_ROUTE_TO_DEST: u8 = 6; 106 107 /// ICMPv6 time exceeded code for "hop limit exceeded in transit" 108 pub const CODE_TIME_EXCEEDED_HOP_LIMIT_EXCEEDED: u8 = 0; 109 110 /// ICMPv6 time exceeded code for "fragment reassembly time exceeded" 111 pub const CODE_TIME_EXCEEDED_FRAGMENT_REASSEMBLY_TIME_EXCEEDED: u8 = 1; 112 113 /// ICMPv6 parameter problem code for "erroneous header field encountered" (from [RFC 4443](https://tools.ietf.org/html/rfc4443)). 114 pub const CODE_PARAM_PROBLEM_ERR_HEADER_FIELD: u8 = 0; 115 116 /// ICMPv6 parameter problem code for "unrecognized Next Header type encountered" (from [RFC 4443](https://tools.ietf.org/html/rfc4443)). 117 pub const CODE_PARAM_PROBLEM_UNRECOG_NEXT_HEADER: u8 = 1; 118 119 /// ICMPv6 parameter problem code for "unrecognized IPv6 option encountered" (from [RFC 4443](https://tools.ietf.org/html/rfc4443)). 120 pub const CODE_PARAM_PROBLEM_UNRECOG_IPV6_OPTION: u8 = 2; 121 122 /// ICMPv6 parameter problem code for "IPv6 First Fragment has incomplete IPv6 Header Chain" (from [RFC 7112](https://tools.ietf.org/html/rfc7112)). 123 pub const CODE_PARAM_PROBLEM_IPV6_FIRST_FRAG_INCOMP_HEADER_CHAIN: u8 = 3; 124 125 /// ICMPv6 parameter problem code for "SR Upper-layer Header Error" (from [RFC 8754](https://tools.ietf.org/html/rfc8754)). 126 pub const CODE_PARAM_PROBLEM_SR_UPPER_LAYER_HEADER_ERROR: u8 = 4; 127 128 /// ICMPv6 parameter problem code for "Unrecognized Next Header type encountered by intermediate node" (from [RFC 8883](https://tools.ietf.org/html/rfc8883)). 129 pub const CODE_PARAM_PROBLEM_UNRECOG_NEXT_HEADER_BY_INTERMEDIATE_NODE: u8 = 5; 130 131 /// ICMPv6 parameter problem code for "Extension header too big" (from [RFC 8883](https://tools.ietf.org/html/rfc8883)). 132 pub const CODE_PARAM_PROBLEM_EXT_HEADER_TOO_BIG: u8 = 6; 133 134 /// ICMPv6 parameter problem code for "Extension header chain too long" (from [RFC 8883](https://tools.ietf.org/html/rfc8883)). 135 pub const CODE_PARAM_PROBLEM_EXT_HEADER_CHAIN_TOO_LONG: u8 = 7; 136 137 /// ICMPv6 parameter problem code for "Too many extension headers" (from [RFC 8883](https://tools.ietf.org/html/rfc8883)). 138 pub const CODE_PARAM_PROBLEM_TOO_MANY_EXT_HEADERS: u8 = 8; 139 140 /// ICMPv6 parameter problem code for "Too many options in extension header" (from [RFC 8883](https://tools.ietf.org/html/rfc8883)). 141 pub const CODE_PARAM_PROBLEM_TOO_MANY_OPTIONS_EXT_HEADER: u8 = 9; 142 143 /// ICMPv6 parameter problem code for "Option too big" (from [RFC 8883](https://tools.ietf.org/html/rfc8883)). 144 pub const CODE_PARAM_PROBLEM_OPTION_TOO_BIG: u8 = 10; 145 146 #[cfg(test)] 147 mod test { 148 use super::*; 149 150 #[test] constants()151 fn constants() { 152 // type values according to 153 // https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-codes-16 154 assert_eq!(1, TYPE_DST_UNREACH); 155 assert_eq!(2, TYPE_PACKET_TOO_BIG); 156 assert_eq!(3, TYPE_TIME_EXCEEDED); 157 assert_eq!(4, TYPE_PARAMETER_PROBLEM); 158 assert_eq!(128, TYPE_ECHO_REQUEST); 159 assert_eq!(129, TYPE_ECHO_REPLY); 160 assert_eq!(130, TYPE_MULTICAST_LISTENER_QUERY); 161 assert_eq!(131, TYPE_MULTICAST_LISTENER_REPORT); 162 assert_eq!(132, TYPE_MULTICAST_LISTENER_REDUCTION); 163 assert_eq!(133, TYPE_ROUTER_SOLICITATION); 164 assert_eq!(134, TYPE_ROUTER_ADVERTISEMENT); 165 assert_eq!(135, TYPE_NEIGHBOR_SOLICITATION); 166 assert_eq!(136, TYPE_NEIGHBOR_ADVERTISEMENT); 167 assert_eq!(137, TYPE_REDIRECT_MESSAGE); 168 assert_eq!(138, TYPE_ROUTER_RENUMBERING); 169 assert_eq!(141, TYPE_INVERSE_NEIGHBOR_DISCOVERY_SOLICITATION); 170 assert_eq!(142, TYPE_INVERSE_NEIGHBOR_DISCOVERY_ADVERTISEMENT); 171 assert_eq!(160, TYPE_EXT_ECHO_REQUEST); 172 assert_eq!(161, TYPE_EXT_ECHO_REPLY); 173 174 // destination unreachable code values according to 175 // https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-codes-2 176 assert_eq!(0, CODE_DST_UNREACH_NO_ROUTE); 177 assert_eq!(1, CODE_DST_UNREACH_PROHIBITED); 178 assert_eq!(2, CODE_DST_UNREACH_BEYOND_SCOPE); 179 assert_eq!(3, CODE_DST_UNREACH_ADDR); 180 assert_eq!(4, CODE_DST_UNREACH_PORT); 181 assert_eq!(5, CODE_DST_UNREACH_SOURCE_ADDRESS_FAILED_POLICY); 182 assert_eq!(6, CODE_DST_UNREACH_REJECT_ROUTE_TO_DEST); 183 184 // time exceeded code values according to 185 // https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-codes-4 186 assert_eq!(0, CODE_TIME_EXCEEDED_HOP_LIMIT_EXCEEDED); 187 assert_eq!(1, CODE_TIME_EXCEEDED_FRAGMENT_REASSEMBLY_TIME_EXCEEDED); 188 189 // parameter problem codes according to 190 // https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-codes-5 191 assert_eq!(0, CODE_PARAM_PROBLEM_ERR_HEADER_FIELD); 192 assert_eq!(1, CODE_PARAM_PROBLEM_UNRECOG_NEXT_HEADER); 193 assert_eq!(2, CODE_PARAM_PROBLEM_UNRECOG_IPV6_OPTION); 194 assert_eq!(3, CODE_PARAM_PROBLEM_IPV6_FIRST_FRAG_INCOMP_HEADER_CHAIN); 195 assert_eq!(4, CODE_PARAM_PROBLEM_SR_UPPER_LAYER_HEADER_ERROR); 196 assert_eq!( 197 5, 198 CODE_PARAM_PROBLEM_UNRECOG_NEXT_HEADER_BY_INTERMEDIATE_NODE 199 ); 200 assert_eq!(6, CODE_PARAM_PROBLEM_EXT_HEADER_TOO_BIG); 201 assert_eq!(7, CODE_PARAM_PROBLEM_EXT_HEADER_CHAIN_TOO_LONG); 202 assert_eq!(8, CODE_PARAM_PROBLEM_TOO_MANY_EXT_HEADERS); 203 assert_eq!(9, CODE_PARAM_PROBLEM_TOO_MANY_OPTIONS_EXT_HEADER); 204 assert_eq!(10, CODE_PARAM_PROBLEM_OPTION_TOO_BIG); 205 } 206 } 207