Skip to content

Commit 5b985ee

Browse files
committed
Implement space saving algorithm
1 parent 80a665b commit 5b985ee

File tree

3 files changed

+926
-1
lines changed

3 files changed

+926
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ SRCS-y += sol/main.c
4444
# Libraries.
4545
SRCS-y += lib/mailbox.c lib/net.c lib/flow.c lib/ipip.c \
4646
lib/luajit-ffi-cdata.c lib/launch.c lib/lpm.c lib/acl.c lib/varip.c \
47-
lib/l2.c
47+
lib/l2.c lib/space_saving.c
4848

4949
LDLIBS += $(LDIR) -Bstatic -lluajit-5.1 -Bdynamic -lm -lmnl
5050
CFLAGS += $(WERROR_FLAGS) -I${GATEKEEPER}/include -I/usr/local/include/luajit-2.0/

include/space_saving.h

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Gatekeeper - DoS protection system.
3+
* Copyright (C) 2016 Digirati LTDA.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef _SPACE_SAVING_H_
20+
#define _SPACE_SAVING_H_
21+
22+
#include <rte_hash.h>
23+
24+
#include "gatekeeper_gk.h"
25+
#include "gatekeeper_net.h"
26+
#include "gatekeeper_flow.h"
27+
28+
/* Data structure for Counter Table */
29+
struct counter_table {
30+
31+
/* Counter for IPV4 address */
32+
struct rte_hash *ct_ip4;
33+
34+
/* Counter for IPV6 address */
35+
struct rte_hash *ct_ip6;
36+
};
37+
38+
/* Data structure for Counter bucket */
39+
struct counter_bucket {
40+
41+
int proto;
42+
43+
union {
44+
/* Bucket for IPV4 address */
45+
struct rte_hash *bkt_ip4;
46+
47+
/* Bucket for IPV6 address */
48+
struct rte_hash *bkt_ip6;
49+
} bkt;
50+
};
51+
52+
/* Data present in a Counter bucket */
53+
struct bucket_data {
54+
55+
int err;
56+
struct ip_flow flow;
57+
};
58+
59+
/* Data structure of IP data */
60+
struct ip_data {
61+
62+
int bkt_id;
63+
struct bucket_data bkt_data;
64+
};
65+
66+
static int
67+
setup_bucket_params(unsigned int socket_id, int bkt_id, int bkt_size,
68+
int ip_ver, struct rte_hash_parameters *bkt_hash_params);
69+
70+
static int
71+
create_bucket(struct gatekeeper_if *iface, struct gk_config *gk_conf,
72+
int bkt_id);
73+
74+
static int
75+
get_bucket(int bkt_id, int proto, struct counter_bucket *ct_bkt);
76+
77+
static int
78+
get_bucket_entry(struct counter_bucket *ct_bkt, struct ip_flow *flow,
79+
struct bucket_data *bkt_data);
80+
81+
static int
82+
add_bucket_entry(struct counter_bucket *ct_bkt, struct ip_flow *flow,
83+
struct bucket_data *bkt_data);
84+
85+
static int
86+
delete_bucket_entry(struct counter_bucket *ct_bkt, struct ip_flow *flow);
87+
88+
static int
89+
setup_counter_params(unsigned int socket_id, int identifier, int ht_size,
90+
int ip_ver, struct rte_hash_parameters *ct_hash_params);
91+
92+
static int
93+
create_counter_table(struct gatekeeper_if *iface, struct gk_config *gk_conf);
94+
95+
static int
96+
get_bucket_id(struct counter_table *ct_table, struct ip_flow *flow,
97+
int *bkt_id);
98+
99+
static int
100+
add_bucket_id(struct counter_table *ct_table, struct ip_flow *flow,
101+
int *bkt_id);
102+
103+
static int
104+
delete_bucket_id(struct counter_table *ct_table, struct ip_flow *flow);
105+
106+
static int
107+
update_bucket_id(struct counter_table *ct_table, struct ip_flow *flow);
108+
109+
static int
110+
get_ip_data(struct counter_table *ct_table, struct ip_flow *flow,
111+
struct ip_data *data);
112+
113+
static int
114+
add_ip_data(struct counter_table *ct_table, struct ip_flow *flow,
115+
struct ip_data *data);
116+
117+
static int
118+
delete_ip_data(struct counter_table *ct_table, struct ip_flow *flow);
119+
120+
static int
121+
update_ip_data(struct counter_table *ct_table, struct ip_flow *flow,
122+
struct gatekeeper_if *iface, struct gk_config *gk_conf);
123+
124+
static int
125+
space_saving(struct counter_table *ct_table, struct ip_flow *flow,
126+
struct gatekeeper_if *iface, struct gk_config *gk_conf);
127+
128+
int run(struct gatekeeper_if *iface, struct gk_config *gk_conf);
129+
#endif /* _SPACE_SAVING_H */
130+

0 commit comments

Comments
 (0)