xref: /openbsd-src/regress/sys/netinet/arp/arp_probe.py (revision ac29c8e0bbd85ab37116eea98eaaa09e07bf6b26)
1*ac29c8e0Sbluhm#!/usr/local/bin/python3
2a13597faSbluhm# send Address Resolution Protocol Probe
3a13597faSbluhm# expect Address Resolution Protocol response and check all fields
4a13597faSbluhm# RFC 5227  IPv4 Address Conflict Detection
5a13597faSbluhm# 2.1.1.  Probe Details
6a13597faSbluhm
7a13597faSbluhm
8a13597faSbluhmimport os
9a13597faSbluhmfrom addr import *
10a13597faSbluhmfrom scapy.all import *
11a13597faSbluhm
12a13597faSbluhmarp=ARP(op='who-has', hwsrc=LOCAL_MAC, psrc="0.0.0.0",
13a13597faSbluhm    hwdst="00:00:00:00:00:00", pdst=REMOTE_ADDR)
14a13597faSbluhmeth=Ether(src=LOCAL_MAC, dst="ff:ff:ff:ff:ff:ff")/arp
15a13597faSbluhm
16a13597faSbluhme=srp1(eth, iface=LOCAL_IF, timeout=2)
17a13597faSbluhm
18a13597faSbluhmif e and e.type == ETH_P_ARP:
19a13597faSbluhm	a=e.payload
20a13597faSbluhm	if a.hwtype != ARPHDR_ETHER:
21*ac29c8e0Sbluhm		print("HWTYPE=%#0.4x != ARPHDR_ETHER" % (a.hwtype))
22a13597faSbluhm		exit(1)
23a13597faSbluhm	if a.ptype != ETH_P_IP:
24*ac29c8e0Sbluhm		print("PTYPE=%#0.4x != ETH_P_IP" % (a.ptype))
25a13597faSbluhm		exit(1)
26a13597faSbluhm	if a.hwlen != 6:
27*ac29c8e0Sbluhm		print("HWLEN=%d != 6" % (a.hwlen))
28a13597faSbluhm		exit(1)
29a13597faSbluhm	if a.plen != 4:
30*ac29c8e0Sbluhm		print("PLEN=%d != 4" % (a.plen))
31a13597faSbluhm		exit(1)
32a13597faSbluhm	if a.op != 2:
33*ac29c8e0Sbluhm		print("OP=%s != is-at" % (a.op))
34a13597faSbluhm		exit(1)
35a13597faSbluhm	if a.hwsrc != REMOTE_MAC:
36*ac29c8e0Sbluhm		print("HWLOCAL=%s != REMOTE_MAC" % (a.hwsrc))
37a13597faSbluhm		exit(1)
38a13597faSbluhm	if a.psrc != REMOTE_ADDR:
39*ac29c8e0Sbluhm		print("PLOCAL=%s != REMOTE_ADDR" % (a.psrc))
40a13597faSbluhm		exit(1)
41a13597faSbluhm	if a.hwdst != LOCAL_MAC:
42*ac29c8e0Sbluhm		print("HWREMOTE=%s != LOCAL_MAC" % (a.hwdst))
43a13597faSbluhm		exit(1)
44a13597faSbluhm	if a.pdst != "0.0.0.0":
45*ac29c8e0Sbluhm		print("PREMOTE=%s != 0.0.0.0" % (a.pdst))
46a13597faSbluhm		exit(1)
47*ac29c8e0Sbluhm	print("arp reply")
48a13597faSbluhm	exit(0)
49a13597faSbluhm
50*ac29c8e0Sbluhmprint("NO ARP REPLY")
51a13597faSbluhmexit(2)
52