blob: f259eeb2e053783b570d390a896a0198e2ba38e4 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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"
Feng Lu471ea392015-05-22 11:40:00 +020035#include "vrf.h"
Christian Franke581ecbf2016-05-03 19:59:43 +020036#include "command.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "zebra/interface.h"
39#include "zebra/rtadv.h"
40#include "zebra/rib.h"
41#include "zebra/zserv.h"
42#include "zebra/redistribute.h"
43#include "zebra/debug.h"
hassoca776982004-06-12 14:33:05 +000044#include "zebra/irdp.h"
paul718e3742002-12-13 20:15:29 +000045
Donald Sharp64257732015-11-20 08:33:30 -050046#if defined (HAVE_RTADV)
Chris Caputob60668d2009-05-03 04:40:57 +000047/* Order is intentional. Matches RFC4191. This array is also used for
48 command matching, so only modify with care. */
49const char *rtadv_pref_strs[] = { "medium", "high", "INVALID", "low", 0 };
Donald Sharp64257732015-11-20 08:33:30 -050050#endif /* HAVE_RTADV */
paul718e3742002-12-13 20:15:29 +000051
52/* Called when new interface is added. */
paula1ac18c2005-06-28 17:17:12 +000053static int
paul718e3742002-12-13 20:15:29 +000054if_zebra_new_hook (struct interface *ifp)
55{
56 struct zebra_if *zebra_if;
57
Stephen Hemminger393deb92008-08-18 14:13:29 -070058 zebra_if = XCALLOC (MTYPE_TMP, sizeof (struct zebra_if));
paul718e3742002-12-13 20:15:29 +000059
60 zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC;
Christian Frankebfac8dc2013-01-24 14:04:50 +000061 zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
paul718e3742002-12-13 20:15:29 +000062
Donald Sharp64257732015-11-20 08:33:30 -050063#if defined (HAVE_RTADV)
paul718e3742002-12-13 20:15:29 +000064 {
65 /* Set default router advertise values. */
66 struct rtadvconf *rtadv;
67
68 rtadv = &zebra_if->rtadv;
69
70 rtadv->AdvSendAdvertisements = 0;
71 rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL;
72 rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL;
73 rtadv->AdvIntervalTimer = 0;
74 rtadv->AdvManagedFlag = 0;
75 rtadv->AdvOtherConfigFlag = 0;
vincent7cee1bb2005-03-25 13:08:53 +000076 rtadv->AdvHomeAgentFlag = 0;
paul718e3742002-12-13 20:15:29 +000077 rtadv->AdvLinkMTU = 0;
78 rtadv->AdvReachableTime = 0;
79 rtadv->AdvRetransTimer = 0;
80 rtadv->AdvCurHopLimit = 0;
Denis Ovsienkod660f692011-12-30 21:55:49 +040081 rtadv->AdvDefaultLifetime = -1; /* derive from MaxRtrAdvInterval */
vincent7cee1bb2005-03-25 13:08:53 +000082 rtadv->HomeAgentPreference = 0;
Denis Ovsienkod660f692011-12-30 21:55:49 +040083 rtadv->HomeAgentLifetime = -1; /* derive from AdvDefaultLifetime */
vincent7cee1bb2005-03-25 13:08:53 +000084 rtadv->AdvIntervalOption = 0;
Chris Caputob60668d2009-05-03 04:40:57 +000085 rtadv->DefaultPreference = RTADV_PREF_MEDIUM;
paul718e3742002-12-13 20:15:29 +000086
87 rtadv->AdvPrefixList = list_new ();
88 }
Donald Sharp64257732015-11-20 08:33:30 -050089#endif /* HAVE_RTADV */
paul718e3742002-12-13 20:15:29 +000090
hassoeef1fe12004-10-03 18:46:08 +000091 /* Initialize installed address chains tree. */
92 zebra_if->ipv4_subnets = route_table_init ();
93
paul718e3742002-12-13 20:15:29 +000094 ifp->info = zebra_if;
95 return 0;
96}
97
98/* Called when interface is deleted. */
paula1ac18c2005-06-28 17:17:12 +000099static int
paul718e3742002-12-13 20:15:29 +0000100if_zebra_delete_hook (struct interface *ifp)
101{
hassoeef1fe12004-10-03 18:46:08 +0000102 struct zebra_if *zebra_if;
103
paul718e3742002-12-13 20:15:29 +0000104 if (ifp->info)
hassoeef1fe12004-10-03 18:46:08 +0000105 {
106 zebra_if = ifp->info;
107
108 /* Free installed address chains tree. */
109 if (zebra_if->ipv4_subnets)
110 route_table_finish (zebra_if->ipv4_subnets);
111
112 XFREE (MTYPE_TMP, zebra_if);
113 }
114
115 return 0;
116}
117
118/* Tie an interface address to its derived subnet list of addresses. */
119int
120if_subnet_add (struct interface *ifp, struct connected *ifc)
121{
122 struct route_node *rn;
123 struct zebra_if *zebra_if;
124 struct prefix cp;
125 struct list *addr_list;
126
127 assert (ifp && ifp->info && ifc);
128 zebra_if = ifp->info;
129
130 /* Get address derived subnet node and associated address list, while marking
131 address secondary attribute appropriately. */
132 cp = *ifc->address;
133 apply_mask (&cp);
134 rn = route_node_get (zebra_if->ipv4_subnets, &cp);
135
136 if ((addr_list = rn->info))
137 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
138 else
139 {
140 UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
141 rn->info = addr_list = list_new ();
142 route_lock_node (rn);
143 }
144
145 /* Tie address at the tail of address list. */
146 listnode_add (addr_list, ifc);
147
148 /* Return list element count. */
149 return (addr_list->count);
150}
151
152/* Untie an interface address from its derived subnet list of addresses. */
153int
154if_subnet_delete (struct interface *ifp, struct connected *ifc)
155{
156 struct route_node *rn;
157 struct zebra_if *zebra_if;
158 struct list *addr_list;
159
160 assert (ifp && ifp->info && ifc);
161 zebra_if = ifp->info;
162
163 /* Get address derived subnet node. */
164 rn = route_node_lookup (zebra_if->ipv4_subnets, ifc->address);
165 if (! (rn && rn->info))
Christian Franke9db047f2013-01-24 14:04:44 +0000166 {
167 zlog_warn("Trying to remove an address from an unknown subnet."
168 " (please report this bug)");
169 return -1;
170 }
hassoeef1fe12004-10-03 18:46:08 +0000171 route_unlock_node (rn);
172
173 /* Untie address from subnet's address list. */
174 addr_list = rn->info;
Christian Franke9db047f2013-01-24 14:04:44 +0000175
176 /* Deleting an address that is not registered is a bug.
177 * In any case, we shouldn't decrement the lock counter if the address
178 * is unknown. */
179 if (!listnode_lookup(addr_list, ifc))
180 {
181 zlog_warn("Trying to remove an address from a subnet where it is not"
182 " currently registered. (please report this bug)");
183 return -1;
184 }
185
hassoeef1fe12004-10-03 18:46:08 +0000186 listnode_delete (addr_list, ifc);
187 route_unlock_node (rn);
188
189 /* Return list element count, if not empty. */
190 if (addr_list->count)
191 {
192 /* If deleted address is primary, mark subsequent one as such and distribute. */
193 if (! CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY))
194 {
Olivier Dugeon15773a82016-04-19 18:29:55 +0200195 ifc = listgetdata ((struct listnode *)listhead (addr_list));
hassoeef1fe12004-10-03 18:46:08 +0000196 zebra_interface_address_delete_update (ifp, ifc);
197 UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
Christian Franke02b48052013-01-24 14:04:49 +0000198 /* XXX: Linux kernel removes all the secondary addresses when the primary
199 * address is removed. We could try to work around that, though this is
200 * non-trivial. */
hassoeef1fe12004-10-03 18:46:08 +0000201 zebra_interface_address_add_update (ifp, ifc);
202 }
203
204 return addr_list->count;
205 }
206
207 /* Otherwise, free list and route node. */
208 list_free (addr_list);
209 rn->info = NULL;
210 route_unlock_node (rn);
211
paul718e3742002-12-13 20:15:29 +0000212 return 0;
213}
214
paul5c78b3d2006-01-25 04:31:40 +0000215/* if_flags_mangle: A place for hacks that require mangling
216 * or tweaking the interface flags.
217 *
218 * ******************** Solaris flags hacks **************************
219 *
220 * Solaris IFF_UP flag reflects only the primary interface as the
221 * routing socket only sends IFINFO for the primary interface. Hence
222 * ~IFF_UP does not per se imply all the logical interfaces are also
223 * down - which we only know of as addresses. Instead we must determine
224 * whether the interface really is up or not according to how many
225 * addresses are still attached. (Solaris always sends RTM_DELADDR if
226 * an interface, logical or not, goes ~IFF_UP).
227 *
228 * Ie, we mangle IFF_UP to *additionally* reflect whether or not there
229 * are addresses left in struct connected, not just the actual underlying
230 * IFF_UP flag.
231 *
232 * We must hence remember the real state of IFF_UP, which we do in
233 * struct zebra_if.primary_state.
234 *
235 * Setting IFF_UP within zebra to administratively shutdown the
236 * interface will affect only the primary interface/address on Solaris.
237 ************************End Solaris flags hacks ***********************
238 */
Paul Jakmaf63f06d2011-04-08 12:44:43 +0100239static void
paul5c78b3d2006-01-25 04:31:40 +0000240if_flags_mangle (struct interface *ifp, uint64_t *newflags)
241{
242#ifdef SUNOS_5
243 struct zebra_if *zif = ifp->info;
244
245 zif->primary_state = *newflags & (IFF_UP & 0xff);
246
247 if (CHECK_FLAG (zif->primary_state, IFF_UP)
248 || listcount(ifp->connected) > 0)
249 SET_FLAG (*newflags, IFF_UP);
250 else
251 UNSET_FLAG (*newflags, IFF_UP);
252#endif /* SUNOS_5 */
253}
254
255/* Update the flags field of the ifp with the new flag set provided.
256 * Take whatever actions are required for any changes in flags we care
257 * about.
258 *
259 * newflags should be the raw value, as obtained from the OS.
260 */
261void
262if_flags_update (struct interface *ifp, uint64_t newflags)
263{
264 if_flags_mangle (ifp, &newflags);
265
266 if (if_is_operative (ifp))
267 {
268 /* operative -> inoperative? */
269 ifp->flags = newflags;
270 if (!if_is_operative (ifp))
271 if_down (ifp);
272 }
273 else
274 {
275 /* inoperative -> operative? */
276 ifp->flags = newflags;
277 if (if_is_operative (ifp))
278 if_up (ifp);
279 }
280}
281
paul718e3742002-12-13 20:15:29 +0000282/* Wake up configured address if it is not in current kernel
283 address. */
paula1ac18c2005-06-28 17:17:12 +0000284static void
paul718e3742002-12-13 20:15:29 +0000285if_addr_wakeup (struct interface *ifp)
286{
paul1eb8ef22005-04-07 07:30:20 +0000287 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000288 struct connected *ifc;
289 struct prefix *p;
290 int ret;
291
paul1eb8ef22005-04-07 07:30:20 +0000292 for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc))
paul718e3742002-12-13 20:15:29 +0000293 {
paul718e3742002-12-13 20:15:29 +0000294 p = ifc->address;
295
296 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)
Christian Frankef7f740f2013-01-24 14:04:48 +0000297 && ! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED))
paul718e3742002-12-13 20:15:29 +0000298 {
299 /* Address check. */
300 if (p->family == AF_INET)
301 {
302 if (! if_is_up (ifp))
303 {
Christian Franke02b48052013-01-24 14:04:49 +0000304 /* Assume zebra is configured like following:
305 *
306 * interface gre0
307 * ip addr 192.0.2.1/24
308 * !
309 *
310 * As soon as zebra becomes first aware that gre0 exists in the
311 * kernel, it will set gre0 up and configure its addresses.
312 *
313 * (This may happen at startup when the interface already exists
314 * or during runtime when the interface is added to the kernel)
315 *
316 * XXX: IRDP code is calling here via if_add_update - this seems
317 * somewhat weird.
318 * XXX: RUNNING is not a settable flag on any system
319 * I (paulj) am aware of.
320 */
paul718e3742002-12-13 20:15:29 +0000321 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
322 if_refresh (ifp);
323 }
324
325 ret = if_set_prefix (ifp, ifc);
326 if (ret < 0)
327 {
328 zlog_warn ("Can't set interface's address: %s",
ajs6099b3b2004-11-20 02:06:59 +0000329 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +0000330 continue;
331 }
hassoeef1fe12004-10-03 18:46:08 +0000332
Christian Frankef7f740f2013-01-24 14:04:48 +0000333 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
Christian Franke02b48052013-01-24 14:04:49 +0000334 /* The address will be advertised to zebra clients when the notification
335 * from the kernel has been received.
336 * It will also be added to the interface's subnet list then. */
paul718e3742002-12-13 20:15:29 +0000337 }
338#ifdef HAVE_IPV6
339 if (p->family == AF_INET6)
340 {
341 if (! if_is_up (ifp))
342 {
Christian Franke02b48052013-01-24 14:04:49 +0000343 /* See long comment above */
paul718e3742002-12-13 20:15:29 +0000344 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
345 if_refresh (ifp);
346 }
347
348 ret = if_prefix_add_ipv6 (ifp, ifc);
349 if (ret < 0)
350 {
351 zlog_warn ("Can't set interface's address: %s",
ajs6099b3b2004-11-20 02:06:59 +0000352 safe_strerror(errno));
paul718e3742002-12-13 20:15:29 +0000353 continue;
354 }
Christian Franke02b48052013-01-24 14:04:49 +0000355
Christian Frankef7f740f2013-01-24 14:04:48 +0000356 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
Christian Franke02b48052013-01-24 14:04:49 +0000357 /* The address will be advertised to zebra clients when the notification
358 * from the kernel has been received. */
paul718e3742002-12-13 20:15:29 +0000359 }
360#endif /* HAVE_IPV6 */
361 }
362 }
363}
364
Christian Franke581ecbf2016-05-03 19:59:43 +0200365static void if_count_up(struct zebra_if *zif)
366{
367 event_counter_inc(&zif->up_events);
368}
369
370static void if_count_down(struct zebra_if *zif)
371{
372 event_counter_inc(&zif->down_events);
373}
374
375void
376if_startup_count_up (void)
377{
378 vrf_iter_t iter;
379 struct interface *ifp;
380 struct zebra_if *zif;
381 struct listnode *node;
382
383 for (iter = vrf_first(); iter != VRF_ITER_INVALID; iter = vrf_next(iter))
384 {
385 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist(iter), node, ifp))
386 {
387 zif = ifp->info;
388 if (!zif->up_events.count && if_is_operative(ifp))
389 if_count_up(zif);
390 }
391 }
392}
393
paul718e3742002-12-13 20:15:29 +0000394/* Handle interface addition */
395void
396if_add_update (struct interface *ifp)
397{
paul48b33aa2002-12-13 20:52:52 +0000398 struct zebra_if *if_data;
399
400 if_data = ifp->info;
Morgan Stewartc8394ac2015-09-17 19:04:30 -0400401 assert(if_data);
402
paul48b33aa2002-12-13 20:52:52 +0000403 if (if_data->multicast == IF_ZEBRA_MULTICAST_ON)
404 if_set_flags (ifp, IFF_MULTICAST);
405 else if (if_data->multicast == IF_ZEBRA_MULTICAST_OFF)
406 if_unset_flags (ifp, IFF_MULTICAST);
407
paul718e3742002-12-13 20:15:29 +0000408 zebra_interface_add_update (ifp);
409
410 if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
411 {
412 SET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
413
Christian Frankebfac8dc2013-01-24 14:04:50 +0000414 if (if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
415 {
416 if (IS_ZEBRA_DEBUG_KERNEL)
Feng Lu2fc97f62015-05-22 11:39:57 +0200417 zlog_debug ("interface %s vrf %u index %d is shutdown. "
418 "Won't wake it up.",
419 ifp->name, ifp->vrf_id, ifp->ifindex);
Christian Frankebfac8dc2013-01-24 14:04:50 +0000420 return;
421 }
422
paul718e3742002-12-13 20:15:29 +0000423 if_addr_wakeup (ifp);
424
425 if (IS_ZEBRA_DEBUG_KERNEL)
Feng Lu2fc97f62015-05-22 11:39:57 +0200426 zlog_debug ("interface %s vrf %u index %d becomes active.",
427 ifp->name, ifp->vrf_id, ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000428 }
429 else
430 {
431 if (IS_ZEBRA_DEBUG_KERNEL)
Feng Lu2fc97f62015-05-22 11:39:57 +0200432 zlog_debug ("interface %s vrf %u index %d is added.",
433 ifp->name, ifp->vrf_id, ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000434 }
Christian Franke581ecbf2016-05-03 19:59:43 +0200435
436 if (host_config_get())
437 {
438 /* If configuration and therefore link-detect have already been
439 * loaded, count an initial up event when new interfaces are added
440 * in up state.
441 * If configuration has not been loaded yet, this is handled by
442 * if_startup_count_up which is called after reading the config. */
443 if (!if_data->up_events.count && if_is_operative(ifp))
444 if_count_up(if_data);
445 }
paul718e3742002-12-13 20:15:29 +0000446}
447
paul6eb88272005-07-29 14:36:00 +0000448/* Handle an interface delete event */
paul718e3742002-12-13 20:15:29 +0000449void
450if_delete_update (struct interface *ifp)
451{
paul718e3742002-12-13 20:15:29 +0000452 struct connected *ifc;
453 struct prefix *p;
hassoeef1fe12004-10-03 18:46:08 +0000454 struct route_node *rn;
455 struct zebra_if *zebra_if;
hassoeef1fe12004-10-03 18:46:08 +0000456
457 zebra_if = ifp->info;
paul718e3742002-12-13 20:15:29 +0000458
459 if (if_is_up(ifp))
460 {
Feng Lu2fc97f62015-05-22 11:39:57 +0200461 zlog_err ("interface %s vrf %u index %d is still up while being deleted.",
462 ifp->name, ifp->vrf_id, ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000463 return;
464 }
465
466 /* Mark interface as inactive */
467 UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
468
469 if (IS_ZEBRA_DEBUG_KERNEL)
Feng Lu2fc97f62015-05-22 11:39:57 +0200470 zlog_debug ("interface %s vrf %u index %d is now inactive.",
471 ifp->name, ifp->vrf_id, ifp->ifindex);
paul718e3742002-12-13 20:15:29 +0000472
473 /* Delete connected routes from the kernel. */
474 if (ifp->connected)
475 {
Paul Jakmad9a18f12007-04-10 19:30:20 +0000476 struct listnode *node;
477 struct listnode *last = NULL;
478
hassoeef1fe12004-10-03 18:46:08 +0000479 while ((node = (last ? last->next : listhead (ifp->connected))))
paul718e3742002-12-13 20:15:29 +0000480 {
paul1eb8ef22005-04-07 07:30:20 +0000481 ifc = listgetdata (node);
paul718e3742002-12-13 20:15:29 +0000482 p = ifc->address;
hassoeef1fe12004-10-03 18:46:08 +0000483
Paul Jakmabeb56332006-05-11 13:28:05 +0000484 if (p->family == AF_INET
485 && (rn = route_node_lookup (zebra_if->ipv4_subnets, p)))
hassoeef1fe12004-10-03 18:46:08 +0000486 {
Paul Jakmad9a18f12007-04-10 19:30:20 +0000487 struct listnode *anode;
488 struct listnode *next;
489 struct listnode *first;
490 struct list *addr_list;
491
hassoeef1fe12004-10-03 18:46:08 +0000492 route_unlock_node (rn);
493 addr_list = (struct list *) rn->info;
494
495 /* Remove addresses, secondaries first. */
496 first = listhead (addr_list);
Paul Jakmad9a18f12007-04-10 19:30:20 +0000497 for (anode = first->next; anode || first; anode = next)
hassoeef1fe12004-10-03 18:46:08 +0000498 {
Paul Jakmad9a18f12007-04-10 19:30:20 +0000499 if (!anode)
hassoeef1fe12004-10-03 18:46:08 +0000500 {
Paul Jakmad9a18f12007-04-10 19:30:20 +0000501 anode = first;
hassoeef1fe12004-10-03 18:46:08 +0000502 first = NULL;
503 }
Paul Jakmad9a18f12007-04-10 19:30:20 +0000504 next = anode->next;
hassoeef1fe12004-10-03 18:46:08 +0000505
Paul Jakmad9a18f12007-04-10 19:30:20 +0000506 ifc = listgetdata (anode);
hassoeef1fe12004-10-03 18:46:08 +0000507 p = ifc->address;
hassoeef1fe12004-10-03 18:46:08 +0000508 connected_down_ipv4 (ifp, ifc);
509
Christian Franke02b48052013-01-24 14:04:49 +0000510 /* XXX: We have to send notifications here explicitly, because we destroy
511 * the ifc before receiving the notification about the address being deleted.
512 */
hassoeef1fe12004-10-03 18:46:08 +0000513 zebra_interface_address_delete_update (ifp, ifc);
514
515 UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
Christian Frankef7f740f2013-01-24 14:04:48 +0000516 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
hassoeef1fe12004-10-03 18:46:08 +0000517
518 /* Remove from subnet chain. */
Paul Jakmad9a18f12007-04-10 19:30:20 +0000519 list_delete_node (addr_list, anode);
hassoeef1fe12004-10-03 18:46:08 +0000520 route_unlock_node (rn);
521
522 /* Remove from interface address list (unconditionally). */
Paul Jakmad9a18f12007-04-10 19:30:20 +0000523 if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
524 {
525 listnode_delete (ifp->connected, ifc);
526 connected_free (ifc);
527 }
528 else
529 last = node;
hassoeef1fe12004-10-03 18:46:08 +0000530 }
531
532 /* Free chain list and respective route node. */
533 list_delete (addr_list);
534 rn->info = NULL;
535 route_unlock_node (rn);
536 }
paul718e3742002-12-13 20:15:29 +0000537#ifdef HAVE_IPV6
538 else if (p->family == AF_INET6)
hassoeef1fe12004-10-03 18:46:08 +0000539 {
540 connected_down_ipv6 (ifp, ifc);
paul718e3742002-12-13 20:15:29 +0000541
hassoeef1fe12004-10-03 18:46:08 +0000542 zebra_interface_address_delete_update (ifp, ifc);
paul718e3742002-12-13 20:15:29 +0000543
hassoeef1fe12004-10-03 18:46:08 +0000544 UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL);
Christian Frankef7f740f2013-01-24 14:04:48 +0000545 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
hassoeef1fe12004-10-03 18:46:08 +0000546
547 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
548 last = node;
549 else
550 {
551 listnode_delete (ifp->connected, ifc);
552 connected_free (ifc);
553 }
paul718e3742002-12-13 20:15:29 +0000554 }
hassoeef1fe12004-10-03 18:46:08 +0000555#endif /* HAVE_IPV6 */
Roman Hoog Antinke26873f2010-05-05 16:00:50 +0200556 else
557 {
558 last = node;
559 }
paul718e3742002-12-13 20:15:29 +0000560 }
561 }
562 zebra_interface_delete_update (ifp);
ajsd2fc8892005-04-02 18:38:43 +0000563
564 /* Update ifindex after distributing the delete message. This is in
565 case any client needs to have the old value of ifindex available
566 while processing the deletion. Each client daemon is responsible
567 for setting ifindex to IFINDEX_INTERNAL after processing the
568 interface deletion message. */
569 ifp->ifindex = IFINDEX_INTERNAL;
paul718e3742002-12-13 20:15:29 +0000570}
571
572/* Interface is up. */
573void
574if_up (struct interface *ifp)
575{
hasso52dc7ee2004-09-23 19:18:23 +0000576 struct listnode *node;
577 struct listnode *next;
paul718e3742002-12-13 20:15:29 +0000578 struct connected *ifc;
579 struct prefix *p;
580
Christian Franke581ecbf2016-05-03 19:59:43 +0200581 if_count_up(ifp->info);
582
paul718e3742002-12-13 20:15:29 +0000583 /* Notify the protocol daemons. */
584 zebra_interface_up_update (ifp);
585
586 /* Install connected routes to the kernel. */
587 if (ifp->connected)
588 {
paul1eb8ef22005-04-07 07:30:20 +0000589 for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc))
paul718e3742002-12-13 20:15:29 +0000590 {
paul718e3742002-12-13 20:15:29 +0000591 p = ifc->address;
592
593 if (p->family == AF_INET)
594 connected_up_ipv4 (ifp, ifc);
595#ifdef HAVE_IPV6
596 else if (p->family == AF_INET6)
597 connected_up_ipv6 (ifp, ifc);
598#endif /* HAVE_IPV6 */
599 }
600 }
601
602 /* Examine all static routes. */
Feng Lu0d0686f2015-05-22 11:40:02 +0200603 rib_update (ifp->vrf_id);
paul718e3742002-12-13 20:15:29 +0000604}
605
606/* Interface goes down. We have to manage different behavior of based
607 OS. */
608void
609if_down (struct interface *ifp)
610{
hasso52dc7ee2004-09-23 19:18:23 +0000611 struct listnode *node;
612 struct listnode *next;
paul718e3742002-12-13 20:15:29 +0000613 struct connected *ifc;
614 struct prefix *p;
Christian Franke581ecbf2016-05-03 19:59:43 +0200615 struct zebra_if *zif;
616
617 zif = ifp->info;
618 if (zif->up_events.count)
619 if_count_down(zif);
paul718e3742002-12-13 20:15:29 +0000620
621 /* Notify to the protocol daemons. */
622 zebra_interface_down_update (ifp);
623
624 /* Delete connected routes from the kernel. */
625 if (ifp->connected)
626 {
paul1eb8ef22005-04-07 07:30:20 +0000627 for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc))
paul718e3742002-12-13 20:15:29 +0000628 {
paul718e3742002-12-13 20:15:29 +0000629 p = ifc->address;
630
631 if (p->family == AF_INET)
632 connected_down_ipv4 (ifp, ifc);
633#ifdef HAVE_IPV6
634 else if (p->family == AF_INET6)
635 connected_down_ipv6 (ifp, ifc);
636#endif /* HAVE_IPV6 */
637 }
638 }
639
640 /* Examine all static routes which direct to the interface. */
Feng Lu0d0686f2015-05-22 11:40:02 +0200641 rib_update (ifp->vrf_id);
paul718e3742002-12-13 20:15:29 +0000642}
643
644void
645if_refresh (struct interface *ifp)
646{
paul5c78b3d2006-01-25 04:31:40 +0000647 if_get_flags (ifp);
paul718e3742002-12-13 20:15:29 +0000648}
649
paul718e3742002-12-13 20:15:29 +0000650/* Output prefix string to vty. */
paula1ac18c2005-06-28 17:17:12 +0000651static int
paul718e3742002-12-13 20:15:29 +0000652prefix_vty_out (struct vty *vty, struct prefix *p)
653{
654 char str[INET6_ADDRSTRLEN];
655
656 inet_ntop (p->family, &p->u.prefix, str, sizeof (str));
657 vty_out (vty, "%s", str);
658 return strlen (str);
659}
660
661/* Dump if address information to vty. */
paula1ac18c2005-06-28 17:17:12 +0000662static void
paul718e3742002-12-13 20:15:29 +0000663connected_dump_vty (struct vty *vty, struct connected *connected)
664{
665 struct prefix *p;
paul718e3742002-12-13 20:15:29 +0000666
667 /* Print interface address. */
668 p = connected->address;
669 vty_out (vty, " %s ", prefix_family_str (p));
670 prefix_vty_out (vty, p);
671 vty_out (vty, "/%d", p->prefixlen);
672
673 /* If there is destination address, print it. */
Andrew J. Schorre4529632006-12-12 19:18:21 +0000674 if (connected->destination)
paul718e3742002-12-13 20:15:29 +0000675 {
Andrew J. Schorre4529632006-12-12 19:18:21 +0000676 vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast "));
677 prefix_vty_out (vty, connected->destination);
paul718e3742002-12-13 20:15:29 +0000678 }
679
680 if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY))
681 vty_out (vty, " secondary");
682
683 if (connected->label)
684 vty_out (vty, " %s", connected->label);
685
686 vty_out (vty, "%s", VTY_NEWLINE);
687}
688
Donald Sharp64257732015-11-20 08:33:30 -0500689#if defined (HAVE_RTADV)
paul718e3742002-12-13 20:15:29 +0000690/* Dump interface ND information to vty. */
paula1ac18c2005-06-28 17:17:12 +0000691static void
paul718e3742002-12-13 20:15:29 +0000692nd_dump_vty (struct vty *vty, struct interface *ifp)
693{
694 struct zebra_if *zif;
695 struct rtadvconf *rtadv;
vincent7cee1bb2005-03-25 13:08:53 +0000696 int interval;
paul718e3742002-12-13 20:15:29 +0000697
698 zif = (struct zebra_if *) ifp->info;
699 rtadv = &zif->rtadv;
700
701 if (rtadv->AdvSendAdvertisements)
702 {
703 vty_out (vty, " ND advertised reachable time is %d milliseconds%s",
704 rtadv->AdvReachableTime, VTY_NEWLINE);
705 vty_out (vty, " ND advertised retransmit interval is %d milliseconds%s",
706 rtadv->AdvRetransTimer, VTY_NEWLINE);
vincent7cee1bb2005-03-25 13:08:53 +0000707 interval = rtadv->MaxRtrAdvInterval;
708 if (interval % 1000)
709 vty_out (vty, " ND router advertisements are sent every "
710 "%d milliseconds%s", interval,
711 VTY_NEWLINE);
712 else
713 vty_out (vty, " ND router advertisements are sent every "
714 "%d seconds%s", interval / 1000,
715 VTY_NEWLINE);
Denis Ovsienkod660f692011-12-30 21:55:49 +0400716 if (rtadv->AdvDefaultLifetime != -1)
717 vty_out (vty, " ND router advertisements live for %d seconds%s",
718 rtadv->AdvDefaultLifetime, VTY_NEWLINE);
719 else
720 vty_out (vty, " ND router advertisements lifetime tracks ra-interval%s",
721 VTY_NEWLINE);
Chris Caputob60668d2009-05-03 04:40:57 +0000722 vty_out (vty, " ND router advertisement default router preference is "
723 "%s%s", rtadv_pref_strs[rtadv->DefaultPreference],
724 VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000725 if (rtadv->AdvManagedFlag)
726 vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s",
727 VTY_NEWLINE);
728 else
729 vty_out (vty, " Hosts use stateless autoconfig for addresses.%s",
730 VTY_NEWLINE);
vincent7cee1bb2005-03-25 13:08:53 +0000731 if (rtadv->AdvHomeAgentFlag)
Denis Ovsienkod660f692011-12-30 21:55:49 +0400732 {
vincent7cee1bb2005-03-25 13:08:53 +0000733 vty_out (vty, " ND router advertisements with "
734 "Home Agent flag bit set.%s",
735 VTY_NEWLINE);
Denis Ovsienkod660f692011-12-30 21:55:49 +0400736 if (rtadv->HomeAgentLifetime != -1)
737 vty_out (vty, " Home Agent lifetime is %u seconds%s",
738 rtadv->HomeAgentLifetime, VTY_NEWLINE);
739 else
740 vty_out (vty, " Home Agent lifetime tracks ra-lifetime%s",
741 VTY_NEWLINE);
742 vty_out (vty, " Home Agent preference is %u%s",
743 rtadv->HomeAgentPreference, VTY_NEWLINE);
744 }
vincent7cee1bb2005-03-25 13:08:53 +0000745 if (rtadv->AdvIntervalOption)
746 vty_out (vty, " ND router advertisements with Adv. Interval option.%s",
747 VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000748 }
749}
Donald Sharp64257732015-11-20 08:33:30 -0500750#endif /* HAVE_RTADV */
paul718e3742002-12-13 20:15:29 +0000751
752/* Interface's information print out to vty interface. */
paula1ac18c2005-06-28 17:17:12 +0000753static void
paul718e3742002-12-13 20:15:29 +0000754if_dump_vty (struct vty *vty, struct interface *ifp)
755{
paul718e3742002-12-13 20:15:29 +0000756 struct connected *connected;
hasso52dc7ee2004-09-23 19:18:23 +0000757 struct listnode *node;
hassoeef1fe12004-10-03 18:46:08 +0000758 struct route_node *rn;
759 struct zebra_if *zebra_if;
760
761 zebra_if = ifp->info;
paul718e3742002-12-13 20:15:29 +0000762
paul2e3b2e42002-12-13 21:03:13 +0000763 vty_out (vty, "Interface %s is ", ifp->name);
764 if (if_is_up(ifp)) {
765 vty_out (vty, "up, line protocol ");
766
767 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) {
768 if (if_is_running(ifp))
769 vty_out (vty, "is up%s", VTY_NEWLINE);
770 else
771 vty_out (vty, "is down%s", VTY_NEWLINE);
772 } else {
773 vty_out (vty, "detection is disabled%s", VTY_NEWLINE);
774 }
775 } else {
776 vty_out (vty, "down%s", VTY_NEWLINE);
777 }
778
Christian Franke581ecbf2016-05-03 19:59:43 +0200779 vty_out (vty, " Link ups: %s%s",
780 event_counter_format(&zebra_if->up_events), VTY_NEWLINE);
781 vty_out (vty, " Link downs: %s%s",
782 event_counter_format(&zebra_if->down_events), VTY_NEWLINE);
783
Feng Lu2fc97f62015-05-22 11:39:57 +0200784 vty_out (vty, " vrf: %u%s", ifp->vrf_id, VTY_NEWLINE);
785
paul718e3742002-12-13 20:15:29 +0000786 if (ifp->desc)
787 vty_out (vty, " Description: %s%s", ifp->desc,
788 VTY_NEWLINE);
ajsd2fc8892005-04-02 18:38:43 +0000789 if (ifp->ifindex == IFINDEX_INTERNAL)
paul718e3742002-12-13 20:15:29 +0000790 {
ajsd2fc8892005-04-02 18:38:43 +0000791 vty_out(vty, " pseudo interface%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000792 return;
793 }
794 else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
795 {
796 vty_out(vty, " index %d inactive interface%s",
797 ifp->ifindex,
798 VTY_NEWLINE);
799 return;
800 }
801
802 vty_out (vty, " index %d metric %d mtu %d ",
803 ifp->ifindex, ifp->metric, ifp->mtu);
paul44145db2004-05-09 11:00:23 +0000804#ifdef HAVE_IPV6
805 if (ifp->mtu6 != ifp->mtu)
806 vty_out (vty, "mtu6 %d ", ifp->mtu6);
807#endif
Paul Jakma630c97c2006-06-15 12:48:17 +0000808 vty_out (vty, "%s flags: %s%s", VTY_NEWLINE,
809 if_flag_dump (ifp->flags), VTY_NEWLINE);
paul3a570c82006-02-02 17:27:13 +0000810
paul718e3742002-12-13 20:15:29 +0000811 /* Hardware address. */
Timo Teräs954c7d62016-01-15 17:36:33 +0200812 vty_out (vty, " Type: %s%s", if_link_type_str (ifp->ll_type), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000813 if (ifp->hw_addr_len != 0)
814 {
815 int i;
816
817 vty_out (vty, " HWaddr: ");
818 for (i = 0; i < ifp->hw_addr_len; i++)
819 vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]);
820 vty_out (vty, "%s", VTY_NEWLINE);
821 }
paul718e3742002-12-13 20:15:29 +0000822
823 /* Bandwidth in kbps */
824 if (ifp->bandwidth != 0)
825 {
826 vty_out(vty, " bandwidth %u kbps", ifp->bandwidth);
827 vty_out(vty, "%s", VTY_NEWLINE);
828 }
829
hassoeef1fe12004-10-03 18:46:08 +0000830 for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +0000831 {
hassoeef1fe12004-10-03 18:46:08 +0000832 if (! rn->info)
833 continue;
Olivier Dugeon15773a82016-04-19 18:29:55 +0200834
paul1eb8ef22005-04-07 07:30:20 +0000835 for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected))
836 connected_dump_vty (vty, connected);
paul718e3742002-12-13 20:15:29 +0000837 }
838
paul1eb8ef22005-04-07 07:30:20 +0000839 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
hasso39db97e2004-10-12 20:50:58 +0000840 {
hasso39db97e2004-10-12 20:50:58 +0000841 if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) &&
842 (connected->address->family == AF_INET6))
843 connected_dump_vty (vty, connected);
844 }
845
Olivier Dugeon15773a82016-04-19 18:29:55 +0200846 if (HAS_LINK_PARAMS(ifp))
847 {
848 int i;
849 struct if_link_params *iflp = ifp->link_params;
850 vty_out(vty, " Traffic Engineering Link Parameters:%s", VTY_NEWLINE);
851 if (IS_PARAM_SET(iflp, LP_TE))
852 vty_out(vty, " TE metric %u%s",iflp->te_metric, VTY_NEWLINE);
853 if (IS_PARAM_SET(iflp, LP_MAX_BW))
854 vty_out(vty, " Maximum Bandwidth %g (Byte/s)%s", iflp->max_bw, VTY_NEWLINE);
855 if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW))
856 vty_out(vty, " Maximum Reservable Bandwidth %g (Byte/s)%s", iflp->max_rsv_bw, VTY_NEWLINE);
857 if (IS_PARAM_SET(iflp, LP_UNRSV_BW)) {
858 vty_out(vty, " Unreserved Bandwidth per Class Type in Byte/s:%s", VTY_NEWLINE);
859 for (i = 0; i < MAX_CLASS_TYPE; i+=2)
860 vty_out(vty, " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)%s",
861 i, iflp->unrsv_bw[i], i+1, iflp->unrsv_bw[i+1], VTY_NEWLINE);
862 }
863
864 if (IS_PARAM_SET(iflp, LP_ADM_GRP))
865 vty_out(vty, " Administrative Group:%u%s", iflp->admin_grp, VTY_NEWLINE);
866 if (IS_PARAM_SET(iflp, LP_DELAY))
867 {
868 vty_out(vty, " Link Delay Average: %u (micro-sec.)", iflp->av_delay);
869 if (IS_PARAM_SET(iflp, LP_MM_DELAY))
870 {
871 vty_out(vty, " Min: %u (micro-sec.)", iflp->min_delay);
872 vty_out(vty, " Max: %u (micro-sec.)", iflp->max_delay);
873 }
874 vty_out(vty, "%s", VTY_NEWLINE);
875 }
876 if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
877 vty_out(vty, " Link Delay Variation %u (micro-sec.)%s", iflp->delay_var, VTY_NEWLINE);
878 if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
879 vty_out(vty, " Link Packet Loss %g (in %%)%s", iflp->pkt_loss, VTY_NEWLINE);
880 if (IS_PARAM_SET(iflp, LP_AVA_BW))
881 vty_out(vty, " Available Bandwidth %g (Byte/s)%s", iflp->ava_bw, VTY_NEWLINE);
882 if (IS_PARAM_SET(iflp, LP_RES_BW))
883 vty_out(vty, " Residual Bandwidth %g (Byte/s)%s", iflp->res_bw, VTY_NEWLINE);
884 if (IS_PARAM_SET(iflp, LP_USE_BW))
885 vty_out(vty, " Utilized Bandwidth %g (Byte/s)%s", iflp->use_bw, VTY_NEWLINE);
886 if (IS_PARAM_SET(iflp, LP_RMT_AS))
887 vty_out(vty, " Neighbor ASBR IP: %s AS: %u %s", inet_ntoa(iflp->rmt_ip), iflp->rmt_as, VTY_NEWLINE);
888 }
889
890 #ifdef RTADV
891 nd_dump_vty (vty, ifp);
892 #endif /* RTADV */
Donald Sharp64257732015-11-20 08:33:30 -0500893#if defined (HAVE_RTADV)
paul718e3742002-12-13 20:15:29 +0000894 nd_dump_vty (vty, ifp);
Donald Sharp64257732015-11-20 08:33:30 -0500895#endif /* HAVE_RTADV */
paul718e3742002-12-13 20:15:29 +0000896
897#ifdef HAVE_PROC_NET_DEV
898 /* Statistics print out using proc file system. */
hasso6f2c27a2005-01-18 13:44:35 +0000899 vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, "
900 "%lu dropped%s",
901 ifp->stats.rx_packets, ifp->stats.rx_multicast,
902 ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000903
hasso6f2c27a2005-01-18 13:44:35 +0000904 vty_out (vty, " %lu input errors, %lu length, %lu overrun,"
hasso3452d472005-03-06 13:42:05 +0000905 " %lu CRC, %lu frame%s",
paul718e3742002-12-13 20:15:29 +0000906 ifp->stats.rx_errors, ifp->stats.rx_length_errors,
907 ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors,
hasso6f2c27a2005-01-18 13:44:35 +0000908 ifp->stats.rx_frame_errors, VTY_NEWLINE);
909
910 vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors,
paul718e3742002-12-13 20:15:29 +0000911 ifp->stats.rx_missed_errors, VTY_NEWLINE);
912
hasso6f2c27a2005-01-18 13:44:35 +0000913 vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s",
paul718e3742002-12-13 20:15:29 +0000914 ifp->stats.tx_packets, ifp->stats.tx_bytes,
915 ifp->stats.tx_dropped, VTY_NEWLINE);
916
hasso6f2c27a2005-01-18 13:44:35 +0000917 vty_out (vty, " %lu output errors, %lu aborted, %lu carrier,"
918 " %lu fifo, %lu heartbeat%s",
paul718e3742002-12-13 20:15:29 +0000919 ifp->stats.tx_errors, ifp->stats.tx_aborted_errors,
920 ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors,
hasso6f2c27a2005-01-18 13:44:35 +0000921 ifp->stats.tx_heartbeat_errors, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000922
hasso6f2c27a2005-01-18 13:44:35 +0000923 vty_out (vty, " %lu window, %lu collisions%s",
924 ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000925#endif /* HAVE_PROC_NET_DEV */
926
927#ifdef HAVE_NET_RT_IFLIST
928#if defined (__bsdi__) || defined (__NetBSD__)
929 /* Statistics print out using sysctl (). */
David Lamparter193e78f2015-04-21 10:42:30 +0200930 vty_out (vty, " input packets %llu, bytes %llu, dropped %llu,"
931 " multicast packets %llu%s",
932 (unsigned long long)ifp->stats.ifi_ipackets,
933 (unsigned long long)ifp->stats.ifi_ibytes,
934 (unsigned long long)ifp->stats.ifi_iqdrops,
935 (unsigned long long)ifp->stats.ifi_imcasts,
936 VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000937
David Lamparter193e78f2015-04-21 10:42:30 +0200938 vty_out (vty, " input errors %llu%s",
939 (unsigned long long)ifp->stats.ifi_ierrors, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000940
David Lamparter193e78f2015-04-21 10:42:30 +0200941 vty_out (vty, " output packets %llu, bytes %llu,"
942 " multicast packets %llu%s",
943 (unsigned long long)ifp->stats.ifi_opackets,
944 (unsigned long long)ifp->stats.ifi_obytes,
945 (unsigned long long)ifp->stats.ifi_omcasts,
946 VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000947
David Lamparter193e78f2015-04-21 10:42:30 +0200948 vty_out (vty, " output errors %llu%s",
949 (unsigned long long)ifp->stats.ifi_oerrors, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000950
David Lamparter193e78f2015-04-21 10:42:30 +0200951 vty_out (vty, " collisions %llu%s",
952 (unsigned long long)ifp->stats.ifi_collisions, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000953#else
954 /* Statistics print out using sysctl (). */
955 vty_out (vty, " input packets %lu, bytes %lu, dropped %lu,"
956 " multicast packets %lu%s",
957 ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes,
958 ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts,
959 VTY_NEWLINE);
960
961 vty_out (vty, " input errors %lu%s",
962 ifp->stats.ifi_ierrors, VTY_NEWLINE);
963
964 vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s",
965 ifp->stats.ifi_opackets, ifp->stats.ifi_obytes,
966 ifp->stats.ifi_omcasts, VTY_NEWLINE);
967
968 vty_out (vty, " output errors %lu%s",
969 ifp->stats.ifi_oerrors, VTY_NEWLINE);
970
971 vty_out (vty, " collisions %lu%s",
972 ifp->stats.ifi_collisions, VTY_NEWLINE);
973#endif /* __bsdi__ || __NetBSD__ */
974#endif /* HAVE_NET_RT_IFLIST */
975}
976
paul718e3742002-12-13 20:15:29 +0000977/* Wrapper hook point for zebra daemon so that ifindex can be set
978 * DEFUN macro not used as extract.pl HAS to ignore this
979 * See also interface_cmd in lib/if.c
980 */
981DEFUN_NOSH (zebra_interface,
982 zebra_interface_cmd,
983 "interface IFNAME",
984 "Select an interface to configure\n"
985 "Interface's name\n")
986{
987 int ret;
Olivier Dugeon15773a82016-04-19 18:29:55 +0200988 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +0000989
990 /* Call lib interface() */
ajsd2fc8892005-04-02 18:38:43 +0000991 if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
992 return ret;
paul718e3742002-12-13 20:15:29 +0000993
Olivier Dugeon15773a82016-04-19 18:29:55 +0200994 ifp = vty->index;
paul718e3742002-12-13 20:15:29 +0000995
ajsd2fc8892005-04-02 18:38:43 +0000996 if (ifp->ifindex == IFINDEX_INTERNAL)
997 /* Is this really necessary? Shouldn't status be initialized to 0
998 in that case? */
999 UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
paul718e3742002-12-13 20:15:29 +00001000
1001 return ret;
1002}
1003
Feng Lu471ea392015-05-22 11:40:00 +02001004ALIAS (zebra_interface,
1005 zebra_interface_vrf_cmd,
1006 "interface IFNAME " VRF_CMD_STR,
1007 "Select an interface to configure\n"
1008 "Interface's name\n"
1009 VRF_CMD_HELP_STR)
1010
paul718e3742002-12-13 20:15:29 +00001011struct cmd_node interface_node =
1012{
1013 INTERFACE_NODE,
1014 "%s(config-if)# ",
1015 1
1016};
1017
Feng Lua2854772015-05-22 11:40:01 +02001018/* Show all interfaces to vty. */
paul718e3742002-12-13 20:15:29 +00001019DEFUN (show_interface, show_interface_cmd,
Feng Lua2854772015-05-22 11:40:01 +02001020 "show interface",
paul718e3742002-12-13 20:15:29 +00001021 SHOW_STR
Feng Lua2854772015-05-22 11:40:01 +02001022 "Interface status and configuration\n")
paul718e3742002-12-13 20:15:29 +00001023{
hasso52dc7ee2004-09-23 19:18:23 +00001024 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001025 struct interface *ifp;
Feng Lua2854772015-05-22 11:40:01 +02001026 vrf_id_t vrf_id = VRF_DEFAULT;
1027
paul718e3742002-12-13 20:15:29 +00001028#ifdef HAVE_PROC_NET_DEV
1029 /* If system has interface statistics via proc file system, update
1030 statistics. */
1031 ifstat_update_proc ();
1032#endif /* HAVE_PROC_NET_DEV */
1033#ifdef HAVE_NET_RT_IFLIST
1034 ifstat_update_sysctl ();
1035#endif /* HAVE_NET_RT_IFLIST */
1036
Feng Lua2854772015-05-22 11:40:01 +02001037 if (argc > 0)
1038 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
paul718e3742002-12-13 20:15:29 +00001039
1040 /* All interface print. */
Feng Lua2854772015-05-22 11:40:01 +02001041 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
paul1eb8ef22005-04-07 07:30:20 +00001042 if_dump_vty (vty, ifp);
paul718e3742002-12-13 20:15:29 +00001043
1044 return CMD_SUCCESS;
1045}
1046
Feng Lua2854772015-05-22 11:40:01 +02001047ALIAS (show_interface,
1048 show_interface_vrf_cmd,
1049 "show interface " VRF_CMD_STR,
hassoed9bb6d2005-03-13 19:17:21 +00001050 SHOW_STR
1051 "Interface status and configuration\n"
Feng Lua2854772015-05-22 11:40:01 +02001052 VRF_CMD_HELP_STR)
1053
1054/* Show all interfaces to vty. */
1055DEFUN (show_interface_vrf_all, show_interface_vrf_all_cmd,
1056 "show interface " VRF_ALL_CMD_STR,
1057 SHOW_STR
1058 "Interface status and configuration\n"
1059 VRF_ALL_CMD_HELP_STR)
1060{
1061 struct listnode *node;
1062 struct interface *ifp;
1063 vrf_iter_t iter;
1064
1065#ifdef HAVE_PROC_NET_DEV
1066 /* If system has interface statistics via proc file system, update
1067 statistics. */
1068 ifstat_update_proc ();
1069#endif /* HAVE_PROC_NET_DEV */
1070#ifdef HAVE_NET_RT_IFLIST
1071 ifstat_update_sysctl ();
1072#endif /* HAVE_NET_RT_IFLIST */
1073
1074 /* All interface print. */
1075 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1076 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
1077 if_dump_vty (vty, ifp);
1078
1079 return CMD_SUCCESS;
1080}
1081
1082/* Show specified interface to vty. */
1083DEFUN (show_interface_name, show_interface_name_cmd,
1084 "show interface IFNAME",
1085 SHOW_STR
1086 "Interface status and configuration\n"
1087 "Inteface name\n")
1088{
1089 struct interface *ifp;
1090 vrf_id_t vrf_id = VRF_DEFAULT;
1091
1092#ifdef HAVE_PROC_NET_DEV
1093 /* If system has interface statistics via proc file system, update
1094 statistics. */
1095 ifstat_update_proc ();
1096#endif /* HAVE_PROC_NET_DEV */
1097#ifdef HAVE_NET_RT_IFLIST
1098 ifstat_update_sysctl ();
1099#endif /* HAVE_NET_RT_IFLIST */
1100
1101 if (argc > 1)
1102 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]);
1103
1104 /* Specified interface print. */
1105 ifp = if_lookup_by_name_vrf (argv[0], vrf_id);
1106 if (ifp == NULL)
1107 {
1108 vty_out (vty, "%% Can't find interface %s%s", argv[0],
1109 VTY_NEWLINE);
1110 return CMD_WARNING;
1111 }
1112 if_dump_vty (vty, ifp);
1113
1114 return CMD_SUCCESS;
1115}
1116
1117ALIAS (show_interface_name,
1118 show_interface_name_vrf_cmd,
1119 "show interface IFNAME " VRF_CMD_STR,
1120 SHOW_STR
1121 "Interface status and configuration\n"
1122 "Inteface name\n"
1123 VRF_CMD_HELP_STR)
1124
1125/* Show specified interface to vty. */
1126DEFUN (show_interface_name_vrf_all, show_interface_name_vrf_all_cmd,
1127 "show interface IFNAME " VRF_ALL_CMD_STR,
1128 SHOW_STR
1129 "Interface status and configuration\n"
1130 "Inteface name\n"
1131 VRF_ALL_CMD_HELP_STR)
1132{
1133 struct interface *ifp;
1134 vrf_iter_t iter;
1135 int found = 0;
1136
1137#ifdef HAVE_PROC_NET_DEV
1138 /* If system has interface statistics via proc file system, update
1139 statistics. */
1140 ifstat_update_proc ();
1141#endif /* HAVE_PROC_NET_DEV */
1142#ifdef HAVE_NET_RT_IFLIST
1143 ifstat_update_sysctl ();
1144#endif /* HAVE_NET_RT_IFLIST */
1145
1146 /* All interface print. */
1147 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1148 {
1149 /* Specified interface print. */
1150 ifp = if_lookup_by_name_vrf (argv[0], vrf_iter2id (iter));
1151 if (ifp)
1152 {
1153 if_dump_vty (vty, ifp);
1154 found++;
1155 }
1156 }
1157
1158 if (!found)
1159 {
1160 vty_out (vty, "%% Can't find interface %s%s", argv[0], VTY_NEWLINE);
1161 return CMD_WARNING;
1162 }
1163
1164 return CMD_SUCCESS;
1165}
1166
1167static void
1168if_show_description (struct vty *vty, vrf_id_t vrf_id)
hassoed9bb6d2005-03-13 19:17:21 +00001169{
1170 struct listnode *node;
1171 struct interface *ifp;
1172
1173 vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE);
Feng Lua2854772015-05-22 11:40:01 +02001174 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
hassoed9bb6d2005-03-13 19:17:21 +00001175 {
1176 int len;
hassoed9bb6d2005-03-13 19:17:21 +00001177
1178 len = vty_out (vty, "%s", ifp->name);
1179 vty_out (vty, "%*s", (16 - len), " ");
1180
1181 if (if_is_up(ifp))
1182 {
1183 vty_out (vty, "up ");
1184 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
1185 {
1186 if (if_is_running(ifp))
1187 vty_out (vty, "up ");
1188 else
1189 vty_out (vty, "down ");
1190 }
1191 else
1192 {
1193 vty_out (vty, "unknown ");
1194 }
1195 }
1196 else
1197 {
1198 vty_out (vty, "down down ");
1199 }
1200
1201 if (ifp->desc)
1202 vty_out (vty, "%s", ifp->desc);
1203 vty_out (vty, "%s", VTY_NEWLINE);
1204 }
Feng Lua2854772015-05-22 11:40:01 +02001205}
1206
1207DEFUN (show_interface_desc,
1208 show_interface_desc_cmd,
1209 "show interface description",
1210 SHOW_STR
1211 "Interface status and configuration\n"
1212 "Interface description\n")
1213{
1214 vrf_id_t vrf_id = VRF_DEFAULT;
1215
1216 if (argc > 0)
1217 VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]);
1218
1219 if_show_description (vty, vrf_id);
1220
1221 return CMD_SUCCESS;
1222}
1223
1224ALIAS (show_interface_desc,
1225 show_interface_desc_vrf_cmd,
1226 "show interface description " VRF_CMD_STR,
1227 SHOW_STR
1228 "Interface status and configuration\n"
1229 "Interface description\n"
1230 VRF_CMD_HELP_STR)
1231
1232DEFUN (show_interface_desc_vrf_all,
1233 show_interface_desc_vrf_all_cmd,
1234 "show interface description " VRF_ALL_CMD_STR,
1235 SHOW_STR
1236 "Interface status and configuration\n"
1237 "Interface description\n"
1238 VRF_ALL_CMD_HELP_STR)
1239{
1240 vrf_iter_t iter;
1241
1242 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
1243 if (!list_isempty (vrf_iter2iflist (iter)))
1244 {
1245 vty_out (vty, "%s\tVRF %u%s%s", VTY_NEWLINE,
1246 vrf_iter2id (iter),
1247 VTY_NEWLINE, VTY_NEWLINE);
1248 if_show_description (vty, vrf_iter2id (iter));
1249 }
1250
hassoed9bb6d2005-03-13 19:17:21 +00001251 return CMD_SUCCESS;
1252}
1253
paul718e3742002-12-13 20:15:29 +00001254DEFUN (multicast,
1255 multicast_cmd,
1256 "multicast",
1257 "Set multicast flag to interface\n")
1258{
1259 int ret;
1260 struct interface *ifp;
1261 struct zebra_if *if_data;
1262
1263 ifp = (struct interface *) vty->index;
paul48b33aa2002-12-13 20:52:52 +00001264 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
paul718e3742002-12-13 20:15:29 +00001265 {
paul48b33aa2002-12-13 20:52:52 +00001266 ret = if_set_flags (ifp, IFF_MULTICAST);
1267 if (ret < 0)
1268 {
1269 vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE);
1270 return CMD_WARNING;
1271 }
1272 if_refresh (ifp);
paul718e3742002-12-13 20:15:29 +00001273 }
paul718e3742002-12-13 20:15:29 +00001274 if_data = ifp->info;
1275 if_data->multicast = IF_ZEBRA_MULTICAST_ON;
paul48b33aa2002-12-13 20:52:52 +00001276
paul718e3742002-12-13 20:15:29 +00001277 return CMD_SUCCESS;
1278}
1279
1280DEFUN (no_multicast,
1281 no_multicast_cmd,
1282 "no multicast",
1283 NO_STR
1284 "Unset multicast flag to interface\n")
1285{
1286 int ret;
1287 struct interface *ifp;
1288 struct zebra_if *if_data;
1289
1290 ifp = (struct interface *) vty->index;
paul48b33aa2002-12-13 20:52:52 +00001291 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
paul718e3742002-12-13 20:15:29 +00001292 {
paul48b33aa2002-12-13 20:52:52 +00001293 ret = if_unset_flags (ifp, IFF_MULTICAST);
1294 if (ret < 0)
1295 {
1296 vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE);
1297 return CMD_WARNING;
1298 }
1299 if_refresh (ifp);
paul718e3742002-12-13 20:15:29 +00001300 }
paul718e3742002-12-13 20:15:29 +00001301 if_data = ifp->info;
1302 if_data->multicast = IF_ZEBRA_MULTICAST_OFF;
1303
1304 return CMD_SUCCESS;
1305}
1306
paul2e3b2e42002-12-13 21:03:13 +00001307DEFUN (linkdetect,
1308 linkdetect_cmd,
1309 "link-detect",
1310 "Enable link detection on interface\n")
1311{
paul2e3b2e42002-12-13 21:03:13 +00001312 struct interface *ifp;
1313 int if_was_operative;
1314
1315 ifp = (struct interface *) vty->index;
1316 if_was_operative = if_is_operative(ifp);
1317 SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
1318
1319 /* When linkdetection is enabled, if might come down */
1320 if (!if_is_operative(ifp) && if_was_operative) if_down(ifp);
1321
1322 /* FIXME: Will defer status change forwarding if interface
1323 does not come down! */
1324
1325 return CMD_SUCCESS;
1326}
1327
1328
1329DEFUN (no_linkdetect,
1330 no_linkdetect_cmd,
1331 "no link-detect",
1332 NO_STR
1333 "Disable link detection on interface\n")
1334{
paul2e3b2e42002-12-13 21:03:13 +00001335 struct interface *ifp;
1336 int if_was_operative;
1337
1338 ifp = (struct interface *) vty->index;
1339 if_was_operative = if_is_operative(ifp);
1340 UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
1341
1342 /* Interface may come up after disabling link detection */
1343 if (if_is_operative(ifp) && !if_was_operative) if_up(ifp);
1344
1345 /* FIXME: see linkdetect_cmd */
1346
1347 return CMD_SUCCESS;
1348}
1349
paul718e3742002-12-13 20:15:29 +00001350DEFUN (shutdown_if,
1351 shutdown_if_cmd,
1352 "shutdown",
1353 "Shutdown the selected interface\n")
1354{
1355 int ret;
1356 struct interface *ifp;
1357 struct zebra_if *if_data;
1358
1359 ifp = (struct interface *) vty->index;
Christian Frankebfac8dc2013-01-24 14:04:50 +00001360 if (ifp->ifindex != IFINDEX_INTERNAL)
paul718e3742002-12-13 20:15:29 +00001361 {
Christian Frankebfac8dc2013-01-24 14:04:50 +00001362 ret = if_unset_flags (ifp, IFF_UP);
1363 if (ret < 0)
1364 {
1365 vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE);
1366 return CMD_WARNING;
1367 }
1368 if_refresh (ifp);
paul718e3742002-12-13 20:15:29 +00001369 }
paul718e3742002-12-13 20:15:29 +00001370 if_data = ifp->info;
1371 if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON;
1372
1373 return CMD_SUCCESS;
1374}
1375
1376DEFUN (no_shutdown_if,
1377 no_shutdown_if_cmd,
1378 "no shutdown",
1379 NO_STR
1380 "Shutdown the selected interface\n")
1381{
1382 int ret;
1383 struct interface *ifp;
1384 struct zebra_if *if_data;
1385
1386 ifp = (struct interface *) vty->index;
Christian Frankebfac8dc2013-01-24 14:04:50 +00001387
1388 if (ifp->ifindex != IFINDEX_INTERNAL)
paul718e3742002-12-13 20:15:29 +00001389 {
Christian Frankebfac8dc2013-01-24 14:04:50 +00001390 ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING);
1391 if (ret < 0)
1392 {
1393 vty_out (vty, "Can't up interface%s", VTY_NEWLINE);
1394 return CMD_WARNING;
1395 }
1396 if_refresh (ifp);
1397
1398 /* Some addresses (in particular, IPv6 addresses on Linux) get
1399 * removed when the interface goes down. They need to be readded.
1400 */
1401 if_addr_wakeup(ifp);
paul718e3742002-12-13 20:15:29 +00001402 }
Christian Frankebfac8dc2013-01-24 14:04:50 +00001403
paul718e3742002-12-13 20:15:29 +00001404 if_data = ifp->info;
1405 if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
1406
1407 return CMD_SUCCESS;
1408}
1409
1410DEFUN (bandwidth_if,
1411 bandwidth_if_cmd,
1412 "bandwidth <1-10000000>",
1413 "Set bandwidth informational parameter\n"
1414 "Bandwidth in kilobits\n")
1415{
1416 struct interface *ifp;
1417 unsigned int bandwidth;
1418
1419 ifp = (struct interface *) vty->index;
1420 bandwidth = strtol(argv[0], NULL, 10);
1421
1422 /* bandwidth range is <1-10000000> */
1423 if (bandwidth < 1 || bandwidth > 10000000)
1424 {
1425 vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE);
1426 return CMD_WARNING;
1427 }
1428
1429 ifp->bandwidth = bandwidth;
1430
1431 /* force protocols to recalculate routes due to cost change */
paul2e3b2e42002-12-13 21:03:13 +00001432 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +00001433 zebra_interface_up_update (ifp);
1434
1435 return CMD_SUCCESS;
1436}
1437
1438DEFUN (no_bandwidth_if,
1439 no_bandwidth_if_cmd,
1440 "no bandwidth",
1441 NO_STR
1442 "Set bandwidth informational parameter\n")
1443{
1444 struct interface *ifp;
1445
1446 ifp = (struct interface *) vty->index;
1447
1448 ifp->bandwidth = 0;
1449
1450 /* force protocols to recalculate routes due to cost change */
paul2e3b2e42002-12-13 21:03:13 +00001451 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +00001452 zebra_interface_up_update (ifp);
1453
1454 return CMD_SUCCESS;
1455}
1456
1457ALIAS (no_bandwidth_if,
1458 no_bandwidth_if_val_cmd,
1459 "no bandwidth <1-10000000>",
1460 NO_STR
1461 "Set bandwidth informational parameter\n"
1462 "Bandwidth in kilobits\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02001463
Olivier Dugeon15773a82016-04-19 18:29:55 +02001464struct cmd_node link_params_node =
1465{
1466 LINK_PARAMS_NODE,
1467 "%s(config-link-params)# ",
1468 1,
1469};
1470
1471static void
1472link_param_cmd_set_uint32 (struct interface *ifp, uint32_t *field,
1473 uint32_t type, uint32_t value)
1474{
1475 /* Update field as needed */
1476 if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value)
1477 {
1478 *field = value;
1479 SET_PARAM(ifp->link_params, type);
1480
1481 /* force protocols to update LINK STATE due to parameters change */
1482 if (if_is_operative (ifp))
1483 zebra_interface_parameters_update (ifp);
1484 }
1485}
1486static void
1487link_param_cmd_set_float (struct interface *ifp, float *field,
1488 uint32_t type, float value)
1489{
1490
1491 /* Update field as needed */
1492 if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value)
1493 {
1494 *field = value;
1495 SET_PARAM(ifp->link_params, type);
1496
1497 /* force protocols to update LINK STATE due to parameters change */
1498 if (if_is_operative (ifp))
1499 zebra_interface_parameters_update (ifp);
1500 }
1501}
1502
1503static void
1504link_param_cmd_unset (struct interface *ifp, uint32_t type)
1505{
1506
1507 /* Unset field */
1508 UNSET_PARAM(ifp->link_params, type);
1509
1510 /* force protocols to update LINK STATE due to parameters change */
1511 if (if_is_operative (ifp))
1512 zebra_interface_parameters_update (ifp);
1513}
1514
1515DEFUN (link_params,
1516 link_params_cmd,
1517 "link-params",
1518 LINK_PARAMS_STR)
1519{
1520 vty->node = LINK_PARAMS_NODE;
1521
1522 return CMD_SUCCESS;
1523}
1524
1525/* Specific Traffic Engineering parameters commands */
1526DEFUN (link_params_enable,
1527 link_params_enable_cmd,
1528 "enable",
1529 "Activate link parameters on this interface\n")
1530{
1531 struct interface *ifp = (struct interface *) vty->index;
1532
1533 /* This command could be issue at startup, when activate MPLS TE */
1534 /* on a new interface or after a ON / OFF / ON toggle */
1535 /* In all case, TE parameters are reset to their default factory */
1536 if (IS_ZEBRA_DEBUG_EVENT)
1537 zlog_debug ("Link-params: enable TE link parameters on interface %s", ifp->name);
1538
1539 if (!if_link_params_get (ifp))
1540 {
1541 if (IS_ZEBRA_DEBUG_EVENT)
1542 zlog_debug ("Link-params: failed to init TE link parameters %s", ifp->name);
1543
1544 return CMD_WARNING;
1545 }
1546
1547 /* force protocols to update LINK STATE due to parameters change */
1548 if (if_is_operative (ifp))
1549 zebra_interface_parameters_update (ifp);
1550
1551 return CMD_SUCCESS;
1552}
1553
1554DEFUN (no_link_params_enable,
1555 no_link_params_enable_cmd,
1556 "no enable",
1557 NO_STR
1558 "Disable link parameters on this interface\n")
1559{
1560 struct interface *ifp = (struct interface *) vty->index;
1561
1562 zlog_debug ("MPLS-TE: disable TE link parameters on interface %s", ifp->name);
1563
1564 if_link_params_free (ifp);
1565
1566 /* force protocols to update LINK STATE due to parameters change */
1567 if (if_is_operative (ifp))
1568 zebra_interface_parameters_update (ifp);
1569
1570 return CMD_SUCCESS;
1571}
1572
1573/* STANDARD TE metrics */
1574DEFUN (link_params_metric,
1575 link_params_metric_cmd,
1576 "metric <0-4294967295>",
1577 "Link metric for MPLS-TE purpose\n"
1578 "Metric value in decimal\n")
1579{
1580 struct interface *ifp = (struct interface *) vty->index;
1581 struct if_link_params *iflp = if_link_params_get (ifp);
1582 u_int32_t metric;
1583
1584 VTY_GET_ULONG("metric", metric, argv[0]);
1585
1586 /* Update TE metric if needed */
1587 link_param_cmd_set_uint32 (ifp, &iflp->te_metric, LP_TE, metric);
1588
1589 return CMD_SUCCESS;
1590}
1591
1592DEFUN (no_link_params_metric,
1593 no_link_params_metric_cmd,
1594 "no metric",
1595 NO_STR
1596 "Disbale Link Metric on this interface\n")
1597{
1598 struct interface *ifp = (struct interface *) vty->index;
1599
1600 /* Unset TE Metric */
1601 link_param_cmd_unset(ifp, LP_TE);
1602
1603 return CMD_SUCCESS;
1604}
1605
1606DEFUN (link_params_maxbw,
1607 link_params_maxbw_cmd,
1608 "max-bw BANDWIDTH",
1609 "Maximum bandwidth that can be used\n"
1610 "Bytes/second (IEEE floating point format)\n")
1611{
1612 struct interface *ifp = (struct interface *) vty->index;
1613 struct if_link_params *iflp = if_link_params_get (ifp);
1614
1615 float bw;
1616
1617 if (sscanf (argv[0], "%g", &bw) != 1)
1618 {
1619 vty_out (vty, "link_params_maxbw: fscanf: %s%s", safe_strerror (errno),
1620 VTY_NEWLINE);
1621 return CMD_WARNING;
1622 }
1623
1624 /* Check that Maximum bandwidth is not lower than other bandwidth parameters */
1625 if ((bw <= iflp->max_rsv_bw)
1626 || (bw <= iflp->unrsv_bw[0])
1627 || (bw <= iflp->unrsv_bw[1])
1628 || (bw <= iflp->unrsv_bw[2])
1629 || (bw <= iflp->unrsv_bw[3])
1630 || (bw <= iflp->unrsv_bw[4])
1631 || (bw <= iflp->unrsv_bw[5])
1632 || (bw <= iflp->unrsv_bw[6])
1633 || (bw <= iflp->unrsv_bw[7])
1634 || (bw <= iflp->ava_bw)
1635 || (bw <= iflp->res_bw)
1636 || (bw <= iflp->use_bw))
1637 {
1638 vty_out (vty,
1639 "Maximum Bandwidth could not be lower than others bandwidth%s",
1640 VTY_NEWLINE);
1641 return CMD_WARNING;
1642 }
1643
1644 /* Update Maximum Bandwidth if needed */
1645 link_param_cmd_set_float (ifp, &iflp->max_bw, LP_MAX_BW, bw);
1646
1647 return CMD_SUCCESS;
1648}
1649
1650DEFUN (link_params_max_rsv_bw,
1651 link_params_max_rsv_bw_cmd,
1652 "max-rsv-bw BANDWIDTH",
1653 "Maximum bandwidth that may be reserved\n"
1654 "Bytes/second (IEEE floating point format)\n")
1655{
1656 struct interface *ifp = (struct interface *) vty->index;
1657 struct if_link_params *iflp = if_link_params_get (ifp);
1658 float bw;
1659
1660 if (sscanf (argv[0], "%g", &bw) != 1)
1661 {
1662 vty_out (vty, "link_params_max_rsv_bw: fscanf: %s%s", safe_strerror (errno),
1663 VTY_NEWLINE);
1664 return CMD_WARNING;
1665 }
1666
1667 /* Check that bandwidth is not greater than maximum bandwidth parameter */
1668 if (bw > iflp->max_bw)
1669 {
1670 vty_out (vty,
1671 "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
1672 iflp->max_bw, VTY_NEWLINE);
1673 return CMD_WARNING;
1674 }
1675
1676 /* Update Maximum Reservable Bandwidth if needed */
1677 link_param_cmd_set_float (ifp, &iflp->max_rsv_bw, LP_MAX_RSV_BW, bw);
1678
1679 return CMD_SUCCESS;
1680}
1681
1682DEFUN (link_params_unrsv_bw,
1683 link_params_unrsv_bw_cmd,
1684 "unrsv-bw <0-7> BANDWIDTH",
1685 "Unreserved bandwidth at each priority level\n"
1686 "Priority\n"
1687 "Bytes/second (IEEE floating point format)\n")
1688{
1689 struct interface *ifp = (struct interface *) vty->index;
1690 struct if_link_params *iflp = if_link_params_get (ifp);
1691 int priority;
1692 float bw;
1693
1694 /* We don't have to consider about range check here. */
1695 if (sscanf (argv[0], "%d", &priority) != 1)
1696 {
1697 vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno),
1698 VTY_NEWLINE);
1699 return CMD_WARNING;
1700 }
1701
1702 if (sscanf (argv[1], "%g", &bw) != 1)
1703 {
1704 vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno),
1705 VTY_NEWLINE);
1706 return CMD_WARNING;
1707 }
1708
1709 /* Check that bandwidth is not greater than maximum bandwidth parameter */
1710 if (bw > iflp->max_bw)
1711 {
1712 vty_out (vty,
1713 "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
1714 iflp->max_bw, VTY_NEWLINE);
1715 return CMD_WARNING;
1716 }
1717
1718 /* Update Unreserved Bandwidth if needed */
1719 link_param_cmd_set_float (ifp, &iflp->unrsv_bw[priority], LP_UNRSV_BW, bw);
1720
1721 return CMD_SUCCESS;
1722}
1723
1724DEFUN (link_params_admin_grp,
1725 link_params_admin_grp_cmd,
1726 "admin-grp BITPATTERN",
1727 "Administrative group membership\n"
1728 "32-bit Hexadecimal value (e.g. 0xa1)\n")
1729{
1730 struct interface *ifp = (struct interface *) vty->index;
1731 struct if_link_params *iflp = if_link_params_get (ifp);
1732 unsigned long value;
1733
1734 if (sscanf (argv[0], "0x%lx", &value) != 1)
1735 {
1736 vty_out (vty, "link_params_admin_grp: fscanf: %s%s",
1737 safe_strerror (errno), VTY_NEWLINE);
1738 return CMD_WARNING;
1739 }
1740
1741 /* Update Administrative Group if needed */
1742 link_param_cmd_set_uint32 (ifp, &iflp->admin_grp, LP_ADM_GRP, value);
1743
1744 return CMD_SUCCESS;
1745}
1746
1747DEFUN (no_link_params_admin_grp,
1748 no_link_params_admin_grp_cmd,
1749 "no admin-grp",
1750 NO_STR
1751 "Disbale Administrative group membership on this interface\n")
1752{
1753 struct interface *ifp = (struct interface *) vty->index;
1754
1755 /* Unset Admin Group */
1756 link_param_cmd_unset(ifp, LP_ADM_GRP);
1757
1758 return CMD_SUCCESS;
1759}
1760
1761/* RFC5392 & RFC5316: INTER-AS */
1762DEFUN (link_params_inter_as,
1763 link_params_inter_as_cmd,
1764 "neighbor A.B.C.D as <1-4294967295>",
1765 "Configure remote ASBR information (Neighbor IP address and AS number)\n"
1766 "Remote IP address in dot decimal A.B.C.D\n"
1767 "Remote AS number\n"
1768 "AS number in the range <1-4294967295>\n")
1769{
1770
1771 struct interface *ifp = (struct interface *) vty->index;
1772 struct if_link_params *iflp = if_link_params_get (ifp);
1773 struct in_addr addr;
1774 u_int32_t as;
1775
1776 if (!inet_aton (argv[0], &addr))
1777 {
1778 vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE);
1779 return CMD_WARNING;
1780 }
1781
1782 VTY_GET_ULONG("AS number", as, argv[1]);
1783
1784 /* Update Remote IP and Remote AS fields if needed */
1785 if (IS_PARAM_UNSET(iflp, LP_RMT_AS)
1786 || iflp->rmt_as != as
1787 || iflp->rmt_ip.s_addr != addr.s_addr)
1788 {
1789
1790 iflp->rmt_as = as;
1791 iflp->rmt_ip.s_addr = addr.s_addr;
1792 SET_PARAM(iflp, LP_RMT_AS);
1793
1794 /* force protocols to update LINK STATE due to parameters change */
1795 if (if_is_operative (ifp))
1796 zebra_interface_parameters_update (ifp);
1797 }
1798 return CMD_SUCCESS;
1799}
1800
1801DEFUN (no_link_params_inter_as,
1802 no_link_params_inter_as_cmd,
1803 "no neighbor",
1804 NO_STR
1805 "Remove Neighbor IP address and AS number for Inter-AS TE\n")
1806{
1807
1808 struct interface *ifp = (struct interface *) vty->index;
1809 struct if_link_params *iflp = if_link_params_get (ifp);
1810
1811 /* Reset Remote IP and AS neighbor */
1812 iflp->rmt_as = 0;
1813 iflp->rmt_ip.s_addr = 0;
1814 UNSET_PARAM(iflp, LP_RMT_AS);
1815
1816 /* force protocols to update LINK STATE due to parameters change */
1817 if (if_is_operative (ifp))
1818 zebra_interface_parameters_update (ifp);
1819
1820 return CMD_SUCCESS;
1821}
1822
1823/* RFC7471: OSPF Traffic Engineering (TE) Metric extensions & draft-ietf-isis-metric-extensions-07.txt */
1824DEFUN (link_params_delay,
1825 link_params_delay_cmd,
1826 "delay <0-16777215>",
1827 "Unidirectional Average Link Delay\n"
1828 "Average delay in micro-second as decimal (0...16777215)\n")
1829{
1830
1831 struct interface *ifp = (struct interface *) vty->index;
1832 struct if_link_params *iflp = if_link_params_get (ifp);
1833 u_int32_t delay = 0, low = 0, high = 0;
1834 u_int8_t update = 0;
1835
1836 /* Get and Check new delay values */
1837 VTY_GET_ULONG("delay", delay, argv[0]);
1838 switch (argc)
1839 {
1840 case 1:
1841 /* Check new delay value against old Min and Max delays if set */
1842 if (IS_PARAM_SET(iflp, LP_MM_DELAY)
1843 && (delay <= iflp->min_delay || delay >= iflp->max_delay))
1844 {
1845 vty_out (vty, "Average delay should be comprise between Min (%d) and Max (%d) delay%s",
1846 iflp->min_delay, iflp->max_delay, VTY_NEWLINE);
1847 return CMD_WARNING;
1848 }
1849 /* Update delay if value is not set or change */
1850 if (IS_PARAM_UNSET(iflp, LP_DELAY)|| iflp->av_delay != delay)
1851 {
1852 iflp->av_delay = delay;
1853 SET_PARAM(iflp, LP_DELAY);
1854 update = 1;
1855 }
1856 /* Unset Min and Max delays if already set */
1857 if (IS_PARAM_SET(iflp, LP_MM_DELAY))
1858 {
1859 iflp->min_delay = 0;
1860 iflp->max_delay = 0;
1861 UNSET_PARAM(iflp, LP_MM_DELAY);
1862 update = 1;
1863 }
1864 break;
1865 case 2:
1866 vty_out (vty, "You should specify both Minimum and Maximum delay with Average delay%s",
1867 VTY_NEWLINE);
1868 return CMD_WARNING;
1869 break;
1870 case 3:
1871 VTY_GET_ULONG("minimum delay", low, argv[1]);
1872 VTY_GET_ULONG("maximum delay", high, argv[2]);
1873 /* Check new delays value coherency */
1874 if (delay <= low || delay >= high)
1875 {
1876 vty_out (vty, "Average delay should be comprise between Min (%d) and Max (%d) delay%s",
1877 low, high, VTY_NEWLINE);
1878 return CMD_WARNING;
1879 }
1880 /* Update Delays if needed */
1881 if (IS_PARAM_UNSET(iflp, LP_DELAY)
1882 || IS_PARAM_UNSET(iflp, LP_MM_DELAY)
1883 || iflp->av_delay != delay
1884 || iflp->min_delay != low
1885 || iflp->max_delay != high)
1886 {
1887 iflp->av_delay = delay;
1888 SET_PARAM(iflp, LP_DELAY);
1889 iflp->min_delay = low;
1890 iflp->max_delay = high;
1891 SET_PARAM(iflp, LP_MM_DELAY);
1892 update = 1;
1893 }
1894 break;
1895 default:
1896 return CMD_WARNING;
1897 break;
1898 }
1899
1900 /* force protocols to update LINK STATE due to parameters change */
1901 if (update == 1 && if_is_operative (ifp))
1902 zebra_interface_parameters_update (ifp);
1903
1904 return CMD_SUCCESS;
1905}
1906
1907ALIAS (link_params_delay,
1908 link_params_delay_mm_cmd,
1909 "delay <0-16777215> min <0-16777215> max <0-16777215>",
1910 "Unidirectional Average Link Delay (optionally Minimum and Maximum delays)\n"
1911 "Average delay in micro-second as decimal (0...16777215)\n"
1912 "Minimum delay\n"
1913 "Minimum delay in micro-second as decimal (0...16777215)\n"
1914 "Maximum delay\n"
1915 "Maximum delay in micro-second as decimal (0...16777215)\n")
1916
1917DEFUN (no_link_params_delay,
1918 no_link_params_delay_cmd,
1919 "no delay",
1920 NO_STR
1921 "Disbale Unidirectional Average, Min & Max Link Delay on this interface\n")
1922{
1923 struct interface *ifp = (struct interface *) vty->index;
1924 struct if_link_params *iflp = if_link_params_get (ifp);
1925
1926 /* Unset Delays */
1927 iflp->av_delay = 0;
1928 UNSET_PARAM(iflp, LP_DELAY);
1929 iflp->min_delay = 0;
1930 iflp->max_delay = 0;
1931 UNSET_PARAM(iflp, LP_MM_DELAY);
1932
1933 /* force protocols to update LINK STATE due to parameters change */
1934 if (if_is_operative (ifp))
1935 zebra_interface_parameters_update (ifp);
1936
1937 return CMD_SUCCESS;
1938}
1939
1940DEFUN (link_params_delay_var,
1941 link_params_delay_var_cmd,
1942 "delay-variation <0-16777215>",
1943 "Unidirectional Link Delay Variation\n"
1944 "delay variation in micro-second as decimal (0...16777215)\n")
1945{
1946 struct interface *ifp = (struct interface *) vty->index;
1947 struct if_link_params *iflp = if_link_params_get (ifp);
1948 u_int32_t value;
1949
1950 VTY_GET_ULONG("delay variation", value, argv[0]);
1951
1952 /* Update Delay Variation if needed */
1953 link_param_cmd_set_uint32 (ifp, &iflp->delay_var, LP_DELAY_VAR, value);
1954
1955 return CMD_SUCCESS;
1956}
1957
1958DEFUN (no_link_params_delay_var,
1959 no_link_params_delay_var_cmd,
1960 "no delay-variation",
1961 NO_STR
1962 "Disbale Unidirectional Delay Variation on this interface\n")
1963{
1964 struct interface *ifp = (struct interface *) vty->index;
1965
1966 /* Unset Delay Variation */
1967 link_param_cmd_unset(ifp, LP_DELAY_VAR);
1968
1969 return CMD_SUCCESS;
1970}
1971
1972DEFUN (link_params_pkt_loss,
1973 link_params_pkt_loss_cmd,
1974 "packet-loss PERCENTAGE",
1975 "Unidirectional Link Packet Loss\n"
1976 "percentage of total traffic by 0.000003% step and less than 50.331642%\n")
1977{
1978 struct interface *ifp = (struct interface *) vty->index;
1979 struct if_link_params *iflp = if_link_params_get (ifp);
1980 float fval;
1981
1982 if (sscanf (argv[0], "%g", &fval) != 1)
1983 {
1984 vty_out (vty, "link_params_pkt_loss: fscanf: %s%s", safe_strerror (errno),
1985 VTY_NEWLINE);
1986 return CMD_WARNING;
1987 }
1988
1989 if (fval > MAX_PKT_LOSS)
1990 fval = MAX_PKT_LOSS;
1991
1992 /* Update Packet Loss if needed */
1993 link_param_cmd_set_float (ifp, &iflp->pkt_loss, LP_PKT_LOSS, fval);
1994
1995 return CMD_SUCCESS;
1996}
1997
1998DEFUN (no_link_params_pkt_loss,
1999 no_link_params_pkt_loss_cmd,
2000 "no packet-loss",
2001 NO_STR
2002 "Disbale Unidirectional Link Packet Loss on this interface\n")
2003{
2004 struct interface *ifp = (struct interface *) vty->index;
2005
2006 /* Unset Packet Loss */
2007 link_param_cmd_unset(ifp, LP_PKT_LOSS);
2008
2009 return CMD_SUCCESS;
2010}
2011
2012DEFUN (link_params_res_bw,
2013 link_params_res_bw_cmd,
2014 "res-bw BANDWIDTH",
2015 "Unidirectional Residual Bandwidth\n"
2016 "Bytes/second (IEEE floating point format)\n")
2017{
2018 struct interface *ifp = (struct interface *) vty->index;
2019 struct if_link_params *iflp = if_link_params_get (ifp);
2020 float bw;
2021
2022 if (sscanf (argv[0], "%g", &bw) != 1)
2023 {
2024 vty_out (vty, "link_params_res_bw: fscanf: %s%s", safe_strerror (errno),
2025 VTY_NEWLINE);
2026 return CMD_WARNING;
2027 }
2028
2029 /* Check that bandwidth is not greater than maximum bandwidth parameter */
2030 if (bw > iflp->max_bw)
2031 {
2032 vty_out (vty,
2033 "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
2034 iflp->max_bw, VTY_NEWLINE);
2035 return CMD_WARNING;
2036 }
2037
2038 /* Update Residual Bandwidth if needed */
2039 link_param_cmd_set_float (ifp, &iflp->res_bw, LP_RES_BW, bw);
2040
2041 return CMD_SUCCESS;
2042}
2043
2044DEFUN (no_link_params_res_bw,
2045 no_link_params_res_bw_cmd,
2046 "no res-bw",
2047 NO_STR
2048 "Disbale Unidirectional Residual Bandwidth on this interface\n")
2049{
2050 struct interface *ifp = (struct interface *) vty->index;
2051
2052 /* Unset Residual Bandwidth */
2053 link_param_cmd_unset(ifp, LP_RES_BW);
2054
2055 return CMD_SUCCESS;
2056}
2057
2058DEFUN (link_params_ava_bw,
2059 link_params_ava_bw_cmd,
2060 "ava-bw BANDWIDTH",
2061 "Unidirectional Available Bandwidth\n"
2062 "Bytes/second (IEEE floating point format)\n")
2063{
2064 struct interface *ifp = (struct interface *) vty->index;
2065 struct if_link_params *iflp = if_link_params_get (ifp);
2066 float bw;
2067
2068 if (sscanf (argv[0], "%g", &bw) != 1)
2069 {
2070 vty_out (vty, "link_params_ava_bw: fscanf: %s%s", safe_strerror (errno),
2071 VTY_NEWLINE);
2072 return CMD_WARNING;
2073 }
2074
2075 /* Check that bandwidth is not greater than maximum bandwidth parameter */
2076 if (bw > iflp->max_bw)
2077 {
2078 vty_out (vty,
2079 "Available Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
2080 iflp->max_bw, VTY_NEWLINE);
2081 return CMD_WARNING;
2082 }
2083
2084 /* Update Residual Bandwidth if needed */
2085 link_param_cmd_set_float (ifp, &iflp->ava_bw, LP_AVA_BW, bw);
2086
2087 return CMD_SUCCESS;
2088}
2089
2090DEFUN (no_link_params_ava_bw,
2091 no_link_params_ava_bw_cmd,
2092 "no ava-bw",
2093 NO_STR
2094 "Disbale Unidirectional Available Bandwidth on this interface\n")
2095{
2096 struct interface *ifp = (struct interface *) vty->index;
2097
2098 /* Unset Available Bandwidth */
2099 link_param_cmd_unset(ifp, LP_AVA_BW);
2100
2101 return CMD_SUCCESS;
2102}
2103
2104DEFUN (link_params_use_bw,
2105 link_params_use_bw_cmd,
2106 "use-bw BANDWIDTH",
2107 "Unidirectional Utilised Bandwidth\n"
2108 "Bytes/second (IEEE floating point format)\n")
2109{
2110 struct interface *ifp = (struct interface *) vty->index;
2111 struct if_link_params *iflp = if_link_params_get (ifp);
2112 float bw;
2113
2114 if (sscanf (argv[0], "%g", &bw) != 1)
2115 {
2116 vty_out (vty, "link_params_use_bw: fscanf: %s%s", safe_strerror (errno),
2117 VTY_NEWLINE);
2118 return CMD_WARNING;
2119 }
2120
2121 /* Check that bandwidth is not greater than maximum bandwidth parameter */
2122 if (bw > iflp->max_bw)
2123 {
2124 vty_out (vty,
2125 "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)%s",
2126 iflp->max_bw, VTY_NEWLINE);
2127 return CMD_WARNING;
2128 }
2129
2130 /* Update Utilized Bandwidth if needed */
2131 link_param_cmd_set_float (ifp, &iflp->use_bw, LP_USE_BW, bw);
2132
2133 return CMD_SUCCESS;
2134}
2135
2136DEFUN (no_link_params_use_bw,
2137 no_link_params_use_bw_cmd,
2138 "no use-bw",
2139 NO_STR
2140 "Disbale Unidirectional Utilised Bandwidth on this interface\n")
2141{
2142 struct interface *ifp = (struct interface *) vty->index;
2143
2144 /* Unset Utilised Bandwidth */
2145 link_param_cmd_unset(ifp, LP_USE_BW);
2146
2147 return CMD_SUCCESS;
2148}
2149
paula1ac18c2005-06-28 17:17:12 +00002150static int
hasso39db97e2004-10-12 20:50:58 +00002151ip_address_install (struct vty *vty, struct interface *ifp,
2152 const char *addr_str, const char *peer_str,
2153 const char *label)
paul718e3742002-12-13 20:15:29 +00002154{
Christian Frankebfac8dc2013-01-24 14:04:50 +00002155 struct zebra_if *if_data;
paul718e3742002-12-13 20:15:29 +00002156 struct prefix_ipv4 cp;
2157 struct connected *ifc;
2158 struct prefix_ipv4 *p;
paul718e3742002-12-13 20:15:29 +00002159 int ret;
2160
Christian Frankebfac8dc2013-01-24 14:04:50 +00002161 if_data = ifp->info;
2162
paul718e3742002-12-13 20:15:29 +00002163 ret = str2prefix_ipv4 (addr_str, &cp);
2164 if (ret <= 0)
2165 {
2166 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
2167 return CMD_WARNING;
2168 }
2169
paulca162182005-09-12 16:58:52 +00002170 ifc = connected_check (ifp, (struct prefix *) &cp);
paul718e3742002-12-13 20:15:29 +00002171 if (! ifc)
2172 {
2173 ifc = connected_new ();
2174 ifc->ifp = ifp;
2175
2176 /* Address. */
2177 p = prefix_ipv4_new ();
2178 *p = cp;
2179 ifc->address = (struct prefix *) p;
2180
2181 /* Broadcast. */
hasso3fb9cd62004-10-19 19:44:43 +00002182 if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2)
paul718e3742002-12-13 20:15:29 +00002183 {
2184 p = prefix_ipv4_new ();
2185 *p = cp;
hasso3fb9cd62004-10-19 19:44:43 +00002186 p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen);
paul718e3742002-12-13 20:15:29 +00002187 ifc->destination = (struct prefix *) p;
2188 }
2189
paul718e3742002-12-13 20:15:29 +00002190 /* Label. */
2191 if (label)
paul0752ef02005-11-03 12:35:21 +00002192 ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
paul718e3742002-12-13 20:15:29 +00002193
2194 /* Add to linked list. */
2195 listnode_add (ifp->connected, ifc);
2196 }
2197
2198 /* This address is configured from zebra. */
2199 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2200 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
2201
2202 /* In case of this route need to install kernel. */
Christian Frankef7f740f2013-01-24 14:04:48 +00002203 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
Christian Frankebfac8dc2013-01-24 14:04:50 +00002204 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)
2205 && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON))
paul718e3742002-12-13 20:15:29 +00002206 {
2207 /* Some system need to up the interface to set IP address. */
2208 if (! if_is_up (ifp))
2209 {
2210 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
2211 if_refresh (ifp);
2212 }
2213
2214 ret = if_set_prefix (ifp, ifc);
2215 if (ret < 0)
2216 {
2217 vty_out (vty, "%% Can't set interface IP address: %s.%s",
ajs6099b3b2004-11-20 02:06:59 +00002218 safe_strerror(errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00002219 return CMD_WARNING;
2220 }
2221
Christian Frankef7f740f2013-01-24 14:04:48 +00002222 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
Christian Franke02b48052013-01-24 14:04:49 +00002223 /* The address will be advertised to zebra clients when the notification
2224 * from the kernel has been received.
2225 * It will also be added to the subnet chain list, then. */
paul718e3742002-12-13 20:15:29 +00002226 }
2227
2228 return CMD_SUCCESS;
2229}
2230
paula1ac18c2005-06-28 17:17:12 +00002231static int
hasso39db97e2004-10-12 20:50:58 +00002232ip_address_uninstall (struct vty *vty, struct interface *ifp,
2233 const char *addr_str, const char *peer_str,
2234 const char *label)
paul718e3742002-12-13 20:15:29 +00002235{
2236 struct prefix_ipv4 cp;
2237 struct connected *ifc;
2238 int ret;
2239
2240 /* Convert to prefix structure. */
2241 ret = str2prefix_ipv4 (addr_str, &cp);
2242 if (ret <= 0)
2243 {
2244 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
2245 return CMD_WARNING;
2246 }
2247
2248 /* Check current interface address. */
paulca162182005-09-12 16:58:52 +00002249 ifc = connected_check (ifp, (struct prefix *) &cp);
paul718e3742002-12-13 20:15:29 +00002250 if (! ifc)
2251 {
2252 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
2253 return CMD_WARNING;
2254 }
2255
2256 /* This is not configured address. */
2257 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2258 return CMD_WARNING;
2259
Paul Jakma74ecdc92006-06-15 18:10:47 +00002260 UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
2261
paul718e3742002-12-13 20:15:29 +00002262 /* This is not real address or interface is not active. */
Christian Frankef7f740f2013-01-24 14:04:48 +00002263 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
paul718e3742002-12-13 20:15:29 +00002264 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
2265 {
2266 listnode_delete (ifp->connected, ifc);
2267 connected_free (ifc);
2268 return CMD_WARNING;
2269 }
2270
2271 /* This is real route. */
2272 ret = if_unset_prefix (ifp, ifc);
2273 if (ret < 0)
2274 {
2275 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
ajs6099b3b2004-11-20 02:06:59 +00002276 safe_strerror(errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00002277 return CMD_WARNING;
2278 }
Christian Frankef7f740f2013-01-24 14:04:48 +00002279 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
Christian Franke02b48052013-01-24 14:04:49 +00002280 /* we will receive a kernel notification about this route being removed.
2281 * this will trigger its removal from the connected list. */
paul718e3742002-12-13 20:15:29 +00002282 return CMD_SUCCESS;
2283}
2284
2285DEFUN (ip_address,
2286 ip_address_cmd,
2287 "ip address A.B.C.D/M",
2288 "Interface Internet Protocol config commands\n"
2289 "Set the IP address of an interface\n"
2290 "IP address (e.g. 10.0.0.1/8)\n")
2291{
hassoeef1fe12004-10-03 18:46:08 +00002292 return ip_address_install (vty, vty->index, argv[0], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002293}
2294
2295DEFUN (no_ip_address,
2296 no_ip_address_cmd,
2297 "no ip address A.B.C.D/M",
2298 NO_STR
2299 "Interface Internet Protocol config commands\n"
2300 "Set the IP address of an interface\n"
2301 "IP Address (e.g. 10.0.0.1/8)")
2302{
hassoeef1fe12004-10-03 18:46:08 +00002303 return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002304}
2305
2306#ifdef HAVE_NETLINK
paul718e3742002-12-13 20:15:29 +00002307DEFUN (ip_address_label,
2308 ip_address_label_cmd,
2309 "ip address A.B.C.D/M label LINE",
2310 "Interface Internet Protocol config commands\n"
2311 "Set the IP address of an interface\n"
2312 "IP address (e.g. 10.0.0.1/8)\n"
2313 "Label of this address\n"
2314 "Label\n")
2315{
hassoeef1fe12004-10-03 18:46:08 +00002316 return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]);
paul718e3742002-12-13 20:15:29 +00002317}
2318
2319DEFUN (no_ip_address_label,
2320 no_ip_address_label_cmd,
2321 "no ip address A.B.C.D/M label LINE",
2322 NO_STR
2323 "Interface Internet Protocol config commands\n"
2324 "Set the IP address of an interface\n"
2325 "IP address (e.g. 10.0.0.1/8)\n"
2326 "Label of this address\n"
2327 "Label\n")
2328{
hassoeef1fe12004-10-03 18:46:08 +00002329 return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]);
paul718e3742002-12-13 20:15:29 +00002330}
2331#endif /* HAVE_NETLINK */
2332
2333#ifdef HAVE_IPV6
paula1ac18c2005-06-28 17:17:12 +00002334static int
hasso39db97e2004-10-12 20:50:58 +00002335ipv6_address_install (struct vty *vty, struct interface *ifp,
2336 const char *addr_str, const char *peer_str,
2337 const char *label, int secondary)
paul718e3742002-12-13 20:15:29 +00002338{
Christian Frankebfac8dc2013-01-24 14:04:50 +00002339 struct zebra_if *if_data;
paul718e3742002-12-13 20:15:29 +00002340 struct prefix_ipv6 cp;
2341 struct connected *ifc;
2342 struct prefix_ipv6 *p;
2343 int ret;
2344
Christian Frankebfac8dc2013-01-24 14:04:50 +00002345 if_data = ifp->info;
2346
paul718e3742002-12-13 20:15:29 +00002347 ret = str2prefix_ipv6 (addr_str, &cp);
2348 if (ret <= 0)
2349 {
2350 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
2351 return CMD_WARNING;
2352 }
2353
paulca162182005-09-12 16:58:52 +00002354 ifc = connected_check (ifp, (struct prefix *) &cp);
paul718e3742002-12-13 20:15:29 +00002355 if (! ifc)
2356 {
2357 ifc = connected_new ();
2358 ifc->ifp = ifp;
2359
2360 /* Address. */
2361 p = prefix_ipv6_new ();
2362 *p = cp;
2363 ifc->address = (struct prefix *) p;
2364
2365 /* Secondary. */
2366 if (secondary)
2367 SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY);
2368
2369 /* Label. */
2370 if (label)
paul0752ef02005-11-03 12:35:21 +00002371 ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label);
paul718e3742002-12-13 20:15:29 +00002372
2373 /* Add to linked list. */
2374 listnode_add (ifp->connected, ifc);
2375 }
2376
2377 /* This address is configured from zebra. */
2378 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2379 SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
2380
2381 /* In case of this route need to install kernel. */
Christian Frankef7f740f2013-01-24 14:04:48 +00002382 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
Christian Frankebfac8dc2013-01-24 14:04:50 +00002383 && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)
2384 && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON))
paul718e3742002-12-13 20:15:29 +00002385 {
2386 /* Some system need to up the interface to set IP address. */
2387 if (! if_is_up (ifp))
2388 {
2389 if_set_flags (ifp, IFF_UP | IFF_RUNNING);
2390 if_refresh (ifp);
2391 }
2392
2393 ret = if_prefix_add_ipv6 (ifp, ifc);
2394
2395 if (ret < 0)
2396 {
2397 vty_out (vty, "%% Can't set interface IP address: %s.%s",
ajs6099b3b2004-11-20 02:06:59 +00002398 safe_strerror(errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00002399 return CMD_WARNING;
2400 }
2401
Christian Frankef7f740f2013-01-24 14:04:48 +00002402 SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
Christian Franke02b48052013-01-24 14:04:49 +00002403 /* The address will be advertised to zebra clients when the notification
2404 * from the kernel has been received. */
paul718e3742002-12-13 20:15:29 +00002405 }
2406
2407 return CMD_SUCCESS;
2408}
2409
paula1ac18c2005-06-28 17:17:12 +00002410static int
hasso39db97e2004-10-12 20:50:58 +00002411ipv6_address_uninstall (struct vty *vty, struct interface *ifp,
2412 const char *addr_str, const char *peer_str,
2413 const char *label, int secondry)
paul718e3742002-12-13 20:15:29 +00002414{
2415 struct prefix_ipv6 cp;
2416 struct connected *ifc;
2417 int ret;
2418
2419 /* Convert to prefix structure. */
2420 ret = str2prefix_ipv6 (addr_str, &cp);
2421 if (ret <= 0)
2422 {
2423 vty_out (vty, "%% Malformed address %s", VTY_NEWLINE);
2424 return CMD_WARNING;
2425 }
2426
2427 /* Check current interface address. */
paulca162182005-09-12 16:58:52 +00002428 ifc = connected_check (ifp, (struct prefix *) &cp);
paul718e3742002-12-13 20:15:29 +00002429 if (! ifc)
2430 {
2431 vty_out (vty, "%% Can't find address%s", VTY_NEWLINE);
2432 return CMD_WARNING;
2433 }
2434
2435 /* This is not configured address. */
2436 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2437 return CMD_WARNING;
2438
Christian Franke676e1a02013-01-24 14:04:45 +00002439 UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED);
2440
paul718e3742002-12-13 20:15:29 +00002441 /* This is not real address or interface is not active. */
Christian Frankef7f740f2013-01-24 14:04:48 +00002442 if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)
paul718e3742002-12-13 20:15:29 +00002443 || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
2444 {
2445 listnode_delete (ifp->connected, ifc);
2446 connected_free (ifc);
2447 return CMD_WARNING;
2448 }
2449
2450 /* This is real route. */
2451 ret = if_prefix_delete_ipv6 (ifp, ifc);
2452 if (ret < 0)
2453 {
2454 vty_out (vty, "%% Can't unset interface IP address: %s.%s",
ajs6099b3b2004-11-20 02:06:59 +00002455 safe_strerror(errno), VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00002456 return CMD_WARNING;
2457 }
2458
Christian Frankef7f740f2013-01-24 14:04:48 +00002459 UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED);
Christian Franke02b48052013-01-24 14:04:49 +00002460 /* This information will be propagated to the zclients when the
2461 * kernel notification is received. */
paul718e3742002-12-13 20:15:29 +00002462 return CMD_SUCCESS;
2463}
2464
2465DEFUN (ipv6_address,
2466 ipv6_address_cmd,
2467 "ipv6 address X:X::X:X/M",
hassoe23949c2004-03-11 15:54:02 +00002468 "Interface IPv6 config commands\n"
paul718e3742002-12-13 20:15:29 +00002469 "Set the IP address of an interface\n"
2470 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2471{
2472 return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0);
2473}
2474
2475DEFUN (no_ipv6_address,
2476 no_ipv6_address_cmd,
2477 "no ipv6 address X:X::X:X/M",
2478 NO_STR
hassoe23949c2004-03-11 15:54:02 +00002479 "Interface IPv6 config commands\n"
paul718e3742002-12-13 20:15:29 +00002480 "Set the IP address of an interface\n"
2481 "IPv6 address (e.g. 3ffe:506::1/48)\n")
2482{
2483 return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0);
2484}
2485#endif /* HAVE_IPV6 */
2486
paula1ac18c2005-06-28 17:17:12 +00002487static int
Olivier Dugeon15773a82016-04-19 18:29:55 +02002488link_params_config_write (struct vty *vty, struct interface *ifp)
2489{
Paul Jakma3676cb02016-07-29 13:39:37 +01002490 int i;
2491
Olivier Dugeon15773a82016-04-19 18:29:55 +02002492 if ((ifp == NULL) || !HAS_LINK_PARAMS(ifp))
2493 return -1;
2494
2495 struct if_link_params *iflp = ifp->link_params;
2496
2497 vty_out (vty, " link-params%s", VTY_NEWLINE);
2498 vty_out(vty, " enable%s", VTY_NEWLINE);
2499 if (IS_PARAM_SET(iflp, LP_TE))
2500 vty_out(vty, " metric %u%s",iflp->te_metric, VTY_NEWLINE);
2501 if (IS_PARAM_SET(iflp, LP_MAX_BW))
2502 vty_out(vty, " max-bw %g%s", iflp->max_bw, VTY_NEWLINE);
2503 if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW))
2504 vty_out(vty, " max-rsv-bw %g%s", iflp->max_rsv_bw, VTY_NEWLINE);
2505 if (IS_PARAM_SET(iflp, LP_UNRSV_BW))
2506 {
Paul Jakma3676cb02016-07-29 13:39:37 +01002507 for (i = 0; i < 8; i++)
Olivier Dugeon15773a82016-04-19 18:29:55 +02002508 vty_out(vty, " unrsv-bw %d %g%s",
2509 i, iflp->unrsv_bw[i], VTY_NEWLINE);
2510 }
2511 if (IS_PARAM_SET(iflp, LP_ADM_GRP))
2512 vty_out(vty, " admin-grp %u%s", iflp->admin_grp, VTY_NEWLINE);
2513 if (IS_PARAM_SET(iflp, LP_DELAY))
2514 {
2515 vty_out(vty, " delay %u", iflp->av_delay);
2516 if (IS_PARAM_SET(iflp, LP_MM_DELAY))
2517 {
2518 vty_out(vty, " min %u", iflp->min_delay);
2519 vty_out(vty, " max %u", iflp->max_delay);
2520 }
2521 vty_out(vty, "%s", VTY_NEWLINE);
2522 }
2523 if (IS_PARAM_SET(iflp, LP_DELAY_VAR))
2524 vty_out(vty, " delay-variation %u%s", iflp->delay_var, VTY_NEWLINE);
2525 if (IS_PARAM_SET(iflp, LP_PKT_LOSS))
2526 vty_out(vty, " packet-loss %g%s", iflp->pkt_loss, VTY_NEWLINE);
2527 if (IS_PARAM_SET(iflp, LP_AVA_BW))
2528 vty_out(vty, " ava-bw %g%s", iflp->ava_bw, VTY_NEWLINE);
2529 if (IS_PARAM_SET(iflp, LP_RES_BW))
2530 vty_out(vty, " res-bw %g%s", iflp->res_bw, VTY_NEWLINE);
2531 if (IS_PARAM_SET(iflp, LP_USE_BW))
2532 vty_out(vty, " use-bw %g%s", iflp->use_bw, VTY_NEWLINE);
2533 if (IS_PARAM_SET(iflp, LP_RMT_AS))
2534 vty_out(vty, " neighbor %s as %u%s", inet_ntoa(iflp->rmt_ip),
2535 iflp->rmt_as, VTY_NEWLINE);
2536 return 0;
2537}
2538
2539static int
paul718e3742002-12-13 20:15:29 +00002540if_config_write (struct vty *vty)
2541{
hasso52dc7ee2004-09-23 19:18:23 +00002542 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00002543 struct interface *ifp;
Feng Lu471ea392015-05-22 11:40:00 +02002544 vrf_iter_t iter;
paul718e3742002-12-13 20:15:29 +00002545
Feng Lu471ea392015-05-22 11:40:00 +02002546 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
2547 for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp))
paul718e3742002-12-13 20:15:29 +00002548 {
2549 struct zebra_if *if_data;
hasso52dc7ee2004-09-23 19:18:23 +00002550 struct listnode *addrnode;
paul718e3742002-12-13 20:15:29 +00002551 struct connected *ifc;
2552 struct prefix *p;
2553
paul718e3742002-12-13 20:15:29 +00002554 if_data = ifp->info;
Feng Lu471ea392015-05-22 11:40:00 +02002555
2556 if (ifp->vrf_id == VRF_DEFAULT)
2557 vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE);
2558 else
2559 vty_out (vty, "interface %s vrf %u%s", ifp->name, ifp->vrf_id,
2560 VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00002561
Christian Frankebfac8dc2013-01-24 14:04:50 +00002562 if (if_data)
2563 {
2564 if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)
2565 vty_out (vty, " shutdown%s", VTY_NEWLINE);
2566 }
2567
paul718e3742002-12-13 20:15:29 +00002568 if (ifp->desc)
2569 vty_out (vty, " description %s%s", ifp->desc,
2570 VTY_NEWLINE);
2571
2572 /* Assign bandwidth here to avoid unnecessary interface flap
2573 while processing config script */
2574 if (ifp->bandwidth != 0)
2575 vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE);
paul2e3b2e42002-12-13 21:03:13 +00002576 if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION))
2577 vty_out(vty, " link-detect%s", VTY_NEWLINE);
David Lamparter4c421212015-03-02 06:42:11 +01002578 else
2579 vty_out(vty, " no link-detect%s", VTY_NEWLINE);
paul2e3b2e42002-12-13 21:03:13 +00002580
paul1eb8ef22005-04-07 07:30:20 +00002581 for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc))
paul718e3742002-12-13 20:15:29 +00002582 {
paul718e3742002-12-13 20:15:29 +00002583 if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED))
2584 {
Stephen Hemminger81cce012009-04-28 14:28:00 -07002585 char buf[INET6_ADDRSTRLEN];
paul718e3742002-12-13 20:15:29 +00002586 p = ifc->address;
Timo Teräsbe6335d2015-05-23 11:08:41 +03002587 vty_out (vty, " ip%s address %s",
paul718e3742002-12-13 20:15:29 +00002588 p->family == AF_INET ? "" : "v6",
Timo Teräsbe6335d2015-05-23 11:08:41 +03002589 prefix2str (p, buf, sizeof(buf)));
paul718e3742002-12-13 20:15:29 +00002590
paul718e3742002-12-13 20:15:29 +00002591 if (ifc->label)
2592 vty_out (vty, " label %s", ifc->label);
2593
2594 vty_out (vty, "%s", VTY_NEWLINE);
2595 }
2596 }
2597
2598 if (if_data)
2599 {
paul718e3742002-12-13 20:15:29 +00002600 if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC)
2601 vty_out (vty, " %smulticast%s",
2602 if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ",
2603 VTY_NEWLINE);
2604 }
2605
Donald Sharp64257732015-11-20 08:33:30 -05002606#if defined (HAVE_RTADV)
paul718e3742002-12-13 20:15:29 +00002607 rtadv_config_write (vty, ifp);
Donald Sharp64257732015-11-20 08:33:30 -05002608#endif /* HAVE_RTADV */
paul718e3742002-12-13 20:15:29 +00002609
hassoca776982004-06-12 14:33:05 +00002610#ifdef HAVE_IRDP
2611 irdp_config_write (vty, ifp);
2612#endif /* IRDP */
2613
Olivier Dugeon15773a82016-04-19 18:29:55 +02002614 link_params_config_write (vty, ifp);
2615
paul718e3742002-12-13 20:15:29 +00002616 vty_out (vty, "!%s", VTY_NEWLINE);
2617 }
2618 return 0;
2619}
2620
Olivier Dugeon15773a82016-04-19 18:29:55 +02002621
paul718e3742002-12-13 20:15:29 +00002622/* Allocate and initialize interface vector. */
2623void
paula1ac18c2005-06-28 17:17:12 +00002624zebra_if_init (void)
paul718e3742002-12-13 20:15:29 +00002625{
2626 /* Initialize interface and new hook. */
paul718e3742002-12-13 20:15:29 +00002627 if_add_hook (IF_NEW_HOOK, if_zebra_new_hook);
2628 if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook);
2629
2630 /* Install configuration write function. */
2631 install_node (&interface_node, if_config_write);
2632
Olivier Dugeon15773a82016-04-19 18:29:55 +02002633 install_node (&link_params_node, NULL);
2634
paul718e3742002-12-13 20:15:29 +00002635 install_element (VIEW_NODE, &show_interface_cmd);
Feng Lua2854772015-05-22 11:40:01 +02002636 install_element (VIEW_NODE, &show_interface_vrf_cmd);
2637 install_element (VIEW_NODE, &show_interface_vrf_all_cmd);
2638 install_element (VIEW_NODE, &show_interface_name_cmd);
2639 install_element (VIEW_NODE, &show_interface_name_vrf_cmd);
2640 install_element (VIEW_NODE, &show_interface_name_vrf_all_cmd);
paul718e3742002-12-13 20:15:29 +00002641 install_element (CONFIG_NODE, &zebra_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002642 install_element (CONFIG_NODE, &zebra_interface_vrf_cmd);
paulbfc13532003-05-24 06:40:04 +00002643 install_element (CONFIG_NODE, &no_interface_cmd);
Feng Lu471ea392015-05-22 11:40:00 +02002644 install_element (CONFIG_NODE, &no_interface_vrf_cmd);
paul718e3742002-12-13 20:15:29 +00002645 install_default (INTERFACE_NODE);
2646 install_element (INTERFACE_NODE, &interface_desc_cmd);
2647 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
2648 install_element (INTERFACE_NODE, &multicast_cmd);
2649 install_element (INTERFACE_NODE, &no_multicast_cmd);
paul2e3b2e42002-12-13 21:03:13 +00002650 install_element (INTERFACE_NODE, &linkdetect_cmd);
2651 install_element (INTERFACE_NODE, &no_linkdetect_cmd);
paul718e3742002-12-13 20:15:29 +00002652 install_element (INTERFACE_NODE, &shutdown_if_cmd);
2653 install_element (INTERFACE_NODE, &no_shutdown_if_cmd);
2654 install_element (INTERFACE_NODE, &bandwidth_if_cmd);
2655 install_element (INTERFACE_NODE, &no_bandwidth_if_cmd);
2656 install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd);
2657 install_element (INTERFACE_NODE, &ip_address_cmd);
2658 install_element (INTERFACE_NODE, &no_ip_address_cmd);
2659#ifdef HAVE_IPV6
2660 install_element (INTERFACE_NODE, &ipv6_address_cmd);
2661 install_element (INTERFACE_NODE, &no_ipv6_address_cmd);
2662#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002663#ifdef HAVE_NETLINK
paul718e3742002-12-13 20:15:29 +00002664 install_element (INTERFACE_NODE, &ip_address_label_cmd);
paul718e3742002-12-13 20:15:29 +00002665 install_element (INTERFACE_NODE, &no_ip_address_label_cmd);
paul718e3742002-12-13 20:15:29 +00002666#endif /* HAVE_NETLINK */
Olivier Dugeon15773a82016-04-19 18:29:55 +02002667 install_element(INTERFACE_NODE, &link_params_cmd);
2668 install_default(LINK_PARAMS_NODE);
2669 install_element(LINK_PARAMS_NODE, &link_params_enable_cmd);
2670 install_element(LINK_PARAMS_NODE, &no_link_params_enable_cmd);
2671 install_element(LINK_PARAMS_NODE, &link_params_metric_cmd);
2672 install_element(LINK_PARAMS_NODE, &link_params_maxbw_cmd);
2673 install_element(LINK_PARAMS_NODE, &link_params_max_rsv_bw_cmd);
2674 install_element(LINK_PARAMS_NODE, &link_params_unrsv_bw_cmd);
2675 install_element(LINK_PARAMS_NODE, &link_params_admin_grp_cmd);
2676 install_element(LINK_PARAMS_NODE, &link_params_inter_as_cmd);
2677 install_element(LINK_PARAMS_NODE, &no_link_params_inter_as_cmd);
2678 install_element(LINK_PARAMS_NODE, &link_params_delay_cmd);
2679 install_element(LINK_PARAMS_NODE, &link_params_delay_mm_cmd);
2680 install_element(LINK_PARAMS_NODE, &link_params_delay_var_cmd);
2681 install_element(LINK_PARAMS_NODE, &link_params_pkt_loss_cmd);
2682 install_element(LINK_PARAMS_NODE, &link_params_ava_bw_cmd);
2683 install_element(LINK_PARAMS_NODE, &link_params_res_bw_cmd);
2684 install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd);
paul718e3742002-12-13 20:15:29 +00002685}