Skip to content

Commit

Permalink
Allow to disable auto-loading of routes
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Feb 3, 2024
1 parent b2f3587 commit 1556289
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
33 changes: 33 additions & 0 deletions doc/scapy/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,39 @@ There are quite a few ways of speeding up scapy's dissection. You can use all of
# Disable filtering: restore everything to normal
conf.layers.unfilter()
Very slow start because of big routes
-------------------------------------

Problem
^^^^^^^

Scapy takes ages to start because you have very big routing tables.

Solution
^^^^^^^^

Disable the auto-loading of the routing tables:

**CLI:** in ``~/.config/scapy/prestart.py`` add:

.. code:: python
conf.route_autoload = False
conf.route6_autoload = False
**Programmatically:**

.. code:: python
# Before any other Scapy import
from scapy.config import conf
conf.route_autoload = False
conf.route6_autoload = False
# Import Scapy here
from scapy.all import *
At anytime, you can trigger the routes loading using ``conf.route.resync()`` or ``conf.route6.resync()``, or add the routes yourself `as shown here <#routing>`_.


OS Fingerprinting
-----------------
Expand Down
6 changes: 6 additions & 0 deletions scapy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,12 @@ class Conf(ConfClass):
neighbor = None # type: 'scapy.layers.l2.Neighbor'
#: holds the name servers IP/hosts used for custom DNS resolution
nameservers = None # type: str
#: automatically load IPv4 routes on startup. Disable this if your
#: routing table is too big.
route_autoload = True
#: automatically load IPv6 routes on startup. Disable this if your
#: routing table is too big.
route6_autoload = True
#: holds the Scapy IPv4 routing table and provides methods to
#: manipulate it
route = None # type: 'scapy.route.Route'
Expand Down
4 changes: 3 additions & 1 deletion scapy/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class Route:
def __init__(self):
# type: () -> None
self.routes = [] # type: List[Tuple[int, int, str, str, str, int]]
self.resync()
self.invalidate_cache()
if conf.route_autoload:
self.resync()

def invalidate_cache(self):
# type: () -> None
Expand Down
9 changes: 6 additions & 3 deletions scapy/route6.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class Route6:

def __init__(self):
# type: () -> None
self.resync()
self.routes = [] # type: List[Tuple[str, int, str, str, List[str], int]] # noqa: E501
self.ipv6_ifaces = set() # type: Set[Union[str, NetworkInterface]]
self.invalidate_cache()
if conf.route6_autoload:
self.resync()

def invalidate_cache(self):
# type: () -> None
Expand All @@ -50,8 +53,8 @@ def invalidate_cache(self):
def flush(self):
# type: () -> None
self.invalidate_cache()
self.ipv6_ifaces = set() # type: Set[Union[str, NetworkInterface]]
self.routes = [] # type: List[Tuple[str, int, str, str, List[str], int]] # noqa: E501
self.routes.clear()
self.ipv6_ifaces.clear()

def resync(self):
# type: () -> None
Expand Down

0 comments on commit 1556289

Please sign in to comment.