FD.io VPP  v18.01.2-1-g9b554f3
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 
33  src->mpls.fesm_label = MPLS_LABEL_INVALID;
34 
36  {
37  src->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 {
53  src->mpls.fesm_label = MPLS_LABEL_INVALID;
54 }
55 
56 static void
58  const fib_entry_t *entry,
60  dpo_proto_t proto,
61  const dpo_id_t *dpo)
62 {
63  src->fes_pl =
66  drop_dpo_get(proto));
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;
76  mpls_label_t label;
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 
87  if (MPLS_LABEL_INVALID == label)
88  {
89  /*
90  * removing the local label
91  */
93  {
94  fib_table_entry_delete_index(src->mpls.fesm_lfes[eos],
96  }
100  src->mpls.fesm_label = label;
101  }
102  else
103  {
104  fib_prefix_t prefix = {
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->mpls.fesm_label)
115  {
116  fib_index =
120  }
121  else
122  {
124 
125  /*
126  * if this is a change in label, reomve the old one first
127  */
128  if (src->mpls.fesm_label != label)
129  {
131  {
132  ASSERT(FIB_NODE_INDEX_INVALID != src->mpls.fesm_lfes[eos]);
133  fib_table_entry_delete_index(src->mpls.fesm_lfes[eos],
135  }
136  }
137  }
138 
139  src->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->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->mpls.fesm_label));
167 }
168 
169 static u8*
171  u8* s)
172 {
173  return (format(s, " local-label:%d", src->mpls.fesm_label));
174 }
175 
176 const static fib_entry_src_vft_t mpls_src_vft = {
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 {
196  fib_entry_src_register(FIB_SOURCE_MPLS, &mpls_src_vft);
197 }
198 
199 
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:181
static void fib_entry_src_mpls_remove(fib_entry_src_t *src)
fib_entry_src_init_t fesv_init
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)
struct fib_entry_src_t_::@109::@114 mpls
An entry in a FIB table.
Definition: fib_entry.h:385
static u8 * fib_entry_src_mpls_format(fib_entry_src_t *src, u8 *s)
static const void * fib_entry_src_mpls_get_data(fib_entry_src_t *src, const fib_entry_t *entry)
Virtual function table each FIB entry source will register.
Information related to the source of a FIB entry.
Definition: fib_entry.h:294
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)
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:408
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:24
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
dpo_proto_t fp_payload_proto
This protocol determines the payload protocol of packets that will be forwarded by this entry once th...
Definition: fib_types.h:205
Aggregrate type for a prefix.
Definition: fib_types.h:172
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:56
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
static void fib_entry_src_mpls_init(fib_entry_src_t *src)
Source initialisation Function.
MPLS label.
Definition: fib_entry.h:106
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:166
Contribute an object that is to be used to forward end-of-stack MPLS packets.
Definition: fib_types.h:108
Definition: fib_entry.h:242
static void fib_entry_src_mpls_deinit(fib_entry_src_t *src)
Source deinitialisation Function.
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:1180
#define MPLS_FIB_DEFAULT_TABLE_ID
Definition: mpls_fib.h:28
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:860
Definition: fib_entry.h:279
#define MPLS_LABEL_INVALID
Definition: mpls_types.h:48
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
u32 mpls_fib_index_from_table_id(u32 table_id)
Definition: mpls_fib.c:73
enum fib_entry_flag_t_ fib_entry_flag_t
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 &#39;special&#39; entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
Definition: fib_table.c:290
#define FOR_EACH_MPLS_EOS_BIT(_eos)
Definition: packet.h:45
#define ASSERT(truth)
fib_entry_src_flag_t fes_flags
Flags on the source.
Definition: fib_entry.h:311
void fib_entry_src_register(fib_source_t source, const fib_entry_src_vft_t *vft)
Definition: fib_entry_src.c:33
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:1087
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:211
fib_node_index_t fes_pl
The path-list created by the source.
Definition: fib_entry.h:303
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
unsigned char u8
Definition: types.h:56
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:193
static void fib_entry_src_mpls_set_data(fib_entry_src_t *src, const fib_entry_t *entry, const void *data)
Special sources.
Definition: fib_entry.h:40
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:228
Contribute an object that is to be used to forward non-end-of-stack MPLS packets. ...
Definition: fib_types.h:97
u32 flags
Definition: vhost-user.h:77
void fib_entry_src_mpls_register(void)
const fib_prefix_t fe_prefix
The prefix of the route.
Definition: fib_entry.h:394
mpls_eos_bit_t fp_eos
Definition: fib_types.h:199
enum mpls_eos_bit_t_ mpls_eos_bit_t