Firewall Rules
You are given a list of firewall rules. Each rule contains an action, either ALLOW or DENY, and an IPv4 address or CIDR block. Determine how to evaluate the rules and what access should be granted for incoming IP addresses based on the rule list.
Example rules:
ALLOW 192.168.100.0/24DENY 192.168.0.5/30ALLOW 192.168.1.1/22ALLOW 1.0.0.0/8ALLOW 2.3.4.9DENY 8.8.8.8/1ALLOW 5.6.7.8
This problem focuses on IPv4 range matching and firewall policy evaluation. The input consists of ALLOW and DENY rules, where each rule may be a single IP address or a CIDR block. A typical solution converts IPv4 addresses into 32-bit integers and uses bit masks to test whether an incoming IP falls inside a rule’s range; if rule order matters, the rules should be processed sequentially according to the statement.