[PATCH] broadband-bearer: allow matching empty APN when looking for PDP CID
Dan Williams
dcbw at redhat.com
Mon Apr 30 15:59:07 UTC 2018
On Sat, 2018-04-28 at 10:38 +0200, Aleksander Morgado wrote:
> The PDP contexts that are found with an empty APN configured are
> right
> now used as placeholders that can be overwritten with the user
> provided APN if no direct match is found.
>
> We want to keep that logic in place, but for the case where we do get
> an empty APN requested by the user, we need to perform the full
> context match, so that the first PDP context matching the empty APN
> is
> used.
>
> Right now we're overwriting with the empty APN again the last PDP
> context found with an empty APN, which doesn't make much sense:
LGTM.
Dan
> Apr 27 08:15:21 ModemManager[4251]: <debug> Found '3' PDP
> contexts
> Apr 27 08:15:21 ModemManager[4251]: <debug> PDP context [cid=1]
> [type='ipv4'] [apn='']
> Apr 27 08:15:21 ModemManager[4251]: <debug> PDP context [cid=2]
> [type='ipv4'] [apn='broadband']
> Apr 27 08:15:21 ModemManager[4251]: <debug> PDP context
> [cid=15] [type='ipv4'] [apn='']
> Apr 27 08:15:21 ModemManager[4251]: <debug> Found PDP context
> with CID 1 and no APN
> Apr 27 08:15:21 ModemManager[4251]: <debug> Found PDP context
> with CID 15 and no APN
> Apr 27 08:15:21 ModemManager[4251]: <debug> (ttyUSB3) device open
> count is 3 (open)
> Apr 27 08:15:21 ModemManager[4251]: <debug> (ttyUSB3) device open
> count is 2 (close)
> Apr 27 08:15:21 ModemManager[4251]: <debug> (ttyUSB3): -->
> 'AT+CGDCONT=15,"IP",""<CR>'
> Apr 27 08:15:21 ModemManager[4251]: <debug> (ttyUSB3): <--
> '<CR><LF>OK<CR><LF>'
> ---
> src/mm-broadband-bearer.c | 37 +++++++++++++++++++-------------
> -----
> src/mm-modem-helpers.c | 4 ++++
> src/tests/test-modem-helpers.c | 7 ++++++-
> 3 files changed, 29 insertions(+), 19 deletions(-)
>
> diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c
> index 0a0d235e..6321de25 100644
> --- a/src/mm-broadband-bearer.c
> +++ b/src/mm-broadband-bearer.c
> @@ -867,29 +867,30 @@ parse_pdp_list (MMBaseModem *modem,
> MM3gppPdpContext *pdp = l->data;
>
> if (pdp->pdp_type == ctx->ip_family) {
> + const gchar *apn;
> +
> + apn = mm_bearer_properties_get_apn
> (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)));
> +
> + /* First requested, then existing */
> + if (mm_3gpp_cmp_apn_name (apn, pdp->apn)) {
> + gchar *ip_family_str;
> +
> + /* Found a PDP context with the same APN and PDP
> type, we'll use it. */
> + ip_family_str =
> mm_bearer_ip_family_build_string_from_mask (pdp->pdp_type);
> + mm_dbg ("Found PDP context with CID %u and PDP type
> %s for APN '%s'",
> + pdp->cid, ip_family_str, apn ? apn : "");
> + cid = pdp->cid;
> + ctx->use_existing_cid = TRUE;
> + g_free (ip_family_str);
> + /* In this case, stop searching */
> + break;
> + }
> +
> /* PDP with no APN set? we may use that one if not exact
> match found */
> if (!pdp->apn || !pdp->apn[0]) {
> mm_dbg ("Found PDP context with CID %u and no APN",
> pdp->cid);
> cid = pdp->cid;
> - } else {
> - const gchar *apn;
> -
> - apn = mm_bearer_properties_get_apn
> (mm_base_bearer_peek_config (MM_BASE_BEARER (ctx->self)));
> - /* First requested, then existing */
> - if (mm_3gpp_cmp_apn_name (apn, pdp->apn)) {
> - gchar *ip_family_str;
> -
> - /* Found a PDP context with the same APN and PDP
> type, we'll use it. */
> - ip_family_str =
> mm_bearer_ip_family_build_string_from_mask (pdp->pdp_type);
> - mm_dbg ("Found PDP context with CID %u and PDP
> type %s for APN '%s'",
> - pdp->cid, ip_family_str, apn);
> - cid = pdp->cid;
> - ctx->use_existing_cid = TRUE;
> - g_free (ip_family_str);
> - /* In this case, stop searching */
> - break;
> - }
> }
> }
>
> diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
> index 48cd1e16..c2586712 100644
> --- a/src/mm-modem-helpers.c
> +++ b/src/mm-modem-helpers.c
> @@ -1305,6 +1305,10 @@ mm_3gpp_cmp_apn_name (const gchar *requested,
> size_t requested_len;
> size_t existing_len;
>
> + /* If both empty, that's a good match */
> + if ((!existing || !existing[0]) && (!requested ||
> !requested[0]))
> + return TRUE;
> +
> /* Both must be given to compare properly */
> if (!existing || !existing[0] || !requested || !requested[0])
> return FALSE;
> diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-
> helpers.c
> index c2cc1105..483b56f5 100644
> --- a/src/tests/test-modem-helpers.c
> +++ b/src/tests/test-modem-helpers.c
> @@ -2166,17 +2166,22 @@ typedef struct {
> } TestApnCmp;
>
> static const TestApnCmp test_apn_cmp[] = {
> + {
> "", "",
> TRUE },
> + {
> NULL, "",
> TRUE },
> + {
> "", NULL,
> TRUE },
> + {
> NULL, NULL,
> TRUE },
> {
> "m2m.com.attz", "m2m.com.attz",
> TRUE },
> {
> "m2m.com.attz", "M2M.COM.ATTZ",
> TRUE },
> {
> "M2M.COM.ATTZ", "m2m.com.attz",
> TRUE },
> {
> "m2m.com.attz.mnc170.mcc310.gprs", "m2m.com.attz",
> TRUE },
> { "ac.vodafone.es.MNC001.MCC214.GPRS",
> "ac.vodafone.es", TRUE },
> + {
> "", "m2m.com.attz",
> FALSE },
> + {
> "m2m.com.attz", "",
> FALSE },
> {
> "m2m.com.attz", "m2m.com.attz.mnc170.mcc310.gprs
> ", FALSE },
> {
> "ac.vodafone.es", "ac.vodafone.es.MNC001.MCC214.GP
> RS", FALSE },
> {
> "internet.test", "internet",
> FALSE },
> {
> "internet.test", "INTERNET",
> FALSE },
> {
> "internet.test", "internet.tes",
> FALSE },
> - {
> "", "",
> FALSE },
> };
>
> static void
More information about the ModemManager-devel
mailing list