]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_ext.c
Merge pull request #6987 from Niral-Networks/acl_fix
[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 /* Process only Active Extended Prefix/Link LSA */
466 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
467 return;
468
469 osr_debug("EXT (%s): Disable %s%s%s-SID on interface %s", __func__,
470 exti->stype == LOCAL_SID ? "Prefix" : "",
471 exti->stype == ADJ_SID ? "Adjacency" : "",
472 exti->stype == LAN_ADJ_SID ? "LAN-Adjacency" : "",
473 exti->ifp->name);
474
475 /* Flush LSA if already engaged */
476 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
477 ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
478 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
479 }
480
481 /* De-activate this Extended Prefix/Link and remove corresponding
482 * Segment-Routing Prefix-SID or (LAN)-ADJ-SID */
483 if (exti->stype == ADJ_SID || exti->stype == LAN_ADJ_SID)
484 ospf_ext_link_delete_adj_sid(exti);
485 else
486 ospf_sr_ext_itf_delete(exti);
487 }
488
489 /*
490 * Update Extended prefix SID index for Loopback interface type
491 *
492 * @param ifname - Loopback interface name
493 * @param index - new value for the prefix SID of this interface
494 * @param p - prefix for this interface or NULL if Extended Prefix
495 * should be remove
496 *
497 * @return instance number if update is OK, 0 otherwise
498 */
499 uint32_t ospf_ext_schedule_prefix_index(struct interface *ifp, uint32_t index,
500 struct prefix_ipv4 *p, uint8_t flags)
501 {
502 int rc = 0;
503 struct ext_itf *exti;
504
505 /* Find Extended Prefix interface */
506 exti = lookup_ext_by_ifp(ifp);
507 if (exti == NULL)
508 return rc;
509
510 if (p != NULL) {
511 osr_debug("EXT (%s): Schedule new prefix %pFX with index %u on interface %s", __func__, p, index, ifp->name);
512
513 /* Set first Extended Prefix then the Prefix SID information */
514 set_ext_prefix(exti, OSPF_PATH_INTRA_AREA, EXT_TLV_PREF_NFLG,
515 *p);
516 set_prefix_sid(exti, SR_ALGORITHM_SPF, index, SID_INDEX, flags);
517
518 /* Try to Schedule LSA */
519 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
520 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
521 ospf_ext_pref_lsa_schedule(exti,
522 REFRESH_THIS_LSA);
523 else
524 ospf_ext_pref_lsa_schedule(
525 exti, REORIGINATE_THIS_LSA);
526 }
527 } else {
528 osr_debug("EXT (%s): Remove prefix for interface %s", __func__,
529 ifp->name);
530
531 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
532 ospf_ext_pref_lsa_schedule(exti, FLUSH_THIS_LSA);
533 }
534
535 return SET_OPAQUE_LSID(exti->type, exti->instance);
536 }
537
538 /**
539 * Update Adjacecny-SID for Extended Link LSA
540 *
541 * @param exti Extended Link information
542 */
543 static void ospf_ext_link_update_adj_sid(struct ext_itf *exti)
544 {
545 mpls_label_t label;
546 mpls_label_t bck_label;
547
548 /* Process only (LAN)Adjacency-SID Type */
549 if (exti->stype != ADJ_SID && exti->stype != LAN_ADJ_SID)
550 return;
551
552 /* Request Primary & Backup Labels from Label Manager */
553 bck_label = ospf_sr_local_block_request_label();
554 label = ospf_sr_local_block_request_label();
555 if (bck_label == MPLS_INVALID_LABEL || label == MPLS_INVALID_LABEL) {
556 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
557 ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
558 return;
559 }
560
561 /* Set Adjacency-SID, backup first */
562 if (exti->stype == ADJ_SID) {
563 set_adj_sid(exti, true, bck_label, SID_LABEL);
564 set_adj_sid(exti, false, label, SID_LABEL);
565 } else {
566 set_lan_adj_sid(exti, true, bck_label, SID_LABEL,
567 exti->lan_sid[0].neighbor_id);
568 set_lan_adj_sid(exti, false, label, SID_LABEL,
569 exti->lan_sid[1].neighbor_id);
570 }
571
572 /* Finally, add corresponding SR Link in SRDB & MPLS LFIB */
573 SET_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET);
574 ospf_sr_ext_itf_add(exti);
575 }
576
577 /**
578 * Delete Adjacecny-SID for Extended Link LSA
579 *
580 * @param exti Extended Link information
581 */
582 static void ospf_ext_link_delete_adj_sid(struct ext_itf *exti)
583 {
584 /* Process only (LAN)Adjacency-SID Type */
585 if (exti->stype != ADJ_SID && exti->stype != LAN_ADJ_SID)
586 return;
587
588 /* Release Primary & Backup Labels from Label Manager */
589 if (exti->stype == ADJ_SID) {
590 ospf_sr_local_block_release_label(exti->adj_sid[0].value);
591 ospf_sr_local_block_release_label(exti->adj_sid[1].value);
592 } else {
593 ospf_sr_local_block_release_label(exti->lan_sid[0].value);
594 ospf_sr_local_block_release_label(exti->lan_sid[1].value);
595 }
596 /* And reset corresponding TLV */
597 unset_adjacency_sid(exti);
598
599 /* Finally, remove corresponding SR Link in SRDB & MPLS LFIB */
600 UNSET_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET);
601 ospf_sr_ext_itf_delete(exti);
602 }
603
604 /**
605 * Update Extended Link LSA once Segment Routing Label Block has been changed.
606 */
607 void ospf_ext_link_srlb_update(void)
608 {
609 struct listnode *node;
610 struct ext_itf *exti;
611
612
613 osr_debug("EXT (%s): Update Extended Links with new SRLB", __func__);
614
615 /* Update all Extended Link Adjaceny-SID */
616 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
617 /* Skip Extended Prefix */
618 if (exti->stype == PREF_SID || exti->stype == LOCAL_SID)
619 continue;
620
621 /* Skip inactive Extended Link */
622 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
623 continue;
624
625 ospf_ext_link_update_adj_sid(exti);
626 }
627 }
628
629 /*
630 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
631 *
632 * @param enable To activate or not Segment Routing Extended LSA flooding
633 *
634 * @return none
635 */
636 void ospf_ext_update_sr(bool enable)
637 {
638 struct listnode *node;
639 struct ext_itf *exti;
640
641 osr_debug("EXT (%s): %s Extended LSAs for Segment Routing ", __func__,
642 enable ? "Enable" : "Disable");
643
644 if (enable) {
645 OspfEXT.enabled = true;
646
647 /* Refresh LSAs if already engaged or originate */
648 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
649 /* Skip Inactive Extended Link */
650 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
651 continue;
652
653 /* Update Extended Link (LAN)Adj-SID if not set */
654 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET))
655 ospf_ext_link_update_adj_sid(exti);
656
657 /* Finally, flood the extended Link */
658 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
659 ospf_ext_lsa_schedule(exti, REFRESH_THIS_LSA);
660 else
661 ospf_ext_lsa_schedule(exti,
662 REORIGINATE_THIS_LSA);
663 }
664 } else {
665 /* Start by Removing Extended LSA */
666 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
667 ospf_extended_lsa_delete(exti);
668
669 /* And then disable Extended Link/Prefix */
670 OspfEXT.enabled = false;
671 }
672 }
673
674 /*
675 * -----------------------------------------------------------------------
676 * Followings are callback functions against generic Opaque-LSAs handling
677 * -----------------------------------------------------------------------
678 */
679
680 /* Add new Interface in Extended Interface List */
681 static int ospf_ext_link_new_if(struct interface *ifp)
682 {
683 struct ext_itf *new;
684 int rc = -1;
685
686 if (lookup_ext_by_ifp(ifp) != NULL) {
687 rc = 0; /* Do nothing here. */
688 return rc;
689 }
690
691 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf));
692
693 /* initialize new information and link back the interface */
694 new->ifp = ifp;
695 new->flags = EXT_LPFLG_LSA_INACTIVE;
696
697 listnode_add(OspfEXT.iflist, new);
698
699 rc = 0;
700 return rc;
701 }
702
703 /* Remove existing Interface from Extended Interface List */
704 static int ospf_ext_link_del_if(struct interface *ifp)
705 {
706 struct ext_itf *exti;
707 int rc = -1;
708
709 exti = lookup_ext_by_ifp(ifp);
710 if (exti != NULL) {
711 /* Flush LSA and remove Adjacency SID */
712 ospf_extended_lsa_delete(exti);
713
714 /* Dequeue listnode entry from the list. */
715 listnode_delete(OspfEXT.iflist, exti);
716
717 XFREE(MTYPE_OSPF_EXT_PARAMS, exti);
718
719 rc = 0;
720 } else {
721 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
722 "EXT (%s): interface %s is not found", __func__,
723 ifp ? ifp->name : "-");
724 }
725
726 return rc;
727 }
728
729 /*
730 * Determine if an Interface belongs to an Extended Link Adjacency or
731 * Extended Prefix SID type and allocate new instance value accordingly
732 */
733 static void ospf_ext_ism_change(struct ospf_interface *oi, int old_status)
734 {
735 struct ext_itf *exti;
736
737 /* Get interface information for Segment Routing */
738 exti = lookup_ext_by_ifp(oi->ifp);
739 if (exti == NULL) {
740 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
741 "EXT (%s): Cannot get Extended info. from OI(%s)",
742 __func__, IF_NAME(oi));
743 return;
744 }
745
746 /* Reset Extended information if ospf interface goes Down */
747 if (oi->state == ISM_Down) {
748 ospf_extended_lsa_delete(exti);
749 exti->area = NULL;
750 exti->flags = EXT_LPFLG_LSA_INACTIVE;
751 return;
752 }
753
754 /* Determine if interface is related to a Prefix or an Adjacency SID */
755 if (oi->type == OSPF_IFTYPE_LOOPBACK) {
756 exti->stype = PREF_SID;
757 exti->type = OPAQUE_TYPE_EXTENDED_PREFIX_LSA;
758 exti->flags = EXT_LPFLG_LSA_ACTIVE;
759 exti->instance = get_ext_pref_instance_value();
760 exti->area = oi->area;
761
762 osr_debug("EXT (%s): Set Prefix SID to interface %s ",
763 __func__, oi->ifp->name);
764
765 /* Complete SRDB if the interface belongs to a Prefix */
766 if (OspfEXT.enabled)
767 ospf_sr_update_local_prefix(oi->ifp, oi->address);
768 } else {
769 /* Determine if interface is related to Adj. or LAN Adj. SID */
770 if (oi->state == ISM_DR)
771 exti->stype = LAN_ADJ_SID;
772 else
773 exti->stype = ADJ_SID;
774
775 exti->type = OPAQUE_TYPE_EXTENDED_LINK_LSA;
776 exti->instance = get_ext_link_instance_value();
777 exti->area = oi->area;
778
779 /*
780 * Note: Adjacency SID information are completed when ospf
781 * adjacency become up see ospf_ext_link_nsm_change()
782 */
783 osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
784 __func__, exti->stype == ADJ_SID ? "" : "LAN-",
785 oi->ifp->name);
786 }
787 }
788
789 /*
790 * Finish Extended Link configuration and flood corresponding LSA
791 * when OSPF adjacency on this link fire up
792 */
793 static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
794 {
795 struct ospf_interface *oi = nbr->oi;
796 struct ext_itf *exti;
797
798 /* Process Link only when neighbor old or new state is NSM Full */
799 if (nbr->state != NSM_Full && old_status != NSM_Full)
800 return;
801
802 /* Get interface information for Segment Routing */
803 exti = lookup_ext_by_ifp(oi->ifp);
804 if (exti == NULL) {
805 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
806 "EXT (%s): Cannot get Extended info. from OI(%s)",
807 __func__, IF_NAME(oi));
808 return;
809 }
810
811 /* Check that we have a valid area and ospf context */
812 if (oi->area == NULL || oi->area->ospf == NULL) {
813 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
814 "EXT (%s): Cannot refer to OSPF from OI(%s)",
815 __func__, IF_NAME(oi));
816 return;
817 }
818
819 /* Remove Extended Link if Neighbor State goes Down or Deleted */
820 if (nbr->state == NSM_Down || nbr->state == NSM_Deleted) {
821 ospf_ext_link_delete_adj_sid(exti);
822 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
823 ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA);
824 exti->flags = EXT_LPFLG_LSA_INACTIVE;
825 return;
826 }
827
828 /* Keep Area information in combination with SR info. */
829 exti->area = oi->area;
830
831 /* Process only Adjacency/LAN SID */
832 if (exti->stype == PREF_SID)
833 return;
834
835 switch (oi->state) {
836 case ISM_PointToPoint:
837 /* Segment ID is an Adjacency one */
838 exti->stype = ADJ_SID;
839
840 /* Set Extended Link TLV with link_id == Nbr Router ID */
841 set_ext_link(exti, OSPF_IFTYPE_POINTOPOINT, nbr->router_id,
842 oi->address->u.prefix4);
843
844 /* And Remote Interface address */
845 set_rmt_itf_addr(exti, nbr->address.u.prefix4);
846
847 break;
848
849 case ISM_DR:
850 /* Segment ID is a LAN Adjacency for the DR only */
851 exti->stype = LAN_ADJ_SID;
852
853 /* Set Extended Link TLV with link_id == DR */
854 set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
855 oi->address->u.prefix4);
856
857 /* Set Neighbor ID */
858 exti->lan_sid[0].neighbor_id = nbr->router_id;
859 exti->lan_sid[1].neighbor_id = nbr->router_id;
860
861 break;
862
863 case ISM_DROther:
864 case ISM_Backup:
865 /* Segment ID is an Adjacency if not the DR */
866 exti->stype = ADJ_SID;
867
868 /* Set Extended Link TLV with link_id == DR */
869 set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
870 oi->address->u.prefix4);
871
872 break;
873
874 default:
875 if (CHECK_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET))
876 ospf_ext_link_delete_adj_sid(exti);
877 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
878 ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA);
879 exti->flags = EXT_LPFLG_LSA_INACTIVE;
880 return;
881 }
882
883 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
884
885 if (OspfEXT.enabled) {
886 osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
887 __func__, exti->stype == ADJ_SID ? "" : "LAN-",
888 oi->ifp->name);
889
890 /* Update (LAN)Adjacency SID */
891 ospf_ext_link_update_adj_sid(exti);
892
893 /* flood this links params if everything is ok */
894 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
895 ospf_ext_link_lsa_schedule(exti, REFRESH_THIS_LSA);
896 else
897 ospf_ext_link_lsa_schedule(exti, REORIGINATE_THIS_LSA);
898 }
899 }
900
901 /* Callbacks to handle Extended Link Segment Routing LSA information */
902 static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa)
903 {
904 /* Sanity Check */
905 if (lsa == NULL) {
906 flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL",
907 __func__);
908 return -1;
909 }
910
911 /* Process only Opaque LSA */
912 if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA)
913 && (lsa->data->type != OSPF_OPAQUE_AS_LSA))
914 return 0;
915
916 /* Process only Extended Link LSA */
917 if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr))
918 != OPAQUE_TYPE_EXTENDED_LINK_LSA)
919 return 0;
920
921 /* Check if it is not my LSA */
922 if (IS_LSA_SELF(lsa))
923 return 0;
924
925 /* Check if Extended is enable */
926 if (!OspfEXT.enabled)
927 return 0;
928
929 /* Call Segment Routing LSA update or deletion */
930 if (!IS_LSA_MAXAGE(lsa))
931 ospf_sr_ext_link_lsa_update(lsa);
932 else
933 ospf_sr_ext_link_lsa_delete(lsa);
934
935 return 0;
936 }
937
938 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
939 static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa)
940 {
941
942 /* Sanity Check */
943 if (lsa == NULL) {
944 flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL",
945 __func__);
946 return -1;
947 }
948
949 /* Process only Opaque LSA */
950 if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA)
951 && (lsa->data->type != OSPF_OPAQUE_AS_LSA))
952 return 0;
953
954 /* Process only Extended Prefix LSA */
955 if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr))
956 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA)
957 return 0;
958
959 /* Check if it is not my LSA */
960 if (IS_LSA_SELF(lsa))
961 return 0;
962
963 /* Check if Extended is enable */
964 if (!OspfEXT.enabled)
965 return 0;
966
967 /* Call Segment Routing LSA update or deletion */
968 if (!IS_LSA_MAXAGE(lsa))
969 ospf_sr_ext_prefix_lsa_update(lsa);
970 else
971 ospf_sr_ext_prefix_lsa_delete(lsa);
972
973 return 0;
974 }
975
976 /*
977 * -------------------------------------------------------
978 * Followings are OSPF protocol processing functions for
979 * Extended Prefix/Link Opaque LSA
980 * -------------------------------------------------------
981 */
982
983 static void build_tlv_header(struct stream *s, struct tlv_header *tlvh)
984 {
985 stream_put(s, tlvh, sizeof(struct tlv_header));
986 }
987
988 static void build_tlv(struct stream *s, struct tlv_header *tlvh)
989 {
990
991 if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) {
992 build_tlv_header(s, tlvh);
993 stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
994 }
995 }
996
997 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
998 static void ospf_ext_pref_lsa_body_set(struct stream *s, struct ext_itf *exti)
999 {
1000
1001 /* Sanity check */
1002 if ((exti == NULL) || (exti->stype != PREF_SID))
1003 return;
1004
1005 /* Adjust Extended Prefix TLV size */
1006 TLV_LEN(exti->prefix) = htons(ntohs(TLV_LEN(exti->node_sid))
1007 + EXT_TLV_PREFIX_SIZE + TLV_HDR_SIZE);
1008
1009 /* Build LSA body for an Extended Prefix TLV */
1010 build_tlv_header(s, &exti->prefix.header);
1011 stream_put(s, TLV_DATA(&exti->prefix.header), EXT_TLV_PREFIX_SIZE);
1012 /* Then add Prefix SID SubTLV */
1013 build_tlv(s, &exti->node_sid.header);
1014 }
1015
1016 /* Build an Extended Link Opaque LSA body for extended link TLV */
1017 static void ospf_ext_link_lsa_body_set(struct stream *s, struct ext_itf *exti)
1018 {
1019 size_t size;
1020
1021 /* Sanity check */
1022 if ((exti == NULL)
1023 || ((exti->stype != ADJ_SID) && (exti->stype != LAN_ADJ_SID)))
1024 return;
1025
1026 if (exti->stype == ADJ_SID) {
1027 /* Adjust Extended Link TLV size for Adj. SID */
1028 size = EXT_TLV_LINK_SIZE + 2 * EXT_SUBTLV_ADJ_SID_SIZE
1029 + 2 * TLV_HDR_SIZE;
1030 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
1031 size = size + EXT_SUBTLV_RMT_ITF_ADDR_SIZE
1032 + TLV_HDR_SIZE;
1033 TLV_LEN(exti->link) = htons(size);
1034
1035 /* Build LSA body for an Extended Link TLV with Adj. SID */
1036 build_tlv_header(s, &exti->link.header);
1037 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
1038 /* then add Adjacency SubTLVs */
1039 build_tlv(s, &exti->adj_sid[1].header);
1040 build_tlv(s, &exti->adj_sid[0].header);
1041
1042 /* Add Cisco experimental SubTLV if interface is PtoP */
1043 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
1044 build_tlv(s, &exti->rmt_itf_addr.header);
1045 } else {
1046 /* Adjust Extended Link TLV size for LAN SID */
1047 size = EXT_TLV_LINK_SIZE
1048 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE + TLV_HDR_SIZE);
1049 TLV_LEN(exti->link) = htons(size);
1050
1051 /* Build LSA body for an Extended Link TLV with LAN SID */
1052 build_tlv_header(s, &exti->link.header);
1053 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
1054 /* then add LAN-Adjacency SubTLVs */
1055 build_tlv(s, &exti->lan_sid[1].header);
1056 build_tlv(s, &exti->lan_sid[0].header);
1057 }
1058 }
1059
1060 /* Create new Extended Prefix opaque-LSA for every extended prefix */
1061 static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area,
1062 struct ext_itf *exti)
1063 {
1064 struct stream *s;
1065 struct lsa_header *lsah;
1066 struct ospf_lsa *new = NULL;
1067 struct ospf *top;
1068 uint8_t options, lsa_type;
1069 struct in_addr lsa_id;
1070 struct in_addr router_id;
1071 uint32_t tmp;
1072 uint16_t length;
1073
1074 /* Sanity Check */
1075 if (exti == NULL)
1076 return NULL;
1077
1078 /* Create a stream for LSA. */
1079 s = stream_new(OSPF_MAX_LSA_SIZE);
1080
1081 /* Prepare LSA Header */
1082 lsah = (struct lsa_header *)STREAM_DATA(s);
1083
1084 lsa_type = OspfEXT.scope;
1085
1086 /*
1087 * LSA ID is a variable number identifying different instances of
1088 * Extended Prefix Opaque LSA from the same router see RFC 7684
1089 */
1090 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
1091 lsa_id.s_addr = htonl(tmp);
1092
1093 options = OSPF_OPTION_O; /* Don't forget this :-) */
1094
1095 /* Fix Options and Router ID depending of the flooding scope */
1096 if ((OspfEXT.scope == OSPF_OPAQUE_AS_LSA) || (area == NULL)) {
1097 options = OSPF_OPTION_E;
1098 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1099 router_id.s_addr = top ? top->router_id.s_addr : 0;
1100 } else {
1101 options |= LSA_OPTIONS_GET(area); /* Get area default option */
1102 options |= LSA_OPTIONS_NSSA_GET(area);
1103 router_id = area->ospf->router_id;
1104 }
1105
1106 /* Set opaque-LSA header fields. */
1107 lsa_header_set(s, options, lsa_type, lsa_id, router_id);
1108
1109 osr_debug(
1110 "EXT (%s): LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Prefix Opaque LSA instance",
1111 __func__, lsa_type, &lsa_id);
1112
1113 /* Set opaque-LSA body fields. */
1114 ospf_ext_pref_lsa_body_set(s, exti);
1115
1116 /* Set length. */
1117 length = stream_get_endp(s);
1118 lsah->length = htons(length);
1119
1120 /* Now, create an OSPF LSA instance. */
1121 new = ospf_lsa_new_and_data(length);
1122
1123 /* Segment Routing belongs only to default VRF */
1124 new->vrf_id = VRF_DEFAULT;
1125 new->area = area;
1126 SET_FLAG(new->flags, OSPF_LSA_SELF);
1127 memcpy(new->data, lsah, length);
1128 stream_free(s);
1129
1130 return new;
1131 }
1132
1133 /* Create new Extended Link opaque-LSA for every extended link TLV */
1134 static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area,
1135 struct ext_itf *exti)
1136 {
1137 struct stream *s;
1138 struct lsa_header *lsah;
1139 struct ospf_lsa *new = NULL;
1140 uint8_t options, lsa_type;
1141 struct in_addr lsa_id;
1142 uint32_t tmp;
1143 uint16_t length;
1144
1145 /* Sanity Check */
1146 if (exti == NULL)
1147 return NULL;
1148
1149 /* Create a stream for LSA. */
1150 s = stream_new(OSPF_MAX_LSA_SIZE);
1151 lsah = (struct lsa_header *)STREAM_DATA(s);
1152
1153 options = OSPF_OPTION_O; /* Don't forget this :-) */
1154 options |= LSA_OPTIONS_GET(area); /* Get area default option */
1155 options |= LSA_OPTIONS_NSSA_GET(area);
1156 /* Extended Link Opaque LSA are only flooded within an area */
1157 lsa_type = OSPF_OPAQUE_AREA_LSA;
1158
1159 /*
1160 * LSA ID is a variable number identifying different instances of
1161 * Extended Link Opaque LSA from the same router see RFC 7684
1162 */
1163 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1164 lsa_id.s_addr = htonl(tmp);
1165
1166 osr_debug(
1167 "EXT (%s) LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Link Opaque LSA instance",
1168 __func__, lsa_type, &lsa_id);
1169
1170 /* Set opaque-LSA header fields. */
1171 lsa_header_set(s, options, lsa_type, lsa_id, area->ospf->router_id);
1172
1173 /* Set opaque-LSA body fields. */
1174 ospf_ext_link_lsa_body_set(s, exti);
1175
1176 /* Set length. */
1177 length = stream_get_endp(s);
1178 lsah->length = htons(length);
1179
1180 /* Now, create an OSPF LSA instance. */
1181 new = ospf_lsa_new_and_data(length);
1182
1183 /* Segment Routing belongs only to default VRF */
1184 new->vrf_id = VRF_DEFAULT;
1185 new->area = area;
1186 SET_FLAG(new->flags, OSPF_LSA_SELF);
1187 memcpy(new->data, lsah, length);
1188 stream_free(s);
1189
1190 return new;
1191 }
1192
1193 /*
1194 * Process the origination of an Extended Prefix Opaque LSA
1195 * for every extended prefix TLV
1196 */
1197 static int ospf_ext_pref_lsa_originate1(struct ospf_area *area,
1198 struct ext_itf *exti)
1199 {
1200 struct ospf_lsa *new;
1201 int rc = -1;
1202
1203
1204 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1205 new = ospf_ext_pref_lsa_new(area, exti);
1206 if (new == NULL) {
1207 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1208 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
1209 return rc;
1210 }
1211
1212 /* Install this LSA into LSDB. */
1213 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
1214 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1215 "EXT (%s): ospf_lsa_install() error", __func__);
1216 ospf_lsa_unlock(&new);
1217 return rc;
1218 }
1219
1220 /* Now this Extended Prefix Opaque LSA info parameter entry has
1221 * associated LSA.
1222 */
1223 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1224
1225 /* Update new LSA origination count. */
1226 area->ospf->lsa_originate_count++;
1227
1228 /* Flood new LSA through area. */
1229 ospf_flood_through_area(area, NULL /*nbr */, new);
1230
1231 osr_debug(
1232 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSAExtended Prefix Opaque LSA: Area(%pI4), Link(%s)",
1233 __func__, new->data->type, &new->data->id,
1234 &area->area_id, exti->ifp->name);
1235 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1236 ospf_lsa_header_dump(new->data);
1237
1238 rc = 0;
1239
1240 return rc;
1241 }
1242
1243 /*
1244 * Process the origination of an Extended Link Opaque LSA
1245 * for every extended link TLV
1246 */
1247 static int ospf_ext_link_lsa_originate1(struct ospf_area *area,
1248 struct ext_itf *exti)
1249 {
1250 struct ospf_lsa *new;
1251 int rc = -1;
1252
1253 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1254 new = ospf_ext_link_lsa_new(area, exti);
1255 if (new == NULL) {
1256 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1257 "EXT (%s): ospf_ext_link_lsa_new() error", __func__);
1258 return rc;
1259 }
1260
1261 /* Install this LSA into LSDB. */
1262 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
1263 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1264 "EXT (%s): ospf_lsa_install() error", __func__);
1265 ospf_lsa_unlock(&new);
1266 return rc;
1267 }
1268
1269 /* Now this link-parameter entry has associated LSA. */
1270 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1271
1272 /* Update new LSA origination count. */
1273 area->ospf->lsa_originate_count++;
1274
1275 /* Flood new LSA through area. */
1276 ospf_flood_through_area(area, NULL /*nbr */, new);
1277
1278 osr_debug(
1279 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSA Extended Link Opaque LSA: Area(%pI4), Link(%s)",
1280 __func__, new->data->type, &new->data->id,
1281 &area->area_id, exti->ifp->name);
1282 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1283 ospf_lsa_header_dump(new->data);
1284
1285 rc = 0;
1286
1287 return rc;
1288 }
1289
1290 /* Trigger the origination of Extended Prefix Opaque LSAs */
1291 static int ospf_ext_pref_lsa_originate(void *arg)
1292 {
1293 struct ospf_area *area = (struct ospf_area *)arg;
1294 struct listnode *node;
1295 struct ext_itf *exti;
1296 int rc = -1;
1297
1298 if (!OspfEXT.enabled) {
1299 zlog_info(
1300 "EXT (%s): Segment Routing functionality is Disabled now",
1301 __func__);
1302 rc = 0; /* This is not an error case. */
1303 return rc;
1304 }
1305 osr_debug("EXT (%s): Start Originate Prefix LSA for area %pI4",
1306 __func__, &area->area_id);
1307
1308 /* Check if Extended Prefix Opaque LSA is already engaged */
1309 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1310
1311 /* Process only Prefix SID */
1312 if (exti->stype != PREF_SID)
1313 continue;
1314
1315 /* Process only Extended Prefix with valid Area ID */
1316 if ((exti->area == NULL)
1317 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1318 continue;
1319
1320 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1321 if (CHECK_FLAG(exti->flags,
1322 EXT_LPFLG_LSA_FORCED_REFRESH)) {
1323 flog_warn(
1324 EC_OSPF_EXT_LSA_UNEXPECTED,
1325 "EXT (%s): Refresh instead of Originate",
1326 __func__);
1327 UNSET_FLAG(exti->flags,
1328 EXT_LPFLG_LSA_FORCED_REFRESH);
1329 ospf_ext_pref_lsa_schedule(exti,
1330 REFRESH_THIS_LSA);
1331 }
1332 continue;
1333 }
1334
1335 /* Ok, let's try to originate an LSA */
1336 osr_debug(
1337 "EXT (%s): Let's finally re-originate the LSA 7.0.0.%u for Itf %s", __func__, exti->instance,
1338 exti->ifp ? exti->ifp->name : "");
1339 ospf_ext_pref_lsa_originate1(area, exti);
1340 }
1341
1342 rc = 0;
1343 return rc;
1344 }
1345
1346 /* Trigger the origination of Extended Link Opaque LSAs */
1347 static int ospf_ext_link_lsa_originate(void *arg)
1348 {
1349 struct ospf_area *area = (struct ospf_area *)arg;
1350 struct listnode *node;
1351 struct ext_itf *exti;
1352 int rc = -1;
1353
1354 if (!OspfEXT.enabled) {
1355 zlog_info(
1356 "EXT (%s): Segment Routing functionality is Disabled now",
1357 __func__);
1358 rc = 0; /* This is not an error case. */
1359 return rc;
1360 }
1361
1362 /* Check if Extended Prefix Opaque LSA is already engaged */
1363 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1364 /* Process only Adjacency or LAN SID */
1365 if (exti->stype == PREF_SID)
1366 continue;
1367
1368 /* Skip Inactive Extended Link */
1369 if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
1370 continue;
1371
1372 /* Process only Extended Link with valid Area ID */
1373 if ((exti->area == NULL)
1374 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1375 continue;
1376
1377 /* Check if LSA not already engaged */
1378 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1379 if (CHECK_FLAG(exti->flags,
1380 EXT_LPFLG_LSA_FORCED_REFRESH)) {
1381 flog_warn(
1382 EC_OSPF_EXT_LSA_UNEXPECTED,
1383 "EXT (%s): Refresh instead of Originate",
1384 __func__);
1385 UNSET_FLAG(exti->flags,
1386 EXT_LPFLG_LSA_FORCED_REFRESH);
1387 ospf_ext_link_lsa_schedule(exti,
1388 REFRESH_THIS_LSA);
1389 }
1390 continue;
1391 }
1392
1393 /* Ok, let's try to originate an LSA */
1394 osr_debug(
1395 "EXT (%s): Let's finally reoriginate the LSA 8.0.0.%u for Itf %s through the Area %pI4", __func__,
1396 exti->instance, exti->ifp ? exti->ifp->name : "-",
1397 &area->area_id);
1398 ospf_ext_link_lsa_originate1(area, exti);
1399 }
1400
1401 rc = 0;
1402 return rc;
1403 }
1404
1405 /* Refresh an Extended Prefix Opaque LSA */
1406 static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
1407 {
1408 struct ospf_lsa *new = NULL;
1409 struct ospf_area *area = lsa->area;
1410 struct ospf *top;
1411 struct ext_itf *exti;
1412
1413 if (!OspfEXT.enabled) {
1414 /*
1415 * This LSA must have flushed before due to Extended Prefix
1416 * Opaque LSA status change.
1417 * It seems a slip among routers in the routing domain.
1418 */
1419 zlog_info(
1420 "EXT (%s): Segment Routing functionality is Disabled",
1421 __func__);
1422 /* Flush it anyway. */
1423 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1424 }
1425
1426 /* Lookup this lsa corresponding Extended parameters */
1427 exti = lookup_ext_by_instance(lsa);
1428 if (exti == NULL) {
1429 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1430 "EXT (%s): Invalid parameter LSA ID", __func__);
1431 /* Flush it anyway. */
1432 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1433 }
1434
1435 /* Check if Interface was not disable in the interval */
1436 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
1437 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1438 "EXT (%s): Interface was Disabled: Flush it!",
1439 __func__);
1440 /* Flush it anyway. */
1441 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1442 }
1443
1444 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1445 if (IS_LSA_MAXAGE(lsa)) {
1446 if (exti)
1447 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1448 ospf_opaque_lsa_flush_schedule(lsa);
1449 return NULL;
1450 }
1451
1452 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1453 new = ospf_ext_pref_lsa_new(area, exti);
1454
1455 if (new == NULL) {
1456 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1457 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
1458 return NULL;
1459 }
1460 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1461
1462 /*
1463 * Install this LSA into LSDB
1464 * Given "lsa" will be freed in the next function
1465 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1466 * ospf_lookup() to get ospf instance
1467 */
1468 if (area)
1469 top = area->ospf;
1470 else
1471 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1472
1473 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1474 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1475 "EXT (%s): ospf_lsa_install() error", __func__);
1476 ospf_lsa_unlock(&new);
1477 return NULL;
1478 }
1479
1480 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1481 ospf_flood_through_area(area, NULL /*nbr */, new);
1482
1483 /* Debug logging. */
1484 osr_debug("EXT (%s): LSA[Type%u:%pI4] Refresh Extended Prefix LSA",
1485 __func__, new->data->type, &new->data->id);
1486 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1487 ospf_lsa_header_dump(new->data);
1488
1489
1490 return new;
1491 }
1492
1493 /* Refresh an Extended Link Opaque LSA */
1494 static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
1495 {
1496 struct ext_itf *exti;
1497 struct ospf_area *area = lsa->area;
1498 struct ospf *top = area->ospf;
1499 struct ospf_lsa *new = NULL;
1500
1501 if (!OspfEXT.enabled) {
1502 /*
1503 * This LSA must have flushed before due to OSPF-SR status
1504 * change. It seems a slip among routers in the routing domain.
1505 */
1506 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1507 __func__);
1508 /* Flush it anyway. */
1509 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1510 }
1511
1512 /* Lookup this LSA corresponding Extended parameters */
1513 exti = lookup_ext_by_instance(lsa);
1514 if (exti == NULL) {
1515 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1516 "EXT (%s): Invalid parameter LSA ID", __func__);
1517 /* Flush it anyway. */
1518 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1519 }
1520
1521 /* Check if Interface was not disable in the interval */
1522 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
1523 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1524 "EXT (%s): Interface was Disabled: Flush it!",
1525 __func__);
1526 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1527 }
1528
1529 /* If the lsa's age reached to MaxAge, start flushing procedure */
1530 if (IS_LSA_MAXAGE(lsa)) {
1531 if (exti)
1532 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1533 ospf_opaque_lsa_flush_schedule(lsa);
1534 return NULL;
1535 }
1536
1537 /* Create new Opaque-LSA/Extended Link instance */
1538 new = ospf_ext_link_lsa_new(area, exti);
1539 if (new == NULL) {
1540 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1541 "EXT (%s): Error creating new LSA", __func__);
1542 return NULL;
1543 }
1544 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1545
1546 /* Install this LSA into LSDB. */
1547 /* Given "lsa" will be freed in the next function */
1548 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1549 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
1550 "EXT (%s): Error installing new LSA", __func__);
1551 ospf_lsa_unlock(&new);
1552 return NULL;
1553 }
1554
1555 /* Flood updated LSA through the link Area according to the RFC7684 */
1556 ospf_flood_through_area(area, NULL /*nbr */, new);
1557
1558 /* Debug logging. */
1559 osr_debug("EXT (%s): LSA[Type%u:%pI4]: Refresh Extended Link LSA",
1560 __func__, new->data->type, &new->data->id);
1561 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1562 ospf_lsa_header_dump(new->data);
1563
1564 return new;
1565 }
1566
1567 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1568 static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
1569 enum lsa_opcode opcode)
1570 {
1571 struct ospf_lsa lsa;
1572 struct lsa_header lsah;
1573 struct ospf *top;
1574 uint32_t tmp;
1575
1576 memset(&lsa, 0, sizeof(lsa));
1577 memset(&lsah, 0, sizeof(lsah));
1578
1579 /* Sanity Check */
1580 if (exti == NULL)
1581 return;
1582
1583 /* Check if the corresponding link is ready to be flooded */
1584 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1585 return;
1586
1587 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1588 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1589 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1590 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1591 exti->ifp ? exti->ifp->name : "-");
1592
1593 /* Verify Area */
1594 if (exti->area == NULL) {
1595 osr_debug(
1596 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1597 __func__);
1598
1599 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1600 struct in_addr backbone = {.s_addr = INADDR_ANY};
1601 exti->area = ospf_area_lookup_by_area_id(top, backbone);
1602 if (exti->area == NULL) {
1603 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1604 "EXT (%s): Unable to set Area", __func__);
1605 return;
1606 }
1607 }
1608 /* Set LSA header information */
1609 lsa.area = exti->area;
1610 lsa.data = &lsah;
1611 lsah.type = OSPF_OPAQUE_AREA_LSA;
1612 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
1613 lsah.id.s_addr = htonl(tmp);
1614
1615 switch (opcode) {
1616 case REORIGINATE_THIS_LSA:
1617 ospf_opaque_lsa_reoriginate_schedule(
1618 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1619 OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
1620 break;
1621 case REFRESH_THIS_LSA:
1622 ospf_opaque_lsa_refresh_schedule(&lsa);
1623 break;
1624 case FLUSH_THIS_LSA:
1625 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1626 ospf_opaque_lsa_flush_schedule(&lsa);
1627 break;
1628 }
1629 }
1630
1631 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1632 static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
1633 enum lsa_opcode opcode)
1634 {
1635 struct ospf_lsa lsa;
1636 struct lsa_header lsah;
1637 struct ospf *top;
1638 uint32_t tmp;
1639
1640 memset(&lsa, 0, sizeof(lsa));
1641 memset(&lsah, 0, sizeof(lsah));
1642
1643 /* Sanity Check */
1644 if (exti == NULL)
1645 return;
1646
1647 /* Check if the corresponding link is ready to be flooded */
1648 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1649 return;
1650
1651 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1652 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1653 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1654 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1655 exti->ifp ? exti->ifp->name : "-");
1656
1657 /* Verify Area */
1658 if (exti->area == NULL) {
1659 osr_debug(
1660 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1661 __func__);
1662
1663 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1664 struct in_addr backbone = {.s_addr = INADDR_ANY};
1665 exti->area = ospf_area_lookup_by_area_id(top, backbone);
1666 if (exti->area == NULL) {
1667 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
1668 "EXT (%s): Unable to set Area", __func__);
1669 return;
1670 }
1671 }
1672 /* Set LSA header information */
1673 lsa.area = exti->area;
1674 lsa.data = &lsah;
1675 lsah.type = OSPF_OPAQUE_AREA_LSA;
1676 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1677 lsah.id.s_addr = htonl(tmp);
1678
1679 switch (opcode) {
1680 case REORIGINATE_THIS_LSA:
1681 ospf_opaque_lsa_reoriginate_schedule(
1682 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1683 OPAQUE_TYPE_EXTENDED_LINK_LSA);
1684 break;
1685 case REFRESH_THIS_LSA:
1686 ospf_opaque_lsa_refresh_schedule(&lsa);
1687 break;
1688 case FLUSH_THIS_LSA:
1689 ospf_opaque_lsa_flush_schedule(&lsa);
1690 break;
1691 }
1692 }
1693
1694 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1695 static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op)
1696 {
1697
1698 if (exti->stype == PREF_SID)
1699 ospf_ext_pref_lsa_schedule(exti, op);
1700 else
1701 ospf_ext_link_lsa_schedule(exti, op);
1702 }
1703
1704 /*
1705 * ------------------------------------
1706 * Followings are vty show functions.
1707 * ------------------------------------
1708 */
1709
1710 /* Cisco experimental SubTLV */
1711 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty *vty,
1712 struct tlv_header *tlvh)
1713 {
1714 struct ext_subtlv_rmt_itf_addr *top;
1715
1716 top = (struct ext_subtlv_rmt_itf_addr *)tlvh;
1717
1718 vty_out(vty,
1719 " Remote Interface Address Sub-TLV: Length %u\n Address: %s\n",
1720 ntohs(top->header.length), inet_ntoa(top->value));
1721
1722 return TLV_SIZE(tlvh);
1723 }
1724
1725 /* Adjacency SID SubTLV */
1726 static uint16_t show_vty_ext_link_adj_sid(struct vty *vty,
1727 struct tlv_header *tlvh)
1728 {
1729 struct ext_subtlv_adj_sid *top = (struct ext_subtlv_adj_sid *)tlvh;
1730
1731 vty_out(vty,
1732 " Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1733 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1734 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1735 : "Index",
1736 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1737 ? GET_LABEL(ntohl(top->value))
1738 : ntohl(top->value));
1739
1740 return TLV_SIZE(tlvh);
1741 }
1742
1743 /* LAN Adjacency SubTLV */
1744 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty *vty,
1745 struct tlv_header *tlvh)
1746 {
1747 struct ext_subtlv_lan_adj_sid *top =
1748 (struct ext_subtlv_lan_adj_sid *)tlvh;
1749
1750 vty_out(vty,
1751 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: %s\n\t%s: %u\n",
1752 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1753 inet_ntoa(top->neighbor_id),
1754 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1755 : "Index",
1756 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1757 ? GET_LABEL(ntohl(top->value))
1758 : ntohl(top->value));
1759
1760 return TLV_SIZE(tlvh);
1761 }
1762
1763 static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh)
1764 {
1765 vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1766 ntohs(tlvh->type), ntohs(tlvh->length));
1767
1768 return TLV_SIZE(tlvh);
1769 }
1770
1771 /* Extended Link Sub TLVs */
1772 static uint16_t show_vty_link_info(struct vty *vty, struct tlv_header *ext)
1773 {
1774 struct ext_tlv_link *top = (struct ext_tlv_link *)ext;
1775 struct tlv_header *tlvh;
1776 uint16_t length = ntohs(top->header.length) - 3 * sizeof(uint32_t);
1777 uint16_t sum = 0;
1778
1779 vty_out(vty,
1780 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1781 " Link ID: %s\n",
1782 ntohs(top->header.length), top->link_type,
1783 inet_ntoa(top->link_id));
1784 vty_out(vty, " Link data: %s\n", inet_ntoa(top->link_data));
1785
1786 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1787 + EXT_TLV_LINK_SIZE);
1788 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1789 switch (ntohs(tlvh->type)) {
1790 case EXT_SUBTLV_ADJ_SID:
1791 sum += show_vty_ext_link_adj_sid(vty, tlvh);
1792 break;
1793 case EXT_SUBTLV_LAN_ADJ_SID:
1794 sum += show_vty_ext_link_lan_adj_sid(vty, tlvh);
1795 break;
1796 case EXT_SUBTLV_RMT_ITF_ADDR:
1797 sum += show_vty_ext_link_rmt_itf_addr(vty, tlvh);
1798 break;
1799 default:
1800 sum += show_vty_unknown_tlv(vty, tlvh);
1801 break;
1802 }
1803 }
1804
1805 return sum + sizeof(struct ext_tlv_link);
1806 }
1807
1808 /* Extended Link TLVs */
1809 static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa)
1810 {
1811 struct lsa_header *lsah = lsa->data;
1812 struct tlv_header *tlvh;
1813 uint16_t length = 0, sum = 0;
1814
1815 /* Initialize TLV browsing */
1816 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1817
1818 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1819 tlvh = TLV_HDR_NEXT(tlvh)) {
1820 switch (ntohs(tlvh->type)) {
1821 case EXT_TLV_LINK:
1822 sum += show_vty_link_info(vty, tlvh);
1823 break;
1824 default:
1825 sum += show_vty_unknown_tlv(vty, tlvh);
1826 break;
1827 }
1828 }
1829 }
1830
1831 /* Prefix SID SubTLV */
1832 static uint16_t show_vty_ext_pref_pref_sid(struct vty *vty,
1833 struct tlv_header *tlvh)
1834 {
1835 struct ext_subtlv_prefix_sid *top =
1836 (struct ext_subtlv_prefix_sid *)tlvh;
1837
1838 vty_out(vty,
1839 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1840 ntohs(top->header.length), top->algorithm, top->flags,
1841 top->mtid,
1842 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) ? "Label"
1843 : "Index",
1844 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG)
1845 ? GET_LABEL(ntohl(top->value))
1846 : ntohl(top->value));
1847
1848 return TLV_SIZE(tlvh);
1849 }
1850
1851 /* Extended Prefix SubTLVs */
1852 static uint16_t show_vty_pref_info(struct vty *vty, struct tlv_header *ext)
1853 {
1854 struct ext_tlv_prefix *top = (struct ext_tlv_prefix *)ext;
1855 struct tlv_header *tlvh;
1856 uint16_t length = ntohs(top->header.length) - 2 * sizeof(uint32_t);
1857 uint16_t sum = 0;
1858
1859 vty_out(vty,
1860 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1861 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%u\n",
1862 ntohs(top->header.length), top->route_type, top->af, top->flags,
1863 inet_ntoa(top->address), top->pref_length);
1864
1865 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1866 + EXT_TLV_PREFIX_SIZE);
1867 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1868 switch (ntohs(tlvh->type)) {
1869 case EXT_SUBTLV_PREFIX_SID:
1870 sum += show_vty_ext_pref_pref_sid(vty, tlvh);
1871 break;
1872 default:
1873 sum += show_vty_unknown_tlv(vty, tlvh);
1874 break;
1875 }
1876 }
1877
1878 return sum + sizeof(struct ext_tlv_prefix);
1879 }
1880
1881 /* Extended Prefix TLVs */
1882 static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa)
1883 {
1884 struct lsa_header *lsah = lsa->data;
1885 struct tlv_header *tlvh;
1886 uint16_t length = 0, sum = 0;
1887
1888 /* Initialize TLV browsing */
1889 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1890
1891 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1892 tlvh = TLV_HDR_NEXT(tlvh)) {
1893 switch (ntohs(tlvh->type)) {
1894 case EXT_TLV_PREFIX:
1895 sum += show_vty_pref_info(vty, tlvh);
1896 break;
1897 default:
1898 sum += show_vty_unknown_tlv(vty, tlvh);
1899 break;
1900 }
1901 }
1902 }