paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Interface related function for RIP. |
| 2 | * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org> |
| 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | * 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <zebra.h> |
| 23 | |
| 24 | #include "command.h" |
| 25 | #include "if.h" |
| 26 | #include "sockunion.h" |
| 27 | #include "prefix.h" |
| 28 | #include "memory.h" |
| 29 | #include "network.h" |
| 30 | #include "table.h" |
| 31 | #include "log.h" |
| 32 | #include "stream.h" |
| 33 | #include "thread.h" |
| 34 | #include "zclient.h" |
| 35 | #include "filter.h" |
| 36 | #include "sockopt.h" |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 37 | #include "privs.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 38 | |
| 39 | #include "zebra/connected.h" |
| 40 | |
| 41 | #include "ripd/ripd.h" |
| 42 | #include "ripd/rip_debug.h" |
| 43 | |
| 44 | void rip_enable_apply (struct interface *); |
| 45 | void rip_passive_interface_apply (struct interface *); |
| 46 | int rip_if_down(struct interface *ifp); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 47 | int rip_enable_if_lookup (char *ifname); |
| 48 | int rip_enable_network_lookup2 (struct connected *connected); |
| 49 | void rip_enable_apply_all (); |
| 50 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 51 | |
| 52 | struct message ri_version_msg[] = |
| 53 | { |
| 54 | {RI_RIP_VERSION_1, "1"}, |
| 55 | {RI_RIP_VERSION_2, "2"}, |
| 56 | {RI_RIP_VERSION_1_AND_2, "1 2"}, |
| 57 | {0, NULL} |
| 58 | }; |
| 59 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 60 | extern struct zebra_privs_t ripd_privs; |
| 61 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 62 | /* RIP enabled network vector. */ |
| 63 | vector rip_enable_interface; |
| 64 | |
| 65 | /* RIP enabled interface table. */ |
| 66 | struct route_table *rip_enable_network; |
| 67 | |
| 68 | /* Vector to store passive-interface name. */ |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 69 | static int passive_default; /* are we in passive-interface default mode? */ |
| 70 | vector Vrip_passive_nondefault; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 71 | |
| 72 | /* Join to the RIP version 2 multicast group. */ |
| 73 | int |
| 74 | ipv4_multicast_join (int sock, |
| 75 | struct in_addr group, |
| 76 | struct in_addr ifa, |
| 77 | unsigned int ifindex) |
| 78 | { |
| 79 | int ret; |
| 80 | |
| 81 | ret = setsockopt_multicast_ipv4 (sock, |
| 82 | IP_ADD_MEMBERSHIP, |
| 83 | ifa, |
| 84 | group.s_addr, |
| 85 | ifindex); |
| 86 | |
| 87 | if (ret < 0) |
| 88 | zlog (NULL, LOG_INFO, "can't setsockopt IP_ADD_MEMBERSHIP %s", |
| 89 | strerror (errno)); |
| 90 | |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | /* Leave from the RIP version 2 multicast group. */ |
| 95 | int |
| 96 | ipv4_multicast_leave (int sock, |
| 97 | struct in_addr group, |
| 98 | struct in_addr ifa, |
| 99 | unsigned int ifindex) |
| 100 | { |
| 101 | int ret; |
| 102 | |
| 103 | ret = setsockopt_multicast_ipv4 (sock, |
| 104 | IP_DROP_MEMBERSHIP, |
| 105 | ifa, |
| 106 | group.s_addr, |
| 107 | ifindex); |
| 108 | |
| 109 | if (ret < 0) |
| 110 | zlog (NULL, LOG_INFO, "can't setsockopt IP_DROP_MEMBERSHIP"); |
| 111 | |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | /* Allocate new RIP's interface configuration. */ |
| 116 | struct rip_interface * |
| 117 | rip_interface_new () |
| 118 | { |
| 119 | struct rip_interface *ri; |
| 120 | |
| 121 | ri = XMALLOC (MTYPE_RIP_INTERFACE, sizeof (struct rip_interface)); |
| 122 | memset (ri, 0, sizeof (struct rip_interface)); |
| 123 | |
| 124 | /* Default authentication type is simple password for Cisco |
| 125 | compatibility. */ |
| 126 | /* ri->auth_type = RIP_NO_AUTH; */ |
| 127 | ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD; |
| 128 | |
| 129 | /* Set default split-horizon behavior. If the interface is Frame |
| 130 | Relay or SMDS is enabled, the default value for split-horizon is |
| 131 | off. But currently Zebra does detect Frame Relay or SMDS |
| 132 | interface. So all interface is set to split horizon. */ |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 133 | ri->split_horizon_default = RIP_SPLIT_HORIZON; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 134 | ri->split_horizon = ri->split_horizon_default; |
| 135 | |
| 136 | return ri; |
| 137 | } |
| 138 | |
| 139 | void |
paul | cc1131a | 2003-10-15 23:20:17 +0000 | [diff] [blame] | 140 | rip_interface_multicast_set (int sock, struct connected *connected, |
| 141 | int if_pointopoint) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 142 | { |
| 143 | int ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 144 | struct servent *sp; |
| 145 | struct sockaddr_in from; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 146 | struct in_addr addr; |
paul | cc1131a | 2003-10-15 23:20:17 +0000 | [diff] [blame] | 147 | struct prefix_ipv4 *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 148 | |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame^] | 149 | if (connected != NULL) |
| 150 | { |
paul | cc1131a | 2003-10-15 23:20:17 +0000 | [diff] [blame] | 151 | if (if_pointopoint) |
| 152 | p = (struct prefix_ipv4 *) connected->destination; |
| 153 | else |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 154 | p = (struct prefix_ipv4 *) connected->address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 155 | addr = p->prefix; |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame^] | 156 | } |
| 157 | else |
| 158 | { |
| 159 | addr.s_addr = INADDR_ANY; |
| 160 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 161 | |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame^] | 162 | if (setsockopt_multicast_ipv4 (sock, IP_MULTICAST_IF, addr, 0, 0) < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 163 | { |
| 164 | zlog_warn ("Can't setsockopt IP_MULTICAST_IF to fd %d", sock); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | /* Bind myself. */ |
| 169 | memset (&from, 0, sizeof (struct sockaddr_in)); |
| 170 | |
| 171 | /* Set RIP port. */ |
| 172 | sp = getservbyname ("router", "udp"); |
| 173 | if (sp) |
| 174 | from.sin_port = sp->s_port; |
| 175 | else |
| 176 | from.sin_port = htons (RIP_PORT_DEFAULT); |
| 177 | |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame^] | 178 | /* Address should be any address. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 179 | from.sin_family = AF_INET; |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame^] | 180 | if (connected) |
paul | cc1131a | 2003-10-15 23:20:17 +0000 | [diff] [blame] | 181 | addr = ((struct prefix_ipv4 *) connected->address)->prefix; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 182 | from.sin_addr = addr; |
| 183 | #ifdef HAVE_SIN_LEN |
| 184 | from.sin_len = sizeof (struct sockaddr_in); |
| 185 | #endif /* HAVE_SIN_LEN */ |
| 186 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 187 | if (ripd_privs.change (ZPRIVS_RAISE)) |
| 188 | zlog_err ("rip_interface_multicast_set: could not raise privs"); |
| 189 | |
paul | cc1131a | 2003-10-15 23:20:17 +0000 | [diff] [blame] | 190 | ret = bind (sock, (struct sockaddr *) & from, sizeof (struct sockaddr_in)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 191 | if (ret < 0) |
| 192 | { |
| 193 | zlog_warn ("Can't bind socket: %s", strerror (errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 194 | } |
| 195 | |
paul | edd7c24 | 2003-06-04 13:59:38 +0000 | [diff] [blame] | 196 | if (ripd_privs.change (ZPRIVS_LOWER)) |
| 197 | zlog_err ("rip_interface_multicast_set: could not lower privs"); |
| 198 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 199 | return; |
| 200 | |
| 201 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 202 | |
| 203 | /* Send RIP request packet to specified interface. */ |
| 204 | void |
| 205 | rip_request_interface_send (struct interface *ifp, u_char version) |
| 206 | { |
| 207 | struct sockaddr_in to; |
| 208 | |
| 209 | /* RIPv2 support multicast. */ |
| 210 | if (version == RIPv2 && if_is_multicast (ifp)) |
| 211 | { |
| 212 | |
| 213 | if (IS_RIP_DEBUG_EVENT) |
| 214 | zlog_info ("multicast request on %s", ifp->name); |
| 215 | |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame^] | 216 | rip_request_send (NULL, ifp, version, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 217 | return; |
| 218 | } |
| 219 | |
| 220 | /* RIPv1 and non multicast interface. */ |
| 221 | if (if_is_pointopoint (ifp) || if_is_broadcast (ifp)) |
| 222 | { |
| 223 | listnode cnode; |
| 224 | |
| 225 | if (IS_RIP_DEBUG_EVENT) |
| 226 | zlog_info ("broadcast request to %s", ifp->name); |
| 227 | |
| 228 | for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) |
| 229 | { |
| 230 | struct prefix_ipv4 *p; |
| 231 | struct connected *connected; |
| 232 | |
| 233 | connected = getdata (cnode); |
| 234 | p = (struct prefix_ipv4 *) connected->destination; |
| 235 | |
| 236 | if (p->family == AF_INET) |
| 237 | { |
| 238 | memset (&to, 0, sizeof (struct sockaddr_in)); |
| 239 | to.sin_port = htons (RIP_PORT_DEFAULT); |
| 240 | to.sin_addr = p->prefix; |
| 241 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 242 | if (IS_RIP_DEBUG_EVENT) |
| 243 | zlog_info ("SEND request to %s", inet_ntoa (to.sin_addr)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 244 | |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame^] | 245 | rip_request_send (&to, ifp, version, connected); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /* This will be executed when interface goes up. */ |
| 252 | void |
| 253 | rip_request_interface (struct interface *ifp) |
| 254 | { |
| 255 | struct rip_interface *ri; |
| 256 | |
| 257 | /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */ |
| 258 | if (if_is_loopback (ifp)) |
| 259 | return; |
| 260 | |
| 261 | /* If interface is down, don't send RIP packet. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 262 | if (! if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 263 | return; |
| 264 | |
| 265 | /* Fetch RIP interface information. */ |
| 266 | ri = ifp->info; |
| 267 | |
| 268 | |
| 269 | /* If there is no version configuration in the interface, |
| 270 | use rip's version setting. */ |
paul | f38a471 | 2003-06-07 01:10:00 +0000 | [diff] [blame] | 271 | { |
| 272 | int vsend = ((ri->ri_send == RI_RIP_UNSPEC) ? |
| 273 | rip->version_send : ri->ri_send); |
| 274 | if (vsend & RIPv1) |
| 275 | rip_request_interface_send (ifp, RIPv1); |
| 276 | if (vsend & RIPv2) |
| 277 | rip_request_interface_send (ifp, RIPv2); |
| 278 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /* Send RIP request to the neighbor. */ |
| 282 | void |
| 283 | rip_request_neighbor (struct in_addr addr) |
| 284 | { |
| 285 | struct sockaddr_in to; |
| 286 | |
| 287 | memset (&to, 0, sizeof (struct sockaddr_in)); |
| 288 | to.sin_port = htons (RIP_PORT_DEFAULT); |
| 289 | to.sin_addr = addr; |
| 290 | |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame^] | 291 | rip_request_send (&to, NULL, rip->version_send, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* Request routes at all interfaces. */ |
| 295 | void |
| 296 | rip_request_neighbor_all () |
| 297 | { |
| 298 | struct route_node *rp; |
| 299 | |
| 300 | if (! rip) |
| 301 | return; |
| 302 | |
| 303 | if (IS_RIP_DEBUG_EVENT) |
| 304 | zlog_info ("request to the all neighbor"); |
| 305 | |
| 306 | /* Send request to all neighbor. */ |
| 307 | for (rp = route_top (rip->neighbor); rp; rp = route_next (rp)) |
| 308 | if (rp->info) |
| 309 | rip_request_neighbor (rp->p.u.prefix4); |
| 310 | } |
| 311 | |
| 312 | /* Multicast packet receive socket. */ |
| 313 | int |
| 314 | rip_multicast_join (struct interface *ifp, int sock) |
| 315 | { |
| 316 | listnode cnode; |
| 317 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 318 | if (if_is_operative (ifp) && if_is_multicast (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 319 | { |
| 320 | if (IS_RIP_DEBUG_EVENT) |
| 321 | zlog_info ("multicast join at %s", ifp->name); |
| 322 | |
| 323 | for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) |
| 324 | { |
| 325 | struct prefix_ipv4 *p; |
| 326 | struct connected *connected; |
| 327 | struct in_addr group; |
| 328 | |
| 329 | connected = getdata (cnode); |
| 330 | p = (struct prefix_ipv4 *) connected->address; |
| 331 | |
| 332 | if (p->family != AF_INET) |
| 333 | continue; |
| 334 | |
| 335 | group.s_addr = htonl (INADDR_RIP_GROUP); |
| 336 | if (ipv4_multicast_join (sock, group, p->prefix, ifp->ifindex) < 0) |
| 337 | return -1; |
| 338 | else |
| 339 | return 0; |
| 340 | } |
| 341 | } |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | /* Leave from multicast group. */ |
| 346 | void |
| 347 | rip_multicast_leave (struct interface *ifp, int sock) |
| 348 | { |
| 349 | listnode cnode; |
| 350 | |
| 351 | if (if_is_up (ifp) && if_is_multicast (ifp)) |
| 352 | { |
| 353 | if (IS_RIP_DEBUG_EVENT) |
| 354 | zlog_info ("multicast leave from %s", ifp->name); |
| 355 | |
| 356 | for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) |
| 357 | { |
| 358 | struct prefix_ipv4 *p; |
| 359 | struct connected *connected; |
| 360 | struct in_addr group; |
| 361 | |
| 362 | connected = getdata (cnode); |
| 363 | p = (struct prefix_ipv4 *) connected->address; |
| 364 | |
| 365 | if (p->family != AF_INET) |
| 366 | continue; |
| 367 | |
| 368 | group.s_addr = htonl (INADDR_RIP_GROUP); |
| 369 | if (ipv4_multicast_leave (sock, group, p->prefix, ifp->ifindex) == 0) |
| 370 | return; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /* Is there and address on interface that I could use ? */ |
| 376 | int |
| 377 | rip_if_ipv4_address_check (struct interface *ifp) |
| 378 | { |
| 379 | struct listnode *nn; |
| 380 | struct connected *connected; |
| 381 | int count = 0; |
| 382 | |
| 383 | for (nn = listhead (ifp->connected); nn; nextnode (nn)) |
| 384 | if ((connected = getdata (nn)) != NULL) |
| 385 | { |
| 386 | struct prefix *p; |
| 387 | |
| 388 | p = connected->address; |
| 389 | |
| 390 | if (p->family == AF_INET) |
| 391 | { |
| 392 | count++; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | return count; |
| 397 | } |
paul | 31a476c | 2003-09-29 19:54:53 +0000 | [diff] [blame] | 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | /* Does this address belongs to me ? */ |
| 403 | int |
| 404 | if_check_address (struct in_addr addr) |
| 405 | { |
| 406 | listnode node; |
| 407 | |
| 408 | for (node = listhead (iflist); node; nextnode (node)) |
| 409 | { |
| 410 | listnode cnode; |
| 411 | struct interface *ifp; |
| 412 | |
| 413 | ifp = getdata (node); |
| 414 | |
| 415 | for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) |
| 416 | { |
| 417 | struct connected *connected; |
| 418 | struct prefix_ipv4 *p; |
| 419 | |
| 420 | connected = getdata (cnode); |
| 421 | p = (struct prefix_ipv4 *) connected->address; |
| 422 | |
| 423 | if (p->family != AF_INET) |
| 424 | continue; |
| 425 | |
| 426 | if (IPV4_ADDR_CMP (&p->prefix, &addr) == 0) |
| 427 | return 1; |
| 428 | } |
| 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | /* is this address from a valid neighbor? (RFC2453 - Sec. 3.9.2) */ |
| 434 | int |
| 435 | if_valid_neighbor (struct in_addr addr) |
| 436 | { |
| 437 | listnode node; |
| 438 | struct connected *connected = NULL; |
| 439 | struct prefix_ipv4 *p; |
| 440 | |
| 441 | for (node = listhead (iflist); node; nextnode (node)) |
| 442 | { |
| 443 | listnode cnode; |
| 444 | struct interface *ifp; |
| 445 | |
| 446 | ifp = getdata (node); |
| 447 | |
| 448 | for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) |
| 449 | { |
| 450 | struct prefix *pxn = NULL; /* Prefix of the neighbor */ |
| 451 | struct prefix *pxc = NULL; /* Prefix of the connected network */ |
| 452 | |
| 453 | connected = getdata (cnode); |
| 454 | |
| 455 | if (if_is_pointopoint (ifp)) |
| 456 | { |
| 457 | p = (struct prefix_ipv4 *) connected->address; |
| 458 | |
| 459 | if (p && p->family == AF_INET) |
| 460 | { |
| 461 | if (IPV4_ADDR_SAME (&p->prefix, &addr)) |
| 462 | return 1; |
| 463 | |
| 464 | p = (struct prefix_ipv4 *) connected->destination; |
| 465 | if (p && IPV4_ADDR_SAME (&p->prefix, &addr)) |
| 466 | return 1; |
| 467 | } |
| 468 | } |
| 469 | else |
| 470 | { |
| 471 | p = (struct prefix_ipv4 *) connected->address; |
| 472 | |
| 473 | if (p->family != AF_INET) |
| 474 | continue; |
| 475 | |
| 476 | pxn = prefix_new(); |
| 477 | pxn->family = AF_INET; |
| 478 | pxn->prefixlen = 32; |
| 479 | pxn->u.prefix4 = addr; |
| 480 | |
| 481 | pxc = prefix_new(); |
| 482 | prefix_copy(pxc, (struct prefix *) p); |
| 483 | apply_mask(pxc); |
| 484 | |
| 485 | if (prefix_match (pxc, pxn)) |
| 486 | { |
| 487 | prefix_free (pxn); |
| 488 | prefix_free (pxc); |
| 489 | return 1; |
| 490 | } |
| 491 | prefix_free(pxc); |
| 492 | prefix_free(pxn); |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | return 0; |
| 497 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 498 | |
| 499 | /* Inteface link down message processing. */ |
| 500 | int |
| 501 | rip_interface_down (int command, struct zclient *zclient, zebra_size_t length) |
| 502 | { |
| 503 | struct interface *ifp; |
| 504 | struct stream *s; |
| 505 | |
| 506 | s = zclient->ibuf; |
| 507 | |
| 508 | /* zebra_interface_state_read() updates interface structure in |
| 509 | iflist. */ |
| 510 | ifp = zebra_interface_state_read(s); |
| 511 | |
| 512 | if (ifp == NULL) |
| 513 | return 0; |
| 514 | |
| 515 | rip_if_down(ifp); |
| 516 | |
| 517 | if (IS_RIP_DEBUG_ZEBRA) |
| 518 | zlog_info ("interface %s index %d flags %ld metric %d mtu %d is down", |
| 519 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | /* Inteface link up message processing */ |
| 525 | int |
| 526 | rip_interface_up (int command, struct zclient *zclient, zebra_size_t length) |
| 527 | { |
| 528 | struct interface *ifp; |
| 529 | |
| 530 | /* zebra_interface_state_read () updates interface structure in |
| 531 | iflist. */ |
| 532 | ifp = zebra_interface_state_read (zclient->ibuf); |
| 533 | |
| 534 | if (ifp == NULL) |
| 535 | return 0; |
| 536 | |
| 537 | if (IS_RIP_DEBUG_ZEBRA) |
| 538 | zlog_info ("interface %s index %d flags %ld metric %d mtu %d is up", |
| 539 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); |
| 540 | |
| 541 | /* Check if this interface is RIP enabled or not.*/ |
| 542 | rip_enable_apply (ifp); |
| 543 | |
| 544 | /* Check for a passive interface */ |
| 545 | rip_passive_interface_apply (ifp); |
| 546 | |
| 547 | /* Apply distribute list to the all interface. */ |
| 548 | rip_distribute_update_interface (ifp); |
| 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | /* Inteface addition message from zebra. */ |
| 554 | int |
| 555 | rip_interface_add (int command, struct zclient *zclient, zebra_size_t length) |
| 556 | { |
| 557 | struct interface *ifp; |
| 558 | |
| 559 | ifp = zebra_interface_add_read (zclient->ibuf); |
| 560 | |
| 561 | if (IS_RIP_DEBUG_ZEBRA) |
| 562 | zlog_info ("interface add %s index %d flags %ld metric %d mtu %d", |
| 563 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); |
| 564 | |
| 565 | /* Check if this interface is RIP enabled or not.*/ |
| 566 | rip_enable_apply (ifp); |
| 567 | |
| 568 | /* Apply distribute list to the all interface. */ |
| 569 | rip_distribute_update_interface (ifp); |
| 570 | |
| 571 | /* rip_request_neighbor_all (); */ |
| 572 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 573 | /* Check interface routemap. */ |
| 574 | rip_if_rmap_update_interface (ifp); |
| 575 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | int |
| 580 | rip_interface_delete (int command, struct zclient *zclient, |
| 581 | zebra_size_t length) |
| 582 | { |
| 583 | struct interface *ifp; |
| 584 | struct stream *s; |
| 585 | |
| 586 | |
| 587 | s = zclient->ibuf; |
| 588 | /* zebra_interface_state_read() updates interface structure in iflist */ |
| 589 | ifp = zebra_interface_state_read(s); |
| 590 | |
| 591 | if (ifp == NULL) |
| 592 | return 0; |
| 593 | |
| 594 | if (if_is_up (ifp)) { |
| 595 | rip_if_down(ifp); |
| 596 | } |
| 597 | |
| 598 | zlog_info("interface delete %s index %d flags %ld metric %d mtu %d", |
| 599 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); |
| 600 | |
| 601 | /* To support pseudo interface do not free interface structure. */ |
| 602 | /* if_delete(ifp); */ |
| 603 | |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | void |
| 608 | rip_interface_clean () |
| 609 | { |
| 610 | listnode node; |
| 611 | struct interface *ifp; |
| 612 | struct rip_interface *ri; |
| 613 | |
| 614 | for (node = listhead (iflist); node; nextnode (node)) |
| 615 | { |
| 616 | ifp = getdata (node); |
| 617 | ri = ifp->info; |
| 618 | |
| 619 | ri->enable_network = 0; |
| 620 | ri->enable_interface = 0; |
| 621 | ri->running = 0; |
| 622 | |
| 623 | if (ri->t_wakeup) |
| 624 | { |
| 625 | thread_cancel (ri->t_wakeup); |
| 626 | ri->t_wakeup = NULL; |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | void |
| 632 | rip_interface_reset () |
| 633 | { |
| 634 | listnode node; |
| 635 | struct interface *ifp; |
| 636 | struct rip_interface *ri; |
| 637 | |
| 638 | for (node = listhead (iflist); node; nextnode (node)) |
| 639 | { |
| 640 | ifp = getdata (node); |
| 641 | ri = ifp->info; |
| 642 | |
| 643 | ri->enable_network = 0; |
| 644 | ri->enable_interface = 0; |
| 645 | ri->running = 0; |
| 646 | |
| 647 | ri->ri_send = RI_RIP_UNSPEC; |
| 648 | ri->ri_receive = RI_RIP_UNSPEC; |
| 649 | |
| 650 | /* ri->auth_type = RIP_NO_AUTH; */ |
| 651 | ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD; |
| 652 | |
| 653 | if (ri->auth_str) |
| 654 | { |
| 655 | free (ri->auth_str); |
| 656 | ri->auth_str = NULL; |
| 657 | } |
| 658 | if (ri->key_chain) |
| 659 | { |
| 660 | free (ri->key_chain); |
| 661 | ri->key_chain = NULL; |
| 662 | } |
| 663 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 664 | ri->split_horizon = RIP_NO_SPLIT_HORIZON; |
| 665 | ri->split_horizon_default = RIP_NO_SPLIT_HORIZON; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 666 | |
| 667 | ri->list[RIP_FILTER_IN] = NULL; |
| 668 | ri->list[RIP_FILTER_OUT] = NULL; |
| 669 | |
| 670 | ri->prefix[RIP_FILTER_IN] = NULL; |
| 671 | ri->prefix[RIP_FILTER_OUT] = NULL; |
| 672 | |
| 673 | if (ri->t_wakeup) |
| 674 | { |
| 675 | thread_cancel (ri->t_wakeup); |
| 676 | ri->t_wakeup = NULL; |
| 677 | } |
| 678 | |
| 679 | ri->recv_badpackets = 0; |
| 680 | ri->recv_badroutes = 0; |
| 681 | ri->sent_updates = 0; |
| 682 | |
| 683 | ri->passive = 0; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | int |
| 688 | rip_if_down(struct interface *ifp) |
| 689 | { |
| 690 | struct route_node *rp; |
| 691 | struct rip_info *rinfo; |
| 692 | struct rip_interface *ri = NULL; |
| 693 | if (rip) |
| 694 | { |
| 695 | for (rp = route_top (rip->table); rp; rp = route_next (rp)) |
| 696 | if ((rinfo = rp->info) != NULL) |
| 697 | { |
| 698 | /* Routes got through this interface. */ |
| 699 | if (rinfo->ifindex == ifp->ifindex && |
| 700 | rinfo->type == ZEBRA_ROUTE_RIP && |
| 701 | rinfo->sub_type == RIP_ROUTE_RTE) |
| 702 | { |
| 703 | rip_zebra_ipv4_delete ((struct prefix_ipv4 *) &rp->p, |
| 704 | &rinfo->nexthop, |
| 705 | rinfo->ifindex); |
| 706 | |
| 707 | rip_redistribute_delete (rinfo->type,rinfo->sub_type, |
| 708 | (struct prefix_ipv4 *)&rp->p, |
| 709 | rinfo->ifindex); |
| 710 | } |
| 711 | else |
| 712 | { |
| 713 | /* All redistributed routes but static and system */ |
| 714 | if ((rinfo->ifindex == ifp->ifindex) && |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 715 | /* (rinfo->type != ZEBRA_ROUTE_STATIC) && */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 716 | (rinfo->type != ZEBRA_ROUTE_SYSTEM)) |
| 717 | rip_redistribute_delete (rinfo->type,rinfo->sub_type, |
| 718 | (struct prefix_ipv4 *)&rp->p, |
| 719 | rinfo->ifindex); |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | ri = ifp->info; |
| 725 | |
| 726 | if (ri->running) |
| 727 | { |
| 728 | if (IS_RIP_DEBUG_EVENT) |
| 729 | zlog_info ("turn off %s", ifp->name); |
| 730 | |
| 731 | /* Leave from multicast group. */ |
| 732 | rip_multicast_leave (ifp, rip->sock); |
| 733 | |
| 734 | ri->running = 0; |
| 735 | } |
| 736 | |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | /* Needed for stop RIP process. */ |
| 741 | void |
| 742 | rip_if_down_all () |
| 743 | { |
| 744 | struct interface *ifp; |
| 745 | listnode node; |
| 746 | |
| 747 | for (node = listhead (iflist); node; nextnode (node)) |
| 748 | { |
| 749 | ifp = getdata (node); |
| 750 | rip_if_down (ifp); |
| 751 | } |
| 752 | } |
| 753 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 754 | static void |
| 755 | rip_apply_address_add (struct connected *ifc) { |
| 756 | struct prefix_ipv4 address; |
| 757 | struct prefix *p; |
| 758 | |
| 759 | if (!rip) |
| 760 | return; |
| 761 | |
| 762 | if (! if_is_up(ifc->ifp)) |
| 763 | return; |
| 764 | |
| 765 | p = ifc->address; |
| 766 | |
| 767 | memset (&address, 0, sizeof (address)); |
| 768 | address.family = p->family; |
| 769 | address.prefix = p->u.prefix4; |
| 770 | address.prefixlen = p->prefixlen; |
| 771 | apply_mask_ipv4(&address); |
| 772 | |
| 773 | /* Check if this interface is RIP enabled or not |
| 774 | or Check if this address's prefix is RIP enabled */ |
| 775 | if ((rip_enable_if_lookup(ifc->ifp->name) >= 0) || |
| 776 | (rip_enable_network_lookup2(ifc) >= 0)) |
| 777 | rip_redistribute_add(ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, |
| 778 | &address, ifc->ifp->ifindex, NULL); |
| 779 | |
| 780 | } |
| 781 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 782 | int |
| 783 | rip_interface_address_add (int command, struct zclient *zclient, |
| 784 | zebra_size_t length) |
| 785 | { |
| 786 | struct connected *ifc; |
| 787 | struct prefix *p; |
| 788 | |
| 789 | ifc = zebra_interface_address_add_read (zclient->ibuf); |
| 790 | |
| 791 | if (ifc == NULL) |
| 792 | return 0; |
| 793 | |
| 794 | p = ifc->address; |
| 795 | |
| 796 | if (p->family == AF_INET) |
| 797 | { |
| 798 | if (IS_RIP_DEBUG_ZEBRA) |
| 799 | zlog_info ("connected address %s/%d is added", |
| 800 | inet_ntoa (p->u.prefix4), p->prefixlen); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 801 | |
paul | 878ef2e | 2003-09-23 23:41:50 +0000 | [diff] [blame] | 802 | rip_enable_apply(ifc->ifp); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 803 | /* Check if this prefix needs to be redistributed */ |
| 804 | rip_apply_address_add(ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 805 | |
| 806 | #ifdef HAVE_SNMP |
| 807 | rip_ifaddr_add (ifc->ifp, ifc); |
| 808 | #endif /* HAVE_SNMP */ |
| 809 | } |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 814 | static void |
| 815 | rip_apply_address_del (struct connected *ifc) { |
| 816 | struct prefix_ipv4 address; |
| 817 | struct prefix *p; |
| 818 | |
| 819 | if (!rip) |
| 820 | return; |
| 821 | |
| 822 | if (! if_is_up(ifc->ifp)) |
| 823 | return; |
| 824 | |
| 825 | p = ifc->address; |
| 826 | |
| 827 | memset (&address, 0, sizeof (address)); |
| 828 | address.family = p->family; |
| 829 | address.prefix = p->u.prefix4; |
| 830 | address.prefixlen = p->prefixlen; |
| 831 | apply_mask_ipv4(&address); |
| 832 | |
| 833 | rip_redistribute_delete(ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, |
| 834 | &address, ifc->ifp->ifindex); |
| 835 | } |
| 836 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 837 | int |
| 838 | rip_interface_address_delete (int command, struct zclient *zclient, |
| 839 | zebra_size_t length) |
| 840 | { |
| 841 | struct connected *ifc; |
| 842 | struct prefix *p; |
| 843 | |
| 844 | ifc = zebra_interface_address_delete_read (zclient->ibuf); |
| 845 | |
| 846 | if (ifc) |
| 847 | { |
| 848 | p = ifc->address; |
| 849 | if (p->family == AF_INET) |
| 850 | { |
| 851 | if (IS_RIP_DEBUG_ZEBRA) |
| 852 | |
| 853 | zlog_info ("connected address %s/%d is deleted", |
| 854 | inet_ntoa (p->u.prefix4), p->prefixlen); |
| 855 | |
| 856 | #ifdef HAVE_SNMP |
| 857 | rip_ifaddr_delete (ifc->ifp, ifc); |
| 858 | #endif /* HAVE_SNMP */ |
| 859 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 860 | /* Chech wether this prefix needs to be removed */ |
| 861 | rip_apply_address_del(ifc); |
| 862 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | connected_free (ifc); |
| 866 | |
| 867 | } |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | /* Check interface is enabled by network statement. */ |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 873 | /* Check wether the interface has at least a connected prefix that |
| 874 | * is within the ripng_enable_network table. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 875 | int |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 876 | rip_enable_network_lookup_if (struct interface *ifp) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 877 | { |
| 878 | struct listnode *nn; |
| 879 | struct connected *connected; |
| 880 | struct prefix_ipv4 address; |
| 881 | |
| 882 | for (nn = listhead (ifp->connected); nn; nextnode (nn)) |
| 883 | if ((connected = getdata (nn)) != NULL) |
| 884 | { |
| 885 | struct prefix *p; |
| 886 | struct route_node *node; |
| 887 | |
| 888 | p = connected->address; |
| 889 | |
| 890 | if (p->family == AF_INET) |
| 891 | { |
| 892 | address.family = AF_INET; |
| 893 | address.prefix = p->u.prefix4; |
| 894 | address.prefixlen = IPV4_MAX_BITLEN; |
| 895 | |
| 896 | node = route_node_match (rip_enable_network, |
| 897 | (struct prefix *)&address); |
| 898 | if (node) |
| 899 | { |
| 900 | route_unlock_node (node); |
| 901 | return 1; |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | return -1; |
| 906 | } |
| 907 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 908 | /* Check wether connected is within the ripng_enable_network table. */ |
| 909 | int |
| 910 | rip_enable_network_lookup2 (struct connected *connected) |
| 911 | { |
| 912 | struct prefix_ipv4 address; |
| 913 | struct prefix *p; |
| 914 | |
| 915 | p = connected->address; |
| 916 | |
| 917 | if (p->family == AF_INET) { |
| 918 | struct route_node *node; |
| 919 | |
| 920 | address.family = p->family; |
| 921 | address.prefix = p->u.prefix4; |
| 922 | address.prefixlen = IPV4_MAX_BITLEN; |
| 923 | |
| 924 | /* LPM on p->family, p->u.prefix4/IPV4_MAX_BITLEN within rip_enable_network */ |
| 925 | node = route_node_match (rip_enable_network, |
| 926 | (struct prefix *)&address); |
| 927 | |
| 928 | if (node) { |
| 929 | route_unlock_node (node); |
| 930 | return 1; |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | return -1; |
| 935 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 936 | /* Add RIP enable network. */ |
| 937 | int |
| 938 | rip_enable_network_add (struct prefix *p) |
| 939 | { |
| 940 | struct route_node *node; |
| 941 | |
| 942 | node = route_node_get (rip_enable_network, p); |
| 943 | |
| 944 | if (node->info) |
| 945 | { |
| 946 | route_unlock_node (node); |
| 947 | return -1; |
| 948 | } |
| 949 | else |
| 950 | node->info = "enabled"; |
| 951 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 952 | /* XXX: One should find a better solution than a generic one */ |
| 953 | rip_enable_apply_all(); |
| 954 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 955 | return 1; |
| 956 | } |
| 957 | |
| 958 | /* Delete RIP enable network. */ |
| 959 | int |
| 960 | rip_enable_network_delete (struct prefix *p) |
| 961 | { |
| 962 | struct route_node *node; |
| 963 | |
| 964 | node = route_node_lookup (rip_enable_network, p); |
| 965 | if (node) |
| 966 | { |
| 967 | node->info = NULL; |
| 968 | |
| 969 | /* Unlock info lock. */ |
| 970 | route_unlock_node (node); |
| 971 | |
| 972 | /* Unlock lookup lock. */ |
| 973 | route_unlock_node (node); |
| 974 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 975 | /* XXX: One should find a better solution than a generic one */ |
| 976 | rip_enable_apply_all (); |
| 977 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 978 | return 1; |
| 979 | } |
| 980 | return -1; |
| 981 | } |
| 982 | |
| 983 | /* Check interface is enabled by ifname statement. */ |
| 984 | int |
| 985 | rip_enable_if_lookup (char *ifname) |
| 986 | { |
| 987 | int i; |
| 988 | char *str; |
| 989 | |
| 990 | for (i = 0; i < vector_max (rip_enable_interface); i++) |
| 991 | if ((str = vector_slot (rip_enable_interface, i)) != NULL) |
| 992 | if (strcmp (str, ifname) == 0) |
| 993 | return i; |
| 994 | return -1; |
| 995 | } |
| 996 | |
| 997 | /* Add interface to rip_enable_if. */ |
| 998 | int |
| 999 | rip_enable_if_add (char *ifname) |
| 1000 | { |
| 1001 | int ret; |
| 1002 | |
| 1003 | ret = rip_enable_if_lookup (ifname); |
| 1004 | if (ret >= 0) |
| 1005 | return -1; |
| 1006 | |
| 1007 | vector_set (rip_enable_interface, strdup (ifname)); |
| 1008 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1009 | rip_enable_apply_all(); /* TODOVJ */ |
| 1010 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1011 | return 1; |
| 1012 | } |
| 1013 | |
| 1014 | /* Delete interface from rip_enable_if. */ |
| 1015 | int |
| 1016 | rip_enable_if_delete (char *ifname) |
| 1017 | { |
| 1018 | int index; |
| 1019 | char *str; |
| 1020 | |
| 1021 | index = rip_enable_if_lookup (ifname); |
| 1022 | if (index < 0) |
| 1023 | return -1; |
| 1024 | |
| 1025 | str = vector_slot (rip_enable_interface, index); |
| 1026 | free (str); |
| 1027 | vector_unset (rip_enable_interface, index); |
| 1028 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1029 | rip_enable_apply_all(); /* TODOVJ */ |
| 1030 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1031 | return 1; |
| 1032 | } |
| 1033 | |
| 1034 | /* Join to multicast group and send request to the interface. */ |
| 1035 | int |
| 1036 | rip_interface_wakeup (struct thread *t) |
| 1037 | { |
| 1038 | struct interface *ifp; |
| 1039 | struct rip_interface *ri; |
| 1040 | |
| 1041 | /* Get interface. */ |
| 1042 | ifp = THREAD_ARG (t); |
| 1043 | |
| 1044 | ri = ifp->info; |
| 1045 | ri->t_wakeup = NULL; |
| 1046 | |
| 1047 | /* Join to multicast group. */ |
| 1048 | if (rip_multicast_join (ifp, rip->sock) < 0) |
| 1049 | { |
| 1050 | zlog_err ("multicast join failed, interface %s not running", ifp->name); |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | /* Set running flag. */ |
| 1055 | ri->running = 1; |
| 1056 | |
| 1057 | /* Send RIP request to the interface. */ |
| 1058 | rip_request_interface (ifp); |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | int rip_redistribute_check (int); |
| 1064 | |
| 1065 | void |
| 1066 | rip_connect_set (struct interface *ifp, int set) |
| 1067 | { |
| 1068 | struct listnode *nn; |
| 1069 | struct connected *connected; |
| 1070 | struct prefix_ipv4 address; |
| 1071 | |
| 1072 | for (nn = listhead (ifp->connected); nn; nextnode (nn)) |
| 1073 | if ((connected = getdata (nn)) != NULL) |
| 1074 | { |
| 1075 | struct prefix *p; |
| 1076 | p = connected->address; |
| 1077 | |
| 1078 | if (p->family != AF_INET) |
| 1079 | continue; |
| 1080 | |
| 1081 | address.family = AF_INET; |
| 1082 | address.prefix = p->u.prefix4; |
| 1083 | address.prefixlen = p->prefixlen; |
| 1084 | apply_mask_ipv4 (&address); |
| 1085 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1086 | if (set) { |
| 1087 | /* Check once more wether this prefix is within a "network IF_OR_PREF" one */ |
| 1088 | if ((rip_enable_if_lookup(connected->ifp->name) >= 0) || |
| 1089 | (rip_enable_network_lookup2(connected) >= 0)) |
| 1090 | rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, |
| 1091 | &address, connected->ifp->ifindex, NULL); |
| 1092 | } else |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1093 | { |
| 1094 | rip_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, |
| 1095 | &address, connected->ifp->ifindex); |
| 1096 | if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT)) |
| 1097 | rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_REDISTRIBUTE, |
| 1098 | &address, connected->ifp->ifindex, NULL); |
| 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | /* Update interface status. */ |
| 1104 | void |
| 1105 | rip_enable_apply (struct interface *ifp) |
| 1106 | { |
| 1107 | int ret; |
| 1108 | struct rip_interface *ri = NULL; |
| 1109 | |
| 1110 | /* Check interface. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1111 | if (! if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1112 | return; |
| 1113 | |
| 1114 | ri = ifp->info; |
| 1115 | |
| 1116 | /* Check network configuration. */ |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1117 | ret = rip_enable_network_lookup_if (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1118 | |
| 1119 | /* If the interface is matched. */ |
| 1120 | if (ret > 0) |
| 1121 | ri->enable_network = 1; |
| 1122 | else |
| 1123 | ri->enable_network = 0; |
| 1124 | |
| 1125 | /* Check interface name configuration. */ |
| 1126 | ret = rip_enable_if_lookup (ifp->name); |
| 1127 | if (ret >= 0) |
| 1128 | ri->enable_interface = 1; |
| 1129 | else |
| 1130 | ri->enable_interface = 0; |
| 1131 | |
| 1132 | /* any interface MUST have an IPv4 address */ |
| 1133 | if ( ! rip_if_ipv4_address_check (ifp) ) |
| 1134 | { |
| 1135 | ri->enable_network = 0; |
| 1136 | ri->enable_interface = 0; |
| 1137 | } |
| 1138 | |
| 1139 | /* Update running status of the interface. */ |
| 1140 | if (ri->enable_network || ri->enable_interface) |
| 1141 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1142 | { |
| 1143 | if (IS_RIP_DEBUG_EVENT) |
| 1144 | zlog_info ("turn on %s", ifp->name); |
| 1145 | |
| 1146 | /* Add interface wake up thread. */ |
| 1147 | if (! ri->t_wakeup) |
| 1148 | ri->t_wakeup = thread_add_timer (master, rip_interface_wakeup, |
| 1149 | ifp, 1); |
| 1150 | rip_connect_set (ifp, 1); |
| 1151 | } |
| 1152 | } |
| 1153 | else |
| 1154 | { |
| 1155 | if (ri->running) |
| 1156 | { |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1157 | /* Might as well clean up the route table as well |
| 1158 | * rip_if_down sets to 0 ri->running, and displays "turn off %s" |
| 1159 | **/ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1160 | rip_if_down(ifp); |
| 1161 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1162 | rip_connect_set (ifp, 0); |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | /* Apply network configuration to all interface. */ |
| 1168 | void |
| 1169 | rip_enable_apply_all () |
| 1170 | { |
| 1171 | struct interface *ifp; |
| 1172 | listnode node; |
| 1173 | |
| 1174 | /* Check each interface. */ |
| 1175 | for (node = listhead (iflist); node; nextnode (node)) |
| 1176 | { |
| 1177 | ifp = getdata (node); |
| 1178 | rip_enable_apply (ifp); |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | int |
| 1183 | rip_neighbor_lookup (struct sockaddr_in *from) |
| 1184 | { |
| 1185 | struct prefix_ipv4 p; |
| 1186 | struct route_node *node; |
| 1187 | |
| 1188 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 1189 | p.family = AF_INET; |
| 1190 | p.prefix = from->sin_addr; |
| 1191 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1192 | |
| 1193 | node = route_node_lookup (rip->neighbor, (struct prefix *) &p); |
| 1194 | if (node) |
| 1195 | { |
| 1196 | route_unlock_node (node); |
| 1197 | return 1; |
| 1198 | } |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
| 1202 | /* Add new RIP neighbor to the neighbor tree. */ |
| 1203 | int |
| 1204 | rip_neighbor_add (struct prefix_ipv4 *p) |
| 1205 | { |
| 1206 | struct route_node *node; |
| 1207 | |
| 1208 | node = route_node_get (rip->neighbor, (struct prefix *) p); |
| 1209 | |
| 1210 | if (node->info) |
| 1211 | return -1; |
| 1212 | |
| 1213 | node->info = rip->neighbor; |
| 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | /* Delete RIP neighbor from the neighbor tree. */ |
| 1219 | int |
| 1220 | rip_neighbor_delete (struct prefix_ipv4 *p) |
| 1221 | { |
| 1222 | struct route_node *node; |
| 1223 | |
| 1224 | /* Lock for look up. */ |
| 1225 | node = route_node_lookup (rip->neighbor, (struct prefix *) p); |
| 1226 | if (! node) |
| 1227 | return -1; |
| 1228 | |
| 1229 | node->info = NULL; |
| 1230 | |
| 1231 | /* Unlock lookup lock. */ |
| 1232 | route_unlock_node (node); |
| 1233 | |
| 1234 | /* Unlock real neighbor information lock. */ |
| 1235 | route_unlock_node (node); |
| 1236 | |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | /* Clear all network and neighbor configuration. */ |
| 1241 | void |
| 1242 | rip_clean_network () |
| 1243 | { |
| 1244 | int i; |
| 1245 | char *str; |
| 1246 | struct route_node *rn; |
| 1247 | |
| 1248 | /* rip_enable_network. */ |
| 1249 | for (rn = route_top (rip_enable_network); rn; rn = route_next (rn)) |
| 1250 | if (rn->info) |
| 1251 | { |
| 1252 | rn->info = NULL; |
| 1253 | route_unlock_node (rn); |
| 1254 | } |
| 1255 | |
| 1256 | /* rip_enable_interface. */ |
| 1257 | for (i = 0; i < vector_max (rip_enable_interface); i++) |
| 1258 | if ((str = vector_slot (rip_enable_interface, i)) != NULL) |
| 1259 | { |
| 1260 | free (str); |
| 1261 | vector_slot (rip_enable_interface, i) = NULL; |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | /* Utility function for looking up passive interface settings. */ |
| 1266 | int |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1267 | rip_passive_nondefault_lookup (char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1268 | { |
| 1269 | int i; |
| 1270 | char *str; |
| 1271 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1272 | for (i = 0; i < vector_max (Vrip_passive_nondefault); i++) |
| 1273 | if ((str = vector_slot (Vrip_passive_nondefault, i)) != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1274 | if (strcmp (str, ifname) == 0) |
| 1275 | return i; |
| 1276 | return -1; |
| 1277 | } |
| 1278 | |
| 1279 | void |
| 1280 | rip_passive_interface_apply (struct interface *ifp) |
| 1281 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1282 | struct rip_interface *ri; |
| 1283 | |
| 1284 | ri = ifp->info; |
| 1285 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1286 | ri->passive = ((rip_passive_nondefault_lookup (ifp->name) < 0) ? |
| 1287 | passive_default : !passive_default); |
| 1288 | |
| 1289 | if (IS_RIP_DEBUG_ZEBRA) |
| 1290 | zlog_info ("interface %s: passive = %d",ifp->name,ri->passive); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | void |
| 1294 | rip_passive_interface_apply_all () |
| 1295 | { |
| 1296 | struct interface *ifp; |
| 1297 | listnode node; |
| 1298 | |
| 1299 | for (node = listhead (iflist); node; nextnode (node)) |
| 1300 | { |
| 1301 | ifp = getdata (node); |
| 1302 | rip_passive_interface_apply (ifp); |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | /* Passive interface. */ |
| 1307 | int |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1308 | rip_passive_nondefault_set (struct vty *vty, char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1309 | { |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1310 | if (rip_passive_nondefault_lookup (ifname) >= 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1311 | return CMD_WARNING; |
| 1312 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1313 | vector_set (Vrip_passive_nondefault, strdup (ifname)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1314 | |
| 1315 | rip_passive_interface_apply_all (); |
| 1316 | |
| 1317 | return CMD_SUCCESS; |
| 1318 | } |
| 1319 | |
| 1320 | int |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1321 | rip_passive_nondefault_unset (struct vty *vty, char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1322 | { |
| 1323 | int i; |
| 1324 | char *str; |
| 1325 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1326 | i = rip_passive_nondefault_lookup (ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1327 | if (i < 0) |
| 1328 | return CMD_WARNING; |
| 1329 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1330 | str = vector_slot (Vrip_passive_nondefault, i); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1331 | free (str); |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1332 | vector_unset (Vrip_passive_nondefault, i); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1333 | |
| 1334 | rip_passive_interface_apply_all (); |
| 1335 | |
| 1336 | return CMD_SUCCESS; |
| 1337 | } |
| 1338 | |
| 1339 | /* Free all configured RIP passive-interface settings. */ |
| 1340 | void |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1341 | rip_passive_nondefault_clean () |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1342 | { |
| 1343 | int i; |
| 1344 | char *str; |
| 1345 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1346 | for (i = 0; i < vector_max (Vrip_passive_nondefault); i++) |
| 1347 | if ((str = vector_slot (Vrip_passive_nondefault, i)) != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1348 | { |
| 1349 | free (str); |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1350 | vector_slot (Vrip_passive_nondefault, i) = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1351 | } |
| 1352 | rip_passive_interface_apply_all (); |
| 1353 | } |
| 1354 | |
| 1355 | /* RIP enable network or interface configuration. */ |
| 1356 | DEFUN (rip_network, |
| 1357 | rip_network_cmd, |
| 1358 | "network (A.B.C.D/M|WORD)", |
| 1359 | "Enable routing on an IP network\n" |
| 1360 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 1361 | "Interface name\n") |
| 1362 | { |
| 1363 | int ret; |
| 1364 | struct prefix_ipv4 p; |
| 1365 | |
| 1366 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1367 | |
| 1368 | if (ret) |
| 1369 | ret = rip_enable_network_add ((struct prefix *) &p); |
| 1370 | else |
| 1371 | ret = rip_enable_if_add (argv[0]); |
| 1372 | |
| 1373 | if (ret < 0) |
| 1374 | { |
| 1375 | vty_out (vty, "There is a same network configuration %s%s", argv[0], |
| 1376 | VTY_NEWLINE); |
| 1377 | return CMD_WARNING; |
| 1378 | } |
| 1379 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1380 | return CMD_SUCCESS; |
| 1381 | } |
| 1382 | |
| 1383 | /* RIP enable network or interface configuration. */ |
| 1384 | DEFUN (no_rip_network, |
| 1385 | no_rip_network_cmd, |
| 1386 | "no network (A.B.C.D/M|WORD)", |
| 1387 | NO_STR |
| 1388 | "Enable routing on an IP network\n" |
| 1389 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 1390 | "Interface name\n") |
| 1391 | { |
| 1392 | int ret; |
| 1393 | struct prefix_ipv4 p; |
| 1394 | |
| 1395 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1396 | |
| 1397 | if (ret) |
| 1398 | ret = rip_enable_network_delete ((struct prefix *) &p); |
| 1399 | else |
| 1400 | ret = rip_enable_if_delete (argv[0]); |
| 1401 | |
| 1402 | if (ret < 0) |
| 1403 | { |
| 1404 | vty_out (vty, "Can't find network configuration %s%s", argv[0], |
| 1405 | VTY_NEWLINE); |
| 1406 | return CMD_WARNING; |
| 1407 | } |
| 1408 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1409 | return CMD_SUCCESS; |
| 1410 | } |
| 1411 | |
| 1412 | /* RIP neighbor configuration set. */ |
| 1413 | DEFUN (rip_neighbor, |
| 1414 | rip_neighbor_cmd, |
| 1415 | "neighbor A.B.C.D", |
| 1416 | "Specify a neighbor router\n" |
| 1417 | "Neighbor address\n") |
| 1418 | { |
| 1419 | int ret; |
| 1420 | struct prefix_ipv4 p; |
| 1421 | |
| 1422 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1423 | |
| 1424 | if (ret <= 0) |
| 1425 | { |
| 1426 | vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE); |
| 1427 | return CMD_WARNING; |
| 1428 | } |
| 1429 | |
| 1430 | rip_neighbor_add (&p); |
| 1431 | |
| 1432 | return CMD_SUCCESS; |
| 1433 | } |
| 1434 | |
| 1435 | /* RIP neighbor configuration unset. */ |
| 1436 | DEFUN (no_rip_neighbor, |
| 1437 | no_rip_neighbor_cmd, |
| 1438 | "no neighbor A.B.C.D", |
| 1439 | NO_STR |
| 1440 | "Specify a neighbor router\n" |
| 1441 | "Neighbor address\n") |
| 1442 | { |
| 1443 | int ret; |
| 1444 | struct prefix_ipv4 p; |
| 1445 | |
| 1446 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1447 | |
| 1448 | if (ret <= 0) |
| 1449 | { |
| 1450 | vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE); |
| 1451 | return CMD_WARNING; |
| 1452 | } |
| 1453 | |
| 1454 | rip_neighbor_delete (&p); |
| 1455 | |
| 1456 | return CMD_SUCCESS; |
| 1457 | } |
| 1458 | |
| 1459 | DEFUN (ip_rip_receive_version, |
| 1460 | ip_rip_receive_version_cmd, |
| 1461 | "ip rip receive version (1|2)", |
| 1462 | IP_STR |
| 1463 | "Routing Information Protocol\n" |
| 1464 | "Advertisement reception\n" |
| 1465 | "Version control\n" |
| 1466 | "RIP version 1\n" |
| 1467 | "RIP version 2\n") |
| 1468 | { |
| 1469 | struct interface *ifp; |
| 1470 | struct rip_interface *ri; |
| 1471 | |
| 1472 | ifp = (struct interface *)vty->index; |
| 1473 | ri = ifp->info; |
| 1474 | |
| 1475 | /* Version 1. */ |
| 1476 | if (atoi (argv[0]) == 1) |
| 1477 | { |
| 1478 | ri->ri_receive = RI_RIP_VERSION_1; |
| 1479 | return CMD_SUCCESS; |
| 1480 | } |
| 1481 | if (atoi (argv[0]) == 2) |
| 1482 | { |
| 1483 | ri->ri_receive = RI_RIP_VERSION_2; |
| 1484 | return CMD_SUCCESS; |
| 1485 | } |
| 1486 | return CMD_WARNING; |
| 1487 | } |
| 1488 | |
| 1489 | DEFUN (ip_rip_receive_version_1, |
| 1490 | ip_rip_receive_version_1_cmd, |
| 1491 | "ip rip receive version 1 2", |
| 1492 | IP_STR |
| 1493 | "Routing Information Protocol\n" |
| 1494 | "Advertisement reception\n" |
| 1495 | "Version control\n" |
| 1496 | "RIP version 1\n" |
| 1497 | "RIP version 2\n") |
| 1498 | { |
| 1499 | struct interface *ifp; |
| 1500 | struct rip_interface *ri; |
| 1501 | |
| 1502 | ifp = (struct interface *)vty->index; |
| 1503 | ri = ifp->info; |
| 1504 | |
| 1505 | /* Version 1 and 2. */ |
| 1506 | ri->ri_receive = RI_RIP_VERSION_1_AND_2; |
| 1507 | return CMD_SUCCESS; |
| 1508 | } |
| 1509 | |
| 1510 | DEFUN (ip_rip_receive_version_2, |
| 1511 | ip_rip_receive_version_2_cmd, |
| 1512 | "ip rip receive version 2 1", |
| 1513 | IP_STR |
| 1514 | "Routing Information Protocol\n" |
| 1515 | "Advertisement reception\n" |
| 1516 | "Version control\n" |
| 1517 | "RIP version 2\n" |
| 1518 | "RIP version 1\n") |
| 1519 | { |
| 1520 | struct interface *ifp; |
| 1521 | struct rip_interface *ri; |
| 1522 | |
| 1523 | ifp = (struct interface *)vty->index; |
| 1524 | ri = ifp->info; |
| 1525 | |
| 1526 | /* Version 1 and 2. */ |
| 1527 | ri->ri_receive = RI_RIP_VERSION_1_AND_2; |
| 1528 | return CMD_SUCCESS; |
| 1529 | } |
| 1530 | |
| 1531 | DEFUN (no_ip_rip_receive_version, |
| 1532 | no_ip_rip_receive_version_cmd, |
| 1533 | "no ip rip receive version", |
| 1534 | NO_STR |
| 1535 | IP_STR |
| 1536 | "Routing Information Protocol\n" |
| 1537 | "Advertisement reception\n" |
| 1538 | "Version control\n") |
| 1539 | { |
| 1540 | struct interface *ifp; |
| 1541 | struct rip_interface *ri; |
| 1542 | |
| 1543 | ifp = (struct interface *)vty->index; |
| 1544 | ri = ifp->info; |
| 1545 | |
| 1546 | ri->ri_receive = RI_RIP_UNSPEC; |
| 1547 | return CMD_SUCCESS; |
| 1548 | } |
| 1549 | |
| 1550 | ALIAS (no_ip_rip_receive_version, |
| 1551 | no_ip_rip_receive_version_num_cmd, |
| 1552 | "no ip rip receive version (1|2)", |
| 1553 | NO_STR |
| 1554 | IP_STR |
| 1555 | "Routing Information Protocol\n" |
| 1556 | "Advertisement reception\n" |
| 1557 | "Version control\n" |
| 1558 | "Version 1\n" |
| 1559 | "Version 2\n") |
| 1560 | |
| 1561 | DEFUN (ip_rip_send_version, |
| 1562 | ip_rip_send_version_cmd, |
| 1563 | "ip rip send version (1|2)", |
| 1564 | IP_STR |
| 1565 | "Routing Information Protocol\n" |
| 1566 | "Advertisement transmission\n" |
| 1567 | "Version control\n" |
| 1568 | "RIP version 1\n" |
| 1569 | "RIP version 2\n") |
| 1570 | { |
| 1571 | struct interface *ifp; |
| 1572 | struct rip_interface *ri; |
| 1573 | |
| 1574 | ifp = (struct interface *)vty->index; |
| 1575 | ri = ifp->info; |
| 1576 | |
| 1577 | /* Version 1. */ |
| 1578 | if (atoi (argv[0]) == 1) |
| 1579 | { |
| 1580 | ri->ri_send = RI_RIP_VERSION_1; |
| 1581 | return CMD_SUCCESS; |
| 1582 | } |
| 1583 | if (atoi (argv[0]) == 2) |
| 1584 | { |
| 1585 | ri->ri_send = RI_RIP_VERSION_2; |
| 1586 | return CMD_SUCCESS; |
| 1587 | } |
| 1588 | return CMD_WARNING; |
| 1589 | } |
| 1590 | |
| 1591 | DEFUN (ip_rip_send_version_1, |
| 1592 | ip_rip_send_version_1_cmd, |
| 1593 | "ip rip send version 1 2", |
| 1594 | IP_STR |
| 1595 | "Routing Information Protocol\n" |
| 1596 | "Advertisement transmission\n" |
| 1597 | "Version control\n" |
| 1598 | "RIP version 1\n" |
| 1599 | "RIP version 2\n") |
| 1600 | { |
| 1601 | struct interface *ifp; |
| 1602 | struct rip_interface *ri; |
| 1603 | |
| 1604 | ifp = (struct interface *)vty->index; |
| 1605 | ri = ifp->info; |
| 1606 | |
| 1607 | /* Version 1 and 2. */ |
| 1608 | ri->ri_send = RI_RIP_VERSION_1_AND_2; |
| 1609 | return CMD_SUCCESS; |
| 1610 | } |
| 1611 | |
| 1612 | DEFUN (ip_rip_send_version_2, |
| 1613 | ip_rip_send_version_2_cmd, |
| 1614 | "ip rip send version 2 1", |
| 1615 | IP_STR |
| 1616 | "Routing Information Protocol\n" |
| 1617 | "Advertisement transmission\n" |
| 1618 | "Version control\n" |
| 1619 | "RIP version 2\n" |
| 1620 | "RIP version 1\n") |
| 1621 | { |
| 1622 | struct interface *ifp; |
| 1623 | struct rip_interface *ri; |
| 1624 | |
| 1625 | ifp = (struct interface *)vty->index; |
| 1626 | ri = ifp->info; |
| 1627 | |
| 1628 | /* Version 1 and 2. */ |
| 1629 | ri->ri_send = RI_RIP_VERSION_1_AND_2; |
| 1630 | return CMD_SUCCESS; |
| 1631 | } |
| 1632 | |
| 1633 | DEFUN (no_ip_rip_send_version, |
| 1634 | no_ip_rip_send_version_cmd, |
| 1635 | "no ip rip send version", |
| 1636 | NO_STR |
| 1637 | IP_STR |
| 1638 | "Routing Information Protocol\n" |
| 1639 | "Advertisement transmission\n" |
| 1640 | "Version control\n") |
| 1641 | { |
| 1642 | struct interface *ifp; |
| 1643 | struct rip_interface *ri; |
| 1644 | |
| 1645 | ifp = (struct interface *)vty->index; |
| 1646 | ri = ifp->info; |
| 1647 | |
| 1648 | ri->ri_send = RI_RIP_UNSPEC; |
| 1649 | return CMD_SUCCESS; |
| 1650 | } |
| 1651 | |
| 1652 | ALIAS (no_ip_rip_send_version, |
| 1653 | no_ip_rip_send_version_num_cmd, |
| 1654 | "no ip rip send version (1|2)", |
| 1655 | NO_STR |
| 1656 | IP_STR |
| 1657 | "Routing Information Protocol\n" |
| 1658 | "Advertisement transmission\n" |
| 1659 | "Version control\n" |
| 1660 | "Version 1\n" |
| 1661 | "Version 2\n") |
| 1662 | |
| 1663 | DEFUN (ip_rip_authentication_mode, |
| 1664 | ip_rip_authentication_mode_cmd, |
| 1665 | "ip rip authentication mode (md5|text)", |
| 1666 | IP_STR |
| 1667 | "Routing Information Protocol\n" |
| 1668 | "Authentication control\n" |
| 1669 | "Authentication mode\n" |
| 1670 | "Keyed message digest\n" |
| 1671 | "Clear text authentication\n") |
| 1672 | { |
| 1673 | struct interface *ifp; |
| 1674 | struct rip_interface *ri; |
| 1675 | |
| 1676 | ifp = (struct interface *)vty->index; |
| 1677 | ri = ifp->info; |
| 1678 | |
| 1679 | if (strncmp ("md5", argv[0], strlen (argv[0])) == 0) |
| 1680 | ri->auth_type = RIP_AUTH_MD5; |
| 1681 | else if (strncmp ("text", argv[0], strlen (argv[0])) == 0) |
| 1682 | ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD; |
| 1683 | else |
| 1684 | { |
| 1685 | vty_out (vty, "mode should be md5 or text%s", VTY_NEWLINE); |
| 1686 | return CMD_WARNING; |
| 1687 | } |
| 1688 | |
| 1689 | return CMD_SUCCESS; |
| 1690 | } |
| 1691 | |
| 1692 | DEFUN (no_ip_rip_authentication_mode, |
| 1693 | no_ip_rip_authentication_mode_cmd, |
| 1694 | "no ip rip authentication mode", |
| 1695 | NO_STR |
| 1696 | IP_STR |
| 1697 | "Routing Information Protocol\n" |
| 1698 | "Authentication control\n" |
| 1699 | "Authentication mode\n") |
| 1700 | { |
| 1701 | struct interface *ifp; |
| 1702 | struct rip_interface *ri; |
| 1703 | |
| 1704 | ifp = (struct interface *)vty->index; |
| 1705 | ri = ifp->info; |
| 1706 | |
| 1707 | /* ri->auth_type = RIP_NO_AUTH; */ |
| 1708 | ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD; |
| 1709 | |
| 1710 | return CMD_SUCCESS; |
| 1711 | } |
| 1712 | |
| 1713 | ALIAS (no_ip_rip_authentication_mode, |
| 1714 | no_ip_rip_authentication_mode_type_cmd, |
| 1715 | "no ip rip authentication mode (md5|text)", |
| 1716 | NO_STR |
| 1717 | IP_STR |
| 1718 | "Routing Information Protocol\n" |
| 1719 | "Authentication control\n" |
| 1720 | "Authentication mode\n" |
| 1721 | "Keyed message digest\n" |
| 1722 | "Clear text authentication\n") |
| 1723 | |
| 1724 | DEFUN (ip_rip_authentication_string, |
| 1725 | ip_rip_authentication_string_cmd, |
| 1726 | "ip rip authentication string LINE", |
| 1727 | IP_STR |
| 1728 | "Routing Information Protocol\n" |
| 1729 | "Authentication control\n" |
| 1730 | "Authentication string\n" |
| 1731 | "Authentication string\n") |
| 1732 | { |
| 1733 | struct interface *ifp; |
| 1734 | struct rip_interface *ri; |
| 1735 | |
| 1736 | ifp = (struct interface *)vty->index; |
| 1737 | ri = ifp->info; |
| 1738 | |
| 1739 | if (strlen (argv[0]) > 16) |
| 1740 | { |
| 1741 | vty_out (vty, "%% RIPv2 authentication string must be shorter than 16%s", |
| 1742 | VTY_NEWLINE); |
| 1743 | return CMD_WARNING; |
| 1744 | } |
| 1745 | |
| 1746 | if (ri->key_chain) |
| 1747 | { |
| 1748 | vty_out (vty, "%% key-chain configuration exists%s", VTY_NEWLINE); |
| 1749 | return CMD_WARNING; |
| 1750 | } |
| 1751 | |
| 1752 | if (ri->auth_str) |
| 1753 | free (ri->auth_str); |
| 1754 | |
| 1755 | ri->auth_str = strdup (argv[0]); |
| 1756 | |
| 1757 | return CMD_SUCCESS; |
| 1758 | } |
| 1759 | |
| 1760 | DEFUN (no_ip_rip_authentication_string, |
| 1761 | no_ip_rip_authentication_string_cmd, |
| 1762 | "no ip rip authentication string", |
| 1763 | NO_STR |
| 1764 | IP_STR |
| 1765 | "Routing Information Protocol\n" |
| 1766 | "Authentication control\n" |
| 1767 | "Authentication string\n") |
| 1768 | { |
| 1769 | struct interface *ifp; |
| 1770 | struct rip_interface *ri; |
| 1771 | |
| 1772 | ifp = (struct interface *)vty->index; |
| 1773 | ri = ifp->info; |
| 1774 | |
| 1775 | if (ri->auth_str) |
| 1776 | free (ri->auth_str); |
| 1777 | |
| 1778 | ri->auth_str = NULL; |
| 1779 | |
| 1780 | return CMD_SUCCESS; |
| 1781 | } |
| 1782 | |
| 1783 | ALIAS (no_ip_rip_authentication_string, |
| 1784 | no_ip_rip_authentication_string2_cmd, |
| 1785 | "no ip rip authentication string LINE", |
| 1786 | NO_STR |
| 1787 | IP_STR |
| 1788 | "Routing Information Protocol\n" |
| 1789 | "Authentication control\n" |
| 1790 | "Authentication string\n" |
| 1791 | "Authentication string\n") |
| 1792 | |
| 1793 | DEFUN (ip_rip_authentication_key_chain, |
| 1794 | ip_rip_authentication_key_chain_cmd, |
| 1795 | "ip rip authentication key-chain LINE", |
| 1796 | IP_STR |
| 1797 | "Routing Information Protocol\n" |
| 1798 | "Authentication control\n" |
| 1799 | "Authentication key-chain\n" |
| 1800 | "name of key-chain\n") |
| 1801 | { |
| 1802 | struct interface *ifp; |
| 1803 | struct rip_interface *ri; |
| 1804 | |
| 1805 | ifp = (struct interface *) vty->index; |
| 1806 | ri = ifp->info; |
| 1807 | |
| 1808 | if (ri->auth_str) |
| 1809 | { |
| 1810 | vty_out (vty, "%% authentication string configuration exists%s", |
| 1811 | VTY_NEWLINE); |
| 1812 | return CMD_WARNING; |
| 1813 | } |
| 1814 | |
| 1815 | if (ri->key_chain) |
| 1816 | free (ri->key_chain); |
| 1817 | |
| 1818 | ri->key_chain = strdup (argv[0]); |
| 1819 | |
| 1820 | return CMD_SUCCESS; |
| 1821 | } |
| 1822 | |
| 1823 | DEFUN (no_ip_rip_authentication_key_chain, |
| 1824 | no_ip_rip_authentication_key_chain_cmd, |
| 1825 | "no ip rip authentication key-chain", |
| 1826 | NO_STR |
| 1827 | IP_STR |
| 1828 | "Routing Information Protocol\n" |
| 1829 | "Authentication control\n" |
| 1830 | "Authentication key-chain\n") |
| 1831 | { |
| 1832 | struct interface *ifp; |
| 1833 | struct rip_interface *ri; |
| 1834 | |
| 1835 | ifp = (struct interface *) vty->index; |
| 1836 | ri = ifp->info; |
| 1837 | |
| 1838 | if (ri->key_chain) |
| 1839 | free (ri->key_chain); |
| 1840 | |
| 1841 | ri->key_chain = NULL; |
| 1842 | |
| 1843 | return CMD_SUCCESS; |
| 1844 | } |
| 1845 | |
| 1846 | ALIAS (no_ip_rip_authentication_key_chain, |
| 1847 | no_ip_rip_authentication_key_chain2_cmd, |
| 1848 | "no ip rip authentication key-chain LINE", |
| 1849 | NO_STR |
| 1850 | IP_STR |
| 1851 | "Routing Information Protocol\n" |
| 1852 | "Authentication control\n" |
| 1853 | "Authentication key-chain\n" |
| 1854 | "name of key-chain\n") |
| 1855 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1856 | /* CHANGED: ip rip split-horizon |
| 1857 | Cisco and Zebra's command is |
| 1858 | ip split-horizon |
| 1859 | */ |
| 1860 | DEFUN (ip_rip_split_horizon, |
| 1861 | ip_rip_split_horizon_cmd, |
| 1862 | "ip rip split-horizon", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1863 | IP_STR |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1864 | "Routing Information Protocol\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1865 | "Perform split horizon\n") |
| 1866 | { |
| 1867 | struct interface *ifp; |
| 1868 | struct rip_interface *ri; |
| 1869 | |
| 1870 | ifp = vty->index; |
| 1871 | ri = ifp->info; |
| 1872 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1873 | ri->split_horizon = RIP_SPLIT_HORIZON; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1874 | return CMD_SUCCESS; |
| 1875 | } |
| 1876 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1877 | DEFUN (ip_rip_split_horizon_poisoned_reverse, |
| 1878 | ip_rip_split_horizon_poisoned_reverse_cmd, |
| 1879 | "ip rip split-horizon poisoned-reverse", |
| 1880 | IP_STR |
| 1881 | "Routing Information Protocol\n" |
| 1882 | "Perform split horizon\n" |
| 1883 | "With poisoned-reverse\n") |
| 1884 | { |
| 1885 | struct interface *ifp; |
| 1886 | struct rip_interface *ri; |
| 1887 | |
| 1888 | ifp = vty->index; |
| 1889 | ri = ifp->info; |
| 1890 | |
| 1891 | ri->split_horizon = RIP_SPLIT_HORIZON_POISONED_REVERSE; |
| 1892 | return CMD_SUCCESS; |
| 1893 | } |
| 1894 | |
| 1895 | /* CHANGED: no ip rip split-horizon |
| 1896 | Cisco and Zebra's command is |
| 1897 | no ip split-horizon |
| 1898 | */ |
| 1899 | DEFUN (no_ip_rip_split_horizon, |
| 1900 | no_ip_rip_split_horizon_cmd, |
| 1901 | "no ip rip split-horizon", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1902 | NO_STR |
| 1903 | IP_STR |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1904 | "Routing Information Protocol\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1905 | "Perform split horizon\n") |
| 1906 | { |
| 1907 | struct interface *ifp; |
| 1908 | struct rip_interface *ri; |
| 1909 | |
| 1910 | ifp = vty->index; |
| 1911 | ri = ifp->info; |
| 1912 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1913 | ri->split_horizon = RIP_NO_SPLIT_HORIZON; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1914 | return CMD_SUCCESS; |
| 1915 | } |
| 1916 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1917 | ALIAS (no_ip_rip_split_horizon, |
| 1918 | no_ip_rip_split_horizon_poisoned_reverse_cmd, |
| 1919 | "no ip rip split-horizon poisoned-reverse", |
| 1920 | NO_STR |
| 1921 | IP_STR |
| 1922 | "Routing Information Protocol\n" |
| 1923 | "Perform split horizon\n" |
| 1924 | "With poisoned-reverse\n") |
| 1925 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1926 | DEFUN (rip_passive_interface, |
| 1927 | rip_passive_interface_cmd, |
paul | 56e475c | 2003-06-20 00:23:27 +0000 | [diff] [blame] | 1928 | "passive-interface (IFNAME|default)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1929 | "Suppress routing updates on an interface\n" |
paul | 56e475c | 2003-06-20 00:23:27 +0000 | [diff] [blame] | 1930 | "Interface name\n" |
| 1931 | "default for all interfaces\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1932 | { |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1933 | char *ifname = argv[0]; |
| 1934 | |
| 1935 | if (!strcmp(ifname,"default")) { |
| 1936 | passive_default = 1; |
| 1937 | rip_passive_nondefault_clean(); |
| 1938 | return CMD_SUCCESS; |
| 1939 | } |
| 1940 | if (passive_default) |
| 1941 | return rip_passive_nondefault_unset (vty, ifname); |
| 1942 | else |
| 1943 | return rip_passive_nondefault_set (vty, ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | DEFUN (no_rip_passive_interface, |
| 1947 | no_rip_passive_interface_cmd, |
paul | 56e475c | 2003-06-20 00:23:27 +0000 | [diff] [blame] | 1948 | "no passive-interface (IFNAME|default)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1949 | NO_STR |
| 1950 | "Suppress routing updates on an interface\n" |
paul | 56e475c | 2003-06-20 00:23:27 +0000 | [diff] [blame] | 1951 | "Interface name\n" |
| 1952 | "default for all interfaces\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1953 | { |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1954 | char *ifname = argv[0]; |
| 1955 | |
| 1956 | if (!strcmp(ifname,"default")) { |
| 1957 | passive_default = 0; |
| 1958 | rip_passive_nondefault_clean(); |
| 1959 | return CMD_SUCCESS; |
| 1960 | } |
| 1961 | if (passive_default) |
| 1962 | return rip_passive_nondefault_set (vty, ifname); |
| 1963 | else |
| 1964 | return rip_passive_nondefault_unset (vty, ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /* Write rip configuration of each interface. */ |
| 1968 | int |
| 1969 | rip_interface_config_write (struct vty *vty) |
| 1970 | { |
| 1971 | listnode node; |
| 1972 | struct interface *ifp; |
| 1973 | |
| 1974 | for (node = listhead (iflist); node; nextnode (node)) |
| 1975 | { |
| 1976 | struct rip_interface *ri; |
| 1977 | |
| 1978 | ifp = getdata (node); |
| 1979 | ri = ifp->info; |
| 1980 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1981 | /* Do not display the interface if there is no |
| 1982 | * configuration about it. |
| 1983 | **/ |
| 1984 | if ((!ifp->desc) && |
| 1985 | (ri->split_horizon == ri->split_horizon_default) && |
| 1986 | (ri->ri_send == RI_RIP_UNSPEC) && |
| 1987 | (ri->ri_receive == RI_RIP_UNSPEC) && |
| 1988 | (ri->auth_type != RIP_AUTH_MD5) && |
| 1989 | (!ri->auth_str) && |
| 1990 | (!ri->key_chain) ) |
| 1991 | continue; |
| 1992 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1993 | vty_out (vty, "interface %s%s", ifp->name, |
| 1994 | VTY_NEWLINE); |
| 1995 | |
| 1996 | if (ifp->desc) |
| 1997 | vty_out (vty, " description %s%s", ifp->desc, |
| 1998 | VTY_NEWLINE); |
| 1999 | |
| 2000 | /* Split horizon. */ |
| 2001 | if (ri->split_horizon != ri->split_horizon_default) |
| 2002 | { |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 2003 | switch (ri->split_horizon) { |
| 2004 | case RIP_SPLIT_HORIZON: |
| 2005 | vty_out (vty, " ip rip split-horizon%s", VTY_NEWLINE); |
| 2006 | break; |
| 2007 | case RIP_SPLIT_HORIZON_POISONED_REVERSE: |
| 2008 | vty_out (vty, " ip rip split-horizon poisoned-reverse%s", |
| 2009 | VTY_NEWLINE); |
| 2010 | break; |
| 2011 | case RIP_NO_SPLIT_HORIZON: |
| 2012 | default: |
| 2013 | vty_out (vty, " no ip rip split-horizon%s", VTY_NEWLINE); |
| 2014 | break; |
| 2015 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | /* RIP version setting. */ |
| 2019 | if (ri->ri_send != RI_RIP_UNSPEC) |
| 2020 | vty_out (vty, " ip rip send version %s%s", |
| 2021 | lookup (ri_version_msg, ri->ri_send), |
| 2022 | VTY_NEWLINE); |
| 2023 | |
| 2024 | if (ri->ri_receive != RI_RIP_UNSPEC) |
| 2025 | vty_out (vty, " ip rip receive version %s%s", |
| 2026 | lookup (ri_version_msg, ri->ri_receive), |
| 2027 | VTY_NEWLINE); |
| 2028 | |
| 2029 | /* RIP authentication. */ |
| 2030 | #if 0 |
| 2031 | /* RIP_AUTH_SIMPLE_PASSWORD becomes default mode. */ |
| 2032 | if (ri->auth_type == RIP_AUTH_SIMPLE_PASSWORD) |
| 2033 | vty_out (vty, " ip rip authentication mode text%s", VTY_NEWLINE); |
| 2034 | #endif /* 0 */ |
| 2035 | if (ri->auth_type == RIP_AUTH_MD5) |
| 2036 | vty_out (vty, " ip rip authentication mode md5%s", VTY_NEWLINE); |
| 2037 | |
| 2038 | if (ri->auth_str) |
| 2039 | vty_out (vty, " ip rip authentication string %s%s", |
| 2040 | ri->auth_str, VTY_NEWLINE); |
| 2041 | |
| 2042 | if (ri->key_chain) |
| 2043 | vty_out (vty, " ip rip authentication key-chain %s%s", |
| 2044 | ri->key_chain, VTY_NEWLINE); |
| 2045 | |
| 2046 | vty_out (vty, "!%s", VTY_NEWLINE); |
| 2047 | } |
| 2048 | return 0; |
| 2049 | } |
| 2050 | |
| 2051 | int |
| 2052 | config_write_rip_network (struct vty *vty, int config_mode) |
| 2053 | { |
| 2054 | int i; |
| 2055 | char *ifname; |
| 2056 | struct route_node *node; |
| 2057 | |
| 2058 | /* Network type RIP enable interface statement. */ |
| 2059 | for (node = route_top (rip_enable_network); node; node = route_next (node)) |
| 2060 | if (node->info) |
| 2061 | vty_out (vty, "%s%s/%d%s", |
| 2062 | config_mode ? " network " : " ", |
| 2063 | inet_ntoa (node->p.u.prefix4), |
| 2064 | node->p.prefixlen, |
| 2065 | VTY_NEWLINE); |
| 2066 | |
| 2067 | /* Interface name RIP enable statement. */ |
| 2068 | for (i = 0; i < vector_max (rip_enable_interface); i++) |
| 2069 | if ((ifname = vector_slot (rip_enable_interface, i)) != NULL) |
| 2070 | vty_out (vty, "%s%s%s", |
| 2071 | config_mode ? " network " : " ", |
| 2072 | ifname, |
| 2073 | VTY_NEWLINE); |
| 2074 | |
| 2075 | /* RIP neighbors listing. */ |
| 2076 | for (node = route_top (rip->neighbor); node; node = route_next (node)) |
| 2077 | if (node->info) |
| 2078 | vty_out (vty, "%s%s%s", |
| 2079 | config_mode ? " neighbor " : " ", |
| 2080 | inet_ntoa (node->p.u.prefix4), |
| 2081 | VTY_NEWLINE); |
| 2082 | |
| 2083 | /* RIP passive interface listing. */ |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 2084 | if (config_mode) { |
| 2085 | if (passive_default) |
paul | 01d0908 | 2003-06-08 21:22:18 +0000 | [diff] [blame] | 2086 | vty_out (vty, " passive-interface default%s", VTY_NEWLINE); |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 2087 | for (i = 0; i < vector_max (Vrip_passive_nondefault); i++) |
| 2088 | if ((ifname = vector_slot (Vrip_passive_nondefault, i)) != NULL) |
| 2089 | vty_out (vty, " %spassive-interface %s%s", |
| 2090 | (passive_default ? "no " : ""), ifname, VTY_NEWLINE); |
| 2091 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2092 | |
| 2093 | return 0; |
| 2094 | } |
| 2095 | |
| 2096 | struct cmd_node interface_node = |
| 2097 | { |
| 2098 | INTERFACE_NODE, |
| 2099 | "%s(config-if)# ", |
| 2100 | 1, |
| 2101 | }; |
| 2102 | |
| 2103 | /* Called when interface structure allocated. */ |
| 2104 | int |
| 2105 | rip_interface_new_hook (struct interface *ifp) |
| 2106 | { |
| 2107 | ifp->info = rip_interface_new (); |
| 2108 | return 0; |
| 2109 | } |
| 2110 | |
| 2111 | /* Called when interface structure deleted. */ |
| 2112 | int |
| 2113 | rip_interface_delete_hook (struct interface *ifp) |
| 2114 | { |
| 2115 | XFREE (MTYPE_RIP_INTERFACE, ifp->info); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 2116 | ifp->info = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2117 | return 0; |
| 2118 | } |
| 2119 | |
| 2120 | /* Allocate and initialize interface vector. */ |
| 2121 | void |
| 2122 | rip_if_init () |
| 2123 | { |
| 2124 | /* Default initial size of interface vector. */ |
| 2125 | if_init(); |
| 2126 | if_add_hook (IF_NEW_HOOK, rip_interface_new_hook); |
| 2127 | if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook); |
| 2128 | |
| 2129 | /* RIP network init. */ |
| 2130 | rip_enable_interface = vector_init (1); |
| 2131 | rip_enable_network = route_table_init (); |
| 2132 | |
| 2133 | /* RIP passive interface. */ |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 2134 | Vrip_passive_nondefault = vector_init (1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2135 | |
| 2136 | /* Install interface node. */ |
| 2137 | install_node (&interface_node, rip_interface_config_write); |
| 2138 | |
| 2139 | /* Install commands. */ |
| 2140 | install_element (CONFIG_NODE, &interface_cmd); |
hasso | 034489d | 2003-05-24 07:59:25 +0000 | [diff] [blame] | 2141 | install_element (CONFIG_NODE, &no_interface_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2142 | install_default (INTERFACE_NODE); |
| 2143 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
| 2144 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
| 2145 | install_element (RIP_NODE, &rip_network_cmd); |
| 2146 | install_element (RIP_NODE, &no_rip_network_cmd); |
| 2147 | install_element (RIP_NODE, &rip_neighbor_cmd); |
| 2148 | install_element (RIP_NODE, &no_rip_neighbor_cmd); |
| 2149 | |
| 2150 | install_element (RIP_NODE, &rip_passive_interface_cmd); |
| 2151 | install_element (RIP_NODE, &no_rip_passive_interface_cmd); |
| 2152 | |
| 2153 | install_element (INTERFACE_NODE, &ip_rip_send_version_cmd); |
| 2154 | install_element (INTERFACE_NODE, &ip_rip_send_version_1_cmd); |
| 2155 | install_element (INTERFACE_NODE, &ip_rip_send_version_2_cmd); |
| 2156 | install_element (INTERFACE_NODE, &no_ip_rip_send_version_cmd); |
| 2157 | install_element (INTERFACE_NODE, &no_ip_rip_send_version_num_cmd); |
| 2158 | |
| 2159 | install_element (INTERFACE_NODE, &ip_rip_receive_version_cmd); |
| 2160 | install_element (INTERFACE_NODE, &ip_rip_receive_version_1_cmd); |
| 2161 | install_element (INTERFACE_NODE, &ip_rip_receive_version_2_cmd); |
| 2162 | install_element (INTERFACE_NODE, &no_ip_rip_receive_version_cmd); |
| 2163 | install_element (INTERFACE_NODE, &no_ip_rip_receive_version_num_cmd); |
| 2164 | |
| 2165 | install_element (INTERFACE_NODE, &ip_rip_authentication_mode_cmd); |
| 2166 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_cmd); |
| 2167 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_type_cmd); |
| 2168 | |
| 2169 | install_element (INTERFACE_NODE, &ip_rip_authentication_key_chain_cmd); |
| 2170 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain_cmd); |
| 2171 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain2_cmd); |
| 2172 | |
| 2173 | install_element (INTERFACE_NODE, &ip_rip_authentication_string_cmd); |
| 2174 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_string_cmd); |
| 2175 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_string2_cmd); |
| 2176 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 2177 | install_element (INTERFACE_NODE, &ip_rip_split_horizon_cmd); |
| 2178 | install_element (INTERFACE_NODE, &ip_rip_split_horizon_poisoned_reverse_cmd); |
| 2179 | install_element (INTERFACE_NODE, &no_ip_rip_split_horizon_cmd); |
| 2180 | install_element (INTERFACE_NODE, &no_ip_rip_split_horizon_poisoned_reverse_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2181 | } |