How to automatically ifup wan after USB disconnect?

I have an Ateros device with a Huawei modem at USB port. Because of a known hardware bug, USB port randomly disconnects for a second. After that the modem is detected again, but netifd doesn't ifup wan.

If I manually send "ifup wan", all works well. What is the best way to automate the process?

I don't like a dumb script with pinging, etc.

Here is the log

Mon Jul  2 10:32:43 2018 kern.info kernel: [74062.319887] usb 1-1: USB disconnect, device number 20
Mon Jul  2 10:32:43 2018 kern.info kernel: [74062.324007] option1 ttyUSB0: GSM modem (1-port) converter now disconnected from ttyUSB0
Mon Jul  2 10:32:43 2018 kern.info kernel: [74062.331721] option 1-1:1.0: device disconnected
Mon Jul  2 10:32:43 2018 kern.info kernel: [74062.336354] huawei_cdc_ncm 1-1:1.1 wwan0: unregister 'huawei_cdc_ncm' usb-ehci-platform-1, Huawei CDC NCM device
Mon Jul  2 10:32:44 2018 daemon.notice netifd: Interface 'wan_4' is disabled
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.697164] usb 1-1: new high-speed USB device number 21 using ehci-platform
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.863143] option 1-1:1.0: GSM modem (1-port) converter detected
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.868354] usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.911653] huawei_cdc_ncm 1-1:1.1: MAC-Address: 0c:5b:8f:27:9a:64
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.916473] huawei_cdc_ncm 1-1:1.1: setting rx_max = 16384
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.947122] huawei_cdc_ncm 1-1:1.1: setting tx_max = 16384
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.957368] huawei_cdc_ncm 1-1:1.1: NDP will be placed at end of frame for this device.
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.964347] huawei_cdc_ncm 1-1:1.1: cdc-wdm0: USB WDM device
Mon Jul  2 10:32:44 2018 kern.info kernel: [74062.970956] huawei_cdc_ncm 1-1:1.1 wwan0: register 'huawei_cdc_ncm' at usb-ehci-platform-1, Huawei CDC NCM device, 0c:5b:8f:27:9a:64
Mon Jul  2 10:32:44 2018 daemon.notice netifd: Interface 'wan_4' is enabled

How can I execute "ifup wan" after "Interface 'wan_4' is enabled"?

You could try placing a hotplug handler in /etc/hotplug.d/usb/ that reacts on ACTION=add or ACTION=remove to issue ifup wan.

Now I've set a debug script to hotplug.d to see if it really catches the event.

I wonder why /etc/hotplug.d/usbmisc/00-wwan.sh

doesn't contain ifup. Is it a bug. The "wwan" protocol in /etc/hotplug.d/usb/00-wwan.sh does contain it, but the NCM version doesn't.

Maybe adding

ifup $cfg

will do the job.

And why there are two scripts? One for all protos including wwan, and one for only wwan with specific ids. Is it a bug?