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 u_int32_t
get_ext_pref_instance_value(void)
210 static u_int32_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 u_int32_t
get_ext_link_instance_value(void)
223 static u_int32_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
, u_int8_t route_type
,
269 u_int8_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
, u_int8_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
, u_int8_t algorithm
,
298 u_int32_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
, u_int32_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
, u_int32_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
, u_int32_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
;
921 /* Create a stream for LSA. */
922 if ((s
= stream_new(OSPF_MAX_LSA_SIZE
)) == NULL
) {
923 zlog_warn("EXT: stream_new() error");
927 /* Prepare LSA Header */
928 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
930 lsa_type
= OspfEXT
.scope
;
932 /* LSA ID is a variable number identifying different instances of
933 * Extended Prefix Opaque LSA from the same router see RFC 7684 */
934 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
935 lsa_id
.s_addr
= htonl(tmp
);
937 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
939 /* Fix Options and Router ID depending of the flooding scope */
940 if ((OspfEXT
.scope
== OSPF_OPAQUE_AS_LSA
) || (area
== NULL
)) {
941 options
= OSPF_OPTION_E
;
942 struct ospf
*top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
943 router_id
= top
->router_id
;
945 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
946 options
|= LSA_OPTIONS_NSSA_GET(area
);
947 router_id
= area
->ospf
->router_id
;
950 /* Set opaque-LSA header fields. */
951 lsa_header_set(s
, options
, lsa_type
, lsa_id
, router_id
);
953 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
955 "EXT: LSA[Type%d:%s]: Create an Opaque-LSA/Extended "
956 "Prefix Opaque LSA instance",
957 lsa_type
, inet_ntoa(lsa_id
));
960 /* Set opaque-LSA body fields. */
961 ospf_ext_pref_lsa_body_set(s
, exti
);
964 length
= stream_get_endp(s
);
965 lsah
->length
= htons(length
);
967 /* Now, create an OSPF LSA instance. */
968 if ((new = ospf_lsa_new()) == NULL
) {
969 zlog_warn("EXT: ospf_lsa_new() error");
973 if ((new->data
= ospf_lsa_data_new(length
)) == NULL
) {
974 zlog_warn("EXT: ospf_lsa_data_new() error");
975 ospf_lsa_unlock(&new);
982 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
983 memcpy(new->data
, lsah
, length
);
989 /* Create new Extended Link opaque-LSA for every extended link TLV */
990 static struct ospf_lsa
*ospf_ext_link_lsa_new(struct ospf_area
*area
,
991 struct ext_itf
*exti
)
994 struct lsa_header
*lsah
;
995 struct ospf_lsa
*new = NULL
;
996 u_char options
, lsa_type
;
997 struct in_addr lsa_id
;
1001 /* Create a stream for LSA. */
1002 if ((s
= stream_new(OSPF_MAX_LSA_SIZE
)) == NULL
) {
1003 zlog_warn("EXT: stream_new() error");
1006 lsah
= (struct lsa_header
*)STREAM_DATA(s
);
1008 options
= OSPF_OPTION_O
; /* Don't forget this :-) */
1009 options
|= LSA_OPTIONS_GET(area
); /* Get area default option */
1010 options
|= LSA_OPTIONS_NSSA_GET(area
);
1011 /* Extended Link Opaque LSA are only flooded within an area */
1012 lsa_type
= OSPF_OPAQUE_AREA_LSA
;
1014 /* LSA ID is a variable number identifying different instances of
1015 * Extended Link Opaque LSA from the same router see RFC 7684 */
1016 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1017 lsa_id
.s_addr
= htonl(tmp
);
1019 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
))
1021 "EXT: LSA[Type%d:%s]: Create an Opaque-LSA/Extended "
1022 "Link Opaque LSA instance",
1023 lsa_type
, inet_ntoa(lsa_id
));
1025 /* Set opaque-LSA header fields. */
1026 lsa_header_set(s
, options
, lsa_type
, lsa_id
, area
->ospf
->router_id
);
1028 /* Set opaque-LSA body fields. */
1029 ospf_ext_link_lsa_body_set(s
, exti
);
1032 length
= stream_get_endp(s
);
1033 lsah
->length
= htons(length
);
1035 /* Now, create an OSPF LSA instance. */
1036 if ((new = ospf_lsa_new()) == NULL
) {
1037 zlog_warn("EXT: ospf_lsa_new() error");
1041 if ((new->data
= ospf_lsa_data_new(length
)) == NULL
) {
1042 zlog_warn("EXT: ospf_lsa_data_new() error");
1043 ospf_lsa_unlock(&new);
1050 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1051 memcpy(new->data
, lsah
, length
);
1057 /* Process the origination of an Extended Prefix Opaque LSA
1058 * for every extended prefix TLV */
1059 static int ospf_ext_pref_lsa_originate1(struct ospf_area
*area
,
1060 struct ext_itf
*exti
)
1062 struct ospf_lsa
*new;
1066 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1067 if ((new = ospf_ext_pref_lsa_new(area
, exti
)) == NULL
) {
1068 zlog_warn("EXT: ospf_ext_pref_lsa_new() error");
1072 /* Install this LSA into LSDB. */
1073 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1074 zlog_warn("EXT: ospf_lsa_install() error");
1075 ospf_lsa_unlock(&new);
1079 /* Now this Extended Prefix Opaque LSA info parameter entry has
1080 * associated LSA. */
1081 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1083 /* Update new LSA origination count. */
1084 area
->ospf
->lsa_originate_count
++;
1086 /* Flood new LSA through area. */
1087 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1089 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1090 char area_id
[INET_ADDRSTRLEN
];
1091 strncpy(area_id
, inet_ntoa(area
->area_id
), INET_ADDRSTRLEN
);
1093 "EXT: LSA[Type%d:%s]: Originate Opaque-LSA/Extended "
1094 "Prefix Opaque LSA: Area(%s), Link(%s)",
1095 new->data
->type
, inet_ntoa(new->data
->id
), area_id
,
1097 ospf_lsa_header_dump(new->data
);
1105 /* Process the origination of an Extended Link Opaque LSA
1106 * for every extended link TLV */
1107 static int ospf_ext_link_lsa_originate1(struct ospf_area
*area
,
1108 struct ext_itf
*exti
)
1110 struct ospf_lsa
*new;
1113 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1114 if ((new = ospf_ext_link_lsa_new(area
, exti
)) == NULL
) {
1115 zlog_warn("EXT: ospf_ext_link_lsa_new() error");
1119 /* Install this LSA into LSDB. */
1120 if (ospf_lsa_install(area
->ospf
, NULL
/*oi */, new) == NULL
) {
1121 zlog_warn("EXT: ospf_lsa_install() error");
1122 ospf_lsa_unlock(&new);
1126 /* Now this link-parameter entry has associated LSA. */
1127 SET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1129 /* Update new LSA origination count. */
1130 area
->ospf
->lsa_originate_count
++;
1132 /* Flood new LSA through area. */
1133 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1135 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1136 char area_id
[INET_ADDRSTRLEN
];
1137 strncpy(area_id
, inet_ntoa(area
->area_id
), INET_ADDRSTRLEN
);
1139 "EXT: LSA[Type%d:%s]: Originate Opaque-LSA/Extended "
1140 "Link Opaque LSA: Area(%s), Link(%s)",
1141 new->data
->type
, inet_ntoa(new->data
->id
), area_id
,
1143 ospf_lsa_header_dump(new->data
);
1151 /* Trigger the origination of Extended Prefix Opaque LSAs */
1152 static int ospf_ext_pref_lsa_originate(void *arg
)
1154 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1155 struct listnode
*node
;
1156 struct ext_itf
*exti
;
1159 if (!OspfEXT
.enabled
) {
1161 "EXT: Segment Routing "
1162 "functionality is Disabled now.");
1163 rc
= 0; /* This is not an error case. */
1166 if (IS_DEBUG_OSPF_SR
)
1168 "EXT (ospf_ext_pref_lsa_originate) "
1169 "Start Originate Prefix LSA for area %s",
1170 inet_ntoa(area
->area_id
));
1172 /* Check if Extended Prefix Opaque LSA is already engaged */
1173 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1175 /* Process only Prefix SID */
1176 if (exti
->stype
!= PREF_SID
)
1179 /* Process only Extended Prefix with valid Area ID */
1180 if ((exti
->area
== NULL
)
1181 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1184 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1185 if (CHECK_FLAG(exti
->flags
,
1186 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1187 zlog_warn("EXT: Refresh instead of Originate");
1188 UNSET_FLAG(exti
->flags
,
1189 EXT_LPFLG_LSA_FORCED_REFRESH
);
1190 ospf_ext_pref_lsa_schedule(exti
,
1196 /* Ok, let's try to originate an LSA */
1197 if (IS_DEBUG_OSPF_SR
)
1199 "EXT: Let's finally reoriginate the "
1200 "LSA 7.0.0.%d for Itf %s",
1202 exti
->ifp
? exti
->ifp
->name
: "");
1203 ospf_ext_pref_lsa_originate1(area
, exti
);
1210 /* Trigger the origination of Extended Link Opaque LSAs */
1211 static int ospf_ext_link_lsa_originate(void *arg
)
1213 struct ospf_area
*area
= (struct ospf_area
*)arg
;
1214 struct listnode
*node
;
1215 struct ext_itf
*exti
;
1218 if (!OspfEXT
.enabled
) {
1220 "EXT: Segment Routing "
1221 "functionality is Disabled now.");
1222 rc
= 0; /* This is not an error case. */
1226 /* Check if Extended Prefix Opaque LSA is already engaged */
1227 for (ALL_LIST_ELEMENTS_RO(OspfEXT
.iflist
, node
, exti
)) {
1228 /* Process only Adjacency or LAN SID */
1229 if (exti
->stype
== PREF_SID
)
1232 /* Process only Extended Link with valid Area ID */
1233 if ((exti
->area
== NULL
)
1234 || (!IPV4_ADDR_SAME(&exti
->area
->area_id
, &area
->area_id
)))
1237 /* Check if LSA not already engaged */
1238 if (CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
)) {
1239 if (CHECK_FLAG(exti
->flags
,
1240 EXT_LPFLG_LSA_FORCED_REFRESH
)) {
1241 zlog_warn("EXT: Refresh instead of Originate");
1242 UNSET_FLAG(exti
->flags
,
1243 EXT_LPFLG_LSA_FORCED_REFRESH
);
1244 ospf_ext_link_lsa_schedule(exti
,
1250 /* Ok, let's try to originate an LSA */
1251 if (IS_DEBUG_OSPF_SR
)
1253 "EXT Let's finally reoriginate the "
1254 "LSA 8.0.0.%d for Itf %s through the Area %s",
1256 exti
->ifp
? exti
->ifp
->name
: "-",
1257 inet_ntoa(area
->area_id
));
1258 ospf_ext_link_lsa_originate1(area
, exti
);
1265 /* Refresh an Extended Prefix Opaque LSA */
1266 static struct ospf_lsa
*ospf_ext_pref_lsa_refresh(struct ospf_lsa
*lsa
)
1268 struct ospf_lsa
*new = NULL
;
1269 struct ospf_area
*area
= lsa
->area
;
1271 struct ext_itf
*exti
;
1273 if (!OspfEXT
.enabled
) {
1275 * This LSA must have flushed before due to Extended Prefix
1276 * Opaque LSA status change.
1277 * It seems a slip among routers in the routing domain.
1279 zlog_info("EXT: Segment Routing functionality is Disabled");
1280 /* Flush it anyway. */
1281 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1284 /* Lookup this lsa corresponding Extended parameters */
1285 if ((exti
= lookup_ext_by_instance(lsa
)) == NULL
) {
1286 zlog_warn("EXT: Invalid parameter LSA ID");
1287 /* Flush it anyway. */
1288 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1291 /* Check if Interface was not disable in the interval */
1292 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1293 zlog_warn("EXT: Interface was Disabled: Flush it!");
1294 /* Flush it anyway. */
1295 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1298 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1299 if (IS_LSA_MAXAGE(lsa
)) {
1301 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1302 ospf_opaque_lsa_flush_schedule(lsa
);
1306 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1308 new = ospf_ext_pref_lsa_new(area
, exti
);
1311 zlog_warn("EXT: ospf_ext_pref_lsa_new() error");
1314 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1316 /* Install this LSA into LSDB. */
1317 /* Given "lsa" will be freed in the next function. */
1318 /* As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1319 * ospf_lookup() to get ospf instance */
1323 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1325 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1326 zlog_warn("EXT: ospf_lsa_install() error");
1327 ospf_lsa_unlock(&new);
1331 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1332 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1334 /* Debug logging. */
1335 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1336 zlog_debug("EXT: LSA[Type%d:%s]: Refresh Extended Prefix LSA",
1337 new->data
->type
, inet_ntoa(new->data
->id
));
1338 ospf_lsa_header_dump(new->data
);
1344 /* Refresh an Extended Link Opaque LSA */
1345 static struct ospf_lsa
*ospf_ext_link_lsa_refresh(struct ospf_lsa
*lsa
)
1347 struct ext_itf
*exti
;
1348 struct ospf_area
*area
= lsa
->area
;
1349 struct ospf
*top
= area
->ospf
;
1350 struct ospf_lsa
*new = NULL
;
1352 if (!OspfEXT
.enabled
) {
1354 * This LSA must have flushed before due to OSPF-SR status
1355 * change. It seems a slip among routers in the routing domain.
1358 "EXT (ospf_ext_link_lsa_refresh): Segment Routing "
1359 "functionality is Disabled");
1360 /* Flush it anyway. */
1361 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1364 /* Lookup this lsa corresponding Extended parameters */
1365 if ((exti
= lookup_ext_by_instance(lsa
)) == NULL
) {
1367 "EXT (ospf_ext_link_lsa_refresh): Invalid parameter "
1369 /* Flush it anyway. */
1370 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1373 /* Check if Interface was not disable in the interval */
1374 if ((exti
!= NULL
) && !CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)) {
1376 "EXT (ospf_ext_link_lsa_refresh): Interface was "
1377 "Disabled: Flush it!");
1378 lsa
->data
->ls_age
= htons(OSPF_LSA_MAXAGE
);
1381 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1382 if (IS_LSA_MAXAGE(lsa
)) {
1384 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1385 ospf_opaque_lsa_flush_schedule(lsa
);
1389 /* Create new Opaque-LSA/MPLS-TE instance. */
1390 if ((new = ospf_ext_link_lsa_new(area
, exti
)) == NULL
) {
1392 "EXT (ospf_ext_link_lsa_refresh): Error creating "
1396 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1398 /* Install this LSA into LSDB. */
1399 /* Given "lsa" will be freed in the next function. */
1400 if (ospf_lsa_install(top
, NULL
/*oi */, new) == NULL
) {
1402 "EXT (ospf_ext_link_lsa_refresh): Error installing "
1404 ospf_lsa_unlock(&new);
1408 /* Flood updated LSA through the link Area according to the RFC7684 */
1409 ospf_flood_through_area(area
, NULL
/*nbr */, new);
1411 /* Debug logging. */
1412 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1414 "EXT (ospf_ext_link_lsa_refresh): LSA[Type%d:%s]: "
1415 "Refresh Extended Link LSA",
1416 new->data
->type
, inet_ntoa(new->data
->id
));
1417 ospf_lsa_header_dump(new->data
);
1423 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1424 static void ospf_ext_pref_lsa_schedule(struct ext_itf
*exti
,
1425 enum lsa_opcode opcode
)
1427 struct ospf_lsa lsa
;
1428 struct lsa_header lsah
;
1432 memset(&lsa
, 0, sizeof(lsa
));
1433 memset(&lsah
, 0, sizeof(lsah
));
1439 /* Check if the corresponding link is ready to be flooded */
1440 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1444 "EXT (ospf_ext_pref_lsa_schedule): Schedule %s%s%s LSA "
1446 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1447 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1448 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1449 exti
->ifp
? exti
->ifp
->name
: "-");
1451 /* Set LSA header information */
1452 if (exti
->area
== NULL
) {
1454 "EXT (ospf_ext_pref_lsa_schedule): Flooding is "
1455 "Area scope but area is not yet set");
1456 if (OspfEXT
.area
== NULL
) {
1457 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1458 OspfEXT
.area
= ospf_area_lookup_by_area_id(
1459 top
, OspfEXT
.area_id
);
1461 exti
->area
= OspfEXT
.area
;
1463 lsa
.area
= exti
->area
;
1465 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1466 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA
, exti
->instance
);
1467 lsah
.id
.s_addr
= htonl(tmp
);
1470 case REORIGINATE_THIS_LSA
:
1471 ospf_opaque_lsa_reoriginate_schedule(
1472 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1473 OPAQUE_TYPE_EXTENDED_PREFIX_LSA
);
1475 case REFRESH_THIS_LSA
:
1476 ospf_opaque_lsa_refresh_schedule(&lsa
);
1478 case FLUSH_THIS_LSA
:
1479 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1480 ospf_opaque_lsa_flush_schedule(&lsa
);
1483 zlog_warn("EXT (ospf_ext_pref_lsa_schedule): Unknown opcode");
1490 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1491 static void ospf_ext_link_lsa_schedule(struct ext_itf
*exti
,
1492 enum lsa_opcode opcode
)
1494 struct ospf_lsa lsa
;
1495 struct lsa_header lsah
;
1499 memset(&lsa
, 0, sizeof(lsa
));
1500 memset(&lsah
, 0, sizeof(lsah
));
1506 /* Check if the corresponding link is ready to be flooded */
1507 if (!(CHECK_FLAG(exti
->flags
, EXT_LPFLG_LSA_ACTIVE
)))
1511 "EXT (ospf_ext_link_lsa_schedule): Schedule %s%s%s LSA "
1513 opcode
== REORIGINATE_THIS_LSA
? "Re-Originate" : "",
1514 opcode
== REFRESH_THIS_LSA
? "Refresh" : "",
1515 opcode
== FLUSH_THIS_LSA
? "Flush" : "",
1516 exti
->ifp
? exti
->ifp
->name
: "-");
1518 /* Set LSA header information */
1519 if (exti
->area
== NULL
) {
1521 "EXT (ospf_ext_link_lsa_schedule): Flooding is "
1522 "Area scope but area is not yet set");
1523 if (OspfEXT
.area
== NULL
) {
1524 top
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1525 OspfEXT
.area
= ospf_area_lookup_by_area_id(
1526 top
, OspfEXT
.area_id
);
1528 exti
->area
= OspfEXT
.area
;
1530 lsa
.area
= exti
->area
;
1532 lsah
.type
= OSPF_OPAQUE_AREA_LSA
;
1533 tmp
= SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA
, exti
->instance
);
1534 lsah
.id
.s_addr
= htonl(tmp
);
1537 case REORIGINATE_THIS_LSA
:
1538 ospf_opaque_lsa_reoriginate_schedule(
1539 (void *)exti
->area
, OSPF_OPAQUE_AREA_LSA
,
1540 OPAQUE_TYPE_EXTENDED_LINK_LSA
);
1542 case REFRESH_THIS_LSA
:
1543 ospf_opaque_lsa_refresh_schedule(&lsa
);
1545 case FLUSH_THIS_LSA
:
1546 UNSET_FLAG(exti
->flags
, EXT_LPFLG_LSA_ENGAGED
);
1547 ospf_opaque_lsa_flush_schedule(&lsa
);
1550 zlog_warn("EXT (ospf_ext_link_lsa_schedule): Unknown opcode");
1557 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1558 static void ospf_ext_lsa_schedule(struct ext_itf
*exti
, enum lsa_opcode op
)
1561 if (exti
->stype
== PREF_SID
)
1562 ospf_ext_pref_lsa_schedule(exti
, op
);
1564 ospf_ext_link_lsa_schedule(exti
, op
);
1567 /*------------------------------------------------------------------------*
1568 * Followings are vty show functions.
1569 *------------------------------------------------------------------------*/
1570 /* Cisco experimental SubTLV */
1571 static u_int16_t
show_vty_ext_link_rmt_itf_addr(struct vty
*vty
,
1572 struct tlv_header
*tlvh
)
1574 struct ext_subtlv_rmt_itf_addr
*top
;
1575 top
= (struct ext_subtlv_rmt_itf_addr
*)tlvh
;
1578 " Remote Interface Address Sub-TLV: Length %d\n "
1580 ntohs(top
->header
.length
), inet_ntoa(top
->value
));
1582 return TLV_SIZE(tlvh
);
1585 /* Adjacency SID SubTLV */
1586 static u_int16_t
show_vty_ext_link_adj_sid(struct vty
*vty
,
1587 struct tlv_header
*tlvh
)
1589 struct ext_subtlv_adj_sid
*top
= (struct ext_subtlv_adj_sid
*)tlvh
;
1592 " Adj-SID Sub-TLV: Length %d\n\tFlags: "
1593 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %d\n",
1594 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1595 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1597 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1598 ? GET_LABEL(ntohl(top
->value
))
1599 : ntohl(top
->value
));
1601 return TLV_SIZE(tlvh
);
1604 /* LAN Adjacency SubTLV */
1605 static u_int16_t
show_vty_ext_link_lan_adj_sid(struct vty
*vty
,
1606 struct tlv_header
*tlvh
)
1608 struct ext_subtlv_lan_adj_sid
*top
=
1609 (struct ext_subtlv_lan_adj_sid
*)tlvh
;
1612 " LAN-Adj-SID Sub-TLV: Length %d\n\tFlags: "
1613 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: "
1614 "%s\n\tLabel: %d\n",
1615 ntohs(top
->header
.length
), top
->flags
, top
->mtid
, top
->weight
,
1616 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
) ? "Label"
1618 CHECK_FLAG(top
->flags
, EXT_SUBTLV_LINK_ADJ_SID_VFLG
)
1619 ? GET_LABEL(ntohl(top
->value
))
1620 : ntohl(top
->value
));
1622 return TLV_SIZE(tlvh
);
1625 static u_int16_t
show_vty_unknown_tlv(struct vty
*vty
, struct tlv_header
*tlvh
)
1627 vty_out(vty
, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1628 ntohs(tlvh
->type
), ntohs(tlvh
->length
));
1630 return TLV_SIZE(tlvh
);
1633 /* Extended Link Sub TLVs */
1634 static u_int16_t
show_vty_link_info(struct vty
*vty
, struct tlv_header
*ext
)
1636 struct ext_tlv_link
*top
= (struct ext_tlv_link
*)ext
;
1637 struct tlv_header
*tlvh
;
1638 u_int16_t length
= ntohs(top
->header
.length
) - 3 * sizeof(u_int32_t
);
1642 " Extended Link TLV: Length %d\n Link Type: 0x%x\n"
1644 ntohs(top
->header
.length
), top
->link_type
,
1645 inet_ntoa(top
->link_id
));
1646 vty_out(vty
, " Link data: %s\n", inet_ntoa(top
->link_data
));
1648 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1649 + EXT_TLV_LINK_SIZE
);
1650 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1651 switch (ntohs(tlvh
->type
)) {
1652 case EXT_SUBTLV_ADJ_SID
:
1653 sum
+= show_vty_ext_link_adj_sid(vty
, tlvh
);
1655 case EXT_SUBTLV_LAN_ADJ_SID
:
1656 sum
+= show_vty_ext_link_lan_adj_sid(vty
, tlvh
);
1658 case EXT_SUBTLV_RMT_ITF_ADDR
:
1659 sum
+= show_vty_ext_link_rmt_itf_addr(vty
, tlvh
);
1662 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1667 return sum
+ sizeof(struct ext_tlv_link
);
1670 /* Extended Link TLVs */
1671 static void ospf_ext_link_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1673 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
1674 struct tlv_header
*tlvh
;
1675 u_int16_t length
= 0, sum
= 0;
1677 /* Initialize TLV browsing */
1678 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1680 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1681 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1682 switch (ntohs(tlvh
->type
)) {
1684 sum
+= show_vty_link_info(vty
, tlvh
);
1687 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1695 /* Prefix SID SubTLV */
1696 static u_int16_t
show_vty_ext_pref_pref_sid(struct vty
*vty
,
1697 struct tlv_header
*tlvh
)
1699 struct ext_subtlv_prefix_sid
*top
=
1700 (struct ext_subtlv_prefix_sid
*)tlvh
;
1703 " Prefix SID Sub-TLV: Length %d\n\tAlgorithm: "
1704 "%d\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %d\n",
1705 ntohs(top
->header
.length
), top
->algorithm
, top
->flags
,
1707 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
) ? "Label"
1709 CHECK_FLAG(top
->flags
, EXT_SUBTLV_PREFIX_SID_VFLG
)
1710 ? GET_LABEL(ntohl(top
->value
))
1711 : ntohl(top
->value
));
1713 return TLV_SIZE(tlvh
);
1716 /* Extended Prefix SubTLVs */
1717 static u_int16_t
show_vty_pref_info(struct vty
*vty
, struct tlv_header
*ext
)
1719 struct ext_tlv_prefix
*top
= (struct ext_tlv_prefix
*)ext
;
1720 struct tlv_header
*tlvh
;
1721 u_int16_t length
= ntohs(top
->header
.length
) - 2 * sizeof(u_int32_t
);
1725 " Extended Prefix TLV: Length %d\n\tRoute Type: %d\n"
1726 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%d\n",
1727 ntohs(top
->header
.length
), top
->route_type
, top
->af
, top
->flags
,
1728 inet_ntoa(top
->address
), top
->pref_length
);
1730 tlvh
= (struct tlv_header
*)((char *)(ext
) + TLV_HDR_SIZE
1731 + EXT_TLV_PREFIX_SIZE
);
1732 for (; sum
< length
; tlvh
= TLV_HDR_NEXT(tlvh
)) {
1733 switch (ntohs(tlvh
->type
)) {
1734 case EXT_SUBTLV_PREFIX_SID
:
1735 sum
+= show_vty_ext_pref_pref_sid(vty
, tlvh
);
1738 sum
+= show_vty_unknown_tlv(vty
, tlvh
);
1743 return sum
+ sizeof(struct ext_tlv_prefix
);
1746 /* Extended Prefix TLVs */
1747 static void ospf_ext_pref_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
1749 struct lsa_header
*lsah
= (struct lsa_header
*)lsa
->data
;
1750 struct tlv_header
*tlvh
;
1751 u_int16_t length
= 0, sum
= 0;
1753 /* Initialize TLV browsing */
1754 length
= ntohs(lsah
->length
) - OSPF_LSA_HEADER_SIZE
;
1756 for (tlvh
= TLV_HDR_TOP(lsah
); sum
< length
;
1757 tlvh
= TLV_HDR_NEXT(tlvh
)) {
1758 switch (ntohs(tlvh
->type
)) {
1759 case EXT_TLV_PREFIX
:
1760 sum
+= show_vty_pref_info(vty
, tlvh
);
1763 sum
+= show_vty_unknown_tlv(vty
, tlvh
);