Skip to content

Commit

Permalink
applications: slm: try to continue even no DNS record was sent
Browse files Browse the repository at this point in the history
We shouldn't expect 2 DNS records from ISP.
Because it sends sometimes 1 and even 0.
It must try to continue like in MOSH.

Signed-off-by: Oguzhan Turk <[email protected]>
  • Loading branch information
TaeZStkyoht committed Dec 23, 2024
1 parent 6266884 commit d1fa9c0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion applications/serial_lte_modem/src/slm_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static int ppp_start_internal(void)
if (ret) {
/* If any error happened on pdn getting with IPv4, try to parse with IPv6 */
ret = pdn_dynamic_params_get_v6(PDP_CID, NULL, NULL, &mtu);
if (ret) {
if (ret && ret != -EBADMSG) {
return ret;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ Modem libraries
* :ref:`pdn_readme` library:

* Added the :c:func:`pdn_dynamic_params_get_v6` function to get PDN parameters for IPv6-only.
* Changed logic DNS record expectation. Because ISP sends sometimes 1 and even 0.

* :ref:`lte_lc_readme` library:

Expand Down
42 changes: 34 additions & 8 deletions lib/pdn/pdn.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,17 @@ int pdn_dynamic_params_get(uint8_t cid, struct in_addr *dns4_pri,
char dns4_sec_str[INET_ADDRSTRLEN];
char at_cmd[sizeof("AT+CGCONTRDP=10")];

/* Initialize out variables with default */
if (dns4_pri) {
memset(dns4_pri, 0, sizeof(struct in_addr));
}
if (dns4_sec) {
memset(dns4_sec, 0, sizeof(struct in_addr));
}
if (ipv4_mtu) {
*ipv4_mtu = 0;
}

if (snprintf(at_cmd, sizeof(at_cmd), "AT+CGCONTRDP=%u", cid) >= sizeof(at_cmd)) {
return -E2BIG;
}
Expand All @@ -632,8 +643,8 @@ int pdn_dynamic_params_get(uint8_t cid, struct in_addr *dns4_pri,

/* If IPv4 is enabled, it will be the first response line. */
matched = nrf_modem_at_scanf(at_cmd, fmt, &dns4_pri_str, &dns4_sec_str, &mtu);
/* Need to match at least the two IP addresses, or there is an error */
if (matched < 2) {

if (matched < 1) {
return -EBADMSG;
}

Expand All @@ -643,8 +654,10 @@ int pdn_dynamic_params_get(uint8_t cid, struct in_addr *dns4_pri,
}
}
if (dns4_sec) {
if (zsock_inet_pton(AF_INET, dns4_sec_str, dns4_sec) != 1) {
return -EADDRNOTAVAIL;
if (matched >= 2) {
if (zsock_inet_pton(AF_INET, dns4_sec_str, dns4_sec) != 1) {
return -EADDRNOTAVAIL;
}
}
}
if (ipv4_mtu) {
Expand All @@ -669,6 +682,17 @@ int pdn_dynamic_params_get_v6(uint8_t cid, struct in6_addr *dns6_pri,
char dns6_sec_str[INET6_ADDRSTRLEN];
char at_cmd[sizeof("AT+CGCONTRDP=10")];

/* Initialize out variables with default */
if (dns6_pri) {
memset(dns6_pri, 0, sizeof(struct in6_addr));
}
if (dns6_sec) {
memset(dns6_sec, 0, sizeof(struct in6_addr));
}
if (ipv6_mtu) {
*ipv6_mtu = 0;
}

if (snprintf(at_cmd, sizeof(at_cmd), "AT+CGCONTRDP=%u", cid) >= sizeof(at_cmd)) {
return -E2BIG;
}
Expand All @@ -681,8 +705,8 @@ int pdn_dynamic_params_get_v6(uint8_t cid, struct in6_addr *dns6_pri,

/* If IPv6 is enabled, it will be the first response line. */
matched = nrf_modem_at_scanf(at_cmd, fmt, &dns6_pri_str, &dns6_sec_str, &mtu);
/* Need to match at least the two IP addresses, or there is an error */
if (matched < 2) {

if (matched < 1) {
return -EBADMSG;
}

Expand All @@ -692,8 +716,10 @@ int pdn_dynamic_params_get_v6(uint8_t cid, struct in6_addr *dns6_pri,
}
}
if (dns6_sec) {
if (zsock_inet_pton(AF_INET6, dns6_sec_str, dns6_sec) != 1) {
return -EADDRNOTAVAIL;
if (matched >= 2) {
if (zsock_inet_pton(AF_INET6, dns6_sec_str, dns6_sec) != 1) {
return -EADDRNOTAVAIL;
}
}
}
if (ipv6_mtu) {
Expand Down

0 comments on commit d1fa9c0

Please sign in to comment.