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