]>
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 | |
3012671f DL |
45 | DEFINE_HOOK(rip_ifaddr_add, (struct connected *ifc), (ifc)) |
46 | DEFINE_HOOK(rip_ifaddr_del, (struct connected *ifc), (ifc)) | |
47 | ||
dc63bfd4 | 48 | /* static prototypes */ |
49 | static void rip_enable_apply (struct interface *); | |
50 | static void rip_passive_interface_apply (struct interface *); | |
51 | static int rip_if_down(struct interface *ifp); | |
52 | static int rip_enable_if_lookup (const char *ifname); | |
53 | static int rip_enable_network_lookup2 (struct connected *connected); | |
54 | static void rip_enable_apply_all (void); | |
6b0655a2 | 55 | |
bdcf8f59 | 56 | const struct message ri_version_msg[] = |
718e3744 | 57 | { |
58 | {RI_RIP_VERSION_1, "1"}, | |
59 | {RI_RIP_VERSION_2, "2"}, | |
60 | {RI_RIP_VERSION_1_AND_2, "1 2"}, | |
6aec4b41 | 61 | {RI_RIP_VERSION_NONE, "none"}, |
718e3744 | 62 | }; |
63 | ||
edd7c245 | 64 | extern struct zebra_privs_t ripd_privs; |
65 | ||
718e3744 | 66 | /* RIP enabled network vector. */ |
67 | vector rip_enable_interface; | |
68 | ||
69 | /* RIP enabled interface table. */ | |
70 | struct route_table *rip_enable_network; | |
71 | ||
72 | /* Vector to store passive-interface name. */ | |
4aaff3f8 | 73 | static int passive_default; /* are we in passive-interface default mode? */ |
74 | vector Vrip_passive_nondefault; | |
6b0655a2 | 75 | |
718e3744 | 76 | /* Join to the RIP version 2 multicast group. */ |
dc63bfd4 | 77 | static int |
718e3744 | 78 | ipv4_multicast_join (int sock, |
79 | struct in_addr group, | |
80 | struct in_addr ifa, | |
b892f1dd | 81 | ifindex_t ifindex) |
718e3744 | 82 | { |
83 | int ret; | |
84 | ||
69bf3a39 | 85 | ret = setsockopt_ipv4_multicast (sock, |
718e3744 | 86 | IP_ADD_MEMBERSHIP, |
4a3867d0 | 87 | ifa, |
718e3744 | 88 | group.s_addr, |
89 | ifindex); | |
90 | ||
91 | if (ret < 0) | |
4525281a | 92 | zlog_info("can't setsockopt IP_ADD_MEMBERSHIP %s", safe_strerror(errno)); |
718e3744 | 93 | |
94 | return ret; | |
95 | } | |
96 | ||
97 | /* Leave from the RIP version 2 multicast group. */ | |
dc63bfd4 | 98 | static int |
718e3744 | 99 | ipv4_multicast_leave (int sock, |
100 | struct in_addr group, | |
101 | struct in_addr ifa, | |
b892f1dd | 102 | ifindex_t ifindex) |
718e3744 | 103 | { |
104 | int ret; | |
105 | ||
69bf3a39 | 106 | ret = setsockopt_ipv4_multicast (sock, |
718e3744 | 107 | IP_DROP_MEMBERSHIP, |
4a3867d0 | 108 | ifa, |
718e3744 | 109 | group.s_addr, |
110 | ifindex); | |
111 | ||
112 | if (ret < 0) | |
4525281a | 113 | zlog_info("can't setsockopt IP_DROP_MEMBERSHIP"); |
718e3744 | 114 | |
115 | return ret; | |
116 | } | |
6b0655a2 | 117 | |
1dec2166 PJ |
118 | static void rip_interface_reset (struct rip_interface *); |
119 | ||
718e3744 | 120 | /* Allocate new RIP's interface configuration. */ |
dc63bfd4 | 121 | static struct rip_interface * |
122 | rip_interface_new (void) | |
718e3744 | 123 | { |
124 | struct rip_interface *ri; | |
125 | ||
393deb9b | 126 | ri = XCALLOC (MTYPE_RIP_INTERFACE, sizeof (struct rip_interface)); |
718e3744 | 127 | |
1dec2166 | 128 | rip_interface_reset (ri); |
718e3744 | 129 | |
130 | return ri; | |
131 | } | |
132 | ||
133 | void | |
1a51786a | 134 | rip_interface_multicast_set (int sock, struct connected *connected) |
718e3744 | 135 | { |
4a3867d0 RW |
136 | struct in_addr addr; |
137 | ||
c49ad8f1 | 138 | assert (connected != NULL); |
4a3867d0 RW |
139 | |
140 | addr = CONNECTED_ID(connected)->u.prefix4; | |
141 | ||
142 | if (setsockopt_ipv4_multicast_if (sock, addr, connected->ifp->ifindex) < 0) | |
3fb9cd6e | 143 | { |
144 | zlog_warn ("Can't setsockopt IP_MULTICAST_IF on fd %d to " | |
69bf3a39 DT |
145 | "ifindex %d for interface %s", |
146 | sock, connected->ifp->ifindex, | |
c49ad8f1 | 147 | connected->ifp->name); |
3fb9cd6e | 148 | } |
2c61ae37 | 149 | |
3fb9cd6e | 150 | return; |
151 | } | |
718e3744 | 152 | |
153 | /* Send RIP request packet to specified interface. */ | |
dc63bfd4 | 154 | static void |
718e3744 | 155 | rip_request_interface_send (struct interface *ifp, u_char version) |
156 | { | |
157 | struct sockaddr_in to; | |
158 | ||
159 | /* RIPv2 support multicast. */ | |
160 | if (version == RIPv2 && if_is_multicast (ifp)) | |
161 | { | |
162 | ||
163 | if (IS_RIP_DEBUG_EVENT) | |
5d6c3779 | 164 | zlog_debug ("multicast request on %s", ifp->name); |
718e3744 | 165 | |
931cd54d | 166 | rip_request_send (NULL, ifp, version, NULL); |
718e3744 | 167 | return; |
168 | } | |
169 | ||
170 | /* RIPv1 and non multicast interface. */ | |
171 | if (if_is_pointopoint (ifp) || if_is_broadcast (ifp)) | |
172 | { | |
1eb8ef25 | 173 | struct listnode *cnode, *cnnode; |
174 | struct connected *connected; | |
718e3744 | 175 | |
176 | if (IS_RIP_DEBUG_EVENT) | |
5d6c3779 | 177 | zlog_debug ("broadcast request to %s", ifp->name); |
718e3744 | 178 | |
1eb8ef25 | 179 | for (ALL_LIST_ELEMENTS (ifp->connected, cnode, cnnode, connected)) |
718e3744 | 180 | { |
3fb9cd6e | 181 | if (connected->address->family == AF_INET) |
718e3744 | 182 | { |
183 | memset (&to, 0, sizeof (struct sockaddr_in)); | |
184 | to.sin_port = htons (RIP_PORT_DEFAULT); | |
3fb9cd6e | 185 | if (connected->destination) |
e4529636 | 186 | /* use specified broadcast or peer destination addr */ |
3fb9cd6e | 187 | to.sin_addr = connected->destination->u.prefix4; |
e4529636 | 188 | else if (connected->address->prefixlen < IPV4_MAX_PREFIXLEN) |
3fb9cd6e | 189 | /* calculate the appropriate broadcast address */ |
190 | to.sin_addr.s_addr = | |
191 | ipv4_broadcast_addr(connected->address->u.prefix4.s_addr, | |
192 | connected->address->prefixlen); | |
e4529636 AS |
193 | else |
194 | /* do not know where to send the packet */ | |
195 | continue; | |
718e3744 | 196 | |
718e3744 | 197 | if (IS_RIP_DEBUG_EVENT) |
5d6c3779 | 198 | zlog_debug ("SEND request to %s", inet_ntoa (to.sin_addr)); |
718e3744 | 199 | |
931cd54d | 200 | rip_request_send (&to, ifp, version, connected); |
718e3744 | 201 | } |
202 | } | |
203 | } | |
204 | } | |
205 | ||
206 | /* This will be executed when interface goes up. */ | |
dc63bfd4 | 207 | static void |
718e3744 | 208 | rip_request_interface (struct interface *ifp) |
209 | { | |
210 | struct rip_interface *ri; | |
211 | ||
212 | /* In default ripd doesn't send RIP_REQUEST to the loopback interface. */ | |
213 | if (if_is_loopback (ifp)) | |
214 | return; | |
215 | ||
216 | /* If interface is down, don't send RIP packet. */ | |
2e3b2e47 | 217 | if (! if_is_operative (ifp)) |
718e3744 | 218 | return; |
219 | ||
220 | /* Fetch RIP interface information. */ | |
221 | ri = ifp->info; | |
222 | ||
223 | ||
224 | /* If there is no version configuration in the interface, | |
225 | use rip's version setting. */ | |
f38a471c | 226 | { |
227 | int vsend = ((ri->ri_send == RI_RIP_UNSPEC) ? | |
228 | rip->version_send : ri->ri_send); | |
229 | if (vsend & RIPv1) | |
230 | rip_request_interface_send (ifp, RIPv1); | |
231 | if (vsend & RIPv2) | |
232 | rip_request_interface_send (ifp, RIPv2); | |
233 | } | |
718e3744 | 234 | } |
235 | ||
2c239705 | 236 | #if 0 |
718e3744 | 237 | /* Send RIP request to the neighbor. */ |
dc63bfd4 | 238 | static void |
718e3744 | 239 | rip_request_neighbor (struct in_addr addr) |
240 | { | |
241 | struct sockaddr_in to; | |
242 | ||
243 | memset (&to, 0, sizeof (struct sockaddr_in)); | |
244 | to.sin_port = htons (RIP_PORT_DEFAULT); | |
245 | to.sin_addr = addr; | |
246 | ||
931cd54d | 247 | rip_request_send (&to, NULL, rip->version_send, NULL); |
718e3744 | 248 | } |
249 | ||
250 | /* Request routes at all interfaces. */ | |
dc63bfd4 | 251 | static void |
252 | rip_request_neighbor_all (void) | |
718e3744 | 253 | { |
254 | struct route_node *rp; | |
255 | ||
256 | if (! rip) | |
257 | return; | |
258 | ||
259 | if (IS_RIP_DEBUG_EVENT) | |
5d6c3779 | 260 | zlog_debug ("request to the all neighbor"); |
718e3744 | 261 | |
262 | /* Send request to all neighbor. */ | |
263 | for (rp = route_top (rip->neighbor); rp; rp = route_next (rp)) | |
264 | if (rp->info) | |
265 | rip_request_neighbor (rp->p.u.prefix4); | |
266 | } | |
2c239705 | 267 | #endif |
718e3744 | 268 | |
269 | /* Multicast packet receive socket. */ | |
dc63bfd4 | 270 | static int |
718e3744 | 271 | rip_multicast_join (struct interface *ifp, int sock) |
272 | { | |
52dc7ee6 | 273 | struct listnode *cnode; |
1eb8ef25 | 274 | struct connected *ifc; |
718e3744 | 275 | |
2e3b2e47 | 276 | if (if_is_operative (ifp) && if_is_multicast (ifp)) |
718e3744 | 277 | { |
278 | if (IS_RIP_DEBUG_EVENT) | |
5d6c3779 | 279 | zlog_debug ("multicast join at %s", ifp->name); |
718e3744 | 280 | |
1eb8ef25 | 281 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, ifc)) |
718e3744 | 282 | { |
283 | struct prefix_ipv4 *p; | |
718e3744 | 284 | struct in_addr group; |
285 | ||
1eb8ef25 | 286 | p = (struct prefix_ipv4 *) ifc->address; |
718e3744 | 287 | |
288 | if (p->family != AF_INET) | |
289 | continue; | |
290 | ||
291 | group.s_addr = htonl (INADDR_RIP_GROUP); | |
292 | if (ipv4_multicast_join (sock, group, p->prefix, ifp->ifindex) < 0) | |
293 | return -1; | |
294 | else | |
295 | return 0; | |
296 | } | |
297 | } | |
298 | return 0; | |
299 | } | |
300 | ||
301 | /* Leave from multicast group. */ | |
dc63bfd4 | 302 | static void |
718e3744 | 303 | rip_multicast_leave (struct interface *ifp, int sock) |
304 | { | |
52dc7ee6 | 305 | struct listnode *cnode; |
1eb8ef25 | 306 | struct connected *connected; |
718e3744 | 307 | |
308 | if (if_is_up (ifp) && if_is_multicast (ifp)) | |
309 | { | |
310 | if (IS_RIP_DEBUG_EVENT) | |
5d6c3779 | 311 | zlog_debug ("multicast leave from %s", ifp->name); |
718e3744 | 312 | |
1eb8ef25 | 313 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
718e3744 | 314 | { |
315 | struct prefix_ipv4 *p; | |
718e3744 | 316 | struct in_addr group; |
1eb8ef25 | 317 | |
718e3744 | 318 | p = (struct prefix_ipv4 *) connected->address; |
1eb8ef25 | 319 | |
718e3744 | 320 | if (p->family != AF_INET) |
321 | continue; | |
322 | ||
323 | group.s_addr = htonl (INADDR_RIP_GROUP); | |
324 | if (ipv4_multicast_leave (sock, group, p->prefix, ifp->ifindex) == 0) | |
325 | return; | |
326 | } | |
327 | } | |
328 | } | |
329 | ||
330 | /* Is there and address on interface that I could use ? */ | |
dc63bfd4 | 331 | static int |
718e3744 | 332 | rip_if_ipv4_address_check (struct interface *ifp) |
333 | { | |
334 | struct listnode *nn; | |
335 | struct connected *connected; | |
336 | int count = 0; | |
337 | ||
1eb8ef25 | 338 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, nn, connected)) |
339 | { | |
340 | struct prefix *p; | |
718e3744 | 341 | |
1eb8ef25 | 342 | p = connected->address; |
718e3744 | 343 | |
1eb8ef25 | 344 | if (p->family == AF_INET) |
345 | count++; | |
346 | } | |
718e3744 | 347 | |
348 | return count; | |
349 | } | |
31a476c7 | 350 | |
351 | ||
352 | ||
353 | ||
354 | /* Does this address belongs to me ? */ | |
355 | int | |
356 | if_check_address (struct in_addr addr) | |
357 | { | |
52dc7ee6 | 358 | struct listnode *node; |
1eb8ef25 | 359 | struct interface *ifp; |
360 | ||
b2d7c082 | 361 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp)) |
31a476c7 | 362 | { |
52dc7ee6 | 363 | struct listnode *cnode; |
1eb8ef25 | 364 | struct connected *connected; |
31a476c7 | 365 | |
1eb8ef25 | 366 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) |
31a476c7 | 367 | { |
31a476c7 | 368 | struct prefix_ipv4 *p; |
369 | ||
31a476c7 | 370 | p = (struct prefix_ipv4 *) connected->address; |
371 | ||
372 | if (p->family != AF_INET) | |
373 | continue; | |
374 | ||
375 | if (IPV4_ADDR_CMP (&p->prefix, &addr) == 0) | |
376 | return 1; | |
377 | } | |
378 | } | |
379 | return 0; | |
380 | } | |
381 | ||
718e3744 | 382 | /* Inteface link down message processing. */ |
383 | int | |
7076bb2f FL |
384 | rip_interface_down (int command, struct zclient *zclient, zebra_size_t length, |
385 | vrf_id_t vrf_id) | |
718e3744 | 386 | { |
387 | struct interface *ifp; | |
388 | struct stream *s; | |
389 | ||
390 | s = zclient->ibuf; | |
391 | ||
392 | /* zebra_interface_state_read() updates interface structure in | |
393 | iflist. */ | |
7076bb2f | 394 | ifp = zebra_interface_state_read (s, vrf_id); |
718e3744 | 395 | |
396 | if (ifp == NULL) | |
397 | return 0; | |
398 | ||
399 | rip_if_down(ifp); | |
400 | ||
401 | if (IS_RIP_DEBUG_ZEBRA) | |
30d20590 SH |
402 | zlog_debug ("interface %s index %d flags %llx metric %d mtu %d is down", |
403 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, | |
404 | ifp->metric, ifp->mtu); | |
718e3744 | 405 | |
406 | return 0; | |
407 | } | |
408 | ||
409 | /* Inteface link up message processing */ | |
410 | int | |
7076bb2f FL |
411 | rip_interface_up (int command, struct zclient *zclient, zebra_size_t length, |
412 | vrf_id_t vrf_id) | |
718e3744 | 413 | { |
414 | struct interface *ifp; | |
415 | ||
416 | /* zebra_interface_state_read () updates interface structure in | |
417 | iflist. */ | |
7076bb2f | 418 | ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); |
718e3744 | 419 | |
420 | if (ifp == NULL) | |
421 | return 0; | |
422 | ||
423 | if (IS_RIP_DEBUG_ZEBRA) | |
2c239705 SH |
424 | zlog_debug ("interface %s index %d flags %#llx metric %d mtu %d is up", |
425 | ifp->name, ifp->ifindex, (unsigned long long) ifp->flags, | |
426 | ifp->metric, ifp->mtu); | |
718e3744 | 427 | |
428 | /* Check if this interface is RIP enabled or not.*/ | |
429 | rip_enable_apply (ifp); | |
430 | ||
431 | /* Check for a passive interface */ | |
432 | rip_passive_interface_apply (ifp); | |
433 | ||
434 | /* Apply distribute list to the all interface. */ | |
435 | rip_distribute_update_interface (ifp); | |
436 | ||
437 | return 0; | |
438 | } | |
439 | ||
440 | /* Inteface addition message from zebra. */ | |
441 | int | |
7076bb2f FL |
442 | rip_interface_add (int command, struct zclient *zclient, zebra_size_t length, |
443 | vrf_id_t vrf_id) | |
718e3744 | 444 | { |
445 | struct interface *ifp; | |
446 | ||
7076bb2f | 447 | ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); |
718e3744 | 448 | |
449 | if (IS_RIP_DEBUG_ZEBRA) | |
2c239705 SH |
450 | zlog_debug ("interface add %s index %d flags %#llx metric %d mtu %d", |
451 | ifp->name, ifp->ifindex, (unsigned long long) ifp->flags, | |
452 | ifp->metric, ifp->mtu); | |
718e3744 | 453 | |
454 | /* Check if this interface is RIP enabled or not.*/ | |
455 | rip_enable_apply (ifp); | |
d4e47287 | 456 | |
457 | /* Check for a passive interface */ | |
458 | rip_passive_interface_apply (ifp); | |
718e3744 | 459 | |
460 | /* Apply distribute list to the all interface. */ | |
461 | rip_distribute_update_interface (ifp); | |
462 | ||
463 | /* rip_request_neighbor_all (); */ | |
464 | ||
16705130 | 465 | /* Check interface routemap. */ |
466 | rip_if_rmap_update_interface (ifp); | |
467 | ||
718e3744 | 468 | return 0; |
469 | } | |
470 | ||
471 | int | |
472 | rip_interface_delete (int command, struct zclient *zclient, | |
7076bb2f | 473 | zebra_size_t length, vrf_id_t vrf_id) |
718e3744 | 474 | { |
475 | struct interface *ifp; | |
476 | struct stream *s; | |
477 | ||
478 | ||
479 | s = zclient->ibuf; | |
480 | /* zebra_interface_state_read() updates interface structure in iflist */ | |
7076bb2f | 481 | ifp = zebra_interface_state_read (s, vrf_id); |
718e3744 | 482 | |
483 | if (ifp == NULL) | |
484 | return 0; | |
485 | ||
486 | if (if_is_up (ifp)) { | |
487 | rip_if_down(ifp); | |
488 | } | |
489 | ||
2c239705 SH |
490 | zlog_info("interface delete %s index %d flags %#llx metric %d mtu %d", |
491 | ifp->name, ifp->ifindex, (unsigned long long) ifp->flags, | |
492 | ifp->metric, ifp->mtu); | |
718e3744 | 493 | |
494 | /* To support pseudo interface do not free interface structure. */ | |
495 | /* if_delete(ifp); */ | |
84361d61 | 496 | ifp->ifindex = IFINDEX_DELETED; |
718e3744 | 497 | |
498 | return 0; | |
499 | } | |
500 | ||
1dec2166 PJ |
501 | static void |
502 | rip_interface_clean (struct rip_interface *ri) | |
4305dfd1 RW |
503 | { |
504 | ri->enable_network = 0; | |
505 | ri->enable_interface = 0; | |
506 | ri->running = 0; | |
718e3744 | 507 | |
4305dfd1 RW |
508 | if (ri->t_wakeup) |
509 | { | |
510 | thread_cancel (ri->t_wakeup); | |
511 | ri->t_wakeup = NULL; | |
718e3744 | 512 | } |
4305dfd1 | 513 | } |
718e3744 | 514 | |
515 | void | |
1dec2166 | 516 | rip_interfaces_clean (void) |
718e3744 | 517 | { |
52dc7ee6 | 518 | struct listnode *node; |
718e3744 | 519 | struct interface *ifp; |
718e3744 | 520 | |
b2d7c082 | 521 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp)) |
1dec2166 PJ |
522 | rip_interface_clean (ifp->info); |
523 | } | |
718e3744 | 524 | |
1dec2166 PJ |
525 | static void |
526 | rip_interface_reset (struct rip_interface *ri) | |
4305dfd1 | 527 | { |
1dec2166 PJ |
528 | /* Default authentication type is simple password for Cisco |
529 | compatibility. */ | |
530 | ri->auth_type = RIP_NO_AUTH; | |
531 | ri->md5_auth_len = RIP_AUTH_MD5_COMPAT_SIZE; | |
718e3744 | 532 | |
1dec2166 PJ |
533 | /* Set default split-horizon behavior. If the interface is Frame |
534 | Relay or SMDS is enabled, the default value for split-horizon is | |
535 | off. But currently Zebra does detect Frame Relay or SMDS | |
536 | interface. So all interface is set to split horizon. */ | |
537 | ri->split_horizon_default = RIP_SPLIT_HORIZON; | |
538 | ri->split_horizon = ri->split_horizon_default; | |
718e3744 | 539 | |
4305dfd1 RW |
540 | ri->ri_send = RI_RIP_UNSPEC; |
541 | ri->ri_receive = RI_RIP_UNSPEC; | |
718e3744 | 542 | |
4305dfd1 | 543 | ri->v2_broadcast = 0; |
f90310cf | 544 | |
4305dfd1 RW |
545 | if (ri->auth_str) |
546 | { | |
547 | free (ri->auth_str); | |
548 | ri->auth_str = NULL; | |
549 | } | |
550 | if (ri->key_chain) | |
551 | { | |
552 | free (ri->key_chain); | |
553 | ri->key_chain = NULL; | |
554 | } | |
718e3744 | 555 | |
4305dfd1 RW |
556 | ri->list[RIP_FILTER_IN] = NULL; |
557 | ri->list[RIP_FILTER_OUT] = NULL; | |
718e3744 | 558 | |
4305dfd1 RW |
559 | ri->prefix[RIP_FILTER_IN] = NULL; |
560 | ri->prefix[RIP_FILTER_OUT] = NULL; | |
561 | ||
562 | ri->recv_badpackets = 0; | |
563 | ri->recv_badroutes = 0; | |
564 | ri->sent_updates = 0; | |
718e3744 | 565 | |
4305dfd1 | 566 | ri->passive = 0; |
1dec2166 PJ |
567 | |
568 | rip_interface_clean (ri); | |
4305dfd1 | 569 | } |
718e3744 | 570 | |
1dec2166 PJ |
571 | void |
572 | rip_interfaces_reset (void) | |
573 | { | |
574 | struct listnode *node; | |
575 | struct interface *ifp; | |
718e3744 | 576 | |
1dec2166 PJ |
577 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp)) |
578 | rip_interface_reset (ifp->info); | |
718e3744 | 579 | } |
580 | ||
581 | int | |
582 | rip_if_down(struct interface *ifp) | |
583 | { | |
584 | struct route_node *rp; | |
585 | struct rip_info *rinfo; | |
586 | struct rip_interface *ri = NULL; | |
bce8e868 LF |
587 | struct list *list = NULL; |
588 | struct listnode *listnode = NULL, *nextnode = NULL; | |
718e3744 | 589 | if (rip) |
65093755 DS |
590 | { |
591 | for (rp = route_top (rip->table); rp; rp = route_next (rp)) | |
592 | if ((list = rp->info) != NULL) | |
593 | for (ALL_LIST_ELEMENTS (list, listnode, nextnode, rinfo)) | |
594 | if (rinfo->ifindex == ifp->ifindex) | |
595 | rip_ecmp_delete (rinfo); | |
bce8e868 | 596 | |
65093755 | 597 | ri = ifp->info; |
718e3744 | 598 | |
65093755 DS |
599 | if (ri->running) |
600 | { | |
601 | if (IS_RIP_DEBUG_EVENT) | |
602 | zlog_debug ("turn off %s", ifp->name); | |
718e3744 | 603 | |
65093755 DS |
604 | /* Leave from multicast group. */ |
605 | rip_multicast_leave (ifp, rip->sock); | |
718e3744 | 606 | |
65093755 DS |
607 | ri->running = 0; |
608 | } | |
609 | } | |
718e3744 | 610 | |
611 | return 0; | |
612 | } | |
613 | ||
614 | /* Needed for stop RIP process. */ | |
615 | void | |
616 | rip_if_down_all () | |
617 | { | |
618 | struct interface *ifp; | |
1eb8ef25 | 619 | struct listnode *node, *nnode; |
718e3744 | 620 | |
b2d7c082 | 621 | for (ALL_LIST_ELEMENTS (vrf_iflist (VRF_DEFAULT), node, nnode, ifp)) |
1eb8ef25 | 622 | rip_if_down (ifp); |
718e3744 | 623 | } |
624 | ||
16705130 | 625 | static void |
dc63bfd4 | 626 | rip_apply_address_add (struct connected *ifc) |
627 | { | |
16705130 | 628 | struct prefix_ipv4 address; |
629 | struct prefix *p; | |
630 | ||
631 | if (!rip) | |
632 | return; | |
633 | ||
634 | if (! if_is_up(ifc->ifp)) | |
635 | return; | |
636 | ||
637 | p = ifc->address; | |
638 | ||
639 | memset (&address, 0, sizeof (address)); | |
640 | address.family = p->family; | |
641 | address.prefix = p->u.prefix4; | |
642 | address.prefixlen = p->prefixlen; | |
643 | apply_mask_ipv4(&address); | |
644 | ||
645 | /* Check if this interface is RIP enabled or not | |
646 | or Check if this address's prefix is RIP enabled */ | |
647 | if ((rip_enable_if_lookup(ifc->ifp->name) >= 0) || | |
648 | (rip_enable_network_lookup2(ifc) >= 0)) | |
649 | rip_redistribute_add(ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, | |
9471675f | 650 | &address, ifc->ifp->ifindex, NULL, 0, 0, 0); |
16705130 | 651 | |
652 | } | |
653 | ||
718e3744 | 654 | int |
655 | rip_interface_address_add (int command, struct zclient *zclient, | |
7076bb2f | 656 | zebra_size_t length, vrf_id_t vrf_id) |
718e3744 | 657 | { |
658 | struct connected *ifc; | |
659 | struct prefix *p; | |
660 | ||
0a589359 | 661 | ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, |
7076bb2f | 662 | zclient->ibuf, vrf_id); |
718e3744 | 663 | |
664 | if (ifc == NULL) | |
665 | return 0; | |
666 | ||
667 | p = ifc->address; | |
668 | ||
669 | if (p->family == AF_INET) | |
670 | { | |
671 | if (IS_RIP_DEBUG_ZEBRA) | |
5d6c3779 | 672 | zlog_debug ("connected address %s/%d is added", |
718e3744 | 673 | inet_ntoa (p->u.prefix4), p->prefixlen); |
16705130 | 674 | |
878ef2e7 | 675 | rip_enable_apply(ifc->ifp); |
16705130 | 676 | /* Check if this prefix needs to be redistributed */ |
677 | rip_apply_address_add(ifc); | |
718e3744 | 678 | |
3012671f | 679 | hook_call(rip_ifaddr_add, ifc); |
718e3744 | 680 | } |
681 | ||
682 | return 0; | |
683 | } | |
684 | ||
16705130 | 685 | static void |
686 | rip_apply_address_del (struct connected *ifc) { | |
687 | struct prefix_ipv4 address; | |
688 | struct prefix *p; | |
689 | ||
690 | if (!rip) | |
691 | return; | |
692 | ||
693 | if (! if_is_up(ifc->ifp)) | |
694 | return; | |
695 | ||
696 | p = ifc->address; | |
697 | ||
698 | memset (&address, 0, sizeof (address)); | |
699 | address.family = p->family; | |
700 | address.prefix = p->u.prefix4; | |
701 | address.prefixlen = p->prefixlen; | |
702 | apply_mask_ipv4(&address); | |
703 | ||
704 | rip_redistribute_delete(ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, | |
705 | &address, ifc->ifp->ifindex); | |
706 | } | |
707 | ||
718e3744 | 708 | int |
709 | rip_interface_address_delete (int command, struct zclient *zclient, | |
7076bb2f | 710 | zebra_size_t length, vrf_id_t vrf_id) |
718e3744 | 711 | { |
712 | struct connected *ifc; | |
713 | struct prefix *p; | |
714 | ||
0a589359 | 715 | ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, |
7076bb2f | 716 | zclient->ibuf, vrf_id); |
718e3744 | 717 | |
718 | if (ifc) | |
719 | { | |
720 | p = ifc->address; | |
721 | if (p->family == AF_INET) | |
722 | { | |
723 | if (IS_RIP_DEBUG_ZEBRA) | |
5d6c3779 | 724 | zlog_debug ("connected address %s/%d is deleted", |
718e3744 | 725 | inet_ntoa (p->u.prefix4), p->prefixlen); |
726 | ||
3012671f | 727 | hook_call(rip_ifaddr_del, ifc); |
718e3744 | 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, | |
6147e2c6 | 1219 | "network <A.B.C.D/M|WORD>", |
718e3744 | 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 | { | |
80fa0c69 | 1224 | int idx_ipv4_word = 1; |
718e3744 | 1225 | int ret; |
1226 | struct prefix_ipv4 p; | |
1227 | ||
80fa0c69 | 1228 | ret = str2prefix_ipv4 (argv[idx_ipv4_word]->arg, &p); |
718e3744 | 1229 | |
1230 | if (ret) | |
1231 | ret = rip_enable_network_add ((struct prefix *) &p); | |
1232 | else | |
80fa0c69 | 1233 | ret = rip_enable_if_add (argv[idx_ipv4_word]->arg); |
718e3744 | 1234 | |
1235 | if (ret < 0) | |
1236 | { | |
80fa0c69 | 1237 | vty_out (vty, "There is a same network configuration %s%s", argv[idx_ipv4_word]->arg, |
718e3744 | 1238 | VTY_NEWLINE); |
1239 | return CMD_WARNING; | |
1240 | } | |
1241 | ||
718e3744 | 1242 | return CMD_SUCCESS; |
1243 | } | |
1244 | ||
1245 | /* RIP enable network or interface configuration. */ | |
1246 | DEFUN (no_rip_network, | |
1247 | no_rip_network_cmd, | |
6147e2c6 | 1248 | "no network <A.B.C.D/M|WORD>", |
718e3744 | 1249 | NO_STR |
1250 | "Enable routing on an IP network\n" | |
1251 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
1252 | "Interface name\n") | |
1253 | { | |
80fa0c69 | 1254 | int idx_ipv4_word = 2; |
718e3744 | 1255 | int ret; |
1256 | struct prefix_ipv4 p; | |
1257 | ||
80fa0c69 | 1258 | ret = str2prefix_ipv4 (argv[idx_ipv4_word]->arg, &p); |
718e3744 | 1259 | |
1260 | if (ret) | |
1261 | ret = rip_enable_network_delete ((struct prefix *) &p); | |
1262 | else | |
80fa0c69 | 1263 | ret = rip_enable_if_delete (argv[idx_ipv4_word]->arg); |
718e3744 | 1264 | |
1265 | if (ret < 0) | |
1266 | { | |
80fa0c69 | 1267 | vty_out (vty, "Can't find network configuration %s%s", argv[idx_ipv4_word]->arg, |
718e3744 | 1268 | VTY_NEWLINE); |
1269 | return CMD_WARNING; | |
1270 | } | |
1271 | ||
718e3744 | 1272 | return CMD_SUCCESS; |
1273 | } | |
1274 | ||
1275 | /* RIP neighbor configuration set. */ | |
1276 | DEFUN (rip_neighbor, | |
1277 | rip_neighbor_cmd, | |
1278 | "neighbor A.B.C.D", | |
1279 | "Specify a neighbor router\n" | |
1280 | "Neighbor address\n") | |
1281 | { | |
80fa0c69 | 1282 | int idx_ipv4 = 1; |
718e3744 | 1283 | int ret; |
1284 | struct prefix_ipv4 p; | |
1285 | ||
80fa0c69 | 1286 | ret = str2prefix_ipv4 (argv[idx_ipv4]->arg, &p); |
718e3744 | 1287 | |
1288 | if (ret <= 0) | |
1289 | { | |
1290 | vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE); | |
1291 | return CMD_WARNING; | |
1292 | } | |
1293 | ||
1294 | rip_neighbor_add (&p); | |
1295 | ||
1296 | return CMD_SUCCESS; | |
1297 | } | |
1298 | ||
1299 | /* RIP neighbor configuration unset. */ | |
1300 | DEFUN (no_rip_neighbor, | |
1301 | no_rip_neighbor_cmd, | |
1302 | "no neighbor A.B.C.D", | |
1303 | NO_STR | |
1304 | "Specify a neighbor router\n" | |
1305 | "Neighbor address\n") | |
1306 | { | |
80fa0c69 | 1307 | int idx_ipv4 = 2; |
718e3744 | 1308 | int ret; |
1309 | struct prefix_ipv4 p; | |
1310 | ||
80fa0c69 | 1311 | ret = str2prefix_ipv4 (argv[idx_ipv4]->arg, &p); |
718e3744 | 1312 | |
1313 | if (ret <= 0) | |
1314 | { | |
1315 | vty_out (vty, "Please specify address by A.B.C.D%s", VTY_NEWLINE); | |
1316 | return CMD_WARNING; | |
1317 | } | |
1318 | ||
1319 | rip_neighbor_delete (&p); | |
1320 | ||
1321 | return CMD_SUCCESS; | |
1322 | } | |
1323 | ||
1324 | DEFUN (ip_rip_receive_version, | |
1325 | ip_rip_receive_version_cmd, | |
bca63dc7 | 1326 | "ip rip receive version <(1-2)|none>", |
718e3744 | 1327 | IP_STR |
1328 | "Routing Information Protocol\n" | |
1329 | "Advertisement reception\n" | |
1330 | "Version control\n" | |
1331 | "RIP version 1\n" | |
6aec4b41 RW |
1332 | "RIP version 2\n" |
1333 | "None\n") | |
718e3744 | 1334 | { |
cdc2d765 | 1335 | VTY_DECLVAR_CONTEXT(interface, ifp); |
80fa0c69 | 1336 | int idx_type = 4; |
718e3744 | 1337 | struct rip_interface *ri; |
1338 | ||
718e3744 | 1339 | ri = ifp->info; |
1340 | ||
53dc2b05 | 1341 | switch (argv[idx_type]->arg[0]) |
718e3744 | 1342 | { |
6aec4b41 | 1343 | case '1': |
718e3744 | 1344 | ri->ri_receive = RI_RIP_VERSION_1; |
1345 | return CMD_SUCCESS; | |
6aec4b41 | 1346 | case '2': |
718e3744 | 1347 | ri->ri_receive = RI_RIP_VERSION_2; |
1348 | return CMD_SUCCESS; | |
6aec4b41 RW |
1349 | case 'n': |
1350 | ri->ri_receive = RI_RIP_VERSION_NONE; | |
1351 | return CMD_SUCCESS; | |
1352 | default: | |
1353 | break; | |
718e3744 | 1354 | } |
6aec4b41 | 1355 | |
718e3744 | 1356 | return CMD_WARNING; |
1357 | } | |
1358 | ||
1359 | DEFUN (ip_rip_receive_version_1, | |
1360 | ip_rip_receive_version_1_cmd, | |
12dcf78e | 1361 | "ip rip receive version (1-1) (2-2)", |
718e3744 | 1362 | IP_STR |
1363 | "Routing Information Protocol\n" | |
1364 | "Advertisement reception\n" | |
1365 | "Version control\n" | |
1366 | "RIP version 1\n" | |
1367 | "RIP version 2\n") | |
1368 | { | |
cdc2d765 | 1369 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1370 | struct rip_interface *ri; |
1371 | ||
718e3744 | 1372 | ri = ifp->info; |
1373 | ||
1374 | /* Version 1 and 2. */ | |
1375 | ri->ri_receive = RI_RIP_VERSION_1_AND_2; | |
1376 | return CMD_SUCCESS; | |
1377 | } | |
1378 | ||
1379 | DEFUN (ip_rip_receive_version_2, | |
1380 | ip_rip_receive_version_2_cmd, | |
ccb8e0c7 | 1381 | "ip rip receive version (2-2) (1-1)", |
718e3744 | 1382 | IP_STR |
1383 | "Routing Information Protocol\n" | |
1384 | "Advertisement reception\n" | |
1385 | "Version control\n" | |
1386 | "RIP version 2\n" | |
1387 | "RIP version 1\n") | |
1388 | { | |
cdc2d765 | 1389 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1390 | struct rip_interface *ri; |
1391 | ||
718e3744 | 1392 | ri = ifp->info; |
1393 | ||
1394 | /* Version 1 and 2. */ | |
1395 | ri->ri_receive = RI_RIP_VERSION_1_AND_2; | |
1396 | return CMD_SUCCESS; | |
1397 | } | |
1398 | ||
1399 | DEFUN (no_ip_rip_receive_version, | |
1400 | no_ip_rip_receive_version_cmd, | |
e83a9414 | 1401 | "no ip rip receive version [(1-2)]", |
718e3744 | 1402 | NO_STR |
1403 | IP_STR | |
1404 | "Routing Information Protocol\n" | |
1405 | "Advertisement reception\n" | |
55c727dd QY |
1406 | "Version control\n" |
1407 | "Version 1\n" | |
1408 | "Version 2\n") | |
718e3744 | 1409 | { |
cdc2d765 | 1410 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1411 | struct rip_interface *ri; |
1412 | ||
718e3744 | 1413 | ri = ifp->info; |
1414 | ||
1415 | ri->ri_receive = RI_RIP_UNSPEC; | |
1416 | return CMD_SUCCESS; | |
1417 | } | |
1418 | ||
718e3744 | 1419 | |
1420 | DEFUN (ip_rip_send_version, | |
1421 | ip_rip_send_version_cmd, | |
e83a9414 | 1422 | "ip rip send version (1-2)", |
718e3744 | 1423 | IP_STR |
1424 | "Routing Information Protocol\n" | |
1425 | "Advertisement transmission\n" | |
1426 | "Version control\n" | |
1427 | "RIP version 1\n" | |
1428 | "RIP version 2\n") | |
1429 | { | |
cdc2d765 | 1430 | VTY_DECLVAR_CONTEXT(interface, ifp); |
80fa0c69 | 1431 | int idx_type = 4; |
718e3744 | 1432 | struct rip_interface *ri; |
1433 | ||
718e3744 | 1434 | ri = ifp->info; |
1435 | ||
1436 | /* Version 1. */ | |
80fa0c69 | 1437 | if (atoi (argv[idx_type]->arg) == 1) |
718e3744 | 1438 | { |
1439 | ri->ri_send = RI_RIP_VERSION_1; | |
1440 | return CMD_SUCCESS; | |
1441 | } | |
80fa0c69 | 1442 | if (atoi (argv[idx_type]->arg) == 2) |
718e3744 | 1443 | { |
1444 | ri->ri_send = RI_RIP_VERSION_2; | |
1445 | return CMD_SUCCESS; | |
1446 | } | |
1447 | return CMD_WARNING; | |
1448 | } | |
1449 | ||
1450 | DEFUN (ip_rip_send_version_1, | |
1451 | ip_rip_send_version_1_cmd, | |
ccb8e0c7 | 1452 | "ip rip send version (1-1) (2-2)", |
718e3744 | 1453 | IP_STR |
1454 | "Routing Information Protocol\n" | |
1455 | "Advertisement transmission\n" | |
1456 | "Version control\n" | |
1457 | "RIP version 1\n" | |
1458 | "RIP version 2\n") | |
1459 | { | |
cdc2d765 | 1460 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1461 | struct rip_interface *ri; |
1462 | ||
718e3744 | 1463 | ri = ifp->info; |
1464 | ||
1465 | /* Version 1 and 2. */ | |
1466 | ri->ri_send = RI_RIP_VERSION_1_AND_2; | |
1467 | return CMD_SUCCESS; | |
1468 | } | |
1469 | ||
1470 | DEFUN (ip_rip_send_version_2, | |
1471 | ip_rip_send_version_2_cmd, | |
ccb8e0c7 | 1472 | "ip rip send version (2-2) (1-1)", |
718e3744 | 1473 | IP_STR |
1474 | "Routing Information Protocol\n" | |
1475 | "Advertisement transmission\n" | |
1476 | "Version control\n" | |
1477 | "RIP version 2\n" | |
1478 | "RIP version 1\n") | |
1479 | { | |
cdc2d765 | 1480 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1481 | struct rip_interface *ri; |
1482 | ||
718e3744 | 1483 | ri = ifp->info; |
1484 | ||
1485 | /* Version 1 and 2. */ | |
1486 | ri->ri_send = RI_RIP_VERSION_1_AND_2; | |
1487 | return CMD_SUCCESS; | |
1488 | } | |
1489 | ||
1490 | DEFUN (no_ip_rip_send_version, | |
1491 | no_ip_rip_send_version_cmd, | |
e83a9414 | 1492 | "no ip rip send version [(1-2)]", |
718e3744 | 1493 | NO_STR |
1494 | IP_STR | |
1495 | "Routing Information Protocol\n" | |
1496 | "Advertisement transmission\n" | |
55c727dd QY |
1497 | "Version control\n" |
1498 | "Version 1\n" | |
1499 | "Version 2\n") | |
718e3744 | 1500 | { |
cdc2d765 | 1501 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1502 | struct rip_interface *ri; |
1503 | ||
718e3744 | 1504 | ri = ifp->info; |
1505 | ||
1506 | ri->ri_send = RI_RIP_UNSPEC; | |
1507 | return CMD_SUCCESS; | |
1508 | } | |
1509 | ||
718e3744 | 1510 | |
f90310cf RW |
1511 | DEFUN (ip_rip_v2_broadcast, |
1512 | ip_rip_v2_broadcast_cmd, | |
1513 | "ip rip v2-broadcast", | |
1514 | IP_STR | |
1515 | "Routing Information Protocol\n" | |
1516 | "Send ip broadcast v2 update\n") | |
1517 | { | |
cdc2d765 | 1518 | VTY_DECLVAR_CONTEXT(interface, ifp); |
f90310cf RW |
1519 | struct rip_interface *ri; |
1520 | ||
f90310cf RW |
1521 | ri = ifp->info; |
1522 | ||
1523 | ri->v2_broadcast = 1; | |
1524 | return CMD_SUCCESS; | |
1525 | } | |
1526 | ||
1527 | DEFUN (no_ip_rip_v2_broadcast, | |
1528 | no_ip_rip_v2_broadcast_cmd, | |
1529 | "no ip rip v2-broadcast", | |
1530 | NO_STR | |
1531 | IP_STR | |
1532 | "Routing Information Protocol\n" | |
1533 | "Send ip broadcast v2 update\n") | |
1534 | { | |
cdc2d765 | 1535 | VTY_DECLVAR_CONTEXT(interface, ifp); |
f90310cf RW |
1536 | struct rip_interface *ri; |
1537 | ||
f90310cf RW |
1538 | ri = ifp->info; |
1539 | ||
1540 | ri->v2_broadcast = 0; | |
1541 | return CMD_SUCCESS; | |
1542 | } | |
1543 | ||
718e3744 | 1544 | DEFUN (ip_rip_authentication_mode, |
1545 | ip_rip_authentication_mode_cmd, | |
55c727dd | 1546 | "ip rip authentication mode <md5|text> [auth-length <rfc|old-ripd>]", |
718e3744 | 1547 | IP_STR |
1548 | "Routing Information Protocol\n" | |
1549 | "Authentication control\n" | |
1550 | "Authentication mode\n" | |
1551 | "Keyed message digest\n" | |
55c727dd QY |
1552 | "Clear text authentication\n" |
1553 | "MD5 authentication data length\n" | |
1554 | "RFC compatible\n" | |
1555 | "Old ripd compatible\n") | |
718e3744 | 1556 | { |
cdc2d765 | 1557 | VTY_DECLVAR_CONTEXT(interface, ifp); |
55c727dd QY |
1558 | char *cryptmode = argv[4]->text; |
1559 | char *authlen = (argc > 5) ? argv[6]->text : NULL; | |
718e3744 | 1560 | struct rip_interface *ri; |
15a2b089 | 1561 | int auth_type; |
718e3744 | 1562 | |
718e3744 | 1563 | ri = ifp->info; |
1564 | ||
55c727dd | 1565 | if (strmatch ("md5", cryptmode)) |
15a2b089 | 1566 | auth_type = RIP_AUTH_MD5; |
55c727dd QY |
1567 | else { |
1568 | assert (strmatch ("text", cryptmode)); | |
15a2b089 | 1569 | auth_type = RIP_AUTH_SIMPLE_PASSWORD; |
55c727dd | 1570 | } |
718e3744 | 1571 | |
55c727dd | 1572 | ri->auth_type = auth_type; |
ca5e516c | 1573 | |
55c727dd QY |
1574 | if (argc > 5) |
1575 | { | |
1576 | if (auth_type != RIP_AUTH_MD5) | |
ca5e516c | 1577 | { |
1578 | vty_out (vty, "auth length argument only valid for md5%s", VTY_NEWLINE); | |
1579 | return CMD_WARNING; | |
15a2b089 | 1580 | } |
55c727dd QY |
1581 | if (strmatch ("rfc", authlen)) |
1582 | ri->md5_auth_len = RIP_AUTH_MD5_SIZE; | |
1583 | else | |
1584 | { | |
1585 | assert (strmatch ("old-ripd", authlen)); | |
1586 | ri->md5_auth_len = RIP_AUTH_MD5_COMPAT_SIZE; | |
1587 | } | |
1588 | } | |
ca5e516c | 1589 | |
718e3744 | 1590 | return CMD_SUCCESS; |
1591 | } | |
1592 | ||
1593 | DEFUN (no_ip_rip_authentication_mode, | |
1594 | no_ip_rip_authentication_mode_cmd, | |
55c727dd | 1595 | "no ip rip authentication mode [<md5|text> [auth-length <rfc|old-ripd>]]", |
718e3744 | 1596 | NO_STR |
1597 | IP_STR | |
1598 | "Routing Information Protocol\n" | |
1599 | "Authentication control\n" | |
55c727dd QY |
1600 | "Authentication mode\n" |
1601 | "Keyed message digest\n" | |
1602 | "Clear text authentication\n" | |
1603 | "MD5 authentication data length\n" | |
1604 | "RFC compatible\n" | |
1605 | "Old ripd compatible\n") | |
718e3744 | 1606 | { |
cdc2d765 | 1607 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1608 | struct rip_interface *ri; |
1609 | ||
718e3744 | 1610 | ri = ifp->info; |
1611 | ||
7755a8c2 | 1612 | ri->auth_type = RIP_NO_AUTH; |
ca5e516c | 1613 | ri->md5_auth_len = RIP_AUTH_MD5_COMPAT_SIZE; |
718e3744 | 1614 | |
1615 | return CMD_SUCCESS; | |
1616 | } | |
1617 | ||
718e3744 | 1618 | DEFUN (ip_rip_authentication_string, |
1619 | ip_rip_authentication_string_cmd, | |
1620 | "ip rip authentication string LINE", | |
1621 | IP_STR | |
1622 | "Routing Information Protocol\n" | |
1623 | "Authentication control\n" | |
1624 | "Authentication string\n" | |
1625 | "Authentication string\n") | |
1626 | { | |
cdc2d765 | 1627 | VTY_DECLVAR_CONTEXT(interface, ifp); |
80fa0c69 | 1628 | int idx_line = 4; |
718e3744 | 1629 | struct rip_interface *ri; |
1630 | ||
718e3744 | 1631 | ri = ifp->info; |
1632 | ||
80fa0c69 | 1633 | if (strlen (argv[idx_line]->arg) > 16) |
718e3744 | 1634 | { |
1635 | vty_out (vty, "%% RIPv2 authentication string must be shorter than 16%s", | |
1636 | VTY_NEWLINE); | |
1637 | return CMD_WARNING; | |
1638 | } | |
1639 | ||
1640 | if (ri->key_chain) | |
1641 | { | |
1642 | vty_out (vty, "%% key-chain configuration exists%s", VTY_NEWLINE); | |
1643 | return CMD_WARNING; | |
1644 | } | |
1645 | ||
1646 | if (ri->auth_str) | |
1647 | free (ri->auth_str); | |
1648 | ||
80fa0c69 | 1649 | ri->auth_str = strdup (argv[idx_line]->arg); |
718e3744 | 1650 | |
1651 | return CMD_SUCCESS; | |
1652 | } | |
1653 | ||
1654 | DEFUN (no_ip_rip_authentication_string, | |
1655 | no_ip_rip_authentication_string_cmd, | |
55c727dd | 1656 | "no ip rip authentication string [LINE]", |
718e3744 | 1657 | NO_STR |
1658 | IP_STR | |
1659 | "Routing Information Protocol\n" | |
1660 | "Authentication control\n" | |
55c727dd | 1661 | "Authentication string\n" |
718e3744 | 1662 | "Authentication string\n") |
1663 | { | |
cdc2d765 | 1664 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1665 | struct rip_interface *ri; |
1666 | ||
718e3744 | 1667 | ri = ifp->info; |
1668 | ||
1669 | if (ri->auth_str) | |
1670 | free (ri->auth_str); | |
1671 | ||
1672 | ri->auth_str = NULL; | |
1673 | ||
1674 | return CMD_SUCCESS; | |
1675 | } | |
1676 | ||
718e3744 | 1677 | |
1678 | DEFUN (ip_rip_authentication_key_chain, | |
1679 | ip_rip_authentication_key_chain_cmd, | |
1680 | "ip rip authentication key-chain LINE", | |
1681 | IP_STR | |
1682 | "Routing Information Protocol\n" | |
1683 | "Authentication control\n" | |
1684 | "Authentication key-chain\n" | |
1685 | "name of key-chain\n") | |
1686 | { | |
cdc2d765 | 1687 | VTY_DECLVAR_CONTEXT(interface, ifp); |
80fa0c69 | 1688 | int idx_line = 4; |
718e3744 | 1689 | struct rip_interface *ri; |
1690 | ||
718e3744 | 1691 | ri = ifp->info; |
1692 | ||
1693 | if (ri->auth_str) | |
1694 | { | |
1695 | vty_out (vty, "%% authentication string configuration exists%s", | |
1696 | VTY_NEWLINE); | |
1697 | return CMD_WARNING; | |
1698 | } | |
1699 | ||
1700 | if (ri->key_chain) | |
1701 | free (ri->key_chain); | |
1702 | ||
80fa0c69 | 1703 | ri->key_chain = strdup (argv[idx_line]->arg); |
718e3744 | 1704 | |
1705 | return CMD_SUCCESS; | |
1706 | } | |
1707 | ||
1708 | DEFUN (no_ip_rip_authentication_key_chain, | |
1709 | no_ip_rip_authentication_key_chain_cmd, | |
55c727dd | 1710 | "no ip rip authentication key-chain [LINE]", |
718e3744 | 1711 | NO_STR |
1712 | IP_STR | |
1713 | "Routing Information Protocol\n" | |
1714 | "Authentication control\n" | |
55c727dd QY |
1715 | "Authentication key-chain\n" |
1716 | "name of key-chain\n") | |
718e3744 | 1717 | { |
cdc2d765 | 1718 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1719 | struct rip_interface *ri; |
1720 | ||
718e3744 | 1721 | ri = ifp->info; |
1722 | ||
1723 | if (ri->key_chain) | |
1724 | free (ri->key_chain); | |
1725 | ||
1726 | ri->key_chain = NULL; | |
1727 | ||
1728 | return CMD_SUCCESS; | |
1729 | } | |
1730 | ||
718e3744 | 1731 | |
16705130 | 1732 | /* CHANGED: ip rip split-horizon |
1733 | Cisco and Zebra's command is | |
1734 | ip split-horizon | |
1735 | */ | |
1736 | DEFUN (ip_rip_split_horizon, | |
1737 | ip_rip_split_horizon_cmd, | |
1738 | "ip rip split-horizon", | |
718e3744 | 1739 | IP_STR |
16705130 | 1740 | "Routing Information Protocol\n" |
718e3744 | 1741 | "Perform split horizon\n") |
1742 | { | |
cdc2d765 | 1743 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1744 | struct rip_interface *ri; |
1745 | ||
718e3744 | 1746 | ri = ifp->info; |
1747 | ||
16705130 | 1748 | ri->split_horizon = RIP_SPLIT_HORIZON; |
718e3744 | 1749 | return CMD_SUCCESS; |
1750 | } | |
1751 | ||
16705130 | 1752 | DEFUN (ip_rip_split_horizon_poisoned_reverse, |
1753 | ip_rip_split_horizon_poisoned_reverse_cmd, | |
1754 | "ip rip split-horizon poisoned-reverse", | |
1755 | IP_STR | |
1756 | "Routing Information Protocol\n" | |
1757 | "Perform split horizon\n" | |
1758 | "With poisoned-reverse\n") | |
1759 | { | |
cdc2d765 | 1760 | VTY_DECLVAR_CONTEXT(interface, ifp); |
16705130 | 1761 | struct rip_interface *ri; |
1762 | ||
16705130 | 1763 | ri = ifp->info; |
1764 | ||
1765 | ri->split_horizon = RIP_SPLIT_HORIZON_POISONED_REVERSE; | |
1766 | return CMD_SUCCESS; | |
1767 | } | |
1768 | ||
1769 | /* CHANGED: no ip rip split-horizon | |
1770 | Cisco and Zebra's command is | |
1771 | no ip split-horizon | |
1772 | */ | |
1773 | DEFUN (no_ip_rip_split_horizon, | |
1774 | no_ip_rip_split_horizon_cmd, | |
1775 | "no ip rip split-horizon", | |
718e3744 | 1776 | NO_STR |
1777 | IP_STR | |
16705130 | 1778 | "Routing Information Protocol\n" |
718e3744 | 1779 | "Perform split horizon\n") |
1780 | { | |
cdc2d765 | 1781 | VTY_DECLVAR_CONTEXT(interface, ifp); |
718e3744 | 1782 | struct rip_interface *ri; |
1783 | ||
718e3744 | 1784 | ri = ifp->info; |
1785 | ||
16705130 | 1786 | ri->split_horizon = RIP_NO_SPLIT_HORIZON; |
718e3744 | 1787 | return CMD_SUCCESS; |
1788 | } | |
1789 | ||
fac3e841 | 1790 | DEFUN (no_ip_rip_split_horizon_poisoned_reverse, |
16705130 | 1791 | no_ip_rip_split_horizon_poisoned_reverse_cmd, |
1792 | "no ip rip split-horizon poisoned-reverse", | |
1793 | NO_STR | |
1794 | IP_STR | |
1795 | "Routing Information Protocol\n" | |
1796 | "Perform split horizon\n" | |
1797 | "With poisoned-reverse\n") | |
fac3e841 | 1798 | { |
cdc2d765 | 1799 | VTY_DECLVAR_CONTEXT(interface, ifp); |
fac3e841 | 1800 | struct rip_interface *ri; |
1801 | ||
fac3e841 | 1802 | ri = ifp->info; |
1803 | ||
1804 | switch( ri->split_horizon ) | |
1805 | { | |
55c727dd QY |
1806 | case RIP_SPLIT_HORIZON_POISONED_REVERSE: |
1807 | ri->split_horizon = RIP_SPLIT_HORIZON; | |
1808 | default: | |
1809 | break; | |
fac3e841 | 1810 | } |
1811 | ||
1812 | return CMD_SUCCESS; | |
1813 | } | |
16705130 | 1814 | |
718e3744 | 1815 | DEFUN (rip_passive_interface, |
1816 | rip_passive_interface_cmd, | |
6147e2c6 | 1817 | "passive-interface <IFNAME|default>", |
718e3744 | 1818 | "Suppress routing updates on an interface\n" |
56e475cb | 1819 | "Interface name\n" |
1820 | "default for all interfaces\n") | |
718e3744 | 1821 | { |
55c727dd | 1822 | if (argv[1]->type == WORD_TKN) { // user passed 'default' |
4aaff3f8 | 1823 | passive_default = 1; |
1824 | rip_passive_nondefault_clean(); | |
1825 | return CMD_SUCCESS; | |
1826 | } | |
1827 | if (passive_default) | |
55c727dd | 1828 | return rip_passive_nondefault_unset (vty, argv[1]->arg); |
4aaff3f8 | 1829 | else |
55c727dd | 1830 | return rip_passive_nondefault_set (vty, argv[1]->arg); |
718e3744 | 1831 | } |
1832 | ||
1833 | DEFUN (no_rip_passive_interface, | |
1834 | no_rip_passive_interface_cmd, | |
6147e2c6 | 1835 | "no passive-interface <IFNAME|default>", |
718e3744 | 1836 | NO_STR |
1837 | "Suppress routing updates on an interface\n" | |
56e475cb | 1838 | "Interface name\n" |
1839 | "default for all interfaces\n") | |
718e3744 | 1840 | { |
55c727dd | 1841 | if (argv[2]->type == WORD_TKN) { |
4aaff3f8 | 1842 | passive_default = 0; |
1843 | rip_passive_nondefault_clean(); | |
1844 | return CMD_SUCCESS; | |
1845 | } | |
1846 | if (passive_default) | |
55c727dd | 1847 | return rip_passive_nondefault_set (vty, argv[2]->arg); |
4aaff3f8 | 1848 | else |
55c727dd | 1849 | return rip_passive_nondefault_unset (vty, argv[2]->arg); |
718e3744 | 1850 | } |
6b0655a2 | 1851 | |
718e3744 | 1852 | /* Write rip configuration of each interface. */ |
dc63bfd4 | 1853 | static int |
718e3744 | 1854 | rip_interface_config_write (struct vty *vty) |
1855 | { | |
52dc7ee6 | 1856 | struct listnode *node; |
718e3744 | 1857 | struct interface *ifp; |
1858 | ||
b2d7c082 | 1859 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp)) |
718e3744 | 1860 | { |
1861 | struct rip_interface *ri; | |
1862 | ||
84361d61 DS |
1863 | if (ifp->ifindex == IFINDEX_DELETED) |
1864 | continue; | |
1865 | ||
718e3744 | 1866 | ri = ifp->info; |
1867 | ||
16705130 | 1868 | /* Do not display the interface if there is no |
1869 | * configuration about it. | |
1870 | **/ | |
1871 | if ((!ifp->desc) && | |
1872 | (ri->split_horizon == ri->split_horizon_default) && | |
1873 | (ri->ri_send == RI_RIP_UNSPEC) && | |
1874 | (ri->ri_receive == RI_RIP_UNSPEC) && | |
1875 | (ri->auth_type != RIP_AUTH_MD5) && | |
f90310cf | 1876 | (!ri->v2_broadcast) && |
ca5e516c | 1877 | (ri->md5_auth_len != RIP_AUTH_MD5_SIZE) && |
16705130 | 1878 | (!ri->auth_str) && |
1879 | (!ri->key_chain) ) | |
1880 | continue; | |
1881 | ||
718e3744 | 1882 | vty_out (vty, "interface %s%s", ifp->name, |
1883 | VTY_NEWLINE); | |
1884 | ||
1885 | if (ifp->desc) | |
1886 | vty_out (vty, " description %s%s", ifp->desc, | |
1887 | VTY_NEWLINE); | |
1888 | ||
1889 | /* Split horizon. */ | |
1890 | if (ri->split_horizon != ri->split_horizon_default) | |
1891 | { | |
16705130 | 1892 | switch (ri->split_horizon) { |
1893 | case RIP_SPLIT_HORIZON: | |
1894 | vty_out (vty, " ip rip split-horizon%s", VTY_NEWLINE); | |
1895 | break; | |
1896 | case RIP_SPLIT_HORIZON_POISONED_REVERSE: | |
1897 | vty_out (vty, " ip rip split-horizon poisoned-reverse%s", | |
1898 | VTY_NEWLINE); | |
1899 | break; | |
1900 | case RIP_NO_SPLIT_HORIZON: | |
1901 | default: | |
1902 | vty_out (vty, " no ip rip split-horizon%s", VTY_NEWLINE); | |
1903 | break; | |
1904 | } | |
718e3744 | 1905 | } |
1906 | ||
1907 | /* RIP version setting. */ | |
1908 | if (ri->ri_send != RI_RIP_UNSPEC) | |
1909 | vty_out (vty, " ip rip send version %s%s", | |
1910 | lookup (ri_version_msg, ri->ri_send), | |
1911 | VTY_NEWLINE); | |
1912 | ||
1913 | if (ri->ri_receive != RI_RIP_UNSPEC) | |
1914 | vty_out (vty, " ip rip receive version %s%s", | |
1915 | lookup (ri_version_msg, ri->ri_receive), | |
1916 | VTY_NEWLINE); | |
1917 | ||
f90310cf RW |
1918 | if (ri->v2_broadcast) |
1919 | vty_out (vty, " ip rip v2-broadcast%s", VTY_NEWLINE); | |
1920 | ||
718e3744 | 1921 | /* RIP authentication. */ |
718e3744 | 1922 | if (ri->auth_type == RIP_AUTH_SIMPLE_PASSWORD) |
1923 | vty_out (vty, " ip rip authentication mode text%s", VTY_NEWLINE); | |
ca5e516c | 1924 | |
718e3744 | 1925 | if (ri->auth_type == RIP_AUTH_MD5) |
ca5e516c | 1926 | { |
1927 | vty_out (vty, " ip rip authentication mode md5"); | |
1928 | if (ri->md5_auth_len == RIP_AUTH_MD5_COMPAT_SIZE) | |
1929 | vty_out (vty, " auth-length old-ripd"); | |
1930 | else | |
1931 | vty_out (vty, " auth-length rfc"); | |
1932 | vty_out (vty, "%s", VTY_NEWLINE); | |
1933 | } | |
718e3744 | 1934 | |
1935 | if (ri->auth_str) | |
1936 | vty_out (vty, " ip rip authentication string %s%s", | |
1937 | ri->auth_str, VTY_NEWLINE); | |
1938 | ||
1939 | if (ri->key_chain) | |
1940 | vty_out (vty, " ip rip authentication key-chain %s%s", | |
1941 | ri->key_chain, VTY_NEWLINE); | |
1942 | ||
1943 | vty_out (vty, "!%s", VTY_NEWLINE); | |
1944 | } | |
1945 | return 0; | |
1946 | } | |
1947 | ||
1948 | int | |
1949 | config_write_rip_network (struct vty *vty, int config_mode) | |
1950 | { | |
8a676be3 | 1951 | unsigned int i; |
718e3744 | 1952 | char *ifname; |
1953 | struct route_node *node; | |
1954 | ||
1955 | /* Network type RIP enable interface statement. */ | |
1956 | for (node = route_top (rip_enable_network); node; node = route_next (node)) | |
1957 | if (node->info) | |
1958 | vty_out (vty, "%s%s/%d%s", | |
1959 | config_mode ? " network " : " ", | |
1960 | inet_ntoa (node->p.u.prefix4), | |
1961 | node->p.prefixlen, | |
1962 | VTY_NEWLINE); | |
1963 | ||
1964 | /* Interface name RIP enable statement. */ | |
55468c86 | 1965 | for (i = 0; i < vector_active (rip_enable_interface); i++) |
718e3744 | 1966 | if ((ifname = vector_slot (rip_enable_interface, i)) != NULL) |
1967 | vty_out (vty, "%s%s%s", | |
1968 | config_mode ? " network " : " ", | |
1969 | ifname, | |
1970 | VTY_NEWLINE); | |
1971 | ||
1972 | /* RIP neighbors listing. */ | |
1973 | for (node = route_top (rip->neighbor); node; node = route_next (node)) | |
1974 | if (node->info) | |
1975 | vty_out (vty, "%s%s%s", | |
1976 | config_mode ? " neighbor " : " ", | |
1977 | inet_ntoa (node->p.u.prefix4), | |
1978 | VTY_NEWLINE); | |
1979 | ||
1980 | /* RIP passive interface listing. */ | |
4aaff3f8 | 1981 | if (config_mode) { |
1982 | if (passive_default) | |
01d0908a | 1983 | vty_out (vty, " passive-interface default%s", VTY_NEWLINE); |
55468c86 | 1984 | for (i = 0; i < vector_active (Vrip_passive_nondefault); i++) |
4aaff3f8 | 1985 | if ((ifname = vector_slot (Vrip_passive_nondefault, i)) != NULL) |
1986 | vty_out (vty, " %spassive-interface %s%s", | |
1987 | (passive_default ? "no " : ""), ifname, VTY_NEWLINE); | |
1988 | } | |
718e3744 | 1989 | |
1990 | return 0; | |
1991 | } | |
1992 | ||
7fc626de | 1993 | static struct cmd_node interface_node = |
718e3744 | 1994 | { |
1995 | INTERFACE_NODE, | |
1996 | "%s(config-if)# ", | |
1997 | 1, | |
1998 | }; | |
1999 | ||
2000 | /* Called when interface structure allocated. */ | |
dc63bfd4 | 2001 | static int |
718e3744 | 2002 | rip_interface_new_hook (struct interface *ifp) |
2003 | { | |
2004 | ifp->info = rip_interface_new (); | |
2005 | return 0; | |
2006 | } | |
2007 | ||
2008 | /* Called when interface structure deleted. */ | |
dc63bfd4 | 2009 | static int |
718e3744 | 2010 | rip_interface_delete_hook (struct interface *ifp) |
2011 | { | |
2012 | XFREE (MTYPE_RIP_INTERFACE, ifp->info); | |
16705130 | 2013 | ifp->info = NULL; |
718e3744 | 2014 | return 0; |
2015 | } | |
2016 | ||
2017 | /* Allocate and initialize interface vector. */ | |
2018 | void | |
dc63bfd4 | 2019 | rip_if_init (void) |
718e3744 | 2020 | { |
2021 | /* Default initial size of interface vector. */ | |
718e3744 | 2022 | if_add_hook (IF_NEW_HOOK, rip_interface_new_hook); |
2023 | if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook); | |
2024 | ||
2025 | /* RIP network init. */ | |
2026 | rip_enable_interface = vector_init (1); | |
2027 | rip_enable_network = route_table_init (); | |
2028 | ||
2029 | /* RIP passive interface. */ | |
4aaff3f8 | 2030 | Vrip_passive_nondefault = vector_init (1); |
718e3744 | 2031 | |
2032 | /* Install interface node. */ | |
2033 | install_node (&interface_node, rip_interface_config_write); | |
0b84f294 | 2034 | if_cmd_init (); |
718e3744 | 2035 | |
2036 | /* Install commands. */ | |
718e3744 | 2037 | install_element (RIP_NODE, &rip_network_cmd); |
2038 | install_element (RIP_NODE, &no_rip_network_cmd); | |
2039 | install_element (RIP_NODE, &rip_neighbor_cmd); | |
2040 | install_element (RIP_NODE, &no_rip_neighbor_cmd); | |
2041 | ||
2042 | install_element (RIP_NODE, &rip_passive_interface_cmd); | |
2043 | install_element (RIP_NODE, &no_rip_passive_interface_cmd); | |
2044 | ||
2045 | install_element (INTERFACE_NODE, &ip_rip_send_version_cmd); | |
2046 | install_element (INTERFACE_NODE, &ip_rip_send_version_1_cmd); | |
2047 | install_element (INTERFACE_NODE, &ip_rip_send_version_2_cmd); | |
2048 | install_element (INTERFACE_NODE, &no_ip_rip_send_version_cmd); | |
718e3744 | 2049 | |
2050 | install_element (INTERFACE_NODE, &ip_rip_receive_version_cmd); | |
2051 | install_element (INTERFACE_NODE, &ip_rip_receive_version_1_cmd); | |
2052 | install_element (INTERFACE_NODE, &ip_rip_receive_version_2_cmd); | |
2053 | install_element (INTERFACE_NODE, &no_ip_rip_receive_version_cmd); | |
718e3744 | 2054 | |
f90310cf RW |
2055 | install_element (INTERFACE_NODE, &ip_rip_v2_broadcast_cmd); |
2056 | install_element (INTERFACE_NODE, &no_ip_rip_v2_broadcast_cmd); | |
2057 | ||
718e3744 | 2058 | install_element (INTERFACE_NODE, &ip_rip_authentication_mode_cmd); |
2059 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_mode_cmd); | |
718e3744 | 2060 | |
2061 | install_element (INTERFACE_NODE, &ip_rip_authentication_key_chain_cmd); | |
2062 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_key_chain_cmd); | |
718e3744 | 2063 | |
2064 | install_element (INTERFACE_NODE, &ip_rip_authentication_string_cmd); | |
2065 | install_element (INTERFACE_NODE, &no_ip_rip_authentication_string_cmd); | |
718e3744 | 2066 | |
16705130 | 2067 | install_element (INTERFACE_NODE, &ip_rip_split_horizon_cmd); |
2068 | install_element (INTERFACE_NODE, &ip_rip_split_horizon_poisoned_reverse_cmd); | |
2069 | install_element (INTERFACE_NODE, &no_ip_rip_split_horizon_cmd); | |
2070 | install_element (INTERFACE_NODE, &no_ip_rip_split_horizon_poisoned_reverse_cmd); | |
718e3744 | 2071 | } |