vppinfra: fallback to builtin memcpy if vector code is not enabled
[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 /*
46  * Vlib nodes
47  */
48 extern vlib_node_registration_t adj_nsh_midchain_node;
49 extern vlib_node_registration_t adj_nsh_rewrite_node;
50 extern vlib_node_registration_t adj_midchain_tx;
51
52 static inline u32
53 adj_get_rewrite_node (vnet_link_t linkt)
54 {
55     switch (linkt) {
56     case VNET_LINK_IP4:
57         return (ip4_rewrite_node.index);
58     case VNET_LINK_IP6:
59         return (ip6_rewrite_node.index);
60     case VNET_LINK_MPLS:
61         return (mpls_output_node.index);
62     case VNET_LINK_ETHERNET:
63         return (adj_l2_rewrite_node.index);
64     case VNET_LINK_NSH:
65         return (adj_nsh_rewrite_node.index);
66     case VNET_LINK_ARP:
67         break;
68     }
69     ASSERT(0);
70     return (0);
71 }
72
73 static inline vnet_link_t
74 adj_fib_proto_2_nd (fib_protocol_t fp)
75 {
76     switch (fp)
77     {
78     case FIB_PROTOCOL_IP4:
79         return (VNET_LINK_ARP);
80     case FIB_PROTOCOL_IP6:
81         return (VNET_LINK_IP6);
82     case FIB_PROTOCOL_MPLS:
83         return (VNET_LINK_MPLS);
84     }
85     return (0);
86 }
87
88 static inline ip46_type_t
89 adj_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
103 /**
104  * @brief
105  * Get a pointer to an adjacency object from its index
106  */
107 static inline adj_index_t
108 adj_get_index (const ip_adjacency_t *adj)
109 {
110     return (adj - adj_pool);
111 }
112
113 extern 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);
118 extern void adj_midchain_setup(adj_index_t adj_index,
119                                adj_midchain_fixup_t fixup,
120                                const void *data,
121                                adj_flags_t flags);
122
123 extern ip_adjacency_t * adj_alloc(fib_protocol_t proto);
124
125 extern void adj_nbr_remove(adj_index_t ai,
126                            fib_protocol_t nh_proto,
127                            vnet_link_t link_type,
128                            const ip46_address_t *nh_addr,
129                            u32 sw_if_index);
130 extern u32 adj_nbr_get_n_adjs(vnet_link_t link_type, u32 sw_if_index);
131 extern void adj_glean_remove(ip_adjacency_t *adj);
132 extern void adj_mcast_remove(fib_protocol_t proto,
133                              u32 sw_if_index);
134 extern void adj_midchain_teardown(ip_adjacency_t *adj);
135
136 extern u32 adj_dpo_get_urpf(const dpo_id_t *dpo);
137 extern u16 adj_dpo_get_mtu(const dpo_id_t *dpo);
138
139 /*
140  * Adj BFD
141  */
142 extern int adj_bfd_is_up (adj_index_t ai);
143
144 /*
145  * Adj delegates
146  */ 
147 extern void adj_delegate_adj_deleted(ip_adjacency_t *adj);
148 extern void adj_delegate_adj_created(ip_adjacency_t *adj);
149 extern void adj_delegate_adj_modified(ip_adjacency_t *adj);
150 extern u8* adj_delegate_format(u8* s, ip_adjacency_t *adj);
151
152 #endif