]>
Commit | Line | Data |
---|---|---|
eb5d44eb | 1 | /* |
2 | * IS-IS Rout(e)ing protocol - isis_circuit.h | |
3 | * | |
4 | * Copyright (C) 2001,2002 Sampo Saaristo | |
d62a17ae | 5 | * Tampere University of Technology |
eb5d44eb | 6 | * Institute of Communications Engineering |
7 | * | |
d62a17ae | 8 | * This program is free software; you can redistribute it and/or modify it |
9 | * under the terms of the GNU General Public Licenseas published by the Free | |
10 | * Software Foundation; either version 2 of the License, or (at your option) | |
eb5d44eb | 11 | * any later version. |
12 | * | |
d62a17ae | 13 | * This program is distributed in the hope that it will be useful,but WITHOUT |
14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
eb5d44eb | 16 | * more details. |
896014f4 DL |
17 | * |
18 | * You should have received a copy of the GNU General Public License along | |
19 | * with this program; see the file COPYING; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
eb5d44eb | 21 | */ |
eb5d44eb | 22 | #include <zebra.h> |
37da8c01 | 23 | #ifdef GNU_LINUX |
eb5d44eb | 24 | #include <net/ethernet.h> |
37da8c01 | 25 | #else |
26 | #include <netinet/if_ether.h> | |
27 | #endif | |
eb5d44eb | 28 | |
29 | #include "log.h" | |
30 | #include "memory.h" | |
b2d7c082 | 31 | #include "vrf.h" |
eb5d44eb | 32 | #include "if.h" |
33 | #include "linklist.h" | |
34 | #include "command.h" | |
35 | #include "thread.h" | |
f8c06e2c | 36 | #include "vty.h" |
eb5d44eb | 37 | #include "hash.h" |
38 | #include "prefix.h" | |
39 | #include "stream.h" | |
676a4ea3 | 40 | #include "qobj.h" |
20600086 | 41 | #include "lib/northbound_cli.h" |
eb5d44eb | 42 | |
43 | #include "isisd/dict.h" | |
eb5d44eb | 44 | #include "isisd/isis_constants.h" |
45 | #include "isisd/isis_common.h" | |
3f045a08 | 46 | #include "isisd/isis_flags.h" |
eb5d44eb | 47 | #include "isisd/isis_circuit.h" |
eb5d44eb | 48 | #include "isisd/isis_lsp.h" |
49 | #include "isisd/isis_pdu.h" | |
50 | #include "isisd/isis_network.h" | |
51 | #include "isisd/isis_misc.h" | |
52 | #include "isisd/isis_constants.h" | |
53 | #include "isisd/isis_adjacency.h" | |
54 | #include "isisd/isis_dr.h" | |
eb5d44eb | 55 | #include "isisd/isisd.h" |
56 | #include "isisd/isis_csm.h" | |
57 | #include "isisd/isis_events.h" | |
f8c06e2c | 58 | #include "isisd/isis_te.h" |
064f4896 | 59 | #include "isisd/isis_mt.h" |
54ece698 | 60 | #include "isisd/isis_errors.h" |
9b39405f | 61 | #include "isisd/isis_tx_queue.h" |
eb5d44eb | 62 | |
676a4ea3 DL |
63 | DEFINE_QOBJ_TYPE(isis_circuit) |
64 | ||
41b36e90 PJ |
65 | /* |
66 | * Prototypes. | |
67 | */ | |
41b36e90 PJ |
68 | int isis_interface_config_write(struct vty *); |
69 | int isis_if_new_hook(struct interface *); | |
70 | int isis_if_delete_hook(struct interface *); | |
71 | ||
d62a17ae | 72 | struct isis_circuit *isis_circuit_new() |
eb5d44eb | 73 | { |
d62a17ae | 74 | struct isis_circuit *circuit; |
75 | int i; | |
76 | ||
77 | circuit = XCALLOC(MTYPE_ISIS_CIRCUIT, sizeof(struct isis_circuit)); | |
d62a17ae | 78 | |
79 | /* | |
80 | * Default values | |
81 | */ | |
82 | circuit->is_type = IS_LEVEL_1_AND_2; | |
83 | circuit->flags = 0; | |
84 | circuit->pad_hellos = 1; | |
85 | for (i = 0; i < 2; i++) { | |
86 | circuit->hello_interval[i] = DEFAULT_HELLO_INTERVAL; | |
87 | circuit->hello_multiplier[i] = DEFAULT_HELLO_MULTIPLIER; | |
88 | circuit->csnp_interval[i] = DEFAULT_CSNP_INTERVAL; | |
89 | circuit->psnp_interval[i] = DEFAULT_PSNP_INTERVAL; | |
90 | circuit->priority[i] = DEFAULT_PRIORITY; | |
91 | circuit->metric[i] = DEFAULT_CIRCUIT_METRIC; | |
92 | circuit->te_metric[i] = DEFAULT_CIRCUIT_METRIC; | |
7da4aa3c CF |
93 | circuit->level_arg[i].level = i + 1; |
94 | circuit->level_arg[i].circuit = circuit; | |
d62a17ae | 95 | } |
96 | ||
97 | circuit->mtc = mpls_te_circuit_new(); | |
98 | ||
99 | circuit_mt_init(circuit); | |
100 | ||
101 | QOBJ_REG(circuit, isis_circuit); | |
102 | ||
103 | return circuit; | |
eb5d44eb | 104 | } |
105 | ||
d62a17ae | 106 | void isis_circuit_del(struct isis_circuit *circuit) |
3f045a08 | 107 | { |
d62a17ae | 108 | if (!circuit) |
109 | return; | |
3f045a08 | 110 | |
d62a17ae | 111 | QOBJ_UNREG(circuit); |
676a4ea3 | 112 | |
d62a17ae | 113 | isis_circuit_if_unbind(circuit, circuit->interface); |
3f045a08 | 114 | |
d62a17ae | 115 | circuit_mt_finish(circuit); |
064f4896 | 116 | |
d62a17ae | 117 | /* and lastly the circuit itself */ |
118 | XFREE(MTYPE_ISIS_CIRCUIT, circuit); | |
3f045a08 | 119 | |
d62a17ae | 120 | return; |
3f045a08 JB |
121 | } |
122 | ||
d62a17ae | 123 | void isis_circuit_configure(struct isis_circuit *circuit, |
124 | struct isis_area *area) | |
eb5d44eb | 125 | { |
d62a17ae | 126 | assert(area); |
127 | circuit->area = area; | |
128 | ||
129 | /* | |
130 | * Whenever the is-type of an area is changed, the is-type of each | |
131 | * circuit | |
132 | * in that area is updated to a non-empty subset of the area is-type. | |
133 | * Inversely, when configuring a new circuit, this property should be | |
134 | * ensured as well. | |
135 | */ | |
136 | if (area->is_type != IS_LEVEL_1_AND_2) | |
137 | circuit->is_type = area->is_type; | |
138 | ||
139 | /* | |
140 | * Add the circuit into area | |
141 | */ | |
142 | listnode_add(area->circuit_list, circuit); | |
143 | ||
144 | circuit->idx = flags_get_index(&area->flags); | |
145 | ||
146 | return; | |
eb5d44eb | 147 | } |
148 | ||
d62a17ae | 149 | void isis_circuit_deconfigure(struct isis_circuit *circuit, |
150 | struct isis_area *area) | |
eb5d44eb | 151 | { |
d62a17ae | 152 | /* Free the index of SRM and SSN flags */ |
153 | flags_free_index(&area->flags, circuit->idx); | |
154 | circuit->idx = 0; | |
155 | /* Remove circuit from area */ | |
156 | assert(circuit->area == area); | |
157 | listnode_delete(area->circuit_list, circuit); | |
158 | circuit->area = NULL; | |
159 | ||
160 | return; | |
eb5d44eb | 161 | } |
162 | ||
d62a17ae | 163 | struct isis_circuit *circuit_lookup_by_ifp(struct interface *ifp, |
164 | struct list *list) | |
eb5d44eb | 165 | { |
d62a17ae | 166 | struct isis_circuit *circuit = NULL; |
167 | struct listnode *node; | |
f390d2c7 | 168 | |
d62a17ae | 169 | if (!list) |
170 | return NULL; | |
f390d2c7 | 171 | |
d62a17ae | 172 | for (ALL_LIST_ELEMENTS_RO(list, node, circuit)) |
173 | if (circuit->interface == ifp) { | |
174 | assert(ifp->info == circuit); | |
175 | return circuit; | |
176 | } | |
3f045a08 | 177 | |
d62a17ae | 178 | return NULL; |
eb5d44eb | 179 | } |
180 | ||
d62a17ae | 181 | struct isis_circuit *circuit_scan_by_ifp(struct interface *ifp) |
eb5d44eb | 182 | { |
d62a17ae | 183 | struct isis_area *area; |
184 | struct listnode *node; | |
185 | struct isis_circuit *circuit; | |
186 | ||
187 | if (ifp->info) | |
188 | return (struct isis_circuit *)ifp->info; | |
189 | ||
190 | if (isis->area_list) { | |
191 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { | |
192 | circuit = | |
193 | circuit_lookup_by_ifp(ifp, area->circuit_list); | |
194 | if (circuit) | |
195 | return circuit; | |
196 | } | |
197 | } | |
198 | return circuit_lookup_by_ifp(ifp, isis->init_circ_list); | |
eb5d44eb | 199 | } |
200 | ||
d62a17ae | 201 | void isis_circuit_add_addr(struct isis_circuit *circuit, |
202 | struct connected *connected) | |
eb5d44eb | 203 | { |
d62a17ae | 204 | struct listnode *node; |
205 | struct prefix_ipv4 *ipv4; | |
4690c7d7 | 206 | #if defined(EXTREME_DEBUG) |
d62a17ae | 207 | char buf[PREFIX2STR_BUFFER]; |
4690c7d7 | 208 | #endif |
d62a17ae | 209 | struct prefix_ipv6 *ipv6; |
f891f443 | 210 | |
d62a17ae | 211 | if (connected->address->family == AF_INET) { |
d7c0a89a | 212 | uint32_t addr = connected->address->u.prefix4.s_addr; |
d62a17ae | 213 | addr = ntohl(addr); |
214 | if (IPV4_NET0(addr) || IPV4_NET127(addr) || IN_CLASSD(addr) | |
215 | || IPV4_LINKLOCAL(addr)) | |
216 | return; | |
3f045a08 | 217 | |
d62a17ae | 218 | for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ipv4)) |
219 | if (prefix_same((struct prefix *)ipv4, | |
220 | connected->address)) | |
221 | return; | |
3f045a08 | 222 | |
d62a17ae | 223 | ipv4 = prefix_ipv4_new(); |
224 | ipv4->prefixlen = connected->address->prefixlen; | |
225 | ipv4->prefix = connected->address->u.prefix4; | |
226 | listnode_add(circuit->ip_addrs, ipv4); | |
f8c06e2c | 227 | |
d62a17ae | 228 | /* Update MPLS TE Local IP address parameter */ |
229 | set_circuitparams_local_ipaddr(circuit->mtc, ipv4->prefix); | |
f8c06e2c | 230 | |
d62a17ae | 231 | if (circuit->area) |
232 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
233 | 0); | |
f891f443 | 234 | |
eb5d44eb | 235 | #ifdef EXTREME_DEBUG |
d62a17ae | 236 | prefix2str(connected->address, buf, sizeof(buf)); |
c59f88c8 CF |
237 | zlog_debug("Added IP address %s to circuit %s", buf, |
238 | circuit->interface->name); | |
f390d2c7 | 239 | #endif /* EXTREME_DEBUG */ |
d62a17ae | 240 | } |
241 | if (connected->address->family == AF_INET6) { | |
242 | if (IN6_IS_ADDR_LOOPBACK(&connected->address->u.prefix6)) | |
243 | return; | |
244 | ||
245 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, ipv6)) | |
246 | if (prefix_same((struct prefix *)ipv6, | |
247 | connected->address)) | |
248 | return; | |
249 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, ipv6)) | |
250 | if (prefix_same((struct prefix *)ipv6, | |
251 | connected->address)) | |
252 | return; | |
253 | ||
254 | ipv6 = prefix_ipv6_new(); | |
255 | ipv6->prefixlen = connected->address->prefixlen; | |
256 | ipv6->prefix = connected->address->u.prefix6; | |
257 | ||
258 | if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix)) | |
259 | listnode_add(circuit->ipv6_link, ipv6); | |
260 | else | |
261 | listnode_add(circuit->ipv6_non_link, ipv6); | |
262 | if (circuit->area) | |
263 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
264 | 0); | |
f891f443 | 265 | |
eb5d44eb | 266 | #ifdef EXTREME_DEBUG |
d62a17ae | 267 | prefix2str(connected->address, buf, sizeof(buf)); |
c59f88c8 CF |
268 | zlog_debug("Added IPv6 address %s to circuit %s", buf, |
269 | circuit->interface->name); | |
f390d2c7 | 270 | #endif /* EXTREME_DEBUG */ |
d62a17ae | 271 | } |
272 | return; | |
eb5d44eb | 273 | } |
274 | ||
d62a17ae | 275 | void isis_circuit_del_addr(struct isis_circuit *circuit, |
276 | struct connected *connected) | |
eb5d44eb | 277 | { |
d62a17ae | 278 | struct prefix_ipv4 *ipv4, *ip = NULL; |
279 | struct listnode *node; | |
280 | char buf[PREFIX2STR_BUFFER]; | |
281 | struct prefix_ipv6 *ipv6, *ip6 = NULL; | |
282 | int found = 0; | |
283 | ||
284 | if (connected->address->family == AF_INET) { | |
285 | ipv4 = prefix_ipv4_new(); | |
286 | ipv4->prefixlen = connected->address->prefixlen; | |
287 | ipv4->prefix = connected->address->u.prefix4; | |
288 | ||
289 | for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ip)) | |
290 | if (prefix_same((struct prefix *)ip, | |
291 | (struct prefix *)ipv4)) | |
292 | break; | |
293 | ||
294 | if (ip) { | |
295 | listnode_delete(circuit->ip_addrs, ip); | |
d0a6f3e0 | 296 | prefix_ipv4_free(ip); |
d62a17ae | 297 | if (circuit->area) |
298 | lsp_regenerate_schedule(circuit->area, | |
299 | circuit->is_type, 0); | |
300 | } else { | |
301 | prefix2str(connected->address, buf, sizeof(buf)); | |
302 | zlog_warn( | |
c59f88c8 CF |
303 | "Nonexistent ip address %s removal attempt from \ |
304 | circuit %s", | |
305 | buf, circuit->interface->name); | |
d62a17ae | 306 | zlog_warn("Current ip addresses on %s:", |
307 | circuit->interface->name); | |
308 | for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, | |
309 | ip)) { | |
310 | prefix2str(ip, buf, sizeof(buf)); | |
311 | zlog_warn(" %s", buf); | |
312 | } | |
313 | zlog_warn("End of addresses"); | |
314 | } | |
315 | ||
316 | prefix_ipv4_free(ipv4); | |
f891f443 | 317 | } |
d62a17ae | 318 | if (connected->address->family == AF_INET6) { |
319 | ipv6 = prefix_ipv6_new(); | |
320 | ipv6->prefixlen = connected->address->prefixlen; | |
321 | ipv6->prefix = connected->address->u.prefix6; | |
322 | ||
323 | if (IN6_IS_ADDR_LINKLOCAL(&ipv6->prefix)) { | |
324 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, | |
325 | ip6)) { | |
326 | if (prefix_same((struct prefix *)ip6, | |
327 | (struct prefix *)ipv6)) | |
328 | break; | |
329 | } | |
330 | if (ip6) { | |
331 | listnode_delete(circuit->ipv6_link, ip6); | |
d0a6f3e0 | 332 | prefix_ipv6_free(ip6); |
d62a17ae | 333 | found = 1; |
334 | } | |
335 | } else { | |
336 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, | |
337 | ip6)) { | |
338 | if (prefix_same((struct prefix *)ip6, | |
339 | (struct prefix *)ipv6)) | |
340 | break; | |
341 | } | |
342 | if (ip6) { | |
343 | listnode_delete(circuit->ipv6_non_link, ip6); | |
d0a6f3e0 | 344 | prefix_ipv6_free(ip6); |
d62a17ae | 345 | found = 1; |
346 | } | |
347 | } | |
348 | ||
349 | if (!found) { | |
350 | prefix2str(connected->address, buf, sizeof(buf)); | |
351 | zlog_warn( | |
c59f88c8 CF |
352 | "Nonexistent ip address %s removal attempt from \ |
353 | circuit %s", | |
354 | buf, circuit->interface->name); | |
d62a17ae | 355 | zlog_warn("Current ip addresses on %s:", |
356 | circuit->interface->name); | |
357 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, | |
358 | ip6)) { | |
359 | prefix2str((struct prefix *)ip6, (char *)buf, | |
c28135f3 | 360 | sizeof(buf)); |
d62a17ae | 361 | zlog_warn(" %s", buf); |
362 | } | |
363 | zlog_warn(" -----"); | |
364 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, | |
365 | ip6)) { | |
366 | prefix2str((struct prefix *)ip6, (char *)buf, | |
c28135f3 | 367 | sizeof(buf)); |
d62a17ae | 368 | zlog_warn(" %s", buf); |
369 | } | |
370 | zlog_warn("End of addresses"); | |
371 | } else if (circuit->area) | |
372 | lsp_regenerate_schedule(circuit->area, circuit->is_type, | |
373 | 0); | |
374 | ||
375 | prefix_ipv6_free(ipv6); | |
f891f443 | 376 | } |
d62a17ae | 377 | return; |
378 | } | |
e8aca32f | 379 | |
0849c75e | 380 | static uint8_t isis_circuit_id_gen(struct isis *isis, struct interface *ifp) |
d62a17ae | 381 | { |
068c8222 CF |
382 | /* Circuit ids MUST be unique for any broadcast circuits. Otherwise, |
383 | * Pseudo-Node LSPs cannot be generated correctly. | |
384 | * | |
98c5bc15 | 385 | * Currently, allocate one circuit ID for any circuit, limiting the total |
068c8222 CF |
386 | * numer of circuits IS-IS can run on to 255. |
387 | * | |
98c5bc15 | 388 | * We should revisit this when implementing 3-way adjacencies for p2p, since |
068c8222 CF |
389 | * we then have extended interface IDs available. |
390 | */ | |
391 | uint8_t id = ifp->ifindex; | |
d62a17ae | 392 | unsigned int i; |
d62a17ae | 393 | |
068c8222 CF |
394 | for (i = 0; i < 256; i++) { |
395 | if (id && !_ISIS_CHECK_FLAG(isis->circuit_ids_used, id)) | |
d62a17ae | 396 | break; |
068c8222 | 397 | id++; |
f891f443 | 398 | } |
399 | ||
068c8222 | 400 | if (i == 256) { |
996c9314 LB |
401 | zlog_warn("Could not allocate a circuit id for '%s'", |
402 | ifp->name); | |
068c8222 | 403 | return 0; |
f891f443 | 404 | } |
e8aca32f | 405 | |
0849c75e | 406 | _ISIS_SET_FLAG(isis->circuit_ids_used, id); |
d62a17ae | 407 | return id; |
3f045a08 JB |
408 | } |
409 | ||
d62a17ae | 410 | void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp) |
eb5d44eb | 411 | { |
d62a17ae | 412 | struct listnode *node, *nnode; |
413 | struct connected *conn; | |
414 | ||
d62a17ae | 415 | isis_circuit_if_bind(circuit, ifp); |
d62a17ae | 416 | |
417 | if (if_is_broadcast(ifp)) { | |
65f18157 | 418 | if (fabricd || circuit->circ_type_config == CIRCUIT_T_P2P) |
d62a17ae | 419 | circuit->circ_type = CIRCUIT_T_P2P; |
420 | else | |
421 | circuit->circ_type = CIRCUIT_T_BROADCAST; | |
422 | } else if (if_is_pointopoint(ifp)) { | |
423 | circuit->circ_type = CIRCUIT_T_P2P; | |
424 | } else if (if_is_loopback(ifp)) { | |
425 | circuit->circ_type = CIRCUIT_T_LOOPBACK; | |
426 | circuit->is_passive = 1; | |
427 | } else { | |
428 | /* It's normal in case of loopback etc. */ | |
429 | if (isis->debugs & DEBUG_EVENTS) | |
430 | zlog_debug("isis_circuit_if_add: unsupported media"); | |
431 | circuit->circ_type = CIRCUIT_T_UNKNOWN; | |
432 | } | |
433 | ||
434 | circuit->ip_addrs = list_new(); | |
435 | circuit->ipv6_link = list_new(); | |
436 | circuit->ipv6_non_link = list_new(); | |
437 | ||
438 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn)) | |
439 | isis_circuit_add_addr(circuit, conn); | |
eb5d44eb | 440 | } |
441 | ||
d62a17ae | 442 | void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp) |
eb5d44eb | 443 | { |
d62a17ae | 444 | struct listnode *node, *nnode; |
445 | struct connected *conn; | |
446 | ||
447 | assert(circuit->interface == ifp); | |
448 | ||
449 | /* destroy addresses */ | |
450 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn)) | |
451 | isis_circuit_del_addr(circuit, conn); | |
452 | ||
453 | if (circuit->ip_addrs) { | |
454 | assert(listcount(circuit->ip_addrs) == 0); | |
6a154c88 | 455 | list_delete(&circuit->ip_addrs); |
d62a17ae | 456 | } |
457 | ||
458 | if (circuit->ipv6_link) { | |
459 | assert(listcount(circuit->ipv6_link) == 0); | |
6a154c88 | 460 | list_delete(&circuit->ipv6_link); |
d62a17ae | 461 | } |
462 | ||
463 | if (circuit->ipv6_non_link) { | |
464 | assert(listcount(circuit->ipv6_non_link) == 0); | |
6a154c88 | 465 | list_delete(&circuit->ipv6_non_link); |
d62a17ae | 466 | } |
467 | ||
468 | circuit->circ_type = CIRCUIT_T_UNKNOWN; | |
eb5d44eb | 469 | } |
470 | ||
d62a17ae | 471 | void isis_circuit_if_bind(struct isis_circuit *circuit, struct interface *ifp) |
3f045a08 | 472 | { |
d62a17ae | 473 | assert(circuit != NULL); |
474 | assert(ifp != NULL); | |
475 | if (circuit->interface) | |
476 | assert(circuit->interface == ifp); | |
477 | else | |
478 | circuit->interface = ifp; | |
479 | if (ifp->info) | |
480 | assert(ifp->info == circuit); | |
481 | else | |
482 | ifp->info = circuit; | |
483 | isis_link_params_update(circuit, ifp); | |
3f045a08 JB |
484 | } |
485 | ||
d62a17ae | 486 | void isis_circuit_if_unbind(struct isis_circuit *circuit, struct interface *ifp) |
eb5d44eb | 487 | { |
d62a17ae | 488 | assert(circuit != NULL); |
489 | assert(ifp != NULL); | |
490 | assert(circuit->interface == ifp); | |
491 | assert(ifp->info == circuit); | |
492 | circuit->interface = NULL; | |
493 | ifp->info = NULL; | |
3f045a08 | 494 | } |
f390d2c7 | 495 | |
d62a17ae | 496 | static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit, |
497 | int is_set) | |
3f045a08 | 498 | { |
d62a17ae | 499 | struct isis_area *area; |
500 | struct isis_lsp *lsp; | |
9b39405f | 501 | dnode_t *dnode; |
d62a17ae | 502 | int level; |
503 | ||
504 | assert(circuit); | |
505 | area = circuit->area; | |
506 | assert(area); | |
507 | for (level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) { | |
9b39405f CF |
508 | if (!(level & circuit->is_type)) |
509 | continue; | |
510 | ||
511 | if (!area->lspdb[level - 1] | |
512 | || !dict_count(area->lspdb[level - 1])) | |
513 | continue; | |
514 | ||
515 | for (dnode = dict_first(area->lspdb[level - 1]); | |
516 | dnode != NULL; | |
517 | dnode = dict_next(area->lspdb[level - 1], dnode)) { | |
518 | lsp = dnode_get(dnode); | |
519 | if (is_set) { | |
520 | isis_tx_queue_add(circuit->tx_queue, lsp, | |
521 | TX_LSP_NORMAL); | |
522 | } else { | |
523 | isis_tx_queue_del(circuit->tx_queue, lsp); | |
d62a17ae | 524 | } |
525 | } | |
526 | } | |
eb5d44eb | 527 | } |
528 | ||
d62a17ae | 529 | size_t isis_circuit_pdu_size(struct isis_circuit *circuit) |
b20ccb3a | 530 | { |
d62a17ae | 531 | return ISO_MTU(circuit); |
b20ccb3a CF |
532 | } |
533 | ||
d62a17ae | 534 | void isis_circuit_stream(struct isis_circuit *circuit, struct stream **stream) |
b20ccb3a | 535 | { |
d62a17ae | 536 | size_t stream_size = isis_circuit_pdu_size(circuit); |
537 | ||
538 | if (!*stream) { | |
539 | *stream = stream_new(stream_size); | |
540 | } else { | |
541 | if (STREAM_SIZE(*stream) != stream_size) | |
db3c830a | 542 | stream_resize_inplace(stream, stream_size); |
d62a17ae | 543 | stream_reset(*stream); |
544 | } | |
b20ccb3a CF |
545 | } |
546 | ||
d62a17ae | 547 | void isis_circuit_prepare(struct isis_circuit *circuit) |
5904f19f | 548 | { |
b0dd98e7 | 549 | #if ISIS_METHOD != ISIS_METHOD_DLPI |
d62a17ae | 550 | thread_add_read(master, isis_receive, circuit, circuit->fd, |
551 | &circuit->t_read); | |
5904f19f | 552 | #else |
d62a17ae | 553 | thread_add_timer_msec(master, isis_receive, circuit, |
554 | listcount(circuit->area->circuit_list) * 100, | |
555 | &circuit->t_read); | |
5904f19f RW |
556 | #endif |
557 | } | |
558 | ||
d62a17ae | 559 | int isis_circuit_up(struct isis_circuit *circuit) |
eb5d44eb | 560 | { |
d62a17ae | 561 | int retv; |
562 | ||
563 | /* Set the flags for all the lsps of the circuit. */ | |
564 | isis_circuit_update_all_srmflags(circuit, 1); | |
565 | ||
566 | if (circuit->state == C_STATE_UP) | |
567 | return ISIS_OK; | |
568 | ||
569 | if (circuit->is_passive) | |
570 | return ISIS_OK; | |
571 | ||
572 | if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) { | |
af4c2728 | 573 | flog_err( |
1a7ecb96 | 574 | EC_ISIS_CONFIG, |
d62a17ae | 575 | "Interface MTU %zu on %s is too low to support area lsp mtu %u!", |
576 | isis_circuit_pdu_size(circuit), | |
577 | circuit->interface->name, circuit->area->lsp_mtu); | |
578 | isis_circuit_update_all_srmflags(circuit, 0); | |
579 | return ISIS_ERROR; | |
580 | } | |
581 | ||
582 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
0849c75e CF |
583 | circuit->circuit_id = isis_circuit_id_gen(isis, circuit->interface); |
584 | if (!circuit->circuit_id) { | |
af4c2728 | 585 | flog_err( |
1a7ecb96 | 586 | EC_ISIS_CONFIG, |
54ece698 | 587 | "There are already 255 broadcast circuits active!"); |
0849c75e CF |
588 | return ISIS_ERROR; |
589 | } | |
590 | ||
d62a17ae | 591 | /* |
592 | * Get the Hardware Address | |
593 | */ | |
594 | if (circuit->interface->hw_addr_len != ETH_ALEN) { | |
595 | zlog_warn("unsupported link layer"); | |
596 | } else { | |
597 | memcpy(circuit->u.bc.snpa, circuit->interface->hw_addr, | |
598 | ETH_ALEN); | |
599 | } | |
3f045a08 | 600 | #ifdef EXTREME_DEGUG |
d62a17ae | 601 | zlog_debug("isis_circuit_if_add: if_id %d, isomtu %d snpa %s", |
602 | circuit->interface->ifindex, ISO_MTU(circuit), | |
603 | snpa_print(circuit->u.bc.snpa)); | |
3f045a08 | 604 | #endif /* EXTREME_DEBUG */ |
3f045a08 | 605 | |
d62a17ae | 606 | circuit->u.bc.adjdb[0] = list_new(); |
607 | circuit->u.bc.adjdb[1] = list_new(); | |
608 | ||
609 | /* | |
610 | * ISO 10589 - 8.4.1 Enabling of broadcast circuits | |
611 | */ | |
612 | ||
613 | /* initilizing the hello sending threads | |
614 | * for a broadcast IF | |
615 | */ | |
616 | ||
617 | /* 8.4.1 a) commence sending of IIH PDUs */ | |
618 | ||
7c4f7aab CF |
619 | for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) { |
620 | if (!(circuit->is_type & level)) | |
621 | continue; | |
622 | ||
a0a707ee | 623 | send_hello_sched(circuit, level, TRIGGERED_IIH_DELAY); |
7c4f7aab CF |
624 | circuit->u.bc.lan_neighs[level - 1] = list_new(); |
625 | ||
626 | thread_add_timer(master, isis_run_dr, | |
627 | &circuit->level_arg[level - 1], | |
628 | 2 * circuit->hello_interval[level - 1], | |
629 | &circuit->u.bc.t_run_dr[level - 1]); | |
d62a17ae | 630 | } |
631 | ||
632 | /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */ | |
633 | /* 8.4.1 c) FIXME: listen for ESH PDUs */ | |
d4670f51 | 634 | } else if (circuit->circ_type == CIRCUIT_T_P2P) { |
d62a17ae | 635 | /* initializing the hello send threads |
636 | * for a ptp IF | |
637 | */ | |
638 | circuit->u.p2p.neighbor = NULL; | |
a0a707ee | 639 | send_hello_sched(circuit, 0, TRIGGERED_IIH_DELAY); |
d62a17ae | 640 | } |
641 | ||
642 | /* initializing PSNP timers */ | |
643 | if (circuit->is_type & IS_LEVEL_1) | |
644 | thread_add_timer( | |
645 | master, send_l1_psnp, circuit, | |
646 | isis_jitter(circuit->psnp_interval[0], PSNP_JITTER), | |
647 | &circuit->t_send_psnp[0]); | |
648 | ||
649 | if (circuit->is_type & IS_LEVEL_2) | |
650 | thread_add_timer( | |
651 | master, send_l2_psnp, circuit, | |
652 | isis_jitter(circuit->psnp_interval[1], PSNP_JITTER), | |
653 | &circuit->t_send_psnp[1]); | |
654 | ||
655 | /* unified init for circuits; ignore warnings below this level */ | |
656 | retv = isis_sock_init(circuit); | |
657 | if (retv != ISIS_OK) { | |
658 | isis_circuit_down(circuit); | |
659 | return retv; | |
660 | } | |
661 | ||
662 | /* initialize the circuit streams after opening connection */ | |
663 | isis_circuit_stream(circuit, &circuit->rcv_stream); | |
664 | isis_circuit_stream(circuit, &circuit->snd_stream); | |
665 | ||
666 | isis_circuit_prepare(circuit); | |
667 | ||
9b39405f | 668 | circuit->tx_queue = isis_tx_queue_new(circuit, send_lsp); |
d62a17ae | 669 | |
670 | return ISIS_OK; | |
eb5d44eb | 671 | } |
672 | ||
d62a17ae | 673 | void isis_circuit_down(struct isis_circuit *circuit) |
eb5d44eb | 674 | { |
d62a17ae | 675 | /* Clear the flags for all the lsps of the circuit. */ |
676 | isis_circuit_update_all_srmflags(circuit, 0); | |
677 | ||
678 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) { | |
679 | /* destroy neighbour lists */ | |
680 | if (circuit->u.bc.lan_neighs[0]) { | |
6a154c88 | 681 | list_delete(&circuit->u.bc.lan_neighs[0]); |
d62a17ae | 682 | circuit->u.bc.lan_neighs[0] = NULL; |
683 | } | |
684 | if (circuit->u.bc.lan_neighs[1]) { | |
6a154c88 | 685 | list_delete(&circuit->u.bc.lan_neighs[1]); |
d62a17ae | 686 | circuit->u.bc.lan_neighs[1] = NULL; |
687 | } | |
688 | /* destroy adjacency databases */ | |
689 | if (circuit->u.bc.adjdb[0]) { | |
690 | circuit->u.bc.adjdb[0]->del = isis_delete_adj; | |
6a154c88 | 691 | list_delete(&circuit->u.bc.adjdb[0]); |
d62a17ae | 692 | circuit->u.bc.adjdb[0] = NULL; |
693 | } | |
694 | if (circuit->u.bc.adjdb[1]) { | |
695 | circuit->u.bc.adjdb[1]->del = isis_delete_adj; | |
6a154c88 | 696 | list_delete(&circuit->u.bc.adjdb[1]); |
d62a17ae | 697 | circuit->u.bc.adjdb[1] = NULL; |
698 | } | |
699 | if (circuit->u.bc.is_dr[0]) { | |
700 | isis_dr_resign(circuit, 1); | |
701 | circuit->u.bc.is_dr[0] = 0; | |
702 | } | |
703 | memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1); | |
704 | if (circuit->u.bc.is_dr[1]) { | |
705 | isis_dr_resign(circuit, 2); | |
706 | circuit->u.bc.is_dr[1] = 0; | |
707 | } | |
708 | memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1); | |
709 | memset(circuit->u.bc.snpa, 0, ETH_ALEN); | |
710 | ||
711 | THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[0]); | |
712 | THREAD_TIMER_OFF(circuit->u.bc.t_send_lan_hello[1]); | |
713 | THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]); | |
714 | THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]); | |
715 | THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[0]); | |
716 | THREAD_TIMER_OFF(circuit->u.bc.t_refresh_pseudo_lsp[1]); | |
717 | circuit->lsp_regenerate_pending[0] = 0; | |
718 | circuit->lsp_regenerate_pending[1] = 0; | |
0849c75e CF |
719 | |
720 | _ISIS_CLEAR_FLAG(isis->circuit_ids_used, circuit->circuit_id); | |
721 | circuit->circuit_id = 0; | |
d62a17ae | 722 | } else if (circuit->circ_type == CIRCUIT_T_P2P) { |
723 | isis_delete_adj(circuit->u.p2p.neighbor); | |
724 | circuit->u.p2p.neighbor = NULL; | |
725 | THREAD_TIMER_OFF(circuit->u.p2p.t_send_p2p_hello); | |
726 | } | |
727 | ||
728 | /* Cancel all active threads */ | |
729 | THREAD_TIMER_OFF(circuit->t_send_csnp[0]); | |
730 | THREAD_TIMER_OFF(circuit->t_send_csnp[1]); | |
731 | THREAD_TIMER_OFF(circuit->t_send_psnp[0]); | |
732 | THREAD_TIMER_OFF(circuit->t_send_psnp[1]); | |
733 | THREAD_OFF(circuit->t_read); | |
734 | ||
9b39405f CF |
735 | if (circuit->tx_queue) { |
736 | isis_tx_queue_free(circuit->tx_queue); | |
737 | circuit->tx_queue = NULL; | |
58e16237 CF |
738 | } |
739 | ||
d62a17ae | 740 | /* send one gratuitous hello to spead up convergence */ |
d4670f51 CF |
741 | if (circuit->state == C_STATE_UP) { |
742 | if (circuit->is_type & IS_LEVEL_1) | |
743 | send_hello(circuit, IS_LEVEL_1); | |
744 | if (circuit->is_type & IS_LEVEL_2) | |
745 | send_hello(circuit, IS_LEVEL_2); | |
746 | } | |
d62a17ae | 747 | |
748 | circuit->upadjcount[0] = 0; | |
749 | circuit->upadjcount[1] = 0; | |
750 | ||
751 | /* close the socket */ | |
752 | if (circuit->fd) { | |
753 | close(circuit->fd); | |
754 | circuit->fd = 0; | |
755 | } | |
756 | ||
757 | if (circuit->rcv_stream != NULL) { | |
758 | stream_free(circuit->rcv_stream); | |
759 | circuit->rcv_stream = NULL; | |
760 | } | |
761 | ||
762 | if (circuit->snd_stream != NULL) { | |
763 | stream_free(circuit->snd_stream); | |
764 | circuit->snd_stream = NULL; | |
765 | } | |
766 | ||
767 | thread_cancel_event(master, circuit); | |
768 | ||
769 | return; | |
eb5d44eb | 770 | } |
771 | ||
d62a17ae | 772 | void circuit_update_nlpids(struct isis_circuit *circuit) |
eb5d44eb | 773 | { |
d62a17ae | 774 | circuit->nlpids.count = 0; |
775 | ||
776 | if (circuit->ip_router) { | |
777 | circuit->nlpids.nlpids[0] = NLPID_IP; | |
778 | circuit->nlpids.count++; | |
779 | } | |
780 | if (circuit->ipv6_router) { | |
781 | circuit->nlpids.nlpids[circuit->nlpids.count] = NLPID_IPV6; | |
782 | circuit->nlpids.count++; | |
783 | } | |
784 | return; | |
eb5d44eb | 785 | } |
786 | ||
d62a17ae | 787 | void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty, |
788 | char detail) | |
3f045a08 | 789 | { |
d62a17ae | 790 | if (detail == ISIS_UI_LEVEL_BRIEF) { |
791 | vty_out(vty, " %-12s", circuit->interface->name); | |
792 | vty_out(vty, "0x%-7x", circuit->circuit_id); | |
793 | vty_out(vty, "%-9s", circuit_state2string(circuit->state)); | |
794 | vty_out(vty, "%-9s", circuit_type2string(circuit->circ_type)); | |
795 | vty_out(vty, "%-9s", circuit_t2string(circuit->is_type)); | |
796 | vty_out(vty, "\n"); | |
797 | } | |
798 | ||
799 | if (detail == ISIS_UI_LEVEL_DETAIL) { | |
800 | struct listnode *node; | |
801 | struct prefix *ip_addr; | |
802 | char buf[BUFSIZ]; | |
803 | ||
804 | vty_out(vty, " Interface: %s", circuit->interface->name); | |
805 | vty_out(vty, ", State: %s", | |
806 | circuit_state2string(circuit->state)); | |
807 | if (circuit->is_passive) | |
808 | vty_out(vty, ", Passive"); | |
809 | else | |
810 | vty_out(vty, ", Active"); | |
811 | vty_out(vty, ", Circuit Id: 0x%x", circuit->circuit_id); | |
812 | vty_out(vty, "\n"); | |
813 | vty_out(vty, " Type: %s", | |
814 | circuit_type2string(circuit->circ_type)); | |
815 | vty_out(vty, ", Level: %s", circuit_t2string(circuit->is_type)); | |
816 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
817 | vty_out(vty, ", SNPA: %-10s", | |
818 | snpa_print(circuit->u.bc.snpa)); | |
819 | vty_out(vty, "\n"); | |
820 | if (circuit->is_type & IS_LEVEL_1) { | |
821 | vty_out(vty, " Level-1 Information:\n"); | |
822 | if (circuit->area->newmetric) | |
823 | vty_out(vty, " Metric: %d", | |
824 | circuit->te_metric[0]); | |
825 | else | |
826 | vty_out(vty, " Metric: %d", | |
827 | circuit->metric[0]); | |
828 | if (!circuit->is_passive) { | |
829 | vty_out(vty, ", Active neighbors: %u\n", | |
830 | circuit->upadjcount[0]); | |
831 | vty_out(vty, | |
832 | " Hello interval: %u, " | |
833 | "Holddown count: %u %s\n", | |
834 | circuit->hello_interval[0], | |
835 | circuit->hello_multiplier[0], | |
836 | (circuit->pad_hellos ? "(pad)" | |
837 | : "(no-pad)")); | |
838 | vty_out(vty, | |
839 | " CNSP interval: %u, " | |
840 | "PSNP interval: %u\n", | |
841 | circuit->csnp_interval[0], | |
842 | circuit->psnp_interval[0]); | |
843 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
844 | vty_out(vty, | |
845 | " LAN Priority: %u, %s\n", | |
846 | circuit->priority[0], | |
847 | (circuit->u.bc.is_dr[0] | |
848 | ? "is DIS" | |
849 | : "is not DIS")); | |
850 | } else { | |
851 | vty_out(vty, "\n"); | |
852 | } | |
853 | } | |
854 | if (circuit->is_type & IS_LEVEL_2) { | |
855 | vty_out(vty, " Level-2 Information:\n"); | |
856 | if (circuit->area->newmetric) | |
857 | vty_out(vty, " Metric: %d", | |
858 | circuit->te_metric[1]); | |
859 | else | |
860 | vty_out(vty, " Metric: %d", | |
861 | circuit->metric[1]); | |
862 | if (!circuit->is_passive) { | |
863 | vty_out(vty, ", Active neighbors: %u\n", | |
864 | circuit->upadjcount[1]); | |
865 | vty_out(vty, | |
866 | " Hello interval: %u, " | |
867 | "Holddown count: %u %s\n", | |
868 | circuit->hello_interval[1], | |
869 | circuit->hello_multiplier[1], | |
870 | (circuit->pad_hellos ? "(pad)" | |
871 | : "(no-pad)")); | |
872 | vty_out(vty, | |
873 | " CNSP interval: %u, " | |
874 | "PSNP interval: %u\n", | |
875 | circuit->csnp_interval[1], | |
876 | circuit->psnp_interval[1]); | |
877 | if (circuit->circ_type == CIRCUIT_T_BROADCAST) | |
878 | vty_out(vty, | |
879 | " LAN Priority: %u, %s\n", | |
880 | circuit->priority[1], | |
881 | (circuit->u.bc.is_dr[1] | |
882 | ? "is DIS" | |
883 | : "is not DIS")); | |
884 | } else { | |
885 | vty_out(vty, "\n"); | |
886 | } | |
887 | } | |
888 | if (circuit->ip_addrs && listcount(circuit->ip_addrs) > 0) { | |
889 | vty_out(vty, " IP Prefix(es):\n"); | |
890 | for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, | |
891 | ip_addr)) { | |
1445b43c A |
892 | prefix2str(ip_addr, buf, sizeof(buf)); |
893 | vty_out(vty, " %s\n", buf); | |
d62a17ae | 894 | } |
895 | } | |
896 | if (circuit->ipv6_link && listcount(circuit->ipv6_link) > 0) { | |
897 | vty_out(vty, " IPv6 Link-Locals:\n"); | |
898 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_link, node, | |
899 | ip_addr)) { | |
1445b43c A |
900 | prefix2str(ip_addr, (char *)buf, BUFSIZ); |
901 | vty_out(vty, " %s\n", buf); | |
d62a17ae | 902 | } |
903 | } | |
904 | if (circuit->ipv6_non_link | |
905 | && listcount(circuit->ipv6_non_link) > 0) { | |
906 | vty_out(vty, " IPv6 Prefixes:\n"); | |
907 | for (ALL_LIST_ELEMENTS_RO(circuit->ipv6_non_link, node, | |
908 | ip_addr)) { | |
1445b43c A |
909 | prefix2str(ip_addr, (char *)buf, BUFSIZ); |
910 | vty_out(vty, " %s\n", buf); | |
d62a17ae | 911 | } |
912 | } | |
913 | ||
914 | vty_out(vty, "\n"); | |
915 | } | |
916 | return; | |
3f045a08 JB |
917 | } |
918 | ||
d56afe53 CF |
919 | DEFINE_HOOK(isis_circuit_config_write, |
920 | (struct isis_circuit *circuit, struct vty *vty), | |
921 | (circuit, vty)) | |
922 | ||
20600086 | 923 | #ifdef FABRICD |
d62a17ae | 924 | int isis_interface_config_write(struct vty *vty) |
eb5d44eb | 925 | { |
f4e14fdb | 926 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 927 | int write = 0; |
f4e14fdb | 928 | struct listnode *node; |
d62a17ae | 929 | struct interface *ifp; |
930 | struct isis_area *area; | |
931 | struct isis_circuit *circuit; | |
932 | int i; | |
933 | ||
451fda4f | 934 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 935 | /* IF name */ |
a8b828f3 | 936 | vty_frame(vty, "interface %s\n", ifp->name); |
d62a17ae | 937 | write++; |
938 | /* IF desc */ | |
939 | if (ifp->desc) { | |
940 | vty_out(vty, " description %s\n", ifp->desc); | |
941 | write++; | |
942 | } | |
943 | /* ISIS Circuit */ | |
f4e14fdb | 944 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { |
d62a17ae | 945 | circuit = |
946 | circuit_lookup_by_ifp(ifp, area->circuit_list); | |
947 | if (circuit == NULL) | |
948 | continue; | |
949 | if (circuit->ip_router) { | |
7c0cbd0e | 950 | vty_out(vty, " ip router " PROTO_NAME " %s\n", |
d62a17ae | 951 | area->area_tag); |
952 | write++; | |
953 | } | |
954 | if (circuit->is_passive) { | |
7c0cbd0e | 955 | vty_out(vty, " " PROTO_NAME " passive\n"); |
d62a17ae | 956 | write++; |
957 | } | |
958 | if (circuit->circ_type_config == CIRCUIT_T_P2P) { | |
7c0cbd0e | 959 | vty_out(vty, " " PROTO_NAME " network point-to-point\n"); |
d62a17ae | 960 | write++; |
961 | } | |
962 | if (circuit->ipv6_router) { | |
7c0cbd0e | 963 | vty_out(vty, " ipv6 router " PROTO_NAME " %s\n", |
d62a17ae | 964 | area->area_tag); |
965 | write++; | |
966 | } | |
967 | ||
968 | /* ISIS - circuit type */ | |
65f18157 CF |
969 | if (!fabricd) { |
970 | if (circuit->is_type == IS_LEVEL_1) { | |
971 | vty_out(vty, " " PROTO_NAME " circuit-type level-1\n"); | |
d62a17ae | 972 | write++; |
65f18157 CF |
973 | } else { |
974 | if (circuit->is_type == IS_LEVEL_2) { | |
975 | vty_out(vty, | |
976 | " " PROTO_NAME " circuit-type level-2-only\n"); | |
977 | write++; | |
978 | } | |
d62a17ae | 979 | } |
980 | } | |
981 | ||
982 | /* ISIS - CSNP interval */ | |
983 | if (circuit->csnp_interval[0] | |
984 | == circuit->csnp_interval[1]) { | |
985 | if (circuit->csnp_interval[0] | |
986 | != DEFAULT_CSNP_INTERVAL) { | |
7c0cbd0e | 987 | vty_out(vty, " " PROTO_NAME " csnp-interval %d\n", |
d62a17ae | 988 | circuit->csnp_interval[0]); |
989 | write++; | |
990 | } | |
991 | } else { | |
992 | for (i = 0; i < 2; i++) { | |
993 | if (circuit->csnp_interval[i] | |
994 | != DEFAULT_CSNP_INTERVAL) { | |
995 | vty_out(vty, | |
7c0cbd0e | 996 | " " PROTO_NAME " csnp-interval %d level-%d\n", |
d62a17ae | 997 | circuit->csnp_interval |
998 | [i], | |
999 | i + 1); | |
1000 | write++; | |
1001 | } | |
1002 | } | |
1003 | } | |
1004 | ||
1005 | /* ISIS - PSNP interval */ | |
1006 | if (circuit->psnp_interval[0] | |
1007 | == circuit->psnp_interval[1]) { | |
1008 | if (circuit->psnp_interval[0] | |
1009 | != DEFAULT_PSNP_INTERVAL) { | |
7c0cbd0e | 1010 | vty_out(vty, " " PROTO_NAME " psnp-interval %d\n", |
d62a17ae | 1011 | circuit->psnp_interval[0]); |
1012 | write++; | |
1013 | } | |
1014 | } else { | |
1015 | for (i = 0; i < 2; i++) { | |
1016 | if (circuit->psnp_interval[i] | |
1017 | != DEFAULT_PSNP_INTERVAL) { | |
1018 | vty_out(vty, | |
7c0cbd0e | 1019 | " " PROTO_NAME " psnp-interval %d level-%d\n", |
d62a17ae | 1020 | circuit->psnp_interval |
1021 | [i], | |
1022 | i + 1); | |
1023 | write++; | |
1024 | } | |
1025 | } | |
1026 | } | |
1027 | ||
1028 | /* ISIS - Hello padding - Defaults to true so only | |
1029 | * display if false */ | |
1030 | if (circuit->pad_hellos == 0) { | |
7c0cbd0e | 1031 | vty_out(vty, " no " PROTO_NAME " hello padding\n"); |
d62a17ae | 1032 | write++; |
1033 | } | |
1034 | ||
58e5d748 CF |
1035 | if (circuit->disable_threeway_adj) { |
1036 | vty_out(vty, " no isis three-way-handshake\n"); | |
1037 | write++; | |
1038 | } | |
1039 | ||
d62a17ae | 1040 | /* ISIS - Hello interval */ |
1041 | if (circuit->hello_interval[0] | |
1042 | == circuit->hello_interval[1]) { | |
1043 | if (circuit->hello_interval[0] | |
1044 | != DEFAULT_HELLO_INTERVAL) { | |
1045 | vty_out(vty, | |
7c0cbd0e | 1046 | " " PROTO_NAME " hello-interval %d\n", |
d62a17ae | 1047 | circuit->hello_interval[0]); |
1048 | write++; | |
1049 | } | |
1050 | } else { | |
1051 | for (i = 0; i < 2; i++) { | |
1052 | if (circuit->hello_interval[i] | |
1053 | != DEFAULT_HELLO_INTERVAL) { | |
1054 | vty_out(vty, | |
7c0cbd0e | 1055 | " " PROTO_NAME " hello-interval %d level-%d\n", |
d62a17ae | 1056 | circuit->hello_interval |
1057 | [i], | |
1058 | i + 1); | |
1059 | write++; | |
1060 | } | |
1061 | } | |
1062 | } | |
1063 | ||
1064 | /* ISIS - Hello Multiplier */ | |
1065 | if (circuit->hello_multiplier[0] | |
1066 | == circuit->hello_multiplier[1]) { | |
1067 | if (circuit->hello_multiplier[0] | |
1068 | != DEFAULT_HELLO_MULTIPLIER) { | |
1069 | vty_out(vty, | |
7c0cbd0e | 1070 | " " PROTO_NAME " hello-multiplier %d\n", |
d62a17ae | 1071 | circuit->hello_multiplier[0]); |
1072 | write++; | |
1073 | } | |
1074 | } else { | |
1075 | for (i = 0; i < 2; i++) { | |
1076 | if (circuit->hello_multiplier[i] | |
1077 | != DEFAULT_HELLO_MULTIPLIER) { | |
1078 | vty_out(vty, | |
7c0cbd0e | 1079 | " " PROTO_NAME " hello-multiplier %d level-%d\n", |
d62a17ae | 1080 | circuit->hello_multiplier |
1081 | [i], | |
1082 | i + 1); | |
1083 | write++; | |
1084 | } | |
1085 | } | |
1086 | } | |
1087 | ||
1088 | /* ISIS - Priority */ | |
1089 | if (circuit->priority[0] == circuit->priority[1]) { | |
1090 | if (circuit->priority[0] != DEFAULT_PRIORITY) { | |
7c0cbd0e | 1091 | vty_out(vty, " " PROTO_NAME " priority %d\n", |
d62a17ae | 1092 | circuit->priority[0]); |
1093 | write++; | |
1094 | } | |
1095 | } else { | |
1096 | for (i = 0; i < 2; i++) { | |
1097 | if (circuit->priority[i] | |
1098 | != DEFAULT_PRIORITY) { | |
1099 | vty_out(vty, | |
7c0cbd0e | 1100 | " " PROTO_NAME " priority %d level-%d\n", |
d62a17ae | 1101 | circuit->priority[i], |
1102 | i + 1); | |
1103 | write++; | |
1104 | } | |
1105 | } | |
1106 | } | |
1107 | ||
1108 | /* ISIS - Metric */ | |
1109 | if (circuit->te_metric[0] == circuit->te_metric[1]) { | |
1110 | if (circuit->te_metric[0] | |
1111 | != DEFAULT_CIRCUIT_METRIC) { | |
7c0cbd0e | 1112 | vty_out(vty, " " PROTO_NAME " metric %d\n", |
d62a17ae | 1113 | circuit->te_metric[0]); |
1114 | write++; | |
1115 | } | |
1116 | } else { | |
1117 | for (i = 0; i < 2; i++) { | |
1118 | if (circuit->te_metric[i] | |
1119 | != DEFAULT_CIRCUIT_METRIC) { | |
1120 | vty_out(vty, | |
7c0cbd0e | 1121 | " " PROTO_NAME " metric %d level-%d\n", |
d62a17ae | 1122 | circuit->te_metric[i], |
1123 | i + 1); | |
1124 | write++; | |
1125 | } | |
1126 | } | |
1127 | } | |
1128 | if (circuit->passwd.type == ISIS_PASSWD_TYPE_HMAC_MD5) { | |
7c0cbd0e | 1129 | vty_out(vty, " " PROTO_NAME " password md5 %s\n", |
d62a17ae | 1130 | circuit->passwd.passwd); |
1131 | write++; | |
1132 | } else if (circuit->passwd.type | |
1133 | == ISIS_PASSWD_TYPE_CLEARTXT) { | |
7c0cbd0e | 1134 | vty_out(vty, " " PROTO_NAME " password clear %s\n", |
d62a17ae | 1135 | circuit->passwd.passwd); |
1136 | write++; | |
1137 | } | |
5489eb45 CF |
1138 | write += hook_call(isis_circuit_config_write, |
1139 | circuit, vty); | |
d62a17ae | 1140 | } |
a8b828f3 | 1141 | vty_endframe(vty, "!\n"); |
d62a17ae | 1142 | } |
1143 | ||
1144 | return write; | |
eb5d44eb | 1145 | } |
20600086 EDP |
1146 | #else |
1147 | int isis_interface_config_write(struct vty *vty) | |
1148 | { | |
1149 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); | |
1150 | int write = 0; | |
1151 | struct interface *ifp; | |
1152 | struct isis_circuit *circuit; | |
1153 | struct lyd_node *dnode; | |
1154 | ||
1155 | FOR_ALL_INTERFACES (vrf, ifp) { | |
1156 | dnode = yang_dnode_get( | |
1157 | running_config->dnode, | |
1158 | "/frr-interface:lib/interface[name='%s'][vrf='%s']", | |
1159 | ifp->name, vrf->name); | |
1160 | if (dnode == NULL) | |
1161 | continue; | |
1162 | ||
1163 | write++; | |
1164 | nb_cli_show_dnode_cmds(vty, dnode, false); | |
1165 | circuit = circuit_scan_by_ifp(ifp); | |
1166 | if (circuit) | |
1167 | write += hook_call(isis_circuit_config_write, circuit, | |
1168 | vty); | |
1169 | } | |
1170 | return write; | |
1171 | } | |
1172 | #endif /* ifdef FABRICD */ | |
eb5d44eb | 1173 | |
d62a17ae | 1174 | struct isis_circuit *isis_circuit_create(struct isis_area *area, |
1175 | struct interface *ifp) | |
eb5d44eb | 1176 | { |
d62a17ae | 1177 | struct isis_circuit *circuit = circuit_scan_by_ifp(ifp); |
1178 | if (circuit && circuit->area) | |
1179 | return NULL; | |
1180 | circuit = isis_csm_state_change(ISIS_ENABLE, circuit, area); | |
1181 | if (circuit->state != C_STATE_CONF && circuit->state != C_STATE_UP) | |
1182 | return circuit; | |
1183 | isis_circuit_if_bind(circuit, ifp); | |
1184 | return circuit; | |
eb5d44eb | 1185 | } |
1186 | ||
d62a17ae | 1187 | void isis_circuit_af_set(struct isis_circuit *circuit, bool ip_router, |
1188 | bool ipv6_router) | |
eb5d44eb | 1189 | { |
d62a17ae | 1190 | struct isis_area *area = circuit->area; |
1191 | bool change = circuit->ip_router != ip_router | |
1192 | || circuit->ipv6_router != ipv6_router; | |
d62a17ae | 1193 | |
1194 | area->ip_circuits += ip_router - circuit->ip_router; | |
1195 | area->ipv6_circuits += ipv6_router - circuit->ipv6_router; | |
1196 | circuit->ip_router = ip_router; | |
1197 | circuit->ipv6_router = ipv6_router; | |
1198 | ||
1199 | if (!change) | |
1200 | return; | |
1201 | ||
1202 | circuit_update_nlpids(circuit); | |
1203 | ||
1204 | if (!ip_router && !ipv6_router) | |
1205 | isis_csm_state_change(ISIS_DISABLE, circuit, area); | |
d62a17ae | 1206 | else |
1207 | lsp_regenerate_schedule(circuit->area, circuit->is_type, 0); | |
3f045a08 | 1208 | } |
eb5d44eb | 1209 | |
64dd3ffe | 1210 | ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive) |
3f045a08 | 1211 | { |
d62a17ae | 1212 | if (circuit->is_passive == passive) |
64dd3ffe | 1213 | return ferr_ok(); |
d62a17ae | 1214 | |
1215 | if (if_is_loopback(circuit->interface) && !passive) | |
64dd3ffe | 1216 | return ferr_cfg_invalid("loopback is always passive"); |
d62a17ae | 1217 | |
1218 | if (circuit->state != C_STATE_UP) { | |
1219 | circuit->is_passive = passive; | |
1220 | } else { | |
1221 | struct isis_area *area = circuit->area; | |
1222 | isis_csm_state_change(ISIS_DISABLE, circuit, area); | |
1223 | circuit->is_passive = passive; | |
1224 | isis_csm_state_change(ISIS_ENABLE, circuit, area); | |
1225 | } | |
1226 | ||
64dd3ffe | 1227 | return ferr_ok(); |
eb5d44eb | 1228 | } |
1229 | ||
64dd3ffe DL |
1230 | ferr_r isis_circuit_metric_set(struct isis_circuit *circuit, int level, |
1231 | int metric) | |
3f045a08 | 1232 | { |
d62a17ae | 1233 | assert(level == IS_LEVEL_1 || level == IS_LEVEL_2); |
1234 | if (metric > MAX_WIDE_LINK_METRIC) | |
64dd3ffe DL |
1235 | return ferr_cfg_invalid("metric %d too large for wide metric", |
1236 | metric); | |
d62a17ae | 1237 | if (circuit->area && circuit->area->oldmetric |
1238 | && metric > MAX_NARROW_LINK_METRIC) | |
64dd3ffe DL |
1239 | return ferr_cfg_invalid("metric %d too large for narrow metric", |
1240 | metric); | |
d62a17ae | 1241 | |
1242 | circuit->te_metric[level - 1] = metric; | |
1243 | circuit->metric[level - 1] = metric; | |
1244 | ||
1245 | if (circuit->area) | |
1246 | lsp_regenerate_schedule(circuit->area, level, 0); | |
64dd3ffe | 1247 | return ferr_ok(); |
eb5d44eb | 1248 | } |
1249 | ||
64dd3ffe | 1250 | ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit) |
eb5d44eb | 1251 | { |
d62a17ae | 1252 | memset(&circuit->passwd, 0, sizeof(circuit->passwd)); |
64dd3ffe | 1253 | return ferr_ok(); |
3f045a08 JB |
1254 | } |
1255 | ||
d62a17ae | 1256 | static int isis_circuit_passwd_set(struct isis_circuit *circuit, |
d7c0a89a | 1257 | uint8_t passwd_type, const char *passwd) |
3f045a08 | 1258 | { |
d62a17ae | 1259 | int len; |
f390d2c7 | 1260 | |
d62a17ae | 1261 | if (!passwd) |
64dd3ffe | 1262 | return ferr_code_bug("no circuit password given"); |
50c7d14a | 1263 | |
d62a17ae | 1264 | len = strlen(passwd); |
1265 | if (len > 254) | |
64dd3ffe DL |
1266 | return ferr_code_bug( |
1267 | "circuit password too long (max 254 chars)"); | |
f390d2c7 | 1268 | |
d62a17ae | 1269 | circuit->passwd.len = len; |
1270 | strncpy((char *)circuit->passwd.passwd, passwd, 255); | |
1271 | circuit->passwd.type = passwd_type; | |
64dd3ffe | 1272 | return ferr_ok(); |
eb5d44eb | 1273 | } |
1274 | ||
64dd3ffe DL |
1275 | ferr_r isis_circuit_passwd_cleartext_set(struct isis_circuit *circuit, |
1276 | const char *passwd) | |
eb5d44eb | 1277 | { |
d62a17ae | 1278 | return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_CLEARTXT, |
1279 | passwd); | |
50c7d14a | 1280 | } |
f390d2c7 | 1281 | |
64dd3ffe DL |
1282 | ferr_r isis_circuit_passwd_hmac_md5_set(struct isis_circuit *circuit, |
1283 | const char *passwd) | |
50c7d14a | 1284 | { |
d62a17ae | 1285 | return isis_circuit_passwd_set(circuit, ISIS_PASSWD_TYPE_HMAC_MD5, |
1286 | passwd); | |
eb5d44eb | 1287 | } |
64dd3ffe | 1288 | |
3f045a08 | 1289 | struct cmd_node interface_node = { |
9d303b37 | 1290 | INTERFACE_NODE, "%s(config-if)# ", 1, |
eb5d44eb | 1291 | }; |
1292 | ||
d0820765 | 1293 | void isis_circuit_circ_type_set(struct isis_circuit *circuit, int circ_type) |
3f045a08 | 1294 | { |
64dd3ffe | 1295 | if (circuit->circ_type == circ_type) |
d0820765 | 1296 | return; |
d62a17ae | 1297 | |
d62a17ae | 1298 | if (circuit->state != C_STATE_UP) { |
1299 | circuit->circ_type = circ_type; | |
1300 | circuit->circ_type_config = circ_type; | |
1301 | } else { | |
1302 | struct isis_area *area = circuit->area; | |
d62a17ae | 1303 | |
1304 | isis_csm_state_change(ISIS_DISABLE, circuit, area); | |
1305 | circuit->circ_type = circ_type; | |
1306 | circuit->circ_type_config = circ_type; | |
1307 | isis_csm_state_change(ISIS_ENABLE, circuit, area); | |
1308 | } | |
3f045a08 JB |
1309 | } |
1310 | ||
d62a17ae | 1311 | int isis_circuit_mt_enabled_set(struct isis_circuit *circuit, uint16_t mtid, |
1312 | bool enabled) | |
064f4896 | 1313 | { |
d62a17ae | 1314 | struct isis_circuit_mt_setting *setting; |
064f4896 | 1315 | |
d62a17ae | 1316 | setting = circuit_get_mt_setting(circuit, mtid); |
1317 | if (setting->enabled != enabled) { | |
1318 | setting->enabled = enabled; | |
1319 | lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2, | |
1320 | 0); | |
1321 | } | |
064f4896 | 1322 | |
d62a17ae | 1323 | return CMD_SUCCESS; |
064f4896 CF |
1324 | } |
1325 | ||
d62a17ae | 1326 | int isis_if_new_hook(struct interface *ifp) |
eb5d44eb | 1327 | { |
d62a17ae | 1328 | return 0; |
eb5d44eb | 1329 | } |
1330 | ||
d62a17ae | 1331 | int isis_if_delete_hook(struct interface *ifp) |
eb5d44eb | 1332 | { |
d62a17ae | 1333 | struct isis_circuit *circuit; |
1334 | /* Clean up the circuit data */ | |
1335 | if (ifp && ifp->info) { | |
1336 | circuit = ifp->info; | |
1337 | isis_csm_state_change(IF_DOWN_FROM_Z, circuit, circuit->area); | |
1338 | isis_csm_state_change(ISIS_DISABLE, circuit, circuit->area); | |
1339 | } | |
1340 | ||
1341 | return 0; | |
eb5d44eb | 1342 | } |
1343 | ||
d62a17ae | 1344 | void isis_circuit_init() |
eb5d44eb | 1345 | { |
d62a17ae | 1346 | /* Initialize Zebra interface data structure */ |
ce19a04a DL |
1347 | hook_register_prio(if_add, 0, isis_if_new_hook); |
1348 | hook_register_prio(if_del, 0, isis_if_delete_hook); | |
eb5d44eb | 1349 | |
d62a17ae | 1350 | /* Install interface node */ |
1351 | install_node(&interface_node, isis_interface_config_write); | |
1352 | if_cmd_init(); | |
eb5d44eb | 1353 | } |