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>
22 * The key for an Contract
24 typedef struct gbp_contract_key_t_
31 * source and destination EPGs for which the ACL applies
40 typedef struct gbp_next_hop_t_
43 ip46_address_t gnh_ip;
44 mac_address_t gnh_mac;
50 index_t gnh_ai[FIB_PROTOCOL_IP_MAX];
53 #define foreach_gbp_hash_mode \
56 _(SYMMETRIC, "symmetric")
58 typedef enum gbp_hash_mode_t_
60 #define _(v,s) GBP_HASH_MODE_##v,
65 #define foreach_gbp_rule_action \
68 _(REDIRECT, "redirect")
70 typedef enum gbp_rule_action_t_
72 #define _(v,s) GBP_RULE_##v,
73 foreach_gbp_rule_action
77 #define foreach_gbp_policy_node \
82 typedef enum gbp_policy_node_t_
84 #define _(v,s) GBP_POLICY_NODE_##v,
85 foreach_gbp_policy_node
88 #define GBP_POLICY_N_NODES (GBP_POLICY_NODE_IP6+1)
90 #define FOR_EACH_GBP_POLICY_NODE(pnode) \
91 for (pnode = GBP_POLICY_NODE_L2; pnode < GBP_POLICY_N_NODES; pnode++)
93 typedef struct gbp_rule_t_
95 gbp_rule_action_t gu_action;
96 gbp_hash_mode_t gu_hash_mode;
100 * DPO of the load-balance object used to redirect
102 dpo_id_t gu_dpo[GBP_POLICY_N_NODES][FIB_PROTOCOL_IP_MAX];
106 * A Group Based Policy Contract.
107 * Determines the ACL that applies to traffic pass between two endpoint groups
109 typedef struct gbp_contract_t_
112 * source and destination EPGs
114 gbp_contract_key_t gc_key;
120 * The ACL to apply for packets from the source to the destination EPG
125 * An ethertype whitelist
127 u16 *gc_allowed_ethertypes;
131 * EPG src,dst pair to ACL mapping table, aka contract DB
133 typedef struct gbp_contract_db_t_
136 * We can form a u64 key from the pair, so use a simple hash table
141 extern int gbp_contract_update (epg_id_t src_epg,
144 index_t * rules, u16 * allowed_ethertypes);
145 extern int gbp_contract_delete (epg_id_t src_epg, epg_id_t dst_epg);
147 extern index_t gbp_rule_alloc (gbp_rule_action_t action,
148 gbp_hash_mode_t hash_mode, index_t * nhs);
149 extern index_t gbp_next_hop_alloc (const ip46_address_t * ip,
151 const mac_address_t * mac, index_t gbd);
153 typedef int (*gbp_contract_cb_t) (gbp_contract_t * gbpe, void *ctx);
154 extern void gbp_contract_walk (gbp_contract_cb_t bgpe, void *ctx);
156 extern u8 *format_gbp_contract (u8 * s, va_list * args);
159 * DP functions and databases
161 extern gbp_contract_db_t gbp_contract_db;
163 always_inline index_t
164 gbp_contract_find (gbp_contract_key_t * key)
168 p = hash_get (gbp_contract_db.gc_hash, key->as_u32);
173 return (INDEX_INVALID);
176 extern gbp_contract_t *gbp_contract_pool;
178 always_inline gbp_contract_t *
179 gbp_contract_get (index_t gci)
181 return (pool_elt_at_index (gbp_contract_pool, gci));
184 extern gbp_rule_t *gbp_rule_pool;
186 always_inline gbp_rule_t *
187 gbp_rule_get (index_t gui)
189 return (pool_elt_at_index (gbp_rule_pool, gui));
195 * fd.io coding-style-patch-verification: ON
198 * eval: (c-set-style "gnu")