Skip to content

Commit

Permalink
tests/divert: use PF_DIVERT
Browse files Browse the repository at this point in the history
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 322b5b7.

[1] python/cpython#96536 (comment)
  • Loading branch information
glebius authored and bsdjhb committed Feb 28, 2023
2 parents 9e9fbe5 + 5e4ae30 commit 532af6f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions tests/sys/common/divert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -52,22 +49,22 @@ 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))


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))

Expand Down

0 comments on commit 532af6f

Please sign in to comment.