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); */ |
| 334 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 335 | return 0; |
| 336 | } |
| 337 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 338 | void |
| 339 | ripng_interface_clean () |
| 340 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 341 | struct listnode *node; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 342 | struct interface *ifp; |
| 343 | struct ripng_interface *ri; |
| 344 | |
| 345 | for (node = listhead (iflist); node; nextnode (node)) |
| 346 | { |
| 347 | ifp = getdata (node); |
| 348 | ri = ifp->info; |
| 349 | |
| 350 | ri->enable_network = 0; |
| 351 | ri->enable_interface = 0; |
| 352 | ri->running = 0; |
| 353 | |
| 354 | if (ri->t_wakeup) |
| 355 | { |
| 356 | thread_cancel (ri->t_wakeup); |
| 357 | ri->t_wakeup = NULL; |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | void |
| 363 | ripng_interface_reset () { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 364 | struct listnode *node; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 365 | struct interface *ifp; |
| 366 | struct ripng_interface *ri; |
| 367 | |
| 368 | for (node = listhead (iflist); node; nextnode (node)) |
| 369 | { |
| 370 | ifp = getdata (node); |
| 371 | ri = ifp->info; |
| 372 | |
| 373 | ri->enable_network = 0; |
| 374 | ri->enable_interface = 0; |
| 375 | ri->running = 0; |
| 376 | |
| 377 | ri->split_horizon = RIPNG_NO_SPLIT_HORIZON; |
| 378 | ri->split_horizon_default = RIPNG_NO_SPLIT_HORIZON; |
| 379 | |
| 380 | ri->list[RIPNG_FILTER_IN] = NULL; |
| 381 | ri->list[RIPNG_FILTER_OUT] = NULL; |
| 382 | |
| 383 | ri->prefix[RIPNG_FILTER_IN] = NULL; |
| 384 | ri->prefix[RIPNG_FILTER_OUT] = NULL; |
| 385 | |
| 386 | if (ri->t_wakeup) |
| 387 | { |
| 388 | thread_cancel (ri->t_wakeup); |
| 389 | ri->t_wakeup = NULL; |
| 390 | } |
| 391 | |
| 392 | ri->passive = 0; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | static void |
| 397 | ripng_apply_address_add (struct connected *ifc) { |
| 398 | struct prefix_ipv6 address; |
| 399 | struct prefix *p; |
| 400 | |
| 401 | if (!ripng) |
| 402 | return; |
| 403 | |
| 404 | if (! if_is_up(ifc->ifp)) |
| 405 | return; |
| 406 | |
| 407 | p = ifc->address; |
| 408 | |
| 409 | memset (&address, 0, sizeof (address)); |
| 410 | address.family = p->family; |
| 411 | address.prefix = p->u.prefix6; |
| 412 | address.prefixlen = p->prefixlen; |
| 413 | apply_mask_ipv6(&address); |
| 414 | |
| 415 | /* Check if this interface is RIP enabled or not |
| 416 | or Check if this address's prefix is RIP enabled */ |
| 417 | if ((ripng_enable_if_lookup(ifc->ifp->name) >= 0) || |
| 418 | (ripng_enable_network_lookup2(ifc) >= 0)) |
| 419 | ripng_redistribute_add(ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE, |
| 420 | &address, ifc->ifp->ifindex, NULL); |
| 421 | |
| 422 | } |
| 423 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 424 | int |
| 425 | ripng_interface_address_add (int command, struct zclient *zclient, |
| 426 | zebra_size_t length) |
| 427 | { |
| 428 | struct connected *c; |
| 429 | struct prefix *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 431 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, |
| 432 | zclient->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 433 | |
| 434 | if (c == NULL) |
| 435 | return 0; |
| 436 | |
| 437 | p = c->address; |
| 438 | |
| 439 | if (p->family == AF_INET6) |
| 440 | { |
| 441 | if (IS_RIPNG_DEBUG_ZEBRA) |
ajs | 2e23ab2 | 2004-12-08 19:46:50 +0000 | [diff] [blame] | 442 | zlog_debug ("RIPng connected address %s/%d add", |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 443 | inet6_ntop(&p->u.prefix6), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 444 | p->prefixlen); |
| 445 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 446 | /* Check is this prefix needs to be redistributed. */ |
| 447 | ripng_apply_address_add(c); |
| 448 | |
| 449 | /* Let's try once again whether the interface could be activated */ |
| 450 | if (c->ifp) { |
| 451 | struct ripng_interface *ri = c->ifp->info; |
| 452 | |
| 453 | if (!ri->running) { |
| 454 | /* Check if this interface is RIP enabled or not.*/ |
| 455 | ripng_enable_apply (c->ifp); |
| 456 | |
| 457 | /* Apply distribute list to the interface. */ |
| 458 | ripng_distribute_update_interface (c->ifp); |
| 459 | |
| 460 | /* Check interface routemap. */ |
| 461 | ripng_if_rmap_update_interface (c->ifp); |
| 462 | } |
| 463 | } |
| 464 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 470 | static void |
| 471 | ripng_apply_address_del (struct connected *ifc) { |
| 472 | struct prefix_ipv6 address; |
| 473 | struct prefix *p; |
| 474 | |
| 475 | if (!ripng) |
| 476 | return; |
| 477 | |
| 478 | if (! if_is_up(ifc->ifp)) |
| 479 | return; |
| 480 | |
| 481 | p = ifc->address; |
| 482 | |
| 483 | memset (&address, 0, sizeof (address)); |
| 484 | address.family = p->family; |
| 485 | address.prefix = p->u.prefix6; |
| 486 | address.prefixlen = p->prefixlen; |
| 487 | apply_mask_ipv6(&address); |
| 488 | |
| 489 | ripng_redistribute_delete(ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE, |
| 490 | &address, ifc->ifp->ifindex); |
| 491 | } |
| 492 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 493 | int |
| 494 | ripng_interface_address_delete (int command, struct zclient *zclient, |
| 495 | zebra_size_t length) |
| 496 | { |
| 497 | struct connected *ifc; |
| 498 | struct prefix *p; |
| 499 | char buf[INET6_ADDRSTRLEN]; |
| 500 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 501 | ifc = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, |
| 502 | zclient->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 503 | |
| 504 | if (ifc) |
| 505 | { |
| 506 | p = ifc->address; |
| 507 | |
| 508 | if (p->family == AF_INET6) |
| 509 | { |
| 510 | if (IS_RIPNG_DEBUG_ZEBRA) |
ajs | 2e23ab2 | 2004-12-08 19:46:50 +0000 | [diff] [blame] | 511 | zlog_debug ("RIPng connected address %s/%d delete", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 512 | inet_ntop (AF_INET6, &p->u.prefix6, buf, |
| 513 | INET6_ADDRSTRLEN), |
| 514 | p->prefixlen); |
| 515 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 516 | /* Check wether this prefix needs to be removed. */ |
| 517 | ripng_apply_address_del(ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 518 | } |
| 519 | connected_free (ifc); |
| 520 | } |
| 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | /* RIPng enable interface vector. */ |
| 526 | vector ripng_enable_if; |
| 527 | |
| 528 | /* RIPng enable network table. */ |
| 529 | struct route_table *ripng_enable_network; |
| 530 | |
| 531 | /* Lookup RIPng enable network. */ |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 532 | /* Check wether the interface has at least a connected prefix that |
| 533 | * is within the ripng_enable_network table. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 534 | int |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 535 | ripng_enable_network_lookup_if (struct interface *ifp) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 536 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 537 | struct listnode *listnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | struct connected *connected; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 539 | struct prefix_ipv6 address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 540 | |
| 541 | for (listnode = listhead (ifp->connected); listnode; nextnode (listnode)) |
| 542 | if ((connected = getdata (listnode)) != NULL) |
| 543 | { |
| 544 | struct prefix *p; |
| 545 | struct route_node *node; |
| 546 | |
| 547 | p = connected->address; |
| 548 | |
| 549 | if (p->family == AF_INET6) |
| 550 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 551 | address.family = AF_INET6; |
| 552 | address.prefix = p->u.prefix6; |
| 553 | address.prefixlen = IPV6_MAX_BITLEN; |
| 554 | |
| 555 | node = route_node_match (ripng_enable_network, |
| 556 | (struct prefix *)&address); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 557 | if (node) |
| 558 | { |
| 559 | route_unlock_node (node); |
| 560 | return 1; |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | return -1; |
| 565 | } |
| 566 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 567 | /* Check wether connected is within the ripng_enable_network table. */ |
| 568 | int |
| 569 | ripng_enable_network_lookup2 (struct connected *connected) |
| 570 | { |
| 571 | struct prefix_ipv6 address; |
| 572 | struct prefix *p; |
| 573 | |
| 574 | p = connected->address; |
| 575 | |
| 576 | if (p->family == AF_INET6) { |
| 577 | struct route_node *node; |
| 578 | |
| 579 | address.family = p->family; |
| 580 | address.prefix = p->u.prefix6; |
| 581 | address.prefixlen = IPV6_MAX_BITLEN; |
| 582 | |
| 583 | /* LPM on p->family, p->u.prefix6/IPV6_MAX_BITLEN within ripng_enable_network */ |
| 584 | node = route_node_match (ripng_enable_network, |
| 585 | (struct prefix *)&address); |
| 586 | |
| 587 | if (node) { |
| 588 | route_unlock_node (node); |
| 589 | return 1; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | return -1; |
| 594 | } |
| 595 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 596 | /* Add RIPng enable network. */ |
| 597 | int |
| 598 | ripng_enable_network_add (struct prefix *p) |
| 599 | { |
| 600 | struct route_node *node; |
| 601 | |
| 602 | node = route_node_get (ripng_enable_network, p); |
| 603 | |
| 604 | if (node->info) |
| 605 | { |
| 606 | route_unlock_node (node); |
| 607 | return -1; |
| 608 | } |
| 609 | else |
hasso | 7a1d583 | 2004-10-08 06:32:23 +0000 | [diff] [blame] | 610 | node->info = (char *) "enabled"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 611 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 612 | /* XXX: One should find a better solution than a generic one */ |
| 613 | ripng_enable_apply_all(); |
| 614 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 615 | return 1; |
| 616 | } |
| 617 | |
| 618 | /* Delete RIPng enable network. */ |
| 619 | int |
| 620 | ripng_enable_network_delete (struct prefix *p) |
| 621 | { |
| 622 | struct route_node *node; |
| 623 | |
| 624 | node = route_node_lookup (ripng_enable_network, p); |
| 625 | if (node) |
| 626 | { |
| 627 | node->info = NULL; |
| 628 | |
| 629 | /* Unlock info lock. */ |
| 630 | route_unlock_node (node); |
| 631 | |
| 632 | /* Unlock lookup lock. */ |
| 633 | route_unlock_node (node); |
| 634 | |
| 635 | return 1; |
| 636 | } |
| 637 | return -1; |
| 638 | } |
| 639 | |
| 640 | /* Lookup function. */ |
| 641 | int |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 642 | ripng_enable_if_lookup (const char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 643 | { |
hasso | 7a1d583 | 2004-10-08 06:32:23 +0000 | [diff] [blame] | 644 | unsigned int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 645 | char *str; |
| 646 | |
| 647 | for (i = 0; i < vector_max (ripng_enable_if); i++) |
| 648 | if ((str = vector_slot (ripng_enable_if, i)) != NULL) |
| 649 | if (strcmp (str, ifname) == 0) |
| 650 | return i; |
| 651 | return -1; |
| 652 | } |
| 653 | |
| 654 | /* Add interface to ripng_enable_if. */ |
| 655 | int |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 656 | ripng_enable_if_add (const char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 657 | { |
| 658 | int ret; |
| 659 | |
| 660 | ret = ripng_enable_if_lookup (ifname); |
| 661 | if (ret >= 0) |
| 662 | return -1; |
| 663 | |
| 664 | vector_set (ripng_enable_if, strdup (ifname)); |
| 665 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 666 | ripng_enable_apply_all(); |
| 667 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 668 | return 1; |
| 669 | } |
| 670 | |
| 671 | /* Delete interface from ripng_enable_if. */ |
| 672 | int |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 673 | ripng_enable_if_delete (const char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 674 | { |
| 675 | int index; |
| 676 | char *str; |
| 677 | |
| 678 | index = ripng_enable_if_lookup (ifname); |
| 679 | if (index < 0) |
| 680 | return -1; |
| 681 | |
| 682 | str = vector_slot (ripng_enable_if, index); |
| 683 | free (str); |
| 684 | vector_unset (ripng_enable_if, index); |
| 685 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 686 | ripng_enable_apply_all(); |
| 687 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 688 | return 1; |
| 689 | } |
| 690 | |
| 691 | /* Wake up interface. */ |
| 692 | int |
| 693 | ripng_interface_wakeup (struct thread *t) |
| 694 | { |
| 695 | struct interface *ifp; |
| 696 | struct ripng_interface *ri; |
| 697 | |
| 698 | /* Get interface. */ |
| 699 | ifp = THREAD_ARG (t); |
| 700 | |
| 701 | ri = ifp->info; |
| 702 | ri->t_wakeup = NULL; |
| 703 | |
| 704 | /* Join to multicast group. */ |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 705 | if (ripng_multicast_join (ifp) < 0) { |
| 706 | zlog_err ("multicast join failed, interface %s not running", ifp->name); |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | /* Set running flag. */ |
| 711 | ri->running = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 712 | |
| 713 | /* Send RIP request to the interface. */ |
| 714 | ripng_request (ifp); |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 719 | int ripng_redistribute_check (int); |
| 720 | |
| 721 | void |
| 722 | ripng_connect_set (struct interface *ifp, int set) |
| 723 | { |
| 724 | struct listnode *nn; |
| 725 | struct connected *connected; |
| 726 | struct prefix_ipv6 address; |
| 727 | |
| 728 | for (nn = listhead (ifp->connected); nn; nextnode (nn)) |
| 729 | if ((connected = getdata (nn)) != NULL) { |
| 730 | struct prefix *p; |
| 731 | p = connected->address; |
| 732 | |
| 733 | if (p->family != AF_INET6) |
| 734 | continue; |
| 735 | |
| 736 | address.family = AF_INET6; |
| 737 | address.prefix = p->u.prefix6; |
| 738 | address.prefixlen = p->prefixlen; |
| 739 | apply_mask_ipv6 (&address); |
| 740 | |
| 741 | if (set) { |
| 742 | /* Check once more wether this prefix is within a "network IF_OR_PREF" one */ |
| 743 | if ((ripng_enable_if_lookup(connected->ifp->name) >= 0) || |
| 744 | (ripng_enable_network_lookup2(connected) >= 0)) |
| 745 | ripng_redistribute_add (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE, |
| 746 | &address, connected->ifp->ifindex, NULL); |
| 747 | } else { |
| 748 | ripng_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_INTERFACE, |
| 749 | &address, connected->ifp->ifindex); |
| 750 | if (ripng_redistribute_check (ZEBRA_ROUTE_CONNECT)) |
| 751 | ripng_redistribute_add (ZEBRA_ROUTE_CONNECT, RIPNG_ROUTE_REDISTRIBUTE, |
| 752 | &address, connected->ifp->ifindex, NULL); |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 757 | /* Check RIPng is enabed on this interface. */ |
| 758 | void |
| 759 | ripng_enable_apply (struct interface *ifp) |
| 760 | { |
| 761 | int ret; |
| 762 | struct ripng_interface *ri = NULL; |
| 763 | |
| 764 | /* Check interface. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 765 | if (! if_is_up (ifp)) |
| 766 | return; |
| 767 | |
| 768 | ri = ifp->info; |
| 769 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 770 | /* Is this interface a candidate for RIPng ? */ |
| 771 | ret = ripng_enable_network_lookup_if (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 772 | |
| 773 | /* If the interface is matched. */ |
| 774 | if (ret > 0) |
| 775 | ri->enable_network = 1; |
| 776 | else |
| 777 | ri->enable_network = 0; |
| 778 | |
| 779 | /* Check interface name configuration. */ |
| 780 | ret = ripng_enable_if_lookup (ifp->name); |
| 781 | if (ret >= 0) |
| 782 | ri->enable_interface = 1; |
| 783 | else |
| 784 | ri->enable_interface = 0; |
| 785 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 786 | /* any candidate interface MUST have a link-local IPv6 address */ |
| 787 | if ((! ripng_if_ipv6_lladdress_check (ifp)) && |
| 788 | (ri->enable_network || ri->enable_interface)) { |
| 789 | ri->enable_network = 0; |
| 790 | ri->enable_interface = 0; |
| 791 | zlog_warn("Interface %s does not have any link-local address", |
| 792 | ifp->name); |
| 793 | } |
| 794 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 795 | /* Update running status of the interface. */ |
| 796 | if (ri->enable_network || ri->enable_interface) |
| 797 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 798 | { |
| 799 | if (IS_RIPNG_DEBUG_EVENT) |
ajs | 2e23ab2 | 2004-12-08 19:46:50 +0000 | [diff] [blame] | 800 | zlog_debug ("RIPng turn on %s", ifp->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 801 | |
| 802 | /* Add interface wake up thread. */ |
| 803 | if (! ri->t_wakeup) |
| 804 | ri->t_wakeup = thread_add_timer (master, ripng_interface_wakeup, |
| 805 | ifp, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 806 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 807 | ripng_connect_set (ifp, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | else |
| 811 | { |
| 812 | if (ri->running) |
| 813 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 814 | /* Might as well clean up the route table as well |
| 815 | * ripng_if_down sets to 0 ri->running, and displays "turn off %s" |
| 816 | **/ |
| 817 | ripng_if_down(ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 818 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 819 | ripng_connect_set (ifp, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | /* Set distribute list to all interfaces. */ |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 825 | void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 826 | ripng_enable_apply_all () |
| 827 | { |
| 828 | struct interface *ifp; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 829 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 830 | |
| 831 | for (node = listhead (iflist); node; nextnode (node)) |
| 832 | { |
| 833 | ifp = getdata (node); |
| 834 | ripng_enable_apply (ifp); |
| 835 | } |
| 836 | } |
| 837 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 838 | /* Clear all network and neighbor configuration */ |
| 839 | void |
| 840 | ripng_clean_network () |
| 841 | { |
hasso | 7a1d583 | 2004-10-08 06:32:23 +0000 | [diff] [blame] | 842 | unsigned int i; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 843 | char *str; |
| 844 | struct route_node *rn; |
| 845 | |
| 846 | /* ripng_enable_network */ |
| 847 | for (rn = route_top (ripng_enable_network); rn; rn = route_next (rn)) |
| 848 | if (rn->info) { |
| 849 | rn->info = NULL; |
| 850 | route_unlock_node(rn); |
| 851 | } |
| 852 | |
| 853 | /* ripng_enable_if */ |
| 854 | for (i = 0; i < vector_max (ripng_enable_if); i++) |
| 855 | if ((str = vector_slot (ripng_enable_if, i)) != NULL) { |
| 856 | free (str); |
| 857 | vector_slot (ripng_enable_if, i) = NULL; |
| 858 | } |
| 859 | } |
| 860 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 861 | /* Vector to store passive-interface name. */ |
| 862 | vector Vripng_passive_interface; |
| 863 | |
| 864 | /* Utility function for looking up passive interface settings. */ |
| 865 | int |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 866 | ripng_passive_interface_lookup (const char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 867 | { |
hasso | 7a1d583 | 2004-10-08 06:32:23 +0000 | [diff] [blame] | 868 | unsigned int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 869 | char *str; |
| 870 | |
| 871 | for (i = 0; i < vector_max (Vripng_passive_interface); i++) |
| 872 | if ((str = vector_slot (Vripng_passive_interface, i)) != NULL) |
| 873 | if (strcmp (str, ifname) == 0) |
| 874 | return i; |
| 875 | return -1; |
| 876 | } |
| 877 | |
| 878 | void |
| 879 | ripng_passive_interface_apply (struct interface *ifp) |
| 880 | { |
| 881 | int ret; |
| 882 | struct ripng_interface *ri; |
| 883 | |
| 884 | ri = ifp->info; |
| 885 | |
| 886 | ret = ripng_passive_interface_lookup (ifp->name); |
| 887 | if (ret < 0) |
| 888 | ri->passive = 0; |
| 889 | else |
| 890 | ri->passive = 1; |
| 891 | } |
| 892 | |
| 893 | void |
| 894 | ripng_passive_interface_apply_all (void) |
| 895 | { |
| 896 | struct interface *ifp; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 897 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 898 | |
| 899 | for (node = listhead (iflist); node; nextnode (node)) |
| 900 | { |
| 901 | ifp = getdata (node); |
| 902 | ripng_passive_interface_apply (ifp); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | /* Passive interface. */ |
| 907 | int |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 908 | ripng_passive_interface_set (struct vty *vty, const char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 909 | { |
| 910 | if (ripng_passive_interface_lookup (ifname) >= 0) |
| 911 | return CMD_WARNING; |
| 912 | |
| 913 | vector_set (Vripng_passive_interface, strdup (ifname)); |
| 914 | |
| 915 | ripng_passive_interface_apply_all (); |
| 916 | |
| 917 | return CMD_SUCCESS; |
| 918 | } |
| 919 | |
| 920 | int |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 921 | ripng_passive_interface_unset (struct vty *vty, const char *ifname) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 922 | { |
| 923 | int i; |
| 924 | char *str; |
| 925 | |
| 926 | i = ripng_passive_interface_lookup (ifname); |
| 927 | if (i < 0) |
| 928 | return CMD_WARNING; |
| 929 | |
| 930 | str = vector_slot (Vripng_passive_interface, i); |
| 931 | free (str); |
| 932 | vector_unset (Vripng_passive_interface, i); |
| 933 | |
| 934 | ripng_passive_interface_apply_all (); |
| 935 | |
| 936 | return CMD_SUCCESS; |
| 937 | } |
| 938 | |
| 939 | /* Free all configured RIP passive-interface settings. */ |
| 940 | void |
| 941 | ripng_passive_interface_clean (void) |
| 942 | { |
hasso | 7a1d583 | 2004-10-08 06:32:23 +0000 | [diff] [blame] | 943 | unsigned int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 944 | char *str; |
| 945 | |
| 946 | for (i = 0; i < vector_max (Vripng_passive_interface); i++) |
| 947 | if ((str = vector_slot (Vripng_passive_interface, i)) != NULL) |
| 948 | { |
| 949 | free (str); |
| 950 | vector_slot (Vripng_passive_interface, i) = NULL; |
| 951 | } |
| 952 | ripng_passive_interface_apply_all (); |
| 953 | } |
| 954 | |
| 955 | /* Write RIPng enable network and interface to the vty. */ |
| 956 | int |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 957 | ripng_network_write (struct vty *vty, int config_mode) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 958 | { |
hasso | 7a1d583 | 2004-10-08 06:32:23 +0000 | [diff] [blame] | 959 | unsigned int i; |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 960 | const char *ifname; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 961 | struct route_node *node; |
| 962 | char buf[BUFSIZ]; |
| 963 | |
| 964 | /* Write enable network. */ |
| 965 | for (node = route_top (ripng_enable_network); node; node = route_next (node)) |
| 966 | if (node->info) |
| 967 | { |
| 968 | struct prefix *p = &node->p; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 969 | vty_out (vty, "%s%s/%d%s", |
| 970 | config_mode ? " network " : " ", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 971 | inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), |
| 972 | p->prefixlen, |
| 973 | VTY_NEWLINE); |
| 974 | |
| 975 | } |
| 976 | |
| 977 | /* Write enable interface. */ |
| 978 | for (i = 0; i < vector_max (ripng_enable_if); i++) |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 979 | if ((ifname = vector_slot (ripng_enable_if, i)) != NULL) |
| 980 | vty_out (vty, "%s%s%s", |
| 981 | config_mode ? " network " : " ", |
| 982 | ifname, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 983 | VTY_NEWLINE); |
| 984 | |
| 985 | /* Write passive interface. */ |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 986 | if (config_mode) |
| 987 | for (i = 0; i < vector_max (Vripng_passive_interface); i++) |
| 988 | if ((ifname = vector_slot (Vripng_passive_interface, i)) != NULL) |
| 989 | vty_out (vty, " passive-interface %s%s", ifname, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 990 | |
| 991 | return 0; |
| 992 | } |
| 993 | |
| 994 | /* RIPng enable on specified interface or matched network. */ |
| 995 | DEFUN (ripng_network, |
| 996 | ripng_network_cmd, |
| 997 | "network IF_OR_ADDR", |
| 998 | "RIPng enable on specified interface or network.\n" |
| 999 | "Interface or address") |
| 1000 | { |
| 1001 | int ret; |
| 1002 | struct prefix p; |
| 1003 | |
| 1004 | ret = str2prefix (argv[0], &p); |
| 1005 | |
| 1006 | /* Given string is IPv6 network or interface name. */ |
| 1007 | if (ret) |
| 1008 | ret = ripng_enable_network_add (&p); |
| 1009 | else |
| 1010 | ret = ripng_enable_if_add (argv[0]); |
| 1011 | |
| 1012 | if (ret < 0) |
| 1013 | { |
| 1014 | vty_out (vty, "There is same network configuration %s%s", argv[0], |
| 1015 | VTY_NEWLINE); |
| 1016 | return CMD_WARNING; |
| 1017 | } |
| 1018 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1019 | return CMD_SUCCESS; |
| 1020 | } |
| 1021 | |
| 1022 | /* RIPng enable on specified interface or matched network. */ |
| 1023 | DEFUN (no_ripng_network, |
| 1024 | no_ripng_network_cmd, |
| 1025 | "no network IF_OR_ADDR", |
| 1026 | NO_STR |
| 1027 | "RIPng enable on specified interface or network.\n" |
| 1028 | "Interface or address") |
| 1029 | { |
| 1030 | int ret; |
| 1031 | struct prefix p; |
| 1032 | |
| 1033 | ret = str2prefix (argv[0], &p); |
| 1034 | |
| 1035 | /* Given string is interface name. */ |
| 1036 | if (ret) |
| 1037 | ret = ripng_enable_network_delete (&p); |
| 1038 | else |
| 1039 | ret = ripng_enable_if_delete (argv[0]); |
| 1040 | |
| 1041 | if (ret < 0) |
| 1042 | { |
| 1043 | vty_out (vty, "can't find network %s%s", argv[0], |
| 1044 | VTY_NEWLINE); |
| 1045 | return CMD_WARNING; |
| 1046 | } |
| 1047 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1048 | return CMD_SUCCESS; |
| 1049 | } |
| 1050 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1051 | DEFUN (ipv6_ripng_split_horizon, |
| 1052 | ipv6_ripng_split_horizon_cmd, |
| 1053 | "ipv6 ripng split-horizon", |
| 1054 | IPV6_STR |
| 1055 | "Routing Information Protocol\n" |
| 1056 | "Perform split horizon\n") |
| 1057 | { |
| 1058 | struct interface *ifp; |
| 1059 | struct ripng_interface *ri; |
| 1060 | |
| 1061 | ifp = vty->index; |
| 1062 | ri = ifp->info; |
| 1063 | |
| 1064 | ri->split_horizon = RIPNG_SPLIT_HORIZON; |
| 1065 | return CMD_SUCCESS; |
| 1066 | } |
| 1067 | |
| 1068 | DEFUN (ipv6_ripng_split_horizon_poisoned_reverse, |
| 1069 | ipv6_ripng_split_horizon_poisoned_reverse_cmd, |
| 1070 | "ipv6 ripng split-horizon poisoned-reverse", |
| 1071 | IPV6_STR |
| 1072 | "Routing Information Protocol\n" |
| 1073 | "Perform split horizon\n" |
| 1074 | "With poisoned-reverse\n") |
| 1075 | { |
| 1076 | struct interface *ifp; |
| 1077 | struct ripng_interface *ri; |
| 1078 | |
| 1079 | ifp = vty->index; |
| 1080 | ri = ifp->info; |
| 1081 | |
| 1082 | ri->split_horizon = RIPNG_SPLIT_HORIZON_POISONED_REVERSE; |
| 1083 | return CMD_SUCCESS; |
| 1084 | } |
| 1085 | |
| 1086 | DEFUN (no_ipv6_ripng_split_horizon, |
| 1087 | no_ipv6_ripng_split_horizon_cmd, |
| 1088 | "no ipv6 ripng split-horizon", |
| 1089 | NO_STR |
| 1090 | IPV6_STR |
| 1091 | "Routing Information Protocol\n" |
| 1092 | "Perform split horizon\n") |
| 1093 | { |
| 1094 | struct interface *ifp; |
| 1095 | struct ripng_interface *ri; |
| 1096 | |
| 1097 | ifp = vty->index; |
| 1098 | ri = ifp->info; |
| 1099 | |
| 1100 | ri->split_horizon = RIPNG_NO_SPLIT_HORIZON; |
| 1101 | return CMD_SUCCESS; |
| 1102 | } |
| 1103 | |
| 1104 | ALIAS (no_ipv6_ripng_split_horizon, |
| 1105 | no_ipv6_ripng_split_horizon_poisoned_reverse_cmd, |
| 1106 | "no ipv6 ripng split-horizon poisoned-reverse", |
| 1107 | NO_STR |
| 1108 | IPV6_STR |
| 1109 | "Routing Information Protocol\n" |
| 1110 | "Perform split horizon\n" |
| 1111 | "With poisoned-reverse\n") |
| 1112 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1113 | DEFUN (ripng_passive_interface, |
| 1114 | ripng_passive_interface_cmd, |
| 1115 | "passive-interface IFNAME", |
| 1116 | "Suppress routing updates on an interface\n" |
| 1117 | "Interface name\n") |
| 1118 | { |
| 1119 | return ripng_passive_interface_set (vty, argv[0]); |
| 1120 | } |
| 1121 | |
| 1122 | DEFUN (no_ripng_passive_interface, |
| 1123 | no_ripng_passive_interface_cmd, |
| 1124 | "no passive-interface IFNAME", |
| 1125 | NO_STR |
| 1126 | "Suppress routing updates on an interface\n" |
| 1127 | "Interface name\n") |
| 1128 | { |
| 1129 | return ripng_passive_interface_unset (vty, argv[0]); |
| 1130 | } |
| 1131 | |
| 1132 | struct ripng_interface * |
| 1133 | ri_new () |
| 1134 | { |
| 1135 | struct ripng_interface *ri; |
| 1136 | ri = XCALLOC (MTYPE_IF, sizeof (struct ripng_interface)); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1137 | |
| 1138 | /* Set default split-horizon behavior. If the interface is Frame |
| 1139 | Relay or SMDS is enabled, the default value for split-horizon is |
| 1140 | off. But currently Zebra does detect Frame Relay or SMDS |
| 1141 | interface. So all interface is set to split horizon. */ |
| 1142 | ri->split_horizon_default = RIPNG_SPLIT_HORIZON; |
| 1143 | ri->split_horizon = ri->split_horizon_default; |
| 1144 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1145 | return ri; |
| 1146 | } |
| 1147 | |
| 1148 | int |
| 1149 | ripng_if_new_hook (struct interface *ifp) |
| 1150 | { |
| 1151 | ifp->info = ri_new (); |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1155 | /* Called when interface structure deleted. */ |
| 1156 | int |
| 1157 | ripng_if_delete_hook (struct interface *ifp) |
| 1158 | { |
| 1159 | XFREE (MTYPE_IF, ifp->info); |
| 1160 | ifp->info = NULL; |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1164 | /* Configuration write function for ripngd. */ |
| 1165 | int |
| 1166 | interface_config_write (struct vty *vty) |
| 1167 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 1168 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1169 | struct interface *ifp; |
| 1170 | struct ripng_interface *ri; |
| 1171 | int write = 0; |
| 1172 | |
| 1173 | for (node = listhead (iflist); node; nextnode (node)) |
| 1174 | { |
| 1175 | ifp = getdata (node); |
| 1176 | ri = ifp->info; |
| 1177 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1178 | /* Do not display the interface if there is no |
| 1179 | * configuration about it. |
| 1180 | **/ |
| 1181 | if ((!ifp->desc) && |
| 1182 | (ri->split_horizon == ri->split_horizon_default)) |
| 1183 | continue; |
| 1184 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1185 | vty_out (vty, "interface %s%s", ifp->name, |
| 1186 | VTY_NEWLINE); |
| 1187 | if (ifp->desc) |
| 1188 | vty_out (vty, " description %s%s", ifp->desc, |
| 1189 | VTY_NEWLINE); |
| 1190 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1191 | /* Split horizon. */ |
| 1192 | if (ri->split_horizon != ri->split_horizon_default) |
| 1193 | { |
| 1194 | switch (ri->split_horizon) { |
| 1195 | case RIPNG_SPLIT_HORIZON: |
| 1196 | vty_out (vty, " ipv6 ripng split-horizon%s", VTY_NEWLINE); |
| 1197 | break; |
| 1198 | case RIPNG_SPLIT_HORIZON_POISONED_REVERSE: |
| 1199 | vty_out (vty, " ipv6 ripng split-horizon poisoned-reverse%s", |
| 1200 | VTY_NEWLINE); |
| 1201 | break; |
| 1202 | case RIPNG_NO_SPLIT_HORIZON: |
| 1203 | default: |
| 1204 | vty_out (vty, " no ipv6 ripng split-horizon%s", VTY_NEWLINE); |
| 1205 | break; |
| 1206 | } |
| 1207 | } |
| 1208 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1209 | vty_out (vty, "!%s", VTY_NEWLINE); |
| 1210 | |
| 1211 | write++; |
| 1212 | } |
| 1213 | return write; |
| 1214 | } |
| 1215 | |
| 1216 | /* ripngd's interface node. */ |
| 1217 | struct cmd_node interface_node = |
| 1218 | { |
| 1219 | INTERFACE_NODE, |
| 1220 | "%s(config-if)# ", |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1221 | 1 /* VTYSH */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1222 | }; |
| 1223 | |
| 1224 | /* Initialization of interface. */ |
| 1225 | void |
| 1226 | ripng_if_init () |
| 1227 | { |
| 1228 | /* Interface initialize. */ |
| 1229 | iflist = list_new (); |
| 1230 | if_add_hook (IF_NEW_HOOK, ripng_if_new_hook); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1231 | if_add_hook (IF_DELETE_HOOK, ripng_if_delete_hook); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1232 | |
| 1233 | /* RIPng enable network init. */ |
| 1234 | ripng_enable_network = route_table_init (); |
| 1235 | |
| 1236 | /* RIPng enable interface init. */ |
| 1237 | ripng_enable_if = vector_init (1); |
| 1238 | |
| 1239 | /* RIPng passive interface. */ |
| 1240 | Vripng_passive_interface = vector_init (1); |
| 1241 | |
| 1242 | /* Install interface node. */ |
| 1243 | install_node (&interface_node, interface_config_write); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1244 | |
| 1245 | /* Install commands. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1246 | install_element (CONFIG_NODE, &interface_cmd); |
paul | 32d2463 | 2003-05-23 09:25:20 +0000 | [diff] [blame] | 1247 | install_element (CONFIG_NODE, &no_interface_cmd); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1248 | install_default (INTERFACE_NODE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1249 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
| 1250 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
| 1251 | |
| 1252 | install_element (RIPNG_NODE, &ripng_network_cmd); |
| 1253 | install_element (RIPNG_NODE, &no_ripng_network_cmd); |
| 1254 | install_element (RIPNG_NODE, &ripng_passive_interface_cmd); |
| 1255 | install_element (RIPNG_NODE, &no_ripng_passive_interface_cmd); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 1256 | |
| 1257 | install_element (INTERFACE_NODE, &ipv6_ripng_split_horizon_cmd); |
| 1258 | install_element (INTERFACE_NODE, &ipv6_ripng_split_horizon_poisoned_reverse_cmd); |
| 1259 | install_element (INTERFACE_NODE, &no_ipv6_ripng_split_horizon_cmd); |
| 1260 | install_element (INTERFACE_NODE, &no_ipv6_ripng_split_horizon_poisoned_reverse_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1261 | } |