| 1 |
#!/usr/bin/expect -f |
| 2 |
# |
| 3 |
# Usage: packets.exp <path to arping> |
| 4 |
# |
| 5 |
# Uses dummy0 interface on linux to verify that packets are byte-perfect |
| 6 |
# when they're sent out from arping. |
| 7 |
# |
| 8 |
# Ideas: |
| 9 |
# * Run this with a new network namespace, to eliminate stray packets. |
| 10 |
# * Merge with testing.exp. |
| 11 |
# |
| 12 |
# Currently tested: |
| 13 |
# -b |
| 14 |
# -d |
| 15 |
# -0 |
| 16 |
# -S |
| 17 |
# |
| 18 |
set bin [lindex $argv 0] |
| 19 |
set DEV "dummy0" |
| 20 |
set my_mac "52:2b:c8:01:02:03" |
| 21 |
set PACKETDUMP "packetdump.pcap" |
| 22 |
|
| 23 |
proc dotest {name count filter cmd lines} { |
| 24 |
upvar DEV DEV |
| 25 |
upvar PACKETDUMP PACKETDUMP |
| 26 |
upvar bin bin |
| 27 |
upvar my_mac my_mac |
| 28 |
|
| 29 |
send_user -- "----------- $name -----------\n" |
| 30 |
send_user -- "Command: $cmd\n" |
| 31 |
spawn ip a a 192.0.2.100/24 dev "$DEV" |
| 32 |
expect eof |
| 33 |
|
| 34 |
spawn ip l set dev "$DEV" address "$my_mac" |
| 35 |
expect eof |
| 36 |
|
| 37 |
spawn ip l set up "$DEV" |
| 38 |
expect eof |
| 39 |
|
| 40 |
spawn tcpdump -c $count -i "$DEV" -s1500 -w "${PACKETDUMP}" "${filter}" |
| 41 |
set tcpdump_id $spawn_id |
| 42 |
expect -re "tcpdump: listening on .*bytes\r" |
| 43 |
|
| 44 |
spawn $bin {*}[eval "concat $cmd"] |
| 45 |
expect eof |
| 46 |
|
| 47 |
spawn ip l set down "$DEV" |
| 48 |
spawn ip a d 192.0.2.100/24 dev "$DEV" |
| 49 |
|
| 50 |
set spawn_id $tcpdump_id |
| 51 |
wait |
| 52 |
|
| 53 |
spawn -noecho tcpdump -etnXXr "${PACKETDUMP}" "${filter}" |
| 54 |
#log_user 0 |
| 55 |
foreach l $lines { |
| 56 |
puts "Expecting: $l" |
| 57 |
expect "$l\r" |
| 58 |
} |
| 59 |
expect eof |
| 60 |
#log_user 1 |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
dotest "Simple" 1 "arp" {-c 1 -i "$DEV" 192.0.2.1} { |
| 65 |
"52:2b:c8:01:02:03 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 192.0.2.1 tell 192.0.2.100, length 28" |
| 66 |
"\t0x0000: ffff ffff ffff 522b c801 0203 0806 0001 ......R+........" |
| 67 |
"\t0x0010: 0800 0604 0001 522b c801 0203 c000 0264 ......R+.......d" |
| 68 |
"\t0x0020: 0000 0000 0000 c000 0201 .........." |
| 69 |
} |
| 70 |
|
| 71 |
dotest "SrcIP 0 -0" 1 "arp" {-0 -c 1 -i "$DEV" 192.0.2.1} { |
| 72 |
"52:2b:c8:01:02:03 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 192.0.2.1 tell 0.0.0.0, length 28" |
| 73 |
"\t0x0000: ffff ffff ffff 522b c801 0203 0806 0001 ......R+........" |
| 74 |
"\t0x0010: 0800 0604 0001 522b c801 0203 0000 0000 ......R+........" |
| 75 |
"\t0x0020: 0000 0000 0000 c000 0201 .........." |
| 76 |
} |
| 77 |
|
| 78 |
dotest "SrcIP bc -b" 1 "arp" {-b -c 1 -i "$DEV" 192.0.2.1} { |
| 79 |
"52:2b:c8:01:02:03 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 192.0.2.1 tell 255.255.255.255, length 28" |
| 80 |
"\t0x0000: ffff ffff ffff 522b c801 0203 0806 0001 ......R+........" |
| 81 |
"\t0x0010: 0800 0604 0001 522b c801 0203 ffff ffff ......R+........" |
| 82 |
"\t0x0020: 0000 0000 0000 c000 0201 .........." |
| 83 |
} |
| 84 |
|
| 85 |
dotest "SrcIP bc manual" 1 "arp" {-S 255.255.255.255 -c 1 -i "$DEV" 192.0.2.1} { |
| 86 |
"52:2b:c8:01:02:03 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 192.0.2.1 tell 255.255.255.255, length 28" |
| 87 |
"\t0x0000: ffff ffff ffff 522b c801 0203 0806 0001 ......R+........" |
| 88 |
"\t0x0010: 0800 0604 0001 522b c801 0203 ffff ffff ......R+........" |
| 89 |
"\t0x0020: 0000 0000 0000 c000 0201 .........." |
| 90 |
} |
| 91 |
|
| 92 |
dotest "SrcIP other manual" 1 "arp" {-S 61.62.63.64 -c 1 -i "$DEV" 192.0.2.1} { |
| 93 |
"52:2b:c8:01:02:03 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 192.0.2.1 tell 61.62.63.64, length 28" |
| 94 |
"\t0x0000: ffff ffff ffff 522b c801 0203 0806 0001 ......R+........" |
| 95 |
"\t0x0010: 0800 0604 0001 522b c801 0203 3d3e 3f40 ......R+....=>?@" |
| 96 |
"\t0x0020: 0000 0000 0000 c000 0201 .........." |
| 97 |
} |
| 98 |
|
| 99 |
dotest "Finddup" 1 "arp" {-c 1 -d -i "$DEV"} { |
| 100 |
"52:2b:c8:01:02:03 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 192.0.2.100 tell 192.0.2.100, length 28" |
| 101 |
"\t0x0000: ffff ffff ffff 522b c801 0203 0806 0001 ......R+........" |
| 102 |
"\t0x0010: 0800 0604 0001 522b c801 0203 c000 0264 ......R+.......d" |
| 103 |
"\t0x0020: 0000 0000 0000 c000 0264 .........d" |
| 104 |
} |
| 105 |
|
| 106 |
send_user "\n==================== ALL DONE =================\n" |
| 107 |
|
| 108 |
# ---- Emacs Variables ---- |
| 109 |
# Local Variables: |
| 110 |
# c-basic-offset: 8 |
| 111 |
# tcl-basic-offset: 8 |
| 112 |
# indent-tabs-mode: nil |
| 113 |
# End: |
| 114 |
# |
| 115 |
# vim: ts=8 sw=8 |