Re: Ifstated help needed

2015-12-25 Thread Timo Myyrä
Stuart Henderson  writes:

> On 2015-12-24, Timo Myyrä  wrote:
>
>> Hi,
>>
>> I'm trying to use ifstated to switch between my laptops wireless and wired
>> interface.
>> Currently it works when I don't have cable plugged in but once I plug in
the
>> cable the ifstated starts to switch between wired and wireless states and
won't
>> stay in wired state.
>>
>> So it seems the em0.link.down condition gets triggered in wired state but
why?
>> The dhclient seems to run so the em0 should have IP and so it should be
up.
>
> Kill ifstated and watch 'route -n monitor' when you plug in. Does state
> change more than once e.g. does it go up/down/up during negotiation
> with the switch? If so, you may need a sleep before re-checking link state.
>
> As it stands, I don't think this ifstated.conf is doing anything that
> you can't do just by running a dhclient on each interface all the time,
> dhclient already tracks link state itself, multiple priority routes
> work fine, and you aren't doing anything to alleviate the problem
> I mentioned in the other thread that does exist with that setup.

I'll look into the route stuff to see if I find the culprit.

I was operating under assumption that continual scanning of wireless networks
would drain more power. I'm using the bob beck's wireless scripts which
periodicly tries to associate with AP. When running both interfaces with
dhclient the wireless interface would try to scan and associate with AP even
if
I had ethernet cable attached.
Though I've already made the first mistake by going with assumption and not
actually measuring the power use the wireless would have.

I could probably tweak the wifinwid script a bit to skip AP scanning when em0
has carrier present.

But I'm testing the dhclient setup but it doesn't seem to work correctly. Once
I connect
ethernet cable I lose connectivity. Seems dhclient notices the em0 is up and
polls address for the interface and sets the routes:

$ ifconfig
...
em0: flags=8843 mtu 1500
lladdr 3c:97:0e:60:8d:ca
priority: 0
groups: egress
media: Ethernet autoselect (100baseTX full-duplex)
status: active
inet 192.168.0.105 netmask 0xff00 broadcast 192.168.0.255
iwn0: flags=8843 mtu 1500
lladdr 60:67:20:f8:17:f4
priority: 4
groups: wlan
media: IEEE802.11 autoselect (HT-MCS7 mode 11n)
status: active
ieee80211: nwid TW-EAV510v4A4A3 chan 11 bssid 00:1e:ab:0a:a4:a4 -28dBm
wpakey  wpaprotos wpa1,wpa2 wpaakms psk wpaciphers tkip,ccmp
wpagroupcipher tkip
inet 192.168.0.106 netmask 0xff00 broadcast 192.168.0.255
...

$ route -n show
Routing tables

Internet:
DestinationGatewayFlags   Refs  Use   Mtu  Prio Iface
default192.168.0.254  UGS01 - 8 em0
default192.168.0.254  UGS27 -12 iwn0
127.0.0.1  127.0.0.1  UHl00 32768 1 lo0
192.168.0/24   192.168.0.106  UCP12 - 4 iwn0
192.168.0/24   192.168.0.105  UCP00 - 4 em0
192.168.0.105  3c:97:0e:60:8d:ca  UHLl   02 - 1 em0
192.168.0.106  60:67:20:f8:17:f4  UHLl   0   40 - 1 iwn0
192.168.0.254  link#2 UHLc   02 - 4 iwn0
192.168.0.255  192.168.0.106  UHPb   00 - 1 iwn0
192.168.0.255  192.168.0.105  UHPb   00 - 1 em0

Timo



Re: Ifstated help needed

2015-12-24 Thread Zé Loff
> On 24/12/2015, at 10:07, Timo Myyrä  wrote:
>
> Hi,
>
> I'm trying to use ifstated to switch between my laptops wireless and wired
> interface

man trunk

> Currently it works when I don't have cable plugged in but once I plug in
the
> cable the ifstated starts to switch between wired and wireless states and
won't
> stay in wired state.
>
> So it seems the em0.link.down condition gets triggered in wired state but
why?
> The dhclient seems to run so the em0 should have IP and so it should be up.
>
> Timo
>
> daemon:
> Dec 24 10:43:29 phobos ifstated[31262]: changing state to wired
> Dec 24 10:43:29 phobos dhclient[2004]: iwn0 down; exiting
> Dec 24 10:43:33 phobos dhclient[22725]: DHCPREQUEST on em0 to
255.255.255.255
> Dec 24 10:43:33 phobos dhclient[22725]: DHCPACK from 192.168.0.254
(00:1e:ab:0a:a4:a3)
> Dec 24 10:43:33 phobos dhclient[22725]: bound to 192.168.0.105 -- renewal in
43200 seconds.
> Dec 24 10:43:33 phobos ifstated[31262]: changing state to wireless
> Dec 24 10:43:33 phobos dhclient[5042]: em0 down; exiting
> Dec 24 10:43:37 phobos dhclient[9581]: DHCPREQUEST on iwn0 to
255.255.255.255
> Dec 24 10:43:37 phobos dhclient[9581]: DHCPACK from 192.168.0.254
(00:1e:ab:0a:a4:a3)
> Dec 24 10:43:37 phobos dhclient[9581]: bound to 192.168.0.106 -- renewal in
43200 seconds.
> Dec 24 10:44:29 phobos dhclient[9921]: DHCPREQUEST on iwn0 to
255.255.255.255
> Dec 24 10:44:31 phobos findnwid: attached to network TW-EAV510v4A4A3 on
interface iwn0
> ...
>
> ifstated.conf:
> nwid  = '"[[ $(ifconfig iwn0 | sed -n \'/status/s/.*status: //p\') ==
\'active\' ]]" every 2'
>
> init-state wired
>
> state wireless {
>init {
>run "ifconfig em0 down"
>run "ifconfig iwn0 up"
>run "dhclient iwn0"
>}
>
># check if we have active wireless network
># if not, re-check for networks
>if ! $nwid && em0.link.down
>run "/usr/local/bin/findnwid iwn0"
>
>if em0.link.up
>set-state wired
> }
>
> state wired {
>init {
>run "ifconfig iwn0 down"
>run "ifconfig em0 up"
>run "dhclient em0"
>}
>
>if em0.link.down
>set-state wireless
> }



Re: Ifstated help needed

2015-12-24 Thread Timo Myyrä
Zé Loff  writes:

>> On 24/12/2015, at 10:07, Timo Myyrä  wrote:
>>
>> Hi,
>>
>> I'm trying to use ifstated to switch between my laptops wireless and wired
>> interface
>
> man trunk

Just switched from using trunk as it won't renew the addresses. And I'd like
to
run the wireless down when I'm not using it to reduce power use.

>
>> Currently it works when I don't have cable plugged in but once I plug in
the
>> cable the ifstated starts to switch between wired and wireless states and
won't
>> stay in wired state.
>>
>> So it seems the em0.link.down condition gets triggered in wired state but
why?
>> The dhclient seems to run so the em0 should have IP and so it should be
up.
>>
>> Timo
>>
>> daemon:
>> Dec 24 10:43:29 phobos ifstated[31262]: changing state to wired
>> Dec 24 10:43:29 phobos dhclient[2004]: iwn0 down; exiting
>> Dec 24 10:43:33 phobos dhclient[22725]: DHCPREQUEST on em0 to
255.255.255.255
>> Dec 24 10:43:33 phobos dhclient[22725]: DHCPACK from 192.168.0.254
(00:1e:ab:0a:a4:a3)
>> Dec 24 10:43:33 phobos dhclient[22725]: bound to 192.168.0.105 -- renewal
in 43200 seconds.
>> Dec 24 10:43:33 phobos ifstated[31262]: changing state to wireless
>> Dec 24 10:43:33 phobos dhclient[5042]: em0 down; exiting
>> Dec 24 10:43:37 phobos dhclient[9581]: DHCPREQUEST on iwn0 to
255.255.255.255
>> Dec 24 10:43:37 phobos dhclient[9581]: DHCPACK from 192.168.0.254
(00:1e:ab:0a:a4:a3)
>> Dec 24 10:43:37 phobos dhclient[9581]: bound to 192.168.0.106 -- renewal in
43200 seconds.
>> Dec 24 10:44:29 phobos dhclient[9921]: DHCPREQUEST on iwn0 to
255.255.255.255
>> Dec 24 10:44:31 phobos findnwid: attached to network TW-EAV510v4A4A3 on
interface iwn0
>> ...
>>
>> ifstated.conf:
>> nwid  = '"[[ $(ifconfig iwn0 | sed -n \'/status/s/.*status: //p\') ==
\'active\' ]]" every 2'
>>
>> init-state wired
>>
>> state wireless {
>>init {
>>run "ifconfig em0 down"
>>run "ifconfig iwn0 up"
>>run "dhclient iwn0"
>>}
>>
>># check if we have active wireless network
>># if not, re-check for networks
>>if ! $nwid && em0.link.down
>>run "/usr/local/bin/findnwid iwn0"
>>
>>if em0.link.up
>>set-state wired
>> }
>>
>> state wired {
>>init {
>>run "ifconfig iwn0 down"
>>run "ifconfig em0 up"
>>run "dhclient em0"
>>}
>>
>>if em0.link.down
>>set-state wireless
>> }



Re: Ifstated help needed

2015-12-24 Thread Stuart Henderson
On 2015-12-24, Timo Myyrä  wrote:
> Hi,
>
> I'm trying to use ifstated to switch between my laptops wireless and wired
> interface.
> Currently it works when I don't have cable plugged in but once I plug in the
> cable the ifstated starts to switch between wired and wireless states and 
> won't
> stay in wired state.
>
> So it seems the em0.link.down condition gets triggered in wired state but why?
> The dhclient seems to run so the em0 should have IP and so it should be up.

Kill ifstated and watch 'route -n monitor' when you plug in. Does state
change more than once e.g. does it go up/down/up during negotiation
with the switch? If so, you may need a sleep before re-checking link state.

As it stands, I don't think this ifstated.conf is doing anything that
you can't do just by running a dhclient on each interface all the time,
dhclient already tracks link state itself, multiple priority routes
work fine, and you aren't doing anything to alleviate the problem
I mentioned in the other thread that does exist with that setup.



Ifstated help needed

2015-12-24 Thread Timo Myyrä
Hi,

I'm trying to use ifstated to switch between my laptops wireless and wired
interface.
Currently it works when I don't have cable plugged in but once I plug in the
cable the ifstated starts to switch between wired and wireless states and won't
stay in wired state.

So it seems the em0.link.down condition gets triggered in wired state but why?
The dhclient seems to run so the em0 should have IP and so it should be up.

Timo

daemon:
Dec 24 10:43:29 phobos ifstated[31262]: changing state to wired
Dec 24 10:43:29 phobos dhclient[2004]: iwn0 down; exiting
Dec 24 10:43:33 phobos dhclient[22725]: DHCPREQUEST on em0 to 255.255.255.255
Dec 24 10:43:33 phobos dhclient[22725]: DHCPACK from 192.168.0.254 
(00:1e:ab:0a:a4:a3)
Dec 24 10:43:33 phobos dhclient[22725]: bound to 192.168.0.105 -- renewal in 
43200 seconds.
Dec 24 10:43:33 phobos ifstated[31262]: changing state to wireless
Dec 24 10:43:33 phobos dhclient[5042]: em0 down; exiting
Dec 24 10:43:37 phobos dhclient[9581]: DHCPREQUEST on iwn0 to 255.255.255.255
Dec 24 10:43:37 phobos dhclient[9581]: DHCPACK from 192.168.0.254 
(00:1e:ab:0a:a4:a3)
Dec 24 10:43:37 phobos dhclient[9581]: bound to 192.168.0.106 -- renewal in 
43200 seconds.
Dec 24 10:44:29 phobos dhclient[9921]: DHCPREQUEST on iwn0 to 255.255.255.255
Dec 24 10:44:31 phobos findnwid: attached to network TW-EAV510v4A4A3 on 
interface iwn0
...

ifstated.conf:
nwid  = '"[[ $(ifconfig iwn0 | sed -n \'/status/s/.*status: //p\') == 
\'active\' ]]" every 2'

init-state wired

state wireless {
init {
run "ifconfig em0 down"
run "ifconfig iwn0 up"
run "dhclient iwn0"
}

# check if we have active wireless network
# if not, re-check for networks
if ! $nwid && em0.link.down
run "/usr/local/bin/findnwid iwn0"

if em0.link.up
set-state wired
}

state wired {
init {
run "ifconfig iwn0 down"
run "ifconfig em0 up"
run "dhclient em0"
}

if em0.link.down 
set-state wireless
}