ping tests: Add a regression test

Test regression fixed in 4630a3252a. Add two tests that do not
use the verbose flag, so the code path in question can be reached:

1. Respond with a proper ICMP destination host unreachable packet.
2. Respond with a doctored ICMP destination host unreachable packet,
   that has the ICMP Identifier field modified (+1 bit).

Reviewed by:	cy
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39244
This commit is contained in:
Jose Luis Duran 2023-03-25 20:11:50 -07:00 committed by Cy Schubert
parent ec1bc53002
commit 9fc2d858b4

View File

@ -56,6 +56,9 @@ def build_response_packet(echo, ip, icmp, oip_ihl, special):
# Build a package with a wrong last byte
payload_no_last_byte = sc.bytes_hex(load)[:-2]
load = (sc.hex_bytes(payload_no_last_byte)) + b"\x00"
if special == "not-mine":
# Modify the ICMP Identifier field
oicmp.id += 1
if icmp.type in icmp_id_seq_types:
pkt = ip / icmp / load
@ -148,6 +151,7 @@ def pinger(
# Miscellaneous arguments
count: int = 1,
dup: bool = False,
verbose: bool = True,
) -> subprocess.CompletedProcess:
"""P I N G E R
@ -173,8 +177,8 @@ def pinger(
:type opts: str, optional
:keyword oip_ihl: Inner packet's Internet Header Length, defaults to None
:type oip_ihl: class:`scapy.fields.BitField`, optional
:keyword special: Send a special packet - one of `no-payload`, `tcp`,
`udp`, `wrong` or `warp`, defaults to None
:keyword special: Send a special packet - one of `no-payload`, `not-mine`,
`tcp`, `udp`, `wrong` or `warp`, defaults to None
:type special: str, optional
:keyword icmp_pptr: ICMP pointer, defaults to 0
:type icmp_pptr: class:`scapy.fields.ByteField`
@ -197,6 +201,8 @@ def pinger(
:type count: int
:keyword dup: Duplicate packets, defaults to `False`
:type dup: bool
:keyword verbose: Turn on/off verbosity, defaults to `True`
:type verbose: bool
:return: A class:`subprocess.CompletedProcess` with the output from the
ping utility
@ -213,8 +219,9 @@ def pinger(
str(count),
"-t",
str(count),
"-v",
]
if verbose:
command += ["-v"]
if request == "mask":
command += ["-Mm"]
if request == "timestamp":
@ -1210,6 +1217,54 @@ def test_ping_46(self, expected):
},
id="_3_1_special_udp",
),
pytest.param(
{
"src": "192.0.2.1",
"dst": "192.0.2.2",
"icmp_type": 3,
"icmp_code": 1,
"verbose": False,
},
{
"returncode": 2,
"stdout": """\
PING 192.0.2.2 (192.0.2.2): 56 data bytes
92 bytes from 192.0.2.2: Destination Host Unreachable
Vr HL TOS Len ID Flg off TTL Pro cks Src Dst
4 5 00 0054 0001 0 0000 40 01 f6a4 192.0.2.1 192.0.2.2
--- 192.0.2.2 ping statistics ---
1 packets transmitted, 0 packets received, 100.0% packet loss
""",
"stderr": "",
"redacted": False,
},
id="_3_1_verbose_false",
),
pytest.param(
{
"src": "192.0.2.1",
"dst": "192.0.2.2",
"icmp_type": 3,
"icmp_code": 1,
"special": "not-mine",
"verbose": False,
},
{
"returncode": 2,
"stdout": """\
PATTERN: 0x01
PING 192.0.2.2 (192.0.2.2): 56 data bytes
--- 192.0.2.2 ping statistics ---
1 packets transmitted, 0 packets received, 100.0% packet loss
""",
"stderr": "",
"redacted": False,
},
id="_3_1_special_not_mine_verbose_false",
),
pytest.param(
{
"src": "192.0.2.1",