40 s =
format (s,
"IPv%s mtu: %u fragments: %u next: %d",
68 to->
flags |= VNET_BUFFER_F_QOS_DATA_VALID;
99 u16 len, max, rem, ip_frag_id, ip_frag_offset;
100 u8 *org_from_packet, more;
114 return IP_FRAG_ERROR_MALFORMED;
119 return IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
125 return IP_FRAG_ERROR_DONT_FRAGMENT_SET;
143 u8 *from_data = (
void *) (ip4 + 1);
146 u16 left_in_from_buffer =
158 len = (rem > max ? max : rem);
163 return IP_FRAG_ERROR_MEMORY;
172 to_ip4 = (
ip4_header_t *) (to_data + l2unfragmentablesize);
173 to_data = (
void *) (to_ip4 + 1);
176 to_b->
flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
178 if (from_b->
flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID)
184 to_b->
flags |= VNET_BUFFER_F_L4_HDR_OFFSET_VALID;
188 u16 left_in_to_buffer =
len, to_ptr = 0;
194 bytes_to_copy = left_in_to_buffer <= left_in_from_buffer ?
195 left_in_to_buffer : left_in_from_buffer;
197 left_in_to_buffer -= bytes_to_copy;
198 ptr += bytes_to_copy;
199 left_in_from_buffer -= bytes_to_copy;
200 if (left_in_to_buffer == 0)
203 ASSERT (left_in_from_buffer <= 0);
205 if (!(from_b->
flags & VLIB_BUFFER_NEXT_PRESENT))
207 return IP_FRAG_ERROR_MALFORMED;
213 to_ptr += bytes_to_copy;
216 to_b->
flags |= VNET_BUFFER_F_IS_IP4;
222 clib_host_to_net_u16 ((fo >> 3) + ip_frag_offset);
224 clib_host_to_net_u16 (((len != rem) || more) << 13);
229 to_b->
flags &= ~VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
235 return IP_FRAG_ERROR_NONE;
251 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
256 u32 frag_sent = 0, small_packets = 0;
259 while (n_left_from > 0)
263 while (n_left_from > 0 && n_left_to_next > 0)
265 u32 pi0, *frag_from, frag_left;
290 tr->
ipv6 = is_ip6 ? 1 : 0;
295 if (!is_ip6 && error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET)
298 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
304 next0 = (error0 == IP_FRAG_ERROR_NONE ?
309 if (error0 == IP_FRAG_ERROR_NONE)
313 small_packets += (
vec_len (buffer) == 1);
326 while (frag_left > 0)
328 while (frag_left > 0 && n_left_to_next > 0)
331 i = to_next[0] = frag_from[0];
339 to_next, n_left_to_next, i,
353 IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
355 IP_FRAG_ERROR_SMALL_PACKET, small_packets);
387 u16 len, max, rem, ip_frag_id;
395 max = (mtu -
sizeof (
ip6_header_t) -
sizeof (ip6_frag_hdr_t)) & ~0x7;
400 return IP_FRAG_ERROR_MALFORMED;
404 if (ip6->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION)
406 return IP_FRAG_ERROR_MALFORMED;
409 u8 *from_data = (
void *) (ip6 + 1);
412 u16 left_in_from_buffer =
424 ip6_frag_hdr_t *to_frag_hdr;
429 (mtu -
sizeof (
ip6_header_t) -
sizeof (ip6_frag_hdr_t)) ? max : rem);
434 return IP_FRAG_ERROR_MEMORY;
443 to_frag_hdr = (ip6_frag_hdr_t *) (to_ip6 + 1);
444 to_data = (
void *) (to_frag_hdr + 1);
447 to_b->
flags |= VNET_BUFFER_F_L3_HDR_OFFSET_VALID;
449 if (from_b->
flags & VNET_BUFFER_F_L4_HDR_OFFSET_VALID)
455 to_b->
flags |= VNET_BUFFER_F_L4_HDR_OFFSET_VALID;
457 to_b->
flags |= VNET_BUFFER_F_IS_IP6;
460 u16 left_in_to_buffer =
len, to_ptr = 0;
466 bytes_to_copy = left_in_to_buffer <= left_in_from_buffer ?
467 left_in_to_buffer : left_in_from_buffer;
469 left_in_to_buffer -= bytes_to_copy;
470 ptr += bytes_to_copy;
471 left_in_from_buffer -= bytes_to_copy;
472 if (left_in_to_buffer == 0)
475 ASSERT (left_in_from_buffer <= 0);
477 if (!(from_b->
flags & VLIB_BUFFER_NEXT_PRESENT))
479 return IP_FRAG_ERROR_MALFORMED;
485 to_ptr += bytes_to_copy;
491 clib_host_to_net_u16 (len +
sizeof (ip6_frag_hdr_t));
492 to_ip6->
protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
493 to_frag_hdr->fragment_offset_and_more =
495 to_frag_hdr->identification = ip_frag_id;
496 to_frag_hdr->next_hdr = ip6->
protocol;
497 to_frag_hdr->rsv = 0;
503 return IP_FRAG_ERROR_NONE;
507 #define _(sym,string) string, 516 .vector_size =
sizeof (
u32),
539 .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)
vl_api_wireguard_peer_flags_t flags
#define IP6_FRAG_NODE_NAME
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
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
description fragment has unexpected format
static uword ip4_frag(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
vl_api_fib_path_type_t type
vlib_error_t error
Error code for buffers to be enqueued to error handler.
#define IP4_FRAG_NODE_NAME
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
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)
ip_frag_error_t ip6_frag_do_fragment(vlib_main_t *vm, u32 from_bi, u16 mtu, u16 l2unfragmentablesize, u32 **buffer)
sll srl srl sll sra u16x4 i
static u16 ip4_get_fragment_offset(const ip4_header_t *i)
#define vec_free(V)
Free vector's memory (no header).
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.
vlib_main_t vlib_node_runtime_t * node
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
static vlib_main_t * vlib_get_main(void)
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.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
#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.
ip_frag_error_t ip4_frag_do_fragment(vlib_main_t *vm, u32 from_bi, u16 mtu, u16 l2unfragmentablesize, u32 **buffer)
static uword ip6_frag(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define IP4_HEADER_FLAG_DONT_FRAGMENT
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#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_always_inline void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
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)