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 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 77 | static struct prefix * |
| 78 | irdp_get_prefix(struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 79 | { |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 80 | struct listnode *node; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 81 | struct connected *ifc; |
| 82 | |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 83 | if (ifp->connected) |
| 84 | LIST_LOOP (ifp->connected, ifc, node) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 85 | return ifc->address; |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 86 | |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | /* Join to the add/leave multicast group. */ |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 91 | static int |
| 92 | if_group (struct interface *ifp, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 93 | int sock, |
| 94 | u_int32_t group, |
| 95 | int add_leave) |
| 96 | { |
| 97 | struct zebra_if *zi; |
| 98 | struct ip_mreq m; |
| 99 | struct prefix *p; |
| 100 | int ret; |
| 101 | |
| 102 | zi = ifp->info; |
| 103 | |
| 104 | bzero (&m, sizeof (m)); |
| 105 | m.imr_multiaddr.s_addr = htonl (group); |
| 106 | p = irdp_get_prefix(ifp); |
| 107 | |
| 108 | if(!p) { |
| 109 | zlog_warn ("IRDP: can't get address for %s", ifp->name); |
| 110 | return 1; |
| 111 | } |
| 112 | |
| 113 | m.imr_interface = p->u.prefix4; |
| 114 | |
| 115 | ret = setsockopt (sock, IPPROTO_IP, add_leave, |
| 116 | (char *) &m, sizeof (struct ip_mreq)); |
| 117 | if (ret < 0) |
| 118 | zlog_warn ("IRDP: %s can't setsockopt %s: %s", |
| 119 | add_leave == IP_ADD_MEMBERSHIP? "join group":"leave group", |
| 120 | inet_2a(group, b1), |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 121 | safe_strerror (errno)); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 126 | static int |
| 127 | if_add_group (struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 128 | { |
| 129 | struct zebra_if *zi= ifp->info; |
| 130 | struct irdp_interface *irdp = &zi->irdp; |
| 131 | int ret; |
| 132 | |
| 133 | ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_ADD_MEMBERSHIP); |
| 134 | if (ret < 0) { |
| 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | if(irdp->flags & IF_DEBUG_MISC ) |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 139 | zlog_debug("IRDP: Adding group %s for %s", |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 140 | inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1), |
| 141 | ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 142 | return 0; |
| 143 | } |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 144 | |
| 145 | static int |
| 146 | if_drop_group (struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 147 | { |
| 148 | struct zebra_if *zi= ifp->info; |
| 149 | struct irdp_interface *irdp = &zi->irdp; |
| 150 | int ret; |
| 151 | |
| 152 | ret = if_group (ifp, irdp_sock, INADDR_ALLRTRS_GROUP, IP_DROP_MEMBERSHIP); |
| 153 | if (ret < 0) |
| 154 | return ret; |
| 155 | |
| 156 | if(irdp->flags & IF_DEBUG_MISC) |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 157 | zlog_debug("IRDP: Leaving group %s for %s", |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 158 | inet_2a(htonl(INADDR_ALLRTRS_GROUP), b1), |
| 159 | ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 160 | return 0; |
| 161 | } |
| 162 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 163 | static void |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 164 | if_set_defaults(struct interface *ifp) |
| 165 | { |
| 166 | struct zebra_if *zi=ifp->info; |
| 167 | struct irdp_interface *irdp=&zi->irdp; |
| 168 | |
| 169 | irdp->MaxAdvertInterval = IRDP_MAXADVERTINTERVAL; |
| 170 | irdp->MinAdvertInterval = IRDP_MINADVERTINTERVAL; |
| 171 | irdp->Preference = IRDP_PREFERENCE; |
| 172 | irdp->Lifetime = IRDP_LIFETIME; |
| 173 | } |
| 174 | |
| 175 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 176 | struct Adv *Adv_new (void) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 177 | { |
| 178 | struct Adv *new; |
| 179 | new = XMALLOC (MTYPE_TMP, sizeof (struct Adv)); |
| 180 | memset (new, 0, sizeof (struct Adv)); |
| 181 | return new; |
| 182 | } |
| 183 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 184 | static void |
| 185 | Adv_free (struct Adv *adv) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 186 | { |
| 187 | XFREE (MTYPE_TMP, adv); |
| 188 | } |
| 189 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 190 | static void |
| 191 | irdp_if_start(struct interface *ifp, int multicast, int set_defaults) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 192 | { |
| 193 | struct zebra_if *zi= ifp->info; |
| 194 | struct irdp_interface *irdp = &zi->irdp; |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 195 | struct listnode *node; |
| 196 | struct connected *ifc; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 197 | u_int32_t timer, seed; |
| 198 | |
| 199 | if (irdp->flags & IF_ACTIVE ) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 200 | zlog_warn("IRDP: Interface is already active %s", ifp->name); |
| 201 | return; |
| 202 | } |
| 203 | if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) { |
| 204 | zlog_warn("IRDP: Cannot activate interface %s (cannot create " |
| 205 | "IRDP socket)", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 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)) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 216 | zlog_warn("IRDP: Interface is down %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 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))) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 225 | zlog_warn("IRDP: Interface not multicast enabled %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 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; |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 237 | if( ifp->connected) |
| 238 | LIST_LOOP (ifp->connected, ifc, node) |
| 239 | { |
| 240 | seed = ifc->address->u.prefix4.s_addr; |
| 241 | break; |
| 242 | } |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 243 | |
| 244 | srandom(seed); |
| 245 | timer = (random () % IRDP_DEFAULT_INTERVAL) + 1; |
| 246 | |
| 247 | irdp->AdvPrefList = list_new(); |
hasso | c9e52be | 2004-09-26 16:09:34 +0000 | [diff] [blame] | 248 | irdp->AdvPrefList->del = (void (*)(void *)) Adv_free; /* Destructor */ |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 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) |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 259 | zlog_debug("IRDP: Init timer for %s set to %u", |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 260 | ifp->name, |
| 261 | timer); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 262 | |
| 263 | irdp->t_advertise = thread_add_timer(zebrad.master, |
| 264 | irdp_send_thread, |
| 265 | ifp, |
| 266 | timer); |
| 267 | } |
| 268 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 269 | static void |
| 270 | irdp_if_stop(struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 271 | { |
| 272 | struct zebra_if *zi=ifp->info; |
| 273 | struct irdp_interface *irdp=&zi->irdp; |
| 274 | |
| 275 | if (irdp == NULL) { |
| 276 | zlog_warn ("Interface %s structure is NULL", ifp->name); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | if (! (irdp->flags & IF_ACTIVE )) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 281 | zlog_warn("Interface is not active %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
| 285 | if(! (irdp->flags & IF_BROADCAST)) |
| 286 | if_drop_group(ifp); |
| 287 | |
| 288 | irdp_advert_off(ifp); |
| 289 | |
| 290 | list_delete(irdp->AdvPrefList); |
| 291 | irdp->AdvPrefList=NULL; |
| 292 | |
| 293 | irdp->flags = 0; |
| 294 | } |
| 295 | |
| 296 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 297 | static void |
| 298 | irdp_if_shutdown(struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 299 | { |
| 300 | struct zebra_if *zi= ifp->info; |
| 301 | struct irdp_interface *irdp = &zi->irdp; |
| 302 | |
| 303 | if (irdp->flags & IF_SHUTDOWN ) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 304 | zlog_warn("IRDP: Interface is already shutdown %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 305 | return; |
| 306 | } |
| 307 | |
| 308 | irdp->flags |= IF_SHUTDOWN; |
| 309 | irdp->flags &= ~IF_ACTIVE; |
| 310 | |
| 311 | if(! (irdp->flags & IF_BROADCAST)) |
| 312 | if_drop_group(ifp); |
| 313 | |
| 314 | /* Tell the hosts we are out of service */ |
| 315 | irdp_advert_off(ifp); |
| 316 | } |
| 317 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 318 | static void |
| 319 | irdp_if_no_shutdown(struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 320 | { |
| 321 | struct zebra_if *zi= ifp->info; |
| 322 | struct irdp_interface *irdp = &zi->irdp; |
| 323 | |
| 324 | if (! (irdp->flags & IF_SHUTDOWN )) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 325 | zlog_warn("IRDP: Interface is not shutdown %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 326 | return; |
| 327 | } |
| 328 | |
| 329 | irdp->flags &= ~IF_SHUTDOWN; |
| 330 | |
| 331 | irdp_if_start(ifp, irdp->flags & IF_BROADCAST? FALSE : TRUE, FALSE); |
| 332 | |
| 333 | } |
| 334 | |
| 335 | |
| 336 | /* Write configuration to user */ |
| 337 | |
| 338 | void irdp_config_write (struct vty *vty, struct interface *ifp) |
| 339 | { |
| 340 | struct zebra_if *zi=ifp->info; |
| 341 | struct irdp_interface *irdp=&zi->irdp; |
| 342 | struct Adv *adv; |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 343 | struct listnode *node; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 344 | |
| 345 | if(irdp->flags & IF_ACTIVE || irdp->flags & IF_SHUTDOWN) { |
| 346 | |
| 347 | if( irdp->flags & IF_SHUTDOWN) |
| 348 | vty_out (vty, " ip irdp shutdown %s", VTY_NEWLINE); |
| 349 | |
| 350 | if( irdp->flags & IF_BROADCAST) |
| 351 | vty_out (vty, " ip irdp broadcast%s", VTY_NEWLINE); |
| 352 | else |
| 353 | vty_out (vty, " ip irdp multicast%s", VTY_NEWLINE); |
| 354 | |
| 355 | vty_out (vty, " ip irdp preference %ld%s", |
| 356 | irdp->Preference, VTY_NEWLINE); |
| 357 | |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 358 | LIST_LOOP (irdp->AdvPrefList, adv, node) |
| 359 | vty_out (vty, " ip irdp address %s preference %d%s", |
| 360 | inet_2a(adv->ip.s_addr, b1), |
| 361 | adv->pref, |
| 362 | VTY_NEWLINE); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 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", |
hasso | 8d0f15f | 2004-09-11 16:33:28 +0000 | [diff] [blame] | 414 | NO_STR |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 415 | IP_STR |
| 416 | "Disable ICMP Router discovery on this interface\n") |
| 417 | { |
| 418 | struct interface *ifp; |
| 419 | |
| 420 | ifp = (struct interface *) vty->index; |
| 421 | if(!ifp) { |
| 422 | return CMD_WARNING; |
| 423 | } |
| 424 | |
| 425 | irdp_if_stop(ifp); |
| 426 | return CMD_SUCCESS; |
| 427 | } |
| 428 | |
| 429 | DEFUN (ip_irdp_shutdown, |
| 430 | ip_irdp_shutdown_cmd, |
| 431 | "ip irdp shutdown", |
| 432 | IP_STR |
| 433 | "ICMP Router discovery shutdown on this interface\n") |
| 434 | { |
| 435 | struct interface *ifp; |
| 436 | |
| 437 | ifp = (struct interface *) vty->index; |
| 438 | if(!ifp) { |
| 439 | return CMD_WARNING; |
| 440 | } |
| 441 | |
| 442 | irdp_if_shutdown(ifp); |
| 443 | return CMD_SUCCESS; |
| 444 | } |
| 445 | |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 446 | DEFUN (no_ip_irdp_shutdown, |
| 447 | no_ip_irdp_shutdown_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 448 | "no ip irdp shutdown", |
hasso | 8d0f15f | 2004-09-11 16:33:28 +0000 | [diff] [blame] | 449 | NO_STR |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 450 | IP_STR |
| 451 | "ICMP Router discovery no shutdown on this interface\n") |
| 452 | { |
| 453 | struct interface *ifp; |
| 454 | |
| 455 | ifp = (struct interface *) vty->index; |
| 456 | if(!ifp) { |
| 457 | return CMD_WARNING; |
| 458 | } |
| 459 | |
| 460 | irdp_if_no_shutdown(ifp); |
| 461 | return CMD_SUCCESS; |
| 462 | } |
| 463 | |
| 464 | DEFUN (ip_irdp_holdtime, |
| 465 | ip_irdp_holdtime_cmd, |
| 466 | "ip irdp holdtime <0-9000>", |
| 467 | IP_STR |
| 468 | "ICMP Router discovery on this interface\n" |
| 469 | "Set holdtime value\n" |
| 470 | "Holdtime value in seconds. Default is 1800 seconds\n") |
| 471 | { |
| 472 | struct interface *ifp; |
| 473 | struct zebra_if *zi; |
| 474 | struct irdp_interface *irdp; |
| 475 | ifp = (struct interface *) vty->index; |
| 476 | if(!ifp) { |
| 477 | return CMD_WARNING; |
| 478 | } |
| 479 | |
| 480 | zi=ifp->info; |
| 481 | irdp=&zi->irdp; |
| 482 | |
| 483 | irdp->Lifetime = atoi(argv[0]); |
| 484 | return CMD_SUCCESS; |
| 485 | } |
| 486 | |
| 487 | DEFUN (ip_irdp_minadvertinterval, |
| 488 | ip_irdp_minadvertinterval_cmd, |
| 489 | "ip irdp minadvertinterval <3-1800>", |
| 490 | IP_STR |
| 491 | "ICMP Router discovery on this interface\n" |
| 492 | "Set minimum time between advertisement\n" |
| 493 | "Minimum advertisement interval in seconds\n") |
| 494 | { |
| 495 | struct interface *ifp; |
| 496 | struct zebra_if *zi; |
| 497 | struct irdp_interface *irdp; |
| 498 | ifp = (struct interface *) vty->index; |
| 499 | if(!ifp) { |
| 500 | return CMD_WARNING; |
| 501 | } |
| 502 | |
| 503 | zi=ifp->info; |
| 504 | irdp=&zi->irdp; |
| 505 | |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 506 | if( (unsigned) atoi(argv[0]) <= irdp->MaxAdvertInterval) { |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 507 | irdp->MinAdvertInterval = atoi(argv[0]); |
| 508 | |
| 509 | return CMD_SUCCESS; |
| 510 | } |
| 511 | |
| 512 | vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", |
| 513 | VTY_NEWLINE); |
| 514 | |
| 515 | vty_out (vty, "Please correct!%s", |
| 516 | VTY_NEWLINE); |
| 517 | return CMD_WARNING; |
| 518 | } |
| 519 | |
| 520 | DEFUN (ip_irdp_maxadvertinterval, |
| 521 | ip_irdp_maxadvertinterval_cmd, |
| 522 | "ip irdp maxadvertinterval <4-1800>", |
| 523 | IP_STR |
| 524 | "ICMP Router discovery on this interface\n" |
| 525 | "Set maximum time between advertisement\n" |
| 526 | "Maximum advertisement interval in seconds\n") |
| 527 | { |
| 528 | struct interface *ifp; |
| 529 | struct zebra_if *zi; |
| 530 | struct irdp_interface *irdp; |
| 531 | ifp = (struct interface *) vty->index; |
| 532 | if(!ifp) { |
| 533 | return CMD_WARNING; |
| 534 | } |
| 535 | |
| 536 | zi=ifp->info; |
| 537 | irdp=&zi->irdp; |
| 538 | |
| 539 | |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 540 | if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[0]) ) { |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 541 | irdp->MaxAdvertInterval = atoi(argv[0]); |
| 542 | |
| 543 | return CMD_SUCCESS; |
| 544 | } |
| 545 | |
| 546 | vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", |
| 547 | VTY_NEWLINE); |
| 548 | |
| 549 | vty_out (vty, "Please correct!%s", |
| 550 | VTY_NEWLINE); |
| 551 | return CMD_WARNING; |
| 552 | } |
| 553 | |
hasso | accb156 | 2004-11-25 19:21:07 +0000 | [diff] [blame] | 554 | /* DEFUN needs to be fixed for negative ranages... |
| 555 | * "ip irdp preference <-2147483648-2147483647>", |
| 556 | * Be positive for now. :-) |
| 557 | */ |
| 558 | |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 559 | DEFUN (ip_irdp_preference, |
| 560 | ip_irdp_preference_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 561 | "ip irdp preference <0-2147483647>", |
| 562 | IP_STR |
| 563 | "ICMP Router discovery on this interface\n" |
| 564 | "Set default preference level for this interface\n" |
| 565 | "Preference level\n") |
| 566 | { |
| 567 | struct interface *ifp; |
| 568 | struct zebra_if *zi; |
| 569 | struct irdp_interface *irdp; |
| 570 | ifp = (struct interface *) vty->index; |
| 571 | if(!ifp) { |
| 572 | return CMD_WARNING; |
| 573 | } |
| 574 | |
| 575 | zi=ifp->info; |
| 576 | irdp=&zi->irdp; |
| 577 | |
| 578 | irdp->Preference = atoi(argv[0]); |
| 579 | return CMD_SUCCESS; |
| 580 | } |
| 581 | |
| 582 | DEFUN (ip_irdp_address_preference, |
| 583 | ip_irdp_address_preference_cmd, |
| 584 | "ip irdp address A.B.C.D preference <0-2147483647>", |
| 585 | IP_STR |
| 586 | "Alter ICMP Router discovery preference this interface\n" |
| 587 | "Specify IRDP non-default preference to advertise\n" |
| 588 | "Set IRDP address for advertise\n" |
| 589 | "Preference level\n") |
| 590 | { |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 591 | struct listnode *node; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 592 | struct in_addr ip; |
| 593 | int pref; |
| 594 | int ret; |
| 595 | struct interface *ifp; |
| 596 | struct zebra_if *zi; |
| 597 | struct irdp_interface *irdp; |
| 598 | struct Adv *adv; |
| 599 | |
| 600 | ifp = (struct interface *) vty->index; |
| 601 | if(!ifp) { |
| 602 | return CMD_WARNING; |
| 603 | } |
| 604 | |
| 605 | zi=ifp->info; |
| 606 | irdp=&zi->irdp; |
| 607 | |
| 608 | ret = inet_aton(argv[0], &ip); |
| 609 | if(!ret) return CMD_WARNING; |
| 610 | |
| 611 | pref = atoi(argv[1]); |
| 612 | |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 613 | LIST_LOOP (irdp->AdvPrefList, adv, node) |
| 614 | if(adv->ip.s_addr == ip.s_addr) |
| 615 | return CMD_SUCCESS; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 616 | |
| 617 | adv = Adv_new(); |
| 618 | adv->ip = ip; |
| 619 | adv->pref = pref; |
| 620 | listnode_add(irdp->AdvPrefList, adv); |
| 621 | |
| 622 | return CMD_SUCCESS; |
| 623 | |
| 624 | } |
| 625 | |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 626 | DEFUN (no_ip_irdp_address_preference, |
| 627 | no_ip_irdp_address_preference_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 628 | "no ip irdp address A.B.C.D preference <0-2147483647>", |
hasso | 8d0f15f | 2004-09-11 16:33:28 +0000 | [diff] [blame] | 629 | NO_STR |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 630 | IP_STR |
| 631 | "Alter ICMP Router discovery preference this interface\n" |
| 632 | "Removes IRDP non-default preference\n" |
| 633 | "Select IRDP address\n" |
| 634 | "Old preference level\n") |
| 635 | { |
paul | 26f7a24 | 2004-09-24 08:45:10 +0000 | [diff] [blame] | 636 | struct listnode *node, *nnode; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 637 | struct in_addr ip; |
| 638 | int pref; |
| 639 | int ret; |
| 640 | struct interface *ifp; |
| 641 | struct zebra_if *zi; |
| 642 | struct irdp_interface *irdp; |
| 643 | struct Adv *adv; |
| 644 | |
| 645 | ifp = (struct interface *) vty->index; |
| 646 | if(!ifp) { |
| 647 | return CMD_WARNING; |
| 648 | } |
| 649 | |
| 650 | zi=ifp->info; |
| 651 | irdp=&zi->irdp; |
| 652 | |
| 653 | ret = inet_aton(argv[0], &ip); |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 654 | if (!ret) |
| 655 | return CMD_WARNING; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 656 | |
| 657 | pref = atoi(argv[1]); |
| 658 | |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 659 | for (node = listhead (irdp->AdvPrefList); node; node = nnode) |
| 660 | { |
| 661 | nnode = node->next; |
| 662 | adv = getdata (node); |
| 663 | |
| 664 | if(adv->ip.s_addr == ip.s_addr ) |
| 665 | { |
| 666 | listnode_delete(irdp->AdvPrefList, adv); |
| 667 | break; |
| 668 | } |
| 669 | } |
| 670 | |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 671 | return CMD_SUCCESS; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | DEFUN (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 | |
| 696 | DEFUN (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 | |
| 718 | DEFUN (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 | |
| 741 | DEFUN (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 | |
| 765 | void |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame^] | 766 | irdp_init () |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 767 | { |
| 768 | install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd); |
| 769 | install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 770 | install_element (INTERFACE_NODE, &no_ip_irdp_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 771 | install_element (INTERFACE_NODE, &ip_irdp_shutdown_cmd); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 772 | install_element (INTERFACE_NODE, &no_ip_irdp_shutdown_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 773 | 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); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 778 | install_element (INTERFACE_NODE, &no_ip_irdp_address_preference_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 779 | |
| 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 */ |