atmodem: Filter unspecified PPP DNS addresses
PATCH 1/1 atmodem: Filter unspecified PPP DNS addresses
When the PPP peer rejects the secondary DNS option before supplying an address, ipcp_rcn_rej() clears REQ_OPTION_DNS2 but leaves dns2 at its initial value of zero. Once IPCP is up, ipcp_up() converts that value to the non-empty string "0.0.0.0". ppp_connect() then includes it in the ConnectionContext Settings DomainNameServers array, for example:
DomainNameServers: [172.25.0.1, 0.0.0.0]
A connection with only one DNS server is valid. RFC 1877 section 1 says that primary and secondary addresses are negotiated independently, and section 1.3 states that no secondary DNS address is provided by default. 3GPP TS 27.060 V17.0.0 section 9 (pages 13-14) requires IPv4 DNS information over the TE-MT PPP link to be delivered as defined in RFC 1877.
Skip unspecified, empty and missing DNS addresses when building the list. Keep it compact and NULL-terminated so that a usable secondary address is retained even if the primary address is unavailable. The example above is then published as [172.25.0.1]. Log the filtered list, using "(none)" when no usable DNS address is available.
This only changes the exported settings and logging, not IPCP negotiation or the handling of previously supplied nonzero addresses for rejected options.
References:
https://www.rfc-editor.org/rfc/rfc1877.html#section-1
https://www.rfc-editor.org/rfc/rfc1877.html#section-1.3
https://www.etsi.org/deliver/etsi_ts/127000_127099/127060/17.00.00_60/ts_127060v170000p.pdf
--- drivers/atmodem/gprs-context.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/atmodem/gprs-context.c +11 -4
@@ -70,15 +70,22 @@ static void ppp_connect(const char *interface, const char *local,struct ofono_gprs_context *gc = user_data;struct gprs_context_data *gcd =ofono_gprs_context_get_data (gc);const char *dns[3 ]; +unsigned int n_dns =0 ;DBG ("" ); - dns[0 ] = dns1; - dns[1 ] = dns2; - dns[2 ] =0 ; +if (dns1 && dns1[0 ] &&strcmp (dns1,"0.0.0.0" )) + dns[n_dns++] = dns1; + +if (dns2 && dns2[0 ] &&strcmp (dns2,"0.0.0.0" )) + dns[n_dns++] = dns2; + + dns[n_dns] =NULL ;ofono_info ("IP: %s" , local); -ofono_info ("DNS: %s, %s" , dns1, dns2); +ofono_info ("DNS: %s%s%s" , n_dns ? dns[0 ] :"(none)" , + n_dns >1 ?", " :"" , + n_dns >1 ? dns[1 ] :"" ); gcd->state =STATE_ACTIVE ;ofono_gprs_context_set_interface (gc, interface);