Skip to content

Commit dd27f48

Browse files
committed
If the connection is established before kmesh starts, then the sock storage is not created, so remove the error logging
Signed-off-by: Zhonghu Xu <xuzhonghu@huawei.com>
1 parent 9ef41e7 commit dd27f48

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

bpf/kmesh/probes/probe.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static inline void observe_on_close(struct bpf_sock *sk)
7777

7878
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
7979
if (!storage) {
80-
BPF_LOG(ERR, PROBE, "on close: bpf_sk_storage_get failed\n");
80+
// maybe the connection is established before kmesh start
8181
return;
8282
}
8383

@@ -95,10 +95,9 @@ static inline void observe_on_data(struct bpf_sock *sk)
9595
if (!tcp_sock)
9696
return;
9797

98-
// Use BPF_LOCAL_STORAGE_GET_F_CREATE in case a connection being established before kmesh start.
99-
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE);
98+
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
10099
if (!storage) {
101-
BPF_LOG(ERR, PROBE, "on data: bpf_sk_storage_get failed dst %u \n", bpf_ntohs(sk->dst_port));
100+
// maybe the connection is established before kmesh start
102101
return;
103102
}
104103
__u64 now = bpf_ktime_get_ns();

bpf/kmesh/probes/tcp_probe.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,9 @@ static inline void get_tcp_probe_info(struct bpf_tcp_sock *tcp_sock, struct tcp_
110110

111111
// construct_orig_dst_info try to read the dst_info from map_of_sock_storage first
112112
// if not found, use the tuple info for orig_dst
113-
static inline void construct_orig_dst_info(struct bpf_sock *sk, struct tcp_probe_info *info)
113+
static inline void
114+
construct_orig_dst_info(struct bpf_sock *sk, struct sock_storage_data *storage, struct tcp_probe_info *info)
114115
{
115-
struct sock_storage_data *storage = NULL;
116-
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
117-
if (!storage) {
118-
BPF_LOG(ERR, PROBE, "on close: bpf_sk_storage_get failed\n");
119-
return;
120-
}
121-
122116
if (sk->family == AF_INET) {
123117
info->orig_dst.ipv4.addr = storage->sk_tuple.ipv4.daddr;
124118
info->orig_dst.ipv4.port = bpf_ntohs(storage->sk_tuple.ipv4.dport);
@@ -136,7 +130,6 @@ static inline void construct_orig_dst_info(struct bpf_sock *sk, struct tcp_probe
136130
static inline void
137131
tcp_report(struct bpf_sock *sk, struct bpf_tcp_sock *tcp_sock, struct sock_storage_data *storage, __u32 state)
138132
{
139-
// struct connect_info *info = NULL;
140133
struct tcp_probe_info *info = NULL;
141134

142135
// store tuple
@@ -157,7 +150,7 @@ tcp_report(struct bpf_sock *sk, struct bpf_tcp_sock *tcp_sock, struct sock_stora
157150
(*info).type = IPV4;
158151
}
159152

160-
construct_orig_dst_info(sk, info);
153+
construct_orig_dst_info(sk, storage, info);
161154
info->last_report_ns = bpf_ktime_get_ns();
162155
info->duration = info->last_report_ns - storage->connect_ns;
163156
storage->last_report_ns = info->last_report_ns;

0 commit comments

Comments
 (0)