On 28.10.2013, at 01:43, Fred Snurd <[email protected]> wrote:
> On Monday, October 28, 2013 12:38 AM, Fred Snurd <[email protected]> wrote:
>
> I found the following article on undeadly which uses ifstated(8) to
> automatically acquire a DHCP lease upon link state
> changes on an Ethernet interface:
>
> http://undeadly.org/cgi?action=article&sid=20071012140725&mode=expanded
>
I don’t get why you’re doing this. The article is from 2007 and dhclient has
been fixed in 2008:
----------------------------
dhclient.c revision 1.118
date: 2008/05/09 05:19:14; author: reyk; state: Exp; lines: +27 -15
- don't give up when the link is not available on startup: dhclient
goes to background and listens on the routing socket for link to come
up before it retries.
- renew the lease whenever the link was lost and becomes active again.
- listen for link state changes on non-ethernet devices like wireless,
the link state becomes active when the wireless has been associated to
the AP and becomes active. this helps to automatically renew the lease
when the user is roaming.
ok beck@, deraadt@
> ...& thought that it would be simple to modify this for wireless links. To
> prove this to myself, I looked at the output of
> ifconfig(8) on an Alix system as it was connecting to an access point.
> Before doing any interface configuration:
>
> $ ifconfig ath0
> ath0: flags=8822<BROADCAST,NOTRAILERS,SIMPLEX,MULTICAST> mtu 1500
> lladdr a8:54:b2:23:da:80
> priority: 4
> groups: wlan
> media: IEEE802.11 autoselect
> status: no network
> ieee80211: nwid ""
> $
>
> ...where "status" indicates the link state. Upon connecting to the AP,
>
> $ sudo ifconfig ath0 nwid <my-id> wpakey <my-password>
> $ ifconfig ath0ath0: flags=8822<BROADCAST,NOTRAILERS,SIMPLEX,MULTICAST> mtu
> 1500
> lladdr a8:54:b2:23:da:80
> priority: 4
> groups: wlan
> media: IEEE802.11 autoselect
> status: no network
> ieee80211: nwid <my-id>
> wpakey <not displayed> wpaprotos wpa1,wpa2 wpaakms psk wpaciphers
> tkip,ccmp wpagroupcipher tkip
> $
>
> ...which still shows that the link has not changed as expected. Upon getting
> a DHCP lease,
>
> $ sudo dhclient ath0
> DHCPREQUEST on ath0 to 255.255.255.255 on port 67
> DHCPACK from 192.168.0.1 (..:..:..:..:..:..)
> bound to 192.168.0.4 -- renewal in 43200 seconds.
> $ ifconfig ath0
> ath0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> lladdr a8:54:b2:23:da:80
> priority: 4
> groups: wlan egress
> media: IEEE802.11 autoselect (DS11 mode 11b)
> status: active
> ieee80211: nwid homestead chan 1 bssid 00:26:b8:d4:1c:49 wpakey <not
> displayed> wpaprotos wpa1,wpa2 wpaakms psk wpaciphers tkip,ccmp
> wpagroupcipher tkip
> inet6 fe80::aa54:b2ff:fe23:da80%ath0 prefixlen 64 scopeid 0x4
> inet 192.168.0.2 netmask 0xffffff00 broadcast 192.168.0.255
> $
>
> ...which now shows that the link is active. After turning off the AP, the
> link is seen to go down:
>
> $ ifconfig ath0
> ath0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> lladdr a8:54:b2:23:da:80
> priority: 4
> groups: wlan egress
> media: IEEE802.11 autoselect (DS11 mode 11b)
> status: no network
> ieee80211: nwid homestead wpakey <not displayed> wpaprotos wpa1,wpa2
> wpaakms psk wpaciphers
> tkip,ccmp wpagroupcipher tkip
> inet6 fe80::aa54:b2ff:fe23:da80%ath0 prefixlen 64 scopeid 0x4
> $
>
> Upon turning the AP back on, the link is seen again to become active:
>
> $ ifconfig ath0
> ath0: flags=8863<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> lladdr a8:54:b2:23:da:80
> priority: 4
> groups: wlan egress
> media: IEEE802.11 autoselect (DS11 mode 11b)
> status: active
> ieee80211: nwid homestead wpakey <not displayed> wpaprotos
> wpa1,wpa2 wpaakms psk wpaciphers tkip,ccmp wpagroupcipher tkip
> inet6 fe80::aa54:b2ff:fe23:da80%ath0 prefixlen 64 scopeid 0x4
> $
>
> ...so I assumed that ifstated.conf file shown in the article doesn't require
> much modification. Below is the minimal changes made:
>
> $ cat /etc/ifstated.conf
> wireless_up = 'ath0.link.up'
> wireless_down = '!ath0.link.up'
>
> state auto {
> if $wireless_up
> set-state main
> }
>
> state main {
> init {
> run 'ifconfig ath0 nwid <my-id> wpakey <my-password>'
> run 'dhclient ath0'
> }
> if $wireless_down {
> # run 'ifconfig ath0 delete'
> set-state auto
> }
> }
>
> init-state auto
> $
>
> ifstated has been enabled in /etc/rc.conf.local, & the system has been
> rebooted:
>
> $ grep ifstated /etc/rc.conf.local
> ifstated_flags=''
> $
>
> No /etc/hostname.ath0 file has been created. ath0 comes up as expected at
> system boot, but cycling the AP
> doesn't result in the network connection to be re-established.
>
> Can someone point out what I am missing for I'm not seeing it. Thanks for
> any clarification shared.