FD.io VPP  v18.04-17-g3a0d853
Vector Packet Processing
mfib_types.c
Go to the documentation of this file.
1  /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include <vnet/mfib/mfib_types.h>
17 
18 #include <vnet/ip/ip.h>
19 
20 /**
21  * String names for each flag
22  */
23 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
25 
28 
29 u8 *
30 format_mfib_prefix (u8 * s, va_list * args)
31 {
32  mfib_prefix_t *fp = va_arg (*args, mfib_prefix_t *);
33 
34  /*
35  * protocol specific so it prints ::/0 correctly.
36  */
37  switch (fp->fp_proto)
38  {
39  case FIB_PROTOCOL_IP6:
40  {
41  ip6_address_t p6 = fp->fp_grp_addr.ip6;
42  u32 len = (fp->fp_len > 128 ? 128 : fp->fp_len);
43 
44  ip6_address_mask(&p6, &(ip6_main.fib_masks[len]));
45 
46  if (ip6_address_is_zero(&fp->fp_src_addr.ip6))
47  {
48  s = format(s, "(*, ");
49  }
50  else
51  {
52  s = format (s, "(%U, ", format_ip6_address, &fp->fp_src_addr.ip6);
53  }
54  s = format (s, "%U", format_ip6_address, &p6);
55  s = format (s, "/%d)", len);
56  break;
57  }
58  case FIB_PROTOCOL_IP4:
59  {
60  ip4_address_t p4 = fp->fp_grp_addr.ip4;
61  u32 len = (fp->fp_len > 32 ? 32 : fp->fp_len);
62 
63  p4.as_u32 &= ip4_main.fib_masks[len];
64 
65  if (0 == fp->fp_src_addr.ip4.as_u32)
66  {
67  s = format(s, "(*, ");
68  }
69  else
70  {
71  s = format (s, "(%U, ", format_ip4_address, &fp->fp_src_addr.ip4);
72  }
73  s = format (s, "%U", format_ip4_address, &p4);
74  s = format (s, "/%d)", len);
75  break;
76  }
77  case FIB_PROTOCOL_MPLS:
78  break;
79  }
80 
81  return (s);
82 }
83 
84 u8 *
85 format_mfib_entry_flags (u8 * s, va_list * args)
86 {
89 
90  flags = va_arg (*args, mfib_entry_flags_t);
91 
92  if (MFIB_ENTRY_FLAG_NONE != flags) {
93  s = format(s, " flags:");
95  if ((1<<attr) & flags) {
96  s = format (s, "%s,", mfib_flag_names[attr]);
97  }
98  }
99  }
100 
101  return (s);
102 }
103 
104 u8 *
105 format_mfib_itf_flags (u8 * s, va_list * args)
106 {
109 
110  flags = va_arg (*args, mfib_itf_flags_t);
111 
113  if ((1<<attr) & flags) {
114  s = format (s, "%s,", mfib_itf_flag_long_names[attr]);
115  }
116  }
117 
118  return (s);
119 }
120 
121 uword
123  va_list * args)
124 {
125  mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t*);
127 
128  old = *iflags;
130  if (unformat (input, mfib_itf_flag_long_names[attr]))
131  *iflags |= (1 << attr);
132  }
134  if (unformat (input, mfib_itf_flag_names[attr]))
135  *iflags |= (1 << attr);
136  }
137 
138  return (old == *iflags ? 0 : 1);
139 }
140 
141 uword
143  va_list * args)
144 {
145  mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t*);
147 
148  old = *eflags;
150  if (unformat (input, mfib_flag_names[attr]))
151  *eflags |= (1 << attr);
152  }
153 
154  return (old == *eflags ? 0 : 1);
155 }
156 
157 clib_error_t *
159  unformat_input_t * main_input,
160  vlib_cli_command_t * cmd)
161 {
163 
165  vlib_cli_output(vm, "%s = %s",
166  mfib_flag_names[attr],
167  mfib_flag_names_long[attr]);
168  }
169 
170  return (NULL);
171 }
172 
173 /*?
174  * This command displays the set of supported flags applicable to an MFIB route
175  */
176 /* *INDENT-OFF* */
177 VLIB_CLI_COMMAND (mfib_route_flags_command, static) =
178 {
179  .path = "show mfib route flags",
180  .short_help = "Flags applicable to an MFIB route",
181  .function = mfib_show_route_flags,
182  .is_mp_safe = 1,
183 };
184 /* *INDENT-ON* */
185 
186 clib_error_t *
188  unformat_input_t * main_input,
189  vlib_cli_command_t * cmd)
190 {
192 
194  vlib_cli_output(vm, "%s = %s",
195  mfib_itf_flag_names[attr],
197  }
198 
199  return (NULL);
200 }
201 
202 /*?
203  * This command displays the set of supported flags applicable to an MFIB interface
204  */
205 /* *INDENT-OFF* */
206 VLIB_CLI_COMMAND (mfib_itf_flags_command, static) =
207 {
208  .path = "show mfib itf flags",
209  .short_help = "Flags applicable to an MFIB interfaces",
210  .function = mfib_show_itf_flags,
211  .is_mp_safe = 1,
212 };
213 /* *INDENT-ON* */
static void ip6_address_mask(ip6_address_t *a, ip6_address_t *mask)
Definition: ip6_packet.h:236
ip46_address_t fp_src_addr
Definition: mfib_types.h:47
enum mfib_entry_flags_t_ mfib_entry_flags_t
uword unformat_mfib_itf_flags(unformat_input_t *input, va_list *args)
Definition: mfib_types.c:122
clib_error_t * mfib_show_itf_flags(vlib_main_t *vm, unformat_input_t *main_input, vlib_cli_command_t *cmd)
Definition: mfib_types.c:187
#define NULL
Definition: clib.h:55
static const char * mfib_flag_names_long[]
Definition: mfib_types.c:24
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u8 * format_mfib_entry_flags(u8 *s, va_list *args)
Definition: mfib_types.c:85
enum mfib_entry_attribute_t_ mfib_entry_attribute_t
format_function_t format_ip4_address
Definition: format.h:79
#define FOR_EACH_MFIB_ITF_ATTRIBUTE(_item)
Definition: mfib_types.h:127
#define FOR_EACH_MFIB_ATTRIBUTE(_item)
Definition: mfib_types.h:82
clib_error_t * mfib_show_route_flags(vlib_main_t *vm, unformat_input_t *main_input, vlib_cli_command_t *cmd)
Definition: mfib_types.c:158
static const char * mfib_flag_names[]
String names for each flag.
Definition: mfib_types.c:23
static const char * mfib_itf_flag_names[]
Definition: mfib_types.c:27
struct _unformat_input_t unformat_input_t
#define MFIB_ENTRY_NAMES_LONG
Definition: mfib_types.h:96
ip6_address_t fib_masks[129]
Definition: ip6.h:173
uword unformat_mfib_entry_flags(unformat_input_t *input, va_list *args)
Definition: mfib_types.c:142
format_function_t format_ip6_address
Definition: format.h:95
vlib_main_t * vm
Definition: buffer.c:294
enum mfib_itf_attribute_t_ mfib_itf_attribute_t
Aggregrate type for a prefix.
Definition: mfib_types.h:24
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
static uword ip6_address_is_zero(ip6_address_t *a)
Definition: ip6_packet.h:267
unsigned int u32
Definition: types.h:88
ip6_main_t ip6_main
Definition: ip6_forward.c:2750
#define MFIB_ENTRY_NAMES_SHORT
Definition: mfib_types.h:87
#define MFIB_ITF_NAMES_LONG
Definition: mfib_types.h:140
u64 uword
Definition: types.h:112
fib_protocol_t fp_proto
protocol type
Definition: mfib_types.h:33
unsigned char u8
Definition: types.h:56
#define MFIB_ITF_NAMES_SHORT
Definition: mfib_types.h:132
u8 * format_mfib_itf_flags(u8 *s, va_list *args)
Definition: mfib_types.c:105
enum mfib_itf_flags_t_ mfib_itf_flags_t
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:818
u16 fp_len
The mask length.
Definition: mfib_types.h:28
u32 flags
Definition: vhost-user.h:77
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
static const char * mfib_itf_flag_long_names[]
Definition: mfib_types.c:26
u8 * format_mfib_prefix(u8 *s, va_list *args)
Definition: mfib_types.c:30
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
ip46_address_t fp_grp_addr
The address type is not deriveable from the fp_addr member.
Definition: mfib_types.h:46
u32 fib_masks[33]
Definition: ip4.h:108