From d15dc57cfda5c08796c7518f100c2e310fd875a6 Mon Sep 17 00:00:00 2001 From: Adam Samalik Date: Thu, 29 Jun 2023 17:35:00 +0200 Subject: [PATCH] re-import sources as agreed with the maintainer --- .gitignore | 9 ++- tests/basic/nd.pcap | Bin 0 -> 448 bytes tests/basic/send_monitor_nd.sh | 133 +++++++++++++++++++++++++++++++++ tests/tests.yml | 17 +++++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 tests/basic/nd.pcap create mode 100755 tests/basic/send_monitor_nd.sh create mode 100644 tests/tests.yml diff --git a/.gitignore b/.gitignore index f6a574c..95d60e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ -SOURCES/libndp-1.7.tar.gz +/libndp-20130504gitca3c399.tar.gz +/libndp-20130607git39e1f53.tar.gz +/libndp-1.0.tar.gz +/libndp-1.2.tar.gz +/libndp-1.3.tar.gz +/libndp-1.4.tar.gz +/libndp-1.5.tar.gz +/libndp-1.6.tar.gz /libndp-1.7.tar.gz diff --git a/tests/basic/nd.pcap b/tests/basic/nd.pcap new file mode 100644 index 0000000000000000000000000000000000000000..b604a780f5738f2cc3e5cb9dbd0a45370a0dc10c GIT binary patch literal 448 zcmca|c+)~A1{MYcU}0bca#CV7VwtvbGlT)zAZ%<5BtQ~Cvh8jHh*q%r|E~eWU|?Wk zVEF$JDDxl4Kmv^I43)D%d~|h;P?Iu%wq!X&Y#`s34u#beUjzvHg{hUHS_i0^0p|7`ps9g1oD5|^F%ZTQLJkB?Wo%=x>15zw=Kz@u g0x;8A!ER^0!_4AvfI+>Nfq~Pi0VJ;=1R@at0M>9n9RL6T literal 0 HcmV?d00001 diff --git a/tests/basic/send_monitor_nd.sh b/tests/basic/send_monitor_nd.sh new file mode 100755 index 0000000..5521751 --- /dev/null +++ b/tests/basic/send_monitor_nd.sh @@ -0,0 +1,133 @@ +#!/bin/sh + +ret=0 +nsuccess=0 +nfail=0 +NETNS_0="ns-$(mktemp -u XXXXXX)" +NETNS_1="ns-$(mktemp -u XXXXXX)" + +# $1: return value +# $2: log message +libndp_log() { + local rc=$1 + local msg="$2" + + if [ $rc -eq 0 ]; then + printf "[libndp gating]: %-30s [ PASS ]\n" "$msg" + nsuccess=$((nsuccess+1)) + else + printf "[libndp gating]: %-30s [ FAIL ]\n" "$msg" + nfail=$((nfail+1)) && ret=1 + fi +} + +install_tcpreplay() { + which tcpreplay && return 0 + wget https://github.com/appneta/tcpreplay/releases/download/v4.3.0/tcpreplay-4.3.0.tar.xz + tar xf tcpreplay-4.3.0.tar.xz + cd tcpreplay-4.3.0 + ./configure && make && make install + cd ../ + which tcpreplay +} + +clean_up() { + ip netns del ${NETNS_0} &> /dev/null + ip netns del ${NETNS_1} &> /dev/null + ip link del veth0 &> /dev/null + ip link del veth1 &> /dev/null +} + +trap clean_up EXIT + +setup() { + install_tcpreplay &> tcpreplay.log || \ + { libndp_log $? "Install tcpreplay" && cat tcpreplay.log; return 1; } + + clean_up + + ip netns add "${NETNS_0}" + ip netns add "${NETNS_1}" + ip -netns "${NETNS_0}" link set lo up + ip -netns "${NETNS_1}" link set lo up + + ip link add type veth + ip link set veth0 netns "${NETNS_0}" + ip link set veth1 netns "${NETNS_1}" + ip -netns "${NETNS_0}" link set veth0 addr 00:00:00:00:00:01 + ip -netns "${NETNS_1}" link set veth1 addr 00:00:00:00:00:02 + ip -netns "${NETNS_0}" link set veth0 up + ip -netns "${NETNS_1}" link set veth1 up +} + +monitor_nd() +{ + ip netns exec "${NETNS_1}" unbuffer ndptool -i veth1 monitor &> monitor.log & + sleep 2 + # TODO: maybe fuzz the pcap file and see if ndptool still works + ip netns exec "${NETNS_0}" tcpreplay -l 2 -i veth0 nd.pcap + sleep 2 && kill -9 $! + + grep -q "Type: NS" monitor.log; libndp_log $? "Monitor NS" + grep -q "Type: NA" monitor.log; libndp_log $? "Monitor NA" + # commit this due to bug 1082933 + # grep -q "Type: RS" monitor.log; libndp_log $? "Monitor RS" + grep -q "Type: RA" monitor.log; libndp_log $? "Monitor RA" + # TODO: add ICMPv6 redirect support + +} + +send_nd() +{ + ip netns exec "${NETNS_1}" tcpdump -i veth1 -nn -l &> rs.log & + sleep 2 + ip netns exec "${NETNS_0}" ndptool -i veth0 -t rs send + sleep 2 && kill -9 $! + + #ip netns exec "${NETNS_0}" ndptool -i veth0 -t ra send + + ip netns exec "${NETNS_1}" tcpdump -i veth1 -nn -l &> ns.log & + sleep 2 + ip netns exec "${NETNS_0}" ndptool -i veth0 -t ns send + sleep 2 && kill -9 $! + + ip netns exec "${NETNS_1}" tcpdump -i veth1 -nn -l &> ns_t.log & + sleep 2 + ip netns exec "${NETNS_0}" ndptool -i veth0 -t ns -T fe80::200:ff:fe00:2 send + sleep 2 && kill -9 $! + + #ip netns exec "${NETNS_0}" ndptool -i veth0 -t na send + + ip netns exec "${NETNS_1}" tcpdump -i veth1 -nn -l &> na_d_t.log & + sleep 2 + ip netns exec "${NETNS_0}" ndptool -i veth0 -t na -D fe80::200:ff:fe00:2 -T fe80::200:ff:fe00:1 send + sleep 2 && kill -9 $! + + ip netns exec "${NETNS_1}" tcpdump -i veth1 -nn -l &> na_u.log & + sleep 2 + ip netns exec "${NETNS_0}" ndptool -i veth0 -U -t na send + sleep 2 && kill -9 $! + + grep -q "fe80::200:ff:fe00:1 > ff02::2: ICMP6, router solicitation" rs.log; libndp_log $? "Send RS" + grep -q "fe80::200:ff:fe00:1 > ff02::1: ICMP6, neighbor solicitation, who has ::" ns.log; libndp_log $? "Send NS" + grep -q "fe80::200:ff:fe00:1 > ff02::1:ff00:2: ICMP6, neighbor solicitation, who has fe80::200:ff:fe00:2" ns_t.log; libndp_log $? "Send NS with target" + grep -q "fe80::200:ff:fe00:1 > fe80::200:ff:fe00:2: ICMP6, neighbor advertisement, tgt is fe80::200:ff:fe00:1" na_d_t.log; libndp_log $? "Send NA with dest and target" + grep -q "fe80::200:ff:fe00:1 > ff02::1: ICMP6, neighbor advertisement, tgt is ::" na_u.log; libndp_log $? "Send unsolicited NA" +} + +setup || exit 1 +monitor_nd +send_nd + +printf "\nTests passed: %3d\n" ${nsuccess} +printf "Tests failed: %3d\n" ${nfail} + +if [ ${nfail} -ne 0 ]; then + echo -e "\nDEBUG INFO:\n" + for log in `ls *.log`; do + echo "# cat $log" + cat $log + done +fi + +exit $ret diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..193bce2 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,17 @@ +# Tests for libndp +- hosts: localhost + roles: + - role: standard-test-basic + required_packages: + - expect + - gcc + - libpcap-devel + - make + - tcpdump + - wget + tags: + - classic + tests: + - sanity-tests: + dir: basic + run: sh send_monitor_nd.sh