summaryrefslogtreecommitdiffstats
path: root/zebra/irdp_interface.c
blob: 28db2ad87d6526619e67d79d4245fe5d8c04f9f4 (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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/*
 *
 * Copyright (C) 1997, 2000
 * Portions:
 *   Swedish University of Agricultural Sciences
 *   Robert Olsson
 *   Kunihiro Ishiguro
 *
 * Thanks to Jens Laas at Swedish University of Agricultural Sciences
 * for reviewing and tests.
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * GNU Zebra is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; see the file COPYING; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <zebra.h>

#include "if.h"
#include "vty.h"
#include "sockunion.h"
#include "prefix.h"
#include "command.h"
#include "memory.h"
#include "stream.h"
#include "ioctl.h"
#include "connected.h"
#include "log.h"
#include "zclient.h"
#include "thread.h"
#include "lib_errors.h"
#include "zebra/interface.h"
#include "zebra/rtadv.h"
#include "zebra/rib.h"
#include "zebra/zebra_router.h"
#include "zebra/redistribute.h"
#include "zebra/irdp.h"
#include "zebra/zebra_errors.h"
#include <netinet/ip_icmp.h>
#include "if.h"
#include "sockunion.h"
#include "log.h"
#include "network.h"

extern int irdp_sock;

DEFINE_MTYPE_STATIC(ZEBRA, IRDP_IF, "IRDP interface data");

#define IRDP_CONFIGED                                                                 \
	do {                                                                          \
		if (!irdp) {                                                          \
			vty_out(vty,                                                  \
				"Please Configure IRDP before using this command\n"); \
			return CMD_WARNING_CONFIG_FAILED;                             \
		}                                                                     \
	} while (0)

static struct irdp_interface *irdp_if_get(struct interface *ifp)
{
	struct zebra_if *zi = ifp->info;

	if (!zi)
		return NULL;

	if (!zi->irdp)
		zi->irdp = XCALLOC(MTYPE_IRDP_IF, sizeof(*zi->irdp));

	if (!zi->irdp->started)
		return NULL;

	return zi->irdp;
}

static int irdp_if_delete(struct interface *ifp)
{
	struct zebra_if *zi = ifp->info;
	if (!zi)
		return 0;
	XFREE(MTYPE_IRDP_IF, zi->irdp);
	return 0;
}

static const char *inet_2a(uint32_t a, char *b, size_t b_len)
{
	snprintf(b, b_len, "%u.%u.%u.%u", (a)&0xFF, (a >> 8) & 0xFF,
		 (a >> 16) & 0xFF, (a >> 24) & 0xFF);
	return b;
}


static struct prefix *irdp_get_prefix(struct interface *ifp)
{
	struct listnode *node;
	struct connected *ifc;

	if (ifp->connected)
		for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc))
			return ifc->address;

	return NULL;
}

/* Join to the add/leave multicast group. */
static int if_group(struct interface *ifp, int sock, uint32_t group,
		    int add_leave)
{
	struct ip_mreq m;
	struct prefix *p;
	int ret;
	char b1[INET_ADDRSTRLEN];

	memset(&m, 0, sizeof(m));
	m.imr_multiaddr.s_addr = htonl(group);
	p = irdp_get_prefix(ifp);

	if (!p) {
		flog_warn(EC_ZEBRA_NO_IFACE_ADDR,
			  "IRDP: can't get address for %s", ifp->name);
		return 1;
	}

	m.imr_interface = p->u.prefix4;

	ret = setsockopt(sock, IPPROTO_IP, add_leave, (char *)&m,
			 sizeof(struct ip_mreq));
	if (ret < 0)
		flog_err_sys(EC_LIB_SOCKET, "IRDP: %s can't setsockopt %s: %s",
			     add_leave == IP_ADD_MEMBERSHIP ? "join group"
							    : "leave group",
			     inet_2a(group, b1, sizeof(b1)),
			     safe_strerror(errno));

	return ret;
}

static int if_add_group(struct interface *ifp)
{
	struct zebra_if *zi = ifp->info;
	struct irdp_interface *irdp = zi->irdp;
	int ret;
	char b1[INET_ADDRSTRLEN];

	if (!irdp)
		return -1;

	ret = if_group(ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP);
	if (ret < 0) {
		return ret;
	}

	if (irdp->flags & IF_DEBUG_MISC)
		zlog_debug("IRDP: Adding group %s for %s",
			   inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1, sizeof(b1)),
			   ifp->name);
	return 0;
}

static int if_drop_group(struct interface *ifp)
{
	struct zebra_if *zi = ifp->info;
	struct irdp_interface *irdp = zi->irdp;
	int ret;
	char b1[INET_ADDRSTRLEN];

	if (!irdp)
		return -1;

	ret = if_group(ifp, irdp_sock, INADDR_ALLRTRS_GROUP,
		       IP_DROP_MEMBERSHIP);
	if (ret < 0)
		return ret;

	if (irdp->flags & IF_DEBUG_MISC)
		zlog_debug("IRDP: Leaving group %s for %s",
			   inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1, sizeof(b1)),
			   ifp->name);
	return 0;
}

static void if_set_defaults(struct irdp_interface *irdp)
{
	irdp->MaxAdvertInterval = IRDP_MAXADVERTINTERVAL;
	irdp->MinAdvertInterval = IRDP_MINADVERTINTERVAL;
	irdp->Preference = IRDP_PREFERENCE;
	irdp->Lifetime = IRDP_LIFETIME;
}


static struct Adv *Adv_new(void)
{
	return XCALLOC(MTYPE_TMP, sizeof(struct Adv));
}

static void Adv_free(struct Adv *adv)
{
	XFREE(MTYPE_TMP, adv);
}

static void irdp_if_start(struct interface *ifp, int multicast,
			  int set_defaults)
{
	struct zebra_if *zi = ifp->info;
	struct irdp_interface *irdp = zi->irdp;
	struct listnode *node;
	struct connected *ifc;
	uint32_t timer, seed;

	assert(irdp);

	irdp->started = true;
	if (irdp->flags & IF_ACTIVE) {
		zlog_debug("IRDP: Interface is already active %s", ifp->name);
		return;
	}
	if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) {
		flog_warn(EC_ZEBRA_IRDP_CANNOT_ACTIVATE_IFACE,
			  "IRDP: Cannot activate interface %s (cannot create IRDP socket)",
			  ifp->name);
		return;
	}
	irdp->flags |= IF_ACTIVE;

	if (!multicast)
		irdp->flags |= IF_BROADCAST;

	if_add_update(ifp);

	if (!(ifp->flags & IFF_UP)) {
		flog_warn(EC_ZEBRA_IRDP_IFACE_DOWN,
			  "IRDP: Interface is down %s", ifp->name);
	}

	/* Shall we cancel if_start if if_add_group fails? */

	if (multicast) {
		if_add_group(ifp);

		if (!(ifp->flags & (IFF_MULTICAST | IFF_ALLMULTI))) {
			flog_warn(EC_ZEBRA_IRDP_IFACE_MCAST_DISABLED,
				  "IRDP: Interface not multicast enabled %s",
				  ifp->name);
		}
	}

	if (set_defaults)
		if_set_defaults(irdp);

	irdp->irdp_sent = 0;

	/* The spec suggests this for randomness */

	seed = 0;
	if (ifp->connected)
		for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
			seed = ifc->address->u.prefix4.s_addr;
			break;
		}

	srandom(seed);
	timer = (frr_weak_random() % IRDP_DEFAULT_INTERVAL) + 1;

	irdp->AdvPrefList = list_new();
	irdp->AdvPrefList->del = (void (*)(void *))Adv_free; /* Destructor */


	/* And this for startup. Speed limit from 1991 :-). But it's OK*/

	if (irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS
	    && timer > MAX_INITIAL_ADVERT_INTERVAL)
		timer = MAX_INITIAL_ADVERT_INTERVAL;


	if (irdp->flags & IF_DEBUG_MISC)
		zlog_debug("IRDP: Init timer for %s set to %u", ifp->name,
			   timer);

	irdp->t_advertise = NULL;
	thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer,
			 &irdp->t_advertise);
}

static void irdp_if_stop(struct interface *ifp)
{
	struct zebra_if *zi = ifp->info;
	struct irdp_interface *irdp = zi->irdp;

	if (irdp == NULL) {
		zlog_debug("Interface %s structure is NULL", ifp->name);
		return;
	}

	if (!(irdp->flags & IF_ACTIVE)) {
		zlog_debug("Interface is not active %s", ifp->name);
		return;
	}

	if (!(irdp->flags & IF_BROADCAST))
		if_drop_group(ifp);

	irdp_advert_off(ifp);

	list_delete(&irdp->AdvPrefList);

	irdp->flags = 0;
}


static void irdp_if_shutdown(struct interface *ifp)
{
	struct zebra_if *zi = ifp->info;
	struct irdp_interface *irdp = zi->irdp;

	if (!irdp)
		return;

	if (irdp->flags & IF_SHUTDOWN) {
		zlog_debug("IRDP: Interface is already shutdown %s", ifp->name);
		return;
	}

	irdp->flags |= IF_SHUTDOWN;
	irdp->flags &= ~IF_ACTIVE;

	if (!(irdp->flags & IF_BROADCAST))
		if_drop_group(ifp);

	/* Tell the hosts we are out of service */
	irdp_advert_off(ifp);
}

static void irdp_if_no_shutdown(struct interface *ifp)
{
	struct irdp_interface *irdp = irdp_if_get(ifp);

	if (!irdp)
		return;

	if (!(irdp->flags & IF_SHUTDOWN)) {
		zlog_debug("IRDP: Interface is not shutdown %s", ifp->name);
		return;
	}

	irdp->flags &= ~IF_SHUTDOWN;

	irdp_if_start(ifp, irdp->flags & IF_BROADCAST ? false : true, false);
}


/* Write configuration to user */

int irdp_config_write(struct vty *vty, struct interface *ifp)
{
	struct zebra_if *zi = ifp->info;
	struct irdp_interface *irdp = zi->irdp;
	struct Adv *adv;
	struct listnode *node;
	char b1[INET_ADDRSTRLEN];

	if (!irdp)
		return 0;

	if (irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) {

		if (irdp->flags & IF_SHUTDOWN)
			vty_out(vty, " ip irdp shutdown \n");

		if (irdp->flags & IF_BROADCAST)
			vty_out(vty, " ip irdp broadcast\n");
		else
			vty_out(vty, " ip irdp multicast\n");

		vty_out(vty, " ip irdp preference %ld\n", irdp->Preference);

		for (ALL_LIST_ELEMENTS_RO(irdp->AdvPrefList, node, adv))
			vty_out(vty, " ip irdp address %s preference %d\n",
				inet_2a(adv->ip.s_addr, b1, sizeof(b1)),
				adv->pref);

		vty_out(vty, " ip irdp holdtime %d\n", irdp->Lifetime);

		vty_out(vty, " ip irdp minadvertinterval %ld\n",
			irdp->MinAdvertInterval);

		vty_out(vty, " ip irdp maxadvertinterval %ld\n",
			irdp->MaxAdvertInterval);
	}
	return 0;
}


DEFUN (ip_irdp_multicast,
       ip_irdp_multicast_cmd,
       "ip irdp multicast",
       IP_STR
       "ICMP Router discovery on this interface\n"
       "Use multicast mode\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	irdp_if_get(ifp);

	irdp_if_start(ifp, true, true);
	return CMD_SUCCESS;
}

DEFUN (ip_irdp_broadcast,
       ip_irdp_broadcast_cmd,
       "ip irdp broadcast",
       IP_STR
       "ICMP Router discovery on this interface\n"
       "Use broadcast mode\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	irdp_if_get(ifp);

	irdp_if_start(ifp, false, true);
	return CMD_SUCCESS;
}

DEFUN (no_ip_irdp,
       no_ip_irdp_cmd,
       "no ip irdp",
       NO_STR
       IP_STR
       "Disable ICMP Router discovery on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	irdp_if_stop(ifp);
	return CMD_SUCCESS;
}

DEFUN (ip_irdp_shutdown,
       ip_irdp_shutdown_cmd,
       "ip irdp shutdown",
       IP_STR
       "ICMP Router discovery on this interface\n"
       "ICMP Router discovery shutdown on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	irdp_if_shutdown(ifp);
	return CMD_SUCCESS;
}

DEFUN (no_ip_irdp_shutdown,
       no_ip_irdp_shutdown_cmd,
       "no ip irdp shutdown",
       NO_STR
       IP_STR
       "ICMP Router discovery on this interface\n"
       "ICMP Router discovery no shutdown on this interface\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);

	irdp_if_no_shutdown(ifp);
	return CMD_SUCCESS;
}

DEFUN (ip_irdp_holdtime,
       ip_irdp_holdtime_cmd,
       "ip irdp holdtime (0-9000)",
       IP_STR
       "ICMP Router discovery on this interface\n"
       "Set holdtime value\n"
       "Holdtime value in seconds. Default is 1800 seconds\n")
{
	int idx_number = 3;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);

	IRDP_CONFIGED;

	irdp->Lifetime = atoi(argv[idx_number]->arg);
	return CMD_SUCCESS;
}

DEFUN (ip_irdp_minadvertinterval,
       ip_irdp_minadvertinterval_cmd,
       "ip irdp minadvertinterval (3-1800)",
       IP_STR
       "ICMP Router discovery on this interface\n"
       "Set minimum time between advertisement\n"
       "Minimum advertisement interval in seconds\n")
{
	int idx_number = 3;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);

	IRDP_CONFIGED;

	if ((unsigned)atoi(argv[idx_number]->arg) <= irdp->MaxAdvertInterval) {
		irdp->MinAdvertInterval = atoi(argv[idx_number]->arg);
		return CMD_SUCCESS;
	} else {
		vty_out(vty,
			"%% MinAdvertInterval must be less than or equal to MaxAdvertInterval\n");
		return CMD_WARNING_CONFIG_FAILED;
	}
}

DEFUN (ip_irdp_maxadvertinterval,
       ip_irdp_maxadvertinterval_cmd,
       "ip irdp maxadvertinterval (4-1800)",
       IP_STR
       "ICMP Router discovery on this interface\n"
       "Set maximum time between advertisement\n"
       "Maximum advertisement interval in seconds\n")
{
	int idx_number = 3;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);

	IRDP_CONFIGED;

	if (irdp->MinAdvertInterval <= (unsigned)atoi(argv[idx_number]->arg)) {
		irdp->MaxAdvertInterval = atoi(argv[idx_number]->arg);
		return CMD_SUCCESS;
	} else {
		vty_out(vty,
			"%% MaxAdvertInterval must be greater than or equal to MinAdvertInterval\n");
		return CMD_WARNING_CONFIG_FAILED;
	}
}

/* DEFUN needs to be fixed for negative ranages...
 * "ip irdp preference <-2147483648-2147483647>",
 * Be positive for now. :-)
 */

DEFUN (ip_irdp_preference,
       ip_irdp_preference_cmd,
       "ip irdp preference (0-2147483647)",
       IP_STR
       "ICMP Router discovery on this interface\n"
       "Set default preference level for this interface\n"
       "Preference level\n")
{
	int idx_number = 3;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);

	IRDP_CONFIGED;

	irdp->Preference = atoi(argv[idx_number]->arg);
	return CMD_SUCCESS;
}

DEFUN (ip_irdp_address_preference,
       ip_irdp_address_preference_cmd,
       "ip irdp address A.B.C.D preference (0-2147483647)",
       IP_STR
       "Alter ICMP Router discovery preference on this interface\n"
       "Set IRDP address for advertise\n"
       "IPv4 address\n"
       "Specify IRDP non-default preference to advertise\n"
       "Preference level\n")
{
	int idx_ipv4 = 3;
	int idx_number = 5;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);
	struct listnode *node;
	struct in_addr ip;
	int pref;
	int ret;
	struct Adv *adv;

	IRDP_CONFIGED;

	ret = inet_aton(argv[idx_ipv4]->arg, &ip);
	if (!ret)
		return CMD_WARNING_CONFIG_FAILED;

	pref = atoi(argv[idx_number]->arg);

	for (ALL_LIST_ELEMENTS_RO(irdp->AdvPrefList, node, adv))
		if (adv->ip.s_addr == ip.s_addr)
			return CMD_SUCCESS;

	adv = Adv_new();
	adv->ip = ip;
	adv->pref = pref;
	listnode_add(irdp->AdvPrefList, adv);

	return CMD_SUCCESS;
}

DEFUN (no_ip_irdp_address_preference,
       no_ip_irdp_address_preference_cmd,
       "no ip irdp address A.B.C.D preference (0-2147483647)",
       NO_STR
       IP_STR
       "Alter ICMP Router discovery preference on this interface\n"
       "Select IRDP address\n"
       "IPv4 address\n"
       "Reset ICMP Router discovery preference on this interface\n"
       "Old preference level\n")
{
	int idx_ipv4 = 4;
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);
	struct listnode *node, *nnode;
	struct in_addr ip;
	int ret;
	struct Adv *adv;

	IRDP_CONFIGED;

	ret = inet_aton(argv[idx_ipv4]->arg, &ip);
	if (!ret)
		return CMD_WARNING_CONFIG_FAILED;

	for (ALL_LIST_ELEMENTS(irdp->AdvPrefList, node, nnode, adv)) {
		if (adv->ip.s_addr == ip.s_addr) {
			listnode_delete(irdp->AdvPrefList, adv);
			break;
		}
	}

	return CMD_SUCCESS;
}

DEFUN (ip_irdp_debug_messages,
       ip_irdp_debug_messages_cmd,
       "ip irdp debug messages",
       IP_STR
       "ICMP Router discovery debug Averts. and Solicits (short)\n"
       "IRDP debugging options\n"
       "Enable debugging for IRDP messages\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);

	IRDP_CONFIGED;

	irdp->flags |= IF_DEBUG_MESSAGES;

	return CMD_SUCCESS;
}

DEFUN (ip_irdp_debug_misc,
       ip_irdp_debug_misc_cmd,
       "ip irdp debug misc",
       IP_STR
       "ICMP Router discovery debug Averts. and Solicits (short)\n"
       "IRDP debugging options\n"
       "Enable debugging for miscellaneous IRDP events\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);

	IRDP_CONFIGED;

	irdp->flags |= IF_DEBUG_MISC;

	return CMD_SUCCESS;
}

DEFUN (ip_irdp_debug_packet,
       ip_irdp_debug_packet_cmd,
       "ip irdp debug packet",
       IP_STR
       "ICMP Router discovery debug Averts. and Solicits (short)\n"
       "IRDP debugging options\n"
       "Enable debugging for IRDP packets\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);

	IRDP_CONFIGED;

	irdp->flags |= IF_DEBUG_PACKET;

	return CMD_SUCCESS;
}


DEFUN (ip_irdp_debug_disable,
       ip_irdp_debug_disable_cmd,
       "ip irdp debug disable",
       IP_STR
       "ICMP Router discovery debug Averts. and Solicits (short)\n"
       "IRDP debugging options\n"
       "Disable debugging for all IRDP events\n")
{
	VTY_DECLVAR_CONTEXT(interface, ifp);
	struct irdp_interface *irdp = irdp_if_get(ifp);

	IRDP_CONFIGED;

	irdp->flags &= ~IF_DEBUG_PACKET;
	irdp->flags &= ~IF_DEBUG_MESSAGES;
	irdp->flags &= ~IF_DEBUG_MISC;

	return CMD_SUCCESS;
}

void irdp_if_init(void)
{
	hook_register(zebra_if_config_wr, irdp_config_write);
	hook_register(if_del, irdp_if_delete);

	install_element(INTERFACE_NODE, &ip_irdp_broadcast_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_multicast_cmd);
	install_element(INTERFACE_NODE, &no_ip_irdp_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_shutdown_cmd);
	install_element(INTERFACE_NODE, &no_ip_irdp_shutdown_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_holdtime_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_maxadvertinterval_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_minadvertinterval_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_preference_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_address_preference_cmd);
	install_element(INTERFACE_NODE, &no_ip_irdp_address_preference_cmd);

	install_element(INTERFACE_NODE, &ip_irdp_debug_messages_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_debug_misc_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_debug_packet_cmd);
	install_element(INTERFACE_NODE, &ip_irdp_debug_disable_cmd);
}