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