3 * Copyright (C) 2018 Cumulus Networks, Inc.
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "nexthop_group.h"
28 #include "nexthop_group_private.h"
34 #include "pbrd/pbr_nht.h"
35 #include "pbrd/pbr_map.h"
36 #include "pbrd/pbr_zebra.h"
37 #include "pbrd/pbr_vty.h"
38 #include "pbrd/pbr_debug.h"
39 #ifndef VTYSH_EXTRACT_PL
40 #include "pbrd/pbr_vty_clippy.c"
43 DEFUN_NOSH(pbr_map
, pbr_map_cmd
, "pbr-map PBRMAP seq (1-700)",
44 "Create pbr-map or enter pbr-map command mode\n"
45 "The name of the PBR MAP\n"
46 "Sequence to insert in existing pbr-map entry\n"
49 const char *pbrm_name
= argv
[1]->arg
;
50 uint32_t seqno
= atoi(argv
[3]->arg
);
51 struct pbr_map_sequence
*pbrms
;
53 pbrms
= pbrms_get(pbrm_name
, seqno
);
54 VTY_PUSH_CONTEXT(PBRMAP_NODE
, pbrms
);
59 DEFUN_NOSH(no_pbr_map
, no_pbr_map_cmd
, "no pbr-map PBRMAP [seq (1-700)]",
62 "The name of the PBR MAP\n"
63 "Sequence to delete from existing pbr-map entry\n"
66 const char *pbrm_name
= argv
[2]->arg
;
68 struct pbr_map
*pbrm
= pbrm_find(pbrm_name
);
69 struct pbr_map_sequence
*pbrms
;
70 struct listnode
*node
, *next_node
;
73 seqno
= atoi(argv
[4]->arg
);
76 vty_out(vty
, "pbr-map %s not found\n", pbrm_name
);
80 for (ALL_LIST_ELEMENTS(pbrm
->seqnumbers
, node
, next_node
, pbrms
)) {
81 if (seqno
&& pbrms
->seqno
!= seqno
)
84 pbr_map_delete(pbrms
);
90 DEFPY(pbr_set_table_range
,
91 pbr_set_table_range_cmd
,
92 "pbr table range (10000-4294966272)$lb (10000-4294966272)$ub",
94 "Set table ID range\n"
95 "Set table ID range\n"
96 "Lower bound for table ID range\n"
97 "Upper bound for table ID range\n")
99 /* upper bound is 2^32 - 2^10 */
100 int ret
= CMD_WARNING
;
101 const int minrange
= 1000;
103 /* validate given bounds */
105 vty_out(vty
, "%% Lower bound must be less than upper bound\n");
106 else if (ub
- lb
< minrange
)
107 vty_out(vty
, "%% Range breadth must be at least %d\n", minrange
);
110 pbr_nht_set_tableid_range((uint32_t) lb
, (uint32_t) ub
);
116 DEFPY(no_pbr_set_table_range
, no_pbr_set_table_range_cmd
,
117 "no pbr table range [(10000-4294966272)$lb (10000-4294966272)$ub]",
120 "Set table ID range\n"
121 "Set table ID range\n"
122 "Lower bound for table ID range\n"
123 "Upper bound for table ID range\n")
125 pbr_nht_set_tableid_range(PBR_NHT_DEFAULT_LOW_TABLEID
,
126 PBR_NHT_DEFAULT_HIGH_TABLEID
);
130 DEFPY(pbr_map_match_src
, pbr_map_match_src_cmd
,
131 "[no] match src-ip <A.B.C.D/M|X:X::X:X/M>$prefix",
133 "Match the rest of the command\n"
134 "Choose the src ip or ipv6 prefix to use\n"
138 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
140 pbrms
->family
= prefix
->family
;
144 if (prefix_same(pbrms
->src
, prefix
))
147 pbrms
->src
= prefix_new();
149 prefix_copy(pbrms
->src
, prefix
);
151 prefix_free(&pbrms
->src
);
153 pbr_map_check(pbrms
, true);
158 DEFPY(pbr_map_match_dst
, pbr_map_match_dst_cmd
,
159 "[no] match dst-ip <A.B.C.D/M|X:X::X:X/M>$prefix",
161 "Match the rest of the command\n"
162 "Choose the dst ip or ipv6 prefix to use\n"
166 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
168 pbrms
->family
= prefix
->family
;
172 if (prefix_same(pbrms
->dst
, prefix
))
175 pbrms
->dst
= prefix_new();
177 prefix_copy(pbrms
->dst
, prefix
);
179 prefix_free(&pbrms
->dst
);
181 pbr_map_check(pbrms
, true);
186 DEFPY(pbr_map_match_mark
, pbr_map_match_mark_cmd
,
187 "[no] match mark (1-4294967295)$mark",
189 "Match the rest of the command\n"
190 "Choose the mark value to use\n"
193 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
196 vty_out(vty
, "pbr marks are not supported on this platform");
197 return CMD_WARNING_CONFIG_FAILED
;
202 if (pbrms
->mark
== (uint32_t)mark
)
205 pbrms
->mark
= (uint32_t)mark
;
209 pbr_map_check(pbrms
, true);
214 static void pbrms_clear_set_vrf_config(struct pbr_map_sequence
*pbrms
)
216 if (pbrms
->vrf_lookup
|| pbrms
->vrf_unchanged
) {
217 pbr_map_delete_vrf(pbrms
);
218 pbrms
->vrf_name
[0] = '\0';
219 pbrms
->vrf_lookup
= false;
220 pbrms
->vrf_unchanged
= false;
224 static void pbrms_clear_set_nhg_config(struct pbr_map_sequence
*pbrms
)
226 if (pbrms
->nhgrp_name
)
227 pbr_map_delete_nexthops(pbrms
);
230 static void pbrms_clear_set_nexthop_config(struct pbr_map_sequence
*pbrms
)
233 pbr_nht_delete_individual_nexthop(pbrms
);
236 static void pbrms_clear_set_config(struct pbr_map_sequence
*pbrms
)
238 pbrms_clear_set_vrf_config(pbrms
);
239 pbrms_clear_set_nhg_config(pbrms
);
240 pbrms_clear_set_nexthop_config(pbrms
);
242 pbrms
->nhs_installed
= false;
245 DEFPY(pbr_map_nexthop_group
, pbr_map_nexthop_group_cmd
,
246 "set nexthop-group NHGNAME$name",
247 "Set for the PBR-MAP\n"
248 "nexthop-group to use\n"
249 "The name of the nexthop-group\n")
251 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
252 struct nexthop_group_cmd
*nhgc
;
254 nhgc
= nhgc_find(name
);
256 vty_out(vty
, "Specified nexthop-group %s does not exist\n",
259 "PBR-MAP will not be applied until it is created\n");
262 if (pbrms
->nhgrp_name
&& strcmp(name
, pbrms
->nhgrp_name
) == 0)
265 /* This is new/replacement config */
266 pbrms_clear_set_config(pbrms
);
268 pbrms
->nhgrp_name
= XSTRDUP(MTYPE_TMP
, name
);
269 pbr_map_check(pbrms
, true);
274 DEFPY(no_pbr_map_nexthop_group
, no_pbr_map_nexthop_group_cmd
,
275 "no set nexthop-group [NHGNAME$name]",
277 "Set for the PBR-MAP\n"
278 "nexthop-group to use\n"
279 "The name of the nexthop-group\n")
281 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
283 pbrms_clear_set_config(pbrms
);
288 DEFPY(pbr_map_nexthop
, pbr_map_nexthop_cmd
,
291 <A.B.C.D|X:X::X:X>$addr [INTERFACE$intf]\
294 [nexthop-vrf NAME$vrf_name]",
295 "Set for the PBR-MAP\n"
296 "Specify one of the nexthops in this map\n"
301 "If the nexthop is in a different vrf tell us\n"
302 "The nexthop-vrf Name\n")
304 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
307 struct nexthop
*nh
= NULL
;
310 vrf
= vrf_lookup_by_name(vrf_name
);
312 vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
315 vty_out(vty
, "Specified: %s is non-existent\n", vrf_name
);
316 return CMD_WARNING_CONFIG_FAILED
;
319 memset(&nhop
, 0, sizeof(nhop
));
320 nhop
.vrf_id
= vrf
->vrf_id
;
323 nhop
.ifindex
= ifname2ifindex(intf
, vrf
->vrf_id
);
324 if (nhop
.ifindex
== IFINDEX_INTERNAL
) {
326 "Specified Intf %s does not exist in vrf: %s\n",
328 return CMD_WARNING_CONFIG_FAILED
;
333 if (addr
->sa
.sa_family
== AF_INET
) {
334 nhop
.gate
.ipv4
.s_addr
= addr
->sin
.sin_addr
.s_addr
;
336 nhop
.type
= NEXTHOP_TYPE_IPV4_IFINDEX
;
338 nhop
.type
= NEXTHOP_TYPE_IPV4
;
340 nhop
.gate
.ipv6
= addr
->sin6
.sin6_addr
;
342 nhop
.type
= NEXTHOP_TYPE_IPV6_IFINDEX
;
344 if (IN6_IS_ADDR_LINKLOCAL(&nhop
.gate
.ipv6
)) {
346 "Specified a v6 LL with no interface, rejecting\n");
347 return CMD_WARNING_CONFIG_FAILED
;
349 nhop
.type
= NEXTHOP_TYPE_IPV6
;
353 nhop
.type
= NEXTHOP_TYPE_IFINDEX
;
356 nh
= nexthop_exists(pbrms
->nhg
, &nhop
);
358 if (nh
) /* Same config re-entered */
361 /* This is new/replacement config */
362 pbrms_clear_set_config(pbrms
);
364 pbr_nht_add_individual_nexthop(pbrms
, &nhop
);
366 pbr_map_check(pbrms
, true);
369 if (nhop
.type
== NEXTHOP_TYPE_IFINDEX
370 || (nhop
.type
== NEXTHOP_TYPE_IPV6_IFINDEX
371 && IN6_IS_ADDR_LINKLOCAL(&nhop
.gate
.ipv6
))) {
372 struct interface
*ifp
;
374 ifp
= if_lookup_by_index(nhop
.ifindex
, nhop
.vrf_id
);
376 pbr_nht_nexthop_interface_update(ifp
);
382 DEFPY(no_pbr_map_nexthop
, no_pbr_map_nexthop_cmd
,
385 <A.B.C.D|X:X::X:X>$addr [INTERFACE$intf]\
388 [nexthop-vrf NAME$vrf_name]]",
390 "Set for the PBR-MAP\n"
391 "Specify one of the nexthops in this map\n"
396 "If the nexthop is in a different vrf tell us\n"
397 "The nexthop-vrf Name\n")
399 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
401 pbrms_clear_set_config(pbrms
);
406 DEFPY(pbr_map_vrf
, pbr_map_vrf_cmd
,
407 "set vrf <NAME$vrf_name|unchanged>",
408 "Set for the PBR-MAP\n"
409 "Specify the VRF for this map\n"
411 "Use the interface's VRF for lookup\n")
413 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
416 * If an equivalent set vrf * exists, just return success.
418 if (vrf_name
&& pbrms
->vrf_lookup
419 && strncmp(pbrms
->vrf_name
, vrf_name
, sizeof(pbrms
->vrf_name
)) == 0)
421 else if (!vrf_name
&& pbrms
->vrf_unchanged
) /* Unchanged already set */
424 if (vrf_name
&& !pbr_vrf_lookup_by_name(vrf_name
)) {
425 vty_out(vty
, "Specified: %s is non-existent\n", vrf_name
);
426 return CMD_WARNING_CONFIG_FAILED
;
429 /* This is new/replacement config */
430 pbrms_clear_set_config(pbrms
);
433 pbrms
->vrf_lookup
= true;
434 strlcpy(pbrms
->vrf_name
, vrf_name
, sizeof(pbrms
->vrf_name
));
436 pbrms
->vrf_unchanged
= true;
438 pbr_map_check(pbrms
, true);
443 DEFPY(no_pbr_map_vrf
, no_pbr_map_vrf_cmd
,
444 "no set vrf [<NAME$vrf_name|unchanged>]",
446 "Set for the PBR-MAP\n"
447 "Specify the VRF for this map\n"
449 "Use the interface's VRF for lookup\n")
451 struct pbr_map_sequence
*pbrms
= VTY_GET_CONTEXT(pbr_map_sequence
);
453 pbrms_clear_set_config(pbrms
);
460 "[no] pbr-policy PBRMAP$mapname",
463 "Name of the pbr-map to apply\n")
465 VTY_DECLVAR_CONTEXT(interface
, ifp
);
466 struct pbr_map
*pbrm
, *old_pbrm
;
467 struct pbr_interface
*pbr_ifp
= ifp
->info
;
470 pbrm
= pbrm_find(mapname
);
473 /* we don't want one and we don't have one, so... */
477 /* Some one could have fat fingered the interface name */
478 pbr_ifp
= pbr_if_new(ifp
);
482 if (strcmp(pbr_ifp
->mapname
, mapname
) == 0) {
483 pbr_ifp
->mapname
[0] = '\0';
485 pbr_map_interface_delete(pbrm
, ifp
);
488 if (strcmp(pbr_ifp
->mapname
, "") != 0) {
489 old_pbrm
= pbrm_find(pbr_ifp
->mapname
);
492 * So if we have an old pbrm we should only
493 * delete it if we are actually deleting and
494 * moving to a new pbrm
496 if (old_pbrm
&& old_pbrm
!= pbrm
)
497 pbr_map_interface_delete(old_pbrm
, ifp
);
499 snprintf(pbr_ifp
->mapname
, sizeof(pbr_ifp
->mapname
),
503 * So only reinstall if the old_pbrm and this pbrm are
506 if (pbrm
&& pbrm
!= old_pbrm
)
507 pbr_map_add_interface(pbrm
, ifp
);
519 pbr_nht_write_table_range(vty
);
520 pbr_nht_write_rule_range(vty
);
525 static void vty_show_pbrms(struct vty
*vty
,
526 const struct pbr_map_sequence
*pbrms
, bool detail
)
528 char buf
[PREFIX_STRLEN
];
532 pbr_map_reason_string(pbrms
->reason
, rbuf
, sizeof(rbuf
));
534 vty_out(vty
, " Seq: %u rule: %u\n", pbrms
->seqno
, pbrms
->ruleno
);
537 vty_out(vty
, " Installed: %" PRIu64
"(%u) Reason: %s\n",
538 pbrms
->installed
, pbrms
->unique
,
539 pbrms
->reason
? rbuf
: "Valid");
541 vty_out(vty
, " Installed: %s Reason: %s\n",
542 pbrms
->installed
? "yes" : "no",
543 pbrms
->reason
? rbuf
: "Valid");
546 vty_out(vty
, " SRC Match: %s\n",
547 prefix2str(pbrms
->src
, buf
, sizeof(buf
)));
549 vty_out(vty
, " DST Match: %s\n",
550 prefix2str(pbrms
->dst
, buf
, sizeof(buf
)));
552 vty_out(vty
, " MARK Match: %u\n", pbrms
->mark
);
554 if (pbrms
->nhgrp_name
) {
555 vty_out(vty
, " Nexthop-Group: %s\n", pbrms
->nhgrp_name
);
559 " Installed: %u(%d) Tableid: %d\n",
560 pbrms
->nhs_installed
,
561 pbr_nht_get_installed(pbrms
->nhgrp_name
),
562 pbr_nht_get_table(pbrms
->nhgrp_name
));
564 vty_out(vty
, " Installed: %s Tableid: %d\n",
565 pbr_nht_get_installed(pbrms
->nhgrp_name
) ? "yes"
567 pbr_nht_get_table(pbrms
->nhgrp_name
));
569 } else if (pbrms
->nhg
) {
571 nexthop_group_write_nexthop(vty
, pbrms
->nhg
->nexthop
);
574 " Installed: %u(%d) Tableid: %d\n",
575 pbrms
->nhs_installed
,
576 pbr_nht_get_installed(pbrms
->internal_nhg_name
),
577 pbr_nht_get_table(pbrms
->internal_nhg_name
));
579 vty_out(vty
, " Installed: %s Tableid: %d\n",
580 pbr_nht_get_installed(pbrms
->internal_nhg_name
)
583 pbr_nht_get_table(pbrms
->internal_nhg_name
));
585 } else if (pbrms
->vrf_unchanged
) {
586 vty_out(vty
, " VRF Unchanged (use interface vrf)\n");
587 } else if (pbrms
->vrf_lookup
) {
588 vty_out(vty
, " VRF Lookup: %s\n", pbrms
->vrf_name
);
590 vty_out(vty
, " Nexthop-Group: Unknown Installed: no\n");
594 static void vty_json_pbrms(json_object
*j
, struct vty
*vty
,
595 const struct pbr_map_sequence
*pbrms
)
597 json_object
*jpbrm
, *nexthop_group
;
598 char *nhg_name
= pbrms
->nhgrp_name
? pbrms
->nhgrp_name
599 : pbrms
->internal_nhg_name
;
600 char buf
[PREFIX_STRLEN
];
603 jpbrm
= json_object_new_object();
605 json_object_int_add(jpbrm
, "id", pbrms
->unique
);
608 pbr_map_reason_string(pbrms
->reason
, rbuf
, sizeof(rbuf
));
610 json_object_int_add(jpbrm
, "sequenceNumber", pbrms
->seqno
);
611 json_object_int_add(jpbrm
, "ruleNumber", pbrms
->ruleno
);
612 json_object_boolean_add(jpbrm
, "vrfUnchanged", pbrms
->vrf_unchanged
);
613 json_object_boolean_add(jpbrm
, "installed",
614 pbr_nht_get_installed(nhg_name
));
615 json_object_string_add(jpbrm
, "installedReason",
616 pbrms
->reason
? rbuf
: "Valid");
619 nexthop_group
= json_object_new_object();
621 json_object_int_add(nexthop_group
, "tableId",
622 pbr_nht_get_table(nhg_name
));
623 json_object_string_add(nexthop_group
, "name", nhg_name
);
624 json_object_boolean_add(nexthop_group
, "installed",
625 pbr_nht_get_installed(nhg_name
));
626 json_object_int_add(nexthop_group
, "installedInternally",
627 pbrms
->nhs_installed
);
629 json_object_object_add(jpbrm
, "nexthopGroup", nexthop_group
);
632 if (pbrms
->vrf_lookup
)
633 json_object_string_add(jpbrm
, "vrfName", pbrms
->vrf_name
);
636 json_object_string_add(
638 prefix2str(pbrms
->src
, buf
, sizeof(buf
)));
640 json_object_string_add(
642 prefix2str(pbrms
->dst
, buf
, sizeof(buf
)));
644 json_object_int_add(jpbrm
, "matchMark", pbrms
->mark
);
646 json_object_array_add(j
, jpbrm
);
649 static void vty_show_pbr_map(struct vty
*vty
, const struct pbr_map
*pbrm
,
652 struct pbr_map_sequence
*pbrms
;
653 struct listnode
*node
;
655 vty_out(vty
, " pbr-map %s valid: %s\n", pbrm
->name
,
656 pbrm
->valid
? "yes" : "no");
658 for (ALL_LIST_ELEMENTS_RO(pbrm
->seqnumbers
, node
, pbrms
))
659 vty_show_pbrms(vty
, pbrms
, detail
);
662 static void vty_json_pbr_map(json_object
*j
, struct vty
*vty
,
663 const struct pbr_map
*pbrm
)
665 struct pbr_map_sequence
*pbrms
;
666 struct listnode
*node
;
669 json_object_string_add(j
, "name", pbrm
->name
);
670 json_object_boolean_add(j
, "valid", pbrm
->valid
);
672 jpbrms
= json_object_new_array();
674 for (ALL_LIST_ELEMENTS_RO(pbrm
->seqnumbers
, node
, pbrms
))
675 vty_json_pbrms(jpbrms
, vty
, pbrms
);
677 json_object_object_add(j
, "policies", jpbrms
);
682 "show pbr map [NAME$name] [detail$detail|json$json]",
687 "Detailed information\n"
690 struct pbr_map
*pbrm
;
691 json_object
*j
= NULL
;
694 j
= json_object_new_array();
696 RB_FOREACH (pbrm
, pbr_map_entry_head
, &pbr_maps
) {
697 json_object
*this_map
= NULL
;
698 if (name
&& strcmp(name
, pbrm
->name
) != 0)
702 this_map
= json_object_new_object();
705 vty_json_pbr_map(this_map
, vty
, pbrm
);
707 json_object_array_add(j
, this_map
);
711 vty_show_pbr_map(vty
, pbrm
, detail
);
716 json_object_to_json_string_ext(
717 j
, JSON_C_TO_STRING_PRETTY
));
724 DEFPY(show_pbr_nexthop_group
,
725 show_pbr_nexthop_group_cmd
,
726 "show pbr nexthop-groups [WORD$word] [json$json]",
730 "Optional Name of the nexthop group\n"
733 json_object
*j
= NULL
;
736 j
= json_object_new_array();
739 pbr_nht_json_nexthop_group(j
, word
);
742 json_object_to_json_string_ext(
743 j
, JSON_C_TO_STRING_PRETTY
));
747 pbr_nht_show_nexthop_group(vty
, word
);
753 DEFPY (show_pbr_interface
,
754 show_pbr_interface_cmd
,
755 "show pbr interface [NAME$name] [json$json]",
759 "PBR Interface Name\n"
762 struct interface
*ifp
;
764 struct pbr_interface
*pbr_ifp
;
765 json_object
*j
= NULL
;
768 j
= json_object_new_array();
770 RB_FOREACH(vrf
, vrf_name_head
, &vrfs_by_name
) {
771 FOR_ALL_INTERFACES(vrf
, ifp
) {
772 struct pbr_map
*pbrm
;
773 json_object
*this_iface
= NULL
;
776 this_iface
= json_object_new_object();
781 if (name
&& strcmp(ifp
->name
, name
) != 0)
786 if (strcmp(pbr_ifp
->mapname
, "") == 0)
789 pbrm
= pbrm_find(pbr_ifp
->mapname
);
792 json_object_string_add(this_iface
, "name",
794 json_object_int_add(this_iface
, "index",
796 json_object_string_add(this_iface
, "policy",
798 json_object_boolean_add(this_iface
, "valid",
801 json_object_array_add(j
, this_iface
);
805 vty_out(vty
, " %s(%d) with pbr-policy %s", ifp
->name
,
806 ifp
->ifindex
, pbr_ifp
->mapname
);
808 vty_out(vty
, " (map doesn't exist)");
815 json_object_to_json_string_ext(
816 j
, JSON_C_TO_STRING_PRETTY
));
823 /* PBR debugging CLI ------------------------------------------------------- */
825 static struct cmd_node debug_node
= {
829 .config_write
= pbr_debug_config_write
,
834 "[no] debug pbr [{map$map|zebra$zebra|nht$nht|events$events}]",
839 "PBRD <-> Zebra communications\n"
843 uint32_t mode
= DEBUG_NODE2MODE(vty
->node
);
846 DEBUG_MODE_SET(&pbr_dbg_map
, mode
, !no
);
848 DEBUG_MODE_SET(&pbr_dbg_zebra
, mode
, !no
);
850 DEBUG_MODE_SET(&pbr_dbg_nht
, mode
, !no
);
852 DEBUG_MODE_SET(&pbr_dbg_event
, mode
, !no
);
854 /* no specific debug --> act on all of them */
855 if (strmatch(argv
[argc
- 1]->text
, "pbr"))
856 pbr_debug_set_all(mode
, !no
);
861 DEFUN_NOSH(show_debugging_pbr
,
862 show_debugging_pbr_cmd
,
863 "show debugging [pbr]",
868 vty_out(vty
, "PBR debugging status:\n");
870 pbr_debug_config_write_helper(vty
, false);
875 /* ------------------------------------------------------------------------- */
878 static int pbr_interface_config_write(struct vty
*vty
);
879 static struct cmd_node interface_node
= {
881 .node
= INTERFACE_NODE
,
882 .parent_node
= CONFIG_NODE
,
883 .prompt
= "%s(config-if)# ",
884 .config_write
= pbr_interface_config_write
,
887 static int pbr_interface_config_write(struct vty
*vty
)
889 struct interface
*ifp
;
892 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
893 FOR_ALL_INTERFACES (vrf
, ifp
) {
894 if (vrf
->vrf_id
== VRF_DEFAULT
)
895 vty_frame(vty
, "interface %s\n", ifp
->name
);
897 vty_frame(vty
, "interface %s vrf %s\n",
898 ifp
->name
, vrf
->name
);
901 vty_out(vty
, " description %s\n", ifp
->desc
);
903 pbr_map_write_interfaces(vty
, ifp
);
905 vty_endframe(vty
, "!\n");
912 static int pbr_vty_map_config_write(struct vty
*vty
);
913 /* PBR map node structure. */
914 static struct cmd_node pbr_map_node
= {
917 .parent_node
= CONFIG_NODE
,
918 .prompt
= "%s(config-pbr-map)# ",
919 .config_write
= pbr_vty_map_config_write
,
922 static int pbr_vty_map_config_write_sequence(struct vty
*vty
,
923 struct pbr_map
*pbrm
,
924 struct pbr_map_sequence
*pbrms
)
926 char buff
[PREFIX_STRLEN
];
928 vty_out(vty
, "pbr-map %s seq %u\n", pbrm
->name
, pbrms
->seqno
);
931 vty_out(vty
, " match src-ip %s\n",
932 prefix2str(pbrms
->src
, buff
, sizeof(buff
)));
935 vty_out(vty
, " match dst-ip %s\n",
936 prefix2str(pbrms
->dst
, buff
, sizeof(buff
)));
939 vty_out(vty
, " match mark %u\n", pbrms
->mark
);
941 if (pbrms
->vrf_unchanged
)
942 vty_out(vty
, " set vrf unchanged\n");
944 if (pbrms
->vrf_lookup
)
945 vty_out(vty
, " set vrf %s\n", pbrms
->vrf_name
);
947 if (pbrms
->nhgrp_name
)
948 vty_out(vty
, " set nexthop-group %s\n", pbrms
->nhgrp_name
);
951 vty_out(vty
, " set ");
952 nexthop_group_write_nexthop(vty
, pbrms
->nhg
->nexthop
);
959 static int pbr_vty_map_config_write(struct vty
*vty
)
961 struct pbr_map
*pbrm
;
963 pbr_nht_write_table_range(vty
);
964 pbr_nht_write_rule_range(vty
);
966 RB_FOREACH(pbrm
, pbr_map_entry_head
, &pbr_maps
) {
967 struct pbr_map_sequence
*pbrms
;
968 struct listnode
*node
;
970 for (ALL_LIST_ELEMENTS_RO(pbrm
->seqnumbers
, node
, pbrms
))
971 pbr_vty_map_config_write_sequence(vty
, pbrm
, pbrms
);
977 static void pbr_map_completer(vector comps
, struct cmd_token
*token
)
979 struct pbr_map
*pbrm
;
981 RB_FOREACH (pbrm
, pbr_map_entry_head
, &pbr_maps
)
982 vector_set(comps
, XSTRDUP(MTYPE_COMPLETION
, pbrm
->name
));
985 static const struct cmd_variable_handler pbr_map_name
[] = {
987 .tokenname
= "PBRMAP", .completions
= pbr_map_completer
,
994 void pbr_vty_init(void)
996 cmd_variable_handler_register(pbr_map_name
);
998 install_node(&interface_node
);
1001 install_node(&pbr_map_node
);
1004 install_node(&debug_node
);
1005 install_element(VIEW_NODE
, &debug_pbr_cmd
);
1006 install_element(CONFIG_NODE
, &debug_pbr_cmd
);
1007 install_element(VIEW_NODE
, &show_debugging_pbr_cmd
);
1009 install_default(PBRMAP_NODE
);
1011 install_element(CONFIG_NODE
, &pbr_map_cmd
);
1012 install_element(CONFIG_NODE
, &no_pbr_map_cmd
);
1013 install_element(CONFIG_NODE
, &pbr_set_table_range_cmd
);
1014 install_element(CONFIG_NODE
, &no_pbr_set_table_range_cmd
);
1015 install_element(INTERFACE_NODE
, &pbr_policy_cmd
);
1016 install_element(PBRMAP_NODE
, &pbr_map_match_src_cmd
);
1017 install_element(PBRMAP_NODE
, &pbr_map_match_dst_cmd
);
1018 install_element(PBRMAP_NODE
, &pbr_map_match_mark_cmd
);
1019 install_element(PBRMAP_NODE
, &pbr_map_nexthop_group_cmd
);
1020 install_element(PBRMAP_NODE
, &no_pbr_map_nexthop_group_cmd
);
1021 install_element(PBRMAP_NODE
, &pbr_map_nexthop_cmd
);
1022 install_element(PBRMAP_NODE
, &no_pbr_map_nexthop_cmd
);
1023 install_element(PBRMAP_NODE
, &pbr_map_vrf_cmd
);
1024 install_element(PBRMAP_NODE
, &no_pbr_map_vrf_cmd
);
1025 install_element(VIEW_NODE
, &show_pbr_cmd
);
1026 install_element(VIEW_NODE
, &show_pbr_map_cmd
);
1027 install_element(VIEW_NODE
, &show_pbr_interface_cmd
);
1028 install_element(VIEW_NODE
, &show_pbr_nexthop_group_cmd
);