blob: 03e0488016168c164184a6c1e4872ab2a8183a8f [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 Ranns93688d72022-08-09 03:34:51 +000025#include <vnet/ipsec/ipsec.api_enum.h>
Neale Ranns041add72020-01-02 04:06:10 +000026#include <vnet/tunnel/tunnel_dp.h>
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080027
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020028#define foreach_ah_encrypt_next \
Neale Rannsf62a8c02019-04-02 08:13:33 +000029 _ (DROP, "error-drop") \
30 _ (HANDOFF, "handoff") \
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020031 _ (INTERFACE_OUTPUT, "interface-output")
32
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080033
34#define _(v, s) AH_ENCRYPT_NEXT_##v,
35typedef enum
36{
37 foreach_ah_encrypt_next
38#undef _
39 AH_ENCRYPT_N_NEXT,
40} ah_encrypt_next_t;
41
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080042typedef struct
43{
Neale Ranns8d7c5022019-02-06 01:41:05 -080044 u32 sa_index;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080045 u32 spi;
Neale Ranns3833ffd2019-03-21 14:34:09 +000046 u32 seq_lo;
47 u32 seq_hi;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080048 ipsec_integ_alg_t integ_alg;
49} ah_encrypt_trace_t;
50
51/* packet trace format function */
52static u8 *
53format_ah_encrypt_trace (u8 * s, va_list * args)
54{
55 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
56 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
57 ah_encrypt_trace_t *t = va_arg (*args, ah_encrypt_trace_t *);
58
Guillaume Solignac8f818cc2019-05-15 12:02:33 +020059 s = format (s, "ah: sa-index %d spi %u (0x%08x) seq %u:%u integrity %U",
60 t->sa_index, t->spi, t->spi, t->seq_hi, t->seq_lo,
Neale Ranns8d7c5022019-02-06 01:41:05 -080061 format_ipsec_integ_alg, t->integ_alg);
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080062 return s;
63}
64
Filip Tehlar11974492019-04-17 07:16:39 +000065static_always_inline void
66ah_process_ops (vlib_main_t * vm, vlib_node_runtime_t * node,
67 vnet_crypto_op_t * ops, vlib_buffer_t * b[], u16 * nexts)
68{
69 u32 n_fail, n_ops = vec_len (ops);
70 vnet_crypto_op_t *op = ops;
71
72 if (n_ops == 0)
73 return;
74
75 n_fail = n_ops - vnet_crypto_process_ops (vm, op, n_ops);
76
77 while (n_fail)
78 {
79 ASSERT (op - ops < n_ops);
80
81 if (op->status != VNET_CRYPTO_OP_STATUS_COMPLETED)
82 {
83 u32 bi = op->user_data;
Arthur de Kerhorad95b062022-11-16 19:12:05 +010084 ah_encrypt_set_next_index (b[bi], node, vm->thread_index,
85 AH_ENCRYPT_ERROR_CRYPTO_ENGINE_ERROR, bi,
86 nexts, AH_ENCRYPT_NEXT_DROP,
87 vnet_buffer (b[bi])->ipsec.sad_index);
Filip Tehlar11974492019-04-17 07:16:39 +000088 n_fail--;
89 }
90 op++;
91 }
92}
93
94typedef struct
95{
96 union
97 {
Neale Ranns041add72020-01-02 04:06:10 +000098 /* Variable fields in the IP header not covered by the AH
99 * integrity check */
Filip Tehlar11974492019-04-17 07:16:39 +0000100 struct
101 {
Filip Tehlar11974492019-04-17 07:16:39 +0000102 u32 ip_version_traffic_class_and_flow_label;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000103 u8 hop_limit;
Filip Tehlar11974492019-04-17 07:16:39 +0000104 };
Filip Tehlar11974492019-04-17 07:16:39 +0000105 struct
106 {
107 u8 ttl;
108 u8 tos;
109 };
110 };
Filip Tehlar11974492019-04-17 07:16:39 +0000111 u8 skip;
Neale Ranns9ec846c2021-02-09 14:04:02 +0000112 i16 current_data;
Filip Tehlar11974492019-04-17 07:16:39 +0000113 u32 sa_index;
114} ah_encrypt_packet_data_t;
115
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200116always_inline uword
117ah_encrypt_inline (vlib_main_t * vm,
Filip Tehlar11974492019-04-17 07:16:39 +0000118 vlib_node_runtime_t * node, vlib_frame_t * frame,
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200119 int is_ip6)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800120{
Filip Tehlar11974492019-04-17 07:16:39 +0000121 u32 n_left, *from, thread_index;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800122 int icv_size = 0;
Filip Tehlar11974492019-04-17 07:16:39 +0000123 from = vlib_frame_vector_args (frame);
124 n_left = frame->n_vectors;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800125 ipsec_main_t *im = &ipsec_main;
Filip Tehlar11974492019-04-17 07:16:39 +0000126 ah_encrypt_packet_data_t pkt_data[VLIB_FRAME_SIZE], *pd = pkt_data;
Neale Rannseba31ec2019-02-17 18:04:27 +0000127 thread_index = vm->thread_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000128 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs;
129 u16 nexts[VLIB_FRAME_SIZE], *next = nexts;
130 ipsec_per_thread_data_t *ptd = vec_elt_at_index (im->ptd, thread_index);
131 ipsec_sa_t *sa0 = 0;
132 ip4_and_ah_header_t *ih0, *oh0 = 0;
133 ip6_and_ah_header_t *ih6_0, *oh6_0 = 0;
134 u32 current_sa_index = ~0, current_sa_bytes = 0, current_sa_pkts = 0;
135 const static ip4_header_t ip4_hdr_template = {
136 .ip_version_and_header_length = 0x45,
137 .protocol = IP_PROTOCOL_IPSEC_AH,
138 };
139 const static ip6_header_t ip6_hdr_template = {
140 .ip_version_traffic_class_and_flow_label = 0x60,
141 .protocol = IP_PROTOCOL_IPSEC_AH,
142 };
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800143
Filip Tehlar11974492019-04-17 07:16:39 +0000144 clib_memset (pkt_data, 0, VLIB_FRAME_SIZE * sizeof (pkt_data[0]));
145 vlib_get_buffers (vm, from, b, n_left);
146 vec_reset_length (ptd->crypto_ops);
147 vec_reset_length (ptd->integ_ops);
148
149 while (n_left > 0)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800150 {
Filip Tehlar11974492019-04-17 07:16:39 +0000151 u8 ip_hdr_size;
152 u8 next_hdr_type;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800153
Filip Tehlar11974492019-04-17 07:16:39 +0000154 if (vnet_buffer (b[0])->ipsec.sad_index != current_sa_index)
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800155 {
Filip Tehlar98d6ee72019-06-03 23:36:10 +0000156 if (current_sa_index != ~0)
157 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
Arthur de Kerhorad95b062022-11-16 19:12:05 +0100158 current_sa_index, current_sa_pkts,
Filip Tehlar98d6ee72019-06-03 23:36:10 +0000159 current_sa_bytes);
Filip Tehlar11974492019-04-17 07:16:39 +0000160 current_sa_index = vnet_buffer (b[0])->ipsec.sad_index;
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000161 sa0 = ipsec_sa_get (current_sa_index);
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800162
Filip Tehlar11974492019-04-17 07:16:39 +0000163 current_sa_bytes = current_sa_pkts = 0;
Arthur de Kerhorad95b062022-11-16 19:12:05 +0100164 vlib_prefetch_combined_counter (&ipsec_sa_counters, thread_index,
165 current_sa_index);
Filip Tehlar11974492019-04-17 07:16:39 +0000166 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800167
Filip Tehlar11974492019-04-17 07:16:39 +0000168 pd->sa_index = current_sa_index;
169 next[0] = AH_ENCRYPT_NEXT_DROP;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800170
Benoît Ganne5527a782022-01-18 15:56:41 +0100171 if (PREDICT_FALSE ((u16) ~0 == sa0->thread_index))
Neale Rannsf62a8c02019-04-02 08:13:33 +0000172 {
173 /* this is the first packet to use this SA, claim the SA
174 * for this thread. this could happen simultaneously on
175 * another thread */
Neale Ranns1a52d372021-02-04 11:33:32 +0000176 clib_atomic_cmp_and_swap (&sa0->thread_index, ~0,
Neale Rannsf62a8c02019-04-02 08:13:33 +0000177 ipsec_sa_assign_thread (thread_index));
178 }
179
Neale Ranns1a52d372021-02-04 11:33:32 +0000180 if (PREDICT_TRUE (thread_index != sa0->thread_index))
Neale Rannsf62a8c02019-04-02 08:13:33 +0000181 {
Neale Rannsaa7d7662021-02-10 08:42:49 +0000182 vnet_buffer (b[0])->ipsec.thread_index = sa0->thread_index;
Neale Rannsf62a8c02019-04-02 08:13:33 +0000183 next[0] = AH_ENCRYPT_NEXT_HANDOFF;
184 goto next;
185 }
186
Filip Tehlar11974492019-04-17 07:16:39 +0000187 if (PREDICT_FALSE (esp_seq_advance (sa0)))
188 {
Arthur de Kerhorad95b062022-11-16 19:12:05 +0100189 ah_encrypt_set_next_index (b[0], node, vm->thread_index,
190 AH_ENCRYPT_ERROR_SEQ_CYCLED, 0, next,
191 AH_ENCRYPT_NEXT_DROP, current_sa_index);
Filip Tehlar11974492019-04-17 07:16:39 +0000192 pd->skip = 1;
193 goto next;
194 }
195
196 current_sa_pkts += 1;
197 current_sa_bytes += b[0]->current_length;
198
199 ssize_t adv;
200 ih0 = vlib_buffer_get_current (b[0]);
Filip Tehlar11974492019-04-17 07:16:39 +0000201
202 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
203 {
204 if (is_ip6)
205 adv = -sizeof (ip6_and_ah_header_t);
206 else
207 adv = -sizeof (ip4_and_ah_header_t);
208 }
209 else
210 {
211 adv = -sizeof (ah_header_t);
212 }
213
214 icv_size = sa0->integ_icv_size;
215 const u8 padding_len = ah_calc_icv_padding_len (icv_size, is_ip6);
216 adv -= padding_len;
217 /* transport mode save the eth header before it is overwritten */
218 if (PREDICT_FALSE (!ipsec_sa_is_set_IS_TUNNEL (sa0)))
219 {
Klement Sekera45155452019-06-19 11:26:34 +0000220 const u32 l2_len = vnet_buffer (b[0])->ip.save_rewrite_length;
221 u8 *l2_hdr_in = (u8 *) vlib_buffer_get_current (b[0]) - l2_len;
222
223 u8 *l2_hdr_out = l2_hdr_in + adv - icv_size;
224
225 clib_memcpy_le32 (l2_hdr_out, l2_hdr_in, l2_len);
Filip Tehlar11974492019-04-17 07:16:39 +0000226 }
227
228 vlib_buffer_advance (b[0], adv - icv_size);
229
230 if (is_ip6)
231 {
232 ih6_0 = (ip6_and_ah_header_t *) ih0;
233 ip_hdr_size = sizeof (ip6_header_t);
234 oh6_0 = vlib_buffer_get_current (b[0]);
235 pd->current_data = b[0]->current_data;
Filip Tehlar11974492019-04-17 07:16:39 +0000236 pd->hop_limit = ih6_0->ip6.hop_limit;
Neale Ranns041add72020-01-02 04:06:10 +0000237
238 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
Filip Tehlar11974492019-04-17 07:16:39 +0000239 ih6_0->ip6.ip_version_traffic_class_and_flow_label;
Neale Ranns041add72020-01-02 04:06:10 +0000240
Neale Ranns9ec846c2021-02-09 14:04:02 +0000241 if (PREDICT_FALSE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
242 {
243 ip6_set_dscp_network_order (&oh6_0->ip6, sa0->tunnel.t_dscp);
244 tunnel_encap_fixup_6o6 (sa0->tunnel_flags, &ih6_0->ip6,
245 &oh6_0->ip6);
246 }
Neale Ranns041add72020-01-02 04:06:10 +0000247 pd->ip_version_traffic_class_and_flow_label =
248 oh6_0->ip6.ip_version_traffic_class_and_flow_label;
Neale Ranns041add72020-01-02 04:06:10 +0000249
Filip Tehlar11974492019-04-17 07:16:39 +0000250 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800251 {
Filip Tehlar11974492019-04-17 07:16:39 +0000252 next_hdr_type = IP_PROTOCOL_IPV6;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800253 }
Filip Tehlar11974492019-04-17 07:16:39 +0000254 else
255 {
256 next_hdr_type = ih6_0->ip6.protocol;
257 memmove (oh6_0, ih6_0, sizeof (ip6_header_t));
258 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800259
Filip Tehlar11974492019-04-17 07:16:39 +0000260 clib_memcpy_fast (&oh6_0->ip6, &ip6_hdr_template, 8);
261 oh6_0->ah.reserved = 0;
262 oh6_0->ah.nexthdr = next_hdr_type;
263 oh6_0->ah.spi = clib_net_to_host_u32 (sa0->spi);
264 oh6_0->ah.seq_no = clib_net_to_host_u32 (sa0->seq);
265 oh6_0->ip6.payload_length =
266 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b[0]) -
267 sizeof (ip6_header_t));
268 oh6_0->ah.hdrlen =
269 (sizeof (ah_header_t) + icv_size + padding_len) / 4 - 2;
270 }
271 else
272 {
273 ip_hdr_size = sizeof (ip4_header_t);
274 oh0 = vlib_buffer_get_current (b[0]);
Neale Ranns041add72020-01-02 04:06:10 +0000275 pd->ttl = ih0->ip4.ttl;
276
Neale Ranns9ec846c2021-02-09 14:04:02 +0000277 if (PREDICT_FALSE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
278 {
279 if (sa0->tunnel.t_dscp)
280 pd->tos = sa0->tunnel.t_dscp << 2;
281 else
282 {
283 pd->tos = ih0->ip4.tos;
284
285 if (!(sa0->tunnel_flags &
286 TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP))
287 pd->tos &= 0x3;
288 if (!(sa0->tunnel_flags &
289 TUNNEL_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
290 pd->tos &= 0xfc;
291 }
292 }
Neale Ranns041add72020-01-02 04:06:10 +0000293 else
294 {
295 pd->tos = ih0->ip4.tos;
Neale Ranns041add72020-01-02 04:06:10 +0000296 }
Neale Ranns9ec846c2021-02-09 14:04:02 +0000297
Filip Tehlar11974492019-04-17 07:16:39 +0000298 pd->current_data = b[0]->current_data;
Neale Ranns041add72020-01-02 04:06:10 +0000299 clib_memset (oh0, 0, sizeof (ip4_and_ah_header_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800300
Damjan Mariond709cbc2019-03-26 13:16:42 +0100301 if (PREDICT_TRUE (ipsec_sa_is_set_IS_TUNNEL (sa0)))
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800302 {
Filip Tehlar11974492019-04-17 07:16:39 +0000303 next_hdr_type = IP_PROTOCOL_IP_IN_IP;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800304 }
305 else
306 {
Filip Tehlar11974492019-04-17 07:16:39 +0000307 next_hdr_type = ih0->ip4.protocol;
308 memmove (oh0, ih0, sizeof (ip4_header_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800309 }
310
Filip Tehlar11974492019-04-17 07:16:39 +0000311 clib_memcpy_fast (&oh0->ip4, &ip4_hdr_template,
312 sizeof (ip4_header_t) -
313 sizeof (ip4_address_pair_t));
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800314
Filip Tehlar11974492019-04-17 07:16:39 +0000315 oh0->ip4.length =
316 clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b[0]));
317 oh0->ah.spi = clib_net_to_host_u32 (sa0->spi);
318 oh0->ah.seq_no = clib_net_to_host_u32 (sa0->seq);
319 oh0->ah.nexthdr = next_hdr_type;
320 oh0->ah.hdrlen =
321 (sizeof (ah_header_t) + icv_size + padding_len) / 4 - 2;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800322 }
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800323
Filip Tehlar11974492019-04-17 07:16:39 +0000324 if (PREDICT_TRUE (!is_ip6 && ipsec_sa_is_set_IS_TUNNEL (sa0) &&
325 !ipsec_sa_is_set_IS_TUNNEL_V6 (sa0)))
326 {
327 clib_memcpy_fast (&oh0->ip4.address_pair,
328 &sa0->ip4_hdr.address_pair,
Neale Rannsf3a66222020-01-02 05:04:00 +0000329 sizeof (ip4_address_pair_t));
Filip Tehlar11974492019-04-17 07:16:39 +0000330
Neale Ranns72f2a3a2019-06-17 15:43:38 +0000331 next[0] = sa0->dpo.dpoi_next_node;
332 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = sa0->dpo.dpoi_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000333 }
334 else if (is_ip6 && ipsec_sa_is_set_IS_TUNNEL (sa0) &&
335 ipsec_sa_is_set_IS_TUNNEL_V6 (sa0))
336 {
337 clib_memcpy_fast (&oh6_0->ip6.src_address,
338 &sa0->ip6_hdr.src_address,
339 sizeof (ip6_address_t) * 2);
Neale Ranns72f2a3a2019-06-17 15:43:38 +0000340 next[0] = sa0->dpo.dpoi_next_node;
341 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = sa0->dpo.dpoi_index;
Filip Tehlar11974492019-04-17 07:16:39 +0000342 }
343
344 if (PREDICT_TRUE (sa0->integ_op_id))
345 {
346 vnet_crypto_op_t *op;
347 vec_add2_aligned (ptd->integ_ops, op, 1, CLIB_CACHE_LINE_BYTES);
348 vnet_crypto_op_init (op, sa0->integ_op_id);
349 op->src = vlib_buffer_get_current (b[0]);
350 op->len = b[0]->current_length;
351 op->digest = vlib_buffer_get_current (b[0]) + ip_hdr_size +
352 sizeof (ah_header_t);
353 clib_memset (op->digest, 0, icv_size);
354 op->digest_len = icv_size;
355 op->key_index = sa0->integ_key_index;
356 op->user_data = b - bufs;
357 if (ipsec_sa_is_set_USE_ESN (sa0))
358 {
359 u32 seq_hi = clib_host_to_net_u32 (sa0->seq_hi);
360
361 op->len += sizeof (seq_hi);
362 clib_memcpy (op->src + b[0]->current_length, &seq_hi,
363 sizeof (seq_hi));
364 }
365 }
366
367 if (!ipsec_sa_is_set_IS_TUNNEL (sa0))
368 {
369 next[0] = AH_ENCRYPT_NEXT_INTERFACE_OUTPUT;
370 vlib_buffer_advance (b[0], -sizeof (ethernet_header_t));
371 }
372
373 next:
Neale Ranns9ec846c2021-02-09 14:04:02 +0000374 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
375 {
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000376 sa0 = ipsec_sa_get (pd->sa_index);
Neale Ranns9ec846c2021-02-09 14:04:02 +0000377 ah_encrypt_trace_t *tr =
378 vlib_add_trace (vm, node, b[0], sizeof (*tr));
379 tr->spi = sa0->spi;
380 tr->seq_lo = sa0->seq;
381 tr->seq_hi = sa0->seq_hi;
382 tr->integ_alg = sa0->integ_alg;
383 tr->sa_index = pd->sa_index;
384 }
385
Filip Tehlar11974492019-04-17 07:16:39 +0000386 n_left -= 1;
387 next += 1;
388 pd += 1;
389 b += 1;
390 }
391
392 n_left = frame->n_vectors;
393 next = nexts;
394 pd = pkt_data;
395 b = bufs;
396
397 vlib_node_increment_counter (vm, node->node_index,
398 AH_ENCRYPT_ERROR_RX_PKTS, n_left);
399 vlib_increment_combined_counter (&ipsec_sa_counters, thread_index,
400 current_sa_index, current_sa_pkts,
401 current_sa_bytes);
402
403 ah_process_ops (vm, node, ptd->integ_ops, bufs, nexts);
404
405 while (n_left)
406 {
407 if (pd->skip)
Neale Ranns9ec846c2021-02-09 14:04:02 +0000408 goto next_pkt;
Filip Tehlar11974492019-04-17 07:16:39 +0000409
410 if (is_ip6)
411 {
412 oh6_0 = (ip6_and_ah_header_t *) (b[0]->data + pd->current_data);
413 oh6_0->ip6.hop_limit = pd->hop_limit;
414 oh6_0->ip6.ip_version_traffic_class_and_flow_label =
415 pd->ip_version_traffic_class_and_flow_label;
416 }
417 else
418 {
419 oh0 = (ip4_and_ah_header_t *) (b[0]->data + pd->current_data);
420 oh0->ip4.ttl = pd->ttl;
421 oh0->ip4.tos = pd->tos;
422 oh0->ip4.checksum = ip4_header_checksum (&oh0->ip4);
423 }
424
Neale Ranns9ec846c2021-02-09 14:04:02 +0000425 next_pkt:
Filip Tehlar11974492019-04-17 07:16:39 +0000426 n_left -= 1;
427 next += 1;
428 pd += 1;
429 b += 1;
430 }
431
432 n_left = frame->n_vectors;
433 vlib_buffer_enqueue_to_next (vm, node, from, nexts, n_left);
434
435 return n_left;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800436}
437
Klement Sekerab8f35442018-10-29 13:38:19 +0100438VLIB_NODE_FN (ah4_encrypt_node) (vlib_main_t * vm,
439 vlib_node_runtime_t * node,
440 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200441{
442 return ah_encrypt_inline (vm, node, from_frame, 0 /* is_ip6 */ );
443}
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800444
445/* *INDENT-OFF* */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200446VLIB_REGISTER_NODE (ah4_encrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200447 .name = "ah4-encrypt",
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800448 .vector_size = sizeof (u32),
449 .format_trace = format_ah_encrypt_trace,
450 .type = VLIB_NODE_TYPE_INTERNAL,
451
Neale Ranns93688d72022-08-09 03:34:51 +0000452 .n_errors = AH_ENCRYPT_N_ERROR,
453 .error_counters = ah_encrypt_error_counters,
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800454
455 .n_next_nodes = AH_ENCRYPT_N_NEXT,
456 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +0000457 [AH_ENCRYPT_NEXT_DROP] = "ip4-drop",
458 [AH_ENCRYPT_NEXT_HANDOFF] = "ah4-encrypt-handoff",
459 [AH_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output",
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800460 },
461};
462/* *INDENT-ON* */
463
Klement Sekerab8f35442018-10-29 13:38:19 +0100464VLIB_NODE_FN (ah6_encrypt_node) (vlib_main_t * vm,
465 vlib_node_runtime_t * node,
466 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200467{
468 return ah_encrypt_inline (vm, node, from_frame, 1 /* is_ip6 */ );
469}
470
471/* *INDENT-OFF* */
472VLIB_REGISTER_NODE (ah6_encrypt_node) = {
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200473 .name = "ah6-encrypt",
474 .vector_size = sizeof (u32),
475 .format_trace = format_ah_encrypt_trace,
476 .type = VLIB_NODE_TYPE_INTERNAL,
477
Neale Ranns93688d72022-08-09 03:34:51 +0000478 .n_errors = AH_ENCRYPT_N_ERROR,
479 .error_counters = ah_encrypt_error_counters,
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200480
481 .n_next_nodes = AH_ENCRYPT_N_NEXT,
482 .next_nodes = {
Neale Rannsf62a8c02019-04-02 08:13:33 +0000483 [AH_ENCRYPT_NEXT_DROP] = "ip6-drop",
484 [AH_ENCRYPT_NEXT_HANDOFF] = "ah6-encrypt-handoff",
485 [AH_ENCRYPT_NEXT_INTERFACE_OUTPUT] = "interface-output",
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200486 },
487};
488/* *INDENT-ON* */
489
Neale Ranns2d498302021-02-25 08:38:58 +0000490#ifndef CLIB_MARCH_VARIANT
491
492static clib_error_t *
493ah_encrypt_init (vlib_main_t *vm)
494{
495 ipsec_main_t *im = &ipsec_main;
496
497 im->ah4_enc_fq_index =
498 vlib_frame_queue_main_init (ah4_encrypt_node.index, 0);
499 im->ah6_enc_fq_index =
500 vlib_frame_queue_main_init (ah6_encrypt_node.index, 0);
501
502 return 0;
503}
504
505VLIB_INIT_FUNCTION (ah_encrypt_init);
506
507#endif
508
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800509/*
510 * fd.io coding-style-patch-verification: ON
511 *
512 * Local Variables:
513 * eval: (c-set-style "gnu")
514 * End:
515 */