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
;
306 /* Extended Link TLV - RFC7684 section 3.1 */
307 static void set_ext_link(struct ext_itf
*exti
, uint8_t type
, struct in_addr id
,
311 TLV_TYPE(exti
->link
) = htons(EXT_TLV_LINK
);
312 /* Warning: Size must be adjust depending of subTLV's */
313 TLV_LEN(exti
->link
) = htons(EXT_TLV_LINK_SIZE
);
314 exti
->link
.link_type
= type
;
315 exti
->link
.link_id
= id
;
316 exti
->link
.link_data
= data
;
319 /* Prefix SID SubTLV - section 5 */
320 static void set_prefix_sid(struct ext_itf
*exti
, uint8_t algorithm
,
321 uint32_t value
, int value_type
, uint8_t flags
)
324 if ((algorithm
!= SR_ALGORITHM_SPF
)
325 && (algorithm
!= SR_ALGORITHM_STRICT_SPF
)) {
326 flog_err(EC_OSPF_INVALID_ALGORITHM
,
327 "EXT (%s): unrecognized algorithm, not SPF or S-SPF",
332 /* Update flags according to the type of value field: label or index */
333 if (value_type
== SID_LABEL
)
334 SET_FLAG(flags
, EXT_SUBTLV_PREFIX_SID_VFLG
);
336 /* set prefix sid subtlv for an extended prefix tlv */
337 TLV_TYPE(exti
->node_sid
) = htons(EXT_SUBTLV_PREFIX_SID
);
338 exti
->node_sid
.algorithm
= algorithm
;
339 exti
->node_sid
.flags
= flags
;
340 exti
->node_sid
.mtid
= 0; /* Multi-Topology is not supported */
342 /* Set Label or Index value */
343 if (value_type
== SID_LABEL
) {
344 TLV_LEN(exti
->node_sid
) =
345 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE
));
346 exti
->node_sid
.value
= htonl(SET_LABEL(value
));
348 TLV_LEN(exti
->node_sid
) =
349 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE
));
350 exti
->node_sid
.value
= htonl(value
);
354 /* Adjacency SID SubTLV - section 6.1 */
355 static void set_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
361 /* Determine which ADJ_SID must be set: nominal or backup */
363 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
371 TLV_TYPE(exti
->adj_sid
[index
]) = htons(EXT_SUBTLV_ADJ_SID
);
373 /* Only Local ADJ-SID is supported for the moment */
374 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
376 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
378 /* Adjust Length, Flags and Value depending on the type of Label */
379 if (value_type
== SID_LABEL
) {
380 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
381 TLV_LEN(exti
->adj_sid
[index
]) =
382 htons(SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE
));
383 exti
->adj_sid
[index
].value
= htonl(SET_LABEL(value
));
385 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
386 TLV_LEN(exti
->adj_sid
[index
]) =
387 htons(SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE
));
388 exti
->adj_sid
[index
].value
= htonl(value
);
391 exti
->adj_sid
[index
].flags
= flags
; /* Set computed flags */
392 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
393 exti
->adj_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
396 /* LAN Adjacency SID SubTLV - section 6.2 */
397 static void set_lan_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
398 int value_type
, struct in_addr neighbor_id
)
404 /* Determine which ADJ_SID must be set: nominal or backup */
406 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
414 TLV_TYPE(exti
->lan_sid
[index
]) = htons(EXT_SUBTLV_LAN_ADJ_SID
);
416 /* Only Local ADJ-SID is supported for the moment */
417 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
419 /* Adjust Length, Flags and Value depending on the type of Label */
420 if (value_type
== SID_LABEL
) {
421 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
422 TLV_LEN(exti
->lan_sid
[index
]) =
423 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE
));
424 exti
->lan_sid
[index
].value
= htonl(SET_LABEL(value
));
426 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
427 TLV_LEN(exti
->lan_sid
[index
]) =
428 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE
));
429 exti
->lan_sid
[index
].value
= htonl(value
);
432 exti
->lan_sid
[index
].flags
= flags
; /* Set computed flags */
433 exti
->lan_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
434 exti
->lan_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
435 exti
->lan_sid
[index
].neighbor_id
= neighbor_id
;
438 static void unset_adjacency_sid(struct ext_itf
*exti
)
440 /* Reset Adjacency TLV */
441 if (exti
->type
== ADJ_SID
) {
442 TLV_TYPE(exti
->adj_sid
[0]) = 0;
443 TLV_TYPE(exti
->adj_sid
[1]) = 0;
445 /* or Lan-Adjacency TLV */
446 if (exti
->type
== LAN_ADJ_SID
) {
447 TLV_TYPE(exti
->lan_sid
[0]) = 0;
448 TLV_TYPE(exti
->lan_sid
[1]) = 0;
452 /* Experimental SubTLV from Cisco */
453 static void set_rmt_itf_addr(struct ext_itf
*exti
, struct in_addr rmtif
)
456 TLV_TYPE(exti
->rmt_itf_addr
) = htons(EXT_SUBTLV_RMT_ITF_ADDR
);
457 TLV_LEN(exti
->rmt_itf_addr
) = htons(sizeof(struct in_addr
));
458 exti
->rmt_itf_addr
.value
= rmtif
;
461 /* Delete Extended LSA */
462 static void ospf_extended_lsa_delete(struct ext_itf
*exti
)
465 /* Avoid deleting LSA if Extended is not enable */
466 if (!OspfEXT
.enabled
)
469 /* Process only Active Extended Prefix/Link LSA */
470 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
473 osr_debug("EXT (%s): Disable %s%s%s-SID on interface %s", __func__
,
474 exti
->stype
== LOCAL_SID
? "Prefix" : "",
475 exti
->stype
== ADJ_SID
? "Adjacency" : "",
476 exti
->stype
== LAN_ADJ_SID
? "LAN-Adjacency" : "",
479 /* Flush LSA if already engaged */
480 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
481 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
482 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
485 /* De-activate this Extended Prefix/Link and remove corresponding
486 * Segment-Routing Prefix-SID or (LAN)-ADJ-SID */
487 if (exti
->stype
== ADJ_SID
|| exti
->stype
== LAN_ADJ_SID
)
488 ospf_ext_link_delete_adj_sid(exti
);
490 ospf_sr_ext_itf_delete(exti
);
494 * Update Extended prefix SID index for Loopback interface type
496 * @param ifname - Loopback interface name
497 * @param index - new value for the prefix SID of this interface
498 * @param p - prefix for this interface or NULL if Extended Prefix
501 * @return instance number if update is OK, 0 otherwise
503 uint32_t ospf_ext_schedule_prefix_index(struct interface
*ifp
, uint32_t index
,
504 struct prefix_ipv4
*p
, uint8_t flags
)
507 struct ext_itf
*exti
;
509 /* Find Extended Prefix interface */
510 exti
= lookup_ext_by_ifp(ifp
);
515 osr_debug("EXT (%s): Schedule new prefix %pFX with index %u on interface %s", __func__
, p
, index
, ifp
->name
);
517 /* Set first Extended Prefix then the Prefix SID information */
518 set_ext_prefix(exti
, OSPF_PATH_INTRA_AREA
, EXT_TLV_PREF_NFLG
,
520 set_prefix_sid(exti
, SR_ALGORITHM_SPF
, index
, SID_INDEX
, flags
);
522 /* Try to Schedule LSA */
523 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
524 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
525 ospf_ext_pref_lsa_schedule(exti
,
528 ospf_ext_pref_lsa_schedule(
529 exti
, REORIGINATE_THIS_LSA
);
532 osr_debug("EXT (%s): Remove prefix for interface %s", __func__
,
535 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
536 ospf_ext_pref_lsa_schedule(exti
, FLUSH_THIS_LSA
);
539 return SET_OPAQUE_LSID(exti
->type
, exti
->instance
);
543 * Update Adjacecny-SID for Extended Link LSA
545 * @param exti Extended Link information
547 static void ospf_ext_link_update_adj_sid(struct ext_itf
*exti
)
550 mpls_label_t bck_label
;
552 /* Process only (LAN)Adjacency-SID Type */
553 if (exti
->stype
!= ADJ_SID
&& exti
->stype
!= LAN_ADJ_SID
)
556 /* Request Primary & Backup Labels from Label Manager */
557 bck_label
= ospf_sr_local_block_request_label();
558 label
= ospf_sr_local_block_request_label();
559 if (bck_label
== MPLS_INVALID_LABEL
|| label
== MPLS_INVALID_LABEL
) {
560 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
561 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
565 /* Set Adjacency-SID, backup first */
566 if (exti
->stype
== ADJ_SID
) {
567 set_adj_sid(exti
, true, bck_label
, SID_LABEL
);
568 set_adj_sid(exti
, false, label
, SID_LABEL
);
570 set_lan_adj_sid(exti
, true, bck_label
, SID_LABEL
,
571 exti
->lan_sid
[0].neighbor_id
);
572 set_lan_adj_sid(exti
, false, label
, SID_LABEL
,
573 exti
->lan_sid
[1].neighbor_id
);
576 /* Finally, add corresponding SR Link in SRDB & MPLS LFIB */
577 SET_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
);
578 ospf_sr_ext_itf_add(exti
);
582 * Delete Adjacecny-SID for Extended Link LSA
584 * @param exti Extended Link information
586 static void ospf_ext_link_delete_adj_sid(struct ext_itf
*exti
)
588 /* Process only (LAN)Adjacency-SID Type */
589 if (exti
->stype
!= ADJ_SID
&& exti
->stype
!= LAN_ADJ_SID
)
592 /* Release Primary & Backup Labels from Label Manager */
593 if (exti
->stype
== ADJ_SID
) {
594 ospf_sr_local_block_release_label(exti
->adj_sid
[0].value
);
595 ospf_sr_local_block_release_label(exti
->adj_sid
[1].value
);
597 ospf_sr_local_block_release_label(exti
->lan_sid
[0].value
);
598 ospf_sr_local_block_release_label(exti
->lan_sid
[1].value
);
600 /* And reset corresponding TLV */
601 unset_adjacency_sid(exti
);
603 /* Finally, remove corresponding SR Link in SRDB & MPLS LFIB */
604 UNSET_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
);
605 ospf_sr_ext_itf_delete(exti
);
609 * Update Extended Link LSA once Segment Routing Label Block has been changed.
611 void ospf_ext_link_srlb_update(void)
613 struct listnode
*node
;
614 struct ext_itf
*exti
;
617 osr_debug("EXT (%s): Update Extended Links with new SRLB", __func__
);
619 /* Update all Extended Link Adjaceny-SID */
620 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
621 /* Skip Extended Prefix */
622 if (exti
->stype
== PREF_SID
|| exti
->stype
== LOCAL_SID
)
625 /* Skip inactive Extended Link */
626 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
629 ospf_ext_link_update_adj_sid(exti
);
634 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
636 * @param enable To activate or not Segment Routing Extended LSA flooding
640 void ospf_ext_update_sr(bool enable
)
642 struct listnode
*node
;
643 struct ext_itf
*exti
;
645 osr_debug("EXT (%s): %s Extended LSAs for Segment Routing ", __func__
,
646 enable
? "Enable" : "Disable");
649 OspfEXT
.enabled
= true;
651 /* Refresh LSAs if already engaged or originate */
652 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
653 /* Skip Inactive Extended Link */
654 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
657 /* Update Extended Link (LAN)Adj-SID if not set */
658 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
))
659 ospf_ext_link_update_adj_sid(exti
);
661 /* Finally, flood the extended Link */
662 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
663 ospf_ext_lsa_schedule(exti
, REFRESH_THIS_LSA
);
665 ospf_ext_lsa_schedule(exti
,
666 REORIGINATE_THIS_LSA
);
669 /* Start by Removing Extended LSA */
670 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
671 ospf_extended_lsa_delete(exti
);
673 /* And then disable Extended Link/Prefix */
674 OspfEXT
.enabled
= false;
679 * -----------------------------------------------------------------------
680 * Followings are callback functions against generic Opaque-LSAs handling
681 * -----------------------------------------------------------------------
684 /* Add new Interface in Extended Interface List */
685 static int ospf_ext_link_new_if(struct interface
*ifp
)
690 if (lookup_ext_by_ifp(ifp
) != NULL
) {
691 rc
= 0; /* Do nothing here. */
695 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS
, sizeof(struct ext_itf
));
697 /* initialize new information and link back the interface */
699 new->flags
= EXT_LPFLG_LSA_INACTIVE
;
701 listnode_add(OspfEXT
.iflist
, new);
707 /* Remove existing Interface from Extended Interface List */
708 static int ospf_ext_link_del_if(struct interface
*ifp
)
710 struct ext_itf
*exti
;
713 exti
= lookup_ext_by_ifp(ifp
);
715 /* Flush LSA and remove Adjacency SID */
716 ospf_extended_lsa_delete(exti
);
718 /* Dequeue listnode entry from the list. */
719 listnode_delete(OspfEXT
.iflist
, exti
);
721 XFREE(MTYPE_OSPF_EXT_PARAMS
, exti
);
725 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
726 "EXT (%s): interface %s is not found", __func__
,
727 ifp
? ifp
->name
: "-");
734 * Determine if an Interface belongs to an Extended Link Adjacency or
735 * Extended Prefix SID type and allocate new instance value accordingly
737 static void ospf_ext_ism_change(struct ospf_interface
*oi
, int old_status
)
739 struct ext_itf
*exti
;
741 /* Get interface information for Segment Routing */
742 exti
= lookup_ext_by_ifp(oi
->ifp
);
744 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
745 "EXT (%s): Cannot get Extended info. from OI(%s)",
746 __func__
, IF_NAME(oi
));
750 /* Reset Extended information if ospf interface goes Down */
751 if (oi
->state
== ISM_Down
) {
752 ospf_extended_lsa_delete(exti
);
754 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
758 /* Determine if interface is related to a Prefix or an Adjacency SID */
759 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
760 exti
->stype
= PREF_SID
;
761 exti
->type
= OPAQUE_TYPE_EXTENDED_PREFIX_LSA
;
762 exti
->instance
= get_ext_pref_instance_value();
763 exti
->area
= oi
->area
;
765 /* Complete SRDB if the interface belongs to a Prefix */
766 if (OspfEXT
.enabled
) {
767 osr_debug("EXT (%s): Set Prefix SID to interface %s ",
768 __func__
, oi
->ifp
->name
);
769 exti
->flags
= EXT_LPFLG_LSA_ACTIVE
;
770 ospf_sr_update_local_prefix(oi
->ifp
, oi
->address
);
773 /* Determine if interface is related to Adj. or LAN Adj. SID */
774 if (oi
->state
== ISM_DR
)
775 exti
->stype
= LAN_ADJ_SID
;
777 exti
->stype
= ADJ_SID
;
779 exti
->type
= OPAQUE_TYPE_EXTENDED_LINK_LSA
;
780 exti
->instance
= get_ext_link_instance_value();
781 exti
->area
= oi
->area
;
784 * Note: Adjacency SID information are completed when ospf
785 * adjacency become up see ospf_ext_link_nsm_change()
789 "EXT (%s): Set %sAdjacency SID for interface %s ",
790 __func__
, exti
->stype
== ADJ_SID
? "" : "LAN-",
796 * Finish Extended Link configuration and flood corresponding LSA
797 * when OSPF adjacency on this link fire up
799 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
)
801 struct ospf_interface
*oi
= nbr
->oi
;
802 struct ext_itf
*exti
;
804 /* Process Link only when neighbor old or new state is NSM Full */
805 if (nbr
->state
!= NSM_Full
&& old_status
!= NSM_Full
)
808 /* Get interface information for Segment Routing */
809 exti
= lookup_ext_by_ifp(oi
->ifp
);
811 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
812 "EXT (%s): Cannot get Extended info. from OI(%s)",
813 __func__
, IF_NAME(oi
));
817 /* Check that we have a valid area and ospf context */
818 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
819 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
820 "EXT (%s): Cannot refer to OSPF from OI(%s)",
821 __func__
, IF_NAME(oi
));
825 /* Remove Extended Link if Neighbor State goes Down or Deleted */
827 && (nbr
->state
== NSM_Down
|| nbr
->state
== NSM_Deleted
)) {
828 ospf_ext_link_delete_adj_sid(exti
);
829 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
830 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
831 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
835 /* Keep Area information in combination with SR info. */
836 exti
->area
= oi
->area
;
838 /* Process only Adjacency/LAN SID */
839 if (exti
->stype
== PREF_SID
)
843 case ISM_PointToPoint
:
844 /* Segment ID is an Adjacency one */
845 exti
->stype
= ADJ_SID
;
847 /* Set Extended Link TLV with link_id == Nbr Router ID */
848 set_ext_link(exti
, OSPF_IFTYPE_POINTOPOINT
, nbr
->router_id
,
849 oi
->address
->u
.prefix4
);
851 /* And Remote Interface address */
852 set_rmt_itf_addr(exti
, nbr
->address
.u
.prefix4
);
857 /* Segment ID is a LAN Adjacency for the DR only */
858 exti
->stype
= LAN_ADJ_SID
;
860 /* Set Extended Link TLV with link_id == DR */
861 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
862 oi
->address
->u
.prefix4
);
864 /* Set Neighbor ID */
865 exti
->lan_sid
[0].neighbor_id
= nbr
->router_id
;
866 exti
->lan_sid
[1].neighbor_id
= nbr
->router_id
;
872 /* Segment ID is an Adjacency if not the DR */
873 exti
->stype
= ADJ_SID
;
875 /* Set Extended Link TLV with link_id == DR */
876 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
877 oi
->address
->u
.prefix4
);
882 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
))
883 ospf_ext_link_delete_adj_sid(exti
);
884 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
885 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
886 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
890 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
892 if (OspfEXT
.enabled
) {
893 osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
894 __func__
, exti
->stype
== ADJ_SID
? "" : "LAN-",
897 /* Update (LAN)Adjacency SID */
898 ospf_ext_link_update_adj_sid(exti
);
900 /* flood this links params if everything is ok */
901 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
902 ospf_ext_link_lsa_schedule(exti
, REFRESH_THIS_LSA
);
904 ospf_ext_link_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
908 /* Callbacks to handle Extended Link Segment Routing LSA information */
909 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
)
913 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
918 /* Process only Opaque LSA */
919 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
920 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
923 /* Process only Extended Link LSA */
924 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
925 != OPAQUE_TYPE_EXTENDED_LINK_LSA
)
928 /* Check if it is not my LSA */
929 if (IS_LSA_SELF(lsa
))
932 /* Check if Extended is enable */
933 if (!OspfEXT
.enabled
)
936 /* Call Segment Routing LSA update or deletion */
937 if (!IS_LSA_MAXAGE(lsa
))
938 ospf_sr_ext_link_lsa_update(lsa
);
940 ospf_sr_ext_link_lsa_delete(lsa
);
945 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
946 static int ospf_ext_pref_lsa_update(struct ospf_lsa
*lsa
)
951 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
956 /* Process only Opaque LSA */
957 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
958 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
961 /* Process only Extended Prefix LSA */
962 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
963 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA
)
966 /* Check if it is not my LSA */
967 if (IS_LSA_SELF(lsa
))
970 /* Check if Extended is enable */
971 if (!OspfEXT
.enabled
)
974 /* Call Segment Routing LSA update or deletion */
975 if (!IS_LSA_MAXAGE(lsa
))
976 ospf_sr_ext_prefix_lsa_update(lsa
);
978 ospf_sr_ext_prefix_lsa_delete(lsa
);
984 * -------------------------------------------------------
985 * Followings are OSPF protocol processing functions for
986 * Extended Prefix/Link Opaque LSA
987 * -------------------------------------------------------
990 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
992 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
995 static void build_tlv(struct stream
*s
, struct tlv_header
*tlvh
)
998 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
999 build_tlv_header(s
, tlvh
);
1000 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
1004 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
1005 static void ospf_ext_pref_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
1009 if ((exti
== NULL
) || (exti
->stype
!= PREF_SID
))
1012 /* Adjust Extended Prefix TLV size */
1013 TLV_LEN(exti
->prefix
) = htons(ntohs(TLV_LEN(exti
->node_sid
))
1014 + EXT_TLV_PREFIX_SIZE
+ TLV_HDR_SIZE
);
1016 /* Build LSA body for an Extended Prefix TLV */
1017 build_tlv_header(s
, &exti
->prefix
.header
);
1018 stream_put(s
, TLV_DATA(&exti
->prefix
.header
), EXT_TLV_PREFIX_SIZE
);
1019 /* Then add Prefix SID SubTLV */
1020 build_tlv(s
, &exti
->node_sid
.header
);
1023 /* Build an Extended Link Opaque LSA body for extended link TLV */
1024 static void ospf_ext_link_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
1030 || ((exti
->stype
!= ADJ_SID
) && (exti
->stype
!= LAN_ADJ_SID
)))
1033 if (exti
->stype
== ADJ_SID
) {
1034 /* Adjust Extended Link TLV size for Adj. SID */
1035 size
= EXT_TLV_LINK_SIZE
+ 2 * EXT_SUBTLV_ADJ_SID_SIZE
1037 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
1038 size
= size
+ EXT_SUBTLV_RMT_ITF_ADDR_SIZE
1040 TLV_LEN(exti
->link
) = htons(size
);
1042 /* Build LSA body for an Extended Link TLV with Adj. SID */
1043 build_tlv_header(s
, &exti
->link
.header
);
1044 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
1045 /* then add Adjacency SubTLVs */
1046 build_tlv(s
, &exti
->adj_sid
[1].header
);
1047 build_tlv(s
, &exti
->adj_sid
[0].header
);
1049 /* Add Cisco experimental SubTLV if interface is PtoP */
1050 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
1051 build_tlv(s
, &exti
->rmt_itf_addr
.header
);
1053 /* Adjust Extended Link TLV size for LAN SID */
1054 size
= EXT_TLV_LINK_SIZE
1055 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE
+ TLV_HDR_SIZE
);
1056 TLV_LEN(exti
->link
) = htons(size
);
1058 /* Build LSA body for an Extended Link TLV with LAN SID */
1059 build_tlv_header(s
, &exti
->link
.header
);
1060 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
1061 /* then add LAN-Adjacency SubTLVs */
1062 build_tlv(s
, &exti
->lan_sid
[1].header
);
1063 build_tlv(s
, &exti
->lan_sid
[0].header
);
1067 /* Create new Extended Prefix opaque-LSA for every extended prefix */
1068 static struct ospf_lsa
*ospf_ext_pref_lsa_new(struct ospf_area
*area
,
1069 struct ext_itf
*exti
)
1072 struct lsa_header
*lsah
;
1073 struct ospf_lsa
*new = NULL
;
1075 uint8_t options
, lsa_type
;
1076 struct in_addr lsa_id
;
1077 struct in_addr router_id
;
1085 /* Create a stream for LSA. */
1086 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1088 /* Prepare LSA Header */
1089 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1091 lsa_type
= OspfEXT
.scope
;
1094 * LSA ID is a variable number identifying different instances of
1095 * Extended Prefix Opaque LSA from the same router see RFC 7684
1097 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1098 lsa_id
.s_addr
= htonl(tmp
);
1100 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1102 /* Fix Options and Router ID depending of the flooding scope */
1103 if ((OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
) || (area
== NULL
)) {
1104 options
= OSPF_OPTION_E
;
1105 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1106 router_id
.s_addr
= top
? top
->router_id
.s_addr
: 0;
1108 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1109 options
|= LSA_OPTIONS_NSSA_GET(area
);
1110 router_id
= area
->ospf
->router_id
;
1113 /* Set opaque-LSA header fields. */
1114 lsa_header_set(s
, options
, lsa_type
, lsa_id
, router_id
);
1117 "EXT (%s): LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Prefix Opaque LSA instance",
1118 __func__
, lsa_type
, &lsa_id
);
1120 /* Set opaque-LSA body fields. */
1121 ospf_ext_pref_lsa_body_set(s
, exti
);
1124 length
= stream_get_endp(s
);
1125 lsah
->length
= htons(length
);
1127 /* Now, create an OSPF LSA instance. */
1128 new = ospf_lsa_new_and_data(length
);
1130 /* Segment Routing belongs only to default VRF */
1131 new->vrf_id
= VRF_DEFAULT
;
1133 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1134 memcpy(new->data
, lsah
, length
);
1140 /* Create new Extended Link opaque-LSA for every extended link TLV */
1141 static struct ospf_lsa
*ospf_ext_link_lsa_new(struct ospf_area
*area
,
1142 struct ext_itf
*exti
)
1145 struct lsa_header
*lsah
;
1146 struct ospf_lsa
*new = NULL
;
1147 uint8_t options
, lsa_type
;
1148 struct in_addr lsa_id
;
1156 /* Create a stream for LSA. */
1157 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1158 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1160 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1161 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1162 options
|= LSA_OPTIONS_NSSA_GET(area
);
1163 /* Extended Link Opaque LSA are only flooded within an area */
1164 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1167 * LSA ID is a variable number identifying different instances of
1168 * Extended Link Opaque LSA from the same router see RFC 7684
1170 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1171 lsa_id
.s_addr
= htonl(tmp
);
1174 "EXT (%s) LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Link Opaque LSA instance",
1175 __func__
, lsa_type
, &lsa_id
);
1177 /* Set opaque-LSA header fields. */
1178 lsa_header_set(s
, options
, lsa_type
, lsa_id
, area
->ospf
->router_id
);
1180 /* Set opaque-LSA body fields. */
1181 ospf_ext_link_lsa_body_set(s
, exti
);
1184 length
= stream_get_endp(s
);
1185 lsah
->length
= htons(length
);
1187 /* Now, create an OSPF LSA instance. */
1188 new = ospf_lsa_new_and_data(length
);
1190 /* Segment Routing belongs only to default VRF */
1191 new->vrf_id
= VRF_DEFAULT
;
1193 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1194 memcpy(new->data
, lsah
, length
);
1201 * Process the origination of an Extended Prefix Opaque LSA
1202 * for every extended prefix TLV
1204 static int ospf_ext_pref_lsa_originate1(struct ospf_area
*area
,
1205 struct ext_itf
*exti
)
1207 struct ospf_lsa
*new;
1211 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1212 new = ospf_ext_pref_lsa_new(area
, exti
);
1214 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1215 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1219 /* Install this LSA into LSDB. */
1220 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1221 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1222 "EXT (%s): ospf_lsa_install() error", __func__
);
1223 ospf_lsa_unlock(&new);
1227 /* Now this Extended Prefix Opaque LSA info parameter entry has
1230 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1232 /* Update new LSA origination count. */
1233 area
->ospf
->lsa_originate_count
++;
1235 /* Flood new LSA through area. */
1236 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1239 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSAExtended Prefix Opaque LSA: Area(%pI4), Link(%s)",
1240 __func__
, new->data
->type
, &new->data
->id
,
1241 &area
->area_id
, exti
->ifp
->name
);
1242 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1243 ospf_lsa_header_dump(new->data
);
1251 * Process the origination of an Extended Link Opaque LSA
1252 * for every extended link TLV
1254 static int ospf_ext_link_lsa_originate1(struct ospf_area
*area
,
1255 struct ext_itf
*exti
)
1257 struct ospf_lsa
*new;
1260 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1261 new = ospf_ext_link_lsa_new(area
, exti
);
1263 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1264 "EXT (%s): ospf_ext_link_lsa_new() error", __func__
);
1268 /* Install this LSA into LSDB. */
1269 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1270 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1271 "EXT (%s): ospf_lsa_install() error", __func__
);
1272 ospf_lsa_unlock(&new);
1276 /* Now this link-parameter entry has associated LSA. */
1277 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1279 /* Update new LSA origination count. */
1280 area
->ospf
->lsa_originate_count
++;
1282 /* Flood new LSA through area. */
1283 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1286 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSA Extended Link Opaque LSA: Area(%pI4), Link(%s)",
1287 __func__
, new->data
->type
, &new->data
->id
,
1288 &area
->area_id
, exti
->ifp
->name
);
1289 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1290 ospf_lsa_header_dump(new->data
);
1297 /* Trigger the origination of Extended Prefix Opaque LSAs */
1298 static int ospf_ext_pref_lsa_originate(void *arg
)
1300 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1301 struct listnode
*node
;
1302 struct ext_itf
*exti
;
1305 if (!OspfEXT
.enabled
) {
1307 "EXT (%s): Segment Routing functionality is Disabled now",
1309 rc
= 0; /* This is not an error case. */
1312 osr_debug("EXT (%s): Start Originate Prefix LSA for area %pI4",
1313 __func__
, &area
->area_id
);
1315 /* Check if Extended Prefix Opaque LSA is already engaged */
1316 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1318 /* Process only Prefix SID */
1319 if (exti
->stype
!= PREF_SID
)
1322 /* Process only Extended Prefix with valid Area ID */
1323 if ((exti
->area
== NULL
)
1324 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1327 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1328 if (CHECK_FLAG(exti
->flags
,
1329 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1331 EC_OSPF_EXT_LSA_UNEXPECTED
,
1332 "EXT (%s): Refresh instead of Originate",
1334 UNSET_FLAG(exti
->flags
,
1335 EXT_LPFLG_LSA_FORCED_REFRESH
);
1336 ospf_ext_pref_lsa_schedule(exti
,
1342 /* Ok, let's try to originate an LSA */
1344 "EXT (%s): Let's finally re-originate the LSA 7.0.0.%u for Itf %s", __func__
, exti
->instance
,
1345 exti
->ifp
? exti
->ifp
->name
: "");
1346 ospf_ext_pref_lsa_originate1(area
, exti
);
1353 /* Trigger the origination of Extended Link Opaque LSAs */
1354 static int ospf_ext_link_lsa_originate(void *arg
)
1356 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1357 struct listnode
*node
;
1358 struct ext_itf
*exti
;
1361 if (!OspfEXT
.enabled
) {
1363 "EXT (%s): Segment Routing functionality is Disabled now",
1365 rc
= 0; /* This is not an error case. */
1369 /* Check if Extended Prefix Opaque LSA is already engaged */
1370 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1371 /* Process only Adjacency or LAN SID */
1372 if (exti
->stype
== PREF_SID
)
1375 /* Skip Inactive Extended Link */
1376 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
1379 /* Process only Extended Link with valid Area ID */
1380 if ((exti
->area
== NULL
)
1381 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1384 /* Check if LSA not already engaged */
1385 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1386 if (CHECK_FLAG(exti
->flags
,
1387 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1389 EC_OSPF_EXT_LSA_UNEXPECTED
,
1390 "EXT (%s): Refresh instead of Originate",
1392 UNSET_FLAG(exti
->flags
,
1393 EXT_LPFLG_LSA_FORCED_REFRESH
);
1394 ospf_ext_link_lsa_schedule(exti
,
1400 /* Ok, let's try to originate an LSA */
1402 "EXT (%s): Let's finally reoriginate the LSA 8.0.0.%u for Itf %s through the Area %pI4", __func__
,
1403 exti
->instance
, exti
->ifp
? exti
->ifp
->name
: "-",
1405 ospf_ext_link_lsa_originate1(area
, exti
);
1412 /* Refresh an Extended Prefix Opaque LSA */
1413 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
)
1415 struct ospf_lsa
*new = NULL
;
1416 struct ospf_area
*area
= lsa
->area
;
1418 struct ext_itf
*exti
;
1420 if (!OspfEXT
.enabled
) {
1422 * This LSA must have flushed before due to Extended Prefix
1423 * Opaque LSA status change.
1424 * It seems a slip among routers in the routing domain.
1427 "EXT (%s): Segment Routing functionality is Disabled",
1429 /* Flush it anyway. */
1430 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1433 /* Lookup this lsa corresponding Extended parameters */
1434 exti
= lookup_ext_by_instance(lsa
);
1436 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1437 "EXT (%s): Invalid parameter LSA ID", __func__
);
1438 /* Flush it anyway. */
1439 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1442 /* Check if Interface was not disable in the interval */
1443 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1444 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1445 "EXT (%s): Interface was Disabled: Flush it!",
1447 /* Flush it anyway. */
1448 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1451 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1452 if (IS_LSA_MAXAGE(lsa
)) {
1454 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1455 ospf_opaque_lsa_flush_schedule(lsa
);
1459 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1460 new = ospf_ext_pref_lsa_new(area
, exti
);
1463 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1464 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1467 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1470 * Install this LSA into LSDB
1471 * Given "lsa" will be freed in the next function
1472 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1473 * ospf_lookup() to get ospf instance
1478 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1480 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1481 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1482 "EXT (%s): ospf_lsa_install() error", __func__
);
1483 ospf_lsa_unlock(&new);
1487 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1488 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1490 /* Debug logging. */
1491 osr_debug("EXT (%s): LSA[Type%u:%pI4] Refresh Extended Prefix LSA",
1492 __func__
, new->data
->type
, &new->data
->id
);
1493 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1494 ospf_lsa_header_dump(new->data
);
1500 /* Refresh an Extended Link Opaque LSA */
1501 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
)
1503 struct ext_itf
*exti
;
1504 struct ospf_area
*area
= lsa
->area
;
1505 struct ospf
*top
= area
->ospf
;
1506 struct ospf_lsa
*new = NULL
;
1508 if (!OspfEXT
.enabled
) {
1510 * This LSA must have flushed before due to OSPF-SR status
1511 * change. It seems a slip among routers in the routing domain.
1513 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1515 /* Flush it anyway. */
1516 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1519 /* Lookup this LSA corresponding Extended parameters */
1520 exti
= lookup_ext_by_instance(lsa
);
1522 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1523 "EXT (%s): Invalid parameter LSA ID", __func__
);
1524 /* Flush it anyway. */
1525 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1528 /* Check if Interface was not disable in the interval */
1529 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1530 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1531 "EXT (%s): Interface was Disabled: Flush it!",
1533 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1536 /* If the lsa's age reached to MaxAge, start flushing procedure */
1537 if (IS_LSA_MAXAGE(lsa
)) {
1539 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1540 ospf_opaque_lsa_flush_schedule(lsa
);
1544 /* Create new Opaque-LSA/Extended Link instance */
1545 new = ospf_ext_link_lsa_new(area
, exti
);
1547 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1548 "EXT (%s): Error creating new LSA", __func__
);
1551 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1553 /* Install this LSA into LSDB. */
1554 /* Given "lsa" will be freed in the next function */
1555 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1556 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1557 "EXT (%s): Error installing new LSA", __func__
);
1558 ospf_lsa_unlock(&new);
1562 /* Flood updated LSA through the link Area according to the RFC7684 */
1563 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1565 /* Debug logging. */
1566 osr_debug("EXT (%s): LSA[Type%u:%pI4]: Refresh Extended Link LSA",
1567 __func__
, new->data
->type
, &new->data
->id
);
1568 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1569 ospf_lsa_header_dump(new->data
);
1574 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1575 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
1576 enum lsa_opcode opcode
)
1578 struct ospf_lsa lsa
;
1579 struct lsa_header lsah
;
1583 memset(&lsa
, 0, sizeof(lsa
));
1584 memset(&lsah
, 0, sizeof(lsah
));
1590 /* Check if the corresponding link is ready to be flooded */
1591 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1594 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1595 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1596 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1597 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1598 exti
->ifp
? exti
->ifp
->name
: "-");
1601 if (exti
->area
== NULL
) {
1603 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1606 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1607 struct in_addr backbone
= {.s_addr
= INADDR_ANY
};
1608 exti
->area
= ospf_area_lookup_by_area_id(top
, backbone
);
1609 if (exti
->area
== NULL
) {
1610 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1611 "EXT (%s): Unable to set Area", __func__
);
1615 /* Set LSA header information */
1616 lsa
.area
= exti
->area
;
1618 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1619 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1620 lsah
.id
.s_addr
= htonl(tmp
);
1623 case REORIGINATE_THIS_LSA
:
1624 ospf_opaque_lsa_reoriginate_schedule(
1625 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1626 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
1628 case REFRESH_THIS_LSA
:
1629 ospf_opaque_lsa_refresh_schedule(&lsa
);
1631 case FLUSH_THIS_LSA
:
1632 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1633 ospf_opaque_lsa_flush_schedule(&lsa
);
1638 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1639 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
1640 enum lsa_opcode opcode
)
1642 struct ospf_lsa lsa
;
1643 struct lsa_header lsah
;
1647 memset(&lsa
, 0, sizeof(lsa
));
1648 memset(&lsah
, 0, sizeof(lsah
));
1654 /* Check if the corresponding link is ready to be flooded */
1655 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1658 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1659 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1660 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1661 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1662 exti
->ifp
? exti
->ifp
->name
: "-");
1665 if (exti
->area
== NULL
) {
1667 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1670 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1671 struct in_addr backbone
= {.s_addr
= INADDR_ANY
};
1672 exti
->area
= ospf_area_lookup_by_area_id(top
, backbone
);
1673 if (exti
->area
== NULL
) {
1674 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1675 "EXT (%s): Unable to set Area", __func__
);
1679 /* Set LSA header information */
1680 lsa
.area
= exti
->area
;
1682 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1683 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1684 lsah
.id
.s_addr
= htonl(tmp
);
1687 case REORIGINATE_THIS_LSA
:
1688 ospf_opaque_lsa_reoriginate_schedule(
1689 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1690 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
1692 case REFRESH_THIS_LSA
:
1693 ospf_opaque_lsa_refresh_schedule(&lsa
);
1695 case FLUSH_THIS_LSA
:
1696 ospf_opaque_lsa_flush_schedule(&lsa
);
1701 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1702 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
)
1705 if (exti
->stype
== PREF_SID
)
1706 ospf_ext_pref_lsa_schedule(exti
, op
);
1708 ospf_ext_link_lsa_schedule(exti
, op
);
1712 * ------------------------------------
1713 * Followings are vty show functions.
1714 * ------------------------------------
1717 /* Cisco experimental SubTLV */
1718 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty
*vty
,
1719 struct tlv_header
*tlvh
)
1721 struct ext_subtlv_rmt_itf_addr
*top
;
1723 top
= (struct ext_subtlv_rmt_itf_addr
*)tlvh
;
1726 " Remote Interface Address Sub-TLV: Length %u\n Address: %pI4\n",
1727 ntohs(top
->header
.length
), &top
->value
);
1729 return TLV_SIZE(tlvh
);
1732 /* Adjacency SID SubTLV */
1733 static uint16_t show_vty_ext_link_adj_sid(struct vty
*vty
,
1734 struct tlv_header
*tlvh
)
1736 struct ext_subtlv_adj_sid
*top
= (struct ext_subtlv_adj_sid
*)tlvh
;
1739 " Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1740 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1741 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1743 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1744 ? GET_LABEL(ntohl(top
->value
))
1745 : ntohl(top
->value
));
1747 return TLV_SIZE(tlvh
);
1750 /* LAN Adjacency SubTLV */
1751 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty
*vty
,
1752 struct tlv_header
*tlvh
)
1754 struct ext_subtlv_lan_adj_sid
*top
=
1755 (struct ext_subtlv_lan_adj_sid
*)tlvh
;
1758 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: %pI4\n\t%s: %u\n",
1759 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1761 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1763 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1764 ? GET_LABEL(ntohl(top
->value
))
1765 : ntohl(top
->value
));
1767 return TLV_SIZE(tlvh
);
1770 static uint16_t show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
)
1772 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1773 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
1775 return TLV_SIZE(tlvh
);
1778 /* Extended Link Sub TLVs */
1779 static uint16_t show_vty_link_info(struct vty
*vty
, struct tlv_header
*ext
)
1781 struct ext_tlv_link
*top
= (struct ext_tlv_link
*)ext
;
1782 struct tlv_header
*tlvh
;
1783 uint16_t length
= ntohs(top
->header
.length
) - 3 * sizeof(uint32_t);
1787 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1789 ntohs(top
->header
.length
), top
->link_type
,
1791 vty_out(vty
, " Link data: %pI4\n", &top
->link_data
);
1793 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1794 + EXT_TLV_LINK_SIZE
);
1795 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1796 switch (ntohs(tlvh
->type
)) {
1797 case EXT_SUBTLV_ADJ_SID
:
1798 sum
+= show_vty_ext_link_adj_sid(vty
, tlvh
);
1800 case EXT_SUBTLV_LAN_ADJ_SID
:
1801 sum
+= show_vty_ext_link_lan_adj_sid(vty
, tlvh
);
1803 case EXT_SUBTLV_RMT_ITF_ADDR
:
1804 sum
+= show_vty_ext_link_rmt_itf_addr(vty
, tlvh
);
1807 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1812 return sum
+ sizeof(struct ext_tlv_link
);
1815 /* Extended Link TLVs */
1816 static void ospf_ext_link_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1818 struct lsa_header
*lsah
= lsa
->data
;
1819 struct tlv_header
*tlvh
;
1820 uint16_t length
= 0, sum
= 0;
1822 /* Initialize TLV browsing */
1823 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1825 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1826 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1827 switch (ntohs(tlvh
->type
)) {
1829 sum
+= show_vty_link_info(vty
, tlvh
);
1832 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1838 /* Prefix SID SubTLV */
1839 static uint16_t show_vty_ext_pref_pref_sid(struct vty
*vty
,
1840 struct tlv_header
*tlvh
)
1842 struct ext_subtlv_prefix_sid
*top
=
1843 (struct ext_subtlv_prefix_sid
*)tlvh
;
1846 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1847 ntohs(top
->header
.length
), top
->algorithm
, top
->flags
,
1849 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
) ? "Label"
1851 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
)
1852 ? GET_LABEL(ntohl(top
->value
))
1853 : ntohl(top
->value
));
1855 return TLV_SIZE(tlvh
);
1858 /* Extended Prefix SubTLVs */
1859 static uint16_t show_vty_pref_info(struct vty
*vty
, struct tlv_header
*ext
)
1861 struct ext_tlv_prefix
*top
= (struct ext_tlv_prefix
*)ext
;
1862 struct tlv_header
*tlvh
;
1863 uint16_t length
= ntohs(top
->header
.length
) - 2 * sizeof(uint32_t);
1867 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1868 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %pI4/%u\n",
1869 ntohs(top
->header
.length
), top
->route_type
, top
->af
, top
->flags
,
1870 &top
->address
, top
->pref_length
);
1872 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1873 + EXT_TLV_PREFIX_SIZE
);
1874 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1875 switch (ntohs(tlvh
->type
)) {
1876 case EXT_SUBTLV_PREFIX_SID
:
1877 sum
+= show_vty_ext_pref_pref_sid(vty
, tlvh
);
1880 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1885 return sum
+ sizeof(struct ext_tlv_prefix
);
1888 /* Extended Prefix TLVs */
1889 static void ospf_ext_pref_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1891 struct lsa_header
*lsah
= lsa
->data
;
1892 struct tlv_header
*tlvh
;
1893 uint16_t length
= 0, sum
= 0;
1895 /* Initialize TLV browsing */
1896 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1898 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1899 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1900 switch (ntohs(tlvh
->type
)) {
1901 case EXT_TLV_PREFIX
:
1902 sum
+= show_vty_pref_info(vty
, tlvh
);
1905 sum
+= show_vty_unknown_tlv(vty
, tlvh
);