FD.io VPP  v19.04.2-12-g66b1689
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 int
31  const mfib_prefix_t *p2)
32 {
34  return (0);
35 
36  switch (p1->fp_proto)
37  {
38  case FIB_PROTOCOL_IP4:
40  &p1->fp_grp_addr.ip4,
41  &p2->fp_grp_addr.ip4,
42  p1->fp_len));
43  case FIB_PROTOCOL_IP6:
45  &p1->fp_grp_addr.ip6,
46  &p2->fp_grp_addr.ip6,
47  p1->fp_len));
48  case FIB_PROTOCOL_MPLS:
49  break;
50  }
51  return (0);
52 }
53 
54 int
56 {
57  switch (pfx->fp_proto)
58  {
59  case FIB_PROTOCOL_IP4:
60  return (64 == pfx->fp_len);
61  case FIB_PROTOCOL_IP6:
62  return (256 == pfx->fp_len);
63  case FIB_PROTOCOL_MPLS:
64  ASSERT(0);
65  break;
66  }
67  return (0);
68 }
69 
72 {
73  switch (proto)
74  {
75  case DPO_PROTO_IP4:
77  case DPO_PROTO_IP6:
79  case DPO_PROTO_MPLS:
80  case DPO_PROTO_ETHERNET:
81  case DPO_PROTO_NSH:
82  case DPO_PROTO_BIER:
83  break;
84  }
85  ASSERT(0);
87 }
88 
91 {
92  switch (proto)
93  {
94  case FIB_PROTOCOL_IP4:
96  case FIB_PROTOCOL_IP6:
98  case FIB_PROTOCOL_MPLS:
99  break;
100  }
101  ASSERT(0);
103 }
104 
105 u8 *
106 format_mfib_prefix (u8 * s, va_list * args)
107 {
108  mfib_prefix_t *fp = va_arg (*args, mfib_prefix_t *);
109 
110  /*
111  * protocol specific so it prints ::/0 correctly.
112  */
113  switch (fp->fp_proto)
114  {
115  case FIB_PROTOCOL_IP6:
116  {
117  ip6_address_t p6 = fp->fp_grp_addr.ip6;
118  u32 len = (fp->fp_len > 128 ? 128 : fp->fp_len);
119 
120  ip6_address_mask(&p6, &(ip6_main.fib_masks[len]));
121 
122  if (ip6_address_is_zero(&fp->fp_src_addr.ip6))
123  {
124  s = format(s, "(*, ");
125  }
126  else
127  {
128  s = format (s, "(%U, ", format_ip6_address, &fp->fp_src_addr.ip6);
129  }
130  s = format (s, "%U", format_ip6_address, &p6);
131  s = format (s, "/%d)", len);
132  break;
133  }
134  case FIB_PROTOCOL_IP4:
135  {
136  ip4_address_t p4 = fp->fp_grp_addr.ip4;
137  u32 len = (fp->fp_len > 32 ? 32 : fp->fp_len);
138 
139  p4.as_u32 &= ip4_main.fib_masks[len];
140 
141  if (0 == fp->fp_src_addr.ip4.as_u32)
142  {
143  s = format(s, "(*, ");
144  }
145  else
146  {
147  s = format (s, "(%U, ", format_ip4_address, &fp->fp_src_addr.ip4);
148  }
149  s = format (s, "%U", format_ip4_address, &p4);
150  s = format (s, "/%d)", len);
151  break;
152  }
153  case FIB_PROTOCOL_MPLS:
154  break;
155  }
156 
157  return (s);
158 }
159 
160 u8 *
161 format_mfib_entry_flags (u8 * s, va_list * args)
162 {
165 
166  flags = va_arg (*args, mfib_entry_flags_t);
167 
168  if (MFIB_ENTRY_FLAG_NONE != flags) {
169  s = format(s, " flags:");
171  if ((1<<attr) & flags) {
172  s = format (s, "%s,", mfib_flag_names_long[attr]);
173  }
174  }
175  }
176 
177  return (s);
178 }
179 
180 u8 *
181 format_mfib_itf_flags (u8 * s, va_list * args)
182 {
185 
186  flags = va_arg (*args, mfib_itf_flags_t);
187 
189  if ((1<<attr) & flags) {
190  s = format (s, "%s,", mfib_itf_flag_long_names[attr]);
191  }
192  }
193 
194  return (s);
195 }
196 
197 uword
199  va_list * args)
200 {
201  mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t*);
203 
204  old = *iflags;
206  if (unformat (input, mfib_itf_flag_long_names[attr]))
207  *iflags |= (1 << attr);
208  }
210  if (unformat (input, mfib_itf_flag_names[attr]))
211  *iflags |= (1 << attr);
212  }
213 
214  return (old == *iflags ? 0 : 1);
215 }
216 
217 uword
219  va_list * args)
220 {
221  mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t*);
223 
224  old = *eflags;
226  if (unformat (input, mfib_flag_names_long[attr]))
227  *eflags |= (1 << attr);
228  }
230  if (unformat (input, mfib_flag_names[attr]))
231  *eflags |= (1 << attr);
232  }
233 
234  return (old == *eflags ? 0 : 1);
235 }
236 
237 clib_error_t *
239  unformat_input_t * main_input,
240  vlib_cli_command_t * cmd)
241 {
243 
245  vlib_cli_output(vm, "%s = %s",
246  mfib_flag_names[attr],
247  mfib_flag_names_long[attr]);
248  }
249 
250  return (NULL);
251 }
252 
253 /*?
254  * This command displays the set of supported flags applicable to an MFIB route
255  */
256 /* *INDENT-OFF* */
257 VLIB_CLI_COMMAND (mfib_route_flags_command, static) =
258 {
259  .path = "show mfib route flags",
260  .short_help = "Flags applicable to an MFIB route",
261  .function = mfib_show_route_flags,
262  .is_mp_safe = 1,
263 };
264 /* *INDENT-ON* */
265 
266 clib_error_t *
268  unformat_input_t * main_input,
269  vlib_cli_command_t * cmd)
270 {
272 
274  vlib_cli_output(vm, "%s = %s",
275  mfib_itf_flag_names[attr],
277  }
278 
279  return (NULL);
280 }
281 
282 /*?
283  * This command displays the set of supported flags applicable to an MFIB interface
284  */
285 /* *INDENT-OFF* */
286 VLIB_CLI_COMMAND (mfib_itf_flags_command, static) =
287 {
288  .path = "show mfib itf flags",
289  .short_help = "Flags applicable to an MFIB interfaces",
290  .function = mfib_show_itf_flags,
291  .is_mp_safe = 1,
292 };
293 /* *INDENT-ON* */
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:137
ip46_address_t fp_src_addr
Definition: mfib_types.h:47
u32 flags
Definition: vhost_user.h:115
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:198
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:267
#define NULL
Definition: clib.h:58
static const char * mfib_flag_names_long[]
Definition: mfib_types.c:24
static uword ip4_destination_matches_route(const ip4_main_t *im, const ip4_address_t *key, const ip4_address_t *dest, uword dest_length)
Definition: ip4.h:181
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static void ip6_address_mask(ip6_address_t *a, const ip6_address_t *mask)
Definition: ip6_packet.h:270
fib_forward_chain_type_t mfib_forw_chain_type_from_dpo_proto(dpo_proto_t proto)
Definition: mfib_types.c:71
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
u8 * format_mfib_entry_flags(u8 *s, va_list *args)
Definition: mfib_types.c:161
enum mfib_entry_attribute_t_ mfib_entry_attribute_t
format_function_t format_ip4_address
Definition: format.h:75
static uword ip6_destination_matches_route(const ip6_main_t *im, const ip6_address_t *key, const ip6_address_t *dest, uword dest_length)
Definition: ip6.h:265
unsigned int u32
Definition: types.h:88
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
#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:238
static const char * mfib_flag_names[]
String names for each flag.
Definition: mfib_types.c:23
int mfib_prefix_is_cover(const mfib_prefix_t *p1, const mfib_prefix_t *p2)
Compare two prefixes for covering relationship.
Definition: mfib_types.c:30
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
u8 len
Definition: ip_types.api:49
ip6_address_t fib_masks[129]
Definition: ip6.h:191
uword unformat_mfib_entry_flags(unformat_input_t *input, va_list *args)
Definition: mfib_types.c:218
format_function_t format_ip6_address
Definition: format.h:93
vlib_main_t * vm
Definition: buffer.c:312
static uword ip6_address_is_zero(const ip6_address_t *a)
Definition: ip6_packet.h:301
enum mfib_itf_attribute_t_ mfib_itf_attribute_t
fib_forward_chain_type_t mfib_forw_chain_type_from_fib_proto(fib_protocol_t proto)
Definition: mfib_types.c:90
Aggregrate type for a prefix.
Definition: mfib_types.h:24
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
#define ASSERT(truth)
ip6_main_t ip6_main
Definition: ip6_forward.c:2688
#define MFIB_ENTRY_NAMES_SHORT
Definition: mfib_types.h:87
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
#define MFIB_ITF_NAMES_LONG
Definition: mfib_types.h:140
fib_protocol_t fp_proto
protocol type
Definition: mfib_types.h:33
#define ip46_address_is_equal(a1, a2)
Definition: ip6_packet.h:94
#define MFIB_ITF_NAMES_SHORT
Definition: mfib_types.h:132
u64 uword
Definition: types.h:112
int mfib_prefix_is_host(const mfib_prefix_t *pfx)
Return true is the prefix is a host prefix.
Definition: mfib_types.c:55
u8 * format_mfib_itf_flags(u8 *s, va_list *args)
Definition: mfib_types.c:181
enum mfib_itf_flags_t_ mfib_itf_flags_t
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:905
u16 fp_len
The mask length.
Definition: mfib_types.h:28
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:133
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
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:106
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:109