A multithreaded firewall simulator written in C, using the producer-consumer model.
The program reads network packets, processes them through multiple worker threads, and outputs security verdicts such as allow, deny, or inspect based on packet contents.
This project implements a real-time packet processing system using ring buffers, threads, and synchronization primitives (pthread_mutex, pthread_cond).
It simulates how a firewall handles concurrent data streams, ensuring safe access to shared resources and efficient packet throughput.
Language: C
Focus: Concurrency, synchronization, producer-consumer pattern, systems programming
- Producer threads — read packet data from input files and enqueue it in a shared ring buffer.
- Consumer threads — dequeue packets, process them, and determine firewall actions.
- Ring buffer — thread-safe, circular buffer for inter-thread communication.
- Packet structure — stores header and payload data for classification.
- Firewall logic — simulates packet filtering, hashing, and timestamp-based decisions.
pthread_mutex— protects buffer access.pthread_cond— coordinates producers and consumers when the buffer is full or empty.- Graceful termination — handled through a stop signal to wake all threads safely.
firewall.c— main program logic, initializes threads and synchronizes workflow.producer.c— reads packet data and enqueues it in the ring buffer.consumer.c— dequeues and processes packets concurrently.ring_buffer.c— circular buffer implementation with blocking synchronization.packet.c— packet structure definition and hash computation.serial.c— sequential reference version for testing.
./firewall input_packets.bin output_results.txt
- Implemented synchronization using mutexes and condition variables.
- Designed a scalable, thread-safe producer-consumer system.
- Practiced low-level memory management and concurrent data access.
- Simulated real-world packet processing behavior in a firewall system.