41 s =
format (s,
"IPv%s mtu: %u fragments: %u",
95 u16 mtu, len, max, rem, ip_frag_id, ip_frag_offset;
96 u8 *org_from_packet, more;
110 *error = IP_FRAG_ERROR_MALFORMED;
116 *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
123 *error = IP_FRAG_ERROR_DONT_FRAGMENT_SET;
142 u8 *from_data = (
void *) (ip4 + 1);
156 len = (rem > max ? max : rem);
161 *error = IP_FRAG_ERROR_MEMORY;
170 to_data = (
void *) (to_ip4 + 1);
173 u16 left_in_to_buffer = len, to_ptr = 0;
179 bytes_to_copy = left_in_to_buffer <= left_in_from_buffer ?
180 left_in_to_buffer : left_in_from_buffer;
181 clib_memcpy (to_data + to_ptr, from_data + ptr, bytes_to_copy);
182 left_in_to_buffer -= bytes_to_copy;
183 ptr += bytes_to_copy;
184 left_in_from_buffer -= bytes_to_copy;
185 if (left_in_to_buffer == 0)
188 ASSERT (left_in_from_buffer <= 0);
190 if (!(from_b->
flags & VLIB_BUFFER_NEXT_PRESENT))
192 *error = IP_FRAG_ERROR_MALFORMED;
199 to_ptr += bytes_to_copy;
206 clib_host_to_net_u16 ((fo >> 3) + ip_frag_offset);
208 clib_host_to_net_u16 (((len != rem) || more) << 13);
228 sizeof (*encap_header6));
248 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
253 u32 frag_sent = 0, small_packets = 0;
256 while (n_left_from > 0)
260 while (n_left_from > 0 && n_left_to_next > 0)
262 u32 pi0, *frag_from, frag_left;
274 error0 = IP_FRAG_ERROR_NONE;
287 tr->
ipv6 = is_ip6 ? 1 : 0;
292 if (!is_ip6 && error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET)
295 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
313 if (error0 == IP_FRAG_ERROR_NONE)
317 small_packets += (
vec_len (buffer) == 1);
330 while (frag_left > 0)
332 while (frag_left > 0 && n_left_to_next > 0)
335 i = to_next[0] = frag_from[0];
343 to_next, n_left_to_next, i,
357 IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
359 IP_FRAG_ERROR_SMALL_PACKET, small_packets);
390 u16 mtu, len, max, rem, ip_frag_id;
397 max = (mtu -
sizeof (
ip6_header_t) -
sizeof (ip6_frag_hdr_t)) & ~0x7;
402 *error = IP_FRAG_ERROR_MALFORMED;
407 if (ip6->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
409 *error = IP_FRAG_ERROR_MALFORMED;
413 u8 *from_data = (
void *) (ip6 + 1);
427 ip6_frag_hdr_t *to_frag_hdr;
432 (mtu -
sizeof (
ip6_header_t) -
sizeof (ip6_frag_hdr_t)) ? max : rem);
437 *error = IP_FRAG_ERROR_MEMORY;
446 to_frag_hdr = (ip6_frag_hdr_t *) (to_ip6 + 1);
447 to_data = (
void *) (to_frag_hdr + 1);
450 u16 left_in_to_buffer = len, to_ptr = 0;
456 bytes_to_copy = left_in_to_buffer <= left_in_from_buffer ?
457 left_in_to_buffer : left_in_from_buffer;
458 clib_memcpy (to_data + to_ptr, from_data + ptr, bytes_to_copy);
459 left_in_to_buffer -= bytes_to_copy;
460 ptr += bytes_to_copy;
461 left_in_from_buffer -= bytes_to_copy;
462 if (left_in_to_buffer == 0)
465 ASSERT (left_in_from_buffer <= 0);
467 if (!(from_b->
flags & VLIB_BUFFER_NEXT_PRESENT))
469 *error = IP_FRAG_ERROR_MALFORMED;
476 to_ptr += bytes_to_copy;
482 clib_host_to_net_u16 (len +
sizeof (ip6_frag_hdr_t));
483 to_ip6->
protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
484 to_frag_hdr->fragment_offset_and_more =
486 to_frag_hdr->identification = ip_frag_id;
487 to_frag_hdr->next_hdr = ip6->
protocol;
488 to_frag_hdr->rsv = 0;
496 #define _(sym,string) string, 505 .vector_size =
sizeof (
u32),
527 .vector_size =
sizeof (
u32),
static uword frag_node_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, u32 node_index, bool is_ip6)
#define foreach_ip_frag_error
void ip_frag_set_vnet_buffer(vlib_buffer_t *b, u16 mtu, u8 next_index, u8 flags)
#define IP6_FRAG_NODE_NAME
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static void frag_set_sw_if_index(vlib_buffer_t *to, vlib_buffer_t *from)
vlib_error_t * errors
Vector of errors for this node.
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
static u8 * format_ip_frag_trace(u8 *s, va_list *args)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static int ip4_is_fragment(const ip4_header_t *i)
static u32 running_fragment_id
void ip4_frag_do_fragment(vlib_main_t *vm, u32 from_bi, u32 **buffer, ip_frag_error_t *error)
static uword ip4_frag(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
void ip6_frag_do_fragment(vlib_main_t *vm, u32 from_bi, u32 **buffer, ip_frag_error_t *error)
u16 current_length
Nbytes between current data and the end of this buffer.
#define IP4_FRAG_NODE_NAME
static int ip4_get_fragment_offset(const ip4_header_t *i)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
vlib_node_registration_t ip6_frag_node
(constructor) VLIB_REGISTER_NODE (ip6_frag_node)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
#define IP4_HEADER_FLAG_MORE_FRAGMENTS
#define VLIB_REGISTER_NODE(x,...)
static void vlib_buffer_copy_trace_flag(vlib_main_t *vm, vlib_buffer_t *b, u32 bi_target)
#define vec_free(V)
Free vector's memory (no header).
void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
#define clib_memcpy(a, b, c)
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
#define VLIB_BUFFER_DATA_SIZE
#define IP_FRAG_FLAG_IP6_HEADER
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
#define IP_FRAG_FLAG_IP4_HEADER
u32 next_buffer
Next buffer for this linked-list of buffers.
static vlib_main_t * vlib_get_main(void)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
vlib_node_registration_t ip4_frag_node
(constructor) VLIB_REGISTER_NODE (ip4_frag_node)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
static char * ip4_frag_error_strings[]
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static void vlib_buffer_init_for_free_list(vlib_buffer_t *dst, vlib_buffer_free_list_t *fl)
static uword ip6_frag(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define IP4_HEADER_FLAG_DONT_FRAGMENT
#define ip6_frag_hdr_offset_and_more(offset, more)
static void vlib_buffer_free_one(vlib_main_t *vm, u32 buffer_index)
Free one buffer Shorthand to free a single buffer chain.
static vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, vlib_buffer_free_list_index_t free_list_index)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip4_header_checksum(ip4_header_t *i)
static vlib_buffer_t * frag_buffer_alloc(vlib_buffer_t *org_b, u32 *bi)