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) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 84 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) |
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 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 178 | return XCALLOC (MTYPE_TMP, sizeof (struct Adv)); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 179 | } |
| 180 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 181 | static void |
| 182 | Adv_free (struct Adv *adv) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 183 | { |
| 184 | XFREE (MTYPE_TMP, adv); |
| 185 | } |
| 186 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 187 | static void |
| 188 | irdp_if_start(struct interface *ifp, int multicast, int set_defaults) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 189 | { |
| 190 | struct zebra_if *zi= ifp->info; |
| 191 | struct irdp_interface *irdp = &zi->irdp; |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 192 | struct listnode *node; |
| 193 | struct connected *ifc; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 194 | u_int32_t timer, seed; |
| 195 | |
| 196 | if (irdp->flags & IF_ACTIVE ) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 197 | zlog_warn("IRDP: Interface is already active %s", ifp->name); |
| 198 | return; |
| 199 | } |
| 200 | if ((irdp_sock < 0) && ((irdp_sock = irdp_sock_init()) < 0)) { |
| 201 | zlog_warn("IRDP: Cannot activate interface %s (cannot create " |
| 202 | "IRDP socket)", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 203 | return; |
| 204 | } |
| 205 | irdp->flags |= IF_ACTIVE; |
| 206 | |
| 207 | if(!multicast) |
| 208 | irdp->flags |= IF_BROADCAST; |
| 209 | |
| 210 | if_add_update(ifp); |
| 211 | |
| 212 | if (! (ifp->flags & IFF_UP)) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 213 | zlog_warn("IRDP: Interface is down %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /* Shall we cancel if_start if if_add_group fails? */ |
| 217 | |
| 218 | if( multicast) { |
| 219 | if_add_group(ifp); |
| 220 | |
| 221 | if (! (ifp->flags & (IFF_MULTICAST|IFF_ALLMULTI))) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 222 | zlog_warn("IRDP: Interface not multicast enabled %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
| 226 | if(set_defaults) |
| 227 | if_set_defaults(ifp); |
| 228 | |
| 229 | irdp->irdp_sent = 0; |
| 230 | |
| 231 | /* The spec suggests this for randomness */ |
| 232 | |
| 233 | seed = 0; |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 234 | if( ifp->connected) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 235 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 236 | { |
| 237 | seed = ifc->address->u.prefix4.s_addr; |
| 238 | break; |
| 239 | } |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 240 | |
| 241 | srandom(seed); |
| 242 | timer = (random () % IRDP_DEFAULT_INTERVAL) + 1; |
| 243 | |
| 244 | irdp->AdvPrefList = list_new(); |
hasso | c9e52be | 2004-09-26 16:09:34 +0000 | [diff] [blame] | 245 | irdp->AdvPrefList->del = (void (*)(void *)) Adv_free; /* Destructor */ |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 246 | |
| 247 | |
| 248 | /* And this for startup. Speed limit from 1991 :-). But it's OK*/ |
| 249 | |
| 250 | if(irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS && |
| 251 | timer > MAX_INITIAL_ADVERT_INTERVAL ) |
| 252 | timer= MAX_INITIAL_ADVERT_INTERVAL; |
| 253 | |
| 254 | |
| 255 | if(irdp->flags & IF_DEBUG_MISC) |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 256 | zlog_debug("IRDP: Init timer for %s set to %u", |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 257 | ifp->name, |
| 258 | timer); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 259 | |
| 260 | irdp->t_advertise = thread_add_timer(zebrad.master, |
| 261 | irdp_send_thread, |
| 262 | ifp, |
| 263 | timer); |
| 264 | } |
| 265 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 266 | static void |
| 267 | irdp_if_stop(struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 268 | { |
| 269 | struct zebra_if *zi=ifp->info; |
| 270 | struct irdp_interface *irdp=&zi->irdp; |
| 271 | |
| 272 | if (irdp == NULL) { |
| 273 | zlog_warn ("Interface %s structure is NULL", ifp->name); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | if (! (irdp->flags & IF_ACTIVE )) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 278 | zlog_warn("Interface is not active %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 279 | return; |
| 280 | } |
| 281 | |
| 282 | if(! (irdp->flags & IF_BROADCAST)) |
| 283 | if_drop_group(ifp); |
| 284 | |
| 285 | irdp_advert_off(ifp); |
| 286 | |
| 287 | list_delete(irdp->AdvPrefList); |
| 288 | irdp->AdvPrefList=NULL; |
| 289 | |
| 290 | irdp->flags = 0; |
| 291 | } |
| 292 | |
| 293 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 294 | static void |
| 295 | irdp_if_shutdown(struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 296 | { |
| 297 | struct zebra_if *zi= ifp->info; |
| 298 | struct irdp_interface *irdp = &zi->irdp; |
| 299 | |
| 300 | if (irdp->flags & IF_SHUTDOWN ) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 301 | zlog_warn("IRDP: Interface is already shutdown %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 302 | return; |
| 303 | } |
| 304 | |
| 305 | irdp->flags |= IF_SHUTDOWN; |
| 306 | irdp->flags &= ~IF_ACTIVE; |
| 307 | |
| 308 | if(! (irdp->flags & IF_BROADCAST)) |
| 309 | if_drop_group(ifp); |
| 310 | |
| 311 | /* Tell the hosts we are out of service */ |
| 312 | irdp_advert_off(ifp); |
| 313 | } |
| 314 | |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 315 | static void |
| 316 | irdp_if_no_shutdown(struct interface *ifp) |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 317 | { |
| 318 | struct zebra_if *zi= ifp->info; |
| 319 | struct irdp_interface *irdp = &zi->irdp; |
| 320 | |
| 321 | if (! (irdp->flags & IF_SHUTDOWN )) { |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 322 | zlog_warn("IRDP: Interface is not shutdown %s", ifp->name); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 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; |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 340 | struct listnode *node; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 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 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 355 | for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv)) |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 356 | vty_out (vty, " ip irdp address %s preference %d%s", |
| 357 | inet_2a(adv->ip.s_addr, b1), |
| 358 | adv->pref, |
| 359 | VTY_NEWLINE); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 360 | |
| 361 | vty_out (vty, " ip irdp holdtime %d%s", |
| 362 | irdp->Lifetime, VTY_NEWLINE); |
| 363 | |
| 364 | vty_out (vty, " ip irdp minadvertinterval %ld%s", |
| 365 | irdp->MinAdvertInterval, VTY_NEWLINE); |
| 366 | |
| 367 | vty_out (vty, " ip irdp maxadvertinterval %ld%s", |
| 368 | irdp->MaxAdvertInterval, VTY_NEWLINE); |
| 369 | |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | |
| 374 | DEFUN (ip_irdp_multicast, |
| 375 | ip_irdp_multicast_cmd, |
| 376 | "ip irdp multicast", |
| 377 | IP_STR |
| 378 | "ICMP Router discovery on this interface using multicast\n") |
| 379 | { |
| 380 | struct interface *ifp; |
| 381 | |
| 382 | ifp = (struct interface *) vty->index; |
| 383 | if(!ifp) { |
| 384 | return CMD_WARNING; |
| 385 | } |
| 386 | |
| 387 | irdp_if_start(ifp, TRUE, TRUE); |
| 388 | return CMD_SUCCESS; |
| 389 | } |
| 390 | |
| 391 | DEFUN (ip_irdp_broadcast, |
| 392 | ip_irdp_broadcast_cmd, |
| 393 | "ip irdp broadcast", |
| 394 | IP_STR |
| 395 | "ICMP Router discovery on this interface using broadcast\n") |
| 396 | { |
| 397 | struct interface *ifp; |
| 398 | |
| 399 | ifp = (struct interface *) vty->index; |
| 400 | if(!ifp) { |
| 401 | return CMD_WARNING; |
| 402 | } |
| 403 | |
| 404 | irdp_if_start(ifp, FALSE, TRUE); |
| 405 | return CMD_SUCCESS; |
| 406 | } |
| 407 | |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 408 | DEFUN (no_ip_irdp, |
| 409 | no_ip_irdp_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 410 | "no ip irdp", |
hasso | 8d0f15f | 2004-09-11 16:33:28 +0000 | [diff] [blame] | 411 | NO_STR |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 412 | IP_STR |
| 413 | "Disable ICMP Router discovery on this interface\n") |
| 414 | { |
| 415 | struct interface *ifp; |
| 416 | |
| 417 | ifp = (struct interface *) vty->index; |
| 418 | if(!ifp) { |
| 419 | return CMD_WARNING; |
| 420 | } |
| 421 | |
| 422 | irdp_if_stop(ifp); |
| 423 | return CMD_SUCCESS; |
| 424 | } |
| 425 | |
| 426 | DEFUN (ip_irdp_shutdown, |
| 427 | ip_irdp_shutdown_cmd, |
| 428 | "ip irdp shutdown", |
| 429 | IP_STR |
| 430 | "ICMP Router discovery shutdown on this interface\n") |
| 431 | { |
| 432 | struct interface *ifp; |
| 433 | |
| 434 | ifp = (struct interface *) vty->index; |
| 435 | if(!ifp) { |
| 436 | return CMD_WARNING; |
| 437 | } |
| 438 | |
| 439 | irdp_if_shutdown(ifp); |
| 440 | return CMD_SUCCESS; |
| 441 | } |
| 442 | |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 443 | DEFUN (no_ip_irdp_shutdown, |
| 444 | no_ip_irdp_shutdown_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 445 | "no ip irdp shutdown", |
hasso | 8d0f15f | 2004-09-11 16:33:28 +0000 | [diff] [blame] | 446 | NO_STR |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 447 | IP_STR |
| 448 | "ICMP Router discovery no shutdown on this interface\n") |
| 449 | { |
| 450 | struct interface *ifp; |
| 451 | |
| 452 | ifp = (struct interface *) vty->index; |
| 453 | if(!ifp) { |
| 454 | return CMD_WARNING; |
| 455 | } |
| 456 | |
| 457 | irdp_if_no_shutdown(ifp); |
| 458 | return CMD_SUCCESS; |
| 459 | } |
| 460 | |
| 461 | DEFUN (ip_irdp_holdtime, |
| 462 | ip_irdp_holdtime_cmd, |
| 463 | "ip irdp holdtime <0-9000>", |
| 464 | IP_STR |
| 465 | "ICMP Router discovery on this interface\n" |
| 466 | "Set holdtime value\n" |
| 467 | "Holdtime value in seconds. Default is 1800 seconds\n") |
| 468 | { |
| 469 | struct interface *ifp; |
| 470 | struct zebra_if *zi; |
| 471 | struct irdp_interface *irdp; |
| 472 | ifp = (struct interface *) vty->index; |
| 473 | if(!ifp) { |
| 474 | return CMD_WARNING; |
| 475 | } |
| 476 | |
| 477 | zi=ifp->info; |
| 478 | irdp=&zi->irdp; |
| 479 | |
| 480 | irdp->Lifetime = atoi(argv[0]); |
| 481 | return CMD_SUCCESS; |
| 482 | } |
| 483 | |
| 484 | DEFUN (ip_irdp_minadvertinterval, |
| 485 | ip_irdp_minadvertinterval_cmd, |
| 486 | "ip irdp minadvertinterval <3-1800>", |
| 487 | IP_STR |
| 488 | "ICMP Router discovery on this interface\n" |
| 489 | "Set minimum time between advertisement\n" |
| 490 | "Minimum advertisement interval in seconds\n") |
| 491 | { |
| 492 | struct interface *ifp; |
| 493 | struct zebra_if *zi; |
| 494 | struct irdp_interface *irdp; |
| 495 | ifp = (struct interface *) vty->index; |
| 496 | if(!ifp) { |
| 497 | return CMD_WARNING; |
| 498 | } |
| 499 | |
| 500 | zi=ifp->info; |
| 501 | irdp=&zi->irdp; |
| 502 | |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 503 | if( (unsigned) atoi(argv[0]) <= irdp->MaxAdvertInterval) { |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 504 | irdp->MinAdvertInterval = atoi(argv[0]); |
| 505 | |
| 506 | return CMD_SUCCESS; |
| 507 | } |
| 508 | |
| 509 | vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", |
| 510 | VTY_NEWLINE); |
| 511 | |
| 512 | vty_out (vty, "Please correct!%s", |
| 513 | VTY_NEWLINE); |
| 514 | return CMD_WARNING; |
| 515 | } |
| 516 | |
| 517 | DEFUN (ip_irdp_maxadvertinterval, |
| 518 | ip_irdp_maxadvertinterval_cmd, |
| 519 | "ip irdp maxadvertinterval <4-1800>", |
| 520 | IP_STR |
| 521 | "ICMP Router discovery on this interface\n" |
| 522 | "Set maximum time between advertisement\n" |
| 523 | "Maximum advertisement interval in seconds\n") |
| 524 | { |
| 525 | struct interface *ifp; |
| 526 | struct zebra_if *zi; |
| 527 | struct irdp_interface *irdp; |
| 528 | ifp = (struct interface *) vty->index; |
| 529 | if(!ifp) { |
| 530 | return CMD_WARNING; |
| 531 | } |
| 532 | |
| 533 | zi=ifp->info; |
| 534 | irdp=&zi->irdp; |
| 535 | |
| 536 | |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 537 | if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[0]) ) { |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 538 | irdp->MaxAdvertInterval = atoi(argv[0]); |
| 539 | |
| 540 | return CMD_SUCCESS; |
| 541 | } |
| 542 | |
| 543 | vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", |
| 544 | VTY_NEWLINE); |
| 545 | |
| 546 | vty_out (vty, "Please correct!%s", |
| 547 | VTY_NEWLINE); |
| 548 | return CMD_WARNING; |
| 549 | } |
| 550 | |
hasso | accb156 | 2004-11-25 19:21:07 +0000 | [diff] [blame] | 551 | /* DEFUN needs to be fixed for negative ranages... |
| 552 | * "ip irdp preference <-2147483648-2147483647>", |
| 553 | * Be positive for now. :-) |
| 554 | */ |
| 555 | |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 556 | DEFUN (ip_irdp_preference, |
| 557 | ip_irdp_preference_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 558 | "ip irdp preference <0-2147483647>", |
| 559 | IP_STR |
| 560 | "ICMP Router discovery on this interface\n" |
| 561 | "Set default preference level for this interface\n" |
| 562 | "Preference level\n") |
| 563 | { |
| 564 | struct interface *ifp; |
| 565 | struct zebra_if *zi; |
| 566 | struct irdp_interface *irdp; |
| 567 | ifp = (struct interface *) vty->index; |
| 568 | if(!ifp) { |
| 569 | return CMD_WARNING; |
| 570 | } |
| 571 | |
| 572 | zi=ifp->info; |
| 573 | irdp=&zi->irdp; |
| 574 | |
| 575 | irdp->Preference = atoi(argv[0]); |
| 576 | return CMD_SUCCESS; |
| 577 | } |
| 578 | |
| 579 | DEFUN (ip_irdp_address_preference, |
| 580 | ip_irdp_address_preference_cmd, |
| 581 | "ip irdp address A.B.C.D preference <0-2147483647>", |
| 582 | IP_STR |
| 583 | "Alter ICMP Router discovery preference this interface\n" |
| 584 | "Specify IRDP non-default preference to advertise\n" |
| 585 | "Set IRDP address for advertise\n" |
| 586 | "Preference level\n") |
| 587 | { |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 588 | struct listnode *node; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 589 | struct in_addr ip; |
| 590 | int pref; |
| 591 | int ret; |
| 592 | struct interface *ifp; |
| 593 | struct zebra_if *zi; |
| 594 | struct irdp_interface *irdp; |
| 595 | struct Adv *adv; |
| 596 | |
| 597 | ifp = (struct interface *) vty->index; |
| 598 | if(!ifp) { |
| 599 | return CMD_WARNING; |
| 600 | } |
| 601 | |
| 602 | zi=ifp->info; |
| 603 | irdp=&zi->irdp; |
| 604 | |
| 605 | ret = inet_aton(argv[0], &ip); |
| 606 | if(!ret) return CMD_WARNING; |
| 607 | |
| 608 | pref = atoi(argv[1]); |
| 609 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 610 | for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv)) |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 611 | if(adv->ip.s_addr == ip.s_addr) |
| 612 | return CMD_SUCCESS; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 613 | |
| 614 | adv = Adv_new(); |
| 615 | adv->ip = ip; |
| 616 | adv->pref = pref; |
| 617 | listnode_add(irdp->AdvPrefList, adv); |
| 618 | |
| 619 | return CMD_SUCCESS; |
| 620 | |
| 621 | } |
| 622 | |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 623 | DEFUN (no_ip_irdp_address_preference, |
| 624 | no_ip_irdp_address_preference_cmd, |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 625 | "no ip irdp address A.B.C.D preference <0-2147483647>", |
hasso | 8d0f15f | 2004-09-11 16:33:28 +0000 | [diff] [blame] | 626 | NO_STR |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 627 | IP_STR |
| 628 | "Alter ICMP Router discovery preference this interface\n" |
| 629 | "Removes IRDP non-default preference\n" |
| 630 | "Select IRDP address\n" |
| 631 | "Old preference level\n") |
| 632 | { |
paul | 26f7a24 | 2004-09-24 08:45:10 +0000 | [diff] [blame] | 633 | struct listnode *node, *nnode; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 634 | struct in_addr ip; |
| 635 | int pref; |
| 636 | int ret; |
| 637 | struct interface *ifp; |
| 638 | struct zebra_if *zi; |
| 639 | struct irdp_interface *irdp; |
| 640 | struct Adv *adv; |
| 641 | |
| 642 | ifp = (struct interface *) vty->index; |
| 643 | if(!ifp) { |
| 644 | return CMD_WARNING; |
| 645 | } |
| 646 | |
| 647 | zi=ifp->info; |
| 648 | irdp=&zi->irdp; |
| 649 | |
| 650 | ret = inet_aton(argv[0], &ip); |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 651 | if (!ret) |
| 652 | return CMD_WARNING; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 653 | |
| 654 | pref = atoi(argv[1]); |
| 655 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 656 | for (ALL_LIST_ELEMENTS (irdp->AdvPrefList, node, nnode, adv)) |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 657 | { |
paul | 0c0f911 | 2004-09-24 08:24:42 +0000 | [diff] [blame] | 658 | if(adv->ip.s_addr == ip.s_addr ) |
| 659 | { |
| 660 | listnode_delete(irdp->AdvPrefList, adv); |
| 661 | break; |
| 662 | } |
| 663 | } |
| 664 | |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 665 | return CMD_SUCCESS; |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | DEFUN (ip_irdp_debug_messages, |
| 669 | ip_irdp_debug_messages_cmd, |
| 670 | "ip irdp debug messages", |
| 671 | IP_STR |
| 672 | "ICMP Router discovery debug Averts. and Solicits (short)\n") |
| 673 | { |
| 674 | struct interface *ifp; |
| 675 | struct zebra_if *zi; |
| 676 | struct irdp_interface *irdp; |
| 677 | ifp = (struct interface *) vty->index; |
| 678 | if(!ifp) { |
| 679 | return CMD_WARNING; |
| 680 | } |
| 681 | |
| 682 | zi=ifp->info; |
| 683 | irdp=&zi->irdp; |
| 684 | |
| 685 | irdp->flags |= IF_DEBUG_MESSAGES; |
| 686 | |
| 687 | return CMD_SUCCESS; |
| 688 | } |
| 689 | |
| 690 | DEFUN (ip_irdp_debug_misc, |
| 691 | ip_irdp_debug_misc_cmd, |
| 692 | "ip irdp debug misc", |
| 693 | IP_STR |
| 694 | "ICMP Router discovery debug Averts. and Solicits (short)\n") |
| 695 | { |
| 696 | struct interface *ifp; |
| 697 | struct zebra_if *zi; |
| 698 | struct irdp_interface *irdp; |
| 699 | ifp = (struct interface *) vty->index; |
| 700 | if(!ifp) { |
| 701 | return CMD_WARNING; |
| 702 | } |
| 703 | |
| 704 | zi=ifp->info; |
| 705 | irdp=&zi->irdp; |
| 706 | |
| 707 | irdp->flags |= IF_DEBUG_MISC; |
| 708 | |
| 709 | return CMD_SUCCESS; |
| 710 | } |
| 711 | |
| 712 | DEFUN (ip_irdp_debug_packet, |
| 713 | ip_irdp_debug_packet_cmd, |
| 714 | "ip irdp debug packet", |
| 715 | IP_STR |
| 716 | "ICMP Router discovery debug Averts. and Solicits (short)\n") |
| 717 | { |
| 718 | struct interface *ifp; |
| 719 | struct zebra_if *zi; |
| 720 | struct irdp_interface *irdp; |
| 721 | ifp = (struct interface *) vty->index; |
| 722 | if(!ifp) { |
| 723 | return CMD_WARNING; |
| 724 | } |
| 725 | |
| 726 | zi=ifp->info; |
| 727 | irdp=&zi->irdp; |
| 728 | |
| 729 | irdp->flags |= IF_DEBUG_PACKET; |
| 730 | |
| 731 | return CMD_SUCCESS; |
| 732 | } |
| 733 | |
| 734 | |
| 735 | DEFUN (ip_irdp_debug_disable, |
| 736 | ip_irdp_debug_disable_cmd, |
| 737 | "ip irdp debug disable", |
| 738 | IP_STR |
| 739 | "ICMP Router discovery debug Averts. and Solicits (short)\n") |
| 740 | { |
| 741 | struct interface *ifp; |
| 742 | struct zebra_if *zi; |
| 743 | struct irdp_interface *irdp; |
| 744 | ifp = (struct interface *) vty->index; |
| 745 | if(!ifp) { |
| 746 | return CMD_WARNING; |
| 747 | } |
| 748 | |
| 749 | zi=ifp->info; |
| 750 | irdp=&zi->irdp; |
| 751 | |
| 752 | irdp->flags &= ~IF_DEBUG_PACKET; |
| 753 | irdp->flags &= ~IF_DEBUG_MESSAGES; |
| 754 | irdp->flags &= ~IF_DEBUG_MISC; |
| 755 | |
| 756 | return CMD_SUCCESS; |
| 757 | } |
| 758 | |
| 759 | void |
ajs | 2da40f4 | 2005-03-30 16:33:13 +0000 | [diff] [blame] | 760 | irdp_init () |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 761 | { |
| 762 | install_element (INTERFACE_NODE, &ip_irdp_broadcast_cmd); |
| 763 | install_element (INTERFACE_NODE, &ip_irdp_multicast_cmd); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 764 | install_element (INTERFACE_NODE, &no_ip_irdp_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 765 | install_element (INTERFACE_NODE, &ip_irdp_shutdown_cmd); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 766 | install_element (INTERFACE_NODE, &no_ip_irdp_shutdown_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 767 | install_element (INTERFACE_NODE, &ip_irdp_holdtime_cmd); |
| 768 | install_element (INTERFACE_NODE, &ip_irdp_maxadvertinterval_cmd); |
| 769 | install_element (INTERFACE_NODE, &ip_irdp_minadvertinterval_cmd); |
| 770 | install_element (INTERFACE_NODE, &ip_irdp_preference_cmd); |
| 771 | install_element (INTERFACE_NODE, &ip_irdp_address_preference_cmd); |
hasso | 996933f | 2004-07-12 16:32:56 +0000 | [diff] [blame] | 772 | install_element (INTERFACE_NODE, &no_ip_irdp_address_preference_cmd); |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 773 | |
| 774 | install_element (INTERFACE_NODE, &ip_irdp_debug_messages_cmd); |
| 775 | install_element (INTERFACE_NODE, &ip_irdp_debug_misc_cmd); |
| 776 | install_element (INTERFACE_NODE, &ip_irdp_debug_packet_cmd); |
| 777 | install_element (INTERFACE_NODE, &ip_irdp_debug_disable_cmd); |
| 778 | } |
| 779 | |
| 780 | #endif /* HAVE_IRDP */ |