Skip to content

probe_mtu doesn't work on Alpine Linux #3

@zonescape

Description

@zonescape

I think this is because of ping command on Alpine Linux has different options than e.g. on Debian.

# docker container run -it --rm python:3.13.1-alpine3.21 sh

/ # ping -c 1 -s 1072 -W 4 -i 1 -M do -4 192.168.1.1
ping: unrecognized option: M
BusyBox v1.37.0 (2024-12-13 21:18:49 UTC) multi-call binary.

Usage: ping [OPTIONS] HOST

Send ICMP ECHO_REQUESTs to HOST

	-4,-6		Force IP or IPv6 name resolution
	-c CNT		Send only CNT pings
	-s SIZE		Send SIZE data bytes in packets (default 56)
	-i SECS		Interval
	-A		Ping as soon as reply is received
	-t TTL		Set TTL
	-I IFACE/IP	Source interface or IP address
	-W SEC		Seconds to wait for the first response (default 10)
			(after all -c CNT packets are sent)
	-w SEC		Seconds until ping exits (default:infinite)
			(can exit earlier with -c CNT)
	-q		Quiet, only display output at start/finish
	-p HEXBYTE	Payload pattern

Here is the steps to reproduce the bug:

# docker container run -it --rm python:3.13.1-alpine3.21 sh

/ # python --version
Python 3.13.1

/ # pip --version
pip 24.3.1 from /usr/local/lib/python3.13/site-packages/pip (python 3.13)

/ # apk add gcc python3-dev musl-dev linux-headers
fetch https://dl-cdn.alpinelinux.org/alpine/v3.21/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.21/community/x86_64/APKINDEX.tar.gz
(1/22) Installing libgcc (14.2.0-r4)
(2/22) Installing jansson (2.14-r4)
(3/22) Installing libstdc++ (14.2.0-r4)
(4/22) Installing zstd-libs (1.5.6-r2)
(5/22) Installing binutils (2.43.1-r1)
(6/22) Installing libgomp (14.2.0-r4)
(7/22) Installing libatomic (14.2.0-r4)
(8/22) Installing gmp (6.3.0-r2)
(9/22) Installing isl26 (0.26-r1)
(10/22) Installing mpfr4 (4.2.1-r0)
(11/22) Installing mpc1 (1.3.1-r1)
(12/22) Installing gcc (14.2.0-r4)
(13/22) Installing linux-headers (6.6-r1)
(14/22) Installing musl-dev (1.2.5-r8)
(15/22) Installing pkgconf (2.3.0-r0)
(16/22) Installing libexpat (2.6.4-r0)
(17/22) Installing mpdecimal (4.0.0-r0)
(18/22) Installing python3 (3.12.8-r1)
(19/22) Installing python3-pycache-pyc0 (3.12.8-r1)
(20/22) Installing pyc (3.12.8-r1)
(21/22) Installing python3-pyc (3.12.8-r1)
(22/22) Installing python3-dev (3.12.8-r1)
Executing busybox-1.37.0-r9.trigger
OK: 305 MiB in 50 packages

/ # pip install ofunctions.network
Collecting ofunctions.network
  Downloading ofunctions.network-1.6.0-py3-none-any.whl.metadata (18 kB)
Collecting requests>=2.22.0 (from ofunctions.network)
  Downloading requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)
Collecting command-runner>=1.3.1 (from ofunctions.network)
  Downloading command_runner-1.7.0-py3-none-any.whl.metadata (26 kB)
Collecting ofunctions.bisection>=0.2.1 (from ofunctions.network)
  Downloading ofunctions.bisection-1.0.0-py3-none-any.whl.metadata (9.0 kB)
Collecting ofunctions.threading>=2.3.0 (from ofunctions.network)
  Downloading ofunctions.threading-2.3.0-py3-none-any.whl.metadata (17 kB)
Collecting ofunctions.misc>=1.5.2 (from ofunctions.network)
  Downloading ofunctions.misc-1.8.0-py3-none-any.whl.metadata (18 kB)
Collecting psutil>=5.3.0 (from ofunctions.network)
  Downloading psutil-6.1.1.tar.gz (508 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting typing>=3.5.0 (from ofunctions.network)
  Downloading typing-3.7.4.3.tar.gz (78 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting ipaddress (from ofunctions.network)
  Downloading ipaddress-1.0.23-py2.py3-none-any.whl.metadata (923 bytes)
Collecting charset-normalizer<4,>=2 (from requests>=2.22.0->ofunctions.network)
  Downloading charset_normalizer-3.4.1-cp313-cp313-musllinux_1_2_x86_64.whl.metadata (35 kB)
Collecting idna<4,>=2.5 (from requests>=2.22.0->ofunctions.network)
  Downloading idna-3.10-py3-none-any.whl.metadata (10 kB)
Collecting urllib3<3,>=1.21.1 (from requests>=2.22.0->ofunctions.network)
  Downloading urllib3-2.3.0-py3-none-any.whl.metadata (6.5 kB)
Collecting certifi>=2017.4.17 (from requests>=2.22.0->ofunctions.network)
  Downloading certifi-2024.12.14-py3-none-any.whl.metadata (2.3 kB)
Downloading ofunctions.network-1.6.0-py3-none-any.whl (15 kB)
Downloading command_runner-1.7.0-py3-none-any.whl (25 kB)
Downloading ofunctions.bisection-1.0.0-py3-none-any.whl (8.0 kB)
Downloading ofunctions.misc-1.8.0-py3-none-any.whl (13 kB)
Downloading ofunctions.threading-2.3.0-py3-none-any.whl (11 kB)
Downloading requests-2.32.3-py3-none-any.whl (64 kB)
Downloading ipaddress-1.0.23-py2.py3-none-any.whl (18 kB)
Downloading certifi-2024.12.14-py3-none-any.whl (164 kB)
Downloading charset_normalizer-3.4.1-cp313-cp313-musllinux_1_2_x86_64.whl (145 kB)
Downloading idna-3.10-py3-none-any.whl (70 kB)
Downloading urllib3-2.3.0-py3-none-any.whl (128 kB)
Building wheels for collected packages: psutil, typing
  Building wheel for psutil (pyproject.toml) ... done
  Created wheel for psutil: filename=psutil-6.1.1-cp36-abi3-linux_x86_64.whl size=283373 sha256=d61e3ac7210bd39db4ae1a86bf5ad080b773196ed92a5d8ef003bbcbcaec391d
  Stored in directory: /root/.cache/pip/wheels/ff/fe/eb/59cac25690b1a9600e50b007a414ddabb88c04e3ca5df008d9
  Building wheel for typing (pyproject.toml) ... done
  Created wheel for typing: filename=typing-3.7.4.3-py3-none-any.whl size=26365 sha256=16cbc3570112ac826109cd4b73dbef1eca6ddde996f868f080f433bf544bbb09
  Stored in directory: /root/.cache/pip/wheels/5d/1b/f4/fbdc2bc618f0ba7aec7295d67f62d40e6027a6ce14df9ec3c8
Successfully built psutil typing
Installing collected packages: ipaddress, urllib3, typing, psutil, ofunctions.threading, idna, charset-normalizer, certifi, requests, ofunctions.misc, ofunctions.bisection, command-runner, ofunctions.network
Successfully installed certifi-2024.12.14 charset-normalizer-3.4.1 command-runner-1.7.0 idna-3.10 ipaddress-1.0.23 ofunctions.bisection-1.0.0 ofunctions.misc-1.8.0 ofunctions.network-1.6.0 ofunctions.threading-2.3.0 psutil-6.1.1 requests-2.32.3 typing-3.7.4.3 urllib3-2.3.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.

/ # python
Python 3.13.1 (main, Jan  8 2025, 18:18:10) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> from ofunctions.network import probe_mtu

>>> print(probe_mtu("192.168.1.1"))
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/ofunctions/network/__init__.py", line 451, in probe_mtu
    return bisection.bisect(ping, ping_args, allow_all_expected=True)[1]
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/ofunctions/bisection/__init__.py", line 79, in bisect
    raise ValueError("Both sides of the argument list are unexpected results")
ValueError: Both sides of the argument list are unexpected results

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    print(probe_mtu("192.168.1.1"))
          ~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/ofunctions/network/__init__.py", line 462, in probe_mtu
    raise ValueError(
        "Unable to determine MTU via defined method: {}".format(exc)
    )
ValueError: Unable to determine MTU via defined method: Both sides of the argument list are unexpected results

It should be noted that the same error ("ValueError: Both sides of the argument list are unexpected results") happens if ping command is not installed. This is confusing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions