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