]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_ext.c
ospfd: Convert ospf_ext.c to use new error-code subsystem
[mirror_frr.git] / ospfd / ospf_ext.c
1 /*
2 * This is an implementation of RFC7684 OSPFv2 Prefix/Link Attribute
3 * Advertisement
4 *
5 * Module name: Extended Prefix/Link Opaque LSA
6 *
7 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
8 * Author: Anselme Sawadogo <anselmesawadogo@gmail.com>
9 *
10 * Copyright (C) 2016 - 2018 Orange Labs http://www.orange.com
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; see the file COPYING; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include <zebra.h>
28 #include <math.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31
32 #include "linklist.h"
33 #include "prefix.h"
34 #include "if.h"
35 #include "table.h"
36 #include "memory.h"
37 #include "command.h"
38 #include "vty.h"
39 #include "stream.h"
40 #include "log.h"
41 #include "thread.h"
42 #include "hash.h"
43 #include "sockunion.h" /* for inet_aton() */
44 #include "network.h"
45 #include "if.h"
46 #include "libospf.h" /* for ospf interface types */
47
48 #include "ospfd/ospfd.h"
49 #include "ospfd/ospf_interface.h"
50 #include "ospfd/ospf_ism.h"
51 #include "ospfd/ospf_asbr.h"
52 #include "ospfd/ospf_lsa.h"
53 #include "ospfd/ospf_lsdb.h"
54 #include "ospfd/ospf_neighbor.h"
55 #include "ospfd/ospf_nsm.h"
56 #include "ospfd/ospf_flood.h"
57 #include "ospfd/ospf_packet.h"
58 #include "ospfd/ospf_spf.h"
59 #include "ospfd/ospf_dump.h"
60 #include "ospfd/ospf_route.h"
61 #include "ospfd/ospf_ase.h"
62 #include "ospfd/ospf_zebra.h"
63 #include "ospfd/ospf_sr.h"
64 #include "ospfd/ospf_ext.h"
65 #include "ospfd/ospf_errors.h"
66
67 /* Following structure are internal use only. */
68
69 /*
70 * Global variable to manage Extended Prefix/Link Opaque LSA on this node.
71 * Note that all parameter values are stored in network byte order.
72 */
73 static struct ospf_ext_lp OspfEXT;
74
75 /*
76 * -----------------------------------------------------------------------
77 * Followings are initialize/terminate functions for Extended Prefix/Link
78 * Opaque LSA handling.
79 * -----------------------------------------------------------------------
80 */
81
82 /* Extended Prefix Opaque LSA related callback functions */
83 static void ospf_ext_pref_ism_change(struct ospf_interface *oi, int old_status);
84 static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa);
85 static int ospf_ext_pref_lsa_originate(void *arg);
86 static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa);
87 static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
88 enum lsa_opcode opcode);
89 /* Extended Link Opaque LSA related callback functions */
90 static int ospf_ext_link_new_if(struct interface *ifp);
91 static int ospf_ext_link_del_if(struct interface *ifp);
92 static void ospf_ext_link_ism_change(struct ospf_interface *oi, int old_status);
93 static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status);
94 static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa);
95 static int ospf_ext_link_lsa_originate(void *arg);
96 static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa);
97 static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
98 enum lsa_opcode opcode);
99 static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op);
100 static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa);
101 static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa);
102 static void del_ext_info(void *val);
103
104 /*
105 * Extended Link/Prefix initialization
106 *
107 * @param - none
108 *
109 * @return - 0 if OK, <> 0 otherwise
110 */
111 int ospf_ext_init(void)
112 {
113 int rc = 0;
114
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;
122
123 zlog_info("EXT (%s): Register Extended Link Opaque LSA", __func__);
124 rc = ospf_register_opaque_functab(
125 OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_EXTENDED_LINK_LSA,
126 ospf_ext_link_new_if, /* new if */
127 ospf_ext_link_del_if, /* del if */
128 ospf_ext_link_ism_change, /* ism change */
129 ospf_ext_link_nsm_change, /* nsm change */
130 NULL, /* Write router config. */
131 NULL, /* Write interface conf. */
132 NULL, /* Write debug config. */
133 ospf_ext_link_show_info, /* Show LSA info */
134 ospf_ext_link_lsa_originate, /* Originate LSA */
135 ospf_ext_link_lsa_refresh, /* Refresh LSA */
136 ospf_ext_link_lsa_update, /* new_lsa_hook */
137 NULL); /* del_lsa_hook */
138
139 if (rc != 0) {
140 flog_warn(OSPF_WARN_OPAQUE_REGISTRATION,
141 "EXT (%s): Failed to register Extended Link LSA",
142 __func__);
143 return rc;
144 }
145
146 zlog_info("EXT (%s): Register Extended Prefix Opaque LSA", __func__);
147 rc = ospf_register_opaque_functab(
148 OspfEXT.scope, OPAQUE_TYPE_EXTENDED_PREFIX_LSA,
149 NULL, /* new if handle by link */
150 NULL, /* del if handle by link */
151 ospf_ext_pref_ism_change, /* ism change */
152 NULL, /* nsm change */
153 ospf_sr_config_write_router, /* Write router config. */
154 NULL, /* Write interface conf. */
155 NULL, /* Write debug config. */
156 ospf_ext_pref_show_info, /* Show LSA info */
157 ospf_ext_pref_lsa_originate, /* Originate LSA */
158 ospf_ext_pref_lsa_refresh, /* Refresh LSA */
159 ospf_ext_pref_lsa_update, /* new_lsa_hook */
160 NULL); /* del_lsa_hook */
161 if (rc != 0) {
162 flog_warn(OSPF_WARN_OPAQUE_REGISTRATION,
163 "EXT (%s): Failed to register Extended Prefix LSA",
164 __func__);
165 return rc;
166 }
167
168 return rc;
169 }
170
171 /*
172 * Extended Link/Prefix termination function
173 *
174 * @param - none
175 * @return - none
176 */
177 void ospf_ext_term(void)
178 {
179
180 if ((OspfEXT.scope == OSPF_OPAQUE_AREA_LSA)
181 || (OspfEXT.scope == OSPF_OPAQUE_AS_LSA))
182 ospf_delete_opaque_functab(OspfEXT.scope,
183 OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
184
185 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA,
186 OPAQUE_TYPE_EXTENDED_LINK_LSA);
187
188 list_delete_and_null(&OspfEXT.iflist);
189 OspfEXT.scope = 0;
190 OspfEXT.enabled = false;
191
192 return;
193 }
194
195 /*
196 * Extended Link/Prefix finish function
197 *
198 * @param - none
199 * @return - none
200 */
201 void ospf_ext_finish(void)
202 {
203 // list_delete_all_node(OspfEXT.iflist);
204 OspfEXT.enabled = false;
205 }
206
207 /*
208 * ---------------------------------------------------------------------
209 * Followings are control functions for Extended Prefix/Link Opaque LSA
210 * parameters management.
211 * ---------------------------------------------------------------------
212 */
213
214 /* Functions to free memory space */
215 static void del_ext_info(void *val)
216 {
217 XFREE(MTYPE_OSPF_EXT_PARAMS, val);
218 }
219
220 /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
221 static uint32_t get_ext_pref_instance_value(void)
222 {
223 static uint32_t seqno = 0;
224
225 if (seqno < MAX_LEGAL_EXT_INSTANCE_NUM)
226 seqno += 1;
227 else
228 seqno = 1; /* Avoid zero. */
229
230 return seqno;
231 }
232
233 /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */
234 static uint32_t get_ext_link_instance_value(void)
235 {
236 static uint32_t seqno = 0;
237
238 if (seqno < MAX_LEGAL_EXT_INSTANCE_NUM)
239 seqno += 1;
240 else
241 seqno = 1; /* Avoid zero. */
242
243 return seqno;
244 }
245
246 /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
247 static struct ext_itf *lookup_ext_by_ifp(struct interface *ifp)
248 {
249 struct listnode *node, *nnode;
250 struct ext_itf *exti;
251
252 for (ALL_LIST_ELEMENTS(OspfEXT.iflist, node, nnode, exti))
253 if (exti->ifp == ifp)
254 return exti;
255
256 return NULL;
257 }
258
259 /* Lookup Extended Prefix/Links by LSA ID from OspfEXT struct iflist */
260 static struct ext_itf *lookup_ext_by_instance(struct ospf_lsa *lsa)
261 {
262 struct listnode *node;
263 struct ext_itf *exti;
264 uint32_t key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr));
265 uint8_t type = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr));
266
267
268 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
269 if ((exti->instance == key) && (exti->type == type))
270 return exti;
271
272 return NULL;
273 }
274
275 /*
276 * ----------------------------------------------------------------------
277 * The underlying subsection defines setters and unsetters to create and
278 * delete tlvs and subtlvs
279 * ----------------------------------------------------------------------
280 */
281
282 /* Extended Prefix TLV - RFC7684 section 2.1 */
283 static void set_ext_prefix(struct ext_itf *exti, uint8_t route_type,
284 uint8_t flags, struct prefix_ipv4 p)
285 {
286
287 TLV_TYPE(exti->prefix) = htons(EXT_TLV_PREFIX);
288 /* Warning: Size must be adjust depending of subTLV's */
289 TLV_LEN(exti->prefix) = htons(EXT_TLV_PREFIX_SIZE);
290 exti->prefix.route_type = route_type;
291 exti->prefix.flags = flags;
292 /* Only Address Family Ipv4 (0) is defined in RFC 7684 */
293 exti->prefix.af = 0;
294 exti->prefix.pref_length = p.prefixlen;
295 exti->prefix.address = p.prefix;
296 }
297
298 /* Extended Link TLV - RFC7684 section 3.1 */
299 static void set_ext_link(struct ext_itf *exti, uint8_t type, struct in_addr id,
300 struct in_addr data)
301 {
302
303 TLV_TYPE(exti->link) = htons(EXT_TLV_LINK);
304 /* Warning: Size must be adjust depending of subTLV's */
305 TLV_LEN(exti->link) = htons(EXT_TLV_LINK_SIZE);
306 exti->link.link_type = type;
307 exti->link.link_id = id;
308 exti->link.link_data = data;
309 }
310
311 /* Prefix SID SubTLV - section 5 */
312 static void set_prefix_sid(struct ext_itf *exti, uint8_t algorithm,
313 uint32_t value, int value_type, uint8_t flags)
314 {
315
316 if ((algorithm != SR_ALGORITHM_SPF)
317 && (algorithm != SR_ALGORITHM_STRICT_SPF)) {
318 flog_err(OSPF_ERR_INVALID_ALGORITHM,
319 "EXT (%s): unrecognized algorithm, not SPF or S-SPF",
320 __func__);
321 return;
322 }
323
324 /* Update flags according to the type of value field: label or index */
325 if (value_type == SID_LABEL)
326 SET_FLAG(flags, EXT_SUBTLV_PREFIX_SID_VFLG);
327
328 /* set prefix sid subtlv for an extended prefix tlv */
329 TLV_TYPE(exti->node_sid) = htons(EXT_SUBTLV_PREFIX_SID);
330 exti->node_sid.algorithm = algorithm;
331 exti->node_sid.flags = flags;
332 exti->node_sid.mtid = 0; /* Multi-Topology is not supported */
333
334 /* Set Label or Index value */
335 if (value_type == SID_LABEL) {
336 TLV_LEN(exti->node_sid) =
337 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE));
338 exti->node_sid.value = htonl(SET_LABEL(value));
339 } else {
340 TLV_LEN(exti->node_sid) =
341 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE));
342 exti->node_sid.value = htonl(value);
343 }
344 }
345
346 /* Adjacency SID SubTLV - section 6.1 */
347 static void set_adj_sid(struct ext_itf *exti, bool backup, uint32_t value,
348 int value_type)
349 {
350 int index;
351 uint8_t flags;
352
353 /* Determine which ADJ_SID must be set: nominal or backup */
354 if (backup) {
355 flags = EXT_SUBTLV_LINK_ADJ_SID_BFLG;
356 index = 1;
357 } else {
358 index = 0;
359 flags = 0;
360 }
361
362 /* Set Header */
363 TLV_TYPE(exti->adj_sid[index]) = htons(EXT_SUBTLV_ADJ_SID);
364
365 /* Only Local ADJ-SID is supported for the moment */
366 SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_LFLG);
367
368 exti->adj_sid[index].mtid = 0; /* Multi-Topology is not supported */
369
370 /* Adjust Length, Flags and Value depending on the type of Label */
371 if (value_type == SID_LABEL) {
372 SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
373 TLV_LEN(exti->adj_sid[index]) =
374 htons(SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE));
375 exti->adj_sid[index].value = htonl(SET_LABEL(value));
376 } else {
377 UNSET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
378 TLV_LEN(exti->adj_sid[index]) =
379 htons(SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE));
380 exti->adj_sid[index].value = htonl(value);
381 }
382
383 exti->adj_sid[index].flags = flags; /* Set computed flags */
384 exti->adj_sid[index].mtid = 0; /* Multi-Topology is not supported */
385 exti->adj_sid[index].weight = 0; /* Load-Balancing is not supported */
386 }
387
388 /* LAN Adjacency SID SubTLV - section 6.2 */
389 static void set_lan_adj_sid(struct ext_itf *exti, bool backup, uint32_t value,
390 int value_type, struct in_addr neighbor_id)
391 {
392
393 int index;
394 uint8_t flags;
395
396 /* Determine which ADJ_SID must be set: nominal or backup */
397 if (backup) {
398 flags = EXT_SUBTLV_LINK_ADJ_SID_BFLG;
399 index = 1;
400 } else {
401 index = 0;
402 flags = 0;
403 }
404
405 /* Set Header */
406 TLV_TYPE(exti->lan_sid[index]) = htons(EXT_SUBTLV_LAN_ADJ_SID);
407
408 /* Only Local ADJ-SID is supported for the moment */
409 SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_LFLG);
410
411 /* Adjust Length, Flags and Value depending on the type of Label */
412 if (value_type == SID_LABEL) {
413 SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
414 TLV_LEN(exti->lan_sid[index]) =
415 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE));
416 exti->lan_sid[index].value = htonl(SET_LABEL(value));
417 } else {
418 UNSET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
419 TLV_LEN(exti->lan_sid[index]) =
420 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE));
421 exti->lan_sid[index].value = htonl(value);
422 }
423
424 exti->lan_sid[index].flags = flags; /* Set computed flags */
425 exti->lan_sid[index].mtid = 0; /* Multi-Topology is not supported */
426 exti->lan_sid[index].weight = 0; /* Load-Balancing is not supported */
427 exti->lan_sid[index].neighbor_id = neighbor_id;
428 }
429
430 /* Experimental SubTLV from Cisco */
431 static void set_rmt_itf_addr(struct ext_itf *exti, struct in_addr rmtif)
432 {
433
434 TLV_TYPE(exti->rmt_itf_addr) = htons(EXT_SUBTLV_RMT_ITF_ADDR);
435 TLV_LEN(exti->rmt_itf_addr) = htons(sizeof(struct in_addr));
436 exti->rmt_itf_addr.value = rmtif;
437 }
438
439 /*
440 * Update Extended prefix SID index for Loopback interface type
441 *
442 * @param ifname - Loopback interface name
443 * @param index - new value for the prefix SID of this interface
444 * @param p - prefix for this interface or NULL if Extended Prefix
445 * should be remove
446 *
447 * @return instance number if update is OK, 0 otherwise
448 */
449 uint32_t ospf_ext_schedule_prefix_index(struct interface *ifp, uint32_t index,
450 struct prefix_ipv4 *p, uint8_t flags)
451 {
452 int rc = 0;
453 struct ext_itf *exti;
454
455 /* Find Extended Prefix interface */
456 exti = lookup_ext_by_ifp(ifp);
457 if (exti == NULL)
458 return rc;
459
460 if (p != NULL) {
461 if (IS_DEBUG_OSPF_SR)
462 zlog_debug(
463 "EXT (%s): Schedule new prefix %s/%u with "
464 "index %u on interface %s",
465 __func__, inet_ntoa(p->prefix), p->prefixlen,
466 index, ifp->name);
467
468 /* Set first Extended Prefix then the Prefix SID information */
469 set_ext_prefix(exti, OSPF_PATH_INTRA_AREA, EXT_TLV_PREF_NFLG,
470 *p);
471 set_prefix_sid(exti, SR_ALGORITHM_SPF, index, SID_INDEX, flags);
472
473 /* Try to Schedule LSA */
474 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
475 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
476 ospf_ext_pref_lsa_schedule(exti, REFRESH_THIS_LSA);
477 else
478 ospf_ext_pref_lsa_schedule(exti, REORIGINATE_THIS_LSA);
479 } else {
480 if (IS_DEBUG_OSPF_SR)
481 zlog_debug("EXT (%s): Remove prefix for interface %s",
482 __func__, ifp->name);
483
484 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
485 ospf_ext_pref_lsa_schedule(exti, FLUSH_THIS_LSA);
486 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
487 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
488 }
489 }
490
491 return SET_OPAQUE_LSID(exti->type, exti->instance);
492 }
493
494 /*
495 * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
496 *
497 * @param enable To activate or not Segment Routing Extended LSA flooding
498 *
499 * @return none
500 */
501 void ospf_ext_update_sr(bool enable)
502 {
503 struct listnode *node;
504 struct ext_itf *exti;
505
506 if (IS_DEBUG_OSPF_SR)
507 zlog_debug("EXT (%s): %s Extended LSAs for Segment Routing ",
508 __func__, enable ? "Enable" : "Disable");
509
510 if (enable) {
511 OspfEXT.enabled = true;
512 /* Refresh LSAs if already engaged or originate */
513 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
514 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
515 ospf_ext_lsa_schedule(exti, REFRESH_THIS_LSA);
516 else
517 ospf_ext_lsa_schedule(exti,
518 REORIGINATE_THIS_LSA);
519 } else {
520 /* Start by Flushing engaged LSAs */
521 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
522 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
523 ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
524 /* And then disable Extended Link/Prefix */
525 OspfEXT.enabled = false;
526 }
527 }
528 /*
529 * -----------------------------------------------------------------------
530 * Followings are callback functions against generic Opaque-LSAs handling
531 * -----------------------------------------------------------------------
532 */
533
534 /* Add new Interface in Extended Interface List */
535 static int ospf_ext_link_new_if(struct interface *ifp)
536 {
537 struct ext_itf *new;
538 int rc = -1;
539
540 if (lookup_ext_by_ifp(ifp) != NULL) {
541 rc = 0; /* Do nothing here. */
542 return rc;
543 }
544
545 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf));
546
547 /* initialize new information and link back the interface */
548 new->ifp = ifp;
549 new->flags = EXT_LPFLG_LSA_INACTIVE;
550
551 listnode_add(OspfEXT.iflist, new);
552
553 rc = 0;
554 return rc;
555 }
556
557 /* Remove existing Interface from Extended Interface List */
558 static int ospf_ext_link_del_if(struct interface *ifp)
559 {
560 struct ext_itf *exti;
561 int rc = -1;
562
563 exti = lookup_ext_by_ifp(ifp);
564 if (exti != NULL) {
565 struct list *iflist = OspfEXT.iflist;
566
567 /* Dequeue listnode entry from the list. */
568 listnode_delete(iflist, exti);
569
570 XFREE(MTYPE_OSPF_EXT_PARAMS, exti);
571
572 rc = 0;
573 } else {
574 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
575 "EXT (%s): interface %s is not found", __func__,
576 ifp ? ifp->name : "-");
577 }
578
579 return rc;
580 }
581
582 /*
583 * Determine if an Interface belongs to an Extended Link Adjacency or LAN Adj.
584 * type and allocate new instance value accordingly
585 */
586 static void ospf_ext_link_ism_change(struct ospf_interface *oi, int old_status)
587 {
588 struct ext_itf *exti;
589
590 /* Get interface information for Segment Routing */
591 exti = lookup_ext_by_ifp(oi->ifp);
592 if (exti == NULL)
593 return;
594
595 /* Determine if interface is related to Adjacency or LAN Adj. SID */
596 if (oi->type != OSPF_IFTYPE_LOOPBACK) {
597 if (oi->state == ISM_DR)
598 exti->stype = LAN_ADJ_SID;
599 else
600 exti->stype = ADJ_SID;
601
602 exti->instance = get_ext_link_instance_value();
603 exti->type = OPAQUE_TYPE_EXTENDED_LINK_LSA;
604
605 zlog_debug("EXT (%s): Set %s SID to interface %s ", __func__,
606 exti->stype == ADJ_SID ? "Adj." : "LAN Adj.",
607 oi->ifp->name);
608 }
609 }
610
611 /*
612 * Determine if an Interface belongs to an Extended Prefix and
613 * allocate new instance value accordingly
614 */
615 static void ospf_ext_pref_ism_change(struct ospf_interface *oi, int old_status)
616 {
617 struct ext_itf *exti;
618
619 /* Get interface information for Segment Routing */
620 exti = lookup_ext_by_ifp(oi->ifp);
621 if (exti == NULL) {
622 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
623 "EXT (%s): Cannot get Extended info. from OI(%s)",
624 __func__, IF_NAME(oi));
625 return;
626 }
627
628 /* Determine if interface is related to a Node SID */
629 if (oi->type == OSPF_IFTYPE_LOOPBACK) {
630 exti->stype = PREF_SID;
631 exti->instance = get_ext_pref_instance_value();
632 exti->type = OPAQUE_TYPE_EXTENDED_PREFIX_LSA;
633
634 zlog_debug("EXT (%s): Set Node SID to interface %s ", __func__,
635 oi->ifp->name);
636
637 /* Complete SRDB if the interface belongs to a Prefix */
638 if (OspfEXT.enabled)
639 ospf_sr_update_prefix(oi->ifp, oi->address);
640 }
641 }
642
643 /*
644 * Finish Extended Link configuration and flood corresponding LSA
645 * when OSPF adjacency on this link fire up
646 */
647 static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
648 {
649 struct ospf_interface *oi = nbr->oi;
650 struct ext_itf *exti;
651 uint32_t label;
652
653 /* Process Neighbor only when its state is NSM Full */
654 if (nbr->state != NSM_Full)
655 return;
656
657 /* Get interface information for Segment Routing */
658 exti = lookup_ext_by_ifp(oi->ifp);
659 if (exti == NULL) {
660 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
661 "EXT (%s): Cannot get Extended info. from OI(%s)",
662 __func__, IF_NAME(oi));
663 return;
664 }
665
666 if (oi->area == NULL || oi->area->ospf == NULL) {
667 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
668 "EXT (%s): Cannot refer to OSPF from OI(%s)",
669 __func__, IF_NAME(oi));
670 return;
671 }
672
673 /* Keep Area information in combination with SR info. */
674 exti->area = oi->area;
675 OspfEXT.area = oi->area;
676
677 /* Process only Adjacency/LAN SID */
678 if (exti->stype == PREF_SID)
679 return;
680
681 switch (oi->state) {
682 case ISM_PointToPoint:
683 /* Segment ID is an Adjacency one */
684 exti->stype = ADJ_SID;
685
686 /* Set Extended Link TLV with link_id == Nbr Router ID */
687 set_ext_link(exti, OSPF_IFTYPE_POINTOPOINT, nbr->router_id,
688 oi->address->u.prefix4);
689
690 /* Set Extended Link Adjacency SubTLVs, backup first */
691 label = get_ext_link_label_value();
692 set_adj_sid(exti, true, label, SID_LABEL);
693 label = get_ext_link_label_value();
694 set_adj_sid(exti, false, label, SID_LABEL);
695 /* And Remote Interface address */
696 set_rmt_itf_addr(exti, nbr->address.u.prefix4);
697
698 break;
699
700 case ISM_DR:
701 /* Segment ID is a LAN Adjacency for the DR only */
702 exti->stype = LAN_ADJ_SID;
703
704 /* Set Extended Link TLV with link_id == DR */
705 set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
706 oi->address->u.prefix4);
707
708 /* Set Extended Link Adjacency SubTLVs, backup first */
709 label = get_ext_link_label_value();
710 set_lan_adj_sid(exti, true, label, SID_LABEL, nbr->router_id);
711 label = get_ext_link_label_value();
712 set_lan_adj_sid(exti, false, label, SID_LABEL, nbr->router_id);
713
714 break;
715
716 case ISM_DROther:
717 case ISM_Backup:
718 /* Segment ID is an Adjacency if not the DR */
719 exti->stype = ADJ_SID;
720
721 /* Set Extended Link TLV with link_id == DR */
722 set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
723 oi->address->u.prefix4);
724
725 /* Set Extended Link Adjacency SubTLVs, backup first */
726 label = get_ext_link_label_value();
727 set_adj_sid(exti, true, label, SID_LABEL);
728 label = get_ext_link_label_value();
729 set_adj_sid(exti, false, label, SID_LABEL);
730
731 break;
732
733 default:
734 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
735 ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA);
736 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
737 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
738 }
739 return;
740 }
741
742 if (IS_DEBUG_OSPF_SR)
743 zlog_debug("EXT (%s): Complete %s SID to interface %s ",
744 __func__,
745 exti->stype == ADJ_SID ? "Adj." : "LAN Adj.",
746 oi->ifp->name);
747
748 /* flood this links params if everything is ok */
749 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
750 if (OspfEXT.enabled) {
751 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
752 ospf_ext_link_lsa_schedule(exti, REFRESH_THIS_LSA);
753 else
754 ospf_ext_link_lsa_schedule(exti, REORIGINATE_THIS_LSA);
755 }
756 }
757
758 /* Callbacks to handle Extended Link Segment Routing LSA information */
759 static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa)
760 {
761 /* Sanity Check */
762 if (lsa == NULL) {
763 flog_warn(OSPF_WARN_LSA_NULL,
764 "EXT (%s): Abort! LSA is NULL", __func__);
765 return -1;
766 }
767
768 /* Process only Opaque LSA */
769 if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA)
770 && (lsa->data->type != OSPF_OPAQUE_AS_LSA))
771 return 0;
772
773 /* Process only Extended Link LSA */
774 if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr))
775 != OPAQUE_TYPE_EXTENDED_LINK_LSA)
776 return 0;
777
778 /* Check if Extended is enable */
779 if (!OspfEXT.enabled)
780 return 0;
781
782 /* Call Segment Routing LSA update or deletion */
783 if (!IS_LSA_MAXAGE(lsa))
784 ospf_sr_ext_link_lsa_update(lsa);
785 else
786 ospf_sr_ext_link_lsa_delete(lsa);
787
788 return 0;
789 }
790
791 /* Callbacks to handle Extended Prefix Segment Routing LSA information */
792 static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa)
793 {
794
795 /* Sanity Check */
796 if (lsa == NULL) {
797 flog_warn(OSPF_WARN_LSA_NULL,
798 "EXT (%s): Abort! LSA is NULL", __func__);
799 return -1;
800 }
801
802 /* Process only Opaque LSA */
803 if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA)
804 && (lsa->data->type != OSPF_OPAQUE_AS_LSA))
805 return 0;
806
807 /* Process only Extended Prefix LSA */
808 if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr))
809 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA)
810 return 0;
811
812 /* Check if it is not my LSA */
813 if (IS_LSA_SELF(lsa))
814 return 0;
815
816 /* Check if Extended is enable */
817 if (!OspfEXT.enabled)
818 return 0;
819
820 /* Call Segment Routing LSA update or deletion */
821 if (!IS_LSA_MAXAGE(lsa))
822 ospf_sr_ext_prefix_lsa_update(lsa);
823 else
824 ospf_sr_ext_prefix_lsa_delete(lsa);
825
826 return 0;
827 }
828
829 /*
830 * -------------------------------------------------------
831 * Followings are OSPF protocol processing functions for
832 * Extended Prefix/Link Opaque LSA
833 * -------------------------------------------------------
834 */
835
836 static void build_tlv_header(struct stream *s, struct tlv_header *tlvh)
837 {
838 stream_put(s, tlvh, sizeof(struct tlv_header));
839 }
840
841 static void build_tlv(struct stream *s, struct tlv_header *tlvh)
842 {
843
844 if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) {
845 build_tlv_header(s, tlvh);
846 stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
847 }
848 }
849
850 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
851 static void ospf_ext_pref_lsa_body_set(struct stream *s, struct ext_itf *exti)
852 {
853
854 /* Sanity check */
855 if ((exti == NULL) || (exti->stype != PREF_SID))
856 return;
857
858 /* Adjust Extended Prefix TLV size */
859 TLV_LEN(exti->prefix) = htons(ntohs(TLV_LEN(exti->node_sid))
860 + EXT_TLV_PREFIX_SIZE + TLV_HDR_SIZE);
861
862 /* Build LSA body for an Extended Prefix TLV */
863 build_tlv_header(s, &exti->prefix.header);
864 stream_put(s, TLV_DATA(&exti->prefix.header), EXT_TLV_PREFIX_SIZE);
865 /* Then add Prefix SID SubTLV */
866 build_tlv(s, &exti->node_sid.header);
867 }
868
869 /* Build an Extended Link Opaque LSA body for extended link TLV */
870 static void ospf_ext_link_lsa_body_set(struct stream *s, struct ext_itf *exti)
871 {
872 size_t size;
873
874 /* Sanity check */
875 if ((exti == NULL)
876 || ((exti->stype != ADJ_SID) && (exti->stype != LAN_ADJ_SID)))
877 return;
878
879 if (exti->stype == ADJ_SID) {
880 /* Adjust Extended Link TLV size for Adj. SID */
881 size = EXT_TLV_LINK_SIZE + 2 * EXT_SUBTLV_ADJ_SID_SIZE
882 + 2 * TLV_HDR_SIZE;
883 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
884 size = size + EXT_SUBTLV_RMT_ITF_ADDR_SIZE
885 + TLV_HDR_SIZE;
886 TLV_LEN(exti->link) = htons(size);
887
888 /* Build LSA body for an Extended Link TLV with Adj. SID */
889 build_tlv_header(s, &exti->link.header);
890 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
891 /* then add Adjacency SubTLVs */
892 build_tlv(s, &exti->adj_sid[1].header);
893 build_tlv(s, &exti->adj_sid[0].header);
894
895 /* Add Cisco experimental SubTLV if interface is PtoP */
896 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
897 build_tlv(s, &exti->rmt_itf_addr.header);
898 } else {
899 /* Adjust Extended Link TLV size for LAN SID */
900 size = EXT_TLV_LINK_SIZE
901 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE + TLV_HDR_SIZE);
902 TLV_LEN(exti->link) = htons(size);
903
904 /* Build LSA body for an Extended Link TLV with LAN SID */
905 build_tlv_header(s, &exti->link.header);
906 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
907 /* then add LAN-Adjacency SubTLVs */
908 build_tlv(s, &exti->lan_sid[1].header);
909 build_tlv(s, &exti->lan_sid[0].header);
910 }
911 }
912
913 /* Create new Extended Prefix opaque-LSA for every extended prefix */
914 static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area,
915 struct ext_itf *exti)
916 {
917 struct stream *s;
918 struct lsa_header *lsah;
919 struct ospf_lsa *new = NULL;
920 struct ospf *top;
921 uint8_t options, lsa_type;
922 struct in_addr lsa_id;
923 struct in_addr router_id;
924 uint32_t tmp;
925 uint16_t length;
926
927 /* Sanity Check */
928 if (exti == NULL)
929 return NULL;
930
931 /* Create a stream for LSA. */
932 s = stream_new(OSPF_MAX_LSA_SIZE);
933
934 /* Prepare LSA Header */
935 lsah = (struct lsa_header *)STREAM_DATA(s);
936
937 lsa_type = OspfEXT.scope;
938
939 /*
940 * LSA ID is a variable number identifying different instances of
941 * Extended Prefix Opaque LSA from the same router see RFC 7684
942 */
943 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
944 lsa_id.s_addr = htonl(tmp);
945
946 options = OSPF_OPTION_O; /* Don't forget this :-) */
947
948 /* Fix Options and Router ID depending of the flooding scope */
949 if ((OspfEXT.scope == OSPF_OPAQUE_AS_LSA) || (area == NULL)) {
950 options = OSPF_OPTION_E;
951 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
952 router_id.s_addr = top ? top->router_id.s_addr : 0;
953 } else {
954 options |= LSA_OPTIONS_GET(area); /* Get area default option */
955 options |= LSA_OPTIONS_NSSA_GET(area);
956 router_id = area->ospf->router_id;
957 }
958
959 /* Set opaque-LSA header fields. */
960 lsa_header_set(s, options, lsa_type, lsa_id, router_id);
961
962 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
963 zlog_debug(
964 "EXT (%s): LSA[Type%u:%s]: Create an Opaque-LSA "
965 "Extended Prefix Opaque LSA instance",
966 __func__, lsa_type, inet_ntoa(lsa_id));
967
968
969 /* Set opaque-LSA body fields. */
970 ospf_ext_pref_lsa_body_set(s, exti);
971
972 /* Set length. */
973 length = stream_get_endp(s);
974 lsah->length = htons(length);
975
976 /* Now, create an OSPF LSA instance. */
977 new = ospf_lsa_new_and_data(length);
978
979 /* Segment Routing belongs only to default VRF */
980 new->vrf_id = VRF_DEFAULT;
981 new->area = area;
982 SET_FLAG(new->flags, OSPF_LSA_SELF);
983 memcpy(new->data, lsah, length);
984 stream_free(s);
985
986 return new;
987 }
988
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)
992 {
993 struct stream *s;
994 struct lsa_header *lsah;
995 struct ospf_lsa *new = NULL;
996 uint8_t options, lsa_type;
997 struct in_addr lsa_id;
998 uint32_t tmp;
999 uint16_t length;
1000
1001 /* Sanity Check */
1002 if (exti == NULL)
1003 return NULL;
1004
1005 /* Create a stream for LSA. */
1006 s = stream_new(OSPF_MAX_LSA_SIZE);
1007 lsah = (struct lsa_header *)STREAM_DATA(s);
1008
1009 options = OSPF_OPTION_O; /* Don't forget this :-) */
1010 options |= LSA_OPTIONS_GET(area); /* Get area default option */
1011 options |= LSA_OPTIONS_NSSA_GET(area);
1012 /* Extended Link Opaque LSA are only flooded within an area */
1013 lsa_type = OSPF_OPAQUE_AREA_LSA;
1014
1015 /*
1016 * LSA ID is a variable number identifying different instances of
1017 * Extended Link Opaque LSA from the same router see RFC 7684
1018 */
1019 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1020 lsa_id.s_addr = htonl(tmp);
1021
1022 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1023 zlog_debug(
1024 "EXT (%s) LSA[Type%u:%s]: Create an Opaque-LSA "
1025 "Extended Link Opaque LSA instance",
1026 __func__, lsa_type, inet_ntoa(lsa_id));
1027
1028 /* Set opaque-LSA header fields. */
1029 lsa_header_set(s, options, lsa_type, lsa_id, area->ospf->router_id);
1030
1031 /* Set opaque-LSA body fields. */
1032 ospf_ext_link_lsa_body_set(s, exti);
1033
1034 /* Set length. */
1035 length = stream_get_endp(s);
1036 lsah->length = htons(length);
1037
1038 /* Now, create an OSPF LSA instance. */
1039 new = ospf_lsa_new_and_data(length);
1040
1041 /* Segment Routing belongs only to default VRF */
1042 new->vrf_id = VRF_DEFAULT;
1043 new->area = area;
1044 SET_FLAG(new->flags, OSPF_LSA_SELF);
1045 memcpy(new->data, lsah, length);
1046 stream_free(s);
1047
1048 return new;
1049 }
1050
1051 /*
1052 * Process the origination of an Extended Prefix Opaque LSA
1053 * for every extended prefix TLV
1054 */
1055 static int ospf_ext_pref_lsa_originate1(struct ospf_area *area,
1056 struct ext_itf *exti)
1057 {
1058 struct ospf_lsa *new;
1059 int rc = -1;
1060
1061
1062 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1063 new = ospf_ext_pref_lsa_new(area, exti);
1064 if (new == NULL) {
1065 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1066 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
1067 return rc;
1068 }
1069
1070 /* Install this LSA into LSDB. */
1071 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
1072 flog_warn(OSPF_WARN_LSA_INSTALL_FAILURE,
1073 "EXT (%s): ospf_lsa_install() error", __func__);
1074 ospf_lsa_unlock(&new);
1075 return rc;
1076 }
1077
1078 /* Now this Extended Prefix Opaque LSA info parameter entry has
1079 * associated LSA.
1080 */
1081 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1082
1083 /* Update new LSA origination count. */
1084 area->ospf->lsa_originate_count++;
1085
1086 /* Flood new LSA through area. */
1087 ospf_flood_through_area(area, NULL /*nbr */, new);
1088
1089 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1090 char area_id[INET_ADDRSTRLEN];
1091
1092 inet_ntop(AF_INET, &area->area_id, area_id, sizeof(area_id));
1093 zlog_debug(
1094 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1095 "Extended Prefix Opaque LSA: Area(%s), Link(%s)",
1096 __func__, new->data->type, inet_ntoa(new->data->id),
1097 area_id, exti->ifp->name);
1098 ospf_lsa_header_dump(new->data);
1099 }
1100
1101 rc = 0;
1102
1103 return rc;
1104 }
1105
1106 /*
1107 * Process the origination of an Extended Link Opaque LSA
1108 * for every extended link TLV
1109 */
1110 static int ospf_ext_link_lsa_originate1(struct ospf_area *area,
1111 struct ext_itf *exti)
1112 {
1113 struct ospf_lsa *new;
1114 int rc = -1;
1115
1116 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1117 new = ospf_ext_link_lsa_new(area, exti);
1118 if (new == NULL) {
1119 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1120 "EXT (%s): ospf_ext_link_lsa_new() error", __func__);
1121 return rc;
1122 }
1123
1124 /* Install this LSA into LSDB. */
1125 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
1126 flog_warn(OSPF_WARN_LSA_INSTALL_FAILURE,
1127 "EXT (%s): ospf_lsa_install() error", __func__);
1128 ospf_lsa_unlock(&new);
1129 return rc;
1130 }
1131
1132 /* Now this link-parameter entry has associated LSA. */
1133 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1134
1135 /* Update new LSA origination count. */
1136 area->ospf->lsa_originate_count++;
1137
1138 /* Flood new LSA through area. */
1139 ospf_flood_through_area(area, NULL /*nbr */, new);
1140
1141 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1142 char area_id[INET_ADDRSTRLEN];
1143
1144 inet_ntop(AF_INET, &area->area_id, area_id, sizeof(area_id));
1145 zlog_debug(
1146 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1147 "Extended Link Opaque LSA: Area(%s), Link(%s)",
1148 __func__, new->data->type, inet_ntoa(new->data->id),
1149 area_id, exti->ifp->name);
1150 ospf_lsa_header_dump(new->data);
1151 }
1152
1153 rc = 0;
1154
1155 return rc;
1156 }
1157
1158 /* Trigger the origination of Extended Prefix Opaque LSAs */
1159 static int ospf_ext_pref_lsa_originate(void *arg)
1160 {
1161 struct ospf_area *area = (struct ospf_area *)arg;
1162 struct listnode *node;
1163 struct ext_itf *exti;
1164 int rc = -1;
1165
1166 if (!OspfEXT.enabled) {
1167 zlog_info(
1168 "EXT (%s): Segment Routing "
1169 "functionality is Disabled now",
1170 __func__);
1171 rc = 0; /* This is not an error case. */
1172 return rc;
1173 }
1174 if (IS_DEBUG_OSPF_SR)
1175 zlog_debug("EXT (%s): Start Originate Prefix LSA for area %s",
1176 __func__, inet_ntoa(area->area_id));
1177
1178 /* Check if Extended Prefix Opaque LSA is already engaged */
1179 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1180
1181 /* Process only Prefix SID */
1182 if (exti->stype != PREF_SID)
1183 continue;
1184
1185 /* Process only Extended Prefix with valid Area ID */
1186 if ((exti->area == NULL)
1187 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1188 continue;
1189
1190 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1191 if (CHECK_FLAG(exti->flags,
1192 EXT_LPFLG_LSA_FORCED_REFRESH)) {
1193 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1194 "EXT (%s): Refresh instead of Originate",
1195 __func__);
1196 UNSET_FLAG(exti->flags,
1197 EXT_LPFLG_LSA_FORCED_REFRESH);
1198 ospf_ext_pref_lsa_schedule(exti,
1199 REFRESH_THIS_LSA);
1200 }
1201 continue;
1202 }
1203
1204 /* Ok, let's try to originate an LSA */
1205 if (IS_DEBUG_OSPF_SR)
1206 zlog_debug(
1207 "EXT (%s): Let's finally reoriginate the "
1208 "LSA 7.0.0.%u for Itf %s",
1209 __func__, exti->instance,
1210 exti->ifp ? exti->ifp->name : "");
1211 ospf_ext_pref_lsa_originate1(area, exti);
1212 }
1213
1214 rc = 0;
1215 return rc;
1216 }
1217
1218 /* Trigger the origination of Extended Link Opaque LSAs */
1219 static int ospf_ext_link_lsa_originate(void *arg)
1220 {
1221 struct ospf_area *area = (struct ospf_area *)arg;
1222 struct listnode *node;
1223 struct ext_itf *exti;
1224 int rc = -1;
1225
1226 if (!OspfEXT.enabled) {
1227 zlog_info(
1228 "EXT (%s): Segment Routing "
1229 "functionality is Disabled now",
1230 __func__);
1231 rc = 0; /* This is not an error case. */
1232 return rc;
1233 }
1234
1235 /* Check if Extended Prefix Opaque LSA is already engaged */
1236 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1237 /* Process only Adjacency or LAN SID */
1238 if (exti->stype == PREF_SID)
1239 continue;
1240
1241 /* Process only Extended Link with valid Area ID */
1242 if ((exti->area == NULL)
1243 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1244 continue;
1245
1246 /* Check if LSA not already engaged */
1247 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1248 if (CHECK_FLAG(exti->flags,
1249 EXT_LPFLG_LSA_FORCED_REFRESH)) {
1250 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1251 "EXT (%s): Refresh instead of Originate",
1252 __func__);
1253 UNSET_FLAG(exti->flags,
1254 EXT_LPFLG_LSA_FORCED_REFRESH);
1255 ospf_ext_link_lsa_schedule(exti,
1256 REFRESH_THIS_LSA);
1257 }
1258 continue;
1259 }
1260
1261 /* Ok, let's try to originate an LSA */
1262 if (IS_DEBUG_OSPF_SR)
1263 zlog_debug(
1264 "EXT (%s): Let's finally reoriginate the "
1265 "LSA 8.0.0.%u for Itf %s through the Area %s",
1266 __func__, exti->instance,
1267 exti->ifp ? exti->ifp->name : "-",
1268 inet_ntoa(area->area_id));
1269 ospf_ext_link_lsa_originate1(area, exti);
1270 }
1271
1272 rc = 0;
1273 return rc;
1274 }
1275
1276 /* Refresh an Extended Prefix Opaque LSA */
1277 static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
1278 {
1279 struct ospf_lsa *new = NULL;
1280 struct ospf_area *area = lsa->area;
1281 struct ospf *top;
1282 struct ext_itf *exti;
1283
1284 if (!OspfEXT.enabled) {
1285 /*
1286 * This LSA must have flushed before due to Extended Prefix
1287 * Opaque LSA status change.
1288 * It seems a slip among routers in the routing domain.
1289 */
1290 zlog_info(
1291 "EXT (%s): Segment Routing functionality is "
1292 "Disabled",
1293 __func__);
1294 /* Flush it anyway. */
1295 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1296 }
1297
1298 /* Lookup this lsa corresponding Extended parameters */
1299 exti = lookup_ext_by_instance(lsa);
1300 if (exti == NULL) {
1301 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1302 "EXT (%s): Invalid parameter LSA ID", __func__);
1303 /* Flush it anyway. */
1304 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1305 }
1306
1307 /* Check if Interface was not disable in the interval */
1308 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
1309 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1310 "EXT (%s): Interface was Disabled: Flush it!",
1311 __func__);
1312 /* Flush it anyway. */
1313 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1314 }
1315
1316 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1317 if (IS_LSA_MAXAGE(lsa)) {
1318 if (exti)
1319 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1320 ospf_opaque_lsa_flush_schedule(lsa);
1321 return NULL;
1322 }
1323
1324 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1325 new = ospf_ext_pref_lsa_new(area, exti);
1326
1327 if (new == NULL) {
1328 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1329 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
1330 return NULL;
1331 }
1332 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1333
1334 /*
1335 * Install this LSA into LSDB
1336 * Given "lsa" will be freed in the next function
1337 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1338 * ospf_lookup() to get ospf instance
1339 */
1340 if (area)
1341 top = area->ospf;
1342 else
1343 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1344
1345 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1346 flog_warn(OSPF_WARN_LSA_INSTALL_FAILURE,
1347 "EXT (%s): ospf_lsa_install() error", __func__);
1348 ospf_lsa_unlock(&new);
1349 return NULL;
1350 }
1351
1352 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1353 ospf_flood_through_area(area, NULL /*nbr */, new);
1354
1355 /* Debug logging. */
1356 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1357 zlog_debug(
1358 "EXT (%s): LSA[Type%u:%s] Refresh Extended Prefix LSA",
1359 __func__, new->data->type, inet_ntoa(new->data->id));
1360 ospf_lsa_header_dump(new->data);
1361 }
1362
1363 return new;
1364 }
1365
1366 /* Refresh an Extended Link Opaque LSA */
1367 static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
1368 {
1369 struct ext_itf *exti;
1370 struct ospf_area *area = lsa->area;
1371 struct ospf *top = area->ospf;
1372 struct ospf_lsa *new = NULL;
1373
1374 if (!OspfEXT.enabled) {
1375 /*
1376 * This LSA must have flushed before due to OSPF-SR status
1377 * change. It seems a slip among routers in the routing domain.
1378 */
1379 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1380 __func__);
1381 /* Flush it anyway. */
1382 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1383 }
1384
1385 /* Lookup this LSA corresponding Extended parameters */
1386 exti = lookup_ext_by_instance(lsa);
1387 if (exti == NULL) {
1388 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1389 "EXT (%s): Invalid parameter LSA ID", __func__);
1390 /* Flush it anyway. */
1391 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1392 }
1393
1394 /* Check if Interface was not disable in the interval */
1395 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
1396 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1397 "EXT (%s): Interface was Disabled: Flush it!",
1398 __func__);
1399 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1400 }
1401
1402 /* If the lsa's age reached to MaxAge, start flushing procedure */
1403 if (IS_LSA_MAXAGE(lsa)) {
1404 if (exti)
1405 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1406 ospf_opaque_lsa_flush_schedule(lsa);
1407 return NULL;
1408 }
1409
1410 /* Create new Opaque-LSA/Extended Link instance */
1411 new = ospf_ext_link_lsa_new(area, exti);
1412 if (new == NULL) {
1413 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1414 "EXT (%s): Error creating new LSA", __func__);
1415 return NULL;
1416 }
1417 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1418
1419 /* Install this LSA into LSDB. */
1420 /* Given "lsa" will be freed in the next function */
1421 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1422 flog_warn(OSPF_WARN_LSA_INSTALL_FAILURE,
1423 "EXT (%s): Error installing new LSA", __func__);
1424 ospf_lsa_unlock(&new);
1425 return NULL;
1426 }
1427
1428 /* Flood updated LSA through the link Area according to the RFC7684 */
1429 ospf_flood_through_area(area, NULL /*nbr */, new);
1430
1431 /* Debug logging. */
1432 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1433 zlog_debug(
1434 "EXT (%s): LSA[Type%u:%s]: Refresh Extended Link LSA",
1435 __func__, new->data->type, inet_ntoa(new->data->id));
1436 ospf_lsa_header_dump(new->data);
1437 }
1438
1439 return new;
1440 }
1441
1442 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1443 static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
1444 enum lsa_opcode opcode)
1445 {
1446 struct ospf_lsa lsa;
1447 struct lsa_header lsah;
1448 struct ospf *top;
1449 uint32_t tmp;
1450
1451 memset(&lsa, 0, sizeof(lsa));
1452 memset(&lsah, 0, sizeof(lsah));
1453
1454 /* Sanity Check */
1455 if (exti == NULL)
1456 return;
1457
1458 /* Check if the corresponding link is ready to be flooded */
1459 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1460 return;
1461
1462 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1463 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1464 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1465 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1466 exti->ifp ? exti->ifp->name : "-");
1467
1468 /* Set LSA header information */
1469 if (exti->area == NULL) {
1470 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1471 "EXT (%s): Flooding is Area scope but area is not yet set",
1472 __func__);
1473 if (OspfEXT.area == NULL) {
1474 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1475 OspfEXT.area = ospf_area_lookup_by_area_id(
1476 top, OspfEXT.area_id);
1477 }
1478 exti->area = OspfEXT.area;
1479 }
1480 lsa.area = exti->area;
1481 lsa.data = &lsah;
1482 lsah.type = OSPF_OPAQUE_AREA_LSA;
1483 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
1484 lsah.id.s_addr = htonl(tmp);
1485
1486 switch (opcode) {
1487 case REORIGINATE_THIS_LSA:
1488 ospf_opaque_lsa_reoriginate_schedule(
1489 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1490 OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
1491 break;
1492 case REFRESH_THIS_LSA:
1493 ospf_opaque_lsa_refresh_schedule(&lsa);
1494 break;
1495 case FLUSH_THIS_LSA:
1496 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1497 ospf_opaque_lsa_flush_schedule(&lsa);
1498 break;
1499 }
1500 }
1501
1502 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1503 static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
1504 enum lsa_opcode opcode)
1505 {
1506 struct ospf_lsa lsa;
1507 struct lsa_header lsah;
1508 struct ospf *top;
1509 uint32_t tmp;
1510
1511 memset(&lsa, 0, sizeof(lsa));
1512 memset(&lsah, 0, sizeof(lsah));
1513
1514 /* Sanity Check */
1515 if (exti == NULL)
1516 return;
1517
1518 /* Check if the corresponding link is ready to be flooded */
1519 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1520 return;
1521
1522 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1523 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1524 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1525 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1526 exti->ifp ? exti->ifp->name : "-");
1527
1528 /* Set LSA header information */
1529 if (exti->area == NULL) {
1530 flog_warn(OSPF_WARN_EXT_LSA_UNEXPECTED,
1531 "EXT (%s): Flooding is Area scope but area is not yet set",
1532 __func__);
1533 if (OspfEXT.area == NULL) {
1534 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1535 OspfEXT.area = ospf_area_lookup_by_area_id(
1536 top, OspfEXT.area_id);
1537 }
1538 exti->area = OspfEXT.area;
1539 }
1540 lsa.area = exti->area;
1541 lsa.data = &lsah;
1542 lsah.type = OSPF_OPAQUE_AREA_LSA;
1543 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1544 lsah.id.s_addr = htonl(tmp);
1545
1546 switch (opcode) {
1547 case REORIGINATE_THIS_LSA:
1548 ospf_opaque_lsa_reoriginate_schedule(
1549 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1550 OPAQUE_TYPE_EXTENDED_LINK_LSA);
1551 break;
1552 case REFRESH_THIS_LSA:
1553 ospf_opaque_lsa_refresh_schedule(&lsa);
1554 break;
1555 case FLUSH_THIS_LSA:
1556 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1557 ospf_opaque_lsa_flush_schedule(&lsa);
1558 break;
1559 }
1560 }
1561
1562 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1563 static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op)
1564 {
1565
1566 if (exti->stype == PREF_SID)
1567 ospf_ext_pref_lsa_schedule(exti, op);
1568 else
1569 ospf_ext_link_lsa_schedule(exti, op);
1570 }
1571
1572 /*
1573 * ------------------------------------
1574 * Followings are vty show functions.
1575 * ------------------------------------
1576 */
1577
1578 /* Cisco experimental SubTLV */
1579 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty *vty,
1580 struct tlv_header *tlvh)
1581 {
1582 struct ext_subtlv_rmt_itf_addr *top;
1583
1584 top = (struct ext_subtlv_rmt_itf_addr *)tlvh;
1585
1586 vty_out(vty,
1587 " Remote Interface Address Sub-TLV: Length %u\n "
1588 "Address: %s\n",
1589 ntohs(top->header.length), inet_ntoa(top->value));
1590
1591 return TLV_SIZE(tlvh);
1592 }
1593
1594 /* Adjacency SID SubTLV */
1595 static uint16_t show_vty_ext_link_adj_sid(struct vty *vty,
1596 struct tlv_header *tlvh)
1597 {
1598 struct ext_subtlv_adj_sid *top = (struct ext_subtlv_adj_sid *)tlvh;
1599
1600 vty_out(vty,
1601 " Adj-SID Sub-TLV: Length %u\n\tFlags: "
1602 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1603 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1604 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1605 : "Index",
1606 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1607 ? GET_LABEL(ntohl(top->value))
1608 : ntohl(top->value));
1609
1610 return TLV_SIZE(tlvh);
1611 }
1612
1613 /* LAN Adjacency SubTLV */
1614 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty *vty,
1615 struct tlv_header *tlvh)
1616 {
1617 struct ext_subtlv_lan_adj_sid *top =
1618 (struct ext_subtlv_lan_adj_sid *)tlvh;
1619
1620 vty_out(vty,
1621 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: "
1622 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: "
1623 "%s\n\t%s: %u\n",
1624 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1625 inet_ntoa(top->neighbor_id),
1626 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1627 : "Index",
1628 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1629 ? GET_LABEL(ntohl(top->value))
1630 : ntohl(top->value));
1631
1632 return TLV_SIZE(tlvh);
1633 }
1634
1635 static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh)
1636 {
1637 vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1638 ntohs(tlvh->type), ntohs(tlvh->length));
1639
1640 return TLV_SIZE(tlvh);
1641 }
1642
1643 /* Extended Link Sub TLVs */
1644 static uint16_t show_vty_link_info(struct vty *vty, struct tlv_header *ext)
1645 {
1646 struct ext_tlv_link *top = (struct ext_tlv_link *)ext;
1647 struct tlv_header *tlvh;
1648 uint16_t length = ntohs(top->header.length) - 3 * sizeof(uint32_t);
1649 uint16_t sum = 0;
1650
1651 vty_out(vty,
1652 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1653 " Link ID: %s\n",
1654 ntohs(top->header.length), top->link_type,
1655 inet_ntoa(top->link_id));
1656 vty_out(vty, " Link data: %s\n", inet_ntoa(top->link_data));
1657
1658 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1659 + EXT_TLV_LINK_SIZE);
1660 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1661 switch (ntohs(tlvh->type)) {
1662 case EXT_SUBTLV_ADJ_SID:
1663 sum += show_vty_ext_link_adj_sid(vty, tlvh);
1664 break;
1665 case EXT_SUBTLV_LAN_ADJ_SID:
1666 sum += show_vty_ext_link_lan_adj_sid(vty, tlvh);
1667 break;
1668 case EXT_SUBTLV_RMT_ITF_ADDR:
1669 sum += show_vty_ext_link_rmt_itf_addr(vty, tlvh);
1670 break;
1671 default:
1672 sum += show_vty_unknown_tlv(vty, tlvh);
1673 break;
1674 }
1675 }
1676
1677 return sum + sizeof(struct ext_tlv_link);
1678 }
1679
1680 /* Extended Link TLVs */
1681 static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa)
1682 {
1683 struct lsa_header *lsah = (struct lsa_header *)lsa->data;
1684 struct tlv_header *tlvh;
1685 uint16_t length = 0, sum = 0;
1686
1687 /* Initialize TLV browsing */
1688 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1689
1690 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1691 tlvh = TLV_HDR_NEXT(tlvh)) {
1692 switch (ntohs(tlvh->type)) {
1693 case EXT_TLV_LINK:
1694 sum += show_vty_link_info(vty, tlvh);
1695 break;
1696 default:
1697 sum += show_vty_unknown_tlv(vty, tlvh);
1698 break;
1699 }
1700 }
1701 }
1702
1703 /* Prefix SID SubTLV */
1704 static uint16_t show_vty_ext_pref_pref_sid(struct vty *vty,
1705 struct tlv_header *tlvh)
1706 {
1707 struct ext_subtlv_prefix_sid *top =
1708 (struct ext_subtlv_prefix_sid *)tlvh;
1709
1710 vty_out(vty,
1711 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: "
1712 "%u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1713 ntohs(top->header.length), top->algorithm, top->flags,
1714 top->mtid,
1715 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) ? "Label"
1716 : "Index",
1717 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG)
1718 ? GET_LABEL(ntohl(top->value))
1719 : ntohl(top->value));
1720
1721 return TLV_SIZE(tlvh);
1722 }
1723
1724 /* Extended Prefix SubTLVs */
1725 static uint16_t show_vty_pref_info(struct vty *vty, struct tlv_header *ext)
1726 {
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);
1730 uint16_t sum = 0;
1731
1732 vty_out(vty,
1733 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1734 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%u\n",
1735 ntohs(top->header.length), top->route_type, top->af, top->flags,
1736 inet_ntoa(top->address), top->pref_length);
1737
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);
1744 break;
1745 default:
1746 sum += show_vty_unknown_tlv(vty, tlvh);
1747 break;
1748 }
1749 }
1750
1751 return sum + sizeof(struct ext_tlv_prefix);
1752 }
1753
1754 /* Extended Prefix TLVs */
1755 static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa)
1756 {
1757 struct lsa_header *lsah = (struct lsa_header *)lsa->data;
1758 struct tlv_header *tlvh;
1759 uint16_t length = 0, sum = 0;
1760
1761 /* Initialize TLV browsing */
1762 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1763
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);
1769 break;
1770 default:
1771 sum += show_vty_unknown_tlv(vty, tlvh);
1772 break;
1773 }
1774 }
1775 }