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