tunnel: support copying TTL and flow label from inner to outer
[vpp.git] / src / vnet / tunnel / tunnel.h
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 #ifndef __TUNNEL_H__
19 #define __TUNNEL_H__
20
21 #include <vnet/ip/ip_types.h>
22 #include <vnet/fib/fib_node.h>
23
24 #define foreach_tunnel_mode     \
25   _(P2P, "point-to-point")      \
26   _(MP, "multi-point")          \
27
28 typedef enum tunnel_mode_t_
29 {
30 #define _(n, s) TUNNEL_MODE_##n,
31   foreach_tunnel_mode
32 #undef _
33 } __clib_packed tunnel_mode_t;
34
35 extern u8 *format_tunnel_mode (u8 * s, va_list * args);
36 extern uword unformat_tunnel_mode (unformat_input_t * input, va_list * args);
37
38 /**
39  * Keep these idenitical to those in ipip.api
40  */
41 #define foreach_tunnel_encap_decap_flag                                       \
42   _ (NONE, "none", 0x0)                                                       \
43   _ (ENCAP_COPY_DF, "encap-copy-df", 0x1)                                     \
44   _ (ENCAP_SET_DF, "encap-set-df", 0x2)                                       \
45   _ (ENCAP_COPY_DSCP, "encap-copy-dscp", 0x4)                                 \
46   _ (ENCAP_COPY_ECN, "encap-copy-ecn", 0x8)                                   \
47   _ (DECAP_COPY_ECN, "decap-copy-ecn", 0x10)                                  \
48   _ (ENCAP_INNER_HASH, "encap-inner-hash", 0x20)                              \
49   _ (ENCAP_COPY_HOP_LIMIT, "encap-copy-hop-limit", 0x40)                      \
50   _ (ENCAP_COPY_FLOW_LABEL, "encap-copy-flow-label", 0x80)
51
52 typedef enum tunnel_encap_decap_flags_t_
53 {
54 #define _(a,b,c) TUNNEL_ENCAP_DECAP_FLAG_##a = c,
55   foreach_tunnel_encap_decap_flag
56 #undef _
57 } __clib_packed tunnel_encap_decap_flags_t;
58
59 extern const u8 TUNNEL_ENCAP_DECAP_FLAG_MASK;
60
61 extern u8 *format_tunnel_encap_decap_flags (u8 * s, va_list * args);
62 extern uword unformat_tunnel_encap_decap_flags (unformat_input_t *input,
63                                                 va_list *args);
64
65 #define foreach_tunnel_flag                                                   \
66   _ (RESOLVED, 0, "resolved")                                                 \
67   _ (TRACK_MTU, 1, "track-mtu")
68
69 typedef enum tunnel_flags_t_
70 {
71   TUNNEL_FLAG_NONE = 0,
72 #define _(n, b, s) TUNNEL_FLAG_##n = (1 << b),
73   foreach_tunnel_flag
74 #undef _
75 } __clib_packed tunnel_flags_t;
76
77 extern const u8 TUNNEL_FLAG_MASK;
78
79 extern u8 *format_tunnel_flags (u8 *s, va_list *args);
80 extern uword unformat_tunnel_flags (unformat_input_t *input, va_list *args);
81
82 /**
83  * A representation of an IP tunnel config
84  */
85 typedef struct tunnel_t_
86 {
87   ip_address_t t_src;
88   ip_address_t t_dst;
89   tunnel_encap_decap_flags_t t_encap_decap_flags;
90   tunnel_flags_t t_flags;
91   tunnel_mode_t t_mode;
92   u32 t_table_id;
93   ip_dscp_t t_dscp;
94   u8 t_hop_limit;
95
96   /**
97    * derived data
98    */
99   u32 t_fib_index;
100
101   fib_node_index_t t_fib_entry_index;
102   u32 t_sibling;
103
104 } tunnel_t;
105
106 extern u8 *format_tunnel (u8 *s, va_list *args);
107 extern uword unformat_tunnel (unformat_input_t *input, va_list *args);
108
109 extern void tunnel_copy (const tunnel_t *src, tunnel_t *dst);
110 extern int tunnel_resolve (tunnel_t *t, fib_node_type_t child_type,
111                            index_t child_index);
112 extern void tunnel_unresolve (tunnel_t *t);
113
114 extern ip_address_family_t tunnel_get_af (const tunnel_t *t);
115
116 extern void tunnel_contribute_forwarding (const tunnel_t *t, dpo_id_t *dpo);
117
118 extern void tunnel_build_v6_hdr (const tunnel_t *t, ip_protocol_t next_proto,
119                                  ip6_header_t *ip);
120 extern void tunnel_build_v4_hdr (const tunnel_t *t, ip_protocol_t next_proto,
121                                  ip4_header_t *ip);
122
123 #endif
124
125 /*
126  * fd.io coding-style-patch-verification: ON
127  *
128  * Local Variables:
129  * eval: (c-set-style "gnu")
130  * End:
131  */