Bug in /etc/rc.newwanip pfSense 1.2.3



  • Hello All,

    I have found a problem with /etc/rc.newwanip on pfSense 1.2.3-RELEASE

    The problem was discovered under 1.2.3 when configuring the WAN port with DHCP.  It was noted that when booting pfSense while connected to a WAN connection with a DHCP server that /etc/resolv.conf was correctly updated.  However, if pfSense is disconnected from the WAN while powered off and then connected to the WAN after it has been powered up the WAN interface acquires a valid DHCP address ** BUT ** /etc/resolv.con is not updated…

    Looking at rc.newwanip under 1.2.3 we see the following code which is supposed to update the dns server entries in resolv.conf

    /* regenerate resolv.conf if DNS overrides are allowed or the BigPond
      client is enabled */
    if (isset($config['system']['dnsallowoverride']) ||
            ($config['interfaces'][$interface]['ipaddr'] == "bigpond"))
                    system_resolvconf_generate(true);

    So… if dnsallowoverride is set (which is the default) then system_resolvconf_generate(true) should be executed...

    The problem is that ** IT IS NOT! **

    As it turns out the if condition is never executed...  Looking at the code in /etc/rc.newwanip we see

    if($old_ip) {
            $helpers = exec("/bin/ps awux | grep "{$old_ip}" | grep -v "grep"  | awk '{ print $2 }'");
            if($helpers)
                mwexec("kill " . trim($helpers));
    } else {
            log_error("WARNING! /etc/rc.newwanip could not deterimine the previous ip address ( $interface ).");
    }

    which kills the itself because rc.newwanip is invoked from check_reload_status with the old_ip address as an argument.  So... rc.newwanip does not execute to completion when run from within check_reload_status.

    The solution is pretty simple... We need to add a grep -v with our pid so that we don't kill ourselves.

    Here is the new code which resolves the problem.

    if($old_ip) {
            $mypid = getmypid();
            $helpers = exec("/bin/ps awux | grep "{$old_ip}" | grep -v "grep" | grep -v "{$mypid}" | awk '{ print $2 }'");
            if($helpers)
                mwexec("kill " . trim($helpers));
    } else {
            log_error("WARNING! /etc/rc.newwanip could not deterimine the previous ip address ( $interface ).");
    }

    the WAN interface is now brought up correctly when its plugged into the WAN after it has booted.

    /etc/rc.newwanip has been totally rewritten for pfSense 2.0.  I don't see a kill anywhere in the script so this is something that has been fixed.

    Thanks,

    --luis


Locked