2 * This is an implementation of RFC7684 OSPFv2 Prefix/Link Attribute
5 * Module name: Extended Prefix/Link Opaque LSA
7 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
8 * Author: Anselme Sawadogo <anselmesawadogo@gmail.com>
10 * Copyright (C) 2016 - 2018 Orange Labs http://www.orange.com
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)
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
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
43 #include "sockunion.h" /* for inet_aton() */
46 #include "libospf.h" /* for ospf interface types */
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"
67 /* Following structure are internal use only. */
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.
73 static struct ospf_ext_lp OspfEXT
;
76 * -----------------------------------------------------------------------
77 * Followings are initialize/terminate functions for Extended Prefix/Link
78 * Opaque LSA handling.
79 * -----------------------------------------------------------------------
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
);
105 * Extended Link/Prefix initialization
109 * @return - 0 if OK, <> 0 otherwise
111 int ospf_ext_init(void)
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
;
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 */
140 flog_warn(EC_OSPF_OPAQUE_REGISTRATION
,
141 "EXT (%s): Failed to register Extended Link LSA",
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 */
162 flog_warn(EC_OSPF_OPAQUE_REGISTRATION
,
163 "EXT (%s): Failed to register Extended Prefix LSA",
172 * Extended Link/Prefix termination function
177 void ospf_ext_term(void)
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
);
185 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA
,
186 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
188 list_delete(&OspfEXT
.iflist
);
190 OspfEXT
.enabled
= false;
196 * Extended Link/Prefix finish function
201 void ospf_ext_finish(void)
204 struct listnode
*node
;
205 struct ext_itf
*exti
;
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
);
212 OspfEXT
.enabled
= false;
216 * ---------------------------------------------------------------------
217 * Followings are control functions for Extended Prefix/Link Opaque LSA
218 * parameters management.
219 * ---------------------------------------------------------------------
222 /* Functions to free memory space */
223 static void del_ext_info(void *val
)
225 XFREE(MTYPE_OSPF_EXT_PARAMS
, val
);
228 /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
229 static uint32_t get_ext_pref_instance_value(void)
231 static uint32_t seqno
= 0;
233 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
236 seqno
= 1; /* Avoid zero. */
241 /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */
242 static uint32_t get_ext_link_instance_value(void)
244 static uint32_t seqno
= 0;
246 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
249 seqno
= 1; /* Avoid zero. */
254 /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
255 static struct ext_itf
*lookup_ext_by_ifp(struct interface
*ifp
)
257 struct listnode
*node
, *nnode
;
258 struct ext_itf
*exti
;
260 for (ALL_LIST_ELEMENTS(OspfEXT
.iflist
, node
, nnode
, exti
))
261 if (exti
->ifp
== ifp
)
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
)
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
));
276 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
277 if ((exti
->instance
== key
) && (exti
->type
== type
))
284 * ----------------------------------------------------------------------
285 * The underlying subsection defines setters and unsetters to create and
286 * delete tlvs and subtlvs
287 * ----------------------------------------------------------------------
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
)
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 */
302 exti
->prefix
.pref_length
= p
.prefixlen
;
303 exti
->prefix
.address
= p
.prefix
;
305 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
308 /* Extended Link TLV - RFC7684 section 3.1 */
309 static void set_ext_link(struct ext_itf
*exti
, uint8_t type
, struct in_addr id
,
313 TLV_TYPE(exti
->link
) = htons(EXT_TLV_LINK
);
314 /* Warning: Size must be adjust depending of subTLV's */
315 TLV_LEN(exti
->link
) = htons(EXT_TLV_LINK_SIZE
);
316 exti
->link
.link_type
= type
;
317 exti
->link
.link_id
= id
;
318 exti
->link
.link_data
= data
;
321 /* Prefix SID SubTLV - section 5 */
322 static void set_prefix_sid(struct ext_itf
*exti
, uint8_t algorithm
,
323 uint32_t value
, int value_type
, uint8_t flags
)
326 if ((algorithm
!= SR_ALGORITHM_SPF
)
327 && (algorithm
!= SR_ALGORITHM_STRICT_SPF
)) {
328 flog_err(EC_OSPF_INVALID_ALGORITHM
,
329 "EXT (%s): unrecognized algorithm, not SPF or S-SPF",
334 /* Update flags according to the type of value field: label or index */
335 if (value_type
== SID_LABEL
)
336 SET_FLAG(flags
, EXT_SUBTLV_PREFIX_SID_VFLG
);
338 /* set prefix sid subtlv for an extended prefix tlv */
339 TLV_TYPE(exti
->node_sid
) = htons(EXT_SUBTLV_PREFIX_SID
);
340 exti
->node_sid
.algorithm
= algorithm
;
341 exti
->node_sid
.flags
= flags
;
342 exti
->node_sid
.mtid
= 0; /* Multi-Topology is not supported */
344 /* Set Label or Index value */
345 if (value_type
== SID_LABEL
) {
346 TLV_LEN(exti
->node_sid
) =
347 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE
));
348 exti
->node_sid
.value
= htonl(SET_LABEL(value
));
350 TLV_LEN(exti
->node_sid
) =
351 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE
));
352 exti
->node_sid
.value
= htonl(value
);
356 /* Adjacency SID SubTLV - section 6.1 */
357 static void set_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
363 /* Determine which ADJ_SID must be set: nominal or backup */
365 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
373 TLV_TYPE(exti
->adj_sid
[index
]) = htons(EXT_SUBTLV_ADJ_SID
);
375 /* Only Local ADJ-SID is supported for the moment */
376 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
378 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
380 /* Adjust Length, Flags and Value depending on the type of Label */
381 if (value_type
== SID_LABEL
) {
382 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
383 TLV_LEN(exti
->adj_sid
[index
]) =
384 htons(SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE
));
385 exti
->adj_sid
[index
].value
= htonl(SET_LABEL(value
));
387 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
388 TLV_LEN(exti
->adj_sid
[index
]) =
389 htons(SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE
));
390 exti
->adj_sid
[index
].value
= htonl(value
);
393 exti
->adj_sid
[index
].flags
= flags
; /* Set computed flags */
394 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
395 exti
->adj_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
398 /* LAN Adjacency SID SubTLV - section 6.2 */
399 static void set_lan_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
400 int value_type
, struct in_addr neighbor_id
)
406 /* Determine which ADJ_SID must be set: nominal or backup */
408 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
416 TLV_TYPE(exti
->lan_sid
[index
]) = htons(EXT_SUBTLV_LAN_ADJ_SID
);
418 /* Only Local ADJ-SID is supported for the moment */
419 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
421 /* Adjust Length, Flags and Value depending on the type of Label */
422 if (value_type
== SID_LABEL
) {
423 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
424 TLV_LEN(exti
->lan_sid
[index
]) =
425 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE
));
426 exti
->lan_sid
[index
].value
= htonl(SET_LABEL(value
));
428 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
429 TLV_LEN(exti
->lan_sid
[index
]) =
430 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE
));
431 exti
->lan_sid
[index
].value
= htonl(value
);
434 exti
->lan_sid
[index
].flags
= flags
; /* Set computed flags */
435 exti
->lan_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
436 exti
->lan_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
437 exti
->lan_sid
[index
].neighbor_id
= neighbor_id
;
440 static void unset_adjacency_sid(struct ext_itf
*exti
)
442 /* Reset Adjacency TLV */
443 if (exti
->type
== ADJ_SID
) {
444 TLV_TYPE(exti
->adj_sid
[0]) = 0;
445 TLV_TYPE(exti
->adj_sid
[1]) = 0;
447 /* or Lan-Adjacency TLV */
448 if (exti
->type
== LAN_ADJ_SID
) {
449 TLV_TYPE(exti
->lan_sid
[0]) = 0;
450 TLV_TYPE(exti
->lan_sid
[1]) = 0;
454 /* Experimental SubTLV from Cisco */
455 static void set_rmt_itf_addr(struct ext_itf
*exti
, struct in_addr rmtif
)
458 TLV_TYPE(exti
->rmt_itf_addr
) = htons(EXT_SUBTLV_RMT_ITF_ADDR
);
459 TLV_LEN(exti
->rmt_itf_addr
) = htons(sizeof(struct in_addr
));
460 exti
->rmt_itf_addr
.value
= rmtif
;
463 /* Delete Extended LSA */
464 static void ospf_extended_lsa_delete(struct ext_itf
*exti
)
467 /* Avoid deleting LSA if Extended is not enable */
468 if (!OspfEXT
.enabled
)
471 /* Process only Active Extended Prefix/Link LSA */
472 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
475 osr_debug("EXT (%s): Disable %s%s%s-SID on interface %s", __func__
,
476 exti
->stype
== LOCAL_SID
? "Prefix" : "",
477 exti
->stype
== ADJ_SID
? "Adjacency" : "",
478 exti
->stype
== LAN_ADJ_SID
? "LAN-Adjacency" : "",
481 /* Flush LSA if already engaged */
482 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
483 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
484 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
487 /* De-activate this Extended Prefix/Link and remove corresponding
488 * Segment-Routing Prefix-SID or (LAN)-ADJ-SID */
489 if (exti
->stype
== ADJ_SID
|| exti
->stype
== LAN_ADJ_SID
)
490 ospf_ext_link_delete_adj_sid(exti
);
492 ospf_sr_ext_itf_delete(exti
);
496 * Update Extended prefix SID index for Loopback interface type
498 * @param ifname - Loopback interface name
499 * @param index - new value for the prefix SID of this interface
500 * @param p - prefix for this interface or NULL if Extended Prefix
503 * @return instance number if update is OK, 0 otherwise
505 uint32_t ospf_ext_schedule_prefix_index(struct interface
*ifp
, uint32_t index
,
506 struct prefix_ipv4
*p
, uint8_t flags
)
509 struct ext_itf
*exti
;
511 /* Find Extended Prefix interface */
512 exti
= lookup_ext_by_ifp(ifp
);
517 osr_debug("EXT (%s): Schedule new prefix %pFX with index %u on interface %s", __func__
, p
, index
, ifp
->name
);
519 /* Set first Extended Prefix then the Prefix SID information */
520 set_ext_prefix(exti
, OSPF_PATH_INTRA_AREA
, EXT_TLV_PREF_NFLG
,
522 set_prefix_sid(exti
, SR_ALGORITHM_SPF
, index
, SID_INDEX
, flags
);
524 /* Try to Schedule LSA */
525 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
526 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
527 ospf_ext_pref_lsa_schedule(exti
,
530 ospf_ext_pref_lsa_schedule(
531 exti
, REORIGINATE_THIS_LSA
);
534 osr_debug("EXT (%s): Remove prefix for interface %s", __func__
,
537 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
538 ospf_ext_pref_lsa_schedule(exti
, FLUSH_THIS_LSA
);
541 return SET_OPAQUE_LSID(exti
->type
, exti
->instance
);
545 * Update Adjacecny-SID for Extended Link LSA
547 * @param exti Extended Link information
549 static void ospf_ext_link_update_adj_sid(struct ext_itf
*exti
)
552 mpls_label_t bck_label
;
554 /* Process only (LAN)Adjacency-SID Type */
555 if (exti
->stype
!= ADJ_SID
&& exti
->stype
!= LAN_ADJ_SID
)
558 /* Request Primary & Backup Labels from Label Manager */
559 bck_label
= ospf_sr_local_block_request_label();
560 label
= ospf_sr_local_block_request_label();
561 if (bck_label
== MPLS_INVALID_LABEL
|| label
== MPLS_INVALID_LABEL
) {
562 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
563 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
567 /* Set Adjacency-SID, backup first */
568 if (exti
->stype
== ADJ_SID
) {
569 set_adj_sid(exti
, true, bck_label
, SID_LABEL
);
570 set_adj_sid(exti
, false, label
, SID_LABEL
);
572 set_lan_adj_sid(exti
, true, bck_label
, SID_LABEL
,
573 exti
->lan_sid
[0].neighbor_id
);
574 set_lan_adj_sid(exti
, false, label
, SID_LABEL
,
575 exti
->lan_sid
[1].neighbor_id
);
578 /* Finally, add corresponding SR Link in SRDB & MPLS LFIB */
579 SET_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
);
580 ospf_sr_ext_itf_add(exti
);
584 * Delete Adjacecny-SID for Extended Link LSA
586 * @param exti Extended Link information
588 static void ospf_ext_link_delete_adj_sid(struct ext_itf
*exti
)
590 /* Process only (LAN)Adjacency-SID Type */
591 if (exti
->stype
!= ADJ_SID
&& exti
->stype
!= LAN_ADJ_SID
)
594 /* Release Primary & Backup Labels from Label Manager */
595 if (exti
->stype
== ADJ_SID
) {
596 ospf_sr_local_block_release_label(exti
->adj_sid
[0].value
);
597 ospf_sr_local_block_release_label(exti
->adj_sid
[1].value
);
599 ospf_sr_local_block_release_label(exti
->lan_sid
[0].value
);
600 ospf_sr_local_block_release_label(exti
->lan_sid
[1].value
);
602 /* And reset corresponding TLV */
603 unset_adjacency_sid(exti
);
605 /* Finally, remove corresponding SR Link in SRDB & MPLS LFIB */
606 UNSET_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
);
607 ospf_sr_ext_itf_delete(exti
);
611 * Update Extended Link LSA once Segment Routing Label Block has been changed.
613 void ospf_ext_link_srlb_update(void)
615 struct listnode
*node
;
616 struct ext_itf
*exti
;
619 osr_debug("EXT (%s): Update Extended Links with new SRLB", __func__
);
621 /* Update all Extended Link Adjaceny-SID */
622 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
623 /* Skip Extended Prefix */
624 if (exti
->stype
== PREF_SID
|| exti
->stype
== LOCAL_SID
)
627 /* Skip inactive Extended Link */
628 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
631 ospf_ext_link_update_adj_sid(exti
);
636 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
638 * @param enable To activate or not Segment Routing Extended LSA flooding
642 void ospf_ext_update_sr(bool enable
)
644 struct listnode
*node
;
645 struct ext_itf
*exti
;
647 osr_debug("EXT (%s): %s Extended LSAs for Segment Routing ", __func__
,
648 enable
? "Enable" : "Disable");
651 OspfEXT
.enabled
= true;
653 /* Refresh LSAs if already engaged or originate */
654 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
655 /* Skip Inactive Extended Link */
656 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
659 /* Update Extended Link (LAN)Adj-SID if not set */
660 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
))
661 ospf_ext_link_update_adj_sid(exti
);
663 /* Finally, flood the extended Link */
664 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
665 ospf_ext_lsa_schedule(exti
, REFRESH_THIS_LSA
);
667 ospf_ext_lsa_schedule(exti
,
668 REORIGINATE_THIS_LSA
);
671 /* Start by Removing Extended LSA */
672 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
673 ospf_extended_lsa_delete(exti
);
675 /* And then disable Extended Link/Prefix */
676 OspfEXT
.enabled
= false;
681 * -----------------------------------------------------------------------
682 * Followings are callback functions against generic Opaque-LSAs handling
683 * -----------------------------------------------------------------------
686 /* Add new Interface in Extended Interface List */
687 static int ospf_ext_link_new_if(struct interface
*ifp
)
692 if (lookup_ext_by_ifp(ifp
) != NULL
) {
693 rc
= 0; /* Do nothing here. */
697 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS
, sizeof(struct ext_itf
));
699 /* initialize new information and link back the interface */
701 new->flags
= EXT_LPFLG_LSA_INACTIVE
;
703 listnode_add(OspfEXT
.iflist
, new);
709 /* Remove existing Interface from Extended Interface List */
710 static int ospf_ext_link_del_if(struct interface
*ifp
)
712 struct ext_itf
*exti
;
715 exti
= lookup_ext_by_ifp(ifp
);
717 /* Flush LSA and remove Adjacency SID */
718 ospf_extended_lsa_delete(exti
);
720 /* Dequeue listnode entry from the list. */
721 listnode_delete(OspfEXT
.iflist
, exti
);
723 XFREE(MTYPE_OSPF_EXT_PARAMS
, exti
);
727 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
728 "EXT (%s): interface %s is not found", __func__
,
729 ifp
? ifp
->name
: "-");
736 * Determine if an Interface belongs to an Extended Link Adjacency or
737 * Extended Prefix SID type and allocate new instance value accordingly
739 static void ospf_ext_ism_change(struct ospf_interface
*oi
, int old_status
)
741 struct ext_itf
*exti
;
743 /* Get interface information for Segment Routing */
744 exti
= lookup_ext_by_ifp(oi
->ifp
);
746 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
747 "EXT (%s): Cannot get Extended info. from OI(%s)",
748 __func__
, IF_NAME(oi
));
752 /* Reset Extended information if ospf interface goes Down */
753 if (oi
->state
== ISM_Down
) {
754 ospf_extended_lsa_delete(exti
);
756 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
760 /* Determine if interface is related to a Prefix or an Adjacency SID */
761 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
762 exti
->stype
= PREF_SID
;
763 exti
->type
= OPAQUE_TYPE_EXTENDED_PREFIX_LSA
;
764 exti
->instance
= get_ext_pref_instance_value();
765 exti
->area
= oi
->area
;
767 /* Complete SRDB if the interface belongs to a Prefix */
768 if (OspfEXT
.enabled
) {
769 osr_debug("EXT (%s): Set Prefix SID to interface %s ",
770 __func__
, oi
->ifp
->name
);
771 ospf_sr_update_local_prefix(oi
->ifp
, oi
->address
);
774 /* Determine if interface is related to Adj. or LAN Adj. SID */
775 if (oi
->state
== ISM_DR
)
776 exti
->stype
= LAN_ADJ_SID
;
778 exti
->stype
= ADJ_SID
;
780 exti
->type
= OPAQUE_TYPE_EXTENDED_LINK_LSA
;
781 exti
->instance
= get_ext_link_instance_value();
782 exti
->area
= oi
->area
;
785 * Note: Adjacency SID information are completed when ospf
786 * adjacency become up see ospf_ext_link_nsm_change()
790 "EXT (%s): Set %sAdjacency SID for interface %s ",
791 __func__
, exti
->stype
== ADJ_SID
? "" : "LAN-",
797 * Finish Extended Link configuration and flood corresponding LSA
798 * when OSPF adjacency on this link fire up
800 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
)
802 struct ospf_interface
*oi
= nbr
->oi
;
803 struct ext_itf
*exti
;
805 /* Process Link only when neighbor old or new state is NSM Full */
806 if (nbr
->state
!= NSM_Full
&& old_status
!= NSM_Full
)
809 /* Get interface information for Segment Routing */
810 exti
= lookup_ext_by_ifp(oi
->ifp
);
812 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
813 "EXT (%s): Cannot get Extended info. from OI(%s)",
814 __func__
, IF_NAME(oi
));
818 /* Check that we have a valid area and ospf context */
819 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
820 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
821 "EXT (%s): Cannot refer to OSPF from OI(%s)",
822 __func__
, IF_NAME(oi
));
826 /* Remove Extended Link if Neighbor State goes Down or Deleted */
828 && (nbr
->state
== NSM_Down
|| nbr
->state
== NSM_Deleted
)) {
829 ospf_ext_link_delete_adj_sid(exti
);
830 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
831 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
832 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
836 /* Keep Area information in combination with SR info. */
837 exti
->area
= oi
->area
;
839 /* Process only Adjacency/LAN SID */
840 if (exti
->stype
== PREF_SID
)
844 case ISM_PointToPoint
:
845 /* Segment ID is an Adjacency one */
846 exti
->stype
= ADJ_SID
;
848 /* Set Extended Link TLV with link_id == Nbr Router ID */
849 set_ext_link(exti
, OSPF_IFTYPE_POINTOPOINT
, nbr
->router_id
,
850 oi
->address
->u
.prefix4
);
852 /* And Remote Interface address */
853 set_rmt_itf_addr(exti
, nbr
->address
.u
.prefix4
);
858 /* Segment ID is a LAN Adjacency for the DR only */
859 exti
->stype
= LAN_ADJ_SID
;
861 /* Set Extended Link TLV with link_id == DR */
862 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
863 oi
->address
->u
.prefix4
);
865 /* Set Neighbor ID */
866 exti
->lan_sid
[0].neighbor_id
= nbr
->router_id
;
867 exti
->lan_sid
[1].neighbor_id
= nbr
->router_id
;
873 /* Segment ID is an Adjacency if not the DR */
874 exti
->stype
= ADJ_SID
;
876 /* Set Extended Link TLV with link_id == DR */
877 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
878 oi
->address
->u
.prefix4
);
883 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
))
884 ospf_ext_link_delete_adj_sid(exti
);
885 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
886 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
887 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
891 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
893 if (OspfEXT
.enabled
) {
894 osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
895 __func__
, exti
->stype
== ADJ_SID
? "" : "LAN-",
898 /* Update (LAN)Adjacency SID */
899 ospf_ext_link_update_adj_sid(exti
);
901 /* flood this links params if everything is ok */
902 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
903 ospf_ext_link_lsa_schedule(exti
, REFRESH_THIS_LSA
);
905 ospf_ext_link_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
909 /* Callbacks to handle Extended Link Segment Routing LSA information */
910 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
)
914 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
919 /* Process only Opaque LSA */
920 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
921 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
924 /* Process only Extended Link LSA */
925 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
926 != OPAQUE_TYPE_EXTENDED_LINK_LSA
)
929 /* Check if it is not my LSA */
930 if (IS_LSA_SELF(lsa
))
933 /* Check if Extended is enable */
934 if (!OspfEXT
.enabled
)
937 /* Call Segment Routing LSA update or deletion */
938 if (!IS_LSA_MAXAGE(lsa
))
939 ospf_sr_ext_link_lsa_update(lsa
);
941 ospf_sr_ext_link_lsa_delete(lsa
);
946 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
947 static int ospf_ext_pref_lsa_update(struct ospf_lsa
*lsa
)
952 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
957 /* Process only Opaque LSA */
958 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
959 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
962 /* Process only Extended Prefix LSA */
963 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
964 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA
)
967 /* Check if it is not my LSA */
968 if (IS_LSA_SELF(lsa
))
971 /* Check if Extended is enable */
972 if (!OspfEXT
.enabled
)
975 /* Call Segment Routing LSA update or deletion */
976 if (!IS_LSA_MAXAGE(lsa
))
977 ospf_sr_ext_prefix_lsa_update(lsa
);
979 ospf_sr_ext_prefix_lsa_delete(lsa
);
985 * -------------------------------------------------------
986 * Followings are OSPF protocol processing functions for
987 * Extended Prefix/Link Opaque LSA
988 * -------------------------------------------------------
991 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
993 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
996 static void build_tlv(struct stream
*s
, struct tlv_header
*tlvh
)
999 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
1000 build_tlv_header(s
, tlvh
);
1001 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
1005 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
1006 static void ospf_ext_pref_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
1010 if ((exti
== NULL
) || (exti
->stype
!= PREF_SID
))
1013 /* Adjust Extended Prefix TLV size */
1014 TLV_LEN(exti
->prefix
) = htons(ntohs(TLV_LEN(exti
->node_sid
))
1015 + EXT_TLV_PREFIX_SIZE
+ TLV_HDR_SIZE
);
1017 /* Build LSA body for an Extended Prefix TLV */
1018 build_tlv_header(s
, &exti
->prefix
.header
);
1019 stream_put(s
, TLV_DATA(&exti
->prefix
.header
), EXT_TLV_PREFIX_SIZE
);
1020 /* Then add Prefix SID SubTLV */
1021 build_tlv(s
, &exti
->node_sid
.header
);
1024 /* Build an Extended Link Opaque LSA body for extended link TLV */
1025 static void ospf_ext_link_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
1031 || ((exti
->stype
!= ADJ_SID
) && (exti
->stype
!= LAN_ADJ_SID
)))
1034 if (exti
->stype
== ADJ_SID
) {
1035 /* Adjust Extended Link TLV size for Adj. SID */
1036 size
= EXT_TLV_LINK_SIZE
+ 2 * EXT_SUBTLV_ADJ_SID_SIZE
1038 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
1039 size
= size
+ EXT_SUBTLV_RMT_ITF_ADDR_SIZE
1041 TLV_LEN(exti
->link
) = htons(size
);
1043 /* Build LSA body for an Extended Link TLV with Adj. SID */
1044 build_tlv_header(s
, &exti
->link
.header
);
1045 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
1046 /* then add Adjacency SubTLVs */
1047 build_tlv(s
, &exti
->adj_sid
[1].header
);
1048 build_tlv(s
, &exti
->adj_sid
[0].header
);
1050 /* Add Cisco experimental SubTLV if interface is PtoP */
1051 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
1052 build_tlv(s
, &exti
->rmt_itf_addr
.header
);
1054 /* Adjust Extended Link TLV size for LAN SID */
1055 size
= EXT_TLV_LINK_SIZE
1056 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE
+ TLV_HDR_SIZE
);
1057 TLV_LEN(exti
->link
) = htons(size
);
1059 /* Build LSA body for an Extended Link TLV with LAN SID */
1060 build_tlv_header(s
, &exti
->link
.header
);
1061 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
1062 /* then add LAN-Adjacency SubTLVs */
1063 build_tlv(s
, &exti
->lan_sid
[1].header
);
1064 build_tlv(s
, &exti
->lan_sid
[0].header
);
1068 /* Create new Extended Prefix opaque-LSA for every extended prefix */
1069 static struct ospf_lsa
*ospf_ext_pref_lsa_new(struct ospf_area
*area
,
1070 struct ext_itf
*exti
)
1073 struct lsa_header
*lsah
;
1074 struct ospf_lsa
*new = NULL
;
1076 uint8_t options
, lsa_type
;
1077 struct in_addr lsa_id
;
1078 struct in_addr router_id
;
1086 /* Create a stream for LSA. */
1087 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1089 /* Prepare LSA Header */
1090 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1092 lsa_type
= OspfEXT
.scope
;
1095 * LSA ID is a variable number identifying different instances of
1096 * Extended Prefix Opaque LSA from the same router see RFC 7684
1098 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1099 lsa_id
.s_addr
= htonl(tmp
);
1101 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1103 /* Fix Options and Router ID depending of the flooding scope */
1104 if ((OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
) || (area
== NULL
)) {
1105 options
= OSPF_OPTION_E
;
1106 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1107 router_id
.s_addr
= top
? top
->router_id
.s_addr
: 0;
1109 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1110 options
|= LSA_OPTIONS_NSSA_GET(area
);
1111 router_id
= area
->ospf
->router_id
;
1114 /* Set opaque-LSA header fields. */
1115 lsa_header_set(s
, options
, lsa_type
, lsa_id
, router_id
);
1118 "EXT (%s): LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Prefix Opaque LSA instance",
1119 __func__
, lsa_type
, &lsa_id
);
1121 /* Set opaque-LSA body fields. */
1122 ospf_ext_pref_lsa_body_set(s
, exti
);
1125 length
= stream_get_endp(s
);
1126 lsah
->length
= htons(length
);
1128 /* Now, create an OSPF LSA instance. */
1129 new = ospf_lsa_new_and_data(length
);
1131 /* Segment Routing belongs only to default VRF */
1132 new->vrf_id
= VRF_DEFAULT
;
1134 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1135 memcpy(new->data
, lsah
, length
);
1141 /* Create new Extended Link opaque-LSA for every extended link TLV */
1142 static struct ospf_lsa
*ospf_ext_link_lsa_new(struct ospf_area
*area
,
1143 struct ext_itf
*exti
)
1146 struct lsa_header
*lsah
;
1147 struct ospf_lsa
*new = NULL
;
1148 uint8_t options
, lsa_type
;
1149 struct in_addr lsa_id
;
1157 /* Create a stream for LSA. */
1158 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1159 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1161 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1162 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1163 options
|= LSA_OPTIONS_NSSA_GET(area
);
1164 /* Extended Link Opaque LSA are only flooded within an area */
1165 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1168 * LSA ID is a variable number identifying different instances of
1169 * Extended Link Opaque LSA from the same router see RFC 7684
1171 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1172 lsa_id
.s_addr
= htonl(tmp
);
1175 "EXT (%s) LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Link Opaque LSA instance",
1176 __func__
, lsa_type
, &lsa_id
);
1178 /* Set opaque-LSA header fields. */
1179 lsa_header_set(s
, options
, lsa_type
, lsa_id
, area
->ospf
->router_id
);
1181 /* Set opaque-LSA body fields. */
1182 ospf_ext_link_lsa_body_set(s
, exti
);
1185 length
= stream_get_endp(s
);
1186 lsah
->length
= htons(length
);
1188 /* Now, create an OSPF LSA instance. */
1189 new = ospf_lsa_new_and_data(length
);
1191 /* Segment Routing belongs only to default VRF */
1192 new->vrf_id
= VRF_DEFAULT
;
1194 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1195 memcpy(new->data
, lsah
, length
);
1202 * Process the origination of an Extended Prefix Opaque LSA
1203 * for every extended prefix TLV
1205 static int ospf_ext_pref_lsa_originate1(struct ospf_area
*area
,
1206 struct ext_itf
*exti
)
1208 struct ospf_lsa
*new;
1212 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1213 new = ospf_ext_pref_lsa_new(area
, exti
);
1215 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1216 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1220 /* Install this LSA into LSDB. */
1221 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1222 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1223 "EXT (%s): ospf_lsa_install() error", __func__
);
1224 ospf_lsa_unlock(&new);
1228 /* Now this Extended Prefix Opaque LSA info parameter entry has
1231 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1233 /* Update new LSA origination count. */
1234 area
->ospf
->lsa_originate_count
++;
1236 /* Flood new LSA through area. */
1237 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1240 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSAExtended Prefix Opaque LSA: Area(%pI4), Link(%s)",
1241 __func__
, new->data
->type
, &new->data
->id
,
1242 &area
->area_id
, exti
->ifp
->name
);
1243 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1244 ospf_lsa_header_dump(new->data
);
1252 * Process the origination of an Extended Link Opaque LSA
1253 * for every extended link TLV
1255 static int ospf_ext_link_lsa_originate1(struct ospf_area
*area
,
1256 struct ext_itf
*exti
)
1258 struct ospf_lsa
*new;
1261 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1262 new = ospf_ext_link_lsa_new(area
, exti
);
1264 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1265 "EXT (%s): ospf_ext_link_lsa_new() error", __func__
);
1269 /* Install this LSA into LSDB. */
1270 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1271 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1272 "EXT (%s): ospf_lsa_install() error", __func__
);
1273 ospf_lsa_unlock(&new);
1277 /* Now this link-parameter entry has associated LSA. */
1278 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1280 /* Update new LSA origination count. */
1281 area
->ospf
->lsa_originate_count
++;
1283 /* Flood new LSA through area. */
1284 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1287 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSA Extended Link Opaque LSA: Area(%pI4), Link(%s)",
1288 __func__
, new->data
->type
, &new->data
->id
,
1289 &area
->area_id
, exti
->ifp
->name
);
1290 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1291 ospf_lsa_header_dump(new->data
);
1298 /* Trigger the origination of Extended Prefix Opaque LSAs */
1299 static int ospf_ext_pref_lsa_originate(void *arg
)
1301 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1302 struct listnode
*node
;
1303 struct ext_itf
*exti
;
1306 if (!OspfEXT
.enabled
) {
1308 "EXT (%s): Segment Routing functionality is Disabled now",
1310 rc
= 0; /* This is not an error case. */
1313 osr_debug("EXT (%s): Start Originate Prefix LSA for area %pI4",
1314 __func__
, &area
->area_id
);
1316 /* Check if Extended Prefix Opaque LSA is already engaged */
1317 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1319 /* Process only Prefix SID */
1320 if (exti
->stype
!= PREF_SID
)
1323 /* Process only Extended Prefix with valid Area ID */
1324 if ((exti
->area
== NULL
)
1325 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1328 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1329 if (CHECK_FLAG(exti
->flags
,
1330 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1332 EC_OSPF_EXT_LSA_UNEXPECTED
,
1333 "EXT (%s): Refresh instead of Originate",
1335 UNSET_FLAG(exti
->flags
,
1336 EXT_LPFLG_LSA_FORCED_REFRESH
);
1337 ospf_ext_pref_lsa_schedule(exti
,
1343 /* Ok, let's try to originate an LSA */
1345 "EXT (%s): Let's finally re-originate the LSA 7.0.0.%u for Itf %s", __func__
, exti
->instance
,
1346 exti
->ifp
? exti
->ifp
->name
: "");
1347 ospf_ext_pref_lsa_originate1(area
, exti
);
1354 /* Trigger the origination of Extended Link Opaque LSAs */
1355 static int ospf_ext_link_lsa_originate(void *arg
)
1357 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1358 struct listnode
*node
;
1359 struct ext_itf
*exti
;
1362 if (!OspfEXT
.enabled
) {
1364 "EXT (%s): Segment Routing functionality is Disabled now",
1366 rc
= 0; /* This is not an error case. */
1370 /* Check if Extended Prefix Opaque LSA is already engaged */
1371 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1372 /* Process only Adjacency or LAN SID */
1373 if (exti
->stype
== PREF_SID
)
1376 /* Skip Inactive Extended Link */
1377 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
1380 /* Process only Extended Link with valid Area ID */
1381 if ((exti
->area
== NULL
)
1382 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1385 /* Check if LSA not already engaged */
1386 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1387 if (CHECK_FLAG(exti
->flags
,
1388 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1390 EC_OSPF_EXT_LSA_UNEXPECTED
,
1391 "EXT (%s): Refresh instead of Originate",
1393 UNSET_FLAG(exti
->flags
,
1394 EXT_LPFLG_LSA_FORCED_REFRESH
);
1395 ospf_ext_link_lsa_schedule(exti
,
1401 /* Ok, let's try to originate an LSA */
1403 "EXT (%s): Let's finally reoriginate the LSA 8.0.0.%u for Itf %s through the Area %pI4", __func__
,
1404 exti
->instance
, exti
->ifp
? exti
->ifp
->name
: "-",
1406 ospf_ext_link_lsa_originate1(area
, exti
);
1413 /* Refresh an Extended Prefix Opaque LSA */
1414 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
)
1416 struct ospf_lsa
*new = NULL
;
1417 struct ospf_area
*area
= lsa
->area
;
1419 struct ext_itf
*exti
;
1421 if (!OspfEXT
.enabled
) {
1423 * This LSA must have flushed before due to Extended Prefix
1424 * Opaque LSA status change.
1425 * It seems a slip among routers in the routing domain.
1428 "EXT (%s): Segment Routing functionality is Disabled",
1430 /* Flush it anyway. */
1431 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1434 /* Lookup this lsa corresponding Extended parameters */
1435 exti
= lookup_ext_by_instance(lsa
);
1437 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1438 "EXT (%s): Invalid parameter LSA ID", __func__
);
1439 /* Flush it anyway. */
1440 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1443 /* Check if Interface was not disable in the interval */
1444 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1445 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1446 "EXT (%s): Interface was Disabled: Flush it!",
1448 /* Flush it anyway. */
1449 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1452 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1453 if (IS_LSA_MAXAGE(lsa
)) {
1455 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1456 ospf_opaque_lsa_flush_schedule(lsa
);
1460 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1461 new = ospf_ext_pref_lsa_new(area
, exti
);
1464 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1465 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1468 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1471 * Install this LSA into LSDB
1472 * Given "lsa" will be freed in the next function
1473 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1474 * ospf_lookup() to get ospf instance
1479 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1481 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1482 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1483 "EXT (%s): ospf_lsa_install() error", __func__
);
1484 ospf_lsa_unlock(&new);
1488 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1489 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1491 /* Debug logging. */
1492 osr_debug("EXT (%s): LSA[Type%u:%pI4] Refresh Extended Prefix LSA",
1493 __func__
, new->data
->type
, &new->data
->id
);
1494 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1495 ospf_lsa_header_dump(new->data
);
1501 /* Refresh an Extended Link Opaque LSA */
1502 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
)
1504 struct ext_itf
*exti
;
1505 struct ospf_area
*area
= lsa
->area
;
1506 struct ospf
*top
= area
->ospf
;
1507 struct ospf_lsa
*new = NULL
;
1509 if (!OspfEXT
.enabled
) {
1511 * This LSA must have flushed before due to OSPF-SR status
1512 * change. It seems a slip among routers in the routing domain.
1514 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1516 /* Flush it anyway. */
1517 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1520 /* Lookup this LSA corresponding Extended parameters */
1521 exti
= lookup_ext_by_instance(lsa
);
1523 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1524 "EXT (%s): Invalid parameter LSA ID", __func__
);
1525 /* Flush it anyway. */
1526 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1529 /* Check if Interface was not disable in the interval */
1530 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1531 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1532 "EXT (%s): Interface was Disabled: Flush it!",
1534 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1537 /* If the lsa's age reached to MaxAge, start flushing procedure */
1538 if (IS_LSA_MAXAGE(lsa
)) {
1540 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1541 ospf_opaque_lsa_flush_schedule(lsa
);
1545 /* Create new Opaque-LSA/Extended Link instance */
1546 new = ospf_ext_link_lsa_new(area
, exti
);
1548 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1549 "EXT (%s): Error creating new LSA", __func__
);
1552 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1554 /* Install this LSA into LSDB. */
1555 /* Given "lsa" will be freed in the next function */
1556 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1557 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1558 "EXT (%s): Error installing new LSA", __func__
);
1559 ospf_lsa_unlock(&new);
1563 /* Flood updated LSA through the link Area according to the RFC7684 */
1564 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1566 /* Debug logging. */
1567 osr_debug("EXT (%s): LSA[Type%u:%pI4]: Refresh Extended Link LSA",
1568 __func__
, new->data
->type
, &new->data
->id
);
1569 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1570 ospf_lsa_header_dump(new->data
);
1575 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1576 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
1577 enum lsa_opcode opcode
)
1579 struct ospf_lsa lsa
;
1580 struct lsa_header lsah
;
1584 memset(&lsa
, 0, sizeof(lsa
));
1585 memset(&lsah
, 0, sizeof(lsah
));
1591 /* Check if the corresponding link is ready to be flooded */
1592 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1595 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1596 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1597 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1598 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1599 exti
->ifp
? exti
->ifp
->name
: "-");
1602 if (exti
->area
== NULL
) {
1604 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1607 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1608 struct in_addr backbone
= {.s_addr
= INADDR_ANY
};
1609 exti
->area
= ospf_area_lookup_by_area_id(top
, backbone
);
1610 if (exti
->area
== NULL
) {
1611 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1612 "EXT (%s): Unable to set Area", __func__
);
1616 /* Set LSA header information */
1617 lsa
.area
= exti
->area
;
1619 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1620 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1621 lsah
.id
.s_addr
= htonl(tmp
);
1624 case REORIGINATE_THIS_LSA
:
1625 ospf_opaque_lsa_reoriginate_schedule(
1626 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1627 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
1629 case REFRESH_THIS_LSA
:
1630 ospf_opaque_lsa_refresh_schedule(&lsa
);
1632 case FLUSH_THIS_LSA
:
1633 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1634 ospf_opaque_lsa_flush_schedule(&lsa
);
1639 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1640 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
1641 enum lsa_opcode opcode
)
1643 struct ospf_lsa lsa
;
1644 struct lsa_header lsah
;
1648 memset(&lsa
, 0, sizeof(lsa
));
1649 memset(&lsah
, 0, sizeof(lsah
));
1655 /* Check if the corresponding link is ready to be flooded */
1656 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1659 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1660 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1661 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1662 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1663 exti
->ifp
? exti
->ifp
->name
: "-");
1666 if (exti
->area
== NULL
) {
1668 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1671 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1672 struct in_addr backbone
= {.s_addr
= INADDR_ANY
};
1673 exti
->area
= ospf_area_lookup_by_area_id(top
, backbone
);
1674 if (exti
->area
== NULL
) {
1675 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1676 "EXT (%s): Unable to set Area", __func__
);
1680 /* Set LSA header information */
1681 lsa
.area
= exti
->area
;
1683 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1684 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1685 lsah
.id
.s_addr
= htonl(tmp
);
1688 case REORIGINATE_THIS_LSA
:
1689 ospf_opaque_lsa_reoriginate_schedule(
1690 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1691 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
1693 case REFRESH_THIS_LSA
:
1694 ospf_opaque_lsa_refresh_schedule(&lsa
);
1696 case FLUSH_THIS_LSA
:
1697 ospf_opaque_lsa_flush_schedule(&lsa
);
1702 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1703 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
)
1706 if (exti
->stype
== PREF_SID
)
1707 ospf_ext_pref_lsa_schedule(exti
, op
);
1709 ospf_ext_link_lsa_schedule(exti
, op
);
1713 * ------------------------------------
1714 * Followings are vty show functions.
1715 * ------------------------------------
1718 #define check_tlv_size(size, msg) \
1720 if (ntohs(tlvh->length) != size) { \
1721 vty_out(vty, " Wrong %s TLV size: %d(%d). Abort!\n", \
1722 msg, ntohs(tlvh->length), size); \
1723 return size + TLV_HDR_SIZE; \
1727 /* Cisco experimental SubTLV */
1728 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty
*vty
,
1729 struct tlv_header
*tlvh
)
1731 struct ext_subtlv_rmt_itf_addr
*top
=
1732 (struct ext_subtlv_rmt_itf_addr
*)tlvh
;
1734 check_tlv_size(EXT_SUBTLV_RMT_ITF_ADDR_SIZE
, "Remote Itf. Address");
1737 " Remote Interface Address Sub-TLV: Length %u\n Address: %pI4\n",
1738 ntohs(top
->header
.length
), &top
->value
);
1740 return TLV_SIZE(tlvh
);
1743 /* Adjacency SID SubTLV */
1744 static uint16_t show_vty_ext_link_adj_sid(struct vty
*vty
,
1745 struct tlv_header
*tlvh
)
1747 struct ext_subtlv_adj_sid
*top
= (struct ext_subtlv_adj_sid
*)tlvh
;
1749 check_tlv_size(EXT_SUBTLV_ADJ_SID_SIZE
, "Adjacency SID");
1752 " Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1753 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1754 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1756 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1757 ? GET_LABEL(ntohl(top
->value
))
1758 : ntohl(top
->value
));
1760 return TLV_SIZE(tlvh
);
1763 /* LAN Adjacency SubTLV */
1764 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty
*vty
,
1765 struct tlv_header
*tlvh
)
1767 struct ext_subtlv_lan_adj_sid
*top
=
1768 (struct ext_subtlv_lan_adj_sid
*)tlvh
;
1770 check_tlv_size(EXT_SUBTLV_LAN_ADJ_SID_SIZE
, "Lan-Adjacency SID");
1773 " 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",
1774 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1776 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1778 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1779 ? GET_LABEL(ntohl(top
->value
))
1780 : ntohl(top
->value
));
1782 return TLV_SIZE(tlvh
);
1785 static uint16_t show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
,
1788 if (TLV_SIZE(tlvh
) > buf_size
) {
1789 vty_out(vty
, " TLV size %d exceeds buffer size. Abort!",
1794 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1795 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
1797 return TLV_SIZE(tlvh
);
1800 /* Extended Link Sub TLVs */
1801 static uint16_t show_vty_link_info(struct vty
*vty
, struct tlv_header
*ext
,
1804 struct ext_tlv_link
*top
= (struct ext_tlv_link
*)ext
;
1805 struct tlv_header
*tlvh
;
1806 uint16_t length
= ntohs(top
->header
.length
);
1809 /* Verify that TLV length is valid against remaining buffer size */
1810 if (length
> buf_size
) {
1812 " Extended Link TLV size %d exceeds buffer size. Abort!\n",
1818 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1820 ntohs(top
->header
.length
), top
->link_type
,
1822 vty_out(vty
, " Link data: %pI4\n", &top
->link_data
);
1824 /* Skip Extended TLV and parse sub-TLVs */
1825 length
-= EXT_TLV_LINK_SIZE
;
1826 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1827 + EXT_TLV_LINK_SIZE
);
1828 for (; sum
< length
&& tlvh
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1829 switch (ntohs(tlvh
->type
)) {
1830 case EXT_SUBTLV_ADJ_SID
:
1831 sum
+= show_vty_ext_link_adj_sid(vty
, tlvh
);
1833 case EXT_SUBTLV_LAN_ADJ_SID
:
1834 sum
+= show_vty_ext_link_lan_adj_sid(vty
, tlvh
);
1836 case EXT_SUBTLV_RMT_ITF_ADDR
:
1837 sum
+= show_vty_ext_link_rmt_itf_addr(vty
, tlvh
);
1840 sum
+= show_vty_unknown_tlv(vty
, tlvh
, length
- sum
);
1845 return sum
+ sizeof(struct ext_tlv_link
);
1848 /* Extended Link TLVs */
1849 static void ospf_ext_link_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1851 struct lsa_header
*lsah
= lsa
->data
;
1852 struct tlv_header
*tlvh
;
1853 uint16_t length
= 0, sum
= 0;
1855 /* Initialize TLV browsing */
1856 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
;
1858 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
&& tlvh
;
1859 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1860 switch (ntohs(tlvh
->type
)) {
1862 sum
+= show_vty_link_info(vty
, tlvh
, length
- sum
);
1865 sum
+= show_vty_unknown_tlv(vty
, tlvh
, length
- sum
);
1871 /* Prefix SID SubTLV */
1872 static uint16_t show_vty_ext_pref_pref_sid(struct vty
*vty
,
1873 struct tlv_header
*tlvh
)
1875 struct ext_subtlv_prefix_sid
*top
=
1876 (struct ext_subtlv_prefix_sid
*)tlvh
;
1878 check_tlv_size(EXT_SUBTLV_PREFIX_SID_SIZE
, "Prefix SID");
1881 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1882 ntohs(top
->header
.length
), top
->algorithm
, top
->flags
,
1884 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
) ? "Label"
1886 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
)
1887 ? GET_LABEL(ntohl(top
->value
))
1888 : ntohl(top
->value
));
1890 return TLV_SIZE(tlvh
);
1893 /* Extended Prefix SubTLVs */
1894 static uint16_t show_vty_pref_info(struct vty
*vty
, struct tlv_header
*ext
,
1897 struct ext_tlv_prefix
*top
= (struct ext_tlv_prefix
*)ext
;
1898 struct tlv_header
*tlvh
;
1899 uint16_t length
= ntohs(top
->header
.length
);
1902 /* Verify that TLV length is valid against remaining buffer size */
1903 if (length
> buf_size
) {
1905 " Extended Link TLV size %d exceeds buffer size. Abort!\n",
1911 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1912 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %pI4/%u\n",
1913 ntohs(top
->header
.length
), top
->route_type
, top
->af
, top
->flags
,
1914 &top
->address
, top
->pref_length
);
1916 /* Skip Extended Prefix TLV and parse sub-TLVs */
1917 length
-= EXT_TLV_PREFIX_SIZE
;
1918 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1919 + EXT_TLV_PREFIX_SIZE
);
1920 for (; sum
< length
&& tlvh
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1921 switch (ntohs(tlvh
->type
)) {
1922 case EXT_SUBTLV_PREFIX_SID
:
1923 sum
+= show_vty_ext_pref_pref_sid(vty
, tlvh
);
1926 sum
+= show_vty_unknown_tlv(vty
, tlvh
, length
- sum
);
1931 return sum
+ sizeof(struct ext_tlv_prefix
);
1934 /* Extended Prefix TLVs */
1935 static void ospf_ext_pref_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1937 struct lsa_header
*lsah
= lsa
->data
;
1938 struct tlv_header
*tlvh
;
1939 uint16_t length
= 0, sum
= 0;
1941 /* Initialize TLV browsing */
1942 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
;
1944 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
&& tlvh
;
1945 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1946 switch (ntohs(tlvh
->type
)) {
1947 case EXT_TLV_PREFIX
:
1948 sum
+= show_vty_pref_info(vty
, tlvh
, length
- sum
);
1951 sum
+= show_vty_unknown_tlv(vty
, tlvh
, length
- sum
);