blob: acf0e4ca4e07bcab0f5fd869a940e4206d6b480d [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#ifndef __TUNNEL_H__
19#define __TUNNEL_H__
20
Neale Rannsa91cb452021-02-04 11:02:52 +000021#include <vnet/ip/ip_types.h>
22#include <vnet/fib/fib_node.h>
Neale Ranns59ff9182019-12-29 23:55:18 +000023
Neale Ranns14053c92019-12-29 23:55:18 +000024#define foreach_tunnel_mode \
Neale Ranns59ff9182019-12-29 23:55:18 +000025 _(P2P, "point-to-point") \
26 _(MP, "multi-point") \
27
28typedef 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
35extern u8 *format_tunnel_mode (u8 * s, va_list * args);
Neale Ranns14053c92019-12-29 23:55:18 +000036extern uword unformat_tunnel_mode (unformat_input_t * input, va_list * args);
Neale Ranns59ff9182019-12-29 23:55:18 +000037
38/**
39 * Keep these idenitical to those in ipip.api
40 */
Neale Rannsa91cb452021-02-04 11:02:52 +000041#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)
Neale Ranns59ff9182019-12-29 23:55:18 +000051
52typedef enum tunnel_encap_decap_flags_t_
53{
54#define _(a,b,c) TUNNEL_ENCAP_DECAP_FLAG_##a = c,
Neale Rannsa91cb452021-02-04 11:02:52 +000055 foreach_tunnel_encap_decap_flag
Neale Ranns59ff9182019-12-29 23:55:18 +000056#undef _
57} __clib_packed tunnel_encap_decap_flags_t;
58
Neale Rannsa91cb452021-02-04 11:02:52 +000059extern const u8 TUNNEL_ENCAP_DECAP_FLAG_MASK;
Neale Ranns59ff9182019-12-29 23:55:18 +000060
61extern u8 *format_tunnel_encap_decap_flags (u8 * s, va_list * args);
Neale Rannsa91cb452021-02-04 11:02:52 +000062extern 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
69typedef 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
77extern const u8 TUNNEL_FLAG_MASK;
78
79extern u8 *format_tunnel_flags (u8 *s, va_list *args);
80extern uword unformat_tunnel_flags (unformat_input_t *input, va_list *args);
81
82/**
83 * A representation of an IP tunnel config
84 */
85typedef 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
106extern u8 *format_tunnel (u8 *s, va_list *args);
107extern uword unformat_tunnel (unformat_input_t *input, va_list *args);
108
109extern void tunnel_copy (const tunnel_t *src, tunnel_t *dst);
110extern int tunnel_resolve (tunnel_t *t, fib_node_type_t child_type,
111 index_t child_index);
112extern void tunnel_unresolve (tunnel_t *t);
113
114extern ip_address_family_t tunnel_get_af (const tunnel_t *t);
115
116extern void tunnel_contribute_forwarding (const tunnel_t *t, dpo_id_t *dpo);
117
118extern void tunnel_build_v6_hdr (const tunnel_t *t, ip_protocol_t next_proto,
119 ip6_header_t *ip);
120extern void tunnel_build_v4_hdr (const tunnel_t *t, ip_protocol_t next_proto,
121 ip4_header_t *ip);
122
Neale Ranns59ff9182019-12-29 23:55:18 +0000123#endif
Neale Rannsa91cb452021-02-04 11:02:52 +0000124
Neale Ranns59ff9182019-12-29 23:55:18 +0000125/*
126 * fd.io coding-style-patch-verification: ON
127 *
128 * Local Variables:
129 * eval: (c-set-style "gnu")
130 * End:
131 */