2 * Copyright (C) 2016 Volta Networks, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
30 #include "zebra/debug.h"
31 #include "zebra/rib.h"
32 #include "zebra/zebra_router.h"
33 #include "zebra/zapi_msg.h"
34 #include "zebra/zebra_rnh.h"
35 #include "zebra/zebra_vrf.h"
36 #include "zebra/zebra_pw.h"
38 DEFINE_MTYPE_STATIC(LIB
, PW
, "Pseudowire");
40 DEFINE_QOBJ_TYPE(zebra_pw
);
42 DEFINE_HOOK(pw_install
, (struct zebra_pw
* pw
), (pw
));
43 DEFINE_HOOK(pw_uninstall
, (struct zebra_pw
* pw
), (pw
));
45 #define MPLS_NO_LABEL MPLS_INVALID_LABEL
47 static int zebra_pw_enabled(struct zebra_pw
*);
48 static void zebra_pw_install(struct zebra_pw
*);
49 static void zebra_pw_uninstall(struct zebra_pw
*);
50 static void zebra_pw_install_retry(struct thread
*thread
);
51 static int zebra_pw_check_reachability(const struct zebra_pw
*);
52 static void zebra_pw_update_status(struct zebra_pw
*, int);
54 static inline int zebra_pw_compare(const struct zebra_pw
*a
,
55 const struct zebra_pw
*b
)
57 return (strcmp(a
->ifname
, b
->ifname
));
60 RB_GENERATE(zebra_pw_head
, zebra_pw
, pw_entry
, zebra_pw_compare
)
61 RB_GENERATE(zebra_static_pw_head
, zebra_pw
, static_pw_entry
, zebra_pw_compare
)
63 struct zebra_pw
*zebra_pw_add(struct zebra_vrf
*zvrf
, const char *ifname
,
64 uint8_t protocol
, struct zserv
*client
)
68 if (IS_ZEBRA_DEBUG_PW
)
69 zlog_debug("%u: adding pseudowire %s protocol %s",
70 zvrf_id(zvrf
), ifname
, zebra_route_string(protocol
));
72 pw
= XCALLOC(MTYPE_PW
, sizeof(*pw
));
73 strlcpy(pw
->ifname
, ifname
, sizeof(pw
->ifname
));
74 pw
->protocol
= protocol
;
75 pw
->vrf_id
= zvrf_id(zvrf
);
77 pw
->status
= PW_NOT_FORWARDING
;
78 pw
->local_label
= MPLS_NO_LABEL
;
79 pw
->remote_label
= MPLS_NO_LABEL
;
80 pw
->flags
= F_PSEUDOWIRE_CWORD
;
82 RB_INSERT(zebra_pw_head
, &zvrf
->pseudowires
, pw
);
83 if (pw
->protocol
== ZEBRA_ROUTE_STATIC
) {
84 RB_INSERT(zebra_static_pw_head
, &zvrf
->static_pseudowires
, pw
);
85 QOBJ_REG(pw
, zebra_pw
);
91 void zebra_pw_del(struct zebra_vrf
*zvrf
, struct zebra_pw
*pw
)
93 if (IS_ZEBRA_DEBUG_PW
)
94 zlog_debug("%u: deleting pseudowire %s protocol %s", pw
->vrf_id
,
95 pw
->ifname
, zebra_route_string(pw
->protocol
));
97 /* remove nexthop tracking */
98 zebra_deregister_rnh_pseudowire(pw
->vrf_id
, pw
);
101 if (pw
->status
== PW_FORWARDING
) {
102 hook_call(pw_uninstall
, pw
);
103 dplane_pw_uninstall(pw
);
106 THREAD_OFF(pw
->install_retry_timer
);
108 /* unlink and release memory */
109 RB_REMOVE(zebra_pw_head
, &zvrf
->pseudowires
, pw
);
110 if (pw
->protocol
== ZEBRA_ROUTE_STATIC
)
111 RB_REMOVE(zebra_static_pw_head
, &zvrf
->static_pseudowires
, pw
);
116 void zebra_pw_change(struct zebra_pw
*pw
, ifindex_t ifindex
, int type
, int af
,
117 union g_addr
*nexthop
, uint32_t local_label
,
118 uint32_t remote_label
, uint8_t flags
,
119 union pw_protocol_fields
*data
)
121 pw
->ifindex
= ifindex
;
124 pw
->nexthop
= *nexthop
;
125 pw
->local_label
= local_label
;
126 pw
->remote_label
= remote_label
;
130 if (zebra_pw_enabled(pw
)) {
132 zebra_register_rnh_pseudowire(pw
->vrf_id
, pw
, &nht_exists
);
136 if (pw
->protocol
== ZEBRA_ROUTE_STATIC
)
137 zebra_deregister_rnh_pseudowire(pw
->vrf_id
, pw
);
138 zebra_pw_uninstall(pw
);
142 struct zebra_pw
*zebra_pw_find(struct zebra_vrf
*zvrf
, const char *ifname
)
145 strlcpy(pw
.ifname
, ifname
, sizeof(pw
.ifname
));
146 return (RB_FIND(zebra_pw_head
, &zvrf
->pseudowires
, &pw
));
149 static int zebra_pw_enabled(struct zebra_pw
*pw
)
151 if (pw
->protocol
== ZEBRA_ROUTE_STATIC
) {
152 if (pw
->local_label
== MPLS_NO_LABEL
153 || pw
->remote_label
== MPLS_NO_LABEL
|| pw
->af
== AF_UNSPEC
)
160 void zebra_pw_update(struct zebra_pw
*pw
)
162 if (zebra_pw_check_reachability(pw
) < 0) {
163 zebra_pw_uninstall(pw
);
164 zebra_pw_install_failure(pw
, PW_NOT_FORWARDING
);
165 /* wait for NHT and try again later */
168 * Install or reinstall the pseudowire (e.g. to update
169 * parameters like the nexthop or the use of the control word).
171 zebra_pw_install(pw
);
175 static void zebra_pw_install(struct zebra_pw
*pw
)
177 if (IS_ZEBRA_DEBUG_PW
)
178 zlog_debug("%u: installing pseudowire %s protocol %s",
179 pw
->vrf_id
, pw
->ifname
,
180 zebra_route_string(pw
->protocol
));
182 hook_call(pw_install
, pw
);
183 if (dplane_pw_install(pw
) == ZEBRA_DPLANE_REQUEST_FAILURE
) {
184 zebra_pw_install_failure(pw
, PW_NOT_FORWARDING
);
188 if (pw
->status
!= PW_FORWARDING
)
189 zebra_pw_update_status(pw
, PW_FORWARDING
);
192 static void zebra_pw_uninstall(struct zebra_pw
*pw
)
194 if (pw
->status
!= PW_FORWARDING
)
197 if (IS_ZEBRA_DEBUG_PW
)
198 zlog_debug("%u: uninstalling pseudowire %s protocol %s",
199 pw
->vrf_id
, pw
->ifname
,
200 zebra_route_string(pw
->protocol
));
202 /* ignore any possible error */
203 hook_call(pw_uninstall
, pw
);
204 dplane_pw_uninstall(pw
);
206 if (zebra_pw_enabled(pw
))
207 zebra_pw_update_status(pw
, PW_NOT_FORWARDING
);
211 * Installation of the pseudowire in the kernel or hardware has failed. This
212 * function will notify the pseudowire client about the failure and schedule
213 * to retry the installation later. This function can be called by an external
214 * agent that performs the pseudowire installation in an asynchronous way.
216 void zebra_pw_install_failure(struct zebra_pw
*pw
, int pwstatus
)
218 if (IS_ZEBRA_DEBUG_PW
)
220 "%u: failed installing pseudowire %s, scheduling retry in %u seconds",
221 pw
->vrf_id
, pw
->ifname
, PW_INSTALL_RETRY_INTERVAL
);
223 /* schedule to retry later */
224 THREAD_OFF(pw
->install_retry_timer
);
225 thread_add_timer(zrouter
.master
, zebra_pw_install_retry
, pw
,
226 PW_INSTALL_RETRY_INTERVAL
, &pw
->install_retry_timer
);
228 zebra_pw_update_status(pw
, pwstatus
);
231 static void zebra_pw_install_retry(struct thread
*thread
)
233 struct zebra_pw
*pw
= THREAD_ARG(thread
);
235 zebra_pw_install(pw
);
238 static void zebra_pw_update_status(struct zebra_pw
*pw
, int status
)
242 zsend_pw_update(pw
->client
, pw
);
245 static int zebra_pw_check_reachability_strict(const struct zebra_pw
*pw
,
246 struct route_entry
*re
)
248 const struct nexthop
*nexthop
;
249 const struct nexthop_group
*nhg
;
250 bool found_p
= false;
253 /* TODO: consider GRE/L2TPv3 tunnels in addition to MPLS LSPs */
255 /* All active nexthops must be labelled; look at
256 * primary and backup fib lists, in case there's been
257 * a backup nexthop activation.
259 nhg
= rib_get_fib_nhg(re
);
260 if (nhg
&& nhg
->nexthop
) {
261 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
262 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
265 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
)) {
266 if (nexthop
->nh_label
!= NULL
)
279 nhg
= rib_get_fib_backup_nhg(re
);
280 if (nhg
&& nhg
->nexthop
) {
281 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
282 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
285 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
)) {
286 if (nexthop
->nh_label
!= NULL
)
298 if (fail_p
|| !found_p
) {
299 if (IS_ZEBRA_DEBUG_PW
)
300 zlog_debug("%s: unlabeled route for %s",
301 __func__
, pw
->ifname
);
308 static int zebra_pw_check_reachability(const struct zebra_pw
*pw
)
310 struct route_entry
*re
;
311 const struct nexthop
*nexthop
;
312 const struct nexthop_group
*nhg
;
313 bool found_p
= false;
315 /* TODO: consider GRE/L2TPv3 tunnels in addition to MPLS LSPs */
317 /* Find route to the remote end of the pseudowire */
318 re
= rib_match(family2afi(pw
->af
), SAFI_UNICAST
, pw
->vrf_id
,
321 if (IS_ZEBRA_DEBUG_PW
)
322 zlog_debug("%s: no route found for %s", __func__
,
327 /* Stricter checking for some OSes (OBSD, e.g.) */
328 if (mpls_pw_reach_strict
)
329 return zebra_pw_check_reachability_strict(pw
, re
);
331 /* There must be at least one installed labelled nexthop;
332 * look at primary and backup fib lists, in case there's been
333 * a backup nexthop activation.
335 nhg
= rib_get_fib_nhg(re
);
336 if (nhg
&& nhg
->nexthop
) {
337 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
338 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
341 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
) &&
342 nexthop
->nh_label
!= NULL
) {
352 nhg
= rib_get_fib_backup_nhg(re
);
353 if (nhg
&& nhg
->nexthop
) {
354 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
355 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_RECURSIVE
))
358 if (CHECK_FLAG(nexthop
->flags
, NEXTHOP_FLAG_ACTIVE
) &&
359 nexthop
->nh_label
!= NULL
) {
367 if (IS_ZEBRA_DEBUG_PW
)
368 zlog_debug("%s: unlabeled route for %s",
369 __func__
, pw
->ifname
);
376 static int zebra_pw_client_close(struct zserv
*client
)
379 struct zebra_vrf
*zvrf
;
380 struct zebra_pw
*pw
, *tmp
;
382 RB_FOREACH (vrf
, vrf_id_head
, &vrfs_by_id
) {
384 RB_FOREACH_SAFE (pw
, zebra_pw_head
, &zvrf
->pseudowires
, tmp
) {
385 if (pw
->client
!= client
)
387 zebra_pw_del(zvrf
, pw
);
394 void zebra_pw_init(struct zebra_vrf
*zvrf
)
396 RB_INIT(zebra_pw_head
, &zvrf
->pseudowires
);
397 RB_INIT(zebra_static_pw_head
, &zvrf
->static_pseudowires
);
399 hook_register(zserv_client_close
, zebra_pw_client_close
);
402 void zebra_pw_exit(struct zebra_vrf
*zvrf
)
406 while (!RB_EMPTY(zebra_pw_head
, &zvrf
->pseudowires
)) {
407 pw
= RB_ROOT(zebra_pw_head
, &zvrf
->pseudowires
);
409 zebra_pw_del(zvrf
, pw
);
413 DEFUN_NOSH (pseudowire_if
,
416 "Static pseudowire configuration\n"
419 struct zebra_vrf
*zvrf
;
424 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
428 argv_find(argv
, argc
, "IFNAME", &idx
);
429 ifname
= argv
[idx
]->arg
;
431 pw
= zebra_pw_find(zvrf
, ifname
);
432 if (pw
&& pw
->protocol
!= ZEBRA_ROUTE_STATIC
) {
433 vty_out(vty
, "%% Pseudowire is not static\n");
438 pw
= zebra_pw_add(zvrf
, ifname
, ZEBRA_ROUTE_STATIC
, NULL
);
439 VTY_PUSH_CONTEXT(PW_NODE
, pw
);
444 DEFUN (no_pseudowire_if
,
445 no_pseudowire_if_cmd
,
446 "no pseudowire IFNAME",
448 "Static pseudowire configuration\n"
451 struct zebra_vrf
*zvrf
;
456 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
460 argv_find(argv
, argc
, "IFNAME", &idx
);
461 ifname
= argv
[idx
]->arg
;
463 pw
= zebra_pw_find(zvrf
, ifname
);
465 if (pw
->protocol
!= ZEBRA_ROUTE_STATIC
) {
466 vty_out(vty
, "%% Pseudowire is not static\n");
469 zebra_pw_del(zvrf
, pw
);
475 DEFUN (pseudowire_labels
,
476 pseudowire_labels_cmd
,
477 "[no] mpls label local (16-1048575) remote (16-1048575)",
479 "MPLS L2VPN PW command\n"
480 "MPLS L2VPN static labels\n"
481 "Local pseudowire label\n"
482 "Local pseudowire label\n"
483 "Remote pseudowire label\n"
484 "Remote pseudowire label\n")
486 VTY_DECLVAR_CONTEXT(zebra_pw
, pw
);
488 mpls_label_t local_label
, remote_label
;
490 if (argv_find(argv
, argc
, "no", &idx
)) {
491 local_label
= MPLS_NO_LABEL
;
492 remote_label
= MPLS_NO_LABEL
;
494 argv_find(argv
, argc
, "local", &idx
);
495 local_label
= atoi(argv
[idx
+ 1]->arg
);
496 argv_find(argv
, argc
, "remote", &idx
);
497 remote_label
= atoi(argv
[idx
+ 1]->arg
);
500 zebra_pw_change(pw
, pw
->ifindex
, pw
->type
, pw
->af
, &pw
->nexthop
,
501 local_label
, remote_label
, pw
->flags
, &pw
->data
);
506 DEFUN (pseudowire_neighbor
,
507 pseudowire_neighbor_cmd
,
508 "[no] neighbor <A.B.C.D|X:X::X:X>",
510 "Specify the IPv4 or IPv6 address of the remote endpoint\n"
514 VTY_DECLVAR_CONTEXT(zebra_pw
, pw
);
518 union g_addr nexthop
;
521 memset(&nexthop
, 0, sizeof(nexthop
));
523 if (!argv_find(argv
, argc
, "no", &idx
)) {
524 argv_find(argv
, argc
, "neighbor", &idx
);
525 address
= argv
[idx
+ 1]->arg
;
527 if (inet_pton(AF_INET
, address
, &nexthop
.ipv4
) == 1)
529 else if (inet_pton(AF_INET6
, address
, &nexthop
.ipv6
) == 1)
532 vty_out(vty
, "%% Malformed address\n");
537 zebra_pw_change(pw
, pw
->ifindex
, pw
->type
, af
, &nexthop
,
538 pw
->local_label
, pw
->remote_label
, pw
->flags
,
544 DEFUN (pseudowire_control_word
,
545 pseudowire_control_word_cmd
,
546 "[no] control-word <exclude|include>",
548 "Control-word options\n"
549 "Exclude control-word in pseudowire packets\n"
550 "Include control-word in pseudowire packets\n")
552 VTY_DECLVAR_CONTEXT(zebra_pw
, pw
);
556 if (argv_find(argv
, argc
, "no", &idx
))
557 flags
= F_PSEUDOWIRE_CWORD
;
559 argv_find(argv
, argc
, "control-word", &idx
);
560 if (argv
[idx
+ 1]->text
[0] == 'i')
561 flags
= F_PSEUDOWIRE_CWORD
;
564 zebra_pw_change(pw
, pw
->ifindex
, pw
->type
, pw
->af
, &pw
->nexthop
,
565 pw
->local_label
, pw
->remote_label
, flags
, &pw
->data
);
570 DEFUN (show_pseudowires
,
571 show_pseudowires_cmd
,
572 "show mpls pseudowires",
577 struct zebra_vrf
*zvrf
;
580 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
584 vty_out(vty
, "%-16s %-24s %-12s %-8s %-10s\n", "Interface", "Neighbor",
585 "Labels", "Protocol", "Status");
587 RB_FOREACH (pw
, zebra_pw_head
, &zvrf
->pseudowires
) {
588 char buf_nbr
[INET6_ADDRSTRLEN
];
591 inet_ntop(pw
->af
, &pw
->nexthop
, buf_nbr
, sizeof(buf_nbr
));
593 if (pw
->local_label
!= MPLS_NO_LABEL
594 && pw
->remote_label
!= MPLS_NO_LABEL
)
595 snprintf(buf_labels
, sizeof(buf_labels
), "%u/%u",
596 pw
->local_label
, pw
->remote_label
);
598 snprintf(buf_labels
, sizeof(buf_labels
), "-");
600 vty_out(vty
, "%-16s %-24s %-12s %-8s %-10s\n", pw
->ifname
,
601 (pw
->af
!= AF_UNSPEC
) ? buf_nbr
: "-", buf_labels
,
602 zebra_route_string(pw
->protocol
),
603 (zebra_pw_enabled(pw
) && pw
->status
== PW_FORWARDING
)
611 static void vty_show_mpls_pseudowire_detail(struct vty
*vty
)
613 struct zebra_vrf
*zvrf
;
615 struct route_entry
*re
;
616 struct nexthop
*nexthop
;
617 struct nexthop_group
*nhg
;
619 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
623 RB_FOREACH (pw
, zebra_pw_head
, &zvrf
->pseudowires
) {
624 char buf_nbr
[INET6_ADDRSTRLEN
];
627 vty_out(vty
, "Interface: %s\n", pw
->ifname
);
628 inet_ntop(pw
->af
, &pw
->nexthop
, buf_nbr
, sizeof(buf_nbr
));
629 vty_out(vty
, " Neighbor: %s\n",
630 (pw
->af
!= AF_UNSPEC
) ? buf_nbr
: "-");
631 if (pw
->local_label
!= MPLS_NO_LABEL
)
632 vty_out(vty
, " Local Label: %u\n", pw
->local_label
);
634 vty_out(vty
, " Local Label: %s\n", "-");
635 if (pw
->remote_label
!= MPLS_NO_LABEL
)
636 vty_out(vty
, " Remote Label: %u\n", pw
->remote_label
);
638 vty_out(vty
, " Remote Label: %s\n", "-");
639 vty_out(vty
, " Protocol: %s\n",
640 zebra_route_string(pw
->protocol
));
641 if (pw
->protocol
== ZEBRA_ROUTE_LDP
)
642 vty_out(vty
, " VC-ID: %u\n", pw
->data
.ldp
.pwid
);
643 vty_out(vty
, " Status: %s \n",
644 (zebra_pw_enabled(pw
) && pw
->status
== PW_FORWARDING
)
647 re
= rib_match(family2afi(pw
->af
), SAFI_UNICAST
, pw
->vrf_id
,
652 nhg
= rib_get_fib_nhg(re
);
653 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
654 snprintfrr(buf_nh
, sizeof(buf_nh
), "%pNHv",
656 vty_out(vty
, " Next Hop: %s\n", buf_nh
);
657 if (nexthop
->nh_label
)
658 vty_out(vty
, " Next Hop label: %u\n",
659 nexthop
->nh_label
->label
[0]);
661 vty_out(vty
, " Next Hop label: %s\n",
665 /* Include any installed backups */
666 nhg
= rib_get_fib_backup_nhg(re
);
670 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
671 snprintfrr(buf_nh
, sizeof(buf_nh
), "%pNHv",
673 vty_out(vty
, " Next Hop: %s\n", buf_nh
);
674 if (nexthop
->nh_label
)
675 vty_out(vty
, " Next Hop label: %u\n",
676 nexthop
->nh_label
->label
[0]);
678 vty_out(vty
, " Next Hop label: %s\n",
684 static void vty_show_mpls_pseudowire(struct zebra_pw
*pw
, json_object
*json_pws
)
686 struct route_entry
*re
;
687 struct nexthop
*nexthop
;
688 struct nexthop_group
*nhg
;
689 char buf_nbr
[INET6_ADDRSTRLEN
];
691 json_object
*json_pw
= NULL
;
692 json_object
*json_nexthop
= NULL
;
693 json_object
*json_nexthops
= NULL
;
695 json_nexthops
= json_object_new_array();
696 json_pw
= json_object_new_object();
698 json_object_string_add(json_pw
, "interface", pw
->ifname
);
699 if (pw
->af
== AF_UNSPEC
)
700 json_object_string_add(json_pw
, "neighbor", "-");
702 inet_ntop(pw
->af
, &pw
->nexthop
, buf_nbr
, sizeof(buf_nbr
));
703 json_object_string_add(json_pw
, "neighbor", buf_nbr
);
705 if (pw
->local_label
!= MPLS_NO_LABEL
)
706 json_object_int_add(json_pw
, "localLabel", pw
->local_label
);
708 json_object_string_add(json_pw
, "localLabel", "-");
709 if (pw
->remote_label
!= MPLS_NO_LABEL
)
710 json_object_int_add(json_pw
, "remoteLabel", pw
->remote_label
);
712 json_object_string_add(json_pw
, "remoteLabel", "-");
713 json_object_string_add(json_pw
, "protocol",
714 zebra_route_string(pw
->protocol
));
715 if (pw
->protocol
== ZEBRA_ROUTE_LDP
)
716 json_object_int_add(json_pw
, "vcId", pw
->data
.ldp
.pwid
);
717 json_object_string_add(
719 (zebra_pw_enabled(pw
) && pw
->status
== PW_FORWARDING
) ? "Up"
721 re
= rib_match(family2afi(pw
->af
), SAFI_UNICAST
, pw
->vrf_id
,
726 nhg
= rib_get_fib_nhg(re
);
727 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
728 json_nexthop
= json_object_new_object();
729 snprintfrr(buf_nh
, sizeof(buf_nh
), "%pNHv", nexthop
);
730 json_object_string_add(json_nexthop
, "nexthop", buf_nh
);
731 if (nexthop
->nh_label
)
733 json_nexthop
, "nhLabel",
734 nexthop
->nh_label
->label
[0]);
736 json_object_string_add(json_nexthop
, "nhLabel",
739 json_object_array_add(json_nexthops
, json_nexthop
);
742 /* Include installed backup nexthops also */
743 nhg
= rib_get_fib_backup_nhg(re
);
747 for (ALL_NEXTHOPS_PTR(nhg
, nexthop
)) {
748 json_nexthop
= json_object_new_object();
749 snprintfrr(buf_nh
, sizeof(buf_nh
), "%pNHv", nexthop
);
750 json_object_string_add(json_nexthop
, "nexthop", buf_nh
);
751 if (nexthop
->nh_label
)
753 json_nexthop
, "nhLabel",
754 nexthop
->nh_label
->label
[0]);
756 json_object_string_add(json_nexthop
, "nhLabel",
759 json_object_array_add(json_nexthops
, json_nexthop
);
764 json_object_object_add(json_pw
, "nexthops", json_nexthops
);
765 json_object_array_add(json_pws
, json_pw
);
768 static void vty_show_mpls_pseudowire_detail_json(struct vty
*vty
)
770 json_object
*json
= NULL
;
771 json_object
*json_pws
= NULL
;
772 struct zebra_vrf
*zvrf
;
775 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
779 json
= json_object_new_object();
780 json_pws
= json_object_new_array();
781 RB_FOREACH (pw
, zebra_pw_head
, &zvrf
->pseudowires
) {
782 vty_show_mpls_pseudowire(pw
, json_pws
);
784 json_object_object_add(json
, "pw", json_pws
);
788 DEFUN(show_pseudowires_detail
, show_pseudowires_detail_cmd
,
789 "show mpls pseudowires detail [json]$json",
792 "Detailed output\n" JSON_STR
)
794 bool uj
= use_json(argc
, argv
);
797 vty_show_mpls_pseudowire_detail_json(vty
);
799 vty_show_mpls_pseudowire_detail(vty
);
804 /* Pseudowire configuration write function. */
805 static int zebra_pw_config(struct vty
*vty
)
808 struct zebra_vrf
*zvrf
;
811 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
815 RB_FOREACH (pw
, zebra_static_pw_head
, &zvrf
->static_pseudowires
) {
816 vty_out(vty
, "pseudowire %s\n", pw
->ifname
);
817 if (pw
->local_label
!= MPLS_NO_LABEL
818 && pw
->remote_label
!= MPLS_NO_LABEL
)
819 vty_out(vty
, " mpls label local %u remote %u\n",
820 pw
->local_label
, pw
->remote_label
);
823 " ! Incomplete config, specify the static MPLS labels\n");
825 if (pw
->af
!= AF_UNSPEC
) {
826 char buf
[INET6_ADDRSTRLEN
];
827 inet_ntop(pw
->af
, &pw
->nexthop
, buf
, sizeof(buf
));
828 vty_out(vty
, " neighbor %s\n", buf
);
831 " ! Incomplete config, specify a neighbor address\n");
833 if (!(pw
->flags
& F_PSEUDOWIRE_CWORD
))
834 vty_out(vty
, " control-word exclude\n");
836 vty_out(vty
, "exit\n");
844 static int zebra_pw_config(struct vty
*vty
);
845 static struct cmd_node pw_node
= {
848 .parent_node
= CONFIG_NODE
,
849 .prompt
= "%s(config-pw)# ",
850 .config_write
= zebra_pw_config
,
853 void zebra_pw_vty_init(void)
855 install_node(&pw_node
);
856 install_default(PW_NODE
);
858 install_element(CONFIG_NODE
, &pseudowire_if_cmd
);
859 install_element(CONFIG_NODE
, &no_pseudowire_if_cmd
);
860 install_element(PW_NODE
, &pseudowire_labels_cmd
);
861 install_element(PW_NODE
, &pseudowire_neighbor_cmd
);
862 install_element(PW_NODE
, &pseudowire_control_word_cmd
);
864 install_element(VIEW_NODE
, &show_pseudowires_cmd
);
865 install_element(VIEW_NODE
, &show_pseudowires_detail_cmd
);