2 * Copyright (c) 2020 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __CNAT_INLINE_H__
18 #define __CNAT_INLINE_H__
20 #include <cnat/cnat_types.h>
23 cnat_timestamp_new (f64 t)
27 clib_rwlock_writer_lock (&cnat_main.ts_lock);
28 pool_get (cnat_timestamps, ts);
30 ts->lifetime = cnat_main.session_max_age;
31 ts->refcnt = CNAT_TIMESTAMP_INIT_REFCNT;
32 index = ts - cnat_timestamps;
33 clib_rwlock_writer_unlock (&cnat_main.ts_lock);
38 cnat_timestamp_inc_refcnt (u32 index)
40 clib_rwlock_reader_lock (&cnat_main.ts_lock);
41 cnat_timestamp_t *ts = pool_elt_at_index (cnat_timestamps, index);
43 clib_rwlock_reader_unlock (&cnat_main.ts_lock);
47 cnat_timestamp_update (u32 index, f64 t)
49 clib_rwlock_reader_lock (&cnat_main.ts_lock);
50 cnat_timestamp_t *ts = pool_elt_at_index (cnat_timestamps, index);
52 clib_rwlock_reader_unlock (&cnat_main.ts_lock);
56 cnat_timestamp_set_lifetime (u32 index, u16 lifetime)
58 clib_rwlock_reader_lock (&cnat_main.ts_lock);
59 cnat_timestamp_t *ts = pool_elt_at_index (cnat_timestamps, index);
60 ts->lifetime = lifetime;
61 clib_rwlock_reader_unlock (&cnat_main.ts_lock);
65 cnat_timestamp_exp (u32 index)
68 if (INDEX_INVALID == index)
70 clib_rwlock_reader_lock (&cnat_main.ts_lock);
71 cnat_timestamp_t *ts = pool_elt_at_index (cnat_timestamps, index);
72 t = ts->last_seen + (f64) ts->lifetime;
73 clib_rwlock_reader_unlock (&cnat_main.ts_lock);
78 cnat_timestamp_free (u32 index)
80 if (INDEX_INVALID == index)
82 clib_rwlock_writer_lock (&cnat_main.ts_lock);
83 cnat_timestamp_t *ts = pool_elt_at_index (cnat_timestamps, index);
86 pool_put (cnat_timestamps, ts);
87 clib_rwlock_writer_unlock (&cnat_main.ts_lock);
91 * fd.io coding-style-patch-verification: ON
94 * eval: (c-set-style "gnu")