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"
66 /* Following structure are internal use only. */
69 * Global variable to manage Extended Prefix/Link Opaque LSA on this node.
70 * Note that all parameter values are stored in network byte order.
72 static struct ospf_ext_lp OspfEXT
;
75 * -----------------------------------------------------------------------
76 * Followings are initialize/terminate functions for Extended Prefix/Link
77 * Opaque LSA handling.
78 * -----------------------------------------------------------------------
81 /* Extended Prefix Opaque LSA related callback functions */
82 static void ospf_ext_pref_ism_change(struct ospf_interface
*oi
, int old_status
);
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_link_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 del_ext_info(void *val
);
104 * Extended Link/Prefix initialization
108 * @return - 0 if OK, <> 0 otherwise
110 int ospf_ext_init(void)
114 memset(&OspfEXT
, 0, sizeof(struct ospf_ext_lp
));
115 OspfEXT
.enabled
= false;
116 /* Only Area flooding is supported yet */
117 OspfEXT
.scope
= OSPF_OPAQUE_AREA_LSA
;
118 /* Initialize interface list */
119 OspfEXT
.iflist
= list_new();
120 OspfEXT
.iflist
->del
= del_ext_info
;
122 zlog_info("EXT (%s): Register Extended Link Opaque LSA", __func__
);
123 rc
= ospf_register_opaque_functab(
124 OSPF_OPAQUE_AREA_LSA
, OPAQUE_TYPE_EXTENDED_LINK_LSA
,
125 ospf_ext_link_new_if
, /* new if */
126 ospf_ext_link_del_if
, /* del if */
127 ospf_ext_link_ism_change
, /* ism change */
128 ospf_ext_link_nsm_change
, /* nsm change */
129 NULL
, /* Write router config. */
130 NULL
, /* Write interface conf. */
131 NULL
, /* Write debug config. */
132 ospf_ext_link_show_info
, /* Show LSA info */
133 ospf_ext_link_lsa_originate
, /* Originate LSA */
134 ospf_ext_link_lsa_refresh
, /* Refresh LSA */
135 ospf_ext_link_lsa_update
, /* new_lsa_hook */
136 NULL
); /* del_lsa_hook */
139 zlog_warn("EXT (%s): Failed to register Extended Link LSA",
144 zlog_info("EXT (%s): Register Extended Prefix Opaque LSA", __func__
);
145 rc
= ospf_register_opaque_functab(
146 OspfEXT
.scope
, OPAQUE_TYPE_EXTENDED_PREFIX_LSA
,
147 NULL
, /* new if handle by link */
148 NULL
, /* del if handle by link */
149 ospf_ext_pref_ism_change
, /* ism change */
150 NULL
, /* nsm change */
151 ospf_sr_config_write_router
, /* Write router config. */
152 NULL
, /* Write interface conf. */
153 NULL
, /* Write debug config. */
154 ospf_ext_pref_show_info
, /* Show LSA info */
155 ospf_ext_pref_lsa_originate
, /* Originate LSA */
156 ospf_ext_pref_lsa_refresh
, /* Refresh LSA */
157 ospf_ext_pref_lsa_update
, /* new_lsa_hook */
158 NULL
); /* del_lsa_hook */
160 zlog_warn("EXT (%s): Failed to register Extended Prefix LSA",
169 * Extended Link/Prefix termination function
174 void ospf_ext_term(void)
177 if ((OspfEXT
.scope
!= OSPF_OPAQUE_AREA_LSA
)
178 && (OspfEXT
.scope
!= OSPF_OPAQUE_AS_LSA
))
180 "EXT: Unable to unregister Extended Prefix "
181 "Opaque LSA functions: Wrong scope!");
183 ospf_delete_opaque_functab(OspfEXT
.scope
,
184 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
186 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA
,
187 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
189 list_delete_and_null(&OspfEXT
.iflist
);
191 OspfEXT
.enabled
= false;
197 * Extended Link/Prefix finish function
202 void ospf_ext_finish(void)
204 // list_delete_all_node(OspfEXT.iflist);
205 OspfEXT
.enabled
= false;
209 * ---------------------------------------------------------------------
210 * Followings are control functions for Extended Prefix/Link Opaque LSA
211 * parameters management.
212 * ---------------------------------------------------------------------
215 /* Functions to free memory space */
216 static void del_ext_info(void *val
)
218 XFREE(MTYPE_OSPF_EXT_PARAMS
, val
);
221 /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
222 static uint32_t get_ext_pref_instance_value(void)
224 static uint32_t seqno
= 0;
226 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
229 seqno
= 1; /* Avoid zero. */
234 /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */
235 static uint32_t get_ext_link_instance_value(void)
237 static uint32_t seqno
= 0;
239 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
242 seqno
= 1; /* Avoid zero. */
247 /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
248 static struct ext_itf
*lookup_ext_by_ifp(struct interface
*ifp
)
250 struct listnode
*node
, *nnode
;
251 struct ext_itf
*exti
;
253 for (ALL_LIST_ELEMENTS(OspfEXT
.iflist
, node
, nnode
, exti
))
254 if (exti
->ifp
== ifp
)
260 /* Lookup Extended Prefix/Links by LSA ID from OspfEXT struct iflist */
261 static struct ext_itf
*lookup_ext_by_instance(struct ospf_lsa
*lsa
)
263 struct listnode
*node
;
264 struct ext_itf
*exti
;
265 uint32_t key
= GET_OPAQUE_ID(ntohl(lsa
->data
->id
.s_addr
));
266 uint8_t type
= GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
));
269 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
270 if ((exti
->instance
== key
) && (exti
->type
== type
))
277 * ----------------------------------------------------------------------
278 * The underlying subsection defines setters and unsetters to create and
279 * delete tlvs and subtlvs
280 * ----------------------------------------------------------------------
283 /* Extended Prefix TLV - RFC7684 section 2.1 */
284 static void set_ext_prefix(struct ext_itf
*exti
, uint8_t route_type
,
285 uint8_t flags
, struct prefix_ipv4 p
)
288 TLV_TYPE(exti
->prefix
) = htons(EXT_TLV_PREFIX
);
289 /* Warning: Size must be adjust depending of subTLV's */
290 TLV_LEN(exti
->prefix
) = htons(EXT_TLV_PREFIX_SIZE
);
291 exti
->prefix
.route_type
= route_type
;
292 exti
->prefix
.flags
= flags
;
293 /* Only Address Family Ipv4 (0) is defined in RFC 7684 */
295 exti
->prefix
.pref_length
= p
.prefixlen
;
296 exti
->prefix
.address
= p
.prefix
;
299 /* Extended Link TLV - RFC7684 section 3.1 */
300 static void set_ext_link(struct ext_itf
*exti
, uint8_t type
, struct in_addr id
,
304 TLV_TYPE(exti
->link
) = htons(EXT_TLV_LINK
);
305 /* Warning: Size must be adjust depending of subTLV's */
306 TLV_LEN(exti
->link
) = htons(EXT_TLV_LINK_SIZE
);
307 exti
->link
.link_type
= type
;
308 exti
->link
.link_id
= id
;
309 exti
->link
.link_data
= data
;
312 /* Prefix SID SubTLV - section 5 */
313 static void set_prefix_sid(struct ext_itf
*exti
, uint8_t algorithm
,
314 uint32_t value
, int value_type
, uint8_t flags
)
317 if ((algorithm
!= SR_ALGORITHM_SPF
)
318 && (algorithm
!= SR_ALGORITHM_STRICT_SPF
)) {
319 zlog_warn("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 zlog_warn("EXT (%s): interface %s is already in use", __func__
,
542 ifp
? ifp
->name
: "-");
543 rc
= 0; /* Do nothing here. */
547 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS
, sizeof(struct ext_itf
));
549 /* initialize new information and link back the interface */
551 new->flags
= EXT_LPFLG_LSA_INACTIVE
;
553 listnode_add(OspfEXT
.iflist
, new);
559 /* Remove existing Interface from Extended Interface List */
560 static int ospf_ext_link_del_if(struct interface
*ifp
)
562 struct ext_itf
*exti
;
565 exti
= lookup_ext_by_ifp(ifp
);
567 struct list
*iflist
= OspfEXT
.iflist
;
569 /* Dequeue listnode entry from the list. */
570 listnode_delete(iflist
, exti
);
572 XFREE(MTYPE_OSPF_EXT_PARAMS
, exti
);
576 zlog_warn("EXT (%s): interface %s is not found", __func__
,
577 ifp
? ifp
->name
: "-");
584 * Determine if an Interface belongs to an Extended Link Adjacency or LAN Adj.
585 * type and allocate new instance value accordingly
587 static void ospf_ext_link_ism_change(struct ospf_interface
*oi
, int old_status
)
589 struct ext_itf
*exti
;
591 /* Get interface information for Segment Routing */
592 exti
= lookup_ext_by_ifp(oi
->ifp
);
594 zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
595 __func__
, IF_NAME(oi
));
599 /* Determine if interface is related to Adjacency or LAN Adj. SID */
600 if (oi
->type
!= OSPF_IFTYPE_LOOPBACK
) {
601 if (oi
->state
== ISM_DR
)
602 exti
->stype
= LAN_ADJ_SID
;
604 exti
->stype
= ADJ_SID
;
606 exti
->instance
= get_ext_link_instance_value();
607 exti
->type
= OPAQUE_TYPE_EXTENDED_LINK_LSA
;
609 zlog_debug("EXT (%s): Set %s SID to interface %s ", __func__
,
610 exti
->stype
== ADJ_SID
? "Adj." : "LAN Adj.",
616 * Determine if an Interface belongs to an Extended Prefix and
617 * allocate new instance value accordingly
619 static void ospf_ext_pref_ism_change(struct ospf_interface
*oi
, int old_status
)
621 struct ext_itf
*exti
;
623 /* Get interface information for Segment Routing */
624 exti
= lookup_ext_by_ifp(oi
->ifp
);
626 zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
627 __func__
, IF_NAME(oi
));
631 /* Determine if interface is related to a Node SID */
632 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
633 exti
->stype
= PREF_SID
;
634 exti
->instance
= get_ext_pref_instance_value();
635 exti
->type
= OPAQUE_TYPE_EXTENDED_PREFIX_LSA
;
637 zlog_debug("EXT (%s): Set Node SID to interface %s ", __func__
,
640 /* Complete SRDB if the interface belongs to a Prefix */
642 ospf_sr_update_prefix(oi
->ifp
, oi
->address
);
647 * Finish Extended Link configuration and flood corresponding LSA
648 * when OSPF adjacency on this link fire up
650 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
)
652 struct ospf_interface
*oi
= nbr
->oi
;
653 struct ext_itf
*exti
;
656 /* Process Neighbor only when its state is NSM Full */
657 if (nbr
->state
!= NSM_Full
)
660 /* Get interface information for Segment Routing */
661 exti
= lookup_ext_by_ifp(oi
->ifp
);
663 zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
664 __func__
, IF_NAME(oi
));
668 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
669 zlog_warn("EXT (%s): Cannot refer to OSPF from OI(%s)",
670 __func__
, IF_NAME(oi
));
674 /* Keep Area information in combination with SR info. */
675 exti
->area
= oi
->area
;
676 OspfEXT
.area
= oi
->area
;
678 /* Process only Adjacency/LAN SID */
679 if (exti
->stype
== PREF_SID
)
683 case ISM_PointToPoint
:
684 /* Segment ID is an Adjacency one */
685 exti
->stype
= ADJ_SID
;
687 /* Set Extended Link TLV with link_id == Nbr Router ID */
688 set_ext_link(exti
, OSPF_IFTYPE_POINTOPOINT
, nbr
->router_id
,
689 oi
->address
->u
.prefix4
);
691 /* Set Extended Link Adjacency SubTLVs, backup first */
692 label
= get_ext_link_label_value();
693 set_adj_sid(exti
, true, label
, SID_LABEL
);
694 label
= get_ext_link_label_value();
695 set_adj_sid(exti
, false, label
, SID_LABEL
);
696 /* And Remote Interface address */
697 set_rmt_itf_addr(exti
, nbr
->address
.u
.prefix4
);
702 /* Segment ID is a LAN Adjacency for the DR only */
703 exti
->stype
= LAN_ADJ_SID
;
705 /* Set Extended Link TLV with link_id == DR */
706 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
707 oi
->address
->u
.prefix4
);
709 /* Set Extended Link Adjacency SubTLVs, backup first */
710 label
= get_ext_link_label_value();
711 set_lan_adj_sid(exti
, true, label
, SID_LABEL
, nbr
->router_id
);
712 label
= get_ext_link_label_value();
713 set_lan_adj_sid(exti
, false, label
, SID_LABEL
, nbr
->router_id
);
719 /* Segment ID is an Adjacency if not the DR */
720 exti
->stype
= ADJ_SID
;
722 /* Set Extended Link TLV with link_id == DR */
723 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
724 oi
->address
->u
.prefix4
);
726 /* Set Extended Link Adjacency SubTLVs, backup first */
727 label
= get_ext_link_label_value();
728 set_adj_sid(exti
, true, label
, SID_LABEL
);
729 label
= get_ext_link_label_value();
730 set_adj_sid(exti
, false, label
, SID_LABEL
);
735 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
736 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
737 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
738 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
743 if (IS_DEBUG_OSPF_SR
)
744 zlog_debug("EXT (%s): Complete %s SID to interface %s ",
746 exti
->stype
== ADJ_SID
? "Adj." : "LAN Adj.",
749 /* flood this links params if everything is ok */
750 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
751 if (OspfEXT
.enabled
) {
752 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
753 ospf_ext_link_lsa_schedule(exti
, REFRESH_THIS_LSA
);
755 ospf_ext_link_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
759 /* Callbacks to handle Extended Link Segment Routing LSA information */
760 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
)
764 zlog_warn("EXT (%s): Abort! LSA is NULL", __func__
);
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 zlog_warn("EXT (%s): Abort! LSA is NULL", __func__
);
801 /* Process only Opaque LSA */
802 if ((lsa
->data
->type
!= OSPF_OPAQUE_AREA_LSA
)
803 && (lsa
->data
->type
!= OSPF_OPAQUE_AS_LSA
))
806 /* Process only Extended Prefix LSA */
807 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
808 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA
)
811 /* Check if it is not my LSA */
812 if (IS_LSA_SELF(lsa
))
815 /* Check if Extended is enable */
816 if (!OspfEXT
.enabled
)
819 /* Call Segment Routing LSA update or deletion */
820 if (!IS_LSA_MAXAGE(lsa
))
821 ospf_sr_ext_prefix_lsa_update(lsa
);
823 ospf_sr_ext_prefix_lsa_delete(lsa
);
829 * -------------------------------------------------------
830 * Followings are OSPF protocol processing functions for
831 * Extended Prefix/Link Opaque LSA
832 * -------------------------------------------------------
835 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
837 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
840 static void build_tlv(struct stream
*s
, struct tlv_header
*tlvh
)
843 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
844 build_tlv_header(s
, tlvh
);
845 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
849 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
850 static void ospf_ext_pref_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
854 if ((exti
== NULL
) || (exti
->stype
!= PREF_SID
))
857 /* Adjust Extended Prefix TLV size */
858 TLV_LEN(exti
->prefix
) = htons(ntohs(TLV_LEN(exti
->node_sid
))
859 + EXT_TLV_PREFIX_SIZE
+ TLV_HDR_SIZE
);
861 /* Build LSA body for an Extended Prefix TLV */
862 build_tlv_header(s
, &exti
->prefix
.header
);
863 stream_put(s
, TLV_DATA(&exti
->prefix
.header
), EXT_TLV_PREFIX_SIZE
);
864 /* Then add Prefix SID SubTLV */
865 build_tlv(s
, &exti
->node_sid
.header
);
868 /* Build an Extended Link Opaque LSA body for extended link TLV */
869 static void ospf_ext_link_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
875 || ((exti
->stype
!= ADJ_SID
) && (exti
->stype
!= LAN_ADJ_SID
)))
878 if (exti
->stype
== ADJ_SID
) {
879 /* Adjust Extended Link TLV size for Adj. SID */
880 size
= EXT_TLV_LINK_SIZE
+ 2 * EXT_SUBTLV_ADJ_SID_SIZE
882 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
883 size
= size
+ EXT_SUBTLV_RMT_ITF_ADDR_SIZE
885 TLV_LEN(exti
->link
) = htons(size
);
887 /* Build LSA body for an Extended Link TLV with Adj. SID */
888 build_tlv_header(s
, &exti
->link
.header
);
889 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
890 /* then add Adjacency SubTLVs */
891 build_tlv(s
, &exti
->adj_sid
[1].header
);
892 build_tlv(s
, &exti
->adj_sid
[0].header
);
894 /* Add Cisco experimental SubTLV if interface is PtoP */
895 if (ntohs(TLV_TYPE(exti
->rmt_itf_addr
)) != 0)
896 build_tlv(s
, &exti
->rmt_itf_addr
.header
);
898 /* Adjust Extended Link TLV size for LAN SID */
899 size
= EXT_TLV_LINK_SIZE
900 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE
+ TLV_HDR_SIZE
);
901 TLV_LEN(exti
->link
) = htons(size
);
903 /* Build LSA body for an Extended Link TLV with LAN SID */
904 build_tlv_header(s
, &exti
->link
.header
);
905 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
906 /* then add LAN-Adjacency SubTLVs */
907 build_tlv(s
, &exti
->lan_sid
[1].header
);
908 build_tlv(s
, &exti
->lan_sid
[0].header
);
912 /* Create new Extended Prefix opaque-LSA for every extended prefix */
913 static struct ospf_lsa
*ospf_ext_pref_lsa_new(struct ospf_area
*area
,
914 struct ext_itf
*exti
)
917 struct lsa_header
*lsah
;
918 struct ospf_lsa
*new = NULL
;
920 uint8_t options
, lsa_type
;
921 struct in_addr lsa_id
;
922 struct in_addr router_id
;
930 /* Create a stream for LSA. */
931 s
= stream_new(OSPF_MAX_LSA_SIZE
);
933 zlog_warn("EXT (%s): stream_new() error", __func__
);
937 /* Prepare LSA Header */
938 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
940 lsa_type
= OspfEXT
.scope
;
943 * LSA ID is a variable number identifying different instances of
944 * Extended Prefix Opaque LSA from the same router see RFC 7684
946 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
947 lsa_id
.s_addr
= htonl(tmp
);
949 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
951 /* Fix Options and Router ID depending of the flooding scope */
952 if ((OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
) || (area
== NULL
)) {
953 options
= OSPF_OPTION_E
;
954 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
955 router_id
.s_addr
= top
? top
->router_id
.s_addr
: 0;
957 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
958 options
|= LSA_OPTIONS_NSSA_GET(area
);
959 router_id
= area
->ospf
->router_id
;
962 /* Set opaque-LSA header fields. */
963 lsa_header_set(s
, options
, lsa_type
, lsa_id
, router_id
);
965 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
967 "EXT (%s): LSA[Type%u:%s]: Create an Opaque-LSA "
968 "Extended Prefix Opaque LSA instance",
969 __func__
, lsa_type
, inet_ntoa(lsa_id
));
972 /* Set opaque-LSA body fields. */
973 ospf_ext_pref_lsa_body_set(s
, exti
);
976 length
= stream_get_endp(s
);
977 lsah
->length
= htons(length
);
979 /* Now, create an OSPF LSA instance. */
980 new = ospf_lsa_new_and_data(length
);
982 /* Segment Routing belongs only to default VRF */
983 new->vrf_id
= VRF_DEFAULT
;
985 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
986 memcpy(new->data
, lsah
, length
);
992 /* Create new Extended Link opaque-LSA for every extended link TLV */
993 static struct ospf_lsa
*ospf_ext_link_lsa_new(struct ospf_area
*area
,
994 struct ext_itf
*exti
)
997 struct lsa_header
*lsah
;
998 struct ospf_lsa
*new = NULL
;
999 uint8_t options
, lsa_type
;
1000 struct in_addr lsa_id
;
1008 /* Create a stream for LSA. */
1009 s
= stream_new(OSPF_MAX_LSA_SIZE
);
1011 zlog_warn("EXT (%s): stream_new() error", __func__
);
1014 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1016 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1017 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1018 options
|= LSA_OPTIONS_NSSA_GET(area
);
1019 /* Extended Link Opaque LSA are only flooded within an area */
1020 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1023 * LSA ID is a variable number identifying different instances of
1024 * Extended Link Opaque LSA from the same router see RFC 7684
1026 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1027 lsa_id
.s_addr
= htonl(tmp
);
1029 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1031 "EXT (%s) LSA[Type%u:%s]: Create an Opaque-LSA "
1032 "Extended Link Opaque LSA instance",
1033 __func__
, lsa_type
, inet_ntoa(lsa_id
));
1035 /* Set opaque-LSA header fields. */
1036 lsa_header_set(s
, options
, lsa_type
, lsa_id
, area
->ospf
->router_id
);
1038 /* Set opaque-LSA body fields. */
1039 ospf_ext_link_lsa_body_set(s
, exti
);
1042 length
= stream_get_endp(s
);
1043 lsah
->length
= htons(length
);
1045 /* Now, create an OSPF LSA instance. */
1046 new = ospf_lsa_new_and_data(length
);
1048 /* Segment Routing belongs only to default VRF */
1049 new->vrf_id
= VRF_DEFAULT
;
1051 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1052 memcpy(new->data
, lsah
, length
);
1059 * Process the origination of an Extended Prefix Opaque LSA
1060 * for every extended prefix TLV
1062 static int ospf_ext_pref_lsa_originate1(struct ospf_area
*area
,
1063 struct ext_itf
*exti
)
1065 struct ospf_lsa
*new;
1069 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1070 new = ospf_ext_pref_lsa_new(area
, exti
);
1072 zlog_warn("EXT (%s): ospf_ext_pref_lsa_new() error", __func__
);
1076 /* Install this LSA into LSDB. */
1077 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1078 zlog_warn("EXT (%s): ospf_lsa_install() error", __func__
);
1079 ospf_lsa_unlock(&new);
1083 /* Now this Extended Prefix Opaque LSA info parameter entry has
1086 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1088 /* Update new LSA origination count. */
1089 area
->ospf
->lsa_originate_count
++;
1091 /* Flood new LSA through area. */
1092 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1094 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1095 char area_id
[INET_ADDRSTRLEN
];
1097 inet_ntop(AF_INET
, &area
->area_id
, area_id
, sizeof(area_id
));
1099 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1100 "Extended Prefix Opaque LSA: Area(%s), Link(%s)",
1101 __func__
, new->data
->type
, inet_ntoa(new->data
->id
),
1102 area_id
, exti
->ifp
->name
);
1103 ospf_lsa_header_dump(new->data
);
1112 * Process the origination of an Extended Link Opaque LSA
1113 * for every extended link TLV
1115 static int ospf_ext_link_lsa_originate1(struct ospf_area
*area
,
1116 struct ext_itf
*exti
)
1118 struct ospf_lsa
*new;
1121 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1122 new = ospf_ext_link_lsa_new(area
, exti
);
1124 zlog_warn("EXT (%s): ospf_ext_link_lsa_new() error", __func__
);
1128 /* Install this LSA into LSDB. */
1129 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1130 zlog_warn("EXT (%s): ospf_lsa_install() error", __func__
);
1131 ospf_lsa_unlock(&new);
1135 /* Now this link-parameter entry has associated LSA. */
1136 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1138 /* Update new LSA origination count. */
1139 area
->ospf
->lsa_originate_count
++;
1141 /* Flood new LSA through area. */
1142 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1144 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1145 char area_id
[INET_ADDRSTRLEN
];
1147 inet_ntop(AF_INET
, &area
->area_id
, area_id
, sizeof(area_id
));
1149 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1150 "Extended Link Opaque LSA: Area(%s), Link(%s)",
1151 __func__
, new->data
->type
, inet_ntoa(new->data
->id
),
1152 area_id
, exti
->ifp
->name
);
1153 ospf_lsa_header_dump(new->data
);
1161 /* Trigger the origination of Extended Prefix Opaque LSAs */
1162 static int ospf_ext_pref_lsa_originate(void *arg
)
1164 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1165 struct listnode
*node
;
1166 struct ext_itf
*exti
;
1169 if (!OspfEXT
.enabled
) {
1171 "EXT (%s): Segment Routing "
1172 "functionality is Disabled now",
1174 rc
= 0; /* This is not an error case. */
1177 if (IS_DEBUG_OSPF_SR
)
1178 zlog_debug("EXT (%s): Start Originate Prefix LSA for area %s",
1179 __func__
, inet_ntoa(area
->area_id
));
1181 /* Check if Extended Prefix Opaque LSA is already engaged */
1182 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1184 /* Process only Prefix SID */
1185 if (exti
->stype
!= PREF_SID
)
1188 /* Process only Extended Prefix with valid Area ID */
1189 if ((exti
->area
== NULL
)
1190 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1193 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1194 if (CHECK_FLAG(exti
->flags
,
1195 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1197 "EXT (%s): Refresh instead of "
1200 UNSET_FLAG(exti
->flags
,
1201 EXT_LPFLG_LSA_FORCED_REFRESH
);
1202 ospf_ext_pref_lsa_schedule(exti
,
1208 /* Ok, let's try to originate an LSA */
1209 if (IS_DEBUG_OSPF_SR
)
1211 "EXT (%s): Let's finally reoriginate the "
1212 "LSA 7.0.0.%u for Itf %s",
1213 __func__
, exti
->instance
,
1214 exti
->ifp
? exti
->ifp
->name
: "");
1215 ospf_ext_pref_lsa_originate1(area
, exti
);
1222 /* Trigger the origination of Extended Link Opaque LSAs */
1223 static int ospf_ext_link_lsa_originate(void *arg
)
1225 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1226 struct listnode
*node
;
1227 struct ext_itf
*exti
;
1230 if (!OspfEXT
.enabled
) {
1232 "EXT (%s): Segment Routing "
1233 "functionality is Disabled now",
1235 rc
= 0; /* This is not an error case. */
1239 /* Check if Extended Prefix Opaque LSA is already engaged */
1240 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1241 /* Process only Adjacency or LAN SID */
1242 if (exti
->stype
== PREF_SID
)
1245 /* Process only Extended Link with valid Area ID */
1246 if ((exti
->area
== NULL
)
1247 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1250 /* Check if LSA not already engaged */
1251 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1252 if (CHECK_FLAG(exti
->flags
,
1253 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1255 "EXT (%s): Refresh instead of "
1258 UNSET_FLAG(exti
->flags
,
1259 EXT_LPFLG_LSA_FORCED_REFRESH
);
1260 ospf_ext_link_lsa_schedule(exti
,
1266 /* Ok, let's try to originate an LSA */
1267 if (IS_DEBUG_OSPF_SR
)
1269 "EXT (%s): Let's finally reoriginate the "
1270 "LSA 8.0.0.%u for Itf %s through the Area %s",
1271 __func__
, exti
->instance
,
1272 exti
->ifp
? exti
->ifp
->name
: "-",
1273 inet_ntoa(area
->area_id
));
1274 ospf_ext_link_lsa_originate1(area
, exti
);
1281 /* Refresh an Extended Prefix Opaque LSA */
1282 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
)
1284 struct ospf_lsa
*new = NULL
;
1285 struct ospf_area
*area
= lsa
->area
;
1287 struct ext_itf
*exti
;
1289 if (!OspfEXT
.enabled
) {
1291 * This LSA must have flushed before due to Extended Prefix
1292 * Opaque LSA status change.
1293 * It seems a slip among routers in the routing domain.
1296 "EXT (%s): Segment Routing functionality is "
1299 /* Flush it anyway. */
1300 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1303 /* Lookup this lsa corresponding Extended parameters */
1304 exti
= lookup_ext_by_instance(lsa
);
1306 zlog_warn("EXT (%s): Invalid parameter LSA ID", __func__
);
1307 /* Flush it anyway. */
1308 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1311 /* Check if Interface was not disable in the interval */
1312 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1313 zlog_warn("EXT (%s): Interface was Disabled: Flush it!",
1315 /* Flush it anyway. */
1316 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1319 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1320 if (IS_LSA_MAXAGE(lsa
)) {
1322 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1323 ospf_opaque_lsa_flush_schedule(lsa
);
1327 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1328 new = ospf_ext_pref_lsa_new(area
, exti
);
1331 zlog_warn("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 zlog_warn("EXT (%s): ospf_lsa_install() error", __func__
);
1349 ospf_lsa_unlock(&new);
1353 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1354 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1356 /* Debug logging. */
1357 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1359 "EXT (%s): LSA[Type%u:%s] Refresh Extended Prefix LSA",
1360 __func__
, new->data
->type
, inet_ntoa(new->data
->id
));
1361 ospf_lsa_header_dump(new->data
);
1367 /* Refresh an Extended Link Opaque LSA */
1368 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
)
1370 struct ext_itf
*exti
;
1371 struct ospf_area
*area
= lsa
->area
;
1372 struct ospf
*top
= area
->ospf
;
1373 struct ospf_lsa
*new = NULL
;
1375 if (!OspfEXT
.enabled
) {
1377 * This LSA must have flushed before due to OSPF-SR status
1378 * change. It seems a slip among routers in the routing domain.
1380 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1382 /* Flush it anyway. */
1383 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1386 /* Lookup this LSA corresponding Extended parameters */
1387 exti
= lookup_ext_by_instance(lsa
);
1389 zlog_warn("EXT (%s): Invalid parameter LSA ID", __func__
);
1390 /* Flush it anyway. */
1391 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1394 /* Check if Interface was not disable in the interval */
1395 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1396 zlog_warn("EXT (%s): Interface was Disabled: Flush it!",
1398 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1401 /* If the lsa's age reached to MaxAge, start flushing procedure */
1402 if (IS_LSA_MAXAGE(lsa
)) {
1404 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1405 ospf_opaque_lsa_flush_schedule(lsa
);
1409 /* Create new Opaque-LSA/Extended Link instance */
1410 new = ospf_ext_link_lsa_new(area
, exti
);
1412 zlog_warn("EXT (%s): Error creating new LSA", __func__
);
1415 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1417 /* Install this LSA into LSDB. */
1418 /* Given "lsa" will be freed in the next function */
1419 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1420 zlog_warn("EXT (%s): Error installing new LSA", __func__
);
1421 ospf_lsa_unlock(&new);
1425 /* Flood updated LSA through the link Area according to the RFC7684 */
1426 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1428 /* Debug logging. */
1429 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1431 "EXT (%s): LSA[Type%u:%s]: Refresh Extended Link LSA",
1432 __func__
, new->data
->type
, inet_ntoa(new->data
->id
));
1433 ospf_lsa_header_dump(new->data
);
1439 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1440 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
1441 enum lsa_opcode opcode
)
1443 struct ospf_lsa lsa
;
1444 struct lsa_header lsah
;
1448 memset(&lsa
, 0, sizeof(lsa
));
1449 memset(&lsah
, 0, sizeof(lsah
));
1455 /* Check if the corresponding link is ready to be flooded */
1456 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1459 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1460 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1461 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1462 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1463 exti
->ifp
? exti
->ifp
->name
: "-");
1465 /* Set LSA header information */
1466 if (exti
->area
== NULL
) {
1468 "EXT (%s): Flooding is Area scope but area is not yet "
1471 if (OspfEXT
.area
== NULL
) {
1472 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1473 OspfEXT
.area
= ospf_area_lookup_by_area_id(
1474 top
, OspfEXT
.area_id
);
1476 exti
->area
= OspfEXT
.area
;
1478 lsa
.area
= exti
->area
;
1480 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1481 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1482 lsah
.id
.s_addr
= htonl(tmp
);
1485 case REORIGINATE_THIS_LSA
:
1486 ospf_opaque_lsa_reoriginate_schedule(
1487 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1488 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
1490 case REFRESH_THIS_LSA
:
1491 ospf_opaque_lsa_refresh_schedule(&lsa
);
1493 case FLUSH_THIS_LSA
:
1494 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1495 ospf_opaque_lsa_flush_schedule(&lsa
);
1498 zlog_warn("EXT (%s): Unknown opcode", __func__
);
1503 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1504 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
1505 enum lsa_opcode opcode
)
1507 struct ospf_lsa lsa
;
1508 struct lsa_header lsah
;
1512 memset(&lsa
, 0, sizeof(lsa
));
1513 memset(&lsah
, 0, sizeof(lsah
));
1519 /* Check if the corresponding link is ready to be flooded */
1520 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1523 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__
,
1524 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1525 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1526 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1527 exti
->ifp
? exti
->ifp
->name
: "-");
1529 /* Set LSA header information */
1530 if (exti
->area
== NULL
) {
1532 "EXT (%s): Flooding is Area scope but area is not "
1535 if (OspfEXT
.area
== NULL
) {
1536 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1537 OspfEXT
.area
= ospf_area_lookup_by_area_id(
1538 top
, OspfEXT
.area_id
);
1540 exti
->area
= OspfEXT
.area
;
1542 lsa
.area
= exti
->area
;
1544 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1545 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1546 lsah
.id
.s_addr
= htonl(tmp
);
1549 case REORIGINATE_THIS_LSA
:
1550 ospf_opaque_lsa_reoriginate_schedule(
1551 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1552 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
1554 case REFRESH_THIS_LSA
:
1555 ospf_opaque_lsa_refresh_schedule(&lsa
);
1557 case FLUSH_THIS_LSA
:
1558 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1559 ospf_opaque_lsa_flush_schedule(&lsa
);
1562 zlog_warn("EXT (%s): Unknown opcode", __func__
);
1567 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1568 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
)
1571 if (exti
->stype
== PREF_SID
)
1572 ospf_ext_pref_lsa_schedule(exti
, op
);
1574 ospf_ext_link_lsa_schedule(exti
, op
);
1578 * ------------------------------------
1579 * Followings are vty show functions.
1580 * ------------------------------------
1583 /* Cisco experimental SubTLV */
1584 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty
*vty
,
1585 struct tlv_header
*tlvh
)
1587 struct ext_subtlv_rmt_itf_addr
*top
;
1589 top
= (struct ext_subtlv_rmt_itf_addr
*)tlvh
;
1592 " Remote Interface Address Sub-TLV: Length %u\n "
1594 ntohs(top
->header
.length
), inet_ntoa(top
->value
));
1596 return TLV_SIZE(tlvh
);
1599 /* Adjacency SID SubTLV */
1600 static uint16_t show_vty_ext_link_adj_sid(struct vty
*vty
,
1601 struct tlv_header
*tlvh
)
1603 struct ext_subtlv_adj_sid
*top
= (struct ext_subtlv_adj_sid
*)tlvh
;
1606 " Adj-SID Sub-TLV: Length %u\n\tFlags: "
1607 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1608 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1609 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1611 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1612 ? GET_LABEL(ntohl(top
->value
))
1613 : ntohl(top
->value
));
1615 return TLV_SIZE(tlvh
);
1618 /* LAN Adjacency SubTLV */
1619 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty
*vty
,
1620 struct tlv_header
*tlvh
)
1622 struct ext_subtlv_lan_adj_sid
*top
=
1623 (struct ext_subtlv_lan_adj_sid
*)tlvh
;
1626 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: "
1627 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: "
1629 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1630 inet_ntoa(top
->neighbor_id
),
1631 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1633 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1634 ? GET_LABEL(ntohl(top
->value
))
1635 : ntohl(top
->value
));
1637 return TLV_SIZE(tlvh
);
1640 static uint16_t show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
)
1642 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1643 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
1645 return TLV_SIZE(tlvh
);
1648 /* Extended Link Sub TLVs */
1649 static uint16_t show_vty_link_info(struct vty
*vty
, struct tlv_header
*ext
)
1651 struct ext_tlv_link
*top
= (struct ext_tlv_link
*)ext
;
1652 struct tlv_header
*tlvh
;
1653 uint16_t length
= ntohs(top
->header
.length
) - 3 * sizeof(uint32_t);
1657 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1659 ntohs(top
->header
.length
), top
->link_type
,
1660 inet_ntoa(top
->link_id
));
1661 vty_out(vty
, " Link data: %s\n", inet_ntoa(top
->link_data
));
1663 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1664 + EXT_TLV_LINK_SIZE
);
1665 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1666 switch (ntohs(tlvh
->type
)) {
1667 case EXT_SUBTLV_ADJ_SID
:
1668 sum
+= show_vty_ext_link_adj_sid(vty
, tlvh
);
1670 case EXT_SUBTLV_LAN_ADJ_SID
:
1671 sum
+= show_vty_ext_link_lan_adj_sid(vty
, tlvh
);
1673 case EXT_SUBTLV_RMT_ITF_ADDR
:
1674 sum
+= show_vty_ext_link_rmt_itf_addr(vty
, tlvh
);
1677 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1682 return sum
+ sizeof(struct ext_tlv_link
);
1685 /* Extended Link TLVs */
1686 static void ospf_ext_link_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1688 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
1689 struct tlv_header
*tlvh
;
1690 uint16_t length
= 0, sum
= 0;
1692 /* Initialize TLV browsing */
1693 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1695 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1696 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1697 switch (ntohs(tlvh
->type
)) {
1699 sum
+= show_vty_link_info(vty
, tlvh
);
1702 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1708 /* Prefix SID SubTLV */
1709 static uint16_t show_vty_ext_pref_pref_sid(struct vty
*vty
,
1710 struct tlv_header
*tlvh
)
1712 struct ext_subtlv_prefix_sid
*top
=
1713 (struct ext_subtlv_prefix_sid
*)tlvh
;
1716 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: "
1717 "%u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1718 ntohs(top
->header
.length
), top
->algorithm
, top
->flags
,
1720 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
) ? "Label"
1722 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
)
1723 ? GET_LABEL(ntohl(top
->value
))
1724 : ntohl(top
->value
));
1726 return TLV_SIZE(tlvh
);
1729 /* Extended Prefix SubTLVs */
1730 static uint16_t show_vty_pref_info(struct vty
*vty
, struct tlv_header
*ext
)
1732 struct ext_tlv_prefix
*top
= (struct ext_tlv_prefix
*)ext
;
1733 struct tlv_header
*tlvh
;
1734 uint16_t length
= ntohs(top
->header
.length
) - 2 * sizeof(uint32_t);
1738 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1739 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%u\n",
1740 ntohs(top
->header
.length
), top
->route_type
, top
->af
, top
->flags
,
1741 inet_ntoa(top
->address
), top
->pref_length
);
1743 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1744 + EXT_TLV_PREFIX_SIZE
);
1745 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1746 switch (ntohs(tlvh
->type
)) {
1747 case EXT_SUBTLV_PREFIX_SID
:
1748 sum
+= show_vty_ext_pref_pref_sid(vty
, tlvh
);
1751 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1756 return sum
+ sizeof(struct ext_tlv_prefix
);
1759 /* Extended Prefix TLVs */
1760 static void ospf_ext_pref_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1762 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
1763 struct tlv_header
*tlvh
;
1764 uint16_t length
= 0, sum
= 0;
1766 /* Initialize TLV browsing */
1767 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1769 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1770 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1771 switch (ntohs(tlvh
->type
)) {
1772 case EXT_TLV_PREFIX
:
1773 sum
+= show_vty_pref_info(vty
, tlvh
);
1776 sum
+= show_vty_unknown_tlv(vty
, tlvh
);