4
4
5
5
#######
6
6
+ Test Linux-specific protocol headers for TunTap
7
- ~ linux tun
7
+ ~ linux tun not_libpcap
8
8
9
9
= Linux-specific protocol headers
10
10
@@ -26,7 +26,7 @@ assert isinstance(p.payload, IPv6)
26
26
#######
27
27
+ Test tun device
28
28
29
- ~ tun netaccess
29
+ ~ tun netaccess not_libpcap
30
30
31
31
= Create a tun interface
32
32
@@ -47,32 +47,31 @@ elif BSD:
47
47
else:
48
48
raise NotImplementedError()
49
49
50
+ conf.ifaces.reload()
51
+ conf.route.resync()
52
+ conf.route6.resync()
53
+
50
54
= Setup ICMPEcho_am on the interface
51
55
52
56
am = tun0.am(ICMPEcho_am, count=3)
53
57
am.defoptsniff['timeout'] = 5
54
58
t_am = Thread(target=am)
55
59
t_am.start()
56
- time.sleep(1)
57
60
58
61
= Send ping packets from OS into scapy
59
62
60
- # ping returns non-zero exit code on 100% packet loss
61
- assert subprocess.check_call(["ping", "-c3", "192.0.2.2"]) == 0
63
+ send(IP(dst="192.0.2.2")/ICMP(seq=(1,3)))
62
64
63
65
= Cleanup
64
66
65
67
t_am.join(timeout=3)
66
68
67
69
tun0.close()
68
- if not conf.use_pypy:
69
- # See https://pypy.readthedocs.io/en/latest/cpython_differences.html
70
- del tun0
71
70
72
71
#######
73
72
+ Test strip_packet_info=False on Linux
74
73
75
- ~ tun linux netaccess
74
+ ~ tun linux netaccess not_libpcap
76
75
77
76
= Create a tun interface
78
77
@@ -88,17 +87,18 @@ assert subprocess.check_call([
88
87
"ip", "addr", "change",
89
88
"192.0.2.1", "peer", "192.0.2.2", "dev", "tun0"]) == 0
90
89
91
- = Send ping packets from Linux into Scapy
90
+ conf.ifaces.reload()
91
+ conf.route.resync()
92
+ conf.route6.resync()
92
93
93
- t = AsyncSniffer(opened_socket=tun0)
94
- t.start()
94
+ = Send ping packets from Linux into Scapy
95
95
96
- # We expect this to return exit code 1, because there's nothing in Scapy that
97
- # responds to these packets.
98
- assert subprocess.call(["ping", "-c3", "192.0.2.2"]) == 1
96
+ def cb():
97
+ send(IP(dst="192.0.2.2")/ICMP(seq=(1,3)))
99
98
100
- time.sleep(1)
101
- t.stop()
99
+ t = AsyncSniffer(opened_socket=tun0, lfilter=lambda x: IP in x, started_callback=cb, count=3)
100
+ t.start()
101
+ t.join(timeout=3)
102
102
103
103
assert len(t.results) >= 3
104
104
icmp4_sequences = set()
@@ -118,13 +118,10 @@ assert len(icmp4_sequences) == 3
118
118
119
119
= Delete the tun interface
120
120
tun0.close()
121
- if not conf.use_pypy:
122
- # See https://pypy.readthedocs.io/en/latest/cpython_differences.html
123
- del tun0
124
121
125
122
+ Test strip_packet_info=True and IPv6
126
123
127
- ~ tun netaccess ipv6
124
+ ~ tun netaccess ipv6 not_libpcap
128
125
129
126
= Create a tun interface with IPv4 + IPv6
130
127
@@ -149,19 +146,19 @@ elif BSD:
149
146
else:
150
147
raise NotImplementedError()
151
148
152
- = Send ping packets from OS into Scapy
149
+ conf.ifaces.reload()
150
+ conf.route.resync()
151
+ conf.route6.resync()
153
152
154
- t = AsyncSniffer(opened_socket=tun0)
155
- t.start()
153
+ = Send ping packets from OS into Scapy
156
154
157
- # There's nothing in Scapy that responds, but we expect the packets to be sent
158
- # successfully. Linux and BSD (incl. macOS) have different exit codes.
159
- EXPECTED_EXIT = 1 if LINUX else 2
160
- assert subprocess.call(["ping", "-c3", "192.0.2.2"]) == EXPECTED_EXIT
161
- assert subprocess.call(["ping6", "-c3", "2001:db8::2"]) == EXPECTED_EXIT
155
+ def cb():
156
+ send(IP(dst="192.0.2.2")/ICMP(seq=(1,3)))
157
+ send(IPv6(dst="2001:db8::2")/ICMPv6EchoRequest(seq=(1,3)))
162
158
163
- time.sleep(1)
164
- t.stop()
159
+ t = AsyncSniffer(opened_socket=tun0, lfilter=lambda x: ICMP in x or ICMPv6EchoRequest in x, started_callback=cb, count=6)
160
+ t.start()
161
+ t.join(timeout=3)
165
162
166
163
assert len(t.results) >= 6
167
164
icmp4_sequences = set()
@@ -187,13 +184,10 @@ assert len(icmp6_sequences) == 3, (
187
184
188
185
= Delete the tun interface
189
186
tun0.close()
190
- if not conf.use_pypy:
191
- # See https://pypy.readthedocs.io/en/latest/cpython_differences.html
192
- del tun0
193
187
194
188
+ Test tap interfaces
195
189
196
- ~ tap netaccess
190
+ ~ tap netaccess not_libpcap
197
191
198
192
= Create a tap interface with IPv4
199
193
@@ -215,18 +209,21 @@ else:
215
209
assert subprocess.check_call([
216
210
"arp", "-s", "192.0.2.2", "20:00:00:20:00:00", "temp"]) == 0
217
211
212
+ conf.ifaces.reload()
213
+ conf.route.resync()
214
+ conf.route6.resync()
215
+
218
216
= Send ping packets from OS into Scapy
219
217
220
- t = AsyncSniffer(opened_socket=tap0)
221
- t.start()
218
+ conf.ifaces
219
+ conf.route
222
220
223
- # There's nothing in Scapy that responds, but we expect the packets to be sent
224
- # successfully. Linux and BSD (incl. macOS) have different exit codes.
225
- EXPECTED_EXIT = 1 if LINUX else 2
226
- assert subprocess.call(["ping", "-c3", "192.0.2.2"]) == EXPECTED_EXIT
221
+ def cb():
222
+ sendp(Ether(dst="ff:ff:ff:ff:ff:ff")/IP(dst="192.0.2.2")/ICMP(seq=(1,3)), iface="tap0")
227
223
228
- time.sleep(1)
229
- t.stop()
224
+ t = AsyncSniffer(opened_socket=tap0, lfilter=lambda x: ICMP in x, started_callback=cb, count=3)
225
+ t.start()
226
+ t.join(timeout=3)
230
227
231
228
assert len(t.results) >= 3
232
229
icmp4_sequences = set()
@@ -245,6 +242,12 @@ assert len(icmp4_sequences) == 3, (
245
242
246
243
= Delete the tap interface
247
244
tap0.close()
248
- if not conf.use_pypy:
249
- # See https://pypy.readthedocs.io/en/latest/cpython_differences.html
250
- del tap0
245
+
246
+ + Refresh interfaces
247
+ ~ linux tun tap not_libpcap
248
+
249
+ = Cleanup
250
+
251
+ conf.ifaces.reload()
252
+ conf.route.resync()
253
+ conf.route6.resync()
0 commit comments