blob: 38bde34e7f2a2516dcce04ea419e151760944018 [file] [log] [blame]
Neale Ranns59ff9182019-12-29 23:55:18 +00001/*
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
20u8 *
21format_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;
30 foreach_tunnel_mode
31#undef _
32 }
33
34 return (s);
35}
36
Neale Ranns14053c92019-12-29 23:55:18 +000037uword
38unformat_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
Neale Ranns59ff9182019-12-29 23:55:18 +000051u8 *
52format_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);
60 forech_tunnel_encap_decap_flag
61#undef _
62 return (s);
63}
64
Mohammed Hawari59b792f2020-12-01 11:30:57 +010065uword
66unformat_tunnel_encap_decap_flags (unformat_input_t * input, va_list * args)
67{
68 tunnel_encap_decap_flags_t *f =
69 va_arg (*args, tunnel_encap_decap_flags_t *);
70#define _(a,b,c) if (unformat(input, b)) {\
71 *f |= TUNNEL_ENCAP_DECAP_FLAG_##a;\
72 return 1;\
73 }
74 forech_tunnel_encap_decap_flag;
75#undef _
76 return 0;
77}
78
Neale Ranns59ff9182019-12-29 23:55:18 +000079
80/*
81 * fd.io coding-style-patch-verification: ON
82 *
83 * Local Variables:
84 * eval: (c-set-style "gnu")
85 * End:
86 */