Skip to content
Snippets Groups Projects

Support for dispatchers reporting connection/disconnection events

1 unresolved thread

This allows users or packages to include custom scripts under /etc/ModemManager/connection.d (for users) or /usr/lib/ModemManager/connection.d (for packages) so that they are executed whenever bearers are connected or disconnected.

The scripts will receive 4 arguments:

  • Modem DBus path
  • Bearer DBus path
  • Data interface name
  • Status string: "connected" or "disconnected"

This will help us solve https://github.com/openwrt/openwrt/issues/8368

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • added 19 commits

    • f7b90f9f...afd3ce86 - 13 commits from branch mobile-broadband:main
    • ebd3aa94 - dispatcher: new generic object to handle script dispatchers
    • 7e018cf4 - dispatcher-fcc-unlock: inherit from the base dispatcher object
    • c2c19140 - dispatcher-connection: new dispatcher for connection status scripts
    • 96632122 - base-bearer: integrate connection status dispatcher scripts
    • 512b34dd - build: rename directory where fcc unlocks are kept
    • b67c6ff9 - data: add example connection dispatcher

    Compare with previous version

    • With these changes, and the following script installed under /usr/lib/ModemManager/connection.d/10-report-down, the openwrt netifd based setup can properly detect network-initiated disconnections.

      #!/bin/sh
      
      # SPDX-License-Identifier: CC0-1.0
      # 2022 Aleksander Morgado <aleksander@aleksander.es>
      #
      # Automatically report to netifd that the underlying modem
      # is really disconnected
      #
      # require program name and at least 4 arguments
      [ $# -lt 4 ] && exit 1
      
      MODEM_PATH="$1"
      BEARER_PATH="$2"
      INTERFACE="$3"
      STATE="$4"
      
      [ "${STATE}" = "disconnected" ] || exit 0
      
      . /usr/share/ModemManager/modemmanager.common
      . /lib/netifd/netifd-proto.sh
      INCLUDE_ONLY=1 . /lib/netifd/proto/modemmanager.sh
      
      MODEM_STATUS=$(mmcli --modem="${MODEM_PATH}" --output-keyvalue)
      [ -n "${MODEM_STATUS}" ] || exit 1
      
      MODEM_DEVICE=$(modemmanager_get_field "${MODEM_STATUS}" "modem.generic.device")
      [ -n "${MODEM_DEVICE}" ] || exit 2
      
      CFG=$(mm_get_modem_config "${MODEM_DEVICE}")
      [ -n "${CFG}" ] || exit 3
      
      logger -t "modemmanager" "interface ${CFG} (network device ${INTERFACE}) ${STATE}"
      proto_init_update $INTERFACE 0
      proto_send_update $CFG
      exit 0
      Edited by Aleksander Morgado
    • Without the new dispatch script we could see how netifd was not properly notified of network-initiated disconnections:

      root@OpenWrt:~# ifup wwan
      
      root@OpenWrt:~# ip addr show dev wwan0
      5: wwan0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN qlen 1000
          link/[65534] 
          inet 10.121.148.171/29 brd 10.121.148.175 scope global wwan0
             valid_lft forever preferred_lft forever
          inet6 fe80::cf29:8f18:f7d4:ec10/64 scope link flags 800 
             valid_lft forever preferred_lft forever
      
      // simulate network-initiated disconnection by manually disconnecting the bearer
      
      root@OpenWrt:~# mmcli -m a -K | grep bearers
      modem.generic.bearers.length                    : 1
      modem.generic.bearers.value[1]                  : /org/freedesktop/ModemManager1/Bearer/15
      
      root@OpenWrt:~# mmcli -b 15 --disconnect
      successfully disconnected the bearer
      
      // network interface still has IP settings (wrong!)
      
      root@OpenWrt:~# ip addr show dev wwan0
      5: wwan0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN qlen 1000
          link/[65534] 
          inet 10.121.148.171/29 brd 10.121.148.175 scope global wwan0
             valid_lft forever preferred_lft forever
          inet6 fe80::cf29:8f18:f7d4:ec10/64 scope link flags 800 
             valid_lft forever preferred_lft forever
      
      // interface status still reports connected (wrong!)
      
      root@OpenWrt:~# ifstatus wwan
      {
      	"up": true,
      	"pending": false,
      	"available": true,
      	"autostart": true,
      	"dynamic": false,
      	"uptime": 52,
      	"l3_device": "wwan0",
      	"proto": "modemmanager",
              .....

      After installing the new connection dispatcher script, we can see how netifd gets notified about the disconnection successfully:

      root@OpenWrt:~# ifup wwan
      
      root@OpenWrt:~# ip addr show dev wwan0
      5: wwan0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN qlen 1000
          link/[65534] 
          inet 10.120.109.253/30 brd 10.120.109.255 scope global wwan0
             valid_lft forever preferred_lft forever
          inet6 fe80::cf29:8f18:f7d4:ec10/64 scope link flags 800 
             valid_lft forever preferred_lft forever
      
      // simulate network-initiated disconnection by manually disconnecting the bearer
      
      root@OpenWrt:~# mmcli -m a -K | grep bearers
      modem.generic.bearers.length                    : 1
      modem.generic.bearers.value[1]                  : /org/freedesktop/ModemManager1/Bearer/13
      
      root@OpenWrt:~# mmcli -b 13 --disconnect
      successfully disconnected the bearer
      
      // network interface doesn't have IP settings (right!)
      
      root@OpenWrt:~# ip addr show dev wwan0
      5: wwan0: <POINTOPOINT,MULTICAST,NOARP> mtu 1500 qdisc fq_codel state DOWN qlen 1000
          link/[65534] 
      
      // interface status is disconnected (right!)
      
      root@OpenWrt:~# ifstatus wwan
      {
      	"up": false,
      	"pending": true,
      	"available": true,
      	"autostart": true,
      	"dynamic": false,
      	"proto": "modemmanager",
      	"data": {
      		
      	}
      }
      Edited by Aleksander Morgado
    • Please register or sign in to reply
  • added 16 commits

    • b67c6ff9...1fec1cd3 - 10 commits from branch mobile-broadband:main
    • 01c8edf6 - dispatcher: new generic object to handle script dispatchers
    • e188a77e - dispatcher-fcc-unlock: inherit from the base dispatcher object
    • e8612671 - dispatcher-connection: new dispatcher for connection status scripts
    • 2dafb32d - base-bearer: integrate connection status dispatcher scripts
    • 99232154 - build: rename directory where fcc unlocks are kept
    • 7960b365 - data: add example connection dispatcher

    Compare with previous version

  • Aleksander Morgado approved this merge request

    approved this merge request

  • Aleksander Morgado enabled an automatic merge when the pipeline for 7960b365 succeeds

    enabled an automatic merge when the pipeline for 7960b365 succeeds

Please register or sign in to reply
Loading