What does a Firewall do, and how does it typically decide on what traffic to allow or block?

Technical