FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
cnat_inline.h
Go to the documentation of this file.
1 /*
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:
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 
17 #ifndef __CNAT_INLINE_H__
18 #define __CNAT_INLINE_H__
19 
20 #include <cnat/cnat_types.h>
21 
24 {
25  u32 index;
26  cnat_timestamp_t *ts;
29  ts->last_seen = t;
32  index = ts - cnat_timestamps;
34  return index;
35 }
36 
37 always_inline void
39 {
42  ts->refcnt++;
44 }
45 
46 always_inline void
48 {
51  ts->last_seen = t;
53 }
54 
55 always_inline void
57 {
60  ts->lifetime = lifetime;
62 }
63 
66 {
67  f64 t;
68  if (INDEX_INVALID == index)
69  return -1;
72  t = ts->last_seen + (f64) ts->lifetime;
74  return t;
75 }
76 
77 always_inline void
79 {
80  if (INDEX_INVALID == index)
81  return;
84  ts->refcnt--;
85  if (0 == ts->refcnt)
88 }
89 
90 /*
91  * fd.io coding-style-patch-verification: ON
92  *
93  * Local Variables:
94  * eval: (c-set-style "gnu")
95  * End:
96  */
97 
98 #endif
cnat_timestamp_t_::lifetime
u16 lifetime
Definition: cnat_types.h:150
cnat_timestamp_t_::last_seen
f64 last_seen
Definition: cnat_types.h:148
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
cnat_timestamp_exp
static f64 cnat_timestamp_exp(u32 index)
Definition: cnat_inline.h:65
cnat_main
cnat_main_t cnat_main
Definition: cnat_types.c:18
u16
unsigned short u16
Definition: types.h:57
cnat_timestamps
cnat_timestamp_t * cnat_timestamps
Definition: cnat_types.c:20
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
clib_rwlock_reader_lock
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
Definition: lock.h:169
clib_rwlock_reader_unlock
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
Definition: lock.h:184
clib_rwlock_writer_unlock
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
Definition: lock.h:206
cnat_types.h
cnat_main_::ts_lock
clib_rwlock_t ts_lock
Definition: cnat_types.h:129
clib_rwlock_writer_lock
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
Definition: lock.h:192
lifetime
u64 lifetime
Definition: ikev2_types.api:80
cnat_timestamp_update
static void cnat_timestamp_update(u32 index, f64 t)
Definition: cnat_inline.h:47
f64
double f64
Definition: types.h:142
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
cnat_timestamp_set_lifetime
static void cnat_timestamp_set_lifetime(u32 index, u16 lifetime)
Definition: cnat_inline.h:56
cnat_timestamp_t_
Definition: cnat_types.h:145
cnat_timestamp_t_::refcnt
u16 refcnt
Definition: cnat_types.h:152
index
u32 index
Definition: flow_types.api:221
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
u32
unsigned int u32
Definition: types.h:88
cnat_timestamp_free
static void cnat_timestamp_free(u32 index)
Definition: cnat_inline.h:78
CNAT_TIMESTAMP_INIT_REFCNT
#define CNAT_TIMESTAMP_INIT_REFCNT
Definition: cnat_types.h:54
cnat_timestamp_new
static u32 cnat_timestamp_new(f64 t)
Definition: cnat_inline.h:23
cnat_timestamp_inc_refcnt
static void cnat_timestamp_inc_refcnt(u32 index)
Definition: cnat_inline.h:38
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
cnat_main_::session_max_age
u32 session_max_age
Definition: cnat_types.h:119