Skip to content

Commit 74ab646

Browse files
committed
applications: serial_lte_modem: Serve DNS from PDN to PPP
When remote peer requests a DNS address from PPP using IPCP, we should offer that in the ipcp.peer_options or ipcp.my_options. Populate this information from PDN, or use any of the known Kconfig DNS addresses as a fallback. Signed-off-by: Seppo Takalo <[email protected]>
1 parent b160827 commit 74ab646

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

applications/serial_lte_modem/src/slm_ppp.c

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ static void ppp_start_failure(void)
252252
net_if_down(ppp_iface);
253253
}
254254

255-
static unsigned int ppp_retrieve_mtu(void)
255+
static void ppp_retrieve_pdn_info(struct ppp_context *const ctx)
256256
{
257-
struct pdn_dynamic_info populated_info = { 0 };
257+
struct pdn_dynamic_info populated_info = {0};
258+
unsigned int mtu = CONFIG_SLM_PPP_FALLBACK_MTU;
258259

259260
if (!pdn_dynamic_info_get(ppp_pdn_cid, &populated_info)) {
260261
if (populated_info.ipv6_mtu) {
@@ -263,23 +264,44 @@ static unsigned int ppp_retrieve_mtu(void)
263264
* Because, it must be at least 1280 for IPv6,
264265
* while MTU of IPv4 may be less.
265266
*/
266-
return MIN(populated_info.ipv6_mtu, sizeof(ppp_data_buf));
267-
}
268-
if (populated_info.ipv4_mtu) {
267+
mtu = MIN(populated_info.ipv6_mtu, sizeof(ppp_data_buf));
268+
} else if (populated_info.ipv4_mtu) {
269269
/* Set the PPP MTU to that of the LTE link. */
270-
return MIN(populated_info.ipv4_mtu, sizeof(ppp_data_buf));
270+
mtu = MIN(populated_info.ipv4_mtu, sizeof(ppp_data_buf));
271271
}
272-
}
273-
274-
LOG_DBG("Could not retrieve MTU, using fallback value.");
275-
BUILD_ASSERT(sizeof(ppp_data_buf) >= CONFIG_SLM_PPP_FALLBACK_MTU);
276-
return CONFIG_SLM_PPP_FALLBACK_MTU;
277-
}
278-
279-
static void ppp_set_mtu(void)
280-
{
281-
const unsigned int mtu = ppp_retrieve_mtu();
282272

273+
/* Try to populate DNS addresses from PDN */
274+
if (populated_info.dns_addr4_primary.s_addr != INADDR_ANY) {
275+
/* Populate both My address and peer options
276+
* as these are wrong way in Zephyr (it offers my_option DNS)
277+
*/
278+
ctx->ipcp.peer_options.dns1_address = populated_info.dns_addr4_primary;
279+
ctx->ipcp.peer_options.dns2_address = populated_info.dns_addr4_secondary;
280+
ctx->ipcp.my_options.dns1_address = populated_info.dns_addr4_primary;
281+
ctx->ipcp.my_options.dns2_address = populated_info.dns_addr4_secondary;
282+
#if defined(CONFIG_LTE_LC_DNS_FALLBACK_ADDRESS)
283+
} else {
284+
/* Use fallback DNS addresses from LTE_LC module */
285+
(void)nrf_inet_pton(NRF_AF_INET, CONFIG_LTE_LC_DNS_FALLBACK_ADDRESS,
286+
&ctx->ipcp.peer_options.dns1_address);
287+
ctx->ipcp.my_options.dns1_address = ctx->ipcp.peer_options.dns1_address;
288+
}
289+
#elif defined(CONFIG_DNS_SERVER1)
290+
} else {
291+
/* Use fallback DNS addresses from Zephyr */
292+
(void)nrf_inet_pton(NRF_AF_INET, CONFIG_DNS_SERVER1,
293+
&ctx->ipcp.peer_options.dns1_address);
294+
ctx->ipcp.my_options.dns1_address = ctx->ipcp.peer_options.dns1_address;
295+
}
296+
#else
297+
} else {
298+
LOG_WRN("No DNS addresses available on PDN and no fallback configured.");
299+
}
300+
#endif
301+
} else {
302+
LOG_DBG("Could not retrieve MTU, using fallback value.");
303+
BUILD_ASSERT(sizeof(ppp_data_buf) >= CONFIG_SLM_PPP_FALLBACK_MTU);
304+
}
283305
net_if_set_mtu(ppp_iface, mtu);
284306
LOG_DBG("MTU set to %u.", mtu);
285307
}
@@ -300,7 +322,7 @@ static int ppp_start(void)
300322
goto error;
301323
}
302324

303-
ppp_set_mtu();
325+
ppp_retrieve_pdn_info(ctx);
304326

305327
ret = net_if_up(ppp_iface);
306328
if (ret) {

0 commit comments

Comments
 (0)