FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
gbp_subnet.c
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 #include <plugins/gbp/gbp.h>
19 
20 #include <vnet/fib/fib_table.h>
21 #include <vnet/dpo/load_balance.h>
22 
23 static int
24 gbp_internal_subnet_add (u32 fib_index, const fib_prefix_t * pfx)
25 {
26  dpo_id_t gfd = DPO_INVALID;
27 
29 
31  pfx,
34 
35  dpo_reset (&gfd);
36 
37  return (0);
38 }
39 
40 static int
42  const fib_prefix_t * pfx,
43  u32 sw_if_index, epg_id_t epg)
44 {
45  dpo_id_t gpd = DPO_INVALID;
46 
48  epg, sw_if_index, &gpd);
49 
51  pfx,
55  &gpd);
56 
57  dpo_reset (&gpd);
58 
59  return (0);
60 }
61 
62 static int
63 gbp_subnet_del (u32 fib_index, const fib_prefix_t * pfx)
64 {
66 
67  return (0);
68 }
69 
70 int
72  const fib_prefix_t * pfx,
73  u32 sw_if_index, epg_id_t epg, u8 is_add, u8 is_internal)
74 {
75  u32 fib_index;
76 
77  fib_index = fib_table_find (pfx->fp_proto, table_id);
78 
79  if (~0 == fib_index)
80  return (VNET_API_ERROR_NO_SUCH_FIB);
81 
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));
86 
87  return (gbp_subnet_del (fib_index, pfx));
88 }
89 
91 {
93  void *ctx;
95 
98 {
100  const dpo_id_t *dpo;
101  fib_prefix_t pfx;
102  u32 table_id;
103 
104  fib_entry_get_prefix (fei, &pfx);
106  pfx.fp_proto);
108 
109  if (DPO_LOAD_BALANCE == dpo->dpoi_type)
110  {
111  dpo = load_balance_get_bucket (dpo->dpoi_index, 0);
112 
113  if (dpo->dpoi_type == gbp_policy_dpo_get_type ())
114  {
115  gbp_policy_dpo_t *gpd;
116 
117  gpd = gbp_policy_dpo_get (dpo->dpoi_index);
118 
119  /* *INDENT-OFF* */
120  ctx->cb (table_id, &pfx,
121  gpd->gpd_sw_if_index,
122  gpd->gpd_epg,
123  0, // is_internal
124  ctx->ctx);
125  /* *INDENT-ON* */
126  }
127  else if (dpo->dpoi_type == gbp_fwd_dpo_get_type ())
128  {
129  /* *INDENT-OFF* */
130  ctx->cb (table_id, &pfx,
131  ~0, // sw_if_index
132  ~0, // epg
133  1, // is_internal
134  ctx->ctx);
135  /* *INDENT-ON* */
136  }
137  }
138 
139  return (FIB_TABLE_WALK_CONTINUE);
140 }
141 
142 void
144 {
145  fib_table_t *fib_table;
146 
148  .cb = cb,
149  .ctx = ctx,
150  };
151 
152  /* *INDENT-OFF* */
153  pool_foreach (fib_table, ip4_main.fibs,
154  ({
155  fib_table_walk(fib_table->ft_index,
156  FIB_PROTOCOL_IP4,
157  gbp_subnet_fib_table_walk,
158  &wctx);
159  }));
160  pool_foreach (fib_table, ip6_main.fibs,
161  ({
162  fib_table_walk(fib_table->ft_index,
163  FIB_PROTOCOL_IP6,
164  gbp_subnet_fib_table_walk,
165  &wctx);
166  }));
167  /* *INDENT-ON* */
168 }
169 
170 /*
171  * fd.io coding-style-patch-verification: ON
172  *
173  * Local Variables:
174  * eval: (c-set-style "gnu")
175  * End:
176  */
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:197
static int gbp_internal_subnet_add(u32 fib_index, const fib_prefix_t *pfx)
Definition: gbp_subnet.c:24
u32 fib_entry_get_fib_index(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1626
Continue on to the next entry.
Definition: fib_table.h:857
void gbp_subnet_walk(gbp_subnet_cb_t cb, void *ctx)
Definition: gbp_subnet.c:143
void fib_entry_get_prefix(fib_node_index_t fib_entry_index, fib_prefix_t *pfx)
Definition: fib_entry.c:1616
int(* gbp_subnet_cb_t)(u32 table_id, const fib_prefix_t *pfx, u32 sw_if_index, epg_id_t epg, u8 is_internal, void *ctx)
Definition: gbp_subnet.h:27
const dpo_id_t * fib_entry_contribute_ip_forwarding(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:478
gbp_policy_dpo_t * gbp_policy_dpo_get(index_t index)
static int gbp_external_subnet_add(u32 fib_index, const fib_prefix_t *pfx, u32 sw_if_index, epg_id_t epg)
Definition: gbp_subnet.c:41
unsigned char u8
Definition: types.h:56
Definition: fib_entry.h:278
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:440
static fib_table_walk_rc_t gbp_subnet_fib_table_walk(fib_node_index_t fei, void *arg)
Definition: gbp_subnet.c:97
epg_id_t gpd_epg
EPG.
A high priority source a plugin can use.
Definition: fib_entry.h:62
int gbp_subnet_add_del(u32 table_id, const fib_prefix_t *pfx, u32 sw_if_index, epg_id_t epg, u8 is_add, u8 is_internal)
Definition: gbp_subnet.c:71
Aggregrate type for a prefix.
Definition: fib_types.h:188
u32 epg_id_t
Definition: gbp_types.h:21
unsigned int u32
Definition: types.h:88
u32 gpd_sw_if_index
output sw_if_index
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1056
dpo_type_t gbp_policy_dpo_get_type(void)
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
Definition: fib_entry.h:274
The GBP FWD DPO.
dpo_type_t dpoi_type
the type
Definition: dpo.h:172
load-balancing over a choice of [un]equal cost paths
Definition: dpo.h:102
const dpo_id_t * load_balance_get_bucket(index_t lbi, u32 bucket)
Definition: load_balance.c:294
static int gbp_subnet_del(u32 fib_index, const fib_prefix_t *pfx)
Definition: gbp_subnet.c:63
fib_node_index_t fib_table_entry_special_dpo_update(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Update a &#39;special&#39; entry to the FIB that links to the DPO passed A special entry is an entry that the...
Definition: fib_table.c:346
dpo_type_t gbp_fwd_dpo_get_type(void)
Definition: gbp_fwd_dpo.c:145
void gbp_policy_dpo_add_or_lock(dpo_proto_t dproto, epg_id_t epg, u32 sw_if_index, dpo_id_t *dpo)
enum fib_table_walk_rc_t_ fib_table_walk_rc_t
return code controlling how a table walk proceeds
void fib_table_entry_delete(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:853
void gbp_fwd_dpo_add_or_lock(dpo_proto_t dproto, dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:86
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
ip6_main_t ip6_main
Definition: ip6_forward.c:2574
u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto)
Get the Table-ID of the FIB from protocol and index.
Definition: fib_table.c:1045
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:236
struct gbp_subnet_fib_table_walk_ctx_t_ gbp_subnet_fib_table_walk_ctx_t
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:184
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:195
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:832
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:100
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:231
struct fib_table_t_ * fibs
Definition: ip6.h:164
A protocol Independent FIB table.
Definition: fib_table.h:69