blob: 6403830b9af8c008a87e6cb57d7a83d39abc3c63 [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{
hassoca776982004-06-12 14:33:05 +0000102 struct ip_mreq m;
103 struct prefix *p;
104 int ret;
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300105 char b1[INET_ADDRSTRLEN];
hassoca776982004-06-12 14:33:05 +0000106
Jeremy Jacksonec5e42b2009-01-21 20:51:57 -0500107 memset (&m, 0, sizeof (m));
hassoca776982004-06-12 14:33:05 +0000108 m.imr_multiaddr.s_addr = htonl (group);
109 p = irdp_get_prefix(ifp);
110
111 if(!p) {
112 zlog_warn ("IRDP: can't get address for %s", ifp->name);
113 return 1;
114 }
115
116 m.imr_interface = p->u.prefix4;
117
118 ret = setsockopt (sock, IPPROTO_IP, add_leave,
119 (char *) &m, sizeof (struct ip_mreq));
120 if (ret < 0)
121 zlog_warn ("IRDP: %s can't setsockopt %s: %s",
122 add_leave == IP_ADD_MEMBERSHIP? "join group":"leave group",
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300123 inet_2a(group, b1),
124 safe_strerror (errno));
hassoca776982004-06-12 14:33:05 +0000125
126 return ret;
127}
128
ajs2da40f42005-03-30 16:33:13 +0000129static int
130if_add_group (struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000131{
132 struct zebra_if *zi= ifp->info;
133 struct irdp_interface *irdp = &zi->irdp;
134 int ret;
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300135 char b1[INET_ADDRSTRLEN];
hassoca776982004-06-12 14:33:05 +0000136
137 ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP);
138 if (ret < 0) {
139 return ret;
140 }
141
142 if(irdp->flags & IF_DEBUG_MISC )
ajs2da40f42005-03-30 16:33:13 +0000143 zlog_debug("IRDP: Adding group %s for %s",
ajsb6178002004-12-07 21:12:56 +0000144 inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
145 ifp->name);
hassoca776982004-06-12 14:33:05 +0000146 return 0;
147}
ajs2da40f42005-03-30 16:33:13 +0000148
149static int
150if_drop_group (struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000151{
152 struct zebra_if *zi= ifp->info;
153 struct irdp_interface *irdp = &zi->irdp;
154 int ret;
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300155 char b1[INET_ADDRSTRLEN];
hassoca776982004-06-12 14:33:05 +0000156
157 ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_DROP_MEMBERSHIP);
158 if (ret < 0)
159 return ret;
160
161 if(irdp->flags & IF_DEBUG_MISC)
ajs2da40f42005-03-30 16:33:13 +0000162 zlog_debug("IRDP: Leaving group %s for %s",
ajsb6178002004-12-07 21:12:56 +0000163 inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1),
164 ifp->name);
hassoca776982004-06-12 14:33:05 +0000165 return 0;
166}
167
ajs2da40f42005-03-30 16:33:13 +0000168static void
hassoca776982004-06-12 14:33:05 +0000169if_set_defaults(struct interface *ifp)
170{
171 struct zebra_if *zi=ifp->info;
172 struct irdp_interface *irdp=&zi->irdp;
173
174 irdp->MaxAdvertInterval = IRDP_MAXADVERTINTERVAL;
175 irdp->MinAdvertInterval = IRDP_MINADVERTINTERVAL;
176 irdp->Preference = IRDP_PREFERENCE;
177 irdp->Lifetime = IRDP_LIFETIME;
178}
179
180
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300181static struct Adv *Adv_new (void)
hassoca776982004-06-12 14:33:05 +0000182{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700183 return XCALLOC (MTYPE_TMP, sizeof (struct Adv));
hassoca776982004-06-12 14:33:05 +0000184}
185
ajs2da40f42005-03-30 16:33:13 +0000186static void
187Adv_free (struct Adv *adv)
hassoca776982004-06-12 14:33:05 +0000188{
189 XFREE (MTYPE_TMP, adv);
190}
191
ajs2da40f42005-03-30 16:33:13 +0000192static void
193irdp_if_start(struct interface *ifp, int multicast, int set_defaults)
hassoca776982004-06-12 14:33:05 +0000194{
195 struct zebra_if *zi= ifp->info;
196 struct irdp_interface *irdp = &zi->irdp;
paul0c0f9112004-09-24 08:24:42 +0000197 struct listnode *node;
198 struct connected *ifc;
hassoca776982004-06-12 14:33:05 +0000199 u_int32_t timer, seed;
200
201 if (irdp->flags & IF_ACTIVE ) {
ajs2da40f42005-03-30 16:33:13 +0000202 zlog_warn("IRDP: Interface is already active %s", ifp->name);
203 return;
204 }
205 if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) {
206 zlog_warn("IRDP: Cannot activate interface %s (cannot create "
207 "IRDP socket)", ifp->name);
hassoca776982004-06-12 14:33:05 +0000208 return;
209 }
210 irdp->flags |= IF_ACTIVE;
211
212 if(!multicast)
213 irdp->flags |= IF_BROADCAST;
214
215 if_add_update(ifp);
216
217 if (! (ifp->flags & IFF_UP)) {
ajs2da40f42005-03-30 16:33:13 +0000218 zlog_warn("IRDP: Interface is down %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000219 }
220
221 /* Shall we cancel if_start if if_add_group fails? */
222
223 if( multicast) {
224 if_add_group(ifp);
225
226 if (! (ifp->flags & (IFF_MULTICAST|IFF_ALLMULTI))) {
ajs2da40f42005-03-30 16:33:13 +0000227 zlog_warn("IRDP: Interface not multicast enabled %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000228 }
229 }
230
231 if(set_defaults)
232 if_set_defaults(ifp);
233
234 irdp->irdp_sent = 0;
235
236 /* The spec suggests this for randomness */
237
238 seed = 0;
paul0c0f9112004-09-24 08:24:42 +0000239 if( ifp->connected)
paul1eb8ef22005-04-07 07:30:20 +0000240 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
paul0c0f9112004-09-24 08:24:42 +0000241 {
242 seed = ifc->address->u.prefix4.s_addr;
243 break;
244 }
hassoca776982004-06-12 14:33:05 +0000245
246 srandom(seed);
247 timer = (random () % IRDP_DEFAULT_INTERVAL) + 1;
248
249 irdp->AdvPrefList = list_new();
hassoc9e52be2004-09-26 16:09:34 +0000250 irdp->AdvPrefList->del = (void (*)(void *)) Adv_free; /* Destructor */
hassoca776982004-06-12 14:33:05 +0000251
252
253 /* And this for startup. Speed limit from 1991 :-). But it's OK*/
254
255 if(irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS &&
256 timer > MAX_INITIAL_ADVERT_INTERVAL )
257 timer= MAX_INITIAL_ADVERT_INTERVAL;
258
259
260 if(irdp->flags & IF_DEBUG_MISC)
ajs2da40f42005-03-30 16:33:13 +0000261 zlog_debug("IRDP: Init timer for %s set to %u",
ajsb6178002004-12-07 21:12:56 +0000262 ifp->name,
263 timer);
hassoca776982004-06-12 14:33:05 +0000264
265 irdp->t_advertise = thread_add_timer(zebrad.master,
266 irdp_send_thread,
267 ifp,
268 timer);
269}
270
ajs2da40f42005-03-30 16:33:13 +0000271static void
272irdp_if_stop(struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000273{
274 struct zebra_if *zi=ifp->info;
275 struct irdp_interface *irdp=&zi->irdp;
276
277 if (irdp == NULL) {
278 zlog_warn ("Interface %s structure is NULL", ifp->name);
279 return;
280 }
281
282 if (! (irdp->flags & IF_ACTIVE )) {
ajs2da40f42005-03-30 16:33:13 +0000283 zlog_warn("Interface is not active %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000284 return;
285 }
286
287 if(! (irdp->flags & IF_BROADCAST))
288 if_drop_group(ifp);
289
290 irdp_advert_off(ifp);
291
292 list_delete(irdp->AdvPrefList);
293 irdp->AdvPrefList=NULL;
294
295 irdp->flags = 0;
296}
297
298
ajs2da40f42005-03-30 16:33:13 +0000299static void
300irdp_if_shutdown(struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000301{
302 struct zebra_if *zi= ifp->info;
303 struct irdp_interface *irdp = &zi->irdp;
304
305 if (irdp->flags & IF_SHUTDOWN ) {
ajs2da40f42005-03-30 16:33:13 +0000306 zlog_warn("IRDP: Interface is already shutdown %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000307 return;
308 }
309
310 irdp->flags |= IF_SHUTDOWN;
311 irdp->flags &= ~IF_ACTIVE;
312
313 if(! (irdp->flags & IF_BROADCAST))
314 if_drop_group(ifp);
315
316 /* Tell the hosts we are out of service */
317 irdp_advert_off(ifp);
318}
319
ajs2da40f42005-03-30 16:33:13 +0000320static void
321irdp_if_no_shutdown(struct interface *ifp)
hassoca776982004-06-12 14:33:05 +0000322{
323 struct zebra_if *zi= ifp->info;
324 struct irdp_interface *irdp = &zi->irdp;
325
326 if (! (irdp->flags & IF_SHUTDOWN )) {
ajs2da40f42005-03-30 16:33:13 +0000327 zlog_warn("IRDP: Interface is not shutdown %s", ifp->name);
hassoca776982004-06-12 14:33:05 +0000328 return;
329 }
330
331 irdp->flags &= ~IF_SHUTDOWN;
332
333 irdp_if_start(ifp, irdp->flags & IF_BROADCAST? FALSE : TRUE, FALSE);
334
335}
336
337
338/* Write configuration to user */
339
340void irdp_config_write (struct vty *vty, struct interface *ifp)
341{
342 struct zebra_if *zi=ifp->info;
343 struct irdp_interface *irdp=&zi->irdp;
344 struct Adv *adv;
paul0c0f9112004-09-24 08:24:42 +0000345 struct listnode *node;
Stephen Hemmingerab0f6152009-12-10 14:22:44 +0300346 char b1[INET_ADDRSTRLEN];
hassoca776982004-06-12 14:33:05 +0000347
348 if(irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) {
349
350 if( irdp->flags & IF_SHUTDOWN)
351 vty_out (vty, " ip irdp shutdown %s", VTY_NEWLINE);
352
353 if( irdp->flags & IF_BROADCAST)
354 vty_out (vty, " ip irdp broadcast%s", VTY_NEWLINE);
355 else
356 vty_out (vty, " ip irdp multicast%s", VTY_NEWLINE);
357
358 vty_out (vty, " ip irdp preference %ld%s",
359 irdp->Preference, VTY_NEWLINE);
360
paul1eb8ef22005-04-07 07:30:20 +0000361 for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
paul0c0f9112004-09-24 08:24:42 +0000362 vty_out (vty, " ip irdp address %s preference %d%s",
363 inet_2a(adv->ip.s_addr, b1),
364 adv->pref,
365 VTY_NEWLINE);
hassoca776982004-06-12 14:33:05 +0000366
367 vty_out (vty, " ip irdp holdtime %d%s",
368 irdp->Lifetime, VTY_NEWLINE);
369
370 vty_out (vty, " ip irdp minadvertinterval %ld%s",
371 irdp->MinAdvertInterval, VTY_NEWLINE);
372
373 vty_out (vty, " ip irdp maxadvertinterval %ld%s",
374 irdp->MaxAdvertInterval, VTY_NEWLINE);
375
376 }
377}
378
379
380DEFUN (ip_irdp_multicast,
381 ip_irdp_multicast_cmd,
382 "ip irdp multicast",
383 IP_STR
384 "ICMP Router discovery on this interface using multicast\n")
385{
386 struct interface *ifp;
387
388 ifp = (struct interface *) vty->index;
389 if(!ifp) {
390 return CMD_WARNING;
391 }
392
393 irdp_if_start(ifp, TRUE, TRUE);
394 return CMD_SUCCESS;
395}
396
397DEFUN (ip_irdp_broadcast,
398 ip_irdp_broadcast_cmd,
399 "ip irdp broadcast",
400 IP_STR
401 "ICMP Router discovery on this interface using broadcast\n")
402{
403 struct interface *ifp;
404
405 ifp = (struct interface *) vty->index;
406 if(!ifp) {
407 return CMD_WARNING;
408 }
409
410 irdp_if_start(ifp, FALSE, TRUE);
411 return CMD_SUCCESS;
412}
413
hasso996933f2004-07-12 16:32:56 +0000414DEFUN (no_ip_irdp,
415 no_ip_irdp_cmd,
hassoca776982004-06-12 14:33:05 +0000416 "no ip irdp",
hasso8d0f15f2004-09-11 16:33:28 +0000417 NO_STR
hassoca776982004-06-12 14:33:05 +0000418 IP_STR
419 "Disable ICMP Router discovery on this interface\n")
420{
421 struct interface *ifp;
422
423 ifp = (struct interface *) vty->index;
424 if(!ifp) {
425 return CMD_WARNING;
426 }
427
428 irdp_if_stop(ifp);
429 return CMD_SUCCESS;
430}
431
432DEFUN (ip_irdp_shutdown,
433 ip_irdp_shutdown_cmd,
434 "ip irdp shutdown",
435 IP_STR
436 "ICMP Router discovery shutdown on this interface\n")
437{
438 struct interface *ifp;
439
440 ifp = (struct interface *) vty->index;
441 if(!ifp) {
442 return CMD_WARNING;
443 }
444
445 irdp_if_shutdown(ifp);
446 return CMD_SUCCESS;
447}
448
hasso996933f2004-07-12 16:32:56 +0000449DEFUN (no_ip_irdp_shutdown,
450 no_ip_irdp_shutdown_cmd,
hassoca776982004-06-12 14:33:05 +0000451 "no ip irdp shutdown",
hasso8d0f15f2004-09-11 16:33:28 +0000452 NO_STR
hassoca776982004-06-12 14:33:05 +0000453 IP_STR
454 "ICMP Router discovery no shutdown on this interface\n")
455{
456 struct interface *ifp;
457
458 ifp = (struct interface *) vty->index;
459 if(!ifp) {
460 return CMD_WARNING;
461 }
462
463 irdp_if_no_shutdown(ifp);
464 return CMD_SUCCESS;
465}
466
467DEFUN (ip_irdp_holdtime,
468 ip_irdp_holdtime_cmd,
469 "ip irdp holdtime <0-9000>",
470 IP_STR
471 "ICMP Router discovery on this interface\n"
472 "Set holdtime value\n"
473 "Holdtime value in seconds. Default is 1800 seconds\n")
474{
475 struct interface *ifp;
476 struct zebra_if *zi;
477 struct irdp_interface *irdp;
478 ifp = (struct interface *) vty->index;
479 if(!ifp) {
480 return CMD_WARNING;
481 }
482
483 zi=ifp->info;
484 irdp=&zi->irdp;
485
486 irdp->Lifetime = atoi(argv[0]);
487 return CMD_SUCCESS;
488}
489
490DEFUN (ip_irdp_minadvertinterval,
491 ip_irdp_minadvertinterval_cmd,
492 "ip irdp minadvertinterval <3-1800>",
493 IP_STR
494 "ICMP Router discovery on this interface\n"
495 "Set minimum time between advertisement\n"
496 "Minimum advertisement interval in seconds\n")
497{
498 struct interface *ifp;
499 struct zebra_if *zi;
500 struct irdp_interface *irdp;
501 ifp = (struct interface *) vty->index;
502 if(!ifp) {
503 return CMD_WARNING;
504 }
505
506 zi=ifp->info;
507 irdp=&zi->irdp;
508
hasso39db97e2004-10-12 20:50:58 +0000509 if( (unsigned) atoi(argv[0]) <= irdp->MaxAdvertInterval) {
hassoca776982004-06-12 14:33:05 +0000510 irdp->MinAdvertInterval = atoi(argv[0]);
511
512 return CMD_SUCCESS;
513 }
514
515 vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s",
516 VTY_NEWLINE);
517
518 vty_out (vty, "Please correct!%s",
519 VTY_NEWLINE);
520 return CMD_WARNING;
521}
522
523DEFUN (ip_irdp_maxadvertinterval,
524 ip_irdp_maxadvertinterval_cmd,
525 "ip irdp maxadvertinterval <4-1800>",
526 IP_STR
527 "ICMP Router discovery on this interface\n"
528 "Set maximum time between advertisement\n"
529 "Maximum advertisement interval in seconds\n")
530{
531 struct interface *ifp;
532 struct zebra_if *zi;
533 struct irdp_interface *irdp;
534 ifp = (struct interface *) vty->index;
535 if(!ifp) {
536 return CMD_WARNING;
537 }
538
539 zi=ifp->info;
540 irdp=&zi->irdp;
541
542
hasso39db97e2004-10-12 20:50:58 +0000543 if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[0]) ) {
hassoca776982004-06-12 14:33:05 +0000544 irdp->MaxAdvertInterval = atoi(argv[0]);
545
546 return CMD_SUCCESS;
547 }
548
549 vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s",
550 VTY_NEWLINE);
551
552 vty_out (vty, "Please correct!%s",
553 VTY_NEWLINE);
554 return CMD_WARNING;
555}
556
hassoaccb1562004-11-25 19:21:07 +0000557/* DEFUN needs to be fixed for negative ranages...
558 * "ip irdp preference <-2147483648-2147483647>",
559 * Be positive for now. :-)
560 */
561
hassoca776982004-06-12 14:33:05 +0000562DEFUN (ip_irdp_preference,
563 ip_irdp_preference_cmd,
hassoca776982004-06-12 14:33:05 +0000564 "ip irdp preference <0-2147483647>",
565 IP_STR
566 "ICMP Router discovery on this interface\n"
567 "Set default preference level for this interface\n"
568 "Preference level\n")
569{
570 struct interface *ifp;
571 struct zebra_if *zi;
572 struct irdp_interface *irdp;
573 ifp = (struct interface *) vty->index;
574 if(!ifp) {
575 return CMD_WARNING;
576 }
577
578 zi=ifp->info;
579 irdp=&zi->irdp;
580
581 irdp->Preference = atoi(argv[0]);
582 return CMD_SUCCESS;
583}
584
585DEFUN (ip_irdp_address_preference,
586 ip_irdp_address_preference_cmd,
587 "ip irdp address A.B.C.D preference <0-2147483647>",
588 IP_STR
589 "Alter ICMP Router discovery preference this interface\n"
590 "Specify IRDP non-default preference to advertise\n"
591 "Set IRDP address for advertise\n"
592 "Preference level\n")
593{
paul0c0f9112004-09-24 08:24:42 +0000594 struct listnode *node;
hassoca776982004-06-12 14:33:05 +0000595 struct in_addr ip;
596 int pref;
597 int ret;
598 struct interface *ifp;
599 struct zebra_if *zi;
600 struct irdp_interface *irdp;
601 struct Adv *adv;
602
603 ifp = (struct interface *) vty->index;
604 if(!ifp) {
605 return CMD_WARNING;
606 }
607
608 zi=ifp->info;
609 irdp=&zi->irdp;
610
611 ret = inet_aton(argv[0], &ip);
612 if(!ret) return CMD_WARNING;
613
614 pref = atoi(argv[1]);
615
paul1eb8ef22005-04-07 07:30:20 +0000616 for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv))
paul0c0f9112004-09-24 08:24:42 +0000617 if(adv->ip.s_addr == ip.s_addr)
618 return CMD_SUCCESS;
hassoca776982004-06-12 14:33:05 +0000619
620 adv = Adv_new();
621 adv->ip = ip;
622 adv->pref = pref;
623 listnode_add(irdp->AdvPrefList, adv);
624
625 return CMD_SUCCESS;
626
627}
628
hasso996933f2004-07-12 16:32:56 +0000629DEFUN (no_ip_irdp_address_preference,
630 no_ip_irdp_address_preference_cmd,
hassoca776982004-06-12 14:33:05 +0000631 "no ip irdp address A.B.C.D preference <0-2147483647>",
hasso8d0f15f2004-09-11 16:33:28 +0000632 NO_STR
hassoca776982004-06-12 14:33:05 +0000633 IP_STR
634 "Alter ICMP Router discovery preference this interface\n"
635 "Removes IRDP non-default preference\n"
636 "Select IRDP address\n"
637 "Old preference level\n")
638{
paul26f7a242004-09-24 08:45:10 +0000639 struct listnode *node, *nnode;
hassoca776982004-06-12 14:33:05 +0000640 struct in_addr ip;
641 int pref;
642 int ret;
643 struct interface *ifp;
644 struct zebra_if *zi;
645 struct irdp_interface *irdp;
646 struct Adv *adv;
647
648 ifp = (struct interface *) vty->index;
649 if(!ifp) {
650 return CMD_WARNING;
651 }
652
653 zi=ifp->info;
654 irdp=&zi->irdp;
655
656 ret = inet_aton(argv[0], &ip);
paul0c0f9112004-09-24 08:24:42 +0000657 if (!ret)
658 return CMD_WARNING;
hassoca776982004-06-12 14:33:05 +0000659
660 pref = atoi(argv[1]);
661
paul1eb8ef22005-04-07 07:30:20 +0000662 for (ALL_LIST_ELEMENTS (irdp->AdvPrefList, node, nnode, adv))
paul0c0f9112004-09-24 08:24:42 +0000663 {
paul0c0f9112004-09-24 08:24:42 +0000664 if(adv->ip.s_addr == ip.s_addr )
665 {
666 listnode_delete(irdp->AdvPrefList, adv);
667 break;
668 }
669 }
670
hassoca776982004-06-12 14:33:05 +0000671 return CMD_SUCCESS;
hassoca776982004-06-12 14:33:05 +0000672}
673
674DEFUN (ip_irdp_debug_messages,
675 ip_irdp_debug_messages_cmd,
676 "ip irdp debug messages",
677 IP_STR
678 "ICMP Router discovery debug Averts. and Solicits (short)\n")
679{
680 struct interface *ifp;
681 struct zebra_if *zi;
682 struct irdp_interface *irdp;
683 ifp = (struct interface *) vty->index;
684 if(!ifp) {
685 return CMD_WARNING;
686 }
687
688 zi=ifp->info;
689 irdp=&zi->irdp;
690
691 irdp->flags |= IF_DEBUG_MESSAGES;
692
693 return CMD_SUCCESS;
694}
695
696DEFUN (ip_irdp_debug_misc,
697 ip_irdp_debug_misc_cmd,
698 "ip irdp debug misc",
699 IP_STR
700 "ICMP Router discovery debug Averts. and Solicits (short)\n")
701{
702 struct interface *ifp;
703 struct zebra_if *zi;
704 struct irdp_interface *irdp;
705 ifp = (struct interface *) vty->index;
706 if(!ifp) {
707 return CMD_WARNING;
708 }
709
710 zi=ifp->info;
711 irdp=&zi->irdp;
712
713 irdp->flags |= IF_DEBUG_MISC;
714
715 return CMD_SUCCESS;
716}
717
718DEFUN (ip_irdp_debug_packet,
719 ip_irdp_debug_packet_cmd,
720 "ip irdp debug packet",
721 IP_STR
722 "ICMP Router discovery debug Averts. and Solicits (short)\n")
723{
724 struct interface *ifp;
725 struct zebra_if *zi;
726 struct irdp_interface *irdp;
727 ifp = (struct interface *) vty->index;
728 if(!ifp) {
729 return CMD_WARNING;
730 }
731
732 zi=ifp->info;
733 irdp=&zi->irdp;
734
735 irdp->flags |= IF_DEBUG_PACKET;
736
737 return CMD_SUCCESS;
738}
739
740
741DEFUN (ip_irdp_debug_disable,
742 ip_irdp_debug_disable_cmd,
743 "ip irdp debug disable",
744 IP_STR
745 "ICMP Router discovery debug Averts. and Solicits (short)\n")
746{
747 struct interface *ifp;
748 struct zebra_if *zi;
749 struct irdp_interface *irdp;
750 ifp = (struct interface *) vty->index;
751 if(!ifp) {
752 return CMD_WARNING;
753 }
754
755 zi=ifp->info;
756 irdp=&zi->irdp;
757
758 irdp->flags &= ~IF_DEBUG_PACKET;
759 irdp->flags &= ~IF_DEBUG_MESSAGES;
760 irdp->flags &= ~IF_DEBUG_MISC;
761
762 return CMD_SUCCESS;
763}
764
765void
ajs2da40f42005-03-30 16:33:13 +0000766irdp_init ()
hassoca776982004-06-12 14:33:05 +0000767{
768 install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd);
769 install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd);
hasso996933f2004-07-12 16:32:56 +0000770 install_element (INTERFACE_NODE, &no_ip_irdp_cmd);
hassoca776982004-06-12 14:33:05 +0000771 install_element (INTERFACE_NODE, &ip_irdp_shutdown_cmd);
hasso996933f2004-07-12 16:32:56 +0000772 install_element (INTERFACE_NODE, &no_ip_irdp_shutdown_cmd);
hassoca776982004-06-12 14:33:05 +0000773 install_element (INTERFACE_NODE, &ip_irdp_holdtime_cmd);
774 install_element (INTERFACE_NODE, &ip_irdp_maxadvertinterval_cmd);
775 install_element (INTERFACE_NODE, &ip_irdp_minadvertinterval_cmd);
776 install_element (INTERFACE_NODE, &ip_irdp_preference_cmd);
777 install_element (INTERFACE_NODE, &ip_irdp_address_preference_cmd);
hasso996933f2004-07-12 16:32:56 +0000778 install_element (INTERFACE_NODE, &no_ip_irdp_address_preference_cmd);
hassoca776982004-06-12 14:33:05 +0000779
780 install_element (INTERFACE_NODE, &ip_irdp_debug_messages_cmd);
781 install_element (INTERFACE_NODE, &ip_irdp_debug_misc_cmd);
782 install_element (INTERFACE_NODE, &ip_irdp_debug_packet_cmd);
783 install_element (INTERFACE_NODE, &ip_irdp_debug_disable_cmd);
784}
785
786#endif /* HAVE_IRDP */