# Default route is lost when power switches from AC to battery

## Kaorukun

Few days ago I stumbled upon a weird issue where a statically configured default route on my laptop would seemingly randomly disappear. Today I finally discovered what causes it and to my surprise it's something within the power management. Once I disconnect my power cable and switch to battery, my default route is lost.

I'm working on a wired connection and use a static IP configuration:

```

my /etc/conf.d/net :

config_eth0="10.105.150.158/16"

routes_eth0="default via 10.105.0.1"

```

The network works fine and the default route is there after boot or restarting the net.eth0 init script:

```

# ip route show                                                                                                                                                     

default via 10.105.0.1 dev eth0  metric 2

10.105.0.0/16 dev eth0  proto kernel  scope link  src 10.105.150.158

127.0.0.0/8 dev lo  scope host

127.0.0.0/8 via 127.0.0.1 dev lo

```

When I disconnect my power cable and the laptop switches to battery, the default route suddenly disappears, while all the other configuration is still intact. I have to restore it manually or by restarting the interface:

```

# ip route show

10.105.0.0/16 dev eth0  proto kernel  scope link  src 10.105.150.158

127.0.0.0/8 dev lo  scope host        

127.0.0.0/8 via 127.0.0.1 dev lo

# ip route add default via 10.105.0.1

# ip route show                                                                                                                                                     

default via 10.105.0.1 dev eth0

10.105.0.0/16 dev eth0  proto kernel  scope link  src 10.105.150.158

127.0.0.0/8 dev lo  scope host

127.0.0.0/8 via 127.0.0.1 dev lo

```

Note that the network cable is permanently plugged in, and the interface never shuts down or loses the link. Even if I disconnect the network cable the route does not go away. Switching from the battery to AC power also does not cause the route to disappear.

Just to be sure I stopped laptop_mode and powernowd daemons and even removed them from the runlevels - still same behavior.

Any clues what subsystem is responsible for this behavior?

/etc/conf.d/net : http://pastebin.com/sdpfGnYS

emerge --info : http://pastebin.com/thMBKtbq

rc-update show : http://pastebin.com/wc6dcTim

----------

## Roman_Gruber

so what are you using systemd? eudev? static init? what else? (+ useflags + package version isntalled appreciated)

looks like a broken behaviour of some udev rules or udev ot myself and therefore its important to know what type of box yours is.

or something in /etc misconfigured

----------

## krinn

openrc start service, but once done, it do nothing, if you disconnect a device where a service is attach to it, the service will stay start, as openrc isn't aware the device disappears, there's no need then to restart it.

If you remove the cable, your ip and route will remains, only disabling the route or removing the card will remove the route.

So i think really, the card gets disconnect and reconnect while you switch from power to battery, devmanager may even see it, but devmanager add drivers to device, while it could also trigger another script, i don't think anyone have its net service attach to any network device, it's just when you boot, devmanager coldplug drivers for network, and openrc then see it should start net to provide it.

What you could do is try to force the hotplug, and glad for you, there's a tool that is not really made to hotplug a card, but sense the cable state. Use ifplugd or some tool like that, it will detect the lost or availability of the cable, making it restart the configuration (and so reenabling the route, asking openrc to stop and start the network where the cable state change).

If it's not that, it really mean something is deleting the route then.

----------

## Kaorukun

 *tw04l124 wrote:*   

> so what are you using systemd? eudev? static init? what else? (+ useflags + package version isntalled appreciated)
> 
> looks like a broken behaviour of some udev rules or udev ot myself and therefore its important to know what type of box yours is.
> 
> or something in /etc misconfigured

 

I'm using openrc, udev and ifplugd:

sys-apps/ifplugd-0.28-r9::gentoo  USE="-doc (-selinux)"

sys-apps/openrc-0.17::gentoo  USE="ncurses netifrc pam unicode -audit -debug -newnet (-prefix) (-selinux) -static-libs -tools"

sys-fs/udev-216::gentoo  USE="acl firmware-loader gudev introspection kmod -doc (-selinux) -static-libs"

So far I can see I have no specific ifplugd configuration (/etc/ifplugd/ifplugd.conf), just /etc/ifplugd/ifplugd.action : http://pastebin.com/0x3zTusT

Also I noticed the route removal occurs only when connected using the Ethernet interface, and not with WLAN.

----------

## Buffoon

Is your laptop switching to a different runlevel when on battery?

----------

## krinn

if devmanager reload the device, it should appears in dmesg

if ifplugd detect cable change, it should appears in dmesg

So, if any of the two do anything, it is in your dmesg.

----------

