Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical issues remain: missing ESP overhead causes silent packet drops and stalled TCP traffic, while reusing a static SAK after reset repeats AES-GCM nonces and resets replay protection.
2 open issues
What changed in this PR
Integrates the software MACsec SecY into wolfIP’s Ethernet datapath, enabling interface-level protection with application-managed or MKA-provided keys.
Changes:
- Adds MACsec attachment, statistics, frame protection and validation, and MTU handling.
- Caches AES-GCM contexts and decouples SecY/SA layers from the supplicant.
- Adds unit tests, Linux interoperability testing, CI integration, and documentation.
| File | Description |
|---|---|
| wolfip.h | Declares MACsec interface APIs and statistics. |
| tools/macsec/run_macsec_link_test.sh | Adds kernel interoperability checks. |
| tools/macsec/macsec_sta.c | Frees channel crypto contexts. |
| src/wolfip.c | Integrates MACsec into Ethernet traffic handling. |
| src/wolfesp.c | Routes ESP output through MACsec protection. |
| src/test/unit/unit.c | Registers packet-socket MTU test. |
| src/test/unit/unit_tests_socket_api_arms.c | Tests oversized packet-socket sends. |
| src/test/unit/unit_macsec.c | Adds MACsec datapath unit coverage. |
| src/test/test_macsec_link.c | Adds TAP-based protected echo server. |
| src/macsec/test_macsec_sa.c | Tests rekeying and crypto-device dispatch. |
| src/macsec/test_macsec_mka.c | Releases test channel resources. |
| src/macsec/mka_wolfmka.h | Clarifies channel lifecycle documentation. |
| src/macsec/mka_wolfmka.c | Updates status after key-install failure. |
| src/macsec/macsec_secy.h | Declares cached AES transform APIs. |
| src/macsec/macsec_secy.c | Reuses AES contexts and removes supplicant dependencies. |
| src/macsec/macsec_sa.h | Adds cached contexts and device configuration. |
| src/macsec/macsec_sa.c | Manages cached per-SA crypto resources. |
| src/macsec/fuzz_macsec_secy.c | Frees receive-channel resources. |
| README.md | Links the MACsec guide. |
| Makefile | Adds datapath and test build targets. |
| docs/macsec_howto.md | Documents setup, key rotation, and interoperability. |
| docs/API.md | Lists MACsec support and guide. |
| .github/workflows/supplicant.yml | Runs kernel datapath interoperability testing. |
| .github/workflows/linux.yml | Builds and runs MACsec unit tests. |
Review effort: Balanced
|
macsec_protect() and macsec_validate() rebuilt the AES key schedule and
GHASH table for every frame. Each SA now owns an Aes context scheduled
once in set_key and freed in delete_sa or sc_free.
- Add macsec_{tx,rx}_sc_set_devid() to run an SA on a crypto callback
device
- Re-initialising a keyed channel leaks; reset it with sc_free
macsec_secy.c and macsec_sa.c pulled in the WPA supplicant only for wpa_secure_zero(). They now use macsec_force_zero(), since older wolfSSL lacks wc_ForceZero(), and need just AES-GCM. -DWOLFIP_ENABLE_MACSEC=1 moves from the global CFLAGS into MACSEC_CFLAGS, so build/wolfip.o stays MACsec-free, and the MACsec dependency files are now included.
TCP MSS, UDP sendto and ICMP datagram sockets sized packets to the full IP MTU, so with an outbound ESP SA a full-size packet grew past the link MTU once wrapped. Size them to the largest packet that still fits after the matching SA adds its header, padding and ICV.
6931d27 to
1849dcb
Compare
There was a problem hiding this comment.
🟡 Changes recommended
A critical issue lets the first SA installation on an MKA-managed channel enable transmission before the enable callback and peer readiness; activation handling must be corrected and covered by an attached-port regression test.
1 open issue
2 resolved since last review
Review effort: Balanced
wolfIP_macsec_attach() binds caller-owned transmit and receive Secure Channels to an Ethernet interface. Every sent frame, including VLAN and ESP output, is protected; received 0x88E5 frames are validated and demultiplexed as plain. EAPOL bypasses protection. The frame MTU drops by 32 bytes so protected frames stay at 1514. unit-macsec covers each branch.
test-macsec-link runs wolfIP with a static-key SecY on a TAP device against a kernel macsec0, and run_macsec_link_test.sh requires ping, full-size ping and a TCP echo to pass. The supplicant workflow runs it when the macsec module is available. docs/macsec_howto.md covers setup, key rotation and counters.
1849dcb to
1f23567
Compare
|
@claude review |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #207
Scan targets checked: wolfip-src, wolfip-bugs
Not reviewed (no scan target covers them): .github/workflows/linux.yml, .github/workflows/supplicant.yml, Makefile, README.md, docs/API.md, docs/ipsec_esp_howto.md, docs/macsec_howto.md, src/test/test_macsec_link.c, src/test/unit/unit.c, src/test/unit/unit_esp.c, src/test/unit/unit_macsec.c, src/test/unit/unit_tests_socket_api_arms.c, tools/macsec/run_macsec_link_test.sh, wolfip.h
Coverage: 11 of 11 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Max
dgarske
left a comment
There was a problem hiding this comment.
Tested the PR head and a local merge onto master with wolfSSL v5.9.1 (CI config): unit, unit-esp, unit-macsec, the ASan/UBSan variants, the MACsec supplicant tests and run_macsec_link_test.sh against a kernel macsec0 all pass. Non-MACsec builds are unchanged in size (+8 B on Cortex-M33).
Main concern is RAM on embedded targets. Caching an Aes per SA takes a channel from 120 B to 2.3 KB (GCM_TABLE_4BIT) or 9.5 KB (GCM_TABLE). Please either add a build option to keep the per-frame key schedule, or document the GCM table choice in docs/macsec_howto.md. The other notes are inline.
| mtu = wolfIP_ll_link_mtu(ll); | ||
| #if WOLFIP_ENABLE_MACSEC | ||
| if (ll && ll->macsec) { | ||
| if (mtu > ETH_HEADER_LEN + IP_MTU_MAX) |
There was a problem hiding this comment.
If frames are already queued at attach, a 1514 B frame now fails len > frame_mtu in wolfIP_ll_xmit with -WOLFIP_EINVAL, and the UDP/TCP drain loops break without popping it, so the socket wedges. Please drop and pop oversize frames rather than retrying them forever. The same applies to a wolfIP_mtu_set shrink.
| /* One transmit Secure Association: a SAK under one Association Number, with | ||
| * its own packet-number counter. */ | ||
| struct macsec_tx_sa { | ||
| Aes aes; /* SAK scheduled for GCM */ |
There was a problem hiding this comment.
With the schedule cached, sak[] and sak_len are no longer read by the library (only macsec_sta.c uses them). Please remove them so we don't keep a second plaintext copy of the SAK. Saves 40 B per SA.
| #if WOLFIP_ENABLE_MACSEC | ||
| struct wolfIP_macsec_port macsec[WOLFIP_MAX_INTERFACES]; | ||
| uint8_t macsec_tx_buf[LINK_MTU]; | ||
| uint8_t macsec_rx_buf[LINK_MTU]; |
There was a problem hiding this comment.
Consider decrypting in place in the rx buffer and moving the MAC pair forward over the SecTAG. That drops the 1514 B macsec_rx_buf from struct wolfIP.
| const struct wolfIP_wifi_ops *wifi_ops; | ||
| #if WOLFIP_ENABLE_MACSEC | ||
| /* Set while a MACsec SecY is attached; see wolfIP_macsec_attach(). */ | ||
| struct wolfIP_macsec_port *macsec; |
There was a problem hiding this comment.
Consider making macsec unconditional like wifi_ops, so the ll_dev layout doesn't depend on a build flag.
|
|
||
| if (!ll || !ll->send || !tx || !rx || rx_count == 0 || ll->non_ethernet | ||
| || wolfIP_is_loopback_if(if_idx) | ||
| || (flags & ~WOLFIP_MACSEC_ACCEPT_UNPROTECTED) != 0) |
There was a problem hiding this comment.
Use 0x01UL (or cast to uint32_t) so ~ covers 32 bits on 16-bit int targets.
|
|
||
| if (len < ETH_HEADER_LEN) | ||
| return -WOLFIP_EINVAL; | ||
| if (((struct wolfIP_eth_frame *)buf)->type == ee16(0x888E)) { |
There was a problem hiding this comment.
Please add an ETH_TYPE_EAPOL define. 0x888E is now bare in three places.
| struct wolfIP_macsec_stats stats; | ||
| struct macsec_tx_sc *tx; | ||
| struct macsec_rx_sc *rx; | ||
| uint8_t *tx_buf; |
There was a problem hiding this comment.
tx_buf is always s->macsec_tx_buf. Drop the field.
| #endif | ||
|
|
||
| /* wc_ForceZero() is missing from older wolfSSL releases such as 5.6.6. */ | ||
| void macsec_force_zero(void *mem, size_t len) |
There was a problem hiding this comment.
Consider sharing one force-zero helper with wolfesp.c.

Wires the software MACsec SecY in src/macsec/ into the wolfIP datapath, so a static-key or MKA-driven SecY can protect every Ethernet frame on an interface. The SecY and SA layers now build without the WPA supplicant.
Changes
mka_wolfmka_free()now frees its channelsmacsec_{tx,rx}_sc_set_devid()to run an SA on a wolfCrypt crypto callback deviceWOLFIP_ENABLE_MACSECmoves intoMACSEC_CFLAGSwolfIP_macsec_attach(),_detach()and_get_stats(): TX protects plain, VLAN and ESP output; RX validates 0x88E5 frames and demuxes them as plain; EAPOL bypasses bothTesting
unit-macsecsuite covering each TX and RX branch, run in the Linux workflowrun_macsec_link_test.sh: wolfIP on TAP against kernel macsec0 (ping, full-size ping, TCP echo), run in the supplicant workflowLimitations
MACSEC_RX_CRYPTO_ERRkey-schedule failure path; it needs a crypto device that rejects keys