]>
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; | |
99ffac18 | 501 | zebra_interface_address_add_update (ifp, ifc); |
718e3744 | 502 | |
c8e264b6 | 503 | if (p->family == AF_INET) |
504 | connected_up_ipv4 (ifp, ifc); | |
505 | else if (p->family == AF_INET6) | |
506 | connected_up_ipv6 (ifp, ifc); | |
507 | } | |
508 | } | |
509 | } | |
510 | ||
511 | /* Uninstall connected routes corresponding to an interface. */ | |
512 | static void | |
513 | if_uninstall_connected (struct interface *ifp) | |
514 | { | |
515 | struct listnode *node; | |
516 | struct listnode *next; | |
517 | struct connected *ifc; | |
518 | struct prefix *p; | |
519 | ||
520 | if (ifp->connected) | |
718e3744 | 521 | { |
c8e264b6 | 522 | for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) |
523 | { | |
524 | p = ifc->address; | |
99ffac18 | 525 | zebra_interface_address_delete_update (ifp, ifc); |
c8e264b6 | 526 | |
527 | if (p->family == AF_INET) | |
528 | connected_down_ipv4 (ifp, ifc); | |
529 | else if (p->family == AF_INET6) | |
530 | connected_down_ipv6 (ifp, ifc); | |
531 | } | |
718e3744 | 532 | } |
c8e264b6 | 533 | } |
718e3744 | 534 | |
c8e264b6 | 535 | /* Uninstall and delete connected routes corresponding to an interface. */ |
536 | /* TODO - Check why IPv4 handling here is different from install or if_down */ | |
537 | static void | |
538 | if_delete_connected (struct interface *ifp) | |
539 | { | |
540 | struct connected *ifc; | |
541 | struct prefix *p; | |
542 | struct route_node *rn; | |
543 | struct zebra_if *zebra_if; | |
544 | ||
545 | zebra_if = ifp->info; | |
718e3744 | 546 | |
718e3744 | 547 | if (ifp->connected) |
548 | { | |
d9a18f11 PJ |
549 | struct listnode *node; |
550 | struct listnode *last = NULL; | |
551 | ||
eef1fe11 | 552 | while ((node = (last ? last->next : listhead (ifp->connected)))) |
718e3744 | 553 | { |
1eb8ef25 | 554 | ifc = listgetdata (node); |
718e3744 | 555 | p = ifc->address; |
eef1fe11 | 556 | |
beb56336 PJ |
557 | if (p->family == AF_INET |
558 | && (rn = route_node_lookup (zebra_if->ipv4_subnets, p))) | |
eef1fe11 | 559 | { |
d9a18f11 PJ |
560 | struct listnode *anode; |
561 | struct listnode *next; | |
562 | struct listnode *first; | |
563 | struct list *addr_list; | |
564 | ||
eef1fe11 | 565 | route_unlock_node (rn); |
566 | addr_list = (struct list *) rn->info; | |
567 | ||
568 | /* Remove addresses, secondaries first. */ | |
569 | first = listhead (addr_list); | |
d9a18f11 | 570 | for (anode = first->next; anode || first; anode = next) |
eef1fe11 | 571 | { |
d9a18f11 | 572 | if (!anode) |
eef1fe11 | 573 | { |
d9a18f11 | 574 | anode = first; |
eef1fe11 | 575 | first = NULL; |
576 | } | |
d9a18f11 | 577 | next = anode->next; |
eef1fe11 | 578 | |
d9a18f11 | 579 | ifc = listgetdata (anode); |
eef1fe11 | 580 | p = ifc->address; |
eef1fe11 | 581 | connected_down_ipv4 (ifp, ifc); |
582 | ||
02b4805f CF |
583 | /* XXX: We have to send notifications here explicitly, because we destroy |
584 | * the ifc before receiving the notification about the address being deleted. | |
585 | */ | |
eef1fe11 | 586 | zebra_interface_address_delete_update (ifp, ifc); |
587 | ||
588 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); | |
f7f740fe | 589 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
eef1fe11 | 590 | |
591 | /* Remove from subnet chain. */ | |
d9a18f11 | 592 | list_delete_node (addr_list, anode); |
eef1fe11 | 593 | route_unlock_node (rn); |
594 | ||
595 | /* Remove from interface address list (unconditionally). */ | |
d9a18f11 PJ |
596 | if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
597 | { | |
598 | listnode_delete (ifp->connected, ifc); | |
599 | connected_free (ifc); | |
600 | } | |
601 | else | |
602 | last = node; | |
eef1fe11 | 603 | } |
604 | ||
605 | /* Free chain list and respective route node. */ | |
606 | list_delete (addr_list); | |
607 | rn->info = NULL; | |
608 | route_unlock_node (rn); | |
609 | } | |
718e3744 | 610 | else if (p->family == AF_INET6) |
eef1fe11 | 611 | { |
612 | connected_down_ipv6 (ifp, ifc); | |
718e3744 | 613 | |
eef1fe11 | 614 | zebra_interface_address_delete_update (ifp, ifc); |
718e3744 | 615 | |
eef1fe11 | 616 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
f7f740fe | 617 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
eef1fe11 | 618 | |
619 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
620 | last = node; | |
621 | else | |
622 | { | |
623 | listnode_delete (ifp->connected, ifc); | |
624 | connected_free (ifc); | |
625 | } | |
718e3744 | 626 | } |
e26873fd RHA |
627 | else |
628 | { | |
629 | last = node; | |
630 | } | |
718e3744 | 631 | } |
632 | } | |
c8e264b6 | 633 | } |
634 | ||
635 | /* Handle an interface delete event */ | |
636 | void | |
637 | if_delete_update (struct interface *ifp) | |
638 | { | |
639 | if (if_is_up(ifp)) | |
640 | { | |
641 | zlog_err ("interface %s vrf %u index %d is still up while being deleted.", | |
642 | ifp->name, ifp->vrf_id, ifp->ifindex); | |
643 | return; | |
644 | } | |
645 | ||
646 | /* Mark interface as inactive */ | |
647 | UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); | |
648 | ||
649 | if (IS_ZEBRA_DEBUG_KERNEL) | |
650 | zlog_debug ("interface %s vrf %u index %d is now inactive.", | |
651 | ifp->name, ifp->vrf_id, ifp->ifindex); | |
652 | ||
653 | /* Delete connected routes from the kernel. */ | |
654 | if_delete_connected (ifp); | |
655 | ||
656 | /* Send out notification on interface delete. */ | |
718e3744 | 657 | zebra_interface_delete_update (ifp); |
d2fc8896 | 658 | |
12f6fb97 DS |
659 | if_unlink_per_ns(ifp); |
660 | ||
d2fc8896 | 661 | /* Update ifindex after distributing the delete message. This is in |
662 | case any client needs to have the old value of ifindex available | |
663 | while processing the deletion. Each client daemon is responsible | |
664 | for setting ifindex to IFINDEX_INTERNAL after processing the | |
665 | interface deletion message. */ | |
666 | ifp->ifindex = IFINDEX_INTERNAL; | |
718e3744 | 667 | } |
668 | ||
c8e264b6 | 669 | /* VRF change for an interface */ |
670 | void | |
671 | if_handle_vrf_change (struct interface *ifp, vrf_id_t vrf_id) | |
672 | { | |
673 | vrf_id_t old_vrf_id; | |
674 | ||
675 | old_vrf_id = ifp->vrf_id; | |
676 | ||
677 | /* Uninstall connected routes. */ | |
678 | if_uninstall_connected (ifp); | |
679 | ||
680 | /* Delete any IPv4 neighbors created to implement RFC 5549 */ | |
681 | if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp); | |
682 | ||
683 | /* Delete all neighbor addresses learnt through IPv6 RA */ | |
684 | if_down_del_nbr_connected (ifp); | |
685 | ||
686 | /* Suppress RAs on this interface, if enabled. */ | |
687 | ipv6_nd_suppress_ra_set (ifp, RA_SUPPRESS); | |
688 | ||
689 | /* Send out notification on interface VRF change. */ | |
690 | /* This is to issue an UPDATE or a DELETE, as appropriate. */ | |
691 | zebra_interface_vrf_update_del (ifp, vrf_id); | |
692 | ||
693 | /* update VRF */ | |
694 | if_update_vrf (ifp, ifp->name, strlen (ifp->name), vrf_id); | |
695 | ||
696 | /* Send out notification on interface VRF change. */ | |
697 | /* This is to issue an ADD, if needed. */ | |
698 | zebra_interface_vrf_update_add (ifp, old_vrf_id); | |
699 | ||
700 | /* Install connected routes (in new VRF). */ | |
701 | if_install_connected (ifp); | |
702 | ||
703 | /* Enable RAs on this interface, if IPv6 addresses are present. */ | |
704 | if (ipv6_address_configured(ifp)) | |
705 | ipv6_nd_suppress_ra_set (ifp, RA_ENABLE); | |
706 | ||
707 | /* Due to connected route change, schedule RIB processing for both old | |
708 | * and new VRF. | |
709 | */ | |
710 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) | |
711 | zlog_debug ("%u: IF %s VRF change, scheduling RIB processing", | |
712 | ifp->vrf_id, ifp->name); | |
713 | rib_update (old_vrf_id, RIB_UPDATE_IF_CHANGE); | |
714 | rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); | |
715 | } | |
716 | ||
717 | ||
12f6fb97 DS |
718 | /* Handle VRF addition */ |
719 | void | |
720 | vrf_add_update (struct vrf *vrfp) | |
721 | { | |
9e1bf607 | 722 | zebra_vrf_add_update (vrf_info_lookup (vrfp->vrf_id)); |
12f6fb97 DS |
723 | |
724 | if (! CHECK_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE)) | |
725 | { | |
726 | SET_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE); | |
727 | ||
728 | //Pending: Check if the equivalent of if_addr_wakeup (ifp) is needed here. | |
729 | ||
730 | if (IS_ZEBRA_DEBUG_KERNEL) | |
731 | zlog_debug ("VRF %s id %u becomes active.", | |
732 | vrfp->name, vrfp->vrf_id); | |
733 | } | |
734 | else | |
735 | { | |
736 | if (IS_ZEBRA_DEBUG_KERNEL) | |
737 | zlog_debug ("VRF %s id %u is added.", | |
738 | vrfp->name, vrfp->vrf_id); | |
739 | } | |
740 | } | |
741 | ||
742 | /* Handle an interface delete event */ | |
743 | void | |
744 | vrf_delete_update (struct vrf *vrfp) | |
745 | { | |
746 | /* Mark VRF as inactive */ | |
747 | UNSET_FLAG (vrfp->status, ZEBRA_VRF_ACTIVE); | |
748 | ||
749 | if (IS_ZEBRA_DEBUG_KERNEL) | |
750 | zlog_debug ("VRF %s id %u is now inactive.", | |
751 | vrfp->name, vrfp->vrf_id); | |
752 | ||
9e1bf607 | 753 | zebra_vrf_delete_update (vrf_info_lookup (vrfp->vrf_id)); |
12f6fb97 DS |
754 | |
755 | /* Pending: Update ifindex after distributing the delete message. This is in | |
756 | case any client needs to have the old value of ifindex available | |
757 | while processing the deletion. Each client daemon is responsible | |
758 | for setting vrf-id to IFINDEX_INTERNAL after processing the | |
759 | interface deletion message. */ | |
760 | vrfp->vrf_id = 0; | |
761 | } | |
762 | ||
763 | ||
88177fe3 | 764 | static void |
5c610faf DS |
765 | ipv6_ll_address_to_mac (struct in6_addr *address, u_char *mac) |
766 | { | |
eb4b1830 | 767 | mac[0] = address->s6_addr[8] ^ 0x02; |
5c610faf DS |
768 | mac[1] = address->s6_addr[9]; |
769 | mac[2] = address->s6_addr[10]; | |
770 | mac[3] = address->s6_addr[13]; | |
771 | mac[4] = address->s6_addr[14]; | |
772 | mac[5] = address->s6_addr[15]; | |
773 | } | |
774 | ||
775 | void | |
776 | if_nbr_ipv6ll_to_ipv4ll_neigh_update (struct interface *ifp, | |
777 | struct in6_addr *address, | |
778 | int add) | |
779 | { | |
780 | char buf[16] = "169.254.0.1"; | |
781 | struct in_addr ipv4_ll; | |
88177fe3 | 782 | char mac[6]; |
5c610faf DS |
783 | |
784 | inet_pton (AF_INET, buf, &ipv4_ll); | |
785 | ||
88177fe3 | 786 | ipv6_ll_address_to_mac(address, (u_char *)mac); |
5c610faf DS |
787 | netlink_neigh_update (add ? RTM_NEWNEIGH : RTM_DELNEIGH, |
788 | ifp->ifindex, ipv4_ll.s_addr, mac, 6); | |
789 | } | |
790 | ||
88177fe3 | 791 | static void |
5c610faf DS |
792 | if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (struct interface *ifp) |
793 | { | |
794 | if (listhead(ifp->nbr_connected)) | |
795 | { | |
796 | struct nbr_connected *nbr_connected; | |
797 | struct listnode *node; | |
798 | ||
799 | for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected)) | |
800 | if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp, | |
801 | &nbr_connected->address->u.prefix6, | |
802 | 1); | |
803 | } | |
804 | } | |
805 | ||
806 | void | |
807 | if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (struct interface *ifp) | |
808 | { | |
809 | if (listhead(ifp->nbr_connected)) | |
810 | { | |
811 | struct nbr_connected *nbr_connected; | |
812 | struct listnode *node; | |
813 | ||
814 | for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected)) | |
815 | if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp, | |
816 | &nbr_connected->address->u.prefix6, | |
817 | 0); | |
818 | } | |
819 | } | |
820 | ||
88177fe3 | 821 | static void |
a197c47c DS |
822 | if_down_del_nbr_connected (struct interface *ifp) |
823 | { | |
824 | struct nbr_connected *nbr_connected; | |
825 | struct listnode *node, *nnode; | |
826 | ||
827 | for (ALL_LIST_ELEMENTS (ifp->nbr_connected, node, nnode, nbr_connected)) | |
828 | { | |
829 | listnode_delete (ifp->nbr_connected, nbr_connected); | |
830 | nbr_connected_free (nbr_connected); | |
831 | } | |
832 | } | |
833 | ||
718e3744 | 834 | /* Interface is up. */ |
835 | void | |
836 | if_up (struct interface *ifp) | |
837 | { | |
718e3744 | 838 | /* Notify the protocol daemons. */ |
950bd436 | 839 | if (ifp->ptm_enable && (ifp->ptm_status == ZEBRA_PTM_STATUS_DOWN)) { |
244c1cdc DS |
840 | zlog_warn("%s: interface %s hasn't passed ptm check\n", __func__, |
841 | ifp->name); | |
842 | return; | |
843 | } | |
718e3744 | 844 | zebra_interface_up_update (ifp); |
845 | ||
5c610faf | 846 | if_nbr_ipv6ll_to_ipv4ll_neigh_add_all (ifp); |
244c1cdc | 847 | |
718e3744 | 848 | /* Install connected routes to the kernel. */ |
c8e264b6 | 849 | if_install_connected (ifp); |
718e3744 | 850 | |
41ec9222 | 851 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) |
1c848137 | 852 | zlog_debug ("%u: IF %s up, scheduling RIB processing", |
853 | ifp->vrf_id, ifp->name); | |
854 | rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); | |
718e3744 | 855 | } |
856 | ||
857 | /* Interface goes down. We have to manage different behavior of based | |
858 | OS. */ | |
859 | void | |
860 | if_down (struct interface *ifp) | |
861 | { | |
718e3744 | 862 | /* Notify to the protocol daemons. */ |
863 | zebra_interface_down_update (ifp); | |
864 | ||
c8e264b6 | 865 | /* Uninstall connected routes from the kernel. */ |
866 | if_uninstall_connected (ifp); | |
718e3744 | 867 | |
41ec9222 | 868 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) |
1c848137 | 869 | zlog_debug ("%u: IF %s down, scheduling RIB processing", |
870 | ifp->vrf_id, ifp->name); | |
871 | rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); | |
5c610faf DS |
872 | |
873 | if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp); | |
a197c47c DS |
874 | |
875 | /* Delete all neighbor addresses learnt through IPv6 RA */ | |
876 | if_down_del_nbr_connected (ifp); | |
718e3744 | 877 | } |
878 | ||
879 | void | |
880 | if_refresh (struct interface *ifp) | |
881 | { | |
5c78b3d0 | 882 | if_get_flags (ifp); |
718e3744 | 883 | } |
884 | ||
d5a5c8f0 | 885 | |
718e3744 | 886 | /* Output prefix string to vty. */ |
a1ac18c4 | 887 | static int |
718e3744 | 888 | prefix_vty_out (struct vty *vty, struct prefix *p) |
889 | { | |
890 | char str[INET6_ADDRSTRLEN]; | |
891 | ||
892 | inet_ntop (p->family, &p->u.prefix, str, sizeof (str)); | |
893 | vty_out (vty, "%s", str); | |
894 | return strlen (str); | |
895 | } | |
896 | ||
897 | /* Dump if address information to vty. */ | |
a1ac18c4 | 898 | static void |
718e3744 | 899 | connected_dump_vty (struct vty *vty, struct connected *connected) |
900 | { | |
901 | struct prefix *p; | |
718e3744 | 902 | |
903 | /* Print interface address. */ | |
904 | p = connected->address; | |
905 | vty_out (vty, " %s ", prefix_family_str (p)); | |
906 | prefix_vty_out (vty, p); | |
907 | vty_out (vty, "/%d", p->prefixlen); | |
908 | ||
909 | /* If there is destination address, print it. */ | |
e4529636 | 910 | if (connected->destination) |
718e3744 | 911 | { |
e4529636 AS |
912 | vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast ")); |
913 | prefix_vty_out (vty, connected->destination); | |
718e3744 | 914 | } |
915 | ||
916 | if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY)) | |
917 | vty_out (vty, " secondary"); | |
918 | ||
525c1839 DS |
919 | if (CHECK_FLAG (connected->flags, ZEBRA_IFA_UNNUMBERED)) |
920 | vty_out (vty, " unnumbered"); | |
921 | ||
718e3744 | 922 | if (connected->label) |
923 | vty_out (vty, " %s", connected->label); | |
924 | ||
925 | vty_out (vty, "%s", VTY_NEWLINE); | |
926 | } | |
927 | ||
a80beece DS |
928 | /* Dump interface neighbor address information to vty. */ |
929 | static void | |
930 | nbr_connected_dump_vty (struct vty *vty, struct nbr_connected *connected) | |
931 | { | |
932 | struct prefix *p; | |
933 | ||
934 | /* Print interface address. */ | |
935 | p = connected->address; | |
936 | vty_out (vty, " %s ", prefix_family_str (p)); | |
937 | prefix_vty_out (vty, p); | |
938 | vty_out (vty, "/%d", p->prefixlen); | |
939 | ||
940 | vty_out (vty, "%s", VTY_NEWLINE); | |
941 | } | |
942 | ||
8da4e946 | 943 | #if defined (HAVE_RTADV) |
718e3744 | 944 | /* Dump interface ND information to vty. */ |
a1ac18c4 | 945 | static void |
718e3744 | 946 | nd_dump_vty (struct vty *vty, struct interface *ifp) |
947 | { | |
948 | struct zebra_if *zif; | |
949 | struct rtadvconf *rtadv; | |
7cee1bb1 | 950 | int interval; |
718e3744 | 951 | |
952 | zif = (struct zebra_if *) ifp->info; | |
953 | rtadv = &zif->rtadv; | |
954 | ||
955 | if (rtadv->AdvSendAdvertisements) | |
956 | { | |
957 | vty_out (vty, " ND advertised reachable time is %d milliseconds%s", | |
958 | rtadv->AdvReachableTime, VTY_NEWLINE); | |
959 | vty_out (vty, " ND advertised retransmit interval is %d milliseconds%s", | |
960 | rtadv->AdvRetransTimer, VTY_NEWLINE); | |
7cee1bb1 | 961 | interval = rtadv->MaxRtrAdvInterval; |
962 | if (interval % 1000) | |
963 | vty_out (vty, " ND router advertisements are sent every " | |
964 | "%d milliseconds%s", interval, | |
965 | VTY_NEWLINE); | |
966 | else | |
967 | vty_out (vty, " ND router advertisements are sent every " | |
968 | "%d seconds%s", interval / 1000, | |
969 | VTY_NEWLINE); | |
d660f698 DO |
970 | if (rtadv->AdvDefaultLifetime != -1) |
971 | vty_out (vty, " ND router advertisements live for %d seconds%s", | |
972 | rtadv->AdvDefaultLifetime, VTY_NEWLINE); | |
973 | else | |
974 | vty_out (vty, " ND router advertisements lifetime tracks ra-interval%s", | |
975 | VTY_NEWLINE); | |
b60668d0 CC |
976 | vty_out (vty, " ND router advertisement default router preference is " |
977 | "%s%s", rtadv_pref_strs[rtadv->DefaultPreference], | |
978 | VTY_NEWLINE); | |
718e3744 | 979 | if (rtadv->AdvManagedFlag) |
980 | vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s", | |
981 | VTY_NEWLINE); | |
982 | else | |
983 | vty_out (vty, " Hosts use stateless autoconfig for addresses.%s", | |
984 | VTY_NEWLINE); | |
7cee1bb1 | 985 | if (rtadv->AdvHomeAgentFlag) |
d660f698 | 986 | { |
7cee1bb1 | 987 | vty_out (vty, " ND router advertisements with " |
988 | "Home Agent flag bit set.%s", | |
989 | VTY_NEWLINE); | |
d660f698 DO |
990 | if (rtadv->HomeAgentLifetime != -1) |
991 | vty_out (vty, " Home Agent lifetime is %u seconds%s", | |
992 | rtadv->HomeAgentLifetime, VTY_NEWLINE); | |
993 | else | |
994 | vty_out (vty, " Home Agent lifetime tracks ra-lifetime%s", | |
995 | VTY_NEWLINE); | |
996 | vty_out (vty, " Home Agent preference is %u%s", | |
997 | rtadv->HomeAgentPreference, VTY_NEWLINE); | |
998 | } | |
7cee1bb1 | 999 | if (rtadv->AdvIntervalOption) |
1000 | vty_out (vty, " ND router advertisements with Adv. Interval option.%s", | |
1001 | VTY_NEWLINE); | |
718e3744 | 1002 | } |
1003 | } | |
8da4e946 | 1004 | #endif /* HAVE_RTADV */ |
718e3744 | 1005 | |
1006 | /* Interface's information print out to vty interface. */ | |
a1ac18c4 | 1007 | static void |
718e3744 | 1008 | if_dump_vty (struct vty *vty, struct interface *ifp) |
1009 | { | |
6f0e3f6e | 1010 | #ifdef HAVE_STRUCT_SOCKADDR_DL |
718e3744 | 1011 | struct sockaddr_dl *sdl; |
6f0e3f6e | 1012 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ |
718e3744 | 1013 | struct connected *connected; |
a80beece | 1014 | struct nbr_connected *nbr_connected; |
52dc7ee6 | 1015 | struct listnode *node; |
eef1fe11 | 1016 | struct route_node *rn; |
1017 | struct zebra_if *zebra_if; | |
e6a59b35 | 1018 | struct vrf *vrf; |
eef1fe11 | 1019 | |
1020 | zebra_if = ifp->info; | |
718e3744 | 1021 | |
2e3b2e47 | 1022 | vty_out (vty, "Interface %s is ", ifp->name); |
1023 | if (if_is_up(ifp)) { | |
1024 | vty_out (vty, "up, line protocol "); | |
1025 | ||
1026 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) { | |
1027 | if (if_is_running(ifp)) | |
1028 | vty_out (vty, "is up%s", VTY_NEWLINE); | |
1029 | else | |
1030 | vty_out (vty, "is down%s", VTY_NEWLINE); | |
1031 | } else { | |
1032 | vty_out (vty, "detection is disabled%s", VTY_NEWLINE); | |
1033 | } | |
1034 | } else { | |
1035 | vty_out (vty, "down%s", VTY_NEWLINE); | |
1036 | } | |
1037 | ||
950bd436 | 1038 | zebra_ptm_show_status(vty, ifp); |
244c1cdc | 1039 | |
e6a59b35 DS |
1040 | vrf = vrf_lookup(ifp->vrf_id); |
1041 | vty_out (vty, " vrf: %s%s", vrf->name, VTY_NEWLINE); | |
3968dbf8 | 1042 | |
718e3744 | 1043 | if (ifp->desc) |
1044 | vty_out (vty, " Description: %s%s", ifp->desc, | |
1045 | VTY_NEWLINE); | |
d2fc8896 | 1046 | if (ifp->ifindex == IFINDEX_INTERNAL) |
718e3744 | 1047 | { |
d2fc8896 | 1048 | vty_out(vty, " pseudo interface%s", VTY_NEWLINE); |
718e3744 | 1049 | return; |
1050 | } | |
1051 | else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) | |
1052 | { | |
1053 | vty_out(vty, " index %d inactive interface%s", | |
1054 | ifp->ifindex, | |
1055 | VTY_NEWLINE); | |
1056 | return; | |
1057 | } | |
1058 | ||
1059 | vty_out (vty, " index %d metric %d mtu %d ", | |
1060 | ifp->ifindex, ifp->metric, ifp->mtu); | |
44145db3 | 1061 | #ifdef HAVE_IPV6 |
1062 | if (ifp->mtu6 != ifp->mtu) | |
1063 | vty_out (vty, "mtu6 %d ", ifp->mtu6); | |
1064 | #endif | |
630c97ce PJ |
1065 | vty_out (vty, "%s flags: %s%s", VTY_NEWLINE, |
1066 | if_flag_dump (ifp->flags), VTY_NEWLINE); | |
3a570c8b | 1067 | |
718e3744 | 1068 | /* Hardware address. */ |
6f0e3f6e | 1069 | #ifdef HAVE_STRUCT_SOCKADDR_DL |
718e3744 | 1070 | sdl = &ifp->sdl; |
1071 | if (sdl != NULL && sdl->sdl_alen != 0) | |
1072 | { | |
1073 | int i; | |
1074 | u_char *ptr; | |
1075 | ||
1076 | vty_out (vty, " HWaddr: "); | |
5b73a671 | 1077 | for (i = 0, ptr = (u_char *)LLADDR (sdl); i < sdl->sdl_alen; i++, ptr++) |
1078 | vty_out (vty, "%s%02x", i == 0 ? "" : ":", *ptr); | |
718e3744 | 1079 | vty_out (vty, "%s", VTY_NEWLINE); |
1080 | } | |
1081 | #else | |
1082 | if (ifp->hw_addr_len != 0) | |
1083 | { | |
1084 | int i; | |
1085 | ||
1086 | vty_out (vty, " HWaddr: "); | |
1087 | for (i = 0; i < ifp->hw_addr_len; i++) | |
1088 | vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]); | |
1089 | vty_out (vty, "%s", VTY_NEWLINE); | |
1090 | } | |
6f0e3f6e | 1091 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ |
718e3744 | 1092 | |
1093 | /* Bandwidth in kbps */ | |
1094 | if (ifp->bandwidth != 0) | |
1095 | { | |
1096 | vty_out(vty, " bandwidth %u kbps", ifp->bandwidth); | |
1097 | vty_out(vty, "%s", VTY_NEWLINE); | |
1098 | } | |
1099 | ||
eef1fe11 | 1100 | for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn)) |
718e3744 | 1101 | { |
eef1fe11 | 1102 | if (! rn->info) |
1103 | continue; | |
1104 | ||
1eb8ef25 | 1105 | for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected)) |
1106 | connected_dump_vty (vty, connected); | |
718e3744 | 1107 | } |
1108 | ||
1eb8ef25 | 1109 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) |
39db97e4 | 1110 | { |
39db97e4 | 1111 | if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && |
1112 | (connected->address->family == AF_INET6)) | |
1113 | connected_dump_vty (vty, connected); | |
1114 | } | |
1115 | ||
8da4e946 | 1116 | #if defined (HAVE_RTADV) |
718e3744 | 1117 | nd_dump_vty (vty, ifp); |
8da4e946 | 1118 | #endif /* HAVE_RTADV */ |
a80beece DS |
1119 | if (listhead(ifp->nbr_connected)) |
1120 | vty_out (vty, " Neighbor address(s):%s", VTY_NEWLINE); | |
1121 | for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, nbr_connected)) | |
1122 | nbr_connected_dump_vty (vty, nbr_connected); | |
718e3744 | 1123 | |
1124 | #ifdef HAVE_PROC_NET_DEV | |
1125 | /* Statistics print out using proc file system. */ | |
6f2c27af | 1126 | vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, " |
1127 | "%lu dropped%s", | |
1128 | ifp->stats.rx_packets, ifp->stats.rx_multicast, | |
1129 | ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE); | |
718e3744 | 1130 | |
6f2c27af | 1131 | vty_out (vty, " %lu input errors, %lu length, %lu overrun," |
3452d475 | 1132 | " %lu CRC, %lu frame%s", |
718e3744 | 1133 | ifp->stats.rx_errors, ifp->stats.rx_length_errors, |
1134 | ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors, | |
6f2c27af | 1135 | ifp->stats.rx_frame_errors, VTY_NEWLINE); |
1136 | ||
1137 | vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors, | |
718e3744 | 1138 | ifp->stats.rx_missed_errors, VTY_NEWLINE); |
1139 | ||
6f2c27af | 1140 | vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s", |
718e3744 | 1141 | ifp->stats.tx_packets, ifp->stats.tx_bytes, |
1142 | ifp->stats.tx_dropped, VTY_NEWLINE); | |
1143 | ||
6f2c27af | 1144 | vty_out (vty, " %lu output errors, %lu aborted, %lu carrier," |
1145 | " %lu fifo, %lu heartbeat%s", | |
718e3744 | 1146 | ifp->stats.tx_errors, ifp->stats.tx_aborted_errors, |
1147 | ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors, | |
6f2c27af | 1148 | ifp->stats.tx_heartbeat_errors, VTY_NEWLINE); |
718e3744 | 1149 | |
6f2c27af | 1150 | vty_out (vty, " %lu window, %lu collisions%s", |
1151 | ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE); | |
718e3744 | 1152 | #endif /* HAVE_PROC_NET_DEV */ |
1153 | ||
1154 | #ifdef HAVE_NET_RT_IFLIST | |
1155 | #if defined (__bsdi__) || defined (__NetBSD__) | |
1156 | /* Statistics print out using sysctl (). */ | |
1157 | vty_out (vty, " input packets %qu, bytes %qu, dropped %qu," | |
1158 | " multicast packets %qu%s", | |
1159 | ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, | |
1160 | ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, | |
1161 | VTY_NEWLINE); | |
1162 | ||
1163 | vty_out (vty, " input errors %qu%s", | |
1164 | ifp->stats.ifi_ierrors, VTY_NEWLINE); | |
1165 | ||
1166 | vty_out (vty, " output packets %qu, bytes %qu, multicast packets %qu%s", | |
1167 | ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, | |
1168 | ifp->stats.ifi_omcasts, VTY_NEWLINE); | |
1169 | ||
1170 | vty_out (vty, " output errors %qu%s", | |
1171 | ifp->stats.ifi_oerrors, VTY_NEWLINE); | |
1172 | ||
1173 | vty_out (vty, " collisions %qu%s", | |
1174 | ifp->stats.ifi_collisions, VTY_NEWLINE); | |
1175 | #else | |
1176 | /* Statistics print out using sysctl (). */ | |
1177 | vty_out (vty, " input packets %lu, bytes %lu, dropped %lu," | |
1178 | " multicast packets %lu%s", | |
1179 | ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, | |
1180 | ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, | |
1181 | VTY_NEWLINE); | |
1182 | ||
1183 | vty_out (vty, " input errors %lu%s", | |
1184 | ifp->stats.ifi_ierrors, VTY_NEWLINE); | |
1185 | ||
1186 | vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s", | |
1187 | ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, | |
1188 | ifp->stats.ifi_omcasts, VTY_NEWLINE); | |
1189 | ||
1190 | vty_out (vty, " output errors %lu%s", | |
1191 | ifp->stats.ifi_oerrors, VTY_NEWLINE); | |
1192 | ||
1193 | vty_out (vty, " collisions %lu%s", | |
1194 | ifp->stats.ifi_collisions, VTY_NEWLINE); | |
1195 | #endif /* __bsdi__ || __NetBSD__ */ | |
1196 | #endif /* HAVE_NET_RT_IFLIST */ | |
1197 | } | |
1198 | ||
718e3744 | 1199 | /* Wrapper hook point for zebra daemon so that ifindex can be set |
1200 | * DEFUN macro not used as extract.pl HAS to ignore this | |
1201 | * See also interface_cmd in lib/if.c | |
1202 | */ | |
1203 | DEFUN_NOSH (zebra_interface, | |
1204 | zebra_interface_cmd, | |
1205 | "interface IFNAME", | |
1206 | "Select an interface to configure\n" | |
1207 | "Interface's name\n") | |
1208 | { | |
1209 | int ret; | |
1210 | struct interface * ifp; | |
1211 | ||
1212 | /* Call lib interface() */ | |
d2fc8896 | 1213 | if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS) |
1214 | return ret; | |
718e3744 | 1215 | |
1216 | ifp = vty->index; | |
1217 | ||
d2fc8896 | 1218 | if (ifp->ifindex == IFINDEX_INTERNAL) |
1219 | /* Is this really necessary? Shouldn't status be initialized to 0 | |
1220 | in that case? */ | |
1221 | UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); | |
718e3744 | 1222 | |
1223 | return ret; | |
1224 | } | |
1225 | ||
cd2a8a42 FL |
1226 | ALIAS (zebra_interface, |
1227 | zebra_interface_vrf_cmd, | |
1228 | "interface IFNAME " VRF_CMD_STR, | |
1229 | "Select an interface to configure\n" | |
1230 | "Interface's name\n" | |
1231 | VRF_CMD_HELP_STR) | |
1232 | ||
718e3744 | 1233 | struct cmd_node interface_node = |
1234 | { | |
1235 | INTERFACE_NODE, | |
1236 | "%s(config-if)# ", | |
1237 | 1 | |
1238 | }; | |
1239 | ||
12f6fb97 DS |
1240 | /* Wrapper hook point for zebra daemon so that ifindex can be set |
1241 | * DEFUN macro not used as extract.pl HAS to ignore this | |
1242 | * See also interface_cmd in lib/if.c | |
1243 | */ | |
1244 | DEFUN_NOSH (zebra_vrf, | |
1245 | zebra_vrf_cmd, | |
1246 | "vrf NAME", | |
1247 | "Select a VRF to configure\n" | |
1248 | "VRF's name\n") | |
1249 | { | |
1250 | int ret; | |
1251 | ||
1252 | /* Call lib vrf() */ | |
1253 | if ((ret = vrf_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS) | |
1254 | return ret; | |
1255 | ||
1256 | // vrfp = vty->index; | |
1257 | ||
1258 | return ret; | |
1259 | } | |
1260 | ||
1261 | struct cmd_node vrf_node = | |
1262 | { | |
1263 | VRF_NODE, | |
1264 | "%s(config-vrf)# ", | |
1265 | 1 | |
1266 | }; | |
1267 | ||
8b87bdf4 | 1268 | /* Show all interfaces to vty. */ |
718e3744 | 1269 | DEFUN (show_interface, show_interface_cmd, |
8b87bdf4 FL |
1270 | "show interface", |
1271 | SHOW_STR | |
1272 | "Interface status and configuration\n") | |
1273 | { | |
1274 | struct listnode *node; | |
1275 | struct interface *ifp; | |
1276 | vrf_id_t vrf_id = VRF_DEFAULT; | |
1277 | ||
1278 | #ifdef HAVE_PROC_NET_DEV | |
1279 | /* If system has interface statistics via proc file system, update | |
1280 | statistics. */ | |
1281 | ifstat_update_proc (); | |
1282 | #endif /* HAVE_PROC_NET_DEV */ | |
1283 | #ifdef HAVE_NET_RT_IFLIST | |
1284 | ifstat_update_sysctl (); | |
1285 | #endif /* HAVE_NET_RT_IFLIST */ | |
1286 | ||
1287 | if (argc > 0) | |
12f6fb97 | 1288 | VRF_GET_ID (vrf_id, argv[0]); |
8b87bdf4 FL |
1289 | |
1290 | /* All interface print. */ | |
1291 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) | |
1292 | if_dump_vty (vty, ifp); | |
1293 | ||
1294 | return CMD_SUCCESS; | |
1295 | } | |
1296 | ||
1297 | ALIAS (show_interface, | |
1298 | show_interface_vrf_cmd, | |
1299 | "show interface " VRF_CMD_STR, | |
718e3744 | 1300 | SHOW_STR |
1301 | "Interface status and configuration\n" | |
8b87bdf4 FL |
1302 | VRF_CMD_HELP_STR) |
1303 | ||
1304 | /* Show all interfaces to vty. */ | |
1305 | DEFUN (show_interface_vrf_all, show_interface_vrf_all_cmd, | |
1306 | "show interface " VRF_ALL_CMD_STR, | |
1307 | SHOW_STR | |
1308 | "Interface status and configuration\n" | |
1309 | VRF_ALL_CMD_HELP_STR) | |
718e3744 | 1310 | { |
52dc7ee6 | 1311 | struct listnode *node; |
718e3744 | 1312 | struct interface *ifp; |
8b87bdf4 FL |
1313 | vrf_iter_t iter; |
1314 | ||
718e3744 | 1315 | #ifdef HAVE_PROC_NET_DEV |
1316 | /* If system has interface statistics via proc file system, update | |
1317 | statistics. */ | |
1318 | ifstat_update_proc (); | |
1319 | #endif /* HAVE_PROC_NET_DEV */ | |
1320 | #ifdef HAVE_NET_RT_IFLIST | |
1321 | ifstat_update_sysctl (); | |
1322 | #endif /* HAVE_NET_RT_IFLIST */ | |
1323 | ||
8b87bdf4 FL |
1324 | /* All interface print. */ |
1325 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) | |
1326 | for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) | |
1327 | if_dump_vty (vty, ifp); | |
1328 | ||
1329 | return CMD_SUCCESS; | |
1330 | } | |
1331 | ||
1332 | /* Show specified interface to vty. */ | |
1721646e DS |
1333 | |
1334 | DEFUN (show_interface_name_vrf, | |
1335 | show_interface_name_vrf_cmd, | |
1336 | "show interface IFNAME " VRF_CMD_STR, | |
8b87bdf4 FL |
1337 | SHOW_STR |
1338 | "Interface status and configuration\n" | |
1721646e DS |
1339 | "Interface name\n" |
1340 | VRF_CMD_HELP_STR) | |
8b87bdf4 FL |
1341 | { |
1342 | struct interface *ifp; | |
1343 | vrf_id_t vrf_id = VRF_DEFAULT; | |
1344 | ||
1345 | #ifdef HAVE_PROC_NET_DEV | |
1346 | /* If system has interface statistics via proc file system, update | |
1347 | statistics. */ | |
1348 | ifstat_update_proc (); | |
1349 | #endif /* HAVE_PROC_NET_DEV */ | |
1350 | #ifdef HAVE_NET_RT_IFLIST | |
1351 | ifstat_update_sysctl (); | |
1352 | #endif /* HAVE_NET_RT_IFLIST */ | |
1353 | ||
1354 | if (argc > 1) | |
12f6fb97 | 1355 | VRF_GET_ID (vrf_id, argv[1]); |
8b87bdf4 | 1356 | |
718e3744 | 1357 | /* Specified interface print. */ |
8b87bdf4 FL |
1358 | ifp = if_lookup_by_name_vrf (argv[0], vrf_id); |
1359 | if (ifp == NULL) | |
718e3744 | 1360 | { |
8b87bdf4 FL |
1361 | vty_out (vty, "%% Can't find interface %s%s", argv[0], |
1362 | VTY_NEWLINE); | |
1363 | return CMD_WARNING; | |
718e3744 | 1364 | } |
8b87bdf4 | 1365 | if_dump_vty (vty, ifp); |
718e3744 | 1366 | |
1367 | return CMD_SUCCESS; | |
1368 | } | |
1369 | ||
8b87bdf4 FL |
1370 | /* Show specified interface to vty. */ |
1371 | DEFUN (show_interface_name_vrf_all, show_interface_name_vrf_all_cmd, | |
1372 | "show interface IFNAME " VRF_ALL_CMD_STR, | |
1373 | SHOW_STR | |
1374 | "Interface status and configuration\n" | |
1721646e | 1375 | "Interface name\n" |
8b87bdf4 FL |
1376 | VRF_ALL_CMD_HELP_STR) |
1377 | { | |
1378 | struct interface *ifp; | |
1379 | vrf_iter_t iter; | |
1380 | int found = 0; | |
1381 | ||
1382 | #ifdef HAVE_PROC_NET_DEV | |
1383 | /* If system has interface statistics via proc file system, update | |
1384 | statistics. */ | |
1385 | ifstat_update_proc (); | |
1386 | #endif /* HAVE_PROC_NET_DEV */ | |
1387 | #ifdef HAVE_NET_RT_IFLIST | |
1388 | ifstat_update_sysctl (); | |
1389 | #endif /* HAVE_NET_RT_IFLIST */ | |
1390 | ||
1391 | /* All interface print. */ | |
1392 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) | |
1393 | { | |
1394 | /* Specified interface print. */ | |
1395 | ifp = if_lookup_by_name_vrf (argv[0], vrf_iter2id (iter)); | |
1396 | if (ifp) | |
1397 | { | |
1398 | if_dump_vty (vty, ifp); | |
1399 | found++; | |
1400 | } | |
1401 | } | |
1402 | ||
1403 | if (!found) | |
1404 | { | |
1405 | vty_out (vty, "%% Can't find interface %s%s", argv[0], VTY_NEWLINE); | |
1406 | return CMD_WARNING; | |
1407 | } | |
1408 | ||
1409 | return CMD_SUCCESS; | |
1410 | } | |
1411 | ||
1721646e DS |
1412 | ALIAS (show_interface_name_vrf_all, show_interface_name_cmd, |
1413 | "show interface IFNAME", | |
1414 | SHOW_STR | |
1415 | "Interface status and configuration\n" | |
1416 | "Interface name\n") | |
1417 | ||
8b87bdf4 FL |
1418 | static void |
1419 | if_show_description (struct vty *vty, vrf_id_t vrf_id) | |
ed9bb6d5 | 1420 | { |
1421 | struct listnode *node; | |
1422 | struct interface *ifp; | |
1423 | ||
1424 | vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE); | |
8b87bdf4 | 1425 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) |
ed9bb6d5 | 1426 | { |
1427 | int len; | |
ed9bb6d5 | 1428 | |
1429 | len = vty_out (vty, "%s", ifp->name); | |
1430 | vty_out (vty, "%*s", (16 - len), " "); | |
1431 | ||
1432 | if (if_is_up(ifp)) | |
1433 | { | |
1434 | vty_out (vty, "up "); | |
1435 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) | |
1436 | { | |
1437 | if (if_is_running(ifp)) | |
1438 | vty_out (vty, "up "); | |
1439 | else | |
1440 | vty_out (vty, "down "); | |
1441 | } | |
1442 | else | |
1443 | { | |
1444 | vty_out (vty, "unknown "); | |
1445 | } | |
1446 | } | |
1447 | else | |
1448 | { | |
1449 | vty_out (vty, "down down "); | |
1450 | } | |
1451 | ||
1452 | if (ifp->desc) | |
1453 | vty_out (vty, "%s", ifp->desc); | |
1454 | vty_out (vty, "%s", VTY_NEWLINE); | |
1455 | } | |
8b87bdf4 FL |
1456 | } |
1457 | ||
1458 | DEFUN (show_interface_desc, | |
1459 | show_interface_desc_cmd, | |
1460 | "show interface description", | |
1461 | SHOW_STR | |
1462 | "Interface status and configuration\n" | |
1463 | "Interface description\n") | |
1464 | { | |
1465 | vrf_id_t vrf_id = VRF_DEFAULT; | |
1466 | ||
1467 | if (argc > 0) | |
12f6fb97 | 1468 | VRF_GET_ID (vrf_id, argv[0]); |
8b87bdf4 FL |
1469 | |
1470 | if_show_description (vty, vrf_id); | |
1471 | ||
1472 | return CMD_SUCCESS; | |
1473 | } | |
1474 | ||
1475 | ALIAS (show_interface_desc, | |
1476 | show_interface_desc_vrf_cmd, | |
1477 | "show interface description " VRF_CMD_STR, | |
1478 | SHOW_STR | |
1479 | "Interface status and configuration\n" | |
1480 | "Interface description\n" | |
1481 | VRF_CMD_HELP_STR) | |
1482 | ||
1483 | DEFUN (show_interface_desc_vrf_all, | |
1484 | show_interface_desc_vrf_all_cmd, | |
1485 | "show interface description " VRF_ALL_CMD_STR, | |
1486 | SHOW_STR | |
1487 | "Interface status and configuration\n" | |
1488 | "Interface description\n" | |
1489 | VRF_ALL_CMD_HELP_STR) | |
1490 | { | |
1491 | vrf_iter_t iter; | |
1492 | ||
1493 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) | |
1494 | if (!list_isempty (vrf_iter2iflist (iter))) | |
1495 | { | |
1496 | vty_out (vty, "%s\tVRF %u%s%s", VTY_NEWLINE, | |
1497 | vrf_iter2id (iter), | |
1498 | VTY_NEWLINE, VTY_NEWLINE); | |
1499 | if_show_description (vty, vrf_iter2id (iter)); | |
1500 | } | |
1501 | ||
ed9bb6d5 | 1502 | return CMD_SUCCESS; |
1503 | } | |
1504 | ||
718e3744 | 1505 | DEFUN (multicast, |
1506 | multicast_cmd, | |
1507 | "multicast", | |
1508 | "Set multicast flag to interface\n") | |
1509 | { | |
1510 | int ret; | |
1511 | struct interface *ifp; | |
1512 | struct zebra_if *if_data; | |
1513 | ||
1514 | ifp = (struct interface *) vty->index; | |
48b33aaf | 1515 | if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
718e3744 | 1516 | { |
48b33aaf | 1517 | ret = if_set_flags (ifp, IFF_MULTICAST); |
1518 | if (ret < 0) | |
1519 | { | |
1520 | vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE); | |
1521 | return CMD_WARNING; | |
1522 | } | |
1523 | if_refresh (ifp); | |
718e3744 | 1524 | } |
718e3744 | 1525 | if_data = ifp->info; |
1526 | if_data->multicast = IF_ZEBRA_MULTICAST_ON; | |
48b33aaf | 1527 | |
718e3744 | 1528 | return CMD_SUCCESS; |
1529 | } | |
1530 | ||
1531 | DEFUN (no_multicast, | |
1532 | no_multicast_cmd, | |
1533 | "no multicast", | |
1534 | NO_STR | |
1535 | "Unset multicast flag to interface\n") | |
1536 | { | |
1537 | int ret; | |
1538 | struct interface *ifp; | |
1539 | struct zebra_if *if_data; | |
1540 | ||
1541 | ifp = (struct interface *) vty->index; | |
48b33aaf | 1542 | if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
718e3744 | 1543 | { |
48b33aaf | 1544 | ret = if_unset_flags (ifp, IFF_MULTICAST); |
1545 | if (ret < 0) | |
1546 | { | |
1547 | vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE); | |
1548 | return CMD_WARNING; | |
1549 | } | |
1550 | if_refresh (ifp); | |
718e3744 | 1551 | } |
718e3744 | 1552 | if_data = ifp->info; |
1553 | if_data->multicast = IF_ZEBRA_MULTICAST_OFF; | |
1554 | ||
1555 | return CMD_SUCCESS; | |
1556 | } | |
1557 | ||
2e3b2e47 | 1558 | DEFUN (linkdetect, |
1559 | linkdetect_cmd, | |
1560 | "link-detect", | |
1561 | "Enable link detection on interface\n") | |
1562 | { | |
2e3b2e47 | 1563 | struct interface *ifp; |
1564 | int if_was_operative; | |
1565 | ||
1566 | ifp = (struct interface *) vty->index; | |
244c1cdc | 1567 | if_was_operative = if_is_no_ptm_operative(ifp); |
2e3b2e47 | 1568 | SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
1569 | ||
1570 | /* When linkdetection is enabled, if might come down */ | |
244c1cdc | 1571 | if (!if_is_no_ptm_operative(ifp) && if_was_operative) if_down(ifp); |
2e3b2e47 | 1572 | |
1573 | /* FIXME: Will defer status change forwarding if interface | |
1574 | does not come down! */ | |
1575 | ||
1576 | return CMD_SUCCESS; | |
1577 | } | |
1578 | ||
1579 | ||
1580 | DEFUN (no_linkdetect, | |
1581 | no_linkdetect_cmd, | |
1582 | "no link-detect", | |
1583 | NO_STR | |
1584 | "Disable link detection on interface\n") | |
1585 | { | |
2e3b2e47 | 1586 | struct interface *ifp; |
1587 | int if_was_operative; | |
1588 | ||
1589 | ifp = (struct interface *) vty->index; | |
244c1cdc | 1590 | if_was_operative = if_is_no_ptm_operative(ifp); |
2e3b2e47 | 1591 | UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
1592 | ||
1593 | /* Interface may come up after disabling link detection */ | |
1594 | if (if_is_operative(ifp) && !if_was_operative) if_up(ifp); | |
1595 | ||
1596 | /* FIXME: see linkdetect_cmd */ | |
1597 | ||
1598 | return CMD_SUCCESS; | |
1599 | } | |
1600 | ||
718e3744 | 1601 | DEFUN (shutdown_if, |
1602 | shutdown_if_cmd, | |
1603 | "shutdown", | |
1604 | "Shutdown the selected interface\n") | |
1605 | { | |
1606 | int ret; | |
1607 | struct interface *ifp; | |
1608 | struct zebra_if *if_data; | |
1609 | ||
1610 | ifp = (struct interface *) vty->index; | |
bfac8dcd | 1611 | if (ifp->ifindex != IFINDEX_INTERNAL) |
718e3744 | 1612 | { |
bfac8dcd CF |
1613 | ret = if_unset_flags (ifp, IFF_UP); |
1614 | if (ret < 0) | |
1615 | { | |
1616 | vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE); | |
1617 | return CMD_WARNING; | |
1618 | } | |
1619 | if_refresh (ifp); | |
718e3744 | 1620 | } |
718e3744 | 1621 | if_data = ifp->info; |
1622 | if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON; | |
1623 | ||
1624 | return CMD_SUCCESS; | |
1625 | } | |
1626 | ||
1627 | DEFUN (no_shutdown_if, | |
1628 | no_shutdown_if_cmd, | |
1629 | "no shutdown", | |
1630 | NO_STR | |
1631 | "Shutdown the selected interface\n") | |
1632 | { | |
1633 | int ret; | |
1634 | struct interface *ifp; | |
1635 | struct zebra_if *if_data; | |
1636 | ||
1637 | ifp = (struct interface *) vty->index; | |
bfac8dcd CF |
1638 | |
1639 | if (ifp->ifindex != IFINDEX_INTERNAL) | |
718e3744 | 1640 | { |
bfac8dcd CF |
1641 | ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
1642 | if (ret < 0) | |
1643 | { | |
1644 | vty_out (vty, "Can't up interface%s", VTY_NEWLINE); | |
1645 | return CMD_WARNING; | |
1646 | } | |
1647 | if_refresh (ifp); | |
1648 | ||
1649 | /* Some addresses (in particular, IPv6 addresses on Linux) get | |
1650 | * removed when the interface goes down. They need to be readded. | |
1651 | */ | |
1652 | if_addr_wakeup(ifp); | |
718e3744 | 1653 | } |
bfac8dcd | 1654 | |
718e3744 | 1655 | if_data = ifp->info; |
1656 | if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF; | |
1657 | ||
1658 | return CMD_SUCCESS; | |
1659 | } | |
1660 | ||
1661 | DEFUN (bandwidth_if, | |
1662 | bandwidth_if_cmd, | |
1663 | "bandwidth <1-10000000>", | |
1664 | "Set bandwidth informational parameter\n" | |
1665 | "Bandwidth in kilobits\n") | |
1666 | { | |
1667 | struct interface *ifp; | |
1668 | unsigned int bandwidth; | |
1669 | ||
1670 | ifp = (struct interface *) vty->index; | |
1671 | bandwidth = strtol(argv[0], NULL, 10); | |
1672 | ||
1673 | /* bandwidth range is <1-10000000> */ | |
1674 | if (bandwidth < 1 || bandwidth > 10000000) | |
1675 | { | |
1676 | vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE); | |
1677 | return CMD_WARNING; | |
1678 | } | |
1679 | ||
1680 | ifp->bandwidth = bandwidth; | |
1681 | ||
1682 | /* force protocols to recalculate routes due to cost change */ | |
2e3b2e47 | 1683 | if (if_is_operative (ifp)) |
718e3744 | 1684 | zebra_interface_up_update (ifp); |
1685 | ||
1686 | return CMD_SUCCESS; | |
1687 | } | |
1688 | ||
1689 | DEFUN (no_bandwidth_if, | |
1690 | no_bandwidth_if_cmd, | |
1691 | "no bandwidth", | |
1692 | NO_STR | |
1693 | "Set bandwidth informational parameter\n") | |
1694 | { | |
1695 | struct interface *ifp; | |
1696 | ||
1697 | ifp = (struct interface *) vty->index; | |
1698 | ||
1699 | ifp->bandwidth = 0; | |
1700 | ||
1701 | /* force protocols to recalculate routes due to cost change */ | |
2e3b2e47 | 1702 | if (if_is_operative (ifp)) |
718e3744 | 1703 | zebra_interface_up_update (ifp); |
1704 | ||
1705 | return CMD_SUCCESS; | |
1706 | } | |
1707 | ||
1708 | ALIAS (no_bandwidth_if, | |
1709 | no_bandwidth_if_val_cmd, | |
1710 | "no bandwidth <1-10000000>", | |
1711 | NO_STR | |
1712 | "Set bandwidth informational parameter\n" | |
1713 | "Bandwidth in kilobits\n") | |
6b0655a2 | 1714 | |
a1ac18c4 | 1715 | static int |
39db97e4 | 1716 | ip_address_install (struct vty *vty, struct interface *ifp, |
1717 | const char *addr_str, const char *peer_str, | |
1718 | const char *label) | |
718e3744 | 1719 | { |
bfac8dcd | 1720 | struct zebra_if *if_data; |
718e3744 | 1721 | struct prefix_ipv4 cp; |
1722 | struct connected *ifc; | |
1723 | struct prefix_ipv4 *p; | |
718e3744 | 1724 | int ret; |
1725 | ||
bfac8dcd CF |
1726 | if_data = ifp->info; |
1727 | ||
718e3744 | 1728 | ret = str2prefix_ipv4 (addr_str, &cp); |
1729 | if (ret <= 0) | |
1730 | { | |
1731 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); | |
1732 | return CMD_WARNING; | |
1733 | } | |
1734 | ||
d914d5ff DS |
1735 | if (ipv4_martian(&cp.prefix)) |
1736 | { | |
1737 | vty_out (vty, "%% Invalid address%s", VTY_NEWLINE); | |
1738 | return CMD_WARNING; | |
1739 | } | |
1740 | ||
ca16218d | 1741 | ifc = connected_check (ifp, (struct prefix *) &cp); |
718e3744 | 1742 | if (! ifc) |
1743 | { | |
1744 | ifc = connected_new (); | |
1745 | ifc->ifp = ifp; | |
1746 | ||
1747 | /* Address. */ | |
1748 | p = prefix_ipv4_new (); | |
1749 | *p = cp; | |
1750 | ifc->address = (struct prefix *) p; | |
1751 | ||
1752 | /* Broadcast. */ | |
3fb9cd6e | 1753 | if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2) |
718e3744 | 1754 | { |
1755 | p = prefix_ipv4_new (); | |
1756 | *p = cp; | |
3fb9cd6e | 1757 | p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen); |
718e3744 | 1758 | ifc->destination = (struct prefix *) p; |
1759 | } | |
1760 | ||
718e3744 | 1761 | /* Label. */ |
1762 | if (label) | |
0752ef0b | 1763 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
718e3744 | 1764 | |
1765 | /* Add to linked list. */ | |
1766 | listnode_add (ifp->connected, ifc); | |
1767 | } | |
1768 | ||
1769 | /* This address is configured from zebra. */ | |
1770 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
1771 | SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); | |
1772 | ||
1773 | /* In case of this route need to install kernel. */ | |
f7f740fe | 1774 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
bfac8dcd CF |
1775 | && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE) |
1776 | && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) | |
718e3744 | 1777 | { |
1778 | /* Some system need to up the interface to set IP address. */ | |
1779 | if (! if_is_up (ifp)) | |
1780 | { | |
1781 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); | |
1782 | if_refresh (ifp); | |
1783 | } | |
1784 | ||
1785 | ret = if_set_prefix (ifp, ifc); | |
1786 | if (ret < 0) | |
1787 | { | |
1788 | vty_out (vty, "%% Can't set interface IP address: %s.%s", | |
6099b3b5 | 1789 | safe_strerror(errno), VTY_NEWLINE); |
718e3744 | 1790 | return CMD_WARNING; |
1791 | } | |
1792 | ||
f7f740fe | 1793 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
1794 | /* The address will be advertised to zebra clients when the notification |
1795 | * from the kernel has been received. | |
1796 | * It will also be added to the subnet chain list, then. */ | |
718e3744 | 1797 | } |
1798 | ||
1799 | return CMD_SUCCESS; | |
1800 | } | |
1801 | ||
a1ac18c4 | 1802 | static int |
39db97e4 | 1803 | ip_address_uninstall (struct vty *vty, struct interface *ifp, |
1804 | const char *addr_str, const char *peer_str, | |
1805 | const char *label) | |
718e3744 | 1806 | { |
1807 | struct prefix_ipv4 cp; | |
1808 | struct connected *ifc; | |
1809 | int ret; | |
1810 | ||
1811 | /* Convert to prefix structure. */ | |
1812 | ret = str2prefix_ipv4 (addr_str, &cp); | |
1813 | if (ret <= 0) | |
1814 | { | |
1815 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); | |
1816 | return CMD_WARNING; | |
1817 | } | |
1818 | ||
1819 | /* Check current interface address. */ | |
ca16218d | 1820 | ifc = connected_check (ifp, (struct prefix *) &cp); |
718e3744 | 1821 | if (! ifc) |
1822 | { | |
1823 | vty_out (vty, "%% Can't find address%s", VTY_NEWLINE); | |
1824 | return CMD_WARNING; | |
1825 | } | |
1826 | ||
1827 | /* This is not configured address. */ | |
1828 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
1829 | return CMD_WARNING; | |
1830 | ||
74ecdc9e PJ |
1831 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
1832 | ||
718e3744 | 1833 | /* This is not real address or interface is not active. */ |
f7f740fe | 1834 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
718e3744 | 1835 | || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
1836 | { | |
1837 | listnode_delete (ifp->connected, ifc); | |
1838 | connected_free (ifc); | |
1839 | return CMD_WARNING; | |
1840 | } | |
1841 | ||
1842 | /* This is real route. */ | |
1843 | ret = if_unset_prefix (ifp, ifc); | |
1844 | if (ret < 0) | |
1845 | { | |
1846 | vty_out (vty, "%% Can't unset interface IP address: %s.%s", | |
6099b3b5 | 1847 | safe_strerror(errno), VTY_NEWLINE); |
718e3744 | 1848 | return CMD_WARNING; |
1849 | } | |
f7f740fe | 1850 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
1851 | /* we will receive a kernel notification about this route being removed. |
1852 | * this will trigger its removal from the connected list. */ | |
718e3744 | 1853 | return CMD_SUCCESS; |
1854 | } | |
1855 | ||
1856 | DEFUN (ip_address, | |
1857 | ip_address_cmd, | |
1858 | "ip address A.B.C.D/M", | |
1859 | "Interface Internet Protocol config commands\n" | |
1860 | "Set the IP address of an interface\n" | |
1861 | "IP address (e.g. 10.0.0.1/8)\n") | |
1862 | { | |
eef1fe11 | 1863 | return ip_address_install (vty, vty->index, argv[0], NULL, NULL); |
718e3744 | 1864 | } |
1865 | ||
1866 | DEFUN (no_ip_address, | |
1867 | no_ip_address_cmd, | |
1868 | "no ip address A.B.C.D/M", | |
1869 | NO_STR | |
1870 | "Interface Internet Protocol config commands\n" | |
1871 | "Set the IP address of an interface\n" | |
1872 | "IP Address (e.g. 10.0.0.1/8)") | |
1873 | { | |
eef1fe11 | 1874 | return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL); |
718e3744 | 1875 | } |
1876 | ||
1877 | #ifdef HAVE_NETLINK | |
718e3744 | 1878 | DEFUN (ip_address_label, |
1879 | ip_address_label_cmd, | |
1880 | "ip address A.B.C.D/M label LINE", | |
1881 | "Interface Internet Protocol config commands\n" | |
1882 | "Set the IP address of an interface\n" | |
1883 | "IP address (e.g. 10.0.0.1/8)\n" | |
1884 | "Label of this address\n" | |
1885 | "Label\n") | |
1886 | { | |
eef1fe11 | 1887 | return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]); |
718e3744 | 1888 | } |
1889 | ||
1890 | DEFUN (no_ip_address_label, | |
1891 | no_ip_address_label_cmd, | |
1892 | "no ip address A.B.C.D/M label LINE", | |
1893 | NO_STR | |
1894 | "Interface Internet Protocol config commands\n" | |
1895 | "Set the IP address of an interface\n" | |
1896 | "IP address (e.g. 10.0.0.1/8)\n" | |
1897 | "Label of this address\n" | |
1898 | "Label\n") | |
1899 | { | |
eef1fe11 | 1900 | return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]); |
718e3744 | 1901 | } |
1902 | #endif /* HAVE_NETLINK */ | |
1903 | ||
1904 | #ifdef HAVE_IPV6 | |
a1ac18c4 | 1905 | static int |
39db97e4 | 1906 | ipv6_address_install (struct vty *vty, struct interface *ifp, |
1907 | const char *addr_str, const char *peer_str, | |
1908 | const char *label, int secondary) | |
718e3744 | 1909 | { |
bfac8dcd | 1910 | struct zebra_if *if_data; |
718e3744 | 1911 | struct prefix_ipv6 cp; |
1912 | struct connected *ifc; | |
1913 | struct prefix_ipv6 *p; | |
1914 | int ret; | |
1915 | ||
bfac8dcd CF |
1916 | if_data = ifp->info; |
1917 | ||
718e3744 | 1918 | ret = str2prefix_ipv6 (addr_str, &cp); |
1919 | if (ret <= 0) | |
1920 | { | |
1921 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); | |
1922 | return CMD_WARNING; | |
1923 | } | |
1924 | ||
d914d5ff DS |
1925 | if (ipv6_martian(&cp.prefix)) |
1926 | { | |
1927 | vty_out (vty, "%% Invalid address%s", VTY_NEWLINE); | |
1928 | return CMD_WARNING; | |
1929 | } | |
1930 | ||
ca16218d | 1931 | ifc = connected_check (ifp, (struct prefix *) &cp); |
718e3744 | 1932 | if (! ifc) |
1933 | { | |
1934 | ifc = connected_new (); | |
1935 | ifc->ifp = ifp; | |
1936 | ||
1937 | /* Address. */ | |
1938 | p = prefix_ipv6_new (); | |
1939 | *p = cp; | |
1940 | ifc->address = (struct prefix *) p; | |
1941 | ||
1942 | /* Secondary. */ | |
1943 | if (secondary) | |
1944 | SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); | |
1945 | ||
1946 | /* Label. */ | |
1947 | if (label) | |
0752ef0b | 1948 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
718e3744 | 1949 | |
1950 | /* Add to linked list. */ | |
1951 | listnode_add (ifp->connected, ifc); | |
b6120505 | 1952 | |
30a3822f | 1953 | /* Enable RA on this interface */ |
1954 | if (interface_ipv6_auto_ra_allowed (ifp)) | |
1955 | ipv6_nd_suppress_ra_set (ifp, RA_ENABLE); | |
718e3744 | 1956 | } |
1957 | ||
1958 | /* This address is configured from zebra. */ | |
1959 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
1960 | SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); | |
1961 | ||
1962 | /* In case of this route need to install kernel. */ | |
f7f740fe | 1963 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
bfac8dcd CF |
1964 | && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE) |
1965 | && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) | |
718e3744 | 1966 | { |
1967 | /* Some system need to up the interface to set IP address. */ | |
1968 | if (! if_is_up (ifp)) | |
1969 | { | |
1970 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); | |
1971 | if_refresh (ifp); | |
1972 | } | |
1973 | ||
1974 | ret = if_prefix_add_ipv6 (ifp, ifc); | |
1975 | ||
1976 | if (ret < 0) | |
1977 | { | |
1978 | vty_out (vty, "%% Can't set interface IP address: %s.%s", | |
6099b3b5 | 1979 | safe_strerror(errno), VTY_NEWLINE); |
718e3744 | 1980 | return CMD_WARNING; |
1981 | } | |
1982 | ||
f7f740fe | 1983 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
1984 | /* The address will be advertised to zebra clients when the notification |
1985 | * from the kernel has been received. */ | |
718e3744 | 1986 | } |
1987 | ||
1988 | return CMD_SUCCESS; | |
1989 | } | |
1990 | ||
b6120505 DW |
1991 | /* Return true if an ipv6 address is configured on ifp */ |
1992 | int | |
1993 | ipv6_address_configured (struct interface *ifp) | |
1994 | { | |
1995 | struct connected *connected; | |
1996 | struct listnode *node; | |
1997 | ||
1998 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) | |
1999 | if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && (connected->address->family == AF_INET6)) | |
2000 | return 1; | |
2001 | ||
2002 | return 0; | |
2003 | } | |
2004 | ||
a1ac18c4 | 2005 | static int |
39db97e4 | 2006 | ipv6_address_uninstall (struct vty *vty, struct interface *ifp, |
2007 | const char *addr_str, const char *peer_str, | |
2008 | const char *label, int secondry) | |
718e3744 | 2009 | { |
2010 | struct prefix_ipv6 cp; | |
2011 | struct connected *ifc; | |
2012 | int ret; | |
2013 | ||
2014 | /* Convert to prefix structure. */ | |
2015 | ret = str2prefix_ipv6 (addr_str, &cp); | |
2016 | if (ret <= 0) | |
2017 | { | |
2018 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); | |
2019 | return CMD_WARNING; | |
2020 | } | |
2021 | ||
2022 | /* Check current interface address. */ | |
ca16218d | 2023 | ifc = connected_check (ifp, (struct prefix *) &cp); |
718e3744 | 2024 | if (! ifc) |
2025 | { | |
2026 | vty_out (vty, "%% Can't find address%s", VTY_NEWLINE); | |
2027 | return CMD_WARNING; | |
2028 | } | |
2029 | ||
2030 | /* This is not configured address. */ | |
2031 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) | |
2032 | return CMD_WARNING; | |
2033 | ||
676e1a01 CF |
2034 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
2035 | ||
718e3744 | 2036 | /* This is not real address or interface is not active. */ |
f7f740fe | 2037 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
718e3744 | 2038 | || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
2039 | { | |
2040 | listnode_delete (ifp->connected, ifc); | |
2041 | connected_free (ifc); | |
2042 | return CMD_WARNING; | |
2043 | } | |
2044 | ||
2045 | /* This is real route. */ | |
2046 | ret = if_prefix_delete_ipv6 (ifp, ifc); | |
2047 | if (ret < 0) | |
2048 | { | |
2049 | vty_out (vty, "%% Can't unset interface IP address: %s.%s", | |
6099b3b5 | 2050 | safe_strerror(errno), VTY_NEWLINE); |
718e3744 | 2051 | return CMD_WARNING; |
2052 | } | |
2053 | ||
b6120505 | 2054 | /* Enable RA suppression if there are no IPv6 addresses on this interface */ |
30a3822f | 2055 | if (interface_ipv6_auto_ra_allowed (ifp)) |
2056 | { | |
2057 | if (! ipv6_address_configured(ifp)) | |
2058 | ipv6_nd_suppress_ra_set (ifp, RA_SUPPRESS); | |
2059 | } | |
b6120505 | 2060 | |
f7f740fe | 2061 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
02b4805f CF |
2062 | /* This information will be propagated to the zclients when the |
2063 | * kernel notification is received. */ | |
718e3744 | 2064 | return CMD_SUCCESS; |
2065 | } | |
2066 | ||
2067 | DEFUN (ipv6_address, | |
2068 | ipv6_address_cmd, | |
2069 | "ipv6 address X:X::X:X/M", | |
e23949c0 | 2070 | "Interface IPv6 config commands\n" |
718e3744 | 2071 | "Set the IP address of an interface\n" |
2072 | "IPv6 address (e.g. 3ffe:506::1/48)\n") | |
2073 | { | |
2074 | return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0); | |
2075 | } | |
2076 | ||
2077 | DEFUN (no_ipv6_address, | |
2078 | no_ipv6_address_cmd, | |
2079 | "no ipv6 address X:X::X:X/M", | |
2080 | NO_STR | |
e23949c0 | 2081 | "Interface IPv6 config commands\n" |
718e3744 | 2082 | "Set the IP address of an interface\n" |
2083 | "IPv6 address (e.g. 3ffe:506::1/48)\n") | |
2084 | { | |
2085 | return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0); | |
2086 | } | |
2087 | #endif /* HAVE_IPV6 */ | |
2088 | ||
a1ac18c4 | 2089 | static int |
718e3744 | 2090 | if_config_write (struct vty *vty) |
2091 | { | |
52dc7ee6 | 2092 | struct listnode *node; |
718e3744 | 2093 | struct interface *ifp; |
cd2a8a42 | 2094 | vrf_iter_t iter; |
718e3744 | 2095 | |
244c1cdc DS |
2096 | zebra_ptm_write (vty); |
2097 | ||
cd2a8a42 FL |
2098 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
2099 | for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) | |
718e3744 | 2100 | { |
2101 | struct zebra_if *if_data; | |
52dc7ee6 | 2102 | struct listnode *addrnode; |
718e3744 | 2103 | struct connected *ifc; |
2104 | struct prefix *p; | |
12f6fb97 | 2105 | struct vrf *vrf; |
718e3744 | 2106 | |
718e3744 | 2107 | if_data = ifp->info; |
12f6fb97 | 2108 | vrf = vrf_lookup(ifp->vrf_id); |
cd2a8a42 FL |
2109 | |
2110 | if (ifp->vrf_id == VRF_DEFAULT) | |
2111 | vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE); | |
2112 | else | |
12f6fb97 | 2113 | vty_out (vty, "interface %s vrf %s%s", ifp->name, vrf->name, |
cd2a8a42 | 2114 | VTY_NEWLINE); |
718e3744 | 2115 | |
bfac8dcd CF |
2116 | if (if_data) |
2117 | { | |
2118 | if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) | |
2119 | vty_out (vty, " shutdown%s", VTY_NEWLINE); | |
2120 | } | |
2121 | ||
718e3744 | 2122 | if (ifp->desc) |
2123 | vty_out (vty, " description %s%s", ifp->desc, | |
2124 | VTY_NEWLINE); | |
2125 | ||
2126 | /* Assign bandwidth here to avoid unnecessary interface flap | |
2127 | while processing config script */ | |
2128 | if (ifp->bandwidth != 0) | |
2129 | vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE); | |
2130 | ||
2e3b2e47 | 2131 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) |
2132 | vty_out(vty, " link-detect%s", VTY_NEWLINE); | |
2133 | ||
1eb8ef25 | 2134 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc)) |
718e3744 | 2135 | { |
718e3744 | 2136 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
2137 | { | |
81cce018 | 2138 | char buf[INET6_ADDRSTRLEN]; |
718e3744 | 2139 | p = ifc->address; |
2140 | vty_out (vty, " ip%s address %s/%d", | |
2141 | p->family == AF_INET ? "" : "v6", | |
81cce018 | 2142 | inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)), |
718e3744 | 2143 | p->prefixlen); |
2144 | ||
718e3744 | 2145 | if (ifc->label) |
2146 | vty_out (vty, " label %s", ifc->label); | |
2147 | ||
2148 | vty_out (vty, "%s", VTY_NEWLINE); | |
2149 | } | |
2150 | } | |
2151 | ||
2152 | if (if_data) | |
2153 | { | |
718e3744 | 2154 | if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC) |
2155 | vty_out (vty, " %smulticast%s", | |
2156 | if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ", | |
2157 | VTY_NEWLINE); | |
2158 | } | |
2159 | ||
8da4e946 | 2160 | #if defined (HAVE_RTADV) |
718e3744 | 2161 | rtadv_config_write (vty, ifp); |
8da4e946 | 2162 | #endif /* HAVE_RTADV */ |
718e3744 | 2163 | |
ca776988 | 2164 | #ifdef HAVE_IRDP |
2165 | irdp_config_write (vty, ifp); | |
2166 | #endif /* IRDP */ | |
2167 | ||
718e3744 | 2168 | vty_out (vty, "!%s", VTY_NEWLINE); |
2169 | } | |
2170 | return 0; | |
2171 | } | |
2172 | ||
12f6fb97 DS |
2173 | static int |
2174 | vrf_config_write (struct vty *vty) | |
2175 | { | |
2176 | struct listnode *node; | |
2177 | struct vrf *vrf; | |
2178 | ||
2179 | for (ALL_LIST_ELEMENTS_RO (vrf_list, node, vrf)) | |
2180 | { | |
2181 | if (strcmp(vrf->name, VRF_DEFAULT_NAME)) | |
2182 | { | |
2183 | vty_out (vty, "vrf %s%s", vrf->name, VTY_NEWLINE); | |
2184 | vty_out (vty, "!%s", VTY_NEWLINE); | |
2185 | } | |
2186 | } | |
2187 | return 0; | |
2188 | } | |
2189 | ||
718e3744 | 2190 | /* Allocate and initialize interface vector. */ |
2191 | void | |
a1ac18c4 | 2192 | zebra_if_init (void) |
718e3744 | 2193 | { |
2194 | /* Initialize interface and new hook. */ | |
718e3744 | 2195 | if_add_hook (IF_NEW_HOOK, if_zebra_new_hook); |
2196 | if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook); | |
2197 | ||
2198 | /* Install configuration write function. */ | |
2199 | install_node (&interface_node, if_config_write); | |
12f6fb97 | 2200 | install_node (&vrf_node, vrf_config_write); |
718e3744 | 2201 | |
2202 | install_element (VIEW_NODE, &show_interface_cmd); | |
8b87bdf4 FL |
2203 | install_element (VIEW_NODE, &show_interface_vrf_cmd); |
2204 | install_element (VIEW_NODE, &show_interface_vrf_all_cmd); | |
2205 | install_element (VIEW_NODE, &show_interface_name_cmd); | |
2206 | install_element (VIEW_NODE, &show_interface_name_vrf_cmd); | |
2207 | install_element (VIEW_NODE, &show_interface_name_vrf_all_cmd); | |
718e3744 | 2208 | install_element (ENABLE_NODE, &show_interface_cmd); |
8b87bdf4 FL |
2209 | install_element (ENABLE_NODE, &show_interface_vrf_cmd); |
2210 | install_element (ENABLE_NODE, &show_interface_vrf_all_cmd); | |
2211 | install_element (ENABLE_NODE, &show_interface_name_cmd); | |
2212 | install_element (ENABLE_NODE, &show_interface_name_vrf_cmd); | |
2213 | install_element (ENABLE_NODE, &show_interface_name_vrf_all_cmd); | |
ed9bb6d5 | 2214 | install_element (ENABLE_NODE, &show_interface_desc_cmd); |
8b87bdf4 FL |
2215 | install_element (ENABLE_NODE, &show_interface_desc_vrf_cmd); |
2216 | install_element (ENABLE_NODE, &show_interface_desc_vrf_all_cmd); | |
718e3744 | 2217 | install_element (CONFIG_NODE, &zebra_interface_cmd); |
cd2a8a42 | 2218 | install_element (CONFIG_NODE, &zebra_interface_vrf_cmd); |
bfc13532 | 2219 | install_element (CONFIG_NODE, &no_interface_cmd); |
cd2a8a42 | 2220 | install_element (CONFIG_NODE, &no_interface_vrf_cmd); |
718e3744 | 2221 | install_default (INTERFACE_NODE); |
2222 | install_element (INTERFACE_NODE, &interface_desc_cmd); | |
2223 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); | |
2224 | install_element (INTERFACE_NODE, &multicast_cmd); | |
2225 | install_element (INTERFACE_NODE, &no_multicast_cmd); | |
2e3b2e47 | 2226 | install_element (INTERFACE_NODE, &linkdetect_cmd); |
2227 | install_element (INTERFACE_NODE, &no_linkdetect_cmd); | |
718e3744 | 2228 | install_element (INTERFACE_NODE, &shutdown_if_cmd); |
2229 | install_element (INTERFACE_NODE, &no_shutdown_if_cmd); | |
2230 | install_element (INTERFACE_NODE, &bandwidth_if_cmd); | |
2231 | install_element (INTERFACE_NODE, &no_bandwidth_if_cmd); | |
2232 | install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd); | |
2233 | install_element (INTERFACE_NODE, &ip_address_cmd); | |
2234 | install_element (INTERFACE_NODE, &no_ip_address_cmd); | |
2235 | #ifdef HAVE_IPV6 | |
2236 | install_element (INTERFACE_NODE, &ipv6_address_cmd); | |
2237 | install_element (INTERFACE_NODE, &no_ipv6_address_cmd); | |
2238 | #endif /* HAVE_IPV6 */ | |
718e3744 | 2239 | #ifdef HAVE_NETLINK |
718e3744 | 2240 | install_element (INTERFACE_NODE, &ip_address_label_cmd); |
718e3744 | 2241 | install_element (INTERFACE_NODE, &no_ip_address_label_cmd); |
2242 | #endif /* HAVE_NETLINK */ | |
12f6fb97 DS |
2243 | |
2244 | install_element (CONFIG_NODE, &zebra_vrf_cmd); | |
2245 | install_element (CONFIG_NODE, &no_vrf_cmd); | |
2246 | install_default (VRF_NODE); | |
2247 | ||
718e3744 | 2248 | } |