Skip to content

LLDP: add IEEE 802.1Q and 802.1AX org-specific TLVs - #4970

Open
ali-keys wants to merge 3 commits into
secdev:masterfrom
ali-keys:lldp-ieee8021-tlvs
Open

LLDP: add IEEE 802.1Q and 802.1AX org-specific TLVs#4970
ali-keys wants to merge 3 commits into
secdev:masterfrom
ali-keys:lldp-ieee8021-tlvs

Conversation

@ali-keys

Copy link
Copy Markdown
Contributor

Hi everyone,

This PR adds 15 new org-specific TLVs for IEEE 802.1Q:

  • Port VLAN ID (PVID)
  • Port and Protocol VLAN ID (PPVID)
  • VLAN Name
  • Protocol Identity
  • VID Usage Digest
  • Management VID
  • Link Aggregation (this TLV is from 802.1AX)
  • Congestion Notification
  • ETS Configuration
  • ETS Recommendation
  • PFC Configuration
  • Application Priority
  • EVB
  • CDCP
  • Application VLAN

First, I wanted to implement only the ones that I needed (VLAN stuff), but then decided to implement all of them.
The code has been written mostly by AI. I've reviewed and corrected every line of it.

@polydroi

Copy link
Copy Markdown

Thanks for the PR.

Could you please check if it is possible to add interoperability tests with existing tools or libraries, such as lldpd, to the unit tests.

@ali-keys

ali-keys commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the PR.

Could you please check if it is possible to add interoperability tests with existing tools or libraries, such as lldpd, to the unit tests.

Hi Nils,

by interoperability tests you mean: Making a real environment -> capturing everything -> writing tests based on the pcaps to make sure it gets parsed correctly? Like the last test (Wireshark sample: Summit300-48*)?

* https://github.com/secdev/scapy/pull/4970/changes#diff-cd75a14a55c0b70a338abe750de68641d9a5c2c43acee32f99291161bb66100eR1689-R1742

@polydroi

Copy link
Copy Markdown

No, those tests are also important, but if possible I have something like this in mind.

Start lldpd with a certain configuration in a subprocess,
Start your test code that interacts with lldpd. Evaluate the test.
Stop the subprocess.

In this way we can automatically verify the interaction with a real world application/libray.

@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.74011% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.67%. Comparing base (b3bbcc8) to head (8db6c2e).

Files with missing lines Patch % Lines
scapy/autorun.py 88.23% 2 Missing ⚠️
scapy/contrib/lldp.py 98.74% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4970      +/-   ##
==========================================
+ Coverage   80.63%   80.67%   +0.03%     
==========================================
  Files         390      390              
  Lines       96936    97089     +153     
==========================================
+ Hits        78168    78324     +156     
+ Misses      18768    18765       -3     
Files with missing lines Coverage Δ
scapy/main.py 68.54% <100.00%> (+0.07%) ⬆️
scapy/autorun.py 84.32% <88.23%> (+0.50%) ⬆️
scapy/contrib/lldp.py 96.21% <98.74%> (+1.58%) ⬆️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gpotter2

gpotter2 commented May 9, 2026

Copy link
Copy Markdown
Member

LGTM, but the doc tests fail with

/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_AppPriority_Entry:9: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_AppVLANEntry:9: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Application_Priority:14: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Application_Priority:17: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Application_VLAN:12: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Application_VLAN:15: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_CDCP:12: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_CDCP:15: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_CDCP:17: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_CDCP:18: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_ETS_Configuration:13: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_ETS_Configuration:14: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_EVB:11: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_EVB:15: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_PFC_Configuration:13: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_PFC_Configuration:14: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Port_And_Protocol_VLAN_ID:13: ERROR: Unexpected indentation. [docutils]
/home/runner/work/scapy/scapy/scapy/contrib/lldp.py:docstring of scapy.contrib.lldp.LLDPDUOrgSpecific_IEEE8021_Port_And_Protocol_VLAN_ID:14: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils]

@ali-keys

Copy link
Copy Markdown
Contributor Author

@gpotter2 I fixed the docstrings.

@polydroi I have had some progress with interoperability tests (not pushed), but not all of the TLVs are implemented in lldpd/lldpad.

@polybassa

Copy link
Copy Markdown
Contributor

Regarding the interoperability tests, it doesn't matter if not all IDs are supported. At least we get an overall good coverage on AI generated code.

@ali-keys
ali-keys force-pushed the lldp-ieee8021-tlvs branch from 8e2d6e7 to bc7e272 Compare July 31, 2026 09:50
@ali-keys

ali-keys commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@polybassa I added interoperability tests for LLDP (via lldp and lldpad).

While writing the tests I also found a bug in autorun.py that makes tests hang forever.
The bug has two parts:

  • CPython gh-130250 (affected versions: 3.12.0-3.12.9 and 3.13.0-3.13.2)
  • q.put() having no exception handling

I also made the regression tests to not fail when IPython is missing. (the change in main.py)

PoC for the hang - tested with Python 3.12.3 (affected) and 3.14.6 (not affected):

"""
PoC: UTScapy (scapy.autorun) hangs forever when a test raises, on affected
"""

import sys


def check_python():
    v = sys.version_info
    affected = (v[:2] == (3, 12) and v[2] < 10) or (v[:2] == (3, 13) and v[2] < 3)
    print(f"Python {sys.version.split()[0]} -- affected by gh-130250: {affected}")
    return affected


def demo_cpython_bug():
    """Reproduce CPython gh-130250 standalone (no scapy)."""
    import io
    import traceback

    try:
        raise RuntimeError("boom")
    except RuntimeError:
        sys.last_exc = sys.exc_info()[1]
        sys.last_type = type(sys.last_exc)
        sys.last_value = sys.last_exc
        sys.last_traceback = sys.last_exc.__traceback__
        buf = io.StringIO()
        try:
            traceback.print_last(file=buf)
            print("no error -- Python is fixed")
        except AttributeError as e:
            print(f"reproduced gh-130250: {e!r}")


def demo_scapy_hang():
    """Trigger the full UTScapy hang path."""
    from scapy.autorun import autorun_get_interactive_session
    cmds = "assert False, 'boom'\n"
    print("calling autorun_get_interactive_session -- hangs on affected Python")
    out, res = autorun_get_interactive_session(cmds, timeout=5)
    print("returned:", repr(res))


if __name__ == "__main__":
    check_python()
    demo_cpython_bug()
    demo_scapy_hang()

@ali-keys
ali-keys force-pushed the lldp-ieee8021-tlvs branch from bc7e272 to 5e824af Compare July 31, 2026 10:06
@ali-keys

Copy link
Copy Markdown
Contributor Author

@polybassa, @gpotter2 anything to update here?

@gpotter2

Copy link
Copy Markdown
Member

Hi @ali-keys, could you fix the conflicts by rebasing ? Tests also don't pass. Thanks !

…rg-specific dispatch

AI-Assisted: yes (Claude Sonnet 4.6)
@ali-keys
ali-keys force-pushed the lldp-ieee8021-tlvs branch 2 times, most recently from 43b065b to 563d7e6 Compare September 2, 2026 08:20
+ Emulate interact test to work without IPython installed

AI-Assisted: yes (Claude Opus 4.7)
@ali-keys
ali-keys force-pushed the lldp-ieee8021-tlvs branch 2 times, most recently from 9772494 to f30a2db Compare September 2, 2026 09:31
@ali-keys

ali-keys commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@gpotter2 done!
Ready for 2.8.0 release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants