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