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