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_CONTRACT_H__
17 #define __GBP_CONTRACT_H__
19 #include <plugins/gbp/gbp_types.h>
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")
32 * The key for an Contract
34 typedef struct gbp_contract_key_t_
41 * source and destination EPGs for which the ACL applies
50 typedef struct gbp_next_hop_t_
53 ip46_address_t gnh_ip;
54 mac_address_t gnh_mac;
60 index_t gnh_ai[FIB_PROTOCOL_IP_MAX];
63 #define foreach_gbp_hash_mode \
66 _(SYMMETRIC, "symmetric")
68 typedef enum gbp_hash_mode_t_
70 #define _(v,s) GBP_HASH_MODE_##v,
75 #define foreach_gbp_rule_action \
78 _(REDIRECT, "redirect")
80 typedef enum gbp_rule_action_t_
82 #define _(v,s) GBP_RULE_##v,
83 foreach_gbp_rule_action
87 #define foreach_gbp_policy_node \
92 typedef enum gbp_policy_node_t_
94 #define _(v,s) GBP_POLICY_NODE_##v,
95 foreach_gbp_policy_node
98 #define GBP_POLICY_N_NODES (GBP_POLICY_NODE_IP6+1)
100 #define FOR_EACH_GBP_POLICY_NODE(pnode) \
101 for (pnode = GBP_POLICY_NODE_L2; pnode < GBP_POLICY_N_NODES; pnode++)
103 typedef struct gbp_rule_t_
105 gbp_rule_action_t gu_action;
106 gbp_hash_mode_t gu_hash_mode;
110 * DPO of the load-balance object used to redirect
112 dpo_id_t gu_dpo[GBP_POLICY_N_NODES][FIB_PROTOCOL_IP_MAX];
116 * A Group Based Policy Contract.
117 * Determines the ACL that applies to traffic pass between two endpoint groups
119 typedef struct gbp_contract_t_
122 * source and destination EPGs
124 gbp_contract_key_t gc_key;
130 * The ACL to apply for packets from the source to the destination EPG
135 * An ethertype whitelist
137 u16 *gc_allowed_ethertypes;
141 * EPG src,dst pair to ACL mapping table, aka contract DB
143 typedef struct gbp_contract_db_t_
146 * We can form a u64 key from the pair, so use a simple hash table
151 extern int gbp_contract_update (sclass_t sclass,
155 u16 * allowed_ethertypes, u32 * stats_index);
156 extern int gbp_contract_delete (sclass_t sclass, sclass_t dclass);
158 extern index_t gbp_rule_alloc (gbp_rule_action_t action,
159 gbp_hash_mode_t hash_mode, index_t * nhs);
160 extern index_t gbp_next_hop_alloc (const ip46_address_t * ip,
162 const mac_address_t * mac, index_t gbd);
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);
167 extern u8 *format_gbp_contract (u8 * s, va_list * args);
170 * DP functions and databases
172 extern gbp_contract_db_t gbp_contract_db;
174 always_inline index_t
175 gbp_contract_find (gbp_contract_key_t * key)
179 p = hash_get (gbp_contract_db.gc_hash, key->as_u32);
184 return (INDEX_INVALID);
187 extern gbp_contract_t *gbp_contract_pool;
189 always_inline gbp_contract_t *
190 gbp_contract_get (index_t gci)
192 return (pool_elt_at_index (gbp_contract_pool, gci));
195 extern gbp_rule_t *gbp_rule_pool;
197 always_inline gbp_rule_t *
198 gbp_rule_get (index_t gui)
200 return (pool_elt_at_index (gbp_rule_pool, gui));
203 extern vlib_combined_counter_main_t gbp_contract_permit_counters;
204 extern vlib_combined_counter_main_t gbp_contract_drop_counters;
209 * fd.io coding-style-patch-verification: ON
212 * eval: (c-set-style "gnu")