From 646797acb5cd8600f566ba92bb590876ad18f9ee Mon Sep 17 00:00:00 2001
From: Maxime Bizon <mbizon@freebox.fr>
Date: Thu, 16 Jan 2020 01:00:19 +0100
Subject: [PATCH 11/12] pppd: add option to skip network config apply

---
 pppd/ipcp.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/pppd/ipcp.c b/pppd/ipcp.c
index ded4370..1fb6844 100644
--- a/pppd/ipcp.c
+++ b/pppd/ipcp.c
@@ -94,6 +94,7 @@ static int ipcp_is_open;		/* haven't called np_finished() */
 static bool ask_for_local;		/* request our address from peer */
 static char vj_value[8];		/* string form of vj option value */
 static char netmask_str[20];		/* string form of netmask value */
+static bool noapplycfg;			/* don't apply network config */
 
 /*
  * Callbacks for fsm code.  (CI = Configuration Information)
@@ -244,6 +245,9 @@ static struct option ipcp_option_list[] = {
       "set local and remote IP addresses",
       OPT_NOARG | OPT_A2PRINTER, (void *) &printipaddr },
 
+    { "noapplycfg", o_bool, &noapplycfg,
+      "don't apply network config", 1 },
+
     { NULL }
 };
 
@@ -1768,18 +1772,19 @@ ip_demand_conf(int u)
 	wo->accept_local = 1;
 	ask_for_local = 0;	/* don't tell the peer this address */
     }
-    if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
+    if (!noapplycfg &&
+	!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
 	return 0;
     ipcp_script(path_ippreup, 1);
-    if (!sifup(u))
+    if (!noapplycfg && !sifup(u))
 	return 0;
     if (!sifnpmode(u, PPP_IP, NPMODE_QUEUE))
 	return 0;
-    if (wo->default_route)
+    if (!noapplycfg && wo->default_route)
 	if (sifdefaultroute(u, wo->ouraddr, wo->hisaddr,
 					    wo->replace_default_route))
 	    default_route_set[u] = 1;
-    if (wo->proxy_arp)
+    if (!noapplycfg && wo->proxy_arp)
 	if (sifproxyarp(u, wo->hisaddr))
 	    proxy_arp_set[u] = 1;
 
@@ -1849,7 +1854,8 @@ ipcp_up(fsm *f)
 	ppp_script_setenv("DNS2", ip_ntoa(go->dnsaddr[1]), 0);
     if (usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
 	ppp_script_setenv("USEPEERDNS", "1", 0);
-	create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
+	if (!noapplycfg)
+		create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
     }
 
     if (go->winsaddr[0])
@@ -1925,7 +1931,7 @@ ipcp_up(fsm *f)
 	mask = GetMask(go->ouraddr);
 
 #if !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
-	if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
+	if (!noapplycfg && !sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
 	    if (debug)
 		warn("Interface configuration failed");
 	    ipcp_close(f->unit, "Interface configuration failed");
@@ -1946,7 +1952,7 @@ ipcp_up(fsm *f)
 	}
 
 	/* bring the interface up for IP */
-	if (!sifup(f->unit)) {
+	if (!noapplycfg && !sifup(f->unit)) {
 	    if (debug)
 		warn("Interface failed to come up");
 	    ipcp_close(f->unit, "Interface configuration failed");
@@ -1954,7 +1960,7 @@ ipcp_up(fsm *f)
 	}
 
 #if (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
-	if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
+	if (!noapplycfg && !sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
 	    if (debug)
 		warn("Interface configuration failed");
 	    ipcp_close(f->unit, "Interface configuration failed");
@@ -1965,13 +1971,15 @@ ipcp_up(fsm *f)
 
 	/* assign a default route through the interface if required */
 	if (ipcp_wantoptions[f->unit].default_route) 
-	    if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr,
+	    if (!noapplycfg &&
+		sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr,
 					 wo->replace_default_route))
 		default_route_set[f->unit] = 1;
 
 	/* Make a proxy ARP entry if requested. */
 	if (ho->hisaddr != 0 && ipcp_wantoptions[f->unit].proxy_arp)
-	    if (sifproxyarp(f->unit, ho->hisaddr))
+	    if (!noapplycfg &&
+		sifproxyarp(f->unit, ho->hisaddr))
 		proxy_arp_set[f->unit] = 1;
 
 	ipcp_wantoptions[0].ouraddr = go->ouraddr;
-- 
2.34.1

