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> |
| 20 | #include <vnet/ip/ip.h> |
| 21 | #include <vnet/mpls/mpls.h> |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 22 | #include <vnet/adj/adj_l2.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 23 | |
| 24 | |
| 25 | /** |
| 26 | * big switch to turn on Adjacency debugging |
| 27 | */ |
| 28 | #undef ADJ_DEBUG |
| 29 | |
| 30 | /* |
| 31 | * Debug macro |
| 32 | */ |
| 33 | #ifdef ADJ_DEBUG |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 34 | #define ADJ_DBG(_adj, _fmt, _args...) \ |
| 35 | { \ |
| 36 | clib_warning("adj:[%d:%p]:" _fmt, \ |
| 37 | _adj - adj_pool, _adj, \ |
| 38 | ##_args); \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 39 | } |
| 40 | #else |
| 41 | #define ADJ_DBG(_e, _fmt, _args...) |
| 42 | #endif |
| 43 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 44 | static inline u32 |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 45 | adj_get_rewrite_node (vnet_link_t linkt) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 46 | { |
| 47 | switch (linkt) { |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 48 | case VNET_LINK_IP4: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 49 | return (ip4_rewrite_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 50 | case VNET_LINK_IP6: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 51 | return (ip6_rewrite_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 52 | case VNET_LINK_MPLS: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 53 | return (mpls_output_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 54 | case VNET_LINK_ETHERNET: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 55 | return (adj_l2_rewrite_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 56 | case VNET_LINK_ARP: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 57 | break; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 58 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 59 | ASSERT(0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 60 | return (0); |
| 61 | } |
| 62 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 63 | static inline vnet_link_t |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 64 | adj_fib_proto_2_nd (fib_protocol_t fp) |
| 65 | { |
| 66 | switch (fp) |
| 67 | { |
| 68 | case FIB_PROTOCOL_IP4: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 69 | return (VNET_LINK_ARP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 70 | case FIB_PROTOCOL_IP6: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 71 | return (VNET_LINK_IP6); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 72 | case FIB_PROTOCOL_MPLS: |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 73 | return (VNET_LINK_MPLS); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 74 | } |
| 75 | return (0); |
| 76 | } |
| 77 | |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 78 | /** |
| 79 | * @brief |
| 80 | * Get a pointer to an adjacency object from its index |
| 81 | */ |
| 82 | static inline adj_index_t |
| 83 | adj_get_index (ip_adjacency_t *adj) |
| 84 | { |
| 85 | return (adj - adj_pool); |
| 86 | } |
| 87 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 88 | extern void adj_nbr_update_rewrite_internal (ip_adjacency_t *adj, |
Neale Ranns | 450cd30 | 2016-11-09 17:49:42 +0000 | [diff] [blame] | 89 | ip_lookup_next_t adj_next_index, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 90 | u32 complete_next_index, |
| 91 | u32 next_index, |
| 92 | u8 *rewrite); |
| 93 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 94 | extern ip_adjacency_t * adj_alloc(fib_protocol_t proto); |
| 95 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 96 | extern void adj_nbr_remove(adj_index_t ai, |
| 97 | fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 98 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 99 | const ip46_address_t *nh_addr, |
| 100 | u32 sw_if_index); |
| 101 | extern void adj_glean_remove(fib_protocol_t proto, |
| 102 | u32 sw_if_index); |
| 103 | |
| 104 | #endif |