2 * Copyright (c) 2018 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __GBP_ENDPOINT_H__
17 #define __GBP_ENDPOINT_H__
19 #include <plugins/gbp/gbp_types.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/ethernet/mac_address.h>
23 #include <vppinfra/bihash_16_8.h>
24 #include <vppinfra/bihash_template.h>
25 #include <vppinfra/bihash_24_8.h>
26 #include <vppinfra/bihash_template.h>
29 * Flags for each endpoint
31 typedef enum gbp_endpoint_attr_t_
33 GBP_ENDPOINT_ATTR_FIRST = 0,
34 GBP_ENDPOINT_ATTR_BOUNCE = GBP_ENDPOINT_ATTR_FIRST,
35 GBP_ENDPOINT_ATTR_REMOTE = 1,
36 GBP_ENDPOINT_ATTR_LEARNT = 2,
37 GBP_ENDPOINT_ATTR_LAST,
38 } gbp_endpoint_attr_t;
40 typedef enum gbp_endpoint_flags_t_
42 GBP_ENDPOINT_FLAG_NONE = 0,
43 GBP_ENDPOINT_FLAG_BOUNCE = (1 << GBP_ENDPOINT_ATTR_BOUNCE),
44 GBP_ENDPOINT_FLAG_REMOTE = (1 << GBP_ENDPOINT_ATTR_REMOTE),
45 GBP_ENDPOINT_FLAG_LEARNT = (1 << GBP_ENDPOINT_ATTR_LEARNT),
46 } gbp_endpoint_flags_t;
48 #define GBP_ENDPOINT_ATTR_NAMES { \
49 [GBP_ENDPOINT_ATTR_BOUNCE] = "bounce", \
50 [GBP_ENDPOINT_ATTR_REMOTE] = "remote", \
51 [GBP_ENDPOINT_ATTR_LEARNT] = "learnt", \
54 extern u8 *format_gbp_endpoint_flags (u8 * s, va_list * args);
57 * A Group Based Policy Endpoint.
58 * This is typically a VM or container. If the endpoint is local (i.e. on
59 * the same compute node as VPP) then there is one interface per-endpoint.
60 * If the EP is remote,e.g. reachable over a [vxlan] tunnel, then there
61 * will be multiple EPs reachable over the tunnel and they can be distinguished
62 * via either their MAC or IP Address[es].
64 typedef struct gbp_endpoint_t_
67 * The interface on which the EP is connected
73 * A vector of ip addresses that below to the endpoint
75 const ip46_address_t *ge_ips;
78 * MAC address of the endpoint
83 * Index of the Endpoint's Group
95 gbp_endpoint_flags_t ge_flags;
98 * The L3 adj, if created
103 * The last time a packet from seen from this end point
108 * Tunnel info for remote endpoints
112 u32 ge_parent_sw_if_index;
113 ip46_address_t ge_src;
114 ip46_address_t ge_dst;
118 extern u8 *format_gbp_endpoint (u8 * s, va_list * args);
121 * GBP Endpoint Databases
123 typedef struct gbp_ep_by_ip_itf_db_t_
125 index_t *ged_by_sw_if_index;
126 clib_bihash_24_8_t ged_by_ip_rd;
127 clib_bihash_16_8_t ged_by_mac_bd;
130 extern int gbp_endpoint_update (u32 sw_if_index,
131 const ip46_address_t * ip,
132 const mac_address_t * mac,
134 gbp_endpoint_flags_t flags,
135 const ip46_address_t * tun_src,
136 const ip46_address_t * tun_dst, u32 * handle);
137 extern void gbp_endpoint_delete (index_t gbpei);
139 typedef walk_rc_t (*gbp_endpoint_cb_t) (index_t gbpei, void *ctx);
140 extern void gbp_endpoint_walk (gbp_endpoint_cb_t cb, void *ctx);
141 extern void gbp_endpoint_scan (vlib_main_t * vm);
142 extern f64 gbp_endpoint_scan_threshold (void);
143 extern int gbp_endpoint_is_remote (const gbp_endpoint_t * ge);
145 extern void gbp_endpoint_flush (u32 sw_if_index);
148 * DP functions and databases
150 extern gbp_ep_db_t gbp_ep_db;
151 extern gbp_endpoint_t *gbp_endpoint_pool;
154 * Get the endpoint from a port/interface
156 always_inline gbp_endpoint_t *
157 gbp_endpoint_get (index_t gbpei)
159 return (pool_elt_at_index (gbp_endpoint_pool, gbpei));
162 static_always_inline void
163 gbp_endpoint_mk_key_mac (const u8 * mac,
164 u32 bd_index, clib_bihash_kv_16_8_t * key)
166 key->key[0] = ethernet_mac_address_u64 (mac);
167 key->key[1] = bd_index;
170 static_always_inline gbp_endpoint_t *
171 gbp_endpoint_find_mac (const u8 * mac, u32 bd_index)
173 clib_bihash_kv_16_8_t key, value;
176 gbp_endpoint_mk_key_mac (mac, bd_index, &key);
178 rv = clib_bihash_search_16_8 (&gbp_ep_db.ged_by_mac_bd, &key, &value);
183 return (gbp_endpoint_get (value.value));
186 static_always_inline void
187 gbp_endpoint_mk_key_ip (const ip46_address_t * ip,
188 u32 fib_index, clib_bihash_kv_24_8_t * key)
190 key->key[0] = ip->as_u64[0];
191 key->key[1] = ip->as_u64[1];
192 key->key[2] = fib_index;
195 static_always_inline void
196 gbp_endpoint_mk_key_ip4 (const ip4_address_t * ip,
197 u32 fib_index, clib_bihash_kv_24_8_t * key)
199 const ip46_address_t a = {
202 gbp_endpoint_mk_key_ip (&a, fib_index, key);
205 static_always_inline gbp_endpoint_t *
206 gbp_endpoint_find_ip4 (const ip4_address_t * ip, u32 fib_index)
208 clib_bihash_kv_24_8_t key, value;
211 gbp_endpoint_mk_key_ip4 (ip, fib_index, &key);
213 rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
218 return (gbp_endpoint_get (value.value));
221 static_always_inline void
222 gbp_endpoint_mk_key_ip6 (const ip6_address_t * ip,
223 u32 fib_index, clib_bihash_kv_24_8_t * key)
225 key->key[0] = ip->as_u64[0];
226 key->key[1] = ip->as_u64[1];
227 key->key[2] = fib_index;
230 static_always_inline gbp_endpoint_t *
231 gbp_endpoint_find_ip6 (const ip6_address_t * ip, u32 fib_index)
233 clib_bihash_kv_24_8_t key, value;
236 gbp_endpoint_mk_key_ip6 (ip, fib_index, &key);
238 rv = clib_bihash_search_24_8 (&gbp_ep_db.ged_by_ip_rd, &key, &value);
243 return (gbp_endpoint_get (value.value));
246 static_always_inline gbp_endpoint_t *
247 gbp_endpoint_find_itf (u32 sw_if_index)
251 gei = gbp_ep_db.ged_by_sw_if_index[sw_if_index];
253 if (INDEX_INVALID != gei)
254 return (gbp_endpoint_get (gei));
263 * fd.io coding-style-patch-verification: ON
266 * eval: (c-set-style "gnu")