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