broadband-bearer: allow matching empty APN when looking for PDP CID

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:

    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>'
This commit is contained in:
Aleksander Morgado
2018-04-28 10:38:53 +02:00
parent 43d0bd0f91
commit e17d5a51a2
3 changed files with 29 additions and 19 deletions

View File

@@ -867,15 +867,10 @@ parse_pdp_list (MMBaseModem *modem,
MM3gppPdpContext *pdp = l->data;
if (pdp->pdp_type == ctx->ip_family) {
/* 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;
@@ -883,13 +878,19 @@ parse_pdp_list (MMBaseModem *modem,
/* 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);
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;
}
}

View File

@@ -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;

View File

@@ -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.GPRS", FALSE },
{ "internet.test", "internet", FALSE },
{ "internet.test", "INTERNET", FALSE },
{ "internet.test", "internet.tes", FALSE },
{ "", "", FALSE },
};
static void