blob: bb971e4081154e58bab2360403937881d8d926e5 [file] [log] [blame]
“mukeshyadav1984”430ac932017-11-23 02:39:33 -08001/*
2 * ah_encrypt.c : IPSec AH encrypt node
3 *
4 * Copyright (c) 2015 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <vnet/vnet.h>
19#include <vnet/api_errno.h>
20#include <vnet/ip/ip.h>
21
22#include <vnet/ipsec/ipsec.h>
23#include <vnet/ipsec/esp.h>
24#include <vnet/ipsec/ah.h>
Neale Ranns041add72020-01-02 04:06:10 +000025#include <vnet/tunnel/tunnel_dp.h>
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080026
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020027#define foreach_ah_encrypt_next \
Neale Rannsf62a8c02019-04-02 08:13:33 +000028 _ (DROP, "error-drop") \
29 _ (HANDOFF, "handoff") \
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020030 _ (INTERFACE_OUTPUT, "interface-output")
31
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080032
33#define _(v, s) AH_ENCRYPT_NEXT_##v,
34typedef enum
35{
36 foreach_ah_encrypt_next
37#undef _
38 AH_ENCRYPT_N_NEXT,
39} ah_encrypt_next_t;
40
Ole Troane66443c2021-03-18 11:12:01 +010041#define foreach_ah_encrypt_error \
42 _ (RX_PKTS, "AH pkts received") \
43 _ (CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \
44 _ (SEQ_CYCLED, "sequence number cycled (packet dropped)")
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080045
46typedef enum
47{
48#define _(sym,str) AH_ENCRYPT_ERROR_##sym,
49 foreach_ah_encrypt_error
50#undef _
51 AH_ENCRYPT_N_ERROR,
52} ah_encrypt_error_t;
53
54static char *ah_encrypt_error_strings[] = {
55#define _(sym,string) string,
56 foreach_ah_encrypt_error
57#undef _
58};
59
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080060typedef struct
61{
Neale Ranns8d7c5022019-02-06 01:41:05 -080062 u32 sa_index;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080063 u32 spi;
Neale Ranns3833ffd2019-03-21 14:34:09 +000064 u32 seq_lo;
65 u32 seq_hi;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080066 ipsec_integ_alg_t integ_alg;
67} ah_encrypt_trace_t;
68
69/* packet trace format function */
70static u8 *
71format_ah_encrypt_trace (u8 * s, va_list * args)
72{
73 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
74 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
75 ah_encrypt_trace_t *t = va_arg (*args, ah_encrypt_trace_t *);
76
Guillaume Solignac8f818cc2019-05-15 12:02:33 +020077 s = format (s, "ah: sa-index %d spi %u (0x%08x) seq %u:%u integrity %U",
78 t->sa_index, t->spi, t->spi, t->seq_hi, t->seq_lo,
Neale Ranns8d7c5022019-02-06 01:41:05 -080079 format_ipsec_integ_alg, t->integ_alg);
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080080 return s;
81}
82
Filip Tehlar11974492019-04-17 07:16:39 +000083static_always_inline void
84ah_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
85 vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts)
86{
87 u32 n_fail, n_ops = vec_len (ops);
88 vnet_crypto_op_t *op = ops;
89
90 if (n_ops == 0)
91 return;
92
93 n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
94
95 while (n_fail)
96 {
97 ASSERT (op - ops < n_ops);
98
99 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
100 {
101 u32 bi = op->user_data;
102 b[bi]->error = node->errors[AH_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR];
103 nexts[bi] = AH_ENCRYPT_NEXT_DROP;
104 n_fail--;
105 }
106 op++;
107 }
108}
109
110typedef struct
111{
112 union
113 {
Neale Ranns041add72020-01-02 04:06:10 +0000114 /* Variable fields in the IP header not covered by the AH
115 * integrity check */
Filip Tehlar11974492019-04-17 07:16:39 +0000116 struct
117 {
Filip Tehlar11974492019-04-17 07:16:39 +0000118 u32 ip_version_traffic_class_and_flow_label;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000119 u8 hop_limit;
Filip Tehlar11974492019-04-17 07:16:39 +0000120 };
Filip Tehlar11974492019-04-17 07:16:39 +0000121 struct
122 {
123 u8 ttl;
124 u8 tos;
125 };
126 };
Filip Tehlar11974492019-04-17 07:16:39 +0000127 u8 skip;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000128 i16 current_data;
Filip Tehlar11974492019-04-17 07:16:39 +0000129 u32 sa_index;
130} ah_encrypt_packet_data_t;
131
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200132always_inline uword
133ah_encrypt_inline (vlib_main_t * vm,
Filip Tehlar11974492019-04-17 07:16:39 +0000134 vlib_node_runtime_t * node, vlib_frame_t * frame,
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200135 int is_ip6)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800136{
Filip Tehlar11974492019-04-17 07:16:39 +0000137 u32 n_left, *from, thread_index;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800138 int icv_size = 0;
Filip Tehlar11974492019-04-17 07:16:39 +0000139 from = vlib_frame_vector_args (frame);
140 n_left = frame->n_vectors;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800141 ipsec_main_t *im = &ipsec_main;
Filip Tehlar11974492019-04-17 07:16:39 +0000142 ah_encrypt_packet_data_t pkt_data[VLIB_FRAME_SIZE], *pd = pkt_data;
Neale Rannseba31ec2019-02-17 18:04:27 +0000143 thread_index = vm->thread_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000144 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
145 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
146 ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, thread_index);
147 ipsec_sa_t *sa0 = 0;
148 ip4_and_ah_header_t *ih0, *oh0 = 0;
149 ip6_and_ah_header_t *ih6_0, *oh6_0 = 0;
150 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
151 const static ip4_header_t ip4_hdr_template = {
152 .ip_version_and_header_length = 0x45,
153 .protocol = IP_PROTOCOL_IPSEC_AH,
154 };
155 const static ip6_header_t ip6_hdr_template = {
156 .ip_version_traffic_class_and_flow_label = 0x60,
157 .protocol = IP_PROTOCOL_IPSEC_AH,
158 };
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800159
Filip Tehlar11974492019-04-17 07:16:39 +0000160 clib_memset (pkt_data, 0, VLIB_FRAME_SIZE * sizeof (pkt_data[0]));
161 vlib_get_buffers (vm, from, b, n_left);
162 vec_reset_length (ptd->crypto_ops);
163 vec_reset_length (ptd->integ_ops);
164
165 while (n_left > 0)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800166 {
Filip Tehlar11974492019-04-17 07:16:39 +0000167 u8 ip_hdr_size;
168 u8 next_hdr_type;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800169
Filip Tehlar11974492019-04-17 07:16:39 +0000170 if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800171 {
Filip Tehlar98d6ee72019-06-03 23:36:10 +0000172 if (current_sa_index != ~0)
173 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
174 current_sa_index,
175 current_sa_pkts,
176 current_sa_bytes);
Filip Tehlar11974492019-04-17 07:16:39 +0000177 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000178 sa0 = ipsec_sa_get (current_sa_index);
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800179
Filip Tehlar11974492019-04-17 07:16:39 +0000180 current_sa_bytes = current_sa_pkts = 0;
181 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800182
Filip Tehlar11974492019-04-17 07:16:39 +0000183 pd->sa_index = current_sa_index;
184 next[0] = AH_ENCRYPT_NEXT_DROP;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800185
Neale Ranns1a52d372021-02-04 11:33:32 +0000186 if (PREDICT_FALSE (~0 == sa0->thread_index))
Neale Rannsf62a8c02019-04-02 08:13:33 +0000187 {
188 /* this is the first packet to use this SA, claim the SA
189 * for this thread. this could happen simultaneously on
190 * another thread */
Neale Ranns1a52d372021-02-04 11:33:32 +0000191 clib_atomic_cmp_and_swap (&sa0->thread_index, ~0,
Neale Rannsf62a8c02019-04-02 08:13:33 +0000192 ipsec_sa_assign_thread (thread_index));
193 }
194
Neale Ranns1a52d372021-02-04 11:33:32 +0000195 if (PREDICT_TRUE (thread_index != sa0->thread_index))
Neale Rannsf62a8c02019-04-02 08:13:33 +0000196 {
Neale Rannsaa7d7662021-02-10 08:42:49 +0000197 vnet_buffer (b[0])->ipsec.thread_index = sa0->thread_index;
Neale Rannsf62a8c02019-04-02 08:13:33 +0000198 next[0] = AH_ENCRYPT_NEXT_HANDOFF;
199 goto next;
200 }
201
Filip Tehlar11974492019-04-17 07:16:39 +0000202 if (PREDICT_FALSE (esp_seq_advance (sa0)))
203 {
204 b[0]->error = node->errors[AH_ENCRYPT_ERROR_SEQ_CYCLED];
205 pd->skip = 1;
206 goto next;
207 }
208
209 current_sa_pkts += 1;
210 current_sa_bytes += b[0]->current_length;
211
212 ssize_t adv;
213 ih0 = vlib_buffer_get_current (b[0]);
Filip Tehlar11974492019-04-17 07:16:39 +0000214
215 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
216 {
217 if (is_ip6)
218 adv = -sizeof (ip6_and_ah_header_t);
219 else
220 adv = -sizeof (ip4_and_ah_header_t);
221 }
222 else
223 {
224 adv = -sizeof (ah_header_t);
225 }
226
227 icv_size = sa0->integ_icv_size;
228 const u8 padding_len = ah_calc_icv_padding_len (icv_size, is_ip6);
229 adv -= padding_len;
230 /* transport mode save the eth header before it is overwritten */
231 if (PREDICT_FALSE (!ipsec_sa_is_set_IS_TUNNEL (sa0)))
232 {
Klement Sekera45155452019-06-19 11:26:34 +0000233 const u32 l2_len = vnet_buffer (b[0])->ip.save_rewrite_length;
234 u8 *l2_hdr_in = (u8 *) vlib_buffer_get_current (b[0]) - l2_len;
235
236 u8 *l2_hdr_out = l2_hdr_in + adv - icv_size;
237
238 clib_memcpy_le32 (l2_hdr_out, l2_hdr_in, l2_len);
Filip Tehlar11974492019-04-17 07:16:39 +0000239 }
240
241 vlib_buffer_advance (b[0], adv - icv_size);
242
243 if (is_ip6)
244 {
245 ih6_0 = (ip6_and_ah_header_t *) ih0;
246 ip_hdr_size = sizeof (ip6_header_t);
247 oh6_0 = vlib_buffer_get_current (b[0]);
248 pd->current_data = b[0]->current_data;
Filip Tehlar11974492019-04-17 07:16:39 +0000249 pd->hop_limit = ih6_0->ip6.hop_limit;
Neale Ranns041add72020-01-02 04:06:10 +0000250
251 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
Filip Tehlar11974492019-04-17 07:16:39 +0000252 ih6_0->ip6.ip_version_traffic_class_and_flow_label;
Neale Ranns041add72020-01-02 04:06:10 +0000253
Neale Ranns9ec846c2021-02-09 14:04:02 +0000254 if (PREDICT_FALSE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
255 {
256 ip6_set_dscp_network_order (&oh6_0->ip6, sa0->tunnel.t_dscp);
257 tunnel_encap_fixup_6o6 (sa0->tunnel_flags, &ih6_0->ip6,
258 &oh6_0->ip6);
259 }
Neale Ranns041add72020-01-02 04:06:10 +0000260 pd->ip_version_traffic_class_and_flow_label =
261 oh6_0->ip6.ip_version_traffic_class_and_flow_label;
Neale Ranns041add72020-01-02 04:06:10 +0000262
Filip Tehlar11974492019-04-17 07:16:39 +0000263 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800264 {
Filip Tehlar11974492019-04-17 07:16:39 +0000265 next_hdr_type = IP_PROTOCOL_IPV6;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800266 }
Filip Tehlar11974492019-04-17 07:16:39 +0000267 else
268 {
269 next_hdr_type = ih6_0->ip6.protocol;
270 memmove (oh6_0, ih6_0, sizeof (ip6_header_t));
271 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800272
Filip Tehlar11974492019-04-17 07:16:39 +0000273 clib_memcpy_fast (&oh6_0->ip6, &ip6_hdr_template, 8);
274 oh6_0->ah.reserved = 0;
275 oh6_0->ah.nexthdr = next_hdr_type;
276 oh6_0->ah.spi = clib_net_to_host_u32 (sa0->spi);
277 oh6_0->ah.seq_no = clib_net_to_host_u32 (sa0->seq);
278 oh6_0->ip6.payload_length =
279 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b[0]) -
280 sizeof (ip6_header_t));
281 oh6_0->ah.hdrlen =
282 (sizeof (ah_header_t) + icv_size + padding_len) / 4 - 2;
283 }
284 else
285 {
286 ip_hdr_size = sizeof (ip4_header_t);
287 oh0 = vlib_buffer_get_current (b[0]);
Neale Ranns041add72020-01-02 04:06:10 +0000288 pd->ttl = ih0->ip4.ttl;
289
Neale Ranns9ec846c2021-02-09 14:04:02 +0000290 if (PREDICT_FALSE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
291 {
292 if (sa0->tunnel.t_dscp)
293 pd->tos = sa0->tunnel.t_dscp << 2;
294 else
295 {
296 pd->tos = ih0->ip4.tos;
297
298 if (!(sa0->tunnel_flags &
299 TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
300 pd->tos &= 0x3;
301 if (!(sa0->tunnel_flags &
302 TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
303 pd->tos &= 0xfc;
304 }
305 }
Neale Ranns041add72020-01-02 04:06:10 +0000306 else
307 {
308 pd->tos = ih0->ip4.tos;
Neale Ranns041add72020-01-02 04:06:10 +0000309 }
Neale Ranns9ec846c2021-02-09 14:04:02 +0000310
Filip Tehlar11974492019-04-17 07:16:39 +0000311 pd->current_data = b[0]->current_data;
Neale Ranns041add72020-01-02 04:06:10 +0000312 clib_memset (oh0, 0, sizeof (ip4_and_ah_header_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800313
Damjan Mariond709cbc2019-03-26 13:16:42 +0100314 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800315 {
Filip Tehlar11974492019-04-17 07:16:39 +0000316 next_hdr_type = IP_PROTOCOL_IP_IN_IP;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800317 }
318 else
319 {
Filip Tehlar11974492019-04-17 07:16:39 +0000320 next_hdr_type = ih0->ip4.protocol;
321 memmove (oh0, ih0, sizeof (ip4_header_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800322 }
323
Filip Tehlar11974492019-04-17 07:16:39 +0000324 clib_memcpy_fast (&oh0->ip4, &ip4_hdr_template,
325 sizeof (ip4_header_t) -
326 sizeof (ip4_address_pair_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800327
Filip Tehlar11974492019-04-17 07:16:39 +0000328 oh0->ip4.length =
329 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b[0]));
330 oh0->ah.spi = clib_net_to_host_u32 (sa0->spi);
331 oh0->ah.seq_no = clib_net_to_host_u32 (sa0->seq);
332 oh0->ah.nexthdr = next_hdr_type;
333 oh0->ah.hdrlen =
334 (sizeof (ah_header_t) + icv_size + padding_len) / 4 - 2;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800335 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800336
Filip Tehlar11974492019-04-17 07:16:39 +0000337 if (PREDICT_TRUE (!is_ip6 && ipsec_sa_is_set_IS_TUNNEL (sa0) &&
338 !ipsec_sa_is_set_IS_TUNNEL_V6 (sa0)))
339 {
340 clib_memcpy_fast (&oh0->ip4.address_pair,
341 &sa0->ip4_hdr.address_pair,
Neale Rannsf3a66222020-01-02 05:04:00 +0000342 sizeof (ip4_address_pair_t));
Filip Tehlar11974492019-04-17 07:16:39 +0000343
Neale Ranns72f2a3a2019-06-17 15:43:38 +0000344 next[0] = sa0->dpo.dpoi_next_node;
345 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = sa0->dpo.dpoi_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000346 }
347 else if (is_ip6 && ipsec_sa_is_set_IS_TUNNEL (sa0) &&
348 ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
349 {
350 clib_memcpy_fast (&oh6_0->ip6.src_address,
351 &sa0->ip6_hdr.src_address,
352 sizeof (ip6_address_t) * 2);
Neale Ranns72f2a3a2019-06-17 15:43:38 +0000353 next[0] = sa0->dpo.dpoi_next_node;
354 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = sa0->dpo.dpoi_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000355 }
356
357 if (PREDICT_TRUE (sa0->integ_op_id))
358 {
359 vnet_crypto_op_t *op;
360 vec_add2_aligned (ptd->integ_ops, op, 1, CLIB_CACHE_LINE_BYTES);
361 vnet_crypto_op_init (op, sa0->integ_op_id);
362 op->src = vlib_buffer_get_current (b[0]);
363 op->len = b[0]->current_length;
364 op->digest = vlib_buffer_get_current (b[0]) + ip_hdr_size +
365 sizeof (ah_header_t);
366 clib_memset (op->digest, 0, icv_size);
367 op->digest_len = icv_size;
368 op->key_index = sa0->integ_key_index;
369 op->user_data = b - bufs;
370 if (ipsec_sa_is_set_USE_ESN (sa0))
371 {
372 u32 seq_hi = clib_host_to_net_u32 (sa0->seq_hi);
373
374 op->len += sizeof (seq_hi);
375 clib_memcpy (op->src + b[0]->current_length, &seq_hi,
376 sizeof (seq_hi));
377 }
378 }
379
380 if (!ipsec_sa_is_set_IS_TUNNEL (sa0))
381 {
382 next[0] = AH_ENCRYPT_NEXT_INTERFACE_OUTPUT;
383 vlib_buffer_advance (b[0], -sizeof (ethernet_header_t));
384 }
385
386 next:
Neale Ranns9ec846c2021-02-09 14:04:02 +0000387 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
388 {
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000389 sa0 = ipsec_sa_get (pd->sa_index);
Neale Ranns9ec846c2021-02-09 14:04:02 +0000390 ah_encrypt_trace_t *tr =
391 vlib_add_trace (vm, node, b[0], sizeof (*tr));
392 tr->spi = sa0->spi;
393 tr->seq_lo = sa0->seq;
394 tr->seq_hi = sa0->seq_hi;
395 tr->integ_alg = sa0->integ_alg;
396 tr->sa_index = pd->sa_index;
397 }
398
Filip Tehlar11974492019-04-17 07:16:39 +0000399 n_left -= 1;
400 next += 1;
401 pd += 1;
402 b += 1;
403 }
404
405 n_left = frame->n_vectors;
406 next = nexts;
407 pd = pkt_data;
408 b = bufs;
409
410 vlib_node_increment_counter (vm, node->node_index,
411 AH_ENCRYPT_ERROR_RX_PKTS, n_left);
412 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
413 current_sa_index, current_sa_pkts,
414 current_sa_bytes);
415
416 ah_process_ops (vm, node, ptd->integ_ops, bufs, nexts);
417
418 while (n_left)
419 {
420 if (pd->skip)
Neale Ranns9ec846c2021-02-09 14:04:02 +0000421 goto next_pkt;
Filip Tehlar11974492019-04-17 07:16:39 +0000422
423 if (is_ip6)
424 {
425 oh6_0 = (ip6_and_ah_header_t *) (b[0]->data + pd->current_data);
426 oh6_0->ip6.hop_limit = pd->hop_limit;
427 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
428 pd->ip_version_traffic_class_and_flow_label;
429 }
430 else
431 {
432 oh0 = (ip4_and_ah_header_t *) (b[0]->data + pd->current_data);
433 oh0->ip4.ttl = pd->ttl;
434 oh0->ip4.tos = pd->tos;
435 oh0->ip4.checksum = ip4_header_checksum (&oh0->ip4);
436 }
437
Neale Ranns9ec846c2021-02-09 14:04:02 +0000438 next_pkt:
Filip Tehlar11974492019-04-17 07:16:39 +0000439 n_left -= 1;
440 next += 1;
441 pd += 1;
442 b += 1;
443 }
444
445 n_left = frame->n_vectors;
446 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
447
448 return n_left;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800449}
450
Klement Sekerab8f35442018-10-29 13:38:19 +0100451VLIB_NODE_FN (ah4_encrypt_node) (vlib_main_t * vm,
452 vlib_node_runtime_t * node,
453 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200454{
455 return ah_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ );
456}
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800457
458/* *INDENT-OFF* */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200459VLIB_REGISTER_NODE (ah4_encrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200460 .name = "ah4-encrypt",
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800461 .vector_size = sizeof (u32),
462 .format_trace = format_ah_encrypt_trace,
463 .type = VLIB_NODE_TYPE_INTERNAL,
464
465 .n_errors = ARRAY_LEN(ah_encrypt_error_strings),
466 .error_strings = ah_encrypt_error_strings,
467
468 .n_next_nodes = AH_ENCRYPT_N_NEXT,
469 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +0000470 [AH_ENCRYPT_NEXT_DROP] = "ip4-drop",
471 [AH_ENCRYPT_NEXT_HANDOFF] = "ah4-encrypt-handoff",
472 [AH_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output",
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800473 },
474};
475/* *INDENT-ON* */
476
Klement Sekerab8f35442018-10-29 13:38:19 +0100477VLIB_NODE_FN (ah6_encrypt_node) (vlib_main_t * vm,
478 vlib_node_runtime_t * node,
479 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200480{
481 return ah_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ );
482}
483
484/* *INDENT-OFF* */
485VLIB_REGISTER_NODE (ah6_encrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200486 .name = "ah6-encrypt",
487 .vector_size = sizeof (u32),
488 .format_trace = format_ah_encrypt_trace,
489 .type = VLIB_NODE_TYPE_INTERNAL,
490
491 .n_errors = ARRAY_LEN(ah_encrypt_error_strings),
492 .error_strings = ah_encrypt_error_strings,
493
494 .n_next_nodes = AH_ENCRYPT_N_NEXT,
495 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +0000496 [AH_ENCRYPT_NEXT_DROP] = "ip6-drop",
497 [AH_ENCRYPT_NEXT_HANDOFF] = "ah6-encrypt-handoff",
498 [AH_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output",
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200499 },
500};
501/* *INDENT-ON* */
502
Neale Ranns2d498302021-02-25 08:38:58 +0000503#ifndef CLIB_MARCH_VARIANT
504
505static clib_error_t *
506ah_encrypt_init (vlib_main_t *vm)
507{
508 ipsec_main_t *im = &ipsec_main;
509
510 im->ah4_enc_fq_index =
511 vlib_frame_queue_main_init (ah4_encrypt_node.index, 0);
512 im->ah6_enc_fq_index =
513 vlib_frame_queue_main_init (ah6_encrypt_node.index, 0);
514
515 return 0;
516}
517
518VLIB_INIT_FUNCTION (ah_encrypt_init);
519
520#endif
521
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800522/*
523 * fd.io coding-style-patch-verification: ON
524 *
525 * Local Variables:
526 * eval: (c-set-style "gnu")
527 * End:
528 */