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_ism_change(struct ospf_interface
*oi
, int old_status
);
84 static void ospf_ext_pref_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
);
85 static int ospf_ext_pref_lsa_originate(void *arg
);
86 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
);
87 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
88 enum lsa_opcode opcode
);
89 /* Extended Link Opaque LSA related callback functions */
90 static int ospf_ext_link_new_if(struct interface
*ifp
);
91 static int ospf_ext_link_del_if(struct interface
*ifp
);
92 static void ospf_ext_link_ism_change(struct ospf_interface
*oi
, int old_status
);
93 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
);
94 static void ospf_ext_link_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
);
95 static int ospf_ext_link_lsa_originate(void *arg
);
96 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
);
97 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
98 enum lsa_opcode opcode
);
99 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
);
100 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
);
101 static int ospf_ext_pref_lsa_update(struct ospf_lsa
*lsa
);
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_link_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 ospf_ext_pref_ism_change
, /* 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)
203 // list_delete_all_node(OspfEXT.iflist);
204 OspfEXT
.enabled
= false;
208 * ---------------------------------------------------------------------
209 * Followings are control functions for Extended Prefix/Link Opaque LSA
210 * parameters management.
211 * ---------------------------------------------------------------------
214 /* Functions to free memory space */
215 static void del_ext_info(void *val
)
217 XFREE(MTYPE_OSPF_EXT_PARAMS
, val
);
220 /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
221 static uint32_t get_ext_pref_instance_value(void)
223 static uint32_t seqno
= 0;
225 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
228 seqno
= 1; /* Avoid zero. */
233 /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */
234 static uint32_t get_ext_link_instance_value(void)
236 static uint32_t seqno
= 0;
238 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
241 seqno
= 1; /* Avoid zero. */
246 /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
247 static struct ext_itf
*lookup_ext_by_ifp(struct interface
*ifp
)
249 struct listnode
*node
, *nnode
;
250 struct ext_itf
*exti
;
252 for (ALL_LIST_ELEMENTS(OspfEXT
.iflist
, node
, nnode
, exti
))
253 if (exti
->ifp
== ifp
)
259 /* Lookup Extended Prefix/Links by LSA ID from OspfEXT struct iflist */
260 static struct ext_itf
*lookup_ext_by_instance(struct ospf_lsa
*lsa
)
262 struct listnode
*node
;
263 struct ext_itf
*exti
;
264 uint32_t key
= GET_OPAQUE_ID(ntohl(lsa
->data
->id
.s_addr
));
265 uint8_t type
= GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
));
268 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
269 if ((exti
->instance
== key
) && (exti
->type
== type
))
276 * ----------------------------------------------------------------------
277 * The underlying subsection defines setters and unsetters to create and
278 * delete tlvs and subtlvs
279 * ----------------------------------------------------------------------
282 /* Extended Prefix TLV - RFC7684 section 2.1 */
283 static void set_ext_prefix(struct ext_itf
*exti
, uint8_t route_type
,
284 uint8_t flags
, struct prefix_ipv4 p
)
287 TLV_TYPE(exti
->prefix
) = htons(EXT_TLV_PREFIX
);
288 /* Warning: Size must be adjust depending of subTLV's */
289 TLV_LEN(exti
->prefix
) = htons(EXT_TLV_PREFIX_SIZE
);
290 exti
->prefix
.route_type
= route_type
;
291 exti
->prefix
.flags
= flags
;
292 /* Only Address Family Ipv4 (0) is defined in RFC 7684 */
294 exti
->prefix
.pref_length
= p
.prefixlen
;
295 exti
->prefix
.address
= p
.prefix
;
298 /* Extended Link TLV - RFC7684 section 3.1 */
299 static void set_ext_link(struct ext_itf
*exti
, uint8_t type
, struct in_addr id
,
303 TLV_TYPE(exti
->link
) = htons(EXT_TLV_LINK
);
304 /* Warning: Size must be adjust depending of subTLV's */
305 TLV_LEN(exti
->link
) = htons(EXT_TLV_LINK_SIZE
);
306 exti
->link
.link_type
= type
;
307 exti
->link
.link_id
= id
;
308 exti
->link
.link_data
= data
;
311 /* Prefix SID SubTLV - section 5 */
312 static void set_prefix_sid(struct ext_itf
*exti
, uint8_t algorithm
,
313 uint32_t value
, int value_type
, uint8_t flags
)
316 if ((algorithm
!= SR_ALGORITHM_SPF
)
317 && (algorithm
!= SR_ALGORITHM_STRICT_SPF
)) {
318 flog_err(EC_OSPF_INVALID_ALGORITHM
,
319 "EXT (%s): unrecognized algorithm, not SPF or S-SPF",
324 /* Update flags according to the type of value field: label or index */
325 if (value_type
== SID_LABEL
)
326 SET_FLAG(flags
, EXT_SUBTLV_PREFIX_SID_VFLG
);
328 /* set prefix sid subtlv for an extended prefix tlv */
329 TLV_TYPE(exti
->node_sid
) = htons(EXT_SUBTLV_PREFIX_SID
);
330 exti
->node_sid
.algorithm
= algorithm
;
331 exti
->node_sid
.flags
= flags
;
332 exti
->node_sid
.mtid
= 0; /* Multi-Topology is not supported */
334 /* Set Label or Index value */
335 if (value_type
== SID_LABEL
) {
336 TLV_LEN(exti
->node_sid
) =
337 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE
));
338 exti
->node_sid
.value
= htonl(SET_LABEL(value
));
340 TLV_LEN(exti
->node_sid
) =
341 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE
));
342 exti
->node_sid
.value
= htonl(value
);
346 /* Adjacency SID SubTLV - section 6.1 */
347 static void set_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
353 /* Determine which ADJ_SID must be set: nominal or backup */
355 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
363 TLV_TYPE(exti
->adj_sid
[index
]) = htons(EXT_SUBTLV_ADJ_SID
);
365 /* Only Local ADJ-SID is supported for the moment */
366 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
368 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
370 /* Adjust Length, Flags and Value depending on the type of Label */
371 if (value_type
== SID_LABEL
) {
372 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
373 TLV_LEN(exti
->adj_sid
[index
]) =
374 htons(SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE
));
375 exti
->adj_sid
[index
].value
= htonl(SET_LABEL(value
));
377 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
378 TLV_LEN(exti
->adj_sid
[index
]) =
379 htons(SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE
));
380 exti
->adj_sid
[index
].value
= htonl(value
);
383 exti
->adj_sid
[index
].flags
= flags
; /* Set computed flags */
384 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
385 exti
->adj_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
388 /* LAN Adjacency SID SubTLV - section 6.2 */
389 static void set_lan_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
390 int value_type
, struct in_addr neighbor_id
)
396 /* Determine which ADJ_SID must be set: nominal or backup */
398 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
406 TLV_TYPE(exti
->lan_sid
[index
]) = htons(EXT_SUBTLV_LAN_ADJ_SID
);
408 /* Only Local ADJ-SID is supported for the moment */
409 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
411 /* Adjust Length, Flags and Value depending on the type of Label */
412 if (value_type
== SID_LABEL
) {
413 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
414 TLV_LEN(exti
->lan_sid
[index
]) =
415 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE
));
416 exti
->lan_sid
[index
].value
= htonl(SET_LABEL(value
));
418 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
419 TLV_LEN(exti
->lan_sid
[index
]) =
420 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE
));
421 exti
->lan_sid
[index
].value
= htonl(value
);
424 exti
->lan_sid
[index
].flags
= flags
; /* Set computed flags */
425 exti
->lan_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
426 exti
->lan_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
427 exti
->lan_sid
[index
].neighbor_id
= neighbor_id
;
430 /* Experimental SubTLV from Cisco */
431 static void set_rmt_itf_addr(struct ext_itf
*exti
, struct in_addr rmtif
)
434 TLV_TYPE(exti
->rmt_itf_addr
) = htons(EXT_SUBTLV_RMT_ITF_ADDR
);
435 TLV_LEN(exti
->rmt_itf_addr
) = htons(sizeof(struct in_addr
));
436 exti
->rmt_itf_addr
.value
= rmtif
;
440 * Update Extended prefix SID index for Loopback interface type
442 * @param ifname - Loopback interface name
443 * @param index - new value for the prefix SID of this interface
444 * @param p - prefix for this interface or NULL if Extended Prefix
447 * @return instance number if update is OK, 0 otherwise
449 uint32_t ospf_ext_schedule_prefix_index(struct interface
*ifp
, uint32_t index
,
450 struct prefix_ipv4
*p
, uint8_t flags
)
453 struct ext_itf
*exti
;
455 /* Find Extended Prefix interface */
456 exti
= lookup_ext_by_ifp(ifp
);
461 if (IS_DEBUG_OSPF_SR
)
463 "EXT (%s): Schedule new prefix %s/%u with "
464 "index %u on interface %s",
465 __func__
, inet_ntoa(p
->prefix
), p
->prefixlen
,
468 /* Set first Extended Prefix then the Prefix SID information */
469 set_ext_prefix(exti
, OSPF_PATH_INTRA_AREA
, EXT_TLV_PREF_NFLG
,
471 set_prefix_sid(exti
, SR_ALGORITHM_SPF
, index
, SID_INDEX
, flags
);
473 /* Try to Schedule LSA */
474 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
475 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
476 ospf_ext_pref_lsa_schedule(exti
, REFRESH_THIS_LSA
);
478 ospf_ext_pref_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
480 if (IS_DEBUG_OSPF_SR
)
481 zlog_debug("EXT (%s): Remove prefix for interface %s",
482 __func__
, ifp
->name
);
484 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
485 ospf_ext_pref_lsa_schedule(exti
, FLUSH_THIS_LSA
);
486 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
487 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
491 return SET_OPAQUE_LSID(exti
->type
, exti
->instance
);
495 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
497 * @param enable To activate or not Segment Routing Extended LSA flooding
501 void ospf_ext_update_sr(bool enable
)
503 struct listnode
*node
;
504 struct ext_itf
*exti
;
506 if (IS_DEBUG_OSPF_SR
)
507 zlog_debug("EXT (%s): %s Extended LSAs for Segment Routing ",
508 __func__
, enable
? "Enable" : "Disable");
511 OspfEXT
.enabled
= true;
512 /* Refresh LSAs if already engaged or originate */
513 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
514 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
515 ospf_ext_lsa_schedule(exti
, REFRESH_THIS_LSA
);
517 ospf_ext_lsa_schedule(exti
,
518 REORIGINATE_THIS_LSA
);
520 /* Start by Flushing engaged LSAs */
521 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
522 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
523 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
524 /* And then disable Extended Link/Prefix */
525 OspfEXT
.enabled
= false;
529 * -----------------------------------------------------------------------
530 * Followings are callback functions against generic Opaque-LSAs handling
531 * -----------------------------------------------------------------------
534 /* Add new Interface in Extended Interface List */
535 static int ospf_ext_link_new_if(struct interface
*ifp
)
540 if (lookup_ext_by_ifp(ifp
) != NULL
) {
541 rc
= 0; /* Do nothing here. */
545 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS
, sizeof(struct ext_itf
));
547 /* initialize new information and link back the interface */
549 new->flags
= EXT_LPFLG_LSA_INACTIVE
;
551 listnode_add(OspfEXT
.iflist
, new);
557 /* Remove existing Interface from Extended Interface List */
558 static int ospf_ext_link_del_if(struct interface
*ifp
)
560 struct ext_itf
*exti
;
563 exti
= lookup_ext_by_ifp(ifp
);
565 struct list
*iflist
= OspfEXT
.iflist
;
567 /* Dequeue listnode entry from the list. */
568 listnode_delete(iflist
, exti
);
570 XFREE(MTYPE_OSPF_EXT_PARAMS
, exti
);
574 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
575 "EXT (%s): interface %s is not found", __func__
,
576 ifp
? ifp
->name
: "-");
583 * Determine if an Interface belongs to an Extended Link Adjacency or LAN Adj.
584 * type and allocate new instance value accordingly
586 static void ospf_ext_link_ism_change(struct ospf_interface
*oi
, int old_status
)
588 struct ext_itf
*exti
;
590 /* Get interface information for Segment Routing */
591 exti
= lookup_ext_by_ifp(oi
->ifp
);
595 /* Determine if interface is related to Adjacency or LAN Adj. SID */
596 if (oi
->type
!= OSPF_IFTYPE_LOOPBACK
) {
597 if (oi
->state
== ISM_DR
)
598 exti
->stype
= LAN_ADJ_SID
;
600 exti
->stype
= ADJ_SID
;
602 exti
->instance
= get_ext_link_instance_value();
603 exti
->type
= OPAQUE_TYPE_EXTENDED_LINK_LSA
;
605 zlog_debug("EXT (%s): Set %s SID to interface %s ", __func__
,
606 exti
->stype
== ADJ_SID
? "Adj." : "LAN Adj.",
612 * Determine if an Interface belongs to an Extended Prefix and
613 * allocate new instance value accordingly
615 static void ospf_ext_pref_ism_change(struct ospf_interface
*oi
, int old_status
)
617 struct ext_itf
*exti
;
619 /* Get interface information for Segment Routing */
620 exti
= lookup_ext_by_ifp(oi
->ifp
);
622 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
623 "EXT (%s): Cannot get Extended info. from OI(%s)",
624 __func__
, IF_NAME(oi
));
628 /* Determine if interface is related to a Node SID */
629 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
630 exti
->stype
= PREF_SID
;
631 exti
->instance
= get_ext_pref_instance_value();
632 exti
->type
= OPAQUE_TYPE_EXTENDED_PREFIX_LSA
;
634 zlog_debug("EXT (%s): Set Node SID to interface %s ", __func__
,
637 /* Complete SRDB if the interface belongs to a Prefix */
639 ospf_sr_update_prefix(oi
->ifp
, oi
->address
);
644 * Finish Extended Link configuration and flood corresponding LSA
645 * when OSPF adjacency on this link fire up
647 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
)
649 struct ospf_interface
*oi
= nbr
->oi
;
650 struct ext_itf
*exti
;
653 /* Process Neighbor only when its state is NSM Full */
654 if (nbr
->state
!= NSM_Full
)
657 /* Get interface information for Segment Routing */
658 exti
= lookup_ext_by_ifp(oi
->ifp
);
660 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
661 "EXT (%s): Cannot get Extended info. from OI(%s)",
662 __func__
, IF_NAME(oi
));
666 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
667 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
668 "EXT (%s): Cannot refer to OSPF from OI(%s)",
669 __func__
, IF_NAME(oi
));
673 /* Keep Area information in combination with SR info. */
674 exti
->area
= oi
->area
;
675 OspfEXT
.area
= oi
->area
;
677 /* Process only Adjacency/LAN SID */
678 if (exti
->stype
== PREF_SID
)
682 case ISM_PointToPoint
:
683 /* Segment ID is an Adjacency one */
684 exti
->stype
= ADJ_SID
;
686 /* Set Extended Link TLV with link_id == Nbr Router ID */
687 set_ext_link(exti
, OSPF_IFTYPE_POINTOPOINT
, nbr
->router_id
,
688 oi
->address
->u
.prefix4
);
690 /* Set Extended Link Adjacency SubTLVs, backup first */
691 label
= get_ext_link_label_value();
692 set_adj_sid(exti
, true, label
, SID_LABEL
);
693 label
= get_ext_link_label_value();
694 set_adj_sid(exti
, false, label
, SID_LABEL
);
695 /* And Remote Interface address */
696 set_rmt_itf_addr(exti
, nbr
->address
.u
.prefix4
);
701 /* Segment ID is a LAN Adjacency for the DR only */
702 exti
->stype
= LAN_ADJ_SID
;
704 /* Set Extended Link TLV with link_id == DR */
705 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
706 oi
->address
->u
.prefix4
);
708 /* Set Extended Link Adjacency SubTLVs, backup first */
709 label
= get_ext_link_label_value();
710 set_lan_adj_sid(exti
, true, label
, SID_LABEL
, nbr
->router_id
);
711 label
= get_ext_link_label_value();
712 set_lan_adj_sid(exti
, false, label
, SID_LABEL
, nbr
->router_id
);
718 /* Segment ID is an Adjacency if not the DR */
719 exti
->stype
= ADJ_SID
;
721 /* Set Extended Link TLV with link_id == DR */
722 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
723 oi
->address
->u
.prefix4
);
725 /* Set Extended Link Adjacency SubTLVs, backup first */
726 label
= get_ext_link_label_value();
727 set_adj_sid(exti
, true, label
, SID_LABEL
);
728 label
= get_ext_link_label_value();
729 set_adj_sid(exti
, false, label
, SID_LABEL
);
734 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
735 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
736 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
737 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
742 if (IS_DEBUG_OSPF_SR
)
743 zlog_debug("EXT (%s): Complete %s SID to interface %s ",
745 exti
->stype
== ADJ_SID
? "Adj." : "LAN Adj.",
748 /* flood this links params if everything is ok */
749 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
750 if (OspfEXT
.enabled
) {
751 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
752 ospf_ext_link_lsa_schedule(exti
, REFRESH_THIS_LSA
);
754 ospf_ext_link_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
758 /* Callbacks to handle Extended Link Segment Routing LSA information */
759 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
)
763 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
768 /* Process only Opaque LSA */
769 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
770 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
773 /* Process only Extended Link LSA */
774 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
775 != OPAQUE_TYPE_EXTENDED_LINK_LSA
)
778 /* Check if Extended is enable */
779 if (!OspfEXT
.enabled
)
782 /* Call Segment Routing LSA update or deletion */
783 if (!IS_LSA_MAXAGE(lsa
))
784 ospf_sr_ext_link_lsa_update(lsa
);
786 ospf_sr_ext_link_lsa_delete(lsa
);
791 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
792 static int ospf_ext_pref_lsa_update(struct ospf_lsa
*lsa
)
797 flog_warn(EC_OSPF_LSA_NULL
, "EXT (%s): Abort! LSA is NULL",
802 /* Process only Opaque LSA */
803 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
804 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
807 /* Process only Extended Prefix LSA */
808 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
809 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA
)
812 /* Check if it is not my LSA */
813 if (IS_LSA_SELF(lsa
))
816 /* Check if Extended is enable */
817 if (!OspfEXT
.enabled
)
820 /* Call Segment Routing LSA update or deletion */
821 if (!IS_LSA_MAXAGE(lsa
))
822 ospf_sr_ext_prefix_lsa_update(lsa
);
824 ospf_sr_ext_prefix_lsa_delete(lsa
);
830 * -------------------------------------------------------
831 * Followings are OSPF protocol processing functions for
832 * Extended Prefix/Link Opaque LSA
833 * -------------------------------------------------------
836 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
838 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
841 static void build_tlv(struct stream
*s
, struct tlv_header
*tlvh
)
844 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
845 build_tlv_header(s
, tlvh
);
846 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
850 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
851 static void ospf_ext_pref_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
855 if ((exti
== NULL
) || (exti
->stype
!= PREF_SID
))
858 /* Adjust Extended Prefix TLV size */
859 TLV_LEN(exti
->prefix
) = htons(ntohs(TLV_LEN(exti
->node_sid
))
860 + EXT_TLV_PREFIX_SIZE
+ TLV_HDR_SIZE
);
862 /* Build LSA body for an Extended Prefix TLV */
863 build_tlv_header(s
, &exti
->prefix
.header
);
864 stream_put(s
, TLV_DATA(&exti
->prefix
.header
), EXT_TLV_PREFIX_SIZE
);
865 /* Then add Prefix SID SubTLV */
866 build_tlv(s
, &exti
->node_sid
.header
);
869 /* Build an Extended Link Opaque LSA body for extended link TLV */
870 static void ospf_ext_link_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
876 || ((exti
->stype
!= ADJ_SID
) && (exti
->stype
!= LAN_ADJ_SID
)))
879 if (exti
->stype
== ADJ_SID
) {
880 /* Adjust Extended Link TLV size for Adj. SID */
881 size
= EXT_TLV_LINK_SIZE
+ 2 * EXT_SUBTLV_ADJ_SID_SIZE
883 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
884 size
= size
+ EXT_SUBTLV_RMT_ITF_ADDR_SIZE
886 TLV_LEN(exti
->link
) = htons(size
);
888 /* Build LSA body for an Extended Link TLV with Adj. SID */
889 build_tlv_header(s
, &exti
->link
.header
);
890 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
891 /* then add Adjacency SubTLVs */
892 build_tlv(s
, &exti
->adj_sid
[1].header
);
893 build_tlv(s
, &exti
->adj_sid
[0].header
);
895 /* Add Cisco experimental SubTLV if interface is PtoP */
896 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
897 build_tlv(s
, &exti
->rmt_itf_addr
.header
);
899 /* Adjust Extended Link TLV size for LAN SID */
900 size
= EXT_TLV_LINK_SIZE
901 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE
+ TLV_HDR_SIZE
);
902 TLV_LEN(exti
->link
) = htons(size
);
904 /* Build LSA body for an Extended Link TLV with LAN SID */
905 build_tlv_header(s
, &exti
->link
.header
);
906 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
907 /* then add LAN-Adjacency SubTLVs */
908 build_tlv(s
, &exti
->lan_sid
[1].header
);
909 build_tlv(s
, &exti
->lan_sid
[0].header
);
913 /* Create new Extended Prefix opaque-LSA for every extended prefix */
914 static struct ospf_lsa
*ospf_ext_pref_lsa_new(struct ospf_area
*area
,
915 struct ext_itf
*exti
)
918 struct lsa_header
*lsah
;
919 struct ospf_lsa
*new = NULL
;
921 uint8_t options
, lsa_type
;
922 struct in_addr lsa_id
;
923 struct in_addr router_id
;
931 /* Create a stream for LSA. */
932 s
= stream_new(OSPF_MAX_LSA_SIZE
);
934 /* Prepare LSA Header */
935 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
937 lsa_type
= OspfEXT
.scope
;
940 * LSA ID is a variable number identifying different instances of
941 * Extended Prefix Opaque LSA from the same router see RFC 7684
943 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
944 lsa_id
.s_addr
= htonl(tmp
);
946 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
948 /* Fix Options and Router ID depending of the flooding scope */
949 if ((OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
) || (area
== NULL
)) {
950 options
= OSPF_OPTION_E
;
951 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
952 router_id
.s_addr
= top
? top
->router_id
.s_addr
: 0;
954 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
955 options
|= LSA_OPTIONS_NSSA_GET(area
);
956 router_id
= area
->ospf
->router_id
;
959 /* Set opaque-LSA header fields. */
960 lsa_header_set(s
, options
, lsa_type
, lsa_id
, router_id
);
962 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
964 "EXT (%s): LSA[Type%u:%s]: Create an Opaque-LSA "
965 "Extended Prefix Opaque LSA instance",
966 __func__
, lsa_type
, inet_ntoa(lsa_id
));
969 /* Set opaque-LSA body fields. */
970 ospf_ext_pref_lsa_body_set(s
, exti
);
973 length
= stream_get_endp(s
);
974 lsah
->length
= htons(length
);
976 /* Now, create an OSPF LSA instance. */
977 new = ospf_lsa_new_and_data(length
);
979 /* Segment Routing belongs only to default VRF */
980 new->vrf_id
= VRF_DEFAULT
;
982 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
983 memcpy(new->data
, lsah
, length
);
989 /* Create new Extended Link opaque-LSA for every extended link TLV */
990 static struct ospf_lsa
*ospf_ext_link_lsa_new(struct ospf_area
*area
,
991 struct ext_itf
*exti
)
994 struct lsa_header
*lsah
;
995 struct ospf_lsa
*new = NULL
;
996 uint8_t options
, lsa_type
;
997 struct in_addr lsa_id
;
1005 /* Create a stream for LSA. */
1006 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1007 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1009 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1010 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1011 options
|= LSA_OPTIONS_NSSA_GET(area
);
1012 /* Extended Link Opaque LSA are only flooded within an area */
1013 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1016 * LSA ID is a variable number identifying different instances of
1017 * Extended Link Opaque LSA from the same router see RFC 7684
1019 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1020 lsa_id
.s_addr
= htonl(tmp
);
1022 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1024 "EXT (%s) LSA[Type%u:%s]: Create an Opaque-LSA "
1025 "Extended Link Opaque LSA instance",
1026 __func__
, lsa_type
, inet_ntoa(lsa_id
));
1028 /* Set opaque-LSA header fields. */
1029 lsa_header_set(s
, options
, lsa_type
, lsa_id
, area
->ospf
->router_id
);
1031 /* Set opaque-LSA body fields. */
1032 ospf_ext_link_lsa_body_set(s
, exti
);
1035 length
= stream_get_endp(s
);
1036 lsah
->length
= htons(length
);
1038 /* Now, create an OSPF LSA instance. */
1039 new = ospf_lsa_new_and_data(length
);
1041 /* Segment Routing belongs only to default VRF */
1042 new->vrf_id
= VRF_DEFAULT
;
1044 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1045 memcpy(new->data
, lsah
, length
);
1052 * Process the origination of an Extended Prefix Opaque LSA
1053 * for every extended prefix TLV
1055 static int ospf_ext_pref_lsa_originate1(struct ospf_area
*area
,
1056 struct ext_itf
*exti
)
1058 struct ospf_lsa
*new;
1062 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1063 new = ospf_ext_pref_lsa_new(area
, exti
);
1065 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1066 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1070 /* Install this LSA into LSDB. */
1071 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1072 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1073 "EXT (%s): ospf_lsa_install() error", __func__
);
1074 ospf_lsa_unlock(&new);
1078 /* Now this Extended Prefix Opaque LSA info parameter entry has
1081 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1083 /* Update new LSA origination count. */
1084 area
->ospf
->lsa_originate_count
++;
1086 /* Flood new LSA through area. */
1087 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1089 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1090 char area_id
[INET_ADDRSTRLEN
];
1092 inet_ntop(AF_INET
, &area
->area_id
, area_id
, sizeof(area_id
));
1094 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1095 "Extended Prefix Opaque LSA: Area(%s), Link(%s)",
1096 __func__
, new->data
->type
, inet_ntoa(new->data
->id
),
1097 area_id
, exti
->ifp
->name
);
1098 ospf_lsa_header_dump(new->data
);
1107 * Process the origination of an Extended Link Opaque LSA
1108 * for every extended link TLV
1110 static int ospf_ext_link_lsa_originate1(struct ospf_area
*area
,
1111 struct ext_itf
*exti
)
1113 struct ospf_lsa
*new;
1116 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1117 new = ospf_ext_link_lsa_new(area
, exti
);
1119 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1120 "EXT (%s): ospf_ext_link_lsa_new() error", __func__
);
1124 /* Install this LSA into LSDB. */
1125 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1126 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1127 "EXT (%s): ospf_lsa_install() error", __func__
);
1128 ospf_lsa_unlock(&new);
1132 /* Now this link-parameter entry has associated LSA. */
1133 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1135 /* Update new LSA origination count. */
1136 area
->ospf
->lsa_originate_count
++;
1138 /* Flood new LSA through area. */
1139 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1141 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1142 char area_id
[INET_ADDRSTRLEN
];
1144 inet_ntop(AF_INET
, &area
->area_id
, area_id
, sizeof(area_id
));
1146 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1147 "Extended Link Opaque LSA: Area(%s), Link(%s)",
1148 __func__
, new->data
->type
, inet_ntoa(new->data
->id
),
1149 area_id
, exti
->ifp
->name
);
1150 ospf_lsa_header_dump(new->data
);
1158 /* Trigger the origination of Extended Prefix Opaque LSAs */
1159 static int ospf_ext_pref_lsa_originate(void *arg
)
1161 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1162 struct listnode
*node
;
1163 struct ext_itf
*exti
;
1166 if (!OspfEXT
.enabled
) {
1168 "EXT (%s): Segment Routing "
1169 "functionality is Disabled now",
1171 rc
= 0; /* This is not an error case. */
1174 if (IS_DEBUG_OSPF_SR
)
1175 zlog_debug("EXT (%s): Start Originate Prefix LSA for area %s",
1176 __func__
, inet_ntoa(area
->area_id
));
1178 /* Check if Extended Prefix Opaque LSA is already engaged */
1179 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1181 /* Process only Prefix SID */
1182 if (exti
->stype
!= PREF_SID
)
1185 /* Process only Extended Prefix with valid Area ID */
1186 if ((exti
->area
== NULL
)
1187 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1190 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1191 if (CHECK_FLAG(exti
->flags
,
1192 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1194 EC_OSPF_EXT_LSA_UNEXPECTED
,
1195 "EXT (%s): Refresh instead of Originate",
1197 UNSET_FLAG(exti
->flags
,
1198 EXT_LPFLG_LSA_FORCED_REFRESH
);
1199 ospf_ext_pref_lsa_schedule(exti
,
1205 /* Ok, let's try to originate an LSA */
1206 if (IS_DEBUG_OSPF_SR
)
1208 "EXT (%s): Let's finally reoriginate the "
1209 "LSA 7.0.0.%u for Itf %s",
1210 __func__
, exti
->instance
,
1211 exti
->ifp
? exti
->ifp
->name
: "");
1212 ospf_ext_pref_lsa_originate1(area
, exti
);
1219 /* Trigger the origination of Extended Link Opaque LSAs */
1220 static int ospf_ext_link_lsa_originate(void *arg
)
1222 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1223 struct listnode
*node
;
1224 struct ext_itf
*exti
;
1227 if (!OspfEXT
.enabled
) {
1229 "EXT (%s): Segment Routing "
1230 "functionality is Disabled now",
1232 rc
= 0; /* This is not an error case. */
1236 /* Check if Extended Prefix Opaque LSA is already engaged */
1237 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1238 /* Process only Adjacency or LAN SID */
1239 if (exti
->stype
== PREF_SID
)
1242 /* Process only Extended Link with valid Area ID */
1243 if ((exti
->area
== NULL
)
1244 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1247 /* Check if LSA not already engaged */
1248 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1249 if (CHECK_FLAG(exti
->flags
,
1250 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1252 EC_OSPF_EXT_LSA_UNEXPECTED
,
1253 "EXT (%s): Refresh instead of Originate",
1255 UNSET_FLAG(exti
->flags
,
1256 EXT_LPFLG_LSA_FORCED_REFRESH
);
1257 ospf_ext_link_lsa_schedule(exti
,
1263 /* Ok, let's try to originate an LSA */
1264 if (IS_DEBUG_OSPF_SR
)
1266 "EXT (%s): Let's finally reoriginate the "
1267 "LSA 8.0.0.%u for Itf %s through the Area %s",
1268 __func__
, exti
->instance
,
1269 exti
->ifp
? exti
->ifp
->name
: "-",
1270 inet_ntoa(area
->area_id
));
1271 ospf_ext_link_lsa_originate1(area
, exti
);
1278 /* Refresh an Extended Prefix Opaque LSA */
1279 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
)
1281 struct ospf_lsa
*new = NULL
;
1282 struct ospf_area
*area
= lsa
->area
;
1284 struct ext_itf
*exti
;
1286 if (!OspfEXT
.enabled
) {
1288 * This LSA must have flushed before due to Extended Prefix
1289 * Opaque LSA status change.
1290 * It seems a slip among routers in the routing domain.
1293 "EXT (%s): Segment Routing functionality is "
1296 /* Flush it anyway. */
1297 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1300 /* Lookup this lsa corresponding Extended parameters */
1301 exti
= lookup_ext_by_instance(lsa
);
1303 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1304 "EXT (%s): Invalid parameter LSA ID", __func__
);
1305 /* Flush it anyway. */
1306 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1309 /* Check if Interface was not disable in the interval */
1310 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1311 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1312 "EXT (%s): Interface was Disabled: Flush it!",
1314 /* Flush it anyway. */
1315 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1318 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1319 if (IS_LSA_MAXAGE(lsa
)) {
1321 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1322 ospf_opaque_lsa_flush_schedule(lsa
);
1326 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1327 new = ospf_ext_pref_lsa_new(area
, exti
);
1330 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1331 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1334 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1337 * Install this LSA into LSDB
1338 * Given "lsa" will be freed in the next function
1339 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1340 * ospf_lookup() to get ospf instance
1345 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1347 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1348 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1349 "EXT (%s): ospf_lsa_install() error", __func__
);
1350 ospf_lsa_unlock(&new);
1354 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1355 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1357 /* Debug logging. */
1358 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1360 "EXT (%s): LSA[Type%u:%s] Refresh Extended Prefix LSA",
1361 __func__
, new->data
->type
, inet_ntoa(new->data
->id
));
1362 ospf_lsa_header_dump(new->data
);
1368 /* Refresh an Extended Link Opaque LSA */
1369 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
)
1371 struct ext_itf
*exti
;
1372 struct ospf_area
*area
= lsa
->area
;
1373 struct ospf
*top
= area
->ospf
;
1374 struct ospf_lsa
*new = NULL
;
1376 if (!OspfEXT
.enabled
) {
1378 * This LSA must have flushed before due to OSPF-SR status
1379 * change. It seems a slip among routers in the routing domain.
1381 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1383 /* Flush it anyway. */
1384 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1387 /* Lookup this LSA corresponding Extended parameters */
1388 exti
= lookup_ext_by_instance(lsa
);
1390 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1391 "EXT (%s): Invalid parameter LSA ID", __func__
);
1392 /* Flush it anyway. */
1393 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1396 /* Check if Interface was not disable in the interval */
1397 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1398 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1399 "EXT (%s): Interface was Disabled: Flush it!",
1401 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1404 /* If the lsa's age reached to MaxAge, start flushing procedure */
1405 if (IS_LSA_MAXAGE(lsa
)) {
1407 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1408 ospf_opaque_lsa_flush_schedule(lsa
);
1412 /* Create new Opaque-LSA/Extended Link instance */
1413 new = ospf_ext_link_lsa_new(area
, exti
);
1415 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED
,
1416 "EXT (%s): Error creating new LSA", __func__
);
1419 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1421 /* Install this LSA into LSDB. */
1422 /* Given "lsa" will be freed in the next function */
1423 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1424 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1425 "EXT (%s): Error installing new LSA", __func__
);
1426 ospf_lsa_unlock(&new);
1430 /* Flood updated LSA through the link Area according to the RFC7684 */
1431 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1433 /* Debug logging. */
1434 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1436 "EXT (%s): LSA[Type%u:%s]: Refresh Extended Link LSA",
1437 __func__
, new->data
->type
, inet_ntoa(new->data
->id
));
1438 ospf_lsa_header_dump(new->data
);
1444 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1445 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
1446 enum lsa_opcode opcode
)
1448 struct ospf_lsa lsa
;
1449 struct lsa_header lsah
;
1453 memset(&lsa
, 0, sizeof(lsa
));
1454 memset(&lsah
, 0, sizeof(lsah
));
1460 /* Check if the corresponding link is ready to be flooded */
1461 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1464 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1465 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1466 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1467 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1468 exti
->ifp
? exti
->ifp
->name
: "-");
1470 /* Set LSA header information */
1471 if (exti
->area
== NULL
) {
1473 EC_OSPF_EXT_LSA_UNEXPECTED
,
1474 "EXT (%s): Flooding is Area scope but area is not yet set",
1476 if (OspfEXT
.area
== NULL
) {
1477 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1478 OspfEXT
.area
= ospf_area_lookup_by_area_id(
1479 top
, OspfEXT
.area_id
);
1481 exti
->area
= OspfEXT
.area
;
1483 lsa
.area
= exti
->area
;
1485 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1486 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1487 lsah
.id
.s_addr
= htonl(tmp
);
1490 case REORIGINATE_THIS_LSA
:
1491 ospf_opaque_lsa_reoriginate_schedule(
1492 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1493 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
1495 case REFRESH_THIS_LSA
:
1496 ospf_opaque_lsa_refresh_schedule(&lsa
);
1498 case FLUSH_THIS_LSA
:
1499 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1500 ospf_opaque_lsa_flush_schedule(&lsa
);
1505 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1506 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
1507 enum lsa_opcode opcode
)
1509 struct ospf_lsa lsa
;
1510 struct lsa_header lsah
;
1514 memset(&lsa
, 0, sizeof(lsa
));
1515 memset(&lsah
, 0, sizeof(lsah
));
1521 /* Check if the corresponding link is ready to be flooded */
1522 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1525 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1526 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1527 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1528 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1529 exti
->ifp
? exti
->ifp
->name
: "-");
1531 /* Set LSA header information */
1532 if (exti
->area
== NULL
) {
1534 EC_OSPF_EXT_LSA_UNEXPECTED
,
1535 "EXT (%s): Flooding is Area scope but area is not yet set",
1537 if (OspfEXT
.area
== NULL
) {
1538 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1539 OspfEXT
.area
= ospf_area_lookup_by_area_id(
1540 top
, OspfEXT
.area_id
);
1542 exti
->area
= OspfEXT
.area
;
1544 lsa
.area
= exti
->area
;
1546 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1547 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1548 lsah
.id
.s_addr
= htonl(tmp
);
1551 case REORIGINATE_THIS_LSA
:
1552 ospf_opaque_lsa_reoriginate_schedule(
1553 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1554 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
1556 case REFRESH_THIS_LSA
:
1557 ospf_opaque_lsa_refresh_schedule(&lsa
);
1559 case FLUSH_THIS_LSA
:
1560 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1561 ospf_opaque_lsa_flush_schedule(&lsa
);
1566 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1567 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
)
1570 if (exti
->stype
== PREF_SID
)
1571 ospf_ext_pref_lsa_schedule(exti
, op
);
1573 ospf_ext_link_lsa_schedule(exti
, op
);
1577 * ------------------------------------
1578 * Followings are vty show functions.
1579 * ------------------------------------
1582 /* Cisco experimental SubTLV */
1583 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty
*vty
,
1584 struct tlv_header
*tlvh
)
1586 struct ext_subtlv_rmt_itf_addr
*top
;
1588 top
= (struct ext_subtlv_rmt_itf_addr
*)tlvh
;
1591 " Remote Interface Address Sub-TLV: Length %u\n "
1593 ntohs(top
->header
.length
), inet_ntoa(top
->value
));
1595 return TLV_SIZE(tlvh
);
1598 /* Adjacency SID SubTLV */
1599 static uint16_t show_vty_ext_link_adj_sid(struct vty
*vty
,
1600 struct tlv_header
*tlvh
)
1602 struct ext_subtlv_adj_sid
*top
= (struct ext_subtlv_adj_sid
*)tlvh
;
1605 " Adj-SID Sub-TLV: Length %u\n\tFlags: "
1606 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1607 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1608 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1610 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1611 ? GET_LABEL(ntohl(top
->value
))
1612 : ntohl(top
->value
));
1614 return TLV_SIZE(tlvh
);
1617 /* LAN Adjacency SubTLV */
1618 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty
*vty
,
1619 struct tlv_header
*tlvh
)
1621 struct ext_subtlv_lan_adj_sid
*top
=
1622 (struct ext_subtlv_lan_adj_sid
*)tlvh
;
1625 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: "
1626 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: "
1628 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1629 inet_ntoa(top
->neighbor_id
),
1630 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1632 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1633 ? GET_LABEL(ntohl(top
->value
))
1634 : ntohl(top
->value
));
1636 return TLV_SIZE(tlvh
);
1639 static uint16_t show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
)
1641 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1642 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
1644 return TLV_SIZE(tlvh
);
1647 /* Extended Link Sub TLVs */
1648 static uint16_t show_vty_link_info(struct vty
*vty
, struct tlv_header
*ext
)
1650 struct ext_tlv_link
*top
= (struct ext_tlv_link
*)ext
;
1651 struct tlv_header
*tlvh
;
1652 uint16_t length
= ntohs(top
->header
.length
) - 3 * sizeof(uint32_t);
1656 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1658 ntohs(top
->header
.length
), top
->link_type
,
1659 inet_ntoa(top
->link_id
));
1660 vty_out(vty
, " Link data: %s\n", inet_ntoa(top
->link_data
));
1662 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1663 + EXT_TLV_LINK_SIZE
);
1664 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1665 switch (ntohs(tlvh
->type
)) {
1666 case EXT_SUBTLV_ADJ_SID
:
1667 sum
+= show_vty_ext_link_adj_sid(vty
, tlvh
);
1669 case EXT_SUBTLV_LAN_ADJ_SID
:
1670 sum
+= show_vty_ext_link_lan_adj_sid(vty
, tlvh
);
1672 case EXT_SUBTLV_RMT_ITF_ADDR
:
1673 sum
+= show_vty_ext_link_rmt_itf_addr(vty
, tlvh
);
1676 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1681 return sum
+ sizeof(struct ext_tlv_link
);
1684 /* Extended Link TLVs */
1685 static void ospf_ext_link_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1687 struct lsa_header
*lsah
= lsa
->data
;
1688 struct tlv_header
*tlvh
;
1689 uint16_t length
= 0, sum
= 0;
1691 /* Initialize TLV browsing */
1692 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1694 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1695 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1696 switch (ntohs(tlvh
->type
)) {
1698 sum
+= show_vty_link_info(vty
, tlvh
);
1701 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1707 /* Prefix SID SubTLV */
1708 static uint16_t show_vty_ext_pref_pref_sid(struct vty
*vty
,
1709 struct tlv_header
*tlvh
)
1711 struct ext_subtlv_prefix_sid
*top
=
1712 (struct ext_subtlv_prefix_sid
*)tlvh
;
1715 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: "
1716 "%u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1717 ntohs(top
->header
.length
), top
->algorithm
, top
->flags
,
1719 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
) ? "Label"
1721 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
)
1722 ? GET_LABEL(ntohl(top
->value
))
1723 : ntohl(top
->value
));
1725 return TLV_SIZE(tlvh
);
1728 /* Extended Prefix SubTLVs */
1729 static uint16_t show_vty_pref_info(struct vty
*vty
, struct tlv_header
*ext
)
1731 struct ext_tlv_prefix
*top
= (struct ext_tlv_prefix
*)ext
;
1732 struct tlv_header
*tlvh
;
1733 uint16_t length
= ntohs(top
->header
.length
) - 2 * sizeof(uint32_t);
1737 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1738 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%u\n",
1739 ntohs(top
->header
.length
), top
->route_type
, top
->af
, top
->flags
,
1740 inet_ntoa(top
->address
), top
->pref_length
);
1742 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1743 + EXT_TLV_PREFIX_SIZE
);
1744 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1745 switch (ntohs(tlvh
->type
)) {
1746 case EXT_SUBTLV_PREFIX_SID
:
1747 sum
+= show_vty_ext_pref_pref_sid(vty
, tlvh
);
1750 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1755 return sum
+ sizeof(struct ext_tlv_prefix
);
1758 /* Extended Prefix TLVs */
1759 static void ospf_ext_pref_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1761 struct lsa_header
*lsah
= lsa
->data
;
1762 struct tlv_header
*tlvh
;
1763 uint16_t length
= 0, sum
= 0;
1765 /* Initialize TLV browsing */
1766 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1768 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1769 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1770 switch (ntohs(tlvh
->type
)) {
1771 case EXT_TLV_PREFIX
:
1772 sum
+= show_vty_pref_info(vty
, tlvh
);
1775 sum
+= show_vty_unknown_tlv(vty
, tlvh
);