As far as 'making' a software level filtering firewall goes, try seeing how others work as well. You might want to look into iptables (*nix) and it's switches.

You might want to ellaborate a...