From 94871ce0500fd2eace62c1b09a1402dd3bcdc2c1 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Sun, 15 Dec 2024 15:57:05 +1000 Subject: [PATCH] nrf_modem_lib: lte_net_if: query actual link MTU Update the network interface MTU before raising the connectivity event, so that the MTU as queried by downstream users is correct, instead of an assumed value based on IPv6 required minimums. Signed-off-by: Jordan Yates --- .../releases/release-notes-changelog.rst | 2 +- lib/nrf_modem_lib/lte_net_if/lte_net_if.c | 18 +++++++++++++++++- lib/nrf_modem_lib/nrf9x_sockets.c | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 72ef9d8e1fca..f666a3d4bfd4 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -443,7 +443,7 @@ Security libraries Modem libraries --------------- -|no_changes_yet_note| +* Updated the :ref:`nrf_modem_lib_lte_net_if` to automatically set the actual link :term:`Maximum Transmission Unit (MTU)` on the network interface when PDN connectivity is gained. Multiprotocol Service Layer libraries ------------------------------------- diff --git a/lib/nrf_modem_lib/lte_net_if/lte_net_if.c b/lib/nrf_modem_lib/lte_net_if/lte_net_if.c index 15476b1a400b..5ac78e85a6b3 100644 --- a/lib/nrf_modem_lib/lte_net_if/lte_net_if.c +++ b/lib/nrf_modem_lib/lte_net_if/lte_net_if.c @@ -60,13 +60,29 @@ void lte_net_if_modem_fault_handler(void) net_if_dormant_on(iface_bound); } +static uint16_t pdn_mtu(void) +{ + unsigned int mtu = 0; + int rc; + + rc = pdn_dynamic_params_get(0, NULL, NULL, &mtu); + if ((rc != 0) || (mtu == 0)) { + LOG_WRN("MTU query failed, error: %d, MTU: %d", rc, mtu); + /* Fallback to the minimum value that IPv4 is required to support */ + mtu = NET_IPV4_MTU; + } + LOG_DBG("Network MTU: %d", mtu); + return mtu; +} + /* Called when we detect LTE connectivity has been gained. * - * Marks the iface as active and cancels any pending timeout. + * Queries the network MTU, marks the iface as active, and cancels any pending timeout. */ static void become_active(void) { LOG_DBG("Becoming active"); + net_if_set_mtu(iface_bound, pdn_mtu()); net_if_dormant_off(iface_bound); k_work_cancel_delayable(&connection_timeout_work); } diff --git a/lib/nrf_modem_lib/nrf9x_sockets.c b/lib/nrf_modem_lib/nrf9x_sockets.c index a593b22222f0..da8c84266366 100644 --- a/lib/nrf_modem_lib/nrf9x_sockets.c +++ b/lib/nrf_modem_lib/nrf9x_sockets.c @@ -1168,7 +1168,7 @@ static struct offloaded_if_api nrf9x_iface_offload_api = { .enable = nrf9x_iface_enable, }; -/* TODO Get the actual MTU for the nRF9x LTE link. */ +/* Actual MTU for the nRF9x LTE link is handled by `lte_net_if.c` */ NET_DEVICE_OFFLOAD_INIT(nrf9x_socket, "nrf9x_socket", nrf9x_socket_offload_init, NULL,