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