]> git.proxmox.com Git - mirror_frr.git/blame - lib/if.c
build: massively remove needless checks
[mirror_frr.git] / lib / if.c
CommitLineData
106d2fd5 1
718e3744 2/*
3 * Interface functions.
4 * Copyright (C) 1997, 98 Kunihiro Ishiguro
5 *
6 * This file is part of GNU Zebra.
7 *
8 * GNU Zebra is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2, or (at your
11 * option) any later version.
12 *
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Zebra; see the file COPYING. If not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24#include <zebra.h>
25
26#include "linklist.h"
27#include "vector.h"
28#include "vty.h"
29#include "command.h"
8736158a 30#include "vrf.h"
718e3744 31#include "if.h"
32#include "sockunion.h"
33#include "prefix.h"
718e3744 34#include "memory.h"
35#include "table.h"
36#include "buffer.h"
37#include "str.h"
38#include "log.h"
6b0655a2 39
4a1ab8e4
DL
40DEFINE_MTYPE( LIB, IF, "Interface")
41DEFINE_MTYPE_STATIC(LIB, CONNECTED, "Connected")
42DEFINE_MTYPE_STATIC(LIB, NBR_CONNECTED, "Neighbor Connected")
43DEFINE_MTYPE( LIB, CONNECTED_LABEL, "Connected interface label")
44DEFINE_MTYPE_STATIC(LIB, IF_LINK_PARAMS, "Informational Link Parameters")
45
e80e7cce
DL
46DEFINE_QOBJ_TYPE(interface)
47
8736158a 48/* List of interfaces in only the default VRF */
244c1cdc 49int ptm_enable = 0;
718e3744 50
51/* One for each program. This structure is needed to store hooks. */
52struct if_master
53{
54 int (*if_new_hook) (struct interface *);
55 int (*if_delete_hook) (struct interface *);
8736158a 56} if_master = {0,};
6b0655a2 57
3a0391a9 58/* Compare interface names, returning an integer greater than, equal to, or
59 * less than 0, (following the strcmp convention), according to the
60 * relationship between ifp1 and ifp2. Interface names consist of an
61 * alphabetic prefix and a numeric suffix. The primary sort key is
62 * lexicographic by name, and then numeric by number. No number sorts
63 * before all numbers. Examples: de0 < de1, de100 < fxp0 < xl0, devpty <
64 * devpty0, de0 < del0
65 */
106d2fd5 66int
974fc9d2 67if_cmp_name_func (char *p1, char *p2)
106d2fd5 68{
69 unsigned int l1, l2;
70 long int x1, x2;
106d2fd5 71 int res;
72
90578521 73 while (*p1 && *p2) {
106d2fd5 74 /* look up to any number */
75 l1 = strcspn(p1, "0123456789");
76 l2 = strcspn(p2, "0123456789");
77
78 /* name lengths are different -> compare names */
79 if (l1 != l2)
80 return (strcmp(p1, p2));
81
3a0391a9 82 /* Note that this relies on all numbers being less than all letters, so
83 * that de0 < del0.
84 */
106d2fd5 85 res = strncmp(p1, p2, l1);
86
87 /* names are different -> compare them */
88 if (res)
89 return res;
90
91 /* with identical name part, go to numeric part */
106d2fd5 92 p1 += l1;
93 p2 += l1;
94
b06c14f2 95 if (!*p1)
96 return -1;
97 if (!*p2)
98 return 1;
99
106d2fd5 100 x1 = strtol(p1, &p1, 10);
101 x2 = strtol(p2, &p2, 10);
102
103 /* let's compare numbers now */
104 if (x1 < x2)
105 return -1;
106 if (x1 > x2)
107 return 1;
108
109 /* numbers were equal, lets do it again..
110 (it happens with name like "eth123.456:789") */
111 }
90578521 112 if (*p1)
113 return 1;
114 if (*p2)
115 return -1;
116 return 0;
106d2fd5 117}
118
974fc9d2
DS
119static int
120if_cmp_func (struct interface *ifp1, struct interface *ifp2)
121{
122 return if_cmp_name_func (ifp1->name, ifp2->name);
123}
124
718e3744 125/* Create new interface structure. */
718e3744 126struct interface *
8736158a 127if_create_vrf (const char *name, int namelen, vrf_id_t vrf_id)
718e3744 128{
129 struct interface *ifp;
8736158a 130 struct list *intf_list = vrf_iflist_get (vrf_id);
718e3744 131
d2fc8896 132 ifp = XCALLOC (MTYPE_IF, sizeof (struct interface));
133 ifp->ifindex = IFINDEX_INTERNAL;
718e3744 134
106d2fd5 135 assert (name);
d2fc8896 136 assert (namelen <= INTERFACE_NAMSIZ); /* Need space for '\0' at end. */
106d2fd5 137 strncpy (ifp->name, name, namelen);
d2fc8896 138 ifp->name[namelen] = '\0';
8736158a
FL
139 ifp->vrf_id = vrf_id;
140 if (if_lookup_by_name_vrf (ifp->name, vrf_id) == NULL)
141 listnode_add_sort (intf_list, ifp);
d2fc8896 142 else
143 zlog_err("if_create(%s): corruption detected -- interface with this "
8736158a 144 "name exists already in VRF %u!", ifp->name, vrf_id);
718e3744 145 ifp->connected = list_new ();
146 ifp->connected->del = (void (*) (void *)) connected_free;
147
a80beece
DS
148 ifp->nbr_connected = list_new ();
149 ifp->nbr_connected->del = (void (*) (void *)) nbr_connected_free;
150
c9506a0a
DS
151 /* Enable Link-detection by default */
152 SET_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION);
153
e80e7cce
DL
154 QOBJ_REG (ifp, interface);
155
718e3744 156 if (if_master.if_new_hook)
157 (*if_master.if_new_hook) (ifp);
158
159 return ifp;
160}
161
8736158a
FL
162struct interface *
163if_create (const char *name, int namelen)
164{
165 return if_create_vrf (name, namelen, VRF_DEFAULT);
166}
167
f93e3f69
DS
168/* Create new interface structure. */
169void
170if_update_vrf (struct interface *ifp, const char *name, int namelen, vrf_id_t vrf_id)
171{
172 struct list *intf_list = vrf_iflist_get (vrf_id);
173
174 /* remove interface from old master vrf list */
175 if (vrf_iflist (ifp->vrf_id))
176 listnode_delete (vrf_iflist (ifp->vrf_id), ifp);
177
178 assert (name);
179 assert (namelen <= INTERFACE_NAMSIZ); /* Need space for '\0' at end. */
180 strncpy (ifp->name, name, namelen);
181 ifp->name[namelen] = '\0';
182 ifp->vrf_id = vrf_id;
183 if (if_lookup_by_name_vrf (ifp->name, vrf_id) == NULL)
184 listnode_add_sort (intf_list, ifp);
185 else
186 zlog_err("if_create(%s): corruption detected -- interface with this "
187 "name exists already in VRF %u!", ifp->name, vrf_id);
188
189 return;
190}
191
192
d2fc8896 193/* Delete interface structure. */
718e3744 194void
d2fc8896 195if_delete_retain (struct interface *ifp)
718e3744 196{
718e3744 197 if (if_master.if_delete_hook)
198 (*if_master.if_delete_hook) (ifp);
199
e80e7cce
DL
200 QOBJ_UNREG (ifp);
201
718e3744 202 /* Free connected address list */
2dd04c5d 203 list_delete_all_node (ifp->connected);
a80beece
DS
204
205 /* Free connected nbr address list */
206 list_delete_all_node (ifp->nbr_connected);
d2fc8896 207}
208
209/* Delete and free interface structure. */
210void
211if_delete (struct interface *ifp)
212{
8736158a 213 listnode_delete (vrf_iflist (ifp->vrf_id), ifp);
d2fc8896 214
215 if_delete_retain(ifp);
718e3744 216
2dd04c5d 217 list_free (ifp->connected);
a80beece 218 list_free (ifp->nbr_connected);
2dd04c5d 219
16f1b9ee
OD
220 if_link_params_free (ifp);
221
718e3744 222 XFREE (MTYPE_IF, ifp);
223}
224
225/* Add hook to interface master. */
226void
227if_add_hook (int type, int (*func)(struct interface *ifp))
228{
229 switch (type) {
230 case IF_NEW_HOOK:
231 if_master.if_new_hook = func;
232 break;
233 case IF_DELETE_HOOK:
234 if_master.if_delete_hook = func;
235 break;
236 default:
237 break;
238 }
239}
240
241/* Interface existance check by index. */
242struct interface *
b892f1dd 243if_lookup_by_index_vrf (ifindex_t ifindex, vrf_id_t vrf_id)
718e3744 244{
52dc7ee6 245 struct listnode *node;
718e3744 246 struct interface *ifp;
247
8736158a 248 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
718e3744 249 {
b892f1dd 250 if (ifp->ifindex == ifindex)
718e3744 251 return ifp;
252 }
253 return NULL;
254}
255
8736158a 256struct interface *
b892f1dd 257if_lookup_by_index (ifindex_t ifindex)
8736158a 258{
b892f1dd 259 return if_lookup_by_index_vrf (ifindex, VRF_DEFAULT);
8736158a
FL
260}
261
8cc4198f 262const char *
b892f1dd 263ifindex2ifname_vrf (ifindex_t ifindex, vrf_id_t vrf_id)
718e3744 264{
718e3744 265 struct interface *ifp;
266
b892f1dd 267 return ((ifp = if_lookup_by_index_vrf (ifindex, vrf_id)) != NULL) ?
8cc4198f 268 ifp->name : "unknown";
d2fc8896 269}
270
8736158a 271const char *
b892f1dd 272ifindex2ifname (ifindex_t ifindex)
8736158a 273{
b892f1dd 274 return ifindex2ifname_vrf (ifindex, VRF_DEFAULT);
8736158a
FL
275}
276
b892f1dd 277ifindex_t
8736158a 278ifname2ifindex_vrf (const char *name, vrf_id_t vrf_id)
d2fc8896 279{
280 struct interface *ifp;
281
8736158a 282 return ((ifp = if_lookup_by_name_vrf (name, vrf_id)) != NULL) ? ifp->ifindex
3e4ee959 283 : IFINDEX_INTERNAL;
718e3744 284}
285
b892f1dd 286ifindex_t
8736158a
FL
287ifname2ifindex (const char *name)
288{
289 return ifname2ifindex_vrf (name, VRF_DEFAULT);
290}
291
718e3744 292/* Interface existance check by interface name. */
293struct interface *
8736158a 294if_lookup_by_name_vrf (const char *name, vrf_id_t vrf_id)
718e3744 295{
52dc7ee6 296 struct listnode *node;
718e3744 297 struct interface *ifp;
3e4ee959
PJ
298
299 if (name)
8736158a 300 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
3e4ee959
PJ
301 {
302 if (strcmp(name, ifp->name) == 0)
303 return ifp;
304 }
718e3744 305 return NULL;
306}
307
f8962871
DS
308struct interface *
309if_lookup_by_name_all_vrf (const char *name)
310{
311 struct interface *ifp;
312 struct vrf *vrf = NULL;
313 vrf_iter_t iter;
314
315 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
316 {
317 vrf = vrf_iter2vrf (iter);
318 ifp = if_lookup_by_name_vrf (name, vrf->vrf_id);
319 if (ifp)
320 return ifp;
321 }
322
323 return NULL;
324}
325
a349198f 326struct interface *
8736158a
FL
327if_lookup_by_name (const char *name)
328{
329 return if_lookup_by_name_vrf (name, VRF_DEFAULT);
330}
331
332struct interface *
333if_lookup_by_name_len_vrf (const char *name, size_t namelen, vrf_id_t vrf_id)
a349198f 334{
335 struct listnode *node;
1eb8ef25 336 struct interface *ifp;
a349198f 337
338 if (namelen > INTERFACE_NAMSIZ)
339 return NULL;
340
8736158a 341 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
a349198f 342 {
a349198f 343 if (!memcmp(name, ifp->name, namelen) && (ifp->name[namelen] == '\0'))
344 return ifp;
345 }
346 return NULL;
347}
348
8736158a
FL
349struct interface *
350if_lookup_by_name_len(const char *name, size_t namelen)
351{
352 return if_lookup_by_name_len_vrf (name, namelen, VRF_DEFAULT);
353}
354
718e3744 355/* Lookup interface by IPv4 address. */
356struct interface *
8736158a 357if_lookup_exact_address_vrf (void *src, int family, vrf_id_t vrf_id)
718e3744 358{
52dc7ee6 359 struct listnode *node;
360 struct listnode *cnode;
718e3744 361 struct interface *ifp;
362 struct prefix *p;
363 struct connected *c;
364
8736158a 365 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
718e3744 366 {
1eb8ef25 367 for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
718e3744 368 {
718e3744 369 p = c->address;
370
0aabccc0 371 if (p && (p->family == family))
718e3744 372 {
0aabccc0
DD
373 if (family == AF_INET)
374 {
375 if (IPV4_ADDR_SAME (&p->u.prefix4, (struct in_addr *)src))
376 return ifp;
377 }
378 else if (family == AF_INET6)
379 {
380 if (IPV6_ADDR_SAME (&p->u.prefix4, (struct in6_addr *)src))
381 return ifp;
382 }
383 }
718e3744 384 }
385 }
386 return NULL;
387}
388
8736158a
FL
389struct interface *
390if_lookup_exact_address (void *src, int family)
391{
392 return if_lookup_exact_address_vrf (src, family, VRF_DEFAULT);
393}
394
718e3744 395/* Lookup interface by IPv4 address. */
396struct interface *
8736158a 397if_lookup_address_vrf (void *matchaddr, int family, vrf_id_t vrf_id)
718e3744 398{
52dc7ee6 399 struct listnode *node;
718e3744 400 struct prefix addr;
3fb9cd6e 401 int bestlen = 0;
52dc7ee6 402 struct listnode *cnode;
718e3744 403 struct interface *ifp;
718e3744 404 struct connected *c;
405 struct interface *match;
406
0aabccc0
DD
407 if (family == AF_INET)
408 {
409 addr.family = AF_INET;
410 addr.u.prefix4 = *((struct in_addr *)matchaddr);
411 addr.prefixlen = IPV4_MAX_BITLEN;
412 }
413 else if (family == AF_INET6)
414 {
415 addr.family = AF_INET6;
416 addr.u.prefix6 = *((struct in6_addr *)matchaddr);
417 addr.prefixlen = IPV6_MAX_BITLEN;
418 }
718e3744 419
420 match = NULL;
421
8736158a 422 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
718e3744 423 {
1eb8ef25 424 for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
718e3744 425 {
e4529636
AS
426 if (c->address && (c->address->family == AF_INET) &&
427 prefix_match(CONNECTED_PREFIX(c), &addr) &&
428 (c->address->prefixlen > bestlen))
718e3744 429 {
e4529636
AS
430 bestlen = c->address->prefixlen;
431 match = ifp;
718e3744 432 }
433 }
434 }
435 return match;
436}
437
8736158a
FL
438struct interface *
439if_lookup_address (void *matchaddr, int family)
440{
441 return if_lookup_address_vrf (matchaddr, family, VRF_DEFAULT);
442}
443
b81e97a8
DD
444/* Lookup interface by prefix */
445struct interface *
8736158a 446if_lookup_prefix_vrf (struct prefix *prefix, vrf_id_t vrf_id)
b81e97a8
DD
447{
448 struct listnode *node;
b81e97a8
DD
449 struct listnode *cnode;
450 struct interface *ifp;
451 struct connected *c;
452
8736158a 453 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
b81e97a8
DD
454 {
455 for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
456 {
457 if (prefix_cmp(c->address, prefix) == 0)
458 {
459 return ifp;
460 }
461 }
462 }
463 return NULL;
464}
465
8736158a
FL
466struct interface *
467if_lookup_prefix (struct prefix *prefix)
468{
469 return if_lookup_prefix_vrf (prefix, VRF_DEFAULT);
470}
471
718e3744 472/* Get interface by name if given name interface doesn't exist create
473 one. */
474struct interface *
8736158a 475if_get_by_name_vrf (const char *name, vrf_id_t vrf_id)
718e3744 476{
477 struct interface *ifp;
478
8736158a
FL
479 return ((ifp = if_lookup_by_name_vrf (name, vrf_id)) != NULL) ? ifp :
480 if_create_vrf (name, strlen(name), vrf_id);
a349198f 481}
482
483struct interface *
8736158a
FL
484if_get_by_name (const char *name)
485{
486 return if_get_by_name_vrf (name, VRF_DEFAULT);
487}
488
489struct interface *
85f9da7f 490if_get_by_name_len_vrf (const char *name, size_t namelen, vrf_id_t vrf_id, int vty)
a349198f 491{
492 struct interface *ifp;
85f9da7f
DS
493 struct listnode *node;
494 struct vrf *vrf = NULL;
495 vrf_iter_t iter;
496
497 ifp = if_lookup_by_name_len_vrf (name, namelen, vrf_id);
498 if (ifp)
499 return ifp;
a349198f 500
85f9da7f
DS
501 /* Didn't find the interface on that vrf. Defined on a different one? */
502 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
503 {
504 vrf = vrf_iter2vrf(iter);
505 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf->vrf_id), node, ifp))
506 {
507 if (!memcmp(name, ifp->name, namelen) && (ifp->name[namelen] == '\0'))
508 {
509 /* Found a match. If the interface command was entered in vty without a
510 * VRF (passed as VRF_DEFAULT), accept the ifp we found. If a vrf was
511 * entered and there is a mismatch, reject it if from vty. If it came
512 * from the kernel by way of zclient, believe it and update
513 * the ifp accordingly.
514 */
53eadacf 515 if (vty)
516 {
517 if (vrf_id == VRF_DEFAULT)
518 return ifp;
519 return NULL;
520 }
85f9da7f
DS
521 else
522 {
523 if_update_vrf (ifp, name, namelen, vrf_id);
524 return ifp;
525 }
526 }
527 }
528 }
529 return (if_create_vrf (name, namelen, vrf_id));
8736158a
FL
530}
531
532struct interface *
533if_get_by_name_len (const char *name, size_t namelen)
534{
85f9da7f 535 return if_get_by_name_len_vrf (name, namelen, VRF_DEFAULT, 0);
718e3744 536}
537
538/* Does interface up ? */
539int
540if_is_up (struct interface *ifp)
541{
542 return ifp->flags & IFF_UP;
543}
544
2e3b2e47 545/* Is interface running? */
546int
547if_is_running (struct interface *ifp)
548{
549 return ifp->flags & IFF_RUNNING;
550}
551
552/* Is the interface operative, eg. either UP & RUNNING
244c1cdc
DS
553 or UP & !ZEBRA_INTERFACE_LINK_DETECTION and
554 if ptm checking is enabled, then ptm check has passed */
2e3b2e47 555int
556if_is_operative (struct interface *ifp)
557{
558 return ((ifp->flags & IFF_UP) &&
244c1cdc
DS
559 (((ifp->flags & IFF_RUNNING) &&
560 (ifp->ptm_status || !ifp->ptm_enable)) ||
561 !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)));
562}
563
564/* Is the interface operative, eg. either UP & RUNNING
565 or UP & !ZEBRA_INTERFACE_LINK_DETECTION, without PTM check */
566int
567if_is_no_ptm_operative (struct interface *ifp)
568{
569 return ((ifp->flags & IFF_UP) &&
570 ((ifp->flags & IFF_RUNNING) ||
571 !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)));
2e3b2e47 572}
573
718e3744 574/* Is this loopback interface ? */
575int
576if_is_loopback (struct interface *ifp)
577{
4ba9b924 578 /* XXX: Do this better, eg what if IFF_WHATEVER means X on platform M
579 * but Y on platform N?
580 */
581 return (ifp->flags & (IFF_LOOPBACK|IFF_NOXMIT|IFF_VIRTUAL));
718e3744 582}
583
584/* Does this interface support broadcast ? */
585int
586if_is_broadcast (struct interface *ifp)
587{
588 return ifp->flags & IFF_BROADCAST;
589}
590
591/* Does this interface support broadcast ? */
592int
593if_is_pointopoint (struct interface *ifp)
594{
595 return ifp->flags & IFF_POINTOPOINT;
596}
597
598/* Does this interface support multicast ? */
599int
600if_is_multicast (struct interface *ifp)
601{
602 return ifp->flags & IFF_MULTICAST;
603}
604
605/* Printout flag information into log */
606const char *
607if_flag_dump (unsigned long flag)
608{
609 int separator = 0;
610 static char logbuf[BUFSIZ];
611
612#define IFF_OUT_LOG(X,STR) \
4ba9b924 613 if (flag & (X)) \
718e3744 614 { \
615 if (separator) \
616 strlcat (logbuf, ",", BUFSIZ); \
617 else \
618 separator = 1; \
619 strlcat (logbuf, STR, BUFSIZ); \
620 }
621
630c97ce 622 strlcpy (logbuf, "<", BUFSIZ);
718e3744 623 IFF_OUT_LOG (IFF_UP, "UP");
624 IFF_OUT_LOG (IFF_BROADCAST, "BROADCAST");
625 IFF_OUT_LOG (IFF_DEBUG, "DEBUG");
626 IFF_OUT_LOG (IFF_LOOPBACK, "LOOPBACK");
627 IFF_OUT_LOG (IFF_POINTOPOINT, "POINTOPOINT");
628 IFF_OUT_LOG (IFF_NOTRAILERS, "NOTRAILERS");
629 IFF_OUT_LOG (IFF_RUNNING, "RUNNING");
630 IFF_OUT_LOG (IFF_NOARP, "NOARP");
631 IFF_OUT_LOG (IFF_PROMISC, "PROMISC");
632 IFF_OUT_LOG (IFF_ALLMULTI, "ALLMULTI");
633 IFF_OUT_LOG (IFF_OACTIVE, "OACTIVE");
634 IFF_OUT_LOG (IFF_SIMPLEX, "SIMPLEX");
635 IFF_OUT_LOG (IFF_LINK0, "LINK0");
636 IFF_OUT_LOG (IFF_LINK1, "LINK1");
637 IFF_OUT_LOG (IFF_LINK2, "LINK2");
638 IFF_OUT_LOG (IFF_MULTICAST, "MULTICAST");
4ba9b924 639 IFF_OUT_LOG (IFF_NOXMIT, "NOXMIT");
640 IFF_OUT_LOG (IFF_NORTEXCH, "NORTEXCH");
641 IFF_OUT_LOG (IFF_VIRTUAL, "VIRTUAL");
642 IFF_OUT_LOG (IFF_IPV4, "IPv4");
643 IFF_OUT_LOG (IFF_IPV6, "IPv6");
718e3744 644
645 strlcat (logbuf, ">", BUFSIZ);
646
647 return logbuf;
630c97ce 648#undef IFF_OUT_LOG
718e3744 649}
650
651/* For debugging */
8cc4198f 652static void
cedd7f2f 653if_dump (const struct interface *ifp)
718e3744 654{
1f9a9fff
PJ
655 struct listnode *node;
656 struct connected *c __attribute__((unused));
657
658 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, c))
3968dbf8 659 zlog_info ("Interface %s vrf %u index %d metric %d mtu %d "
1f9a9fff 660 "mtu6 %d %s",
3968dbf8 661 ifp->name, ifp->vrf_id, ifp->ifindex, ifp->metric, ifp->mtu,
1f9a9fff 662 ifp->mtu6, if_flag_dump (ifp->flags));
718e3744 663}
664
665/* Interface printing for all interface. */
666void
66e5cd87 667if_dump_all (void)
718e3744 668{
8736158a 669 struct list *intf_list;
52dc7ee6 670 struct listnode *node;
1eb8ef25 671 void *p;
8736158a 672 vrf_iter_t iter;
718e3744 673
8736158a
FL
674 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
675 if ((intf_list = vrf_iter2iflist (iter)) != NULL)
676 for (ALL_LIST_ELEMENTS_RO (intf_list, node, p))
677 if_dump (p);
718e3744 678}
679
680DEFUN (interface_desc,
681 interface_desc_cmd,
682 "description .LINE",
683 "Interface specific description\n"
684 "Characters describing this interface\n")
685{
be301cc2 686 VTY_DECLVAR_CONTEXT (interface, ifp);
718e3744 687
688 if (argc == 0)
689 return CMD_SUCCESS;
690
718e3744 691 if (ifp->desc)
3b8b1855 692 XFREE (MTYPE_TMP, ifp->desc);
693 ifp->desc = argv_concat(argv, argc, 0);
718e3744 694
695 return CMD_SUCCESS;
696}
697
698DEFUN (no_interface_desc,
699 no_interface_desc_cmd,
700 "no description",
701 NO_STR
702 "Interface specific description\n")
703{
be301cc2 704 VTY_DECLVAR_CONTEXT (interface, ifp);
718e3744 705
718e3744 706 if (ifp->desc)
0241684e 707 XFREE (MTYPE_TMP, ifp->desc);
718e3744 708 ifp->desc = NULL;
709
710 return CMD_SUCCESS;
711}
6b0655a2 712
98954844
PJ
713#ifdef SUNOS_5
714/* Need to handle upgrade from SUNWzebra to Quagga. SUNWzebra created
715 * a seperate struct interface for each logical interface, so config
716 * file may be full of 'interface fooX:Y'. Solaris however does not
717 * expose logical interfaces via PF_ROUTE, so trying to track logical
718 * interfaces can be fruitless, for that reason Quagga only tracks
719 * the primary IP interface.
720 *
721 * We try accomodate SUNWzebra by:
722 * - looking up the interface name, to see whether it exists, if so
723 * its useable
724 * - for protocol daemons, this could only because zebra told us of
725 * the interface
726 * - for zebra, only because it learnt from kernel
727 * - if not:
728 * - search the name to see if it contains a sub-ipif / logical interface
729 * seperator, the ':' char. If it does:
730 * - text up to that char must be the primary name - get that name.
731 * if not:
732 * - no idea, just get the name in its entirety.
733 */
734static struct interface *
8736158a 735if_sunwzebra_get (const char *name, size_t nlen, vrf_id_t vrf_id)
98954844
PJ
736{
737 struct interface *ifp;
738 size_t seppos = 0;
718e3744 739
8736158a 740 if ( (ifp = if_lookup_by_name_len_vrf (name, nlen, vrf_id)) != NULL)
98954844
PJ
741 return ifp;
742
743 /* hunt the primary interface name... */
744 while (seppos < nlen && name[seppos] != ':')
745 seppos++;
746
747 /* Wont catch seperator as last char, e.g. 'foo0:' but thats invalid */
748 if (seppos < nlen)
85f9da7f 749 return if_get_by_name_len_vrf (name, seppos, vrf_id, 1);
98954844 750 else
85f9da7f 751 return if_get_by_name_len_vrf (name, nlen, vrf_id, 1);
98954844
PJ
752}
753#endif /* SUNOS_5 */
6b0655a2 754
718e3744 755DEFUN (interface,
756 interface_cmd,
757 "interface IFNAME",
758 "Select an interface to configure\n"
759 "Interface's name\n")
760{
761 struct interface *ifp;
d2fc8896 762 size_t sl;
8736158a 763 vrf_id_t vrf_id = VRF_DEFAULT;
d2fc8896 764
765 if ((sl = strlen(argv[0])) > INTERFACE_NAMSIZ)
766 {
767 vty_out (vty, "%% Interface name %s is invalid: length exceeds "
768 "%d characters%s",
769 argv[0], INTERFACE_NAMSIZ, VTY_NEWLINE);
770 return CMD_WARNING;
771 }
718e3744 772
f93e3f69
DS
773/*Pending: need proper vrf name based lookup/(possible creation of VRF)
774 Imagine forward reference of a vrf by name in this interface config */
cd2a8a42 775 if (argc > 1)
f93e3f69 776 VRF_GET_ID (vrf_id, argv[1]);
cd2a8a42 777
98954844 778#ifdef SUNOS_5
8736158a 779 ifp = if_sunwzebra_get (argv[0], sl, vrf_id);
98954844 780#else
85f9da7f 781 ifp = if_get_by_name_len_vrf (argv[0], sl, vrf_id, 1);
98954844 782#endif /* SUNOS_5 */
718e3744 783
85f9da7f
DS
784 if (!ifp)
785 {
786 vty_out (vty, "%% interface %s not in %s%s", argv[0], argv[1], VTY_NEWLINE);
787 return CMD_WARNING;
788 }
be301cc2 789 VTY_PUSH_CONTEXT_COMPAT (INTERFACE_NODE, ifp);
718e3744 790
791 return CMD_SUCCESS;
792}
793
cd2a8a42
FL
794ALIAS (interface,
795 interface_vrf_cmd,
796 "interface IFNAME " VRF_CMD_STR,
797 "Select an interface to configure\n"
798 "Interface's name\n"
799 VRF_CMD_HELP_STR)
800
32d2463c 801DEFUN_NOSH (no_interface,
802 no_interface_cmd,
803 "no interface IFNAME",
804 NO_STR
805 "Delete a pseudo interface's configuration\n"
806 "Interface's name\n")
807{
808 // deleting interface
809 struct interface *ifp;
8736158a 810 vrf_id_t vrf_id = VRF_DEFAULT;
32d2463c 811
cd2a8a42 812 if (argc > 1)
f93e3f69 813 VRF_GET_ID (vrf_id, argv[1]);
cd2a8a42 814
8736158a 815 ifp = if_lookup_by_name_vrf (argv[0], vrf_id);
32d2463c 816
817 if (ifp == NULL)
d2fc8896 818 {
819 vty_out (vty, "%% Interface %s does not exist%s", argv[0], VTY_NEWLINE);
820 return CMD_WARNING;
821 }
32d2463c 822
bfc13532 823 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
d2fc8896 824 {
825 vty_out (vty, "%% Only inactive interfaces can be deleted%s",
826 VTY_NEWLINE);
827 return CMD_WARNING;
828 }
32d2463c 829
830 if_delete(ifp);
831
832 return CMD_SUCCESS;
833}
834
cd2a8a42
FL
835ALIAS (no_interface,
836 no_interface_vrf_cmd,
837 "no interface IFNAME " VRF_CMD_STR,
838 NO_STR
839 "Delete a pseudo interface's configuration\n"
840 "Interface's name\n"
841 VRF_CMD_HELP_STR)
842
f93e3f69
DS
843DEFUN (vrf,
844 vrf_cmd,
845 "vrf NAME",
846 "Select a VRF to configure\n"
847 "VRF's name\n")
848{
849 struct vrf *vrfp;
850 size_t sl;
851
852 if ((sl = strlen(argv[0])) > VRF_NAMSIZ)
853 {
854 vty_out (vty, "%% VRF name %s is invalid: length exceeds "
855 "%d characters%s",
856 argv[0], VRF_NAMSIZ, VTY_NEWLINE);
857 return CMD_WARNING;
858 }
859
58255d34 860 vrfp = vrf_get (VRF_UNKNOWN, argv[0]);
f93e3f69 861
be301cc2 862 VTY_PUSH_CONTEXT_COMPAT (VRF_NODE, vrfp);
f93e3f69
DS
863
864 return CMD_SUCCESS;
865}
866
867DEFUN_NOSH (no_vrf,
868 no_vrf_cmd,
869 "no vrf NAME",
870 NO_STR
871 "Delete a pseudo VRF's configuration\n"
872 "VRF's name\n")
873{
874 struct vrf *vrfp;
875
876 vrfp = vrf_list_lookup_by_name (argv[0]);
877
878 if (vrfp == NULL)
879 {
880 vty_out (vty, "%% VRF %s does not exist%s", argv[0], VTY_NEWLINE);
881 return CMD_WARNING;
882 }
883
79694123 884 if (CHECK_FLAG (vrfp->status, VRF_ACTIVE))
f93e3f69
DS
885 {
886 vty_out (vty, "%% Only inactive VRFs can be deleted%s",
887 VTY_NEWLINE);
888 return CMD_WARNING;
889 }
890
891 vrf_delete(vrfp);
892
893 return CMD_SUCCESS;
894}
895
896
718e3744 897/* For debug purpose. */
898DEFUN (show_address,
899 show_address_cmd,
900 "show address",
901 SHOW_STR
902 "address\n")
903{
52dc7ee6 904 struct listnode *node;
905 struct listnode *node2;
718e3744 906 struct interface *ifp;
907 struct connected *ifc;
908 struct prefix *p;
8736158a 909 vrf_id_t vrf_id = VRF_DEFAULT;
718e3744 910
8736158a 911 if (argc > 0)
f93e3f69 912 VRF_GET_ID (vrf_id, argv[0]);
8736158a
FL
913
914 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
718e3744 915 {
1eb8ef25 916 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc))
718e3744 917 {
718e3744 918 p = ifc->address;
919
920 if (p->family == AF_INET)
921 vty_out (vty, "%s/%d%s", inet_ntoa (p->u.prefix4), p->prefixlen,
922 VTY_NEWLINE);
923 }
924 }
925 return CMD_SUCCESS;
926}
927
8736158a
FL
928ALIAS (show_address,
929 show_address_vrf_cmd,
930 "show address " VRF_CMD_STR,
931 SHOW_STR
932 "address\n"
933 VRF_CMD_HELP_STR)
934
935DEFUN (show_address_vrf_all,
936 show_address_vrf_all_cmd,
937 "show address " VRF_ALL_CMD_STR,
938 SHOW_STR
939 "address\n"
940 VRF_ALL_CMD_HELP_STR)
941{
942 struct list *intf_list;
943 struct listnode *node;
944 struct listnode *node2;
945 struct interface *ifp;
946 struct connected *ifc;
947 struct prefix *p;
948 vrf_iter_t iter;
949
950 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
951 {
952 intf_list = vrf_iter2iflist (iter);
953 if (!intf_list || !listcount (intf_list))
954 continue;
955
956 vty_out (vty, "%sVRF %u%s%s", VTY_NEWLINE, vrf_iter2id (iter),
957 VTY_NEWLINE, VTY_NEWLINE);
958
959 for (ALL_LIST_ELEMENTS_RO (intf_list, node, ifp))
960 {
961 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc))
962 {
963 p = ifc->address;
964
965 if (p->family == AF_INET)
966 vty_out (vty, "%s/%d%s", inet_ntoa (p->u.prefix4), p->prefixlen,
967 VTY_NEWLINE);
968 }
969 }
970 }
971 return CMD_SUCCESS;
972}
973
718e3744 974/* Allocate connected structure. */
975struct connected *
8cc4198f 976connected_new (void)
718e3744 977{
393deb9b 978 return XCALLOC (MTYPE_CONNECTED, sizeof (struct connected));
718e3744 979}
980
a80beece
DS
981/* Allocate nbr connected structure. */
982struct nbr_connected *
983nbr_connected_new (void)
984{
985 return XCALLOC (MTYPE_NBR_CONNECTED, sizeof (struct nbr_connected));
986}
987
718e3744 988/* Free connected structure. */
989void
990connected_free (struct connected *connected)
991{
992 if (connected->address)
993 prefix_free (connected->address);
994
995 if (connected->destination)
996 prefix_free (connected->destination);
997
998 if (connected->label)
9c4f1c6f 999 XFREE (MTYPE_CONNECTED_LABEL, connected->label);
718e3744 1000
1001 XFREE (MTYPE_CONNECTED, connected);
1002}
1003
a80beece
DS
1004/* Free nbr connected structure. */
1005void
1006nbr_connected_free (struct nbr_connected *connected)
1007{
1008 if (connected->address)
1009 prefix_free (connected->address);
1010
1011 XFREE (MTYPE_NBR_CONNECTED, connected);
1012}
1013
1014/* If same interface nbr address already exists... */
1015struct nbr_connected *
1016nbr_connected_check (struct interface *ifp, struct prefix *p)
1017{
1018 struct nbr_connected *ifc;
1019 struct listnode *node;
1020
1021 for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, ifc))
1022 if (prefix_same (ifc->address, p))
1023 return ifc;
1024
1025 return NULL;
1026}
1027
718e3744 1028/* Print if_addr structure. */
8cc4198f 1029static void __attribute__ ((unused))
718e3744 1030connected_log (struct connected *connected, char *str)
1031{
1032 struct prefix *p;
1033 struct interface *ifp;
1034 char logbuf[BUFSIZ];
1035 char buf[BUFSIZ];
1036
1037 ifp = connected->ifp;
1038 p = connected->address;
1039
3968dbf8
FL
1040 snprintf (logbuf, BUFSIZ, "%s interface %s vrf %u %s %s/%d ",
1041 str, ifp->name, ifp->vrf_id, prefix_family_str (p),
718e3744 1042 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1043 p->prefixlen);
1044
1045 p = connected->destination;
1046 if (p)
1047 {
1048 strncat (logbuf, inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1049 BUFSIZ - strlen(logbuf));
1050 }
fc95186c 1051 zlog (NULL, LOG_INFO, "%s", logbuf);
718e3744 1052}
1053
a80beece
DS
1054/* Print if_addr structure. */
1055static void __attribute__ ((unused))
1056nbr_connected_log (struct nbr_connected *connected, char *str)
1057{
1058 struct prefix *p;
1059 struct interface *ifp;
1060 char logbuf[BUFSIZ];
1061 char buf[BUFSIZ];
1062
1063 ifp = connected->ifp;
1064 p = connected->address;
1065
1066 snprintf (logbuf, BUFSIZ, "%s interface %s %s %s/%d ",
1067 str, ifp->name, prefix_family_str (p),
1068 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1069 p->prefixlen);
1070
1071 zlog (NULL, LOG_INFO, "%s", logbuf);
1072}
1073
718e3744 1074/* If two connected address has same prefix return 1. */
8cc4198f 1075static int
718e3744 1076connected_same_prefix (struct prefix *p1, struct prefix *p2)
1077{
1078 if (p1->family == p2->family)
1079 {
1080 if (p1->family == AF_INET &&
1081 IPV4_ADDR_SAME (&p1->u.prefix4, &p2->u.prefix4))
1082 return 1;
1083#ifdef HAVE_IPV6
1084 if (p1->family == AF_INET6 &&
1085 IPV6_ADDR_SAME (&p1->u.prefix6, &p2->u.prefix6))
1086 return 1;
1087#endif /* HAVE_IPV6 */
1088 }
1089 return 0;
1090}
1091
38485402
DS
1092struct connected *
1093connected_lookup_prefix_exact (struct interface *ifp, struct prefix *p)
1094{
1095 struct listnode *node;
1096 struct listnode *next;
1097 struct connected *ifc;
1098
1099 for (node = listhead (ifp->connected); node; node = next)
1100 {
1101 ifc = listgetdata (node);
1102 next = node->next;
1103
1104 if (connected_same_prefix (ifc->address, p))
1105 return ifc;
1106 }
1107 return NULL;
1108}
1109
718e3744 1110struct connected *
1111connected_delete_by_prefix (struct interface *ifp, struct prefix *p)
1112{
1113 struct listnode *node;
1114 struct listnode *next;
1115 struct connected *ifc;
1116
1117 /* In case of same prefix come, replace it with new one. */
1118 for (node = listhead (ifp->connected); node; node = next)
1119 {
1eb8ef25 1120 ifc = listgetdata (node);
718e3744 1121 next = node->next;
1122
1123 if (connected_same_prefix (ifc->address, p))
1124 {
1125 listnode_delete (ifp->connected, ifc);
1126 return ifc;
1127 }
1128 }
1129 return NULL;
1130}
1131
bd40c341 1132/* Find the address on our side that will be used when packets
727d104b 1133 are sent to dst. */
1134struct connected *
bd40c341 1135connected_lookup_prefix (struct interface *ifp, struct prefix *addr)
727d104b 1136{
52dc7ee6 1137 struct listnode *cnode;
727d104b 1138 struct connected *c;
1139 struct connected *match;
1140
727d104b 1141 match = NULL;
1142
1eb8ef25 1143 for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
727d104b 1144 {
bd40c341
DS
1145 if (c->address && (c->address->family == addr->family) &&
1146 prefix_match(CONNECTED_PREFIX(c), addr) &&
e4529636
AS
1147 (!match || (c->address->prefixlen > match->address->prefixlen)))
1148 match = c;
727d104b 1149 }
1150 return match;
1151}
1152
4a7aac1b 1153struct connected *
1154connected_add_by_prefix (struct interface *ifp, struct prefix *p,
1155 struct prefix *destination)
1156{
1157 struct connected *ifc;
1158
1159 /* Allocate new connected address. */
1160 ifc = connected_new ();
1161 ifc->ifp = ifp;
1162
1163 /* Fetch interface address */
1164 ifc->address = prefix_new();
1165 memcpy (ifc->address, p, sizeof(struct prefix));
1166
1167 /* Fetch dest address */
3fb9cd6e 1168 if (destination)
1169 {
1170 ifc->destination = prefix_new();
1171 memcpy (ifc->destination, destination, sizeof(struct prefix));
1172 }
4a7aac1b 1173
1174 /* Add connected address to the interface. */
1175 listnode_add (ifp->connected, ifc);
1176 return ifc;
1177}
1178
8cc4198f 1179#if 0 /* this route_table of struct connected's is unused
1180 * however, it would be good to use a route_table rather than
1181 * a list..
1182 */
718e3744 1183/* Interface looking up by interface's address. */
718e3744 1184/* Interface's IPv4 address reverse lookup table. */
1185struct route_table *ifaddr_ipv4_table;
1186/* struct route_table *ifaddr_ipv6_table; */
1187
8cc4198f 1188static void
718e3744 1189ifaddr_ipv4_add (struct in_addr *ifaddr, struct interface *ifp)
1190{
1191 struct route_node *rn;
1192 struct prefix_ipv4 p;
1193
1194 p.family = AF_INET;
1195 p.prefixlen = IPV4_MAX_PREFIXLEN;
1196 p.prefix = *ifaddr;
1197
1198 rn = route_node_get (ifaddr_ipv4_table, (struct prefix *) &p);
1199 if (rn)
1200 {
1201 route_unlock_node (rn);
1202 zlog_info ("ifaddr_ipv4_add(): address %s is already added",
1203 inet_ntoa (*ifaddr));
1204 return;
1205 }
1206 rn->info = ifp;
1207}
1208
8cc4198f 1209static void
718e3744 1210ifaddr_ipv4_delete (struct in_addr *ifaddr, struct interface *ifp)
1211{
1212 struct route_node *rn;
1213 struct prefix_ipv4 p;
1214
1215 p.family = AF_INET;
1216 p.prefixlen = IPV4_MAX_PREFIXLEN;
1217 p.prefix = *ifaddr;
1218
1219 rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
1220 if (! rn)
1221 {
1222 zlog_info ("ifaddr_ipv4_delete(): can't find address %s",
1223 inet_ntoa (*ifaddr));
1224 return;
1225 }
1226 rn->info = NULL;
1227 route_unlock_node (rn);
1228 route_unlock_node (rn);
1229}
1230
1231/* Lookup interface by interface's IP address or interface index. */
8cc4198f 1232static struct interface *
b892f1dd 1233ifaddr_ipv4_lookup (struct in_addr *addr, ifindex_t ifindex)
718e3744 1234{
1235 struct prefix_ipv4 p;
1236 struct route_node *rn;
1237 struct interface *ifp;
718e3744 1238
1239 if (addr)
1240 {
1241 p.family = AF_INET;
1242 p.prefixlen = IPV4_MAX_PREFIXLEN;
1243 p.prefix = *addr;
1244
1245 rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
1246 if (! rn)
1247 return NULL;
1248
1249 ifp = rn->info;
1250 route_unlock_node (rn);
1251 return ifp;
1252 }
1253 else
d2fc8896 1254 return if_lookup_by_index(ifindex);
718e3744 1255}
8cc4198f 1256#endif /* ifaddr_ipv4_table */
718e3744 1257
1258/* Initialize interface list. */
1259void
b2d7c082 1260if_init (struct list **intf_list)
718e3744 1261{
8736158a 1262 *intf_list = list_new ();
8cc4198f 1263#if 0
718e3744 1264 ifaddr_ipv4_table = route_table_init ();
8cc4198f 1265#endif /* ifaddr_ipv4_table */
718e3744 1266
8736158a 1267 (*intf_list)->cmp = (int (*)(void *, void *))if_cmp_func;
718e3744 1268}
4bd045d5
TG
1269
1270void
b2d7c082 1271if_terminate (struct list **intf_list)
4bd045d5
TG
1272{
1273 for (;;)
1274 {
1275 struct interface *ifp;
1276
8736158a 1277 ifp = listnode_head (*intf_list);
4bd045d5
TG
1278 if (ifp == NULL)
1279 break;
1280
3f6d6a5d
DS
1281 if (ifp->node)
1282 {
1283 ifp->node->info = NULL;
1284 route_unlock_node (ifp->node);
1285 }
1286
4bd045d5
TG
1287 if_delete (ifp);
1288 }
1289
8736158a
FL
1290 list_delete (*intf_list);
1291 *intf_list = NULL;
4bd045d5 1292}
8ccc7e80
TT
1293
1294const char *
1295if_link_type_str (enum zebra_link_type llt)
1296{
1297 switch (llt)
1298 {
1299#define llts(T,S) case (T): return (S)
1300 llts(ZEBRA_LLT_UNKNOWN, "Unknown");
1301 llts(ZEBRA_LLT_ETHER, "Ethernet");
1302 llts(ZEBRA_LLT_EETHER, "Experimental Ethernet");
1303 llts(ZEBRA_LLT_AX25, "AX.25 Level 2");
1304 llts(ZEBRA_LLT_PRONET, "PROnet token ring");
1305 llts(ZEBRA_LLT_IEEE802, "IEEE 802.2 Ethernet/TR/TB");
1306 llts(ZEBRA_LLT_ARCNET, "ARCnet");
1307 llts(ZEBRA_LLT_APPLETLK, "AppleTalk");
1308 llts(ZEBRA_LLT_DLCI, "Frame Relay DLCI");
1309 llts(ZEBRA_LLT_ATM, "ATM");
1310 llts(ZEBRA_LLT_METRICOM, "Metricom STRIP");
1311 llts(ZEBRA_LLT_IEEE1394, "IEEE 1394 IPv4");
1312 llts(ZEBRA_LLT_EUI64, "EUI-64");
1313 llts(ZEBRA_LLT_INFINIBAND, "InfiniBand");
1314 llts(ZEBRA_LLT_SLIP, "SLIP");
1315 llts(ZEBRA_LLT_CSLIP, "Compressed SLIP");
1316 llts(ZEBRA_LLT_SLIP6, "SLIPv6");
1317 llts(ZEBRA_LLT_CSLIP6, "Compressed SLIPv6");
1318 llts(ZEBRA_LLT_ROSE, "ROSE packet radio");
1319 llts(ZEBRA_LLT_X25, "CCITT X.25");
1320 llts(ZEBRA_LLT_PPP, "PPP");
1321 llts(ZEBRA_LLT_CHDLC, "Cisco HDLC");
1322 llts(ZEBRA_LLT_RAWHDLC, "Raw HDLC");
1323 llts(ZEBRA_LLT_LAPB, "LAPB");
1324 llts(ZEBRA_LLT_IPIP, "IPIP Tunnel");
1325 llts(ZEBRA_LLT_IPIP6, "IPIP6 Tunnel");
1326 llts(ZEBRA_LLT_FRAD, "FRAD");
1327 llts(ZEBRA_LLT_SKIP, "SKIP vif");
1328 llts(ZEBRA_LLT_LOOPBACK, "Loopback");
1329 llts(ZEBRA_LLT_LOCALTLK, "Localtalk");
1330 llts(ZEBRA_LLT_FDDI, "FDDI");
1331 llts(ZEBRA_LLT_SIT, "IPv6-in-IPv4 SIT");
1332 llts(ZEBRA_LLT_IPDDP, "IP-in-DDP tunnel");
1333 llts(ZEBRA_LLT_IPGRE, "GRE over IP");
1334 llts(ZEBRA_LLT_PIMREG, "PIMSM registration");
1335 llts(ZEBRA_LLT_HIPPI, "HiPPI");
1336 llts(ZEBRA_LLT_IRDA, "IrDA");
1337 llts(ZEBRA_LLT_FCPP, "Fibre-Channel PtP");
1338 llts(ZEBRA_LLT_FCAL, "Fibre-Channel Arbitrated Loop");
1339 llts(ZEBRA_LLT_FCPL, "Fibre-Channel Public Loop");
1340 llts(ZEBRA_LLT_FCFABRIC, "Fibre-Channel Fabric");
1341 llts(ZEBRA_LLT_IEEE802_TR, "IEEE 802.2 Token Ring");
1342 llts(ZEBRA_LLT_IEEE80211, "IEEE 802.11");
1343 llts(ZEBRA_LLT_IEEE80211_RADIOTAP, "IEEE 802.11 Radiotap");
1344 llts(ZEBRA_LLT_IEEE802154, "IEEE 802.15.4");
1345 llts(ZEBRA_LLT_IEEE802154_PHY, "IEEE 802.15.4 Phy");
1346 default:
1347 zlog_warn ("Unknown value %d", llt);
1348 return "Unknown type!";
1349#undef llts
1350 }
1351 return NULL;
1352}
16f1b9ee
OD
1353
1354struct if_link_params *
1355if_link_params_get (struct interface *ifp)
1356{
1357 int i;
1358
1359 if (ifp->link_params != NULL)
1360 return ifp->link_params;
1361
1362 struct if_link_params *iflp = XCALLOC(MTYPE_IF_LINK_PARAMS,
1363 sizeof (struct if_link_params));
1364 if (iflp == NULL) return NULL;
1365
1366 /* Set TE metric == standard metric */
1367 iflp->te_metric = ifp->metric;
1368
1369 /* Compute default bandwidth based on interface */
1370 int bw = (float)((ifp->bandwidth ? ifp->bandwidth : DEFAULT_BANDWIDTH)
1371 * TE_KILO_BIT / TE_BYTE);
1372
1373 /* Set Max, Reservable and Unreserved Bandwidth */
1374 iflp->max_bw = bw;
1375 iflp->max_rsv_bw = bw;
1376 for (i = 0; i < MAX_CLASS_TYPE; i++)
1377 iflp->unrsv_bw[i] = bw;
1378
1379 /* Update Link parameters status */
1380 iflp->lp_status = LP_TE | LP_MAX_BW | LP_MAX_RSV_BW | LP_UNRSV_BW;
1381
1382 /* Finally attach newly created Link Parameters */
1383 ifp->link_params = iflp;
1384
1385 return iflp;
1386}
1387
1388void
1389if_link_params_free (struct interface *ifp)
1390{
1391 if (ifp->link_params == NULL) return;
1392 XFREE(MTYPE_IF_LINK_PARAMS, ifp->link_params);
1393 ifp->link_params = NULL;
1394}