e6d276e4d0246792f18c691fe2fcd772e8548d64
[vpp.git] / src / vnet / adj / adj_internal.h
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/adj/adj_mcast.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/mpls/mpls.h>
23 #include <vnet/adj/adj_l2.h>
24 #include <vnet/adj/adj_nsh.h>
25
26 /**
27  * big switch to turn on Adjacency debugging
28  */
29 #undef ADJ_DEBUG
30
31 /*
32  * Debug macro
33  */
34 #ifdef ADJ_DEBUG
35 #define ADJ_DBG(_adj, _fmt, _args...)           \
36 {                                               \
37     clib_warning("adj:[%d:%p]:" _fmt,           \
38                  _adj - adj_pool, _adj,         \
39                  ##_args);                      \
40 }
41 #else
42 #define ADJ_DBG(_e, _fmt, _args...)
43 #endif
44
45 static inline u32
46 adj_get_rewrite_node (vnet_link_t linkt)
47 {
48     switch (linkt) {
49     case VNET_LINK_IP4:
50         return (ip4_rewrite_node.index);
51     case VNET_LINK_IP6:
52         return (ip6_rewrite_node.index);
53     case VNET_LINK_MPLS:
54         return (mpls_output_node.index);
55     case VNET_LINK_ETHERNET:
56         return (adj_l2_rewrite_node.index);
57     case VNET_LINK_NSH:
58         return (adj_nsh_rewrite_node.index);
59     case VNET_LINK_ARP:
60         break;
61     }
62     ASSERT(0);
63     return (0);
64 }
65
66 static inline vnet_link_t
67 adj_fib_proto_2_nd (fib_protocol_t fp)
68 {
69     switch (fp)
70     {
71     case FIB_PROTOCOL_IP4:
72         return (VNET_LINK_ARP);
73     case FIB_PROTOCOL_IP6:
74         return (VNET_LINK_IP6);
75     case FIB_PROTOCOL_MPLS:
76         return (VNET_LINK_MPLS);
77     }
78     return (0);
79 }
80
81 /**
82  * @brief
83  * Get a pointer to an adjacency object from its index
84  */
85 static inline adj_index_t
86 adj_get_index (ip_adjacency_t *adj)
87 {
88     return (adj - adj_pool);
89 }
90
91 extern void adj_nbr_update_rewrite_internal(ip_adjacency_t *adj,
92                                             ip_lookup_next_t adj_next_index,
93                                             u32 complete_next_index,
94                                             u32 next_index,
95                                             u8 *rewrite);
96 extern void adj_midchain_setup(adj_index_t adj_index,
97                                adj_midchain_fixup_t fixup,
98                                const void *data,
99                                adj_flags_t flags);
100
101 extern ip_adjacency_t * adj_alloc(fib_protocol_t proto);
102
103 extern void adj_nbr_remove(adj_index_t ai,
104                            fib_protocol_t nh_proto,
105                            vnet_link_t link_type,
106                            const ip46_address_t *nh_addr,
107                            u32 sw_if_index);
108 extern void adj_glean_remove(fib_protocol_t proto,
109                              u32 sw_if_index);
110 extern void adj_mcast_remove(fib_protocol_t proto,
111                              u32 sw_if_index);
112
113 extern u32 adj_dpo_get_urpf(const dpo_id_t *dpo);
114
115 #endif