Skip to content

Commit

Permalink
fix(backend): enable process filtering for the cgroup-skb backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Feb 9, 2025
1 parent 4d15144 commit 3575e4a
Show file tree
Hide file tree
Showing 34 changed files with 63 additions and 209 deletions.
86 changes: 32 additions & 54 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,15 @@ jobs:
run: |
bash testdata/test_run_with_docker.sh "quay.io/ptcpdump/ptcpdump:latest"
test-backend:
runs-on: ubuntu-latest
needs: build
timeout-minutes: 5

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Retrieve stored ptcpdump executable
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: ptcpdump
path: ptcpdump

- name: test cgroup-skb
run: |
set -ex
chmod +x ./ptcpdump/ptcpdump
sudo bash testdata/test_cgroup_skb_base_pcap.sh ./ptcpdump/ptcpdump
sudo bash testdata/test_cgroup_skb_base_pcapng.sh ./ptcpdump/ptcpdump
sudo bash testdata/test_cgroup_skb_filter_ifindex.sh ./ptcpdump/ptcpdump
e2e-test:
name: e2e-test
needs: build
strategy:
fail-fast: false
matrix:
backend:
- 'tc'
- 'cgroup-skb'
kernel:
# renovate: datasource=docker depName=quay.io/lvh-images/kernel-images
- '4.19-20241031.113911'
Expand All @@ -98,6 +80,14 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- run: |
if [ "${{ matrix.backend }}" = "tc" ]; then
PTCPDUMP_EXTRA_ARGS=''
else
PTCPDUMP_EXTRA_ARGS='--backend cgroup-skb'
fi
echo "PTCPDUMP_EXTRA_ARGS=${PTCPDUMP_EXTRA_ARGS}" >> $GITHUB_ENV
- name: Retrieve stored ptcpdump executable
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
Expand Down Expand Up @@ -150,8 +140,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_default.sh /host/ptcpdump/ptcpdump
Expand All @@ -161,8 +150,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_base.sh /host/ptcpdump/ptcpdump
Expand All @@ -172,8 +160,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_parent_info.sh /host/ptcpdump/ptcpdump
Expand All @@ -183,8 +170,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_pname_filter.sh /host/ptcpdump/ptcpdump
Expand All @@ -194,8 +180,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_pid_filter.sh /host/ptcpdump/ptcpdump
Expand All @@ -205,8 +190,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_read_pcap.sh /host/ptcpdump/ptcpdump
Expand All @@ -216,8 +200,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_write_pcap.sh /host/ptcpdump/ptcpdump
Expand All @@ -227,8 +210,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_write_stdout.sh /host/ptcpdump/ptcpdump
Expand All @@ -238,20 +220,18 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_exist_connection.sh /host/ptcpdump/ptcpdump
- name: Test arp and icmp
if: ${{ (!startsWith(matrix.kernel, '5.4')) && (!startsWith(matrix.kernel, '4.')) }}
if: ${{ (!startsWith(matrix.kernel, '5.4')) && (!startsWith(matrix.kernel, '4.')) && (!startsWith(matrix.backend, 'cgroup-skb')) }}
uses: cilium/little-vm-helper@e87948476ca97050b1f149ab2aec379d0de19b84 # v0.0.23
with:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_arp.sh /host/ptcpdump/ptcpdump
bash /host/testdata/test_icmp.sh /host/ptcpdump/ptcpdump
Expand All @@ -263,6 +243,8 @@ jobs:
provision: 'false'
cmd: |
set -ex
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_netns.sh /host/ptcpdump/ptcpdump
- name: Test netns newly
Expand All @@ -272,6 +254,8 @@ jobs:
provision: 'false'
cmd: |
set -ex
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_netns_newly_normal.sh /host/ptcpdump/ptcpdump
bash /host/testdata/test_netns_newly_exec.sh /host/ptcpdump/ptcpdump
Expand All @@ -281,8 +265,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
bash /host/testdata/test_sub_program.sh /host/ptcpdump/ptcpdump
bash /host/testdata/test_sub_curl_domain_program.sh /host/ptcpdump/ptcpdump
Expand All @@ -293,8 +276,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
for i in {1..10}; do
bash /host/testdata/test_nat.sh /host/ptcpdump/ptcpdump && exit 0 || sleep 1
Expand All @@ -313,8 +295,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
ls -lh /host/testdata/gohttpapp
Expand All @@ -332,8 +313,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
ls -lh /host/testdata/gohttpapp
Expand All @@ -351,8 +331,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
ls -lh /host/testdata/gohttpapp
Expand All @@ -370,8 +349,7 @@ jobs:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
export PTCPDUMP_EXTRA_ARGS="${{ env.PTCPDUMP_EXTRA_ARGS }}"
ls -lh /host/testdata/gohttpapp
Expand Down
Binary file modified bpf/bpf_arm64_bpfel.o
Binary file not shown.
Binary file modified bpf/bpf_legacy_arm64_bpfel.o
Binary file not shown.
Binary file modified bpf/bpf_legacy_x86_bpfel.o
Binary file not shown.
Binary file modified bpf/bpf_no_tracing_arm64_bpfel.o
Binary file not shown.
Binary file modified bpf/bpf_no_tracing_x86_bpfel.o
Binary file not shown.
Binary file modified bpf/bpf_x86_bpfel.o
Binary file not shown.
7 changes: 7 additions & 0 deletions bpf/ptcpdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,20 @@ static __always_inline int fill_packet_event_meta(struct __sk_buff *skb, bool cg
if (cgroup_skb && egress) {
struct task_struct *task = (struct task_struct *)bpf_get_current_task();
if (task && !is_kernel_thread(task)) {
if (parent_process_filter(task) < 0) {
if (process_filter(task) < 0) {
goto outer;
}
}
event_meta->l3_protocol = bpf_ntohs(skb->protocol);
fill_process_meta_with_thread(task, pid_meta);
if (pid_meta->pid > 0) {
// debug_log("[ptcpdump][cgroup_sk] get_current_task success\n");
return 0;
}
}
outer:
(void)0;
// debug_log("[ptcpdump][cgroup_sk] get_current_task failed\n");
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/test_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RNAME="${FILE_PREFIX}_base.read.txt"


function test_ptcpdump() {
timeout 30s ${CMD} -c 1 -v -i any --print -w "${FNAME}" \
timeout 30s ${CMD} -c 1 -v -i any ${PTCPDUMP_EXTRA_ARGS} --print -w "${FNAME}" \
'dst host 1.1.1.1 and tcp[tcpflags] = tcp-syn' | tee "${LNAME}" &
sleep 10
curl -m 10 1.1.1.1 &>/dev/null || true
Expand Down
41 changes: 0 additions & 41 deletions testdata/test_cgroup_skb_base_pcap.sh

This file was deleted.

44 changes: 0 additions & 44 deletions testdata/test_cgroup_skb_base_pcapng.sh

This file was deleted.

45 changes: 0 additions & 45 deletions testdata/test_cgroup_skb_filter_ifindex.sh

This file was deleted.

Loading

0 comments on commit 3575e4a

Please sign in to comment.