Deduplicate and simplify code
Take dynamic6 into consideration too
ipprotocol is inet or inet6