FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
gbp_contract.h
Go to the documentation of this file.
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_CONTRACT_H__
17 #define __GBP_CONTRACT_H__
18 
19 #include <plugins/gbp/gbp_types.h>
20 
21 #define foreach_gbp_policy_error \
22  _(ALLOW_NO_SCLASS, "allow-no-sclass") \
23  _(ALLOW_INTRA, "allow-intra-sclass") \
24  _(ALLOW_A_BIT, "allow-a-bit-set") \
25  _(ALLOW_CONTRACT, "allow-contract") \
26  _(DROP_CONTRACT, "drop-contract") \
27  _(DROP_ETHER_TYPE, "drop-ether-type") \
28  _(DROP_NO_CONTRACT, "drop-no-contract") \
29  _(DROP_NO_DCLASS, "drop-no-dclass")
30 
31 /**
32  * The key for an Contract
33  */
34 typedef struct gbp_contract_key_t_
35 {
36  union
37  {
38  struct
39  {
40  /**
41  * source and destination EPGs for which the ACL applies
42  */
45  };
47  };
49 
50 typedef struct gbp_next_hop_t_
51 {
53  ip46_address_t gnh_ip;
62 
63 #define foreach_gbp_hash_mode \
64  _(SRC_IP, "src-ip") \
65  _(DST_IP, "dst-ip") \
66  _(SYMMETRIC, "symmetric")
67 
68 typedef enum gbp_hash_mode_t_
69 {
70 #define _(v,s) GBP_HASH_MODE_##v,
72 #undef _
74 
75 #define foreach_gbp_rule_action \
76  _(PERMIT, "permit") \
77  _(DENY, "deny") \
78  _(REDIRECT, "redirect")
79 
80 typedef enum gbp_rule_action_t_
81 {
82 #define _(v,s) GBP_RULE_##v,
84 #undef _
86 
87 #define foreach_gbp_policy_node \
88  _(L2, "L2") \
89  _(IP4, "ip4") \
90  _(IP6, "ip6")
91 
92 typedef enum gbp_policy_node_t_
93 {
94 #define _(v,s) GBP_POLICY_NODE_##v,
96 #undef _
98 #define GBP_POLICY_N_NODES (GBP_POLICY_NODE_IP6+1)
99 
100 #define FOR_EACH_GBP_POLICY_NODE(pnode) \
101  for (pnode = GBP_POLICY_NODE_L2; pnode < GBP_POLICY_N_NODES; pnode++)
102 
103 typedef struct gbp_rule_t_
104 {
108 
109  /**
110  * DPO of the load-balance object used to redirect
111  */
113 } gbp_rule_t;
114 
115 /**
116  * A Group Based Policy Contract.
117  * Determines the ACL that applies to traffic pass between two endpoint groups
118  */
119 typedef struct gbp_contract_t_
120 {
121  /**
122  * source and destination EPGs
123  */
125 
128 
129  /**
130  * The ACL to apply for packets from the source to the destination EPG
131  */
133 
134  /**
135  * An ethertype whitelist
136  */
139 
140 /**
141  * EPG src,dst pair to ACL mapping table, aka contract DB
142  */
143 typedef struct gbp_contract_db_t_
144 {
145  /**
146  * We can form a u64 key from the pair, so use a simple hash table
147  */
150 
153  u32 acl_index,
154  index_t * rules,
155  u16 * allowed_ethertypes, u32 * stats_index);
157 
159  gbp_hash_mode_t hash_mode, index_t * nhs);
160 extern index_t gbp_next_hop_alloc (const ip46_address_t * ip,
161  index_t grd,
162  const mac_address_t * mac, index_t gbd);
163 
164 typedef int (*gbp_contract_cb_t) (gbp_contract_t * gbpe, void *ctx);
165 extern void gbp_contract_walk (gbp_contract_cb_t bgpe, void *ctx);
166 
167 extern u8 *format_gbp_contract (u8 * s, va_list * args);
168 
169 /**
170  * DP functions and databases
171  */
173 
176 {
177  uword *p;
178 
179  p = hash_get (gbp_contract_db.gc_hash, key->as_u32);
180 
181  if (NULL != p)
182  return (p[0]);
183 
184  return (INDEX_INVALID);
185 }
186 
188 
191 {
192  return (pool_elt_at_index (gbp_contract_pool, gci));
193 }
194 
195 extern gbp_rule_t *gbp_rule_pool;
196 
199 {
200  return (pool_elt_at_index (gbp_rule_pool, gui));
201 }
202 
205 
206 #endif
207 
208 /*
209  * fd.io coding-style-patch-verification: ON
210  *
211  * Local Variables:
212  * eval: (c-set-style "gnu")
213  * End:
214  */
u16 * gc_allowed_ethertypes
An ethertype whitelist.
Definition: gbp_contract.h:137
u32 acl_index
Definition: gbp.api:304
u16 sclass_t
Definition: gbp_types.h:24
gbp_contract_key_t gc_key
source and destination EPGs
Definition: gbp_contract.h:124
fib_node_t gnh_node
Definition: gbp_contract.h:52
struct gbp_next_hop_t_ gbp_next_hop_t
struct gbp_rule_t_ gbp_rule_t
struct gbp_contract_key_t_ gbp_contract_key_t
The key for an Contract.
#define NULL
Definition: clib.h:58
The key for an Contract.
Definition: gbp_contract.h:34
#define FIB_PROTOCOL_IP_MAX
Definition outside of enum so it does not need to be included in non-defaulted switch statements...
Definition: fib_types.h:58
ip46_address_t gnh_ip
Definition: gbp_contract.h:53
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
EPG src,dst pair to ACL mapping table, aka contract DB.
Definition: gbp_contract.h:143
static gbp_rule_t * gbp_rule_get(index_t gui)
Definition: gbp_contract.h:198
gbp_policy_node_t_
Definition: gbp_contract.h:92
gbp_rule_action_t_
Definition: gbp_contract.h:80
unsigned char u8
Definition: types.h:56
#define always_inline
Definition: clib.h:98
vlib_combined_counter_main_t gbp_contract_drop_counters
Definition: gbp_contract.c:49
vlib_combined_counter_main_t gbp_contract_permit_counters
Definition: gbp_contract.c:44
struct gbp_contract_db_t_ gbp_contract_db_t
EPG src,dst pair to ACL mapping table, aka contract DB.
void gbp_contract_walk(gbp_contract_cb_t bgpe, void *ctx)
Definition: gbp_contract.c:544
unsigned int u32
Definition: types.h:88
gbp_contract_db_t gbp_contract_db
DP functions and databases.
Definition: gbp_contract.c:29
uword * gc_hash
We can form a u64 key from the pair, so use a simple hash table.
Definition: gbp_contract.h:148
gbp_hash_mode_t_
Definition: gbp_contract.h:68
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:168
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
gbp_rule_t * gbp_rule_pool
Definition: gbp_contract.c:37
#define foreach_gbp_policy_node
Definition: gbp_contract.h:87
long ctx[MAX_CONNS]
Definition: main.c:144
index_t * gc_rules
The ACL to apply for packets from the source to the destination EPG.
Definition: gbp_contract.h:132
unsigned short u16
Definition: types.h:57
sclass_t gck_src
source and destination EPGs for which the ACL applies
Definition: gbp_contract.h:43
u16 sclass
Definition: gbp.api:118
gbp_rule_action_t gu_action
Definition: gbp_contract.h:105
#define GBP_POLICY_N_NODES
Definition: gbp_contract.h:98
vl_api_gbp_next_hop_t nhs[8]
Definition: gbp.api:284
An node in the FIB graph.
Definition: fib_node.h:291
u8 * format_gbp_contract(u8 *s, va_list *args)
Definition: gbp_contract.c:627
int gbp_contract_update(sclass_t sclass, sclass_t dclass, u32 acl_index, index_t *rules, u16 *allowed_ethertypes, u32 *stats_index)
Definition: gbp_contract.c:447
enum gbp_hash_mode_t_ gbp_hash_mode_t
index_t gbp_next_hop_alloc(const ip46_address_t *ip, index_t grd, const mac_address_t *mac, index_t gbd)
Definition: gbp_contract.c:70
int gbp_contract_delete(sclass_t sclass, sclass_t dclass)
Definition: gbp_contract.c:516
vl_api_gbp_rule_t rules[n_rules]
Definition: gbp.api:308
mac_address_t gnh_mac
Definition: gbp_contract.h:54
struct gbp_contract_t_ gbp_contract_t
A Group Based Policy Contract.
static gbp_contract_t * gbp_contract_get(index_t gci)
Definition: gbp_contract.h:190
index_t gbp_rule_alloc(gbp_rule_action_t action, gbp_hash_mode_t hash_mode, index_t *nhs)
Definition: gbp_contract.c:55
enum gbp_rule_action_t_ gbp_rule_action_t
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
u64 uword
Definition: types.h:112
#define foreach_gbp_rule_action
Definition: gbp_contract.h:75
typedef key
Definition: ipsec.api:244
#define foreach_gbp_hash_mode
Definition: gbp_contract.h:63
A collection of combined counters.
Definition: counter.h:188
enum gbp_policy_node_t_ gbp_policy_node_t
gbp_hash_mode_t gu_hash_mode
Definition: gbp_contract.h:106
u16 allowed_ethertypes[16]
Definition: gbp.api:306
u16 dclass
Definition: gbp.api:303
vl_api_mac_address_t mac
Definition: gbp.api:120
index_t * gu_nhs
Definition: gbp_contract.h:107
gbp_contract_t * gbp_contract_pool
Definition: gbp_contract.c:31
static index_t gbp_contract_find(gbp_contract_key_t *key)
Definition: gbp_contract.h:175
A Group Based Policy Contract.
Definition: gbp_contract.h:119
int(* gbp_contract_cb_t)(gbp_contract_t *gbpe, void *ctx)
Definition: gbp_contract.h:164