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 | |
Neale Ranns | e403113 | 2020-10-26 13:00:06 +0000 | [diff] [blame] | 51 | //#include <vnet/vnet.h> |
| 52 | #include <vlib/vlib.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | #include <vlib/buffer.h> |
Damjan Marion | 102ec52 | 2016-03-29 13:18:17 +0200 | [diff] [blame] | 54 | #include <vnet/ip/ip4_packet.h> |
Pierre Pfister | 1dabaaf | 2016-04-25 14:15:15 +0100 | [diff] [blame] | 55 | #include <vnet/ip/ip6_packet.h> |
Neale Ranns | e403113 | 2020-10-26 13:00:06 +0000 | [diff] [blame] | 56 | #include <vnet/ip/ip_types.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 57 | #include <vnet/fib/fib_node.h> |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 58 | #include <vnet/adj/adj.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 59 | #include <vnet/dpo/dpo.h> |
Neale Ranns | e403113 | 2020-10-26 13:00:06 +0000 | [diff] [blame] | 60 | ///#include <vnet/feature/feature.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 61 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 62 | /* An all zeros address */ |
| 63 | extern const ip46_address_t zero_addr; |
Dave Barach | dbf19ca | 2016-03-15 10:21:54 +0100 | [diff] [blame] | 64 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 65 | typedef enum ip_interface_address_flags_t_ |
| 66 | { |
| 67 | IP_INTERFACE_ADDRESS_FLAG_STALE = (1 << 0), |
| 68 | } __clib_packed ip_interface_address_flags_t; |
| 69 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 70 | typedef struct |
| 71 | { |
| 72 | fib_prefix_t prefix; |
| 73 | |
| 74 | u32 sw_if_index; |
| 75 | } ip_interface_prefix_key_t; |
| 76 | |
| 77 | typedef struct |
| 78 | { |
| 79 | /* key - prefix and sw_if_index */ |
| 80 | ip_interface_prefix_key_t key; |
| 81 | |
| 82 | /* number of addresses in this prefix on the interface */ |
| 83 | u16 ref_count; |
| 84 | |
| 85 | /* index of the interface address used as a default source address */ |
| 86 | u32 src_ia_index; |
| 87 | } ip_interface_prefix_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 89 | typedef struct |
| 90 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | /* Key for mhash; in fact, just a byte offset into mhash key vector. */ |
| 92 | u32 address_key; |
| 93 | |
| 94 | /* Interface which has this address. */ |
| 95 | u32 sw_if_index; |
| 96 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | /* Address (prefix) length for this interface. */ |
| 98 | u16 address_length; |
| 99 | |
Neale Ranns | 59f7113 | 2020-04-08 12:19:38 +0000 | [diff] [blame] | 100 | /* flags relating to this prefix */ |
| 101 | ip_interface_address_flags_t flags; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 102 | |
| 103 | /* Next and previous pointers for doubly linked list of |
| 104 | addresses per software interface. */ |
| 105 | u32 next_this_sw_interface; |
| 106 | u32 prev_this_sw_interface; |
| 107 | } ip_interface_address_t; |
| 108 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 109 | typedef enum |
| 110 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | IP_LOCAL_NEXT_DROP, |
| 112 | IP_LOCAL_NEXT_PUNT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | IP_LOCAL_NEXT_UDP_LOOKUP, |
| 114 | IP_LOCAL_NEXT_ICMP, |
Juraj Sloboda | 3048b63 | 2018-10-02 11:13:53 +0200 | [diff] [blame] | 115 | IP_LOCAL_NEXT_REASSEMBLY, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | IP_LOCAL_N_NEXT, |
| 117 | } ip_local_next_t; |
| 118 | |
| 119 | struct ip_lookup_main_t; |
| 120 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 121 | typedef struct ip_lookup_main_t |
| 122 | { |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 123 | /** Pool of addresses that are assigned to interfaces. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 124 | ip_interface_address_t *if_address_pool; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 125 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 126 | /** Hash table mapping address to index in interface address pool. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 127 | mhash_t address_to_if_address_index; |
| 128 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 129 | /** Head of doubly linked list of interface addresses for each software interface. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | ~0 means this interface has no address. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 131 | u32 *if_address_pool_index_by_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 132 | |
Matthew Smith | 6c92f5b | 2019-08-07 11:46:30 -0500 | [diff] [blame] | 133 | /** Pool of prefixes containing addresses assigned to interfaces */ |
| 134 | ip_interface_prefix_t *if_prefix_pool; |
| 135 | |
| 136 | /** Hash table mapping prefix to index in interface prefix pool */ |
| 137 | mhash_t prefix_to_if_prefix_index; |
| 138 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 139 | /** First table index to use for this interface, ~0 => none */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 140 | u32 *classify_table_index_by_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 141 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 142 | /** Feature arc indices */ |
| 143 | u8 mcast_feature_arc_index; |
| 144 | u8 ucast_feature_arc_index; |
| 145 | u8 output_feature_arc_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 146 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 147 | /** Number of bytes in a fib result. Must be at least |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 148 | sizeof (uword). First word is always adjacency index. */ |
| 149 | u32 fib_result_n_bytes, fib_result_n_words; |
| 150 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 151 | /** 1 for ip6; 0 for ip4. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 152 | u32 is_ip6; |
| 153 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 154 | /** Either format_ip4_address_and_length or format_ip6_address_and_length. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 155 | format_function_t *format_address_and_length; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 157 | /** Table mapping ip protocol to ip[46]-local node next index. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | u8 local_next_by_ip_protocol[256]; |
| 159 | |
Keith Burns (alagalah) | 79b5f63 | 2016-08-02 05:40:20 -0700 | [diff] [blame] | 160 | /** IP_BUILTIN_PROTOCOL_{TCP,UDP,ICMP,OTHER} by protocol in IP header. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | u8 builtin_protocol_by_ip_protocol[256]; |
| 162 | } ip_lookup_main_t; |
| 163 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 164 | u8 *format_ip_flow_hash_config (u8 * s, va_list * args); |
Nathan Skrzypczak | e2d0c6e | 2022-03-23 18:08:53 +0100 | [diff] [blame] | 165 | uword unformat_ip_flow_hash_config (unformat_input_t *input, va_list *args); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | |
Florin Coras | 3a0325f | 2018-06-01 12:22:23 -0700 | [diff] [blame] | 167 | always_inline void |
| 168 | ip_lookup_set_buffer_fib_index (u32 * fib_index_by_sw_if_index, |
| 169 | vlib_buffer_t * b) |
| 170 | { |
| 171 | vnet_buffer (b)->ip.fib_index = |
| 172 | vec_elt (fib_index_by_sw_if_index, vnet_buffer (b)->sw_if_index[VLIB_RX]); |
| 173 | vnet_buffer (b)->ip.fib_index = |
Neale Ranns | 9b2f51a | 2018-09-11 05:55:50 -0700 | [diff] [blame] | 174 | ((vnet_buffer (b)->sw_if_index[VLIB_TX] == (u32) ~ 0) ? |
| 175 | vnet_buffer (b)->ip.fib_index : |
| 176 | vnet_buffer (b)->sw_if_index[VLIB_TX]); |
Florin Coras | 3a0325f | 2018-06-01 12:22:23 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index); |
Gavril Florian | e7f34c9 | 2023-06-15 18:39:57 +0000 | [diff] [blame] | 180 | bool fib_prefix_validate (const fib_prefix_t *prefix); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 182 | #endif /* included_ip_lookup_h */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 183 | /* |
| 184 | * fd.io coding-style-patch-verification: ON |
| 185 | * |
| 186 | * Local Variables: |
| 187 | * eval: (c-set-style "gnu") |
| 188 | * End: |
| 189 | */ |