]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_ext.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / ospfd / ospf_ext.c
CommitLineData
cf9b9f77
OD
1/*
2 * This is an implementation of RFC7684 OSPFv2 Prefix/Link Attribute
3 * Advertisement
4 *
5 * Module name: Extended Prefix/Link Opaque LSA
6 *
cf9b9f77 7 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
7743f2f8 8 * Author: Anselme Sawadogo <anselmesawadogo@gmail.com>
cf9b9f77 9 *
7743f2f8 10 * Copyright (C) 2016 - 2018 Orange Labs http://www.orange.com
cf9b9f77 11 *
7743f2f8
OD
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.
cf9b9f77 16 *
7743f2f8
OD
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.
cf9b9f77 21 *
7743f2f8
OD
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
cf9b9f77
OD
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"
85c9b439 65#include "ospfd/ospf_errors.h"
cf9b9f77
OD
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 */
73static struct ospf_ext_lp OspfEXT;
74
7743f2f8
OD
75/*
76 * -----------------------------------------------------------------------
77 * Followings are initialize/terminate functions for Extended Prefix/Link
78 * Opaque LSA handling.
79 * -----------------------------------------------------------------------
80 */
cf9b9f77
OD
81
82/* Extended Prefix Opaque LSA related callback functions */
7743f2f8 83static void ospf_ext_pref_ism_change(struct ospf_interface *oi, int old_status);
cf9b9f77
OD
84static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa);
85static int ospf_ext_pref_lsa_originate(void *arg);
86static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa);
87static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
88 enum lsa_opcode opcode);
89/* Extended Link Opaque LSA related callback functions */
90static int ospf_ext_link_new_if(struct interface *ifp);
91static int ospf_ext_link_del_if(struct interface *ifp);
92static void ospf_ext_link_ism_change(struct ospf_interface *oi, int old_status);
93static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status);
94static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa);
95static int ospf_ext_link_lsa_originate(void *arg);
96static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa);
97static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
98 enum lsa_opcode opcode);
99static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op);
100static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa);
101static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa);
102static 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 */
111int 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
7743f2f8 123 zlog_info("EXT (%s): Register Extended Link Opaque LSA", __func__);
cf9b9f77
OD
124 rc = ospf_register_opaque_functab(
125 OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_EXTENDED_LINK_LSA,
996c9314
LB
126 ospf_ext_link_new_if, /* new if */
127 ospf_ext_link_del_if, /* del if */
cf9b9f77
OD
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) {
cf444bcf 140 flog_warn(EC_OSPF_OPAQUE_REGISTRATION,
85c9b439 141 "EXT (%s): Failed to register Extended Link LSA",
7743f2f8 142 __func__);
cf9b9f77
OD
143 return rc;
144 }
145
7743f2f8 146 zlog_info("EXT (%s): Register Extended Prefix Opaque LSA", __func__);
cf9b9f77
OD
147 rc = ospf_register_opaque_functab(
148 OspfEXT.scope, OPAQUE_TYPE_EXTENDED_PREFIX_LSA,
7743f2f8
OD
149 NULL, /* new if handle by link */
150 NULL, /* del if handle by link */
151 ospf_ext_pref_ism_change, /* ism change */
cf9b9f77
OD
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) {
cf444bcf 162 flog_warn(EC_OSPF_OPAQUE_REGISTRATION,
85c9b439 163 "EXT (%s): Failed to register Extended Prefix LSA",
7743f2f8 164 __func__);
cf9b9f77
OD
165 return rc;
166 }
167
168 return rc;
169}
170
171/*
172 * Extended Link/Prefix termination function
173 *
bcf4475e 174 * @param - none
cf9b9f77
OD
175 * @return - none
176 */
177void ospf_ext_term(void)
178{
179
89f60109
DS
180 if ((OspfEXT.scope == OSPF_OPAQUE_AREA_LSA)
181 || (OspfEXT.scope == OSPF_OPAQUE_AS_LSA))
bcf4475e
OD
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
6a154c88 188 list_delete(&OspfEXT.iflist);
cf9b9f77
OD
189 OspfEXT.scope = 0;
190 OspfEXT.enabled = false;
191
bcf4475e
OD
192 return;
193}
194
195/*
196 * Extended Link/Prefix finish function
197 *
198 * @param - none
199 * @return - none
200 */
201void ospf_ext_finish(void)
202{
203 // list_delete_all_node(OspfEXT.iflist);
204 OspfEXT.enabled = false;
cf9b9f77
OD
205}
206
7743f2f8
OD
207/*
208 * ---------------------------------------------------------------------
cf9b9f77
OD
209 * Followings are control functions for Extended Prefix/Link Opaque LSA
210 * parameters management.
7743f2f8
OD
211 * ---------------------------------------------------------------------
212 */
213
cf9b9f77
OD
214/* Functions to free memory space */
215static void del_ext_info(void *val)
216{
217 XFREE(MTYPE_OSPF_EXT_PARAMS, val);
cf9b9f77
OD
218}
219
220/* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */
93f0a26e 221static uint32_t get_ext_pref_instance_value(void)
cf9b9f77 222{
93f0a26e 223 static uint32_t seqno = 0;
cf9b9f77
OD
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 */
93f0a26e 234static uint32_t get_ext_link_instance_value(void)
cf9b9f77 235{
93f0a26e 236 static uint32_t seqno = 0;
cf9b9f77
OD
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 */
247static 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 */
260static struct ext_itf *lookup_ext_by_instance(struct ospf_lsa *lsa)
261{
262 struct listnode *node;
263 struct ext_itf *exti;
db28a51f
OD
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
cf9b9f77
OD
267
268 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
db28a51f 269 if ((exti->instance == key) && (exti->type == type))
cf9b9f77
OD
270 return exti;
271
cf9b9f77
OD
272 return NULL;
273}
274
7743f2f8
OD
275/*
276 * ----------------------------------------------------------------------
cf9b9f77
OD
277 * The underlying subsection defines setters and unsetters to create and
278 * delete tlvs and subtlvs
7743f2f8
OD
279 * ----------------------------------------------------------------------
280 */
cf9b9f77
OD
281
282/* Extended Prefix TLV - RFC7684 section 2.1 */
93f0a26e
OD
283static void set_ext_prefix(struct ext_itf *exti, uint8_t route_type,
284 uint8_t flags, struct prefix_ipv4 p)
cf9b9f77
OD
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 */
93f0a26e 299static void set_ext_link(struct ext_itf *exti, uint8_t type, struct in_addr id,
cf9b9f77
OD
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 */
93f0a26e 312static void set_prefix_sid(struct ext_itf *exti, uint8_t algorithm,
7743f2f8 313 uint32_t value, int value_type, uint8_t flags)
cf9b9f77
OD
314{
315
cf9b9f77
OD
316 if ((algorithm != SR_ALGORITHM_SPF)
317 && (algorithm != SR_ALGORITHM_STRICT_SPF)) {
cf444bcf 318 flog_err(EC_OSPF_INVALID_ALGORITHM,
89f60109
DS
319 "EXT (%s): unrecognized algorithm, not SPF or S-SPF",
320 __func__);
cf9b9f77
OD
321 return;
322 }
323
7743f2f8 324 /* Update flags according to the type of value field: label or index */
cf9b9f77 325 if (value_type == SID_LABEL)
7743f2f8 326 SET_FLAG(flags, EXT_SUBTLV_PREFIX_SID_VFLG);
cf9b9f77
OD
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) {
d922605d
OD
336 TLV_LEN(exti->node_sid) =
337 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE));
cf9b9f77
OD
338 exti->node_sid.value = htonl(SET_LABEL(value));
339 } else {
d922605d
OD
340 TLV_LEN(exti->node_sid) =
341 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE));
cf9b9f77
OD
342 exti->node_sid.value = htonl(value);
343 }
cf9b9f77
OD
344}
345
346/* Adjacency SID SubTLV - section 6.1 */
93f0a26e 347static void set_adj_sid(struct ext_itf *exti, bool backup, uint32_t value,
cf9b9f77
OD
348 int value_type)
349{
350 int index;
93f0a26e 351 uint8_t flags;
cf9b9f77
OD
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);
d922605d
OD
373 TLV_LEN(exti->adj_sid[index]) =
374 htons(SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE));
cf9b9f77
OD
375 exti->adj_sid[index].value = htonl(SET_LABEL(value));
376 } else {
377 UNSET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
d922605d
OD
378 TLV_LEN(exti->adj_sid[index]) =
379 htons(SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE));
cf9b9f77
OD
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 */
cf9b9f77
OD
386}
387
388/* LAN Adjacency SID SubTLV - section 6.2 */
93f0a26e 389static void set_lan_adj_sid(struct ext_itf *exti, bool backup, uint32_t value,
cf9b9f77
OD
390 int value_type, struct in_addr neighbor_id)
391{
392
393 int index;
93f0a26e 394 uint8_t flags;
cf9b9f77
OD
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 */
d922605d 406 TLV_TYPE(exti->lan_sid[index]) = htons(EXT_SUBTLV_LAN_ADJ_SID);
cf9b9f77
OD
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);
d922605d
OD
414 TLV_LEN(exti->lan_sid[index]) =
415 htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE));
cf9b9f77
OD
416 exti->lan_sid[index].value = htonl(SET_LABEL(value));
417 } else {
418 UNSET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG);
d922605d
OD
419 TLV_LEN(exti->lan_sid[index]) =
420 htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE));
cf9b9f77
OD
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;
cf9b9f77
OD
428}
429
430/* Experimental SubTLV from Cisco */
431static 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;
cf9b9f77
OD
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 */
db28a51f 449uint32_t ospf_ext_schedule_prefix_index(struct interface *ifp, uint32_t index,
996c9314 450 struct prefix_ipv4 *p, uint8_t flags)
cf9b9f77
OD
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(
7743f2f8
OD
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);
cf9b9f77
OD
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);
7743f2f8 471 set_prefix_sid(exti, SR_ALGORITHM_SPF, index, SID_INDEX, flags);
cf9b9f77
OD
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)
996c9314
LB
481 zlog_debug("EXT (%s): Remove prefix for interface %s",
482 __func__, ifp->name);
cf9b9f77
OD
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
db28a51f 491 return SET_OPAQUE_LSID(exti->type, exti->instance);
cf9b9f77
OD
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 */
501void ospf_ext_update_sr(bool enable)
502{
503 struct listnode *node;
504 struct ext_itf *exti;
505
506 if (IS_DEBUG_OSPF_SR)
996c9314
LB
507 zlog_debug("EXT (%s): %s Extended LSAs for Segment Routing ",
508 __func__, enable ? "Enable" : "Disable");
cf9b9f77
OD
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}
7743f2f8
OD
528/*
529 * -----------------------------------------------------------------------
530 * Followings are callback functions against generic Opaque-LSAs handling
531 * -----------------------------------------------------------------------
532 */
cf9b9f77
OD
533
534/* Add new Interface in Extended Interface List */
535static 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) {
cf9b9f77
OD
541 rc = 0; /* Do nothing here. */
542 return rc;
543 }
544
545 new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf));
cf9b9f77
OD
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 */
558static int ospf_ext_link_del_if(struct interface *ifp)
559{
560 struct ext_itf *exti;
561 int rc = -1;
562
7743f2f8
OD
563 exti = lookup_ext_by_ifp(ifp);
564 if (exti != NULL) {
cf9b9f77
OD
565 struct list *iflist = OspfEXT.iflist;
566
cf9b9f77
OD
567 /* Dequeue listnode entry from the list. */
568 listnode_delete(iflist, exti);
569
cf9b9f77
OD
570 XFREE(MTYPE_OSPF_EXT_PARAMS, exti);
571
572 rc = 0;
573 } else {
cf444bcf 574 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 575 "EXT (%s): interface %s is not found", __func__,
996c9314 576 ifp ? ifp->name : "-");
cf9b9f77
OD
577 }
578
579 return rc;
580}
581
7743f2f8
OD
582/*
583 * Determine if an Interface belongs to an Extended Link Adjacency or LAN Adj.
584 * type and allocate new instance value accordingly
585 */
586static void ospf_ext_link_ism_change(struct ospf_interface *oi, int old_status)
cf9b9f77
OD
587{
588 struct ext_itf *exti;
cf9b9f77 589
7743f2f8
OD
590 /* Get interface information for Segment Routing */
591 exti = lookup_ext_by_ifp(oi->ifp);
89f60109 592 if (exti == NULL)
7743f2f8 593 return;
cf9b9f77 594
7743f2f8
OD
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;
cf9b9f77 601
7743f2f8 602 exti->instance = get_ext_link_instance_value();
db28a51f 603 exti->type = OPAQUE_TYPE_EXTENDED_LINK_LSA;
cf9b9f77 604
996c9314
LB
605 zlog_debug("EXT (%s): Set %s SID to interface %s ", __func__,
606 exti->stype == ADJ_SID ? "Adj." : "LAN Adj.",
607 oi->ifp->name);
cf9b9f77 608 }
cf9b9f77
OD
609}
610
611/*
7743f2f8 612 * Determine if an Interface belongs to an Extended Prefix and
cf9b9f77
OD
613 * allocate new instance value accordingly
614 */
7743f2f8 615static void ospf_ext_pref_ism_change(struct ospf_interface *oi, int old_status)
cf9b9f77
OD
616{
617 struct ext_itf *exti;
618
619 /* Get interface information for Segment Routing */
7743f2f8
OD
620 exti = lookup_ext_by_ifp(oi->ifp);
621 if (exti == NULL) {
cf444bcf 622 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 623 "EXT (%s): Cannot get Extended info. from OI(%s)",
996c9314 624 __func__, IF_NAME(oi));
cf9b9f77
OD
625 return;
626 }
627
7743f2f8 628 /* Determine if interface is related to a Node SID */
cf9b9f77
OD
629 if (oi->type == OSPF_IFTYPE_LOOPBACK) {
630 exti->stype = PREF_SID;
631 exti->instance = get_ext_pref_instance_value();
db28a51f 632 exti->type = OPAQUE_TYPE_EXTENDED_PREFIX_LSA;
7743f2f8 633
996c9314
LB
634 zlog_debug("EXT (%s): Set Node SID to interface %s ", __func__,
635 oi->ifp->name);
7743f2f8
OD
636
637 /* Complete SRDB if the interface belongs to a Prefix */
62c99790
OD
638 if (OspfEXT.enabled)
639 ospf_sr_update_prefix(oi->ifp, oi->address);
cf9b9f77 640 }
cf9b9f77
OD
641}
642
643/*
644 * Finish Extended Link configuration and flood corresponding LSA
645 * when OSPF adjacency on this link fire up
646 */
647static 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;
93f0a26e 651 uint32_t label;
cf9b9f77
OD
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 */
7743f2f8
OD
658 exti = lookup_ext_by_ifp(oi->ifp);
659 if (exti == NULL) {
cf444bcf 660 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 661 "EXT (%s): Cannot get Extended info. from OI(%s)",
996c9314 662 __func__, IF_NAME(oi));
cf9b9f77
OD
663 return;
664 }
665
666 if (oi->area == NULL || oi->area->ospf == NULL) {
cf444bcf 667 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 668 "EXT (%s): Cannot refer to OSPF from OI(%s)",
996c9314 669 __func__, IF_NAME(oi));
cf9b9f77
OD
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
7743f2f8 742 if (IS_DEBUG_OSPF_SR)
996c9314
LB
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);
7743f2f8 747
cf9b9f77
OD
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 }
cf9b9f77
OD
756}
757
758/* Callbacks to handle Extended Link Segment Routing LSA information */
759static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa)
760{
761 /* Sanity Check */
762 if (lsa == NULL) {
cf444bcf 763 flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL",
ade6974d 764 __func__);
cf9b9f77
OD
765 return -1;
766 }
767
6aaf0fdd
OD
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
cf9b9f77
OD
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 */
792static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa)
793{
794
795 /* Sanity Check */
796 if (lsa == NULL) {
cf444bcf 797 flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL",
ade6974d 798 __func__);
cf9b9f77
OD
799 return -1;
800 }
801
6aaf0fdd
OD
802 /* Process only Opaque LSA */
803 if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA)
804 && (lsa->data->type != OSPF_OPAQUE_AS_LSA))
7743f2f8
OD
805 return 0;
806
cf9b9f77
OD
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
6aaf0fdd
OD
812 /* Check if it is not my LSA */
813 if (IS_LSA_SELF(lsa))
814 return 0;
815
cf9b9f77
OD
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
7743f2f8
OD
829/*
830 * -------------------------------------------------------
cf9b9f77
OD
831 * Followings are OSPF protocol processing functions for
832 * Extended Prefix/Link Opaque LSA
7743f2f8
OD
833 * -------------------------------------------------------
834 */
cf9b9f77
OD
835
836static void build_tlv_header(struct stream *s, struct tlv_header *tlvh)
837{
838 stream_put(s, tlvh, sizeof(struct tlv_header));
cf9b9f77
OD
839}
840
841static 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 }
cf9b9f77
OD
848}
849
850/* Build an Extended Prefix Opaque LSA body for extended prefix TLV */
851static 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 */
996c9314
LB
859 TLV_LEN(exti->prefix) = htons(ntohs(TLV_LEN(exti->node_sid))
860 + EXT_TLV_PREFIX_SIZE + TLV_HDR_SIZE);
cf9b9f77
OD
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);
cf9b9f77
OD
867}
868
869/* Build an Extended Link Opaque LSA body for extended link TLV */
870static void ospf_ext_link_lsa_body_set(struct stream *s, struct ext_itf *exti)
871{
7743f2f8 872 size_t size;
cf9b9f77
OD
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 */
7743f2f8 881 size = EXT_TLV_LINK_SIZE + 2 * EXT_SUBTLV_ADJ_SID_SIZE
996c9314 882 + 2 * TLV_HDR_SIZE;
7743f2f8
OD
883 if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0)
884 size = size + EXT_SUBTLV_RMT_ITF_ADDR_SIZE
996c9314 885 + TLV_HDR_SIZE;
7743f2f8 886 TLV_LEN(exti->link) = htons(size);
cf9b9f77
OD
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);
d922605d 891 /* then add Adjacency SubTLVs */
cf9b9f77
OD
892 build_tlv(s, &exti->adj_sid[1].header);
893 build_tlv(s, &exti->adj_sid[0].header);
7743f2f8
OD
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);
cf9b9f77
OD
898 } else {
899 /* Adjust Extended Link TLV size for LAN SID */
7743f2f8 900 size = EXT_TLV_LINK_SIZE
996c9314 901 + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE + TLV_HDR_SIZE);
7743f2f8 902 TLV_LEN(exti->link) = htons(size);
cf9b9f77
OD
903
904 /* Build LSA body for an Extended Link TLV with LAN SID */
905 build_tlv_header(s, &exti->link.header);
d922605d
OD
906 stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE);
907 /* then add LAN-Adjacency SubTLVs */
cf9b9f77
OD
908 build_tlv(s, &exti->lan_sid[1].header);
909 build_tlv(s, &exti->lan_sid[0].header);
910 }
cf9b9f77
OD
911}
912
913/* Create new Extended Prefix opaque-LSA for every extended prefix */
914static 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;
7743f2f8 920 struct ospf *top;
d7c0a89a 921 uint8_t options, lsa_type;
cf9b9f77
OD
922 struct in_addr lsa_id;
923 struct in_addr router_id;
93f0a26e
OD
924 uint32_t tmp;
925 uint16_t length;
cf9b9f77 926
fd3b19f2
OD
927 /* Sanity Check */
928 if (exti == NULL)
929 return NULL;
930
cf9b9f77 931 /* Create a stream for LSA. */
7743f2f8 932 s = stream_new(OSPF_MAX_LSA_SIZE);
cf9b9f77
OD
933
934 /* Prepare LSA Header */
935 lsah = (struct lsa_header *)STREAM_DATA(s);
936
937 lsa_type = OspfEXT.scope;
938
7743f2f8
OD
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 */
cf9b9f77
OD
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;
7743f2f8
OD
951 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
952 router_id.s_addr = top ? top->router_id.s_addr : 0;
cf9b9f77
OD
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(
7743f2f8
OD
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));
cf9b9f77
OD
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. */
5b3d4186 977 new = ospf_lsa_new_and_data(length);
cf9b9f77 978
7743f2f8
OD
979 /* Segment Routing belongs only to default VRF */
980 new->vrf_id = VRF_DEFAULT;
cf9b9f77
OD
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 */
990static 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;
d7c0a89a 996 uint8_t options, lsa_type;
cf9b9f77 997 struct in_addr lsa_id;
93f0a26e
OD
998 uint32_t tmp;
999 uint16_t length;
cf9b9f77 1000
fd3b19f2
OD
1001 /* Sanity Check */
1002 if (exti == NULL)
1003 return NULL;
1004
cf9b9f77 1005 /* Create a stream for LSA. */
7743f2f8 1006 s = stream_new(OSPF_MAX_LSA_SIZE);
cf9b9f77
OD
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
7743f2f8
OD
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 */
cf9b9f77
OD
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(
7743f2f8
OD
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));
cf9b9f77
OD
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. */
5b3d4186 1039 new = ospf_lsa_new_and_data(length);
cf9b9f77 1040
7743f2f8
OD
1041 /* Segment Routing belongs only to default VRF */
1042 new->vrf_id = VRF_DEFAULT;
cf9b9f77
OD
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
7743f2f8
OD
1051/*
1052 * Process the origination of an Extended Prefix Opaque LSA
1053 * for every extended prefix TLV
1054 */
cf9b9f77
OD
1055static 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. */
7743f2f8
OD
1063 new = ospf_ext_pref_lsa_new(area, exti);
1064 if (new == NULL) {
cf444bcf 1065 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 1066 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
cf9b9f77
OD
1067 return rc;
1068 }
1069
1070 /* Install this LSA into LSDB. */
1071 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
cf444bcf 1072 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
542a208f 1073 "EXT (%s): ospf_lsa_install() error", __func__);
cf9b9f77
OD
1074 ospf_lsa_unlock(&new);
1075 return rc;
1076 }
1077
1078 /* Now this Extended Prefix Opaque LSA info parameter entry has
7743f2f8
OD
1079 * associated LSA.
1080 */
cf9b9f77
OD
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];
7743f2f8 1091
e4407ea6 1092 inet_ntop(AF_INET, &area->area_id, area_id, sizeof(area_id));
cf9b9f77 1093 zlog_debug(
7743f2f8
OD
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);
cf9b9f77
OD
1098 ospf_lsa_header_dump(new->data);
1099 }
1100
1101 rc = 0;
1102
1103 return rc;
1104}
1105
7743f2f8
OD
1106/*
1107 * Process the origination of an Extended Link Opaque LSA
1108 * for every extended link TLV
1109 */
cf9b9f77
OD
1110static 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. */
7743f2f8
OD
1117 new = ospf_ext_link_lsa_new(area, exti);
1118 if (new == NULL) {
cf444bcf 1119 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 1120 "EXT (%s): ospf_ext_link_lsa_new() error", __func__);
cf9b9f77
OD
1121 return rc;
1122 }
1123
1124 /* Install this LSA into LSDB. */
1125 if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
cf444bcf 1126 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
542a208f 1127 "EXT (%s): ospf_lsa_install() error", __func__);
cf9b9f77
OD
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];
7743f2f8 1143
e4407ea6 1144 inet_ntop(AF_INET, &area->area_id, area_id, sizeof(area_id));
cf9b9f77 1145 zlog_debug(
7743f2f8
OD
1146 "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
1147 "Extended Link Opaque LSA: Area(%s), Link(%s)",
996c9314
LB
1148 __func__, new->data->type, inet_ntoa(new->data->id),
1149 area_id, exti->ifp->name);
cf9b9f77
OD
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 */
1159static 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(
7743f2f8 1168 "EXT (%s): Segment Routing "
996c9314
LB
1169 "functionality is Disabled now",
1170 __func__);
cf9b9f77
OD
1171 rc = 0; /* This is not an error case. */
1172 return rc;
1173 }
1174 if (IS_DEBUG_OSPF_SR)
996c9314
LB
1175 zlog_debug("EXT (%s): Start Originate Prefix LSA for area %s",
1176 __func__, inet_ntoa(area->area_id));
cf9b9f77
OD
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)) {
ade6974d 1193 flog_warn(
cf444bcf 1194 EC_OSPF_EXT_LSA_UNEXPECTED,
ade6974d 1195 "EXT (%s): Refresh instead of Originate",
996c9314 1196 __func__);
cf9b9f77
OD
1197 UNSET_FLAG(exti->flags,
1198 EXT_LPFLG_LSA_FORCED_REFRESH);
1199 ospf_ext_pref_lsa_schedule(exti,
1200 REFRESH_THIS_LSA);
1201 }
1202 continue;
1203 }
1204
1205 /* Ok, let's try to originate an LSA */
1206 if (IS_DEBUG_OSPF_SR)
1207 zlog_debug(
7743f2f8
OD
1208 "EXT (%s): Let's finally reoriginate the "
1209 "LSA 7.0.0.%u for Itf %s",
1210 __func__, exti->instance,
cf9b9f77
OD
1211 exti->ifp ? exti->ifp->name : "");
1212 ospf_ext_pref_lsa_originate1(area, exti);
1213 }
1214
1215 rc = 0;
1216 return rc;
1217}
1218
1219/* Trigger the origination of Extended Link Opaque LSAs */
1220static int ospf_ext_link_lsa_originate(void *arg)
1221{
1222 struct ospf_area *area = (struct ospf_area *)arg;
1223 struct listnode *node;
1224 struct ext_itf *exti;
1225 int rc = -1;
1226
1227 if (!OspfEXT.enabled) {
1228 zlog_info(
7743f2f8 1229 "EXT (%s): Segment Routing "
996c9314
LB
1230 "functionality is Disabled now",
1231 __func__);
cf9b9f77
OD
1232 rc = 0; /* This is not an error case. */
1233 return rc;
1234 }
1235
1236 /* Check if Extended Prefix Opaque LSA is already engaged */
1237 for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
1238 /* Process only Adjacency or LAN SID */
1239 if (exti->stype == PREF_SID)
1240 continue;
1241
1242 /* Process only Extended Link with valid Area ID */
1243 if ((exti->area == NULL)
1244 || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
1245 continue;
1246
1247 /* Check if LSA not already engaged */
1248 if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
1249 if (CHECK_FLAG(exti->flags,
1250 EXT_LPFLG_LSA_FORCED_REFRESH)) {
ade6974d 1251 flog_warn(
cf444bcf 1252 EC_OSPF_EXT_LSA_UNEXPECTED,
ade6974d
QY
1253 "EXT (%s): Refresh instead of Originate",
1254 __func__);
cf9b9f77
OD
1255 UNSET_FLAG(exti->flags,
1256 EXT_LPFLG_LSA_FORCED_REFRESH);
1257 ospf_ext_link_lsa_schedule(exti,
1258 REFRESH_THIS_LSA);
1259 }
1260 continue;
1261 }
1262
1263 /* Ok, let's try to originate an LSA */
1264 if (IS_DEBUG_OSPF_SR)
1265 zlog_debug(
7743f2f8
OD
1266 "EXT (%s): Let's finally reoriginate the "
1267 "LSA 8.0.0.%u for Itf %s through the Area %s",
1268 __func__, exti->instance,
cf9b9f77
OD
1269 exti->ifp ? exti->ifp->name : "-",
1270 inet_ntoa(area->area_id));
1271 ospf_ext_link_lsa_originate1(area, exti);
1272 }
1273
1274 rc = 0;
1275 return rc;
1276}
1277
1278/* Refresh an Extended Prefix Opaque LSA */
1279static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
1280{
1281 struct ospf_lsa *new = NULL;
1282 struct ospf_area *area = lsa->area;
1283 struct ospf *top;
1284 struct ext_itf *exti;
1285
1286 if (!OspfEXT.enabled) {
1287 /*
1288 * This LSA must have flushed before due to Extended Prefix
1289 * Opaque LSA status change.
1290 * It seems a slip among routers in the routing domain.
1291 */
7743f2f8
OD
1292 zlog_info(
1293 "EXT (%s): Segment Routing functionality is "
996c9314
LB
1294 "Disabled",
1295 __func__);
cf9b9f77
OD
1296 /* Flush it anyway. */
1297 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1298 }
1299
1300 /* Lookup this lsa corresponding Extended parameters */
7743f2f8
OD
1301 exti = lookup_ext_by_instance(lsa);
1302 if (exti == NULL) {
cf444bcf 1303 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 1304 "EXT (%s): Invalid parameter LSA ID", __func__);
cf9b9f77
OD
1305 /* Flush it anyway. */
1306 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1307 }
1308
1309 /* Check if Interface was not disable in the interval */
1310 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
cf444bcf 1311 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 1312 "EXT (%s): Interface was Disabled: Flush it!",
996c9314 1313 __func__);
cf9b9f77
OD
1314 /* Flush it anyway. */
1315 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1316 }
1317
1318 /* If the lsa's age reached to MaxAge, start flushing procedure. */
1319 if (IS_LSA_MAXAGE(lsa)) {
1320 if (exti)
1321 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1322 ospf_opaque_lsa_flush_schedule(lsa);
1323 return NULL;
1324 }
1325
1326 /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
db28a51f 1327 new = ospf_ext_pref_lsa_new(area, exti);
cf9b9f77
OD
1328
1329 if (new == NULL) {
cf444bcf 1330 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 1331 "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
cf9b9f77
OD
1332 return NULL;
1333 }
1334 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1335
7743f2f8
OD
1336 /*
1337 * Install this LSA into LSDB
1338 * Given "lsa" will be freed in the next function
1339 * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use
1340 * ospf_lookup() to get ospf instance
1341 */
cf9b9f77
OD
1342 if (area)
1343 top = area->ospf;
1344 else
1345 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1346
1347 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
cf444bcf 1348 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
542a208f 1349 "EXT (%s): ospf_lsa_install() error", __func__);
cf9b9f77
OD
1350 ospf_lsa_unlock(&new);
1351 return NULL;
1352 }
1353
1354 /* Flood updated LSA through the Prefix Area according to the RFC7684 */
1355 ospf_flood_through_area(area, NULL /*nbr */, new);
1356
1357 /* Debug logging. */
1358 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
7743f2f8
OD
1359 zlog_debug(
1360 "EXT (%s): LSA[Type%u:%s] Refresh Extended Prefix LSA",
1361 __func__, new->data->type, inet_ntoa(new->data->id));
cf9b9f77
OD
1362 ospf_lsa_header_dump(new->data);
1363 }
1364
1365 return new;
1366}
1367
1368/* Refresh an Extended Link Opaque LSA */
1369static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
1370{
1371 struct ext_itf *exti;
1372 struct ospf_area *area = lsa->area;
1373 struct ospf *top = area->ospf;
1374 struct ospf_lsa *new = NULL;
1375
1376 if (!OspfEXT.enabled) {
1377 /*
1378 * This LSA must have flushed before due to OSPF-SR status
1379 * change. It seems a slip among routers in the routing domain.
1380 */
996c9314
LB
1381 zlog_info("EXT (%s): Segment Routing functionality is Disabled",
1382 __func__);
cf9b9f77
OD
1383 /* Flush it anyway. */
1384 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1385 }
1386
7743f2f8
OD
1387 /* Lookup this LSA corresponding Extended parameters */
1388 exti = lookup_ext_by_instance(lsa);
1389 if (exti == NULL) {
cf444bcf 1390 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 1391 "EXT (%s): Invalid parameter LSA ID", __func__);
cf9b9f77
OD
1392 /* Flush it anyway. */
1393 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1394 }
1395
1396 /* Check if Interface was not disable in the interval */
1397 if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
cf444bcf 1398 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 1399 "EXT (%s): Interface was Disabled: Flush it!",
996c9314 1400 __func__);
cf9b9f77
OD
1401 lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
1402 }
1403
7743f2f8 1404 /* If the lsa's age reached to MaxAge, start flushing procedure */
cf9b9f77
OD
1405 if (IS_LSA_MAXAGE(lsa)) {
1406 if (exti)
1407 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1408 ospf_opaque_lsa_flush_schedule(lsa);
1409 return NULL;
1410 }
1411
7743f2f8
OD
1412 /* Create new Opaque-LSA/Extended Link instance */
1413 new = ospf_ext_link_lsa_new(area, exti);
1414 if (new == NULL) {
cf444bcf 1415 flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
89f60109 1416 "EXT (%s): Error creating new LSA", __func__);
cf9b9f77
OD
1417 return NULL;
1418 }
1419 new->data->ls_seqnum = lsa_seqnum_increment(lsa);
1420
1421 /* Install this LSA into LSDB. */
7743f2f8 1422 /* Given "lsa" will be freed in the next function */
cf9b9f77 1423 if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
cf444bcf 1424 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
542a208f 1425 "EXT (%s): Error installing new LSA", __func__);
cf9b9f77
OD
1426 ospf_lsa_unlock(&new);
1427 return NULL;
1428 }
1429
1430 /* Flood updated LSA through the link Area according to the RFC7684 */
1431 ospf_flood_through_area(area, NULL /*nbr */, new);
1432
1433 /* Debug logging. */
1434 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
1435 zlog_debug(
7743f2f8
OD
1436 "EXT (%s): LSA[Type%u:%s]: Refresh Extended Link LSA",
1437 __func__, new->data->type, inet_ntoa(new->data->id));
cf9b9f77
OD
1438 ospf_lsa_header_dump(new->data);
1439 }
1440
1441 return new;
1442}
1443
1444/* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */
1445static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
1446 enum lsa_opcode opcode)
1447{
1448 struct ospf_lsa lsa;
1449 struct lsa_header lsah;
1450 struct ospf *top;
93f0a26e 1451 uint32_t tmp;
cf9b9f77
OD
1452
1453 memset(&lsa, 0, sizeof(lsa));
1454 memset(&lsah, 0, sizeof(lsah));
1455
1456 /* Sanity Check */
1457 if (exti == NULL)
1458 return;
1459
1460 /* Check if the corresponding link is ready to be flooded */
1461 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1462 return;
1463
996c9314
LB
1464 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1465 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1466 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1467 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1468 exti->ifp ? exti->ifp->name : "-");
cf9b9f77
OD
1469
1470 /* Set LSA header information */
1471 if (exti->area == NULL) {
ade6974d 1472 flog_warn(
cf444bcf 1473 EC_OSPF_EXT_LSA_UNEXPECTED,
ade6974d
QY
1474 "EXT (%s): Flooding is Area scope but area is not yet set",
1475 __func__);
cf9b9f77
OD
1476 if (OspfEXT.area == NULL) {
1477 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1478 OspfEXT.area = ospf_area_lookup_by_area_id(
1479 top, OspfEXT.area_id);
1480 }
1481 exti->area = OspfEXT.area;
1482 }
1483 lsa.area = exti->area;
1484 lsa.data = &lsah;
1485 lsah.type = OSPF_OPAQUE_AREA_LSA;
1486 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance);
1487 lsah.id.s_addr = htonl(tmp);
1488
1489 switch (opcode) {
1490 case REORIGINATE_THIS_LSA:
1491 ospf_opaque_lsa_reoriginate_schedule(
1492 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1493 OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
1494 break;
1495 case REFRESH_THIS_LSA:
1496 ospf_opaque_lsa_refresh_schedule(&lsa);
1497 break;
1498 case FLUSH_THIS_LSA:
1499 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1500 ospf_opaque_lsa_flush_schedule(&lsa);
1501 break;
cf9b9f77 1502 }
cf9b9f77
OD
1503}
1504
1505/* Schedule Extended Link Opaque LSA origination/refreshment/flushing */
1506static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
1507 enum lsa_opcode opcode)
1508{
1509 struct ospf_lsa lsa;
1510 struct lsa_header lsah;
1511 struct ospf *top;
93f0a26e 1512 uint32_t tmp;
cf9b9f77
OD
1513
1514 memset(&lsa, 0, sizeof(lsa));
1515 memset(&lsah, 0, sizeof(lsah));
1516
1517 /* Sanity Check */
1518 if (exti == NULL)
1519 return;
1520
1521 /* Check if the corresponding link is ready to be flooded */
1522 if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
1523 return;
1524
996c9314
LB
1525 zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
1526 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
1527 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
1528 opcode == FLUSH_THIS_LSA ? "Flush" : "",
1529 exti->ifp ? exti->ifp->name : "-");
cf9b9f77
OD
1530
1531 /* Set LSA header information */
1532 if (exti->area == NULL) {
ade6974d 1533 flog_warn(
cf444bcf 1534 EC_OSPF_EXT_LSA_UNEXPECTED,
ade6974d
QY
1535 "EXT (%s): Flooding is Area scope but area is not yet set",
1536 __func__);
cf9b9f77
OD
1537 if (OspfEXT.area == NULL) {
1538 top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
1539 OspfEXT.area = ospf_area_lookup_by_area_id(
1540 top, OspfEXT.area_id);
1541 }
1542 exti->area = OspfEXT.area;
1543 }
1544 lsa.area = exti->area;
1545 lsa.data = &lsah;
1546 lsah.type = OSPF_OPAQUE_AREA_LSA;
1547 tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
1548 lsah.id.s_addr = htonl(tmp);
1549
1550 switch (opcode) {
1551 case REORIGINATE_THIS_LSA:
1552 ospf_opaque_lsa_reoriginate_schedule(
1553 (void *)exti->area, OSPF_OPAQUE_AREA_LSA,
1554 OPAQUE_TYPE_EXTENDED_LINK_LSA);
1555 break;
1556 case REFRESH_THIS_LSA:
1557 ospf_opaque_lsa_refresh_schedule(&lsa);
1558 break;
1559 case FLUSH_THIS_LSA:
1560 UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
1561 ospf_opaque_lsa_flush_schedule(&lsa);
1562 break;
cf9b9f77 1563 }
cf9b9f77
OD
1564}
1565
1566/* Schedule Extended Link or Prefix depending of the Type of LSA */
1567static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op)
1568{
1569
1570 if (exti->stype == PREF_SID)
1571 ospf_ext_pref_lsa_schedule(exti, op);
1572 else
1573 ospf_ext_link_lsa_schedule(exti, op);
1574}
1575
7743f2f8
OD
1576/*
1577 * ------------------------------------
cf9b9f77 1578 * Followings are vty show functions.
7743f2f8
OD
1579 * ------------------------------------
1580 */
1581
cf9b9f77 1582/* Cisco experimental SubTLV */
93f0a26e 1583static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty *vty,
996c9314 1584 struct tlv_header *tlvh)
cf9b9f77
OD
1585{
1586 struct ext_subtlv_rmt_itf_addr *top;
7743f2f8 1587
cf9b9f77
OD
1588 top = (struct ext_subtlv_rmt_itf_addr *)tlvh;
1589
1590 vty_out(vty,
7743f2f8 1591 " Remote Interface Address Sub-TLV: Length %u\n "
cf9b9f77
OD
1592 "Address: %s\n",
1593 ntohs(top->header.length), inet_ntoa(top->value));
1594
1595 return TLV_SIZE(tlvh);
1596}
1597
1598/* Adjacency SID SubTLV */
93f0a26e 1599static uint16_t show_vty_ext_link_adj_sid(struct vty *vty,
996c9314 1600 struct tlv_header *tlvh)
cf9b9f77
OD
1601{
1602 struct ext_subtlv_adj_sid *top = (struct ext_subtlv_adj_sid *)tlvh;
1603
1604 vty_out(vty,
7743f2f8
OD
1605 " Adj-SID Sub-TLV: Length %u\n\tFlags: "
1606 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
cf9b9f77
OD
1607 ntohs(top->header.length), top->flags, top->mtid, top->weight,
1608 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1609 : "Index",
1610 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1611 ? GET_LABEL(ntohl(top->value))
1612 : ntohl(top->value));
1613
1614 return TLV_SIZE(tlvh);
1615}
1616
1617/* LAN Adjacency SubTLV */
93f0a26e 1618static uint16_t show_vty_ext_link_lan_adj_sid(struct vty *vty,
996c9314 1619 struct tlv_header *tlvh)
cf9b9f77
OD
1620{
1621 struct ext_subtlv_lan_adj_sid *top =
1622 (struct ext_subtlv_lan_adj_sid *)tlvh;
1623
1624 vty_out(vty,
7743f2f8 1625 " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: "
cf9b9f77 1626 "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: "
d922605d 1627 "%s\n\t%s: %u\n",
cf9b9f77 1628 ntohs(top->header.length), top->flags, top->mtid, top->weight,
d922605d 1629 inet_ntoa(top->neighbor_id),
cf9b9f77
OD
1630 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
1631 : "Index",
1632 CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG)
1633 ? GET_LABEL(ntohl(top->value))
1634 : ntohl(top->value));
1635
1636 return TLV_SIZE(tlvh);
1637}
1638
93f0a26e 1639static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh)
cf9b9f77
OD
1640{
1641 vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n",
1642 ntohs(tlvh->type), ntohs(tlvh->length));
1643
1644 return TLV_SIZE(tlvh);
1645}
1646
1647/* Extended Link Sub TLVs */
93f0a26e 1648static uint16_t show_vty_link_info(struct vty *vty, struct tlv_header *ext)
cf9b9f77
OD
1649{
1650 struct ext_tlv_link *top = (struct ext_tlv_link *)ext;
1651 struct tlv_header *tlvh;
93f0a26e
OD
1652 uint16_t length = ntohs(top->header.length) - 3 * sizeof(uint32_t);
1653 uint16_t sum = 0;
cf9b9f77
OD
1654
1655 vty_out(vty,
7743f2f8 1656 " Extended Link TLV: Length %u\n Link Type: 0x%x\n"
cf9b9f77
OD
1657 " Link ID: %s\n",
1658 ntohs(top->header.length), top->link_type,
1659 inet_ntoa(top->link_id));
1660 vty_out(vty, " Link data: %s\n", inet_ntoa(top->link_data));
1661
1662 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1663 + EXT_TLV_LINK_SIZE);
1664 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1665 switch (ntohs(tlvh->type)) {
1666 case EXT_SUBTLV_ADJ_SID:
1667 sum += show_vty_ext_link_adj_sid(vty, tlvh);
1668 break;
1669 case EXT_SUBTLV_LAN_ADJ_SID:
1670 sum += show_vty_ext_link_lan_adj_sid(vty, tlvh);
1671 break;
1672 case EXT_SUBTLV_RMT_ITF_ADDR:
1673 sum += show_vty_ext_link_rmt_itf_addr(vty, tlvh);
1674 break;
1675 default:
1676 sum += show_vty_unknown_tlv(vty, tlvh);
1677 break;
1678 }
1679 }
1680
1681 return sum + sizeof(struct ext_tlv_link);
1682}
1683
1684/* Extended Link TLVs */
1685static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa)
1686{
1687 struct lsa_header *lsah = (struct lsa_header *)lsa->data;
1688 struct tlv_header *tlvh;
93f0a26e 1689 uint16_t length = 0, sum = 0;
cf9b9f77
OD
1690
1691 /* Initialize TLV browsing */
1692 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1693
1694 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1695 tlvh = TLV_HDR_NEXT(tlvh)) {
1696 switch (ntohs(tlvh->type)) {
1697 case EXT_TLV_LINK:
1698 sum += show_vty_link_info(vty, tlvh);
1699 break;
1700 default:
1701 sum += show_vty_unknown_tlv(vty, tlvh);
1702 break;
1703 }
1704 }
cf9b9f77
OD
1705}
1706
1707/* Prefix SID SubTLV */
93f0a26e 1708static uint16_t show_vty_ext_pref_pref_sid(struct vty *vty,
996c9314 1709 struct tlv_header *tlvh)
cf9b9f77
OD
1710{
1711 struct ext_subtlv_prefix_sid *top =
1712 (struct ext_subtlv_prefix_sid *)tlvh;
1713
1714 vty_out(vty,
7743f2f8
OD
1715 " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: "
1716 "%u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
cf9b9f77
OD
1717 ntohs(top->header.length), top->algorithm, top->flags,
1718 top->mtid,
1719 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) ? "Label"
1720 : "Index",
1721 CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG)
1722 ? GET_LABEL(ntohl(top->value))
1723 : ntohl(top->value));
1724
1725 return TLV_SIZE(tlvh);
1726}
1727
1728/* Extended Prefix SubTLVs */
93f0a26e 1729static uint16_t show_vty_pref_info(struct vty *vty, struct tlv_header *ext)
cf9b9f77
OD
1730{
1731 struct ext_tlv_prefix *top = (struct ext_tlv_prefix *)ext;
1732 struct tlv_header *tlvh;
93f0a26e
OD
1733 uint16_t length = ntohs(top->header.length) - 2 * sizeof(uint32_t);
1734 uint16_t sum = 0;
cf9b9f77
OD
1735
1736 vty_out(vty,
7743f2f8
OD
1737 " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n"
1738 "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%u\n",
cf9b9f77
OD
1739 ntohs(top->header.length), top->route_type, top->af, top->flags,
1740 inet_ntoa(top->address), top->pref_length);
1741
1742 tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE
1743 + EXT_TLV_PREFIX_SIZE);
1744 for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) {
1745 switch (ntohs(tlvh->type)) {
1746 case EXT_SUBTLV_PREFIX_SID:
1747 sum += show_vty_ext_pref_pref_sid(vty, tlvh);
1748 break;
1749 default:
1750 sum += show_vty_unknown_tlv(vty, tlvh);
1751 break;
1752 }
1753 }
1754
1755 return sum + sizeof(struct ext_tlv_prefix);
1756}
1757
1758/* Extended Prefix TLVs */
1759static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa)
1760{
1761 struct lsa_header *lsah = (struct lsa_header *)lsa->data;
1762 struct tlv_header *tlvh;
93f0a26e 1763 uint16_t length = 0, sum = 0;
cf9b9f77
OD
1764
1765 /* Initialize TLV browsing */
1766 length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE;
1767
1768 for (tlvh = TLV_HDR_TOP(lsah); sum < length;
1769 tlvh = TLV_HDR_NEXT(tlvh)) {
1770 switch (ntohs(tlvh->type)) {
1771 case EXT_TLV_PREFIX:
1772 sum += show_vty_pref_info(vty, tlvh);
1773 break;
1774 default:
1775 sum += show_vty_unknown_tlv(vty, tlvh);
1776 break;
1777 }
1778 }
cf9b9f77 1779}