2 * ipip.h: types/functions for ipip.
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef included_ipip_h
19 #define included_ipip_h
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>
27 extern vnet_hw_interface_class_t ipip_hw_interface_class;
29 #define foreach_ipip_error \
30 /* Must be first. */ \
31 _(DECAP_PKTS, "packets decapsulated") \
32 _(BAD_PROTOCOL, "bad protocol") \
33 _(NO_TUNNEL, "no tunnel")
37 #define _(sym, str) IPIP_ERROR_##sym,
44 * @brief IPIP Tunnel key
54 ipip_transport_t transport;
58 } __attribute__ ((packed)) ipip_tunnel_key_t;
67 * @brief A representation of a IPIP tunnel
71 /* Required for pool_get_aligned */
72 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
75 ipip_transport_t transport;
76 ipip_tunnel_key_t *key;
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 */
90 fib_node_index_t fib_entry_index;
95 ip6_address_t ip6_prefix;
96 ip4_address_t ip4_prefix;
107 ipip_tunnel_t *tunnels;
108 uword *tunnel_by_key;
109 u32 *tunnel_index_by_sw_if_index;
110 fib_node_type_t fib_node_type;
113 vlib_main_t *vlib_main;
114 vnet_main_t *vnet_main;
116 /* Record used instances */
117 uword *instance_used;
119 bool ip4_protocol_registered;
120 bool ip6_protocol_registered;
123 extern ipip_main_t ipip_main;
124 extern vlib_node_registration_t ipip4_input_node;
125 extern vlib_node_registration_t ipip6_input_node;
130 static_always_inline u32
131 sixrd_get_addr_net (const ipip_tunnel_t * t, u64 dal)
134 if (t->sixrd.ip4_prefix_len == 32)
135 return (t->sixrd.ip4_prefix.as_u32);
137 dal = clib_net_to_host_u64 (dal);
139 /* Grab 32 - ip4_prefix_len bits out of IPv6 address from offset
141 u32 mask = ~(~0ULL << (32 - t->sixrd.ip4_prefix_len));
143 clib_net_to_host_u32 (t->sixrd.
144 ip4_prefix.as_u32) | ((u32) (dal >> t->sixrd.
146 return clib_host_to_net_u32 (ip4);
149 int ipip_add_tunnel (ipip_transport_t transport, u32 instance,
150 ip46_address_t * src, ip46_address_t * dst,
151 u32 fib_index, u32 * sw_if_indexp);
152 int ipip_del_tunnel (u32 sw_if_index);
153 int sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len,
154 ip4_address_t * ip4_prefix, u8 ip4_prefix_len,
155 ip4_address_t * ip4_src, bool security_check,
156 u32 fib_index, u32 * sw_if_index);
157 int sixrd_del_tunnel (u32 sw_if_index);
158 void ipip_tunnel_db_add (ipip_tunnel_t * t, ipip_tunnel_key_t * key);
159 void ipip_tunnel_db_remove (ipip_tunnel_t * t);
160 ipip_tunnel_t *ipip_tunnel_db_find (ipip_tunnel_key_t * key);
161 ipip_tunnel_t *ipip_tunnel_db_find_by_sw_if_index (u32 sw_if_index);
166 * fd.io coding-style-patch-verification: ON
169 * eval: (c-set-style "gnu")