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