2 *------------------------------------------------------------------
5 * Copyright (c) 2020 Graphiant.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vnet/ip/ip_path_mtu.h>
21 #include <vnet/ip/ip_frag.h>
29 typedef struct ip_pmtu_trace_t_
36 format_ip_pmtu_trace (u8 *s, va_list *args)
38 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
39 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
40 ip_pmtu_trace_t *t = va_arg (*args, ip_pmtu_trace_t *);
42 s = format (s, "path mtu:%d packet size:%d", t->pmtu, t->packet_size);
48 ip_pmtu_dpo_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
49 vlib_frame_t *frame, ip_address_family_t af)
51 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
53 from = vlib_frame_vector_args (frame);
54 n_left_from = frame->n_vectors;
55 next_index = node->cached_next_index;
59 while (n_left_from > 0)
61 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
63 while (n_left_from > 0 && n_left_to_next > 0)
65 const ip_pmtu_dpo_t *ipm0;
66 u32 pi0, *frag_from, frag_left;
68 ip_frag_error_t error0;
72 * Note: The packet is not enqueued now. It is instead put
73 * in a vector where other fragments will be put as well.
79 p0 = vlib_get_buffer (vm, pi0);
80 ipm0 = ip_pmtu_dpo_get (vnet_buffer (p0)->ip.adj_index[VLIB_TX]);
81 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = ipm0->ipm_dpo.dpoi_index;
82 next0 = ipm0->ipm_dpo.dpoi_next_node;
84 if (PREDICT_FALSE (p0->flags & VLIB_BUFFER_IS_TRACED))
87 t = vlib_add_trace (vm, node, p0, sizeof (*t));
88 t->pmtu = ipm0->ipm_pmtu;
89 t->packet_size = vlib_buffer_length_in_chain (vm, p0);
94 ip6_frag_do_fragment (vm, pi0, ipm0->ipm_pmtu, 0, &buffer);
97 ip4_frag_do_fragment (vm, pi0, ipm0->ipm_pmtu, 0, &buffer);
99 if (AF_IP4 == af && error0 == IP_FRAG_ERROR_DONT_FRAGMENT_SET)
101 icmp4_error_set_vnet_buffer (
102 p0, ICMP4_destination_unreachable,
103 ICMP4_destination_unreachable_fragmentation_needed_and_dont_fragment_set,
105 next0 = IP_FRAG_NEXT_ICMP_ERROR;
110 (error0 == IP_FRAG_ERROR_NONE ? next0 : IP_FRAG_NEXT_DROP);
113 if (error0 == IP_FRAG_ERROR_NONE)
115 /* Free original buffer chain */
116 vlib_buffer_free_one (vm, pi0); /* Free original packet */
120 vlib_error_count (vm, node->node_index, error0, 1);
121 vec_add1 (buffer, pi0); /* Get rid of the original buffer */
124 /* Send fragments that were added in the frame */
126 frag_left = vec_len (buffer);
128 while (frag_left > 0)
130 while (frag_left > 0 && n_left_to_next > 0)
133 i = to_next[0] = frag_from[0];
139 vlib_get_buffer (vm, i)->error = node->errors[error0];
140 vlib_validate_buffer_enqueue_x1 (
141 vm, node, next_index, to_next, n_left_to_next, i, next0);
143 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
144 vlib_get_next_frame (vm, node, next_index, to_next,
147 vec_reset_length (buffer);
149 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
153 return frame->n_vectors;
158 VLIB_NODE_FN (ip4_ip_pmtu_dpo_node) (vlib_main_t *vm,
159 vlib_node_runtime_t *node,
160 vlib_frame_t *from_frame)
162 return (ip_pmtu_dpo_inline (vm, node, from_frame, 0));
165 VLIB_NODE_FN (ip6_ip_pmtu_dpo_node) (vlib_main_t *vm,
166 vlib_node_runtime_t *node,
167 vlib_frame_t *from_frame)
169 return (ip_pmtu_dpo_inline (vm, node, from_frame, 1));
172 VLIB_REGISTER_NODE (ip4_ip_pmtu_dpo_node) = {
173 .name = "ip4-pmtu-dpo",
174 .vector_size = sizeof (u32),
175 .format_trace = format_ip_pmtu_trace,
176 .n_errors = IP_FRAG_N_ERROR,
177 .error_counters = ip_frag_error_counters,
178 .n_next_nodes = IP_PMTU_N_NEXT,
181 [IP_PMTU_DROP] = "ip4-drop",
184 VLIB_REGISTER_NODE (ip6_ip_pmtu_dpo_node) = {
185 .name = "ip6-pmtu-dpo",
186 .vector_size = sizeof (u32),
187 .format_trace = format_ip_pmtu_trace,
188 .n_errors = IP_FRAG_N_ERROR,
189 .error_counters = ip_frag_error_counters,
190 .n_next_nodes = IP_PMTU_N_NEXT,
193 [IP_PMTU_DROP] = "ip6-drop",
200 * fd.io coding-style-patch-verification: ON
203 * eval: (c-set-style "gnu")