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