]>
Commit | Line | Data |
---|---|---|
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 | */ | |
73 | static 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 */ | |
cf9b9f77 OD |
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); | |
731271b0 | 91 | static void ospf_ext_ism_change(struct ospf_interface *oi, int old_status); |
cf9b9f77 OD |
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); | |
6f751f14 | 101 | static void ospf_ext_link_delete_adj_sid(struct ext_itf *exti); |
cf9b9f77 OD |
102 | static void del_ext_info(void *val); |
103 | ||
104 | /* | |
105 | * Extended Link/Prefix initialization | |
106 | * | |
107 | * @param - none | |
108 | * | |
109 | * @return - 0 if OK, <> 0 otherwise | |
110 | */ | |
111 | int ospf_ext_init(void) | |
112 | { | |
113 | int rc = 0; | |
114 | ||
115 | memset(&OspfEXT, 0, sizeof(struct ospf_ext_lp)); | |
116 | OspfEXT.enabled = false; | |
117 | /* Only Area flooding is supported yet */ | |
118 | OspfEXT.scope = OSPF_OPAQUE_AREA_LSA; | |
119 | /* Initialize interface list */ | |
120 | OspfEXT.iflist = list_new(); | |
121 | OspfEXT.iflist->del = del_ext_info; | |
122 | ||
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 */ | |
731271b0 | 128 | ospf_ext_ism_change, /* ism change */ |
cf9b9f77 OD |
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 */ | |
731271b0 | 151 | NULL, /* 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 | */ | |
177 | void 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 | */ | |
201 | void ospf_ext_finish(void) | |
202 | { | |
731271b0 OD |
203 | |
204 | struct listnode *node; | |
205 | struct ext_itf *exti; | |
206 | ||
207 | /* Flush Router Info LSA */ | |
208 | for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) | |
209 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) | |
210 | ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA); | |
211 | ||
bcf4475e | 212 | OspfEXT.enabled = false; |
cf9b9f77 OD |
213 | } |
214 | ||
7743f2f8 OD |
215 | /* |
216 | * --------------------------------------------------------------------- | |
cf9b9f77 OD |
217 | * Followings are control functions for Extended Prefix/Link Opaque LSA |
218 | * parameters management. | |
7743f2f8 OD |
219 | * --------------------------------------------------------------------- |
220 | */ | |
221 | ||
cf9b9f77 OD |
222 | /* Functions to free memory space */ |
223 | static void del_ext_info(void *val) | |
224 | { | |
225 | XFREE(MTYPE_OSPF_EXT_PARAMS, val); | |
cf9b9f77 OD |
226 | } |
227 | ||
228 | /* Increment instance value for Extended Prefix Opaque LSAs Opaque ID field */ | |
93f0a26e | 229 | static uint32_t get_ext_pref_instance_value(void) |
cf9b9f77 | 230 | { |
93f0a26e | 231 | static uint32_t seqno = 0; |
cf9b9f77 OD |
232 | |
233 | if (seqno < MAX_LEGAL_EXT_INSTANCE_NUM) | |
234 | seqno += 1; | |
235 | else | |
236 | seqno = 1; /* Avoid zero. */ | |
237 | ||
238 | return seqno; | |
239 | } | |
240 | ||
241 | /* Increment instance value for Extended Link Opaque LSAs Opaque ID field */ | |
93f0a26e | 242 | static uint32_t get_ext_link_instance_value(void) |
cf9b9f77 | 243 | { |
93f0a26e | 244 | static uint32_t seqno = 0; |
cf9b9f77 OD |
245 | |
246 | if (seqno < MAX_LEGAL_EXT_INSTANCE_NUM) | |
247 | seqno += 1; | |
248 | else | |
249 | seqno = 1; /* Avoid zero. */ | |
250 | ||
251 | return seqno; | |
252 | } | |
253 | ||
254 | /* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */ | |
255 | static struct ext_itf *lookup_ext_by_ifp(struct interface *ifp) | |
256 | { | |
257 | struct listnode *node, *nnode; | |
258 | struct ext_itf *exti; | |
259 | ||
260 | for (ALL_LIST_ELEMENTS(OspfEXT.iflist, node, nnode, exti)) | |
261 | if (exti->ifp == ifp) | |
262 | return exti; | |
263 | ||
264 | return NULL; | |
265 | } | |
266 | ||
267 | /* Lookup Extended Prefix/Links by LSA ID from OspfEXT struct iflist */ | |
268 | static struct ext_itf *lookup_ext_by_instance(struct ospf_lsa *lsa) | |
269 | { | |
270 | struct listnode *node; | |
271 | struct ext_itf *exti; | |
db28a51f OD |
272 | uint32_t key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)); |
273 | uint8_t type = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)); | |
274 | ||
cf9b9f77 OD |
275 | |
276 | for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) | |
db28a51f | 277 | if ((exti->instance == key) && (exti->type == type)) |
cf9b9f77 OD |
278 | return exti; |
279 | ||
cf9b9f77 OD |
280 | return NULL; |
281 | } | |
282 | ||
7743f2f8 OD |
283 | /* |
284 | * ---------------------------------------------------------------------- | |
cf9b9f77 OD |
285 | * The underlying subsection defines setters and unsetters to create and |
286 | * delete tlvs and subtlvs | |
7743f2f8 OD |
287 | * ---------------------------------------------------------------------- |
288 | */ | |
cf9b9f77 OD |
289 | |
290 | /* Extended Prefix TLV - RFC7684 section 2.1 */ | |
93f0a26e OD |
291 | static void set_ext_prefix(struct ext_itf *exti, uint8_t route_type, |
292 | uint8_t flags, struct prefix_ipv4 p) | |
cf9b9f77 OD |
293 | { |
294 | ||
295 | TLV_TYPE(exti->prefix) = htons(EXT_TLV_PREFIX); | |
296 | /* Warning: Size must be adjust depending of subTLV's */ | |
297 | TLV_LEN(exti->prefix) = htons(EXT_TLV_PREFIX_SIZE); | |
298 | exti->prefix.route_type = route_type; | |
299 | exti->prefix.flags = flags; | |
300 | /* Only Address Family Ipv4 (0) is defined in RFC 7684 */ | |
301 | exti->prefix.af = 0; | |
302 | exti->prefix.pref_length = p.prefixlen; | |
303 | exti->prefix.address = p.prefix; | |
304 | } | |
305 | ||
306 | /* Extended Link TLV - RFC7684 section 3.1 */ | |
93f0a26e | 307 | static void set_ext_link(struct ext_itf *exti, uint8_t type, struct in_addr id, |
cf9b9f77 OD |
308 | struct in_addr data) |
309 | { | |
310 | ||
311 | TLV_TYPE(exti->link) = htons(EXT_TLV_LINK); | |
312 | /* Warning: Size must be adjust depending of subTLV's */ | |
313 | TLV_LEN(exti->link) = htons(EXT_TLV_LINK_SIZE); | |
314 | exti->link.link_type = type; | |
315 | exti->link.link_id = id; | |
316 | exti->link.link_data = data; | |
317 | } | |
318 | ||
319 | /* Prefix SID SubTLV - section 5 */ | |
93f0a26e | 320 | static void set_prefix_sid(struct ext_itf *exti, uint8_t algorithm, |
7743f2f8 | 321 | uint32_t value, int value_type, uint8_t flags) |
cf9b9f77 OD |
322 | { |
323 | ||
cf9b9f77 OD |
324 | if ((algorithm != SR_ALGORITHM_SPF) |
325 | && (algorithm != SR_ALGORITHM_STRICT_SPF)) { | |
cf444bcf | 326 | flog_err(EC_OSPF_INVALID_ALGORITHM, |
89f60109 DS |
327 | "EXT (%s): unrecognized algorithm, not SPF or S-SPF", |
328 | __func__); | |
cf9b9f77 OD |
329 | return; |
330 | } | |
331 | ||
7743f2f8 | 332 | /* Update flags according to the type of value field: label or index */ |
cf9b9f77 | 333 | if (value_type == SID_LABEL) |
7743f2f8 | 334 | SET_FLAG(flags, EXT_SUBTLV_PREFIX_SID_VFLG); |
cf9b9f77 OD |
335 | |
336 | /* set prefix sid subtlv for an extended prefix tlv */ | |
337 | TLV_TYPE(exti->node_sid) = htons(EXT_SUBTLV_PREFIX_SID); | |
338 | exti->node_sid.algorithm = algorithm; | |
339 | exti->node_sid.flags = flags; | |
340 | exti->node_sid.mtid = 0; /* Multi-Topology is not supported */ | |
341 | ||
342 | /* Set Label or Index value */ | |
343 | if (value_type == SID_LABEL) { | |
d922605d OD |
344 | TLV_LEN(exti->node_sid) = |
345 | htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE)); | |
cf9b9f77 OD |
346 | exti->node_sid.value = htonl(SET_LABEL(value)); |
347 | } else { | |
d922605d OD |
348 | TLV_LEN(exti->node_sid) = |
349 | htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_SID_SIZE)); | |
cf9b9f77 OD |
350 | exti->node_sid.value = htonl(value); |
351 | } | |
cf9b9f77 OD |
352 | } |
353 | ||
354 | /* Adjacency SID SubTLV - section 6.1 */ | |
93f0a26e | 355 | static void set_adj_sid(struct ext_itf *exti, bool backup, uint32_t value, |
cf9b9f77 OD |
356 | int value_type) |
357 | { | |
358 | int index; | |
93f0a26e | 359 | uint8_t flags; |
cf9b9f77 OD |
360 | |
361 | /* Determine which ADJ_SID must be set: nominal or backup */ | |
362 | if (backup) { | |
363 | flags = EXT_SUBTLV_LINK_ADJ_SID_BFLG; | |
364 | index = 1; | |
365 | } else { | |
366 | index = 0; | |
367 | flags = 0; | |
368 | } | |
369 | ||
370 | /* Set Header */ | |
371 | TLV_TYPE(exti->adj_sid[index]) = htons(EXT_SUBTLV_ADJ_SID); | |
372 | ||
373 | /* Only Local ADJ-SID is supported for the moment */ | |
374 | SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_LFLG); | |
375 | ||
376 | exti->adj_sid[index].mtid = 0; /* Multi-Topology is not supported */ | |
377 | ||
378 | /* Adjust Length, Flags and Value depending on the type of Label */ | |
379 | if (value_type == SID_LABEL) { | |
380 | SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG); | |
d922605d OD |
381 | TLV_LEN(exti->adj_sid[index]) = |
382 | htons(SID_LABEL_SIZE(EXT_SUBTLV_ADJ_SID_SIZE)); | |
cf9b9f77 OD |
383 | exti->adj_sid[index].value = htonl(SET_LABEL(value)); |
384 | } else { | |
385 | UNSET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG); | |
d922605d OD |
386 | TLV_LEN(exti->adj_sid[index]) = |
387 | htons(SID_INDEX_SIZE(EXT_SUBTLV_ADJ_SID_SIZE)); | |
cf9b9f77 OD |
388 | exti->adj_sid[index].value = htonl(value); |
389 | } | |
390 | ||
391 | exti->adj_sid[index].flags = flags; /* Set computed flags */ | |
392 | exti->adj_sid[index].mtid = 0; /* Multi-Topology is not supported */ | |
393 | exti->adj_sid[index].weight = 0; /* Load-Balancing is not supported */ | |
cf9b9f77 OD |
394 | } |
395 | ||
396 | /* LAN Adjacency SID SubTLV - section 6.2 */ | |
93f0a26e | 397 | static void set_lan_adj_sid(struct ext_itf *exti, bool backup, uint32_t value, |
cf9b9f77 OD |
398 | int value_type, struct in_addr neighbor_id) |
399 | { | |
400 | ||
401 | int index; | |
93f0a26e | 402 | uint8_t flags; |
cf9b9f77 OD |
403 | |
404 | /* Determine which ADJ_SID must be set: nominal or backup */ | |
405 | if (backup) { | |
406 | flags = EXT_SUBTLV_LINK_ADJ_SID_BFLG; | |
407 | index = 1; | |
408 | } else { | |
409 | index = 0; | |
410 | flags = 0; | |
411 | } | |
412 | ||
413 | /* Set Header */ | |
d922605d | 414 | TLV_TYPE(exti->lan_sid[index]) = htons(EXT_SUBTLV_LAN_ADJ_SID); |
cf9b9f77 OD |
415 | |
416 | /* Only Local ADJ-SID is supported for the moment */ | |
417 | SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_LFLG); | |
418 | ||
419 | /* Adjust Length, Flags and Value depending on the type of Label */ | |
420 | if (value_type == SID_LABEL) { | |
421 | SET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG); | |
d922605d OD |
422 | TLV_LEN(exti->lan_sid[index]) = |
423 | htons(SID_LABEL_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE)); | |
cf9b9f77 OD |
424 | exti->lan_sid[index].value = htonl(SET_LABEL(value)); |
425 | } else { | |
426 | UNSET_FLAG(flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG); | |
d922605d OD |
427 | TLV_LEN(exti->lan_sid[index]) = |
428 | htons(SID_INDEX_SIZE(EXT_SUBTLV_PREFIX_RANGE_SIZE)); | |
cf9b9f77 OD |
429 | exti->lan_sid[index].value = htonl(value); |
430 | } | |
431 | ||
432 | exti->lan_sid[index].flags = flags; /* Set computed flags */ | |
433 | exti->lan_sid[index].mtid = 0; /* Multi-Topology is not supported */ | |
434 | exti->lan_sid[index].weight = 0; /* Load-Balancing is not supported */ | |
435 | exti->lan_sid[index].neighbor_id = neighbor_id; | |
cf9b9f77 OD |
436 | } |
437 | ||
6f751f14 OD |
438 | static void unset_adjacency_sid(struct ext_itf *exti) |
439 | { | |
440 | /* Reset Adjacency TLV */ | |
441 | if (exti->type == ADJ_SID) { | |
442 | TLV_TYPE(exti->adj_sid[0]) = 0; | |
443 | TLV_TYPE(exti->adj_sid[1]) = 0; | |
444 | } | |
445 | /* or Lan-Adjacency TLV */ | |
446 | if (exti->type == LAN_ADJ_SID) { | |
447 | TLV_TYPE(exti->lan_sid[0]) = 0; | |
448 | TLV_TYPE(exti->lan_sid[1]) = 0; | |
449 | } | |
450 | } | |
451 | ||
cf9b9f77 OD |
452 | /* Experimental SubTLV from Cisco */ |
453 | static void set_rmt_itf_addr(struct ext_itf *exti, struct in_addr rmtif) | |
454 | { | |
455 | ||
456 | TLV_TYPE(exti->rmt_itf_addr) = htons(EXT_SUBTLV_RMT_ITF_ADDR); | |
457 | TLV_LEN(exti->rmt_itf_addr) = htons(sizeof(struct in_addr)); | |
458 | exti->rmt_itf_addr.value = rmtif; | |
cf9b9f77 OD |
459 | } |
460 | ||
21baf89a OD |
461 | /* Delete Extended LSA */ |
462 | static void ospf_extended_lsa_delete(struct ext_itf *exti) | |
463 | { | |
464 | ||
465 | /* Process only Active Extended Prefix/Link LSA */ | |
466 | if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) | |
467 | return; | |
468 | ||
469 | osr_debug("EXT (%s): Disable %s%s%s-SID on interface %s", __func__, | |
6f751f14 | 470 | exti->stype == LOCAL_SID ? "Prefix" : "", |
21baf89a OD |
471 | exti->stype == ADJ_SID ? "Adjacency" : "", |
472 | exti->stype == LAN_ADJ_SID ? "LAN-Adjacency" : "", | |
473 | exti->ifp->name); | |
474 | ||
475 | /* Flush LSA if already engaged */ | |
476 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) { | |
477 | ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA); | |
478 | UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED); | |
479 | } | |
480 | ||
481 | /* De-activate this Extended Prefix/Link and remove corresponding | |
482 | * Segment-Routing Prefix-SID or (LAN)-ADJ-SID */ | |
6f751f14 OD |
483 | if (exti->stype == ADJ_SID || exti->stype == LAN_ADJ_SID) |
484 | ospf_ext_link_delete_adj_sid(exti); | |
485 | else | |
486 | ospf_sr_ext_itf_delete(exti); | |
21baf89a OD |
487 | } |
488 | ||
cf9b9f77 OD |
489 | /* |
490 | * Update Extended prefix SID index for Loopback interface type | |
491 | * | |
492 | * @param ifname - Loopback interface name | |
493 | * @param index - new value for the prefix SID of this interface | |
494 | * @param p - prefix for this interface or NULL if Extended Prefix | |
495 | * should be remove | |
496 | * | |
497 | * @return instance number if update is OK, 0 otherwise | |
498 | */ | |
db28a51f | 499 | uint32_t ospf_ext_schedule_prefix_index(struct interface *ifp, uint32_t index, |
996c9314 | 500 | struct prefix_ipv4 *p, uint8_t flags) |
cf9b9f77 OD |
501 | { |
502 | int rc = 0; | |
503 | struct ext_itf *exti; | |
504 | ||
505 | /* Find Extended Prefix interface */ | |
506 | exti = lookup_ext_by_ifp(ifp); | |
507 | if (exti == NULL) | |
508 | return rc; | |
509 | ||
510 | if (p != NULL) { | |
3efd0893 | 511 | osr_debug("EXT (%s): Schedule new prefix %pFX with index %u on interface %s", __func__, p, index, ifp->name); |
cf9b9f77 OD |
512 | |
513 | /* Set first Extended Prefix then the Prefix SID information */ | |
514 | set_ext_prefix(exti, OSPF_PATH_INTRA_AREA, EXT_TLV_PREF_NFLG, | |
515 | *p); | |
7743f2f8 | 516 | set_prefix_sid(exti, SR_ALGORITHM_SPF, index, SID_INDEX, flags); |
cf9b9f77 OD |
517 | |
518 | /* Try to Schedule LSA */ | |
731271b0 OD |
519 | // SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE); |
520 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) { | |
521 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) | |
522 | ospf_ext_pref_lsa_schedule(exti, | |
523 | REFRESH_THIS_LSA); | |
524 | else | |
525 | ospf_ext_pref_lsa_schedule( | |
526 | exti, REORIGINATE_THIS_LSA); | |
527 | } | |
cf9b9f77 | 528 | } else { |
b37eb79c OD |
529 | osr_debug("EXT (%s): Remove prefix for interface %s", __func__, |
530 | ifp->name); | |
cf9b9f77 OD |
531 | |
532 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) { | |
533 | ospf_ext_pref_lsa_schedule(exti, FLUSH_THIS_LSA); | |
731271b0 | 534 | exti->flags = EXT_LPFLG_LSA_INACTIVE; |
cf9b9f77 OD |
535 | } |
536 | } | |
537 | ||
db28a51f | 538 | return SET_OPAQUE_LSID(exti->type, exti->instance); |
cf9b9f77 OD |
539 | } |
540 | ||
6f751f14 OD |
541 | /** |
542 | * Update Adjacecny-SID for Extended Link LSA | |
543 | * | |
544 | * @param exti Extended Link information | |
545 | */ | |
546 | static void ospf_ext_link_update_adj_sid(struct ext_itf *exti) | |
547 | { | |
548 | mpls_label_t label; | |
549 | mpls_label_t bck_label; | |
550 | ||
551 | /* Process only (LAN)Adjacency-SID Type */ | |
552 | if (exti->stype != ADJ_SID && exti->stype != LAN_ADJ_SID) | |
553 | return; | |
554 | ||
555 | /* Request Primary & Backup Labels from Label Manager */ | |
556 | bck_label = ospf_sr_local_block_request_label(); | |
557 | label = ospf_sr_local_block_request_label(); | |
558 | if (bck_label == MPLS_INVALID_LABEL || label == MPLS_INVALID_LABEL) { | |
559 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) | |
560 | ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA); | |
561 | return; | |
562 | } | |
563 | ||
564 | /* Set Adjacency-SID, backup first */ | |
565 | if (exti->stype == ADJ_SID) { | |
566 | set_adj_sid(exti, true, bck_label, SID_LABEL); | |
567 | set_adj_sid(exti, false, label, SID_LABEL); | |
568 | } else { | |
569 | set_lan_adj_sid(exti, true, bck_label, SID_LABEL, | |
570 | exti->lan_sid[0].neighbor_id); | |
571 | set_lan_adj_sid(exti, false, label, SID_LABEL, | |
572 | exti->lan_sid[1].neighbor_id); | |
573 | } | |
574 | ||
575 | /* Finally, add corresponding SR Link in SRDB & MPLS LFIB */ | |
576 | SET_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET); | |
577 | ospf_sr_ext_itf_add(exti); | |
578 | } | |
579 | ||
580 | /** | |
581 | * Delete Adjacecny-SID for Extended Link LSA | |
582 | * | |
583 | * @param exti Extended Link information | |
584 | */ | |
585 | static void ospf_ext_link_delete_adj_sid(struct ext_itf *exti) | |
586 | { | |
587 | /* Process only (LAN)Adjacency-SID Type */ | |
588 | if (exti->stype != ADJ_SID && exti->stype != LAN_ADJ_SID) | |
589 | return; | |
590 | ||
591 | /* Release Primary & Backup Labels from Label Manager */ | |
592 | if (exti->stype == ADJ_SID) { | |
593 | ospf_sr_local_block_release_label(exti->adj_sid[0].value); | |
594 | ospf_sr_local_block_release_label(exti->adj_sid[1].value); | |
595 | } else { | |
596 | ospf_sr_local_block_release_label(exti->adj_sid[0].value); | |
597 | ospf_sr_local_block_release_label(exti->adj_sid[1].value); | |
598 | } | |
599 | /* And reset corresponding TLV */ | |
600 | unset_adjacency_sid(exti); | |
601 | ||
602 | /* Finally, remove corresponding SR Link in SRDB & MPLS LFIB */ | |
603 | UNSET_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET); | |
604 | ospf_sr_ext_itf_delete(exti); | |
605 | } | |
606 | ||
607 | /** | |
608 | * Update Extended Link LSA once Segment Routing Label Block has been changed. | |
609 | */ | |
610 | void ospf_ext_link_srlb_update(void) | |
611 | { | |
612 | struct listnode *node; | |
613 | struct ext_itf *exti; | |
614 | ||
615 | ||
616 | osr_debug("EXT (%s): Update Extended Links with new SRLB", __func__); | |
617 | ||
618 | /* Update all Extended Link Adjaceny-SID */ | |
619 | for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) { | |
620 | /* Skip Extended Prefix */ | |
621 | if (exti->stype == PREF_SID || exti->stype == LOCAL_SID) | |
622 | continue; | |
623 | ||
624 | /* Skip inactive Extended Link */ | |
625 | if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) | |
626 | continue; | |
627 | ||
628 | ospf_ext_link_update_adj_sid(exti); | |
629 | } | |
630 | } | |
631 | ||
cf9b9f77 OD |
632 | /* |
633 | * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding | |
634 | * | |
635 | * @param enable To activate or not Segment Routing Extended LSA flooding | |
636 | * | |
637 | * @return none | |
638 | */ | |
639 | void ospf_ext_update_sr(bool enable) | |
640 | { | |
641 | struct listnode *node; | |
642 | struct ext_itf *exti; | |
643 | ||
b37eb79c OD |
644 | osr_debug("EXT (%s): %s Extended LSAs for Segment Routing ", __func__, |
645 | enable ? "Enable" : "Disable"); | |
cf9b9f77 OD |
646 | |
647 | if (enable) { | |
648 | OspfEXT.enabled = true; | |
731271b0 | 649 | |
cf9b9f77 | 650 | /* Refresh LSAs if already engaged or originate */ |
731271b0 | 651 | for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) { |
6f751f14 | 652 | /* Skip Inactive Extended Link */ |
731271b0 OD |
653 | if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) |
654 | continue; | |
655 | ||
6f751f14 OD |
656 | /* Update Extended Link (LAN)Adj-SID if not set */ |
657 | if (!CHECK_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET)) | |
658 | ospf_ext_link_update_adj_sid(exti); | |
659 | ||
660 | /* Finally, flood the extended Link */ | |
cf9b9f77 OD |
661 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) |
662 | ospf_ext_lsa_schedule(exti, REFRESH_THIS_LSA); | |
663 | else | |
664 | ospf_ext_lsa_schedule(exti, | |
665 | REORIGINATE_THIS_LSA); | |
731271b0 | 666 | } |
cf9b9f77 | 667 | } else { |
21baf89a OD |
668 | /* Start by Removing Extended LSA */ |
669 | for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) | |
670 | ospf_extended_lsa_delete(exti); | |
731271b0 | 671 | |
cf9b9f77 OD |
672 | /* And then disable Extended Link/Prefix */ |
673 | OspfEXT.enabled = false; | |
674 | } | |
675 | } | |
21baf89a | 676 | |
7743f2f8 OD |
677 | /* |
678 | * ----------------------------------------------------------------------- | |
679 | * Followings are callback functions against generic Opaque-LSAs handling | |
680 | * ----------------------------------------------------------------------- | |
681 | */ | |
cf9b9f77 OD |
682 | |
683 | /* Add new Interface in Extended Interface List */ | |
684 | static int ospf_ext_link_new_if(struct interface *ifp) | |
685 | { | |
686 | struct ext_itf *new; | |
687 | int rc = -1; | |
688 | ||
689 | if (lookup_ext_by_ifp(ifp) != NULL) { | |
cf9b9f77 OD |
690 | rc = 0; /* Do nothing here. */ |
691 | return rc; | |
692 | } | |
693 | ||
694 | new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf)); | |
cf9b9f77 OD |
695 | |
696 | /* initialize new information and link back the interface */ | |
697 | new->ifp = ifp; | |
698 | new->flags = EXT_LPFLG_LSA_INACTIVE; | |
699 | ||
700 | listnode_add(OspfEXT.iflist, new); | |
701 | ||
702 | rc = 0; | |
703 | return rc; | |
704 | } | |
705 | ||
706 | /* Remove existing Interface from Extended Interface List */ | |
707 | static int ospf_ext_link_del_if(struct interface *ifp) | |
708 | { | |
709 | struct ext_itf *exti; | |
710 | int rc = -1; | |
711 | ||
7743f2f8 OD |
712 | exti = lookup_ext_by_ifp(ifp); |
713 | if (exti != NULL) { | |
21baf89a OD |
714 | /* Flush LSA and remove Adjacency SID */ |
715 | ospf_extended_lsa_delete(exti); | |
cf9b9f77 | 716 | |
cf9b9f77 | 717 | /* Dequeue listnode entry from the list. */ |
21baf89a | 718 | listnode_delete(OspfEXT.iflist, exti); |
cf9b9f77 | 719 | |
cf9b9f77 OD |
720 | XFREE(MTYPE_OSPF_EXT_PARAMS, exti); |
721 | ||
722 | rc = 0; | |
723 | } else { | |
cf444bcf | 724 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 725 | "EXT (%s): interface %s is not found", __func__, |
996c9314 | 726 | ifp ? ifp->name : "-"); |
cf9b9f77 OD |
727 | } |
728 | ||
729 | return rc; | |
730 | } | |
731 | ||
7743f2f8 | 732 | /* |
731271b0 OD |
733 | * Determine if an Interface belongs to an Extended Link Adjacency or |
734 | * Extended Prefix SID type and allocate new instance value accordingly | |
cf9b9f77 | 735 | */ |
731271b0 | 736 | static void ospf_ext_ism_change(struct ospf_interface *oi, int old_status) |
cf9b9f77 OD |
737 | { |
738 | struct ext_itf *exti; | |
739 | ||
740 | /* Get interface information for Segment Routing */ | |
7743f2f8 OD |
741 | exti = lookup_ext_by_ifp(oi->ifp); |
742 | if (exti == NULL) { | |
cf444bcf | 743 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 744 | "EXT (%s): Cannot get Extended info. from OI(%s)", |
996c9314 | 745 | __func__, IF_NAME(oi)); |
cf9b9f77 OD |
746 | return; |
747 | } | |
748 | ||
731271b0 OD |
749 | /* Reset Extended information if ospf interface goes Down */ |
750 | if (oi->state == ISM_Down) { | |
21baf89a | 751 | ospf_extended_lsa_delete(exti); |
731271b0 OD |
752 | exti->area = NULL; |
753 | exti->flags = EXT_LPFLG_LSA_INACTIVE; | |
754 | return; | |
755 | } | |
756 | ||
757 | /* Determine if interface is related to a Prefix or an Adjacency SID */ | |
cf9b9f77 OD |
758 | if (oi->type == OSPF_IFTYPE_LOOPBACK) { |
759 | exti->stype = PREF_SID; | |
db28a51f | 760 | exti->type = OPAQUE_TYPE_EXTENDED_PREFIX_LSA; |
731271b0 OD |
761 | exti->flags = EXT_LPFLG_LSA_ACTIVE; |
762 | exti->instance = get_ext_pref_instance_value(); | |
763 | exti->area = oi->area; | |
7743f2f8 | 764 | |
b37eb79c OD |
765 | osr_debug("EXT (%s): Set Prefix SID to interface %s ", |
766 | __func__, oi->ifp->name); | |
7743f2f8 OD |
767 | |
768 | /* Complete SRDB if the interface belongs to a Prefix */ | |
62c99790 | 769 | if (OspfEXT.enabled) |
b37eb79c | 770 | ospf_sr_update_local_prefix(oi->ifp, oi->address); |
731271b0 OD |
771 | } else { |
772 | /* Determine if interface is related to Adj. or LAN Adj. SID */ | |
773 | if (oi->state == ISM_DR) | |
774 | exti->stype = LAN_ADJ_SID; | |
775 | else | |
776 | exti->stype = ADJ_SID; | |
777 | ||
778 | exti->type = OPAQUE_TYPE_EXTENDED_LINK_LSA; | |
779 | exti->instance = get_ext_link_instance_value(); | |
780 | exti->area = oi->area; | |
781 | ||
782 | /* | |
783 | * Note: Adjacency SID information are completed when ospf | |
784 | * adjacency become up see ospf_ext_link_nsm_change() | |
785 | */ | |
b37eb79c OD |
786 | osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ", |
787 | __func__, exti->stype == ADJ_SID ? "" : "LAN-", | |
788 | oi->ifp->name); | |
cf9b9f77 | 789 | } |
cf9b9f77 OD |
790 | } |
791 | ||
792 | /* | |
793 | * Finish Extended Link configuration and flood corresponding LSA | |
794 | * when OSPF adjacency on this link fire up | |
795 | */ | |
796 | static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status) | |
797 | { | |
798 | struct ospf_interface *oi = nbr->oi; | |
799 | struct ext_itf *exti; | |
cf9b9f77 | 800 | |
21baf89a OD |
801 | /* Process Link only when neighbor old or new state is NSM Full */ |
802 | if (nbr->state != NSM_Full && old_status != NSM_Full) | |
cf9b9f77 OD |
803 | return; |
804 | ||
805 | /* Get interface information for Segment Routing */ | |
7743f2f8 OD |
806 | exti = lookup_ext_by_ifp(oi->ifp); |
807 | if (exti == NULL) { | |
cf444bcf | 808 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 809 | "EXT (%s): Cannot get Extended info. from OI(%s)", |
996c9314 | 810 | __func__, IF_NAME(oi)); |
cf9b9f77 OD |
811 | return; |
812 | } | |
813 | ||
21baf89a OD |
814 | /* Check that we have a valid area and ospf context */ |
815 | if (oi->area == NULL || oi->area->ospf == NULL) { | |
816 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, | |
817 | "EXT (%s): Cannot refer to OSPF from OI(%s)", | |
818 | __func__, IF_NAME(oi)); | |
819 | return; | |
820 | } | |
821 | ||
822 | /* Remove Extended Link if Neighbor State goes Down or Deleted */ | |
823 | if (nbr->state == NSM_Down || nbr->state == NSM_Deleted) { | |
6f751f14 OD |
824 | ospf_ext_link_delete_adj_sid(exti); |
825 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) | |
826 | ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA); | |
827 | exti->flags = EXT_LPFLG_LSA_INACTIVE; | |
21baf89a OD |
828 | return; |
829 | } | |
830 | ||
831 | /* Keep Area information in combination with SR info. */ | |
832 | exti->area = oi->area; | |
833 | ||
cf9b9f77 OD |
834 | /* Process only Adjacency/LAN SID */ |
835 | if (exti->stype == PREF_SID) | |
836 | return; | |
837 | ||
838 | switch (oi->state) { | |
839 | case ISM_PointToPoint: | |
840 | /* Segment ID is an Adjacency one */ | |
841 | exti->stype = ADJ_SID; | |
842 | ||
843 | /* Set Extended Link TLV with link_id == Nbr Router ID */ | |
844 | set_ext_link(exti, OSPF_IFTYPE_POINTOPOINT, nbr->router_id, | |
845 | oi->address->u.prefix4); | |
846 | ||
cf9b9f77 OD |
847 | /* And Remote Interface address */ |
848 | set_rmt_itf_addr(exti, nbr->address.u.prefix4); | |
849 | ||
850 | break; | |
851 | ||
852 | case ISM_DR: | |
853 | /* Segment ID is a LAN Adjacency for the DR only */ | |
854 | exti->stype = LAN_ADJ_SID; | |
855 | ||
856 | /* Set Extended Link TLV with link_id == DR */ | |
857 | set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi), | |
858 | oi->address->u.prefix4); | |
859 | ||
6f751f14 OD |
860 | /* Set Neighbor ID */ |
861 | exti->lan_sid[0].neighbor_id = nbr->router_id; | |
862 | exti->lan_sid[1].neighbor_id = nbr->router_id; | |
cf9b9f77 OD |
863 | |
864 | break; | |
865 | ||
866 | case ISM_DROther: | |
867 | case ISM_Backup: | |
868 | /* Segment ID is an Adjacency if not the DR */ | |
869 | exti->stype = ADJ_SID; | |
870 | ||
871 | /* Set Extended Link TLV with link_id == DR */ | |
872 | set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi), | |
873 | oi->address->u.prefix4); | |
874 | ||
cf9b9f77 OD |
875 | break; |
876 | ||
877 | default: | |
6f751f14 OD |
878 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET)) |
879 | ospf_ext_link_delete_adj_sid(exti); | |
731271b0 | 880 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) |
cf9b9f77 | 881 | ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA); |
731271b0 | 882 | exti->flags = EXT_LPFLG_LSA_INACTIVE; |
cf9b9f77 OD |
883 | return; |
884 | } | |
885 | ||
cf9b9f77 | 886 | SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE); |
6f751f14 | 887 | |
cf9b9f77 | 888 | if (OspfEXT.enabled) { |
6f751f14 OD |
889 | osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ", |
890 | __func__, exti->stype == ADJ_SID ? "" : "LAN-", | |
891 | oi->ifp->name); | |
892 | ||
893 | /* Update (LAN)Adjacency SID */ | |
894 | ospf_ext_link_update_adj_sid(exti); | |
895 | ||
896 | /* flood this links params if everything is ok */ | |
cf9b9f77 OD |
897 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) |
898 | ospf_ext_link_lsa_schedule(exti, REFRESH_THIS_LSA); | |
899 | else | |
900 | ospf_ext_link_lsa_schedule(exti, REORIGINATE_THIS_LSA); | |
901 | } | |
cf9b9f77 OD |
902 | } |
903 | ||
904 | /* Callbacks to handle Extended Link Segment Routing LSA information */ | |
905 | static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa) | |
906 | { | |
907 | /* Sanity Check */ | |
908 | if (lsa == NULL) { | |
cf444bcf | 909 | flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL", |
ade6974d | 910 | __func__); |
cf9b9f77 OD |
911 | return -1; |
912 | } | |
913 | ||
6aaf0fdd OD |
914 | /* Process only Opaque LSA */ |
915 | if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA) | |
916 | && (lsa->data->type != OSPF_OPAQUE_AS_LSA)) | |
917 | return 0; | |
918 | ||
cf9b9f77 OD |
919 | /* Process only Extended Link LSA */ |
920 | if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)) | |
921 | != OPAQUE_TYPE_EXTENDED_LINK_LSA) | |
922 | return 0; | |
923 | ||
21baf89a OD |
924 | /* Check if it is not my LSA */ |
925 | if (IS_LSA_SELF(lsa)) | |
926 | return 0; | |
927 | ||
cf9b9f77 OD |
928 | /* Check if Extended is enable */ |
929 | if (!OspfEXT.enabled) | |
930 | return 0; | |
931 | ||
932 | /* Call Segment Routing LSA update or deletion */ | |
933 | if (!IS_LSA_MAXAGE(lsa)) | |
934 | ospf_sr_ext_link_lsa_update(lsa); | |
935 | else | |
936 | ospf_sr_ext_link_lsa_delete(lsa); | |
937 | ||
938 | return 0; | |
939 | } | |
940 | ||
941 | /* Callbacks to handle Extended Prefix Segment Routing LSA information */ | |
942 | static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa) | |
943 | { | |
944 | ||
945 | /* Sanity Check */ | |
946 | if (lsa == NULL) { | |
cf444bcf | 947 | flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL", |
ade6974d | 948 | __func__); |
cf9b9f77 OD |
949 | return -1; |
950 | } | |
951 | ||
6aaf0fdd OD |
952 | /* Process only Opaque LSA */ |
953 | if ((lsa->data->type != OSPF_OPAQUE_AREA_LSA) | |
954 | && (lsa->data->type != OSPF_OPAQUE_AS_LSA)) | |
7743f2f8 OD |
955 | return 0; |
956 | ||
cf9b9f77 OD |
957 | /* Process only Extended Prefix LSA */ |
958 | if (GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)) | |
959 | != OPAQUE_TYPE_EXTENDED_PREFIX_LSA) | |
960 | return 0; | |
961 | ||
6aaf0fdd OD |
962 | /* Check if it is not my LSA */ |
963 | if (IS_LSA_SELF(lsa)) | |
964 | return 0; | |
965 | ||
cf9b9f77 OD |
966 | /* Check if Extended is enable */ |
967 | if (!OspfEXT.enabled) | |
968 | return 0; | |
969 | ||
970 | /* Call Segment Routing LSA update or deletion */ | |
971 | if (!IS_LSA_MAXAGE(lsa)) | |
972 | ospf_sr_ext_prefix_lsa_update(lsa); | |
973 | else | |
974 | ospf_sr_ext_prefix_lsa_delete(lsa); | |
975 | ||
976 | return 0; | |
977 | } | |
978 | ||
7743f2f8 OD |
979 | /* |
980 | * ------------------------------------------------------- | |
cf9b9f77 OD |
981 | * Followings are OSPF protocol processing functions for |
982 | * Extended Prefix/Link Opaque LSA | |
7743f2f8 OD |
983 | * ------------------------------------------------------- |
984 | */ | |
cf9b9f77 OD |
985 | |
986 | static void build_tlv_header(struct stream *s, struct tlv_header *tlvh) | |
987 | { | |
988 | stream_put(s, tlvh, sizeof(struct tlv_header)); | |
cf9b9f77 OD |
989 | } |
990 | ||
991 | static void build_tlv(struct stream *s, struct tlv_header *tlvh) | |
992 | { | |
993 | ||
994 | if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) { | |
995 | build_tlv_header(s, tlvh); | |
996 | stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh)); | |
997 | } | |
cf9b9f77 OD |
998 | } |
999 | ||
1000 | /* Build an Extended Prefix Opaque LSA body for extended prefix TLV */ | |
1001 | static void ospf_ext_pref_lsa_body_set(struct stream *s, struct ext_itf *exti) | |
1002 | { | |
1003 | ||
1004 | /* Sanity check */ | |
1005 | if ((exti == NULL) || (exti->stype != PREF_SID)) | |
1006 | return; | |
1007 | ||
1008 | /* Adjust Extended Prefix TLV size */ | |
996c9314 LB |
1009 | TLV_LEN(exti->prefix) = htons(ntohs(TLV_LEN(exti->node_sid)) |
1010 | + EXT_TLV_PREFIX_SIZE + TLV_HDR_SIZE); | |
cf9b9f77 OD |
1011 | |
1012 | /* Build LSA body for an Extended Prefix TLV */ | |
1013 | build_tlv_header(s, &exti->prefix.header); | |
1014 | stream_put(s, TLV_DATA(&exti->prefix.header), EXT_TLV_PREFIX_SIZE); | |
1015 | /* Then add Prefix SID SubTLV */ | |
1016 | build_tlv(s, &exti->node_sid.header); | |
cf9b9f77 OD |
1017 | } |
1018 | ||
1019 | /* Build an Extended Link Opaque LSA body for extended link TLV */ | |
1020 | static void ospf_ext_link_lsa_body_set(struct stream *s, struct ext_itf *exti) | |
1021 | { | |
7743f2f8 | 1022 | size_t size; |
cf9b9f77 OD |
1023 | |
1024 | /* Sanity check */ | |
1025 | if ((exti == NULL) | |
1026 | || ((exti->stype != ADJ_SID) && (exti->stype != LAN_ADJ_SID))) | |
1027 | return; | |
1028 | ||
1029 | if (exti->stype == ADJ_SID) { | |
1030 | /* Adjust Extended Link TLV size for Adj. SID */ | |
7743f2f8 | 1031 | size = EXT_TLV_LINK_SIZE + 2 * EXT_SUBTLV_ADJ_SID_SIZE |
996c9314 | 1032 | + 2 * TLV_HDR_SIZE; |
7743f2f8 OD |
1033 | if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0) |
1034 | size = size + EXT_SUBTLV_RMT_ITF_ADDR_SIZE | |
996c9314 | 1035 | + TLV_HDR_SIZE; |
7743f2f8 | 1036 | TLV_LEN(exti->link) = htons(size); |
cf9b9f77 OD |
1037 | |
1038 | /* Build LSA body for an Extended Link TLV with Adj. SID */ | |
1039 | build_tlv_header(s, &exti->link.header); | |
1040 | stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE); | |
d922605d | 1041 | /* then add Adjacency SubTLVs */ |
cf9b9f77 OD |
1042 | build_tlv(s, &exti->adj_sid[1].header); |
1043 | build_tlv(s, &exti->adj_sid[0].header); | |
7743f2f8 OD |
1044 | |
1045 | /* Add Cisco experimental SubTLV if interface is PtoP */ | |
1046 | if (ntohs(TLV_TYPE(exti->rmt_itf_addr)) != 0) | |
1047 | build_tlv(s, &exti->rmt_itf_addr.header); | |
cf9b9f77 OD |
1048 | } else { |
1049 | /* Adjust Extended Link TLV size for LAN SID */ | |
7743f2f8 | 1050 | size = EXT_TLV_LINK_SIZE |
996c9314 | 1051 | + 2 * (EXT_SUBTLV_LAN_ADJ_SID_SIZE + TLV_HDR_SIZE); |
7743f2f8 | 1052 | TLV_LEN(exti->link) = htons(size); |
cf9b9f77 OD |
1053 | |
1054 | /* Build LSA body for an Extended Link TLV with LAN SID */ | |
1055 | build_tlv_header(s, &exti->link.header); | |
d922605d OD |
1056 | stream_put(s, TLV_DATA(&exti->link.header), EXT_TLV_LINK_SIZE); |
1057 | /* then add LAN-Adjacency SubTLVs */ | |
cf9b9f77 OD |
1058 | build_tlv(s, &exti->lan_sid[1].header); |
1059 | build_tlv(s, &exti->lan_sid[0].header); | |
1060 | } | |
cf9b9f77 OD |
1061 | } |
1062 | ||
1063 | /* Create new Extended Prefix opaque-LSA for every extended prefix */ | |
1064 | static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area, | |
1065 | struct ext_itf *exti) | |
1066 | { | |
1067 | struct stream *s; | |
1068 | struct lsa_header *lsah; | |
1069 | struct ospf_lsa *new = NULL; | |
7743f2f8 | 1070 | struct ospf *top; |
d7c0a89a | 1071 | uint8_t options, lsa_type; |
cf9b9f77 OD |
1072 | struct in_addr lsa_id; |
1073 | struct in_addr router_id; | |
93f0a26e OD |
1074 | uint32_t tmp; |
1075 | uint16_t length; | |
cf9b9f77 | 1076 | |
fd3b19f2 OD |
1077 | /* Sanity Check */ |
1078 | if (exti == NULL) | |
1079 | return NULL; | |
1080 | ||
cf9b9f77 | 1081 | /* Create a stream for LSA. */ |
7743f2f8 | 1082 | s = stream_new(OSPF_MAX_LSA_SIZE); |
cf9b9f77 OD |
1083 | |
1084 | /* Prepare LSA Header */ | |
1085 | lsah = (struct lsa_header *)STREAM_DATA(s); | |
1086 | ||
1087 | lsa_type = OspfEXT.scope; | |
1088 | ||
7743f2f8 OD |
1089 | /* |
1090 | * LSA ID is a variable number identifying different instances of | |
1091 | * Extended Prefix Opaque LSA from the same router see RFC 7684 | |
1092 | */ | |
cf9b9f77 OD |
1093 | tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance); |
1094 | lsa_id.s_addr = htonl(tmp); | |
1095 | ||
1096 | options = OSPF_OPTION_O; /* Don't forget this :-) */ | |
1097 | ||
1098 | /* Fix Options and Router ID depending of the flooding scope */ | |
1099 | if ((OspfEXT.scope == OSPF_OPAQUE_AS_LSA) || (area == NULL)) { | |
1100 | options = OSPF_OPTION_E; | |
7743f2f8 OD |
1101 | top = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
1102 | router_id.s_addr = top ? top->router_id.s_addr : 0; | |
cf9b9f77 OD |
1103 | } else { |
1104 | options |= LSA_OPTIONS_GET(area); /* Get area default option */ | |
1105 | options |= LSA_OPTIONS_NSSA_GET(area); | |
1106 | router_id = area->ospf->router_id; | |
1107 | } | |
1108 | ||
1109 | /* Set opaque-LSA header fields. */ | |
1110 | lsa_header_set(s, options, lsa_type, lsa_id, router_id); | |
1111 | ||
b37eb79c | 1112 | osr_debug( |
3efd0893 | 1113 | "EXT (%s): LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Prefix Opaque LSA instance", |
b37eb79c | 1114 | __func__, lsa_type, &lsa_id); |
cf9b9f77 OD |
1115 | |
1116 | /* Set opaque-LSA body fields. */ | |
1117 | ospf_ext_pref_lsa_body_set(s, exti); | |
1118 | ||
1119 | /* Set length. */ | |
1120 | length = stream_get_endp(s); | |
1121 | lsah->length = htons(length); | |
1122 | ||
1123 | /* Now, create an OSPF LSA instance. */ | |
5b3d4186 | 1124 | new = ospf_lsa_new_and_data(length); |
cf9b9f77 | 1125 | |
7743f2f8 OD |
1126 | /* Segment Routing belongs only to default VRF */ |
1127 | new->vrf_id = VRF_DEFAULT; | |
cf9b9f77 OD |
1128 | new->area = area; |
1129 | SET_FLAG(new->flags, OSPF_LSA_SELF); | |
1130 | memcpy(new->data, lsah, length); | |
1131 | stream_free(s); | |
1132 | ||
1133 | return new; | |
1134 | } | |
1135 | ||
1136 | /* Create new Extended Link opaque-LSA for every extended link TLV */ | |
1137 | static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area, | |
1138 | struct ext_itf *exti) | |
1139 | { | |
1140 | struct stream *s; | |
1141 | struct lsa_header *lsah; | |
1142 | struct ospf_lsa *new = NULL; | |
d7c0a89a | 1143 | uint8_t options, lsa_type; |
cf9b9f77 | 1144 | struct in_addr lsa_id; |
93f0a26e OD |
1145 | uint32_t tmp; |
1146 | uint16_t length; | |
cf9b9f77 | 1147 | |
fd3b19f2 OD |
1148 | /* Sanity Check */ |
1149 | if (exti == NULL) | |
1150 | return NULL; | |
1151 | ||
cf9b9f77 | 1152 | /* Create a stream for LSA. */ |
7743f2f8 | 1153 | s = stream_new(OSPF_MAX_LSA_SIZE); |
cf9b9f77 OD |
1154 | lsah = (struct lsa_header *)STREAM_DATA(s); |
1155 | ||
1156 | options = OSPF_OPTION_O; /* Don't forget this :-) */ | |
1157 | options |= LSA_OPTIONS_GET(area); /* Get area default option */ | |
1158 | options |= LSA_OPTIONS_NSSA_GET(area); | |
1159 | /* Extended Link Opaque LSA are only flooded within an area */ | |
1160 | lsa_type = OSPF_OPAQUE_AREA_LSA; | |
1161 | ||
7743f2f8 OD |
1162 | /* |
1163 | * LSA ID is a variable number identifying different instances of | |
1164 | * Extended Link Opaque LSA from the same router see RFC 7684 | |
1165 | */ | |
cf9b9f77 OD |
1166 | tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance); |
1167 | lsa_id.s_addr = htonl(tmp); | |
1168 | ||
b37eb79c | 1169 | osr_debug( |
3efd0893 | 1170 | "EXT (%s) LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Link Opaque LSA instance", |
b37eb79c | 1171 | __func__, lsa_type, &lsa_id); |
cf9b9f77 OD |
1172 | |
1173 | /* Set opaque-LSA header fields. */ | |
1174 | lsa_header_set(s, options, lsa_type, lsa_id, area->ospf->router_id); | |
1175 | ||
1176 | /* Set opaque-LSA body fields. */ | |
1177 | ospf_ext_link_lsa_body_set(s, exti); | |
1178 | ||
1179 | /* Set length. */ | |
1180 | length = stream_get_endp(s); | |
1181 | lsah->length = htons(length); | |
1182 | ||
1183 | /* Now, create an OSPF LSA instance. */ | |
5b3d4186 | 1184 | new = ospf_lsa_new_and_data(length); |
cf9b9f77 | 1185 | |
7743f2f8 OD |
1186 | /* Segment Routing belongs only to default VRF */ |
1187 | new->vrf_id = VRF_DEFAULT; | |
cf9b9f77 OD |
1188 | new->area = area; |
1189 | SET_FLAG(new->flags, OSPF_LSA_SELF); | |
1190 | memcpy(new->data, lsah, length); | |
1191 | stream_free(s); | |
1192 | ||
1193 | return new; | |
1194 | } | |
1195 | ||
7743f2f8 OD |
1196 | /* |
1197 | * Process the origination of an Extended Prefix Opaque LSA | |
1198 | * for every extended prefix TLV | |
1199 | */ | |
cf9b9f77 OD |
1200 | static int ospf_ext_pref_lsa_originate1(struct ospf_area *area, |
1201 | struct ext_itf *exti) | |
1202 | { | |
1203 | struct ospf_lsa *new; | |
1204 | int rc = -1; | |
1205 | ||
1206 | ||
1207 | /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */ | |
7743f2f8 OD |
1208 | new = ospf_ext_pref_lsa_new(area, exti); |
1209 | if (new == NULL) { | |
cf444bcf | 1210 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 1211 | "EXT (%s): ospf_ext_pref_lsa_new() error", __func__); |
cf9b9f77 OD |
1212 | return rc; |
1213 | } | |
1214 | ||
1215 | /* Install this LSA into LSDB. */ | |
1216 | if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) { | |
cf444bcf | 1217 | flog_warn(EC_OSPF_LSA_INSTALL_FAILURE, |
542a208f | 1218 | "EXT (%s): ospf_lsa_install() error", __func__); |
cf9b9f77 OD |
1219 | ospf_lsa_unlock(&new); |
1220 | return rc; | |
1221 | } | |
1222 | ||
1223 | /* Now this Extended Prefix Opaque LSA info parameter entry has | |
7743f2f8 OD |
1224 | * associated LSA. |
1225 | */ | |
cf9b9f77 OD |
1226 | SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED); |
1227 | ||
1228 | /* Update new LSA origination count. */ | |
1229 | area->ospf->lsa_originate_count++; | |
1230 | ||
1231 | /* Flood new LSA through area. */ | |
1232 | ospf_flood_through_area(area, NULL /*nbr */, new); | |
1233 | ||
b37eb79c | 1234 | osr_debug( |
3efd0893 | 1235 | "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSAExtended Prefix Opaque LSA: Area(%pI4), Link(%s)", |
b37eb79c OD |
1236 | __func__, new->data->type, &new->data->id, |
1237 | &area->area_id, exti->ifp->name); | |
1238 | if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) | |
cf9b9f77 | 1239 | ospf_lsa_header_dump(new->data); |
cf9b9f77 OD |
1240 | |
1241 | rc = 0; | |
1242 | ||
1243 | return rc; | |
1244 | } | |
1245 | ||
7743f2f8 OD |
1246 | /* |
1247 | * Process the origination of an Extended Link Opaque LSA | |
1248 | * for every extended link TLV | |
1249 | */ | |
cf9b9f77 OD |
1250 | static int ospf_ext_link_lsa_originate1(struct ospf_area *area, |
1251 | struct ext_itf *exti) | |
1252 | { | |
1253 | struct ospf_lsa *new; | |
1254 | int rc = -1; | |
1255 | ||
1256 | /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */ | |
7743f2f8 OD |
1257 | new = ospf_ext_link_lsa_new(area, exti); |
1258 | if (new == NULL) { | |
cf444bcf | 1259 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 1260 | "EXT (%s): ospf_ext_link_lsa_new() error", __func__); |
cf9b9f77 OD |
1261 | return rc; |
1262 | } | |
1263 | ||
1264 | /* Install this LSA into LSDB. */ | |
1265 | if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) { | |
cf444bcf | 1266 | flog_warn(EC_OSPF_LSA_INSTALL_FAILURE, |
542a208f | 1267 | "EXT (%s): ospf_lsa_install() error", __func__); |
cf9b9f77 OD |
1268 | ospf_lsa_unlock(&new); |
1269 | return rc; | |
1270 | } | |
1271 | ||
1272 | /* Now this link-parameter entry has associated LSA. */ | |
1273 | SET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED); | |
1274 | ||
1275 | /* Update new LSA origination count. */ | |
1276 | area->ospf->lsa_originate_count++; | |
1277 | ||
1278 | /* Flood new LSA through area. */ | |
1279 | ospf_flood_through_area(area, NULL /*nbr */, new); | |
1280 | ||
b37eb79c | 1281 | osr_debug( |
3efd0893 | 1282 | "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSA Extended Link Opaque LSA: Area(%pI4), Link(%s)", |
b37eb79c OD |
1283 | __func__, new->data->type, &new->data->id, |
1284 | &area->area_id, exti->ifp->name); | |
1285 | if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) | |
cf9b9f77 | 1286 | ospf_lsa_header_dump(new->data); |
cf9b9f77 OD |
1287 | |
1288 | rc = 0; | |
1289 | ||
1290 | return rc; | |
1291 | } | |
1292 | ||
1293 | /* Trigger the origination of Extended Prefix Opaque LSAs */ | |
1294 | static int ospf_ext_pref_lsa_originate(void *arg) | |
1295 | { | |
1296 | struct ospf_area *area = (struct ospf_area *)arg; | |
1297 | struct listnode *node; | |
1298 | struct ext_itf *exti; | |
1299 | int rc = -1; | |
1300 | ||
1301 | if (!OspfEXT.enabled) { | |
1302 | zlog_info( | |
b37eb79c | 1303 | "EXT (%s): Segment Routing functionality is Disabled now", |
996c9314 | 1304 | __func__); |
cf9b9f77 OD |
1305 | rc = 0; /* This is not an error case. */ |
1306 | return rc; | |
1307 | } | |
b37eb79c OD |
1308 | osr_debug("EXT (%s): Start Originate Prefix LSA for area %pI4", |
1309 | __func__, &area->area_id); | |
cf9b9f77 OD |
1310 | |
1311 | /* Check if Extended Prefix Opaque LSA is already engaged */ | |
1312 | for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) { | |
1313 | ||
1314 | /* Process only Prefix SID */ | |
1315 | if (exti->stype != PREF_SID) | |
1316 | continue; | |
1317 | ||
1318 | /* Process only Extended Prefix with valid Area ID */ | |
1319 | if ((exti->area == NULL) | |
1320 | || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id))) | |
1321 | continue; | |
1322 | ||
1323 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) { | |
1324 | if (CHECK_FLAG(exti->flags, | |
1325 | EXT_LPFLG_LSA_FORCED_REFRESH)) { | |
ade6974d | 1326 | flog_warn( |
cf444bcf | 1327 | EC_OSPF_EXT_LSA_UNEXPECTED, |
ade6974d | 1328 | "EXT (%s): Refresh instead of Originate", |
996c9314 | 1329 | __func__); |
cf9b9f77 OD |
1330 | UNSET_FLAG(exti->flags, |
1331 | EXT_LPFLG_LSA_FORCED_REFRESH); | |
1332 | ospf_ext_pref_lsa_schedule(exti, | |
1333 | REFRESH_THIS_LSA); | |
1334 | } | |
1335 | continue; | |
1336 | } | |
1337 | ||
1338 | /* Ok, let's try to originate an LSA */ | |
b37eb79c | 1339 | osr_debug( |
3efd0893 | 1340 | "EXT (%s): Let's finally re-originate the LSA 7.0.0.%u for Itf %s", __func__, exti->instance, |
b37eb79c | 1341 | exti->ifp ? exti->ifp->name : ""); |
cf9b9f77 OD |
1342 | ospf_ext_pref_lsa_originate1(area, exti); |
1343 | } | |
1344 | ||
1345 | rc = 0; | |
1346 | return rc; | |
1347 | } | |
1348 | ||
1349 | /* Trigger the origination of Extended Link Opaque LSAs */ | |
1350 | static int ospf_ext_link_lsa_originate(void *arg) | |
1351 | { | |
1352 | struct ospf_area *area = (struct ospf_area *)arg; | |
1353 | struct listnode *node; | |
1354 | struct ext_itf *exti; | |
1355 | int rc = -1; | |
1356 | ||
1357 | if (!OspfEXT.enabled) { | |
1358 | zlog_info( | |
b37eb79c | 1359 | "EXT (%s): Segment Routing functionality is Disabled now", |
996c9314 | 1360 | __func__); |
cf9b9f77 OD |
1361 | rc = 0; /* This is not an error case. */ |
1362 | return rc; | |
1363 | } | |
1364 | ||
1365 | /* Check if Extended Prefix Opaque LSA is already engaged */ | |
1366 | for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) { | |
1367 | /* Process only Adjacency or LAN SID */ | |
1368 | if (exti->stype == PREF_SID) | |
1369 | continue; | |
1370 | ||
21baf89a OD |
1371 | /* Skip Inactive Extended Link */ |
1372 | if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) | |
1373 | continue; | |
1374 | ||
cf9b9f77 OD |
1375 | /* Process only Extended Link with valid Area ID */ |
1376 | if ((exti->area == NULL) | |
1377 | || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id))) | |
1378 | continue; | |
1379 | ||
731271b0 OD |
1380 | /* Skip Extended Link which are not Active */ |
1381 | if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) | |
1382 | continue; | |
1383 | ||
cf9b9f77 OD |
1384 | /* Check if LSA not already engaged */ |
1385 | if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) { | |
1386 | if (CHECK_FLAG(exti->flags, | |
1387 | EXT_LPFLG_LSA_FORCED_REFRESH)) { | |
ade6974d | 1388 | flog_warn( |
cf444bcf | 1389 | EC_OSPF_EXT_LSA_UNEXPECTED, |
ade6974d QY |
1390 | "EXT (%s): Refresh instead of Originate", |
1391 | __func__); | |
cf9b9f77 OD |
1392 | UNSET_FLAG(exti->flags, |
1393 | EXT_LPFLG_LSA_FORCED_REFRESH); | |
1394 | ospf_ext_link_lsa_schedule(exti, | |
1395 | REFRESH_THIS_LSA); | |
1396 | } | |
1397 | continue; | |
1398 | } | |
1399 | ||
1400 | /* Ok, let's try to originate an LSA */ | |
b37eb79c | 1401 | osr_debug( |
3efd0893 | 1402 | "EXT (%s): Let's finally reoriginate the LSA 8.0.0.%u for Itf %s through the Area %pI4", __func__, |
b37eb79c OD |
1403 | exti->instance, exti->ifp ? exti->ifp->name : "-", |
1404 | &area->area_id); | |
cf9b9f77 OD |
1405 | ospf_ext_link_lsa_originate1(area, exti); |
1406 | } | |
1407 | ||
1408 | rc = 0; | |
1409 | return rc; | |
1410 | } | |
1411 | ||
1412 | /* Refresh an Extended Prefix Opaque LSA */ | |
1413 | static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa) | |
1414 | { | |
1415 | struct ospf_lsa *new = NULL; | |
1416 | struct ospf_area *area = lsa->area; | |
1417 | struct ospf *top; | |
1418 | struct ext_itf *exti; | |
1419 | ||
1420 | if (!OspfEXT.enabled) { | |
1421 | /* | |
1422 | * This LSA must have flushed before due to Extended Prefix | |
1423 | * Opaque LSA status change. | |
1424 | * It seems a slip among routers in the routing domain. | |
1425 | */ | |
7743f2f8 | 1426 | zlog_info( |
b37eb79c | 1427 | "EXT (%s): Segment Routing functionality is Disabled", |
996c9314 | 1428 | __func__); |
cf9b9f77 OD |
1429 | /* Flush it anyway. */ |
1430 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); | |
1431 | } | |
1432 | ||
1433 | /* Lookup this lsa corresponding Extended parameters */ | |
7743f2f8 OD |
1434 | exti = lookup_ext_by_instance(lsa); |
1435 | if (exti == NULL) { | |
cf444bcf | 1436 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 1437 | "EXT (%s): Invalid parameter LSA ID", __func__); |
cf9b9f77 OD |
1438 | /* Flush it anyway. */ |
1439 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); | |
1440 | } | |
1441 | ||
1442 | /* Check if Interface was not disable in the interval */ | |
1443 | if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) { | |
cf444bcf | 1444 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 1445 | "EXT (%s): Interface was Disabled: Flush it!", |
996c9314 | 1446 | __func__); |
cf9b9f77 OD |
1447 | /* Flush it anyway. */ |
1448 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); | |
1449 | } | |
1450 | ||
1451 | /* If the lsa's age reached to MaxAge, start flushing procedure. */ | |
1452 | if (IS_LSA_MAXAGE(lsa)) { | |
1453 | if (exti) | |
1454 | UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED); | |
1455 | ospf_opaque_lsa_flush_schedule(lsa); | |
1456 | return NULL; | |
1457 | } | |
1458 | ||
1459 | /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */ | |
db28a51f | 1460 | new = ospf_ext_pref_lsa_new(area, exti); |
cf9b9f77 OD |
1461 | |
1462 | if (new == NULL) { | |
cf444bcf | 1463 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 1464 | "EXT (%s): ospf_ext_pref_lsa_new() error", __func__); |
cf9b9f77 OD |
1465 | return NULL; |
1466 | } | |
1467 | new->data->ls_seqnum = lsa_seqnum_increment(lsa); | |
1468 | ||
7743f2f8 OD |
1469 | /* |
1470 | * Install this LSA into LSDB | |
1471 | * Given "lsa" will be freed in the next function | |
1472 | * As area could be NULL i.e. when using OPAQUE_LSA_AS, we prefer to use | |
1473 | * ospf_lookup() to get ospf instance | |
1474 | */ | |
cf9b9f77 OD |
1475 | if (area) |
1476 | top = area->ospf; | |
1477 | else | |
1478 | top = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
1479 | ||
1480 | if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) { | |
cf444bcf | 1481 | flog_warn(EC_OSPF_LSA_INSTALL_FAILURE, |
542a208f | 1482 | "EXT (%s): ospf_lsa_install() error", __func__); |
cf9b9f77 OD |
1483 | ospf_lsa_unlock(&new); |
1484 | return NULL; | |
1485 | } | |
1486 | ||
1487 | /* Flood updated LSA through the Prefix Area according to the RFC7684 */ | |
1488 | ospf_flood_through_area(area, NULL /*nbr */, new); | |
1489 | ||
1490 | /* Debug logging. */ | |
b37eb79c OD |
1491 | osr_debug("EXT (%s): LSA[Type%u:%pI4] Refresh Extended Prefix LSA", |
1492 | __func__, new->data->type, &new->data->id); | |
1493 | if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) | |
cf9b9f77 | 1494 | ospf_lsa_header_dump(new->data); |
b37eb79c | 1495 | |
cf9b9f77 OD |
1496 | |
1497 | return new; | |
1498 | } | |
1499 | ||
1500 | /* Refresh an Extended Link Opaque LSA */ | |
1501 | static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa) | |
1502 | { | |
1503 | struct ext_itf *exti; | |
1504 | struct ospf_area *area = lsa->area; | |
1505 | struct ospf *top = area->ospf; | |
1506 | struct ospf_lsa *new = NULL; | |
1507 | ||
1508 | if (!OspfEXT.enabled) { | |
1509 | /* | |
1510 | * This LSA must have flushed before due to OSPF-SR status | |
1511 | * change. It seems a slip among routers in the routing domain. | |
1512 | */ | |
996c9314 LB |
1513 | zlog_info("EXT (%s): Segment Routing functionality is Disabled", |
1514 | __func__); | |
cf9b9f77 OD |
1515 | /* Flush it anyway. */ |
1516 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); | |
1517 | } | |
1518 | ||
7743f2f8 OD |
1519 | /* Lookup this LSA corresponding Extended parameters */ |
1520 | exti = lookup_ext_by_instance(lsa); | |
1521 | if (exti == NULL) { | |
cf444bcf | 1522 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 1523 | "EXT (%s): Invalid parameter LSA ID", __func__); |
cf9b9f77 OD |
1524 | /* Flush it anyway. */ |
1525 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); | |
1526 | } | |
1527 | ||
1528 | /* Check if Interface was not disable in the interval */ | |
1529 | if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) { | |
cf444bcf | 1530 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 1531 | "EXT (%s): Interface was Disabled: Flush it!", |
996c9314 | 1532 | __func__); |
cf9b9f77 OD |
1533 | lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); |
1534 | } | |
1535 | ||
7743f2f8 | 1536 | /* If the lsa's age reached to MaxAge, start flushing procedure */ |
cf9b9f77 OD |
1537 | if (IS_LSA_MAXAGE(lsa)) { |
1538 | if (exti) | |
1539 | UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED); | |
1540 | ospf_opaque_lsa_flush_schedule(lsa); | |
1541 | return NULL; | |
1542 | } | |
1543 | ||
7743f2f8 OD |
1544 | /* Create new Opaque-LSA/Extended Link instance */ |
1545 | new = ospf_ext_link_lsa_new(area, exti); | |
1546 | if (new == NULL) { | |
cf444bcf | 1547 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, |
89f60109 | 1548 | "EXT (%s): Error creating new LSA", __func__); |
cf9b9f77 OD |
1549 | return NULL; |
1550 | } | |
1551 | new->data->ls_seqnum = lsa_seqnum_increment(lsa); | |
1552 | ||
1553 | /* Install this LSA into LSDB. */ | |
7743f2f8 | 1554 | /* Given "lsa" will be freed in the next function */ |
cf9b9f77 | 1555 | if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) { |
cf444bcf | 1556 | flog_warn(EC_OSPF_LSA_INSTALL_FAILURE, |
542a208f | 1557 | "EXT (%s): Error installing new LSA", __func__); |
cf9b9f77 OD |
1558 | ospf_lsa_unlock(&new); |
1559 | return NULL; | |
1560 | } | |
1561 | ||
1562 | /* Flood updated LSA through the link Area according to the RFC7684 */ | |
1563 | ospf_flood_through_area(area, NULL /*nbr */, new); | |
1564 | ||
1565 | /* Debug logging. */ | |
b37eb79c OD |
1566 | osr_debug("EXT (%s): LSA[Type%u:%pI4]: Refresh Extended Link LSA", |
1567 | __func__, new->data->type, &new->data->id); | |
1568 | if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) | |
cf9b9f77 | 1569 | ospf_lsa_header_dump(new->data); |
cf9b9f77 OD |
1570 | |
1571 | return new; | |
1572 | } | |
1573 | ||
1574 | /* Schedule Extended Prefix Opaque LSA origination/refreshment/flushing */ | |
1575 | static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti, | |
1576 | enum lsa_opcode opcode) | |
1577 | { | |
1578 | struct ospf_lsa lsa; | |
1579 | struct lsa_header lsah; | |
1580 | struct ospf *top; | |
93f0a26e | 1581 | uint32_t tmp; |
cf9b9f77 OD |
1582 | |
1583 | memset(&lsa, 0, sizeof(lsa)); | |
1584 | memset(&lsah, 0, sizeof(lsah)); | |
1585 | ||
1586 | /* Sanity Check */ | |
1587 | if (exti == NULL) | |
1588 | return; | |
1589 | ||
1590 | /* Check if the corresponding link is ready to be flooded */ | |
1591 | if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))) | |
1592 | return; | |
1593 | ||
b37eb79c OD |
1594 | osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__, |
1595 | opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "", | |
1596 | opcode == REFRESH_THIS_LSA ? "Refresh" : "", | |
1597 | opcode == FLUSH_THIS_LSA ? "Flush" : "", | |
1598 | exti->ifp ? exti->ifp->name : "-"); | |
cf9b9f77 | 1599 | |
731271b0 | 1600 | /* Verify Area */ |
cf9b9f77 | 1601 | if (exti->area == NULL) { |
b37eb79c OD |
1602 | osr_debug( |
1603 | "EXT (%s): Area is not yet set. Try to use Backbone Area", | |
1604 | __func__); | |
731271b0 OD |
1605 | |
1606 | top = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
1607 | struct in_addr backbone = {.s_addr = INADDR_ANY}; | |
1608 | exti->area = ospf_area_lookup_by_area_id(top, backbone); | |
1609 | if (exti->area == NULL) { | |
1610 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, | |
1611 | "EXT (%s): Unable to set Area", __func__); | |
1612 | return; | |
cf9b9f77 | 1613 | } |
cf9b9f77 | 1614 | } |
731271b0 | 1615 | /* Set LSA header information */ |
cf9b9f77 OD |
1616 | lsa.area = exti->area; |
1617 | lsa.data = &lsah; | |
1618 | lsah.type = OSPF_OPAQUE_AREA_LSA; | |
1619 | tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_PREFIX_LSA, exti->instance); | |
1620 | lsah.id.s_addr = htonl(tmp); | |
1621 | ||
1622 | switch (opcode) { | |
1623 | case REORIGINATE_THIS_LSA: | |
1624 | ospf_opaque_lsa_reoriginate_schedule( | |
1625 | (void *)exti->area, OSPF_OPAQUE_AREA_LSA, | |
1626 | OPAQUE_TYPE_EXTENDED_PREFIX_LSA); | |
1627 | break; | |
1628 | case REFRESH_THIS_LSA: | |
1629 | ospf_opaque_lsa_refresh_schedule(&lsa); | |
1630 | break; | |
1631 | case FLUSH_THIS_LSA: | |
1632 | UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED); | |
1633 | ospf_opaque_lsa_flush_schedule(&lsa); | |
1634 | break; | |
cf9b9f77 | 1635 | } |
cf9b9f77 OD |
1636 | } |
1637 | ||
1638 | /* Schedule Extended Link Opaque LSA origination/refreshment/flushing */ | |
1639 | static void ospf_ext_link_lsa_schedule(struct ext_itf *exti, | |
1640 | enum lsa_opcode opcode) | |
1641 | { | |
1642 | struct ospf_lsa lsa; | |
1643 | struct lsa_header lsah; | |
1644 | struct ospf *top; | |
93f0a26e | 1645 | uint32_t tmp; |
cf9b9f77 OD |
1646 | |
1647 | memset(&lsa, 0, sizeof(lsa)); | |
1648 | memset(&lsah, 0, sizeof(lsah)); | |
1649 | ||
1650 | /* Sanity Check */ | |
1651 | if (exti == NULL) | |
1652 | return; | |
1653 | ||
1654 | /* Check if the corresponding link is ready to be flooded */ | |
1655 | if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))) | |
1656 | return; | |
1657 | ||
b37eb79c OD |
1658 | osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__, |
1659 | opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "", | |
1660 | opcode == REFRESH_THIS_LSA ? "Refresh" : "", | |
1661 | opcode == FLUSH_THIS_LSA ? "Flush" : "", | |
1662 | exti->ifp ? exti->ifp->name : "-"); | |
cf9b9f77 | 1663 | |
731271b0 | 1664 | /* Verify Area */ |
cf9b9f77 | 1665 | if (exti->area == NULL) { |
b37eb79c OD |
1666 | osr_debug( |
1667 | "EXT (%s): Area is not yet set. Try to use Backbone Area", | |
1668 | __func__); | |
731271b0 OD |
1669 | |
1670 | top = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
1671 | struct in_addr backbone = {.s_addr = INADDR_ANY}; | |
1672 | exti->area = ospf_area_lookup_by_area_id(top, backbone); | |
1673 | if (exti->area == NULL) { | |
1674 | flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED, | |
1675 | "EXT (%s): Unable to set Area", __func__); | |
1676 | return; | |
cf9b9f77 | 1677 | } |
cf9b9f77 | 1678 | } |
731271b0 | 1679 | /* Set LSA header information */ |
cf9b9f77 OD |
1680 | lsa.area = exti->area; |
1681 | lsa.data = &lsah; | |
1682 | lsah.type = OSPF_OPAQUE_AREA_LSA; | |
1683 | tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance); | |
1684 | lsah.id.s_addr = htonl(tmp); | |
1685 | ||
1686 | switch (opcode) { | |
1687 | case REORIGINATE_THIS_LSA: | |
1688 | ospf_opaque_lsa_reoriginate_schedule( | |
1689 | (void *)exti->area, OSPF_OPAQUE_AREA_LSA, | |
1690 | OPAQUE_TYPE_EXTENDED_LINK_LSA); | |
1691 | break; | |
1692 | case REFRESH_THIS_LSA: | |
1693 | ospf_opaque_lsa_refresh_schedule(&lsa); | |
1694 | break; | |
1695 | case FLUSH_THIS_LSA: | |
cf9b9f77 OD |
1696 | ospf_opaque_lsa_flush_schedule(&lsa); |
1697 | break; | |
cf9b9f77 | 1698 | } |
cf9b9f77 OD |
1699 | } |
1700 | ||
1701 | /* Schedule Extended Link or Prefix depending of the Type of LSA */ | |
1702 | static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op) | |
1703 | { | |
1704 | ||
1705 | if (exti->stype == PREF_SID) | |
1706 | ospf_ext_pref_lsa_schedule(exti, op); | |
1707 | else | |
1708 | ospf_ext_link_lsa_schedule(exti, op); | |
1709 | } | |
1710 | ||
7743f2f8 OD |
1711 | /* |
1712 | * ------------------------------------ | |
cf9b9f77 | 1713 | * Followings are vty show functions. |
7743f2f8 OD |
1714 | * ------------------------------------ |
1715 | */ | |
1716 | ||
cf9b9f77 | 1717 | /* Cisco experimental SubTLV */ |
93f0a26e | 1718 | static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty *vty, |
996c9314 | 1719 | struct tlv_header *tlvh) |
cf9b9f77 OD |
1720 | { |
1721 | struct ext_subtlv_rmt_itf_addr *top; | |
7743f2f8 | 1722 | |
cf9b9f77 OD |
1723 | top = (struct ext_subtlv_rmt_itf_addr *)tlvh; |
1724 | ||
1725 | vty_out(vty, | |
3efd0893 | 1726 | " Remote Interface Address Sub-TLV: Length %u\n Address: %s\n", |
cf9b9f77 OD |
1727 | ntohs(top->header.length), inet_ntoa(top->value)); |
1728 | ||
1729 | return TLV_SIZE(tlvh); | |
1730 | } | |
1731 | ||
1732 | /* Adjacency SID SubTLV */ | |
93f0a26e | 1733 | static uint16_t show_vty_ext_link_adj_sid(struct vty *vty, |
996c9314 | 1734 | struct tlv_header *tlvh) |
cf9b9f77 OD |
1735 | { |
1736 | struct ext_subtlv_adj_sid *top = (struct ext_subtlv_adj_sid *)tlvh; | |
1737 | ||
1738 | vty_out(vty, | |
3efd0893 | 1739 | " Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n", |
cf9b9f77 OD |
1740 | ntohs(top->header.length), top->flags, top->mtid, top->weight, |
1741 | CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label" | |
1742 | : "Index", | |
1743 | CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) | |
1744 | ? GET_LABEL(ntohl(top->value)) | |
1745 | : ntohl(top->value)); | |
1746 | ||
1747 | return TLV_SIZE(tlvh); | |
1748 | } | |
1749 | ||
1750 | /* LAN Adjacency SubTLV */ | |
93f0a26e | 1751 | static uint16_t show_vty_ext_link_lan_adj_sid(struct vty *vty, |
996c9314 | 1752 | struct tlv_header *tlvh) |
cf9b9f77 OD |
1753 | { |
1754 | struct ext_subtlv_lan_adj_sid *top = | |
1755 | (struct ext_subtlv_lan_adj_sid *)tlvh; | |
1756 | ||
1757 | vty_out(vty, | |
3efd0893 | 1758 | " LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: %s\n\t%s: %u\n", |
cf9b9f77 | 1759 | ntohs(top->header.length), top->flags, top->mtid, top->weight, |
d922605d | 1760 | inet_ntoa(top->neighbor_id), |
cf9b9f77 OD |
1761 | CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label" |
1762 | : "Index", | |
1763 | CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) | |
1764 | ? GET_LABEL(ntohl(top->value)) | |
1765 | : ntohl(top->value)); | |
1766 | ||
1767 | return TLV_SIZE(tlvh); | |
1768 | } | |
1769 | ||
93f0a26e | 1770 | static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh) |
cf9b9f77 OD |
1771 | { |
1772 | vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n", | |
1773 | ntohs(tlvh->type), ntohs(tlvh->length)); | |
1774 | ||
1775 | return TLV_SIZE(tlvh); | |
1776 | } | |
1777 | ||
1778 | /* Extended Link Sub TLVs */ | |
93f0a26e | 1779 | static uint16_t show_vty_link_info(struct vty *vty, struct tlv_header *ext) |
cf9b9f77 OD |
1780 | { |
1781 | struct ext_tlv_link *top = (struct ext_tlv_link *)ext; | |
1782 | struct tlv_header *tlvh; | |
93f0a26e OD |
1783 | uint16_t length = ntohs(top->header.length) - 3 * sizeof(uint32_t); |
1784 | uint16_t sum = 0; | |
cf9b9f77 OD |
1785 | |
1786 | vty_out(vty, | |
7743f2f8 | 1787 | " Extended Link TLV: Length %u\n Link Type: 0x%x\n" |
cf9b9f77 OD |
1788 | " Link ID: %s\n", |
1789 | ntohs(top->header.length), top->link_type, | |
1790 | inet_ntoa(top->link_id)); | |
1791 | vty_out(vty, " Link data: %s\n", inet_ntoa(top->link_data)); | |
1792 | ||
1793 | tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE | |
1794 | + EXT_TLV_LINK_SIZE); | |
1795 | for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) { | |
1796 | switch (ntohs(tlvh->type)) { | |
1797 | case EXT_SUBTLV_ADJ_SID: | |
1798 | sum += show_vty_ext_link_adj_sid(vty, tlvh); | |
1799 | break; | |
1800 | case EXT_SUBTLV_LAN_ADJ_SID: | |
1801 | sum += show_vty_ext_link_lan_adj_sid(vty, tlvh); | |
1802 | break; | |
1803 | case EXT_SUBTLV_RMT_ITF_ADDR: | |
1804 | sum += show_vty_ext_link_rmt_itf_addr(vty, tlvh); | |
1805 | break; | |
1806 | default: | |
1807 | sum += show_vty_unknown_tlv(vty, tlvh); | |
1808 | break; | |
1809 | } | |
1810 | } | |
1811 | ||
1812 | return sum + sizeof(struct ext_tlv_link); | |
1813 | } | |
1814 | ||
1815 | /* Extended Link TLVs */ | |
1816 | static void ospf_ext_link_show_info(struct vty *vty, struct ospf_lsa *lsa) | |
1817 | { | |
c4efd0f4 | 1818 | struct lsa_header *lsah = lsa->data; |
cf9b9f77 | 1819 | struct tlv_header *tlvh; |
93f0a26e | 1820 | uint16_t length = 0, sum = 0; |
cf9b9f77 OD |
1821 | |
1822 | /* Initialize TLV browsing */ | |
1823 | length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE; | |
1824 | ||
1825 | for (tlvh = TLV_HDR_TOP(lsah); sum < length; | |
1826 | tlvh = TLV_HDR_NEXT(tlvh)) { | |
1827 | switch (ntohs(tlvh->type)) { | |
1828 | case EXT_TLV_LINK: | |
1829 | sum += show_vty_link_info(vty, tlvh); | |
1830 | break; | |
1831 | default: | |
1832 | sum += show_vty_unknown_tlv(vty, tlvh); | |
1833 | break; | |
1834 | } | |
1835 | } | |
cf9b9f77 OD |
1836 | } |
1837 | ||
1838 | /* Prefix SID SubTLV */ | |
93f0a26e | 1839 | static uint16_t show_vty_ext_pref_pref_sid(struct vty *vty, |
996c9314 | 1840 | struct tlv_header *tlvh) |
cf9b9f77 OD |
1841 | { |
1842 | struct ext_subtlv_prefix_sid *top = | |
1843 | (struct ext_subtlv_prefix_sid *)tlvh; | |
1844 | ||
1845 | vty_out(vty, | |
3efd0893 | 1846 | " Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n", |
cf9b9f77 OD |
1847 | ntohs(top->header.length), top->algorithm, top->flags, |
1848 | top->mtid, | |
1849 | CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) ? "Label" | |
1850 | : "Index", | |
1851 | CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) | |
1852 | ? GET_LABEL(ntohl(top->value)) | |
1853 | : ntohl(top->value)); | |
1854 | ||
1855 | return TLV_SIZE(tlvh); | |
1856 | } | |
1857 | ||
1858 | /* Extended Prefix SubTLVs */ | |
93f0a26e | 1859 | static uint16_t show_vty_pref_info(struct vty *vty, struct tlv_header *ext) |
cf9b9f77 OD |
1860 | { |
1861 | struct ext_tlv_prefix *top = (struct ext_tlv_prefix *)ext; | |
1862 | struct tlv_header *tlvh; | |
93f0a26e OD |
1863 | uint16_t length = ntohs(top->header.length) - 2 * sizeof(uint32_t); |
1864 | uint16_t sum = 0; | |
cf9b9f77 OD |
1865 | |
1866 | vty_out(vty, | |
7743f2f8 OD |
1867 | " Extended Prefix TLV: Length %u\n\tRoute Type: %u\n" |
1868 | "\tAddress Family: 0x%x\n\tFlags: 0x%x\n\tAddress: %s/%u\n", | |
cf9b9f77 OD |
1869 | ntohs(top->header.length), top->route_type, top->af, top->flags, |
1870 | inet_ntoa(top->address), top->pref_length); | |
1871 | ||
1872 | tlvh = (struct tlv_header *)((char *)(ext) + TLV_HDR_SIZE | |
1873 | + EXT_TLV_PREFIX_SIZE); | |
1874 | for (; sum < length; tlvh = TLV_HDR_NEXT(tlvh)) { | |
1875 | switch (ntohs(tlvh->type)) { | |
1876 | case EXT_SUBTLV_PREFIX_SID: | |
1877 | sum += show_vty_ext_pref_pref_sid(vty, tlvh); | |
1878 | break; | |
1879 | default: | |
1880 | sum += show_vty_unknown_tlv(vty, tlvh); | |
1881 | break; | |
1882 | } | |
1883 | } | |
1884 | ||
1885 | return sum + sizeof(struct ext_tlv_prefix); | |
1886 | } | |
1887 | ||
1888 | /* Extended Prefix TLVs */ | |
1889 | static void ospf_ext_pref_show_info(struct vty *vty, struct ospf_lsa *lsa) | |
1890 | { | |
c4efd0f4 | 1891 | struct lsa_header *lsah = lsa->data; |
cf9b9f77 | 1892 | struct tlv_header *tlvh; |
93f0a26e | 1893 | uint16_t length = 0, sum = 0; |
cf9b9f77 OD |
1894 | |
1895 | /* Initialize TLV browsing */ | |
1896 | length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE; | |
1897 | ||
1898 | for (tlvh = TLV_HDR_TOP(lsah); sum < length; | |
1899 | tlvh = TLV_HDR_NEXT(tlvh)) { | |
1900 | switch (ntohs(tlvh->type)) { | |
1901 | case EXT_TLV_PREFIX: | |
1902 | sum += show_vty_pref_info(vty, tlvh); | |
1903 | break; | |
1904 | default: | |
1905 | sum += show_vty_unknown_tlv(vty, tlvh); | |
1906 | break; | |
1907 | } | |
1908 | } | |
cf9b9f77 | 1909 | } |