blob: 8742b62b8cc8572a9a1af508ea55037af9636449 [file] [log] [blame]
hassoca776982004-06-12 14:33:05 +00001/*
2 *
3 * Copyright (C) 2000 Robert Olsson.
4 * Swedish University of Agricultural Sciences
5 *
6 * This file is part of GNU Zebra.
7 *
8 * GNU Zebra is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Zebra; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * 02111-1307, USA.
22 */
23
24/*
25 * This work includes work with the following copywrite:
26 *
27 * Copyright (C) 1997, 2000 Kunihiro Ishiguro
28 *
29 */
30
31/*
32 * Thanks to Jens Låås at Swedish University of Agricultural Sciences
33 * for reviewing and tests.
34 */
35
36
37#include <zebra.h>
38
39#ifdef HAVE_IRDP
40
41#include "if.h"
42#include "vty.h"
43#include "sockunion.h"
44#include "prefix.h"
45#include "command.h"
46#include "memory.h"
47#include "stream.h"
48#include "ioctl.h"
49#include "connected.h"
50#include "log.h"
51#include "zclient.h"
52#include "thread.h"
53#include "zebra/interface.h"
54#include "zebra/rtadv.h"
55#include "zebra/rib.h"
56#include "zebra/zserv.h"
57#include "zebra/redistribute.h"
58#include "zebra/irdp.h"
59#include <netinet/ip_icmp.h>
60#include "if.h"
61#include "sockunion.h"
62#include "log.h"
63
64
65/* Master of threads. */
66extern struct zebra_t zebrad;
67
hassoca776982004-06-12 14:33:05 +000068extern int irdp_sock;
hassoca776982004-06-12 14:33:05 +000069
Stephen Hemmingerab0f6152009-12-10 14:22:44 +030070static const char *
71inet_2a(u_int32_t a, char *b)
72{
73 sprintf(b, "%u.%u.%u.%u",
74 (a ) & 0xFF,
75 (a>> 8) & 0xFF,
76 (a>>16) & 0xFF,
77 (a>>24) & 0xFF);
78 return b;
79}
hassoca776982004-06-12 14:33:05 +000080
hassoca776982004-06-12 14:33:05 +000081
ajs2da40f42005-03-30 16:33:13 +000082static struct prefix *
83irdp_get_prefix(struct interface *ifp)
hassoca776982004-06-12 14:33:05 +000084{
paul0c0f9112004-09-24 08:24:42 +000085 struct listnode *node;
hassoca776982004-06-12 14:33:05 +000086 struct connected *ifc;
87
paul0c0f9112004-09-24 08:24:42 +000088 if (ifp->connected)
paul1eb8ef22005-04-07 07:30:20 +000089 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
hassoca776982004-06-12 14:33:05 +000090 return ifc->address;
paul0c0f9112004-09-24 08:24:42 +000091
hassoca776982004-06-12 14:33:05 +000092 return NULL;
93}
94
95/* Join to the add/leave multicast group. */
ajs2da40f42005-03-30 16:33:13 +000096static int
97if_group (struct interface *ifp,
hassoca776982004-06-12 14:33:05 +000098 int sock,
99 u_int32_t group,
100 int add_leave)
101{
102 struct zebra_if *zi;
103 struct ip_mreq m;
104 struct prefix *p;
105 int ret;
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300106 char b1[INET_ADDRSTRLEN];
hassoca776982004-06-12 14:33:05 +0000107
108 zi = ifp->info;
109
Jeremy Jacksonec5e42b2009-01-21 20:51:57 -0500110 memset (&m, 0, sizeof (m));
hassoca776982004-06-12 14:33:05 +0000111 m.imr_multiaddr.s_addr = htonl (group);
112 p = irdp_get_prefix(ifp);
113
114 if(!p) {
115 zlog_warn ("IRDP: can't get address for %s", ifp->name);
116 return 1;
117 }
118
119 m.imr_interface = p->u.prefix4;
120
121 ret = setsockopt (sock, IPPROTO_IP, add_leave,
122 (char *) &m, sizeof (struct ip_mreq));
123 if (ret < 0)
124 zlog_warn ("IRDP: %s can't setsockopt %s: %s",
125 add_leave == IP_ADD_MEMBERSHIP? "join group":"leave group",
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300126 inet_2a(group, b1),
127 safe_strerror (errno));
hassoca776982004-06-12 14:33:05 +0000128
129 return ret;
130}
131
ajs2da40f42005-03-30 16:33:13 +0000132static int
133if_add_group (struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000134{
135 struct zebra_if *zi= ifp->info;
136 struct irdp_interface *irdp = &zi->irdp;
137 int ret;
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300138 char b1[INET_ADDRSTRLEN];
hassoca776982004-06-12 14:33:05 +0000139
140 ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP);
141 if (ret < 0) {
142 return ret;
143 }
144
145 if(irdp->flags & IF_DEBUG_MISC )
ajs2da40f42005-03-30 16:33:13 +0000146 zlog_debug("IRDP: Adding group %s for %s",
ajsb6178002004-12-07 21:12:56 +0000147 inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
148 ifp->name);
hassoca776982004-06-12 14:33:05 +0000149 return 0;
150}
ajs2da40f42005-03-30 16:33:13 +0000151
152static int
153if_drop_group (struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000154{
155 struct zebra_if *zi= ifp->info;
156 struct irdp_interface *irdp = &zi->irdp;
157 int ret;
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300158 char b1[INET_ADDRSTRLEN];
hassoca776982004-06-12 14:33:05 +0000159
160 ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_DROP_MEMBERSHIP);
161 if (ret < 0)
162 return ret;
163
164 if(irdp->flags & IF_DEBUG_MISC)
ajs2da40f42005-03-30 16:33:13 +0000165 zlog_debug("IRDP: Leaving group %s for %s",
ajsb6178002004-12-07 21:12:56 +0000166 inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
167 ifp->name);
hassoca776982004-06-12 14:33:05 +0000168 return 0;
169}
170
ajs2da40f42005-03-30 16:33:13 +0000171static void
hassoca776982004-06-12 14:33:05 +0000172if_set_defaults(struct interface *ifp)
173{
174 struct zebra_if *zi=ifp->info;
175 struct irdp_interface *irdp=&zi->irdp;
176
177 irdp->MaxAdvertInterval = IRDP_MAXADVERTINTERVAL;
178 irdp->MinAdvertInterval = IRDP_MINADVERTINTERVAL;
179 irdp->Preference = IRDP_PREFERENCE;
180 irdp->Lifetime = IRDP_LIFETIME;
181}
182
183
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300184static struct Adv *Adv_new (void)
hassoca776982004-06-12 14:33:05 +0000185{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700186 return XCALLOC (MTYPE_TMP, sizeof (struct Adv));
hassoca776982004-06-12 14:33:05 +0000187}
188
ajs2da40f42005-03-30 16:33:13 +0000189static void
190Adv_free (struct Adv *adv)
hassoca776982004-06-12 14:33:05 +0000191{
192 XFREE (MTYPE_TMP, adv);
193}
194
ajs2da40f42005-03-30 16:33:13 +0000195static void
196irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
hassoca776982004-06-12 14:33:05 +0000197{
198 struct zebra_if *zi= ifp->info;
199 struct irdp_interface *irdp = &zi->irdp;
paul0c0f9112004-09-24 08:24:42 +0000200 struct listnode *node;
201 struct connected *ifc;
hassoca776982004-06-12 14:33:05 +0000202 u_int32_t timer, seed;
203
204 if (irdp->flags & IF_ACTIVE ) {
ajs2da40f42005-03-30 16:33:13 +0000205 zlog_warn("IRDP: Interface is already active %s", ifp->name);
206 return;
207 }
208 if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) {
209 zlog_warn("IRDP: Cannot activate interface %s (cannot create "
210 "IRDP socket)", ifp->name);
hassoca776982004-06-12 14:33:05 +0000211 return;
212 }
213 irdp->flags |= IF_ACTIVE;
214
215 if(!multicast)
216 irdp->flags |= IF_BROADCAST;
217
218 if_add_update(ifp);
219
220 if (! (ifp->flags & IFF_UP)) {
ajs2da40f42005-03-30 16:33:13 +0000221 zlog_warn("IRDP: Interface is down %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000222 }
223
224 /* Shall we cancel if_start if if_add_group fails? */
225
226 if( multicast) {
227 if_add_group(ifp);
228
229 if (! (ifp->flags & (IFF_MULTICAST|IFF_ALLMULTI))) {
ajs2da40f42005-03-30 16:33:13 +0000230 zlog_warn("IRDP: Interface not multicast enabled %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000231 }
232 }
233
234 if(set_defaults)
235 if_set_defaults(ifp);
236
237 irdp->irdp_sent = 0;
238
239 /* The spec suggests this for randomness */
240
241 seed = 0;
paul0c0f9112004-09-24 08:24:42 +0000242 if( ifp->connected)
paul1eb8ef22005-04-07 07:30:20 +0000243 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
paul0c0f9112004-09-24 08:24:42 +0000244 {
245 seed = ifc->address->u.prefix4.s_addr;
246 break;
247 }
hassoca776982004-06-12 14:33:05 +0000248
249 srandom(seed);
250 timer = (random () % IRDP_DEFAULT_INTERVAL) + 1;
251
252 irdp->AdvPrefList = list_new();
hassoc9e52be2004-09-26 16:09:34 +0000253 irdp->AdvPrefList->del = (void (*)(void *)) Adv_free; /* Destructor */
hassoca776982004-06-12 14:33:05 +0000254
255
256 /* And this for startup. Speed limit from 1991 :-). But it's OK*/
257
258 if(irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS &&
259 timer > MAX_INITIAL_ADVERT_INTERVAL )
260 timer= MAX_INITIAL_ADVERT_INTERVAL;
261
262
263 if(irdp->flags & IF_DEBUG_MISC)
ajs2da40f42005-03-30 16:33:13 +0000264 zlog_debug("IRDP: Init timer for %s set to %u",
ajsb6178002004-12-07 21:12:56 +0000265 ifp->name,
266 timer);
hassoca776982004-06-12 14:33:05 +0000267
268 irdp->t_advertise = thread_add_timer(zebrad.master,
269 irdp_send_thread,
270 ifp,
271 timer);
272}
273
ajs2da40f42005-03-30 16:33:13 +0000274static void
275irdp_if_stop(struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000276{
277 struct zebra_if *zi=ifp->info;
278 struct irdp_interface *irdp=&zi->irdp;
279
280 if (irdp == NULL) {
281 zlog_warn ("Interface %s structure is NULL", ifp->name);
282 return;
283 }
284
285 if (! (irdp->flags & IF_ACTIVE )) {
ajs2da40f42005-03-30 16:33:13 +0000286 zlog_warn("Interface is not active %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000287 return;
288 }
289
290 if(! (irdp->flags & IF_BROADCAST))
291 if_drop_group(ifp);
292
293 irdp_advert_off(ifp);
294
295 list_delete(irdp->AdvPrefList);
296 irdp->AdvPrefList=NULL;
297
298 irdp->flags = 0;
299}
300
301
ajs2da40f42005-03-30 16:33:13 +0000302static void
303irdp_if_shutdown(struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000304{
305 struct zebra_if *zi= ifp->info;
306 struct irdp_interface *irdp = &zi->irdp;
307
308 if (irdp->flags & IF_SHUTDOWN ) {
ajs2da40f42005-03-30 16:33:13 +0000309 zlog_warn("IRDP: Interface is already shutdown %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000310 return;
311 }
312
313 irdp->flags |= IF_SHUTDOWN;
314 irdp->flags &= ~IF_ACTIVE;
315
316 if(! (irdp->flags & IF_BROADCAST))
317 if_drop_group(ifp);
318
319 /* Tell the hosts we are out of service */
320 irdp_advert_off(ifp);
321}
322
ajs2da40f42005-03-30 16:33:13 +0000323static void
324irdp_if_no_shutdown(struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000325{
326 struct zebra_if *zi= ifp->info;
327 struct irdp_interface *irdp = &zi->irdp;
328
329 if (! (irdp->flags & IF_SHUTDOWN )) {
ajs2da40f42005-03-30 16:33:13 +0000330 zlog_warn("IRDP: Interface is not shutdown %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000331 return;
332 }
333
334 irdp->flags &= ~IF_SHUTDOWN;
335
336 irdp_if_start(ifp, irdp->flags & IF_BROADCAST? FALSE : TRUE, FALSE);
337
338}
339
340
341/* Write configuration to user */
342
343void irdp_config_write (struct vty *vty, struct interface *ifp)
344{
345 struct zebra_if *zi=ifp->info;
346 struct irdp_interface *irdp=&zi->irdp;
347 struct Adv *adv;
paul0c0f9112004-09-24 08:24:42 +0000348 struct listnode *node;
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300349 char b1[INET_ADDRSTRLEN];
hassoca776982004-06-12 14:33:05 +0000350
351 if(irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) {
352
353 if( irdp->flags & IF_SHUTDOWN)
354 vty_out (vty, " ip irdp shutdown %s", VTY_NEWLINE);
355
356 if( irdp->flags & IF_BROADCAST)
357 vty_out (vty, " ip irdp broadcast%s", VTY_NEWLINE);
358 else
359 vty_out (vty, " ip irdp multicast%s", VTY_NEWLINE);
360
361 vty_out (vty, " ip irdp preference %ld%s",
362 irdp->Preference, VTY_NEWLINE);
363
paul1eb8ef22005-04-07 07:30:20 +0000364 for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
paul0c0f9112004-09-24 08:24:42 +0000365 vty_out (vty, " ip irdp address %s preference %d%s",
366 inet_2a(adv->ip.s_addr, b1),
367 adv->pref,
368 VTY_NEWLINE);
hassoca776982004-06-12 14:33:05 +0000369
370 vty_out (vty, " ip irdp holdtime %d%s",
371 irdp->Lifetime, VTY_NEWLINE);
372
373 vty_out (vty, " ip irdp minadvertinterval %ld%s",
374 irdp->MinAdvertInterval, VTY_NEWLINE);
375
376 vty_out (vty, " ip irdp maxadvertinterval %ld%s",
377 irdp->MaxAdvertInterval, VTY_NEWLINE);
378
379 }
380}
381
382
383DEFUN (ip_irdp_multicast,
384 ip_irdp_multicast_cmd,
385 "ip irdp multicast",
386 IP_STR
387 "ICMP Router discovery on this interface using multicast\n")
388{
389 struct interface *ifp;
390
391 ifp = (struct interface *) vty->index;
392 if(!ifp) {
393 return CMD_WARNING;
394 }
395
396 irdp_if_start(ifp, TRUE, TRUE);
397 return CMD_SUCCESS;
398}
399
400DEFUN (ip_irdp_broadcast,
401 ip_irdp_broadcast_cmd,
402 "ip irdp broadcast",
403 IP_STR
404 "ICMP Router discovery on this interface using broadcast\n")
405{
406 struct interface *ifp;
407
408 ifp = (struct interface *) vty->index;
409 if(!ifp) {
410 return CMD_WARNING;
411 }
412
413 irdp_if_start(ifp, FALSE, TRUE);
414 return CMD_SUCCESS;
415}
416
hasso996933f2004-07-12 16:32:56 +0000417DEFUN (no_ip_irdp,
418 no_ip_irdp_cmd,
hassoca776982004-06-12 14:33:05 +0000419 "no ip irdp",
hasso8d0f15f2004-09-11 16:33:28 +0000420 NO_STR
hassoca776982004-06-12 14:33:05 +0000421 IP_STR
422 "Disable ICMP Router discovery on this interface\n")
423{
424 struct interface *ifp;
425
426 ifp = (struct interface *) vty->index;
427 if(!ifp) {
428 return CMD_WARNING;
429 }
430
431 irdp_if_stop(ifp);
432 return CMD_SUCCESS;
433}
434
435DEFUN (ip_irdp_shutdown,
436 ip_irdp_shutdown_cmd,
437 "ip irdp shutdown",
438 IP_STR
439 "ICMP Router discovery shutdown on this interface\n")
440{
441 struct interface *ifp;
442
443 ifp = (struct interface *) vty->index;
444 if(!ifp) {
445 return CMD_WARNING;
446 }
447
448 irdp_if_shutdown(ifp);
449 return CMD_SUCCESS;
450}
451
hasso996933f2004-07-12 16:32:56 +0000452DEFUN (no_ip_irdp_shutdown,
453 no_ip_irdp_shutdown_cmd,
hassoca776982004-06-12 14:33:05 +0000454 "no ip irdp shutdown",
hasso8d0f15f2004-09-11 16:33:28 +0000455 NO_STR
hassoca776982004-06-12 14:33:05 +0000456 IP_STR
457 "ICMP Router discovery no shutdown on this interface\n")
458{
459 struct interface *ifp;
460
461 ifp = (struct interface *) vty->index;
462 if(!ifp) {
463 return CMD_WARNING;
464 }
465
466 irdp_if_no_shutdown(ifp);
467 return CMD_SUCCESS;
468}
469
470DEFUN (ip_irdp_holdtime,
471 ip_irdp_holdtime_cmd,
472 "ip irdp holdtime <0-9000>",
473 IP_STR
474 "ICMP Router discovery on this interface\n"
475 "Set holdtime value\n"
476 "Holdtime value in seconds. Default is 1800 seconds\n")
477{
478 struct interface *ifp;
479 struct zebra_if *zi;
480 struct irdp_interface *irdp;
481 ifp = (struct interface *) vty->index;
482 if(!ifp) {
483 return CMD_WARNING;
484 }
485
486 zi=ifp->info;
487 irdp=&zi->irdp;
488
489 irdp->Lifetime = atoi(argv[0]);
490 return CMD_SUCCESS;
491}
492
493DEFUN (ip_irdp_minadvertinterval,
494 ip_irdp_minadvertinterval_cmd,
495 "ip irdp minadvertinterval <3-1800>",
496 IP_STR
497 "ICMP Router discovery on this interface\n"
498 "Set minimum time between advertisement\n"
499 "Minimum advertisement interval in seconds\n")
500{
501 struct interface *ifp;
502 struct zebra_if *zi;
503 struct irdp_interface *irdp;
504 ifp = (struct interface *) vty->index;
505 if(!ifp) {
506 return CMD_WARNING;
507 }
508
509 zi=ifp->info;
510 irdp=&zi->irdp;
511
hasso39db97e2004-10-12 20:50:58 +0000512 if( (unsigned) atoi(argv[0]) <= irdp->MaxAdvertInterval) {
hassoca776982004-06-12 14:33:05 +0000513 irdp->MinAdvertInterval = atoi(argv[0]);
514
515 return CMD_SUCCESS;
516 }
517
518 vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s",
519 VTY_NEWLINE);
520
521 vty_out (vty, "Please correct!%s",
522 VTY_NEWLINE);
523 return CMD_WARNING;
524}
525
526DEFUN (ip_irdp_maxadvertinterval,
527 ip_irdp_maxadvertinterval_cmd,
528 "ip irdp maxadvertinterval <4-1800>",
529 IP_STR
530 "ICMP Router discovery on this interface\n"
531 "Set maximum time between advertisement\n"
532 "Maximum advertisement interval in seconds\n")
533{
534 struct interface *ifp;
535 struct zebra_if *zi;
536 struct irdp_interface *irdp;
537 ifp = (struct interface *) vty->index;
538 if(!ifp) {
539 return CMD_WARNING;
540 }
541
542 zi=ifp->info;
543 irdp=&zi->irdp;
544
545
hasso39db97e2004-10-12 20:50:58 +0000546 if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[0]) ) {
hassoca776982004-06-12 14:33:05 +0000547 irdp->MaxAdvertInterval = atoi(argv[0]);
548
549 return CMD_SUCCESS;
550 }
551
552 vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s",
553 VTY_NEWLINE);
554
555 vty_out (vty, "Please correct!%s",
556 VTY_NEWLINE);
557 return CMD_WARNING;
558}
559
hassoaccb1562004-11-25 19:21:07 +0000560/* DEFUN needs to be fixed for negative ranages...
561 * "ip irdp preference <-2147483648-2147483647>",
562 * Be positive for now. :-)
563 */
564
hassoca776982004-06-12 14:33:05 +0000565DEFUN (ip_irdp_preference,
566 ip_irdp_preference_cmd,
hassoca776982004-06-12 14:33:05 +0000567 "ip irdp preference <0-2147483647>",
568 IP_STR
569 "ICMP Router discovery on this interface\n"
570 "Set default preference level for this interface\n"
571 "Preference level\n")
572{
573 struct interface *ifp;
574 struct zebra_if *zi;
575 struct irdp_interface *irdp;
576 ifp = (struct interface *) vty->index;
577 if(!ifp) {
578 return CMD_WARNING;
579 }
580
581 zi=ifp->info;
582 irdp=&zi->irdp;
583
584 irdp->Preference = atoi(argv[0]);
585 return CMD_SUCCESS;
586}
587
588DEFUN (ip_irdp_address_preference,
589 ip_irdp_address_preference_cmd,
590 "ip irdp address A.B.C.D preference <0-2147483647>",
591 IP_STR
592 "Alter ICMP Router discovery preference this interface\n"
593 "Specify IRDP non-default preference to advertise\n"
594 "Set IRDP address for advertise\n"
595 "Preference level\n")
596{
paul0c0f9112004-09-24 08:24:42 +0000597 struct listnode *node;
hassoca776982004-06-12 14:33:05 +0000598 struct in_addr ip;
599 int pref;
600 int ret;
601 struct interface *ifp;
602 struct zebra_if *zi;
603 struct irdp_interface *irdp;
604 struct Adv *adv;
605
606 ifp = (struct interface *) vty->index;
607 if(!ifp) {
608 return CMD_WARNING;
609 }
610
611 zi=ifp->info;
612 irdp=&zi->irdp;
613
614 ret = inet_aton(argv[0], &ip);
615 if(!ret) return CMD_WARNING;
616
617 pref = atoi(argv[1]);
618
paul1eb8ef22005-04-07 07:30:20 +0000619 for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
paul0c0f9112004-09-24 08:24:42 +0000620 if(adv->ip.s_addr == ip.s_addr)
621 return CMD_SUCCESS;
hassoca776982004-06-12 14:33:05 +0000622
623 adv = Adv_new();
624 adv->ip = ip;
625 adv->pref = pref;
626 listnode_add(irdp->AdvPrefList, adv);
627
628 return CMD_SUCCESS;
629
630}
631
hasso996933f2004-07-12 16:32:56 +0000632DEFUN (no_ip_irdp_address_preference,
633 no_ip_irdp_address_preference_cmd,
hassoca776982004-06-12 14:33:05 +0000634 "no ip irdp address A.B.C.D preference <0-2147483647>",
hasso8d0f15f2004-09-11 16:33:28 +0000635 NO_STR
hassoca776982004-06-12 14:33:05 +0000636 IP_STR
637 "Alter ICMP Router discovery preference this interface\n"
638 "Removes IRDP non-default preference\n"
639 "Select IRDP address\n"
640 "Old preference level\n")
641{
paul26f7a242004-09-24 08:45:10 +0000642 struct listnode *node, *nnode;
hassoca776982004-06-12 14:33:05 +0000643 struct in_addr ip;
644 int pref;
645 int ret;
646 struct interface *ifp;
647 struct zebra_if *zi;
648 struct irdp_interface *irdp;
649 struct Adv *adv;
650
651 ifp = (struct interface *) vty->index;
652 if(!ifp) {
653 return CMD_WARNING;
654 }
655
656 zi=ifp->info;
657 irdp=&zi->irdp;
658
659 ret = inet_aton(argv[0], &ip);
paul0c0f9112004-09-24 08:24:42 +0000660 if (!ret)
661 return CMD_WARNING;
hassoca776982004-06-12 14:33:05 +0000662
663 pref = atoi(argv[1]);
664
paul1eb8ef22005-04-07 07:30:20 +0000665 for (ALL_LIST_ELEMENTS (irdp->AdvPrefList, node, nnode, adv))
paul0c0f9112004-09-24 08:24:42 +0000666 {
paul0c0f9112004-09-24 08:24:42 +0000667 if(adv->ip.s_addr == ip.s_addr )
668 {
669 listnode_delete(irdp->AdvPrefList, adv);
670 break;
671 }
672 }
673
hassoca776982004-06-12 14:33:05 +0000674 return CMD_SUCCESS;
hassoca776982004-06-12 14:33:05 +0000675}
676
677DEFUN (ip_irdp_debug_messages,
678 ip_irdp_debug_messages_cmd,
679 "ip irdp debug messages",
680 IP_STR
681 "ICMP Router discovery debug Averts. and Solicits (short)\n")
682{
683 struct interface *ifp;
684 struct zebra_if *zi;
685 struct irdp_interface *irdp;
686 ifp = (struct interface *) vty->index;
687 if(!ifp) {
688 return CMD_WARNING;
689 }
690
691 zi=ifp->info;
692 irdp=&zi->irdp;
693
694 irdp->flags |= IF_DEBUG_MESSAGES;
695
696 return CMD_SUCCESS;
697}
698
699DEFUN (ip_irdp_debug_misc,
700 ip_irdp_debug_misc_cmd,
701 "ip irdp debug misc",
702 IP_STR
703 "ICMP Router discovery debug Averts. and Solicits (short)\n")
704{
705 struct interface *ifp;
706 struct zebra_if *zi;
707 struct irdp_interface *irdp;
708 ifp = (struct interface *) vty->index;
709 if(!ifp) {
710 return CMD_WARNING;
711 }
712
713 zi=ifp->info;
714 irdp=&zi->irdp;
715
716 irdp->flags |= IF_DEBUG_MISC;
717
718 return CMD_SUCCESS;
719}
720
721DEFUN (ip_irdp_debug_packet,
722 ip_irdp_debug_packet_cmd,
723 "ip irdp debug packet",
724 IP_STR
725 "ICMP Router discovery debug Averts. and Solicits (short)\n")
726{
727 struct interface *ifp;
728 struct zebra_if *zi;
729 struct irdp_interface *irdp;
730 ifp = (struct interface *) vty->index;
731 if(!ifp) {
732 return CMD_WARNING;
733 }
734
735 zi=ifp->info;
736 irdp=&zi->irdp;
737
738 irdp->flags |= IF_DEBUG_PACKET;
739
740 return CMD_SUCCESS;
741}
742
743
744DEFUN (ip_irdp_debug_disable,
745 ip_irdp_debug_disable_cmd,
746 "ip irdp debug disable",
747 IP_STR
748 "ICMP Router discovery debug Averts. and Solicits (short)\n")
749{
750 struct interface *ifp;
751 struct zebra_if *zi;
752 struct irdp_interface *irdp;
753 ifp = (struct interface *) vty->index;
754 if(!ifp) {
755 return CMD_WARNING;
756 }
757
758 zi=ifp->info;
759 irdp=&zi->irdp;
760
761 irdp->flags &= ~IF_DEBUG_PACKET;
762 irdp->flags &= ~IF_DEBUG_MESSAGES;
763 irdp->flags &= ~IF_DEBUG_MISC;
764
765 return CMD_SUCCESS;
766}
767
768void
ajs2da40f42005-03-30 16:33:13 +0000769irdp_init ()
hassoca776982004-06-12 14:33:05 +0000770{
771 install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd);
772 install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd);
hasso996933f2004-07-12 16:32:56 +0000773 install_element (INTERFACE_NODE, &no_ip_irdp_cmd);
hassoca776982004-06-12 14:33:05 +0000774 install_element (INTERFACE_NODE, &ip_irdp_shutdown_cmd);
hasso996933f2004-07-12 16:32:56 +0000775 install_element (INTERFACE_NODE, &no_ip_irdp_shutdown_cmd);
hassoca776982004-06-12 14:33:05 +0000776 install_element (INTERFACE_NODE, &ip_irdp_holdtime_cmd);
777 install_element (INTERFACE_NODE, &ip_irdp_maxadvertinterval_cmd);
778 install_element (INTERFACE_NODE, &ip_irdp_minadvertinterval_cmd);
779 install_element (INTERFACE_NODE, &ip_irdp_preference_cmd);
780 install_element (INTERFACE_NODE, &ip_irdp_address_preference_cmd);
hasso996933f2004-07-12 16:32:56 +0000781 install_element (INTERFACE_NODE, &no_ip_irdp_address_preference_cmd);
hassoca776982004-06-12 14:33:05 +0000782
783 install_element (INTERFACE_NODE, &ip_irdp_debug_messages_cmd);
784 install_element (INTERFACE_NODE, &ip_irdp_debug_misc_cmd);
785 install_element (INTERFACE_NODE, &ip_irdp_debug_packet_cmd);
786 install_element (INTERFACE_NODE, &ip_irdp_debug_disable_cmd);
787}
788
789#endif /* HAVE_IRDP */