blob: abd94ba4f1d601fdd69c3744242b8cf96ad2e366 [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
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.h>
17
18u32
19transport_endpoint_lookup (transport_endpoint_table_t *ht, ip46_address_t *ip,
20 u16 port)
21{
22 clib_bihash_kv_24_8_t kv;
23 int rv;
24
25 kv.key[0] = ip->as_u64[0];
26 kv.key[1] = ip->as_u64[1];
27 kv.key[2] = port;
28
29 rv = clib_bihash_search_inline_24_8 (ht, &kv);
30 if (rv == 0)
31 return kv.value;
32
33 return TRANSPORT_ENDPOINT_INVALID_INDEX;
34}
35
36void
37transport_endpoint_table_add (transport_endpoint_table_t *ht,
38 transport_endpoint_t *te, u32 value)
39{
40 clib_bihash_kv_24_8_t kv;
41
42 kv.key[0] = te->ip.as_u64[0];
43 kv.key[1] = te->ip.as_u64[1];
44 kv.key[2] = te->port;
45 kv.value = value;
46
47 clib_bihash_add_del_24_8 (ht, &kv, 1);
48}
49
50void
51transport_endpoint_table_del (transport_endpoint_table_t *ht,
52 transport_endpoint_t *te)
53{
54 clib_bihash_kv_24_8_t kv;
55
56 kv.key[0] = te->ip.as_u64[0];
57 kv.key[1] = te->ip.as_u64[1];
58 kv.key[2] = te->port;
59
60 clib_bihash_add_del_24_8 (ht, &kv, 0);
61}
62
63
64