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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#ifndef _CACHE_H_
#define _CACHE_H_
#include <stdint.h>
#include <stddef.h>
#include <time.h>
/* cache features */
enum {
NO_FEATURES = 0,
TIMER_FEATURE = 0,
TIMER = (1 << TIMER_FEATURE),
LIFETIME_FEATURE = 2,
LIFETIME = (1 << LIFETIME_FEATURE),
WRITE_THROUGH_FEATURE = 3,
WRITE_THROUGH = (1 << WRITE_THROUGH_FEATURE),
__CACHE_MAX_FEATURE
};
#define CACHE_MAX_FEATURE __CACHE_MAX_FEATURE
struct cache;
struct us_conntrack;
struct cache_feature {
size_t size;
void (*add)(struct us_conntrack *u, void *data);
void (*update)(struct us_conntrack *u, void *data);
void (*destroy)(struct us_conntrack *u, void *data);
int (*dump)(struct us_conntrack *u, void *data, char *buf, int type);
};
extern struct cache_feature lifetime_feature;
extern struct cache_feature timer_feature;
extern struct cache_feature writethrough_feature;
#define CACHE_MAX_NAMELEN 32
struct cache {
char name[CACHE_MAX_NAMELEN];
struct hashtable *h;
unsigned int num_features;
struct cache_feature **features;
unsigned int feature_type[CACHE_MAX_FEATURE];
unsigned int *feature_offset;
struct cache_extra *extra;
unsigned int extra_offset;
/* statistics */
unsigned int add_ok;
unsigned int del_ok;
unsigned int upd_ok;
unsigned int add_fail;
unsigned int del_fail;
unsigned int upd_fail;
unsigned int commit_ok;
unsigned int commit_exist;
unsigned int commit_fail;
unsigned int flush;
};
struct cache_extra {
unsigned int size;
void (*add)(struct us_conntrack *u, void *data);
void (*update)(struct us_conntrack *u, void *data);
void (*destroy)(struct us_conntrack *u, void *data);
};
struct nf_conntrack;
struct cache *cache_create(const char *name, unsigned int features, uint8_t proto, struct cache_extra *extra);
void cache_destroy(struct cache *e);
struct us_conntrack *cache_add(struct cache *c, struct nf_conntrack *ct);
struct us_conntrack *cache_update(struct cache *c, struct nf_conntrack *ct);
struct us_conntrack *cache_update_force(struct cache *c, struct nf_conntrack *ct);
int cache_del(struct cache *c, struct nf_conntrack *ct);
int cache_test(struct cache *c, struct nf_conntrack *ct);
void cache_stats(const struct cache *c, int fd);
struct us_conntrack *cache_get_conntrack(struct cache *, void *);
void *cache_get_extra(struct cache *, void *);
void cache_iterate(struct cache *c, void *data, int (*iterate)(void *data1, void *data2));
/* iterators */
void cache_dump(struct cache *c, int fd, int type);
void cache_commit(struct cache *c);
void cache_flush(struct cache *c);
void cache_bulk(struct cache *c);
#endif
|