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 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 789 | ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, |
| 790 | zclient->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 791 | |
| 792 | if (ifc == NULL) |
| 793 | return 0; |
| 794 | |
| 795 | p = ifc->address; |
| 796 | |
| 797 | if (p->family == AF_INET) |
| 798 | { |
| 799 | if (IS_RIP_DEBUG_ZEBRA) |
| 800 | zlog_info ("connected address %s/%d is added", |
| 801 | inet_ntoa (p->u.prefix4), p->prefixlen); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 802 | |
paul | 878ef2e | 2003-09-23 23:41:50 +0000 | [diff] [blame] | 803 | rip_enable_apply(ifc->ifp); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 804 | /* Check if this prefix needs to be redistributed */ |
| 805 | rip_apply_address_add(ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 806 | |
| 807 | #ifdef HAVE_SNMP |
| 808 | rip_ifaddr_add (ifc->ifp, ifc); |
| 809 | #endif /* HAVE_SNMP */ |
| 810 | } |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 815 | static void |
| 816 | rip_apply_address_del (struct connected *ifc) { |
| 817 | struct prefix_ipv4 address; |
| 818 | struct prefix *p; |
| 819 | |
| 820 | if (!rip) |
| 821 | return; |
| 822 | |
| 823 | if (! if_is_up(ifc->ifp)) |
| 824 | return; |
| 825 | |
| 826 | p = ifc->address; |
| 827 | |
| 828 | memset (&address, 0, sizeof (address)); |
| 829 | address.family = p->family; |
| 830 | address.prefix = p->u.prefix4; |
| 831 | address.prefixlen = p->prefixlen; |
| 832 | apply_mask_ipv4(&address); |
| 833 | |
| 834 | rip_redistribute_delete(ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, |
| 835 | &address, ifc->ifp->ifindex); |
| 836 | } |
| 837 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 838 | int |
| 839 | rip_interface_address_delete (int command, struct zclient *zclient, |
| 840 | zebra_size_t length) |
| 841 | { |
| 842 | struct connected *ifc; |
| 843 | struct prefix *p; |
| 844 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 845 | ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, |
| 846 | zclient->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 847 | |
| 848 | if (ifc) |
| 849 | { |
| 850 | p = ifc->address; |
| 851 | if (p->family == AF_INET) |
| 852 | { |
| 853 | if (IS_RIP_DEBUG_ZEBRA) |
| 854 | |
| 855 | zlog_info ("connected address %s/%d is deleted", |
| 856 | inet_ntoa (p->u.prefix4), p->prefixlen); |
| 857 | |
| 858 | #ifdef HAVE_SNMP |
| 859 | rip_ifaddr_delete (ifc->ifp, ifc); |
| 860 | #endif /* HAVE_SNMP */ |
| 861 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 862 | /* Chech wether this prefix needs to be removed */ |
| 863 | rip_apply_address_del(ifc); |
| 864 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | connected_free (ifc); |
| 868 | |
| 869 | } |
| 870 | |
| 871 | return 0; |
| 872 | } |
| 873 | |
| 874 | /* Check interface is enabled by network statement. */ |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 875 | /* Check wether the interface has at least a connected prefix that |
| 876 | * is within the ripng_enable_network table. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 877 | int |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 878 | rip_enable_network_lookup_if (struct interface *ifp) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 879 | { |
| 880 | struct listnode *nn; |
| 881 | struct connected *connected; |
| 882 | struct prefix_ipv4 address; |
| 883 | |
| 884 | for (nn = listhead (ifp->connected); nn; nextnode (nn)) |
| 885 | if ((connected = getdata (nn)) != NULL) |
| 886 | { |
| 887 | struct prefix *p; |
| 888 | struct route_node *node; |
| 889 | |
| 890 | p = connected->address; |
| 891 | |
| 892 | if (p->family == AF_INET) |
| 893 | { |
| 894 | address.family = AF_INET; |
| 895 | address.prefix = p->u.prefix4; |
| 896 | address.prefixlen = IPV4_MAX_BITLEN; |
| 897 | |
| 898 | node = route_node_match (rip_enable_network, |
| 899 | (struct prefix *)&address); |
| 900 | if (node) |
| 901 | { |
| 902 | route_unlock_node (node); |
| 903 | return 1; |
| 904 | } |
| 905 | } |
| 906 | } |
| 907 | return -1; |
| 908 | } |
| 909 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 910 | /* Check wether connected is within the ripng_enable_network table. */ |
| 911 | int |
| 912 | rip_enable_network_lookup2 (struct connected *connected) |
| 913 | { |
| 914 | struct prefix_ipv4 address; |
| 915 | struct prefix *p; |
| 916 | |
| 917 | p = connected->address; |
| 918 | |
| 919 | if (p->family == AF_INET) { |
| 920 | struct route_node *node; |
| 921 | |
| 922 | address.family = p->family; |
| 923 | address.prefix = p->u.prefix4; |
| 924 | address.prefixlen = IPV4_MAX_BITLEN; |
| 925 | |
| 926 | /* LPM on p->family, p->u.prefix4/IPV4_MAX_BITLEN within rip_enable_network */ |
| 927 | node = route_node_match (rip_enable_network, |
| 928 | (struct prefix *)&address); |
| 929 | |
| 930 | if (node) { |
| 931 | route_unlock_node (node); |
| 932 | return 1; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | return -1; |
| 937 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 938 | /* Add RIP enable network. */ |
| 939 | int |
| 940 | rip_enable_network_add (struct prefix *p) |
| 941 | { |
| 942 | struct route_node *node; |
| 943 | |
| 944 | node = route_node_get (rip_enable_network, p); |
| 945 | |
| 946 | if (node->info) |
| 947 | { |
| 948 | route_unlock_node (node); |
| 949 | return -1; |
| 950 | } |
| 951 | else |
| 952 | node->info = "enabled"; |
| 953 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 954 | /* XXX: One should find a better solution than a generic one */ |
| 955 | rip_enable_apply_all(); |
| 956 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 957 | return 1; |
| 958 | } |
| 959 | |
| 960 | /* Delete RIP enable network. */ |
| 961 | int |
| 962 | rip_enable_network_delete (struct prefix *p) |
| 963 | { |
| 964 | struct route_node *node; |
| 965 | |
| 966 | node = route_node_lookup (rip_enable_network, p); |
| 967 | if (node) |
| 968 | { |
| 969 | node->info = NULL; |
| 970 | |
| 971 | /* Unlock info lock. */ |
| 972 | route_unlock_node (node); |
| 973 | |
| 974 | /* Unlock lookup lock. */ |
| 975 | route_unlock_node (node); |
| 976 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 977 | /* XXX: One should find a better solution than a generic one */ |
| 978 | rip_enable_apply_all (); |
| 979 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 980 | return 1; |
| 981 | } |
| 982 | return -1; |
| 983 | } |
| 984 | |
| 985 | /* Check interface is enabled by ifname statement. */ |
| 986 | int |
| 987 | rip_enable_if_lookup (char *ifname) |
| 988 | { |
| 989 | int i; |
| 990 | char *str; |
| 991 | |
| 992 | for (i = 0; i < vector_max (rip_enable_interface); i++) |
| 993 | if ((str = vector_slot (rip_enable_interface, i)) != NULL) |
| 994 | if (strcmp (str, ifname) == 0) |
| 995 | return i; |
| 996 | return -1; |
| 997 | } |
| 998 | |
| 999 | /* Add interface to rip_enable_if. */ |
| 1000 | int |
| 1001 | rip_enable_if_add (char *ifname) |
| 1002 | { |
| 1003 | int ret; |
| 1004 | |
| 1005 | ret = rip_enable_if_lookup (ifname); |
| 1006 | if (ret >= 0) |
| 1007 | return -1; |
| 1008 | |
| 1009 | vector_set (rip_enable_interface, strdup (ifname)); |
| 1010 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1011 | rip_enable_apply_all(); /* TODOVJ */ |
| 1012 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1013 | return 1; |
| 1014 | } |
| 1015 | |
| 1016 | /* Delete interface from rip_enable_if. */ |
| 1017 | int |
| 1018 | rip_enable_if_delete (char *ifname) |
| 1019 | { |
| 1020 | int index; |
| 1021 | char *str; |
| 1022 | |
| 1023 | index = rip_enable_if_lookup (ifname); |
| 1024 | if (index < 0) |
| 1025 | return -1; |
| 1026 | |
| 1027 | str = vector_slot (rip_enable_interface, index); |
| 1028 | free (str); |
| 1029 | vector_unset (rip_enable_interface, index); |
| 1030 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1031 | rip_enable_apply_all(); /* TODOVJ */ |
| 1032 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1033 | return 1; |
| 1034 | } |
| 1035 | |
| 1036 | /* Join to multicast group and send request to the interface. */ |
| 1037 | int |
| 1038 | rip_interface_wakeup (struct thread *t) |
| 1039 | { |
| 1040 | struct interface *ifp; |
| 1041 | struct rip_interface *ri; |
| 1042 | |
| 1043 | /* Get interface. */ |
| 1044 | ifp = THREAD_ARG (t); |
| 1045 | |
| 1046 | ri = ifp->info; |
| 1047 | ri->t_wakeup = NULL; |
| 1048 | |
| 1049 | /* Join to multicast group. */ |
| 1050 | if (rip_multicast_join (ifp, rip->sock) < 0) |
| 1051 | { |
| 1052 | zlog_err ("multicast join failed, interface %s not running", ifp->name); |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
| 1056 | /* Set running flag. */ |
| 1057 | ri->running = 1; |
| 1058 | |
| 1059 | /* Send RIP request to the interface. */ |
| 1060 | rip_request_interface (ifp); |
| 1061 | |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
| 1065 | int rip_redistribute_check (int); |
| 1066 | |
| 1067 | void |
| 1068 | rip_connect_set (struct interface *ifp, int set) |
| 1069 | { |
| 1070 | struct listnode *nn; |
| 1071 | struct connected *connected; |
| 1072 | struct prefix_ipv4 address; |
| 1073 | |
| 1074 | for (nn = listhead (ifp->connected); nn; nextnode (nn)) |
| 1075 | if ((connected = getdata (nn)) != NULL) |
| 1076 | { |
| 1077 | struct prefix *p; |
| 1078 | p = connected->address; |
| 1079 | |
| 1080 | if (p->family != AF_INET) |
| 1081 | continue; |
| 1082 | |
| 1083 | address.family = AF_INET; |
| 1084 | address.prefix = p->u.prefix4; |
| 1085 | address.prefixlen = p->prefixlen; |
| 1086 | apply_mask_ipv4 (&address); |
| 1087 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1088 | if (set) { |
| 1089 | /* Check once more wether this prefix is within a "network IF_OR_PREF" one */ |
| 1090 | if ((rip_enable_if_lookup(connected->ifp->name) >= 0) || |
| 1091 | (rip_enable_network_lookup2(connected) >= 0)) |
| 1092 | rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, |
| 1093 | &address, connected->ifp->ifindex, NULL); |
| 1094 | } else |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1095 | { |
| 1096 | rip_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, |
| 1097 | &address, connected->ifp->ifindex); |
| 1098 | if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT)) |
| 1099 | rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_REDISTRIBUTE, |
| 1100 | &address, connected->ifp->ifindex, NULL); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | /* Update interface status. */ |
| 1106 | void |
| 1107 | rip_enable_apply (struct interface *ifp) |
| 1108 | { |
| 1109 | int ret; |
| 1110 | struct rip_interface *ri = NULL; |
| 1111 | |
| 1112 | /* Check interface. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1113 | if (! if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1114 | return; |
| 1115 | |
| 1116 | ri = ifp->info; |
| 1117 | |
| 1118 | /* Check network configuration. */ |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1119 | ret = rip_enable_network_lookup_if (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1120 | |
| 1121 | /* If the interface is matched. */ |
| 1122 | if (ret > 0) |
| 1123 | ri->enable_network = 1; |
| 1124 | else |
| 1125 | ri->enable_network = 0; |
| 1126 | |
| 1127 | /* Check interface name configuration. */ |
| 1128 | ret = rip_enable_if_lookup (ifp->name); |
| 1129 | if (ret >= 0) |
| 1130 | ri->enable_interface = 1; |
| 1131 | else |
| 1132 | ri->enable_interface = 0; |
| 1133 | |
| 1134 | /* any interface MUST have an IPv4 address */ |
| 1135 | if ( ! rip_if_ipv4_address_check (ifp) ) |
| 1136 | { |
| 1137 | ri->enable_network = 0; |
| 1138 | ri->enable_interface = 0; |
| 1139 | } |
| 1140 | |
| 1141 | /* Update running status of the interface. */ |
| 1142 | if (ri->enable_network || ri->enable_interface) |
| 1143 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1144 | { |
| 1145 | if (IS_RIP_DEBUG_EVENT) |
| 1146 | zlog_info ("turn on %s", ifp->name); |
| 1147 | |
| 1148 | /* Add interface wake up thread. */ |
| 1149 | if (! ri->t_wakeup) |
| 1150 | ri->t_wakeup = thread_add_timer (master, rip_interface_wakeup, |
| 1151 | ifp, 1); |
| 1152 | rip_connect_set (ifp, 1); |
| 1153 | } |
| 1154 | } |
| 1155 | else |
| 1156 | { |
| 1157 | if (ri->running) |
| 1158 | { |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1159 | /* Might as well clean up the route table as well |
| 1160 | * rip_if_down sets to 0 ri->running, and displays "turn off %s" |
| 1161 | **/ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1162 | rip_if_down(ifp); |
| 1163 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1164 | rip_connect_set (ifp, 0); |
| 1165 | } |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | /* Apply network configuration to all interface. */ |
| 1170 | void |
| 1171 | rip_enable_apply_all () |
| 1172 | { |
| 1173 | struct interface *ifp; |
| 1174 | listnode node; |
| 1175 | |
| 1176 | /* Check each interface. */ |
| 1177 | for (node = listhead (iflist); node; nextnode (node)) |
| 1178 | { |
| 1179 | ifp = getdata (node); |
| 1180 | rip_enable_apply (ifp); |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | int |
| 1185 | rip_neighbor_lookup (struct sockaddr_in *from) |
| 1186 | { |
| 1187 | struct prefix_ipv4 p; |
| 1188 | struct route_node *node; |
| 1189 | |
| 1190 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 1191 | p.family = AF_INET; |
| 1192 | p.prefix = from->sin_addr; |
| 1193 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1194 | |
| 1195 | node = route_node_lookup (rip->neighbor, (struct prefix *) &p); |
| 1196 | if (node) |
| 1197 | { |
| 1198 | route_unlock_node (node); |
| 1199 | return 1; |
| 1200 | } |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | /* Add new RIP neighbor to the neighbor tree. */ |
| 1205 | int |
| 1206 | rip_neighbor_add (struct prefix_ipv4 *p) |
| 1207 | { |
| 1208 | struct route_node *node; |
| 1209 | |
| 1210 | node = route_node_get (rip->neighbor, (struct prefix *) p); |
| 1211 | |
| 1212 | if (node->info) |
| 1213 | return -1; |
| 1214 | |
| 1215 | node->info = rip->neighbor; |
| 1216 | |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | /* Delete RIP neighbor from the neighbor tree. */ |
| 1221 | int |
| 1222 | rip_neighbor_delete (struct prefix_ipv4 *p) |
| 1223 | { |
| 1224 | struct route_node *node; |
| 1225 | |
| 1226 | /* Lock for look up. */ |
| 1227 | node = route_node_lookup (rip->neighbor, (struct prefix *) p); |
| 1228 | if (! node) |
| 1229 | return -1; |
| 1230 | |
| 1231 | node->info = NULL; |
| 1232 | |
| 1233 | /* Unlock lookup lock. */ |
| 1234 | route_unlock_node (node); |
| 1235 | |
| 1236 | /* Unlock real neighbor information lock. */ |
| 1237 | route_unlock_node (node); |
| 1238 | |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | /* Clear all network and neighbor configuration. */ |
| 1243 | void |
| 1244 | rip_clean_network () |
| 1245 | { |
| 1246 | int i; |
| 1247 | char *str; |
| 1248 | struct route_node *rn; |
| 1249 | |
| 1250 | /* rip_enable_network. */ |
| 1251 | for (rn = route_top (rip_enable_network); rn; rn = route_next (rn)) |
| 1252 | if (rn->info) |
| 1253 | { |
| 1254 | rn->info = NULL; |
| 1255 | route_unlock_node (rn); |
| 1256 | } |
| 1257 | |
| 1258 | /* rip_enable_interface. */ |
| 1259 | for (i = 0; i < vector_max (rip_enable_interface); i++) |
| 1260 | if ((str = vector_slot (rip_enable_interface, i)) != NULL) |
| 1261 | { |
| 1262 | free (str); |
| 1263 | vector_slot (rip_enable_interface, i) = NULL; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | /* Utility function for looking up passive interface settings. */ |
| 1268 | int |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1269 | rip_passive_nondefault_lookup (char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1270 | { |
| 1271 | int i; |
| 1272 | char *str; |
| 1273 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1274 | for (i = 0; i < vector_max (Vrip_passive_nondefault); i++) |
| 1275 | if ((str = vector_slot (Vrip_passive_nondefault, i)) != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1276 | if (strcmp (str, ifname) == 0) |
| 1277 | return i; |
| 1278 | return -1; |
| 1279 | } |
| 1280 | |
| 1281 | void |
| 1282 | rip_passive_interface_apply (struct interface *ifp) |
| 1283 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1284 | struct rip_interface *ri; |
| 1285 | |
| 1286 | ri = ifp->info; |
| 1287 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1288 | ri->passive = ((rip_passive_nondefault_lookup (ifp->name) < 0) ? |
| 1289 | passive_default : !passive_default); |
| 1290 | |
| 1291 | if (IS_RIP_DEBUG_ZEBRA) |
| 1292 | zlog_info ("interface %s: passive = %d",ifp->name,ri->passive); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | void |
| 1296 | rip_passive_interface_apply_all () |
| 1297 | { |
| 1298 | struct interface *ifp; |
| 1299 | listnode node; |
| 1300 | |
| 1301 | for (node = listhead (iflist); node; nextnode (node)) |
| 1302 | { |
| 1303 | ifp = getdata (node); |
| 1304 | rip_passive_interface_apply (ifp); |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | /* Passive interface. */ |
| 1309 | int |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1310 | rip_passive_nondefault_set (struct vty *vty, char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1311 | { |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1312 | if (rip_passive_nondefault_lookup (ifname) >= 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1313 | return CMD_WARNING; |
| 1314 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1315 | vector_set (Vrip_passive_nondefault, strdup (ifname)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1316 | |
| 1317 | rip_passive_interface_apply_all (); |
| 1318 | |
| 1319 | return CMD_SUCCESS; |
| 1320 | } |
| 1321 | |
| 1322 | int |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1323 | rip_passive_nondefault_unset (struct vty *vty, char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1324 | { |
| 1325 | int i; |
| 1326 | char *str; |
| 1327 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1328 | i = rip_passive_nondefault_lookup (ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1329 | if (i < 0) |
| 1330 | return CMD_WARNING; |
| 1331 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1332 | str = vector_slot (Vrip_passive_nondefault, i); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1333 | free (str); |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1334 | vector_unset (Vrip_passive_nondefault, i); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1335 | |
| 1336 | rip_passive_interface_apply_all (); |
| 1337 | |
| 1338 | return CMD_SUCCESS; |
| 1339 | } |
| 1340 | |
| 1341 | /* Free all configured RIP passive-interface settings. */ |
| 1342 | void |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1343 | rip_passive_nondefault_clean () |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1344 | { |
| 1345 | int i; |
| 1346 | char *str; |
| 1347 | |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1348 | for (i = 0; i < vector_max (Vrip_passive_nondefault); i++) |
| 1349 | if ((str = vector_slot (Vrip_passive_nondefault, i)) != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1350 | { |
| 1351 | free (str); |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1352 | vector_slot (Vrip_passive_nondefault, i) = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1353 | } |
| 1354 | rip_passive_interface_apply_all (); |
| 1355 | } |
| 1356 | |
| 1357 | /* RIP enable network or interface configuration. */ |
| 1358 | DEFUN (rip_network, |
| 1359 | rip_network_cmd, |
| 1360 | "network (A.B.C.D/M|WORD)", |
| 1361 | "Enable routing on an IP network\n" |
| 1362 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 1363 | "Interface name\n") |
| 1364 | { |
| 1365 | int ret; |
| 1366 | struct prefix_ipv4 p; |
| 1367 | |
| 1368 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1369 | |
| 1370 | if (ret) |
| 1371 | ret = rip_enable_network_add ((struct prefix *) &p); |
| 1372 | else |
| 1373 | ret = rip_enable_if_add (argv[0]); |
| 1374 | |
| 1375 | if (ret < 0) |
| 1376 | { |
| 1377 | vty_out (vty, "There is a same network configuration %s%s", argv[0], |
| 1378 | VTY_NEWLINE); |
| 1379 | return CMD_WARNING; |
| 1380 | } |
| 1381 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1382 | return CMD_SUCCESS; |
| 1383 | } |
| 1384 | |
| 1385 | /* RIP enable network or interface configuration. */ |
| 1386 | DEFUN (no_rip_network, |
| 1387 | no_rip_network_cmd, |
| 1388 | "no network (A.B.C.D/M|WORD)", |
| 1389 | NO_STR |
| 1390 | "Enable routing on an IP network\n" |
| 1391 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" |
| 1392 | "Interface name\n") |
| 1393 | { |
| 1394 | int ret; |
| 1395 | struct prefix_ipv4 p; |
| 1396 | |
| 1397 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1398 | |
| 1399 | if (ret) |
| 1400 | ret = rip_enable_network_delete ((struct prefix *) &p); |
| 1401 | else |
| 1402 | ret = rip_enable_if_delete (argv[0]); |
| 1403 | |
| 1404 | if (ret < 0) |
| 1405 | { |
| 1406 | vty_out (vty, "Can't find network configuration %s%s", argv[0], |
| 1407 | VTY_NEWLINE); |
| 1408 | return CMD_WARNING; |
| 1409 | } |
| 1410 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1411 | return CMD_SUCCESS; |
| 1412 | } |
| 1413 | |
| 1414 | /* RIP neighbor configuration set. */ |
| 1415 | DEFUN (rip_neighbor, |
| 1416 | rip_neighbor_cmd, |
| 1417 | "neighbor A.B.C.D", |
| 1418 | "Specify a neighbor router\n" |
| 1419 | "Neighbor address\n") |
| 1420 | { |
| 1421 | int ret; |
| 1422 | struct prefix_ipv4 p; |
| 1423 | |
| 1424 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1425 | |
| 1426 | if (ret <= 0) |
| 1427 | { |
| 1428 | vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE); |
| 1429 | return CMD_WARNING; |
| 1430 | } |
| 1431 | |
| 1432 | rip_neighbor_add (&p); |
| 1433 | |
| 1434 | return CMD_SUCCESS; |
| 1435 | } |
| 1436 | |
| 1437 | /* RIP neighbor configuration unset. */ |
| 1438 | DEFUN (no_rip_neighbor, |
| 1439 | no_rip_neighbor_cmd, |
| 1440 | "no neighbor A.B.C.D", |
| 1441 | NO_STR |
| 1442 | "Specify a neighbor router\n" |
| 1443 | "Neighbor address\n") |
| 1444 | { |
| 1445 | int ret; |
| 1446 | struct prefix_ipv4 p; |
| 1447 | |
| 1448 | ret = str2prefix_ipv4 (argv[0], &p); |
| 1449 | |
| 1450 | if (ret <= 0) |
| 1451 | { |
| 1452 | vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE); |
| 1453 | return CMD_WARNING; |
| 1454 | } |
| 1455 | |
| 1456 | rip_neighbor_delete (&p); |
| 1457 | |
| 1458 | return CMD_SUCCESS; |
| 1459 | } |
| 1460 | |
| 1461 | DEFUN (ip_rip_receive_version, |
| 1462 | ip_rip_receive_version_cmd, |
| 1463 | "ip rip receive version (1|2)", |
| 1464 | IP_STR |
| 1465 | "Routing Information Protocol\n" |
| 1466 | "Advertisement reception\n" |
| 1467 | "Version control\n" |
| 1468 | "RIP version 1\n" |
| 1469 | "RIP version 2\n") |
| 1470 | { |
| 1471 | struct interface *ifp; |
| 1472 | struct rip_interface *ri; |
| 1473 | |
| 1474 | ifp = (struct interface *)vty->index; |
| 1475 | ri = ifp->info; |
| 1476 | |
| 1477 | /* Version 1. */ |
| 1478 | if (atoi (argv[0]) == 1) |
| 1479 | { |
| 1480 | ri->ri_receive = RI_RIP_VERSION_1; |
| 1481 | return CMD_SUCCESS; |
| 1482 | } |
| 1483 | if (atoi (argv[0]) == 2) |
| 1484 | { |
| 1485 | ri->ri_receive = RI_RIP_VERSION_2; |
| 1486 | return CMD_SUCCESS; |
| 1487 | } |
| 1488 | return CMD_WARNING; |
| 1489 | } |
| 1490 | |
| 1491 | DEFUN (ip_rip_receive_version_1, |
| 1492 | ip_rip_receive_version_1_cmd, |
| 1493 | "ip rip receive version 1 2", |
| 1494 | IP_STR |
| 1495 | "Routing Information Protocol\n" |
| 1496 | "Advertisement reception\n" |
| 1497 | "Version control\n" |
| 1498 | "RIP version 1\n" |
| 1499 | "RIP version 2\n") |
| 1500 | { |
| 1501 | struct interface *ifp; |
| 1502 | struct rip_interface *ri; |
| 1503 | |
| 1504 | ifp = (struct interface *)vty->index; |
| 1505 | ri = ifp->info; |
| 1506 | |
| 1507 | /* Version 1 and 2. */ |
| 1508 | ri->ri_receive = RI_RIP_VERSION_1_AND_2; |
| 1509 | return CMD_SUCCESS; |
| 1510 | } |
| 1511 | |
| 1512 | DEFUN (ip_rip_receive_version_2, |
| 1513 | ip_rip_receive_version_2_cmd, |
| 1514 | "ip rip receive version 2 1", |
| 1515 | IP_STR |
| 1516 | "Routing Information Protocol\n" |
| 1517 | "Advertisement reception\n" |
| 1518 | "Version control\n" |
| 1519 | "RIP version 2\n" |
| 1520 | "RIP version 1\n") |
| 1521 | { |
| 1522 | struct interface *ifp; |
| 1523 | struct rip_interface *ri; |
| 1524 | |
| 1525 | ifp = (struct interface *)vty->index; |
| 1526 | ri = ifp->info; |
| 1527 | |
| 1528 | /* Version 1 and 2. */ |
| 1529 | ri->ri_receive = RI_RIP_VERSION_1_AND_2; |
| 1530 | return CMD_SUCCESS; |
| 1531 | } |
| 1532 | |
| 1533 | DEFUN (no_ip_rip_receive_version, |
| 1534 | no_ip_rip_receive_version_cmd, |
| 1535 | "no ip rip receive version", |
| 1536 | NO_STR |
| 1537 | IP_STR |
| 1538 | "Routing Information Protocol\n" |
| 1539 | "Advertisement reception\n" |
| 1540 | "Version control\n") |
| 1541 | { |
| 1542 | struct interface *ifp; |
| 1543 | struct rip_interface *ri; |
| 1544 | |
| 1545 | ifp = (struct interface *)vty->index; |
| 1546 | ri = ifp->info; |
| 1547 | |
| 1548 | ri->ri_receive = RI_RIP_UNSPEC; |
| 1549 | return CMD_SUCCESS; |
| 1550 | } |
| 1551 | |
| 1552 | ALIAS (no_ip_rip_receive_version, |
| 1553 | no_ip_rip_receive_version_num_cmd, |
| 1554 | "no ip rip receive version (1|2)", |
| 1555 | NO_STR |
| 1556 | IP_STR |
| 1557 | "Routing Information Protocol\n" |
| 1558 | "Advertisement reception\n" |
| 1559 | "Version control\n" |
| 1560 | "Version 1\n" |
| 1561 | "Version 2\n") |
| 1562 | |
| 1563 | DEFUN (ip_rip_send_version, |
| 1564 | ip_rip_send_version_cmd, |
| 1565 | "ip rip send version (1|2)", |
| 1566 | IP_STR |
| 1567 | "Routing Information Protocol\n" |
| 1568 | "Advertisement transmission\n" |
| 1569 | "Version control\n" |
| 1570 | "RIP version 1\n" |
| 1571 | "RIP version 2\n") |
| 1572 | { |
| 1573 | struct interface *ifp; |
| 1574 | struct rip_interface *ri; |
| 1575 | |
| 1576 | ifp = (struct interface *)vty->index; |
| 1577 | ri = ifp->info; |
| 1578 | |
| 1579 | /* Version 1. */ |
| 1580 | if (atoi (argv[0]) == 1) |
| 1581 | { |
| 1582 | ri->ri_send = RI_RIP_VERSION_1; |
| 1583 | return CMD_SUCCESS; |
| 1584 | } |
| 1585 | if (atoi (argv[0]) == 2) |
| 1586 | { |
| 1587 | ri->ri_send = RI_RIP_VERSION_2; |
| 1588 | return CMD_SUCCESS; |
| 1589 | } |
| 1590 | return CMD_WARNING; |
| 1591 | } |
| 1592 | |
| 1593 | DEFUN (ip_rip_send_version_1, |
| 1594 | ip_rip_send_version_1_cmd, |
| 1595 | "ip rip send version 1 2", |
| 1596 | IP_STR |
| 1597 | "Routing Information Protocol\n" |
| 1598 | "Advertisement transmission\n" |
| 1599 | "Version control\n" |
| 1600 | "RIP version 1\n" |
| 1601 | "RIP version 2\n") |
| 1602 | { |
| 1603 | struct interface *ifp; |
| 1604 | struct rip_interface *ri; |
| 1605 | |
| 1606 | ifp = (struct interface *)vty->index; |
| 1607 | ri = ifp->info; |
| 1608 | |
| 1609 | /* Version 1 and 2. */ |
| 1610 | ri->ri_send = RI_RIP_VERSION_1_AND_2; |
| 1611 | return CMD_SUCCESS; |
| 1612 | } |
| 1613 | |
| 1614 | DEFUN (ip_rip_send_version_2, |
| 1615 | ip_rip_send_version_2_cmd, |
| 1616 | "ip rip send version 2 1", |
| 1617 | IP_STR |
| 1618 | "Routing Information Protocol\n" |
| 1619 | "Advertisement transmission\n" |
| 1620 | "Version control\n" |
| 1621 | "RIP version 2\n" |
| 1622 | "RIP version 1\n") |
| 1623 | { |
| 1624 | struct interface *ifp; |
| 1625 | struct rip_interface *ri; |
| 1626 | |
| 1627 | ifp = (struct interface *)vty->index; |
| 1628 | ri = ifp->info; |
| 1629 | |
| 1630 | /* Version 1 and 2. */ |
| 1631 | ri->ri_send = RI_RIP_VERSION_1_AND_2; |
| 1632 | return CMD_SUCCESS; |
| 1633 | } |
| 1634 | |
| 1635 | DEFUN (no_ip_rip_send_version, |
| 1636 | no_ip_rip_send_version_cmd, |
| 1637 | "no ip rip send version", |
| 1638 | NO_STR |
| 1639 | IP_STR |
| 1640 | "Routing Information Protocol\n" |
| 1641 | "Advertisement transmission\n" |
| 1642 | "Version control\n") |
| 1643 | { |
| 1644 | struct interface *ifp; |
| 1645 | struct rip_interface *ri; |
| 1646 | |
| 1647 | ifp = (struct interface *)vty->index; |
| 1648 | ri = ifp->info; |
| 1649 | |
| 1650 | ri->ri_send = RI_RIP_UNSPEC; |
| 1651 | return CMD_SUCCESS; |
| 1652 | } |
| 1653 | |
| 1654 | ALIAS (no_ip_rip_send_version, |
| 1655 | no_ip_rip_send_version_num_cmd, |
| 1656 | "no ip rip send version (1|2)", |
| 1657 | NO_STR |
| 1658 | IP_STR |
| 1659 | "Routing Information Protocol\n" |
| 1660 | "Advertisement transmission\n" |
| 1661 | "Version control\n" |
| 1662 | "Version 1\n" |
| 1663 | "Version 2\n") |
| 1664 | |
| 1665 | DEFUN (ip_rip_authentication_mode, |
| 1666 | ip_rip_authentication_mode_cmd, |
| 1667 | "ip rip authentication mode (md5|text)", |
| 1668 | IP_STR |
| 1669 | "Routing Information Protocol\n" |
| 1670 | "Authentication control\n" |
| 1671 | "Authentication mode\n" |
| 1672 | "Keyed message digest\n" |
| 1673 | "Clear text authentication\n") |
| 1674 | { |
| 1675 | struct interface *ifp; |
| 1676 | struct rip_interface *ri; |
| 1677 | |
| 1678 | ifp = (struct interface *)vty->index; |
| 1679 | ri = ifp->info; |
| 1680 | |
| 1681 | if (strncmp ("md5", argv[0], strlen (argv[0])) == 0) |
| 1682 | ri->auth_type = RIP_AUTH_MD5; |
| 1683 | else if (strncmp ("text", argv[0], strlen (argv[0])) == 0) |
| 1684 | ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD; |
| 1685 | else |
| 1686 | { |
| 1687 | vty_out (vty, "mode should be md5 or text%s", VTY_NEWLINE); |
| 1688 | return CMD_WARNING; |
| 1689 | } |
| 1690 | |
| 1691 | return CMD_SUCCESS; |
| 1692 | } |
| 1693 | |
| 1694 | DEFUN (no_ip_rip_authentication_mode, |
| 1695 | no_ip_rip_authentication_mode_cmd, |
| 1696 | "no ip rip authentication mode", |
| 1697 | NO_STR |
| 1698 | IP_STR |
| 1699 | "Routing Information Protocol\n" |
| 1700 | "Authentication control\n" |
| 1701 | "Authentication mode\n") |
| 1702 | { |
| 1703 | struct interface *ifp; |
| 1704 | struct rip_interface *ri; |
| 1705 | |
| 1706 | ifp = (struct interface *)vty->index; |
| 1707 | ri = ifp->info; |
| 1708 | |
| 1709 | /* ri->auth_type = RIP_NO_AUTH; */ |
| 1710 | ri->auth_type = RIP_AUTH_SIMPLE_PASSWORD; |
| 1711 | |
| 1712 | return CMD_SUCCESS; |
| 1713 | } |
| 1714 | |
| 1715 | ALIAS (no_ip_rip_authentication_mode, |
| 1716 | no_ip_rip_authentication_mode_type_cmd, |
| 1717 | "no ip rip authentication mode (md5|text)", |
| 1718 | NO_STR |
| 1719 | IP_STR |
| 1720 | "Routing Information Protocol\n" |
| 1721 | "Authentication control\n" |
| 1722 | "Authentication mode\n" |
| 1723 | "Keyed message digest\n" |
| 1724 | "Clear text authentication\n") |
| 1725 | |
| 1726 | DEFUN (ip_rip_authentication_string, |
| 1727 | ip_rip_authentication_string_cmd, |
| 1728 | "ip rip authentication string LINE", |
| 1729 | IP_STR |
| 1730 | "Routing Information Protocol\n" |
| 1731 | "Authentication control\n" |
| 1732 | "Authentication string\n" |
| 1733 | "Authentication string\n") |
| 1734 | { |
| 1735 | struct interface *ifp; |
| 1736 | struct rip_interface *ri; |
| 1737 | |
| 1738 | ifp = (struct interface *)vty->index; |
| 1739 | ri = ifp->info; |
| 1740 | |
| 1741 | if (strlen (argv[0]) > 16) |
| 1742 | { |
| 1743 | vty_out (vty, "%% RIPv2 authentication string must be shorter than 16%s", |
| 1744 | VTY_NEWLINE); |
| 1745 | return CMD_WARNING; |
| 1746 | } |
| 1747 | |
| 1748 | if (ri->key_chain) |
| 1749 | { |
| 1750 | vty_out (vty, "%% key-chain configuration exists%s", VTY_NEWLINE); |
| 1751 | return CMD_WARNING; |
| 1752 | } |
| 1753 | |
| 1754 | if (ri->auth_str) |
| 1755 | free (ri->auth_str); |
| 1756 | |
| 1757 | ri->auth_str = strdup (argv[0]); |
| 1758 | |
| 1759 | return CMD_SUCCESS; |
| 1760 | } |
| 1761 | |
| 1762 | DEFUN (no_ip_rip_authentication_string, |
| 1763 | no_ip_rip_authentication_string_cmd, |
| 1764 | "no ip rip authentication string", |
| 1765 | NO_STR |
| 1766 | IP_STR |
| 1767 | "Routing Information Protocol\n" |
| 1768 | "Authentication control\n" |
| 1769 | "Authentication string\n") |
| 1770 | { |
| 1771 | struct interface *ifp; |
| 1772 | struct rip_interface *ri; |
| 1773 | |
| 1774 | ifp = (struct interface *)vty->index; |
| 1775 | ri = ifp->info; |
| 1776 | |
| 1777 | if (ri->auth_str) |
| 1778 | free (ri->auth_str); |
| 1779 | |
| 1780 | ri->auth_str = NULL; |
| 1781 | |
| 1782 | return CMD_SUCCESS; |
| 1783 | } |
| 1784 | |
| 1785 | ALIAS (no_ip_rip_authentication_string, |
| 1786 | no_ip_rip_authentication_string2_cmd, |
| 1787 | "no ip rip authentication string LINE", |
| 1788 | NO_STR |
| 1789 | IP_STR |
| 1790 | "Routing Information Protocol\n" |
| 1791 | "Authentication control\n" |
| 1792 | "Authentication string\n" |
| 1793 | "Authentication string\n") |
| 1794 | |
| 1795 | DEFUN (ip_rip_authentication_key_chain, |
| 1796 | ip_rip_authentication_key_chain_cmd, |
| 1797 | "ip rip authentication key-chain LINE", |
| 1798 | IP_STR |
| 1799 | "Routing Information Protocol\n" |
| 1800 | "Authentication control\n" |
| 1801 | "Authentication key-chain\n" |
| 1802 | "name of key-chain\n") |
| 1803 | { |
| 1804 | struct interface *ifp; |
| 1805 | struct rip_interface *ri; |
| 1806 | |
| 1807 | ifp = (struct interface *) vty->index; |
| 1808 | ri = ifp->info; |
| 1809 | |
| 1810 | if (ri->auth_str) |
| 1811 | { |
| 1812 | vty_out (vty, "%% authentication string configuration exists%s", |
| 1813 | VTY_NEWLINE); |
| 1814 | return CMD_WARNING; |
| 1815 | } |
| 1816 | |
| 1817 | if (ri->key_chain) |
| 1818 | free (ri->key_chain); |
| 1819 | |
| 1820 | ri->key_chain = strdup (argv[0]); |
| 1821 | |
| 1822 | return CMD_SUCCESS; |
| 1823 | } |
| 1824 | |
| 1825 | DEFUN (no_ip_rip_authentication_key_chain, |
| 1826 | no_ip_rip_authentication_key_chain_cmd, |
| 1827 | "no ip rip authentication key-chain", |
| 1828 | NO_STR |
| 1829 | IP_STR |
| 1830 | "Routing Information Protocol\n" |
| 1831 | "Authentication control\n" |
| 1832 | "Authentication key-chain\n") |
| 1833 | { |
| 1834 | struct interface *ifp; |
| 1835 | struct rip_interface *ri; |
| 1836 | |
| 1837 | ifp = (struct interface *) vty->index; |
| 1838 | ri = ifp->info; |
| 1839 | |
| 1840 | if (ri->key_chain) |
| 1841 | free (ri->key_chain); |
| 1842 | |
| 1843 | ri->key_chain = NULL; |
| 1844 | |
| 1845 | return CMD_SUCCESS; |
| 1846 | } |
| 1847 | |
| 1848 | ALIAS (no_ip_rip_authentication_key_chain, |
| 1849 | no_ip_rip_authentication_key_chain2_cmd, |
| 1850 | "no ip rip authentication key-chain LINE", |
| 1851 | NO_STR |
| 1852 | IP_STR |
| 1853 | "Routing Information Protocol\n" |
| 1854 | "Authentication control\n" |
| 1855 | "Authentication key-chain\n" |
| 1856 | "name of key-chain\n") |
| 1857 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1858 | /* CHANGED: ip rip split-horizon |
| 1859 | Cisco and Zebra's command is |
| 1860 | ip split-horizon |
| 1861 | */ |
| 1862 | DEFUN (ip_rip_split_horizon, |
| 1863 | ip_rip_split_horizon_cmd, |
| 1864 | "ip rip split-horizon", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1865 | IP_STR |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1866 | "Routing Information Protocol\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1867 | "Perform split horizon\n") |
| 1868 | { |
| 1869 | struct interface *ifp; |
| 1870 | struct rip_interface *ri; |
| 1871 | |
| 1872 | ifp = vty->index; |
| 1873 | ri = ifp->info; |
| 1874 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1875 | ri->split_horizon = RIP_SPLIT_HORIZON; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1876 | return CMD_SUCCESS; |
| 1877 | } |
| 1878 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1879 | DEFUN (ip_rip_split_horizon_poisoned_reverse, |
| 1880 | ip_rip_split_horizon_poisoned_reverse_cmd, |
| 1881 | "ip rip split-horizon poisoned-reverse", |
| 1882 | IP_STR |
| 1883 | "Routing Information Protocol\n" |
| 1884 | "Perform split horizon\n" |
| 1885 | "With poisoned-reverse\n") |
| 1886 | { |
| 1887 | struct interface *ifp; |
| 1888 | struct rip_interface *ri; |
| 1889 | |
| 1890 | ifp = vty->index; |
| 1891 | ri = ifp->info; |
| 1892 | |
| 1893 | ri->split_horizon = RIP_SPLIT_HORIZON_POISONED_REVERSE; |
| 1894 | return CMD_SUCCESS; |
| 1895 | } |
| 1896 | |
| 1897 | /* CHANGED: no ip rip split-horizon |
| 1898 | Cisco and Zebra's command is |
| 1899 | no ip split-horizon |
| 1900 | */ |
| 1901 | DEFUN (no_ip_rip_split_horizon, |
| 1902 | no_ip_rip_split_horizon_cmd, |
| 1903 | "no ip rip split-horizon", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1904 | NO_STR |
| 1905 | IP_STR |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1906 | "Routing Information Protocol\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1907 | "Perform split horizon\n") |
| 1908 | { |
| 1909 | struct interface *ifp; |
| 1910 | struct rip_interface *ri; |
| 1911 | |
| 1912 | ifp = vty->index; |
| 1913 | ri = ifp->info; |
| 1914 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1915 | ri->split_horizon = RIP_NO_SPLIT_HORIZON; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1916 | return CMD_SUCCESS; |
| 1917 | } |
| 1918 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1919 | ALIAS (no_ip_rip_split_horizon, |
| 1920 | no_ip_rip_split_horizon_poisoned_reverse_cmd, |
| 1921 | "no ip rip split-horizon poisoned-reverse", |
| 1922 | NO_STR |
| 1923 | IP_STR |
| 1924 | "Routing Information Protocol\n" |
| 1925 | "Perform split horizon\n" |
| 1926 | "With poisoned-reverse\n") |
| 1927 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1928 | DEFUN (rip_passive_interface, |
| 1929 | rip_passive_interface_cmd, |
paul | 56e475c | 2003-06-20 00:23:27 +0000 | [diff] [blame] | 1930 | "passive-interface (IFNAME|default)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1931 | "Suppress routing updates on an interface\n" |
paul | 56e475c | 2003-06-20 00:23:27 +0000 | [diff] [blame] | 1932 | "Interface name\n" |
| 1933 | "default for all interfaces\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1934 | { |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1935 | char *ifname = argv[0]; |
| 1936 | |
| 1937 | if (!strcmp(ifname,"default")) { |
| 1938 | passive_default = 1; |
| 1939 | rip_passive_nondefault_clean(); |
| 1940 | return CMD_SUCCESS; |
| 1941 | } |
| 1942 | if (passive_default) |
| 1943 | return rip_passive_nondefault_unset (vty, ifname); |
| 1944 | else |
| 1945 | return rip_passive_nondefault_set (vty, ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | DEFUN (no_rip_passive_interface, |
| 1949 | no_rip_passive_interface_cmd, |
paul | 56e475c | 2003-06-20 00:23:27 +0000 | [diff] [blame] | 1950 | "no passive-interface (IFNAME|default)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1951 | NO_STR |
| 1952 | "Suppress routing updates on an interface\n" |
paul | 56e475c | 2003-06-20 00:23:27 +0000 | [diff] [blame] | 1953 | "Interface name\n" |
| 1954 | "default for all interfaces\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1955 | { |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 1956 | char *ifname = argv[0]; |
| 1957 | |
| 1958 | if (!strcmp(ifname,"default")) { |
| 1959 | passive_default = 0; |
| 1960 | rip_passive_nondefault_clean(); |
| 1961 | return CMD_SUCCESS; |
| 1962 | } |
| 1963 | if (passive_default) |
| 1964 | return rip_passive_nondefault_set (vty, ifname); |
| 1965 | else |
| 1966 | return rip_passive_nondefault_unset (vty, ifname); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | /* Write rip configuration of each interface. */ |
| 1970 | int |
| 1971 | rip_interface_config_write (struct vty *vty) |
| 1972 | { |
| 1973 | listnode node; |
| 1974 | struct interface *ifp; |
| 1975 | |
| 1976 | for (node = listhead (iflist); node; nextnode (node)) |
| 1977 | { |
| 1978 | struct rip_interface *ri; |
| 1979 | |
| 1980 | ifp = getdata (node); |
| 1981 | ri = ifp->info; |
| 1982 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 1983 | /* Do not display the interface if there is no |
| 1984 | * configuration about it. |
| 1985 | **/ |
| 1986 | if ((!ifp->desc) && |
| 1987 | (ri->split_horizon == ri->split_horizon_default) && |
| 1988 | (ri->ri_send == RI_RIP_UNSPEC) && |
| 1989 | (ri->ri_receive == RI_RIP_UNSPEC) && |
| 1990 | (ri->auth_type != RIP_AUTH_MD5) && |
| 1991 | (!ri->auth_str) && |
| 1992 | (!ri->key_chain) ) |
| 1993 | continue; |
| 1994 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1995 | vty_out (vty, "interface %s%s", ifp->name, |
| 1996 | VTY_NEWLINE); |
| 1997 | |
| 1998 | if (ifp->desc) |
| 1999 | vty_out (vty, " description %s%s", ifp->desc, |
| 2000 | VTY_NEWLINE); |
| 2001 | |
| 2002 | /* Split horizon. */ |
| 2003 | if (ri->split_horizon != ri->split_horizon_default) |
| 2004 | { |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 2005 | switch (ri->split_horizon) { |
| 2006 | case RIP_SPLIT_HORIZON: |
| 2007 | vty_out (vty, " ip rip split-horizon%s", VTY_NEWLINE); |
| 2008 | break; |
| 2009 | case RIP_SPLIT_HORIZON_POISONED_REVERSE: |
| 2010 | vty_out (vty, " ip rip split-horizon poisoned-reverse%s", |
| 2011 | VTY_NEWLINE); |
| 2012 | break; |
| 2013 | case RIP_NO_SPLIT_HORIZON: |
| 2014 | default: |
| 2015 | vty_out (vty, " no ip rip split-horizon%s", VTY_NEWLINE); |
| 2016 | break; |
| 2017 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | /* RIP version setting. */ |
| 2021 | if (ri->ri_send != RI_RIP_UNSPEC) |
| 2022 | vty_out (vty, " ip rip send version %s%s", |
| 2023 | lookup (ri_version_msg, ri->ri_send), |
| 2024 | VTY_NEWLINE); |
| 2025 | |
| 2026 | if (ri->ri_receive != RI_RIP_UNSPEC) |
| 2027 | vty_out (vty, " ip rip receive version %s%s", |
| 2028 | lookup (ri_version_msg, ri->ri_receive), |
| 2029 | VTY_NEWLINE); |
| 2030 | |
| 2031 | /* RIP authentication. */ |
| 2032 | #if 0 |
| 2033 | /* RIP_AUTH_SIMPLE_PASSWORD becomes default mode. */ |
| 2034 | if (ri->auth_type == RIP_AUTH_SIMPLE_PASSWORD) |
| 2035 | vty_out (vty, " ip rip authentication mode text%s", VTY_NEWLINE); |
| 2036 | #endif /* 0 */ |
| 2037 | if (ri->auth_type == RIP_AUTH_MD5) |
| 2038 | vty_out (vty, " ip rip authentication mode md5%s", VTY_NEWLINE); |
| 2039 | |
| 2040 | if (ri->auth_str) |
| 2041 | vty_out (vty, " ip rip authentication string %s%s", |
| 2042 | ri->auth_str, VTY_NEWLINE); |
| 2043 | |
| 2044 | if (ri->key_chain) |
| 2045 | vty_out (vty, " ip rip authentication key-chain %s%s", |
| 2046 | ri->key_chain, VTY_NEWLINE); |
| 2047 | |
| 2048 | vty_out (vty, "!%s", VTY_NEWLINE); |
| 2049 | } |
| 2050 | return 0; |
| 2051 | } |
| 2052 | |
| 2053 | int |
| 2054 | config_write_rip_network (struct vty *vty, int config_mode) |
| 2055 | { |
| 2056 | int i; |
| 2057 | char *ifname; |
| 2058 | struct route_node *node; |
| 2059 | |
| 2060 | /* Network type RIP enable interface statement. */ |
| 2061 | for (node = route_top (rip_enable_network); node; node = route_next (node)) |
| 2062 | if (node->info) |
| 2063 | vty_out (vty, "%s%s/%d%s", |
| 2064 | config_mode ? " network " : " ", |
| 2065 | inet_ntoa (node->p.u.prefix4), |
| 2066 | node->p.prefixlen, |
| 2067 | VTY_NEWLINE); |
| 2068 | |
| 2069 | /* Interface name RIP enable statement. */ |
| 2070 | for (i = 0; i < vector_max (rip_enable_interface); i++) |
| 2071 | if ((ifname = vector_slot (rip_enable_interface, i)) != NULL) |
| 2072 | vty_out (vty, "%s%s%s", |
| 2073 | config_mode ? " network " : " ", |
| 2074 | ifname, |
| 2075 | VTY_NEWLINE); |
| 2076 | |
| 2077 | /* RIP neighbors listing. */ |
| 2078 | for (node = route_top (rip->neighbor); node; node = route_next (node)) |
| 2079 | if (node->info) |
| 2080 | vty_out (vty, "%s%s%s", |
| 2081 | config_mode ? " neighbor " : " ", |
| 2082 | inet_ntoa (node->p.u.prefix4), |
| 2083 | VTY_NEWLINE); |
| 2084 | |
| 2085 | /* RIP passive interface listing. */ |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 2086 | if (config_mode) { |
| 2087 | if (passive_default) |
paul | 01d0908 | 2003-06-08 21:22:18 +0000 | [diff] [blame] | 2088 | vty_out (vty, " passive-interface default%s", VTY_NEWLINE); |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 2089 | for (i = 0; i < vector_max (Vrip_passive_nondefault); i++) |
| 2090 | if ((ifname = vector_slot (Vrip_passive_nondefault, i)) != NULL) |
| 2091 | vty_out (vty, " %spassive-interface %s%s", |
| 2092 | (passive_default ? "no " : ""), ifname, VTY_NEWLINE); |
| 2093 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2094 | |
| 2095 | return 0; |
| 2096 | } |
| 2097 | |
| 2098 | struct cmd_node interface_node = |
| 2099 | { |
| 2100 | INTERFACE_NODE, |
| 2101 | "%s(config-if)# ", |
| 2102 | 1, |
| 2103 | }; |
| 2104 | |
| 2105 | /* Called when interface structure allocated. */ |
| 2106 | int |
| 2107 | rip_interface_new_hook (struct interface *ifp) |
| 2108 | { |
| 2109 | ifp->info = rip_interface_new (); |
| 2110 | return 0; |
| 2111 | } |
| 2112 | |
| 2113 | /* Called when interface structure deleted. */ |
| 2114 | int |
| 2115 | rip_interface_delete_hook (struct interface *ifp) |
| 2116 | { |
| 2117 | XFREE (MTYPE_RIP_INTERFACE, ifp->info); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 2118 | ifp->info = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2119 | return 0; |
| 2120 | } |
| 2121 | |
| 2122 | /* Allocate and initialize interface vector. */ |
| 2123 | void |
| 2124 | rip_if_init () |
| 2125 | { |
| 2126 | /* Default initial size of interface vector. */ |
| 2127 | if_init(); |
| 2128 | if_add_hook (IF_NEW_HOOK, rip_interface_new_hook); |
| 2129 | if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook); |
| 2130 | |
| 2131 | /* RIP network init. */ |
| 2132 | rip_enable_interface = vector_init (1); |
| 2133 | rip_enable_network = route_table_init (); |
| 2134 | |
| 2135 | /* RIP passive interface. */ |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 2136 | Vrip_passive_nondefault = vector_init (1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2137 | |
| 2138 | /* Install interface node. */ |
| 2139 | install_node (&interface_node, rip_interface_config_write); |
| 2140 | |
| 2141 | /* Install commands. */ |
| 2142 | install_element (CONFIG_NODE, &interface_cmd); |
hasso | 034489d | 2003-05-24 07:59:25 +0000 | [diff] [blame] | 2143 | install_element (CONFIG_NODE, &no_interface_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2144 | install_default (INTERFACE_NODE); |
| 2145 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
| 2146 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
| 2147 | install_element (RIP_NODE, &rip_network_cmd); |
| 2148 | install_element (RIP_NODE, &no_rip_network_cmd); |
| 2149 | install_element (RIP_NODE, &rip_neighbor_cmd); |
| 2150 | install_element (RIP_NODE, &no_rip_neighbor_cmd); |
| 2151 | |
| 2152 | install_element (RIP_NODE, &rip_passive_interface_cmd); |
| 2153 | install_element (RIP_NODE, &no_rip_passive_interface_cmd); |
| 2154 | |
| 2155 | install_element (INTERFACE_NODE, &ip_rip_send_version_cmd); |
| 2156 | install_element (INTERFACE_NODE, &ip_rip_send_version_1_cmd); |
| 2157 | install_element (INTERFACE_NODE, &ip_rip_send_version_2_cmd); |
| 2158 | install_element (INTERFACE_NODE, &no_ip_rip_send_version_cmd); |
| 2159 | install_element (INTERFACE_NODE, &no_ip_rip_send_version_num_cmd); |
| 2160 | |
| 2161 | install_element (INTERFACE_NODE, &ip_rip_receive_version_cmd); |
| 2162 | install_element (INTERFACE_NODE, &ip_rip_receive_version_1_cmd); |
| 2163 | install_element (INTERFACE_NODE, &ip_rip_receive_version_2_cmd); |
| 2164 | install_element (INTERFACE_NODE, &no_ip_rip_receive_version_cmd); |
| 2165 | install_element (INTERFACE_NODE, &no_ip_rip_receive_version_num_cmd); |
| 2166 | |
| 2167 | install_element (INTERFACE_NODE, &ip_rip_authentication_mode_cmd); |
| 2168 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_cmd); |
| 2169 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_type_cmd); |
| 2170 | |
| 2171 | install_element (INTERFACE_NODE, &ip_rip_authentication_key_chain_cmd); |
| 2172 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain_cmd); |
| 2173 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain2_cmd); |
| 2174 | |
| 2175 | install_element (INTERFACE_NODE, &ip_rip_authentication_string_cmd); |
| 2176 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_string_cmd); |
| 2177 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_string2_cmd); |
| 2178 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 2179 | install_element (INTERFACE_NODE, &ip_rip_split_horizon_cmd); |
| 2180 | install_element (INTERFACE_NODE, &ip_rip_split_horizon_poisoned_reverse_cmd); |
| 2181 | install_element (INTERFACE_NODE, &no_ip_rip_split_horizon_cmd); |
| 2182 | install_element (INTERFACE_NODE, &no_ip_rip_split_horizon_poisoned_reverse_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2183 | } |