summaryrefslogtreecommitdiff
path: root/regress/sys/kern/sosplice/scapy/scapy-payload-delay-connect.py
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2020-12-25 16:50:41 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2020-12-25 16:50:41 +0000
commitb076a4ce3441ffde6f43779bde8949af58118170 (patch)
treeb8d27c3a0b11b0f4b48f6d790015fabef6576c81 /regress/sys/kern/sosplice/scapy/scapy-payload-delay-connect.py
parentfda3c6e935a2ffe2518ef6fae079686b2221b4a3 (diff)
Switch to scapy with python 3.
Diffstat (limited to 'regress/sys/kern/sosplice/scapy/scapy-payload-delay-connect.py')
-rw-r--r--regress/sys/kern/sosplice/scapy/scapy-payload-delay-connect.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/regress/sys/kern/sosplice/scapy/scapy-payload-delay-connect.py b/regress/sys/kern/sosplice/scapy/scapy-payload-delay-connect.py
index 4b58b32c2a1..aeef1eeeedc 100644
--- a/regress/sys/kern/sosplice/scapy/scapy-payload-delay-connect.py
+++ b/regress/sys/kern/sosplice/scapy/scapy-payload-delay-connect.py
@@ -1,4 +1,4 @@
-#!/usr/local/bin/python2.7
+#!/usr/local/bin/python3
# send payload from client to relay before connecting to server
import os
@@ -28,55 +28,55 @@ class Sniff1(threading.Thread):
ip=IP(src=FAKE_NET_ADDR, dst=REMOTE_ADDR)
-print "Send SYN packet, receive SYN+ACK"
+print("Send SYN packet, receive SYN+ACK")
syn=TCP(sport=client, dport=relay, seq=0, flags='S', window=(2**16)-1)
synack=sr1(ip/syn, iface=LOCAL_IF, timeout=5)
if synack is None:
- print "ERROR: No matching SYN+ACK packet received"
+ print("ERROR: No matching SYN+ACK packet received")
exit(1)
-print "Send ACK packet to finish handshake"
+print("Send ACK packet to finish handshake")
ack=TCP(sport=synack.dport, dport=synack.sport,
seq=1, ack=synack.seq+1, flags='A')
send(ip/ack, iface=LOCAL_IF)
-print "Expect spliced SYN"
+print("Expect spliced SYN")
sniffer = Sniff1();
sniffer.filter = "src %s and dst %s and tcp port %u " \
"and tcp[tcpflags] = tcp-syn" % (ip.dst, ip.src, server)
sniffer.start()
time.sleep(1)
-print "Send 10 bytes payload"
+print("Send 10 bytes payload")
data="0123456789"
payload=TCP(sport=synack.dport, dport=synack.sport,
seq=1, ack=synack.seq+1, flags='APU')/data
payload_ack=sr1(ip/payload, iface=LOCAL_IF)
if payload_ack is None:
- print "ERROR: No payload ACK packet received"
+ print("ERROR: No payload ACK packet received")
exit(1)
if payload_ack.ack != len(data)+1:
- print "ERROR: Expected ack %d, got %d in payload ACK" % \
- (len(data)+1, payload_ack.ack)
+ print("ERROR: Expected ack %d, got %d in payload ACK" %
+ (len(data)+1, payload_ack.ack))
exit(1)
sniffer.join(timeout=7)
spliced_syn = sniffer.packet
if spliced_syn is None:
- print "ERROR: No spliced SYN packet received"
+ print("ERROR: No spliced SYN packet received")
exit(1)
-print "Expect spliced payload"
+print("Expect spliced payload")
sniffer = Sniff1();
sniffer.filter = "src %s and dst %s and tcp port %u " \
"and tcp[tcpflags] = tcp-ack|tcp-push" % (ip.dst, ip.src, server)
sniffer.start()
time.sleep(1)
-print "Wait for splicing syscall, grep it in relay log"
+print("Wait for splicing syscall, grep it in relay log")
def loggrep(file, regex, timeout):
for i in range(timeout):
for line in open(file, 'r'):
@@ -85,34 +85,34 @@ def loggrep(file, regex, timeout):
time.sleep(1)
return None
if not loggrep("relay.log", "Spliced", 5):
- print "ERROR: Relay did not splice"
+ print("ERROR: Relay did not splice")
exit(1)
-print "Send spliced SYN+ACK packet to finish handshake"
+print("Send spliced SYN+ACK packet to finish handshake")
spliced_synack=TCP(sport=spliced_syn.dport, dport=spliced_syn.sport,
seq=0, ack=spliced_syn.seq+1, flags='SA')
spliced_ack=sr1(ip/spliced_synack, iface=LOCAL_IF)
if spliced_ack is None:
- print "ERROR: No spliced ACK packet received"
+ print("ERROR: No spliced ACK packet received")
exit(1)
sniffer.join(timeout=7)
spliced_payload = sniffer.packet
if spliced_payload is None:
- print "ERROR: No spliced payload packet received"
+ print("ERROR: No spliced payload packet received")
exit(1)
if spliced_payload.seq != spliced_ack.seq:
- print "ERROR: Expected seq %d, got %d in spliced payload" % \
- (spliced_ack.seq, spliced_payload.seq)
+ print("ERROR: Expected seq %d, got %d in spliced payload" %
+ (spliced_ack.seq, spliced_payload.seq))
exit(1)
if spliced_payload.len-20-20 != len(data):
- print "ERROR: Expected len %d, got %d in spliced payload" % \
- (len(data), spliced_payload.len-20-20)
+ print("ERROR: Expected len %d, got %d in spliced payload" %
+ (len(data), spliced_payload.len-20-20))
exit(1)
-print "Kill connections with RST"
+print("Kill connections with RST")
spliced_rst=TCP(sport=spliced_ack.dport, dport=spliced_ack.sport,
seq=1, ack=spliced_ack.seq, flags='RA')
send(ip/spliced_rst, iface=LOCAL_IF)