]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_te.c
zebra: Fix label manager memory leak (#5680)
[mirror_frr.git] / isisd / isis_te.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_te.c
3 *
4 * This is an implementation of RFC5305 & RFC 7810
5 *
6 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
7 *
8 * Copyright (C) 2014 - 2019 Orange Labs http://www.orange.com
9 *
10 * This file is part of GNU Zebra.
11 *
12 * GNU Zebra is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
15 * later version.
16 *
17 * GNU Zebra is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; see the file COPYING; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include <zebra.h>
28 #include <math.h>
29
30 #include "linklist.h"
31 #include "thread.h"
32 #include "vty.h"
33 #include "stream.h"
34 #include "memory.h"
35 #include "log.h"
36 #include "prefix.h"
37 #include "command.h"
38 #include "hash.h"
39 #include "if.h"
40 #include "vrf.h"
41 #include "checksum.h"
42 #include "md5.h"
43 #include "sockunion.h"
44 #include "network.h"
45 #include "sbuf.h"
46
47 #include "isisd/isis_constants.h"
48 #include "isisd/isis_common.h"
49 #include "isisd/isis_flags.h"
50 #include "isisd/isis_circuit.h"
51 #include "isisd/isis_adjacency.h"
52 #include "isisd/isisd.h"
53 #include "isisd/isis_lsp.h"
54 #include "isisd/isis_pdu.h"
55 #include "isisd/isis_dynhn.h"
56 #include "isisd/isis_misc.h"
57 #include "isisd/isis_csm.h"
58 #include "isisd/isis_adjacency.h"
59 #include "isisd/isis_spf.h"
60 #include "isisd/isis_te.h"
61 #include "isisd/isis_zebra.h"
62
63 /*------------------------------------------------------------------------*
64 * Followings are control functions for MPLS-TE parameters management.
65 *------------------------------------------------------------------------*/
66
67 /* Main initialization / update function of the MPLS TE Circuit context */
68 /* Call when interface TE Link parameters are modified */
69 void isis_link_params_update(struct isis_circuit *circuit,
70 struct interface *ifp)
71 {
72 int i;
73 struct prefix_ipv4 *addr;
74 struct prefix_ipv6 *addr6;
75 struct isis_ext_subtlvs *ext;
76
77 /* Check if TE is enable or not */
78 if (!circuit->area || !IS_MPLS_TE(circuit->area->mta))
79 return;
80
81 /* Sanity Check */
82 if ((ifp == NULL) || (circuit->state != C_STATE_UP))
83 return;
84
85 zlog_debug("TE(%s): Update circuit parameters for interface %s",
86 circuit->area->area_tag, ifp->name);
87
88 /* Check if MPLS TE Circuit context has not been already created */
89 if (circuit->ext == NULL) {
90 circuit->ext = isis_alloc_ext_subtlvs();
91 zlog_debug(" |- Allocated new Ext-subTLVs for interface %s",
92 ifp->name);
93 }
94
95 ext = circuit->ext;
96
97 /* Fulfill Extended subTLVs from interface link parameters */
98 if (HAS_LINK_PARAMS(ifp)) {
99 /* STD_TE metrics */
100 if (IS_PARAM_SET(ifp->link_params, LP_ADM_GRP)) {
101 ext->adm_group = ifp->link_params->admin_grp;
102 SET_SUBTLV(ext, EXT_ADM_GRP);
103 } else
104 UNSET_SUBTLV(ext, EXT_ADM_GRP);
105
106 /* If known, register local IPv4 addr from ip_addr list */
107 if (circuit->ip_addrs != NULL
108 && listcount(circuit->ip_addrs) != 0) {
109 addr = (struct prefix_ipv4 *)listgetdata(
110 (struct listnode *)listhead(circuit->ip_addrs));
111 IPV4_ADDR_COPY(&ext->local_addr, &addr->prefix);
112 SET_SUBTLV(ext, EXT_LOCAL_ADDR);
113 } else
114 UNSET_SUBTLV(ext, EXT_LOCAL_ADDR);
115
116 /* Same for Remote IPv4 address */
117 if (circuit->circ_type == CIRCUIT_T_P2P) {
118 struct isis_adjacency *adj = circuit->u.p2p.neighbor;
119
120 if (adj && adj->adj_state == ISIS_ADJ_UP
121 && adj->ipv4_address_count) {
122 IPV4_ADDR_COPY(&ext->neigh_addr,
123 &adj->ipv4_addresses[0]);
124 SET_SUBTLV(ext, EXT_NEIGH_ADDR);
125 }
126 } else
127 UNSET_SUBTLV(ext, EXT_NEIGH_ADDR);
128
129 /* If known, register local IPv6 addr from ip_addr list */
130 if (circuit->ipv6_non_link != NULL
131 && listcount(circuit->ipv6_non_link) != 0) {
132 addr6 = (struct prefix_ipv6 *)listgetdata(
133 (struct listnode *)listhead(
134 circuit->ipv6_non_link));
135 IPV6_ADDR_COPY(&ext->local_addr6, &addr6->prefix);
136 SET_SUBTLV(ext, EXT_LOCAL_ADDR6);
137 } else
138 UNSET_SUBTLV(ext, EXT_LOCAL_ADDR6);
139
140 /* Same for Remote IPv6 address */
141 if (circuit->circ_type == CIRCUIT_T_P2P) {
142 struct isis_adjacency *adj = circuit->u.p2p.neighbor;
143
144 if (adj && adj->adj_state == ISIS_ADJ_UP
145 && adj->ipv6_address_count) {
146 IPV6_ADDR_COPY(&ext->neigh_addr6,
147 &adj->ipv6_addresses[0]);
148 SET_SUBTLV(ext, EXT_NEIGH_ADDR6);
149 }
150 } else
151 UNSET_SUBTLV(ext, EXT_NEIGH_ADDR6);
152
153 if (IS_PARAM_SET(ifp->link_params, LP_MAX_BW)) {
154 ext->max_bw = ifp->link_params->max_bw;
155 SET_SUBTLV(ext, EXT_MAX_BW);
156 } else
157 UNSET_SUBTLV(ext, EXT_MAX_BW);
158
159 if (IS_PARAM_SET(ifp->link_params, LP_MAX_RSV_BW)) {
160 ext->max_rsv_bw = ifp->link_params->max_rsv_bw;
161 SET_SUBTLV(ext, EXT_MAX_RSV_BW);
162 } else
163 UNSET_SUBTLV(ext, EXT_MAX_RSV_BW);
164
165 if (IS_PARAM_SET(ifp->link_params, LP_UNRSV_BW)) {
166 for (i = 0; i < MAX_CLASS_TYPE; i++)
167 ext->unrsv_bw[i] =
168 ifp->link_params->unrsv_bw[i];
169 SET_SUBTLV(ext, EXT_UNRSV_BW);
170 } else
171 UNSET_SUBTLV(ext, EXT_UNRSV_BW);
172
173 if (IS_PARAM_SET(ifp->link_params, LP_TE_METRIC)) {
174 ext->te_metric = ifp->link_params->te_metric;
175 SET_SUBTLV(ext, EXT_TE_METRIC);
176 } else
177 UNSET_SUBTLV(ext, EXT_TE_METRIC);
178
179 /* TE metric extensions */
180 if (IS_PARAM_SET(ifp->link_params, LP_DELAY)) {
181 ext->delay = ifp->link_params->av_delay;
182 SET_SUBTLV(ext, EXT_DELAY);
183 } else
184 UNSET_SUBTLV(ext, EXT_DELAY);
185
186 if (IS_PARAM_SET(ifp->link_params, LP_MM_DELAY)) {
187 ext->min_delay = ifp->link_params->min_delay;
188 ext->max_delay = ifp->link_params->max_delay;
189 SET_SUBTLV(ext, EXT_MM_DELAY);
190 } else
191 UNSET_SUBTLV(ext, EXT_MM_DELAY);
192
193 if (IS_PARAM_SET(ifp->link_params, LP_DELAY_VAR)) {
194 ext->delay_var = ifp->link_params->delay_var;
195 SET_SUBTLV(ext, EXT_DELAY_VAR);
196 } else
197 UNSET_SUBTLV(ext, EXT_DELAY_VAR);
198
199 if (IS_PARAM_SET(ifp->link_params, LP_PKT_LOSS)) {
200 ext->pkt_loss = ifp->link_params->pkt_loss;
201 SET_SUBTLV(ext, EXT_PKT_LOSS);
202 } else
203 UNSET_SUBTLV(ext, EXT_PKT_LOSS);
204
205 if (IS_PARAM_SET(ifp->link_params, LP_RES_BW)) {
206 ext->res_bw = ifp->link_params->res_bw;
207 SET_SUBTLV(ext, EXT_RES_BW);
208 } else
209 UNSET_SUBTLV(ext, EXT_RES_BW);
210
211 if (IS_PARAM_SET(ifp->link_params, LP_AVA_BW)) {
212 ext->ava_bw = ifp->link_params->ava_bw;
213 SET_SUBTLV(ext, EXT_AVA_BW);
214 } else
215 UNSET_SUBTLV(ext, EXT_AVA_BW);
216
217 if (IS_PARAM_SET(ifp->link_params, LP_USE_BW)) {
218 ext->use_bw = ifp->link_params->use_bw;
219 SET_SUBTLV(ext, EXT_USE_BW);
220 } else
221 UNSET_SUBTLV(ext, EXT_USE_BW);
222
223 /* INTER_AS */
224 if (IS_PARAM_SET(ifp->link_params, LP_RMT_AS)) {
225 ext->remote_as = ifp->link_params->rmt_as;
226 ext->remote_ip = ifp->link_params->rmt_ip;
227 SET_SUBTLV(ext, EXT_RMT_AS);
228 SET_SUBTLV(ext, EXT_RMT_IP);
229 } else {
230 /* reset inter-as TE params */
231 UNSET_SUBTLV(ext, EXT_RMT_AS);
232 UNSET_SUBTLV(ext, EXT_RMT_IP);
233 }
234 zlog_debug(" |- New MPLS-TE link parameters status 0x%x",
235 ext->status);
236 } else {
237 zlog_debug(" |- Reset Extended subTLVs status 0x%x",
238 ext->status);
239 /* Reset TE subTLVs keeping SR one's */
240 if (IS_SUBTLV(ext, EXT_ADJ_SID))
241 ext->status = EXT_ADJ_SID;
242 else if (IS_SUBTLV(ext, EXT_LAN_ADJ_SID))
243 ext->status = EXT_LAN_ADJ_SID;
244 else
245 ext->status = 0;
246 }
247
248 return;
249 }
250
251 static int isis_link_update_adj_hook(struct isis_adjacency *adj)
252 {
253
254 struct isis_circuit *circuit = adj->circuit;
255
256 /* Update MPLS TE Remote IP address parameter if possible */
257 if (!IS_MPLS_TE(circuit->area->mta) || !IS_EXT_TE(circuit->ext))
258 return 0;
259
260 /* IPv4 first */
261 if (adj->ipv4_address_count > 0) {
262 IPV4_ADDR_COPY(&circuit->ext->neigh_addr,
263 &adj->ipv4_addresses[0]);
264 SET_SUBTLV(circuit->ext, EXT_NEIGH_ADDR);
265 }
266
267 /* and IPv6 */
268 if (adj->ipv6_address_count > 0) {
269 IPV6_ADDR_COPY(&circuit->ext->neigh_addr6,
270 &adj->ipv6_addresses[0]);
271 SET_SUBTLV(circuit->ext, EXT_NEIGH_ADDR6);
272 }
273
274 return 0;
275 }
276
277 int isis_mpls_te_update(struct interface *ifp)
278 {
279 struct isis_circuit *circuit;
280 uint8_t rc = 1;
281
282 /* Sanity Check */
283 if (ifp == NULL)
284 return rc;
285
286 /* Get circuit context from interface */
287 circuit = circuit_scan_by_ifp(ifp);
288 if (circuit == NULL)
289 return rc;
290
291 /* Update TE TLVs ... */
292 isis_link_params_update(circuit, ifp);
293
294 /* ... and LSP */
295 if (circuit->area && IS_MPLS_TE(circuit->area->mta))
296 lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
297
298 rc = 0;
299 return rc;
300 }
301
302 /* Followings are vty command functions */
303 #ifndef FABRICD
304
305 DEFUN (show_isis_mpls_te_router,
306 show_isis_mpls_te_router_cmd,
307 "show " PROTO_NAME " mpls-te router",
308 SHOW_STR
309 PROTO_HELP
310 MPLS_TE_STR
311 "Router information\n")
312 {
313
314 struct listnode *anode;
315 struct isis_area *area;
316
317 if (!isis) {
318 vty_out(vty, "IS-IS Routing Process not enabled\n");
319 return CMD_SUCCESS;
320 }
321
322 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
323
324 if (!IS_MPLS_TE(area->mta))
325 continue;
326
327 vty_out(vty, "Area %s:\n", area->area_tag);
328 if (ntohs(area->mta->router_id.s_addr) != 0)
329 vty_out(vty, " MPLS-TE Router-Address: %s\n",
330 inet_ntoa(area->mta->router_id));
331 else
332 vty_out(vty, " N/A\n");
333 }
334
335 return CMD_SUCCESS;
336 }
337
338 static void show_ext_sub(struct vty *vty, char *name,
339 struct isis_ext_subtlvs *ext)
340 {
341 struct sbuf buf;
342 char ibuf[PREFIX2STR_BUFFER];
343
344 sbuf_init(&buf, NULL, 0);
345
346 if (!ext || ext->status == EXT_DISABLE)
347 return;
348
349 vty_out(vty, "-- MPLS-TE link parameters for %s --\n", name);
350
351 sbuf_reset(&buf);
352
353 if (IS_SUBTLV(ext, EXT_ADM_GRP))
354 sbuf_push(&buf, 4, "Administrative Group: 0x%" PRIx32 "\n",
355 ext->adm_group);
356 if (IS_SUBTLV(ext, EXT_LLRI)) {
357 sbuf_push(&buf, 4, "Link Local ID: %" PRIu32 "\n",
358 ext->local_llri);
359 sbuf_push(&buf, 4, "Link Remote ID: %" PRIu32 "\n",
360 ext->remote_llri);
361 }
362 if (IS_SUBTLV(ext, EXT_LOCAL_ADDR))
363 sbuf_push(&buf, 4, "Local Interface IP Address(es): %s\n",
364 inet_ntoa(ext->local_addr));
365 if (IS_SUBTLV(ext, EXT_NEIGH_ADDR))
366 sbuf_push(&buf, 4, "Remote Interface IP Address(es): %s\n",
367 inet_ntoa(ext->neigh_addr));
368 if (IS_SUBTLV(ext, EXT_LOCAL_ADDR6))
369 sbuf_push(&buf, 4, "Local Interface IPv6 Address(es): %s\n",
370 inet_ntop(AF_INET6, &ext->local_addr6, ibuf,
371 PREFIX2STR_BUFFER));
372 if (IS_SUBTLV(ext, EXT_NEIGH_ADDR6))
373 sbuf_push(&buf, 4, "Remote Interface IPv6 Address(es): %s\n",
374 inet_ntop(AF_INET6, &ext->local_addr6, ibuf,
375 PREFIX2STR_BUFFER));
376 if (IS_SUBTLV(ext, EXT_MAX_BW))
377 sbuf_push(&buf, 4, "Maximum Bandwidth: %g (Bytes/sec)\n",
378 ext->max_bw);
379 if (IS_SUBTLV(ext, EXT_MAX_RSV_BW))
380 sbuf_push(&buf, 4,
381 "Maximum Reservable Bandwidth: %g (Bytes/sec)\n",
382 ext->max_rsv_bw);
383 if (IS_SUBTLV(ext, EXT_UNRSV_BW)) {
384 sbuf_push(&buf, 4, "Unreserved Bandwidth:\n");
385 for (int j = 0; j < MAX_CLASS_TYPE; j += 2) {
386 sbuf_push(&buf, 4 + 2,
387 "[%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)\n",
388 j, ext->unrsv_bw[j],
389 j + 1, ext->unrsv_bw[j + 1]);
390 }
391 }
392 if (IS_SUBTLV(ext, EXT_TE_METRIC))
393 sbuf_push(&buf, 4, "Traffic Engineering Metric: %u\n",
394 ext->te_metric);
395 if (IS_SUBTLV(ext, EXT_RMT_AS))
396 sbuf_push(&buf, 4,
397 "Inter-AS TE Remote AS number: %" PRIu32 "\n",
398 ext->remote_as);
399 if (IS_SUBTLV(ext, EXT_RMT_IP))
400 sbuf_push(&buf, 4,
401 "Inter-AS TE Remote ASBR IP address: %s\n",
402 inet_ntoa(ext->remote_ip));
403 if (IS_SUBTLV(ext, EXT_DELAY))
404 sbuf_push(&buf, 4,
405 "%s Average Link Delay: %" PRIu32 " (micro-sec)\n",
406 IS_ANORMAL(ext->delay) ? "Anomalous" : "Normal",
407 ext->delay);
408 if (IS_SUBTLV(ext, EXT_MM_DELAY)) {
409 sbuf_push(&buf, 4, "%s Min/Max Link Delay: %" PRIu32 " / %"
410 PRIu32 " (micro-sec)\n",
411 IS_ANORMAL(ext->min_delay) ? "Anomalous" : "Normal",
412 ext->min_delay & TE_EXT_MASK,
413 ext->max_delay & TE_EXT_MASK);
414 }
415 if (IS_SUBTLV(ext, EXT_DELAY_VAR))
416 sbuf_push(&buf, 4,
417 "Delay Variation: %" PRIu32 " (micro-sec)\n",
418 ext->delay_var & TE_EXT_MASK);
419 if (IS_SUBTLV(ext, EXT_PKT_LOSS))
420 sbuf_push(&buf, 4, "%s Link Packet Loss: %g (%%)\n",
421 IS_ANORMAL(ext->pkt_loss) ? "Anomalous" : "Normal",
422 (float)((ext->pkt_loss & TE_EXT_MASK)
423 * LOSS_PRECISION));
424 if (IS_SUBTLV(ext, EXT_RES_BW))
425 sbuf_push(&buf, 4,
426 "Unidirectional Residual Bandwidth: %g (Bytes/sec)\n",
427 ext->res_bw);
428 if (IS_SUBTLV(ext, EXT_AVA_BW))
429 sbuf_push(&buf, 4,
430 "Unidirectional Available Bandwidth: %g (Bytes/sec)\n",
431 ext->ava_bw);
432 if (IS_SUBTLV(ext, EXT_USE_BW))
433 sbuf_push(&buf, 4,
434 "Unidirectional Utilized Bandwidth: %g (Bytes/sec)\n",
435 ext->use_bw);
436
437 vty_multiline(vty, "", "%s", sbuf_buf(&buf));
438 vty_out(vty, "---------------\n\n");
439
440 sbuf_free(&buf);
441 return;
442 }
443
444 DEFUN (show_isis_mpls_te_interface,
445 show_isis_mpls_te_interface_cmd,
446 "show " PROTO_NAME " mpls-te interface [INTERFACE]",
447 SHOW_STR
448 PROTO_HELP
449 MPLS_TE_STR
450 "Interface information\n"
451 "Interface name\n")
452 {
453 struct listnode *anode, *cnode;
454 struct isis_area *area;
455 struct isis_circuit *circuit;
456 struct interface *ifp;
457 int idx_interface = 4;
458
459 if (!isis) {
460 vty_out(vty, "IS-IS Routing Process not enabled\n");
461 return CMD_SUCCESS;
462 }
463
464 if (argc == idx_interface) {
465 /* Show All Interfaces. */
466 for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
467
468 if (!IS_MPLS_TE(area->mta))
469 continue;
470
471 vty_out(vty, "Area %s:\n", area->area_tag);
472
473 for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode,
474 circuit))
475 show_ext_sub(vty, circuit->interface->name,
476 circuit->ext);
477 }
478 } else {
479 /* Interface name is specified. */
480 ifp = if_lookup_by_name(argv[idx_interface]->arg, VRF_DEFAULT);
481 if (ifp == NULL)
482 vty_out(vty, "No such interface name\n");
483 else {
484 circuit = circuit_scan_by_ifp(ifp);
485 if (!circuit)
486 vty_out(vty,
487 "ISIS is not enabled on circuit %s\n",
488 ifp->name);
489 else
490 show_ext_sub(vty, ifp->name, circuit->ext);
491 }
492 }
493
494 return CMD_SUCCESS;
495 }
496 #endif
497
498 /* Initialize MPLS_TE */
499 void isis_mpls_te_init(void)
500 {
501
502 /* Register Circuit and Adjacency hook */
503 hook_register(isis_if_new_hook, isis_mpls_te_update);
504 hook_register(isis_adj_state_change_hook, isis_link_update_adj_hook);
505
506
507 #ifndef FABRICD
508 /* Register new VTY commands */
509 install_element(VIEW_NODE, &show_isis_mpls_te_router_cmd);
510 install_element(VIEW_NODE, &show_isis_mpls_te_interface_cmd);
511 #endif
512
513 return;
514 }