FD.io VPP  v21.01.1
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
static void clib_rwlock_reader_lock(clib_rwlock_t *p)
Definition: lock.h:169
#define CNAT_TIMESTAMP_INIT_REFCNT
Definition: cnat_types.h:50
static void clib_rwlock_writer_lock(clib_rwlock_t *p)
Definition: lock.h:192
static void cnat_timestamp_free(u32 index)
Definition: cnat_inline.h:78
static u32 cnat_timestamp_new(f64 t)
Definition: cnat_inline.h:23
static void cnat_timestamp_update(u32 index, f64 t)
Definition: cnat_inline.h:47
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:251
double f64
Definition: types.h:142
static void cnat_timestamp_set_lifetime(u32 index, u16 lifetime)
Definition: cnat_inline.h:56
u64 lifetime
Definition: ikev2_types.api:80
unsigned int u32
Definition: types.h:88
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
static void clib_rwlock_reader_unlock(clib_rwlock_t *p)
Definition: lock.h:184
unsigned short u16
Definition: types.h:57
cnat_timestamp_t * cnat_timestamps
Definition: cnat_types.c:20
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:301
#define always_inline
Definition: ipsec.h:28
static f64 cnat_timestamp_exp(u32 index)
Definition: cnat_inline.h:65
static void clib_rwlock_writer_unlock(clib_rwlock_t *p)
Definition: lock.h:206
static void cnat_timestamp_inc_refcnt(u32 index)
Definition: cnat_inline.h:38
clib_rwlock_t ts_lock
Definition: cnat_types.h:128
u32 session_max_age
Definition: cnat_types.h:118
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
cnat_main_t cnat_main
Definition: cnat_types.c:18
u32 index
Definition: flow_types.api:221