FD.io VPP  v20.09-rc2-28-g3c5414029
Vector Packet Processing
tunnel.c
Go to the documentation of this file.
1 /*
2  * tunnel.h: shared definitions for tunnels.
3  *
4  * Copyright (c) 2019 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/tunnel/tunnel.h>
19 
20 u8 *
21 format_tunnel_mode (u8 * s, va_list * args)
22 {
23  tunnel_mode_t mode = va_arg (*args, int);
24 
25  switch (mode)
26  {
27 #define _(n, v) case TUNNEL_MODE_##n: \
28  s = format (s, "%s", v); \
29  break;
31 #undef _
32  }
33 
34  return (s);
35 }
36 
37 uword
38 unformat_tunnel_mode (unformat_input_t * input, va_list * args)
39 {
40  tunnel_mode_t *m = va_arg (*args, tunnel_mode_t *);
41 
42  if (unformat (input, "p2p"))
43  *m = TUNNEL_MODE_P2P;
44  else if (unformat (input, "p2mp") || unformat (input, "mp"))
45  *m = TUNNEL_MODE_MP;
46  else
47  return 0;
48  return 1;
49 }
50 
51 u8 *
52 format_tunnel_encap_decap_flags (u8 * s, va_list * args)
53 {
54  tunnel_encap_decap_flags_t f = va_arg (*args, int);
55 
56  if (f == TUNNEL_ENCAP_DECAP_FLAG_NONE)
57  return (format (s, "none"));
58 
59 #define _(a,b,c) if (f & TUNNEL_ENCAP_DECAP_FLAG_##a) s = format(s, "%s ", b);
61 #undef _
62  return (s);
63 }
64 
65 
66 /*
67  * fd.io coding-style-patch-verification: ON
68  *
69  * Local Variables:
70  * eval: (c-set-style "gnu")
71  * End:
72  */
uword unformat_tunnel_mode(unformat_input_t *input, va_list *args)
Definition: tunnel.c:38
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unsigned char u8
Definition: types.h:56
struct _unformat_input_t unformat_input_t
enum tunnel_encap_decap_flags_t_ tunnel_encap_decap_flags_t
vl_api_tunnel_mode_t mode
Definition: gre.api:48
u64 uword
Definition: types.h:112
u8 * format_tunnel_mode(u8 *s, va_list *args)
Definition: tunnel.c:21
u8 * format_tunnel_encap_decap_flags(u8 *s, va_list *args)
Definition: tunnel.c:52
enum tunnel_mode_t_ tunnel_mode_t
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978