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