FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
fib_entry_src_mpls.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 <vnet/mpls/mpls_types.h>
17 #include <vnet/dpo/drop_dpo.h>
18 
19 #include <vnet/fib/fib_table.h>
20 #include <vnet/fib/fib_entry.h>
21 #include <vnet/fib/fib_entry_src.h>
22 #include <vnet/fib/mpls_fib.h>
23 
24 /**
25  * Source initialisation Function
26  */
27 static void
29 {
30  mpls_eos_bit_t eos;
31 
32  src->fes_flags = FIB_ENTRY_SRC_FLAG_NONE;
33  src->u.mpls.fesm_label = MPLS_LABEL_INVALID;
34 
36  {
37  src->u.mpls.fesm_lfes[eos] = FIB_NODE_INDEX_INVALID;
38  }
39 }
40 
41 /**
42  * Source deinitialisation Function
43  */
44 static void
46 {
47 }
48 
49 static void
51 {
52  src->fes_pl = FIB_NODE_INDEX_INVALID;
53  src->u.mpls.fesm_label = MPLS_LABEL_INVALID;
54 }
55 
56 static void
58  const fib_entry_t *entry,
61  const dpo_id_t *dpo)
62 {
63  src->fes_pl =
67 }
68 
69 static void
71  const fib_entry_t *entry,
72  const void *data)
73 {
74  fib_protocol_t payload_proto;
75  fib_node_index_t fei;
77  mpls_eos_bit_t eos;
78 
79  /*
80  * post MPLS table alloc and the possible rea-alloc of fib entrys
81  * the entry pointer will no longer be valid. so save its index
82  */
83  payload_proto = entry->fe_prefix.fp_proto;
84  fei = fib_entry_get_index(entry);
85  label = *(mpls_label_t*)data;
86 
88  {
89  /*
90  * removing the local label
91  */
93  {
94  fib_table_entry_delete_index(src->u.mpls.fesm_lfes[eos],
96  }
100  src->u.mpls.fesm_label = label;
101  }
102  else
103  {
104  fib_prefix_t prefix = {
105  .fp_proto = FIB_PROTOCOL_MPLS,
106  .fp_label = label,
107  };
108  fib_node_index_t fib_index;
109  dpo_id_t dpo = DPO_INVALID;
110 
111  /*
112  * adding a new local label. make sure the MPLS fib exists.
113  */
114  if (MPLS_LABEL_INVALID == src->u.mpls.fesm_label)
115  {
116  fib_index =
120  }
121  else
122  {
124 
125  /*
126  * if this is a change in label, remove the old one first
127  */
128  if (src->u.mpls.fesm_label != label)
129  {
131  {
132  ASSERT(FIB_NODE_INDEX_INVALID != src->u.mpls.fesm_lfes[eos]);
133  fib_table_entry_delete_index(src->u.mpls.fesm_lfes[eos],
135  }
136  }
137  }
138 
139  src->u.mpls.fesm_label = label;
140 
142  {
143  prefix.fp_eos = eos;
144  prefix.fp_payload_proto = fib_proto_to_dpo(payload_proto);
145 
147  (eos ?
150  &dpo);
151  src->u.mpls.fesm_lfes[eos] =
153  &prefix,
156  &dpo);
157  dpo_reset(&dpo);
158  }
159  }
160 }
161 
162 static const void *
164  const fib_entry_t *entry)
165 {
166  return (&(src->u.mpls.fesm_label));
167 }
168 
169 static u8*
171  u8* s)
172 {
173  return (format(s, " local-label:%d", src->u.mpls.fesm_label));
174 }
175 
178  .fesv_deinit = fib_entry_src_mpls_deinit,
179  .fesv_add = fib_entry_src_mpls_add,
180  .fesv_remove = fib_entry_src_mpls_remove,
181  .fesv_format = fib_entry_src_mpls_format,
182  .fesv_set_data = fib_entry_src_mpls_set_data,
183  .fesv_get_data = fib_entry_src_mpls_get_data,
184  /*
185  * .fesv_fwd_update = fib_entry_src_mpls_fwd_update,
186  * When the forwarding for the IP entry is updated, any MPLS chains
187  * it has created are also updated. Since the MPLS entry will have already
188  * installed that chain/load-balance there is no need to update the netry
189  * FIXME: later: propagate any walk to the children of the MPLS entry. for SR
190  */
191 };
192 
193 void
195 {
197 }
fib_entry.h
FIB_PATH_LIST_FLAG_DROP
@ FIB_PATH_LIST_FLAG_DROP
Definition: fib_path_list.h:82
fib_entry_src_mpls_init
static void fib_entry_src_mpls_init(fib_entry_src_t *src)
Source initialisation Function.
Definition: fib_entry_src_mpls.c:28
DPO_INVALID
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:204
label
u32 label
Definition: fib_types.api:25
fib_table_entry_special_dpo_add
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a 'special' entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
Definition: fib_table.c:324
fib_entry_t_
An entry in a FIB table.
Definition: fib_entry.h:305
dpo_proto_t
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
FIB_FORW_CHAIN_TYPE_MPLS_EOS
@ FIB_FORW_CHAIN_TYPE_MPLS_EOS
Contribute an object that is to be used to forward end-of-stack MPLS packets.
Definition: fib_types.h:128
fib_entry_src_t_
Information related to the source of a FIB entry.
Definition: fib_entry.h:197
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
fib_entry_src_mpls_register
void fib_entry_src_mpls_register(void)
Definition: fib_entry_src_mpls.c:194
fib_table.h
mpls_fib_index_from_table_id
u32 mpls_fib_index_from_table_id(u32 table_id)
Definition: mpls_fib.c:73
FIB_ENTRY_FLAG_EXCLUSIVE
@ FIB_ENTRY_FLAG_EXCLUSIVE
Definition: fib_entry.h:116
drop_dpo.h
FIB_SOURCE_BH_MPLS
@ FIB_SOURCE_BH_MPLS
associated label stored in private data
Definition: fib_source.h:219
fib_entry_contribute_forwarding
void fib_entry_contribute_forwarding(fib_node_index_t fib_entry_index, fib_forward_chain_type_t fct, dpo_id_t *dpo)
Definition: fib_entry.c:437
fib_entry_src_mpls_format
static u8 * fib_entry_src_mpls_format(fib_entry_src_t *src, u8 *s)
Definition: fib_entry_src_mpls.c:170
mpls_fib.h
fib_entry_src.h
fib_entry_src_mpls_set_data
static void fib_entry_src_mpls_set_data(fib_entry_src_t *src, const fib_entry_t *entry, const void *data)
Definition: fib_entry_src_mpls.c:70
fib_entry_src_vft_t_
Virtual function table each FIB entry source will register.
Definition: fib_entry_src.h:195
fib_entry_src_mpls_add
static void fib_entry_src_mpls_add(fib_entry_src_t *src, const fib_entry_t *entry, fib_entry_flag_t flags, dpo_proto_t proto, const dpo_id_t *dpo)
Definition: fib_entry_src_mpls.c:57
fib_entry_flag_t
enum fib_entry_flag_t_ fib_entry_flag_t
fib_entry_src_mpls_deinit
static void fib_entry_src_mpls_deinit(fib_entry_src_t *src)
Source deinitialisation Function.
Definition: fib_entry_src_mpls.c:45
fib_table_find_or_create_and_lock
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1165
FIB_ENTRY_SRC_FLAG_NONE
@ FIB_ENTRY_SRC_FLAG_NONE
Definition: fib_entry.h:177
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
fib_entry_get_index
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:63
fib_entry_src_mpls_remove
static void fib_entry_src_mpls_remove(fib_entry_src_t *src)
Definition: fib_entry_src_mpls.c:50
src
vl_api_address_t src
Definition: gre.api:54
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
fib_proto_to_dpo
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:343
mpls_types.h
data
u8 data[128]
Definition: ipsec_types.api:92
fib_path_list_create_special
fib_node_index_t fib_path_list_create_special(dpo_proto_t nh_proto, fib_path_list_flags_t flags, const dpo_id_t *dpo)
Definition: fib_path_list.c:774
FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS
@ FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS
Contribute an object that is to be used to forward non-end-of-stack MPLS packets.
Definition: fib_types.h:117
mpls_src_vft
const static fib_entry_src_vft_t mpls_src_vft
Definition: fib_entry_src_mpls.c:176
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
FIB_PROTOCOL_MPLS
@ FIB_PROTOCOL_MPLS
Definition: fib_types.h:38
MPLS_FIB_DEFAULT_TABLE_ID
#define MPLS_FIB_DEFAULT_TABLE_ID
Definition: mpls_fib.h:28
fib_prefix_t_::fp_proto
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:211
FIB_SOURCE_SPECIAL
@ FIB_SOURCE_SPECIAL
Special sources.
Definition: fib_source.h:45
FOR_EACH_MPLS_EOS_BIT
#define FOR_EACH_MPLS_EOS_BIT(_eos)
Definition: packet.h:73
drop_dpo_get
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
fib_entry_src_vft_t_::fesv_init
fib_entry_src_init_t fesv_init
Definition: fib_entry_src.h:196
fib_entry_t_::fe_prefix
const fib_prefix_t fe_prefix
The prefix of the route.
Definition: fib_entry.h:314
u8
unsigned char u8
Definition: types.h:56
FIB_SOURCE_MPLS
@ FIB_SOURCE_MPLS
MPLS label.
Definition: fib_source.h:111
fib_table_unlock
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1336
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
mpls_label_t
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:26
fib_entry_src_behaviour_register
void fib_entry_src_behaviour_register(fib_source_behaviour_t bh, const fib_entry_src_vft_t *vft)
Definition: fib_entry_src.c:61
fib_table_entry_delete_index
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:919
fib_entry_src_mpls_get_data
static const void * fib_entry_src_mpls_get_data(fib_entry_src_t *src, const fib_entry_t *entry)
Definition: fib_entry_src_mpls.c:163
mpls_eos_bit_t
enum mpls_eos_bit_t_ mpls_eos_bit_t
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
MPLS_LABEL_INVALID
#define MPLS_LABEL_INVALID
Definition: mpls_types.h:48
dpo_reset
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:234
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
prefix
vl_api_prefix_t prefix
Definition: ip.api:146
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105