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 json_object
*json
,
84 struct ospf_lsa
*lsa
);
85 static int ospf_ext_pref_lsa_originate(void *arg
);
86 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
);
87 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
88 enum lsa_opcode opcode
);
89 /* Extended Link Opaque LSA related callback functions */
90 static int ospf_ext_link_new_if(struct interface
*ifp
);
91 static int ospf_ext_link_del_if(struct interface
*ifp
);
92 static void ospf_ext_ism_change(struct ospf_interface
*oi
, int old_status
);
93 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
);
94 static void ospf_ext_link_show_info(struct vty
*vty
, struct json_object
*json
,
95 struct ospf_lsa
*lsa
);
96 static int ospf_ext_link_lsa_originate(void *arg
);
97 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
);
98 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
99 enum lsa_opcode opcode
);
100 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
);
101 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
);
102 static int ospf_ext_pref_lsa_update(struct ospf_lsa
*lsa
);
103 static void ospf_ext_link_delete_adj_sid(struct ext_itf
*exti
);
104 static void del_ext_info(void *val
);
107 * Extended Link/Prefix initialization
111 * @return - 0 if OK, <> 0 otherwise
113 int ospf_ext_init(void)
117 memset(&OspfEXT
, 0, sizeof(struct ospf_ext_lp
));
118 OspfEXT
.enabled
= false;
119 /* Only Area flooding is supported yet */
120 OspfEXT
.scope
= OSPF_OPAQUE_AREA_LSA
;
121 /* Initialize interface list */
122 OspfEXT
.iflist
= list_new();
123 OspfEXT
.iflist
->del
= del_ext_info
;
125 zlog_info("EXT (%s): Register Extended Link Opaque LSA", __func__
);
126 rc
= ospf_register_opaque_functab(
127 OSPF_OPAQUE_AREA_LSA
, OPAQUE_TYPE_EXTENDED_LINK_LSA
,
128 ospf_ext_link_new_if
, /* new if */
129 ospf_ext_link_del_if
, /* del if */
130 ospf_ext_ism_change
, /* ism change */
131 ospf_ext_link_nsm_change
, /* nsm change */
132 NULL
, /* Write router config. */
133 NULL
, /* Write interface conf. */
134 NULL
, /* Write debug config. */
135 ospf_ext_link_show_info
, /* Show LSA info */
136 ospf_ext_link_lsa_originate
, /* Originate LSA */
137 ospf_ext_link_lsa_refresh
, /* Refresh LSA */
138 ospf_ext_link_lsa_update
, /* new_lsa_hook */
139 NULL
); /* del_lsa_hook */
142 flog_warn(EC_OSPF_OPAQUE_REGISTRATION
,
143 "EXT (%s): Failed to register Extended Link LSA",
148 zlog_info("EXT (%s): Register Extended Prefix Opaque LSA", __func__
);
149 rc
= ospf_register_opaque_functab(
150 OspfEXT
.scope
, OPAQUE_TYPE_EXTENDED_PREFIX_LSA
,
151 NULL
, /* new if handle by link */
152 NULL
, /* del if handle by link */
153 NULL
, /* ism change */
154 NULL
, /* nsm change */
155 ospf_sr_config_write_router
, /* Write router config. */
156 NULL
, /* Write interface conf. */
157 NULL
, /* Write debug config. */
158 ospf_ext_pref_show_info
, /* Show LSA info */
159 ospf_ext_pref_lsa_originate
, /* Originate LSA */
160 ospf_ext_pref_lsa_refresh
, /* Refresh LSA */
161 ospf_ext_pref_lsa_update
, /* new_lsa_hook */
162 NULL
); /* del_lsa_hook */
164 flog_warn(EC_OSPF_OPAQUE_REGISTRATION
,
165 "EXT (%s): Failed to register Extended Prefix LSA",
174 * Extended Link/Prefix termination function
179 void ospf_ext_term(void)
182 if ((OspfEXT
.scope
== OSPF_OPAQUE_AREA_LSA
)
183 || (OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
))
184 ospf_delete_opaque_functab(OspfEXT
.scope
,
185 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
187 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA
,
188 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
190 list_delete(&OspfEXT
.iflist
);
192 OspfEXT
.enabled
= false;
198 * Extended Link/Prefix finish function
203 void ospf_ext_finish(void)
206 struct listnode
*node
;
207 struct ext_itf
*exti
;
209 /* Flush Router Info LSA */
210 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
211 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
212 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
214 OspfEXT
.enabled
= false;
218 * ---------------------------------------------------------------------
219 * Followings are control functions for Extended Prefix/Link Opaque LSA
220 * parameters management.
221 * ---------------------------------------------------------------------
224 /* Functions to free memory space */
225 static void del_ext_info(void *val
)
227 XFREE(MTYPE_OSPF_EXT_PARAMS
, val
);
230 /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
231 static uint32_t get_ext_pref_instance_value(void)
233 static uint32_t seqno
= 0;
235 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
238 seqno
= 1; /* Avoid zero. */
243 /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */
244 static uint32_t get_ext_link_instance_value(void)
246 static uint32_t seqno
= 0;
248 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
251 seqno
= 1; /* Avoid zero. */
256 /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
257 static struct ext_itf
*lookup_ext_by_ifp(struct interface
*ifp
)
259 struct listnode
*node
;
260 struct ext_itf
*exti
;
262 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
263 if (exti
->ifp
== ifp
)
269 /* Lookup Extended Prefix/Links by LSA ID from OspfEXT struct iflist */
270 static struct ext_itf
*lookup_ext_by_instance(struct ospf_lsa
*lsa
)
272 struct listnode
*node
;
273 struct ext_itf
*exti
;
274 uint32_t key
= GET_OPAQUE_ID(ntohl(lsa
->data
->id
.s_addr
));
275 uint8_t type
= GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
));
278 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
279 if ((exti
->instance
== key
) && (exti
->type
== type
))
286 * ----------------------------------------------------------------------
287 * The underlying subsection defines setters and unsetters to create and
288 * delete tlvs and subtlvs
289 * ----------------------------------------------------------------------
292 /* Extended Prefix TLV - RFC7684 section 2.1 */
293 static void set_ext_prefix(struct ext_itf
*exti
, uint8_t route_type
,
294 uint8_t flags
, struct prefix_ipv4 p
)
297 TLV_TYPE(exti
->prefix
) = htons(EXT_TLV_PREFIX
);
298 /* Warning: Size must be adjust depending of subTLV's */
299 TLV_LEN(exti
->prefix
) = htons(EXT_TLV_PREFIX_SIZE
);
300 exti
->prefix
.route_type
= route_type
;
301 exti
->prefix
.flags
= flags
;
302 /* Only Address Family Ipv4 (0) is defined in RFC 7684 */
304 exti
->prefix
.pref_length
= p
.prefixlen
;
305 exti
->prefix
.address
= p
.prefix
;
307 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
310 /* Extended Link TLV - RFC7684 section 3.1 */
311 static void set_ext_link(struct ext_itf
*exti
, uint8_t type
, struct in_addr id
,
315 TLV_TYPE(exti
->link
) = htons(EXT_TLV_LINK
);
316 /* Warning: Size must be adjust depending of subTLV's */
317 TLV_LEN(exti
->link
) = htons(EXT_TLV_LINK_SIZE
);
318 exti
->link
.link_type
= type
;
319 exti
->link
.link_id
= id
;
320 exti
->link
.link_data
= data
;
323 /* Prefix SID SubTLV - section 5 */
324 static void set_prefix_sid(struct ext_itf
*exti
, uint8_t algorithm
,
325 uint32_t value
, int value_type
, uint8_t flags
)
328 if ((algorithm
!= SR_ALGORITHM_SPF
)
329 && (algorithm
!= SR_ALGORITHM_STRICT_SPF
)) {
330 flog_err(EC_OSPF_INVALID_ALGORITHM
,
331 "EXT (%s): unrecognized algorithm, not SPF or S-SPF",
336 /* Update flags according to the type of value field: label or index */
337 if (value_type
== SID_LABEL
)
338 SET_FLAG(flags
, EXT_SUBTLV_PREFIX_SID_VFLG
);
340 /* set prefix sid subtlv for an extended prefix tlv */
341 TLV_TYPE(exti
->node_sid
) = htons(EXT_SUBTLV_PREFIX_SID
);
342 exti
->node_sid
.algorithm
= algorithm
;
343 exti
->node_sid
.flags
= flags
;
344 exti
->node_sid
.mtid
= 0; /* Multi-Topology is not supported */
346 /* Set Label or Index value */
347 if (value_type
== SID_LABEL
) {
348 TLV_LEN(exti
->node_sid
) =
349 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE
));
350 exti
->node_sid
.value
= htonl(SET_LABEL(value
));
352 TLV_LEN(exti
->node_sid
) =
353 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE
));
354 exti
->node_sid
.value
= htonl(value
);
358 /* Adjacency SID SubTLV - section 6.1 */
359 static void set_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
365 /* Determine which ADJ_SID must be set: nominal or backup */
367 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
375 TLV_TYPE(exti
->adj_sid
[index
]) = htons(EXT_SUBTLV_ADJ_SID
);
377 /* Only Local ADJ-SID is supported for the moment */
378 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
380 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
382 /* Adjust Length, Flags and Value depending on the type of Label */
383 if (value_type
== SID_LABEL
) {
384 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
385 TLV_LEN(exti
->adj_sid
[index
]) =
386 htons(SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE
));
387 exti
->adj_sid
[index
].value
= htonl(SET_LABEL(value
));
389 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
390 TLV_LEN(exti
->adj_sid
[index
]) =
391 htons(SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE
));
392 exti
->adj_sid
[index
].value
= htonl(value
);
395 exti
->adj_sid
[index
].flags
= flags
; /* Set computed flags */
396 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
397 exti
->adj_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
400 /* LAN Adjacency SID SubTLV - section 6.2 */
401 static void set_lan_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
402 int value_type
, struct in_addr neighbor_id
)
408 /* Determine which ADJ_SID must be set: nominal or backup */
410 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
418 TLV_TYPE(exti
->lan_sid
[index
]) = htons(EXT_SUBTLV_LAN_ADJ_SID
);
420 /* Only Local ADJ-SID is supported for the moment */
421 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
423 /* Adjust Length, Flags and Value depending on the type of Label */
424 if (value_type
== SID_LABEL
) {
425 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
426 TLV_LEN(exti
->lan_sid
[index
]) =
427 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE
));
428 exti
->lan_sid
[index
].value
= htonl(SET_LABEL(value
));
430 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
431 TLV_LEN(exti
->lan_sid
[index
]) =
432 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE
));
433 exti
->lan_sid
[index
].value
= htonl(value
);
436 exti
->lan_sid
[index
].flags
= flags
; /* Set computed flags */
437 exti
->lan_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
438 exti
->lan_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
439 exti
->lan_sid
[index
].neighbor_id
= neighbor_id
;
442 static void unset_adjacency_sid(struct ext_itf
*exti
)
444 /* Reset Adjacency TLV */
445 if (exti
->type
== ADJ_SID
) {
446 TLV_TYPE(exti
->adj_sid
[0]) = 0;
447 TLV_TYPE(exti
->adj_sid
[1]) = 0;
449 /* or Lan-Adjacency TLV */
450 if (exti
->type
== LAN_ADJ_SID
) {
451 TLV_TYPE(exti
->lan_sid
[0]) = 0;
452 TLV_TYPE(exti
->lan_sid
[1]) = 0;
456 /* Experimental SubTLV from Cisco */
457 static void set_rmt_itf_addr(struct ext_itf
*exti
, struct in_addr rmtif
)
460 TLV_TYPE(exti
->rmt_itf_addr
) = htons(EXT_SUBTLV_RMT_ITF_ADDR
);
461 TLV_LEN(exti
->rmt_itf_addr
) = htons(sizeof(struct in_addr
));
462 exti
->rmt_itf_addr
.value
= rmtif
;
465 /* Delete Extended LSA */
466 static void ospf_extended_lsa_delete(struct ext_itf
*exti
)
469 /* Avoid deleting LSA if Extended is not enable */
470 if (!OspfEXT
.enabled
)
473 /* Process only Active Extended Prefix/Link LSA */
474 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
477 osr_debug("EXT (%s): Disable %s%s%s-SID on interface %s", __func__
,
478 exti
->stype
== LOCAL_SID
? "Prefix" : "",
479 exti
->stype
== ADJ_SID
? "Adjacency" : "",
480 exti
->stype
== LAN_ADJ_SID
? "LAN-Adjacency" : "",
483 /* Flush LSA if already engaged */
484 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
485 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
486 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
489 /* De-activate this Extended Prefix/Link and remove corresponding
490 * Segment-Routing Prefix-SID or (LAN)-ADJ-SID */
491 if (exti
->stype
== ADJ_SID
|| exti
->stype
== LAN_ADJ_SID
)
492 ospf_ext_link_delete_adj_sid(exti
);
494 ospf_sr_ext_itf_delete(exti
);
498 * Update Extended prefix SID index for Loopback interface type
500 * @param ifname - Loopback interface name
501 * @param index - new value for the prefix SID of this interface
502 * @param p - prefix for this interface or NULL if Extended Prefix
505 * @return instance number if update is OK, 0 otherwise
507 uint32_t ospf_ext_schedule_prefix_index(struct interface
*ifp
, uint32_t index
,
508 struct prefix_ipv4
*p
, uint8_t flags
)
511 struct ext_itf
*exti
;
513 /* Find Extended Prefix interface */
514 exti
= lookup_ext_by_ifp(ifp
);
519 osr_debug("EXT (%s): Schedule new prefix %pFX with index %u on interface %s", __func__
, p
, index
, ifp
->name
);
521 /* Set first Extended Prefix then the Prefix SID information */
522 set_ext_prefix(exti
, OSPF_PATH_INTRA_AREA
, EXT_TLV_PREF_NFLG
,
524 set_prefix_sid(exti
, SR_ALGORITHM_SPF
, index
, SID_INDEX
, flags
);
526 /* Try to Schedule LSA */
527 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
528 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
529 ospf_ext_pref_lsa_schedule(exti
,
532 ospf_ext_pref_lsa_schedule(
533 exti
, REORIGINATE_THIS_LSA
);
536 osr_debug("EXT (%s): Remove prefix for interface %s", __func__
,
539 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
540 ospf_ext_pref_lsa_schedule(exti
, FLUSH_THIS_LSA
);
543 return SET_OPAQUE_LSID(exti
->type
, exti
->instance
);
547 * Update Adjacecny-SID for Extended Link LSA
549 * @param exti Extended Link information
551 static void ospf_ext_link_update_adj_sid(struct ext_itf
*exti
)
554 mpls_label_t bck_label
;
556 /* Process only (LAN)Adjacency-SID Type */
557 if (exti
->stype
!= ADJ_SID
&& exti
->stype
!= LAN_ADJ_SID
)
560 /* Request Primary & Backup Labels from Label Manager */
561 bck_label
= ospf_sr_local_block_request_label();
562 label
= ospf_sr_local_block_request_label();
563 if (bck_label
== MPLS_INVALID_LABEL
|| label
== MPLS_INVALID_LABEL
) {
564 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
565 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
569 /* Set Adjacency-SID, backup first */
570 if (exti
->stype
== ADJ_SID
) {
571 set_adj_sid(exti
, true, bck_label
, SID_LABEL
);
572 set_adj_sid(exti
, false, label
, SID_LABEL
);
574 set_lan_adj_sid(exti
, true, bck_label
, SID_LABEL
,
575 exti
->lan_sid
[0].neighbor_id
);
576 set_lan_adj_sid(exti
, false, label
, SID_LABEL
,
577 exti
->lan_sid
[1].neighbor_id
);
580 /* Finally, add corresponding SR Link in SRDB & MPLS LFIB */
581 SET_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
);
582 ospf_sr_ext_itf_add(exti
);
586 * Delete Adjacecny-SID for Extended Link LSA
588 * @param exti Extended Link information
590 static void ospf_ext_link_delete_adj_sid(struct ext_itf
*exti
)
592 /* Process only (LAN)Adjacency-SID Type */
593 if (exti
->stype
!= ADJ_SID
&& exti
->stype
!= LAN_ADJ_SID
)
596 /* Release Primary & Backup Labels from Label Manager */
597 if (exti
->stype
== ADJ_SID
) {
598 ospf_sr_local_block_release_label(exti
->adj_sid
[0].value
);
599 ospf_sr_local_block_release_label(exti
->adj_sid
[1].value
);
601 ospf_sr_local_block_release_label(exti
->lan_sid
[0].value
);
602 ospf_sr_local_block_release_label(exti
->lan_sid
[1].value
);
604 /* And reset corresponding TLV */
605 unset_adjacency_sid(exti
);
607 /* Finally, remove corresponding SR Link in SRDB & MPLS LFIB */
608 UNSET_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
);
609 ospf_sr_ext_itf_delete(exti
);
613 * Update Extended Link LSA once Segment Routing Label Block has been changed.
615 void ospf_ext_link_srlb_update(void)
617 struct listnode
*node
;
618 struct ext_itf
*exti
;
621 osr_debug("EXT (%s): Update Extended Links with new SRLB", __func__
);
623 /* Update all Extended Link Adjaceny-SID */
624 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
625 /* Skip Extended Prefix */
626 if (exti
->stype
== PREF_SID
|| exti
->stype
== LOCAL_SID
)
629 /* Skip inactive Extended Link */
630 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
633 ospf_ext_link_update_adj_sid(exti
);
638 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
640 * @param enable To activate or not Segment Routing Extended LSA flooding
644 void ospf_ext_update_sr(bool enable
)
646 struct listnode
*node
;
647 struct ext_itf
*exti
;
649 osr_debug("EXT (%s): %s Extended LSAs for Segment Routing ", __func__
,
650 enable
? "Enable" : "Disable");
653 OspfEXT
.enabled
= true;
655 /* Refresh LSAs if already engaged or originate */
656 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
657 /* Skip Inactive Extended Link */
658 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
661 /* Update Extended Link (LAN)Adj-SID if not set */
662 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
))
663 ospf_ext_link_update_adj_sid(exti
);
665 /* Finally, flood the extended Link */
666 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
667 ospf_ext_lsa_schedule(exti
, REFRESH_THIS_LSA
);
669 ospf_ext_lsa_schedule(exti
,
670 REORIGINATE_THIS_LSA
);
673 /* Start by Removing Extended LSA */
674 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
675 ospf_extended_lsa_delete(exti
);
677 /* And then disable Extended Link/Prefix */
678 OspfEXT
.enabled
= false;
683 * -----------------------------------------------------------------------
684 * Followings are callback functions against generic Opaque-LSAs handling
685 * -----------------------------------------------------------------------
688 /* Add new Interface in Extended Interface List */
689 static int ospf_ext_link_new_if(struct interface
*ifp
)
694 if (lookup_ext_by_ifp(ifp
) != NULL
) {
695 rc
= 0; /* Do nothing here. */
699 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS
, sizeof(struct ext_itf
));
701 /* initialize new information and link back the interface */
703 new->flags
= EXT_LPFLG_LSA_INACTIVE
;
705 listnode_add(OspfEXT
.iflist
, new);
711 /* Remove existing Interface from Extended Interface List */
712 static int ospf_ext_link_del_if(struct interface
*ifp
)
714 struct ext_itf
*exti
;
717 exti
= lookup_ext_by_ifp(ifp
);
719 /* Flush LSA and remove Adjacency SID */
720 ospf_extended_lsa_delete(exti
);
722 /* Dequeue listnode entry from the list. */
723 listnode_delete(OspfEXT
.iflist
, exti
);
725 XFREE(MTYPE_OSPF_EXT_PARAMS
, exti
);
729 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
730 "EXT (%s): interface %s is not found", __func__
,
731 ifp
? ifp
->name
: "-");
738 * Determine if an Interface belongs to an Extended Link Adjacency or
739 * Extended Prefix SID type and allocate new instance value accordingly
741 static void ospf_ext_ism_change(struct ospf_interface
*oi
, int old_status
)
743 struct ext_itf
*exti
;
745 /* Get interface information for Segment Routing */
746 exti
= lookup_ext_by_ifp(oi
->ifp
);
748 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
749 "EXT (%s): Cannot get Extended info. from OI(%s)",
750 __func__
, IF_NAME(oi
));
754 /* Reset Extended information if ospf interface goes Down */
755 if (oi
->state
== ISM_Down
) {
756 ospf_extended_lsa_delete(exti
);
758 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
762 /* Determine if interface is related to a Prefix or an Adjacency SID */
763 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
764 exti
->stype
= PREF_SID
;
765 exti
->type
= OPAQUE_TYPE_EXTENDED_PREFIX_LSA
;
766 exti
->instance
= get_ext_pref_instance_value();
767 exti
->area
= oi
->area
;
769 /* Complete SRDB if the interface belongs to a Prefix */
770 if (OspfEXT
.enabled
) {
771 osr_debug("EXT (%s): Set Prefix SID to interface %s ",
772 __func__
, oi
->ifp
->name
);
773 ospf_sr_update_local_prefix(oi
->ifp
, oi
->address
);
776 /* Determine if interface is related to Adj. or LAN Adj. SID */
777 if (oi
->state
== ISM_DR
)
778 exti
->stype
= LAN_ADJ_SID
;
780 exti
->stype
= ADJ_SID
;
782 exti
->type
= OPAQUE_TYPE_EXTENDED_LINK_LSA
;
783 exti
->instance
= get_ext_link_instance_value();
784 exti
->area
= oi
->area
;
787 * Note: Adjacency SID information are completed when ospf
788 * adjacency become up see ospf_ext_link_nsm_change()
792 "EXT (%s): Set %sAdjacency SID for interface %s ",
793 __func__
, exti
->stype
== ADJ_SID
? "" : "LAN-",
799 * Finish Extended Link configuration and flood corresponding LSA
800 * when OSPF adjacency on this link fire up
802 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
)
804 struct ospf_interface
*oi
= nbr
->oi
;
805 struct ext_itf
*exti
;
807 /* Process Link only when neighbor old or new state is NSM Full */
808 if (nbr
->state
!= NSM_Full
&& old_status
!= NSM_Full
)
811 /* Get interface information for Segment Routing */
812 exti
= lookup_ext_by_ifp(oi
->ifp
);
814 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
815 "EXT (%s): Cannot get Extended info. from OI(%s)",
816 __func__
, IF_NAME(oi
));
820 /* Check that we have a valid area and ospf context */
821 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
822 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
823 "EXT (%s): Cannot refer to OSPF from OI(%s)",
824 __func__
, IF_NAME(oi
));
828 /* Remove Extended Link if Neighbor State goes Down or Deleted */
830 && (nbr
->state
== NSM_Down
|| nbr
->state
== NSM_Deleted
)) {
831 ospf_ext_link_delete_adj_sid(exti
);
832 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
833 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
834 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
838 /* Keep Area information in combination with SR info. */
839 exti
->area
= oi
->area
;
841 /* Process only Adjacency/LAN SID */
842 if (exti
->stype
== PREF_SID
)
846 case ISM_PointToPoint
:
847 /* Segment ID is an Adjacency one */
848 exti
->stype
= ADJ_SID
;
850 /* Set Extended Link TLV with link_id == Nbr Router ID */
851 set_ext_link(exti
, OSPF_IFTYPE_POINTOPOINT
, nbr
->router_id
,
852 oi
->address
->u
.prefix4
);
854 /* And Remote Interface address */
855 set_rmt_itf_addr(exti
, nbr
->address
.u
.prefix4
);
860 /* Segment ID is a LAN Adjacency for the DR only */
861 exti
->stype
= LAN_ADJ_SID
;
863 /* Set Extended Link TLV with link_id == DR */
864 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
865 oi
->address
->u
.prefix4
);
867 /* Set Neighbor ID */
868 exti
->lan_sid
[0].neighbor_id
= nbr
->router_id
;
869 exti
->lan_sid
[1].neighbor_id
= nbr
->router_id
;
875 /* Segment ID is an Adjacency if not the DR */
876 exti
->stype
= ADJ_SID
;
878 /* Set Extended Link TLV with link_id == DR */
879 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
880 oi
->address
->u
.prefix4
);
885 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
))
886 ospf_ext_link_delete_adj_sid(exti
);
887 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
888 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
889 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
893 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
895 if (OspfEXT
.enabled
) {
896 osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
897 __func__
, exti
->stype
== ADJ_SID
? "" : "LAN-",
900 /* Update (LAN)Adjacency SID */
901 ospf_ext_link_update_adj_sid(exti
);
903 /* flood this links params if everything is ok */
904 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
905 ospf_ext_link_lsa_schedule(exti
, REFRESH_THIS_LSA
);
907 ospf_ext_link_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
911 /* Callbacks to handle Extended Link Segment Routing LSA information */
912 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
)
916 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
921 /* Process only Opaque LSA */
922 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
923 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
926 /* Process only Extended Link LSA */
927 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
928 != OPAQUE_TYPE_EXTENDED_LINK_LSA
)
931 /* Check if it is not my LSA */
932 if (IS_LSA_SELF(lsa
))
935 /* Check if Extended is enable */
936 if (!OspfEXT
.enabled
)
939 /* Call Segment Routing LSA update or deletion */
940 if (!IS_LSA_MAXAGE(lsa
))
941 ospf_sr_ext_link_lsa_update(lsa
);
943 ospf_sr_ext_link_lsa_delete(lsa
);
948 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
949 static int ospf_ext_pref_lsa_update(struct ospf_lsa
*lsa
)
954 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
959 /* Process only Opaque LSA */
960 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
961 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
964 /* Process only Extended Prefix LSA */
965 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
966 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA
)
969 /* Check if it is not my LSA */
970 if (IS_LSA_SELF(lsa
))
973 /* Check if Extended is enable */
974 if (!OspfEXT
.enabled
)
977 /* Call Segment Routing LSA update or deletion */
978 if (!IS_LSA_MAXAGE(lsa
))
979 ospf_sr_ext_prefix_lsa_update(lsa
);
981 ospf_sr_ext_prefix_lsa_delete(lsa
);
987 * -------------------------------------------------------
988 * Followings are OSPF protocol processing functions for
989 * Extended Prefix/Link Opaque LSA
990 * -------------------------------------------------------
993 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
995 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
998 static void build_tlv(struct stream
*s
, struct tlv_header
*tlvh
)
1001 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
1002 build_tlv_header(s
, tlvh
);
1003 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
1007 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
1008 static void ospf_ext_pref_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
1012 if ((exti
== NULL
) || (exti
->stype
!= PREF_SID
))
1015 /* Adjust Extended Prefix TLV size */
1016 TLV_LEN(exti
->prefix
) = htons(ntohs(TLV_LEN(exti
->node_sid
))
1017 + EXT_TLV_PREFIX_SIZE
+ TLV_HDR_SIZE
);
1019 /* Build LSA body for an Extended Prefix TLV */
1020 build_tlv_header(s
, &exti
->prefix
.header
);
1021 stream_put(s
, TLV_DATA(&exti
->prefix
.header
), EXT_TLV_PREFIX_SIZE
);
1022 /* Then add Prefix SID SubTLV */
1023 build_tlv(s
, &exti
->node_sid
.header
);
1026 /* Build an Extended Link Opaque LSA body for extended link TLV */
1027 static void ospf_ext_link_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
1033 || ((exti
->stype
!= ADJ_SID
) && (exti
->stype
!= LAN_ADJ_SID
)))
1036 if (exti
->stype
== ADJ_SID
) {
1037 /* Adjust Extended Link TLV size for Adj. SID */
1038 size
= EXT_TLV_LINK_SIZE
+ 2 * EXT_SUBTLV_ADJ_SID_SIZE
1040 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
1041 size
= size
+ EXT_SUBTLV_RMT_ITF_ADDR_SIZE
1043 TLV_LEN(exti
->link
) = htons(size
);
1045 /* Build LSA body for an Extended Link TLV with Adj. SID */
1046 build_tlv_header(s
, &exti
->link
.header
);
1047 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
1048 /* then add Adjacency SubTLVs */
1049 build_tlv(s
, &exti
->adj_sid
[1].header
);
1050 build_tlv(s
, &exti
->adj_sid
[0].header
);
1052 /* Add Cisco experimental SubTLV if interface is PtoP */
1053 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
1054 build_tlv(s
, &exti
->rmt_itf_addr
.header
);
1056 /* Adjust Extended Link TLV size for LAN SID */
1057 size
= EXT_TLV_LINK_SIZE
1058 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE
+ TLV_HDR_SIZE
);
1059 TLV_LEN(exti
->link
) = htons(size
);
1061 /* Build LSA body for an Extended Link TLV with LAN SID */
1062 build_tlv_header(s
, &exti
->link
.header
);
1063 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
1064 /* then add LAN-Adjacency SubTLVs */
1065 build_tlv(s
, &exti
->lan_sid
[1].header
);
1066 build_tlv(s
, &exti
->lan_sid
[0].header
);
1070 /* Create new Extended Prefix opaque-LSA for every extended prefix */
1071 static struct ospf_lsa
*ospf_ext_pref_lsa_new(struct ospf_area
*area
,
1072 struct ext_itf
*exti
)
1075 struct lsa_header
*lsah
;
1076 struct ospf_lsa
*new = NULL
;
1078 uint8_t options
, lsa_type
;
1079 struct in_addr lsa_id
;
1080 struct in_addr router_id
;
1088 /* Create a stream for LSA. */
1089 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1091 /* Prepare LSA Header */
1092 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1094 lsa_type
= OspfEXT
.scope
;
1097 * LSA ID is a variable number identifying different instances of
1098 * Extended Prefix Opaque LSA from the same router see RFC 7684
1100 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1101 lsa_id
.s_addr
= htonl(tmp
);
1103 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1105 /* Fix Options and Router ID depending of the flooding scope */
1106 if ((OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
) || (area
== NULL
)) {
1107 options
= OSPF_OPTION_E
;
1108 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1109 router_id
.s_addr
= top
? top
->router_id
.s_addr
: 0;
1111 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1112 options
|= LSA_OPTIONS_NSSA_GET(area
);
1113 router_id
= area
->ospf
->router_id
;
1116 /* Set opaque-LSA header fields. */
1117 lsa_header_set(s
, options
, lsa_type
, lsa_id
, router_id
);
1120 "EXT (%s): LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Prefix Opaque LSA instance",
1121 __func__
, lsa_type
, &lsa_id
);
1123 /* Set opaque-LSA body fields. */
1124 ospf_ext_pref_lsa_body_set(s
, exti
);
1127 length
= stream_get_endp(s
);
1128 lsah
->length
= htons(length
);
1130 /* Now, create an OSPF LSA instance. */
1131 new = ospf_lsa_new_and_data(length
);
1133 /* Segment Routing belongs only to default VRF */
1134 new->vrf_id
= VRF_DEFAULT
;
1136 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1137 memcpy(new->data
, lsah
, length
);
1143 /* Create new Extended Link opaque-LSA for every extended link TLV */
1144 static struct ospf_lsa
*ospf_ext_link_lsa_new(struct ospf_area
*area
,
1145 struct ext_itf
*exti
)
1148 struct lsa_header
*lsah
;
1149 struct ospf_lsa
*new = NULL
;
1150 uint8_t options
, lsa_type
;
1151 struct in_addr lsa_id
;
1159 /* Create a stream for LSA. */
1160 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1161 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1163 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1164 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1165 options
|= LSA_OPTIONS_NSSA_GET(area
);
1166 /* Extended Link Opaque LSA are only flooded within an area */
1167 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1170 * LSA ID is a variable number identifying different instances of
1171 * Extended Link Opaque LSA from the same router see RFC 7684
1173 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1174 lsa_id
.s_addr
= htonl(tmp
);
1177 "EXT (%s) LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Link Opaque LSA instance",
1178 __func__
, lsa_type
, &lsa_id
);
1180 /* Set opaque-LSA header fields. */
1181 lsa_header_set(s
, options
, lsa_type
, lsa_id
, area
->ospf
->router_id
);
1183 /* Set opaque-LSA body fields. */
1184 ospf_ext_link_lsa_body_set(s
, exti
);
1187 length
= stream_get_endp(s
);
1188 lsah
->length
= htons(length
);
1190 /* Now, create an OSPF LSA instance. */
1191 new = ospf_lsa_new_and_data(length
);
1193 /* Segment Routing belongs only to default VRF */
1194 new->vrf_id
= VRF_DEFAULT
;
1196 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1197 memcpy(new->data
, lsah
, length
);
1204 * Process the origination of an Extended Prefix Opaque LSA
1205 * for every extended prefix TLV
1207 static int ospf_ext_pref_lsa_originate1(struct ospf_area
*area
,
1208 struct ext_itf
*exti
)
1210 struct ospf_lsa
*new;
1214 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1215 new = ospf_ext_pref_lsa_new(area
, exti
);
1217 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1218 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1222 /* Install this LSA into LSDB. */
1223 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1224 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1225 "EXT (%s): ospf_lsa_install() error", __func__
);
1226 ospf_lsa_unlock(&new);
1230 /* Now this Extended Prefix Opaque LSA info parameter entry has
1233 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1235 /* Update new LSA origination count. */
1236 area
->ospf
->lsa_originate_count
++;
1238 /* Flood new LSA through area. */
1239 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1242 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSAExtended Prefix Opaque LSA: Area(%pI4), Link(%s)",
1243 __func__
, new->data
->type
, &new->data
->id
,
1244 &area
->area_id
, exti
->ifp
->name
);
1245 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1246 ospf_lsa_header_dump(new->data
);
1254 * Process the origination of an Extended Link Opaque LSA
1255 * for every extended link TLV
1257 static int ospf_ext_link_lsa_originate1(struct ospf_area
*area
,
1258 struct ext_itf
*exti
)
1260 struct ospf_lsa
*new;
1263 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1264 new = ospf_ext_link_lsa_new(area
, exti
);
1266 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1267 "EXT (%s): ospf_ext_link_lsa_new() error", __func__
);
1271 /* Install this LSA into LSDB. */
1272 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1273 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1274 "EXT (%s): ospf_lsa_install() error", __func__
);
1275 ospf_lsa_unlock(&new);
1279 /* Now this link-parameter entry has associated LSA. */
1280 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1282 /* Update new LSA origination count. */
1283 area
->ospf
->lsa_originate_count
++;
1285 /* Flood new LSA through area. */
1286 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1289 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSA Extended Link Opaque LSA: Area(%pI4), Link(%s)",
1290 __func__
, new->data
->type
, &new->data
->id
,
1291 &area
->area_id
, exti
->ifp
->name
);
1292 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1293 ospf_lsa_header_dump(new->data
);
1300 /* Trigger the origination of Extended Prefix Opaque LSAs */
1301 static int ospf_ext_pref_lsa_originate(void *arg
)
1303 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1304 struct listnode
*node
;
1305 struct ext_itf
*exti
;
1308 if (!OspfEXT
.enabled
) {
1310 "EXT (%s): Segment Routing functionality is Disabled now",
1312 rc
= 0; /* This is not an error case. */
1315 osr_debug("EXT (%s): Start Originate Prefix LSA for area %pI4",
1316 __func__
, &area
->area_id
);
1318 /* Check if Extended Prefix Opaque LSA is already engaged */
1319 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1321 /* Process only Prefix SID */
1322 if (exti
->stype
!= PREF_SID
)
1325 /* Process only Extended Prefix with valid Area ID */
1326 if ((exti
->area
== NULL
)
1327 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1330 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1331 if (CHECK_FLAG(exti
->flags
,
1332 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1334 EC_OSPF_EXT_LSA_UNEXPECTED
,
1335 "EXT (%s): Refresh instead of Originate",
1337 UNSET_FLAG(exti
->flags
,
1338 EXT_LPFLG_LSA_FORCED_REFRESH
);
1339 ospf_ext_pref_lsa_schedule(exti
,
1345 /* Ok, let's try to originate an LSA */
1347 "EXT (%s): Let's finally re-originate the LSA 7.0.0.%u for Itf %s", __func__
, exti
->instance
,
1348 exti
->ifp
? exti
->ifp
->name
: "");
1349 ospf_ext_pref_lsa_originate1(area
, exti
);
1356 /* Trigger the origination of Extended Link Opaque LSAs */
1357 static int ospf_ext_link_lsa_originate(void *arg
)
1359 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1360 struct listnode
*node
;
1361 struct ext_itf
*exti
;
1364 if (!OspfEXT
.enabled
) {
1366 "EXT (%s): Segment Routing functionality is Disabled now",
1368 rc
= 0; /* This is not an error case. */
1372 /* Check if Extended Prefix Opaque LSA is already engaged */
1373 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1374 /* Process only Adjacency or LAN SID */
1375 if (exti
->stype
== PREF_SID
)
1378 /* Skip Inactive Extended Link */
1379 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
1382 /* Process only Extended Link with valid Area ID */
1383 if ((exti
->area
== NULL
)
1384 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1387 /* Check if LSA not already engaged */
1388 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1389 if (CHECK_FLAG(exti
->flags
,
1390 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1392 EC_OSPF_EXT_LSA_UNEXPECTED
,
1393 "EXT (%s): Refresh instead of Originate",
1395 UNSET_FLAG(exti
->flags
,
1396 EXT_LPFLG_LSA_FORCED_REFRESH
);
1397 ospf_ext_link_lsa_schedule(exti
,
1403 /* Ok, let's try to originate an LSA */
1405 "EXT (%s): Let's finally reoriginate the LSA 8.0.0.%u for Itf %s through the Area %pI4", __func__
,
1406 exti
->instance
, exti
->ifp
? exti
->ifp
->name
: "-",
1408 ospf_ext_link_lsa_originate1(area
, exti
);
1415 /* Refresh an Extended Prefix Opaque LSA */
1416 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
)
1418 struct ospf_lsa
*new = NULL
;
1419 struct ospf_area
*area
= lsa
->area
;
1421 struct ext_itf
*exti
;
1423 if (!OspfEXT
.enabled
) {
1425 * This LSA must have flushed before due to Extended Prefix
1426 * Opaque LSA status change.
1427 * It seems a slip among routers in the routing domain.
1430 "EXT (%s): Segment Routing functionality is Disabled",
1432 /* Flush it anyway. */
1433 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1436 /* Lookup this lsa corresponding Extended parameters */
1437 exti
= lookup_ext_by_instance(lsa
);
1439 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1440 "EXT (%s): Invalid parameter LSA ID", __func__
);
1441 /* Flush it anyway. */
1442 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1445 /* Check if Interface was not disable in the interval */
1446 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1447 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1448 "EXT (%s): Interface was Disabled: Flush it!",
1450 /* Flush it anyway. */
1451 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1454 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1455 if (IS_LSA_MAXAGE(lsa
)) {
1457 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1458 ospf_opaque_lsa_flush_schedule(lsa
);
1462 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1463 new = ospf_ext_pref_lsa_new(area
, exti
);
1466 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1467 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1470 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1473 * Install this LSA into LSDB
1474 * Given "lsa" will be freed in the next function
1475 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1476 * ospf_lookup() to get ospf instance
1481 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1483 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1484 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1485 "EXT (%s): ospf_lsa_install() error", __func__
);
1486 ospf_lsa_unlock(&new);
1490 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1491 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1493 /* Debug logging. */
1494 osr_debug("EXT (%s): LSA[Type%u:%pI4] Refresh Extended Prefix LSA",
1495 __func__
, new->data
->type
, &new->data
->id
);
1496 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1497 ospf_lsa_header_dump(new->data
);
1503 /* Refresh an Extended Link Opaque LSA */
1504 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
)
1506 struct ext_itf
*exti
;
1507 struct ospf_area
*area
= lsa
->area
;
1508 struct ospf
*top
= area
->ospf
;
1509 struct ospf_lsa
*new = NULL
;
1511 if (!OspfEXT
.enabled
) {
1513 * This LSA must have flushed before due to OSPF-SR status
1514 * change. It seems a slip among routers in the routing domain.
1516 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1518 /* Flush it anyway. */
1519 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1522 /* Lookup this LSA corresponding Extended parameters */
1523 exti
= lookup_ext_by_instance(lsa
);
1525 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1526 "EXT (%s): Invalid parameter LSA ID", __func__
);
1527 /* Flush it anyway. */
1528 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1531 /* Check if Interface was not disable in the interval */
1532 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1533 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1534 "EXT (%s): Interface was Disabled: Flush it!",
1536 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1539 /* If the lsa's age reached to MaxAge, start flushing procedure */
1540 if (IS_LSA_MAXAGE(lsa
)) {
1542 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1543 ospf_opaque_lsa_flush_schedule(lsa
);
1547 /* Create new Opaque-LSA/Extended Link instance */
1548 new = ospf_ext_link_lsa_new(area
, exti
);
1550 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1551 "EXT (%s): Error creating new LSA", __func__
);
1554 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1556 /* Install this LSA into LSDB. */
1557 /* Given "lsa" will be freed in the next function */
1558 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1559 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1560 "EXT (%s): Error installing new LSA", __func__
);
1561 ospf_lsa_unlock(&new);
1565 /* Flood updated LSA through the link Area according to the RFC7684 */
1566 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1568 /* Debug logging. */
1569 osr_debug("EXT (%s): LSA[Type%u:%pI4]: Refresh Extended Link LSA",
1570 __func__
, new->data
->type
, &new->data
->id
);
1571 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1572 ospf_lsa_header_dump(new->data
);
1577 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1578 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
1579 enum lsa_opcode opcode
)
1581 struct ospf_lsa lsa
;
1582 struct lsa_header lsah
;
1586 memset(&lsa
, 0, sizeof(lsa
));
1587 memset(&lsah
, 0, sizeof(lsah
));
1593 /* Check if the corresponding link is ready to be flooded */
1594 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1597 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1598 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1599 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1600 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1601 exti
->ifp
? exti
->ifp
->name
: "-");
1604 if (exti
->area
== NULL
) {
1606 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1609 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1610 struct in_addr backbone
= {.s_addr
= INADDR_ANY
};
1611 exti
->area
= ospf_area_lookup_by_area_id(top
, backbone
);
1612 if (exti
->area
== NULL
) {
1613 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1614 "EXT (%s): Unable to set Area", __func__
);
1618 /* Set LSA header information */
1619 lsa
.area
= exti
->area
;
1621 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1622 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1623 lsah
.id
.s_addr
= htonl(tmp
);
1626 case REORIGINATE_THIS_LSA
:
1627 ospf_opaque_lsa_reoriginate_schedule(
1628 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1629 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
1631 case REFRESH_THIS_LSA
:
1632 ospf_opaque_lsa_refresh_schedule(&lsa
);
1634 case FLUSH_THIS_LSA
:
1635 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1636 ospf_opaque_lsa_flush_schedule(&lsa
);
1641 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1642 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
1643 enum lsa_opcode opcode
)
1645 struct ospf_lsa lsa
;
1646 struct lsa_header lsah
;
1650 memset(&lsa
, 0, sizeof(lsa
));
1651 memset(&lsah
, 0, sizeof(lsah
));
1657 /* Check if the corresponding link is ready to be flooded */
1658 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1661 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1662 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1663 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1664 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1665 exti
->ifp
? exti
->ifp
->name
: "-");
1668 if (exti
->area
== NULL
) {
1670 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1673 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1674 struct in_addr backbone
= {.s_addr
= INADDR_ANY
};
1675 exti
->area
= ospf_area_lookup_by_area_id(top
, backbone
);
1676 if (exti
->area
== NULL
) {
1677 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1678 "EXT (%s): Unable to set Area", __func__
);
1682 /* Set LSA header information */
1683 lsa
.area
= exti
->area
;
1685 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1686 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1687 lsah
.id
.s_addr
= htonl(tmp
);
1690 case REORIGINATE_THIS_LSA
:
1691 ospf_opaque_lsa_reoriginate_schedule(
1692 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1693 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
1695 case REFRESH_THIS_LSA
:
1696 ospf_opaque_lsa_refresh_schedule(&lsa
);
1698 case FLUSH_THIS_LSA
:
1699 ospf_opaque_lsa_flush_schedule(&lsa
);
1704 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1705 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
)
1708 if (exti
->stype
== PREF_SID
)
1709 ospf_ext_pref_lsa_schedule(exti
, op
);
1711 ospf_ext_link_lsa_schedule(exti
, op
);
1715 * ------------------------------------
1716 * Followings are vty show functions.
1717 * ------------------------------------
1720 #define check_tlv_size(size, msg) \
1722 if (ntohs(tlvh->length) != size) { \
1723 vty_out(vty, " Wrong %s TLV size: %d(%d). Abort!\n", \
1724 msg, ntohs(tlvh->length), size); \
1725 return size + TLV_HDR_SIZE; \
1729 /* Cisco experimental SubTLV */
1730 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty
*vty
,
1731 struct tlv_header
*tlvh
)
1733 struct ext_subtlv_rmt_itf_addr
*top
=
1734 (struct ext_subtlv_rmt_itf_addr
*)tlvh
;
1736 check_tlv_size(EXT_SUBTLV_RMT_ITF_ADDR_SIZE
, "Remote Itf. Address");
1739 " Remote Interface Address Sub-TLV: Length %u\n Address: %pI4\n",
1740 ntohs(top
->header
.length
), &top
->value
);
1742 return TLV_SIZE(tlvh
);
1745 /* Adjacency SID SubTLV */
1746 static uint16_t show_vty_ext_link_adj_sid(struct vty
*vty
,
1747 struct tlv_header
*tlvh
)
1749 struct ext_subtlv_adj_sid
*top
= (struct ext_subtlv_adj_sid
*)tlvh
;
1751 check_tlv_size(EXT_SUBTLV_ADJ_SID_SIZE
, "Adjacency SID");
1754 " Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1755 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1756 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1758 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1759 ? GET_LABEL(ntohl(top
->value
))
1760 : ntohl(top
->value
));
1762 return TLV_SIZE(tlvh
);
1765 /* LAN Adjacency SubTLV */
1766 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty
*vty
,
1767 struct tlv_header
*tlvh
)
1769 struct ext_subtlv_lan_adj_sid
*top
=
1770 (struct ext_subtlv_lan_adj_sid
*)tlvh
;
1772 check_tlv_size(EXT_SUBTLV_LAN_ADJ_SID_SIZE
, "Lan-Adjacency SID");
1775 " 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",
1776 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1778 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1780 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1781 ? GET_LABEL(ntohl(top
->value
))
1782 : ntohl(top
->value
));
1784 return TLV_SIZE(tlvh
);
1787 static uint16_t show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
,
1790 if (TLV_SIZE(tlvh
) > buf_size
) {
1791 vty_out(vty
, " TLV size %d exceeds buffer size. Abort!",
1796 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1797 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
1799 return TLV_SIZE(tlvh
);
1802 /* Extended Link Sub TLVs */
1803 static uint16_t show_vty_link_info(struct vty
*vty
, struct tlv_header
*ext
,
1806 struct ext_tlv_link
*top
= (struct ext_tlv_link
*)ext
;
1807 struct tlv_header
*tlvh
;
1808 uint16_t length
= ntohs(top
->header
.length
);
1811 /* Verify that TLV length is valid against remaining buffer size */
1812 if (length
> buf_size
) {
1814 " Extended Link TLV size %d exceeds buffer size. Abort!\n",
1820 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1822 ntohs(top
->header
.length
), top
->link_type
,
1824 vty_out(vty
, " Link data: %pI4\n", &top
->link_data
);
1826 /* Skip Extended TLV and parse sub-TLVs */
1827 length
-= EXT_TLV_LINK_SIZE
;
1828 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1829 + EXT_TLV_LINK_SIZE
);
1830 for (; sum
< length
&& tlvh
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1831 switch (ntohs(tlvh
->type
)) {
1832 case EXT_SUBTLV_ADJ_SID
:
1833 sum
+= show_vty_ext_link_adj_sid(vty
, tlvh
);
1835 case EXT_SUBTLV_LAN_ADJ_SID
:
1836 sum
+= show_vty_ext_link_lan_adj_sid(vty
, tlvh
);
1838 case EXT_SUBTLV_RMT_ITF_ADDR
:
1839 sum
+= show_vty_ext_link_rmt_itf_addr(vty
, tlvh
);
1842 sum
+= show_vty_unknown_tlv(vty
, tlvh
, length
- sum
);
1847 return sum
+ sizeof(struct ext_tlv_link
);
1850 /* Extended Link TLVs */
1851 static void ospf_ext_link_show_info(struct vty
*vty
, struct json_object
*json
,
1852 struct ospf_lsa
*lsa
)
1854 struct lsa_header
*lsah
= lsa
->data
;
1855 struct tlv_header
*tlvh
;
1856 uint16_t length
= 0, sum
= 0;
1861 /* Initialize TLV browsing */
1862 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
;
1864 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
&& tlvh
;
1865 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1866 switch (ntohs(tlvh
->type
)) {
1868 sum
+= show_vty_link_info(vty
, tlvh
, length
- sum
);
1871 sum
+= show_vty_unknown_tlv(vty
, tlvh
, length
- sum
);
1877 /* Prefix SID SubTLV */
1878 static uint16_t show_vty_ext_pref_pref_sid(struct vty
*vty
,
1879 struct tlv_header
*tlvh
)
1881 struct ext_subtlv_prefix_sid
*top
=
1882 (struct ext_subtlv_prefix_sid
*)tlvh
;
1884 check_tlv_size(EXT_SUBTLV_PREFIX_SID_SIZE
, "Prefix SID");
1887 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1888 ntohs(top
->header
.length
), top
->algorithm
, top
->flags
,
1890 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
) ? "Label"
1892 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
)
1893 ? GET_LABEL(ntohl(top
->value
))
1894 : ntohl(top
->value
));
1896 return TLV_SIZE(tlvh
);
1899 /* Extended Prefix SubTLVs */
1900 static uint16_t show_vty_pref_info(struct vty
*vty
, struct tlv_header
*ext
,
1903 struct ext_tlv_prefix
*top
= (struct ext_tlv_prefix
*)ext
;
1904 struct tlv_header
*tlvh
;
1905 uint16_t length
= ntohs(top
->header
.length
);
1908 /* Verify that TLV length is valid against remaining buffer size */
1909 if (length
> buf_size
) {
1911 " Extended Link TLV size %d exceeds buffer size. Abort!\n",
1917 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1918 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %pI4/%u\n",
1919 ntohs(top
->header
.length
), top
->route_type
, top
->af
, top
->flags
,
1920 &top
->address
, top
->pref_length
);
1922 /* Skip Extended Prefix TLV and parse sub-TLVs */
1923 length
-= EXT_TLV_PREFIX_SIZE
;
1924 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1925 + EXT_TLV_PREFIX_SIZE
);
1926 for (; sum
< length
&& tlvh
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1927 switch (ntohs(tlvh
->type
)) {
1928 case EXT_SUBTLV_PREFIX_SID
:
1929 sum
+= show_vty_ext_pref_pref_sid(vty
, tlvh
);
1932 sum
+= show_vty_unknown_tlv(vty
, tlvh
, length
- sum
);
1937 return sum
+ sizeof(struct ext_tlv_prefix
);
1940 /* Extended Prefix TLVs */
1941 static void ospf_ext_pref_show_info(struct vty
*vty
, struct json_object
*json
,
1942 struct ospf_lsa
*lsa
)
1944 struct lsa_header
*lsah
= lsa
->data
;
1945 struct tlv_header
*tlvh
;
1946 uint16_t length
= 0, sum
= 0;
1951 /* Initialize TLV browsing */
1952 length
= lsa
->size
- OSPF_LSA_HEADER_SIZE
;
1954 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
&& tlvh
;
1955 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1956 switch (ntohs(tlvh
->type
)) {
1957 case EXT_TLV_PREFIX
:
1958 sum
+= show_vty_pref_info(vty
, tlvh
, length
- sum
);
1961 sum
+= show_vty_unknown_tlv(vty
, tlvh
, length
- sum
);