FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
icmp46_packet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  * icmp46_packet.h: ip4/ip6 icmp packet format
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #ifndef included_vnet_icmp46_packet_h
41 #define included_vnet_icmp46_packet_h
42 
43 #include <vnet/ethernet/packet.h>
44 #include <vnet/ip/ip6_packet.h>
45 
46 #define foreach_icmp4_type \
47  _ (0, echo_reply) \
48  _ (3, destination_unreachable) \
49  _ (4, source_quench) \
50  _ (5, redirect) \
51  _ (6, alternate_host_address) \
52  _ (8, echo_request) \
53  _ (9, router_advertisement) \
54  _ (10, router_solicitation) \
55  _ (11, time_exceeded) \
56  _ (12, parameter_problem) \
57  _ (13, timestamp_request) \
58  _ (14, timestamp_reply) \
59  _ (15, information_request) \
60  _ (16, information_reply) \
61  _ (17, address_mask_request) \
62  _ (18, address_mask_reply) \
63  _ (30, traceroute) \
64  _ (31, datagram_conversion_error) \
65  _ (32, mobile_host_redirect) \
66  _ (33, ip6_where_are_you) \
67  _ (34, ip6_i_am_here) \
68  _ (35, mobile_registration_request) \
69  _ (36, mobile_registration_reply) \
70  _ (37, domain_name_request) \
71  _ (38, domain_name_reply) \
72  _ (39, skip) \
73  _ (40, photuris)
74 
75 #define icmp_no_code 0
76 
77 #define foreach_icmp4_code \
78  _ (destination_unreachable, 0, destination_unreachable_net) \
79  _ (destination_unreachable, 1, destination_unreachable_host) \
80  _ (destination_unreachable, 2, protocol_unreachable) \
81  _ (destination_unreachable, 3, port_unreachable) \
82  _ (destination_unreachable, 4, fragmentation_needed_and_dont_fragment_set) \
83  _ (destination_unreachable, 5, source_route_failed) \
84  _ (destination_unreachable, 6, destination_network_unknown) \
85  _ (destination_unreachable, 7, destination_host_unknown) \
86  _ (destination_unreachable, 8, source_host_isolated) \
87  _ (destination_unreachable, 9, network_administratively_prohibited) \
88  _ (destination_unreachable, 10, host_administratively_prohibited) \
89  _ (destination_unreachable, 11, network_unreachable_for_type_of_service) \
90  _ (destination_unreachable, 12, host_unreachable_for_type_of_service) \
91  _ (destination_unreachable, 13, communication_administratively_prohibited) \
92  _ (destination_unreachable, 14, host_precedence_violation) \
93  _ (destination_unreachable, 15, precedence_cutoff_in_effect) \
94  _ (redirect, 0, network_redirect) \
95  _ (redirect, 1, host_redirect) \
96  _ (redirect, 2, type_of_service_and_network_redirect) \
97  _ (redirect, 3, type_of_service_and_host_redirect) \
98  _ (router_advertisement, 0, normal_router_advertisement) \
99  _ (router_advertisement, 16, does_not_route_common_traffic) \
100  _ (time_exceeded, 0, ttl_exceeded_in_transit) \
101  _ (time_exceeded, 1, fragment_reassembly_time_exceeded) \
102  _ (parameter_problem, 0, pointer_indicates_error) \
103  _ (parameter_problem, 1, missing_required_option) \
104  _ (parameter_problem, 2, bad_length)
105 
106 /* ICMPv6 */
107 #define foreach_icmp6_type \
108  _ (1, destination_unreachable) \
109  _ (2, packet_too_big) \
110  _ (3, time_exceeded) \
111  _ (4, parameter_problem) \
112  _ (128, echo_request) \
113  _ (129, echo_reply) \
114  _ (130, multicast_listener_request) \
115  _ (131, multicast_listener_report) \
116  _ (132, multicast_listener_done) \
117  _ (133, router_solicitation) \
118  _ (134, router_advertisement) \
119  _ (135, neighbor_solicitation) \
120  _ (136, neighbor_advertisement) \
121  _ (137, redirect) \
122  _ (138, router_renumbering) \
123  _ (139, node_information_request) \
124  _ (140, node_information_response) \
125  _ (141, inverse_neighbor_solicitation) \
126  _ (142, inverse_neighbor_advertisement) \
127  _ (143, multicast_listener_report_v2) \
128  _ (144, home_agent_address_discovery_request) \
129  _ (145, home_agent_address_discovery_reply) \
130  _ (146, mobile_prefix_solicitation) \
131  _ (147, mobile_prefix_advertisement) \
132  _ (148, certification_path_solicitation) \
133  _ (149, certification_path_advertisement) \
134  _ (151, multicast_router_advertisement) \
135  _ (152, multicast_router_solicitation) \
136  _ (153, multicast_router_termination) \
137  _ (154, fmipv6_messages)
138 
139 #define foreach_icmp6_code \
140  _ (destination_unreachable, 0, no_route_to_destination) \
141  _ (destination_unreachable, 1, destination_administratively_prohibited) \
142  _ (destination_unreachable, 2, beyond_scope_of_source_address) \
143  _ (destination_unreachable, 3, address_unreachable) \
144  _ (destination_unreachable, 4, port_unreachable) \
145  _ (destination_unreachable, 5, source_address_failed_policy) \
146  _ (destination_unreachable, 6, reject_route_to_destination) \
147  _ (time_exceeded, 0, ttl_exceeded_in_transit) \
148  _ (time_exceeded, 1, fragment_reassembly_time_exceeded) \
149  _ (parameter_problem, 0, erroneous_header_field) \
150  _ (parameter_problem, 1, unrecognized_next_header) \
151  _ (parameter_problem, 2, unrecognized_option) \
152  _ (parameter_problem, 3, first_fragment_has_incomplete_header_chain) \
153  _ (router_renumbering, 0, command) \
154  _ (router_renumbering, 1, result) \
155  _ (node_information_request, 0, data_contains_ip6_address) \
156  _ (node_information_request, 1, data_contains_name) \
157  _ (node_information_request, 2, data_contains_ip4_address) \
158  _ (node_information_response, 0, success) \
159  _ (node_information_response, 1, failed) \
160  _ (node_information_response, 2, unknown_request)
161 
162 typedef enum
163 {
164 #define _(n,f) ICMP4_##f = n,
166 #undef _
167 } icmp4_type_t;
168 
169 typedef enum
170 {
171 #define _(t,n,f) ICMP4_##t##_##f = n,
173 #undef _
174 } icmp4_code_t;
175 
176 typedef enum
177 {
178 #define _(n,f) ICMP6_##f = n,
180 #undef _
181 } icmp6_type_t;
182 
183 typedef enum
184 {
185 #define _(t,n,f) ICMP6_##t##_##f = n,
187 #undef _
188 } icmp6_code_t;
189 
190 typedef CLIB_PACKED (struct
191  {
192  u8 type;
193  u8 code;
194  /* IP checksum of icmp header plus data which follows. */
195  u16 checksum;
196  }) icmp46_header_t;
197 
198 /* ip6 neighbor discovery */
199 #define foreach_icmp6_neighbor_discovery_option \
200  _ (1, source_link_layer_address) \
201  _ (2, target_link_layer_address) \
202  _ (3, prefix_information) \
203  _ (4, redirected_header) \
204  _ (5, mtu) \
205  _ (6, nbma_shortcut_limit) \
206  _ (7, advertisement_interval) \
207  _ (8, home_agent_information) \
208  _ (9, source_address_list) \
209  _ (10, target_address_list) \
210  _ (11, cryptographically_generated_address) \
211  _ (12, rsa_signature) \
212  _ (13, timestamp) \
213  _ (14, nonce) \
214  _ (15, trust_anchor) \
215  _ (16, certificate) \
216  _ (17, ip_address_and_prefix) \
217  _ (18, new_router_prefix_information) \
218  _ (19, mobile_link_layer_address) \
219  _ (20, neighbor_advertisement_acknowledgment) \
220  _ (23, map) \
221  _ (24, route_information) \
222  _ (25, recursive_dns_server) \
223  _ (26, ra_flags_extension) \
224  _ (27, handover_key_request) \
225  _ (28, handover_key_reply) \
226  _ (29, handover_assist_information) \
227  _ (30, mobile_node_identifier) \
228  _ (31, dns_search_list) \
229  _ (138, card_request) \
230  _ (139, card_reply)
231 
233 {
234 #define _(n,f) ICMP6_NEIGHBOR_DISCOVERY_OPTION_##f = n,
236 #undef _
238 
239 typedef CLIB_PACKED (struct
240  {
241  /* Option type. */
242  u8 type;
243  /* Length of this header plus option data in 8 byte units. */
244  u8 n_data_u64s;
245  /* Option data follows. */
246  u8 data[0];
247  }) icmp6_neighbor_discovery_option_header_t;
248 
249 typedef CLIB_PACKED (struct
250  {
251  icmp6_neighbor_discovery_option_header_t header;
252  u8 dst_address_length;
253  u8 flags;
254 #define ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_FLAG_ON_LINK (1 << 7)
255 #define ICMP6_NEIGHBOR_DISCOVERY_PREFIX_INFORMATION_AUTO (1 << 6)
256  u32 valid_time;
257  u32 preferred_time;
258  u32 unused; ip6_address_t dst_address;
259  }) icmp6_neighbor_discovery_prefix_information_option_t;
260 
261 typedef CLIB_PACKED (struct
262  {
263  u8 type;
264  u8 aux_data_len_u32s;
265  u16 num_sources;
266  ip6_address_t mcast_addr; ip6_address_t source_addr[0];
267  }) icmp6_multicast_address_record_t;
268 
269 typedef CLIB_PACKED (struct
270  {
271  ip6_hop_by_hop_ext_t ext_hdr;
272  ip6_router_alert_option_t alert;
273  ip6_padN_option_t pad;
274  icmp46_header_t icmp;
275  u16 rsvd;
276  u16 num_addr_records;
277  icmp6_multicast_address_record_t records[0];
278  }) icmp6_multicast_listener_report_header_t;
279 
280 typedef CLIB_PACKED (struct
281  {
282  icmp6_neighbor_discovery_option_header_t header;
283  u8 reserved[6];
284  /* IP6 header plus payload follows. */
285  u8 data[0];
286  }) icmp6_neighbor_discovery_redirected_header_option_t;
287 
288 typedef CLIB_PACKED (struct
289  {
290  icmp6_neighbor_discovery_option_header_t header;
291  u16 unused; u32 mtu;
292  }) icmp6_neighbor_discovery_mtu_option_t;
293 
294 typedef CLIB_PACKED (struct
295  {
296  icmp6_neighbor_discovery_option_header_t header;
297  u8 ethernet_address[6];
298  })
299  icmp6_neighbor_discovery_ethernet_link_layer_address_option_t;
300 
301 typedef CLIB_PACKED (struct
302  {
303  icmp6_neighbor_discovery_option_header_t header;
304  u8 max_l2_address[6 + 8];
305  })
306  icmp6_neighbor_discovery_max_link_layer_address_option_t;
307 
308 /* Generic neighbor discover header. Used for router solicitations,
309  etc. */
310 typedef CLIB_PACKED (struct
311  {
312  icmp46_header_t icmp; u32 reserved_must_be_zero;
313  }) icmp6_neighbor_discovery_header_t;
314 
315 /* Router advertisement packet formats. */
316 typedef CLIB_PACKED (struct
317  {
318  icmp46_header_t icmp;
319  /* Current hop limit to use for outgoing packets. */
320  u8 current_hop_limit;
321  u8 flags;
322 #define ICMP6_ROUTER_DISCOVERY_FLAG_ADDRESS_CONFIG_VIA_DHCP (1 << 7)
323 #define ICMP6_ROUTER_DISCOVERY_FLAG_OTHER_CONFIG_VIA_DHCP (1 << 6)
324  /* Zero means unspecified. */
325  u16 router_lifetime_in_sec;
326  /* Zero means unspecified. */
327  u32 neighbor_reachable_time_in_msec;
328  /* Zero means unspecified. */
329  u32
330  time_in_msec_between_retransmitted_neighbor_solicitations;
331  /* Options that may follow: source_link_layer_address, mtu, prefix_information. */
332  }) icmp6_router_advertisement_header_t;
333 
334 /* Neighbor solicitation/advertisement header. */
335 typedef CLIB_PACKED (struct
336  {
337  icmp46_header_t icmp;
338  /* Zero for solicitation; flags for advertisement. */
339  u32 advertisement_flags;
340  /* Set when sent by a router. */
341 #define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_ROUTER (1 << 31)
342  /* Set when response to solicitation. */
343 #define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED (1 << 30)
344 #define ICMP6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERRIDE (1 << 29)
345  ip6_address_t target_address;
346  /* Options that may follow: source_link_layer_address
347  (for solicitation) target_link_layer_address (for advertisement). */
348  }) icmp6_neighbor_solicitation_or_advertisement_header_t;
349 
350 typedef CLIB_PACKED (struct
351  {
352  icmp46_header_t icmp;
353  u32 reserved_must_be_zero;
354  /* Better next hop to use for given destination. */
355  ip6_address_t better_next_hop_address;
356  ip6_address_t dst_address;
357  /* Options that may follow: target_link_layer_address,
358  redirected_header. */
359  }) icmp6_redirect_header_t;
360 
361 /* Solicitation/advertisement packet format for ethernet. */
362 typedef CLIB_PACKED (struct
363  {
364  ip6_header_t ip;
365  icmp6_neighbor_solicitation_or_advertisement_header_t
366  neighbor;
367  icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
368  link_layer_option;
369  }) icmp6_neighbor_solicitation_header_t;
370 
371 /* Router solicitation packet format for ethernet. */
372 typedef CLIB_PACKED (struct
373  {
374  ip6_header_t ip;
375  icmp6_neighbor_discovery_header_t neighbor;
376  icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
377  link_layer_option;
378  }) icmp6_router_solicitation_header_t;
379 
380 /* router advertisement packet format for ethernet. */
381 typedef CLIB_PACKED (struct
382  {
383  ip6_header_t ip;
384  icmp6_router_advertisement_header_t router;
385  icmp6_neighbor_discovery_ethernet_link_layer_address_option_t
386  link_layer_option;
387  icmp6_neighbor_discovery_mtu_option_t mtu_option;
388  icmp6_neighbor_discovery_prefix_information_option_t
389  prefix[0];
390  }) icmp6_router_advertisement_packet_t;
391 
392 /* multicast listener report packet format for ethernet. */
393 typedef CLIB_PACKED (struct
394  {
395  ip6_header_t ip;
396  icmp6_multicast_listener_report_header_t report_hdr;
397  }) icmp6_multicast_listener_report_packet_t;
398 
399 #endif /* included_vnet_icmp46_packet_h */
#define foreach_icmp4_code
Definition: icmp46_packet.h:77
u8 pad[3]
log2 (size of the packing page block)
Definition: bihash_doc.h:61
u32 flags
Definition: vhost_user.h:115
icmp6_code_t
#define foreach_icmp6_code
u8 data[128]
Definition: ipsec.api:248
unsigned char u8
Definition: types.h:56
unsigned int u32
Definition: types.h:88
#define foreach_icmp6_neighbor_discovery_option
icmp4_code_t
unsigned short u16
Definition: types.h:57
enum icmp6_neighbor_discovery_option_type icmp6_neighbor_discovery_option_type_t
typedef CLIB_PACKED(struct { u8 type;u8 code;u16 checksum;}) icmp46_header_t
#define foreach_icmp4_type
Definition: icmp46_packet.h:46
icmp4_type_t
#define foreach_icmp6_type
icmp6_neighbor_discovery_option_type
icmp6_type_t
typedef prefix
Definition: ip_types.api:35