-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhash.c
49 lines (39 loc) · 1.11 KB
/
hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "hash.h"
#include <rte_hash.h>
static void print_table(struct rte_hash* table) {
struct net_key* key = NULL;
struct sock* sk = NULL;
uint32_t next = 0;
while (rte_hash_iterate(table, (const void**)&key, (void**)&sk, &next) >= 0) {
debug_ip_port("tbl i", sk->sip, sk->dip, sk->sport, sk->dport, sk->protocol);
}
}
void* hash_find(struct rte_hash* table, void* key) {
void* data = NULL;
int32_t idx = rte_hash_lookup_data(table, key, &data);
if (idx < 0) {
print_key("Not find sock", key);
print_table(table);
}
return data;
}
int hash_add(struct rte_hash* table, void* key, void* val) {
int ret = rte_hash_add_key_data(table, key, val);
if (ret) {
print_key("Add sock failed", key);
print_table(table);
} else {
print_key("Add sock", key);
}
return ret;
}
int hash_rm(struct rte_hash* table, void* key) {
int ret = rte_hash_del_key(table, key);
if (ret) {
print_key("Remove sock failed", key);
print_table(table);
} else {
print_key("Remove sock", key);
}
return ret;
}