42 s =
format (s,
"IPv%s offset: %u mtu: %u fragments: %u",
55 u16 mtu, ptr, len, max, rem,
offset, ip_frag_id, ip_frag_offset;
65 rem = clib_net_to_host_u16 (ip4->
length) -
sizeof (*ip4);
67 max = (mtu -
sizeof (*ip4) -
vnet_buffer (p)->ip_frag.header_offset) & ~0x7;
71 *error = IP_FRAG_ERROR_MALFORMED;
75 if (mtu <
sizeof (*ip4))
77 *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
84 *error = IP_FRAG_ERROR_DONT_FRAGMENT_SET;
88 if (p->
flags & VLIB_BUFFER_NEXT_PRESENT)
90 *error = IP_FRAG_ERROR_MALFORMED;
118 (mtu -
sizeof (*ip4) -
119 vnet_buffer (p)->ip_frag.header_offset)) ? max : rem;
131 *error = IP_FRAG_ERROR_MEMORY;
152 packet + offset +
sizeof (*fip4) + ptr, len);
158 clib_host_to_net_u16 ((ptr >> 3) + ip_frag_offset);
160 clib_host_to_net_u16 (((len != rem) || more) << 13);
163 fip4->
length = clib_host_to_net_u16 (len +
sizeof (*fip4));
181 sizeof (*encap_header6));
202 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
208 u32 frag_sent = 0, small_packets = 0;
211 while (n_left_from > 0)
215 while (n_left_from > 0 && n_left_to_next > 0)
217 u32 pi0, *frag_from, frag_left;
228 error0 = IP_FRAG_ERROR_NONE;
244 if (error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET)
247 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
256 next0 = (error0 == IP_FRAG_ERROR_NONE) ?
vnet_buffer (p0)->
261 if (error0 == IP_FRAG_ERROR_NONE)
264 small_packets += (
vec_len (buffer) == 1);
273 while (frag_left > 0)
275 while (frag_left > 0 && n_left_to_next > 0)
278 i = to_next[0] = frag_from[0];
286 to_next, n_left_to_next, i,
300 IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
302 IP_FRAG_ERROR_SMALL_PACKET, small_packets);
314 ip6_frag_hdr_t *frag_hdr;
315 u8 *payload, *next_header;
322 payload = (
u8 *) (ip6_hdr + 1);
324 if (*next_header == IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS)
326 next_header = payload;
327 payload += payload[1] * 8;
330 if (*next_header == IP_PROTOCOL_IP6_DESTINATION_OPTIONS)
332 next_header = payload;
333 payload += payload[1] * 8;
336 if (*next_header == IP_PROTOCOL_IPV6_ROUTE)
338 next_header = payload;
339 payload += payload[1] * 8;
347 *error = IP_FRAG_ERROR_MALFORMED;
351 if (p->
flags & VLIB_BUFFER_NEXT_PRESENT)
353 *error = IP_FRAG_ERROR_MALFORMED;
359 if (*next_header == IP_PROTOCOL_IPV6_FRAGMENTATION)
362 frag_hdr = (ip6_frag_hdr_t *) payload;
369 u8 nh = *next_header;
370 *next_header = IP_PROTOCOL_IPV6_FRAGMENTATION;
373 memmove (start, start +
sizeof (*frag_hdr),
374 payload - (start +
sizeof (*frag_hdr)));
375 frag_hdr = (ip6_frag_hdr_t *) (payload -
sizeof (*frag_hdr));
377 frag_hdr->next_hdr = nh;
382 payload = (
u8 *) (frag_hdr + 1);
391 *error = IP_FRAG_ERROR_CANT_FRAGMENT_HEADER;
399 u16 len = (rem > max_payload) ? (max_payload & ~0x7) : rem;
406 *error = IP_FRAG_ERROR_MEMORY;
438 frag_hdr->fragment_offset_and_more =
462 sizeof (*encap_header6));
474 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
480 u32 frag_sent = 0, small_packets = 0;
483 while (n_left_from > 0)
487 while (n_left_from > 0 && n_left_to_next > 0)
489 u32 pi0, *frag_from, frag_left;
497 error0 = IP_FRAG_ERROR_NONE;
514 next0 = (error0 == IP_FRAG_ERROR_NONE) ?
vnet_buffer (p0)->
519 small_packets += (
vec_len (buffer) == 1);
524 while (frag_left > 0)
526 while (frag_left > 0 && n_left_to_next > 0)
529 i = to_next[0] = frag_from[0];
537 to_next, n_left_to_next, i,
550 IP_FRAG_ERROR_FRAGMENT_SENT, frag_sent);
552 IP_FRAG_ERROR_SMALL_PACKET, small_packets);
558 #define _(sym,string) string, 567 .vector_size =
sizeof (
u32),
589 .vector_size =
sizeof (
u32),
#define foreach_ip_frag_error
void ip_frag_set_vnet_buffer(vlib_buffer_t *b, u16 offset, 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).
vlib_error_t * errors
Vector of errors for this node.
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 u32 running_fragment_id
static int ip4_get_fragment_offset(ip4_header_t *i)
static uword ip4_frag(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static int ip4_is_fragment(ip4_header_t *i)
#define ip6_frag_hdr_more(hdr)
u16 current_length
Nbytes between current data and the end of this buffer.
#define IP4_FRAG_NODE_NAME
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)
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,...)
#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 ip6_frag_hdr_offset(hdr)
#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 void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
template key/value backing page structure
void ip6_frag_do_fragment(vlib_main_t *vm, u32 pi, u32 **buffer, ip_frag_error_t *error)
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)
static char * ip4_frag_error_strings[]
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
struct clib_bihash_value offset
template key/value backing page structure
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)
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.
void ip4_frag_do_fragment(vlib_main_t *vm, u32 pi, u32 **buffer, ip_frag_error_t *error)
static u16 ip4_header_checksum(ip4_header_t *i)