Skip to content

Concurrent packet processing firewall written in C, implementing a producer-consumer architecture with thread synchronization and a custom ring buffer for inter-thread communication

Notifications You must be signed in to change notification settings

marinaa13/parallel-firewall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Multithreaded Firewall

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.


Overview

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


Features

Core Components

  • 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.

Thread Synchronization

  • 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.

File Overview

  • 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.

Example Usage

./firewall input_packets.bin output_results.txt

Learning Outcomes

  • 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.

About

Concurrent packet processing firewall written in C, implementing a producer-consumer architecture with thread synchronization and a custom ring buffer for inter-thread communication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published