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