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 #include <plugins/gbp/gbp.h>
17 #include <plugins/gbp/gbp_fwd_dpo.h>
18 #include <plugins/gbp/gbp_policy_dpo.h>
20 #include <vnet/fib/fib_table.h>
21 #include <vnet/dpo/load_balance.h>
24 gbp_internal_subnet_add (u32 fib_index, const fib_prefix_t * pfx)
26 dpo_id_t gfd = DPO_INVALID;
28 gbp_fwd_dpo_add_or_lock (fib_proto_to_dpo (pfx->fp_proto), &gfd);
30 fib_table_entry_special_dpo_update (fib_index,
33 FIB_ENTRY_FLAG_EXCLUSIVE, &gfd);
41 gbp_external_subnet_add (u32 fib_index,
42 const fib_prefix_t * pfx,
43 u32 sw_if_index, epg_id_t epg)
45 dpo_id_t gpd = DPO_INVALID;
47 gbp_policy_dpo_add_or_lock (fib_proto_to_dpo (pfx->fp_proto),
48 epg, sw_if_index, &gpd);
50 fib_table_entry_special_dpo_update (fib_index,
53 (FIB_ENTRY_FLAG_EXCLUSIVE |
54 FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT),
63 gbp_subnet_del (u32 fib_index, const fib_prefix_t * pfx)
65 fib_table_entry_delete (fib_index, pfx, FIB_SOURCE_PLUGIN_HI);
71 gbp_subnet_add_del (u32 table_id,
72 const fib_prefix_t * pfx,
73 u32 sw_if_index, epg_id_t epg, u8 is_add, u8 is_internal)
77 fib_index = fib_table_find (pfx->fp_proto, table_id);
80 return (VNET_API_ERROR_NO_SUCH_FIB);
82 if (is_internal && is_add)
83 return (gbp_internal_subnet_add (fib_index, pfx));
84 else if (!is_internal && is_add)
85 return (gbp_external_subnet_add (fib_index, pfx, sw_if_index, epg));
87 return (gbp_subnet_del (fib_index, pfx));
90 typedef struct gbp_subnet_fib_table_walk_ctx_t_
94 } gbp_subnet_fib_table_walk_ctx_t;
96 static fib_table_walk_rc_t
97 gbp_subnet_fib_table_walk (fib_node_index_t fei, void *arg)
99 gbp_subnet_fib_table_walk_ctx_t *ctx = arg;
100 const fib_prefix_t *pfx;
104 pfx = fib_entry_get_prefix (fei);
105 table_id = fib_table_get_table_id (fib_entry_get_fib_index (fei),
107 dpo = fib_entry_contribute_ip_forwarding (fei);
109 if (DPO_LOAD_BALANCE == dpo->dpoi_type)
111 dpo = load_balance_get_bucket (dpo->dpoi_index, 0);
113 if (dpo->dpoi_type == gbp_policy_dpo_get_type ())
115 gbp_policy_dpo_t *gpd;
117 gpd = gbp_policy_dpo_get (dpo->dpoi_index);
120 ctx->cb (table_id, pfx,
121 gpd->gpd_sw_if_index,
127 else if (dpo->dpoi_type == gbp_fwd_dpo_get_type ())
130 ctx->cb (table_id, pfx,
139 return (FIB_TABLE_WALK_CONTINUE);
143 gbp_subnet_walk (gbp_subnet_cb_t cb, void *ctx)
145 fib_table_t *fib_table;
147 gbp_subnet_fib_table_walk_ctx_t wctx = {
153 pool_foreach (fib_table, ip4_main.fibs,
155 fib_table_walk(fib_table->ft_index,
157 gbp_subnet_fib_table_walk,
160 pool_foreach (fib_table, ip6_main.fibs,
162 fib_table_walk(fib_table->ft_index,
164 gbp_subnet_fib_table_walk,
171 * fd.io coding-style-patch-verification: ON
174 * eval: (c-set-style "gnu")