1
- #define KBUILD_MODNAME "dummy"
1
+ /* Copyright (C) 2022 calesanz
2
+ // 2023-2024 Gustavo Iñiguez Goya
3
+ //
4
+ // This file is part of OpenSnitch.
5
+ //
6
+ // OpenSnitch is free software: you can redistribute it and/or modify
7
+ // it under the terms of the GNU General Public License as published by
8
+ // the Free Software Foundation, either version 3 of the License, or
9
+ // (at your option) any later version.
10
+ //
11
+ // OpenSnitch is distributed in the hope that it will be useful,
12
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ // GNU General Public License for more details.
15
+ //
16
+ // You should have received a copy of the GNU General Public License
17
+ // along with OpenSnitch. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+
21
+ #define KBUILD_MODNAME "opensnitch-dns"
2
22
3
23
#include <linux/in.h>
4
24
#include <linux/in6.h>
@@ -51,7 +71,7 @@ struct addrinfo_args_cache {
51
71
// define temporary array for data
52
72
struct bpf_map_def SEC ("maps/addrinfo_args_hash" ) addrinfo_args_hash = {
53
73
.type = BPF_MAP_TYPE_HASH ,
54
- .max_entries = MAPSIZE ,
74
+ .max_entries = 256 , // max entries at any time
55
75
.key_size = sizeof (u32 ),
56
76
.value_size = sizeof (struct addrinfo_args_cache ),
57
77
};
@@ -61,7 +81,7 @@ struct bpf_map_def SEC("maps/events") events = {
61
81
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY ,
62
82
.key_size = sizeof (u32 ),
63
83
.value_size = sizeof (u32 ),
64
- .max_entries = MAPSIZE ,
84
+ .max_entries = 256 , // max cpus
65
85
};
66
86
67
87
/**
@@ -170,7 +190,7 @@ int ret_addrinfo(struct pt_regs *ctx) {
170
190
struct addrinfo * res ;
171
191
bpf_probe_read (& res , sizeof (res ), res_p );
172
192
if (res == NULL ) {
173
- return 0 ;
193
+ goto out ;
174
194
}
175
195
bpf_probe_read (& data .addr_type , sizeof (data .addr_type ),
176
196
& res -> ai_family );
@@ -186,7 +206,7 @@ int ret_addrinfo(struct pt_regs *ctx) {
186
206
187
207
bpf_probe_read_user (& data .ip , sizeof (data .ip ), & ipv6 -> sin6_addr );
188
208
} else {
189
- return 1 ;
209
+ goto out ;
190
210
}
191
211
192
212
bpf_probe_read_kernel_str (& data .host , sizeof (data .host ),
@@ -198,9 +218,15 @@ int ret_addrinfo(struct pt_regs *ctx) {
198
218
199
219
struct addrinfo * next ;
200
220
bpf_probe_read (& next , sizeof (next ), & res -> ai_next );
221
+ if (next == NULL ){
222
+ goto out ;
223
+ }
201
224
res_p = & next ;
202
225
}
203
226
227
+ out :
228
+ bpf_map_delete_elem (& addrinfo_args_hash , & tid );
229
+
204
230
return 0 ;
205
231
}
206
232
0 commit comments