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" |
| 35 | |
| 36 | #include "zebra/interface.h" |
| 37 | #include "zebra/rtadv.h" |
| 38 | #include "zebra/rib.h" |
| 39 | #include "zebra/zserv.h" |
| 40 | #include "zebra/redistribute.h" |
| 41 | #include "zebra/debug.h" |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 42 | #include "zebra/irdp.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 43 | |
Chris Caputo | b60668d | 2009-05-03 04:40:57 +0000 | [diff] [blame] | 44 | #ifdef RTADV |
| 45 | /* Order is intentional. Matches RFC4191. This array is also used for |
| 46 | command matching, so only modify with care. */ |
| 47 | const char *rtadv_pref_strs[] = { "medium", "high", "INVALID", "low", 0 }; |
| 48 | #endif /* RTADV */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 49 | |
| 50 | /* Called when new interface is added. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 51 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 52 | if_zebra_new_hook (struct interface *ifp) |
| 53 | { |
| 54 | struct zebra_if *zebra_if; |
| 55 | |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 56 | zebra_if = XCALLOC (MTYPE_TMP, sizeof (struct zebra_if)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | |
| 58 | zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC; |
| 59 | zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_UNSPEC; |
| 60 | |
| 61 | #ifdef RTADV |
| 62 | { |
| 63 | /* Set default router advertise values. */ |
| 64 | struct rtadvconf *rtadv; |
| 65 | |
| 66 | rtadv = &zebra_if->rtadv; |
| 67 | |
| 68 | rtadv->AdvSendAdvertisements = 0; |
| 69 | rtadv->MaxRtrAdvInterval = RTADV_MAX_RTR_ADV_INTERVAL; |
| 70 | rtadv->MinRtrAdvInterval = RTADV_MIN_RTR_ADV_INTERVAL; |
| 71 | rtadv->AdvIntervalTimer = 0; |
| 72 | rtadv->AdvManagedFlag = 0; |
| 73 | rtadv->AdvOtherConfigFlag = 0; |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 74 | rtadv->AdvHomeAgentFlag = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 75 | rtadv->AdvLinkMTU = 0; |
| 76 | rtadv->AdvReachableTime = 0; |
| 77 | rtadv->AdvRetransTimer = 0; |
| 78 | rtadv->AdvCurHopLimit = 0; |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 79 | rtadv->AdvDefaultLifetime = -1; /* derive from MaxRtrAdvInterval */ |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 80 | rtadv->HomeAgentPreference = 0; |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 81 | rtadv->HomeAgentLifetime = -1; /* derive from AdvDefaultLifetime */ |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 82 | rtadv->AdvIntervalOption = 0; |
Chris Caputo | b60668d | 2009-05-03 04:40:57 +0000 | [diff] [blame] | 83 | rtadv->DefaultPreference = RTADV_PREF_MEDIUM; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 84 | |
| 85 | rtadv->AdvPrefixList = list_new (); |
| 86 | } |
| 87 | #endif /* RTADV */ |
| 88 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 89 | /* Initialize installed address chains tree. */ |
| 90 | zebra_if->ipv4_subnets = route_table_init (); |
| 91 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 92 | ifp->info = zebra_if; |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | /* Called when interface is deleted. */ |
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_delete_hook (struct interface *ifp) |
| 99 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 100 | struct zebra_if *zebra_if; |
| 101 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 102 | if (ifp->info) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 103 | { |
| 104 | zebra_if = ifp->info; |
| 105 | |
| 106 | /* Free installed address chains tree. */ |
| 107 | if (zebra_if->ipv4_subnets) |
| 108 | route_table_finish (zebra_if->ipv4_subnets); |
| 109 | |
| 110 | XFREE (MTYPE_TMP, zebra_if); |
| 111 | } |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | /* Tie an interface address to its derived subnet list of addresses. */ |
| 117 | int |
| 118 | if_subnet_add (struct interface *ifp, struct connected *ifc) |
| 119 | { |
| 120 | struct route_node *rn; |
| 121 | struct zebra_if *zebra_if; |
| 122 | struct prefix cp; |
| 123 | struct list *addr_list; |
| 124 | |
| 125 | assert (ifp && ifp->info && ifc); |
| 126 | zebra_if = ifp->info; |
| 127 | |
| 128 | /* Get address derived subnet node and associated address list, while marking |
| 129 | address secondary attribute appropriately. */ |
| 130 | cp = *ifc->address; |
| 131 | apply_mask (&cp); |
| 132 | rn = route_node_get (zebra_if->ipv4_subnets, &cp); |
| 133 | |
| 134 | if ((addr_list = rn->info)) |
| 135 | SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); |
| 136 | else |
| 137 | { |
| 138 | UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); |
| 139 | rn->info = addr_list = list_new (); |
| 140 | route_lock_node (rn); |
| 141 | } |
| 142 | |
| 143 | /* Tie address at the tail of address list. */ |
| 144 | listnode_add (addr_list, ifc); |
| 145 | |
| 146 | /* Return list element count. */ |
| 147 | return (addr_list->count); |
| 148 | } |
| 149 | |
| 150 | /* Untie an interface address from its derived subnet list of addresses. */ |
| 151 | int |
| 152 | if_subnet_delete (struct interface *ifp, struct connected *ifc) |
| 153 | { |
| 154 | struct route_node *rn; |
| 155 | struct zebra_if *zebra_if; |
| 156 | struct list *addr_list; |
| 157 | |
| 158 | assert (ifp && ifp->info && ifc); |
| 159 | zebra_if = ifp->info; |
| 160 | |
| 161 | /* Get address derived subnet node. */ |
| 162 | rn = route_node_lookup (zebra_if->ipv4_subnets, ifc->address); |
| 163 | if (! (rn && rn->info)) |
Christian Franke | 9db047f | 2013-01-24 14:04:44 +0000 | [diff] [blame] | 164 | { |
| 165 | zlog_warn("Trying to remove an address from an unknown subnet." |
| 166 | " (please report this bug)"); |
| 167 | return -1; |
| 168 | } |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 169 | route_unlock_node (rn); |
| 170 | |
| 171 | /* Untie address from subnet's address list. */ |
| 172 | addr_list = rn->info; |
Christian Franke | 9db047f | 2013-01-24 14:04:44 +0000 | [diff] [blame] | 173 | |
| 174 | /* Deleting an address that is not registered is a bug. |
| 175 | * In any case, we shouldn't decrement the lock counter if the address |
| 176 | * is unknown. */ |
| 177 | if (!listnode_lookup(addr_list, ifc)) |
| 178 | { |
| 179 | zlog_warn("Trying to remove an address from a subnet where it is not" |
| 180 | " currently registered. (please report this bug)"); |
| 181 | return -1; |
| 182 | } |
| 183 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 184 | listnode_delete (addr_list, ifc); |
| 185 | route_unlock_node (rn); |
| 186 | |
| 187 | /* Return list element count, if not empty. */ |
| 188 | if (addr_list->count) |
| 189 | { |
| 190 | /* If deleted address is primary, mark subsequent one as such and distribute. */ |
| 191 | if (! CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY)) |
| 192 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 193 | ifc = listgetdata (listhead (addr_list)); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 194 | zebra_interface_address_delete_update (ifp, ifc); |
| 195 | UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); |
| 196 | zebra_interface_address_add_update (ifp, ifc); |
| 197 | } |
| 198 | |
| 199 | return addr_list->count; |
| 200 | } |
| 201 | |
| 202 | /* Otherwise, free list and route node. */ |
| 203 | list_free (addr_list); |
| 204 | rn->info = NULL; |
| 205 | route_unlock_node (rn); |
| 206 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 210 | /* if_flags_mangle: A place for hacks that require mangling |
| 211 | * or tweaking the interface flags. |
| 212 | * |
| 213 | * ******************** Solaris flags hacks ************************** |
| 214 | * |
| 215 | * Solaris IFF_UP flag reflects only the primary interface as the |
| 216 | * routing socket only sends IFINFO for the primary interface. Hence |
| 217 | * ~IFF_UP does not per se imply all the logical interfaces are also |
| 218 | * down - which we only know of as addresses. Instead we must determine |
| 219 | * whether the interface really is up or not according to how many |
| 220 | * addresses are still attached. (Solaris always sends RTM_DELADDR if |
| 221 | * an interface, logical or not, goes ~IFF_UP). |
| 222 | * |
| 223 | * Ie, we mangle IFF_UP to *additionally* reflect whether or not there |
| 224 | * are addresses left in struct connected, not just the actual underlying |
| 225 | * IFF_UP flag. |
| 226 | * |
| 227 | * We must hence remember the real state of IFF_UP, which we do in |
| 228 | * struct zebra_if.primary_state. |
| 229 | * |
| 230 | * Setting IFF_UP within zebra to administratively shutdown the |
| 231 | * interface will affect only the primary interface/address on Solaris. |
| 232 | ************************End Solaris flags hacks *********************** |
| 233 | */ |
Paul Jakma | f63f06d | 2011-04-08 12:44:43 +0100 | [diff] [blame] | 234 | static void |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 235 | if_flags_mangle (struct interface *ifp, uint64_t *newflags) |
| 236 | { |
| 237 | #ifdef SUNOS_5 |
| 238 | struct zebra_if *zif = ifp->info; |
| 239 | |
| 240 | zif->primary_state = *newflags & (IFF_UP & 0xff); |
| 241 | |
| 242 | if (CHECK_FLAG (zif->primary_state, IFF_UP) |
| 243 | || listcount(ifp->connected) > 0) |
| 244 | SET_FLAG (*newflags, IFF_UP); |
| 245 | else |
| 246 | UNSET_FLAG (*newflags, IFF_UP); |
| 247 | #endif /* SUNOS_5 */ |
| 248 | } |
| 249 | |
| 250 | /* Update the flags field of the ifp with the new flag set provided. |
| 251 | * Take whatever actions are required for any changes in flags we care |
| 252 | * about. |
| 253 | * |
| 254 | * newflags should be the raw value, as obtained from the OS. |
| 255 | */ |
| 256 | void |
| 257 | if_flags_update (struct interface *ifp, uint64_t newflags) |
| 258 | { |
| 259 | if_flags_mangle (ifp, &newflags); |
| 260 | |
| 261 | if (if_is_operative (ifp)) |
| 262 | { |
| 263 | /* operative -> inoperative? */ |
| 264 | ifp->flags = newflags; |
| 265 | if (!if_is_operative (ifp)) |
| 266 | if_down (ifp); |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | /* inoperative -> operative? */ |
| 271 | ifp->flags = newflags; |
| 272 | if (if_is_operative (ifp)) |
| 273 | if_up (ifp); |
| 274 | } |
| 275 | } |
| 276 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 277 | /* Wake up configured address if it is not in current kernel |
| 278 | address. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 279 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 280 | if_addr_wakeup (struct interface *ifp) |
| 281 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 282 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 283 | struct connected *ifc; |
| 284 | struct prefix *p; |
| 285 | int ret; |
| 286 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 287 | for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 288 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 289 | p = ifc->address; |
| 290 | |
| 291 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED) |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 292 | && ! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 293 | { |
| 294 | /* Address check. */ |
| 295 | if (p->family == AF_INET) |
| 296 | { |
| 297 | if (! if_is_up (ifp)) |
| 298 | { |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 299 | /* XXX: WTF is it trying to set flags here? |
| 300 | * caller has just gotten a new interface, has been |
| 301 | * handed the flags already. This code has no business |
| 302 | * trying to override administrative status of the interface. |
| 303 | * The only call path to here which doesn't originate from |
| 304 | * kernel event is irdp - what on earth is it trying to do? |
| 305 | * |
| 306 | * further RUNNING is not a settable flag on any system |
| 307 | * I (paulj) am aware of. |
| 308 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 309 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 310 | if_refresh (ifp); |
| 311 | } |
| 312 | |
| 313 | ret = if_set_prefix (ifp, ifc); |
| 314 | if (ret < 0) |
| 315 | { |
| 316 | zlog_warn ("Can't set interface's address: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 317 | safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 318 | continue; |
| 319 | } |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 320 | |
| 321 | /* Add to subnet chain list. */ |
| 322 | if_subnet_add (ifp, ifc); |
| 323 | |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 324 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 325 | SET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
| 326 | |
| 327 | zebra_interface_address_add_update (ifp, ifc); |
| 328 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 329 | if (if_is_operative(ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 330 | connected_up_ipv4 (ifp, ifc); |
| 331 | } |
| 332 | #ifdef HAVE_IPV6 |
| 333 | if (p->family == AF_INET6) |
| 334 | { |
| 335 | if (! if_is_up (ifp)) |
| 336 | { |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 337 | /* XXX: See long comment above */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 338 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 339 | if_refresh (ifp); |
| 340 | } |
| 341 | |
| 342 | ret = if_prefix_add_ipv6 (ifp, ifc); |
| 343 | if (ret < 0) |
| 344 | { |
| 345 | zlog_warn ("Can't set interface's address: %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 346 | safe_strerror(errno)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 347 | continue; |
| 348 | } |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 349 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 350 | SET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
| 351 | |
| 352 | zebra_interface_address_add_update (ifp, ifc); |
| 353 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 354 | if (if_is_operative(ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 355 | connected_up_ipv6 (ifp, ifc); |
| 356 | } |
| 357 | #endif /* HAVE_IPV6 */ |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /* Handle interface addition */ |
| 363 | void |
| 364 | if_add_update (struct interface *ifp) |
| 365 | { |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 366 | struct zebra_if *if_data; |
| 367 | |
| 368 | if_data = ifp->info; |
| 369 | if (if_data->multicast == IF_ZEBRA_MULTICAST_ON) |
| 370 | if_set_flags (ifp, IFF_MULTICAST); |
| 371 | else if (if_data->multicast == IF_ZEBRA_MULTICAST_OFF) |
| 372 | if_unset_flags (ifp, IFF_MULTICAST); |
| 373 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 374 | zebra_interface_add_update (ifp); |
| 375 | |
| 376 | if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 377 | { |
| 378 | SET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); |
| 379 | |
| 380 | if_addr_wakeup (ifp); |
| 381 | |
| 382 | if (IS_ZEBRA_DEBUG_KERNEL) |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 383 | zlog_debug ("interface %s index %d becomes active.", |
| 384 | ifp->name, ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 385 | } |
| 386 | else |
| 387 | { |
| 388 | if (IS_ZEBRA_DEBUG_KERNEL) |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 389 | zlog_debug ("interface %s index %d is added.", ifp->name, ifp->ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
paul | 6eb8827 | 2005-07-29 14:36:00 +0000 | [diff] [blame] | 393 | /* Handle an interface delete event */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 394 | void |
| 395 | if_delete_update (struct interface *ifp) |
| 396 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 397 | struct connected *ifc; |
| 398 | struct prefix *p; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 399 | struct route_node *rn; |
| 400 | struct zebra_if *zebra_if; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 401 | |
| 402 | zebra_if = ifp->info; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 403 | |
| 404 | if (if_is_up(ifp)) |
| 405 | { |
| 406 | zlog_err ("interface %s index %d is still up while being deleted.", |
| 407 | ifp->name, ifp->ifindex); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | /* Mark interface as inactive */ |
| 412 | UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); |
| 413 | |
| 414 | if (IS_ZEBRA_DEBUG_KERNEL) |
ajs | b617800 | 2004-12-07 21:12:56 +0000 | [diff] [blame] | 415 | zlog_debug ("interface %s index %d is now inactive.", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 416 | ifp->name, ifp->ifindex); |
| 417 | |
| 418 | /* Delete connected routes from the kernel. */ |
| 419 | if (ifp->connected) |
| 420 | { |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 421 | struct listnode *node; |
| 422 | struct listnode *last = NULL; |
| 423 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 424 | while ((node = (last ? last->next : listhead (ifp->connected)))) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 425 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 426 | ifc = listgetdata (node); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 427 | p = ifc->address; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 428 | |
Paul Jakma | beb5633 | 2006-05-11 13:28:05 +0000 | [diff] [blame] | 429 | if (p->family == AF_INET |
| 430 | && (rn = route_node_lookup (zebra_if->ipv4_subnets, p))) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 431 | { |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 432 | struct listnode *anode; |
| 433 | struct listnode *next; |
| 434 | struct listnode *first; |
| 435 | struct list *addr_list; |
| 436 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 437 | route_unlock_node (rn); |
| 438 | addr_list = (struct list *) rn->info; |
| 439 | |
| 440 | /* Remove addresses, secondaries first. */ |
| 441 | first = listhead (addr_list); |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 442 | for (anode = first->next; anode || first; anode = next) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 443 | { |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 444 | if (!anode) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 445 | { |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 446 | anode = first; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 447 | first = NULL; |
| 448 | } |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 449 | next = anode->next; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 450 | |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 451 | ifc = listgetdata (anode); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 452 | p = ifc->address; |
| 453 | |
| 454 | connected_down_ipv4 (ifp, ifc); |
| 455 | |
| 456 | zebra_interface_address_delete_update (ifp, ifc); |
| 457 | |
| 458 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 459 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 460 | |
| 461 | /* Remove from subnet chain. */ |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 462 | list_delete_node (addr_list, anode); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 463 | route_unlock_node (rn); |
| 464 | |
| 465 | /* Remove from interface address list (unconditionally). */ |
Paul Jakma | d9a18f1 | 2007-04-10 19:30:20 +0000 | [diff] [blame] | 466 | if (!CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 467 | { |
| 468 | listnode_delete (ifp->connected, ifc); |
| 469 | connected_free (ifc); |
| 470 | } |
| 471 | else |
| 472 | last = node; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /* Free chain list and respective route node. */ |
| 476 | list_delete (addr_list); |
| 477 | rn->info = NULL; |
| 478 | route_unlock_node (rn); |
| 479 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 480 | #ifdef HAVE_IPV6 |
| 481 | else if (p->family == AF_INET6) |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 482 | { |
| 483 | connected_down_ipv6 (ifp, ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 484 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 485 | zebra_interface_address_delete_update (ifp, ifc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 486 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 487 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 488 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 489 | |
| 490 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 491 | last = node; |
| 492 | else |
| 493 | { |
| 494 | listnode_delete (ifp->connected, ifc); |
| 495 | connected_free (ifc); |
| 496 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 497 | } |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 498 | #endif /* HAVE_IPV6 */ |
Roman Hoog Antink | e26873f | 2010-05-05 16:00:50 +0200 | [diff] [blame] | 499 | else |
| 500 | { |
| 501 | last = node; |
| 502 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | zebra_interface_delete_update (ifp); |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 506 | |
| 507 | /* Update ifindex after distributing the delete message. This is in |
| 508 | case any client needs to have the old value of ifindex available |
| 509 | while processing the deletion. Each client daemon is responsible |
| 510 | for setting ifindex to IFINDEX_INTERNAL after processing the |
| 511 | interface deletion message. */ |
| 512 | ifp->ifindex = IFINDEX_INTERNAL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /* Interface is up. */ |
| 516 | void |
| 517 | if_up (struct interface *ifp) |
| 518 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 519 | struct listnode *node; |
| 520 | struct listnode *next; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 521 | struct connected *ifc; |
| 522 | struct prefix *p; |
| 523 | |
| 524 | /* Notify the protocol daemons. */ |
| 525 | zebra_interface_up_update (ifp); |
| 526 | |
| 527 | /* Install connected routes to the kernel. */ |
| 528 | if (ifp->connected) |
| 529 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 530 | for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 532 | p = ifc->address; |
| 533 | |
| 534 | if (p->family == AF_INET) |
| 535 | connected_up_ipv4 (ifp, ifc); |
| 536 | #ifdef HAVE_IPV6 |
| 537 | else if (p->family == AF_INET6) |
| 538 | connected_up_ipv6 (ifp, ifc); |
| 539 | #endif /* HAVE_IPV6 */ |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | /* Examine all static routes. */ |
| 544 | rib_update (); |
| 545 | } |
| 546 | |
| 547 | /* Interface goes down. We have to manage different behavior of based |
| 548 | OS. */ |
| 549 | void |
| 550 | if_down (struct interface *ifp) |
| 551 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 552 | struct listnode *node; |
| 553 | struct listnode *next; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 554 | struct connected *ifc; |
| 555 | struct prefix *p; |
| 556 | |
| 557 | /* Notify to the protocol daemons. */ |
| 558 | zebra_interface_down_update (ifp); |
| 559 | |
| 560 | /* Delete connected routes from the kernel. */ |
| 561 | if (ifp->connected) |
| 562 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 563 | for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 564 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 565 | p = ifc->address; |
| 566 | |
| 567 | if (p->family == AF_INET) |
| 568 | connected_down_ipv4 (ifp, ifc); |
| 569 | #ifdef HAVE_IPV6 |
| 570 | else if (p->family == AF_INET6) |
| 571 | connected_down_ipv6 (ifp, ifc); |
| 572 | #endif /* HAVE_IPV6 */ |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | /* Examine all static routes which direct to the interface. */ |
| 577 | rib_update (); |
| 578 | } |
| 579 | |
| 580 | void |
| 581 | if_refresh (struct interface *ifp) |
| 582 | { |
paul | 5c78b3d | 2006-01-25 04:31:40 +0000 | [diff] [blame] | 583 | if_get_flags (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 584 | } |
| 585 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 586 | /* Output prefix string to vty. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 587 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 588 | prefix_vty_out (struct vty *vty, struct prefix *p) |
| 589 | { |
| 590 | char str[INET6_ADDRSTRLEN]; |
| 591 | |
| 592 | inet_ntop (p->family, &p->u.prefix, str, sizeof (str)); |
| 593 | vty_out (vty, "%s", str); |
| 594 | return strlen (str); |
| 595 | } |
| 596 | |
| 597 | /* Dump if address information to vty. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 598 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 599 | connected_dump_vty (struct vty *vty, struct connected *connected) |
| 600 | { |
| 601 | struct prefix *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 602 | |
| 603 | /* Print interface address. */ |
| 604 | p = connected->address; |
| 605 | vty_out (vty, " %s ", prefix_family_str (p)); |
| 606 | prefix_vty_out (vty, p); |
| 607 | vty_out (vty, "/%d", p->prefixlen); |
| 608 | |
| 609 | /* If there is destination address, print it. */ |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 610 | if (connected->destination) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 611 | { |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 612 | vty_out (vty, (CONNECTED_PEER(connected) ? " peer " : " broadcast ")); |
| 613 | prefix_vty_out (vty, connected->destination); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | if (CHECK_FLAG (connected->flags, ZEBRA_IFA_SECONDARY)) |
| 617 | vty_out (vty, " secondary"); |
| 618 | |
| 619 | if (connected->label) |
| 620 | vty_out (vty, " %s", connected->label); |
| 621 | |
| 622 | vty_out (vty, "%s", VTY_NEWLINE); |
| 623 | } |
| 624 | |
| 625 | #ifdef RTADV |
| 626 | /* Dump interface ND information to vty. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 627 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 628 | nd_dump_vty (struct vty *vty, struct interface *ifp) |
| 629 | { |
| 630 | struct zebra_if *zif; |
| 631 | struct rtadvconf *rtadv; |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 632 | int interval; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 633 | |
| 634 | zif = (struct zebra_if *) ifp->info; |
| 635 | rtadv = &zif->rtadv; |
| 636 | |
| 637 | if (rtadv->AdvSendAdvertisements) |
| 638 | { |
| 639 | vty_out (vty, " ND advertised reachable time is %d milliseconds%s", |
| 640 | rtadv->AdvReachableTime, VTY_NEWLINE); |
| 641 | vty_out (vty, " ND advertised retransmit interval is %d milliseconds%s", |
| 642 | rtadv->AdvRetransTimer, VTY_NEWLINE); |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 643 | interval = rtadv->MaxRtrAdvInterval; |
| 644 | if (interval % 1000) |
| 645 | vty_out (vty, " ND router advertisements are sent every " |
| 646 | "%d milliseconds%s", interval, |
| 647 | VTY_NEWLINE); |
| 648 | else |
| 649 | vty_out (vty, " ND router advertisements are sent every " |
| 650 | "%d seconds%s", interval / 1000, |
| 651 | VTY_NEWLINE); |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 652 | if (rtadv->AdvDefaultLifetime != -1) |
| 653 | vty_out (vty, " ND router advertisements live for %d seconds%s", |
| 654 | rtadv->AdvDefaultLifetime, VTY_NEWLINE); |
| 655 | else |
| 656 | vty_out (vty, " ND router advertisements lifetime tracks ra-interval%s", |
| 657 | VTY_NEWLINE); |
Chris Caputo | b60668d | 2009-05-03 04:40:57 +0000 | [diff] [blame] | 658 | vty_out (vty, " ND router advertisement default router preference is " |
| 659 | "%s%s", rtadv_pref_strs[rtadv->DefaultPreference], |
| 660 | VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 661 | if (rtadv->AdvManagedFlag) |
| 662 | vty_out (vty, " Hosts use DHCP to obtain routable addresses.%s", |
| 663 | VTY_NEWLINE); |
| 664 | else |
| 665 | vty_out (vty, " Hosts use stateless autoconfig for addresses.%s", |
| 666 | VTY_NEWLINE); |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 667 | if (rtadv->AdvHomeAgentFlag) |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 668 | { |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 669 | vty_out (vty, " ND router advertisements with " |
| 670 | "Home Agent flag bit set.%s", |
| 671 | VTY_NEWLINE); |
Denis Ovsienko | d660f69 | 2011-12-30 21:55:49 +0400 | [diff] [blame] | 672 | if (rtadv->HomeAgentLifetime != -1) |
| 673 | vty_out (vty, " Home Agent lifetime is %u seconds%s", |
| 674 | rtadv->HomeAgentLifetime, VTY_NEWLINE); |
| 675 | else |
| 676 | vty_out (vty, " Home Agent lifetime tracks ra-lifetime%s", |
| 677 | VTY_NEWLINE); |
| 678 | vty_out (vty, " Home Agent preference is %u%s", |
| 679 | rtadv->HomeAgentPreference, VTY_NEWLINE); |
| 680 | } |
vincent | 7cee1bb | 2005-03-25 13:08:53 +0000 | [diff] [blame] | 681 | if (rtadv->AdvIntervalOption) |
| 682 | vty_out (vty, " ND router advertisements with Adv. Interval option.%s", |
| 683 | VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | #endif /* RTADV */ |
| 687 | |
| 688 | /* Interface's information print out to vty interface. */ |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 689 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 690 | if_dump_vty (struct vty *vty, struct interface *ifp) |
| 691 | { |
Paul Jakma | 6f0e3f6 | 2007-05-10 02:38:51 +0000 | [diff] [blame] | 692 | #ifdef HAVE_STRUCT_SOCKADDR_DL |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 693 | struct sockaddr_dl *sdl; |
Paul Jakma | 6f0e3f6 | 2007-05-10 02:38:51 +0000 | [diff] [blame] | 694 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 695 | struct connected *connected; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 696 | struct listnode *node; |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 697 | struct route_node *rn; |
| 698 | struct zebra_if *zebra_if; |
| 699 | |
| 700 | zebra_if = ifp->info; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 701 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 702 | vty_out (vty, "Interface %s is ", ifp->name); |
| 703 | if (if_is_up(ifp)) { |
| 704 | vty_out (vty, "up, line protocol "); |
| 705 | |
| 706 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) { |
| 707 | if (if_is_running(ifp)) |
| 708 | vty_out (vty, "is up%s", VTY_NEWLINE); |
| 709 | else |
| 710 | vty_out (vty, "is down%s", VTY_NEWLINE); |
| 711 | } else { |
| 712 | vty_out (vty, "detection is disabled%s", VTY_NEWLINE); |
| 713 | } |
| 714 | } else { |
| 715 | vty_out (vty, "down%s", VTY_NEWLINE); |
| 716 | } |
| 717 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 718 | if (ifp->desc) |
| 719 | vty_out (vty, " Description: %s%s", ifp->desc, |
| 720 | VTY_NEWLINE); |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 721 | if (ifp->ifindex == IFINDEX_INTERNAL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 722 | { |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 723 | vty_out(vty, " pseudo interface%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 724 | return; |
| 725 | } |
| 726 | else if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 727 | { |
| 728 | vty_out(vty, " index %d inactive interface%s", |
| 729 | ifp->ifindex, |
| 730 | VTY_NEWLINE); |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | vty_out (vty, " index %d metric %d mtu %d ", |
| 735 | ifp->ifindex, ifp->metric, ifp->mtu); |
paul | 44145db | 2004-05-09 11:00:23 +0000 | [diff] [blame] | 736 | #ifdef HAVE_IPV6 |
| 737 | if (ifp->mtu6 != ifp->mtu) |
| 738 | vty_out (vty, "mtu6 %d ", ifp->mtu6); |
| 739 | #endif |
Paul Jakma | 630c97c | 2006-06-15 12:48:17 +0000 | [diff] [blame] | 740 | vty_out (vty, "%s flags: %s%s", VTY_NEWLINE, |
| 741 | if_flag_dump (ifp->flags), VTY_NEWLINE); |
paul | 3a570c8 | 2006-02-02 17:27:13 +0000 | [diff] [blame] | 742 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 743 | /* Hardware address. */ |
Paul Jakma | 6f0e3f6 | 2007-05-10 02:38:51 +0000 | [diff] [blame] | 744 | #ifdef HAVE_STRUCT_SOCKADDR_DL |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 745 | sdl = &ifp->sdl; |
| 746 | if (sdl != NULL && sdl->sdl_alen != 0) |
| 747 | { |
| 748 | int i; |
| 749 | u_char *ptr; |
| 750 | |
| 751 | vty_out (vty, " HWaddr: "); |
paul | 5b73a67 | 2004-07-23 15:26:14 +0000 | [diff] [blame] | 752 | for (i = 0, ptr = (u_char *)LLADDR (sdl); i < sdl->sdl_alen; i++, ptr++) |
| 753 | vty_out (vty, "%s%02x", i == 0 ? "" : ":", *ptr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 754 | vty_out (vty, "%s", VTY_NEWLINE); |
| 755 | } |
| 756 | #else |
| 757 | if (ifp->hw_addr_len != 0) |
| 758 | { |
| 759 | int i; |
| 760 | |
| 761 | vty_out (vty, " HWaddr: "); |
| 762 | for (i = 0; i < ifp->hw_addr_len; i++) |
| 763 | vty_out (vty, "%s%02x", i == 0 ? "" : ":", ifp->hw_addr[i]); |
| 764 | vty_out (vty, "%s", VTY_NEWLINE); |
| 765 | } |
Paul Jakma | 6f0e3f6 | 2007-05-10 02:38:51 +0000 | [diff] [blame] | 766 | #endif /* HAVE_STRUCT_SOCKADDR_DL */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 767 | |
| 768 | /* Bandwidth in kbps */ |
| 769 | if (ifp->bandwidth != 0) |
| 770 | { |
| 771 | vty_out(vty, " bandwidth %u kbps", ifp->bandwidth); |
| 772 | vty_out(vty, "%s", VTY_NEWLINE); |
| 773 | } |
| 774 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 775 | for (rn = route_top (zebra_if->ipv4_subnets); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 776 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 777 | if (! rn->info) |
| 778 | continue; |
| 779 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 780 | for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected)) |
| 781 | connected_dump_vty (vty, connected); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 782 | } |
| 783 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 784 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 785 | { |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 786 | if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && |
| 787 | (connected->address->family == AF_INET6)) |
| 788 | connected_dump_vty (vty, connected); |
| 789 | } |
| 790 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 791 | #ifdef RTADV |
| 792 | nd_dump_vty (vty, ifp); |
| 793 | #endif /* RTADV */ |
| 794 | |
| 795 | #ifdef HAVE_PROC_NET_DEV |
| 796 | /* Statistics print out using proc file system. */ |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 797 | vty_out (vty, " %lu input packets (%lu multicast), %lu bytes, " |
| 798 | "%lu dropped%s", |
| 799 | ifp->stats.rx_packets, ifp->stats.rx_multicast, |
| 800 | ifp->stats.rx_bytes, ifp->stats.rx_dropped, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 801 | |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 802 | vty_out (vty, " %lu input errors, %lu length, %lu overrun," |
hasso | 3452d47 | 2005-03-06 13:42:05 +0000 | [diff] [blame] | 803 | " %lu CRC, %lu frame%s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 804 | ifp->stats.rx_errors, ifp->stats.rx_length_errors, |
| 805 | ifp->stats.rx_over_errors, ifp->stats.rx_crc_errors, |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 806 | ifp->stats.rx_frame_errors, VTY_NEWLINE); |
| 807 | |
| 808 | vty_out (vty, " %lu fifo, %lu missed%s", ifp->stats.rx_fifo_errors, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 809 | ifp->stats.rx_missed_errors, VTY_NEWLINE); |
| 810 | |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 811 | vty_out (vty, " %lu output packets, %lu bytes, %lu dropped%s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 812 | ifp->stats.tx_packets, ifp->stats.tx_bytes, |
| 813 | ifp->stats.tx_dropped, VTY_NEWLINE); |
| 814 | |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 815 | vty_out (vty, " %lu output errors, %lu aborted, %lu carrier," |
| 816 | " %lu fifo, %lu heartbeat%s", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 817 | ifp->stats.tx_errors, ifp->stats.tx_aborted_errors, |
| 818 | ifp->stats.tx_carrier_errors, ifp->stats.tx_fifo_errors, |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 819 | ifp->stats.tx_heartbeat_errors, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 820 | |
hasso | 6f2c27a | 2005-01-18 13:44:35 +0000 | [diff] [blame] | 821 | vty_out (vty, " %lu window, %lu collisions%s", |
| 822 | ifp->stats.tx_window_errors, ifp->stats.collisions, VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 823 | #endif /* HAVE_PROC_NET_DEV */ |
| 824 | |
| 825 | #ifdef HAVE_NET_RT_IFLIST |
| 826 | #if defined (__bsdi__) || defined (__NetBSD__) |
| 827 | /* Statistics print out using sysctl (). */ |
| 828 | vty_out (vty, " input packets %qu, bytes %qu, dropped %qu," |
| 829 | " multicast packets %qu%s", |
| 830 | ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, |
| 831 | ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, |
| 832 | VTY_NEWLINE); |
| 833 | |
| 834 | vty_out (vty, " input errors %qu%s", |
| 835 | ifp->stats.ifi_ierrors, VTY_NEWLINE); |
| 836 | |
| 837 | vty_out (vty, " output packets %qu, bytes %qu, multicast packets %qu%s", |
| 838 | ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, |
| 839 | ifp->stats.ifi_omcasts, VTY_NEWLINE); |
| 840 | |
| 841 | vty_out (vty, " output errors %qu%s", |
| 842 | ifp->stats.ifi_oerrors, VTY_NEWLINE); |
| 843 | |
| 844 | vty_out (vty, " collisions %qu%s", |
| 845 | ifp->stats.ifi_collisions, VTY_NEWLINE); |
| 846 | #else |
| 847 | /* Statistics print out using sysctl (). */ |
| 848 | vty_out (vty, " input packets %lu, bytes %lu, dropped %lu," |
| 849 | " multicast packets %lu%s", |
| 850 | ifp->stats.ifi_ipackets, ifp->stats.ifi_ibytes, |
| 851 | ifp->stats.ifi_iqdrops, ifp->stats.ifi_imcasts, |
| 852 | VTY_NEWLINE); |
| 853 | |
| 854 | vty_out (vty, " input errors %lu%s", |
| 855 | ifp->stats.ifi_ierrors, VTY_NEWLINE); |
| 856 | |
| 857 | vty_out (vty, " output packets %lu, bytes %lu, multicast packets %lu%s", |
| 858 | ifp->stats.ifi_opackets, ifp->stats.ifi_obytes, |
| 859 | ifp->stats.ifi_omcasts, VTY_NEWLINE); |
| 860 | |
| 861 | vty_out (vty, " output errors %lu%s", |
| 862 | ifp->stats.ifi_oerrors, VTY_NEWLINE); |
| 863 | |
| 864 | vty_out (vty, " collisions %lu%s", |
| 865 | ifp->stats.ifi_collisions, VTY_NEWLINE); |
| 866 | #endif /* __bsdi__ || __NetBSD__ */ |
| 867 | #endif /* HAVE_NET_RT_IFLIST */ |
| 868 | } |
| 869 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 870 | /* Wrapper hook point for zebra daemon so that ifindex can be set |
| 871 | * DEFUN macro not used as extract.pl HAS to ignore this |
| 872 | * See also interface_cmd in lib/if.c |
| 873 | */ |
| 874 | DEFUN_NOSH (zebra_interface, |
| 875 | zebra_interface_cmd, |
| 876 | "interface IFNAME", |
| 877 | "Select an interface to configure\n" |
| 878 | "Interface's name\n") |
| 879 | { |
| 880 | int ret; |
| 881 | struct interface * ifp; |
| 882 | |
| 883 | /* Call lib interface() */ |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 884 | if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS) |
| 885 | return ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 886 | |
| 887 | ifp = vty->index; |
| 888 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 889 | if (ifp->ifindex == IFINDEX_INTERNAL) |
| 890 | /* Is this really necessary? Shouldn't status be initialized to 0 |
| 891 | in that case? */ |
| 892 | UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 893 | |
| 894 | return ret; |
| 895 | } |
| 896 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 897 | struct cmd_node interface_node = |
| 898 | { |
| 899 | INTERFACE_NODE, |
| 900 | "%s(config-if)# ", |
| 901 | 1 |
| 902 | }; |
| 903 | |
| 904 | /* Show all or specified interface to vty. */ |
| 905 | DEFUN (show_interface, show_interface_cmd, |
| 906 | "show interface [IFNAME]", |
| 907 | SHOW_STR |
| 908 | "Interface status and configuration\n" |
| 909 | "Inteface name\n") |
| 910 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 911 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 912 | struct interface *ifp; |
| 913 | |
| 914 | #ifdef HAVE_PROC_NET_DEV |
| 915 | /* If system has interface statistics via proc file system, update |
| 916 | statistics. */ |
| 917 | ifstat_update_proc (); |
| 918 | #endif /* HAVE_PROC_NET_DEV */ |
| 919 | #ifdef HAVE_NET_RT_IFLIST |
| 920 | ifstat_update_sysctl (); |
| 921 | #endif /* HAVE_NET_RT_IFLIST */ |
| 922 | |
| 923 | /* Specified interface print. */ |
| 924 | if (argc != 0) |
| 925 | { |
| 926 | ifp = if_lookup_by_name (argv[0]); |
| 927 | if (ifp == NULL) |
| 928 | { |
| 929 | vty_out (vty, "%% Can't find interface %s%s", argv[0], |
| 930 | VTY_NEWLINE); |
| 931 | return CMD_WARNING; |
| 932 | } |
| 933 | if_dump_vty (vty, ifp); |
| 934 | return CMD_SUCCESS; |
| 935 | } |
| 936 | |
| 937 | /* All interface print. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 938 | for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) |
| 939 | if_dump_vty (vty, ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 940 | |
| 941 | return CMD_SUCCESS; |
| 942 | } |
| 943 | |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 944 | DEFUN (show_interface_desc, |
| 945 | show_interface_desc_cmd, |
| 946 | "show interface description", |
| 947 | SHOW_STR |
| 948 | "Interface status and configuration\n" |
| 949 | "Interface description\n") |
| 950 | { |
| 951 | struct listnode *node; |
| 952 | struct interface *ifp; |
| 953 | |
| 954 | vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 955 | for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 956 | { |
| 957 | int len; |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 958 | |
| 959 | len = vty_out (vty, "%s", ifp->name); |
| 960 | vty_out (vty, "%*s", (16 - len), " "); |
| 961 | |
| 962 | if (if_is_up(ifp)) |
| 963 | { |
| 964 | vty_out (vty, "up "); |
| 965 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) |
| 966 | { |
| 967 | if (if_is_running(ifp)) |
| 968 | vty_out (vty, "up "); |
| 969 | else |
| 970 | vty_out (vty, "down "); |
| 971 | } |
| 972 | else |
| 973 | { |
| 974 | vty_out (vty, "unknown "); |
| 975 | } |
| 976 | } |
| 977 | else |
| 978 | { |
| 979 | vty_out (vty, "down down "); |
| 980 | } |
| 981 | |
| 982 | if (ifp->desc) |
| 983 | vty_out (vty, "%s", ifp->desc); |
| 984 | vty_out (vty, "%s", VTY_NEWLINE); |
| 985 | } |
| 986 | return CMD_SUCCESS; |
| 987 | } |
| 988 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 989 | DEFUN (multicast, |
| 990 | multicast_cmd, |
| 991 | "multicast", |
| 992 | "Set multicast flag to interface\n") |
| 993 | { |
| 994 | int ret; |
| 995 | struct interface *ifp; |
| 996 | struct zebra_if *if_data; |
| 997 | |
| 998 | ifp = (struct interface *) vty->index; |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 999 | if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1000 | { |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1001 | ret = if_set_flags (ifp, IFF_MULTICAST); |
| 1002 | if (ret < 0) |
| 1003 | { |
| 1004 | vty_out (vty, "Can't set multicast flag%s", VTY_NEWLINE); |
| 1005 | return CMD_WARNING; |
| 1006 | } |
| 1007 | if_refresh (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1008 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1009 | if_data = ifp->info; |
| 1010 | if_data->multicast = IF_ZEBRA_MULTICAST_ON; |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1011 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1012 | return CMD_SUCCESS; |
| 1013 | } |
| 1014 | |
| 1015 | DEFUN (no_multicast, |
| 1016 | no_multicast_cmd, |
| 1017 | "no multicast", |
| 1018 | NO_STR |
| 1019 | "Unset multicast flag to interface\n") |
| 1020 | { |
| 1021 | int ret; |
| 1022 | struct interface *ifp; |
| 1023 | struct zebra_if *if_data; |
| 1024 | |
| 1025 | ifp = (struct interface *) vty->index; |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1026 | if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1027 | { |
paul | 48b33aa | 2002-12-13 20:52:52 +0000 | [diff] [blame] | 1028 | ret = if_unset_flags (ifp, IFF_MULTICAST); |
| 1029 | if (ret < 0) |
| 1030 | { |
| 1031 | vty_out (vty, "Can't unset multicast flag%s", VTY_NEWLINE); |
| 1032 | return CMD_WARNING; |
| 1033 | } |
| 1034 | if_refresh (ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1035 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1036 | if_data = ifp->info; |
| 1037 | if_data->multicast = IF_ZEBRA_MULTICAST_OFF; |
| 1038 | |
| 1039 | return CMD_SUCCESS; |
| 1040 | } |
| 1041 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1042 | DEFUN (linkdetect, |
| 1043 | linkdetect_cmd, |
| 1044 | "link-detect", |
| 1045 | "Enable link detection on interface\n") |
| 1046 | { |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1047 | struct interface *ifp; |
| 1048 | int if_was_operative; |
| 1049 | |
| 1050 | ifp = (struct interface *) vty->index; |
| 1051 | if_was_operative = if_is_operative(ifp); |
| 1052 | SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
| 1053 | |
| 1054 | /* When linkdetection is enabled, if might come down */ |
| 1055 | if (!if_is_operative(ifp) && if_was_operative) if_down(ifp); |
| 1056 | |
| 1057 | /* FIXME: Will defer status change forwarding if interface |
| 1058 | does not come down! */ |
| 1059 | |
| 1060 | return CMD_SUCCESS; |
| 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | DEFUN (no_linkdetect, |
| 1065 | no_linkdetect_cmd, |
| 1066 | "no link-detect", |
| 1067 | NO_STR |
| 1068 | "Disable link detection on interface\n") |
| 1069 | { |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1070 | struct interface *ifp; |
| 1071 | int if_was_operative; |
| 1072 | |
| 1073 | ifp = (struct interface *) vty->index; |
| 1074 | if_was_operative = if_is_operative(ifp); |
| 1075 | UNSET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION); |
| 1076 | |
| 1077 | /* Interface may come up after disabling link detection */ |
| 1078 | if (if_is_operative(ifp) && !if_was_operative) if_up(ifp); |
| 1079 | |
| 1080 | /* FIXME: see linkdetect_cmd */ |
| 1081 | |
| 1082 | return CMD_SUCCESS; |
| 1083 | } |
| 1084 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1085 | DEFUN (shutdown_if, |
| 1086 | shutdown_if_cmd, |
| 1087 | "shutdown", |
| 1088 | "Shutdown the selected interface\n") |
| 1089 | { |
| 1090 | int ret; |
| 1091 | struct interface *ifp; |
| 1092 | struct zebra_if *if_data; |
| 1093 | |
| 1094 | ifp = (struct interface *) vty->index; |
| 1095 | ret = if_unset_flags (ifp, IFF_UP); |
| 1096 | if (ret < 0) |
| 1097 | { |
| 1098 | vty_out (vty, "Can't shutdown interface%s", VTY_NEWLINE); |
| 1099 | return CMD_WARNING; |
| 1100 | } |
| 1101 | if_refresh (ifp); |
| 1102 | if_data = ifp->info; |
| 1103 | if_data->shutdown = IF_ZEBRA_SHUTDOWN_ON; |
| 1104 | |
| 1105 | return CMD_SUCCESS; |
| 1106 | } |
| 1107 | |
| 1108 | DEFUN (no_shutdown_if, |
| 1109 | no_shutdown_if_cmd, |
| 1110 | "no shutdown", |
| 1111 | NO_STR |
| 1112 | "Shutdown the selected interface\n") |
| 1113 | { |
| 1114 | int ret; |
| 1115 | struct interface *ifp; |
| 1116 | struct zebra_if *if_data; |
| 1117 | |
| 1118 | ifp = (struct interface *) vty->index; |
| 1119 | ret = if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 1120 | if (ret < 0) |
| 1121 | { |
| 1122 | vty_out (vty, "Can't up interface%s", VTY_NEWLINE); |
| 1123 | return CMD_WARNING; |
| 1124 | } |
| 1125 | if_refresh (ifp); |
| 1126 | if_data = ifp->info; |
| 1127 | if_data->shutdown = IF_ZEBRA_SHUTDOWN_OFF; |
| 1128 | |
| 1129 | return CMD_SUCCESS; |
| 1130 | } |
| 1131 | |
| 1132 | DEFUN (bandwidth_if, |
| 1133 | bandwidth_if_cmd, |
| 1134 | "bandwidth <1-10000000>", |
| 1135 | "Set bandwidth informational parameter\n" |
| 1136 | "Bandwidth in kilobits\n") |
| 1137 | { |
| 1138 | struct interface *ifp; |
| 1139 | unsigned int bandwidth; |
| 1140 | |
| 1141 | ifp = (struct interface *) vty->index; |
| 1142 | bandwidth = strtol(argv[0], NULL, 10); |
| 1143 | |
| 1144 | /* bandwidth range is <1-10000000> */ |
| 1145 | if (bandwidth < 1 || bandwidth > 10000000) |
| 1146 | { |
| 1147 | vty_out (vty, "Bandwidth is invalid%s", VTY_NEWLINE); |
| 1148 | return CMD_WARNING; |
| 1149 | } |
| 1150 | |
| 1151 | ifp->bandwidth = bandwidth; |
| 1152 | |
| 1153 | /* force protocols to recalculate routes due to cost change */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1154 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1155 | zebra_interface_up_update (ifp); |
| 1156 | |
| 1157 | return CMD_SUCCESS; |
| 1158 | } |
| 1159 | |
| 1160 | DEFUN (no_bandwidth_if, |
| 1161 | no_bandwidth_if_cmd, |
| 1162 | "no bandwidth", |
| 1163 | NO_STR |
| 1164 | "Set bandwidth informational parameter\n") |
| 1165 | { |
| 1166 | struct interface *ifp; |
| 1167 | |
| 1168 | ifp = (struct interface *) vty->index; |
| 1169 | |
| 1170 | ifp->bandwidth = 0; |
| 1171 | |
| 1172 | /* force protocols to recalculate routes due to cost change */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1173 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1174 | zebra_interface_up_update (ifp); |
| 1175 | |
| 1176 | return CMD_SUCCESS; |
| 1177 | } |
| 1178 | |
| 1179 | ALIAS (no_bandwidth_if, |
| 1180 | no_bandwidth_if_val_cmd, |
| 1181 | "no bandwidth <1-10000000>", |
| 1182 | NO_STR |
| 1183 | "Set bandwidth informational parameter\n" |
| 1184 | "Bandwidth in kilobits\n") |
| 1185 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1186 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 1187 | ip_address_install (struct vty *vty, struct interface *ifp, |
| 1188 | const char *addr_str, const char *peer_str, |
| 1189 | const char *label) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1190 | { |
| 1191 | struct prefix_ipv4 cp; |
| 1192 | struct connected *ifc; |
| 1193 | struct prefix_ipv4 *p; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1194 | int ret; |
| 1195 | |
| 1196 | ret = str2prefix_ipv4 (addr_str, &cp); |
| 1197 | if (ret <= 0) |
| 1198 | { |
| 1199 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); |
| 1200 | return CMD_WARNING; |
| 1201 | } |
| 1202 | |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 1203 | ifc = connected_check (ifp, (struct prefix *) &cp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1204 | if (! ifc) |
| 1205 | { |
| 1206 | ifc = connected_new (); |
| 1207 | ifc->ifp = ifp; |
| 1208 | |
| 1209 | /* Address. */ |
| 1210 | p = prefix_ipv4_new (); |
| 1211 | *p = cp; |
| 1212 | ifc->address = (struct prefix *) p; |
| 1213 | |
| 1214 | /* Broadcast. */ |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 1215 | if (p->prefixlen <= IPV4_MAX_PREFIXLEN-2) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1216 | { |
| 1217 | p = prefix_ipv4_new (); |
| 1218 | *p = cp; |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 1219 | p->prefix.s_addr = ipv4_broadcast_addr(p->prefix.s_addr,p->prefixlen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1220 | ifc->destination = (struct prefix *) p; |
| 1221 | } |
| 1222 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1223 | /* Label. */ |
| 1224 | if (label) |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 1225 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1226 | |
| 1227 | /* Add to linked list. */ |
| 1228 | listnode_add (ifp->connected, ifc); |
| 1229 | } |
| 1230 | |
| 1231 | /* This address is configured from zebra. */ |
| 1232 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 1233 | SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 1234 | |
| 1235 | /* In case of this route need to install kernel. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 1236 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1237 | && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 1238 | { |
| 1239 | /* Some system need to up the interface to set IP address. */ |
| 1240 | if (! if_is_up (ifp)) |
| 1241 | { |
| 1242 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 1243 | if_refresh (ifp); |
| 1244 | } |
| 1245 | |
| 1246 | ret = if_set_prefix (ifp, ifc); |
| 1247 | if (ret < 0) |
| 1248 | { |
| 1249 | vty_out (vty, "%% Can't set interface IP address: %s.%s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1250 | safe_strerror(errno), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1251 | return CMD_WARNING; |
| 1252 | } |
| 1253 | |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 1254 | /* Add to subnet chain list (while marking secondary attribute). */ |
| 1255 | if_subnet_add (ifp, ifc); |
| 1256 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1257 | /* IP address propery set. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 1258 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1259 | SET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
| 1260 | |
| 1261 | /* Update interface address information to protocol daemon. */ |
| 1262 | zebra_interface_address_add_update (ifp, ifc); |
| 1263 | |
| 1264 | /* If interface is up register connected route. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1265 | if (if_is_operative(ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1266 | connected_up_ipv4 (ifp, ifc); |
| 1267 | } |
| 1268 | |
| 1269 | return CMD_SUCCESS; |
| 1270 | } |
| 1271 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1272 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 1273 | ip_address_uninstall (struct vty *vty, struct interface *ifp, |
| 1274 | const char *addr_str, const char *peer_str, |
| 1275 | const char *label) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1276 | { |
| 1277 | struct prefix_ipv4 cp; |
| 1278 | struct connected *ifc; |
| 1279 | int ret; |
| 1280 | |
| 1281 | /* Convert to prefix structure. */ |
| 1282 | ret = str2prefix_ipv4 (addr_str, &cp); |
| 1283 | if (ret <= 0) |
| 1284 | { |
| 1285 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); |
| 1286 | return CMD_WARNING; |
| 1287 | } |
| 1288 | |
| 1289 | /* Check current interface address. */ |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 1290 | ifc = connected_check (ifp, (struct prefix *) &cp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1291 | if (! ifc) |
| 1292 | { |
| 1293 | vty_out (vty, "%% Can't find address%s", VTY_NEWLINE); |
| 1294 | return CMD_WARNING; |
| 1295 | } |
| 1296 | |
| 1297 | /* This is not configured address. */ |
| 1298 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 1299 | return CMD_WARNING; |
| 1300 | |
Paul Jakma | 74ecdc9 | 2006-06-15 18:10:47 +0000 | [diff] [blame] | 1301 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 1302 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1303 | /* This is not real address or interface is not active. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 1304 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1305 | || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 1306 | { |
| 1307 | listnode_delete (ifp->connected, ifc); |
| 1308 | connected_free (ifc); |
| 1309 | return CMD_WARNING; |
| 1310 | } |
| 1311 | |
| 1312 | /* This is real route. */ |
| 1313 | ret = if_unset_prefix (ifp, ifc); |
| 1314 | if (ret < 0) |
| 1315 | { |
| 1316 | vty_out (vty, "%% Can't unset interface IP address: %s.%s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1317 | safe_strerror(errno), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1318 | return CMD_WARNING; |
| 1319 | } |
David Lamparter | 7f062c2 | 2010-02-01 16:41:26 +0100 | [diff] [blame] | 1320 | /* success! call returned that the address deletion went through. |
| 1321 | * this is a synchronous operation, so we know it succeeded and can |
| 1322 | * now update all internal state. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1323 | |
David Lamparter | 7f062c2 | 2010-02-01 16:41:26 +0100 | [diff] [blame] | 1324 | /* the HAVE_NETLINK check is only here because, on BSD, although the |
| 1325 | * call above is still synchronous, we get a second confirmation later |
| 1326 | * through the route socket, and we don't want to touch that behaviour |
| 1327 | * for now. It should work without the #ifdef, but why take the risk... |
| 1328 | * -- equinox 2012-07-13 */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 1329 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
David Lamparter | 7f062c2 | 2010-02-01 16:41:26 +0100 | [diff] [blame] | 1330 | #ifdef HAVE_NETLINK |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1331 | |
| 1332 | /* Remove connected route. */ |
| 1333 | connected_down_ipv4 (ifp, ifc); |
| 1334 | |
David Lamparter | 7f062c2 | 2010-02-01 16:41:26 +0100 | [diff] [blame] | 1335 | /* Redistribute this information. */ |
| 1336 | zebra_interface_address_delete_update (ifp, ifc); |
| 1337 | |
| 1338 | /* IP address propery set. */ |
| 1339 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
| 1340 | |
| 1341 | /* remove from interface, remark secondaries */ |
| 1342 | if_subnet_delete (ifp, ifc); |
| 1343 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1344 | /* Free address information. */ |
| 1345 | listnode_delete (ifp->connected, ifc); |
| 1346 | connected_free (ifc); |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 1347 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1348 | |
| 1349 | return CMD_SUCCESS; |
| 1350 | } |
| 1351 | |
| 1352 | DEFUN (ip_address, |
| 1353 | ip_address_cmd, |
| 1354 | "ip address A.B.C.D/M", |
| 1355 | "Interface Internet Protocol config commands\n" |
| 1356 | "Set the IP address of an interface\n" |
| 1357 | "IP address (e.g. 10.0.0.1/8)\n") |
| 1358 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 1359 | return ip_address_install (vty, vty->index, argv[0], NULL, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | DEFUN (no_ip_address, |
| 1363 | no_ip_address_cmd, |
| 1364 | "no ip address A.B.C.D/M", |
| 1365 | NO_STR |
| 1366 | "Interface Internet Protocol config commands\n" |
| 1367 | "Set the IP address of an interface\n" |
| 1368 | "IP Address (e.g. 10.0.0.1/8)") |
| 1369 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 1370 | return ip_address_uninstall (vty, vty->index, argv[0], NULL, NULL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | #ifdef HAVE_NETLINK |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1374 | DEFUN (ip_address_label, |
| 1375 | ip_address_label_cmd, |
| 1376 | "ip address A.B.C.D/M label LINE", |
| 1377 | "Interface Internet Protocol config commands\n" |
| 1378 | "Set the IP address of an interface\n" |
| 1379 | "IP address (e.g. 10.0.0.1/8)\n" |
| 1380 | "Label of this address\n" |
| 1381 | "Label\n") |
| 1382 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 1383 | return ip_address_install (vty, vty->index, argv[0], NULL, argv[1]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | DEFUN (no_ip_address_label, |
| 1387 | no_ip_address_label_cmd, |
| 1388 | "no ip address A.B.C.D/M label LINE", |
| 1389 | NO_STR |
| 1390 | "Interface Internet Protocol config commands\n" |
| 1391 | "Set the IP address of an interface\n" |
| 1392 | "IP address (e.g. 10.0.0.1/8)\n" |
| 1393 | "Label of this address\n" |
| 1394 | "Label\n") |
| 1395 | { |
hasso | eef1fe1 | 2004-10-03 18:46:08 +0000 | [diff] [blame] | 1396 | return ip_address_uninstall (vty, vty->index, argv[0], NULL, argv[1]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1397 | } |
| 1398 | #endif /* HAVE_NETLINK */ |
| 1399 | |
| 1400 | #ifdef HAVE_IPV6 |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1401 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 1402 | ipv6_address_install (struct vty *vty, struct interface *ifp, |
| 1403 | const char *addr_str, const char *peer_str, |
| 1404 | const char *label, int secondary) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1405 | { |
| 1406 | struct prefix_ipv6 cp; |
| 1407 | struct connected *ifc; |
| 1408 | struct prefix_ipv6 *p; |
| 1409 | int ret; |
| 1410 | |
| 1411 | ret = str2prefix_ipv6 (addr_str, &cp); |
| 1412 | if (ret <= 0) |
| 1413 | { |
| 1414 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); |
| 1415 | return CMD_WARNING; |
| 1416 | } |
| 1417 | |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 1418 | ifc = connected_check (ifp, (struct prefix *) &cp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1419 | if (! ifc) |
| 1420 | { |
| 1421 | ifc = connected_new (); |
| 1422 | ifc->ifp = ifp; |
| 1423 | |
| 1424 | /* Address. */ |
| 1425 | p = prefix_ipv6_new (); |
| 1426 | *p = cp; |
| 1427 | ifc->address = (struct prefix *) p; |
| 1428 | |
| 1429 | /* Secondary. */ |
| 1430 | if (secondary) |
| 1431 | SET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); |
| 1432 | |
| 1433 | /* Label. */ |
| 1434 | if (label) |
paul | 0752ef0 | 2005-11-03 12:35:21 +0000 | [diff] [blame] | 1435 | ifc->label = XSTRDUP (MTYPE_CONNECTED_LABEL, label); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1436 | |
| 1437 | /* Add to linked list. */ |
| 1438 | listnode_add (ifp->connected, ifc); |
| 1439 | } |
| 1440 | |
| 1441 | /* This address is configured from zebra. */ |
| 1442 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 1443 | SET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 1444 | |
| 1445 | /* In case of this route need to install kernel. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 1446 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1447 | && CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 1448 | { |
| 1449 | /* Some system need to up the interface to set IP address. */ |
| 1450 | if (! if_is_up (ifp)) |
| 1451 | { |
| 1452 | if_set_flags (ifp, IFF_UP | IFF_RUNNING); |
| 1453 | if_refresh (ifp); |
| 1454 | } |
| 1455 | |
| 1456 | ret = if_prefix_add_ipv6 (ifp, ifc); |
| 1457 | |
| 1458 | if (ret < 0) |
| 1459 | { |
| 1460 | vty_out (vty, "%% Can't set interface IP address: %s.%s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1461 | safe_strerror(errno), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1462 | return CMD_WARNING; |
| 1463 | } |
| 1464 | |
| 1465 | /* IP address propery set. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 1466 | SET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1467 | SET_FLAG (ifc->conf, ZEBRA_IFC_REAL); |
| 1468 | |
| 1469 | /* Update interface address information to protocol daemon. */ |
| 1470 | zebra_interface_address_add_update (ifp, ifc); |
| 1471 | |
| 1472 | /* If interface is up register connected route. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1473 | if (if_is_operative(ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1474 | connected_up_ipv6 (ifp, ifc); |
| 1475 | } |
| 1476 | |
| 1477 | return CMD_SUCCESS; |
| 1478 | } |
| 1479 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1480 | static int |
hasso | 39db97e | 2004-10-12 20:50:58 +0000 | [diff] [blame] | 1481 | ipv6_address_uninstall (struct vty *vty, struct interface *ifp, |
| 1482 | const char *addr_str, const char *peer_str, |
| 1483 | const char *label, int secondry) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1484 | { |
| 1485 | struct prefix_ipv6 cp; |
| 1486 | struct connected *ifc; |
| 1487 | int ret; |
| 1488 | |
| 1489 | /* Convert to prefix structure. */ |
| 1490 | ret = str2prefix_ipv6 (addr_str, &cp); |
| 1491 | if (ret <= 0) |
| 1492 | { |
| 1493 | vty_out (vty, "%% Malformed address %s", VTY_NEWLINE); |
| 1494 | return CMD_WARNING; |
| 1495 | } |
| 1496 | |
| 1497 | /* Check current interface address. */ |
paul | ca16218 | 2005-09-12 16:58:52 +0000 | [diff] [blame] | 1498 | ifc = connected_check (ifp, (struct prefix *) &cp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1499 | if (! ifc) |
| 1500 | { |
| 1501 | vty_out (vty, "%% Can't find address%s", VTY_NEWLINE); |
| 1502 | return CMD_WARNING; |
| 1503 | } |
| 1504 | |
| 1505 | /* This is not configured address. */ |
| 1506 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 1507 | return CMD_WARNING; |
| 1508 | |
Christian Franke | 676e1a0 | 2013-01-24 14:04:45 +0000 | [diff] [blame] | 1509 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED); |
| 1510 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1511 | /* This is not real address or interface is not active. */ |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 1512 | if (! CHECK_FLAG (ifc->conf, ZEBRA_IFC_QUEUED) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1513 | || ! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) |
| 1514 | { |
| 1515 | listnode_delete (ifp->connected, ifc); |
| 1516 | connected_free (ifc); |
| 1517 | return CMD_WARNING; |
| 1518 | } |
| 1519 | |
| 1520 | /* This is real route. */ |
| 1521 | ret = if_prefix_delete_ipv6 (ifp, ifc); |
| 1522 | if (ret < 0) |
| 1523 | { |
| 1524 | vty_out (vty, "%% Can't unset interface IP address: %s.%s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 1525 | safe_strerror(errno), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1526 | return CMD_WARNING; |
| 1527 | } |
| 1528 | |
Christian Franke | f7f740f | 2013-01-24 14:04:48 +0000 | [diff] [blame^] | 1529 | UNSET_FLAG (ifc->conf, ZEBRA_IFC_QUEUED); |
| 1530 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1531 | /* Redistribute this information. */ |
| 1532 | zebra_interface_address_delete_update (ifp, ifc); |
| 1533 | |
| 1534 | /* Remove connected route. */ |
| 1535 | connected_down_ipv6 (ifp, ifc); |
| 1536 | |
| 1537 | /* Free address information. */ |
| 1538 | listnode_delete (ifp->connected, ifc); |
| 1539 | connected_free (ifc); |
| 1540 | |
| 1541 | return CMD_SUCCESS; |
| 1542 | } |
| 1543 | |
| 1544 | DEFUN (ipv6_address, |
| 1545 | ipv6_address_cmd, |
| 1546 | "ipv6 address X:X::X:X/M", |
hasso | e23949c | 2004-03-11 15:54:02 +0000 | [diff] [blame] | 1547 | "Interface IPv6 config commands\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1548 | "Set the IP address of an interface\n" |
| 1549 | "IPv6 address (e.g. 3ffe:506::1/48)\n") |
| 1550 | { |
| 1551 | return ipv6_address_install (vty, vty->index, argv[0], NULL, NULL, 0); |
| 1552 | } |
| 1553 | |
| 1554 | DEFUN (no_ipv6_address, |
| 1555 | no_ipv6_address_cmd, |
| 1556 | "no ipv6 address X:X::X:X/M", |
| 1557 | NO_STR |
hasso | e23949c | 2004-03-11 15:54:02 +0000 | [diff] [blame] | 1558 | "Interface IPv6 config commands\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1559 | "Set the IP address of an interface\n" |
| 1560 | "IPv6 address (e.g. 3ffe:506::1/48)\n") |
| 1561 | { |
| 1562 | return ipv6_address_uninstall (vty, vty->index, argv[0], NULL, NULL, 0); |
| 1563 | } |
| 1564 | #endif /* HAVE_IPV6 */ |
| 1565 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1566 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1567 | if_config_write (struct vty *vty) |
| 1568 | { |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 1569 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1570 | struct interface *ifp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1571 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1572 | for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1573 | { |
| 1574 | struct zebra_if *if_data; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 1575 | struct listnode *addrnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1576 | struct connected *ifc; |
| 1577 | struct prefix *p; |
| 1578 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1579 | if_data = ifp->info; |
| 1580 | |
| 1581 | vty_out (vty, "interface %s%s", ifp->name, |
| 1582 | VTY_NEWLINE); |
| 1583 | |
| 1584 | if (ifp->desc) |
| 1585 | vty_out (vty, " description %s%s", ifp->desc, |
| 1586 | VTY_NEWLINE); |
| 1587 | |
| 1588 | /* Assign bandwidth here to avoid unnecessary interface flap |
| 1589 | while processing config script */ |
| 1590 | if (ifp->bandwidth != 0) |
| 1591 | vty_out(vty, " bandwidth %u%s", ifp->bandwidth, VTY_NEWLINE); |
| 1592 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1593 | if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) |
| 1594 | vty_out(vty, " link-detect%s", VTY_NEWLINE); |
| 1595 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1596 | for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1597 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1598 | if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) |
| 1599 | { |
Stephen Hemminger | 81cce01 | 2009-04-28 14:28:00 -0700 | [diff] [blame] | 1600 | char buf[INET6_ADDRSTRLEN]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1601 | p = ifc->address; |
| 1602 | vty_out (vty, " ip%s address %s/%d", |
| 1603 | p->family == AF_INET ? "" : "v6", |
Stephen Hemminger | 81cce01 | 2009-04-28 14:28:00 -0700 | [diff] [blame] | 1604 | inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1605 | p->prefixlen); |
| 1606 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1607 | if (ifc->label) |
| 1608 | vty_out (vty, " label %s", ifc->label); |
| 1609 | |
| 1610 | vty_out (vty, "%s", VTY_NEWLINE); |
| 1611 | } |
| 1612 | } |
| 1613 | |
| 1614 | if (if_data) |
| 1615 | { |
| 1616 | if (if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) |
| 1617 | vty_out (vty, " shutdown%s", VTY_NEWLINE); |
| 1618 | |
| 1619 | if (if_data->multicast != IF_ZEBRA_MULTICAST_UNSPEC) |
| 1620 | vty_out (vty, " %smulticast%s", |
| 1621 | if_data->multicast == IF_ZEBRA_MULTICAST_ON ? "" : "no ", |
| 1622 | VTY_NEWLINE); |
| 1623 | } |
| 1624 | |
| 1625 | #ifdef RTADV |
| 1626 | rtadv_config_write (vty, ifp); |
| 1627 | #endif /* RTADV */ |
| 1628 | |
hasso | ca77698 | 2004-06-12 14:33:05 +0000 | [diff] [blame] | 1629 | #ifdef HAVE_IRDP |
| 1630 | irdp_config_write (vty, ifp); |
| 1631 | #endif /* IRDP */ |
| 1632 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1633 | vty_out (vty, "!%s", VTY_NEWLINE); |
| 1634 | } |
| 1635 | return 0; |
| 1636 | } |
| 1637 | |
| 1638 | /* Allocate and initialize interface vector. */ |
| 1639 | void |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 1640 | zebra_if_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1641 | { |
| 1642 | /* Initialize interface and new hook. */ |
| 1643 | if_init (); |
| 1644 | if_add_hook (IF_NEW_HOOK, if_zebra_new_hook); |
| 1645 | if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook); |
| 1646 | |
| 1647 | /* Install configuration write function. */ |
| 1648 | install_node (&interface_node, if_config_write); |
| 1649 | |
| 1650 | install_element (VIEW_NODE, &show_interface_cmd); |
| 1651 | install_element (ENABLE_NODE, &show_interface_cmd); |
hasso | ed9bb6d | 2005-03-13 19:17:21 +0000 | [diff] [blame] | 1652 | install_element (ENABLE_NODE, &show_interface_desc_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1653 | install_element (CONFIG_NODE, &zebra_interface_cmd); |
paul | bfc1353 | 2003-05-24 06:40:04 +0000 | [diff] [blame] | 1654 | install_element (CONFIG_NODE, &no_interface_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1655 | install_default (INTERFACE_NODE); |
| 1656 | install_element (INTERFACE_NODE, &interface_desc_cmd); |
| 1657 | install_element (INTERFACE_NODE, &no_interface_desc_cmd); |
| 1658 | install_element (INTERFACE_NODE, &multicast_cmd); |
| 1659 | install_element (INTERFACE_NODE, &no_multicast_cmd); |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 1660 | install_element (INTERFACE_NODE, &linkdetect_cmd); |
| 1661 | install_element (INTERFACE_NODE, &no_linkdetect_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1662 | install_element (INTERFACE_NODE, &shutdown_if_cmd); |
| 1663 | install_element (INTERFACE_NODE, &no_shutdown_if_cmd); |
| 1664 | install_element (INTERFACE_NODE, &bandwidth_if_cmd); |
| 1665 | install_element (INTERFACE_NODE, &no_bandwidth_if_cmd); |
| 1666 | install_element (INTERFACE_NODE, &no_bandwidth_if_val_cmd); |
| 1667 | install_element (INTERFACE_NODE, &ip_address_cmd); |
| 1668 | install_element (INTERFACE_NODE, &no_ip_address_cmd); |
| 1669 | #ifdef HAVE_IPV6 |
| 1670 | install_element (INTERFACE_NODE, &ipv6_address_cmd); |
| 1671 | install_element (INTERFACE_NODE, &no_ipv6_address_cmd); |
| 1672 | #endif /* HAVE_IPV6 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1673 | #ifdef HAVE_NETLINK |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1674 | install_element (INTERFACE_NODE, &ip_address_label_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1675 | install_element (INTERFACE_NODE, &no_ip_address_label_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1676 | #endif /* HAVE_NETLINK */ |
| 1677 | } |