FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
ipip.h
Go to the documentation of this file.
1 /*
2  * ipip.h: types/functions for ipip.
3  *
4  * Copyright (c) 2018 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 aipiped 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 included_ipip_h
19 #define included_ipip_h
20 
21 #include <vnet/adj/adj_types.h>
22 #include <vnet/ip/ip6_packet.h>
23 #include <vnet/ip/format.h>
24 #include <vnet/ip/ip.h>
25 #include <vnet/vnet.h>
26 
28 
29 #define foreach_ipip_error \
30  /* Must be first. */ \
31  _(DECAP_PKTS, "packets decapsulated") \
32  _(BAD_PROTOCOL, "bad protocol") \
33  _(NO_TUNNEL, "no tunnel") \
34  _(FRAGMENTED_PACKET, "fragmented outer packet")
35 
36 typedef enum
37 {
38 #define _(sym, str) IPIP_ERROR_##sym,
40 #undef _
42 } ipip_error_t;
43 
44 /**
45  * @brief IPIP Tunnel key
46  */
47 typedef enum
48 {
52 
53 typedef struct
54 {
55  ip46_address_t src;
56  ip46_address_t dst;
57  ipip_transport_t transport;
59 } __attribute__ ((packed)) ipip_tunnel_key_t;
60 
61 typedef enum
62 {
65 } ipip_mode_t;
66 
67 /**
68  * Keep these idenitical to those in ipip.api
69  */
70 #define forech_ipip_tunnel_flag \
71  _(NONE, "none", 0x0) \
72  _(ENCAP_COPY_DF, "encap-copy-df", 0x1) \
73  _(ENCAP_SET_DF, "encap-set-df", 0x2) \
74  _(ENCAP_COPY_DSCP, "encap-copy-dscp", 0x4) \
75  _(ENCAP_COPY_ECN, "encap-copy-ecn", 0x8) \
76  _(DECAP_COPY_ECN, "decap-copy-ecn", 0x10)
77 
79 {
80 #define _(a,b,c) IPIP_TUNNEL_FLAG_##a = c,
82 #undef _
83 } __clib_packed ipip_tunnel_flags_t;
84 
85 #define IPIP_TUNNEL_FLAG_MASK (0x1f)
86 
87 extern u8 *format_ipip_tunnel_flags (u8 * s, va_list * args);
88 
89 /**
90  * @brief A representation of a IPIP tunnel
91  */
92 typedef struct
93 {
94  /* Required for pool_get_aligned */
95  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
96 
97  ipip_mode_t mode;
98  ipip_transport_t transport;
100  ip46_address_t tunnel_src;
101  ip46_address_t tunnel_dst;
105  u32 dev_instance; /* Real device instance in tunnel vector */
106  u32 user_instance; /* Instance name being shown to user */
107  ipip_tunnel_flags_t flags;
109 
110  struct
111  {
119  } sixrd;
120 } ipip_tunnel_t;
121 
122 typedef struct
123 {
127 
128  /* convenience */
131 
132  /* Record used instances */
134 
137 
139 } ipip_main_t;
140 
141 extern ipip_main_t ipip_main;
144 
145 /*
146  * sixrd_get_addr_net
147  */
150 {
151  /* 1:1 mode */
152  if (t->sixrd.ip4_prefix_len == 32)
153  return (t->sixrd.ip4_prefix.as_u32);
154 
155  dal = clib_net_to_host_u64 (dal);
156 
157  /* Grab 32 - ip4_prefix_len bits out of IPv6 address from offset
158  * ip6_prefix_len */
159  u32 mask = ~(~0ULL << (32 - t->sixrd.ip4_prefix_len));
160  u32 ip4 =
161  clib_net_to_host_u32 (t->sixrd.
162  ip4_prefix.as_u32) | ((u32) (dal >> t->sixrd.
163  shift) & mask);
164  return clib_host_to_net_u32 (ip4);
165 }
166 
167 int ipip_add_tunnel (ipip_transport_t transport, u32 instance,
168  ip46_address_t * src, ip46_address_t * dst,
169  u32 fib_index, ipip_tunnel_flags_t flags,
170  ip_dscp_t dscp, u32 * sw_if_indexp);
171 int ipip_del_tunnel (u32 sw_if_index);
172 int sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
173  ip4_address_t * ip4_prefix, u8 ip4_prefix_len,
174  ip4_address_t * ip4_src, bool security_check,
175  u32 ip4_fib_index, u32 ip6_fib_index,
176  u32 * sw_if_index);
177 int sixrd_del_tunnel (u32 sw_if_index);
182 
183 #endif
184 
185 /*
186  * fd.io coding-style-patch-verification: ON
187  *
188  * Local Variables:
189  * eval: (c-set-style "gnu")
190  * End:
191  */
int sixrd_add_tunnel(ip6_address_t *ip6_prefix, u8 ip6_prefix_len, ip4_address_t *ip4_prefix, u8 ip4_prefix_len, ip4_address_t *ip4_src, bool security_check, u32 ip4_fib_index, u32 ip6_fib_index, u32 *sw_if_index)
Definition: sixrd.c:271
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
ipip_mode_t
Definition: ipip.h:61
A representation of a IPIP tunnel.
Definition: ipip.h:92
ip46_address_t tunnel_src
Definition: ipip.h:100
u8 * format_ipip_tunnel_flags(u8 *s, va_list *args)
Definition: ipip.c:269
unsigned long u64
Definition: types.h:89
vnet_hw_interface_class_t ipip_hw_interface_class
ipip_tunnel_flags_t flags
Definition: ipip.h:107
ip4_address_t ip4_prefix
Definition: ipip.h:113
u32 hw_if_index
Definition: ipip.h:103
bool ip4_protocol_registered
Definition: ipip.h:135
unsigned char u8
Definition: types.h:56
int ipip_add_tunnel(ipip_transport_t transport, u32 instance, ip46_address_t *src, ip46_address_t *dst, u32 fib_index, ipip_tunnel_flags_t flags, ip_dscp_t dscp, u32 *sw_if_indexp)
Definition: ipip.c:414
static_always_inline u32 sixrd_get_addr_net(const ipip_tunnel_t *t, u64 dal)
Definition: ipip.h:149
#define static_always_inline
Definition: clib.h:99
ip46_address_t src
Definition: ipip.h:55
u32 user_instance
Definition: ipip.h:106
ipip_tunnel_t * ipip_tunnel_db_find_by_sw_if_index(u32 sw_if_index)
Definition: ipip.c:382
ip46_address_t dst
Definition: ipip.h:56
u32 * tunnel_index_by_sw_if_index
Definition: ipip.h:126
unsigned int u32
Definition: types.h:88
ipip_error_t
Definition: ipip.h:36
ipip_transport_t transport
Definition: ipip.h:57
#define foreach_ipip_error
Definition: ipip.h:29
ipip_tunnel_t * ipip_tunnel_db_find(ipip_tunnel_key_t *key)
Definition: ipip.c:370
u32 ip6_fib_index
Definition: ipip.h:118
ip6_address_t ip6_prefix
Definition: ipip.h:112
unsigned short u16
Definition: types.h:57
ipip_tunnel_t * tunnels
Definition: ipip.h:124
int sixrd_del_tunnel(u32 sw_if_index)
Definition: sixrd.c:376
u8 shift
Definition: ipip.h:116
ipip_tunnel_key_t * key
Definition: ipip.h:99
ip_dscp_t dscp
Definition: ipip.h:108
ipip_transport_t
IPIP Tunnel key.
Definition: ipip.h:47
u32 fib_index
Definition: ipip.h:58
vlib_node_registration_t ipip4_input_node
(constructor) VLIB_REGISTER_NODE (ipip4_input_node)
Definition: node.c:262
u32 fib_index
Definition: ipip.h:102
u8 ip6_prefix_len
Definition: ipip.h:114
ipip_transport_t transport
Definition: ipip.h:98
enum ip_dscp_t_ ip_dscp_t
ipip_tunnel_flags_t_
Definition: ipip.h:78
bool security_check
Definition: ipip.h:117
uword * tunnel_by_key
Definition: ipip.h:125
u8 ip4_prefix_len
Definition: ipip.h:115
enum ipip_tunnel_flags_t_ ipip_tunnel_flags_t
u32 sw_if_index
Definition: ipip.h:104
struct _vlib_node_registration vlib_node_registration_t
vlib_node_registration_t ipip6_input_node
(constructor) VLIB_REGISTER_NODE (ipip6_input_node)
Definition: node.c:278
#define forech_ipip_tunnel_flag
Keep these idenitical to those in ipip.api.
Definition: ipip.h:70
int ipip_del_tunnel(u32 sw_if_index)
Definition: ipip.c:512
vnet_main_t * vnet_main
Definition: ipip.h:130
struct _vnet_hw_interface_class vnet_hw_interface_class_t
bool ip6_protocol_registered
Definition: ipip.h:136
u64 uword
Definition: types.h:112
ipip_mode_t mode
Definition: ipip.h:97
u16 msg_id_base
Definition: ipip.h:138
void ipip_tunnel_db_add(ipip_tunnel_t *t, ipip_tunnel_key_t *key)
Definition: ipip.c:394
struct ipip_tunnel_t::@338 sixrd
u32 dev_instance
Definition: ipip.h:105
ip46_address_t tunnel_dst
Definition: ipip.h:101
u32 ip4
Definition: one.api:440
vlib_main_t * vlib_main
Definition: ipip.h:129
ipip_main_t ipip_main
Definition: ipip.c:29
uword * instance_used
Definition: ipip.h:133
void ipip_tunnel_db_remove(ipip_tunnel_t *t)
Definition: ipip.c:404