]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_ext.c
Merge pull request #4770 from kssoman/fib
[mirror_frr.git] / ospfd / ospf_ext.c
1 /*
2 * This is an implementation of RFC7684 OSPFv2 Prefix/Link Attribute
3 * Advertisement
4 *
5 * Module name: Extended Prefix/Link Opaque LSA
6 *
7 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
8 * Author: Anselme Sawadogo <anselmesawadogo@gmail.com>
9 *
10 * Copyright (C) 2016 - 2018 Orange Labs http://www.orange.com
11 *
12 * This program 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 Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * 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 #include <stdio.h>
30 #include <stdlib.h>
31
32 #include "linklist.h"
33 #include "prefix.h"
34 #include "if.h"
35 #include "table.h"
36 #include "memory.h"
37 #include "command.h"
38 #include "vty.h"
39 #include "stream.h"
40 #include "log.h"
41 #include "thread.h"
42 #include "hash.h"
43 #include "sockunion.h" /* for inet_aton() */
44 #include "network.h"
45 #include "if.h"
46 #include "libospf.h" /* for ospf interface types */
47
48 #include "ospfd/ospfd.h"
49 #include "ospfd/ospf_interface.h"
50 #include "ospfd/ospf_ism.h"
51 #include "ospfd/ospf_asbr.h"
52 #include "ospfd/ospf_lsa.h"
53 #include "ospfd/ospf_lsdb.h"
54 #include "ospfd/ospf_neighbor.h"
55 #include "ospfd/ospf_nsm.h"
56 #include "ospfd/ospf_flood.h"
57 #include "ospfd/ospf_packet.h"
58 #include "ospfd/ospf_spf.h"
59 #include "ospfd/ospf_dump.h"
60 #include "ospfd/ospf_route.h"
61 #include "ospfd/ospf_ase.h"
62 #include "ospfd/ospf_zebra.h"
63 #include "ospfd/ospf_sr.h"
64 #include "ospfd/ospf_ext.h"
65 #include "ospfd/ospf_errors.h"
66
67 /* Following structure are internal use only. */
68
69 /*
70 * Global variable to manage Extended Prefix/Link Opaque LSA on this node.
71 * Note that all parameter values are stored in network byte order.
72 */
73 static struct ospf_ext_lp OspfEXT;
74
75 /*
76 * -----------------------------------------------------------------------
77 * Followings are initialize/terminate functions for Extended Prefix/Link
78 * Opaque LSA handling.
79 * -----------------------------------------------------------------------
80 */
81
82 /* Extended Prefix Opaque LSA related callback functions */
83 static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa);
84 static int ospf_ext_pref_lsa_originate(void *arg);
85 static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa);
86 static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
87 enum lsa_opcode opcode);
88 /* Extended Link Opaque LSA related callback functions */
89 static int ospf_ext_link_new_if(struct interface *ifp);
90 static int ospf_ext_link_del_if(struct interface *ifp);
91 static void ospf_ext_ism_change(struct ospf_interface *oi, int old_status);
92 static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status);
93 static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa);
94 static int ospf_ext_link_lsa_originate(void *arg);
95 static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa);
96 static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
97 enum lsa_opcode opcode);
98 static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op);
99 static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa);
100 static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa);
101 static void ospf_ext_link_delete_adj_sid(struct ext_itf *exti);
102 static void del_ext_info(void *val);
103
104 /*
105 * Extended Link/Prefix initialization
106 *
107 * @param - none
108 *
109 * @return - 0 if OK, <> 0 otherwise
110 */
111 int ospf_ext_init(void)
112 {
113 int rc = 0;
114
115 memset(&OspfEXT, 0, sizeof(struct ospf_ext_lp));
116 OspfEXT.enabled = false;
117 /* Only Area flooding is supported yet */
118 OspfEXT.scope = OSPF_OPAQUE_AREA_LSA;
119 /* Initialize interface list */
120 OspfEXT.iflist = list_new();
121 OspfEXT.iflist->del = del_ext_info;
122
123 zlog_info("EXT (%s): Register Extended Link Opaque LSA", __func__);
124 rc = ospf_register_opaque_functab(
125 OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_EXTENDED_LINK_LSA,
126 ospf_ext_link_new_if, /* new if */
127 ospf_ext_link_del_if, /* del if */
128 ospf_ext_ism_change, /* ism change */
129 ospf_ext_link_nsm_change, /* nsm change */
130 NULL, /* Write router config. */
131 NULL, /* Write interface conf. */
132 NULL, /* Write debug config. */
133 ospf_ext_link_show_info, /* Show LSA info */
134 ospf_ext_link_lsa_originate, /* Originate LSA */
135 ospf_ext_link_lsa_refresh, /* Refresh LSA */
136 ospf_ext_link_lsa_update, /* new_lsa_hook */
137 NULL); /* del_lsa_hook */
138
139 if (rc != 0) {
140 flog_warn(EC_OSPF_OPAQUE_REGISTRATION,
141 "EXT (%s): Failed to register Extended Link LSA",
142 __func__);
143 return rc;
144 }
145
146 zlog_info("EXT (%s): Register Extended Prefix Opaque LSA", __func__);
147 rc = ospf_register_opaque_functab(
148 OspfEXT.scope, OPAQUE_TYPE_EXTENDED_PREFIX_LSA,
149 NULL, /* new if handle by link */
150 NULL, /* del if handle by link */
151 NULL, /* ism change */
152 NULL, /* nsm change */
153 ospf_sr_config_write_router, /* Write router config. */
154 NULL, /* Write interface conf. */
155 NULL, /* Write debug config. */
156 ospf_ext_pref_show_info, /* Show LSA info */
157 ospf_ext_pref_lsa_originate, /* Originate LSA */
158 ospf_ext_pref_lsa_refresh, /* Refresh LSA */
159 ospf_ext_pref_lsa_update, /* new_lsa_hook */
160 NULL); /* del_lsa_hook */
161 if (rc != 0) {
162 flog_warn(EC_OSPF_OPAQUE_REGISTRATION,
163 "EXT (%s): Failed to register Extended Prefix LSA",
164 __func__);
165 return rc;
166 }
167
168 return rc;
169 }
170
171 /*
172 * Extended Link/Prefix termination function
173 *
174 * @param - none
175 * @return - none
176 */
177 void ospf_ext_term(void)
178 {
179
180 if ((OspfEXT.scope == OSPF_OPAQUE_AREA_LSA)
181 || (OspfEXT.scope == OSPF_OPAQUE_AS_LSA))
182 ospf_delete_opaque_functab(OspfEXT.scope,
183 OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
184
185 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA,
186 OPAQUE_TYPE_EXTENDED_LINK_LSA);
187
188 list_delete(&OspfEXT.iflist);
189 OspfEXT.scope = 0;
190 OspfEXT.enabled = false;
191
192 return;
193 }
194
195 /*
196 * Extended Link/Prefix finish function
197 *
198 * @param - none
199 * @return - none
200 */
201 void ospf_ext_finish(void)
202 {
203
204 struct listnode *node;
205 struct ext_itf *exti;
206
207 /* Flush Router Info LSA */
208 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
209 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
210 ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
211
212 OspfEXT.enabled = false;
213 }
214
215 /*
216 * ---------------------------------------------------------------------
217 * Followings are control functions for Extended Prefix/Link Opaque LSA
218 * parameters management.
219 * ---------------------------------------------------------------------
220 */
221
222 /* Functions to free memory space */
223 static void del_ext_info(void *val)
224 {
225 XFREE(MTYPE_OSPF_EXT_PARAMS, val);
226 }
227
228 /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
229 static uint32_t get_ext_pref_instance_value(void)
230 {
231 static uint32_t seqno = 0;
232
233 if (seqno < MAX_LEGAL_EXT_INSTANCE_NUM)
234 seqno += 1;
235 else
236 seqno = 1; /* Avoid zero. */
237
238 return seqno;
239 }
240
241 /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */
242 static uint32_t get_ext_link_instance_value(void)
243 {
244 static uint32_t seqno = 0;
245
246 if (seqno < MAX_LEGAL_EXT_INSTANCE_NUM)
247 seqno += 1;
248 else
249 seqno = 1; /* Avoid zero. */
250
251 return seqno;
252 }
253
254 /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
255 static struct ext_itf *lookup_ext_by_ifp(struct interface *ifp)
256 {
257 struct listnode *node, *nnode;
258 struct ext_itf *exti;
259
260 for (ALL_LIST_ELEMENTS(OspfEXT.iflist, node, nnode, exti))
261 if (exti->ifp == ifp)
262 return exti;
263
264 return NULL;
265 }
266
267 /* Lookup Extended Prefix/Links by LSA ID from OspfEXT struct iflist */
268 static struct ext_itf *lookup_ext_by_instance(struct ospf_lsa *lsa)
269 {
270 struct listnode *node;
271 struct ext_itf *exti;
272 uint32_t key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr));
273 uint8_t type = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr));
274
275
276 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
277 if ((exti->instance == key) && (exti->type == type))
278 return exti;
279
280 return NULL;
281 }
282
283 /*
284 * ----------------------------------------------------------------------
285 * The underlying subsection defines setters and unsetters to create and
286 * delete tlvs and subtlvs
287 * ----------------------------------------------------------------------
288 */
289
290 /* Extended Prefix TLV - RFC7684 section 2.1 */
291 static void set_ext_prefix(struct ext_itf *exti, uint8_t route_type,
292 uint8_t flags, struct prefix_ipv4 p)
293 {
294
295 TLV_TYPE(exti->prefix) = htons(EXT_TLV_PREFIX);
296 /* Warning: Size must be adjust depending of subTLV's */
297 TLV_LEN(exti->prefix) = htons(EXT_TLV_PREFIX_SIZE);
298 exti->prefix.route_type = route_type;
299 exti->prefix.flags = flags;
300 /* Only Address Family Ipv4 (0) is defined in RFC 7684 */
301 exti->prefix.af = 0;
302 exti->prefix.pref_length = p.prefixlen;
303 exti->prefix.address = p.prefix;
304 }
305
306 /* Extended Link TLV - RFC7684 section 3.1 */
307 static void set_ext_link(struct ext_itf *exti, uint8_t type, struct in_addr id,
308 struct in_addr data)
309 {
310
311 TLV_TYPE(exti->link) = htons(EXT_TLV_LINK);
312 /* Warning: Size must be adjust depending of subTLV's */
313 TLV_LEN(exti->link) = htons(EXT_TLV_LINK_SIZE);
314 exti->link.link_type = type;
315 exti->link.link_id = id;
316 exti->link.link_data = data;
317 }
318
319 /* Prefix SID SubTLV - section 5 */
320 static void set_prefix_sid(struct ext_itf *exti, uint8_t algorithm,
321 uint32_t value, int value_type, uint8_t flags)
322 {
323
324 if ((algorithm != SR_ALGORITHM_SPF)
325 && (algorithm != SR_ALGORITHM_STRICT_SPF)) {
326 flog_err(EC_OSPF_INVALID_ALGORITHM,
327 "EXT (%s): unrecognized algorithm, not SPF or S-SPF",
328 __func__);
329 return;
330 }
331
332 /* Update flags according to the type of value field: label or index */
333 if (value_type == SID_LABEL)
334 SET_FLAG(flags, EXT_SUBTLV_PREFIX_SID_VFLG);
335
336 /* set prefix sid subtlv for an extended prefix tlv */
337 TLV_TYPE(exti->node_sid) = htons(EXT_SUBTLV_PREFIX_SID);
338 exti->node_sid.algorithm = algorithm;
339 exti->node_sid.flags = flags;
340 exti->node_sid.mtid = 0; /* Multi-Topology is not supported */
341
342 /* Set Label or Index value */
343 if (value_type == SID_LABEL) {
344 TLV_LEN(exti->node_sid) =
345 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE));
346 exti->node_sid.value = htonl(SET_LABEL(value));
347 } else {
348 TLV_LEN(exti->node_sid) =
349 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE));
350 exti->node_sid.value = htonl(value);
351 }
352 }
353
354 /* Adjacency SID SubTLV - section 6.1 */
355 static void set_adj_sid(struct ext_itf *exti, bool backup, uint32_t value,
356 int value_type)
357 {
358 int index;
359 uint8_t flags;
360
361 /* Determine which ADJ_SID must be set: nominal or backup */
362 if (backup) {
363 flags = EXT_SUBTLV_LINK_ADJ_SID_BFLG;
364 index = 1;
365 } else {
366 index = 0;
367 flags = 0;
368 }
369
370 /* Set Header */
371 TLV_TYPE(exti->adj_sid[index]) = htons(EXT_SUBTLV_ADJ_SID);
372
373 /* Only Local ADJ-SID is supported for the moment */
374 SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_LFLG);
375
376 exti->adj_sid[index].mtid = 0; /* Multi-Topology is not supported */
377
378 /* Adjust Length, Flags and Value depending on the type of Label */
379 if (value_type == SID_LABEL) {
380 SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
381 TLV_LEN(exti->adj_sid[index]) =
382 htons(SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE));
383 exti->adj_sid[index].value = htonl(SET_LABEL(value));
384 } else {
385 UNSET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
386 TLV_LEN(exti->adj_sid[index]) =
387 htons(SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE));
388 exti->adj_sid[index].value = htonl(value);
389 }
390
391 exti->adj_sid[index].flags = flags; /* Set computed flags */
392 exti->adj_sid[index].mtid = 0; /* Multi-Topology is not supported */
393 exti->adj_sid[index].weight = 0; /* Load-Balancing is not supported */
394 }
395
396 /* LAN Adjacency SID SubTLV - section 6.2 */
397 static void set_lan_adj_sid(struct ext_itf *exti, bool backup, uint32_t value,
398 int value_type, struct in_addr neighbor_id)
399 {
400
401 int index;
402 uint8_t flags;
403
404 /* Determine which ADJ_SID must be set: nominal or backup */
405 if (backup) {
406 flags = EXT_SUBTLV_LINK_ADJ_SID_BFLG;
407 index = 1;
408 } else {
409 index = 0;
410 flags = 0;
411 }
412
413 /* Set Header */
414 TLV_TYPE(exti->lan_sid[index]) = htons(EXT_SUBTLV_LAN_ADJ_SID);
415
416 /* Only Local ADJ-SID is supported for the moment */
417 SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_LFLG);
418
419 /* Adjust Length, Flags and Value depending on the type of Label */
420 if (value_type == SID_LABEL) {
421 SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
422 TLV_LEN(exti->lan_sid[index]) =
423 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE));
424 exti->lan_sid[index].value = htonl(SET_LABEL(value));
425 } else {
426 UNSET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
427 TLV_LEN(exti->lan_sid[index]) =
428 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE));
429 exti->lan_sid[index].value = htonl(value);
430 }
431
432 exti->lan_sid[index].flags = flags; /* Set computed flags */
433 exti->lan_sid[index].mtid = 0; /* Multi-Topology is not supported */
434 exti->lan_sid[index].weight = 0; /* Load-Balancing is not supported */
435 exti->lan_sid[index].neighbor_id = neighbor_id;
436 }
437
438 static void unset_adjacency_sid(struct ext_itf *exti)
439 {
440 /* Reset Adjacency TLV */
441 if (exti->type == ADJ_SID) {
442 TLV_TYPE(exti->adj_sid[0]) = 0;
443 TLV_TYPE(exti->adj_sid[1]) = 0;
444 }
445 /* or Lan-Adjacency TLV */
446 if (exti->type == LAN_ADJ_SID) {
447 TLV_TYPE(exti->lan_sid[0]) = 0;
448 TLV_TYPE(exti->lan_sid[1]) = 0;
449 }
450 }
451
452 /* Experimental SubTLV from Cisco */
453 static void set_rmt_itf_addr(struct ext_itf *exti, struct in_addr rmtif)
454 {
455
456 TLV_TYPE(exti->rmt_itf_addr) = htons(EXT_SUBTLV_RMT_ITF_ADDR);
457 TLV_LEN(exti->rmt_itf_addr) = htons(sizeof(struct in_addr));
458 exti->rmt_itf_addr.value = rmtif;
459 }
460
461 /* Delete Extended LSA */
462 static void ospf_extended_lsa_delete(struct ext_itf *exti)
463 {
464
465 /* Avoid deleting LSA if Extended is not enable */
466 if (!OspfEXT.enabled)
467 return;
468
469 /* Process only Active Extended Prefix/Link LSA */
470 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
471 return;
472
473 osr_debug("EXT (%s): Disable %s%s%s-SID on interface %s", __func__,
474 exti->stype == LOCAL_SID ? "Prefix" : "",
475 exti->stype == ADJ_SID ? "Adjacency" : "",
476 exti->stype == LAN_ADJ_SID ? "LAN-Adjacency" : "",
477 exti->ifp->name);
478
479 /* Flush LSA if already engaged */
480 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
481 ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
482 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
483 }
484
485 /* De-activate this Extended Prefix/Link and remove corresponding
486 * Segment-Routing Prefix-SID or (LAN)-ADJ-SID */
487 if (exti->stype == ADJ_SID || exti->stype == LAN_ADJ_SID)
488 ospf_ext_link_delete_adj_sid(exti);
489 else
490 ospf_sr_ext_itf_delete(exti);
491 }
492
493 /*
494 * Update Extended prefix SID index for Loopback interface type
495 *
496 * @param ifname - Loopback interface name
497 * @param index - new value for the prefix SID of this interface
498 * @param p - prefix for this interface or NULL if Extended Prefix
499 * should be remove
500 *
501 * @return instance number if update is OK, 0 otherwise
502 */
503 uint32_t ospf_ext_schedule_prefix_index(struct interface *ifp, uint32_t index,
504 struct prefix_ipv4 *p, uint8_t flags)
505 {
506 int rc = 0;
507 struct ext_itf *exti;
508
509 /* Find Extended Prefix interface */
510 exti = lookup_ext_by_ifp(ifp);
511 if (exti == NULL)
512 return rc;
513
514 if (p != NULL) {
515 osr_debug("EXT (%s): Schedule new prefix %pFX with index %u on interface %s", __func__, p, index, ifp->name);
516
517 /* Set first Extended Prefix then the Prefix SID information */
518 set_ext_prefix(exti, OSPF_PATH_INTRA_AREA, EXT_TLV_PREF_NFLG,
519 *p);
520 set_prefix_sid(exti, SR_ALGORITHM_SPF, index, SID_INDEX, flags);
521
522 /* Try to Schedule LSA */
523 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
524 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
525 ospf_ext_pref_lsa_schedule(exti,
526 REFRESH_THIS_LSA);
527 else
528 ospf_ext_pref_lsa_schedule(
529 exti, REORIGINATE_THIS_LSA);
530 }
531 } else {
532 osr_debug("EXT (%s): Remove prefix for interface %s", __func__,
533 ifp->name);
534
535 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
536 ospf_ext_pref_lsa_schedule(exti, FLUSH_THIS_LSA);
537 }
538
539 return SET_OPAQUE_LSID(exti->type, exti->instance);
540 }
541
542 /**
543 * Update Adjacecny-SID for Extended Link LSA
544 *
545 * @param exti Extended Link information
546 */
547 static void ospf_ext_link_update_adj_sid(struct ext_itf *exti)
548 {
549 mpls_label_t label;
550 mpls_label_t bck_label;
551
552 /* Process only (LAN)Adjacency-SID Type */
553 if (exti->stype != ADJ_SID && exti->stype != LAN_ADJ_SID)
554 return;
555
556 /* Request Primary & Backup Labels from Label Manager */
557 bck_label = ospf_sr_local_block_request_label();
558 label = ospf_sr_local_block_request_label();
559 if (bck_label == MPLS_INVALID_LABEL || label == MPLS_INVALID_LABEL) {
560 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
561 ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
562 return;
563 }
564
565 /* Set Adjacency-SID, backup first */
566 if (exti->stype == ADJ_SID) {
567 set_adj_sid(exti, true, bck_label, SID_LABEL);
568 set_adj_sid(exti, false, label, SID_LABEL);
569 } else {
570 set_lan_adj_sid(exti, true, bck_label, SID_LABEL,
571 exti->lan_sid[0].neighbor_id);
572 set_lan_adj_sid(exti, false, label, SID_LABEL,
573 exti->lan_sid[1].neighbor_id);
574 }
575
576 /* Finally, add corresponding SR Link in SRDB & MPLS LFIB */
577 SET_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET);
578 ospf_sr_ext_itf_add(exti);
579 }
580
581 /**
582 * Delete Adjacecny-SID for Extended Link LSA
583 *
584 * @param exti Extended Link information
585 */
586 static void ospf_ext_link_delete_adj_sid(struct ext_itf *exti)
587 {
588 /* Process only (LAN)Adjacency-SID Type */
589 if (exti->stype != ADJ_SID && exti->stype != LAN_ADJ_SID)
590 return;
591
592 /* Release Primary & Backup Labels from Label Manager */
593 if (exti->stype == ADJ_SID) {
594 ospf_sr_local_block_release_label(exti->adj_sid[0].value);
595 ospf_sr_local_block_release_label(exti->adj_sid[1].value);
596 } else {
597 ospf_sr_local_block_release_label(exti->lan_sid[0].value);
598 ospf_sr_local_block_release_label(exti->lan_sid[1].value);
599 }
600 /* And reset corresponding TLV */
601 unset_adjacency_sid(exti);
602
603 /* Finally, remove corresponding SR Link in SRDB & MPLS LFIB */
604 UNSET_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET);
605 ospf_sr_ext_itf_delete(exti);
606 }
607
608 /**
609 * Update Extended Link LSA once Segment Routing Label Block has been changed.
610 */
611 void ospf_ext_link_srlb_update(void)
612 {
613 struct listnode *node;
614 struct ext_itf *exti;
615
616
617 osr_debug("EXT (%s): Update Extended Links with new SRLB", __func__);
618
619 /* Update all Extended Link Adjaceny-SID */
620 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
621 /* Skip Extended Prefix */
622 if (exti->stype == PREF_SID || exti->stype == LOCAL_SID)
623 continue;
624
625 /* Skip inactive Extended Link */
626 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
627 continue;
628
629 ospf_ext_link_update_adj_sid(exti);
630 }
631 }
632
633 /*
634 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
635 *
636 * @param enable To activate or not Segment Routing Extended LSA flooding
637 *
638 * @return none
639 */
640 void ospf_ext_update_sr(bool enable)
641 {
642 struct listnode *node;
643 struct ext_itf *exti;
644
645 osr_debug("EXT (%s): %s Extended LSAs for Segment Routing ", __func__,
646 enable ? "Enable" : "Disable");
647
648 if (enable) {
649 OspfEXT.enabled = true;
650
651 /* Refresh LSAs if already engaged or originate */
652 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
653 /* Skip Inactive Extended Link */
654 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
655 continue;
656
657 /* Update Extended Link (LAN)Adj-SID if not set */
658 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET))
659 ospf_ext_link_update_adj_sid(exti);
660
661 /* Finally, flood the extended Link */
662 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
663 ospf_ext_lsa_schedule(exti, REFRESH_THIS_LSA);
664 else
665 ospf_ext_lsa_schedule(exti,
666 REORIGINATE_THIS_LSA);
667 }
668 } else {
669 /* Start by Removing Extended LSA */
670 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
671 ospf_extended_lsa_delete(exti);
672
673 /* And then disable Extended Link/Prefix */
674 OspfEXT.enabled = false;
675 }
676 }
677
678 /*
679 * -----------------------------------------------------------------------
680 * Followings are callback functions against generic Opaque-LSAs handling
681 * -----------------------------------------------------------------------
682 */
683
684 /* Add new Interface in Extended Interface List */
685 static int ospf_ext_link_new_if(struct interface *ifp)
686 {
687 struct ext_itf *new;
688 int rc = -1;
689
690 if (lookup_ext_by_ifp(ifp) != NULL) {
691 rc = 0; /* Do nothing here. */
692 return rc;
693 }
694
695 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf));
696
697 /* initialize new information and link back the interface */
698 new->ifp = ifp;
699 new->flags = EXT_LPFLG_LSA_INACTIVE;
700
701 listnode_add(OspfEXT.iflist, new);
702
703 rc = 0;
704 return rc;
705 }
706
707 /* Remove existing Interface from Extended Interface List */
708 static int ospf_ext_link_del_if(struct interface *ifp)
709 {
710 struct ext_itf *exti;
711 int rc = -1;
712
713 exti = lookup_ext_by_ifp(ifp);
714 if (exti != NULL) {
715 /* Flush LSA and remove Adjacency SID */
716 ospf_extended_lsa_delete(exti);
717
718 /* Dequeue listnode entry from the list. */
719 listnode_delete(OspfEXT.iflist, exti);
720
721 XFREE(MTYPE_OSPF_EXT_PARAMS, exti);
722
723 rc = 0;
724 } else {
725 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
726 "EXT (%s): interface %s is not found", __func__,
727 ifp ? ifp->name : "-");
728 }
729
730 return rc;
731 }
732
733 /*
734 * Determine if an Interface belongs to an Extended Link Adjacency or
735 * Extended Prefix SID type and allocate new instance value accordingly
736 */
737 static void ospf_ext_ism_change(struct ospf_interface *oi, int old_status)
738 {
739 struct ext_itf *exti;
740
741 /* Get interface information for Segment Routing */
742 exti = lookup_ext_by_ifp(oi->ifp);
743 if (exti == NULL) {
744 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
745 "EXT (%s): Cannot get Extended info. from OI(%s)",
746 __func__, IF_NAME(oi));
747 return;
748 }
749
750 /* Reset Extended information if ospf interface goes Down */
751 if (oi->state == ISM_Down) {
752 ospf_extended_lsa_delete(exti);
753 exti->area = NULL;
754 exti->flags = EXT_LPFLG_LSA_INACTIVE;
755 return;
756 }
757
758 /* Determine if interface is related to a Prefix or an Adjacency SID */
759 if (oi->type == OSPF_IFTYPE_LOOPBACK) {
760 exti->stype = PREF_SID;
761 exti->type = OPAQUE_TYPE_EXTENDED_PREFIX_LSA;
762 exti->instance = get_ext_pref_instance_value();
763 exti->area = oi->area;
764
765 /* Complete SRDB if the interface belongs to a Prefix */
766 if (OspfEXT.enabled) {
767 osr_debug("EXT (%s): Set Prefix SID to interface %s ",
768 __func__, oi->ifp->name);
769 exti->flags = EXT_LPFLG_LSA_ACTIVE;
770 ospf_sr_update_local_prefix(oi->ifp, oi->address);
771 }
772 } else {
773 /* Determine if interface is related to Adj. or LAN Adj. SID */
774 if (oi->state == ISM_DR)
775 exti->stype = LAN_ADJ_SID;
776 else
777 exti->stype = ADJ_SID;
778
779 exti->type = OPAQUE_TYPE_EXTENDED_LINK_LSA;
780 exti->instance = get_ext_link_instance_value();
781 exti->area = oi->area;
782
783 /*
784 * Note: Adjacency SID information are completed when ospf
785 * adjacency become up see ospf_ext_link_nsm_change()
786 */
787 if (OspfEXT.enabled)
788 osr_debug(
789 "EXT (%s): Set %sAdjacency SID for interface %s ",
790 __func__, exti->stype == ADJ_SID ? "" : "LAN-",
791 oi->ifp->name);
792 }
793 }
794
795 /*
796 * Finish Extended Link configuration and flood corresponding LSA
797 * when OSPF adjacency on this link fire up
798 */
799 static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
800 {
801 struct ospf_interface *oi = nbr->oi;
802 struct ext_itf *exti;
803
804 /* Process Link only when neighbor old or new state is NSM Full */
805 if (nbr->state != NSM_Full && old_status != NSM_Full)
806 return;
807
808 /* Get interface information for Segment Routing */
809 exti = lookup_ext_by_ifp(oi->ifp);
810 if (exti == NULL) {
811 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
812 "EXT (%s): Cannot get Extended info. from OI(%s)",
813 __func__, IF_NAME(oi));
814 return;
815 }
816
817 /* Check that we have a valid area and ospf context */
818 if (oi->area == NULL || oi->area->ospf == NULL) {
819 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
820 "EXT (%s): Cannot refer to OSPF from OI(%s)",
821 __func__, IF_NAME(oi));
822 return;
823 }
824
825 /* Remove Extended Link if Neighbor State goes Down or Deleted */
826 if (OspfEXT.enabled
827 && (nbr->state == NSM_Down || nbr->state == NSM_Deleted)) {
828 ospf_ext_link_delete_adj_sid(exti);
829 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
830 ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA);
831 exti->flags = EXT_LPFLG_LSA_INACTIVE;
832 return;
833 }
834
835 /* Keep Area information in combination with SR info. */
836 exti->area = oi->area;
837
838 /* Process only Adjacency/LAN SID */
839 if (exti->stype == PREF_SID)
840 return;
841
842 switch (oi->state) {
843 case ISM_PointToPoint:
844 /* Segment ID is an Adjacency one */
845 exti->stype = ADJ_SID;
846
847 /* Set Extended Link TLV with link_id == Nbr Router ID */
848 set_ext_link(exti, OSPF_IFTYPE_POINTOPOINT, nbr->router_id,
849 oi->address->u.prefix4);
850
851 /* And Remote Interface address */
852 set_rmt_itf_addr(exti, nbr->address.u.prefix4);
853
854 break;
855
856 case ISM_DR:
857 /* Segment ID is a LAN Adjacency for the DR only */
858 exti->stype = LAN_ADJ_SID;
859
860 /* Set Extended Link TLV with link_id == DR */
861 set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
862 oi->address->u.prefix4);
863
864 /* Set Neighbor ID */
865 exti->lan_sid[0].neighbor_id = nbr->router_id;
866 exti->lan_sid[1].neighbor_id = nbr->router_id;
867
868 break;
869
870 case ISM_DROther:
871 case ISM_Backup:
872 /* Segment ID is an Adjacency if not the DR */
873 exti->stype = ADJ_SID;
874
875 /* Set Extended Link TLV with link_id == DR */
876 set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
877 oi->address->u.prefix4);
878
879 break;
880
881 default:
882 if (CHECK_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET))
883 ospf_ext_link_delete_adj_sid(exti);
884 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
885 ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA);
886 exti->flags = EXT_LPFLG_LSA_INACTIVE;
887 return;
888 }
889
890 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
891
892 if (OspfEXT.enabled) {
893 osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
894 __func__, exti->stype == ADJ_SID ? "" : "LAN-",
895 oi->ifp->name);
896
897 /* Update (LAN)Adjacency SID */
898 ospf_ext_link_update_adj_sid(exti);
899
900 /* flood this links params if everything is ok */
901 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
902 ospf_ext_link_lsa_schedule(exti, REFRESH_THIS_LSA);
903 else
904 ospf_ext_link_lsa_schedule(exti, REORIGINATE_THIS_LSA);
905 }
906 }
907
908 /* Callbacks to handle Extended Link Segment Routing LSA information */
909 static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa)
910 {
911 /* Sanity Check */
912 if (lsa == NULL) {
913 flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL",
914 __func__);
915 return -1;
916 }
917
918 /* Process only Opaque LSA */
919 if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA)
920 && (lsa->data->type != OSPF_OPAQUE_AS_LSA))
921 return 0;
922
923 /* Process only Extended Link LSA */
924 if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr))
925 != OPAQUE_TYPE_EXTENDED_LINK_LSA)
926 return 0;
927
928 /* Check if it is not my LSA */
929 if (IS_LSA_SELF(lsa))
930 return 0;
931
932 /* Check if Extended is enable */
933 if (!OspfEXT.enabled)
934 return 0;
935
936 /* Call Segment Routing LSA update or deletion */
937 if (!IS_LSA_MAXAGE(lsa))
938 ospf_sr_ext_link_lsa_update(lsa);
939 else
940 ospf_sr_ext_link_lsa_delete(lsa);
941
942 return 0;
943 }
944
945 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
946 static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa)
947 {
948
949 /* Sanity Check */
950 if (lsa == NULL) {
951 flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL",
952 __func__);
953 return -1;
954 }
955
956 /* Process only Opaque LSA */
957 if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA)
958 && (lsa->data->type != OSPF_OPAQUE_AS_LSA))
959 return 0;
960
961 /* Process only Extended Prefix LSA */
962 if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr))
963 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA)
964 return 0;
965
966 /* Check if it is not my LSA */
967 if (IS_LSA_SELF(lsa))
968 return 0;
969
970 /* Check if Extended is enable */
971 if (!OspfEXT.enabled)
972 return 0;
973
974 /* Call Segment Routing LSA update or deletion */
975 if (!IS_LSA_MAXAGE(lsa))
976 ospf_sr_ext_prefix_lsa_update(lsa);
977 else
978 ospf_sr_ext_prefix_lsa_delete(lsa);
979
980 return 0;
981 }
982
983 /*
984 * -------------------------------------------------------
985 * Followings are OSPF protocol processing functions for
986 * Extended Prefix/Link Opaque LSA
987 * -------------------------------------------------------
988 */
989
990 static void build_tlv_header(struct stream *s, struct tlv_header *tlvh)
991 {
992 stream_put(s, tlvh, sizeof(struct tlv_header));
993 }
994
995 static void build_tlv(struct stream *s, struct tlv_header *tlvh)
996 {
997
998 if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) {
999 build_tlv_header(s, tlvh);
1000 stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
1001 }
1002 }
1003
1004 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
1005 static void ospf_ext_pref_lsa_body_set(struct stream *s, struct ext_itf *exti)
1006 {
1007
1008 /* Sanity check */
1009 if ((exti == NULL) || (exti->stype != PREF_SID))
1010 return;
1011
1012 /* Adjust Extended Prefix TLV size */
1013 TLV_LEN(exti->prefix) = htons(ntohs(TLV_LEN(exti->node_sid))
1014 + EXT_TLV_PREFIX_SIZE + TLV_HDR_SIZE);
1015
1016 /* Build LSA body for an Extended Prefix TLV */
1017 build_tlv_header(s, &exti->prefix.header);
1018 stream_put(s, TLV_DATA(&exti->prefix.header), EXT_TLV_PREFIX_SIZE);
1019 /* Then add Prefix SID SubTLV */
1020 build_tlv(s, &exti->node_sid.header);
1021 }
1022
1023 /* Build an Extended Link Opaque LSA body for extended link TLV */
1024 static void ospf_ext_link_lsa_body_set(struct stream *s, struct ext_itf *exti)
1025 {
1026 size_t size;
1027
1028 /* Sanity check */
1029 if ((exti == NULL)
1030 || ((exti->stype != ADJ_SID) && (exti->stype != LAN_ADJ_SID)))
1031 return;
1032
1033 if (exti->stype == ADJ_SID) {
1034 /* Adjust Extended Link TLV size for Adj. SID */
1035 size = EXT_TLV_LINK_SIZE + 2 * EXT_SUBTLV_ADJ_SID_SIZE
1036 + 2 * TLV_HDR_SIZE;
1037 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
1038 size = size + EXT_SUBTLV_RMT_ITF_ADDR_SIZE
1039 + TLV_HDR_SIZE;
1040 TLV_LEN(exti->link) = htons(size);
1041
1042 /* Build LSA body for an Extended Link TLV with Adj. SID */
1043 build_tlv_header(s, &exti->link.header);
1044 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
1045 /* then add Adjacency SubTLVs */
1046 build_tlv(s, &exti->adj_sid[1].header);
1047 build_tlv(s, &exti->adj_sid[0].header);
1048
1049 /* Add Cisco experimental SubTLV if interface is PtoP */
1050 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
1051 build_tlv(s, &exti->rmt_itf_addr.header);
1052 } else {
1053 /* Adjust Extended Link TLV size for LAN SID */
1054 size = EXT_TLV_LINK_SIZE
1055 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE + TLV_HDR_SIZE);
1056 TLV_LEN(exti->link) = htons(size);
1057
1058 /* Build LSA body for an Extended Link TLV with LAN SID */
1059 build_tlv_header(s, &exti->link.header);
1060 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
1061 /* then add LAN-Adjacency SubTLVs */
1062 build_tlv(s, &exti->lan_sid[1].header);
1063 build_tlv(s, &exti->lan_sid[0].header);
1064 }
1065 }
1066
1067 /* Create new Extended Prefix opaque-LSA for every extended prefix */
1068 static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area,
1069 struct ext_itf *exti)
1070 {
1071 struct stream *s;
1072 struct lsa_header *lsah;
1073 struct ospf_lsa *new = NULL;
1074 struct ospf *top;
1075 uint8_t options, lsa_type;
1076 struct in_addr lsa_id;
1077 struct in_addr router_id;
1078 uint32_t tmp;
1079 uint16_t length;
1080
1081 /* Sanity Check */
1082 if (exti == NULL)
1083 return NULL;
1084
1085 /* Create a stream for LSA. */
1086 s = stream_new(OSPF_MAX_LSA_SIZE);
1087
1088 /* Prepare LSA Header */
1089 lsah = (struct lsa_header *)STREAM_DATA(s);
1090
1091 lsa_type = OspfEXT.scope;
1092
1093 /*
1094 * LSA ID is a variable number identifying different instances of
1095 * Extended Prefix Opaque LSA from the same router see RFC 7684
1096 */
1097 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
1098 lsa_id.s_addr = htonl(tmp);
1099
1100 options = OSPF_OPTION_O; /* Don't forget this :-) */
1101
1102 /* Fix Options and Router ID depending of the flooding scope */
1103 if ((OspfEXT.scope == OSPF_OPAQUE_AS_LSA) || (area == NULL)) {
1104 options = OSPF_OPTION_E;
1105 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1106 router_id.s_addr = top ? top->router_id.s_addr : 0;
1107 } else {
1108 options |= LSA_OPTIONS_GET(area); /* Get area default option */
1109 options |= LSA_OPTIONS_NSSA_GET(area);
1110 router_id = area->ospf->router_id;
1111 }
1112
1113 /* Set opaque-LSA header fields. */
1114 lsa_header_set(s, options, lsa_type, lsa_id, router_id);
1115
1116 osr_debug(
1117 "EXT (%s): LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Prefix Opaque LSA instance",
1118 __func__, lsa_type, &lsa_id);
1119
1120 /* Set opaque-LSA body fields. */
1121 ospf_ext_pref_lsa_body_set(s, exti);
1122
1123 /* Set length. */
1124 length = stream_get_endp(s);
1125 lsah->length = htons(length);
1126
1127 /* Now, create an OSPF LSA instance. */
1128 new = ospf_lsa_new_and_data(length);
1129
1130 /* Segment Routing belongs only to default VRF */
1131 new->vrf_id = VRF_DEFAULT;
1132 new->area = area;
1133 SET_FLAG(new->flags, OSPF_LSA_SELF);
1134 memcpy(new->data, lsah, length);
1135 stream_free(s);
1136
1137 return new;
1138 }
1139
1140 /* Create new Extended Link opaque-LSA for every extended link TLV */
1141 static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area,
1142 struct ext_itf *exti)
1143 {
1144 struct stream *s;
1145 struct lsa_header *lsah;
1146 struct ospf_lsa *new = NULL;
1147 uint8_t options, lsa_type;
1148 struct in_addr lsa_id;
1149 uint32_t tmp;
1150 uint16_t length;
1151
1152 /* Sanity Check */
1153 if (exti == NULL)
1154 return NULL;
1155
1156 /* Create a stream for LSA. */
1157 s = stream_new(OSPF_MAX_LSA_SIZE);
1158 lsah = (struct lsa_header *)STREAM_DATA(s);
1159
1160 options = OSPF_OPTION_O; /* Don't forget this :-) */
1161 options |= LSA_OPTIONS_GET(area); /* Get area default option */
1162 options |= LSA_OPTIONS_NSSA_GET(area);
1163 /* Extended Link Opaque LSA are only flooded within an area */
1164 lsa_type = OSPF_OPAQUE_AREA_LSA;
1165
1166 /*
1167 * LSA ID is a variable number identifying different instances of
1168 * Extended Link Opaque LSA from the same router see RFC 7684
1169 */
1170 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1171 lsa_id.s_addr = htonl(tmp);
1172
1173 osr_debug(
1174 "EXT (%s) LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Link Opaque LSA instance",
1175 __func__, lsa_type, &lsa_id);
1176
1177 /* Set opaque-LSA header fields. */
1178 lsa_header_set(s, options, lsa_type, lsa_id, area->ospf->router_id);
1179
1180 /* Set opaque-LSA body fields. */
1181 ospf_ext_link_lsa_body_set(s, exti);
1182
1183 /* Set length. */
1184 length = stream_get_endp(s);
1185 lsah->length = htons(length);
1186
1187 /* Now, create an OSPF LSA instance. */
1188 new = ospf_lsa_new_and_data(length);
1189
1190 /* Segment Routing belongs only to default VRF */
1191 new->vrf_id = VRF_DEFAULT;
1192 new->area = area;
1193 SET_FLAG(new->flags, OSPF_LSA_SELF);
1194 memcpy(new->data, lsah, length);
1195 stream_free(s);
1196
1197 return new;
1198 }
1199
1200 /*
1201 * Process the origination of an Extended Prefix Opaque LSA
1202 * for every extended prefix TLV
1203 */
1204 static int ospf_ext_pref_lsa_originate1(struct ospf_area *area,
1205 struct ext_itf *exti)
1206 {
1207 struct ospf_lsa *new;
1208 int rc = -1;
1209
1210
1211 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1212 new = ospf_ext_pref_lsa_new(area, exti);
1213 if (new == NULL) {
1214 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1215 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
1216 return rc;
1217 }
1218
1219 /* Install this LSA into LSDB. */
1220 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
1221 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1222 "EXT (%s): ospf_lsa_install() error", __func__);
1223 ospf_lsa_unlock(&new);
1224 return rc;
1225 }
1226
1227 /* Now this Extended Prefix Opaque LSA info parameter entry has
1228 * associated LSA.
1229 */
1230 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1231
1232 /* Update new LSA origination count. */
1233 area->ospf->lsa_originate_count++;
1234
1235 /* Flood new LSA through area. */
1236 ospf_flood_through_area(area, NULL /*nbr */, new);
1237
1238 osr_debug(
1239 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSAExtended Prefix Opaque LSA: Area(%pI4), Link(%s)",
1240 __func__, new->data->type, &new->data->id,
1241 &area->area_id, exti->ifp->name);
1242 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1243 ospf_lsa_header_dump(new->data);
1244
1245 rc = 0;
1246
1247 return rc;
1248 }
1249
1250 /*
1251 * Process the origination of an Extended Link Opaque LSA
1252 * for every extended link TLV
1253 */
1254 static int ospf_ext_link_lsa_originate1(struct ospf_area *area,
1255 struct ext_itf *exti)
1256 {
1257 struct ospf_lsa *new;
1258 int rc = -1;
1259
1260 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1261 new = ospf_ext_link_lsa_new(area, exti);
1262 if (new == NULL) {
1263 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1264 "EXT (%s): ospf_ext_link_lsa_new() error", __func__);
1265 return rc;
1266 }
1267
1268 /* Install this LSA into LSDB. */
1269 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
1270 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1271 "EXT (%s): ospf_lsa_install() error", __func__);
1272 ospf_lsa_unlock(&new);
1273 return rc;
1274 }
1275
1276 /* Now this link-parameter entry has associated LSA. */
1277 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1278
1279 /* Update new LSA origination count. */
1280 area->ospf->lsa_originate_count++;
1281
1282 /* Flood new LSA through area. */
1283 ospf_flood_through_area(area, NULL /*nbr */, new);
1284
1285 osr_debug(
1286 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSA Extended Link Opaque LSA: Area(%pI4), Link(%s)",
1287 __func__, new->data->type, &new->data->id,
1288 &area->area_id, exti->ifp->name);
1289 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1290 ospf_lsa_header_dump(new->data);
1291
1292 rc = 0;
1293
1294 return rc;
1295 }
1296
1297 /* Trigger the origination of Extended Prefix Opaque LSAs */
1298 static int ospf_ext_pref_lsa_originate(void *arg)
1299 {
1300 struct ospf_area *area = (struct ospf_area *)arg;
1301 struct listnode *node;
1302 struct ext_itf *exti;
1303 int rc = -1;
1304
1305 if (!OspfEXT.enabled) {
1306 zlog_info(
1307 "EXT (%s): Segment Routing functionality is Disabled now",
1308 __func__);
1309 rc = 0; /* This is not an error case. */
1310 return rc;
1311 }
1312 osr_debug("EXT (%s): Start Originate Prefix LSA for area %pI4",
1313 __func__, &area->area_id);
1314
1315 /* Check if Extended Prefix Opaque LSA is already engaged */
1316 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1317
1318 /* Process only Prefix SID */
1319 if (exti->stype != PREF_SID)
1320 continue;
1321
1322 /* Process only Extended Prefix with valid Area ID */
1323 if ((exti->area == NULL)
1324 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1325 continue;
1326
1327 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1328 if (CHECK_FLAG(exti->flags,
1329 EXT_LPFLG_LSA_FORCED_REFRESH)) {
1330 flog_warn(
1331 EC_OSPF_EXT_LSA_UNEXPECTED,
1332 "EXT (%s): Refresh instead of Originate",
1333 __func__);
1334 UNSET_FLAG(exti->flags,
1335 EXT_LPFLG_LSA_FORCED_REFRESH);
1336 ospf_ext_pref_lsa_schedule(exti,
1337 REFRESH_THIS_LSA);
1338 }
1339 continue;
1340 }
1341
1342 /* Ok, let's try to originate an LSA */
1343 osr_debug(
1344 "EXT (%s): Let's finally re-originate the LSA 7.0.0.%u for Itf %s", __func__, exti->instance,
1345 exti->ifp ? exti->ifp->name : "");
1346 ospf_ext_pref_lsa_originate1(area, exti);
1347 }
1348
1349 rc = 0;
1350 return rc;
1351 }
1352
1353 /* Trigger the origination of Extended Link Opaque LSAs */
1354 static int ospf_ext_link_lsa_originate(void *arg)
1355 {
1356 struct ospf_area *area = (struct ospf_area *)arg;
1357 struct listnode *node;
1358 struct ext_itf *exti;
1359 int rc = -1;
1360
1361 if (!OspfEXT.enabled) {
1362 zlog_info(
1363 "EXT (%s): Segment Routing functionality is Disabled now",
1364 __func__);
1365 rc = 0; /* This is not an error case. */
1366 return rc;
1367 }
1368
1369 /* Check if Extended Prefix Opaque LSA is already engaged */
1370 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1371 /* Process only Adjacency or LAN SID */
1372 if (exti->stype == PREF_SID)
1373 continue;
1374
1375 /* Skip Inactive Extended Link */
1376 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
1377 continue;
1378
1379 /* Process only Extended Link with valid Area ID */
1380 if ((exti->area == NULL)
1381 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1382 continue;
1383
1384 /* Check if LSA not already engaged */
1385 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1386 if (CHECK_FLAG(exti->flags,
1387 EXT_LPFLG_LSA_FORCED_REFRESH)) {
1388 flog_warn(
1389 EC_OSPF_EXT_LSA_UNEXPECTED,
1390 "EXT (%s): Refresh instead of Originate",
1391 __func__);
1392 UNSET_FLAG(exti->flags,
1393 EXT_LPFLG_LSA_FORCED_REFRESH);
1394 ospf_ext_link_lsa_schedule(exti,
1395 REFRESH_THIS_LSA);
1396 }
1397 continue;
1398 }
1399
1400 /* Ok, let's try to originate an LSA */
1401 osr_debug(
1402 "EXT (%s): Let's finally reoriginate the LSA 8.0.0.%u for Itf %s through the Area %pI4", __func__,
1403 exti->instance, exti->ifp ? exti->ifp->name : "-",
1404 &area->area_id);
1405 ospf_ext_link_lsa_originate1(area, exti);
1406 }
1407
1408 rc = 0;
1409 return rc;
1410 }
1411
1412 /* Refresh an Extended Prefix Opaque LSA */
1413 static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
1414 {
1415 struct ospf_lsa *new = NULL;
1416 struct ospf_area *area = lsa->area;
1417 struct ospf *top;
1418 struct ext_itf *exti;
1419
1420 if (!OspfEXT.enabled) {
1421 /*
1422 * This LSA must have flushed before due to Extended Prefix
1423 * Opaque LSA status change.
1424 * It seems a slip among routers in the routing domain.
1425 */
1426 zlog_info(
1427 "EXT (%s): Segment Routing functionality is Disabled",
1428 __func__);
1429 /* Flush it anyway. */
1430 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1431 }
1432
1433 /* Lookup this lsa corresponding Extended parameters */
1434 exti = lookup_ext_by_instance(lsa);
1435 if (exti == NULL) {
1436 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1437 "EXT (%s): Invalid parameter LSA ID", __func__);
1438 /* Flush it anyway. */
1439 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1440 }
1441
1442 /* Check if Interface was not disable in the interval */
1443 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
1444 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1445 "EXT (%s): Interface was Disabled: Flush it!",
1446 __func__);
1447 /* Flush it anyway. */
1448 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1449 }
1450
1451 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1452 if (IS_LSA_MAXAGE(lsa)) {
1453 if (exti)
1454 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1455 ospf_opaque_lsa_flush_schedule(lsa);
1456 return NULL;
1457 }
1458
1459 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1460 new = ospf_ext_pref_lsa_new(area, exti);
1461
1462 if (new == NULL) {
1463 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1464 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
1465 return NULL;
1466 }
1467 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1468
1469 /*
1470 * Install this LSA into LSDB
1471 * Given "lsa" will be freed in the next function
1472 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1473 * ospf_lookup() to get ospf instance
1474 */
1475 if (area)
1476 top = area->ospf;
1477 else
1478 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1479
1480 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1481 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1482 "EXT (%s): ospf_lsa_install() error", __func__);
1483 ospf_lsa_unlock(&new);
1484 return NULL;
1485 }
1486
1487 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1488 ospf_flood_through_area(area, NULL /*nbr */, new);
1489
1490 /* Debug logging. */
1491 osr_debug("EXT (%s): LSA[Type%u:%pI4] Refresh Extended Prefix LSA",
1492 __func__, new->data->type, &new->data->id);
1493 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1494 ospf_lsa_header_dump(new->data);
1495
1496
1497 return new;
1498 }
1499
1500 /* Refresh an Extended Link Opaque LSA */
1501 static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
1502 {
1503 struct ext_itf *exti;
1504 struct ospf_area *area = lsa->area;
1505 struct ospf *top = area->ospf;
1506 struct ospf_lsa *new = NULL;
1507
1508 if (!OspfEXT.enabled) {
1509 /*
1510 * This LSA must have flushed before due to OSPF-SR status
1511 * change. It seems a slip among routers in the routing domain.
1512 */
1513 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1514 __func__);
1515 /* Flush it anyway. */
1516 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1517 }
1518
1519 /* Lookup this LSA corresponding Extended parameters */
1520 exti = lookup_ext_by_instance(lsa);
1521 if (exti == NULL) {
1522 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1523 "EXT (%s): Invalid parameter LSA ID", __func__);
1524 /* Flush it anyway. */
1525 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1526 }
1527
1528 /* Check if Interface was not disable in the interval */
1529 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
1530 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1531 "EXT (%s): Interface was Disabled: Flush it!",
1532 __func__);
1533 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1534 }
1535
1536 /* If the lsa's age reached to MaxAge, start flushing procedure */
1537 if (IS_LSA_MAXAGE(lsa)) {
1538 if (exti)
1539 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1540 ospf_opaque_lsa_flush_schedule(lsa);
1541 return NULL;
1542 }
1543
1544 /* Create new Opaque-LSA/Extended Link instance */
1545 new = ospf_ext_link_lsa_new(area, exti);
1546 if (new == NULL) {
1547 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1548 "EXT (%s): Error creating new LSA", __func__);
1549 return NULL;
1550 }
1551 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1552
1553 /* Install this LSA into LSDB. */
1554 /* Given "lsa" will be freed in the next function */
1555 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1556 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1557 "EXT (%s): Error installing new LSA", __func__);
1558 ospf_lsa_unlock(&new);
1559 return NULL;
1560 }
1561
1562 /* Flood updated LSA through the link Area according to the RFC7684 */
1563 ospf_flood_through_area(area, NULL /*nbr */, new);
1564
1565 /* Debug logging. */
1566 osr_debug("EXT (%s): LSA[Type%u:%pI4]: Refresh Extended Link LSA",
1567 __func__, new->data->type, &new->data->id);
1568 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1569 ospf_lsa_header_dump(new->data);
1570
1571 return new;
1572 }
1573
1574 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1575 static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
1576 enum lsa_opcode opcode)
1577 {
1578 struct ospf_lsa lsa;
1579 struct lsa_header lsah;
1580 struct ospf *top;
1581 uint32_t tmp;
1582
1583 memset(&lsa, 0, sizeof(lsa));
1584 memset(&lsah, 0, sizeof(lsah));
1585
1586 /* Sanity Check */
1587 if (exti == NULL)
1588 return;
1589
1590 /* Check if the corresponding link is ready to be flooded */
1591 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1592 return;
1593
1594 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1595 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1596 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1597 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1598 exti->ifp ? exti->ifp->name : "-");
1599
1600 /* Verify Area */
1601 if (exti->area == NULL) {
1602 osr_debug(
1603 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1604 __func__);
1605
1606 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1607 struct in_addr backbone = {.s_addr = INADDR_ANY};
1608 exti->area = ospf_area_lookup_by_area_id(top, backbone);
1609 if (exti->area == NULL) {
1610 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1611 "EXT (%s): Unable to set Area", __func__);
1612 return;
1613 }
1614 }
1615 /* Set LSA header information */
1616 lsa.area = exti->area;
1617 lsa.data = &lsah;
1618 lsah.type = OSPF_OPAQUE_AREA_LSA;
1619 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
1620 lsah.id.s_addr = htonl(tmp);
1621
1622 switch (opcode) {
1623 case REORIGINATE_THIS_LSA:
1624 ospf_opaque_lsa_reoriginate_schedule(
1625 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1626 OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
1627 break;
1628 case REFRESH_THIS_LSA:
1629 ospf_opaque_lsa_refresh_schedule(&lsa);
1630 break;
1631 case FLUSH_THIS_LSA:
1632 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1633 ospf_opaque_lsa_flush_schedule(&lsa);
1634 break;
1635 }
1636 }
1637
1638 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1639 static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
1640 enum lsa_opcode opcode)
1641 {
1642 struct ospf_lsa lsa;
1643 struct lsa_header lsah;
1644 struct ospf *top;
1645 uint32_t tmp;
1646
1647 memset(&lsa, 0, sizeof(lsa));
1648 memset(&lsah, 0, sizeof(lsah));
1649
1650 /* Sanity Check */
1651 if (exti == NULL)
1652 return;
1653
1654 /* Check if the corresponding link is ready to be flooded */
1655 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1656 return;
1657
1658 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1659 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1660 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1661 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1662 exti->ifp ? exti->ifp->name : "-");
1663
1664 /* Verify Area */
1665 if (exti->area == NULL) {
1666 osr_debug(
1667 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1668 __func__);
1669
1670 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1671 struct in_addr backbone = {.s_addr = INADDR_ANY};
1672 exti->area = ospf_area_lookup_by_area_id(top, backbone);
1673 if (exti->area == NULL) {
1674 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1675 "EXT (%s): Unable to set Area", __func__);
1676 return;
1677 }
1678 }
1679 /* Set LSA header information */
1680 lsa.area = exti->area;
1681 lsa.data = &lsah;
1682 lsah.type = OSPF_OPAQUE_AREA_LSA;
1683 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1684 lsah.id.s_addr = htonl(tmp);
1685
1686 switch (opcode) {
1687 case REORIGINATE_THIS_LSA:
1688 ospf_opaque_lsa_reoriginate_schedule(
1689 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1690 OPAQUE_TYPE_EXTENDED_LINK_LSA);
1691 break;
1692 case REFRESH_THIS_LSA:
1693 ospf_opaque_lsa_refresh_schedule(&lsa);
1694 break;
1695 case FLUSH_THIS_LSA:
1696 ospf_opaque_lsa_flush_schedule(&lsa);
1697 break;
1698 }
1699 }
1700
1701 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1702 static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op)
1703 {
1704
1705 if (exti->stype == PREF_SID)
1706 ospf_ext_pref_lsa_schedule(exti, op);
1707 else
1708 ospf_ext_link_lsa_schedule(exti, op);
1709 }
1710
1711 /*
1712 * ------------------------------------
1713 * Followings are vty show functions.
1714 * ------------------------------------
1715 */
1716
1717 /* Cisco experimental SubTLV */
1718 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty *vty,
1719 struct tlv_header *tlvh)
1720 {
1721 struct ext_subtlv_rmt_itf_addr *top;
1722
1723 top = (struct ext_subtlv_rmt_itf_addr *)tlvh;
1724
1725 vty_out(vty,
1726 " Remote Interface Address Sub-TLV: Length %u\n Address: %pI4\n",
1727 ntohs(top->header.length), &top->value);
1728
1729 return TLV_SIZE(tlvh);
1730 }
1731
1732 /* Adjacency SID SubTLV */
1733 static uint16_t show_vty_ext_link_adj_sid(struct vty *vty,
1734 struct tlv_header *tlvh)
1735 {
1736 struct ext_subtlv_adj_sid *top = (struct ext_subtlv_adj_sid *)tlvh;
1737
1738 vty_out(vty,
1739 " Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1740 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1741 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1742 : "Index",
1743 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1744 ? GET_LABEL(ntohl(top->value))
1745 : ntohl(top->value));
1746
1747 return TLV_SIZE(tlvh);
1748 }
1749
1750 /* LAN Adjacency SubTLV */
1751 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty *vty,
1752 struct tlv_header *tlvh)
1753 {
1754 struct ext_subtlv_lan_adj_sid *top =
1755 (struct ext_subtlv_lan_adj_sid *)tlvh;
1756
1757 vty_out(vty,
1758 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: %pI4\n\t%s: %u\n",
1759 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1760 &top->neighbor_id,
1761 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1762 : "Index",
1763 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1764 ? GET_LABEL(ntohl(top->value))
1765 : ntohl(top->value));
1766
1767 return TLV_SIZE(tlvh);
1768 }
1769
1770 static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh)
1771 {
1772 vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1773 ntohs(tlvh->type), ntohs(tlvh->length));
1774
1775 return TLV_SIZE(tlvh);
1776 }
1777
1778 /* Extended Link Sub TLVs */
1779 static uint16_t show_vty_link_info(struct vty *vty, struct tlv_header *ext)
1780 {
1781 struct ext_tlv_link *top = (struct ext_tlv_link *)ext;
1782 struct tlv_header *tlvh;
1783 uint16_t length = ntohs(top->header.length) - 3 * sizeof(uint32_t);
1784 uint16_t sum = 0;
1785
1786 vty_out(vty,
1787 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1788 " Link ID: %pI4\n",
1789 ntohs(top->header.length), top->link_type,
1790 &top->link_id);
1791 vty_out(vty, " Link data: %pI4\n", &top->link_data);
1792
1793 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1794 + EXT_TLV_LINK_SIZE);
1795 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1796 switch (ntohs(tlvh->type)) {
1797 case EXT_SUBTLV_ADJ_SID:
1798 sum += show_vty_ext_link_adj_sid(vty, tlvh);
1799 break;
1800 case EXT_SUBTLV_LAN_ADJ_SID:
1801 sum += show_vty_ext_link_lan_adj_sid(vty, tlvh);
1802 break;
1803 case EXT_SUBTLV_RMT_ITF_ADDR:
1804 sum += show_vty_ext_link_rmt_itf_addr(vty, tlvh);
1805 break;
1806 default:
1807 sum += show_vty_unknown_tlv(vty, tlvh);
1808 break;
1809 }
1810 }
1811
1812 return sum + sizeof(struct ext_tlv_link);
1813 }
1814
1815 /* Extended Link TLVs */
1816 static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa)
1817 {
1818 struct lsa_header *lsah = lsa->data;
1819 struct tlv_header *tlvh;
1820 uint16_t length = 0, sum = 0;
1821
1822 /* Initialize TLV browsing */
1823 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1824
1825 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1826 tlvh = TLV_HDR_NEXT(tlvh)) {
1827 switch (ntohs(tlvh->type)) {
1828 case EXT_TLV_LINK:
1829 sum += show_vty_link_info(vty, tlvh);
1830 break;
1831 default:
1832 sum += show_vty_unknown_tlv(vty, tlvh);
1833 break;
1834 }
1835 }
1836 }
1837
1838 /* Prefix SID SubTLV */
1839 static uint16_t show_vty_ext_pref_pref_sid(struct vty *vty,
1840 struct tlv_header *tlvh)
1841 {
1842 struct ext_subtlv_prefix_sid *top =
1843 (struct ext_subtlv_prefix_sid *)tlvh;
1844
1845 vty_out(vty,
1846 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1847 ntohs(top->header.length), top->algorithm, top->flags,
1848 top->mtid,
1849 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) ? "Label"
1850 : "Index",
1851 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG)
1852 ? GET_LABEL(ntohl(top->value))
1853 : ntohl(top->value));
1854
1855 return TLV_SIZE(tlvh);
1856 }
1857
1858 /* Extended Prefix SubTLVs */
1859 static uint16_t show_vty_pref_info(struct vty *vty, struct tlv_header *ext)
1860 {
1861 struct ext_tlv_prefix *top = (struct ext_tlv_prefix *)ext;
1862 struct tlv_header *tlvh;
1863 uint16_t length = ntohs(top->header.length) - 2 * sizeof(uint32_t);
1864 uint16_t sum = 0;
1865
1866 vty_out(vty,
1867 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1868 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %pI4/%u\n",
1869 ntohs(top->header.length), top->route_type, top->af, top->flags,
1870 &top->address, top->pref_length);
1871
1872 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1873 + EXT_TLV_PREFIX_SIZE);
1874 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1875 switch (ntohs(tlvh->type)) {
1876 case EXT_SUBTLV_PREFIX_SID:
1877 sum += show_vty_ext_pref_pref_sid(vty, tlvh);
1878 break;
1879 default:
1880 sum += show_vty_unknown_tlv(vty, tlvh);
1881 break;
1882 }
1883 }
1884
1885 return sum + sizeof(struct ext_tlv_prefix);
1886 }
1887
1888 /* Extended Prefix TLVs */
1889 static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa)
1890 {
1891 struct lsa_header *lsah = lsa->data;
1892 struct tlv_header *tlvh;
1893 uint16_t length = 0, sum = 0;
1894
1895 /* Initialize TLV browsing */
1896 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1897
1898 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1899 tlvh = TLV_HDR_NEXT(tlvh)) {
1900 switch (ntohs(tlvh->type)) {
1901 case EXT_TLV_PREFIX:
1902 sum += show_vty_pref_info(vty, tlvh);
1903 break;
1904 default:
1905 sum += show_vty_unknown_tlv(vty, tlvh);
1906 break;
1907 }
1908 }
1909 }