• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

Interface_has_gateway is not true if static ip and gateway configured

Scheduled Pinned Locked Moved 2.1 Snapshot Feedback and Problems - RETIRED
6 Posts 2 Posters 1.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G
    ggzengel
    last edited by May 7, 2013, 6:28 PM

    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;
    }
    
    
    1 Reply Last reply Reply Quote 0
    • P
      phil.davis
      last edited by May 8, 2013, 3:52 AM

      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.

      As the Greek philosopher Isosceles used to say, "There are 3 sides to every triangle."
      If I helped you, then help someone else - buy someone a gift from the INF catalog http://secure.inf.org/gifts/usd/

      1 Reply Last reply Reply Quote 0
      • G
        ggzengel
        last edited by May 8, 2013, 9:09 AM

        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.

        1 Reply Last reply Reply Quote 0
        • P
          phil.davis
          last edited by May 8, 2013, 9:22 AM

          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.

          As the Greek philosopher Isosceles used to say, "There are 3 sides to every triangle."
          If I helped you, then help someone else - buy someone a gift from the INF catalog http://secure.inf.org/gifts/usd/

          1 Reply Last reply Reply Quote 0
          • G
            ggzengel
            last edited by May 8, 2013, 7:03 PM

            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.

            1 Reply Last reply Reply Quote 0
            • P
              phil.davis
              last edited by May 9, 2013, 2:11 AM

              @phil.davis:

              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…)

              As the Greek philosopher Isosceles used to say, "There are 3 sides to every triangle."
              If I helped you, then help someone else - buy someone a gift from the INF catalog http://secure.inf.org/gifts/usd/

              1 Reply Last reply Reply Quote 0
              6 out of 6
              • First post
                6/6
                Last post
              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                This community forum collects and processes your personal information.
                consent.not_received