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