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