41 s =
format (s,
"IPv%s mtu: %u fragments: %u",
69 to->
flags |= VNET_BUFFER_F_QOS_DATA_VALID;
99 u16 mtu,
len, max, rem, ip_frag_id, ip_frag_offset;
100 u8 *org_from_packet, more;
115 *error = IP_FRAG_ERROR_MALFORMED;
121 *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
128 *error = IP_FRAG_ERROR_DONT_FRAGMENT_SET;
147 u8 *from_data = (
void *) (ip4 + 1);
161 len = (rem > max ? max : rem);
166 *error = IP_FRAG_ERROR_MEMORY;
175 to_data = (
void *) (to_ip4 + 1);
178 u16 left_in_to_buffer =
len, to_ptr = 0;
184 bytes_to_copy = left_in_to_buffer <= left_in_from_buffer ?
185 left_in_to_buffer : left_in_from_buffer;
187 left_in_to_buffer -= bytes_to_copy;
188 ptr += bytes_to_copy;
189 left_in_from_buffer -= bytes_to_copy;
190 if (left_in_to_buffer == 0)
193 ASSERT (left_in_from_buffer <= 0);
195 if (!(from_b->
flags & VLIB_BUFFER_NEXT_PRESENT))
197 *error = IP_FRAG_ERROR_MALFORMED;
204 to_ptr += bytes_to_copy;
211 clib_host_to_net_u16 ((fo >> 3) + ip_frag_offset);
213 clib_host_to_net_u16 (((len != rem) || more) << 13);
233 sizeof (*encap_header6));
253 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
258 u32 frag_sent = 0, small_packets = 0;
261 while (n_left_from > 0)
265 while (n_left_from > 0 && n_left_to_next > 0)
267 u32 pi0, *frag_from, frag_left;
279 error0 = IP_FRAG_ERROR_NONE;
292 tr->
ipv6 = is_ip6 ? 1 : 0;
297 if (!is_ip6 && error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET)
300 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
318 if (error0 == IP_FRAG_ERROR_NONE)
322 small_packets += (
vec_len (buffer) == 1);
335 while (frag_left > 0)
337 while (frag_left > 0 && n_left_to_next > 0)
340 i = to_next[0] = frag_from[0];
348 to_next, n_left_to_next, i,
362 IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
364 IP_FRAG_ERROR_SMALL_PACKET, small_packets);
395 u16 mtu,
len, max, rem, ip_frag_id;
402 max = (mtu -
sizeof (
ip6_header_t) -
sizeof (ip6_frag_hdr_t)) & ~0x7;
407 *error = IP_FRAG_ERROR_MALFORMED;
412 if (ip6->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
414 *error = IP_FRAG_ERROR_MALFORMED;
418 u8 *from_data = (
void *) (ip6 + 1);
432 ip6_frag_hdr_t *to_frag_hdr;
437 (mtu -
sizeof (
ip6_header_t) -
sizeof (ip6_frag_hdr_t)) ? max : rem);
442 *error = IP_FRAG_ERROR_MEMORY;
451 to_frag_hdr = (ip6_frag_hdr_t *) (to_ip6 + 1);
452 to_data = (
void *) (to_frag_hdr + 1);
455 u16 left_in_to_buffer =
len, to_ptr = 0;
461 bytes_to_copy = left_in_to_buffer <= left_in_from_buffer ?
462 left_in_to_buffer : left_in_from_buffer;
464 left_in_to_buffer -= bytes_to_copy;
465 ptr += bytes_to_copy;
466 left_in_from_buffer -= bytes_to_copy;
467 if (left_in_to_buffer == 0)
470 ASSERT (left_in_from_buffer <= 0);
472 if (!(from_b->
flags & VLIB_BUFFER_NEXT_PRESENT))
474 *error = IP_FRAG_ERROR_MALFORMED;
481 to_ptr += bytes_to_copy;
487 clib_host_to_net_u16 (len +
sizeof (ip6_frag_hdr_t));
488 to_ip6->
protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
489 to_frag_hdr->fragment_offset_and_more =
491 to_frag_hdr->identification = ip_frag_id;
492 to_frag_hdr->next_hdr = ip6->
protocol;
493 to_frag_hdr->rsv = 0;
501 #define _(sym,string) string, 510 .vector_size =
sizeof (
u32),
532 .vector_size =
sizeof (
u32),
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 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 clib_memcpy_fast(a, b, c)
u16 current_length
Nbytes between current data and the end of this buffer.
#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)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
#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_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)
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
#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.
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 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
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)
u32 next_buffer
Next buffer for this linked-list of buffers.
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
static char * ip4_frag_error_strings[]
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
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 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)