saltstack / saltstack/salt

[BUG] `network.routes` execution module tracebacks on blackhole route

Open
#60,126 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Execution-Module severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description

The network.routes execution module does not handle blackhole routes when netstat is not installed.
If netstat is not installed, then the module uses ip, which does not display backhole route the same way, and ends up with a traceback:

# salt-call network.routes
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
ValueError: 'blackhole' does not appear to be an IPv4 or IPv6 network
Traceback (most recent call last):
  File "/bin/salt-call", line 11, in <module>
    load_entry_point('salt==3002.6', 'console_scripts', 'salt-call')()
  File "/usr/lib/python3.6/site-packages/salt/scripts.py", line 449, in salt_call
    client.run()
  File "/usr/lib/python3.6/site-packages/salt/cli/call.py", line 58, in run
    caller.run()
  File "/usr/lib/python3.6/site-packages/salt/cli/caller.py", line 112, in run
    ret = self.call()
  File "/usr/lib/python3.6/site-packages/salt/cli/caller.py", line 220, in call
    self.opts, data, func, args, kwargs
  File "/usr/lib/python3.6/site-packages/salt/executors/direct_call.py", line 12, in execute
    return func(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/salt/modules/network.py", line 1769, in routes
    routes_ = _ip_route_linux()
  File "/usr/lib/python3.6/site-packages/salt/modules/network.py", line 554, in _ip_route_linux
    address_mask = convert_cidr(comps[0])
  File "/usr/lib/python3.6/site-packages/salt/modules/network.py", line 1237, in convert_cidr
    cidr = calc_net(cidr)
  File "/usr/lib/python3.6/site-packages/salt/modules/network.py", line 1260, in calc_net
    return __utils__["network.calc_net"](ip_addr, netmask)
  File "/usr/lib/python3.6/site-packages/salt/utils/network.py", line 1109, in calc_net
    return str(ipaddress.ip_network(ipaddr, strict=False))
  File "/usr/lib64/python3.6/ipaddress.py", line 84, in ip_network
    address)

Setup

  • No netstat binary present
  • A blackhole route set
$ ip r
[...]
blackhole 10.233.162.0/26 proto bird
[...]

Steps to Reproduce the behavior
Ensure that net-tools package is not present, then setup a backhole route and run the following command:

salt-call network.routes

Expected behavior
The module returns a list of all routes on the host.

Versions Report

$ salt-call --versions-report
Salt Version:
          Salt: 3002.6

Dependency Versions:
          cffi: 1.9.1
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.1
       libgit2: Not Installed
      M2Crypto: 0.35.2
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.14
      pycrypto: Not Installed
  pycryptodome: Not Installed
        pygit2: Not Installed
        Python: 3.6.8 (default, Nov 16 2020, 16:55:22)
  python-gnupg: Not Installed
        PyYAML: 3.13
         PyZMQ: 17.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.1.4

System Versions:
          dist: centos 7 Core
        locale: UTF-8
       machine: x86_64
       release: 3.10.0-1127.el7.x86_64
        system: Linux
       version: CentOS Linux 7 Core

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in salt/modules/network.py at _ip_route_linux(), where the traceback reaches convert_cidr(), and reproduce with salt-call network.routes without net-tools installed. Trace how the blackhole line from ip r is parsed. Done means the command returns all host routes, including blackhole routes, without a traceback.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.