he tricky part is that, at the moment, when you are adding a new rule, $pconfig['ipprotocol'] is actually blank. And that causes all GWGs to be listed here - both IPv4 and IPv6. I was going to explicitly set $pconfig['ipprotocol']="inet" on starting a new rule (which is the default displayed to the user). Doing that causes just the IPv4 gateways and GWGs to be listed.
But then when the user changes the IP version selection to IPv6, there is no code that triggers to rebuild the gateways dropdown list. So the user would have to save the rule with version IPv6 and "default" gateway, then edit it again (causing the gateways dropdown list to be correctly built for IPv6) and select the gateway they want.
Because of those side-effects, I abandoned compressing these tests like you suggest. To avoid the side-effects it needs some Java-Ajax fancy stuff to trigger the dropdown list being rebuilt when the user changes the IP version selection.
I do have a nicely compressed version of these lines, but it has the (little?) side-effect I described. What to do?