tohojo / sqm-scripts

SQM scripts traffic shaper
http://www.bufferbloat.net/projects/cerowrt/wiki/Smart_Queue_Management
234 stars 64 forks source link

sqm-hotplug: 'ifname' replaced by 'device' #163

Closed efahl closed 1 year ago

efahl commented 1 year ago

In OpenWrt 22.03, network.$INTERFACE.ifname was removed and ifname was renamed to device, so the following code no longer functions properly:

https://github.com/tohojo/sqm-scripts/blob/master/platform/openwrt/sqm-hotplug#L3

More about this change in first warning box at https://openwrt.org/docs/guide-user/base-system/basic-networking

tohojo commented 1 year ago

Hmm, right; that code was a bit of a hack in the first place. Maybe moving to using the 'net' hotplug (as @moeller0 suggested back when it was added) will allow us to get rid of that hack entirely? 🤔

efahl commented 1 year ago

Yup, when I noticed the problem I started digging through the history and decided against the simple PR with a name change. The real issue looked much deeper than I was able to understand, hence my somewhat terse "it's busted."

moeller0 commented 1 year ago

I have been keeping a low profile on this, as I am still on turrisOS which as far as I can see has not yet made that change (being based on OpenWrt21). So I can not actually test any proposed changes for new functionality, only for backward compatibility...

tohojo commented 1 year ago

OK, to answer my own question, the 'net' hotplug event only gives us 'add' and 'remove' events, so we can't just substitute that. We'll have to query the device sections instead...

tohojo commented 1 year ago

@moeller0 and @efahl could you please test #164 and see if that works correctly (it's totally untested as I don't have a compatible config myself to test this on right now)...

moeller0 commented 1 year ago

I will be able to test the back-ward compatibility later this week, still on turrisOS which has not made the step to OpenWrt22. How do I properly test this? Instantiate sqm-scripts on a LAN interface, but do I force a hotplug event?

tohojo commented 1 year ago

ifup/ifdown should work I think :)

openwrtdiy commented 1 year ago

@moeller0 and @efahl could you please test #164 and see if that works correctly (it's totally untested as I don't have a compatible config myself to test this on right now)...

I just tested SQM with OpenWrt-23.05! Now submit the SQM system log

Mon Aug 21 14:16:39 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on wan, in: 85000 Kbps, out: 10000 Kbps Mon Aug 21 14:16:39 2023 user.notice SQM: piece_of_cake.qos was started on wan successfully Mon Aug 21 14:21:36 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:21:59 2023 user.notice SQM: Stopping SQM on wan Mon Aug 21 14:22:00 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on lan4, in: 37500 Kbps, out: 12500 Kbps Mon Aug 21 14:22:01 2023 user.notice SQM: piece_of_cake.qos was started on lan4 successfully Mon Aug 21 14:23:50 2023 user.notice SQM: Stopping SQM on lan4 Mon Aug 21 14:23:51 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on lan4, in: 12500 Kbps, out: 37500 Kbps Mon Aug 21 14:23:52 2023 user.notice SQM: piece_of_cake.qos was started on lan4 successfully Mon Aug 21 14:25:31 2023 user.notice SQM: Stopping SQM on lan4 Mon Aug 21 14:25:32 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on br-lan, in: 25000 Kbps, out: 12500 Kbps Mon Aug 21 14:25:32 2023 user.notice SQM: piece_of_cake.qos was started on br-lan successfully Mon Aug 21 14:26:45 2023 user.notice SQM: Stopping SQM on br-lan Mon Aug 21 14:26:45 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on br-lan, in: 12500 Kbps, out: 25000 Kbps Mon Aug 21 14:26:46 2023 user.notice SQM: piece_of_cake.qos was started on br-lan successfully Mon Aug 21 14:29:20 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:30:45 2023 user.notice SQM: Stopping SQM on br-lan Mon Aug 21 14:30:46 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on eth0, in: 37500 Kbps, out: 12500 Kbps Mon Aug 21 14:30:47 2023 user.notice SQM: piece_of_cake.qos was started on eth0 successfully Mon Aug 21 14:32:22 2023 user.notice SQM: Stopping SQM on eth0 Mon Aug 21 14:32:22 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on lan4, in: 25000 Kbps, out: 37500 Kbps Mon Aug 21 14:32:23 2023 user.notice SQM: piece_of_cake.qos was started on lan4 successfully Mon Aug 21 14:33:22 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:33:24 2023 kern.info kernel: [ 1280.676382] mt7530-mdio mdio-bus:1f lan4: Link is Down Mon Aug 21 14:33:24 2023 kern.info kernel: [ 1280.683659] br-lan: port 4(lan4) entered disabled state Mon Aug 21 14:33:24 2023 daemon.notice netifd: Network device 'lan4' link is down Mon Aug 21 14:33:25 2023 daemon.notice netifd: bridge 'br-lan' link is down Mon Aug 21 14:33:25 2023 daemon.notice netifd: Interface 'lan' has link connectivity loss Mon Aug 21 14:33:25 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:35:08 2023 kern.info kernel: [ 1385.418297] mt7530-mdio mdio-bus:1f lan4: Link is Up - 1Gbps/Full - flow control off Mon Aug 21 14:35:08 2023 kern.info kernel: [ 1385.426160] br-lan: port 4(lan4) entered blocking state Mon Aug 21 14:35:08 2023 kern.info kernel: [ 1385.431375] br-lan: port 4(lan4) entered forwarding state Mon Aug 21 14:35:08 2023 daemon.notice netifd: Network device 'lan4' link is up Mon Aug 21 14:35:08 2023 daemon.notice netifd: bridge 'br-lan' link is up Mon Aug 21 14:35:08 2023 daemon.notice netifd: Interface 'lan' has link connectivity Mon Aug 21 14:35:09 2023 kern.info kernel: [ 1386.235835] mt7530-mdio mdio-bus:1f lan4: Link is Down Mon Aug 21 14:35:09 2023 kern.info kernel: [ 1386.242751] br-lan: port 4(lan4) entered disabled state Mon Aug 21 14:35:09 2023 daemon.notice netifd: Network device 'lan4' link is down Mon Aug 21 14:35:09 2023 daemon.notice netifd: bridge 'br-lan' link is down Mon Aug 21 14:35:09 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:35:09 2023 daemon.notice netifd: Interface 'lan' has link connectivity loss Mon Aug 21 14:35:12 2023 kern.info kernel: [ 1389.195747] mt7530-mdio mdio-bus:1f lan4: Link is Up - 1Gbps/Full - flow control rx/tx Mon Aug 21 14:35:12 2023 kern.info kernel: [ 1389.203736] br-lan: port 4(lan4) entered blocking state Mon Aug 21 14:35:12 2023 kern.info kernel: [ 1389.208993] br-lan: port 4(lan4) entered forwarding state Mon Aug 21 14:35:12 2023 daemon.notice netifd: Network device 'lan4' link is up Mon Aug 21 14:35:12 2023 daemon.notice netifd: bridge 'br-lan' link is up Mon Aug 21 14:35:12 2023 daemon.notice netifd: Interface 'lan' has link connectivity Mon Aug 21 14:35:12 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:35:13 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:35:16 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:35:20 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:35:29 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:37:15 2023 authpriv.info dropbear[6556]: Child connection from 192.168.95.239:12172 Mon Aug 21 14:37:17 2023 authpriv.notice dropbear[6556]: Auth succeeded with blank password for 'root' from 192.168.95.239:12172 Mon Aug 21 14:41:36 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:47:45 2023 authpriv.info dropbear[6624]: Child connection from 192.168.95.239:12207 Mon Aug 21 14:47:46 2023 authpriv.notice dropbear[6624]: Auth succeeded with blank password for 'root' from 192.168.95.239:12207 Mon Aug 21 14:50:45 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 14:51:42 2023 authpriv.info dropbear[6556]: Exit (root) from <192.168.95.239:12172>: Exited normally Mon Aug 21 14:52:25 2023 user.notice SQM: Stopping SQM on lan4 Mon Aug 21 14:52:25 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on lan4, in: 25000 Kbps, out: 37500 Kbps Mon Aug 21 14:52:26 2023 user.notice SQM: piece_of_cake.qos was started on lan4 successfully Mon Aug 21 14:52:34 2023 authpriv.info dropbear[7142]: Child connection from 192.168.95.239:12218 Mon Aug 21 14:52:35 2023 authpriv.notice dropbear[7142]: Auth succeeded with blank password for 'root' from 192.168.95.239:12218 Mon Aug 21 14:52:35 2023 authpriv.info dropbear[6624]: Exit (root) from <192.168.95.239:12207>: Exited normally Mon Aug 21 14:52:51 2023 authpriv.info dropbear[7142]: Exit (root) from <192.168.95.239:12218>: Exited normally Mon Aug 21 14:53:50 2023 user.notice SQM: Stopping SQM on lan4 Mon Aug 21 14:53:56 2023 authpriv.info dropbear[7289]: Child connection from 192.168.95.239:12241 Mon Aug 21 14:53:56 2023 authpriv.notice dropbear[7289]: Auth succeeded with blank password for 'root' from 192.168.95.239:12241 Mon Aug 21 14:54:06 2023 authpriv.info dropbear[7289]: Exit (root) from <192.168.95.239:12241>: Exited normally Mon Aug 21 14:54:37 2023 daemon.info pppoe-server[7311]: Session 664 created for client 80:76:93:b4:36:c2 (10.67.2.152) on br-lan using Service-Name 'service-name1' Mon Aug 21 14:54:37 2023 daemon.info pppd[7311]: Plugin pppoe.so loaded. Mon Aug 21 14:54:37 2023 daemon.info pppd[7311]: PPPoE plugin from pppd 2.4.9 Mon Aug 21 14:54:37 2023 daemon.notice pppd[7311]: pppd 2.4.9 started by root, uid 0 Mon Aug 21 14:54:37 2023 daemon.warn pppd[7311]: Connected to 80:76:93:b4:36:c2 via interface br-lan Mon Aug 21 14:54:37 2023 daemon.info pppd[7311]: Using interface ppp663 Mon Aug 21 14:54:37 2023 daemon.notice pppd[7311]: Connect: ppp663 <--> br-lan Mon Aug 21 14:54:39 2023 daemon.notice pppd[7311]: peer from calling number 80:76:93:B4:36:C2 authorized Mon Aug 21 14:54:39 2023 daemon.notice pppd[7311]: local IP address 10.0.0.1 Mon Aug 21 14:54:39 2023 daemon.notice pppd[7311]: remote IP address 10.67.2.152 Mon Aug 21 14:54:39 2023 user.notice root: 2023-08-21_14:54:39 guest 10.67.2.152 ONLINE-USERS >>>>>> The script has been executed! Mon Aug 21 14:54:39 2023 user.notice root: guest SPEED-LIMIT >>>>>> The script has been executed! Mon Aug 21 14:54:48 2023 authpriv.info dropbear[7399]: Child connection from 10.67.2.152:12249 Mon Aug 21 14:54:48 2023 authpriv.notice dropbear[7399]: Auth succeeded with blank password for 'root' from 10.67.2.152:12249 Mon Aug 21 14:57:39 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on ppp663, in: 12500 Kbps, out: 37500 Kbps Mon Aug 21 14:57:39 2023 user.notice SQM: piece_of_cake.qos was started on ppp663 successfully Mon Aug 21 14:58:46 2023 daemon.warn odhcpd[1864]: No default route present, overriding ra_lifetime! Mon Aug 21 15:00:12 2023 authpriv.info dropbear[7876]: Child connection from 10.67.2.152:12322 Mon Aug 21 15:00:12 2023 authpriv.notice dropbear[7876]: Auth succeeded with blank password for 'root' from 10.67.2.152:12322 Mon Aug 21 15:00:53 2023 daemon.info pppd[7311]: LCP terminated by peer (AoWM-&^@<M-Mt^@^@^@^@) Mon Aug 21 15:00:53 2023 daemon.info pppd[7311]: Connect time 6.3 minutes. Mon Aug 21 15:00:53 2023 daemon.info pppd[7311]: Sent 72307416 bytes, received 25440885 bytes. Mon Aug 21 15:00:53 2023 daemon.notice pppd[7311]: Modem hangup Mon Aug 21 15:00:53 2023 daemon.notice pppd[7311]: Connection terminated. Mon Aug 21 15:00:53 2023 daemon.info pppoe-server[2088]: Sent PADT Mon Aug 21 15:00:53 2023 user.notice root: 2023-08-21_15:00:53 guest 10.67.2.152 OFFLINE-USERS >>>>>> The script has been executed! Mon Aug 21 15:00:53 2023 user.notice SQM: Stopping SQM on ppp663 Mon Aug 21 15:00:53 2023 daemon.info pppd[7311]: Terminating on signal 15 Mon Aug 21 15:00:53 2023 daemon.info pppd[7311]: Exit. Mon Aug 21 15:00:53 2023 daemon.info pppoe-server[2088]: Session 664 closed for client 80:76:93:b4:36:c2 (10.67.2.152) on br-lan Mon Aug 21 15:00:53 2023 user.notice SQM: ERROR: cmd_wrapper: tc: FAILURE (1): /sbin/tc qdisc del dev ppp663 ingress Mon Aug 21 15:00:53 2023 user.notice SQM: ERROR: cmd_wrapper: tc: LAST ERROR: Cannot find device "ppp663" Mon Aug 21 15:00:53 2023 user.notice SQM: ERROR: cmd_wrapper: tc: FAILURE (1): /sbin/tc qdisc del dev ppp663 root Mon Aug 21 15:00:53 2023 user.notice SQM: ERROR: cmd_wrapper: tc: LAST ERROR: Cannot find device "ppp663" Mon Aug 21 15:00:53 2023 user.notice root: guest SPEED-LIMIT >>>>>> The script has been executed! Mon Aug 21 15:01:00 2023 daemon.info pppoe-server[7972]: Session 650 created for client 80:76:93:b4:36:c2 (10.67.2.138) on br-lan using Service-Name 'service-name1' Mon Aug 21 15:01:00 2023 daemon.info pppd[7972]: Plugin pppoe.so loaded. Mon Aug 21 15:01:00 2023 daemon.info pppd[7972]: PPPoE plugin from pppd 2.4.9 Mon Aug 21 15:01:00 2023 daemon.notice pppd[7972]: pppd 2.4.9 started by root, uid 0 Mon Aug 21 15:01:00 2023 daemon.warn pppd[7972]: Connected to 80:76:93:b4:36:c2 via interface br-lan Mon Aug 21 15:01:00 2023 daemon.info pppd[7972]: Using interface ppp649 Mon Aug 21 15:01:00 2023 daemon.notice pppd[7972]: Connect: ppp649 <--> br-lan Mon Aug 21 15:01:02 2023 daemon.notice pppd[7972]: peer from calling number 80:76:93:B4:36:C2 authorized Mon Aug 21 15:01:02 2023 daemon.notice pppd[7972]: local IP address 10.0.0.1 Mon Aug 21 15:01:02 2023 daemon.notice pppd[7972]: remote IP address 10.67.2.138 Mon Aug 21 15:01:02 2023 user.notice root: 2023-08-21_15:01:02 guest 10.67.2.138 ONLINE-USERS >>>>>> The script has been executed! Mon Aug 21 15:01:02 2023 user.notice SQM: Starting SQM script: piece_of_cake.qos on ppp649, in: 3750 Kbps, out: 3750 Kbps Mon Aug 21 15:01:02 2023 authpriv.info dropbear[8121]: Child connection from 10.67.2.138:12327 Mon Aug 21 15:01:03 2023 user.notice SQM: piece_of_cake.qos was started on ppp649 successfully Mon Aug 21 15:01:03 2023 user.notice root: guest SPEED-LIMIT >>>>>> The script has been executed! Mon Aug 21 15:01:03 2023 authpriv.notice dropbear[8121]: Auth succeeded with blank password for 'root' from 10.67.2.138:12327 Mon Aug 21 15:02:41 2023 daemon.info pppd[7972]: LCP terminated by peer (UM-R^HM-^^^@<M-Mt^@^@^@^@) Mon Aug 21 15:02:41 2023 daemon.info pppd[7972]: Connect time 1.7 minutes. Mon Aug 21 15:02:41 2023 daemon.info pppd[7972]: Sent 8181142 bytes, received 8012665 bytes. Mon Aug 21 15:02:41 2023 daemon.notice pppd[7972]: Modem hangup Mon Aug 21 15:02:41 2023 daemon.info pppoe-server[2088]: Sent PADT Mon Aug 21 15:02:41 2023 daemon.notice pppd[7972]: Connection terminated. Mon Aug 21 15:02:41 2023 user.notice root: 2023-08-21_15:02:41 guest 10.67.2.138 OFFLINE-USERS >>>>>> The script has been executed! Mon Aug 21 15:02:41 2023 daemon.info pppd[7972]: Terminating on signal 15 Mon Aug 21 15:02:41 2023 daemon.info pppd[7972]: Exit. Mon Aug 21 15:02:41 2023 daemon.info pppoe-server[2088]: Session 650 closed for client 80:76:93:b4:36:c2 (10.67.2.138) on br-lan Mon Aug 21 15:02:41 2023 user.notice SQM: Stopping SQM on ppp649 Mon Aug 21 15:02:41 2023 user.notice SQM: ERROR: cmd_wrapper: tc: FAILURE (1): /sbin/tc qdisc del dev ppp649 ingress Mon Aug 21 15:02:41 2023 user.notice SQM: ERROR: cmd_wrapper: tc: LAST ERROR: Cannot find device "ppp649" Mon Aug 21 15:02:41 2023 user.notice SQM: ERROR: cmd_wrapper: tc: FAILURE (1): /sbin/tc qdisc del dev ppp649 root Mon Aug 21 15:02:41 2023 user.notice SQM: ERROR: cmd_wrapper: tc: LAST ERROR: Cannot find device "ppp649" Mon Aug 21 15:02:42 2023 user.notice root: guest SPEED-LIMIT >>>>>> The script has been executed! Mon Aug 21 15:03:00 2023 authpriv.info dropbear[8403]: Child connection from 192.168.95.239:12407 Mon Aug 21 15:03:01 2023 authpriv.notice dropbear[8403]: Auth succeeded with blank password for 'root' from 192.168.95.239:12407 Mon Aug 21 15:03:14 2023 authpriv.info dropbear[8417]: Child connection from 192.168.95.239:12410 Mon Aug 21 15:03:14 2023 authpriv.notice dropbear[8417]: Auth succeeded with blank password for 'root' from 192.168.95.239:12410

efahl commented 1 year ago

Well, I'm not set up to test, but I did a deep-dive code review and it looks good to me. I then cut out the new code and did some unit testing on the functions, hardcoding the values of DEVICE and INTERFACE to existing and non-existent values, all worked as I expected, for what that's worth...

tohojo commented 1 year ago

Awesome, thank you for testing! I'll merge this and see if we can still get it into OpenWrt 23.05 before the final release :)