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