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"
52 extern struct isis
*isis
;
54 static struct isis_adjacency
*adj_alloc(const u_char
*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 u_char
*id
, const u_char
*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 u_char
*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 u_char
*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 void isis_delete_adj(void *arg
)
126 struct isis_adjacency
*adj
= arg
;
131 THREAD_TIMER_OFF(adj
->t_expire
);
133 /* remove from SPF trees */
134 spftree_area_adj_del(adj
->circuit
->area
, adj
);
136 if (adj
->area_addresses
)
137 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->area_addresses
);
138 if (adj
->ipv4_addresses
)
139 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->ipv4_addresses
);
140 if (adj
->ipv6_addresses
)
141 XFREE(MTYPE_ISIS_ADJACENCY_INFO
, adj
->ipv6_addresses
);
145 XFREE(MTYPE_ISIS_ADJACENCY
, adj
);
149 static const char *adj_state2string(int state
)
153 case ISIS_ADJ_INITIALIZING
:
154 return "Initializing";
163 return NULL
; /* not reached */
166 void isis_adj_process_threeway(struct isis_adjacency
*adj
,
167 struct isis_threeway_adj
*tw_adj
,
168 enum isis_adj_usage adj_usage
)
170 enum isis_threeway_state next_tw_state
= ISIS_THREEWAY_DOWN
;
172 if (tw_adj
&& !adj
->circuit
->disable_threeway_adj
) {
173 if (tw_adj
->state
== ISIS_THREEWAY_DOWN
) {
174 next_tw_state
= ISIS_THREEWAY_INITIALIZING
;
175 } else if (tw_adj
->state
== ISIS_THREEWAY_INITIALIZING
) {
176 next_tw_state
= ISIS_THREEWAY_UP
;
177 } else if (tw_adj
->state
== ISIS_THREEWAY_UP
) {
178 if (adj
->threeway_state
== ISIS_THREEWAY_DOWN
)
179 next_tw_state
= ISIS_THREEWAY_DOWN
;
181 next_tw_state
= ISIS_THREEWAY_UP
;
184 next_tw_state
= ISIS_THREEWAY_UP
;
187 if (next_tw_state
!= adj
->threeway_state
) {
188 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
189 zlog_info("ISIS-Adj (%s): Threeway state change %s to %s",
190 adj
->circuit
->area
->area_tag
,
191 isis_threeway_state_name(adj
->threeway_state
),
192 isis_threeway_state_name(next_tw_state
));
196 if (next_tw_state
== ISIS_THREEWAY_DOWN
) {
197 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "Neighbor restarted");
201 if (next_tw_state
== ISIS_THREEWAY_UP
) {
202 if (adj
->adj_state
!= ISIS_ADJ_UP
) {
203 isis_adj_state_change(adj
, ISIS_ADJ_UP
, NULL
);
204 adj
->adj_usage
= adj_usage
;
208 adj
->threeway_state
= next_tw_state
;
211 void isis_adj_state_change(struct isis_adjacency
*adj
,
212 enum isis_adj_state new_state
, const char *reason
)
216 struct isis_circuit
*circuit
;
219 old_state
= adj
->adj_state
;
220 adj
->adj_state
= new_state
;
222 circuit
= adj
->circuit
;
224 if (isis
->debugs
& DEBUG_ADJ_PACKETS
) {
225 zlog_debug("ISIS-Adj (%s): Adjacency state change %d->%d: %s",
226 circuit
->area
->area_tag
, old_state
, new_state
,
227 reason
? reason
: "unspecified");
230 if (circuit
->area
->log_adj_changes
) {
231 const char *adj_name
;
232 struct isis_dynhn
*dyn
;
234 dyn
= dynhn_find_by_id(adj
->sysid
);
236 adj_name
= dyn
->hostname
;
238 adj_name
= sysid_print(adj
->sysid
);
241 "%%ADJCHANGE: Adjacency to %s (%s) changed from %s to %s, %s",
242 adj_name
, adj
->circuit
->interface
->name
,
243 adj_state2string(old_state
),
244 adj_state2string(new_state
),
245 reason
? reason
: "unspecified");
248 if (circuit
->circ_type
== CIRCUIT_T_BROADCAST
) {
250 for (level
= IS_LEVEL_1
; level
<= IS_LEVEL_2
; level
++) {
251 if ((adj
->level
& level
) == 0)
253 if (new_state
== ISIS_ADJ_UP
) {
254 circuit
->upadjcount
[level
- 1]++;
255 isis_event_adjacency_state_change(adj
,
257 /* update counter & timers for debugging
259 adj
->last_flap
= time(NULL
);
261 } else if (new_state
== ISIS_ADJ_DOWN
) {
262 listnode_delete(circuit
->u
.bc
.adjdb
[level
- 1],
265 circuit
->upadjcount
[level
- 1]--;
266 if (circuit
->upadjcount
[level
- 1] == 0)
267 isis_circuit_lsp_queue_clean(circuit
);
269 isis_event_adjacency_state_change(adj
,
274 if (circuit
->u
.bc
.lan_neighs
[level
- 1]) {
275 list_delete_all_node(
276 circuit
->u
.bc
.lan_neighs
[level
- 1]);
277 isis_adj_build_neigh_list(
278 circuit
->u
.bc
.adjdb
[level
- 1],
279 circuit
->u
.bc
.lan_neighs
[level
- 1]);
282 /* On adjacency state change send new pseudo LSP if we
284 if (circuit
->u
.bc
.is_dr
[level
- 1])
285 lsp_regenerate_schedule_pseudo(circuit
, level
);
289 isis_delete_adj(adj
);
292 } else if (circuit
->circ_type
== CIRCUIT_T_P2P
) {
294 for (level
= IS_LEVEL_1
; level
<= IS_LEVEL_2
; level
++) {
295 if ((adj
->level
& level
) == 0)
297 if (new_state
== ISIS_ADJ_UP
) {
298 circuit
->upadjcount
[level
- 1]++;
299 isis_event_adjacency_state_change(adj
,
302 if (adj
->sys_type
== ISIS_SYSTYPE_UNKNOWN
)
303 send_hello(circuit
, level
);
305 /* update counter & timers for debugging
307 adj
->last_flap
= time(NULL
);
310 /* 7.3.17 - going up on P2P -> send CSNP */
311 /* FIXME: yup, I know its wrong... but i will do
313 send_csnp(circuit
, level
);
314 } else if (new_state
== ISIS_ADJ_DOWN
) {
315 if (adj
->circuit
->u
.p2p
.neighbor
== adj
)
316 adj
->circuit
->u
.p2p
.neighbor
= NULL
;
317 circuit
->upadjcount
[level
- 1]--;
318 if (circuit
->upadjcount
[level
- 1] == 0)
319 isis_circuit_lsp_queue_clean(circuit
);
321 isis_event_adjacency_state_change(adj
,
328 isis_delete_adj(adj
);
337 void isis_adj_print(struct isis_adjacency
*adj
)
339 struct isis_dynhn
*dyn
;
343 dyn
= dynhn_find_by_id(adj
->sysid
);
345 zlog_debug("%s", dyn
->hostname
);
347 zlog_debug("SystemId %20s SNPA %s, level %d\nHolding Time %d",
348 sysid_print(adj
->sysid
), snpa_print(adj
->snpa
), adj
->level
,
350 if (adj
->ipv4_address_count
) {
351 zlog_debug("IPv4 Address(es):");
352 for (unsigned int i
= 0; i
< adj
->ipv4_address_count
; i
++)
353 zlog_debug("%s", inet_ntoa(adj
->ipv4_addresses
[i
]));
356 if (adj
->ipv6_address_count
) {
357 zlog_debug("IPv6 Address(es):");
358 for (unsigned int i
= 0; i
< adj
->ipv6_address_count
; i
++) {
359 char buf
[INET6_ADDRSTRLEN
];
360 inet_ntop(AF_INET6
, &adj
->ipv6_addresses
[i
], buf
,
362 zlog_debug("%s", buf
);
365 zlog_debug("Speaks: %s", nlpid2string(&adj
->nlpids
));
370 int isis_adj_expire(struct thread
*thread
)
372 struct isis_adjacency
*adj
;
377 adj
= THREAD_ARG(thread
);
379 adj
->t_expire
= NULL
;
381 /* trigger the adj expire event */
382 isis_adj_state_change(adj
, ISIS_ADJ_DOWN
, "holding time expired");
388 * show isis neighbor [detail]
390 void isis_adj_print_vty(struct isis_adjacency
*adj
, struct vty
*vty
,
394 struct isis_dynhn
*dyn
;
397 dyn
= dynhn_find_by_id(adj
->sysid
);
399 vty_out(vty
, " %-20s", dyn
->hostname
);
401 vty_out(vty
, " %-20s", sysid_print(adj
->sysid
));
403 if (detail
== ISIS_UI_LEVEL_BRIEF
) {
405 vty_out(vty
, "%-12s", adj
->circuit
->interface
->name
);
407 vty_out(vty
, "NULL circuit!");
408 vty_out(vty
, "%-3u", adj
->level
); /* level */
409 vty_out(vty
, "%-13s", adj_state2string(adj
->adj_state
));
412 vty_out(vty
, "%-9llu",
413 (unsigned long long)adj
->last_upd
414 + adj
->hold_time
- now
);
417 vty_out(vty
, "%-10s", snpa_print(adj
->snpa
));
421 if (detail
== ISIS_UI_LEVEL_DETAIL
) {
425 vty_out(vty
, " Interface: %s",
426 adj
->circuit
->interface
->name
);
428 vty_out(vty
, " Interface: NULL circuit");
429 vty_out(vty
, ", Level: %u", adj
->level
); /* level */
430 vty_out(vty
, ", State: %s", adj_state2string(adj
->adj_state
));
433 vty_out(vty
, ", Expires in %s",
434 time2string(adj
->last_upd
+ adj
->hold_time
437 vty_out(vty
, ", Expires in %s",
438 time2string(adj
->hold_time
));
440 vty_out(vty
, " Adjacency flaps: %u", adj
->flaps
);
441 vty_out(vty
, ", Last: %s ago",
442 time2string(now
- adj
->last_flap
));
444 vty_out(vty
, " Circuit type: %s",
445 circuit_t2string(adj
->circuit_t
));
446 vty_out(vty
, ", Speaks: %s", nlpid2string(&adj
->nlpids
));
448 if (adj
->mt_count
!= 1
449 || adj
->mt_set
[0] != ISIS_MT_IPV4_UNICAST
) {
450 vty_out(vty
, " Topologies:\n");
451 for (unsigned int i
= 0; i
< adj
->mt_count
; i
++)
452 vty_out(vty
, " %s\n",
453 isis_mtid2str(adj
->mt_set
[i
]));
455 vty_out(vty
, " SNPA: %s", snpa_print(adj
->snpa
));
457 && (adj
->circuit
->circ_type
== CIRCUIT_T_BROADCAST
)) {
458 dyn
= dynhn_find_by_id(adj
->lanid
);
460 vty_out(vty
, ", LAN id: %s.%02x", dyn
->hostname
,
461 adj
->lanid
[ISIS_SYS_ID_LEN
]);
463 vty_out(vty
, ", LAN id: %s.%02x",
464 sysid_print(adj
->lanid
),
465 adj
->lanid
[ISIS_SYS_ID_LEN
]);
468 vty_out(vty
, " LAN Priority: %u",
469 adj
->prio
[adj
->level
- 1]);
471 vty_out(vty
, ", %s, DIS flaps: %u, Last: %s ago",
473 adj
->dis_record
[ISIS_LEVELS
+ level
- 1]
475 adj
->dischanges
[level
- 1],
476 time2string(now
- (adj
->dis_record
[ISIS_LEVELS
482 if (adj
->area_address_count
) {
483 vty_out(vty
, " Area Address(es):\n");
484 for (unsigned int i
= 0; i
< adj
->area_address_count
;
486 vty_out(vty
, " %s\n",
487 isonet_print(adj
->area_addresses
[i
]
489 adj
->area_addresses
[i
]
493 if (adj
->ipv4_address_count
) {
494 vty_out(vty
, " IPv4 Address(es):\n");
495 for (unsigned int i
= 0; i
< adj
->ipv4_address_count
;
497 vty_out(vty
, " %s\n",
498 inet_ntoa(adj
->ipv4_addresses
[i
]));
500 if (adj
->ipv6_address_count
) {
501 vty_out(vty
, " IPv6 Address(es):\n");
502 for (unsigned int i
= 0; i
< adj
->ipv6_address_count
;
504 char buf
[INET6_ADDRSTRLEN
];
505 inet_ntop(AF_INET6
, &adj
->ipv6_addresses
[i
],
507 vty_out(vty
, " %s\n", buf
);
515 void isis_adj_build_neigh_list(struct list
*adjdb
, struct list
*list
)
517 struct isis_adjacency
*adj
;
518 struct listnode
*node
;
521 zlog_warn("isis_adj_build_neigh_list(): NULL list");
525 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
)) {
527 zlog_warn("isis_adj_build_neigh_list(): NULL adj");
531 if ((adj
->adj_state
== ISIS_ADJ_UP
532 || adj
->adj_state
== ISIS_ADJ_INITIALIZING
))
533 listnode_add(list
, adj
->snpa
);
538 void isis_adj_build_up_list(struct list
*adjdb
, struct list
*list
)
540 struct isis_adjacency
*adj
;
541 struct listnode
*node
;
544 zlog_warn("isis_adj_build_up_list(): adjacency DB is empty");
549 zlog_warn("isis_adj_build_up_list(): NULL list");
553 for (ALL_LIST_ELEMENTS_RO(adjdb
, node
, adj
)) {
555 zlog_warn("isis_adj_build_up_list(): NULL adj");
559 if (adj
->adj_state
== ISIS_ADJ_UP
)
560 listnode_add(list
, adj
);
566 int isis_adj_usage2levels(enum isis_adj_usage usage
)
569 case ISIS_ADJ_LEVEL1
:
571 case ISIS_ADJ_LEVEL2
:
573 case ISIS_ADJ_LEVEL1AND2
:
574 return IS_LEVEL_1
| IS_LEVEL_2
;