Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | #ifndef __ADJ_INTERNAL_H__ |
| 17 | #define __ADJ_INTERNAL_H__ |
| 18 | |
| 19 | #include <vnet/adj/adj.h> |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 20 | #include <vnet/adj/adj_mcast.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 21 | #include <vnet/ip/ip.h> |
| 22 | #include <vnet/mpls/mpls.h> |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 23 | #include <vnet/adj/adj_l2.h> |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 24 | #include <vnet/adj/adj_nsh.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * big switch to turn on Adjacency debugging |
| 28 | */ |
| 29 | #undef ADJ_DEBUG |
| 30 | |
| 31 | /* |
| 32 | * Debug macro |
| 33 | */ |
Neale Ranns | 2164f7b | 2022-02-18 11:10:11 +0000 | [diff] [blame] | 34 | extern vlib_log_class_t adj_logger; |
| 35 | #define ADJ_DBG(_adj, _fmt, _args...) \ |
| 36 | { \ |
| 37 | vlib_log_debug(adj_logger, "adj:[%d:%p]:" _fmt, \ |
| 38 | _adj - adj_pool, _adj, \ |
| 39 | ##_args); \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 40 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 41 | |
Neale Ranns | f339f49 | 2021-03-31 07:36:33 +0000 | [diff] [blame] | 42 | /* |
| 43 | * Vlib nodes |
| 44 | */ |
| 45 | extern vlib_node_registration_t adj_nsh_midchain_node; |
| 46 | extern vlib_node_registration_t adj_nsh_rewrite_node; |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 47 | extern vlib_node_registration_t adj_midchain_tx; |
Neale Ranns | f339f49 | 2021-03-31 07:36:33 +0000 | [diff] [blame] | 48 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 49 | static inline u32 |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 50 | adj_get_rewrite_node (vnet_link_t linkt) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 51 | { |
| 52 | switch (linkt) { |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 53 | case VNET_LINK_IP4: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 54 | return (ip4_rewrite_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 55 | case VNET_LINK_IP6: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 56 | return (ip6_rewrite_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 57 | case VNET_LINK_MPLS: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 58 | return (mpls_output_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 59 | case VNET_LINK_ETHERNET: |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 60 | return (adj_l2_rewrite_node.index); |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 61 | case VNET_LINK_NSH: |
| 62 | return (adj_nsh_rewrite_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 63 | case VNET_LINK_ARP: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 64 | break; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 65 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 66 | ASSERT(0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 67 | return (0); |
| 68 | } |
| 69 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 70 | static inline vnet_link_t |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 71 | adj_fib_proto_2_nd (fib_protocol_t fp) |
| 72 | { |
| 73 | switch (fp) |
| 74 | { |
| 75 | case FIB_PROTOCOL_IP4: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 76 | return (VNET_LINK_ARP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 77 | case FIB_PROTOCOL_IP6: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 78 | return (VNET_LINK_IP6); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 79 | case FIB_PROTOCOL_MPLS: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 80 | return (VNET_LINK_MPLS); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 81 | } |
| 82 | return (0); |
| 83 | } |
| 84 | |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 85 | static inline ip46_type_t |
| 86 | adj_proto_to_46 (fib_protocol_t proto) |
| 87 | { |
| 88 | switch (proto) |
| 89 | { |
| 90 | case FIB_PROTOCOL_IP4: |
| 91 | return (IP46_TYPE_IP4); |
| 92 | case FIB_PROTOCOL_IP6: |
| 93 | return (IP46_TYPE_IP6); |
| 94 | default: |
| 95 | return (IP46_TYPE_IP4); |
| 96 | } |
| 97 | return (IP46_TYPE_IP4); |
| 98 | } |
| 99 | |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 100 | /** |
| 101 | * @brief |
| 102 | * Get a pointer to an adjacency object from its index |
| 103 | */ |
| 104 | static inline adj_index_t |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 105 | adj_get_index (const ip_adjacency_t *adj) |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 106 | { |
| 107 | return (adj - adj_pool); |
| 108 | } |
| 109 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 110 | extern void adj_nbr_update_rewrite_internal(ip_adjacency_t *adj, |
| 111 | ip_lookup_next_t adj_next_index, |
| 112 | u32 complete_next_index, |
| 113 | u32 next_index, |
| 114 | u8 *rewrite); |
| 115 | extern void adj_midchain_setup(adj_index_t adj_index, |
| 116 | adj_midchain_fixup_t fixup, |
Neale Ranns | db14f5a | 2018-01-29 10:43:33 -0800 | [diff] [blame] | 117 | const void *data, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 118 | adj_flags_t flags); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 119 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 120 | extern ip_adjacency_t * adj_alloc(fib_protocol_t proto); |
| 121 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 122 | extern void adj_nbr_remove(adj_index_t ai, |
| 123 | fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 124 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 125 | const ip46_address_t *nh_addr, |
| 126 | u32 sw_if_index); |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 127 | extern u32 adj_nbr_get_n_adjs(vnet_link_t link_type, u32 sw_if_index); |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 128 | extern void adj_glean_remove(ip_adjacency_t *adj); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 129 | extern void adj_mcast_remove(fib_protocol_t proto, |
| 130 | u32 sw_if_index); |
Neale Ranns | 3ebebc3 | 2020-02-18 13:56:24 +0000 | [diff] [blame] | 131 | extern void adj_midchain_teardown(ip_adjacency_t *adj); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 132 | |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 133 | extern u32 adj_dpo_get_urpf(const dpo_id_t *dpo); |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 134 | extern u16 adj_dpo_get_mtu(const dpo_id_t *dpo); |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * Adj BFD |
| 138 | */ |
| 139 | extern int adj_bfd_is_up (adj_index_t ai); |
| 140 | |
| 141 | /* |
| 142 | * Adj delegates |
| 143 | */ |
| 144 | extern void adj_delegate_adj_deleted(ip_adjacency_t *adj); |
Neale Ranns | 77cfc01 | 2019-12-15 22:26:37 +0000 | [diff] [blame] | 145 | extern void adj_delegate_adj_created(ip_adjacency_t *adj); |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 146 | extern void adj_delegate_adj_modified(ip_adjacency_t *adj); |
Neale Ranns | d79a43c | 2018-02-19 02:36:19 -0800 | [diff] [blame] | 147 | extern u8* adj_delegate_format(u8* s, ip_adjacency_t *adj); |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 148 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 149 | #endif |