]>
Commit | Line | Data |
---|---|---|
718e3744 | 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 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
23 | ||
24 | #include "prefix.h" | |
25 | #include "linklist.h" | |
26 | #include "if.h" | |
27 | #include "table.h" | |
28 | #include "rib.h" | |
29 | #include "table.h" | |
30 | #include "log.h" | |
0752ef0b | 31 | #include "memory.h" |
718e3744 | 32 | |
82f97584 | 33 | #include "vty.h" |
b84c7253 | 34 | #include "zebra/debug.h" |
718e3744 | 35 | #include "zebra/zserv.h" |
36 | #include "zebra/redistribute.h" | |
eef1fe11 | 37 | #include "zebra/interface.h" |
a1ac18c4 | 38 | #include "zebra/connected.h" |
b6120505 | 39 | #include "zebra/rtadv.h" |
40c7bdb0 | 40 | #include "zebra/zebra_mpls.h" |
9df414fe | 41 | #include "zebra/zebra_errors.h" |
e4876266 | 42 | #include "zebra/zebra_router.h" |
6b0655a2 | 43 | |
02b4805f | 44 | /* communicate the withdrawal of a connected address */ |
d62a17ae | 45 | static void connected_withdraw(struct connected *ifc) |
ca16218d | 46 | { |
d62a17ae | 47 | if (!ifc) |
48 | return; | |
ca16218d | 49 | |
d62a17ae | 50 | /* Update interface address information to protocol daemon. */ |
51 | if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) { | |
52 | zebra_interface_address_delete_update(ifc->ifp, ifc); | |
ca16218d | 53 | |
d62a17ae | 54 | if (ifc->address->family == AF_INET) |
55 | if_subnet_delete(ifc->ifp, ifc); | |
9db047fc | 56 | |
11461c63 | 57 | connected_down(ifc->ifp, ifc); |
ca16218d | 58 | |
d62a17ae | 59 | UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL); |
60 | } | |
ca16218d | 61 | |
d62a17ae | 62 | /* The address is not in the kernel anymore, so clear the flag */ |
63 | UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED); | |
f7f740fe | 64 | |
d62a17ae | 65 | if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) { |
66 | listnode_delete(ifc->ifp->connected, ifc); | |
721c0857 | 67 | connected_free(&ifc); |
d62a17ae | 68 | } |
ca16218d | 69 | } |
70 | ||
d62a17ae | 71 | static void connected_announce(struct interface *ifp, struct connected *ifc) |
ca16218d | 72 | { |
d62a17ae | 73 | if (!ifc) |
74 | return; | |
75 | ||
608c8870 | 76 | if (!if_is_loopback(ifp) && ifc->address->family == AF_INET) { |
12256b84 | 77 | if (ifc->address->prefixlen == IPV4_MAX_BITLEN) |
d62a17ae | 78 | SET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED); |
79 | else | |
80 | UNSET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED); | |
81 | } | |
82 | ||
83 | listnode_add(ifp->connected, ifc); | |
84 | ||
85 | /* Update interface address information to protocol daemon. */ | |
86 | if (ifc->address->family == AF_INET) | |
87 | if_subnet_add(ifp, ifc); | |
88 | ||
89 | zebra_interface_address_add_update(ifp, ifc); | |
90 | ||
91 | if (if_is_operative(ifp)) { | |
ae87977c | 92 | connected_up(ifp, ifc); |
d62a17ae | 93 | } |
ca16218d | 94 | } |
6b0655a2 | 95 | |
718e3744 | 96 | /* If same interface address is already exist... */ |
abffde07 DL |
97 | struct connected *connected_check(struct interface *ifp, |
98 | union prefixconstptr pu) | |
718e3744 | 99 | { |
abffde07 | 100 | const struct prefix *p = pu.p; |
d62a17ae | 101 | struct connected *ifc; |
102 | struct listnode *node; | |
718e3744 | 103 | |
d62a17ae | 104 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) |
105 | if (prefix_same(ifc->address, p)) | |
106 | return ifc; | |
718e3744 | 107 | |
d62a17ae | 108 | return NULL; |
718e3744 | 109 | } |
110 | ||
abffde07 DL |
111 | /* same, but with peer address */ |
112 | struct connected *connected_check_ptp(struct interface *ifp, | |
113 | union prefixconstptr pu, | |
114 | union prefixconstptr du) | |
115 | { | |
116 | const struct prefix *p = pu.p; | |
117 | const struct prefix *d = du.p; | |
118 | struct connected *ifc; | |
119 | struct listnode *node; | |
120 | ||
abffde07 DL |
121 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { |
122 | if (!prefix_same(ifc->address, p)) | |
123 | continue; | |
124 | if (!CONNECTED_PEER(ifc) && !d) | |
125 | return ifc; | |
126 | if (CONNECTED_PEER(ifc) && d | |
127 | && prefix_same(ifc->destination, d)) | |
128 | return ifc; | |
129 | } | |
130 | ||
131 | return NULL; | |
132 | } | |
133 | ||
02b4805f | 134 | /* Check if two ifc's describe the same address in the same state */ |
d62a17ae | 135 | static int connected_same(struct connected *ifc1, struct connected *ifc2) |
74ecdc9e | 136 | { |
d62a17ae | 137 | if (ifc1->ifp != ifc2->ifp) |
138 | return 0; | |
139 | ||
0f3af738 JW |
140 | if (ifc1->flags != ifc2->flags) |
141 | return 0; | |
142 | ||
143 | if (ifc1->conf != ifc2->conf) | |
144 | return 0; | |
145 | ||
d62a17ae | 146 | if (ifc1->destination) |
147 | if (!ifc2->destination) | |
148 | return 0; | |
149 | if (ifc2->destination) | |
150 | if (!ifc1->destination) | |
151 | return 0; | |
152 | ||
153 | if (ifc1->destination && ifc2->destination) | |
154 | if (!prefix_same(ifc1->destination, ifc2->destination)) | |
155 | return 0; | |
156 | ||
d62a17ae | 157 | return 1; |
74ecdc9e PJ |
158 | } |
159 | ||
d7f5dad6 CF |
160 | /* Handle changes to addresses and send the neccesary announcements |
161 | * to clients. */ | |
d62a17ae | 162 | static void connected_update(struct interface *ifp, struct connected *ifc) |
74ecdc9e | 163 | { |
d62a17ae | 164 | struct connected *current; |
165 | ||
166 | /* Check same connected route. */ | |
abffde07 DL |
167 | current = connected_check_ptp(ifp, ifc->address, ifc->destination); |
168 | if (current) { | |
d62a17ae | 169 | if (CHECK_FLAG(current->conf, ZEBRA_IFC_CONFIGURED)) |
170 | SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED); | |
171 | ||
172 | /* Avoid spurious withdraws, this might be just the kernel | |
173 | * 'reflecting' | |
174 | * back an address we have already added. | |
175 | */ | |
176 | if (connected_same(current, ifc)) { | |
177 | /* nothing to do */ | |
721c0857 | 178 | connected_free(&ifc); |
d62a17ae | 179 | return; |
180 | } | |
181 | ||
182 | /* Clear the configured flag on the old ifc, so it will be freed | |
183 | * by | |
184 | * connected withdraw. */ | |
185 | UNSET_FLAG(current->conf, ZEBRA_IFC_CONFIGURED); | |
186 | connected_withdraw( | |
187 | current); /* implicit withdraw - freebsd does this */ | |
188 | } | |
189 | ||
190 | /* If the connected is new or has changed, announce it, if it is usable | |
191 | */ | |
192 | if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) | |
193 | connected_announce(ifp, ifc); | |
74ecdc9e PJ |
194 | } |
195 | ||
718e3744 | 196 | /* Called from if_up(). */ |
ae87977c | 197 | void connected_up(struct interface *ifp, struct connected *ifc) |
718e3744 | 198 | { |
ae87977c | 199 | afi_t afi; |
b08dcc3f | 200 | struct prefix p; |
fd36be7e | 201 | struct nexthop nh = { |
4a7371e9 DS |
202 | .type = NEXTHOP_TYPE_IFINDEX, |
203 | .ifindex = ifp->ifindex, | |
096f7609 | 204 | .vrf_id = ifp->vrf->vrf_id, |
fd36be7e | 205 | }; |
56e78254 | 206 | struct zebra_vrf *zvrf; |
cde1af84 | 207 | uint32_t metric; |
e4876266 | 208 | uint32_t flags = 0; |
92980561 DS |
209 | uint32_t count = 0; |
210 | struct listnode *cnode; | |
211 | struct connected *c; | |
d62a17ae | 212 | |
096f7609 | 213 | zvrf = ifp->vrf->info; |
56e78254 | 214 | if (!zvrf) { |
15569c58 DA |
215 | flog_err( |
216 | EC_ZEBRA_VRF_NOT_FOUND, | |
096f7609 IR |
217 | "%s: Received Up for interface but no associated zvrf: %s(%d)", |
218 | __func__, ifp->vrf->name, ifp->vrf->vrf_id); | |
56e78254 DS |
219 | return; |
220 | } | |
d62a17ae | 221 | if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) |
222 | return; | |
223 | ||
e3d901f8 MS |
224 | /* Ensure 'down' flag is cleared */ |
225 | UNSET_FLAG(ifc->conf, ZEBRA_IFC_DOWN); | |
226 | ||
b08dcc3f | 227 | prefix_copy(&p, CONNECTED_PREFIX(ifc)); |
d62a17ae | 228 | |
229 | /* Apply mask to the network. */ | |
230 | apply_mask(&p); | |
231 | ||
ae87977c DS |
232 | afi = family2afi(p.family); |
233 | ||
234 | switch (afi) { | |
235 | case AFI_IP: | |
236 | /* | |
237 | * In case of connected address is 0.0.0.0/0 we treat it tunnel | |
238 | * address. | |
239 | */ | |
240 | if (prefix_ipv4_any((struct prefix_ipv4 *)&p)) | |
241 | return; | |
242 | break; | |
243 | case AFI_IP6: | |
70bc8385 | 244 | #ifndef GNU_LINUX |
ae87977c DS |
245 | /* XXX: It is already done by rib_bogus_ipv6 within rib_add */ |
246 | if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6)) | |
247 | return; | |
248 | #endif | |
249 | break; | |
250 | default: | |
e914ccbe | 251 | flog_warn(EC_ZEBRA_CONNECTED_AFI_UNKNOWN, |
9df414fe | 252 | "Received unknown AFI: %s", afi2str(afi)); |
d62a17ae | 253 | return; |
ae87977c DS |
254 | break; |
255 | } | |
d62a17ae | 256 | |
cde1af84 AK |
257 | metric = (ifc->metric < (uint32_t)METRIC_MAX) ? |
258 | ifc->metric : ifp->metric; | |
d62a17ae | 259 | |
e4876266 DS |
260 | /* |
261 | * Since we are hand creating the connected routes | |
262 | * in our main routing table, *if* we are working | |
263 | * in an offloaded environment then we need to | |
264 | * pretend like the route is offloaded so everything | |
265 | * else will work | |
266 | */ | |
267 | if (zrouter.asic_offloaded) | |
268 | flags |= ZEBRA_FLAG_OFFLOADED; | |
269 | ||
92980561 DS |
270 | /* |
271 | * It's possible to add the same network and mask | |
272 | * to an interface over and over. This would | |
273 | * result in an equivalent number of connected | |
274 | * routes. Just add one connected route in | |
275 | * for all the addresses on an interface that | |
276 | * resolve to the same network and mask | |
277 | */ | |
278 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { | |
b08dcc3f | 279 | struct prefix cp; |
92980561 | 280 | |
b08dcc3f | 281 | prefix_copy(&cp, CONNECTED_PREFIX(c)); |
92980561 DS |
282 | apply_mask(&cp); |
283 | ||
e3d901f8 MS |
284 | if (prefix_same(&cp, &p) && |
285 | !CHECK_FLAG(c->conf, ZEBRA_IFC_DOWN)) | |
92980561 DS |
286 | count++; |
287 | ||
288 | if (count >= 2) | |
289 | return; | |
290 | } | |
291 | ||
e4876266 | 292 | rib_add(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0, |
c6eee91f DS |
293 | flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0, |
294 | false); | |
e4876266 DS |
295 | |
296 | rib_add(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0, | |
c6eee91f DS |
297 | flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0, |
298 | false); | |
d62a17ae | 299 | |
d62a17ae | 300 | /* Schedule LSP forwarding entries for processing, if appropriate. */ |
56e78254 | 301 | if (zvrf->vrf->vrf_id == VRF_DEFAULT) { |
2dbe669b | 302 | if (IS_ZEBRA_DEBUG_MPLS) |
996c9314 | 303 | zlog_debug( |
2dbe669b DA |
304 | "%u: IF %s IP %pFX address add/up, scheduling MPLS processing", |
305 | zvrf->vrf->vrf_id, ifp->name, &p); | |
56e78254 | 306 | mpls_mark_lsps_for_processing(zvrf, &p); |
d62a17ae | 307 | } |
718e3744 | 308 | } |
309 | ||
310 | /* Add connected IPv4 route to the interface. */ | |
9c86ee1e MS |
311 | void connected_add_ipv4(struct interface *ifp, int flags, |
312 | const struct in_addr *addr, uint16_t prefixlen, | |
313 | const struct in_addr *dest, const char *label, | |
314 | uint32_t metric) | |
718e3744 | 315 | { |
d62a17ae | 316 | struct prefix_ipv4 *p; |
317 | struct connected *ifc; | |
318 | ||
319 | if (ipv4_martian(addr)) | |
320 | return; | |
321 | ||
322 | /* Make connected structure. */ | |
323 | ifc = connected_new(); | |
324 | ifc->ifp = ifp; | |
325 | ifc->flags = flags; | |
cde1af84 | 326 | ifc->metric = metric; |
d62a17ae | 327 | /* If we get a notification from the kernel, |
328 | * we can safely assume the address is known to the kernel */ | |
329 | SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED); | |
330 | ||
331 | /* Allocate new connected address. */ | |
332 | p = prefix_ipv4_new(); | |
333 | p->family = AF_INET; | |
334 | p->prefix = *addr; | |
936fbaef DA |
335 | p->prefixlen = |
336 | CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_BITLEN : prefixlen; | |
d62a17ae | 337 | ifc->address = (struct prefix *)p; |
338 | ||
0f3af738 JW |
339 | /* If there is a peer address. */ |
340 | if (CONNECTED_PEER(ifc)) { | |
d62a17ae | 341 | /* validate the destination address */ |
0f3af738 JW |
342 | if (dest) { |
343 | p = prefix_ipv4_new(); | |
344 | p->family = AF_INET; | |
345 | p->prefix = *dest; | |
346 | p->prefixlen = prefixlen; | |
347 | ifc->destination = (struct prefix *)p; | |
348 | ||
349 | if (IPV4_ADDR_SAME(addr, dest)) | |
9df414fe | 350 | flog_warn( |
e914ccbe | 351 | EC_ZEBRA_IFACE_SAME_LOCAL_AS_PEER, |
ad6f7449 | 352 | "interface %s has same local and peer address %pI4, routing protocols may malfunction", |
9bcef951 | 353 | ifp->name, addr); |
d62a17ae | 354 | } else { |
9df414fe | 355 | zlog_debug( |
ad6f7449 | 356 | "%s called for interface %s with peer flag set, but no peer address supplied", |
d62a17ae | 357 | __func__, ifp->name); |
358 | UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER); | |
359 | } | |
e4529636 AS |
360 | } |
361 | ||
0f3af738 | 362 | /* no destination address was supplied */ |
936fbaef | 363 | if (!dest && (prefixlen == IPV4_MAX_BITLEN) && if_is_pointopoint(ifp)) |
0f3af738 | 364 | zlog_debug( |
ad6f7449 | 365 | "PtP interface %s with addr %pI4/%d needs a peer address", |
9bcef951 | 366 | ifp->name, addr, prefixlen); |
0f3af738 | 367 | |
d62a17ae | 368 | /* Label of this address. */ |
369 | if (label) | |
370 | ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label); | |
718e3744 | 371 | |
d62a17ae | 372 | /* For all that I know an IPv4 address is always ready when we receive |
373 | * the notification. So it should be safe to set the REAL flag here. */ | |
374 | SET_FLAG(ifc->conf, ZEBRA_IFC_REAL); | |
718e3744 | 375 | |
d62a17ae | 376 | connected_update(ifp, ifc); |
718e3744 | 377 | } |
378 | ||
11461c63 | 379 | void connected_down(struct interface *ifp, struct connected *ifc) |
718e3744 | 380 | { |
11461c63 | 381 | afi_t afi; |
d62a17ae | 382 | struct prefix p; |
fd36be7e | 383 | struct nexthop nh = { |
4a7371e9 DS |
384 | .type = NEXTHOP_TYPE_IFINDEX, |
385 | .ifindex = ifp->ifindex, | |
096f7609 | 386 | .vrf_id = ifp->vrf->vrf_id, |
fd36be7e | 387 | }; |
56e78254 | 388 | struct zebra_vrf *zvrf; |
92980561 DS |
389 | uint32_t count = 0; |
390 | struct listnode *cnode; | |
391 | struct connected *c; | |
56e78254 | 392 | |
096f7609 | 393 | zvrf = ifp->vrf->info; |
56e78254 | 394 | if (!zvrf) { |
15569c58 DA |
395 | flog_err( |
396 | EC_ZEBRA_VRF_NOT_FOUND, | |
096f7609 IR |
397 | "%s: Received Down for interface but no associated zvrf: %s(%d)", |
398 | __func__, ifp->vrf->name, ifp->vrf->vrf_id); | |
56e78254 DS |
399 | return; |
400 | } | |
718e3744 | 401 | |
d62a17ae | 402 | if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) |
403 | return; | |
718e3744 | 404 | |
e3d901f8 MS |
405 | /* Skip if we've already done this; this can happen if we have a |
406 | * config change that takes an interface down, then we receive kernel | |
407 | * notifications about the downed interface and its addresses. | |
408 | */ | |
409 | if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_DOWN)) { | |
410 | if (IS_ZEBRA_DEBUG_RIB) | |
411 | zlog_debug("%s: ifc %p, %pFX already DOWN", | |
412 | __func__, ifc, ifc->address); | |
413 | return; | |
414 | } | |
415 | ||
b08dcc3f | 416 | prefix_copy(&p, CONNECTED_PREFIX(ifc)); |
718e3744 | 417 | |
d62a17ae | 418 | /* Apply mask to the network. */ |
419 | apply_mask(&p); | |
718e3744 | 420 | |
11461c63 DS |
421 | afi = family2afi(p.family); |
422 | ||
423 | switch (afi) { | |
424 | case AFI_IP: | |
425 | /* | |
426 | * In case of connected address is 0.0.0.0/0 we treat it tunnel | |
427 | * address. | |
428 | */ | |
429 | if (prefix_ipv4_any((struct prefix_ipv4 *)&p)) | |
430 | return; | |
431 | break; | |
432 | case AFI_IP6: | |
433 | if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6)) | |
434 | return; | |
435 | break; | |
436 | default: | |
14a4d9d0 | 437 | zlog_warn("Unknown AFI: %s", afi2str(afi)); |
11461c63 DS |
438 | break; |
439 | } | |
718e3744 | 440 | |
e3d901f8 MS |
441 | /* Mark the address as 'down' */ |
442 | SET_FLAG(ifc->conf, ZEBRA_IFC_DOWN); | |
443 | ||
92980561 DS |
444 | /* |
445 | * It's possible to have X number of addresses | |
446 | * on a interface that all resolve to the same | |
447 | * network and mask. Find them and just | |
448 | * allow the deletion when are removing the last | |
449 | * one. | |
450 | */ | |
451 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { | |
452 | struct prefix cp; | |
453 | ||
b08dcc3f | 454 | prefix_copy(&cp, CONNECTED_PREFIX(c)); |
92980561 DS |
455 | apply_mask(&cp); |
456 | ||
e3d901f8 MS |
457 | if (prefix_same(&p, &cp) && |
458 | !CHECK_FLAG(c->conf, ZEBRA_IFC_DOWN)) | |
92980561 DS |
459 | count++; |
460 | ||
e3d901f8 | 461 | if (count >= 1) |
92980561 DS |
462 | return; |
463 | } | |
464 | ||
11461c63 DS |
465 | /* |
466 | * Same logic as for connected_up(): push the changes into the | |
467 | * head. | |
468 | */ | |
bc541126 | 469 | rib_delete(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0, |
3ceae22b | 470 | 0, &p, NULL, &nh, 0, zvrf->table_id, 0, 0, false); |
718e3744 | 471 | |
56e78254 | 472 | rib_delete(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, |
3ceae22b | 473 | 0, 0, &p, NULL, &nh, 0, zvrf->table_id, 0, 0, false); |
42cb6b66 | 474 | |
d62a17ae | 475 | /* Schedule LSP forwarding entries for processing, if appropriate. */ |
56e78254 | 476 | if (zvrf->vrf->vrf_id == VRF_DEFAULT) { |
2dbe669b | 477 | if (IS_ZEBRA_DEBUG_MPLS) |
996c9314 | 478 | zlog_debug( |
2dbe669b DA |
479 | "%u: IF %s IP %pFX address down, scheduling MPLS processing", |
480 | zvrf->vrf->vrf_id, ifp->name, &p); | |
56e78254 | 481 | mpls_mark_lsps_for_processing(zvrf, &p); |
d62a17ae | 482 | } |
718e3744 | 483 | } |
484 | ||
dc7cd304 DS |
485 | static void connected_delete_helper(struct connected *ifc, struct prefix *p) |
486 | { | |
487 | struct interface *ifp; | |
488 | ||
489 | if (!ifc) | |
490 | return; | |
491 | ifp = ifc->ifp; | |
492 | ||
493 | connected_withdraw(ifc); | |
494 | ||
dc7cd304 | 495 | /* Schedule LSP forwarding entries for processing, if appropriate. */ |
096f7609 | 496 | if (ifp->vrf->vrf_id == VRF_DEFAULT) { |
2dbe669b | 497 | if (IS_ZEBRA_DEBUG_MPLS) |
996c9314 | 498 | zlog_debug( |
2dbe669b | 499 | "%u: IF %s IP %pFX address delete, scheduling MPLS processing", |
096f7609 IR |
500 | ifp->vrf->vrf_id, ifp->name, p); |
501 | mpls_mark_lsps_for_processing(ifp->vrf->info, p); | |
dc7cd304 DS |
502 | } |
503 | } | |
504 | ||
718e3744 | 505 | /* Delete connected IPv4 route to the interface. */ |
d62a17ae | 506 | void connected_delete_ipv4(struct interface *ifp, int flags, |
9c86ee1e MS |
507 | const struct in_addr *addr, uint16_t prefixlen, |
508 | const struct in_addr *dest) | |
718e3744 | 509 | { |
dc7cd304 | 510 | struct prefix p, d; |
d62a17ae | 511 | struct connected *ifc; |
512 | ||
dc7cd304 | 513 | memset(&p, 0, sizeof(struct prefix)); |
d62a17ae | 514 | p.family = AF_INET; |
dc7cd304 | 515 | p.u.prefix4 = *addr; |
936fbaef DA |
516 | p.prefixlen = |
517 | CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_BITLEN : prefixlen; | |
abffde07 | 518 | |
0f3af738 | 519 | if (dest) { |
dc7cd304 | 520 | memset(&d, 0, sizeof(struct prefix)); |
abffde07 | 521 | d.family = AF_INET; |
0f3af738 | 522 | d.u.prefix4 = *dest; |
abffde07 | 523 | d.prefixlen = prefixlen; |
dc7cd304 | 524 | ifc = connected_check_ptp(ifp, &p, &d); |
abffde07 | 525 | } else |
dc7cd304 | 526 | ifc = connected_check_ptp(ifp, &p, NULL); |
d62a17ae | 527 | |
dc7cd304 | 528 | connected_delete_helper(ifc, &p); |
718e3744 | 529 | } |
530 | ||
718e3744 | 531 | /* Add connected IPv6 route to the interface. */ |
9c86ee1e MS |
532 | void connected_add_ipv6(struct interface *ifp, int flags, |
533 | const struct in6_addr *addr, | |
534 | const struct in6_addr *dest, uint16_t prefixlen, | |
cde1af84 | 535 | const char *label, uint32_t metric) |
718e3744 | 536 | { |
d62a17ae | 537 | struct prefix_ipv6 *p; |
538 | struct connected *ifc; | |
539 | ||
540 | if (ipv6_martian(addr)) | |
541 | return; | |
542 | ||
543 | /* Make connected structure. */ | |
544 | ifc = connected_new(); | |
545 | ifc->ifp = ifp; | |
546 | ifc->flags = flags; | |
cde1af84 | 547 | ifc->metric = metric; |
d62a17ae | 548 | /* If we get a notification from the kernel, |
549 | * we can safely assume the address is known to the kernel */ | |
550 | SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED); | |
551 | ||
552 | /* Allocate new connected address. */ | |
553 | p = prefix_ipv6_new(); | |
554 | p->family = AF_INET6; | |
555 | IPV6_ADDR_COPY(&p->prefix, addr); | |
556 | p->prefixlen = prefixlen; | |
557 | ifc->address = (struct prefix *)p; | |
558 | ||
2a855763 DS |
559 | /* Add global ipv6 address to the RA prefix list */ |
560 | if (!IN6_IS_ADDR_LINKLOCAL(&p->prefix)) | |
561 | rtadv_add_prefix(ifp->info, p); | |
562 | ||
0f3af738 | 563 | if (dest) { |
60c0687a DS |
564 | p = prefix_ipv6_new(); |
565 | p->family = AF_INET6; | |
0f3af738 | 566 | IPV6_ADDR_COPY(&p->prefix, dest); |
60c0687a DS |
567 | p->prefixlen = prefixlen; |
568 | ifc->destination = (struct prefix *)p; | |
f52d0a1a DS |
569 | } else { |
570 | if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER)) { | |
9df414fe | 571 | zlog_debug( |
ad6f7449 | 572 | "%s called for interface %s with peer flag set, but no peer address supplied", |
9df414fe | 573 | __func__, ifp->name); |
f52d0a1a DS |
574 | UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER); |
575 | } | |
60c0687a DS |
576 | } |
577 | ||
d62a17ae | 578 | /* Label of this address. */ |
579 | if (label) | |
580 | ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label); | |
581 | ||
582 | /* On Linux, we only get here when DAD is complete, therefore we can set | |
583 | * ZEBRA_IFC_REAL. | |
584 | * | |
585 | * On BSD, there currently doesn't seem to be a way to check for | |
586 | * completion of | |
587 | * DAD, so we replicate the old behaviour and set ZEBRA_IFC_REAL, | |
588 | * although DAD | |
589 | * might still be running. | |
590 | */ | |
591 | SET_FLAG(ifc->conf, ZEBRA_IFC_REAL); | |
592 | connected_update(ifp, ifc); | |
718e3744 | 593 | } |
594 | ||
9c86ee1e MS |
595 | void connected_delete_ipv6(struct interface *ifp, |
596 | const struct in6_addr *address, | |
597 | const struct in6_addr *dest, uint16_t prefixlen) | |
718e3744 | 598 | { |
60c0687a | 599 | struct prefix p, d; |
d62a17ae | 600 | struct connected *ifc; |
601 | ||
dc7cd304 | 602 | memset(&p, 0, sizeof(struct prefix)); |
d62a17ae | 603 | p.family = AF_INET6; |
dc7cd304 | 604 | memcpy(&p.u.prefix6, address, sizeof(struct in6_addr)); |
d62a17ae | 605 | p.prefixlen = prefixlen; |
606 | ||
2a855763 DS |
607 | /* Delete global ipv6 address from RA prefix list */ |
608 | if (!IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) | |
609 | rtadv_delete_prefix(ifp->info, &p); | |
610 | ||
0f3af738 | 611 | if (dest) { |
60c0687a DS |
612 | memset(&d, 0, sizeof(struct prefix)); |
613 | d.family = AF_INET6; | |
0f3af738 | 614 | IPV6_ADDR_COPY(&d.u.prefix6, dest); |
60c0687a DS |
615 | d.prefixlen = prefixlen; |
616 | ifc = connected_check_ptp(ifp, &p, &d); | |
617 | } else | |
618 | ifc = connected_check_ptp(ifp, &p, NULL); | |
d62a17ae | 619 | |
dc7cd304 | 620 | connected_delete_helper(ifc, &p); |
718e3744 | 621 | } |
d44ca835 | 622 | |
d62a17ae | 623 | int connected_is_unnumbered(struct interface *ifp) |
d44ca835 | 624 | { |
d62a17ae | 625 | struct connected *connected; |
626 | struct listnode *node; | |
627 | ||
628 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { | |
629 | if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) | |
630 | && connected->address->family == AF_INET) | |
631 | return CHECK_FLAG(connected->flags, | |
632 | ZEBRA_IFA_UNNUMBERED); | |
633 | } | |
a79fdd65 | 634 | return 0; |
d44ca835 | 635 | } |