]> git.proxmox.com Git - mirror_frr.git/blame - ripd/rip_interface.c
bgpd: [7.1] Strip `delete` keyword when looking up for lcommuni… (#4786)
[mirror_frr.git] / ripd / rip_interface.c
CommitLineData
718e3744 1/* Interface related function for RIP.
2 * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org>
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
718e3744 19 */
20
21#include <zebra.h>
22
23#include "command.h"
24#include "if.h"
25#include "sockunion.h"
26#include "prefix.h"
27#include "memory.h"
28#include "network.h"
29#include "table.h"
30#include "log.h"
31#include "stream.h"
32#include "thread.h"
33#include "zclient.h"
34#include "filter.h"
35#include "sockopt.h"
edd7c245 36#include "privs.h"
77cbe4a1 37#include "lib_errors.h"
f0ab22fb 38#include "northbound_cli.h"
718e3744 39
40#include "zebra/connected.h"
41
42#include "ripd/ripd.h"
43#include "ripd/rip_debug.h"
dc63bfd4 44#include "ripd/rip_interface.h"
6b0655a2 45
d62a17ae 46DEFINE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc))
47DEFINE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc))
3012671f 48
dc63bfd4 49/* static prototypes */
d62a17ae 50static void rip_enable_apply(struct interface *);
51static void rip_passive_interface_apply(struct interface *);
dc63bfd4 52static int rip_if_down(struct interface *ifp);
045c5389 53static int rip_enable_if_lookup(struct rip *rip, const char *ifname);
d62a17ae 54static int rip_enable_network_lookup2(struct connected *connected);
045c5389 55static void rip_enable_apply_all(struct rip *rip);
6b0655a2 56
d62a17ae 57const struct message ri_version_msg[] = {{RI_RIP_VERSION_1, "1"},
58 {RI_RIP_VERSION_2, "2"},
59 {RI_RIP_VERSION_1_AND_2, "1 2"},
60 {RI_RIP_VERSION_NONE, "none"},
61 {0}};
718e3744 62
718e3744 63/* Join to the RIP version 2 multicast group. */
d62a17ae 64static int ipv4_multicast_join(int sock, struct in_addr group,
65 struct in_addr ifa, ifindex_t ifindex)
718e3744 66{
d62a17ae 67 int ret;
718e3744 68
d62a17ae 69 ret = setsockopt_ipv4_multicast(sock, IP_ADD_MEMBERSHIP, ifa,
70 group.s_addr, ifindex);
718e3744 71
d62a17ae 72 if (ret < 0)
73 zlog_info("can't setsockopt IP_ADD_MEMBERSHIP %s",
74 safe_strerror(errno));
718e3744 75
d62a17ae 76 return ret;
718e3744 77}
78
79/* Leave from the RIP version 2 multicast group. */
d62a17ae 80static int ipv4_multicast_leave(int sock, struct in_addr group,
81 struct in_addr ifa, ifindex_t ifindex)
718e3744 82{
d62a17ae 83 int ret;
718e3744 84
d62a17ae 85 ret = setsockopt_ipv4_multicast(sock, IP_DROP_MEMBERSHIP, ifa,
86 group.s_addr, ifindex);
718e3744 87
d62a17ae 88 if (ret < 0)
89 zlog_info("can't setsockopt IP_DROP_MEMBERSHIP");
718e3744 90
d62a17ae 91 return ret;
718e3744 92}
6b0655a2 93
d62a17ae 94static void rip_interface_reset(struct rip_interface *);
1dec2166 95
718e3744 96/* Allocate new RIP's interface configuration. */
d62a17ae 97static struct rip_interface *rip_interface_new(void)
718e3744 98{
d62a17ae 99 struct rip_interface *ri;
718e3744 100
d62a17ae 101 ri = XCALLOC(MTYPE_RIP_INTERFACE, sizeof(struct rip_interface));
718e3744 102
d62a17ae 103 rip_interface_reset(ri);
718e3744 104
d62a17ae 105 return ri;
718e3744 106}
107
d62a17ae 108void rip_interface_multicast_set(int sock, struct connected *connected)
718e3744 109{
d62a17ae 110 struct in_addr addr;
4a3867d0 111
d62a17ae 112 assert(connected != NULL);
4a3867d0 113
d62a17ae 114 addr = CONNECTED_ID(connected)->u.prefix4;
115
116 if (setsockopt_ipv4_multicast_if(sock, addr, connected->ifp->ifindex)
117 < 0) {
118 zlog_warn(
119 "Can't setsockopt IP_MULTICAST_IF on fd %d to "
120 "ifindex %d for interface %s",
121 sock, connected->ifp->ifindex, connected->ifp->name);
122 }
4a3867d0 123
d62a17ae 124 return;
3fb9cd6e 125}
718e3744 126
127/* Send RIP request packet to specified interface. */
d7c0a89a 128static void rip_request_interface_send(struct interface *ifp, uint8_t version)
718e3744 129{
d62a17ae 130 struct sockaddr_in to;
718e3744 131
d62a17ae 132 /* RIPv2 support multicast. */
133 if (version == RIPv2 && if_is_multicast(ifp)) {
718e3744 134
d62a17ae 135 if (IS_RIP_DEBUG_EVENT)
136 zlog_debug("multicast request on %s", ifp->name);
718e3744 137
d62a17ae 138 rip_request_send(NULL, ifp, version, NULL);
139 return;
140 }
718e3744 141
d62a17ae 142 /* RIPv1 and non multicast interface. */
143 if (if_is_pointopoint(ifp) || if_is_broadcast(ifp)) {
144 struct listnode *cnode, *cnnode;
145 struct connected *connected;
146
147 if (IS_RIP_DEBUG_EVENT)
148 zlog_debug("broadcast request to %s", ifp->name);
149
150 for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode,
151 connected)) {
2e37ad7f
RW
152 if (connected->address->family != AF_INET)
153 continue;
154
155 memset(&to, 0, sizeof(struct sockaddr_in));
156 to.sin_port = htons(RIP_PORT_DEFAULT);
157 if (connected->destination)
158 /* use specified broadcast or peer
159 * destination addr */
160 to.sin_addr = connected->destination->u.prefix4;
161 else if (connected->address->prefixlen
162 < IPV4_MAX_PREFIXLEN)
163 /* calculate the appropriate broadcast
164 * address */
165 to.sin_addr.s_addr = ipv4_broadcast_addr(
166 connected->address->u.prefix4.s_addr,
167 connected->address->prefixlen);
168 else
169 /* do not know where to send the packet
170 */
171 continue;
172
173 if (IS_RIP_DEBUG_EVENT)
174 zlog_debug("SEND request to %s",
175 inet_ntoa(to.sin_addr));
176
177 rip_request_send(&to, ifp, version, connected);
d62a17ae 178 }
718e3744 179 }
718e3744 180}
181
182/* This will be executed when interface goes up. */
d62a17ae 183static void rip_request_interface(struct interface *ifp)
718e3744 184{
d62a17ae 185 struct rip_interface *ri;
2e37ad7f 186 int vsend;
718e3744 187
d62a17ae 188 /* In default ripd doesn't send RIP_REQUEST to the loopback interface.
189 */
190 if (if_is_loopback(ifp))
191 return;
718e3744 192
d62a17ae 193 /* If interface is down, don't send RIP packet. */
194 if (!if_is_operative(ifp))
195 return;
718e3744 196
d62a17ae 197 /* Fetch RIP interface information. */
198 ri = ifp->info;
718e3744 199
d62a17ae 200 /* If there is no version configuration in the interface,
201 use rip's version setting. */
045c5389 202 vsend = ((ri->ri_send == RI_RIP_UNSPEC) ? ri->rip->version_send
2e37ad7f
RW
203 : ri->ri_send);
204 if (vsend & RIPv1)
205 rip_request_interface_send(ifp, RIPv1);
206 if (vsend & RIPv2)
207 rip_request_interface_send(ifp, RIPv2);
718e3744 208}
209
2c239705 210#if 0
718e3744 211/* Send RIP request to the neighbor. */
dc63bfd4 212static void
718e3744 213rip_request_neighbor (struct in_addr addr)
214{
215 struct sockaddr_in to;
216
217 memset (&to, 0, sizeof (struct sockaddr_in));
218 to.sin_port = htons (RIP_PORT_DEFAULT);
219 to.sin_addr = addr;
220
931cd54d 221 rip_request_send (&to, NULL, rip->version_send, NULL);
718e3744 222}
223
224/* Request routes at all interfaces. */
dc63bfd4 225static void
226rip_request_neighbor_all (void)
718e3744 227{
228 struct route_node *rp;
229
230 if (! rip)
231 return;
232
233 if (IS_RIP_DEBUG_EVENT)
5d6c3779 234 zlog_debug ("request to the all neighbor");
718e3744 235
236 /* Send request to all neighbor. */
237 for (rp = route_top (rip->neighbor); rp; rp = route_next (rp))
238 if (rp->info)
239 rip_request_neighbor (rp->p.u.prefix4);
240}
2c239705 241#endif
718e3744 242
243/* Multicast packet receive socket. */
d62a17ae 244static int rip_multicast_join(struct interface *ifp, int sock)
718e3744 245{
d62a17ae 246 struct listnode *cnode;
247 struct connected *ifc;
718e3744 248
d62a17ae 249 if (if_is_operative(ifp) && if_is_multicast(ifp)) {
250 if (IS_RIP_DEBUG_EVENT)
251 zlog_debug("multicast join at %s", ifp->name);
718e3744 252
d62a17ae 253 for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) {
254 struct prefix_ipv4 *p;
255 struct in_addr group;
256
257 p = (struct prefix_ipv4 *)ifc->address;
258
259 if (p->family != AF_INET)
260 continue;
261
262 group.s_addr = htonl(INADDR_RIP_GROUP);
263 if (ipv4_multicast_join(sock, group, p->prefix,
264 ifp->ifindex)
265 < 0)
266 return -1;
267 else
268 return 0;
269 }
718e3744 270 }
d62a17ae 271 return 0;
718e3744 272}
273
274/* Leave from multicast group. */
d62a17ae 275static void rip_multicast_leave(struct interface *ifp, int sock)
718e3744 276{
d62a17ae 277 struct listnode *cnode;
278 struct connected *connected;
718e3744 279
d62a17ae 280 if (if_is_up(ifp) && if_is_multicast(ifp)) {
281 if (IS_RIP_DEBUG_EVENT)
282 zlog_debug("multicast leave from %s", ifp->name);
718e3744 283
d62a17ae 284 for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
285 struct prefix_ipv4 *p;
286 struct in_addr group;
287
288 p = (struct prefix_ipv4 *)connected->address;
289
290 if (p->family != AF_INET)
291 continue;
292
293 group.s_addr = htonl(INADDR_RIP_GROUP);
294 if (ipv4_multicast_leave(sock, group, p->prefix,
295 ifp->ifindex)
296 == 0)
297 return;
298 }
299 }
718e3744 300}
301
302/* Is there and address on interface that I could use ? */
d62a17ae 303static int rip_if_ipv4_address_check(struct interface *ifp)
718e3744 304{
d62a17ae 305 struct listnode *nn;
306 struct connected *connected;
307 int count = 0;
718e3744 308
d62a17ae 309 for (ALL_LIST_ELEMENTS_RO(ifp->connected, nn, connected)) {
310 struct prefix *p;
718e3744 311
d62a17ae 312 p = connected->address;
313
314 if (p->family == AF_INET)
315 count++;
316 }
718e3744 317
d62a17ae 318 return count;
718e3744 319}
d62a17ae 320
31a476c7 321
322/* Does this address belongs to me ? */
045c5389 323int if_check_address(struct rip *rip, struct in_addr addr)
d62a17ae 324{
d62a17ae 325 struct interface *ifp;
31a476c7 326
ae7b826a 327 FOR_ALL_INTERFACES (rip->vrf, ifp) {
d62a17ae 328 struct listnode *cnode;
329 struct connected *connected;
31a476c7 330
d62a17ae 331 for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
332 struct prefix_ipv4 *p;
31a476c7 333
d62a17ae 334 p = (struct prefix_ipv4 *)connected->address;
335
336 if (p->family != AF_INET)
337 continue;
338
339 if (IPV4_ADDR_CMP(&p->prefix, &addr) == 0)
340 return 1;
341 }
31a476c7 342 }
d62a17ae 343 return 0;
31a476c7 344}
345
718e3744 346/* Inteface link down message processing. */
121f9dee 347int rip_interface_down(ZAPI_CALLBACK_ARGS)
718e3744 348{
d62a17ae 349 struct interface *ifp;
350 struct stream *s;
718e3744 351
d62a17ae 352 s = zclient->ibuf;
718e3744 353
d62a17ae 354 /* zebra_interface_state_read() updates interface structure in
355 iflist. */
356 ifp = zebra_interface_state_read(s, vrf_id);
718e3744 357
d62a17ae 358 if (ifp == NULL)
359 return 0;
718e3744 360
ae7b826a 361 rip_interface_sync(ifp);
d62a17ae 362 rip_if_down(ifp);
718e3744 363
d62a17ae 364 if (IS_RIP_DEBUG_ZEBRA)
365 zlog_debug(
ae7b826a
RW
366 "interface %s vrf %u index %d flags %llx metric %d mtu %d is down",
367 ifp->name, ifp->vrf_id, ifp->ifindex,
368 (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
d62a17ae 369
370 return 0;
718e3744 371}
372
373/* Inteface link up message processing */
121f9dee 374int rip_interface_up(ZAPI_CALLBACK_ARGS)
718e3744 375{
d62a17ae 376 struct interface *ifp;
377
378 /* zebra_interface_state_read () updates interface structure in
379 iflist. */
380 ifp = zebra_interface_state_read(zclient->ibuf, vrf_id);
718e3744 381
d62a17ae 382 if (ifp == NULL)
383 return 0;
718e3744 384
d62a17ae 385 if (IS_RIP_DEBUG_ZEBRA)
386 zlog_debug(
ae7b826a
RW
387 "interface %s vrf %u index %d flags %#llx metric %d mtu %d is up",
388 ifp->name, ifp->vrf_id, ifp->ifindex,
389 (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
390
391 rip_interface_sync(ifp);
718e3744 392
d62a17ae 393 /* Check if this interface is RIP enabled or not.*/
394 rip_enable_apply(ifp);
718e3744 395
d62a17ae 396 /* Check for a passive interface */
397 rip_passive_interface_apply(ifp);
718e3744 398
d62a17ae 399 /* Apply distribute list to the all interface. */
400 rip_distribute_update_interface(ifp);
718e3744 401
d62a17ae 402 return 0;
718e3744 403}
404
405/* Inteface addition message from zebra. */
121f9dee 406int rip_interface_add(ZAPI_CALLBACK_ARGS)
718e3744 407{
d62a17ae 408 struct interface *ifp;
718e3744 409
d62a17ae 410 ifp = zebra_interface_add_read(zclient->ibuf, vrf_id);
ae7b826a 411 rip_interface_sync(ifp);
718e3744 412
d62a17ae 413 if (IS_RIP_DEBUG_ZEBRA)
414 zlog_debug(
ae7b826a
RW
415 "interface add %s vrf %u index %d flags %#llx metric %d mtu %d",
416 ifp->name, ifp->vrf_id, ifp->ifindex,
417 (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
718e3744 418
d62a17ae 419 /* Check if this interface is RIP enabled or not.*/
420 rip_enable_apply(ifp);
718e3744 421
d62a17ae 422 /* Check for a passive interface */
423 rip_passive_interface_apply(ifp);
718e3744 424
d62a17ae 425 /* Apply distribute list to the all interface. */
426 rip_distribute_update_interface(ifp);
718e3744 427
d62a17ae 428 /* rip_request_neighbor_all (); */
16705130 429
d62a17ae 430 /* Check interface routemap. */
431 rip_if_rmap_update_interface(ifp);
432
433 return 0;
718e3744 434}
435
121f9dee 436int rip_interface_delete(ZAPI_CALLBACK_ARGS)
718e3744 437{
d62a17ae 438 struct interface *ifp;
439 struct stream *s;
440
718e3744 441
d62a17ae 442 s = zclient->ibuf;
443 /* zebra_interface_state_read() updates interface structure in iflist */
444 ifp = zebra_interface_state_read(s, vrf_id);
718e3744 445
d62a17ae 446 if (ifp == NULL)
447 return 0;
448
ae7b826a 449 rip_interface_sync(ifp);
d62a17ae 450 if (if_is_up(ifp)) {
451 rip_if_down(ifp);
452 }
718e3744 453
ae7b826a
RW
454 zlog_info(
455 "interface delete %s vrf %u index %d flags %#llx metric %d mtu %d",
456 ifp->name, ifp->vrf_id, ifp->ifindex,
457 (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
718e3744 458
d62a17ae 459 /* To support pseudo interface do not free interface structure. */
460 /* if_delete(ifp); */
ff880b78 461 if_set_index(ifp, IFINDEX_INTERNAL);
718e3744 462
d62a17ae 463 return 0;
718e3744 464}
465
ae7b826a 466/* VRF update for an interface. */
121f9dee 467int rip_interface_vrf_update(ZAPI_CALLBACK_ARGS)
ae7b826a
RW
468{
469 struct interface *ifp;
470 vrf_id_t new_vrf_id;
471
472 ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id,
473 &new_vrf_id);
474 if (!ifp)
475 return 0;
476
477 if (IS_RIP_DEBUG_ZEBRA)
478 zlog_debug("interface %s VRF change vrf_id %u new vrf id %u",
479 ifp->name, vrf_id, new_vrf_id);
480
481 if_update_to_new_vrf(ifp, new_vrf_id);
482 rip_interface_sync(ifp);
483
484 return 0;
485}
486
d62a17ae 487static void rip_interface_clean(struct rip_interface *ri)
4305dfd1 488{
d62a17ae 489 ri->enable_network = 0;
490 ri->enable_interface = 0;
491 ri->running = 0;
718e3744 492
d62a17ae 493 if (ri->t_wakeup) {
494 thread_cancel(ri->t_wakeup);
495 ri->t_wakeup = NULL;
496 }
4305dfd1 497}
718e3744 498
045c5389 499void rip_interfaces_clean(struct rip *rip)
718e3744 500{
d62a17ae 501 struct interface *ifp;
718e3744 502
ae7b826a 503 FOR_ALL_INTERFACES (rip->vrf, ifp)
d62a17ae 504 rip_interface_clean(ifp->info);
1dec2166 505}
718e3744 506
d62a17ae 507static void rip_interface_reset(struct rip_interface *ri)
4305dfd1 508{
94b117b2
RW
509 ri->auth_type = yang_get_default_enum("%s/authentication-scheme/mode",
510 RIP_IFACE);
511 ri->md5_auth_len = yang_get_default_enum(
512 "%s/authentication-scheme/md5-auth-length", RIP_IFACE);
718e3744 513
d62a17ae 514 /* Set default split-horizon behavior. If the interface is Frame
515 Relay or SMDS is enabled, the default value for split-horizon is
516 off. But currently Zebra does detect Frame Relay or SMDS
517 interface. So all interface is set to split horizon. */
94b117b2
RW
518 ri->split_horizon =
519 yang_get_default_enum("%s/split-horizon", RIP_IFACE);
718e3744 520
94b117b2
RW
521 ri->ri_send = yang_get_default_enum("%s/version-send", RIP_IFACE);
522 ri->ri_receive = yang_get_default_enum("%s/version-receive", RIP_IFACE);
523 ri->v2_broadcast = yang_get_default_bool("%s/v2-broadcast", RIP_IFACE);
f90310cf 524
0a22ddfb 525 XFREE(MTYPE_RIP_INTERFACE_STRING, ri->auth_str);
03c20031 526
0a22ddfb 527 XFREE(MTYPE_RIP_INTERFACE_STRING, ri->key_chain);
03c20031 528
d62a17ae 529 ri->list[RIP_FILTER_IN] = NULL;
530 ri->list[RIP_FILTER_OUT] = NULL;
718e3744 531
d62a17ae 532 ri->prefix[RIP_FILTER_IN] = NULL;
533 ri->prefix[RIP_FILTER_OUT] = NULL;
718e3744 534
d62a17ae 535 ri->recv_badpackets = 0;
536 ri->recv_badroutes = 0;
537 ri->sent_updates = 0;
4305dfd1 538
d62a17ae 539 ri->passive = 0;
718e3744 540
d62a17ae 541 rip_interface_clean(ri);
4305dfd1 542}
718e3744 543
d62a17ae 544int rip_if_down(struct interface *ifp)
718e3744 545{
045c5389 546 struct rip *rip;
d62a17ae 547 struct route_node *rp;
548 struct rip_info *rinfo;
549 struct rip_interface *ri = NULL;
550 struct list *list = NULL;
551 struct listnode *listnode = NULL, *nextnode = NULL;
045c5389
RW
552
553 ri = ifp->info;
554 rip = ri->rip;
d62a17ae 555 if (rip) {
556 for (rp = route_top(rip->table); rp; rp = route_next(rp))
557 if ((list = rp->info) != NULL)
558 for (ALL_LIST_ELEMENTS(list, listnode, nextnode,
559 rinfo))
dd127197 560 if (rinfo->nh.ifindex == ifp->ifindex)
045c5389 561 rip_ecmp_delete(rip, rinfo);
d62a17ae 562
563 if (ri->running) {
564 if (IS_RIP_DEBUG_EVENT)
565 zlog_debug("turn off %s", ifp->name);
566
567 /* Leave from multicast group. */
568 rip_multicast_leave(ifp, rip->sock);
569
570 ri->running = 0;
571 }
572 }
573
574 return 0;
718e3744 575}
576
d62a17ae 577static void rip_apply_address_add(struct connected *ifc)
dc63bfd4 578{
045c5389
RW
579 struct rip_interface *ri = ifc->ifp->info;
580 struct rip *rip = ri->rip;
d62a17ae 581 struct prefix_ipv4 address;
3f5682c8 582 struct nexthop nh;
d62a17ae 583 struct prefix *p;
16705130 584
d62a17ae 585 if (!rip)
586 return;
16705130 587
d62a17ae 588 if (!if_is_up(ifc->ifp))
589 return;
16705130 590
d62a17ae 591 p = ifc->address;
16705130 592
d62a17ae 593 memset(&address, 0, sizeof(address));
3f5682c8
DS
594 memset(&nh, 0, sizeof(nh));
595
d62a17ae 596 address.family = p->family;
597 address.prefix = p->u.prefix4;
598 address.prefixlen = p->prefixlen;
599 apply_mask_ipv4(&address);
16705130 600
3f5682c8
DS
601 nh.ifindex = ifc->ifp->ifindex;
602 nh.type = NEXTHOP_TYPE_IFINDEX;
603
d62a17ae 604 /* Check if this interface is RIP enabled or not
605 or Check if this address's prefix is RIP enabled */
045c5389 606 if ((rip_enable_if_lookup(rip, ifc->ifp->name) >= 0)
d62a17ae 607 || (rip_enable_network_lookup2(ifc) >= 0))
045c5389
RW
608 rip_redistribute_add(rip, ZEBRA_ROUTE_CONNECT,
609 RIP_ROUTE_INTERFACE, &address, &nh, 0, 0,
610 0);
16705130 611}
612
121f9dee 613int rip_interface_address_add(ZAPI_CALLBACK_ARGS)
718e3744 614{
d62a17ae 615 struct connected *ifc;
616 struct prefix *p;
718e3744 617
d62a17ae 618 ifc = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD,
619 zclient->ibuf, vrf_id);
718e3744 620
d62a17ae 621 if (ifc == NULL)
622 return 0;
718e3744 623
d62a17ae 624 p = ifc->address;
718e3744 625
d62a17ae 626 if (p->family == AF_INET) {
627 if (IS_RIP_DEBUG_ZEBRA)
628 zlog_debug("connected address %s/%d is added",
629 inet_ntoa(p->u.prefix4), p->prefixlen);
16705130 630
d62a17ae 631 rip_enable_apply(ifc->ifp);
632 /* Check if this prefix needs to be redistributed */
633 rip_apply_address_add(ifc);
718e3744 634
d62a17ae 635 hook_call(rip_ifaddr_add, ifc);
636 }
718e3744 637
d62a17ae 638 return 0;
718e3744 639}
640
d62a17ae 641static void rip_apply_address_del(struct connected *ifc)
642{
045c5389
RW
643 struct rip_interface *ri = ifc->ifp->info;
644 struct rip *rip = ri->rip;
d62a17ae 645 struct prefix_ipv4 address;
646 struct prefix *p;
16705130 647
d62a17ae 648 if (!rip)
649 return;
16705130 650
d62a17ae 651 if (!if_is_up(ifc->ifp))
652 return;
16705130 653
d62a17ae 654 p = ifc->address;
16705130 655
d62a17ae 656 memset(&address, 0, sizeof(address));
657 address.family = p->family;
658 address.prefix = p->u.prefix4;
659 address.prefixlen = p->prefixlen;
660 apply_mask_ipv4(&address);
16705130 661
045c5389 662 rip_redistribute_delete(rip, ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
d62a17ae 663 &address, ifc->ifp->ifindex);
16705130 664}
665
121f9dee 666int rip_interface_address_delete(ZAPI_CALLBACK_ARGS)
718e3744 667{
d62a17ae 668 struct connected *ifc;
669 struct prefix *p;
718e3744 670
d62a17ae 671 ifc = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE,
672 zclient->ibuf, vrf_id);
718e3744 673
d62a17ae 674 if (ifc) {
675 p = ifc->address;
676 if (p->family == AF_INET) {
677 if (IS_RIP_DEBUG_ZEBRA)
678 zlog_debug("connected address %s/%d is deleted",
679 inet_ntoa(p->u.prefix4),
680 p->prefixlen);
16705130 681
d62a17ae 682 hook_call(rip_ifaddr_del, ifc);
718e3744 683
d62a17ae 684 /* Chech wether this prefix needs to be removed */
685 rip_apply_address_del(ifc);
686 }
718e3744 687
d62a17ae 688 connected_free(ifc);
689 }
718e3744 690
d62a17ae 691 return 0;
718e3744 692}
6b0655a2 693
718e3744 694/* Check interface is enabled by network statement. */
16705130 695/* Check wether the interface has at least a connected prefix that
696 * is within the ripng_enable_network table. */
d62a17ae 697static int rip_enable_network_lookup_if(struct interface *ifp)
698{
045c5389
RW
699 struct rip_interface *ri = ifp->info;
700 struct rip *rip = ri->rip;
d62a17ae 701 struct listnode *node, *nnode;
702 struct connected *connected;
703 struct prefix_ipv4 address;
704
1205fdc4
RW
705 if (!rip)
706 return -1;
707
d62a17ae 708 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) {
709 struct prefix *p;
dc7204b7 710 struct route_node *n;
d62a17ae 711
712 p = connected->address;
713
714 if (p->family == AF_INET) {
715 address.family = AF_INET;
716 address.prefix = p->u.prefix4;
717 address.prefixlen = IPV4_MAX_BITLEN;
718
1205fdc4 719 n = route_node_match(rip->enable_network,
dc7204b7
A
720 (struct prefix *)&address);
721 if (n) {
722 route_unlock_node(n);
d62a17ae 723 return 1;
724 }
725 }
726 }
727 return -1;
718e3744 728}
729
16705130 730/* Check wether connected is within the ripng_enable_network table. */
045c5389 731static int rip_enable_network_lookup2(struct connected *connected)
16705130 732{
045c5389
RW
733 struct rip_interface *ri = connected->ifp->info;
734 struct rip *rip = ri->rip;
d62a17ae 735 struct prefix_ipv4 address;
736 struct prefix *p;
16705130 737
d62a17ae 738 p = connected->address;
16705130 739
d62a17ae 740 if (p->family == AF_INET) {
741 struct route_node *node;
16705130 742
d62a17ae 743 address.family = p->family;
744 address.prefix = p->u.prefix4;
745 address.prefixlen = IPV4_MAX_BITLEN;
16705130 746
d62a17ae 747 /* LPM on p->family, p->u.prefix4/IPV4_MAX_BITLEN within
1205fdc4
RW
748 * rip->enable_network */
749 node = route_node_match(rip->enable_network,
d62a17ae 750 (struct prefix *)&address);
16705130 751
d62a17ae 752 if (node) {
753 route_unlock_node(node);
754 return 1;
755 }
756 }
16705130 757
d62a17ae 758 return -1;
16705130 759}
718e3744 760/* Add RIP enable network. */
045c5389 761int rip_enable_network_add(struct rip *rip, struct prefix *p)
718e3744 762{
d62a17ae 763 struct route_node *node;
718e3744 764
1205fdc4 765 node = route_node_get(rip->enable_network, p);
718e3744 766
d62a17ae 767 if (node->info) {
768 route_unlock_node(node);
3d7a1be8 769 return NB_ERR_INCONSISTENCY;
d62a17ae 770 } else
771 node->info = (void *)1;
718e3744 772
d62a17ae 773 /* XXX: One should find a better solution than a generic one */
045c5389 774 rip_enable_apply_all(rip);
16705130 775
3d7a1be8 776 return NB_OK;
718e3744 777}
778
779/* Delete RIP enable network. */
045c5389 780int rip_enable_network_delete(struct rip *rip, struct prefix *p)
718e3744 781{
d62a17ae 782 struct route_node *node;
718e3744 783
1205fdc4 784 node = route_node_lookup(rip->enable_network, p);
d62a17ae 785 if (node) {
786 node->info = NULL;
718e3744 787
d62a17ae 788 /* Unlock info lock. */
789 route_unlock_node(node);
718e3744 790
d62a17ae 791 /* Unlock lookup lock. */
792 route_unlock_node(node);
718e3744 793
d62a17ae 794 /* XXX: One should find a better solution than a generic one */
045c5389 795 rip_enable_apply_all(rip);
16705130 796
3d7a1be8 797 return NB_OK;
d62a17ae 798 }
3d7a1be8
RW
799
800 return NB_ERR_INCONSISTENCY;
718e3744 801}
802
803/* Check interface is enabled by ifname statement. */
045c5389 804static int rip_enable_if_lookup(struct rip *rip, const char *ifname)
718e3744 805{
d62a17ae 806 unsigned int i;
807 char *str;
718e3744 808
ca046902
RW
809 if (!rip)
810 return -1;
811
812 for (i = 0; i < vector_active(rip->enable_interface); i++)
813 if ((str = vector_slot(rip->enable_interface, i)) != NULL)
d62a17ae 814 if (strcmp(str, ifname) == 0)
815 return i;
816 return -1;
718e3744 817}
818
819/* Add interface to rip_enable_if. */
045c5389 820int rip_enable_if_add(struct rip *rip, const char *ifname)
718e3744 821{
d62a17ae 822 int ret;
718e3744 823
045c5389 824 ret = rip_enable_if_lookup(rip, ifname);
d62a17ae 825 if (ret >= 0)
3d7a1be8 826 return NB_ERR_INCONSISTENCY;
718e3744 827
ca046902 828 vector_set(rip->enable_interface,
03c20031 829 XSTRDUP(MTYPE_RIP_INTERFACE_STRING, ifname));
718e3744 830
045c5389 831 rip_enable_apply_all(rip); /* TODOVJ */
16705130 832
3d7a1be8 833 return NB_OK;
718e3744 834}
835
836/* Delete interface from rip_enable_if. */
045c5389 837int rip_enable_if_delete(struct rip *rip, const char *ifname)
718e3744 838{
d62a17ae 839 int index;
840 char *str;
718e3744 841
045c5389 842 index = rip_enable_if_lookup(rip, ifname);
d62a17ae 843 if (index < 0)
3d7a1be8 844 return NB_ERR_INCONSISTENCY;
718e3744 845
ca046902 846 str = vector_slot(rip->enable_interface, index);
03c20031 847 XFREE(MTYPE_RIP_INTERFACE_STRING, str);
ca046902 848 vector_unset(rip->enable_interface, index);
718e3744 849
045c5389 850 rip_enable_apply_all(rip); /* TODOVJ */
16705130 851
3d7a1be8 852 return NB_OK;
718e3744 853}
854
855/* Join to multicast group and send request to the interface. */
d62a17ae 856static int rip_interface_wakeup(struct thread *t)
718e3744 857{
d62a17ae 858 struct interface *ifp;
859 struct rip_interface *ri;
718e3744 860
d62a17ae 861 /* Get interface. */
862 ifp = THREAD_ARG(t);
718e3744 863
d62a17ae 864 ri = ifp->info;
865 ri->t_wakeup = NULL;
718e3744 866
d62a17ae 867 /* Join to multicast group. */
045c5389 868 if (rip_multicast_join(ifp, ri->rip->sock) < 0) {
450971aa 869 flog_err_sys(EC_LIB_SOCKET,
09c866e3
QY
870 "multicast join failed, interface %s not running",
871 ifp->name);
d62a17ae 872 return 0;
873 }
718e3744 874
d62a17ae 875 /* Set running flag. */
876 ri->running = 1;
877
878 /* Send RIP request to the interface. */
879 rip_request_interface(ifp);
880
881 return 0;
882}
883
884static void rip_connect_set(struct interface *ifp, int set)
885{
045c5389
RW
886 struct rip_interface *ri = ifp->info;
887 struct rip *rip = ri->rip;
d62a17ae 888 struct listnode *node, *nnode;
889 struct connected *connected;
890 struct prefix_ipv4 address;
3f5682c8
DS
891 struct nexthop nh;
892
893 memset(&nh, 0, sizeof(nh));
d62a17ae 894
895 for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) {
896 struct prefix *p;
897 p = connected->address;
898
899 if (p->family != AF_INET)
900 continue;
901
902 address.family = AF_INET;
903 address.prefix = p->u.prefix4;
904 address.prefixlen = p->prefixlen;
905 apply_mask_ipv4(&address);
906
3f5682c8
DS
907 nh.ifindex = connected->ifp->ifindex;
908 nh.type = NEXTHOP_TYPE_IFINDEX;
d62a17ae 909 if (set) {
910 /* Check once more wether this prefix is within a
911 * "network IF_OR_PREF" one */
045c5389
RW
912 if ((rip_enable_if_lookup(rip, connected->ifp->name)
913 >= 0)
d62a17ae 914 || (rip_enable_network_lookup2(connected) >= 0))
045c5389 915 rip_redistribute_add(rip, ZEBRA_ROUTE_CONNECT,
996c9314
LB
916 RIP_ROUTE_INTERFACE,
917 &address, &nh, 0, 0, 0);
d62a17ae 918 } else {
045c5389 919 rip_redistribute_delete(rip, ZEBRA_ROUTE_CONNECT,
d62a17ae 920 RIP_ROUTE_INTERFACE, &address,
921 connected->ifp->ifindex);
045c5389
RW
922 if (rip_redistribute_check(rip, ZEBRA_ROUTE_CONNECT))
923 rip_redistribute_add(rip, ZEBRA_ROUTE_CONNECT,
996c9314
LB
924 RIP_ROUTE_REDISTRIBUTE,
925 &address, &nh, 0, 0, 0);
d62a17ae 926 }
927 }
718e3744 928}
929
930/* Update interface status. */
d62a17ae 931void rip_enable_apply(struct interface *ifp)
718e3744 932{
d62a17ae 933 int ret;
934 struct rip_interface *ri = NULL;
718e3744 935
d62a17ae 936 /* Check interface. */
937 if (!if_is_operative(ifp))
938 return;
718e3744 939
d62a17ae 940 ri = ifp->info;
941
942 /* Check network configuration. */
943 ret = rip_enable_network_lookup_if(ifp);
944
945 /* If the interface is matched. */
946 if (ret > 0)
947 ri->enable_network = 1;
948 else
949 ri->enable_network = 0;
950
951 /* Check interface name configuration. */
045c5389 952 ret = rip_enable_if_lookup(ri->rip, ifp->name);
d62a17ae 953 if (ret >= 0)
954 ri->enable_interface = 1;
955 else
956 ri->enable_interface = 0;
718e3744 957
d62a17ae 958 /* any interface MUST have an IPv4 address */
959 if (!rip_if_ipv4_address_check(ifp)) {
960 ri->enable_network = 0;
961 ri->enable_interface = 0;
718e3744 962 }
718e3744 963
d62a17ae 964 /* Update running status of the interface. */
965 if (ri->enable_network || ri->enable_interface) {
2e37ad7f
RW
966 if (IS_RIP_DEBUG_EVENT)
967 zlog_debug("turn on %s", ifp->name);
968
969 /* Add interface wake up thread. */
970 thread_add_timer(master, rip_interface_wakeup, ifp, 1,
971 &ri->t_wakeup);
972 rip_connect_set(ifp, 1);
973 } else if (ri->running) {
974 /* Might as well clean up the route table as well
975 * rip_if_down sets to 0 ri->running, and displays "turn
976 *off %s"
977 **/
978 rip_if_down(ifp);
d62a17ae 979
2e37ad7f 980 rip_connect_set(ifp, 0);
718e3744 981 }
718e3744 982}
983
984/* Apply network configuration to all interface. */
045c5389 985static void rip_enable_apply_all(struct rip *rip)
718e3744 986{
d62a17ae 987 struct interface *ifp;
718e3744 988
d62a17ae 989 /* Check each interface. */
ae7b826a 990 FOR_ALL_INTERFACES (rip->vrf, ifp)
d62a17ae 991 rip_enable_apply(ifp);
718e3744 992}
993
045c5389 994int rip_neighbor_lookup(struct rip *rip, struct sockaddr_in *from)
718e3744 995{
d62a17ae 996 struct prefix_ipv4 p;
997 struct route_node *node;
718e3744 998
d62a17ae 999 memset(&p, 0, sizeof(struct prefix_ipv4));
1000 p.family = AF_INET;
1001 p.prefix = from->sin_addr;
1002 p.prefixlen = IPV4_MAX_BITLEN;
718e3744 1003
d62a17ae 1004 node = route_node_lookup(rip->neighbor, (struct prefix *)&p);
1005 if (node) {
1006 route_unlock_node(node);
1007 return 1;
1008 }
1009 return 0;
718e3744 1010}
1011
1012/* Add new RIP neighbor to the neighbor tree. */
045c5389 1013int rip_neighbor_add(struct rip *rip, struct prefix_ipv4 *p)
718e3744 1014{
d62a17ae 1015 struct route_node *node;
718e3744 1016
d62a17ae 1017 node = route_node_get(rip->neighbor, (struct prefix *)p);
718e3744 1018
d62a17ae 1019 if (node->info)
f0ab22fb 1020 return NB_ERR_INCONSISTENCY;
718e3744 1021
d62a17ae 1022 node->info = rip->neighbor;
718e3744 1023
f0ab22fb 1024 return NB_OK;
718e3744 1025}
1026
1027/* Delete RIP neighbor from the neighbor tree. */
045c5389 1028int rip_neighbor_delete(struct rip *rip, struct prefix_ipv4 *p)
718e3744 1029{
d62a17ae 1030 struct route_node *node;
718e3744 1031
d62a17ae 1032 /* Lock for look up. */
1033 node = route_node_lookup(rip->neighbor, (struct prefix *)p);
1034 if (!node)
f0ab22fb 1035 return NB_ERR_INCONSISTENCY;
718e3744 1036
d62a17ae 1037 node->info = NULL;
718e3744 1038
d62a17ae 1039 /* Unlock lookup lock. */
1040 route_unlock_node(node);
718e3744 1041
d62a17ae 1042 /* Unlock real neighbor information lock. */
1043 route_unlock_node(node);
1044
f0ab22fb 1045 return NB_OK;
718e3744 1046}
1047
1048/* Clear all network and neighbor configuration. */
045c5389 1049void rip_clean_network(struct rip *rip)
d62a17ae 1050{
1051 unsigned int i;
1052 char *str;
1053 struct route_node *rn;
1054
1205fdc4
RW
1055 /* rip->enable_network. */
1056 for (rn = route_top(rip->enable_network); rn; rn = route_next(rn))
d62a17ae 1057 if (rn->info) {
1058 rn->info = NULL;
1059 route_unlock_node(rn);
1060 }
1061
ca046902
RW
1062 /* rip->enable_interface. */
1063 for (i = 0; i < vector_active(rip->enable_interface); i++)
1064 if ((str = vector_slot(rip->enable_interface, i)) != NULL) {
03c20031 1065 XFREE(MTYPE_RIP_INTERFACE_STRING, str);
ca046902 1066 vector_slot(rip->enable_interface, i) = NULL;
d62a17ae 1067 }
718e3744 1068}
6b0655a2 1069
718e3744 1070/* Utility function for looking up passive interface settings. */
045c5389 1071static int rip_passive_nondefault_lookup(struct rip *rip, const char *ifname)
718e3744 1072{
d62a17ae 1073 unsigned int i;
1074 char *str;
718e3744 1075
5a29c0d5
RW
1076 for (i = 0; i < vector_active(rip->passive_nondefault); i++)
1077 if ((str = vector_slot(rip->passive_nondefault, i)) != NULL)
d62a17ae 1078 if (strcmp(str, ifname) == 0)
1079 return i;
1080 return -1;
718e3744 1081}
1082
045c5389 1083static void rip_passive_interface_apply(struct interface *ifp)
718e3744 1084{
045c5389 1085 struct rip *rip;
d62a17ae 1086 struct rip_interface *ri;
718e3744 1087
045c5389
RW
1088 ri = ifp->info;
1089 rip = ri->rip;
44f2f852
RW
1090 if (rip == NULL)
1091 return;
1092
045c5389 1093 ri->passive = ((rip_passive_nondefault_lookup(rip, ifp->name) < 0)
44f2f852
RW
1094 ? rip->passive_default
1095 : !rip->passive_default);
4aaff3f8 1096
d62a17ae 1097 if (IS_RIP_DEBUG_ZEBRA)
1098 zlog_debug("interface %s: passive = %d", ifp->name,
1099 ri->passive);
718e3744 1100}
1101
045c5389 1102static void rip_passive_interface_apply_all(struct rip *rip)
718e3744 1103{
d62a17ae 1104 struct interface *ifp;
718e3744 1105
ae7b826a 1106 FOR_ALL_INTERFACES (rip->vrf, ifp)
d62a17ae 1107 rip_passive_interface_apply(ifp);
718e3744 1108}
1109
1110/* Passive interface. */
045c5389 1111int rip_passive_nondefault_set(struct rip *rip, const char *ifname)
718e3744 1112{
045c5389 1113 if (rip_passive_nondefault_lookup(rip, ifname) >= 0)
44f2f852
RW
1114 /*
1115 * Don't return an error, this can happen after changing
1116 * 'passive-default'.
1117 */
1118 return NB_OK;
718e3744 1119
5a29c0d5 1120 vector_set(rip->passive_nondefault,
03c20031 1121 XSTRDUP(MTYPE_RIP_INTERFACE_STRING, ifname));
718e3744 1122
045c5389 1123 rip_passive_interface_apply_all(rip);
718e3744 1124
44f2f852 1125 return NB_OK;
718e3744 1126}
1127
045c5389 1128int rip_passive_nondefault_unset(struct rip *rip, const char *ifname)
718e3744 1129{
d62a17ae 1130 int i;
1131 char *str;
718e3744 1132
045c5389 1133 i = rip_passive_nondefault_lookup(rip, ifname);
d62a17ae 1134 if (i < 0)
44f2f852
RW
1135 /*
1136 * Don't return an error, this can happen after changing
1137 * 'passive-default'.
1138 */
1139 return NB_OK;
718e3744 1140
5a29c0d5 1141 str = vector_slot(rip->passive_nondefault, i);
03c20031 1142 XFREE(MTYPE_RIP_INTERFACE_STRING, str);
5a29c0d5 1143 vector_unset(rip->passive_nondefault, i);
718e3744 1144
045c5389 1145 rip_passive_interface_apply_all(rip);
718e3744 1146
44f2f852 1147 return NB_OK;
718e3744 1148}
1149
1150/* Free all configured RIP passive-interface settings. */
045c5389 1151void rip_passive_nondefault_clean(struct rip *rip)
718e3744 1152{
d62a17ae 1153 unsigned int i;
1154 char *str;
718e3744 1155
5a29c0d5
RW
1156 for (i = 0; i < vector_active(rip->passive_nondefault); i++)
1157 if ((str = vector_slot(rip->passive_nondefault, i)) != NULL) {
03c20031 1158 XFREE(MTYPE_RIP_INTERFACE_STRING, str);
5a29c0d5 1159 vector_slot(rip->passive_nondefault, i) = NULL;
d62a17ae 1160 }
045c5389 1161 rip_passive_interface_apply_all(rip);
718e3744 1162}
6b0655a2 1163
718e3744 1164/* Write rip configuration of each interface. */
d62a17ae 1165static int rip_interface_config_write(struct vty *vty)
1166{
ae7b826a 1167 struct vrf *vrf;
94b117b2 1168 int write = 0;
d62a17ae 1169
ae7b826a
RW
1170 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
1171 struct interface *ifp;
d62a17ae 1172
ae7b826a
RW
1173 FOR_ALL_INTERFACES (vrf, ifp) {
1174 struct lyd_node *dnode;
1175
1176 dnode = yang_dnode_get(
1177 running_config->dnode,
1178 "/frr-interface:lib/interface[name='%s'][vrf='%s']",
1179 ifp->name, vrf->name);
1180 if (dnode == NULL)
1181 continue;
d62a17ae 1182
ae7b826a
RW
1183 write = 1;
1184 nb_cli_show_dnode_cmds(vty, dnode, false);
1185 }
d62a17ae 1186 }
94b117b2
RW
1187
1188 return write;
d62a17ae 1189}
1190
045c5389 1191int rip_show_network_config(struct vty *vty, struct rip *rip)
d62a17ae 1192{
1193 unsigned int i;
1194 char *ifname;
1195 struct route_node *node;
1196
1197 /* Network type RIP enable interface statement. */
1205fdc4 1198 for (node = route_top(rip->enable_network); node;
d62a17ae 1199 node = route_next(node))
1200 if (node->info)
44f2f852 1201 vty_out(vty, " %s/%u\n",
d62a17ae 1202 inet_ntoa(node->p.u.prefix4),
1203 node->p.prefixlen);
1204
1205 /* Interface name RIP enable statement. */
ca046902
RW
1206 for (i = 0; i < vector_active(rip->enable_interface); i++)
1207 if ((ifname = vector_slot(rip->enable_interface, i)) != NULL)
44f2f852 1208 vty_out(vty, " %s\n", ifname);
d62a17ae 1209
1210 /* RIP neighbors listing. */
1211 for (node = route_top(rip->neighbor); node; node = route_next(node))
1212 if (node->info)
44f2f852 1213 vty_out(vty, " %s\n", inet_ntoa(node->p.u.prefix4));
718e3744 1214
d62a17ae 1215 return 0;
1216}
1217
1218static struct cmd_node interface_node = {
9d303b37 1219 INTERFACE_NODE, "%s(config-if)# ", 1,
718e3744 1220};
1221
ae7b826a
RW
1222void rip_interface_sync(struct interface *ifp)
1223{
1224 struct vrf *vrf;
1225
1226 vrf = vrf_lookup_by_id(ifp->vrf_id);
1227 if (vrf) {
1228 struct rip_interface *ri;
1229
1230 ri = ifp->info;
1231 if (ri)
1232 ri->rip = vrf->info;
1233 }
1234}
1235
718e3744 1236/* Called when interface structure allocated. */
d62a17ae 1237static int rip_interface_new_hook(struct interface *ifp)
718e3744 1238{
d62a17ae 1239 ifp->info = rip_interface_new();
ae7b826a
RW
1240 rip_interface_sync(ifp);
1241
d62a17ae 1242 return 0;
718e3744 1243}
1244
1245/* Called when interface structure deleted. */
d62a17ae 1246static int rip_interface_delete_hook(struct interface *ifp)
718e3744 1247{
72010aca 1248 rip_interface_reset(ifp->info);
d62a17ae 1249 XFREE(MTYPE_RIP_INTERFACE, ifp->info);
1250 ifp->info = NULL;
1251 return 0;
718e3744 1252}
1253
1254/* Allocate and initialize interface vector. */
d62a17ae 1255void rip_if_init(void)
718e3744 1256{
d62a17ae 1257 /* Default initial size of interface vector. */
ce19a04a
DL
1258 hook_register_prio(if_add, 0, rip_interface_new_hook);
1259 hook_register_prio(if_del, 0, rip_interface_delete_hook);
d62a17ae 1260
d62a17ae 1261 /* Install interface node. */
1262 install_node(&interface_node, rip_interface_config_write);
1263 if_cmd_init();
718e3744 1264}