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