Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 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 | |
| 27 | extern vnet_hw_interface_class_t ipip_hw_interface_class; |
| 28 | |
Ole Troan | 4146c65 | 2018-08-08 22:23:19 +0200 | [diff] [blame] | 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") |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 35 | |
| 36 | typedef enum |
| 37 | { |
| 38 | #define _(sym, str) IPIP_ERROR_##sym, |
| 39 | foreach_ipip_error |
| 40 | #undef _ |
| 41 | IPIP_N_ERROR, |
| 42 | } ipip_error_t; |
| 43 | |
| 44 | /** |
| 45 | * @brief IPIP Tunnel key |
| 46 | */ |
| 47 | typedef enum |
| 48 | { |
| 49 | IPIP_TRANSPORT_IP4, |
| 50 | IPIP_TRANSPORT_IP6, |
| 51 | } ipip_transport_t; |
| 52 | |
| 53 | typedef struct |
| 54 | { |
| 55 | ipip_transport_t transport; |
| 56 | u32 fib_index; |
| 57 | ip46_address_t src; |
| 58 | ip46_address_t dst; |
| 59 | } __attribute__ ((packed)) ipip_tunnel_key_t; |
| 60 | |
| 61 | typedef enum |
| 62 | { |
| 63 | IPIP_MODE_P2P = 0, |
| 64 | IPIP_MODE_6RD, |
| 65 | } ipip_mode_t; |
| 66 | |
| 67 | /** |
| 68 | * @brief A representation of a IPIP tunnel |
| 69 | */ |
| 70 | typedef struct |
| 71 | { |
Dave Barach | eb987d3 | 2018-05-03 08:26:39 -0400 | [diff] [blame] | 72 | /* Required for pool_get_aligned */ |
| 73 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 74 | |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 75 | ipip_mode_t mode; |
| 76 | ipip_transport_t transport; |
| 77 | ipip_tunnel_key_t *key; |
| 78 | ip46_address_t tunnel_src; |
| 79 | ip46_address_t tunnel_dst; |
| 80 | u32 fib_index; |
| 81 | u32 hw_if_index; |
| 82 | u32 sw_if_index; |
| 83 | u32 dev_instance; /* Real device instance in tunnel vector */ |
| 84 | u32 user_instance; /* Instance name being shown to user */ |
Ole Troan | d57f636 | 2018-05-24 13:21:43 +0200 | [diff] [blame] | 85 | u8 tc_tos; |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 86 | |
| 87 | union |
| 88 | { |
| 89 | struct |
| 90 | { |
| 91 | fib_node_t node; |
| 92 | fib_node_index_t fib_entry_index; |
| 93 | u32 sibling_index; |
| 94 | } p2p; |
| 95 | struct |
| 96 | { |
| 97 | ip6_address_t ip6_prefix; |
| 98 | ip4_address_t ip4_prefix; |
| 99 | u8 ip6_prefix_len; |
| 100 | u8 ip4_prefix_len; |
| 101 | u8 shift; |
| 102 | bool security_check; |
| 103 | } sixrd; |
| 104 | }; |
| 105 | } ipip_tunnel_t; |
| 106 | |
| 107 | typedef struct |
| 108 | { |
| 109 | ipip_tunnel_t *tunnels; |
| 110 | uword *tunnel_by_key; |
| 111 | u32 *tunnel_index_by_sw_if_index; |
| 112 | fib_node_type_t fib_node_type; |
| 113 | |
| 114 | /* convenience */ |
| 115 | vlib_main_t *vlib_main; |
| 116 | vnet_main_t *vnet_main; |
| 117 | |
| 118 | /* Record used instances */ |
| 119 | uword *instance_used; |
| 120 | |
| 121 | bool ip4_protocol_registered; |
| 122 | bool ip6_protocol_registered; |
| 123 | } ipip_main_t; |
| 124 | |
| 125 | extern ipip_main_t ipip_main; |
| 126 | extern vlib_node_registration_t ipip4_input_node; |
| 127 | extern vlib_node_registration_t ipip6_input_node; |
| 128 | |
| 129 | /* |
| 130 | * sixrd_get_addr_net |
| 131 | */ |
| 132 | static_always_inline u32 |
| 133 | sixrd_get_addr_net (const ipip_tunnel_t * t, u64 dal) |
| 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, |
Ole Troan | d57f636 | 2018-05-24 13:21:43 +0200 | [diff] [blame] | 153 | u32 fib_index, u8 tc_tos, u32 * sw_if_indexp); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 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 fib_index, u32 * sw_if_index); |
| 159 | int sixrd_del_tunnel (u32 sw_if_index); |
| 160 | void ipip_tunnel_db_add (ipip_tunnel_t * t, ipip_tunnel_key_t * key); |
| 161 | void ipip_tunnel_db_remove (ipip_tunnel_t * t); |
| 162 | ipip_tunnel_t *ipip_tunnel_db_find (ipip_tunnel_key_t * key); |
| 163 | ipip_tunnel_t *ipip_tunnel_db_find_by_sw_if_index (u32 sw_if_index); |
| 164 | |
| 165 | #endif |
| 166 | |
| 167 | /* |
| 168 | * fd.io coding-style-patch-verification: ON |
| 169 | * |
| 170 | * Local Variables: |
| 171 | * eval: (c-set-style "gnu") |
| 172 | * End: |
| 173 | */ |