2 * IS-IS Rout(e)ing protocol - isis_adjacency.c
3 * handling of IS-IS adjacencies
5 * Copyright (C) 2001,2002 Sampo Saaristo
6 * Tampere University of Technology
7 * Institute of Communications Engineering
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public Licenseas published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #include "isisd/isis_constants.h"
36 #include "isisd/isis_common.h"
37 #include "isisd/isis_flags.h"
38 #include "isisd/isisd.h"
39 #include "isisd/isis_circuit.h"
40 #include "isisd/isis_adjacency.h"
41 #include "isisd/isis_misc.h"
42 #include "isisd/isis_dr.h"
43 #include "isisd/isis_dynhn.h"
44 #include "isisd/isis_pdu.h"
45 #include "isisd/isis_lsp.h"
46 #include "isisd/isis_spf.h"
47 #include "isisd/isis_events.h"
48 #include "isisd/isis_mt.h"
49 #include "isisd/isis_tlvs.h"
50 #include "isisd/fabricd.h"
52 extern struct isis
*isis
;
54 static struct isis_adjacency
*adj_alloc(const uint8_t *id
)
56 struct isis_adjacency
*adj
;
58 adj
= XCALLOC(MTYPE_ISIS_ADJACENCY
, sizeof(struct isis_adjacency
));
59 memcpy(adj
->sysid
, id
, ISIS_SYS_ID_LEN
);
64 struct isis_adjacency
*isis_new_adj(const uint8_t *id
, const uint8_t *snpa
,
65 int level
, struct isis_circuit
*circuit
)
67 struct isis_adjacency
*adj
;
70 adj
= adj_alloc(id
); /* P2P kludge */
73 memcpy(adj
->snpa
, snpa
, ETH_ALEN
);
75 memset(adj
->snpa
, ' ', ETH_ALEN
);
78 adj
->circuit
= circuit
;
81 adj
->last_flap
= time(NULL
);
82 adj
->threeway_state
= ISIS_THREEWAY_DOWN
;
83 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
84 listnode_add(circuit
->u
.bc
.adjdb
[level
- 1], adj
);
85 adj
->dischanges
[level
- 1] = 0;
86 for (i
= 0; i
< DIS_RECORDS
;
87 i
++) /* clear N DIS state change records */
89 adj
->dis_record
[(i
* ISIS_LEVELS
) + level
- 1].dis
=
91 adj
->dis_record
[(i
* ISIS_LEVELS
) + level
- 1]
92 .last_dis_change
= time(NULL
);
99 struct isis_adjacency
*isis_adj_lookup(const uint8_t *sysid
, struct list
*adjdb
)
101 struct isis_adjacency
*adj
;
102 struct listnode
*node
;
104 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
))
105 if (memcmp(adj
->sysid
, sysid
, ISIS_SYS_ID_LEN
) == 0)
111 struct isis_adjacency
*isis_adj_lookup_snpa(const uint8_t *ssnpa
,
114 struct listnode
*node
;
115 struct isis_adjacency
*adj
;
117 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
))
118 if (memcmp(adj
->snpa
, ssnpa
, ETH_ALEN
) == 0)
124 DEFINE_HOOK(isis_adj_state_change_hook
, (struct isis_adjacency
*adj
), (adj
))
126 void isis_delete_adj(void *arg
)
128 struct isis_adjacency
*adj
= arg
;
133 THREAD_TIMER_OFF(adj
->t_expire
);
134 if (adj
->adj_state
!= ISIS_ADJ_DOWN
) {
135 adj
->adj_state
= ISIS_ADJ_DOWN
;
136 hook_call(isis_adj_state_change_hook
, adj
);
139 /* remove from SPF trees */
140 spftree_area_adj_del(adj
->circuit
->area
, adj
);
142 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->area_addresses
);
143 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->ipv4_addresses
);
144 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->ipv6_addresses
);
148 XFREE(MTYPE_ISIS_ADJACENCY
, adj
);
152 static const char *adj_state2string(int state
)
156 case ISIS_ADJ_INITIALIZING
:
157 return "Initializing";
166 return NULL
; /* not reached */
169 void isis_adj_process_threeway(struct isis_adjacency
*adj
,
170 struct isis_threeway_adj
*tw_adj
,
171 enum isis_adj_usage adj_usage
)
173 enum isis_threeway_state next_tw_state
= ISIS_THREEWAY_DOWN
;
175 if (tw_adj
&& !adj
->circuit
->disable_threeway_adj
) {
176 if (tw_adj
->state
== ISIS_THREEWAY_DOWN
) {
177 next_tw_state
= ISIS_THREEWAY_INITIALIZING
;
178 } else if (tw_adj
->state
== ISIS_THREEWAY_INITIALIZING
) {
179 next_tw_state
= ISIS_THREEWAY_UP
;
180 } else if (tw_adj
->state
== ISIS_THREEWAY_UP
) {
181 if (adj
->threeway_state
== ISIS_THREEWAY_DOWN
)
182 next_tw_state
= ISIS_THREEWAY_DOWN
;
184 next_tw_state
= ISIS_THREEWAY_UP
;
187 next_tw_state
= ISIS_THREEWAY_UP
;
190 if (next_tw_state
!= adj
->threeway_state
) {
191 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
192 zlog_info("ISIS-Adj (%s): Threeway state change %s to %s",
193 adj
->circuit
->area
->area_tag
,
194 isis_threeway_state_name(adj
->threeway_state
),
195 isis_threeway_state_name(next_tw_state
));
199 if (next_tw_state
!= ISIS_THREEWAY_DOWN
)
200 fabricd_initial_sync_hello(adj
->circuit
);
202 if (next_tw_state
== ISIS_THREEWAY_DOWN
) {
203 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Neighbor restarted");
207 if (next_tw_state
== ISIS_THREEWAY_UP
) {
208 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
209 isis_adj_state_change(adj
, ISIS_ADJ_UP
, NULL
);
210 adj
->adj_usage
= adj_usage
;
214 if (adj
->threeway_state
!= next_tw_state
) {
215 send_hello_sched(adj
->circuit
, 0, TRIGGERED_IIH_DELAY
);
218 adj
->threeway_state
= next_tw_state
;
221 void isis_adj_state_change(struct isis_adjacency
*adj
,
222 enum isis_adj_state new_state
, const char *reason
)
224 enum isis_adj_state old_state
= adj
->adj_state
;
225 struct isis_circuit
*circuit
= adj
->circuit
;
228 adj
->adj_state
= new_state
;
229 if (new_state
!= old_state
) {
230 send_hello_sched(circuit
, adj
->level
, TRIGGERED_IIH_DELAY
);
233 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
234 zlog_debug("ISIS-Adj (%s): Adjacency state change %d->%d: %s",
235 circuit
->area
->area_tag
, old_state
, new_state
,
236 reason
? reason
: "unspecified");
239 if (circuit
->area
->log_adj_changes
) {
240 const char *adj_name
;
241 struct isis_dynhn
*dyn
;
243 dyn
= dynhn_find_by_id(adj
->sysid
);
245 adj_name
= dyn
->hostname
;
247 adj_name
= sysid_print(adj
->sysid
);
250 "%%ADJCHANGE: Adjacency to %s (%s) changed from %s to %s, %s",
251 adj_name
, adj
->circuit
->interface
->name
,
252 adj_state2string(old_state
),
253 adj_state2string(new_state
),
254 reason
? reason
: "unspecified");
257 circuit
->adj_state_changes
++;
259 /* send northbound notification */
260 isis_notif_adj_state_change(adj
, new_state
, reason
);
261 #endif /* ifndef FABRICD */
263 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
265 for (int level
= IS_LEVEL_1
; level
<= IS_LEVEL_2
; level
++) {
266 if ((adj
->level
& level
) == 0)
268 if (new_state
== ISIS_ADJ_UP
) {
269 circuit
->upadjcount
[level
- 1]++;
270 hook_call(isis_adj_state_change_hook
, adj
);
271 /* update counter & timers for debugging
273 adj
->last_flap
= time(NULL
);
275 } else if (new_state
== ISIS_ADJ_DOWN
) {
276 listnode_delete(circuit
->u
.bc
.adjdb
[level
- 1],
279 circuit
->upadjcount
[level
- 1]--;
280 if (circuit
->upadjcount
[level
- 1] == 0)
281 isis_tx_queue_clean(circuit
->tx_queue
);
283 hook_call(isis_adj_state_change_hook
, adj
);
287 if (circuit
->u
.bc
.lan_neighs
[level
- 1]) {
288 list_delete_all_node(
289 circuit
->u
.bc
.lan_neighs
[level
- 1]);
290 isis_adj_build_neigh_list(
291 circuit
->u
.bc
.adjdb
[level
- 1],
292 circuit
->u
.bc
.lan_neighs
[level
- 1]);
295 /* On adjacency state change send new pseudo LSP if we
297 if (circuit
->u
.bc
.is_dr
[level
- 1])
298 lsp_regenerate_schedule_pseudo(circuit
, level
);
302 isis_delete_adj(adj
);
304 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
306 for (int level
= IS_LEVEL_1
; level
<= IS_LEVEL_2
; level
++) {
307 if ((adj
->level
& level
) == 0)
309 if (new_state
== ISIS_ADJ_UP
) {
310 circuit
->upadjcount
[level
- 1]++;
311 hook_call(isis_adj_state_change_hook
, adj
);
313 /* update counter & timers for debugging
315 adj
->last_flap
= time(NULL
);
318 if (level
== IS_LEVEL_1
) {
319 thread_add_timer(master
, send_l1_csnp
,
321 &circuit
->t_send_csnp
[0]);
323 thread_add_timer(master
, send_l2_csnp
,
325 &circuit
->t_send_csnp
[1]);
327 } else if (new_state
== ISIS_ADJ_DOWN
) {
328 if (adj
->circuit
->u
.p2p
.neighbor
== adj
)
329 adj
->circuit
->u
.p2p
.neighbor
= NULL
;
330 circuit
->upadjcount
[level
- 1]--;
331 if (circuit
->upadjcount
[level
- 1] == 0)
332 isis_tx_queue_clean(circuit
->tx_queue
);
334 hook_call(isis_adj_state_change_hook
, adj
);
340 isis_delete_adj(adj
);
345 void isis_adj_print(struct isis_adjacency
*adj
)
347 struct isis_dynhn
*dyn
;
351 dyn
= dynhn_find_by_id(adj
->sysid
);
353 zlog_debug("%s", dyn
->hostname
);
355 zlog_debug("SystemId %20s SNPA %s, level %d\nHolding Time %d",
356 sysid_print(adj
->sysid
), snpa_print(adj
->snpa
), adj
->level
,
358 if (adj
->ipv4_address_count
) {
359 zlog_debug("IPv4 Address(es):");
360 for (unsigned int i
= 0; i
< adj
->ipv4_address_count
; i
++)
361 zlog_debug("%s", inet_ntoa(adj
->ipv4_addresses
[i
]));
364 if (adj
->ipv6_address_count
) {
365 zlog_debug("IPv6 Address(es):");
366 for (unsigned int i
= 0; i
< adj
->ipv6_address_count
; i
++) {
367 char buf
[INET6_ADDRSTRLEN
];
368 inet_ntop(AF_INET6
, &adj
->ipv6_addresses
[i
], buf
,
370 zlog_debug("%s", buf
);
373 zlog_debug("Speaks: %s", nlpid2string(&adj
->nlpids
));
378 int isis_adj_expire(struct thread
*thread
)
380 struct isis_adjacency
*adj
;
385 adj
= THREAD_ARG(thread
);
387 adj
->t_expire
= NULL
;
389 /* trigger the adj expire event */
390 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "holding time expired");
396 * show isis neighbor [detail]
398 void isis_adj_print_vty(struct isis_adjacency
*adj
, struct vty
*vty
,
402 struct isis_dynhn
*dyn
;
405 dyn
= dynhn_find_by_id(adj
->sysid
);
407 vty_out(vty
, " %-20s", dyn
->hostname
);
409 vty_out(vty
, " %-20s", sysid_print(adj
->sysid
));
411 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
413 vty_out(vty
, "%-12s", adj
->circuit
->interface
->name
);
415 vty_out(vty
, "NULL circuit!");
416 vty_out(vty
, "%-3u", adj
->level
); /* level */
417 vty_out(vty
, "%-13s", adj_state2string(adj
->adj_state
));
420 vty_out(vty
, "%-9llu",
421 (unsigned long long)adj
->last_upd
422 + adj
->hold_time
- now
);
425 vty_out(vty
, "%-10s", snpa_print(adj
->snpa
));
429 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
433 vty_out(vty
, " Interface: %s",
434 adj
->circuit
->interface
->name
);
436 vty_out(vty
, " Interface: NULL circuit");
437 vty_out(vty
, ", Level: %u", adj
->level
); /* level */
438 vty_out(vty
, ", State: %s", adj_state2string(adj
->adj_state
));
441 vty_out(vty
, ", Expires in %s",
442 time2string(adj
->last_upd
+ adj
->hold_time
445 vty_out(vty
, ", Expires in %s",
446 time2string(adj
->hold_time
));
448 vty_out(vty
, " Adjacency flaps: %u", adj
->flaps
);
449 vty_out(vty
, ", Last: %s ago",
450 time2string(now
- adj
->last_flap
));
452 vty_out(vty
, " Circuit type: %s",
453 circuit_t2string(adj
->circuit_t
));
454 vty_out(vty
, ", Speaks: %s", nlpid2string(&adj
->nlpids
));
456 if (adj
->mt_count
!= 1
457 || adj
->mt_set
[0] != ISIS_MT_IPV4_UNICAST
) {
458 vty_out(vty
, " Topologies:\n");
459 for (unsigned int i
= 0; i
< adj
->mt_count
; i
++)
460 vty_out(vty
, " %s\n",
461 isis_mtid2str(adj
->mt_set
[i
]));
463 vty_out(vty
, " SNPA: %s", snpa_print(adj
->snpa
));
465 && (adj
->circuit
->circ_type
== CIRCUIT_T_BROADCAST
)) {
466 dyn
= dynhn_find_by_id(adj
->lanid
);
468 vty_out(vty
, ", LAN id: %s.%02x", dyn
->hostname
,
469 adj
->lanid
[ISIS_SYS_ID_LEN
]);
471 vty_out(vty
, ", LAN id: %s.%02x",
472 sysid_print(adj
->lanid
),
473 adj
->lanid
[ISIS_SYS_ID_LEN
]);
476 vty_out(vty
, " LAN Priority: %u",
477 adj
->prio
[adj
->level
- 1]);
479 vty_out(vty
, ", %s, DIS flaps: %u, Last: %s ago",
481 adj
->dis_record
[ISIS_LEVELS
+ level
- 1]
483 adj
->dischanges
[level
- 1],
484 time2string(now
- (adj
->dis_record
[ISIS_LEVELS
490 if (adj
->area_address_count
) {
491 vty_out(vty
, " Area Address(es):\n");
492 for (unsigned int i
= 0; i
< adj
->area_address_count
;
494 vty_out(vty
, " %s\n",
495 isonet_print(adj
->area_addresses
[i
]
497 adj
->area_addresses
[i
]
501 if (adj
->ipv4_address_count
) {
502 vty_out(vty
, " IPv4 Address(es):\n");
503 for (unsigned int i
= 0; i
< adj
->ipv4_address_count
;
505 vty_out(vty
, " %s\n",
506 inet_ntoa(adj
->ipv4_addresses
[i
]));
508 if (adj
->ipv6_address_count
) {
509 vty_out(vty
, " IPv6 Address(es):\n");
510 for (unsigned int i
= 0; i
< adj
->ipv6_address_count
;
512 char buf
[INET6_ADDRSTRLEN
];
513 inet_ntop(AF_INET6
, &adj
->ipv6_addresses
[i
],
515 vty_out(vty
, " %s\n", buf
);
523 void isis_adj_build_neigh_list(struct list
*adjdb
, struct list
*list
)
525 struct isis_adjacency
*adj
;
526 struct listnode
*node
;
529 zlog_warn("isis_adj_build_neigh_list(): NULL list");
533 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
)) {
535 zlog_warn("isis_adj_build_neigh_list(): NULL adj");
539 if ((adj
->adj_state
== ISIS_ADJ_UP
540 || adj
->adj_state
== ISIS_ADJ_INITIALIZING
))
541 listnode_add(list
, adj
->snpa
);
546 void isis_adj_build_up_list(struct list
*adjdb
, struct list
*list
)
548 struct isis_adjacency
*adj
;
549 struct listnode
*node
;
552 zlog_warn("isis_adj_build_up_list(): adjacency DB is empty");
557 zlog_warn("isis_adj_build_up_list(): NULL list");
561 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
)) {
563 zlog_warn("isis_adj_build_up_list(): NULL adj");
567 if (adj
->adj_state
== ISIS_ADJ_UP
)
568 listnode_add(list
, adj
);
574 int isis_adj_usage2levels(enum isis_adj_usage usage
)
577 case ISIS_ADJ_LEVEL1
:
579 case ISIS_ADJ_LEVEL2
:
581 case ISIS_ADJ_LEVEL1AND2
:
582 return IS_LEVEL_1
| IS_LEVEL_2
;