nerves-project-attic/nerves_network

Nerves.Network.teardown/1 not disconnecting from wireless network

kyleaa opened this issue · 2 comments

Running on a Raspberry Pi Zero W and connecting to an iPhone 7 personal hotspot, calling Nerves.Network.teardown "wlan0" removes the network configuration from the SystemRegistry, but the network remains up. I added in HTTPoison and confirmed that I could successfully make network calls after tearing down the interface.

iex(2)> Nerves.Network.setup "wlan0", ssid: "kaa7-red", key_mgmt: :"WPA-PSK", psk: "wpakey"
[debug] Elixir.Nerves.Network setup(wlan0, [ssid: "kaa7-red", key_mgmt: :"WPA-PSK", psk: "wpakey"])
[info] WiFiManager(wlan0) starting
[info] Register Nerves.NetworkInterface "wlan0"
[info] Done Registering
{:ok,
 {%{config: %{network_interface: %{"wlan0" => [ssid: "kaa7-red",
         key_mgmt: :"WPA-PSK", psk: "wpakey"]}}}, %{}}}
iex(3)> [info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, down) got event :ifup
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: false, is_multicast: true, is_running: false, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :down, stats: %{collisions: 0, multicast: 0, rx_bytes: 0, rx_dropped: 0, rx_errors: 0, rx_packets: 0, tx_bytes: 0, tx_dropped: 0, tx_errors: 0, tx_packets: 0}, type: :ethernet}
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: false, is_multicast: true, is_running: false, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :down, stats: %{collisions: 0, multicast: 0, rx_bytes: 0, rx_dropped: 0, rx_errors: 0, rx_packets: 0, tx_bytes: 0, tx_dropped: 0, tx_errors: 0, tx_packets: 0}, type: :ethernet}
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: false, is_multicast: true, is_running: false, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :down, stats: %{collisions: 0, multicast: 0, rx_bytes: 0, rx_dropped: 0, rx_errors: 0, rx_packets: 0, tx_bytes: 0, tx_dropped: 0, tx_errors: 0, tx_packets: 0}, type: :ethernet}
[info] Register Nerves.WpaSupplicant "wlan0"
[info] Nerves.WpaSupplicant: sending 'REMOVE_NETWORK all'
[info] Nerves.WpaSupplicant: sending 'ADD_NETWORK'
[info] Nerves.WpaSupplicant: sending 'SET_NETWORK 0 key_mgmt WPA-PSK'
[info] Nerves.WpaSupplicant: sending 'SET_NETWORK 0 psk "wpakey"'
[info] Nerves.WpaSupplicant: sending 'SET_NETWORK 0 ssid "kaa7-red"'
[info] Nerves.WpaSupplicant: sending 'SELECT_NETWORK 0'
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, associate_wifi) got event :ifup
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, associate_wifi) got event :ifup
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, associate_wifi) got event :ifup
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SCAN-STARTED"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 0, "be:a9:20:6f:4d:77"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 1, "ac:a3:1e:78:98:c2"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 2, "ac:a3:1e:78:98:c3"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 3, "ac:a3:1e:78:98:c4"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 4, "ac:a3:1e:78:98:c5"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SCAN-RESULTS"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "Trying to associate with be:a9:20:6f:4d:77 (SSID='kaa7-red' freq=2412 MHz)"}
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: true, is_multicast: true, is_running: false, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :dormant, stats: %{collisions: 0, multicast: 0, rx_bytes: 3827, rx_dropped: 16, rx_errors: 0, rx_packets: 17, tx_bytes: 0, tx_dropped: 0, tx_errors: 0, tx_packets: 0}, type: :ethernet}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "Associated with be:a9:20:6f:4d:77"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SUBNET-STATUS-UPDATE status=0"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, associate_wifi) got event :ifup
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=US"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "Authentication with be:a9:20:6f:4d:77 timed out."}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0) wifi_disconnected
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :wifi_disconnected
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD"
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: false, is_multicast: true, is_running: false, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :down, stats: %{collisions: 0, multicast: 0, rx_bytes: 4857, rx_dropped: 22, rx_errors: 0, rx_packets: 23, tx_bytes: 840, tx_dropped: 0, tx_errors: 0, tx_packets: 8}, type: :ethernet}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SCAN-STARTED"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, associate_wifi) got event :ifup
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 5, "ac:a3:1e:78:98:c6"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 6, "ac:a3:1e:73:06:e4"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 7, "ac:a3:1e:78:98:c1"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SCAN-RESULTS"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "Trying to associate with be:a9:20:6f:4d:77 (SSID='kaa7-red' freq=2412 MHz)"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "Associated with be:a9:20:6f:4d:77"}
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: true, is_multicast: true, is_running: false, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :dormant, stats: %{collisions: 0, multicast: 0, rx_bytes: 7844, rx_dropped: 35, rx_errors: 0, rx_packets: 37, tx_bytes: 840, tx_dropped: 0, tx_errors: 0, tx_packets: 8}, type: :ethernet}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SUBNET-STATUS-UPDATE status=0"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, associate_wifi) got event :ifup
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=US"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[debug] Got Query: %DNS.Record{anlist: [], arlist: [{:dns_rr_opt, '.', :opt, 1440, 0, 0, 4500, <<0, 4, 0, 14, 0, 76, 172, 222, 72, 0, 17, 34, 166, 197, 182, 29, 209, 159>>}], header: %DNS.Header{aa: false, id: 0, opcode: :query, pr: false, qr: false, ra: false, rcode: 0, rd: false, tc: false}, nslist: [], qdlist: [%DNS.Query{class: :in, domain: '_airport._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_airplay._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_raop._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_ippusb._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_uscan._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_uscans._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_scanner._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_ipp._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_ipps._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_printer._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_pdl-datastream._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_ptp._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_apple-mobdev._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '8f8d07cc._sub._apple-mobdev2._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_privet._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_afpovertcp._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_smb._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_rfb._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_adisk._tcp.local', type: :ptr}, %DNS.Query{class: :in, domain: '_googlecast._tcp.local', type: :ptr}]}
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "Authentication with be:a9:20:6f:4d:77 timed out."}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0) wifi_disconnected
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :wifi_disconnected
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SSID-TEMP-DISABLED id=0 ssid=\"kaa7-red\" auth_failures=1 duration=10 reason=CONN_FAILED"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD"
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: false, is_multicast: true, is_running: false, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :down, stats: %{collisions: 0, multicast: 0, rx_bytes: 8713, rx_dropped: 40, rx_errors: 0, rx_packets: 42, tx_bytes: 840, tx_dropped: 0, tx_errors: 0, tx_packets: 8}, type: :ethernet}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SCAN-STARTED"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, associate_wifi) got event :ifup
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:"CTRL-EVENT-BSS-ADDED", 8, "ac:a3:1e:78:98:c0"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SCAN-RESULTS"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SCAN-STARTED"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SCAN-RESULTS"
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SSID-REENABLED id=0 ssid=\"kaa7-red\""
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "Trying to associate with be:a9:20:6f:4d:77 (SSID='kaa7-red' freq=2412 MHz)"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "Associated with be:a9:20:6f:4d:77"}
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: true, is_multicast: true, is_running: false, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :dormant, stats: %{collisions: 0, multicast: 0, rx_bytes: 16264, rx_dropped: 70, rx_errors: 0, rx_packets: 73, tx_bytes: 840, tx_dropped: 0, tx_errors: 0, tx_packets: 8}, type: :ethernet}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-SUBNET-STATUS-UPDATE status=0"
[info] nerves_network_interface received :ifchanged and %{ifname: "wlan0", index: 4, is_broadcast: true, is_lower_up: true, is_multicast: true, is_running: true, is_up: true, mac_address: "b8:27:eb:12:a8:08", mac_broadcast: "ff:ff:ff:ff:ff:ff", mtu: 1500, operstate: :up, stats: %{collisions: 0, multicast: 0, rx_bytes: 16419, rx_dropped: 70, rx_errors: 0, rx_packets: 74, tx_bytes: 1136, tx_dropped: 0, tx_errors: 0, tx_packets: 10}, type: :ethernet}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, associate_wifi) got event :ifup
[info] WiFiManager.EventHandler(wlan0): ignoring event: {:INFO, "WPA: Key negotiation completed with be:a9:20:6f:4d:77 [PTK=CCMP GTK=CCMP]"}
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :noop
[info] WiFiManager.EventHandler(wlan0) wifi_connected
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, associate_wifi) got event :wifi_connected
[info] WiFiManager.EventHandler(wlan0): ignoring event: :"CTRL-EVENT-REGDOM-CHANGE init=COUNTRY_IE type=COUNTRY alpha2=US"
[debug] udhcpc: deconfigure wlan0
[info] Nerves.WpaSupplicant - WiFiManager(wlan0, dhcp) got event :noop
[info] WiFiManager.EventHandler(wlan0) ifup
[info] Nerves.NetworkInterface - WiFiManager(wlan0, dhcp) got event :ifup
[info] DHCPManager.EventHandler(wlan0) udhcpc :deconfig
[debug] udhcpc: bound wlan0: IP=172.20.10.9, dns="172.20.10.1"
[info] DHCPManager.EventHandler(wlan0) udhcpc :bound
HTTPoison.get("http://api.ipify.org")
{:ok,
 %HTTPoison.Response{body: "70.199.142.191",
  headers: [{"Server", "Cowboy"}, {"Connection", "keep-alive"},
   {"Access-Control-Allow-Origin", "*"}, {"Content-Type", "text/plain"},
   {"Date", "Thu, 07 Sep 2017 03:37:08 GMT"}, {"Content-Length", "14"},
   {"Via", "1.1 vegur"}], request_url: "http://api.ipify.org",
  status_code: 200}}
iex(4)> Nerves.Network.teardown "wlan0"
[debug] Elixir.Nerves.Network teardown(wlan0)
{:ok,
 {%{},
  %{config: %{network_interface: %{"wlan0" => [ssid: "kaa7-red",
         key_mgmt: :"WPA-PSK", psk: "wpakey"]}}}}}
iex(5)> HTTPoison.get("http://api.ipify.org")
{:ok,
 %HTTPoison.Response{body: "70.199.142.191",
  headers: [{"Server", "Cowboy"}, {"Connection", "keep-alive"},
   {"Access-Control-Allow-Origin", "*"}, {"Content-Type", "text/plain"},
   {"Date", "Thu, 07 Sep 2017 03:37:22 GMT"}, {"Content-Length", "14"},
   {"Via", "1.1 vegur"}], request_url: "http://api.ipify.org",
  status_code: 200}}
iex(6)> Nerves.Network.status "wlan0"
nil
iex(7)> HTTPoison.get("http://api.ipify.org")
{:ok,
 %HTTPoison.Response{body: "70.199.142.191",
  headers: [{"Server", "Cowboy"}, {"Connection", "keep-alive"},
   {"Access-Control-Allow-Origin", "*"}, {"Content-Type", "text/plain"},
   {"Date", "Thu, 07 Sep 2017 03:37:35 GMT"}, {"Content-Length", "14"},
   {"Via", "1.1 vegur"}], request_url: "http://api.ipify.org",
  status_code: 200}}

This issue is sort of a duplicate of #22 and #26
I'm going to leave it open, but they will likely both be taken care of at the same time.

Should be fixed in #97 but another PR is open #98 to finalize this.