hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 1 | /* |
| 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. */ |
| 66 | extern struct zebra_t zebrad; |
| 67 | |
| 68 | int in_cksum (void *ptr, int nbytes); |
| 69 | extern int irdp_sock; |
| 70 | int irdp_send_thread(struct thread *t_advert); |
| 71 | char *inet_2a(u_int32_t a, char *b); |
| 72 | void irdp_advert_off(struct interface *ifp); |
| 73 | |
| 74 | |
| 75 | char b1[16], b2[16], b3[16], b4[16]; /* For inet_2a */ |
| 76 | |
| 77 | struct prefix *irdp_get_prefix(struct interface *ifp) |
| 78 | { |
| 79 | listnode node; |
| 80 | struct connected *ifc; |
| 81 | |
| 82 | if(ifp->connected) |
| 83 | for (node = listhead (ifp->connected); node; nextnode (node)) { |
| 84 | ifc = getdata (node); |
| 85 | return ifc->address; |
| 86 | } |
| 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | /* Join to the add/leave multicast group. */ |
| 91 | int if_group (struct interface *ifp, |
| 92 | int sock, |
| 93 | u_int32_t group, |
| 94 | int add_leave) |
| 95 | { |
| 96 | struct zebra_if *zi; |
| 97 | struct ip_mreq m; |
| 98 | struct prefix *p; |
| 99 | int ret; |
| 100 | |
| 101 | zi = ifp->info; |
| 102 | |
| 103 | bzero (&m, sizeof (m)); |
| 104 | m.imr_multiaddr.s_addr = htonl (group); |
| 105 | p = irdp_get_prefix(ifp); |
| 106 | |
| 107 | if(!p) { |
| 108 | zlog_warn ("IRDP: can't get address for %s", ifp->name); |
| 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | m.imr_interface = p->u.prefix4; |
| 113 | |
| 114 | ret = setsockopt (sock, IPPROTO_IP, add_leave, |
| 115 | (char *) &m, sizeof (struct ip_mreq)); |
| 116 | if (ret < 0) |
| 117 | zlog_warn ("IRDP: %s can't setsockopt %s: %s", |
| 118 | add_leave == IP_ADD_MEMBERSHIP? "join group":"leave group", |
| 119 | inet_2a(group, b1), |
| 120 | strerror (errno)); |
| 121 | |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | int if_add_group (struct interface *ifp) |
| 126 | { |
| 127 | struct zebra_if *zi= ifp->info; |
| 128 | struct irdp_interface *irdp = &zi->irdp; |
| 129 | int ret; |
| 130 | |
| 131 | ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP); |
| 132 | if (ret < 0) { |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | if(irdp->flags & IF_DEBUG_MISC ) |
| 137 | zlog_warn("IRDP: Adding group %s for %s\n", |
| 138 | inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1), |
| 139 | ifp->name); |
| 140 | return 0; |
| 141 | } |
| 142 | int if_drop_group (struct interface *ifp) |
| 143 | { |
| 144 | struct zebra_if *zi= ifp->info; |
| 145 | struct irdp_interface *irdp = &zi->irdp; |
| 146 | int ret; |
| 147 | |
| 148 | ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_DROP_MEMBERSHIP); |
| 149 | if (ret < 0) |
| 150 | return ret; |
| 151 | |
| 152 | if(irdp->flags & IF_DEBUG_MISC) |
| 153 | zlog_warn("IRDP: Leaving group %s for %s\n", |
| 154 | inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1), |
| 155 | ifp->name); |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | struct interface *get_iflist_ifp(int idx) |
| 160 | { |
| 161 | listnode node; |
| 162 | struct interface *ifp; |
| 163 | |
| 164 | for (node = listhead (iflist); node; nextnode (node)) { |
| 165 | ifp = getdata (node); |
| 166 | if(ifp->ifindex == idx) return ifp; |
| 167 | } |
| 168 | return NULL; |
| 169 | } |
| 170 | |
| 171 | void |
| 172 | if_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 | |
| 184 | struct Adv *Adv_new () |
| 185 | { |
| 186 | struct Adv *new; |
| 187 | new = XMALLOC (MTYPE_TMP, sizeof (struct Adv)); |
| 188 | memset (new, 0, sizeof (struct Adv)); |
| 189 | return new; |
| 190 | } |
| 191 | |
| 192 | void Adv_free (struct Adv *adv) |
| 193 | { |
| 194 | XFREE (MTYPE_TMP, adv); |
| 195 | } |
| 196 | |
| 197 | void irdp_if_start(struct interface *ifp, int multicast, int set_defaults) |
| 198 | { |
| 199 | struct zebra_if *zi= ifp->info; |
| 200 | struct irdp_interface *irdp = &zi->irdp; |
| 201 | listnode node; |
| 202 | u_int32_t timer, seed; |
| 203 | |
| 204 | if (irdp->flags & IF_ACTIVE ) { |
| 205 | zlog_warn("IRDP: Interface is already active %s\n", ifp->name); |
| 206 | return; |
| 207 | } |
| 208 | irdp->flags |= IF_ACTIVE; |
| 209 | |
| 210 | if(!multicast) |
| 211 | irdp->flags |= IF_BROADCAST; |
| 212 | |
| 213 | if_add_update(ifp); |
| 214 | |
| 215 | if (! (ifp->flags & IFF_UP)) { |
| 216 | zlog_warn("IRDP: Interface is down %s\n", ifp->name); |
| 217 | } |
| 218 | |
| 219 | /* Shall we cancel if_start if if_add_group fails? */ |
| 220 | |
| 221 | if( multicast) { |
| 222 | if_add_group(ifp); |
| 223 | |
| 224 | if (! (ifp->flags & (IFF_MULTICAST|IFF_ALLMULTI))) { |
| 225 | zlog_warn("IRDP: Interface not multicast enabled %s\n", ifp->name); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | if(set_defaults) |
| 230 | if_set_defaults(ifp); |
| 231 | |
| 232 | irdp->irdp_sent = 0; |
| 233 | |
| 234 | /* The spec suggests this for randomness */ |
| 235 | |
| 236 | seed = 0; |
| 237 | if( ifp->connected) |
| 238 | for (node = listhead (ifp->connected); node; nextnode (node)) |
| 239 | { |
| 240 | struct connected *ifc = getdata (node); |
| 241 | seed = ifc->address->u.prefix4.s_addr; |
| 242 | } |
| 243 | |
| 244 | srandom(seed); |
| 245 | timer = (random () % IRDP_DEFAULT_INTERVAL) + 1; |
| 246 | |
| 247 | irdp->AdvPrefList = list_new(); |
| 248 | irdp->AdvPrefList->del = (void *) Adv_free; /* Destructor */ |
| 249 | |
| 250 | |
| 251 | /* And this for startup. Speed limit from 1991 :-). But it's OK*/ |
| 252 | |
| 253 | if(irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS && |
| 254 | timer > MAX_INITIAL_ADVERT_INTERVAL ) |
| 255 | timer= MAX_INITIAL_ADVERT_INTERVAL; |
| 256 | |
| 257 | |
| 258 | if(irdp->flags & IF_DEBUG_MISC) |
| 259 | zlog_warn("IRDP: Init timer for %s set to %u\n", |
| 260 | ifp->name, |
| 261 | timer); |
| 262 | |
| 263 | irdp->t_advertise = thread_add_timer(zebrad.master, |
| 264 | irdp_send_thread, |
| 265 | ifp, |
| 266 | timer); |
| 267 | } |
| 268 | |
| 269 | void irdp_if_stop(struct interface *ifp) |
| 270 | { |
| 271 | struct zebra_if *zi=ifp->info; |
| 272 | struct irdp_interface *irdp=&zi->irdp; |
| 273 | |
| 274 | if (irdp == NULL) { |
| 275 | zlog_warn ("Interface %s structure is NULL", ifp->name); |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | if (! (irdp->flags & IF_ACTIVE )) { |
| 280 | zlog_warn("Interface is not active %s\n", ifp->name); |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | if(! (irdp->flags & IF_BROADCAST)) |
| 285 | if_drop_group(ifp); |
| 286 | |
| 287 | irdp_advert_off(ifp); |
| 288 | |
| 289 | list_delete(irdp->AdvPrefList); |
| 290 | irdp->AdvPrefList=NULL; |
| 291 | |
| 292 | irdp->flags = 0; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | void irdp_if_shutdown(struct interface *ifp) |
| 297 | { |
| 298 | struct zebra_if *zi= ifp->info; |
| 299 | struct irdp_interface *irdp = &zi->irdp; |
| 300 | |
| 301 | if (irdp->flags & IF_SHUTDOWN ) { |
| 302 | zlog_warn("IRDP: Interface is already shutdown %s\n", ifp->name); |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | irdp->flags |= IF_SHUTDOWN; |
| 307 | irdp->flags &= ~IF_ACTIVE; |
| 308 | |
| 309 | if(! (irdp->flags & IF_BROADCAST)) |
| 310 | if_drop_group(ifp); |
| 311 | |
| 312 | /* Tell the hosts we are out of service */ |
| 313 | irdp_advert_off(ifp); |
| 314 | } |
| 315 | |
| 316 | void irdp_if_no_shutdown(struct interface *ifp) |
| 317 | { |
| 318 | struct zebra_if *zi= ifp->info; |
| 319 | struct irdp_interface *irdp = &zi->irdp; |
| 320 | |
| 321 | if (! (irdp->flags & IF_SHUTDOWN )) { |
| 322 | zlog_warn("IRDP: Interface is not shutdown %s\n", ifp->name); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | irdp->flags &= ~IF_SHUTDOWN; |
| 327 | |
| 328 | irdp_if_start(ifp, irdp->flags & IF_BROADCAST? FALSE : TRUE, FALSE); |
| 329 | |
| 330 | } |
| 331 | |
| 332 | |
| 333 | /* Write configuration to user */ |
| 334 | |
| 335 | void irdp_config_write (struct vty *vty, struct interface *ifp) |
| 336 | { |
| 337 | struct zebra_if *zi=ifp->info; |
| 338 | struct irdp_interface *irdp=&zi->irdp; |
| 339 | struct Adv *adv; |
| 340 | listnode node; |
| 341 | |
| 342 | if(irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) { |
| 343 | |
| 344 | if( irdp->flags & IF_SHUTDOWN) |
| 345 | vty_out (vty, " ip irdp shutdown %s", VTY_NEWLINE); |
| 346 | |
| 347 | if( irdp->flags & IF_BROADCAST) |
| 348 | vty_out (vty, " ip irdp broadcast%s", VTY_NEWLINE); |
| 349 | else |
| 350 | vty_out (vty, " ip irdp multicast%s", VTY_NEWLINE); |
| 351 | |
| 352 | vty_out (vty, " ip irdp preference %ld%s", |
| 353 | irdp->Preference, VTY_NEWLINE); |
| 354 | |
| 355 | for (node = listhead (irdp->AdvPrefList); node; nextnode (node)) { |
| 356 | adv = getdata (node); |
| 357 | vty_out (vty, " ip irdp address %s preference %d%s", |
| 358 | inet_2a(adv->ip.s_addr, b1), |
| 359 | adv->pref, |
| 360 | VTY_NEWLINE); |
| 361 | |
| 362 | } |
| 363 | |
| 364 | vty_out (vty, " ip irdp holdtime %d%s", |
| 365 | irdp->Lifetime, VTY_NEWLINE); |
| 366 | |
| 367 | vty_out (vty, " ip irdp minadvertinterval %ld%s", |
| 368 | irdp->MinAdvertInterval, VTY_NEWLINE); |
| 369 | |
| 370 | vty_out (vty, " ip irdp maxadvertinterval %ld%s", |
| 371 | irdp->MaxAdvertInterval, VTY_NEWLINE); |
| 372 | |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | |
| 377 | DEFUN (ip_irdp_multicast, |
| 378 | ip_irdp_multicast_cmd, |
| 379 | "ip irdp multicast", |
| 380 | IP_STR |
| 381 | "ICMP Router discovery on this interface using multicast\n") |
| 382 | { |
| 383 | struct interface *ifp; |
| 384 | |
| 385 | ifp = (struct interface *) vty->index; |
| 386 | if(!ifp) { |
| 387 | return CMD_WARNING; |
| 388 | } |
| 389 | |
| 390 | irdp_if_start(ifp, TRUE, TRUE); |
| 391 | return CMD_SUCCESS; |
| 392 | } |
| 393 | |
| 394 | DEFUN (ip_irdp_broadcast, |
| 395 | ip_irdp_broadcast_cmd, |
| 396 | "ip irdp broadcast", |
| 397 | IP_STR |
| 398 | "ICMP Router discovery on this interface using broadcast\n") |
| 399 | { |
| 400 | struct interface *ifp; |
| 401 | |
| 402 | ifp = (struct interface *) vty->index; |
| 403 | if(!ifp) { |
| 404 | return CMD_WARNING; |
| 405 | } |
| 406 | |
| 407 | irdp_if_start(ifp, FALSE, TRUE); |
| 408 | return CMD_SUCCESS; |
| 409 | } |
| 410 | |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame^] | 411 | DEFUN (no_ip_irdp, |
| 412 | no_ip_irdp_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 413 | "no ip irdp", |
| 414 | IP_STR |
| 415 | "Disable ICMP Router discovery on this interface\n") |
| 416 | { |
| 417 | struct interface *ifp; |
| 418 | |
| 419 | ifp = (struct interface *) vty->index; |
| 420 | if(!ifp) { |
| 421 | return CMD_WARNING; |
| 422 | } |
| 423 | |
| 424 | irdp_if_stop(ifp); |
| 425 | return CMD_SUCCESS; |
| 426 | } |
| 427 | |
| 428 | DEFUN (ip_irdp_shutdown, |
| 429 | ip_irdp_shutdown_cmd, |
| 430 | "ip irdp shutdown", |
| 431 | IP_STR |
| 432 | "ICMP Router discovery shutdown on this interface\n") |
| 433 | { |
| 434 | struct interface *ifp; |
| 435 | |
| 436 | ifp = (struct interface *) vty->index; |
| 437 | if(!ifp) { |
| 438 | return CMD_WARNING; |
| 439 | } |
| 440 | |
| 441 | irdp_if_shutdown(ifp); |
| 442 | return CMD_SUCCESS; |
| 443 | } |
| 444 | |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame^] | 445 | DEFUN (no_ip_irdp_shutdown, |
| 446 | no_ip_irdp_shutdown_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 447 | "no ip irdp shutdown", |
| 448 | IP_STR |
| 449 | "ICMP Router discovery no shutdown on this interface\n") |
| 450 | { |
| 451 | struct interface *ifp; |
| 452 | |
| 453 | ifp = (struct interface *) vty->index; |
| 454 | if(!ifp) { |
| 455 | return CMD_WARNING; |
| 456 | } |
| 457 | |
| 458 | irdp_if_no_shutdown(ifp); |
| 459 | return CMD_SUCCESS; |
| 460 | } |
| 461 | |
| 462 | DEFUN (ip_irdp_holdtime, |
| 463 | ip_irdp_holdtime_cmd, |
| 464 | "ip irdp holdtime <0-9000>", |
| 465 | IP_STR |
| 466 | "ICMP Router discovery on this interface\n" |
| 467 | "Set holdtime value\n" |
| 468 | "Holdtime value in seconds. Default is 1800 seconds\n") |
| 469 | { |
| 470 | struct interface *ifp; |
| 471 | struct zebra_if *zi; |
| 472 | struct irdp_interface *irdp; |
| 473 | ifp = (struct interface *) vty->index; |
| 474 | if(!ifp) { |
| 475 | return CMD_WARNING; |
| 476 | } |
| 477 | |
| 478 | zi=ifp->info; |
| 479 | irdp=&zi->irdp; |
| 480 | |
| 481 | irdp->Lifetime = atoi(argv[0]); |
| 482 | return CMD_SUCCESS; |
| 483 | } |
| 484 | |
| 485 | DEFUN (ip_irdp_minadvertinterval, |
| 486 | ip_irdp_minadvertinterval_cmd, |
| 487 | "ip irdp minadvertinterval <3-1800>", |
| 488 | IP_STR |
| 489 | "ICMP Router discovery on this interface\n" |
| 490 | "Set minimum time between advertisement\n" |
| 491 | "Minimum advertisement interval in seconds\n") |
| 492 | { |
| 493 | struct interface *ifp; |
| 494 | struct zebra_if *zi; |
| 495 | struct irdp_interface *irdp; |
| 496 | ifp = (struct interface *) vty->index; |
| 497 | if(!ifp) { |
| 498 | return CMD_WARNING; |
| 499 | } |
| 500 | |
| 501 | zi=ifp->info; |
| 502 | irdp=&zi->irdp; |
| 503 | |
| 504 | if( atoi(argv[0]) <= irdp->MaxAdvertInterval) { |
| 505 | irdp->MinAdvertInterval = atoi(argv[0]); |
| 506 | |
| 507 | return CMD_SUCCESS; |
| 508 | } |
| 509 | |
| 510 | vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", |
| 511 | VTY_NEWLINE); |
| 512 | |
| 513 | vty_out (vty, "Please correct!%s", |
| 514 | VTY_NEWLINE); |
| 515 | return CMD_WARNING; |
| 516 | } |
| 517 | |
| 518 | DEFUN (ip_irdp_maxadvertinterval, |
| 519 | ip_irdp_maxadvertinterval_cmd, |
| 520 | "ip irdp maxadvertinterval <4-1800>", |
| 521 | IP_STR |
| 522 | "ICMP Router discovery on this interface\n" |
| 523 | "Set maximum time between advertisement\n" |
| 524 | "Maximum advertisement interval in seconds\n") |
| 525 | { |
| 526 | struct interface *ifp; |
| 527 | struct zebra_if *zi; |
| 528 | struct irdp_interface *irdp; |
| 529 | ifp = (struct interface *) vty->index; |
| 530 | if(!ifp) { |
| 531 | return CMD_WARNING; |
| 532 | } |
| 533 | |
| 534 | zi=ifp->info; |
| 535 | irdp=&zi->irdp; |
| 536 | |
| 537 | |
| 538 | if( irdp->MinAdvertInterval <= atoi(argv[0]) ) { |
| 539 | irdp->MaxAdvertInterval = atoi(argv[0]); |
| 540 | |
| 541 | return CMD_SUCCESS; |
| 542 | } |
| 543 | |
| 544 | vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", |
| 545 | VTY_NEWLINE); |
| 546 | |
| 547 | vty_out (vty, "Please correct!%s", |
| 548 | VTY_NEWLINE); |
| 549 | return CMD_WARNING; |
| 550 | } |
| 551 | |
| 552 | DEFUN (ip_irdp_preference, |
| 553 | ip_irdp_preference_cmd, |
| 554 | |
| 555 | /* DEFUN needs to be fixed for negative ranages... |
| 556 | Be positive for now. :-) |
| 557 | |
| 558 | "ip irdp preference <-2147483648-2147483647>", |
| 559 | */ |
| 560 | |
| 561 | |
| 562 | "ip irdp preference <0-2147483647>", |
| 563 | IP_STR |
| 564 | "ICMP Router discovery on this interface\n" |
| 565 | "Set default preference level for this interface\n" |
| 566 | "Preference level\n") |
| 567 | { |
| 568 | struct interface *ifp; |
| 569 | struct zebra_if *zi; |
| 570 | struct irdp_interface *irdp; |
| 571 | ifp = (struct interface *) vty->index; |
| 572 | if(!ifp) { |
| 573 | return CMD_WARNING; |
| 574 | } |
| 575 | |
| 576 | zi=ifp->info; |
| 577 | irdp=&zi->irdp; |
| 578 | |
| 579 | irdp->Preference = atoi(argv[0]); |
| 580 | return CMD_SUCCESS; |
| 581 | } |
| 582 | |
| 583 | DEFUN (ip_irdp_address_preference, |
| 584 | ip_irdp_address_preference_cmd, |
| 585 | "ip irdp address A.B.C.D preference <0-2147483647>", |
| 586 | IP_STR |
| 587 | "Alter ICMP Router discovery preference this interface\n" |
| 588 | "Specify IRDP non-default preference to advertise\n" |
| 589 | "Set IRDP address for advertise\n" |
| 590 | "Preference level\n") |
| 591 | { |
| 592 | listnode node; |
| 593 | struct in_addr ip; |
| 594 | int pref; |
| 595 | int ret; |
| 596 | struct interface *ifp; |
| 597 | struct zebra_if *zi; |
| 598 | struct irdp_interface *irdp; |
| 599 | struct Adv *adv; |
| 600 | |
| 601 | ifp = (struct interface *) vty->index; |
| 602 | if(!ifp) { |
| 603 | return CMD_WARNING; |
| 604 | } |
| 605 | |
| 606 | zi=ifp->info; |
| 607 | irdp=&zi->irdp; |
| 608 | |
| 609 | ret = inet_aton(argv[0], &ip); |
| 610 | if(!ret) return CMD_WARNING; |
| 611 | |
| 612 | pref = atoi(argv[1]); |
| 613 | |
| 614 | for (node = listhead (irdp->AdvPrefList); node; nextnode (node)) { |
| 615 | adv = getdata (node); |
| 616 | if(adv->ip.s_addr == ip.s_addr) return CMD_SUCCESS; |
| 617 | } |
| 618 | |
| 619 | adv = Adv_new(); |
| 620 | adv->ip = ip; |
| 621 | adv->pref = pref; |
| 622 | listnode_add(irdp->AdvPrefList, adv); |
| 623 | |
| 624 | return CMD_SUCCESS; |
| 625 | |
| 626 | } |
| 627 | |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame^] | 628 | DEFUN (no_ip_irdp_address_preference, |
| 629 | no_ip_irdp_address_preference_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 630 | "no ip irdp address A.B.C.D preference <0-2147483647>", |
| 631 | IP_STR |
| 632 | "Alter ICMP Router discovery preference this interface\n" |
| 633 | "Removes IRDP non-default preference\n" |
| 634 | "Select IRDP address\n" |
| 635 | "Old preference level\n") |
| 636 | { |
| 637 | listnode node; |
| 638 | struct in_addr ip; |
| 639 | int pref; |
| 640 | int ret; |
| 641 | struct interface *ifp; |
| 642 | struct zebra_if *zi; |
| 643 | struct irdp_interface *irdp; |
| 644 | struct Adv *adv; |
| 645 | |
| 646 | ifp = (struct interface *) vty->index; |
| 647 | if(!ifp) { |
| 648 | return CMD_WARNING; |
| 649 | } |
| 650 | |
| 651 | zi=ifp->info; |
| 652 | irdp=&zi->irdp; |
| 653 | |
| 654 | ret = inet_aton(argv[0], &ip); |
| 655 | if(!ret) return CMD_WARNING; |
| 656 | |
| 657 | pref = atoi(argv[1]); |
| 658 | |
| 659 | for (node = listhead (irdp->AdvPrefList); node; nextnode (node)) { |
| 660 | adv = getdata (node); |
| 661 | if(adv->ip.s_addr == ip.s_addr ) { |
| 662 | listnode_delete(irdp->AdvPrefList, adv); |
| 663 | break; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | return CMD_SUCCESS; |
| 668 | |
| 669 | |
| 670 | } |
| 671 | |
| 672 | DEFUN (ip_irdp_debug_messages, |
| 673 | ip_irdp_debug_messages_cmd, |
| 674 | "ip irdp debug messages", |
| 675 | IP_STR |
| 676 | "ICMP Router discovery debug Averts. and Solicits (short)\n") |
| 677 | { |
| 678 | struct interface *ifp; |
| 679 | struct zebra_if *zi; |
| 680 | struct irdp_interface *irdp; |
| 681 | ifp = (struct interface *) vty->index; |
| 682 | if(!ifp) { |
| 683 | return CMD_WARNING; |
| 684 | } |
| 685 | |
| 686 | zi=ifp->info; |
| 687 | irdp=&zi->irdp; |
| 688 | |
| 689 | irdp->flags |= IF_DEBUG_MESSAGES; |
| 690 | |
| 691 | return CMD_SUCCESS; |
| 692 | } |
| 693 | |
| 694 | DEFUN (ip_irdp_debug_misc, |
| 695 | ip_irdp_debug_misc_cmd, |
| 696 | "ip irdp debug misc", |
| 697 | IP_STR |
| 698 | "ICMP Router discovery debug Averts. and Solicits (short)\n") |
| 699 | { |
| 700 | struct interface *ifp; |
| 701 | struct zebra_if *zi; |
| 702 | struct irdp_interface *irdp; |
| 703 | ifp = (struct interface *) vty->index; |
| 704 | if(!ifp) { |
| 705 | return CMD_WARNING; |
| 706 | } |
| 707 | |
| 708 | zi=ifp->info; |
| 709 | irdp=&zi->irdp; |
| 710 | |
| 711 | irdp->flags |= IF_DEBUG_MISC; |
| 712 | |
| 713 | return CMD_SUCCESS; |
| 714 | } |
| 715 | |
| 716 | DEFUN (ip_irdp_debug_packet, |
| 717 | ip_irdp_debug_packet_cmd, |
| 718 | "ip irdp debug packet", |
| 719 | IP_STR |
| 720 | "ICMP Router discovery debug Averts. and Solicits (short)\n") |
| 721 | { |
| 722 | struct interface *ifp; |
| 723 | struct zebra_if *zi; |
| 724 | struct irdp_interface *irdp; |
| 725 | ifp = (struct interface *) vty->index; |
| 726 | if(!ifp) { |
| 727 | return CMD_WARNING; |
| 728 | } |
| 729 | |
| 730 | zi=ifp->info; |
| 731 | irdp=&zi->irdp; |
| 732 | |
| 733 | irdp->flags |= IF_DEBUG_PACKET; |
| 734 | |
| 735 | return CMD_SUCCESS; |
| 736 | } |
| 737 | |
| 738 | |
| 739 | DEFUN (ip_irdp_debug_disable, |
| 740 | ip_irdp_debug_disable_cmd, |
| 741 | "ip irdp debug disable", |
| 742 | IP_STR |
| 743 | "ICMP Router discovery debug Averts. and Solicits (short)\n") |
| 744 | { |
| 745 | struct interface *ifp; |
| 746 | struct zebra_if *zi; |
| 747 | struct irdp_interface *irdp; |
| 748 | ifp = (struct interface *) vty->index; |
| 749 | if(!ifp) { |
| 750 | return CMD_WARNING; |
| 751 | } |
| 752 | |
| 753 | zi=ifp->info; |
| 754 | irdp=&zi->irdp; |
| 755 | |
| 756 | irdp->flags &= ~IF_DEBUG_PACKET; |
| 757 | irdp->flags &= ~IF_DEBUG_MESSAGES; |
| 758 | irdp->flags &= ~IF_DEBUG_MISC; |
| 759 | |
| 760 | return CMD_SUCCESS; |
| 761 | } |
| 762 | |
| 763 | void |
| 764 | irdp_if_init () |
| 765 | { |
| 766 | install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd); |
| 767 | install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame^] | 768 | install_element (INTERFACE_NODE, &no_ip_irdp_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 769 | install_element (INTERFACE_NODE, &ip_irdp_shutdown_cmd); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame^] | 770 | install_element (INTERFACE_NODE, &no_ip_irdp_shutdown_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 771 | install_element (INTERFACE_NODE, &ip_irdp_holdtime_cmd); |
| 772 | install_element (INTERFACE_NODE, &ip_irdp_maxadvertinterval_cmd); |
| 773 | install_element (INTERFACE_NODE, &ip_irdp_minadvertinterval_cmd); |
| 774 | install_element (INTERFACE_NODE, &ip_irdp_preference_cmd); |
| 775 | install_element (INTERFACE_NODE, &ip_irdp_address_preference_cmd); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame^] | 776 | install_element (INTERFACE_NODE, &no_ip_irdp_address_preference_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 777 | |
| 778 | install_element (INTERFACE_NODE, &ip_irdp_debug_messages_cmd); |
| 779 | install_element (INTERFACE_NODE, &ip_irdp_debug_misc_cmd); |
| 780 | install_element (INTERFACE_NODE, &ip_irdp_debug_packet_cmd); |
| 781 | install_element (INTERFACE_NODE, &ip_irdp_debug_disable_cmd); |
| 782 | } |
| 783 | |
| 784 | #endif /* HAVE_IRDP */ |