]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls.h
Merge pull request #486 from LabNConsulting/working/3.0/patch/issue483
[mirror_frr.git] / zebra / zebra_mpls.h
1 /*
2 * Zebra MPLS Data structures and definitions
3 * Copyright (C) 2015 Cumulus Networks, Inc.
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23 #ifndef _ZEBRA_MPLS_H
24 #define _ZEBRA_MPLS_H
25
26 #include "prefix.h"
27 #include "table.h"
28 #include "queue.h"
29 #include "hash.h"
30 #include "jhash.h"
31 #include "nexthop.h"
32 #include "vty.h"
33 #include "memory.h"
34 #include "mpls.h"
35 #include "zebra/zserv.h"
36 #include "zebra/zebra_vrf.h"
37
38
39 /* Definitions and macros. */
40
41 #define MPLS_MAX_LABELS 2 /* Maximum # labels that can be pushed. */
42
43 #define NHLFE_FAMILY(nhlfe) \
44 (((nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6 || \
45 (nhlfe)->nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) ? AF_INET6 : AF_INET)
46
47
48 /* Typedefs */
49
50 typedef struct zebra_ile_t_ zebra_ile_t;
51 typedef struct zebra_snhlfe_t_ zebra_snhlfe_t;
52 typedef struct zebra_slsp_t_ zebra_slsp_t;
53 typedef struct zebra_nhlfe_t_ zebra_nhlfe_t;
54 typedef struct zebra_lsp_t_ zebra_lsp_t;
55
56 /*
57 * (Outgoing) nexthop label forwarding entry configuration
58 */
59 struct zebra_snhlfe_t_
60 {
61 /* Nexthop information */
62 enum nexthop_types_t gtype;
63 union g_addr gate;
64 char *ifname;
65 ifindex_t ifindex;
66
67 /* Out label. */
68 mpls_label_t out_label;
69
70 /* Backpointer to base entry. */
71 zebra_slsp_t *slsp;
72
73 /* Pointers to more outgoing information for same in-label */
74 zebra_snhlfe_t *next;
75 zebra_snhlfe_t *prev;
76 };
77
78 /*
79 * (Outgoing) nexthop label forwarding entry
80 */
81 struct zebra_nhlfe_t_
82 {
83 /* Type of entry - static etc. */
84 enum lsp_types_t type;
85
86 /* Nexthop information (with outgoing label) */
87 struct nexthop *nexthop;
88
89 /* Backpointer to base entry. */
90 zebra_lsp_t *lsp;
91
92 /* Runtime info - flags, pointers etc. */
93 u_int32_t flags;
94 #define NHLFE_FLAG_CHANGED (1 << 0)
95 #define NHLFE_FLAG_SELECTED (1 << 1)
96 #define NHLFE_FLAG_MULTIPATH (1 << 2)
97 #define NHLFE_FLAG_DELETED (1 << 3)
98 #define NHLFE_FLAG_INSTALLED (1 << 4)
99
100 zebra_nhlfe_t *next;
101 zebra_nhlfe_t *prev;
102 u_char distance;
103 };
104
105 /*
106 * Incoming label entry
107 */
108 struct zebra_ile_t_
109 {
110 mpls_label_t in_label;
111 };
112
113 /*
114 * Label swap entry static configuration.
115 */
116 struct zebra_slsp_t_
117 {
118 /* Incoming label */
119 zebra_ile_t ile;
120
121 /* List of outgoing nexthop static configuration */
122 zebra_snhlfe_t *snhlfe_list;
123
124 };
125
126 /*
127 * Label swap entry (ile -> list of nhlfes)
128 */
129 struct zebra_lsp_t_
130 {
131 /* Incoming label */
132 zebra_ile_t ile;
133
134 /* List of NHLFE, pointer to best and num equal-cost. */
135 zebra_nhlfe_t *nhlfe_list;
136 zebra_nhlfe_t *best_nhlfe;
137 u_int32_t num_ecmp;
138
139 /* Flags */
140 u_int32_t flags;
141 #define LSP_FLAG_SCHEDULED (1 << 0)
142 #define LSP_FLAG_INSTALLED (1 << 1)
143 #define LSP_FLAG_CHANGED (1 << 2)
144
145 /* Address-family of NHLFE - saved here for delete. All NHLFEs */
146 /* have to be of the same AF */
147 u_char addr_family;
148 };
149
150
151 /* Function declarations. */
152
153 /*
154 * String to label conversion, labels separated by '/'.
155 */
156 int
157 mpls_str2label (const char *label_str, u_int8_t *num_labels,
158 mpls_label_t *labels);
159
160 /*
161 * Label to string conversion, labels in string separated by '/'.
162 */
163 char *
164 mpls_label2str (u_int8_t num_labels, mpls_label_t *labels,
165 char *buf, int len);
166
167 /*
168 * Install/uninstall a FEC-To-NHLFE (FTN) binding.
169 */
170 int
171 mpls_ftn_update (int add, struct zebra_vrf *zvrf, enum lsp_types_t type,
172 struct prefix *prefix, enum nexthop_types_t gtype,
173 union g_addr *gate, ifindex_t ifindex, u_int8_t distance,
174 mpls_label_t out_label);
175
176 /*
177 * Install/update a NHLFE for an LSP in the forwarding table. This may be
178 * a new LSP entry or a new NHLFE for an existing in-label or an update of
179 * the out-label for an existing NHLFE (update case).
180 */
181 int
182 mpls_lsp_install (struct zebra_vrf *zvrf, enum lsp_types_t type,
183 mpls_label_t in_label, mpls_label_t out_label,
184 enum nexthop_types_t gtype, union g_addr *gate,
185 char *ifname, ifindex_t ifindex);
186
187 /*
188 * Uninstall a particular NHLFE in the forwarding table. If this is
189 * the only NHLFE, the entire LSP forwarding entry has to be deleted.
190 */
191 int
192 mpls_lsp_uninstall (struct zebra_vrf *zvrf, enum lsp_types_t type,
193 mpls_label_t in_label, enum nexthop_types_t gtype,
194 union g_addr *gate, char *ifname, ifindex_t ifindex);
195
196 /*
197 * Uninstall all LDP NHLFEs for a particular LSP forwarding entry.
198 * If no other NHLFEs exist, the entry would be deleted.
199 */
200 void
201 mpls_ldp_lsp_uninstall_all (struct hash_backet *backet, void *ctxt);
202
203 /*
204 * Uninstall all LDP FEC-To-NHLFE (FTN) bindings of the given address-family.
205 */
206 void
207 mpls_ldp_ftn_uninstall_all (struct zebra_vrf *zvrf, int afi);
208
209 #if defined(HAVE_CUMULUS)
210 /*
211 * Check that the label values used in LSP creation are consistent. The
212 * main criteria is that if there is ECMP, the label operation must still
213 * be consistent - i.e., all paths either do a swap or do PHP. This is due
214 * to current HW restrictions.
215 */
216 int
217 zebra_mpls_lsp_label_consistent (struct zebra_vrf *zvrf, mpls_label_t in_label,
218 mpls_label_t out_label, enum nexthop_types_t gtype,
219 union g_addr *gate, char *ifname, ifindex_t ifindex);
220 #endif /* HAVE_CUMULUS */
221
222 /*
223 * Add static LSP entry. This may be the first entry for this incoming label
224 * or an additional nexthop; an existing entry may also have outgoing label
225 * changed.
226 * Note: The label operation (swap or PHP) is common for the LSP entry (all
227 * NHLFEs).
228 */
229 int
230 zebra_mpls_static_lsp_add (struct zebra_vrf *zvrf, mpls_label_t in_label,
231 mpls_label_t out_label, enum nexthop_types_t gtype,
232 union g_addr *gate, char *ifname, ifindex_t ifindex);
233
234 /*
235 * Delete static LSP entry. This may be the delete of one particular
236 * NHLFE for this incoming label or the delete of the entire entry (i.e.,
237 * all NHLFEs).
238 * NOTE: Delete of the only NHLFE will also end up deleting the entire
239 * LSP configuration.
240 */
241 int
242 zebra_mpls_static_lsp_del (struct zebra_vrf *zvrf, mpls_label_t in_label,
243 enum nexthop_types_t gtype, union g_addr *gate,
244 char *ifname, ifindex_t ifindex);
245
246 /*
247 * Schedule all MPLS label forwarding entries for processing.
248 * Called upon changes that may affect one or more of them such as
249 * interface or nexthop state changes.
250 */
251 void
252 zebra_mpls_lsp_schedule (struct zebra_vrf *zvrf);
253
254 /*
255 * Display MPLS label forwarding table for a specific LSP
256 * (VTY command handler).
257 */
258 void
259 zebra_mpls_print_lsp (struct vty *vty, struct zebra_vrf *zvrf, mpls_label_t label,
260 u_char use_json);
261
262 /*
263 * Display MPLS label forwarding table (VTY command handler).
264 */
265 void
266 zebra_mpls_print_lsp_table (struct vty *vty, struct zebra_vrf *zvrf,
267 u_char use_json);
268
269 /*
270 * Display MPLS LSP configuration of all static LSPs (VTY command handler).
271 */
272 int
273 zebra_mpls_write_lsp_config (struct vty *vty, struct zebra_vrf *zvrf);
274
275 /*
276 * Called upon process exiting, need to delete LSP forwarding
277 * entries from the kernel.
278 * NOTE: Currently supported only for default VRF.
279 */
280 void
281 zebra_mpls_close_tables (struct zebra_vrf *zvrf);
282
283 /*
284 * Allocate MPLS tables for this VRF.
285 * NOTE: Currently supported only for default VRF.
286 */
287 void
288 zebra_mpls_init_tables (struct zebra_vrf *zvrf);
289
290 /*
291 * Global MPLS initialization.
292 */
293 void
294 zebra_mpls_init (void);
295
296 /*
297 * MPLS VTY.
298 */
299 void
300 zebra_mpls_vty_init (void);
301
302 /* Inline functions. */
303
304 /*
305 * Distance (priority) definition for LSP NHLFE.
306 */
307 static inline u_char
308 lsp_distance (enum lsp_types_t type)
309 {
310 if (type == ZEBRA_LSP_STATIC)
311 return (route_distance (ZEBRA_ROUTE_STATIC));
312
313 return 150;
314 }
315
316 /*
317 * Map RIB type to LSP type. Used when labeled-routes from BGP
318 * are converted into LSPs.
319 */
320 static inline enum lsp_types_t
321 lsp_type_from_rib_type (int rib_type)
322 {
323 switch (rib_type)
324 {
325 case ZEBRA_ROUTE_STATIC:
326 return ZEBRA_LSP_STATIC;
327 default:
328 return ZEBRA_LSP_NONE;
329 }
330 }
331
332 /* NHLFE type as printable string. */
333 static inline const char *
334 nhlfe_type2str(enum lsp_types_t lsp_type)
335 {
336 switch (lsp_type)
337 {
338 case ZEBRA_LSP_STATIC:
339 return "Static";
340 case ZEBRA_LSP_LDP:
341 return "LDP";
342 default:
343 return "Unknown";
344 }
345 }
346
347 static inline void
348 mpls_mark_lsps_for_processing(struct zebra_vrf *zvrf)
349 {
350 if (!zvrf)
351 return;
352
353 zvrf->mpls_flags |= MPLS_FLAG_SCHEDULE_LSPS;
354 }
355
356 static inline void
357 mpls_unmark_lsps_for_processing(struct zebra_vrf *zvrf)
358 {
359 if (!zvrf)
360 return;
361
362 zvrf->mpls_flags &= ~MPLS_FLAG_SCHEDULE_LSPS;
363 }
364
365 static inline int
366 mpls_should_lsps_be_processed(struct zebra_vrf *zvrf)
367 {
368 if (!zvrf)
369 return 0;
370
371 return ((zvrf->mpls_flags & MPLS_FLAG_SCHEDULE_LSPS) ? 1 : 0);
372 }
373
374 /* Global variables. */
375 extern int mpls_enabled;
376
377 #endif /*_ZEBRA_MPLS_H */