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/dict.h"
36 #include "isisd/isis_constants.h"
37 #include "isisd/isis_common.h"
38 #include "isisd/isis_flags.h"
39 #include "isisd/isisd.h"
40 #include "isisd/isis_circuit.h"
41 #include "isisd/isis_adjacency.h"
42 #include "isisd/isis_misc.h"
43 #include "isisd/isis_dr.h"
44 #include "isisd/isis_dynhn.h"
45 #include "isisd/isis_pdu.h"
46 #include "isisd/isis_lsp.h"
47 #include "isisd/isis_spf.h"
48 #include "isisd/isis_events.h"
49 #include "isisd/isis_mt.h"
50 #include "isisd/isis_tlvs.h"
51 #include "isisd/fabricd.h"
53 extern struct isis
*isis
;
55 static struct isis_adjacency
*adj_alloc(const uint8_t *id
)
57 struct isis_adjacency
*adj
;
59 adj
= XCALLOC(MTYPE_ISIS_ADJACENCY
, sizeof(struct isis_adjacency
));
60 memcpy(adj
->sysid
, id
, ISIS_SYS_ID_LEN
);
65 struct isis_adjacency
*isis_new_adj(const uint8_t *id
, const uint8_t *snpa
,
66 int level
, struct isis_circuit
*circuit
)
68 struct isis_adjacency
*adj
;
71 adj
= adj_alloc(id
); /* P2P kludge */
74 memcpy(adj
->snpa
, snpa
, ETH_ALEN
);
76 memset(adj
->snpa
, ' ', ETH_ALEN
);
79 adj
->circuit
= circuit
;
82 adj
->last_flap
= time(NULL
);
83 adj
->threeway_state
= ISIS_THREEWAY_DOWN
;
84 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
85 listnode_add(circuit
->u
.bc
.adjdb
[level
- 1], adj
);
86 adj
->dischanges
[level
- 1] = 0;
87 for (i
= 0; i
< DIS_RECORDS
;
88 i
++) /* clear N DIS state change records */
90 adj
->dis_record
[(i
* ISIS_LEVELS
) + level
- 1].dis
=
92 adj
->dis_record
[(i
* ISIS_LEVELS
) + level
- 1]
93 .last_dis_change
= time(NULL
);
100 struct isis_adjacency
*isis_adj_lookup(const uint8_t *sysid
, struct list
*adjdb
)
102 struct isis_adjacency
*adj
;
103 struct listnode
*node
;
105 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
))
106 if (memcmp(adj
->sysid
, sysid
, ISIS_SYS_ID_LEN
) == 0)
112 struct isis_adjacency
*isis_adj_lookup_snpa(const uint8_t *ssnpa
,
115 struct listnode
*node
;
116 struct isis_adjacency
*adj
;
118 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
))
119 if (memcmp(adj
->snpa
, ssnpa
, ETH_ALEN
) == 0)
125 void isis_delete_adj(void *arg
)
127 struct isis_adjacency
*adj
= arg
;
132 THREAD_TIMER_OFF(adj
->t_expire
);
134 /* remove from SPF trees */
135 spftree_area_adj_del(adj
->circuit
->area
, adj
);
137 if (adj
->area_addresses
)
138 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->area_addresses
);
139 if (adj
->ipv4_addresses
)
140 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->ipv4_addresses
);
141 if (adj
->ipv6_addresses
)
142 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->ipv6_addresses
);
146 XFREE(MTYPE_ISIS_ADJACENCY
, adj
);
150 static const char *adj_state2string(int state
)
154 case ISIS_ADJ_INITIALIZING
:
155 return "Initializing";
164 return NULL
; /* not reached */
167 void isis_adj_process_threeway(struct isis_adjacency
*adj
,
168 struct isis_threeway_adj
*tw_adj
,
169 enum isis_adj_usage adj_usage
)
171 enum isis_threeway_state next_tw_state
= ISIS_THREEWAY_DOWN
;
173 if (tw_adj
&& !adj
->circuit
->disable_threeway_adj
) {
174 if (tw_adj
->state
== ISIS_THREEWAY_DOWN
) {
175 next_tw_state
= ISIS_THREEWAY_INITIALIZING
;
176 } else if (tw_adj
->state
== ISIS_THREEWAY_INITIALIZING
) {
177 next_tw_state
= ISIS_THREEWAY_UP
;
178 } else if (tw_adj
->state
== ISIS_THREEWAY_UP
) {
179 if (adj
->threeway_state
== ISIS_THREEWAY_DOWN
)
180 next_tw_state
= ISIS_THREEWAY_DOWN
;
182 next_tw_state
= ISIS_THREEWAY_UP
;
185 next_tw_state
= ISIS_THREEWAY_UP
;
188 if (next_tw_state
!= adj
->threeway_state
) {
189 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
190 zlog_info("ISIS-Adj (%s): Threeway state change %s to %s",
191 adj
->circuit
->area
->area_tag
,
192 isis_threeway_state_name(adj
->threeway_state
),
193 isis_threeway_state_name(next_tw_state
));
197 if (next_tw_state
!= ISIS_THREEWAY_DOWN
)
198 fabricd_initial_sync_hello(adj
->circuit
);
200 if (next_tw_state
== ISIS_THREEWAY_DOWN
) {
201 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Neighbor restarted");
205 if (next_tw_state
== ISIS_THREEWAY_UP
) {
206 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
207 isis_adj_state_change(adj
, ISIS_ADJ_UP
, NULL
);
208 adj
->adj_usage
= adj_usage
;
212 adj
->threeway_state
= next_tw_state
;
215 void isis_adj_state_change(struct isis_adjacency
*adj
,
216 enum isis_adj_state new_state
, const char *reason
)
220 struct isis_circuit
*circuit
;
223 old_state
= adj
->adj_state
;
224 adj
->adj_state
= new_state
;
226 circuit
= adj
->circuit
;
228 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
229 zlog_debug("ISIS-Adj (%s): Adjacency state change %d->%d: %s",
230 circuit
->area
->area_tag
, old_state
, new_state
,
231 reason
? reason
: "unspecified");
234 if (circuit
->area
->log_adj_changes
) {
235 const char *adj_name
;
236 struct isis_dynhn
*dyn
;
238 dyn
= dynhn_find_by_id(adj
->sysid
);
240 adj_name
= dyn
->hostname
;
242 adj_name
= sysid_print(adj
->sysid
);
245 "%%ADJCHANGE: Adjacency to %s (%s) changed from %s to %s, %s",
246 adj_name
, adj
->circuit
->interface
->name
,
247 adj_state2string(old_state
),
248 adj_state2string(new_state
),
249 reason
? reason
: "unspecified");
252 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
254 for (level
= IS_LEVEL_1
; level
<= IS_LEVEL_2
; level
++) {
255 if ((adj
->level
& level
) == 0)
257 if (new_state
== ISIS_ADJ_UP
) {
258 circuit
->upadjcount
[level
- 1]++;
259 isis_event_adjacency_state_change(adj
,
261 /* update counter & timers for debugging
263 adj
->last_flap
= time(NULL
);
265 } else if (new_state
== ISIS_ADJ_DOWN
) {
266 listnode_delete(circuit
->u
.bc
.adjdb
[level
- 1],
269 circuit
->upadjcount
[level
- 1]--;
270 if (circuit
->upadjcount
[level
- 1] == 0)
271 isis_tx_queue_clean(circuit
->tx_queue
);
273 isis_event_adjacency_state_change(adj
,
278 if (circuit
->u
.bc
.lan_neighs
[level
- 1]) {
279 list_delete_all_node(
280 circuit
->u
.bc
.lan_neighs
[level
- 1]);
281 isis_adj_build_neigh_list(
282 circuit
->u
.bc
.adjdb
[level
- 1],
283 circuit
->u
.bc
.lan_neighs
[level
- 1]);
286 /* On adjacency state change send new pseudo LSP if we
288 if (circuit
->u
.bc
.is_dr
[level
- 1])
289 lsp_regenerate_schedule_pseudo(circuit
, level
);
293 isis_delete_adj(adj
);
295 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
297 for (level
= IS_LEVEL_1
; level
<= IS_LEVEL_2
; level
++) {
298 if ((adj
->level
& level
) == 0)
300 if (new_state
== ISIS_ADJ_UP
) {
301 circuit
->upadjcount
[level
- 1]++;
302 isis_event_adjacency_state_change(adj
,
305 if (adj
->sys_type
== ISIS_SYSTYPE_UNKNOWN
)
306 send_hello(circuit
, level
);
308 /* update counter & timers for debugging
310 adj
->last_flap
= time(NULL
);
313 if (level
== IS_LEVEL_1
) {
314 thread_add_timer(master
, send_l1_csnp
,
316 &circuit
->t_send_csnp
[0]);
318 thread_add_timer(master
, send_l2_csnp
,
320 &circuit
->t_send_csnp
[1]);
322 } else if (new_state
== ISIS_ADJ_DOWN
) {
323 if (adj
->circuit
->u
.p2p
.neighbor
== adj
)
324 adj
->circuit
->u
.p2p
.neighbor
= NULL
;
325 circuit
->upadjcount
[level
- 1]--;
326 if (circuit
->upadjcount
[level
- 1] == 0)
327 isis_tx_queue_clean(circuit
->tx_queue
);
329 isis_event_adjacency_state_change(adj
,
336 isis_delete_adj(adj
);
343 void isis_adj_print(struct isis_adjacency
*adj
)
345 struct isis_dynhn
*dyn
;
349 dyn
= dynhn_find_by_id(adj
->sysid
);
351 zlog_debug("%s", dyn
->hostname
);
353 zlog_debug("SystemId %20s SNPA %s, level %d\nHolding Time %d",
354 sysid_print(adj
->sysid
), snpa_print(adj
->snpa
), adj
->level
,
356 if (adj
->ipv4_address_count
) {
357 zlog_debug("IPv4 Address(es):");
358 for (unsigned int i
= 0; i
< adj
->ipv4_address_count
; i
++)
359 zlog_debug("%s", inet_ntoa(adj
->ipv4_addresses
[i
]));
362 if (adj
->ipv6_address_count
) {
363 zlog_debug("IPv6 Address(es):");
364 for (unsigned int i
= 0; i
< adj
->ipv6_address_count
; i
++) {
365 char buf
[INET6_ADDRSTRLEN
];
366 inet_ntop(AF_INET6
, &adj
->ipv6_addresses
[i
], buf
,
368 zlog_debug("%s", buf
);
371 zlog_debug("Speaks: %s", nlpid2string(&adj
->nlpids
));
376 int isis_adj_expire(struct thread
*thread
)
378 struct isis_adjacency
*adj
;
383 adj
= THREAD_ARG(thread
);
385 adj
->t_expire
= NULL
;
387 /* trigger the adj expire event */
388 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "holding time expired");
394 * show isis neighbor [detail]
396 void isis_adj_print_vty(struct isis_adjacency
*adj
, struct vty
*vty
,
400 struct isis_dynhn
*dyn
;
403 dyn
= dynhn_find_by_id(adj
->sysid
);
405 vty_out(vty
, " %-20s", dyn
->hostname
);
407 vty_out(vty
, " %-20s", sysid_print(adj
->sysid
));
409 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
411 vty_out(vty
, "%-12s", adj
->circuit
->interface
->name
);
413 vty_out(vty
, "NULL circuit!");
414 vty_out(vty
, "%-3u", adj
->level
); /* level */
415 vty_out(vty
, "%-13s", adj_state2string(adj
->adj_state
));
418 vty_out(vty
, "%-9llu",
419 (unsigned long long)adj
->last_upd
420 + adj
->hold_time
- now
);
423 vty_out(vty
, "%-10s", snpa_print(adj
->snpa
));
427 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
431 vty_out(vty
, " Interface: %s",
432 adj
->circuit
->interface
->name
);
434 vty_out(vty
, " Interface: NULL circuit");
435 vty_out(vty
, ", Level: %u", adj
->level
); /* level */
436 vty_out(vty
, ", State: %s", adj_state2string(adj
->adj_state
));
439 vty_out(vty
, ", Expires in %s",
440 time2string(adj
->last_upd
+ adj
->hold_time
443 vty_out(vty
, ", Expires in %s",
444 time2string(adj
->hold_time
));
446 vty_out(vty
, " Adjacency flaps: %u", adj
->flaps
);
447 vty_out(vty
, ", Last: %s ago",
448 time2string(now
- adj
->last_flap
));
450 vty_out(vty
, " Circuit type: %s",
451 circuit_t2string(adj
->circuit_t
));
452 vty_out(vty
, ", Speaks: %s", nlpid2string(&adj
->nlpids
));
454 if (adj
->mt_count
!= 1
455 || adj
->mt_set
[0] != ISIS_MT_IPV4_UNICAST
) {
456 vty_out(vty
, " Topologies:\n");
457 for (unsigned int i
= 0; i
< adj
->mt_count
; i
++)
458 vty_out(vty
, " %s\n",
459 isis_mtid2str(adj
->mt_set
[i
]));
461 vty_out(vty
, " SNPA: %s", snpa_print(adj
->snpa
));
463 && (adj
->circuit
->circ_type
== CIRCUIT_T_BROADCAST
)) {
464 dyn
= dynhn_find_by_id(adj
->lanid
);
466 vty_out(vty
, ", LAN id: %s.%02x", dyn
->hostname
,
467 adj
->lanid
[ISIS_SYS_ID_LEN
]);
469 vty_out(vty
, ", LAN id: %s.%02x",
470 sysid_print(adj
->lanid
),
471 adj
->lanid
[ISIS_SYS_ID_LEN
]);
474 vty_out(vty
, " LAN Priority: %u",
475 adj
->prio
[adj
->level
- 1]);
477 vty_out(vty
, ", %s, DIS flaps: %u, Last: %s ago",
479 adj
->dis_record
[ISIS_LEVELS
+ level
- 1]
481 adj
->dischanges
[level
- 1],
482 time2string(now
- (adj
->dis_record
[ISIS_LEVELS
488 if (adj
->area_address_count
) {
489 vty_out(vty
, " Area Address(es):\n");
490 for (unsigned int i
= 0; i
< adj
->area_address_count
;
492 vty_out(vty
, " %s\n",
493 isonet_print(adj
->area_addresses
[i
]
495 adj
->area_addresses
[i
]
499 if (adj
->ipv4_address_count
) {
500 vty_out(vty
, " IPv4 Address(es):\n");
501 for (unsigned int i
= 0; i
< adj
->ipv4_address_count
;
503 vty_out(vty
, " %s\n",
504 inet_ntoa(adj
->ipv4_addresses
[i
]));
506 if (adj
->ipv6_address_count
) {
507 vty_out(vty
, " IPv6 Address(es):\n");
508 for (unsigned int i
= 0; i
< adj
->ipv6_address_count
;
510 char buf
[INET6_ADDRSTRLEN
];
511 inet_ntop(AF_INET6
, &adj
->ipv6_addresses
[i
],
513 vty_out(vty
, " %s\n", buf
);
521 void isis_adj_build_neigh_list(struct list
*adjdb
, struct list
*list
)
523 struct isis_adjacency
*adj
;
524 struct listnode
*node
;
527 zlog_warn("isis_adj_build_neigh_list(): NULL list");
531 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
)) {
533 zlog_warn("isis_adj_build_neigh_list(): NULL adj");
537 if ((adj
->adj_state
== ISIS_ADJ_UP
538 || adj
->adj_state
== ISIS_ADJ_INITIALIZING
))
539 listnode_add(list
, adj
->snpa
);
544 void isis_adj_build_up_list(struct list
*adjdb
, struct list
*list
)
546 struct isis_adjacency
*adj
;
547 struct listnode
*node
;
550 zlog_warn("isis_adj_build_up_list(): adjacency DB is empty");
555 zlog_warn("isis_adj_build_up_list(): NULL list");
559 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
)) {
561 zlog_warn("isis_adj_build_up_list(): NULL adj");
565 if (adj
->adj_state
== ISIS_ADJ_UP
)
566 listnode_add(list
, adj
);
572 int isis_adj_usage2levels(enum isis_adj_usage usage
)
575 case ISIS_ADJ_LEVEL1
:
577 case ISIS_ADJ_LEVEL2
:
579 case ISIS_ADJ_LEVEL1AND2
:
580 return IS_LEVEL_1
| IS_LEVEL_2
;