]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * Interface related function for RIPng. | |
3 | * Copyright (C) 1998 Kunihiro Ishiguro | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
23 | ||
24 | #include "linklist.h" | |
25 | #include "if.h" | |
26 | #include "prefix.h" | |
27 | #include "memory.h" | |
28 | #include "network.h" | |
29 | #include "filter.h" | |
30 | #include "log.h" | |
31 | #include "stream.h" | |
32 | #include "zclient.h" | |
33 | #include "command.h" | |
34 | #include "table.h" | |
35 | #include "thread.h" | |
4d4653af | 36 | #include "privs.h" |
6a69b354 | 37 | #include "vrf.h" |
718e3744 | 38 | |
39 | #include "ripngd/ripngd.h" | |
40 | #include "ripngd/ripng_debug.h" | |
6b0655a2 | 41 | |
718e3744 | 42 | /* If RFC2133 definition is used. */ |
43 | #ifndef IPV6_JOIN_GROUP | |
44 | #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP | |
45 | #endif | |
46 | #ifndef IPV6_LEAVE_GROUP | |
47 | #define IPV6_LEAVE_GROUP IPV6_DROP_MEMBERSHIP | |
48 | #endif | |
49 | ||
4d4653af | 50 | extern struct zebra_privs_t ripngd_privs; |
51 | ||
718e3744 | 52 | /* Static utility function. */ |
d62a17ae | 53 | static void ripng_enable_apply(struct interface *); |
54 | static void ripng_passive_interface_apply(struct interface *); | |
55 | static int ripng_enable_if_lookup(const char *); | |
56 | static int ripng_enable_network_lookup2(struct connected *); | |
57 | static void ripng_enable_apply_all(void); | |
718e3744 | 58 | |
59 | /* Join to the all rip routers multicast group. */ | |
d62a17ae | 60 | static int ripng_multicast_join(struct interface *ifp) |
718e3744 | 61 | { |
d62a17ae | 62 | int ret; |
63 | struct ipv6_mreq mreq; | |
64 | int save_errno; | |
65 | ||
66 | if (if_is_multicast(ifp)) { | |
67 | memset(&mreq, 0, sizeof(mreq)); | |
68 | inet_pton(AF_INET6, RIPNG_GROUP, &mreq.ipv6mr_multiaddr); | |
69 | mreq.ipv6mr_interface = ifp->ifindex; | |
70 | ||
71 | /* | |
72 | * NetBSD 1.6.2 requires root to join groups on gif(4). | |
73 | * While this is bogus, privs are available and easy to use | |
74 | * for this call as a workaround. | |
75 | */ | |
76 | if (ripngd_privs.change(ZPRIVS_RAISE)) | |
77 | zlog_err("ripng_multicast_join: could not raise privs"); | |
78 | ||
79 | ret = setsockopt(ripng->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, | |
80 | (char *)&mreq, sizeof(mreq)); | |
81 | save_errno = errno; | |
82 | ||
83 | if (ripngd_privs.change(ZPRIVS_LOWER)) | |
84 | zlog_err("ripng_multicast_join: could not lower privs"); | |
85 | ||
86 | if (ret < 0 && save_errno == EADDRINUSE) { | |
87 | /* | |
88 | * Group is already joined. This occurs due to sloppy | |
89 | * group | |
90 | * management, in particular declining to leave the | |
91 | * group on | |
92 | * an interface that has just gone down. | |
93 | */ | |
94 | zlog_warn("ripng join on %s EADDRINUSE (ignoring)\n", | |
95 | ifp->name); | |
96 | return 0; /* not an error */ | |
97 | } | |
98 | ||
99 | if (ret < 0) | |
100 | zlog_warn("can't setsockopt IPV6_JOIN_GROUP: %s", | |
101 | safe_strerror(save_errno)); | |
102 | ||
103 | if (IS_RIPNG_DEBUG_EVENT) | |
104 | zlog_debug( | |
105 | "RIPng %s join to all-rip-routers multicast group", | |
106 | ifp->name); | |
107 | ||
108 | if (ret < 0) | |
109 | return -1; | |
110 | } | |
111 | return 0; | |
718e3744 | 112 | } |
113 | ||
114 | /* Leave from the all rip routers multicast group. */ | |
d62a17ae | 115 | static int ripng_multicast_leave(struct interface *ifp) |
718e3744 | 116 | { |
d62a17ae | 117 | int ret; |
118 | struct ipv6_mreq mreq; | |
119 | ||
120 | if (if_is_multicast(ifp)) { | |
121 | memset(&mreq, 0, sizeof(mreq)); | |
122 | inet_pton(AF_INET6, RIPNG_GROUP, &mreq.ipv6mr_multiaddr); | |
123 | mreq.ipv6mr_interface = ifp->ifindex; | |
124 | ||
125 | ret = setsockopt(ripng->sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP, | |
126 | (char *)&mreq, sizeof(mreq)); | |
127 | if (ret < 0) | |
128 | zlog_warn("can't setsockopt IPV6_LEAVE_GROUP: %s\n", | |
129 | safe_strerror(errno)); | |
130 | ||
131 | if (IS_RIPNG_DEBUG_EVENT) | |
132 | zlog_debug( | |
133 | "RIPng %s leave from all-rip-routers multicast group", | |
134 | ifp->name); | |
135 | ||
136 | if (ret < 0) | |
137 | return -1; | |
138 | } | |
a94434b6 | 139 | |
d62a17ae | 140 | return 0; |
a94434b6 | 141 | } |
142 | ||
143 | /* How many link local IPv6 address could be used on the interface ? */ | |
d62a17ae | 144 | static int ripng_if_ipv6_lladdress_check(struct interface *ifp) |
a94434b6 | 145 | { |
d62a17ae | 146 | struct listnode *nn; |
147 | struct connected *connected; | |
148 | int count = 0; | |
a94434b6 | 149 | |
d62a17ae | 150 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, nn, connected)) { |
151 | struct prefix *p; | |
152 | p = connected->address; | |
718e3744 | 153 | |
d62a17ae | 154 | if ((p->family == AF_INET6) |
155 | && IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) | |
156 | count++; | |
157 | } | |
718e3744 | 158 | |
d62a17ae | 159 | return count; |
718e3744 | 160 | } |
161 | ||
d62a17ae | 162 | static int ripng_if_down(struct interface *ifp) |
718e3744 | 163 | { |
d62a17ae | 164 | struct route_node *rp; |
165 | struct ripng_info *rinfo; | |
166 | struct ripng_interface *ri; | |
167 | struct list *list = NULL; | |
168 | struct listnode *listnode = NULL, *nextnode = NULL; | |
169 | ||
170 | if (ripng) | |
171 | for (rp = route_top(ripng->table); rp; rp = route_next(rp)) | |
172 | if ((list = rp->info) != NULL) | |
173 | for (ALL_LIST_ELEMENTS(list, listnode, nextnode, | |
174 | rinfo)) | |
175 | if (rinfo->ifindex == ifp->ifindex) | |
176 | ripng_ecmp_delete(rinfo); | |
177 | ||
178 | ri = ifp->info; | |
179 | ||
180 | if (ri->running) { | |
181 | if (IS_RIPNG_DEBUG_EVENT) | |
182 | zlog_debug("turn off %s", ifp->name); | |
183 | ||
184 | /* Leave from multicast group. */ | |
185 | ripng_multicast_leave(ifp); | |
186 | ||
187 | ri->running = 0; | |
188 | } | |
189 | ||
190 | return 0; | |
718e3744 | 191 | } |
192 | ||
193 | /* Inteface link up message processing. */ | |
d62a17ae | 194 | int ripng_interface_up(int command, struct zclient *zclient, |
195 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 196 | { |
d62a17ae | 197 | struct stream *s; |
198 | struct interface *ifp; | |
718e3744 | 199 | |
d62a17ae | 200 | /* zebra_interface_state_read() updates interface structure in iflist. |
201 | */ | |
202 | s = zclient->ibuf; | |
203 | ifp = zebra_interface_state_read(s, vrf_id); | |
718e3744 | 204 | |
d62a17ae | 205 | if (ifp == NULL) |
206 | return 0; | |
718e3744 | 207 | |
d62a17ae | 208 | if (IS_RIPNG_DEBUG_ZEBRA) |
209 | zlog_debug( | |
210 | "interface up %s index %d flags %llx metric %d mtu %d", | |
211 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, | |
212 | ifp->metric, ifp->mtu6); | |
718e3744 | 213 | |
d62a17ae | 214 | /* Check if this interface is RIPng enabled or not. */ |
215 | ripng_enable_apply(ifp); | |
718e3744 | 216 | |
d62a17ae | 217 | /* Check for a passive interface. */ |
218 | ripng_passive_interface_apply(ifp); | |
718e3744 | 219 | |
d62a17ae | 220 | /* Apply distribute list to the all interface. */ |
221 | ripng_distribute_update_interface(ifp); | |
718e3744 | 222 | |
d62a17ae | 223 | return 0; |
718e3744 | 224 | } |
225 | ||
226 | /* Inteface link down message processing. */ | |
d62a17ae | 227 | int ripng_interface_down(int command, struct zclient *zclient, |
228 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 229 | { |
d62a17ae | 230 | struct stream *s; |
231 | struct interface *ifp; | |
718e3744 | 232 | |
d62a17ae | 233 | /* zebra_interface_state_read() updates interface structure in iflist. |
234 | */ | |
235 | s = zclient->ibuf; | |
236 | ifp = zebra_interface_state_read(s, vrf_id); | |
718e3744 | 237 | |
d62a17ae | 238 | if (ifp == NULL) |
239 | return 0; | |
718e3744 | 240 | |
d62a17ae | 241 | ripng_if_down(ifp); |
718e3744 | 242 | |
d62a17ae | 243 | if (IS_RIPNG_DEBUG_ZEBRA) |
244 | zlog_debug( | |
245 | "interface down %s index %d flags %#llx metric %d mtu %d", | |
246 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, | |
247 | ifp->metric, ifp->mtu6); | |
718e3744 | 248 | |
d62a17ae | 249 | return 0; |
718e3744 | 250 | } |
251 | ||
252 | /* Inteface addition message from zebra. */ | |
d62a17ae | 253 | int ripng_interface_add(int command, struct zclient *zclient, |
254 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 255 | { |
d62a17ae | 256 | struct interface *ifp; |
718e3744 | 257 | |
d62a17ae | 258 | ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); |
718e3744 | 259 | |
d62a17ae | 260 | if (IS_RIPNG_DEBUG_ZEBRA) |
261 | zlog_debug( | |
262 | "RIPng interface add %s index %d flags %#llx metric %d mtu %d", | |
263 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, | |
264 | ifp->metric, ifp->mtu6); | |
718e3744 | 265 | |
d62a17ae | 266 | /* Check is this interface is RIP enabled or not.*/ |
267 | ripng_enable_apply(ifp); | |
718e3744 | 268 | |
d62a17ae | 269 | /* Apply distribute list to the interface. */ |
270 | ripng_distribute_update_interface(ifp); | |
718e3744 | 271 | |
d62a17ae | 272 | /* Check interface routemap. */ |
273 | ripng_if_rmap_update_interface(ifp); | |
718e3744 | 274 | |
d62a17ae | 275 | return 0; |
718e3744 | 276 | } |
277 | ||
d62a17ae | 278 | int ripng_interface_delete(int command, struct zclient *zclient, |
279 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 280 | { |
d62a17ae | 281 | struct interface *ifp; |
282 | struct stream *s; | |
a94434b6 | 283 | |
d62a17ae | 284 | s = zclient->ibuf; |
285 | /* zebra_interface_state_read() updates interface structure in iflist | |
286 | */ | |
287 | ifp = zebra_interface_state_read(s, vrf_id); | |
a94434b6 | 288 | |
d62a17ae | 289 | if (ifp == NULL) |
290 | return 0; | |
a94434b6 | 291 | |
d62a17ae | 292 | if (if_is_up(ifp)) { |
293 | ripng_if_down(ifp); | |
294 | } | |
a94434b6 | 295 | |
d62a17ae | 296 | zlog_info("interface delete %s index %d flags %#llx metric %d mtu %d", |
297 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, | |
298 | ifp->metric, ifp->mtu6); | |
a94434b6 | 299 | |
d62a17ae | 300 | /* To support pseudo interface do not free interface structure. */ |
301 | /* if_delete(ifp); */ | |
ff880b78 | 302 | if_set_index(ifp, IFINDEX_INTERNAL); |
a94434b6 | 303 | |
d62a17ae | 304 | return 0; |
718e3744 | 305 | } |
306 | ||
d62a17ae | 307 | void ripng_interface_clean(void) |
a94434b6 | 308 | { |
f4e14fdb | 309 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 310 | struct interface *ifp; |
311 | struct ripng_interface *ri; | |
a94434b6 | 312 | |
f4e14fdb | 313 | RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { |
d62a17ae | 314 | ri = ifp->info; |
a94434b6 | 315 | |
d62a17ae | 316 | ri->enable_network = 0; |
317 | ri->enable_interface = 0; | |
318 | ri->running = 0; | |
a94434b6 | 319 | |
d62a17ae | 320 | if (ri->t_wakeup) { |
321 | thread_cancel(ri->t_wakeup); | |
322 | ri->t_wakeup = NULL; | |
323 | } | |
324 | } | |
325 | } | |
a94434b6 | 326 | |
d62a17ae | 327 | void ripng_interface_reset(void) |
328 | { | |
f4e14fdb | 329 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 330 | struct interface *ifp; |
331 | struct ripng_interface *ri; | |
a94434b6 | 332 | |
f4e14fdb | 333 | RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { |
d62a17ae | 334 | ri = ifp->info; |
a94434b6 | 335 | |
d62a17ae | 336 | ri->enable_network = 0; |
337 | ri->enable_interface = 0; | |
338 | ri->running = 0; | |
a94434b6 | 339 | |
d62a17ae | 340 | ri->split_horizon = RIPNG_NO_SPLIT_HORIZON; |
341 | ri->split_horizon_default = RIPNG_NO_SPLIT_HORIZON; | |
a94434b6 | 342 | |
d62a17ae | 343 | ri->list[RIPNG_FILTER_IN] = NULL; |
344 | ri->list[RIPNG_FILTER_OUT] = NULL; | |
a94434b6 | 345 | |
d62a17ae | 346 | ri->prefix[RIPNG_FILTER_IN] = NULL; |
347 | ri->prefix[RIPNG_FILTER_OUT] = NULL; | |
a94434b6 | 348 | |
d62a17ae | 349 | if (ri->t_wakeup) { |
350 | thread_cancel(ri->t_wakeup); | |
351 | ri->t_wakeup = NULL; | |
352 | } | |
a94434b6 | 353 | |
d62a17ae | 354 | ri->passive = 0; |
355 | } | |
356 | } | |
a94434b6 | 357 | |
d62a17ae | 358 | static void ripng_apply_address_add(struct connected *ifc) |
359 | { | |
360 | struct prefix_ipv6 address; | |
361 | struct prefix *p; | |
362 | ||
363 | if (!ripng) | |
364 | return; | |
365 | ||
366 | if (!if_is_up(ifc->ifp)) | |
367 | return; | |
368 | ||
369 | p = ifc->address; | |
370 | ||
371 | memset(&address, 0, sizeof(address)); | |
372 | address.family = p->family; | |
373 | address.prefix = p->u.prefix6; | |
374 | address.prefixlen = p->prefixlen; | |
375 | apply_mask_ipv6(&address); | |
376 | ||
377 | /* Check if this interface is RIP enabled or not | |
378 | or Check if this address's prefix is RIP enabled */ | |
379 | if ((ripng_enable_if_lookup(ifc->ifp->name) >= 0) | |
380 | || (ripng_enable_network_lookup2(ifc) >= 0)) | |
381 | ripng_redistribute_add(ZEBRA_ROUTE_CONNECT, | |
382 | RIPNG_ROUTE_INTERFACE, &address, | |
383 | ifc->ifp->ifindex, NULL, 0); | |
a94434b6 | 384 | } |
385 | ||
d62a17ae | 386 | int ripng_interface_address_add(int command, struct zclient *zclient, |
387 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 388 | { |
d62a17ae | 389 | struct connected *c; |
390 | struct prefix *p; | |
718e3744 | 391 | |
d62a17ae | 392 | c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD, |
393 | zclient->ibuf, vrf_id); | |
718e3744 | 394 | |
d62a17ae | 395 | if (c == NULL) |
396 | return 0; | |
718e3744 | 397 | |
d62a17ae | 398 | p = c->address; |
718e3744 | 399 | |
d62a17ae | 400 | if (p->family == AF_INET6) { |
401 | struct ripng_interface *ri = c->ifp->info; | |
a94434b6 | 402 | |
d62a17ae | 403 | if (IS_RIPNG_DEBUG_ZEBRA) |
404 | zlog_debug("RIPng connected address %s/%d add", | |
405 | inet6_ntoa(p->u.prefix6), p->prefixlen); | |
a94434b6 | 406 | |
d62a17ae | 407 | /* Check is this prefix needs to be redistributed. */ |
408 | ripng_apply_address_add(c); | |
a94434b6 | 409 | |
d62a17ae | 410 | /* Let's try once again whether the interface could be activated |
411 | */ | |
412 | if (!ri->running) { | |
413 | /* Check if this interface is RIP enabled or not.*/ | |
414 | ripng_enable_apply(c->ifp); | |
a94434b6 | 415 | |
d62a17ae | 416 | /* Apply distribute list to the interface. */ |
417 | ripng_distribute_update_interface(c->ifp); | |
718e3744 | 418 | |
d62a17ae | 419 | /* Check interface routemap. */ |
420 | ripng_if_rmap_update_interface(c->ifp); | |
421 | } | |
422 | } | |
423 | ||
424 | return 0; | |
718e3744 | 425 | } |
426 | ||
d62a17ae | 427 | static void ripng_apply_address_del(struct connected *ifc) |
428 | { | |
429 | struct prefix_ipv6 address; | |
430 | struct prefix *p; | |
a94434b6 | 431 | |
d62a17ae | 432 | if (!ripng) |
433 | return; | |
a94434b6 | 434 | |
d62a17ae | 435 | if (!if_is_up(ifc->ifp)) |
436 | return; | |
a94434b6 | 437 | |
d62a17ae | 438 | p = ifc->address; |
a94434b6 | 439 | |
d62a17ae | 440 | memset(&address, 0, sizeof(address)); |
441 | address.family = p->family; | |
442 | address.prefix = p->u.prefix6; | |
443 | address.prefixlen = p->prefixlen; | |
444 | apply_mask_ipv6(&address); | |
a94434b6 | 445 | |
d62a17ae | 446 | ripng_redistribute_delete(ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE, |
447 | &address, ifc->ifp->ifindex); | |
a94434b6 | 448 | } |
449 | ||
d62a17ae | 450 | int ripng_interface_address_delete(int command, struct zclient *zclient, |
451 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 452 | { |
d62a17ae | 453 | struct connected *ifc; |
454 | struct prefix *p; | |
455 | char buf[INET6_ADDRSTRLEN]; | |
456 | ||
457 | ifc = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE, | |
458 | zclient->ibuf, vrf_id); | |
459 | ||
460 | if (ifc) { | |
461 | p = ifc->address; | |
462 | ||
463 | if (p->family == AF_INET6) { | |
464 | if (IS_RIPNG_DEBUG_ZEBRA) | |
465 | zlog_debug( | |
466 | "RIPng connected address %s/%d delete", | |
467 | inet_ntop(AF_INET6, &p->u.prefix6, buf, | |
468 | INET6_ADDRSTRLEN), | |
469 | p->prefixlen); | |
470 | ||
471 | /* Check wether this prefix needs to be removed. */ | |
472 | ripng_apply_address_del(ifc); | |
473 | } | |
474 | connected_free(ifc); | |
718e3744 | 475 | } |
718e3744 | 476 | |
d62a17ae | 477 | return 0; |
718e3744 | 478 | } |
6b0655a2 | 479 | |
718e3744 | 480 | /* RIPng enable interface vector. */ |
481 | vector ripng_enable_if; | |
482 | ||
483 | /* RIPng enable network table. */ | |
484 | struct route_table *ripng_enable_network; | |
485 | ||
486 | /* Lookup RIPng enable network. */ | |
a94434b6 | 487 | /* Check wether the interface has at least a connected prefix that |
488 | * is within the ripng_enable_network table. */ | |
d62a17ae | 489 | static int ripng_enable_network_lookup_if(struct interface *ifp) |
718e3744 | 490 | { |
d62a17ae | 491 | struct listnode *node; |
492 | struct connected *connected; | |
493 | struct prefix_ipv6 address; | |
494 | ||
495 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { | |
496 | struct prefix *p; | |
497 | struct route_node *node; | |
498 | ||
499 | p = connected->address; | |
500 | ||
501 | if (p->family == AF_INET6) { | |
502 | address.family = AF_INET6; | |
503 | address.prefix = p->u.prefix6; | |
504 | address.prefixlen = IPV6_MAX_BITLEN; | |
505 | ||
506 | node = route_node_match(ripng_enable_network, | |
507 | (struct prefix *)&address); | |
508 | if (node) { | |
509 | route_unlock_node(node); | |
510 | return 1; | |
511 | } | |
512 | } | |
513 | } | |
514 | return -1; | |
718e3744 | 515 | } |
516 | ||
a94434b6 | 517 | /* Check wether connected is within the ripng_enable_network table. */ |
d62a17ae | 518 | static int ripng_enable_network_lookup2(struct connected *connected) |
a94434b6 | 519 | { |
d62a17ae | 520 | struct prefix_ipv6 address; |
521 | struct prefix *p; | |
a94434b6 | 522 | |
d62a17ae | 523 | p = connected->address; |
a94434b6 | 524 | |
d62a17ae | 525 | if (p->family == AF_INET6) { |
526 | struct route_node *node; | |
a94434b6 | 527 | |
d62a17ae | 528 | address.family = p->family; |
529 | address.prefix = p->u.prefix6; | |
530 | address.prefixlen = IPV6_MAX_BITLEN; | |
a94434b6 | 531 | |
d62a17ae | 532 | /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within |
533 | * ripng_enable_network */ | |
534 | node = route_node_match(ripng_enable_network, | |
535 | (struct prefix *)&address); | |
a94434b6 | 536 | |
d62a17ae | 537 | if (node) { |
538 | route_unlock_node(node); | |
539 | return 1; | |
540 | } | |
541 | } | |
a94434b6 | 542 | |
d62a17ae | 543 | return -1; |
a94434b6 | 544 | } |
545 | ||
718e3744 | 546 | /* Add RIPng enable network. */ |
d62a17ae | 547 | static int ripng_enable_network_add(struct prefix *p) |
718e3744 | 548 | { |
d62a17ae | 549 | struct route_node *node; |
718e3744 | 550 | |
d62a17ae | 551 | node = route_node_get(ripng_enable_network, p); |
718e3744 | 552 | |
d62a17ae | 553 | if (node->info) { |
554 | route_unlock_node(node); | |
555 | return -1; | |
556 | } else | |
557 | node->info = (void *)1; | |
718e3744 | 558 | |
d62a17ae | 559 | /* XXX: One should find a better solution than a generic one */ |
560 | ripng_enable_apply_all(); | |
a94434b6 | 561 | |
d62a17ae | 562 | return 1; |
718e3744 | 563 | } |
564 | ||
565 | /* Delete RIPng enable network. */ | |
d62a17ae | 566 | static int ripng_enable_network_delete(struct prefix *p) |
718e3744 | 567 | { |
d62a17ae | 568 | struct route_node *node; |
718e3744 | 569 | |
d62a17ae | 570 | node = route_node_lookup(ripng_enable_network, p); |
571 | if (node) { | |
572 | node->info = NULL; | |
718e3744 | 573 | |
d62a17ae | 574 | /* Unlock info lock. */ |
575 | route_unlock_node(node); | |
718e3744 | 576 | |
d62a17ae | 577 | /* Unlock lookup lock. */ |
578 | route_unlock_node(node); | |
718e3744 | 579 | |
d62a17ae | 580 | return 1; |
581 | } | |
582 | return -1; | |
718e3744 | 583 | } |
584 | ||
585 | /* Lookup function. */ | |
d62a17ae | 586 | static int ripng_enable_if_lookup(const char *ifname) |
718e3744 | 587 | { |
d62a17ae | 588 | unsigned int i; |
589 | char *str; | |
590 | ||
591 | for (i = 0; i < vector_active(ripng_enable_if); i++) | |
592 | if ((str = vector_slot(ripng_enable_if, i)) != NULL) | |
593 | if (strcmp(str, ifname) == 0) | |
594 | return i; | |
595 | return -1; | |
718e3744 | 596 | } |
597 | ||
598 | /* Add interface to ripng_enable_if. */ | |
d62a17ae | 599 | static int ripng_enable_if_add(const char *ifname) |
718e3744 | 600 | { |
d62a17ae | 601 | int ret; |
718e3744 | 602 | |
d62a17ae | 603 | ret = ripng_enable_if_lookup(ifname); |
604 | if (ret >= 0) | |
605 | return -1; | |
718e3744 | 606 | |
d62a17ae | 607 | vector_set(ripng_enable_if, strdup(ifname)); |
718e3744 | 608 | |
d62a17ae | 609 | ripng_enable_apply_all(); |
a94434b6 | 610 | |
d62a17ae | 611 | return 1; |
718e3744 | 612 | } |
613 | ||
614 | /* Delete interface from ripng_enable_if. */ | |
d62a17ae | 615 | static int ripng_enable_if_delete(const char *ifname) |
718e3744 | 616 | { |
d62a17ae | 617 | int index; |
618 | char *str; | |
718e3744 | 619 | |
d62a17ae | 620 | index = ripng_enable_if_lookup(ifname); |
621 | if (index < 0) | |
622 | return -1; | |
718e3744 | 623 | |
d62a17ae | 624 | str = vector_slot(ripng_enable_if, index); |
625 | free(str); | |
626 | vector_unset(ripng_enable_if, index); | |
718e3744 | 627 | |
d62a17ae | 628 | ripng_enable_apply_all(); |
a94434b6 | 629 | |
d62a17ae | 630 | return 1; |
718e3744 | 631 | } |
632 | ||
633 | /* Wake up interface. */ | |
d62a17ae | 634 | static int ripng_interface_wakeup(struct thread *t) |
718e3744 | 635 | { |
d62a17ae | 636 | struct interface *ifp; |
637 | struct ripng_interface *ri; | |
718e3744 | 638 | |
d62a17ae | 639 | /* Get interface. */ |
640 | ifp = THREAD_ARG(t); | |
718e3744 | 641 | |
d62a17ae | 642 | ri = ifp->info; |
643 | ri->t_wakeup = NULL; | |
718e3744 | 644 | |
d62a17ae | 645 | /* Join to multicast group. */ |
646 | if (ripng_multicast_join(ifp) < 0) { | |
647 | zlog_err("multicast join failed, interface %s not running", | |
648 | ifp->name); | |
649 | return 0; | |
650 | } | |
651 | ||
652 | /* Set running flag. */ | |
653 | ri->running = 1; | |
718e3744 | 654 | |
d62a17ae | 655 | /* Send RIP request to the interface. */ |
656 | ripng_request(ifp); | |
718e3744 | 657 | |
d62a17ae | 658 | return 0; |
718e3744 | 659 | } |
660 | ||
d62a17ae | 661 | static void ripng_connect_set(struct interface *ifp, int set) |
a94434b6 | 662 | { |
d62a17ae | 663 | struct listnode *node, *nnode; |
664 | struct connected *connected; | |
665 | struct prefix_ipv6 address; | |
666 | ||
667 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) { | |
668 | struct prefix *p; | |
669 | p = connected->address; | |
670 | ||
671 | if (p->family != AF_INET6) | |
672 | continue; | |
673 | ||
674 | address.family = AF_INET6; | |
675 | address.prefix = p->u.prefix6; | |
676 | address.prefixlen = p->prefixlen; | |
677 | apply_mask_ipv6(&address); | |
678 | ||
679 | if (set) { | |
680 | /* Check once more wether this prefix is within a | |
681 | * "network IF_OR_PREF" one */ | |
682 | if ((ripng_enable_if_lookup(connected->ifp->name) >= 0) | |
683 | || (ripng_enable_network_lookup2(connected) >= 0)) | |
684 | ripng_redistribute_add( | |
685 | ZEBRA_ROUTE_CONNECT, | |
686 | RIPNG_ROUTE_INTERFACE, &address, | |
687 | connected->ifp->ifindex, NULL, 0); | |
688 | } else { | |
689 | ripng_redistribute_delete( | |
690 | ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE, | |
691 | &address, connected->ifp->ifindex); | |
692 | if (ripng_redistribute_check(ZEBRA_ROUTE_CONNECT)) | |
693 | ripng_redistribute_add( | |
694 | ZEBRA_ROUTE_CONNECT, | |
695 | RIPNG_ROUTE_REDISTRIBUTE, &address, | |
696 | connected->ifp->ifindex, NULL, 0); | |
697 | } | |
698 | } | |
a94434b6 | 699 | } |
700 | ||
718e3744 | 701 | /* Check RIPng is enabed on this interface. */ |
d62a17ae | 702 | void ripng_enable_apply(struct interface *ifp) |
718e3744 | 703 | { |
d62a17ae | 704 | int ret; |
705 | struct ripng_interface *ri = NULL; | |
706 | ||
707 | /* Check interface. */ | |
708 | if (!if_is_up(ifp)) | |
709 | return; | |
710 | ||
711 | ri = ifp->info; | |
712 | ||
713 | /* Is this interface a candidate for RIPng ? */ | |
714 | ret = ripng_enable_network_lookup_if(ifp); | |
715 | ||
716 | /* If the interface is matched. */ | |
717 | if (ret > 0) | |
718 | ri->enable_network = 1; | |
719 | else | |
720 | ri->enable_network = 0; | |
721 | ||
722 | /* Check interface name configuration. */ | |
723 | ret = ripng_enable_if_lookup(ifp->name); | |
724 | if (ret >= 0) | |
725 | ri->enable_interface = 1; | |
726 | else | |
727 | ri->enable_interface = 0; | |
728 | ||
729 | /* any candidate interface MUST have a link-local IPv6 address */ | |
730 | if ((!ripng_if_ipv6_lladdress_check(ifp)) | |
731 | && (ri->enable_network || ri->enable_interface)) { | |
732 | ri->enable_network = 0; | |
733 | ri->enable_interface = 0; | |
734 | zlog_warn("Interface %s does not have any link-local address", | |
735 | ifp->name); | |
736 | } | |
737 | ||
738 | /* Update running status of the interface. */ | |
739 | if (ri->enable_network || ri->enable_interface) { | |
740 | zlog_info("RIPng INTERFACE ON %s", ifp->name); | |
741 | ||
742 | /* Add interface wake up thread. */ | |
743 | thread_add_timer(master, ripng_interface_wakeup, ifp, 1, | |
744 | &ri->t_wakeup); | |
745 | ||
746 | ripng_connect_set(ifp, 1); | |
747 | } else { | |
748 | if (ri->running) { | |
749 | /* Might as well clean up the route table as well | |
750 | * ripng_if_down sets to 0 ri->running, and displays | |
751 | *"turn off %s" | |
752 | **/ | |
753 | ripng_if_down(ifp); | |
754 | ||
755 | ripng_connect_set(ifp, 0); | |
756 | } | |
718e3744 | 757 | } |
718e3744 | 758 | } |
759 | ||
760 | /* Set distribute list to all interfaces. */ | |
d62a17ae | 761 | static void ripng_enable_apply_all(void) |
718e3744 | 762 | { |
f4e14fdb | 763 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 764 | struct interface *ifp; |
718e3744 | 765 | |
f4e14fdb | 766 | RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) |
d62a17ae | 767 | ripng_enable_apply(ifp); |
718e3744 | 768 | } |
6b0655a2 | 769 | |
a94434b6 | 770 | /* Clear all network and neighbor configuration */ |
d62a17ae | 771 | void ripng_clean_network() |
a94434b6 | 772 | { |
d62a17ae | 773 | unsigned int i; |
774 | char *str; | |
775 | struct route_node *rn; | |
776 | ||
777 | /* ripng_enable_network */ | |
778 | for (rn = route_top(ripng_enable_network); rn; rn = route_next(rn)) | |
779 | if (rn->info) { | |
780 | rn->info = NULL; | |
781 | route_unlock_node(rn); | |
782 | } | |
783 | ||
784 | /* ripng_enable_if */ | |
785 | for (i = 0; i < vector_active(ripng_enable_if); i++) | |
786 | if ((str = vector_slot(ripng_enable_if, i)) != NULL) { | |
787 | free(str); | |
788 | vector_slot(ripng_enable_if, i) = NULL; | |
789 | } | |
a94434b6 | 790 | } |
6b0655a2 | 791 | |
718e3744 | 792 | /* Vector to store passive-interface name. */ |
793 | vector Vripng_passive_interface; | |
794 | ||
795 | /* Utility function for looking up passive interface settings. */ | |
d62a17ae | 796 | static int ripng_passive_interface_lookup(const char *ifname) |
718e3744 | 797 | { |
d62a17ae | 798 | unsigned int i; |
799 | char *str; | |
800 | ||
801 | for (i = 0; i < vector_active(Vripng_passive_interface); i++) | |
802 | if ((str = vector_slot(Vripng_passive_interface, i)) != NULL) | |
803 | if (strcmp(str, ifname) == 0) | |
804 | return i; | |
805 | return -1; | |
718e3744 | 806 | } |
807 | ||
d62a17ae | 808 | void ripng_passive_interface_apply(struct interface *ifp) |
718e3744 | 809 | { |
d62a17ae | 810 | int ret; |
811 | struct ripng_interface *ri; | |
718e3744 | 812 | |
d62a17ae | 813 | ri = ifp->info; |
718e3744 | 814 | |
d62a17ae | 815 | ret = ripng_passive_interface_lookup(ifp->name); |
816 | if (ret < 0) | |
817 | ri->passive = 0; | |
818 | else | |
819 | ri->passive = 1; | |
718e3744 | 820 | } |
821 | ||
d62a17ae | 822 | static void ripng_passive_interface_apply_all(void) |
718e3744 | 823 | { |
f4e14fdb | 824 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 825 | struct interface *ifp; |
718e3744 | 826 | |
f4e14fdb | 827 | RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) |
d62a17ae | 828 | ripng_passive_interface_apply(ifp); |
718e3744 | 829 | } |
830 | ||
831 | /* Passive interface. */ | |
d62a17ae | 832 | static int ripng_passive_interface_set(struct vty *vty, const char *ifname) |
718e3744 | 833 | { |
d62a17ae | 834 | if (ripng_passive_interface_lookup(ifname) >= 0) |
835 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 836 | |
d62a17ae | 837 | vector_set(Vripng_passive_interface, strdup(ifname)); |
718e3744 | 838 | |
d62a17ae | 839 | ripng_passive_interface_apply_all(); |
718e3744 | 840 | |
d62a17ae | 841 | return CMD_SUCCESS; |
718e3744 | 842 | } |
843 | ||
d62a17ae | 844 | static int ripng_passive_interface_unset(struct vty *vty, const char *ifname) |
718e3744 | 845 | { |
d62a17ae | 846 | int i; |
847 | char *str; | |
718e3744 | 848 | |
d62a17ae | 849 | i = ripng_passive_interface_lookup(ifname); |
850 | if (i < 0) | |
851 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 852 | |
d62a17ae | 853 | str = vector_slot(Vripng_passive_interface, i); |
854 | free(str); | |
855 | vector_unset(Vripng_passive_interface, i); | |
718e3744 | 856 | |
d62a17ae | 857 | ripng_passive_interface_apply_all(); |
718e3744 | 858 | |
d62a17ae | 859 | return CMD_SUCCESS; |
718e3744 | 860 | } |
861 | ||
862 | /* Free all configured RIP passive-interface settings. */ | |
d62a17ae | 863 | void ripng_passive_interface_clean(void) |
718e3744 | 864 | { |
d62a17ae | 865 | unsigned int i; |
866 | char *str; | |
867 | ||
868 | for (i = 0; i < vector_active(Vripng_passive_interface); i++) | |
869 | if ((str = vector_slot(Vripng_passive_interface, i)) != NULL) { | |
870 | free(str); | |
871 | vector_slot(Vripng_passive_interface, i) = NULL; | |
872 | } | |
873 | ripng_passive_interface_apply_all(); | |
718e3744 | 874 | } |
875 | ||
876 | /* Write RIPng enable network and interface to the vty. */ | |
d62a17ae | 877 | int ripng_network_write(struct vty *vty, int config_mode) |
718e3744 | 878 | { |
d62a17ae | 879 | unsigned int i; |
880 | const char *ifname; | |
881 | struct route_node *node; | |
882 | char buf[BUFSIZ]; | |
883 | ||
884 | /* Write enable network. */ | |
885 | for (node = route_top(ripng_enable_network); node; | |
886 | node = route_next(node)) | |
887 | if (node->info) { | |
888 | struct prefix *p = &node->p; | |
889 | vty_out(vty, "%s%s/%d\n", | |
890 | config_mode ? " network " : " ", | |
891 | inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), | |
892 | p->prefixlen); | |
893 | } | |
894 | ||
895 | /* Write enable interface. */ | |
896 | for (i = 0; i < vector_active(ripng_enable_if); i++) | |
897 | if ((ifname = vector_slot(ripng_enable_if, i)) != NULL) | |
898 | vty_out(vty, "%s%s\n", | |
899 | config_mode ? " network " : " ", ifname); | |
900 | ||
901 | /* Write passive interface. */ | |
902 | if (config_mode) | |
903 | for (i = 0; i < vector_active(Vripng_passive_interface); i++) | |
904 | if ((ifname = vector_slot(Vripng_passive_interface, i)) | |
905 | != NULL) | |
906 | vty_out(vty, " passive-interface %s\n", ifname); | |
907 | ||
908 | return 0; | |
718e3744 | 909 | } |
910 | ||
911 | /* RIPng enable on specified interface or matched network. */ | |
912 | DEFUN (ripng_network, | |
913 | ripng_network_cmd, | |
914 | "network IF_OR_ADDR", | |
915 | "RIPng enable on specified interface or network.\n" | |
d911a12a | 916 | "Interface or address\n") |
718e3744 | 917 | { |
d62a17ae | 918 | int idx_if_or_addr = 1; |
919 | int ret; | |
920 | struct prefix p; | |
921 | ||
922 | ret = str2prefix(argv[idx_if_or_addr]->arg, &p); | |
923 | ||
924 | /* Given string is IPv6 network or interface name. */ | |
925 | if (ret) | |
926 | ret = ripng_enable_network_add(&p); | |
927 | else | |
928 | ret = ripng_enable_if_add(argv[idx_if_or_addr]->arg); | |
929 | ||
930 | if (ret < 0) { | |
931 | vty_out(vty, "There is same network configuration %s\n", | |
932 | argv[idx_if_or_addr]->arg); | |
933 | return CMD_WARNING_CONFIG_FAILED; | |
934 | } | |
935 | ||
936 | return CMD_SUCCESS; | |
718e3744 | 937 | } |
938 | ||
939 | /* RIPng enable on specified interface or matched network. */ | |
940 | DEFUN (no_ripng_network, | |
941 | no_ripng_network_cmd, | |
942 | "no network IF_OR_ADDR", | |
943 | NO_STR | |
944 | "RIPng enable on specified interface or network.\n" | |
d911a12a | 945 | "Interface or address\n") |
718e3744 | 946 | { |
d62a17ae | 947 | int idx_if_or_addr = 2; |
948 | int ret; | |
949 | struct prefix p; | |
950 | ||
951 | ret = str2prefix(argv[idx_if_or_addr]->arg, &p); | |
952 | ||
953 | /* Given string is interface name. */ | |
954 | if (ret) | |
955 | ret = ripng_enable_network_delete(&p); | |
956 | else | |
957 | ret = ripng_enable_if_delete(argv[idx_if_or_addr]->arg); | |
958 | ||
959 | if (ret < 0) { | |
960 | vty_out(vty, "can't find network %s\n", | |
961 | argv[idx_if_or_addr]->arg); | |
962 | return CMD_WARNING_CONFIG_FAILED; | |
963 | } | |
964 | ||
965 | return CMD_SUCCESS; | |
a94434b6 | 966 | } |
967 | ||
968 | DEFUN (ipv6_ripng_split_horizon, | |
969 | ipv6_ripng_split_horizon_cmd, | |
970 | "ipv6 ripng split-horizon", | |
971 | IPV6_STR | |
972 | "Routing Information Protocol\n" | |
973 | "Perform split horizon\n") | |
974 | { | |
d62a17ae | 975 | VTY_DECLVAR_CONTEXT(interface, ifp); |
976 | struct ripng_interface *ri; | |
a94434b6 | 977 | |
d62a17ae | 978 | ri = ifp->info; |
a94434b6 | 979 | |
d62a17ae | 980 | ri->split_horizon = RIPNG_SPLIT_HORIZON; |
981 | return CMD_SUCCESS; | |
a94434b6 | 982 | } |
983 | ||
984 | DEFUN (ipv6_ripng_split_horizon_poisoned_reverse, | |
985 | ipv6_ripng_split_horizon_poisoned_reverse_cmd, | |
986 | "ipv6 ripng split-horizon poisoned-reverse", | |
987 | IPV6_STR | |
988 | "Routing Information Protocol\n" | |
989 | "Perform split horizon\n" | |
990 | "With poisoned-reverse\n") | |
991 | { | |
d62a17ae | 992 | VTY_DECLVAR_CONTEXT(interface, ifp); |
993 | struct ripng_interface *ri; | |
a94434b6 | 994 | |
d62a17ae | 995 | ri = ifp->info; |
a94434b6 | 996 | |
d62a17ae | 997 | ri->split_horizon = RIPNG_SPLIT_HORIZON_POISONED_REVERSE; |
998 | return CMD_SUCCESS; | |
a94434b6 | 999 | } |
718e3744 | 1000 | |
a94434b6 | 1001 | DEFUN (no_ipv6_ripng_split_horizon, |
1002 | no_ipv6_ripng_split_horizon_cmd, | |
481af2ed | 1003 | "no ipv6 ripng split-horizon [poisoned-reverse]", |
a94434b6 | 1004 | NO_STR |
1005 | IPV6_STR | |
1006 | "Routing Information Protocol\n" | |
481af2ed QY |
1007 | "Perform split horizon\n" |
1008 | "With poisoned-reverse\n") | |
a94434b6 | 1009 | { |
d62a17ae | 1010 | VTY_DECLVAR_CONTEXT(interface, ifp); |
1011 | struct ripng_interface *ri; | |
a94434b6 | 1012 | |
d62a17ae | 1013 | ri = ifp->info; |
a94434b6 | 1014 | |
d62a17ae | 1015 | ri->split_horizon = RIPNG_NO_SPLIT_HORIZON; |
1016 | return CMD_SUCCESS; | |
718e3744 | 1017 | } |
1018 | ||
1019 | DEFUN (ripng_passive_interface, | |
1020 | ripng_passive_interface_cmd, | |
1021 | "passive-interface IFNAME", | |
1022 | "Suppress routing updates on an interface\n" | |
1023 | "Interface name\n") | |
1024 | { | |
d62a17ae | 1025 | int idx_ifname = 1; |
1026 | return ripng_passive_interface_set(vty, argv[idx_ifname]->arg); | |
718e3744 | 1027 | } |
1028 | ||
1029 | DEFUN (no_ripng_passive_interface, | |
1030 | no_ripng_passive_interface_cmd, | |
1031 | "no passive-interface IFNAME", | |
1032 | NO_STR | |
1033 | "Suppress routing updates on an interface\n" | |
1034 | "Interface name\n") | |
1035 | { | |
d62a17ae | 1036 | int idx_ifname = 2; |
1037 | return ripng_passive_interface_unset(vty, argv[idx_ifname]->arg); | |
718e3744 | 1038 | } |
6b0655a2 | 1039 | |
d62a17ae | 1040 | static struct ripng_interface *ri_new(void) |
718e3744 | 1041 | { |
d62a17ae | 1042 | struct ripng_interface *ri; |
1043 | ri = XCALLOC(MTYPE_IF, sizeof(struct ripng_interface)); | |
a94434b6 | 1044 | |
d62a17ae | 1045 | /* Set default split-horizon behavior. If the interface is Frame |
1046 | Relay or SMDS is enabled, the default value for split-horizon is | |
1047 | off. But currently Zebra does detect Frame Relay or SMDS | |
1048 | interface. So all interface is set to split horizon. */ | |
1049 | ri->split_horizon_default = RIPNG_SPLIT_HORIZON; | |
1050 | ri->split_horizon = ri->split_horizon_default; | |
a94434b6 | 1051 | |
d62a17ae | 1052 | return ri; |
718e3744 | 1053 | } |
1054 | ||
d62a17ae | 1055 | static int ripng_if_new_hook(struct interface *ifp) |
718e3744 | 1056 | { |
d62a17ae | 1057 | ifp->info = ri_new(); |
1058 | return 0; | |
718e3744 | 1059 | } |
1060 | ||
a94434b6 | 1061 | /* Called when interface structure deleted. */ |
d62a17ae | 1062 | static int ripng_if_delete_hook(struct interface *ifp) |
a94434b6 | 1063 | { |
d62a17ae | 1064 | XFREE(MTYPE_IF, ifp->info); |
1065 | ifp->info = NULL; | |
1066 | return 0; | |
a94434b6 | 1067 | } |
1068 | ||
718e3744 | 1069 | /* Configuration write function for ripngd. */ |
d62a17ae | 1070 | static int interface_config_write(struct vty *vty) |
718e3744 | 1071 | { |
f4e14fdb | 1072 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 1073 | struct interface *ifp; |
1074 | struct ripng_interface *ri; | |
1075 | int write = 0; | |
1076 | ||
f4e14fdb | 1077 | RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { |
d62a17ae | 1078 | ri = ifp->info; |
1079 | ||
1080 | /* Do not display the interface if there is no | |
1081 | * configuration about it. | |
1082 | **/ | |
1083 | if ((!ifp->desc) | |
1084 | && (ri->split_horizon == ri->split_horizon_default)) | |
1085 | continue; | |
1086 | ||
a8b828f3 | 1087 | vty_frame(vty, "interface %s\n", ifp->name); |
d62a17ae | 1088 | if (ifp->desc) |
1089 | vty_out(vty, " description %s\n", ifp->desc); | |
1090 | ||
1091 | /* Split horizon. */ | |
1092 | if (ri->split_horizon != ri->split_horizon_default) { | |
1093 | switch (ri->split_horizon) { | |
1094 | case RIPNG_SPLIT_HORIZON: | |
1095 | vty_out(vty, " ipv6 ripng split-horizon\n"); | |
1096 | break; | |
1097 | case RIPNG_SPLIT_HORIZON_POISONED_REVERSE: | |
1098 | vty_out(vty, | |
1099 | " ipv6 ripng split-horizon poisoned-reverse\n"); | |
1100 | break; | |
1101 | case RIPNG_NO_SPLIT_HORIZON: | |
1102 | default: | |
1103 | vty_out(vty, " no ipv6 ripng split-horizon\n"); | |
1104 | break; | |
1105 | } | |
1106 | } | |
1107 | ||
a8b828f3 | 1108 | vty_endframe(vty, "!\n"); |
d62a17ae | 1109 | |
1110 | write++; | |
a94434b6 | 1111 | } |
d62a17ae | 1112 | return write; |
718e3744 | 1113 | } |
1114 | ||
1115 | /* ripngd's interface node. */ | |
d62a17ae | 1116 | static struct cmd_node interface_node = { |
1117 | INTERFACE_NODE, "%s(config-if)# ", 1 /* VTYSH */ | |
718e3744 | 1118 | }; |
1119 | ||
1120 | /* Initialization of interface. */ | |
d62a17ae | 1121 | void ripng_if_init() |
718e3744 | 1122 | { |
d62a17ae | 1123 | /* Interface initialize. */ |
ce19a04a DL |
1124 | hook_register_prio(if_add, 0, ripng_if_new_hook); |
1125 | hook_register_prio(if_del, 0, ripng_if_delete_hook); | |
718e3744 | 1126 | |
d62a17ae | 1127 | /* RIPng enable network init. */ |
1128 | ripng_enable_network = route_table_init(); | |
718e3744 | 1129 | |
d62a17ae | 1130 | /* RIPng enable interface init. */ |
1131 | ripng_enable_if = vector_init(1); | |
718e3744 | 1132 | |
d62a17ae | 1133 | /* RIPng passive interface. */ |
1134 | Vripng_passive_interface = vector_init(1); | |
718e3744 | 1135 | |
d62a17ae | 1136 | /* Install interface node. */ |
1137 | install_node(&interface_node, interface_config_write); | |
1138 | if_cmd_init(); | |
718e3744 | 1139 | |
d62a17ae | 1140 | install_element(RIPNG_NODE, &ripng_network_cmd); |
1141 | install_element(RIPNG_NODE, &no_ripng_network_cmd); | |
1142 | install_element(RIPNG_NODE, &ripng_passive_interface_cmd); | |
1143 | install_element(RIPNG_NODE, &no_ripng_passive_interface_cmd); | |
a94434b6 | 1144 | |
d62a17ae | 1145 | install_element(INTERFACE_NODE, &ipv6_ripng_split_horizon_cmd); |
1146 | install_element(INTERFACE_NODE, | |
1147 | &ipv6_ripng_split_horizon_poisoned_reverse_cmd); | |
1148 | install_element(INTERFACE_NODE, &no_ipv6_ripng_split_horizon_cmd); | |
718e3744 | 1149 | } |