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