Skip to content

Add ModemManager integration with networkd#38855

Merged
yuwata merged 1 commit intosystemd:mainfrom
andr2000:main-pr-mm
Feb 16, 2026
Merged

Add ModemManager integration with networkd#38855
yuwata merged 1 commit intosystemd:mainfrom
andr2000:main-pr-mm

Conversation

@andr2000
Copy link
Contributor

@andr2000 andr2000 commented Sep 8, 2025

  1. ModemManager (MM) integration consists of two big parts: things
    we do on the networkd start and what we do during the run-time.

  2. Initialization phase
    2.1. Wait for networkd to connect to D-Bus
    2.2. Setup D-Bus handlers for the essential signals:

    • /org/freedesktop/DBus, org.freedesktop.DBus, NameOwnerChanged - to track MM serice availability
    • /org/freedesktop/ModemManager1, org.freedesktop.DBus.ObjectManager Interfaces{Added|Removed} -
      to track modem plug/unplug
    • /org/freedesktop/ModemManager1/Bearer org.freedesktop.DBus.Properties PropertiesChanged
      to track bearers
      2.3. Check if MM service is yet available: for that call /org/freedesktop/DBus, org.freedesktop.DBus
      ListNames method and see if MM is available. If it is not, then wait for the NameOwnerChanged
      signal and see when it is; finish initialization phase.
      2.4. If MM is available - enumerate modems, see p.4.
      2.5. Finish initialization phase.
  3. Run-time
    3.1. During the run-time we track MM service avaialbility. When it is gone we remove all the modems
    and bearers.
    3.2. When MM is connected we do modem enumeration to get in sync with their current state.
    3.3. If a modem was removed we also remove all its bearers.
    3.4. If a modem was added we try to start a simple connect.
    3.5. If connection was interrupted, e.g. modem changed its network connection from connected state
    we start an automatic reconnect.

  4. Modem enumeration proces
    4.1. Modem enumeration is done by calling GetManagedObjects.
    4.2. By receiving managed objects we try to instantiate all new modems found.
    4.3. For that we inspect all bearers available for that modem and add all new bearers found.
    4.4. We also read modem ports to detect WWAN interface name assigned to this modem, e.g. "wwan0" etc.
    N.B. As we only get the interface name known that late and the corresponding .network file was
    already used by the networkd to match interfaces etc. it is not possible
    to do things like matching APN to .network and so on.

  5. Simple (re)connect
    5.1. Connection is done by calling org.freedesktop.ModemManager1.Modem.Simple Connect method for
    the relevant modem.
    5.2. It is possible that at the time of connect the operation may fail. For that reason and to ensure
    we are always connected we employ a periodic timer which will re-try connection hoping it will
    be successful this time or when modem has recovered after an error state and so on.
    5.3. networkd will automatically start reconnection if any external entity disconnects modem from
    the network.

  6. Open questions
    6.1. WWAN interfaces cannot be configured now with the existing .network file:

    • ModemSimpleConnectProps - simple connect properties used to (re)connect: I've put
      this under [Network] section for now. Is there a better name for that and location?
    • RouteMetric - as we configure address/route dynamically (provided by the modem), we
      do not use any section of .network to define/alter relevant parts. This patch uses
      [DHCP]:RouteMetric for that for now.
    • I have a use-case when I do not want the default gateway to be set for WWAN inteface.
      I use [DHCPv4]:UseGateway now which probably needs a better way of defining.
      6.2. Use MM header files - add MM as a build dependency?

@andr2000
Copy link
Contributor Author

andr2000 commented Sep 8, 2025

This PR is heavily based on the work done by Yu Watanabe (#22315) and addresses #20370

It has number of open questions, so it is better viewed as RFC for now

@andr2000 andr2000 force-pushed the main-pr-mm branch 3 times, most recently from 6e7df9a to 1407daa Compare September 10, 2025 05:04
@andr2000 andr2000 force-pushed the main-pr-mm branch 2 times, most recently from 4861500 to 16b9cb2 Compare September 15, 2025 05:15
@andr2000
Copy link
Contributor Author

I have tested the PR over the weekend with 3 modems making random modem disconnects (with usbreset utility), ModemManager restarts and disconnects with mmcli -m X --simple-disconnect.
I also used valgrind to test for leaks.
Everything went smooth, so I have squashed the issues found during clang/mkosi tests.

@andr2000 andr2000 force-pushed the main-pr-mm branch 5 times, most recently from 83fedb5 to 8031c0c Compare September 19, 2025 09:37
Copy link
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late review.
This is quite large and I only reviewed first third of the PR.

Thank you for working on this. Looks basically nice!

@yuwata yuwata added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Sep 26, 2025
@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Oct 3, 2025
@gizahNL
Copy link

gizahNL commented Feb 13, 2026

@andr2000: did you test with trying to change apn or other properties at runtime? I've been running (an earlier version of) your PR for a while, and ran into having to change the APN, the only way I've been able to do so effectively is by restarting ModemManager after changing the config file & notifying systemd of this. Not a real requirement for me (i've got a solid work around that's reliable), but very much a nice to have to be able to change the APN at runtime without having to fiddle with the services.
-edit-
I've done some testing. I can get away without restarting ModemManager if I manually delete the bearer(s) from the modem.

please check the latest as before that networkctl reload didn't work

I've just backported the current patchset to 257.8, and it indeed does now generate a new Bearer token. I do see the old bearer still listed via mmcli, does the current patchset disable/disconnect the stale bearer? Otherwise I'd argue it's better to delete it ;)

@yuwata
Copy link
Member

yuwata commented Feb 15, 2026

@andr2000 Sorry for late re-review. I addressed the comments by @keszybz and pushed the revised version.

@andr2000: did you test with trying to change apn or other properties at runtime? I've been running (an earlier version of) your PR for a while, and ran into having to change the APN, the only way I've been able to do so effectively is by restarting ModemManager after changing the config file & notifying systemd of this. Not a real requirement for me (i've got a solid work around that's reliable), but very much a nice to have to be able to change the APN at runtime without having to fiddle with the services.
-edit-
I've done some testing. I can get away without restarting ModemManager if I manually delete the bearer(s) from the modem.

please check the latest as before that networkctl reload didn't work

I've just backported the current patchset to 257.8, and it indeed does now generate a new Bearer token. I do see the old bearer still listed via mmcli, does the current patchset disable/disconnect the stale bearer? Otherwise I'd argue it's better to delete it ;)

Let's address this after this merged.

@yuwata yuwata added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed new-feature and removed resolve systemctl build-system util-lib tests sd-boot/sd-stub/bootctl random-seed meson squash-on-merge busctl please-review PR is ready for (re-)review by a maintainer documentation labels Feb 15, 2026
@bluca bluca added ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR and removed good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed labels Feb 15, 2026
[Match]
Name=wwan*

[Network]
LLDP=no
LinkLocalAddressing=no
IPv6AcceptRA=no

[ModemManager]
SimpleConnectPropertie]s=apn=internet ip-type=ipv4 allow-roaming=no pin=1111 operator-id=25503
RouteMetric=200
UseGateway=yes

Co-authored-by: Yu Watanabe <[email protected]>
@yuwata yuwata added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR labels Feb 16, 2026
@yuwata yuwata merged commit f8a4c3d into systemd:main Feb 16, 2026
49 of 56 checks passed
@github-actions github-actions bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Integration with ModemManager

6 participants