VPP-1474: fix 2x coverity warnings
[vpp.git] / src / plugins / gbp / gbp_endpoint_group.h
1 /*
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:
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 __GBP_ENDPOINT_GROUP_H__
17 #define __GBP_ENDPOINT_GROUP_H__
18
19 #include <plugins/gbp/gbp_types.h>
20
21 #include <vnet/fib/fib_types.h>
22
23 /**
24  * An Endpoint Group representation
25  */
26 typedef struct gpb_endpoint_group_t_
27 {
28   /**
29    * ID
30    */
31   epg_id_t gg_id;
32
33   /**
34    * Bridge-domain ID the EPG is in
35    */
36   index_t gg_gbd;
37   index_t gg_bd_index;
38
39   /**
40    * route-domain/IP-table ID the EPG is in
41    */
42   index_t gg_rd;
43
44   /**
45    * Is the EPG an external/NAT
46    */
47   u8 gg_is_ext;
48
49   /**
50    * the uplink interface dedicated to the EPG
51    */
52   u32 gg_uplink_sw_if_index;
53
54   /**
55    * The DPO used in the L3 path for forwarding internal subnets
56    */
57   dpo_id_t gg_dpo[FIB_PROTOCOL_IP_MAX];
58
59   /**
60    * Locks/references to this EPG
61    */
62   u32 gg_locks;
63 } gbp_endpoint_group_t;
64
65 /**
66  * EPG DB, key'd on EGP-ID
67  */
68 typedef struct gbp_endpoint_group_db_t_
69 {
70   uword *gg_hash;
71 } gbp_endpoint_group_db_t;
72
73 extern int gbp_endpoint_group_add_and_lock (epg_id_t epg_id,
74                                             u32 bd_id,
75                                             u32 rd_id,
76                                             u32 uplink_sw_if_index);
77 extern index_t gbp_endpoint_group_find_and_lock (epg_id_t epg_id);
78 extern index_t gbp_endpoint_group_find (epg_id_t epg_id);
79 extern int gbp_endpoint_group_delete (epg_id_t epg_id);
80 extern void gbp_endpoint_group_unlock (index_t index);
81 extern u32 gbp_endpoint_group_get_bd_id (const gbp_endpoint_group_t *);
82
83 extern gbp_endpoint_group_t *gbp_endpoint_group_get (index_t i);
84 extern index_t gbp_endpoint_group_get_fib_index (gbp_endpoint_group_t * gg,
85                                                  fib_protocol_t fproto);
86 extern u32 gbp_endpoint_group_get_bvi (gbp_endpoint_group_t * gg);
87
88 typedef int (*gbp_endpoint_group_cb_t) (gbp_endpoint_group_t * gbpe,
89                                         void *ctx);
90 extern void gbp_endpoint_group_walk (gbp_endpoint_group_cb_t bgpe, void *ctx);
91
92
93 extern u8 *format_gbp_endpoint_group (u8 * s, va_list * args);
94
95 /**
96  * DP functions and databases
97  */
98 extern gbp_endpoint_group_db_t gbp_endpoint_group_db;
99 extern gbp_endpoint_group_t *gbp_endpoint_group_pool;
100
101 always_inline u32
102 gbp_epg_itf_lookup (epg_id_t epg)
103 {
104   uword *p;
105
106   p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
107
108   if (NULL != p)
109     {
110       gbp_endpoint_group_t *gg;
111
112       gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
113       return (gg->gg_uplink_sw_if_index);
114     }
115   return (~0);
116 }
117
118 always_inline const dpo_id_t *
119 gbp_epg_dpo_lookup (epg_id_t epg, fib_protocol_t fproto)
120 {
121   uword *p;
122
123   p = hash_get (gbp_endpoint_group_db.gg_hash, epg);
124
125   if (NULL != p)
126     {
127       gbp_endpoint_group_t *gg;
128
129       gg = pool_elt_at_index (gbp_endpoint_group_pool, p[0]);
130       return (&gg->gg_dpo[fproto]);
131     }
132   return (NULL);
133 }
134
135 #endif
136
137 /*
138  * fd.io coding-style-patch-verification: ON
139  *
140  * Local Variables:
141  * eval: (c-set-style "gnu")
142  * End:
143  */