Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | #include <vnet/session/transport_interface.h> |
| 17 | #include <vnet/session/session.h> |
| 18 | |
| 19 | /** |
| 20 | * Per-type vector of transport protocol virtual function tables |
| 21 | */ |
| 22 | transport_proto_vft_t *tp_vfts; |
| 23 | |
| 24 | u32 |
| 25 | transport_endpoint_lookup (transport_endpoint_table_t * ht, |
| 26 | ip46_address_t * ip, u16 port) |
| 27 | { |
| 28 | clib_bihash_kv_24_8_t kv; |
| 29 | int rv; |
| 30 | |
| 31 | kv.key[0] = ip->as_u64[0]; |
| 32 | kv.key[1] = ip->as_u64[1]; |
| 33 | kv.key[2] = port; |
| 34 | |
| 35 | rv = clib_bihash_search_inline_24_8 (ht, &kv); |
| 36 | if (rv == 0) |
| 37 | return kv.value; |
| 38 | |
| 39 | return TRANSPORT_ENDPOINT_INVALID_INDEX; |
| 40 | } |
| 41 | |
| 42 | void |
| 43 | transport_endpoint_table_add (transport_endpoint_table_t * ht, |
| 44 | transport_endpoint_t * te, u32 value) |
| 45 | { |
| 46 | clib_bihash_kv_24_8_t kv; |
| 47 | |
| 48 | kv.key[0] = te->ip.as_u64[0]; |
| 49 | kv.key[1] = te->ip.as_u64[1]; |
| 50 | kv.key[2] = te->port; |
| 51 | kv.value = value; |
| 52 | |
| 53 | clib_bihash_add_del_24_8 (ht, &kv, 1); |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | transport_endpoint_table_del (transport_endpoint_table_t * ht, |
| 58 | transport_endpoint_t * te) |
| 59 | { |
| 60 | clib_bihash_kv_24_8_t kv; |
| 61 | |
| 62 | kv.key[0] = te->ip.as_u64[0]; |
| 63 | kv.key[1] = te->ip.as_u64[1]; |
| 64 | kv.key[2] = te->port; |
| 65 | |
| 66 | clib_bihash_add_del_24_8 (ht, &kv, 0); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Register transport virtual function table. |
| 71 | * |
| 72 | * @param type - session type (not protocol type) |
| 73 | * @param vft - virtual function table |
| 74 | */ |
| 75 | void |
Florin Coras | 6881062 | 2017-07-24 17:40:28 -0700 | [diff] [blame^] | 76 | session_register_transport (transport_proto_t transport_proto, u8 is_ip4, |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 77 | const transport_proto_vft_t * vft) |
| 78 | { |
Florin Coras | 6881062 | 2017-07-24 17:40:28 -0700 | [diff] [blame^] | 79 | u8 session_type; |
| 80 | session_type = session_type_from_proto_and_ip (transport_proto, is_ip4); |
| 81 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 82 | vec_validate (tp_vfts, session_type); |
| 83 | tp_vfts[session_type] = *vft; |
| 84 | |
| 85 | /* If an offset function is provided, then peek instead of dequeue */ |
| 86 | session_manager_set_transport_rx_fn (session_type, |
| 87 | vft->tx_fifo_offset != 0); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Get transport virtual function table |
| 92 | * |
| 93 | * @param type - session type (not protocol type) |
| 94 | */ |
| 95 | transport_proto_vft_t * |
| 96 | session_get_transport_vft (u8 session_type) |
| 97 | { |
| 98 | if (session_type >= vec_len (tp_vfts)) |
| 99 | return 0; |
| 100 | return &tp_vfts[session_type]; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * fd.io coding-style-patch-verification: ON |
| 105 | * |
| 106 | * Local Variables: |
| 107 | * eval: (c-set-style "gnu") |
| 108 | * End: |
| 109 | */ |