blob: 2af697e96b6ab548d3351eb1090e5faa286dbb12 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*---------------------------------------------------------------------------
2 * Copyright (c) 2009-2014 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/*
17 * IPv4 Fragmentation Node
18 *
19 *
20 */
21
22#include "ip_frag.h"
23
24#include <vnet/ip/ip.h>
25
26
Dave Barachd7cb1b52016-12-09 09:52:16 -050027typedef struct
28{
Ed Warnickecb9cada2015-12-08 15:45:58 -070029 u8 ipv6;
30 u16 header_offset;
31 u16 mtu;
32 u8 next;
33 u16 n_fragments;
34} ip_frag_trace_t;
35
Dave Barachd7cb1b52016-12-09 09:52:16 -050036static u8 *
37format_ip_frag_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070038{
39 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
40 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Dave Barachd7cb1b52016-12-09 09:52:16 -050041 ip_frag_trace_t *t = va_arg (*args, ip_frag_trace_t *);
42 s = format (s, "IPv%s offset: %u mtu: %u fragments: %u",
43 t->ipv6 ? "6" : "4", t->header_offset, t->mtu, t->n_fragments);
Ed Warnickecb9cada2015-12-08 15:45:58 -070044 return s;
45}
46
47static u32 running_fragment_id;
48
49static void
Dave Barachd7cb1b52016-12-09 09:52:16 -050050ip4_frag_do_fragment (vlib_main_t * vm, u32 pi, u32 ** buffer,
51 ip_frag_error_t * error)
Ed Warnickecb9cada2015-12-08 15:45:58 -070052{
53 vlib_buffer_t *p;
54 ip4_header_t *ip4;
Dave Barachd7cb1b52016-12-09 09:52:16 -050055 u16 mtu, ptr, len, max, rem, offset, ip_frag_id, ip_frag_offset;
Ed Warnickecb9cada2015-12-08 15:45:58 -070056 u8 *packet, more;
57
Dave Barachd7cb1b52016-12-09 09:52:16 -050058 vec_add1 (*buffer, pi);
59 p = vlib_get_buffer (vm, pi);
60 offset = vnet_buffer (p)->ip_frag.header_offset;
61 mtu = vnet_buffer (p)->ip_frag.mtu;
62 packet = (u8 *) vlib_buffer_get_current (p);
63 ip4 = (ip4_header_t *) (packet + offset);
Ed Warnickecb9cada2015-12-08 15:45:58 -070064
Dave Barachd7cb1b52016-12-09 09:52:16 -050065 rem = clib_net_to_host_u16 (ip4->length) - sizeof (*ip4);
Ed Warnickecb9cada2015-12-08 15:45:58 -070066 ptr = 0;
Dave Barachd7cb1b52016-12-09 09:52:16 -050067 max = (mtu - sizeof (*ip4) - vnet_buffer (p)->ip_frag.header_offset) & ~0x7;
Ed Warnickecb9cada2015-12-08 15:45:58 -070068
Dave Barachd7cb1b52016-12-09 09:52:16 -050069 if (rem < (p->current_length - offset - sizeof (*ip4)))
70 {
71 *error = IP_FRAG_ERROR_MALFORMED;
72 return;
73 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070074
Dave Barachd7cb1b52016-12-09 09:52:16 -050075 if (mtu < sizeof (*ip4))
76 {
77 *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
78 return;
79 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
81 if (ip4->flags_and_fragment_offset &
Dave Barachd7cb1b52016-12-09 09:52:16 -050082 clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT))
83 {
84 *error = IP_FRAG_ERROR_DONT_FRAGMENT_SET;
85 return;
86 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070087
Dave Barachd7cb1b52016-12-09 09:52:16 -050088 if (ip4_is_fragment (ip4))
89 {
90 ip_frag_id = ip4->fragment_id;
91 ip_frag_offset = ip4_get_fragment_offset (ip4);
92 more =
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -080093 !(!(ip4->flags_and_fragment_offset &
94 clib_host_to_net_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS)));
Dave Barachd7cb1b52016-12-09 09:52:16 -050095 }
96 else
97 {
98 ip_frag_id = (++running_fragment_id);
99 ip_frag_offset = 0;
100 more = 0;
101 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102
103 //Do the actual fragmentation
Dave Barachd7cb1b52016-12-09 09:52:16 -0500104 while (rem)
105 {
106 u32 bi;
107 vlib_buffer_t *b;
108 ip4_header_t *fip4;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109
Dave Barachd7cb1b52016-12-09 09:52:16 -0500110 len =
111 (rem >
112 (mtu - sizeof (*ip4) -
113 vnet_buffer (p)->ip_frag.header_offset)) ? max : rem;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114
Dave Barachd7cb1b52016-12-09 09:52:16 -0500115 if (ptr == 0)
116 {
117 bi = pi;
118 b = p;
119 fip4 = (ip4_header_t *) (vlib_buffer_get_current (b) + offset);
120 }
121 else
122 {
123 if (!vlib_buffer_alloc (vm, &bi, 1))
124 {
125 *error = IP_FRAG_ERROR_MEMORY;
126 return;
127 }
128 vec_add1 (*buffer, bi);
129 b = vlib_get_buffer (vm, bi);
130 vnet_buffer (b)->sw_if_index[VLIB_RX] =
131 vnet_buffer (p)->sw_if_index[VLIB_RX];
132 vnet_buffer (b)->sw_if_index[VLIB_TX] =
133 vnet_buffer (p)->sw_if_index[VLIB_TX];
134 fip4 = (ip4_header_t *) (vlib_buffer_get_current (b) + offset);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135
Dave Barachd7cb1b52016-12-09 09:52:16 -0500136 //Copy offset and ip4 header
137 clib_memcpy (b->data, packet, offset + sizeof (*ip4));
138 //Copy data
139 clib_memcpy (((u8 *) (fip4)) + sizeof (*fip4),
140 packet + offset + sizeof (*fip4) + ptr, len);
141 }
142 b->current_length = offset + len + sizeof (*fip4);
143
144 fip4->fragment_id = ip_frag_id;
145 fip4->flags_and_fragment_offset =
146 clib_host_to_net_u16 ((ptr >> 3) + ip_frag_offset);
147 fip4->flags_and_fragment_offset |=
148 clib_host_to_net_u16 (((len != rem) || more) << 13);
149 // ((len0 != rem0) || more0) << 13 is optimization for
150 // ((len0 != rem0) || more0) ? IP4_HEADER_FLAG_MORE_FRAGMENTS : 0
151 fip4->length = clib_host_to_net_u16 (len + sizeof (*fip4));
152 fip4->checksum = ip4_header_checksum (fip4);
153
154 if (vnet_buffer (p)->ip_frag.flags & IP_FRAG_FLAG_IP4_HEADER)
155 {
156 //Encapsulating ipv4 header
157 ip4_header_t *encap_header4 =
158 (ip4_header_t *) vlib_buffer_get_current (b);
159 encap_header4->length = clib_host_to_net_u16 (b->current_length);
160 encap_header4->checksum = ip4_header_checksum (encap_header4);
161 }
162 else if (vnet_buffer (p)->ip_frag.flags & IP_FRAG_FLAG_IP6_HEADER)
163 {
164 //Encapsulating ipv6 header
165 ip6_header_t *encap_header6 =
166 (ip6_header_t *) vlib_buffer_get_current (b);
167 encap_header6->payload_length =
168 clib_host_to_net_u16 (b->current_length -
169 sizeof (*encap_header6));
170 }
171
172 rem -= len;
173 ptr += len;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700174 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175}
176
Ole Troan9fb87552016-01-13 22:30:43 +0100177void
Dave Barachd7cb1b52016-12-09 09:52:16 -0500178ip_frag_set_vnet_buffer (vlib_buffer_t * b, u16 offset, u16 mtu,
179 u8 next_index, u8 flags)
Ole Troan9fb87552016-01-13 22:30:43 +0100180{
Dave Barachd7cb1b52016-12-09 09:52:16 -0500181 vnet_buffer (b)->ip_frag.header_offset = offset;
182 vnet_buffer (b)->ip_frag.mtu = mtu;
183 vnet_buffer (b)->ip_frag.next_index = next_index;
184 vnet_buffer (b)->ip_frag.flags = flags;
Ole Troan9fb87552016-01-13 22:30:43 +0100185}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186
187static uword
Dave Barachd7cb1b52016-12-09 09:52:16 -0500188ip4_frag (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700189{
190 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500191 vlib_node_runtime_t *error_node =
192 vlib_node_get_runtime (vm, ip4_frag_node.index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700193 from = vlib_frame_vector_args (frame);
194 n_left_from = frame->n_vectors;
195 next_index = node->cached_next_index;
196 u32 frag_sent = 0, small_packets = 0;
197 u32 *buffer = 0;
198
Dave Barachd7cb1b52016-12-09 09:52:16 -0500199 while (n_left_from > 0)
200 {
201 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202
Dave Barachd7cb1b52016-12-09 09:52:16 -0500203 while (n_left_from > 0 && n_left_to_next > 0)
204 {
205 u32 pi0, *frag_from, frag_left;
206 vlib_buffer_t *p0;
207 ip_frag_error_t error0;
208 ip4_frag_next_t next0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700209
Dave Barachd7cb1b52016-12-09 09:52:16 -0500210 //Note: The packet is not enqueued now.
211 //It is instead put in a vector where other fragments
212 //will be put as well.
213 pi0 = from[0];
214 from += 1;
215 n_left_from -= 1;
216 error0 = IP_FRAG_ERROR_NONE;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700217
Dave Barachd7cb1b52016-12-09 09:52:16 -0500218 p0 = vlib_get_buffer (vm, pi0);
219 ip4_frag_do_fragment (vm, pi0, &buffer, &error0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700220
Dave Barachd7cb1b52016-12-09 09:52:16 -0500221 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
222 {
223 ip_frag_trace_t *tr =
224 vlib_add_trace (vm, node, p0, sizeof (*tr));
225 tr->header_offset = vnet_buffer (p0)->ip_frag.header_offset;
226 tr->mtu = vnet_buffer (p0)->ip_frag.mtu;
227 tr->ipv6 = 0;
228 tr->n_fragments = vec_len (buffer);
229 tr->next = vnet_buffer (p0)->ip_frag.next_index;
230 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700231
Dave Barachd7cb1b52016-12-09 09:52:16 -0500232 if (error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET)
233 {
234 icmp4_error_set_vnet_buffer (p0, ICMP4_destination_unreachable,
235 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
236 vnet_buffer (p0)->ip_frag.mtu);
237 vlib_buffer_advance (p0,
238 vnet_buffer (p0)->ip_frag.header_offset);
239 next0 = IP4_FRAG_NEXT_ICMP_ERROR;
240 }
241 else
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800242 {
243 /* *INDENT-OFF* */
244 next0 = (error0 == IP_FRAG_ERROR_NONE) ? vnet_buffer (p0)->
245 ip_frag.next_index : IP4_FRAG_NEXT_DROP;
246 /* *INDENT-ON* */
247 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700248
Dave Barachd7cb1b52016-12-09 09:52:16 -0500249 if (error0 == IP_FRAG_ERROR_NONE)
250 {
251 frag_sent += vec_len (buffer);
252 small_packets += (vec_len (buffer) == 1);
253 }
254 else
255 vlib_error_count (vm, ip4_frag_node.index, error0, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256
Dave Barachd7cb1b52016-12-09 09:52:16 -0500257 //Send fragments that were added in the frame
258 frag_from = buffer;
259 frag_left = vec_len (buffer);
260
261 while (frag_left > 0)
262 {
263 while (frag_left > 0 && n_left_to_next > 0)
264 {
265 u32 i;
266 i = to_next[0] = frag_from[0];
267 frag_from += 1;
268 frag_left -= 1;
269 to_next += 1;
270 n_left_to_next -= 1;
271
272 vlib_get_buffer (vm, i)->error = error_node->errors[error0];
273 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
274 to_next, n_left_to_next, i,
275 next0);
276 }
277 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
278 vlib_get_next_frame (vm, node, next_index, to_next,
279 n_left_to_next);
280 }
281 vec_reset_length (buffer);
282 }
283 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500285 vec_free (buffer);
286
287 vlib_node_increment_counter (vm, ip4_frag_node.index,
288 IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
289 vlib_node_increment_counter (vm, ip4_frag_node.index,
290 IP_FRAG_ERROR_SMALL_PACKET, small_packets);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700291
292 return frame->n_vectors;
293}
294
Dave Barachd7cb1b52016-12-09 09:52:16 -0500295
296static void
297ip6_frag_do_fragment (vlib_main_t * vm, u32 pi, u32 ** buffer,
298 ip_frag_error_t * error)
299{
300 vlib_buffer_t *p;
301 ip6_header_t *ip6_hdr;
302 ip6_frag_hdr_t *frag_hdr;
303 u8 *payload, *next_header;
304
305 p = vlib_get_buffer (vm, pi);
306
307 //Parsing the IPv6 headers
308 ip6_hdr =
309 vlib_buffer_get_current (p) + vnet_buffer (p)->ip_frag.header_offset;
310 payload = (u8 *) (ip6_hdr + 1);
311 next_header = &ip6_hdr->protocol;
312 if (*next_header == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)
313 {
314 next_header = payload;
315 payload += payload[1] * 8;
316 }
317
318 if (*next_header == IP_PROTOCOL_IP6_DESTINATION_OPTIONS)
319 {
320 next_header = payload;
321 payload += payload[1] * 8;
322 }
323
324 if (*next_header == IP_PROTOCOL_IPV6_ROUTE)
325 {
326 next_header = payload;
327 payload += payload[1] * 8;
328 }
329
330 if (PREDICT_FALSE
331 (payload >= (u8 *) vlib_buffer_get_current (p) + p->current_length))
332 {
333 //A malicious packet could set an extension header with a too big size
334 //and make us modify another vlib_buffer
335 *error = IP_FRAG_ERROR_MALFORMED;
336 return;
337 }
338
339 u8 has_more;
340 u16 initial_offset;
341 if (*next_header == IP_PROTOCOL_IPV6_FRAGMENTATION)
342 {
343 //The fragmentation header is already there
344 frag_hdr = (ip6_frag_hdr_t *) payload;
345 has_more = ip6_frag_hdr_more (frag_hdr);
346 initial_offset = ip6_frag_hdr_offset (frag_hdr);
347 }
348 else
349 {
350 //Insert a fragmentation header in the packet
351 u8 nh = *next_header;
352 *next_header = IP_PROTOCOL_IPV6_FRAGMENTATION;
353 vlib_buffer_advance (p, -sizeof (*frag_hdr));
354 u8 *start = vlib_buffer_get_current (p);
355 memmove (start, start + sizeof (*frag_hdr),
356 payload - (start + sizeof (*frag_hdr)));
357 frag_hdr = (ip6_frag_hdr_t *) (payload - sizeof (*frag_hdr));
358 frag_hdr->identification = ++running_fragment_id;
359 frag_hdr->next_hdr = nh;
360 frag_hdr->rsv = 0;
361 has_more = 0;
362 initial_offset = 0;
363 }
364 payload = (u8 *) (frag_hdr + 1);
365
366 u16 headers_len = payload - (u8 *) vlib_buffer_get_current (p);
367 u16 max_payload = vnet_buffer (p)->ip_frag.mtu - headers_len;
368 u16 rem = p->current_length - headers_len;
369 u16 ptr = 0;
370
371 if (max_payload < 8)
372 {
373 *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
374 return;
375 }
376
377 while (rem)
378 {
379 u32 bi;
380 vlib_buffer_t *b;
381 u16 len = (rem > max_payload) ? (max_payload & ~0x7) : rem;
382 rem -= len;
383
384 if (ptr != 0)
385 {
386 if (!vlib_buffer_alloc (vm, &bi, 1))
387 {
388 *error = IP_FRAG_ERROR_MEMORY;
389 return;
390 }
391 b = vlib_get_buffer (vm, bi);
392 vnet_buffer (b)->sw_if_index[VLIB_RX] =
393 vnet_buffer (p)->sw_if_index[VLIB_RX];
394 vnet_buffer (b)->sw_if_index[VLIB_TX] =
395 vnet_buffer (p)->sw_if_index[VLIB_TX];
396 clib_memcpy (vlib_buffer_get_current (b),
397 vlib_buffer_get_current (p), headers_len);
398 clib_memcpy (vlib_buffer_get_current (b) + headers_len,
399 payload + ptr, len);
400 frag_hdr =
401 vlib_buffer_get_current (b) + headers_len - sizeof (*frag_hdr);
402 }
403 else
404 {
405 bi = pi;
406 b = vlib_get_buffer (vm, bi);
407 //frag_hdr already set here
408 }
409
410 ip6_hdr =
411 vlib_buffer_get_current (b) + vnet_buffer (p)->ip_frag.header_offset;
412 frag_hdr->fragment_offset_and_more =
413 ip6_frag_hdr_offset_and_more (initial_offset + (ptr >> 3),
414 (rem || has_more));
415 b->current_length = headers_len + len;
416 ip6_hdr->payload_length =
417 clib_host_to_net_u16 (b->current_length -
418 vnet_buffer (p)->ip_frag.header_offset -
419 sizeof (*ip6_hdr));
420
421 if (vnet_buffer (p)->ip_frag.flags & IP_FRAG_FLAG_IP4_HEADER)
422 {
423 //Encapsulating ipv4 header
424 ip4_header_t *encap_header4 =
425 (ip4_header_t *) vlib_buffer_get_current (b);
426 encap_header4->length = clib_host_to_net_u16 (b->current_length);
427 encap_header4->checksum = ip4_header_checksum (encap_header4);
428 }
429 else if (vnet_buffer (p)->ip_frag.flags & IP_FRAG_FLAG_IP6_HEADER)
430 {
431 //Encapsulating ipv6 header
432 ip6_header_t *encap_header6 =
433 (ip6_header_t *) vlib_buffer_get_current (b);
434 encap_header6->payload_length =
435 clib_host_to_net_u16 (b->current_length -
436 sizeof (*encap_header6));
437 }
438
439 vec_add1 (*buffer, bi);
440
441 ptr += len;
442 }
443}
444
445static uword
446ip6_frag (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
447{
448 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
449 vlib_node_runtime_t *error_node =
450 vlib_node_get_runtime (vm, ip6_frag_node.index);
451 from = vlib_frame_vector_args (frame);
452 n_left_from = frame->n_vectors;
453 next_index = node->cached_next_index;
454 u32 frag_sent = 0, small_packets = 0;
455 u32 *buffer = 0;
456
457 while (n_left_from > 0)
458 {
459 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
460
461 while (n_left_from > 0 && n_left_to_next > 0)
462 {
463 u32 pi0, *frag_from, frag_left;
464 vlib_buffer_t *p0;
465 ip_frag_error_t error0;
466 ip6_frag_next_t next0;
467
468 pi0 = from[0];
469 from += 1;
470 n_left_from -= 1;
471 error0 = IP_FRAG_ERROR_NONE;
472
473 p0 = vlib_get_buffer (vm, pi0);
474 ip6_frag_do_fragment (vm, pi0, &buffer, &error0);
475
476 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
477 {
478 ip_frag_trace_t *tr =
479 vlib_add_trace (vm, node, p0, sizeof (*tr));
480 tr->header_offset = vnet_buffer (p0)->ip_frag.header_offset;
481 tr->mtu = vnet_buffer (p0)->ip_frag.mtu;
482 tr->ipv6 = 1;
483 tr->n_fragments = vec_len (buffer);
484 tr->next = vnet_buffer (p0)->ip_frag.next_index;
485 }
486
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800487 /* *INDENT-OFF* */
488 next0 = (error0 == IP_FRAG_ERROR_NONE) ? vnet_buffer (p0)->
Dave Barachd7cb1b52016-12-09 09:52:16 -0500489 ip_frag.next_index : IP6_FRAG_NEXT_DROP;
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800490 /* *INDENT-ON* */
491
Dave Barachd7cb1b52016-12-09 09:52:16 -0500492 frag_sent += vec_len (buffer);
493 small_packets += (vec_len (buffer) == 1);
494
495 //Send fragments that were added in the frame
496 frag_from = buffer;
497 frag_left = vec_len (buffer);
498 while (frag_left > 0)
499 {
500 while (frag_left > 0 && n_left_to_next > 0)
501 {
502 u32 i;
503 i = to_next[0] = frag_from[0];
504 frag_from += 1;
505 frag_left -= 1;
506 to_next += 1;
507 n_left_to_next -= 1;
508
509 vlib_get_buffer (vm, i)->error = error_node->errors[error0];
510 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
511 to_next, n_left_to_next, i,
512 next0);
513 }
514 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
515 vlib_get_next_frame (vm, node, next_index, to_next,
516 n_left_to_next);
517 }
518 vec_reset_length (buffer);
519 }
520 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
521 }
522 vec_free (buffer);
523 vlib_node_increment_counter (vm, ip6_frag_node.index,
524 IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
525 vlib_node_increment_counter (vm, ip6_frag_node.index,
526 IP_FRAG_ERROR_SMALL_PACKET, small_packets);
527
528 return frame->n_vectors;
529}
530
531static char *ip4_frag_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700532#define _(sym,string) string,
533 foreach_ip_frag_error
534#undef _
535};
536
Dave Barachd7cb1b52016-12-09 09:52:16 -0500537/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700538VLIB_REGISTER_NODE (ip4_frag_node) = {
539 .function = ip4_frag,
540 .name = IP4_FRAG_NODE_NAME,
541 .vector_size = sizeof (u32),
542 .format_trace = format_ip_frag_trace,
543 .type = VLIB_NODE_TYPE_INTERNAL,
544
545 .n_errors = IP_FRAG_N_ERROR,
546 .error_strings = ip4_frag_error_strings,
547
548 .n_next_nodes = IP4_FRAG_N_NEXT,
549 .next_nodes = {
550 [IP4_FRAG_NEXT_IP4_LOOKUP] = "ip4-lookup",
551 [IP4_FRAG_NEXT_IP6_LOOKUP] = "ip6-lookup",
Ole Troan9fb87552016-01-13 22:30:43 +0100552 [IP4_FRAG_NEXT_ICMP_ERROR] = "ip4-icmp-error",
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800553 [IP4_FRAG_NEXT_DROP] = "ip4-drop"
Ed Warnickecb9cada2015-12-08 15:45:58 -0700554 },
555};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500556/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557
Dave Barachd7cb1b52016-12-09 09:52:16 -0500558/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700559VLIB_REGISTER_NODE (ip6_frag_node) = {
560 .function = ip6_frag,
561 .name = IP6_FRAG_NODE_NAME,
562 .vector_size = sizeof (u32),
563 .format_trace = format_ip_frag_trace,
564 .type = VLIB_NODE_TYPE_INTERNAL,
565
566 .n_errors = IP_FRAG_N_ERROR,
567 .error_strings = ip4_frag_error_strings,
568
569 .n_next_nodes = IP6_FRAG_N_NEXT,
570 .next_nodes = {
571 [IP6_FRAG_NEXT_IP4_LOOKUP] = "ip4-lookup",
572 [IP6_FRAG_NEXT_IP6_LOOKUP] = "ip6-lookup",
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800573 [IP6_FRAG_NEXT_DROP] = "ip6-drop"
Ed Warnickecb9cada2015-12-08 15:45:58 -0700574 },
575};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500576/* *INDENT-ON* */
577
578/*
579 * fd.io coding-style-patch-verification: ON
580 *
581 * Local Variables:
582 * eval: (c-set-style "gnu")
583 * End:
584 */