blob: eb12aa6947504ade8a03fdd889775418f2fc3420 [file] [log] [blame]
Florin Coras04e53442017-07-16 17:12:15 -07001/*
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 */
22transport_proto_vft_t *tp_vfts;
23
24u32
25transport_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
42void
43transport_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
56void
57transport_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 */
75void
76session_register_transport (u8 session_type,
77 const transport_proto_vft_t * vft)
78{
79 vec_validate (tp_vfts, session_type);
80 tp_vfts[session_type] = *vft;
81
82 /* If an offset function is provided, then peek instead of dequeue */
83 session_manager_set_transport_rx_fn (session_type,
84 vft->tx_fifo_offset != 0);
85}
86
87/**
88 * Get transport virtual function table
89 *
90 * @param type - session type (not protocol type)
91 */
92transport_proto_vft_t *
93session_get_transport_vft (u8 session_type)
94{
95 if (session_type >= vec_len (tp_vfts))
96 return 0;
97 return &tp_vfts[session_type];
98}
99
100/*
101 * fd.io coding-style-patch-verification: ON
102 *
103 * Local Variables:
104 * eval: (c-set-style "gnu")
105 * End:
106 */