Option to Hot Plug (some) Interfaces



  • Hi,

    For the past week I've been using pfSense, and am LOVING it. There is one thing that I would really like to be added though, that is the ability to have an interface that is safe to unplug and reboot without triggering an interface mismatch.

    e.x.
    Let's say you have a USB 4g modem and you want to use it as a 2nd WAN, you can do that no problem. Except when you unplug it and reboot, it will fail to boot due to a missing interface.

    I understand the downfalls of ignoring interface changes upon boot, however that is not what I am proposing.

    My current set-up:
    I set up WAN1(em0) and OPT1(ue0[USB 4g Modem]) with all the needed gateway groups and firewall rules needed for Load-Balancing and Fail-Over and some policy based routing based on ASNs. When I want to unplug the modem I just need to delete the interface, then I can safely reboot. When I want to reconnect to the modem I plug it in again and add the interface, everything is back to working again (as in it remembers all the set gateway groups and firewall rules).

    A better solution:
    Just add a check box that makes that interface automatically ignored when unplugged, and automatically added when plugged in again. Also tying that device to the OPT1 interface, so that if in the mean time you happen to add a new interface it will try to match that to the previously saved device. If the new device does not match it will not be assigned to OPT1, if the new device does match it will be assigned to OPT1 and automatically added.

    Is this possible? Is there a better solution? Can I write a script to do this? Do you think this is a bad idea?

    Please share your thoughts, and a have a wonderful day/night.


  • Netgate Administrator

    You can do it by adding ue to the list if interfaces to exclude from the check:
    https://github.com/pfsense/pfsense/blob/c07f1c2667995b9c46f9187fdf0baa6efbb8aa19/src/etc/inc/util.inc#L2201

    But it's a bad idea for some of the reasons you eluded to. If the firewall boots past that with ue0 still assigned and enabled but not present you are in an unknown situation. There is no clean way past that currently. The recommendation here is to use a ppp connected modem which is handled gracefully if removed or and Ethernet connected device so the physical interface is not removed from pfSense.

    You can open a feature request in Redmine: https://redmine.pfsense.org/
    There have been several other similar things in the past but it might be time to re-visit it.

    Steve



  • Hi,

    Thank you for the reply.

    I opened a feature request here.

    I managed to make it work good enough so that I can use it. Have been reading the source code and managed to make some php scripts that do what I want.

    This creates the interface:
    Runs on boot-up and when the USB modem is plugged in (using devd).

    <?php
    require_once("config.inc");
    require_once("interfaces.inc");
    
    if (does_interface_exist(ue0)) {
    
            if (!is_array($config['interfaces']['opt100'])) {
                    $config['interfaces']['opt100'] = array();
            }
    
            $config['interfaces']['opt100']['if'] = 'ue0';
            $config['interfaces']['opt100']['enable'] = 'true';
            $config['interfaces']['opt100']['descr'] = 'WAN2';
            $config['interfaces']['opt100']['blockpriv'] = 'on';
            $config['interfaces']['opt100']['blockbogons'] = 'on';
            $config['interfaces']['opt100']['ipaddr'] = 'dhcp';
            $config['interfaces']['opt100']['ipaddrv6'] = 'dhcp6';
            $config['interfaces']['opt100']['dhcp6-ia-pd-len'] = '0';
    
            print_r($config['interfaces']);
            write_config($config);
    
    }
            sleep(2);
            interface_dhcp_configure(ue0);
    ?>
    
    

    This deletes the interface:
    I included it in /etc/rc.bootup so that the interface gets deleted on boot.

    <?php
    require_once("config.inc");
    
    if (isset($config['interfaces']['opt100'])) {
            unset($config['interfaces']['opt100']);
            print_r($config['interfaces']);
            write_config($config);
    }
    
    ?>
    

    This script runs when the USB modem is plugged in and on boot:

    #!/bin/sh
    sleep 10
    logger usb_modeswitch Changing Modem Mode
    usb_modeswitch -v 0x12d1 -p 0x1f01 -c /usr/local/share/usb_modeswitch/12d1:1f01
    sleep 5
    
    php /path/to/create.php
    

    I tested this and seems to work really good.


  • Netgate Administrator

    Nice. 👍



  • @xhivo97 said in Option to Hot Plug (some) Interfaces:

    Hi,

    Thank you for the reply.

    I opened a feature request here.

    I managed to make it work good enough so that I can use it. Have been reading the source code and managed to make some php scripts that do what I want.

    This creates the interface:
    Runs on boot-up and when the USB modem is plugged in (using devd).

    <?php
    require_once("config.inc");
    require_once("interfaces.inc");
    
    if (does_interface_exist(ue0)) {
    
            if (!is_array($config['interfaces']['opt100'])) {
                    $config['interfaces']['opt100'] = array();
            }
    
            $config['interfaces']['opt100']['if'] = 'ue0';
            $config['interfaces']['opt100']['enable'] = 'true';
            $config['interfaces']['opt100']['descr'] = 'WAN2';
            $config['interfaces']['opt100']['blockpriv'] = 'on';
            $config['interfaces']['opt100']['blockbogons'] = 'on';
            $config['interfaces']['opt100']['ipaddr'] = 'dhcp';
            $config['interfaces']['opt100']['ipaddrv6'] = 'dhcp6';
            $config['interfaces']['opt100']['dhcp6-ia-pd-len'] = '0';
    
            print_r($config['interfaces']);
            write_config($config);
    
    }
            sleep(2);
            interface_dhcp_configure(ue0);
    ?>
    
    

    This deletes the interface:
    I included it in /etc/rc.bootup so that the interface gets deleted on boot.

    <?php
    require_once("config.inc");
    
    if (isset($config['interfaces']['opt100'])) {
            unset($config['interfaces']['opt100']);
            print_r($config['interfaces']);
            write_config($config);
    }
    
    ?>
    

    This script runs when the USB modem is plugged in and on boot:

    #!/bin/sh
    sleep 10
    logger usb_modeswitch Changing Modem Mode
    usb_modeswitch -v 0x12d1 -p 0x1f01 -c /usr/local/share/usb_modeswitch/12d1:1f01
    sleep 5
    
    php /path/to/create.php
    

    I tested this and seems to work really good.

    Do you mind to share what 4g mdem your using ??


Log in to reply