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