From 9015c28406c1e98bf5579d9ede3f9a345f5898e3 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sun, 26 Jun 2016 21:36:48 +0200 Subject: [PATCH] PPP, DNS: introduce ppp_set_usepeerdns macro PPP use peer DNS setting is currently hardcoded to true if PPP is acting as a client and set to false if PPP is actinf as a server. This is probably the most wanted behavior, but since we now have the ability to change that at runtime, allow users to do it. We don't have a way to have a different default configuration if the PPP PCB is going to be used as a client or as a server, therefore the default configuration should be fine for both of them. Since enabling peer DNS by default is dangerous for server mode, the default is now not to ask for DNS servers and it should now be explicitely enabled if needed, update the documentation accordingly. --- doc/ppp.txt | 18 ++++++++++++++---- src/include/netif/ppp/ppp.h | 6 ++++++ src/netif/ppp/ppp.c | 4 ---- src/netif/ppp/pppos.c | 5 ----- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/doc/ppp.txt b/doc/ppp.txt index 5821dfa8..43387c23 100644 --- a/doc/ppp.txt +++ b/doc/ppp.txt @@ -277,6 +277,16 @@ ppp_set_default(ppp); * ============================== */ +/* + * Basic PPP client configuration. Can only be set if PPP session is in the + * dead state (i.e. disconnected). We don't need to provide thread-safe + * equivalents through PPPAPI because those helpers are only changing + * structure members. + */ + +/* Ask the peer for up to 2 DNS server addresses. */ +ppp_set_usepeerdns(ppp, 1); + /* * Initiate PPP negotiation, without waiting (holdoff=0), can only be called * if PPP session is in the dead state (i.e. disconnected). @@ -450,10 +460,10 @@ from previous lwIP version is pretty easy: * ppp_sighup and ppp_close functions were merged using an optional argument "nocarrier" on ppp_close. -* DNS servers are now only remotely asked if LWIP_DNS is set and we are now - unconditionally registering them, which is probably the wanted behavior in - almost all cases. If you need it conditional contact us and we will made it - conditional. +* DNS servers are now only remotely asked if LWIP_DNS is set and if + ppp_set_usepeerdns() is set to true, they are now automatically registered + using the dns_setserver() function so you don't need to do that in the PPP + callback anymore. * PPPoS does not use the SIO API anymore, as such it now requires a serial output callback in place of sio_write diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index 98d60790..20f41dbb 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -466,6 +466,12 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas * for PPP server support. */ #define ppp_set_ipcp_dnsaddr(ppp, index, addr) (ppp->ipcp_allowoptions.dnsaddr[index] = ip4_addr_get_u32(addr)) + +/* + * Whether we ask the peer for up to 2 DNS server addresses. Received DNS server addresses are + * registered using the dns_setserver() function. Default is false. + */ +#define ppp_set_usepeerdns(ppp, boolval) (ppp->settings.usepeerdns = boolval) #endif /* LWIP_DNS */ #endif /* PPP_IPV4_SUPPORT */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 70db122c..1fb9566e 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -627,10 +627,6 @@ ppp_pcb *ppp_new(struct netif *pppif, const struct link_callbacks *callbacks, vo memset(pcb, 0, sizeof(ppp_pcb)); /* default configuration */ -#if LWIP_DNS - pcb->settings.usepeerdns = 1; -#endif /* LWIP_DNS */ - #if PAP_SUPPORT pcb->settings.pap_timeout_time = UPAP_DEFTIMEOUT; pcb->settings.pap_max_transmits = UPAP_DEFTRANSMITS; diff --git a/src/netif/ppp/pppos.c b/src/netif/ppp/pppos.c index 47548d54..3478a76b 100644 --- a/src/netif/ppp/pppos.c +++ b/src/netif/ppp/pppos.c @@ -357,11 +357,6 @@ pppos_listen(ppp_pcb *ppp, void *ctx) } #endif /* PPP_AUTH_SUPPORT */ -#if PPP_IPV4_SUPPORT && LWIP_DNS - /* Don't accept DNS from peer */ - ppp->settings.usepeerdns = 0; -#endif /* PPP_IPV4_SUPPORT && LWIP_DNS */ - /* * Default the in and out accm so that escape and flag characters * are always escaped.