Interface_has_gateway is not true if static ip and gateway configured
-
Is it right, that this function returns false on interfaces with static ip and gateways? The function name suggests other.
function interface_has_gateway($friendly) { global $config; if (!empty($config['interfaces'][$friendly])) { $ifname = &$config['interfaces'][$friendly]; switch ($ifname['ipaddr']) { case "dhcp": case "pppoe": case "pptp": case "l2tp": case "ppp"; return true; break; default: if (substr($ifname['if'], 0, 4) == "ovpn") return true; if (!empty($ifname['gateway'])) return true; break; } } return false; }
-
It works for me:
$friendly = "wan"; $xxx = interface_has_gateway($friendly); var_dump($xxx); bool(true)
You have to pass it "wan", "opt1" etc in lower case. It uses this underlying name, not the descriptive name you might have given each interface.
-
I know. If I change the interface to DHCP the function will return true.
Where have you assigned your gateway?
I didn't set a gateway in interface settings. I only assigned a gateway in system->routing. Then the function fails. -
When you choose DHCP for an interface, the gateway is created automagically and gets set at run-time to the gateway provided by DHCP.
When you choose Static IP, then for a WAN link you need to pick a gateway on the Interfaces settings screen. I have a suspicion that when you just use System:Gateways:Edit gateway page and choose an interface, it doesn't put the "backward-pointer" in the Interface settings pointing back at the gateway entry. I'll try that when I get access to my test system in a few hours. -
I was looking on get_interface_gateway and learned that it's necessary to add a gateway at interface settings.
I never did this. So I didn't get route-to rules on static ips.
The strange thing is, that ipsec and openvpn goes the right way. Is there a new logic that service always go to the interfaces where there bound to? Then pfsense don't need route-to rules any more.
-
When you choose DHCP for an interface, the gateway is created automagically and gets set at run-time to the gateway provided by DHCP.
When you choose Static IP, then for a WAN link you need to pick a gateway on the Interfaces settings screen. I have a suspicion that when you just use System:Gateways:Edit gateway page and choose an interface, it doesn't put the "backward-pointer" in the Interface settings pointing back at the gateway entry. I'll try that when I get access to my test system in a few hours.You can add as many gateways as you like. When you select the Interface field while adding a gateway it is just "Choose which interface this gateway applies to." - you are telling the system that this is a potential gateway for the selected interface, not that it is the actual gateway.
When you edit the interface itself, the dropdown list of gateways shows you all the gateways which apply to the interface, and you pick one.
I guess allowing you to predefine multiple possible gateways for an interface lets you have them setup ready to use and you can easily swap around between them, someone must have had a use case for that, or it just fell out easily that way when coding the system. (since you have to be able to have IPv4 and IPv6 gateways…)