On Thu, Jan 04, 2018 at 06:34:26PM +0100, Landry Breuil wrote:
> Hi,
> 
> i know ifstated was designed with carp in mind, but nothing from the
> manpage seems to forbid one to use it with other interfaces, thus im
> trying to make it work with ppp so that i can just up a potentially
> existing ppp0 interface and ifstated would magically start xl2tpd to up
> a tunnel.
> 
> fiddling with this, i came up with this sample config which... behaves
> weird:
> 
> init-state vpn_unknown
> 
> state vpn_up {
>         if ppp1.link.unknown {
>                 run 'echo "ppp1 is up->unk" > /tmp/foo'
>         }
>         if ppp1.link.down {
>                 run 'echo "ppp1 is up->down" > /tmp/foo'
> 
>         }
> }
> state vpn_unknown {
>         if ppp1.link.up {
>                 run 'echo "ppp1 is unk->up" > /tmp/foo'
>                 set-state vpn_up
>         }
>         if ppp1.link.down {
>                 run 'echo "ppp1 is unk->down" > /tmp/foo'
>                 set-state vpn_down
>         }
> }
> 
> $ifconfig ppp1
> ppp1: flags=8010<POINTOPOINT,MULTICAST> mtu 1500
>         index 8 priority 0 llprio 3
>         groups: ppp
> 
> $doas ifstated -vd -f t.conf  
> initial state: vpn_unknown
> changing state to vpn_unknown
> running echo "ppp1 is unk->up" > /tmp/foo
> changing state to vpn_up
> running echo "ppp1 is up->unk" > /tmp/foo
> started
>
> i dont really understand the state flipping here... it's as if at first
> ppp1.link.up was true, then immediately the link state is unknown.. or
> maybe it just evaluates the first statement to true, when no macros are
> used ? the config is valid according to the grammar, but the behaviour
> is .. weird. Dunno if the grammar or the examples or the manpage should be
> adapted/clarified ?
 
Well, 

UNKNOWN has been treated as UP since quite a long time.
That means both statements are true.

from <net/if.h>:

#define LINK_STATE_IS_UP(_s)    \
                ((_s) >= LINK_STATE_UP || (_s) == LINK_STATE_UNKNOWN) 

I think we should either don't use this macro within ifstated
and be more explicit with the link states,
or remove support for "link.unknown".

  Marco

Reply via email to