Skip to content

Commit 436eb3e

Browse files
kknjhdkruces
authored andcommitted
tools/tcpcong: Reduce code redundancy
1: Ports that do not meet the conditions in function "entry_state_update_func" will not be stored in the "start_ipv4" or "start_ipv6", and the "ret_state_update_func" function will not obtain values, so there is no need to perform port filtering again. 2: Sock_store can be directly deleted in function "ret_func". Signed-off-by: Feng Yang <[email protected]>
1 parent bc38816 commit 436eb3e

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

tools/tcpcong.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@
199199
{
200200
u64 ts, ts1;
201201
u16 family, last_cong_state;
202-
u16 dport = 0, lport = 0;
203202
u32 tid = bpf_get_current_pid_tgid();
204203
process_key_t key = {0};
205204
bpf_get_current_comm(&key.comm, sizeof(key.comm));
@@ -216,16 +215,12 @@
216215
if (family == AF_INET) {
217216
ipv4_flow_val_t *val4 = start_ipv4.lookup(&key);
218217
if (val4 == 0) {
219-
SOCK_STORE_DEL
220218
return 0; //missed
221219
}
222220
ipv4_flow_key_t keyv4 = {0};
223221
bpf_probe_read_kernel(&keyv4, sizeof(ipv4_flow_key_t),
224222
&(val4->ipv4_key));
225-
dport = keyv4.dport;
226-
lport = keyv4.lport;
227-
FILTER_LPORT
228-
FILTER_DPORT
223+
229224
datap = ipv4_stat.lookup(&keyv4);
230225
if (datap == 0) {
231226
data.last_ts = bpf_ktime_get_ns();
@@ -246,16 +241,12 @@
246241
} else if (family == AF_INET6) {
247242
ipv6_flow_val_t *val6 = start_ipv6.lookup(&key);
248243
if (val6 == 0) {
249-
SOCK_STORE_DEL
250244
return 0; //missed
251245
}
252246
ipv6_flow_key_t keyv6 = {0};
253247
bpf_probe_read_kernel(&keyv6, sizeof(ipv6_flow_key_t),
254248
&(val6->ipv6_key));
255-
dport = keyv6.dport;
256-
lport = keyv6.lport;
257-
FILTER_LPORT
258-
FILTER_DPORT
249+
259250
datap = ipv6_stat.lookup(&keyv6);
260251
if (datap == 0) {
261252
data.last_ts = bpf_ktime_get_ns();
@@ -274,7 +265,7 @@
274265
}
275266
start_ipv6.delete(&key);
276267
}
277-
SOCK_STORE_DEL
268+
278269
return 0;
279270
}
280271
"""
@@ -366,6 +357,7 @@
366357
return 0; //miss the entry
367358
}
368359
struct sock *sk = *sockpp;
360+
SOCK_STORE_DEL
369361
return ret_state_update_func(sk);
370362
}
371363
"""

0 commit comments

Comments
 (0)