-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
240 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )" | ||
NETNS1="$1" | ||
VETH1="$2" | ||
NETNS2="$3" | ||
VETH2="$4" | ||
|
||
function setup_netns() { | ||
ip netns add ${NETNS1} || true | ||
ip netns add ${NETNS2} || true | ||
|
||
ip link add ${VETH1} type veth peer name ${VETH2} || true | ||
ip link set ${VETH1} netns ${NETNS1} || true | ||
ip link set ${VETH2} netns ${NETNS2} || true | ||
|
||
ip -n ${NETNS1} addr add 192.168.64.1/24 dev ${VETH1} || true | ||
ip -n ${NETNS2} addr add 192.168.64.2/24 dev ${VETH2} || true | ||
|
||
ip -n ${NETNS1} link set ${VETH1} up | ||
ip -n ${NETNS2} link set ${VETH2} up | ||
} | ||
|
||
function main() { | ||
setup_netns | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
CMD="$1" | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )" | ||
FILE_PREFIX="/tmp/ptcpdump" | ||
CREATE_NS_SCRIPT="${SCRIPT_DIR}/create_netns.sh" | ||
FNAME="${FILE_PREFIX}_netns_newly.pcapng" | ||
LNAME="${FILE_PREFIX}_netns_newly.log" | ||
RNAME="${FILE_PREFIX}_netns_newly.read.txt" | ||
NETNS1="netns30" | ||
VETH1="veth30" | ||
NETNS2="netns31" | ||
VETH2="veth31" | ||
|
||
function cleanup() { | ||
ip netns exec ${NETNS1} ip link delete ${VETH1} || true | ||
ip netns exec ${NETNS2} ip link delete ${VETH2} || true | ||
|
||
ip netns delete ${NETNS1} | ||
ip netns delete ${NETNS2} | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
function test_ptcpdump_exec() { | ||
local LNAME="${LNAME}.exec" | ||
curl 1.1.1.1 &>/dev/null || true & | ||
ip netns exec ${NETNS2} sh -c "echo -e 'HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n' | nc -l 8000" & | ||
|
||
timeout 30s ${CMD} -c 4 -i any --netns newly -v --print -w "${FNAME}" \ | ||
'tcp' \ | ||
-- sh -c "bash ${CREATE_NS_SCRIPT} $NETNS1 $VETH1 $NETNS2 $VETH2 && ip netns exec ${NETNS1} curl http://192.168.64.2:8000" | tee "${LNAME}" | ||
|
||
cat "${LNAME}" | ||
cat "${LNAME}" | grep '192.168.64.2.* > 192.168.64.1' | ||
cat "${LNAME}" | grep '192.168.64.1.* > 192.168.64.2' | ||
} | ||
|
||
function main() { | ||
test_ptcpdump_exec | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
CMD="$1" | ||
FILE_PREFIX="/tmp/ptcpdump" | ||
FNAME="${FILE_PREFIX}_netns_newly.pcapng" | ||
LNAME="${FILE_PREFIX}_netns_newly.log" | ||
RNAME="${FILE_PREFIX}_netns_newly.read.txt" | ||
NETNS1="netns20" | ||
VETH1="veth20" | ||
NETNS2="netns21" | ||
VETH2="veth21" | ||
|
||
function setup_netns() { | ||
ip netns add ${NETNS1} || true | ||
ip netns add ${NETNS2} || true | ||
|
||
ip link add ${VETH1} type veth peer name ${VETH2} || true | ||
ip link set ${VETH1} netns ${NETNS1} || true | ||
ip link set ${VETH2} netns ${NETNS2} || true | ||
|
||
ip -n ${NETNS1} addr add 192.168.64.1/24 dev ${VETH1} || true | ||
ip -n ${NETNS2} addr add 192.168.64.2/24 dev ${VETH2} || true | ||
|
||
ip -n ${NETNS1} link set ${VETH1} up | ||
ip -n ${NETNS2} link set ${VETH2} up | ||
} | ||
|
||
function cleanup() { | ||
ip netns exec ${NETNS1} ip link delete ${VETH1} || true | ||
ip netns exec ${NETNS2} ip link delete ${VETH2} || true | ||
|
||
ip netns delete ${NETNS1} | ||
ip netns delete ${NETNS2} | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
function test_ptcpdump_normal() { | ||
local LNAME="${LNAME}.normal" | ||
timeout 30s ${CMD} -c 4 -i any --netns newly -v --print -w "${FNAME}" \ | ||
'icmp' | tee "${LNAME}" & | ||
sleep 10 | ||
setup_netns | ||
|
||
ping -c 5 1.1.1.1 &>/dev/null || true & | ||
ip netns exec ${NETNS1} ping -c 2 192.168.64.2 &>/dev/null || true | ||
wait | ||
|
||
cat "${LNAME}" | ||
cat "${LNAME}" | grep -F '192.168.64.1 > 192.168.64.2: ICMP' | ||
cat "${LNAME}" | grep -F '192.168.64.2 > 192.168.64.1: ICMP' | ||
} | ||
|
||
function main() { | ||
test_ptcpdump_normal | ||
} | ||
|
||
main |