2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/dns/dns.h>
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
21 vlib_node_registration_t dns46_reply_node;
27 } dns46_reply_trace_t;
29 /* packet trace format function */
31 format_dns46_reply_trace (u8 * s, va_list * args)
33 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
34 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
35 dns46_reply_trace_t *t = va_arg (*args, dns46_reply_trace_t *);
37 s = format (s, "DNS46_REPLY: pool index %d, disposition %d",
38 t->pool_index, t->disposition);
42 vlib_node_registration_t dns46_reply_node;
44 static char *dns46_reply_error_strings[] = {
45 #define _(sym,string) string,
46 foreach_dns46_reply_error
52 DNS46_REPLY_NEXT_DROP,
53 DNS46_REPLY_NEXT_PUNT,
58 dns46_reply_node_fn (vlib_main_t * vm,
59 vlib_node_runtime_t * node, vlib_frame_t * frame)
61 u32 n_left_from, *from, *to_next;
62 dns46_reply_next_t next_index;
63 dns_main_t *dm = &dns_main;
65 from = vlib_frame_vector_args (frame);
66 n_left_from = frame->n_vectors;
67 next_index = node->cached_next_index;
69 while (n_left_from > 0)
73 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
76 while (n_left_from >= 4 && n_left_to_next >= 2)
78 u32 next0 = DNS46_REPLY_NEXT_INTERFACE_OUTPUT;
79 u32 next1 = DNS46_REPLY_NEXT_INTERFACE_OUTPUT;
80 u32 sw_if_index0, sw_if_index1;
82 ethernet_header_t *en0, *en1;
84 vlib_buffer_t *b0, *b1;
86 /* Prefetch next iteration. */
88 vlib_buffer_t *p2, *p3;
90 p2 = vlib_get_buffer (vm, from[2]);
91 p3 = vlib_get_buffer (vm, from[3]);
93 vlib_prefetch_buffer_header (p2, LOAD);
94 vlib_prefetch_buffer_header (p3, LOAD);
96 CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE);
97 CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE);
100 /* speculatively enqueue b0 and b1 to the current next frame */
101 to_next[0] = bi0 = from[0];
102 to_next[1] = bi1 = from[1];
108 b0 = vlib_get_buffer (vm, bi0);
109 b1 = vlib_get_buffer (vm, bi1);
111 /* $$$$$ End of processing 2 x packets $$$$$ */
113 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
115 if (b0->flags & VLIB_BUFFER_IS_TRACED)
117 dns46_reply_trace_t *t =
118 vlib_add_trace (vm, node, b0, sizeof (*t));
119 t->sw_if_index = sw_if_index0;
120 t->next_index = next0;
122 if (b1->flags & VLIB_BUFFER_IS_TRACED)
124 dns46_reply_trace_t *t =
125 vlib_add_trace (vm, node, b1, sizeof (*t));
126 t->sw_if_index = sw_if_index1;
127 t->next_index = next1;
131 /* verify speculative enqueues, maybe switch current next frame */
132 vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
133 to_next, n_left_to_next,
134 bi0, bi1, next0, next1);
138 while (n_left_from > 0 && n_left_to_next > 0)
142 u32 next0 = DNS46_REPLY_NEXT_DROP;
144 u32 pool_index0 = ~0;
148 /* speculatively enqueue b0 to the current next frame */
156 b0 = vlib_get_buffer (vm, bi0);
157 d0 = vlib_buffer_get_current (b0);
158 if (PREDICT_FALSE (dm->is_enabled == 0))
160 next0 = DNS46_REPLY_NEXT_PUNT;
161 error0 = DNS46_REPLY_ERROR_DISABLED;
165 pool_index0 = clib_host_to_net_u16 (d0->id);
168 vec_validate (resp0, vlib_buffer_length_in_chain (vm, b0) - 1);
169 clib_memcpy (resp0, d0, vlib_buffer_length_in_chain (vm, b0));
172 * Deal with everything in process ctx on the main thread
174 vlib_process_signal_event_mt (vm, dns_resolver_node.index,
175 DNS_RESOLVER_EVENT_RESOLVED,
177 error0 = DNS46_REPLY_ERROR_PROCESSED;
180 b0->error = node->errors[error0];
182 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
183 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
185 dns46_reply_trace_t *t =
186 vlib_add_trace (vm, node, b0, sizeof (*t));
187 t->disposition = error0;
188 t->pool_index = pool_index0;
191 /* verify speculative enqueue, maybe switch current next frame */
192 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
193 to_next, n_left_to_next,
197 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
200 return frame->n_vectors;
204 VLIB_REGISTER_NODE (dns46_reply_node) =
206 .function = dns46_reply_node_fn,
207 .name = "dns46_reply",
208 .vector_size = sizeof (u32),
209 .format_trace = format_dns46_reply_trace,
210 .type = VLIB_NODE_TYPE_INTERNAL,
211 .n_errors = ARRAY_LEN (dns46_reply_error_strings),
212 .error_strings = dns46_reply_error_strings,
213 .n_next_nodes = DNS46_REPLY_N_NEXT,
215 [DNS46_REPLY_NEXT_DROP] = "error-drop",
216 [DNS46_REPLY_NEXT_PUNT] = "error-punt",
222 * fd.io coding-style-patch-verification: ON
225 * eval: (c-set-style "gnu")