Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not fail on linux < 4.12 #4424

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

christian-sahlmann
Copy link
Contributor

I was getting this error after #4352 was merged:

  File "/usr/lib/python3.11/site-packages/scapy/layers/snmp.py", line 20, in <module>
    from scapy.layers.inet import UDP, IP, ICMP
  File "/usr/lib/python3.11/site-packages/scapy/layers/inet.py", line 20, in <module>
    from scapy.ansmachine import AnsweringMachine
  File "/usr/lib/python3.11/site-packages/scapy/ansmachine.py", line 20, in <module>
    from scapy.arch import get_if_addr
  File "/usr/lib/python3.11/site-packages/scapy/arch/__init__.py", line 189, in <module>
    _set_conf_sockets()  # Apply config
    ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/config.py", line 826, in _set_conf_sockets
    conf.ifaces.reload()
  File "/usr/lib/python3.11/site-packages/scapy/interfaces.py", line 253, in reload
    self._reload_provs()
  File "/usr/lib/python3.11/site-packages/scapy/interfaces.py", line 249, in _reload_provs
    self._load(prov.reload(), prov)
               ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/interfaces.py", line 51, in reload
    return self.load()
           ^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/arch/linux/__init__.py", line 173, in load
    for iface in _get_if_list().values():
                 ^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/arch/linux/rtnetlink.py", line 790, in _get_if_list
    results = _sr1_rtrequest(
              ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/arch/linux/rtnetlink.py", line 718, in _sr1_rtrequest
    sock.setsockopt(SOL_NETLINK, NETLINK_EXT_ACK, 1)
OSError: [Errno 92] Protocol not available

Copy link

codecov bot commented Jun 14, 2024

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 80.39%. Comparing base (6b26ace) to head (ea01a92).
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4424      +/-   ##
==========================================
- Coverage   82.21%   80.39%   -1.82%     
==========================================
  Files         352      353       +1     
  Lines       84032    87515    +3483     
==========================================
+ Hits        69083    70359    +1276     
- Misses      14949    17156    +2207     
Files Coverage Δ
scapy/arch/linux/rtnetlink.py 93.39% <40.00%> (-1.32%) ⬇️

... and 36 files with indirect coverage changes

@gpotter2
Copy link
Member

gpotter2 commented Jun 14, 2024

Could you share details about your setup? What OS / version are affected?

@christian-sahlmann
Copy link
Contributor Author

My problem is that I'm stuck (at least for now) with a pretty old linux kernel (3.10.0-1160.45.1.el7.x86_64). So far, scapy worked perfectly fine there for my purposes (and does again with this fix).

@christian-sahlmann
Copy link
Contributor Author

I did a little bit more research and found out that the minimum version for this to work is Linux 4.12.

See torvalds/linux@2d4bc93

I was getting this error after secdev#4352 was merged on a linux system with a pretty old kernel (3.10.0-1160.45.1.el7.x86_64):
```
  File "/usr/lib/python3.11/site-packages/scapy/layers/snmp.py", line 20, in <module>
    from scapy.layers.inet import UDP, IP, ICMP
  File "/usr/lib/python3.11/site-packages/scapy/layers/inet.py", line 20, in <module>
    from scapy.ansmachine import AnsweringMachine
  File "/usr/lib/python3.11/site-packages/scapy/ansmachine.py", line 20, in <module>
    from scapy.arch import get_if_addr
  File "/usr/lib/python3.11/site-packages/scapy/arch/__init__.py", line 189, in <module>
    _set_conf_sockets()  # Apply config
    ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/config.py", line 826, in _set_conf_sockets
    conf.ifaces.reload()
  File "/usr/lib/python3.11/site-packages/scapy/interfaces.py", line 253, in reload
    self._reload_provs()
  File "/usr/lib/python3.11/site-packages/scapy/interfaces.py", line 249, in _reload_provs
    self._load(prov.reload(), prov)
               ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/interfaces.py", line 51, in reload
    return self.load()
           ^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/arch/linux/__init__.py", line 173, in load
    for iface in _get_if_list().values():
                 ^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/arch/linux/rtnetlink.py", line 790, in _get_if_list
    results = _sr1_rtrequest(
              ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/scapy/arch/linux/rtnetlink.py", line 718, in _sr1_rtrequest
    sock.setsockopt(SOL_NETLINK, NETLINK_EXT_ACK, 1)
OSError: [Errno 92] Protocol not available
```
@christian-sahlmann christian-sahlmann changed the title do not fail when rtnetlink is not available on older systems do not fail on linux < 4.12 Jun 17, 2024
@gpotter2
Copy link
Member

That's interesting thanks. What if you just try: except: pass this request, does it work on your linux version?
From what I understand Scapy shouldn't need extended ack reporting to work.

@gpotter2 gpotter2 closed this Jun 22, 2024
@gpotter2 gpotter2 reopened this Jun 22, 2024
@christian-sahlmann
Copy link
Contributor Author

Yes, I've tried that as well, but then I get an exception at sock.setsockopt(SOL_NETLINK, NETLINK_GET_STRICT_CHK, 1), which apparently is available only since Linux 4.20 (torvalds/linux@89d3552).

@gpotter2
Copy link
Member

Alright, thanks for the pointers.

I'll pop a VM with a Linux 3.0 kernel and investigate to see what we can do, and get back to you.

I can't really merge this PR because it's just a workaround. Scapy should have a way of reading routes on old linux kernels, as it used to. If it happens that RTNETLINK really isn't supported, we'll add a fallback to some other method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants