FPGA Firewall Project
Verilog/SystemVerilog FPGA firewall on DE1-SoC + W5500 MACRAW. Parses IPv4/TCP/UDP, applies 4-rule engine, inline two-W5500 forwarding verified with SHA-256 fil
[English Version]
FPGA Firewall Project — Hardware Packet Filtering on DE1-SoC + W5500
#FPGA #W5500 #Verilog #SystemVerilog #Firewall #PacketFiltering #DE1-SoC #MACRAW #NetworkSecurity
📚 This is a university course project (ELE432). The implementation is real and hardware-verified.
01 — What is this project?
Software firewalls — iptables, Windows Defender, pfSense — run on CPUs. Every packet goes through the operating system, gets inspected by software, and a decision is made. This works, but it is fundamentally limited by CPU throughput.
Hardware firewalls inspect packets in silicon — in logic gates that operate in parallel at clock speed. A packet enters, header fields are parsed, rules are evaluated, and an allow/drop decision is made — all within a few clock cycles, at wire speed.
This project builds exactly that: a hardware packet filter firewall implemented in Verilog/SystemVerilog on a Terasic DE1-SoC FPGA, using W5500 as the Ethernet interface. Packets arrive from W5500 in MACRAW mode, the FPGA parses their IPv4/TCP/UDP headers, a 4-rule engine decides allow or drop, and verified packets are forwarded out through a second W5500.
The final demo: PC1 sends a chunked file over UDP port 5001 (allowed) interleaved with decoy traffic on TCP port 23 (blocked). PC2 receives only the allowed chunks and verifies the reconstructed file with SHA-256.
02 — Why FPGA for a firewall?
🔷 Wire-speed packet inspection
A CPU-based firewall introduces latency and has a maximum throughput limited by the CPU's ability to process interrupts and run the firewall software. An FPGA firewall processes packets in hardware — the parser, rule engine, and decision logic are all parallel circuits that operate every clock cycle.
🔷 Deterministic latency
Software firewalls have variable latency — the OS scheduler, interrupt coalescing, and CPU load all affect how quickly a packet is processed. An FPGA firewall has fixed, deterministic latency: the same number of clock cycles for every packet, regardless of network load.
🔷 Reconfigurable hardware
Unlike an ASIC (Application-Specific Integrated Circuit), an FPGA can be reprogrammed. New firewall rules, new protocol parsers, or new forwarding logic can be deployed by uploading a new bitstream — no new silicon required.
03 — System architecture
[PC1 sender]
UDP port 5001 (allow) + TCP port 23 (drop) interleaved
↓ Ethernet cable
[W5500 A — ingress]
MACRAW mode → raw Ethernet frames → FPGA
↓ SPI (GPIO_0)
[DE1-SoC FPGA]
├─ SPI master → W5500 register access + MACRAW RX
├─ eth_controller_adapter → frame_rx_fifo
├─ Parser: Ethernet II + IPv4 + TCP/UDP header extraction
├─ Rule engine: 4 rules, first-match priority
│ Rule 1: UDP dst port 5001 → ALLOW
│ Rule 2: TCP dst port 22 (SSH) → ALLOW
│ Rule 3: TCP dst port 23 → DROP
│ Rule 4: default → DROP
├─ Counters: RX / allow / drop (HEX display + LEDs)
└─ W5500 B TX path (staged, GPIO_1)
↓ SPI (GPIO_1)
[W5500 B — egress]
↓ Ethernet cable
[PC2 receiver]
Reconstructs file, verifies SHA-25604 — Why W5500?
🔷 MACRAW mode — the only viable interface for a packet filter
A firewall must see raw Ethernet frames — not just TCP/UDP payloads. W5500's MACRAW mode delivers complete Ethernet frames to the FPGA without any TCP/IP processing. The FPGA sees every byte of every frame: Ethernet header, IP header, transport header, and payload.
W5500's hardware socket mode (TOE) would abstract away exactly the header information the firewall needs to inspect. MACRAW is mandatory for this application.
🔷 SPI interface — clean integration with FPGA GPIO
The FPGA has no built-in Ethernet PHY. W5500 connects over SPI — a simple 4-wire interface that maps cleanly to FPGA GPIO pins. The project implements a custom SPI master in Verilog that handles W5500 register access, MACRAW initialization, and RX polling.
Hardware evidence from the README:
- W5500 responds to
VERSIONRregister read after reset ✅ - Adapter reaches RX polling with
init_doneactive ✅ - Wireshark confirmed deterministic Scapy packets received ✅
- Board LEDs show RX/allow/drop counter activity ✅
🔷 Two W5500 modules — inline forwarding
The final architecture uses two W5500 modules:
- W5500 A on
GPIO_0: ingress — receives packets from PC1 - W5500 B on
GPIO_1[0..5]: egress — forwards allowed packets to PC2
Packets flow: PC1 → W5500 A → FPGA rules → W5500 B → PC2. Dropped packets never reach PC2.
05 — Key components
🧠 DE1-SoC FPGA (Intel Cyclone V)
Terasic DE1-SoC development board. Intel Cyclone V SoC FPGA (5CSEMA5F31C6). The firewall logic is implemented entirely in the FPGA fabric — no HPS (ARM) involvement. Compiled with Quartus Prime Lite 25.1.
🌐 WIZnet W5500 (×2) — MACRAW Ethernet
Two W5500 modules. W5500 A receives raw frames from PC1. W5500 B transmits allowed frames to PC2. Both operate in MACRAW mode. FPGA implements a custom SPI master for W5500 register access and frame transfer.
📦 Parser (Verilog)
Extracts Ethernet II + IPv4 + TCP/UDP header fields without IPv4 options support. Outputs: src/dst IP, src/dst port, protocol. Drives the rule engine.
⚖️ Rule engine (Verilog, 4 rules, first-match)
Parameterized. Four rules evaluated in priority order. Default-drop policy. Outputs: allow/drop decision + matched rule index.
📬 frame_rx_fifo
RX-side FIFO between the W5500 adapter and firewall core. Absorbs backpressure when the firewall core is processing a previous frame.
🧪 Testbench suite (SystemVerilog)
9 testbenches covering every module: fake_eth_source_tb, parser_tb, rule_engine_tb, packet_buffer_tb, frame_rx_fifo_tb, firewall_core_tb, spi_master_tb, eth_controller_adapter_tb, adapter_firewall_integration_tb. All pass in XSim regression.
06 — Application scenarios
01. Hardware network security research
A working open-source FPGA firewall reference design. Parser, rule engine, and MACRAW adapter are cleanly separated modules that can be extended — add IPv6 support, stateful inspection, or additional rules without changing the core architecture. #NetworkSecurity #FPGA #OpenSource
02. Industrial edge firewall
In industrial networks where deterministic latency and wire-speed packet filtering are required, an FPGA-based firewall provides guarantees that software solutions cannot. W5500 MACRAW provides the raw frame access needed for deep packet inspection at the hardware layer. #Industrial #EdgeComputing #WireSpeed
03. Embedded security gateway
Two-W5500 inline forwarding on a small FPGA board creates a compact, low-power security gateway. No CPU, no OS, no software stack — pure hardware packet filtering between two Ethernet segments. #SecurityGateway #Embedded #LowPower
04. University / education reference
A complete, well-documented FPGA networking project with architecture docs, interface specs, test plans, and a full testbench suite. Covers SPI master design, MACRAW protocol, packet parsing, and rule engines — the full hardware networking stack from physical layer to application filtering. #Education #FPGA #Networking
Conclusion
Hardware packet filtering at clock speed — W5500 MACRAW delivers raw frames, the FPGA decides allow or drop.
This project builds a complete FPGA firewall pipeline: W5500 A receives packets in MACRAW mode, the FPGA parses IPv4/TCP/UDP headers and evaluates a 4-rule engine, and W5500 B forwards allowed packets to PC2. The final demo reconstructs a chunked file on PC2 and verifies it with SHA-256 — blocked traffic never arrives.
Hardware bring-up is verified: W5500 SPI communication, MACRAW initialization, RX polling, and live packet reception with LED counter feedback are all confirmed on real hardware.
- ✅ W5500 MACRAW — raw Ethernet frame access for hardware packet inspection
- ✅ Verilog parser: Ethernet II + IPv4 + TCP/UDP header extraction
- ✅ 4-rule parameterized rule engine, first-match, default-drop
- ✅ frame_rx_fifo — backpressure handling between adapter and firewall core
- ✅ Custom SPI master for W5500 register access and MACRAW RX
- ✅ 9-testbench XSim regression suite — all passing
- ✅ Hardware verified: W5500 VERSIONR, MACRAW init, live RX, LED counters
- ✅ Two-W5500 inline forwarding — PC1→FPGA→PC2 with SHA-256 file verification
- ✅ Quartus Prime Lite 25.1, DE1-SoC (Intel Cyclone V)
Q&A
Q. What is MACRAW mode and why is it essential for a firewall? MACRAW mode makes W5500 pass complete raw Ethernet frames to the host without any TCP/IP processing. A firewall must inspect packet headers — source/destination IP, port numbers, protocol — to make allow/drop decisions. W5500's hardware socket mode only exposes TCP/UDP payloads, hiding the header fields the firewall needs. MACRAW is the only mode that gives the FPGA access to the full frame.
Q. What is a packet filter firewall? A firewall that inspects packet headers (IP addresses, port numbers, protocol) and applies rules to decide whether to allow or drop each packet. It does not inspect payload content (that is deep packet inspection, DPI). This project implements a stateless packet filter — each packet is evaluated independently without connection tracking.
Q. How does the two-W5500 inline forwarding work? W5500 A receives packets from PC1 in MACRAW mode and delivers raw frames to the FPGA. The FPGA parser and rule engine process each frame. Allowed frames are written to W5500 B's TX buffer and transmitted to PC2. Dropped frames are discarded — they never reach W5500 B. From PC2's perspective, only allowed traffic appears.
Q. What is the SHA-256 file verification demo? PC1 splits a file into numbered chunks, sends allowed chunks as UDP port 5001 packets, and interleaves blocked decoy traffic as TCP port 23. The FPGA drops TCP/23 packets. PC2 receives only UDP/5001 chunks, reassembles the file, and computes SHA-256. If the hash matches PC1's original, the firewall correctly passed all allowed traffic and dropped all blocked traffic.
Q. What does "first-match priority" mean in the rule engine? Rules are evaluated in order (Rule 1, Rule 2, Rule 3, Rule 4). The first rule that matches the packet's header fields wins. If no rule matches, the default policy applies — in this project, default-drop. This is the standard behavior of most production firewalls (iptables, pf, Windows Firewall).
[한글 버전]
FPGA 방화벽 프로젝트 — DE1-SoC + W5500으로 구현하는 하드웨어 패킷 필터
#FPGA #W5500 #Verilog #SystemVerilog #방화벽 #패킷필터링 #DE1-SoC #MACRAW #네트워크보안
📚 대학 수업(ELE432) 프로젝트입니다. 구현은 실제이며 하드웨어에서 검증되었습니다.
01 — 이 프로젝트는 무엇인가?
소프트웨어 방화벽 — iptables, Windows Defender, pfSense — 은 CPU에서 동작합니다. 모든 패킷이 운영체제를 통과하고, 소프트웨어가 검사하고, 결정이 내려집니다. 동작하지만 CPU 처리량에 의해 본질적으로 제한됩니다.
하드웨어 방화벽은 패킷을 실리콘에서 검사합니다 — 클럭 속도로 병렬 동작하는 로직 게이트에서. 패킷이 들어오면 헤더 필드가 파싱되고, 규칙이 평가되고, 허용/차단 결정이 내려집니다 — 모두 몇 클럭 사이클 안에, 와이어 속도로.
이 프로젝트가 정확히 그것을 만듭니다: Terasic DE1-SoC FPGA에 Verilog/SystemVerilog로 구현된 하드웨어 패킷 필터 방화벽, W5500이 이더넷 인터페이스를 담당합니다. 패킷이 MACRAW 모드로 W5500에서 도착하면, FPGA가 IPv4/TCP/UDP 헤더를 파싱하고, 4-규칙 엔진이 허용/차단을 결정하고, 검증된 패킷이 두 번째 W5500을 통해 전달됩니다.
최종 데모: PC1이 UDP 포트 5001(허용)로 청크 파일을 보내면서 TCP 포트 23(차단) 디코이 트래픽을 섞습니다. PC2는 허용된 청크만 수신하고 SHA-256으로 재구성된 파일을 검증합니다.
02 — 왜 방화벽에 FPGA인가?
🔷 와이어 속도 패킷 검사
CPU 기반 방화벽은 지연을 발생시키고 인터럽트 처리와 방화벽 소프트웨어 실행 능력에 제한됩니다. FPGA 방화벽은 패킷을 하드웨어에서 처리합니다 — 파서, 규칙 엔진, 결정 로직이 모두 매 클럭 사이클마다 동작하는 병렬 회로입니다.
🔷 결정론적 지연
소프트웨어 방화벽은 가변 지연을 가집니다 — OS 스케줄러, 인터럽트 병합, CPU 부하가 모두 처리 속도에 영향을 미칩니다. FPGA 방화벽은 고정되고 결정론적인 지연을 가집니다: 네트워크 부하에 관계없이 모든 패킷에 동일한 클럭 사이클 수.
🔷 재구성 가능한 하드웨어
ASIC과 달리 FPGA는 재프로그래밍이 가능합니다. 새로운 방화벽 규칙, 새로운 프로토콜 파서, 새로운 포워딩 로직을 새 비트스트림 업로드로 배포할 수 있습니다 — 새 실리콘 불필요.
03 — 시스템 구조
[PC1 송신측]
UDP 포트 5001(허용) + TCP 포트 23(차단) 혼합
↓ 이더넷 케이블
[W5500 A — 인그레스]
MACRAW 모드 → 원시 이더넷 프레임 → FPGA
↓ SPI (GPIO_0)
[DE1-SoC FPGA]
├─ SPI 마스터 → W5500 레지스터 접근 + MACRAW RX
├─ eth_controller_adapter → frame_rx_fifo
├─ 파서: Ethernet II + IPv4 + TCP/UDP 헤더 추출
├─ 규칙 엔진: 4개 규칙, 첫 번째 매칭 우선
│ 규칙 1: UDP dst 포트 5001 → 허용
│ 규칙 2: TCP dst 포트 22(SSH) → 허용
│ 규칙 3: TCP dst 포트 23 → 차단
│ 규칙 4: 기본 → 차단
├─ 카운터: RX/허용/차단 (HEX 표시 + LED)
└─ W5500 B TX 경로 (단계적, GPIO_1)
↓ SPI (GPIO_1)
[W5500 B — 이그레스]
↓ 이더넷 케이블
[PC2 수신측]
파일 재구성, SHA-256 검증04 — 왜 W5500인가?
🔷 MACRAW 모드 — 패킷 필터에 유일한 실용적 인터페이스
방화벽은 원시 이더넷 프레임을 봐야 합니다 — TCP/UDP 페이로드만이 아닌. W5500의 MACRAW 모드가 TCP/IP 처리 없이 완전한 이더넷 프레임을 FPGA에 전달합니다. FPGA는 모든 프레임의 모든 바이트를 봅니다: 이더넷 헤더, IP 헤더, 전송 계층 헤더, 페이로드.
W5500의 하드웨어 소켓 모드(TOE)는 방화벽이 검사해야 할 헤더 정보를 추상화합니다. MACRAW가 이 애플리케이션에 필수입니다.
🔷 SPI 인터페이스 — FPGA GPIO와 깔끔한 통합
FPGA에는 내장 이더넷 PHY가 없습니다. W5500이 SPI로 연결됩니다 — FPGA GPIO 핀에 깔끔하게 매핑되는 단순한 4선 인터페이스. 프로젝트는 W5500 레지스터 접근, MACRAW 초기화, RX 폴링을 처리하는 커스텀 SPI 마스터를 Verilog로 구현했습니다.
README의 하드웨어 증거:
- 리셋 후 W5500이
VERSIONR레지스터 읽기에 응답 ✅ - 어댑터가
init_done활성 상태로 RX 폴링 도달 ✅ - Wireshark가 결정론적 Scapy 패킷 수신 확인 ✅
- 보드 LED가 RX/허용/차단 카운터 활동 표시 ✅
🔷 두 개의 W5500 — 인라인 포워딩
최종 아키텍처는 두 개의 W5500을 사용합니다:
- W5500 A (GPIO_0): 인그레스 — PC1에서 패킷 수신
- W5500 B (GPIO_1[0..5]): 이그레스 — 허용된 패킷을 PC2로 전달
패킷 흐름: PC1 → W5500 A → FPGA 규칙 → W5500 B → PC2. 차단된 패킷은 PC2에 도달하지 않습니다.
05 — 핵심 구성 요소
🧠 DE1-SoC FPGA (Intel Cyclone V)
Terasic DE1-SoC 개발 보드. Intel Cyclone V SoC FPGA (5CSEMA5F31C6). 방화벽 로직이 전적으로 FPGA 패브릭에 구현됩니다 — HPS(ARM) 관여 없음. Quartus Prime Lite 25.1로 컴파일.
🌐 WIZnet W5500 (×2) — MACRAW 이더넷
두 개의 W5500 모듈. W5500 A가 PC1에서 원시 프레임을 수신합니다. W5500 B가 허용된 프레임을 PC2로 전송합니다. 둘 다 MACRAW 모드로 동작합니다.
📦 파서 (Verilog)
IPv4 옵션 없이 Ethernet II + IPv4 + TCP/UDP 헤더 필드를 추출합니다. 출력: 출발지/목적지 IP, 출발지/목적지 포트, 프로토콜. 규칙 엔진을 구동합니다.
⚖️ 규칙 엔진 (Verilog, 4개 규칙, 첫 번째 매칭)
파라미터화됨. 4개 규칙을 우선순위 순서로 평가합니다. 기본-차단 정책. 출력: 허용/차단 결정 + 매칭된 규칙 인덱스.
📬 frame_rx_fifo
W5500 어댑터와 방화벽 코어 사이의 RX 측 FIFO. 방화벽 코어가 이전 프레임을 처리하는 동안 역압을 흡수합니다.
🧪 테스트벤치 스위트 (SystemVerilog)
모든 모듈을 커버하는 9개 테스트벤치. XSim 리그레션에서 전부 통과.
06 — 응용 시나리오
01. 하드웨어 네트워크 보안 연구
동작하는 오픈소스 FPGA 방화벽 레퍼런스 설계. 파서, 규칙 엔진, MACRAW 어댑터가 깔끔하게 분리된 모듈로 확장 가능합니다 — IPv6 지원, 상태 기반 검사, 추가 규칙을 코어 아키텍처 변경 없이 추가할 수 있습니다. #네트워크보안 #FPGA #오픈소스
02. 산업 엣지 방화벽
결정론적 지연과 와이어 속도 패킷 필터링이 필요한 산업 네트워크에서 FPGA 기반 방화벽이 소프트웨어 솔루션이 제공할 수 없는 보증을 제공합니다. W5500 MACRAW가 하드웨어 레이어에서 딥 패킷 검사에 필요한 원시 프레임 접근을 제공합니다. #산업 #엣지컴퓨팅 #와이어속도
03. 임베디드 보안 게이트웨이
소형 FPGA 보드에서 두 W5500 인라인 포워딩이 소형 저전력 보안 게이트웨이를 만듭니다. CPU 없음, OS 없음, 소프트웨어 스택 없음 — 두 이더넷 세그먼트 사이의 순수 하드웨어 패킷 필터링. #보안게이트웨이 #임베디드 #저전력
04. 대학/교육 레퍼런스
아키텍처 문서, 인터페이스 명세, 테스트 계획, 완전한 테스트벤치 스위트를 갖춘 완전하고 잘 문서화된 FPGA 네트워킹 프로젝트. SPI 마스터 설계, MACRAW 프로토콜, 패킷 파싱, 규칙 엔진 — 물리 계층부터 애플리케이션 필터링까지 전체 하드웨어 네트워킹 스택을 다룹니다. #교육 #FPGA #네트워킹
결론
클럭 속도의 하드웨어 패킷 필터링 — W5500 MACRAW가 원시 프레임을 전달하고 FPGA가 허용/차단을 결정한다.
이 프로젝트는 완전한 FPGA 방화벽 파이프라인을 구축합니다: W5500 A가 MACRAW 모드로 패킷을 수신하고, FPGA가 IPv4/TCP/UDP 헤더를 파싱하고 4-규칙 엔진을 평가하고, W5500 B가 허용된 패킷을 PC2에 전달합니다. 최종 데모는 PC2에서 청크 파일을 재구성하고 SHA-256으로 검증합니다 — 차단된 트래픽은 절대 도달하지 않습니다.
하드웨어 브링업이 검증됨: W5500 SPI 통신, MACRAW 초기화, RX 폴링, LED 카운터 피드백이 있는 라이브 패킷 수신이 모두 실제 하드웨어에서 확인됩니다.
- ✅ W5500 MACRAW — 하드웨어 패킷 검사를 위한 원시 이더넷 프레임 접근
- ✅ Verilog 파서: Ethernet II + IPv4 + TCP/UDP 헤더 추출
- ✅ 파라미터화된 4-규칙 엔진, 첫 번째 매칭, 기본-차단
- ✅ frame_rx_fifo — 어댑터와 방화벽 코어 사이 역압 처리
- ✅ W5500 레지스터 접근과 MACRAW RX를 위한 커스텀 SPI 마스터
- ✅ 9개 테스트벤치 XSim 리그레션 스위트 — 전부 통과
- ✅ 하드웨어 검증: W5500 VERSIONR, MACRAW 초기화, 라이브 RX, LED 카운터
- ✅ 두 W5500 인라인 포워딩 — PC1→FPGA→PC2, SHA-256 파일 검증
- ✅ Quartus Prime Lite 25.1, DE1-SoC (Intel Cyclone V)
Q&A
Q. MACRAW 모드란 무엇이고 왜 방화벽에 필수인가요? MACRAW 모드는 W5500이 TCP/IP 처리 없이 완전한 원시 이더넷 프레임을 호스트에 전달하게 합니다. 방화벽은 허용/차단 결정을 내리기 위해 패킷 헤더 — 출발지/목적지 IP, 포트 번호, 프로토콜 — 를 검사해야 합니다. W5500의 하드웨어 소켓 모드는 TCP/UDP 페이로드만 노출해 방화벽이 필요한 헤더 필드를 숨깁니다. MACRAW가 FPGA에 전체 프레임 접근을 제공하는 유일한 모드입니다.
Q. 패킷 필터 방화벽이란 무엇인가요? 패킷 헤더(IP 주소, 포트 번호, 프로토콜)를 검사하고 각 패킷을 허용하거나 차단하는 규칙을 적용하는 방화벽입니다. 페이로드 내용은 검사하지 않습니다(그건 딥 패킷 검사, DPI입니다). 이 프로젝트는 무상태 패킷 필터를 구현합니다 — 각 패킷이 연결 추적 없이 독립적으로 평가됩니다.
Q. 두 W5500 인라인 포워딩은 어떻게 동작하나요? W5500 A가 MACRAW 모드로 PC1에서 패킷을 수신하고 FPGA에 원시 프레임을 전달합니다. FPGA 파서와 규칙 엔진이 각 프레임을 처리합니다. 허용된 프레임은 W5500 B의 TX 버퍼에 기록되어 PC2로 전송됩니다. 차단된 프레임은 폐기됩니다 — W5500 B에 절대 도달하지 않습니다.
Q. SHA-256 파일 검증 데모란 무엇인가요? PC1이 파일을 번호가 매겨진 청크로 나누고, 허용된 청크를 UDP 포트 5001 패킷으로 보내고, 차단된 디코이 트래픽을 TCP 포트 23으로 섞습니다. FPGA가 TCP/23 패킷을 차단합니다. PC2는 UDP/5001 청크만 수신하고, 파일을 재조립하고, SHA-256을 계산합니다. 해시가 PC1의 원본과 일치하면 방화벽이 모든 허용 트래픽을 올바르게 통과시키고 모든 차단 트래픽을 드롭한 것입니다.
Q. 규칙 엔진에서 "첫 번째 매칭 우선"이란 무엇인가요? 규칙이 순서대로 평가됩니다(규칙 1, 2, 3, 4). 패킷 헤더 필드와 매칭되는 첫 번째 규칙이 적용됩니다. 매칭되는 규칙이 없으면 기본 정책이 적용됩니다 — 이 프로젝트에서는 기본-차단. iptables, pf, Windows 방화벽 등 대부분의 프로덕션 방화벽의 표준 동작입니다.
