Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * ip/ip_lookup.h: ip (4 or 6) lookup structures, adjacencies, ... |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 40 | /** |
| 41 | * @file |
| 42 | * Definitions for all things IP (v4|v6) unicast and multicast lookup related. |
| 43 | * |
| 44 | * - Adjacency definitions and registration. |
| 45 | * - Callbacks on route add. |
| 46 | * - Callbacks on interface address change. |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 47 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | #ifndef included_ip_lookup_h |
| 49 | #define included_ip_lookup_h |
| 50 | |
| 51 | #include <vnet/vnet.h> |
| 52 | #include <vlib/buffer.h> |
Damjan Marion | 102ec52 | 2016-03-29 13:18:17 +0200 | [diff] [blame] | 53 | #include <vnet/ip/ip4_packet.h> |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 54 | #include <vnet/ip/ip6_packet.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 55 | #include <vnet/fib/fib_node.h> |
| 56 | #include <vnet/dpo/dpo.h> |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 57 | #include <vnet/feature/feature.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | |
Dave Barach | 6f9bca2 | 2016-04-30 10:25:32 -0400 | [diff] [blame] | 59 | /** @brief Common (IP4/IP6) next index stored in adjacency. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 60 | typedef enum |
| 61 | { |
Dave Barach | 6f9bca2 | 2016-04-30 10:25:32 -0400 | [diff] [blame] | 62 | /** Adjacency to drop this packet. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | IP_LOOKUP_NEXT_DROP, |
Dave Barach | 6f9bca2 | 2016-04-30 10:25:32 -0400 | [diff] [blame] | 64 | /** Adjacency to punt this packet. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | IP_LOOKUP_NEXT_PUNT, |
| 66 | |
Dave Barach | 6f9bca2 | 2016-04-30 10:25:32 -0400 | [diff] [blame] | 67 | /** This packet is for one of our own IP addresses. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | IP_LOOKUP_NEXT_LOCAL, |
| 69 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 70 | /** This packet matches an "incomplete adjacency" and packets |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | need to be passed to ARP to find rewrite string for |
| 72 | this destination. */ |
| 73 | IP_LOOKUP_NEXT_ARP, |
| 74 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 75 | /** This packet matches an "interface route" and packets |
| 76 | need to be passed to ARP to find rewrite string for |
| 77 | this destination. */ |
| 78 | IP_LOOKUP_NEXT_GLEAN, |
| 79 | |
Dave Barach | 6f9bca2 | 2016-04-30 10:25:32 -0400 | [diff] [blame] | 80 | /** This packet is to be rewritten and forwarded to the next |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 81 | processing node. This is typically the output interface but |
| 82 | might be another node for further output processing. */ |
| 83 | IP_LOOKUP_NEXT_REWRITE, |
| 84 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 85 | /** This packets follow a load-balance */ |
| 86 | IP_LOOKUP_NEXT_LOAD_BALANCE, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 88 | /** This packets follow a mid-chain adjacency */ |
| 89 | IP_LOOKUP_NEXT_MIDCHAIN, |
Damjan Marion | aca64c9 | 2016-04-13 09:48:56 +0200 | [diff] [blame] | 90 | |
Dave Barach | 6f9bca2 | 2016-04-30 10:25:32 -0400 | [diff] [blame] | 91 | /** This packets needs to go to ICMP error */ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 92 | IP_LOOKUP_NEXT_ICMP_ERROR, |
| 93 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 94 | /** Multicast Adjacency. */ |
| 95 | IP_LOOKUP_NEXT_MCAST, |
| 96 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | IP_LOOKUP_N_NEXT, |
| 98 | } ip_lookup_next_t; |
| 99 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 100 | typedef enum |
| 101 | { |
Ole Troan | f0f8522 | 2016-06-14 21:12:32 +0200 | [diff] [blame] | 102 | IP4_LOOKUP_N_NEXT = IP_LOOKUP_N_NEXT, |
| 103 | } ip4_lookup_next_t; |
| 104 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 105 | typedef enum |
| 106 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 107 | /* Hop-by-hop header handling */ |
Ole Troan | f0f8522 | 2016-06-14 21:12:32 +0200 | [diff] [blame] | 108 | IP6_LOOKUP_NEXT_HOP_BY_HOP = IP_LOOKUP_N_NEXT, |
| 109 | IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP, |
| 110 | IP6_LOOKUP_NEXT_POP_HOP_BY_HOP, |
| 111 | IP6_LOOKUP_N_NEXT, |
| 112 | } ip6_lookup_next_t; |
| 113 | |
Damjan Marion | b270789 | 2016-04-13 11:21:07 +0200 | [diff] [blame] | 114 | #define IP4_LOOKUP_NEXT_NODES { \ |
Damjan Marion | b270789 | 2016-04-13 11:21:07 +0200 | [diff] [blame] | 115 | [IP_LOOKUP_NEXT_DROP] = "ip4-drop", \ |
| 116 | [IP_LOOKUP_NEXT_PUNT] = "ip4-punt", \ |
| 117 | [IP_LOOKUP_NEXT_LOCAL] = "ip4-local", \ |
| 118 | [IP_LOOKUP_NEXT_ARP] = "ip4-arp", \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 119 | [IP_LOOKUP_NEXT_GLEAN] = "ip4-glean", \ |
Neale Ranns | f06aea5 | 2016-11-29 06:51:37 -0800 | [diff] [blame] | 120 | [IP_LOOKUP_NEXT_REWRITE] = "ip4-rewrite", \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 121 | [IP_LOOKUP_NEXT_MCAST] = "ip4-rewrite-mcast", \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 122 | [IP_LOOKUP_NEXT_MIDCHAIN] = "ip4-midchain", \ |
| 123 | [IP_LOOKUP_NEXT_LOAD_BALANCE] = "ip4-load-balance", \ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 124 | [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip4-icmp-error", \ |
Damjan Marion | b270789 | 2016-04-13 11:21:07 +0200 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | #define IP6_LOOKUP_NEXT_NODES { \ |
Damjan Marion | b270789 | 2016-04-13 11:21:07 +0200 | [diff] [blame] | 128 | [IP_LOOKUP_NEXT_DROP] = "ip6-drop", \ |
| 129 | [IP_LOOKUP_NEXT_PUNT] = "ip6-punt", \ |
| 130 | [IP_LOOKUP_NEXT_LOCAL] = "ip6-local", \ |
| 131 | [IP_LOOKUP_NEXT_ARP] = "ip6-discover-neighbor", \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 132 | [IP_LOOKUP_NEXT_GLEAN] = "ip6-glean", \ |
Damjan Marion | b270789 | 2016-04-13 11:21:07 +0200 | [diff] [blame] | 133 | [IP_LOOKUP_NEXT_REWRITE] = "ip6-rewrite", \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 134 | [IP_LOOKUP_NEXT_MCAST] = "ip6-rewrite-mcast", \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 135 | [IP_LOOKUP_NEXT_MIDCHAIN] = "ip6-midchain", \ |
| 136 | [IP_LOOKUP_NEXT_LOAD_BALANCE] = "ip6-load-balance", \ |
Ole Troan | 944f548 | 2016-05-24 11:56:58 +0200 | [diff] [blame] | 137 | [IP_LOOKUP_NEXT_ICMP_ERROR] = "ip6-icmp-error", \ |
Ole Troan | f0f8522 | 2016-06-14 21:12:32 +0200 | [diff] [blame] | 138 | [IP6_LOOKUP_NEXT_HOP_BY_HOP] = "ip6-hop-by-hop", \ |
| 139 | [IP6_LOOKUP_NEXT_ADD_HOP_BY_HOP] = "ip6-add-hop-by-hop", \ |
| 140 | [IP6_LOOKUP_NEXT_POP_HOP_BY_HOP] = "ip6-pop-hop-by-hop", \ |
Damjan Marion | b270789 | 2016-04-13 11:21:07 +0200 | [diff] [blame] | 141 | } |
| 142 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 143 | /** Flow hash configuration */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 144 | #define IP_FLOW_HASH_SRC_ADDR (1<<0) |
| 145 | #define IP_FLOW_HASH_DST_ADDR (1<<1) |
| 146 | #define IP_FLOW_HASH_PROTO (1<<2) |
| 147 | #define IP_FLOW_HASH_SRC_PORT (1<<3) |
| 148 | #define IP_FLOW_HASH_DST_PORT (1<<4) |
| 149 | #define IP_FLOW_HASH_REVERSE_SRC_DST (1<<5) |
| 150 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 151 | /** Default: 5-tuple without the "reverse" bit */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 152 | #define IP_FLOW_HASH_DEFAULT (0x1F) |
| 153 | |
| 154 | #define foreach_flow_hash_bit \ |
| 155 | _(src, IP_FLOW_HASH_SRC_ADDR) \ |
| 156 | _(dst, IP_FLOW_HASH_DST_ADDR) \ |
| 157 | _(sport, IP_FLOW_HASH_SRC_PORT) \ |
| 158 | _(dport, IP_FLOW_HASH_DST_PORT) \ |
| 159 | _(proto, IP_FLOW_HASH_PROTO) \ |
| 160 | _(reverse, IP_FLOW_HASH_REVERSE_SRC_DST) |
| 161 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 162 | /** |
| 163 | * A flow hash configuration is a mask of the flow hash options |
| 164 | */ |
| 165 | typedef u32 flow_hash_config_t; |
| 166 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 167 | /** |
| 168 | * Forward delcartion |
| 169 | */ |
| 170 | struct ip_adjacency_t_; |
| 171 | |
| 172 | /** |
| 173 | * @brief A function type for post-rewrite fixups on midchain adjacency |
| 174 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 175 | typedef void (*adj_midchain_fixup_t) (vlib_main_t * vm, |
| 176 | struct ip_adjacency_t_ * adj, |
| 177 | vlib_buffer_t * b0); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 178 | |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 179 | /** |
| 180 | * @brief Flags on an IP adjacency |
| 181 | */ |
| 182 | typedef enum ip_adjacency_flags_t_ |
| 183 | { |
| 184 | /** |
| 185 | * Currently a sync walk is active. Used to prevent re-entrant walking |
| 186 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 187 | IP_ADJ_SYNC_WALK_ACTIVE = (1 << 0), |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 188 | } ip_adjacency_flags_t; |
| 189 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 190 | /** @brief IP unicast adjacency. |
| 191 | @note cache aligned. |
| 192 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 193 | typedef struct ip_adjacency_t_ |
| 194 | { |
| 195 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 196 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 197 | /** Number of adjecencies in block. Greater than 1 means multipath; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | otherwise equal to 1. */ |
| 199 | u16 n_adj; |
| 200 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 201 | /** Next hop after ip4-lookup. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 202 | union |
| 203 | { |
| 204 | ip_lookup_next_t lookup_next_index:16; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 205 | u16 lookup_next_index_as_int; |
| 206 | }; |
| 207 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 208 | /** Interface address index for this local/arp adjacency. */ |
| 209 | u32 if_address_index; |
| 210 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 211 | /* |
| 212 | * link/ether-type |
| 213 | */ |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 214 | vnet_link_t ia_link; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 215 | u8 ia_nh_proto; |
| 216 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 217 | union |
| 218 | { |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 219 | /** |
| 220 | * IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE |
| 221 | * |
| 222 | * neighbour adjacency sub-type; |
| 223 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 224 | struct |
| 225 | { |
| 226 | ip46_address_t next_hop; |
| 227 | } nbr; |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 228 | /** |
| 229 | * IP_LOOKUP_NEXT_MIDCHAIN |
| 230 | * |
| 231 | * A nbr adj that is also recursive. Think tunnels. |
| 232 | * A nbr adj can transition to be of type MDICHAIN |
| 233 | * so be sure to leave the two structs with the next_hop |
| 234 | * fields aligned. |
| 235 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 236 | struct |
| 237 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 238 | /** |
| 239 | * The recursive next-hop |
| 240 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 241 | ip46_address_t next_hop; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 242 | /** |
| 243 | * The node index of the tunnel's post rewrite/TX function. |
| 244 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 245 | u32 tx_function_node; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 246 | /** |
| 247 | * The next DPO to use |
| 248 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 249 | dpo_id_t next_dpo; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 250 | /** |
| 251 | * A function to perform the post-rewrite fixup |
| 252 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 253 | adj_midchain_fixup_t fixup_func; |
| 254 | } midchain; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 255 | /** |
| 256 | * IP_LOOKUP_NEXT_GLEAN |
| 257 | * |
| 258 | * Glean the address to ARP for from the packet's destination |
| 259 | */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 260 | struct |
| 261 | { |
| 262 | ip46_address_t receive_addr; |
| 263 | } glean; |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 264 | } sub_type; |
Damjan Marion | f1bd8be | 2016-03-29 13:06:36 +0200 | [diff] [blame] | 265 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 266 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); |
Dave Barach | dbf19ca | 2016-03-15 10:21:54 +0100 | [diff] [blame] | 267 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 268 | /* Rewrite in second/third cache lines */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 269 | vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 270 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 271 | /* |
| 272 | * member not accessed in the data plane are relgated to the |
| 273 | * remaining cachelines |
| 274 | */ |
| 275 | fib_node_t ia_node; |
Neale Ranns | 19c68d2 | 2016-12-07 15:38:14 +0000 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * Flags on the adjacency |
| 279 | */ |
| 280 | ip_adjacency_flags_t ia_flags; |
| 281 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 282 | } ip_adjacency_t; |
| 283 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 284 | STATIC_ASSERT ((STRUCT_OFFSET_OF (ip_adjacency_t, cacheline0) == 0), |
| 285 | "IP adjacency cachline 0 is not offset"); |
| 286 | STATIC_ASSERT ((STRUCT_OFFSET_OF (ip_adjacency_t, cacheline1) == |
| 287 | CLIB_CACHE_LINE_BYTES), |
| 288 | "IP adjacency cachline 1 is more than one cachline size offset"); |
Dave Barach | dbf19ca | 2016-03-15 10:21:54 +0100 | [diff] [blame] | 289 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 290 | /* An all zeros address */ |
| 291 | extern const ip46_address_t zero_addr; |
Dave Barach | dbf19ca | 2016-03-15 10:21:54 +0100 | [diff] [blame] | 292 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 293 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 294 | typedef struct |
| 295 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 296 | /* Key for mhash; in fact, just a byte offset into mhash key vector. */ |
| 297 | u32 address_key; |
| 298 | |
| 299 | /* Interface which has this address. */ |
| 300 | u32 sw_if_index; |
| 301 | |
| 302 | /* Adjacency for neighbor probe (ARP) for this interface address. */ |
| 303 | u32 neighbor_probe_adj_index; |
| 304 | |
| 305 | /* Address (prefix) length for this interface. */ |
| 306 | u16 address_length; |
| 307 | |
| 308 | /* Will be used for something eventually. Primary vs. secondary? */ |
| 309 | u16 flags; |
| 310 | |
| 311 | /* Next and previous pointers for doubly linked list of |
| 312 | addresses per software interface. */ |
| 313 | u32 next_this_sw_interface; |
| 314 | u32 prev_this_sw_interface; |
| 315 | } ip_interface_address_t; |
| 316 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 317 | typedef enum |
| 318 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 319 | IP_LOCAL_NEXT_DROP, |
| 320 | IP_LOCAL_NEXT_PUNT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 321 | IP_LOCAL_NEXT_UDP_LOOKUP, |
| 322 | IP_LOCAL_NEXT_ICMP, |
| 323 | IP_LOCAL_N_NEXT, |
| 324 | } ip_local_next_t; |
| 325 | |
| 326 | struct ip_lookup_main_t; |
| 327 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 328 | typedef struct ip_lookup_main_t |
| 329 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 330 | /* Adjacency heap. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 331 | ip_adjacency_t *adjacency_heap; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 332 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 333 | /** load-balance packet/byte counters indexed by LB index. */ |
| 334 | vlib_combined_counter_main_t load_balance_counters; |
Dave Barach | dbf19ca | 2016-03-15 10:21:54 +0100 | [diff] [blame] | 335 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 336 | /** Pool of addresses that are assigned to interfaces. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 337 | ip_interface_address_t *if_address_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 338 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 339 | /** Hash table mapping address to index in interface address pool. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 340 | mhash_t address_to_if_address_index; |
| 341 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 342 | /** Head of doubly linked list of interface addresses for each software interface. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 343 | ~0 means this interface has no address. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 344 | u32 *if_address_pool_index_by_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 345 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 346 | /** First table index to use for this interface, ~0 => none */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 347 | u32 *classify_table_index_by_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 348 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 349 | /** Feature arc indices */ |
| 350 | u8 mcast_feature_arc_index; |
| 351 | u8 ucast_feature_arc_index; |
| 352 | u8 output_feature_arc_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 353 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 354 | /** Number of bytes in a fib result. Must be at least |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 355 | sizeof (uword). First word is always adjacency index. */ |
| 356 | u32 fib_result_n_bytes, fib_result_n_words; |
| 357 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 358 | format_function_t *format_fib_result; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 360 | /** 1 for ip6; 0 for ip4. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | u32 is_ip6; |
| 362 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 363 | /** Either format_ip4_address_and_length or format_ip6_address_and_length. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 364 | format_function_t *format_address_and_length; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 365 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 366 | /** Special adjacency format functions */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 367 | format_function_t **special_adjacency_format_functions; |
Dave Barach | 6f9bca2 | 2016-04-30 10:25:32 -0400 | [diff] [blame] | 368 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 369 | /** Table mapping ip protocol to ip[46]-local node next index. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 370 | u8 local_next_by_ip_protocol[256]; |
| 371 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 372 | /** IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 373 | u8 builtin_protocol_by_ip_protocol[256]; |
| 374 | } ip_lookup_main_t; |
| 375 | |
| 376 | always_inline ip_adjacency_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 377 | ip_get_adjacency (ip_lookup_main_t * lm, u32 adj_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 378 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 379 | ip_adjacency_t *adj; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | |
Dave Barach | b2ef4dd | 2016-03-23 08:56:01 -0400 | [diff] [blame] | 381 | adj = vec_elt_at_index (lm->adjacency_heap, adj_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 383 | return adj; |
| 384 | } |
| 385 | |
| 386 | #define ip_prefetch_adjacency(lm,adj_index,type) \ |
| 387 | do { \ |
| 388 | ip_adjacency_t * _adj = (lm)->adjacency_heap + (adj_index); \ |
| 389 | CLIB_PREFETCH (_adj, sizeof (_adj[0]), type); \ |
| 390 | } while (0) |
| 391 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 392 | clib_error_t *ip_interface_address_add_del (ip_lookup_main_t * lm, |
| 393 | u32 sw_if_index, |
| 394 | void *address, |
| 395 | u32 address_length, |
| 396 | u32 is_del, u32 * result_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 397 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 398 | u8 *format_ip_flow_hash_config (u8 * s, va_list * args); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 399 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | always_inline ip_interface_address_t * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 401 | ip_get_interface_address (ip_lookup_main_t * lm, void *addr_fib) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 402 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 403 | uword *p = mhash_get (&lm->address_to_if_address_index, addr_fib); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | return p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0; |
| 405 | } |
| 406 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 407 | u32 fib_table_id_find_fib_index (fib_protocol_t proto, u32 table_id); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 408 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 409 | always_inline void * |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 410 | ip_interface_address_get_address (ip_lookup_main_t * lm, |
| 411 | ip_interface_address_t * a) |
| 412 | { |
| 413 | return mhash_key_to_mem (&lm->address_to_if_address_index, a->address_key); |
| 414 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 415 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 416 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 417 | #define foreach_ip_interface_address(lm,a,sw_if_index,loop,body) \ |
| 418 | do { \ |
| 419 | vnet_main_t *_vnm = vnet_get_main(); \ |
| 420 | u32 _sw_if_index = sw_if_index; \ |
| 421 | vnet_sw_interface_t *_swif; \ |
| 422 | _swif = vnet_get_sw_interface (_vnm, _sw_if_index); \ |
| 423 | \ |
| 424 | /* \ |
| 425 | * Loop => honor unnumbered interface addressing. \ |
| 426 | */ \ |
| 427 | if (loop && _swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) \ |
| 428 | _sw_if_index = _swif->unnumbered_sw_if_index; \ |
| 429 | u32 _ia = \ |
| 430 | (vec_len((lm)->if_address_pool_index_by_sw_if_index) \ |
| 431 | > (_sw_if_index)) \ |
| 432 | ? vec_elt ((lm)->if_address_pool_index_by_sw_if_index, \ |
| 433 | (_sw_if_index)) : (u32)~0; \ |
| 434 | ip_interface_address_t * _a; \ |
| 435 | while (_ia != ~0) \ |
| 436 | { \ |
| 437 | _a = pool_elt_at_index ((lm)->if_address_pool, _ia); \ |
| 438 | _ia = _a->next_this_sw_interface; \ |
| 439 | (a) = _a; \ |
| 440 | body; \ |
| 441 | } \ |
| 442 | } while (0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 443 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 444 | |
| 445 | void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index); |
| 446 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 447 | #endif /* included_ip_lookup_h */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 448 | |
| 449 | /* |
| 450 | * fd.io coding-style-patch-verification: ON |
| 451 | * |
| 452 | * Local Variables: |
| 453 | * eval: (c-set-style "gnu") |
| 454 | * End: |
| 455 | */ |