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