Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #ifndef VNET_VNET_URI_TRANSPORT_H_ |
| 17 | #define VNET_VNET_URI_TRANSPORT_H_ |
| 18 | |
| 19 | #include <vnet/vnet.h> |
| 20 | #include <vnet/ip/ip.h> |
| 21 | #include <vppinfra/bihash_16_8.h> |
| 22 | #include <vppinfra/bihash_48_8.h> |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 23 | #include <vnet/tcp/tcp_debug.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 24 | /* |
| 25 | * Protocol independent transport properties associated to a session |
| 26 | */ |
| 27 | typedef struct _transport_connection |
| 28 | { |
| 29 | ip46_address_t rmt_ip; /**< Remote IP */ |
| 30 | ip46_address_t lcl_ip; /**< Local IP */ |
| 31 | u16 lcl_port; /**< Local port */ |
| 32 | u16 rmt_port; /**< Remote port */ |
Florin Coras | f6359c8 | 2017-06-19 12:26:09 -0400 | [diff] [blame^] | 33 | u8 proto; /**< Protocol id (also session type) */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 34 | |
| 35 | u32 s_index; /**< Parent session index */ |
| 36 | u32 c_index; /**< Connection index in transport pool */ |
| 37 | u8 is_ip4; /**< Flag if IP4 connection */ |
| 38 | u32 thread_index; /**< Worker-thread index */ |
| 39 | |
Florin Coras | f6359c8 | 2017-06-19 12:26:09 -0400 | [diff] [blame^] | 40 | fib_node_index_t rmt_fei; /**< FIB entry index for rmt */ |
| 41 | dpo_id_t rmt_dpo; /**< Forwarding DPO for rmt */ |
| 42 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 43 | #if TRANSPORT_DEBUG |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 44 | elog_track_t elog_track; /**< Event logging */ |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 45 | u32 cc_stat_tstamp; /**< CC stats timestamp */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 46 | #endif |
| 47 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 48 | /** Macros for 'derived classes' where base is named "connection" */ |
| 49 | #define c_lcl_ip connection.lcl_ip |
| 50 | #define c_rmt_ip connection.rmt_ip |
| 51 | #define c_lcl_ip4 connection.lcl_ip.ip4 |
| 52 | #define c_rmt_ip4 connection.rmt_ip.ip4 |
| 53 | #define c_lcl_ip6 connection.lcl_ip.ip6 |
| 54 | #define c_rmt_ip6 connection.rmt_ip.ip6 |
| 55 | #define c_lcl_port connection.lcl_port |
| 56 | #define c_rmt_port connection.rmt_port |
| 57 | #define c_proto connection.proto |
| 58 | #define c_state connection.state |
| 59 | #define c_s_index connection.s_index |
| 60 | #define c_c_index connection.c_index |
| 61 | #define c_is_ip4 connection.is_ip4 |
| 62 | #define c_thread_index connection.thread_index |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 63 | #define c_elog_track connection.elog_track |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 64 | #define c_cc_stat_tstamp connection.cc_stat_tstamp |
Florin Coras | f6359c8 | 2017-06-19 12:26:09 -0400 | [diff] [blame^] | 65 | #define c_rmt_fei connection.rmt_fei |
| 66 | #define c_rmt_dpo connection.rmt_dpo |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 67 | } transport_connection_t; |
| 68 | |
| 69 | /* |
| 70 | * Transport protocol virtual function table |
| 71 | */ |
| 72 | typedef struct _transport_proto_vft |
| 73 | { |
| 74 | /* |
| 75 | * Setup |
| 76 | */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 77 | u32 (*bind) (u32, ip46_address_t *, u16); |
| 78 | u32 (*unbind) (u32); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 79 | int (*open) (ip46_address_t * addr, u16 port_host_byte_order); |
| 80 | void (*close) (u32 conn_index, u32 thread_index); |
| 81 | void (*cleanup) (u32 conn_index, u32 thread_index); |
| 82 | |
| 83 | /* |
| 84 | * Transmission |
| 85 | */ |
| 86 | u32 (*push_header) (transport_connection_t * tconn, vlib_buffer_t * b); |
| 87 | u16 (*send_mss) (transport_connection_t * tc); |
| 88 | u32 (*send_space) (transport_connection_t * tc); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 89 | u32 (*tx_fifo_offset) (transport_connection_t * tc); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Connection retrieval |
| 93 | */ |
| 94 | transport_connection_t *(*get_connection) (u32 conn_idx, u32 thread_idx); |
| 95 | transport_connection_t *(*get_listener) (u32 conn_index); |
| 96 | transport_connection_t *(*get_half_open) (u32 conn_index); |
| 97 | |
| 98 | /* |
| 99 | * Format |
| 100 | */ |
| 101 | u8 *(*format_connection) (u8 * s, va_list * args); |
| 102 | u8 *(*format_listener) (u8 * s, va_list * args); |
| 103 | u8 *(*format_half_open) (u8 * s, va_list * args); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 104 | } transport_proto_vft_t; |
| 105 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 106 | /* *INDENT-OFF* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 107 | /* 16 octets */ |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 108 | typedef CLIB_PACKED (struct { |
| 109 | union |
| 110 | { |
| 111 | struct |
| 112 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 113 | ip4_address_t src; |
| 114 | ip4_address_t dst; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 115 | u16 src_port; |
| 116 | u16 dst_port; |
| 117 | /* align by making this 4 octets even though its a 1-bit field |
| 118 | * NOTE: avoid key overlap with other transports that use 5 tuples for |
| 119 | * session identification. |
| 120 | */ |
| 121 | u32 proto; |
| 122 | }; |
| 123 | u64 as_u64[2]; |
| 124 | }; |
| 125 | }) v4_connection_key_t; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 126 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 127 | typedef CLIB_PACKED (struct { |
| 128 | union |
| 129 | { |
| 130 | struct |
| 131 | { |
| 132 | /* 48 octets */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 133 | ip6_address_t src; |
| 134 | ip6_address_t dst; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 135 | u16 src_port; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 136 | u16 dst_port; |
| 137 | u32 proto; |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 138 | u64 unused; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 139 | }; |
| 140 | u64 as_u64[6]; |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 141 | }; |
| 142 | }) v6_connection_key_t; |
| 143 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 144 | |
| 145 | typedef clib_bihash_kv_16_8_t session_kv4_t; |
| 146 | typedef clib_bihash_kv_48_8_t session_kv6_t; |
| 147 | |
| 148 | always_inline void |
| 149 | make_v4_ss_kv (session_kv4_t * kv, ip4_address_t * lcl, ip4_address_t * rmt, |
| 150 | u16 lcl_port, u16 rmt_port, u8 proto) |
| 151 | { |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 152 | v4_connection_key_t *key = (v4_connection_key_t *) kv->key; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 153 | |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 154 | key->src.as_u32 = lcl->as_u32; |
| 155 | key->dst.as_u32 = rmt->as_u32; |
| 156 | key->src_port = lcl_port; |
| 157 | key->dst_port = rmt_port; |
| 158 | key->proto = proto; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 159 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 160 | kv->value = ~0ULL; |
| 161 | } |
| 162 | |
| 163 | always_inline void |
| 164 | make_v4_listener_kv (session_kv4_t * kv, ip4_address_t * lcl, u16 lcl_port, |
| 165 | u8 proto) |
| 166 | { |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 167 | v4_connection_key_t *key = (v4_connection_key_t *) kv->key; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 168 | |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 169 | key->src.as_u32 = lcl->as_u32; |
| 170 | key->dst.as_u32 = 0; |
| 171 | key->src_port = lcl_port; |
| 172 | key->dst_port = 0; |
| 173 | key->proto = proto; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 174 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 175 | kv->value = ~0ULL; |
| 176 | } |
| 177 | |
| 178 | always_inline void |
| 179 | make_v4_ss_kv_from_tc (session_kv4_t * kv, transport_connection_t * t) |
| 180 | { |
| 181 | return make_v4_ss_kv (kv, &t->lcl_ip.ip4, &t->rmt_ip.ip4, t->lcl_port, |
| 182 | t->rmt_port, t->proto); |
| 183 | } |
| 184 | |
| 185 | always_inline void |
| 186 | make_v6_ss_kv (session_kv6_t * kv, ip6_address_t * lcl, ip6_address_t * rmt, |
| 187 | u16 lcl_port, u16 rmt_port, u8 proto) |
| 188 | { |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 189 | v6_connection_key_t *key = (v6_connection_key_t *) kv->key; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 190 | |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 191 | key->src.as_u64[0] = lcl->as_u64[0]; |
| 192 | key->src.as_u64[1] = lcl->as_u64[1]; |
| 193 | key->dst.as_u64[0] = rmt->as_u64[0]; |
| 194 | key->dst.as_u64[1] = rmt->as_u64[1]; |
| 195 | key->src_port = lcl_port; |
| 196 | key->dst_port = rmt_port; |
| 197 | key->proto = proto; |
| 198 | key->unused = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 199 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 200 | kv->value = ~0ULL; |
| 201 | } |
| 202 | |
| 203 | always_inline void |
| 204 | make_v6_listener_kv (session_kv6_t * kv, ip6_address_t * lcl, u16 lcl_port, |
| 205 | u8 proto) |
| 206 | { |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 207 | v6_connection_key_t *key = (v6_connection_key_t *) kv->key; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 208 | |
Clement Durand | da7567c | 2017-05-04 08:33:55 +0200 | [diff] [blame] | 209 | key->src.as_u64[0] = lcl->as_u64[0]; |
| 210 | key->src.as_u64[1] = lcl->as_u64[1]; |
| 211 | key->dst.as_u64[0] = 0; |
| 212 | key->dst.as_u64[1] = 0; |
| 213 | key->src_port = lcl_port; |
| 214 | key->dst_port = 0; |
| 215 | key->proto = proto; |
| 216 | key->unused = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 217 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 218 | kv->value = ~0ULL; |
| 219 | } |
| 220 | |
| 221 | always_inline void |
| 222 | make_v6_ss_kv_from_tc (session_kv6_t * kv, transport_connection_t * t) |
| 223 | { |
| 224 | make_v6_ss_kv (kv, &t->lcl_ip.ip6, &t->rmt_ip.ip6, t->lcl_port, |
| 225 | t->rmt_port, t->proto); |
| 226 | } |
| 227 | |
| 228 | typedef struct _transport_endpoint |
| 229 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 230 | ip46_address_t ip; /** ip address */ |
| 231 | u16 port; /** port in host order */ |
| 232 | u8 is_ip4; /** 1 if ip4 */ |
| 233 | u32 vrf; /** fib table the endpoint is associated with */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 234 | } transport_endpoint_t; |
| 235 | |
| 236 | typedef clib_bihash_24_8_t transport_endpoint_table_t; |
| 237 | |
| 238 | #define TRANSPORT_ENDPOINT_INVALID_INDEX ((u32)~0) |
| 239 | |
| 240 | u32 |
| 241 | transport_endpoint_lookup (transport_endpoint_table_t * ht, |
| 242 | ip46_address_t * ip, u16 port); |
| 243 | void transport_endpoint_table_add (transport_endpoint_table_t * ht, |
| 244 | transport_endpoint_t * te, u32 value); |
| 245 | void transport_endpoint_table_del (transport_endpoint_table_t * ht, |
| 246 | transport_endpoint_t * te); |
| 247 | |
| 248 | #endif /* VNET_VNET_URI_TRANSPORT_H_ */ |
| 249 | |
| 250 | /* |
| 251 | * fd.io coding-style-patch-verification: ON |
| 252 | * |
| 253 | * Local Variables: |
| 254 | * eval: (c-set-style "gnu") |
| 255 | * End: |
| 256 | */ |