FD.io VPP  v18.07.1-13-g909ba93
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 
35 typedef enum
36 {
37 #define _(sym, str) IPIP_ERROR_##sym,
39 #undef _
41 } ipip_error_t;
42 
43 /**
44  * @brief IPIP Tunnel key
45  */
46 typedef enum
47 {
51 
52 typedef struct
53 {
54  ip46_address_t src;
55  ip46_address_t dst;
56  ipip_transport_t transport;
58 } __attribute__ ((packed)) ipip_tunnel_key_t;
59 
60 typedef enum
61 {
64 } ipip_mode_t;
65 
66 /**
67  * @brief A representation of a IPIP tunnel
68  */
69 typedef struct
70 {
71  /* Required for pool_get_aligned */
72  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
73 
74  ipip_mode_t mode;
75  ipip_transport_t transport;
77  ip46_address_t tunnel_src;
78  ip46_address_t tunnel_dst;
82  u32 dev_instance; /* Real device instance in tunnel vector */
83  u32 user_instance; /* Instance name being shown to user */
85 
86  union
87  {
88  struct
89  {
93  } p2p;
94  struct
95  {
103  } sixrd;
104  };
105 } ipip_tunnel_t;
106 
107 typedef struct
108 {
113 
114  /* convenience */
117 
118  /* Record used instances */
120 
123 } ipip_main_t;
124 
125 extern ipip_main_t ipip_main;
128 
129 /*
130  * sixrd_get_addr_net
131  */
134 {
135  /* 1:1 mode */
136  if (t->sixrd.ip4_prefix_len == 32)
137  return (t->sixrd.ip4_prefix.as_u32);
138 
139  dal = clib_net_to_host_u64 (dal);
140 
141  /* Grab 32 - ip4_prefix_len bits out of IPv6 address from offset
142  * ip6_prefix_len */
143  u32 mask = ~(~0ULL << (32 - t->sixrd.ip4_prefix_len));
144  u32 ip4 =
145  clib_net_to_host_u32 (t->sixrd.
146  ip4_prefix.as_u32) | ((u32) (dal >> t->sixrd.
147  shift) & mask);
148  return clib_host_to_net_u32 (ip4);
149 }
150 
151 int ipip_add_tunnel (ipip_transport_t transport, u32 instance,
152  ip46_address_t * src, ip46_address_t * dst,
153  u32 fib_index, u8 tc_tos, u32 * sw_if_indexp);
154 int ipip_del_tunnel (u32 sw_if_index);
155 int sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
156  ip4_address_t * ip4_prefix, u8 ip4_prefix_len,
157  ip4_address_t * ip4_src, bool security_check,
158  u32 ip4_fib_index, u32 ip6_fib_index,
159  u32 * sw_if_index);
160 int sixrd_del_tunnel (u32 sw_if_index);
165 
166 #endif
167 
168 /*
169  * fd.io coding-style-patch-verification: ON
170  *
171  * Local Variables:
172  * eval: (c-set-style "gnu")
173  * End:
174  */
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:282
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:63
ipip_mode_t
Definition: ipip.h:60
fib_node_t node
Definition: ipip.h:90
A representation of a IPIP tunnel.
Definition: ipip.h:69
ip46_address_t tunnel_src
Definition: ipip.h:77
unsigned long u64
Definition: types.h:89
vnet_hw_interface_class_t ipip_hw_interface_class
u8 tc_tos
Definition: ipip.h:84
ip4_address_t ip4_prefix
Definition: ipip.h:97
u32 hw_if_index
Definition: ipip.h:80
bool ip4_protocol_registered
Definition: ipip.h:121
unsigned char u8
Definition: types.h:56
fib_node_index_t fib_entry_index
Definition: ipip.h:91
static_always_inline u32 sixrd_get_addr_net(const ipip_tunnel_t *t, u64 dal)
Definition: ipip.h:133
#define static_always_inline
Definition: clib.h:93
ip46_address_t src
Definition: ipip.h:54
u32 user_instance
Definition: ipip.h:83
ipip_tunnel_t * ipip_tunnel_db_find_by_sw_if_index(u32 sw_if_index)
Definition: ipip.c:355
ip46_address_t dst
Definition: ipip.h:55
u32 * tunnel_index_by_sw_if_index
Definition: ipip.h:111
u32 sibling_index
Definition: ipip.h:92
unsigned int u32
Definition: types.h:88
ipip_error_t
Definition: ipip.h:35
ipip_transport_t transport
Definition: ipip.h:56
#define foreach_ipip_error
Definition: ipip.h:29
ipip_tunnel_t * ipip_tunnel_db_find(ipip_tunnel_key_t *key)
Definition: ipip.c:343
u32 ip6_fib_index
Definition: ipip.h:102
ip6_address_t ip6_prefix
Definition: ipip.h:96
ipip_tunnel_t * tunnels
Definition: ipip.h:109
int sixrd_del_tunnel(u32 sw_if_index)
Definition: sixrd.c:387
u8 shift
Definition: ipip.h:100
int ipip_add_tunnel(ipip_transport_t transport, u32 instance, ip46_address_t *src, ip46_address_t *dst, u32 fib_index, u8 tc_tos, u32 *sw_if_indexp)
Definition: ipip.c:463
An node in the FIB graph.
Definition: fib_node.h:287
ipip_tunnel_key_t * key
Definition: ipip.h:76
ipip_transport_t
IPIP Tunnel key.
Definition: ipip.h:46
u32 fib_index
Definition: ipip.h:57
vlib_node_registration_t ipip4_input_node
(constructor) VLIB_REGISTER_NODE (ipip4_input_node)
Definition: node.c:224
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
fib_node_type_t fib_node_type
Definition: ipip.h:112
u32 fib_index
Definition: ipip.h:79
u8 ip6_prefix_len
Definition: ipip.h:98
struct ipip_tunnel_t::@229::@232 sixrd
ipip_transport_t transport
Definition: ipip.h:75
bool security_check
Definition: ipip.h:101
uword * tunnel_by_key
Definition: ipip.h:110
u8 ip4_prefix_len
Definition: ipip.h:99
u32 sw_if_index
Definition: ipip.h:81
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:241
int ipip_del_tunnel(u32 sw_if_index)
Definition: ipip.c:562
vnet_main_t * vnet_main
Definition: ipip.h:116
struct _vnet_hw_interface_class vnet_hw_interface_class_t
bool ip6_protocol_registered
Definition: ipip.h:122
u64 uword
Definition: types.h:112
ipip_mode_t mode
Definition: ipip.h:74
void ipip_tunnel_db_add(ipip_tunnel_t *t, ipip_tunnel_key_t *key)
Definition: ipip.c:367
u32 dev_instance
Definition: ipip.h:82
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
ip46_address_t tunnel_dst
Definition: ipip.h:78
vlib_main_t * vlib_main
Definition: ipip.h:115
ipip_main_t ipip_main
Definition: ipip.c:28
uword * instance_used
Definition: ipip.h:119
void ipip_tunnel_db_remove(ipip_tunnel_t *t)
Definition: ipip.c:377