Skip to content

Commit 5b9ec37

Browse files
committed
Fix unexpected log
Signed-off-by: Zhonghu Xu <xuzhonghu@huawei.com>
1 parent 8a07412 commit 5b9ec37

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

bpf/include/bpf_common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,22 @@ static inline void remove_kmesh_managed_ip(__u32 family, __u32 ip4, __u32 *ip6)
260260
BPF_LOG(ERR, KMESH, "remove ip failed, err is %d\n", err);
261261
}
262262

263+
static inline bool sock_conn_from_sim(struct bpf_sock *sk)
264+
{
265+
__u16 enable_port = ENABLE_KMESH_PORT;
266+
__u16 disable_port = DISABLE_KMESH_PORT;
267+
__u16 dst_port = sk->dst_port;
268+
if (bpf_ntohs(dst_port) != enable_port && bpf_ntohs(dst_port) != disable_port)
269+
return false;
270+
271+
if (sk->family == AF_INET)
272+
return bpf_ntohl(sk->dst_ip4) == CONTROL_CMD_IP;
273+
274+
return (
275+
sk->dst_ip6[0] == 0 && sk->dst_ip6[1] == 0 && sk->dst_ip6[2] == 0
276+
&& bpf_ntohl(sk->dst_ip6[3]) == CONTROL_CMD_IP);
277+
}
278+
263279
static inline bool conn_from_sim(struct bpf_sock_ops *skops, __u32 ip, __u16 port)
264280
{
265281
__u16 remote_port = GET_SKOPS_REMOTE_PORT(skops);

bpf/kmesh/probes/probe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ static inline void observe_on_data(struct bpf_sock *sk)
9090
struct sock_storage_data *storage = NULL;
9191
if (!sk)
9292
return;
93+
9394
tcp_sock = bpf_tcp_sock(sk);
9495
if (!tcp_sock)
9596
return;
9697

9798
storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, 0);
9899
if (!storage) {
99-
BPF_LOG(ERR, PROBE, "on data: bpf_sk_storage_get failed\n");
100+
BPF_LOG(ERR, PROBE, "on data: bpf_sk_storage_get failed dst %u \n", bpf_ntohs(sk->dst_port));
100101
return;
101102
}
102103
__u64 now = bpf_ktime_get_ns();

bpf/kmesh/workload/cgroup_skb.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ int cgroup_skb_ingress_prog(struct __sk_buff *skb)
2424
if (!sk)
2525
return SK_PASS;
2626

27+
if (sock_conn_from_sim(sk)) {
28+
return SK_PASS;
29+
}
30+
2731
if (!is_managed_by_kmesh_skb(skb))
2832
return SK_PASS;
33+
2934
observe_on_data(sk);
3035
return SK_PASS;
3136
}
@@ -43,8 +48,13 @@ int cgroup_skb_egress_prog(struct __sk_buff *skb)
4348
if (!sk)
4449
return SK_PASS;
4550

51+
if (sock_conn_from_sim(sk)) {
52+
return SK_PASS;
53+
}
54+
4655
if (!is_managed_by_kmesh_skb(skb))
4756
return SK_PASS;
57+
4858
observe_on_data(sk);
4959
return SK_PASS;
5060
}

0 commit comments

Comments
 (0)