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