2 * This is an implementation of RFC7684 OSPFv2 Prefix/Link Attribute
5 * Module name: Extended Prefix/Link Opaque LSA
7 * Author: Anselme Sawadogo <anselmesawadogo@gmail.com>
8 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
10 * Copyright (C) 2016 - 2017 Orange Labs http://www.orange.com
12 * This file is part of FRR.
14 * FRR is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2, or (at your option) any
19 * FRR is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with FRR; see the file COPYING. If not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
46 #include "sockunion.h" /* for inet_aton() */
49 #include "libospf.h" /* for ospf interface types */
51 #include "ospfd/ospfd.h"
52 #include "ospfd/ospf_interface.h"
53 #include "ospfd/ospf_ism.h"
54 #include "ospfd/ospf_asbr.h"
55 #include "ospfd/ospf_lsa.h"
56 #include "ospfd/ospf_lsdb.h"
57 #include "ospfd/ospf_neighbor.h"
58 #include "ospfd/ospf_nsm.h"
59 #include "ospfd/ospf_flood.h"
60 #include "ospfd/ospf_packet.h"
61 #include "ospfd/ospf_spf.h"
62 #include "ospfd/ospf_dump.h"
63 #include "ospfd/ospf_route.h"
64 #include "ospfd/ospf_ase.h"
65 #include "ospfd/ospf_zebra.h"
66 #include "ospfd/ospf_sr.h"
67 #include "ospfd/ospf_ext.h"
69 /* Following structure are internal use only. */
72 * Global variable to manage Extended Prefix/Link Opaque LSA on this node.
73 * Note that all parameter values are stored in network byte order.
75 static struct ospf_ext_lp OspfEXT
;
77 /*------------------------------------------------------------------------------*
78 * Followings are initialize/terminate functions for Extended Prefix/Link Opaque
80 *------------------------------------------------------------------------------*/
82 /* Extended Prefix Opaque LSA related callback functions */
83 static int ospf_ext_pref_del_if(struct interface
*ifp
);
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: Register Extended Link Opaque LSA");
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 zlog_warn("EXT: Failed to register Extended Link LSA");
144 zlog_info("EXT: Register Extended Prefix Opaque LSA");
145 rc
= ospf_register_opaque_functab(
146 OspfEXT
.scope
, OPAQUE_TYPE_EXTENDED_PREFIX_LSA
,
147 NULL
, /* new interface */
148 ospf_ext_pref_del_if
, /* del interface */
149 NULL
, /* 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: Failed to register Extended Prefix LSA");
168 * 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;
196 /*------------------------------------------------------------------------*
197 * Followings are control functions for Extended Prefix/Link Opaque LSA
198 * parameters management.
199 *------------------------------------------------------------------------*/
200 /* Functions to free memory space */
201 static void del_ext_info(void *val
)
203 XFREE(MTYPE_OSPF_EXT_PARAMS
, val
);
207 /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
208 static uint32_t get_ext_pref_instance_value(void)
210 static uint32_t seqno
= 0;
212 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
215 seqno
= 1; /* Avoid zero. */
220 /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */
221 static uint32_t get_ext_link_instance_value(void)
223 static uint32_t seqno
= 0;
225 if (seqno
< MAX_LEGAL_EXT_INSTANCE_NUM
)
228 seqno
= 1; /* Avoid zero. */
233 /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
234 static struct ext_itf
*lookup_ext_by_ifp(struct interface
*ifp
)
236 struct listnode
*node
, *nnode
;
237 struct ext_itf
*exti
;
239 for (ALL_LIST_ELEMENTS(OspfEXT
.iflist
, node
, nnode
, exti
))
240 if (exti
->ifp
== ifp
)
246 /* Lookup Extended Prefix/Links by LSA ID from OspfEXT struct iflist */
247 static struct ext_itf
*lookup_ext_by_instance(struct ospf_lsa
*lsa
)
249 struct listnode
*node
;
250 struct ext_itf
*exti
;
251 unsigned int key
= GET_OPAQUE_ID(ntohl(lsa
->data
->id
.s_addr
));
253 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
254 if (exti
->instance
== key
)
257 zlog_warn("lookup_linkparams_by_instance: Entry not found: key(%x)",
262 /*------------------------------------------------------------------------*
263 * The underlying subsection defines setters and unsetters to create and
264 * delete tlvs and subtlvs
265 *------------------------------------------------------------------------*/
267 /* Extended Prefix TLV - RFC7684 section 2.1 */
268 static void set_ext_prefix(struct ext_itf
*exti
, uint8_t route_type
,
269 uint8_t flags
, struct prefix_ipv4 p
)
272 TLV_TYPE(exti
->prefix
) = htons(EXT_TLV_PREFIX
);
273 /* Warning: Size must be adjust depending of subTLV's */
274 TLV_LEN(exti
->prefix
) = htons(EXT_TLV_PREFIX_SIZE
);
275 exti
->prefix
.route_type
= route_type
;
276 exti
->prefix
.flags
= flags
;
277 /* Only Address Family Ipv4 (0) is defined in RFC 7684 */
279 exti
->prefix
.pref_length
= p
.prefixlen
;
280 exti
->prefix
.address
= p
.prefix
;
283 /* Extended Link TLV - RFC7684 section 3.1 */
284 static void set_ext_link(struct ext_itf
*exti
, uint8_t type
, struct in_addr id
,
288 TLV_TYPE(exti
->link
) = htons(EXT_TLV_LINK
);
289 /* Warning: Size must be adjust depending of subTLV's */
290 TLV_LEN(exti
->link
) = htons(EXT_TLV_LINK_SIZE
);
291 exti
->link
.link_type
= type
;
292 exti
->link
.link_id
= id
;
293 exti
->link
.link_data
= data
;
296 /* Prefix SID SubTLV - section 5 */
297 static void set_prefix_sid(struct ext_itf
*exti
, uint8_t algorithm
,
298 uint32_t value
, int value_type
)
303 if ((algorithm
!= SR_ALGORITHM_SPF
)
304 && (algorithm
!= SR_ALGORITHM_STRICT_SPF
)) {
306 "OSPF_SR: unrecognized "
307 "algorithm, not spf or strict spf");
311 /* Set the flags according to the type of value field: label or index
312 * other flags flags are cleared, in particular the No-PHP as the
313 * Linux Kernel only supports Penultimate Hop Popping (PHP)
315 if (value_type
== SID_LABEL
)
316 flags
= EXT_SUBTLV_PREFIX_SID_VFLG
;
320 /* set prefix sid subtlv for an extended prefix tlv */
321 TLV_TYPE(exti
->node_sid
) = htons(EXT_SUBTLV_PREFIX_SID
);
322 exti
->node_sid
.algorithm
= algorithm
;
323 exti
->node_sid
.flags
= flags
;
324 exti
->node_sid
.mtid
= 0; /* Multi-Topology is not supported */
326 /* Set Label or Index value */
327 if (value_type
== SID_LABEL
) {
328 TLV_LEN(exti
->node_sid
) = htons(SID_LABEL_SIZE
);
329 exti
->node_sid
.value
= htonl(SET_LABEL(value
));
331 TLV_LEN(exti
->node_sid
) = htons(SID_INDEX_SIZE
);
332 exti
->node_sid
.value
= htonl(value
);
338 /* Adjacency SID SubTLV - section 6.1 */
339 static void set_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
345 /* Determine which ADJ_SID must be set: nominal or backup */
347 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
355 TLV_TYPE(exti
->adj_sid
[index
]) = htons(EXT_SUBTLV_ADJ_SID
);
357 /* Only Local ADJ-SID is supported for the moment */
358 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
360 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
362 /* Adjust Length, Flags and Value depending on the type of Label */
363 if (value_type
== SID_LABEL
) {
364 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
365 TLV_LEN(exti
->adj_sid
[index
]) = htons(SID_LABEL_SIZE
);
366 exti
->adj_sid
[index
].value
= htonl(SET_LABEL(value
));
368 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
369 TLV_LEN(exti
->adj_sid
[index
]) = htons(SID_INDEX_SIZE
);
370 exti
->adj_sid
[index
].value
= htonl(value
);
373 exti
->adj_sid
[index
].flags
= flags
; /* Set computed flags */
374 exti
->adj_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
375 exti
->adj_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
379 /* LAN Adjacency SID SubTLV - section 6.2 */
380 static void set_lan_adj_sid(struct ext_itf
*exti
, bool backup
, uint32_t value
,
381 int value_type
, struct in_addr neighbor_id
)
387 /* Determine which ADJ_SID must be set: nominal or backup */
389 flags
= EXT_SUBTLV_LINK_ADJ_SID_BFLG
;
397 TLV_TYPE(exti
->lan_sid
[index
]) = htons(EXT_SUBTLV_ADJ_SID
);
399 /* Only Local ADJ-SID is supported for the moment */
400 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_LFLG
);
402 /* Adjust Length, Flags and Value depending on the type of Label */
403 if (value_type
== SID_LABEL
) {
404 SET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
405 TLV_LEN(exti
->lan_sid
[index
]) = htons(SID_LABEL_SIZE
);
406 exti
->lan_sid
[index
].value
= htonl(SET_LABEL(value
));
408 UNSET_FLAG(flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
);
409 TLV_LEN(exti
->lan_sid
[index
]) = htons(SID_INDEX_SIZE
);
410 exti
->lan_sid
[index
].value
= htonl(value
);
413 exti
->lan_sid
[index
].flags
= flags
; /* Set computed flags */
414 exti
->lan_sid
[index
].mtid
= 0; /* Multi-Topology is not supported */
415 exti
->lan_sid
[index
].weight
= 0; /* Load-Balancing is not supported */
416 exti
->lan_sid
[index
].neighbor_id
= neighbor_id
;
420 /* Experimental SubTLV from Cisco */
421 static void set_rmt_itf_addr(struct ext_itf
*exti
, struct in_addr rmtif
)
424 TLV_TYPE(exti
->rmt_itf_addr
) = htons(EXT_SUBTLV_RMT_ITF_ADDR
);
425 TLV_LEN(exti
->rmt_itf_addr
) = htons(sizeof(struct in_addr
));
426 exti
->rmt_itf_addr
.value
= rmtif
;
431 * Update Extended prefix SID index for Loopback interface type
433 * @param ifname - Loopback interface name
434 * @param index - new value for the prefix SID of this interface
435 * @param p - prefix for this interface or NULL if Extended Prefix
438 * @return instance number if update is OK, 0 otherwise
440 int ospf_ext_schedule_prefix_index(struct interface
*ifp
, uint32_t index
,
441 struct prefix_ipv4
*p
)
444 struct ext_itf
*exti
;
446 /* Find Extended Prefix interface */
447 exti
= lookup_ext_by_ifp(ifp
);
452 if (IS_DEBUG_OSPF_SR
)
454 "EXT (ospf_ext_schedule_prefix_index) "
455 "Schedule new prefix %s/%d with index %d "
457 inet_ntoa(p
->prefix
), p
->prefixlen
, index
,
460 /* Set first Extended Prefix then the Prefix SID information */
461 set_ext_prefix(exti
, OSPF_PATH_INTRA_AREA
, EXT_TLV_PREF_NFLG
,
463 set_prefix_sid(exti
, SR_ALGORITHM_SPF
, index
, SID_INDEX
);
465 /* Try to Schedule LSA */
466 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
467 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
468 ospf_ext_pref_lsa_schedule(exti
, REFRESH_THIS_LSA
);
470 ospf_ext_pref_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
472 if (IS_DEBUG_OSPF_SR
)
474 "EXT (ospf_ext_schedule_prefix_index) "
475 "Remove prefix for interface %s",
478 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
479 ospf_ext_pref_lsa_schedule(exti
, FLUSH_THIS_LSA
);
480 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
481 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
485 return exti
->instance
;
489 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
491 * @param enable To activate or not Segment Routing Extended LSA flooding
495 void ospf_ext_update_sr(bool enable
)
497 struct listnode
*node
;
498 struct ext_itf
*exti
;
500 if (IS_DEBUG_OSPF_SR
)
502 "EXT (ospf_ext_update_sr): %s Extended LSAs for "
504 enable
? "Enable" : "Disable");
507 OspfEXT
.enabled
= true;
508 /* Refresh LSAs if already engaged or originate */
509 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
510 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
511 ospf_ext_lsa_schedule(exti
, REFRESH_THIS_LSA
);
513 ospf_ext_lsa_schedule(exti
,
514 REORIGINATE_THIS_LSA
);
516 /* Start by Flushing engaged LSAs */
517 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
))
518 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
519 ospf_ext_lsa_schedule(exti
, FLUSH_THIS_LSA
);
520 /* And then disable Extended Link/Prefix */
521 OspfEXT
.enabled
= false;
524 /*------------------------------------------------------------------------*
525 * Followings are callback functions against generic Opaque-LSAs handling.
526 *------------------------------------------------------------------------*/
528 /* Add new Interface in Extended Interface List */
529 static int ospf_ext_link_new_if(struct interface
*ifp
)
534 if (lookup_ext_by_ifp(ifp
) != NULL
) {
536 "EXT (ospf_ext_link_new_if) interface %s"
537 " is already in use",
538 ifp
? ifp
->name
: "-");
539 rc
= 0; /* Do nothing here. */
543 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS
, sizeof(struct ext_itf
));
545 zlog_warn("EXT: XCALLOC: %s", safe_strerror(errno
));
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 if ((exti
= lookup_ext_by_ifp(ifp
)) != NULL
) {
566 struct list
*iflist
= OspfEXT
.iflist
;
568 /* Skip Extended Prefix interface */
569 if (exti
->stype
== PREF_SID
)
572 /* Dequeue listnode entry from the list. */
573 listnode_delete(iflist
, exti
);
575 /* Avoid misjudgement in the next lookup. */
576 if (listcount(iflist
) == 0)
577 iflist
->head
= iflist
->tail
= NULL
;
579 XFREE(MTYPE_OSPF_EXT_PARAMS
, exti
);
584 "EXT (ospf_ext_link_del_if) interface %s "
586 ifp
? ifp
->name
: "-");
592 /* Remove existing Interface from Extended Interface List */
593 static int ospf_ext_pref_del_if(struct interface
*ifp
)
595 struct ext_itf
*exti
;
598 if ((exti
= lookup_ext_by_ifp(ifp
)) != NULL
) {
599 struct list
*iflist
= OspfEXT
.iflist
;
601 /* Look only to Extended Prefix interface */
602 if (exti
->stype
!= PREF_SID
)
605 /* Dequeue listnode entry from the list. */
606 listnode_delete(iflist
, exti
);
608 /* Avoid misjudgement in the next lookup. */
609 if (listcount(iflist
) == 0)
610 iflist
->head
= iflist
->tail
= NULL
;
612 XFREE(MTYPE_OSPF_EXT_PARAMS
, exti
);
617 "EXT (ospf_ext_pref_del_if) interface %s "
619 ifp
? ifp
->name
: "-");
626 * Determine if an Extended Interface is Link or Prefix type and
627 * allocate new instance value accordingly
629 static void ospf_ext_link_ism_change(struct ospf_interface
*oi
, int old_status
)
631 struct ext_itf
*exti
;
633 /* Get interface information for Segment Routing */
634 if ((exti
= lookup_ext_by_ifp(oi
->ifp
)) == NULL
) {
636 "EXT (ospf_ext_link_ism_change) Cannot get Extended "
637 "information from OI(%s)",
642 /* Determine if interface is related to Node SID or Adjacency/LAN SID */
643 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
) {
644 exti
->stype
= PREF_SID
;
645 exti
->instance
= get_ext_pref_instance_value();
647 exti
->stype
= ADJ_SID
;
648 exti
->instance
= get_ext_link_instance_value();
650 zlog_debug("EXT (ospf_ext_link_ism_change) Set %s SID to interface %s ",
651 exti
->stype
== PREF_SID
? "Node" : "Adj.", oi
->ifp
->name
);
655 * Finish Extended Link configuration and flood corresponding LSA
656 * when OSPF adjacency on this link fire up
658 static void ospf_ext_link_nsm_change(struct ospf_neighbor
*nbr
, int old_status
)
660 struct ospf_interface
*oi
= nbr
->oi
;
661 struct ext_itf
*exti
;
664 /* Process Neighbor only when its state is NSM Full */
665 if (nbr
->state
!= NSM_Full
)
668 /* Get interface information for Segment Routing */
669 if ((exti
= lookup_ext_by_ifp(oi
->ifp
)) == NULL
) {
671 "EXT (ospf_ext_link_nsm_change) Cannot get Extended "
672 "information from OI(%s)",
677 if (oi
->area
== NULL
|| oi
->area
->ospf
== NULL
) {
679 "EXT (ospf_ext_link_nsm_change) Cannot refer to "
685 /* Keep Area information in combination with SR info. */
686 exti
->area
= oi
->area
;
687 OspfEXT
.area
= oi
->area
;
689 /* Process only Adjacency/LAN SID */
690 if (exti
->stype
== PREF_SID
)
694 case ISM_PointToPoint
:
695 /* Segment ID is an Adjacency one */
696 exti
->stype
= ADJ_SID
;
698 /* Set Extended Link TLV with link_id == Nbr Router ID */
699 set_ext_link(exti
, OSPF_IFTYPE_POINTOPOINT
, nbr
->router_id
,
700 oi
->address
->u
.prefix4
);
702 /* Set Extended Link Adjacency SubTLVs, backup first */
703 label
= get_ext_link_label_value();
704 set_adj_sid(exti
, true, label
, SID_LABEL
);
705 label
= get_ext_link_label_value();
706 set_adj_sid(exti
, false, label
, SID_LABEL
);
707 /* And Remote Interface address */
708 set_rmt_itf_addr(exti
, nbr
->address
.u
.prefix4
);
713 /* Segment ID is a LAN Adjacency for the DR only */
714 exti
->stype
= LAN_ADJ_SID
;
716 /* Set Extended Link TLV with link_id == DR */
717 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
718 oi
->address
->u
.prefix4
);
720 /* Set Extended Link Adjacency SubTLVs, backup first */
721 label
= get_ext_link_label_value();
722 set_lan_adj_sid(exti
, true, label
, SID_LABEL
, nbr
->router_id
);
723 label
= get_ext_link_label_value();
724 set_lan_adj_sid(exti
, false, label
, SID_LABEL
, nbr
->router_id
);
730 /* Segment ID is an Adjacency if not the DR */
731 exti
->stype
= ADJ_SID
;
733 /* Set Extended Link TLV with link_id == DR */
734 set_ext_link(exti
, OSPF_IFTYPE_BROADCAST
, DR(oi
),
735 oi
->address
->u
.prefix4
);
737 /* Set Extended Link Adjacency SubTLVs, backup first */
738 label
= get_ext_link_label_value();
739 set_adj_sid(exti
, true, label
, SID_LABEL
);
740 label
= get_ext_link_label_value();
741 set_adj_sid(exti
, false, label
, SID_LABEL
);
746 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
747 ospf_ext_link_lsa_schedule(exti
, FLUSH_THIS_LSA
);
748 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
749 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
754 /* flood this links params if everything is ok */
755 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
);
756 if (OspfEXT
.enabled
) {
757 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
))
758 ospf_ext_link_lsa_schedule(exti
, REFRESH_THIS_LSA
);
760 ospf_ext_link_lsa_schedule(exti
, REORIGINATE_THIS_LSA
);
766 /* Callbacks to handle Extended Link Segment Routing LSA information */
767 static int ospf_ext_link_lsa_update(struct ospf_lsa
*lsa
)
772 "EXT (ospf_ext_link_lsa_update): Abort! LSA is "
777 /* Process only Extended Link LSA */
778 if (GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
779 != OPAQUE_TYPE_EXTENDED_LINK_LSA
)
782 /* Check if Extended is enable */
783 if (!OspfEXT
.enabled
)
786 /* Call Segment Routing LSA update or deletion */
787 if (!IS_LSA_MAXAGE(lsa
))
788 ospf_sr_ext_link_lsa_update(lsa
);
790 ospf_sr_ext_link_lsa_delete(lsa
);
795 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
796 static int ospf_ext_pref_lsa_update(struct ospf_lsa
*lsa
)
802 "EXT (ospf_ext_pref_lsa_update): Abort! LSA is "
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 Extended is enable */
813 if (!OspfEXT
.enabled
)
816 /* Call Segment Routing LSA update or deletion */
817 if (!IS_LSA_MAXAGE(lsa
))
818 ospf_sr_ext_prefix_lsa_update(lsa
);
820 ospf_sr_ext_prefix_lsa_delete(lsa
);
825 /*------------------------------------------------------------------------*
826 * Followings are OSPF protocol processing functions for
827 * Extended Prefix/Link Opaque LSA
828 *------------------------------------------------------------------------*/
830 static void build_tlv_header(struct stream
*s
, struct tlv_header
*tlvh
)
832 stream_put(s
, tlvh
, sizeof(struct tlv_header
));
836 static void build_tlv(struct stream
*s
, struct tlv_header
*tlvh
)
839 if ((tlvh
!= NULL
) && (ntohs(tlvh
->type
) != 0)) {
840 build_tlv_header(s
, tlvh
);
841 stream_put(s
, TLV_DATA(tlvh
), TLV_BODY_SIZE(tlvh
));
846 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
847 static void ospf_ext_pref_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
851 if ((exti
== NULL
) || (exti
->stype
!= PREF_SID
))
854 /* Adjust Extended Prefix TLV size */
855 TLV_LEN(exti
->prefix
) =
856 htons(ntohs(TLV_LEN(exti
->node_sid
)) + EXT_TLV_PREFIX_SIZE
);
858 /* Build LSA body for an Extended Prefix TLV */
859 build_tlv_header(s
, &exti
->prefix
.header
);
860 stream_put(s
, TLV_DATA(&exti
->prefix
.header
), EXT_TLV_PREFIX_SIZE
);
861 /* Then add Prefix SID SubTLV */
862 build_tlv(s
, &exti
->node_sid
.header
);
867 /* Build an Extended Link Opaque LSA body for extended link TLV */
868 static void ospf_ext_link_lsa_body_set(struct stream
*s
, struct ext_itf
*exti
)
873 || ((exti
->stype
!= ADJ_SID
) && (exti
->stype
!= LAN_ADJ_SID
)))
876 if (exti
->stype
== ADJ_SID
) {
877 /* Adjust Extended Link TLV size for Adj. SID */
878 TLV_LEN(exti
->link
) =
879 htons(EXT_TLV_LINK_SIZE
+ 2 * EXT_SUBTLV_ADJ_SID_SIZE
880 + 2 * TLV_HDR_SIZE
+ EXT_SUBTLV_RMT_ITF_ADDR_SIZE
883 /* Build LSA body for an Extended Link TLV with Adj. SID */
884 build_tlv_header(s
, &exti
->link
.header
);
885 stream_put(s
, TLV_DATA(&exti
->link
.header
), EXT_TLV_LINK_SIZE
);
886 /* then add Ajacency SubTLVs */
887 build_tlv(s
, &exti
->adj_sid
[1].header
);
888 build_tlv(s
, &exti
->adj_sid
[0].header
);
889 /* Cisco experimental SubTLV */
890 build_tlv(s
, &exti
->rmt_itf_addr
.header
);
892 /* Adjust Extended Link TLV size for LAN SID */
893 TLV_LEN(exti
->link
) = htons(EXT_TLV_LINK_SIZE
894 + 2 * EXT_SUBTLV_LAN_ADJ_SID_SIZE
897 /* Build LSA body for an Extended Link TLV with LAN SID */
898 build_tlv_header(s
, &exti
->link
.header
);
899 stream_put(s
, &exti
->link
.header
, EXT_TLV_LINK_SIZE
);
900 /* then add LAN-Ajacency SubTLVs */
901 build_tlv(s
, &exti
->lan_sid
[1].header
);
902 build_tlv(s
, &exti
->lan_sid
[0].header
);
908 /* Create new Extended Prefix opaque-LSA for every extended prefix */
909 static struct ospf_lsa
*ospf_ext_pref_lsa_new(struct ospf_area
*area
,
910 struct ext_itf
*exti
)
913 struct lsa_header
*lsah
;
914 struct ospf_lsa
*new = NULL
;
915 u_char options
, lsa_type
;
916 struct in_addr lsa_id
;
917 struct in_addr router_id
;
925 /* Create a stream for LSA. */
926 if ((s
= stream_new(OSPF_MAX_LSA_SIZE
)) == NULL
) {
927 zlog_warn("EXT: stream_new() error");
931 /* Prepare LSA Header */
932 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
934 lsa_type
= OspfEXT
.scope
;
936 /* LSA ID is a variable number identifying different instances of
937 * Extended Prefix Opaque LSA from the same router see RFC 7684 */
938 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
939 lsa_id
.s_addr
= htonl(tmp
);
941 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
943 /* Fix Options and Router ID depending of the flooding scope */
944 if ((OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
) || (area
== NULL
)) {
945 options
= OSPF_OPTION_E
;
946 struct ospf
*top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
947 router_id
= top
->router_id
;
949 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
950 options
|= LSA_OPTIONS_NSSA_GET(area
);
951 router_id
= area
->ospf
->router_id
;
954 /* Set opaque-LSA header fields. */
955 lsa_header_set(s
, options
, lsa_type
, lsa_id
, router_id
);
957 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
959 "EXT: LSA[Type%d:%s]: Create an Opaque-LSA/Extended "
960 "Prefix Opaque LSA instance",
961 lsa_type
, inet_ntoa(lsa_id
));
964 /* Set opaque-LSA body fields. */
965 ospf_ext_pref_lsa_body_set(s
, exti
);
968 length
= stream_get_endp(s
);
969 lsah
->length
= htons(length
);
971 /* Now, create an OSPF LSA instance. */
972 if ((new = ospf_lsa_new()) == NULL
) {
973 zlog_warn("EXT: ospf_lsa_new() error");
977 if ((new->data
= ospf_lsa_data_new(length
)) == NULL
) {
978 zlog_warn("EXT: ospf_lsa_data_new() error");
979 ospf_lsa_unlock(&new);
986 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
987 memcpy(new->data
, lsah
, length
);
993 /* Create new Extended Link opaque-LSA for every extended link TLV */
994 static struct ospf_lsa
*ospf_ext_link_lsa_new(struct ospf_area
*area
,
995 struct ext_itf
*exti
)
998 struct lsa_header
*lsah
;
999 struct ospf_lsa
*new = NULL
;
1000 u_char options
, lsa_type
;
1001 struct in_addr lsa_id
;
1009 /* Create a stream for LSA. */
1010 if ((s
= stream_new(OSPF_MAX_LSA_SIZE
)) == NULL
) {
1011 zlog_warn("EXT: stream_new() error");
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
;
1022 /* LSA ID is a variable number identifying different instances of
1023 * Extended Link Opaque LSA from the same router see RFC 7684 */
1024 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1025 lsa_id
.s_addr
= htonl(tmp
);
1027 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1029 "EXT: LSA[Type%d:%s]: Create an Opaque-LSA/Extended "
1030 "Link Opaque LSA instance",
1031 lsa_type
, inet_ntoa(lsa_id
));
1033 /* Set opaque-LSA header fields. */
1034 lsa_header_set(s
, options
, lsa_type
, lsa_id
, area
->ospf
->router_id
);
1036 /* Set opaque-LSA body fields. */
1037 ospf_ext_link_lsa_body_set(s
, exti
);
1040 length
= stream_get_endp(s
);
1041 lsah
->length
= htons(length
);
1043 /* Now, create an OSPF LSA instance. */
1044 if ((new = ospf_lsa_new()) == NULL
) {
1045 zlog_warn("EXT: ospf_lsa_new() error");
1049 if ((new->data
= ospf_lsa_data_new(length
)) == NULL
) {
1050 zlog_warn("EXT: ospf_lsa_data_new() error");
1051 ospf_lsa_unlock(&new);
1058 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1059 memcpy(new->data
, lsah
, length
);
1065 /* Process the origination of an Extended Prefix Opaque LSA
1066 * for every extended prefix TLV */
1067 static int ospf_ext_pref_lsa_originate1(struct ospf_area
*area
,
1068 struct ext_itf
*exti
)
1070 struct ospf_lsa
*new;
1074 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1075 if ((new = ospf_ext_pref_lsa_new(area
, exti
)) == NULL
) {
1076 zlog_warn("EXT: ospf_ext_pref_lsa_new() error");
1080 /* Install this LSA into LSDB. */
1081 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1082 zlog_warn("EXT: ospf_lsa_install() error");
1083 ospf_lsa_unlock(&new);
1087 /* Now this Extended Prefix Opaque LSA info parameter entry has
1088 * associated LSA. */
1089 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1091 /* Update new LSA origination count. */
1092 area
->ospf
->lsa_originate_count
++;
1094 /* Flood new LSA through area. */
1095 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1097 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1098 char area_id
[INET_ADDRSTRLEN
];
1099 strncpy(area_id
, inet_ntoa(area
->area_id
), INET_ADDRSTRLEN
);
1101 "EXT: LSA[Type%d:%s]: Originate Opaque-LSA/Extended "
1102 "Prefix Opaque LSA: Area(%s), Link(%s)",
1103 new->data
->type
, inet_ntoa(new->data
->id
), area_id
,
1105 ospf_lsa_header_dump(new->data
);
1113 /* Process the origination of an Extended Link Opaque LSA
1114 * 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 if ((new = ospf_ext_link_lsa_new(area
, exti
)) == NULL
) {
1123 zlog_warn("EXT: ospf_ext_link_lsa_new() error");
1127 /* Install this LSA into LSDB. */
1128 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1129 zlog_warn("EXT: ospf_lsa_install() error");
1130 ospf_lsa_unlock(&new);
1134 /* Now this link-parameter entry has associated LSA. */
1135 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1137 /* Update new LSA origination count. */
1138 area
->ospf
->lsa_originate_count
++;
1140 /* Flood new LSA through area. */
1141 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1143 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1144 char area_id
[INET_ADDRSTRLEN
];
1145 strncpy(area_id
, inet_ntoa(area
->area_id
), INET_ADDRSTRLEN
);
1147 "EXT: LSA[Type%d:%s]: Originate Opaque-LSA/Extended "
1148 "Link Opaque LSA: Area(%s), Link(%s)",
1149 new->data
->type
, inet_ntoa(new->data
->id
), area_id
,
1151 ospf_lsa_header_dump(new->data
);
1159 /* Trigger the origination of Extended Prefix Opaque LSAs */
1160 static int ospf_ext_pref_lsa_originate(void *arg
)
1162 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1163 struct listnode
*node
;
1164 struct ext_itf
*exti
;
1167 if (!OspfEXT
.enabled
) {
1169 "EXT: Segment Routing "
1170 "functionality is Disabled now.");
1171 rc
= 0; /* This is not an error case. */
1174 if (IS_DEBUG_OSPF_SR
)
1176 "EXT (ospf_ext_pref_lsa_originate) "
1177 "Start Originate Prefix LSA for area %s",
1178 inet_ntoa(area
->area_id
));
1180 /* Check if Extended Prefix Opaque LSA is already engaged */
1181 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1183 /* Process only Prefix SID */
1184 if (exti
->stype
!= PREF_SID
)
1187 /* Process only Extended Prefix with valid Area ID */
1188 if ((exti
->area
== NULL
)
1189 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1192 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1193 if (CHECK_FLAG(exti
->flags
,
1194 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1195 zlog_warn("EXT: Refresh instead of Originate");
1196 UNSET_FLAG(exti
->flags
,
1197 EXT_LPFLG_LSA_FORCED_REFRESH
);
1198 ospf_ext_pref_lsa_schedule(exti
,
1204 /* Ok, let's try to originate an LSA */
1205 if (IS_DEBUG_OSPF_SR
)
1207 "EXT: Let's finally reoriginate the "
1208 "LSA 7.0.0.%d for Itf %s",
1210 exti
->ifp
? exti
->ifp
->name
: "");
1211 ospf_ext_pref_lsa_originate1(area
, exti
);
1218 /* Trigger the origination of Extended Link Opaque LSAs */
1219 static int ospf_ext_link_lsa_originate(void *arg
)
1221 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1222 struct listnode
*node
;
1223 struct ext_itf
*exti
;
1226 if (!OspfEXT
.enabled
) {
1228 "EXT: Segment Routing "
1229 "functionality is Disabled now.");
1230 rc
= 0; /* This is not an error case. */
1234 /* Check if Extended Prefix Opaque LSA is already engaged */
1235 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1236 /* Process only Adjacency or LAN SID */
1237 if (exti
->stype
== PREF_SID
)
1240 /* Process only Extended Link with valid Area ID */
1241 if ((exti
->area
== NULL
)
1242 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1245 /* Check if LSA not already engaged */
1246 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1247 if (CHECK_FLAG(exti
->flags
,
1248 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1249 zlog_warn("EXT: Refresh instead of Originate");
1250 UNSET_FLAG(exti
->flags
,
1251 EXT_LPFLG_LSA_FORCED_REFRESH
);
1252 ospf_ext_link_lsa_schedule(exti
,
1258 /* Ok, let's try to originate an LSA */
1259 if (IS_DEBUG_OSPF_SR
)
1261 "EXT Let's finally reoriginate the "
1262 "LSA 8.0.0.%d for Itf %s through the Area %s",
1264 exti
->ifp
? exti
->ifp
->name
: "-",
1265 inet_ntoa(area
->area_id
));
1266 ospf_ext_link_lsa_originate1(area
, exti
);
1273 /* Refresh an Extended Prefix Opaque LSA */
1274 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
)
1276 struct ospf_lsa
*new = NULL
;
1277 struct ospf_area
*area
= lsa
->area
;
1279 struct ext_itf
*exti
;
1281 if (!OspfEXT
.enabled
) {
1283 * This LSA must have flushed before due to Extended Prefix
1284 * Opaque LSA status change.
1285 * It seems a slip among routers in the routing domain.
1287 zlog_info("EXT: Segment Routing functionality is Disabled");
1288 /* Flush it anyway. */
1289 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1292 /* Lookup this lsa corresponding Extended parameters */
1293 if ((exti
= lookup_ext_by_instance(lsa
)) == NULL
) {
1294 zlog_warn("EXT: Invalid parameter LSA ID");
1295 /* Flush it anyway. */
1296 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1299 /* Check if Interface was not disable in the interval */
1300 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1301 zlog_warn("EXT: Interface was Disabled: Flush it!");
1302 /* Flush it anyway. */
1303 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1306 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1307 if (IS_LSA_MAXAGE(lsa
)) {
1309 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1310 ospf_opaque_lsa_flush_schedule(lsa
);
1314 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1316 new = ospf_ext_pref_lsa_new(area
, exti
);
1319 zlog_warn("EXT: ospf_ext_pref_lsa_new() error");
1322 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1324 /* Install this LSA into LSDB. */
1325 /* Given "lsa" will be freed in the next function. */
1326 /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1327 * ospf_lookup() to get ospf instance */
1331 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1333 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1334 zlog_warn("EXT: ospf_lsa_install() error");
1335 ospf_lsa_unlock(&new);
1339 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1340 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1342 /* Debug logging. */
1343 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1344 zlog_debug("EXT: LSA[Type%d:%s]: Refresh Extended Prefix LSA",
1345 new->data
->type
, inet_ntoa(new->data
->id
));
1346 ospf_lsa_header_dump(new->data
);
1352 /* Refresh an Extended Link Opaque LSA */
1353 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
)
1355 struct ext_itf
*exti
;
1356 struct ospf_area
*area
= lsa
->area
;
1357 struct ospf
*top
= area
->ospf
;
1358 struct ospf_lsa
*new = NULL
;
1360 if (!OspfEXT
.enabled
) {
1362 * This LSA must have flushed before due to OSPF-SR status
1363 * change. It seems a slip among routers in the routing domain.
1366 "EXT (ospf_ext_link_lsa_refresh): Segment Routing "
1367 "functionality is Disabled");
1368 /* Flush it anyway. */
1369 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1372 /* Lookup this lsa corresponding Extended parameters */
1373 if ((exti
= lookup_ext_by_instance(lsa
)) == NULL
) {
1375 "EXT (ospf_ext_link_lsa_refresh): Invalid parameter "
1377 /* Flush it anyway. */
1378 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1381 /* Check if Interface was not disable in the interval */
1382 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1384 "EXT (ospf_ext_link_lsa_refresh): Interface was "
1385 "Disabled: Flush it!");
1386 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1389 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1390 if (IS_LSA_MAXAGE(lsa
)) {
1392 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1393 ospf_opaque_lsa_flush_schedule(lsa
);
1397 /* Create new Opaque-LSA/MPLS-TE instance. */
1398 if ((new = ospf_ext_link_lsa_new(area
, exti
)) == NULL
) {
1400 "EXT (ospf_ext_link_lsa_refresh): Error creating "
1404 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1406 /* Install this LSA into LSDB. */
1407 /* Given "lsa" will be freed in the next function. */
1408 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1410 "EXT (ospf_ext_link_lsa_refresh): Error installing "
1412 ospf_lsa_unlock(&new);
1416 /* Flood updated LSA through the link Area according to the RFC7684 */
1417 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1419 /* Debug logging. */
1420 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1422 "EXT (ospf_ext_link_lsa_refresh): LSA[Type%d:%s]: "
1423 "Refresh Extended Link LSA",
1424 new->data
->type
, inet_ntoa(new->data
->id
));
1425 ospf_lsa_header_dump(new->data
);
1431 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1432 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
1433 enum lsa_opcode opcode
)
1435 struct ospf_lsa lsa
;
1436 struct lsa_header lsah
;
1440 memset(&lsa
, 0, sizeof(lsa
));
1441 memset(&lsah
, 0, sizeof(lsah
));
1447 /* Check if the corresponding link is ready to be flooded */
1448 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1452 "EXT (ospf_ext_pref_lsa_schedule): Schedule %s%s%s LSA "
1454 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1455 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1456 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1457 exti
->ifp
? exti
->ifp
->name
: "-");
1459 /* Set LSA header information */
1460 if (exti
->area
== NULL
) {
1462 "EXT (ospf_ext_pref_lsa_schedule): Flooding is "
1463 "Area scope but area is not yet set");
1464 if (OspfEXT
.area
== NULL
) {
1465 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1466 OspfEXT
.area
= ospf_area_lookup_by_area_id(
1467 top
, OspfEXT
.area_id
);
1469 exti
->area
= OspfEXT
.area
;
1471 lsa
.area
= exti
->area
;
1473 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1474 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1475 lsah
.id
.s_addr
= htonl(tmp
);
1478 case REORIGINATE_THIS_LSA
:
1479 ospf_opaque_lsa_reoriginate_schedule(
1480 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1481 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
1483 case REFRESH_THIS_LSA
:
1484 ospf_opaque_lsa_refresh_schedule(&lsa
);
1486 case FLUSH_THIS_LSA
:
1487 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1488 ospf_opaque_lsa_flush_schedule(&lsa
);
1491 zlog_warn("EXT (ospf_ext_pref_lsa_schedule): Unknown opcode");
1498 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1499 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
1500 enum lsa_opcode opcode
)
1502 struct ospf_lsa lsa
;
1503 struct lsa_header lsah
;
1507 memset(&lsa
, 0, sizeof(lsa
));
1508 memset(&lsah
, 0, sizeof(lsah
));
1514 /* Check if the corresponding link is ready to be flooded */
1515 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1519 "EXT (ospf_ext_link_lsa_schedule): Schedule %s%s%s LSA "
1521 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1522 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1523 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1524 exti
->ifp
? exti
->ifp
->name
: "-");
1526 /* Set LSA header information */
1527 if (exti
->area
== NULL
) {
1529 "EXT (ospf_ext_link_lsa_schedule): Flooding is "
1530 "Area scope but area is not yet set");
1531 if (OspfEXT
.area
== NULL
) {
1532 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1533 OspfEXT
.area
= ospf_area_lookup_by_area_id(
1534 top
, OspfEXT
.area_id
);
1536 exti
->area
= OspfEXT
.area
;
1538 lsa
.area
= exti
->area
;
1540 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1541 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1542 lsah
.id
.s_addr
= htonl(tmp
);
1545 case REORIGINATE_THIS_LSA
:
1546 ospf_opaque_lsa_reoriginate_schedule(
1547 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1548 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
1550 case REFRESH_THIS_LSA
:
1551 ospf_opaque_lsa_refresh_schedule(&lsa
);
1553 case FLUSH_THIS_LSA
:
1554 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1555 ospf_opaque_lsa_flush_schedule(&lsa
);
1558 zlog_warn("EXT (ospf_ext_link_lsa_schedule): Unknown opcode");
1565 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1566 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
)
1569 if (exti
->stype
== PREF_SID
)
1570 ospf_ext_pref_lsa_schedule(exti
, op
);
1572 ospf_ext_link_lsa_schedule(exti
, op
);
1575 /*------------------------------------------------------------------------*
1576 * Followings are vty show functions.
1577 *------------------------------------------------------------------------*/
1578 /* Cisco experimental SubTLV */
1579 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty
*vty
,
1580 struct tlv_header
*tlvh
)
1582 struct ext_subtlv_rmt_itf_addr
*top
;
1583 top
= (struct ext_subtlv_rmt_itf_addr
*)tlvh
;
1586 " Remote Interface Address Sub-TLV: Length %d\n "
1588 ntohs(top
->header
.length
), inet_ntoa(top
->value
));
1590 return TLV_SIZE(tlvh
);
1593 /* Adjacency SID SubTLV */
1594 static uint16_t show_vty_ext_link_adj_sid(struct vty
*vty
,
1595 struct tlv_header
*tlvh
)
1597 struct ext_subtlv_adj_sid
*top
= (struct ext_subtlv_adj_sid
*)tlvh
;
1600 " Adj-SID Sub-TLV: Length %d\n\tFlags: "
1601 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %d\n",
1602 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1603 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1605 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1606 ? GET_LABEL(ntohl(top
->value
))
1607 : ntohl(top
->value
));
1609 return TLV_SIZE(tlvh
);
1612 /* LAN Adjacency SubTLV */
1613 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty
*vty
,
1614 struct tlv_header
*tlvh
)
1616 struct ext_subtlv_lan_adj_sid
*top
=
1617 (struct ext_subtlv_lan_adj_sid
*)tlvh
;
1620 " LAN-Adj-SID Sub-TLV: Length %d\n\tFlags: "
1621 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: "
1622 "%s\n\tLabel: %d\n",
1623 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1624 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1626 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1627 ? GET_LABEL(ntohl(top
->value
))
1628 : ntohl(top
->value
));
1630 return TLV_SIZE(tlvh
);
1633 static uint16_t show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
)
1635 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1636 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
1638 return TLV_SIZE(tlvh
);
1641 /* Extended Link Sub TLVs */
1642 static uint16_t show_vty_link_info(struct vty
*vty
, struct tlv_header
*ext
)
1644 struct ext_tlv_link
*top
= (struct ext_tlv_link
*)ext
;
1645 struct tlv_header
*tlvh
;
1646 uint16_t length
= ntohs(top
->header
.length
) - 3 * sizeof(uint32_t);
1650 " Extended Link TLV: Length %d\n Link Type: 0x%x\n"
1652 ntohs(top
->header
.length
), top
->link_type
,
1653 inet_ntoa(top
->link_id
));
1654 vty_out(vty
, " Link data: %s\n", inet_ntoa(top
->link_data
));
1656 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1657 + EXT_TLV_LINK_SIZE
);
1658 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1659 switch (ntohs(tlvh
->type
)) {
1660 case EXT_SUBTLV_ADJ_SID
:
1661 sum
+= show_vty_ext_link_adj_sid(vty
, tlvh
);
1663 case EXT_SUBTLV_LAN_ADJ_SID
:
1664 sum
+= show_vty_ext_link_lan_adj_sid(vty
, tlvh
);
1666 case EXT_SUBTLV_RMT_ITF_ADDR
:
1667 sum
+= show_vty_ext_link_rmt_itf_addr(vty
, tlvh
);
1670 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1675 return sum
+ sizeof(struct ext_tlv_link
);
1678 /* Extended Link TLVs */
1679 static void ospf_ext_link_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1681 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
1682 struct tlv_header
*tlvh
;
1683 uint16_t length
= 0, sum
= 0;
1685 /* Initialize TLV browsing */
1686 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1688 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1689 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1690 switch (ntohs(tlvh
->type
)) {
1692 sum
+= show_vty_link_info(vty
, tlvh
);
1695 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1703 /* Prefix SID SubTLV */
1704 static uint16_t show_vty_ext_pref_pref_sid(struct vty
*vty
,
1705 struct tlv_header
*tlvh
)
1707 struct ext_subtlv_prefix_sid
*top
=
1708 (struct ext_subtlv_prefix_sid
*)tlvh
;
1711 " Prefix SID Sub-TLV: Length %d\n\tAlgorithm: "
1712 "%d\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %d\n",
1713 ntohs(top
->header
.length
), top
->algorithm
, top
->flags
,
1715 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
) ? "Label"
1717 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
)
1718 ? GET_LABEL(ntohl(top
->value
))
1719 : ntohl(top
->value
));
1721 return TLV_SIZE(tlvh
);
1724 /* Extended Prefix SubTLVs */
1725 static uint16_t show_vty_pref_info(struct vty
*vty
, struct tlv_header
*ext
)
1727 struct ext_tlv_prefix
*top
= (struct ext_tlv_prefix
*)ext
;
1728 struct tlv_header
*tlvh
;
1729 uint16_t length
= ntohs(top
->header
.length
) - 2 * sizeof(uint32_t);
1733 " Extended Prefix TLV: Length %d\n\tRoute Type: %d\n"
1734 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%d\n",
1735 ntohs(top
->header
.length
), top
->route_type
, top
->af
, top
->flags
,
1736 inet_ntoa(top
->address
), top
->pref_length
);
1738 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1739 + EXT_TLV_PREFIX_SIZE
);
1740 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1741 switch (ntohs(tlvh
->type
)) {
1742 case EXT_SUBTLV_PREFIX_SID
:
1743 sum
+= show_vty_ext_pref_pref_sid(vty
, tlvh
);
1746 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1751 return sum
+ sizeof(struct ext_tlv_prefix
);
1754 /* Extended Prefix TLVs */
1755 static void ospf_ext_pref_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1757 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
1758 struct tlv_header
*tlvh
;
1759 uint16_t length
= 0, sum
= 0;
1761 /* Initialize TLV browsing */
1762 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1764 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1765 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1766 switch (ntohs(tlvh
->type
)) {
1767 case EXT_TLV_PREFIX
:
1768 sum
+= show_vty_pref_info(vty
, tlvh
);
1771 sum
+= show_vty_unknown_tlv(vty
, tlvh
);