blob: c962ea9038785d998b91cca761c3d698120d8696 [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
Filip Tehlar11974492019-04-17 07:16:39 +000041#define foreach_ah_encrypt_error \
42 _(RX_PKTS, "AH pkts received") \
43 _(CRYPTO_ENGINE_ERROR, "crypto engine error (packet dropped)") \
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080044 _(SEQ_CYCLED, "sequence number cycled")
45
46
47typedef enum
48{
49#define _(sym,str) AH_ENCRYPT_ERROR_##sym,
50 foreach_ah_encrypt_error
51#undef _
52 AH_ENCRYPT_N_ERROR,
53} ah_encrypt_error_t;
54
55static char *ah_encrypt_error_strings[] = {
56#define _(sym,string) string,
57 foreach_ah_encrypt_error
58#undef _
59};
60
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080061typedef struct
62{
Neale Ranns8d7c5022019-02-06 01:41:05 -080063 u32 sa_index;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080064 u32 spi;
Neale Ranns3833ffd2019-03-21 14:34:09 +000065 u32 seq_lo;
66 u32 seq_hi;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080067 ipsec_integ_alg_t integ_alg;
68} ah_encrypt_trace_t;
69
70/* packet trace format function */
71static u8 *
72format_ah_encrypt_trace (u8 * s, va_list * args)
73{
74 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
75 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
76 ah_encrypt_trace_t *t = va_arg (*args, ah_encrypt_trace_t *);
77
Guillaume Solignac8f818cc2019-05-15 12:02:33 +020078 s = format (s, "ah: sa-index %d spi %u (0x%08x) seq %u:%u integrity %U",
79 t->sa_index, t->spi, t->spi, t->seq_hi, t->seq_lo,
Neale Ranns8d7c5022019-02-06 01:41:05 -080080 format_ipsec_integ_alg, t->integ_alg);
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080081 return s;
82}
83
Filip Tehlar11974492019-04-17 07:16:39 +000084static_always_inline void
85ah_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
86 vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts)
87{
88 u32 n_fail, n_ops = vec_len (ops);
89 vnet_crypto_op_t *op = ops;
90
91 if (n_ops == 0)
92 return;
93
94 n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
95
96 while (n_fail)
97 {
98 ASSERT (op - ops < n_ops);
99
100 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
101 {
102 u32 bi = op->user_data;
103 b[bi]->error = node->errors[AH_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR];
104 nexts[bi] = AH_ENCRYPT_NEXT_DROP;
105 n_fail--;
106 }
107 op++;
108 }
109}
110
111typedef struct
112{
113 union
114 {
Neale Ranns041add72020-01-02 04:06:10 +0000115 /* Variable fields in the IP header not covered by the AH
116 * integrity check */
Filip Tehlar11974492019-04-17 07:16:39 +0000117 struct
118 {
Filip Tehlar11974492019-04-17 07:16:39 +0000119 u32 ip_version_traffic_class_and_flow_label;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000120 u8 hop_limit;
Filip Tehlar11974492019-04-17 07:16:39 +0000121 };
Filip Tehlar11974492019-04-17 07:16:39 +0000122 struct
123 {
124 u8 ttl;
125 u8 tos;
126 };
127 };
Filip Tehlar11974492019-04-17 07:16:39 +0000128 u8 skip;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000129 i16 current_data;
Filip Tehlar11974492019-04-17 07:16:39 +0000130 u32 sa_index;
131} ah_encrypt_packet_data_t;
132
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200133always_inline uword
134ah_encrypt_inline (vlib_main_t * vm,
Filip Tehlar11974492019-04-17 07:16:39 +0000135 vlib_node_runtime_t * node, vlib_frame_t * frame,
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200136 int is_ip6)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800137{
Filip Tehlar11974492019-04-17 07:16:39 +0000138 u32 n_left, *from, thread_index;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800139 int icv_size = 0;
Filip Tehlar11974492019-04-17 07:16:39 +0000140 from = vlib_frame_vector_args (frame);
141 n_left = frame->n_vectors;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800142 ipsec_main_t *im = &ipsec_main;
Filip Tehlar11974492019-04-17 07:16:39 +0000143 ah_encrypt_packet_data_t pkt_data[VLIB_FRAME_SIZE], *pd = pkt_data;
Neale Rannseba31ec2019-02-17 18:04:27 +0000144 thread_index = vm->thread_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000145 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
146 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
147 ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, thread_index);
148 ipsec_sa_t *sa0 = 0;
149 ip4_and_ah_header_t *ih0, *oh0 = 0;
150 ip6_and_ah_header_t *ih6_0, *oh6_0 = 0;
151 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
152 const static ip4_header_t ip4_hdr_template = {
153 .ip_version_and_header_length = 0x45,
154 .protocol = IP_PROTOCOL_IPSEC_AH,
155 };
156 const static ip6_header_t ip6_hdr_template = {
157 .ip_version_traffic_class_and_flow_label = 0x60,
158 .protocol = IP_PROTOCOL_IPSEC_AH,
159 };
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800160
Filip Tehlar11974492019-04-17 07:16:39 +0000161 clib_memset (pkt_data, 0, VLIB_FRAME_SIZE * sizeof (pkt_data[0]));
162 vlib_get_buffers (vm, from, b, n_left);
163 vec_reset_length (ptd->crypto_ops);
164 vec_reset_length (ptd->integ_ops);
165
166 while (n_left > 0)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800167 {
Filip Tehlar11974492019-04-17 07:16:39 +0000168 u8 ip_hdr_size;
169 u8 next_hdr_type;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800170
Filip Tehlar11974492019-04-17 07:16:39 +0000171 if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800172 {
Filip Tehlar98d6ee72019-06-03 23:36:10 +0000173 if (current_sa_index != ~0)
174 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
175 current_sa_index,
176 current_sa_pkts,
177 current_sa_bytes);
Filip Tehlar11974492019-04-17 07:16:39 +0000178 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000179 sa0 = ipsec_sa_get (current_sa_index);
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800180
Filip Tehlar11974492019-04-17 07:16:39 +0000181 current_sa_bytes = current_sa_pkts = 0;
182 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800183
Filip Tehlar11974492019-04-17 07:16:39 +0000184 pd->sa_index = current_sa_index;
185 next[0] = AH_ENCRYPT_NEXT_DROP;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800186
Neale Ranns1a52d372021-02-04 11:33:32 +0000187 if (PREDICT_FALSE (~0 == sa0->thread_index))
Neale Rannsf62a8c02019-04-02 08:13:33 +0000188 {
189 /* this is the first packet to use this SA, claim the SA
190 * for this thread. this could happen simultaneously on
191 * another thread */
Neale Ranns1a52d372021-02-04 11:33:32 +0000192 clib_atomic_cmp_and_swap (&sa0->thread_index, ~0,
Neale Rannsf62a8c02019-04-02 08:13:33 +0000193 ipsec_sa_assign_thread (thread_index));
194 }
195
Neale Ranns1a52d372021-02-04 11:33:32 +0000196 if (PREDICT_TRUE (thread_index != sa0->thread_index))
Neale Rannsf62a8c02019-04-02 08:13:33 +0000197 {
Neale Rannsaa7d7662021-02-10 08:42:49 +0000198 vnet_buffer (b[0])->ipsec.thread_index = sa0->thread_index;
Neale Rannsf62a8c02019-04-02 08:13:33 +0000199 next[0] = AH_ENCRYPT_NEXT_HANDOFF;
200 goto next;
201 }
202
Filip Tehlar11974492019-04-17 07:16:39 +0000203 if (PREDICT_FALSE (esp_seq_advance (sa0)))
204 {
205 b[0]->error = node->errors[AH_ENCRYPT_ERROR_SEQ_CYCLED];
206 pd->skip = 1;
207 goto next;
208 }
209
210 current_sa_pkts += 1;
211 current_sa_bytes += b[0]->current_length;
212
213 ssize_t adv;
214 ih0 = vlib_buffer_get_current (b[0]);
Filip Tehlar11974492019-04-17 07:16:39 +0000215
216 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
217 {
218 if (is_ip6)
219 adv = -sizeof (ip6_and_ah_header_t);
220 else
221 adv = -sizeof (ip4_and_ah_header_t);
222 }
223 else
224 {
225 adv = -sizeof (ah_header_t);
226 }
227
228 icv_size = sa0->integ_icv_size;
229 const u8 padding_len = ah_calc_icv_padding_len (icv_size, is_ip6);
230 adv -= padding_len;
231 /* transport mode save the eth header before it is overwritten */
232 if (PREDICT_FALSE (!ipsec_sa_is_set_IS_TUNNEL (sa0)))
233 {
Klement Sekera45155452019-06-19 11:26:34 +0000234 const u32 l2_len = vnet_buffer (b[0])->ip.save_rewrite_length;
235 u8 *l2_hdr_in = (u8 *) vlib_buffer_get_current (b[0]) - l2_len;
236
237 u8 *l2_hdr_out = l2_hdr_in + adv - icv_size;
238
239 clib_memcpy_le32 (l2_hdr_out, l2_hdr_in, l2_len);
Filip Tehlar11974492019-04-17 07:16:39 +0000240 }
241
242 vlib_buffer_advance (b[0], adv - icv_size);
243
244 if (is_ip6)
245 {
246 ih6_0 = (ip6_and_ah_header_t *) ih0;
247 ip_hdr_size = sizeof (ip6_header_t);
248 oh6_0 = vlib_buffer_get_current (b[0]);
249 pd->current_data = b[0]->current_data;
Filip Tehlar11974492019-04-17 07:16:39 +0000250 pd->hop_limit = ih6_0->ip6.hop_limit;
Neale Ranns041add72020-01-02 04:06:10 +0000251
252 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
Filip Tehlar11974492019-04-17 07:16:39 +0000253 ih6_0->ip6.ip_version_traffic_class_and_flow_label;
Neale Ranns041add72020-01-02 04:06:10 +0000254
Neale Ranns9ec846c2021-02-09 14:04:02 +0000255 if (PREDICT_FALSE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
256 {
257 ip6_set_dscp_network_order (&oh6_0->ip6, sa0->tunnel.t_dscp);
258 tunnel_encap_fixup_6o6 (sa0->tunnel_flags, &ih6_0->ip6,
259 &oh6_0->ip6);
260 }
Neale Ranns041add72020-01-02 04:06:10 +0000261 pd->ip_version_traffic_class_and_flow_label =
262 oh6_0->ip6.ip_version_traffic_class_and_flow_label;
Neale Ranns041add72020-01-02 04:06:10 +0000263
Filip Tehlar11974492019-04-17 07:16:39 +0000264 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800265 {
Filip Tehlar11974492019-04-17 07:16:39 +0000266 next_hdr_type = IP_PROTOCOL_IPV6;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800267 }
Filip Tehlar11974492019-04-17 07:16:39 +0000268 else
269 {
270 next_hdr_type = ih6_0->ip6.protocol;
271 memmove (oh6_0, ih6_0, sizeof (ip6_header_t));
272 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800273
Filip Tehlar11974492019-04-17 07:16:39 +0000274 clib_memcpy_fast (&oh6_0->ip6, &ip6_hdr_template, 8);
275 oh6_0->ah.reserved = 0;
276 oh6_0->ah.nexthdr = next_hdr_type;
277 oh6_0->ah.spi = clib_net_to_host_u32 (sa0->spi);
278 oh6_0->ah.seq_no = clib_net_to_host_u32 (sa0->seq);
279 oh6_0->ip6.payload_length =
280 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b[0]) -
281 sizeof (ip6_header_t));
282 oh6_0->ah.hdrlen =
283 (sizeof (ah_header_t) + icv_size + padding_len) / 4 - 2;
284 }
285 else
286 {
287 ip_hdr_size = sizeof (ip4_header_t);
288 oh0 = vlib_buffer_get_current (b[0]);
Neale Ranns041add72020-01-02 04:06:10 +0000289 pd->ttl = ih0->ip4.ttl;
290
Neale Ranns9ec846c2021-02-09 14:04:02 +0000291 if (PREDICT_FALSE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
292 {
293 if (sa0->tunnel.t_dscp)
294 pd->tos = sa0->tunnel.t_dscp << 2;
295 else
296 {
297 pd->tos = ih0->ip4.tos;
298
299 if (!(sa0->tunnel_flags &
300 TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
301 pd->tos &= 0x3;
302 if (!(sa0->tunnel_flags &
303 TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
304 pd->tos &= 0xfc;
305 }
306 }
Neale Ranns041add72020-01-02 04:06:10 +0000307 else
308 {
309 pd->tos = ih0->ip4.tos;
Neale Ranns041add72020-01-02 04:06:10 +0000310 }
Neale Ranns9ec846c2021-02-09 14:04:02 +0000311
Filip Tehlar11974492019-04-17 07:16:39 +0000312 pd->current_data = b[0]->current_data;
Neale Ranns041add72020-01-02 04:06:10 +0000313 clib_memset (oh0, 0, sizeof (ip4_and_ah_header_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800314
Damjan Mariond709cbc2019-03-26 13:16:42 +0100315 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800316 {
Filip Tehlar11974492019-04-17 07:16:39 +0000317 next_hdr_type = IP_PROTOCOL_IP_IN_IP;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800318 }
319 else
320 {
Filip Tehlar11974492019-04-17 07:16:39 +0000321 next_hdr_type = ih0->ip4.protocol;
322 memmove (oh0, ih0, sizeof (ip4_header_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800323 }
324
Filip Tehlar11974492019-04-17 07:16:39 +0000325 clib_memcpy_fast (&oh0->ip4, &ip4_hdr_template,
326 sizeof (ip4_header_t) -
327 sizeof (ip4_address_pair_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800328
Filip Tehlar11974492019-04-17 07:16:39 +0000329 oh0->ip4.length =
330 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b[0]));
331 oh0->ah.spi = clib_net_to_host_u32 (sa0->spi);
332 oh0->ah.seq_no = clib_net_to_host_u32 (sa0->seq);
333 oh0->ah.nexthdr = next_hdr_type;
334 oh0->ah.hdrlen =
335 (sizeof (ah_header_t) + icv_size + padding_len) / 4 - 2;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800336 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800337
Filip Tehlar11974492019-04-17 07:16:39 +0000338 if (PREDICT_TRUE (!is_ip6 && ipsec_sa_is_set_IS_TUNNEL (sa0) &&
339 !ipsec_sa_is_set_IS_TUNNEL_V6 (sa0)))
340 {
341 clib_memcpy_fast (&oh0->ip4.address_pair,
342 &sa0->ip4_hdr.address_pair,
Neale Rannsf3a66222020-01-02 05:04:00 +0000343 sizeof (ip4_address_pair_t));
Filip Tehlar11974492019-04-17 07:16:39 +0000344
Neale Ranns72f2a3a2019-06-17 15:43:38 +0000345 next[0] = sa0->dpo.dpoi_next_node;
346 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = sa0->dpo.dpoi_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000347 }
348 else if (is_ip6 && ipsec_sa_is_set_IS_TUNNEL (sa0) &&
349 ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
350 {
351 clib_memcpy_fast (&oh6_0->ip6.src_address,
352 &sa0->ip6_hdr.src_address,
353 sizeof (ip6_address_t) * 2);
Neale Ranns72f2a3a2019-06-17 15:43:38 +0000354 next[0] = sa0->dpo.dpoi_next_node;
355 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = sa0->dpo.dpoi_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000356 }
357
358 if (PREDICT_TRUE (sa0->integ_op_id))
359 {
360 vnet_crypto_op_t *op;
361 vec_add2_aligned (ptd->integ_ops, op, 1, CLIB_CACHE_LINE_BYTES);
362 vnet_crypto_op_init (op, sa0->integ_op_id);
363 op->src = vlib_buffer_get_current (b[0]);
364 op->len = b[0]->current_length;
365 op->digest = vlib_buffer_get_current (b[0]) + ip_hdr_size +
366 sizeof (ah_header_t);
367 clib_memset (op->digest, 0, icv_size);
368 op->digest_len = icv_size;
369 op->key_index = sa0->integ_key_index;
370 op->user_data = b - bufs;
371 if (ipsec_sa_is_set_USE_ESN (sa0))
372 {
373 u32 seq_hi = clib_host_to_net_u32 (sa0->seq_hi);
374
375 op->len += sizeof (seq_hi);
376 clib_memcpy (op->src + b[0]->current_length, &seq_hi,
377 sizeof (seq_hi));
378 }
379 }
380
381 if (!ipsec_sa_is_set_IS_TUNNEL (sa0))
382 {
383 next[0] = AH_ENCRYPT_NEXT_INTERFACE_OUTPUT;
384 vlib_buffer_advance (b[0], -sizeof (ethernet_header_t));
385 }
386
387 next:
Neale Ranns9ec846c2021-02-09 14:04:02 +0000388 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
389 {
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000390 sa0 = ipsec_sa_get (pd->sa_index);
Neale Ranns9ec846c2021-02-09 14:04:02 +0000391 ah_encrypt_trace_t *tr =
392 vlib_add_trace (vm, node, b[0], sizeof (*tr));
393 tr->spi = sa0->spi;
394 tr->seq_lo = sa0->seq;
395 tr->seq_hi = sa0->seq_hi;
396 tr->integ_alg = sa0->integ_alg;
397 tr->sa_index = pd->sa_index;
398 }
399
Filip Tehlar11974492019-04-17 07:16:39 +0000400 n_left -= 1;
401 next += 1;
402 pd += 1;
403 b += 1;
404 }
405
406 n_left = frame->n_vectors;
407 next = nexts;
408 pd = pkt_data;
409 b = bufs;
410
411 vlib_node_increment_counter (vm, node->node_index,
412 AH_ENCRYPT_ERROR_RX_PKTS, n_left);
413 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
414 current_sa_index, current_sa_pkts,
415 current_sa_bytes);
416
417 ah_process_ops (vm, node, ptd->integ_ops, bufs, nexts);
418
419 while (n_left)
420 {
421 if (pd->skip)
Neale Ranns9ec846c2021-02-09 14:04:02 +0000422 goto next_pkt;
Filip Tehlar11974492019-04-17 07:16:39 +0000423
424 if (is_ip6)
425 {
426 oh6_0 = (ip6_and_ah_header_t *) (b[0]->data + pd->current_data);
427 oh6_0->ip6.hop_limit = pd->hop_limit;
428 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
429 pd->ip_version_traffic_class_and_flow_label;
430 }
431 else
432 {
433 oh0 = (ip4_and_ah_header_t *) (b[0]->data + pd->current_data);
434 oh0->ip4.ttl = pd->ttl;
435 oh0->ip4.tos = pd->tos;
436 oh0->ip4.checksum = ip4_header_checksum (&oh0->ip4);
437 }
438
Neale Ranns9ec846c2021-02-09 14:04:02 +0000439 next_pkt:
Filip Tehlar11974492019-04-17 07:16:39 +0000440 n_left -= 1;
441 next += 1;
442 pd += 1;
443 b += 1;
444 }
445
446 n_left = frame->n_vectors;
447 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
448
449 return n_left;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800450}
451
Klement Sekerab8f35442018-10-29 13:38:19 +0100452VLIB_NODE_FN (ah4_encrypt_node) (vlib_main_t * vm,
453 vlib_node_runtime_t * node,
454 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200455{
456 return ah_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ );
457}
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800458
459/* *INDENT-OFF* */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200460VLIB_REGISTER_NODE (ah4_encrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200461 .name = "ah4-encrypt",
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800462 .vector_size = sizeof (u32),
463 .format_trace = format_ah_encrypt_trace,
464 .type = VLIB_NODE_TYPE_INTERNAL,
465
466 .n_errors = ARRAY_LEN(ah_encrypt_error_strings),
467 .error_strings = ah_encrypt_error_strings,
468
469 .n_next_nodes = AH_ENCRYPT_N_NEXT,
470 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +0000471 [AH_ENCRYPT_NEXT_DROP] = "ip4-drop",
472 [AH_ENCRYPT_NEXT_HANDOFF] = "ah4-encrypt-handoff",
473 [AH_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output",
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800474 },
475};
476/* *INDENT-ON* */
477
Klement Sekerab8f35442018-10-29 13:38:19 +0100478VLIB_NODE_FN (ah6_encrypt_node) (vlib_main_t * vm,
479 vlib_node_runtime_t * node,
480 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200481{
482 return ah_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ );
483}
484
485/* *INDENT-OFF* */
486VLIB_REGISTER_NODE (ah6_encrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200487 .name = "ah6-encrypt",
488 .vector_size = sizeof (u32),
489 .format_trace = format_ah_encrypt_trace,
490 .type = VLIB_NODE_TYPE_INTERNAL,
491
492 .n_errors = ARRAY_LEN(ah_encrypt_error_strings),
493 .error_strings = ah_encrypt_error_strings,
494
495 .n_next_nodes = AH_ENCRYPT_N_NEXT,
496 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +0000497 [AH_ENCRYPT_NEXT_DROP] = "ip6-drop",
498 [AH_ENCRYPT_NEXT_HANDOFF] = "ah6-encrypt-handoff",
499 [AH_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output",
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200500 },
501};
502/* *INDENT-ON* */
503
Neale Ranns2d498302021-02-25 08:38:58 +0000504#ifndef CLIB_MARCH_VARIANT
505
506static clib_error_t *
507ah_encrypt_init (vlib_main_t *vm)
508{
509 ipsec_main_t *im = &ipsec_main;
510
511 im->ah4_enc_fq_index =
512 vlib_frame_queue_main_init (ah4_encrypt_node.index, 0);
513 im->ah6_enc_fq_index =
514 vlib_frame_queue_main_init (ah6_encrypt_node.index, 0);
515
516 return 0;
517}
518
519VLIB_INIT_FUNCTION (ah_encrypt_init);
520
521#endif
522
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800523/*
524 * fd.io coding-style-patch-verification: ON
525 *
526 * Local Variables:
527 * eval: (c-set-style "gnu")
528 * End:
529 */