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