Topic: How does hotplug work for network interfaces?
I'm trying to wrap my mind around the full sequence of events from an interface coming up (or its address changing) to the scripts in /etc/hotplug.d/iface being called. I'm specifically interested in this for ddns purposes (ddns-scripts packages drops a 25-ddns script there), but the discussion should apply more generally.
I start in the kernel, where subsystems can inject a uevent using kobject_uevent:
http://lxr.linux.no/linux+v3.12.6/lib/k … ent.c#L322
That takes an enum for the action, which is stringified according to this LUT for inclusion in the netlink message as "ACTION=":
http://lxr.linux.no/linux+v3.12.6/lib/k … vent.c#L45
The possible values are: add, remove, change, move, online, offline.
I looked around linux/net/ for call sites of kobject_uevent and it seems like net only delivers add/remove for devices as a whole, plus change for a few protocol/driver specific cases like rfkill. No interface address change events? Anyway, let's continue..
From here procd appears to create a netlink socket and pump events out of it:
http://nbd.name/gitweb.cgi?p=luci2/proc … =HEAD#l451
There doesn't seem to be much event-specific handling in C code, but there is a mini domain-specific language (why a new language instead of bash or lua?) expressed in JSON that takes care of certain subsystems specially:
https://dev.openwrt.org/browser/trunk/p … ?rev=36994
netifd *also* creates a netlink socket and pumps events out of it:
http://nbd.name/gitweb.cgi?p=luci2/neti … =HEAD#l141
netifd seems to handle "add" and "remove" events only, using them to update internal state about device presence and to rebroadcast state changes to internal subscribers. I see calls to device_claim in alias.c, bridge.c, vlan.c, a few others. Do these events somehow end up on ubus? Are there any bash scripts (ala /etc/hotplug.d) executed as a result of these events? examples/hotplug-cmd seems to be a hotplug script, when does this come into play?
Going back to procd, the openwrt hotplug.json, for "net" events, runs /sbin/hotplug-call %SUBSYSTEM%. This runs the scripts in /etc/hotplug.d/net with environment from the uevent:
https://dev.openwrt.org/browser/trunk/p … =36994#L71
hotplug.json has no configuration for SUBSYSTEM=iface. Are these events swallowed? What about the "ifup" and "ifdown" values for ACTION? (these are documented on the wiki: http://wiki.openwrt.org/doc/techref/hotplug and used by the scripts in /etc/hotplug.d/iface) I'm starting to think SUBSYSTEM=iface may not actually exist..
Does uevent deliver events only for device add/remove, or also when an interface alias is created? What about when the addresses of an interface change? I tried answering some of these questions by running 'strace -f -p 1' (stracing procd) and bringing up an alias of lo (ifconfig lo:1 220.127.116.11 netmask 255.255.255.0) but it didn't seem to get any events. I also tried stracing netifd, again with no visible effects. I can't easily play with the other interface on this router because it's in active use.
The reason I'm doing this is I suspect ddns-scripts is not being triggered when my WAN interface gets an IP. It has the following script in /etc/hotplug.d/iface/25-ddns:
if [ "$ACTION" = "ifup" ]; then
In my case the WAN proto is DHCP - I want an event when WAN gets an IP (*after* the underlying network device has come up). What is the best hook to trigger for this? I have another router that uses PPP on wan so I'm looking for a generic solution.