]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * Interface function. | |
3 | * Copyright (C) 1997, 1999 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 "if.h" | |
26 | #include "vty.h" | |
27 | #include "sockunion.h" | |
28 | #include "prefix.h" | |
29 | #include "command.h" | |
30 | #include "memory.h" | |
31 | #include "ioctl.h" | |
32 | #include "connected.h" | |
33 | #include "log.h" | |
34 | #include "zclient.h" | |
cd2a8a42 | 35 | #include "vrf.h" |
718e3744 | 36 | |
37 | #include "zebra/interface.h" | |
38 | #include "zebra/rtadv.h" | |
39 | #include "zebra/rib.h" | |
40 | #include "zebra/zserv.h" | |
41 | #include "zebra/redistribute.h" | |
42 | #include "zebra/debug.h" | |
ca776988 | 43 | #include "zebra/irdp.h" |
244c1cdc | 44 | #include "zebra/zebra_ptm.h" |
5c610faf | 45 | #include "zebra/rt_netlink.h" |
a197c47c | 46 | #include "zebra/zserv.h" |
88177fe3 | 47 | #include "zebra/interface.h" |
244c1cdc DS |
48 | |
49 | #define ZEBRA_PTM_SUPPORT | |
718e3744 | 50 | |
8da4e946 | 51 | #if defined (HAVE_RTADV) |
b60668d0 CC |
52 | /* Order is intentional. Matches RFC4191. This array is also used for |
53 | command matching, so only modify with care. */ | |
54 | const char *rtadv_pref_strs[] = { "medium", "high", "INVALID", "low", 0 }; | |
8da4e946 | 55 | #endif /* HAVE_RTADV */ |
718e3744 | 56 | |
c8e264b6 | 57 | static void if_down_del_nbr_connected (struct interface *ifp); |
58 | ||
12f6fb97 DS |
59 | struct zebra_ns *dzns; |
60 | ||
718e3744 | 61 | /* Called when new interface is added. */ |
a1ac18c4 | 62 | static int |
718e3744 | 63 | if_zebra_new_hook (struct interface *ifp) |
64 | { | |
65 | struct zebra_if *zebra_if; | |
66 | ||
393deb9b | 67 | zebra_if = XCALLOC (MTYPE_TMP, sizeof (struct zebra_if)); |
718e3744 | 68 | |
69 | zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC; | |
bfac8dcd | 70 | zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF; |
718e3744 | 71 | |
c8ed14dd | 72 | ifp->ptm_enable = zebra_ptm_get_enable_state(); |
8da4e946 | 73 | #if defined (HAVE_RTADV) |
718e3744 | 74 | { |
75 | /* Set default router advertise values. */ | |
76 | struct rtadvconf *rtadv; | |
77 | ||
78 | rtadv = &zebra_if->rtadv; | |
79 | ||
80 | rtadv->AdvSendAdvertisements = 0; | |
81 | rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL; | |
82 | rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL; | |
83 | rtadv->AdvIntervalTimer = 0; | |
84 | rtadv->AdvManagedFlag = 0; | |
85 | rtadv->AdvOtherConfigFlag = 0; | |
7cee1bb1 | 86 | rtadv->AdvHomeAgentFlag = 0; |
718e3744 | 87 | rtadv->AdvLinkMTU = 0; |
88 | rtadv->AdvReachableTime = 0; | |
89 | rtadv->AdvRetransTimer = 0; | |
90 | rtadv->AdvCurHopLimit = 0; | |
d660f698 | 91 | rtadv->AdvDefaultLifetime = -1; /* derive from MaxRtrAdvInterval */ |
7cee1bb1 | 92 | rtadv->HomeAgentPreference = 0; |
d660f698 | 93 | rtadv->HomeAgentLifetime = -1; /* derive from AdvDefaultLifetime */ |
7cee1bb1 | 94 | rtadv->AdvIntervalOption = 0; |
b60668d0 | 95 | rtadv->DefaultPreference = RTADV_PREF_MEDIUM; |
718e3744 | 96 | |
97 | rtadv->AdvPrefixList = list_new (); | |
98 | } | |
8da4e946 | 99 | #endif /* HAVE_RTADV */ |
718e3744 | 100 | |
eef1fe11 | 101 | /* Initialize installed address chains tree. */ |
102 | zebra_if->ipv4_subnets = route_table_init (); | |
103 | ||
718e3744 | 104 | ifp->info = zebra_if; |
105 | return 0; | |
106 | } | |
107 | ||
108 | /* Called when interface is deleted. */ | |
a1ac18c4 | 109 | static int |
718e3744 | 110 | if_zebra_delete_hook (struct interface *ifp) |
111 | { | |
eef1fe11 | 112 | struct zebra_if *zebra_if; |
113 | ||
718e3744 | 114 | if (ifp->info) |
eef1fe11 | 115 | { |
116 | zebra_if = ifp->info; | |
117 | ||
118 | /* Free installed address chains tree. */ | |
119 | if (zebra_if->ipv4_subnets) | |
120 | route_table_finish (zebra_if->ipv4_subnets); | |
121 | ||
122 | XFREE (MTYPE_TMP, zebra_if); | |
123 | } | |
124 | ||
125 | return 0; | |
126 | } | |
127 | ||
12f6fb97 DS |
128 | /* Build the table key */ |
129 | static void | |
130 | if_build_key (u_int32_t ifindex, struct prefix *p) | |
131 | { | |
132 | p->family = AF_INET; | |
133 | p->prefixlen = IPV4_MAX_BITLEN; | |
134 | p->u.prefix4.s_addr = ifindex; | |
135 | } | |
136 | ||
137 | /* Link an interface in a per NS interface tree */ | |
138 | struct interface * | |
139 | if_link_per_ns (struct zebra_ns *ns, struct interface *ifp) | |
140 | { | |
141 | struct prefix p; | |
142 | struct route_node *rn; | |
143 | ||
144 | if (ifp->ifindex == IFINDEX_INTERNAL) | |
145 | return NULL; | |
146 | ||
147 | if_build_key (ifp->ifindex, &p); | |
148 | rn = route_node_get (ns->if_table, &p); | |
149 | if (rn->info) | |
150 | { | |
151 | ifp = (struct interface *)rn->info; | |
152 | route_unlock_node (rn); /* get */ | |
153 | return ifp; | |
154 | } | |
155 | ||
156 | rn->info = ifp; | |
157 | ifp->node = rn; | |
158 | ||
159 | return ifp; | |
160 | } | |
161 | ||
162 | /* Delete a VRF. This is called in vrf_terminate(). */ | |
163 | void | |
164 | if_unlink_per_ns (struct interface *ifp) | |
165 | { | |
166 | ifp->node->info = NULL; | |
167 | route_unlock_node(ifp->node); | |
168 | } | |
169 | ||
170 | /* Look up an interface by identifier within a NS */ | |
171 | struct interface * | |
172 | if_lookup_by_index_per_ns (struct zebra_ns *ns, u_int32_t ifindex) | |
173 | { | |
174 | struct prefix p; | |
175 | struct route_node *rn; | |
176 | struct interface *ifp = NULL; | |
177 | ||
178 | if_build_key (ifindex, &p); | |
179 | rn = route_node_lookup (ns->if_table, &p); | |
180 | if (rn) | |
181 | { | |
182 | ifp = (struct interface *)rn->info; | |
183 | route_unlock_node (rn); /* lookup */ | |
184 | } | |
185 | return ifp; | |
186 | } | |
187 | ||
a815b788 | 188 | const char * |
189 | ifindex2ifname_per_ns (struct zebra_ns *zns, unsigned int ifindex) | |
190 | { | |
191 | struct interface *ifp; | |
192 | ||
193 | return ((ifp = if_lookup_by_index_per_ns (zns, ifindex)) != NULL) ? | |
194 | ifp->name : "unknown"; | |
195 | } | |
12f6fb97 | 196 | |
eef1fe11 | 197 | /* Tie an interface address to its derived subnet list of addresses. */ |
198 | int | |
199 | if_subnet_add (struct interface *ifp, struct connected *ifc) | |
200 | { | |
201 | struct route_node *rn; | |
202 | struct zebra_if *zebra_if; | |
203 | struct prefix cp; | |
204 | struct list *addr_list; | |
205 | ||
206 | assert (ifp && ifp->info && ifc); | |
207 | zebra_if = ifp->info; | |
208 | ||
209 | /* Get address derived subnet node and associated address list, while marking | |
210 | address secondary attribute appropriately. */ | |
211 | cp = *ifc->address; | |
212 | apply_mask (&cp); | |
213 | rn = route_node_get (zebra_if->ipv4_subnets, &cp); | |
214 | ||
215 | if ((addr_list = rn->info)) | |
216 | SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); | |
217 | else | |
218 | { | |
219 | UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); | |
220 | rn->info = addr_list = list_new (); | |
221 | route_lock_node (rn); | |
222 | } | |
223 | ||
224 | /* Tie address at the tail of address list. */ | |
225 | listnode_add (addr_list, ifc); | |
226 | ||
227 | /* Return list element count. */ | |
228 | return (addr_list->count); | |
229 | } | |
230 | ||
231 | /* Untie an interface address from its derived subnet list of addresses. */ | |
232 | int | |
233 | if_subnet_delete (struct interface *ifp, struct connected *ifc) | |
234 | { | |
235 | struct route_node *rn; | |
236 | struct zebra_if *zebra_if; | |
237 | struct list *addr_list; | |
238 | ||
239 | assert (ifp && ifp->info && ifc); | |
240 | zebra_if = ifp->info; | |
241 | ||
242 | /* Get address derived subnet node. */ | |
243 | rn = route_node_lookup (zebra_if->ipv4_subnets, ifc->address); | |
244 | if (! (rn && rn->info)) | |
9db047fc CF |
245 | { |
246 | zlog_warn("Trying to remove an address from an unknown subnet." | |
247 | " (please report this bug)"); | |
248 | return -1; | |
249 | } | |
eef1fe11 | 250 | route_unlock_node (rn); |
251 | ||
252 | /* Untie address from subnet's address list. */ | |
253 | addr_list = rn->info; | |
9db047fc CF |
254 | |
255 | /* Deleting an address that is not registered is a bug. | |
256 | * In any case, we shouldn't decrement the lock counter if the address | |
257 | * is unknown. */ | |
258 | if (!listnode_lookup(addr_list, ifc)) | |
259 | { | |
260 | zlog_warn("Trying to remove an address from a subnet where it is not" | |
261 | " currently registered. (please report this bug)"); | |
262 | return -1; | |
263 | } | |
264 | ||
eef1fe11 | 265 | listnode_delete (addr_list, ifc); |
266 | route_unlock_node (rn); | |
267 | ||
268 | /* Return list element count, if not empty. */ | |
269 | if (addr_list->count) | |
270 | { | |
271 | /* If deleted address is primary, mark subsequent one as such and distribute. */ | |
272 | if (! CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY)) | |
273 | { | |
1eb8ef25 | 274 | ifc = listgetdata (listhead (addr_list)); |
eef1fe11 | 275 | zebra_interface_address_delete_update (ifp, ifc); |
276 | UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); | |
02b4805f CF |
277 | /* XXX: Linux kernel removes all the secondary addresses when the primary |
278 | * address is removed. We could try to work around that, though this is | |
279 | * non-trivial. */ | |
eef1fe11 | 280 | zebra_interface_address_add_update (ifp, ifc); |
281 | } | |
282 | ||
283 | return addr_list->count; | |
284 | } | |
285 | ||
286 | /* Otherwise, free list and route node. */ | |
287 | list_free (addr_list); | |
288 | rn->info = NULL; | |
289 | route_unlock_node (rn); | |
290 | ||
718e3744 | 291 | return 0; |
292 | } | |
293 | ||
5c78b3d0 | 294 | /* if_flags_mangle: A place for hacks that require mangling |
295 | * or tweaking the interface flags. | |
296 | * | |
297 | * ******************** Solaris flags hacks ************************** | |
298 | * | |
299 | * Solaris IFF_UP flag reflects only the primary interface as the | |
300 | * routing socket only sends IFINFO for the primary interface. Hence | |
301 | * ~IFF_UP does not per se imply all the logical interfaces are also | |
302 | * down - which we only know of as addresses. Instead we must determine | |
303 | * whether the interface really is up or not according to how many | |
304 | * addresses are still attached. (Solaris always sends RTM_DELADDR if | |
305 | * an interface, logical or not, goes ~IFF_UP). | |
306 | * | |
307 | * Ie, we mangle IFF_UP to *additionally* reflect whether or not there | |
308 | * are addresses left in struct connected, not just the actual underlying | |
309 | * IFF_UP flag. | |
310 | * | |
311 | * We must hence remember the real state of IFF_UP, which we do in | |
312 | * struct zebra_if.primary_state. | |
313 | * | |
314 | * Setting IFF_UP within zebra to administratively shutdown the | |
315 | * interface will affect only the primary interface/address on Solaris. | |
316 | ************************End Solaris flags hacks *********************** | |
317 | */ | |
f63f06da | 318 | static void |
5c78b3d0 | 319 | if_flags_mangle (struct interface *ifp, uint64_t *newflags) |
320 | { | |
321 | #ifdef SUNOS_5 | |
322 | struct zebra_if *zif = ifp->info; | |
323 | ||
324 | zif->primary_state = *newflags & (IFF_UP & 0xff); | |
325 | ||
326 | if (CHECK_FLAG (zif->primary_state, IFF_UP) | |
327 | || listcount(ifp->connected) > 0) | |
328 | SET_FLAG (*newflags, IFF_UP); | |
329 | else | |
330 | UNSET_FLAG (*newflags, IFF_UP); | |
331 | #endif /* SUNOS_5 */ | |
332 | } | |
333 | ||
334 | /* Update the flags field of the ifp with the new flag set provided. | |
335 | * Take whatever actions are required for any changes in flags we care | |
336 | * about. | |
337 | * | |
338 | * newflags should be the raw value, as obtained from the OS. | |
339 | */ | |
340 | void | |
341 | if_flags_update (struct interface *ifp, uint64_t newflags) | |
342 | { | |
343 | if_flags_mangle (ifp, &newflags); | |
344 | ||
244c1cdc | 345 | if (if_is_no_ptm_operative (ifp)) |
5c78b3d0 | 346 | { |
347 | /* operative -> inoperative? */ | |
348 | ifp->flags = newflags; | |
349 | if (!if_is_operative (ifp)) | |
350 | if_down (ifp); | |
351 | } | |
352 | else | |
353 | { | |
354 | /* inoperative -> operative? */ | |
355 | ifp->flags = newflags; | |
356 | if (if_is_operative (ifp)) | |
357 | if_up (ifp); | |
358 | } | |
359 | } | |
360 | ||
718e3744 | 361 | /* Wake up configured address if it is not in current kernel |
362 | address. */ | |
a1ac18c4 | 363 | static void |
718e3744 | 364 | if_addr_wakeup (struct interface *ifp) |
365 | { | |
1eb8ef25 | 366 | struct listnode *node, *nnode; |
718e3744 | 367 | struct connected *ifc; |
368 | struct prefix *p; | |
369 | int ret; | |
370 | ||
1eb8ef25 | 371 | for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc)) |
718e3744 | 372 | { |
718e3744 | 373 | p = ifc->address; |
374 | ||
375 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED) | |
f7f740fe | 376 | && ! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)) |
718e3744 | 377 | { |
378 | /* Address check. */ | |
379 | if (p->family == AF_INET) | |
380 | { | |
381 | if (! if_is_up (ifp)) | |
382 | { | |
02b4805f CF |
383 | /* Assume zebra is configured like following: |
384 | * | |
385 | * interface gre0 | |
386 | * ip addr 192.0.2.1/24 | |
387 | * ! | |
388 | * | |
389 | * As soon as zebra becomes first aware that gre0 exists in the | |
390 | * kernel, it will set gre0 up and configure its addresses. | |
391 | * | |
392 | * (This may happen at startup when the interface already exists | |
393 | * or during runtime when the interface is added to the kernel) | |
394 | * | |
395 | * XXX: IRDP code is calling here via if_add_update - this seems | |
396 | * somewhat weird. | |
397 | * XXX: RUNNING is not a settable flag on any system | |
398 | * I (paulj) am aware of. | |
399 | */ | |
718e3744 | 400 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
401 | if_refresh (ifp); | |
402 | } | |
403 | ||
404 | ret = if_set_prefix (ifp, ifc); | |
405 | if (ret < 0) | |
406 | { | |
407 | zlog_warn ("Can't set interface's address: %s", | |
6099b3b5 | 408 | safe_strerror(errno)); |
718e3744 | 409 | continue; |
410 | } | |
eef1fe11 | 411 | |
f7f740fe | 412 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
413 | /* The address will be advertised to zebra clients when the notification |
414 | * from the kernel has been received. | |
415 | * It will also be added to the interface's subnet list then. */ | |
718e3744 | 416 | } |
417 | #ifdef HAVE_IPV6 | |
418 | if (p->family == AF_INET6) | |
419 | { | |
420 | if (! if_is_up (ifp)) | |
421 | { | |
02b4805f | 422 | /* See long comment above */ |
718e3744 | 423 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
424 | if_refresh (ifp); | |
425 | } | |
426 | ||
427 | ret = if_prefix_add_ipv6 (ifp, ifc); | |
428 | if (ret < 0) | |
429 | { | |
430 | zlog_warn ("Can't set interface's address: %s", | |
6099b3b5 | 431 | safe_strerror(errno)); |
718e3744 | 432 | continue; |
433 | } | |
718e3744 | 434 | |
02b4805f CF |
435 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
436 | /* The address will be advertised to zebra clients when the notification | |
437 | * from the kernel has been received. */ | |
718e3744 | 438 | } |
439 | #endif /* HAVE_IPV6 */ | |
440 | } | |
441 | } | |
442 | } | |
443 | ||
444 | /* Handle interface addition */ | |
445 | void | |
446 | if_add_update (struct interface *ifp) | |
447 | { | |
48b33aaf | 448 | struct zebra_if *if_data; |
449 | ||
12f6fb97 DS |
450 | if_link_per_ns(dzns, ifp); |
451 | ||
48b33aaf | 452 | if_data = ifp->info; |
453 | if (if_data->multicast == IF_ZEBRA_MULTICAST_ON) | |
454 | if_set_flags (ifp, IFF_MULTICAST); | |
455 | else if (if_data->multicast == IF_ZEBRA_MULTICAST_OFF) | |
456 | if_unset_flags (ifp, IFF_MULTICAST); | |
457 | ||
718e3744 | 458 | zebra_interface_add_update (ifp); |
459 | ||
460 | if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) | |
461 | { | |
462 | SET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); | |
463 | ||
bfac8dcd CF |
464 | if (if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) |
465 | { | |
466 | if (IS_ZEBRA_DEBUG_KERNEL) | |
3968dbf8 FL |
467 | zlog_debug ("interface %s vrf %u index %d is shutdown. " |
468 | "Won't wake it up.", | |
469 | ifp->name, ifp->vrf_id, ifp->ifindex); | |
bfac8dcd CF |
470 | return; |
471 | } | |
472 | ||
718e3744 | 473 | if_addr_wakeup (ifp); |
474 | ||
475 | if (IS_ZEBRA_DEBUG_KERNEL) | |
3968dbf8 FL |
476 | zlog_debug ("interface %s vrf %u index %d becomes active.", |
477 | ifp->name, ifp->vrf_id, ifp->ifindex); | |
718e3744 | 478 | } |
479 | else | |
480 | { | |
481 | if (IS_ZEBRA_DEBUG_KERNEL) | |
3968dbf8 FL |
482 | zlog_debug ("interface %s vrf %u index %d is added.", |
483 | ifp->name, ifp->vrf_id, ifp->ifindex); | |
718e3744 | 484 | } |
485 | } | |
486 | ||
c8e264b6 | 487 | /* Install connected routes corresponding to an interface. */ |
488 | static void | |
489 | if_install_connected (struct interface *ifp) | |
718e3744 | 490 | { |
c8e264b6 | 491 | struct listnode *node; |
492 | struct listnode *next; | |
718e3744 | 493 | struct connected *ifc; |
494 | struct prefix *p; | |
eef1fe11 | 495 | |
c8e264b6 | 496 | if (ifp->connected) |
497 | { | |
498 | for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) | |
499 | { | |
500 | p = ifc->address; | |
718e3744 | 501 | |
c8e264b6 | 502 | if (p->family == AF_INET) |
503 | connected_up_ipv4 (ifp, ifc); | |
504 | else if (p->family == AF_INET6) | |
505 | connected_up_ipv6 (ifp, ifc); | |
506 | } | |
507 | } | |
508 | } | |
509 | ||
510 | /* Uninstall connected routes corresponding to an interface. */ | |
511 | static void | |
512 | if_uninstall_connected (struct interface *ifp) | |
513 | { | |
514 | struct listnode *node; | |
515 | struct listnode *next; | |
516 | struct connected *ifc; | |
517 | struct prefix *p; | |
518 | ||
519 | if (ifp->connected) | |
718e3744 | 520 | { |
c8e264b6 | 521 | for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) |
522 | { | |
523 | p = ifc->address; | |
524 | ||
525 | if (p->family == AF_INET) | |
526 | connected_down_ipv4 (ifp, ifc); | |
527 | else if (p->family == AF_INET6) | |
528 | connected_down_ipv6 (ifp, ifc); | |
529 | } | |
718e3744 | 530 | } |
c8e264b6 | 531 | } |
718e3744 | 532 | |
c8e264b6 | 533 | /* Uninstall and delete connected routes corresponding to an interface. */ |
534 | /* TODO - Check why IPv4 handling here is different from install or if_down */ | |
535 | static void | |
536 | if_delete_connected (struct interface *ifp) | |
537 | { | |
538 | struct connected *ifc; | |
539 | struct prefix *p; | |
540 | struct route_node *rn; | |
541 | struct zebra_if *zebra_if; | |
542 | ||
543 | zebra_if = ifp->info; | |
718e3744 | 544 | |
718e3744 | 545 | if (ifp->connected) |
546 | { | |
d9a18f11 PJ |
547 | struct listnode *node; |
548 | struct listnode *last = NULL; | |
549 | ||
eef1fe11 | 550 | while ((node = (last ? last->next : listhead (ifp->connected)))) |
718e3744 | 551 | { |
1eb8ef25 | 552 | ifc = listgetdata (node); |
718e3744 | 553 | p = ifc->address; |
eef1fe11 | 554 | |
beb56336 PJ |
555 | if (p->family == AF_INET |
556 | && (rn = route_node_lookup (zebra_if->ipv4_subnets, p))) | |
eef1fe11 | 557 | { |
d9a18f11 PJ |
558 | struct listnode *anode; |
559 | struct listnode *next; | |
560 | struct listnode *first; | |
561 | struct list *addr_list; | |
562 | ||
eef1fe11 | 563 | route_unlock_node (rn); |
564 | addr_list = (struct list *) rn->info; | |
565 | ||
566 | /* Remove addresses, secondaries first. */ | |
567 | first = listhead (addr_list); | |
d9a18f11 | 568 | for (anode = first->next; anode || first; anode = next) |
eef1fe11 | 569 | { |
d9a18f11 | 570 | if (!anode) |
eef1fe11 | 571 | { |
d9a18f11 | 572 | anode = first; |
eef1fe11 | 573 | first = NULL; |
574 | } | |
d9a18f11 | 575 | next = anode->next; |
eef1fe11 | 576 | |
d9a18f11 | 577 | ifc = listgetdata (anode); |
eef1fe11 | 578 | p = ifc->address; |
eef1fe11 | 579 | connected_down_ipv4 (ifp, ifc); |
580 | ||
02b4805f CF |
581 | /* XXX: We have to send notifications here explicitly, because we destroy |
582 | * the ifc before receiving the notification about the address being deleted. | |
583 | */ | |
eef1fe11 | 584 | zebra_interface_address_delete_update (ifp, ifc); |
585 | ||
586 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); | |
f7f740fe | 587 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
eef1fe11 | 588 | |
589 | /* Remove from subnet chain. */ | |
d9a18f11 | 590 | list_delete_node (addr_list, anode); |
eef1fe11 | 591 | route_unlock_node (rn); |
592 | ||
593 | /* Remove from interface address list (unconditionally). */ | |
d9a18f11 PJ |
594 | if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
595 | { | |
596 | listnode_delete (ifp->connected, ifc); | |
597 | connected_free (ifc); | |
598 | } | |
599 | else | |
600 | last = node; | |
eef1fe11 | 601 | } |
602 | ||
603 | /* Free chain list and respective route node. */ | |
604 | list_delete (addr_list); | |
605 | rn->info = NULL; | |
606 | route_unlock_node (rn); | |
607 | } | |
718e3744 | 608 | else if (p->family == AF_INET6) |
eef1fe11 | 609 | { |
610 | connected_down_ipv6 (ifp, ifc); | |
718e3744 | 611 | |
eef1fe11 | 612 | zebra_interface_address_delete_update (ifp, ifc); |
718e3744 | 613 | |
eef1fe11 | 614 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
f7f740fe | 615 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
eef1fe11 | 616 | |
617 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
618 | last = node; | |
619 | else | |
620 | { | |
621 | listnode_delete (ifp->connected, ifc); | |
622 | connected_free (ifc); | |
623 | } | |
718e3744 | 624 | } |
e26873fd RHA |
625 | else |
626 | { | |
627 | last = node; | |
628 | } | |
718e3744 | 629 | } |
630 | } | |
c8e264b6 | 631 | } |
632 | ||
633 | /* Handle an interface delete event */ | |
634 | void | |
635 | if_delete_update (struct interface *ifp) | |
636 | { | |
637 | if (if_is_up(ifp)) | |
638 | { | |
639 | zlog_err ("interface %s vrf %u index %d is still up while being deleted.", | |
640 | ifp->name, ifp->vrf_id, ifp->ifindex); | |
641 | return; | |
642 | } | |
643 | ||
644 | /* Mark interface as inactive */ | |
645 | UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); | |
646 | ||
647 | if (IS_ZEBRA_DEBUG_KERNEL) | |
648 | zlog_debug ("interface %s vrf %u index %d is now inactive.", | |
649 | ifp->name, ifp->vrf_id, ifp->ifindex); | |
650 | ||
651 | /* Delete connected routes from the kernel. */ | |
652 | if_delete_connected (ifp); | |
653 | ||
654 | /* Send out notification on interface delete. */ | |
718e3744 | 655 | zebra_interface_delete_update (ifp); |
d2fc8896 | 656 | |
12f6fb97 DS |
657 | if_unlink_per_ns(ifp); |
658 | ||
d2fc8896 | 659 | /* Update ifindex after distributing the delete message. This is in |
660 | case any client needs to have the old value of ifindex available | |
661 | while processing the deletion. Each client daemon is responsible | |
662 | for setting ifindex to IFINDEX_INTERNAL after processing the | |
663 | interface deletion message. */ | |
664 | ifp->ifindex = IFINDEX_INTERNAL; | |
718e3744 | 665 | } |
666 | ||
c8e264b6 | 667 | /* VRF change for an interface */ |
668 | void | |
669 | if_handle_vrf_change (struct interface *ifp, vrf_id_t vrf_id) | |
670 | { | |
671 | vrf_id_t old_vrf_id; | |
672 | ||
673 | old_vrf_id = ifp->vrf_id; | |
674 | ||
675 | /* Uninstall connected routes. */ | |
676 | if_uninstall_connected (ifp); | |
677 | ||
678 | /* Delete any IPv4 neighbors created to implement RFC 5549 */ | |
679 | if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp); | |
680 | ||
681 | /* Delete all neighbor addresses learnt through IPv6 RA */ | |
682 | if_down_del_nbr_connected (ifp); | |
683 | ||
684 | /* Suppress RAs on this interface, if enabled. */ | |
685 | ipv6_nd_suppress_ra_set (ifp, RA_SUPPRESS); | |
686 | ||
687 | /* Send out notification on interface VRF change. */ | |
688 | /* This is to issue an UPDATE or a DELETE, as appropriate. */ | |
689 | zebra_interface_vrf_update_del (ifp, vrf_id); | |
690 | ||
691 | /* update VRF */ | |
692 | if_update_vrf (ifp, ifp->name, strlen (ifp->name), vrf_id); | |
693 | ||
694 | /* Send out notification on interface VRF change. */ | |
695 | /* This is to issue an ADD, if needed. */ | |
696 | zebra_interface_vrf_update_add (ifp, old_vrf_id); | |
697 | ||
698 | /* Install connected routes (in new VRF). */ | |
699 | if_install_connected (ifp); | |
700 | ||
701 | /* Enable RAs on this interface, if IPv6 addresses are present. */ | |
702 | if (ipv6_address_configured(ifp)) | |
703 | ipv6_nd_suppress_ra_set (ifp, RA_ENABLE); | |
704 | ||
705 | /* Due to connected route change, schedule RIB processing for both old | |
706 | * and new VRF. | |
707 | */ | |
708 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) | |
709 | zlog_debug ("%u: IF %s VRF change, scheduling RIB processing", | |
710 | ifp->vrf_id, ifp->name); | |
711 | rib_update (old_vrf_id, RIB_UPDATE_IF_CHANGE); | |
712 | rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); | |
713 | } | |
714 | ||
715 | ||
12f6fb97 DS |
716 | /* Handle VRF addition */ |
717 | void | |
718 | vrf_add_update (struct vrf *vrfp) | |
719 | { | |
720 | zebra_vrf_add_update (vrfp); | |
721 | ||
722 | if (! CHECK_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE)) | |
723 | { | |
724 | SET_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE); | |
725 | ||
726 | //Pending: Check if the equivalent of if_addr_wakeup (ifp) is needed here. | |
727 | ||
728 | if (IS_ZEBRA_DEBUG_KERNEL) | |
729 | zlog_debug ("VRF %s id %u becomes active.", | |
730 | vrfp->name, vrfp->vrf_id); | |
731 | } | |
732 | else | |
733 | { | |
734 | if (IS_ZEBRA_DEBUG_KERNEL) | |
735 | zlog_debug ("VRF %s id %u is added.", | |
736 | vrfp->name, vrfp->vrf_id); | |
737 | } | |
738 | } | |
739 | ||
740 | /* Handle an interface delete event */ | |
741 | void | |
742 | vrf_delete_update (struct vrf *vrfp) | |
743 | { | |
744 | /* Mark VRF as inactive */ | |
745 | UNSET_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE); | |
746 | ||
747 | if (IS_ZEBRA_DEBUG_KERNEL) | |
748 | zlog_debug ("VRF %s id %u is now inactive.", | |
749 | vrfp->name, vrfp->vrf_id); | |
750 | ||
751 | zebra_vrf_delete_update (vrfp); | |
752 | ||
753 | /* Pending: Update ifindex after distributing the delete message. This is in | |
754 | case any client needs to have the old value of ifindex available | |
755 | while processing the deletion. Each client daemon is responsible | |
756 | for setting vrf-id to IFINDEX_INTERNAL after processing the | |
757 | interface deletion message. */ | |
758 | vrfp->vrf_id = 0; | |
759 | } | |
760 | ||
761 | ||
88177fe3 | 762 | static void |
5c610faf DS |
763 | ipv6_ll_address_to_mac (struct in6_addr *address, u_char *mac) |
764 | { | |
eb4b1830 | 765 | mac[0] = address->s6_addr[8] ^ 0x02; |
5c610faf DS |
766 | mac[1] = address->s6_addr[9]; |
767 | mac[2] = address->s6_addr[10]; | |
768 | mac[3] = address->s6_addr[13]; | |
769 | mac[4] = address->s6_addr[14]; | |
770 | mac[5] = address->s6_addr[15]; | |
771 | } | |
772 | ||
773 | void | |
774 | if_nbr_ipv6ll_to_ipv4ll_neigh_update (struct interface *ifp, | |
775 | struct in6_addr *address, | |
776 | int add) | |
777 | { | |
778 | char buf[16] = "169.254.0.1"; | |
779 | struct in_addr ipv4_ll; | |
88177fe3 | 780 | char mac[6]; |
5c610faf DS |
781 | |
782 | inet_pton (AF_INET, buf, &ipv4_ll); | |
783 | ||
88177fe3 | 784 | ipv6_ll_address_to_mac(address, (u_char *)mac); |
5c610faf DS |
785 | netlink_neigh_update (add ? RTM_NEWNEIGH : RTM_DELNEIGH, |
786 | ifp->ifindex, ipv4_ll.s_addr, mac, 6); | |
787 | } | |
788 | ||
88177fe3 | 789 | static void |
5c610faf DS |
790 | if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (struct interface *ifp) |
791 | { | |
792 | if (listhead(ifp->nbr_connected)) | |
793 | { | |
794 | struct nbr_connected *nbr_connected; | |
795 | struct listnode *node; | |
796 | ||
797 | for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected)) | |
798 | if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp, | |
799 | &nbr_connected->address->u.prefix6, | |
800 | 1); | |
801 | } | |
802 | } | |
803 | ||
804 | void | |
805 | if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (struct interface *ifp) | |
806 | { | |
807 | if (listhead(ifp->nbr_connected)) | |
808 | { | |
809 | struct nbr_connected *nbr_connected; | |
810 | struct listnode *node; | |
811 | ||
812 | for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected)) | |
813 | if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp, | |
814 | &nbr_connected->address->u.prefix6, | |
815 | 0); | |
816 | } | |
817 | } | |
818 | ||
88177fe3 | 819 | static void |
a197c47c DS |
820 | if_down_del_nbr_connected (struct interface *ifp) |
821 | { | |
822 | struct nbr_connected *nbr_connected; | |
823 | struct listnode *node, *nnode; | |
824 | ||
825 | for (ALL_LIST_ELEMENTS (ifp->nbr_connected, node, nnode, nbr_connected)) | |
826 | { | |
827 | listnode_delete (ifp->nbr_connected, nbr_connected); | |
828 | nbr_connected_free (nbr_connected); | |
829 | } | |
830 | } | |
831 | ||
718e3744 | 832 | /* Interface is up. */ |
833 | void | |
834 | if_up (struct interface *ifp) | |
835 | { | |
718e3744 | 836 | /* Notify the protocol daemons. */ |
950bd436 | 837 | if (ifp->ptm_enable && (ifp->ptm_status == ZEBRA_PTM_STATUS_DOWN)) { |
244c1cdc DS |
838 | zlog_warn("%s: interface %s hasn't passed ptm check\n", __func__, |
839 | ifp->name); | |
840 | return; | |
841 | } | |
718e3744 | 842 | zebra_interface_up_update (ifp); |
843 | ||
5c610faf | 844 | if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (ifp); |
244c1cdc | 845 | |
718e3744 | 846 | /* Install connected routes to the kernel. */ |
c8e264b6 | 847 | if_install_connected (ifp); |
718e3744 | 848 | |
41ec9222 | 849 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) |
1c848137 | 850 | zlog_debug ("%u: IF %s up, scheduling RIB processing", |
851 | ifp->vrf_id, ifp->name); | |
852 | rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); | |
718e3744 | 853 | } |
854 | ||
855 | /* Interface goes down. We have to manage different behavior of based | |
856 | OS. */ | |
857 | void | |
858 | if_down (struct interface *ifp) | |
859 | { | |
718e3744 | 860 | /* Notify to the protocol daemons. */ |
861 | zebra_interface_down_update (ifp); | |
862 | ||
c8e264b6 | 863 | /* Uninstall connected routes from the kernel. */ |
864 | if_uninstall_connected (ifp); | |
718e3744 | 865 | |
41ec9222 | 866 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) |
1c848137 | 867 | zlog_debug ("%u: IF %s down, scheduling RIB processing", |
868 | ifp->vrf_id, ifp->name); | |
869 | rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); | |
5c610faf DS |
870 | |
871 | if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp); | |
a197c47c DS |
872 | |
873 | /* Delete all neighbor addresses learnt through IPv6 RA */ | |
874 | if_down_del_nbr_connected (ifp); | |
718e3744 | 875 | } |
876 | ||
877 | void | |
878 | if_refresh (struct interface *ifp) | |
879 | { | |
5c78b3d0 | 880 | if_get_flags (ifp); |
718e3744 | 881 | } |
882 | ||
d5a5c8f0 | 883 | |
718e3744 | 884 | /* Output prefix string to vty. */ |
a1ac18c4 | 885 | static int |
718e3744 | 886 | prefix_vty_out (struct vty *vty, struct prefix *p) |
887 | { | |
888 | char str[INET6_ADDRSTRLEN]; | |
889 | ||
890 | inet_ntop (p->family, &p->u.prefix, str, sizeof (str)); | |
891 | vty_out (vty, "%s", str); | |
892 | return strlen (str); | |
893 | } | |
894 | ||
895 | /* Dump if address information to vty. */ | |
a1ac18c4 | 896 | static void |
718e3744 | 897 | connected_dump_vty (struct vty *vty, struct connected *connected) |
898 | { | |
899 | struct prefix *p; | |
718e3744 | 900 | |
901 | /* Print interface address. */ | |
902 | p = connected->address; | |
903 | vty_out (vty, " %s ", prefix_family_str (p)); | |
904 | prefix_vty_out (vty, p); | |
905 | vty_out (vty, "/%d", p->prefixlen); | |
906 | ||
907 | /* If there is destination address, print it. */ | |
e4529636 | 908 | if (connected->destination) |
718e3744 | 909 | { |
e4529636 AS |
910 | vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast ")); |
911 | prefix_vty_out (vty, connected->destination); | |
718e3744 | 912 | } |
913 | ||
914 | if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY)) | |
915 | vty_out (vty, " secondary"); | |
916 | ||
525c1839 DS |
917 | if (CHECK_FLAG (connected->flags, ZEBRA_IFA_UNNUMBERED)) |
918 | vty_out (vty, " unnumbered"); | |
919 | ||
718e3744 | 920 | if (connected->label) |
921 | vty_out (vty, " %s", connected->label); | |
922 | ||
923 | vty_out (vty, "%s", VTY_NEWLINE); | |
924 | } | |
925 | ||
a80beece DS |
926 | /* Dump interface neighbor address information to vty. */ |
927 | static void | |
928 | nbr_connected_dump_vty (struct vty *vty, struct nbr_connected *connected) | |
929 | { | |
930 | struct prefix *p; | |
931 | ||
932 | /* Print interface address. */ | |
933 | p = connected->address; | |
934 | vty_out (vty, " %s ", prefix_family_str (p)); | |
935 | prefix_vty_out (vty, p); | |
936 | vty_out (vty, "/%d", p->prefixlen); | |
937 | ||
938 | vty_out (vty, "%s", VTY_NEWLINE); | |
939 | } | |
940 | ||
8da4e946 | 941 | #if defined (HAVE_RTADV) |
718e3744 | 942 | /* Dump interface ND information to vty. */ |
a1ac18c4 | 943 | static void |
718e3744 | 944 | nd_dump_vty (struct vty *vty, struct interface *ifp) |
945 | { | |
946 | struct zebra_if *zif; | |
947 | struct rtadvconf *rtadv; | |
7cee1bb1 | 948 | int interval; |
718e3744 | 949 | |
950 | zif = (struct zebra_if *) ifp->info; | |
951 | rtadv = &zif->rtadv; | |
952 | ||
953 | if (rtadv->AdvSendAdvertisements) | |
954 | { | |
955 | vty_out (vty, " ND advertised reachable time is %d milliseconds%s", | |
956 | rtadv->AdvReachableTime, VTY_NEWLINE); | |
957 | vty_out (vty, " ND advertised retransmit interval is %d milliseconds%s", | |
958 | rtadv->AdvRetransTimer, VTY_NEWLINE); | |
7cee1bb1 | 959 | interval = rtadv->MaxRtrAdvInterval; |
960 | if (interval % 1000) | |
961 | vty_out (vty, " ND router advertisements are sent every " | |
962 | "%d milliseconds%s", interval, | |
963 | VTY_NEWLINE); | |
964 | else | |
965 | vty_out (vty, " ND router advertisements are sent every " | |
966 | "%d seconds%s", interval / 1000, | |
967 | VTY_NEWLINE); | |
d660f698 DO |
968 | if (rtadv->AdvDefaultLifetime != -1) |
969 | vty_out (vty, " ND router advertisements live for %d seconds%s", | |
970 | rtadv->AdvDefaultLifetime, VTY_NEWLINE); | |
971 | else | |
972 | vty_out (vty, " ND router advertisements lifetime tracks ra-interval%s", | |
973 | VTY_NEWLINE); | |
b60668d0 CC |
974 | vty_out (vty, " ND router advertisement default router preference is " |
975 | "%s%s", rtadv_pref_strs[rtadv->DefaultPreference], | |
976 | VTY_NEWLINE); | |
718e3744 | 977 | if (rtadv->AdvManagedFlag) |
978 | vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s", | |
979 | VTY_NEWLINE); | |
980 | else | |
981 | vty_out (vty, " Hosts use stateless autoconfig for addresses.%s", | |
982 | VTY_NEWLINE); | |
7cee1bb1 | 983 | if (rtadv->AdvHomeAgentFlag) |
d660f698 | 984 | { |
7cee1bb1 | 985 | vty_out (vty, " ND router advertisements with " |
986 | "Home Agent flag bit set.%s", | |
987 | VTY_NEWLINE); | |
d660f698 DO |
988 | if (rtadv->HomeAgentLifetime != -1) |
989 | vty_out (vty, " Home Agent lifetime is %u seconds%s", | |
990 | rtadv->HomeAgentLifetime, VTY_NEWLINE); | |
991 | else | |
992 | vty_out (vty, " Home Agent lifetime tracks ra-lifetime%s", | |
993 | VTY_NEWLINE); | |
994 | vty_out (vty, " Home Agent preference is %u%s", | |
995 | rtadv->HomeAgentPreference, VTY_NEWLINE); | |
996 | } | |
7cee1bb1 | 997 | if (rtadv->AdvIntervalOption) |
998 | vty_out (vty, " ND router advertisements with Adv. Interval option.%s", | |
999 | VTY_NEWLINE); | |
718e3744 | 1000 | } |
1001 | } | |
8da4e946 | 1002 | #endif /* HAVE_RTADV */ |
718e3744 | 1003 | |
1004 | /* Interface's information print out to vty interface. */ | |
a1ac18c4 | 1005 | static void |
718e3744 | 1006 | if_dump_vty (struct vty *vty, struct interface *ifp) |
1007 | { | |
6f0e3f6e | 1008 | #ifdef HAVE_STRUCT_SOCKADDR_DL |
718e3744 | 1009 | struct sockaddr_dl *sdl; |
6f0e3f6e | 1010 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ |
718e3744 | 1011 | struct connected *connected; |
a80beece | 1012 | struct nbr_connected *nbr_connected; |
52dc7ee6 | 1013 | struct listnode *node; |
eef1fe11 | 1014 | struct route_node *rn; |
1015 | struct zebra_if *zebra_if; | |
e6a59b35 | 1016 | struct vrf *vrf; |
eef1fe11 | 1017 | |
1018 | zebra_if = ifp->info; | |
718e3744 | 1019 | |
2e3b2e47 | 1020 | vty_out (vty, "Interface %s is ", ifp->name); |
1021 | if (if_is_up(ifp)) { | |
1022 | vty_out (vty, "up, line protocol "); | |
1023 | ||
1024 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) { | |
1025 | if (if_is_running(ifp)) | |
1026 | vty_out (vty, "is up%s", VTY_NEWLINE); | |
1027 | else | |
1028 | vty_out (vty, "is down%s", VTY_NEWLINE); | |
1029 | } else { | |
1030 | vty_out (vty, "detection is disabled%s", VTY_NEWLINE); | |
1031 | } | |
1032 | } else { | |
1033 | vty_out (vty, "down%s", VTY_NEWLINE); | |
1034 | } | |
1035 | ||
950bd436 | 1036 | zebra_ptm_show_status(vty, ifp); |
244c1cdc | 1037 | |
e6a59b35 DS |
1038 | vrf = vrf_lookup(ifp->vrf_id); |
1039 | vty_out (vty, " vrf: %s%s", vrf->name, VTY_NEWLINE); | |
3968dbf8 | 1040 | |
718e3744 | 1041 | if (ifp->desc) |
1042 | vty_out (vty, " Description: %s%s", ifp->desc, | |
1043 | VTY_NEWLINE); | |
d2fc8896 | 1044 | if (ifp->ifindex == IFINDEX_INTERNAL) |
718e3744 | 1045 | { |
d2fc8896 | 1046 | vty_out(vty, " pseudo interface%s", VTY_NEWLINE); |
718e3744 | 1047 | return; |
1048 | } | |
1049 | else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) | |
1050 | { | |
1051 | vty_out(vty, " index %d inactive interface%s", | |
1052 | ifp->ifindex, | |
1053 | VTY_NEWLINE); | |
1054 | return; | |
1055 | } | |
1056 | ||
1057 | vty_out (vty, " index %d metric %d mtu %d ", | |
1058 | ifp->ifindex, ifp->metric, ifp->mtu); | |
44145db3 | 1059 | #ifdef HAVE_IPV6 |
1060 | if (ifp->mtu6 != ifp->mtu) | |
1061 | vty_out (vty, "mtu6 %d ", ifp->mtu6); | |
1062 | #endif | |
630c97ce PJ |
1063 | vty_out (vty, "%s flags: %s%s", VTY_NEWLINE, |
1064 | if_flag_dump (ifp->flags), VTY_NEWLINE); | |
3a570c8b | 1065 | |
718e3744 | 1066 | /* Hardware address. */ |
6f0e3f6e | 1067 | #ifdef HAVE_STRUCT_SOCKADDR_DL |
718e3744 | 1068 | sdl = &ifp->sdl; |
1069 | if (sdl != NULL && sdl->sdl_alen != 0) | |
1070 | { | |
1071 | int i; | |
1072 | u_char *ptr; | |
1073 | ||
1074 | vty_out (vty, " HWaddr: "); | |
5b73a671 | 1075 | for (i = 0, ptr = (u_char *)LLADDR (sdl); i < sdl->sdl_alen; i++, ptr++) |
1076 | vty_out (vty, "%s%02x", i == 0 ? "" : ":", *ptr); | |
718e3744 | 1077 | vty_out (vty, "%s", VTY_NEWLINE); |
1078 | } | |
1079 | #else | |
1080 | if (ifp->hw_addr_len != 0) | |
1081 | { | |
1082 | int i; | |
1083 | ||
1084 | vty_out (vty, " HWaddr: "); | |
1085 | for (i = 0; i < ifp->hw_addr_len; i++) | |
1086 | vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]); | |
1087 | vty_out (vty, "%s", VTY_NEWLINE); | |
1088 | } | |
6f0e3f6e | 1089 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ |
718e3744 | 1090 | |
1091 | /* Bandwidth in kbps */ | |
1092 | if (ifp->bandwidth != 0) | |
1093 | { | |
1094 | vty_out(vty, " bandwidth %u kbps", ifp->bandwidth); | |
1095 | vty_out(vty, "%s", VTY_NEWLINE); | |
1096 | } | |
1097 | ||
eef1fe11 | 1098 | for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn)) |
718e3744 | 1099 | { |
eef1fe11 | 1100 | if (! rn->info) |
1101 | continue; | |
1102 | ||
1eb8ef25 | 1103 | for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected)) |
1104 | connected_dump_vty (vty, connected); | |
718e3744 | 1105 | } |
1106 | ||
1eb8ef25 | 1107 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) |
39db97e4 | 1108 | { |
39db97e4 | 1109 | if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && |
1110 | (connected->address->family == AF_INET6)) | |
1111 | connected_dump_vty (vty, connected); | |
1112 | } | |
1113 | ||
8da4e946 | 1114 | #if defined (HAVE_RTADV) |
718e3744 | 1115 | nd_dump_vty (vty, ifp); |
8da4e946 | 1116 | #endif /* HAVE_RTADV */ |
a80beece DS |
1117 | if (listhead(ifp->nbr_connected)) |
1118 | vty_out (vty, " Neighbor address(s):%s", VTY_NEWLINE); | |
1119 | for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected)) | |
1120 | nbr_connected_dump_vty (vty, nbr_connected); | |
718e3744 | 1121 | |
1122 | #ifdef HAVE_PROC_NET_DEV | |
1123 | /* Statistics print out using proc file system. */ | |
6f2c27af | 1124 | vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, " |
1125 | "%lu dropped%s", | |
1126 | ifp->stats.rx_packets, ifp->stats.rx_multicast, | |
1127 | ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE); | |
718e3744 | 1128 | |
6f2c27af | 1129 | vty_out (vty, " %lu input errors, %lu length, %lu overrun," |
3452d475 | 1130 | " %lu CRC, %lu frame%s", |
718e3744 | 1131 | ifp->stats.rx_errors, ifp->stats.rx_length_errors, |
1132 | ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors, | |
6f2c27af | 1133 | ifp->stats.rx_frame_errors, VTY_NEWLINE); |
1134 | ||
1135 | vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors, | |
718e3744 | 1136 | ifp->stats.rx_missed_errors, VTY_NEWLINE); |
1137 | ||
6f2c27af | 1138 | vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s", |
718e3744 | 1139 | ifp->stats.tx_packets, ifp->stats.tx_bytes, |
1140 | ifp->stats.tx_dropped, VTY_NEWLINE); | |
1141 | ||
6f2c27af | 1142 | vty_out (vty, " %lu output errors, %lu aborted, %lu carrier," |
1143 | " %lu fifo, %lu heartbeat%s", | |
718e3744 | 1144 | ifp->stats.tx_errors, ifp->stats.tx_aborted_errors, |
1145 | ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors, | |
6f2c27af | 1146 | ifp->stats.tx_heartbeat_errors, VTY_NEWLINE); |
718e3744 | 1147 | |
6f2c27af | 1148 | vty_out (vty, " %lu window, %lu collisions%s", |
1149 | ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE); | |
718e3744 | 1150 | #endif /* HAVE_PROC_NET_DEV */ |
1151 | ||
1152 | #ifdef HAVE_NET_RT_IFLIST | |
1153 | #if defined (__bsdi__) || defined (__NetBSD__) | |
1154 | /* Statistics print out using sysctl (). */ | |
1155 | vty_out (vty, " input packets %qu, bytes %qu, dropped %qu," | |
1156 | " multicast packets %qu%s", | |
1157 | ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, | |
1158 | ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, | |
1159 | VTY_NEWLINE); | |
1160 | ||
1161 | vty_out (vty, " input errors %qu%s", | |
1162 | ifp->stats.ifi_ierrors, VTY_NEWLINE); | |
1163 | ||
1164 | vty_out (vty, " output packets %qu, bytes %qu, multicast packets %qu%s", | |
1165 | ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, | |
1166 | ifp->stats.ifi_omcasts, VTY_NEWLINE); | |
1167 | ||
1168 | vty_out (vty, " output errors %qu%s", | |
1169 | ifp->stats.ifi_oerrors, VTY_NEWLINE); | |
1170 | ||
1171 | vty_out (vty, " collisions %qu%s", | |
1172 | ifp->stats.ifi_collisions, VTY_NEWLINE); | |
1173 | #else | |
1174 | /* Statistics print out using sysctl (). */ | |
1175 | vty_out (vty, " input packets %lu, bytes %lu, dropped %lu," | |
1176 | " multicast packets %lu%s", | |
1177 | ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, | |
1178 | ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, | |
1179 | VTY_NEWLINE); | |
1180 | ||
1181 | vty_out (vty, " input errors %lu%s", | |
1182 | ifp->stats.ifi_ierrors, VTY_NEWLINE); | |
1183 | ||
1184 | vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s", | |
1185 | ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, | |
1186 | ifp->stats.ifi_omcasts, VTY_NEWLINE); | |
1187 | ||
1188 | vty_out (vty, " output errors %lu%s", | |
1189 | ifp->stats.ifi_oerrors, VTY_NEWLINE); | |
1190 | ||
1191 | vty_out (vty, " collisions %lu%s", | |
1192 | ifp->stats.ifi_collisions, VTY_NEWLINE); | |
1193 | #endif /* __bsdi__ || __NetBSD__ */ | |
1194 | #endif /* HAVE_NET_RT_IFLIST */ | |
1195 | } | |
1196 | ||
718e3744 | 1197 | /* Wrapper hook point for zebra daemon so that ifindex can be set |
1198 | * DEFUN macro not used as extract.pl HAS to ignore this | |
1199 | * See also interface_cmd in lib/if.c | |
1200 | */ | |
1201 | DEFUN_NOSH (zebra_interface, | |
1202 | zebra_interface_cmd, | |
1203 | "interface IFNAME", | |
1204 | "Select an interface to configure\n" | |
1205 | "Interface's name\n") | |
1206 | { | |
1207 | int ret; | |
1208 | struct interface * ifp; | |
1209 | ||
1210 | /* Call lib interface() */ | |
d2fc8896 | 1211 | if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS) |
1212 | return ret; | |
718e3744 | 1213 | |
1214 | ifp = vty->index; | |
1215 | ||
d2fc8896 | 1216 | if (ifp->ifindex == IFINDEX_INTERNAL) |
1217 | /* Is this really necessary? Shouldn't status be initialized to 0 | |
1218 | in that case? */ | |
1219 | UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); | |
718e3744 | 1220 | |
1221 | return ret; | |
1222 | } | |
1223 | ||
cd2a8a42 FL |
1224 | ALIAS (zebra_interface, |
1225 | zebra_interface_vrf_cmd, | |
1226 | "interface IFNAME " VRF_CMD_STR, | |
1227 | "Select an interface to configure\n" | |
1228 | "Interface's name\n" | |
1229 | VRF_CMD_HELP_STR) | |
1230 | ||
718e3744 | 1231 | struct cmd_node interface_node = |
1232 | { | |
1233 | INTERFACE_NODE, | |
1234 | "%s(config-if)# ", | |
1235 | 1 | |
1236 | }; | |
1237 | ||
12f6fb97 DS |
1238 | /* Wrapper hook point for zebra daemon so that ifindex can be set |
1239 | * DEFUN macro not used as extract.pl HAS to ignore this | |
1240 | * See also interface_cmd in lib/if.c | |
1241 | */ | |
1242 | DEFUN_NOSH (zebra_vrf, | |
1243 | zebra_vrf_cmd, | |
1244 | "vrf NAME", | |
1245 | "Select a VRF to configure\n" | |
1246 | "VRF's name\n") | |
1247 | { | |
1248 | int ret; | |
1249 | ||
1250 | /* Call lib vrf() */ | |
1251 | if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS) | |
1252 | return ret; | |
1253 | ||
1254 | // vrfp = vty->index; | |
1255 | ||
1256 | return ret; | |
1257 | } | |
1258 | ||
1259 | struct cmd_node vrf_node = | |
1260 | { | |
1261 | VRF_NODE, | |
1262 | "%s(config-vrf)# ", | |
1263 | 1 | |
1264 | }; | |
1265 | ||
8b87bdf4 | 1266 | /* Show all interfaces to vty. */ |
718e3744 | 1267 | DEFUN (show_interface, show_interface_cmd, |
8b87bdf4 FL |
1268 | "show interface", |
1269 | SHOW_STR | |
1270 | "Interface status and configuration\n") | |
1271 | { | |
1272 | struct listnode *node; | |
1273 | struct interface *ifp; | |
1274 | vrf_id_t vrf_id = VRF_DEFAULT; | |
1275 | ||
1276 | #ifdef HAVE_PROC_NET_DEV | |
1277 | /* If system has interface statistics via proc file system, update | |
1278 | statistics. */ | |
1279 | ifstat_update_proc (); | |
1280 | #endif /* HAVE_PROC_NET_DEV */ | |
1281 | #ifdef HAVE_NET_RT_IFLIST | |
1282 | ifstat_update_sysctl (); | |
1283 | #endif /* HAVE_NET_RT_IFLIST */ | |
1284 | ||
1285 | if (argc > 0) | |
12f6fb97 | 1286 | VRF_GET_ID (vrf_id, argv[0]); |
8b87bdf4 FL |
1287 | |
1288 | /* All interface print. */ | |
1289 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) | |
1290 | if_dump_vty (vty, ifp); | |
1291 | ||
1292 | return CMD_SUCCESS; | |
1293 | } | |
1294 | ||
1295 | ALIAS (show_interface, | |
1296 | show_interface_vrf_cmd, | |
1297 | "show interface " VRF_CMD_STR, | |
718e3744 | 1298 | SHOW_STR |
1299 | "Interface status and configuration\n" | |
8b87bdf4 FL |
1300 | VRF_CMD_HELP_STR) |
1301 | ||
1302 | /* Show all interfaces to vty. */ | |
1303 | DEFUN (show_interface_vrf_all, show_interface_vrf_all_cmd, | |
1304 | "show interface " VRF_ALL_CMD_STR, | |
1305 | SHOW_STR | |
1306 | "Interface status and configuration\n" | |
1307 | VRF_ALL_CMD_HELP_STR) | |
718e3744 | 1308 | { |
52dc7ee6 | 1309 | struct listnode *node; |
718e3744 | 1310 | struct interface *ifp; |
8b87bdf4 FL |
1311 | vrf_iter_t iter; |
1312 | ||
718e3744 | 1313 | #ifdef HAVE_PROC_NET_DEV |
1314 | /* If system has interface statistics via proc file system, update | |
1315 | statistics. */ | |
1316 | ifstat_update_proc (); | |
1317 | #endif /* HAVE_PROC_NET_DEV */ | |
1318 | #ifdef HAVE_NET_RT_IFLIST | |
1319 | ifstat_update_sysctl (); | |
1320 | #endif /* HAVE_NET_RT_IFLIST */ | |
1321 | ||
8b87bdf4 FL |
1322 | /* All interface print. */ |
1323 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) | |
1324 | for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) | |
1325 | if_dump_vty (vty, ifp); | |
1326 | ||
1327 | return CMD_SUCCESS; | |
1328 | } | |
1329 | ||
1330 | /* Show specified interface to vty. */ | |
1721646e DS |
1331 | |
1332 | DEFUN (show_interface_name_vrf, | |
1333 | show_interface_name_vrf_cmd, | |
1334 | "show interface IFNAME " VRF_CMD_STR, | |
8b87bdf4 FL |
1335 | SHOW_STR |
1336 | "Interface status and configuration\n" | |
1721646e DS |
1337 | "Interface name\n" |
1338 | VRF_CMD_HELP_STR) | |
8b87bdf4 FL |
1339 | { |
1340 | struct interface *ifp; | |
1341 | vrf_id_t vrf_id = VRF_DEFAULT; | |
1342 | ||
1343 | #ifdef HAVE_PROC_NET_DEV | |
1344 | /* If system has interface statistics via proc file system, update | |
1345 | statistics. */ | |
1346 | ifstat_update_proc (); | |
1347 | #endif /* HAVE_PROC_NET_DEV */ | |
1348 | #ifdef HAVE_NET_RT_IFLIST | |
1349 | ifstat_update_sysctl (); | |
1350 | #endif /* HAVE_NET_RT_IFLIST */ | |
1351 | ||
1352 | if (argc > 1) | |
12f6fb97 | 1353 | VRF_GET_ID (vrf_id, argv[1]); |
8b87bdf4 | 1354 | |
718e3744 | 1355 | /* Specified interface print. */ |
8b87bdf4 FL |
1356 | ifp = if_lookup_by_name_vrf (argv[0], vrf_id); |
1357 | if (ifp == NULL) | |
718e3744 | 1358 | { |
8b87bdf4 FL |
1359 | vty_out (vty, "%% Can't find interface %s%s", argv[0], |
1360 | VTY_NEWLINE); | |
1361 | return CMD_WARNING; | |
718e3744 | 1362 | } |
8b87bdf4 | 1363 | if_dump_vty (vty, ifp); |
718e3744 | 1364 | |
1365 | return CMD_SUCCESS; | |
1366 | } | |
1367 | ||
8b87bdf4 FL |
1368 | /* Show specified interface to vty. */ |
1369 | DEFUN (show_interface_name_vrf_all, show_interface_name_vrf_all_cmd, | |
1370 | "show interface IFNAME " VRF_ALL_CMD_STR, | |
1371 | SHOW_STR | |
1372 | "Interface status and configuration\n" | |
1721646e | 1373 | "Interface name\n" |
8b87bdf4 FL |
1374 | VRF_ALL_CMD_HELP_STR) |
1375 | { | |
1376 | struct interface *ifp; | |
1377 | vrf_iter_t iter; | |
1378 | int found = 0; | |
1379 | ||
1380 | #ifdef HAVE_PROC_NET_DEV | |
1381 | /* If system has interface statistics via proc file system, update | |
1382 | statistics. */ | |
1383 | ifstat_update_proc (); | |
1384 | #endif /* HAVE_PROC_NET_DEV */ | |
1385 | #ifdef HAVE_NET_RT_IFLIST | |
1386 | ifstat_update_sysctl (); | |
1387 | #endif /* HAVE_NET_RT_IFLIST */ | |
1388 | ||
1389 | /* All interface print. */ | |
1390 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) | |
1391 | { | |
1392 | /* Specified interface print. */ | |
1393 | ifp = if_lookup_by_name_vrf (argv[0], vrf_iter2id (iter)); | |
1394 | if (ifp) | |
1395 | { | |
1396 | if_dump_vty (vty, ifp); | |
1397 | found++; | |
1398 | } | |
1399 | } | |
1400 | ||
1401 | if (!found) | |
1402 | { | |
1403 | vty_out (vty, "%% Can't find interface %s%s", argv[0], VTY_NEWLINE); | |
1404 | return CMD_WARNING; | |
1405 | } | |
1406 | ||
1407 | return CMD_SUCCESS; | |
1408 | } | |
1409 | ||
1721646e DS |
1410 | ALIAS (show_interface_name_vrf_all, show_interface_name_cmd, |
1411 | "show interface IFNAME", | |
1412 | SHOW_STR | |
1413 | "Interface status and configuration\n" | |
1414 | "Interface name\n") | |
1415 | ||
8b87bdf4 FL |
1416 | static void |
1417 | if_show_description (struct vty *vty, vrf_id_t vrf_id) | |
ed9bb6d5 | 1418 | { |
1419 | struct listnode *node; | |
1420 | struct interface *ifp; | |
1421 | ||
1422 | vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE); | |
8b87bdf4 | 1423 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) |
ed9bb6d5 | 1424 | { |
1425 | int len; | |
ed9bb6d5 | 1426 | |
1427 | len = vty_out (vty, "%s", ifp->name); | |
1428 | vty_out (vty, "%*s", (16 - len), " "); | |
1429 | ||
1430 | if (if_is_up(ifp)) | |
1431 | { | |
1432 | vty_out (vty, "up "); | |
1433 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) | |
1434 | { | |
1435 | if (if_is_running(ifp)) | |
1436 | vty_out (vty, "up "); | |
1437 | else | |
1438 | vty_out (vty, "down "); | |
1439 | } | |
1440 | else | |
1441 | { | |
1442 | vty_out (vty, "unknown "); | |
1443 | } | |
1444 | } | |
1445 | else | |
1446 | { | |
1447 | vty_out (vty, "down down "); | |
1448 | } | |
1449 | ||
1450 | if (ifp->desc) | |
1451 | vty_out (vty, "%s", ifp->desc); | |
1452 | vty_out (vty, "%s", VTY_NEWLINE); | |
1453 | } | |
8b87bdf4 FL |
1454 | } |
1455 | ||
1456 | DEFUN (show_interface_desc, | |
1457 | show_interface_desc_cmd, | |
1458 | "show interface description", | |
1459 | SHOW_STR | |
1460 | "Interface status and configuration\n" | |
1461 | "Interface description\n") | |
1462 | { | |
1463 | vrf_id_t vrf_id = VRF_DEFAULT; | |
1464 | ||
1465 | if (argc > 0) | |
12f6fb97 | 1466 | VRF_GET_ID (vrf_id, argv[0]); |
8b87bdf4 FL |
1467 | |
1468 | if_show_description (vty, vrf_id); | |
1469 | ||
1470 | return CMD_SUCCESS; | |
1471 | } | |
1472 | ||
1473 | ALIAS (show_interface_desc, | |
1474 | show_interface_desc_vrf_cmd, | |
1475 | "show interface description " VRF_CMD_STR, | |
1476 | SHOW_STR | |
1477 | "Interface status and configuration\n" | |
1478 | "Interface description\n" | |
1479 | VRF_CMD_HELP_STR) | |
1480 | ||
1481 | DEFUN (show_interface_desc_vrf_all, | |
1482 | show_interface_desc_vrf_all_cmd, | |
1483 | "show interface description " VRF_ALL_CMD_STR, | |
1484 | SHOW_STR | |
1485 | "Interface status and configuration\n" | |
1486 | "Interface description\n" | |
1487 | VRF_ALL_CMD_HELP_STR) | |
1488 | { | |
1489 | vrf_iter_t iter; | |
1490 | ||
1491 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) | |
1492 | if (!list_isempty (vrf_iter2iflist (iter))) | |
1493 | { | |
1494 | vty_out (vty, "%s\tVRF %u%s%s", VTY_NEWLINE, | |
1495 | vrf_iter2id (iter), | |
1496 | VTY_NEWLINE, VTY_NEWLINE); | |
1497 | if_show_description (vty, vrf_iter2id (iter)); | |
1498 | } | |
1499 | ||
ed9bb6d5 | 1500 | return CMD_SUCCESS; |
1501 | } | |
1502 | ||
718e3744 | 1503 | DEFUN (multicast, |
1504 | multicast_cmd, | |
1505 | "multicast", | |
1506 | "Set multicast flag to interface\n") | |
1507 | { | |
1508 | int ret; | |
1509 | struct interface *ifp; | |
1510 | struct zebra_if *if_data; | |
1511 | ||
1512 | ifp = (struct interface *) vty->index; | |
48b33aaf | 1513 | if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
718e3744 | 1514 | { |
48b33aaf | 1515 | ret = if_set_flags (ifp, IFF_MULTICAST); |
1516 | if (ret < 0) | |
1517 | { | |
1518 | vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE); | |
1519 | return CMD_WARNING; | |
1520 | } | |
1521 | if_refresh (ifp); | |
718e3744 | 1522 | } |
718e3744 | 1523 | if_data = ifp->info; |
1524 | if_data->multicast = IF_ZEBRA_MULTICAST_ON; | |
48b33aaf | 1525 | |
718e3744 | 1526 | return CMD_SUCCESS; |
1527 | } | |
1528 | ||
1529 | DEFUN (no_multicast, | |
1530 | no_multicast_cmd, | |
1531 | "no multicast", | |
1532 | NO_STR | |
1533 | "Unset multicast flag to interface\n") | |
1534 | { | |
1535 | int ret; | |
1536 | struct interface *ifp; | |
1537 | struct zebra_if *if_data; | |
1538 | ||
1539 | ifp = (struct interface *) vty->index; | |
48b33aaf | 1540 | if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
718e3744 | 1541 | { |
48b33aaf | 1542 | ret = if_unset_flags (ifp, IFF_MULTICAST); |
1543 | if (ret < 0) | |
1544 | { | |
1545 | vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE); | |
1546 | return CMD_WARNING; | |
1547 | } | |
1548 | if_refresh (ifp); | |
718e3744 | 1549 | } |
718e3744 | 1550 | if_data = ifp->info; |
1551 | if_data->multicast = IF_ZEBRA_MULTICAST_OFF; | |
1552 | ||
1553 | return CMD_SUCCESS; | |
1554 | } | |
1555 | ||
2e3b2e47 | 1556 | DEFUN (linkdetect, |
1557 | linkdetect_cmd, | |
1558 | "link-detect", | |
1559 | "Enable link detection on interface\n") | |
1560 | { | |
2e3b2e47 | 1561 | struct interface *ifp; |
1562 | int if_was_operative; | |
1563 | ||
1564 | ifp = (struct interface *) vty->index; | |
244c1cdc | 1565 | if_was_operative = if_is_no_ptm_operative(ifp); |
2e3b2e47 | 1566 | SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
1567 | ||
1568 | /* When linkdetection is enabled, if might come down */ | |
244c1cdc | 1569 | if (!if_is_no_ptm_operative(ifp) && if_was_operative) if_down(ifp); |
2e3b2e47 | 1570 | |
1571 | /* FIXME: Will defer status change forwarding if interface | |
1572 | does not come down! */ | |
1573 | ||
1574 | return CMD_SUCCESS; | |
1575 | } | |
1576 | ||
1577 | ||
1578 | DEFUN (no_linkdetect, | |
1579 | no_linkdetect_cmd, | |
1580 | "no link-detect", | |
1581 | NO_STR | |
1582 | "Disable link detection on interface\n") | |
1583 | { | |
2e3b2e47 | 1584 | struct interface *ifp; |
1585 | int if_was_operative; | |
1586 | ||
1587 | ifp = (struct interface *) vty->index; | |
244c1cdc | 1588 | if_was_operative = if_is_no_ptm_operative(ifp); |
2e3b2e47 | 1589 | UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
1590 | ||
1591 | /* Interface may come up after disabling link detection */ | |
1592 | if (if_is_operative(ifp) && !if_was_operative) if_up(ifp); | |
1593 | ||
1594 | /* FIXME: see linkdetect_cmd */ | |
1595 | ||
1596 | return CMD_SUCCESS; | |
1597 | } | |
1598 | ||
718e3744 | 1599 | DEFUN (shutdown_if, |
1600 | shutdown_if_cmd, | |
1601 | "shutdown", | |
1602 | "Shutdown the selected interface\n") | |
1603 | { | |
1604 | int ret; | |
1605 | struct interface *ifp; | |
1606 | struct zebra_if *if_data; | |
1607 | ||
1608 | ifp = (struct interface *) vty->index; | |
bfac8dcd | 1609 | if (ifp->ifindex != IFINDEX_INTERNAL) |
718e3744 | 1610 | { |
bfac8dcd CF |
1611 | ret = if_unset_flags (ifp, IFF_UP); |
1612 | if (ret < 0) | |
1613 | { | |
1614 | vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE); | |
1615 | return CMD_WARNING; | |
1616 | } | |
1617 | if_refresh (ifp); | |
718e3744 | 1618 | } |
718e3744 | 1619 | if_data = ifp->info; |
1620 | if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON; | |
1621 | ||
1622 | return CMD_SUCCESS; | |
1623 | } | |
1624 | ||
1625 | DEFUN (no_shutdown_if, | |
1626 | no_shutdown_if_cmd, | |
1627 | "no shutdown", | |
1628 | NO_STR | |
1629 | "Shutdown the selected interface\n") | |
1630 | { | |
1631 | int ret; | |
1632 | struct interface *ifp; | |
1633 | struct zebra_if *if_data; | |
1634 | ||
1635 | ifp = (struct interface *) vty->index; | |
bfac8dcd CF |
1636 | |
1637 | if (ifp->ifindex != IFINDEX_INTERNAL) | |
718e3744 | 1638 | { |
bfac8dcd CF |
1639 | ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
1640 | if (ret < 0) | |
1641 | { | |
1642 | vty_out (vty, "Can't up interface%s", VTY_NEWLINE); | |
1643 | return CMD_WARNING; | |
1644 | } | |
1645 | if_refresh (ifp); | |
1646 | ||
1647 | /* Some addresses (in particular, IPv6 addresses on Linux) get | |
1648 | * removed when the interface goes down. They need to be readded. | |
1649 | */ | |
1650 | if_addr_wakeup(ifp); | |
718e3744 | 1651 | } |
bfac8dcd | 1652 | |
718e3744 | 1653 | if_data = ifp->info; |
1654 | if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF; | |
1655 | ||
1656 | return CMD_SUCCESS; | |
1657 | } | |
1658 | ||
1659 | DEFUN (bandwidth_if, | |
1660 | bandwidth_if_cmd, | |
1661 | "bandwidth <1-10000000>", | |
1662 | "Set bandwidth informational parameter\n" | |
1663 | "Bandwidth in kilobits\n") | |
1664 | { | |
1665 | struct interface *ifp; | |
1666 | unsigned int bandwidth; | |
1667 | ||
1668 | ifp = (struct interface *) vty->index; | |
1669 | bandwidth = strtol(argv[0], NULL, 10); | |
1670 | ||
1671 | /* bandwidth range is <1-10000000> */ | |
1672 | if (bandwidth < 1 || bandwidth > 10000000) | |
1673 | { | |
1674 | vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE); | |
1675 | return CMD_WARNING; | |
1676 | } | |
1677 | ||
1678 | ifp->bandwidth = bandwidth; | |
1679 | ||
1680 | /* force protocols to recalculate routes due to cost change */ | |
2e3b2e47 | 1681 | if (if_is_operative (ifp)) |
718e3744 | 1682 | zebra_interface_up_update (ifp); |
1683 | ||
1684 | return CMD_SUCCESS; | |
1685 | } | |
1686 | ||
1687 | DEFUN (no_bandwidth_if, | |
1688 | no_bandwidth_if_cmd, | |
1689 | "no bandwidth", | |
1690 | NO_STR | |
1691 | "Set bandwidth informational parameter\n") | |
1692 | { | |
1693 | struct interface *ifp; | |
1694 | ||
1695 | ifp = (struct interface *) vty->index; | |
1696 | ||
1697 | ifp->bandwidth = 0; | |
1698 | ||
1699 | /* force protocols to recalculate routes due to cost change */ | |
2e3b2e47 | 1700 | if (if_is_operative (ifp)) |
718e3744 | 1701 | zebra_interface_up_update (ifp); |
1702 | ||
1703 | return CMD_SUCCESS; | |
1704 | } | |
1705 | ||
1706 | ALIAS (no_bandwidth_if, | |
1707 | no_bandwidth_if_val_cmd, | |
1708 | "no bandwidth <1-10000000>", | |
1709 | NO_STR | |
1710 | "Set bandwidth informational parameter\n" | |
1711 | "Bandwidth in kilobits\n") | |
6b0655a2 | 1712 | |
a1ac18c4 | 1713 | static int |
39db97e4 | 1714 | ip_address_install (struct vty *vty, struct interface *ifp, |
1715 | const char *addr_str, const char *peer_str, | |
1716 | const char *label) | |
718e3744 | 1717 | { |
bfac8dcd | 1718 | struct zebra_if *if_data; |
718e3744 | 1719 | struct prefix_ipv4 cp; |
1720 | struct connected *ifc; | |
1721 | struct prefix_ipv4 *p; | |
718e3744 | 1722 | int ret; |
1723 | ||
bfac8dcd CF |
1724 | if_data = ifp->info; |
1725 | ||
718e3744 | 1726 | ret = str2prefix_ipv4 (addr_str, &cp); |
1727 | if (ret <= 0) | |
1728 | { | |
1729 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); | |
1730 | return CMD_WARNING; | |
1731 | } | |
1732 | ||
d914d5ff DS |
1733 | if (ipv4_martian(&cp.prefix)) |
1734 | { | |
1735 | vty_out (vty, "%% Invalid address%s", VTY_NEWLINE); | |
1736 | return CMD_WARNING; | |
1737 | } | |
1738 | ||
ca16218d | 1739 | ifc = connected_check (ifp, (struct prefix *) &cp); |
718e3744 | 1740 | if (! ifc) |
1741 | { | |
1742 | ifc = connected_new (); | |
1743 | ifc->ifp = ifp; | |
1744 | ||
1745 | /* Address. */ | |
1746 | p = prefix_ipv4_new (); | |
1747 | *p = cp; | |
1748 | ifc->address = (struct prefix *) p; | |
1749 | ||
1750 | /* Broadcast. */ | |
3fb9cd6e | 1751 | if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2) |
718e3744 | 1752 | { |
1753 | p = prefix_ipv4_new (); | |
1754 | *p = cp; | |
3fb9cd6e | 1755 | p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen); |
718e3744 | 1756 | ifc->destination = (struct prefix *) p; |
1757 | } | |
1758 | ||
718e3744 | 1759 | /* Label. */ |
1760 | if (label) | |
0752ef0b | 1761 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
718e3744 | 1762 | |
1763 | /* Add to linked list. */ | |
1764 | listnode_add (ifp->connected, ifc); | |
1765 | } | |
1766 | ||
1767 | /* This address is configured from zebra. */ | |
1768 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
1769 | SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); | |
1770 | ||
1771 | /* In case of this route need to install kernel. */ | |
f7f740fe | 1772 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
bfac8dcd CF |
1773 | && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE) |
1774 | && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) | |
718e3744 | 1775 | { |
1776 | /* Some system need to up the interface to set IP address. */ | |
1777 | if (! if_is_up (ifp)) | |
1778 | { | |
1779 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); | |
1780 | if_refresh (ifp); | |
1781 | } | |
1782 | ||
1783 | ret = if_set_prefix (ifp, ifc); | |
1784 | if (ret < 0) | |
1785 | { | |
1786 | vty_out (vty, "%% Can't set interface IP address: %s.%s", | |
6099b3b5 | 1787 | safe_strerror(errno), VTY_NEWLINE); |
718e3744 | 1788 | return CMD_WARNING; |
1789 | } | |
1790 | ||
f7f740fe | 1791 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
1792 | /* The address will be advertised to zebra clients when the notification |
1793 | * from the kernel has been received. | |
1794 | * It will also be added to the subnet chain list, then. */ | |
718e3744 | 1795 | } |
1796 | ||
1797 | return CMD_SUCCESS; | |
1798 | } | |
1799 | ||
a1ac18c4 | 1800 | static int |
39db97e4 | 1801 | ip_address_uninstall (struct vty *vty, struct interface *ifp, |
1802 | const char *addr_str, const char *peer_str, | |
1803 | const char *label) | |
718e3744 | 1804 | { |
1805 | struct prefix_ipv4 cp; | |
1806 | struct connected *ifc; | |
1807 | int ret; | |
1808 | ||
1809 | /* Convert to prefix structure. */ | |
1810 | ret = str2prefix_ipv4 (addr_str, &cp); | |
1811 | if (ret <= 0) | |
1812 | { | |
1813 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); | |
1814 | return CMD_WARNING; | |
1815 | } | |
1816 | ||
1817 | /* Check current interface address. */ | |
ca16218d | 1818 | ifc = connected_check (ifp, (struct prefix *) &cp); |
718e3744 | 1819 | if (! ifc) |
1820 | { | |
1821 | vty_out (vty, "%% Can't find address%s", VTY_NEWLINE); | |
1822 | return CMD_WARNING; | |
1823 | } | |
1824 | ||
1825 | /* This is not configured address. */ | |
1826 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
1827 | return CMD_WARNING; | |
1828 | ||
74ecdc9e PJ |
1829 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
1830 | ||
718e3744 | 1831 | /* This is not real address or interface is not active. */ |
f7f740fe | 1832 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
718e3744 | 1833 | || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
1834 | { | |
1835 | listnode_delete (ifp->connected, ifc); | |
1836 | connected_free (ifc); | |
1837 | return CMD_WARNING; | |
1838 | } | |
1839 | ||
1840 | /* This is real route. */ | |
1841 | ret = if_unset_prefix (ifp, ifc); | |
1842 | if (ret < 0) | |
1843 | { | |
1844 | vty_out (vty, "%% Can't unset interface IP address: %s.%s", | |
6099b3b5 | 1845 | safe_strerror(errno), VTY_NEWLINE); |
718e3744 | 1846 | return CMD_WARNING; |
1847 | } | |
f7f740fe | 1848 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
1849 | /* we will receive a kernel notification about this route being removed. |
1850 | * this will trigger its removal from the connected list. */ | |
718e3744 | 1851 | return CMD_SUCCESS; |
1852 | } | |
1853 | ||
1854 | DEFUN (ip_address, | |
1855 | ip_address_cmd, | |
1856 | "ip address A.B.C.D/M", | |
1857 | "Interface Internet Protocol config commands\n" | |
1858 | "Set the IP address of an interface\n" | |
1859 | "IP address (e.g. 10.0.0.1/8)\n") | |
1860 | { | |
eef1fe11 | 1861 | return ip_address_install (vty, vty->index, argv[0], NULL, NULL); |
718e3744 | 1862 | } |
1863 | ||
1864 | DEFUN (no_ip_address, | |
1865 | no_ip_address_cmd, | |
1866 | "no ip address A.B.C.D/M", | |
1867 | NO_STR | |
1868 | "Interface Internet Protocol config commands\n" | |
1869 | "Set the IP address of an interface\n" | |
1870 | "IP Address (e.g. 10.0.0.1/8)") | |
1871 | { | |
eef1fe11 | 1872 | return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL); |
718e3744 | 1873 | } |
1874 | ||
1875 | #ifdef HAVE_NETLINK | |
718e3744 | 1876 | DEFUN (ip_address_label, |
1877 | ip_address_label_cmd, | |
1878 | "ip address A.B.C.D/M label LINE", | |
1879 | "Interface Internet Protocol config commands\n" | |
1880 | "Set the IP address of an interface\n" | |
1881 | "IP address (e.g. 10.0.0.1/8)\n" | |
1882 | "Label of this address\n" | |
1883 | "Label\n") | |
1884 | { | |
eef1fe11 | 1885 | return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]); |
718e3744 | 1886 | } |
1887 | ||
1888 | DEFUN (no_ip_address_label, | |
1889 | no_ip_address_label_cmd, | |
1890 | "no ip address A.B.C.D/M label LINE", | |
1891 | NO_STR | |
1892 | "Interface Internet Protocol config commands\n" | |
1893 | "Set the IP address of an interface\n" | |
1894 | "IP address (e.g. 10.0.0.1/8)\n" | |
1895 | "Label of this address\n" | |
1896 | "Label\n") | |
1897 | { | |
eef1fe11 | 1898 | return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]); |
718e3744 | 1899 | } |
1900 | #endif /* HAVE_NETLINK */ | |
1901 | ||
1902 | #ifdef HAVE_IPV6 | |
a1ac18c4 | 1903 | static int |
39db97e4 | 1904 | ipv6_address_install (struct vty *vty, struct interface *ifp, |
1905 | const char *addr_str, const char *peer_str, | |
1906 | const char *label, int secondary) | |
718e3744 | 1907 | { |
bfac8dcd | 1908 | struct zebra_if *if_data; |
718e3744 | 1909 | struct prefix_ipv6 cp; |
1910 | struct connected *ifc; | |
1911 | struct prefix_ipv6 *p; | |
1912 | int ret; | |
1913 | ||
bfac8dcd CF |
1914 | if_data = ifp->info; |
1915 | ||
718e3744 | 1916 | ret = str2prefix_ipv6 (addr_str, &cp); |
1917 | if (ret <= 0) | |
1918 | { | |
1919 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); | |
1920 | return CMD_WARNING; | |
1921 | } | |
1922 | ||
d914d5ff DS |
1923 | if (ipv6_martian(&cp.prefix)) |
1924 | { | |
1925 | vty_out (vty, "%% Invalid address%s", VTY_NEWLINE); | |
1926 | return CMD_WARNING; | |
1927 | } | |
1928 | ||
ca16218d | 1929 | ifc = connected_check (ifp, (struct prefix *) &cp); |
718e3744 | 1930 | if (! ifc) |
1931 | { | |
1932 | ifc = connected_new (); | |
1933 | ifc->ifp = ifp; | |
1934 | ||
1935 | /* Address. */ | |
1936 | p = prefix_ipv6_new (); | |
1937 | *p = cp; | |
1938 | ifc->address = (struct prefix *) p; | |
1939 | ||
1940 | /* Secondary. */ | |
1941 | if (secondary) | |
1942 | SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); | |
1943 | ||
1944 | /* Label. */ | |
1945 | if (label) | |
0752ef0b | 1946 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
718e3744 | 1947 | |
1948 | /* Add to linked list. */ | |
1949 | listnode_add (ifp->connected, ifc); | |
b6120505 | 1950 | |
30a3822f | 1951 | /* Enable RA on this interface */ |
1952 | if (interface_ipv6_auto_ra_allowed (ifp)) | |
1953 | ipv6_nd_suppress_ra_set (ifp, RA_ENABLE); | |
718e3744 | 1954 | } |
1955 | ||
1956 | /* This address is configured from zebra. */ | |
1957 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
1958 | SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); | |
1959 | ||
1960 | /* In case of this route need to install kernel. */ | |
f7f740fe | 1961 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
bfac8dcd CF |
1962 | && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE) |
1963 | && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) | |
718e3744 | 1964 | { |
1965 | /* Some system need to up the interface to set IP address. */ | |
1966 | if (! if_is_up (ifp)) | |
1967 | { | |
1968 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); | |
1969 | if_refresh (ifp); | |
1970 | } | |
1971 | ||
1972 | ret = if_prefix_add_ipv6 (ifp, ifc); | |
1973 | ||
1974 | if (ret < 0) | |
1975 | { | |
1976 | vty_out (vty, "%% Can't set interface IP address: %s.%s", | |
6099b3b5 | 1977 | safe_strerror(errno), VTY_NEWLINE); |
718e3744 | 1978 | return CMD_WARNING; |
1979 | } | |
1980 | ||
f7f740fe | 1981 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
1982 | /* The address will be advertised to zebra clients when the notification |
1983 | * from the kernel has been received. */ | |
718e3744 | 1984 | } |
1985 | ||
1986 | return CMD_SUCCESS; | |
1987 | } | |
1988 | ||
b6120505 DW |
1989 | /* Return true if an ipv6 address is configured on ifp */ |
1990 | int | |
1991 | ipv6_address_configured (struct interface *ifp) | |
1992 | { | |
1993 | struct connected *connected; | |
1994 | struct listnode *node; | |
1995 | ||
1996 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) | |
1997 | if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && (connected->address->family == AF_INET6)) | |
1998 | return 1; | |
1999 | ||
2000 | return 0; | |
2001 | } | |
2002 | ||
a1ac18c4 | 2003 | static int |
39db97e4 | 2004 | ipv6_address_uninstall (struct vty *vty, struct interface *ifp, |
2005 | const char *addr_str, const char *peer_str, | |
2006 | const char *label, int secondry) | |
718e3744 | 2007 | { |
2008 | struct prefix_ipv6 cp; | |
2009 | struct connected *ifc; | |
2010 | int ret; | |
2011 | ||
2012 | /* Convert to prefix structure. */ | |
2013 | ret = str2prefix_ipv6 (addr_str, &cp); | |
2014 | if (ret <= 0) | |
2015 | { | |
2016 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); | |
2017 | return CMD_WARNING; | |
2018 | } | |
2019 | ||
2020 | /* Check current interface address. */ | |
ca16218d | 2021 | ifc = connected_check (ifp, (struct prefix *) &cp); |
718e3744 | 2022 | if (! ifc) |
2023 | { | |
2024 | vty_out (vty, "%% Can't find address%s", VTY_NEWLINE); | |
2025 | return CMD_WARNING; | |
2026 | } | |
2027 | ||
2028 | /* This is not configured address. */ | |
2029 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
2030 | return CMD_WARNING; | |
2031 | ||
676e1a01 CF |
2032 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
2033 | ||
718e3744 | 2034 | /* This is not real address or interface is not active. */ |
f7f740fe | 2035 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
718e3744 | 2036 | || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
2037 | { | |
2038 | listnode_delete (ifp->connected, ifc); | |
2039 | connected_free (ifc); | |
2040 | return CMD_WARNING; | |
2041 | } | |
2042 | ||
2043 | /* This is real route. */ | |
2044 | ret = if_prefix_delete_ipv6 (ifp, ifc); | |
2045 | if (ret < 0) | |
2046 | { | |
2047 | vty_out (vty, "%% Can't unset interface IP address: %s.%s", | |
6099b3b5 | 2048 | safe_strerror(errno), VTY_NEWLINE); |
718e3744 | 2049 | return CMD_WARNING; |
2050 | } | |
2051 | ||
b6120505 | 2052 | /* Enable RA suppression if there are no IPv6 addresses on this interface */ |
30a3822f | 2053 | if (interface_ipv6_auto_ra_allowed (ifp)) |
2054 | { | |
2055 | if (! ipv6_address_configured(ifp)) | |
2056 | ipv6_nd_suppress_ra_set (ifp, RA_SUPPRESS); | |
2057 | } | |
b6120505 | 2058 | |
f7f740fe | 2059 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
2060 | /* This information will be propagated to the zclients when the |
2061 | * kernel notification is received. */ | |
718e3744 | 2062 | return CMD_SUCCESS; |
2063 | } | |
2064 | ||
2065 | DEFUN (ipv6_address, | |
2066 | ipv6_address_cmd, | |
2067 | "ipv6 address X:X::X:X/M", | |
e23949c0 | 2068 | "Interface IPv6 config commands\n" |
718e3744 | 2069 | "Set the IP address of an interface\n" |
2070 | "IPv6 address (e.g. 3ffe:506::1/48)\n") | |
2071 | { | |
2072 | return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0); | |
2073 | } | |
2074 | ||
2075 | DEFUN (no_ipv6_address, | |
2076 | no_ipv6_address_cmd, | |
2077 | "no ipv6 address X:X::X:X/M", | |
2078 | NO_STR | |
e23949c0 | 2079 | "Interface IPv6 config commands\n" |
718e3744 | 2080 | "Set the IP address of an interface\n" |
2081 | "IPv6 address (e.g. 3ffe:506::1/48)\n") | |
2082 | { | |
2083 | return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0); | |
2084 | } | |
2085 | #endif /* HAVE_IPV6 */ | |
2086 | ||
a1ac18c4 | 2087 | static int |
718e3744 | 2088 | if_config_write (struct vty *vty) |
2089 | { | |
52dc7ee6 | 2090 | struct listnode *node; |
718e3744 | 2091 | struct interface *ifp; |
cd2a8a42 | 2092 | vrf_iter_t iter; |
718e3744 | 2093 | |
244c1cdc DS |
2094 | zebra_ptm_write (vty); |
2095 | ||
cd2a8a42 FL |
2096 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
2097 | for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) | |
718e3744 | 2098 | { |
2099 | struct zebra_if *if_data; | |
52dc7ee6 | 2100 | struct listnode *addrnode; |
718e3744 | 2101 | struct connected *ifc; |
2102 | struct prefix *p; | |
12f6fb97 | 2103 | struct vrf *vrf; |
718e3744 | 2104 | |
718e3744 | 2105 | if_data = ifp->info; |
12f6fb97 | 2106 | vrf = vrf_lookup(ifp->vrf_id); |
cd2a8a42 FL |
2107 | |
2108 | if (ifp->vrf_id == VRF_DEFAULT) | |
2109 | vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE); | |
2110 | else | |
12f6fb97 | 2111 | vty_out (vty, "interface %s vrf %s%s", ifp->name, vrf->name, |
cd2a8a42 | 2112 | VTY_NEWLINE); |
718e3744 | 2113 | |
bfac8dcd CF |
2114 | if (if_data) |
2115 | { | |
2116 | if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) | |
2117 | vty_out (vty, " shutdown%s", VTY_NEWLINE); | |
2118 | } | |
2119 | ||
718e3744 | 2120 | if (ifp->desc) |
2121 | vty_out (vty, " description %s%s", ifp->desc, | |
2122 | VTY_NEWLINE); | |
2123 | ||
2124 | /* Assign bandwidth here to avoid unnecessary interface flap | |
2125 | while processing config script */ | |
2126 | if (ifp->bandwidth != 0) | |
2127 | vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE); | |
2128 | ||
2e3b2e47 | 2129 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) |
2130 | vty_out(vty, " link-detect%s", VTY_NEWLINE); | |
2131 | ||
1eb8ef25 | 2132 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc)) |
718e3744 | 2133 | { |
718e3744 | 2134 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
2135 | { | |
81cce018 | 2136 | char buf[INET6_ADDRSTRLEN]; |
718e3744 | 2137 | p = ifc->address; |
2138 | vty_out (vty, " ip%s address %s/%d", | |
2139 | p->family == AF_INET ? "" : "v6", | |
81cce018 | 2140 | inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)), |
718e3744 | 2141 | p->prefixlen); |
2142 | ||
718e3744 | 2143 | if (ifc->label) |
2144 | vty_out (vty, " label %s", ifc->label); | |
2145 | ||
2146 | vty_out (vty, "%s", VTY_NEWLINE); | |
2147 | } | |
2148 | } | |
2149 | ||
2150 | if (if_data) | |
2151 | { | |
718e3744 | 2152 | if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC) |
2153 | vty_out (vty, " %smulticast%s", | |
2154 | if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ", | |
2155 | VTY_NEWLINE); | |
2156 | } | |
2157 | ||
8da4e946 | 2158 | #if defined (HAVE_RTADV) |
718e3744 | 2159 | rtadv_config_write (vty, ifp); |
8da4e946 | 2160 | #endif /* HAVE_RTADV */ |
718e3744 | 2161 | |
ca776988 | 2162 | #ifdef HAVE_IRDP |
2163 | irdp_config_write (vty, ifp); | |
2164 | #endif /* IRDP */ | |
2165 | ||
718e3744 | 2166 | vty_out (vty, "!%s", VTY_NEWLINE); |
2167 | } | |
2168 | return 0; | |
2169 | } | |
2170 | ||
12f6fb97 DS |
2171 | static int |
2172 | vrf_config_write (struct vty *vty) | |
2173 | { | |
2174 | struct listnode *node; | |
2175 | struct vrf *vrf; | |
2176 | ||
2177 | for (ALL_LIST_ELEMENTS_RO (vrf_list, node, vrf)) | |
2178 | { | |
2179 | if (strcmp(vrf->name, VRF_DEFAULT_NAME)) | |
2180 | { | |
2181 | vty_out (vty, "vrf %s%s", vrf->name, VTY_NEWLINE); | |
2182 | vty_out (vty, "!%s", VTY_NEWLINE); | |
2183 | } | |
2184 | } | |
2185 | return 0; | |
2186 | } | |
2187 | ||
718e3744 | 2188 | /* Allocate and initialize interface vector. */ |
2189 | void | |
a1ac18c4 | 2190 | zebra_if_init (void) |
718e3744 | 2191 | { |
2192 | /* Initialize interface and new hook. */ | |
718e3744 | 2193 | if_add_hook (IF_NEW_HOOK, if_zebra_new_hook); |
2194 | if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook); | |
2195 | ||
2196 | /* Install configuration write function. */ | |
2197 | install_node (&interface_node, if_config_write); | |
12f6fb97 | 2198 | install_node (&vrf_node, vrf_config_write); |
718e3744 | 2199 | |
2200 | install_element (VIEW_NODE, &show_interface_cmd); | |
8b87bdf4 FL |
2201 | install_element (VIEW_NODE, &show_interface_vrf_cmd); |
2202 | install_element (VIEW_NODE, &show_interface_vrf_all_cmd); | |
2203 | install_element (VIEW_NODE, &show_interface_name_cmd); | |
2204 | install_element (VIEW_NODE, &show_interface_name_vrf_cmd); | |
2205 | install_element (VIEW_NODE, &show_interface_name_vrf_all_cmd); | |
718e3744 | 2206 | install_element (ENABLE_NODE, &show_interface_cmd); |
8b87bdf4 FL |
2207 | install_element (ENABLE_NODE, &show_interface_vrf_cmd); |
2208 | install_element (ENABLE_NODE, &show_interface_vrf_all_cmd); | |
2209 | install_element (ENABLE_NODE, &show_interface_name_cmd); | |
2210 | install_element (ENABLE_NODE, &show_interface_name_vrf_cmd); | |
2211 | install_element (ENABLE_NODE, &show_interface_name_vrf_all_cmd); | |
ed9bb6d5 | 2212 | install_element (ENABLE_NODE, &show_interface_desc_cmd); |
8b87bdf4 FL |
2213 | install_element (ENABLE_NODE, &show_interface_desc_vrf_cmd); |
2214 | install_element (ENABLE_NODE, &show_interface_desc_vrf_all_cmd); | |
718e3744 | 2215 | install_element (CONFIG_NODE, &zebra_interface_cmd); |
cd2a8a42 | 2216 | install_element (CONFIG_NODE, &zebra_interface_vrf_cmd); |
bfc13532 | 2217 | install_element (CONFIG_NODE, &no_interface_cmd); |
cd2a8a42 | 2218 | install_element (CONFIG_NODE, &no_interface_vrf_cmd); |
718e3744 | 2219 | install_default (INTERFACE_NODE); |
2220 | install_element (INTERFACE_NODE, &interface_desc_cmd); | |
2221 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); | |
2222 | install_element (INTERFACE_NODE, &multicast_cmd); | |
2223 | install_element (INTERFACE_NODE, &no_multicast_cmd); | |
2e3b2e47 | 2224 | install_element (INTERFACE_NODE, &linkdetect_cmd); |
2225 | install_element (INTERFACE_NODE, &no_linkdetect_cmd); | |
718e3744 | 2226 | install_element (INTERFACE_NODE, &shutdown_if_cmd); |
2227 | install_element (INTERFACE_NODE, &no_shutdown_if_cmd); | |
2228 | install_element (INTERFACE_NODE, &bandwidth_if_cmd); | |
2229 | install_element (INTERFACE_NODE, &no_bandwidth_if_cmd); | |
2230 | install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd); | |
2231 | install_element (INTERFACE_NODE, &ip_address_cmd); | |
2232 | install_element (INTERFACE_NODE, &no_ip_address_cmd); | |
2233 | #ifdef HAVE_IPV6 | |
2234 | install_element (INTERFACE_NODE, &ipv6_address_cmd); | |
2235 | install_element (INTERFACE_NODE, &no_ipv6_address_cmd); | |
2236 | #endif /* HAVE_IPV6 */ | |
718e3744 | 2237 | #ifdef HAVE_NETLINK |
718e3744 | 2238 | install_element (INTERFACE_NODE, &ip_address_label_cmd); |
718e3744 | 2239 | install_element (INTERFACE_NODE, &no_ip_address_label_cmd); |
2240 | #endif /* HAVE_NETLINK */ | |
12f6fb97 DS |
2241 | |
2242 | install_element (CONFIG_NODE, &zebra_vrf_cmd); | |
2243 | install_element (CONFIG_NODE, &no_vrf_cmd); | |
2244 | install_default (VRF_NODE); | |
2245 | ||
718e3744 | 2246 | } |