paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Interface function. |
| 3 | * Copyright (C) 1997, 1999 Kunihiro Ishiguro |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 | * 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "if.h" |
| 26 | #include "vty.h" |
| 27 | #include "sockunion.h" |
| 28 | #include "prefix.h" |
| 29 | #include "command.h" |
| 30 | #include "memory.h" |
| 31 | #include "ioctl.h" |
| 32 | #include "connected.h" |
| 33 | #include "log.h" |
| 34 | #include "zclient.h" |
Feng Lu | 471ea39 | 2015-05-22 11:40:00 +0200 | [diff] [blame] | 35 | #include "vrf.h" |
Christian Franke | 581ecbf | 2016-05-03 19:59:43 +0200 | [diff] [blame] | 36 | #include "command.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 37 | |
| 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" |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 44 | #include "zebra/irdp.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 45 | |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 46 | #if defined (HAVE_RTADV) |
Chris Caputo | b60668d | 2009-05-03 04:40:57 +0000 | [diff] [blame] | 47 | /* Order is intentional. Matches RFC4191. This array is also used for |
| 48 | command matching, so only modify with care. */ |
| 49 | const char *rtadv_pref_strs[] = { "medium", "high", "INVALID", "low", 0 }; |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 50 | #endif /* HAVE_RTADV */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 51 | |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 52 | /* We don't have a tidy top-level instance object for zebra, or interfaces */ |
| 53 | static struct zebra_if_defaults zif_defaults = { |
| 54 | .linkdetect = IF_LINKDETECT_UNSPEC, |
| 55 | }; |
| 56 | |
| 57 | /* helper only for if_zebra_linkdetect */ |
| 58 | static void |
| 59 | if_zebra_linkdetect_set_val (struct interface *ifp, zebra_if_linkdetect val) |
| 60 | { |
| 61 | switch (val) |
| 62 | { |
| 63 | case IF_LINKDETECT_ON: |
| 64 | SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
| 65 | break; |
| 66 | case IF_LINKDETECT_OFF: |
| 67 | UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
| 68 | break; |
| 69 | default: break; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static void |
| 74 | if_zebra_linkdetect_set (struct interface *ifp) |
| 75 | { |
| 76 | struct zebra_if *zif = ifp->info; |
| 77 | assert (zif != NULL); |
| 78 | int if_was_operative = if_is_operative(ifp); |
| 79 | |
| 80 | /* If user has explicitly configured for the interface, let that set */ |
| 81 | if (zif->linkdetect != IF_LINKDETECT_UNSPEC) |
| 82 | if_zebra_linkdetect_set_val (ifp, zif->linkdetect); |
| 83 | else |
| 84 | { |
| 85 | /* general compiled in default is to set */ |
| 86 | SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
| 87 | /* but user can specify a default too */ |
| 88 | if_zebra_linkdetect_set_val (ifp, zif_defaults.linkdetect); |
| 89 | } |
| 90 | /* When linkdetection is enabled, interface might come down */ |
| 91 | if (!if_is_operative(ifp) && if_was_operative) if_down(ifp); |
| 92 | /* Alternatively, it may come up after disabling link detection */ |
| 93 | if (if_is_operative(ifp) && !if_was_operative) if_up(ifp); |
| 94 | } |
| 95 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 96 | /* Called when new interface is added. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 97 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 98 | if_zebra_new_hook (struct interface *ifp) |
| 99 | { |
| 100 | struct zebra_if *zebra_if; |
| 101 | |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 102 | zebra_if = XCALLOC (MTYPE_TMP, sizeof (struct zebra_if)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 103 | |
| 104 | zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC; |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 105 | zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 106 | |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 107 | switch (zif_defaults.linkdetect) |
| 108 | { |
| 109 | case IF_LINKDETECT_OFF: |
| 110 | UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
| 111 | break; |
| 112 | case IF_LINKDETECT_UNSPEC: |
| 113 | case IF_LINKDETECT_ON: |
| 114 | default: |
| 115 | SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
| 116 | break; |
| 117 | } |
| 118 | |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 119 | #if defined (HAVE_RTADV) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 120 | { |
| 121 | /* Set default router advertise values. */ |
| 122 | struct rtadvconf *rtadv; |
| 123 | |
| 124 | rtadv = &zebra_if->rtadv; |
| 125 | |
| 126 | rtadv->AdvSendAdvertisements = 0; |
| 127 | rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL; |
| 128 | rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL; |
| 129 | rtadv->AdvIntervalTimer = 0; |
| 130 | rtadv->AdvManagedFlag = 0; |
| 131 | rtadv->AdvOtherConfigFlag = 0; |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 132 | rtadv->AdvHomeAgentFlag = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 133 | rtadv->AdvLinkMTU = 0; |
| 134 | rtadv->AdvReachableTime = 0; |
| 135 | rtadv->AdvRetransTimer = 0; |
| 136 | rtadv->AdvCurHopLimit = 0; |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 137 | rtadv->AdvDefaultLifetime = -1; /* derive from MaxRtrAdvInterval */ |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 138 | rtadv->HomeAgentPreference = 0; |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 139 | rtadv->HomeAgentLifetime = -1; /* derive from AdvDefaultLifetime */ |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 140 | rtadv->AdvIntervalOption = 0; |
Chris Caputo | b60668d | 2009-05-03 04:40:57 +0000 | [diff] [blame] | 141 | rtadv->DefaultPreference = RTADV_PREF_MEDIUM; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 142 | |
| 143 | rtadv->AdvPrefixList = list_new (); |
| 144 | } |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 145 | #endif /* HAVE_RTADV */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 146 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 147 | /* Initialize installed address chains tree. */ |
| 148 | zebra_if->ipv4_subnets = route_table_init (); |
| 149 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 150 | ifp->info = zebra_if; |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /* Called when interface is deleted. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 155 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 156 | if_zebra_delete_hook (struct interface *ifp) |
| 157 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 158 | struct zebra_if *zebra_if; |
| 159 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 160 | if (ifp->info) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 161 | { |
| 162 | zebra_if = ifp->info; |
| 163 | |
| 164 | /* Free installed address chains tree. */ |
| 165 | if (zebra_if->ipv4_subnets) |
| 166 | route_table_finish (zebra_if->ipv4_subnets); |
| 167 | |
| 168 | XFREE (MTYPE_TMP, zebra_if); |
| 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | /* Tie an interface address to its derived subnet list of addresses. */ |
| 175 | int |
| 176 | if_subnet_add (struct interface *ifp, struct connected *ifc) |
| 177 | { |
| 178 | struct route_node *rn; |
| 179 | struct zebra_if *zebra_if; |
| 180 | struct prefix cp; |
| 181 | struct list *addr_list; |
| 182 | |
| 183 | assert (ifp && ifp->info && ifc); |
| 184 | zebra_if = ifp->info; |
| 185 | |
| 186 | /* Get address derived subnet node and associated address list, while marking |
| 187 | address secondary attribute appropriately. */ |
| 188 | cp = *ifc->address; |
| 189 | apply_mask (&cp); |
| 190 | rn = route_node_get (zebra_if->ipv4_subnets, &cp); |
| 191 | |
| 192 | if ((addr_list = rn->info)) |
| 193 | SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); |
| 194 | else |
| 195 | { |
| 196 | UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); |
| 197 | rn->info = addr_list = list_new (); |
| 198 | route_lock_node (rn); |
| 199 | } |
| 200 | |
| 201 | /* Tie address at the tail of address list. */ |
| 202 | listnode_add (addr_list, ifc); |
| 203 | |
| 204 | /* Return list element count. */ |
| 205 | return (addr_list->count); |
| 206 | } |
| 207 | |
| 208 | /* Untie an interface address from its derived subnet list of addresses. */ |
| 209 | int |
| 210 | if_subnet_delete (struct interface *ifp, struct connected *ifc) |
| 211 | { |
| 212 | struct route_node *rn; |
| 213 | struct zebra_if *zebra_if; |
| 214 | struct list *addr_list; |
| 215 | |
| 216 | assert (ifp && ifp->info && ifc); |
| 217 | zebra_if = ifp->info; |
| 218 | |
| 219 | /* Get address derived subnet node. */ |
| 220 | rn = route_node_lookup (zebra_if->ipv4_subnets, ifc->address); |
| 221 | if (! (rn && rn->info)) |
Christian Franke | 9db047f | 2013-01-24 14:04:44 +0000 | [diff] [blame] | 222 | { |
| 223 | zlog_warn("Trying to remove an address from an unknown subnet." |
| 224 | " (please report this bug)"); |
| 225 | return -1; |
| 226 | } |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 227 | route_unlock_node (rn); |
| 228 | |
| 229 | /* Untie address from subnet's address list. */ |
| 230 | addr_list = rn->info; |
Christian Franke | 9db047f | 2013-01-24 14:04:44 +0000 | [diff] [blame] | 231 | |
| 232 | /* Deleting an address that is not registered is a bug. |
| 233 | * In any case, we shouldn't decrement the lock counter if the address |
| 234 | * is unknown. */ |
| 235 | if (!listnode_lookup(addr_list, ifc)) |
| 236 | { |
| 237 | zlog_warn("Trying to remove an address from a subnet where it is not" |
| 238 | " currently registered. (please report this bug)"); |
| 239 | return -1; |
| 240 | } |
| 241 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 242 | listnode_delete (addr_list, ifc); |
| 243 | route_unlock_node (rn); |
| 244 | |
| 245 | /* Return list element count, if not empty. */ |
| 246 | if (addr_list->count) |
| 247 | { |
| 248 | /* If deleted address is primary, mark subsequent one as such and distribute. */ |
| 249 | if (! CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY)) |
| 250 | { |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 251 | ifc = listgetdata ((struct listnode *)listhead (addr_list)); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 252 | zebra_interface_address_delete_update (ifp, ifc); |
| 253 | UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 254 | /* XXX: Linux kernel removes all the secondary addresses when the primary |
| 255 | * address is removed. We could try to work around that, though this is |
| 256 | * non-trivial. */ |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 257 | zebra_interface_address_add_update (ifp, ifc); |
| 258 | } |
| 259 | |
| 260 | return addr_list->count; |
| 261 | } |
| 262 | |
| 263 | /* Otherwise, free list and route node. */ |
| 264 | list_free (addr_list); |
| 265 | rn->info = NULL; |
| 266 | route_unlock_node (rn); |
| 267 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 268 | return 0; |
| 269 | } |
| 270 | |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 271 | /* if_flags_mangle: A place for hacks that require mangling |
| 272 | * or tweaking the interface flags. |
| 273 | * |
| 274 | * ******************** Solaris flags hacks ************************** |
| 275 | * |
| 276 | * Solaris IFF_UP flag reflects only the primary interface as the |
| 277 | * routing socket only sends IFINFO for the primary interface. Hence |
| 278 | * ~IFF_UP does not per se imply all the logical interfaces are also |
| 279 | * down - which we only know of as addresses. Instead we must determine |
| 280 | * whether the interface really is up or not according to how many |
| 281 | * addresses are still attached. (Solaris always sends RTM_DELADDR if |
| 282 | * an interface, logical or not, goes ~IFF_UP). |
| 283 | * |
| 284 | * Ie, we mangle IFF_UP to *additionally* reflect whether or not there |
| 285 | * are addresses left in struct connected, not just the actual underlying |
| 286 | * IFF_UP flag. |
| 287 | * |
| 288 | * We must hence remember the real state of IFF_UP, which we do in |
| 289 | * struct zebra_if.primary_state. |
| 290 | * |
| 291 | * Setting IFF_UP within zebra to administratively shutdown the |
| 292 | * interface will affect only the primary interface/address on Solaris. |
| 293 | ************************End Solaris flags hacks *********************** |
| 294 | */ |
Paul Jakma | f63f06d | 2011-04-08 12:44:43 +0100 | [diff] [blame] | 295 | static void |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 296 | if_flags_mangle (struct interface *ifp, uint64_t *newflags) |
| 297 | { |
| 298 | #ifdef SUNOS_5 |
| 299 | struct zebra_if *zif = ifp->info; |
| 300 | |
| 301 | zif->primary_state = *newflags & (IFF_UP & 0xff); |
| 302 | |
| 303 | if (CHECK_FLAG (zif->primary_state, IFF_UP) |
| 304 | || listcount(ifp->connected) > 0) |
| 305 | SET_FLAG (*newflags, IFF_UP); |
| 306 | else |
| 307 | UNSET_FLAG (*newflags, IFF_UP); |
| 308 | #endif /* SUNOS_5 */ |
| 309 | } |
| 310 | |
| 311 | /* Update the flags field of the ifp with the new flag set provided. |
| 312 | * Take whatever actions are required for any changes in flags we care |
| 313 | * about. |
| 314 | * |
| 315 | * newflags should be the raw value, as obtained from the OS. |
| 316 | */ |
| 317 | void |
| 318 | if_flags_update (struct interface *ifp, uint64_t newflags) |
| 319 | { |
| 320 | if_flags_mangle (ifp, &newflags); |
| 321 | |
| 322 | if (if_is_operative (ifp)) |
| 323 | { |
| 324 | /* operative -> inoperative? */ |
| 325 | ifp->flags = newflags; |
| 326 | if (!if_is_operative (ifp)) |
| 327 | if_down (ifp); |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | /* inoperative -> operative? */ |
| 332 | ifp->flags = newflags; |
| 333 | if (if_is_operative (ifp)) |
| 334 | if_up (ifp); |
| 335 | } |
| 336 | } |
| 337 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 338 | /* Wake up configured address if it is not in current kernel |
| 339 | address. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 340 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 341 | if_addr_wakeup (struct interface *ifp) |
| 342 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 343 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 344 | struct connected *ifc; |
| 345 | struct prefix *p; |
| 346 | int ret; |
| 347 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 348 | for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 349 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 350 | p = ifc->address; |
| 351 | |
| 352 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED) |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 353 | && ! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 354 | { |
| 355 | /* Address check. */ |
| 356 | if (p->family == AF_INET) |
| 357 | { |
| 358 | if (! if_is_up (ifp)) |
| 359 | { |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 360 | /* Assume zebra is configured like following: |
| 361 | * |
| 362 | * interface gre0 |
| 363 | * ip addr 192.0.2.1/24 |
| 364 | * ! |
| 365 | * |
| 366 | * As soon as zebra becomes first aware that gre0 exists in the |
| 367 | * kernel, it will set gre0 up and configure its addresses. |
| 368 | * |
| 369 | * (This may happen at startup when the interface already exists |
| 370 | * or during runtime when the interface is added to the kernel) |
| 371 | * |
| 372 | * XXX: IRDP code is calling here via if_add_update - this seems |
| 373 | * somewhat weird. |
| 374 | * XXX: RUNNING is not a settable flag on any system |
| 375 | * I (paulj) am aware of. |
| 376 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 377 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 378 | if_refresh (ifp); |
| 379 | } |
| 380 | |
| 381 | ret = if_set_prefix (ifp, ifc); |
| 382 | if (ret < 0) |
| 383 | { |
| 384 | zlog_warn ("Can't set interface's address: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 385 | safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 386 | continue; |
| 387 | } |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 388 | |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 389 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 390 | /* The address will be advertised to zebra clients when the notification |
| 391 | * from the kernel has been received. |
| 392 | * It will also be added to the interface's subnet list then. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 393 | } |
| 394 | #ifdef HAVE_IPV6 |
| 395 | if (p->family == AF_INET6) |
| 396 | { |
| 397 | if (! if_is_up (ifp)) |
| 398 | { |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 399 | /* See long comment above */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 400 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 401 | if_refresh (ifp); |
| 402 | } |
| 403 | |
| 404 | ret = if_prefix_add_ipv6 (ifp, ifc); |
| 405 | if (ret < 0) |
| 406 | { |
| 407 | zlog_warn ("Can't set interface's address: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 408 | safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 409 | continue; |
| 410 | } |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 411 | |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 412 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 413 | /* The address will be advertised to zebra clients when the notification |
| 414 | * from the kernel has been received. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 415 | } |
| 416 | #endif /* HAVE_IPV6 */ |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
Christian Franke | 581ecbf | 2016-05-03 19:59:43 +0200 | [diff] [blame] | 421 | static void if_count_up(struct zebra_if *zif) |
| 422 | { |
| 423 | event_counter_inc(&zif->up_events); |
| 424 | } |
| 425 | |
| 426 | static void if_count_down(struct zebra_if *zif) |
| 427 | { |
| 428 | event_counter_inc(&zif->down_events); |
| 429 | } |
| 430 | |
| 431 | void |
| 432 | if_startup_count_up (void) |
| 433 | { |
| 434 | vrf_iter_t iter; |
| 435 | struct interface *ifp; |
| 436 | struct zebra_if *zif; |
| 437 | struct listnode *node; |
| 438 | |
| 439 | for (iter = vrf_first(); iter != VRF_ITER_INVALID; iter = vrf_next(iter)) |
| 440 | { |
| 441 | for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist(iter), node, ifp)) |
| 442 | { |
| 443 | zif = ifp->info; |
| 444 | if (!zif->up_events.count && if_is_operative(ifp)) |
| 445 | if_count_up(zif); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 450 | /* Handle interface addition */ |
| 451 | void |
| 452 | if_add_update (struct interface *ifp) |
| 453 | { |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 454 | struct zebra_if *if_data; |
| 455 | |
| 456 | if_data = ifp->info; |
Morgan Stewart | c8394ac | 2015-09-17 19:04:30 -0400 | [diff] [blame] | 457 | assert(if_data); |
| 458 | |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 459 | if (if_data->multicast == IF_ZEBRA_MULTICAST_ON) |
| 460 | if_set_flags (ifp, IFF_MULTICAST); |
| 461 | else if (if_data->multicast == IF_ZEBRA_MULTICAST_OFF) |
| 462 | if_unset_flags (ifp, IFF_MULTICAST); |
| 463 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 464 | zebra_interface_add_update (ifp); |
| 465 | |
| 466 | if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 467 | { |
| 468 | SET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); |
| 469 | |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 470 | if (if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) |
| 471 | { |
| 472 | if (IS_ZEBRA_DEBUG_KERNEL) |
Feng Lu | 2fc97f6 | 2015-05-22 11:39:57 +0200 | [diff] [blame] | 473 | zlog_debug ("interface %s vrf %u index %d is shutdown. " |
| 474 | "Won't wake it up.", |
| 475 | ifp->name, ifp->vrf_id, ifp->ifindex); |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 476 | return; |
| 477 | } |
| 478 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 479 | if_addr_wakeup (ifp); |
| 480 | |
| 481 | if (IS_ZEBRA_DEBUG_KERNEL) |
Feng Lu | 2fc97f6 | 2015-05-22 11:39:57 +0200 | [diff] [blame] | 482 | zlog_debug ("interface %s vrf %u index %d becomes active.", |
| 483 | ifp->name, ifp->vrf_id, ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 484 | } |
| 485 | else |
| 486 | { |
| 487 | if (IS_ZEBRA_DEBUG_KERNEL) |
Feng Lu | 2fc97f6 | 2015-05-22 11:39:57 +0200 | [diff] [blame] | 488 | zlog_debug ("interface %s vrf %u index %d is added.", |
| 489 | ifp->name, ifp->vrf_id, ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 490 | } |
Christian Franke | 581ecbf | 2016-05-03 19:59:43 +0200 | [diff] [blame] | 491 | |
| 492 | if (host_config_get()) |
| 493 | { |
| 494 | /* If configuration and therefore link-detect have already been |
| 495 | * loaded, count an initial up event when new interfaces are added |
| 496 | * in up state. |
| 497 | * If configuration has not been loaded yet, this is handled by |
| 498 | * if_startup_count_up which is called after reading the config. */ |
| 499 | if (!if_data->up_events.count && if_is_operative(ifp)) |
| 500 | if_count_up(if_data); |
| 501 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 502 | } |
| 503 | |
paul | 6eb8827 | 2005-07-29 14:36:00 +0000 | [diff] [blame] | 504 | /* Handle an interface delete event */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 505 | void |
| 506 | if_delete_update (struct interface *ifp) |
| 507 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 508 | struct connected *ifc; |
| 509 | struct prefix *p; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 510 | struct route_node *rn; |
| 511 | struct zebra_if *zebra_if; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 512 | |
| 513 | zebra_if = ifp->info; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 514 | |
| 515 | if (if_is_up(ifp)) |
| 516 | { |
Feng Lu | 2fc97f6 | 2015-05-22 11:39:57 +0200 | [diff] [blame] | 517 | zlog_err ("interface %s vrf %u index %d is still up while being deleted.", |
| 518 | ifp->name, ifp->vrf_id, ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 519 | return; |
| 520 | } |
| 521 | |
| 522 | /* Mark interface as inactive */ |
| 523 | UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); |
| 524 | |
| 525 | if (IS_ZEBRA_DEBUG_KERNEL) |
Feng Lu | 2fc97f6 | 2015-05-22 11:39:57 +0200 | [diff] [blame] | 526 | zlog_debug ("interface %s vrf %u index %d is now inactive.", |
| 527 | ifp->name, ifp->vrf_id, ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 528 | |
| 529 | /* Delete connected routes from the kernel. */ |
| 530 | if (ifp->connected) |
| 531 | { |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 532 | struct listnode *node; |
| 533 | struct listnode *last = NULL; |
| 534 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 535 | while ((node = (last ? last->next : listhead (ifp->connected)))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 536 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 537 | ifc = listgetdata (node); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | p = ifc->address; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 539 | |
Paul Jakma | beb5633 | 2006-05-11 13:28:05 +0000 | [diff] [blame] | 540 | if (p->family == AF_INET |
| 541 | && (rn = route_node_lookup (zebra_if->ipv4_subnets, p))) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 542 | { |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 543 | struct listnode *anode; |
| 544 | struct listnode *next; |
| 545 | struct listnode *first; |
| 546 | struct list *addr_list; |
| 547 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 548 | route_unlock_node (rn); |
| 549 | addr_list = (struct list *) rn->info; |
| 550 | |
| 551 | /* Remove addresses, secondaries first. */ |
| 552 | first = listhead (addr_list); |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 553 | for (anode = first->next; anode || first; anode = next) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 554 | { |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 555 | if (!anode) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 556 | { |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 557 | anode = first; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 558 | first = NULL; |
| 559 | } |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 560 | next = anode->next; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 561 | |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 562 | ifc = listgetdata (anode); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 563 | p = ifc->address; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 564 | connected_down_ipv4 (ifp, ifc); |
| 565 | |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 566 | /* XXX: We have to send notifications here explicitly, because we destroy |
| 567 | * the ifc before receiving the notification about the address being deleted. |
| 568 | */ |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 569 | zebra_interface_address_delete_update (ifp, ifc); |
| 570 | |
| 571 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 572 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 573 | |
| 574 | /* Remove from subnet chain. */ |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 575 | list_delete_node (addr_list, anode); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 576 | route_unlock_node (rn); |
| 577 | |
| 578 | /* Remove from interface address list (unconditionally). */ |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 579 | if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 580 | { |
| 581 | listnode_delete (ifp->connected, ifc); |
| 582 | connected_free (ifc); |
| 583 | } |
| 584 | else |
| 585 | last = node; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* Free chain list and respective route node. */ |
| 589 | list_delete (addr_list); |
| 590 | rn->info = NULL; |
| 591 | route_unlock_node (rn); |
| 592 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 593 | #ifdef HAVE_IPV6 |
| 594 | else if (p->family == AF_INET6) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 595 | { |
| 596 | connected_down_ipv6 (ifp, ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 597 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 598 | zebra_interface_address_delete_update (ifp, ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 599 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 600 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 601 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 602 | |
| 603 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 604 | last = node; |
| 605 | else |
| 606 | { |
| 607 | listnode_delete (ifp->connected, ifc); |
| 608 | connected_free (ifc); |
| 609 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 610 | } |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 611 | #endif /* HAVE_IPV6 */ |
Roman Hoog Antink | e26873f | 2010-05-05 16:00:50 +0200 | [diff] [blame] | 612 | else |
| 613 | { |
| 614 | last = node; |
| 615 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | zebra_interface_delete_update (ifp); |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 619 | |
| 620 | /* Update ifindex after distributing the delete message. This is in |
| 621 | case any client needs to have the old value of ifindex available |
| 622 | while processing the deletion. Each client daemon is responsible |
| 623 | for setting ifindex to IFINDEX_INTERNAL after processing the |
| 624 | interface deletion message. */ |
| 625 | ifp->ifindex = IFINDEX_INTERNAL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /* Interface is up. */ |
| 629 | void |
| 630 | if_up (struct interface *ifp) |
| 631 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 632 | struct listnode *node; |
| 633 | struct listnode *next; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 634 | struct connected *ifc; |
| 635 | struct prefix *p; |
| 636 | |
Christian Franke | 581ecbf | 2016-05-03 19:59:43 +0200 | [diff] [blame] | 637 | if_count_up(ifp->info); |
| 638 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 639 | /* Notify the protocol daemons. */ |
| 640 | zebra_interface_up_update (ifp); |
| 641 | |
| 642 | /* Install connected routes to the kernel. */ |
| 643 | if (ifp->connected) |
| 644 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 645 | for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 646 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 647 | p = ifc->address; |
| 648 | |
| 649 | if (p->family == AF_INET) |
| 650 | connected_up_ipv4 (ifp, ifc); |
| 651 | #ifdef HAVE_IPV6 |
| 652 | else if (p->family == AF_INET6) |
| 653 | connected_up_ipv6 (ifp, ifc); |
| 654 | #endif /* HAVE_IPV6 */ |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | /* Examine all static routes. */ |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 659 | rib_update (ifp->vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /* Interface goes down. We have to manage different behavior of based |
| 663 | OS. */ |
| 664 | void |
| 665 | if_down (struct interface *ifp) |
| 666 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 667 | struct listnode *node; |
| 668 | struct listnode *next; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 669 | struct connected *ifc; |
| 670 | struct prefix *p; |
Christian Franke | 581ecbf | 2016-05-03 19:59:43 +0200 | [diff] [blame] | 671 | struct zebra_if *zif; |
| 672 | |
| 673 | zif = ifp->info; |
| 674 | if (zif->up_events.count) |
| 675 | if_count_down(zif); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 676 | |
| 677 | /* Notify to the protocol daemons. */ |
| 678 | zebra_interface_down_update (ifp); |
| 679 | |
| 680 | /* Delete connected routes from the kernel. */ |
| 681 | if (ifp->connected) |
| 682 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 683 | for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 684 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 685 | p = ifc->address; |
| 686 | |
| 687 | if (p->family == AF_INET) |
| 688 | connected_down_ipv4 (ifp, ifc); |
| 689 | #ifdef HAVE_IPV6 |
| 690 | else if (p->family == AF_INET6) |
| 691 | connected_down_ipv6 (ifp, ifc); |
| 692 | #endif /* HAVE_IPV6 */ |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | /* Examine all static routes which direct to the interface. */ |
Feng Lu | 0d0686f | 2015-05-22 11:40:02 +0200 | [diff] [blame] | 697 | rib_update (ifp->vrf_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | void |
| 701 | if_refresh (struct interface *ifp) |
| 702 | { |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 703 | if_get_flags (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 704 | } |
| 705 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 706 | /* Output prefix string to vty. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 707 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 708 | prefix_vty_out (struct vty *vty, struct prefix *p) |
| 709 | { |
| 710 | char str[INET6_ADDRSTRLEN]; |
| 711 | |
| 712 | inet_ntop (p->family, &p->u.prefix, str, sizeof (str)); |
| 713 | vty_out (vty, "%s", str); |
| 714 | return strlen (str); |
| 715 | } |
| 716 | |
| 717 | /* Dump if address information to vty. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 718 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 719 | connected_dump_vty (struct vty *vty, struct connected *connected) |
| 720 | { |
| 721 | struct prefix *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 722 | |
| 723 | /* Print interface address. */ |
| 724 | p = connected->address; |
| 725 | vty_out (vty, " %s ", prefix_family_str (p)); |
| 726 | prefix_vty_out (vty, p); |
| 727 | vty_out (vty, "/%d", p->prefixlen); |
| 728 | |
| 729 | /* If there is destination address, print it. */ |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 730 | if (connected->destination) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 731 | { |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 732 | vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast ")); |
| 733 | prefix_vty_out (vty, connected->destination); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY)) |
| 737 | vty_out (vty, " secondary"); |
| 738 | |
Donald Sharp | 4c7efde | 2015-11-16 18:19:18 -0500 | [diff] [blame^] | 739 | if (CHECK_FLAG (connected->flags, ZEBRA_IFA_UNNUMBERED)) |
| 740 | vty_out (vty, " unnumbered"); |
| 741 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 742 | if (connected->label) |
| 743 | vty_out (vty, " %s", connected->label); |
| 744 | |
| 745 | vty_out (vty, "%s", VTY_NEWLINE); |
| 746 | } |
| 747 | |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 748 | #if defined (HAVE_RTADV) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 749 | /* Dump interface ND information to vty. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 750 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 751 | nd_dump_vty (struct vty *vty, struct interface *ifp) |
| 752 | { |
| 753 | struct zebra_if *zif; |
| 754 | struct rtadvconf *rtadv; |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 755 | int interval; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 756 | |
| 757 | zif = (struct zebra_if *) ifp->info; |
| 758 | rtadv = &zif->rtadv; |
| 759 | |
| 760 | if (rtadv->AdvSendAdvertisements) |
| 761 | { |
| 762 | vty_out (vty, " ND advertised reachable time is %d milliseconds%s", |
| 763 | rtadv->AdvReachableTime, VTY_NEWLINE); |
| 764 | vty_out (vty, " ND advertised retransmit interval is %d milliseconds%s", |
| 765 | rtadv->AdvRetransTimer, VTY_NEWLINE); |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 766 | interval = rtadv->MaxRtrAdvInterval; |
| 767 | if (interval % 1000) |
| 768 | vty_out (vty, " ND router advertisements are sent every " |
| 769 | "%d milliseconds%s", interval, |
| 770 | VTY_NEWLINE); |
| 771 | else |
| 772 | vty_out (vty, " ND router advertisements are sent every " |
| 773 | "%d seconds%s", interval / 1000, |
| 774 | VTY_NEWLINE); |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 775 | if (rtadv->AdvDefaultLifetime != -1) |
| 776 | vty_out (vty, " ND router advertisements live for %d seconds%s", |
| 777 | rtadv->AdvDefaultLifetime, VTY_NEWLINE); |
| 778 | else |
| 779 | vty_out (vty, " ND router advertisements lifetime tracks ra-interval%s", |
| 780 | VTY_NEWLINE); |
Chris Caputo | b60668d | 2009-05-03 04:40:57 +0000 | [diff] [blame] | 781 | vty_out (vty, " ND router advertisement default router preference is " |
| 782 | "%s%s", rtadv_pref_strs[rtadv->DefaultPreference], |
| 783 | VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 784 | if (rtadv->AdvManagedFlag) |
| 785 | vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s", |
| 786 | VTY_NEWLINE); |
| 787 | else |
| 788 | vty_out (vty, " Hosts use stateless autoconfig for addresses.%s", |
| 789 | VTY_NEWLINE); |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 790 | if (rtadv->AdvHomeAgentFlag) |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 791 | { |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 792 | vty_out (vty, " ND router advertisements with " |
| 793 | "Home Agent flag bit set.%s", |
| 794 | VTY_NEWLINE); |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 795 | if (rtadv->HomeAgentLifetime != -1) |
| 796 | vty_out (vty, " Home Agent lifetime is %u seconds%s", |
| 797 | rtadv->HomeAgentLifetime, VTY_NEWLINE); |
| 798 | else |
| 799 | vty_out (vty, " Home Agent lifetime tracks ra-lifetime%s", |
| 800 | VTY_NEWLINE); |
| 801 | vty_out (vty, " Home Agent preference is %u%s", |
| 802 | rtadv->HomeAgentPreference, VTY_NEWLINE); |
| 803 | } |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 804 | if (rtadv->AdvIntervalOption) |
| 805 | vty_out (vty, " ND router advertisements with Adv. Interval option.%s", |
| 806 | VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 807 | } |
| 808 | } |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 809 | #endif /* HAVE_RTADV */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 810 | |
| 811 | /* Interface's information print out to vty interface. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 812 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 813 | if_dump_vty (struct vty *vty, struct interface *ifp) |
| 814 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 815 | struct connected *connected; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 816 | struct listnode *node; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 817 | struct route_node *rn; |
| 818 | struct zebra_if *zebra_if; |
| 819 | |
| 820 | zebra_if = ifp->info; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 821 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 822 | vty_out (vty, "Interface %s is ", ifp->name); |
| 823 | if (if_is_up(ifp)) { |
| 824 | vty_out (vty, "up, line protocol "); |
| 825 | |
| 826 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) { |
| 827 | if (if_is_running(ifp)) |
| 828 | vty_out (vty, "is up%s", VTY_NEWLINE); |
| 829 | else |
| 830 | vty_out (vty, "is down%s", VTY_NEWLINE); |
| 831 | } else { |
| 832 | vty_out (vty, "detection is disabled%s", VTY_NEWLINE); |
| 833 | } |
| 834 | } else { |
| 835 | vty_out (vty, "down%s", VTY_NEWLINE); |
| 836 | } |
| 837 | |
Christian Franke | 581ecbf | 2016-05-03 19:59:43 +0200 | [diff] [blame] | 838 | vty_out (vty, " Link ups: %s%s", |
| 839 | event_counter_format(&zebra_if->up_events), VTY_NEWLINE); |
| 840 | vty_out (vty, " Link downs: %s%s", |
| 841 | event_counter_format(&zebra_if->down_events), VTY_NEWLINE); |
| 842 | |
Feng Lu | 2fc97f6 | 2015-05-22 11:39:57 +0200 | [diff] [blame] | 843 | vty_out (vty, " vrf: %u%s", ifp->vrf_id, VTY_NEWLINE); |
| 844 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 845 | if (ifp->desc) |
| 846 | vty_out (vty, " Description: %s%s", ifp->desc, |
| 847 | VTY_NEWLINE); |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 848 | if (ifp->ifindex == IFINDEX_INTERNAL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 849 | { |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 850 | vty_out(vty, " pseudo interface%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 851 | return; |
| 852 | } |
| 853 | else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 854 | { |
| 855 | vty_out(vty, " index %d inactive interface%s", |
| 856 | ifp->ifindex, |
| 857 | VTY_NEWLINE); |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | vty_out (vty, " index %d metric %d mtu %d ", |
| 862 | ifp->ifindex, ifp->metric, ifp->mtu); |
paul | 44145db | 2004-05-09 11:00:23 +0000 | [diff] [blame] | 863 | #ifdef HAVE_IPV6 |
| 864 | if (ifp->mtu6 != ifp->mtu) |
| 865 | vty_out (vty, "mtu6 %d ", ifp->mtu6); |
| 866 | #endif |
Paul Jakma | 630c97c | 2006-06-15 12:48:17 +0000 | [diff] [blame] | 867 | vty_out (vty, "%s flags: %s%s", VTY_NEWLINE, |
| 868 | if_flag_dump (ifp->flags), VTY_NEWLINE); |
paul | 3a570c8 | 2006-02-02 17:27:13 +0000 | [diff] [blame] | 869 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 870 | /* Hardware address. */ |
Timo Teräs | 954c7d6 | 2016-01-15 17:36:33 +0200 | [diff] [blame] | 871 | vty_out (vty, " Type: %s%s", if_link_type_str (ifp->ll_type), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 872 | if (ifp->hw_addr_len != 0) |
| 873 | { |
| 874 | int i; |
| 875 | |
| 876 | vty_out (vty, " HWaddr: "); |
| 877 | for (i = 0; i < ifp->hw_addr_len; i++) |
| 878 | vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]); |
| 879 | vty_out (vty, "%s", VTY_NEWLINE); |
| 880 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 881 | |
| 882 | /* Bandwidth in kbps */ |
| 883 | if (ifp->bandwidth != 0) |
| 884 | { |
| 885 | vty_out(vty, " bandwidth %u kbps", ifp->bandwidth); |
| 886 | vty_out(vty, "%s", VTY_NEWLINE); |
| 887 | } |
| 888 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 889 | for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 890 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 891 | if (! rn->info) |
| 892 | continue; |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 893 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 894 | for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected)) |
| 895 | connected_dump_vty (vty, connected); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 896 | } |
| 897 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 898 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 899 | { |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 900 | if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && |
| 901 | (connected->address->family == AF_INET6)) |
| 902 | connected_dump_vty (vty, connected); |
| 903 | } |
| 904 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 905 | if (HAS_LINK_PARAMS(ifp)) |
| 906 | { |
| 907 | int i; |
| 908 | struct if_link_params *iflp = ifp->link_params; |
| 909 | vty_out(vty, " Traffic Engineering Link Parameters:%s", VTY_NEWLINE); |
| 910 | if (IS_PARAM_SET(iflp, LP_TE)) |
| 911 | vty_out(vty, " TE metric %u%s",iflp->te_metric, VTY_NEWLINE); |
| 912 | if (IS_PARAM_SET(iflp, LP_MAX_BW)) |
| 913 | vty_out(vty, " Maximum Bandwidth %g (Byte/s)%s", iflp->max_bw, VTY_NEWLINE); |
| 914 | if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW)) |
| 915 | vty_out(vty, " Maximum Reservable Bandwidth %g (Byte/s)%s", iflp->max_rsv_bw, VTY_NEWLINE); |
| 916 | if (IS_PARAM_SET(iflp, LP_UNRSV_BW)) { |
| 917 | vty_out(vty, " Unreserved Bandwidth per Class Type in Byte/s:%s", VTY_NEWLINE); |
| 918 | for (i = 0; i < MAX_CLASS_TYPE; i+=2) |
| 919 | vty_out(vty, " [%d]: %g (Bytes/sec),\t[%d]: %g (Bytes/sec)%s", |
| 920 | i, iflp->unrsv_bw[i], i+1, iflp->unrsv_bw[i+1], VTY_NEWLINE); |
| 921 | } |
| 922 | |
| 923 | if (IS_PARAM_SET(iflp, LP_ADM_GRP)) |
| 924 | vty_out(vty, " Administrative Group:%u%s", iflp->admin_grp, VTY_NEWLINE); |
| 925 | if (IS_PARAM_SET(iflp, LP_DELAY)) |
| 926 | { |
| 927 | vty_out(vty, " Link Delay Average: %u (micro-sec.)", iflp->av_delay); |
| 928 | if (IS_PARAM_SET(iflp, LP_MM_DELAY)) |
| 929 | { |
| 930 | vty_out(vty, " Min: %u (micro-sec.)", iflp->min_delay); |
| 931 | vty_out(vty, " Max: %u (micro-sec.)", iflp->max_delay); |
| 932 | } |
| 933 | vty_out(vty, "%s", VTY_NEWLINE); |
| 934 | } |
| 935 | if (IS_PARAM_SET(iflp, LP_DELAY_VAR)) |
| 936 | vty_out(vty, " Link Delay Variation %u (micro-sec.)%s", iflp->delay_var, VTY_NEWLINE); |
| 937 | if (IS_PARAM_SET(iflp, LP_PKT_LOSS)) |
| 938 | vty_out(vty, " Link Packet Loss %g (in %%)%s", iflp->pkt_loss, VTY_NEWLINE); |
| 939 | if (IS_PARAM_SET(iflp, LP_AVA_BW)) |
| 940 | vty_out(vty, " Available Bandwidth %g (Byte/s)%s", iflp->ava_bw, VTY_NEWLINE); |
| 941 | if (IS_PARAM_SET(iflp, LP_RES_BW)) |
| 942 | vty_out(vty, " Residual Bandwidth %g (Byte/s)%s", iflp->res_bw, VTY_NEWLINE); |
| 943 | if (IS_PARAM_SET(iflp, LP_USE_BW)) |
| 944 | vty_out(vty, " Utilized Bandwidth %g (Byte/s)%s", iflp->use_bw, VTY_NEWLINE); |
| 945 | if (IS_PARAM_SET(iflp, LP_RMT_AS)) |
| 946 | vty_out(vty, " Neighbor ASBR IP: %s AS: %u %s", inet_ntoa(iflp->rmt_ip), iflp->rmt_as, VTY_NEWLINE); |
| 947 | } |
| 948 | |
| 949 | #ifdef RTADV |
| 950 | nd_dump_vty (vty, ifp); |
| 951 | #endif /* RTADV */ |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 952 | #if defined (HAVE_RTADV) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 953 | nd_dump_vty (vty, ifp); |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 954 | #endif /* HAVE_RTADV */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 955 | |
| 956 | #ifdef HAVE_PROC_NET_DEV |
| 957 | /* Statistics print out using proc file system. */ |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 958 | vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, " |
| 959 | "%lu dropped%s", |
| 960 | ifp->stats.rx_packets, ifp->stats.rx_multicast, |
| 961 | ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 962 | |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 963 | vty_out (vty, " %lu input errors, %lu length, %lu overrun," |
hasso | 3452d47 | 2005-03-06 13:42:05 +0000 | [diff] [blame] | 964 | " %lu CRC, %lu frame%s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 965 | ifp->stats.rx_errors, ifp->stats.rx_length_errors, |
| 966 | ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors, |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 967 | ifp->stats.rx_frame_errors, VTY_NEWLINE); |
| 968 | |
| 969 | vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 970 | ifp->stats.rx_missed_errors, VTY_NEWLINE); |
| 971 | |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 972 | vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 973 | ifp->stats.tx_packets, ifp->stats.tx_bytes, |
| 974 | ifp->stats.tx_dropped, VTY_NEWLINE); |
| 975 | |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 976 | vty_out (vty, " %lu output errors, %lu aborted, %lu carrier," |
| 977 | " %lu fifo, %lu heartbeat%s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 978 | ifp->stats.tx_errors, ifp->stats.tx_aborted_errors, |
| 979 | ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors, |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 980 | ifp->stats.tx_heartbeat_errors, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 981 | |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 982 | vty_out (vty, " %lu window, %lu collisions%s", |
| 983 | ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 984 | #endif /* HAVE_PROC_NET_DEV */ |
| 985 | |
| 986 | #ifdef HAVE_NET_RT_IFLIST |
| 987 | #if defined (__bsdi__) || defined (__NetBSD__) |
| 988 | /* Statistics print out using sysctl (). */ |
David Lamparter | 193e78f | 2015-04-21 10:42:30 +0200 | [diff] [blame] | 989 | vty_out (vty, " input packets %llu, bytes %llu, dropped %llu," |
| 990 | " multicast packets %llu%s", |
| 991 | (unsigned long long)ifp->stats.ifi_ipackets, |
| 992 | (unsigned long long)ifp->stats.ifi_ibytes, |
| 993 | (unsigned long long)ifp->stats.ifi_iqdrops, |
| 994 | (unsigned long long)ifp->stats.ifi_imcasts, |
| 995 | VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 996 | |
David Lamparter | 193e78f | 2015-04-21 10:42:30 +0200 | [diff] [blame] | 997 | vty_out (vty, " input errors %llu%s", |
| 998 | (unsigned long long)ifp->stats.ifi_ierrors, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 999 | |
David Lamparter | 193e78f | 2015-04-21 10:42:30 +0200 | [diff] [blame] | 1000 | vty_out (vty, " output packets %llu, bytes %llu," |
| 1001 | " multicast packets %llu%s", |
| 1002 | (unsigned long long)ifp->stats.ifi_opackets, |
| 1003 | (unsigned long long)ifp->stats.ifi_obytes, |
| 1004 | (unsigned long long)ifp->stats.ifi_omcasts, |
| 1005 | VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1006 | |
David Lamparter | 193e78f | 2015-04-21 10:42:30 +0200 | [diff] [blame] | 1007 | vty_out (vty, " output errors %llu%s", |
| 1008 | (unsigned long long)ifp->stats.ifi_oerrors, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1009 | |
David Lamparter | 193e78f | 2015-04-21 10:42:30 +0200 | [diff] [blame] | 1010 | vty_out (vty, " collisions %llu%s", |
| 1011 | (unsigned long long)ifp->stats.ifi_collisions, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1012 | #else |
| 1013 | /* Statistics print out using sysctl (). */ |
| 1014 | vty_out (vty, " input packets %lu, bytes %lu, dropped %lu," |
| 1015 | " multicast packets %lu%s", |
| 1016 | ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, |
| 1017 | ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, |
| 1018 | VTY_NEWLINE); |
| 1019 | |
| 1020 | vty_out (vty, " input errors %lu%s", |
| 1021 | ifp->stats.ifi_ierrors, VTY_NEWLINE); |
| 1022 | |
| 1023 | vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s", |
| 1024 | ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, |
| 1025 | ifp->stats.ifi_omcasts, VTY_NEWLINE); |
| 1026 | |
| 1027 | vty_out (vty, " output errors %lu%s", |
| 1028 | ifp->stats.ifi_oerrors, VTY_NEWLINE); |
| 1029 | |
| 1030 | vty_out (vty, " collisions %lu%s", |
| 1031 | ifp->stats.ifi_collisions, VTY_NEWLINE); |
| 1032 | #endif /* __bsdi__ || __NetBSD__ */ |
| 1033 | #endif /* HAVE_NET_RT_IFLIST */ |
| 1034 | } |
| 1035 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1036 | /* Wrapper hook point for zebra daemon so that ifindex can be set |
| 1037 | * DEFUN macro not used as extract.pl HAS to ignore this |
| 1038 | * See also interface_cmd in lib/if.c |
| 1039 | */ |
| 1040 | DEFUN_NOSH (zebra_interface, |
| 1041 | zebra_interface_cmd, |
| 1042 | "interface IFNAME", |
| 1043 | "Select an interface to configure\n" |
| 1044 | "Interface's name\n") |
| 1045 | { |
| 1046 | int ret; |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 1047 | struct interface *ifp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1048 | |
| 1049 | /* Call lib interface() */ |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 1050 | if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS) |
| 1051 | return ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1052 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 1053 | ifp = vty->index; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1054 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 1055 | if (ifp->ifindex == IFINDEX_INTERNAL) |
| 1056 | /* Is this really necessary? Shouldn't status be initialized to 0 |
| 1057 | in that case? */ |
| 1058 | UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1059 | |
| 1060 | return ret; |
| 1061 | } |
| 1062 | |
Feng Lu | 471ea39 | 2015-05-22 11:40:00 +0200 | [diff] [blame] | 1063 | ALIAS (zebra_interface, |
| 1064 | zebra_interface_vrf_cmd, |
| 1065 | "interface IFNAME " VRF_CMD_STR, |
| 1066 | "Select an interface to configure\n" |
| 1067 | "Interface's name\n" |
| 1068 | VRF_CMD_HELP_STR) |
| 1069 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1070 | struct cmd_node interface_node = |
| 1071 | { |
| 1072 | INTERFACE_NODE, |
| 1073 | "%s(config-if)# ", |
| 1074 | 1 |
| 1075 | }; |
| 1076 | |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1077 | /* Show all interfaces to vty. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1078 | DEFUN (show_interface, show_interface_cmd, |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1079 | "show interface", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1080 | SHOW_STR |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1081 | "Interface status and configuration\n") |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1082 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 1083 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1084 | struct interface *ifp; |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1085 | vrf_id_t vrf_id = VRF_DEFAULT; |
| 1086 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1087 | #ifdef HAVE_PROC_NET_DEV |
| 1088 | /* If system has interface statistics via proc file system, update |
| 1089 | statistics. */ |
| 1090 | ifstat_update_proc (); |
| 1091 | #endif /* HAVE_PROC_NET_DEV */ |
| 1092 | #ifdef HAVE_NET_RT_IFLIST |
| 1093 | ifstat_update_sysctl (); |
| 1094 | #endif /* HAVE_NET_RT_IFLIST */ |
| 1095 | |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1096 | if (argc > 0) |
| 1097 | VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1098 | |
| 1099 | /* All interface print. */ |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1100 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1101 | if_dump_vty (vty, ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1102 | |
| 1103 | return CMD_SUCCESS; |
| 1104 | } |
| 1105 | |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1106 | ALIAS (show_interface, |
| 1107 | show_interface_vrf_cmd, |
| 1108 | "show interface " VRF_CMD_STR, |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 1109 | SHOW_STR |
| 1110 | "Interface status and configuration\n" |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1111 | VRF_CMD_HELP_STR) |
| 1112 | |
| 1113 | /* Show all interfaces to vty. */ |
| 1114 | DEFUN (show_interface_vrf_all, show_interface_vrf_all_cmd, |
| 1115 | "show interface " VRF_ALL_CMD_STR, |
| 1116 | SHOW_STR |
| 1117 | "Interface status and configuration\n" |
| 1118 | VRF_ALL_CMD_HELP_STR) |
| 1119 | { |
| 1120 | struct listnode *node; |
| 1121 | struct interface *ifp; |
| 1122 | vrf_iter_t iter; |
| 1123 | |
| 1124 | #ifdef HAVE_PROC_NET_DEV |
| 1125 | /* If system has interface statistics via proc file system, update |
| 1126 | statistics. */ |
| 1127 | ifstat_update_proc (); |
| 1128 | #endif /* HAVE_PROC_NET_DEV */ |
| 1129 | #ifdef HAVE_NET_RT_IFLIST |
| 1130 | ifstat_update_sysctl (); |
| 1131 | #endif /* HAVE_NET_RT_IFLIST */ |
| 1132 | |
| 1133 | /* All interface print. */ |
| 1134 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
| 1135 | for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) |
| 1136 | if_dump_vty (vty, ifp); |
| 1137 | |
| 1138 | return CMD_SUCCESS; |
| 1139 | } |
| 1140 | |
| 1141 | /* Show specified interface to vty. */ |
| 1142 | DEFUN (show_interface_name, show_interface_name_cmd, |
| 1143 | "show interface IFNAME", |
| 1144 | SHOW_STR |
| 1145 | "Interface status and configuration\n" |
| 1146 | "Inteface name\n") |
| 1147 | { |
| 1148 | struct interface *ifp; |
| 1149 | vrf_id_t vrf_id = VRF_DEFAULT; |
| 1150 | |
| 1151 | #ifdef HAVE_PROC_NET_DEV |
| 1152 | /* If system has interface statistics via proc file system, update |
| 1153 | statistics. */ |
| 1154 | ifstat_update_proc (); |
| 1155 | #endif /* HAVE_PROC_NET_DEV */ |
| 1156 | #ifdef HAVE_NET_RT_IFLIST |
| 1157 | ifstat_update_sysctl (); |
| 1158 | #endif /* HAVE_NET_RT_IFLIST */ |
| 1159 | |
| 1160 | if (argc > 1) |
| 1161 | VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]); |
| 1162 | |
| 1163 | /* Specified interface print. */ |
| 1164 | ifp = if_lookup_by_name_vrf (argv[0], vrf_id); |
| 1165 | if (ifp == NULL) |
| 1166 | { |
| 1167 | vty_out (vty, "%% Can't find interface %s%s", argv[0], |
| 1168 | VTY_NEWLINE); |
| 1169 | return CMD_WARNING; |
| 1170 | } |
| 1171 | if_dump_vty (vty, ifp); |
| 1172 | |
| 1173 | return CMD_SUCCESS; |
| 1174 | } |
| 1175 | |
| 1176 | ALIAS (show_interface_name, |
| 1177 | show_interface_name_vrf_cmd, |
| 1178 | "show interface IFNAME " VRF_CMD_STR, |
| 1179 | SHOW_STR |
| 1180 | "Interface status and configuration\n" |
| 1181 | "Inteface name\n" |
| 1182 | VRF_CMD_HELP_STR) |
| 1183 | |
| 1184 | /* Show specified interface to vty. */ |
| 1185 | DEFUN (show_interface_name_vrf_all, show_interface_name_vrf_all_cmd, |
| 1186 | "show interface IFNAME " VRF_ALL_CMD_STR, |
| 1187 | SHOW_STR |
| 1188 | "Interface status and configuration\n" |
| 1189 | "Inteface name\n" |
| 1190 | VRF_ALL_CMD_HELP_STR) |
| 1191 | { |
| 1192 | struct interface *ifp; |
| 1193 | vrf_iter_t iter; |
| 1194 | int found = 0; |
| 1195 | |
| 1196 | #ifdef HAVE_PROC_NET_DEV |
| 1197 | /* If system has interface statistics via proc file system, update |
| 1198 | statistics. */ |
| 1199 | ifstat_update_proc (); |
| 1200 | #endif /* HAVE_PROC_NET_DEV */ |
| 1201 | #ifdef HAVE_NET_RT_IFLIST |
| 1202 | ifstat_update_sysctl (); |
| 1203 | #endif /* HAVE_NET_RT_IFLIST */ |
| 1204 | |
| 1205 | /* All interface print. */ |
| 1206 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
| 1207 | { |
| 1208 | /* Specified interface print. */ |
| 1209 | ifp = if_lookup_by_name_vrf (argv[0], vrf_iter2id (iter)); |
| 1210 | if (ifp) |
| 1211 | { |
| 1212 | if_dump_vty (vty, ifp); |
| 1213 | found++; |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | if (!found) |
| 1218 | { |
| 1219 | vty_out (vty, "%% Can't find interface %s%s", argv[0], VTY_NEWLINE); |
| 1220 | return CMD_WARNING; |
| 1221 | } |
| 1222 | |
| 1223 | return CMD_SUCCESS; |
| 1224 | } |
| 1225 | |
| 1226 | static void |
| 1227 | if_show_description (struct vty *vty, vrf_id_t vrf_id) |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 1228 | { |
| 1229 | struct listnode *node; |
| 1230 | struct interface *ifp; |
| 1231 | |
| 1232 | vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE); |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1233 | for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 1234 | { |
| 1235 | int len; |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 1236 | |
| 1237 | len = vty_out (vty, "%s", ifp->name); |
| 1238 | vty_out (vty, "%*s", (16 - len), " "); |
| 1239 | |
| 1240 | if (if_is_up(ifp)) |
| 1241 | { |
| 1242 | vty_out (vty, "up "); |
| 1243 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) |
| 1244 | { |
| 1245 | if (if_is_running(ifp)) |
| 1246 | vty_out (vty, "up "); |
| 1247 | else |
| 1248 | vty_out (vty, "down "); |
| 1249 | } |
| 1250 | else |
| 1251 | { |
| 1252 | vty_out (vty, "unknown "); |
| 1253 | } |
| 1254 | } |
| 1255 | else |
| 1256 | { |
| 1257 | vty_out (vty, "down down "); |
| 1258 | } |
| 1259 | |
| 1260 | if (ifp->desc) |
| 1261 | vty_out (vty, "%s", ifp->desc); |
| 1262 | vty_out (vty, "%s", VTY_NEWLINE); |
| 1263 | } |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | DEFUN (show_interface_desc, |
| 1267 | show_interface_desc_cmd, |
| 1268 | "show interface description", |
| 1269 | SHOW_STR |
| 1270 | "Interface status and configuration\n" |
| 1271 | "Interface description\n") |
| 1272 | { |
| 1273 | vrf_id_t vrf_id = VRF_DEFAULT; |
| 1274 | |
| 1275 | if (argc > 0) |
| 1276 | VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]); |
| 1277 | |
| 1278 | if_show_description (vty, vrf_id); |
| 1279 | |
| 1280 | return CMD_SUCCESS; |
| 1281 | } |
| 1282 | |
| 1283 | ALIAS (show_interface_desc, |
| 1284 | show_interface_desc_vrf_cmd, |
| 1285 | "show interface description " VRF_CMD_STR, |
| 1286 | SHOW_STR |
| 1287 | "Interface status and configuration\n" |
| 1288 | "Interface description\n" |
| 1289 | VRF_CMD_HELP_STR) |
| 1290 | |
| 1291 | DEFUN (show_interface_desc_vrf_all, |
| 1292 | show_interface_desc_vrf_all_cmd, |
| 1293 | "show interface description " VRF_ALL_CMD_STR, |
| 1294 | SHOW_STR |
| 1295 | "Interface status and configuration\n" |
| 1296 | "Interface description\n" |
| 1297 | VRF_ALL_CMD_HELP_STR) |
| 1298 | { |
| 1299 | vrf_iter_t iter; |
| 1300 | |
| 1301 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
| 1302 | if (!list_isempty (vrf_iter2iflist (iter))) |
| 1303 | { |
| 1304 | vty_out (vty, "%s\tVRF %u%s%s", VTY_NEWLINE, |
| 1305 | vrf_iter2id (iter), |
| 1306 | VTY_NEWLINE, VTY_NEWLINE); |
| 1307 | if_show_description (vty, vrf_iter2id (iter)); |
| 1308 | } |
| 1309 | |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 1310 | return CMD_SUCCESS; |
| 1311 | } |
| 1312 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1313 | DEFUN (multicast, |
| 1314 | multicast_cmd, |
| 1315 | "multicast", |
| 1316 | "Set multicast flag to interface\n") |
| 1317 | { |
| 1318 | int ret; |
| 1319 | struct interface *ifp; |
| 1320 | struct zebra_if *if_data; |
| 1321 | |
| 1322 | ifp = (struct interface *) vty->index; |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1323 | if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1324 | { |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1325 | ret = if_set_flags (ifp, IFF_MULTICAST); |
| 1326 | if (ret < 0) |
| 1327 | { |
| 1328 | vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE); |
| 1329 | return CMD_WARNING; |
| 1330 | } |
| 1331 | if_refresh (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1332 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1333 | if_data = ifp->info; |
| 1334 | if_data->multicast = IF_ZEBRA_MULTICAST_ON; |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1335 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1336 | return CMD_SUCCESS; |
| 1337 | } |
| 1338 | |
| 1339 | DEFUN (no_multicast, |
| 1340 | no_multicast_cmd, |
| 1341 | "no multicast", |
| 1342 | NO_STR |
| 1343 | "Unset multicast flag to interface\n") |
| 1344 | { |
| 1345 | int ret; |
| 1346 | struct interface *ifp; |
| 1347 | struct zebra_if *if_data; |
| 1348 | |
| 1349 | ifp = (struct interface *) vty->index; |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1350 | if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1351 | { |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1352 | ret = if_unset_flags (ifp, IFF_MULTICAST); |
| 1353 | if (ret < 0) |
| 1354 | { |
| 1355 | vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE); |
| 1356 | return CMD_WARNING; |
| 1357 | } |
| 1358 | if_refresh (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1359 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1360 | if_data = ifp->info; |
| 1361 | if_data->multicast = IF_ZEBRA_MULTICAST_OFF; |
| 1362 | |
| 1363 | return CMD_SUCCESS; |
| 1364 | } |
| 1365 | |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 1366 | /* Hacky: create a dummy node just to hang a config-writer callback off it */ |
| 1367 | static struct cmd_node zebra_if_defaults_node = { |
| 1368 | ZEBRA_IF_DEFAULTS_NODE, |
| 1369 | "", |
| 1370 | 1, |
| 1371 | }; |
| 1372 | |
| 1373 | static int |
| 1374 | config_write_zebra_if_defaults (struct vty *vty) |
| 1375 | { |
| 1376 | if (zif_defaults.linkdetect != IF_LINKDETECT_UNSPEC) |
| 1377 | vty_out (vty, "default link-detect %s%s", |
| 1378 | zif_defaults.linkdetect == IF_LINKDETECT_ON ? "on" : "off", |
| 1379 | VTY_NEWLINE); |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | DEFUN(default_linkdetect, |
| 1384 | default_linkdetect_cmd, |
| 1385 | "default link-detect (on|off)", |
| 1386 | "Configure defaults of settings\n" |
| 1387 | "Interface link detection\n" |
| 1388 | "Interface link-detect defaults to enabled\n" |
| 1389 | "Interface link-detect defaults to disabled\n") |
| 1390 | { |
| 1391 | zebra_if_linkdetect prev = zif_defaults.linkdetect; |
| 1392 | struct listnode *node; |
| 1393 | struct interface *ifp; |
| 1394 | vrf_iter_t iter; |
| 1395 | |
| 1396 | if (strcmp (argv[1], "on") == 0) |
| 1397 | zif_defaults.linkdetect = IF_LINKDETECT_ON; |
| 1398 | else |
| 1399 | zif_defaults.linkdetect = IF_LINKDETECT_OFF; |
| 1400 | |
| 1401 | if (zif_defaults.linkdetect != prev) |
| 1402 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
| 1403 | for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) |
| 1404 | if_zebra_linkdetect_set (ifp); |
| 1405 | |
| 1406 | return CMD_SUCCESS; |
| 1407 | } |
| 1408 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1409 | DEFUN (linkdetect, |
| 1410 | linkdetect_cmd, |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 1411 | "link-detect [default]", |
| 1412 | "Enable link detection on interface\n" |
| 1413 | "Leave link-detect to the default\n") |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1414 | { |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1415 | struct interface *ifp; |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 1416 | struct zebra_if *zif; |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1417 | |
| 1418 | ifp = (struct interface *) vty->index; |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 1419 | zif = ifp->info; |
| 1420 | assert (zif != NULL); |
| 1421 | |
| 1422 | zif->linkdetect = IF_LINKDETECT_ON; |
| 1423 | if_zebra_linkdetect_set (ifp); |
| 1424 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1425 | /* FIXME: Will defer status change forwarding if interface |
| 1426 | does not come down! */ |
| 1427 | |
| 1428 | return CMD_SUCCESS; |
| 1429 | } |
| 1430 | |
| 1431 | |
| 1432 | DEFUN (no_linkdetect, |
| 1433 | no_linkdetect_cmd, |
| 1434 | "no link-detect", |
| 1435 | NO_STR |
| 1436 | "Disable link detection on interface\n") |
| 1437 | { |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1438 | struct interface *ifp; |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 1439 | struct zebra_if *zif; |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1440 | |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 1441 | ifp = (struct interface *) vty->index; |
| 1442 | zif = ifp->info; |
| 1443 | assert (zif != NULL); |
| 1444 | |
| 1445 | zif->linkdetect = IF_LINKDETECT_OFF; |
| 1446 | if_zebra_linkdetect_set (ifp); |
| 1447 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1448 | /* FIXME: see linkdetect_cmd */ |
| 1449 | |
| 1450 | return CMD_SUCCESS; |
| 1451 | } |
| 1452 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1453 | DEFUN (shutdown_if, |
| 1454 | shutdown_if_cmd, |
| 1455 | "shutdown", |
| 1456 | "Shutdown the selected interface\n") |
| 1457 | { |
| 1458 | int ret; |
| 1459 | struct interface *ifp; |
| 1460 | struct zebra_if *if_data; |
| 1461 | |
| 1462 | ifp = (struct interface *) vty->index; |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 1463 | if (ifp->ifindex != IFINDEX_INTERNAL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1464 | { |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 1465 | ret = if_unset_flags (ifp, IFF_UP); |
| 1466 | if (ret < 0) |
| 1467 | { |
| 1468 | vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE); |
| 1469 | return CMD_WARNING; |
| 1470 | } |
| 1471 | if_refresh (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1472 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1473 | if_data = ifp->info; |
| 1474 | if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON; |
| 1475 | |
| 1476 | return CMD_SUCCESS; |
| 1477 | } |
| 1478 | |
| 1479 | DEFUN (no_shutdown_if, |
| 1480 | no_shutdown_if_cmd, |
| 1481 | "no shutdown", |
| 1482 | NO_STR |
| 1483 | "Shutdown the selected interface\n") |
| 1484 | { |
| 1485 | int ret; |
| 1486 | struct interface *ifp; |
| 1487 | struct zebra_if *if_data; |
| 1488 | |
| 1489 | ifp = (struct interface *) vty->index; |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 1490 | |
| 1491 | if (ifp->ifindex != IFINDEX_INTERNAL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1492 | { |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 1493 | ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 1494 | if (ret < 0) |
| 1495 | { |
| 1496 | vty_out (vty, "Can't up interface%s", VTY_NEWLINE); |
| 1497 | return CMD_WARNING; |
| 1498 | } |
| 1499 | if_refresh (ifp); |
| 1500 | |
| 1501 | /* Some addresses (in particular, IPv6 addresses on Linux) get |
| 1502 | * removed when the interface goes down. They need to be readded. |
| 1503 | */ |
| 1504 | if_addr_wakeup(ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1505 | } |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 1506 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1507 | if_data = ifp->info; |
| 1508 | if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF; |
| 1509 | |
| 1510 | return CMD_SUCCESS; |
| 1511 | } |
| 1512 | |
| 1513 | DEFUN (bandwidth_if, |
| 1514 | bandwidth_if_cmd, |
| 1515 | "bandwidth <1-10000000>", |
| 1516 | "Set bandwidth informational parameter\n" |
| 1517 | "Bandwidth in kilobits\n") |
| 1518 | { |
| 1519 | struct interface *ifp; |
| 1520 | unsigned int bandwidth; |
| 1521 | |
| 1522 | ifp = (struct interface *) vty->index; |
| 1523 | bandwidth = strtol(argv[0], NULL, 10); |
| 1524 | |
| 1525 | /* bandwidth range is <1-10000000> */ |
| 1526 | if (bandwidth < 1 || bandwidth > 10000000) |
| 1527 | { |
| 1528 | vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE); |
| 1529 | return CMD_WARNING; |
| 1530 | } |
| 1531 | |
| 1532 | ifp->bandwidth = bandwidth; |
| 1533 | |
| 1534 | /* force protocols to recalculate routes due to cost change */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1535 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1536 | zebra_interface_up_update (ifp); |
| 1537 | |
| 1538 | return CMD_SUCCESS; |
| 1539 | } |
| 1540 | |
| 1541 | DEFUN (no_bandwidth_if, |
| 1542 | no_bandwidth_if_cmd, |
| 1543 | "no bandwidth", |
| 1544 | NO_STR |
| 1545 | "Set bandwidth informational parameter\n") |
| 1546 | { |
| 1547 | struct interface *ifp; |
| 1548 | |
| 1549 | ifp = (struct interface *) vty->index; |
| 1550 | |
| 1551 | ifp->bandwidth = 0; |
| 1552 | |
| 1553 | /* force protocols to recalculate routes due to cost change */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1554 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1555 | zebra_interface_up_update (ifp); |
| 1556 | |
| 1557 | return CMD_SUCCESS; |
| 1558 | } |
| 1559 | |
| 1560 | ALIAS (no_bandwidth_if, |
| 1561 | no_bandwidth_if_val_cmd, |
| 1562 | "no bandwidth <1-10000000>", |
| 1563 | NO_STR |
| 1564 | "Set bandwidth informational parameter\n" |
| 1565 | "Bandwidth in kilobits\n") |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1566 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 1567 | struct cmd_node link_params_node = |
| 1568 | { |
| 1569 | LINK_PARAMS_NODE, |
| 1570 | "%s(config-link-params)# ", |
| 1571 | 1, |
| 1572 | }; |
| 1573 | |
| 1574 | static void |
| 1575 | link_param_cmd_set_uint32 (struct interface *ifp, uint32_t *field, |
| 1576 | uint32_t type, uint32_t value) |
| 1577 | { |
| 1578 | /* Update field as needed */ |
| 1579 | if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value) |
| 1580 | { |
| 1581 | *field = value; |
| 1582 | SET_PARAM(ifp->link_params, type); |
| 1583 | |
| 1584 | /* force protocols to update LINK STATE due to parameters change */ |
| 1585 | if (if_is_operative (ifp)) |
| 1586 | zebra_interface_parameters_update (ifp); |
| 1587 | } |
| 1588 | } |
| 1589 | static void |
| 1590 | link_param_cmd_set_float (struct interface *ifp, float *field, |
| 1591 | uint32_t type, float value) |
| 1592 | { |
| 1593 | |
| 1594 | /* Update field as needed */ |
| 1595 | if (IS_PARAM_UNSET(ifp->link_params, type) || *field != value) |
| 1596 | { |
| 1597 | *field = value; |
| 1598 | SET_PARAM(ifp->link_params, type); |
| 1599 | |
| 1600 | /* force protocols to update LINK STATE due to parameters change */ |
| 1601 | if (if_is_operative (ifp)) |
| 1602 | zebra_interface_parameters_update (ifp); |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | static void |
| 1607 | link_param_cmd_unset (struct interface *ifp, uint32_t type) |
| 1608 | { |
| 1609 | |
| 1610 | /* Unset field */ |
| 1611 | UNSET_PARAM(ifp->link_params, type); |
| 1612 | |
| 1613 | /* force protocols to update LINK STATE due to parameters change */ |
| 1614 | if (if_is_operative (ifp)) |
| 1615 | zebra_interface_parameters_update (ifp); |
| 1616 | } |
| 1617 | |
| 1618 | DEFUN (link_params, |
| 1619 | link_params_cmd, |
| 1620 | "link-params", |
| 1621 | LINK_PARAMS_STR) |
| 1622 | { |
| 1623 | vty->node = LINK_PARAMS_NODE; |
| 1624 | |
| 1625 | return CMD_SUCCESS; |
| 1626 | } |
| 1627 | |
| 1628 | /* Specific Traffic Engineering parameters commands */ |
| 1629 | DEFUN (link_params_enable, |
| 1630 | link_params_enable_cmd, |
| 1631 | "enable", |
| 1632 | "Activate link parameters on this interface\n") |
| 1633 | { |
| 1634 | struct interface *ifp = (struct interface *) vty->index; |
| 1635 | |
| 1636 | /* This command could be issue at startup, when activate MPLS TE */ |
| 1637 | /* on a new interface or after a ON / OFF / ON toggle */ |
| 1638 | /* In all case, TE parameters are reset to their default factory */ |
| 1639 | if (IS_ZEBRA_DEBUG_EVENT) |
| 1640 | zlog_debug ("Link-params: enable TE link parameters on interface %s", ifp->name); |
| 1641 | |
| 1642 | if (!if_link_params_get (ifp)) |
| 1643 | { |
| 1644 | if (IS_ZEBRA_DEBUG_EVENT) |
| 1645 | zlog_debug ("Link-params: failed to init TE link parameters %s", ifp->name); |
| 1646 | |
| 1647 | return CMD_WARNING; |
| 1648 | } |
| 1649 | |
| 1650 | /* force protocols to update LINK STATE due to parameters change */ |
| 1651 | if (if_is_operative (ifp)) |
| 1652 | zebra_interface_parameters_update (ifp); |
| 1653 | |
| 1654 | return CMD_SUCCESS; |
| 1655 | } |
| 1656 | |
| 1657 | DEFUN (no_link_params_enable, |
| 1658 | no_link_params_enable_cmd, |
| 1659 | "no enable", |
| 1660 | NO_STR |
| 1661 | "Disable link parameters on this interface\n") |
| 1662 | { |
| 1663 | struct interface *ifp = (struct interface *) vty->index; |
| 1664 | |
| 1665 | zlog_debug ("MPLS-TE: disable TE link parameters on interface %s", ifp->name); |
| 1666 | |
| 1667 | if_link_params_free (ifp); |
| 1668 | |
| 1669 | /* force protocols to update LINK STATE due to parameters change */ |
| 1670 | if (if_is_operative (ifp)) |
| 1671 | zebra_interface_parameters_update (ifp); |
| 1672 | |
| 1673 | return CMD_SUCCESS; |
| 1674 | } |
| 1675 | |
| 1676 | /* STANDARD TE metrics */ |
| 1677 | DEFUN (link_params_metric, |
| 1678 | link_params_metric_cmd, |
| 1679 | "metric <0-4294967295>", |
| 1680 | "Link metric for MPLS-TE purpose\n" |
| 1681 | "Metric value in decimal\n") |
| 1682 | { |
| 1683 | struct interface *ifp = (struct interface *) vty->index; |
| 1684 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 1685 | u_int32_t metric; |
| 1686 | |
| 1687 | VTY_GET_ULONG("metric", metric, argv[0]); |
| 1688 | |
| 1689 | /* Update TE metric if needed */ |
| 1690 | link_param_cmd_set_uint32 (ifp, &iflp->te_metric, LP_TE, metric); |
| 1691 | |
| 1692 | return CMD_SUCCESS; |
| 1693 | } |
| 1694 | |
| 1695 | DEFUN (no_link_params_metric, |
| 1696 | no_link_params_metric_cmd, |
| 1697 | "no metric", |
| 1698 | NO_STR |
| 1699 | "Disbale Link Metric on this interface\n") |
| 1700 | { |
| 1701 | struct interface *ifp = (struct interface *) vty->index; |
| 1702 | |
| 1703 | /* Unset TE Metric */ |
| 1704 | link_param_cmd_unset(ifp, LP_TE); |
| 1705 | |
| 1706 | return CMD_SUCCESS; |
| 1707 | } |
| 1708 | |
| 1709 | DEFUN (link_params_maxbw, |
| 1710 | link_params_maxbw_cmd, |
| 1711 | "max-bw BANDWIDTH", |
| 1712 | "Maximum bandwidth that can be used\n" |
| 1713 | "Bytes/second (IEEE floating point format)\n") |
| 1714 | { |
| 1715 | struct interface *ifp = (struct interface *) vty->index; |
| 1716 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 1717 | |
| 1718 | float bw; |
| 1719 | |
| 1720 | if (sscanf (argv[0], "%g", &bw) != 1) |
| 1721 | { |
| 1722 | vty_out (vty, "link_params_maxbw: fscanf: %s%s", safe_strerror (errno), |
| 1723 | VTY_NEWLINE); |
| 1724 | return CMD_WARNING; |
| 1725 | } |
| 1726 | |
| 1727 | /* Check that Maximum bandwidth is not lower than other bandwidth parameters */ |
| 1728 | if ((bw <= iflp->max_rsv_bw) |
| 1729 | || (bw <= iflp->unrsv_bw[0]) |
| 1730 | || (bw <= iflp->unrsv_bw[1]) |
| 1731 | || (bw <= iflp->unrsv_bw[2]) |
| 1732 | || (bw <= iflp->unrsv_bw[3]) |
| 1733 | || (bw <= iflp->unrsv_bw[4]) |
| 1734 | || (bw <= iflp->unrsv_bw[5]) |
| 1735 | || (bw <= iflp->unrsv_bw[6]) |
| 1736 | || (bw <= iflp->unrsv_bw[7]) |
| 1737 | || (bw <= iflp->ava_bw) |
| 1738 | || (bw <= iflp->res_bw) |
| 1739 | || (bw <= iflp->use_bw)) |
| 1740 | { |
| 1741 | vty_out (vty, |
| 1742 | "Maximum Bandwidth could not be lower than others bandwidth%s", |
| 1743 | VTY_NEWLINE); |
| 1744 | return CMD_WARNING; |
| 1745 | } |
| 1746 | |
| 1747 | /* Update Maximum Bandwidth if needed */ |
| 1748 | link_param_cmd_set_float (ifp, &iflp->max_bw, LP_MAX_BW, bw); |
| 1749 | |
| 1750 | return CMD_SUCCESS; |
| 1751 | } |
| 1752 | |
| 1753 | DEFUN (link_params_max_rsv_bw, |
| 1754 | link_params_max_rsv_bw_cmd, |
| 1755 | "max-rsv-bw BANDWIDTH", |
| 1756 | "Maximum bandwidth that may be reserved\n" |
| 1757 | "Bytes/second (IEEE floating point format)\n") |
| 1758 | { |
| 1759 | struct interface *ifp = (struct interface *) vty->index; |
| 1760 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 1761 | float bw; |
| 1762 | |
| 1763 | if (sscanf (argv[0], "%g", &bw) != 1) |
| 1764 | { |
| 1765 | vty_out (vty, "link_params_max_rsv_bw: fscanf: %s%s", safe_strerror (errno), |
| 1766 | VTY_NEWLINE); |
| 1767 | return CMD_WARNING; |
| 1768 | } |
| 1769 | |
| 1770 | /* Check that bandwidth is not greater than maximum bandwidth parameter */ |
| 1771 | if (bw > iflp->max_bw) |
| 1772 | { |
| 1773 | vty_out (vty, |
| 1774 | "Maximum Reservable Bandwidth could not be greater than Maximum Bandwidth (%g)%s", |
| 1775 | iflp->max_bw, VTY_NEWLINE); |
| 1776 | return CMD_WARNING; |
| 1777 | } |
| 1778 | |
| 1779 | /* Update Maximum Reservable Bandwidth if needed */ |
| 1780 | link_param_cmd_set_float (ifp, &iflp->max_rsv_bw, LP_MAX_RSV_BW, bw); |
| 1781 | |
| 1782 | return CMD_SUCCESS; |
| 1783 | } |
| 1784 | |
| 1785 | DEFUN (link_params_unrsv_bw, |
| 1786 | link_params_unrsv_bw_cmd, |
| 1787 | "unrsv-bw <0-7> BANDWIDTH", |
| 1788 | "Unreserved bandwidth at each priority level\n" |
| 1789 | "Priority\n" |
| 1790 | "Bytes/second (IEEE floating point format)\n") |
| 1791 | { |
| 1792 | struct interface *ifp = (struct interface *) vty->index; |
| 1793 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 1794 | int priority; |
| 1795 | float bw; |
| 1796 | |
| 1797 | /* We don't have to consider about range check here. */ |
| 1798 | if (sscanf (argv[0], "%d", &priority) != 1) |
| 1799 | { |
| 1800 | vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno), |
| 1801 | VTY_NEWLINE); |
| 1802 | return CMD_WARNING; |
| 1803 | } |
| 1804 | |
| 1805 | if (sscanf (argv[1], "%g", &bw) != 1) |
| 1806 | { |
| 1807 | vty_out (vty, "link_params_unrsv_bw: fscanf: %s%s", safe_strerror (errno), |
| 1808 | VTY_NEWLINE); |
| 1809 | return CMD_WARNING; |
| 1810 | } |
| 1811 | |
| 1812 | /* Check that bandwidth is not greater than maximum bandwidth parameter */ |
| 1813 | if (bw > iflp->max_bw) |
| 1814 | { |
| 1815 | vty_out (vty, |
| 1816 | "UnReserved Bandwidth could not be greater than Maximum Bandwidth (%g)%s", |
| 1817 | iflp->max_bw, VTY_NEWLINE); |
| 1818 | return CMD_WARNING; |
| 1819 | } |
| 1820 | |
| 1821 | /* Update Unreserved Bandwidth if needed */ |
| 1822 | link_param_cmd_set_float (ifp, &iflp->unrsv_bw[priority], LP_UNRSV_BW, bw); |
| 1823 | |
| 1824 | return CMD_SUCCESS; |
| 1825 | } |
| 1826 | |
| 1827 | DEFUN (link_params_admin_grp, |
| 1828 | link_params_admin_grp_cmd, |
| 1829 | "admin-grp BITPATTERN", |
| 1830 | "Administrative group membership\n" |
| 1831 | "32-bit Hexadecimal value (e.g. 0xa1)\n") |
| 1832 | { |
| 1833 | struct interface *ifp = (struct interface *) vty->index; |
| 1834 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 1835 | unsigned long value; |
| 1836 | |
| 1837 | if (sscanf (argv[0], "0x%lx", &value) != 1) |
| 1838 | { |
| 1839 | vty_out (vty, "link_params_admin_grp: fscanf: %s%s", |
| 1840 | safe_strerror (errno), VTY_NEWLINE); |
| 1841 | return CMD_WARNING; |
| 1842 | } |
| 1843 | |
| 1844 | /* Update Administrative Group if needed */ |
| 1845 | link_param_cmd_set_uint32 (ifp, &iflp->admin_grp, LP_ADM_GRP, value); |
| 1846 | |
| 1847 | return CMD_SUCCESS; |
| 1848 | } |
| 1849 | |
| 1850 | DEFUN (no_link_params_admin_grp, |
| 1851 | no_link_params_admin_grp_cmd, |
| 1852 | "no admin-grp", |
| 1853 | NO_STR |
| 1854 | "Disbale Administrative group membership on this interface\n") |
| 1855 | { |
| 1856 | struct interface *ifp = (struct interface *) vty->index; |
| 1857 | |
| 1858 | /* Unset Admin Group */ |
| 1859 | link_param_cmd_unset(ifp, LP_ADM_GRP); |
| 1860 | |
| 1861 | return CMD_SUCCESS; |
| 1862 | } |
| 1863 | |
| 1864 | /* RFC5392 & RFC5316: INTER-AS */ |
| 1865 | DEFUN (link_params_inter_as, |
| 1866 | link_params_inter_as_cmd, |
| 1867 | "neighbor A.B.C.D as <1-4294967295>", |
| 1868 | "Configure remote ASBR information (Neighbor IP address and AS number)\n" |
| 1869 | "Remote IP address in dot decimal A.B.C.D\n" |
| 1870 | "Remote AS number\n" |
| 1871 | "AS number in the range <1-4294967295>\n") |
| 1872 | { |
| 1873 | |
| 1874 | struct interface *ifp = (struct interface *) vty->index; |
| 1875 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 1876 | struct in_addr addr; |
| 1877 | u_int32_t as; |
| 1878 | |
| 1879 | if (!inet_aton (argv[0], &addr)) |
| 1880 | { |
| 1881 | vty_out (vty, "Please specify Router-Addr by A.B.C.D%s", VTY_NEWLINE); |
| 1882 | return CMD_WARNING; |
| 1883 | } |
| 1884 | |
| 1885 | VTY_GET_ULONG("AS number", as, argv[1]); |
| 1886 | |
| 1887 | /* Update Remote IP and Remote AS fields if needed */ |
| 1888 | if (IS_PARAM_UNSET(iflp, LP_RMT_AS) |
| 1889 | || iflp->rmt_as != as |
| 1890 | || iflp->rmt_ip.s_addr != addr.s_addr) |
| 1891 | { |
| 1892 | |
| 1893 | iflp->rmt_as = as; |
| 1894 | iflp->rmt_ip.s_addr = addr.s_addr; |
| 1895 | SET_PARAM(iflp, LP_RMT_AS); |
| 1896 | |
| 1897 | /* force protocols to update LINK STATE due to parameters change */ |
| 1898 | if (if_is_operative (ifp)) |
| 1899 | zebra_interface_parameters_update (ifp); |
| 1900 | } |
| 1901 | return CMD_SUCCESS; |
| 1902 | } |
| 1903 | |
| 1904 | DEFUN (no_link_params_inter_as, |
| 1905 | no_link_params_inter_as_cmd, |
| 1906 | "no neighbor", |
| 1907 | NO_STR |
| 1908 | "Remove Neighbor IP address and AS number for Inter-AS TE\n") |
| 1909 | { |
| 1910 | |
| 1911 | struct interface *ifp = (struct interface *) vty->index; |
| 1912 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 1913 | |
| 1914 | /* Reset Remote IP and AS neighbor */ |
| 1915 | iflp->rmt_as = 0; |
| 1916 | iflp->rmt_ip.s_addr = 0; |
| 1917 | UNSET_PARAM(iflp, LP_RMT_AS); |
| 1918 | |
| 1919 | /* force protocols to update LINK STATE due to parameters change */ |
| 1920 | if (if_is_operative (ifp)) |
| 1921 | zebra_interface_parameters_update (ifp); |
| 1922 | |
| 1923 | return CMD_SUCCESS; |
| 1924 | } |
| 1925 | |
| 1926 | /* RFC7471: OSPF Traffic Engineering (TE) Metric extensions & draft-ietf-isis-metric-extensions-07.txt */ |
| 1927 | DEFUN (link_params_delay, |
| 1928 | link_params_delay_cmd, |
| 1929 | "delay <0-16777215>", |
| 1930 | "Unidirectional Average Link Delay\n" |
| 1931 | "Average delay in micro-second as decimal (0...16777215)\n") |
| 1932 | { |
| 1933 | |
| 1934 | struct interface *ifp = (struct interface *) vty->index; |
| 1935 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 1936 | u_int32_t delay = 0, low = 0, high = 0; |
| 1937 | u_int8_t update = 0; |
| 1938 | |
| 1939 | /* Get and Check new delay values */ |
| 1940 | VTY_GET_ULONG("delay", delay, argv[0]); |
| 1941 | switch (argc) |
| 1942 | { |
| 1943 | case 1: |
| 1944 | /* Check new delay value against old Min and Max delays if set */ |
| 1945 | if (IS_PARAM_SET(iflp, LP_MM_DELAY) |
| 1946 | && (delay <= iflp->min_delay || delay >= iflp->max_delay)) |
| 1947 | { |
| 1948 | vty_out (vty, "Average delay should be comprise between Min (%d) and Max (%d) delay%s", |
| 1949 | iflp->min_delay, iflp->max_delay, VTY_NEWLINE); |
| 1950 | return CMD_WARNING; |
| 1951 | } |
| 1952 | /* Update delay if value is not set or change */ |
| 1953 | if (IS_PARAM_UNSET(iflp, LP_DELAY)|| iflp->av_delay != delay) |
| 1954 | { |
| 1955 | iflp->av_delay = delay; |
| 1956 | SET_PARAM(iflp, LP_DELAY); |
| 1957 | update = 1; |
| 1958 | } |
| 1959 | /* Unset Min and Max delays if already set */ |
| 1960 | if (IS_PARAM_SET(iflp, LP_MM_DELAY)) |
| 1961 | { |
| 1962 | iflp->min_delay = 0; |
| 1963 | iflp->max_delay = 0; |
| 1964 | UNSET_PARAM(iflp, LP_MM_DELAY); |
| 1965 | update = 1; |
| 1966 | } |
| 1967 | break; |
| 1968 | case 2: |
| 1969 | vty_out (vty, "You should specify both Minimum and Maximum delay with Average delay%s", |
| 1970 | VTY_NEWLINE); |
| 1971 | return CMD_WARNING; |
| 1972 | break; |
| 1973 | case 3: |
| 1974 | VTY_GET_ULONG("minimum delay", low, argv[1]); |
| 1975 | VTY_GET_ULONG("maximum delay", high, argv[2]); |
| 1976 | /* Check new delays value coherency */ |
| 1977 | if (delay <= low || delay >= high) |
| 1978 | { |
| 1979 | vty_out (vty, "Average delay should be comprise between Min (%d) and Max (%d) delay%s", |
| 1980 | low, high, VTY_NEWLINE); |
| 1981 | return CMD_WARNING; |
| 1982 | } |
| 1983 | /* Update Delays if needed */ |
| 1984 | if (IS_PARAM_UNSET(iflp, LP_DELAY) |
| 1985 | || IS_PARAM_UNSET(iflp, LP_MM_DELAY) |
| 1986 | || iflp->av_delay != delay |
| 1987 | || iflp->min_delay != low |
| 1988 | || iflp->max_delay != high) |
| 1989 | { |
| 1990 | iflp->av_delay = delay; |
| 1991 | SET_PARAM(iflp, LP_DELAY); |
| 1992 | iflp->min_delay = low; |
| 1993 | iflp->max_delay = high; |
| 1994 | SET_PARAM(iflp, LP_MM_DELAY); |
| 1995 | update = 1; |
| 1996 | } |
| 1997 | break; |
| 1998 | default: |
| 1999 | return CMD_WARNING; |
| 2000 | break; |
| 2001 | } |
| 2002 | |
| 2003 | /* force protocols to update LINK STATE due to parameters change */ |
| 2004 | if (update == 1 && if_is_operative (ifp)) |
| 2005 | zebra_interface_parameters_update (ifp); |
| 2006 | |
| 2007 | return CMD_SUCCESS; |
| 2008 | } |
| 2009 | |
| 2010 | ALIAS (link_params_delay, |
| 2011 | link_params_delay_mm_cmd, |
| 2012 | "delay <0-16777215> min <0-16777215> max <0-16777215>", |
| 2013 | "Unidirectional Average Link Delay (optionally Minimum and Maximum delays)\n" |
| 2014 | "Average delay in micro-second as decimal (0...16777215)\n" |
| 2015 | "Minimum delay\n" |
| 2016 | "Minimum delay in micro-second as decimal (0...16777215)\n" |
| 2017 | "Maximum delay\n" |
| 2018 | "Maximum delay in micro-second as decimal (0...16777215)\n") |
| 2019 | |
| 2020 | DEFUN (no_link_params_delay, |
| 2021 | no_link_params_delay_cmd, |
| 2022 | "no delay", |
| 2023 | NO_STR |
| 2024 | "Disbale Unidirectional Average, Min & Max Link Delay on this interface\n") |
| 2025 | { |
| 2026 | struct interface *ifp = (struct interface *) vty->index; |
| 2027 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 2028 | |
| 2029 | /* Unset Delays */ |
| 2030 | iflp->av_delay = 0; |
| 2031 | UNSET_PARAM(iflp, LP_DELAY); |
| 2032 | iflp->min_delay = 0; |
| 2033 | iflp->max_delay = 0; |
| 2034 | UNSET_PARAM(iflp, LP_MM_DELAY); |
| 2035 | |
| 2036 | /* force protocols to update LINK STATE due to parameters change */ |
| 2037 | if (if_is_operative (ifp)) |
| 2038 | zebra_interface_parameters_update (ifp); |
| 2039 | |
| 2040 | return CMD_SUCCESS; |
| 2041 | } |
| 2042 | |
| 2043 | DEFUN (link_params_delay_var, |
| 2044 | link_params_delay_var_cmd, |
| 2045 | "delay-variation <0-16777215>", |
| 2046 | "Unidirectional Link Delay Variation\n" |
| 2047 | "delay variation in micro-second as decimal (0...16777215)\n") |
| 2048 | { |
| 2049 | struct interface *ifp = (struct interface *) vty->index; |
| 2050 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 2051 | u_int32_t value; |
| 2052 | |
| 2053 | VTY_GET_ULONG("delay variation", value, argv[0]); |
| 2054 | |
| 2055 | /* Update Delay Variation if needed */ |
| 2056 | link_param_cmd_set_uint32 (ifp, &iflp->delay_var, LP_DELAY_VAR, value); |
| 2057 | |
| 2058 | return CMD_SUCCESS; |
| 2059 | } |
| 2060 | |
| 2061 | DEFUN (no_link_params_delay_var, |
| 2062 | no_link_params_delay_var_cmd, |
| 2063 | "no delay-variation", |
| 2064 | NO_STR |
| 2065 | "Disbale Unidirectional Delay Variation on this interface\n") |
| 2066 | { |
| 2067 | struct interface *ifp = (struct interface *) vty->index; |
| 2068 | |
| 2069 | /* Unset Delay Variation */ |
| 2070 | link_param_cmd_unset(ifp, LP_DELAY_VAR); |
| 2071 | |
| 2072 | return CMD_SUCCESS; |
| 2073 | } |
| 2074 | |
| 2075 | DEFUN (link_params_pkt_loss, |
| 2076 | link_params_pkt_loss_cmd, |
| 2077 | "packet-loss PERCENTAGE", |
| 2078 | "Unidirectional Link Packet Loss\n" |
| 2079 | "percentage of total traffic by 0.000003% step and less than 50.331642%\n") |
| 2080 | { |
| 2081 | struct interface *ifp = (struct interface *) vty->index; |
| 2082 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 2083 | float fval; |
| 2084 | |
| 2085 | if (sscanf (argv[0], "%g", &fval) != 1) |
| 2086 | { |
| 2087 | vty_out (vty, "link_params_pkt_loss: fscanf: %s%s", safe_strerror (errno), |
| 2088 | VTY_NEWLINE); |
| 2089 | return CMD_WARNING; |
| 2090 | } |
| 2091 | |
| 2092 | if (fval > MAX_PKT_LOSS) |
| 2093 | fval = MAX_PKT_LOSS; |
| 2094 | |
| 2095 | /* Update Packet Loss if needed */ |
| 2096 | link_param_cmd_set_float (ifp, &iflp->pkt_loss, LP_PKT_LOSS, fval); |
| 2097 | |
| 2098 | return CMD_SUCCESS; |
| 2099 | } |
| 2100 | |
| 2101 | DEFUN (no_link_params_pkt_loss, |
| 2102 | no_link_params_pkt_loss_cmd, |
| 2103 | "no packet-loss", |
| 2104 | NO_STR |
| 2105 | "Disbale Unidirectional Link Packet Loss on this interface\n") |
| 2106 | { |
| 2107 | struct interface *ifp = (struct interface *) vty->index; |
| 2108 | |
| 2109 | /* Unset Packet Loss */ |
| 2110 | link_param_cmd_unset(ifp, LP_PKT_LOSS); |
| 2111 | |
| 2112 | return CMD_SUCCESS; |
| 2113 | } |
| 2114 | |
| 2115 | DEFUN (link_params_res_bw, |
| 2116 | link_params_res_bw_cmd, |
| 2117 | "res-bw BANDWIDTH", |
| 2118 | "Unidirectional Residual Bandwidth\n" |
| 2119 | "Bytes/second (IEEE floating point format)\n") |
| 2120 | { |
| 2121 | struct interface *ifp = (struct interface *) vty->index; |
| 2122 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 2123 | float bw; |
| 2124 | |
| 2125 | if (sscanf (argv[0], "%g", &bw) != 1) |
| 2126 | { |
| 2127 | vty_out (vty, "link_params_res_bw: fscanf: %s%s", safe_strerror (errno), |
| 2128 | VTY_NEWLINE); |
| 2129 | return CMD_WARNING; |
| 2130 | } |
| 2131 | |
| 2132 | /* Check that bandwidth is not greater than maximum bandwidth parameter */ |
| 2133 | if (bw > iflp->max_bw) |
| 2134 | { |
| 2135 | vty_out (vty, |
| 2136 | "Residual Bandwidth could not be greater than Maximum Bandwidth (%g)%s", |
| 2137 | iflp->max_bw, VTY_NEWLINE); |
| 2138 | return CMD_WARNING; |
| 2139 | } |
| 2140 | |
| 2141 | /* Update Residual Bandwidth if needed */ |
| 2142 | link_param_cmd_set_float (ifp, &iflp->res_bw, LP_RES_BW, bw); |
| 2143 | |
| 2144 | return CMD_SUCCESS; |
| 2145 | } |
| 2146 | |
| 2147 | DEFUN (no_link_params_res_bw, |
| 2148 | no_link_params_res_bw_cmd, |
| 2149 | "no res-bw", |
| 2150 | NO_STR |
| 2151 | "Disbale Unidirectional Residual Bandwidth on this interface\n") |
| 2152 | { |
| 2153 | struct interface *ifp = (struct interface *) vty->index; |
| 2154 | |
| 2155 | /* Unset Residual Bandwidth */ |
| 2156 | link_param_cmd_unset(ifp, LP_RES_BW); |
| 2157 | |
| 2158 | return CMD_SUCCESS; |
| 2159 | } |
| 2160 | |
| 2161 | DEFUN (link_params_ava_bw, |
| 2162 | link_params_ava_bw_cmd, |
| 2163 | "ava-bw BANDWIDTH", |
| 2164 | "Unidirectional Available Bandwidth\n" |
| 2165 | "Bytes/second (IEEE floating point format)\n") |
| 2166 | { |
| 2167 | struct interface *ifp = (struct interface *) vty->index; |
| 2168 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 2169 | float bw; |
| 2170 | |
| 2171 | if (sscanf (argv[0], "%g", &bw) != 1) |
| 2172 | { |
| 2173 | vty_out (vty, "link_params_ava_bw: fscanf: %s%s", safe_strerror (errno), |
| 2174 | VTY_NEWLINE); |
| 2175 | return CMD_WARNING; |
| 2176 | } |
| 2177 | |
| 2178 | /* Check that bandwidth is not greater than maximum bandwidth parameter */ |
| 2179 | if (bw > iflp->max_bw) |
| 2180 | { |
| 2181 | vty_out (vty, |
| 2182 | "Available Bandwidth could not be greater than Maximum Bandwidth (%g)%s", |
| 2183 | iflp->max_bw, VTY_NEWLINE); |
| 2184 | return CMD_WARNING; |
| 2185 | } |
| 2186 | |
| 2187 | /* Update Residual Bandwidth if needed */ |
| 2188 | link_param_cmd_set_float (ifp, &iflp->ava_bw, LP_AVA_BW, bw); |
| 2189 | |
| 2190 | return CMD_SUCCESS; |
| 2191 | } |
| 2192 | |
| 2193 | DEFUN (no_link_params_ava_bw, |
| 2194 | no_link_params_ava_bw_cmd, |
| 2195 | "no ava-bw", |
| 2196 | NO_STR |
| 2197 | "Disbale Unidirectional Available Bandwidth on this interface\n") |
| 2198 | { |
| 2199 | struct interface *ifp = (struct interface *) vty->index; |
| 2200 | |
| 2201 | /* Unset Available Bandwidth */ |
| 2202 | link_param_cmd_unset(ifp, LP_AVA_BW); |
| 2203 | |
| 2204 | return CMD_SUCCESS; |
| 2205 | } |
| 2206 | |
| 2207 | DEFUN (link_params_use_bw, |
| 2208 | link_params_use_bw_cmd, |
| 2209 | "use-bw BANDWIDTH", |
| 2210 | "Unidirectional Utilised Bandwidth\n" |
| 2211 | "Bytes/second (IEEE floating point format)\n") |
| 2212 | { |
| 2213 | struct interface *ifp = (struct interface *) vty->index; |
| 2214 | struct if_link_params *iflp = if_link_params_get (ifp); |
| 2215 | float bw; |
| 2216 | |
| 2217 | if (sscanf (argv[0], "%g", &bw) != 1) |
| 2218 | { |
| 2219 | vty_out (vty, "link_params_use_bw: fscanf: %s%s", safe_strerror (errno), |
| 2220 | VTY_NEWLINE); |
| 2221 | return CMD_WARNING; |
| 2222 | } |
| 2223 | |
| 2224 | /* Check that bandwidth is not greater than maximum bandwidth parameter */ |
| 2225 | if (bw > iflp->max_bw) |
| 2226 | { |
| 2227 | vty_out (vty, |
| 2228 | "Utilised Bandwidth could not be greater than Maximum Bandwidth (%g)%s", |
| 2229 | iflp->max_bw, VTY_NEWLINE); |
| 2230 | return CMD_WARNING; |
| 2231 | } |
| 2232 | |
| 2233 | /* Update Utilized Bandwidth if needed */ |
| 2234 | link_param_cmd_set_float (ifp, &iflp->use_bw, LP_USE_BW, bw); |
| 2235 | |
| 2236 | return CMD_SUCCESS; |
| 2237 | } |
| 2238 | |
| 2239 | DEFUN (no_link_params_use_bw, |
| 2240 | no_link_params_use_bw_cmd, |
| 2241 | "no use-bw", |
| 2242 | NO_STR |
| 2243 | "Disbale Unidirectional Utilised Bandwidth on this interface\n") |
| 2244 | { |
| 2245 | struct interface *ifp = (struct interface *) vty->index; |
| 2246 | |
| 2247 | /* Unset Utilised Bandwidth */ |
| 2248 | link_param_cmd_unset(ifp, LP_USE_BW); |
| 2249 | |
| 2250 | return CMD_SUCCESS; |
| 2251 | } |
| 2252 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2253 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 2254 | ip_address_install (struct vty *vty, struct interface *ifp, |
| 2255 | const char *addr_str, const char *peer_str, |
| 2256 | const char *label) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2257 | { |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 2258 | struct zebra_if *if_data; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2259 | struct prefix_ipv4 cp; |
| 2260 | struct connected *ifc; |
| 2261 | struct prefix_ipv4 *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2262 | int ret; |
| 2263 | |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 2264 | if_data = ifp->info; |
| 2265 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2266 | ret = str2prefix_ipv4 (addr_str, &cp); |
| 2267 | if (ret <= 0) |
| 2268 | { |
| 2269 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); |
| 2270 | return CMD_WARNING; |
| 2271 | } |
| 2272 | |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 2273 | ifc = connected_check (ifp, (struct prefix *) &cp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2274 | if (! ifc) |
| 2275 | { |
| 2276 | ifc = connected_new (); |
| 2277 | ifc->ifp = ifp; |
| 2278 | |
| 2279 | /* Address. */ |
| 2280 | p = prefix_ipv4_new (); |
| 2281 | *p = cp; |
| 2282 | ifc->address = (struct prefix *) p; |
| 2283 | |
| 2284 | /* Broadcast. */ |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 2285 | if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2286 | { |
| 2287 | p = prefix_ipv4_new (); |
| 2288 | *p = cp; |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 2289 | p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2290 | ifc->destination = (struct prefix *) p; |
| 2291 | } |
| 2292 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2293 | /* Label. */ |
| 2294 | if (label) |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 2295 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2296 | |
| 2297 | /* Add to linked list. */ |
| 2298 | listnode_add (ifp->connected, ifc); |
| 2299 | } |
| 2300 | |
| 2301 | /* This address is configured from zebra. */ |
| 2302 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 2303 | SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 2304 | |
| 2305 | /* In case of this route need to install kernel. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 2306 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 2307 | && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE) |
| 2308 | && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2309 | { |
| 2310 | /* Some system need to up the interface to set IP address. */ |
| 2311 | if (! if_is_up (ifp)) |
| 2312 | { |
| 2313 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 2314 | if_refresh (ifp); |
| 2315 | } |
| 2316 | |
| 2317 | ret = if_set_prefix (ifp, ifc); |
| 2318 | if (ret < 0) |
| 2319 | { |
| 2320 | vty_out (vty, "%% Can't set interface IP address: %s.%s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2321 | safe_strerror(errno), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2322 | return CMD_WARNING; |
| 2323 | } |
| 2324 | |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 2325 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 2326 | /* The address will be advertised to zebra clients when the notification |
| 2327 | * from the kernel has been received. |
| 2328 | * It will also be added to the subnet chain list, then. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | return CMD_SUCCESS; |
| 2332 | } |
| 2333 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2334 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 2335 | ip_address_uninstall (struct vty *vty, struct interface *ifp, |
| 2336 | const char *addr_str, const char *peer_str, |
| 2337 | const char *label) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2338 | { |
| 2339 | struct prefix_ipv4 cp; |
| 2340 | struct connected *ifc; |
| 2341 | int ret; |
| 2342 | |
| 2343 | /* Convert to prefix structure. */ |
| 2344 | ret = str2prefix_ipv4 (addr_str, &cp); |
| 2345 | if (ret <= 0) |
| 2346 | { |
| 2347 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); |
| 2348 | return CMD_WARNING; |
| 2349 | } |
| 2350 | |
| 2351 | /* Check current interface address. */ |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 2352 | ifc = connected_check (ifp, (struct prefix *) &cp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2353 | if (! ifc) |
| 2354 | { |
| 2355 | vty_out (vty, "%% Can't find address%s", VTY_NEWLINE); |
| 2356 | return CMD_WARNING; |
| 2357 | } |
| 2358 | |
| 2359 | /* This is not configured address. */ |
| 2360 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 2361 | return CMD_WARNING; |
| 2362 | |
Paul Jakma | 74ecdc9 | 2006-06-15 18:10:47 +0000 | [diff] [blame] | 2363 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 2364 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2365 | /* This is not real address or interface is not active. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 2366 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2367 | || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 2368 | { |
| 2369 | listnode_delete (ifp->connected, ifc); |
| 2370 | connected_free (ifc); |
| 2371 | return CMD_WARNING; |
| 2372 | } |
| 2373 | |
| 2374 | /* This is real route. */ |
| 2375 | ret = if_unset_prefix (ifp, ifc); |
| 2376 | if (ret < 0) |
| 2377 | { |
| 2378 | vty_out (vty, "%% Can't unset interface IP address: %s.%s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2379 | safe_strerror(errno), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2380 | return CMD_WARNING; |
| 2381 | } |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 2382 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 2383 | /* we will receive a kernel notification about this route being removed. |
| 2384 | * this will trigger its removal from the connected list. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2385 | return CMD_SUCCESS; |
| 2386 | } |
| 2387 | |
| 2388 | DEFUN (ip_address, |
| 2389 | ip_address_cmd, |
| 2390 | "ip address A.B.C.D/M", |
| 2391 | "Interface Internet Protocol config commands\n" |
| 2392 | "Set the IP address of an interface\n" |
| 2393 | "IP address (e.g. 10.0.0.1/8)\n") |
| 2394 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 2395 | return ip_address_install (vty, vty->index, argv[0], NULL, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | DEFUN (no_ip_address, |
| 2399 | no_ip_address_cmd, |
| 2400 | "no ip address A.B.C.D/M", |
| 2401 | NO_STR |
| 2402 | "Interface Internet Protocol config commands\n" |
| 2403 | "Set the IP address of an interface\n" |
| 2404 | "IP Address (e.g. 10.0.0.1/8)") |
| 2405 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 2406 | return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | #ifdef HAVE_NETLINK |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2410 | DEFUN (ip_address_label, |
| 2411 | ip_address_label_cmd, |
| 2412 | "ip address A.B.C.D/M label LINE", |
| 2413 | "Interface Internet Protocol config commands\n" |
| 2414 | "Set the IP address of an interface\n" |
| 2415 | "IP address (e.g. 10.0.0.1/8)\n" |
| 2416 | "Label of this address\n" |
| 2417 | "Label\n") |
| 2418 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 2419 | return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | DEFUN (no_ip_address_label, |
| 2423 | no_ip_address_label_cmd, |
| 2424 | "no ip address A.B.C.D/M label LINE", |
| 2425 | NO_STR |
| 2426 | "Interface Internet Protocol config commands\n" |
| 2427 | "Set the IP address of an interface\n" |
| 2428 | "IP address (e.g. 10.0.0.1/8)\n" |
| 2429 | "Label of this address\n" |
| 2430 | "Label\n") |
| 2431 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 2432 | return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2433 | } |
| 2434 | #endif /* HAVE_NETLINK */ |
| 2435 | |
| 2436 | #ifdef HAVE_IPV6 |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2437 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 2438 | ipv6_address_install (struct vty *vty, struct interface *ifp, |
| 2439 | const char *addr_str, const char *peer_str, |
| 2440 | const char *label, int secondary) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2441 | { |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 2442 | struct zebra_if *if_data; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2443 | struct prefix_ipv6 cp; |
| 2444 | struct connected *ifc; |
| 2445 | struct prefix_ipv6 *p; |
| 2446 | int ret; |
| 2447 | |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 2448 | if_data = ifp->info; |
| 2449 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2450 | ret = str2prefix_ipv6 (addr_str, &cp); |
| 2451 | if (ret <= 0) |
| 2452 | { |
| 2453 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); |
| 2454 | return CMD_WARNING; |
| 2455 | } |
| 2456 | |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 2457 | ifc = connected_check (ifp, (struct prefix *) &cp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2458 | if (! ifc) |
| 2459 | { |
| 2460 | ifc = connected_new (); |
| 2461 | ifc->ifp = ifp; |
| 2462 | |
| 2463 | /* Address. */ |
| 2464 | p = prefix_ipv6_new (); |
| 2465 | *p = cp; |
| 2466 | ifc->address = (struct prefix *) p; |
| 2467 | |
| 2468 | /* Secondary. */ |
| 2469 | if (secondary) |
| 2470 | SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); |
| 2471 | |
| 2472 | /* Label. */ |
| 2473 | if (label) |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 2474 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2475 | |
| 2476 | /* Add to linked list. */ |
| 2477 | listnode_add (ifp->connected, ifc); |
| 2478 | } |
| 2479 | |
| 2480 | /* This address is configured from zebra. */ |
| 2481 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 2482 | SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 2483 | |
| 2484 | /* In case of this route need to install kernel. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 2485 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 2486 | && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE) |
| 2487 | && !(if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2488 | { |
| 2489 | /* Some system need to up the interface to set IP address. */ |
| 2490 | if (! if_is_up (ifp)) |
| 2491 | { |
| 2492 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 2493 | if_refresh (ifp); |
| 2494 | } |
| 2495 | |
| 2496 | ret = if_prefix_add_ipv6 (ifp, ifc); |
| 2497 | |
| 2498 | if (ret < 0) |
| 2499 | { |
| 2500 | vty_out (vty, "%% Can't set interface IP address: %s.%s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2501 | safe_strerror(errno), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2502 | return CMD_WARNING; |
| 2503 | } |
| 2504 | |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 2505 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 2506 | /* The address will be advertised to zebra clients when the notification |
| 2507 | * from the kernel has been received. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | return CMD_SUCCESS; |
| 2511 | } |
| 2512 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2513 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 2514 | ipv6_address_uninstall (struct vty *vty, struct interface *ifp, |
| 2515 | const char *addr_str, const char *peer_str, |
| 2516 | const char *label, int secondry) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2517 | { |
| 2518 | struct prefix_ipv6 cp; |
| 2519 | struct connected *ifc; |
| 2520 | int ret; |
| 2521 | |
| 2522 | /* Convert to prefix structure. */ |
| 2523 | ret = str2prefix_ipv6 (addr_str, &cp); |
| 2524 | if (ret <= 0) |
| 2525 | { |
| 2526 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); |
| 2527 | return CMD_WARNING; |
| 2528 | } |
| 2529 | |
| 2530 | /* Check current interface address. */ |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 2531 | ifc = connected_check (ifp, (struct prefix *) &cp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2532 | if (! ifc) |
| 2533 | { |
| 2534 | vty_out (vty, "%% Can't find address%s", VTY_NEWLINE); |
| 2535 | return CMD_WARNING; |
| 2536 | } |
| 2537 | |
| 2538 | /* This is not configured address. */ |
| 2539 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 2540 | return CMD_WARNING; |
| 2541 | |
Christian Franke | 676e1a0 | 2013-01-24 14:04:45 +0000 | [diff] [blame] | 2542 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 2543 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2544 | /* This is not real address or interface is not active. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 2545 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2546 | || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 2547 | { |
| 2548 | listnode_delete (ifp->connected, ifc); |
| 2549 | connected_free (ifc); |
| 2550 | return CMD_WARNING; |
| 2551 | } |
| 2552 | |
| 2553 | /* This is real route. */ |
| 2554 | ret = if_prefix_delete_ipv6 (ifp, ifc); |
| 2555 | if (ret < 0) |
| 2556 | { |
| 2557 | vty_out (vty, "%% Can't unset interface IP address: %s.%s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 2558 | safe_strerror(errno), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2559 | return CMD_WARNING; |
| 2560 | } |
| 2561 | |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame] | 2562 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
Christian Franke | 02b4805 | 2013-01-24 14:04:49 +0000 | [diff] [blame] | 2563 | /* This information will be propagated to the zclients when the |
| 2564 | * kernel notification is received. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2565 | return CMD_SUCCESS; |
| 2566 | } |
| 2567 | |
| 2568 | DEFUN (ipv6_address, |
| 2569 | ipv6_address_cmd, |
| 2570 | "ipv6 address X:X::X:X/M", |
hasso | e23949c | 2004-03-11 15:54:02 +0000 | [diff] [blame] | 2571 | "Interface IPv6 config commands\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2572 | "Set the IP address of an interface\n" |
| 2573 | "IPv6 address (e.g. 3ffe:506::1/48)\n") |
| 2574 | { |
| 2575 | return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0); |
| 2576 | } |
| 2577 | |
| 2578 | DEFUN (no_ipv6_address, |
| 2579 | no_ipv6_address_cmd, |
| 2580 | "no ipv6 address X:X::X:X/M", |
| 2581 | NO_STR |
hasso | e23949c | 2004-03-11 15:54:02 +0000 | [diff] [blame] | 2582 | "Interface IPv6 config commands\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2583 | "Set the IP address of an interface\n" |
| 2584 | "IPv6 address (e.g. 3ffe:506::1/48)\n") |
| 2585 | { |
| 2586 | return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0); |
| 2587 | } |
| 2588 | #endif /* HAVE_IPV6 */ |
| 2589 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2590 | static int |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 2591 | link_params_config_write (struct vty *vty, struct interface *ifp) |
| 2592 | { |
Paul Jakma | 3676cb0 | 2016-07-29 13:39:37 +0100 | [diff] [blame] | 2593 | int i; |
| 2594 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 2595 | if ((ifp == NULL) || !HAS_LINK_PARAMS(ifp)) |
| 2596 | return -1; |
| 2597 | |
| 2598 | struct if_link_params *iflp = ifp->link_params; |
| 2599 | |
| 2600 | vty_out (vty, " link-params%s", VTY_NEWLINE); |
| 2601 | vty_out(vty, " enable%s", VTY_NEWLINE); |
| 2602 | if (IS_PARAM_SET(iflp, LP_TE)) |
| 2603 | vty_out(vty, " metric %u%s",iflp->te_metric, VTY_NEWLINE); |
| 2604 | if (IS_PARAM_SET(iflp, LP_MAX_BW)) |
| 2605 | vty_out(vty, " max-bw %g%s", iflp->max_bw, VTY_NEWLINE); |
| 2606 | if (IS_PARAM_SET(iflp, LP_MAX_RSV_BW)) |
| 2607 | vty_out(vty, " max-rsv-bw %g%s", iflp->max_rsv_bw, VTY_NEWLINE); |
| 2608 | if (IS_PARAM_SET(iflp, LP_UNRSV_BW)) |
| 2609 | { |
Paul Jakma | 3676cb0 | 2016-07-29 13:39:37 +0100 | [diff] [blame] | 2610 | for (i = 0; i < 8; i++) |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 2611 | vty_out(vty, " unrsv-bw %d %g%s", |
| 2612 | i, iflp->unrsv_bw[i], VTY_NEWLINE); |
| 2613 | } |
| 2614 | if (IS_PARAM_SET(iflp, LP_ADM_GRP)) |
| 2615 | vty_out(vty, " admin-grp %u%s", iflp->admin_grp, VTY_NEWLINE); |
| 2616 | if (IS_PARAM_SET(iflp, LP_DELAY)) |
| 2617 | { |
| 2618 | vty_out(vty, " delay %u", iflp->av_delay); |
| 2619 | if (IS_PARAM_SET(iflp, LP_MM_DELAY)) |
| 2620 | { |
| 2621 | vty_out(vty, " min %u", iflp->min_delay); |
| 2622 | vty_out(vty, " max %u", iflp->max_delay); |
| 2623 | } |
| 2624 | vty_out(vty, "%s", VTY_NEWLINE); |
| 2625 | } |
| 2626 | if (IS_PARAM_SET(iflp, LP_DELAY_VAR)) |
| 2627 | vty_out(vty, " delay-variation %u%s", iflp->delay_var, VTY_NEWLINE); |
| 2628 | if (IS_PARAM_SET(iflp, LP_PKT_LOSS)) |
| 2629 | vty_out(vty, " packet-loss %g%s", iflp->pkt_loss, VTY_NEWLINE); |
| 2630 | if (IS_PARAM_SET(iflp, LP_AVA_BW)) |
| 2631 | vty_out(vty, " ava-bw %g%s", iflp->ava_bw, VTY_NEWLINE); |
| 2632 | if (IS_PARAM_SET(iflp, LP_RES_BW)) |
| 2633 | vty_out(vty, " res-bw %g%s", iflp->res_bw, VTY_NEWLINE); |
| 2634 | if (IS_PARAM_SET(iflp, LP_USE_BW)) |
| 2635 | vty_out(vty, " use-bw %g%s", iflp->use_bw, VTY_NEWLINE); |
| 2636 | if (IS_PARAM_SET(iflp, LP_RMT_AS)) |
| 2637 | vty_out(vty, " neighbor %s as %u%s", inet_ntoa(iflp->rmt_ip), |
| 2638 | iflp->rmt_as, VTY_NEWLINE); |
| 2639 | return 0; |
| 2640 | } |
| 2641 | |
| 2642 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2643 | if_config_write (struct vty *vty) |
| 2644 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 2645 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2646 | struct interface *ifp; |
Feng Lu | 471ea39 | 2015-05-22 11:40:00 +0200 | [diff] [blame] | 2647 | vrf_iter_t iter; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2648 | |
Feng Lu | 471ea39 | 2015-05-22 11:40:00 +0200 | [diff] [blame] | 2649 | for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
| 2650 | for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2651 | { |
| 2652 | struct zebra_if *if_data; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 2653 | struct listnode *addrnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2654 | struct connected *ifc; |
| 2655 | struct prefix *p; |
| 2656 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2657 | if_data = ifp->info; |
Feng Lu | 471ea39 | 2015-05-22 11:40:00 +0200 | [diff] [blame] | 2658 | |
| 2659 | if (ifp->vrf_id == VRF_DEFAULT) |
| 2660 | vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE); |
| 2661 | else |
| 2662 | vty_out (vty, "interface %s vrf %u%s", ifp->name, ifp->vrf_id, |
| 2663 | VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2664 | |
Christian Franke | bfac8dc | 2013-01-24 14:04:50 +0000 | [diff] [blame] | 2665 | if (if_data) |
| 2666 | { |
| 2667 | if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) |
| 2668 | vty_out (vty, " shutdown%s", VTY_NEWLINE); |
| 2669 | } |
| 2670 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2671 | if (ifp->desc) |
| 2672 | vty_out (vty, " description %s%s", ifp->desc, |
| 2673 | VTY_NEWLINE); |
| 2674 | |
| 2675 | /* Assign bandwidth here to avoid unnecessary interface flap |
| 2676 | while processing config script */ |
| 2677 | if (ifp->bandwidth != 0) |
| 2678 | vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE); |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 2679 | |
| 2680 | switch (if_data->linkdetect) |
| 2681 | { |
| 2682 | case IF_LINKDETECT_ON: |
| 2683 | vty_out(vty, " link-detect%s", VTY_NEWLINE); |
| 2684 | break; |
| 2685 | case IF_LINKDETECT_OFF: |
| 2686 | vty_out(vty, " no link-detect%s", VTY_NEWLINE); |
| 2687 | break; |
| 2688 | default: break; |
| 2689 | } |
| 2690 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 2691 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2692 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2693 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 2694 | { |
Stephen Hemminger | 81cce01 | 2009-04-28 14:28:00 -0700 | [diff] [blame] | 2695 | char buf[INET6_ADDRSTRLEN]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2696 | p = ifc->address; |
Timo Teräs | be6335d | 2015-05-23 11:08:41 +0300 | [diff] [blame] | 2697 | vty_out (vty, " ip%s address %s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2698 | p->family == AF_INET ? "" : "v6", |
Timo Teräs | be6335d | 2015-05-23 11:08:41 +0300 | [diff] [blame] | 2699 | prefix2str (p, buf, sizeof(buf))); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2700 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2701 | if (ifc->label) |
| 2702 | vty_out (vty, " label %s", ifc->label); |
| 2703 | |
| 2704 | vty_out (vty, "%s", VTY_NEWLINE); |
| 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | if (if_data) |
| 2709 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2710 | if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC) |
| 2711 | vty_out (vty, " %smulticast%s", |
| 2712 | if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ", |
| 2713 | VTY_NEWLINE); |
| 2714 | } |
| 2715 | |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 2716 | #if defined (HAVE_RTADV) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2717 | rtadv_config_write (vty, ifp); |
Donald Sharp | 6425773 | 2015-11-20 08:33:30 -0500 | [diff] [blame] | 2718 | #endif /* HAVE_RTADV */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2719 | |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 2720 | #ifdef HAVE_IRDP |
| 2721 | irdp_config_write (vty, ifp); |
| 2722 | #endif /* IRDP */ |
| 2723 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 2724 | link_params_config_write (vty, ifp); |
| 2725 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2726 | vty_out (vty, "!%s", VTY_NEWLINE); |
| 2727 | } |
| 2728 | return 0; |
| 2729 | } |
| 2730 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 2731 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2732 | /* Allocate and initialize interface vector. */ |
| 2733 | void |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 2734 | zebra_if_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2735 | { |
| 2736 | /* Initialize interface and new hook. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2737 | if_add_hook (IF_NEW_HOOK, if_zebra_new_hook); |
| 2738 | if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook); |
| 2739 | |
| 2740 | /* Install configuration write function. */ |
| 2741 | install_node (&interface_node, if_config_write); |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 2742 | |
| 2743 | install_node (&zebra_if_defaults_node, config_write_zebra_if_defaults); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2744 | |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 2745 | install_node (&link_params_node, NULL); |
| 2746 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2747 | install_element (VIEW_NODE, &show_interface_cmd); |
Feng Lu | a285477 | 2015-05-22 11:40:01 +0200 | [diff] [blame] | 2748 | install_element (VIEW_NODE, &show_interface_vrf_cmd); |
| 2749 | install_element (VIEW_NODE, &show_interface_vrf_all_cmd); |
| 2750 | install_element (VIEW_NODE, &show_interface_name_cmd); |
| 2751 | install_element (VIEW_NODE, &show_interface_name_vrf_cmd); |
| 2752 | install_element (VIEW_NODE, &show_interface_name_vrf_all_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2753 | install_element (CONFIG_NODE, &zebra_interface_cmd); |
Feng Lu | 471ea39 | 2015-05-22 11:40:00 +0200 | [diff] [blame] | 2754 | install_element (CONFIG_NODE, &zebra_interface_vrf_cmd); |
paul | bfc1353 | 2003-05-24 06:40:04 +0000 | [diff] [blame] | 2755 | install_element (CONFIG_NODE, &no_interface_cmd); |
Feng Lu | 471ea39 | 2015-05-22 11:40:00 +0200 | [diff] [blame] | 2756 | install_element (CONFIG_NODE, &no_interface_vrf_cmd); |
Paul Jakma | 8f4269d | 2015-09-18 11:50:33 +0100 | [diff] [blame] | 2757 | install_element (CONFIG_NODE, &default_linkdetect_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2758 | install_default (INTERFACE_NODE); |
| 2759 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
| 2760 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
| 2761 | install_element (INTERFACE_NODE, &multicast_cmd); |
| 2762 | install_element (INTERFACE_NODE, &no_multicast_cmd); |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 2763 | install_element (INTERFACE_NODE, &linkdetect_cmd); |
| 2764 | install_element (INTERFACE_NODE, &no_linkdetect_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2765 | install_element (INTERFACE_NODE, &shutdown_if_cmd); |
| 2766 | install_element (INTERFACE_NODE, &no_shutdown_if_cmd); |
| 2767 | install_element (INTERFACE_NODE, &bandwidth_if_cmd); |
| 2768 | install_element (INTERFACE_NODE, &no_bandwidth_if_cmd); |
| 2769 | install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd); |
| 2770 | install_element (INTERFACE_NODE, &ip_address_cmd); |
| 2771 | install_element (INTERFACE_NODE, &no_ip_address_cmd); |
| 2772 | #ifdef HAVE_IPV6 |
| 2773 | install_element (INTERFACE_NODE, &ipv6_address_cmd); |
| 2774 | install_element (INTERFACE_NODE, &no_ipv6_address_cmd); |
| 2775 | #endif /* HAVE_IPV6 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2776 | #ifdef HAVE_NETLINK |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2777 | install_element (INTERFACE_NODE, &ip_address_label_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2778 | install_element (INTERFACE_NODE, &no_ip_address_label_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2779 | #endif /* HAVE_NETLINK */ |
Olivier Dugeon | 15773a8 | 2016-04-19 18:29:55 +0200 | [diff] [blame] | 2780 | install_element(INTERFACE_NODE, &link_params_cmd); |
| 2781 | install_default(LINK_PARAMS_NODE); |
| 2782 | install_element(LINK_PARAMS_NODE, &link_params_enable_cmd); |
| 2783 | install_element(LINK_PARAMS_NODE, &no_link_params_enable_cmd); |
| 2784 | install_element(LINK_PARAMS_NODE, &link_params_metric_cmd); |
| 2785 | install_element(LINK_PARAMS_NODE, &link_params_maxbw_cmd); |
| 2786 | install_element(LINK_PARAMS_NODE, &link_params_max_rsv_bw_cmd); |
| 2787 | install_element(LINK_PARAMS_NODE, &link_params_unrsv_bw_cmd); |
| 2788 | install_element(LINK_PARAMS_NODE, &link_params_admin_grp_cmd); |
| 2789 | install_element(LINK_PARAMS_NODE, &link_params_inter_as_cmd); |
| 2790 | install_element(LINK_PARAMS_NODE, &no_link_params_inter_as_cmd); |
| 2791 | install_element(LINK_PARAMS_NODE, &link_params_delay_cmd); |
| 2792 | install_element(LINK_PARAMS_NODE, &link_params_delay_mm_cmd); |
| 2793 | install_element(LINK_PARAMS_NODE, &link_params_delay_var_cmd); |
| 2794 | install_element(LINK_PARAMS_NODE, &link_params_pkt_loss_cmd); |
| 2795 | install_element(LINK_PARAMS_NODE, &link_params_ava_bw_cmd); |
| 2796 | install_element(LINK_PARAMS_NODE, &link_params_res_bw_cmd); |
| 2797 | install_element(LINK_PARAMS_NODE, &link_params_use_bw_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 2798 | } |