2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <vnet/mfib/mfib_types.h>
18 #include <vnet/ip/ip.h>
21 * String names for each flag
23 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
24 static const char *mfib_flag_names_long[] = MFIB_ENTRY_NAMES_LONG;
26 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
27 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
30 format_mfib_prefix (u8 * s, va_list * args)
32 mfib_prefix_t *fp = va_arg (*args, mfib_prefix_t *);
35 * protocol specific so it prints ::/0 correctly.
39 case FIB_PROTOCOL_IP6:
41 ip6_address_t p6 = fp->fp_grp_addr.ip6;
42 u32 len = (fp->fp_len > 128 ? 128 : fp->fp_len);
44 ip6_address_mask(&p6, &(ip6_main.fib_masks[len]));
46 if (ip6_address_is_zero(&fp->fp_src_addr.ip6))
48 s = format(s, "(*, ");
52 s = format (s, "(%U, ", format_ip6_address, &fp->fp_src_addr.ip6);
54 s = format (s, "%U", format_ip6_address, &p6);
55 s = format (s, "/%d)", len);
58 case FIB_PROTOCOL_IP4:
60 ip4_address_t p4 = fp->fp_grp_addr.ip4;
61 u32 len = (fp->fp_len > 32 ? 32 : fp->fp_len);
63 p4.as_u32 &= ip4_main.fib_masks[len];
65 if (0 == fp->fp_src_addr.ip4.as_u32)
67 s = format(s, "(*, ");
71 s = format (s, "(%U, ", format_ip4_address, &fp->fp_src_addr.ip4);
73 s = format (s, "%U", format_ip4_address, &p4);
74 s = format (s, "/%d)", len);
77 case FIB_PROTOCOL_MPLS:
85 format_mfib_entry_flags (u8 * s, va_list * args)
87 mfib_entry_attribute_t attr;
88 mfib_entry_flags_t flags;
90 flags = va_arg (*args, mfib_entry_flags_t);
92 if (MFIB_ENTRY_FLAG_NONE != flags) {
93 s = format(s, " flags:");
94 FOR_EACH_MFIB_ATTRIBUTE(attr) {
95 if ((1<<attr) & flags) {
96 s = format (s, "%s,", mfib_flag_names[attr]);
105 format_mfib_itf_flags (u8 * s, va_list * args)
107 mfib_itf_attribute_t attr;
108 mfib_itf_flags_t flags;
110 flags = va_arg (*args, mfib_itf_flags_t);
112 FOR_EACH_MFIB_ITF_ATTRIBUTE(attr) {
113 if ((1<<attr) & flags) {
114 s = format (s, "%s,", mfib_itf_flag_long_names[attr]);
122 unformat_mfib_itf_flags (unformat_input_t * input,
125 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t*);
126 mfib_itf_attribute_t attr;
129 FOR_EACH_MFIB_ITF_ATTRIBUTE(attr) {
130 if (unformat (input, mfib_itf_flag_long_names[attr]))
131 *iflags |= (1 << attr);
133 FOR_EACH_MFIB_ITF_ATTRIBUTE(attr) {
134 if (unformat (input, mfib_itf_flag_names[attr]))
135 *iflags |= (1 << attr);
138 return (old == *iflags ? 0 : 1);
142 unformat_mfib_entry_flags (unformat_input_t * input,
145 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t*);
146 mfib_entry_attribute_t attr;
149 FOR_EACH_MFIB_ATTRIBUTE(attr) {
150 if (unformat (input, mfib_flag_names[attr]))
151 *eflags |= (1 << attr);
154 return (old == *eflags ? 0 : 1);
158 mfib_show_route_flags (vlib_main_t * vm,
159 unformat_input_t * main_input,
160 vlib_cli_command_t * cmd)
162 mfib_entry_attribute_t attr;
164 FOR_EACH_MFIB_ATTRIBUTE(attr) {
165 vlib_cli_output(vm, "%s = %s",
166 mfib_flag_names[attr],
167 mfib_flag_names_long[attr]);
174 * This command displays the set of supported flags applicable to an MFIB route
177 VLIB_CLI_COMMAND (mfib_route_flags_command, static) =
179 .path = "show mfib route flags",
180 .short_help = "Flags applicable to an MFIB route",
181 .function = mfib_show_route_flags,
187 mfib_show_itf_flags (vlib_main_t * vm,
188 unformat_input_t * main_input,
189 vlib_cli_command_t * cmd)
191 mfib_itf_attribute_t attr;
193 FOR_EACH_MFIB_ITF_ATTRIBUTE(attr) {
194 vlib_cli_output(vm, "%s = %s",
195 mfib_itf_flag_names[attr],
196 mfib_itf_flag_long_names[attr]);
203 * This command displays the set of supported flags applicable to an MFIB interface
206 VLIB_CLI_COMMAND (mfib_itf_flags_command, static) =
208 .path = "show mfib itf flags",
209 .short_help = "Flags applicable to an MFIB interfaces",
210 .function = mfib_show_itf_flags,