blob: 6842bc4147eee14bf8d6af0f24528ba573d1466e [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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 Ranns0f26c5a2017-03-01 15:12:11 -080020#include <vnet/adj/adj_mcast.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010021#include <vnet/ip/ip.h>
22#include <vnet/mpls/mpls.h>
Neale Ranns5e575b12016-10-03 09:40:25 +010023#include <vnet/adj/adj_l2.h>
Florin Corasce1b4c72017-01-26 14:25:34 -080024#include <vnet/adj/adj_nsh.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010025
26/**
27 * big switch to turn on Adjacency debugging
28 */
29#undef ADJ_DEBUG
30
31/*
32 * Debug macro
33 */
34#ifdef ADJ_DEBUG
Neale Ranns6c3ebcc2016-10-02 21:20:15 +010035#define ADJ_DBG(_adj, _fmt, _args...) \
36{ \
37 clib_warning("adj:[%d:%p]:" _fmt, \
38 _adj - adj_pool, _adj, \
39 ##_args); \
Neale Ranns0bfe5d82016-08-25 15:29:12 +010040}
41#else
42#define ADJ_DBG(_e, _fmt, _args...)
43#endif
44
Neale Rannsf339f492021-03-31 07:36:33 +000045/*
46 * Vlib nodes
47 */
48extern vlib_node_registration_t adj_nsh_midchain_node;
49extern vlib_node_registration_t adj_nsh_rewrite_node;
Neale Ranns6fdcc3d2021-10-08 07:30:47 +000050extern vlib_node_registration_t adj_midchain_tx;
Neale Rannsf339f492021-03-31 07:36:33 +000051
Neale Rannsb80c5362016-10-08 13:03:40 +010052static inline u32
Neale Ranns924d03a2016-10-19 08:25:46 +010053adj_get_rewrite_node (vnet_link_t linkt)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010054{
55 switch (linkt) {
Neale Ranns924d03a2016-10-19 08:25:46 +010056 case VNET_LINK_IP4:
Neale Rannsb80c5362016-10-08 13:03:40 +010057 return (ip4_rewrite_node.index);
Neale Ranns924d03a2016-10-19 08:25:46 +010058 case VNET_LINK_IP6:
Neale Rannsb80c5362016-10-08 13:03:40 +010059 return (ip6_rewrite_node.index);
Neale Ranns924d03a2016-10-19 08:25:46 +010060 case VNET_LINK_MPLS:
Neale Rannsb80c5362016-10-08 13:03:40 +010061 return (mpls_output_node.index);
Neale Ranns924d03a2016-10-19 08:25:46 +010062 case VNET_LINK_ETHERNET:
Neale Ranns4ec36c52020-03-31 09:21:29 -040063 return (adj_l2_rewrite_node.index);
Florin Corasce1b4c72017-01-26 14:25:34 -080064 case VNET_LINK_NSH:
65 return (adj_nsh_rewrite_node.index);
Neale Ranns924d03a2016-10-19 08:25:46 +010066 case VNET_LINK_ARP:
Neale Ranns5e575b12016-10-03 09:40:25 +010067 break;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010068 }
Neale Ranns924d03a2016-10-19 08:25:46 +010069 ASSERT(0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010070 return (0);
71}
72
Neale Rannsb80c5362016-10-08 13:03:40 +010073static inline vnet_link_t
Neale Ranns0bfe5d82016-08-25 15:29:12 +010074adj_fib_proto_2_nd (fib_protocol_t fp)
75{
76 switch (fp)
77 {
78 case FIB_PROTOCOL_IP4:
Neale Rannsb80c5362016-10-08 13:03:40 +010079 return (VNET_LINK_ARP);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010080 case FIB_PROTOCOL_IP6:
Neale Rannsb80c5362016-10-08 13:03:40 +010081 return (VNET_LINK_IP6);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010082 case FIB_PROTOCOL_MPLS:
Neale Rannsb80c5362016-10-08 13:03:40 +010083 return (VNET_LINK_MPLS);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010084 }
85 return (0);
86}
87
Neale Rannsc819fc62018-02-16 02:44:05 -080088static inline ip46_type_t
89adj_proto_to_46 (fib_protocol_t proto)
90{
91 switch (proto)
92 {
93 case FIB_PROTOCOL_IP4:
94 return (IP46_TYPE_IP4);
95 case FIB_PROTOCOL_IP6:
96 return (IP46_TYPE_IP6);
97 default:
98 return (IP46_TYPE_IP4);
99 }
100 return (IP46_TYPE_IP4);
101}
102
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100103/**
104 * @brief
105 * Get a pointer to an adjacency object from its index
106 */
107static inline adj_index_t
Neale Rannscbe25aa2019-09-30 10:53:31 +0000108adj_get_index (const ip_adjacency_t *adj)
Neale Ranns6c3ebcc2016-10-02 21:20:15 +0100109{
110 return (adj - adj_pool);
111}
112
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800113extern void adj_nbr_update_rewrite_internal(ip_adjacency_t *adj,
114 ip_lookup_next_t adj_next_index,
115 u32 complete_next_index,
116 u32 next_index,
117 u8 *rewrite);
118extern void adj_midchain_setup(adj_index_t adj_index,
119 adj_midchain_fixup_t fixup,
Neale Rannsdb14f5a2018-01-29 10:43:33 -0800120 const void *data,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800121 adj_flags_t flags);
Neale Rannsb80c5362016-10-08 13:03:40 +0100122
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100123extern ip_adjacency_t * adj_alloc(fib_protocol_t proto);
124
Neale Ranns177bbdc2016-11-15 09:46:51 +0000125extern void adj_nbr_remove(adj_index_t ai,
126 fib_protocol_t nh_proto,
Neale Ranns924d03a2016-10-19 08:25:46 +0100127 vnet_link_t link_type,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100128 const ip46_address_t *nh_addr,
129 u32 sw_if_index);
Neale Ranns6fdcc3d2021-10-08 07:30:47 +0000130extern u32 adj_nbr_get_n_adjs(vnet_link_t link_type, u32 sw_if_index);
Neale Rannse2fe0972020-11-26 08:37:27 +0000131extern void adj_glean_remove(ip_adjacency_t *adj);
Neale Ranns32e1c012016-11-22 17:07:28 +0000132extern void adj_mcast_remove(fib_protocol_t proto,
133 u32 sw_if_index);
Neale Ranns3ebebc32020-02-18 13:56:24 +0000134extern void adj_midchain_teardown(ip_adjacency_t *adj);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100135
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700136extern u32 adj_dpo_get_urpf(const dpo_id_t *dpo);
Neale Ranns8f5fef22020-12-21 08:29:34 +0000137extern u16 adj_dpo_get_mtu(const dpo_id_t *dpo);
Neale Rannsd79a43c2018-02-19 02:36:19 -0800138
139/*
140 * Adj BFD
141 */
142extern int adj_bfd_is_up (adj_index_t ai);
143
144/*
145 * Adj delegates
146 */
147extern void adj_delegate_adj_deleted(ip_adjacency_t *adj);
Neale Ranns77cfc012019-12-15 22:26:37 +0000148extern void adj_delegate_adj_created(ip_adjacency_t *adj);
Neale Ranns4ec36c52020-03-31 09:21:29 -0400149extern void adj_delegate_adj_modified(ip_adjacency_t *adj);
Neale Rannsd79a43c2018-02-19 02:36:19 -0800150extern u8* adj_delegate_format(u8* s, ip_adjacency_t *adj);
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700151
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100152#endif