OPNsense Forum

Archive => 24.1, 24.4 Legacy Series => Topic started by: Shcshc on February 03, 2024, 12:10:05 PM

Title: Reboot after periodic Interface reset
Post by: Shcshc on February 03, 2024, 12:10:05 PM
After update to 24.1 the system restarts after cron Job: periodic interface reset wan. It's an ppoe interface. before update it dosn't so.


Gesendet von iPad mit Tapatalk Pro
Title: Re: Reboot after periodic Interface reset
Post by: TheOfficialMrBlah on March 05, 2024, 12:33:53 PM
Same for me...

After the update to 24.1.2 (24.1.2_1) OPNsense freezes or reboots after "CronJob: periodic interface reset wan"..
Title: Re: Reboot after periodic Interface reset
Post by: Roi on March 15, 2024, 12:58:23 PM
Hi,

I have the same problem here.

Regards
Title: Re: Reboot after periodic Interface reset
Post by: Shcshc on March 25, 2024, 07:23:09 AM
After rebooting the system i do:
In reporting settings:
Reset dns data, rrd, netflow and repair netflow.

then system is not rebooting every night.


Gesendet von iPhone mit Tapatalk Pro
Title: Re: Reboot after periodic Interface reset
Post by: Shcshc on April 06, 2024, 08:20:03 AM
After last update problem is back. Resetting the settings is not working


Gesendet von iPhone mit Tapatalk Pro
Title: Re: Reboot after periodic Interface reset
Post by: TheOfficialMrBlah on June 25, 2024, 05:07:27 AM
After it worked for me again for some time, the problem has returned with the 24.1.9 (24.1.9_4) update...

24.7.4_1 <-> Problem still exists
Title: Re: Reboot after periodic Interface reset
Post by: Thomas B. on July 28, 2024, 12:20:22 PM
Same problem here,

after a CronJob "periodic interface reset" Parameter "opt4"

Interface opt4 = Device pppoe0

Could anyone solve the problem?
Title: Re: Reboot after periodic Interface reset
Post by: TheOfficialMrBlah on September 25, 2024, 05:25:33 AM
I still have the problem..
Version: 24.7.4_1

I see the following message on the console:

Fatal trap 12: page fault while in kernel mode
cpuid = 1; apic id = 02
fault virtual address = 0x10
fault code = supervisor read data, page not present


Title: Re: Reboot after periodic Interface reset
Post by: circa1665 on January 12, 2025, 09:02:44 PM
If it's helpful, I Frankensteined a couple of different scripts I found, and used Claude.ai (https://claude.ai/) to help me get this working, this resets the interface rather than rebooting Opnsense.

Create a script called check_gateways.sh in /home: nano /home/check_gateways.shAdd the content below, change the defined interfaces as needed.
Set the permissions of the script: chmod 700 check_gateways.sh
#!/bin/sh

# Define interfaces to check
interfaces="igc0 wg1"

logger -s "INFO: Gateway check started for: $interfaces"

# Function to get the default gateway for a given interface and IP version
get_gateway() {
    iface=$1
    ip_version=$2
    if [ "$ip_version" = "4" ]; then
        netstat -4rn | grep "$iface" | head -1 | awk '{print $2}'
    elif [ "$ip_version" = "6" ]; then
        netstat -6rn | grep "$iface" | head -1 | awk '{print $2}'
    fi
}

# Function to check if interface is WireGuard
is_wireguard() {
    case "$1" in
        wg*) return 0 ;;
        *) return 1 ;;
    esac
}

# Function to check WireGuard interface status
check_wireguard_status() {
    iface=$1
    # Check if interface exists and has an IP address
    if /sbin/ifconfig "$iface" >/dev/null 2>&1 && /sbin/ifconfig "$iface" | grep -q "inet "; then
        return 0  # Interface is up and has IP
    else
        return 1  # Interface is down or has no IP
    fi
}

# Enhanced reset interface function
reset_interface() {
    iface=$1
    logger -s "WARNING: Reset interface $iface"
   
    # Log current interface status before reset
    logger -s "INFO: Interface $iface pre-reset status"
    /sbin/ifconfig "$iface"
   
    # Attempt interface reset
    /sbin/ifconfig "$iface" down
    sleep 2
   
    # Verify interface is down
    if /sbin/ifconfig "$iface" >/dev/null 2>&1; then
        logger -s "ERROR: Failed to bring down interface $iface"
        return 1
    fi
   
    # Bring interface back up
    /sbin/ifconfig "$iface" up
    sleep 2
   
    # Verify interface is up
    if ! /sbin/ifconfig "$iface" >/dev/null 2>&1; then
        logger -s "CRITICAL: Failed to bring up interface $iface after reset"
        return 1
    fi
   
    logger -s "INFO: Interface $iface reset completed"
    return 0
}

# Loop through each interface and check its gateways
for iface in $interfaces; do
    # Get the IPv4 and IPv6 gateways for this interface
    ipv4_gateway=$(get_gateway "$iface" 4)
    ipv6_gateway=$(get_gateway "$iface" 6)
   
    # Process IPv4 gateway
    if [ -n "$ipv4_gateway" ]; then
        logger -s "INFO: Checking IPv4 Gateway $ipv4_gateway on Interface $iface"
       
        if is_wireguard "$iface"; then
            # For WireGuard, check interface status
            if check_wireguard_status "$iface"; then
                logger -s "INFO: WireGuard interface $iface functioning"
            else
                logger -s "ERROR: WireGuard interface $iface down"
                if ! reset_interface "$iface"; then
                    logger -s "CRITICAL: Reset failed for WireGuard interface $iface"
                fi
            fi
        else
            # For non-WireGuard interfaces, use ping check
            if ping -c 3 "$ipv4_gateway" > /dev/null 2>&1; then
                logger -s "INFO: IPv4 Gateway $ipv4_gateway on Interface $iface reachable"
            else
                logger -s "ERROR: IPv4 Gateway $ipv4_gateway on Interface $iface unreachable"
                if ! reset_interface "$iface"; then
                    logger -s "CRITICAL: Reset failed for interface $iface"
                fi
            fi
        fi
    else
        logger -s "WARNING: No IPv4 Gateway found for Interface $iface"
    fi
   
    # Process IPv6 gateway
    if [ -n "$ipv6_gateway" ]; then
        logger -s "INFO: Checking IPv6 Gateway $ipv6_gateway on Interface $iface"
       
        if is_wireguard "$iface"; then
            # Skip IPv6 check for WireGuard as it's already checked above
            logger -s "INFO: WireGuard interface $iface IPv4 verified"
        else
            if ping6 -c 3 "$ipv6_gateway" > /dev/null 2>&1; then
                logger -s "INFO: IPv6 Gateway $ipv6_gateway on Interface $iface reachable"
            else
                logger -s "ERROR: IPv6 Gateway $ipv6_gateway on Interface $iface unreachable"
                if ! reset_interface "$iface"; then
                    logger -s "CRITICAL: Reset failed for interface $iface"
                fi
            fi
        fi
    else
        logger -s "WARNING: No IPv6 Gateway found for Interface $iface"
    fi
done

logger -s "INFO: Gateway check completed"

Next, create a .conf file called actions_checkgateways.conf in /usr/local/opnsense/service/conf/actions.d (your file must start with "actions_"): nano /usr/local/opnsense/service/conf/actions.d/actions_checkgateways.confAdd the content below:

[check]
command:/home/check_gateways.sh
parameters:
type:script
message:Starting gateway check script
description:Check if gateway(s) are down, and if so, reset associated interface

Now run: service configd restart, then: configctl checkgateways check, you should see an "OK" message.

To setup a cron job, go to System > Settings > Cron and add a Job.
You should see your cron command in the dropdown: Check if gateway(s) are down, and if so, reset associated interface.