git: 5e4ae3061f27 - main - tests/divert: use PF_DIVERT

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Mon, 26 Dec 2022 20:07:14 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=5e4ae3061f27039ccc13b4d08004bdaf369f291c

commit 5e4ae3061f27039ccc13b4d08004bdaf369f291c
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2022-12-26 19:10:15 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2022-12-26 20:02:45 +0000

    tests/divert: use PF_DIVERT
    
    Now all Python ports has been patched to support PF_DIVERT, and
    Python kinda promises to add support in 3.12 [1].
    
    This reverts commit 322b5b7c16666c40d2763f18c1a51e6f0580d4e9.
    
    [1] https://github.com/python/cpython/pull/96536#issuecomment-1303974686
---
 tests/sys/common/divert.py | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/tests/sys/common/divert.py b/tests/sys/common/divert.py
index 94e20a03571f..061f787d1b7a 100755
--- a/tests/sys/common/divert.py
+++ b/tests/sys/common/divert.py
@@ -29,16 +29,13 @@
 #
 
 
-import socket
+from socket import socket, PF_DIVERT, SOCK_RAW
 import logging
 logging.getLogger("scapy").setLevel(logging.CRITICAL)
 import scapy.all as sc
 import argparse
 
 
-IPPROTO_DIVERT = 258
-
-
 def parse_args():
     parser = argparse.ArgumentParser(description='divert socket tester')
     parser.add_argument('--dip', type=str, help='destination packet IP')
@@ -52,14 +49,14 @@ def parse_args():
 
 def ipdivert_ip_output_remote_success(args):
     packet = sc.IP(dst=args.dip) / sc.ICMP(type='echo-request')
-    with socket.socket(socket.AF_INET, socket.SOCK_RAW, IPPROTO_DIVERT) as s:
+    with socket(PF_DIVERT, SOCK_RAW, 0) as s:
         s.bind(('0.0.0.0', args.divert_port))
         s.sendto(bytes(packet), ('0.0.0.0', 0))
 
 
 def ipdivert_ip6_output_remote_success(args):
     packet = sc.IPv6(dst=args.dip) / sc.ICMPv6EchoRequest()
-    with socket.socket(socket.AF_INET, socket.SOCK_RAW, IPPROTO_DIVERT) as s:
+    with socket(PF_DIVERT, SOCK_RAW, 0) as s:
         s.bind(('0.0.0.0', args.divert_port))
         s.sendto(bytes(packet), ('0.0.0.0', 0))
 
@@ -67,7 +64,7 @@ def ipdivert_ip6_output_remote_success(args):
 def ipdivert_ip_input_local_success(args):
     """Sends IPv4 packet to OS stack as inbound local packet."""
     packet = sc.IP(dst=args.dip,src=args.sip) / sc.ICMP(type='echo-request')
-    with socket.socket(socket.AF_INET, socket.SOCK_RAW, IPPROTO_DIVERT) as s:
+    with socket(PF_DIVERT, SOCK_RAW, 0) as s:
         s.bind(('0.0.0.0', args.divert_port))
         s.sendto(bytes(packet), (args.dip, 0))