From dde55c6c0efcdf3869416c1c2231488e33ca9343 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 5 Nov 2016 21:34:23 +0100 Subject: [PATCH] PPP, IPCP: fix reset state before reconnecting Commit 7df5496e7b revealed a regression introduced in commit 5a71509353 which broke IPCP reset state. ask_for_local was set to 0 if ouraddr initial value is 0, if ask_for_local was false go->ouraddr was cleared in reset callback, commit 5a71509353 breaks it by removing this clearing. This regression was silent because the whole ppp pcb runtime data was cleared before reconnecting until commit 7df5496e7b which removed this giant clearing. Fix it by reintroducing ask_for_local boolean value, with proper initial value following what unused function ip_check_options do. Fixes: 7df5496e7b ("PPP, rework initial/reconnect cleanup") Fixes: 5a71509353 ("PPP, CORE, IPCP: removed useless ask_for_local boolean") --- src/include/netif/ppp/ppp.h | 4 +++- src/netif/ppp/ipcp.c | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/include/netif/ppp/ppp.h b/src/include/netif/ppp/ppp.h index 28b2732a..d9ea097e 100644 --- a/src/include/netif/ppp/ppp.h +++ b/src/include/netif/ppp/ppp.h @@ -324,6 +324,7 @@ struct ppp_pcb_s { /* flags */ #if PPP_IPV4_SUPPORT + unsigned int ask_for_local :1; /* request our address from peer */ unsigned int ipcp_is_open :1; /* haven't called np_finished() */ unsigned int ipcp_is_up :1; /* have called ipcp_up() */ unsigned int if4_up :1; /* True when the IPv4 interface is up. */ @@ -475,7 +476,8 @@ void ppp_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *pas * * Default is unset (0.0.0.0). */ -#define ppp_set_ipcp_ouraddr(ppp, addr) (ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr)) +#define ppp_set_ipcp_ouraddr(ppp, addr) do { ppp->ipcp_wantoptions.ouraddr = ip4_addr_get_u32(addr); \ + ppp->ask_for_local = ppp->ipcp_wantoptions.ouraddr != 0; } while(0) #define ppp_set_ipcp_hisaddr(ppp, addr) (ppp->ipcp_wantoptions.hisaddr = ip4_addr_get_u32(addr)) #if LWIP_DNS /* diff --git a/src/netif/ppp/ipcp.c b/src/netif/ppp/ipcp.c index 7d9d6fd8..5d859299 100644 --- a/src/netif/ppp/ipcp.c +++ b/src/netif/ppp/ipcp.c @@ -728,13 +728,8 @@ static void ipcp_resetci(fsm *f) { wo->req_dns1 = wo->req_dns2 = pcb->settings.usepeerdns; /* Request DNS addresses from the peer */ #endif /* LWIP_DNS */ *go = *wo; -#if 0 /* UNUSED */ - /* We don't need ask_for_local, this is only useful for setup which - * can determine the local IP address from the system hostname. - */ - if (!ask_for_local) + if (!pcb->ask_for_local) go->ouraddr = 0; -#endif /* UNUSED */ #if 0 /* UNUSED */ if (ip_choose_hook) { ip_choose_hook(&wo->hisaddr);