]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_ext.c
Merge pull request #2830 from pacovn/Coverity_1221459_revert
[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
66 /* Following structure are internal use only. */
67
68 /*
69 * Global variable to manage Extended Prefix/Link Opaque LSA on this node.
70 * Note that all parameter values are stored in network byte order.
71 */
72 static struct ospf_ext_lp OspfEXT;
73
74 /*
75 * -----------------------------------------------------------------------
76 * Followings are initialize/terminate functions for Extended Prefix/Link
77 * Opaque LSA handling.
78 * -----------------------------------------------------------------------
79 */
80
81 /* Extended Prefix Opaque LSA related callback functions */
82 static void ospf_ext_pref_ism_change(struct ospf_interface *oi, int old_status);
83 static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa);
84 static int ospf_ext_pref_lsa_originate(void *arg);
85 static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa);
86 static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
87 enum lsa_opcode opcode);
88 /* Extended Link Opaque LSA related callback functions */
89 static int ospf_ext_link_new_if(struct interface *ifp);
90 static int ospf_ext_link_del_if(struct interface *ifp);
91 static void ospf_ext_link_ism_change(struct ospf_interface *oi, int old_status);
92 static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status);
93 static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa);
94 static int ospf_ext_link_lsa_originate(void *arg);
95 static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa);
96 static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
97 enum lsa_opcode opcode);
98 static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op);
99 static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa);
100 static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa);
101 static void del_ext_info(void *val);
102
103 /*
104 * Extended Link/Prefix initialization
105 *
106 * @param - none
107 *
108 * @return - 0 if OK, <> 0 otherwise
109 */
110 int ospf_ext_init(void)
111 {
112 int rc = 0;
113
114 memset(&OspfEXT, 0, sizeof(struct ospf_ext_lp));
115 OspfEXT.enabled = false;
116 /* Only Area flooding is supported yet */
117 OspfEXT.scope = OSPF_OPAQUE_AREA_LSA;
118 /* Initialize interface list */
119 OspfEXT.iflist = list_new();
120 OspfEXT.iflist->del = del_ext_info;
121
122 zlog_info("EXT (%s): Register Extended Link Opaque LSA", __func__);
123 rc = ospf_register_opaque_functab(
124 OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_EXTENDED_LINK_LSA,
125 ospf_ext_link_new_if, /* new if */
126 ospf_ext_link_del_if, /* del if */
127 ospf_ext_link_ism_change, /* ism change */
128 ospf_ext_link_nsm_change, /* nsm change */
129 NULL, /* Write router config. */
130 NULL, /* Write interface conf. */
131 NULL, /* Write debug config. */
132 ospf_ext_link_show_info, /* Show LSA info */
133 ospf_ext_link_lsa_originate, /* Originate LSA */
134 ospf_ext_link_lsa_refresh, /* Refresh LSA */
135 ospf_ext_link_lsa_update, /* new_lsa_hook */
136 NULL); /* del_lsa_hook */
137
138 if (rc != 0) {
139 zlog_warn("EXT (%s): Failed to register Extended Link LSA",
140 __func__);
141 return rc;
142 }
143
144 zlog_info("EXT (%s): Register Extended Prefix Opaque LSA", __func__);
145 rc = ospf_register_opaque_functab(
146 OspfEXT.scope, OPAQUE_TYPE_EXTENDED_PREFIX_LSA,
147 NULL, /* new if handle by link */
148 NULL, /* del if handle by link */
149 ospf_ext_pref_ism_change, /* ism change */
150 NULL, /* nsm change */
151 ospf_sr_config_write_router, /* Write router config. */
152 NULL, /* Write interface conf. */
153 NULL, /* Write debug config. */
154 ospf_ext_pref_show_info, /* Show LSA info */
155 ospf_ext_pref_lsa_originate, /* Originate LSA */
156 ospf_ext_pref_lsa_refresh, /* Refresh LSA */
157 ospf_ext_pref_lsa_update, /* new_lsa_hook */
158 NULL); /* del_lsa_hook */
159 if (rc != 0) {
160 zlog_warn("EXT (%s): Failed to register Extended Prefix LSA",
161 __func__);
162 return rc;
163 }
164
165 return rc;
166 }
167
168 /*
169 * Extended Link/Prefix termination function
170 *
171 * @param - none
172 * @return - none
173 */
174 void ospf_ext_term(void)
175 {
176
177 if ((OspfEXT.scope != OSPF_OPAQUE_AREA_LSA)
178 && (OspfEXT.scope != OSPF_OPAQUE_AS_LSA))
179 zlog_warn(
180 "EXT: Unable to unregister Extended Prefix "
181 "Opaque LSA functions: Wrong scope!");
182 else
183 ospf_delete_opaque_functab(OspfEXT.scope,
184 OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
185
186 ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA,
187 OPAQUE_TYPE_EXTENDED_LINK_LSA);
188
189 list_delete_and_null(&OspfEXT.iflist);
190 OspfEXT.scope = 0;
191 OspfEXT.enabled = false;
192
193 return;
194 }
195
196 /*
197 * Extended Link/Prefix finish function
198 *
199 * @param - none
200 * @return - none
201 */
202 void ospf_ext_finish(void)
203 {
204 // list_delete_all_node(OspfEXT.iflist);
205 OspfEXT.enabled = false;
206 }
207
208 /*
209 * ---------------------------------------------------------------------
210 * Followings are control functions for Extended Prefix/Link Opaque LSA
211 * parameters management.
212 * ---------------------------------------------------------------------
213 */
214
215 /* Functions to free memory space */
216 static void del_ext_info(void *val)
217 {
218 XFREE(MTYPE_OSPF_EXT_PARAMS, val);
219 }
220
221 /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
222 static uint32_t get_ext_pref_instance_value(void)
223 {
224 static uint32_t seqno = 0;
225
226 if (seqno < MAX_LEGAL_EXT_INSTANCE_NUM)
227 seqno += 1;
228 else
229 seqno = 1; /* Avoid zero. */
230
231 return seqno;
232 }
233
234 /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */
235 static uint32_t get_ext_link_instance_value(void)
236 {
237 static uint32_t seqno = 0;
238
239 if (seqno < MAX_LEGAL_EXT_INSTANCE_NUM)
240 seqno += 1;
241 else
242 seqno = 1; /* Avoid zero. */
243
244 return seqno;
245 }
246
247 /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
248 static struct ext_itf *lookup_ext_by_ifp(struct interface *ifp)
249 {
250 struct listnode *node, *nnode;
251 struct ext_itf *exti;
252
253 for (ALL_LIST_ELEMENTS(OspfEXT.iflist, node, nnode, exti))
254 if (exti->ifp == ifp)
255 return exti;
256
257 return NULL;
258 }
259
260 /* Lookup Extended Prefix/Links by LSA ID from OspfEXT struct iflist */
261 static struct ext_itf *lookup_ext_by_instance(struct ospf_lsa *lsa)
262 {
263 struct listnode *node;
264 struct ext_itf *exti;
265 uint32_t key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr));
266 uint8_t type = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr));
267
268
269 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
270 if ((exti->instance == key) && (exti->type == type))
271 return exti;
272
273 return NULL;
274 }
275
276 /*
277 * ----------------------------------------------------------------------
278 * The underlying subsection defines setters and unsetters to create and
279 * delete tlvs and subtlvs
280 * ----------------------------------------------------------------------
281 */
282
283 /* Extended Prefix TLV - RFC7684 section 2.1 */
284 static void set_ext_prefix(struct ext_itf *exti, uint8_t route_type,
285 uint8_t flags, struct prefix_ipv4 p)
286 {
287
288 TLV_TYPE(exti->prefix) = htons(EXT_TLV_PREFIX);
289 /* Warning: Size must be adjust depending of subTLV's */
290 TLV_LEN(exti->prefix) = htons(EXT_TLV_PREFIX_SIZE);
291 exti->prefix.route_type = route_type;
292 exti->prefix.flags = flags;
293 /* Only Address Family Ipv4 (0) is defined in RFC 7684 */
294 exti->prefix.af = 0;
295 exti->prefix.pref_length = p.prefixlen;
296 exti->prefix.address = p.prefix;
297 }
298
299 /* Extended Link TLV - RFC7684 section 3.1 */
300 static void set_ext_link(struct ext_itf *exti, uint8_t type, struct in_addr id,
301 struct in_addr data)
302 {
303
304 TLV_TYPE(exti->link) = htons(EXT_TLV_LINK);
305 /* Warning: Size must be adjust depending of subTLV's */
306 TLV_LEN(exti->link) = htons(EXT_TLV_LINK_SIZE);
307 exti->link.link_type = type;
308 exti->link.link_id = id;
309 exti->link.link_data = data;
310 }
311
312 /* Prefix SID SubTLV - section 5 */
313 static void set_prefix_sid(struct ext_itf *exti, uint8_t algorithm,
314 uint32_t value, int value_type, uint8_t flags)
315 {
316
317 if ((algorithm != SR_ALGORITHM_SPF)
318 && (algorithm != SR_ALGORITHM_STRICT_SPF)) {
319 zlog_warn("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 zlog_warn("EXT (%s): interface %s is already in use", __func__,
542 ifp ? ifp->name : "-");
543 rc = 0; /* Do nothing here. */
544 return rc;
545 }
546
547 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf));
548
549 /* initialize new information and link back the interface */
550 new->ifp = ifp;
551 new->flags = EXT_LPFLG_LSA_INACTIVE;
552
553 listnode_add(OspfEXT.iflist, new);
554
555 rc = 0;
556 return rc;
557 }
558
559 /* Remove existing Interface from Extended Interface List */
560 static int ospf_ext_link_del_if(struct interface *ifp)
561 {
562 struct ext_itf *exti;
563 int rc = -1;
564
565 exti = lookup_ext_by_ifp(ifp);
566 if (exti != NULL) {
567 struct list *iflist = OspfEXT.iflist;
568
569 /* Dequeue listnode entry from the list. */
570 listnode_delete(iflist, exti);
571
572 XFREE(MTYPE_OSPF_EXT_PARAMS, exti);
573
574 rc = 0;
575 } else {
576 zlog_warn("EXT (%s): interface %s is not found", __func__,
577 ifp ? ifp->name : "-");
578 }
579
580 return rc;
581 }
582
583 /*
584 * Determine if an Interface belongs to an Extended Link Adjacency or LAN Adj.
585 * type and allocate new instance value accordingly
586 */
587 static void ospf_ext_link_ism_change(struct ospf_interface *oi, int old_status)
588 {
589 struct ext_itf *exti;
590
591 /* Get interface information for Segment Routing */
592 exti = lookup_ext_by_ifp(oi->ifp);
593 if (exti == NULL) {
594 zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
595 __func__, IF_NAME(oi));
596 return;
597 }
598
599 /* Determine if interface is related to Adjacency or LAN Adj. SID */
600 if (oi->type != OSPF_IFTYPE_LOOPBACK) {
601 if (oi->state == ISM_DR)
602 exti->stype = LAN_ADJ_SID;
603 else
604 exti->stype = ADJ_SID;
605
606 exti->instance = get_ext_link_instance_value();
607 exti->type = OPAQUE_TYPE_EXTENDED_LINK_LSA;
608
609 zlog_debug("EXT (%s): Set %s SID to interface %s ", __func__,
610 exti->stype == ADJ_SID ? "Adj." : "LAN Adj.",
611 oi->ifp->name);
612 }
613 }
614
615 /*
616 * Determine if an Interface belongs to an Extended Prefix and
617 * allocate new instance value accordingly
618 */
619 static void ospf_ext_pref_ism_change(struct ospf_interface *oi, int old_status)
620 {
621 struct ext_itf *exti;
622
623 /* Get interface information for Segment Routing */
624 exti = lookup_ext_by_ifp(oi->ifp);
625 if (exti == NULL) {
626 zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
627 __func__, IF_NAME(oi));
628 return;
629 }
630
631 /* Determine if interface is related to a Node SID */
632 if (oi->type == OSPF_IFTYPE_LOOPBACK) {
633 exti->stype = PREF_SID;
634 exti->instance = get_ext_pref_instance_value();
635 exti->type = OPAQUE_TYPE_EXTENDED_PREFIX_LSA;
636
637 zlog_debug("EXT (%s): Set Node SID to interface %s ", __func__,
638 oi->ifp->name);
639
640 /* Complete SRDB if the interface belongs to a Prefix */
641 if (OspfEXT.enabled)
642 ospf_sr_update_prefix(oi->ifp, oi->address);
643 }
644 }
645
646 /*
647 * Finish Extended Link configuration and flood corresponding LSA
648 * when OSPF adjacency on this link fire up
649 */
650 static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
651 {
652 struct ospf_interface *oi = nbr->oi;
653 struct ext_itf *exti;
654 uint32_t label;
655
656 /* Process Neighbor only when its state is NSM Full */
657 if (nbr->state != NSM_Full)
658 return;
659
660 /* Get interface information for Segment Routing */
661 exti = lookup_ext_by_ifp(oi->ifp);
662 if (exti == NULL) {
663 zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
664 __func__, IF_NAME(oi));
665 return;
666 }
667
668 if (oi->area == NULL || oi->area->ospf == NULL) {
669 zlog_warn("EXT (%s): Cannot refer to OSPF from OI(%s)",
670 __func__, IF_NAME(oi));
671 return;
672 }
673
674 /* Keep Area information in combination with SR info. */
675 exti->area = oi->area;
676 OspfEXT.area = oi->area;
677
678 /* Process only Adjacency/LAN SID */
679 if (exti->stype == PREF_SID)
680 return;
681
682 switch (oi->state) {
683 case ISM_PointToPoint:
684 /* Segment ID is an Adjacency one */
685 exti->stype = ADJ_SID;
686
687 /* Set Extended Link TLV with link_id == Nbr Router ID */
688 set_ext_link(exti, OSPF_IFTYPE_POINTOPOINT, nbr->router_id,
689 oi->address->u.prefix4);
690
691 /* Set Extended Link Adjacency SubTLVs, backup first */
692 label = get_ext_link_label_value();
693 set_adj_sid(exti, true, label, SID_LABEL);
694 label = get_ext_link_label_value();
695 set_adj_sid(exti, false, label, SID_LABEL);
696 /* And Remote Interface address */
697 set_rmt_itf_addr(exti, nbr->address.u.prefix4);
698
699 break;
700
701 case ISM_DR:
702 /* Segment ID is a LAN Adjacency for the DR only */
703 exti->stype = LAN_ADJ_SID;
704
705 /* Set Extended Link TLV with link_id == DR */
706 set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
707 oi->address->u.prefix4);
708
709 /* Set Extended Link Adjacency SubTLVs, backup first */
710 label = get_ext_link_label_value();
711 set_lan_adj_sid(exti, true, label, SID_LABEL, nbr->router_id);
712 label = get_ext_link_label_value();
713 set_lan_adj_sid(exti, false, label, SID_LABEL, nbr->router_id);
714
715 break;
716
717 case ISM_DROther:
718 case ISM_Backup:
719 /* Segment ID is an Adjacency if not the DR */
720 exti->stype = ADJ_SID;
721
722 /* Set Extended Link TLV with link_id == DR */
723 set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
724 oi->address->u.prefix4);
725
726 /* Set Extended Link Adjacency SubTLVs, backup first */
727 label = get_ext_link_label_value();
728 set_adj_sid(exti, true, label, SID_LABEL);
729 label = get_ext_link_label_value();
730 set_adj_sid(exti, false, label, SID_LABEL);
731
732 break;
733
734 default:
735 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
736 ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA);
737 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
738 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
739 }
740 return;
741 }
742
743 if (IS_DEBUG_OSPF_SR)
744 zlog_debug("EXT (%s): Complete %s SID to interface %s ",
745 __func__,
746 exti->stype == ADJ_SID ? "Adj." : "LAN Adj.",
747 oi->ifp->name);
748
749 /* flood this links params if everything is ok */
750 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
751 if (OspfEXT.enabled) {
752 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
753 ospf_ext_link_lsa_schedule(exti, REFRESH_THIS_LSA);
754 else
755 ospf_ext_link_lsa_schedule(exti, REORIGINATE_THIS_LSA);
756 }
757 }
758
759 /* Callbacks to handle Extended Link Segment Routing LSA information */
760 static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa)
761 {
762 /* Sanity Check */
763 if (lsa == NULL) {
764 zlog_warn("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 zlog_warn("EXT (%s): Abort! LSA is NULL", __func__);
798 return -1;
799 }
800
801 /* Process only Opaque LSA */
802 if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA)
803 && (lsa->data->type != OSPF_OPAQUE_AS_LSA))
804 return 0;
805
806 /* Process only Extended Prefix LSA */
807 if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr))
808 != OPAQUE_TYPE_EXTENDED_PREFIX_LSA)
809 return 0;
810
811 /* Check if it is not my LSA */
812 if (IS_LSA_SELF(lsa))
813 return 0;
814
815 /* Check if Extended is enable */
816 if (!OspfEXT.enabled)
817 return 0;
818
819 /* Call Segment Routing LSA update or deletion */
820 if (!IS_LSA_MAXAGE(lsa))
821 ospf_sr_ext_prefix_lsa_update(lsa);
822 else
823 ospf_sr_ext_prefix_lsa_delete(lsa);
824
825 return 0;
826 }
827
828 /*
829 * -------------------------------------------------------
830 * Followings are OSPF protocol processing functions for
831 * Extended Prefix/Link Opaque LSA
832 * -------------------------------------------------------
833 */
834
835 static void build_tlv_header(struct stream *s, struct tlv_header *tlvh)
836 {
837 stream_put(s, tlvh, sizeof(struct tlv_header));
838 }
839
840 static void build_tlv(struct stream *s, struct tlv_header *tlvh)
841 {
842
843 if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) {
844 build_tlv_header(s, tlvh);
845 stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh));
846 }
847 }
848
849 /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
850 static void ospf_ext_pref_lsa_body_set(struct stream *s, struct ext_itf *exti)
851 {
852
853 /* Sanity check */
854 if ((exti == NULL) || (exti->stype != PREF_SID))
855 return;
856
857 /* Adjust Extended Prefix TLV size */
858 TLV_LEN(exti->prefix) = htons(ntohs(TLV_LEN(exti->node_sid))
859 + EXT_TLV_PREFIX_SIZE + TLV_HDR_SIZE);
860
861 /* Build LSA body for an Extended Prefix TLV */
862 build_tlv_header(s, &exti->prefix.header);
863 stream_put(s, TLV_DATA(&exti->prefix.header), EXT_TLV_PREFIX_SIZE);
864 /* Then add Prefix SID SubTLV */
865 build_tlv(s, &exti->node_sid.header);
866 }
867
868 /* Build an Extended Link Opaque LSA body for extended link TLV */
869 static void ospf_ext_link_lsa_body_set(struct stream *s, struct ext_itf *exti)
870 {
871 size_t size;
872
873 /* Sanity check */
874 if ((exti == NULL)
875 || ((exti->stype != ADJ_SID) && (exti->stype != LAN_ADJ_SID)))
876 return;
877
878 if (exti->stype == ADJ_SID) {
879 /* Adjust Extended Link TLV size for Adj. SID */
880 size = EXT_TLV_LINK_SIZE + 2 * EXT_SUBTLV_ADJ_SID_SIZE
881 + 2 * TLV_HDR_SIZE;
882 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
883 size = size + EXT_SUBTLV_RMT_ITF_ADDR_SIZE
884 + TLV_HDR_SIZE;
885 TLV_LEN(exti->link) = htons(size);
886
887 /* Build LSA body for an Extended Link TLV with Adj. SID */
888 build_tlv_header(s, &exti->link.header);
889 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
890 /* then add Adjacency SubTLVs */
891 build_tlv(s, &exti->adj_sid[1].header);
892 build_tlv(s, &exti->adj_sid[0].header);
893
894 /* Add Cisco experimental SubTLV if interface is PtoP */
895 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
896 build_tlv(s, &exti->rmt_itf_addr.header);
897 } else {
898 /* Adjust Extended Link TLV size for LAN SID */
899 size = EXT_TLV_LINK_SIZE
900 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE + TLV_HDR_SIZE);
901 TLV_LEN(exti->link) = htons(size);
902
903 /* Build LSA body for an Extended Link TLV with LAN SID */
904 build_tlv_header(s, &exti->link.header);
905 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
906 /* then add LAN-Adjacency SubTLVs */
907 build_tlv(s, &exti->lan_sid[1].header);
908 build_tlv(s, &exti->lan_sid[0].header);
909 }
910 }
911
912 /* Create new Extended Prefix opaque-LSA for every extended prefix */
913 static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area,
914 struct ext_itf *exti)
915 {
916 struct stream *s;
917 struct lsa_header *lsah;
918 struct ospf_lsa *new = NULL;
919 struct ospf *top;
920 uint8_t options, lsa_type;
921 struct in_addr lsa_id;
922 struct in_addr router_id;
923 uint32_t tmp;
924 uint16_t length;
925
926 /* Sanity Check */
927 if (exti == NULL)
928 return NULL;
929
930 /* Create a stream for LSA. */
931 s = stream_new(OSPF_MAX_LSA_SIZE);
932 if (s == NULL) {
933 zlog_warn("EXT (%s): stream_new() error", __func__);
934 return NULL;
935 }
936
937 /* Prepare LSA Header */
938 lsah = (struct lsa_header *)STREAM_DATA(s);
939
940 lsa_type = OspfEXT.scope;
941
942 /*
943 * LSA ID is a variable number identifying different instances of
944 * Extended Prefix Opaque LSA from the same router see RFC 7684
945 */
946 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
947 lsa_id.s_addr = htonl(tmp);
948
949 options = OSPF_OPTION_O; /* Don't forget this :-) */
950
951 /* Fix Options and Router ID depending of the flooding scope */
952 if ((OspfEXT.scope == OSPF_OPAQUE_AS_LSA) || (area == NULL)) {
953 options = OSPF_OPTION_E;
954 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
955 router_id.s_addr = top ? top->router_id.s_addr : 0;
956 } else {
957 options |= LSA_OPTIONS_GET(area); /* Get area default option */
958 options |= LSA_OPTIONS_NSSA_GET(area);
959 router_id = area->ospf->router_id;
960 }
961
962 /* Set opaque-LSA header fields. */
963 lsa_header_set(s, options, lsa_type, lsa_id, router_id);
964
965 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
966 zlog_debug(
967 "EXT (%s): LSA[Type%u:%s]: Create an Opaque-LSA "
968 "Extended Prefix Opaque LSA instance",
969 __func__, lsa_type, inet_ntoa(lsa_id));
970
971
972 /* Set opaque-LSA body fields. */
973 ospf_ext_pref_lsa_body_set(s, exti);
974
975 /* Set length. */
976 length = stream_get_endp(s);
977 lsah->length = htons(length);
978
979 /* Now, create an OSPF LSA instance. */
980 new = ospf_lsa_new();
981 if (new == NULL) {
982 zlog_warn("EXT (%s): ospf_lsa_new() error", __func__);
983 stream_free(s);
984 return NULL;
985 }
986 new->data = ospf_lsa_data_new(length);
987 if (new->data == NULL) {
988 zlog_warn("EXT (%s): ospf_lsa_data_new() error", __func__);
989 ospf_lsa_unlock(&new);
990 new = NULL;
991 stream_free(s);
992 return NULL;
993 }
994
995 /* Segment Routing belongs only to default VRF */
996 new->vrf_id = VRF_DEFAULT;
997 new->area = area;
998 SET_FLAG(new->flags, OSPF_LSA_SELF);
999 memcpy(new->data, lsah, length);
1000 stream_free(s);
1001
1002 return new;
1003 }
1004
1005 /* Create new Extended Link opaque-LSA for every extended link TLV */
1006 static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area,
1007 struct ext_itf *exti)
1008 {
1009 struct stream *s;
1010 struct lsa_header *lsah;
1011 struct ospf_lsa *new = NULL;
1012 uint8_t options, lsa_type;
1013 struct in_addr lsa_id;
1014 uint32_t tmp;
1015 uint16_t length;
1016
1017 /* Sanity Check */
1018 if (exti == NULL)
1019 return NULL;
1020
1021 /* Create a stream for LSA. */
1022 s = stream_new(OSPF_MAX_LSA_SIZE);
1023 if (s == NULL) {
1024 zlog_warn("EXT (%s): stream_new() error", __func__);
1025 return NULL;
1026 }
1027 lsah = (struct lsa_header *)STREAM_DATA(s);
1028
1029 options = OSPF_OPTION_O; /* Don't forget this :-) */
1030 options |= LSA_OPTIONS_GET(area); /* Get area default option */
1031 options |= LSA_OPTIONS_NSSA_GET(area);
1032 /* Extended Link Opaque LSA are only flooded within an area */
1033 lsa_type = OSPF_OPAQUE_AREA_LSA;
1034
1035 /*
1036 * LSA ID is a variable number identifying different instances of
1037 * Extended Link Opaque LSA from the same router see RFC 7684
1038 */
1039 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1040 lsa_id.s_addr = htonl(tmp);
1041
1042 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
1043 zlog_debug(
1044 "EXT (%s) LSA[Type%u:%s]: Create an Opaque-LSA "
1045 "Extended Link Opaque LSA instance",
1046 __func__, lsa_type, inet_ntoa(lsa_id));
1047
1048 /* Set opaque-LSA header fields. */
1049 lsa_header_set(s, options, lsa_type, lsa_id, area->ospf->router_id);
1050
1051 /* Set opaque-LSA body fields. */
1052 ospf_ext_link_lsa_body_set(s, exti);
1053
1054 /* Set length. */
1055 length = stream_get_endp(s);
1056 lsah->length = htons(length);
1057
1058 /* Now, create an OSPF LSA instance. */
1059 new = ospf_lsa_new();
1060 if (new == NULL) {
1061 zlog_warn("EXT (%s): ospf_lsa_new() error", __func__);
1062 stream_free(s);
1063 return NULL;
1064 }
1065 new->data = ospf_lsa_data_new(length);
1066 if (new->data == NULL) {
1067 zlog_warn("EXT (%s): ospf_lsa_data_new() error", __func__);
1068 ospf_lsa_unlock(&new);
1069 new = NULL;
1070 stream_free(s);
1071 return NULL;
1072 }
1073
1074 /* Segment Routing belongs only to default VRF */
1075 new->vrf_id = VRF_DEFAULT;
1076 new->area = area;
1077 SET_FLAG(new->flags, OSPF_LSA_SELF);
1078 memcpy(new->data, lsah, length);
1079 stream_free(s);
1080
1081 return new;
1082 }
1083
1084 /*
1085 * Process the origination of an Extended Prefix Opaque LSA
1086 * for every extended prefix TLV
1087 */
1088 static int ospf_ext_pref_lsa_originate1(struct ospf_area *area,
1089 struct ext_itf *exti)
1090 {
1091 struct ospf_lsa *new;
1092 int rc = -1;
1093
1094
1095 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1096 new = ospf_ext_pref_lsa_new(area, exti);
1097 if (new == NULL) {
1098 zlog_warn("EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
1099 return rc;
1100 }
1101
1102 /* Install this LSA into LSDB. */
1103 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
1104 zlog_warn("EXT (%s): ospf_lsa_install() error", __func__);
1105 ospf_lsa_unlock(&new);
1106 return rc;
1107 }
1108
1109 /* Now this Extended Prefix Opaque LSA info parameter entry has
1110 * associated LSA.
1111 */
1112 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1113
1114 /* Update new LSA origination count. */
1115 area->ospf->lsa_originate_count++;
1116
1117 /* Flood new LSA through area. */
1118 ospf_flood_through_area(area, NULL /*nbr */, new);
1119
1120 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1121 char area_id[INET_ADDRSTRLEN];
1122
1123 inet_ntop(AF_INET, &area->area_id, area_id, sizeof(area_id));
1124 zlog_debug(
1125 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1126 "Extended Prefix Opaque LSA: Area(%s), Link(%s)",
1127 __func__, new->data->type, inet_ntoa(new->data->id),
1128 area_id, exti->ifp->name);
1129 ospf_lsa_header_dump(new->data);
1130 }
1131
1132 rc = 0;
1133
1134 return rc;
1135 }
1136
1137 /*
1138 * Process the origination of an Extended Link Opaque LSA
1139 * for every extended link TLV
1140 */
1141 static int ospf_ext_link_lsa_originate1(struct ospf_area *area,
1142 struct ext_itf *exti)
1143 {
1144 struct ospf_lsa *new;
1145 int rc = -1;
1146
1147 /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
1148 new = ospf_ext_link_lsa_new(area, exti);
1149 if (new == NULL) {
1150 zlog_warn("EXT (%s): ospf_ext_link_lsa_new() error", __func__);
1151 return rc;
1152 }
1153
1154 /* Install this LSA into LSDB. */
1155 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
1156 zlog_warn("EXT (%s): ospf_lsa_install() error", __func__);
1157 ospf_lsa_unlock(&new);
1158 return rc;
1159 }
1160
1161 /* Now this link-parameter entry has associated LSA. */
1162 SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1163
1164 /* Update new LSA origination count. */
1165 area->ospf->lsa_originate_count++;
1166
1167 /* Flood new LSA through area. */
1168 ospf_flood_through_area(area, NULL /*nbr */, new);
1169
1170 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1171 char area_id[INET_ADDRSTRLEN];
1172
1173 inet_ntop(AF_INET, &area->area_id, area_id, sizeof(area_id));
1174 zlog_debug(
1175 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1176 "Extended Link Opaque LSA: Area(%s), Link(%s)",
1177 __func__, new->data->type, inet_ntoa(new->data->id),
1178 area_id, exti->ifp->name);
1179 ospf_lsa_header_dump(new->data);
1180 }
1181
1182 rc = 0;
1183
1184 return rc;
1185 }
1186
1187 /* Trigger the origination of Extended Prefix Opaque LSAs */
1188 static int ospf_ext_pref_lsa_originate(void *arg)
1189 {
1190 struct ospf_area *area = (struct ospf_area *)arg;
1191 struct listnode *node;
1192 struct ext_itf *exti;
1193 int rc = -1;
1194
1195 if (!OspfEXT.enabled) {
1196 zlog_info(
1197 "EXT (%s): Segment Routing "
1198 "functionality is Disabled now",
1199 __func__);
1200 rc = 0; /* This is not an error case. */
1201 return rc;
1202 }
1203 if (IS_DEBUG_OSPF_SR)
1204 zlog_debug("EXT (%s): Start Originate Prefix LSA for area %s",
1205 __func__, inet_ntoa(area->area_id));
1206
1207 /* Check if Extended Prefix Opaque LSA is already engaged */
1208 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1209
1210 /* Process only Prefix SID */
1211 if (exti->stype != PREF_SID)
1212 continue;
1213
1214 /* Process only Extended Prefix with valid Area ID */
1215 if ((exti->area == NULL)
1216 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1217 continue;
1218
1219 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1220 if (CHECK_FLAG(exti->flags,
1221 EXT_LPFLG_LSA_FORCED_REFRESH)) {
1222 zlog_warn(
1223 "EXT (%s): Refresh instead of "
1224 "Originate",
1225 __func__);
1226 UNSET_FLAG(exti->flags,
1227 EXT_LPFLG_LSA_FORCED_REFRESH);
1228 ospf_ext_pref_lsa_schedule(exti,
1229 REFRESH_THIS_LSA);
1230 }
1231 continue;
1232 }
1233
1234 /* Ok, let's try to originate an LSA */
1235 if (IS_DEBUG_OSPF_SR)
1236 zlog_debug(
1237 "EXT (%s): Let's finally reoriginate the "
1238 "LSA 7.0.0.%u for Itf %s",
1239 __func__, exti->instance,
1240 exti->ifp ? exti->ifp->name : "");
1241 ospf_ext_pref_lsa_originate1(area, exti);
1242 }
1243
1244 rc = 0;
1245 return rc;
1246 }
1247
1248 /* Trigger the origination of Extended Link Opaque LSAs */
1249 static int ospf_ext_link_lsa_originate(void *arg)
1250 {
1251 struct ospf_area *area = (struct ospf_area *)arg;
1252 struct listnode *node;
1253 struct ext_itf *exti;
1254 int rc = -1;
1255
1256 if (!OspfEXT.enabled) {
1257 zlog_info(
1258 "EXT (%s): Segment Routing "
1259 "functionality is Disabled now",
1260 __func__);
1261 rc = 0; /* This is not an error case. */
1262 return rc;
1263 }
1264
1265 /* Check if Extended Prefix Opaque LSA is already engaged */
1266 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1267 /* Process only Adjacency or LAN SID */
1268 if (exti->stype == PREF_SID)
1269 continue;
1270
1271 /* Process only Extended Link with valid Area ID */
1272 if ((exti->area == NULL)
1273 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1274 continue;
1275
1276 /* Check if LSA not already engaged */
1277 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1278 if (CHECK_FLAG(exti->flags,
1279 EXT_LPFLG_LSA_FORCED_REFRESH)) {
1280 zlog_warn(
1281 "EXT (%s): Refresh instead of "
1282 "Originate",
1283 __func__);
1284 UNSET_FLAG(exti->flags,
1285 EXT_LPFLG_LSA_FORCED_REFRESH);
1286 ospf_ext_link_lsa_schedule(exti,
1287 REFRESH_THIS_LSA);
1288 }
1289 continue;
1290 }
1291
1292 /* Ok, let's try to originate an LSA */
1293 if (IS_DEBUG_OSPF_SR)
1294 zlog_debug(
1295 "EXT (%s): Let's finally reoriginate the "
1296 "LSA 8.0.0.%u for Itf %s through the Area %s",
1297 __func__, exti->instance,
1298 exti->ifp ? exti->ifp->name : "-",
1299 inet_ntoa(area->area_id));
1300 ospf_ext_link_lsa_originate1(area, exti);
1301 }
1302
1303 rc = 0;
1304 return rc;
1305 }
1306
1307 /* Refresh an Extended Prefix Opaque LSA */
1308 static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
1309 {
1310 struct ospf_lsa *new = NULL;
1311 struct ospf_area *area = lsa->area;
1312 struct ospf *top;
1313 struct ext_itf *exti;
1314
1315 if (!OspfEXT.enabled) {
1316 /*
1317 * This LSA must have flushed before due to Extended Prefix
1318 * Opaque LSA status change.
1319 * It seems a slip among routers in the routing domain.
1320 */
1321 zlog_info(
1322 "EXT (%s): Segment Routing functionality is "
1323 "Disabled",
1324 __func__);
1325 /* Flush it anyway. */
1326 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1327 }
1328
1329 /* Lookup this lsa corresponding Extended parameters */
1330 exti = lookup_ext_by_instance(lsa);
1331 if (exti == NULL) {
1332 zlog_warn("EXT (%s): Invalid parameter LSA ID", __func__);
1333 /* Flush it anyway. */
1334 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1335 }
1336
1337 /* Check if Interface was not disable in the interval */
1338 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
1339 zlog_warn("EXT (%s): Interface was Disabled: Flush it!",
1340 __func__);
1341 /* Flush it anyway. */
1342 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1343 }
1344
1345 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1346 if (IS_LSA_MAXAGE(lsa)) {
1347 if (exti)
1348 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1349 ospf_opaque_lsa_flush_schedule(lsa);
1350 return NULL;
1351 }
1352
1353 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
1354 new = ospf_ext_pref_lsa_new(area, exti);
1355
1356 if (new == NULL) {
1357 zlog_warn("EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
1358 return NULL;
1359 }
1360 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1361
1362 /*
1363 * Install this LSA into LSDB
1364 * Given "lsa" will be freed in the next function
1365 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1366 * ospf_lookup() to get ospf instance
1367 */
1368 if (area)
1369 top = area->ospf;
1370 else
1371 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1372
1373 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1374 zlog_warn("EXT (%s): ospf_lsa_install() error", __func__);
1375 ospf_lsa_unlock(&new);
1376 return NULL;
1377 }
1378
1379 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1380 ospf_flood_through_area(area, NULL /*nbr */, new);
1381
1382 /* Debug logging. */
1383 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1384 zlog_debug(
1385 "EXT (%s): LSA[Type%u:%s] Refresh Extended Prefix LSA",
1386 __func__, new->data->type, inet_ntoa(new->data->id));
1387 ospf_lsa_header_dump(new->data);
1388 }
1389
1390 return new;
1391 }
1392
1393 /* Refresh an Extended Link Opaque LSA */
1394 static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
1395 {
1396 struct ext_itf *exti;
1397 struct ospf_area *area = lsa->area;
1398 struct ospf *top = area->ospf;
1399 struct ospf_lsa *new = NULL;
1400
1401 if (!OspfEXT.enabled) {
1402 /*
1403 * This LSA must have flushed before due to OSPF-SR status
1404 * change. It seems a slip among routers in the routing domain.
1405 */
1406 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1407 __func__);
1408 /* Flush it anyway. */
1409 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1410 }
1411
1412 /* Lookup this LSA corresponding Extended parameters */
1413 exti = lookup_ext_by_instance(lsa);
1414 if (exti == NULL) {
1415 zlog_warn("EXT (%s): Invalid parameter LSA ID", __func__);
1416 /* Flush it anyway. */
1417 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1418 }
1419
1420 /* Check if Interface was not disable in the interval */
1421 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
1422 zlog_warn("EXT (%s): Interface was Disabled: Flush it!",
1423 __func__);
1424 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1425 }
1426
1427 /* If the lsa's age reached to MaxAge, start flushing procedure */
1428 if (IS_LSA_MAXAGE(lsa)) {
1429 if (exti)
1430 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1431 ospf_opaque_lsa_flush_schedule(lsa);
1432 return NULL;
1433 }
1434
1435 /* Create new Opaque-LSA/Extended Link instance */
1436 new = ospf_ext_link_lsa_new(area, exti);
1437 if (new == NULL) {
1438 zlog_warn("EXT (%s): Error creating new LSA", __func__);
1439 return NULL;
1440 }
1441 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1442
1443 /* Install this LSA into LSDB. */
1444 /* Given "lsa" will be freed in the next function */
1445 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
1446 zlog_warn("EXT (%s): Error installing new LSA", __func__);
1447 ospf_lsa_unlock(&new);
1448 return NULL;
1449 }
1450
1451 /* Flood updated LSA through the link Area according to the RFC7684 */
1452 ospf_flood_through_area(area, NULL /*nbr */, new);
1453
1454 /* Debug logging. */
1455 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1456 zlog_debug(
1457 "EXT (%s): LSA[Type%u:%s]: Refresh Extended Link LSA",
1458 __func__, new->data->type, inet_ntoa(new->data->id));
1459 ospf_lsa_header_dump(new->data);
1460 }
1461
1462 return new;
1463 }
1464
1465 /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1466 static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
1467 enum lsa_opcode opcode)
1468 {
1469 struct ospf_lsa lsa;
1470 struct lsa_header lsah;
1471 struct ospf *top;
1472 uint32_t tmp;
1473
1474 memset(&lsa, 0, sizeof(lsa));
1475 memset(&lsah, 0, sizeof(lsah));
1476
1477 /* Sanity Check */
1478 if (exti == NULL)
1479 return;
1480
1481 /* Check if the corresponding link is ready to be flooded */
1482 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1483 return;
1484
1485 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1486 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1487 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1488 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1489 exti->ifp ? exti->ifp->name : "-");
1490
1491 /* Set LSA header information */
1492 if (exti->area == NULL) {
1493 zlog_warn(
1494 "EXT (%s): Flooding is Area scope but area is not yet "
1495 "set",
1496 __func__);
1497 if (OspfEXT.area == NULL) {
1498 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1499 OspfEXT.area = ospf_area_lookup_by_area_id(
1500 top, OspfEXT.area_id);
1501 }
1502 exti->area = OspfEXT.area;
1503 }
1504 lsa.area = exti->area;
1505 lsa.data = &lsah;
1506 lsah.type = OSPF_OPAQUE_AREA_LSA;
1507 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
1508 lsah.id.s_addr = htonl(tmp);
1509
1510 switch (opcode) {
1511 case REORIGINATE_THIS_LSA:
1512 ospf_opaque_lsa_reoriginate_schedule(
1513 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1514 OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
1515 break;
1516 case REFRESH_THIS_LSA:
1517 ospf_opaque_lsa_refresh_schedule(&lsa);
1518 break;
1519 case FLUSH_THIS_LSA:
1520 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1521 ospf_opaque_lsa_flush_schedule(&lsa);
1522 break;
1523 default:
1524 zlog_warn("EXT (%s): Unknown opcode", __func__);
1525 break;
1526 }
1527 }
1528
1529 /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1530 static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
1531 enum lsa_opcode opcode)
1532 {
1533 struct ospf_lsa lsa;
1534 struct lsa_header lsah;
1535 struct ospf *top;
1536 uint32_t tmp;
1537
1538 memset(&lsa, 0, sizeof(lsa));
1539 memset(&lsah, 0, sizeof(lsah));
1540
1541 /* Sanity Check */
1542 if (exti == NULL)
1543 return;
1544
1545 /* Check if the corresponding link is ready to be flooded */
1546 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1547 return;
1548
1549 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1550 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1551 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1552 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1553 exti->ifp ? exti->ifp->name : "-");
1554
1555 /* Set LSA header information */
1556 if (exti->area == NULL) {
1557 zlog_warn(
1558 "EXT (%s): Flooding is Area scope but area is not "
1559 "yet set",
1560 __func__);
1561 if (OspfEXT.area == NULL) {
1562 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1563 OspfEXT.area = ospf_area_lookup_by_area_id(
1564 top, OspfEXT.area_id);
1565 }
1566 exti->area = OspfEXT.area;
1567 }
1568 lsa.area = exti->area;
1569 lsa.data = &lsah;
1570 lsah.type = OSPF_OPAQUE_AREA_LSA;
1571 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1572 lsah.id.s_addr = htonl(tmp);
1573
1574 switch (opcode) {
1575 case REORIGINATE_THIS_LSA:
1576 ospf_opaque_lsa_reoriginate_schedule(
1577 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1578 OPAQUE_TYPE_EXTENDED_LINK_LSA);
1579 break;
1580 case REFRESH_THIS_LSA:
1581 ospf_opaque_lsa_refresh_schedule(&lsa);
1582 break;
1583 case FLUSH_THIS_LSA:
1584 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1585 ospf_opaque_lsa_flush_schedule(&lsa);
1586 break;
1587 default:
1588 zlog_warn("EXT (%s): Unknown opcode", __func__);
1589 break;
1590 }
1591 }
1592
1593 /* Schedule Extended Link or Prefix depending of the Type of LSA */
1594 static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op)
1595 {
1596
1597 if (exti->stype == PREF_SID)
1598 ospf_ext_pref_lsa_schedule(exti, op);
1599 else
1600 ospf_ext_link_lsa_schedule(exti, op);
1601 }
1602
1603 /*
1604 * ------------------------------------
1605 * Followings are vty show functions.
1606 * ------------------------------------
1607 */
1608
1609 /* Cisco experimental SubTLV */
1610 static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty *vty,
1611 struct tlv_header *tlvh)
1612 {
1613 struct ext_subtlv_rmt_itf_addr *top;
1614
1615 top = (struct ext_subtlv_rmt_itf_addr *)tlvh;
1616
1617 vty_out(vty,
1618 " Remote Interface Address Sub-TLV: Length %u\n "
1619 "Address: %s\n",
1620 ntohs(top->header.length), inet_ntoa(top->value));
1621
1622 return TLV_SIZE(tlvh);
1623 }
1624
1625 /* Adjacency SID SubTLV */
1626 static uint16_t show_vty_ext_link_adj_sid(struct vty *vty,
1627 struct tlv_header *tlvh)
1628 {
1629 struct ext_subtlv_adj_sid *top = (struct ext_subtlv_adj_sid *)tlvh;
1630
1631 vty_out(vty,
1632 " Adj-SID Sub-TLV: Length %u\n\tFlags: "
1633 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
1634 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1635 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1636 : "Index",
1637 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1638 ? GET_LABEL(ntohl(top->value))
1639 : ntohl(top->value));
1640
1641 return TLV_SIZE(tlvh);
1642 }
1643
1644 /* LAN Adjacency SubTLV */
1645 static uint16_t show_vty_ext_link_lan_adj_sid(struct vty *vty,
1646 struct tlv_header *tlvh)
1647 {
1648 struct ext_subtlv_lan_adj_sid *top =
1649 (struct ext_subtlv_lan_adj_sid *)tlvh;
1650
1651 vty_out(vty,
1652 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: "
1653 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: "
1654 "%s\n\t%s: %u\n",
1655 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1656 inet_ntoa(top->neighbor_id),
1657 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1658 : "Index",
1659 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1660 ? GET_LABEL(ntohl(top->value))
1661 : ntohl(top->value));
1662
1663 return TLV_SIZE(tlvh);
1664 }
1665
1666 static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh)
1667 {
1668 vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1669 ntohs(tlvh->type), ntohs(tlvh->length));
1670
1671 return TLV_SIZE(tlvh);
1672 }
1673
1674 /* Extended Link Sub TLVs */
1675 static uint16_t show_vty_link_info(struct vty *vty, struct tlv_header *ext)
1676 {
1677 struct ext_tlv_link *top = (struct ext_tlv_link *)ext;
1678 struct tlv_header *tlvh;
1679 uint16_t length = ntohs(top->header.length) - 3 * sizeof(uint32_t);
1680 uint16_t sum = 0;
1681
1682 vty_out(vty,
1683 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
1684 " Link ID: %s\n",
1685 ntohs(top->header.length), top->link_type,
1686 inet_ntoa(top->link_id));
1687 vty_out(vty, " Link data: %s\n", inet_ntoa(top->link_data));
1688
1689 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1690 + EXT_TLV_LINK_SIZE);
1691 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1692 switch (ntohs(tlvh->type)) {
1693 case EXT_SUBTLV_ADJ_SID:
1694 sum += show_vty_ext_link_adj_sid(vty, tlvh);
1695 break;
1696 case EXT_SUBTLV_LAN_ADJ_SID:
1697 sum += show_vty_ext_link_lan_adj_sid(vty, tlvh);
1698 break;
1699 case EXT_SUBTLV_RMT_ITF_ADDR:
1700 sum += show_vty_ext_link_rmt_itf_addr(vty, tlvh);
1701 break;
1702 default:
1703 sum += show_vty_unknown_tlv(vty, tlvh);
1704 break;
1705 }
1706 }
1707
1708 return sum + sizeof(struct ext_tlv_link);
1709 }
1710
1711 /* Extended Link TLVs */
1712 static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa)
1713 {
1714 struct lsa_header *lsah = (struct lsa_header *)lsa->data;
1715 struct tlv_header *tlvh;
1716 uint16_t length = 0, sum = 0;
1717
1718 /* Initialize TLV browsing */
1719 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1720
1721 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1722 tlvh = TLV_HDR_NEXT(tlvh)) {
1723 switch (ntohs(tlvh->type)) {
1724 case EXT_TLV_LINK:
1725 sum += show_vty_link_info(vty, tlvh);
1726 break;
1727 default:
1728 sum += show_vty_unknown_tlv(vty, tlvh);
1729 break;
1730 }
1731 }
1732 }
1733
1734 /* Prefix SID SubTLV */
1735 static uint16_t show_vty_ext_pref_pref_sid(struct vty *vty,
1736 struct tlv_header *tlvh)
1737 {
1738 struct ext_subtlv_prefix_sid *top =
1739 (struct ext_subtlv_prefix_sid *)tlvh;
1740
1741 vty_out(vty,
1742 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: "
1743 "%u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
1744 ntohs(top->header.length), top->algorithm, top->flags,
1745 top->mtid,
1746 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) ? "Label"
1747 : "Index",
1748 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG)
1749 ? GET_LABEL(ntohl(top->value))
1750 : ntohl(top->value));
1751
1752 return TLV_SIZE(tlvh);
1753 }
1754
1755 /* Extended Prefix SubTLVs */
1756 static uint16_t show_vty_pref_info(struct vty *vty, struct tlv_header *ext)
1757 {
1758 struct ext_tlv_prefix *top = (struct ext_tlv_prefix *)ext;
1759 struct tlv_header *tlvh;
1760 uint16_t length = ntohs(top->header.length) - 2 * sizeof(uint32_t);
1761 uint16_t sum = 0;
1762
1763 vty_out(vty,
1764 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1765 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%u\n",
1766 ntohs(top->header.length), top->route_type, top->af, top->flags,
1767 inet_ntoa(top->address), top->pref_length);
1768
1769 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1770 + EXT_TLV_PREFIX_SIZE);
1771 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1772 switch (ntohs(tlvh->type)) {
1773 case EXT_SUBTLV_PREFIX_SID:
1774 sum += show_vty_ext_pref_pref_sid(vty, tlvh);
1775 break;
1776 default:
1777 sum += show_vty_unknown_tlv(vty, tlvh);
1778 break;
1779 }
1780 }
1781
1782 return sum + sizeof(struct ext_tlv_prefix);
1783 }
1784
1785 /* Extended Prefix TLVs */
1786 static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa)
1787 {
1788 struct lsa_header *lsah = (struct lsa_header *)lsa->data;
1789 struct tlv_header *tlvh;
1790 uint16_t length = 0, sum = 0;
1791
1792 /* Initialize TLV browsing */
1793 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1794
1795 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1796 tlvh = TLV_HDR_NEXT(tlvh)) {
1797 switch (ntohs(tlvh->type)) {
1798 case EXT_TLV_PREFIX:
1799 sum += show_vty_pref_info(vty, tlvh);
1800 break;
1801 default:
1802 sum += show_vty_unknown_tlv(vty, tlvh);
1803 break;
1804 }
1805 }
1806 }