paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Address linked list routine. |
| 3 | * Copyright (C) 1997, 98 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 "prefix.h" |
| 26 | #include "linklist.h" |
| 27 | #include "if.h" |
| 28 | #include "table.h" |
| 29 | #include "rib.h" |
| 30 | #include "table.h" |
| 31 | #include "log.h" |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 32 | #include "memory.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | |
| 34 | #include "zebra/zserv.h" |
| 35 | #include "zebra/redistribute.h" |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 36 | #include "zebra/interface.h" |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 37 | #include "zebra/connected.h" |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 38 | extern struct zebra_t zebrad; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 39 | |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 40 | /* withdraw a connected address */ |
| 41 | static void |
| 42 | connected_withdraw (struct connected *ifc) |
| 43 | { |
| 44 | if (! ifc) |
| 45 | return; |
| 46 | |
| 47 | /* Update interface address information to protocol daemon. */ |
| 48 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) |
| 49 | { |
| 50 | zebra_interface_address_delete_update (ifc->ifp, ifc); |
| 51 | |
| 52 | if_subnet_delete (ifc->ifp, ifc); |
| 53 | |
| 54 | if (ifc->address->family == AF_INET) |
| 55 | connected_down_ipv4 (ifc->ifp, ifc); |
vincent | aa2e32b | 2005-09-28 13:42:11 +0000 | [diff] [blame] | 56 | #ifdef HAVE_IPV6 |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 57 | else |
| 58 | connected_down_ipv6 (ifc->ifp, ifc); |
vincent | aa2e32b | 2005-09-28 13:42:11 +0000 | [diff] [blame] | 59 | #endif |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 60 | |
| 61 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
| 62 | } |
| 63 | |
Andrew J. Schorr | 9c37851 | 2006-05-21 04:04:49 +0000 | [diff] [blame] | 64 | if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 65 | { |
| 66 | listnode_delete (ifc->ifp->connected, ifc); |
| 67 | connected_free (ifc); |
| 68 | } |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void |
| 72 | connected_announce (struct interface *ifp, struct connected *ifc) |
| 73 | { |
| 74 | if (!ifc) |
| 75 | return; |
| 76 | |
| 77 | listnode_add (ifp->connected, ifc); |
| 78 | |
| 79 | /* Update interface address information to protocol daemon. */ |
| 80 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) |
| 81 | { |
| 82 | if (ifc->address->family == AF_INET) |
| 83 | if_subnet_add (ifp, ifc); |
| 84 | |
| 85 | SET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
| 86 | |
| 87 | zebra_interface_address_add_update (ifp, ifc); |
| 88 | |
| 89 | if (if_is_up(ifp)) |
| 90 | { |
| 91 | if (ifc->address->family == AF_INET) |
| 92 | connected_up_ipv4 (ifp, ifc); |
vincent | aa2e32b | 2005-09-28 13:42:11 +0000 | [diff] [blame] | 93 | #ifdef HAVE_IPV6 |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 94 | else |
| 95 | connected_up_ipv6 (ifp, ifc); |
vincent | aa2e32b | 2005-09-28 13:42:11 +0000 | [diff] [blame] | 96 | #endif |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 101 | /* If same interface address is already exist... */ |
| 102 | struct connected * |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 103 | connected_check (struct interface *ifp, struct prefix *p) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 104 | { |
| 105 | struct connected *ifc; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 106 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 107 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 108 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) |
| 109 | if (prefix_same (ifc->address, p)) |
| 110 | return ifc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 111 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 112 | return NULL; |
| 113 | } |
| 114 | |
Paul Jakma | 74ecdc9 | 2006-06-15 18:10:47 +0000 | [diff] [blame] | 115 | /* Check if two ifc's describe the same address */ |
| 116 | static int |
| 117 | connected_same (struct connected *ifc1, struct connected *ifc2) |
| 118 | { |
| 119 | if (ifc1->ifp != ifc2->ifp) |
| 120 | return 0; |
| 121 | |
| 122 | if (ifc1->destination) |
| 123 | if (!ifc2->destination) |
| 124 | return 0; |
| 125 | if (ifc2->destination) |
| 126 | if (!ifc1->destination) |
| 127 | return 0; |
| 128 | |
| 129 | if (ifc1->destination && ifc2->destination) |
| 130 | if (!prefix_same (ifc1->destination, ifc2->destination)) |
| 131 | return 0; |
| 132 | |
| 133 | if (ifc1->flags != ifc2->flags) |
| 134 | return 0; |
| 135 | |
| 136 | return 1; |
| 137 | } |
| 138 | |
| 139 | /* Handle implicit withdrawals of addresses, where a system ADDs an address |
| 140 | * to an interface which already has the same address configured. |
| 141 | * |
| 142 | * Returns the struct connected which must be announced to clients, |
| 143 | * or NULL if nothing to do. |
| 144 | */ |
| 145 | static struct connected * |
| 146 | connected_implicit_withdraw (struct interface *ifp, struct connected *ifc) |
| 147 | { |
| 148 | struct connected *current; |
| 149 | |
| 150 | /* Check same connected route. */ |
| 151 | if ((current = connected_check (ifp, (struct prefix *) ifc->address))) |
| 152 | { |
| 153 | if (CHECK_FLAG(current->conf, ZEBRA_IFC_CONFIGURED)) |
| 154 | SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 155 | |
| 156 | /* Avoid spurious withdraws, this might be just the kernel 'reflecting' |
| 157 | * back an address we have already added. |
| 158 | */ |
David Young | 33b931e | 2007-04-16 05:54:02 +0000 | [diff] [blame] | 159 | if (connected_same (current, ifc) && CHECK_FLAG(current->conf, ZEBRA_IFC_REAL)) |
Paul Jakma | 74ecdc9 | 2006-06-15 18:10:47 +0000 | [diff] [blame] | 160 | { |
| 161 | /* nothing to do */ |
| 162 | connected_free (ifc); |
| 163 | return NULL; |
| 164 | } |
| 165 | |
| 166 | UNSET_FLAG(current->conf, ZEBRA_IFC_CONFIGURED); |
| 167 | connected_withdraw (current); /* implicit withdraw - freebsd does this */ |
| 168 | } |
| 169 | return ifc; |
| 170 | } |
| 171 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 172 | /* Called from if_up(). */ |
| 173 | void |
| 174 | connected_up_ipv4 (struct interface *ifp, struct connected *ifc) |
| 175 | { |
| 176 | struct prefix_ipv4 p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 177 | |
| 178 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) |
| 179 | return; |
| 180 | |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 181 | PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 182 | |
| 183 | /* Apply mask to the network. */ |
| 184 | apply_mask_ipv4 (&p); |
| 185 | |
| 186 | /* In case of connected address is 0.0.0.0/0 we treat it tunnel |
| 187 | address. */ |
| 188 | if (prefix_ipv4_any (&p)) |
| 189 | return; |
| 190 | |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 191 | /* Always push arriving/departing connected routes into the head of |
| 192 | * the working queue to make possible proper validation of the rest |
| 193 | * of the RIB queue (which will contain the whole RIB after the first |
| 194 | * call to rib_update()). |
| 195 | */ |
| 196 | work_queue_aim_head (zebrad.ribq, 1); |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 197 | rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, &p, NULL, NULL, ifp->ifindex, |
| 198 | RT_TABLE_MAIN, ifp->metric, 0); |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 199 | work_queue_aim_head (zebrad.ribq, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 200 | |
| 201 | rib_update (); |
| 202 | } |
| 203 | |
| 204 | /* Add connected IPv4 route to the interface. */ |
| 205 | void |
| 206 | connected_add_ipv4 (struct interface *ifp, int flags, struct in_addr *addr, |
paul | d06b2a6 | 2005-10-11 03:53:54 +0000 | [diff] [blame] | 207 | u_char prefixlen, struct in_addr *broad, |
| 208 | const char *label) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 209 | { |
| 210 | struct prefix_ipv4 *p; |
| 211 | struct connected *ifc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 212 | |
| 213 | /* Make connected structure. */ |
| 214 | ifc = connected_new (); |
| 215 | ifc->ifp = ifp; |
| 216 | ifc->flags = flags; |
| 217 | |
| 218 | /* Allocate new connected address. */ |
| 219 | p = prefix_ipv4_new (); |
| 220 | p->family = AF_INET; |
| 221 | p->prefix = *addr; |
| 222 | p->prefixlen = prefixlen; |
| 223 | ifc->address = (struct prefix *) p; |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 224 | |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 225 | /* If there is broadcast or peer address. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 226 | if (broad) |
| 227 | { |
| 228 | p = prefix_ipv4_new (); |
| 229 | p->family = AF_INET; |
| 230 | p->prefix = *broad; |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 231 | p->prefixlen = prefixlen; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 232 | ifc->destination = (struct prefix *) p; |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 233 | |
| 234 | /* validate the destination address */ |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 235 | if (CONNECTED_PEER(ifc)) |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 236 | { |
| 237 | if (IPV4_ADDR_SAME(addr,broad)) |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 238 | zlog_warn("warning: interface %s has same local and peer " |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 239 | "address %s, routing protocols may malfunction", |
| 240 | ifp->name,inet_ntoa(*addr)); |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 241 | } |
| 242 | else |
| 243 | { |
| 244 | if (broad->s_addr != ipv4_broadcast_addr(addr->s_addr,prefixlen)) |
| 245 | { |
| 246 | char buf[2][INET_ADDRSTRLEN]; |
| 247 | struct in_addr bcalc; |
| 248 | bcalc.s_addr = ipv4_broadcast_addr(addr->s_addr,prefixlen); |
| 249 | zlog_warn("warning: interface %s broadcast addr %s/%d != " |
| 250 | "calculated %s, routing protocols may malfunction", |
| 251 | ifp->name, |
| 252 | inet_ntop (AF_INET, broad, buf[0], sizeof(buf[0])), |
| 253 | prefixlen, |
| 254 | inet_ntop (AF_INET, &bcalc, buf[1], sizeof(buf[1]))); |
| 255 | } |
| 256 | } |
| 257 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 258 | } |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 259 | else |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 260 | { |
| 261 | if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER)) |
| 262 | { |
| 263 | zlog_warn("warning: %s called for interface %s " |
| 264 | "with peer flag set, but no peer address supplied", |
| 265 | __func__, ifp->name); |
| 266 | UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER); |
| 267 | } |
| 268 | |
| 269 | /* no broadcast or destination address was supplied */ |
| 270 | if ((prefixlen == IPV4_MAX_PREFIXLEN) && if_is_pointopoint(ifp)) |
| 271 | zlog_warn("warning: PtP interface %s with addr %s/%d needs a " |
| 272 | "peer address",ifp->name,inet_ntoa(*addr),prefixlen); |
| 273 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 274 | |
| 275 | /* Label of this address. */ |
| 276 | if (label) |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 277 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 278 | |
Paul Jakma | 74ecdc9 | 2006-06-15 18:10:47 +0000 | [diff] [blame] | 279 | /* nothing to do? */ |
| 280 | if ((ifc = connected_implicit_withdraw (ifp, ifc)) == NULL) |
| 281 | return; |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 282 | |
| 283 | connected_announce (ifp, ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void |
| 287 | connected_down_ipv4 (struct interface *ifp, struct connected *ifc) |
| 288 | { |
| 289 | struct prefix_ipv4 p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 290 | |
| 291 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) |
| 292 | return; |
| 293 | |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 294 | PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 295 | |
| 296 | /* Apply mask to the network. */ |
| 297 | apply_mask_ipv4 (&p); |
| 298 | |
| 299 | /* In case of connected address is 0.0.0.0/0 we treat it tunnel |
| 300 | address. */ |
| 301 | if (prefix_ipv4_any (&p)) |
| 302 | return; |
| 303 | |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 304 | /* Same logic as for connected_up_ipv4(): push the changes into the head. */ |
| 305 | work_queue_aim_head (zebrad.ribq, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 306 | rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, &p, NULL, ifp->ifindex, 0); |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 307 | work_queue_aim_head (zebrad.ribq, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 308 | |
| 309 | rib_update (); |
| 310 | } |
| 311 | |
| 312 | /* Delete connected IPv4 route to the interface. */ |
| 313 | void |
| 314 | connected_delete_ipv4 (struct interface *ifp, int flags, struct in_addr *addr, |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 315 | u_char prefixlen, struct in_addr *broad) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 316 | { |
| 317 | struct prefix_ipv4 p; |
| 318 | struct connected *ifc; |
| 319 | |
| 320 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 321 | p.family = AF_INET; |
| 322 | p.prefix = *addr; |
| 323 | p.prefixlen = prefixlen; |
| 324 | |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 325 | ifc = connected_check (ifp, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 326 | if (! ifc) |
| 327 | return; |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 328 | |
| 329 | connected_withdraw (ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | #ifdef HAVE_IPV6 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 333 | void |
| 334 | connected_up_ipv6 (struct interface *ifp, struct connected *ifc) |
| 335 | { |
| 336 | struct prefix_ipv6 p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 337 | |
| 338 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) |
| 339 | return; |
| 340 | |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 341 | PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 342 | |
| 343 | /* Apply mask to the network. */ |
| 344 | apply_mask_ipv6 (&p); |
| 345 | |
hasso | 726f9b2 | 2003-05-25 21:04:54 +0000 | [diff] [blame] | 346 | #if ! defined (MUSICA) && ! defined (LINUX) |
| 347 | /* XXX: It is already done by rib_bogus_ipv6 within rib_add_ipv6 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 348 | if (IN6_IS_ADDR_UNSPECIFIED (&p.prefix)) |
| 349 | return; |
hasso | 726f9b2 | 2003-05-25 21:04:54 +0000 | [diff] [blame] | 350 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 351 | |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 352 | work_queue_aim_head (zebrad.ribq, 1); |
paul | c713300 | 2006-01-17 17:56:18 +0000 | [diff] [blame] | 353 | rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, &p, NULL, ifp->ifindex, 0, |
| 354 | ifp->metric, 0); |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 355 | work_queue_aim_head (zebrad.ribq, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 356 | |
| 357 | rib_update (); |
| 358 | } |
| 359 | |
| 360 | /* Add connected IPv6 route to the interface. */ |
| 361 | void |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 362 | connected_add_ipv6 (struct interface *ifp, int flags, struct in6_addr *addr, |
paul | 89368d9 | 2005-11-26 09:14:07 +0000 | [diff] [blame] | 363 | u_char prefixlen, struct in6_addr *broad, |
| 364 | const char *label) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 365 | { |
| 366 | struct prefix_ipv6 *p; |
| 367 | struct connected *ifc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 368 | |
| 369 | /* Make connected structure. */ |
| 370 | ifc = connected_new (); |
| 371 | ifc->ifp = ifp; |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 372 | ifc->flags = flags; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 373 | |
| 374 | /* Allocate new connected address. */ |
| 375 | p = prefix_ipv6_new (); |
| 376 | p->family = AF_INET6; |
| 377 | IPV6_ADDR_COPY (&p->prefix, addr); |
| 378 | p->prefixlen = prefixlen; |
| 379 | ifc->address = (struct prefix *) p; |
| 380 | |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 381 | /* If there is broadcast or peer address. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 382 | if (broad) |
| 383 | { |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 384 | if (IN6_IS_ADDR_UNSPECIFIED(broad)) |
| 385 | zlog_warn("warning: %s called for interface %s with unspecified " |
| 386 | "destination address; ignoring!", __func__, ifp->name); |
| 387 | else |
| 388 | { |
| 389 | p = prefix_ipv6_new (); |
| 390 | p->family = AF_INET6; |
| 391 | IPV6_ADDR_COPY (&p->prefix, broad); |
| 392 | p->prefixlen = prefixlen; |
| 393 | ifc->destination = (struct prefix *) p; |
| 394 | } |
| 395 | } |
| 396 | if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER) && !ifc->destination) |
| 397 | { |
| 398 | zlog_warn("warning: %s called for interface %s " |
| 399 | "with peer flag set, but no peer address supplied", |
| 400 | __func__, ifp->name); |
| 401 | UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 402 | } |
| 403 | |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 404 | /* Label of this address. */ |
| 405 | if (label) |
| 406 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
| 407 | |
Paul Jakma | 74ecdc9 | 2006-06-15 18:10:47 +0000 | [diff] [blame] | 408 | if ((ifc = connected_implicit_withdraw (ifp, ifc)) == NULL) |
| 409 | return; |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 410 | |
| 411 | connected_announce (ifp, ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void |
| 415 | connected_down_ipv6 (struct interface *ifp, struct connected *ifc) |
| 416 | { |
| 417 | struct prefix_ipv6 p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 418 | |
| 419 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) |
| 420 | return; |
| 421 | |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 422 | PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 423 | |
| 424 | apply_mask_ipv6 (&p); |
| 425 | |
| 426 | if (IN6_IS_ADDR_UNSPECIFIED (&p.prefix)) |
| 427 | return; |
| 428 | |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 429 | work_queue_aim_head (zebrad.ribq, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, &p, NULL, ifp->ifindex, 0); |
Denis Ovsienko | 6ce80bd | 2007-11-12 14:55:01 +0000 | [diff] [blame] | 431 | work_queue_aim_head (zebrad.ribq, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 432 | |
| 433 | rib_update (); |
| 434 | } |
| 435 | |
| 436 | void |
| 437 | connected_delete_ipv6 (struct interface *ifp, struct in6_addr *address, |
hasso | fce954f | 2004-10-07 20:29:24 +0000 | [diff] [blame] | 438 | u_char prefixlen, struct in6_addr *broad) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 439 | { |
| 440 | struct prefix_ipv6 p; |
| 441 | struct connected *ifc; |
| 442 | |
| 443 | memset (&p, 0, sizeof (struct prefix_ipv6)); |
| 444 | p.family = AF_INET6; |
| 445 | memcpy (&p.prefix, address, sizeof (struct in6_addr)); |
| 446 | p.prefixlen = prefixlen; |
| 447 | |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 448 | ifc = connected_check (ifp, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 449 | if (! ifc) |
| 450 | return; |
| 451 | |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 452 | connected_withdraw (ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 453 | } |
| 454 | #endif /* HAVE_IPV6 */ |