mwarning / zerotier-openwrt

A OpenWrt package for ZeroTier One - Pull requests are welcome!
672 stars 140 forks source link

how to detect IP address assignment #66

Closed jfrogg closed 4 years ago

jfrogg commented 4 years ago

Is it possible programmatically detect the IP address assignment to ZeroTier device? I was thinking about something similar to checking IFUPDATE_ADDRESSES variable available in iface hotplug script. Currently the last ZeroTier event I can catch happens before the Internet connection is established which means that there is no IP on ztxxxxxxxx yet:

Mon Mar  9 20:48:29 2020 daemon.notice netifd: Interface 'ZT0' is enabled
Mon Mar  9 20:48:29 2020 daemon.notice netifd: Interface 'ZT0' is setting up now
Mon Mar  9 20:48:29 2020 daemon.notice netifd: Interface 'ZT0' is now up
Mon Mar  9 20:48:29 2020 daemon.notice netifd: Network device 'ztxxxxxxxx' link is up
Mon Mar  9 20:48:29 2020 daemon.notice netifd: Interface 'ZT0' has link connectivity
Mon Mar  9 20:48:29 2020 daemon.err zerotier-one[2209]: sendto: Network unreachable
Mon Mar  9 20:48:34 2020 user.notice URL-DEBUG: hotplug (iface): action='ifup' interface='ZT0'

Obviously one can run zerotier-cli (or ip -4 a show dev ...) in a loop and wait for IP address to pop up, however that does not look nice.

mwarning commented 4 years ago

I would go with a hotplug script. Keep in mind that there are different hotplug directories in /etc/hotplug.d. See https://openwrt.org/docs/guide-user/base-system/hotplug

jfrogg commented 4 years ago

Hotplug does not work here, at least for me, that is what I started from. As noted earlier, the last hotpug event happens much earlier than the Internet connection is established and IP address assigned to ztxxxxxxxx device. In other words, the 'ifup' below does not mean that the IP address is assigned: hotplug (iface): action='ifup' interface='ZT0'

mwarning commented 4 years ago

ok, then I do not know what to do. Maybe ZT supports some kind of notifications...

jfrogg commented 4 years ago

It looks like the notification mechanism is available internally, see example in 5.1.4 Handling events

ZTS_EVENT_NETIF_UP --- network=a09acf023be465c1, mac=73b7abcfc207, mtu=10000
ZTS_EVENT_ADDR_NEW_IP4 --- addr=11.7.7.184 (on network=a09acf023be465c1)
ZTS_EVENT_ADDR_NEW_IP6 --- addr=fda0:9acf:233:e4b0:7099:9309:4c9b:c3c7 (on network=a09acf023be465c1)
ZTS_EVENT_NODE_ONLINE, node=c4c7ba3cf
ZTS_EVENT_NETWORK_READY_IP4 --- network=a09acf023be465c1
ZTS_EVENT_NETWORK_READY_IP6 --- network=a09acf023be465c1

Don't know how to use this though.

mwarning commented 4 years ago

I do not think we find a solution here. Maybe open a ticket at github.com/zerotier?