# wifi interface not going down when signal lost

## Zedsquared

Hi Folks,

     I have what is going to be a headless gentoo installation running mostly as a router.

I'm trying to get ifmetric to run whenever the wifi connects and disconnects in order to make wifi be chosen over a 3G connection when in range.

My wireless interface is wlp4s0 and it happily connects to my access point, if I manually run ifmetric I can control which interface gets the default route ok.

in /etc/conf.d/net I have:

```

postup()

{

echo "postup running if=" $IFACE >> /var/log/netrb

if [${IFACE}='wlp4s0']; then

echo "changing metric" >> /var/log/netrb

ifmetric ppp0 10

fi

return 0;

}

postdown()

{

echo "postdown running if="$IFACE >> /var/log/netrb

if [${IFACE}='wlp4s0']; then

echo "changing metric" >> /var/log/netrb

ifmetric ppp0 0

fi

return 0;

}

```

I have a two part problem, 

1) If I manually stop the interface I can see the postdown function gets run by the log file but the if statement that checks the interface fails with the error:

/etc/init.d/../conf.d/net: line 24: [wlp4s0=wlp4s0]: command not found

and I never see the "changing metric" message in the log file. I've tried various combinations of syntax I found via googling but can't get it right and my bash-fu is terrible!

[edit] above now solved, see post below..

However:

2) The second problem is that if I switch off the access point then the wireless interface doesn't seem to drop so postdown() never gets run. This needs to be a switchover without intervention as it's going to be tucked away on a vehicle that should use wifi when in the garage and 3G/4G elsewhere.

When the AP is truned off I see a disconnect event from wpa_supplicant but the interface stays up. 

Any thoughts, good people?

Cheers,

       Robin.Last edited by Zedsquared on Sat May 30, 2015 1:02 am; edited 1 time in total

----------

## Zedsquared

Ok, part 1 solved, thanks to the lovely people on gentoo IRC, I was missing some vital spaces in the script so the line should read:

```
 if [ ${IFACE} = 'wlp4s0' ]; then 
```

it now does the right thing when run, however dropping the wifi signal still does not drop the interface so postdown() doesn't run unless I manually stop the interface.

I'm using ath10k drivers on 4.04 kernel AMD64 if that helps.

----------

## szatox

Why should droppping signal take your interface down too? Interface and link are not the same things. If you take your interface down, you will not be able to establish a link.

If failing link would take interface down, it would make you unable to get another link. Not what you expect with wifi. In fact, not even what you expect with wires. You pull the wire out, link goes down, you plug in another one, the link goes up.

You're trying to drive a screw with a hammer. There are things that track link status, but postdown() is not one of them. I think dhcpcd can do that for you. I know there are other ways, but never needed it myself

----------

## Zedsquared

I see what you mean... I thought ifplugd was supposed to work by triggering the  interface up and down routines though.

I just need a way of firing some commands when the link goes up or down. I'll check that ifplugd is setup properly when I get back to it on Monday.

Thanks for clarifying my terminology, it will help my questions and searches for this.

Cheers,

       Robin.

----------

## szatox

you can try polling interface with ifconfig

 *Quote:*   

> 
> 
> IFACE=wlan1
> 
> while sleep 1
> ...

 

It seems you can get ifplugd to do that, but it's not what it does by default.

----------

