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 /* Process only Active Extended Prefix/Link LSA */
466 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
469 osr_debug("EXT (%s): Disable %s%s%s-SID on interface %s", __func__
,
470 exti
->stype
== LOCAL_SID
? "Prefix" : "",
471 exti
->stype
== ADJ_SID
? "Adjacency" : "",
472 exti
->stype
== LAN_ADJ_SID
? "LAN-Adjacency" : "",
475 /* Flush LSA if already engaged */
476 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
477 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
478 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
481 /* De-activate this Extended Prefix/Link and remove corresponding
482 * Segment-Routing Prefix-SID or (LAN)-ADJ-SID */
483 if (exti
->stype
== ADJ_SID
|| exti
->stype
== LAN_ADJ_SID
)
484 ospf_ext_link_delete_adj_sid(exti
);
486 ospf_sr_ext_itf_delete(exti
);
490 * Update Extended prefix SID index for Loopback interface type
492 * @param ifname - Loopback interface name
493 * @param index - new value for the prefix SID of this interface
494 * @param p - prefix for this interface or NULL if Extended Prefix
497 * @return instance number if update is OK, 0 otherwise
499 uint32_t ospf_ext_schedule_prefix_index(struct interface
*ifp
, uint32_t index
,
500 struct prefix_ipv4
*p
, uint8_t flags
)
503 struct ext_itf
*exti
;
505 /* Find Extended Prefix interface */
506 exti
= lookup_ext_by_ifp(ifp
);
511 osr_debug("EXT (%s): Schedule new prefix %pFX with index %u on interface %s", __func__
, p
, index
, ifp
->name
);
513 /* Set first Extended Prefix then the Prefix SID information */
514 set_ext_prefix(exti
, OSPF_PATH_INTRA_AREA
, EXT_TLV_PREF_NFLG
,
516 set_prefix_sid(exti
, SR_ALGORITHM_SPF
, index
, SID_INDEX
, flags
);
518 /* Try to Schedule LSA */
519 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
520 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
521 ospf_ext_pref_lsa_schedule(exti
,
524 ospf_ext_pref_lsa_schedule(
525 exti
, REORIGINATE_THIS_LSA
);
528 osr_debug("EXT (%s): Remove prefix for interface %s", __func__
,
531 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
532 ospf_ext_pref_lsa_schedule(exti
, FLUSH_THIS_LSA
);
535 return SET_OPAQUE_LSID(exti
->type
, exti
->instance
);
539 * Update Adjacecny-SID for Extended Link LSA
541 * @param exti Extended Link information
543 static void ospf_ext_link_update_adj_sid(struct ext_itf
*exti
)
546 mpls_label_t bck_label
;
548 /* Process only (LAN)Adjacency-SID Type */
549 if (exti
->stype
!= ADJ_SID
&& exti
->stype
!= LAN_ADJ_SID
)
552 /* Request Primary & Backup Labels from Label Manager */
553 bck_label
= ospf_sr_local_block_request_label();
554 label
= ospf_sr_local_block_request_label();
555 if (bck_label
== MPLS_INVALID_LABEL
|| label
== MPLS_INVALID_LABEL
) {
556 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
557 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
561 /* Set Adjacency-SID, backup first */
562 if (exti
->stype
== ADJ_SID
) {
563 set_adj_sid(exti
, true, bck_label
, SID_LABEL
);
564 set_adj_sid(exti
, false, label
, SID_LABEL
);
566 set_lan_adj_sid(exti
, true, bck_label
, SID_LABEL
,
567 exti
->lan_sid
[0].neighbor_id
);
568 set_lan_adj_sid(exti
, false, label
, SID_LABEL
,
569 exti
->lan_sid
[1].neighbor_id
);
572 /* Finally, add corresponding SR Link in SRDB & MPLS LFIB */
573 SET_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
);
574 ospf_sr_ext_itf_add(exti
);
578 * Delete Adjacecny-SID for Extended Link LSA
580 * @param exti Extended Link information
582 static void ospf_ext_link_delete_adj_sid(struct ext_itf
*exti
)
584 /* Process only (LAN)Adjacency-SID Type */
585 if (exti
->stype
!= ADJ_SID
&& exti
->stype
!= LAN_ADJ_SID
)
588 /* Release Primary & Backup Labels from Label Manager */
589 if (exti
->stype
== ADJ_SID
) {
590 ospf_sr_local_block_release_label(exti
->adj_sid
[0].value
);
591 ospf_sr_local_block_release_label(exti
->adj_sid
[1].value
);
593 ospf_sr_local_block_release_label(exti
->lan_sid
[0].value
);
594 ospf_sr_local_block_release_label(exti
->lan_sid
[1].value
);
596 /* And reset corresponding TLV */
597 unset_adjacency_sid(exti
);
599 /* Finally, remove corresponding SR Link in SRDB & MPLS LFIB */
600 UNSET_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
);
601 ospf_sr_ext_itf_delete(exti
);
605 * Update Extended Link LSA once Segment Routing Label Block has been changed.
607 void ospf_ext_link_srlb_update(void)
609 struct listnode
*node
;
610 struct ext_itf
*exti
;
613 osr_debug("EXT (%s): Update Extended Links with new SRLB", __func__
);
615 /* Update all Extended Link Adjaceny-SID */
616 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
617 /* Skip Extended Prefix */
618 if (exti
->stype
== PREF_SID
|| exti
->stype
== LOCAL_SID
)
621 /* Skip inactive Extended Link */
622 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
625 ospf_ext_link_update_adj_sid(exti
);
630 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
632 * @param enable To activate or not Segment Routing Extended LSA flooding
636 void ospf_ext_update_sr(bool enable
)
638 struct listnode
*node
;
639 struct ext_itf
*exti
;
641 osr_debug("EXT (%s): %s Extended LSAs for Segment Routing ", __func__
,
642 enable
? "Enable" : "Disable");
645 OspfEXT
.enabled
= true;
647 /* Refresh LSAs if already engaged or originate */
648 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
649 /* Skip Inactive Extended Link */
650 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
653 /* Update Extended Link (LAN)Adj-SID if not set */
654 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
))
655 ospf_ext_link_update_adj_sid(exti
);
657 /* Finally, flood the extended Link */
658 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
659 ospf_ext_lsa_schedule(exti
, REFRESH_THIS_LSA
);
661 ospf_ext_lsa_schedule(exti
,
662 REORIGINATE_THIS_LSA
);
665 /* Start by Removing Extended LSA */
666 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
667 ospf_extended_lsa_delete(exti
);
669 /* And then disable Extended Link/Prefix */
670 OspfEXT
.enabled
= false;
675 * -----------------------------------------------------------------------
676 * Followings are callback functions against generic Opaque-LSAs handling
677 * -----------------------------------------------------------------------
680 /* Add new Interface in Extended Interface List */
681 static int ospf_ext_link_new_if(struct interface
*ifp
)
686 if (lookup_ext_by_ifp(ifp
) != NULL
) {
687 rc
= 0; /* Do nothing here. */
691 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS
, sizeof(struct ext_itf
));
693 /* initialize new information and link back the interface */
695 new->flags
= EXT_LPFLG_LSA_INACTIVE
;
697 listnode_add(OspfEXT
.iflist
, new);
703 /* Remove existing Interface from Extended Interface List */
704 static int ospf_ext_link_del_if(struct interface
*ifp
)
706 struct ext_itf
*exti
;
709 exti
= lookup_ext_by_ifp(ifp
);
711 /* Flush LSA and remove Adjacency SID */
712 ospf_extended_lsa_delete(exti
);
714 /* Dequeue listnode entry from the list. */
715 listnode_delete(OspfEXT
.iflist
, exti
);
717 XFREE(MTYPE_OSPF_EXT_PARAMS
, exti
);
721 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
722 "EXT (%s): interface %s is not found", __func__
,
723 ifp
? ifp
->name
: "-");
730 * Determine if an Interface belongs to an Extended Link Adjacency or
731 * Extended Prefix SID type and allocate new instance value accordingly
733 static void ospf_ext_ism_change(struct ospf_interface
*oi
, int old_status
)
735 struct ext_itf
*exti
;
737 /* Get interface information for Segment Routing */
738 exti
= lookup_ext_by_ifp(oi
->ifp
);
740 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
741 "EXT (%s): Cannot get Extended info. from OI(%s)",
742 __func__
, IF_NAME(oi
));
746 /* Reset Extended information if ospf interface goes Down */
747 if (oi
->state
== ISM_Down
) {
748 ospf_extended_lsa_delete(exti
);
750 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
754 /* Determine if interface is related to a Prefix or an Adjacency SID */
755 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
756 exti
->stype
= PREF_SID
;
757 exti
->type
= OPAQUE_TYPE_EXTENDED_PREFIX_LSA
;
758 exti
->flags
= EXT_LPFLG_LSA_ACTIVE
;
759 exti
->instance
= get_ext_pref_instance_value();
760 exti
->area
= oi
->area
;
762 osr_debug("EXT (%s): Set Prefix SID to interface %s ",
763 __func__
, oi
->ifp
->name
);
765 /* Complete SRDB if the interface belongs to a Prefix */
767 ospf_sr_update_local_prefix(oi
->ifp
, oi
->address
);
769 /* Determine if interface is related to Adj. or LAN Adj. SID */
770 if (oi
->state
== ISM_DR
)
771 exti
->stype
= LAN_ADJ_SID
;
773 exti
->stype
= ADJ_SID
;
775 exti
->type
= OPAQUE_TYPE_EXTENDED_LINK_LSA
;
776 exti
->instance
= get_ext_link_instance_value();
777 exti
->area
= oi
->area
;
780 * Note: Adjacency SID information are completed when ospf
781 * adjacency become up see ospf_ext_link_nsm_change()
783 osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
784 __func__
, exti
->stype
== ADJ_SID
? "" : "LAN-",
790 * Finish Extended Link configuration and flood corresponding LSA
791 * when OSPF adjacency on this link fire up
793 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
)
795 struct ospf_interface
*oi
= nbr
->oi
;
796 struct ext_itf
*exti
;
798 /* Process Link only when neighbor old or new state is NSM Full */
799 if (nbr
->state
!= NSM_Full
&& old_status
!= NSM_Full
)
802 /* Get interface information for Segment Routing */
803 exti
= lookup_ext_by_ifp(oi
->ifp
);
805 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
806 "EXT (%s): Cannot get Extended info. from OI(%s)",
807 __func__
, IF_NAME(oi
));
811 /* Check that we have a valid area and ospf context */
812 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
813 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
814 "EXT (%s): Cannot refer to OSPF from OI(%s)",
815 __func__
, IF_NAME(oi
));
819 /* Remove Extended Link if Neighbor State goes Down or Deleted */
820 if (nbr
->state
== NSM_Down
|| nbr
->state
== NSM_Deleted
) {
821 ospf_ext_link_delete_adj_sid(exti
);
822 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
823 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
824 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
828 /* Keep Area information in combination with SR info. */
829 exti
->area
= oi
->area
;
831 /* Process only Adjacency/LAN SID */
832 if (exti
->stype
== PREF_SID
)
836 case ISM_PointToPoint
:
837 /* Segment ID is an Adjacency one */
838 exti
->stype
= ADJ_SID
;
840 /* Set Extended Link TLV with link_id == Nbr Router ID */
841 set_ext_link(exti
, OSPF_IFTYPE_POINTOPOINT
, nbr
->router_id
,
842 oi
->address
->u
.prefix4
);
844 /* And Remote Interface address */
845 set_rmt_itf_addr(exti
, nbr
->address
.u
.prefix4
);
850 /* Segment ID is a LAN Adjacency for the DR only */
851 exti
->stype
= LAN_ADJ_SID
;
853 /* Set Extended Link TLV with link_id == DR */
854 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
855 oi
->address
->u
.prefix4
);
857 /* Set Neighbor ID */
858 exti
->lan_sid
[0].neighbor_id
= nbr
->router_id
;
859 exti
->lan_sid
[1].neighbor_id
= nbr
->router_id
;
865 /* Segment ID is an Adjacency if not the DR */
866 exti
->stype
= ADJ_SID
;
868 /* Set Extended Link TLV with link_id == DR */
869 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
870 oi
->address
->u
.prefix4
);
875 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_FIB_ENTRY_SET
))
876 ospf_ext_link_delete_adj_sid(exti
);
877 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
878 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
879 exti
->flags
= EXT_LPFLG_LSA_INACTIVE
;
883 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
885 if (OspfEXT
.enabled
) {
886 osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
887 __func__
, exti
->stype
== ADJ_SID
? "" : "LAN-",
890 /* Update (LAN)Adjacency SID */
891 ospf_ext_link_update_adj_sid(exti
);
893 /* flood this links params if everything is ok */
894 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
895 ospf_ext_link_lsa_schedule(exti
, REFRESH_THIS_LSA
);
897 ospf_ext_link_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
901 /* Callbacks to handle Extended Link Segment Routing LSA information */
902 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
)
906 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
911 /* Process only Opaque LSA */
912 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
913 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
916 /* Process only Extended Link LSA */
917 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
918 != OPAQUE_TYPE_EXTENDED_LINK_LSA
)
921 /* Check if it is not my LSA */
922 if (IS_LSA_SELF(lsa
))
925 /* Check if Extended is enable */
926 if (!OspfEXT
.enabled
)
929 /* Call Segment Routing LSA update or deletion */
930 if (!IS_LSA_MAXAGE(lsa
))
931 ospf_sr_ext_link_lsa_update(lsa
);
933 ospf_sr_ext_link_lsa_delete(lsa
);
938 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
939 static int ospf_ext_pref_lsa_update(struct ospf_lsa
*lsa
)
944 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
949 /* Process only Opaque LSA */
950 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
951 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
954 /* Process only Extended Prefix LSA */
955 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
956 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA
)
959 /* Check if it is not my LSA */
960 if (IS_LSA_SELF(lsa
))
963 /* Check if Extended is enable */
964 if (!OspfEXT
.enabled
)
967 /* Call Segment Routing LSA update or deletion */
968 if (!IS_LSA_MAXAGE(lsa
))
969 ospf_sr_ext_prefix_lsa_update(lsa
);
971 ospf_sr_ext_prefix_lsa_delete(lsa
);
977 * -------------------------------------------------------
978 * Followings are OSPF protocol processing functions for
979 * Extended Prefix/Link Opaque LSA
980 * -------------------------------------------------------
983 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
985 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
988 static void build_tlv(struct stream
*s
, struct tlv_header
*tlvh
)
991 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
992 build_tlv_header(s
, tlvh
);
993 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
997 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
998 static void ospf_ext_pref_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
1002 if ((exti
== NULL
) || (exti
->stype
!= PREF_SID
))
1005 /* Adjust Extended Prefix TLV size */
1006 TLV_LEN(exti
->prefix
) = htons(ntohs(TLV_LEN(exti
->node_sid
))
1007 + EXT_TLV_PREFIX_SIZE
+ TLV_HDR_SIZE
);
1009 /* Build LSA body for an Extended Prefix TLV */
1010 build_tlv_header(s
, &exti
->prefix
.header
);
1011 stream_put(s
, TLV_DATA(&exti
->prefix
.header
), EXT_TLV_PREFIX_SIZE
);
1012 /* Then add Prefix SID SubTLV */
1013 build_tlv(s
, &exti
->node_sid
.header
);
1016 /* Build an Extended Link Opaque LSA body for extended link TLV */
1017 static void ospf_ext_link_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
1023 || ((exti
->stype
!= ADJ_SID
) && (exti
->stype
!= LAN_ADJ_SID
)))
1026 if (exti
->stype
== ADJ_SID
) {
1027 /* Adjust Extended Link TLV size for Adj. SID */
1028 size
= EXT_TLV_LINK_SIZE
+ 2 * EXT_SUBTLV_ADJ_SID_SIZE
1030 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
1031 size
= size
+ EXT_SUBTLV_RMT_ITF_ADDR_SIZE
1033 TLV_LEN(exti
->link
) = htons(size
);
1035 /* Build LSA body for an Extended Link TLV with Adj. SID */
1036 build_tlv_header(s
, &exti
->link
.header
);
1037 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
1038 /* then add Adjacency SubTLVs */
1039 build_tlv(s
, &exti
->adj_sid
[1].header
);
1040 build_tlv(s
, &exti
->adj_sid
[0].header
);
1042 /* Add Cisco experimental SubTLV if interface is PtoP */
1043 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
1044 build_tlv(s
, &exti
->rmt_itf_addr
.header
);
1046 /* Adjust Extended Link TLV size for LAN SID */
1047 size
= EXT_TLV_LINK_SIZE
1048 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE
+ TLV_HDR_SIZE
);
1049 TLV_LEN(exti
->link
) = htons(size
);
1051 /* Build LSA body for an Extended Link TLV with LAN SID */
1052 build_tlv_header(s
, &exti
->link
.header
);
1053 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
1054 /* then add LAN-Adjacency SubTLVs */
1055 build_tlv(s
, &exti
->lan_sid
[1].header
);
1056 build_tlv(s
, &exti
->lan_sid
[0].header
);
1060 /* Create new Extended Prefix opaque-LSA for every extended prefix */
1061 static struct ospf_lsa
*ospf_ext_pref_lsa_new(struct ospf_area
*area
,
1062 struct ext_itf
*exti
)
1065 struct lsa_header
*lsah
;
1066 struct ospf_lsa
*new = NULL
;
1068 uint8_t options
, lsa_type
;
1069 struct in_addr lsa_id
;
1070 struct in_addr router_id
;
1078 /* Create a stream for LSA. */
1079 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1081 /* Prepare LSA Header */
1082 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1084 lsa_type
= OspfEXT
.scope
;
1087 * LSA ID is a variable number identifying different instances of
1088 * Extended Prefix Opaque LSA from the same router see RFC 7684
1090 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1091 lsa_id
.s_addr
= htonl(tmp
);
1093 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1095 /* Fix Options and Router ID depending of the flooding scope */
1096 if ((OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
) || (area
== NULL
)) {
1097 options
= OSPF_OPTION_E
;
1098 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1099 router_id
.s_addr
= top
? top
->router_id
.s_addr
: 0;
1101 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1102 options
|= LSA_OPTIONS_NSSA_GET(area
);
1103 router_id
= area
->ospf
->router_id
;
1106 /* Set opaque-LSA header fields. */
1107 lsa_header_set(s
, options
, lsa_type
, lsa_id
, router_id
);
1110 "EXT (%s): LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Prefix Opaque LSA instance",
1111 __func__
, lsa_type
, &lsa_id
);
1113 /* Set opaque-LSA body fields. */
1114 ospf_ext_pref_lsa_body_set(s
, exti
);
1117 length
= stream_get_endp(s
);
1118 lsah
->length
= htons(length
);
1120 /* Now, create an OSPF LSA instance. */
1121 new = ospf_lsa_new_and_data(length
);
1123 /* Segment Routing belongs only to default VRF */
1124 new->vrf_id
= VRF_DEFAULT
;
1126 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1127 memcpy(new->data
, lsah
, length
);
1133 /* Create new Extended Link opaque-LSA for every extended link TLV */
1134 static struct ospf_lsa
*ospf_ext_link_lsa_new(struct ospf_area
*area
,
1135 struct ext_itf
*exti
)
1138 struct lsa_header
*lsah
;
1139 struct ospf_lsa
*new = NULL
;
1140 uint8_t options
, lsa_type
;
1141 struct in_addr lsa_id
;
1149 /* Create a stream for LSA. */
1150 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1151 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1153 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1154 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1155 options
|= LSA_OPTIONS_NSSA_GET(area
);
1156 /* Extended Link Opaque LSA are only flooded within an area */
1157 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1160 * LSA ID is a variable number identifying different instances of
1161 * Extended Link Opaque LSA from the same router see RFC 7684
1163 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1164 lsa_id
.s_addr
= htonl(tmp
);
1167 "EXT (%s) LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Link Opaque LSA instance",
1168 __func__
, lsa_type
, &lsa_id
);
1170 /* Set opaque-LSA header fields. */
1171 lsa_header_set(s
, options
, lsa_type
, lsa_id
, area
->ospf
->router_id
);
1173 /* Set opaque-LSA body fields. */
1174 ospf_ext_link_lsa_body_set(s
, exti
);
1177 length
= stream_get_endp(s
);
1178 lsah
->length
= htons(length
);
1180 /* Now, create an OSPF LSA instance. */
1181 new = ospf_lsa_new_and_data(length
);
1183 /* Segment Routing belongs only to default VRF */
1184 new->vrf_id
= VRF_DEFAULT
;
1186 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1187 memcpy(new->data
, lsah
, length
);
1194 * Process the origination of an Extended Prefix Opaque LSA
1195 * for every extended prefix TLV
1197 static int ospf_ext_pref_lsa_originate1(struct ospf_area
*area
,
1198 struct ext_itf
*exti
)
1200 struct ospf_lsa
*new;
1204 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1205 new = ospf_ext_pref_lsa_new(area
, exti
);
1207 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1208 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1212 /* Install this LSA into LSDB. */
1213 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1214 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1215 "EXT (%s): ospf_lsa_install() error", __func__
);
1216 ospf_lsa_unlock(&new);
1220 /* Now this Extended Prefix Opaque LSA info parameter entry has
1223 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1225 /* Update new LSA origination count. */
1226 area
->ospf
->lsa_originate_count
++;
1228 /* Flood new LSA through area. */
1229 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1232 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSAExtended Prefix Opaque LSA: Area(%pI4), Link(%s)",
1233 __func__
, new->data
->type
, &new->data
->id
,
1234 &area
->area_id
, exti
->ifp
->name
);
1235 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1236 ospf_lsa_header_dump(new->data
);
1244 * Process the origination of an Extended Link Opaque LSA
1245 * for every extended link TLV
1247 static int ospf_ext_link_lsa_originate1(struct ospf_area
*area
,
1248 struct ext_itf
*exti
)
1250 struct ospf_lsa
*new;
1253 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1254 new = ospf_ext_link_lsa_new(area
, exti
);
1256 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1257 "EXT (%s): ospf_ext_link_lsa_new() error", __func__
);
1261 /* Install this LSA into LSDB. */
1262 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1263 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1264 "EXT (%s): ospf_lsa_install() error", __func__
);
1265 ospf_lsa_unlock(&new);
1269 /* Now this link-parameter entry has associated LSA. */
1270 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1272 /* Update new LSA origination count. */
1273 area
->ospf
->lsa_originate_count
++;
1275 /* Flood new LSA through area. */
1276 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1279 "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSA Extended Link Opaque LSA: Area(%pI4), Link(%s)",
1280 __func__
, new->data
->type
, &new->data
->id
,
1281 &area
->area_id
, exti
->ifp
->name
);
1282 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1283 ospf_lsa_header_dump(new->data
);
1290 /* Trigger the origination of Extended Prefix Opaque LSAs */
1291 static int ospf_ext_pref_lsa_originate(void *arg
)
1293 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1294 struct listnode
*node
;
1295 struct ext_itf
*exti
;
1298 if (!OspfEXT
.enabled
) {
1300 "EXT (%s): Segment Routing functionality is Disabled now",
1302 rc
= 0; /* This is not an error case. */
1305 osr_debug("EXT (%s): Start Originate Prefix LSA for area %pI4",
1306 __func__
, &area
->area_id
);
1308 /* Check if Extended Prefix Opaque LSA is already engaged */
1309 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1311 /* Process only Prefix SID */
1312 if (exti
->stype
!= PREF_SID
)
1315 /* Process only Extended Prefix with valid Area ID */
1316 if ((exti
->area
== NULL
)
1317 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1320 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1321 if (CHECK_FLAG(exti
->flags
,
1322 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1324 EC_OSPF_EXT_LSA_UNEXPECTED
,
1325 "EXT (%s): Refresh instead of Originate",
1327 UNSET_FLAG(exti
->flags
,
1328 EXT_LPFLG_LSA_FORCED_REFRESH
);
1329 ospf_ext_pref_lsa_schedule(exti
,
1335 /* Ok, let's try to originate an LSA */
1337 "EXT (%s): Let's finally re-originate the LSA 7.0.0.%u for Itf %s", __func__
, exti
->instance
,
1338 exti
->ifp
? exti
->ifp
->name
: "");
1339 ospf_ext_pref_lsa_originate1(area
, exti
);
1346 /* Trigger the origination of Extended Link Opaque LSAs */
1347 static int ospf_ext_link_lsa_originate(void *arg
)
1349 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1350 struct listnode
*node
;
1351 struct ext_itf
*exti
;
1354 if (!OspfEXT
.enabled
) {
1356 "EXT (%s): Segment Routing functionality is Disabled now",
1358 rc
= 0; /* This is not an error case. */
1362 /* Check if Extended Prefix Opaque LSA is already engaged */
1363 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1364 /* Process only Adjacency or LAN SID */
1365 if (exti
->stype
== PREF_SID
)
1368 /* Skip Inactive Extended Link */
1369 if (!CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
))
1372 /* Process only Extended Link with valid Area ID */
1373 if ((exti
->area
== NULL
)
1374 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1377 /* Check if LSA not already engaged */
1378 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1379 if (CHECK_FLAG(exti
->flags
,
1380 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1382 EC_OSPF_EXT_LSA_UNEXPECTED
,
1383 "EXT (%s): Refresh instead of Originate",
1385 UNSET_FLAG(exti
->flags
,
1386 EXT_LPFLG_LSA_FORCED_REFRESH
);
1387 ospf_ext_link_lsa_schedule(exti
,
1393 /* Ok, let's try to originate an LSA */
1395 "EXT (%s): Let's finally reoriginate the LSA 8.0.0.%u for Itf %s through the Area %pI4", __func__
,
1396 exti
->instance
, exti
->ifp
? exti
->ifp
->name
: "-",
1398 ospf_ext_link_lsa_originate1(area
, exti
);
1405 /* Refresh an Extended Prefix Opaque LSA */
1406 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
)
1408 struct ospf_lsa
*new = NULL
;
1409 struct ospf_area
*area
= lsa
->area
;
1411 struct ext_itf
*exti
;
1413 if (!OspfEXT
.enabled
) {
1415 * This LSA must have flushed before due to Extended Prefix
1416 * Opaque LSA status change.
1417 * It seems a slip among routers in the routing domain.
1420 "EXT (%s): Segment Routing functionality is Disabled",
1422 /* Flush it anyway. */
1423 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1426 /* Lookup this lsa corresponding Extended parameters */
1427 exti
= lookup_ext_by_instance(lsa
);
1429 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1430 "EXT (%s): Invalid parameter LSA ID", __func__
);
1431 /* Flush it anyway. */
1432 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1435 /* Check if Interface was not disable in the interval */
1436 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1437 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1438 "EXT (%s): Interface was Disabled: Flush it!",
1440 /* Flush it anyway. */
1441 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1444 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1445 if (IS_LSA_MAXAGE(lsa
)) {
1447 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1448 ospf_opaque_lsa_flush_schedule(lsa
);
1452 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1453 new = ospf_ext_pref_lsa_new(area
, exti
);
1456 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1457 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1460 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1463 * Install this LSA into LSDB
1464 * Given "lsa" will be freed in the next function
1465 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1466 * ospf_lookup() to get ospf instance
1471 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1473 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1474 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1475 "EXT (%s): ospf_lsa_install() error", __func__
);
1476 ospf_lsa_unlock(&new);
1480 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1481 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1483 /* Debug logging. */
1484 osr_debug("EXT (%s): LSA[Type%u:%pI4] Refresh Extended Prefix LSA",
1485 __func__
, new->data
->type
, &new->data
->id
);
1486 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1487 ospf_lsa_header_dump(new->data
);
1493 /* Refresh an Extended Link Opaque LSA */
1494 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
)
1496 struct ext_itf
*exti
;
1497 struct ospf_area
*area
= lsa
->area
;
1498 struct ospf
*top
= area
->ospf
;
1499 struct ospf_lsa
*new = NULL
;
1501 if (!OspfEXT
.enabled
) {
1503 * This LSA must have flushed before due to OSPF-SR status
1504 * change. It seems a slip among routers in the routing domain.
1506 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1508 /* Flush it anyway. */
1509 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1512 /* Lookup this LSA corresponding Extended parameters */
1513 exti
= lookup_ext_by_instance(lsa
);
1515 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1516 "EXT (%s): Invalid parameter LSA ID", __func__
);
1517 /* Flush it anyway. */
1518 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1521 /* Check if Interface was not disable in the interval */
1522 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1523 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1524 "EXT (%s): Interface was Disabled: Flush it!",
1526 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1529 /* If the lsa's age reached to MaxAge, start flushing procedure */
1530 if (IS_LSA_MAXAGE(lsa
)) {
1532 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1533 ospf_opaque_lsa_flush_schedule(lsa
);
1537 /* Create new Opaque-LSA/Extended Link instance */
1538 new = ospf_ext_link_lsa_new(area
, exti
);
1540 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1541 "EXT (%s): Error creating new LSA", __func__
);
1544 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1546 /* Install this LSA into LSDB. */
1547 /* Given "lsa" will be freed in the next function */
1548 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1549 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1550 "EXT (%s): Error installing new LSA", __func__
);
1551 ospf_lsa_unlock(&new);
1555 /* Flood updated LSA through the link Area according to the RFC7684 */
1556 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1558 /* Debug logging. */
1559 osr_debug("EXT (%s): LSA[Type%u:%pI4]: Refresh Extended Link LSA",
1560 __func__
, new->data
->type
, &new->data
->id
);
1561 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1562 ospf_lsa_header_dump(new->data
);
1567 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1568 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
1569 enum lsa_opcode opcode
)
1571 struct ospf_lsa lsa
;
1572 struct lsa_header lsah
;
1576 memset(&lsa
, 0, sizeof(lsa
));
1577 memset(&lsah
, 0, sizeof(lsah
));
1583 /* Check if the corresponding link is ready to be flooded */
1584 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1587 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1588 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1589 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1590 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1591 exti
->ifp
? exti
->ifp
->name
: "-");
1594 if (exti
->area
== NULL
) {
1596 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1599 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1600 struct in_addr backbone
= {.s_addr
= INADDR_ANY
};
1601 exti
->area
= ospf_area_lookup_by_area_id(top
, backbone
);
1602 if (exti
->area
== NULL
) {
1603 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1604 "EXT (%s): Unable to set Area", __func__
);
1608 /* Set LSA header information */
1609 lsa
.area
= exti
->area
;
1611 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1612 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1613 lsah
.id
.s_addr
= htonl(tmp
);
1616 case REORIGINATE_THIS_LSA
:
1617 ospf_opaque_lsa_reoriginate_schedule(
1618 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1619 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
1621 case REFRESH_THIS_LSA
:
1622 ospf_opaque_lsa_refresh_schedule(&lsa
);
1624 case FLUSH_THIS_LSA
:
1625 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1626 ospf_opaque_lsa_flush_schedule(&lsa
);
1631 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1632 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
1633 enum lsa_opcode opcode
)
1635 struct ospf_lsa lsa
;
1636 struct lsa_header lsah
;
1640 memset(&lsa
, 0, sizeof(lsa
));
1641 memset(&lsah
, 0, sizeof(lsah
));
1647 /* Check if the corresponding link is ready to be flooded */
1648 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1651 osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1652 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1653 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1654 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1655 exti
->ifp
? exti
->ifp
->name
: "-");
1658 if (exti
->area
== NULL
) {
1660 "EXT (%s): Area is not yet set. Try to use Backbone Area",
1663 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1664 struct in_addr backbone
= {.s_addr
= INADDR_ANY
};
1665 exti
->area
= ospf_area_lookup_by_area_id(top
, backbone
);
1666 if (exti
->area
== NULL
) {
1667 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1668 "EXT (%s): Unable to set Area", __func__
);
1672 /* Set LSA header information */
1673 lsa
.area
= exti
->area
;
1675 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1676 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1677 lsah
.id
.s_addr
= htonl(tmp
);
1680 case REORIGINATE_THIS_LSA
:
1681 ospf_opaque_lsa_reoriginate_schedule(
1682 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1683 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
1685 case REFRESH_THIS_LSA
:
1686 ospf_opaque_lsa_refresh_schedule(&lsa
);
1688 case FLUSH_THIS_LSA
:
1689 ospf_opaque_lsa_flush_schedule(&lsa
);
1694 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1695 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
)
1698 if (exti
->stype
== PREF_SID
)
1699 ospf_ext_pref_lsa_schedule(exti
, op
);
1701 ospf_ext_link_lsa_schedule(exti
, op
);
1705 * ------------------------------------
1706 * Followings are vty show functions.
1707 * ------------------------------------
1710 /* Cisco experimental SubTLV */
1711 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty
*vty
,
1712 struct tlv_header
*tlvh
)
1714 struct ext_subtlv_rmt_itf_addr
*top
;
1716 top
= (struct ext_subtlv_rmt_itf_addr
*)tlvh
;
1719 " Remote Interface Address Sub-TLV: Length %u\n Address: %s\n",
1720 ntohs(top
->header
.length
), inet_ntoa(top
->value
));
1722 return TLV_SIZE(tlvh
);
1725 /* Adjacency SID SubTLV */
1726 static uint16_t show_vty_ext_link_adj_sid(struct vty
*vty
,
1727 struct tlv_header
*tlvh
)
1729 struct ext_subtlv_adj_sid
*top
= (struct ext_subtlv_adj_sid
*)tlvh
;
1732 " Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1733 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1734 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1736 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1737 ? GET_LABEL(ntohl(top
->value
))
1738 : ntohl(top
->value
));
1740 return TLV_SIZE(tlvh
);
1743 /* LAN Adjacency SubTLV */
1744 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty
*vty
,
1745 struct tlv_header
*tlvh
)
1747 struct ext_subtlv_lan_adj_sid
*top
=
1748 (struct ext_subtlv_lan_adj_sid
*)tlvh
;
1751 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: %s\n\t%s: %u\n",
1752 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1753 inet_ntoa(top
->neighbor_id
),
1754 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1756 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1757 ? GET_LABEL(ntohl(top
->value
))
1758 : ntohl(top
->value
));
1760 return TLV_SIZE(tlvh
);
1763 static uint16_t show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
)
1765 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1766 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
1768 return TLV_SIZE(tlvh
);
1771 /* Extended Link Sub TLVs */
1772 static uint16_t show_vty_link_info(struct vty
*vty
, struct tlv_header
*ext
)
1774 struct ext_tlv_link
*top
= (struct ext_tlv_link
*)ext
;
1775 struct tlv_header
*tlvh
;
1776 uint16_t length
= ntohs(top
->header
.length
) - 3 * sizeof(uint32_t);
1780 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1782 ntohs(top
->header
.length
), top
->link_type
,
1783 inet_ntoa(top
->link_id
));
1784 vty_out(vty
, " Link data: %s\n", inet_ntoa(top
->link_data
));
1786 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1787 + EXT_TLV_LINK_SIZE
);
1788 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1789 switch (ntohs(tlvh
->type
)) {
1790 case EXT_SUBTLV_ADJ_SID
:
1791 sum
+= show_vty_ext_link_adj_sid(vty
, tlvh
);
1793 case EXT_SUBTLV_LAN_ADJ_SID
:
1794 sum
+= show_vty_ext_link_lan_adj_sid(vty
, tlvh
);
1796 case EXT_SUBTLV_RMT_ITF_ADDR
:
1797 sum
+= show_vty_ext_link_rmt_itf_addr(vty
, tlvh
);
1800 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1805 return sum
+ sizeof(struct ext_tlv_link
);
1808 /* Extended Link TLVs */
1809 static void ospf_ext_link_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1811 struct lsa_header
*lsah
= lsa
->data
;
1812 struct tlv_header
*tlvh
;
1813 uint16_t length
= 0, sum
= 0;
1815 /* Initialize TLV browsing */
1816 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1818 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1819 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1820 switch (ntohs(tlvh
->type
)) {
1822 sum
+= show_vty_link_info(vty
, tlvh
);
1825 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1831 /* Prefix SID SubTLV */
1832 static uint16_t show_vty_ext_pref_pref_sid(struct vty
*vty
,
1833 struct tlv_header
*tlvh
)
1835 struct ext_subtlv_prefix_sid
*top
=
1836 (struct ext_subtlv_prefix_sid
*)tlvh
;
1839 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1840 ntohs(top
->header
.length
), top
->algorithm
, top
->flags
,
1842 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
) ? "Label"
1844 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
)
1845 ? GET_LABEL(ntohl(top
->value
))
1846 : ntohl(top
->value
));
1848 return TLV_SIZE(tlvh
);
1851 /* Extended Prefix SubTLVs */
1852 static uint16_t show_vty_pref_info(struct vty
*vty
, struct tlv_header
*ext
)
1854 struct ext_tlv_prefix
*top
= (struct ext_tlv_prefix
*)ext
;
1855 struct tlv_header
*tlvh
;
1856 uint16_t length
= ntohs(top
->header
.length
) - 2 * sizeof(uint32_t);
1860 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1861 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%u\n",
1862 ntohs(top
->header
.length
), top
->route_type
, top
->af
, top
->flags
,
1863 inet_ntoa(top
->address
), top
->pref_length
);
1865 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1866 + EXT_TLV_PREFIX_SIZE
);
1867 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1868 switch (ntohs(tlvh
->type
)) {
1869 case EXT_SUBTLV_PREFIX_SID
:
1870 sum
+= show_vty_ext_pref_pref_sid(vty
, tlvh
);
1873 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1878 return sum
+ sizeof(struct ext_tlv_prefix
);
1881 /* Extended Prefix TLVs */
1882 static void ospf_ext_pref_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1884 struct lsa_header
*lsah
= lsa
->data
;
1885 struct tlv_header
*tlvh
;
1886 uint16_t length
= 0, sum
= 0;
1888 /* Initialize TLV browsing */
1889 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1891 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1892 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1893 switch (ntohs(tlvh
->type
)) {
1894 case EXT_TLV_PREFIX
:
1895 sum
+= show_vty_pref_info(vty
, tlvh
);
1898 sum
+= show_vty_unknown_tlv(vty
, tlvh
);