Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * decap.c : IPSec tunnel decapsulation |
| 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> |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 21 | #include <vnet/feature/feature.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 22 | |
| 23 | #include <vnet/ipsec/ipsec.h> |
| 24 | #include <vnet/ipsec/esp.h> |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 25 | #include <vnet/ipsec/ah.h> |
Neale Ranns | 918c161 | 2019-02-21 23:34:59 -0800 | [diff] [blame] | 26 | #include <vnet/ipsec/ipsec_io.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 28 | #define foreach_ipsec_input_error \ |
| 29 | _(RX_PKTS, "IPSEC pkts received") \ |
| 30 | _(RX_MATCH_PKTS, "IPSEC pkts matched") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 32 | typedef enum |
| 33 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 34 | #define _(sym,str) IPSEC_INPUT_ERROR_##sym, |
| 35 | foreach_ipsec_input_error |
| 36 | #undef _ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 37 | IPSEC_INPUT_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | } ipsec_input_error_t; |
| 39 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 40 | static char *ipsec_input_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 41 | #define _(sym,string) string, |
| 42 | foreach_ipsec_input_error |
| 43 | #undef _ |
| 44 | }; |
| 45 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 46 | typedef struct |
| 47 | { |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 48 | ip_protocol_t proto; |
Pierre Pfister | 6221927 | 2018-11-26 09:29:00 +0100 | [diff] [blame] | 49 | u32 spd; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 50 | u32 policy_index; |
Matus Fabian | 5539a07 | 2016-09-07 05:57:09 -0700 | [diff] [blame] | 51 | u32 sa_id; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | u32 spi; |
| 53 | u32 seq; |
| 54 | } ipsec_input_trace_t; |
| 55 | |
| 56 | /* packet trace format function */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 57 | static u8 * |
| 58 | format_ipsec_input_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | { |
| 60 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 61 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 62 | ipsec_input_trace_t *t = va_arg (*args, ipsec_input_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | |
Guillaume Solignac | 8f818cc | 2019-05-15 12:02:33 +0200 | [diff] [blame] | 64 | s = format (s, "%U: sa_id %u spd %u policy %d spi %u (0x%08x) seq %u", |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 65 | format_ip_protocol, t->proto, t->sa_id, |
Guillaume Solignac | 8f818cc | 2019-05-15 12:02:33 +0200 | [diff] [blame] | 66 | t->spd, t->policy_index, t->spi, t->spi, t->seq); |
Matus Fabian | 5539a07 | 2016-09-07 05:57:09 -0700 | [diff] [blame] | 67 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | return s; |
| 69 | } |
| 70 | |
| 71 | always_inline ipsec_policy_t * |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 72 | ipsec_input_protect_policy_match (ipsec_spd_t * spd, u32 sa, u32 da, u32 spi) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | { |
| 74 | ipsec_main_t *im = &ipsec_main; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 75 | ipsec_policy_t *p; |
| 76 | ipsec_sa_t *s; |
| 77 | u32 *i; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 78 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 79 | vec_foreach (i, spd->policies[IPSEC_SPD_POLICY_IP4_INBOUND_PROTECT]) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 80 | { |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 81 | p = pool_elt_at_index (im->policies, *i); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 82 | s = pool_elt_at_index (im->sad, p->sa_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 84 | if (spi != s->spi) |
| 85 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 87 | if (ipsec_sa_is_set_IS_TUNNEL (s)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 88 | { |
Neale Ranns | d2029bc | 2019-07-11 09:31:19 +0000 | [diff] [blame] | 89 | if (da != clib_net_to_host_u32 (s->tunnel_dst_addr.ip4.as_u32)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 90 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | |
Neale Ranns | d2029bc | 2019-07-11 09:31:19 +0000 | [diff] [blame] | 92 | if (sa != clib_net_to_host_u32 (s->tunnel_src_addr.ip4.as_u32)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 93 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 95 | return p; |
| 96 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | |
Neale Ranns | d2029bc | 2019-07-11 09:31:19 +0000 | [diff] [blame] | 98 | if (da < clib_net_to_host_u32 (p->laddr.start.ip4.as_u32)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 99 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | |
Neale Ranns | d2029bc | 2019-07-11 09:31:19 +0000 | [diff] [blame] | 101 | if (da > clib_net_to_host_u32 (p->laddr.stop.ip4.as_u32)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 102 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 103 | |
Neale Ranns | d2029bc | 2019-07-11 09:31:19 +0000 | [diff] [blame] | 104 | if (sa < clib_net_to_host_u32 (p->raddr.start.ip4.as_u32)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 105 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 106 | |
Neale Ranns | d2029bc | 2019-07-11 09:31:19 +0000 | [diff] [blame] | 107 | if (sa > clib_net_to_host_u32 (p->raddr.stop.ip4.as_u32)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 108 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 110 | return p; |
| 111 | } |
| 112 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | always_inline uword |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 116 | ip6_addr_match_range (ip6_address_t * a, ip6_address_t * la, |
| 117 | ip6_address_t * ua) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 118 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 119 | if ((memcmp (a->as_u64, la->as_u64, 2 * sizeof (u64)) >= 0) && |
| 120 | (memcmp (a->as_u64, ua->as_u64, 2 * sizeof (u64)) <= 0)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | return 1; |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | always_inline ipsec_policy_t * |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 126 | ipsec6_input_protect_policy_match (ipsec_spd_t * spd, |
| 127 | ip6_address_t * sa, |
| 128 | ip6_address_t * da, u32 spi) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 129 | { |
| 130 | ipsec_main_t *im = &ipsec_main; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 131 | ipsec_policy_t *p; |
| 132 | ipsec_sa_t *s; |
| 133 | u32 *i; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 134 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 135 | vec_foreach (i, spd->policies[IPSEC_SPD_POLICY_IP6_INBOUND_PROTECT]) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 136 | { |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 137 | p = pool_elt_at_index (im->policies, *i); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 138 | s = pool_elt_at_index (im->sad, p->sa_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 140 | if (spi != s->spi) |
| 141 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | |
Damjan Marion | d709cbc | 2019-03-26 13:16:42 +0100 | [diff] [blame] | 143 | if (ipsec_sa_is_set_IS_TUNNEL (s)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 144 | { |
| 145 | if (!ip6_address_is_equal (sa, &s->tunnel_src_addr.ip6)) |
| 146 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 147 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 148 | if (!ip6_address_is_equal (da, &s->tunnel_dst_addr.ip6)) |
| 149 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 150 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 151 | return p; |
| 152 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 154 | if (!ip6_addr_match_range (sa, &p->raddr.start.ip6, &p->raddr.stop.ip6)) |
| 155 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 157 | if (!ip6_addr_match_range (da, &p->laddr.start.ip6, &p->laddr.stop.ip6)) |
| 158 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 160 | return p; |
| 161 | } |
| 162 | return 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 165 | static vlib_node_registration_t ipsec4_input_node; |
Jean-Mickael Guerin | 8941ec2 | 2016-03-04 14:14:21 +0100 | [diff] [blame] | 166 | |
Klement Sekera | b8f3544 | 2018-10-29 13:38:19 +0100 | [diff] [blame] | 167 | VLIB_NODE_FN (ipsec4_input_node) (vlib_main_t * vm, |
| 168 | vlib_node_runtime_t * node, |
| 169 | vlib_frame_t * from_frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | { |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 171 | u32 n_left_from, *from, next_index, *to_next, thread_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 172 | ipsec_main_t *im = &ipsec_main; |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 173 | u32 ipsec_unprocessed = 0; |
| 174 | u32 ipsec_matched = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | |
| 176 | from = vlib_frame_vector_args (from_frame); |
| 177 | n_left_from = from_frame->n_vectors; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 178 | thread_index = vm->thread_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | |
| 180 | next_index = node->cached_next_index; |
| 181 | |
| 182 | while (n_left_from > 0) |
| 183 | { |
| 184 | u32 n_left_to_next; |
| 185 | |
| 186 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 187 | |
| 188 | while (n_left_from > 0 && n_left_to_next > 0) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 189 | { |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 190 | u32 bi0, next0, pi0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 191 | vlib_buffer_t *b0; |
| 192 | ip4_header_t *ip0; |
| 193 | esp_header_t *esp0; |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 194 | ah_header_t *ah0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 195 | ip4_ipsec_config_t *c0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 196 | ipsec_spd_t *spd0; |
Matus Fabian | 5539a07 | 2016-09-07 05:57:09 -0700 | [diff] [blame] | 197 | ipsec_policy_t *p0 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 199 | bi0 = to_next[0] = from[0]; |
| 200 | from += 1; |
| 201 | n_left_from -= 1; |
| 202 | to_next += 1; |
| 203 | n_left_to_next -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 204 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 205 | b0 = vlib_get_buffer (vm, bi0); |
Szymon Sliwa | 65a2727 | 2018-05-09 14:28:08 +0200 | [diff] [blame] | 206 | b0->flags |= VNET_BUFFER_F_IS_IP4; |
| 207 | b0->flags &= ~VNET_BUFFER_F_IS_IP6; |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 208 | c0 = vnet_feature_next_with_data (&next0, b0, sizeof (c0[0])); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 209 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 210 | spd0 = pool_elt_at_index (im->spds, c0->spd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 211 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 212 | ip0 = vlib_buffer_get_current (b0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 213 | |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 214 | if (PREDICT_TRUE |
| 215 | (ip0->protocol == IP_PROTOCOL_IPSEC_ESP |
| 216 | || ip0->protocol == IP_PROTOCOL_UDP)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 217 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 218 | #if 0 |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 219 | clib_warning |
| 220 | ("packet received from %U to %U spi %u size %u spd_id %u", |
| 221 | format_ip4_address, ip0->src_address.as_u8, |
| 222 | format_ip4_address, ip0->dst_address.as_u8, |
| 223 | clib_net_to_host_u32 (esp0->spi), |
| 224 | clib_net_to_host_u16 (ip0->length), spd0->id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 225 | #endif |
Matus Fabian | 5539a07 | 2016-09-07 05:57:09 -0700 | [diff] [blame] | 226 | |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 227 | esp0 = (esp_header_t *) ((u8 *) ip0 + ip4_header_bytes (ip0)); |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 228 | if (PREDICT_FALSE (ip0->protocol == IP_PROTOCOL_UDP)) |
| 229 | { |
| 230 | esp0 = |
| 231 | (esp_header_t *) ((u8 *) esp0 + sizeof (udp_header_t)); |
| 232 | } |
| 233 | /* FIXME TODO missing check whether there is enough data inside |
| 234 | * IP/UDP to contain ESP header & stuff ? */ |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 235 | p0 = ipsec_input_protect_policy_match (spd0, |
Neale Ranns | d2029bc | 2019-07-11 09:31:19 +0000 | [diff] [blame] | 236 | clib_net_to_host_u32 |
| 237 | (ip0->src_address. |
| 238 | as_u32), |
| 239 | clib_net_to_host_u32 |
| 240 | (ip0->dst_address. |
| 241 | as_u32), |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 242 | clib_net_to_host_u32 |
| 243 | (esp0->spi)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 244 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 245 | if (PREDICT_TRUE (p0 != NULL)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 246 | { |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 247 | ipsec_matched += 1; |
| 248 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 249 | pi0 = p0 - im->policies; |
| 250 | vlib_increment_combined_counter |
| 251 | (&ipsec_spd_policy_counters, |
| 252 | thread_index, pi0, 1, |
| 253 | clib_net_to_host_u16 (ip0->length)); |
| 254 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 255 | vnet_buffer (b0)->ipsec.sad_index = p0->sa_index; |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 256 | next0 = im->esp4_decrypt_next_index; |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 257 | vlib_buffer_advance (b0, ((u8 *) esp0 - (u8 *) ip0)); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 258 | goto trace0; |
| 259 | } |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 260 | else |
| 261 | { |
| 262 | pi0 = ~0; |
| 263 | }; |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 264 | |
| 265 | /* FIXME bypass and discard */ |
| 266 | trace0: |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 267 | if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) && |
| 268 | PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 269 | { |
| 270 | ipsec_input_trace_t *tr = |
| 271 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 272 | |
| 273 | tr->proto = ip0->protocol; |
| 274 | if (p0) |
| 275 | tr->sa_id = p0->sa_id; |
| 276 | tr->spi = clib_net_to_host_u32 (esp0->spi); |
| 277 | tr->seq = clib_net_to_host_u32 (esp0->seq); |
| 278 | tr->spd = spd0->id; |
| 279 | tr->policy_index = pi0; |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 280 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 281 | } |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 282 | else if (ip0->protocol == IP_PROTOCOL_IPSEC_AH) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 283 | { |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 284 | ah0 = (ah_header_t *) ((u8 *) ip0 + ip4_header_bytes (ip0)); |
| 285 | p0 = ipsec_input_protect_policy_match (spd0, |
Neale Ranns | d2029bc | 2019-07-11 09:31:19 +0000 | [diff] [blame] | 286 | clib_net_to_host_u32 |
| 287 | (ip0->src_address. |
| 288 | as_u32), |
| 289 | clib_net_to_host_u32 |
| 290 | (ip0->dst_address. |
| 291 | as_u32), |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 292 | clib_net_to_host_u32 |
| 293 | (ah0->spi)); |
| 294 | |
| 295 | if (PREDICT_TRUE (p0 != 0)) |
Matus Fabian | 5539a07 | 2016-09-07 05:57:09 -0700 | [diff] [blame] | 296 | { |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 297 | ipsec_matched += 1; |
| 298 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 299 | pi0 = p0 - im->policies; |
| 300 | vlib_increment_combined_counter |
| 301 | (&ipsec_spd_policy_counters, |
| 302 | thread_index, pi0, 1, |
| 303 | clib_net_to_host_u16 (ip0->length)); |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 304 | |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 305 | vnet_buffer (b0)->ipsec.sad_index = p0->sa_index; |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 306 | next0 = im->ah4_decrypt_next_index; |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 307 | goto trace1; |
| 308 | } |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 309 | else |
| 310 | { |
| 311 | pi0 = ~0; |
| 312 | } |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 313 | /* FIXME bypass and discard */ |
| 314 | trace1: |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 315 | if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) && |
| 316 | PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 317 | { |
| 318 | ipsec_input_trace_t *tr = |
| 319 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 320 | |
| 321 | tr->proto = ip0->protocol; |
| 322 | if (p0) |
| 323 | tr->sa_id = p0->sa_id; |
| 324 | tr->spi = clib_net_to_host_u32 (ah0->spi); |
| 325 | tr->seq = clib_net_to_host_u32 (ah0->seq_no); |
| 326 | tr->spd = spd0->id; |
| 327 | tr->policy_index = pi0; |
Matus Fabian | 5539a07 | 2016-09-07 05:57:09 -0700 | [diff] [blame] | 328 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 329 | } |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 330 | else |
| 331 | { |
| 332 | ipsec_unprocessed += 1; |
| 333 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 335 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 336 | to_next, n_left_to_next, bi0, |
| 337 | next0); |
| 338 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 339 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 340 | } |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 341 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 342 | vlib_node_increment_counter (vm, ipsec4_input_node.index, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 343 | IPSEC_INPUT_ERROR_RX_PKTS, |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 344 | from_frame->n_vectors - ipsec_unprocessed); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 345 | |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 346 | vlib_node_increment_counter (vm, ipsec4_input_node.index, |
| 347 | IPSEC_INPUT_ERROR_RX_MATCH_PKTS, |
| 348 | ipsec_matched); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | return from_frame->n_vectors; |
| 350 | } |
| 351 | |
| 352 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 353 | /* *INDENT-OFF* */ |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 354 | VLIB_REGISTER_NODE (ipsec4_input_node,static) = { |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 355 | .name = "ipsec4-input-feature", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 356 | .vector_size = sizeof (u32), |
| 357 | .format_trace = format_ipsec_input_trace, |
| 358 | .type = VLIB_NODE_TYPE_INTERNAL, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | .n_errors = ARRAY_LEN(ipsec_input_error_strings), |
| 360 | .error_strings = ipsec_input_error_strings, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | .n_next_nodes = IPSEC_INPUT_N_NEXT, |
| 362 | .next_nodes = { |
| 363 | #define _(s,n) [IPSEC_INPUT_NEXT_##s] = n, |
| 364 | foreach_ipsec_input_next |
| 365 | #undef _ |
| 366 | }, |
| 367 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 368 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 370 | static vlib_node_registration_t ipsec6_input_node; |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 371 | |
Klement Sekera | b8f3544 | 2018-10-29 13:38:19 +0100 | [diff] [blame] | 372 | |
| 373 | VLIB_NODE_FN (ipsec6_input_node) (vlib_main_t * vm, |
| 374 | vlib_node_runtime_t * node, |
| 375 | vlib_frame_t * from_frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 376 | { |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 377 | u32 n_left_from, *from, next_index, *to_next, thread_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 378 | ipsec_main_t *im = &ipsec_main; |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 379 | u32 ipsec_unprocessed = 0; |
| 380 | u32 ipsec_matched = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 381 | |
| 382 | from = vlib_frame_vector_args (from_frame); |
| 383 | n_left_from = from_frame->n_vectors; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 384 | thread_index = vm->thread_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 385 | |
| 386 | next_index = node->cached_next_index; |
| 387 | |
| 388 | while (n_left_from > 0) |
| 389 | { |
| 390 | u32 n_left_to_next; |
| 391 | |
| 392 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 393 | |
| 394 | while (n_left_from > 0 && n_left_to_next > 0) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 395 | { |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 396 | u32 bi0, next0, pi0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 397 | vlib_buffer_t *b0; |
| 398 | ip6_header_t *ip0; |
| 399 | esp_header_t *esp0; |
| 400 | ip4_ipsec_config_t *c0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 401 | ipsec_spd_t *spd0; |
Matus Fabian | 5539a07 | 2016-09-07 05:57:09 -0700 | [diff] [blame] | 402 | ipsec_policy_t *p0 = 0; |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 403 | ah_header_t *ah0; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 404 | u32 header_size = sizeof (ip0[0]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 405 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 406 | bi0 = to_next[0] = from[0]; |
| 407 | from += 1; |
| 408 | n_left_from -= 1; |
| 409 | to_next += 1; |
| 410 | n_left_to_next -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 411 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 412 | b0 = vlib_get_buffer (vm, bi0); |
Szymon Sliwa | 65a2727 | 2018-05-09 14:28:08 +0200 | [diff] [blame] | 413 | b0->flags |= VNET_BUFFER_F_IS_IP6; |
| 414 | b0->flags &= ~VNET_BUFFER_F_IS_IP4; |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 415 | c0 = vnet_feature_next_with_data (&next0, b0, sizeof (c0[0])); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 416 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 417 | spd0 = pool_elt_at_index (im->spds, c0->spd_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 418 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 419 | ip0 = vlib_buffer_get_current (b0); |
| 420 | esp0 = (esp_header_t *) ((u8 *) ip0 + header_size); |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 421 | ah0 = (ah_header_t *) ((u8 *) ip0 + header_size); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 422 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 423 | if (PREDICT_TRUE (ip0->protocol == IP_PROTOCOL_IPSEC_ESP)) |
| 424 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 425 | #if 0 |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 426 | clib_warning |
| 427 | ("packet received from %U to %U spi %u size %u spd_id %u", |
| 428 | format_ip6_address, &ip0->src_address, format_ip6_address, |
| 429 | &ip0->dst_address, clib_net_to_host_u32 (esp0->spi), |
| 430 | clib_net_to_host_u16 (ip0->payload_length) + header_size, |
| 431 | spd0->id); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | #endif |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 433 | p0 = ipsec6_input_protect_policy_match (spd0, |
| 434 | &ip0->src_address, |
| 435 | &ip0->dst_address, |
| 436 | clib_net_to_host_u32 |
| 437 | (esp0->spi)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 438 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 439 | if (PREDICT_TRUE (p0 != 0)) |
| 440 | { |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 441 | ipsec_matched += 1; |
| 442 | |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 443 | pi0 = p0 - im->policies; |
| 444 | vlib_increment_combined_counter |
| 445 | (&ipsec_spd_policy_counters, |
| 446 | thread_index, pi0, 1, |
| 447 | clib_net_to_host_u16 (ip0->payload_length) + |
| 448 | header_size); |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 449 | |
Damjan Marion | 9c6ae5f | 2016-11-15 23:20:01 +0100 | [diff] [blame] | 450 | vnet_buffer (b0)->ipsec.sad_index = p0->sa_index; |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 451 | next0 = im->esp6_decrypt_next_index; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 452 | vlib_buffer_advance (b0, header_size); |
| 453 | goto trace0; |
| 454 | } |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 455 | else |
| 456 | { |
| 457 | pi0 = ~0; |
| 458 | } |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 459 | } |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 460 | else if (ip0->protocol == IP_PROTOCOL_IPSEC_AH) |
| 461 | { |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 462 | p0 = ipsec6_input_protect_policy_match (spd0, |
| 463 | &ip0->src_address, |
| 464 | &ip0->dst_address, |
| 465 | clib_net_to_host_u32 |
| 466 | (ah0->spi)); |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 467 | |
| 468 | if (PREDICT_TRUE (p0 != 0)) |
| 469 | { |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 470 | ipsec_matched += 1; |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 471 | pi0 = p0 - im->policies; |
| 472 | vlib_increment_combined_counter |
| 473 | (&ipsec_spd_policy_counters, |
| 474 | thread_index, pi0, 1, |
| 475 | clib_net_to_host_u16 (ip0->payload_length) + |
| 476 | header_size); |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 477 | |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 478 | vnet_buffer (b0)->ipsec.sad_index = p0->sa_index; |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 479 | next0 = im->ah6_decrypt_next_index; |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 480 | goto trace0; |
| 481 | } |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 482 | else |
| 483 | { |
| 484 | pi0 = ~0; |
| 485 | } |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 486 | } |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 487 | else |
| 488 | { |
| 489 | ipsec_unprocessed += 1; |
| 490 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 491 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 492 | trace0: |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 493 | if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) && |
| 494 | PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 495 | { |
| 496 | ipsec_input_trace_t *tr = |
| 497 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
Neale Ranns | a09c1ff | 2019-02-04 01:10:30 -0800 | [diff] [blame] | 498 | |
| 499 | if (p0) |
| 500 | tr->sa_id = p0->sa_id; |
| 501 | tr->proto = ip0->protocol; |
| 502 | tr->spi = clib_net_to_host_u32 (esp0->spi); |
| 503 | tr->seq = clib_net_to_host_u32 (esp0->seq); |
| 504 | tr->spd = spd0->id; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 505 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 507 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 508 | n_left_to_next, bi0, next0); |
| 509 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 510 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 511 | } |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 512 | |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 513 | vlib_node_increment_counter (vm, ipsec6_input_node.index, |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 514 | IPSEC_INPUT_ERROR_RX_PKTS, |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 515 | from_frame->n_vectors - ipsec_unprocessed); |
| 516 | |
| 517 | vlib_node_increment_counter (vm, ipsec6_input_node.index, |
| 518 | IPSEC_INPUT_ERROR_RX_MATCH_PKTS, |
| 519 | ipsec_matched); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 520 | |
| 521 | return from_frame->n_vectors; |
| 522 | } |
| 523 | |
| 524 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 525 | /* *INDENT-OFF* */ |
Klement Sekera | be5a5dd | 2018-10-09 16:05:48 +0200 | [diff] [blame] | 526 | VLIB_REGISTER_NODE (ipsec6_input_node,static) = { |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 527 | .name = "ipsec6-input-feature", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 528 | .vector_size = sizeof (u32), |
| 529 | .format_trace = format_ipsec_input_trace, |
| 530 | .type = VLIB_NODE_TYPE_INTERNAL, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 531 | .n_errors = ARRAY_LEN(ipsec_input_error_strings), |
| 532 | .error_strings = ipsec_input_error_strings, |
Kingwel Xie | c69ac31 | 2019-02-04 01:49:29 -0800 | [diff] [blame] | 533 | .n_next_nodes = IPSEC_INPUT_N_NEXT, |
| 534 | .next_nodes = { |
| 535 | #define _(s,n) [IPSEC_INPUT_NEXT_##s] = n, |
| 536 | foreach_ipsec_input_next |
| 537 | #undef _ |
| 538 | }, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 539 | }; |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 540 | /* *INDENT-ON* */ |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 541 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 542 | /* |
| 543 | * fd.io coding-style-patch-verification: ON |
| 544 | * |
| 545 | * Local Variables: |
| 546 | * eval: (c-set-style "gnu") |
| 547 | * End: |
| 548 | */ |