summaryrefslogtreecommitdiffstats
path: root/isisd/isis_ldp_sync.c
blob: 53676ffe366002b96b26533077fed253291ffbb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
// SPDX-License-Identifier: GPL-2.0-or-later
/**
 * isis_ldp_sync.c: ISIS LDP-IGP Sync  handling routines
 * Copyright (C) 2020 Volta Networks, Inc.
 */

#include <zebra.h>
#include <string.h>

#include "monotime.h"
#include "memory.h"
#include "frrevent.h"
#include "prefix.h"
#include "table.h"
#include "vty.h"
#include "command.h"
#include "plist.h"
#include "log.h"
#include "zclient.h"
#include <lib/json.h>
#include "defaults.h"
#include "ldp_sync.h"

#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_flags.h"
#include "isisd/isis_circuit.h"
#include "isisd/isis_lsp.h"
#include "isisd/isis_pdu.h"
#include "isisd/isis_network.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_dr.h"
#include "isisd/isisd.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
#include "isisd/isis_te.h"
#include "isisd/isis_mt.h"
#include "isisd/isis_errors.h"
#include "isisd/isis_tx_queue.h"
#include "isisd/isis_nb.h"
#include "isisd/isis_ldp_sync.h"

extern struct zclient *zclient;

/*
 * LDP-SYNC msg between IGP and LDP
 */
int isis_ldp_sync_state_update(struct ldp_igp_sync_if_state state)
{
	struct interface *ifp;
	struct isis_circuit *circuit = NULL;
	struct isis_area *area;

	/* lookup circuit */
	ifp = if_lookup_by_index(state.ifindex, VRF_DEFAULT);
	if (ifp == NULL)
		return 0;

	circuit = ifp->info;
	if (circuit == NULL)
		return 0;

	/* if isis is not enabled or LDP-SYNC is not configured ignore */
	area = circuit->area;
	if (area == NULL
	    || !CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE))
		return 0;

	/* received ldp-sync interface state from LDP */
	ils_debug("%s: rcvd %s from LDP if %s", __func__,
		  state.sync_start ? "sync-start" : "sync-complete", ifp->name);
	if (state.sync_start)
		isis_ldp_sync_if_start(circuit, false);
	else
		isis_ldp_sync_if_complete(circuit);

	return 0;
}

int isis_ldp_sync_announce_update(struct ldp_igp_sync_announce announce)
{
	struct isis_area *area;
	struct listnode *anode, *cnode;
	struct isis_circuit *circuit;
	struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);

	/* if isis is not enabled ignore */
	if (!isis)
		return 0;

	if (announce.proto != ZEBRA_ROUTE_LDP)
		return 0;

	ils_debug("%s: rcvd announce from LDP", __func__);

	/* LDP just started up:
	 *  set cost to LSInfinity
	 *  send request to LDP for LDP-SYNC state for each interface
	 */
	for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
		if (!CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE))
			continue;

		for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode, circuit))
			isis_ldp_sync_if_start(circuit, true);
	}

	return 0;
}

void isis_ldp_sync_state_req_msg(struct isis_circuit *circuit)
{
	struct ldp_igp_sync_if_state_req request;
	struct interface *ifp = circuit->interface;

	ils_debug("%s: send state request to LDP for %s", __func__, ifp->name);

	memset(&request, 0, sizeof(request));
	strlcpy(request.name, ifp->name, sizeof(ifp->name));
	request.proto = LDP_IGP_SYNC_IF_STATE_REQUEST;
	request.ifindex = ifp->ifindex;

	zclient_send_opaque(zclient, LDP_IGP_SYNC_IF_STATE_REQUEST,
		(uint8_t *)&request, sizeof(request));
}

/*
 * LDP-SYNC general interface routines
 */
void isis_ldp_sync_if_start(struct isis_circuit *circuit,
	bool send_state_req)
{
	struct ldp_sync_info *ldp_sync_info;

	ldp_sync_info = circuit->ldp_sync_info;

	/* Start LDP-SYNC on this interface:
	 *  set cost of interface to LSInfinity so traffic will use different
	 *  interface until LDP has learned all labels from peer
	 *  start holddown timer if configured
	 *  send msg to LDP to get LDP-SYNC state
	 */
	if (ldp_sync_info &&
	    ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED &&
	    ldp_sync_info->state != LDP_IGP_SYNC_STATE_NOT_REQUIRED) {
		ils_debug("%s: start on if %s state: %s", __func__,
			  circuit->interface->name, "Holding down until Sync");
		ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
		isis_ldp_sync_set_if_metric(circuit, true);
		isis_ldp_sync_holddown_timer_add(circuit);

		if (send_state_req)
			isis_ldp_sync_state_req_msg(circuit);
	}
}

void isis_ldp_sync_if_complete(struct isis_circuit *circuit)
{
	struct ldp_sync_info *ldp_sync_info;

	ldp_sync_info = circuit->ldp_sync_info;

	/* received sync-complete from LDP:
	 *  set state to up
	 *  stop timer
	 *  restore interface cost to original value
	 */
	if (ldp_sync_info && ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED) {
		if (ldp_sync_info->state == LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP)
			ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_UP;

		EVENT_OFF(ldp_sync_info->t_holddown);

		isis_ldp_sync_set_if_metric(circuit, true);
	}
}

void isis_ldp_sync_ldp_fail(struct isis_circuit *circuit)
{
	struct ldp_sync_info *ldp_sync_info;

	ldp_sync_info = circuit->ldp_sync_info;

	/* LDP client close detected:
	 *  stop holddown timer
	 *  set cost of interface to LSInfinity so traffic will use different
	 *  interface until LDP restarts and has learned all labels from peer
	 */
	if (ldp_sync_info &&
	    ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED &&
	    ldp_sync_info->state != LDP_IGP_SYNC_STATE_NOT_REQUIRED) {
		EVENT_OFF(ldp_sync_info->t_holddown);
		ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
		isis_ldp_sync_set_if_metric(circuit, true);
	}
}

static int isis_ldp_sync_adj_state_change(struct isis_adjacency *adj)
{
	struct isis_circuit *circuit = adj->circuit;
	struct ldp_sync_info *ldp_sync_info = circuit->ldp_sync_info;
	struct isis_area *area = circuit->area;

	if (!CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE)
	    || circuit->interface->vrf->vrf_id != VRF_DEFAULT
	    || if_is_loopback(circuit->interface))
		return 0;

	if (ldp_sync_info->enabled != LDP_IGP_SYNC_ENABLED)
		return 0;

	if (adj->adj_state == ISIS_ADJ_UP) {
		if (circuit->circ_type == CIRCUIT_T_P2P ||
		    if_is_pointopoint(circuit->interface)) {
			/* If LDP-SYNC is configure on interface then start */
			ldp_sync_info->state =
				LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
			isis_ldp_sync_if_start(circuit, true);
		} else {
			/* non ptop link so don't run ldp-sync */
			ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;
			isis_ldp_sync_set_if_metric(circuit, true);
		}
	} else {
		/* If LDP-SYNC is configure on this interface then stop it */
		if (circuit->circ_type == CIRCUIT_T_P2P ||
		    if_is_pointopoint(circuit->interface))
			ldp_sync_info->state =
				LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
		else
			ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;

		ils_debug("%s: down on if %s", __func__,
			  circuit->interface->name);
		ldp_sync_if_down(circuit->ldp_sync_info);
	}

	return 0;
}

bool isis_ldp_sync_if_metric_config(struct isis_circuit *circuit, int level,
				    int metric)
{
	struct ldp_sync_info *ldp_sync_info = circuit->ldp_sync_info;
	struct isis_area *area = circuit->area;

	/* configured interface metric has been changed:
	 *   if LDP-IGP Sync is running and metric has been set to LSInfinity
	 *   change saved value so when ldp-sync completes proper metric is
	 *   restored
	 */
	if (area && CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE)
	    && ldp_sync_info != NULL) {

		if (CHECK_FLAG(ldp_sync_info->flags,
			       LDP_SYNC_FLAG_SET_METRIC)) {
			ldp_sync_info->metric[level-1] = metric;
			ldp_sync_info->metric[level-1] = metric;
			return false;
		}
	}
	return true;
}

void isis_ldp_sync_set_if_metric(struct isis_circuit *circuit, bool run_regen)
{
	struct ldp_sync_info *ldp_sync_info;

	/* set interface metric:
	 *   if LDP-IGP Sync is starting set metric so interface
	 *   is used only as last resort
	 *   else restore metric to original value
	 */
	if (circuit->ldp_sync_info == NULL || circuit->area == NULL)
		return;

	ldp_sync_info = circuit->ldp_sync_info;
	if (ldp_sync_if_is_enabled(ldp_sync_info)) {
		/* if metric already set to LSInfinity just return */
		if (CHECK_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_SET_METRIC))
			return;

		SET_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_SET_METRIC);
		if (circuit->is_type & IS_LEVEL_1) {
			if (circuit->area->newmetric) {
				ldp_sync_info->metric[0] =
					circuit->te_metric[0];
				circuit->te_metric[0] =
					ISIS_WIDE_METRIC_INFINITY;
			} else {
				ldp_sync_info->metric[0] = circuit->metric[0];
				circuit->metric[0] =
					ISIS_NARROW_METRIC_INFINITY;
			}
		}
		if (circuit->is_type & IS_LEVEL_2) {
			if (circuit->area->newmetric) {
				ldp_sync_info->metric[1] =
					circuit->te_metric[1];
				circuit->te_metric[1] =
					ISIS_WIDE_METRIC_INFINITY;
			} else {
				ldp_sync_info->metric[1] = circuit->metric[1];
				circuit->metric[1] =
					ISIS_NARROW_METRIC_INFINITY;
			}
		}
	} else {
		/* if metric already restored just return */
		if (!CHECK_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_SET_METRIC))
			return;

		UNSET_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_SET_METRIC);
		if (circuit->is_type & IS_LEVEL_1) {
			circuit->te_metric[0] = ldp_sync_info->metric[0];
			circuit->metric[0] = ldp_sync_info->metric[0];
		}
		if (circuit->is_type & IS_LEVEL_2) {
			circuit->te_metric[1] = ldp_sync_info->metric[1];
			circuit->metric[1] = ldp_sync_info->metric[1];
		}
	}

	if (run_regen)
		lsp_regenerate_schedule(circuit->area, circuit->is_type, 0);
}


/*
 * LDP-SYNC holddown timer routines
 */
static void isis_ldp_sync_holddown_timer(struct event *thread)
{
	struct isis_circuit *circuit;
	struct ldp_sync_info *ldp_sync_info;

	/* holddown timer expired:
	 *  didn't receive msg from LDP indicating sync-complete
	 *  restore interface cost to original value
	 */
	circuit = EVENT_ARG(thread);
	if (circuit->ldp_sync_info == NULL)
		return;

	ldp_sync_info = circuit->ldp_sync_info;

	ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_UP;
	ldp_sync_info->t_holddown = NULL;

	ils_debug("%s: holddown timer expired for %s state:sync achieved",
		  __func__, circuit->interface->name);

	isis_ldp_sync_set_if_metric(circuit, true);
}

void isis_ldp_sync_holddown_timer_add(struct isis_circuit *circuit)
{
	struct ldp_sync_info *ldp_sync_info;

	ldp_sync_info = circuit->ldp_sync_info;

	/* Start holddown timer:
	 *  this timer is used to keep interface cost at LSInfinity
	 *  once expires returns cost to original value
	 *  if timer is already running or holddown time is off just return
	 */
	if (ldp_sync_info->t_holddown ||
	    ldp_sync_info->holddown == LDP_IGP_SYNC_HOLDDOWN_DEFAULT)
		return;

	ils_debug("%s: start holddown timer for %s time %d", __func__,
		  circuit->interface->name, ldp_sync_info->holddown);

	event_add_timer(master, isis_ldp_sync_holddown_timer, circuit,
			ldp_sync_info->holddown, &ldp_sync_info->t_holddown);
}

/*
 * LDP-SYNC handle client close routine
 */
void isis_ldp_sync_handle_client_close(struct zapi_client_close_info *info)
{
	struct isis_area *area;
	struct listnode *anode, *cnode;
	struct isis_circuit *circuit;
	struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);

	/* if isis is not enabled ignore */
	if (!isis)
		return;

	/* Check if the LDP main client session closed */
	if (info->proto != ZEBRA_ROUTE_LDP || info->session_id == 0)
		return;

	/* Handle the zebra notification that the LDP client session closed.
	 *  set cost to LSInfinity
	 *  send request to LDP for LDP-SYNC state for each interface
	 */
	zlog_err("%s: LDP down", __func__);

	for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
		if (!CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE))
			continue;

		for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode, circuit))
			isis_ldp_sync_ldp_fail(circuit);
	}
}

/*
 * LDP-SYNC routes used by set commands.
 */

void isis_area_ldp_sync_enable(struct isis_area *area)
{
	struct isis_circuit *circuit;
	struct listnode *node;

	if (!CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE)) {
		SET_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE);

		for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit))
			isis_if_ldp_sync_enable(circuit);
	}
}

void isis_area_ldp_sync_disable(struct isis_area *area)
{
	struct isis_circuit *circuit;
	struct listnode *node;

	if (CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE)) {
		for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit))
			isis_if_ldp_sync_disable(circuit);

		UNSET_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE);

		UNSET_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_HOLDDOWN);
		area->ldp_sync_cmd.holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT;
	}
}

void isis_area_ldp_sync_set_holddown(struct isis_area *area, uint16_t holddown)
{
	struct isis_circuit *circuit;
	struct listnode *node;

	if (holddown == LDP_IGP_SYNC_HOLDDOWN_DEFAULT)
		UNSET_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_HOLDDOWN);
	else
		SET_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_HOLDDOWN);

	area->ldp_sync_cmd.holddown = holddown;

	for (ALL_LIST_ELEMENTS_RO(area->circuit_list, node, circuit))
		isis_if_set_ldp_sync_holddown(circuit);
}

void isis_if_ldp_sync_enable(struct isis_circuit *circuit)
{
	struct ldp_sync_info *ldp_sync_info = circuit->ldp_sync_info;
	struct isis_area *area = circuit->area;

	/* called when setting LDP-SYNC at the global level:
	 *  specified on interface overrides global config
	 *  if ptop link send msg to LDP indicating ldp-sync enabled
	 */
	if (if_is_loopback(circuit->interface))
		return;

	if (circuit->interface->vrf->vrf_id != VRF_DEFAULT)
		return;

	ils_debug("%s: enable if %s", __func__, circuit->interface->name);

	if (!CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE))
		return;

	/* config on interface, overrides global config. */
	if (CHECK_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_IF_CONFIG))
		if (ldp_sync_info->enabled != LDP_IGP_SYNC_ENABLED)
			return;

	if (!CHECK_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_HOLDDOWN))
		ldp_sync_info->holddown = area->ldp_sync_cmd.holddown;

	if (circuit->circ_type == CIRCUIT_T_P2P
	    || if_is_pointopoint(circuit->interface)) {
		ldp_sync_info->state = LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP;
		isis_ldp_sync_state_req_msg(circuit);
	} else {
		ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;
		ils_debug("%s: Sync only runs on P2P links %s", __func__,
			  circuit->interface->name);
	}
}

void isis_if_ldp_sync_disable(struct isis_circuit *circuit)
{
	struct ldp_sync_info *ldp_sync_info = circuit->ldp_sync_info;
	struct isis_area *area = circuit->area;

	/* Stop LDP-SYNC on this interface:
	 *  if holddown timer is running stop it
	 *  delete ldp instance on interface
	 *  restore metric
	 */
	if (if_is_loopback(circuit->interface))
		return;

	ils_debug("%s: remove if %s", __func__, circuit->interface->name);

	if (!CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE))
		return;

	EVENT_OFF(ldp_sync_info->t_holddown);
	ldp_sync_info->state = LDP_IGP_SYNC_STATE_NOT_REQUIRED;
	isis_ldp_sync_set_if_metric(circuit, true);
}

void isis_if_set_ldp_sync_holddown(struct isis_circuit *circuit)
{
	struct ldp_sync_info *ldp_sync_info = circuit->ldp_sync_info;
	struct isis_area *area = circuit->area;

	/* called when setting LDP-SYNC at the global level:
	 *  specified on interface overrides global config.
	 */
	if (if_is_loopback(circuit->interface))
		return;

	/* config on interface, overrides global config. */
	if (CHECK_FLAG(ldp_sync_info->flags, LDP_SYNC_FLAG_HOLDDOWN))
		return;
	if (CHECK_FLAG(area->ldp_sync_cmd.flags, LDP_SYNC_FLAG_HOLDDOWN))
		ldp_sync_info->holddown = area->ldp_sync_cmd.holddown;
	else
		ldp_sync_info->holddown = LDP_IGP_SYNC_HOLDDOWN_DEFAULT;
}

/*
 * LDP-SYNC routines used by show commands.
 */

static void isis_circuit_ldp_sync_print_vty(struct isis_circuit *circuit,
	struct vty *vty)
{
	struct ldp_sync_info *ldp_sync_info;
	const char *ldp_state;

	if (circuit->ldp_sync_info == NULL ||
	    if_is_loopback(circuit->interface))
		return;

	ldp_sync_info = circuit->ldp_sync_info;
	vty_out(vty, "%-16s\n", circuit->interface->name);
	if (circuit->state == C_STATE_CONF) {
		vty_out(vty, "  Interface down\n");
		return;
	}

	vty_out(vty, "  LDP-IGP Synchronization enabled: %s\n",
		ldp_sync_info->enabled == LDP_IGP_SYNC_ENABLED
		? "yes"
		: "no");
	vty_out(vty, "  holddown timer in seconds: %u\n",
		ldp_sync_info->holddown);

	switch (ldp_sync_info->state) {
	case LDP_IGP_SYNC_STATE_REQUIRED_UP:
		vty_out(vty, "  State: Sync achieved\n");
		break;
	case LDP_IGP_SYNC_STATE_REQUIRED_NOT_UP:
		if (ldp_sync_info->t_holddown != NULL) {
			struct timeval remain =
				event_timer_remain(ldp_sync_info->t_holddown);
			vty_out(vty,
				"  Holddown timer is running %lld.%03lld remaining\n",
				(long long)remain.tv_sec,
				(long long)remain.tv_usec/1000);

			vty_out(vty, "  State: Holding down until Sync\n");
		} else
			vty_out(vty, "  State: Sync not achieved\n");
		break;
	case LDP_IGP_SYNC_STATE_NOT_REQUIRED:
	default:
		if ((circuit->circ_type != CIRCUIT_T_P2P &&
		     !if_is_pointopoint(circuit->interface)) &&
		    circuit->circ_type != CIRCUIT_T_UNKNOWN)
			ldp_state = "Sync not required: non-p2p link";
		else
			ldp_state = "Sync not required";
		vty_out(vty, "  State: %s\n", ldp_state);
		break;
	}
}

DEFUN (show_isis_mpls_ldp_interface,
       show_isis_mpls_ldp_interface_cmd,
       "show " PROTO_NAME " mpls ldp-sync [interface <INTERFACE|all>]",
       SHOW_STR
       PROTO_HELP
       MPLS_STR
       "LDP-IGP Sync information\n"
       "Interface information\n"
       "Interface name\n"
       "All interfaces\n")
{
	char *ifname = NULL;
	int idx_intf = 0;
	struct listnode *anode, *cnode;
	struct isis_area *area;
	struct isis_circuit *circuit;
	struct isis *isis = isis_lookup_by_vrfid(VRF_DEFAULT);
	bool found = false;

	if (!isis) {
		vty_out(vty, "IS-IS Routing Process not enabled\n");
		return CMD_SUCCESS;
	}

	if (argv_find(argv, argc, "INTERFACE", &idx_intf))
		ifname = argv[idx_intf]->arg;

	for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) {
		for (ALL_LIST_ELEMENTS_RO(area->circuit_list, cnode, circuit))
			if (!ifname)
				isis_circuit_ldp_sync_print_vty(circuit, vty);
			else if (strcmp(circuit->interface->name, ifname)
				 == 0) {
				isis_circuit_ldp_sync_print_vty(circuit, vty);
				found = true;
			}
	}

	if (found == false && ifname)
		vty_out(vty, "%-16s\n  ISIS not enabled\n", ifname);

	return CMD_SUCCESS;
}

void isis_ldp_sync_init(void)
{

	/* "show ip isis mpls ldp interface" commands. */
	install_element(VIEW_NODE, &show_isis_mpls_ldp_interface_cmd);

	/* register for adjacency state changes */
	hook_register(isis_adj_state_change_hook,
		      isis_ldp_sync_adj_state_change);
}