FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
session_table.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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 
17 #include <vnet/session/session.h>
18 
19 /**
20  * Pool of session tables
21  */
23 
25 _get_session_tables (void)
26 {
27  return lookup_tables;
28 }
29 
32 {
33  session_table_t *slt;
35  clib_memset (slt, 0, sizeof (*slt));
36  return slt;
37 }
38 
39 u32
41 {
42  return (slt - lookup_tables);
43 }
44 
46 session_table_get (u32 table_index)
47 {
48  if (pool_is_free_index (lookup_tables, table_index))
49  return 0;
50  return pool_elt_at_index (lookup_tables, table_index);
51 }
52 
53 #define foreach_hash_table_parameter \
54  _(v4,session,buckets,20000) \
55  _(v4,session,memory,(64<<20)) \
56  _(v6,session,buckets,20000) \
57  _(v6,session,memory,(64<<20)) \
58  _(v4,halfopen,buckets,20000) \
59  _(v4,halfopen,memory,(64<<20)) \
60  _(v6,halfopen,buckets,20000) \
61  _(v6,halfopen,memory,(64<<20))
62 
63 void
65 {
66  u8 all = fib_proto > FIB_PROTOCOL_IP6 ? 1 : 0;
67  int i;
68 
69  for (i = 0; i < TRANSPORT_N_PROTOS; i++)
70  session_rules_table_free (&slt->session_rules[i]);
71 
72  vec_free (slt->session_rules);
73 
74  if (fib_proto == FIB_PROTOCOL_IP4 || all)
75  {
76  clib_bihash_free_16_8 (&slt->v4_session_hash);
77  clib_bihash_free_16_8 (&slt->v4_half_open_hash);
78  }
79  if (fib_proto == FIB_PROTOCOL_IP6 || all)
80  {
81  clib_bihash_free_48_8 (&slt->v6_session_hash);
82  clib_bihash_free_48_8 (&slt->v6_half_open_hash);
83  }
84 
85  pool_put (lookup_tables, slt);
86 }
87 
88 /**
89  * Initialize session table hash tables
90  *
91  * If vpp configured with set of table parameters it uses them,
92  * otherwise it uses defaults above.
93  */
94 void
96 {
97  u8 all = fib_proto > FIB_PROTOCOL_IP6 ? 1 : 0;
98  int i;
99 
100 #define _(af,table,parm,value) \
101  u32 configured_##af##_##table##_table_##parm = value;
103 #undef _
104 
105 #define _(af,table,parm,value) \
106  if (session_main.configured_##af##_##table##_table_##parm) \
107  configured_##af##_##table##_table_##parm = \
108  session_main.configured_##af##_##table##_table_##parm;
110 #undef _
111 
112  if (fib_proto == FIB_PROTOCOL_IP4 || all)
113  {
114  clib_bihash_init2_args_16_8_t _a, *a = &_a;
115 
116  memset (a, 0, sizeof (*a));
117  a->h = &slt->v4_session_hash;
118  a->name = "v4 session table";
119  a->nbuckets = configured_v4_session_table_buckets;
120  a->memory_size = configured_v4_session_table_memory;
121  a->dont_add_to_all_bihash_list = 1;
122  a->instantiate_immediately = 1;
123  clib_bihash_init2_16_8 (a);
124 
125  memset (a, 0, sizeof (*a));
126  a->h = &slt->v4_half_open_hash;
127  a->name = "v4 half-open table";
128  a->nbuckets = configured_v4_halfopen_table_buckets;
129  a->memory_size = configured_v4_halfopen_table_memory;
130  a->dont_add_to_all_bihash_list = 1;
131  a->instantiate_immediately = 1;
132  clib_bihash_init2_16_8 (a);
133  }
134  if (fib_proto == FIB_PROTOCOL_IP6 || all)
135  {
136  clib_bihash_init2_args_48_8_t _a, *a = &_a;
137 
138  memset (a, 0, sizeof (*a));
139  a->h = &slt->v6_session_hash;
140  a->name = "v6 session table";
141  a->nbuckets = configured_v6_session_table_buckets;
142  a->memory_size = configured_v6_session_table_memory;
143  a->dont_add_to_all_bihash_list = 1;
144  a->instantiate_immediately = 1;
145  clib_bihash_init2_48_8 (a);
146 
147  memset (a, 0, sizeof (*a));
148  a->h = &slt->v6_half_open_hash;
149  a->name = "v6 half-open table";
150  a->nbuckets = configured_v6_halfopen_table_buckets;
151  a->memory_size = configured_v6_halfopen_table_memory;
152  a->dont_add_to_all_bihash_list = 1;
153  a->instantiate_immediately = 1;
154  clib_bihash_init2_48_8 (a);
155  }
156 
157  vec_validate (slt->session_rules, TRANSPORT_N_PROTOS - 1);
158  for (i = 0; i < TRANSPORT_N_PROTOS; i++)
159  session_rules_table_init (&slt->session_rules[i]);
160 }
161 
162 typedef struct _ip4_session_table_walk_ctx_t
163 {
165  void *ctx;
167 
168 static int
170 {
172  ctx->fn (kvp, ctx->ctx);
173  return (BIHASH_WALK_CONTINUE);
174 }
175 
176 void
177 ip4_session_table_walk (clib_bihash_16_8_t * hash,
178  ip4_session_table_walk_fn_t fn, void *arg)
179 {
181  .fn = fn,
182  .ctx = arg,
183  };
184  clib_bihash_foreach_key_value_pair_16_8 (hash, ip4_session_table_walk_cb,
185  &ctx);
186 }
187 
188 /* *INDENT-ON* */
189 /*
190  * fd.io coding-style-patch-verification: ON
191  *
192  * Local Variables:
193  * eval: (c-set-style "gnu")
194  * End:
195  */
ip4_session_table_walk_cb
static int ip4_session_table_walk_cb(clib_bihash_kv_16_8_t *kvp, void *arg)
Definition: session_table.c:169
session_rules_table_free
void session_rules_table_free(session_rules_table_t *srt)
Definition: session_rules_table.c:517
foreach_hash_table_parameter
#define foreach_hash_table_parameter
Definition: session_table.c:53
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
session_table_free
void session_table_free(session_table_t *slt, u8 fib_proto)
Definition: session_table.c:64
pool_get_aligned
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:249
ip4_session_table_walk
void ip4_session_table_walk(clib_bihash_16_8_t *hash, ip4_session_table_walk_fn_t fn, void *arg)
Definition: session_table.c:177
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
session_table_init
void session_table_init(session_table_t *slt, u8 fib_proto)
Initialize session table hash tables.
Definition: session_table.c:95
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
ip4_session_table_walk_fn_t
int(* ip4_session_table_walk_fn_t)(clib_bihash_kv_16_8_t *kvp, void *ctx)
Definition: session_table.h:60
session_table_index
u32 session_table_index(session_table_t *slt)
Definition: session_table.c:40
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:58
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
clib_bihash_kv_16_8_t
Definition: bihash_16_8.h:40
u32
unsigned int u32
Definition: types.h:88
ip4_session_table_walk_ctx_t
struct _ip4_session_table_walk_ctx_t ip4_session_table_walk_ctx_t
TRANSPORT_N_PROTOS
#define TRANSPORT_N_PROTOS
Definition: session.h:259
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u8
unsigned char u8
Definition: types.h:56
a
a
Definition: bitmap.h:525
session.h
i
int i
Definition: flowhash_template.h:376
session_table.h
session_table_alloc
session_table_t * session_table_alloc(void)
Definition: session_table.c:31
session_rules_table_init
void session_rules_table_init(session_rules_table_t *srt)
Definition: session_rules_table.c:524
session_table_t
struct _session_lookup_table session_table_t
session_table_get
session_table_t * session_table_get(u32 table_index)
Definition: session_table.c:46
lookup_tables
static session_table_t * lookup_tables
Pool of session tables.
Definition: session_table.c:22