You can read more about packet filtering on OpenBSD's website, and in the FreeBSD Handbook. If you're looking for free firewall router software based on BSD, check out pfsense.