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