FD.io VPP  v21.06-3-gbb25fbf28
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/tunnel/tunnel.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 {
51 } __clib_packed ipip_transport_t;
52 
53 typedef enum
54 {
58 } __clib_packed ipip_mode_t;
59 
60 typedef struct
61 {
62  ip46_address_t src;
63  ip46_address_t dst;
64  u32 fib_index;
65  ipip_transport_t transport;
66  ipip_mode_t mode;
67  u16 __pad;
68 } __clib_packed ipip_tunnel_key_t;
69 
70 STATIC_ASSERT_SIZEOF (ipip_tunnel_key_t, 5 * sizeof (u64));
71 
72 /**
73  * @brief A representation of a IPIP tunnel
74  */
75 typedef struct
76 {
77  /* Required for pool_get_aligned */
78  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
79 
80  ipip_mode_t mode;
81  ipip_transport_t transport;
82  ip46_address_t tunnel_src;
83  ip46_address_t tunnel_dst;
87  u32 dev_instance; /* Real device instance in tunnel vector */
88  u32 user_instance; /* Instance name being shown to user */
91 
92  struct
93  {
94  ip6_address_t ip6_prefix;
101  } sixrd;
102 } ipip_tunnel_t;
103 
104 typedef struct
105 {
109 
110  /* convenience */
113 
114  /* Record used instances */
116 
119 
121 } ipip_main_t;
122 
123 extern ipip_main_t ipip_main;
126 
127 /*
128  * sixrd_get_addr_net
129  */
132 {
133  /* 1:1 mode */
134  if (t->sixrd.ip4_prefix_len == 32)
135  return (t->sixrd.ip4_prefix.as_u32);
136 
137  dal = clib_net_to_host_u64 (dal);
138 
139  /* Grab 32 - ip4_prefix_len bits out of IPv6 address from offset
140  * ip6_prefix_len */
141  u32 mask = ~(~0ULL << (32 - t->sixrd.ip4_prefix_len));
142  u32 ip4 =
143  clib_net_to_host_u32 (t->sixrd.
144  ip4_prefix.as_u32) | ((u32) (dal >> t->sixrd.
145  shift) & mask);
146  return clib_host_to_net_u32 (ip4);
147 }
148 
149 int ipip_add_tunnel (ipip_transport_t transport, u32 instance,
150  ip46_address_t * src, ip46_address_t * dst,
152  ip_dscp_t dscp, tunnel_mode_t mode, u32 * sw_if_indexp);
154 int sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
155  ip4_address_t * ip4_prefix, u8 ip4_prefix_len,
156  ip4_address_t * ip4_src, bool security_check,
157  u32 ip4_fib_index, u32 ip6_fib_index,
158  u32 * sw_if_index);
160 void ipip_tunnel_db_add (ipip_tunnel_t * t, const ipip_tunnel_key_t * key);
161 void ipip_tunnel_db_remove (ipip_tunnel_t * t, const ipip_tunnel_key_t * key);
162 ipip_tunnel_t *ipip_tunnel_db_find (const ipip_tunnel_key_t * key);
164 void ipip_mk_key (const ipip_tunnel_t * t, ipip_tunnel_key_t * key);
165 void ipip_mk_key_i (ipip_transport_t transport,
166  ipip_mode_t mode,
167  const ip46_address_t * src,
168  const ip46_address_t * dst,
169  u32 fib_index, ipip_tunnel_key_t * key);
170 
171 #endif
172 
173 /*
174  * fd.io coding-style-patch-verification: ON
175  *
176  * Local Variables:
177  * eval: (c-set-style "gnu")
178  * End:
179  */
ipip_main_t::msg_id_base
u16 msg_id_base
Definition: ipip.h:120
IPIP_N_ERROR
@ IPIP_N_ERROR
Definition: ipip.h:41
ipip_main_t::vnet_main
vnet_main_t * vnet_main
Definition: ipip.h:112
adj_types.h
ipip_tunnel_db_find_by_sw_if_index
ipip_tunnel_t * ipip_tunnel_db_find_by_sw_if_index(u32 sw_if_index)
Definition: ipip.c:563
ipip_tunnel_t::shift
u8 shift
Definition: ipip.h:98
ipip_mk_key_i
void ipip_mk_key_i(ipip_transport_t transport, ipip_mode_t mode, const ip46_address_t *src, const ip46_address_t *dst, u32 fib_index, ipip_tunnel_key_t *key)
Definition: ipip.c:591
tunnel_encap_decap_flags_t
enum tunnel_encap_decap_flags_t_ tunnel_encap_decap_flags_t
ip_dscp_t
enum ip_dscp_t_ ip_dscp_t
foreach_ipip_error
#define foreach_ipip_error
Definition: ipip.h:29
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
ipip_tunnel_t::fib_index
u32 fib_index
Definition: ipip.h:84
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
tunnel.h
ipip6_input_node
vlib_node_registration_t ipip6_input_node
(constructor) VLIB_REGISTER_NODE (ipip6_input_node)
Definition: node.c:280
ip4_address_t::as_u32
u32 as_u32
Definition: ip4_packet.h:57
sixrd_del_tunnel
int sixrd_del_tunnel(u32 sw_if_index)
Definition: sixrd.c:374
ipip_tunnel_t::sw_if_index
u32 sw_if_index
Definition: ipip.h:86
u16
unsigned short u16
Definition: types.h:57
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
ipip_error_t
ipip_error_t
Definition: ipip.h:36
ipip_main_t::ip4_protocol_registered
bool ip4_protocol_registered
Definition: ipip.h:117
ipip_main
ipip_main_t ipip_main
Definition: ipip.c:31
ipip_tunnel_t::ip6_prefix_len
u8 ip6_prefix_len
Definition: ipip.h:96
ipip_tunnel_t::transport
ipip_transport_t transport
Definition: ipip.h:81
ipip_tunnel_t::security_check
bool security_check
Definition: ipip.h:99
ipip_tunnel_t::ip4_prefix_len
u8 ip4_prefix_len
Definition: ipip.h:97
ipip_tunnel_t
A representation of a IPIP tunnel.
Definition: ipip.h:75
key
typedef key
Definition: ipsec_types.api:88
ip6_packet.h
ip6_prefix
manual_print typedef ip6_prefix
Definition: ip_types.api:125
ipip_main_t::tunnel_by_key
uword * tunnel_by_key
Definition: ipip.h:107
IPIP_TRANSPORT_IP4
@ IPIP_TRANSPORT_IP4
Definition: ipip.h:49
ipip_hw_interface_class
vnet_hw_interface_class_t ipip_hw_interface_class
ipip_tunnel_t::mode
ipip_mode_t mode
Definition: ipip.h:80
IPIP_MODE_6RD
@ IPIP_MODE_6RD
Definition: ipip.h:57
ipip_main_t::tunnel_index_by_sw_if_index
u32 * tunnel_index_by_sw_if_index
Definition: ipip.h:108
ipip_tunnel_t::dev_instance
u32 dev_instance
Definition: ipip.h:87
format.h
ipip_main_t
Definition: ipip.h:104
ipip_mk_key
void ipip_mk_key(const ipip_tunnel_t *t, ipip_tunnel_key_t *key)
Definition: ipip.c:606
static_always_inline
#define static_always_inline
Definition: clib.h:112
uword
u64 uword
Definition: types.h:112
ipip_tunnel_t::tunnel_dst
ip46_address_t tunnel_dst
Definition: ipip.h:83
ipip_del_tunnel
int ipip_del_tunnel(u32 sw_if_index)
Definition: ipip.c:832
sixrd_get_addr_net
static_always_inline u32 sixrd_get_addr_net(const ipip_tunnel_t *t, u64 dal)
Definition: ipip.h:131
mask
vl_api_pnat_mask_t mask
Definition: pnat.api:45
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
ipip_tunnel_db_add
void ipip_tunnel_db_add(ipip_tunnel_t *t, const ipip_tunnel_key_t *key)
Definition: ipip.c:575
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
ipip_tunnel_t::sixrd
struct ipip_tunnel_t::@420 sixrd
vnet_main_t
Definition: vnet.h:76
ipip_main_t::tunnels
ipip_tunnel_t * tunnels
Definition: ipip.h:106
ipip_add_tunnel
int ipip_add_tunnel(ipip_transport_t transport, u32 instance, ip46_address_t *src, ip46_address_t *dst, u32 fib_index, tunnel_encap_decap_flags_t flags, ip_dscp_t dscp, tunnel_mode_t mode, u32 *sw_if_indexp)
Definition: ipip.c:722
ipip_tunnel_t::ip4_prefix
ip4_address_t ip4_prefix
Definition: ipip.h:95
ipip_tunnel_t::tunnel_src
ip46_address_t tunnel_src
Definition: ipip.h:82
u64
unsigned long u64
Definition: types.h:89
ip.h
u32
unsigned int u32
Definition: types.h:88
ipip_main_t::instance_used
uword * instance_used
Definition: ipip.h:115
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
IPIP_MODE_P2P
@ IPIP_MODE_P2P
Definition: ipip.h:55
sixrd_add_tunnel
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
instance
u32 instance
Definition: gre.api:51
ip4_prefix
manual_print typedef ip4_prefix
Definition: ip_types.api:130
ipip_tunnel_t::hw_if_index
u32 hw_if_index
Definition: ipip.h:85
IPIP_TRANSPORT_IP6
@ IPIP_TRANSPORT_IP6
Definition: ipip.h:50
tunnel_mode_t
enum tunnel_mode_t_ tunnel_mode_t
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
IPIP_MODE_P2MP
@ IPIP_MODE_P2MP
Definition: ipip.h:56
ipip_main_t::vlib_main
vlib_main_t * vlib_main
Definition: ipip.h:111
STATIC_ASSERT_SIZEOF
STATIC_ASSERT_SIZEOF(ipip_tunnel_key_t, 5 *sizeof(u64))
ipip_tunnel_db_find
ipip_tunnel_t * ipip_tunnel_db_find(const ipip_tunnel_key_t *key)
Definition: ipip.c:551
ipip_tunnel_t::user_instance
u32 user_instance
Definition: ipip.h:88
ipip_tunnel_t::flags
tunnel_encap_decap_flags_t flags
Definition: ipip.h:89
ipip4_input_node
vlib_node_registration_t ipip4_input_node
(constructor) VLIB_REGISTER_NODE (ipip4_input_node)
Definition: node.c:264
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ipip_tunnel_t::ip6_fib_index
u32 ip6_fib_index
Definition: ipip.h:100
vnet_hw_interface_class_t
struct _vnet_hw_interface_class vnet_hw_interface_class_t
dscp
vl_api_ip_dscp_t dscp
Definition: dhcp.api:163
ipip_main_t::ip6_protocol_registered
bool ip6_protocol_registered
Definition: ipip.h:118
ipip_tunnel_db_remove
void ipip_tunnel_db_remove(ipip_tunnel_t *t, const ipip_tunnel_key_t *key)
Definition: ipip.c:583
ipip_tunnel_t::ip6_prefix
ip6_address_t ip6_prefix
Definition: ipip.h:94
ipip_tunnel_t::dscp
ip_dscp_t dscp
Definition: ipip.h:90
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105