]> git.proxmox.com Git - mirror_frr.git/blame - lib/if.c
lib: qobj: register ifaces, routemaps & keychains
[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{
718e3744 686 struct interface *ifp;
718e3744 687
688 if (argc == 0)
689 return CMD_SUCCESS;
690
691 ifp = vty->index;
692 if (ifp->desc)
3b8b1855 693 XFREE (MTYPE_TMP, ifp->desc);
694 ifp->desc = argv_concat(argv, argc, 0);
718e3744 695
696 return CMD_SUCCESS;
697}
698
699DEFUN (no_interface_desc,
700 no_interface_desc_cmd,
701 "no description",
702 NO_STR
703 "Interface specific description\n")
704{
705 struct interface *ifp;
706
707 ifp = vty->index;
708 if (ifp->desc)
0241684e 709 XFREE (MTYPE_TMP, ifp->desc);
718e3744 710 ifp->desc = NULL;
711
712 return CMD_SUCCESS;
713}
6b0655a2 714
98954844
PJ
715#ifdef SUNOS_5
716/* Need to handle upgrade from SUNWzebra to Quagga. SUNWzebra created
717 * a seperate struct interface for each logical interface, so config
718 * file may be full of 'interface fooX:Y'. Solaris however does not
719 * expose logical interfaces via PF_ROUTE, so trying to track logical
720 * interfaces can be fruitless, for that reason Quagga only tracks
721 * the primary IP interface.
722 *
723 * We try accomodate SUNWzebra by:
724 * - looking up the interface name, to see whether it exists, if so
725 * its useable
726 * - for protocol daemons, this could only because zebra told us of
727 * the interface
728 * - for zebra, only because it learnt from kernel
729 * - if not:
730 * - search the name to see if it contains a sub-ipif / logical interface
731 * seperator, the ':' char. If it does:
732 * - text up to that char must be the primary name - get that name.
733 * if not:
734 * - no idea, just get the name in its entirety.
735 */
736static struct interface *
8736158a 737if_sunwzebra_get (const char *name, size_t nlen, vrf_id_t vrf_id)
98954844
PJ
738{
739 struct interface *ifp;
740 size_t seppos = 0;
718e3744 741
8736158a 742 if ( (ifp = if_lookup_by_name_len_vrf (name, nlen, vrf_id)) != NULL)
98954844
PJ
743 return ifp;
744
745 /* hunt the primary interface name... */
746 while (seppos < nlen && name[seppos] != ':')
747 seppos++;
748
749 /* Wont catch seperator as last char, e.g. 'foo0:' but thats invalid */
750 if (seppos < nlen)
85f9da7f 751 return if_get_by_name_len_vrf (name, seppos, vrf_id, 1);
98954844 752 else
85f9da7f 753 return if_get_by_name_len_vrf (name, nlen, vrf_id, 1);
98954844
PJ
754}
755#endif /* SUNOS_5 */
6b0655a2 756
718e3744 757DEFUN (interface,
758 interface_cmd,
759 "interface IFNAME",
760 "Select an interface to configure\n"
761 "Interface's name\n")
762{
763 struct interface *ifp;
d2fc8896 764 size_t sl;
8736158a 765 vrf_id_t vrf_id = VRF_DEFAULT;
d2fc8896 766
767 if ((sl = strlen(argv[0])) > INTERFACE_NAMSIZ)
768 {
769 vty_out (vty, "%% Interface name %s is invalid: length exceeds "
770 "%d characters%s",
771 argv[0], INTERFACE_NAMSIZ, VTY_NEWLINE);
772 return CMD_WARNING;
773 }
718e3744 774
f93e3f69
DS
775/*Pending: need proper vrf name based lookup/(possible creation of VRF)
776 Imagine forward reference of a vrf by name in this interface config */
cd2a8a42 777 if (argc > 1)
f93e3f69 778 VRF_GET_ID (vrf_id, argv[1]);
cd2a8a42 779
98954844 780#ifdef SUNOS_5
8736158a 781 ifp = if_sunwzebra_get (argv[0], sl, vrf_id);
98954844 782#else
85f9da7f 783 ifp = if_get_by_name_len_vrf (argv[0], sl, vrf_id, 1);
98954844 784#endif /* SUNOS_5 */
718e3744 785
85f9da7f
DS
786 if (!ifp)
787 {
788 vty_out (vty, "%% interface %s not in %s%s", argv[0], argv[1], VTY_NEWLINE);
789 return CMD_WARNING;
790 }
718e3744 791 vty->index = ifp;
792 vty->node = INTERFACE_NODE;
793
794 return CMD_SUCCESS;
795}
796
cd2a8a42
FL
797ALIAS (interface,
798 interface_vrf_cmd,
799 "interface IFNAME " VRF_CMD_STR,
800 "Select an interface to configure\n"
801 "Interface's name\n"
802 VRF_CMD_HELP_STR)
803
32d2463c 804DEFUN_NOSH (no_interface,
805 no_interface_cmd,
806 "no interface IFNAME",
807 NO_STR
808 "Delete a pseudo interface's configuration\n"
809 "Interface's name\n")
810{
811 // deleting interface
812 struct interface *ifp;
8736158a 813 vrf_id_t vrf_id = VRF_DEFAULT;
32d2463c 814
cd2a8a42 815 if (argc > 1)
f93e3f69 816 VRF_GET_ID (vrf_id, argv[1]);
cd2a8a42 817
8736158a 818 ifp = if_lookup_by_name_vrf (argv[0], vrf_id);
32d2463c 819
820 if (ifp == NULL)
d2fc8896 821 {
822 vty_out (vty, "%% Interface %s does not exist%s", argv[0], VTY_NEWLINE);
823 return CMD_WARNING;
824 }
32d2463c 825
bfc13532 826 if (CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
d2fc8896 827 {
828 vty_out (vty, "%% Only inactive interfaces can be deleted%s",
829 VTY_NEWLINE);
830 return CMD_WARNING;
831 }
32d2463c 832
833 if_delete(ifp);
834
835 return CMD_SUCCESS;
836}
837
cd2a8a42
FL
838ALIAS (no_interface,
839 no_interface_vrf_cmd,
840 "no interface IFNAME " VRF_CMD_STR,
841 NO_STR
842 "Delete a pseudo interface's configuration\n"
843 "Interface's name\n"
844 VRF_CMD_HELP_STR)
845
f93e3f69
DS
846DEFUN (vrf,
847 vrf_cmd,
848 "vrf NAME",
849 "Select a VRF to configure\n"
850 "VRF's name\n")
851{
852 struct vrf *vrfp;
853 size_t sl;
854
855 if ((sl = strlen(argv[0])) > VRF_NAMSIZ)
856 {
857 vty_out (vty, "%% VRF name %s is invalid: length exceeds "
858 "%d characters%s",
859 argv[0], VRF_NAMSIZ, VTY_NEWLINE);
860 return CMD_WARNING;
861 }
862
58255d34 863 vrfp = vrf_get (VRF_UNKNOWN, argv[0]);
f93e3f69
DS
864
865 vty->index = vrfp;
866 vty->node = VRF_NODE;
867
868 return CMD_SUCCESS;
869}
870
871DEFUN_NOSH (no_vrf,
872 no_vrf_cmd,
873 "no vrf NAME",
874 NO_STR
875 "Delete a pseudo VRF's configuration\n"
876 "VRF's name\n")
877{
878 struct vrf *vrfp;
879
880 vrfp = vrf_list_lookup_by_name (argv[0]);
881
882 if (vrfp == NULL)
883 {
884 vty_out (vty, "%% VRF %s does not exist%s", argv[0], VTY_NEWLINE);
885 return CMD_WARNING;
886 }
887
79694123 888 if (CHECK_FLAG (vrfp->status, VRF_ACTIVE))
f93e3f69
DS
889 {
890 vty_out (vty, "%% Only inactive VRFs can be deleted%s",
891 VTY_NEWLINE);
892 return CMD_WARNING;
893 }
894
895 vrf_delete(vrfp);
896
897 return CMD_SUCCESS;
898}
899
900
718e3744 901/* For debug purpose. */
902DEFUN (show_address,
903 show_address_cmd,
904 "show address",
905 SHOW_STR
906 "address\n")
907{
52dc7ee6 908 struct listnode *node;
909 struct listnode *node2;
718e3744 910 struct interface *ifp;
911 struct connected *ifc;
912 struct prefix *p;
8736158a 913 vrf_id_t vrf_id = VRF_DEFAULT;
718e3744 914
8736158a 915 if (argc > 0)
f93e3f69 916 VRF_GET_ID (vrf_id, argv[0]);
8736158a
FL
917
918 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp))
718e3744 919 {
1eb8ef25 920 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc))
718e3744 921 {
718e3744 922 p = ifc->address;
923
924 if (p->family == AF_INET)
925 vty_out (vty, "%s/%d%s", inet_ntoa (p->u.prefix4), p->prefixlen,
926 VTY_NEWLINE);
927 }
928 }
929 return CMD_SUCCESS;
930}
931
8736158a
FL
932ALIAS (show_address,
933 show_address_vrf_cmd,
934 "show address " VRF_CMD_STR,
935 SHOW_STR
936 "address\n"
937 VRF_CMD_HELP_STR)
938
939DEFUN (show_address_vrf_all,
940 show_address_vrf_all_cmd,
941 "show address " VRF_ALL_CMD_STR,
942 SHOW_STR
943 "address\n"
944 VRF_ALL_CMD_HELP_STR)
945{
946 struct list *intf_list;
947 struct listnode *node;
948 struct listnode *node2;
949 struct interface *ifp;
950 struct connected *ifc;
951 struct prefix *p;
952 vrf_iter_t iter;
953
954 for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter))
955 {
956 intf_list = vrf_iter2iflist (iter);
957 if (!intf_list || !listcount (intf_list))
958 continue;
959
960 vty_out (vty, "%sVRF %u%s%s", VTY_NEWLINE, vrf_iter2id (iter),
961 VTY_NEWLINE, VTY_NEWLINE);
962
963 for (ALL_LIST_ELEMENTS_RO (intf_list, node, ifp))
964 {
965 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc))
966 {
967 p = ifc->address;
968
969 if (p->family == AF_INET)
970 vty_out (vty, "%s/%d%s", inet_ntoa (p->u.prefix4), p->prefixlen,
971 VTY_NEWLINE);
972 }
973 }
974 }
975 return CMD_SUCCESS;
976}
977
718e3744 978/* Allocate connected structure. */
979struct connected *
8cc4198f 980connected_new (void)
718e3744 981{
393deb9b 982 return XCALLOC (MTYPE_CONNECTED, sizeof (struct connected));
718e3744 983}
984
a80beece
DS
985/* Allocate nbr connected structure. */
986struct nbr_connected *
987nbr_connected_new (void)
988{
989 return XCALLOC (MTYPE_NBR_CONNECTED, sizeof (struct nbr_connected));
990}
991
718e3744 992/* Free connected structure. */
993void
994connected_free (struct connected *connected)
995{
996 if (connected->address)
997 prefix_free (connected->address);
998
999 if (connected->destination)
1000 prefix_free (connected->destination);
1001
1002 if (connected->label)
9c4f1c6f 1003 XFREE (MTYPE_CONNECTED_LABEL, connected->label);
718e3744 1004
1005 XFREE (MTYPE_CONNECTED, connected);
1006}
1007
a80beece
DS
1008/* Free nbr connected structure. */
1009void
1010nbr_connected_free (struct nbr_connected *connected)
1011{
1012 if (connected->address)
1013 prefix_free (connected->address);
1014
1015 XFREE (MTYPE_NBR_CONNECTED, connected);
1016}
1017
1018/* If same interface nbr address already exists... */
1019struct nbr_connected *
1020nbr_connected_check (struct interface *ifp, struct prefix *p)
1021{
1022 struct nbr_connected *ifc;
1023 struct listnode *node;
1024
1025 for (ALL_LIST_ELEMENTS_RO (ifp->nbr_connected, node, ifc))
1026 if (prefix_same (ifc->address, p))
1027 return ifc;
1028
1029 return NULL;
1030}
1031
718e3744 1032/* Print if_addr structure. */
8cc4198f 1033static void __attribute__ ((unused))
718e3744 1034connected_log (struct connected *connected, char *str)
1035{
1036 struct prefix *p;
1037 struct interface *ifp;
1038 char logbuf[BUFSIZ];
1039 char buf[BUFSIZ];
1040
1041 ifp = connected->ifp;
1042 p = connected->address;
1043
3968dbf8
FL
1044 snprintf (logbuf, BUFSIZ, "%s interface %s vrf %u %s %s/%d ",
1045 str, ifp->name, ifp->vrf_id, prefix_family_str (p),
718e3744 1046 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1047 p->prefixlen);
1048
1049 p = connected->destination;
1050 if (p)
1051 {
1052 strncat (logbuf, inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1053 BUFSIZ - strlen(logbuf));
1054 }
fc95186c 1055 zlog (NULL, LOG_INFO, "%s", logbuf);
718e3744 1056}
1057
a80beece
DS
1058/* Print if_addr structure. */
1059static void __attribute__ ((unused))
1060nbr_connected_log (struct nbr_connected *connected, char *str)
1061{
1062 struct prefix *p;
1063 struct interface *ifp;
1064 char logbuf[BUFSIZ];
1065 char buf[BUFSIZ];
1066
1067 ifp = connected->ifp;
1068 p = connected->address;
1069
1070 snprintf (logbuf, BUFSIZ, "%s interface %s %s %s/%d ",
1071 str, ifp->name, prefix_family_str (p),
1072 inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
1073 p->prefixlen);
1074
1075 zlog (NULL, LOG_INFO, "%s", logbuf);
1076}
1077
718e3744 1078/* If two connected address has same prefix return 1. */
8cc4198f 1079static int
718e3744 1080connected_same_prefix (struct prefix *p1, struct prefix *p2)
1081{
1082 if (p1->family == p2->family)
1083 {
1084 if (p1->family == AF_INET &&
1085 IPV4_ADDR_SAME (&p1->u.prefix4, &p2->u.prefix4))
1086 return 1;
1087#ifdef HAVE_IPV6
1088 if (p1->family == AF_INET6 &&
1089 IPV6_ADDR_SAME (&p1->u.prefix6, &p2->u.prefix6))
1090 return 1;
1091#endif /* HAVE_IPV6 */
1092 }
1093 return 0;
1094}
1095
38485402
DS
1096struct connected *
1097connected_lookup_prefix_exact (struct interface *ifp, struct prefix *p)
1098{
1099 struct listnode *node;
1100 struct listnode *next;
1101 struct connected *ifc;
1102
1103 for (node = listhead (ifp->connected); node; node = next)
1104 {
1105 ifc = listgetdata (node);
1106 next = node->next;
1107
1108 if (connected_same_prefix (ifc->address, p))
1109 return ifc;
1110 }
1111 return NULL;
1112}
1113
718e3744 1114struct connected *
1115connected_delete_by_prefix (struct interface *ifp, struct prefix *p)
1116{
1117 struct listnode *node;
1118 struct listnode *next;
1119 struct connected *ifc;
1120
1121 /* In case of same prefix come, replace it with new one. */
1122 for (node = listhead (ifp->connected); node; node = next)
1123 {
1eb8ef25 1124 ifc = listgetdata (node);
718e3744 1125 next = node->next;
1126
1127 if (connected_same_prefix (ifc->address, p))
1128 {
1129 listnode_delete (ifp->connected, ifc);
1130 return ifc;
1131 }
1132 }
1133 return NULL;
1134}
1135
bd40c341 1136/* Find the address on our side that will be used when packets
727d104b 1137 are sent to dst. */
1138struct connected *
bd40c341 1139connected_lookup_prefix (struct interface *ifp, struct prefix *addr)
727d104b 1140{
52dc7ee6 1141 struct listnode *cnode;
727d104b 1142 struct connected *c;
1143 struct connected *match;
1144
727d104b 1145 match = NULL;
1146
1eb8ef25 1147 for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
727d104b 1148 {
bd40c341
DS
1149 if (c->address && (c->address->family == addr->family) &&
1150 prefix_match(CONNECTED_PREFIX(c), addr) &&
e4529636
AS
1151 (!match || (c->address->prefixlen > match->address->prefixlen)))
1152 match = c;
727d104b 1153 }
1154 return match;
1155}
1156
4a7aac1b 1157struct connected *
1158connected_add_by_prefix (struct interface *ifp, struct prefix *p,
1159 struct prefix *destination)
1160{
1161 struct connected *ifc;
1162
1163 /* Allocate new connected address. */
1164 ifc = connected_new ();
1165 ifc->ifp = ifp;
1166
1167 /* Fetch interface address */
1168 ifc->address = prefix_new();
1169 memcpy (ifc->address, p, sizeof(struct prefix));
1170
1171 /* Fetch dest address */
3fb9cd6e 1172 if (destination)
1173 {
1174 ifc->destination = prefix_new();
1175 memcpy (ifc->destination, destination, sizeof(struct prefix));
1176 }
4a7aac1b 1177
1178 /* Add connected address to the interface. */
1179 listnode_add (ifp->connected, ifc);
1180 return ifc;
1181}
1182
718e3744 1183#ifndef HAVE_IF_NAMETOINDEX
b892f1dd 1184ifindex_t
718e3744 1185if_nametoindex (const char *name)
1186{
718e3744 1187 struct interface *ifp;
1188
018546e9 1189 return ((ifp = if_lookup_by_name_len(name, strnlen(name, IFNAMSIZ))) != NULL)
1190 ? ifp->ifindex : 0;
718e3744 1191}
1192#endif
1193
1194#ifndef HAVE_IF_INDEXTONAME
1195char *
b892f1dd 1196if_indextoname (ifindex_t ifindex, char *name)
718e3744 1197{
718e3744 1198 struct interface *ifp;
1199
d2fc8896 1200 if (!(ifp = if_lookup_by_index(ifindex)))
1201 return NULL;
1202 strncpy (name, ifp->name, IFNAMSIZ);
1203 return ifp->name;
718e3744 1204}
1205#endif
6b0655a2 1206
8cc4198f 1207#if 0 /* this route_table of struct connected's is unused
1208 * however, it would be good to use a route_table rather than
1209 * a list..
1210 */
718e3744 1211/* Interface looking up by interface's address. */
718e3744 1212/* Interface's IPv4 address reverse lookup table. */
1213struct route_table *ifaddr_ipv4_table;
1214/* struct route_table *ifaddr_ipv6_table; */
1215
8cc4198f 1216static void
718e3744 1217ifaddr_ipv4_add (struct in_addr *ifaddr, struct interface *ifp)
1218{
1219 struct route_node *rn;
1220 struct prefix_ipv4 p;
1221
1222 p.family = AF_INET;
1223 p.prefixlen = IPV4_MAX_PREFIXLEN;
1224 p.prefix = *ifaddr;
1225
1226 rn = route_node_get (ifaddr_ipv4_table, (struct prefix *) &p);
1227 if (rn)
1228 {
1229 route_unlock_node (rn);
1230 zlog_info ("ifaddr_ipv4_add(): address %s is already added",
1231 inet_ntoa (*ifaddr));
1232 return;
1233 }
1234 rn->info = ifp;
1235}
1236
8cc4198f 1237static void
718e3744 1238ifaddr_ipv4_delete (struct in_addr *ifaddr, struct interface *ifp)
1239{
1240 struct route_node *rn;
1241 struct prefix_ipv4 p;
1242
1243 p.family = AF_INET;
1244 p.prefixlen = IPV4_MAX_PREFIXLEN;
1245 p.prefix = *ifaddr;
1246
1247 rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
1248 if (! rn)
1249 {
1250 zlog_info ("ifaddr_ipv4_delete(): can't find address %s",
1251 inet_ntoa (*ifaddr));
1252 return;
1253 }
1254 rn->info = NULL;
1255 route_unlock_node (rn);
1256 route_unlock_node (rn);
1257}
1258
1259/* Lookup interface by interface's IP address or interface index. */
8cc4198f 1260static struct interface *
b892f1dd 1261ifaddr_ipv4_lookup (struct in_addr *addr, ifindex_t ifindex)
718e3744 1262{
1263 struct prefix_ipv4 p;
1264 struct route_node *rn;
1265 struct interface *ifp;
718e3744 1266
1267 if (addr)
1268 {
1269 p.family = AF_INET;
1270 p.prefixlen = IPV4_MAX_PREFIXLEN;
1271 p.prefix = *addr;
1272
1273 rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
1274 if (! rn)
1275 return NULL;
1276
1277 ifp = rn->info;
1278 route_unlock_node (rn);
1279 return ifp;
1280 }
1281 else
d2fc8896 1282 return if_lookup_by_index(ifindex);
718e3744 1283}
8cc4198f 1284#endif /* ifaddr_ipv4_table */
718e3744 1285
1286/* Initialize interface list. */
1287void
b2d7c082 1288if_init (struct list **intf_list)
718e3744 1289{
8736158a 1290 *intf_list = list_new ();
8cc4198f 1291#if 0
718e3744 1292 ifaddr_ipv4_table = route_table_init ();
8cc4198f 1293#endif /* ifaddr_ipv4_table */
718e3744 1294
8736158a 1295 (*intf_list)->cmp = (int (*)(void *, void *))if_cmp_func;
718e3744 1296}
4bd045d5
TG
1297
1298void
b2d7c082 1299if_terminate (struct list **intf_list)
4bd045d5
TG
1300{
1301 for (;;)
1302 {
1303 struct interface *ifp;
1304
8736158a 1305 ifp = listnode_head (*intf_list);
4bd045d5
TG
1306 if (ifp == NULL)
1307 break;
1308
3f6d6a5d
DS
1309 if (ifp->node)
1310 {
1311 ifp->node->info = NULL;
1312 route_unlock_node (ifp->node);
1313 }
1314
4bd045d5
TG
1315 if_delete (ifp);
1316 }
1317
8736158a
FL
1318 list_delete (*intf_list);
1319 *intf_list = NULL;
4bd045d5 1320}
8ccc7e80
TT
1321
1322const char *
1323if_link_type_str (enum zebra_link_type llt)
1324{
1325 switch (llt)
1326 {
1327#define llts(T,S) case (T): return (S)
1328 llts(ZEBRA_LLT_UNKNOWN, "Unknown");
1329 llts(ZEBRA_LLT_ETHER, "Ethernet");
1330 llts(ZEBRA_LLT_EETHER, "Experimental Ethernet");
1331 llts(ZEBRA_LLT_AX25, "AX.25 Level 2");
1332 llts(ZEBRA_LLT_PRONET, "PROnet token ring");
1333 llts(ZEBRA_LLT_IEEE802, "IEEE 802.2 Ethernet/TR/TB");
1334 llts(ZEBRA_LLT_ARCNET, "ARCnet");
1335 llts(ZEBRA_LLT_APPLETLK, "AppleTalk");
1336 llts(ZEBRA_LLT_DLCI, "Frame Relay DLCI");
1337 llts(ZEBRA_LLT_ATM, "ATM");
1338 llts(ZEBRA_LLT_METRICOM, "Metricom STRIP");
1339 llts(ZEBRA_LLT_IEEE1394, "IEEE 1394 IPv4");
1340 llts(ZEBRA_LLT_EUI64, "EUI-64");
1341 llts(ZEBRA_LLT_INFINIBAND, "InfiniBand");
1342 llts(ZEBRA_LLT_SLIP, "SLIP");
1343 llts(ZEBRA_LLT_CSLIP, "Compressed SLIP");
1344 llts(ZEBRA_LLT_SLIP6, "SLIPv6");
1345 llts(ZEBRA_LLT_CSLIP6, "Compressed SLIPv6");
1346 llts(ZEBRA_LLT_ROSE, "ROSE packet radio");
1347 llts(ZEBRA_LLT_X25, "CCITT X.25");
1348 llts(ZEBRA_LLT_PPP, "PPP");
1349 llts(ZEBRA_LLT_CHDLC, "Cisco HDLC");
1350 llts(ZEBRA_LLT_RAWHDLC, "Raw HDLC");
1351 llts(ZEBRA_LLT_LAPB, "LAPB");
1352 llts(ZEBRA_LLT_IPIP, "IPIP Tunnel");
1353 llts(ZEBRA_LLT_IPIP6, "IPIP6 Tunnel");
1354 llts(ZEBRA_LLT_FRAD, "FRAD");
1355 llts(ZEBRA_LLT_SKIP, "SKIP vif");
1356 llts(ZEBRA_LLT_LOOPBACK, "Loopback");
1357 llts(ZEBRA_LLT_LOCALTLK, "Localtalk");
1358 llts(ZEBRA_LLT_FDDI, "FDDI");
1359 llts(ZEBRA_LLT_SIT, "IPv6-in-IPv4 SIT");
1360 llts(ZEBRA_LLT_IPDDP, "IP-in-DDP tunnel");
1361 llts(ZEBRA_LLT_IPGRE, "GRE over IP");
1362 llts(ZEBRA_LLT_PIMREG, "PIMSM registration");
1363 llts(ZEBRA_LLT_HIPPI, "HiPPI");
1364 llts(ZEBRA_LLT_IRDA, "IrDA");
1365 llts(ZEBRA_LLT_FCPP, "Fibre-Channel PtP");
1366 llts(ZEBRA_LLT_FCAL, "Fibre-Channel Arbitrated Loop");
1367 llts(ZEBRA_LLT_FCPL, "Fibre-Channel Public Loop");
1368 llts(ZEBRA_LLT_FCFABRIC, "Fibre-Channel Fabric");
1369 llts(ZEBRA_LLT_IEEE802_TR, "IEEE 802.2 Token Ring");
1370 llts(ZEBRA_LLT_IEEE80211, "IEEE 802.11");
1371 llts(ZEBRA_LLT_IEEE80211_RADIOTAP, "IEEE 802.11 Radiotap");
1372 llts(ZEBRA_LLT_IEEE802154, "IEEE 802.15.4");
1373 llts(ZEBRA_LLT_IEEE802154_PHY, "IEEE 802.15.4 Phy");
1374 default:
1375 zlog_warn ("Unknown value %d", llt);
1376 return "Unknown type!";
1377#undef llts
1378 }
1379 return NULL;
1380}
16f1b9ee
OD
1381
1382struct if_link_params *
1383if_link_params_get (struct interface *ifp)
1384{
1385 int i;
1386
1387 if (ifp->link_params != NULL)
1388 return ifp->link_params;
1389
1390 struct if_link_params *iflp = XCALLOC(MTYPE_IF_LINK_PARAMS,
1391 sizeof (struct if_link_params));
1392 if (iflp == NULL) return NULL;
1393
1394 /* Set TE metric == standard metric */
1395 iflp->te_metric = ifp->metric;
1396
1397 /* Compute default bandwidth based on interface */
1398 int bw = (float)((ifp->bandwidth ? ifp->bandwidth : DEFAULT_BANDWIDTH)
1399 * TE_KILO_BIT / TE_BYTE);
1400
1401 /* Set Max, Reservable and Unreserved Bandwidth */
1402 iflp->max_bw = bw;
1403 iflp->max_rsv_bw = bw;
1404 for (i = 0; i < MAX_CLASS_TYPE; i++)
1405 iflp->unrsv_bw[i] = bw;
1406
1407 /* Update Link parameters status */
1408 iflp->lp_status = LP_TE | LP_MAX_BW | LP_MAX_RSV_BW | LP_UNRSV_BW;
1409
1410 /* Finally attach newly created Link Parameters */
1411 ifp->link_params = iflp;
1412
1413 return iflp;
1414}
1415
1416void
1417if_link_params_free (struct interface *ifp)
1418{
1419 if (ifp->link_params == NULL) return;
1420 XFREE(MTYPE_IF_LINK_PARAMS, ifp->link_params);
1421 ifp->link_params = NULL;
1422}